]>
Commit | Line | Data |
---|---|---|
a2654f78 | 1 | aufs4.x-rcN kbuild patch |
7f207e10 AM |
2 | |
3 | diff --git a/fs/Kconfig b/fs/Kconfig | |
a2654f78 | 4 | index 83eab52..31f16c4 100644 |
7f207e10 AM |
5 | --- a/fs/Kconfig |
6 | +++ b/fs/Kconfig | |
a2654f78 | 7 | @@ -248,6 +248,7 @@ source "fs/pstore/Kconfig" |
5527c038 | 8 | source "fs/sysv/Kconfig" |
7e9cd9fe | 9 | source "fs/ufs/Kconfig" |
7f207e10 AM |
10 | source "fs/exofs/Kconfig" |
11 | +source "fs/aufs/Kconfig" | |
12 | ||
13 | endif # MISC_FILESYSTEMS | |
14 | ||
15 | diff --git a/fs/Makefile b/fs/Makefile | |
a2654f78 | 16 | index 7bbaca9..a026491 100644 |
7f207e10 AM |
17 | --- a/fs/Makefile |
18 | +++ b/fs/Makefile | |
a2654f78 | 19 | @@ -128,3 +128,4 @@ obj-y += exofs/ # Multiple modules |
7f207e10 | 20 | obj-$(CONFIG_CEPH_FS) += ceph/ |
bf0370f2 | 21 | obj-$(CONFIG_PSTORE) += pstore/ |
c06a8ce3 | 22 | obj-$(CONFIG_EFIVAR_FS) += efivarfs/ |
86dc4139 | 23 | +obj-$(CONFIG_AUFS_FS) += aufs/ |
c06a8ce3 | 24 | diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild |
521ced18 | 25 | index dd9820b..d0435d9 100644 |
c06a8ce3 AM |
26 | --- a/include/uapi/linux/Kbuild |
27 | +++ b/include/uapi/linux/Kbuild | |
5527c038 | 28 | @@ -59,6 +59,7 @@ header-y += atmsvc.h |
03673fb0 JR |
29 | header-y += atm_tcp.h |
30 | header-y += atm_zatm.h | |
c06a8ce3 AM |
31 | header-y += audit.h |
32 | +header-y += aufs_type.h | |
c06a8ce3 | 33 | header-y += auto_fs4.h |
03673fb0 | 34 | header-y += auto_fs.h |
c06a8ce3 | 35 | header-y += auxvec.h |
a2654f78 | 36 | aufs4.x-rcN base patch |
7f207e10 | 37 | |
c1595e42 | 38 | diff --git a/MAINTAINERS b/MAINTAINERS |
521ced18 | 39 | index 1b0a87f..76fd7cc 100644 |
c1595e42 JR |
40 | --- a/MAINTAINERS |
41 | +++ b/MAINTAINERS | |
521ced18 | 42 | @@ -2319,6 +2319,19 @@ F: include/linux/audit.h |
c1595e42 JR |
43 | F: include/uapi/linux/audit.h |
44 | F: kernel/audit* | |
45 | ||
46 | +AUFS (advanced multi layered unification filesystem) FILESYSTEM | |
47 | +M: "J. R. Okajima" <hooanon05g@gmail.com> | |
48 | +L: linux-unionfs@vger.kernel.org | |
49 | +L: aufs-users@lists.sourceforge.net (members only) | |
50 | +W: http://aufs.sourceforge.net | |
5527c038 | 51 | +T: git://github.com/sfjro/aufs4-linux.git |
c1595e42 JR |
52 | +S: Supported |
53 | +F: Documentation/filesystems/aufs/ | |
54 | +F: Documentation/ABI/testing/debugfs-aufs | |
55 | +F: Documentation/ABI/testing/sysfs-aufs | |
56 | +F: fs/aufs/ | |
57 | +F: include/uapi/linux/aufs_type.h | |
58 | + | |
59 | AUXILIARY DISPLAY DRIVERS | |
60 | M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> | |
61 | W: http://miguelojeda.es/auxdisplay.htm | |
392086de | 62 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c |
521ced18 | 63 | index 0ecb646..cf39138 100644 |
392086de AM |
64 | --- a/drivers/block/loop.c |
65 | +++ b/drivers/block/loop.c | |
e2f27e51 | 66 | @@ -701,6 +701,24 @@ static inline int is_loop_device(struct file *file) |
392086de AM |
67 | return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR; |
68 | } | |
69 | ||
70 | +/* | |
71 | + * for AUFS | |
72 | + * no get/put for file. | |
73 | + */ | |
74 | +struct file *loop_backing_file(struct super_block *sb) | |
75 | +{ | |
76 | + struct file *ret; | |
77 | + struct loop_device *l; | |
78 | + | |
79 | + ret = NULL; | |
80 | + if (MAJOR(sb->s_dev) == LOOP_MAJOR) { | |
81 | + l = sb->s_bdev->bd_disk->private_data; | |
82 | + ret = l->lo_backing_file; | |
83 | + } | |
84 | + return ret; | |
85 | +} | |
febd17d6 | 86 | +EXPORT_SYMBOL_GPL(loop_backing_file); |
392086de AM |
87 | + |
88 | /* loop sysfs attributes */ | |
89 | ||
90 | static ssize_t loop_attr_show(struct device *dev, char *page, | |
c1595e42 | 91 | diff --git a/fs/dcache.c b/fs/dcache.c |
a2654f78 | 92 | index 95d71ed..8ca5f09 100644 |
c1595e42 JR |
93 | --- a/fs/dcache.c |
94 | +++ b/fs/dcache.c | |
e2f27e51 | 95 | @@ -1164,7 +1164,7 @@ enum d_walk_ret { |
c1595e42 JR |
96 | * |
97 | * The @enter() and @finish() callbacks are called with d_lock held. | |
98 | */ | |
99 | -static void d_walk(struct dentry *parent, void *data, | |
100 | +void d_walk(struct dentry *parent, void *data, | |
101 | enum d_walk_ret (*enter)(void *, struct dentry *), | |
102 | void (*finish)(void *)) | |
103 | { | |
febd17d6 | 104 | diff --git a/fs/fcntl.c b/fs/fcntl.c |
521ced18 | 105 | index be8fbe2..f5f4f94 100644 |
febd17d6 JR |
106 | --- a/fs/fcntl.c |
107 | +++ b/fs/fcntl.c | |
521ced18 | 108 | @@ -30,7 +30,7 @@ |
febd17d6 JR |
109 | |
110 | #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME) | |
111 | ||
112 | -static int setfl(int fd, struct file * filp, unsigned long arg) | |
113 | +int setfl(int fd, struct file * filp, unsigned long arg) | |
114 | { | |
115 | struct inode * inode = file_inode(filp); | |
116 | int error = 0; | |
521ced18 | 117 | @@ -61,6 +61,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg) |
febd17d6 JR |
118 | |
119 | if (filp->f_op->check_flags) | |
120 | error = filp->f_op->check_flags(arg); | |
121 | + if (!error && filp->f_op->setfl) | |
122 | + error = filp->f_op->setfl(filp, arg); | |
123 | if (error) | |
124 | return error; | |
125 | ||
5afbbe0d | 126 | diff --git a/fs/inode.c b/fs/inode.c |
f2c43d5f | 127 | index 88110fd..9a9ba3a 100644 |
5afbbe0d AM |
128 | --- a/fs/inode.c |
129 | +++ b/fs/inode.c | |
a2654f78 | 130 | @@ -1642,7 +1642,7 @@ EXPORT_SYMBOL(generic_update_time); |
5afbbe0d AM |
131 | * This does the actual work of updating an inodes time or version. Must have |
132 | * had called mnt_want_write() before calling this. | |
133 | */ | |
134 | -static int update_time(struct inode *inode, struct timespec *time, int flags) | |
135 | +int update_time(struct inode *inode, struct timespec *time, int flags) | |
136 | { | |
137 | int (*update_time)(struct inode *, struct timespec *, int); | |
138 | ||
5527c038 | 139 | diff --git a/fs/read_write.c b/fs/read_write.c |
521ced18 | 140 | index c4f88af..ac71b96 100644 |
5527c038 JR |
141 | --- a/fs/read_write.c |
142 | +++ b/fs/read_write.c | |
521ced18 | 143 | @@ -513,6 +513,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count, |
5527c038 JR |
144 | } |
145 | EXPORT_SYMBOL(__vfs_write); | |
146 | ||
147 | +vfs_readf_t vfs_readf(struct file *file) | |
148 | +{ | |
149 | + const struct file_operations *fop = file->f_op; | |
150 | + | |
151 | + if (fop->read) | |
152 | + return fop->read; | |
153 | + if (fop->read_iter) | |
154 | + return new_sync_read; | |
155 | + return ERR_PTR(-ENOSYS); | |
156 | +} | |
157 | + | |
158 | +vfs_writef_t vfs_writef(struct file *file) | |
159 | +{ | |
160 | + const struct file_operations *fop = file->f_op; | |
161 | + | |
162 | + if (fop->write) | |
163 | + return fop->write; | |
164 | + if (fop->write_iter) | |
165 | + return new_sync_write; | |
166 | + return ERR_PTR(-ENOSYS); | |
167 | +} | |
168 | + | |
169 | ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos) | |
170 | { | |
171 | mm_segment_t old_fs; | |
7f207e10 | 172 | diff --git a/fs/splice.c b/fs/splice.c |
521ced18 | 173 | index 006ba50..46c87af 100644 |
7f207e10 AM |
174 | --- a/fs/splice.c |
175 | +++ b/fs/splice.c | |
521ced18 | 176 | @@ -859,8 +859,8 @@ EXPORT_SYMBOL(generic_splice_sendpage); |
7f207e10 AM |
177 | /* |
178 | * Attempt to initiate a splice from pipe to file. | |
179 | */ | |
180 | -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
181 | - loff_t *ppos, size_t len, unsigned int flags) | |
182 | +long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
183 | + loff_t *ppos, size_t len, unsigned int flags) | |
184 | { | |
185 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, | |
186 | loff_t *, size_t, unsigned int); | |
521ced18 | 187 | @@ -876,9 +876,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
7f207e10 AM |
188 | /* |
189 | * Attempt to initiate a splice from a file to a pipe. | |
190 | */ | |
191 | -static long do_splice_to(struct file *in, loff_t *ppos, | |
192 | - struct pipe_inode_info *pipe, size_t len, | |
193 | - unsigned int flags) | |
194 | +long do_splice_to(struct file *in, loff_t *ppos, | |
195 | + struct pipe_inode_info *pipe, size_t len, | |
196 | + unsigned int flags) | |
197 | { | |
198 | ssize_t (*splice_read)(struct file *, loff_t *, | |
199 | struct pipe_inode_info *, size_t, unsigned int); | |
a2654f78 | 200 | diff --git a/fs/sync.c b/fs/sync.c |
521ced18 | 201 | index 11ba023..abf6a5d 100644 |
a2654f78 AM |
202 | --- a/fs/sync.c |
203 | +++ b/fs/sync.c | |
204 | @@ -27,7 +27,7 @@ | |
205 | * wait == 1 case since in that case write_inode() functions do | |
206 | * sync_dirty_buffer() and thus effectively write one block at a time. | |
207 | */ | |
208 | -static int __sync_filesystem(struct super_block *sb, int wait) | |
209 | +int __sync_filesystem(struct super_block *sb, int wait) | |
210 | { | |
211 | if (wait) | |
212 | sync_inodes_sb(sb); | |
b912730e | 213 | diff --git a/include/linux/file.h b/include/linux/file.h |
a2654f78 | 214 | index 61eb82c..e700888 100644 |
b912730e AM |
215 | --- a/include/linux/file.h |
216 | +++ b/include/linux/file.h | |
a2654f78 | 217 | @@ -19,6 +19,7 @@ struct dentry; |
b912730e | 218 | struct path; |
a2654f78 | 219 | extern struct file *alloc_file(const struct path *, fmode_t mode, |
b912730e AM |
220 | const struct file_operations *fop); |
221 | +extern struct file *get_empty_filp(void); | |
222 | ||
223 | static inline void fput_light(struct file *file, int fput_needed) | |
224 | { | |
5527c038 | 225 | diff --git a/include/linux/fs.h b/include/linux/fs.h |
521ced18 | 226 | index 7251f7b..3668627 100644 |
5527c038 JR |
227 | --- a/include/linux/fs.h |
228 | +++ b/include/linux/fs.h | |
521ced18 | 229 | @@ -1246,6 +1246,7 @@ extern void fasync_free(struct fasync_struct *); |
febd17d6 JR |
230 | /* can be called from interrupts */ |
231 | extern void kill_fasync(struct fasync_struct **, int, int); | |
232 | ||
233 | +extern int setfl(int fd, struct file * filp, unsigned long arg); | |
234 | extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force); | |
235 | extern void f_setown(struct file *filp, unsigned long arg, int force); | |
236 | extern void f_delown(struct file *filp); | |
521ced18 | 237 | @@ -1673,6 +1674,7 @@ struct file_operations { |
febd17d6 JR |
238 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); |
239 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); | |
240 | int (*check_flags)(int); | |
241 | + int (*setfl)(struct file *, unsigned long); | |
242 | int (*flock) (struct file *, int, struct file_lock *); | |
243 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); | |
244 | ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); | |
521ced18 | 245 | @@ -1749,6 +1751,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, |
5527c038 JR |
246 | struct iovec *fast_pointer, |
247 | struct iovec **ret_pointer); | |
248 | ||
249 | +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *); | |
250 | +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t, | |
251 | + loff_t *); | |
252 | +vfs_readf_t vfs_readf(struct file *file); | |
253 | +vfs_writef_t vfs_writef(struct file *file); | |
254 | + | |
255 | extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *); | |
256 | extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *); | |
257 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); | |
521ced18 | 258 | @@ -2127,6 +2135,7 @@ extern int current_umask(void); |
5afbbe0d AM |
259 | extern void ihold(struct inode * inode); |
260 | extern void iput(struct inode *); | |
261 | extern int generic_update_time(struct inode *, struct timespec *, int); | |
262 | +extern int update_time(struct inode *, struct timespec *, int); | |
263 | ||
264 | /* /sys/fs */ | |
265 | extern struct kobject *fs_kobj; | |
521ced18 | 266 | @@ -2407,6 +2416,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb) |
a2654f78 AM |
267 | return false; |
268 | } | |
269 | #endif | |
270 | +extern int __sync_filesystem(struct super_block *, int); | |
271 | extern int sync_filesystem(struct super_block *); | |
272 | extern const struct file_operations def_blk_fops; | |
273 | extern const struct file_operations def_chr_fops; | |
1e00d052 | 274 | diff --git a/include/linux/splice.h b/include/linux/splice.h |
f2c43d5f | 275 | index 00a2116..1f0a4a2 100644 |
1e00d052 AM |
276 | --- a/include/linux/splice.h |
277 | +++ b/include/linux/splice.h | |
a2654f78 | 278 | @@ -86,4 +86,10 @@ extern void spd_release_page(struct splice_pipe_desc *, unsigned int); |
4b3da204 AM |
279 | |
280 | extern const struct pipe_buf_operations page_cache_pipe_buf_ops; | |
106341ce | 281 | extern const struct pipe_buf_operations default_pipe_buf_ops; |
1e00d052 AM |
282 | + |
283 | +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
284 | + loff_t *ppos, size_t len, unsigned int flags); | |
285 | +extern long do_splice_to(struct file *in, loff_t *ppos, | |
286 | + struct pipe_inode_info *pipe, size_t len, | |
287 | + unsigned int flags); | |
288 | #endif | |
a2654f78 | 289 | aufs4.x-rcN mmap patch |
fb47a38f | 290 | |
c1595e42 | 291 | diff --git a/fs/proc/base.c b/fs/proc/base.c |
521ced18 | 292 | index c87b6b9..6b71643 100644 |
c1595e42 JR |
293 | --- a/fs/proc/base.c |
294 | +++ b/fs/proc/base.c | |
521ced18 | 295 | @@ -1946,7 +1946,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path) |
c1595e42 JR |
296 | down_read(&mm->mmap_sem); |
297 | vma = find_exact_vma(mm, vm_start, vm_end); | |
298 | if (vma && vma->vm_file) { | |
299 | - *path = vma->vm_file->f_path; | |
300 | + *path = vma_pr_or_file(vma)->f_path; | |
301 | path_get(path); | |
302 | rc = 0; | |
303 | } | |
fb47a38f | 304 | diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c |
a2654f78 | 305 | index 7563437..7c0dc0f 100644 |
fb47a38f JR |
306 | --- a/fs/proc/nommu.c |
307 | +++ b/fs/proc/nommu.c | |
076b876e | 308 | @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region) |
fb47a38f JR |
309 | file = region->vm_file; |
310 | ||
311 | if (file) { | |
312 | - struct inode *inode = file_inode(region->vm_file); | |
313 | + struct inode *inode; | |
076b876e | 314 | + |
fb47a38f JR |
315 | + file = vmr_pr_or_file(region); |
316 | + inode = file_inode(file); | |
317 | dev = inode->i_sb->s_dev; | |
318 | ino = inode->i_ino; | |
319 | } | |
320 | diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c | |
521ced18 | 321 | index f08bd31..e1b9a37 100644 |
fb47a38f JR |
322 | --- a/fs/proc/task_mmu.c |
323 | +++ b/fs/proc/task_mmu.c | |
521ced18 | 324 | @@ -292,7 +292,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) |
fb47a38f JR |
325 | const char *name = NULL; |
326 | ||
327 | if (file) { | |
328 | - struct inode *inode = file_inode(vma->vm_file); | |
329 | + struct inode *inode; | |
076b876e | 330 | + |
fb47a38f JR |
331 | + file = vma_pr_or_file(vma); |
332 | + inode = file_inode(file); | |
333 | dev = inode->i_sb->s_dev; | |
334 | ino = inode->i_ino; | |
335 | pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; | |
521ced18 | 336 | @@ -1629,7 +1632,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid) |
076b876e AM |
337 | struct proc_maps_private *proc_priv = &numa_priv->proc_maps; |
338 | struct vm_area_struct *vma = v; | |
339 | struct numa_maps *md = &numa_priv->md; | |
340 | - struct file *file = vma->vm_file; | |
341 | + struct file *file = vma_pr_or_file(vma); | |
076b876e | 342 | struct mm_struct *mm = vma->vm_mm; |
7e9cd9fe AM |
343 | struct mm_walk walk = { |
344 | .hugetlb_entry = gather_hugetlb_stats, | |
fb47a38f | 345 | diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c |
521ced18 | 346 | index 23266694..58e59b6 100644 |
fb47a38f JR |
347 | --- a/fs/proc/task_nommu.c |
348 | +++ b/fs/proc/task_nommu.c | |
521ced18 | 349 | @@ -157,7 +157,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma, |
fb47a38f JR |
350 | file = vma->vm_file; |
351 | ||
352 | if (file) { | |
353 | - struct inode *inode = file_inode(vma->vm_file); | |
354 | + struct inode *inode; | |
076b876e | 355 | + |
b912730e | 356 | + file = vma_pr_or_file(vma); |
fb47a38f JR |
357 | + inode = file_inode(file); |
358 | dev = inode->i_sb->s_dev; | |
359 | ino = inode->i_ino; | |
360 | pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT; | |
361 | diff --git a/include/linux/mm.h b/include/linux/mm.h | |
521ced18 | 362 | index 00a8fa7..a90742b 100644 |
fb47a38f JR |
363 | --- a/include/linux/mm.h |
364 | +++ b/include/linux/mm.h | |
521ced18 | 365 | @@ -1294,6 +1294,28 @@ static inline int fixup_user_fault(struct task_struct *tsk, |
fb47a38f JR |
366 | } |
367 | #endif | |
368 | ||
076b876e AM |
369 | +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int); |
370 | +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[], | |
f2c43d5f | 371 | + int); |
076b876e AM |
372 | +extern void vma_do_get_file(struct vm_area_struct *, const char[], int); |
373 | +extern void vma_do_fput(struct vm_area_struct *, const char[], int); | |
fb47a38f | 374 | + |
f2c43d5f AM |
375 | +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \ |
376 | + __LINE__) | |
377 | +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \ | |
378 | + __LINE__) | |
379 | +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__) | |
380 | +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__) | |
b912730e AM |
381 | + |
382 | +#ifndef CONFIG_MMU | |
076b876e AM |
383 | +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int); |
384 | +extern void vmr_do_fput(struct vm_region *, const char[], int); | |
385 | + | |
f2c43d5f AM |
386 | +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \ |
387 | + __LINE__) | |
388 | +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__) | |
b912730e | 389 | +#endif /* !CONFIG_MMU */ |
fb47a38f | 390 | + |
106341ce AM |
391 | extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, |
392 | unsigned int gup_flags); | |
fb47a38f | 393 | extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, |
fb47a38f | 394 | diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h |
521ced18 | 395 | index f60f45f..38c5f76 100644 |
fb47a38f JR |
396 | --- a/include/linux/mm_types.h |
397 | +++ b/include/linux/mm_types.h | |
521ced18 | 398 | @@ -259,6 +259,7 @@ struct vm_region { |
fb47a38f JR |
399 | unsigned long vm_top; /* region allocated to here */ |
400 | unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */ | |
401 | struct file *vm_file; /* the backing file or NULL */ | |
402 | + struct file *vm_prfile; /* the virtual backing file or NULL */ | |
403 | ||
404 | int vm_usage; /* region usage count (access under nommu_region_sem) */ | |
405 | bool vm_icache_flushed : 1; /* true if the icache has been flushed for | |
521ced18 | 406 | @@ -333,6 +334,7 @@ struct vm_area_struct { |
fb47a38f | 407 | unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE |
5afbbe0d | 408 | units */ |
fb47a38f JR |
409 | struct file * vm_file; /* File we map to (can be NULL). */ |
410 | + struct file *vm_prfile; /* shadow of vm_file */ | |
411 | void * vm_private_data; /* was vm_pte (shared mem) */ | |
412 | ||
413 | #ifndef CONFIG_MMU | |
414 | diff --git a/kernel/fork.c b/kernel/fork.c | |
521ced18 | 415 | index 6c463c80..24ae37c 100644 |
fb47a38f JR |
416 | --- a/kernel/fork.c |
417 | +++ b/kernel/fork.c | |
521ced18 | 418 | @@ -641,7 +641,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, |
fb47a38f JR |
419 | struct inode *inode = file_inode(file); |
420 | struct address_space *mapping = file->f_mapping; | |
421 | ||
422 | - get_file(file); | |
423 | + vma_get_file(tmp); | |
424 | if (tmp->vm_flags & VM_DENYWRITE) | |
425 | atomic_dec(&inode->i_writecount); | |
2000de60 | 426 | i_mmap_lock_write(mapping); |
076b876e | 427 | diff --git a/mm/Makefile b/mm/Makefile |
521ced18 | 428 | index 026f6a8..723da17 100644 |
076b876e AM |
429 | --- a/mm/Makefile |
430 | +++ b/mm/Makefile | |
521ced18 | 431 | @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \ |
076b876e | 432 | mm_init.o mmu_context.o percpu.o slab_common.o \ |
521ced18 | 433 | compaction.o vmacache.o swap_slots.o \ |
076b876e | 434 | interval_tree.o list_lru.o workingset.o \ |
7e9cd9fe AM |
435 | - debug.o $(mmu-y) |
436 | + prfile.o debug.o $(mmu-y) | |
076b876e AM |
437 | |
438 | obj-y += init-mm.o | |
439 | ||
fb47a38f | 440 | diff --git a/mm/filemap.c b/mm/filemap.c |
521ced18 | 441 | index 1694623..68cd758 100644 |
fb47a38f JR |
442 | --- a/mm/filemap.c |
443 | +++ b/mm/filemap.c | |
521ced18 | 444 | @@ -2406,7 +2406,7 @@ int filemap_page_mkwrite(struct vm_fault *vmf) |
fb47a38f JR |
445 | int ret = VM_FAULT_LOCKED; |
446 | ||
447 | sb_start_pagefault(inode->i_sb); | |
521ced18 JR |
448 | - file_update_time(vmf->vma->vm_file); |
449 | + vma_file_update_time(vmf->vma); | |
fb47a38f JR |
450 | lock_page(page); |
451 | if (page->mapping != inode->i_mapping) { | |
452 | unlock_page(page); | |
fb47a38f | 453 | diff --git a/mm/mmap.c b/mm/mmap.c |
521ced18 | 454 | index bfbe885..8bd32f9 100644 |
fb47a38f JR |
455 | --- a/mm/mmap.c |
456 | +++ b/mm/mmap.c | |
f2c43d5f | 457 | @@ -170,7 +170,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma) |
fb47a38f JR |
458 | if (vma->vm_ops && vma->vm_ops->close) |
459 | vma->vm_ops->close(vma); | |
460 | if (vma->vm_file) | |
461 | - fput(vma->vm_file); | |
462 | + vma_fput(vma); | |
463 | mpol_put(vma_policy(vma)); | |
464 | kmem_cache_free(vm_area_cachep, vma); | |
465 | return next; | |
521ced18 | 466 | @@ -881,7 +881,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, |
fb47a38f JR |
467 | if (remove_next) { |
468 | if (file) { | |
469 | uprobe_munmap(next, next->vm_start, next->vm_end); | |
470 | - fput(file); | |
471 | + vma_fput(vma); | |
472 | } | |
473 | if (next->anon_vma) | |
474 | anon_vma_merge(vma, next); | |
521ced18 | 475 | @@ -1731,8 +1731,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, |
35939ee7 JR |
476 | return addr; |
477 | ||
fb47a38f | 478 | unmap_and_free_vma: |
fb47a38f JR |
479 | + vma_fput(vma); |
480 | vma->vm_file = NULL; | |
481 | - fput(file); | |
482 | ||
483 | /* Undo any partial mapping done by a device driver. */ | |
484 | unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); | |
521ced18 | 485 | @@ -2537,7 +2537,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
486 | goto out_free_mpol; |
487 | ||
488 | if (new->vm_file) | |
489 | - get_file(new->vm_file); | |
490 | + vma_get_file(new); | |
491 | ||
492 | if (new->vm_ops && new->vm_ops->open) | |
493 | new->vm_ops->open(new); | |
521ced18 | 494 | @@ -2556,7 +2556,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
495 | if (new->vm_ops && new->vm_ops->close) |
496 | new->vm_ops->close(new); | |
497 | if (new->vm_file) | |
498 | - fput(new->vm_file); | |
499 | + vma_fput(new); | |
500 | unlink_anon_vmas(new); | |
501 | out_free_mpol: | |
502 | mpol_put(vma_policy(new)); | |
521ced18 | 503 | @@ -2710,7 +2710,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
7e9cd9fe AM |
504 | struct vm_area_struct *vma; |
505 | unsigned long populate = 0; | |
506 | unsigned long ret = -EINVAL; | |
507 | - struct file *file; | |
5afbbe0d | 508 | + struct file *file, *prfile; |
7e9cd9fe | 509 | |
5afbbe0d AM |
510 | pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n", |
511 | current->comm, current->pid); | |
521ced18 | 512 | @@ -2785,10 +2785,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
febd17d6 | 513 | } |
7e9cd9fe AM |
514 | } |
515 | ||
516 | - file = get_file(vma->vm_file); | |
517 | + vma_get_file(vma); | |
5afbbe0d AM |
518 | + file = vma->vm_file; |
519 | + prfile = vma->vm_prfile; | |
7e9cd9fe | 520 | ret = do_mmap_pgoff(vma->vm_file, start, size, |
521ced18 | 521 | prot, flags, pgoff, &populate, NULL); |
5afbbe0d AM |
522 | + if (!IS_ERR_VALUE(ret) && file && prfile) { |
523 | + struct vm_area_struct *new_vma; | |
524 | + | |
525 | + new_vma = find_vma(mm, ret); | |
526 | + if (!new_vma->vm_prfile) | |
527 | + new_vma->vm_prfile = prfile; | |
528 | + if (new_vma != vma) | |
529 | + get_file(prfile); | |
530 | + } | |
531 | + /* | |
532 | + * two fput()s instead of vma_fput(vma), | |
533 | + * coz vma may not be available anymore. | |
534 | + */ | |
535 | fput(file); | |
536 | + if (prfile) | |
537 | + fput(prfile); | |
7e9cd9fe AM |
538 | out: |
539 | up_write(&mm->mmap_sem); | |
540 | if (populate) | |
521ced18 | 541 | @@ -3079,7 +3096,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, |
79b8bda9 AM |
542 | if (anon_vma_clone(new_vma, vma)) |
543 | goto out_free_mempol; | |
544 | if (new_vma->vm_file) | |
545 | - get_file(new_vma->vm_file); | |
546 | + vma_get_file(new_vma); | |
547 | if (new_vma->vm_ops && new_vma->vm_ops->open) | |
548 | new_vma->vm_ops->open(new_vma); | |
549 | vma_link(mm, new_vma, prev, rb_link, rb_parent); | |
fb47a38f | 550 | diff --git a/mm/nommu.c b/mm/nommu.c |
521ced18 | 551 | index 2d131b9..5dc9a19 100644 |
fb47a38f JR |
552 | --- a/mm/nommu.c |
553 | +++ b/mm/nommu.c | |
521ced18 | 554 | @@ -637,7 +637,7 @@ static void __put_nommu_region(struct vm_region *region) |
fb47a38f JR |
555 | up_write(&nommu_region_sem); |
556 | ||
557 | if (region->vm_file) | |
558 | - fput(region->vm_file); | |
559 | + vmr_fput(region); | |
560 | ||
561 | /* IO memory and memory shared directly out of the pagecache | |
562 | * from ramfs/tmpfs mustn't be released here */ | |
521ced18 | 563 | @@ -795,7 +795,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) |
fb47a38f JR |
564 | if (vma->vm_ops && vma->vm_ops->close) |
565 | vma->vm_ops->close(vma); | |
566 | if (vma->vm_file) | |
567 | - fput(vma->vm_file); | |
568 | + vma_fput(vma); | |
569 | put_nommu_region(vma->vm_region); | |
570 | kmem_cache_free(vm_area_cachep, vma); | |
571 | } | |
521ced18 | 572 | @@ -1322,7 +1322,7 @@ unsigned long do_mmap(struct file *file, |
fb47a38f JR |
573 | goto error_just_free; |
574 | } | |
575 | } | |
576 | - fput(region->vm_file); | |
577 | + vmr_fput(region); | |
578 | kmem_cache_free(vm_region_jar, region); | |
579 | region = pregion; | |
580 | result = start; | |
521ced18 | 581 | @@ -1397,10 +1397,10 @@ unsigned long do_mmap(struct file *file, |
fb47a38f JR |
582 | up_write(&nommu_region_sem); |
583 | error: | |
584 | if (region->vm_file) | |
585 | - fput(region->vm_file); | |
586 | + vmr_fput(region); | |
587 | kmem_cache_free(vm_region_jar, region); | |
588 | if (vma->vm_file) | |
589 | - fput(vma->vm_file); | |
590 | + vma_fput(vma); | |
591 | kmem_cache_free(vm_area_cachep, vma); | |
fb47a38f | 592 | return ret; |
c2c0f25c | 593 | |
076b876e AM |
594 | diff --git a/mm/prfile.c b/mm/prfile.c |
595 | new file mode 100644 | |
c2c0f25c | 596 | index 0000000..b323b8a |
076b876e AM |
597 | --- /dev/null |
598 | +++ b/mm/prfile.c | |
599 | @@ -0,0 +1,86 @@ | |
600 | +/* | |
601 | + * Mainly for aufs which mmap(2) diffrent file and wants to print different path | |
602 | + * in /proc/PID/maps. | |
603 | + * Call these functions via macros defined in linux/mm.h. | |
604 | + * | |
605 | + * See Documentation/filesystems/aufs/design/06mmap.txt | |
606 | + * | |
607 | + * Copyright (c) 2014 Junjro R. Okajima | |
608 | + * Copyright (c) 2014 Ian Campbell | |
609 | + */ | |
610 | + | |
611 | +#include <linux/mm.h> | |
612 | +#include <linux/file.h> | |
613 | +#include <linux/fs.h> | |
614 | + | |
615 | +/* #define PRFILE_TRACE */ | |
616 | +static inline void prfile_trace(struct file *f, struct file *pr, | |
617 | + const char func[], int line, const char func2[]) | |
618 | +{ | |
619 | +#ifdef PRFILE_TRACE | |
620 | + if (pr) | |
c2c0f25c | 621 | + pr_info("%s:%d: %s, %s\n", func, line, func2, |
7e9cd9fe | 622 | + f ? (char *)f->f_path.dentry->d_name.name : "(null)"); |
076b876e AM |
623 | +#endif |
624 | +} | |
625 | + | |
076b876e AM |
626 | +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[], |
627 | + int line) | |
628 | +{ | |
629 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
630 | + | |
631 | + prfile_trace(f, pr, func, line, __func__); | |
632 | + file_update_time(f); | |
633 | + if (f && pr) | |
634 | + file_update_time(pr); | |
635 | +} | |
636 | + | |
637 | +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[], | |
638 | + int line) | |
639 | +{ | |
640 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
641 | + | |
642 | + prfile_trace(f, pr, func, line, __func__); | |
643 | + return (f && pr) ? pr : f; | |
644 | +} | |
645 | + | |
646 | +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line) | |
647 | +{ | |
648 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
649 | + | |
650 | + prfile_trace(f, pr, func, line, __func__); | |
651 | + get_file(f); | |
652 | + if (f && pr) | |
653 | + get_file(pr); | |
654 | +} | |
655 | + | |
656 | +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line) | |
657 | +{ | |
658 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
659 | + | |
660 | + prfile_trace(f, pr, func, line, __func__); | |
661 | + fput(f); | |
662 | + if (f && pr) | |
663 | + fput(pr); | |
664 | +} | |
b912730e AM |
665 | + |
666 | +#ifndef CONFIG_MMU | |
076b876e AM |
667 | +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[], |
668 | + int line) | |
669 | +{ | |
670 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
671 | + | |
672 | + prfile_trace(f, pr, func, line, __func__); | |
673 | + return (f && pr) ? pr : f; | |
674 | +} | |
675 | + | |
676 | +void vmr_do_fput(struct vm_region *region, const char func[], int line) | |
677 | +{ | |
678 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
679 | + | |
680 | + prfile_trace(f, pr, func, line, __func__); | |
681 | + fput(f); | |
682 | + if (f && pr) | |
683 | + fput(pr); | |
684 | +} | |
b912730e | 685 | +#endif /* !CONFIG_MMU */ |
a2654f78 | 686 | aufs4.x-rcN standalone patch |
7f207e10 | 687 | |
c1595e42 | 688 | diff --git a/fs/dcache.c b/fs/dcache.c |
a2654f78 | 689 | index 8ca5f09..b1ff5be 100644 |
c1595e42 JR |
690 | --- a/fs/dcache.c |
691 | +++ b/fs/dcache.c | |
f2c43d5f | 692 | @@ -1272,6 +1272,7 @@ void d_walk(struct dentry *parent, void *data, |
c1595e42 JR |
693 | seq = 1; |
694 | goto again; | |
695 | } | |
febd17d6 | 696 | +EXPORT_SYMBOL_GPL(d_walk); |
c1595e42 | 697 | |
a2654f78 AM |
698 | struct check_mount { |
699 | struct vfsmount *mnt; | |
700 | @@ -2864,6 +2865,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2) | |
f2c43d5f AM |
701 | |
702 | write_sequnlock(&rename_lock); | |
703 | } | |
704 | +EXPORT_SYMBOL_GPL(d_exchange); | |
705 | ||
706 | /** | |
707 | * d_ancestor - search for an ancestor | |
79b8bda9 | 708 | diff --git a/fs/exec.c b/fs/exec.c |
521ced18 | 709 | index 65145a3..8d35776 100644 |
79b8bda9 AM |
710 | --- a/fs/exec.c |
711 | +++ b/fs/exec.c | |
521ced18 | 712 | @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path) |
79b8bda9 AM |
713 | return (path->mnt->mnt_flags & MNT_NOEXEC) || |
714 | (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC); | |
715 | } | |
febd17d6 | 716 | +EXPORT_SYMBOL_GPL(path_noexec); |
79b8bda9 AM |
717 | |
718 | #ifdef CONFIG_USELIB | |
719 | /* | |
febd17d6 | 720 | diff --git a/fs/fcntl.c b/fs/fcntl.c |
521ced18 | 721 | index f5f4f94..c671660 100644 |
febd17d6 JR |
722 | --- a/fs/fcntl.c |
723 | +++ b/fs/fcntl.c | |
521ced18 | 724 | @@ -83,6 +83,7 @@ int setfl(int fd, struct file * filp, unsigned long arg) |
febd17d6 JR |
725 | out: |
726 | return error; | |
727 | } | |
728 | +EXPORT_SYMBOL_GPL(setfl); | |
729 | ||
730 | static void f_modown(struct file *filp, struct pid *pid, enum pid_type type, | |
731 | int force) | |
b912730e | 732 | diff --git a/fs/file_table.c b/fs/file_table.c |
521ced18 | 733 | index 954d510..4fb5b10 100644 |
b912730e AM |
734 | --- a/fs/file_table.c |
735 | +++ b/fs/file_table.c | |
521ced18 | 736 | @@ -148,6 +148,7 @@ struct file *get_empty_filp(void) |
b912730e AM |
737 | } |
738 | return ERR_PTR(-ENFILE); | |
739 | } | |
febd17d6 | 740 | +EXPORT_SYMBOL_GPL(get_empty_filp); |
b912730e AM |
741 | |
742 | /** | |
743 | * alloc_file - allocate and initialize a 'struct file' | |
521ced18 | 744 | @@ -259,6 +260,7 @@ void flush_delayed_fput(void) |
8cdd5066 JR |
745 | { |
746 | delayed_fput(NULL); | |
747 | } | |
febd17d6 | 748 | +EXPORT_SYMBOL_GPL(flush_delayed_fput); |
8cdd5066 JR |
749 | |
750 | static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput); | |
751 | ||
521ced18 | 752 | @@ -301,6 +303,7 @@ void __fput_sync(struct file *file) |
8cdd5066 JR |
753 | } |
754 | ||
755 | EXPORT_SYMBOL(fput); | |
febd17d6 | 756 | +EXPORT_SYMBOL_GPL(__fput_sync); |
8cdd5066 JR |
757 | |
758 | void put_filp(struct file *file) | |
759 | { | |
521ced18 | 760 | @@ -309,6 +312,7 @@ void put_filp(struct file *file) |
b912730e AM |
761 | file_free(file); |
762 | } | |
763 | } | |
febd17d6 | 764 | +EXPORT_SYMBOL_GPL(put_filp); |
b912730e | 765 | |
79b8bda9 | 766 | void __init files_init(void) |
b912730e | 767 | { |
5afbbe0d | 768 | diff --git a/fs/inode.c b/fs/inode.c |
f2c43d5f | 769 | index 9a9ba3a..a3a18d8 100644 |
5afbbe0d AM |
770 | --- a/fs/inode.c |
771 | +++ b/fs/inode.c | |
f2c43d5f | 772 | @@ -1651,6 +1651,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags) |
5afbbe0d AM |
773 | |
774 | return update_time(inode, time, flags); | |
775 | } | |
776 | +EXPORT_SYMBOL_GPL(update_time); | |
777 | ||
778 | /** | |
779 | * touch_atime - update the access time | |
7f207e10 | 780 | diff --git a/fs/namespace.c b/fs/namespace.c |
521ced18 | 781 | index cc1375ef..9b4c67c 100644 |
7f207e10 AM |
782 | --- a/fs/namespace.c |
783 | +++ b/fs/namespace.c | |
521ced18 | 784 | @@ -465,6 +465,7 @@ void __mnt_drop_write(struct vfsmount *mnt) |
c06a8ce3 AM |
785 | mnt_dec_writers(real_mount(mnt)); |
786 | preempt_enable(); | |
787 | } | |
788 | +EXPORT_SYMBOL_GPL(__mnt_drop_write); | |
789 | ||
790 | /** | |
791 | * mnt_drop_write - give up write access to a mount | |
521ced18 | 792 | @@ -1884,6 +1885,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, |
7f207e10 AM |
793 | } |
794 | return 0; | |
795 | } | |
febd17d6 | 796 | +EXPORT_SYMBOL_GPL(iterate_mounts); |
7f207e10 | 797 | |
7eafdf33 | 798 | static void cleanup_group_ids(struct mount *mnt, struct mount *end) |
7f207e10 AM |
799 | { |
800 | diff --git a/fs/notify/group.c b/fs/notify/group.c | |
f2c43d5f | 801 | index fbe3cbe..bdfc61e 100644 |
7f207e10 AM |
802 | --- a/fs/notify/group.c |
803 | +++ b/fs/notify/group.c | |
804 | @@ -22,6 +22,7 @@ | |
805 | #include <linux/srcu.h> | |
806 | #include <linux/rculist.h> | |
807 | #include <linux/wait.h> | |
808 | +#include <linux/module.h> | |
809 | ||
810 | #include <linux/fsnotify_backend.h> | |
811 | #include "fsnotify.h" | |
e2f27e51 | 812 | @@ -100,6 +101,7 @@ void fsnotify_get_group(struct fsnotify_group *group) |
1716fcea AM |
813 | { |
814 | atomic_inc(&group->refcnt); | |
815 | } | |
febd17d6 | 816 | +EXPORT_SYMBOL_GPL(fsnotify_get_group); |
1716fcea AM |
817 | |
818 | /* | |
819 | * Drop a reference to a group. Free it if it's through. | |
e2f27e51 | 820 | @@ -109,6 +111,7 @@ void fsnotify_put_group(struct fsnotify_group *group) |
7f207e10 | 821 | if (atomic_dec_and_test(&group->refcnt)) |
1716fcea | 822 | fsnotify_final_destroy_group(group); |
7f207e10 | 823 | } |
febd17d6 | 824 | +EXPORT_SYMBOL_GPL(fsnotify_put_group); |
7f207e10 AM |
825 | |
826 | /* | |
827 | * Create a new fsnotify_group and hold a reference for the group returned. | |
e2f27e51 | 828 | @@ -137,6 +140,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) |
7f207e10 AM |
829 | |
830 | return group; | |
831 | } | |
febd17d6 | 832 | +EXPORT_SYMBOL_GPL(fsnotify_alloc_group); |
1716fcea AM |
833 | |
834 | int fsnotify_fasync(int fd, struct file *file, int on) | |
835 | { | |
7f207e10 | 836 | diff --git a/fs/notify/mark.c b/fs/notify/mark.c |
a2654f78 | 837 | index 6043306..fdb50e4 100644 |
7f207e10 AM |
838 | --- a/fs/notify/mark.c |
839 | +++ b/fs/notify/mark.c | |
febd17d6 | 840 | @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) |
7f207e10 | 841 | mark->free_mark(mark); |
1716fcea | 842 | } |
7f207e10 | 843 | } |
febd17d6 | 844 | +EXPORT_SYMBOL_GPL(fsnotify_put_mark); |
7f207e10 | 845 | |
2000de60 JR |
846 | /* Calculate mask of events for a list of marks */ |
847 | u32 fsnotify_recalc_mask(struct hlist_head *head) | |
5afbbe0d | 848 | @@ -230,6 +231,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark, |
1716fcea | 849 | mutex_unlock(&group->mark_mutex); |
79b8bda9 | 850 | fsnotify_free_mark(mark); |
7f207e10 | 851 | } |
febd17d6 | 852 | +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark); |
7f207e10 | 853 | |
79b8bda9 AM |
854 | void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock) |
855 | { | |
f2c43d5f | 856 | @@ -415,6 +417,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, |
7f207e10 AM |
857 | |
858 | return ret; | |
859 | } | |
febd17d6 | 860 | +EXPORT_SYMBOL_GPL(fsnotify_add_mark); |
7f207e10 | 861 | |
1716fcea AM |
862 | int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group, |
863 | struct inode *inode, struct vfsmount *mnt, int allow_dups) | |
a2654f78 | 864 | @@ -521,6 +524,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark, |
7f207e10 AM |
865 | atomic_set(&mark->refcnt, 1); |
866 | mark->free_mark = free_mark; | |
867 | } | |
febd17d6 | 868 | +EXPORT_SYMBOL_GPL(fsnotify_init_mark); |
7f207e10 | 869 | |
5afbbe0d AM |
870 | /* |
871 | * Destroy all marks in destroy_list, waits for SRCU period to finish before | |
7f207e10 | 872 | diff --git a/fs/open.c b/fs/open.c |
521ced18 | 873 | index 949cef2..9a892fb8 100644 |
7f207e10 AM |
874 | --- a/fs/open.c |
875 | +++ b/fs/open.c | |
c2c0f25c | 876 | @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, |
febd17d6 | 877 | inode_unlock(dentry->d_inode); |
7f207e10 AM |
878 | return ret; |
879 | } | |
febd17d6 | 880 | +EXPORT_SYMBOL_GPL(do_truncate); |
7f207e10 | 881 | |
5afbbe0d | 882 | long vfs_truncate(const struct path *path, loff_t length) |
7f207e10 | 883 | { |
521ced18 | 884 | @@ -693,6 +694,7 @@ int open_check_o_direct(struct file *f) |
b912730e AM |
885 | } |
886 | return 0; | |
887 | } | |
febd17d6 | 888 | +EXPORT_SYMBOL_GPL(open_check_o_direct); |
b912730e AM |
889 | |
890 | static int do_dentry_open(struct file *f, | |
c2c0f25c | 891 | struct inode *inode, |
5527c038 | 892 | diff --git a/fs/read_write.c b/fs/read_write.c |
521ced18 | 893 | index ac71b96..b69e687 100644 |
5527c038 JR |
894 | --- a/fs/read_write.c |
895 | +++ b/fs/read_write.c | |
521ced18 | 896 | @@ -523,6 +523,7 @@ vfs_readf_t vfs_readf(struct file *file) |
5527c038 JR |
897 | return new_sync_read; |
898 | return ERR_PTR(-ENOSYS); | |
899 | } | |
febd17d6 | 900 | +EXPORT_SYMBOL_GPL(vfs_readf); |
5527c038 JR |
901 | |
902 | vfs_writef_t vfs_writef(struct file *file) | |
903 | { | |
521ced18 | 904 | @@ -534,6 +535,7 @@ vfs_writef_t vfs_writef(struct file *file) |
5527c038 JR |
905 | return new_sync_write; |
906 | return ERR_PTR(-ENOSYS); | |
907 | } | |
febd17d6 | 908 | +EXPORT_SYMBOL_GPL(vfs_writef); |
5527c038 JR |
909 | |
910 | ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos) | |
911 | { | |
7f207e10 | 912 | diff --git a/fs/splice.c b/fs/splice.c |
521ced18 | 913 | index 46c87af..0efa652 100644 |
7f207e10 AM |
914 | --- a/fs/splice.c |
915 | +++ b/fs/splice.c | |
521ced18 | 916 | @@ -872,6 +872,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
392086de AM |
917 | |
918 | return splice_write(pipe, out, ppos, len, flags); | |
7f207e10 | 919 | } |
febd17d6 | 920 | +EXPORT_SYMBOL_GPL(do_splice_from); |
7f207e10 AM |
921 | |
922 | /* | |
923 | * Attempt to initiate a splice from a file to a pipe. | |
521ced18 | 924 | @@ -901,6 +902,7 @@ long do_splice_to(struct file *in, loff_t *ppos, |
7f207e10 AM |
925 | |
926 | return splice_read(in, ppos, pipe, len, flags); | |
927 | } | |
febd17d6 | 928 | +EXPORT_SYMBOL_GPL(do_splice_to); |
7f207e10 AM |
929 | |
930 | /** | |
931 | * splice_direct_to_actor - splices data directly between two non-pipes | |
a2654f78 | 932 | diff --git a/fs/sync.c b/fs/sync.c |
521ced18 | 933 | index abf6a5d..c86fe9c 100644 |
a2654f78 AM |
934 | --- a/fs/sync.c |
935 | +++ b/fs/sync.c | |
936 | @@ -38,6 +38,7 @@ int __sync_filesystem(struct super_block *sb, int wait) | |
937 | sb->s_op->sync_fs(sb, wait); | |
938 | return __sync_blockdev(sb->s_bdev, wait); | |
939 | } | |
940 | +EXPORT_SYMBOL_GPL(__sync_filesystem); | |
941 | ||
942 | /* | |
943 | * Write out and wait upon all dirty data associated with this | |
c1595e42 | 944 | diff --git a/fs/xattr.c b/fs/xattr.c |
a2654f78 | 945 | index 7e3317c..88910fe 100644 |
c1595e42 JR |
946 | --- a/fs/xattr.c |
947 | +++ b/fs/xattr.c | |
a2654f78 | 948 | @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, |
c1595e42 JR |
949 | *xattr_value = value; |
950 | return error; | |
951 | } | |
febd17d6 | 952 | +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc); |
c1595e42 | 953 | |
febd17d6 | 954 | ssize_t |
f2c43d5f | 955 | __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name, |
8cdd5066 | 956 | diff --git a/kernel/task_work.c b/kernel/task_work.c |
e2f27e51 | 957 | index d513051..e056d54 100644 |
8cdd5066 JR |
958 | --- a/kernel/task_work.c |
959 | +++ b/kernel/task_work.c | |
e2f27e51 | 960 | @@ -119,3 +119,4 @@ void task_work_run(void) |
8cdd5066 JR |
961 | } while (work); |
962 | } | |
963 | } | |
febd17d6 | 964 | +EXPORT_SYMBOL_GPL(task_work_run); |
7f207e10 | 965 | diff --git a/security/commoncap.c b/security/commoncap.c |
521ced18 | 966 | index 78b3783..c8b3e88 100644 |
7f207e10 AM |
967 | --- a/security/commoncap.c |
968 | +++ b/security/commoncap.c | |
521ced18 | 969 | @@ -1062,12 +1062,14 @@ int cap_mmap_addr(unsigned long addr) |
94337f0d | 970 | } |
7f207e10 AM |
971 | return ret; |
972 | } | |
febd17d6 | 973 | +EXPORT_SYMBOL_GPL(cap_mmap_addr); |
0c3ec466 AM |
974 | |
975 | int cap_mmap_file(struct file *file, unsigned long reqprot, | |
976 | unsigned long prot, unsigned long flags) | |
977 | { | |
978 | return 0; | |
979 | } | |
febd17d6 | 980 | +EXPORT_SYMBOL_GPL(cap_mmap_file); |
c2c0f25c AM |
981 | |
982 | #ifdef CONFIG_SECURITY | |
983 | ||
7f207e10 | 984 | diff --git a/security/device_cgroup.c b/security/device_cgroup.c |
febd17d6 | 985 | index 03c1652..f88c84b 100644 |
7f207e10 AM |
986 | --- a/security/device_cgroup.c |
987 | +++ b/security/device_cgroup.c | |
f6c5ef8b AM |
988 | @@ -7,6 +7,7 @@ |
989 | #include <linux/device_cgroup.h> | |
990 | #include <linux/cgroup.h> | |
991 | #include <linux/ctype.h> | |
992 | +#include <linux/export.h> | |
993 | #include <linux/list.h> | |
994 | #include <linux/uaccess.h> | |
995 | #include <linux/seq_file.h> | |
076b876e | 996 | @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask) |
537831f9 AM |
997 | return __devcgroup_check_permission(type, imajor(inode), iminor(inode), |
998 | access); | |
7f207e10 | 999 | } |
febd17d6 | 1000 | +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission); |
7f207e10 AM |
1001 | |
1002 | int devcgroup_inode_mknod(int mode, dev_t dev) | |
1003 | { | |
1004 | diff --git a/security/security.c b/security/security.c | |
521ced18 | 1005 | index d0e07f2..5e323b0 100644 |
7f207e10 AM |
1006 | --- a/security/security.c |
1007 | +++ b/security/security.c | |
521ced18 | 1008 | @@ -481,6 +481,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry) |
7f207e10 | 1009 | return 0; |
c2c0f25c | 1010 | return call_int_hook(path_rmdir, 0, dir, dentry); |
7f207e10 | 1011 | } |
febd17d6 | 1012 | +EXPORT_SYMBOL_GPL(security_path_rmdir); |
7f207e10 | 1013 | |
5afbbe0d | 1014 | int security_path_unlink(const struct path *dir, struct dentry *dentry) |
7f207e10 | 1015 | { |
521ced18 | 1016 | @@ -497,6 +498,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry, |
7f207e10 | 1017 | return 0; |
c2c0f25c | 1018 | return call_int_hook(path_symlink, 0, dir, dentry, old_name); |
7f207e10 | 1019 | } |
febd17d6 | 1020 | +EXPORT_SYMBOL_GPL(security_path_symlink); |
7f207e10 | 1021 | |
5afbbe0d | 1022 | int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
7f207e10 | 1023 | struct dentry *new_dentry) |
521ced18 | 1024 | @@ -505,6 +507,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
7f207e10 | 1025 | return 0; |
c2c0f25c | 1026 | return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry); |
7f207e10 | 1027 | } |
febd17d6 | 1028 | +EXPORT_SYMBOL_GPL(security_path_link); |
7f207e10 | 1029 | |
5afbbe0d AM |
1030 | int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
1031 | const struct path *new_dir, struct dentry *new_dentry, | |
521ced18 | 1032 | @@ -532,6 +535,7 @@ int security_path_truncate(const struct path *path) |
7f207e10 | 1033 | return 0; |
c2c0f25c | 1034 | return call_int_hook(path_truncate, 0, path); |
7f207e10 | 1035 | } |
febd17d6 | 1036 | +EXPORT_SYMBOL_GPL(security_path_truncate); |
7f207e10 | 1037 | |
5afbbe0d | 1038 | int security_path_chmod(const struct path *path, umode_t mode) |
7eafdf33 | 1039 | { |
521ced18 | 1040 | @@ -539,6 +543,7 @@ int security_path_chmod(const struct path *path, umode_t mode) |
7f207e10 | 1041 | return 0; |
c2c0f25c | 1042 | return call_int_hook(path_chmod, 0, path, mode); |
7f207e10 | 1043 | } |
febd17d6 | 1044 | +EXPORT_SYMBOL_GPL(security_path_chmod); |
7f207e10 | 1045 | |
5afbbe0d | 1046 | int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 1047 | { |
521ced18 | 1048 | @@ -546,6 +551,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 1049 | return 0; |
c2c0f25c | 1050 | return call_int_hook(path_chown, 0, path, uid, gid); |
7f207e10 | 1051 | } |
febd17d6 | 1052 | +EXPORT_SYMBOL_GPL(security_path_chown); |
7f207e10 | 1053 | |
5afbbe0d | 1054 | int security_path_chroot(const struct path *path) |
7f207e10 | 1055 | { |
521ced18 | 1056 | @@ -631,6 +637,7 @@ int security_inode_readlink(struct dentry *dentry) |
7f207e10 | 1057 | return 0; |
c2c0f25c | 1058 | return call_int_hook(inode_readlink, 0, dentry); |
7f207e10 | 1059 | } |
febd17d6 | 1060 | +EXPORT_SYMBOL_GPL(security_inode_readlink); |
7f207e10 | 1061 | |
c2c0f25c AM |
1062 | int security_inode_follow_link(struct dentry *dentry, struct inode *inode, |
1063 | bool rcu) | |
521ced18 | 1064 | @@ -646,6 +653,7 @@ int security_inode_permission(struct inode *inode, int mask) |
7f207e10 | 1065 | return 0; |
c2c0f25c | 1066 | return call_int_hook(inode_permission, 0, inode, mask); |
7f207e10 | 1067 | } |
febd17d6 | 1068 | +EXPORT_SYMBOL_GPL(security_inode_permission); |
7f207e10 | 1069 | |
1e00d052 | 1070 | int security_inode_setattr(struct dentry *dentry, struct iattr *attr) |
7f207e10 | 1071 | { |
521ced18 | 1072 | @@ -817,6 +825,7 @@ int security_file_permission(struct file *file, int mask) |
7f207e10 AM |
1073 | |
1074 | return fsnotify_perm(file, mask); | |
1075 | } | |
febd17d6 | 1076 | +EXPORT_SYMBOL_GPL(security_file_permission); |
7f207e10 AM |
1077 | |
1078 | int security_file_alloc(struct file *file) | |
1079 | { | |
521ced18 | 1080 | @@ -876,6 +885,7 @@ int security_mmap_file(struct file *file, unsigned long prot, |
7f207e10 AM |
1081 | return ret; |
1082 | return ima_file_mmap(file, prot); | |
1083 | } | |
febd17d6 | 1084 | +EXPORT_SYMBOL_GPL(security_mmap_file); |
7f207e10 | 1085 | |
0c3ec466 AM |
1086 | int security_mmap_addr(unsigned long addr) |
1087 | { | |
7f207e10 AM |
1088 | diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs |
1089 | --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1090 | +++ linux/Documentation/ABI/testing/debugfs-aufs 2017-05-06 22:16:52.774886674 +0200 |
86dc4139 | 1091 | @@ -0,0 +1,50 @@ |
7f207e10 AM |
1092 | +What: /debug/aufs/si_<id>/ |
1093 | +Date: March 2009 | |
f6b6e03d | 1094 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1095 | +Description: |
1096 | + Under /debug/aufs, a directory named si_<id> is created | |
1097 | + per aufs mount, where <id> is a unique id generated | |
1098 | + internally. | |
1facf9fc | 1099 | + |
86dc4139 AM |
1100 | +What: /debug/aufs/si_<id>/plink |
1101 | +Date: Apr 2013 | |
f6b6e03d | 1102 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
86dc4139 AM |
1103 | +Description: |
1104 | + It has three lines and shows the information about the | |
1105 | + pseudo-link. The first line is a single number | |
1106 | + representing a number of buckets. The second line is a | |
1107 | + number of pseudo-links per buckets (separated by a | |
1108 | + blank). The last line is a single number representing a | |
1109 | + total number of psedo-links. | |
1110 | + When the aufs mount option 'noplink' is specified, it | |
1111 | + will show "1\n0\n0\n". | |
1112 | + | |
7f207e10 AM |
1113 | +What: /debug/aufs/si_<id>/xib |
1114 | +Date: March 2009 | |
f6b6e03d | 1115 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1116 | +Description: |
1117 | + It shows the consumed blocks by xib (External Inode Number | |
1118 | + Bitmap), its block size and file size. | |
1119 | + When the aufs mount option 'noxino' is specified, it | |
1120 | + will be empty. About XINO files, see the aufs manual. | |
1121 | + | |
1122 | +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN | |
1123 | +Date: March 2009 | |
f6b6e03d | 1124 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1125 | +Description: |
1126 | + It shows the consumed blocks by xino (External Inode Number | |
1127 | + Translation Table), its link count, block size and file | |
1128 | + size. | |
1129 | + When the aufs mount option 'noxino' is specified, it | |
1130 | + will be empty. About XINO files, see the aufs manual. | |
1131 | + | |
1132 | +What: /debug/aufs/si_<id>/xigen | |
1133 | +Date: March 2009 | |
f6b6e03d | 1134 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1135 | +Description: |
1136 | + It shows the consumed blocks by xigen (External Inode | |
1137 | + Generation Table), its block size and file size. | |
1138 | + If CONFIG_AUFS_EXPORT is disabled, this entry will not | |
1139 | + be created. | |
1140 | + When the aufs mount option 'noxino' is specified, it | |
1141 | + will be empty. About XINO files, see the aufs manual. | |
1142 | diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs | |
1143 | --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1144 | +++ linux/Documentation/ABI/testing/sysfs-aufs 2017-05-06 22:16:52.774886674 +0200 |
392086de | 1145 | @@ -0,0 +1,31 @@ |
7f207e10 AM |
1146 | +What: /sys/fs/aufs/si_<id>/ |
1147 | +Date: March 2009 | |
f6b6e03d | 1148 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1149 | +Description: |
1150 | + Under /sys/fs/aufs, a directory named si_<id> is created | |
1151 | + per aufs mount, where <id> is a unique id generated | |
1152 | + internally. | |
1153 | + | |
1154 | +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN | |
1155 | +Date: March 2009 | |
f6b6e03d | 1156 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1157 | +Description: |
1158 | + It shows the abolute path of a member directory (which | |
1159 | + is called branch) in aufs, and its permission. | |
1160 | + | |
392086de AM |
1161 | +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN |
1162 | +Date: July 2013 | |
f6b6e03d | 1163 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
392086de AM |
1164 | +Description: |
1165 | + It shows the id of a member directory (which is called | |
1166 | + branch) in aufs. | |
1167 | + | |
7f207e10 AM |
1168 | +What: /sys/fs/aufs/si_<id>/xi_path |
1169 | +Date: March 2009 | |
f6b6e03d | 1170 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1171 | +Description: |
1172 | + It shows the abolute path of XINO (External Inode Number | |
1173 | + Bitmap, Translation Table and Generation Table) file | |
1174 | + even if it is the default path. | |
1175 | + When the aufs mount option 'noxino' is specified, it | |
1176 | + will be empty. About XINO files, see the aufs manual. | |
53392da6 AM |
1177 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt |
1178 | --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1179 | +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2017-05-06 22:16:52.774886674 +0200 |
7e9cd9fe | 1180 | @@ -0,0 +1,170 @@ |
53392da6 | 1181 | + |
a2654f78 | 1182 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1183 | +# |
1184 | +# This program is free software; you can redistribute it and/or modify | |
1185 | +# it under the terms of the GNU General Public License as published by | |
1186 | +# the Free Software Foundation; either version 2 of the License, or | |
1187 | +# (at your option) any later version. | |
1188 | +# | |
1189 | +# This program is distributed in the hope that it will be useful, | |
1190 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1191 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1192 | +# GNU General Public License for more details. | |
1193 | +# | |
1194 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1195 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1196 | + |
1197 | +Introduction | |
1198 | +---------------------------------------- | |
1199 | + | |
1200 | +aufs [ei ju: ef es] | [a u f s] | |
1201 | +1. abbrev. for "advanced multi-layered unification filesystem". | |
1202 | +2. abbrev. for "another unionfs". | |
1203 | +3. abbrev. for "auf das" in German which means "on the" in English. | |
1204 | + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E). | |
1205 | + But "Filesystem aufs Filesystem" is hard to understand. | |
1206 | + | |
1207 | +AUFS is a filesystem with features: | |
1208 | +- multi layered stackable unification filesystem, the member directory | |
1209 | + is called as a branch. | |
1210 | +- branch permission and attribute, 'readonly', 'real-readonly', | |
7e9cd9fe | 1211 | + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their |
53392da6 AM |
1212 | + combination. |
1213 | +- internal "file copy-on-write". | |
1214 | +- logical deletion, whiteout. | |
1215 | +- dynamic branch manipulation, adding, deleting and changing permission. | |
1216 | +- allow bypassing aufs, user's direct branch access. | |
1217 | +- external inode number translation table and bitmap which maintains the | |
1218 | + persistent aufs inode number. | |
1219 | +- seekable directory, including NFS readdir. | |
1220 | +- file mapping, mmap and sharing pages. | |
1221 | +- pseudo-link, hardlink over branches. | |
1222 | +- loopback mounted filesystem as a branch. | |
1223 | +- several policies to select one among multiple writable branches. | |
1224 | +- revert a single systemcall when an error occurs in aufs. | |
1225 | +- and more... | |
1226 | + | |
1227 | + | |
1228 | +Multi Layered Stackable Unification Filesystem | |
1229 | +---------------------------------------------------------------------- | |
1230 | +Most people already knows what it is. | |
1231 | +It is a filesystem which unifies several directories and provides a | |
1232 | +merged single directory. When users access a file, the access will be | |
1233 | +passed/re-directed/converted (sorry, I am not sure which English word is | |
1234 | +correct) to the real file on the member filesystem. The member | |
1235 | +filesystem is called 'lower filesystem' or 'branch' and has a mode | |
1236 | +'readonly' and 'readwrite.' And the deletion for a file on the lower | |
1237 | +readonly branch is handled by creating 'whiteout' on the upper writable | |
1238 | +branch. | |
1239 | + | |
1240 | +On LKML, there have been discussions about UnionMount (Jan Blunck, | |
1241 | +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took | |
1242 | +different approaches to implement the merged-view. | |
1243 | +The former tries putting it into VFS, and the latter implements as a | |
1244 | +separate filesystem. | |
1245 | +(If I misunderstand about these implementations, please let me know and | |
1246 | +I shall correct it. Because it is a long time ago when I read their | |
1247 | +source files last time). | |
1248 | + | |
1249 | +UnionMount's approach will be able to small, but may be hard to share | |
1250 | +branches between several UnionMount since the whiteout in it is | |
1251 | +implemented in the inode on branch filesystem and always | |
1252 | +shared. According to Bharata's post, readdir does not seems to be | |
1253 | +finished yet. | |
1254 | +There are several missing features known in this implementations such as | |
1255 | +- for users, the inode number may change silently. eg. copy-up. | |
1256 | +- link(2) may break by copy-up. | |
1257 | +- read(2) may get an obsoleted filedata (fstat(2) too). | |
1258 | +- fcntl(F_SETLK) may be broken by copy-up. | |
1259 | +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after | |
1260 | + open(O_RDWR). | |
1261 | + | |
7e9cd9fe AM |
1262 | +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was |
1263 | +merged into mainline. This is another implementation of UnionMount as a | |
1264 | +separated filesystem. All the limitations and known problems which | |
1265 | +UnionMount are equally inherited to "overlay" filesystem. | |
1266 | + | |
1267 | +Unionfs has a longer history. When I started implementing a stackable | |
1268 | +filesystem (Aug 2005), it already existed. It has virtual super_block, | |
1269 | +inode, dentry and file objects and they have an array pointing lower | |
1270 | +same kind objects. After contributing many patches for Unionfs, I | |
1271 | +re-started my project AUFS (Jun 2006). | |
53392da6 AM |
1272 | + |
1273 | +In AUFS, the structure of filesystem resembles to Unionfs, but I | |
1274 | +implemented my own ideas, approaches and enhancements and it became | |
1275 | +totally different one. | |
1276 | + | |
1277 | +Comparing DM snapshot and fs based implementation | |
1278 | +- the number of bytes to be copied between devices is much smaller. | |
1279 | +- the type of filesystem must be one and only. | |
1280 | +- the fs must be writable, no readonly fs, even for the lower original | |
1281 | + device. so the compression fs will not be usable. but if we use | |
1282 | + loopback mount, we may address this issue. | |
1283 | + for instance, | |
1284 | + mount /cdrom/squashfs.img /sq | |
1285 | + losetup /sq/ext2.img | |
1286 | + losetup /somewhere/cow | |
1287 | + dmsetup "snapshot /dev/loop0 /dev/loop1 ..." | |
1288 | +- it will be difficult (or needs more operations) to extract the | |
1289 | + difference between the original device and COW. | |
1290 | +- DM snapshot-merge may help a lot when users try merging. in the | |
1291 | + fs-layer union, users will use rsync(1). | |
1292 | + | |
7e9cd9fe AM |
1293 | +You may want to read my old paper "Filesystems in LiveCD" |
1294 | +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf). | |
53392da6 | 1295 | + |
7e9cd9fe AM |
1296 | + |
1297 | +Several characters/aspects/persona of aufs | |
53392da6 AM |
1298 | +---------------------------------------------------------------------- |
1299 | + | |
7e9cd9fe | 1300 | +Aufs has several characters, aspects or persona. |
53392da6 AM |
1301 | +1. a filesystem, callee of VFS helper |
1302 | +2. sub-VFS, caller of VFS helper for branches | |
1303 | +3. a virtual filesystem which maintains persistent inode number | |
1304 | +4. reader/writer of files on branches such like an application | |
1305 | + | |
1306 | +1. Callee of VFS Helper | |
1307 | +As an ordinary linux filesystem, aufs is a callee of VFS. For instance, | |
1308 | +unlink(2) from an application reaches sys_unlink() kernel function and | |
1309 | +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it | |
1310 | +calls filesystem specific unlink operation. Actually aufs implements the | |
1311 | +unlink operation but it behaves like a redirector. | |
1312 | + | |
1313 | +2. Caller of VFS Helper for Branches | |
1314 | +aufs_unlink() passes the unlink request to the branch filesystem as if | |
1315 | +it were called from VFS. So the called unlink operation of the branch | |
1316 | +filesystem acts as usual. As a caller of VFS helper, aufs should handle | |
1317 | +every necessary pre/post operation for the branch filesystem. | |
1318 | +- acquire the lock for the parent dir on a branch | |
1319 | +- lookup in a branch | |
1320 | +- revalidate dentry on a branch | |
1321 | +- mnt_want_write() for a branch | |
1322 | +- vfs_unlink() for a branch | |
1323 | +- mnt_drop_write() for a branch | |
1324 | +- release the lock on a branch | |
1325 | + | |
1326 | +3. Persistent Inode Number | |
1327 | +One of the most important issue for a filesystem is to maintain inode | |
1328 | +numbers. This is particularly important to support exporting a | |
1329 | +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a | |
1330 | +backend block device for its own. But some storage is necessary to | |
7e9cd9fe AM |
1331 | +keep and maintain the inode numbers. It may be a large space and may not |
1332 | +suit to keep in memory. Aufs rents some space from its first writable | |
1333 | +branch filesystem (by default) and creates file(s) on it. These files | |
1334 | +are created by aufs internally and removed soon (currently) keeping | |
1335 | +opened. | |
53392da6 AM |
1336 | +Note: Because these files are removed, they are totally gone after |
1337 | + unmounting aufs. It means the inode numbers are not persistent | |
1338 | + across unmount or reboot. I have a plan to make them really | |
1339 | + persistent which will be important for aufs on NFS server. | |
1340 | + | |
1341 | +4. Read/Write Files Internally (copy-on-write) | |
1342 | +Because a branch can be readonly, when you write a file on it, aufs will | |
1343 | +"copy-up" it to the upper writable branch internally. And then write the | |
1344 | +originally requested thing to the file. Generally kernel doesn't | |
1345 | +open/read/write file actively. In aufs, even a single write may cause a | |
1346 | +internal "file copy". This behaviour is very similar to cp(1) command. | |
1347 | + | |
1348 | +Some people may think it is better to pass such work to user space | |
1349 | +helper, instead of doing in kernel space. Actually I am still thinking | |
1350 | +about it. But currently I have implemented it in kernel space. | |
1351 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt | |
1352 | --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1353 | +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2017-05-06 22:16:52.774886674 +0200 |
7e9cd9fe | 1354 | @@ -0,0 +1,258 @@ |
53392da6 | 1355 | + |
a2654f78 | 1356 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1357 | +# |
1358 | +# This program is free software; you can redistribute it and/or modify | |
1359 | +# it under the terms of the GNU General Public License as published by | |
1360 | +# the Free Software Foundation; either version 2 of the License, or | |
1361 | +# (at your option) any later version. | |
1362 | +# | |
1363 | +# This program is distributed in the hope that it will be useful, | |
1364 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1365 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1366 | +# GNU General Public License for more details. | |
1367 | +# | |
1368 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1369 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1370 | + |
1371 | +Basic Aufs Internal Structure | |
1372 | + | |
1373 | +Superblock/Inode/Dentry/File Objects | |
1374 | +---------------------------------------------------------------------- | |
1375 | +As like an ordinary filesystem, aufs has its own | |
1376 | +superblock/inode/dentry/file objects. All these objects have a | |
1377 | +dynamically allocated array and store the same kind of pointers to the | |
1378 | +lower filesystem, branch. | |
1379 | +For example, when you build a union with one readwrite branch and one | |
1380 | +readonly, mounted /au, /rw and /ro respectively. | |
1381 | +- /au = /rw + /ro | |
1382 | +- /ro/fileA exists but /rw/fileA | |
1383 | + | |
1384 | +Aufs lookup operation finds /ro/fileA and gets dentry for that. These | |
1385 | +pointers are stored in a aufs dentry. The array in aufs dentry will be, | |
7e9cd9fe | 1386 | +- [0] = NULL (because /rw/fileA doesn't exist) |
53392da6 AM |
1387 | +- [1] = /ro/fileA |
1388 | + | |
1389 | +This style of an array is essentially same to the aufs | |
1390 | +superblock/inode/dentry/file objects. | |
1391 | + | |
1392 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1393 | +branches dynamically, these objects has its own generation. When |
1394 | +branches are changed, the generation in aufs superblock is | |
1395 | +incremented. And a generation in other object are compared when it is | |
1396 | +accessed. When a generation in other objects are obsoleted, aufs | |
1397 | +refreshes the internal array. | |
53392da6 AM |
1398 | + |
1399 | + | |
1400 | +Superblock | |
1401 | +---------------------------------------------------------------------- | |
1402 | +Additionally aufs superblock has some data for policies to select one | |
1403 | +among multiple writable branches, XIB files, pseudo-links and kobject. | |
1404 | +See below in detail. | |
7e9cd9fe AM |
1405 | +About the policies which supports copy-down a directory, see |
1406 | +wbr_policy.txt too. | |
53392da6 AM |
1407 | + |
1408 | + | |
1409 | +Branch and XINO(External Inode Number Translation Table) | |
1410 | +---------------------------------------------------------------------- | |
1411 | +Every branch has its own xino (external inode number translation table) | |
1412 | +file. The xino file is created and unlinked by aufs internally. When two | |
1413 | +members of a union exist on the same filesystem, they share the single | |
1414 | +xino file. | |
1415 | +The struct of a xino file is simple, just a sequence of aufs inode | |
1416 | +numbers which is indexed by the lower inode number. | |
1417 | +In the above sample, assume the inode number of /ro/fileA is i111 and | |
1418 | +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as | |
1419 | +4(8) bytes at 111 * 4(8) bytes offset in the xino file. | |
1420 | + | |
1421 | +When the inode numbers are not contiguous, the xino file will be sparse | |
1422 | +which has a hole in it and doesn't consume as much disk space as it | |
1423 | +might appear. If your branch filesystem consumes disk space for such | |
1424 | +holes, then you should specify 'xino=' option at mounting aufs. | |
1425 | + | |
7e9cd9fe AM |
1426 | +Aufs has a mount option to free the disk blocks for such holes in XINO |
1427 | +files on tmpfs or ramdisk. But it is not so effective actually. If you | |
1428 | +meet a problem of disk shortage due to XINO files, then you should try | |
1429 | +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git. | |
1430 | +The patch localizes the assignment inumbers per tmpfs-mount and avoid | |
1431 | +the holes in XINO files. | |
1432 | + | |
53392da6 | 1433 | +Also a writable branch has three kinds of "whiteout bases". All these |
7e9cd9fe | 1434 | +are existed when the branch is joined to aufs, and their names are |
53392da6 AM |
1435 | +whiteout-ed doubly, so that users will never see their names in aufs |
1436 | +hierarchy. | |
7e9cd9fe | 1437 | +1. a regular file which will be hardlinked to all whiteouts. |
53392da6 | 1438 | +2. a directory to store a pseudo-link. |
7e9cd9fe | 1439 | +3. a directory to store an "orphan"-ed file temporary. |
53392da6 AM |
1440 | + |
1441 | +1. Whiteout Base | |
1442 | + When you remove a file on a readonly branch, aufs handles it as a | |
1443 | + logical deletion and creates a whiteout on the upper writable branch | |
1444 | + as a hardlink of this file in order not to consume inode on the | |
1445 | + writable branch. | |
1446 | +2. Pseudo-link Dir | |
1447 | + See below, Pseudo-link. | |
1448 | +3. Step-Parent Dir | |
1449 | + When "fileC" exists on the lower readonly branch only and it is | |
1450 | + opened and removed with its parent dir, and then user writes | |
1451 | + something into it, then aufs copies-up fileC to this | |
1452 | + directory. Because there is no other dir to store fileC. After | |
1453 | + creating a file under this dir, the file is unlinked. | |
1454 | + | |
1455 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1456 | +dynamically, a branch has its own id. When the branch order changes, |
1457 | +aufs finds the new index by searching the branch id. | |
53392da6 AM |
1458 | + |
1459 | + | |
1460 | +Pseudo-link | |
1461 | +---------------------------------------------------------------------- | |
1462 | +Assume "fileA" exists on the lower readonly branch only and it is | |
1463 | +hardlinked to "fileB" on the branch. When you write something to fileA, | |
1464 | +aufs copies-up it to the upper writable branch. Additionally aufs | |
1465 | +creates a hardlink under the Pseudo-link Directory of the writable | |
1466 | +branch. The inode of a pseudo-link is kept in aufs super_block as a | |
1467 | +simple list. If fileB is read after unlinking fileA, aufs returns | |
1468 | +filedata from the pseudo-link instead of the lower readonly | |
1469 | +branch. Because the pseudo-link is based upon the inode, to keep the | |
7e9cd9fe | 1470 | +inode number by xino (see above) is essentially necessary. |
53392da6 AM |
1471 | + |
1472 | +All the hardlinks under the Pseudo-link Directory of the writable branch | |
1473 | +should be restored in a proper location later. Aufs provides a utility | |
1474 | +to do this. The userspace helpers executed at remounting and unmounting | |
1475 | +aufs by default. | |
1476 | +During this utility is running, it puts aufs into the pseudo-link | |
1477 | +maintenance mode. In this mode, only the process which began the | |
1478 | +maintenance mode (and its child processes) is allowed to operate in | |
1479 | +aufs. Some other processes which are not related to the pseudo-link will | |
1480 | +be allowed to run too, but the rest have to return an error or wait | |
1481 | +until the maintenance mode ends. If a process already acquires an inode | |
1482 | +mutex (in VFS), it has to return an error. | |
1483 | + | |
1484 | + | |
1485 | +XIB(external inode number bitmap) | |
1486 | +---------------------------------------------------------------------- | |
1487 | +Addition to the xino file per a branch, aufs has an external inode number | |
7e9cd9fe AM |
1488 | +bitmap in a superblock object. It is also an internal file such like a |
1489 | +xino file. | |
53392da6 AM |
1490 | +It is a simple bitmap to mark whether the aufs inode number is in-use or |
1491 | +not. | |
1492 | +To reduce the file I/O, aufs prepares a single memory page to cache xib. | |
1493 | + | |
7e9cd9fe | 1494 | +As well as XINO files, aufs has a feature to truncate/refresh XIB to |
53392da6 AM |
1495 | +reduce the number of consumed disk blocks for these files. |
1496 | + | |
1497 | + | |
1498 | +Virtual or Vertical Dir, and Readdir in Userspace | |
1499 | +---------------------------------------------------------------------- | |
1500 | +In order to support multiple layers (branches), aufs readdir operation | |
1501 | +constructs a virtual dir block on memory. For readdir, aufs calls | |
1502 | +vfs_readdir() internally for each dir on branches, merges their entries | |
1503 | +with eliminating the whiteout-ed ones, and sets it to file (dir) | |
1504 | +object. So the file object has its entry list until it is closed. The | |
1505 | +entry list will be updated when the file position is zero and becomes | |
7e9cd9fe | 1506 | +obsoleted. This decision is made in aufs automatically. |
53392da6 AM |
1507 | + |
1508 | +The dynamically allocated memory block for the name of entries has a | |
1509 | +unit of 512 bytes (by default) and stores the names contiguously (no | |
1510 | +padding). Another block for each entry is handled by kmem_cache too. | |
1511 | +During building dir blocks, aufs creates hash list and judging whether | |
1512 | +the entry is whiteouted by its upper branch or already listed. | |
1513 | +The merged result is cached in the corresponding inode object and | |
1514 | +maintained by a customizable life-time option. | |
1515 | + | |
1516 | +Some people may call it can be a security hole or invite DoS attack | |
1517 | +since the opened and once readdir-ed dir (file object) holds its entry | |
1518 | +list and becomes a pressure for system memory. But I'd say it is similar | |
1519 | +to files under /proc or /sys. The virtual files in them also holds a | |
1520 | +memory page (generally) while they are opened. When an idea to reduce | |
1521 | +memory for them is introduced, it will be applied to aufs too. | |
1522 | +For those who really hate this situation, I've developed readdir(3) | |
1523 | +library which operates this merging in userspace. You just need to set | |
1524 | +LD_PRELOAD environment variable, and aufs will not consume no memory in | |
1525 | +kernel space for readdir(3). | |
1526 | + | |
1527 | + | |
1528 | +Workqueue | |
1529 | +---------------------------------------------------------------------- | |
1530 | +Aufs sometimes requires privilege access to a branch. For instance, | |
1531 | +in copy-up/down operation. When a user process is going to make changes | |
1532 | +to a file which exists in the lower readonly branch only, and the mode | |
1533 | +of one of ancestor directories may not be writable by a user | |
1534 | +process. Here aufs copy-up the file with its ancestors and they may | |
1535 | +require privilege to set its owner/group/mode/etc. | |
1536 | +This is a typical case of a application character of aufs (see | |
1537 | +Introduction). | |
1538 | + | |
1539 | +Aufs uses workqueue synchronously for this case. It creates its own | |
1540 | +workqueue. The workqueue is a kernel thread and has privilege. Aufs | |
1541 | +passes the request to call mkdir or write (for example), and wait for | |
1542 | +its completion. This approach solves a problem of a signal handler | |
1543 | +simply. | |
1544 | +If aufs didn't adopt the workqueue and changed the privilege of the | |
7e9cd9fe AM |
1545 | +process, then the process may receive the unexpected SIGXFSZ or other |
1546 | +signals. | |
53392da6 AM |
1547 | + |
1548 | +Also aufs uses the system global workqueue ("events" kernel thread) too | |
1549 | +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a | |
1550 | +whiteout base and etc. This is unrelated to a privilege. | |
1551 | +Most of aufs operation tries acquiring a rw_semaphore for aufs | |
1552 | +superblock at the beginning, at the same time waits for the completion | |
1553 | +of all queued asynchronous tasks. | |
1554 | + | |
1555 | + | |
1556 | +Whiteout | |
1557 | +---------------------------------------------------------------------- | |
1558 | +The whiteout in aufs is very similar to Unionfs's. That is represented | |
1559 | +by its filename. UnionMount takes an approach of a file mode, but I am | |
1560 | +afraid several utilities (find(1) or something) will have to support it. | |
1561 | + | |
1562 | +Basically the whiteout represents "logical deletion" which stops aufs to | |
1563 | +lookup further, but also it represents "dir is opaque" which also stop | |
7e9cd9fe | 1564 | +further lookup. |
53392da6 AM |
1565 | + |
1566 | +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively. | |
1567 | +In order to make several functions in a single systemcall to be | |
1568 | +revertible, aufs adopts an approach to rename a directory to a temporary | |
1569 | +unique whiteouted name. | |
1570 | +For example, in rename(2) dir where the target dir already existed, aufs | |
1571 | +renames the target dir to a temporary unique whiteouted name before the | |
7e9cd9fe | 1572 | +actual rename on a branch, and then handles other actions (make it opaque, |
53392da6 AM |
1573 | +update the attributes, etc). If an error happens in these actions, aufs |
1574 | +simply renames the whiteouted name back and returns an error. If all are | |
1575 | +succeeded, aufs registers a function to remove the whiteouted unique | |
1576 | +temporary name completely and asynchronously to the system global | |
1577 | +workqueue. | |
1578 | + | |
1579 | + | |
1580 | +Copy-up | |
1581 | +---------------------------------------------------------------------- | |
1582 | +It is a well-known feature or concept. | |
1583 | +When user modifies a file on a readonly branch, aufs operate "copy-up" | |
1584 | +internally and makes change to the new file on the upper writable branch. | |
1585 | +When the trigger systemcall does not update the timestamps of the parent | |
1586 | +dir, aufs reverts it after copy-up. | |
c2b27bf2 AM |
1587 | + |
1588 | + | |
1589 | +Move-down (aufs3.9 and later) | |
1590 | +---------------------------------------------------------------------- | |
1591 | +"Copy-up" is one of the essential feature in aufs. It copies a file from | |
1592 | +the lower readonly branch to the upper writable branch when a user | |
1593 | +changes something about the file. | |
1594 | +"Move-down" is an opposite action of copy-up. Basically this action is | |
1595 | +ran manually instead of automatically and internally. | |
076b876e AM |
1596 | +For desgin and implementation, aufs has to consider these issues. |
1597 | +- whiteout for the file may exist on the lower branch. | |
1598 | +- ancestor directories may not exist on the lower branch. | |
1599 | +- diropq for the ancestor directories may exist on the upper branch. | |
1600 | +- free space on the lower branch will reduce. | |
1601 | +- another access to the file may happen during moving-down, including | |
7e9cd9fe | 1602 | + UDBA (see "Revalidate Dentry and UDBA"). |
076b876e AM |
1603 | +- the file should not be hard-linked nor pseudo-linked. they should be |
1604 | + handled by auplink utility later. | |
c2b27bf2 AM |
1605 | + |
1606 | +Sometimes users want to move-down a file from the upper writable branch | |
1607 | +to the lower readonly or writable branch. For instance, | |
1608 | +- the free space of the upper writable branch is going to run out. | |
1609 | +- create a new intermediate branch between the upper and lower branch. | |
1610 | +- etc. | |
1611 | + | |
1612 | +For this purpose, use "aumvdown" command in aufs-util.git. | |
b912730e AM |
1613 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt |
1614 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1615 | +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2017-05-06 22:16:52.774886674 +0200 |
b912730e AM |
1616 | @@ -0,0 +1,85 @@ |
1617 | + | |
a2654f78 | 1618 | +# Copyright (C) 2015-2017 Junjiro R. Okajima |
b912730e AM |
1619 | +# |
1620 | +# This program is free software; you can redistribute it and/or modify | |
1621 | +# it under the terms of the GNU General Public License as published by | |
1622 | +# the Free Software Foundation; either version 2 of the License, or | |
1623 | +# (at your option) any later version. | |
1624 | +# | |
1625 | +# This program is distributed in the hope that it will be useful, | |
1626 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1627 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1628 | +# GNU General Public License for more details. | |
1629 | +# | |
1630 | +# You should have received a copy of the GNU General Public License | |
1631 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1632 | + | |
1633 | +Support for a branch who has its ->atomic_open() | |
1634 | +---------------------------------------------------------------------- | |
1635 | +The filesystems who implement its ->atomic_open() are not majority. For | |
1636 | +example NFSv4 does, and aufs should call NFSv4 ->atomic_open, | |
1637 | +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than | |
1638 | +->atomic_open(), NFSv4 returns an error for this open(2). While I am not | |
1639 | +sure whether all filesystems who have ->atomic_open() behave like this, | |
1640 | +but NFSv4 surely returns the error. | |
1641 | + | |
1642 | +In order to support ->atomic_open() for aufs, there are a few | |
1643 | +approaches. | |
1644 | + | |
1645 | +A. Introduce aufs_atomic_open() | |
1646 | + - calls one of VFS:do_last(), lookup_open() or atomic_open() for | |
1647 | + branch fs. | |
1648 | +B. Introduce aufs_atomic_open() calling create, open and chmod. this is | |
1649 | + an aufs user Pip Cet's approach | |
1650 | + - calls aufs_create(), VFS finish_open() and notify_change(). | |
1651 | + - pass fake-mode to finish_open(), and then correct the mode by | |
1652 | + notify_change(). | |
1653 | +C. Extend aufs_open() to call branch fs's ->atomic_open() | |
1654 | + - no aufs_atomic_open(). | |
1655 | + - aufs_lookup() registers the TID to an aufs internal object. | |
1656 | + - aufs_create() does nothing when the matching TID is registered, but | |
1657 | + registers the mode. | |
1658 | + - aufs_open() calls branch fs's ->atomic_open() when the matching | |
1659 | + TID is registered. | |
1660 | +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's | |
1661 | + credential | |
1662 | + - no aufs_atomic_open(). | |
1663 | + - aufs_create() registers the TID to an internal object. this info | |
1664 | + represents "this process created this file just now." | |
1665 | + - when aufs gets EACCES from branch fs's ->open(), then confirm the | |
1666 | + registered TID and re-try open() with superuser's credential. | |
1667 | + | |
1668 | +Pros and cons for each approach. | |
1669 | + | |
1670 | +A. | |
1671 | + - straightforward but highly depends upon VFS internal. | |
1672 | + - the atomic behavaiour is kept. | |
1673 | + - some of parameters such as nameidata are hard to reproduce for | |
1674 | + branch fs. | |
1675 | + - large overhead. | |
1676 | +B. | |
1677 | + - easy to implement. | |
1678 | + - the atomic behavaiour is lost. | |
1679 | +C. | |
1680 | + - the atomic behavaiour is kept. | |
1681 | + - dirty and tricky. | |
1682 | + - VFS checks whether the file is created correctly after calling | |
1683 | + ->create(), which means this approach doesn't work. | |
1684 | +D. | |
1685 | + - easy to implement. | |
1686 | + - the atomic behavaiour is lost. | |
1687 | + - to open a file with superuser's credential and give it to a user | |
1688 | + process is a bad idea, since the file object keeps the credential | |
1689 | + in it. It may affect LSM or something. This approach doesn't work | |
1690 | + either. | |
1691 | + | |
1692 | +The approach A is ideal, but it hard to implement. So here is a | |
1693 | +variation of A, which is to be implemented. | |
1694 | + | |
1695 | +A-1. Introduce aufs_atomic_open() | |
1696 | + - calls branch fs ->atomic_open() if exists. otherwise calls | |
1697 | + vfs_create() and finish_open(). | |
1698 | + - the demerit is that the several checks after branch fs | |
1699 | + ->atomic_open() are lost. in the ordinary case, the checks are | |
1700 | + done by VFS:do_last(), lookup_open() and atomic_open(). some can | |
1701 | + be implemented in aufs, but not all I am afraid. | |
53392da6 AM |
1702 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt |
1703 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1704 | +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2017-05-06 22:16:52.774886674 +0200 |
7e9cd9fe | 1705 | @@ -0,0 +1,113 @@ |
53392da6 | 1706 | + |
a2654f78 | 1707 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1708 | +# |
1709 | +# This program is free software; you can redistribute it and/or modify | |
1710 | +# it under the terms of the GNU General Public License as published by | |
1711 | +# the Free Software Foundation; either version 2 of the License, or | |
1712 | +# (at your option) any later version. | |
1713 | +# | |
1714 | +# This program is distributed in the hope that it will be useful, | |
1715 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1716 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1717 | +# GNU General Public License for more details. | |
1718 | +# | |
1719 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1720 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1721 | + |
1722 | +Lookup in a Branch | |
1723 | +---------------------------------------------------------------------- | |
1724 | +Since aufs has a character of sub-VFS (see Introduction), it operates | |
7e9cd9fe AM |
1725 | +lookup for branches as VFS does. It may be a heavy work. But almost all |
1726 | +lookup operation in aufs is the simplest case, ie. lookup only an entry | |
1727 | +directly connected to its parent. Digging down the directory hierarchy | |
1728 | +is unnecessary. VFS has a function lookup_one_len() for that use, and | |
1729 | +aufs calls it. | |
1730 | + | |
1731 | +When a branch is a remote filesystem, aufs basically relies upon its | |
53392da6 AM |
1732 | +->d_revalidate(), also aufs forces the hardest revalidate tests for |
1733 | +them. | |
1734 | +For d_revalidate, aufs implements three levels of revalidate tests. See | |
1735 | +"Revalidate Dentry and UDBA" in detail. | |
1736 | + | |
1737 | + | |
076b876e AM |
1738 | +Test Only the Highest One for the Directory Permission (dirperm1 option) |
1739 | +---------------------------------------------------------------------- | |
1740 | +Let's try case study. | |
1741 | +- aufs has two branches, upper readwrite and lower readonly. | |
1742 | + /au = /rw + /ro | |
1743 | +- "dirA" exists under /ro, but /rw. and its mode is 0700. | |
1744 | +- user invoked "chmod a+rx /au/dirA" | |
1745 | +- the internal copy-up is activated and "/rw/dirA" is created and its | |
7e9cd9fe | 1746 | + permission bits are set to world readable. |
076b876e AM |
1747 | +- then "/au/dirA" becomes world readable? |
1748 | + | |
1749 | +In this case, /ro/dirA is still 0700 since it exists in readonly branch, | |
1750 | +or it may be a natively readonly filesystem. If aufs respects the lower | |
1751 | +branch, it should not respond readdir request from other users. But user | |
1752 | +allowed it by chmod. Should really aufs rejects showing the entries | |
1753 | +under /ro/dirA? | |
1754 | + | |
7e9cd9fe AM |
1755 | +To be honest, I don't have a good solution for this case. So aufs |
1756 | +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to | |
1757 | +users. | |
076b876e AM |
1758 | +When dirperm1 is specified, aufs checks only the highest one for the |
1759 | +directory permission, and shows the entries. Otherwise, as usual, checks | |
1760 | +every dir existing on all branches and rejects the request. | |
1761 | + | |
1762 | +As a side effect, dirperm1 option improves the performance of aufs | |
1763 | +because the number of permission check is reduced when the number of | |
1764 | +branch is many. | |
1765 | + | |
1766 | + | |
53392da6 AM |
1767 | +Revalidate Dentry and UDBA (User's Direct Branch Access) |
1768 | +---------------------------------------------------------------------- | |
1769 | +Generally VFS helpers re-validate a dentry as a part of lookup. | |
1770 | +0. digging down the directory hierarchy. | |
1771 | +1. lock the parent dir by its i_mutex. | |
1772 | +2. lookup the final (child) entry. | |
1773 | +3. revalidate it. | |
1774 | +4. call the actual operation (create, unlink, etc.) | |
1775 | +5. unlock the parent dir | |
1776 | + | |
1777 | +If the filesystem implements its ->d_revalidate() (step 3), then it is | |
1778 | +called. Actually aufs implements it and checks the dentry on a branch is | |
1779 | +still valid. | |
1780 | +But it is not enough. Because aufs has to release the lock for the | |
1781 | +parent dir on a branch at the end of ->lookup() (step 2) and | |
1782 | +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still | |
1783 | +held by VFS. | |
1784 | +If the file on a branch is changed directly, eg. bypassing aufs, after | |
1785 | +aufs released the lock, then the subsequent operation may cause | |
1786 | +something unpleasant result. | |
1787 | + | |
1788 | +This situation is a result of VFS architecture, ->lookup() and | |
1789 | +->d_revalidate() is separated. But I never say it is wrong. It is a good | |
1790 | +design from VFS's point of view. It is just not suitable for sub-VFS | |
1791 | +character in aufs. | |
1792 | + | |
1793 | +Aufs supports such case by three level of revalidation which is | |
1794 | +selectable by user. | |
1795 | +1. Simple Revalidate | |
1796 | + Addition to the native flow in VFS's, confirm the child-parent | |
1797 | + relationship on the branch just after locking the parent dir on the | |
1798 | + branch in the "actual operation" (step 4). When this validation | |
1799 | + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still | |
1800 | + checks the validation of the dentry on branches. | |
1801 | +2. Monitor Changes Internally by Inotify/Fsnotify | |
1802 | + Addition to above, in the "actual operation" (step 4) aufs re-lookup | |
1803 | + the dentry on the branch, and returns EBUSY if it finds different | |
1804 | + dentry. | |
1805 | + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches | |
1806 | + during it is in cache. When the event is notified, aufs registers a | |
1807 | + function to kernel 'events' thread by schedule_work(). And the | |
1808 | + function sets some special status to the cached aufs dentry and inode | |
1809 | + private data. If they are not cached, then aufs has nothing to | |
1810 | + do. When the same file is accessed through aufs (step 0-3) later, | |
1811 | + aufs will detect the status and refresh all necessary data. | |
1812 | + In this mode, aufs has to ignore the event which is fired by aufs | |
1813 | + itself. | |
1814 | +3. No Extra Validation | |
1815 | + This is the simplest test and doesn't add any additional revalidation | |
7e9cd9fe | 1816 | + test, and skip the revalidation in step 4. It is useful and improves |
53392da6 AM |
1817 | + aufs performance when system surely hide the aufs branches from user, |
1818 | + by over-mounting something (or another method). | |
1819 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt | |
1820 | --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1821 | +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2017-05-06 22:16:52.774886674 +0200 |
7e9cd9fe | 1822 | @@ -0,0 +1,74 @@ |
53392da6 | 1823 | + |
a2654f78 | 1824 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1825 | +# |
1826 | +# This program is free software; you can redistribute it and/or modify | |
1827 | +# it under the terms of the GNU General Public License as published by | |
1828 | +# the Free Software Foundation; either version 2 of the License, or | |
1829 | +# (at your option) any later version. | |
1830 | +# | |
1831 | +# This program is distributed in the hope that it will be useful, | |
1832 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1833 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1834 | +# GNU General Public License for more details. | |
1835 | +# | |
1836 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1837 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1838 | + |
1839 | +Branch Manipulation | |
1840 | + | |
1841 | +Since aufs supports dynamic branch manipulation, ie. add/remove a branch | |
1842 | +and changing its permission/attribute, there are a lot of works to do. | |
1843 | + | |
1844 | + | |
1845 | +Add a Branch | |
1846 | +---------------------------------------------------------------------- | |
1847 | +o Confirm the adding dir exists outside of aufs, including loopback | |
7e9cd9fe | 1848 | + mount, and its various attributes. |
53392da6 AM |
1849 | +o Initialize the xino file and whiteout bases if necessary. |
1850 | + See struct.txt. | |
1851 | + | |
1852 | +o Check the owner/group/mode of the directory | |
1853 | + When the owner/group/mode of the adding directory differs from the | |
1854 | + existing branch, aufs issues a warning because it may impose a | |
1855 | + security risk. | |
1856 | + For example, when a upper writable branch has a world writable empty | |
1857 | + top directory, a malicious user can create any files on the writable | |
1858 | + branch directly, like copy-up and modify manually. If something like | |
1859 | + /etc/{passwd,shadow} exists on the lower readonly branch but the upper | |
1860 | + writable branch, and the writable branch is world-writable, then a | |
1861 | + malicious guy may create /etc/passwd on the writable branch directly | |
1862 | + and the infected file will be valid in aufs. | |
7e9cd9fe | 1863 | + I am afraid it can be a security issue, but aufs can do nothing except |
53392da6 AM |
1864 | + producing a warning. |
1865 | + | |
1866 | + | |
1867 | +Delete a Branch | |
1868 | +---------------------------------------------------------------------- | |
1869 | +o Confirm the deleting branch is not busy | |
1870 | + To be general, there is one merit to adopt "remount" interface to | |
1871 | + manipulate branches. It is to discard caches. At deleting a branch, | |
1872 | + aufs checks the still cached (and connected) dentries and inodes. If | |
1873 | + there are any, then they are all in-use. An inode without its | |
1874 | + corresponding dentry can be alive alone (for example, inotify/fsnotify case). | |
1875 | + | |
1876 | + For the cached one, aufs checks whether the same named entry exists on | |
1877 | + other branches. | |
1878 | + If the cached one is a directory, because aufs provides a merged view | |
1879 | + to users, as long as one dir is left on any branch aufs can show the | |
1880 | + dir to users. In this case, the branch can be removed from aufs. | |
1881 | + Otherwise aufs rejects deleting the branch. | |
1882 | + | |
1883 | + If any file on the deleting branch is opened by aufs, then aufs | |
1884 | + rejects deleting. | |
1885 | + | |
1886 | + | |
1887 | +Modify the Permission of a Branch | |
1888 | +---------------------------------------------------------------------- | |
1889 | +o Re-initialize or remove the xino file and whiteout bases if necessary. | |
1890 | + See struct.txt. | |
1891 | + | |
1892 | +o rw --> ro: Confirm the modifying branch is not busy | |
1893 | + Aufs rejects the request if any of these conditions are true. | |
1894 | + - a file on the branch is mmap-ed. | |
1895 | + - a regular file on the branch is opened for write and there is no | |
1896 | + same named entry on the upper branch. | |
1897 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt | |
1898 | --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1899 | +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2017-05-06 22:16:52.774886674 +0200 |
523b37e3 | 1900 | @@ -0,0 +1,64 @@ |
53392da6 | 1901 | + |
a2654f78 | 1902 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1903 | +# |
1904 | +# This program is free software; you can redistribute it and/or modify | |
1905 | +# it under the terms of the GNU General Public License as published by | |
1906 | +# the Free Software Foundation; either version 2 of the License, or | |
1907 | +# (at your option) any later version. | |
1908 | +# | |
1909 | +# This program is distributed in the hope that it will be useful, | |
1910 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1911 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1912 | +# GNU General Public License for more details. | |
1913 | +# | |
1914 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1915 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1916 | + |
1917 | +Policies to Select One among Multiple Writable Branches | |
1918 | +---------------------------------------------------------------------- | |
1919 | +When the number of writable branch is more than one, aufs has to decide | |
1920 | +the target branch for file creation or copy-up. By default, the highest | |
1921 | +writable branch which has the parent (or ancestor) dir of the target | |
1922 | +file is chosen (top-down-parent policy). | |
1923 | +By user's request, aufs implements some other policies to select the | |
7e9cd9fe AM |
1924 | +writable branch, for file creation several policies, round-robin, |
1925 | +most-free-space, and other policies. For copy-up, top-down-parent, | |
1926 | +bottom-up-parent, bottom-up and others. | |
53392da6 AM |
1927 | + |
1928 | +As expected, the round-robin policy selects the branch in circular. When | |
1929 | +you have two writable branches and creates 10 new files, 5 files will be | |
1930 | +created for each branch. mkdir(2) systemcall is an exception. When you | |
1931 | +create 10 new directories, all will be created on the same branch. | |
1932 | +And the most-free-space policy selects the one which has most free | |
1933 | +space among the writable branches. The amount of free space will be | |
1934 | +checked by aufs internally, and users can specify its time interval. | |
1935 | + | |
1936 | +The policies for copy-up is more simple, | |
1937 | +top-down-parent is equivalent to the same named on in create policy, | |
1938 | +bottom-up-parent selects the writable branch where the parent dir | |
1939 | +exists and the nearest upper one from the copyup-source, | |
1940 | +bottom-up selects the nearest upper writable branch from the | |
1941 | +copyup-source, regardless the existence of the parent dir. | |
1942 | + | |
1943 | +There are some rules or exceptions to apply these policies. | |
1944 | +- If there is a readonly branch above the policy-selected branch and | |
1945 | + the parent dir is marked as opaque (a variation of whiteout), or the | |
1946 | + target (creating) file is whiteout-ed on the upper readonly branch, | |
1947 | + then the result of the policy is ignored and the target file will be | |
1948 | + created on the nearest upper writable branch than the readonly branch. | |
1949 | +- If there is a writable branch above the policy-selected branch and | |
1950 | + the parent dir is marked as opaque or the target file is whiteouted | |
1951 | + on the branch, then the result of the policy is ignored and the target | |
1952 | + file will be created on the highest one among the upper writable | |
1953 | + branches who has diropq or whiteout. In case of whiteout, aufs removes | |
1954 | + it as usual. | |
1955 | +- link(2) and rename(2) systemcalls are exceptions in every policy. | |
1956 | + They try selecting the branch where the source exists as possible | |
1957 | + since copyup a large file will take long time. If it can't be, | |
1958 | + ie. the branch where the source exists is readonly, then they will | |
1959 | + follow the copyup policy. | |
1960 | +- There is an exception for rename(2) when the target exists. | |
1961 | + If the rename target exists, aufs compares the index of the branches | |
1962 | + where the source and the target exists and selects the higher | |
1963 | + one. If the selected branch is readonly, then aufs follows the | |
1964 | + copyup policy. | |
076b876e AM |
1965 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt |
1966 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 1967 | +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2017-05-06 22:16:52.774886674 +0200 |
076b876e AM |
1968 | @@ -0,0 +1,120 @@ |
1969 | + | |
a2654f78 | 1970 | +# Copyright (C) 2011-2017 Junjiro R. Okajima |
076b876e AM |
1971 | +# |
1972 | +# This program is free software; you can redistribute it and/or modify | |
1973 | +# it under the terms of the GNU General Public License as published by | |
1974 | +# the Free Software Foundation; either version 2 of the License, or | |
1975 | +# (at your option) any later version. | |
1976 | +# | |
1977 | +# This program is distributed in the hope that it will be useful, | |
1978 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1979 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1980 | +# GNU General Public License for more details. | |
1981 | +# | |
1982 | +# You should have received a copy of the GNU General Public License | |
1983 | +# along with this program; if not, write to the Free Software | |
1984 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1985 | + | |
1986 | + | |
1987 | +File-based Hierarchical Storage Management (FHSM) | |
1988 | +---------------------------------------------------------------------- | |
1989 | +Hierarchical Storage Management (or HSM) is a well-known feature in the | |
1990 | +storage world. Aufs provides this feature as file-based with multiple | |
7e9cd9fe | 1991 | +writable branches, based upon the principle of "Colder, the Lower". |
076b876e | 1992 | +Here the word "colder" means that the less used files, and "lower" means |
7e9cd9fe | 1993 | +that the position in the order of the stacked branches vertically. |
076b876e AM |
1994 | +These multiple writable branches are prioritized, ie. the topmost one |
1995 | +should be the fastest drive and be used heavily. | |
1996 | + | |
1997 | +o Characters in aufs FHSM story | |
1998 | +- aufs itself and a new branch attribute. | |
1999 | +- a new ioctl interface to move-down and to establish a connection with | |
2000 | + the daemon ("move-down" is a converse of "copy-up"). | |
2001 | +- userspace tool and daemon. | |
2002 | + | |
2003 | +The userspace daemon establishes a connection with aufs and waits for | |
2004 | +the notification. The notified information is very similar to struct | |
2005 | +statfs containing the number of consumed blocks and inodes. | |
2006 | +When the consumed blocks/inodes of a branch exceeds the user-specified | |
2007 | +upper watermark, the daemon activates its move-down process until the | |
2008 | +consumed blocks/inodes reaches the user-specified lower watermark. | |
2009 | + | |
2010 | +The actual move-down is done by aufs based upon the request from | |
2011 | +user-space since we need to maintain the inode number and the internal | |
2012 | +pointer arrays in aufs. | |
2013 | + | |
2014 | +Currently aufs FHSM handles the regular files only. Additionally they | |
2015 | +must not be hard-linked nor pseudo-linked. | |
2016 | + | |
2017 | + | |
2018 | +o Cowork of aufs and the user-space daemon | |
2019 | + During the userspace daemon established the connection, aufs sends a | |
2020 | + small notification to it whenever aufs writes something into the | |
2021 | + writable branch. But it may cost high since aufs issues statfs(2) | |
2022 | + internally. So user can specify a new option to cache the | |
2023 | + info. Actually the notification is controlled by these factors. | |
2024 | + + the specified cache time. | |
2025 | + + classified as "force" by aufs internally. | |
2026 | + Until the specified time expires, aufs doesn't send the info | |
2027 | + except the forced cases. When aufs decide forcing, the info is always | |
2028 | + notified to userspace. | |
2029 | + For example, the number of free inodes is generally large enough and | |
2030 | + the shortage of it happens rarely. So aufs doesn't force the | |
2031 | + notification when creating a new file, directory and others. This is | |
2032 | + the typical case which aufs doesn't force. | |
2033 | + When aufs writes the actual filedata and the files consumes any of new | |
2034 | + blocks, the aufs forces notifying. | |
2035 | + | |
2036 | + | |
2037 | +o Interfaces in aufs | |
2038 | +- New branch attribute. | |
2039 | + + fhsm | |
2040 | + Specifies that the branch is managed by FHSM feature. In other word, | |
2041 | + participant in the FHSM. | |
2042 | + When nofhsm is set to the branch, it will not be the source/target | |
2043 | + branch of the move-down operation. This attribute is set | |
2044 | + independently from coo and moo attributes, and if you want full | |
2045 | + FHSM, you should specify them as well. | |
2046 | +- New mount option. | |
2047 | + + fhsm_sec | |
2048 | + Specifies a second to suppress many less important info to be | |
2049 | + notified. | |
2050 | +- New ioctl. | |
2051 | + + AUFS_CTL_FHSM_FD | |
2052 | + create a new file descriptor which userspace can read the notification | |
2053 | + (a subset of struct statfs) from aufs. | |
2054 | +- Module parameter 'brs' | |
2055 | + It has to be set to 1. Otherwise the new mount option 'fhsm' will not | |
2056 | + be set. | |
2057 | +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs | |
2058 | + When there are two or more branches with fhsm attributes, | |
2059 | + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs | |
2060 | + terminates it. As a result of remounting and branch-manipulation, the | |
2061 | + number of branches with fhsm attribute can be one. In this case, | |
2062 | + /sbin/mount.aufs will terminate the user-space daemon. | |
2063 | + | |
2064 | + | |
2065 | +Finally the operation is done as these steps in kernel-space. | |
2066 | +- make sure that, | |
2067 | + + no one else is using the file. | |
2068 | + + the file is not hard-linked. | |
2069 | + + the file is not pseudo-linked. | |
2070 | + + the file is a regular file. | |
2071 | + + the parent dir is not opaqued. | |
2072 | +- find the target writable branch. | |
2073 | +- make sure the file is not whiteout-ed by the upper (than the target) | |
2074 | + branch. | |
2075 | +- make the parent dir on the target branch. | |
2076 | +- mutex lock the inode on the branch. | |
2077 | +- unlink the whiteout on the target branch (if exists). | |
2078 | +- lookup and create the whiteout-ed temporary name on the target branch. | |
2079 | +- copy the file as the whiteout-ed temporary name on the target branch. | |
2080 | +- rename the whiteout-ed temporary name to the original name. | |
2081 | +- unlink the file on the source branch. | |
2082 | +- maintain the internal pointer array and the external inode number | |
2083 | + table (XINO). | |
2084 | +- maintain the timestamps and other attributes of the parent dir and the | |
2085 | + file. | |
2086 | + | |
2087 | +And of course, in every step, an error may happen. So the operation | |
2088 | +should restore the original file state after an error happens. | |
53392da6 AM |
2089 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt |
2090 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 2091 | +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2017-05-06 22:16:52.774886674 +0200 |
b912730e | 2092 | @@ -0,0 +1,72 @@ |
53392da6 | 2093 | + |
a2654f78 | 2094 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
2095 | +# |
2096 | +# This program is free software; you can redistribute it and/or modify | |
2097 | +# it under the terms of the GNU General Public License as published by | |
2098 | +# the Free Software Foundation; either version 2 of the License, or | |
2099 | +# (at your option) any later version. | |
2100 | +# | |
2101 | +# This program is distributed in the hope that it will be useful, | |
2102 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2103 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2104 | +# GNU General Public License for more details. | |
2105 | +# | |
2106 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2107 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2108 | + |
2109 | +mmap(2) -- File Memory Mapping | |
2110 | +---------------------------------------------------------------------- | |
2111 | +In aufs, the file-mapped pages are handled by a branch fs directly, no | |
2112 | +interaction with aufs. It means aufs_mmap() calls the branch fs's | |
2113 | +->mmap(). | |
2114 | +This approach is simple and good, but there is one problem. | |
7e9cd9fe | 2115 | +Under /proc, several entries show the mmapped files by its path (with |
53392da6 AM |
2116 | +device and inode number), and the printed path will be the path on the |
2117 | +branch fs's instead of virtual aufs's. | |
2118 | +This is not a problem in most cases, but some utilities lsof(1) (and its | |
2119 | +user) may expect the path on aufs. | |
2120 | + | |
2121 | +To address this issue, aufs adds a new member called vm_prfile in struct | |
2122 | +vm_area_struct (and struct vm_region). The original vm_file points to | |
2123 | +the file on the branch fs in order to handle everything correctly as | |
2124 | +usual. The new vm_prfile points to a virtual file in aufs, and the | |
2125 | +show-functions in procfs refers to vm_prfile if it is set. | |
2126 | +Also we need to maintain several other places where touching vm_file | |
2127 | +such like | |
2128 | +- fork()/clone() copies vma and the reference count of vm_file is | |
2129 | + incremented. | |
2130 | +- merging vma maintains the ref count too. | |
2131 | + | |
7e9cd9fe | 2132 | +This is not a good approach. It just fakes the printed path. But it |
53392da6 AM |
2133 | +leaves all behaviour around f_mapping unchanged. This is surely an |
2134 | +advantage. | |
2135 | +Actually aufs had adopted another complicated approach which calls | |
2136 | +generic_file_mmap() and handles struct vm_operations_struct. In this | |
2137 | +approach, aufs met a hard problem and I could not solve it without | |
2138 | +switching the approach. | |
b912730e AM |
2139 | + |
2140 | +There may be one more another approach which is | |
2141 | +- bind-mount the branch-root onto the aufs-root internally | |
2142 | +- grab the new vfsmount (ie. struct mount) | |
2143 | +- lazy-umount the branch-root internally | |
2144 | +- in open(2) the aufs-file, open the branch-file with the hidden | |
2145 | + vfsmount (instead of the original branch's vfsmount) | |
2146 | +- ideally this "bind-mount and lazy-umount" should be done atomically, | |
2147 | + but it may be possible from userspace by the mount helper. | |
2148 | + | |
2149 | +Adding the internal hidden vfsmount and using it in opening a file, the | |
2150 | +file path under /proc will be printed correctly. This approach looks | |
2151 | +smarter, but is not possible I am afraid. | |
2152 | +- aufs-root may be bind-mount later. when it happens, another hidden | |
2153 | + vfsmount will be required. | |
2154 | +- it is hard to get the chance to bind-mount and lazy-umount | |
2155 | + + in kernel-space, FS can have vfsmount in open(2) via | |
2156 | + file->f_path, and aufs can know its vfsmount. But several locks are | |
2157 | + already acquired, and if aufs tries to bind-mount and lazy-umount | |
2158 | + here, then it may cause a deadlock. | |
2159 | + + in user-space, bind-mount doesn't invoke the mount helper. | |
2160 | +- since /proc shows dev and ino, aufs has to give vma these info. it | |
2161 | + means a new member vm_prinode will be necessary. this is essentially | |
2162 | + equivalent to vm_prfile described above. | |
2163 | + | |
2164 | +I have to give up this "looks-smater" approach. | |
c1595e42 JR |
2165 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt |
2166 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 2167 | +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2017-05-06 22:16:52.774886674 +0200 |
c1595e42 JR |
2168 | @@ -0,0 +1,96 @@ |
2169 | + | |
a2654f78 | 2170 | +# Copyright (C) 2014-2017 Junjiro R. Okajima |
c1595e42 JR |
2171 | +# |
2172 | +# This program is free software; you can redistribute it and/or modify | |
2173 | +# it under the terms of the GNU General Public License as published by | |
2174 | +# the Free Software Foundation; either version 2 of the License, or | |
2175 | +# (at your option) any later version. | |
2176 | +# | |
2177 | +# This program is distributed in the hope that it will be useful, | |
2178 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2179 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2180 | +# GNU General Public License for more details. | |
2181 | +# | |
2182 | +# You should have received a copy of the GNU General Public License | |
2183 | +# along with this program; if not, write to the Free Software | |
2184 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2185 | + | |
2186 | + | |
2187 | +Listing XATTR/EA and getting the value | |
2188 | +---------------------------------------------------------------------- | |
2189 | +For the inode standard attributes (owner, group, timestamps, etc.), aufs | |
2190 | +shows the values from the topmost existing file. This behaviour is good | |
7e9cd9fe | 2191 | +for the non-dir entries since the bahaviour exactly matches the shown |
c1595e42 JR |
2192 | +information. But for the directories, aufs considers all the same named |
2193 | +entries on the lower branches. Which means, if one of the lower entry | |
2194 | +rejects readdir call, then aufs returns an error even if the topmost | |
2195 | +entry allows it. This behaviour is necessary to respect the branch fs's | |
2196 | +security, but can make users confused since the user-visible standard | |
2197 | +attributes don't match the behaviour. | |
2198 | +To address this issue, aufs has a mount option called dirperm1 which | |
2199 | +checks the permission for the topmost entry only, and ignores the lower | |
2200 | +entry's permission. | |
2201 | + | |
2202 | +A similar issue can happen around XATTR. | |
2203 | +getxattr(2) and listxattr(2) families behave as if dirperm1 option is | |
7e9cd9fe AM |
2204 | +always set. Otherwise these very unpleasant situation would happen. |
2205 | +- listxattr(2) may return the duplicated entries. | |
c1595e42 JR |
2206 | +- users may not be able to remove or reset the XATTR forever, |
2207 | + | |
2208 | + | |
2209 | +XATTR/EA support in the internal (copy,move)-(up,down) | |
2210 | +---------------------------------------------------------------------- | |
7e9cd9fe | 2211 | +Generally the extended attributes of inode are categorized as these. |
c1595e42 JR |
2212 | +- "security" for LSM and capability. |
2213 | +- "system" for posix ACL, 'acl' mount option is required for the branch | |
2214 | + fs generally. | |
2215 | +- "trusted" for userspace, CAP_SYS_ADMIN is required. | |
2216 | +- "user" for userspace, 'user_xattr' mount option is required for the | |
2217 | + branch fs generally. | |
2218 | + | |
2219 | +Moreover there are some other categories. Aufs handles these rather | |
2220 | +unpopular categories as the ordinary ones, ie. there is no special | |
2221 | +condition nor exception. | |
2222 | + | |
2223 | +In copy-up, the support for XATTR on the dst branch may differ from the | |
2224 | +src branch. In this case, the copy-up operation will get an error and | |
7e9cd9fe AM |
2225 | +the original user operation which triggered the copy-up will fail. It |
2226 | +can happen that even all copy-up will fail. | |
c1595e42 JR |
2227 | +When both of src and dst branches support XATTR and if an error occurs |
2228 | +during copying XATTR, then the copy-up should fail obviously. That is a | |
2229 | +good reason and aufs should return an error to userspace. But when only | |
7e9cd9fe | 2230 | +the src branch support that XATTR, aufs should not return an error. |
c1595e42 JR |
2231 | +For example, the src branch supports ACL but the dst branch doesn't |
2232 | +because the dst branch may natively un-support it or temporary | |
2233 | +un-support it due to "noacl" mount option. Of course, the dst branch fs | |
2234 | +may NOT return an error even if the XATTR is not supported. It is | |
2235 | +totally up to the branch fs. | |
2236 | + | |
2237 | +Anyway when the aufs internal copy-up gets an error from the dst branch | |
2238 | +fs, then aufs tries removing the just copied entry and returns the error | |
2239 | +to the userspace. The worst case of this situation will be all copy-up | |
2240 | +will fail. | |
2241 | + | |
2242 | +For the copy-up operation, there two basic approaches. | |
2243 | +- copy the specified XATTR only (by category above), and return the | |
7e9cd9fe | 2244 | + error unconditionally if it happens. |
c1595e42 JR |
2245 | +- copy all XATTR, and ignore the error on the specified category only. |
2246 | + | |
2247 | +In order to support XATTR and to implement the correct behaviour, aufs | |
7e9cd9fe AM |
2248 | +chooses the latter approach and introduces some new branch attributes, |
2249 | +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth". | |
c1595e42 | 2250 | +They correspond to the XATTR namespaces (see above). Additionally, to be |
7e9cd9fe AM |
2251 | +convenient, "icex" is also provided which means all "icex*" attributes |
2252 | +are set (here the word "icex" stands for "ignore copy-error on XATTR"). | |
c1595e42 JR |
2253 | + |
2254 | +The meaning of these attributes is to ignore the error from setting | |
2255 | +XATTR on that branch. | |
2256 | +Note that aufs tries copying all XATTR unconditionally, and ignores the | |
2257 | +error from the dst branch according to the specified attributes. | |
2258 | + | |
2259 | +Some XATTR may have its default value. The default value may come from | |
2260 | +the parent dir or the environment. If the default value is set at the | |
2261 | +file creating-time, it will be overwritten by copy-up. | |
2262 | +Some contradiction may happen I am afraid. | |
2263 | +Do we need another attribute to stop copying XATTR? I am unsure. For | |
2264 | +now, aufs implements the branch attributes to ignore the error. | |
53392da6 AM |
2265 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt |
2266 | --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 2267 | +++ linux/Documentation/filesystems/aufs/design/07export.txt 2017-05-06 22:16:52.774886674 +0200 |
523b37e3 | 2268 | @@ -0,0 +1,58 @@ |
53392da6 | 2269 | + |
a2654f78 | 2270 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
2271 | +# |
2272 | +# This program is free software; you can redistribute it and/or modify | |
2273 | +# it under the terms of the GNU General Public License as published by | |
2274 | +# the Free Software Foundation; either version 2 of the License, or | |
2275 | +# (at your option) any later version. | |
2276 | +# | |
2277 | +# This program is distributed in the hope that it will be useful, | |
2278 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2279 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2280 | +# GNU General Public License for more details. | |
2281 | +# | |
2282 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2283 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2284 | + |
2285 | +Export Aufs via NFS | |
2286 | +---------------------------------------------------------------------- | |
2287 | +Here is an approach. | |
2288 | +- like xino/xib, add a new file 'xigen' which stores aufs inode | |
2289 | + generation. | |
2290 | +- iget_locked(): initialize aufs inode generation for a new inode, and | |
2291 | + store it in xigen file. | |
2292 | +- destroy_inode(): increment aufs inode generation and store it in xigen | |
2293 | + file. it is necessary even if it is not unlinked, because any data of | |
2294 | + inode may be changed by UDBA. | |
2295 | +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise | |
2296 | + build file handle by | |
2297 | + + branch id (4 bytes) | |
2298 | + + superblock generation (4 bytes) | |
2299 | + + inode number (4 or 8 bytes) | |
2300 | + + parent dir inode number (4 or 8 bytes) | |
2301 | + + inode generation (4 bytes)) | |
2302 | + + return value of exportfs_encode_fh() for the parent on a branch (4 | |
2303 | + bytes) | |
2304 | + + file handle for a branch (by exportfs_encode_fh()) | |
2305 | +- fh_to_dentry(): | |
2306 | + + find the index of a branch from its id in handle, and check it is | |
2307 | + still exist in aufs. | |
2308 | + + 1st level: get the inode number from handle and search it in cache. | |
7e9cd9fe AM |
2309 | + + 2nd level: if not found in cache, get the parent inode number from |
2310 | + the handle and search it in cache. and then open the found parent | |
2311 | + dir, find the matching inode number by vfs_readdir() and get its | |
2312 | + name, and call lookup_one_len() for the target dentry. | |
53392da6 AM |
2313 | + + 3rd level: if the parent dir is not cached, call |
2314 | + exportfs_decode_fh() for a branch and get the parent on a branch, | |
2315 | + build a pathname of it, convert it a pathname in aufs, call | |
2316 | + path_lookup(). now aufs gets a parent dir dentry, then handle it as | |
2317 | + the 2nd level. | |
2318 | + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount | |
2319 | + for every branch, but not itself. to get this, (currently) aufs | |
2320 | + searches in current->nsproxy->mnt_ns list. it may not be a good | |
2321 | + idea, but I didn't get other approach. | |
2322 | + + test the generation of the gotten inode. | |
2323 | +- every inode operation: they may get EBUSY due to UDBA. in this case, | |
2324 | + convert it into ESTALE for NFSD. | |
2325 | +- readdir(): call lockdep_on/off() because filldir in NFSD calls | |
2326 | + lookup_one_len(), vfs_getattr(), encode_fh() and others. | |
2327 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt | |
2328 | --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 2329 | +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2017-05-06 22:16:52.774886674 +0200 |
523b37e3 | 2330 | @@ -0,0 +1,52 @@ |
53392da6 | 2331 | + |
a2654f78 | 2332 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
2333 | +# |
2334 | +# This program is free software; you can redistribute it and/or modify | |
2335 | +# it under the terms of the GNU General Public License as published by | |
2336 | +# the Free Software Foundation; either version 2 of the License, or | |
2337 | +# (at your option) any later version. | |
2338 | +# | |
2339 | +# This program is distributed in the hope that it will be useful, | |
2340 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2341 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2342 | +# GNU General Public License for more details. | |
2343 | +# | |
2344 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2345 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2346 | + |
2347 | +Show Whiteout Mode (shwh) | |
2348 | +---------------------------------------------------------------------- | |
2349 | +Generally aufs hides the name of whiteouts. But in some cases, to show | |
2350 | +them is very useful for users. For instance, creating a new middle layer | |
2351 | +(branch) by merging existing layers. | |
2352 | + | |
2353 | +(borrowing aufs1 HOW-TO from a user, Michael Towers) | |
2354 | +When you have three branches, | |
2355 | +- Bottom: 'system', squashfs (underlying base system), read-only | |
2356 | +- Middle: 'mods', squashfs, read-only | |
2357 | +- Top: 'overlay', ram (tmpfs), read-write | |
2358 | + | |
2359 | +The top layer is loaded at boot time and saved at shutdown, to preserve | |
2360 | +the changes made to the system during the session. | |
2361 | +When larger changes have been made, or smaller changes have accumulated, | |
2362 | +the size of the saved top layer data grows. At this point, it would be | |
2363 | +nice to be able to merge the two overlay branches ('mods' and 'overlay') | |
2364 | +and rewrite the 'mods' squashfs, clearing the top layer and thus | |
2365 | +restoring save and load speed. | |
2366 | + | |
2367 | +This merging is simplified by the use of another aufs mount, of just the | |
2368 | +two overlay branches using the 'shwh' option. | |
2369 | +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \ | |
2370 | + aufs /livesys/merge_union | |
2371 | + | |
2372 | +A merged view of these two branches is then available at | |
2373 | +/livesys/merge_union, and the new feature is that the whiteouts are | |
2374 | +visible! | |
2375 | +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable | |
2376 | +writing to all branches. Also the default mode for all branches is 'ro'. | |
2377 | +It is now possible to save the combined contents of the two overlay | |
2378 | +branches to a new squashfs, e.g.: | |
2379 | +# mksquashfs /livesys/merge_union /path/to/newmods.squash | |
2380 | + | |
2381 | +This new squashfs archive can be stored on the boot device and the | |
2382 | +initramfs will use it to replace the old one at the next boot. | |
2383 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt | |
2384 | --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 2385 | +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2017-05-06 22:16:52.774886674 +0200 |
7e9cd9fe | 2386 | @@ -0,0 +1,47 @@ |
53392da6 | 2387 | + |
a2654f78 | 2388 | +# Copyright (C) 2010-2017 Junjiro R. Okajima |
53392da6 AM |
2389 | +# |
2390 | +# This program is free software; you can redistribute it and/or modify | |
2391 | +# it under the terms of the GNU General Public License as published by | |
2392 | +# the Free Software Foundation; either version 2 of the License, or | |
2393 | +# (at your option) any later version. | |
2394 | +# | |
2395 | +# This program is distributed in the hope that it will be useful, | |
2396 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2397 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2398 | +# GNU General Public License for more details. | |
2399 | +# | |
2400 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2401 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2402 | + |
2403 | +Dynamically customizable FS operations | |
2404 | +---------------------------------------------------------------------- | |
2405 | +Generally FS operations (struct inode_operations, struct | |
2406 | +address_space_operations, struct file_operations, etc.) are defined as | |
2407 | +"static const", but it never means that FS have only one set of | |
2408 | +operation. Some FS have multiple sets of them. For instance, ext2 has | |
2409 | +three sets, one for XIP, for NOBH, and for normal. | |
2410 | +Since aufs overrides and redirects these operations, sometimes aufs has | |
7e9cd9fe | 2411 | +to change its behaviour according to the branch FS type. More importantly |
53392da6 AM |
2412 | +VFS acts differently if a function (member in the struct) is set or |
2413 | +not. It means aufs should have several sets of operations and select one | |
2414 | +among them according to the branch FS definition. | |
2415 | + | |
7e9cd9fe | 2416 | +In order to solve this problem and not to affect the behaviour of VFS, |
53392da6 | 2417 | +aufs defines these operations dynamically. For instance, aufs defines |
7e9cd9fe AM |
2418 | +dummy direct_IO function for struct address_space_operations, but it may |
2419 | +not be set to the address_space_operations actually. When the branch FS | |
2420 | +doesn't have it, aufs doesn't set it to its address_space_operations | |
2421 | +while the function definition itself is still alive. So the behaviour | |
2422 | +itself will not change, and it will return an error when direct_IO is | |
2423 | +not set. | |
53392da6 AM |
2424 | + |
2425 | +The lifetime of these dynamically generated operation object is | |
2426 | +maintained by aufs branch object. When the branch is removed from aufs, | |
2427 | +the reference counter of the object is decremented. When it reaches | |
2428 | +zero, the dynamically generated operation object will be freed. | |
2429 | + | |
7e9cd9fe AM |
2430 | +This approach is designed to support AIO (io_submit), Direct I/O and |
2431 | +XIP (DAX) mainly. | |
2432 | +Currently this approach is applied to address_space_operations for | |
2433 | +regular files only. | |
53392da6 AM |
2434 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README |
2435 | --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 2436 | +++ linux/Documentation/filesystems/aufs/README 2017-05-06 22:16:52.774886674 +0200 |
f2c43d5f | 2437 | @@ -0,0 +1,393 @@ |
53392da6 | 2438 | + |
5527c038 | 2439 | +Aufs4 -- advanced multi layered unification filesystem version 4.x |
53392da6 AM |
2440 | +http://aufs.sf.net |
2441 | +Junjiro R. Okajima | |
2442 | + | |
2443 | + | |
2444 | +0. Introduction | |
2445 | +---------------------------------------- | |
2446 | +In the early days, aufs was entirely re-designed and re-implemented | |
7e9cd9fe | 2447 | +Unionfs Version 1.x series. Adding many original ideas, approaches, |
53392da6 AM |
2448 | +improvements and implementations, it becomes totally different from |
2449 | +Unionfs while keeping the basic features. | |
2450 | +Recently, Unionfs Version 2.x series begin taking some of the same | |
2451 | +approaches to aufs1's. | |
2452 | +Unionfs is being developed by Professor Erez Zadok at Stony Brook | |
2453 | +University and his team. | |
2454 | + | |
5527c038 | 2455 | +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3. |
53392da6 AM |
2456 | +If you want older kernel version support, try aufs2-2.6.git or |
2457 | +aufs2-standalone.git repository, aufs1 from CVS on SourceForge. | |
2458 | + | |
2459 | +Note: it becomes clear that "Aufs was rejected. Let's give it up." | |
38d290e6 JR |
2460 | + According to Christoph Hellwig, linux rejects all union-type |
2461 | + filesystems but UnionMount. | |
53392da6 AM |
2462 | +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2> |
2463 | + | |
38d290e6 JR |
2464 | +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and |
2465 | + UnionMount, and he pointed out an issue around a directory mutex | |
2466 | + lock and aufs addressed it. But it is still unsure whether aufs will | |
2467 | + be merged (or any other union solution). | |
076b876e | 2468 | +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1> |
38d290e6 | 2469 | + |
53392da6 AM |
2470 | + |
2471 | +1. Features | |
2472 | +---------------------------------------- | |
2473 | +- unite several directories into a single virtual filesystem. The member | |
2474 | + directory is called as a branch. | |
2475 | +- you can specify the permission flags to the branch, which are 'readonly', | |
2476 | + 'readwrite' and 'whiteout-able.' | |
2477 | +- by upper writable branch, internal copyup and whiteout, files/dirs on | |
2478 | + readonly branch are modifiable logically. | |
2479 | +- dynamic branch manipulation, add, del. | |
2480 | +- etc... | |
2481 | + | |
7e9cd9fe AM |
2482 | +Also there are many enhancements in aufs, such as: |
2483 | +- test only the highest one for the directory permission (dirperm1) | |
2484 | +- copyup on open (coo=) | |
2485 | +- 'move' policy for copy-up between two writable branches, after | |
2486 | + checking free space. | |
2487 | +- xattr, acl | |
53392da6 AM |
2488 | +- readdir(3) in userspace. |
2489 | +- keep inode number by external inode number table | |
2490 | +- keep the timestamps of file/dir in internal copyup operation | |
2491 | +- seekable directory, supporting NFS readdir. | |
2492 | +- whiteout is hardlinked in order to reduce the consumption of inodes | |
2493 | + on branch | |
2494 | +- do not copyup, nor create a whiteout when it is unnecessary | |
2495 | +- revert a single systemcall when an error occurs in aufs | |
2496 | +- remount interface instead of ioctl | |
2497 | +- maintain /etc/mtab by an external command, /sbin/mount.aufs. | |
2498 | +- loopback mounted filesystem as a branch | |
2499 | +- kernel thread for removing the dir who has a plenty of whiteouts | |
2500 | +- support copyup sparse file (a file which has a 'hole' in it) | |
2501 | +- default permission flags for branches | |
2502 | +- selectable permission flags for ro branch, whether whiteout can | |
2503 | + exist or not | |
2504 | +- export via NFS. | |
2505 | +- support <sysfs>/fs/aufs and <debugfs>/aufs. | |
2506 | +- support multiple writable branches, some policies to select one | |
2507 | + among multiple writable branches. | |
2508 | +- a new semantics for link(2) and rename(2) to support multiple | |
2509 | + writable branches. | |
2510 | +- no glibc changes are required. | |
2511 | +- pseudo hardlink (hardlink over branches) | |
2512 | +- allow a direct access manually to a file on branch, e.g. bypassing aufs. | |
2513 | + including NFS or remote filesystem branch. | |
2514 | +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX. | |
2515 | +- and more... | |
2516 | + | |
5527c038 | 2517 | +Currently these features are dropped temporary from aufs4. |
53392da6 | 2518 | +See design/08plan.txt in detail. |
53392da6 AM |
2519 | +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs |
2520 | + (robr) | |
2521 | +- statistics of aufs thread (/sys/fs/aufs/stat) | |
53392da6 AM |
2522 | + |
2523 | +Features or just an idea in the future (see also design/*.txt), | |
2524 | +- reorder the branch index without del/re-add. | |
2525 | +- permanent xino files for NFSD | |
2526 | +- an option for refreshing the opened files after add/del branches | |
53392da6 AM |
2527 | +- light version, without branch manipulation. (unnecessary?) |
2528 | +- copyup in userspace | |
2529 | +- inotify in userspace | |
2530 | +- readv/writev | |
53392da6 AM |
2531 | + |
2532 | + | |
2533 | +2. Download | |
2534 | +---------------------------------------- | |
5527c038 JR |
2535 | +There are three GIT trees for aufs4, aufs4-linux.git, |
2536 | +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in | |
1e00d052 | 2537 | +"aufs-util.git." |
5527c038 JR |
2538 | +While the aufs-util is always necessary, you need either of aufs4-linux |
2539 | +or aufs4-standalone. | |
1e00d052 | 2540 | + |
5527c038 | 2541 | +The aufs4-linux tree includes the whole linux mainline GIT tree, |
1e00d052 AM |
2542 | +git://git.kernel.org/.../torvalds/linux.git. |
2543 | +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot | |
5527c038 | 2544 | +build aufs4 as an external kernel module. |
2000de60 | 2545 | +Several extra patches are not included in this tree. Only |
be52b249 | 2546 | +aufs4-standalone tree contains them. They are described in the later |
2000de60 | 2547 | +section "Configuration and Compilation." |
1e00d052 | 2548 | + |
5527c038 | 2549 | +On the other hand, the aufs4-standalone tree has only aufs source files |
53392da6 | 2550 | +and necessary patches, and you can select CONFIG_AUFS_FS=m. |
2000de60 | 2551 | +But you need to apply all aufs patches manually. |
53392da6 | 2552 | + |
5527c038 JR |
2553 | +You will find GIT branches whose name is in form of "aufs4.x" where "x" |
2554 | +represents the linux kernel version, "linux-4.x". For instance, | |
2555 | +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use | |
2556 | +"aufs4.x-rcN" branch. | |
1e00d052 | 2557 | + |
5527c038 | 2558 | +o aufs4-linux tree |
1e00d052 | 2559 | +$ git clone --reference /your/linux/git/tree \ |
5527c038 | 2560 | + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git |
1e00d052 | 2561 | +- if you don't have linux GIT tree, then remove "--reference ..." |
5527c038 JR |
2562 | +$ cd aufs4-linux.git |
2563 | +$ git checkout origin/aufs4.0 | |
53392da6 | 2564 | + |
2000de60 JR |
2565 | +Or You may want to directly git-pull aufs into your linux GIT tree, and |
2566 | +leave the patch-work to GIT. | |
2567 | +$ cd /your/linux/git/tree | |
5527c038 JR |
2568 | +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git |
2569 | +$ git fetch aufs4 | |
2570 | +$ git checkout -b my4.0 v4.0 | |
2571 | +$ (add your local change...) | |
2572 | +$ git pull aufs4 aufs4.0 | |
2573 | +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch. | |
2000de60 | 2574 | +- you may need to solve some conflicts between your_changes and |
5527c038 JR |
2575 | + aufs4.0. in this case, git-rerere is recommended so that you can |
2576 | + solve the similar conflicts automatically when you upgrade to 4.1 or | |
2000de60 JR |
2577 | + later in the future. |
2578 | + | |
5527c038 JR |
2579 | +o aufs4-standalone tree |
2580 | +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git | |
2581 | +$ cd aufs4-standalone.git | |
2582 | +$ git checkout origin/aufs4.0 | |
53392da6 AM |
2583 | + |
2584 | +o aufs-util tree | |
5527c038 JR |
2585 | +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git |
2586 | +- note that the public aufs-util.git is on SourceForge instead of | |
2587 | + GitHUB. | |
53392da6 | 2588 | +$ cd aufs-util.git |
5527c038 | 2589 | +$ git checkout origin/aufs4.0 |
53392da6 | 2590 | + |
5527c038 JR |
2591 | +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY. |
2592 | +The minor version number, 'x' in '4.x', of aufs may not always | |
9dbd164d AM |
2593 | +follow the minor version number of the kernel. |
2594 | +Because changes in the kernel that cause the use of a new | |
2595 | +minor version number do not always require changes to aufs-util. | |
2596 | + | |
2597 | +Since aufs-util has its own minor version number, you may not be | |
2598 | +able to find a GIT branch in aufs-util for your kernel's | |
2599 | +exact minor version number. | |
2600 | +In this case, you should git-checkout the branch for the | |
53392da6 | 2601 | +nearest lower number. |
9dbd164d AM |
2602 | + |
2603 | +For (an unreleased) example: | |
5527c038 JR |
2604 | +If you are using "linux-4.10" and the "aufs4.10" branch |
2605 | +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8" | |
9dbd164d AM |
2606 | +or something numerically smaller is the branch for your kernel. |
2607 | + | |
53392da6 AM |
2608 | +Also you can view all branches by |
2609 | + $ git branch -a | |
2610 | + | |
2611 | + | |
2612 | +3. Configuration and Compilation | |
2613 | +---------------------------------------- | |
2614 | +Make sure you have git-checkout'ed the correct branch. | |
2615 | + | |
5527c038 | 2616 | +For aufs4-linux tree, |
c06a8ce3 | 2617 | +- enable CONFIG_AUFS_FS. |
1e00d052 AM |
2618 | +- set other aufs configurations if necessary. |
2619 | + | |
5527c038 | 2620 | +For aufs4-standalone tree, |
53392da6 AM |
2621 | +There are several ways to build. |
2622 | + | |
2623 | +1. | |
5527c038 JR |
2624 | +- apply ./aufs4-kbuild.patch to your kernel source files. |
2625 | +- apply ./aufs4-base.patch too. | |
2626 | +- apply ./aufs4-mmap.patch too. | |
2627 | +- apply ./aufs4-standalone.patch too, if you have a plan to set | |
2628 | + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch. | |
537831f9 AM |
2629 | +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your |
2630 | + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild. | |
c06a8ce3 | 2631 | +- enable CONFIG_AUFS_FS, you can select either |
53392da6 AM |
2632 | + =m or =y. |
2633 | +- and build your kernel as usual. | |
2634 | +- install the built kernel. | |
c06a8ce3 AM |
2635 | + Note: Since linux-3.9, every filesystem module requires an alias |
2636 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2637 | + modules.aliases file if you set CONFIG_AUFS_FS=m. | |
7eafdf33 AM |
2638 | +- install the header files too by "make headers_install" to the |
2639 | + directory where you specify. By default, it is $PWD/usr. | |
b4510431 | 2640 | + "make help" shows a brief note for headers_install. |
53392da6 AM |
2641 | +- and reboot your system. |
2642 | + | |
2643 | +2. | |
2644 | +- module only (CONFIG_AUFS_FS=m). | |
5527c038 JR |
2645 | +- apply ./aufs4-base.patch to your kernel source files. |
2646 | +- apply ./aufs4-mmap.patch too. | |
2647 | +- apply ./aufs4-standalone.patch too. | |
53392da6 AM |
2648 | +- build your kernel, don't forget "make headers_install", and reboot. |
2649 | +- edit ./config.mk and set other aufs configurations if necessary. | |
b4510431 | 2650 | + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes |
53392da6 AM |
2651 | + every aufs configurations. |
2652 | +- build the module by simple "make". | |
c06a8ce3 AM |
2653 | + Note: Since linux-3.9, every filesystem module requires an alias |
2654 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2655 | + modules.aliases file. | |
53392da6 AM |
2656 | +- you can specify ${KDIR} make variable which points to your kernel |
2657 | + source tree. | |
2658 | +- install the files | |
2659 | + + run "make install" to install the aufs module, or copy the built | |
b4510431 AM |
2660 | + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply). |
2661 | + + run "make install_headers" (instead of headers_install) to install | |
2662 | + the modified aufs header file (you can specify DESTDIR which is | |
2663 | + available in aufs standalone version's Makefile only), or copy | |
2664 | + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever | |
2665 | + you like manually. By default, the target directory is $PWD/usr. | |
5527c038 | 2666 | +- no need to apply aufs4-kbuild.patch, nor copying source files to your |
53392da6 AM |
2667 | + kernel source tree. |
2668 | + | |
b4510431 | 2669 | +Note: The header file aufs_type.h is necessary to build aufs-util |
53392da6 AM |
2670 | + as well as "make headers_install" in the kernel source tree. |
2671 | + headers_install is subject to be forgotten, but it is essentially | |
2672 | + necessary, not only for building aufs-util. | |
2673 | + You may not meet problems without headers_install in some older | |
2674 | + version though. | |
2675 | + | |
2676 | +And then, | |
2677 | +- read README in aufs-util, build and install it | |
9dbd164d AM |
2678 | +- note that your distribution may contain an obsoleted version of |
2679 | + aufs_type.h in /usr/include/linux or something. When you build aufs | |
2680 | + utilities, make sure that your compiler refers the correct aufs header | |
2681 | + file which is built by "make headers_install." | |
53392da6 AM |
2682 | +- if you want to use readdir(3) in userspace or pathconf(3) wrapper, |
2683 | + then run "make install_ulib" too. And refer to the aufs manual in | |
2684 | + detail. | |
2685 | + | |
5527c038 | 2686 | +There several other patches in aufs4-standalone.git. They are all |
38d290e6 | 2687 | +optional. When you meet some problems, they will help you. |
5527c038 | 2688 | +- aufs4-loopback.patch |
38d290e6 JR |
2689 | + Supports a nested loopback mount in a branch-fs. This patch is |
2690 | + unnecessary until aufs produces a message like "you may want to try | |
2691 | + another patch for loopback file". | |
2692 | +- vfs-ino.patch | |
2693 | + Modifies a system global kernel internal function get_next_ino() in | |
2694 | + order to stop assigning 0 for an inode-number. Not directly related to | |
2695 | + aufs, but recommended generally. | |
2696 | +- tmpfs-idr.patch | |
2697 | + Keeps the tmpfs inode number as the lowest value. Effective to reduce | |
2698 | + the size of aufs XINO files for tmpfs branch. Also it prevents the | |
2699 | + duplication of inode number, which is important for backup tools and | |
2700 | + other utilities. When you find aufs XINO files for tmpfs branch | |
2701 | + growing too much, try this patch. | |
be52b249 AM |
2702 | +- lockdep-debug.patch |
2703 | + Because aufs is not only an ordinary filesystem (callee of VFS), but | |
2704 | + also a caller of VFS functions for branch filesystems, subclassing of | |
2705 | + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging | |
2706 | + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will | |
2707 | + need to apply this debug patch to expand several constant values. | |
2708 | + If don't know what LOCKDEP, then you don't have apply this patch. | |
38d290e6 | 2709 | + |
53392da6 AM |
2710 | + |
2711 | +4. Usage | |
2712 | +---------------------------------------- | |
2713 | +At first, make sure aufs-util are installed, and please read the aufs | |
2714 | +manual, aufs.5 in aufs-util.git tree. | |
2715 | +$ man -l aufs.5 | |
2716 | + | |
2717 | +And then, | |
2718 | +$ mkdir /tmp/rw /tmp/aufs | |
2719 | +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs | |
2720 | + | |
2721 | +Here is another example. The result is equivalent. | |
2722 | +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs | |
2723 | + Or | |
2724 | +# mount -t aufs -o br:/tmp/rw none /tmp/aufs | |
2725 | +# mount -o remount,append:${HOME} /tmp/aufs | |
2726 | + | |
2727 | +Then, you can see whole tree of your home dir through /tmp/aufs. If | |
2728 | +you modify a file under /tmp/aufs, the one on your home directory is | |
2729 | +not affected, instead the same named file will be newly created under | |
2730 | +/tmp/rw. And all of your modification to a file will be applied to | |
2731 | +the one under /tmp/rw. This is called the file based Copy on Write | |
2732 | +(COW) method. | |
2733 | +Aufs mount options are described in aufs.5. | |
2734 | +If you run chroot or something and make your aufs as a root directory, | |
2735 | +then you need to customize the shutdown script. See the aufs manual in | |
2736 | +detail. | |
2737 | + | |
2738 | +Additionally, there are some sample usages of aufs which are a | |
2739 | +diskless system with network booting, and LiveCD over NFS. | |
2740 | +See sample dir in CVS tree on SourceForge. | |
2741 | + | |
2742 | + | |
2743 | +5. Contact | |
2744 | +---------------------------------------- | |
2745 | +When you have any problems or strange behaviour in aufs, please let me | |
2746 | +know with: | |
2747 | +- /proc/mounts (instead of the output of mount(8)) | |
2748 | +- /sys/module/aufs/* | |
2749 | +- /sys/fs/aufs/* (if you have them) | |
2750 | +- /debug/aufs/* (if you have them) | |
2751 | +- linux kernel version | |
2752 | + if your kernel is not plain, for example modified by distributor, | |
2753 | + the url where i can download its source is necessary too. | |
2754 | +- aufs version which was printed at loading the module or booting the | |
2755 | + system, instead of the date you downloaded. | |
2756 | +- configuration (define/undefine CONFIG_AUFS_xxx) | |
2757 | +- kernel configuration or /proc/config.gz (if you have it) | |
2758 | +- behaviour which you think to be incorrect | |
2759 | +- actual operation, reproducible one is better | |
2760 | +- mailto: aufs-users at lists.sourceforge.net | |
2761 | + | |
2762 | +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches, | |
2763 | +and Feature Requests) on SourceForge. Please join and write to | |
2764 | +aufs-users ML. | |
2765 | + | |
2766 | + | |
2767 | +6. Acknowledgements | |
2768 | +---------------------------------------- | |
2769 | +Thanks to everyone who have tried and are using aufs, whoever | |
2770 | +have reported a bug or any feedback. | |
2771 | + | |
2772 | +Especially donators: | |
2773 | +Tomas Matejicek(slax.org) made a donation (much more than once). | |
2774 | + Since Apr 2010, Tomas M (the author of Slax and Linux Live | |
2775 | + scripts) is making "doubling" donations. | |
2776 | + Unfortunately I cannot list all of the donators, but I really | |
b4510431 | 2777 | + appreciate. |
53392da6 AM |
2778 | + It ends Aug 2010, but the ordinary donation URL is still available. |
2779 | + <http://sourceforge.net/donate/index.php?group_id=167503> | |
2780 | +Dai Itasaka made a donation (2007/8). | |
2781 | +Chuck Smith made a donation (2008/4, 10 and 12). | |
2782 | +Henk Schoneveld made a donation (2008/9). | |
2783 | +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10). | |
2784 | +Francois Dupoux made a donation (2008/11). | |
2785 | +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public | |
2786 | + aufs2 GIT tree (2009/2). | |
2787 | +William Grant made a donation (2009/3). | |
2788 | +Patrick Lane made a donation (2009/4). | |
2789 | +The Mail Archive (mail-archive.com) made donations (2009/5). | |
2790 | +Nippy Networks (Ed Wildgoose) made a donation (2009/7). | |
2791 | +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11). | |
2792 | +Pavel Pronskiy made a donation (2011/2). | |
2793 | +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy | |
2794 | + Networks (Ed Wildgoose) made a donation for hardware (2011/3). | |
537831f9 AM |
2795 | +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and |
2796 | +11). | |
1e00d052 | 2797 | +Sam Liddicott made a donation (2011/9). |
86dc4139 AM |
2798 | +Era Scarecrow made a donation (2013/4). |
2799 | +Bor Ratajc made a donation (2013/4). | |
2800 | +Alessandro Gorreta made a donation (2013/4). | |
2801 | +POIRETTE Marc made a donation (2013/4). | |
2802 | +Alessandro Gorreta made a donation (2013/4). | |
2803 | +lauri kasvandik made a donation (2013/5). | |
392086de | 2804 | +"pemasu from Finland" made a donation (2013/7). |
523b37e3 AM |
2805 | +The Parted Magic Project made a donation (2013/9 and 11). |
2806 | +Pavel Barta made a donation (2013/10). | |
38d290e6 | 2807 | +Nikolay Pertsev made a donation (2014/5). |
c2c0f25c | 2808 | +James B made a donation (2014/7 and 2015/7). |
076b876e | 2809 | +Stefano Di Biase made a donation (2014/8). |
2000de60 | 2810 | +Daniel Epellei made a donation (2015/1). |
8cdd5066 | 2811 | +OmegaPhil made a donation (2016/1). |
5afbbe0d | 2812 | +Tomasz Szewczyk made a donation (2016/4). |
f2c43d5f | 2813 | +James Burry made a donation (2016/12). |
53392da6 AM |
2814 | + |
2815 | +Thank you very much. | |
2816 | +Donations are always, including future donations, very important and | |
2817 | +helpful for me to keep on developing aufs. | |
2818 | + | |
2819 | + | |
2820 | +7. | |
2821 | +---------------------------------------- | |
2822 | +If you are an experienced user, no explanation is needed. Aufs is | |
2823 | +just a linux filesystem. | |
2824 | + | |
2825 | + | |
2826 | +Enjoy! | |
2827 | + | |
2828 | +# Local variables: ; | |
2829 | +# mode: text; | |
2830 | +# End: ; | |
7f207e10 AM |
2831 | diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h |
2832 | --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 2833 | +++ linux/fs/aufs/aufs.h 2017-05-06 22:16:52.774886674 +0200 |
523b37e3 | 2834 | @@ -0,0 +1,59 @@ |
7f207e10 | 2835 | +/* |
a2654f78 | 2836 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
7f207e10 AM |
2837 | + * |
2838 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2839 | + * it under the terms of the GNU General Public License as published by | |
2840 | + * the Free Software Foundation; either version 2 of the License, or | |
2841 | + * (at your option) any later version. | |
2842 | + * | |
2843 | + * This program is distributed in the hope that it will be useful, | |
2844 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2845 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2846 | + * GNU General Public License for more details. | |
2847 | + * | |
2848 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2849 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2850 | + */ |
2851 | + | |
2852 | +/* | |
2853 | + * all header files | |
2854 | + */ | |
2855 | + | |
2856 | +#ifndef __AUFS_H__ | |
2857 | +#define __AUFS_H__ | |
2858 | + | |
2859 | +#ifdef __KERNEL__ | |
2860 | + | |
2861 | +#define AuStub(type, name, body, ...) \ | |
2862 | + static inline type name(__VA_ARGS__) { body; } | |
2863 | + | |
2864 | +#define AuStubVoid(name, ...) \ | |
2865 | + AuStub(void, name, , __VA_ARGS__) | |
2866 | +#define AuStubInt0(name, ...) \ | |
2867 | + AuStub(int, name, return 0, __VA_ARGS__) | |
2868 | + | |
2869 | +#include "debug.h" | |
2870 | + | |
2871 | +#include "branch.h" | |
2872 | +#include "cpup.h" | |
2873 | +#include "dcsub.h" | |
2874 | +#include "dbgaufs.h" | |
2875 | +#include "dentry.h" | |
2876 | +#include "dir.h" | |
2877 | +#include "dynop.h" | |
2878 | +#include "file.h" | |
2879 | +#include "fstype.h" | |
2880 | +#include "inode.h" | |
2881 | +#include "loop.h" | |
2882 | +#include "module.h" | |
7f207e10 AM |
2883 | +#include "opts.h" |
2884 | +#include "rwsem.h" | |
2885 | +#include "spl.h" | |
2886 | +#include "super.h" | |
2887 | +#include "sysaufs.h" | |
2888 | +#include "vfsub.h" | |
2889 | +#include "whout.h" | |
2890 | +#include "wkq.h" | |
2891 | + | |
2892 | +#endif /* __KERNEL__ */ | |
2893 | +#endif /* __AUFS_H__ */ | |
2894 | diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c | |
2895 | --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
2896 | +++ linux/fs/aufs/branch.c 2017-05-06 22:16:52.774886674 +0200 |
2897 | @@ -0,0 +1,1423 @@ | |
7f207e10 | 2898 | +/* |
a2654f78 | 2899 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
7f207e10 AM |
2900 | + * |
2901 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2902 | + * it under the terms of the GNU General Public License as published by | |
2903 | + * the Free Software Foundation; either version 2 of the License, or | |
2904 | + * (at your option) any later version. | |
2905 | + * | |
2906 | + * This program is distributed in the hope that it will be useful, | |
2907 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2908 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2909 | + * GNU General Public License for more details. | |
2910 | + * | |
2911 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2912 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2913 | + */ |
2914 | + | |
2915 | +/* | |
2916 | + * branch management | |
2917 | + */ | |
2918 | + | |
027c5e7a | 2919 | +#include <linux/compat.h> |
7f207e10 AM |
2920 | +#include <linux/statfs.h> |
2921 | +#include "aufs.h" | |
2922 | + | |
2923 | +/* | |
2924 | + * free a single branch | |
1facf9fc | 2925 | + */ |
2926 | +static void au_br_do_free(struct au_branch *br) | |
2927 | +{ | |
2928 | + int i; | |
2929 | + struct au_wbr *wbr; | |
4a4d8108 | 2930 | + struct au_dykey **key; |
1facf9fc | 2931 | + |
027c5e7a AM |
2932 | + au_hnotify_fin_br(br); |
2933 | + | |
1facf9fc | 2934 | + if (br->br_xino.xi_file) |
2935 | + fput(br->br_xino.xi_file); | |
521ced18 JR |
2936 | + for (i = br->br_xino.xi_nondir.total - 1; i >= 0; i--) |
2937 | + AuDebugOn(br->br_xino.xi_nondir.array[i]); | |
2938 | + au_delayed_kfree(br->br_xino.xi_nondir.array); | |
1facf9fc | 2939 | + |
5afbbe0d AM |
2940 | + AuDebugOn(au_br_count(br)); |
2941 | + au_br_count_fin(br); | |
1facf9fc | 2942 | + |
2943 | + wbr = br->br_wbr; | |
2944 | + if (wbr) { | |
2945 | + for (i = 0; i < AuBrWh_Last; i++) | |
2946 | + dput(wbr->wbr_wh[i]); | |
2947 | + AuDebugOn(atomic_read(&wbr->wbr_wh_running)); | |
dece6358 | 2948 | + AuRwDestroy(&wbr->wbr_wh_rwsem); |
1facf9fc | 2949 | + } |
2950 | + | |
076b876e AM |
2951 | + if (br->br_fhsm) { |
2952 | + au_br_fhsm_fin(br->br_fhsm); | |
f0c0a007 | 2953 | + au_delayed_kfree(br->br_fhsm); |
076b876e AM |
2954 | + } |
2955 | + | |
4a4d8108 AM |
2956 | + key = br->br_dykey; |
2957 | + for (i = 0; i < AuBrDynOp; i++, key++) | |
2958 | + if (*key) | |
2959 | + au_dy_put(*key); | |
2960 | + else | |
2961 | + break; | |
2962 | + | |
537831f9 AM |
2963 | + /* recursive lock, s_umount of branch's */ |
2964 | + lockdep_off(); | |
86dc4139 | 2965 | + path_put(&br->br_path); |
537831f9 | 2966 | + lockdep_on(); |
f0c0a007 AM |
2967 | + if (wbr) |
2968 | + au_delayed_kfree(wbr); | |
2969 | + au_delayed_kfree(br); | |
1facf9fc | 2970 | +} |
2971 | + | |
2972 | +/* | |
2973 | + * frees all branches | |
2974 | + */ | |
2975 | +void au_br_free(struct au_sbinfo *sbinfo) | |
2976 | +{ | |
2977 | + aufs_bindex_t bmax; | |
2978 | + struct au_branch **br; | |
2979 | + | |
dece6358 AM |
2980 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
2981 | + | |
5afbbe0d | 2982 | + bmax = sbinfo->si_bbot + 1; |
1facf9fc | 2983 | + br = sbinfo->si_branch; |
2984 | + while (bmax--) | |
2985 | + au_br_do_free(*br++); | |
2986 | +} | |
2987 | + | |
2988 | +/* | |
2989 | + * find the index of a branch which is specified by @br_id. | |
2990 | + */ | |
2991 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id) | |
2992 | +{ | |
5afbbe0d | 2993 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 2994 | + |
5afbbe0d AM |
2995 | + bbot = au_sbbot(sb); |
2996 | + for (bindex = 0; bindex <= bbot; bindex++) | |
1facf9fc | 2997 | + if (au_sbr_id(sb, bindex) == br_id) |
2998 | + return bindex; | |
2999 | + return -1; | |
3000 | +} | |
3001 | + | |
3002 | +/* ---------------------------------------------------------------------- */ | |
3003 | + | |
3004 | +/* | |
3005 | + * add a branch | |
3006 | + */ | |
3007 | + | |
b752ccd1 AM |
3008 | +static int test_overlap(struct super_block *sb, struct dentry *h_adding, |
3009 | + struct dentry *h_root) | |
1facf9fc | 3010 | +{ |
b752ccd1 AM |
3011 | + if (unlikely(h_adding == h_root |
3012 | + || au_test_loopback_overlap(sb, h_adding))) | |
1facf9fc | 3013 | + return 1; |
b752ccd1 AM |
3014 | + if (h_adding->d_sb != h_root->d_sb) |
3015 | + return 0; | |
3016 | + return au_test_subdir(h_adding, h_root) | |
3017 | + || au_test_subdir(h_root, h_adding); | |
1facf9fc | 3018 | +} |
3019 | + | |
3020 | +/* | |
3021 | + * returns a newly allocated branch. @new_nbranch is a number of branches | |
3022 | + * after adding a branch. | |
3023 | + */ | |
3024 | +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch, | |
3025 | + int perm) | |
3026 | +{ | |
3027 | + struct au_branch *add_branch; | |
3028 | + struct dentry *root; | |
5527c038 | 3029 | + struct inode *inode; |
4a4d8108 | 3030 | + int err; |
1facf9fc | 3031 | + |
4a4d8108 | 3032 | + err = -ENOMEM; |
be52b249 | 3033 | + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS); |
1facf9fc | 3034 | + if (unlikely(!add_branch)) |
3035 | + goto out; | |
521ced18 JR |
3036 | + add_branch->br_xino.xi_nondir.total = 8; /* initial size */ |
3037 | + add_branch->br_xino.xi_nondir.array | |
3038 | + = kzalloc(sizeof(ino_t) * add_branch->br_xino.xi_nondir.total, | |
3039 | + GFP_NOFS); | |
3040 | + if (unlikely(!add_branch->br_xino.xi_nondir.array)) | |
3041 | + goto out_br; | |
1facf9fc | 3042 | + |
027c5e7a AM |
3043 | + err = au_hnotify_init_br(add_branch, perm); |
3044 | + if (unlikely(err)) | |
521ced18 | 3045 | + goto out_xinondir; |
027c5e7a | 3046 | + |
1facf9fc | 3047 | + if (au_br_writable(perm)) { |
3048 | + /* may be freed separately at changing the branch permission */ | |
be52b249 | 3049 | + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr), |
1facf9fc | 3050 | + GFP_NOFS); |
3051 | + if (unlikely(!add_branch->br_wbr)) | |
027c5e7a | 3052 | + goto out_hnotify; |
1facf9fc | 3053 | + } |
3054 | + | |
076b876e AM |
3055 | + if (au_br_fhsm(perm)) { |
3056 | + err = au_fhsm_br_alloc(add_branch); | |
3057 | + if (unlikely(err)) | |
3058 | + goto out_wbr; | |
3059 | + } | |
3060 | + | |
521ced18 | 3061 | + root = sb->s_root; |
e2f27e51 | 3062 | + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0); |
4a4d8108 | 3063 | + if (!err) |
e2f27e51 | 3064 | + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0); |
5527c038 JR |
3065 | + if (!err) { |
3066 | + inode = d_inode(root); | |
e2f27e51 | 3067 | + err = au_hinode_realloc(au_ii(inode), new_nbranch, /*may_shrink*/0); |
5527c038 | 3068 | + } |
4a4d8108 AM |
3069 | + if (!err) |
3070 | + return add_branch; /* success */ | |
1facf9fc | 3071 | + |
076b876e | 3072 | +out_wbr: |
f0c0a007 AM |
3073 | + if (add_branch->br_wbr) |
3074 | + au_delayed_kfree(add_branch->br_wbr); | |
027c5e7a AM |
3075 | +out_hnotify: |
3076 | + au_hnotify_fin_br(add_branch); | |
521ced18 JR |
3077 | +out_xinondir: |
3078 | + au_delayed_kfree(add_branch->br_xino.xi_nondir.array); | |
4f0767ce | 3079 | +out_br: |
f0c0a007 | 3080 | + au_delayed_kfree(add_branch); |
4f0767ce | 3081 | +out: |
4a4d8108 | 3082 | + return ERR_PTR(err); |
1facf9fc | 3083 | +} |
3084 | + | |
3085 | +/* | |
3086 | + * test if the branch permission is legal or not. | |
3087 | + */ | |
3088 | +static int test_br(struct inode *inode, int brperm, char *path) | |
3089 | +{ | |
3090 | + int err; | |
3091 | + | |
4a4d8108 AM |
3092 | + err = (au_br_writable(brperm) && IS_RDONLY(inode)); |
3093 | + if (!err) | |
3094 | + goto out; | |
1facf9fc | 3095 | + |
4a4d8108 AM |
3096 | + err = -EINVAL; |
3097 | + pr_err("write permission for readonly mount or inode, %s\n", path); | |
3098 | + | |
4f0767ce | 3099 | +out: |
1facf9fc | 3100 | + return err; |
3101 | +} | |
3102 | + | |
3103 | +/* | |
3104 | + * returns: | |
3105 | + * 0: success, the caller will add it | |
3106 | + * plus: success, it is already unified, the caller should ignore it | |
3107 | + * minus: error | |
3108 | + */ | |
3109 | +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3110 | +{ | |
3111 | + int err; | |
5afbbe0d | 3112 | + aufs_bindex_t bbot, bindex; |
5527c038 | 3113 | + struct dentry *root, *h_dentry; |
1facf9fc | 3114 | + struct inode *inode, *h_inode; |
3115 | + | |
3116 | + root = sb->s_root; | |
5afbbe0d AM |
3117 | + bbot = au_sbbot(sb); |
3118 | + if (unlikely(bbot >= 0 | |
1facf9fc | 3119 | + && au_find_dbindex(root, add->path.dentry) >= 0)) { |
3120 | + err = 1; | |
3121 | + if (!remount) { | |
3122 | + err = -EINVAL; | |
4a4d8108 | 3123 | + pr_err("%s duplicated\n", add->pathname); |
1facf9fc | 3124 | + } |
3125 | + goto out; | |
3126 | + } | |
3127 | + | |
3128 | + err = -ENOSPC; /* -E2BIG; */ | |
3129 | + if (unlikely(AUFS_BRANCH_MAX <= add->bindex | |
5afbbe0d | 3130 | + || AUFS_BRANCH_MAX - 1 <= bbot)) { |
4a4d8108 | 3131 | + pr_err("number of branches exceeded %s\n", add->pathname); |
1facf9fc | 3132 | + goto out; |
3133 | + } | |
3134 | + | |
3135 | + err = -EDOM; | |
5afbbe0d | 3136 | + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) { |
4a4d8108 | 3137 | + pr_err("bad index %d\n", add->bindex); |
1facf9fc | 3138 | + goto out; |
3139 | + } | |
3140 | + | |
5527c038 | 3141 | + inode = d_inode(add->path.dentry); |
1facf9fc | 3142 | + err = -ENOENT; |
3143 | + if (unlikely(!inode->i_nlink)) { | |
4a4d8108 | 3144 | + pr_err("no existence %s\n", add->pathname); |
1facf9fc | 3145 | + goto out; |
3146 | + } | |
3147 | + | |
3148 | + err = -EINVAL; | |
3149 | + if (unlikely(inode->i_sb == sb)) { | |
4a4d8108 | 3150 | + pr_err("%s must be outside\n", add->pathname); |
1facf9fc | 3151 | + goto out; |
3152 | + } | |
3153 | + | |
3154 | + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) { | |
4a4d8108 AM |
3155 | + pr_err("unsupported filesystem, %s (%s)\n", |
3156 | + add->pathname, au_sbtype(inode->i_sb)); | |
1facf9fc | 3157 | + goto out; |
3158 | + } | |
3159 | + | |
c1595e42 JR |
3160 | + if (unlikely(inode->i_sb->s_stack_depth)) { |
3161 | + pr_err("already stacked, %s (%s)\n", | |
3162 | + add->pathname, au_sbtype(inode->i_sb)); | |
3163 | + goto out; | |
3164 | + } | |
3165 | + | |
5527c038 | 3166 | + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname); |
1facf9fc | 3167 | + if (unlikely(err)) |
3168 | + goto out; | |
3169 | + | |
5afbbe0d | 3170 | + if (bbot < 0) |
1facf9fc | 3171 | + return 0; /* success */ |
3172 | + | |
3173 | + err = -EINVAL; | |
5afbbe0d | 3174 | + for (bindex = 0; bindex <= bbot; bindex++) |
1facf9fc | 3175 | + if (unlikely(test_overlap(sb, add->path.dentry, |
3176 | + au_h_dptr(root, bindex)))) { | |
4a4d8108 | 3177 | + pr_err("%s is overlapped\n", add->pathname); |
1facf9fc | 3178 | + goto out; |
3179 | + } | |
3180 | + | |
3181 | + err = 0; | |
3182 | + if (au_opt_test(au_mntflags(sb), WARN_PERM)) { | |
5527c038 JR |
3183 | + h_dentry = au_h_dptr(root, 0); |
3184 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 3185 | + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO) |
0c3ec466 AM |
3186 | + || !uid_eq(h_inode->i_uid, inode->i_uid) |
3187 | + || !gid_eq(h_inode->i_gid, inode->i_gid)) | |
3188 | + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n", | |
3189 | + add->pathname, | |
3190 | + i_uid_read(inode), i_gid_read(inode), | |
3191 | + (inode->i_mode & S_IALLUGO), | |
3192 | + i_uid_read(h_inode), i_gid_read(h_inode), | |
3193 | + (h_inode->i_mode & S_IALLUGO)); | |
1facf9fc | 3194 | + } |
3195 | + | |
4f0767ce | 3196 | +out: |
1facf9fc | 3197 | + return err; |
3198 | +} | |
3199 | + | |
3200 | +/* | |
3201 | + * initialize or clean the whiteouts for an adding branch | |
3202 | + */ | |
3203 | +static int au_br_init_wh(struct super_block *sb, struct au_branch *br, | |
86dc4139 | 3204 | + int new_perm) |
1facf9fc | 3205 | +{ |
3206 | + int err, old_perm; | |
3207 | + aufs_bindex_t bindex; | |
febd17d6 | 3208 | + struct inode *h_inode; |
1facf9fc | 3209 | + struct au_wbr *wbr; |
3210 | + struct au_hinode *hdir; | |
5527c038 | 3211 | + struct dentry *h_dentry; |
1facf9fc | 3212 | + |
86dc4139 AM |
3213 | + err = vfsub_mnt_want_write(au_br_mnt(br)); |
3214 | + if (unlikely(err)) | |
3215 | + goto out; | |
3216 | + | |
1facf9fc | 3217 | + wbr = br->br_wbr; |
3218 | + old_perm = br->br_perm; | |
3219 | + br->br_perm = new_perm; | |
3220 | + hdir = NULL; | |
febd17d6 | 3221 | + h_inode = NULL; |
1facf9fc | 3222 | + bindex = au_br_index(sb, br->br_id); |
3223 | + if (0 <= bindex) { | |
5527c038 | 3224 | + hdir = au_hi(d_inode(sb->s_root), bindex); |
5afbbe0d | 3225 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 3226 | + } else { |
5527c038 | 3227 | + h_dentry = au_br_dentry(br); |
febd17d6 JR |
3228 | + h_inode = d_inode(h_dentry); |
3229 | + inode_lock_nested(h_inode, AuLsc_I_PARENT); | |
1facf9fc | 3230 | + } |
3231 | + if (!wbr) | |
86dc4139 | 3232 | + err = au_wh_init(br, sb); |
1facf9fc | 3233 | + else { |
3234 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 3235 | + err = au_wh_init(br, sb); |
1facf9fc | 3236 | + wbr_wh_write_unlock(wbr); |
3237 | + } | |
3238 | + if (hdir) | |
5afbbe0d | 3239 | + au_hn_inode_unlock(hdir); |
1facf9fc | 3240 | + else |
febd17d6 | 3241 | + inode_unlock(h_inode); |
86dc4139 | 3242 | + vfsub_mnt_drop_write(au_br_mnt(br)); |
1facf9fc | 3243 | + br->br_perm = old_perm; |
3244 | + | |
3245 | + if (!err && wbr && !au_br_writable(new_perm)) { | |
f0c0a007 | 3246 | + au_delayed_kfree(wbr); |
1facf9fc | 3247 | + br->br_wbr = NULL; |
3248 | + } | |
3249 | + | |
86dc4139 | 3250 | +out: |
1facf9fc | 3251 | + return err; |
3252 | +} | |
3253 | + | |
3254 | +static int au_wbr_init(struct au_branch *br, struct super_block *sb, | |
86dc4139 | 3255 | + int perm) |
1facf9fc | 3256 | +{ |
3257 | + int err; | |
4a4d8108 | 3258 | + struct kstatfs kst; |
1facf9fc | 3259 | + struct au_wbr *wbr; |
3260 | + | |
3261 | + wbr = br->br_wbr; | |
dece6358 | 3262 | + au_rw_init(&wbr->wbr_wh_rwsem); |
1facf9fc | 3263 | + atomic_set(&wbr->wbr_wh_running, 0); |
1facf9fc | 3264 | + |
4a4d8108 AM |
3265 | + /* |
3266 | + * a limit for rmdir/rename a dir | |
523b37e3 | 3267 | + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h |
4a4d8108 | 3268 | + */ |
86dc4139 | 3269 | + err = vfs_statfs(&br->br_path, &kst); |
4a4d8108 AM |
3270 | + if (unlikely(err)) |
3271 | + goto out; | |
3272 | + err = -EINVAL; | |
3273 | + if (kst.f_namelen >= NAME_MAX) | |
86dc4139 | 3274 | + err = au_br_init_wh(sb, br, perm); |
4a4d8108 | 3275 | + else |
523b37e3 AM |
3276 | + pr_err("%pd(%s), unsupported namelen %ld\n", |
3277 | + au_br_dentry(br), | |
86dc4139 | 3278 | + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen); |
1facf9fc | 3279 | + |
4f0767ce | 3280 | +out: |
1facf9fc | 3281 | + return err; |
3282 | +} | |
3283 | + | |
c1595e42 | 3284 | +/* initialize a new branch */ |
1facf9fc | 3285 | +static int au_br_init(struct au_branch *br, struct super_block *sb, |
3286 | + struct au_opt_add *add) | |
3287 | +{ | |
3288 | + int err; | |
5527c038 | 3289 | + struct inode *h_inode; |
1facf9fc | 3290 | + |
3291 | + err = 0; | |
521ced18 JR |
3292 | + spin_lock_init(&br->br_xino.xi_nondir.spin); |
3293 | + init_waitqueue_head(&br->br_xino.xi_nondir.wqh); | |
1facf9fc | 3294 | + br->br_perm = add->perm; |
86dc4139 | 3295 | + br->br_path = add->path; /* set first, path_get() later */ |
4a4d8108 | 3296 | + spin_lock_init(&br->br_dykey_lock); |
5afbbe0d | 3297 | + au_br_count_init(br); |
1facf9fc | 3298 | + atomic_set(&br->br_xino_running, 0); |
3299 | + br->br_id = au_new_br_id(sb); | |
7f207e10 | 3300 | + AuDebugOn(br->br_id < 0); |
1facf9fc | 3301 | + |
3302 | + if (au_br_writable(add->perm)) { | |
86dc4139 | 3303 | + err = au_wbr_init(br, sb, add->perm); |
1facf9fc | 3304 | + if (unlikely(err)) |
b752ccd1 | 3305 | + goto out_err; |
1facf9fc | 3306 | + } |
3307 | + | |
3308 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
5527c038 JR |
3309 | + h_inode = d_inode(add->path.dentry); |
3310 | + err = au_xino_br(sb, br, h_inode->i_ino, | |
1facf9fc | 3311 | + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1); |
3312 | + if (unlikely(err)) { | |
3313 | + AuDebugOn(br->br_xino.xi_file); | |
b752ccd1 | 3314 | + goto out_err; |
1facf9fc | 3315 | + } |
3316 | + } | |
3317 | + | |
3318 | + sysaufs_br_init(br); | |
86dc4139 | 3319 | + path_get(&br->br_path); |
b752ccd1 | 3320 | + goto out; /* success */ |
1facf9fc | 3321 | + |
4f0767ce | 3322 | +out_err: |
86dc4139 | 3323 | + memset(&br->br_path, 0, sizeof(br->br_path)); |
4f0767ce | 3324 | +out: |
1facf9fc | 3325 | + return err; |
3326 | +} | |
3327 | + | |
3328 | +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3329 | + struct au_branch *br, aufs_bindex_t bbot, |
1facf9fc | 3330 | + aufs_bindex_t amount) |
3331 | +{ | |
3332 | + struct au_branch **brp; | |
3333 | + | |
dece6358 AM |
3334 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3335 | + | |
1facf9fc | 3336 | + brp = sbinfo->si_branch + bindex; |
3337 | + memmove(brp + 1, brp, sizeof(*brp) * amount); | |
3338 | + *brp = br; | |
5afbbe0d AM |
3339 | + sbinfo->si_bbot++; |
3340 | + if (unlikely(bbot < 0)) | |
3341 | + sbinfo->si_bbot = 0; | |
1facf9fc | 3342 | +} |
3343 | + | |
3344 | +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3345 | + aufs_bindex_t bbot, aufs_bindex_t amount) |
1facf9fc | 3346 | +{ |
3347 | + struct au_hdentry *hdp; | |
3348 | + | |
1308ab2a | 3349 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3350 | + | |
5afbbe0d | 3351 | + hdp = au_hdentry(dinfo, bindex); |
1facf9fc | 3352 | + memmove(hdp + 1, hdp, sizeof(*hdp) * amount); |
3353 | + au_h_dentry_init(hdp); | |
5afbbe0d AM |
3354 | + dinfo->di_bbot++; |
3355 | + if (unlikely(bbot < 0)) | |
3356 | + dinfo->di_btop = 0; | |
1facf9fc | 3357 | +} |
3358 | + | |
3359 | +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3360 | + aufs_bindex_t bbot, aufs_bindex_t amount) |
1facf9fc | 3361 | +{ |
3362 | + struct au_hinode *hip; | |
3363 | + | |
1308ab2a | 3364 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3365 | + | |
5afbbe0d | 3366 | + hip = au_hinode(iinfo, bindex); |
1facf9fc | 3367 | + memmove(hip + 1, hip, sizeof(*hip) * amount); |
5afbbe0d AM |
3368 | + au_hinode_init(hip); |
3369 | + iinfo->ii_bbot++; | |
3370 | + if (unlikely(bbot < 0)) | |
3371 | + iinfo->ii_btop = 0; | |
1facf9fc | 3372 | +} |
3373 | + | |
86dc4139 AM |
3374 | +static void au_br_do_add(struct super_block *sb, struct au_branch *br, |
3375 | + aufs_bindex_t bindex) | |
1facf9fc | 3376 | +{ |
86dc4139 | 3377 | + struct dentry *root, *h_dentry; |
5527c038 | 3378 | + struct inode *root_inode, *h_inode; |
5afbbe0d | 3379 | + aufs_bindex_t bbot, amount; |
1facf9fc | 3380 | + |
3381 | + root = sb->s_root; | |
5527c038 | 3382 | + root_inode = d_inode(root); |
5afbbe0d AM |
3383 | + bbot = au_sbbot(sb); |
3384 | + amount = bbot + 1 - bindex; | |
86dc4139 | 3385 | + h_dentry = au_br_dentry(br); |
53392da6 | 3386 | + au_sbilist_lock(); |
5afbbe0d AM |
3387 | + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount); |
3388 | + au_br_do_add_hdp(au_di(root), bindex, bbot, amount); | |
3389 | + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount); | |
1facf9fc | 3390 | + au_set_h_dptr(root, bindex, dget(h_dentry)); |
5527c038 JR |
3391 | + h_inode = d_inode(h_dentry); |
3392 | + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0); | |
53392da6 | 3393 | + au_sbilist_unlock(); |
1facf9fc | 3394 | +} |
3395 | + | |
3396 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3397 | +{ | |
3398 | + int err; | |
5afbbe0d | 3399 | + aufs_bindex_t bbot, add_bindex; |
1facf9fc | 3400 | + struct dentry *root, *h_dentry; |
3401 | + struct inode *root_inode; | |
3402 | + struct au_branch *add_branch; | |
3403 | + | |
3404 | + root = sb->s_root; | |
5527c038 | 3405 | + root_inode = d_inode(root); |
1facf9fc | 3406 | + IMustLock(root_inode); |
5afbbe0d | 3407 | + IiMustWriteLock(root_inode); |
1facf9fc | 3408 | + err = test_add(sb, add, remount); |
3409 | + if (unlikely(err < 0)) | |
3410 | + goto out; | |
3411 | + if (err) { | |
3412 | + err = 0; | |
3413 | + goto out; /* success */ | |
3414 | + } | |
3415 | + | |
5afbbe0d AM |
3416 | + bbot = au_sbbot(sb); |
3417 | + add_branch = au_br_alloc(sb, bbot + 2, add->perm); | |
1facf9fc | 3418 | + err = PTR_ERR(add_branch); |
3419 | + if (IS_ERR(add_branch)) | |
3420 | + goto out; | |
3421 | + | |
3422 | + err = au_br_init(add_branch, sb, add); | |
3423 | + if (unlikely(err)) { | |
3424 | + au_br_do_free(add_branch); | |
3425 | + goto out; | |
3426 | + } | |
3427 | + | |
3428 | + add_bindex = add->bindex; | |
1facf9fc | 3429 | + if (!remount) |
86dc4139 | 3430 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3431 | + else { |
3432 | + sysaufs_brs_del(sb, add_bindex); | |
86dc4139 | 3433 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3434 | + sysaufs_brs_add(sb, add_bindex); |
3435 | + } | |
3436 | + | |
86dc4139 | 3437 | + h_dentry = add->path.dentry; |
1308ab2a | 3438 | + if (!add_bindex) { |
1facf9fc | 3439 | + au_cpup_attr_all(root_inode, /*force*/1); |
1308ab2a | 3440 | + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes; |
3441 | + } else | |
5527c038 | 3442 | + au_add_nlink(root_inode, d_inode(h_dentry)); |
1facf9fc | 3443 | + |
3444 | + /* | |
4a4d8108 | 3445 | + * this test/set prevents aufs from handling unnecesary notify events |
027c5e7a | 3446 | + * of xino files, in case of re-adding a writable branch which was |
1facf9fc | 3447 | + * once detached from aufs. |
3448 | + */ | |
3449 | + if (au_xino_brid(sb) < 0 | |
3450 | + && au_br_writable(add_branch->br_perm) | |
3451 | + && !au_test_fs_bad_xino(h_dentry->d_sb) | |
3452 | + && add_branch->br_xino.xi_file | |
2000de60 | 3453 | + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry) |
1facf9fc | 3454 | + au_xino_brid_set(sb, add_branch->br_id); |
3455 | + | |
4f0767ce | 3456 | +out: |
1facf9fc | 3457 | + return err; |
3458 | +} | |
3459 | + | |
3460 | +/* ---------------------------------------------------------------------- */ | |
3461 | + | |
79b8bda9 | 3462 | +static unsigned long long au_farray_cb(struct super_block *sb, void *a, |
076b876e AM |
3463 | + unsigned long long max __maybe_unused, |
3464 | + void *arg) | |
3465 | +{ | |
3466 | + unsigned long long n; | |
3467 | + struct file **p, *f; | |
3468 | + struct au_sphlhead *files; | |
3469 | + struct au_finfo *finfo; | |
076b876e AM |
3470 | + |
3471 | + n = 0; | |
3472 | + p = a; | |
3473 | + files = &au_sbi(sb)->si_files; | |
3474 | + spin_lock(&files->spin); | |
3475 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
3476 | + f = finfo->fi_file; | |
3477 | + if (file_count(f) | |
3478 | + && !special_file(file_inode(f)->i_mode)) { | |
3479 | + get_file(f); | |
3480 | + *p++ = f; | |
3481 | + n++; | |
3482 | + AuDebugOn(n > max); | |
3483 | + } | |
3484 | + } | |
3485 | + spin_unlock(&files->spin); | |
3486 | + | |
3487 | + return n; | |
3488 | +} | |
3489 | + | |
3490 | +static struct file **au_farray_alloc(struct super_block *sb, | |
3491 | + unsigned long long *max) | |
3492 | +{ | |
5afbbe0d | 3493 | + *max = au_nfiles(sb); |
79b8bda9 | 3494 | + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL); |
076b876e AM |
3495 | +} |
3496 | + | |
3497 | +static void au_farray_free(struct file **a, unsigned long long max) | |
3498 | +{ | |
3499 | + unsigned long long ull; | |
3500 | + | |
3501 | + for (ull = 0; ull < max; ull++) | |
3502 | + if (a[ull]) | |
3503 | + fput(a[ull]); | |
be52b249 | 3504 | + kvfree(a); |
076b876e AM |
3505 | +} |
3506 | + | |
3507 | +/* ---------------------------------------------------------------------- */ | |
3508 | + | |
1facf9fc | 3509 | +/* |
3510 | + * delete a branch | |
3511 | + */ | |
3512 | + | |
3513 | +/* to show the line number, do not make it inlined function */ | |
4a4d8108 | 3514 | +#define AuVerbose(do_info, fmt, ...) do { \ |
1facf9fc | 3515 | + if (do_info) \ |
4a4d8108 | 3516 | + pr_info(fmt, ##__VA_ARGS__); \ |
1facf9fc | 3517 | +} while (0) |
3518 | + | |
5afbbe0d AM |
3519 | +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop, |
3520 | + aufs_bindex_t bbot) | |
027c5e7a | 3521 | +{ |
5afbbe0d | 3522 | + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot; |
027c5e7a AM |
3523 | +} |
3524 | + | |
5afbbe0d AM |
3525 | +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop, |
3526 | + aufs_bindex_t bbot) | |
027c5e7a | 3527 | +{ |
5afbbe0d | 3528 | + return au_test_ibusy(d_inode(dentry), btop, bbot); |
027c5e7a AM |
3529 | +} |
3530 | + | |
1facf9fc | 3531 | +/* |
3532 | + * test if the branch is deletable or not. | |
3533 | + */ | |
3534 | +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex, | |
b752ccd1 | 3535 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3536 | +{ |
3537 | + int err, i, j, ndentry; | |
5afbbe0d | 3538 | + aufs_bindex_t btop, bbot; |
1facf9fc | 3539 | + struct au_dcsub_pages dpages; |
3540 | + struct au_dpage *dpage; | |
3541 | + struct dentry *d; | |
1facf9fc | 3542 | + |
3543 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
3544 | + if (unlikely(err)) | |
3545 | + goto out; | |
3546 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); | |
3547 | + if (unlikely(err)) | |
3548 | + goto out_dpages; | |
3549 | + | |
1facf9fc | 3550 | + for (i = 0; !err && i < dpages.ndpage; i++) { |
3551 | + dpage = dpages.dpages + i; | |
3552 | + ndentry = dpage->ndentry; | |
3553 | + for (j = 0; !err && j < ndentry; j++) { | |
3554 | + d = dpage->dentries[j]; | |
c1595e42 | 3555 | + AuDebugOn(au_dcount(d) <= 0); |
027c5e7a | 3556 | + if (!au_digen_test(d, sigen)) { |
1facf9fc | 3557 | + di_read_lock_child(d, AuLock_IR); |
027c5e7a AM |
3558 | + if (unlikely(au_dbrange_test(d))) { |
3559 | + di_read_unlock(d, AuLock_IR); | |
3560 | + continue; | |
3561 | + } | |
3562 | + } else { | |
1facf9fc | 3563 | + di_write_lock_child(d); |
027c5e7a AM |
3564 | + if (unlikely(au_dbrange_test(d))) { |
3565 | + di_write_unlock(d); | |
3566 | + continue; | |
3567 | + } | |
1facf9fc | 3568 | + err = au_reval_dpath(d, sigen); |
3569 | + if (!err) | |
3570 | + di_downgrade_lock(d, AuLock_IR); | |
3571 | + else { | |
3572 | + di_write_unlock(d); | |
3573 | + break; | |
3574 | + } | |
3575 | + } | |
3576 | + | |
027c5e7a | 3577 | + /* AuDbgDentry(d); */ |
5afbbe0d AM |
3578 | + btop = au_dbtop(d); |
3579 | + bbot = au_dbbot(d); | |
3580 | + if (btop <= bindex | |
3581 | + && bindex <= bbot | |
1facf9fc | 3582 | + && au_h_dptr(d, bindex) |
5afbbe0d | 3583 | + && au_test_dbusy(d, btop, bbot)) { |
1facf9fc | 3584 | + err = -EBUSY; |
523b37e3 | 3585 | + AuVerbose(verbose, "busy %pd\n", d); |
027c5e7a | 3586 | + AuDbgDentry(d); |
1facf9fc | 3587 | + } |
3588 | + di_read_unlock(d, AuLock_IR); | |
3589 | + } | |
3590 | + } | |
3591 | + | |
4f0767ce | 3592 | +out_dpages: |
1facf9fc | 3593 | + au_dpages_free(&dpages); |
4f0767ce | 3594 | +out: |
1facf9fc | 3595 | + return err; |
3596 | +} | |
3597 | + | |
3598 | +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex, | |
b752ccd1 | 3599 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3600 | +{ |
3601 | + int err; | |
7f207e10 AM |
3602 | + unsigned long long max, ull; |
3603 | + struct inode *i, **array; | |
5afbbe0d | 3604 | + aufs_bindex_t btop, bbot; |
1facf9fc | 3605 | + |
7f207e10 AM |
3606 | + array = au_iarray_alloc(sb, &max); |
3607 | + err = PTR_ERR(array); | |
3608 | + if (IS_ERR(array)) | |
3609 | + goto out; | |
3610 | + | |
1facf9fc | 3611 | + err = 0; |
7f207e10 AM |
3612 | + AuDbg("b%d\n", bindex); |
3613 | + for (ull = 0; !err && ull < max; ull++) { | |
3614 | + i = array[ull]; | |
076b876e AM |
3615 | + if (unlikely(!i)) |
3616 | + break; | |
7f207e10 | 3617 | + if (i->i_ino == AUFS_ROOT_INO) |
1facf9fc | 3618 | + continue; |
3619 | + | |
7f207e10 | 3620 | + /* AuDbgInode(i); */ |
537831f9 | 3621 | + if (au_iigen(i, NULL) == sigen) |
1facf9fc | 3622 | + ii_read_lock_child(i); |
3623 | + else { | |
3624 | + ii_write_lock_child(i); | |
027c5e7a AM |
3625 | + err = au_refresh_hinode_self(i); |
3626 | + au_iigen_dec(i); | |
1facf9fc | 3627 | + if (!err) |
3628 | + ii_downgrade_lock(i); | |
3629 | + else { | |
3630 | + ii_write_unlock(i); | |
3631 | + break; | |
3632 | + } | |
3633 | + } | |
3634 | + | |
5afbbe0d AM |
3635 | + btop = au_ibtop(i); |
3636 | + bbot = au_ibbot(i); | |
3637 | + if (btop <= bindex | |
3638 | + && bindex <= bbot | |
1facf9fc | 3639 | + && au_h_iptr(i, bindex) |
5afbbe0d | 3640 | + && au_test_ibusy(i, btop, bbot)) { |
1facf9fc | 3641 | + err = -EBUSY; |
3642 | + AuVerbose(verbose, "busy i%lu\n", i->i_ino); | |
7f207e10 | 3643 | + AuDbgInode(i); |
1facf9fc | 3644 | + } |
3645 | + ii_read_unlock(i); | |
3646 | + } | |
7f207e10 | 3647 | + au_iarray_free(array, max); |
1facf9fc | 3648 | + |
7f207e10 | 3649 | +out: |
1facf9fc | 3650 | + return err; |
3651 | +} | |
3652 | + | |
b752ccd1 AM |
3653 | +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex, |
3654 | + const unsigned int verbose) | |
1facf9fc | 3655 | +{ |
3656 | + int err; | |
3657 | + unsigned int sigen; | |
3658 | + | |
3659 | + sigen = au_sigen(root->d_sb); | |
3660 | + DiMustNoWaiters(root); | |
5527c038 | 3661 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 3662 | + di_write_unlock(root); |
b752ccd1 | 3663 | + err = test_dentry_busy(root, bindex, sigen, verbose); |
1facf9fc | 3664 | + if (!err) |
b752ccd1 | 3665 | + err = test_inode_busy(root->d_sb, bindex, sigen, verbose); |
1facf9fc | 3666 | + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */ |
3667 | + | |
3668 | + return err; | |
3669 | +} | |
3670 | + | |
076b876e AM |
3671 | +static int test_dir_busy(struct file *file, aufs_bindex_t br_id, |
3672 | + struct file **to_free, int *idx) | |
3673 | +{ | |
3674 | + int err; | |
c1595e42 | 3675 | + unsigned char matched, root; |
5afbbe0d | 3676 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
3677 | + struct au_fidir *fidir; |
3678 | + struct au_hfile *hfile; | |
3679 | + | |
3680 | + err = 0; | |
2000de60 | 3681 | + root = IS_ROOT(file->f_path.dentry); |
c1595e42 JR |
3682 | + if (root) { |
3683 | + get_file(file); | |
3684 | + to_free[*idx] = file; | |
3685 | + (*idx)++; | |
3686 | + goto out; | |
3687 | + } | |
3688 | + | |
076b876e | 3689 | + matched = 0; |
076b876e AM |
3690 | + fidir = au_fi(file)->fi_hdir; |
3691 | + AuDebugOn(!fidir); | |
5afbbe0d AM |
3692 | + bbot = au_fbbot_dir(file); |
3693 | + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) { | |
076b876e AM |
3694 | + hfile = fidir->fd_hfile + bindex; |
3695 | + if (!hfile->hf_file) | |
3696 | + continue; | |
3697 | + | |
c1595e42 | 3698 | + if (hfile->hf_br->br_id == br_id) { |
076b876e | 3699 | + matched = 1; |
076b876e | 3700 | + break; |
c1595e42 | 3701 | + } |
076b876e | 3702 | + } |
c1595e42 | 3703 | + if (matched) |
076b876e AM |
3704 | + err = -EBUSY; |
3705 | + | |
3706 | +out: | |
3707 | + return err; | |
3708 | +} | |
3709 | + | |
3710 | +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id, | |
3711 | + struct file **to_free, int opened) | |
3712 | +{ | |
3713 | + int err, idx; | |
3714 | + unsigned long long ull, max; | |
5afbbe0d | 3715 | + aufs_bindex_t btop; |
076b876e | 3716 | + struct file *file, **array; |
076b876e AM |
3717 | + struct dentry *root; |
3718 | + struct au_hfile *hfile; | |
3719 | + | |
3720 | + array = au_farray_alloc(sb, &max); | |
3721 | + err = PTR_ERR(array); | |
3722 | + if (IS_ERR(array)) | |
3723 | + goto out; | |
3724 | + | |
3725 | + err = 0; | |
3726 | + idx = 0; | |
3727 | + root = sb->s_root; | |
3728 | + di_write_unlock(root); | |
3729 | + for (ull = 0; ull < max; ull++) { | |
3730 | + file = array[ull]; | |
3731 | + if (unlikely(!file)) | |
3732 | + break; | |
3733 | + | |
3734 | + /* AuDbg("%pD\n", file); */ | |
3735 | + fi_read_lock(file); | |
5afbbe0d | 3736 | + btop = au_fbtop(file); |
2000de60 | 3737 | + if (!d_is_dir(file->f_path.dentry)) { |
076b876e AM |
3738 | + hfile = &au_fi(file)->fi_htop; |
3739 | + if (hfile->hf_br->br_id == br_id) | |
3740 | + err = -EBUSY; | |
3741 | + } else | |
3742 | + err = test_dir_busy(file, br_id, to_free, &idx); | |
3743 | + fi_read_unlock(file); | |
3744 | + if (unlikely(err)) | |
3745 | + break; | |
3746 | + } | |
3747 | + di_write_lock_child(root); | |
3748 | + au_farray_free(array, max); | |
3749 | + AuDebugOn(idx > opened); | |
3750 | + | |
3751 | +out: | |
3752 | + return err; | |
3753 | +} | |
3754 | + | |
3755 | +static void br_del_file(struct file **to_free, unsigned long long opened, | |
3756 | + aufs_bindex_t br_id) | |
3757 | +{ | |
3758 | + unsigned long long ull; | |
5afbbe0d | 3759 | + aufs_bindex_t bindex, btop, bbot, bfound; |
076b876e AM |
3760 | + struct file *file; |
3761 | + struct au_fidir *fidir; | |
3762 | + struct au_hfile *hfile; | |
3763 | + | |
3764 | + for (ull = 0; ull < opened; ull++) { | |
3765 | + file = to_free[ull]; | |
3766 | + if (unlikely(!file)) | |
3767 | + break; | |
3768 | + | |
3769 | + /* AuDbg("%pD\n", file); */ | |
2000de60 | 3770 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
076b876e AM |
3771 | + bfound = -1; |
3772 | + fidir = au_fi(file)->fi_hdir; | |
3773 | + AuDebugOn(!fidir); | |
3774 | + fi_write_lock(file); | |
5afbbe0d AM |
3775 | + btop = au_fbtop(file); |
3776 | + bbot = au_fbbot_dir(file); | |
3777 | + for (bindex = btop; bindex <= bbot; bindex++) { | |
076b876e AM |
3778 | + hfile = fidir->fd_hfile + bindex; |
3779 | + if (!hfile->hf_file) | |
3780 | + continue; | |
3781 | + | |
3782 | + if (hfile->hf_br->br_id == br_id) { | |
3783 | + bfound = bindex; | |
3784 | + break; | |
3785 | + } | |
3786 | + } | |
3787 | + AuDebugOn(bfound < 0); | |
3788 | + au_set_h_fptr(file, bfound, NULL); | |
5afbbe0d AM |
3789 | + if (bfound == btop) { |
3790 | + for (btop++; btop <= bbot; btop++) | |
3791 | + if (au_hf_dir(file, btop)) { | |
3792 | + au_set_fbtop(file, btop); | |
076b876e AM |
3793 | + break; |
3794 | + } | |
3795 | + } | |
3796 | + fi_write_unlock(file); | |
3797 | + } | |
3798 | +} | |
3799 | + | |
1facf9fc | 3800 | +static void au_br_do_del_brp(struct au_sbinfo *sbinfo, |
3801 | + const aufs_bindex_t bindex, | |
5afbbe0d | 3802 | + const aufs_bindex_t bbot) |
1facf9fc | 3803 | +{ |
3804 | + struct au_branch **brp, **p; | |
3805 | + | |
dece6358 AM |
3806 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3807 | + | |
1facf9fc | 3808 | + brp = sbinfo->si_branch + bindex; |
5afbbe0d AM |
3809 | + if (bindex < bbot) |
3810 | + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex)); | |
3811 | + sbinfo->si_branch[0 + bbot] = NULL; | |
3812 | + sbinfo->si_bbot--; | |
1facf9fc | 3813 | + |
e2f27e51 AM |
3814 | + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST, |
3815 | + /*may_shrink*/1); | |
1facf9fc | 3816 | + if (p) |
3817 | + sbinfo->si_branch = p; | |
4a4d8108 | 3818 | + /* harmless error */ |
1facf9fc | 3819 | +} |
3820 | + | |
3821 | +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex, | |
5afbbe0d | 3822 | + const aufs_bindex_t bbot) |
1facf9fc | 3823 | +{ |
3824 | + struct au_hdentry *hdp, *p; | |
3825 | + | |
1308ab2a | 3826 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3827 | + | |
5afbbe0d AM |
3828 | + hdp = au_hdentry(dinfo, bindex); |
3829 | + if (bindex < bbot) | |
3830 | + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex)); | |
3831 | + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */ | |
3832 | + dinfo->di_bbot--; | |
1facf9fc | 3833 | + |
e2f27e51 AM |
3834 | + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST, |
3835 | + /*may_shrink*/1); | |
1facf9fc | 3836 | + if (p) |
3837 | + dinfo->di_hdentry = p; | |
4a4d8108 | 3838 | + /* harmless error */ |
1facf9fc | 3839 | +} |
3840 | + | |
3841 | +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex, | |
5afbbe0d | 3842 | + const aufs_bindex_t bbot) |
1facf9fc | 3843 | +{ |
3844 | + struct au_hinode *hip, *p; | |
3845 | + | |
1308ab2a | 3846 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3847 | + | |
5afbbe0d AM |
3848 | + hip = au_hinode(iinfo, bindex); |
3849 | + if (bindex < bbot) | |
3850 | + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex)); | |
3851 | + /* au_hinode_init(au_hinode(iinfo, bbot)); */ | |
3852 | + iinfo->ii_bbot--; | |
1facf9fc | 3853 | + |
e2f27e51 AM |
3854 | + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST, |
3855 | + /*may_shrink*/1); | |
1facf9fc | 3856 | + if (p) |
3857 | + iinfo->ii_hinode = p; | |
4a4d8108 | 3858 | + /* harmless error */ |
1facf9fc | 3859 | +} |
3860 | + | |
3861 | +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex, | |
3862 | + struct au_branch *br) | |
3863 | +{ | |
5afbbe0d | 3864 | + aufs_bindex_t bbot; |
1facf9fc | 3865 | + struct au_sbinfo *sbinfo; |
53392da6 AM |
3866 | + struct dentry *root, *h_root; |
3867 | + struct inode *inode, *h_inode; | |
3868 | + struct au_hinode *hinode; | |
1facf9fc | 3869 | + |
dece6358 AM |
3870 | + SiMustWriteLock(sb); |
3871 | + | |
1facf9fc | 3872 | + root = sb->s_root; |
5527c038 | 3873 | + inode = d_inode(root); |
1facf9fc | 3874 | + sbinfo = au_sbi(sb); |
5afbbe0d | 3875 | + bbot = sbinfo->si_bbot; |
1facf9fc | 3876 | + |
53392da6 AM |
3877 | + h_root = au_h_dptr(root, bindex); |
3878 | + hinode = au_hi(inode, bindex); | |
3879 | + h_inode = au_igrab(hinode->hi_inode); | |
3880 | + au_hiput(hinode); | |
1facf9fc | 3881 | + |
53392da6 | 3882 | + au_sbilist_lock(); |
5afbbe0d AM |
3883 | + au_br_do_del_brp(sbinfo, bindex, bbot); |
3884 | + au_br_do_del_hdp(au_di(root), bindex, bbot); | |
3885 | + au_br_do_del_hip(au_ii(inode), bindex, bbot); | |
53392da6 AM |
3886 | + au_sbilist_unlock(); |
3887 | + | |
3888 | + dput(h_root); | |
3889 | + iput(h_inode); | |
3890 | + au_br_do_free(br); | |
1facf9fc | 3891 | +} |
3892 | + | |
79b8bda9 AM |
3893 | +static unsigned long long empty_cb(struct super_block *sb, void *array, |
3894 | + unsigned long long max, void *arg) | |
076b876e AM |
3895 | +{ |
3896 | + return max; | |
3897 | +} | |
3898 | + | |
1facf9fc | 3899 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount) |
3900 | +{ | |
3901 | + int err, rerr, i; | |
076b876e | 3902 | + unsigned long long opened; |
1facf9fc | 3903 | + unsigned int mnt_flags; |
5afbbe0d | 3904 | + aufs_bindex_t bindex, bbot, br_id; |
1facf9fc | 3905 | + unsigned char do_wh, verbose; |
3906 | + struct au_branch *br; | |
3907 | + struct au_wbr *wbr; | |
076b876e AM |
3908 | + struct dentry *root; |
3909 | + struct file **to_free; | |
1facf9fc | 3910 | + |
3911 | + err = 0; | |
076b876e AM |
3912 | + opened = 0; |
3913 | + to_free = NULL; | |
3914 | + root = sb->s_root; | |
3915 | + bindex = au_find_dbindex(root, del->h_path.dentry); | |
1facf9fc | 3916 | + if (bindex < 0) { |
3917 | + if (remount) | |
3918 | + goto out; /* success */ | |
3919 | + err = -ENOENT; | |
4a4d8108 | 3920 | + pr_err("%s no such branch\n", del->pathname); |
1facf9fc | 3921 | + goto out; |
3922 | + } | |
3923 | + AuDbg("bindex b%d\n", bindex); | |
3924 | + | |
3925 | + err = -EBUSY; | |
3926 | + mnt_flags = au_mntflags(sb); | |
3927 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
5afbbe0d AM |
3928 | + bbot = au_sbbot(sb); |
3929 | + if (unlikely(!bbot)) { | |
1facf9fc | 3930 | + AuVerbose(verbose, "no more branches left\n"); |
3931 | + goto out; | |
3932 | + } | |
3933 | + br = au_sbr(sb, bindex); | |
86dc4139 | 3934 | + AuDebugOn(!path_equal(&br->br_path, &del->h_path)); |
076b876e AM |
3935 | + |
3936 | + br_id = br->br_id; | |
5afbbe0d | 3937 | + opened = au_br_count(br); |
076b876e | 3938 | + if (unlikely(opened)) { |
79b8bda9 | 3939 | + to_free = au_array_alloc(&opened, empty_cb, sb, NULL); |
076b876e AM |
3940 | + err = PTR_ERR(to_free); |
3941 | + if (IS_ERR(to_free)) | |
3942 | + goto out; | |
3943 | + | |
3944 | + err = test_file_busy(sb, br_id, to_free, opened); | |
3945 | + if (unlikely(err)) { | |
3946 | + AuVerbose(verbose, "%llu file(s) opened\n", opened); | |
3947 | + goto out; | |
3948 | + } | |
1facf9fc | 3949 | + } |
3950 | + | |
3951 | + wbr = br->br_wbr; | |
3952 | + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph); | |
3953 | + if (do_wh) { | |
1308ab2a | 3954 | + /* instead of WbrWhMustWriteLock(wbr) */ |
3955 | + SiMustWriteLock(sb); | |
1facf9fc | 3956 | + for (i = 0; i < AuBrWh_Last; i++) { |
3957 | + dput(wbr->wbr_wh[i]); | |
3958 | + wbr->wbr_wh[i] = NULL; | |
3959 | + } | |
3960 | + } | |
3961 | + | |
076b876e | 3962 | + err = test_children_busy(root, bindex, verbose); |
1facf9fc | 3963 | + if (unlikely(err)) { |
3964 | + if (do_wh) | |
3965 | + goto out_wh; | |
3966 | + goto out; | |
3967 | + } | |
3968 | + | |
3969 | + err = 0; | |
076b876e AM |
3970 | + if (to_free) { |
3971 | + /* | |
3972 | + * now we confirmed the branch is deletable. | |
3973 | + * let's free the remaining opened dirs on the branch. | |
3974 | + */ | |
3975 | + di_write_unlock(root); | |
3976 | + br_del_file(to_free, opened, br_id); | |
3977 | + di_write_lock_child(root); | |
3978 | + } | |
3979 | + | |
1facf9fc | 3980 | + if (!remount) |
3981 | + au_br_do_del(sb, bindex, br); | |
3982 | + else { | |
3983 | + sysaufs_brs_del(sb, bindex); | |
3984 | + au_br_do_del(sb, bindex, br); | |
3985 | + sysaufs_brs_add(sb, bindex); | |
3986 | + } | |
3987 | + | |
1308ab2a | 3988 | + if (!bindex) { |
5527c038 | 3989 | + au_cpup_attr_all(d_inode(root), /*force*/1); |
1308ab2a | 3990 | + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes; |
3991 | + } else | |
5527c038 | 3992 | + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry)); |
1facf9fc | 3993 | + if (au_opt_test(mnt_flags, PLINK)) |
3994 | + au_plink_half_refresh(sb, br_id); | |
3995 | + | |
b752ccd1 | 3996 | + if (au_xino_brid(sb) == br_id) |
1facf9fc | 3997 | + au_xino_brid_set(sb, -1); |
3998 | + goto out; /* success */ | |
3999 | + | |
4f0767ce | 4000 | +out_wh: |
1facf9fc | 4001 | + /* revert */ |
86dc4139 | 4002 | + rerr = au_br_init_wh(sb, br, br->br_perm); |
1facf9fc | 4003 | + if (rerr) |
0c3ec466 AM |
4004 | + pr_warn("failed re-creating base whiteout, %s. (%d)\n", |
4005 | + del->pathname, rerr); | |
4f0767ce | 4006 | +out: |
076b876e AM |
4007 | + if (to_free) |
4008 | + au_farray_free(to_free, opened); | |
1facf9fc | 4009 | + return err; |
4010 | +} | |
4011 | + | |
4012 | +/* ---------------------------------------------------------------------- */ | |
4013 | + | |
027c5e7a AM |
4014 | +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg) |
4015 | +{ | |
4016 | + int err; | |
5afbbe0d | 4017 | + aufs_bindex_t btop, bbot; |
027c5e7a AM |
4018 | + struct aufs_ibusy ibusy; |
4019 | + struct inode *inode, *h_inode; | |
4020 | + | |
4021 | + err = -EPERM; | |
4022 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
4023 | + goto out; | |
4024 | + | |
4025 | + err = copy_from_user(&ibusy, arg, sizeof(ibusy)); | |
4026 | + if (!err) | |
4027 | + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino)); | |
4028 | + if (unlikely(err)) { | |
4029 | + err = -EFAULT; | |
4030 | + AuTraceErr(err); | |
4031 | + goto out; | |
4032 | + } | |
4033 | + | |
4034 | + err = -EINVAL; | |
4035 | + si_read_lock(sb, AuLock_FLUSH); | |
5afbbe0d | 4036 | + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb))) |
027c5e7a AM |
4037 | + goto out_unlock; |
4038 | + | |
4039 | + err = 0; | |
4040 | + ibusy.h_ino = 0; /* invalid */ | |
4041 | + inode = ilookup(sb, ibusy.ino); | |
4042 | + if (!inode | |
4043 | + || inode->i_ino == AUFS_ROOT_INO | |
5afbbe0d | 4044 | + || au_is_bad_inode(inode)) |
027c5e7a AM |
4045 | + goto out_unlock; |
4046 | + | |
4047 | + ii_read_lock_child(inode); | |
5afbbe0d AM |
4048 | + btop = au_ibtop(inode); |
4049 | + bbot = au_ibbot(inode); | |
4050 | + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) { | |
027c5e7a | 4051 | + h_inode = au_h_iptr(inode, ibusy.bindex); |
5afbbe0d | 4052 | + if (h_inode && au_test_ibusy(inode, btop, bbot)) |
027c5e7a AM |
4053 | + ibusy.h_ino = h_inode->i_ino; |
4054 | + } | |
4055 | + ii_read_unlock(inode); | |
4056 | + iput(inode); | |
4057 | + | |
4058 | +out_unlock: | |
4059 | + si_read_unlock(sb); | |
4060 | + if (!err) { | |
4061 | + err = __put_user(ibusy.h_ino, &arg->h_ino); | |
4062 | + if (unlikely(err)) { | |
4063 | + err = -EFAULT; | |
4064 | + AuTraceErr(err); | |
4065 | + } | |
4066 | + } | |
4067 | +out: | |
4068 | + return err; | |
4069 | +} | |
4070 | + | |
4071 | +long au_ibusy_ioctl(struct file *file, unsigned long arg) | |
4072 | +{ | |
2000de60 | 4073 | + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg); |
027c5e7a AM |
4074 | +} |
4075 | + | |
4076 | +#ifdef CONFIG_COMPAT | |
4077 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg) | |
4078 | +{ | |
2000de60 | 4079 | + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg)); |
027c5e7a AM |
4080 | +} |
4081 | +#endif | |
4082 | + | |
4083 | +/* ---------------------------------------------------------------------- */ | |
4084 | + | |
1facf9fc | 4085 | +/* |
4086 | + * change a branch permission | |
4087 | + */ | |
4088 | + | |
dece6358 AM |
4089 | +static void au_warn_ima(void) |
4090 | +{ | |
4091 | +#ifdef CONFIG_IMA | |
1308ab2a | 4092 | + /* since it doesn't support mark_files_ro() */ |
027c5e7a | 4093 | + AuWarn1("RW -> RO makes IMA to produce wrong message\n"); |
dece6358 AM |
4094 | +#endif |
4095 | +} | |
4096 | + | |
1facf9fc | 4097 | +static int do_need_sigen_inc(int a, int b) |
4098 | +{ | |
4099 | + return au_br_whable(a) && !au_br_whable(b); | |
4100 | +} | |
4101 | + | |
4102 | +static int need_sigen_inc(int old, int new) | |
4103 | +{ | |
4104 | + return do_need_sigen_inc(old, new) | |
4105 | + || do_need_sigen_inc(new, old); | |
4106 | +} | |
4107 | + | |
4108 | +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex) | |
4109 | +{ | |
7f207e10 | 4110 | + int err, do_warn; |
027c5e7a | 4111 | + unsigned int mnt_flags; |
7f207e10 | 4112 | + unsigned long long ull, max; |
e49829fe | 4113 | + aufs_bindex_t br_id; |
38d290e6 | 4114 | + unsigned char verbose, writer; |
7f207e10 | 4115 | + struct file *file, *hf, **array; |
e49829fe | 4116 | + struct au_hfile *hfile; |
1facf9fc | 4117 | + |
027c5e7a AM |
4118 | + mnt_flags = au_mntflags(sb); |
4119 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
4120 | + | |
7f207e10 AM |
4121 | + array = au_farray_alloc(sb, &max); |
4122 | + err = PTR_ERR(array); | |
4123 | + if (IS_ERR(array)) | |
1facf9fc | 4124 | + goto out; |
4125 | + | |
7f207e10 | 4126 | + do_warn = 0; |
e49829fe | 4127 | + br_id = au_sbr_id(sb, bindex); |
7f207e10 AM |
4128 | + for (ull = 0; ull < max; ull++) { |
4129 | + file = array[ull]; | |
076b876e AM |
4130 | + if (unlikely(!file)) |
4131 | + break; | |
1facf9fc | 4132 | + |
523b37e3 | 4133 | + /* AuDbg("%pD\n", file); */ |
1facf9fc | 4134 | + fi_read_lock(file); |
4135 | + if (unlikely(au_test_mmapped(file))) { | |
4136 | + err = -EBUSY; | |
523b37e3 | 4137 | + AuVerbose(verbose, "mmapped %pD\n", file); |
7f207e10 | 4138 | + AuDbgFile(file); |
1facf9fc | 4139 | + FiMustNoWaiters(file); |
4140 | + fi_read_unlock(file); | |
7f207e10 | 4141 | + goto out_array; |
1facf9fc | 4142 | + } |
4143 | + | |
e49829fe JR |
4144 | + hfile = &au_fi(file)->fi_htop; |
4145 | + hf = hfile->hf_file; | |
7e9cd9fe | 4146 | + if (!d_is_reg(file->f_path.dentry) |
1facf9fc | 4147 | + || !(file->f_mode & FMODE_WRITE) |
e49829fe | 4148 | + || hfile->hf_br->br_id != br_id |
7f207e10 AM |
4149 | + || !(hf->f_mode & FMODE_WRITE)) |
4150 | + array[ull] = NULL; | |
4151 | + else { | |
4152 | + do_warn = 1; | |
4153 | + get_file(file); | |
1facf9fc | 4154 | + } |
4155 | + | |
1facf9fc | 4156 | + FiMustNoWaiters(file); |
4157 | + fi_read_unlock(file); | |
7f207e10 AM |
4158 | + fput(file); |
4159 | + } | |
1facf9fc | 4160 | + |
4161 | + err = 0; | |
7f207e10 | 4162 | + if (do_warn) |
dece6358 | 4163 | + au_warn_ima(); |
7f207e10 AM |
4164 | + |
4165 | + for (ull = 0; ull < max; ull++) { | |
4166 | + file = array[ull]; | |
4167 | + if (!file) | |
4168 | + continue; | |
4169 | + | |
1facf9fc | 4170 | + /* todo: already flushed? */ |
523b37e3 AM |
4171 | + /* |
4172 | + * fs/super.c:mark_files_ro() is gone, but aufs keeps its | |
4173 | + * approach which resets f_mode and calls mnt_drop_write() and | |
4174 | + * file_release_write() for each file, because the branch | |
4175 | + * attribute in aufs world is totally different from the native | |
4176 | + * fs rw/ro mode. | |
4177 | + */ | |
7f207e10 AM |
4178 | + /* fi_read_lock(file); */ |
4179 | + hfile = &au_fi(file)->fi_htop; | |
4180 | + hf = hfile->hf_file; | |
4181 | + /* fi_read_unlock(file); */ | |
027c5e7a | 4182 | + spin_lock(&hf->f_lock); |
38d290e6 JR |
4183 | + writer = !!(hf->f_mode & FMODE_WRITER); |
4184 | + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER); | |
027c5e7a | 4185 | + spin_unlock(&hf->f_lock); |
38d290e6 JR |
4186 | + if (writer) { |
4187 | + put_write_access(file_inode(hf)); | |
c06a8ce3 | 4188 | + __mnt_drop_write(hf->f_path.mnt); |
1facf9fc | 4189 | + } |
4190 | + } | |
4191 | + | |
7f207e10 AM |
4192 | +out_array: |
4193 | + au_farray_free(array, max); | |
4f0767ce | 4194 | +out: |
7f207e10 | 4195 | + AuTraceErr(err); |
1facf9fc | 4196 | + return err; |
4197 | +} | |
4198 | + | |
4199 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4200 | + int *do_refresh) |
1facf9fc | 4201 | +{ |
4202 | + int err, rerr; | |
4203 | + aufs_bindex_t bindex; | |
4204 | + struct dentry *root; | |
4205 | + struct au_branch *br; | |
076b876e | 4206 | + struct au_br_fhsm *bf; |
1facf9fc | 4207 | + |
4208 | + root = sb->s_root; | |
1facf9fc | 4209 | + bindex = au_find_dbindex(root, mod->h_root); |
4210 | + if (bindex < 0) { | |
4211 | + if (remount) | |
4212 | + return 0; /* success */ | |
4213 | + err = -ENOENT; | |
4a4d8108 | 4214 | + pr_err("%s no such branch\n", mod->path); |
1facf9fc | 4215 | + goto out; |
4216 | + } | |
4217 | + AuDbg("bindex b%d\n", bindex); | |
4218 | + | |
5527c038 | 4219 | + err = test_br(d_inode(mod->h_root), mod->perm, mod->path); |
1facf9fc | 4220 | + if (unlikely(err)) |
4221 | + goto out; | |
4222 | + | |
4223 | + br = au_sbr(sb, bindex); | |
86dc4139 | 4224 | + AuDebugOn(mod->h_root != au_br_dentry(br)); |
1facf9fc | 4225 | + if (br->br_perm == mod->perm) |
4226 | + return 0; /* success */ | |
4227 | + | |
076b876e AM |
4228 | + /* pre-allocate for non-fhsm --> fhsm */ |
4229 | + bf = NULL; | |
4230 | + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) { | |
4231 | + err = au_fhsm_br_alloc(br); | |
4232 | + if (unlikely(err)) | |
4233 | + goto out; | |
4234 | + bf = br->br_fhsm; | |
4235 | + br->br_fhsm = NULL; | |
4236 | + } | |
4237 | + | |
1facf9fc | 4238 | + if (au_br_writable(br->br_perm)) { |
4239 | + /* remove whiteout base */ | |
86dc4139 | 4240 | + err = au_br_init_wh(sb, br, mod->perm); |
1facf9fc | 4241 | + if (unlikely(err)) |
076b876e | 4242 | + goto out_bf; |
1facf9fc | 4243 | + |
4244 | + if (!au_br_writable(mod->perm)) { | |
4245 | + /* rw --> ro, file might be mmapped */ | |
4246 | + DiMustNoWaiters(root); | |
5527c038 | 4247 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 4248 | + di_write_unlock(root); |
4249 | + err = au_br_mod_files_ro(sb, bindex); | |
4250 | + /* aufs_write_lock() calls ..._child() */ | |
4251 | + di_write_lock_child(root); | |
4252 | + | |
4253 | + if (unlikely(err)) { | |
4254 | + rerr = -ENOMEM; | |
be52b249 | 4255 | + br->br_wbr = kzalloc(sizeof(*br->br_wbr), |
1facf9fc | 4256 | + GFP_NOFS); |
86dc4139 AM |
4257 | + if (br->br_wbr) |
4258 | + rerr = au_wbr_init(br, sb, br->br_perm); | |
1facf9fc | 4259 | + if (unlikely(rerr)) { |
4260 | + AuIOErr("nested error %d (%d)\n", | |
4261 | + rerr, err); | |
4262 | + br->br_perm = mod->perm; | |
4263 | + } | |
4264 | + } | |
4265 | + } | |
4266 | + } else if (au_br_writable(mod->perm)) { | |
4267 | + /* ro --> rw */ | |
4268 | + err = -ENOMEM; | |
be52b249 | 4269 | + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS); |
1facf9fc | 4270 | + if (br->br_wbr) { |
86dc4139 | 4271 | + err = au_wbr_init(br, sb, mod->perm); |
1facf9fc | 4272 | + if (unlikely(err)) { |
f0c0a007 | 4273 | + au_delayed_kfree(br->br_wbr); |
1facf9fc | 4274 | + br->br_wbr = NULL; |
4275 | + } | |
4276 | + } | |
4277 | + } | |
076b876e AM |
4278 | + if (unlikely(err)) |
4279 | + goto out_bf; | |
4280 | + | |
4281 | + if (au_br_fhsm(br->br_perm)) { | |
4282 | + if (!au_br_fhsm(mod->perm)) { | |
4283 | + /* fhsm --> non-fhsm */ | |
4284 | + au_br_fhsm_fin(br->br_fhsm); | |
f0c0a007 | 4285 | + au_delayed_kfree(br->br_fhsm); |
076b876e AM |
4286 | + br->br_fhsm = NULL; |
4287 | + } | |
4288 | + } else if (au_br_fhsm(mod->perm)) | |
4289 | + /* non-fhsm --> fhsm */ | |
4290 | + br->br_fhsm = bf; | |
4291 | + | |
076b876e AM |
4292 | + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm); |
4293 | + br->br_perm = mod->perm; | |
4294 | + goto out; /* success */ | |
1facf9fc | 4295 | + |
076b876e | 4296 | +out_bf: |
f0c0a007 AM |
4297 | + if (bf) |
4298 | + au_delayed_kfree(bf); | |
076b876e AM |
4299 | +out: |
4300 | + AuTraceErr(err); | |
4301 | + return err; | |
4302 | +} | |
4303 | + | |
4304 | +/* ---------------------------------------------------------------------- */ | |
4305 | + | |
4306 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs) | |
4307 | +{ | |
4308 | + int err; | |
4309 | + struct kstatfs kstfs; | |
4310 | + | |
4311 | + err = vfs_statfs(&br->br_path, &kstfs); | |
1facf9fc | 4312 | + if (!err) { |
076b876e AM |
4313 | + stfs->f_blocks = kstfs.f_blocks; |
4314 | + stfs->f_bavail = kstfs.f_bavail; | |
4315 | + stfs->f_files = kstfs.f_files; | |
4316 | + stfs->f_ffree = kstfs.f_ffree; | |
1facf9fc | 4317 | + } |
4318 | + | |
1facf9fc | 4319 | + return err; |
4320 | +} | |
7f207e10 AM |
4321 | diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h |
4322 | --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
4323 | +++ linux/fs/aufs/branch.h 2017-05-06 22:16:52.774886674 +0200 |
4324 | @@ -0,0 +1,321 @@ | |
1facf9fc | 4325 | +/* |
a2654f78 | 4326 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 4327 | + * |
4328 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4329 | + * it under the terms of the GNU General Public License as published by | |
4330 | + * the Free Software Foundation; either version 2 of the License, or | |
4331 | + * (at your option) any later version. | |
dece6358 AM |
4332 | + * |
4333 | + * This program is distributed in the hope that it will be useful, | |
4334 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4335 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4336 | + * GNU General Public License for more details. | |
4337 | + * | |
4338 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4339 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4340 | + */ |
4341 | + | |
4342 | +/* | |
4343 | + * branch filesystems and xino for them | |
4344 | + */ | |
4345 | + | |
4346 | +#ifndef __AUFS_BRANCH_H__ | |
4347 | +#define __AUFS_BRANCH_H__ | |
4348 | + | |
4349 | +#ifdef __KERNEL__ | |
4350 | + | |
1facf9fc | 4351 | +#include <linux/mount.h> |
4a4d8108 | 4352 | +#include "dynop.h" |
1facf9fc | 4353 | +#include "rwsem.h" |
4354 | +#include "super.h" | |
4355 | + | |
4356 | +/* ---------------------------------------------------------------------- */ | |
4357 | + | |
4358 | +/* a xino file */ | |
4359 | +struct au_xino_file { | |
4360 | + struct file *xi_file; | |
521ced18 JR |
4361 | + struct { |
4362 | + spinlock_t spin; | |
4363 | + ino_t *array; | |
4364 | + int total; | |
4365 | + /* reserved for future use */ | |
4366 | + /* unsigned long *bitmap; */ | |
4367 | + wait_queue_head_t wqh; | |
4368 | + } xi_nondir; | |
1facf9fc | 4369 | + |
4370 | + /* todo: make xino files an array to support huge inode number */ | |
4371 | + | |
4372 | +#ifdef CONFIG_DEBUG_FS | |
4373 | + struct dentry *xi_dbgaufs; | |
4374 | +#endif | |
4375 | +}; | |
4376 | + | |
076b876e AM |
4377 | +/* File-based Hierarchical Storage Management */ |
4378 | +struct au_br_fhsm { | |
4379 | +#ifdef CONFIG_AUFS_FHSM | |
4380 | + struct mutex bf_lock; | |
4381 | + unsigned long bf_jiffy; | |
4382 | + struct aufs_stfs bf_stfs; | |
4383 | + int bf_readable; | |
4384 | +#endif | |
4385 | +}; | |
4386 | + | |
1facf9fc | 4387 | +/* members for writable branch only */ |
4388 | +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last}; | |
4389 | +struct au_wbr { | |
dece6358 | 4390 | + struct au_rwsem wbr_wh_rwsem; |
1facf9fc | 4391 | + struct dentry *wbr_wh[AuBrWh_Last]; |
4a4d8108 | 4392 | + atomic_t wbr_wh_running; |
1facf9fc | 4393 | +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */ |
4394 | +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */ | |
4395 | +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */ | |
4396 | + | |
4397 | + /* mfs mode */ | |
4398 | + unsigned long long wbr_bytes; | |
4399 | +}; | |
4400 | + | |
4a4d8108 AM |
4401 | +/* ext2 has 3 types of operations at least, ext3 has 4 */ |
4402 | +#define AuBrDynOp (AuDyLast * 4) | |
4403 | + | |
1716fcea AM |
4404 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
4405 | +/* support for asynchronous destruction */ | |
4406 | +struct au_br_hfsnotify { | |
4407 | + struct fsnotify_group *hfsn_group; | |
4408 | +}; | |
4409 | +#endif | |
4410 | + | |
392086de AM |
4411 | +/* sysfs entries */ |
4412 | +struct au_brsysfs { | |
4413 | + char name[16]; | |
4414 | + struct attribute attr; | |
4415 | +}; | |
4416 | + | |
4417 | +enum { | |
4418 | + AuBrSysfs_BR, | |
4419 | + AuBrSysfs_BRID, | |
4420 | + AuBrSysfs_Last | |
4421 | +}; | |
4422 | + | |
1facf9fc | 4423 | +/* protected by superblock rwsem */ |
4424 | +struct au_branch { | |
4425 | + struct au_xino_file br_xino; | |
4426 | + | |
4427 | + aufs_bindex_t br_id; | |
4428 | + | |
4429 | + int br_perm; | |
86dc4139 | 4430 | + struct path br_path; |
4a4d8108 AM |
4431 | + spinlock_t br_dykey_lock; |
4432 | + struct au_dykey *br_dykey[AuBrDynOp]; | |
5afbbe0d | 4433 | + struct percpu_counter br_count; |
1facf9fc | 4434 | + |
4435 | + struct au_wbr *br_wbr; | |
076b876e | 4436 | + struct au_br_fhsm *br_fhsm; |
1facf9fc | 4437 | + |
4438 | + /* xino truncation */ | |
1facf9fc | 4439 | + atomic_t br_xino_running; |
4440 | + | |
027c5e7a | 4441 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
1716fcea | 4442 | + struct au_br_hfsnotify *br_hfsn; |
027c5e7a AM |
4443 | +#endif |
4444 | + | |
1facf9fc | 4445 | +#ifdef CONFIG_SYSFS |
392086de AM |
4446 | + /* entries under sysfs per mount-point */ |
4447 | + struct au_brsysfs br_sysfs[AuBrSysfs_Last]; | |
1facf9fc | 4448 | +#endif |
4449 | +}; | |
4450 | + | |
4451 | +/* ---------------------------------------------------------------------- */ | |
4452 | + | |
86dc4139 AM |
4453 | +static inline struct vfsmount *au_br_mnt(struct au_branch *br) |
4454 | +{ | |
4455 | + return br->br_path.mnt; | |
4456 | +} | |
4457 | + | |
4458 | +static inline struct dentry *au_br_dentry(struct au_branch *br) | |
4459 | +{ | |
4460 | + return br->br_path.dentry; | |
4461 | +} | |
4462 | + | |
4463 | +static inline struct super_block *au_br_sb(struct au_branch *br) | |
4464 | +{ | |
4465 | + return au_br_mnt(br)->mnt_sb; | |
4466 | +} | |
4467 | + | |
5afbbe0d AM |
4468 | +static inline void au_br_get(struct au_branch *br) |
4469 | +{ | |
4470 | + percpu_counter_inc(&br->br_count); | |
4471 | +} | |
4472 | + | |
4473 | +static inline void au_br_put(struct au_branch *br) | |
4474 | +{ | |
4475 | + percpu_counter_dec(&br->br_count); | |
4476 | +} | |
4477 | + | |
4478 | +static inline s64 au_br_count(struct au_branch *br) | |
4479 | +{ | |
4480 | + return percpu_counter_sum(&br->br_count); | |
4481 | +} | |
4482 | + | |
4483 | +static inline void au_br_count_init(struct au_branch *br) | |
4484 | +{ | |
4485 | + percpu_counter_init(&br->br_count, 0, GFP_NOFS); | |
4486 | +} | |
4487 | + | |
4488 | +static inline void au_br_count_fin(struct au_branch *br) | |
4489 | +{ | |
4490 | + percpu_counter_destroy(&br->br_count); | |
4491 | +} | |
4492 | + | |
1facf9fc | 4493 | +static inline int au_br_rdonly(struct au_branch *br) |
4494 | +{ | |
86dc4139 | 4495 | + return ((au_br_sb(br)->s_flags & MS_RDONLY) |
1facf9fc | 4496 | + || !au_br_writable(br->br_perm)) |
4497 | + ? -EROFS : 0; | |
4498 | +} | |
4499 | + | |
4a4d8108 | 4500 | +static inline int au_br_hnotifyable(int brperm __maybe_unused) |
1facf9fc | 4501 | +{ |
4a4d8108 | 4502 | +#ifdef CONFIG_AUFS_HNOTIFY |
1e00d052 | 4503 | + return !(brperm & AuBrPerm_RR); |
1facf9fc | 4504 | +#else |
4505 | + return 0; | |
4506 | +#endif | |
4507 | +} | |
4508 | + | |
b912730e AM |
4509 | +static inline int au_br_test_oflag(int oflag, struct au_branch *br) |
4510 | +{ | |
4511 | + int err, exec_flag; | |
4512 | + | |
4513 | + err = 0; | |
4514 | + exec_flag = oflag & __FMODE_EXEC; | |
79b8bda9 | 4515 | + if (unlikely(exec_flag && path_noexec(&br->br_path))) |
b912730e AM |
4516 | + err = -EACCES; |
4517 | + | |
4518 | + return err; | |
4519 | +} | |
4520 | + | |
1facf9fc | 4521 | +/* ---------------------------------------------------------------------- */ |
4522 | + | |
4523 | +/* branch.c */ | |
4524 | +struct au_sbinfo; | |
4525 | +void au_br_free(struct au_sbinfo *sinfo); | |
4526 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id); | |
4527 | +struct au_opt_add; | |
4528 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount); | |
4529 | +struct au_opt_del; | |
4530 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount); | |
027c5e7a AM |
4531 | +long au_ibusy_ioctl(struct file *file, unsigned long arg); |
4532 | +#ifdef CONFIG_COMPAT | |
4533 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg); | |
4534 | +#endif | |
1facf9fc | 4535 | +struct au_opt_mod; |
4536 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4537 | + int *do_refresh); |
076b876e AM |
4538 | +struct aufs_stfs; |
4539 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs); | |
1facf9fc | 4540 | + |
4541 | +/* xino.c */ | |
4542 | +static const loff_t au_loff_max = LLONG_MAX; | |
4543 | + | |
4544 | +int au_xib_trunc(struct super_block *sb); | |
5527c038 | 4545 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size, |
1facf9fc | 4546 | + loff_t *pos); |
5527c038 JR |
4547 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
4548 | + size_t size, loff_t *pos); | |
1facf9fc | 4549 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src); |
4550 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent); | |
4551 | +ino_t au_xino_new_ino(struct super_block *sb); | |
b752ccd1 | 4552 | +void au_xino_delete_inode(struct inode *inode, const int unlinked); |
1facf9fc | 4553 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
4554 | + ino_t ino); | |
4555 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4556 | + ino_t *ino); | |
4557 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino, | |
4558 | + struct file *base_file, int do_test); | |
4559 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex); | |
4560 | + | |
4561 | +struct au_opt_xino; | |
4562 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount); | |
4563 | +void au_xino_clr(struct super_block *sb); | |
4564 | +struct file *au_xino_def(struct super_block *sb); | |
4565 | +int au_xino_path(struct seq_file *seq, struct file *file); | |
4566 | + | |
521ced18 JR |
4567 | +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex, |
4568 | + ino_t h_ino, int idx); | |
4569 | +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4570 | + int *idx); | |
4571 | + | |
1facf9fc | 4572 | +/* ---------------------------------------------------------------------- */ |
4573 | + | |
4574 | +/* Superblock to branch */ | |
4575 | +static inline | |
4576 | +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex) | |
4577 | +{ | |
4578 | + return au_sbr(sb, bindex)->br_id; | |
4579 | +} | |
4580 | + | |
4581 | +static inline | |
4582 | +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex) | |
4583 | +{ | |
86dc4139 | 4584 | + return au_br_mnt(au_sbr(sb, bindex)); |
1facf9fc | 4585 | +} |
4586 | + | |
4587 | +static inline | |
4588 | +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex) | |
4589 | +{ | |
86dc4139 | 4590 | + return au_br_sb(au_sbr(sb, bindex)); |
1facf9fc | 4591 | +} |
4592 | + | |
5afbbe0d AM |
4593 | +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex) |
4594 | +{ | |
4595 | + au_br_get(au_sbr(sb, bindex)); | |
4596 | +} | |
4597 | + | |
1facf9fc | 4598 | +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex) |
4599 | +{ | |
5afbbe0d | 4600 | + au_br_put(au_sbr(sb, bindex)); |
1facf9fc | 4601 | +} |
4602 | + | |
4603 | +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex) | |
4604 | +{ | |
4605 | + return au_sbr(sb, bindex)->br_perm; | |
4606 | +} | |
4607 | + | |
4608 | +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex) | |
4609 | +{ | |
4610 | + return au_br_whable(au_sbr_perm(sb, bindex)); | |
4611 | +} | |
4612 | + | |
4613 | +/* ---------------------------------------------------------------------- */ | |
4614 | + | |
4615 | +/* | |
4616 | + * wbr_wh_read_lock, wbr_wh_write_lock | |
4617 | + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock | |
4618 | + */ | |
4619 | +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem); | |
4620 | + | |
dece6358 AM |
4621 | +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem) |
4622 | +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem) | |
4623 | +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem) | |
4624 | + | |
076b876e AM |
4625 | +/* ---------------------------------------------------------------------- */ |
4626 | + | |
4627 | +#ifdef CONFIG_AUFS_FHSM | |
4628 | +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm) | |
4629 | +{ | |
4630 | + mutex_init(&brfhsm->bf_lock); | |
4631 | + brfhsm->bf_jiffy = 0; | |
4632 | + brfhsm->bf_readable = 0; | |
4633 | +} | |
4634 | + | |
4635 | +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm) | |
4636 | +{ | |
4637 | + mutex_destroy(&brfhsm->bf_lock); | |
4638 | +} | |
4639 | +#else | |
4640 | +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm) | |
4641 | +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm) | |
4642 | +#endif | |
4643 | + | |
1facf9fc | 4644 | +#endif /* __KERNEL__ */ |
4645 | +#endif /* __AUFS_BRANCH_H__ */ | |
7f207e10 AM |
4646 | diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk |
4647 | --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 4648 | +++ linux/fs/aufs/conf.mk 2017-05-06 22:16:52.774886674 +0200 |
c1595e42 | 4649 | @@ -0,0 +1,38 @@ |
4a4d8108 AM |
4650 | + |
4651 | +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS} | |
4652 | + | |
4653 | +define AuConf | |
4654 | +ifdef ${1} | |
4655 | +AuConfStr += ${1}=${${1}} | |
4656 | +endif | |
4657 | +endef | |
4658 | + | |
b752ccd1 | 4659 | +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \ |
e49829fe | 4660 | + SBILIST \ |
7f207e10 | 4661 | + HNOTIFY HFSNOTIFY \ |
4a4d8108 | 4662 | + EXPORT INO_T_64 \ |
c1595e42 | 4663 | + XATTR \ |
076b876e | 4664 | + FHSM \ |
4a4d8108 | 4665 | + RDU \ |
4a4d8108 AM |
4666 | + SHWH \ |
4667 | + BR_RAMFS \ | |
4668 | + BR_FUSE POLL \ | |
4669 | + BR_HFSPLUS \ | |
4670 | + BDEV_LOOP \ | |
b752ccd1 AM |
4671 | + DEBUG MAGIC_SYSRQ |
4672 | +$(foreach i, ${AuConfAll}, \ | |
4a4d8108 AM |
4673 | + $(eval $(call AuConf,CONFIG_AUFS_${i}))) |
4674 | + | |
4675 | +AuConfName = ${obj}/conf.str | |
4676 | +${AuConfName}.tmp: FORCE | |
4677 | + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@ | |
4678 | +${AuConfName}: ${AuConfName}.tmp | |
4679 | + @diff -q $< $@ > /dev/null 2>&1 || { \ | |
4680 | + echo ' GEN ' $@; \ | |
4681 | + cp -p $< $@; \ | |
4682 | + } | |
4683 | +FORCE: | |
4684 | +clean-files += ${AuConfName} ${AuConfName}.tmp | |
4685 | +${obj}/sysfs.o: ${AuConfName} | |
b752ccd1 AM |
4686 | + |
4687 | +-include ${srctree}/${src}/conf_priv.mk | |
7f207e10 AM |
4688 | diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c |
4689 | --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
4690 | +++ linux/fs/aufs/cpup.c 2017-05-06 22:16:52.774886674 +0200 |
4691 | @@ -0,0 +1,1407 @@ | |
1facf9fc | 4692 | +/* |
a2654f78 | 4693 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 4694 | + * |
4695 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4696 | + * it under the terms of the GNU General Public License as published by | |
4697 | + * the Free Software Foundation; either version 2 of the License, or | |
4698 | + * (at your option) any later version. | |
dece6358 AM |
4699 | + * |
4700 | + * This program is distributed in the hope that it will be useful, | |
4701 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4702 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4703 | + * GNU General Public License for more details. | |
4704 | + * | |
4705 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4706 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4707 | + */ |
4708 | + | |
4709 | +/* | |
4710 | + * copy-up functions, see wbr_policy.c for copy-down | |
4711 | + */ | |
4712 | + | |
4713 | +#include <linux/fs_stack.h> | |
dece6358 | 4714 | +#include <linux/mm.h> |
8cdd5066 | 4715 | +#include <linux/task_work.h> |
1facf9fc | 4716 | +#include "aufs.h" |
4717 | + | |
86dc4139 | 4718 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags) |
1facf9fc | 4719 | +{ |
4720 | + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE | |
367653fa | 4721 | + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT; |
1facf9fc | 4722 | + |
86dc4139 AM |
4723 | + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags)); |
4724 | + | |
4725 | + dst->i_flags |= iflags & ~mask; | |
1facf9fc | 4726 | + if (au_test_fs_notime(dst->i_sb)) |
4727 | + dst->i_flags |= S_NOATIME | S_NOCMTIME; | |
4728 | +} | |
4729 | + | |
4730 | +void au_cpup_attr_timesizes(struct inode *inode) | |
4731 | +{ | |
4732 | + struct inode *h_inode; | |
4733 | + | |
5afbbe0d | 4734 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 4735 | + fsstack_copy_attr_times(inode, h_inode); |
4a4d8108 | 4736 | + fsstack_copy_inode_size(inode, h_inode); |
1facf9fc | 4737 | +} |
4738 | + | |
4739 | +void au_cpup_attr_nlink(struct inode *inode, int force) | |
4740 | +{ | |
4741 | + struct inode *h_inode; | |
4742 | + struct super_block *sb; | |
5afbbe0d | 4743 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 4744 | + |
4745 | + sb = inode->i_sb; | |
5afbbe0d | 4746 | + bindex = au_ibtop(inode); |
1facf9fc | 4747 | + h_inode = au_h_iptr(inode, bindex); |
4748 | + if (!force | |
4749 | + && !S_ISDIR(h_inode->i_mode) | |
4750 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4751 | + && au_plink_test(inode)) | |
4752 | + return; | |
4753 | + | |
7eafdf33 AM |
4754 | + /* |
4755 | + * 0 can happen in revalidating. | |
38d290e6 JR |
4756 | + * h_inode->i_mutex may not be held here, but it is harmless since once |
4757 | + * i_nlink reaches 0, it will never become positive except O_TMPFILE | |
4758 | + * case. | |
4759 | + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause | |
4760 | + * the incorrect link count. | |
7eafdf33 | 4761 | + */ |
92d182d2 | 4762 | + set_nlink(inode, h_inode->i_nlink); |
1facf9fc | 4763 | + |
4764 | + /* | |
4765 | + * fewer nlink makes find(1) noisy, but larger nlink doesn't. | |
4766 | + * it may includes whplink directory. | |
4767 | + */ | |
4768 | + if (S_ISDIR(h_inode->i_mode)) { | |
5afbbe0d AM |
4769 | + bbot = au_ibbot(inode); |
4770 | + for (bindex++; bindex <= bbot; bindex++) { | |
1facf9fc | 4771 | + h_inode = au_h_iptr(inode, bindex); |
4772 | + if (h_inode) | |
4773 | + au_add_nlink(inode, h_inode); | |
4774 | + } | |
4775 | + } | |
4776 | +} | |
4777 | + | |
4778 | +void au_cpup_attr_changeable(struct inode *inode) | |
4779 | +{ | |
4780 | + struct inode *h_inode; | |
4781 | + | |
5afbbe0d | 4782 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 4783 | + inode->i_mode = h_inode->i_mode; |
4784 | + inode->i_uid = h_inode->i_uid; | |
4785 | + inode->i_gid = h_inode->i_gid; | |
4786 | + au_cpup_attr_timesizes(inode); | |
86dc4139 | 4787 | + au_cpup_attr_flags(inode, h_inode->i_flags); |
1facf9fc | 4788 | +} |
4789 | + | |
4790 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode) | |
4791 | +{ | |
4792 | + struct au_iinfo *iinfo = au_ii(inode); | |
4793 | + | |
1308ab2a | 4794 | + IiMustWriteLock(inode); |
4795 | + | |
1facf9fc | 4796 | + iinfo->ii_higen = h_inode->i_generation; |
4797 | + iinfo->ii_hsb1 = h_inode->i_sb; | |
4798 | +} | |
4799 | + | |
4800 | +void au_cpup_attr_all(struct inode *inode, int force) | |
4801 | +{ | |
4802 | + struct inode *h_inode; | |
4803 | + | |
5afbbe0d | 4804 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 4805 | + au_cpup_attr_changeable(inode); |
4806 | + if (inode->i_nlink > 0) | |
4807 | + au_cpup_attr_nlink(inode, force); | |
4808 | + inode->i_rdev = h_inode->i_rdev; | |
4809 | + inode->i_blkbits = h_inode->i_blkbits; | |
4810 | + au_cpup_igen(inode, h_inode); | |
4811 | +} | |
4812 | + | |
4813 | +/* ---------------------------------------------------------------------- */ | |
4814 | + | |
4815 | +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */ | |
4816 | + | |
4817 | +/* keep the timestamps of the parent dir when cpup */ | |
4818 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
4819 | + struct path *h_path) | |
4820 | +{ | |
4821 | + struct inode *h_inode; | |
4822 | + | |
4823 | + dt->dt_dentry = dentry; | |
4824 | + dt->dt_h_path = *h_path; | |
5527c038 | 4825 | + h_inode = d_inode(h_path->dentry); |
1facf9fc | 4826 | + dt->dt_atime = h_inode->i_atime; |
4827 | + dt->dt_mtime = h_inode->i_mtime; | |
4828 | + /* smp_mb(); */ | |
4829 | +} | |
4830 | + | |
4831 | +void au_dtime_revert(struct au_dtime *dt) | |
4832 | +{ | |
4833 | + struct iattr attr; | |
4834 | + int err; | |
4835 | + | |
4836 | + attr.ia_atime = dt->dt_atime; | |
4837 | + attr.ia_mtime = dt->dt_mtime; | |
4838 | + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET | |
4839 | + | ATTR_ATIME | ATTR_ATIME_SET; | |
4840 | + | |
523b37e3 AM |
4841 | + /* no delegation since this is a directory */ |
4842 | + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL); | |
1facf9fc | 4843 | + if (unlikely(err)) |
0c3ec466 | 4844 | + pr_warn("restoring timestamps failed(%d). ignored\n", err); |
1facf9fc | 4845 | +} |
4846 | + | |
4847 | +/* ---------------------------------------------------------------------- */ | |
4848 | + | |
86dc4139 AM |
4849 | +/* internal use only */ |
4850 | +struct au_cpup_reg_attr { | |
4851 | + int valid; | |
4852 | + struct kstat st; | |
4853 | + unsigned int iflags; /* inode->i_flags */ | |
4854 | +}; | |
4855 | + | |
1facf9fc | 4856 | +static noinline_for_stack |
86dc4139 AM |
4857 | +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src, |
4858 | + struct au_cpup_reg_attr *h_src_attr) | |
1facf9fc | 4859 | +{ |
c1595e42 | 4860 | + int err, sbits, icex; |
7e9cd9fe AM |
4861 | + unsigned int mnt_flags; |
4862 | + unsigned char verbose; | |
1facf9fc | 4863 | + struct iattr ia; |
4864 | + struct path h_path; | |
1308ab2a | 4865 | + struct inode *h_isrc, *h_idst; |
86dc4139 | 4866 | + struct kstat *h_st; |
c1595e42 | 4867 | + struct au_branch *br; |
1facf9fc | 4868 | + |
4869 | + h_path.dentry = au_h_dptr(dst, bindex); | |
5527c038 | 4870 | + h_idst = d_inode(h_path.dentry); |
c1595e42 JR |
4871 | + br = au_sbr(dst->d_sb, bindex); |
4872 | + h_path.mnt = au_br_mnt(br); | |
5527c038 | 4873 | + h_isrc = d_inode(h_src); |
1308ab2a | 4874 | + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID |
1facf9fc | 4875 | + | ATTR_ATIME | ATTR_MTIME |
4876 | + | ATTR_ATIME_SET | ATTR_MTIME_SET; | |
86dc4139 AM |
4877 | + if (h_src_attr && h_src_attr->valid) { |
4878 | + h_st = &h_src_attr->st; | |
4879 | + ia.ia_uid = h_st->uid; | |
4880 | + ia.ia_gid = h_st->gid; | |
4881 | + ia.ia_atime = h_st->atime; | |
4882 | + ia.ia_mtime = h_st->mtime; | |
4883 | + if (h_idst->i_mode != h_st->mode | |
4884 | + && !S_ISLNK(h_idst->i_mode)) { | |
4885 | + ia.ia_valid |= ATTR_MODE; | |
4886 | + ia.ia_mode = h_st->mode; | |
4887 | + } | |
4888 | + sbits = !!(h_st->mode & (S_ISUID | S_ISGID)); | |
4889 | + au_cpup_attr_flags(h_idst, h_src_attr->iflags); | |
4890 | + } else { | |
4891 | + ia.ia_uid = h_isrc->i_uid; | |
4892 | + ia.ia_gid = h_isrc->i_gid; | |
4893 | + ia.ia_atime = h_isrc->i_atime; | |
4894 | + ia.ia_mtime = h_isrc->i_mtime; | |
4895 | + if (h_idst->i_mode != h_isrc->i_mode | |
4896 | + && !S_ISLNK(h_idst->i_mode)) { | |
4897 | + ia.ia_valid |= ATTR_MODE; | |
4898 | + ia.ia_mode = h_isrc->i_mode; | |
4899 | + } | |
4900 | + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID)); | |
4901 | + au_cpup_attr_flags(h_idst, h_isrc->i_flags); | |
1308ab2a | 4902 | + } |
523b37e3 AM |
4903 | + /* no delegation since it is just created */ |
4904 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 4905 | + |
4906 | + /* is this nfs only? */ | |
4907 | + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) { | |
4908 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
4909 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 4910 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); |
1facf9fc | 4911 | + } |
4912 | + | |
c1595e42 | 4913 | + icex = br->br_perm & AuBrAttr_ICEX; |
7e9cd9fe AM |
4914 | + if (!err) { |
4915 | + mnt_flags = au_mntflags(dst->d_sb); | |
4916 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
4917 | + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose); | |
4918 | + } | |
c1595e42 | 4919 | + |
1facf9fc | 4920 | + return err; |
4921 | +} | |
4922 | + | |
4923 | +/* ---------------------------------------------------------------------- */ | |
4924 | + | |
4925 | +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len, | |
4926 | + char *buf, unsigned long blksize) | |
4927 | +{ | |
4928 | + int err; | |
4929 | + size_t sz, rbytes, wbytes; | |
4930 | + unsigned char all_zero; | |
4931 | + char *p, *zp; | |
febd17d6 | 4932 | + struct inode *h_inode; |
1facf9fc | 4933 | + /* reduce stack usage */ |
4934 | + struct iattr *ia; | |
4935 | + | |
4936 | + zp = page_address(ZERO_PAGE(0)); | |
4937 | + if (unlikely(!zp)) | |
4938 | + return -ENOMEM; /* possible? */ | |
4939 | + | |
4940 | + err = 0; | |
4941 | + all_zero = 0; | |
4942 | + while (len) { | |
4943 | + AuDbg("len %lld\n", len); | |
4944 | + sz = blksize; | |
4945 | + if (len < blksize) | |
4946 | + sz = len; | |
4947 | + | |
4948 | + rbytes = 0; | |
4949 | + /* todo: signal_pending? */ | |
4950 | + while (!rbytes || err == -EAGAIN || err == -EINTR) { | |
4951 | + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos); | |
4952 | + err = rbytes; | |
4953 | + } | |
4954 | + if (unlikely(err < 0)) | |
4955 | + break; | |
4956 | + | |
4957 | + all_zero = 0; | |
4958 | + if (len >= rbytes && rbytes == blksize) | |
4959 | + all_zero = !memcmp(buf, zp, rbytes); | |
4960 | + if (!all_zero) { | |
4961 | + wbytes = rbytes; | |
4962 | + p = buf; | |
4963 | + while (wbytes) { | |
4964 | + size_t b; | |
4965 | + | |
4966 | + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos); | |
4967 | + err = b; | |
4968 | + /* todo: signal_pending? */ | |
4969 | + if (unlikely(err == -EAGAIN || err == -EINTR)) | |
4970 | + continue; | |
4971 | + if (unlikely(err < 0)) | |
4972 | + break; | |
4973 | + wbytes -= b; | |
4974 | + p += b; | |
4975 | + } | |
392086de AM |
4976 | + if (unlikely(err < 0)) |
4977 | + break; | |
1facf9fc | 4978 | + } else { |
4979 | + loff_t res; | |
4980 | + | |
4981 | + AuLabel(hole); | |
4982 | + res = vfsub_llseek(dst, rbytes, SEEK_CUR); | |
4983 | + err = res; | |
4984 | + if (unlikely(res < 0)) | |
4985 | + break; | |
4986 | + } | |
4987 | + len -= rbytes; | |
4988 | + err = 0; | |
4989 | + } | |
4990 | + | |
4991 | + /* the last block may be a hole */ | |
4992 | + if (!err && all_zero) { | |
4993 | + AuLabel(last hole); | |
4994 | + | |
4995 | + err = 1; | |
2000de60 | 4996 | + if (au_test_nfs(dst->f_path.dentry->d_sb)) { |
1facf9fc | 4997 | + /* nfs requires this step to make last hole */ |
4998 | + /* is this only nfs? */ | |
4999 | + do { | |
5000 | + /* todo: signal_pending? */ | |
5001 | + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos); | |
5002 | + } while (err == -EAGAIN || err == -EINTR); | |
5003 | + if (err == 1) | |
5004 | + dst->f_pos--; | |
5005 | + } | |
5006 | + | |
5007 | + if (err == 1) { | |
5008 | + ia = (void *)buf; | |
5009 | + ia->ia_size = dst->f_pos; | |
5010 | + ia->ia_valid = ATTR_SIZE | ATTR_FILE; | |
5011 | + ia->ia_file = dst; | |
febd17d6 JR |
5012 | + h_inode = file_inode(dst); |
5013 | + inode_lock_nested(h_inode, AuLsc_I_CHILD2); | |
523b37e3 AM |
5014 | + /* no delegation since it is just created */ |
5015 | + err = vfsub_notify_change(&dst->f_path, ia, | |
5016 | + /*delegated*/NULL); | |
febd17d6 | 5017 | + inode_unlock(h_inode); |
1facf9fc | 5018 | + } |
5019 | + } | |
5020 | + | |
5021 | + return err; | |
5022 | +} | |
5023 | + | |
5024 | +int au_copy_file(struct file *dst, struct file *src, loff_t len) | |
5025 | +{ | |
5026 | + int err; | |
5027 | + unsigned long blksize; | |
5028 | + unsigned char do_kfree; | |
5029 | + char *buf; | |
5030 | + | |
5031 | + err = -ENOMEM; | |
2000de60 | 5032 | + blksize = dst->f_path.dentry->d_sb->s_blocksize; |
1facf9fc | 5033 | + if (!blksize || PAGE_SIZE < blksize) |
5034 | + blksize = PAGE_SIZE; | |
5035 | + AuDbg("blksize %lu\n", blksize); | |
5036 | + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *)); | |
5037 | + if (do_kfree) | |
5038 | + buf = kmalloc(blksize, GFP_NOFS); | |
5039 | + else | |
5040 | + buf = (void *)__get_free_page(GFP_NOFS); | |
5041 | + if (unlikely(!buf)) | |
5042 | + goto out; | |
5043 | + | |
5044 | + if (len > (1 << 22)) | |
5045 | + AuDbg("copying a large file %lld\n", (long long)len); | |
5046 | + | |
5047 | + src->f_pos = 0; | |
5048 | + dst->f_pos = 0; | |
5049 | + err = au_do_copy_file(dst, src, len, buf, blksize); | |
5050 | + if (do_kfree) | |
f0c0a007 | 5051 | + au_delayed_kfree(buf); |
1facf9fc | 5052 | + else |
f0c0a007 | 5053 | + au_delayed_free_page((unsigned long)buf); |
1facf9fc | 5054 | + |
4f0767ce | 5055 | +out: |
1facf9fc | 5056 | + return err; |
5057 | +} | |
5058 | + | |
5059 | +/* | |
5060 | + * to support a sparse file which is opened with O_APPEND, | |
5061 | + * we need to close the file. | |
5062 | + */ | |
c2b27bf2 | 5063 | +static int au_cp_regular(struct au_cp_generic *cpg) |
1facf9fc | 5064 | +{ |
5065 | + int err, i; | |
5066 | + enum { SRC, DST }; | |
5067 | + struct { | |
5068 | + aufs_bindex_t bindex; | |
5069 | + unsigned int flags; | |
5070 | + struct dentry *dentry; | |
392086de | 5071 | + int force_wr; |
1facf9fc | 5072 | + struct file *file; |
523b37e3 | 5073 | + void *label; |
1facf9fc | 5074 | + } *f, file[] = { |
5075 | + { | |
c2b27bf2 | 5076 | + .bindex = cpg->bsrc, |
1facf9fc | 5077 | + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE, |
523b37e3 | 5078 | + .label = &&out |
1facf9fc | 5079 | + }, |
5080 | + { | |
c2b27bf2 | 5081 | + .bindex = cpg->bdst, |
1facf9fc | 5082 | + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE, |
392086de | 5083 | + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST), |
523b37e3 | 5084 | + .label = &&out_src |
1facf9fc | 5085 | + } |
5086 | + }; | |
521ced18 | 5087 | + struct super_block *sb, *h_src_sb; |
e2f27e51 | 5088 | + struct inode *h_src_inode; |
8cdd5066 | 5089 | + struct task_struct *tsk = current; |
1facf9fc | 5090 | + |
5091 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5092 | + sb = cpg->dentry->d_sb; |
1facf9fc | 5093 | + f = file; |
5094 | + for (i = 0; i < 2; i++, f++) { | |
c2b27bf2 AM |
5095 | + f->dentry = au_h_dptr(cpg->dentry, f->bindex); |
5096 | + f->file = au_h_open(cpg->dentry, f->bindex, f->flags, | |
392086de | 5097 | + /*file*/NULL, f->force_wr); |
1facf9fc | 5098 | + err = PTR_ERR(f->file); |
5099 | + if (IS_ERR(f->file)) | |
5100 | + goto *f->label; | |
1facf9fc | 5101 | + } |
5102 | + | |
5103 | + /* try stopping to update while we copyup */ | |
e2f27e51 | 5104 | + h_src_inode = d_inode(file[SRC].dentry); |
521ced18 JR |
5105 | + h_src_sb = h_src_inode->i_sb; |
5106 | + if (!au_test_nfs(h_src_sb)) | |
e2f27e51 | 5107 | + IMustLock(h_src_inode); |
521ced18 JR |
5108 | + |
5109 | + if (h_src_sb != file_inode(file[DST].file)->i_sb | |
5110 | + || !file[DST].file->f_op->clone_file_range) | |
5111 | + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len); | |
5112 | + else { | |
5113 | + if (!au_test_nfs(h_src_sb)) { | |
5114 | + inode_unlock(h_src_inode); | |
5115 | + err = vfsub_clone_file_range(file[SRC].file, | |
5116 | + file[DST].file, cpg->len); | |
5117 | + inode_lock(h_src_inode); | |
5118 | + } else | |
5119 | + err = vfsub_clone_file_range(file[SRC].file, | |
5120 | + file[DST].file, cpg->len); | |
5121 | + if (unlikely(err == -EOPNOTSUPP && au_test_nfs(h_src_sb))) | |
5122 | + /* the backend fs on NFS may not support cloning */ | |
5123 | + err = au_copy_file(file[DST].file, file[SRC].file, | |
5124 | + cpg->len); | |
5125 | + AuTraceErr(err); | |
5126 | + } | |
1facf9fc | 5127 | + |
8cdd5066 JR |
5128 | + /* i wonder if we had O_NO_DELAY_FPUT flag */ |
5129 | + if (tsk->flags & PF_KTHREAD) | |
5130 | + __fput_sync(file[DST].file); | |
5131 | + else { | |
5132 | + WARN(1, "%pD\nPlease report this warning to aufs-users ML", | |
5133 | + file[DST].file); | |
5134 | + fput(file[DST].file); | |
5135 | + /* | |
5136 | + * too bad. | |
5137 | + * we have to call both since we don't know which place the file | |
5138 | + * was added to. | |
5139 | + */ | |
5140 | + task_work_run(); | |
5141 | + flush_delayed_fput(); | |
5142 | + } | |
1facf9fc | 5143 | + au_sbr_put(sb, file[DST].bindex); |
523b37e3 | 5144 | + |
4f0767ce | 5145 | +out_src: |
1facf9fc | 5146 | + fput(file[SRC].file); |
5147 | + au_sbr_put(sb, file[SRC].bindex); | |
4f0767ce | 5148 | +out: |
1facf9fc | 5149 | + return err; |
5150 | +} | |
5151 | + | |
c2b27bf2 | 5152 | +static int au_do_cpup_regular(struct au_cp_generic *cpg, |
86dc4139 | 5153 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5154 | +{ |
5155 | + int err, rerr; | |
5156 | + loff_t l; | |
86dc4139 | 5157 | + struct path h_path; |
38d290e6 | 5158 | + struct inode *h_src_inode, *h_dst_inode; |
1facf9fc | 5159 | + |
5160 | + err = 0; | |
5527c038 | 5161 | + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc); |
86dc4139 | 5162 | + l = i_size_read(h_src_inode); |
c2b27bf2 AM |
5163 | + if (cpg->len == -1 || l < cpg->len) |
5164 | + cpg->len = l; | |
5165 | + if (cpg->len) { | |
86dc4139 | 5166 | + /* try stopping to update while we are referencing */ |
febd17d6 | 5167 | + inode_lock_nested(h_src_inode, AuLsc_I_CHILD); |
c2b27bf2 | 5168 | + au_pin_hdir_unlock(cpg->pin); |
1facf9fc | 5169 | + |
c2b27bf2 AM |
5170 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5171 | + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc); | |
86dc4139 | 5172 | + h_src_attr->iflags = h_src_inode->i_flags; |
5527c038 | 5173 | + if (!au_test_nfs(h_src_inode->i_sb)) |
521ced18 | 5174 | + err = vfsub_getattr(&h_path, &h_src_attr->st); |
5527c038 | 5175 | + else { |
febd17d6 | 5176 | + inode_unlock(h_src_inode); |
521ced18 | 5177 | + err = vfsub_getattr(&h_path, &h_src_attr->st); |
febd17d6 | 5178 | + inode_lock_nested(h_src_inode, AuLsc_I_CHILD); |
5527c038 | 5179 | + } |
86dc4139 | 5180 | + if (unlikely(err)) { |
febd17d6 | 5181 | + inode_unlock(h_src_inode); |
86dc4139 AM |
5182 | + goto out; |
5183 | + } | |
5184 | + h_src_attr->valid = 1; | |
e2f27e51 AM |
5185 | + if (!au_test_nfs(h_src_inode->i_sb)) { |
5186 | + err = au_cp_regular(cpg); | |
5187 | + inode_unlock(h_src_inode); | |
5188 | + } else { | |
5189 | + inode_unlock(h_src_inode); | |
5190 | + err = au_cp_regular(cpg); | |
5191 | + } | |
c2b27bf2 | 5192 | + rerr = au_pin_hdir_relock(cpg->pin); |
86dc4139 AM |
5193 | + if (!err && rerr) |
5194 | + err = rerr; | |
1facf9fc | 5195 | + } |
38d290e6 JR |
5196 | + if (!err && (h_src_inode->i_state & I_LINKABLE)) { |
5197 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst); | |
5527c038 | 5198 | + h_dst_inode = d_inode(h_path.dentry); |
38d290e6 JR |
5199 | + spin_lock(&h_dst_inode->i_lock); |
5200 | + h_dst_inode->i_state |= I_LINKABLE; | |
5201 | + spin_unlock(&h_dst_inode->i_lock); | |
5202 | + } | |
1facf9fc | 5203 | + |
4f0767ce | 5204 | +out: |
1facf9fc | 5205 | + return err; |
5206 | +} | |
5207 | + | |
5208 | +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src, | |
5209 | + struct inode *h_dir) | |
5210 | +{ | |
5211 | + int err, symlen; | |
5212 | + mm_segment_t old_fs; | |
b752ccd1 AM |
5213 | + union { |
5214 | + char *k; | |
5215 | + char __user *u; | |
5216 | + } sym; | |
1facf9fc | 5217 | + |
5218 | + err = -ENOMEM; | |
537831f9 | 5219 | + sym.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 5220 | + if (unlikely(!sym.k)) |
1facf9fc | 5221 | + goto out; |
5222 | + | |
9dbd164d | 5223 | + /* unnecessary to support mmap_sem since symlink is not mmap-able */ |
1facf9fc | 5224 | + old_fs = get_fs(); |
5225 | + set_fs(KERNEL_DS); | |
a2654f78 | 5226 | + symlen = vfs_readlink(h_src, sym.u, PATH_MAX); |
1facf9fc | 5227 | + err = symlen; |
5228 | + set_fs(old_fs); | |
5229 | + | |
5230 | + if (symlen > 0) { | |
b752ccd1 AM |
5231 | + sym.k[symlen] = 0; |
5232 | + err = vfsub_symlink(h_dir, h_path, sym.k); | |
1facf9fc | 5233 | + } |
f0c0a007 | 5234 | + au_delayed_free_page((unsigned long)sym.k); |
1facf9fc | 5235 | + |
4f0767ce | 5236 | +out: |
1facf9fc | 5237 | + return err; |
5238 | +} | |
5239 | + | |
8cdd5066 JR |
5240 | +/* |
5241 | + * regardless 'acl' option, reset all ACL. | |
5242 | + * All ACL will be copied up later from the original entry on the lower branch. | |
5243 | + */ | |
5244 | +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode) | |
5245 | +{ | |
5246 | + int err; | |
5247 | + struct dentry *h_dentry; | |
5248 | + struct inode *h_inode; | |
5249 | + | |
5250 | + h_dentry = h_path->dentry; | |
5251 | + h_inode = d_inode(h_dentry); | |
5252 | + /* forget_all_cached_acls(h_inode)); */ | |
5253 | + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS); | |
5254 | + AuTraceErr(err); | |
5255 | + if (err == -EOPNOTSUPP) | |
5256 | + err = 0; | |
5257 | + if (!err) | |
5258 | + err = vfsub_acl_chmod(h_inode, mode); | |
5259 | + | |
5260 | + AuTraceErr(err); | |
5261 | + return err; | |
5262 | +} | |
5263 | + | |
5264 | +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent, | |
5265 | + struct inode *h_dir, struct path *h_path) | |
5266 | +{ | |
5267 | + int err; | |
5268 | + struct inode *dir, *inode; | |
5269 | + | |
5270 | + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT); | |
5271 | + AuTraceErr(err); | |
5272 | + if (err == -EOPNOTSUPP) | |
5273 | + err = 0; | |
5274 | + if (unlikely(err)) | |
5275 | + goto out; | |
5276 | + | |
5277 | + /* | |
5278 | + * strange behaviour from the users view, | |
5279 | + * particularry setattr case | |
5280 | + */ | |
5281 | + dir = d_inode(dst_parent); | |
5afbbe0d | 5282 | + if (au_ibtop(dir) == cpg->bdst) |
8cdd5066 JR |
5283 | + au_cpup_attr_nlink(dir, /*force*/1); |
5284 | + inode = d_inode(cpg->dentry); | |
5285 | + au_cpup_attr_nlink(inode, /*force*/1); | |
5286 | + | |
5287 | +out: | |
5288 | + return err; | |
5289 | +} | |
5290 | + | |
1facf9fc | 5291 | +static noinline_for_stack |
c2b27bf2 | 5292 | +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent, |
86dc4139 | 5293 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5294 | +{ |
5295 | + int err; | |
5296 | + umode_t mode; | |
5297 | + unsigned int mnt_flags; | |
076b876e | 5298 | + unsigned char isdir, isreg, force; |
c2b27bf2 | 5299 | + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5300 | + struct au_dtime dt; |
5301 | + struct path h_path; | |
5302 | + struct dentry *h_src, *h_dst, *h_parent; | |
8cdd5066 | 5303 | + struct inode *h_inode, *h_dir; |
1facf9fc | 5304 | + struct super_block *sb; |
5305 | + | |
5306 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5307 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 JR |
5308 | + h_inode = d_inode(h_src); |
5309 | + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc)); | |
1facf9fc | 5310 | + |
5311 | + /* try stopping to be referenced while we are creating */ | |
c2b27bf2 AM |
5312 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); |
5313 | + if (au_ftest_cpup(cpg->flags, RENAME)) | |
86dc4139 AM |
5314 | + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX, |
5315 | + AUFS_WH_PFX_LEN)); | |
1facf9fc | 5316 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5317 | + h_dir = d_inode(h_parent); |
1facf9fc | 5318 | + IMustLock(h_dir); |
5319 | + AuDebugOn(h_parent != h_dst->d_parent); | |
5320 | + | |
c2b27bf2 AM |
5321 | + sb = cpg->dentry->d_sb; |
5322 | + h_path.mnt = au_sbr_mnt(sb, cpg->bdst); | |
1facf9fc | 5323 | + if (do_dt) { |
5324 | + h_path.dentry = h_parent; | |
5325 | + au_dtime_store(&dt, dst_parent, &h_path); | |
5326 | + } | |
5327 | + h_path.dentry = h_dst; | |
5328 | + | |
076b876e | 5329 | + isreg = 0; |
1facf9fc | 5330 | + isdir = 0; |
5331 | + mode = h_inode->i_mode; | |
5332 | + switch (mode & S_IFMT) { | |
5333 | + case S_IFREG: | |
076b876e | 5334 | + isreg = 1; |
8cdd5066 | 5335 | + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR, |
b4510431 | 5336 | + /*want_excl*/true); |
1facf9fc | 5337 | + if (!err) |
c2b27bf2 | 5338 | + err = au_do_cpup_regular(cpg, h_src_attr); |
1facf9fc | 5339 | + break; |
5340 | + case S_IFDIR: | |
5341 | + isdir = 1; | |
5342 | + err = vfsub_mkdir(h_dir, &h_path, mode); | |
8cdd5066 JR |
5343 | + if (!err) |
5344 | + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path); | |
1facf9fc | 5345 | + break; |
5346 | + case S_IFLNK: | |
5347 | + err = au_do_cpup_symlink(&h_path, h_src, h_dir); | |
5348 | + break; | |
5349 | + case S_IFCHR: | |
5350 | + case S_IFBLK: | |
5351 | + AuDebugOn(!capable(CAP_MKNOD)); | |
5352 | + /*FALLTHROUGH*/ | |
5353 | + case S_IFIFO: | |
5354 | + case S_IFSOCK: | |
5355 | + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev); | |
5356 | + break; | |
5357 | + default: | |
5358 | + AuIOErr("Unknown inode type 0%o\n", mode); | |
5359 | + err = -EIO; | |
5360 | + } | |
8cdd5066 JR |
5361 | + if (!err) |
5362 | + err = au_reset_acl(h_dir, &h_path, mode); | |
1facf9fc | 5363 | + |
5364 | + mnt_flags = au_mntflags(sb); | |
5365 | + if (!au_opt_test(mnt_flags, UDBA_NONE) | |
5366 | + && !isdir | |
5367 | + && au_opt_test(mnt_flags, XINO) | |
38d290e6 JR |
5368 | + && (h_inode->i_nlink == 1 |
5369 | + || (h_inode->i_state & I_LINKABLE)) | |
1facf9fc | 5370 | + /* todo: unnecessary? */ |
5527c038 | 5371 | + /* && d_inode(cpg->dentry)->i_nlink == 1 */ |
c2b27bf2 AM |
5372 | + && cpg->bdst < cpg->bsrc |
5373 | + && !au_ftest_cpup(cpg->flags, KEEPLINO)) | |
5374 | + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0); | |
1facf9fc | 5375 | + /* ignore this error */ |
5376 | + | |
076b876e AM |
5377 | + if (!err) { |
5378 | + force = 0; | |
5379 | + if (isreg) { | |
5380 | + force = !!cpg->len; | |
5381 | + if (cpg->len == -1) | |
5382 | + force = !!i_size_read(h_inode); | |
5383 | + } | |
5384 | + au_fhsm_wrote(sb, cpg->bdst, force); | |
5385 | + } | |
5386 | + | |
1facf9fc | 5387 | + if (do_dt) |
5388 | + au_dtime_revert(&dt); | |
5389 | + return err; | |
5390 | +} | |
5391 | + | |
392086de | 5392 | +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path) |
86dc4139 AM |
5393 | +{ |
5394 | + int err; | |
392086de | 5395 | + struct dentry *dentry, *h_dentry, *h_parent, *parent; |
86dc4139 | 5396 | + struct inode *h_dir; |
392086de | 5397 | + aufs_bindex_t bdst; |
86dc4139 | 5398 | + |
392086de AM |
5399 | + dentry = cpg->dentry; |
5400 | + bdst = cpg->bdst; | |
5401 | + h_dentry = au_h_dptr(dentry, bdst); | |
5402 | + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) { | |
5403 | + dget(h_dentry); | |
5404 | + au_set_h_dptr(dentry, bdst, NULL); | |
5405 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); | |
5406 | + if (!err) | |
5407 | + h_path->dentry = dget(au_h_dptr(dentry, bdst)); | |
86dc4139 | 5408 | + au_set_h_dptr(dentry, bdst, h_dentry); |
392086de AM |
5409 | + } else { |
5410 | + err = 0; | |
5411 | + parent = dget_parent(dentry); | |
5412 | + h_parent = au_h_dptr(parent, bdst); | |
5413 | + dput(parent); | |
5414 | + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
5415 | + if (IS_ERR(h_path->dentry)) | |
5416 | + err = PTR_ERR(h_path->dentry); | |
86dc4139 | 5417 | + } |
392086de AM |
5418 | + if (unlikely(err)) |
5419 | + goto out; | |
86dc4139 | 5420 | + |
86dc4139 | 5421 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ |
5527c038 | 5422 | + h_dir = d_inode(h_parent); |
86dc4139 | 5423 | + IMustLock(h_dir); |
523b37e3 AM |
5424 | + AuDbg("%pd %pd\n", h_dentry, h_path->dentry); |
5425 | + /* no delegation since it is just created */ | |
f2c43d5f AM |
5426 | + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL, |
5427 | + /*flags*/0); | |
86dc4139 AM |
5428 | + dput(h_path->dentry); |
5429 | + | |
5430 | +out: | |
5431 | + return err; | |
5432 | +} | |
5433 | + | |
1facf9fc | 5434 | +/* |
5435 | + * copyup the @dentry from @bsrc to @bdst. | |
5436 | + * the caller must set the both of lower dentries. | |
5437 | + * @len is for truncating when it is -1 copyup the entire file. | |
5438 | + * in link/rename cases, @dst_parent may be different from the real one. | |
c2b27bf2 | 5439 | + * basic->bsrc can be larger than basic->bdst. |
f2c43d5f AM |
5440 | + * aufs doesn't touch the credential so |
5441 | + * security_inode_copy_up{,_xattr}() are unnecrssary. | |
1facf9fc | 5442 | + */ |
c2b27bf2 | 5443 | +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5444 | +{ |
5445 | + int err, rerr; | |
5afbbe0d | 5446 | + aufs_bindex_t old_ibtop; |
1facf9fc | 5447 | + unsigned char isdir, plink; |
1facf9fc | 5448 | + struct dentry *h_src, *h_dst, *h_parent; |
5527c038 | 5449 | + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode; |
1facf9fc | 5450 | + struct super_block *sb; |
86dc4139 | 5451 | + struct au_branch *br; |
c2b27bf2 AM |
5452 | + /* to reuduce stack size */ |
5453 | + struct { | |
5454 | + struct au_dtime dt; | |
5455 | + struct path h_path; | |
5456 | + struct au_cpup_reg_attr h_src_attr; | |
5457 | + } *a; | |
1facf9fc | 5458 | + |
c2b27bf2 AM |
5459 | + err = -ENOMEM; |
5460 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
5461 | + if (unlikely(!a)) | |
5462 | + goto out; | |
5463 | + a->h_src_attr.valid = 0; | |
1facf9fc | 5464 | + |
c2b27bf2 AM |
5465 | + sb = cpg->dentry->d_sb; |
5466 | + br = au_sbr(sb, cpg->bdst); | |
5467 | + a->h_path.mnt = au_br_mnt(br); | |
5468 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); | |
1facf9fc | 5469 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5470 | + h_dir = d_inode(h_parent); |
1facf9fc | 5471 | + IMustLock(h_dir); |
5472 | + | |
c2b27bf2 | 5473 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5474 | + inode = d_inode(cpg->dentry); |
1facf9fc | 5475 | + |
5476 | + if (!dst_parent) | |
c2b27bf2 | 5477 | + dst_parent = dget_parent(cpg->dentry); |
1facf9fc | 5478 | + else |
5479 | + dget(dst_parent); | |
5480 | + | |
5481 | + plink = !!au_opt_test(au_mntflags(sb), PLINK); | |
c2b27bf2 | 5482 | + dst_inode = au_h_iptr(inode, cpg->bdst); |
1facf9fc | 5483 | + if (dst_inode) { |
5484 | + if (unlikely(!plink)) { | |
5485 | + err = -EIO; | |
027c5e7a AM |
5486 | + AuIOErr("hi%lu(i%lu) exists on b%d " |
5487 | + "but plink is disabled\n", | |
c2b27bf2 AM |
5488 | + dst_inode->i_ino, inode->i_ino, cpg->bdst); |
5489 | + goto out_parent; | |
1facf9fc | 5490 | + } |
5491 | + | |
5492 | + if (dst_inode->i_nlink) { | |
c2b27bf2 | 5493 | + const int do_dt = au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5494 | + |
c2b27bf2 | 5495 | + h_src = au_plink_lkup(inode, cpg->bdst); |
1facf9fc | 5496 | + err = PTR_ERR(h_src); |
5497 | + if (IS_ERR(h_src)) | |
c2b27bf2 | 5498 | + goto out_parent; |
5527c038 | 5499 | + if (unlikely(d_is_negative(h_src))) { |
1facf9fc | 5500 | + err = -EIO; |
79b8bda9 | 5501 | + AuIOErr("i%lu exists on b%d " |
027c5e7a | 5502 | + "but not pseudo-linked\n", |
79b8bda9 | 5503 | + inode->i_ino, cpg->bdst); |
1facf9fc | 5504 | + dput(h_src); |
c2b27bf2 | 5505 | + goto out_parent; |
1facf9fc | 5506 | + } |
5507 | + | |
5508 | + if (do_dt) { | |
c2b27bf2 AM |
5509 | + a->h_path.dentry = h_parent; |
5510 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
1facf9fc | 5511 | + } |
86dc4139 | 5512 | + |
c2b27bf2 | 5513 | + a->h_path.dentry = h_dst; |
523b37e3 AM |
5514 | + delegated = NULL; |
5515 | + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated); | |
c2b27bf2 | 5516 | + if (!err && au_ftest_cpup(cpg->flags, RENAME)) |
392086de | 5517 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
1facf9fc | 5518 | + if (do_dt) |
c2b27bf2 | 5519 | + au_dtime_revert(&a->dt); |
523b37e3 AM |
5520 | + if (unlikely(err == -EWOULDBLOCK)) { |
5521 | + pr_warn("cannot retry for NFSv4 delegation" | |
5522 | + " for an internal link\n"); | |
5523 | + iput(delegated); | |
5524 | + } | |
1facf9fc | 5525 | + dput(h_src); |
c2b27bf2 | 5526 | + goto out_parent; |
1facf9fc | 5527 | + } else |
5528 | + /* todo: cpup_wh_file? */ | |
5529 | + /* udba work */ | |
4a4d8108 | 5530 | + au_update_ibrange(inode, /*do_put_zero*/1); |
1facf9fc | 5531 | + } |
5532 | + | |
86dc4139 | 5533 | + isdir = S_ISDIR(inode->i_mode); |
5afbbe0d | 5534 | + old_ibtop = au_ibtop(inode); |
c2b27bf2 | 5535 | + err = cpup_entry(cpg, dst_parent, &a->h_src_attr); |
1facf9fc | 5536 | + if (unlikely(err)) |
86dc4139 | 5537 | + goto out_rev; |
5527c038 | 5538 | + dst_inode = d_inode(h_dst); |
febd17d6 | 5539 | + inode_lock_nested(dst_inode, AuLsc_I_CHILD2); |
86dc4139 | 5540 | + /* todo: necessary? */ |
c2b27bf2 | 5541 | + /* au_pin_hdir_unlock(cpg->pin); */ |
1facf9fc | 5542 | + |
c2b27bf2 | 5543 | + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr); |
86dc4139 AM |
5544 | + if (unlikely(err)) { |
5545 | + /* todo: necessary? */ | |
c2b27bf2 | 5546 | + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */ |
febd17d6 | 5547 | + inode_unlock(dst_inode); |
86dc4139 AM |
5548 | + goto out_rev; |
5549 | + } | |
5550 | + | |
5afbbe0d | 5551 | + if (cpg->bdst < old_ibtop) { |
86dc4139 | 5552 | + if (S_ISREG(inode->i_mode)) { |
c2b27bf2 | 5553 | + err = au_dy_iaop(inode, cpg->bdst, dst_inode); |
86dc4139 | 5554 | + if (unlikely(err)) { |
c2b27bf2 AM |
5555 | + /* ignore an error */ |
5556 | + /* au_pin_hdir_relock(cpg->pin); */ | |
febd17d6 | 5557 | + inode_unlock(dst_inode); |
86dc4139 | 5558 | + goto out_rev; |
4a4d8108 | 5559 | + } |
4a4d8108 | 5560 | + } |
5afbbe0d | 5561 | + au_set_ibtop(inode, cpg->bdst); |
c2b27bf2 | 5562 | + } else |
5afbbe0d | 5563 | + au_set_ibbot(inode, cpg->bdst); |
c2b27bf2 | 5564 | + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode), |
86dc4139 AM |
5565 | + au_hi_flags(inode, isdir)); |
5566 | + | |
5567 | + /* todo: necessary? */ | |
c2b27bf2 | 5568 | + /* err = au_pin_hdir_relock(cpg->pin); */ |
febd17d6 | 5569 | + inode_unlock(dst_inode); |
86dc4139 AM |
5570 | + if (unlikely(err)) |
5571 | + goto out_rev; | |
5572 | + | |
5527c038 | 5573 | + src_inode = d_inode(h_src); |
86dc4139 | 5574 | + if (!isdir |
5527c038 JR |
5575 | + && (src_inode->i_nlink > 1 |
5576 | + || src_inode->i_state & I_LINKABLE) | |
86dc4139 | 5577 | + && plink) |
c2b27bf2 | 5578 | + au_plink_append(inode, cpg->bdst, h_dst); |
86dc4139 | 5579 | + |
c2b27bf2 AM |
5580 | + if (au_ftest_cpup(cpg->flags, RENAME)) { |
5581 | + a->h_path.dentry = h_dst; | |
392086de | 5582 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
86dc4139 AM |
5583 | + } |
5584 | + if (!err) | |
c2b27bf2 | 5585 | + goto out_parent; /* success */ |
1facf9fc | 5586 | + |
5587 | + /* revert */ | |
4a4d8108 | 5588 | +out_rev: |
c2b27bf2 AM |
5589 | + a->h_path.dentry = h_parent; |
5590 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
5591 | + a->h_path.dentry = h_dst; | |
86dc4139 | 5592 | + rerr = 0; |
5527c038 | 5593 | + if (d_is_positive(h_dst)) { |
523b37e3 AM |
5594 | + if (!isdir) { |
5595 | + /* no delegation since it is just created */ | |
5596 | + rerr = vfsub_unlink(h_dir, &a->h_path, | |
5597 | + /*delegated*/NULL, /*force*/0); | |
5598 | + } else | |
c2b27bf2 | 5599 | + rerr = vfsub_rmdir(h_dir, &a->h_path); |
86dc4139 | 5600 | + } |
c2b27bf2 | 5601 | + au_dtime_revert(&a->dt); |
1facf9fc | 5602 | + if (rerr) { |
5603 | + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr); | |
5604 | + err = -EIO; | |
5605 | + } | |
c2b27bf2 | 5606 | +out_parent: |
1facf9fc | 5607 | + dput(dst_parent); |
f0c0a007 | 5608 | + au_delayed_kfree(a); |
c2b27bf2 | 5609 | +out: |
1facf9fc | 5610 | + return err; |
5611 | +} | |
5612 | + | |
7e9cd9fe | 5613 | +#if 0 /* reserved */ |
1facf9fc | 5614 | +struct au_cpup_single_args { |
5615 | + int *errp; | |
c2b27bf2 | 5616 | + struct au_cp_generic *cpg; |
1facf9fc | 5617 | + struct dentry *dst_parent; |
5618 | +}; | |
5619 | + | |
5620 | +static void au_call_cpup_single(void *args) | |
5621 | +{ | |
5622 | + struct au_cpup_single_args *a = args; | |
86dc4139 | 5623 | + |
c2b27bf2 AM |
5624 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5625 | + *a->errp = au_cpup_single(a->cpg, a->dst_parent); | |
5626 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5627 | +} |
c2b27bf2 | 5628 | +#endif |
1facf9fc | 5629 | + |
53392da6 AM |
5630 | +/* |
5631 | + * prevent SIGXFSZ in copy-up. | |
5632 | + * testing CAP_MKNOD is for generic fs, | |
5633 | + * but CAP_FSETID is for xfs only, currently. | |
5634 | + */ | |
86dc4139 | 5635 | +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode) |
53392da6 AM |
5636 | +{ |
5637 | + int do_sio; | |
86dc4139 AM |
5638 | + struct super_block *sb; |
5639 | + struct inode *h_dir; | |
53392da6 AM |
5640 | + |
5641 | + do_sio = 0; | |
86dc4139 | 5642 | + sb = au_pinned_parent(pin)->d_sb; |
53392da6 AM |
5643 | + if (!au_wkq_test() |
5644 | + && (!au_sbi(sb)->si_plink_maint_pid | |
5645 | + || au_plink_maint(sb, AuLock_NOPLM))) { | |
5646 | + switch (mode & S_IFMT) { | |
5647 | + case S_IFREG: | |
5648 | + /* no condition about RLIMIT_FSIZE and the file size */ | |
5649 | + do_sio = 1; | |
5650 | + break; | |
5651 | + case S_IFCHR: | |
5652 | + case S_IFBLK: | |
5653 | + do_sio = !capable(CAP_MKNOD); | |
5654 | + break; | |
5655 | + } | |
5656 | + if (!do_sio) | |
5657 | + do_sio = ((mode & (S_ISUID | S_ISGID)) | |
5658 | + && !capable(CAP_FSETID)); | |
86dc4139 AM |
5659 | + /* this workaround may be removed in the future */ |
5660 | + if (!do_sio) { | |
5661 | + h_dir = au_pinned_h_dir(pin); | |
5662 | + do_sio = h_dir->i_mode & S_ISVTX; | |
5663 | + } | |
53392da6 AM |
5664 | + } |
5665 | + | |
5666 | + return do_sio; | |
5667 | +} | |
5668 | + | |
7e9cd9fe | 5669 | +#if 0 /* reserved */ |
c2b27bf2 | 5670 | +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5671 | +{ |
5672 | + int err, wkq_err; | |
1facf9fc | 5673 | + struct dentry *h_dentry; |
5674 | + | |
c2b27bf2 | 5675 | + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5676 | + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode)) |
c2b27bf2 | 5677 | + err = au_cpup_single(cpg, dst_parent); |
1facf9fc | 5678 | + else { |
5679 | + struct au_cpup_single_args args = { | |
5680 | + .errp = &err, | |
c2b27bf2 AM |
5681 | + .cpg = cpg, |
5682 | + .dst_parent = dst_parent | |
1facf9fc | 5683 | + }; |
5684 | + wkq_err = au_wkq_wait(au_call_cpup_single, &args); | |
5685 | + if (unlikely(wkq_err)) | |
5686 | + err = wkq_err; | |
5687 | + } | |
5688 | + | |
5689 | + return err; | |
5690 | +} | |
c2b27bf2 | 5691 | +#endif |
1facf9fc | 5692 | + |
5693 | +/* | |
5694 | + * copyup the @dentry from the first active lower branch to @bdst, | |
5695 | + * using au_cpup_single(). | |
5696 | + */ | |
c2b27bf2 | 5697 | +static int au_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5698 | +{ |
5699 | + int err; | |
c2b27bf2 AM |
5700 | + unsigned int flags_orig; |
5701 | + struct dentry *dentry; | |
5702 | + | |
5703 | + AuDebugOn(cpg->bsrc < 0); | |
1facf9fc | 5704 | + |
c2b27bf2 | 5705 | + dentry = cpg->dentry; |
86dc4139 | 5706 | + DiMustWriteLock(dentry); |
1facf9fc | 5707 | + |
c2b27bf2 | 5708 | + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1); |
1facf9fc | 5709 | + if (!err) { |
c2b27bf2 AM |
5710 | + flags_orig = cpg->flags; |
5711 | + au_fset_cpup(cpg->flags, RENAME); | |
5712 | + err = au_cpup_single(cpg, NULL); | |
5713 | + cpg->flags = flags_orig; | |
1facf9fc | 5714 | + if (!err) |
5715 | + return 0; /* success */ | |
5716 | + | |
5717 | + /* revert */ | |
c2b27bf2 | 5718 | + au_set_h_dptr(dentry, cpg->bdst, NULL); |
5afbbe0d | 5719 | + au_set_dbtop(dentry, cpg->bsrc); |
1facf9fc | 5720 | + } |
5721 | + | |
5722 | + return err; | |
5723 | +} | |
5724 | + | |
5725 | +struct au_cpup_simple_args { | |
5726 | + int *errp; | |
c2b27bf2 | 5727 | + struct au_cp_generic *cpg; |
1facf9fc | 5728 | +}; |
5729 | + | |
5730 | +static void au_call_cpup_simple(void *args) | |
5731 | +{ | |
5732 | + struct au_cpup_simple_args *a = args; | |
86dc4139 | 5733 | + |
c2b27bf2 AM |
5734 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5735 | + *a->errp = au_cpup_simple(a->cpg); | |
5736 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5737 | +} |
5738 | + | |
c2b27bf2 | 5739 | +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5740 | +{ |
5741 | + int err, wkq_err; | |
c2b27bf2 AM |
5742 | + struct dentry *dentry, *parent; |
5743 | + struct file *h_file; | |
1facf9fc | 5744 | + struct inode *h_dir; |
5745 | + | |
c2b27bf2 AM |
5746 | + dentry = cpg->dentry; |
5747 | + h_file = NULL; | |
5748 | + if (au_ftest_cpup(cpg->flags, HOPEN)) { | |
5749 | + AuDebugOn(cpg->bsrc < 0); | |
392086de | 5750 | + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0); |
c2b27bf2 AM |
5751 | + err = PTR_ERR(h_file); |
5752 | + if (IS_ERR(h_file)) | |
5753 | + goto out; | |
5754 | + } | |
5755 | + | |
1facf9fc | 5756 | + parent = dget_parent(dentry); |
5527c038 | 5757 | + h_dir = au_h_iptr(d_inode(parent), cpg->bdst); |
53392da6 | 5758 | + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE) |
5527c038 | 5759 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 5760 | + err = au_cpup_simple(cpg); |
1facf9fc | 5761 | + else { |
5762 | + struct au_cpup_simple_args args = { | |
5763 | + .errp = &err, | |
c2b27bf2 | 5764 | + .cpg = cpg |
1facf9fc | 5765 | + }; |
5766 | + wkq_err = au_wkq_wait(au_call_cpup_simple, &args); | |
5767 | + if (unlikely(wkq_err)) | |
5768 | + err = wkq_err; | |
5769 | + } | |
5770 | + | |
5771 | + dput(parent); | |
c2b27bf2 AM |
5772 | + if (h_file) |
5773 | + au_h_open_post(dentry, cpg->bsrc, h_file); | |
5774 | + | |
5775 | +out: | |
1facf9fc | 5776 | + return err; |
5777 | +} | |
5778 | + | |
c2b27bf2 | 5779 | +int au_sio_cpup_simple(struct au_cp_generic *cpg) |
367653fa | 5780 | +{ |
5afbbe0d | 5781 | + aufs_bindex_t bsrc, bbot; |
c2b27bf2 | 5782 | + struct dentry *dentry, *h_dentry; |
367653fa | 5783 | + |
c2b27bf2 AM |
5784 | + if (cpg->bsrc < 0) { |
5785 | + dentry = cpg->dentry; | |
5afbbe0d AM |
5786 | + bbot = au_dbbot(dentry); |
5787 | + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) { | |
c2b27bf2 AM |
5788 | + h_dentry = au_h_dptr(dentry, bsrc); |
5789 | + if (h_dentry) { | |
5527c038 | 5790 | + AuDebugOn(d_is_negative(h_dentry)); |
c2b27bf2 AM |
5791 | + break; |
5792 | + } | |
5793 | + } | |
5afbbe0d | 5794 | + AuDebugOn(bsrc > bbot); |
c2b27bf2 | 5795 | + cpg->bsrc = bsrc; |
367653fa | 5796 | + } |
c2b27bf2 AM |
5797 | + AuDebugOn(cpg->bsrc <= cpg->bdst); |
5798 | + return au_do_sio_cpup_simple(cpg); | |
5799 | +} | |
367653fa | 5800 | + |
c2b27bf2 AM |
5801 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg) |
5802 | +{ | |
5803 | + AuDebugOn(cpg->bdst <= cpg->bsrc); | |
5804 | + return au_do_sio_cpup_simple(cpg); | |
367653fa AM |
5805 | +} |
5806 | + | |
1facf9fc | 5807 | +/* ---------------------------------------------------------------------- */ |
5808 | + | |
5809 | +/* | |
5810 | + * copyup the deleted file for writing. | |
5811 | + */ | |
c2b27bf2 AM |
5812 | +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry, |
5813 | + struct file *file) | |
1facf9fc | 5814 | +{ |
5815 | + int err; | |
c2b27bf2 AM |
5816 | + unsigned int flags_orig; |
5817 | + aufs_bindex_t bsrc_orig; | |
c2b27bf2 | 5818 | + struct au_dinfo *dinfo; |
5afbbe0d AM |
5819 | + struct { |
5820 | + struct au_hdentry *hd; | |
5821 | + struct dentry *h_dentry; | |
5822 | + } hdst, hsrc; | |
1facf9fc | 5823 | + |
c2b27bf2 | 5824 | + dinfo = au_di(cpg->dentry); |
1308ab2a | 5825 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
5826 | + | |
c2b27bf2 | 5827 | + bsrc_orig = cpg->bsrc; |
5afbbe0d AM |
5828 | + cpg->bsrc = dinfo->di_btop; |
5829 | + hdst.hd = au_hdentry(dinfo, cpg->bdst); | |
5830 | + hdst.h_dentry = hdst.hd->hd_dentry; | |
5831 | + hdst.hd->hd_dentry = wh_dentry; | |
5832 | + dinfo->di_btop = cpg->bdst; | |
5833 | + | |
5834 | + hsrc.h_dentry = NULL; | |
027c5e7a | 5835 | + if (file) { |
5afbbe0d AM |
5836 | + hsrc.hd = au_hdentry(dinfo, cpg->bsrc); |
5837 | + hsrc.h_dentry = hsrc.hd->hd_dentry; | |
5838 | + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry; | |
027c5e7a | 5839 | + } |
c2b27bf2 AM |
5840 | + flags_orig = cpg->flags; |
5841 | + cpg->flags = !AuCpup_DTIME; | |
5842 | + err = au_cpup_single(cpg, /*h_parent*/NULL); | |
5843 | + cpg->flags = flags_orig; | |
027c5e7a AM |
5844 | + if (file) { |
5845 | + if (!err) | |
5846 | + err = au_reopen_nondir(file); | |
5afbbe0d | 5847 | + hsrc.hd->hd_dentry = hsrc.h_dentry; |
1facf9fc | 5848 | + } |
5afbbe0d AM |
5849 | + hdst.hd->hd_dentry = hdst.h_dentry; |
5850 | + dinfo->di_btop = cpg->bsrc; | |
c2b27bf2 | 5851 | + cpg->bsrc = bsrc_orig; |
1facf9fc | 5852 | + |
5853 | + return err; | |
5854 | +} | |
5855 | + | |
c2b27bf2 | 5856 | +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5857 | +{ |
5858 | + int err; | |
c2b27bf2 | 5859 | + aufs_bindex_t bdst; |
1facf9fc | 5860 | + struct au_dtime dt; |
c2b27bf2 | 5861 | + struct dentry *dentry, *parent, *h_parent, *wh_dentry; |
1facf9fc | 5862 | + struct au_branch *br; |
5863 | + struct path h_path; | |
5864 | + | |
c2b27bf2 AM |
5865 | + dentry = cpg->dentry; |
5866 | + bdst = cpg->bdst; | |
1facf9fc | 5867 | + br = au_sbr(dentry->d_sb, bdst); |
5868 | + parent = dget_parent(dentry); | |
5869 | + h_parent = au_h_dptr(parent, bdst); | |
5870 | + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
5871 | + err = PTR_ERR(wh_dentry); | |
5872 | + if (IS_ERR(wh_dentry)) | |
5873 | + goto out; | |
5874 | + | |
5875 | + h_path.dentry = h_parent; | |
86dc4139 | 5876 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 5877 | + au_dtime_store(&dt, parent, &h_path); |
c2b27bf2 | 5878 | + err = au_do_cpup_wh(cpg, wh_dentry, file); |
1facf9fc | 5879 | + if (unlikely(err)) |
5880 | + goto out_wh; | |
5881 | + | |
5882 | + dget(wh_dentry); | |
5883 | + h_path.dentry = wh_dentry; | |
2000de60 | 5884 | + if (!d_is_dir(wh_dentry)) { |
523b37e3 | 5885 | + /* no delegation since it is just created */ |
5527c038 | 5886 | + err = vfsub_unlink(d_inode(h_parent), &h_path, |
523b37e3 AM |
5887 | + /*delegated*/NULL, /*force*/0); |
5888 | + } else | |
5527c038 | 5889 | + err = vfsub_rmdir(d_inode(h_parent), &h_path); |
1facf9fc | 5890 | + if (unlikely(err)) { |
523b37e3 AM |
5891 | + AuIOErr("failed remove copied-up tmp file %pd(%d)\n", |
5892 | + wh_dentry, err); | |
1facf9fc | 5893 | + err = -EIO; |
5894 | + } | |
5895 | + au_dtime_revert(&dt); | |
5527c038 | 5896 | + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry); |
1facf9fc | 5897 | + |
4f0767ce | 5898 | +out_wh: |
1facf9fc | 5899 | + dput(wh_dentry); |
4f0767ce | 5900 | +out: |
1facf9fc | 5901 | + dput(parent); |
5902 | + return err; | |
5903 | +} | |
5904 | + | |
5905 | +struct au_cpup_wh_args { | |
5906 | + int *errp; | |
c2b27bf2 | 5907 | + struct au_cp_generic *cpg; |
1facf9fc | 5908 | + struct file *file; |
5909 | +}; | |
5910 | + | |
5911 | +static void au_call_cpup_wh(void *args) | |
5912 | +{ | |
5913 | + struct au_cpup_wh_args *a = args; | |
86dc4139 | 5914 | + |
c2b27bf2 AM |
5915 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5916 | + *a->errp = au_cpup_wh(a->cpg, a->file); | |
5917 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5918 | +} |
5919 | + | |
c2b27bf2 | 5920 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5921 | +{ |
5922 | + int err, wkq_err; | |
c2b27bf2 | 5923 | + aufs_bindex_t bdst; |
c1595e42 | 5924 | + struct dentry *dentry, *parent, *h_orph, *h_parent; |
86dc4139 | 5925 | + struct inode *dir, *h_dir, *h_tmpdir; |
1facf9fc | 5926 | + struct au_wbr *wbr; |
c2b27bf2 | 5927 | + struct au_pin wh_pin, *pin_orig; |
1facf9fc | 5928 | + |
c2b27bf2 AM |
5929 | + dentry = cpg->dentry; |
5930 | + bdst = cpg->bdst; | |
1facf9fc | 5931 | + parent = dget_parent(dentry); |
5527c038 | 5932 | + dir = d_inode(parent); |
1facf9fc | 5933 | + h_orph = NULL; |
5934 | + h_parent = NULL; | |
5935 | + h_dir = au_igrab(au_h_iptr(dir, bdst)); | |
5936 | + h_tmpdir = h_dir; | |
c2b27bf2 | 5937 | + pin_orig = NULL; |
1facf9fc | 5938 | + if (!h_dir->i_nlink) { |
5939 | + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr; | |
5940 | + h_orph = wbr->wbr_orph; | |
5941 | + | |
5942 | + h_parent = dget(au_h_dptr(parent, bdst)); | |
1facf9fc | 5943 | + au_set_h_dptr(parent, bdst, dget(h_orph)); |
5527c038 | 5944 | + h_tmpdir = d_inode(h_orph); |
1facf9fc | 5945 | + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0); |
5946 | + | |
febd17d6 | 5947 | + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3); |
4a4d8108 | 5948 | + /* todo: au_h_open_pre()? */ |
86dc4139 | 5949 | + |
c2b27bf2 | 5950 | + pin_orig = cpg->pin; |
86dc4139 | 5951 | + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT, |
c2b27bf2 AM |
5952 | + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED); |
5953 | + cpg->pin = &wh_pin; | |
1facf9fc | 5954 | + } |
5955 | + | |
53392da6 | 5956 | + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE) |
5527c038 | 5957 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 5958 | + err = au_cpup_wh(cpg, file); |
1facf9fc | 5959 | + else { |
5960 | + struct au_cpup_wh_args args = { | |
5961 | + .errp = &err, | |
c2b27bf2 AM |
5962 | + .cpg = cpg, |
5963 | + .file = file | |
1facf9fc | 5964 | + }; |
5965 | + wkq_err = au_wkq_wait(au_call_cpup_wh, &args); | |
5966 | + if (unlikely(wkq_err)) | |
5967 | + err = wkq_err; | |
5968 | + } | |
5969 | + | |
5970 | + if (h_orph) { | |
febd17d6 | 5971 | + inode_unlock(h_tmpdir); |
4a4d8108 | 5972 | + /* todo: au_h_open_post()? */ |
1facf9fc | 5973 | + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0); |
1facf9fc | 5974 | + au_set_h_dptr(parent, bdst, h_parent); |
c2b27bf2 AM |
5975 | + AuDebugOn(!pin_orig); |
5976 | + cpg->pin = pin_orig; | |
1facf9fc | 5977 | + } |
5978 | + iput(h_dir); | |
5979 | + dput(parent); | |
5980 | + | |
5981 | + return err; | |
5982 | +} | |
5983 | + | |
5984 | +/* ---------------------------------------------------------------------- */ | |
5985 | + | |
5986 | +/* | |
5987 | + * generic routine for both of copy-up and copy-down. | |
5988 | + */ | |
5989 | +/* cf. revalidate function in file.c */ | |
5990 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
5991 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5992 | + struct au_pin *pin, |
1facf9fc | 5993 | + struct dentry *h_parent, void *arg), |
5994 | + void *arg) | |
5995 | +{ | |
5996 | + int err; | |
5997 | + struct au_pin pin; | |
5527c038 | 5998 | + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry; |
1facf9fc | 5999 | + |
6000 | + err = 0; | |
6001 | + parent = dget_parent(dentry); | |
6002 | + if (IS_ROOT(parent)) | |
6003 | + goto out; | |
6004 | + | |
6005 | + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2, | |
6006 | + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE); | |
6007 | + | |
6008 | + /* do not use au_dpage */ | |
6009 | + real_parent = parent; | |
6010 | + while (1) { | |
6011 | + dput(parent); | |
6012 | + parent = dget_parent(dentry); | |
6013 | + h_parent = au_h_dptr(parent, bdst); | |
6014 | + if (h_parent) | |
6015 | + goto out; /* success */ | |
6016 | + | |
6017 | + /* find top dir which is necessary to cpup */ | |
6018 | + do { | |
6019 | + d = parent; | |
6020 | + dput(parent); | |
6021 | + parent = dget_parent(d); | |
6022 | + di_read_lock_parent3(parent, !AuLock_IR); | |
6023 | + h_parent = au_h_dptr(parent, bdst); | |
6024 | + di_read_unlock(parent, !AuLock_IR); | |
6025 | + } while (!h_parent); | |
6026 | + | |
6027 | + if (d != real_parent) | |
6028 | + di_write_lock_child3(d); | |
6029 | + | |
6030 | + /* somebody else might create while we were sleeping */ | |
5527c038 JR |
6031 | + h_dentry = au_h_dptr(d, bdst); |
6032 | + if (!h_dentry || d_is_negative(h_dentry)) { | |
6033 | + if (h_dentry) | |
5afbbe0d | 6034 | + au_update_dbtop(d); |
1facf9fc | 6035 | + |
6036 | + au_pin_set_dentry(&pin, d); | |
6037 | + err = au_do_pin(&pin); | |
6038 | + if (!err) { | |
86dc4139 | 6039 | + err = cp(d, bdst, &pin, h_parent, arg); |
1facf9fc | 6040 | + au_unpin(&pin); |
6041 | + } | |
6042 | + } | |
6043 | + | |
6044 | + if (d != real_parent) | |
6045 | + di_write_unlock(d); | |
6046 | + if (unlikely(err)) | |
6047 | + break; | |
6048 | + } | |
6049 | + | |
4f0767ce | 6050 | +out: |
1facf9fc | 6051 | + dput(parent); |
6052 | + return err; | |
6053 | +} | |
6054 | + | |
6055 | +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6056 | + struct au_pin *pin, |
2000de60 | 6057 | + struct dentry *h_parent __maybe_unused, |
1facf9fc | 6058 | + void *arg __maybe_unused) |
6059 | +{ | |
c2b27bf2 AM |
6060 | + struct au_cp_generic cpg = { |
6061 | + .dentry = dentry, | |
6062 | + .bdst = bdst, | |
6063 | + .bsrc = -1, | |
6064 | + .len = 0, | |
6065 | + .pin = pin, | |
6066 | + .flags = AuCpup_DTIME | |
6067 | + }; | |
6068 | + return au_sio_cpup_simple(&cpg); | |
1facf9fc | 6069 | +} |
6070 | + | |
6071 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
6072 | +{ | |
6073 | + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL); | |
6074 | +} | |
6075 | + | |
6076 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
6077 | +{ | |
6078 | + int err; | |
6079 | + struct dentry *parent; | |
6080 | + struct inode *dir; | |
6081 | + | |
6082 | + parent = dget_parent(dentry); | |
5527c038 | 6083 | + dir = d_inode(parent); |
1facf9fc | 6084 | + err = 0; |
6085 | + if (au_h_iptr(dir, bdst)) | |
6086 | + goto out; | |
6087 | + | |
6088 | + di_read_unlock(parent, AuLock_IR); | |
6089 | + di_write_lock_parent(parent); | |
6090 | + /* someone else might change our inode while we were sleeping */ | |
6091 | + if (!au_h_iptr(dir, bdst)) | |
6092 | + err = au_cpup_dirs(dentry, bdst); | |
6093 | + di_downgrade_lock(parent, AuLock_IR); | |
6094 | + | |
4f0767ce | 6095 | +out: |
1facf9fc | 6096 | + dput(parent); |
6097 | + return err; | |
6098 | +} | |
7f207e10 AM |
6099 | diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h |
6100 | --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 6101 | +++ linux/fs/aufs/cpup.h 2017-05-06 22:16:52.774886674 +0200 |
523b37e3 | 6102 | @@ -0,0 +1,94 @@ |
1facf9fc | 6103 | +/* |
a2654f78 | 6104 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6105 | + * |
6106 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6107 | + * it under the terms of the GNU General Public License as published by | |
6108 | + * the Free Software Foundation; either version 2 of the License, or | |
6109 | + * (at your option) any later version. | |
dece6358 AM |
6110 | + * |
6111 | + * This program is distributed in the hope that it will be useful, | |
6112 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6113 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6114 | + * GNU General Public License for more details. | |
6115 | + * | |
6116 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6117 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6118 | + */ |
6119 | + | |
6120 | +/* | |
6121 | + * copy-up/down functions | |
6122 | + */ | |
6123 | + | |
6124 | +#ifndef __AUFS_CPUP_H__ | |
6125 | +#define __AUFS_CPUP_H__ | |
6126 | + | |
6127 | +#ifdef __KERNEL__ | |
6128 | + | |
dece6358 | 6129 | +#include <linux/path.h> |
1facf9fc | 6130 | + |
dece6358 AM |
6131 | +struct inode; |
6132 | +struct file; | |
86dc4139 | 6133 | +struct au_pin; |
dece6358 | 6134 | + |
86dc4139 | 6135 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags); |
1facf9fc | 6136 | +void au_cpup_attr_timesizes(struct inode *inode); |
6137 | +void au_cpup_attr_nlink(struct inode *inode, int force); | |
6138 | +void au_cpup_attr_changeable(struct inode *inode); | |
6139 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode); | |
6140 | +void au_cpup_attr_all(struct inode *inode, int force); | |
6141 | + | |
6142 | +/* ---------------------------------------------------------------------- */ | |
6143 | + | |
c2b27bf2 AM |
6144 | +struct au_cp_generic { |
6145 | + struct dentry *dentry; | |
6146 | + aufs_bindex_t bdst, bsrc; | |
6147 | + loff_t len; | |
6148 | + struct au_pin *pin; | |
6149 | + unsigned int flags; | |
6150 | +}; | |
6151 | + | |
1facf9fc | 6152 | +/* cpup flags */ |
392086de AM |
6153 | +#define AuCpup_DTIME 1 /* do dtime_store/revert */ |
6154 | +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino, | |
6155 | + for link(2) */ | |
6156 | +#define AuCpup_RENAME (1 << 2) /* rename after cpup */ | |
6157 | +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in | |
6158 | + cpup */ | |
6159 | +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the | |
6160 | + existing entry */ | |
6161 | +#define AuCpup_RWDST (1 << 5) /* force write target even if | |
6162 | + the branch is marked as RO */ | |
c2b27bf2 | 6163 | + |
1facf9fc | 6164 | +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name) |
7f207e10 AM |
6165 | +#define au_fset_cpup(flags, name) \ |
6166 | + do { (flags) |= AuCpup_##name; } while (0) | |
6167 | +#define au_fclr_cpup(flags, name) \ | |
6168 | + do { (flags) &= ~AuCpup_##name; } while (0) | |
1facf9fc | 6169 | + |
6170 | +int au_copy_file(struct file *dst, struct file *src, loff_t len); | |
c2b27bf2 AM |
6171 | +int au_sio_cpup_simple(struct au_cp_generic *cpg); |
6172 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg); | |
6173 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file); | |
1facf9fc | 6174 | + |
6175 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
6176 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6177 | + struct au_pin *pin, |
1facf9fc | 6178 | + struct dentry *h_parent, void *arg), |
6179 | + void *arg); | |
6180 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
6181 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
6182 | + | |
6183 | +/* ---------------------------------------------------------------------- */ | |
6184 | + | |
6185 | +/* keep timestamps when copyup */ | |
6186 | +struct au_dtime { | |
6187 | + struct dentry *dt_dentry; | |
6188 | + struct path dt_h_path; | |
6189 | + struct timespec dt_atime, dt_mtime; | |
6190 | +}; | |
6191 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
6192 | + struct path *h_path); | |
6193 | +void au_dtime_revert(struct au_dtime *dt); | |
6194 | + | |
6195 | +#endif /* __KERNEL__ */ | |
6196 | +#endif /* __AUFS_CPUP_H__ */ | |
7f207e10 AM |
6197 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c |
6198 | --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 6199 | +++ linux/fs/aufs/dbgaufs.c 2017-05-06 22:16:52.774886674 +0200 |
e2f27e51 | 6200 | @@ -0,0 +1,438 @@ |
1facf9fc | 6201 | +/* |
a2654f78 | 6202 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6203 | + * |
6204 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6205 | + * it under the terms of the GNU General Public License as published by | |
6206 | + * the Free Software Foundation; either version 2 of the License, or | |
6207 | + * (at your option) any later version. | |
dece6358 AM |
6208 | + * |
6209 | + * This program is distributed in the hope that it will be useful, | |
6210 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6211 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6212 | + * GNU General Public License for more details. | |
6213 | + * | |
6214 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6215 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6216 | + */ |
6217 | + | |
6218 | +/* | |
6219 | + * debugfs interface | |
6220 | + */ | |
6221 | + | |
6222 | +#include <linux/debugfs.h> | |
6223 | +#include "aufs.h" | |
6224 | + | |
6225 | +#ifndef CONFIG_SYSFS | |
6226 | +#error DEBUG_FS depends upon SYSFS | |
6227 | +#endif | |
6228 | + | |
6229 | +static struct dentry *dbgaufs; | |
6230 | +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH; | |
6231 | + | |
6232 | +/* 20 is max digits length of ulong 64 */ | |
6233 | +struct dbgaufs_arg { | |
6234 | + int n; | |
6235 | + char a[20 * 4]; | |
6236 | +}; | |
6237 | + | |
6238 | +/* | |
6239 | + * common function for all XINO files | |
6240 | + */ | |
6241 | +static int dbgaufs_xi_release(struct inode *inode __maybe_unused, | |
6242 | + struct file *file) | |
6243 | +{ | |
f0c0a007 | 6244 | + au_delayed_kfree(file->private_data); |
1facf9fc | 6245 | + return 0; |
6246 | +} | |
6247 | + | |
6248 | +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt) | |
6249 | +{ | |
6250 | + int err; | |
6251 | + struct kstat st; | |
6252 | + struct dbgaufs_arg *p; | |
6253 | + | |
6254 | + err = -ENOMEM; | |
6255 | + p = kmalloc(sizeof(*p), GFP_NOFS); | |
6256 | + if (unlikely(!p)) | |
6257 | + goto out; | |
6258 | + | |
6259 | + err = 0; | |
6260 | + p->n = 0; | |
6261 | + file->private_data = p; | |
6262 | + if (!xf) | |
6263 | + goto out; | |
6264 | + | |
521ced18 | 6265 | + err = vfsub_getattr(&xf->f_path, &st); |
1facf9fc | 6266 | + if (!err) { |
6267 | + if (do_fcnt) | |
6268 | + p->n = snprintf | |
521ced18 | 6269 | + (p->a, sizeof(p->a), "%ld, %llux%u %lld\n", |
1facf9fc | 6270 | + (long)file_count(xf), st.blocks, st.blksize, |
6271 | + (long long)st.size); | |
6272 | + else | |
521ced18 | 6273 | + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n", |
1facf9fc | 6274 | + st.blocks, st.blksize, |
6275 | + (long long)st.size); | |
6276 | + AuDebugOn(p->n >= sizeof(p->a)); | |
6277 | + } else { | |
6278 | + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err); | |
6279 | + err = 0; | |
6280 | + } | |
6281 | + | |
4f0767ce | 6282 | +out: |
1facf9fc | 6283 | + return err; |
6284 | + | |
6285 | +} | |
6286 | + | |
6287 | +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf, | |
6288 | + size_t count, loff_t *ppos) | |
6289 | +{ | |
6290 | + struct dbgaufs_arg *p; | |
6291 | + | |
6292 | + p = file->private_data; | |
6293 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6294 | +} | |
6295 | + | |
6296 | +/* ---------------------------------------------------------------------- */ | |
6297 | + | |
86dc4139 AM |
6298 | +struct dbgaufs_plink_arg { |
6299 | + int n; | |
6300 | + char a[]; | |
6301 | +}; | |
6302 | + | |
6303 | +static int dbgaufs_plink_release(struct inode *inode __maybe_unused, | |
6304 | + struct file *file) | |
6305 | +{ | |
f0c0a007 | 6306 | + au_delayed_free_page((unsigned long)file->private_data); |
86dc4139 AM |
6307 | + return 0; |
6308 | +} | |
6309 | + | |
6310 | +static int dbgaufs_plink_open(struct inode *inode, struct file *file) | |
6311 | +{ | |
6312 | + int err, i, limit; | |
6313 | + unsigned long n, sum; | |
6314 | + struct dbgaufs_plink_arg *p; | |
6315 | + struct au_sbinfo *sbinfo; | |
6316 | + struct super_block *sb; | |
6317 | + struct au_sphlhead *sphl; | |
6318 | + | |
6319 | + err = -ENOMEM; | |
6320 | + p = (void *)get_zeroed_page(GFP_NOFS); | |
6321 | + if (unlikely(!p)) | |
6322 | + goto out; | |
6323 | + | |
6324 | + err = -EFBIG; | |
6325 | + sbinfo = inode->i_private; | |
6326 | + sb = sbinfo->si_sb; | |
6327 | + si_noflush_read_lock(sb); | |
6328 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
6329 | + limit = PAGE_SIZE - sizeof(p->n); | |
6330 | + | |
6331 | + /* the number of buckets */ | |
6332 | + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH); | |
6333 | + p->n += n; | |
6334 | + limit -= n; | |
6335 | + | |
6336 | + sum = 0; | |
6337 | + for (i = 0, sphl = sbinfo->si_plink; | |
6338 | + i < AuPlink_NHASH; | |
6339 | + i++, sphl++) { | |
6340 | + n = au_sphl_count(sphl); | |
6341 | + sum += n; | |
6342 | + | |
6343 | + n = snprintf(p->a + p->n, limit, "%lu ", n); | |
6344 | + p->n += n; | |
6345 | + limit -= n; | |
6346 | + if (unlikely(limit <= 0)) | |
6347 | + goto out_free; | |
6348 | + } | |
6349 | + p->a[p->n - 1] = '\n'; | |
6350 | + | |
6351 | + /* the sum of plinks */ | |
6352 | + n = snprintf(p->a + p->n, limit, "%lu\n", sum); | |
6353 | + p->n += n; | |
6354 | + limit -= n; | |
6355 | + if (unlikely(limit <= 0)) | |
6356 | + goto out_free; | |
6357 | + } else { | |
6358 | +#define str "1\n0\n0\n" | |
6359 | + p->n = sizeof(str) - 1; | |
6360 | + strcpy(p->a, str); | |
6361 | +#undef str | |
6362 | + } | |
6363 | + si_read_unlock(sb); | |
6364 | + | |
6365 | + err = 0; | |
6366 | + file->private_data = p; | |
6367 | + goto out; /* success */ | |
6368 | + | |
6369 | +out_free: | |
f0c0a007 | 6370 | + au_delayed_free_page((unsigned long)p); |
86dc4139 AM |
6371 | +out: |
6372 | + return err; | |
6373 | +} | |
6374 | + | |
6375 | +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf, | |
6376 | + size_t count, loff_t *ppos) | |
6377 | +{ | |
6378 | + struct dbgaufs_plink_arg *p; | |
6379 | + | |
6380 | + p = file->private_data; | |
6381 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6382 | +} | |
6383 | + | |
6384 | +static const struct file_operations dbgaufs_plink_fop = { | |
6385 | + .owner = THIS_MODULE, | |
6386 | + .open = dbgaufs_plink_open, | |
6387 | + .release = dbgaufs_plink_release, | |
6388 | + .read = dbgaufs_plink_read | |
6389 | +}; | |
6390 | + | |
6391 | +/* ---------------------------------------------------------------------- */ | |
6392 | + | |
1facf9fc | 6393 | +static int dbgaufs_xib_open(struct inode *inode, struct file *file) |
6394 | +{ | |
6395 | + int err; | |
6396 | + struct au_sbinfo *sbinfo; | |
6397 | + struct super_block *sb; | |
6398 | + | |
6399 | + sbinfo = inode->i_private; | |
6400 | + sb = sbinfo->si_sb; | |
6401 | + si_noflush_read_lock(sb); | |
6402 | + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0); | |
6403 | + si_read_unlock(sb); | |
6404 | + return err; | |
6405 | +} | |
6406 | + | |
6407 | +static const struct file_operations dbgaufs_xib_fop = { | |
4a4d8108 | 6408 | + .owner = THIS_MODULE, |
1facf9fc | 6409 | + .open = dbgaufs_xib_open, |
6410 | + .release = dbgaufs_xi_release, | |
6411 | + .read = dbgaufs_xi_read | |
6412 | +}; | |
6413 | + | |
6414 | +/* ---------------------------------------------------------------------- */ | |
6415 | + | |
6416 | +#define DbgaufsXi_PREFIX "xi" | |
6417 | + | |
6418 | +static int dbgaufs_xino_open(struct inode *inode, struct file *file) | |
6419 | +{ | |
6420 | + int err; | |
6421 | + long l; | |
6422 | + struct au_sbinfo *sbinfo; | |
6423 | + struct super_block *sb; | |
6424 | + struct file *xf; | |
6425 | + struct qstr *name; | |
6426 | + | |
6427 | + err = -ENOENT; | |
6428 | + xf = NULL; | |
2000de60 | 6429 | + name = &file->f_path.dentry->d_name; |
1facf9fc | 6430 | + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX) |
6431 | + || memcmp(name->name, DbgaufsXi_PREFIX, | |
6432 | + sizeof(DbgaufsXi_PREFIX) - 1))) | |
6433 | + goto out; | |
9dbd164d | 6434 | + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l); |
1facf9fc | 6435 | + if (unlikely(err)) |
6436 | + goto out; | |
6437 | + | |
6438 | + sbinfo = inode->i_private; | |
6439 | + sb = sbinfo->si_sb; | |
6440 | + si_noflush_read_lock(sb); | |
5afbbe0d | 6441 | + if (l <= au_sbbot(sb)) { |
1facf9fc | 6442 | + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file; |
6443 | + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1); | |
6444 | + } else | |
6445 | + err = -ENOENT; | |
6446 | + si_read_unlock(sb); | |
6447 | + | |
4f0767ce | 6448 | +out: |
1facf9fc | 6449 | + return err; |
6450 | +} | |
6451 | + | |
6452 | +static const struct file_operations dbgaufs_xino_fop = { | |
4a4d8108 | 6453 | + .owner = THIS_MODULE, |
1facf9fc | 6454 | + .open = dbgaufs_xino_open, |
6455 | + .release = dbgaufs_xi_release, | |
6456 | + .read = dbgaufs_xi_read | |
6457 | +}; | |
6458 | + | |
6459 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
6460 | +{ | |
5afbbe0d | 6461 | + aufs_bindex_t bbot; |
1facf9fc | 6462 | + struct au_branch *br; |
6463 | + struct au_xino_file *xi; | |
6464 | + | |
6465 | + if (!au_sbi(sb)->si_dbgaufs) | |
6466 | + return; | |
6467 | + | |
5afbbe0d AM |
6468 | + bbot = au_sbbot(sb); |
6469 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 6470 | + br = au_sbr(sb, bindex); |
6471 | + xi = &br->br_xino; | |
e2f27e51 AM |
6472 | + /* debugfs acquires the parent i_mutex */ |
6473 | + lockdep_off(); | |
c06a8ce3 | 6474 | + debugfs_remove(xi->xi_dbgaufs); |
e2f27e51 | 6475 | + lockdep_on(); |
c06a8ce3 | 6476 | + xi->xi_dbgaufs = NULL; |
1facf9fc | 6477 | + } |
6478 | +} | |
6479 | + | |
6480 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
6481 | +{ | |
6482 | + struct au_sbinfo *sbinfo; | |
6483 | + struct dentry *parent; | |
6484 | + struct au_branch *br; | |
6485 | + struct au_xino_file *xi; | |
5afbbe0d | 6486 | + aufs_bindex_t bbot; |
1facf9fc | 6487 | + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */ |
6488 | + | |
6489 | + sbinfo = au_sbi(sb); | |
6490 | + parent = sbinfo->si_dbgaufs; | |
6491 | + if (!parent) | |
6492 | + return; | |
6493 | + | |
5afbbe0d AM |
6494 | + bbot = au_sbbot(sb); |
6495 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 6496 | + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex); |
6497 | + br = au_sbr(sb, bindex); | |
6498 | + xi = &br->br_xino; | |
6499 | + AuDebugOn(xi->xi_dbgaufs); | |
f0c0a007 AM |
6500 | + /* debugfs acquires the parent i_mutex */ |
6501 | + lockdep_off(); | |
1facf9fc | 6502 | + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent, |
6503 | + sbinfo, &dbgaufs_xino_fop); | |
f0c0a007 | 6504 | + lockdep_on(); |
1facf9fc | 6505 | + /* ignore an error */ |
6506 | + if (unlikely(!xi->xi_dbgaufs)) | |
6507 | + AuWarn1("failed %s under debugfs\n", name); | |
6508 | + } | |
6509 | +} | |
6510 | + | |
6511 | +/* ---------------------------------------------------------------------- */ | |
6512 | + | |
6513 | +#ifdef CONFIG_AUFS_EXPORT | |
6514 | +static int dbgaufs_xigen_open(struct inode *inode, struct file *file) | |
6515 | +{ | |
6516 | + int err; | |
6517 | + struct au_sbinfo *sbinfo; | |
6518 | + struct super_block *sb; | |
6519 | + | |
6520 | + sbinfo = inode->i_private; | |
6521 | + sb = sbinfo->si_sb; | |
6522 | + si_noflush_read_lock(sb); | |
6523 | + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0); | |
6524 | + si_read_unlock(sb); | |
6525 | + return err; | |
6526 | +} | |
6527 | + | |
6528 | +static const struct file_operations dbgaufs_xigen_fop = { | |
4a4d8108 | 6529 | + .owner = THIS_MODULE, |
1facf9fc | 6530 | + .open = dbgaufs_xigen_open, |
6531 | + .release = dbgaufs_xi_release, | |
6532 | + .read = dbgaufs_xi_read | |
6533 | +}; | |
6534 | + | |
6535 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6536 | +{ | |
6537 | + int err; | |
6538 | + | |
dece6358 | 6539 | + /* |
c1595e42 | 6540 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6541 | + * so the tiny check for si_rwsem is unnecessary. |
6542 | + */ | |
6543 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6544 | + | |
1facf9fc | 6545 | + err = -EIO; |
6546 | + sbinfo->si_dbgaufs_xigen = debugfs_create_file | |
6547 | + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6548 | + &dbgaufs_xigen_fop); | |
6549 | + if (sbinfo->si_dbgaufs_xigen) | |
6550 | + err = 0; | |
6551 | + | |
6552 | + return err; | |
6553 | +} | |
6554 | +#else | |
6555 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6556 | +{ | |
6557 | + return 0; | |
6558 | +} | |
6559 | +#endif /* CONFIG_AUFS_EXPORT */ | |
6560 | + | |
6561 | +/* ---------------------------------------------------------------------- */ | |
6562 | + | |
6563 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo) | |
6564 | +{ | |
dece6358 | 6565 | + /* |
7e9cd9fe | 6566 | + * This function is a dynamic '__fin' function actually, |
dece6358 AM |
6567 | + * so the tiny check for si_rwsem is unnecessary. |
6568 | + */ | |
6569 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6570 | + | |
1facf9fc | 6571 | + debugfs_remove_recursive(sbinfo->si_dbgaufs); |
6572 | + sbinfo->si_dbgaufs = NULL; | |
6573 | + kobject_put(&sbinfo->si_kobj); | |
6574 | +} | |
6575 | + | |
6576 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo) | |
6577 | +{ | |
6578 | + int err; | |
6579 | + char name[SysaufsSiNameLen]; | |
6580 | + | |
dece6358 | 6581 | + /* |
c1595e42 | 6582 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6583 | + * so the tiny check for si_rwsem is unnecessary. |
6584 | + */ | |
6585 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6586 | + | |
1facf9fc | 6587 | + err = -ENOENT; |
6588 | + if (!dbgaufs) { | |
6589 | + AuErr1("/debug/aufs is uninitialized\n"); | |
6590 | + goto out; | |
6591 | + } | |
6592 | + | |
6593 | + err = -EIO; | |
6594 | + sysaufs_name(sbinfo, name); | |
6595 | + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs); | |
6596 | + if (unlikely(!sbinfo->si_dbgaufs)) | |
6597 | + goto out; | |
6598 | + kobject_get(&sbinfo->si_kobj); | |
6599 | + | |
6600 | + sbinfo->si_dbgaufs_xib = debugfs_create_file | |
6601 | + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6602 | + &dbgaufs_xib_fop); | |
6603 | + if (unlikely(!sbinfo->si_dbgaufs_xib)) | |
6604 | + goto out_dir; | |
6605 | + | |
86dc4139 AM |
6606 | + sbinfo->si_dbgaufs_plink = debugfs_create_file |
6607 | + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6608 | + &dbgaufs_plink_fop); | |
6609 | + if (unlikely(!sbinfo->si_dbgaufs_plink)) | |
6610 | + goto out_dir; | |
6611 | + | |
1facf9fc | 6612 | + err = dbgaufs_xigen_init(sbinfo); |
6613 | + if (!err) | |
6614 | + goto out; /* success */ | |
6615 | + | |
4f0767ce | 6616 | +out_dir: |
1facf9fc | 6617 | + dbgaufs_si_fin(sbinfo); |
4f0767ce | 6618 | +out: |
1facf9fc | 6619 | + return err; |
6620 | +} | |
6621 | + | |
6622 | +/* ---------------------------------------------------------------------- */ | |
6623 | + | |
6624 | +void dbgaufs_fin(void) | |
6625 | +{ | |
6626 | + debugfs_remove(dbgaufs); | |
6627 | +} | |
6628 | + | |
6629 | +int __init dbgaufs_init(void) | |
6630 | +{ | |
6631 | + int err; | |
6632 | + | |
6633 | + err = -EIO; | |
6634 | + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL); | |
6635 | + if (dbgaufs) | |
6636 | + err = 0; | |
6637 | + return err; | |
6638 | +} | |
7f207e10 AM |
6639 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h |
6640 | --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 6641 | +++ linux/fs/aufs/dbgaufs.h 2017-05-06 22:16:52.774886674 +0200 |
523b37e3 | 6642 | @@ -0,0 +1,48 @@ |
1facf9fc | 6643 | +/* |
a2654f78 | 6644 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6645 | + * |
6646 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6647 | + * it under the terms of the GNU General Public License as published by | |
6648 | + * the Free Software Foundation; either version 2 of the License, or | |
6649 | + * (at your option) any later version. | |
dece6358 AM |
6650 | + * |
6651 | + * This program is distributed in the hope that it will be useful, | |
6652 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6653 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6654 | + * GNU General Public License for more details. | |
6655 | + * | |
6656 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6657 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6658 | + */ |
6659 | + | |
6660 | +/* | |
6661 | + * debugfs interface | |
6662 | + */ | |
6663 | + | |
6664 | +#ifndef __DBGAUFS_H__ | |
6665 | +#define __DBGAUFS_H__ | |
6666 | + | |
6667 | +#ifdef __KERNEL__ | |
6668 | + | |
dece6358 | 6669 | +struct super_block; |
1facf9fc | 6670 | +struct au_sbinfo; |
dece6358 | 6671 | + |
1facf9fc | 6672 | +#ifdef CONFIG_DEBUG_FS |
6673 | +/* dbgaufs.c */ | |
6674 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
6675 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
6676 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo); | |
6677 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo); | |
6678 | +void dbgaufs_fin(void); | |
6679 | +int __init dbgaufs_init(void); | |
1facf9fc | 6680 | +#else |
4a4d8108 AM |
6681 | +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) |
6682 | +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
6683 | +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo) | |
6684 | +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo) | |
6685 | +AuStubVoid(dbgaufs_fin, void) | |
6686 | +AuStubInt0(__init dbgaufs_init, void) | |
1facf9fc | 6687 | +#endif /* CONFIG_DEBUG_FS */ |
6688 | + | |
6689 | +#endif /* __KERNEL__ */ | |
6690 | +#endif /* __DBGAUFS_H__ */ | |
7f207e10 AM |
6691 | diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c |
6692 | --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 6693 | +++ linux/fs/aufs/dcsub.c 2017-05-06 22:16:52.774886674 +0200 |
e2f27e51 | 6694 | @@ -0,0 +1,225 @@ |
1facf9fc | 6695 | +/* |
a2654f78 | 6696 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6697 | + * |
6698 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6699 | + * it under the terms of the GNU General Public License as published by | |
6700 | + * the Free Software Foundation; either version 2 of the License, or | |
6701 | + * (at your option) any later version. | |
dece6358 AM |
6702 | + * |
6703 | + * This program is distributed in the hope that it will be useful, | |
6704 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6705 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6706 | + * GNU General Public License for more details. | |
6707 | + * | |
6708 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6709 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6710 | + */ |
6711 | + | |
6712 | +/* | |
6713 | + * sub-routines for dentry cache | |
6714 | + */ | |
6715 | + | |
6716 | +#include "aufs.h" | |
6717 | + | |
6718 | +static void au_dpage_free(struct au_dpage *dpage) | |
6719 | +{ | |
6720 | + int i; | |
6721 | + struct dentry **p; | |
6722 | + | |
6723 | + p = dpage->dentries; | |
6724 | + for (i = 0; i < dpage->ndentry; i++) | |
6725 | + dput(*p++); | |
f0c0a007 | 6726 | + au_delayed_free_page((unsigned long)dpage->dentries); |
1facf9fc | 6727 | +} |
6728 | + | |
6729 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp) | |
6730 | +{ | |
6731 | + int err; | |
6732 | + void *p; | |
6733 | + | |
6734 | + err = -ENOMEM; | |
6735 | + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp); | |
6736 | + if (unlikely(!dpages->dpages)) | |
6737 | + goto out; | |
6738 | + | |
6739 | + p = (void *)__get_free_page(gfp); | |
6740 | + if (unlikely(!p)) | |
6741 | + goto out_dpages; | |
6742 | + | |
6743 | + dpages->dpages[0].ndentry = 0; | |
6744 | + dpages->dpages[0].dentries = p; | |
6745 | + dpages->ndpage = 1; | |
6746 | + return 0; /* success */ | |
6747 | + | |
4f0767ce | 6748 | +out_dpages: |
f0c0a007 | 6749 | + au_delayed_kfree(dpages->dpages); |
4f0767ce | 6750 | +out: |
1facf9fc | 6751 | + return err; |
6752 | +} | |
6753 | + | |
6754 | +void au_dpages_free(struct au_dcsub_pages *dpages) | |
6755 | +{ | |
6756 | + int i; | |
6757 | + struct au_dpage *p; | |
6758 | + | |
6759 | + p = dpages->dpages; | |
6760 | + for (i = 0; i < dpages->ndpage; i++) | |
6761 | + au_dpage_free(p++); | |
f0c0a007 | 6762 | + au_delayed_kfree(dpages->dpages); |
1facf9fc | 6763 | +} |
6764 | + | |
6765 | +static int au_dpages_append(struct au_dcsub_pages *dpages, | |
6766 | + struct dentry *dentry, gfp_t gfp) | |
6767 | +{ | |
6768 | + int err, sz; | |
6769 | + struct au_dpage *dpage; | |
6770 | + void *p; | |
6771 | + | |
6772 | + dpage = dpages->dpages + dpages->ndpage - 1; | |
6773 | + sz = PAGE_SIZE / sizeof(dentry); | |
6774 | + if (unlikely(dpage->ndentry >= sz)) { | |
6775 | + AuLabel(new dpage); | |
6776 | + err = -ENOMEM; | |
6777 | + sz = dpages->ndpage * sizeof(*dpages->dpages); | |
6778 | + p = au_kzrealloc(dpages->dpages, sz, | |
e2f27e51 AM |
6779 | + sz + sizeof(*dpages->dpages), gfp, |
6780 | + /*may_shrink*/0); | |
1facf9fc | 6781 | + if (unlikely(!p)) |
6782 | + goto out; | |
6783 | + | |
6784 | + dpages->dpages = p; | |
6785 | + dpage = dpages->dpages + dpages->ndpage; | |
6786 | + p = (void *)__get_free_page(gfp); | |
6787 | + if (unlikely(!p)) | |
6788 | + goto out; | |
6789 | + | |
6790 | + dpage->ndentry = 0; | |
6791 | + dpage->dentries = p; | |
6792 | + dpages->ndpage++; | |
6793 | + } | |
6794 | + | |
c1595e42 | 6795 | + AuDebugOn(au_dcount(dentry) <= 0); |
027c5e7a | 6796 | + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry); |
1facf9fc | 6797 | + return 0; /* success */ |
6798 | + | |
4f0767ce | 6799 | +out: |
1facf9fc | 6800 | + return err; |
6801 | +} | |
6802 | + | |
c1595e42 JR |
6803 | +/* todo: BAD approach */ |
6804 | +/* copied from linux/fs/dcache.c */ | |
6805 | +enum d_walk_ret { | |
6806 | + D_WALK_CONTINUE, | |
6807 | + D_WALK_QUIT, | |
6808 | + D_WALK_NORETRY, | |
6809 | + D_WALK_SKIP, | |
6810 | +}; | |
6811 | + | |
6812 | +extern void d_walk(struct dentry *parent, void *data, | |
6813 | + enum d_walk_ret (*enter)(void *, struct dentry *), | |
6814 | + void (*finish)(void *)); | |
6815 | + | |
6816 | +struct ac_dpages_arg { | |
1facf9fc | 6817 | + int err; |
c1595e42 JR |
6818 | + struct au_dcsub_pages *dpages; |
6819 | + struct super_block *sb; | |
6820 | + au_dpages_test test; | |
6821 | + void *arg; | |
6822 | +}; | |
1facf9fc | 6823 | + |
c1595e42 JR |
6824 | +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry) |
6825 | +{ | |
6826 | + enum d_walk_ret ret; | |
6827 | + struct ac_dpages_arg *arg = _arg; | |
1facf9fc | 6828 | + |
c1595e42 JR |
6829 | + ret = D_WALK_CONTINUE; |
6830 | + if (dentry->d_sb == arg->sb | |
6831 | + && !IS_ROOT(dentry) | |
6832 | + && au_dcount(dentry) > 0 | |
6833 | + && au_di(dentry) | |
6834 | + && (!arg->test || arg->test(dentry, arg->arg))) { | |
6835 | + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC); | |
6836 | + if (unlikely(arg->err)) | |
6837 | + ret = D_WALK_QUIT; | |
1facf9fc | 6838 | + } |
6839 | + | |
c1595e42 JR |
6840 | + return ret; |
6841 | +} | |
027c5e7a | 6842 | + |
c1595e42 JR |
6843 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, |
6844 | + au_dpages_test test, void *arg) | |
6845 | +{ | |
6846 | + struct ac_dpages_arg args = { | |
6847 | + .err = 0, | |
6848 | + .dpages = dpages, | |
6849 | + .sb = root->d_sb, | |
6850 | + .test = test, | |
6851 | + .arg = arg | |
6852 | + }; | |
027c5e7a | 6853 | + |
c1595e42 JR |
6854 | + d_walk(root, &args, au_call_dpages_append, NULL); |
6855 | + | |
6856 | + return args.err; | |
1facf9fc | 6857 | +} |
6858 | + | |
6859 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6860 | + int do_include, au_dpages_test test, void *arg) | |
6861 | +{ | |
6862 | + int err; | |
6863 | + | |
6864 | + err = 0; | |
027c5e7a AM |
6865 | + write_seqlock(&rename_lock); |
6866 | + spin_lock(&dentry->d_lock); | |
6867 | + if (do_include | |
c1595e42 | 6868 | + && au_dcount(dentry) > 0 |
027c5e7a | 6869 | + && (!test || test(dentry, arg))) |
1facf9fc | 6870 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6871 | + spin_unlock(&dentry->d_lock); |
6872 | + if (unlikely(err)) | |
6873 | + goto out; | |
6874 | + | |
6875 | + /* | |
523b37e3 | 6876 | + * RCU for vfsmount is unnecessary since this is a traverse in a single |
027c5e7a AM |
6877 | + * mount |
6878 | + */ | |
1facf9fc | 6879 | + while (!IS_ROOT(dentry)) { |
027c5e7a AM |
6880 | + dentry = dentry->d_parent; /* rename_lock is locked */ |
6881 | + spin_lock(&dentry->d_lock); | |
c1595e42 | 6882 | + if (au_dcount(dentry) > 0 |
027c5e7a | 6883 | + && (!test || test(dentry, arg))) |
1facf9fc | 6884 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6885 | + spin_unlock(&dentry->d_lock); |
6886 | + if (unlikely(err)) | |
6887 | + break; | |
1facf9fc | 6888 | + } |
6889 | + | |
4f0767ce | 6890 | +out: |
027c5e7a | 6891 | + write_sequnlock(&rename_lock); |
1facf9fc | 6892 | + return err; |
6893 | +} | |
6894 | + | |
027c5e7a AM |
6895 | +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg) |
6896 | +{ | |
6897 | + return au_di(dentry) && dentry->d_sb == arg; | |
6898 | +} | |
6899 | + | |
6900 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, | |
6901 | + struct dentry *dentry, int do_include) | |
6902 | +{ | |
6903 | + return au_dcsub_pages_rev(dpages, dentry, do_include, | |
6904 | + au_dcsub_dpages_aufs, dentry->d_sb); | |
6905 | +} | |
6906 | + | |
4a4d8108 | 6907 | +int au_test_subdir(struct dentry *d1, struct dentry *d2) |
1facf9fc | 6908 | +{ |
4a4d8108 AM |
6909 | + struct path path[2] = { |
6910 | + { | |
6911 | + .dentry = d1 | |
6912 | + }, | |
6913 | + { | |
6914 | + .dentry = d2 | |
6915 | + } | |
6916 | + }; | |
1facf9fc | 6917 | + |
4a4d8108 | 6918 | + return path_is_under(path + 0, path + 1); |
1facf9fc | 6919 | +} |
7f207e10 AM |
6920 | diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h |
6921 | --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 6922 | +++ linux/fs/aufs/dcsub.h 2017-05-06 22:16:52.778220093 +0200 |
5527c038 | 6923 | @@ -0,0 +1,136 @@ |
1facf9fc | 6924 | +/* |
a2654f78 | 6925 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6926 | + * |
6927 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6928 | + * it under the terms of the GNU General Public License as published by | |
6929 | + * the Free Software Foundation; either version 2 of the License, or | |
6930 | + * (at your option) any later version. | |
dece6358 AM |
6931 | + * |
6932 | + * This program is distributed in the hope that it will be useful, | |
6933 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6934 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6935 | + * GNU General Public License for more details. | |
6936 | + * | |
6937 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6938 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6939 | + */ |
6940 | + | |
6941 | +/* | |
6942 | + * sub-routines for dentry cache | |
6943 | + */ | |
6944 | + | |
6945 | +#ifndef __AUFS_DCSUB_H__ | |
6946 | +#define __AUFS_DCSUB_H__ | |
6947 | + | |
6948 | +#ifdef __KERNEL__ | |
6949 | + | |
7f207e10 | 6950 | +#include <linux/dcache.h> |
027c5e7a | 6951 | +#include <linux/fs.h> |
dece6358 | 6952 | + |
1facf9fc | 6953 | +struct au_dpage { |
6954 | + int ndentry; | |
6955 | + struct dentry **dentries; | |
6956 | +}; | |
6957 | + | |
6958 | +struct au_dcsub_pages { | |
6959 | + int ndpage; | |
6960 | + struct au_dpage *dpages; | |
6961 | +}; | |
6962 | + | |
6963 | +/* ---------------------------------------------------------------------- */ | |
6964 | + | |
7f207e10 | 6965 | +/* dcsub.c */ |
1facf9fc | 6966 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp); |
6967 | +void au_dpages_free(struct au_dcsub_pages *dpages); | |
6968 | +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg); | |
6969 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, | |
6970 | + au_dpages_test test, void *arg); | |
6971 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6972 | + int do_include, au_dpages_test test, void *arg); | |
027c5e7a AM |
6973 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, |
6974 | + struct dentry *dentry, int do_include); | |
4a4d8108 | 6975 | +int au_test_subdir(struct dentry *d1, struct dentry *d2); |
1facf9fc | 6976 | + |
7f207e10 AM |
6977 | +/* ---------------------------------------------------------------------- */ |
6978 | + | |
523b37e3 AM |
6979 | +/* |
6980 | + * todo: in linux-3.13, several similar (but faster) helpers are added to | |
6981 | + * include/linux/dcache.h. Try them (in the future). | |
6982 | + */ | |
6983 | + | |
027c5e7a AM |
6984 | +static inline int au_d_hashed_positive(struct dentry *d) |
6985 | +{ | |
6986 | + int err; | |
5527c038 | 6987 | + struct inode *inode = d_inode(d); |
076b876e | 6988 | + |
027c5e7a | 6989 | + err = 0; |
5527c038 JR |
6990 | + if (unlikely(d_unhashed(d) |
6991 | + || d_is_negative(d) | |
6992 | + || !inode->i_nlink)) | |
027c5e7a AM |
6993 | + err = -ENOENT; |
6994 | + return err; | |
6995 | +} | |
6996 | + | |
38d290e6 JR |
6997 | +static inline int au_d_linkable(struct dentry *d) |
6998 | +{ | |
6999 | + int err; | |
5527c038 | 7000 | + struct inode *inode = d_inode(d); |
076b876e | 7001 | + |
38d290e6 JR |
7002 | + err = au_d_hashed_positive(d); |
7003 | + if (err | |
5527c038 | 7004 | + && d_is_positive(d) |
38d290e6 JR |
7005 | + && (inode->i_state & I_LINKABLE)) |
7006 | + err = 0; | |
7007 | + return err; | |
7008 | +} | |
7009 | + | |
027c5e7a AM |
7010 | +static inline int au_d_alive(struct dentry *d) |
7011 | +{ | |
7012 | + int err; | |
7013 | + struct inode *inode; | |
076b876e | 7014 | + |
027c5e7a AM |
7015 | + err = 0; |
7016 | + if (!IS_ROOT(d)) | |
7017 | + err = au_d_hashed_positive(d); | |
7018 | + else { | |
5527c038 JR |
7019 | + inode = d_inode(d); |
7020 | + if (unlikely(d_unlinked(d) | |
7021 | + || d_is_negative(d) | |
7022 | + || !inode->i_nlink)) | |
027c5e7a AM |
7023 | + err = -ENOENT; |
7024 | + } | |
7025 | + return err; | |
7026 | +} | |
7027 | + | |
7028 | +static inline int au_alive_dir(struct dentry *d) | |
7f207e10 | 7029 | +{ |
027c5e7a | 7030 | + int err; |
076b876e | 7031 | + |
027c5e7a | 7032 | + err = au_d_alive(d); |
5527c038 | 7033 | + if (unlikely(err || IS_DEADDIR(d_inode(d)))) |
027c5e7a AM |
7034 | + err = -ENOENT; |
7035 | + return err; | |
7f207e10 AM |
7036 | +} |
7037 | + | |
38d290e6 JR |
7038 | +static inline int au_qstreq(struct qstr *a, struct qstr *b) |
7039 | +{ | |
7040 | + return a->len == b->len | |
7041 | + && !memcmp(a->name, b->name, a->len); | |
7042 | +} | |
7043 | + | |
7e9cd9fe AM |
7044 | +/* |
7045 | + * by the commit | |
7046 | + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without | |
7047 | + * taking d_lock | |
7048 | + * the type of d_lockref.count became int, but the inlined function d_count() | |
7049 | + * still returns unsigned int. | |
7050 | + * I don't know why. Maybe it is for every d_count() users? | |
7051 | + * Anyway au_dcount() lives on. | |
7052 | + */ | |
c1595e42 JR |
7053 | +static inline int au_dcount(struct dentry *d) |
7054 | +{ | |
7055 | + return (int)d_count(d); | |
7056 | +} | |
7057 | + | |
1facf9fc | 7058 | +#endif /* __KERNEL__ */ |
7059 | +#endif /* __AUFS_DCSUB_H__ */ | |
7f207e10 AM |
7060 | diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c |
7061 | --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 7062 | +++ linux/fs/aufs/debug.c 2017-05-06 22:16:52.778220093 +0200 |
f0c0a007 | 7063 | @@ -0,0 +1,440 @@ |
1facf9fc | 7064 | +/* |
a2654f78 | 7065 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 7066 | + * |
7067 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7068 | + * it under the terms of the GNU General Public License as published by | |
7069 | + * the Free Software Foundation; either version 2 of the License, or | |
7070 | + * (at your option) any later version. | |
dece6358 AM |
7071 | + * |
7072 | + * This program is distributed in the hope that it will be useful, | |
7073 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7074 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7075 | + * GNU General Public License for more details. | |
7076 | + * | |
7077 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7078 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7079 | + */ |
7080 | + | |
7081 | +/* | |
7082 | + * debug print functions | |
7083 | + */ | |
7084 | + | |
7085 | +#include "aufs.h" | |
7086 | + | |
392086de AM |
7087 | +/* Returns 0, or -errno. arg is in kp->arg. */ |
7088 | +static int param_atomic_t_set(const char *val, const struct kernel_param *kp) | |
7089 | +{ | |
7090 | + int err, n; | |
7091 | + | |
7092 | + err = kstrtoint(val, 0, &n); | |
7093 | + if (!err) { | |
7094 | + if (n > 0) | |
7095 | + au_debug_on(); | |
7096 | + else | |
7097 | + au_debug_off(); | |
7098 | + } | |
7099 | + return err; | |
7100 | +} | |
7101 | + | |
7102 | +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
7103 | +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp) | |
7104 | +{ | |
7105 | + atomic_t *a; | |
7106 | + | |
7107 | + a = kp->arg; | |
7108 | + return sprintf(buffer, "%d", atomic_read(a)); | |
7109 | +} | |
7110 | + | |
7111 | +static struct kernel_param_ops param_ops_atomic_t = { | |
7112 | + .set = param_atomic_t_set, | |
7113 | + .get = param_atomic_t_get | |
7114 | + /* void (*free)(void *arg) */ | |
7115 | +}; | |
7116 | + | |
7117 | +atomic_t aufs_debug = ATOMIC_INIT(0); | |
1facf9fc | 7118 | +MODULE_PARM_DESC(debug, "debug print"); |
392086de | 7119 | +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP); |
1facf9fc | 7120 | + |
c1595e42 | 7121 | +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */ |
1facf9fc | 7122 | +char *au_plevel = KERN_DEBUG; |
e49829fe JR |
7123 | +#define dpri(fmt, ...) do { \ |
7124 | + if ((au_plevel \ | |
7125 | + && strcmp(au_plevel, KERN_DEBUG)) \ | |
7126 | + || au_debug_test()) \ | |
7127 | + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \ | |
1facf9fc | 7128 | +} while (0) |
7129 | + | |
7130 | +/* ---------------------------------------------------------------------- */ | |
7131 | + | |
7132 | +void au_dpri_whlist(struct au_nhash *whlist) | |
7133 | +{ | |
7134 | + unsigned long ul, n; | |
7135 | + struct hlist_head *head; | |
c06a8ce3 | 7136 | + struct au_vdir_wh *pos; |
1facf9fc | 7137 | + |
7138 | + n = whlist->nh_num; | |
7139 | + head = whlist->nh_head; | |
7140 | + for (ul = 0; ul < n; ul++) { | |
c06a8ce3 | 7141 | + hlist_for_each_entry(pos, head, wh_hash) |
1facf9fc | 7142 | + dpri("b%d, %.*s, %d\n", |
c06a8ce3 AM |
7143 | + pos->wh_bindex, |
7144 | + pos->wh_str.len, pos->wh_str.name, | |
7145 | + pos->wh_str.len); | |
1facf9fc | 7146 | + head++; |
7147 | + } | |
7148 | +} | |
7149 | + | |
7150 | +void au_dpri_vdir(struct au_vdir *vdir) | |
7151 | +{ | |
7152 | + unsigned long ul; | |
7153 | + union au_vdir_deblk_p p; | |
7154 | + unsigned char *o; | |
7155 | + | |
7156 | + if (!vdir || IS_ERR(vdir)) { | |
7157 | + dpri("err %ld\n", PTR_ERR(vdir)); | |
7158 | + return; | |
7159 | + } | |
7160 | + | |
7161 | + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n", | |
7162 | + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk, | |
7163 | + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version); | |
7164 | + for (ul = 0; ul < vdir->vd_nblk; ul++) { | |
7165 | + p.deblk = vdir->vd_deblk[ul]; | |
7166 | + o = p.deblk; | |
7167 | + dpri("[%lu]: %p\n", ul, o); | |
7168 | + } | |
7169 | +} | |
7170 | + | |
53392da6 | 7171 | +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn, |
1facf9fc | 7172 | + struct dentry *wh) |
7173 | +{ | |
7174 | + char *n = NULL; | |
7175 | + int l = 0; | |
7176 | + | |
7177 | + if (!inode || IS_ERR(inode)) { | |
7178 | + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode)); | |
7179 | + return -1; | |
7180 | + } | |
7181 | + | |
c2b27bf2 | 7182 | + /* the type of i_blocks depends upon CONFIG_LBDAF */ |
1facf9fc | 7183 | + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long) |
7184 | + && sizeof(inode->i_blocks) != sizeof(u64)); | |
7185 | + if (wh) { | |
7186 | + n = (void *)wh->d_name.name; | |
7187 | + l = wh->d_name.len; | |
7188 | + } | |
7189 | + | |
53392da6 AM |
7190 | + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu," |
7191 | + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n", | |
7192 | + bindex, inode, | |
1facf9fc | 7193 | + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??", |
7194 | + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode, | |
7195 | + i_size_read(inode), (unsigned long long)inode->i_blocks, | |
53392da6 | 7196 | + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff, |
1facf9fc | 7197 | + inode->i_mapping ? inode->i_mapping->nrpages : 0, |
b752ccd1 AM |
7198 | + inode->i_state, inode->i_flags, inode->i_version, |
7199 | + inode->i_generation, | |
1facf9fc | 7200 | + l ? ", wh " : "", l, n); |
7201 | + return 0; | |
7202 | +} | |
7203 | + | |
7204 | +void au_dpri_inode(struct inode *inode) | |
7205 | +{ | |
7206 | + struct au_iinfo *iinfo; | |
5afbbe0d | 7207 | + struct au_hinode *hi; |
1facf9fc | 7208 | + aufs_bindex_t bindex; |
53392da6 | 7209 | + int err, hn; |
1facf9fc | 7210 | + |
53392da6 | 7211 | + err = do_pri_inode(-1, inode, -1, NULL); |
5afbbe0d | 7212 | + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode)) |
1facf9fc | 7213 | + return; |
7214 | + | |
7215 | + iinfo = au_ii(inode); | |
5afbbe0d AM |
7216 | + dpri("i-1: btop %d, bbot %d, gen %d\n", |
7217 | + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL)); | |
7218 | + if (iinfo->ii_btop < 0) | |
1facf9fc | 7219 | + return; |
53392da6 | 7220 | + hn = 0; |
5afbbe0d AM |
7221 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) { |
7222 | + hi = au_hinode(iinfo, bindex); | |
7223 | + hn = !!au_hn(hi); | |
7224 | + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry); | |
53392da6 | 7225 | + } |
1facf9fc | 7226 | +} |
7227 | + | |
2cbb1c4b JR |
7228 | +void au_dpri_dalias(struct inode *inode) |
7229 | +{ | |
7230 | + struct dentry *d; | |
7231 | + | |
7232 | + spin_lock(&inode->i_lock); | |
c1595e42 | 7233 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) |
2cbb1c4b JR |
7234 | + au_dpri_dentry(d); |
7235 | + spin_unlock(&inode->i_lock); | |
7236 | +} | |
7237 | + | |
1facf9fc | 7238 | +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry) |
7239 | +{ | |
7240 | + struct dentry *wh = NULL; | |
53392da6 | 7241 | + int hn; |
5afbbe0d | 7242 | + struct inode *inode; |
076b876e | 7243 | + struct au_iinfo *iinfo; |
5afbbe0d | 7244 | + struct au_hinode *hi; |
1facf9fc | 7245 | + |
7246 | + if (!dentry || IS_ERR(dentry)) { | |
7247 | + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry)); | |
7248 | + return -1; | |
7249 | + } | |
7250 | + /* do not call dget_parent() here */ | |
027c5e7a | 7251 | + /* note: access d_xxx without d_lock */ |
523b37e3 AM |
7252 | + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n", |
7253 | + bindex, dentry, dentry, | |
1facf9fc | 7254 | + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??", |
c1595e42 | 7255 | + au_dcount(dentry), dentry->d_flags, |
523b37e3 | 7256 | + d_unhashed(dentry) ? "un" : ""); |
53392da6 | 7257 | + hn = -1; |
5afbbe0d AM |
7258 | + inode = NULL; |
7259 | + if (d_is_positive(dentry)) | |
7260 | + inode = d_inode(dentry); | |
7261 | + if (inode | |
7262 | + && au_test_aufs(dentry->d_sb) | |
7263 | + && bindex >= 0 | |
7264 | + && !au_is_bad_inode(inode)) { | |
7265 | + iinfo = au_ii(inode); | |
7266 | + hi = au_hinode(iinfo, bindex); | |
7267 | + hn = !!au_hn(hi); | |
7268 | + wh = hi->hi_whdentry; | |
7269 | + } | |
7270 | + do_pri_inode(bindex, inode, hn, wh); | |
1facf9fc | 7271 | + return 0; |
7272 | +} | |
7273 | + | |
7274 | +void au_dpri_dentry(struct dentry *dentry) | |
7275 | +{ | |
7276 | + struct au_dinfo *dinfo; | |
7277 | + aufs_bindex_t bindex; | |
7278 | + int err; | |
7279 | + | |
7280 | + err = do_pri_dentry(-1, dentry); | |
7281 | + if (err || !au_test_aufs(dentry->d_sb)) | |
7282 | + return; | |
7283 | + | |
7284 | + dinfo = au_di(dentry); | |
7285 | + if (!dinfo) | |
7286 | + return; | |
5afbbe0d AM |
7287 | + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n", |
7288 | + dinfo->di_btop, dinfo->di_bbot, | |
38d290e6 JR |
7289 | + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry), |
7290 | + dinfo->di_tmpfile); | |
5afbbe0d | 7291 | + if (dinfo->di_btop < 0) |
1facf9fc | 7292 | + return; |
5afbbe0d AM |
7293 | + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++) |
7294 | + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry); | |
1facf9fc | 7295 | +} |
7296 | + | |
7297 | +static int do_pri_file(aufs_bindex_t bindex, struct file *file) | |
7298 | +{ | |
7299 | + char a[32]; | |
7300 | + | |
7301 | + if (!file || IS_ERR(file)) { | |
7302 | + dpri("f%d: err %ld\n", bindex, PTR_ERR(file)); | |
7303 | + return -1; | |
7304 | + } | |
7305 | + a[0] = 0; | |
7306 | + if (bindex < 0 | |
b912730e | 7307 | + && !IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7308 | + && au_test_aufs(file->f_path.dentry->d_sb) |
1facf9fc | 7309 | + && au_fi(file)) |
e49829fe | 7310 | + snprintf(a, sizeof(a), ", gen %d, mmapped %d", |
2cbb1c4b | 7311 | + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped)); |
b752ccd1 | 7312 | + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n", |
1facf9fc | 7313 | + bindex, file->f_mode, file->f_flags, (long)file_count(file), |
b752ccd1 | 7314 | + file->f_version, file->f_pos, a); |
b912730e | 7315 | + if (!IS_ERR_OR_NULL(file->f_path.dentry)) |
2000de60 | 7316 | + do_pri_dentry(bindex, file->f_path.dentry); |
1facf9fc | 7317 | + return 0; |
7318 | +} | |
7319 | + | |
7320 | +void au_dpri_file(struct file *file) | |
7321 | +{ | |
7322 | + struct au_finfo *finfo; | |
4a4d8108 AM |
7323 | + struct au_fidir *fidir; |
7324 | + struct au_hfile *hfile; | |
1facf9fc | 7325 | + aufs_bindex_t bindex; |
7326 | + int err; | |
7327 | + | |
7328 | + err = do_pri_file(-1, file); | |
2000de60 | 7329 | + if (err |
b912730e | 7330 | + || IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7331 | + || !au_test_aufs(file->f_path.dentry->d_sb)) |
1facf9fc | 7332 | + return; |
7333 | + | |
7334 | + finfo = au_fi(file); | |
7335 | + if (!finfo) | |
7336 | + return; | |
4a4d8108 | 7337 | + if (finfo->fi_btop < 0) |
1facf9fc | 7338 | + return; |
4a4d8108 AM |
7339 | + fidir = finfo->fi_hdir; |
7340 | + if (!fidir) | |
7341 | + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file); | |
7342 | + else | |
e49829fe JR |
7343 | + for (bindex = finfo->fi_btop; |
7344 | + bindex >= 0 && bindex <= fidir->fd_bbot; | |
4a4d8108 AM |
7345 | + bindex++) { |
7346 | + hfile = fidir->fd_hfile + bindex; | |
7347 | + do_pri_file(bindex, hfile ? hfile->hf_file : NULL); | |
7348 | + } | |
1facf9fc | 7349 | +} |
7350 | + | |
7351 | +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br) | |
7352 | +{ | |
7353 | + struct vfsmount *mnt; | |
7354 | + struct super_block *sb; | |
7355 | + | |
7356 | + if (!br || IS_ERR(br)) | |
7357 | + goto out; | |
86dc4139 | 7358 | + mnt = au_br_mnt(br); |
1facf9fc | 7359 | + if (!mnt || IS_ERR(mnt)) |
7360 | + goto out; | |
7361 | + sb = mnt->mnt_sb; | |
7362 | + if (!sb || IS_ERR(sb)) | |
7363 | + goto out; | |
7364 | + | |
5afbbe0d | 7365 | + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, " |
b752ccd1 | 7366 | + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, " |
1facf9fc | 7367 | + "xino %d\n", |
5afbbe0d | 7368 | + bindex, br->br_perm, br->br_id, au_br_count(br), |
1e00d052 | 7369 | + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev), |
b752ccd1 | 7370 | + sb->s_flags, sb->s_count, |
1facf9fc | 7371 | + atomic_read(&sb->s_active), !!br->br_xino.xi_file); |
7372 | + return 0; | |
7373 | + | |
4f0767ce | 7374 | +out: |
1facf9fc | 7375 | + dpri("s%d: err %ld\n", bindex, PTR_ERR(br)); |
7376 | + return -1; | |
7377 | +} | |
7378 | + | |
7379 | +void au_dpri_sb(struct super_block *sb) | |
7380 | +{ | |
7381 | + struct au_sbinfo *sbinfo; | |
7382 | + aufs_bindex_t bindex; | |
7383 | + int err; | |
7384 | + /* to reuduce stack size */ | |
7385 | + struct { | |
7386 | + struct vfsmount mnt; | |
7387 | + struct au_branch fake; | |
7388 | + } *a; | |
7389 | + | |
7390 | + /* this function can be called from magic sysrq */ | |
7391 | + a = kzalloc(sizeof(*a), GFP_ATOMIC); | |
7392 | + if (unlikely(!a)) { | |
7393 | + dpri("no memory\n"); | |
7394 | + return; | |
7395 | + } | |
7396 | + | |
7397 | + a->mnt.mnt_sb = sb; | |
86dc4139 | 7398 | + a->fake.br_path.mnt = &a->mnt; |
5afbbe0d | 7399 | + au_br_count_init(&a->fake); |
1facf9fc | 7400 | + err = do_pri_br(-1, &a->fake); |
5afbbe0d | 7401 | + au_br_count_fin(&a->fake); |
f0c0a007 | 7402 | + au_delayed_kfree(a); |
1facf9fc | 7403 | + dpri("dev 0x%x\n", sb->s_dev); |
7404 | + if (err || !au_test_aufs(sb)) | |
7405 | + return; | |
7406 | + | |
7407 | + sbinfo = au_sbi(sb); | |
7408 | + if (!sbinfo) | |
7409 | + return; | |
f0c0a007 AM |
7410 | + dpri("nw %d, gen %u, kobj %d\n", |
7411 | + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation, | |
521ced18 | 7412 | + kref_read(&sbinfo->si_kobj.kref)); |
5afbbe0d | 7413 | + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++) |
1facf9fc | 7414 | + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]); |
7415 | +} | |
7416 | + | |
7417 | +/* ---------------------------------------------------------------------- */ | |
7418 | + | |
027c5e7a AM |
7419 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line) |
7420 | +{ | |
5527c038 | 7421 | + struct inode *h_inode, *inode = d_inode(dentry); |
027c5e7a | 7422 | + struct dentry *h_dentry; |
5afbbe0d | 7423 | + aufs_bindex_t bindex, bbot, bi; |
027c5e7a AM |
7424 | + |
7425 | + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */) | |
7426 | + return; | |
7427 | + | |
5afbbe0d AM |
7428 | + bbot = au_dbbot(dentry); |
7429 | + bi = au_ibbot(inode); | |
7430 | + if (bi < bbot) | |
7431 | + bbot = bi; | |
7432 | + bindex = au_dbtop(dentry); | |
7433 | + bi = au_ibtop(inode); | |
027c5e7a AM |
7434 | + if (bi > bindex) |
7435 | + bindex = bi; | |
7436 | + | |
5afbbe0d | 7437 | + for (; bindex <= bbot; bindex++) { |
027c5e7a AM |
7438 | + h_dentry = au_h_dptr(dentry, bindex); |
7439 | + if (!h_dentry) | |
7440 | + continue; | |
7441 | + h_inode = au_h_iptr(inode, bindex); | |
5527c038 | 7442 | + if (unlikely(h_inode != d_inode(h_dentry))) { |
392086de | 7443 | + au_debug_on(); |
027c5e7a AM |
7444 | + AuDbg("b%d, %s:%d\n", bindex, func, line); |
7445 | + AuDbgDentry(dentry); | |
7446 | + AuDbgInode(inode); | |
392086de | 7447 | + au_debug_off(); |
027c5e7a AM |
7448 | + BUG(); |
7449 | + } | |
7450 | + } | |
7451 | +} | |
7452 | + | |
1facf9fc | 7453 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen) |
7454 | +{ | |
7455 | + int err, i, j; | |
7456 | + struct au_dcsub_pages dpages; | |
7457 | + struct au_dpage *dpage; | |
7458 | + struct dentry **dentries; | |
7459 | + | |
7460 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
7461 | + AuDebugOn(err); | |
027c5e7a | 7462 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1); |
1facf9fc | 7463 | + AuDebugOn(err); |
7464 | + for (i = dpages.ndpage - 1; !err && i >= 0; i--) { | |
7465 | + dpage = dpages.dpages + i; | |
7466 | + dentries = dpage->dentries; | |
7467 | + for (j = dpage->ndentry - 1; !err && j >= 0; j--) | |
027c5e7a | 7468 | + AuDebugOn(au_digen_test(dentries[j], sigen)); |
1facf9fc | 7469 | + } |
7470 | + au_dpages_free(&dpages); | |
7471 | +} | |
7472 | + | |
1facf9fc | 7473 | +void au_dbg_verify_kthread(void) |
7474 | +{ | |
53392da6 | 7475 | + if (au_wkq_test()) { |
1facf9fc | 7476 | + au_dbg_blocked(); |
1e00d052 AM |
7477 | + /* |
7478 | + * It may be recursive, but udba=notify between two aufs mounts, | |
7479 | + * where a single ro branch is shared, is not a problem. | |
7480 | + */ | |
7481 | + /* WARN_ON(1); */ | |
1facf9fc | 7482 | + } |
7483 | +} | |
7484 | + | |
7485 | +/* ---------------------------------------------------------------------- */ | |
7486 | + | |
1facf9fc | 7487 | +int __init au_debug_init(void) |
7488 | +{ | |
7489 | + aufs_bindex_t bindex; | |
7490 | + struct au_vdir_destr destr; | |
7491 | + | |
7492 | + bindex = -1; | |
7493 | + AuDebugOn(bindex >= 0); | |
7494 | + | |
7495 | + destr.len = -1; | |
7496 | + AuDebugOn(destr.len < NAME_MAX); | |
7497 | + | |
7498 | +#ifdef CONFIG_4KSTACKS | |
0c3ec466 | 7499 | + pr_warn("CONFIG_4KSTACKS is defined.\n"); |
1facf9fc | 7500 | +#endif |
7501 | + | |
1facf9fc | 7502 | + return 0; |
7503 | +} | |
7f207e10 AM |
7504 | diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h |
7505 | --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 7506 | +++ linux/fs/aufs/debug.h 2017-05-06 22:16:52.778220093 +0200 |
5527c038 | 7507 | @@ -0,0 +1,225 @@ |
1facf9fc | 7508 | +/* |
a2654f78 | 7509 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 7510 | + * |
7511 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7512 | + * it under the terms of the GNU General Public License as published by | |
7513 | + * the Free Software Foundation; either version 2 of the License, or | |
7514 | + * (at your option) any later version. | |
dece6358 AM |
7515 | + * |
7516 | + * This program is distributed in the hope that it will be useful, | |
7517 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7518 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7519 | + * GNU General Public License for more details. | |
7520 | + * | |
7521 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7522 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7523 | + */ |
7524 | + | |
7525 | +/* | |
7526 | + * debug print functions | |
7527 | + */ | |
7528 | + | |
7529 | +#ifndef __AUFS_DEBUG_H__ | |
7530 | +#define __AUFS_DEBUG_H__ | |
7531 | + | |
7532 | +#ifdef __KERNEL__ | |
7533 | + | |
392086de | 7534 | +#include <linux/atomic.h> |
4a4d8108 AM |
7535 | +#include <linux/module.h> |
7536 | +#include <linux/kallsyms.h> | |
1facf9fc | 7537 | +#include <linux/sysrq.h> |
4a4d8108 | 7538 | + |
1facf9fc | 7539 | +#ifdef CONFIG_AUFS_DEBUG |
7540 | +#define AuDebugOn(a) BUG_ON(a) | |
7541 | + | |
7542 | +/* module parameter */ | |
392086de AM |
7543 | +extern atomic_t aufs_debug; |
7544 | +static inline void au_debug_on(void) | |
1facf9fc | 7545 | +{ |
392086de AM |
7546 | + atomic_inc(&aufs_debug); |
7547 | +} | |
7548 | +static inline void au_debug_off(void) | |
7549 | +{ | |
7550 | + atomic_dec_if_positive(&aufs_debug); | |
1facf9fc | 7551 | +} |
7552 | + | |
7553 | +static inline int au_debug_test(void) | |
7554 | +{ | |
392086de | 7555 | + return atomic_read(&aufs_debug) > 0; |
1facf9fc | 7556 | +} |
7557 | +#else | |
7558 | +#define AuDebugOn(a) do {} while (0) | |
392086de AM |
7559 | +AuStubVoid(au_debug_on, void) |
7560 | +AuStubVoid(au_debug_off, void) | |
4a4d8108 | 7561 | +AuStubInt0(au_debug_test, void) |
1facf9fc | 7562 | +#endif /* CONFIG_AUFS_DEBUG */ |
7563 | + | |
392086de AM |
7564 | +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t) |
7565 | + | |
1facf9fc | 7566 | +/* ---------------------------------------------------------------------- */ |
7567 | + | |
7568 | +/* debug print */ | |
7569 | + | |
4a4d8108 | 7570 | +#define AuDbg(fmt, ...) do { \ |
1facf9fc | 7571 | + if (au_debug_test()) \ |
4a4d8108 | 7572 | + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \ |
1facf9fc | 7573 | +} while (0) |
4a4d8108 AM |
7574 | +#define AuLabel(l) AuDbg(#l "\n") |
7575 | +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__) | |
7576 | +#define AuWarn1(fmt, ...) do { \ | |
1facf9fc | 7577 | + static unsigned char _c; \ |
7578 | + if (!_c++) \ | |
0c3ec466 | 7579 | + pr_warn(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7580 | +} while (0) |
7581 | + | |
4a4d8108 | 7582 | +#define AuErr1(fmt, ...) do { \ |
1facf9fc | 7583 | + static unsigned char _c; \ |
7584 | + if (!_c++) \ | |
4a4d8108 | 7585 | + pr_err(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7586 | +} while (0) |
7587 | + | |
4a4d8108 | 7588 | +#define AuIOErr1(fmt, ...) do { \ |
1facf9fc | 7589 | + static unsigned char _c; \ |
7590 | + if (!_c++) \ | |
4a4d8108 | 7591 | + AuIOErr(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7592 | +} while (0) |
7593 | + | |
7594 | +#define AuUnsupportMsg "This operation is not supported." \ | |
7595 | + " Please report this application to aufs-users ML." | |
4a4d8108 AM |
7596 | +#define AuUnsupport(fmt, ...) do { \ |
7597 | + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \ | |
1facf9fc | 7598 | + dump_stack(); \ |
7599 | +} while (0) | |
7600 | + | |
7601 | +#define AuTraceErr(e) do { \ | |
7602 | + if (unlikely((e) < 0)) \ | |
7603 | + AuDbg("err %d\n", (int)(e)); \ | |
7604 | +} while (0) | |
7605 | + | |
7606 | +#define AuTraceErrPtr(p) do { \ | |
7607 | + if (IS_ERR(p)) \ | |
7608 | + AuDbg("err %ld\n", PTR_ERR(p)); \ | |
7609 | +} while (0) | |
7610 | + | |
7611 | +/* dirty macros for debug print, use with "%.*s" and caution */ | |
7612 | +#define AuLNPair(qstr) (qstr)->len, (qstr)->name | |
1facf9fc | 7613 | + |
7614 | +/* ---------------------------------------------------------------------- */ | |
7615 | + | |
dece6358 | 7616 | +struct dentry; |
1facf9fc | 7617 | +#ifdef CONFIG_AUFS_DEBUG |
c1595e42 | 7618 | +extern struct mutex au_dbg_mtx; |
1facf9fc | 7619 | +extern char *au_plevel; |
7620 | +struct au_nhash; | |
7621 | +void au_dpri_whlist(struct au_nhash *whlist); | |
7622 | +struct au_vdir; | |
7623 | +void au_dpri_vdir(struct au_vdir *vdir); | |
dece6358 | 7624 | +struct inode; |
1facf9fc | 7625 | +void au_dpri_inode(struct inode *inode); |
2cbb1c4b | 7626 | +void au_dpri_dalias(struct inode *inode); |
1facf9fc | 7627 | +void au_dpri_dentry(struct dentry *dentry); |
dece6358 | 7628 | +struct file; |
1facf9fc | 7629 | +void au_dpri_file(struct file *filp); |
dece6358 | 7630 | +struct super_block; |
1facf9fc | 7631 | +void au_dpri_sb(struct super_block *sb); |
7632 | + | |
027c5e7a AM |
7633 | +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__) |
7634 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line); | |
1facf9fc | 7635 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen); |
1facf9fc | 7636 | +void au_dbg_verify_kthread(void); |
7637 | + | |
7638 | +int __init au_debug_init(void); | |
7e9cd9fe | 7639 | + |
1facf9fc | 7640 | +#define AuDbgWhlist(w) do { \ |
c1595e42 | 7641 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7642 | + AuDbg(#w "\n"); \ |
7643 | + au_dpri_whlist(w); \ | |
c1595e42 | 7644 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7645 | +} while (0) |
7646 | + | |
7647 | +#define AuDbgVdir(v) do { \ | |
c1595e42 | 7648 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7649 | + AuDbg(#v "\n"); \ |
7650 | + au_dpri_vdir(v); \ | |
c1595e42 | 7651 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7652 | +} while (0) |
7653 | + | |
7654 | +#define AuDbgInode(i) do { \ | |
c1595e42 | 7655 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7656 | + AuDbg(#i "\n"); \ |
7657 | + au_dpri_inode(i); \ | |
c1595e42 | 7658 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7659 | +} while (0) |
7660 | + | |
2cbb1c4b | 7661 | +#define AuDbgDAlias(i) do { \ |
c1595e42 | 7662 | + mutex_lock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7663 | + AuDbg(#i "\n"); \ |
7664 | + au_dpri_dalias(i); \ | |
c1595e42 | 7665 | + mutex_unlock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7666 | +} while (0) |
7667 | + | |
1facf9fc | 7668 | +#define AuDbgDentry(d) do { \ |
c1595e42 | 7669 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7670 | + AuDbg(#d "\n"); \ |
7671 | + au_dpri_dentry(d); \ | |
c1595e42 | 7672 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7673 | +} while (0) |
7674 | + | |
7675 | +#define AuDbgFile(f) do { \ | |
c1595e42 | 7676 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7677 | + AuDbg(#f "\n"); \ |
7678 | + au_dpri_file(f); \ | |
c1595e42 | 7679 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7680 | +} while (0) |
7681 | + | |
7682 | +#define AuDbgSb(sb) do { \ | |
c1595e42 | 7683 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7684 | + AuDbg(#sb "\n"); \ |
7685 | + au_dpri_sb(sb); \ | |
c1595e42 | 7686 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7687 | +} while (0) |
7688 | + | |
4a4d8108 AM |
7689 | +#define AuDbgSym(addr) do { \ |
7690 | + char sym[KSYM_SYMBOL_LEN]; \ | |
7691 | + sprint_symbol(sym, (unsigned long)addr); \ | |
7692 | + AuDbg("%s\n", sym); \ | |
7693 | +} while (0) | |
1facf9fc | 7694 | +#else |
027c5e7a | 7695 | +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry) |
4a4d8108 AM |
7696 | +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen) |
7697 | +AuStubVoid(au_dbg_verify_kthread, void) | |
7698 | +AuStubInt0(__init au_debug_init, void) | |
1facf9fc | 7699 | + |
1facf9fc | 7700 | +#define AuDbgWhlist(w) do {} while (0) |
7701 | +#define AuDbgVdir(v) do {} while (0) | |
7702 | +#define AuDbgInode(i) do {} while (0) | |
2cbb1c4b | 7703 | +#define AuDbgDAlias(i) do {} while (0) |
1facf9fc | 7704 | +#define AuDbgDentry(d) do {} while (0) |
7705 | +#define AuDbgFile(f) do {} while (0) | |
7706 | +#define AuDbgSb(sb) do {} while (0) | |
4a4d8108 | 7707 | +#define AuDbgSym(addr) do {} while (0) |
1facf9fc | 7708 | +#endif /* CONFIG_AUFS_DEBUG */ |
7709 | + | |
7710 | +/* ---------------------------------------------------------------------- */ | |
7711 | + | |
7712 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
7713 | +int __init au_sysrq_init(void); | |
7714 | +void au_sysrq_fin(void); | |
7715 | + | |
7716 | +#ifdef CONFIG_HW_CONSOLE | |
7717 | +#define au_dbg_blocked() do { \ | |
7718 | + WARN_ON(1); \ | |
0c5527e5 | 7719 | + handle_sysrq('w'); \ |
1facf9fc | 7720 | +} while (0) |
7721 | +#else | |
4a4d8108 | 7722 | +AuStubVoid(au_dbg_blocked, void) |
1facf9fc | 7723 | +#endif |
7724 | + | |
7725 | +#else | |
4a4d8108 AM |
7726 | +AuStubInt0(__init au_sysrq_init, void) |
7727 | +AuStubVoid(au_sysrq_fin, void) | |
7728 | +AuStubVoid(au_dbg_blocked, void) | |
1facf9fc | 7729 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ |
7730 | + | |
7731 | +#endif /* __KERNEL__ */ | |
7732 | +#endif /* __AUFS_DEBUG_H__ */ | |
7f207e10 AM |
7733 | diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c |
7734 | --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 7735 | +++ linux/fs/aufs/dentry.c 2017-05-06 22:16:52.778220093 +0200 |
e2f27e51 | 7736 | @@ -0,0 +1,1130 @@ |
1facf9fc | 7737 | +/* |
a2654f78 | 7738 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 7739 | + * |
7740 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7741 | + * it under the terms of the GNU General Public License as published by | |
7742 | + * the Free Software Foundation; either version 2 of the License, or | |
7743 | + * (at your option) any later version. | |
dece6358 AM |
7744 | + * |
7745 | + * This program is distributed in the hope that it will be useful, | |
7746 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7747 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7748 | + * GNU General Public License for more details. | |
7749 | + * | |
7750 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7751 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7752 | + */ |
7753 | + | |
7754 | +/* | |
7755 | + * lookup and dentry operations | |
7756 | + */ | |
7757 | + | |
dece6358 | 7758 | +#include <linux/namei.h> |
1facf9fc | 7759 | +#include "aufs.h" |
7760 | + | |
1facf9fc | 7761 | +struct au_do_lookup_args { |
7762 | + unsigned int flags; | |
7763 | + mode_t type; | |
1facf9fc | 7764 | +}; |
7765 | + | |
7766 | +/* | |
7767 | + * returns positive/negative dentry, NULL or an error. | |
7768 | + * NULL means whiteout-ed or not-found. | |
7769 | + */ | |
7770 | +static struct dentry* | |
7771 | +au_do_lookup(struct dentry *h_parent, struct dentry *dentry, | |
7772 | + aufs_bindex_t bindex, struct qstr *wh_name, | |
7773 | + struct au_do_lookup_args *args) | |
7774 | +{ | |
7775 | + struct dentry *h_dentry; | |
2000de60 | 7776 | + struct inode *h_inode; |
1facf9fc | 7777 | + struct au_branch *br; |
7778 | + int wh_found, opq; | |
7779 | + unsigned char wh_able; | |
7780 | + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG); | |
076b876e AM |
7781 | + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags, |
7782 | + IGNORE_PERM); | |
1facf9fc | 7783 | + |
1facf9fc | 7784 | + wh_found = 0; |
7785 | + br = au_sbr(dentry->d_sb, bindex); | |
7786 | + wh_able = !!au_br_whable(br->br_perm); | |
7787 | + if (wh_able) | |
e2f27e51 | 7788 | + wh_found = au_wh_test(h_parent, wh_name, ignore_perm); |
1facf9fc | 7789 | + h_dentry = ERR_PTR(wh_found); |
7790 | + if (!wh_found) | |
7791 | + goto real_lookup; | |
7792 | + if (unlikely(wh_found < 0)) | |
7793 | + goto out; | |
7794 | + | |
7795 | + /* We found a whiteout */ | |
5afbbe0d | 7796 | + /* au_set_dbbot(dentry, bindex); */ |
1facf9fc | 7797 | + au_set_dbwh(dentry, bindex); |
7798 | + if (!allow_neg) | |
7799 | + return NULL; /* success */ | |
7800 | + | |
4f0767ce | 7801 | +real_lookup: |
076b876e AM |
7802 | + if (!ignore_perm) |
7803 | + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
7804 | + else | |
7805 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); | |
2000de60 JR |
7806 | + if (IS_ERR(h_dentry)) { |
7807 | + if (PTR_ERR(h_dentry) == -ENAMETOOLONG | |
7808 | + && !allow_neg) | |
7809 | + h_dentry = NULL; | |
1facf9fc | 7810 | + goto out; |
2000de60 | 7811 | + } |
1facf9fc | 7812 | + |
5527c038 JR |
7813 | + h_inode = d_inode(h_dentry); |
7814 | + if (d_is_negative(h_dentry)) { | |
1facf9fc | 7815 | + if (!allow_neg) |
7816 | + goto out_neg; | |
7817 | + } else if (wh_found | |
7818 | + || (args->type && args->type != (h_inode->i_mode & S_IFMT))) | |
7819 | + goto out_neg; | |
7820 | + | |
5afbbe0d AM |
7821 | + if (au_dbbot(dentry) <= bindex) |
7822 | + au_set_dbbot(dentry, bindex); | |
7823 | + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry)) | |
7824 | + au_set_dbtop(dentry, bindex); | |
1facf9fc | 7825 | + au_set_h_dptr(dentry, bindex, h_dentry); |
7826 | + | |
2000de60 JR |
7827 | + if (!d_is_dir(h_dentry) |
7828 | + || !wh_able | |
5527c038 | 7829 | + || (d_really_is_positive(dentry) && !d_is_dir(dentry))) |
1facf9fc | 7830 | + goto out; /* success */ |
7831 | + | |
febd17d6 | 7832 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
076b876e | 7833 | + opq = au_diropq_test(h_dentry); |
febd17d6 | 7834 | + inode_unlock(h_inode); |
1facf9fc | 7835 | + if (opq > 0) |
7836 | + au_set_dbdiropq(dentry, bindex); | |
7837 | + else if (unlikely(opq < 0)) { | |
7838 | + au_set_h_dptr(dentry, bindex, NULL); | |
7839 | + h_dentry = ERR_PTR(opq); | |
7840 | + } | |
7841 | + goto out; | |
7842 | + | |
4f0767ce | 7843 | +out_neg: |
1facf9fc | 7844 | + dput(h_dentry); |
7845 | + h_dentry = NULL; | |
4f0767ce | 7846 | +out: |
1facf9fc | 7847 | + return h_dentry; |
7848 | +} | |
7849 | + | |
dece6358 AM |
7850 | +static int au_test_shwh(struct super_block *sb, const struct qstr *name) |
7851 | +{ | |
7852 | + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH) | |
7853 | + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))) | |
7854 | + return -EPERM; | |
7855 | + return 0; | |
7856 | +} | |
7857 | + | |
1facf9fc | 7858 | +/* |
7859 | + * returns the number of lower positive dentries, | |
7860 | + * otherwise an error. | |
7861 | + * can be called at unlinking with @type is zero. | |
7862 | + */ | |
5afbbe0d AM |
7863 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop, |
7864 | + unsigned int flags) | |
1facf9fc | 7865 | +{ |
7866 | + int npositive, err; | |
7867 | + aufs_bindex_t bindex, btail, bdiropq; | |
076b876e | 7868 | + unsigned char isdir, dirperm1; |
1facf9fc | 7869 | + struct qstr whname; |
7870 | + struct au_do_lookup_args args = { | |
5afbbe0d | 7871 | + .flags = flags |
1facf9fc | 7872 | + }; |
7873 | + const struct qstr *name = &dentry->d_name; | |
7874 | + struct dentry *parent; | |
076b876e | 7875 | + struct super_block *sb; |
1facf9fc | 7876 | + |
076b876e AM |
7877 | + sb = dentry->d_sb; |
7878 | + err = au_test_shwh(sb, name); | |
dece6358 | 7879 | + if (unlikely(err)) |
1facf9fc | 7880 | + goto out; |
7881 | + | |
7882 | + err = au_wh_name_alloc(&whname, name); | |
7883 | + if (unlikely(err)) | |
7884 | + goto out; | |
7885 | + | |
2000de60 | 7886 | + isdir = !!d_is_dir(dentry); |
076b876e | 7887 | + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1); |
1facf9fc | 7888 | + |
7889 | + npositive = 0; | |
4a4d8108 | 7890 | + parent = dget_parent(dentry); |
1facf9fc | 7891 | + btail = au_dbtaildir(parent); |
5afbbe0d | 7892 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 7893 | + struct dentry *h_parent, *h_dentry; |
7894 | + struct inode *h_inode, *h_dir; | |
7895 | + | |
7896 | + h_dentry = au_h_dptr(dentry, bindex); | |
7897 | + if (h_dentry) { | |
5527c038 | 7898 | + if (d_is_positive(h_dentry)) |
1facf9fc | 7899 | + npositive++; |
5afbbe0d | 7900 | + break; |
1facf9fc | 7901 | + } |
7902 | + h_parent = au_h_dptr(parent, bindex); | |
2000de60 | 7903 | + if (!h_parent || !d_is_dir(h_parent)) |
1facf9fc | 7904 | + continue; |
7905 | + | |
5527c038 | 7906 | + h_dir = d_inode(h_parent); |
febd17d6 | 7907 | + inode_lock_nested(h_dir, AuLsc_I_PARENT); |
1facf9fc | 7908 | + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname, |
7909 | + &args); | |
febd17d6 | 7910 | + inode_unlock(h_dir); |
1facf9fc | 7911 | + err = PTR_ERR(h_dentry); |
7912 | + if (IS_ERR(h_dentry)) | |
4a4d8108 | 7913 | + goto out_parent; |
2000de60 JR |
7914 | + if (h_dentry) |
7915 | + au_fclr_lkup(args.flags, ALLOW_NEG); | |
076b876e AM |
7916 | + if (dirperm1) |
7917 | + au_fset_lkup(args.flags, IGNORE_PERM); | |
1facf9fc | 7918 | + |
79b8bda9 | 7919 | + if (au_dbwh(dentry) == bindex) |
1facf9fc | 7920 | + break; |
7921 | + if (!h_dentry) | |
7922 | + continue; | |
5527c038 | 7923 | + if (d_is_negative(h_dentry)) |
1facf9fc | 7924 | + continue; |
5527c038 | 7925 | + h_inode = d_inode(h_dentry); |
1facf9fc | 7926 | + npositive++; |
7927 | + if (!args.type) | |
7928 | + args.type = h_inode->i_mode & S_IFMT; | |
7929 | + if (args.type != S_IFDIR) | |
7930 | + break; | |
7931 | + else if (isdir) { | |
7932 | + /* the type of lower may be different */ | |
7933 | + bdiropq = au_dbdiropq(dentry); | |
7934 | + if (bdiropq >= 0 && bdiropq <= bindex) | |
7935 | + break; | |
7936 | + } | |
7937 | + } | |
7938 | + | |
7939 | + if (npositive) { | |
7940 | + AuLabel(positive); | |
5afbbe0d | 7941 | + au_update_dbtop(dentry); |
1facf9fc | 7942 | + } |
7943 | + err = npositive; | |
076b876e | 7944 | + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE) |
5afbbe0d | 7945 | + && au_dbtop(dentry) < 0)) { |
1facf9fc | 7946 | + err = -EIO; |
523b37e3 AM |
7947 | + AuIOErr("both of real entry and whiteout found, %pd, err %d\n", |
7948 | + dentry, err); | |
027c5e7a | 7949 | + } |
1facf9fc | 7950 | + |
4f0767ce | 7951 | +out_parent: |
4a4d8108 | 7952 | + dput(parent); |
f0c0a007 | 7953 | + au_delayed_kfree(whname.name); |
4f0767ce | 7954 | +out: |
1facf9fc | 7955 | + return err; |
7956 | +} | |
7957 | + | |
076b876e | 7958 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent) |
1facf9fc | 7959 | +{ |
7960 | + struct dentry *dentry; | |
7961 | + int wkq_err; | |
7962 | + | |
5527c038 | 7963 | + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC)) |
b4510431 | 7964 | + dentry = vfsub_lkup_one(name, parent); |
1facf9fc | 7965 | + else { |
b4510431 AM |
7966 | + struct vfsub_lkup_one_args args = { |
7967 | + .errp = &dentry, | |
7968 | + .name = name, | |
7969 | + .parent = parent | |
1facf9fc | 7970 | + }; |
7971 | + | |
b4510431 | 7972 | + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args); |
1facf9fc | 7973 | + if (unlikely(wkq_err)) |
7974 | + dentry = ERR_PTR(wkq_err); | |
7975 | + } | |
7976 | + | |
7977 | + return dentry; | |
7978 | +} | |
7979 | + | |
7980 | +/* | |
7981 | + * lookup @dentry on @bindex which should be negative. | |
7982 | + */ | |
86dc4139 | 7983 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh) |
1facf9fc | 7984 | +{ |
7985 | + int err; | |
7986 | + struct dentry *parent, *h_parent, *h_dentry; | |
86dc4139 | 7987 | + struct au_branch *br; |
1facf9fc | 7988 | + |
1facf9fc | 7989 | + parent = dget_parent(dentry); |
7990 | + h_parent = au_h_dptr(parent, bindex); | |
86dc4139 AM |
7991 | + br = au_sbr(dentry->d_sb, bindex); |
7992 | + if (wh) | |
7993 | + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
7994 | + else | |
076b876e | 7995 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); |
1facf9fc | 7996 | + err = PTR_ERR(h_dentry); |
7997 | + if (IS_ERR(h_dentry)) | |
7998 | + goto out; | |
5527c038 | 7999 | + if (unlikely(d_is_positive(h_dentry))) { |
1facf9fc | 8000 | + err = -EIO; |
523b37e3 | 8001 | + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex); |
1facf9fc | 8002 | + dput(h_dentry); |
8003 | + goto out; | |
8004 | + } | |
8005 | + | |
4a4d8108 | 8006 | + err = 0; |
5afbbe0d AM |
8007 | + if (bindex < au_dbtop(dentry)) |
8008 | + au_set_dbtop(dentry, bindex); | |
8009 | + if (au_dbbot(dentry) < bindex) | |
8010 | + au_set_dbbot(dentry, bindex); | |
1facf9fc | 8011 | + au_set_h_dptr(dentry, bindex, h_dentry); |
1facf9fc | 8012 | + |
4f0767ce | 8013 | +out: |
1facf9fc | 8014 | + dput(parent); |
8015 | + return err; | |
8016 | +} | |
8017 | + | |
8018 | +/* ---------------------------------------------------------------------- */ | |
8019 | + | |
8020 | +/* subset of struct inode */ | |
8021 | +struct au_iattr { | |
8022 | + unsigned long i_ino; | |
8023 | + /* unsigned int i_nlink; */ | |
0c3ec466 AM |
8024 | + kuid_t i_uid; |
8025 | + kgid_t i_gid; | |
1facf9fc | 8026 | + u64 i_version; |
8027 | +/* | |
8028 | + loff_t i_size; | |
8029 | + blkcnt_t i_blocks; | |
8030 | +*/ | |
8031 | + umode_t i_mode; | |
8032 | +}; | |
8033 | + | |
8034 | +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode) | |
8035 | +{ | |
8036 | + ia->i_ino = h_inode->i_ino; | |
8037 | + /* ia->i_nlink = h_inode->i_nlink; */ | |
8038 | + ia->i_uid = h_inode->i_uid; | |
8039 | + ia->i_gid = h_inode->i_gid; | |
8040 | + ia->i_version = h_inode->i_version; | |
8041 | +/* | |
8042 | + ia->i_size = h_inode->i_size; | |
8043 | + ia->i_blocks = h_inode->i_blocks; | |
8044 | +*/ | |
8045 | + ia->i_mode = (h_inode->i_mode & S_IFMT); | |
8046 | +} | |
8047 | + | |
8048 | +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode) | |
8049 | +{ | |
8050 | + return ia->i_ino != h_inode->i_ino | |
8051 | + /* || ia->i_nlink != h_inode->i_nlink */ | |
0c3ec466 | 8052 | + || !uid_eq(ia->i_uid, h_inode->i_uid) |
2dfbb274 | 8053 | + || !gid_eq(ia->i_gid, h_inode->i_gid) |
1facf9fc | 8054 | + || ia->i_version != h_inode->i_version |
8055 | +/* | |
8056 | + || ia->i_size != h_inode->i_size | |
8057 | + || ia->i_blocks != h_inode->i_blocks | |
8058 | +*/ | |
8059 | + || ia->i_mode != (h_inode->i_mode & S_IFMT); | |
8060 | +} | |
8061 | + | |
8062 | +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent, | |
8063 | + struct au_branch *br) | |
8064 | +{ | |
8065 | + int err; | |
8066 | + struct au_iattr ia; | |
8067 | + struct inode *h_inode; | |
8068 | + struct dentry *h_d; | |
8069 | + struct super_block *h_sb; | |
8070 | + | |
8071 | + err = 0; | |
8072 | + memset(&ia, -1, sizeof(ia)); | |
8073 | + h_sb = h_dentry->d_sb; | |
5527c038 JR |
8074 | + h_inode = NULL; |
8075 | + if (d_is_positive(h_dentry)) { | |
8076 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8077 | + au_iattr_save(&ia, h_inode); |
5527c038 | 8078 | + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb)) |
1facf9fc | 8079 | + /* nfs d_revalidate may return 0 for negative dentry */ |
8080 | + /* fuse d_revalidate always return 0 for negative dentry */ | |
8081 | + goto out; | |
8082 | + | |
8083 | + /* main purpose is namei.c:cached_lookup() and d_revalidate */ | |
b4510431 | 8084 | + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent); |
1facf9fc | 8085 | + err = PTR_ERR(h_d); |
8086 | + if (IS_ERR(h_d)) | |
8087 | + goto out; | |
8088 | + | |
8089 | + err = 0; | |
8090 | + if (unlikely(h_d != h_dentry | |
5527c038 | 8091 | + || d_inode(h_d) != h_inode |
1facf9fc | 8092 | + || (h_inode && au_iattr_test(&ia, h_inode)))) |
8093 | + err = au_busy_or_stale(); | |
8094 | + dput(h_d); | |
8095 | + | |
4f0767ce | 8096 | +out: |
1facf9fc | 8097 | + AuTraceErr(err); |
8098 | + return err; | |
8099 | +} | |
8100 | + | |
8101 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, | |
8102 | + struct dentry *h_parent, struct au_branch *br) | |
8103 | +{ | |
8104 | + int err; | |
8105 | + | |
8106 | + err = 0; | |
027c5e7a AM |
8107 | + if (udba == AuOpt_UDBA_REVAL |
8108 | + && !au_test_fs_remote(h_dentry->d_sb)) { | |
1facf9fc | 8109 | + IMustLock(h_dir); |
5527c038 | 8110 | + err = (d_inode(h_dentry->d_parent) != h_dir); |
027c5e7a | 8111 | + } else if (udba != AuOpt_UDBA_NONE) |
1facf9fc | 8112 | + err = au_h_verify_dentry(h_dentry, h_parent, br); |
8113 | + | |
8114 | + return err; | |
8115 | +} | |
8116 | + | |
8117 | +/* ---------------------------------------------------------------------- */ | |
8118 | + | |
027c5e7a | 8119 | +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 8120 | +{ |
027c5e7a | 8121 | + int err; |
5afbbe0d | 8122 | + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq; |
027c5e7a AM |
8123 | + struct au_hdentry tmp, *p, *q; |
8124 | + struct au_dinfo *dinfo; | |
8125 | + struct super_block *sb; | |
1facf9fc | 8126 | + |
027c5e7a | 8127 | + DiMustWriteLock(dentry); |
1308ab2a | 8128 | + |
027c5e7a AM |
8129 | + sb = dentry->d_sb; |
8130 | + dinfo = au_di(dentry); | |
5afbbe0d | 8131 | + bbot = dinfo->di_bbot; |
1facf9fc | 8132 | + bwh = dinfo->di_bwh; |
8133 | + bdiropq = dinfo->di_bdiropq; | |
5afbbe0d AM |
8134 | + bindex = dinfo->di_btop; |
8135 | + p = au_hdentry(dinfo, bindex); | |
8136 | + for (; bindex <= bbot; bindex++, p++) { | |
027c5e7a | 8137 | + if (!p->hd_dentry) |
1facf9fc | 8138 | + continue; |
8139 | + | |
027c5e7a AM |
8140 | + new_bindex = au_br_index(sb, p->hd_id); |
8141 | + if (new_bindex == bindex) | |
1facf9fc | 8142 | + continue; |
1facf9fc | 8143 | + |
1facf9fc | 8144 | + if (dinfo->di_bwh == bindex) |
8145 | + bwh = new_bindex; | |
8146 | + if (dinfo->di_bdiropq == bindex) | |
8147 | + bdiropq = new_bindex; | |
8148 | + if (new_bindex < 0) { | |
8149 | + au_hdput(p); | |
8150 | + p->hd_dentry = NULL; | |
8151 | + continue; | |
8152 | + } | |
8153 | + | |
8154 | + /* swap two lower dentries, and loop again */ | |
5afbbe0d | 8155 | + q = au_hdentry(dinfo, new_bindex); |
1facf9fc | 8156 | + tmp = *q; |
8157 | + *q = *p; | |
8158 | + *p = tmp; | |
8159 | + if (tmp.hd_dentry) { | |
8160 | + bindex--; | |
8161 | + p--; | |
8162 | + } | |
8163 | + } | |
8164 | + | |
1facf9fc | 8165 | + dinfo->di_bwh = -1; |
5afbbe0d | 8166 | + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh)) |
1facf9fc | 8167 | + dinfo->di_bwh = bwh; |
8168 | + | |
8169 | + dinfo->di_bdiropq = -1; | |
8170 | + if (bdiropq >= 0 | |
5afbbe0d | 8171 | + && bdiropq <= au_sbbot(sb) |
1facf9fc | 8172 | + && au_sbr_whable(sb, bdiropq)) |
8173 | + dinfo->di_bdiropq = bdiropq; | |
8174 | + | |
027c5e7a | 8175 | + err = -EIO; |
5afbbe0d AM |
8176 | + dinfo->di_btop = -1; |
8177 | + dinfo->di_bbot = -1; | |
8178 | + bbot = au_dbbot(parent); | |
8179 | + bindex = 0; | |
8180 | + p = au_hdentry(dinfo, bindex); | |
8181 | + for (; bindex <= bbot; bindex++, p++) | |
1facf9fc | 8182 | + if (p->hd_dentry) { |
5afbbe0d | 8183 | + dinfo->di_btop = bindex; |
1facf9fc | 8184 | + break; |
8185 | + } | |
8186 | + | |
5afbbe0d AM |
8187 | + if (dinfo->di_btop >= 0) { |
8188 | + bindex = bbot; | |
8189 | + p = au_hdentry(dinfo, bindex); | |
8190 | + for (; bindex >= 0; bindex--, p--) | |
027c5e7a | 8191 | + if (p->hd_dentry) { |
5afbbe0d | 8192 | + dinfo->di_bbot = bindex; |
027c5e7a AM |
8193 | + err = 0; |
8194 | + break; | |
8195 | + } | |
8196 | + } | |
8197 | + | |
8198 | + return err; | |
1facf9fc | 8199 | +} |
8200 | + | |
027c5e7a | 8201 | +static void au_do_hide(struct dentry *dentry) |
1facf9fc | 8202 | +{ |
027c5e7a | 8203 | + struct inode *inode; |
1facf9fc | 8204 | + |
5527c038 JR |
8205 | + if (d_really_is_positive(dentry)) { |
8206 | + inode = d_inode(dentry); | |
8207 | + if (!d_is_dir(dentry)) { | |
027c5e7a AM |
8208 | + if (inode->i_nlink && !d_unhashed(dentry)) |
8209 | + drop_nlink(inode); | |
8210 | + } else { | |
8211 | + clear_nlink(inode); | |
8212 | + /* stop next lookup */ | |
8213 | + inode->i_flags |= S_DEAD; | |
8214 | + } | |
8215 | + smp_mb(); /* necessary? */ | |
8216 | + } | |
8217 | + d_drop(dentry); | |
8218 | +} | |
1308ab2a | 8219 | + |
027c5e7a AM |
8220 | +static int au_hide_children(struct dentry *parent) |
8221 | +{ | |
8222 | + int err, i, j, ndentry; | |
8223 | + struct au_dcsub_pages dpages; | |
8224 | + struct au_dpage *dpage; | |
8225 | + struct dentry *dentry; | |
1facf9fc | 8226 | + |
027c5e7a | 8227 | + err = au_dpages_init(&dpages, GFP_NOFS); |
1facf9fc | 8228 | + if (unlikely(err)) |
8229 | + goto out; | |
027c5e7a AM |
8230 | + err = au_dcsub_pages(&dpages, parent, NULL, NULL); |
8231 | + if (unlikely(err)) | |
8232 | + goto out_dpages; | |
1facf9fc | 8233 | + |
027c5e7a AM |
8234 | + /* in reverse order */ |
8235 | + for (i = dpages.ndpage - 1; i >= 0; i--) { | |
8236 | + dpage = dpages.dpages + i; | |
8237 | + ndentry = dpage->ndentry; | |
8238 | + for (j = ndentry - 1; j >= 0; j--) { | |
8239 | + dentry = dpage->dentries[j]; | |
8240 | + if (dentry != parent) | |
8241 | + au_do_hide(dentry); | |
8242 | + } | |
8243 | + } | |
1facf9fc | 8244 | + |
027c5e7a AM |
8245 | +out_dpages: |
8246 | + au_dpages_free(&dpages); | |
4f0767ce | 8247 | +out: |
027c5e7a | 8248 | + return err; |
1facf9fc | 8249 | +} |
8250 | + | |
027c5e7a | 8251 | +static void au_hide(struct dentry *dentry) |
1facf9fc | 8252 | +{ |
027c5e7a | 8253 | + int err; |
1facf9fc | 8254 | + |
027c5e7a | 8255 | + AuDbgDentry(dentry); |
2000de60 | 8256 | + if (d_is_dir(dentry)) { |
027c5e7a AM |
8257 | + /* shrink_dcache_parent(dentry); */ |
8258 | + err = au_hide_children(dentry); | |
8259 | + if (unlikely(err)) | |
523b37e3 AM |
8260 | + AuIOErr("%pd, failed hiding children, ignored %d\n", |
8261 | + dentry, err); | |
027c5e7a AM |
8262 | + } |
8263 | + au_do_hide(dentry); | |
8264 | +} | |
1facf9fc | 8265 | + |
027c5e7a AM |
8266 | +/* |
8267 | + * By adding a dirty branch, a cached dentry may be affected in various ways. | |
8268 | + * | |
8269 | + * a dirty branch is added | |
8270 | + * - on the top of layers | |
8271 | + * - in the middle of layers | |
8272 | + * - to the bottom of layers | |
8273 | + * | |
8274 | + * on the added branch there exists | |
8275 | + * - a whiteout | |
8276 | + * - a diropq | |
8277 | + * - a same named entry | |
8278 | + * + exist | |
8279 | + * * negative --> positive | |
8280 | + * * positive --> positive | |
8281 | + * - type is unchanged | |
8282 | + * - type is changed | |
8283 | + * + doesn't exist | |
8284 | + * * negative --> negative | |
8285 | + * * positive --> negative (rejected by au_br_del() for non-dir case) | |
8286 | + * - none | |
8287 | + */ | |
8288 | +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo, | |
8289 | + struct au_dinfo *tmp) | |
8290 | +{ | |
8291 | + int err; | |
5afbbe0d | 8292 | + aufs_bindex_t bindex, bbot; |
027c5e7a AM |
8293 | + struct { |
8294 | + struct dentry *dentry; | |
8295 | + struct inode *inode; | |
8296 | + mode_t mode; | |
be52b249 AM |
8297 | + } orig_h, tmp_h = { |
8298 | + .dentry = NULL | |
8299 | + }; | |
027c5e7a AM |
8300 | + struct au_hdentry *hd; |
8301 | + struct inode *inode, *h_inode; | |
8302 | + struct dentry *h_dentry; | |
8303 | + | |
8304 | + err = 0; | |
5afbbe0d | 8305 | + AuDebugOn(dinfo->di_btop < 0); |
027c5e7a | 8306 | + orig_h.mode = 0; |
5afbbe0d | 8307 | + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry; |
5527c038 JR |
8308 | + orig_h.inode = NULL; |
8309 | + if (d_is_positive(orig_h.dentry)) { | |
8310 | + orig_h.inode = d_inode(orig_h.dentry); | |
027c5e7a | 8311 | + orig_h.mode = orig_h.inode->i_mode & S_IFMT; |
5527c038 | 8312 | + } |
5afbbe0d AM |
8313 | + if (tmp->di_btop >= 0) { |
8314 | + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry; | |
5527c038 JR |
8315 | + if (d_is_positive(tmp_h.dentry)) { |
8316 | + tmp_h.inode = d_inode(tmp_h.dentry); | |
027c5e7a | 8317 | + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT; |
5527c038 | 8318 | + } |
027c5e7a AM |
8319 | + } |
8320 | + | |
5527c038 JR |
8321 | + inode = NULL; |
8322 | + if (d_really_is_positive(dentry)) | |
8323 | + inode = d_inode(dentry); | |
027c5e7a AM |
8324 | + if (!orig_h.inode) { |
8325 | + AuDbg("nagative originally\n"); | |
8326 | + if (inode) { | |
8327 | + au_hide(dentry); | |
8328 | + goto out; | |
8329 | + } | |
8330 | + AuDebugOn(inode); | |
5afbbe0d | 8331 | + AuDebugOn(dinfo->di_btop != dinfo->di_bbot); |
027c5e7a AM |
8332 | + AuDebugOn(dinfo->di_bdiropq != -1); |
8333 | + | |
8334 | + if (!tmp_h.inode) { | |
8335 | + AuDbg("negative --> negative\n"); | |
8336 | + /* should have only one negative lower */ | |
5afbbe0d AM |
8337 | + if (tmp->di_btop >= 0 |
8338 | + && tmp->di_btop < dinfo->di_btop) { | |
8339 | + AuDebugOn(tmp->di_btop != tmp->di_bbot); | |
8340 | + AuDebugOn(dinfo->di_btop != dinfo->di_bbot); | |
8341 | + au_set_h_dptr(dentry, dinfo->di_btop, NULL); | |
027c5e7a | 8342 | + au_di_cp(dinfo, tmp); |
5afbbe0d AM |
8343 | + hd = au_hdentry(tmp, tmp->di_btop); |
8344 | + au_set_h_dptr(dentry, tmp->di_btop, | |
027c5e7a AM |
8345 | + dget(hd->hd_dentry)); |
8346 | + } | |
8347 | + au_dbg_verify_dinode(dentry); | |
8348 | + } else { | |
8349 | + AuDbg("negative --> positive\n"); | |
8350 | + /* | |
8351 | + * similar to the behaviour of creating with bypassing | |
8352 | + * aufs. | |
8353 | + * unhash it in order to force an error in the | |
8354 | + * succeeding create operation. | |
8355 | + * we should not set S_DEAD here. | |
8356 | + */ | |
8357 | + d_drop(dentry); | |
8358 | + /* au_di_swap(tmp, dinfo); */ | |
8359 | + au_dbg_verify_dinode(dentry); | |
8360 | + } | |
8361 | + } else { | |
8362 | + AuDbg("positive originally\n"); | |
8363 | + /* inode may be NULL */ | |
8364 | + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode); | |
8365 | + if (!tmp_h.inode) { | |
8366 | + AuDbg("positive --> negative\n"); | |
8367 | + /* or bypassing aufs */ | |
8368 | + au_hide(dentry); | |
5afbbe0d | 8369 | + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop) |
027c5e7a AM |
8370 | + dinfo->di_bwh = tmp->di_bwh; |
8371 | + if (inode) | |
8372 | + err = au_refresh_hinode_self(inode); | |
8373 | + au_dbg_verify_dinode(dentry); | |
8374 | + } else if (orig_h.mode == tmp_h.mode) { | |
8375 | + AuDbg("positive --> positive, same type\n"); | |
8376 | + if (!S_ISDIR(orig_h.mode) | |
5afbbe0d | 8377 | + && dinfo->di_btop > tmp->di_btop) { |
027c5e7a AM |
8378 | + /* |
8379 | + * similar to the behaviour of removing and | |
8380 | + * creating. | |
8381 | + */ | |
8382 | + au_hide(dentry); | |
8383 | + if (inode) | |
8384 | + err = au_refresh_hinode_self(inode); | |
8385 | + au_dbg_verify_dinode(dentry); | |
8386 | + } else { | |
8387 | + /* fill empty slots */ | |
5afbbe0d AM |
8388 | + if (dinfo->di_btop > tmp->di_btop) |
8389 | + dinfo->di_btop = tmp->di_btop; | |
8390 | + if (dinfo->di_bbot < tmp->di_bbot) | |
8391 | + dinfo->di_bbot = tmp->di_bbot; | |
027c5e7a AM |
8392 | + dinfo->di_bwh = tmp->di_bwh; |
8393 | + dinfo->di_bdiropq = tmp->di_bdiropq; | |
5afbbe0d AM |
8394 | + bbot = dinfo->di_bbot; |
8395 | + bindex = tmp->di_btop; | |
8396 | + hd = au_hdentry(tmp, bindex); | |
8397 | + for (; bindex <= bbot; bindex++, hd++) { | |
027c5e7a AM |
8398 | + if (au_h_dptr(dentry, bindex)) |
8399 | + continue; | |
5afbbe0d | 8400 | + h_dentry = hd->hd_dentry; |
027c5e7a AM |
8401 | + if (!h_dentry) |
8402 | + continue; | |
5527c038 JR |
8403 | + AuDebugOn(d_is_negative(h_dentry)); |
8404 | + h_inode = d_inode(h_dentry); | |
027c5e7a AM |
8405 | + AuDebugOn(orig_h.mode |
8406 | + != (h_inode->i_mode | |
8407 | + & S_IFMT)); | |
8408 | + au_set_h_dptr(dentry, bindex, | |
8409 | + dget(h_dentry)); | |
8410 | + } | |
5afbbe0d AM |
8411 | + if (inode) |
8412 | + err = au_refresh_hinode(inode, dentry); | |
027c5e7a AM |
8413 | + au_dbg_verify_dinode(dentry); |
8414 | + } | |
8415 | + } else { | |
8416 | + AuDbg("positive --> positive, different type\n"); | |
8417 | + /* similar to the behaviour of removing and creating */ | |
8418 | + au_hide(dentry); | |
8419 | + if (inode) | |
8420 | + err = au_refresh_hinode_self(inode); | |
8421 | + au_dbg_verify_dinode(dentry); | |
8422 | + } | |
8423 | + } | |
8424 | + | |
8425 | +out: | |
8426 | + return err; | |
8427 | +} | |
8428 | + | |
79b8bda9 AM |
8429 | +void au_refresh_dop(struct dentry *dentry, int force_reval) |
8430 | +{ | |
8431 | + const struct dentry_operations *dop | |
8432 | + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op; | |
8433 | + static const unsigned int mask | |
8434 | + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE; | |
8435 | + | |
8436 | + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags)); | |
8437 | + | |
8438 | + if (dentry->d_op == dop) | |
8439 | + return; | |
8440 | + | |
8441 | + AuDbg("%pd\n", dentry); | |
8442 | + spin_lock(&dentry->d_lock); | |
8443 | + if (dop == &aufs_dop) | |
8444 | + dentry->d_flags |= mask; | |
8445 | + else | |
8446 | + dentry->d_flags &= ~mask; | |
8447 | + dentry->d_op = dop; | |
8448 | + spin_unlock(&dentry->d_lock); | |
8449 | +} | |
8450 | + | |
027c5e7a AM |
8451 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent) |
8452 | +{ | |
e2f27e51 | 8453 | + int err, ebrange, nbr; |
027c5e7a AM |
8454 | + unsigned int sigen; |
8455 | + struct au_dinfo *dinfo, *tmp; | |
8456 | + struct super_block *sb; | |
8457 | + struct inode *inode; | |
8458 | + | |
8459 | + DiMustWriteLock(dentry); | |
8460 | + AuDebugOn(IS_ROOT(dentry)); | |
5527c038 | 8461 | + AuDebugOn(d_really_is_negative(parent)); |
027c5e7a AM |
8462 | + |
8463 | + sb = dentry->d_sb; | |
027c5e7a AM |
8464 | + sigen = au_sigen(sb); |
8465 | + err = au_digen_test(parent, sigen); | |
8466 | + if (unlikely(err)) | |
8467 | + goto out; | |
8468 | + | |
e2f27e51 | 8469 | + nbr = au_sbbot(sb) + 1; |
027c5e7a | 8470 | + dinfo = au_di(dentry); |
e2f27e51 | 8471 | + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0); |
027c5e7a AM |
8472 | + if (unlikely(err)) |
8473 | + goto out; | |
8474 | + ebrange = au_dbrange_test(dentry); | |
8475 | + if (!ebrange) | |
8476 | + ebrange = au_do_refresh_hdentry(dentry, parent); | |
8477 | + | |
38d290e6 | 8478 | + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) { |
5afbbe0d | 8479 | + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0); |
5527c038 JR |
8480 | + if (d_really_is_positive(dentry)) { |
8481 | + inode = d_inode(dentry); | |
027c5e7a | 8482 | + err = au_refresh_hinode_self(inode); |
5527c038 | 8483 | + } |
027c5e7a AM |
8484 | + au_dbg_verify_dinode(dentry); |
8485 | + if (!err) | |
8486 | + goto out_dgen; /* success */ | |
8487 | + goto out; | |
8488 | + } | |
8489 | + | |
8490 | + /* temporary dinfo */ | |
8491 | + AuDbgDentry(dentry); | |
8492 | + err = -ENOMEM; | |
8493 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
8494 | + if (unlikely(!tmp)) | |
8495 | + goto out; | |
8496 | + au_di_swap(tmp, dinfo); | |
8497 | + /* returns the number of positive dentries */ | |
8498 | + /* | |
8499 | + * if current working dir is removed, it returns an error. | |
8500 | + * but the dentry is legal. | |
8501 | + */ | |
5afbbe0d | 8502 | + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG); |
027c5e7a AM |
8503 | + AuDbgDentry(dentry); |
8504 | + au_di_swap(tmp, dinfo); | |
8505 | + if (err == -ENOENT) | |
8506 | + err = 0; | |
8507 | + if (err >= 0) { | |
8508 | + /* compare/refresh by dinfo */ | |
8509 | + AuDbgDentry(dentry); | |
8510 | + err = au_refresh_by_dinfo(dentry, dinfo, tmp); | |
8511 | + au_dbg_verify_dinode(dentry); | |
8512 | + AuTraceErr(err); | |
8513 | + } | |
e2f27e51 | 8514 | + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */ |
027c5e7a AM |
8515 | + au_rw_write_unlock(&tmp->di_rwsem); |
8516 | + au_di_free(tmp); | |
8517 | + if (unlikely(err)) | |
8518 | + goto out; | |
8519 | + | |
8520 | +out_dgen: | |
8521 | + au_update_digen(dentry); | |
8522 | +out: | |
8523 | + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) { | |
523b37e3 | 8524 | + AuIOErr("failed refreshing %pd, %d\n", dentry, err); |
027c5e7a AM |
8525 | + AuDbgDentry(dentry); |
8526 | + } | |
8527 | + AuTraceErr(err); | |
8528 | + return err; | |
8529 | +} | |
8530 | + | |
b4510431 AM |
8531 | +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags, |
8532 | + struct dentry *dentry, aufs_bindex_t bindex) | |
027c5e7a AM |
8533 | +{ |
8534 | + int err, valid; | |
027c5e7a AM |
8535 | + |
8536 | + err = 0; | |
8537 | + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE)) | |
8538 | + goto out; | |
027c5e7a AM |
8539 | + |
8540 | + AuDbg("b%d\n", bindex); | |
b4510431 AM |
8541 | + /* |
8542 | + * gave up supporting LOOKUP_CREATE/OPEN for lower fs, | |
8543 | + * due to whiteout and branch permission. | |
8544 | + */ | |
8545 | + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE | |
8546 | + | LOOKUP_FOLLOW | LOOKUP_EXCL); | |
8547 | + /* it may return tri-state */ | |
8548 | + valid = h_dentry->d_op->d_revalidate(h_dentry, flags); | |
1facf9fc | 8549 | + |
8550 | + if (unlikely(valid < 0)) | |
8551 | + err = valid; | |
8552 | + else if (!valid) | |
8553 | + err = -EINVAL; | |
8554 | + | |
4f0767ce | 8555 | +out: |
1facf9fc | 8556 | + AuTraceErr(err); |
8557 | + return err; | |
8558 | +} | |
8559 | + | |
8560 | +/* todo: remove this */ | |
8561 | +static int h_d_revalidate(struct dentry *dentry, struct inode *inode, | |
b4510431 | 8562 | + unsigned int flags, int do_udba) |
1facf9fc | 8563 | +{ |
8564 | + int err; | |
8565 | + umode_t mode, h_mode; | |
5afbbe0d | 8566 | + aufs_bindex_t bindex, btail, btop, ibs, ibe; |
38d290e6 | 8567 | + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile; |
4a4d8108 | 8568 | + struct inode *h_inode, *h_cached_inode; |
1facf9fc | 8569 | + struct dentry *h_dentry; |
8570 | + struct qstr *name, *h_name; | |
8571 | + | |
8572 | + err = 0; | |
8573 | + plus = 0; | |
8574 | + mode = 0; | |
1facf9fc | 8575 | + ibs = -1; |
8576 | + ibe = -1; | |
8577 | + unhashed = !!d_unhashed(dentry); | |
8578 | + is_root = !!IS_ROOT(dentry); | |
8579 | + name = &dentry->d_name; | |
38d290e6 | 8580 | + tmpfile = au_di(dentry)->di_tmpfile; |
1facf9fc | 8581 | + |
8582 | + /* | |
7f207e10 AM |
8583 | + * Theoretically, REVAL test should be unnecessary in case of |
8584 | + * {FS,I}NOTIFY. | |
8585 | + * But {fs,i}notify doesn't fire some necessary events, | |
1facf9fc | 8586 | + * IN_ATTRIB for atime/nlink/pageio |
1facf9fc | 8587 | + * Let's do REVAL test too. |
8588 | + */ | |
8589 | + if (do_udba && inode) { | |
8590 | + mode = (inode->i_mode & S_IFMT); | |
8591 | + plus = (inode->i_nlink > 0); | |
5afbbe0d AM |
8592 | + ibs = au_ibtop(inode); |
8593 | + ibe = au_ibbot(inode); | |
1facf9fc | 8594 | + } |
8595 | + | |
5afbbe0d AM |
8596 | + btop = au_dbtop(dentry); |
8597 | + btail = btop; | |
1facf9fc | 8598 | + if (inode && S_ISDIR(inode->i_mode)) |
8599 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 8600 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 8601 | + h_dentry = au_h_dptr(dentry, bindex); |
8602 | + if (!h_dentry) | |
8603 | + continue; | |
8604 | + | |
523b37e3 AM |
8605 | + AuDbg("b%d, %pd\n", bindex, h_dentry); |
8606 | + h_nfs = !!au_test_nfs(h_dentry->d_sb); | |
027c5e7a | 8607 | + spin_lock(&h_dentry->d_lock); |
1facf9fc | 8608 | + h_name = &h_dentry->d_name; |
8609 | + if (unlikely(do_udba | |
8610 | + && !is_root | |
523b37e3 AM |
8611 | + && ((!h_nfs |
8612 | + && (unhashed != !!d_unhashed(h_dentry) | |
38d290e6 JR |
8613 | + || (!tmpfile |
8614 | + && !au_qstreq(name, h_name)) | |
8615 | + )) | |
523b37e3 AM |
8616 | + || (h_nfs |
8617 | + && !(flags & LOOKUP_OPEN) | |
8618 | + && (h_dentry->d_flags | |
8619 | + & DCACHE_NFSFS_RENAMED))) | |
1facf9fc | 8620 | + )) { |
38d290e6 JR |
8621 | + int h_unhashed; |
8622 | + | |
8623 | + h_unhashed = d_unhashed(h_dentry); | |
027c5e7a | 8624 | + spin_unlock(&h_dentry->d_lock); |
38d290e6 JR |
8625 | + AuDbg("unhash 0x%x 0x%x, %pd %pd\n", |
8626 | + unhashed, h_unhashed, dentry, h_dentry); | |
1facf9fc | 8627 | + goto err; |
8628 | + } | |
027c5e7a | 8629 | + spin_unlock(&h_dentry->d_lock); |
1facf9fc | 8630 | + |
b4510431 | 8631 | + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex); |
1facf9fc | 8632 | + if (unlikely(err)) |
8633 | + /* do not goto err, to keep the errno */ | |
8634 | + break; | |
8635 | + | |
8636 | + /* todo: plink too? */ | |
8637 | + if (!do_udba) | |
8638 | + continue; | |
8639 | + | |
8640 | + /* UDBA tests */ | |
5527c038 | 8641 | + if (unlikely(!!inode != d_is_positive(h_dentry))) |
1facf9fc | 8642 | + goto err; |
8643 | + | |
5527c038 JR |
8644 | + h_inode = NULL; |
8645 | + if (d_is_positive(h_dentry)) | |
8646 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8647 | + h_plus = plus; |
8648 | + h_mode = mode; | |
8649 | + h_cached_inode = h_inode; | |
8650 | + if (h_inode) { | |
8651 | + h_mode = (h_inode->i_mode & S_IFMT); | |
8652 | + h_plus = (h_inode->i_nlink > 0); | |
8653 | + } | |
8654 | + if (inode && ibs <= bindex && bindex <= ibe) | |
8655 | + h_cached_inode = au_h_iptr(inode, bindex); | |
8656 | + | |
523b37e3 | 8657 | + if (!h_nfs) { |
38d290e6 | 8658 | + if (unlikely(plus != h_plus && !tmpfile)) |
523b37e3 AM |
8659 | + goto err; |
8660 | + } else { | |
8661 | + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED) | |
8662 | + && !is_root | |
8663 | + && !IS_ROOT(h_dentry) | |
8664 | + && unhashed != d_unhashed(h_dentry))) | |
8665 | + goto err; | |
8666 | + } | |
8667 | + if (unlikely(mode != h_mode | |
1facf9fc | 8668 | + || h_cached_inode != h_inode)) |
8669 | + goto err; | |
8670 | + continue; | |
8671 | + | |
f6b6e03d | 8672 | +err: |
1facf9fc | 8673 | + err = -EINVAL; |
8674 | + break; | |
8675 | + } | |
8676 | + | |
523b37e3 | 8677 | + AuTraceErr(err); |
1facf9fc | 8678 | + return err; |
8679 | +} | |
8680 | + | |
027c5e7a | 8681 | +/* todo: consolidate with do_refresh() and au_reval_for_attr() */ |
1facf9fc | 8682 | +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen) |
8683 | +{ | |
8684 | + int err; | |
8685 | + struct dentry *parent; | |
1facf9fc | 8686 | + |
027c5e7a | 8687 | + if (!au_digen_test(dentry, sigen)) |
1facf9fc | 8688 | + return 0; |
8689 | + | |
8690 | + parent = dget_parent(dentry); | |
8691 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 8692 | + AuDebugOn(au_digen_test(parent, sigen)); |
1facf9fc | 8693 | + au_dbg_verify_gen(parent, sigen); |
027c5e7a | 8694 | + err = au_refresh_dentry(dentry, parent); |
1facf9fc | 8695 | + di_read_unlock(parent, AuLock_IR); |
8696 | + dput(parent); | |
027c5e7a | 8697 | + AuTraceErr(err); |
1facf9fc | 8698 | + return err; |
8699 | +} | |
8700 | + | |
8701 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen) | |
8702 | +{ | |
8703 | + int err; | |
8704 | + struct dentry *d, *parent; | |
1facf9fc | 8705 | + |
027c5e7a | 8706 | + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR)) |
1facf9fc | 8707 | + return simple_reval_dpath(dentry, sigen); |
8708 | + | |
8709 | + /* slow loop, keep it simple and stupid */ | |
8710 | + /* cf: au_cpup_dirs() */ | |
8711 | + err = 0; | |
8712 | + parent = NULL; | |
027c5e7a | 8713 | + while (au_digen_test(dentry, sigen)) { |
1facf9fc | 8714 | + d = dentry; |
8715 | + while (1) { | |
8716 | + dput(parent); | |
8717 | + parent = dget_parent(d); | |
027c5e7a | 8718 | + if (!au_digen_test(parent, sigen)) |
1facf9fc | 8719 | + break; |
8720 | + d = parent; | |
8721 | + } | |
8722 | + | |
1facf9fc | 8723 | + if (d != dentry) |
027c5e7a | 8724 | + di_write_lock_child2(d); |
1facf9fc | 8725 | + |
8726 | + /* someone might update our dentry while we were sleeping */ | |
027c5e7a AM |
8727 | + if (au_digen_test(d, sigen)) { |
8728 | + /* | |
8729 | + * todo: consolidate with simple_reval_dpath(), | |
8730 | + * do_refresh() and au_reval_for_attr(). | |
8731 | + */ | |
1facf9fc | 8732 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a | 8733 | + err = au_refresh_dentry(d, parent); |
1facf9fc | 8734 | + di_read_unlock(parent, AuLock_IR); |
8735 | + } | |
8736 | + | |
8737 | + if (d != dentry) | |
8738 | + di_write_unlock(d); | |
8739 | + dput(parent); | |
8740 | + if (unlikely(err)) | |
8741 | + break; | |
8742 | + } | |
8743 | + | |
8744 | + return err; | |
8745 | +} | |
8746 | + | |
8747 | +/* | |
8748 | + * if valid returns 1, otherwise 0. | |
8749 | + */ | |
b4510431 | 8750 | +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags) |
1facf9fc | 8751 | +{ |
8752 | + int valid, err; | |
8753 | + unsigned int sigen; | |
8754 | + unsigned char do_udba; | |
8755 | + struct super_block *sb; | |
8756 | + struct inode *inode; | |
8757 | + | |
027c5e7a | 8758 | + /* todo: support rcu-walk? */ |
b4510431 | 8759 | + if (flags & LOOKUP_RCU) |
027c5e7a AM |
8760 | + return -ECHILD; |
8761 | + | |
8762 | + valid = 0; | |
8763 | + if (unlikely(!au_di(dentry))) | |
8764 | + goto out; | |
8765 | + | |
e49829fe | 8766 | + valid = 1; |
1facf9fc | 8767 | + sb = dentry->d_sb; |
e49829fe JR |
8768 | + /* |
8769 | + * todo: very ugly | |
8770 | + * i_mutex of parent dir may be held, | |
8771 | + * but we should not return 'invalid' due to busy. | |
8772 | + */ | |
8773 | + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM); | |
8774 | + if (unlikely(err)) { | |
8775 | + valid = err; | |
027c5e7a | 8776 | + AuTraceErr(err); |
e49829fe JR |
8777 | + goto out; |
8778 | + } | |
5527c038 JR |
8779 | + inode = NULL; |
8780 | + if (d_really_is_positive(dentry)) | |
8781 | + inode = d_inode(dentry); | |
5afbbe0d | 8782 | + if (unlikely(inode && au_is_bad_inode(inode))) { |
c1595e42 JR |
8783 | + err = -EINVAL; |
8784 | + AuTraceErr(err); | |
8785 | + goto out_dgrade; | |
8786 | + } | |
027c5e7a AM |
8787 | + if (unlikely(au_dbrange_test(dentry))) { |
8788 | + err = -EINVAL; | |
8789 | + AuTraceErr(err); | |
8790 | + goto out_dgrade; | |
1facf9fc | 8791 | + } |
027c5e7a AM |
8792 | + |
8793 | + sigen = au_sigen(sb); | |
8794 | + if (au_digen_test(dentry, sigen)) { | |
1facf9fc | 8795 | + AuDebugOn(IS_ROOT(dentry)); |
027c5e7a AM |
8796 | + err = au_reval_dpath(dentry, sigen); |
8797 | + if (unlikely(err)) { | |
8798 | + AuTraceErr(err); | |
1facf9fc | 8799 | + goto out_dgrade; |
027c5e7a | 8800 | + } |
1facf9fc | 8801 | + } |
8802 | + di_downgrade_lock(dentry, AuLock_IR); | |
8803 | + | |
1facf9fc | 8804 | + err = -EINVAL; |
c1595e42 | 8805 | + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY)) |
523b37e3 | 8806 | + && inode |
38d290e6 | 8807 | + && !(inode->i_state && I_LINKABLE) |
79b8bda9 AM |
8808 | + && (IS_DEADDIR(inode) || !inode->i_nlink)) { |
8809 | + AuTraceErr(err); | |
027c5e7a | 8810 | + goto out_inval; |
79b8bda9 | 8811 | + } |
027c5e7a | 8812 | + |
1facf9fc | 8813 | + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE); |
8814 | + if (do_udba && inode) { | |
5afbbe0d | 8815 | + aufs_bindex_t btop = au_ibtop(inode); |
027c5e7a | 8816 | + struct inode *h_inode; |
1facf9fc | 8817 | + |
5afbbe0d AM |
8818 | + if (btop >= 0) { |
8819 | + h_inode = au_h_iptr(inode, btop); | |
79b8bda9 AM |
8820 | + if (h_inode && au_test_higen(inode, h_inode)) { |
8821 | + AuTraceErr(err); | |
027c5e7a | 8822 | + goto out_inval; |
79b8bda9 | 8823 | + } |
027c5e7a | 8824 | + } |
1facf9fc | 8825 | + } |
8826 | + | |
b4510431 | 8827 | + err = h_d_revalidate(dentry, inode, flags, do_udba); |
5afbbe0d | 8828 | + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) { |
1facf9fc | 8829 | + err = -EIO; |
523b37e3 AM |
8830 | + AuDbg("both of real entry and whiteout found, %p, err %d\n", |
8831 | + dentry, err); | |
027c5e7a | 8832 | + } |
e49829fe | 8833 | + goto out_inval; |
1facf9fc | 8834 | + |
4f0767ce | 8835 | +out_dgrade: |
1facf9fc | 8836 | + di_downgrade_lock(dentry, AuLock_IR); |
e49829fe | 8837 | +out_inval: |
1facf9fc | 8838 | + aufs_read_unlock(dentry, AuLock_IR); |
8839 | + AuTraceErr(err); | |
8840 | + valid = !err; | |
e49829fe | 8841 | +out: |
027c5e7a | 8842 | + if (!valid) { |
523b37e3 | 8843 | + AuDbg("%pd invalid, %d\n", dentry, valid); |
027c5e7a AM |
8844 | + d_drop(dentry); |
8845 | + } | |
1facf9fc | 8846 | + return valid; |
8847 | +} | |
8848 | + | |
8849 | +static void aufs_d_release(struct dentry *dentry) | |
8850 | +{ | |
027c5e7a | 8851 | + if (au_di(dentry)) { |
4a4d8108 AM |
8852 | + au_di_fin(dentry); |
8853 | + au_hn_di_reinit(dentry); | |
1facf9fc | 8854 | + } |
1facf9fc | 8855 | +} |
8856 | + | |
4a4d8108 | 8857 | +const struct dentry_operations aufs_dop = { |
c06a8ce3 AM |
8858 | + .d_revalidate = aufs_d_revalidate, |
8859 | + .d_weak_revalidate = aufs_d_revalidate, | |
8860 | + .d_release = aufs_d_release | |
1facf9fc | 8861 | +}; |
79b8bda9 AM |
8862 | + |
8863 | +/* aufs_dop without d_revalidate */ | |
8864 | +const struct dentry_operations aufs_dop_noreval = { | |
8865 | + .d_release = aufs_d_release | |
8866 | +}; | |
7f207e10 AM |
8867 | diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h |
8868 | --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 8869 | +++ linux/fs/aufs/dentry.h 2017-05-06 22:16:52.778220093 +0200 |
f0c0a007 | 8870 | @@ -0,0 +1,255 @@ |
1facf9fc | 8871 | +/* |
a2654f78 | 8872 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 8873 | + * |
8874 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8875 | + * it under the terms of the GNU General Public License as published by | |
8876 | + * the Free Software Foundation; either version 2 of the License, or | |
8877 | + * (at your option) any later version. | |
dece6358 AM |
8878 | + * |
8879 | + * This program is distributed in the hope that it will be useful, | |
8880 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8881 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8882 | + * GNU General Public License for more details. | |
8883 | + * | |
8884 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8885 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8886 | + */ |
8887 | + | |
8888 | +/* | |
8889 | + * lookup and dentry operations | |
8890 | + */ | |
8891 | + | |
8892 | +#ifndef __AUFS_DENTRY_H__ | |
8893 | +#define __AUFS_DENTRY_H__ | |
8894 | + | |
8895 | +#ifdef __KERNEL__ | |
8896 | + | |
dece6358 | 8897 | +#include <linux/dcache.h> |
1facf9fc | 8898 | +#include "rwsem.h" |
8899 | + | |
1facf9fc | 8900 | +struct au_hdentry { |
8901 | + struct dentry *hd_dentry; | |
027c5e7a | 8902 | + aufs_bindex_t hd_id; |
1facf9fc | 8903 | +}; |
8904 | + | |
8905 | +struct au_dinfo { | |
8906 | + atomic_t di_generation; | |
8907 | + | |
dece6358 | 8908 | + struct au_rwsem di_rwsem; |
5afbbe0d | 8909 | + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq; |
38d290e6 | 8910 | + unsigned char di_tmpfile; /* to allow the different name */ |
f0c0a007 AM |
8911 | + union { |
8912 | + struct au_hdentry *di_hdentry; | |
8913 | + struct llist_node di_lnode; /* delayed free */ | |
8914 | + }; | |
4a4d8108 | 8915 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 8916 | + |
8917 | +/* ---------------------------------------------------------------------- */ | |
8918 | + | |
5afbbe0d AM |
8919 | +/* flags for au_lkup_dentry() */ |
8920 | +#define AuLkup_ALLOW_NEG 1 | |
8921 | +#define AuLkup_IGNORE_PERM (1 << 1) | |
8922 | +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name) | |
8923 | +#define au_fset_lkup(flags, name) \ | |
8924 | + do { (flags) |= AuLkup_##name; } while (0) | |
8925 | +#define au_fclr_lkup(flags, name) \ | |
8926 | + do { (flags) &= ~AuLkup_##name; } while (0) | |
8927 | + | |
8928 | +/* ---------------------------------------------------------------------- */ | |
8929 | + | |
1facf9fc | 8930 | +/* dentry.c */ |
79b8bda9 | 8931 | +extern const struct dentry_operations aufs_dop, aufs_dop_noreval; |
1facf9fc | 8932 | +struct au_branch; |
076b876e | 8933 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent); |
1facf9fc | 8934 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, |
8935 | + struct dentry *h_parent, struct au_branch *br); | |
8936 | + | |
5afbbe0d AM |
8937 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop, |
8938 | + unsigned int flags); | |
86dc4139 | 8939 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh); |
027c5e7a | 8940 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent); |
1facf9fc | 8941 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen); |
79b8bda9 | 8942 | +void au_refresh_dop(struct dentry *dentry, int force_reval); |
1facf9fc | 8943 | + |
8944 | +/* dinfo.c */ | |
4a4d8108 | 8945 | +void au_di_init_once(void *_di); |
027c5e7a AM |
8946 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc); |
8947 | +void au_di_free(struct au_dinfo *dinfo); | |
8948 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b); | |
8949 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src); | |
4a4d8108 AM |
8950 | +int au_di_init(struct dentry *dentry); |
8951 | +void au_di_fin(struct dentry *dentry); | |
e2f27e51 | 8952 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink); |
1facf9fc | 8953 | + |
8954 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc); | |
8955 | +void di_read_unlock(struct dentry *d, int flags); | |
8956 | +void di_downgrade_lock(struct dentry *d, int flags); | |
8957 | +void di_write_lock(struct dentry *d, unsigned int lsc); | |
8958 | +void di_write_unlock(struct dentry *d); | |
8959 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir); | |
8960 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir); | |
8961 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2); | |
8962 | + | |
8963 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex); | |
2cbb1c4b | 8964 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex); |
1facf9fc | 8965 | +aufs_bindex_t au_dbtail(struct dentry *dentry); |
8966 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry); | |
8967 | + | |
8968 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
8969 | + struct dentry *h_dentry); | |
027c5e7a AM |
8970 | +int au_digen_test(struct dentry *dentry, unsigned int sigen); |
8971 | +int au_dbrange_test(struct dentry *dentry); | |
1facf9fc | 8972 | +void au_update_digen(struct dentry *dentry); |
8973 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero); | |
5afbbe0d AM |
8974 | +void au_update_dbtop(struct dentry *dentry); |
8975 | +void au_update_dbbot(struct dentry *dentry); | |
1facf9fc | 8976 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry); |
8977 | + | |
8978 | +/* ---------------------------------------------------------------------- */ | |
8979 | + | |
8980 | +static inline struct au_dinfo *au_di(struct dentry *dentry) | |
8981 | +{ | |
8982 | + return dentry->d_fsdata; | |
8983 | +} | |
8984 | + | |
8985 | +/* ---------------------------------------------------------------------- */ | |
8986 | + | |
8987 | +/* lock subclass for dinfo */ | |
8988 | +enum { | |
8989 | + AuLsc_DI_CHILD, /* child first */ | |
4a4d8108 | 8990 | + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */ |
1facf9fc | 8991 | + AuLsc_DI_CHILD3, /* copyup dirs */ |
8992 | + AuLsc_DI_PARENT, | |
8993 | + AuLsc_DI_PARENT2, | |
027c5e7a AM |
8994 | + AuLsc_DI_PARENT3, |
8995 | + AuLsc_DI_TMP /* temp for replacing dinfo */ | |
1facf9fc | 8996 | +}; |
8997 | + | |
8998 | +/* | |
8999 | + * di_read_lock_child, di_write_lock_child, | |
9000 | + * di_read_lock_child2, di_write_lock_child2, | |
9001 | + * di_read_lock_child3, di_write_lock_child3, | |
9002 | + * di_read_lock_parent, di_write_lock_parent, | |
9003 | + * di_read_lock_parent2, di_write_lock_parent2, | |
9004 | + * di_read_lock_parent3, di_write_lock_parent3, | |
9005 | + */ | |
9006 | +#define AuReadLockFunc(name, lsc) \ | |
9007 | +static inline void di_read_lock_##name(struct dentry *d, int flags) \ | |
9008 | +{ di_read_lock(d, flags, AuLsc_DI_##lsc); } | |
9009 | + | |
9010 | +#define AuWriteLockFunc(name, lsc) \ | |
9011 | +static inline void di_write_lock_##name(struct dentry *d) \ | |
9012 | +{ di_write_lock(d, AuLsc_DI_##lsc); } | |
9013 | + | |
9014 | +#define AuRWLockFuncs(name, lsc) \ | |
9015 | + AuReadLockFunc(name, lsc) \ | |
9016 | + AuWriteLockFunc(name, lsc) | |
9017 | + | |
9018 | +AuRWLockFuncs(child, CHILD); | |
9019 | +AuRWLockFuncs(child2, CHILD2); | |
9020 | +AuRWLockFuncs(child3, CHILD3); | |
9021 | +AuRWLockFuncs(parent, PARENT); | |
9022 | +AuRWLockFuncs(parent2, PARENT2); | |
9023 | +AuRWLockFuncs(parent3, PARENT3); | |
9024 | + | |
9025 | +#undef AuReadLockFunc | |
9026 | +#undef AuWriteLockFunc | |
9027 | +#undef AuRWLockFuncs | |
9028 | + | |
9029 | +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem) | |
dece6358 AM |
9030 | +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem) |
9031 | +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem) | |
1facf9fc | 9032 | + |
9033 | +/* ---------------------------------------------------------------------- */ | |
9034 | + | |
9035 | +/* todo: memory barrier? */ | |
9036 | +static inline unsigned int au_digen(struct dentry *d) | |
9037 | +{ | |
9038 | + return atomic_read(&au_di(d)->di_generation); | |
9039 | +} | |
9040 | + | |
9041 | +static inline void au_h_dentry_init(struct au_hdentry *hdentry) | |
9042 | +{ | |
9043 | + hdentry->hd_dentry = NULL; | |
9044 | +} | |
9045 | + | |
5afbbe0d AM |
9046 | +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di, |
9047 | + aufs_bindex_t bindex) | |
9048 | +{ | |
9049 | + return di->di_hdentry + bindex; | |
9050 | +} | |
9051 | + | |
1facf9fc | 9052 | +static inline void au_hdput(struct au_hdentry *hd) |
9053 | +{ | |
4a4d8108 AM |
9054 | + if (hd) |
9055 | + dput(hd->hd_dentry); | |
1facf9fc | 9056 | +} |
9057 | + | |
5afbbe0d | 9058 | +static inline aufs_bindex_t au_dbtop(struct dentry *dentry) |
1facf9fc | 9059 | +{ |
1308ab2a | 9060 | + DiMustAnyLock(dentry); |
5afbbe0d | 9061 | + return au_di(dentry)->di_btop; |
1facf9fc | 9062 | +} |
9063 | + | |
5afbbe0d | 9064 | +static inline aufs_bindex_t au_dbbot(struct dentry *dentry) |
1facf9fc | 9065 | +{ |
1308ab2a | 9066 | + DiMustAnyLock(dentry); |
5afbbe0d | 9067 | + return au_di(dentry)->di_bbot; |
1facf9fc | 9068 | +} |
9069 | + | |
9070 | +static inline aufs_bindex_t au_dbwh(struct dentry *dentry) | |
9071 | +{ | |
1308ab2a | 9072 | + DiMustAnyLock(dentry); |
1facf9fc | 9073 | + return au_di(dentry)->di_bwh; |
9074 | +} | |
9075 | + | |
9076 | +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry) | |
9077 | +{ | |
1308ab2a | 9078 | + DiMustAnyLock(dentry); |
1facf9fc | 9079 | + return au_di(dentry)->di_bdiropq; |
9080 | +} | |
9081 | + | |
9082 | +/* todo: hard/soft set? */ | |
5afbbe0d | 9083 | +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex) |
1facf9fc | 9084 | +{ |
1308ab2a | 9085 | + DiMustWriteLock(dentry); |
5afbbe0d | 9086 | + au_di(dentry)->di_btop = bindex; |
1facf9fc | 9087 | +} |
9088 | + | |
5afbbe0d | 9089 | +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex) |
1facf9fc | 9090 | +{ |
1308ab2a | 9091 | + DiMustWriteLock(dentry); |
5afbbe0d | 9092 | + au_di(dentry)->di_bbot = bindex; |
1facf9fc | 9093 | +} |
9094 | + | |
9095 | +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex) | |
9096 | +{ | |
1308ab2a | 9097 | + DiMustWriteLock(dentry); |
5afbbe0d | 9098 | + /* dbwh can be outside of btop - bbot range */ |
1facf9fc | 9099 | + au_di(dentry)->di_bwh = bindex; |
9100 | +} | |
9101 | + | |
9102 | +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex) | |
9103 | +{ | |
1308ab2a | 9104 | + DiMustWriteLock(dentry); |
1facf9fc | 9105 | + au_di(dentry)->di_bdiropq = bindex; |
9106 | +} | |
9107 | + | |
9108 | +/* ---------------------------------------------------------------------- */ | |
9109 | + | |
4a4d8108 | 9110 | +#ifdef CONFIG_AUFS_HNOTIFY |
1facf9fc | 9111 | +static inline void au_digen_dec(struct dentry *d) |
9112 | +{ | |
e49829fe | 9113 | + atomic_dec(&au_di(d)->di_generation); |
1facf9fc | 9114 | +} |
9115 | + | |
4a4d8108 | 9116 | +static inline void au_hn_di_reinit(struct dentry *dentry) |
1facf9fc | 9117 | +{ |
9118 | + dentry->d_fsdata = NULL; | |
9119 | +} | |
9120 | +#else | |
4a4d8108 AM |
9121 | +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused) |
9122 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
1facf9fc | 9123 | + |
9124 | +#endif /* __KERNEL__ */ | |
9125 | +#endif /* __AUFS_DENTRY_H__ */ | |
7f207e10 AM |
9126 | diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c |
9127 | --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 9128 | +++ linux/fs/aufs/dinfo.c 2017-05-06 22:16:52.778220093 +0200 |
e2f27e51 | 9129 | @@ -0,0 +1,553 @@ |
1facf9fc | 9130 | +/* |
a2654f78 | 9131 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 9132 | + * |
9133 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9134 | + * it under the terms of the GNU General Public License as published by | |
9135 | + * the Free Software Foundation; either version 2 of the License, or | |
9136 | + * (at your option) any later version. | |
dece6358 AM |
9137 | + * |
9138 | + * This program is distributed in the hope that it will be useful, | |
9139 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9140 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9141 | + * GNU General Public License for more details. | |
9142 | + * | |
9143 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9144 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9145 | + */ |
9146 | + | |
9147 | +/* | |
9148 | + * dentry private data | |
9149 | + */ | |
9150 | + | |
9151 | +#include "aufs.h" | |
9152 | + | |
e49829fe | 9153 | +void au_di_init_once(void *_dinfo) |
4a4d8108 | 9154 | +{ |
e49829fe | 9155 | + struct au_dinfo *dinfo = _dinfo; |
4a4d8108 | 9156 | + |
e49829fe | 9157 | + au_rw_init(&dinfo->di_rwsem); |
4a4d8108 AM |
9158 | +} |
9159 | + | |
027c5e7a | 9160 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc) |
1facf9fc | 9161 | +{ |
9162 | + struct au_dinfo *dinfo; | |
027c5e7a | 9163 | + int nbr, i; |
1facf9fc | 9164 | + |
9165 | + dinfo = au_cache_alloc_dinfo(); | |
9166 | + if (unlikely(!dinfo)) | |
9167 | + goto out; | |
9168 | + | |
5afbbe0d | 9169 | + nbr = au_sbbot(sb) + 1; |
1facf9fc | 9170 | + if (nbr <= 0) |
9171 | + nbr = 1; | |
9172 | + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS); | |
027c5e7a AM |
9173 | + if (dinfo->di_hdentry) { |
9174 | + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc); | |
5afbbe0d AM |
9175 | + dinfo->di_btop = -1; |
9176 | + dinfo->di_bbot = -1; | |
027c5e7a AM |
9177 | + dinfo->di_bwh = -1; |
9178 | + dinfo->di_bdiropq = -1; | |
38d290e6 | 9179 | + dinfo->di_tmpfile = 0; |
027c5e7a AM |
9180 | + for (i = 0; i < nbr; i++) |
9181 | + dinfo->di_hdentry[i].hd_id = -1; | |
9182 | + goto out; | |
9183 | + } | |
1facf9fc | 9184 | + |
f0c0a007 | 9185 | + au_cache_dfree_dinfo(dinfo); |
027c5e7a AM |
9186 | + dinfo = NULL; |
9187 | + | |
4f0767ce | 9188 | +out: |
027c5e7a | 9189 | + return dinfo; |
1facf9fc | 9190 | +} |
9191 | + | |
027c5e7a | 9192 | +void au_di_free(struct au_dinfo *dinfo) |
4a4d8108 | 9193 | +{ |
4a4d8108 | 9194 | + struct au_hdentry *p; |
5afbbe0d | 9195 | + aufs_bindex_t bbot, bindex; |
4a4d8108 AM |
9196 | + |
9197 | + /* dentry may not be revalidated */ | |
5afbbe0d | 9198 | + bindex = dinfo->di_btop; |
4a4d8108 | 9199 | + if (bindex >= 0) { |
5afbbe0d AM |
9200 | + bbot = dinfo->di_bbot; |
9201 | + p = au_hdentry(dinfo, bindex); | |
9202 | + while (bindex++ <= bbot) | |
4a4d8108 AM |
9203 | + au_hdput(p++); |
9204 | + } | |
f0c0a007 AM |
9205 | + au_delayed_kfree(dinfo->di_hdentry); |
9206 | + au_cache_dfree_dinfo(dinfo); | |
027c5e7a AM |
9207 | +} |
9208 | + | |
9209 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b) | |
9210 | +{ | |
9211 | + struct au_hdentry *p; | |
9212 | + aufs_bindex_t bi; | |
9213 | + | |
9214 | + AuRwMustWriteLock(&a->di_rwsem); | |
9215 | + AuRwMustWriteLock(&b->di_rwsem); | |
9216 | + | |
9217 | +#define DiSwap(v, name) \ | |
9218 | + do { \ | |
9219 | + v = a->di_##name; \ | |
9220 | + a->di_##name = b->di_##name; \ | |
9221 | + b->di_##name = v; \ | |
9222 | + } while (0) | |
9223 | + | |
9224 | + DiSwap(p, hdentry); | |
5afbbe0d AM |
9225 | + DiSwap(bi, btop); |
9226 | + DiSwap(bi, bbot); | |
027c5e7a AM |
9227 | + DiSwap(bi, bwh); |
9228 | + DiSwap(bi, bdiropq); | |
9229 | + /* smp_mb(); */ | |
9230 | + | |
9231 | +#undef DiSwap | |
9232 | +} | |
9233 | + | |
9234 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src) | |
9235 | +{ | |
9236 | + AuRwMustWriteLock(&dst->di_rwsem); | |
9237 | + AuRwMustWriteLock(&src->di_rwsem); | |
9238 | + | |
5afbbe0d AM |
9239 | + dst->di_btop = src->di_btop; |
9240 | + dst->di_bbot = src->di_bbot; | |
027c5e7a AM |
9241 | + dst->di_bwh = src->di_bwh; |
9242 | + dst->di_bdiropq = src->di_bdiropq; | |
9243 | + /* smp_mb(); */ | |
9244 | +} | |
9245 | + | |
9246 | +int au_di_init(struct dentry *dentry) | |
9247 | +{ | |
9248 | + int err; | |
9249 | + struct super_block *sb; | |
9250 | + struct au_dinfo *dinfo; | |
9251 | + | |
9252 | + err = 0; | |
9253 | + sb = dentry->d_sb; | |
9254 | + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD); | |
9255 | + if (dinfo) { | |
9256 | + atomic_set(&dinfo->di_generation, au_sigen(sb)); | |
9257 | + /* smp_mb(); */ /* atomic_set */ | |
9258 | + dentry->d_fsdata = dinfo; | |
9259 | + } else | |
9260 | + err = -ENOMEM; | |
9261 | + | |
9262 | + return err; | |
9263 | +} | |
9264 | + | |
9265 | +void au_di_fin(struct dentry *dentry) | |
9266 | +{ | |
9267 | + struct au_dinfo *dinfo; | |
9268 | + | |
9269 | + dinfo = au_di(dentry); | |
9270 | + AuRwDestroy(&dinfo->di_rwsem); | |
9271 | + au_di_free(dinfo); | |
4a4d8108 AM |
9272 | +} |
9273 | + | |
e2f27e51 | 9274 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink) |
1facf9fc | 9275 | +{ |
9276 | + int err, sz; | |
9277 | + struct au_hdentry *hdp; | |
9278 | + | |
1308ab2a | 9279 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
9280 | + | |
1facf9fc | 9281 | + err = -ENOMEM; |
5afbbe0d | 9282 | + sz = sizeof(*hdp) * (dinfo->di_bbot + 1); |
1facf9fc | 9283 | + if (!sz) |
9284 | + sz = sizeof(*hdp); | |
e2f27e51 AM |
9285 | + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS, |
9286 | + may_shrink); | |
1facf9fc | 9287 | + if (hdp) { |
9288 | + dinfo->di_hdentry = hdp; | |
9289 | + err = 0; | |
9290 | + } | |
9291 | + | |
9292 | + return err; | |
9293 | +} | |
9294 | + | |
9295 | +/* ---------------------------------------------------------------------- */ | |
9296 | + | |
9297 | +static void do_ii_write_lock(struct inode *inode, unsigned int lsc) | |
9298 | +{ | |
9299 | + switch (lsc) { | |
9300 | + case AuLsc_DI_CHILD: | |
9301 | + ii_write_lock_child(inode); | |
9302 | + break; | |
9303 | + case AuLsc_DI_CHILD2: | |
9304 | + ii_write_lock_child2(inode); | |
9305 | + break; | |
9306 | + case AuLsc_DI_CHILD3: | |
9307 | + ii_write_lock_child3(inode); | |
9308 | + break; | |
9309 | + case AuLsc_DI_PARENT: | |
9310 | + ii_write_lock_parent(inode); | |
9311 | + break; | |
9312 | + case AuLsc_DI_PARENT2: | |
9313 | + ii_write_lock_parent2(inode); | |
9314 | + break; | |
9315 | + case AuLsc_DI_PARENT3: | |
9316 | + ii_write_lock_parent3(inode); | |
9317 | + break; | |
9318 | + default: | |
9319 | + BUG(); | |
9320 | + } | |
9321 | +} | |
9322 | + | |
9323 | +static void do_ii_read_lock(struct inode *inode, unsigned int lsc) | |
9324 | +{ | |
9325 | + switch (lsc) { | |
9326 | + case AuLsc_DI_CHILD: | |
9327 | + ii_read_lock_child(inode); | |
9328 | + break; | |
9329 | + case AuLsc_DI_CHILD2: | |
9330 | + ii_read_lock_child2(inode); | |
9331 | + break; | |
9332 | + case AuLsc_DI_CHILD3: | |
9333 | + ii_read_lock_child3(inode); | |
9334 | + break; | |
9335 | + case AuLsc_DI_PARENT: | |
9336 | + ii_read_lock_parent(inode); | |
9337 | + break; | |
9338 | + case AuLsc_DI_PARENT2: | |
9339 | + ii_read_lock_parent2(inode); | |
9340 | + break; | |
9341 | + case AuLsc_DI_PARENT3: | |
9342 | + ii_read_lock_parent3(inode); | |
9343 | + break; | |
9344 | + default: | |
9345 | + BUG(); | |
9346 | + } | |
9347 | +} | |
9348 | + | |
9349 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc) | |
9350 | +{ | |
5527c038 JR |
9351 | + struct inode *inode; |
9352 | + | |
dece6358 | 9353 | + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9354 | + if (d_really_is_positive(d)) { |
9355 | + inode = d_inode(d); | |
1facf9fc | 9356 | + if (au_ftest_lock(flags, IW)) |
5527c038 | 9357 | + do_ii_write_lock(inode, lsc); |
1facf9fc | 9358 | + else if (au_ftest_lock(flags, IR)) |
5527c038 | 9359 | + do_ii_read_lock(inode, lsc); |
1facf9fc | 9360 | + } |
9361 | +} | |
9362 | + | |
9363 | +void di_read_unlock(struct dentry *d, int flags) | |
9364 | +{ | |
5527c038 JR |
9365 | + struct inode *inode; |
9366 | + | |
9367 | + if (d_really_is_positive(d)) { | |
9368 | + inode = d_inode(d); | |
027c5e7a AM |
9369 | + if (au_ftest_lock(flags, IW)) { |
9370 | + au_dbg_verify_dinode(d); | |
5527c038 | 9371 | + ii_write_unlock(inode); |
027c5e7a AM |
9372 | + } else if (au_ftest_lock(flags, IR)) { |
9373 | + au_dbg_verify_dinode(d); | |
5527c038 | 9374 | + ii_read_unlock(inode); |
027c5e7a | 9375 | + } |
1facf9fc | 9376 | + } |
dece6358 | 9377 | + au_rw_read_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9378 | +} |
9379 | + | |
9380 | +void di_downgrade_lock(struct dentry *d, int flags) | |
9381 | +{ | |
5527c038 JR |
9382 | + if (d_really_is_positive(d) && au_ftest_lock(flags, IR)) |
9383 | + ii_downgrade_lock(d_inode(d)); | |
dece6358 | 9384 | + au_rw_dgrade_lock(&au_di(d)->di_rwsem); |
1facf9fc | 9385 | +} |
9386 | + | |
9387 | +void di_write_lock(struct dentry *d, unsigned int lsc) | |
9388 | +{ | |
dece6358 | 9389 | + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9390 | + if (d_really_is_positive(d)) |
9391 | + do_ii_write_lock(d_inode(d), lsc); | |
1facf9fc | 9392 | +} |
9393 | + | |
9394 | +void di_write_unlock(struct dentry *d) | |
9395 | +{ | |
027c5e7a | 9396 | + au_dbg_verify_dinode(d); |
5527c038 JR |
9397 | + if (d_really_is_positive(d)) |
9398 | + ii_write_unlock(d_inode(d)); | |
dece6358 | 9399 | + au_rw_write_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9400 | +} |
9401 | + | |
9402 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir) | |
9403 | +{ | |
9404 | + AuDebugOn(d1 == d2 | |
5527c038 | 9405 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9406 | + || d1->d_sb != d2->d_sb); |
9407 | + | |
521ced18 JR |
9408 | + if ((isdir && au_test_subdir(d1, d2)) |
9409 | + || d1 < d2) { | |
1facf9fc | 9410 | + di_write_lock_child(d1); |
9411 | + di_write_lock_child2(d2); | |
9412 | + } else { | |
1facf9fc | 9413 | + di_write_lock_child(d2); |
9414 | + di_write_lock_child2(d1); | |
9415 | + } | |
9416 | +} | |
9417 | + | |
9418 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir) | |
9419 | +{ | |
9420 | + AuDebugOn(d1 == d2 | |
5527c038 | 9421 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9422 | + || d1->d_sb != d2->d_sb); |
9423 | + | |
521ced18 JR |
9424 | + if ((isdir && au_test_subdir(d1, d2)) |
9425 | + || d1 < d2) { | |
1facf9fc | 9426 | + di_write_lock_parent(d1); |
9427 | + di_write_lock_parent2(d2); | |
9428 | + } else { | |
1facf9fc | 9429 | + di_write_lock_parent(d2); |
9430 | + di_write_lock_parent2(d1); | |
9431 | + } | |
9432 | +} | |
9433 | + | |
9434 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2) | |
9435 | +{ | |
9436 | + di_write_unlock(d1); | |
5527c038 | 9437 | + if (d_inode(d1) == d_inode(d2)) |
dece6358 | 9438 | + au_rw_write_unlock(&au_di(d2)->di_rwsem); |
1facf9fc | 9439 | + else |
9440 | + di_write_unlock(d2); | |
9441 | +} | |
9442 | + | |
9443 | +/* ---------------------------------------------------------------------- */ | |
9444 | + | |
9445 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex) | |
9446 | +{ | |
9447 | + struct dentry *d; | |
9448 | + | |
1308ab2a | 9449 | + DiMustAnyLock(dentry); |
9450 | + | |
5afbbe0d | 9451 | + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry)) |
1facf9fc | 9452 | + return NULL; |
9453 | + AuDebugOn(bindex < 0); | |
5afbbe0d | 9454 | + d = au_hdentry(au_di(dentry), bindex)->hd_dentry; |
c1595e42 | 9455 | + AuDebugOn(d && au_dcount(d) <= 0); |
1facf9fc | 9456 | + return d; |
9457 | +} | |
9458 | + | |
2cbb1c4b JR |
9459 | +/* |
9460 | + * extended version of au_h_dptr(). | |
38d290e6 JR |
9461 | + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or |
9462 | + * error. | |
2cbb1c4b JR |
9463 | + */ |
9464 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex) | |
9465 | +{ | |
9466 | + struct dentry *h_dentry; | |
9467 | + struct inode *inode, *h_inode; | |
9468 | + | |
5527c038 | 9469 | + AuDebugOn(d_really_is_negative(dentry)); |
2cbb1c4b JR |
9470 | + |
9471 | + h_dentry = NULL; | |
5afbbe0d AM |
9472 | + if (au_dbtop(dentry) <= bindex |
9473 | + && bindex <= au_dbbot(dentry)) | |
2cbb1c4b | 9474 | + h_dentry = au_h_dptr(dentry, bindex); |
38d290e6 | 9475 | + if (h_dentry && !au_d_linkable(h_dentry)) { |
2cbb1c4b JR |
9476 | + dget(h_dentry); |
9477 | + goto out; /* success */ | |
9478 | + } | |
9479 | + | |
5527c038 | 9480 | + inode = d_inode(dentry); |
5afbbe0d AM |
9481 | + AuDebugOn(bindex < au_ibtop(inode)); |
9482 | + AuDebugOn(au_ibbot(inode) < bindex); | |
2cbb1c4b JR |
9483 | + h_inode = au_h_iptr(inode, bindex); |
9484 | + h_dentry = d_find_alias(h_inode); | |
9485 | + if (h_dentry) { | |
9486 | + if (!IS_ERR(h_dentry)) { | |
38d290e6 | 9487 | + if (!au_d_linkable(h_dentry)) |
2cbb1c4b JR |
9488 | + goto out; /* success */ |
9489 | + dput(h_dentry); | |
9490 | + } else | |
9491 | + goto out; | |
9492 | + } | |
9493 | + | |
9494 | + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) { | |
9495 | + h_dentry = au_plink_lkup(inode, bindex); | |
9496 | + AuDebugOn(!h_dentry); | |
9497 | + if (!IS_ERR(h_dentry)) { | |
9498 | + if (!au_d_hashed_positive(h_dentry)) | |
9499 | + goto out; /* success */ | |
9500 | + dput(h_dentry); | |
9501 | + h_dentry = NULL; | |
9502 | + } | |
9503 | + } | |
9504 | + | |
9505 | +out: | |
9506 | + AuDbgDentry(h_dentry); | |
9507 | + return h_dentry; | |
9508 | +} | |
9509 | + | |
1facf9fc | 9510 | +aufs_bindex_t au_dbtail(struct dentry *dentry) |
9511 | +{ | |
5afbbe0d | 9512 | + aufs_bindex_t bbot, bwh; |
1facf9fc | 9513 | + |
5afbbe0d AM |
9514 | + bbot = au_dbbot(dentry); |
9515 | + if (0 <= bbot) { | |
1facf9fc | 9516 | + bwh = au_dbwh(dentry); |
9517 | + if (!bwh) | |
9518 | + return bwh; | |
5afbbe0d | 9519 | + if (0 < bwh && bwh < bbot) |
1facf9fc | 9520 | + return bwh - 1; |
9521 | + } | |
5afbbe0d | 9522 | + return bbot; |
1facf9fc | 9523 | +} |
9524 | + | |
9525 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry) | |
9526 | +{ | |
5afbbe0d | 9527 | + aufs_bindex_t bbot, bopq; |
1facf9fc | 9528 | + |
5afbbe0d AM |
9529 | + bbot = au_dbtail(dentry); |
9530 | + if (0 <= bbot) { | |
1facf9fc | 9531 | + bopq = au_dbdiropq(dentry); |
5afbbe0d AM |
9532 | + if (0 <= bopq && bopq < bbot) |
9533 | + bbot = bopq; | |
1facf9fc | 9534 | + } |
5afbbe0d | 9535 | + return bbot; |
1facf9fc | 9536 | +} |
9537 | + | |
9538 | +/* ---------------------------------------------------------------------- */ | |
9539 | + | |
9540 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9541 | + struct dentry *h_dentry) | |
9542 | +{ | |
5afbbe0d AM |
9543 | + struct au_dinfo *dinfo; |
9544 | + struct au_hdentry *hd; | |
027c5e7a | 9545 | + struct au_branch *br; |
1facf9fc | 9546 | + |
1308ab2a | 9547 | + DiMustWriteLock(dentry); |
9548 | + | |
5afbbe0d AM |
9549 | + dinfo = au_di(dentry); |
9550 | + hd = au_hdentry(dinfo, bindex); | |
4a4d8108 | 9551 | + au_hdput(hd); |
1facf9fc | 9552 | + hd->hd_dentry = h_dentry; |
027c5e7a AM |
9553 | + if (h_dentry) { |
9554 | + br = au_sbr(dentry->d_sb, bindex); | |
9555 | + hd->hd_id = br->br_id; | |
9556 | + } | |
9557 | +} | |
9558 | + | |
9559 | +int au_dbrange_test(struct dentry *dentry) | |
9560 | +{ | |
9561 | + int err; | |
5afbbe0d | 9562 | + aufs_bindex_t btop, bbot; |
027c5e7a AM |
9563 | + |
9564 | + err = 0; | |
5afbbe0d AM |
9565 | + btop = au_dbtop(dentry); |
9566 | + bbot = au_dbbot(dentry); | |
9567 | + if (btop >= 0) | |
9568 | + AuDebugOn(bbot < 0 && btop > bbot); | |
027c5e7a AM |
9569 | + else { |
9570 | + err = -EIO; | |
5afbbe0d | 9571 | + AuDebugOn(bbot >= 0); |
027c5e7a AM |
9572 | + } |
9573 | + | |
9574 | + return err; | |
9575 | +} | |
9576 | + | |
9577 | +int au_digen_test(struct dentry *dentry, unsigned int sigen) | |
9578 | +{ | |
9579 | + int err; | |
9580 | + | |
9581 | + err = 0; | |
9582 | + if (unlikely(au_digen(dentry) != sigen | |
5527c038 | 9583 | + || au_iigen_test(d_inode(dentry), sigen))) |
027c5e7a AM |
9584 | + err = -EIO; |
9585 | + | |
9586 | + return err; | |
1facf9fc | 9587 | +} |
9588 | + | |
9589 | +void au_update_digen(struct dentry *dentry) | |
9590 | +{ | |
9591 | + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb)); | |
9592 | + /* smp_mb(); */ /* atomic_set */ | |
9593 | +} | |
9594 | + | |
9595 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero) | |
9596 | +{ | |
9597 | + struct au_dinfo *dinfo; | |
9598 | + struct dentry *h_d; | |
4a4d8108 | 9599 | + struct au_hdentry *hdp; |
5afbbe0d | 9600 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 9601 | + |
1308ab2a | 9602 | + DiMustWriteLock(dentry); |
9603 | + | |
1facf9fc | 9604 | + dinfo = au_di(dentry); |
5afbbe0d | 9605 | + if (!dinfo || dinfo->di_btop < 0) |
1facf9fc | 9606 | + return; |
9607 | + | |
9608 | + if (do_put_zero) { | |
5afbbe0d AM |
9609 | + bbot = dinfo->di_bbot; |
9610 | + bindex = dinfo->di_btop; | |
9611 | + hdp = au_hdentry(dinfo, bindex); | |
9612 | + for (; bindex <= bbot; bindex++, hdp++) { | |
9613 | + h_d = hdp->hd_dentry; | |
5527c038 | 9614 | + if (h_d && d_is_negative(h_d)) |
1facf9fc | 9615 | + au_set_h_dptr(dentry, bindex, NULL); |
9616 | + } | |
9617 | + } | |
9618 | + | |
5afbbe0d AM |
9619 | + dinfo->di_btop = 0; |
9620 | + hdp = au_hdentry(dinfo, dinfo->di_btop); | |
9621 | + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++) | |
9622 | + if (hdp->hd_dentry) | |
1facf9fc | 9623 | + break; |
5afbbe0d AM |
9624 | + if (dinfo->di_btop > dinfo->di_bbot) { |
9625 | + dinfo->di_btop = -1; | |
9626 | + dinfo->di_bbot = -1; | |
1facf9fc | 9627 | + return; |
9628 | + } | |
9629 | + | |
5afbbe0d AM |
9630 | + hdp = au_hdentry(dinfo, dinfo->di_bbot); |
9631 | + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--) | |
9632 | + if (hdp->hd_dentry) | |
1facf9fc | 9633 | + break; |
5afbbe0d | 9634 | + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0); |
1facf9fc | 9635 | +} |
9636 | + | |
5afbbe0d | 9637 | +void au_update_dbtop(struct dentry *dentry) |
1facf9fc | 9638 | +{ |
5afbbe0d | 9639 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 9640 | + struct dentry *h_dentry; |
9641 | + | |
5afbbe0d AM |
9642 | + bbot = au_dbbot(dentry); |
9643 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) { | |
1facf9fc | 9644 | + h_dentry = au_h_dptr(dentry, bindex); |
9645 | + if (!h_dentry) | |
9646 | + continue; | |
5527c038 | 9647 | + if (d_is_positive(h_dentry)) { |
5afbbe0d | 9648 | + au_set_dbtop(dentry, bindex); |
1facf9fc | 9649 | + return; |
9650 | + } | |
9651 | + au_set_h_dptr(dentry, bindex, NULL); | |
9652 | + } | |
9653 | +} | |
9654 | + | |
5afbbe0d | 9655 | +void au_update_dbbot(struct dentry *dentry) |
1facf9fc | 9656 | +{ |
5afbbe0d | 9657 | + aufs_bindex_t bindex, btop; |
1facf9fc | 9658 | + struct dentry *h_dentry; |
9659 | + | |
5afbbe0d AM |
9660 | + btop = au_dbtop(dentry); |
9661 | + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) { | |
1facf9fc | 9662 | + h_dentry = au_h_dptr(dentry, bindex); |
9663 | + if (!h_dentry) | |
9664 | + continue; | |
5527c038 | 9665 | + if (d_is_positive(h_dentry)) { |
5afbbe0d | 9666 | + au_set_dbbot(dentry, bindex); |
1facf9fc | 9667 | + return; |
9668 | + } | |
9669 | + au_set_h_dptr(dentry, bindex, NULL); | |
9670 | + } | |
9671 | +} | |
9672 | + | |
9673 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry) | |
9674 | +{ | |
5afbbe0d | 9675 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 9676 | + |
5afbbe0d AM |
9677 | + bbot = au_dbbot(dentry); |
9678 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) | |
1facf9fc | 9679 | + if (au_h_dptr(dentry, bindex) == h_dentry) |
9680 | + return bindex; | |
9681 | + return -1; | |
9682 | +} | |
7f207e10 AM |
9683 | diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c |
9684 | --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 9685 | +++ linux/fs/aufs/dir.c 2017-05-06 22:16:52.778220093 +0200 |
f0c0a007 | 9686 | @@ -0,0 +1,762 @@ |
1facf9fc | 9687 | +/* |
a2654f78 | 9688 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 9689 | + * |
9690 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9691 | + * it under the terms of the GNU General Public License as published by | |
9692 | + * the Free Software Foundation; either version 2 of the License, or | |
9693 | + * (at your option) any later version. | |
dece6358 AM |
9694 | + * |
9695 | + * This program is distributed in the hope that it will be useful, | |
9696 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9697 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9698 | + * GNU General Public License for more details. | |
9699 | + * | |
9700 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9701 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9702 | + */ |
9703 | + | |
9704 | +/* | |
9705 | + * directory operations | |
9706 | + */ | |
9707 | + | |
9708 | +#include <linux/fs_stack.h> | |
9709 | +#include "aufs.h" | |
9710 | + | |
9711 | +void au_add_nlink(struct inode *dir, struct inode *h_dir) | |
9712 | +{ | |
9dbd164d AM |
9713 | + unsigned int nlink; |
9714 | + | |
1facf9fc | 9715 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9716 | + | |
9dbd164d AM |
9717 | + nlink = dir->i_nlink; |
9718 | + nlink += h_dir->i_nlink - 2; | |
1facf9fc | 9719 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9720 | + nlink += 2; |
f6b6e03d | 9721 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 9722 | + /* 0 can happen in revaliding */ |
92d182d2 | 9723 | + set_nlink(dir, nlink); |
1facf9fc | 9724 | +} |
9725 | + | |
9726 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir) | |
9727 | +{ | |
9dbd164d AM |
9728 | + unsigned int nlink; |
9729 | + | |
1facf9fc | 9730 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9731 | + | |
9dbd164d AM |
9732 | + nlink = dir->i_nlink; |
9733 | + nlink -= h_dir->i_nlink - 2; | |
1facf9fc | 9734 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9735 | + nlink -= 2; |
f6b6e03d | 9736 | + smp_mb(); /* for i_nlink */ |
92d182d2 | 9737 | + /* nlink == 0 means the branch-fs is broken */ |
9dbd164d | 9738 | + set_nlink(dir, nlink); |
1facf9fc | 9739 | +} |
9740 | + | |
1308ab2a | 9741 | +loff_t au_dir_size(struct file *file, struct dentry *dentry) |
9742 | +{ | |
9743 | + loff_t sz; | |
5afbbe0d | 9744 | + aufs_bindex_t bindex, bbot; |
1308ab2a | 9745 | + struct file *h_file; |
9746 | + struct dentry *h_dentry; | |
9747 | + | |
9748 | + sz = 0; | |
9749 | + if (file) { | |
2000de60 | 9750 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
1308ab2a | 9751 | + |
5afbbe0d AM |
9752 | + bbot = au_fbbot_dir(file); |
9753 | + for (bindex = au_fbtop(file); | |
9754 | + bindex <= bbot && sz < KMALLOC_MAX_SIZE; | |
1308ab2a | 9755 | + bindex++) { |
4a4d8108 | 9756 | + h_file = au_hf_dir(file, bindex); |
c06a8ce3 AM |
9757 | + if (h_file && file_inode(h_file)) |
9758 | + sz += vfsub_f_size_read(h_file); | |
1308ab2a | 9759 | + } |
9760 | + } else { | |
9761 | + AuDebugOn(!dentry); | |
2000de60 | 9762 | + AuDebugOn(!d_is_dir(dentry)); |
1308ab2a | 9763 | + |
5afbbe0d AM |
9764 | + bbot = au_dbtaildir(dentry); |
9765 | + for (bindex = au_dbtop(dentry); | |
9766 | + bindex <= bbot && sz < KMALLOC_MAX_SIZE; | |
1308ab2a | 9767 | + bindex++) { |
9768 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 JR |
9769 | + if (h_dentry && d_is_positive(h_dentry)) |
9770 | + sz += i_size_read(d_inode(h_dentry)); | |
1308ab2a | 9771 | + } |
9772 | + } | |
9773 | + if (sz < KMALLOC_MAX_SIZE) | |
9774 | + sz = roundup_pow_of_two(sz); | |
9775 | + if (sz > KMALLOC_MAX_SIZE) | |
9776 | + sz = KMALLOC_MAX_SIZE; | |
9777 | + else if (sz < NAME_MAX) { | |
9778 | + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX); | |
9779 | + sz = AUFS_RDBLK_DEF; | |
9780 | + } | |
9781 | + return sz; | |
9782 | +} | |
9783 | + | |
b912730e AM |
9784 | +struct au_dir_ts_arg { |
9785 | + struct dentry *dentry; | |
9786 | + aufs_bindex_t brid; | |
9787 | +}; | |
9788 | + | |
9789 | +static void au_do_dir_ts(void *arg) | |
9790 | +{ | |
9791 | + struct au_dir_ts_arg *a = arg; | |
9792 | + struct au_dtime dt; | |
9793 | + struct path h_path; | |
9794 | + struct inode *dir, *h_dir; | |
9795 | + struct super_block *sb; | |
9796 | + struct au_branch *br; | |
9797 | + struct au_hinode *hdir; | |
9798 | + int err; | |
5afbbe0d | 9799 | + aufs_bindex_t btop, bindex; |
b912730e AM |
9800 | + |
9801 | + sb = a->dentry->d_sb; | |
5527c038 | 9802 | + if (d_really_is_negative(a->dentry)) |
b912730e | 9803 | + goto out; |
5527c038 | 9804 | + /* no dir->i_mutex lock */ |
b95c5147 AM |
9805 | + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */ |
9806 | + | |
5527c038 | 9807 | + dir = d_inode(a->dentry); |
5afbbe0d | 9808 | + btop = au_ibtop(dir); |
b912730e | 9809 | + bindex = au_br_index(sb, a->brid); |
5afbbe0d | 9810 | + if (bindex < btop) |
b912730e AM |
9811 | + goto out_unlock; |
9812 | + | |
9813 | + br = au_sbr(sb, bindex); | |
9814 | + h_path.dentry = au_h_dptr(a->dentry, bindex); | |
9815 | + if (!h_path.dentry) | |
9816 | + goto out_unlock; | |
9817 | + h_path.mnt = au_br_mnt(br); | |
9818 | + au_dtime_store(&dt, a->dentry, &h_path); | |
9819 | + | |
5afbbe0d | 9820 | + br = au_sbr(sb, btop); |
b912730e AM |
9821 | + if (!au_br_writable(br->br_perm)) |
9822 | + goto out_unlock; | |
5afbbe0d | 9823 | + h_path.dentry = au_h_dptr(a->dentry, btop); |
b912730e AM |
9824 | + h_path.mnt = au_br_mnt(br); |
9825 | + err = vfsub_mnt_want_write(h_path.mnt); | |
9826 | + if (err) | |
9827 | + goto out_unlock; | |
5afbbe0d AM |
9828 | + hdir = au_hi(dir, btop); |
9829 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); | |
9830 | + h_dir = au_h_iptr(dir, btop); | |
b912730e AM |
9831 | + if (h_dir->i_nlink |
9832 | + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) { | |
9833 | + dt.dt_h_path = h_path; | |
9834 | + au_dtime_revert(&dt); | |
9835 | + } | |
5afbbe0d | 9836 | + au_hn_inode_unlock(hdir); |
b912730e AM |
9837 | + vfsub_mnt_drop_write(h_path.mnt); |
9838 | + au_cpup_attr_timesizes(dir); | |
9839 | + | |
9840 | +out_unlock: | |
9841 | + aufs_read_unlock(a->dentry, AuLock_DW); | |
9842 | +out: | |
9843 | + dput(a->dentry); | |
9844 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
f0c0a007 | 9845 | + au_delayed_kfree(arg); |
b912730e AM |
9846 | +} |
9847 | + | |
9848 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex) | |
9849 | +{ | |
9850 | + int perm, wkq_err; | |
5afbbe0d | 9851 | + aufs_bindex_t btop; |
b912730e AM |
9852 | + struct au_dir_ts_arg *arg; |
9853 | + struct dentry *dentry; | |
9854 | + struct super_block *sb; | |
9855 | + | |
9856 | + IMustLock(dir); | |
9857 | + | |
9858 | + dentry = d_find_any_alias(dir); | |
9859 | + AuDebugOn(!dentry); | |
9860 | + sb = dentry->d_sb; | |
5afbbe0d AM |
9861 | + btop = au_ibtop(dir); |
9862 | + if (btop == bindex) { | |
b912730e AM |
9863 | + au_cpup_attr_timesizes(dir); |
9864 | + goto out; | |
9865 | + } | |
9866 | + | |
5afbbe0d | 9867 | + perm = au_sbr_perm(sb, btop); |
b912730e AM |
9868 | + if (!au_br_writable(perm)) |
9869 | + goto out; | |
9870 | + | |
9871 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
9872 | + if (!arg) | |
9873 | + goto out; | |
9874 | + | |
9875 | + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */ | |
9876 | + arg->brid = au_sbr_id(sb, bindex); | |
9877 | + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0); | |
9878 | + if (unlikely(wkq_err)) { | |
9879 | + pr_err("wkq %d\n", wkq_err); | |
9880 | + dput(dentry); | |
f0c0a007 | 9881 | + au_delayed_kfree(arg); |
b912730e AM |
9882 | + } |
9883 | + | |
9884 | +out: | |
9885 | + dput(dentry); | |
9886 | +} | |
9887 | + | |
1facf9fc | 9888 | +/* ---------------------------------------------------------------------- */ |
9889 | + | |
9890 | +static int reopen_dir(struct file *file) | |
9891 | +{ | |
9892 | + int err; | |
9893 | + unsigned int flags; | |
5afbbe0d | 9894 | + aufs_bindex_t bindex, btail, btop; |
1facf9fc | 9895 | + struct dentry *dentry, *h_dentry; |
9896 | + struct file *h_file; | |
9897 | + | |
9898 | + /* open all lower dirs */ | |
2000de60 | 9899 | + dentry = file->f_path.dentry; |
5afbbe0d AM |
9900 | + btop = au_dbtop(dentry); |
9901 | + for (bindex = au_fbtop(file); bindex < btop; bindex++) | |
1facf9fc | 9902 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d | 9903 | + au_set_fbtop(file, btop); |
1facf9fc | 9904 | + |
9905 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 9906 | + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--) |
1facf9fc | 9907 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d | 9908 | + au_set_fbbot_dir(file, btail); |
1facf9fc | 9909 | + |
4a4d8108 | 9910 | + flags = vfsub_file_flags(file); |
5afbbe0d | 9911 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 9912 | + h_dentry = au_h_dptr(dentry, bindex); |
9913 | + if (!h_dentry) | |
9914 | + continue; | |
4a4d8108 | 9915 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 9916 | + if (h_file) |
9917 | + continue; | |
9918 | + | |
392086de | 9919 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9920 | + err = PTR_ERR(h_file); |
9921 | + if (IS_ERR(h_file)) | |
9922 | + goto out; /* close all? */ | |
9923 | + au_set_h_fptr(file, bindex, h_file); | |
9924 | + } | |
9925 | + au_update_figen(file); | |
9926 | + /* todo: necessary? */ | |
9927 | + /* file->f_ra = h_file->f_ra; */ | |
9928 | + err = 0; | |
9929 | + | |
4f0767ce | 9930 | +out: |
1facf9fc | 9931 | + return err; |
9932 | +} | |
9933 | + | |
b912730e | 9934 | +static int do_open_dir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 9935 | +{ |
9936 | + int err; | |
9937 | + aufs_bindex_t bindex, btail; | |
9938 | + struct dentry *dentry, *h_dentry; | |
8cdd5066 | 9939 | + struct vfsmount *mnt; |
1facf9fc | 9940 | + |
1308ab2a | 9941 | + FiMustWriteLock(file); |
b912730e | 9942 | + AuDebugOn(h_file); |
1308ab2a | 9943 | + |
523b37e3 | 9944 | + err = 0; |
8cdd5066 | 9945 | + mnt = file->f_path.mnt; |
2000de60 | 9946 | + dentry = file->f_path.dentry; |
5527c038 | 9947 | + file->f_version = d_inode(dentry)->i_version; |
5afbbe0d AM |
9948 | + bindex = au_dbtop(dentry); |
9949 | + au_set_fbtop(file, bindex); | |
1facf9fc | 9950 | + btail = au_dbtaildir(dentry); |
5afbbe0d | 9951 | + au_set_fbbot_dir(file, btail); |
1facf9fc | 9952 | + for (; !err && bindex <= btail; bindex++) { |
9953 | + h_dentry = au_h_dptr(dentry, bindex); | |
9954 | + if (!h_dentry) | |
9955 | + continue; | |
9956 | + | |
8cdd5066 JR |
9957 | + err = vfsub_test_mntns(mnt, h_dentry->d_sb); |
9958 | + if (unlikely(err)) | |
9959 | + break; | |
392086de | 9960 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9961 | + if (IS_ERR(h_file)) { |
9962 | + err = PTR_ERR(h_file); | |
9963 | + break; | |
9964 | + } | |
9965 | + au_set_h_fptr(file, bindex, h_file); | |
9966 | + } | |
9967 | + au_update_figen(file); | |
9968 | + /* todo: necessary? */ | |
9969 | + /* file->f_ra = h_file->f_ra; */ | |
9970 | + if (!err) | |
9971 | + return 0; /* success */ | |
9972 | + | |
9973 | + /* close all */ | |
5afbbe0d | 9974 | + for (bindex = au_fbtop(file); bindex <= btail; bindex++) |
1facf9fc | 9975 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d AM |
9976 | + au_set_fbtop(file, -1); |
9977 | + au_set_fbbot_dir(file, -1); | |
4a4d8108 | 9978 | + |
1facf9fc | 9979 | + return err; |
9980 | +} | |
9981 | + | |
9982 | +static int aufs_open_dir(struct inode *inode __maybe_unused, | |
9983 | + struct file *file) | |
9984 | +{ | |
4a4d8108 AM |
9985 | + int err; |
9986 | + struct super_block *sb; | |
9987 | + struct au_fidir *fidir; | |
9988 | + | |
9989 | + err = -ENOMEM; | |
2000de60 | 9990 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 9991 | + si_read_lock(sb, AuLock_FLUSH); |
e49829fe | 9992 | + fidir = au_fidir_alloc(sb); |
4a4d8108 | 9993 | + if (fidir) { |
b912730e AM |
9994 | + struct au_do_open_args args = { |
9995 | + .open = do_open_dir, | |
9996 | + .fidir = fidir | |
9997 | + }; | |
9998 | + err = au_do_open(file, &args); | |
4a4d8108 | 9999 | + if (unlikely(err)) |
f0c0a007 | 10000 | + au_delayed_kfree(fidir); |
4a4d8108 AM |
10001 | + } |
10002 | + si_read_unlock(sb); | |
10003 | + return err; | |
1facf9fc | 10004 | +} |
10005 | + | |
10006 | +static int aufs_release_dir(struct inode *inode __maybe_unused, | |
10007 | + struct file *file) | |
10008 | +{ | |
10009 | + struct au_vdir *vdir_cache; | |
4a4d8108 AM |
10010 | + struct au_finfo *finfo; |
10011 | + struct au_fidir *fidir; | |
f0c0a007 | 10012 | + struct au_hfile *hf; |
5afbbe0d | 10013 | + aufs_bindex_t bindex, bbot; |
f0c0a007 | 10014 | + int execed, delayed; |
1facf9fc | 10015 | + |
f0c0a007 | 10016 | + delayed = (current->flags & PF_KTHREAD) || in_interrupt(); |
4a4d8108 AM |
10017 | + finfo = au_fi(file); |
10018 | + fidir = finfo->fi_hdir; | |
10019 | + if (fidir) { | |
076b876e | 10020 | + au_sphl_del(&finfo->fi_hlist, |
2000de60 | 10021 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); |
4a4d8108 AM |
10022 | + vdir_cache = fidir->fd_vdir_cache; /* lock-free */ |
10023 | + if (vdir_cache) | |
f0c0a007 | 10024 | + au_vdir_free(vdir_cache, delayed); |
4a4d8108 AM |
10025 | + |
10026 | + bindex = finfo->fi_btop; | |
10027 | + if (bindex >= 0) { | |
f0c0a007 AM |
10028 | + execed = vfsub_file_execed(file); |
10029 | + hf = fidir->fd_hfile + bindex; | |
4a4d8108 AM |
10030 | + /* |
10031 | + * calls fput() instead of filp_close(), | |
10032 | + * since no dnotify or lock for the lower file. | |
10033 | + */ | |
5afbbe0d | 10034 | + bbot = fidir->fd_bbot; |
f0c0a007 AM |
10035 | + for (; bindex <= bbot; bindex++, hf++) |
10036 | + if (hf->hf_file) | |
10037 | + au_hfput(hf, execed); | |
4a4d8108 | 10038 | + } |
f0c0a007 | 10039 | + au_delayed_kfree(fidir); |
4a4d8108 | 10040 | + finfo->fi_hdir = NULL; |
1facf9fc | 10041 | + } |
f0c0a007 | 10042 | + au_finfo_fin(file, delayed); |
1facf9fc | 10043 | + return 0; |
10044 | +} | |
10045 | + | |
10046 | +/* ---------------------------------------------------------------------- */ | |
10047 | + | |
4a4d8108 AM |
10048 | +static int au_do_flush_dir(struct file *file, fl_owner_t id) |
10049 | +{ | |
10050 | + int err; | |
5afbbe0d | 10051 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
10052 | + struct file *h_file; |
10053 | + | |
10054 | + err = 0; | |
5afbbe0d AM |
10055 | + bbot = au_fbbot_dir(file); |
10056 | + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) { | |
4a4d8108 AM |
10057 | + h_file = au_hf_dir(file, bindex); |
10058 | + if (h_file) | |
10059 | + err = vfsub_flush(h_file, id); | |
10060 | + } | |
10061 | + return err; | |
10062 | +} | |
10063 | + | |
10064 | +static int aufs_flush_dir(struct file *file, fl_owner_t id) | |
10065 | +{ | |
10066 | + return au_do_flush(file, id, au_do_flush_dir); | |
10067 | +} | |
10068 | + | |
10069 | +/* ---------------------------------------------------------------------- */ | |
10070 | + | |
1facf9fc | 10071 | +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync) |
10072 | +{ | |
10073 | + int err; | |
5afbbe0d | 10074 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 10075 | + struct inode *inode; |
10076 | + struct super_block *sb; | |
10077 | + | |
10078 | + err = 0; | |
10079 | + sb = dentry->d_sb; | |
5527c038 | 10080 | + inode = d_inode(dentry); |
1facf9fc | 10081 | + IMustLock(inode); |
5afbbe0d AM |
10082 | + bbot = au_dbbot(dentry); |
10083 | + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) { | |
1facf9fc | 10084 | + struct path h_path; |
1facf9fc | 10085 | + |
10086 | + if (au_test_ro(sb, bindex, inode)) | |
10087 | + continue; | |
10088 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
10089 | + if (!h_path.dentry) | |
10090 | + continue; | |
1facf9fc | 10091 | + |
1facf9fc | 10092 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
53392da6 | 10093 | + err = vfsub_fsync(NULL, &h_path, datasync); |
1facf9fc | 10094 | + } |
10095 | + | |
10096 | + return err; | |
10097 | +} | |
10098 | + | |
10099 | +static int au_do_fsync_dir(struct file *file, int datasync) | |
10100 | +{ | |
10101 | + int err; | |
5afbbe0d | 10102 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 10103 | + struct file *h_file; |
10104 | + struct super_block *sb; | |
10105 | + struct inode *inode; | |
1facf9fc | 10106 | + |
521ced18 | 10107 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0); |
1facf9fc | 10108 | + if (unlikely(err)) |
10109 | + goto out; | |
10110 | + | |
c06a8ce3 | 10111 | + inode = file_inode(file); |
b912730e | 10112 | + sb = inode->i_sb; |
5afbbe0d AM |
10113 | + bbot = au_fbbot_dir(file); |
10114 | + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) { | |
4a4d8108 | 10115 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 10116 | + if (!h_file || au_test_ro(sb, bindex, inode)) |
10117 | + continue; | |
10118 | + | |
53392da6 | 10119 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
1facf9fc | 10120 | + } |
10121 | + | |
4f0767ce | 10122 | +out: |
1facf9fc | 10123 | + return err; |
10124 | +} | |
10125 | + | |
10126 | +/* | |
10127 | + * @file may be NULL | |
10128 | + */ | |
1e00d052 AM |
10129 | +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end, |
10130 | + int datasync) | |
1facf9fc | 10131 | +{ |
10132 | + int err; | |
b752ccd1 | 10133 | + struct dentry *dentry; |
5527c038 | 10134 | + struct inode *inode; |
1facf9fc | 10135 | + struct super_block *sb; |
1facf9fc | 10136 | + |
10137 | + err = 0; | |
2000de60 | 10138 | + dentry = file->f_path.dentry; |
5527c038 | 10139 | + inode = d_inode(dentry); |
febd17d6 | 10140 | + inode_lock(inode); |
1facf9fc | 10141 | + sb = dentry->d_sb; |
10142 | + si_noflush_read_lock(sb); | |
10143 | + if (file) | |
10144 | + err = au_do_fsync_dir(file, datasync); | |
10145 | + else { | |
10146 | + di_write_lock_child(dentry); | |
10147 | + err = au_do_fsync_dir_no_file(dentry, datasync); | |
10148 | + } | |
5527c038 | 10149 | + au_cpup_attr_timesizes(inode); |
1facf9fc | 10150 | + di_write_unlock(dentry); |
10151 | + if (file) | |
10152 | + fi_write_unlock(file); | |
10153 | + | |
10154 | + si_read_unlock(sb); | |
febd17d6 | 10155 | + inode_unlock(inode); |
1facf9fc | 10156 | + return err; |
10157 | +} | |
10158 | + | |
10159 | +/* ---------------------------------------------------------------------- */ | |
10160 | + | |
5afbbe0d | 10161 | +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx) |
1facf9fc | 10162 | +{ |
10163 | + int err; | |
10164 | + struct dentry *dentry; | |
9dbd164d | 10165 | + struct inode *inode, *h_inode; |
1facf9fc | 10166 | + struct super_block *sb; |
10167 | + | |
523b37e3 | 10168 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 10169 | + |
2000de60 | 10170 | + dentry = file->f_path.dentry; |
5527c038 | 10171 | + inode = d_inode(dentry); |
1facf9fc | 10172 | + IMustLock(inode); |
10173 | + | |
10174 | + sb = dentry->d_sb; | |
10175 | + si_read_lock(sb, AuLock_FLUSH); | |
521ced18 | 10176 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0); |
1facf9fc | 10177 | + if (unlikely(err)) |
10178 | + goto out; | |
027c5e7a AM |
10179 | + err = au_alive_dir(dentry); |
10180 | + if (!err) | |
10181 | + err = au_vdir_init(file); | |
1facf9fc | 10182 | + di_downgrade_lock(dentry, AuLock_IR); |
10183 | + if (unlikely(err)) | |
10184 | + goto out_unlock; | |
10185 | + | |
5afbbe0d | 10186 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
b752ccd1 | 10187 | + if (!au_test_nfsd()) { |
392086de | 10188 | + err = au_vdir_fill_de(file, ctx); |
9dbd164d | 10189 | + fsstack_copy_attr_atime(inode, h_inode); |
1facf9fc | 10190 | + } else { |
10191 | + /* | |
10192 | + * nfsd filldir may call lookup_one_len(), vfs_getattr(), | |
10193 | + * encode_fh() and others. | |
10194 | + */ | |
9dbd164d | 10195 | + atomic_inc(&h_inode->i_count); |
1facf9fc | 10196 | + di_read_unlock(dentry, AuLock_IR); |
10197 | + si_read_unlock(sb); | |
392086de | 10198 | + err = au_vdir_fill_de(file, ctx); |
1facf9fc | 10199 | + fsstack_copy_attr_atime(inode, h_inode); |
10200 | + fi_write_unlock(file); | |
9dbd164d | 10201 | + iput(h_inode); |
1facf9fc | 10202 | + |
10203 | + AuTraceErr(err); | |
10204 | + return err; | |
10205 | + } | |
10206 | + | |
4f0767ce | 10207 | +out_unlock: |
1facf9fc | 10208 | + di_read_unlock(dentry, AuLock_IR); |
10209 | + fi_write_unlock(file); | |
4f0767ce | 10210 | +out: |
1facf9fc | 10211 | + si_read_unlock(sb); |
10212 | + return err; | |
10213 | +} | |
10214 | + | |
10215 | +/* ---------------------------------------------------------------------- */ | |
10216 | + | |
10217 | +#define AuTestEmpty_WHONLY 1 | |
dece6358 AM |
10218 | +#define AuTestEmpty_CALLED (1 << 1) |
10219 | +#define AuTestEmpty_SHWH (1 << 2) | |
1facf9fc | 10220 | +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name) |
7f207e10 AM |
10221 | +#define au_fset_testempty(flags, name) \ |
10222 | + do { (flags) |= AuTestEmpty_##name; } while (0) | |
10223 | +#define au_fclr_testempty(flags, name) \ | |
10224 | + do { (flags) &= ~AuTestEmpty_##name; } while (0) | |
1facf9fc | 10225 | + |
dece6358 AM |
10226 | +#ifndef CONFIG_AUFS_SHWH |
10227 | +#undef AuTestEmpty_SHWH | |
10228 | +#define AuTestEmpty_SHWH 0 | |
10229 | +#endif | |
10230 | + | |
1facf9fc | 10231 | +struct test_empty_arg { |
392086de | 10232 | + struct dir_context ctx; |
1308ab2a | 10233 | + struct au_nhash *whlist; |
1facf9fc | 10234 | + unsigned int flags; |
10235 | + int err; | |
10236 | + aufs_bindex_t bindex; | |
10237 | +}; | |
10238 | + | |
392086de AM |
10239 | +static int test_empty_cb(struct dir_context *ctx, const char *__name, |
10240 | + int namelen, loff_t offset __maybe_unused, u64 ino, | |
dece6358 | 10241 | + unsigned int d_type) |
1facf9fc | 10242 | +{ |
392086de AM |
10243 | + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg, |
10244 | + ctx); | |
1facf9fc | 10245 | + char *name = (void *)__name; |
10246 | + | |
10247 | + arg->err = 0; | |
10248 | + au_fset_testempty(arg->flags, CALLED); | |
10249 | + /* smp_mb(); */ | |
10250 | + if (name[0] == '.' | |
10251 | + && (namelen == 1 || (name[1] == '.' && namelen == 2))) | |
10252 | + goto out; /* success */ | |
10253 | + | |
10254 | + if (namelen <= AUFS_WH_PFX_LEN | |
10255 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
10256 | + if (au_ftest_testempty(arg->flags, WHONLY) | |
1308ab2a | 10257 | + && !au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 10258 | + arg->err = -ENOTEMPTY; |
10259 | + goto out; | |
10260 | + } | |
10261 | + | |
10262 | + name += AUFS_WH_PFX_LEN; | |
10263 | + namelen -= AUFS_WH_PFX_LEN; | |
1308ab2a | 10264 | + if (!au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 10265 | + arg->err = au_nhash_append_wh |
1308ab2a | 10266 | + (arg->whlist, name, namelen, ino, d_type, arg->bindex, |
dece6358 | 10267 | + au_ftest_testempty(arg->flags, SHWH)); |
1facf9fc | 10268 | + |
4f0767ce | 10269 | +out: |
1facf9fc | 10270 | + /* smp_mb(); */ |
10271 | + AuTraceErr(arg->err); | |
10272 | + return arg->err; | |
10273 | +} | |
10274 | + | |
10275 | +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
10276 | +{ | |
10277 | + int err; | |
10278 | + struct file *h_file; | |
10279 | + | |
10280 | + h_file = au_h_open(dentry, arg->bindex, | |
10281 | + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE, | |
392086de | 10282 | + /*file*/NULL, /*force_wr*/0); |
1facf9fc | 10283 | + err = PTR_ERR(h_file); |
10284 | + if (IS_ERR(h_file)) | |
10285 | + goto out; | |
10286 | + | |
10287 | + err = 0; | |
10288 | + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE) | |
c06a8ce3 | 10289 | + && !file_inode(h_file)->i_nlink) |
1facf9fc | 10290 | + goto out_put; |
10291 | + | |
10292 | + do { | |
10293 | + arg->err = 0; | |
10294 | + au_fclr_testempty(arg->flags, CALLED); | |
10295 | + /* smp_mb(); */ | |
392086de | 10296 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1facf9fc | 10297 | + if (err >= 0) |
10298 | + err = arg->err; | |
10299 | + } while (!err && au_ftest_testempty(arg->flags, CALLED)); | |
10300 | + | |
4f0767ce | 10301 | +out_put: |
1facf9fc | 10302 | + fput(h_file); |
10303 | + au_sbr_put(dentry->d_sb, arg->bindex); | |
4f0767ce | 10304 | +out: |
1facf9fc | 10305 | + return err; |
10306 | +} | |
10307 | + | |
10308 | +struct do_test_empty_args { | |
10309 | + int *errp; | |
10310 | + struct dentry *dentry; | |
10311 | + struct test_empty_arg *arg; | |
10312 | +}; | |
10313 | + | |
10314 | +static void call_do_test_empty(void *args) | |
10315 | +{ | |
10316 | + struct do_test_empty_args *a = args; | |
10317 | + *a->errp = do_test_empty(a->dentry, a->arg); | |
10318 | +} | |
10319 | + | |
10320 | +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
10321 | +{ | |
10322 | + int err, wkq_err; | |
10323 | + struct dentry *h_dentry; | |
10324 | + struct inode *h_inode; | |
10325 | + | |
10326 | + h_dentry = au_h_dptr(dentry, arg->bindex); | |
5527c038 | 10327 | + h_inode = d_inode(h_dentry); |
53392da6 | 10328 | + /* todo: i_mode changes anytime? */ |
febd17d6 | 10329 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
1facf9fc | 10330 | + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ); |
febd17d6 | 10331 | + inode_unlock(h_inode); |
1facf9fc | 10332 | + if (!err) |
10333 | + err = do_test_empty(dentry, arg); | |
10334 | + else { | |
10335 | + struct do_test_empty_args args = { | |
10336 | + .errp = &err, | |
10337 | + .dentry = dentry, | |
10338 | + .arg = arg | |
10339 | + }; | |
10340 | + unsigned int flags = arg->flags; | |
10341 | + | |
10342 | + wkq_err = au_wkq_wait(call_do_test_empty, &args); | |
10343 | + if (unlikely(wkq_err)) | |
10344 | + err = wkq_err; | |
10345 | + arg->flags = flags; | |
10346 | + } | |
10347 | + | |
10348 | + return err; | |
10349 | +} | |
10350 | + | |
10351 | +int au_test_empty_lower(struct dentry *dentry) | |
10352 | +{ | |
10353 | + int err; | |
1308ab2a | 10354 | + unsigned int rdhash; |
5afbbe0d | 10355 | + aufs_bindex_t bindex, btop, btail; |
1308ab2a | 10356 | + struct au_nhash whlist; |
392086de AM |
10357 | + struct test_empty_arg arg = { |
10358 | + .ctx = { | |
2000de60 | 10359 | + .actor = test_empty_cb |
392086de AM |
10360 | + } |
10361 | + }; | |
076b876e | 10362 | + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg); |
1facf9fc | 10363 | + |
dece6358 AM |
10364 | + SiMustAnyLock(dentry->d_sb); |
10365 | + | |
1308ab2a | 10366 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; |
10367 | + if (!rdhash) | |
10368 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry)); | |
10369 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
dece6358 | 10370 | + if (unlikely(err)) |
1facf9fc | 10371 | + goto out; |
10372 | + | |
1facf9fc | 10373 | + arg.flags = 0; |
1308ab2a | 10374 | + arg.whlist = &whlist; |
5afbbe0d | 10375 | + btop = au_dbtop(dentry); |
dece6358 AM |
10376 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10377 | + au_fset_testempty(arg.flags, SHWH); | |
076b876e AM |
10378 | + test_empty = do_test_empty; |
10379 | + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)) | |
10380 | + test_empty = sio_test_empty; | |
5afbbe0d | 10381 | + arg.bindex = btop; |
076b876e | 10382 | + err = test_empty(dentry, &arg); |
1facf9fc | 10383 | + if (unlikely(err)) |
10384 | + goto out_whlist; | |
10385 | + | |
10386 | + au_fset_testempty(arg.flags, WHONLY); | |
10387 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 10388 | + for (bindex = btop + 1; !err && bindex <= btail; bindex++) { |
1facf9fc | 10389 | + struct dentry *h_dentry; |
10390 | + | |
10391 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10392 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10393 | + arg.bindex = bindex; |
076b876e | 10394 | + err = test_empty(dentry, &arg); |
1facf9fc | 10395 | + } |
10396 | + } | |
10397 | + | |
4f0767ce | 10398 | +out_whlist: |
1308ab2a | 10399 | + au_nhash_wh_free(&whlist); |
4f0767ce | 10400 | +out: |
1facf9fc | 10401 | + return err; |
10402 | +} | |
10403 | + | |
10404 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist) | |
10405 | +{ | |
10406 | + int err; | |
392086de AM |
10407 | + struct test_empty_arg arg = { |
10408 | + .ctx = { | |
2000de60 | 10409 | + .actor = test_empty_cb |
392086de AM |
10410 | + } |
10411 | + }; | |
1facf9fc | 10412 | + aufs_bindex_t bindex, btail; |
10413 | + | |
10414 | + err = 0; | |
1308ab2a | 10415 | + arg.whlist = whlist; |
1facf9fc | 10416 | + arg.flags = AuTestEmpty_WHONLY; |
dece6358 AM |
10417 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10418 | + au_fset_testempty(arg.flags, SHWH); | |
1facf9fc | 10419 | + btail = au_dbtaildir(dentry); |
5afbbe0d | 10420 | + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) { |
1facf9fc | 10421 | + struct dentry *h_dentry; |
10422 | + | |
10423 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10424 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10425 | + arg.bindex = bindex; |
10426 | + err = sio_test_empty(dentry, &arg); | |
10427 | + } | |
10428 | + } | |
10429 | + | |
10430 | + return err; | |
10431 | +} | |
10432 | + | |
10433 | +/* ---------------------------------------------------------------------- */ | |
10434 | + | |
10435 | +const struct file_operations aufs_dir_fop = { | |
4a4d8108 | 10436 | + .owner = THIS_MODULE, |
027c5e7a | 10437 | + .llseek = default_llseek, |
1facf9fc | 10438 | + .read = generic_read_dir, |
5afbbe0d | 10439 | + .iterate_shared = aufs_iterate_shared, |
1facf9fc | 10440 | + .unlocked_ioctl = aufs_ioctl_dir, |
b752ccd1 AM |
10441 | +#ifdef CONFIG_COMPAT |
10442 | + .compat_ioctl = aufs_compat_ioctl_dir, | |
10443 | +#endif | |
1facf9fc | 10444 | + .open = aufs_open_dir, |
10445 | + .release = aufs_release_dir, | |
4a4d8108 | 10446 | + .flush = aufs_flush_dir, |
1facf9fc | 10447 | + .fsync = aufs_fsync_dir |
10448 | +}; | |
7f207e10 AM |
10449 | diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h |
10450 | --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 10451 | +++ linux/fs/aufs/dir.h 2017-05-06 22:16:52.778220093 +0200 |
f0c0a007 | 10452 | @@ -0,0 +1,137 @@ |
1facf9fc | 10453 | +/* |
a2654f78 | 10454 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 10455 | + * |
10456 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10457 | + * it under the terms of the GNU General Public License as published by | |
10458 | + * the Free Software Foundation; either version 2 of the License, or | |
10459 | + * (at your option) any later version. | |
dece6358 AM |
10460 | + * |
10461 | + * This program is distributed in the hope that it will be useful, | |
10462 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10463 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10464 | + * GNU General Public License for more details. | |
10465 | + * | |
10466 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10467 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10468 | + */ |
10469 | + | |
10470 | +/* | |
10471 | + * directory operations | |
10472 | + */ | |
10473 | + | |
10474 | +#ifndef __AUFS_DIR_H__ | |
10475 | +#define __AUFS_DIR_H__ | |
10476 | + | |
10477 | +#ifdef __KERNEL__ | |
10478 | + | |
10479 | +#include <linux/fs.h> | |
1facf9fc | 10480 | + |
10481 | +/* ---------------------------------------------------------------------- */ | |
10482 | + | |
10483 | +/* need to be faster and smaller */ | |
10484 | + | |
10485 | +struct au_nhash { | |
dece6358 AM |
10486 | + unsigned int nh_num; |
10487 | + struct hlist_head *nh_head; | |
1facf9fc | 10488 | +}; |
10489 | + | |
10490 | +struct au_vdir_destr { | |
10491 | + unsigned char len; | |
10492 | + unsigned char name[0]; | |
10493 | +} __packed; | |
10494 | + | |
10495 | +struct au_vdir_dehstr { | |
10496 | + struct hlist_node hash; | |
f0c0a007 AM |
10497 | + union { |
10498 | + struct au_vdir_destr *str; | |
10499 | + struct llist_node lnode; /* delayed free */ | |
10500 | + }; | |
4a4d8108 | 10501 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10502 | + |
10503 | +struct au_vdir_de { | |
10504 | + ino_t de_ino; | |
10505 | + unsigned char de_type; | |
10506 | + /* caution: packed */ | |
10507 | + struct au_vdir_destr de_str; | |
10508 | +} __packed; | |
10509 | + | |
10510 | +struct au_vdir_wh { | |
10511 | + struct hlist_node wh_hash; | |
dece6358 AM |
10512 | +#ifdef CONFIG_AUFS_SHWH |
10513 | + ino_t wh_ino; | |
1facf9fc | 10514 | + aufs_bindex_t wh_bindex; |
dece6358 AM |
10515 | + unsigned char wh_type; |
10516 | +#else | |
10517 | + aufs_bindex_t wh_bindex; | |
10518 | +#endif | |
10519 | + /* caution: packed */ | |
1facf9fc | 10520 | + struct au_vdir_destr wh_str; |
10521 | +} __packed; | |
10522 | + | |
10523 | +union au_vdir_deblk_p { | |
10524 | + unsigned char *deblk; | |
10525 | + struct au_vdir_de *de; | |
10526 | +}; | |
10527 | + | |
10528 | +struct au_vdir { | |
10529 | + unsigned char **vd_deblk; | |
10530 | + unsigned long vd_nblk; | |
1facf9fc | 10531 | + struct { |
10532 | + unsigned long ul; | |
10533 | + union au_vdir_deblk_p p; | |
10534 | + } vd_last; | |
10535 | + | |
10536 | + unsigned long vd_version; | |
dece6358 | 10537 | + unsigned int vd_deblk_sz; |
f0c0a007 AM |
10538 | + union { |
10539 | + unsigned long vd_jiffy; | |
10540 | + struct llist_node vd_lnode; /* delayed free */ | |
10541 | + }; | |
4a4d8108 | 10542 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10543 | + |
10544 | +/* ---------------------------------------------------------------------- */ | |
10545 | + | |
10546 | +/* dir.c */ | |
10547 | +extern const struct file_operations aufs_dir_fop; | |
10548 | +void au_add_nlink(struct inode *dir, struct inode *h_dir); | |
10549 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir); | |
1308ab2a | 10550 | +loff_t au_dir_size(struct file *file, struct dentry *dentry); |
b912730e | 10551 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc); |
1facf9fc | 10552 | +int au_test_empty_lower(struct dentry *dentry); |
10553 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist); | |
10554 | + | |
10555 | +/* vdir.c */ | |
1308ab2a | 10556 | +unsigned int au_rdhash_est(loff_t sz); |
dece6358 AM |
10557 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp); |
10558 | +void au_nhash_wh_free(struct au_nhash *whlist); | |
1facf9fc | 10559 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, |
10560 | + int limit); | |
dece6358 AM |
10561 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen); |
10562 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
10563 | + unsigned int d_type, aufs_bindex_t bindex, | |
10564 | + unsigned char shwh); | |
f0c0a007 | 10565 | +void au_vdir_free(struct au_vdir *vdir, int atonce); |
1facf9fc | 10566 | +int au_vdir_init(struct file *file); |
392086de | 10567 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx); |
1facf9fc | 10568 | + |
10569 | +/* ioctl.c */ | |
10570 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg); | |
10571 | + | |
1308ab2a | 10572 | +#ifdef CONFIG_AUFS_RDU |
10573 | +/* rdu.c */ | |
10574 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
10575 | +#ifdef CONFIG_COMPAT |
10576 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, | |
10577 | + unsigned long arg); | |
10578 | +#endif | |
1308ab2a | 10579 | +#else |
c1595e42 JR |
10580 | +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file, |
10581 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10582 | +#ifdef CONFIG_COMPAT |
c1595e42 JR |
10583 | +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file, |
10584 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10585 | +#endif |
1308ab2a | 10586 | +#endif |
10587 | + | |
1facf9fc | 10588 | +#endif /* __KERNEL__ */ |
10589 | +#endif /* __AUFS_DIR_H__ */ | |
7f207e10 AM |
10590 | diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c |
10591 | --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 10592 | +++ linux/fs/aufs/dynop.c 2017-05-06 22:16:52.778220093 +0200 |
e2f27e51 | 10593 | @@ -0,0 +1,371 @@ |
1facf9fc | 10594 | +/* |
a2654f78 | 10595 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
1facf9fc | 10596 | + * |
10597 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10598 | + * it under the terms of the GNU General Public License as published by | |
10599 | + * the Free Software Foundation; either version 2 of the License, or | |
10600 | + * (at your option) any later version. | |
dece6358 AM |
10601 | + * |
10602 | + * This program is distributed in the hope that it will be useful, | |
10603 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10604 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10605 | + * GNU General Public License for more details. | |
10606 | + * | |
10607 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10608 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10609 | + */ |
10610 | + | |
10611 | +/* | |
4a4d8108 | 10612 | + * dynamically customizable operations for regular files |
1facf9fc | 10613 | + */ |
10614 | + | |
1facf9fc | 10615 | +#include "aufs.h" |
10616 | + | |
4a4d8108 | 10617 | +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop) |
1facf9fc | 10618 | + |
4a4d8108 AM |
10619 | +/* |
10620 | + * How large will these lists be? | |
10621 | + * Usually just a few elements, 20-30 at most for each, I guess. | |
10622 | + */ | |
f0c0a007 | 10623 | +static struct au_sphlhead dynop[AuDyLast]; |
4a4d8108 | 10624 | + |
f0c0a007 | 10625 | +static struct au_dykey *dy_gfind_get(struct au_sphlhead *sphl, const void *h_op) |
1facf9fc | 10626 | +{ |
4a4d8108 | 10627 | + struct au_dykey *key, *tmp; |
f0c0a007 | 10628 | + struct hlist_head *head; |
1facf9fc | 10629 | + |
4a4d8108 | 10630 | + key = NULL; |
f0c0a007 | 10631 | + head = &sphl->head; |
4a4d8108 | 10632 | + rcu_read_lock(); |
f0c0a007 | 10633 | + hlist_for_each_entry_rcu(tmp, head, dk_hnode) |
4a4d8108 AM |
10634 | + if (tmp->dk_op.dy_hop == h_op) { |
10635 | + key = tmp; | |
10636 | + kref_get(&key->dk_kref); | |
10637 | + break; | |
10638 | + } | |
10639 | + rcu_read_unlock(); | |
10640 | + | |
10641 | + return key; | |
1facf9fc | 10642 | +} |
10643 | + | |
4a4d8108 | 10644 | +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key) |
1facf9fc | 10645 | +{ |
4a4d8108 AM |
10646 | + struct au_dykey **k, *found; |
10647 | + const void *h_op = key->dk_op.dy_hop; | |
10648 | + int i; | |
1facf9fc | 10649 | + |
4a4d8108 AM |
10650 | + found = NULL; |
10651 | + k = br->br_dykey; | |
10652 | + for (i = 0; i < AuBrDynOp; i++) | |
10653 | + if (k[i]) { | |
10654 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10655 | + found = k[i]; | |
10656 | + break; | |
10657 | + } | |
10658 | + } else | |
10659 | + break; | |
10660 | + if (!found) { | |
10661 | + spin_lock(&br->br_dykey_lock); | |
10662 | + for (; i < AuBrDynOp; i++) | |
10663 | + if (k[i]) { | |
10664 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10665 | + found = k[i]; | |
10666 | + break; | |
10667 | + } | |
10668 | + } else { | |
10669 | + k[i] = key; | |
10670 | + break; | |
10671 | + } | |
10672 | + spin_unlock(&br->br_dykey_lock); | |
10673 | + BUG_ON(i == AuBrDynOp); /* expand the array */ | |
10674 | + } | |
10675 | + | |
10676 | + return found; | |
1facf9fc | 10677 | +} |
10678 | + | |
4a4d8108 | 10679 | +/* kref_get() if @key is already added */ |
f0c0a007 | 10680 | +static struct au_dykey *dy_gadd(struct au_sphlhead *sphl, struct au_dykey *key) |
4a4d8108 AM |
10681 | +{ |
10682 | + struct au_dykey *tmp, *found; | |
f0c0a007 | 10683 | + struct hlist_head *head; |
4a4d8108 | 10684 | + const void *h_op = key->dk_op.dy_hop; |
1facf9fc | 10685 | + |
4a4d8108 | 10686 | + found = NULL; |
f0c0a007 AM |
10687 | + head = &sphl->head; |
10688 | + spin_lock(&sphl->spin); | |
10689 | + hlist_for_each_entry(tmp, head, dk_hnode) | |
4a4d8108 AM |
10690 | + if (tmp->dk_op.dy_hop == h_op) { |
10691 | + kref_get(&tmp->dk_kref); | |
10692 | + found = tmp; | |
10693 | + break; | |
10694 | + } | |
10695 | + if (!found) | |
f0c0a007 AM |
10696 | + hlist_add_head_rcu(&key->dk_hnode, head); |
10697 | + spin_unlock(&sphl->spin); | |
1facf9fc | 10698 | + |
4a4d8108 AM |
10699 | + if (!found) |
10700 | + DyPrSym(key); | |
10701 | + return found; | |
10702 | +} | |
10703 | + | |
10704 | +static void dy_free_rcu(struct rcu_head *rcu) | |
1facf9fc | 10705 | +{ |
4a4d8108 AM |
10706 | + struct au_dykey *key; |
10707 | + | |
10708 | + key = container_of(rcu, struct au_dykey, dk_rcu); | |
10709 | + DyPrSym(key); | |
f0c0a007 | 10710 | + kfree(key); /* not delayed */ |
1facf9fc | 10711 | +} |
10712 | + | |
4a4d8108 AM |
10713 | +static void dy_free(struct kref *kref) |
10714 | +{ | |
10715 | + struct au_dykey *key; | |
f0c0a007 | 10716 | + struct au_sphlhead *sphl; |
1facf9fc | 10717 | + |
4a4d8108 | 10718 | + key = container_of(kref, struct au_dykey, dk_kref); |
f0c0a007 AM |
10719 | + sphl = dynop + key->dk_op.dy_type; |
10720 | + au_sphl_del_rcu(&key->dk_hnode, sphl); | |
4a4d8108 AM |
10721 | + call_rcu(&key->dk_rcu, dy_free_rcu); |
10722 | +} | |
10723 | + | |
10724 | +void au_dy_put(struct au_dykey *key) | |
1facf9fc | 10725 | +{ |
4a4d8108 AM |
10726 | + kref_put(&key->dk_kref, dy_free); |
10727 | +} | |
1facf9fc | 10728 | + |
4a4d8108 AM |
10729 | +/* ---------------------------------------------------------------------- */ |
10730 | + | |
10731 | +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *)) | |
10732 | + | |
10733 | +#ifdef CONFIG_AUFS_DEBUG | |
10734 | +#define DyDbgDeclare(cnt) unsigned int cnt = 0 | |
4f0767ce | 10735 | +#define DyDbgInc(cnt) do { cnt++; } while (0) |
4a4d8108 AM |
10736 | +#else |
10737 | +#define DyDbgDeclare(cnt) do {} while (0) | |
10738 | +#define DyDbgInc(cnt) do {} while (0) | |
10739 | +#endif | |
10740 | + | |
10741 | +#define DySet(func, dst, src, h_op, h_sb) do { \ | |
10742 | + DyDbgInc(cnt); \ | |
10743 | + if (h_op->func) { \ | |
10744 | + if (src.func) \ | |
10745 | + dst.func = src.func; \ | |
10746 | + else \ | |
10747 | + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \ | |
10748 | + } \ | |
10749 | +} while (0) | |
10750 | + | |
10751 | +#define DySetForce(func, dst, src) do { \ | |
10752 | + AuDebugOn(!src.func); \ | |
10753 | + DyDbgInc(cnt); \ | |
10754 | + dst.func = src.func; \ | |
10755 | +} while (0) | |
10756 | + | |
10757 | +#define DySetAop(func) \ | |
10758 | + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb) | |
10759 | +#define DySetAopForce(func) \ | |
10760 | + DySetForce(func, dyaop->da_op, aufs_aop) | |
10761 | + | |
10762 | +static void dy_aop(struct au_dykey *key, const void *h_op, | |
10763 | + struct super_block *h_sb __maybe_unused) | |
10764 | +{ | |
10765 | + struct au_dyaop *dyaop = (void *)key; | |
10766 | + const struct address_space_operations *h_aop = h_op; | |
10767 | + DyDbgDeclare(cnt); | |
10768 | + | |
10769 | + AuDbg("%s\n", au_sbtype(h_sb)); | |
10770 | + | |
10771 | + DySetAop(writepage); | |
10772 | + DySetAopForce(readpage); /* force */ | |
4a4d8108 AM |
10773 | + DySetAop(writepages); |
10774 | + DySetAop(set_page_dirty); | |
10775 | + DySetAop(readpages); | |
10776 | + DySetAop(write_begin); | |
10777 | + DySetAop(write_end); | |
10778 | + DySetAop(bmap); | |
10779 | + DySetAop(invalidatepage); | |
10780 | + DySetAop(releasepage); | |
027c5e7a | 10781 | + DySetAop(freepage); |
7e9cd9fe | 10782 | + /* this one will be changed according to an aufs mount option */ |
4a4d8108 | 10783 | + DySetAop(direct_IO); |
4a4d8108 | 10784 | + DySetAop(migratepage); |
e2f27e51 AM |
10785 | + DySetAop(isolate_page); |
10786 | + DySetAop(putback_page); | |
4a4d8108 AM |
10787 | + DySetAop(launder_page); |
10788 | + DySetAop(is_partially_uptodate); | |
392086de | 10789 | + DySetAop(is_dirty_writeback); |
4a4d8108 | 10790 | + DySetAop(error_remove_page); |
b4510431 AM |
10791 | + DySetAop(swap_activate); |
10792 | + DySetAop(swap_deactivate); | |
4a4d8108 AM |
10793 | + |
10794 | + DyDbgSize(cnt, *h_aop); | |
4a4d8108 AM |
10795 | +} |
10796 | + | |
4a4d8108 AM |
10797 | +/* ---------------------------------------------------------------------- */ |
10798 | + | |
10799 | +static void dy_bug(struct kref *kref) | |
10800 | +{ | |
10801 | + BUG(); | |
10802 | +} | |
10803 | + | |
10804 | +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br) | |
10805 | +{ | |
10806 | + struct au_dykey *key, *old; | |
f0c0a007 | 10807 | + struct au_sphlhead *sphl; |
b752ccd1 | 10808 | + struct op { |
4a4d8108 | 10809 | + unsigned int sz; |
b752ccd1 AM |
10810 | + void (*set)(struct au_dykey *key, const void *h_op, |
10811 | + struct super_block *h_sb __maybe_unused); | |
10812 | + }; | |
10813 | + static const struct op a[] = { | |
4a4d8108 AM |
10814 | + [AuDy_AOP] = { |
10815 | + .sz = sizeof(struct au_dyaop), | |
b752ccd1 | 10816 | + .set = dy_aop |
4a4d8108 | 10817 | + } |
b752ccd1 AM |
10818 | + }; |
10819 | + const struct op *p; | |
4a4d8108 | 10820 | + |
f0c0a007 AM |
10821 | + sphl = dynop + op->dy_type; |
10822 | + key = dy_gfind_get(sphl, op->dy_hop); | |
4a4d8108 AM |
10823 | + if (key) |
10824 | + goto out_add; /* success */ | |
10825 | + | |
10826 | + p = a + op->dy_type; | |
10827 | + key = kzalloc(p->sz, GFP_NOFS); | |
10828 | + if (unlikely(!key)) { | |
10829 | + key = ERR_PTR(-ENOMEM); | |
10830 | + goto out; | |
10831 | + } | |
10832 | + | |
10833 | + key->dk_op.dy_hop = op->dy_hop; | |
10834 | + kref_init(&key->dk_kref); | |
86dc4139 | 10835 | + p->set(key, op->dy_hop, au_br_sb(br)); |
f0c0a007 | 10836 | + old = dy_gadd(sphl, key); |
4a4d8108 | 10837 | + if (old) { |
f0c0a007 | 10838 | + au_delayed_kfree(key); |
4a4d8108 AM |
10839 | + key = old; |
10840 | + } | |
10841 | + | |
10842 | +out_add: | |
10843 | + old = dy_bradd(br, key); | |
10844 | + if (old) | |
10845 | + /* its ref-count should never be zero here */ | |
10846 | + kref_put(&key->dk_kref, dy_bug); | |
10847 | +out: | |
10848 | + return key; | |
10849 | +} | |
10850 | + | |
10851 | +/* ---------------------------------------------------------------------- */ | |
10852 | +/* | |
10853 | + * Aufs prohibits O_DIRECT by defaut even if the branch supports it. | |
c1595e42 | 10854 | + * This behaviour is necessary to return an error from open(O_DIRECT) instead |
4a4d8108 AM |
10855 | + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes |
10856 | + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error. | |
10857 | + * See the aufs manual in detail. | |
4a4d8108 AM |
10858 | + */ |
10859 | +static void dy_adx(struct au_dyaop *dyaop, int do_dx) | |
10860 | +{ | |
7e9cd9fe | 10861 | + if (!do_dx) |
4a4d8108 | 10862 | + dyaop->da_op.direct_IO = NULL; |
7e9cd9fe | 10863 | + else |
4a4d8108 | 10864 | + dyaop->da_op.direct_IO = aufs_aop.direct_IO; |
4a4d8108 AM |
10865 | +} |
10866 | + | |
10867 | +static struct au_dyaop *dy_aget(struct au_branch *br, | |
10868 | + const struct address_space_operations *h_aop, | |
10869 | + int do_dx) | |
10870 | +{ | |
10871 | + struct au_dyaop *dyaop; | |
10872 | + struct au_dynop op; | |
10873 | + | |
10874 | + op.dy_type = AuDy_AOP; | |
10875 | + op.dy_haop = h_aop; | |
10876 | + dyaop = (void *)dy_get(&op, br); | |
10877 | + if (IS_ERR(dyaop)) | |
10878 | + goto out; | |
10879 | + dy_adx(dyaop, do_dx); | |
10880 | + | |
10881 | +out: | |
10882 | + return dyaop; | |
10883 | +} | |
10884 | + | |
10885 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
10886 | + struct inode *h_inode) | |
10887 | +{ | |
10888 | + int err, do_dx; | |
10889 | + struct super_block *sb; | |
10890 | + struct au_branch *br; | |
10891 | + struct au_dyaop *dyaop; | |
10892 | + | |
10893 | + AuDebugOn(!S_ISREG(h_inode->i_mode)); | |
10894 | + IiMustWriteLock(inode); | |
10895 | + | |
10896 | + sb = inode->i_sb; | |
10897 | + br = au_sbr(sb, bindex); | |
10898 | + do_dx = !!au_opt_test(au_mntflags(sb), DIO); | |
10899 | + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx); | |
10900 | + err = PTR_ERR(dyaop); | |
10901 | + if (IS_ERR(dyaop)) | |
10902 | + /* unnecessary to call dy_fput() */ | |
10903 | + goto out; | |
10904 | + | |
10905 | + err = 0; | |
10906 | + inode->i_mapping->a_ops = &dyaop->da_op; | |
10907 | + | |
10908 | +out: | |
10909 | + return err; | |
10910 | +} | |
10911 | + | |
b752ccd1 AM |
10912 | +/* |
10913 | + * Is it safe to replace a_ops during the inode/file is in operation? | |
10914 | + * Yes, I hope so. | |
10915 | + */ | |
10916 | +int au_dy_irefresh(struct inode *inode) | |
10917 | +{ | |
10918 | + int err; | |
5afbbe0d | 10919 | + aufs_bindex_t btop; |
b752ccd1 AM |
10920 | + struct inode *h_inode; |
10921 | + | |
10922 | + err = 0; | |
10923 | + if (S_ISREG(inode->i_mode)) { | |
5afbbe0d AM |
10924 | + btop = au_ibtop(inode); |
10925 | + h_inode = au_h_iptr(inode, btop); | |
10926 | + err = au_dy_iaop(inode, btop, h_inode); | |
b752ccd1 AM |
10927 | + } |
10928 | + return err; | |
10929 | +} | |
10930 | + | |
4a4d8108 AM |
10931 | +void au_dy_arefresh(int do_dx) |
10932 | +{ | |
f0c0a007 AM |
10933 | + struct au_sphlhead *sphl; |
10934 | + struct hlist_head *head; | |
4a4d8108 AM |
10935 | + struct au_dykey *key; |
10936 | + | |
f0c0a007 AM |
10937 | + sphl = dynop + AuDy_AOP; |
10938 | + head = &sphl->head; | |
10939 | + spin_lock(&sphl->spin); | |
10940 | + hlist_for_each_entry(key, head, dk_hnode) | |
4a4d8108 | 10941 | + dy_adx((void *)key, do_dx); |
f0c0a007 | 10942 | + spin_unlock(&sphl->spin); |
4a4d8108 AM |
10943 | +} |
10944 | + | |
4a4d8108 AM |
10945 | +/* ---------------------------------------------------------------------- */ |
10946 | + | |
10947 | +void __init au_dy_init(void) | |
10948 | +{ | |
10949 | + int i; | |
10950 | + | |
10951 | + /* make sure that 'struct au_dykey *' can be any type */ | |
10952 | + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key)); | |
4a4d8108 AM |
10953 | + |
10954 | + for (i = 0; i < AuDyLast; i++) | |
f0c0a007 | 10955 | + au_sphl_init(dynop + i); |
4a4d8108 AM |
10956 | +} |
10957 | + | |
10958 | +void au_dy_fin(void) | |
10959 | +{ | |
10960 | + int i; | |
10961 | + | |
10962 | + for (i = 0; i < AuDyLast; i++) | |
f0c0a007 | 10963 | + WARN_ON(!hlist_empty(&dynop[i].head)); |
4a4d8108 | 10964 | +} |
7f207e10 AM |
10965 | diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h |
10966 | --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 10967 | +++ linux/fs/aufs/dynop.h 2017-05-06 22:16:52.778220093 +0200 |
7e9cd9fe | 10968 | @@ -0,0 +1,74 @@ |
4a4d8108 | 10969 | +/* |
a2654f78 | 10970 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
4a4d8108 AM |
10971 | + * |
10972 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10973 | + * it under the terms of the GNU General Public License as published by | |
10974 | + * the Free Software Foundation; either version 2 of the License, or | |
10975 | + * (at your option) any later version. | |
10976 | + * | |
10977 | + * This program is distributed in the hope that it will be useful, | |
10978 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10979 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10980 | + * GNU General Public License for more details. | |
10981 | + * | |
10982 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10983 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
10984 | + */ |
10985 | + | |
10986 | +/* | |
10987 | + * dynamically customizable operations (for regular files only) | |
10988 | + */ | |
10989 | + | |
10990 | +#ifndef __AUFS_DYNOP_H__ | |
10991 | +#define __AUFS_DYNOP_H__ | |
10992 | + | |
10993 | +#ifdef __KERNEL__ | |
10994 | + | |
7e9cd9fe AM |
10995 | +#include <linux/fs.h> |
10996 | +#include <linux/kref.h> | |
4a4d8108 | 10997 | + |
2cbb1c4b | 10998 | +enum {AuDy_AOP, AuDyLast}; |
4a4d8108 AM |
10999 | + |
11000 | +struct au_dynop { | |
11001 | + int dy_type; | |
11002 | + union { | |
11003 | + const void *dy_hop; | |
11004 | + const struct address_space_operations *dy_haop; | |
4a4d8108 AM |
11005 | + }; |
11006 | +}; | |
11007 | + | |
11008 | +struct au_dykey { | |
11009 | + union { | |
f0c0a007 | 11010 | + struct hlist_node dk_hnode; |
4a4d8108 AM |
11011 | + struct rcu_head dk_rcu; |
11012 | + }; | |
11013 | + struct au_dynop dk_op; | |
11014 | + | |
11015 | + /* | |
11016 | + * during I am in the branch local array, kref is gotten. when the | |
11017 | + * branch is removed, kref is put. | |
11018 | + */ | |
11019 | + struct kref dk_kref; | |
11020 | +}; | |
11021 | + | |
11022 | +/* stop unioning since their sizes are very different from each other */ | |
11023 | +struct au_dyaop { | |
11024 | + struct au_dykey da_key; | |
11025 | + struct address_space_operations da_op; /* not const */ | |
4a4d8108 AM |
11026 | +}; |
11027 | + | |
4a4d8108 AM |
11028 | +/* ---------------------------------------------------------------------- */ |
11029 | + | |
11030 | +/* dynop.c */ | |
11031 | +struct au_branch; | |
11032 | +void au_dy_put(struct au_dykey *key); | |
11033 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
11034 | + struct inode *h_inode); | |
b752ccd1 | 11035 | +int au_dy_irefresh(struct inode *inode); |
4a4d8108 | 11036 | +void au_dy_arefresh(int do_dio); |
4a4d8108 AM |
11037 | + |
11038 | +void __init au_dy_init(void); | |
11039 | +void au_dy_fin(void); | |
11040 | + | |
4a4d8108 AM |
11041 | +#endif /* __KERNEL__ */ |
11042 | +#endif /* __AUFS_DYNOP_H__ */ | |
7f207e10 AM |
11043 | diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c |
11044 | --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 11045 | +++ linux/fs/aufs/export.c 2017-05-06 22:16:52.778220093 +0200 |
f2c43d5f | 11046 | @@ -0,0 +1,836 @@ |
4a4d8108 | 11047 | +/* |
a2654f78 | 11048 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
11049 | + * |
11050 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11051 | + * it under the terms of the GNU General Public License as published by | |
11052 | + * the Free Software Foundation; either version 2 of the License, or | |
11053 | + * (at your option) any later version. | |
11054 | + * | |
11055 | + * This program is distributed in the hope that it will be useful, | |
11056 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11057 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11058 | + * GNU General Public License for more details. | |
11059 | + * | |
11060 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 11061 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
11062 | + */ |
11063 | + | |
11064 | +/* | |
11065 | + * export via nfs | |
11066 | + */ | |
11067 | + | |
11068 | +#include <linux/exportfs.h> | |
7eafdf33 | 11069 | +#include <linux/fs_struct.h> |
4a4d8108 AM |
11070 | +#include <linux/namei.h> |
11071 | +#include <linux/nsproxy.h> | |
11072 | +#include <linux/random.h> | |
11073 | +#include <linux/writeback.h> | |
11074 | +#include "aufs.h" | |
11075 | + | |
11076 | +union conv { | |
11077 | +#ifdef CONFIG_AUFS_INO_T_64 | |
11078 | + __u32 a[2]; | |
11079 | +#else | |
11080 | + __u32 a[1]; | |
11081 | +#endif | |
11082 | + ino_t ino; | |
11083 | +}; | |
11084 | + | |
11085 | +static ino_t decode_ino(__u32 *a) | |
11086 | +{ | |
11087 | + union conv u; | |
11088 | + | |
11089 | + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a)); | |
11090 | + u.a[0] = a[0]; | |
11091 | +#ifdef CONFIG_AUFS_INO_T_64 | |
11092 | + u.a[1] = a[1]; | |
11093 | +#endif | |
11094 | + return u.ino; | |
11095 | +} | |
11096 | + | |
11097 | +static void encode_ino(__u32 *a, ino_t ino) | |
11098 | +{ | |
11099 | + union conv u; | |
11100 | + | |
11101 | + u.ino = ino; | |
11102 | + a[0] = u.a[0]; | |
11103 | +#ifdef CONFIG_AUFS_INO_T_64 | |
11104 | + a[1] = u.a[1]; | |
11105 | +#endif | |
11106 | +} | |
11107 | + | |
11108 | +/* NFS file handle */ | |
11109 | +enum { | |
11110 | + Fh_br_id, | |
11111 | + Fh_sigen, | |
11112 | +#ifdef CONFIG_AUFS_INO_T_64 | |
11113 | + /* support 64bit inode number */ | |
11114 | + Fh_ino1, | |
11115 | + Fh_ino2, | |
11116 | + Fh_dir_ino1, | |
11117 | + Fh_dir_ino2, | |
11118 | +#else | |
11119 | + Fh_ino1, | |
11120 | + Fh_dir_ino1, | |
11121 | +#endif | |
11122 | + Fh_igen, | |
11123 | + Fh_h_type, | |
11124 | + Fh_tail, | |
11125 | + | |
11126 | + Fh_ino = Fh_ino1, | |
11127 | + Fh_dir_ino = Fh_dir_ino1 | |
11128 | +}; | |
11129 | + | |
11130 | +static int au_test_anon(struct dentry *dentry) | |
11131 | +{ | |
027c5e7a | 11132 | + /* note: read d_flags without d_lock */ |
4a4d8108 AM |
11133 | + return !!(dentry->d_flags & DCACHE_DISCONNECTED); |
11134 | +} | |
11135 | + | |
a2a7ad62 AM |
11136 | +int au_test_nfsd(void) |
11137 | +{ | |
11138 | + int ret; | |
11139 | + struct task_struct *tsk = current; | |
11140 | + char comm[sizeof(tsk->comm)]; | |
11141 | + | |
11142 | + ret = 0; | |
11143 | + if (tsk->flags & PF_KTHREAD) { | |
11144 | + get_task_comm(comm, tsk); | |
11145 | + ret = !strcmp(comm, "nfsd"); | |
11146 | + } | |
11147 | + | |
11148 | + return ret; | |
11149 | +} | |
11150 | + | |
4a4d8108 AM |
11151 | +/* ---------------------------------------------------------------------- */ |
11152 | +/* inode generation external table */ | |
11153 | + | |
b752ccd1 | 11154 | +void au_xigen_inc(struct inode *inode) |
4a4d8108 | 11155 | +{ |
4a4d8108 AM |
11156 | + loff_t pos; |
11157 | + ssize_t sz; | |
11158 | + __u32 igen; | |
11159 | + struct super_block *sb; | |
11160 | + struct au_sbinfo *sbinfo; | |
11161 | + | |
4a4d8108 | 11162 | + sb = inode->i_sb; |
b752ccd1 | 11163 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); |
1facf9fc | 11164 | + |
b752ccd1 | 11165 | + sbinfo = au_sbi(sb); |
1facf9fc | 11166 | + pos = inode->i_ino; |
11167 | + pos *= sizeof(igen); | |
11168 | + igen = inode->i_generation + 1; | |
1facf9fc | 11169 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen, |
11170 | + sizeof(igen), &pos); | |
11171 | + if (sz == sizeof(igen)) | |
b752ccd1 | 11172 | + return; /* success */ |
1facf9fc | 11173 | + |
b752ccd1 | 11174 | + if (unlikely(sz >= 0)) |
1facf9fc | 11175 | + AuIOErr("xigen error (%zd)\n", sz); |
1facf9fc | 11176 | +} |
11177 | + | |
11178 | +int au_xigen_new(struct inode *inode) | |
11179 | +{ | |
11180 | + int err; | |
11181 | + loff_t pos; | |
11182 | + ssize_t sz; | |
11183 | + struct super_block *sb; | |
11184 | + struct au_sbinfo *sbinfo; | |
11185 | + struct file *file; | |
11186 | + | |
11187 | + err = 0; | |
11188 | + /* todo: dirty, at mount time */ | |
11189 | + if (inode->i_ino == AUFS_ROOT_INO) | |
11190 | + goto out; | |
11191 | + sb = inode->i_sb; | |
dece6358 | 11192 | + SiMustAnyLock(sb); |
1facf9fc | 11193 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) |
11194 | + goto out; | |
11195 | + | |
11196 | + err = -EFBIG; | |
11197 | + pos = inode->i_ino; | |
11198 | + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) { | |
11199 | + AuIOErr1("too large i%lld\n", pos); | |
11200 | + goto out; | |
11201 | + } | |
11202 | + pos *= sizeof(inode->i_generation); | |
11203 | + | |
11204 | + err = 0; | |
11205 | + sbinfo = au_sbi(sb); | |
11206 | + file = sbinfo->si_xigen; | |
11207 | + BUG_ON(!file); | |
11208 | + | |
c06a8ce3 | 11209 | + if (vfsub_f_size_read(file) |
1facf9fc | 11210 | + < pos + sizeof(inode->i_generation)) { |
11211 | + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next); | |
11212 | + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation, | |
11213 | + sizeof(inode->i_generation), &pos); | |
11214 | + } else | |
11215 | + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation, | |
11216 | + sizeof(inode->i_generation), &pos); | |
11217 | + if (sz == sizeof(inode->i_generation)) | |
11218 | + goto out; /* success */ | |
11219 | + | |
11220 | + err = sz; | |
11221 | + if (unlikely(sz >= 0)) { | |
11222 | + err = -EIO; | |
11223 | + AuIOErr("xigen error (%zd)\n", sz); | |
11224 | + } | |
11225 | + | |
4f0767ce | 11226 | +out: |
1facf9fc | 11227 | + return err; |
11228 | +} | |
11229 | + | |
11230 | +int au_xigen_set(struct super_block *sb, struct file *base) | |
11231 | +{ | |
11232 | + int err; | |
11233 | + struct au_sbinfo *sbinfo; | |
11234 | + struct file *file; | |
11235 | + | |
dece6358 AM |
11236 | + SiMustWriteLock(sb); |
11237 | + | |
1facf9fc | 11238 | + sbinfo = au_sbi(sb); |
11239 | + file = au_xino_create2(base, sbinfo->si_xigen); | |
11240 | + err = PTR_ERR(file); | |
11241 | + if (IS_ERR(file)) | |
11242 | + goto out; | |
11243 | + err = 0; | |
11244 | + if (sbinfo->si_xigen) | |
11245 | + fput(sbinfo->si_xigen); | |
11246 | + sbinfo->si_xigen = file; | |
11247 | + | |
4f0767ce | 11248 | +out: |
1facf9fc | 11249 | + return err; |
11250 | +} | |
11251 | + | |
11252 | +void au_xigen_clr(struct super_block *sb) | |
11253 | +{ | |
11254 | + struct au_sbinfo *sbinfo; | |
11255 | + | |
dece6358 AM |
11256 | + SiMustWriteLock(sb); |
11257 | + | |
1facf9fc | 11258 | + sbinfo = au_sbi(sb); |
11259 | + if (sbinfo->si_xigen) { | |
11260 | + fput(sbinfo->si_xigen); | |
11261 | + sbinfo->si_xigen = NULL; | |
11262 | + } | |
11263 | +} | |
11264 | + | |
11265 | +/* ---------------------------------------------------------------------- */ | |
11266 | + | |
11267 | +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino, | |
11268 | + ino_t dir_ino) | |
11269 | +{ | |
11270 | + struct dentry *dentry, *d; | |
11271 | + struct inode *inode; | |
11272 | + unsigned int sigen; | |
11273 | + | |
11274 | + dentry = NULL; | |
11275 | + inode = ilookup(sb, ino); | |
11276 | + if (!inode) | |
11277 | + goto out; | |
11278 | + | |
11279 | + dentry = ERR_PTR(-ESTALE); | |
11280 | + sigen = au_sigen(sb); | |
5afbbe0d | 11281 | + if (unlikely(au_is_bad_inode(inode) |
1facf9fc | 11282 | + || IS_DEADDIR(inode) |
537831f9 | 11283 | + || sigen != au_iigen(inode, NULL))) |
1facf9fc | 11284 | + goto out_iput; |
11285 | + | |
11286 | + dentry = NULL; | |
11287 | + if (!dir_ino || S_ISDIR(inode->i_mode)) | |
11288 | + dentry = d_find_alias(inode); | |
11289 | + else { | |
027c5e7a | 11290 | + spin_lock(&inode->i_lock); |
c1595e42 | 11291 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 11292 | + spin_lock(&d->d_lock); |
1facf9fc | 11293 | + if (!au_test_anon(d) |
5527c038 | 11294 | + && d_inode(d->d_parent)->i_ino == dir_ino) { |
027c5e7a AM |
11295 | + dentry = dget_dlock(d); |
11296 | + spin_unlock(&d->d_lock); | |
1facf9fc | 11297 | + break; |
11298 | + } | |
027c5e7a AM |
11299 | + spin_unlock(&d->d_lock); |
11300 | + } | |
11301 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 11302 | + } |
027c5e7a | 11303 | + if (unlikely(dentry && au_digen_test(dentry, sigen))) { |
2cbb1c4b | 11304 | + /* need to refresh */ |
1facf9fc | 11305 | + dput(dentry); |
2cbb1c4b | 11306 | + dentry = NULL; |
1facf9fc | 11307 | + } |
11308 | + | |
4f0767ce | 11309 | +out_iput: |
1facf9fc | 11310 | + iput(inode); |
4f0767ce | 11311 | +out: |
2cbb1c4b | 11312 | + AuTraceErrPtr(dentry); |
1facf9fc | 11313 | + return dentry; |
11314 | +} | |
11315 | + | |
11316 | +/* ---------------------------------------------------------------------- */ | |
11317 | + | |
11318 | +/* todo: dirty? */ | |
11319 | +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */ | |
4a4d8108 AM |
11320 | + |
11321 | +struct au_compare_mnt_args { | |
11322 | + /* input */ | |
11323 | + struct super_block *sb; | |
11324 | + | |
11325 | + /* output */ | |
11326 | + struct vfsmount *mnt; | |
11327 | +}; | |
11328 | + | |
11329 | +static int au_compare_mnt(struct vfsmount *mnt, void *arg) | |
11330 | +{ | |
11331 | + struct au_compare_mnt_args *a = arg; | |
11332 | + | |
11333 | + if (mnt->mnt_sb != a->sb) | |
11334 | + return 0; | |
11335 | + a->mnt = mntget(mnt); | |
11336 | + return 1; | |
11337 | +} | |
11338 | + | |
1facf9fc | 11339 | +static struct vfsmount *au_mnt_get(struct super_block *sb) |
11340 | +{ | |
4a4d8108 | 11341 | + int err; |
7eafdf33 | 11342 | + struct path root; |
4a4d8108 AM |
11343 | + struct au_compare_mnt_args args = { |
11344 | + .sb = sb | |
11345 | + }; | |
1facf9fc | 11346 | + |
7eafdf33 | 11347 | + get_fs_root(current->fs, &root); |
523b37e3 | 11348 | + rcu_read_lock(); |
7eafdf33 | 11349 | + err = iterate_mounts(au_compare_mnt, &args, root.mnt); |
523b37e3 | 11350 | + rcu_read_unlock(); |
7eafdf33 | 11351 | + path_put(&root); |
4a4d8108 AM |
11352 | + AuDebugOn(!err); |
11353 | + AuDebugOn(!args.mnt); | |
11354 | + return args.mnt; | |
1facf9fc | 11355 | +} |
11356 | + | |
11357 | +struct au_nfsd_si_lock { | |
4a4d8108 | 11358 | + unsigned int sigen; |
027c5e7a | 11359 | + aufs_bindex_t bindex, br_id; |
1facf9fc | 11360 | + unsigned char force_lock; |
11361 | +}; | |
11362 | + | |
027c5e7a AM |
11363 | +static int si_nfsd_read_lock(struct super_block *sb, |
11364 | + struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 11365 | +{ |
027c5e7a | 11366 | + int err; |
1facf9fc | 11367 | + aufs_bindex_t bindex; |
11368 | + | |
11369 | + si_read_lock(sb, AuLock_FLUSH); | |
11370 | + | |
11371 | + /* branch id may be wrapped around */ | |
027c5e7a | 11372 | + err = 0; |
1facf9fc | 11373 | + bindex = au_br_index(sb, nsi_lock->br_id); |
11374 | + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb)) | |
11375 | + goto out; /* success */ | |
11376 | + | |
027c5e7a AM |
11377 | + err = -ESTALE; |
11378 | + bindex = -1; | |
1facf9fc | 11379 | + if (!nsi_lock->force_lock) |
11380 | + si_read_unlock(sb); | |
1facf9fc | 11381 | + |
4f0767ce | 11382 | +out: |
027c5e7a AM |
11383 | + nsi_lock->bindex = bindex; |
11384 | + return err; | |
1facf9fc | 11385 | +} |
11386 | + | |
11387 | +struct find_name_by_ino { | |
392086de | 11388 | + struct dir_context ctx; |
1facf9fc | 11389 | + int called, found; |
11390 | + ino_t ino; | |
11391 | + char *name; | |
11392 | + int namelen; | |
11393 | +}; | |
11394 | + | |
11395 | +static int | |
392086de AM |
11396 | +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen, |
11397 | + loff_t offset, u64 ino, unsigned int d_type) | |
1facf9fc | 11398 | +{ |
392086de AM |
11399 | + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino, |
11400 | + ctx); | |
1facf9fc | 11401 | + |
11402 | + a->called++; | |
11403 | + if (a->ino != ino) | |
11404 | + return 0; | |
11405 | + | |
11406 | + memcpy(a->name, name, namelen); | |
11407 | + a->namelen = namelen; | |
11408 | + a->found = 1; | |
11409 | + return 1; | |
11410 | +} | |
11411 | + | |
11412 | +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino, | |
11413 | + struct au_nfsd_si_lock *nsi_lock) | |
11414 | +{ | |
11415 | + struct dentry *dentry, *parent; | |
11416 | + struct file *file; | |
11417 | + struct inode *dir; | |
392086de AM |
11418 | + struct find_name_by_ino arg = { |
11419 | + .ctx = { | |
2000de60 | 11420 | + .actor = find_name_by_ino |
392086de AM |
11421 | + } |
11422 | + }; | |
1facf9fc | 11423 | + int err; |
11424 | + | |
11425 | + parent = path->dentry; | |
11426 | + if (nsi_lock) | |
11427 | + si_read_unlock(parent->d_sb); | |
4a4d8108 | 11428 | + file = vfsub_dentry_open(path, au_dir_roflags); |
1facf9fc | 11429 | + dentry = (void *)file; |
11430 | + if (IS_ERR(file)) | |
11431 | + goto out; | |
11432 | + | |
11433 | + dentry = ERR_PTR(-ENOMEM); | |
537831f9 | 11434 | + arg.name = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 11435 | + if (unlikely(!arg.name)) |
11436 | + goto out_file; | |
11437 | + arg.ino = ino; | |
11438 | + arg.found = 0; | |
11439 | + do { | |
11440 | + arg.called = 0; | |
11441 | + /* smp_mb(); */ | |
392086de | 11442 | + err = vfsub_iterate_dir(file, &arg.ctx); |
1facf9fc | 11443 | + } while (!err && !arg.found && arg.called); |
11444 | + dentry = ERR_PTR(err); | |
11445 | + if (unlikely(err)) | |
11446 | + goto out_name; | |
1716fcea AM |
11447 | + /* instead of ENOENT */ |
11448 | + dentry = ERR_PTR(-ESTALE); | |
1facf9fc | 11449 | + if (!arg.found) |
11450 | + goto out_name; | |
11451 | + | |
b4510431 | 11452 | + /* do not call vfsub_lkup_one() */ |
5527c038 | 11453 | + dir = d_inode(parent); |
febd17d6 | 11454 | + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen); |
1facf9fc | 11455 | + AuTraceErrPtr(dentry); |
11456 | + if (IS_ERR(dentry)) | |
11457 | + goto out_name; | |
11458 | + AuDebugOn(au_test_anon(dentry)); | |
5527c038 | 11459 | + if (unlikely(d_really_is_negative(dentry))) { |
1facf9fc | 11460 | + dput(dentry); |
11461 | + dentry = ERR_PTR(-ENOENT); | |
11462 | + } | |
11463 | + | |
4f0767ce | 11464 | +out_name: |
f0c0a007 | 11465 | + au_delayed_free_page((unsigned long)arg.name); |
4f0767ce | 11466 | +out_file: |
1facf9fc | 11467 | + fput(file); |
4f0767ce | 11468 | +out: |
1facf9fc | 11469 | + if (unlikely(nsi_lock |
11470 | + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0)) | |
11471 | + if (!IS_ERR(dentry)) { | |
11472 | + dput(dentry); | |
11473 | + dentry = ERR_PTR(-ESTALE); | |
11474 | + } | |
11475 | + AuTraceErrPtr(dentry); | |
11476 | + return dentry; | |
11477 | +} | |
11478 | + | |
11479 | +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino, | |
11480 | + ino_t dir_ino, | |
11481 | + struct au_nfsd_si_lock *nsi_lock) | |
11482 | +{ | |
11483 | + struct dentry *dentry; | |
11484 | + struct path path; | |
11485 | + | |
11486 | + if (dir_ino != AUFS_ROOT_INO) { | |
11487 | + path.dentry = decode_by_ino(sb, dir_ino, 0); | |
11488 | + dentry = path.dentry; | |
11489 | + if (!path.dentry || IS_ERR(path.dentry)) | |
11490 | + goto out; | |
11491 | + AuDebugOn(au_test_anon(path.dentry)); | |
11492 | + } else | |
11493 | + path.dentry = dget(sb->s_root); | |
11494 | + | |
11495 | + path.mnt = au_mnt_get(sb); | |
11496 | + dentry = au_lkup_by_ino(&path, ino, nsi_lock); | |
11497 | + path_put(&path); | |
11498 | + | |
4f0767ce | 11499 | +out: |
1facf9fc | 11500 | + AuTraceErrPtr(dentry); |
11501 | + return dentry; | |
11502 | +} | |
11503 | + | |
11504 | +/* ---------------------------------------------------------------------- */ | |
11505 | + | |
11506 | +static int h_acceptable(void *expv, struct dentry *dentry) | |
11507 | +{ | |
11508 | + return 1; | |
11509 | +} | |
11510 | + | |
11511 | +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath, | |
11512 | + char *buf, int len, struct super_block *sb) | |
11513 | +{ | |
11514 | + char *p; | |
11515 | + int n; | |
11516 | + struct path path; | |
11517 | + | |
11518 | + p = d_path(h_rootpath, buf, len); | |
11519 | + if (IS_ERR(p)) | |
11520 | + goto out; | |
11521 | + n = strlen(p); | |
11522 | + | |
11523 | + path.mnt = h_rootpath->mnt; | |
11524 | + path.dentry = h_parent; | |
11525 | + p = d_path(&path, buf, len); | |
11526 | + if (IS_ERR(p)) | |
11527 | + goto out; | |
11528 | + if (n != 1) | |
11529 | + p += n; | |
11530 | + | |
11531 | + path.mnt = au_mnt_get(sb); | |
11532 | + path.dentry = sb->s_root; | |
11533 | + p = d_path(&path, buf, len - strlen(p)); | |
11534 | + mntput(path.mnt); | |
11535 | + if (IS_ERR(p)) | |
11536 | + goto out; | |
11537 | + if (n != 1) | |
11538 | + p[strlen(p)] = '/'; | |
11539 | + | |
4f0767ce | 11540 | +out: |
1facf9fc | 11541 | + AuTraceErrPtr(p); |
11542 | + return p; | |
11543 | +} | |
11544 | + | |
11545 | +static | |
027c5e7a AM |
11546 | +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh, |
11547 | + int fh_len, struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 11548 | +{ |
11549 | + struct dentry *dentry, *h_parent, *root; | |
11550 | + struct super_block *h_sb; | |
11551 | + char *pathname, *p; | |
11552 | + struct vfsmount *h_mnt; | |
11553 | + struct au_branch *br; | |
11554 | + int err; | |
11555 | + struct path path; | |
11556 | + | |
027c5e7a | 11557 | + br = au_sbr(sb, nsi_lock->bindex); |
86dc4139 | 11558 | + h_mnt = au_br_mnt(br); |
1facf9fc | 11559 | + h_sb = h_mnt->mnt_sb; |
11560 | + /* todo: call lower fh_to_dentry()? fh_to_parent()? */ | |
5afbbe0d | 11561 | + lockdep_off(); |
1facf9fc | 11562 | + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail), |
11563 | + fh_len - Fh_tail, fh[Fh_h_type], | |
11564 | + h_acceptable, /*context*/NULL); | |
5afbbe0d | 11565 | + lockdep_on(); |
1facf9fc | 11566 | + dentry = h_parent; |
11567 | + if (unlikely(!h_parent || IS_ERR(h_parent))) { | |
11568 | + AuWarn1("%s decode_fh failed, %ld\n", | |
11569 | + au_sbtype(h_sb), PTR_ERR(h_parent)); | |
11570 | + goto out; | |
11571 | + } | |
11572 | + dentry = NULL; | |
11573 | + if (unlikely(au_test_anon(h_parent))) { | |
11574 | + AuWarn1("%s decode_fh returned a disconnected dentry\n", | |
11575 | + au_sbtype(h_sb)); | |
11576 | + goto out_h_parent; | |
11577 | + } | |
11578 | + | |
11579 | + dentry = ERR_PTR(-ENOMEM); | |
11580 | + pathname = (void *)__get_free_page(GFP_NOFS); | |
11581 | + if (unlikely(!pathname)) | |
11582 | + goto out_h_parent; | |
11583 | + | |
11584 | + root = sb->s_root; | |
11585 | + path.mnt = h_mnt; | |
11586 | + di_read_lock_parent(root, !AuLock_IR); | |
027c5e7a | 11587 | + path.dentry = au_h_dptr(root, nsi_lock->bindex); |
1facf9fc | 11588 | + di_read_unlock(root, !AuLock_IR); |
11589 | + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb); | |
11590 | + dentry = (void *)p; | |
11591 | + if (IS_ERR(p)) | |
11592 | + goto out_pathname; | |
11593 | + | |
11594 | + si_read_unlock(sb); | |
11595 | + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | |
11596 | + dentry = ERR_PTR(err); | |
11597 | + if (unlikely(err)) | |
11598 | + goto out_relock; | |
11599 | + | |
11600 | + dentry = ERR_PTR(-ENOENT); | |
11601 | + AuDebugOn(au_test_anon(path.dentry)); | |
5527c038 | 11602 | + if (unlikely(d_really_is_negative(path.dentry))) |
1facf9fc | 11603 | + goto out_path; |
11604 | + | |
5527c038 | 11605 | + if (ino != d_inode(path.dentry)->i_ino) |
1facf9fc | 11606 | + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL); |
11607 | + else | |
11608 | + dentry = dget(path.dentry); | |
11609 | + | |
4f0767ce | 11610 | +out_path: |
1facf9fc | 11611 | + path_put(&path); |
4f0767ce | 11612 | +out_relock: |
1facf9fc | 11613 | + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0)) |
11614 | + if (!IS_ERR(dentry)) { | |
11615 | + dput(dentry); | |
11616 | + dentry = ERR_PTR(-ESTALE); | |
11617 | + } | |
4f0767ce | 11618 | +out_pathname: |
f0c0a007 | 11619 | + au_delayed_free_page((unsigned long)pathname); |
4f0767ce | 11620 | +out_h_parent: |
1facf9fc | 11621 | + dput(h_parent); |
4f0767ce | 11622 | +out: |
1facf9fc | 11623 | + AuTraceErrPtr(dentry); |
11624 | + return dentry; | |
11625 | +} | |
11626 | + | |
11627 | +/* ---------------------------------------------------------------------- */ | |
11628 | + | |
11629 | +static struct dentry * | |
11630 | +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, | |
11631 | + int fh_type) | |
11632 | +{ | |
11633 | + struct dentry *dentry; | |
11634 | + __u32 *fh = fid->raw; | |
027c5e7a | 11635 | + struct au_branch *br; |
1facf9fc | 11636 | + ino_t ino, dir_ino; |
1facf9fc | 11637 | + struct au_nfsd_si_lock nsi_lock = { |
1facf9fc | 11638 | + .force_lock = 0 |
11639 | + }; | |
11640 | + | |
1facf9fc | 11641 | + dentry = ERR_PTR(-ESTALE); |
4a4d8108 AM |
11642 | + /* it should never happen, but the file handle is unreliable */ |
11643 | + if (unlikely(fh_len < Fh_tail)) | |
11644 | + goto out; | |
11645 | + nsi_lock.sigen = fh[Fh_sigen]; | |
11646 | + nsi_lock.br_id = fh[Fh_br_id]; | |
11647 | + | |
1facf9fc | 11648 | + /* branch id may be wrapped around */ |
027c5e7a AM |
11649 | + br = NULL; |
11650 | + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock))) | |
1facf9fc | 11651 | + goto out; |
11652 | + nsi_lock.force_lock = 1; | |
11653 | + | |
11654 | + /* is this inode still cached? */ | |
11655 | + ino = decode_ino(fh + Fh_ino); | |
4a4d8108 AM |
11656 | + /* it should never happen */ |
11657 | + if (unlikely(ino == AUFS_ROOT_INO)) | |
8cdd5066 | 11658 | + goto out_unlock; |
4a4d8108 | 11659 | + |
1facf9fc | 11660 | + dir_ino = decode_ino(fh + Fh_dir_ino); |
11661 | + dentry = decode_by_ino(sb, ino, dir_ino); | |
11662 | + if (IS_ERR(dentry)) | |
11663 | + goto out_unlock; | |
11664 | + if (dentry) | |
11665 | + goto accept; | |
11666 | + | |
11667 | + /* is the parent dir cached? */ | |
027c5e7a | 11668 | + br = au_sbr(sb, nsi_lock.bindex); |
5afbbe0d | 11669 | + au_br_get(br); |
1facf9fc | 11670 | + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock); |
11671 | + if (IS_ERR(dentry)) | |
11672 | + goto out_unlock; | |
11673 | + if (dentry) | |
11674 | + goto accept; | |
11675 | + | |
11676 | + /* lookup path */ | |
027c5e7a | 11677 | + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock); |
1facf9fc | 11678 | + if (IS_ERR(dentry)) |
11679 | + goto out_unlock; | |
11680 | + if (unlikely(!dentry)) | |
11681 | + /* todo?: make it ESTALE */ | |
11682 | + goto out_unlock; | |
11683 | + | |
4f0767ce | 11684 | +accept: |
027c5e7a | 11685 | + if (!au_digen_test(dentry, au_sigen(sb)) |
5527c038 | 11686 | + && d_inode(dentry)->i_generation == fh[Fh_igen]) |
1facf9fc | 11687 | + goto out_unlock; /* success */ |
11688 | + | |
11689 | + dput(dentry); | |
11690 | + dentry = ERR_PTR(-ESTALE); | |
4f0767ce | 11691 | +out_unlock: |
027c5e7a | 11692 | + if (br) |
5afbbe0d | 11693 | + au_br_put(br); |
1facf9fc | 11694 | + si_read_unlock(sb); |
4f0767ce | 11695 | +out: |
1facf9fc | 11696 | + AuTraceErrPtr(dentry); |
11697 | + return dentry; | |
11698 | +} | |
11699 | + | |
11700 | +#if 0 /* reserved for future use */ | |
11701 | +/* support subtreecheck option */ | |
11702 | +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid, | |
11703 | + int fh_len, int fh_type) | |
11704 | +{ | |
11705 | + struct dentry *parent; | |
11706 | + __u32 *fh = fid->raw; | |
11707 | + ino_t dir_ino; | |
11708 | + | |
11709 | + dir_ino = decode_ino(fh + Fh_dir_ino); | |
11710 | + parent = decode_by_ino(sb, dir_ino, 0); | |
11711 | + if (IS_ERR(parent)) | |
11712 | + goto out; | |
11713 | + if (!parent) | |
11714 | + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]), | |
11715 | + dir_ino, fh, fh_len); | |
11716 | + | |
4f0767ce | 11717 | +out: |
1facf9fc | 11718 | + AuTraceErrPtr(parent); |
11719 | + return parent; | |
11720 | +} | |
11721 | +#endif | |
11722 | + | |
11723 | +/* ---------------------------------------------------------------------- */ | |
11724 | + | |
0c3ec466 AM |
11725 | +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, |
11726 | + struct inode *dir) | |
1facf9fc | 11727 | +{ |
11728 | + int err; | |
0c3ec466 | 11729 | + aufs_bindex_t bindex; |
1facf9fc | 11730 | + struct super_block *sb, *h_sb; |
0c3ec466 AM |
11731 | + struct dentry *dentry, *parent, *h_parent; |
11732 | + struct inode *h_dir; | |
1facf9fc | 11733 | + struct au_branch *br; |
11734 | + | |
1facf9fc | 11735 | + err = -ENOSPC; |
11736 | + if (unlikely(*max_len <= Fh_tail)) { | |
11737 | + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len); | |
11738 | + goto out; | |
11739 | + } | |
11740 | + | |
11741 | + err = FILEID_ROOT; | |
0c3ec466 AM |
11742 | + if (inode->i_ino == AUFS_ROOT_INO) { |
11743 | + AuDebugOn(inode->i_ino != AUFS_ROOT_INO); | |
1facf9fc | 11744 | + goto out; |
11745 | + } | |
11746 | + | |
1facf9fc | 11747 | + h_parent = NULL; |
0c3ec466 AM |
11748 | + sb = inode->i_sb; |
11749 | + err = si_read_lock(sb, AuLock_FLUSH); | |
027c5e7a AM |
11750 | + if (unlikely(err)) |
11751 | + goto out; | |
11752 | + | |
1facf9fc | 11753 | +#ifdef CONFIG_AUFS_DEBUG |
11754 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) | |
11755 | + AuWarn1("NFS-exporting requires xino\n"); | |
11756 | +#endif | |
027c5e7a | 11757 | + err = -EIO; |
0c3ec466 AM |
11758 | + parent = NULL; |
11759 | + ii_read_lock_child(inode); | |
5afbbe0d | 11760 | + bindex = au_ibtop(inode); |
0c3ec466 | 11761 | + if (!dir) { |
c1595e42 | 11762 | + dentry = d_find_any_alias(inode); |
0c3ec466 AM |
11763 | + if (unlikely(!dentry)) |
11764 | + goto out_unlock; | |
11765 | + AuDebugOn(au_test_anon(dentry)); | |
11766 | + parent = dget_parent(dentry); | |
11767 | + dput(dentry); | |
11768 | + if (unlikely(!parent)) | |
11769 | + goto out_unlock; | |
5527c038 JR |
11770 | + if (d_really_is_positive(parent)) |
11771 | + dir = d_inode(parent); | |
1facf9fc | 11772 | + } |
0c3ec466 AM |
11773 | + |
11774 | + ii_read_lock_parent(dir); | |
11775 | + h_dir = au_h_iptr(dir, bindex); | |
11776 | + ii_read_unlock(dir); | |
11777 | + if (unlikely(!h_dir)) | |
11778 | + goto out_parent; | |
c1595e42 | 11779 | + h_parent = d_find_any_alias(h_dir); |
1facf9fc | 11780 | + if (unlikely(!h_parent)) |
0c3ec466 | 11781 | + goto out_hparent; |
1facf9fc | 11782 | + |
11783 | + err = -EPERM; | |
11784 | + br = au_sbr(sb, bindex); | |
86dc4139 | 11785 | + h_sb = au_br_sb(br); |
1facf9fc | 11786 | + if (unlikely(!h_sb->s_export_op)) { |
11787 | + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb)); | |
0c3ec466 | 11788 | + goto out_hparent; |
1facf9fc | 11789 | + } |
11790 | + | |
11791 | + fh[Fh_br_id] = br->br_id; | |
11792 | + fh[Fh_sigen] = au_sigen(sb); | |
11793 | + encode_ino(fh + Fh_ino, inode->i_ino); | |
0c3ec466 | 11794 | + encode_ino(fh + Fh_dir_ino, dir->i_ino); |
1facf9fc | 11795 | + fh[Fh_igen] = inode->i_generation; |
11796 | + | |
11797 | + *max_len -= Fh_tail; | |
11798 | + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail), | |
11799 | + max_len, | |
11800 | + /*connectable or subtreecheck*/0); | |
11801 | + err = fh[Fh_h_type]; | |
11802 | + *max_len += Fh_tail; | |
11803 | + /* todo: macros? */ | |
1716fcea | 11804 | + if (err != FILEID_INVALID) |
1facf9fc | 11805 | + err = 99; |
11806 | + else | |
11807 | + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb)); | |
11808 | + | |
0c3ec466 | 11809 | +out_hparent: |
1facf9fc | 11810 | + dput(h_parent); |
0c3ec466 | 11811 | +out_parent: |
1facf9fc | 11812 | + dput(parent); |
0c3ec466 AM |
11813 | +out_unlock: |
11814 | + ii_read_unlock(inode); | |
11815 | + si_read_unlock(sb); | |
4f0767ce | 11816 | +out: |
1facf9fc | 11817 | + if (unlikely(err < 0)) |
1716fcea | 11818 | + err = FILEID_INVALID; |
1facf9fc | 11819 | + return err; |
11820 | +} | |
11821 | + | |
11822 | +/* ---------------------------------------------------------------------- */ | |
11823 | + | |
4a4d8108 AM |
11824 | +static int aufs_commit_metadata(struct inode *inode) |
11825 | +{ | |
11826 | + int err; | |
11827 | + aufs_bindex_t bindex; | |
11828 | + struct super_block *sb; | |
11829 | + struct inode *h_inode; | |
11830 | + int (*f)(struct inode *inode); | |
11831 | + | |
11832 | + sb = inode->i_sb; | |
e49829fe | 11833 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 11834 | + ii_write_lock_child(inode); |
5afbbe0d | 11835 | + bindex = au_ibtop(inode); |
4a4d8108 AM |
11836 | + AuDebugOn(bindex < 0); |
11837 | + h_inode = au_h_iptr(inode, bindex); | |
11838 | + | |
11839 | + f = h_inode->i_sb->s_export_op->commit_metadata; | |
11840 | + if (f) | |
11841 | + err = f(h_inode); | |
11842 | + else { | |
11843 | + struct writeback_control wbc = { | |
11844 | + .sync_mode = WB_SYNC_ALL, | |
11845 | + .nr_to_write = 0 /* metadata only */ | |
11846 | + }; | |
11847 | + | |
11848 | + err = sync_inode(h_inode, &wbc); | |
11849 | + } | |
11850 | + | |
11851 | + au_cpup_attr_timesizes(inode); | |
11852 | + ii_write_unlock(inode); | |
11853 | + si_read_unlock(sb); | |
11854 | + return err; | |
11855 | +} | |
11856 | + | |
11857 | +/* ---------------------------------------------------------------------- */ | |
11858 | + | |
1facf9fc | 11859 | +static struct export_operations aufs_export_op = { |
4a4d8108 | 11860 | + .fh_to_dentry = aufs_fh_to_dentry, |
1facf9fc | 11861 | + /* .fh_to_parent = aufs_fh_to_parent, */ |
4a4d8108 AM |
11862 | + .encode_fh = aufs_encode_fh, |
11863 | + .commit_metadata = aufs_commit_metadata | |
1facf9fc | 11864 | +}; |
11865 | + | |
11866 | +void au_export_init(struct super_block *sb) | |
11867 | +{ | |
11868 | + struct au_sbinfo *sbinfo; | |
11869 | + __u32 u; | |
11870 | + | |
5afbbe0d AM |
11871 | + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS) |
11872 | + && IS_MODULE(CONFIG_EXPORTFS), | |
11873 | + AUFS_NAME ": unsupported configuration " | |
11874 | + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y"); | |
11875 | + | |
1facf9fc | 11876 | + sb->s_export_op = &aufs_export_op; |
11877 | + sbinfo = au_sbi(sb); | |
11878 | + sbinfo->si_xigen = NULL; | |
11879 | + get_random_bytes(&u, sizeof(u)); | |
11880 | + BUILD_BUG_ON(sizeof(u) != sizeof(int)); | |
11881 | + atomic_set(&sbinfo->si_xigen_next, u); | |
11882 | +} | |
076b876e AM |
11883 | diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c |
11884 | --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 11885 | +++ linux/fs/aufs/fhsm.c 2017-05-06 22:16:52.778220093 +0200 |
c1595e42 | 11886 | @@ -0,0 +1,426 @@ |
076b876e | 11887 | +/* |
a2654f78 | 11888 | + * Copyright (C) 2011-2017 Junjiro R. Okajima |
076b876e AM |
11889 | + * |
11890 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11891 | + * it under the terms of the GNU General Public License as published by | |
11892 | + * the Free Software Foundation; either version 2 of the License, or | |
11893 | + * (at your option) any later version. | |
11894 | + * | |
11895 | + * This program is distributed in the hope that it will be useful, | |
11896 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11897 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11898 | + * GNU General Public License for more details. | |
11899 | + * | |
11900 | + * You should have received a copy of the GNU General Public License | |
11901 | + * along with this program; if not, write to the Free Software | |
11902 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
11903 | + */ | |
11904 | + | |
11905 | +/* | |
11906 | + * File-based Hierarchy Storage Management | |
11907 | + */ | |
11908 | + | |
11909 | +#include <linux/anon_inodes.h> | |
11910 | +#include <linux/poll.h> | |
11911 | +#include <linux/seq_file.h> | |
11912 | +#include <linux/statfs.h> | |
11913 | +#include "aufs.h" | |
11914 | + | |
c1595e42 JR |
11915 | +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb) |
11916 | +{ | |
11917 | + struct au_sbinfo *sbinfo; | |
11918 | + struct au_fhsm *fhsm; | |
11919 | + | |
11920 | + SiMustAnyLock(sb); | |
11921 | + | |
11922 | + sbinfo = au_sbi(sb); | |
11923 | + fhsm = &sbinfo->si_fhsm; | |
11924 | + AuDebugOn(!fhsm); | |
11925 | + return fhsm->fhsm_bottom; | |
11926 | +} | |
11927 | + | |
11928 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex) | |
11929 | +{ | |
11930 | + struct au_sbinfo *sbinfo; | |
11931 | + struct au_fhsm *fhsm; | |
11932 | + | |
11933 | + SiMustWriteLock(sb); | |
11934 | + | |
11935 | + sbinfo = au_sbi(sb); | |
11936 | + fhsm = &sbinfo->si_fhsm; | |
11937 | + AuDebugOn(!fhsm); | |
11938 | + fhsm->fhsm_bottom = bindex; | |
11939 | +} | |
11940 | + | |
11941 | +/* ---------------------------------------------------------------------- */ | |
11942 | + | |
076b876e AM |
11943 | +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br) |
11944 | +{ | |
11945 | + struct au_br_fhsm *bf; | |
11946 | + | |
11947 | + bf = br->br_fhsm; | |
11948 | + MtxMustLock(&bf->bf_lock); | |
11949 | + | |
11950 | + return !bf->bf_readable | |
11951 | + || time_after(jiffies, | |
11952 | + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire); | |
11953 | +} | |
11954 | + | |
11955 | +/* ---------------------------------------------------------------------- */ | |
11956 | + | |
11957 | +static void au_fhsm_notify(struct super_block *sb, int val) | |
11958 | +{ | |
11959 | + struct au_sbinfo *sbinfo; | |
11960 | + struct au_fhsm *fhsm; | |
11961 | + | |
11962 | + SiMustAnyLock(sb); | |
11963 | + | |
11964 | + sbinfo = au_sbi(sb); | |
11965 | + fhsm = &sbinfo->si_fhsm; | |
11966 | + if (au_fhsm_pid(fhsm) | |
11967 | + && atomic_read(&fhsm->fhsm_readable) != -1) { | |
11968 | + atomic_set(&fhsm->fhsm_readable, val); | |
11969 | + if (val) | |
11970 | + wake_up(&fhsm->fhsm_wqh); | |
11971 | + } | |
11972 | +} | |
11973 | + | |
11974 | +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex, | |
11975 | + struct aufs_stfs *rstfs, int do_lock, int do_notify) | |
11976 | +{ | |
11977 | + int err; | |
11978 | + struct au_branch *br; | |
11979 | + struct au_br_fhsm *bf; | |
11980 | + | |
11981 | + br = au_sbr(sb, bindex); | |
11982 | + AuDebugOn(au_br_rdonly(br)); | |
11983 | + bf = br->br_fhsm; | |
11984 | + AuDebugOn(!bf); | |
11985 | + | |
11986 | + if (do_lock) | |
11987 | + mutex_lock(&bf->bf_lock); | |
11988 | + else | |
11989 | + MtxMustLock(&bf->bf_lock); | |
11990 | + | |
11991 | + /* sb->s_root for NFS is unreliable */ | |
11992 | + err = au_br_stfs(br, &bf->bf_stfs); | |
11993 | + if (unlikely(err)) { | |
11994 | + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err); | |
11995 | + goto out; | |
11996 | + } | |
11997 | + | |
11998 | + bf->bf_jiffy = jiffies; | |
11999 | + bf->bf_readable = 1; | |
12000 | + if (do_notify) | |
12001 | + au_fhsm_notify(sb, /*val*/1); | |
12002 | + if (rstfs) | |
12003 | + *rstfs = bf->bf_stfs; | |
12004 | + | |
12005 | +out: | |
12006 | + if (do_lock) | |
12007 | + mutex_unlock(&bf->bf_lock); | |
12008 | + au_fhsm_notify(sb, /*val*/1); | |
12009 | + | |
12010 | + return err; | |
12011 | +} | |
12012 | + | |
12013 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force) | |
12014 | +{ | |
12015 | + int err; | |
076b876e AM |
12016 | + struct au_sbinfo *sbinfo; |
12017 | + struct au_fhsm *fhsm; | |
12018 | + struct au_branch *br; | |
12019 | + struct au_br_fhsm *bf; | |
12020 | + | |
12021 | + AuDbg("b%d, force %d\n", bindex, force); | |
12022 | + SiMustAnyLock(sb); | |
12023 | + | |
12024 | + sbinfo = au_sbi(sb); | |
12025 | + fhsm = &sbinfo->si_fhsm; | |
c1595e42 JR |
12026 | + if (!au_ftest_si(sbinfo, FHSM) |
12027 | + || fhsm->fhsm_bottom == bindex) | |
076b876e AM |
12028 | + return; |
12029 | + | |
12030 | + br = au_sbr(sb, bindex); | |
12031 | + bf = br->br_fhsm; | |
12032 | + AuDebugOn(!bf); | |
12033 | + mutex_lock(&bf->bf_lock); | |
12034 | + if (force | |
12035 | + || au_fhsm_pid(fhsm) | |
12036 | + || au_fhsm_test_jiffy(sbinfo, br)) | |
12037 | + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0, | |
12038 | + /*do_notify*/1); | |
12039 | + mutex_unlock(&bf->bf_lock); | |
12040 | +} | |
12041 | + | |
12042 | +void au_fhsm_wrote_all(struct super_block *sb, int force) | |
12043 | +{ | |
5afbbe0d | 12044 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
12045 | + struct au_branch *br; |
12046 | + | |
12047 | + /* exclude the bottom */ | |
5afbbe0d AM |
12048 | + bbot = au_fhsm_bottom(sb); |
12049 | + for (bindex = 0; bindex < bbot; bindex++) { | |
076b876e AM |
12050 | + br = au_sbr(sb, bindex); |
12051 | + if (au_br_fhsm(br->br_perm)) | |
12052 | + au_fhsm_wrote(sb, bindex, force); | |
12053 | + } | |
12054 | +} | |
12055 | + | |
12056 | +/* ---------------------------------------------------------------------- */ | |
12057 | + | |
12058 | +static unsigned int au_fhsm_poll(struct file *file, | |
12059 | + struct poll_table_struct *wait) | |
12060 | +{ | |
12061 | + unsigned int mask; | |
12062 | + struct au_sbinfo *sbinfo; | |
12063 | + struct au_fhsm *fhsm; | |
12064 | + | |
12065 | + mask = 0; | |
12066 | + sbinfo = file->private_data; | |
12067 | + fhsm = &sbinfo->si_fhsm; | |
12068 | + poll_wait(file, &fhsm->fhsm_wqh, wait); | |
12069 | + if (atomic_read(&fhsm->fhsm_readable)) | |
12070 | + mask = POLLIN /* | POLLRDNORM */; | |
12071 | + | |
12072 | + AuTraceErr((int)mask); | |
12073 | + return mask; | |
12074 | +} | |
12075 | + | |
12076 | +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr, | |
12077 | + struct aufs_stfs *stfs, __s16 brid) | |
12078 | +{ | |
12079 | + int err; | |
12080 | + | |
12081 | + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs)); | |
12082 | + if (!err) | |
12083 | + err = __put_user(brid, &stbr->brid); | |
12084 | + if (unlikely(err)) | |
12085 | + err = -EFAULT; | |
12086 | + | |
12087 | + return err; | |
12088 | +} | |
12089 | + | |
12090 | +static ssize_t au_fhsm_do_read(struct super_block *sb, | |
12091 | + struct aufs_stbr __user *stbr, size_t count) | |
12092 | +{ | |
12093 | + ssize_t err; | |
12094 | + int nstbr; | |
5afbbe0d | 12095 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
12096 | + struct au_branch *br; |
12097 | + struct au_br_fhsm *bf; | |
12098 | + | |
12099 | + /* except the bottom branch */ | |
12100 | + err = 0; | |
12101 | + nstbr = 0; | |
5afbbe0d AM |
12102 | + bbot = au_fhsm_bottom(sb); |
12103 | + for (bindex = 0; !err && bindex < bbot; bindex++) { | |
076b876e AM |
12104 | + br = au_sbr(sb, bindex); |
12105 | + if (!au_br_fhsm(br->br_perm)) | |
12106 | + continue; | |
12107 | + | |
12108 | + bf = br->br_fhsm; | |
12109 | + mutex_lock(&bf->bf_lock); | |
12110 | + if (bf->bf_readable) { | |
12111 | + err = -EFAULT; | |
12112 | + if (count >= sizeof(*stbr)) | |
12113 | + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs, | |
12114 | + br->br_id); | |
12115 | + if (!err) { | |
12116 | + bf->bf_readable = 0; | |
12117 | + count -= sizeof(*stbr); | |
12118 | + nstbr++; | |
12119 | + } | |
12120 | + } | |
12121 | + mutex_unlock(&bf->bf_lock); | |
12122 | + } | |
12123 | + if (!err) | |
12124 | + err = sizeof(*stbr) * nstbr; | |
12125 | + | |
12126 | + return err; | |
12127 | +} | |
12128 | + | |
12129 | +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count, | |
12130 | + loff_t *pos) | |
12131 | +{ | |
12132 | + ssize_t err; | |
12133 | + int readable; | |
5afbbe0d | 12134 | + aufs_bindex_t nfhsm, bindex, bbot; |
076b876e AM |
12135 | + struct au_sbinfo *sbinfo; |
12136 | + struct au_fhsm *fhsm; | |
12137 | + struct au_branch *br; | |
12138 | + struct super_block *sb; | |
12139 | + | |
12140 | + err = 0; | |
12141 | + sbinfo = file->private_data; | |
12142 | + fhsm = &sbinfo->si_fhsm; | |
12143 | +need_data: | |
12144 | + spin_lock_irq(&fhsm->fhsm_wqh.lock); | |
12145 | + if (!atomic_read(&fhsm->fhsm_readable)) { | |
12146 | + if (vfsub_file_flags(file) & O_NONBLOCK) | |
12147 | + err = -EAGAIN; | |
12148 | + else | |
12149 | + err = wait_event_interruptible_locked_irq | |
12150 | + (fhsm->fhsm_wqh, | |
12151 | + atomic_read(&fhsm->fhsm_readable)); | |
12152 | + } | |
12153 | + spin_unlock_irq(&fhsm->fhsm_wqh.lock); | |
12154 | + if (unlikely(err)) | |
12155 | + goto out; | |
12156 | + | |
12157 | + /* sb may already be dead */ | |
12158 | + au_rw_read_lock(&sbinfo->si_rwsem); | |
12159 | + readable = atomic_read(&fhsm->fhsm_readable); | |
12160 | + if (readable > 0) { | |
12161 | + sb = sbinfo->si_sb; | |
12162 | + AuDebugOn(!sb); | |
12163 | + /* exclude the bottom branch */ | |
12164 | + nfhsm = 0; | |
5afbbe0d AM |
12165 | + bbot = au_fhsm_bottom(sb); |
12166 | + for (bindex = 0; bindex < bbot; bindex++) { | |
076b876e AM |
12167 | + br = au_sbr(sb, bindex); |
12168 | + if (au_br_fhsm(br->br_perm)) | |
12169 | + nfhsm++; | |
12170 | + } | |
12171 | + err = -EMSGSIZE; | |
12172 | + if (nfhsm * sizeof(struct aufs_stbr) <= count) { | |
12173 | + atomic_set(&fhsm->fhsm_readable, 0); | |
12174 | + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf, | |
12175 | + count); | |
12176 | + } | |
12177 | + } | |
12178 | + au_rw_read_unlock(&sbinfo->si_rwsem); | |
12179 | + if (!readable) | |
12180 | + goto need_data; | |
12181 | + | |
12182 | +out: | |
12183 | + return err; | |
12184 | +} | |
12185 | + | |
12186 | +static int au_fhsm_release(struct inode *inode, struct file *file) | |
12187 | +{ | |
12188 | + struct au_sbinfo *sbinfo; | |
12189 | + struct au_fhsm *fhsm; | |
12190 | + | |
12191 | + /* sb may already be dead */ | |
12192 | + sbinfo = file->private_data; | |
12193 | + fhsm = &sbinfo->si_fhsm; | |
12194 | + spin_lock(&fhsm->fhsm_spin); | |
12195 | + fhsm->fhsm_pid = 0; | |
12196 | + spin_unlock(&fhsm->fhsm_spin); | |
12197 | + kobject_put(&sbinfo->si_kobj); | |
12198 | + | |
12199 | + return 0; | |
12200 | +} | |
12201 | + | |
12202 | +static const struct file_operations au_fhsm_fops = { | |
12203 | + .owner = THIS_MODULE, | |
12204 | + .llseek = noop_llseek, | |
12205 | + .read = au_fhsm_read, | |
12206 | + .poll = au_fhsm_poll, | |
12207 | + .release = au_fhsm_release | |
12208 | +}; | |
12209 | + | |
12210 | +int au_fhsm_fd(struct super_block *sb, int oflags) | |
12211 | +{ | |
12212 | + int err, fd; | |
12213 | + struct au_sbinfo *sbinfo; | |
12214 | + struct au_fhsm *fhsm; | |
12215 | + | |
12216 | + err = -EPERM; | |
12217 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
12218 | + goto out; | |
12219 | + | |
12220 | + err = -EINVAL; | |
12221 | + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK))) | |
12222 | + goto out; | |
12223 | + | |
12224 | + err = 0; | |
12225 | + sbinfo = au_sbi(sb); | |
12226 | + fhsm = &sbinfo->si_fhsm; | |
12227 | + spin_lock(&fhsm->fhsm_spin); | |
12228 | + if (!fhsm->fhsm_pid) | |
12229 | + fhsm->fhsm_pid = current->pid; | |
12230 | + else | |
12231 | + err = -EBUSY; | |
12232 | + spin_unlock(&fhsm->fhsm_spin); | |
12233 | + if (unlikely(err)) | |
12234 | + goto out; | |
12235 | + | |
12236 | + oflags |= O_RDONLY; | |
12237 | + /* oflags |= FMODE_NONOTIFY; */ | |
12238 | + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags); | |
12239 | + err = fd; | |
12240 | + if (unlikely(fd < 0)) | |
12241 | + goto out_pid; | |
12242 | + | |
12243 | + /* succeed reglardless 'fhsm' status */ | |
12244 | + kobject_get(&sbinfo->si_kobj); | |
12245 | + si_noflush_read_lock(sb); | |
12246 | + if (au_ftest_si(sbinfo, FHSM)) | |
12247 | + au_fhsm_wrote_all(sb, /*force*/0); | |
12248 | + si_read_unlock(sb); | |
12249 | + goto out; /* success */ | |
12250 | + | |
12251 | +out_pid: | |
12252 | + spin_lock(&fhsm->fhsm_spin); | |
12253 | + fhsm->fhsm_pid = 0; | |
12254 | + spin_unlock(&fhsm->fhsm_spin); | |
12255 | +out: | |
12256 | + AuTraceErr(err); | |
12257 | + return err; | |
12258 | +} | |
12259 | + | |
12260 | +/* ---------------------------------------------------------------------- */ | |
12261 | + | |
12262 | +int au_fhsm_br_alloc(struct au_branch *br) | |
12263 | +{ | |
12264 | + int err; | |
12265 | + | |
12266 | + err = 0; | |
12267 | + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS); | |
12268 | + if (br->br_fhsm) | |
12269 | + au_br_fhsm_init(br->br_fhsm); | |
12270 | + else | |
12271 | + err = -ENOMEM; | |
12272 | + | |
12273 | + return err; | |
12274 | +} | |
12275 | + | |
12276 | +/* ---------------------------------------------------------------------- */ | |
12277 | + | |
12278 | +void au_fhsm_fin(struct super_block *sb) | |
12279 | +{ | |
12280 | + au_fhsm_notify(sb, /*val*/-1); | |
12281 | +} | |
12282 | + | |
12283 | +void au_fhsm_init(struct au_sbinfo *sbinfo) | |
12284 | +{ | |
12285 | + struct au_fhsm *fhsm; | |
12286 | + | |
12287 | + fhsm = &sbinfo->si_fhsm; | |
12288 | + spin_lock_init(&fhsm->fhsm_spin); | |
12289 | + init_waitqueue_head(&fhsm->fhsm_wqh); | |
12290 | + atomic_set(&fhsm->fhsm_readable, 0); | |
12291 | + fhsm->fhsm_expire | |
12292 | + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC); | |
c1595e42 | 12293 | + fhsm->fhsm_bottom = -1; |
076b876e AM |
12294 | +} |
12295 | + | |
12296 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec) | |
12297 | +{ | |
12298 | + sbinfo->si_fhsm.fhsm_expire | |
12299 | + = msecs_to_jiffies(sec * MSEC_PER_SEC); | |
12300 | +} | |
12301 | + | |
12302 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo) | |
12303 | +{ | |
12304 | + unsigned int u; | |
12305 | + | |
12306 | + if (!au_ftest_si(sbinfo, FHSM)) | |
12307 | + return; | |
12308 | + | |
12309 | + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC; | |
12310 | + if (u != AUFS_FHSM_CACHE_DEF_SEC) | |
12311 | + seq_printf(seq, ",fhsm_sec=%u", u); | |
12312 | +} | |
7f207e10 AM |
12313 | diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c |
12314 | --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
12315 | +++ linux/fs/aufs/file.c 2017-05-06 22:16:52.778220093 +0200 |
12316 | @@ -0,0 +1,860 @@ | |
1facf9fc | 12317 | +/* |
a2654f78 | 12318 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 12319 | + * |
12320 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12321 | + * it under the terms of the GNU General Public License as published by | |
12322 | + * the Free Software Foundation; either version 2 of the License, or | |
12323 | + * (at your option) any later version. | |
dece6358 AM |
12324 | + * |
12325 | + * This program is distributed in the hope that it will be useful, | |
12326 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12327 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12328 | + * GNU General Public License for more details. | |
12329 | + * | |
12330 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12331 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 12332 | + */ |
12333 | + | |
12334 | +/* | |
4a4d8108 | 12335 | + * handling file/dir, and address_space operation |
1facf9fc | 12336 | + */ |
12337 | + | |
7eafdf33 AM |
12338 | +#ifdef CONFIG_AUFS_DEBUG |
12339 | +#include <linux/migrate.h> | |
12340 | +#endif | |
4a4d8108 | 12341 | +#include <linux/pagemap.h> |
1facf9fc | 12342 | +#include "aufs.h" |
12343 | + | |
4a4d8108 AM |
12344 | +/* drop flags for writing */ |
12345 | +unsigned int au_file_roflags(unsigned int flags) | |
12346 | +{ | |
12347 | + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC); | |
12348 | + flags |= O_RDONLY | O_NOATIME; | |
12349 | + return flags; | |
12350 | +} | |
12351 | + | |
12352 | +/* common functions to regular file and dir */ | |
12353 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 12354 | + struct file *file, int force_wr) |
1facf9fc | 12355 | +{ |
1308ab2a | 12356 | + struct file *h_file; |
4a4d8108 AM |
12357 | + struct dentry *h_dentry; |
12358 | + struct inode *h_inode; | |
12359 | + struct super_block *sb; | |
12360 | + struct au_branch *br; | |
12361 | + struct path h_path; | |
b912730e | 12362 | + int err; |
1facf9fc | 12363 | + |
4a4d8108 AM |
12364 | + /* a race condition can happen between open and unlink/rmdir */ |
12365 | + h_file = ERR_PTR(-ENOENT); | |
12366 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 12367 | + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry))) |
4a4d8108 | 12368 | + goto out; |
5527c038 | 12369 | + h_inode = d_inode(h_dentry); |
027c5e7a AM |
12370 | + spin_lock(&h_dentry->d_lock); |
12371 | + err = (!d_unhashed(dentry) && d_unlinked(h_dentry)) | |
5527c038 | 12372 | + /* || !d_inode(dentry)->i_nlink */ |
027c5e7a AM |
12373 | + ; |
12374 | + spin_unlock(&h_dentry->d_lock); | |
12375 | + if (unlikely(err)) | |
4a4d8108 | 12376 | + goto out; |
1facf9fc | 12377 | + |
4a4d8108 AM |
12378 | + sb = dentry->d_sb; |
12379 | + br = au_sbr(sb, bindex); | |
b912730e AM |
12380 | + err = au_br_test_oflag(flags, br); |
12381 | + h_file = ERR_PTR(err); | |
12382 | + if (unlikely(err)) | |
027c5e7a | 12383 | + goto out; |
1facf9fc | 12384 | + |
4a4d8108 | 12385 | + /* drop flags for writing */ |
5527c038 | 12386 | + if (au_test_ro(sb, bindex, d_inode(dentry))) { |
392086de AM |
12387 | + if (force_wr && !(flags & O_WRONLY)) |
12388 | + force_wr = 0; | |
4a4d8108 | 12389 | + flags = au_file_roflags(flags); |
392086de AM |
12390 | + if (force_wr) { |
12391 | + h_file = ERR_PTR(-EROFS); | |
12392 | + flags = au_file_roflags(flags); | |
12393 | + if (unlikely(vfsub_native_ro(h_inode) | |
12394 | + || IS_APPEND(h_inode))) | |
12395 | + goto out; | |
12396 | + flags &= ~O_ACCMODE; | |
12397 | + flags |= O_WRONLY; | |
12398 | + } | |
12399 | + } | |
4a4d8108 | 12400 | + flags &= ~O_CREAT; |
5afbbe0d | 12401 | + au_br_get(br); |
4a4d8108 | 12402 | + h_path.dentry = h_dentry; |
86dc4139 | 12403 | + h_path.mnt = au_br_mnt(br); |
38d290e6 | 12404 | + h_file = vfsub_dentry_open(&h_path, flags); |
4a4d8108 AM |
12405 | + if (IS_ERR(h_file)) |
12406 | + goto out_br; | |
dece6358 | 12407 | + |
b912730e | 12408 | + if (flags & __FMODE_EXEC) { |
4a4d8108 AM |
12409 | + err = deny_write_access(h_file); |
12410 | + if (unlikely(err)) { | |
12411 | + fput(h_file); | |
12412 | + h_file = ERR_PTR(err); | |
12413 | + goto out_br; | |
12414 | + } | |
12415 | + } | |
953406b4 | 12416 | + fsnotify_open(h_file); |
4a4d8108 | 12417 | + goto out; /* success */ |
1facf9fc | 12418 | + |
4f0767ce | 12419 | +out_br: |
5afbbe0d | 12420 | + au_br_put(br); |
4f0767ce | 12421 | +out: |
4a4d8108 AM |
12422 | + return h_file; |
12423 | +} | |
1308ab2a | 12424 | + |
076b876e AM |
12425 | +static int au_cmoo(struct dentry *dentry) |
12426 | +{ | |
12427 | + int err, cmoo; | |
12428 | + unsigned int udba; | |
12429 | + struct path h_path; | |
12430 | + struct au_pin pin; | |
12431 | + struct au_cp_generic cpg = { | |
12432 | + .dentry = dentry, | |
12433 | + .bdst = -1, | |
12434 | + .bsrc = -1, | |
12435 | + .len = -1, | |
12436 | + .pin = &pin, | |
12437 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
12438 | + }; | |
7e9cd9fe | 12439 | + struct inode *delegated; |
076b876e AM |
12440 | + struct super_block *sb; |
12441 | + struct au_sbinfo *sbinfo; | |
12442 | + struct au_fhsm *fhsm; | |
12443 | + pid_t pid; | |
12444 | + struct au_branch *br; | |
12445 | + struct dentry *parent; | |
12446 | + struct au_hinode *hdir; | |
12447 | + | |
12448 | + DiMustWriteLock(dentry); | |
5527c038 | 12449 | + IiMustWriteLock(d_inode(dentry)); |
076b876e AM |
12450 | + |
12451 | + err = 0; | |
12452 | + if (IS_ROOT(dentry)) | |
12453 | + goto out; | |
5afbbe0d | 12454 | + cpg.bsrc = au_dbtop(dentry); |
076b876e AM |
12455 | + if (!cpg.bsrc) |
12456 | + goto out; | |
12457 | + | |
12458 | + sb = dentry->d_sb; | |
12459 | + sbinfo = au_sbi(sb); | |
12460 | + fhsm = &sbinfo->si_fhsm; | |
12461 | + pid = au_fhsm_pid(fhsm); | |
12462 | + if (pid | |
12463 | + && (current->pid == pid | |
12464 | + || current->real_parent->pid == pid)) | |
12465 | + goto out; | |
12466 | + | |
12467 | + br = au_sbr(sb, cpg.bsrc); | |
12468 | + cmoo = au_br_cmoo(br->br_perm); | |
12469 | + if (!cmoo) | |
12470 | + goto out; | |
7e9cd9fe | 12471 | + if (!d_is_reg(dentry)) |
076b876e AM |
12472 | + cmoo &= AuBrAttr_COO_ALL; |
12473 | + if (!cmoo) | |
12474 | + goto out; | |
12475 | + | |
12476 | + parent = dget_parent(dentry); | |
12477 | + di_write_lock_parent(parent); | |
12478 | + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1); | |
12479 | + cpg.bdst = err; | |
12480 | + if (unlikely(err < 0)) { | |
12481 | + err = 0; /* there is no upper writable branch */ | |
12482 | + goto out_dgrade; | |
12483 | + } | |
12484 | + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst); | |
12485 | + | |
12486 | + /* do not respect the coo attrib for the target branch */ | |
12487 | + err = au_cpup_dirs(dentry, cpg.bdst); | |
12488 | + if (unlikely(err)) | |
12489 | + goto out_dgrade; | |
12490 | + | |
12491 | + di_downgrade_lock(parent, AuLock_IR); | |
12492 | + udba = au_opt_udba(sb); | |
12493 | + err = au_pin(&pin, dentry, cpg.bdst, udba, | |
12494 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12495 | + if (unlikely(err)) | |
12496 | + goto out_parent; | |
12497 | + | |
12498 | + err = au_sio_cpup_simple(&cpg); | |
12499 | + au_unpin(&pin); | |
12500 | + if (unlikely(err)) | |
12501 | + goto out_parent; | |
12502 | + if (!(cmoo & AuBrWAttr_MOO)) | |
12503 | + goto out_parent; /* success */ | |
12504 | + | |
12505 | + err = au_pin(&pin, dentry, cpg.bsrc, udba, | |
12506 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12507 | + if (unlikely(err)) | |
12508 | + goto out_parent; | |
12509 | + | |
12510 | + h_path.mnt = au_br_mnt(br); | |
12511 | + h_path.dentry = au_h_dptr(dentry, cpg.bsrc); | |
5527c038 | 12512 | + hdir = au_hi(d_inode(parent), cpg.bsrc); |
076b876e AM |
12513 | + delegated = NULL; |
12514 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1); | |
12515 | + au_unpin(&pin); | |
12516 | + /* todo: keep h_dentry or not? */ | |
12517 | + if (unlikely(err == -EWOULDBLOCK)) { | |
12518 | + pr_warn("cannot retry for NFSv4 delegation" | |
12519 | + " for an internal unlink\n"); | |
12520 | + iput(delegated); | |
12521 | + } | |
12522 | + if (unlikely(err)) { | |
12523 | + pr_err("unlink %pd after coo failed (%d), ignored\n", | |
12524 | + dentry, err); | |
12525 | + err = 0; | |
12526 | + } | |
12527 | + goto out_parent; /* success */ | |
12528 | + | |
12529 | +out_dgrade: | |
12530 | + di_downgrade_lock(parent, AuLock_IR); | |
12531 | +out_parent: | |
12532 | + di_read_unlock(parent, AuLock_IR); | |
12533 | + dput(parent); | |
12534 | +out: | |
12535 | + AuTraceErr(err); | |
12536 | + return err; | |
12537 | +} | |
12538 | + | |
b912730e | 12539 | +int au_do_open(struct file *file, struct au_do_open_args *args) |
1facf9fc | 12540 | +{ |
b912730e | 12541 | + int err, no_lock = args->no_lock; |
1facf9fc | 12542 | + struct dentry *dentry; |
076b876e | 12543 | + struct au_finfo *finfo; |
1308ab2a | 12544 | + |
b912730e AM |
12545 | + if (!no_lock) |
12546 | + err = au_finfo_init(file, args->fidir); | |
12547 | + else { | |
12548 | + lockdep_off(); | |
12549 | + err = au_finfo_init(file, args->fidir); | |
12550 | + lockdep_on(); | |
12551 | + } | |
4a4d8108 AM |
12552 | + if (unlikely(err)) |
12553 | + goto out; | |
1facf9fc | 12554 | + |
2000de60 | 12555 | + dentry = file->f_path.dentry; |
b912730e AM |
12556 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
12557 | + if (!no_lock) { | |
12558 | + di_write_lock_child(dentry); | |
12559 | + err = au_cmoo(dentry); | |
12560 | + di_downgrade_lock(dentry, AuLock_IR); | |
12561 | + if (!err) | |
12562 | + err = args->open(file, vfsub_file_flags(file), NULL); | |
12563 | + di_read_unlock(dentry, AuLock_IR); | |
12564 | + } else { | |
12565 | + err = au_cmoo(dentry); | |
12566 | + if (!err) | |
12567 | + err = args->open(file, vfsub_file_flags(file), | |
12568 | + args->h_file); | |
5afbbe0d | 12569 | + if (!err && au_fbtop(file) != au_dbtop(dentry)) |
b912730e AM |
12570 | + /* |
12571 | + * cmoo happens after h_file was opened. | |
12572 | + * need to refresh file later. | |
12573 | + */ | |
12574 | + atomic_dec(&au_fi(file)->fi_generation); | |
12575 | + } | |
1facf9fc | 12576 | + |
076b876e AM |
12577 | + finfo = au_fi(file); |
12578 | + if (!err) { | |
12579 | + finfo->fi_file = file; | |
12580 | + au_sphl_add(&finfo->fi_hlist, | |
2000de60 | 12581 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); |
076b876e | 12582 | + } |
b912730e AM |
12583 | + if (!no_lock) |
12584 | + fi_write_unlock(file); | |
12585 | + else { | |
12586 | + lockdep_off(); | |
12587 | + fi_write_unlock(file); | |
12588 | + lockdep_on(); | |
12589 | + } | |
4a4d8108 | 12590 | + if (unlikely(err)) { |
076b876e | 12591 | + finfo->fi_hdir = NULL; |
f0c0a007 | 12592 | + au_finfo_fin(file, /*atonce*/0); |
1308ab2a | 12593 | + } |
4a4d8108 | 12594 | + |
4f0767ce | 12595 | +out: |
1308ab2a | 12596 | + return err; |
12597 | +} | |
dece6358 | 12598 | + |
4a4d8108 | 12599 | +int au_reopen_nondir(struct file *file) |
1308ab2a | 12600 | +{ |
4a4d8108 | 12601 | + int err; |
5afbbe0d | 12602 | + aufs_bindex_t btop; |
4a4d8108 AM |
12603 | + struct dentry *dentry; |
12604 | + struct file *h_file, *h_file_tmp; | |
1308ab2a | 12605 | + |
2000de60 | 12606 | + dentry = file->f_path.dentry; |
5afbbe0d | 12607 | + btop = au_dbtop(dentry); |
4a4d8108 | 12608 | + h_file_tmp = NULL; |
5afbbe0d | 12609 | + if (au_fbtop(file) == btop) { |
4a4d8108 AM |
12610 | + h_file = au_hf_top(file); |
12611 | + if (file->f_mode == h_file->f_mode) | |
12612 | + return 0; /* success */ | |
12613 | + h_file_tmp = h_file; | |
12614 | + get_file(h_file_tmp); | |
5afbbe0d | 12615 | + au_set_h_fptr(file, btop, NULL); |
4a4d8108 AM |
12616 | + } |
12617 | + AuDebugOn(au_fi(file)->fi_hdir); | |
86dc4139 AM |
12618 | + /* |
12619 | + * it can happen | |
12620 | + * file exists on both of rw and ro | |
5afbbe0d | 12621 | + * open --> dbtop and fbtop are both 0 |
86dc4139 AM |
12622 | + * prepend a branch as rw, "rw" become ro |
12623 | + * remove rw/file | |
12624 | + * delete the top branch, "rw" becomes rw again | |
5afbbe0d AM |
12625 | + * --> dbtop is 1, fbtop is still 0 |
12626 | + * write --> fbtop is 0 but dbtop is 1 | |
86dc4139 | 12627 | + */ |
5afbbe0d | 12628 | + /* AuDebugOn(au_fbtop(file) < btop); */ |
1308ab2a | 12629 | + |
5afbbe0d | 12630 | + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC, |
392086de | 12631 | + file, /*force_wr*/0); |
4a4d8108 | 12632 | + err = PTR_ERR(h_file); |
86dc4139 AM |
12633 | + if (IS_ERR(h_file)) { |
12634 | + if (h_file_tmp) { | |
5afbbe0d AM |
12635 | + au_sbr_get(dentry->d_sb, btop); |
12636 | + au_set_h_fptr(file, btop, h_file_tmp); | |
86dc4139 AM |
12637 | + h_file_tmp = NULL; |
12638 | + } | |
4a4d8108 | 12639 | + goto out; /* todo: close all? */ |
86dc4139 | 12640 | + } |
4a4d8108 AM |
12641 | + |
12642 | + err = 0; | |
5afbbe0d AM |
12643 | + au_set_fbtop(file, btop); |
12644 | + au_set_h_fptr(file, btop, h_file); | |
4a4d8108 AM |
12645 | + au_update_figen(file); |
12646 | + /* todo: necessary? */ | |
12647 | + /* file->f_ra = h_file->f_ra; */ | |
12648 | + | |
4f0767ce | 12649 | +out: |
4a4d8108 AM |
12650 | + if (h_file_tmp) |
12651 | + fput(h_file_tmp); | |
12652 | + return err; | |
1facf9fc | 12653 | +} |
12654 | + | |
1308ab2a | 12655 | +/* ---------------------------------------------------------------------- */ |
12656 | + | |
4a4d8108 AM |
12657 | +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt, |
12658 | + struct dentry *hi_wh) | |
1facf9fc | 12659 | +{ |
4a4d8108 | 12660 | + int err; |
5afbbe0d | 12661 | + aufs_bindex_t btop; |
4a4d8108 AM |
12662 | + struct au_dinfo *dinfo; |
12663 | + struct dentry *h_dentry; | |
12664 | + struct au_hdentry *hdp; | |
1facf9fc | 12665 | + |
2000de60 | 12666 | + dinfo = au_di(file->f_path.dentry); |
4a4d8108 | 12667 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
dece6358 | 12668 | + |
5afbbe0d AM |
12669 | + btop = dinfo->di_btop; |
12670 | + dinfo->di_btop = btgt; | |
12671 | + hdp = au_hdentry(dinfo, btgt); | |
12672 | + h_dentry = hdp->hd_dentry; | |
12673 | + hdp->hd_dentry = hi_wh; | |
4a4d8108 | 12674 | + err = au_reopen_nondir(file); |
5afbbe0d AM |
12675 | + hdp->hd_dentry = h_dentry; |
12676 | + dinfo->di_btop = btop; | |
1facf9fc | 12677 | + |
1facf9fc | 12678 | + return err; |
12679 | +} | |
12680 | + | |
4a4d8108 | 12681 | +static int au_ready_to_write_wh(struct file *file, loff_t len, |
86dc4139 | 12682 | + aufs_bindex_t bcpup, struct au_pin *pin) |
1facf9fc | 12683 | +{ |
4a4d8108 | 12684 | + int err; |
027c5e7a | 12685 | + struct inode *inode, *h_inode; |
c2b27bf2 AM |
12686 | + struct dentry *h_dentry, *hi_wh; |
12687 | + struct au_cp_generic cpg = { | |
2000de60 | 12688 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12689 | + .bdst = bcpup, |
12690 | + .bsrc = -1, | |
12691 | + .len = len, | |
12692 | + .pin = pin | |
12693 | + }; | |
1facf9fc | 12694 | + |
5afbbe0d | 12695 | + au_update_dbtop(cpg.dentry); |
5527c038 | 12696 | + inode = d_inode(cpg.dentry); |
027c5e7a | 12697 | + h_inode = NULL; |
5afbbe0d AM |
12698 | + if (au_dbtop(cpg.dentry) <= bcpup |
12699 | + && au_dbbot(cpg.dentry) >= bcpup) { | |
c2b27bf2 | 12700 | + h_dentry = au_h_dptr(cpg.dentry, bcpup); |
5527c038 JR |
12701 | + if (h_dentry && d_is_positive(h_dentry)) |
12702 | + h_inode = d_inode(h_dentry); | |
027c5e7a | 12703 | + } |
4a4d8108 | 12704 | + hi_wh = au_hi_wh(inode, bcpup); |
027c5e7a | 12705 | + if (!hi_wh && !h_inode) |
c2b27bf2 | 12706 | + err = au_sio_cpup_wh(&cpg, file); |
4a4d8108 AM |
12707 | + else |
12708 | + /* already copied-up after unlink */ | |
12709 | + err = au_reopen_wh(file, bcpup, hi_wh); | |
1facf9fc | 12710 | + |
4a4d8108 | 12711 | + if (!err |
38d290e6 JR |
12712 | + && (inode->i_nlink > 1 |
12713 | + || (inode->i_state & I_LINKABLE)) | |
c2b27bf2 AM |
12714 | + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK)) |
12715 | + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup)); | |
1308ab2a | 12716 | + |
dece6358 | 12717 | + return err; |
1facf9fc | 12718 | +} |
12719 | + | |
4a4d8108 AM |
12720 | +/* |
12721 | + * prepare the @file for writing. | |
12722 | + */ | |
12723 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin) | |
1facf9fc | 12724 | +{ |
4a4d8108 | 12725 | + int err; |
5afbbe0d | 12726 | + aufs_bindex_t dbtop; |
c1595e42 | 12727 | + struct dentry *parent; |
86dc4139 | 12728 | + struct inode *inode; |
1facf9fc | 12729 | + struct super_block *sb; |
4a4d8108 | 12730 | + struct file *h_file; |
c2b27bf2 | 12731 | + struct au_cp_generic cpg = { |
2000de60 | 12732 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12733 | + .bdst = -1, |
12734 | + .bsrc = -1, | |
12735 | + .len = len, | |
12736 | + .pin = pin, | |
12737 | + .flags = AuCpup_DTIME | |
12738 | + }; | |
1facf9fc | 12739 | + |
c2b27bf2 | 12740 | + sb = cpg.dentry->d_sb; |
5527c038 | 12741 | + inode = d_inode(cpg.dentry); |
5afbbe0d | 12742 | + cpg.bsrc = au_fbtop(file); |
c2b27bf2 | 12743 | + err = au_test_ro(sb, cpg.bsrc, inode); |
4a4d8108 | 12744 | + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) { |
c2b27bf2 AM |
12745 | + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE, |
12746 | + /*flags*/0); | |
1facf9fc | 12747 | + goto out; |
4a4d8108 | 12748 | + } |
1facf9fc | 12749 | + |
027c5e7a | 12750 | + /* need to cpup or reopen */ |
c2b27bf2 | 12751 | + parent = dget_parent(cpg.dentry); |
4a4d8108 | 12752 | + di_write_lock_parent(parent); |
c2b27bf2 AM |
12753 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12754 | + cpg.bdst = err; | |
4a4d8108 AM |
12755 | + if (unlikely(err < 0)) |
12756 | + goto out_dgrade; | |
12757 | + err = 0; | |
12758 | + | |
c2b27bf2 AM |
12759 | + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) { |
12760 | + err = au_cpup_dirs(cpg.dentry, cpg.bdst); | |
1facf9fc | 12761 | + if (unlikely(err)) |
4a4d8108 AM |
12762 | + goto out_dgrade; |
12763 | + } | |
12764 | + | |
c2b27bf2 | 12765 | + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 AM |
12766 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
12767 | + if (unlikely(err)) | |
12768 | + goto out_dgrade; | |
12769 | + | |
5afbbe0d AM |
12770 | + dbtop = au_dbtop(cpg.dentry); |
12771 | + if (dbtop <= cpg.bdst) | |
c2b27bf2 | 12772 | + cpg.bsrc = cpg.bdst; |
027c5e7a | 12773 | + |
5afbbe0d | 12774 | + if (dbtop <= cpg.bdst /* just reopen */ |
c2b27bf2 | 12775 | + || !d_unhashed(cpg.dentry) /* copyup and reopen */ |
027c5e7a | 12776 | + ) { |
392086de | 12777 | + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0); |
86dc4139 | 12778 | + if (IS_ERR(h_file)) |
027c5e7a | 12779 | + err = PTR_ERR(h_file); |
86dc4139 | 12780 | + else { |
027c5e7a | 12781 | + di_downgrade_lock(parent, AuLock_IR); |
5afbbe0d | 12782 | + if (dbtop > cpg.bdst) |
c2b27bf2 | 12783 | + err = au_sio_cpup_simple(&cpg); |
027c5e7a AM |
12784 | + if (!err) |
12785 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 12786 | + au_h_open_post(cpg.dentry, cpg.bsrc, h_file); |
027c5e7a | 12787 | + } |
027c5e7a AM |
12788 | + } else { /* copyup as wh and reopen */ |
12789 | + /* | |
12790 | + * since writable hfsplus branch is not supported, | |
12791 | + * h_open_pre/post() are unnecessary. | |
12792 | + */ | |
c2b27bf2 | 12793 | + err = au_ready_to_write_wh(file, len, cpg.bdst, pin); |
4a4d8108 | 12794 | + di_downgrade_lock(parent, AuLock_IR); |
4a4d8108 | 12795 | + } |
4a4d8108 AM |
12796 | + |
12797 | + if (!err) { | |
12798 | + au_pin_set_parent_lflag(pin, /*lflag*/0); | |
12799 | + goto out_dput; /* success */ | |
12800 | + } | |
12801 | + au_unpin(pin); | |
12802 | + goto out_unlock; | |
1facf9fc | 12803 | + |
4f0767ce | 12804 | +out_dgrade: |
4a4d8108 | 12805 | + di_downgrade_lock(parent, AuLock_IR); |
4f0767ce | 12806 | +out_unlock: |
4a4d8108 | 12807 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12808 | +out_dput: |
4a4d8108 | 12809 | + dput(parent); |
4f0767ce | 12810 | +out: |
1facf9fc | 12811 | + return err; |
12812 | +} | |
12813 | + | |
4a4d8108 AM |
12814 | +/* ---------------------------------------------------------------------- */ |
12815 | + | |
12816 | +int au_do_flush(struct file *file, fl_owner_t id, | |
12817 | + int (*flush)(struct file *file, fl_owner_t id)) | |
1facf9fc | 12818 | +{ |
4a4d8108 | 12819 | + int err; |
1facf9fc | 12820 | + struct super_block *sb; |
4a4d8108 | 12821 | + struct inode *inode; |
1facf9fc | 12822 | + |
c06a8ce3 AM |
12823 | + inode = file_inode(file); |
12824 | + sb = inode->i_sb; | |
4a4d8108 AM |
12825 | + si_noflush_read_lock(sb); |
12826 | + fi_read_lock(file); | |
b752ccd1 | 12827 | + ii_read_lock_child(inode); |
1facf9fc | 12828 | + |
4a4d8108 AM |
12829 | + err = flush(file, id); |
12830 | + au_cpup_attr_timesizes(inode); | |
1facf9fc | 12831 | + |
b752ccd1 | 12832 | + ii_read_unlock(inode); |
4a4d8108 | 12833 | + fi_read_unlock(file); |
1308ab2a | 12834 | + si_read_unlock(sb); |
dece6358 | 12835 | + return err; |
1facf9fc | 12836 | +} |
12837 | + | |
4a4d8108 AM |
12838 | +/* ---------------------------------------------------------------------- */ |
12839 | + | |
12840 | +static int au_file_refresh_by_inode(struct file *file, int *need_reopen) | |
1facf9fc | 12841 | +{ |
4a4d8108 | 12842 | + int err; |
4a4d8108 AM |
12843 | + struct au_pin pin; |
12844 | + struct au_finfo *finfo; | |
c2b27bf2 | 12845 | + struct dentry *parent, *hi_wh; |
4a4d8108 | 12846 | + struct inode *inode; |
1facf9fc | 12847 | + struct super_block *sb; |
c2b27bf2 | 12848 | + struct au_cp_generic cpg = { |
2000de60 | 12849 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12850 | + .bdst = -1, |
12851 | + .bsrc = -1, | |
12852 | + .len = -1, | |
12853 | + .pin = &pin, | |
12854 | + .flags = AuCpup_DTIME | |
12855 | + }; | |
1facf9fc | 12856 | + |
4a4d8108 AM |
12857 | + FiMustWriteLock(file); |
12858 | + | |
12859 | + err = 0; | |
12860 | + finfo = au_fi(file); | |
c2b27bf2 | 12861 | + sb = cpg.dentry->d_sb; |
5527c038 | 12862 | + inode = d_inode(cpg.dentry); |
5afbbe0d | 12863 | + cpg.bdst = au_ibtop(inode); |
c2b27bf2 | 12864 | + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry)) |
1308ab2a | 12865 | + goto out; |
dece6358 | 12866 | + |
c2b27bf2 AM |
12867 | + parent = dget_parent(cpg.dentry); |
12868 | + if (au_test_ro(sb, cpg.bdst, inode)) { | |
4a4d8108 | 12869 | + di_read_lock_parent(parent, !AuLock_IR); |
c2b27bf2 AM |
12870 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12871 | + cpg.bdst = err; | |
4a4d8108 AM |
12872 | + di_read_unlock(parent, !AuLock_IR); |
12873 | + if (unlikely(err < 0)) | |
12874 | + goto out_parent; | |
12875 | + err = 0; | |
1facf9fc | 12876 | + } |
1facf9fc | 12877 | + |
4a4d8108 | 12878 | + di_read_lock_parent(parent, AuLock_IR); |
c2b27bf2 | 12879 | + hi_wh = au_hi_wh(inode, cpg.bdst); |
7f207e10 AM |
12880 | + if (!S_ISDIR(inode->i_mode) |
12881 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4a4d8108 | 12882 | + && au_plink_test(inode) |
c2b27bf2 | 12883 | + && !d_unhashed(cpg.dentry) |
5afbbe0d | 12884 | + && cpg.bdst < au_dbtop(cpg.dentry)) { |
c2b27bf2 | 12885 | + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst); |
4a4d8108 AM |
12886 | + if (unlikely(err)) |
12887 | + goto out_unlock; | |
12888 | + | |
12889 | + /* always superio. */ | |
c2b27bf2 | 12890 | + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 | 12891 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
367653fa | 12892 | + if (!err) { |
c2b27bf2 | 12893 | + err = au_sio_cpup_simple(&cpg); |
367653fa AM |
12894 | + au_unpin(&pin); |
12895 | + } | |
4a4d8108 AM |
12896 | + } else if (hi_wh) { |
12897 | + /* already copied-up after unlink */ | |
c2b27bf2 | 12898 | + err = au_reopen_wh(file, cpg.bdst, hi_wh); |
4a4d8108 AM |
12899 | + *need_reopen = 0; |
12900 | + } | |
1facf9fc | 12901 | + |
4f0767ce | 12902 | +out_unlock: |
4a4d8108 | 12903 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12904 | +out_parent: |
4a4d8108 | 12905 | + dput(parent); |
4f0767ce | 12906 | +out: |
1308ab2a | 12907 | + return err; |
dece6358 | 12908 | +} |
1facf9fc | 12909 | + |
4a4d8108 | 12910 | +static void au_do_refresh_dir(struct file *file) |
dece6358 | 12911 | +{ |
f0c0a007 | 12912 | + int execed; |
5afbbe0d | 12913 | + aufs_bindex_t bindex, bbot, new_bindex, brid; |
4a4d8108 AM |
12914 | + struct au_hfile *p, tmp, *q; |
12915 | + struct au_finfo *finfo; | |
1308ab2a | 12916 | + struct super_block *sb; |
4a4d8108 | 12917 | + struct au_fidir *fidir; |
1facf9fc | 12918 | + |
4a4d8108 | 12919 | + FiMustWriteLock(file); |
1facf9fc | 12920 | + |
2000de60 | 12921 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 AM |
12922 | + finfo = au_fi(file); |
12923 | + fidir = finfo->fi_hdir; | |
12924 | + AuDebugOn(!fidir); | |
12925 | + p = fidir->fd_hfile + finfo->fi_btop; | |
12926 | + brid = p->hf_br->br_id; | |
5afbbe0d AM |
12927 | + bbot = fidir->fd_bbot; |
12928 | + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) { | |
4a4d8108 AM |
12929 | + if (!p->hf_file) |
12930 | + continue; | |
1308ab2a | 12931 | + |
4a4d8108 AM |
12932 | + new_bindex = au_br_index(sb, p->hf_br->br_id); |
12933 | + if (new_bindex == bindex) | |
12934 | + continue; | |
12935 | + if (new_bindex < 0) { | |
12936 | + au_set_h_fptr(file, bindex, NULL); | |
12937 | + continue; | |
12938 | + } | |
1308ab2a | 12939 | + |
4a4d8108 AM |
12940 | + /* swap two lower inode, and loop again */ |
12941 | + q = fidir->fd_hfile + new_bindex; | |
12942 | + tmp = *q; | |
12943 | + *q = *p; | |
12944 | + *p = tmp; | |
12945 | + if (tmp.hf_file) { | |
12946 | + bindex--; | |
12947 | + p--; | |
12948 | + } | |
12949 | + } | |
1308ab2a | 12950 | + |
f0c0a007 | 12951 | + execed = vfsub_file_execed(file); |
4a4d8108 | 12952 | + p = fidir->fd_hfile; |
2000de60 | 12953 | + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) { |
5afbbe0d AM |
12954 | + bbot = au_sbbot(sb); |
12955 | + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot; | |
4a4d8108 AM |
12956 | + finfo->fi_btop++, p++) |
12957 | + if (p->hf_file) { | |
c06a8ce3 | 12958 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12959 | + break; |
f0c0a007 | 12960 | + au_hfput(p, execed); |
4a4d8108 AM |
12961 | + } |
12962 | + } else { | |
5afbbe0d AM |
12963 | + bbot = au_br_index(sb, brid); |
12964 | + for (finfo->fi_btop = 0; finfo->fi_btop < bbot; | |
4a4d8108 AM |
12965 | + finfo->fi_btop++, p++) |
12966 | + if (p->hf_file) | |
f0c0a007 | 12967 | + au_hfput(p, execed); |
5afbbe0d | 12968 | + bbot = au_sbbot(sb); |
4a4d8108 | 12969 | + } |
1308ab2a | 12970 | + |
5afbbe0d AM |
12971 | + p = fidir->fd_hfile + bbot; |
12972 | + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop; | |
4a4d8108 AM |
12973 | + fidir->fd_bbot--, p--) |
12974 | + if (p->hf_file) { | |
c06a8ce3 | 12975 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12976 | + break; |
f0c0a007 | 12977 | + au_hfput(p, execed); |
4a4d8108 AM |
12978 | + } |
12979 | + AuDebugOn(fidir->fd_bbot < finfo->fi_btop); | |
1308ab2a | 12980 | +} |
12981 | + | |
4a4d8108 AM |
12982 | +/* |
12983 | + * after branch manipulating, refresh the file. | |
12984 | + */ | |
12985 | +static int refresh_file(struct file *file, int (*reopen)(struct file *file)) | |
1facf9fc | 12986 | +{ |
e2f27e51 | 12987 | + int err, need_reopen, nbr; |
5afbbe0d | 12988 | + aufs_bindex_t bbot, bindex; |
4a4d8108 | 12989 | + struct dentry *dentry; |
e2f27e51 | 12990 | + struct super_block *sb; |
1308ab2a | 12991 | + struct au_finfo *finfo; |
4a4d8108 | 12992 | + struct au_hfile *hfile; |
1facf9fc | 12993 | + |
2000de60 | 12994 | + dentry = file->f_path.dentry; |
e2f27e51 AM |
12995 | + sb = dentry->d_sb; |
12996 | + nbr = au_sbbot(sb) + 1; | |
1308ab2a | 12997 | + finfo = au_fi(file); |
4a4d8108 AM |
12998 | + if (!finfo->fi_hdir) { |
12999 | + hfile = &finfo->fi_htop; | |
13000 | + AuDebugOn(!hfile->hf_file); | |
e2f27e51 | 13001 | + bindex = au_br_index(sb, hfile->hf_br->br_id); |
4a4d8108 AM |
13002 | + AuDebugOn(bindex < 0); |
13003 | + if (bindex != finfo->fi_btop) | |
5afbbe0d | 13004 | + au_set_fbtop(file, bindex); |
4a4d8108 | 13005 | + } else { |
e2f27e51 | 13006 | + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0); |
4a4d8108 AM |
13007 | + if (unlikely(err)) |
13008 | + goto out; | |
13009 | + au_do_refresh_dir(file); | |
13010 | + } | |
1facf9fc | 13011 | + |
4a4d8108 AM |
13012 | + err = 0; |
13013 | + need_reopen = 1; | |
13014 | + if (!au_test_mmapped(file)) | |
13015 | + err = au_file_refresh_by_inode(file, &need_reopen); | |
e2f27e51 AM |
13016 | + if (finfo->fi_hdir) |
13017 | + /* harmless if err */ | |
13018 | + au_fidir_realloc(finfo, nbr, /*may_shrink*/1); | |
027c5e7a | 13019 | + if (!err && need_reopen && !d_unlinked(dentry)) |
4a4d8108 AM |
13020 | + err = reopen(file); |
13021 | + if (!err) { | |
13022 | + au_update_figen(file); | |
13023 | + goto out; /* success */ | |
13024 | + } | |
13025 | + | |
13026 | + /* error, close all lower files */ | |
13027 | + if (finfo->fi_hdir) { | |
5afbbe0d AM |
13028 | + bbot = au_fbbot_dir(file); |
13029 | + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) | |
4a4d8108 AM |
13030 | + au_set_h_fptr(file, bindex, NULL); |
13031 | + } | |
1facf9fc | 13032 | + |
4f0767ce | 13033 | +out: |
1facf9fc | 13034 | + return err; |
13035 | +} | |
13036 | + | |
4a4d8108 AM |
13037 | +/* common function to regular file and dir */ |
13038 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
521ced18 | 13039 | + int wlock, unsigned int fi_lsc) |
dece6358 | 13040 | +{ |
1308ab2a | 13041 | + int err; |
4a4d8108 | 13042 | + unsigned int sigen, figen; |
5afbbe0d | 13043 | + aufs_bindex_t btop; |
4a4d8108 AM |
13044 | + unsigned char pseudo_link; |
13045 | + struct dentry *dentry; | |
13046 | + struct inode *inode; | |
1facf9fc | 13047 | + |
4a4d8108 | 13048 | + err = 0; |
2000de60 | 13049 | + dentry = file->f_path.dentry; |
5527c038 | 13050 | + inode = d_inode(dentry); |
4a4d8108 | 13051 | + sigen = au_sigen(dentry->d_sb); |
521ced18 | 13052 | + fi_write_lock_nested(file, fi_lsc); |
4a4d8108 | 13053 | + figen = au_figen(file); |
521ced18 JR |
13054 | + if (!fi_lsc) |
13055 | + di_write_lock_child(dentry); | |
13056 | + else | |
13057 | + di_write_lock_child2(dentry); | |
5afbbe0d AM |
13058 | + btop = au_dbtop(dentry); |
13059 | + pseudo_link = (btop != au_ibtop(inode)); | |
13060 | + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) { | |
4a4d8108 AM |
13061 | + if (!wlock) { |
13062 | + di_downgrade_lock(dentry, AuLock_IR); | |
13063 | + fi_downgrade_lock(file); | |
13064 | + } | |
13065 | + goto out; /* success */ | |
13066 | + } | |
dece6358 | 13067 | + |
4a4d8108 | 13068 | + AuDbg("sigen %d, figen %d\n", sigen, figen); |
027c5e7a | 13069 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 | 13070 | + err = au_reval_dpath(dentry, sigen); |
027c5e7a | 13071 | + AuDebugOn(!err && au_digen_test(dentry, sigen)); |
4a4d8108 | 13072 | + } |
dece6358 | 13073 | + |
027c5e7a AM |
13074 | + if (!err) |
13075 | + err = refresh_file(file, reopen); | |
4a4d8108 AM |
13076 | + if (!err) { |
13077 | + if (!wlock) { | |
13078 | + di_downgrade_lock(dentry, AuLock_IR); | |
13079 | + fi_downgrade_lock(file); | |
13080 | + } | |
13081 | + } else { | |
13082 | + di_write_unlock(dentry); | |
13083 | + fi_write_unlock(file); | |
13084 | + } | |
1facf9fc | 13085 | + |
4f0767ce | 13086 | +out: |
1308ab2a | 13087 | + return err; |
13088 | +} | |
1facf9fc | 13089 | + |
4a4d8108 AM |
13090 | +/* ---------------------------------------------------------------------- */ |
13091 | + | |
13092 | +/* cf. aufs_nopage() */ | |
13093 | +/* for madvise(2) */ | |
13094 | +static int aufs_readpage(struct file *file __maybe_unused, struct page *page) | |
1308ab2a | 13095 | +{ |
4a4d8108 AM |
13096 | + unlock_page(page); |
13097 | + return 0; | |
13098 | +} | |
1facf9fc | 13099 | + |
4a4d8108 | 13100 | +/* it will never be called, but necessary to support O_DIRECT */ |
5afbbe0d | 13101 | +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) |
4a4d8108 | 13102 | +{ BUG(); return 0; } |
1facf9fc | 13103 | + |
4a4d8108 AM |
13104 | +/* they will never be called. */ |
13105 | +#ifdef CONFIG_AUFS_DEBUG | |
13106 | +static int aufs_write_begin(struct file *file, struct address_space *mapping, | |
13107 | + loff_t pos, unsigned len, unsigned flags, | |
13108 | + struct page **pagep, void **fsdata) | |
13109 | +{ AuUnsupport(); return 0; } | |
13110 | +static int aufs_write_end(struct file *file, struct address_space *mapping, | |
13111 | + loff_t pos, unsigned len, unsigned copied, | |
13112 | + struct page *page, void *fsdata) | |
13113 | +{ AuUnsupport(); return 0; } | |
13114 | +static int aufs_writepage(struct page *page, struct writeback_control *wbc) | |
13115 | +{ AuUnsupport(); return 0; } | |
1308ab2a | 13116 | + |
4a4d8108 AM |
13117 | +static int aufs_set_page_dirty(struct page *page) |
13118 | +{ AuUnsupport(); return 0; } | |
392086de AM |
13119 | +static void aufs_invalidatepage(struct page *page, unsigned int offset, |
13120 | + unsigned int length) | |
4a4d8108 AM |
13121 | +{ AuUnsupport(); } |
13122 | +static int aufs_releasepage(struct page *page, gfp_t gfp) | |
13123 | +{ AuUnsupport(); return 0; } | |
79b8bda9 | 13124 | +#if 0 /* called by memory compaction regardless file */ |
4a4d8108 | 13125 | +static int aufs_migratepage(struct address_space *mapping, struct page *newpage, |
7eafdf33 | 13126 | + struct page *page, enum migrate_mode mode) |
4a4d8108 | 13127 | +{ AuUnsupport(); return 0; } |
79b8bda9 | 13128 | +#endif |
e2f27e51 AM |
13129 | +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode) |
13130 | +{ AuUnsupport(); return true; } | |
13131 | +static void aufs_putback_page(struct page *page) | |
13132 | +{ AuUnsupport(); } | |
4a4d8108 AM |
13133 | +static int aufs_launder_page(struct page *page) |
13134 | +{ AuUnsupport(); return 0; } | |
13135 | +static int aufs_is_partially_uptodate(struct page *page, | |
38d290e6 JR |
13136 | + unsigned long from, |
13137 | + unsigned long count) | |
4a4d8108 | 13138 | +{ AuUnsupport(); return 0; } |
392086de AM |
13139 | +static void aufs_is_dirty_writeback(struct page *page, bool *dirty, |
13140 | + bool *writeback) | |
13141 | +{ AuUnsupport(); } | |
4a4d8108 AM |
13142 | +static int aufs_error_remove_page(struct address_space *mapping, |
13143 | + struct page *page) | |
13144 | +{ AuUnsupport(); return 0; } | |
b4510431 AM |
13145 | +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file, |
13146 | + sector_t *span) | |
13147 | +{ AuUnsupport(); return 0; } | |
13148 | +static void aufs_swap_deactivate(struct file *file) | |
13149 | +{ AuUnsupport(); } | |
4a4d8108 AM |
13150 | +#endif /* CONFIG_AUFS_DEBUG */ |
13151 | + | |
13152 | +const struct address_space_operations aufs_aop = { | |
13153 | + .readpage = aufs_readpage, | |
13154 | + .direct_IO = aufs_direct_IO, | |
4a4d8108 AM |
13155 | +#ifdef CONFIG_AUFS_DEBUG |
13156 | + .writepage = aufs_writepage, | |
4a4d8108 AM |
13157 | + /* no writepages, because of writepage */ |
13158 | + .set_page_dirty = aufs_set_page_dirty, | |
13159 | + /* no readpages, because of readpage */ | |
13160 | + .write_begin = aufs_write_begin, | |
13161 | + .write_end = aufs_write_end, | |
13162 | + /* no bmap, no block device */ | |
13163 | + .invalidatepage = aufs_invalidatepage, | |
13164 | + .releasepage = aufs_releasepage, | |
79b8bda9 AM |
13165 | + /* is fallback_migrate_page ok? */ |
13166 | + /* .migratepage = aufs_migratepage, */ | |
e2f27e51 AM |
13167 | + .isolate_page = aufs_isolate_page, |
13168 | + .putback_page = aufs_putback_page, | |
4a4d8108 AM |
13169 | + .launder_page = aufs_launder_page, |
13170 | + .is_partially_uptodate = aufs_is_partially_uptodate, | |
392086de | 13171 | + .is_dirty_writeback = aufs_is_dirty_writeback, |
b4510431 AM |
13172 | + .error_remove_page = aufs_error_remove_page, |
13173 | + .swap_activate = aufs_swap_activate, | |
13174 | + .swap_deactivate = aufs_swap_deactivate | |
4a4d8108 | 13175 | +#endif /* CONFIG_AUFS_DEBUG */ |
dece6358 | 13176 | +}; |
7f207e10 AM |
13177 | diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h |
13178 | --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
13179 | +++ linux/fs/aufs/file.h 2017-05-06 22:16:52.778220093 +0200 |
13180 | @@ -0,0 +1,333 @@ | |
4a4d8108 | 13181 | +/* |
a2654f78 | 13182 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
13183 | + * |
13184 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13185 | + * it under the terms of the GNU General Public License as published by | |
13186 | + * the Free Software Foundation; either version 2 of the License, or | |
13187 | + * (at your option) any later version. | |
13188 | + * | |
13189 | + * This program is distributed in the hope that it will be useful, | |
13190 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13191 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13192 | + * GNU General Public License for more details. | |
13193 | + * | |
13194 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13195 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 13196 | + */ |
1facf9fc | 13197 | + |
4a4d8108 AM |
13198 | +/* |
13199 | + * file operations | |
13200 | + */ | |
1facf9fc | 13201 | + |
4a4d8108 AM |
13202 | +#ifndef __AUFS_FILE_H__ |
13203 | +#define __AUFS_FILE_H__ | |
1facf9fc | 13204 | + |
4a4d8108 | 13205 | +#ifdef __KERNEL__ |
1facf9fc | 13206 | + |
2cbb1c4b | 13207 | +#include <linux/file.h> |
4a4d8108 AM |
13208 | +#include <linux/fs.h> |
13209 | +#include <linux/poll.h> | |
4a4d8108 | 13210 | +#include "rwsem.h" |
1facf9fc | 13211 | + |
4a4d8108 AM |
13212 | +struct au_branch; |
13213 | +struct au_hfile { | |
13214 | + struct file *hf_file; | |
13215 | + struct au_branch *hf_br; | |
13216 | +}; | |
1facf9fc | 13217 | + |
4a4d8108 AM |
13218 | +struct au_vdir; |
13219 | +struct au_fidir { | |
13220 | + aufs_bindex_t fd_bbot; | |
13221 | + aufs_bindex_t fd_nent; | |
13222 | + struct au_vdir *fd_vdir_cache; | |
13223 | + struct au_hfile fd_hfile[]; | |
13224 | +}; | |
1facf9fc | 13225 | + |
4a4d8108 | 13226 | +static inline int au_fidir_sz(int nent) |
dece6358 | 13227 | +{ |
4f0767ce JR |
13228 | + AuDebugOn(nent < 0); |
13229 | + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent; | |
4a4d8108 | 13230 | +} |
1facf9fc | 13231 | + |
4a4d8108 AM |
13232 | +struct au_finfo { |
13233 | + atomic_t fi_generation; | |
dece6358 | 13234 | + |
4a4d8108 AM |
13235 | + struct au_rwsem fi_rwsem; |
13236 | + aufs_bindex_t fi_btop; | |
13237 | + | |
13238 | + /* do not union them */ | |
13239 | + struct { /* for non-dir */ | |
13240 | + struct au_hfile fi_htop; | |
2cbb1c4b | 13241 | + atomic_t fi_mmapped; |
4a4d8108 AM |
13242 | + }; |
13243 | + struct au_fidir *fi_hdir; /* for dir only */ | |
523b37e3 AM |
13244 | + |
13245 | + struct hlist_node fi_hlist; | |
f0c0a007 AM |
13246 | + union { |
13247 | + struct file *fi_file; /* very ugly */ | |
13248 | + struct llist_node fi_lnode; /* delayed free */ | |
13249 | + }; | |
4a4d8108 | 13250 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 13251 | + |
4a4d8108 | 13252 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 13253 | + |
4a4d8108 AM |
13254 | +/* file.c */ |
13255 | +extern const struct address_space_operations aufs_aop; | |
13256 | +unsigned int au_file_roflags(unsigned int flags); | |
13257 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 13258 | + struct file *file, int force_wr); |
b912730e AM |
13259 | +struct au_do_open_args { |
13260 | + int no_lock; | |
13261 | + int (*open)(struct file *file, int flags, | |
13262 | + struct file *h_file); | |
13263 | + struct au_fidir *fidir; | |
13264 | + struct file *h_file; | |
13265 | +}; | |
13266 | +int au_do_open(struct file *file, struct au_do_open_args *args); | |
4a4d8108 AM |
13267 | +int au_reopen_nondir(struct file *file); |
13268 | +struct au_pin; | |
13269 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin); | |
13270 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
521ced18 | 13271 | + int wlock, unsigned int fi_lsc); |
4a4d8108 AM |
13272 | +int au_do_flush(struct file *file, fl_owner_t id, |
13273 | + int (*flush)(struct file *file, fl_owner_t id)); | |
1facf9fc | 13274 | + |
4a4d8108 AM |
13275 | +/* poll.c */ |
13276 | +#ifdef CONFIG_AUFS_POLL | |
13277 | +unsigned int aufs_poll(struct file *file, poll_table *wait); | |
13278 | +#endif | |
1facf9fc | 13279 | + |
4a4d8108 AM |
13280 | +#ifdef CONFIG_AUFS_BR_HFSPLUS |
13281 | +/* hfsplus.c */ | |
392086de AM |
13282 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
13283 | + int force_wr); | |
4a4d8108 AM |
13284 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
13285 | + struct file *h_file); | |
13286 | +#else | |
c1595e42 JR |
13287 | +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry, |
13288 | + aufs_bindex_t bindex, int force_wr) | |
4a4d8108 AM |
13289 | +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex, |
13290 | + struct file *h_file); | |
13291 | +#endif | |
1facf9fc | 13292 | + |
4a4d8108 AM |
13293 | +/* f_op.c */ |
13294 | +extern const struct file_operations aufs_file_fop; | |
b912730e | 13295 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file); |
4a4d8108 | 13296 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file); |
521ced18 | 13297 | +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc); |
4a4d8108 | 13298 | + |
4a4d8108 | 13299 | +/* finfo.c */ |
f0c0a007 | 13300 | +void au_hfput(struct au_hfile *hf, int execed); |
4a4d8108 AM |
13301 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, |
13302 | + struct file *h_file); | |
1facf9fc | 13303 | + |
4a4d8108 | 13304 | +void au_update_figen(struct file *file); |
4a4d8108 | 13305 | +struct au_fidir *au_fidir_alloc(struct super_block *sb); |
e2f27e51 | 13306 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink); |
1facf9fc | 13307 | + |
4a4d8108 | 13308 | +void au_fi_init_once(void *_fi); |
f0c0a007 | 13309 | +void au_finfo_fin(struct file *file, int atonce); |
4a4d8108 | 13310 | +int au_finfo_init(struct file *file, struct au_fidir *fidir); |
1facf9fc | 13311 | + |
4a4d8108 AM |
13312 | +/* ioctl.c */ |
13313 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
13314 | +#ifdef CONFIG_COMPAT |
13315 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
13316 | + unsigned long arg); | |
c2b27bf2 AM |
13317 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
13318 | + unsigned long arg); | |
b752ccd1 | 13319 | +#endif |
1facf9fc | 13320 | + |
4a4d8108 | 13321 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 13322 | + |
4a4d8108 AM |
13323 | +static inline struct au_finfo *au_fi(struct file *file) |
13324 | +{ | |
38d290e6 | 13325 | + return file->private_data; |
4a4d8108 | 13326 | +} |
1facf9fc | 13327 | + |
4a4d8108 | 13328 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 13329 | + |
4a4d8108 AM |
13330 | +/* |
13331 | + * fi_read_lock, fi_write_lock, | |
13332 | + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock | |
13333 | + */ | |
13334 | +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem); | |
1308ab2a | 13335 | + |
521ced18 JR |
13336 | +/* lock subclass for finfo */ |
13337 | +enum { | |
13338 | + AuLsc_FI_1, | |
13339 | + AuLsc_FI_2 | |
13340 | +}; | |
13341 | + | |
13342 | +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc) | |
13343 | +{ | |
13344 | + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc); | |
13345 | +} | |
13346 | + | |
13347 | +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc) | |
13348 | +{ | |
13349 | + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc); | |
13350 | +} | |
13351 | + | |
13352 | +/* | |
13353 | + * fi_read_lock_1, fi_write_lock_1, | |
13354 | + * fi_read_lock_2, fi_write_lock_2 | |
13355 | + */ | |
13356 | +#define AuReadLockFunc(name) \ | |
13357 | +static inline void fi_read_lock_##name(struct file *f) \ | |
13358 | +{ fi_read_lock_nested(f, AuLsc_FI_##name); } | |
13359 | + | |
13360 | +#define AuWriteLockFunc(name) \ | |
13361 | +static inline void fi_write_lock_##name(struct file *f) \ | |
13362 | +{ fi_write_lock_nested(f, AuLsc_FI_##name); } | |
13363 | + | |
13364 | +#define AuRWLockFuncs(name) \ | |
13365 | + AuReadLockFunc(name) \ | |
13366 | + AuWriteLockFunc(name) | |
13367 | + | |
13368 | +AuRWLockFuncs(1); | |
13369 | +AuRWLockFuncs(2); | |
13370 | + | |
13371 | +#undef AuReadLockFunc | |
13372 | +#undef AuWriteLockFunc | |
13373 | +#undef AuRWLockFuncs | |
13374 | + | |
4a4d8108 AM |
13375 | +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem) |
13376 | +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem) | |
13377 | +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem) | |
1facf9fc | 13378 | + |
1308ab2a | 13379 | +/* ---------------------------------------------------------------------- */ |
13380 | + | |
4a4d8108 | 13381 | +/* todo: hard/soft set? */ |
5afbbe0d | 13382 | +static inline aufs_bindex_t au_fbtop(struct file *file) |
dece6358 | 13383 | +{ |
4a4d8108 AM |
13384 | + FiMustAnyLock(file); |
13385 | + return au_fi(file)->fi_btop; | |
13386 | +} | |
dece6358 | 13387 | + |
5afbbe0d | 13388 | +static inline aufs_bindex_t au_fbbot_dir(struct file *file) |
4a4d8108 AM |
13389 | +{ |
13390 | + FiMustAnyLock(file); | |
13391 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13392 | + return au_fi(file)->fi_hdir->fd_bbot; | |
13393 | +} | |
1facf9fc | 13394 | + |
4a4d8108 AM |
13395 | +static inline struct au_vdir *au_fvdir_cache(struct file *file) |
13396 | +{ | |
13397 | + FiMustAnyLock(file); | |
13398 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13399 | + return au_fi(file)->fi_hdir->fd_vdir_cache; | |
13400 | +} | |
1facf9fc | 13401 | + |
5afbbe0d | 13402 | +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex) |
4a4d8108 AM |
13403 | +{ |
13404 | + FiMustWriteLock(file); | |
13405 | + au_fi(file)->fi_btop = bindex; | |
13406 | +} | |
1facf9fc | 13407 | + |
5afbbe0d | 13408 | +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex) |
4a4d8108 AM |
13409 | +{ |
13410 | + FiMustWriteLock(file); | |
13411 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13412 | + au_fi(file)->fi_hdir->fd_bbot = bindex; | |
13413 | +} | |
1308ab2a | 13414 | + |
4a4d8108 AM |
13415 | +static inline void au_set_fvdir_cache(struct file *file, |
13416 | + struct au_vdir *vdir_cache) | |
13417 | +{ | |
13418 | + FiMustWriteLock(file); | |
13419 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13420 | + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache; | |
13421 | +} | |
dece6358 | 13422 | + |
4a4d8108 AM |
13423 | +static inline struct file *au_hf_top(struct file *file) |
13424 | +{ | |
13425 | + FiMustAnyLock(file); | |
13426 | + AuDebugOn(au_fi(file)->fi_hdir); | |
13427 | + return au_fi(file)->fi_htop.hf_file; | |
13428 | +} | |
1facf9fc | 13429 | + |
4a4d8108 AM |
13430 | +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex) |
13431 | +{ | |
13432 | + FiMustAnyLock(file); | |
13433 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13434 | + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file; | |
dece6358 AM |
13435 | +} |
13436 | + | |
4a4d8108 AM |
13437 | +/* todo: memory barrier? */ |
13438 | +static inline unsigned int au_figen(struct file *f) | |
dece6358 | 13439 | +{ |
4a4d8108 AM |
13440 | + return atomic_read(&au_fi(f)->fi_generation); |
13441 | +} | |
dece6358 | 13442 | + |
2cbb1c4b JR |
13443 | +static inline void au_set_mmapped(struct file *f) |
13444 | +{ | |
13445 | + if (atomic_inc_return(&au_fi(f)->fi_mmapped)) | |
13446 | + return; | |
0c3ec466 | 13447 | + pr_warn("fi_mmapped wrapped around\n"); |
2cbb1c4b JR |
13448 | + while (!atomic_inc_return(&au_fi(f)->fi_mmapped)) |
13449 | + ; | |
13450 | +} | |
13451 | + | |
13452 | +static inline void au_unset_mmapped(struct file *f) | |
13453 | +{ | |
13454 | + atomic_dec(&au_fi(f)->fi_mmapped); | |
13455 | +} | |
13456 | + | |
4a4d8108 AM |
13457 | +static inline int au_test_mmapped(struct file *f) |
13458 | +{ | |
2cbb1c4b JR |
13459 | + return atomic_read(&au_fi(f)->fi_mmapped); |
13460 | +} | |
13461 | + | |
13462 | +/* customize vma->vm_file */ | |
13463 | + | |
13464 | +static inline void au_do_vm_file_reset(struct vm_area_struct *vma, | |
13465 | + struct file *file) | |
13466 | +{ | |
53392da6 AM |
13467 | + struct file *f; |
13468 | + | |
13469 | + f = vma->vm_file; | |
2cbb1c4b JR |
13470 | + get_file(file); |
13471 | + vma->vm_file = file; | |
53392da6 | 13472 | + fput(f); |
2cbb1c4b JR |
13473 | +} |
13474 | + | |
13475 | +#ifdef CONFIG_MMU | |
13476 | +#define AuDbgVmRegion(file, vma) do {} while (0) | |
13477 | + | |
13478 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
13479 | + struct file *file) | |
13480 | +{ | |
13481 | + au_do_vm_file_reset(vma, file); | |
13482 | +} | |
13483 | +#else | |
13484 | +#define AuDbgVmRegion(file, vma) \ | |
13485 | + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file)) | |
13486 | + | |
13487 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
13488 | + struct file *file) | |
13489 | +{ | |
53392da6 AM |
13490 | + struct file *f; |
13491 | + | |
2cbb1c4b | 13492 | + au_do_vm_file_reset(vma, file); |
53392da6 | 13493 | + f = vma->vm_region->vm_file; |
2cbb1c4b JR |
13494 | + get_file(file); |
13495 | + vma->vm_region->vm_file = file; | |
53392da6 | 13496 | + fput(f); |
2cbb1c4b JR |
13497 | +} |
13498 | +#endif /* CONFIG_MMU */ | |
13499 | + | |
13500 | +/* handle vma->vm_prfile */ | |
fb47a38f | 13501 | +static inline void au_vm_prfile_set(struct vm_area_struct *vma, |
2cbb1c4b JR |
13502 | + struct file *file) |
13503 | +{ | |
2cbb1c4b JR |
13504 | + get_file(file); |
13505 | + vma->vm_prfile = file; | |
13506 | +#ifndef CONFIG_MMU | |
13507 | + get_file(file); | |
13508 | + vma->vm_region->vm_prfile = file; | |
13509 | +#endif | |
fb47a38f | 13510 | +} |
1308ab2a | 13511 | + |
4a4d8108 AM |
13512 | +#endif /* __KERNEL__ */ |
13513 | +#endif /* __AUFS_FILE_H__ */ | |
7f207e10 AM |
13514 | diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c |
13515 | --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 13516 | +++ linux/fs/aufs/finfo.c 2017-05-06 22:16:52.778220093 +0200 |
f0c0a007 | 13517 | @@ -0,0 +1,151 @@ |
4a4d8108 | 13518 | +/* |
a2654f78 | 13519 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
13520 | + * |
13521 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13522 | + * it under the terms of the GNU General Public License as published by | |
13523 | + * the Free Software Foundation; either version 2 of the License, or | |
13524 | + * (at your option) any later version. | |
13525 | + * | |
13526 | + * This program is distributed in the hope that it will be useful, | |
13527 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13528 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13529 | + * GNU General Public License for more details. | |
13530 | + * | |
13531 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13532 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 13533 | + */ |
1308ab2a | 13534 | + |
4a4d8108 AM |
13535 | +/* |
13536 | + * file private data | |
13537 | + */ | |
1facf9fc | 13538 | + |
4a4d8108 | 13539 | +#include "aufs.h" |
1facf9fc | 13540 | + |
f0c0a007 | 13541 | +void au_hfput(struct au_hfile *hf, int execed) |
4a4d8108 | 13542 | +{ |
f0c0a007 | 13543 | + if (execed) |
4a4d8108 AM |
13544 | + allow_write_access(hf->hf_file); |
13545 | + fput(hf->hf_file); | |
13546 | + hf->hf_file = NULL; | |
5afbbe0d | 13547 | + au_br_put(hf->hf_br); |
4a4d8108 AM |
13548 | + hf->hf_br = NULL; |
13549 | +} | |
1facf9fc | 13550 | + |
4a4d8108 AM |
13551 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val) |
13552 | +{ | |
13553 | + struct au_finfo *finfo = au_fi(file); | |
13554 | + struct au_hfile *hf; | |
13555 | + struct au_fidir *fidir; | |
13556 | + | |
13557 | + fidir = finfo->fi_hdir; | |
13558 | + if (!fidir) { | |
13559 | + AuDebugOn(finfo->fi_btop != bindex); | |
13560 | + hf = &finfo->fi_htop; | |
13561 | + } else | |
13562 | + hf = fidir->fd_hfile + bindex; | |
13563 | + | |
13564 | + if (hf && hf->hf_file) | |
f0c0a007 | 13565 | + au_hfput(hf, vfsub_file_execed(file)); |
4a4d8108 AM |
13566 | + if (val) { |
13567 | + FiMustWriteLock(file); | |
b912730e | 13568 | + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry)); |
4a4d8108 | 13569 | + hf->hf_file = val; |
2000de60 | 13570 | + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex); |
1308ab2a | 13571 | + } |
4a4d8108 | 13572 | +} |
1facf9fc | 13573 | + |
4a4d8108 AM |
13574 | +void au_update_figen(struct file *file) |
13575 | +{ | |
2000de60 | 13576 | + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry)); |
4a4d8108 | 13577 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 13578 | +} |
13579 | + | |
4a4d8108 AM |
13580 | +/* ---------------------------------------------------------------------- */ |
13581 | + | |
4a4d8108 AM |
13582 | +struct au_fidir *au_fidir_alloc(struct super_block *sb) |
13583 | +{ | |
13584 | + struct au_fidir *fidir; | |
13585 | + int nbr; | |
13586 | + | |
5afbbe0d | 13587 | + nbr = au_sbbot(sb) + 1; |
4a4d8108 AM |
13588 | + if (nbr < 2) |
13589 | + nbr = 2; /* initial allocate for 2 branches */ | |
13590 | + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS); | |
13591 | + if (fidir) { | |
13592 | + fidir->fd_bbot = -1; | |
13593 | + fidir->fd_nent = nbr; | |
4a4d8108 AM |
13594 | + } |
13595 | + | |
13596 | + return fidir; | |
13597 | +} | |
13598 | + | |
e2f27e51 | 13599 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink) |
4a4d8108 AM |
13600 | +{ |
13601 | + int err; | |
13602 | + struct au_fidir *fidir, *p; | |
13603 | + | |
13604 | + AuRwMustWriteLock(&finfo->fi_rwsem); | |
13605 | + fidir = finfo->fi_hdir; | |
13606 | + AuDebugOn(!fidir); | |
13607 | + | |
13608 | + err = -ENOMEM; | |
13609 | + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr), | |
e2f27e51 | 13610 | + GFP_NOFS, may_shrink); |
4a4d8108 AM |
13611 | + if (p) { |
13612 | + p->fd_nent = nbr; | |
13613 | + finfo->fi_hdir = p; | |
13614 | + err = 0; | |
13615 | + } | |
1facf9fc | 13616 | + |
dece6358 | 13617 | + return err; |
1facf9fc | 13618 | +} |
1308ab2a | 13619 | + |
13620 | +/* ---------------------------------------------------------------------- */ | |
13621 | + | |
f0c0a007 | 13622 | +void au_finfo_fin(struct file *file, int atonce) |
1308ab2a | 13623 | +{ |
4a4d8108 AM |
13624 | + struct au_finfo *finfo; |
13625 | + | |
2000de60 | 13626 | + au_nfiles_dec(file->f_path.dentry->d_sb); |
7f207e10 | 13627 | + |
4a4d8108 AM |
13628 | + finfo = au_fi(file); |
13629 | + AuDebugOn(finfo->fi_hdir); | |
13630 | + AuRwDestroy(&finfo->fi_rwsem); | |
f0c0a007 AM |
13631 | + if (!atonce) |
13632 | + au_cache_dfree_finfo(finfo); | |
13633 | + else | |
13634 | + au_cache_free_finfo(finfo); | |
1308ab2a | 13635 | +} |
1308ab2a | 13636 | + |
e49829fe | 13637 | +void au_fi_init_once(void *_finfo) |
4a4d8108 | 13638 | +{ |
e49829fe | 13639 | + struct au_finfo *finfo = _finfo; |
1308ab2a | 13640 | + |
e49829fe | 13641 | + au_rw_init(&finfo->fi_rwsem); |
4a4d8108 | 13642 | +} |
1308ab2a | 13643 | + |
4a4d8108 AM |
13644 | +int au_finfo_init(struct file *file, struct au_fidir *fidir) |
13645 | +{ | |
1716fcea | 13646 | + int err; |
4a4d8108 AM |
13647 | + struct au_finfo *finfo; |
13648 | + struct dentry *dentry; | |
13649 | + | |
13650 | + err = -ENOMEM; | |
2000de60 | 13651 | + dentry = file->f_path.dentry; |
4a4d8108 AM |
13652 | + finfo = au_cache_alloc_finfo(); |
13653 | + if (unlikely(!finfo)) | |
13654 | + goto out; | |
13655 | + | |
13656 | + err = 0; | |
7f207e10 | 13657 | + au_nfiles_inc(dentry->d_sb); |
4a4d8108 AM |
13658 | + au_rw_write_lock(&finfo->fi_rwsem); |
13659 | + finfo->fi_btop = -1; | |
13660 | + finfo->fi_hdir = fidir; | |
13661 | + atomic_set(&finfo->fi_generation, au_digen(dentry)); | |
13662 | + /* smp_mb(); */ /* atomic_set */ | |
13663 | + | |
13664 | + file->private_data = finfo; | |
13665 | + | |
13666 | +out: | |
13667 | + return err; | |
13668 | +} | |
7f207e10 AM |
13669 | diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c |
13670 | --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
13671 | +++ linux/fs/aufs/f_op.c 2017-05-06 22:16:52.778220093 +0200 |
13672 | @@ -0,0 +1,819 @@ | |
dece6358 | 13673 | +/* |
a2654f78 | 13674 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
dece6358 AM |
13675 | + * |
13676 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13677 | + * it under the terms of the GNU General Public License as published by | |
13678 | + * the Free Software Foundation; either version 2 of the License, or | |
13679 | + * (at your option) any later version. | |
13680 | + * | |
13681 | + * This program is distributed in the hope that it will be useful, | |
13682 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13683 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13684 | + * GNU General Public License for more details. | |
13685 | + * | |
13686 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13687 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 13688 | + */ |
1facf9fc | 13689 | + |
13690 | +/* | |
4a4d8108 | 13691 | + * file and vm operations |
1facf9fc | 13692 | + */ |
dece6358 | 13693 | + |
86dc4139 | 13694 | +#include <linux/aio.h> |
4a4d8108 AM |
13695 | +#include <linux/fs_stack.h> |
13696 | +#include <linux/mman.h> | |
4a4d8108 | 13697 | +#include <linux/security.h> |
dece6358 AM |
13698 | +#include "aufs.h" |
13699 | + | |
b912730e | 13700 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 13701 | +{ |
4a4d8108 AM |
13702 | + int err; |
13703 | + aufs_bindex_t bindex; | |
8cdd5066 | 13704 | + struct dentry *dentry, *h_dentry; |
4a4d8108 | 13705 | + struct au_finfo *finfo; |
38d290e6 | 13706 | + struct inode *h_inode; |
4a4d8108 AM |
13707 | + |
13708 | + FiMustWriteLock(file); | |
13709 | + | |
523b37e3 | 13710 | + err = 0; |
2000de60 | 13711 | + dentry = file->f_path.dentry; |
b912730e | 13712 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
4a4d8108 AM |
13713 | + finfo = au_fi(file); |
13714 | + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop)); | |
2cbb1c4b | 13715 | + atomic_set(&finfo->fi_mmapped, 0); |
5afbbe0d | 13716 | + bindex = au_dbtop(dentry); |
8cdd5066 JR |
13717 | + if (!h_file) { |
13718 | + h_dentry = au_h_dptr(dentry, bindex); | |
13719 | + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb); | |
13720 | + if (unlikely(err)) | |
13721 | + goto out; | |
b912730e | 13722 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
8cdd5066 JR |
13723 | + } else { |
13724 | + h_dentry = h_file->f_path.dentry; | |
13725 | + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb); | |
13726 | + if (unlikely(err)) | |
13727 | + goto out; | |
b912730e | 13728 | + get_file(h_file); |
8cdd5066 | 13729 | + } |
4a4d8108 AM |
13730 | + if (IS_ERR(h_file)) |
13731 | + err = PTR_ERR(h_file); | |
13732 | + else { | |
38d290e6 JR |
13733 | + if ((flags & __O_TMPFILE) |
13734 | + && !(flags & O_EXCL)) { | |
13735 | + h_inode = file_inode(h_file); | |
13736 | + spin_lock(&h_inode->i_lock); | |
13737 | + h_inode->i_state |= I_LINKABLE; | |
13738 | + spin_unlock(&h_inode->i_lock); | |
13739 | + } | |
5afbbe0d | 13740 | + au_set_fbtop(file, bindex); |
4a4d8108 AM |
13741 | + au_set_h_fptr(file, bindex, h_file); |
13742 | + au_update_figen(file); | |
13743 | + /* todo: necessary? */ | |
13744 | + /* file->f_ra = h_file->f_ra; */ | |
13745 | + } | |
027c5e7a | 13746 | + |
8cdd5066 | 13747 | +out: |
4a4d8108 | 13748 | + return err; |
1facf9fc | 13749 | +} |
13750 | + | |
4a4d8108 AM |
13751 | +static int aufs_open_nondir(struct inode *inode __maybe_unused, |
13752 | + struct file *file) | |
1facf9fc | 13753 | +{ |
4a4d8108 | 13754 | + int err; |
1308ab2a | 13755 | + struct super_block *sb; |
b912730e AM |
13756 | + struct au_do_open_args args = { |
13757 | + .open = au_do_open_nondir | |
13758 | + }; | |
1facf9fc | 13759 | + |
523b37e3 AM |
13760 | + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n", |
13761 | + file, vfsub_file_flags(file), file->f_mode); | |
1facf9fc | 13762 | + |
2000de60 | 13763 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 13764 | + si_read_lock(sb, AuLock_FLUSH); |
b912730e | 13765 | + err = au_do_open(file, &args); |
4a4d8108 AM |
13766 | + si_read_unlock(sb); |
13767 | + return err; | |
13768 | +} | |
1facf9fc | 13769 | + |
4a4d8108 AM |
13770 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file) |
13771 | +{ | |
13772 | + struct au_finfo *finfo; | |
13773 | + aufs_bindex_t bindex; | |
f0c0a007 | 13774 | + int delayed; |
1facf9fc | 13775 | + |
4a4d8108 | 13776 | + finfo = au_fi(file); |
2000de60 JR |
13777 | + au_sphl_del(&finfo->fi_hlist, |
13778 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
4a4d8108 | 13779 | + bindex = finfo->fi_btop; |
b4510431 | 13780 | + if (bindex >= 0) |
4a4d8108 | 13781 | + au_set_h_fptr(file, bindex, NULL); |
7f207e10 | 13782 | + |
f0c0a007 AM |
13783 | + delayed = (current->flags & PF_KTHREAD) || in_interrupt(); |
13784 | + au_finfo_fin(file, delayed); | |
4a4d8108 | 13785 | + return 0; |
1facf9fc | 13786 | +} |
13787 | + | |
4a4d8108 AM |
13788 | +/* ---------------------------------------------------------------------- */ |
13789 | + | |
13790 | +static int au_do_flush_nondir(struct file *file, fl_owner_t id) | |
dece6358 | 13791 | +{ |
1308ab2a | 13792 | + int err; |
4a4d8108 AM |
13793 | + struct file *h_file; |
13794 | + | |
13795 | + err = 0; | |
13796 | + h_file = au_hf_top(file); | |
13797 | + if (h_file) | |
13798 | + err = vfsub_flush(h_file, id); | |
13799 | + return err; | |
13800 | +} | |
13801 | + | |
13802 | +static int aufs_flush_nondir(struct file *file, fl_owner_t id) | |
13803 | +{ | |
13804 | + return au_do_flush(file, id, au_do_flush_nondir); | |
13805 | +} | |
13806 | + | |
13807 | +/* ---------------------------------------------------------------------- */ | |
9dbd164d AM |
13808 | +/* |
13809 | + * read and write functions acquire [fdi]_rwsem once, but release before | |
13810 | + * mmap_sem. This is because to stop a race condition between mmap(2). | |
13811 | + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping | |
13812 | + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in | |
13813 | + * read functions after [fdi]_rwsem are released, but it should be harmless. | |
13814 | + */ | |
4a4d8108 | 13815 | + |
b912730e | 13816 | +/* Callers should call au_read_post() or fput() in the end */ |
521ced18 | 13817 | +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc) |
4a4d8108 | 13818 | +{ |
4a4d8108 | 13819 | + struct file *h_file; |
b912730e | 13820 | + int err; |
1facf9fc | 13821 | + |
521ced18 | 13822 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc); |
b912730e AM |
13823 | + if (!err) { |
13824 | + di_read_unlock(file->f_path.dentry, AuLock_IR); | |
13825 | + h_file = au_hf_top(file); | |
13826 | + get_file(h_file); | |
13827 | + if (!keep_fi) | |
13828 | + fi_read_unlock(file); | |
13829 | + } else | |
13830 | + h_file = ERR_PTR(err); | |
13831 | + | |
13832 | + return h_file; | |
13833 | +} | |
13834 | + | |
13835 | +static void au_read_post(struct inode *inode, struct file *h_file) | |
13836 | +{ | |
13837 | + /* update without lock, I don't think it a problem */ | |
13838 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
13839 | + fput(h_file); | |
13840 | +} | |
13841 | + | |
13842 | +struct au_write_pre { | |
521ced18 JR |
13843 | + /* input */ |
13844 | + unsigned int lsc; | |
13845 | + | |
13846 | + /* output */ | |
b912730e | 13847 | + blkcnt_t blks; |
5afbbe0d | 13848 | + aufs_bindex_t btop; |
b912730e AM |
13849 | +}; |
13850 | + | |
13851 | +/* | |
13852 | + * return with iinfo is write-locked | |
13853 | + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the | |
13854 | + * end | |
13855 | + */ | |
13856 | +static struct file *au_write_pre(struct file *file, int do_ready, | |
13857 | + struct au_write_pre *wpre) | |
13858 | +{ | |
13859 | + struct file *h_file; | |
13860 | + struct dentry *dentry; | |
13861 | + int err; | |
521ced18 | 13862 | + unsigned int lsc; |
b912730e AM |
13863 | + struct au_pin pin; |
13864 | + | |
521ced18 JR |
13865 | + lsc = 0; |
13866 | + if (wpre) | |
13867 | + lsc = wpre->lsc; | |
13868 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc); | |
b912730e | 13869 | + h_file = ERR_PTR(err); |
dece6358 AM |
13870 | + if (unlikely(err)) |
13871 | + goto out; | |
1facf9fc | 13872 | + |
b912730e AM |
13873 | + dentry = file->f_path.dentry; |
13874 | + if (do_ready) { | |
13875 | + err = au_ready_to_write(file, -1, &pin); | |
13876 | + if (unlikely(err)) { | |
13877 | + h_file = ERR_PTR(err); | |
13878 | + di_write_unlock(dentry); | |
13879 | + goto out_fi; | |
13880 | + } | |
13881 | + } | |
13882 | + | |
13883 | + di_downgrade_lock(dentry, /*flags*/0); | |
13884 | + if (wpre) | |
5afbbe0d | 13885 | + wpre->btop = au_fbtop(file); |
4a4d8108 | 13886 | + h_file = au_hf_top(file); |
9dbd164d | 13887 | + get_file(h_file); |
b912730e AM |
13888 | + if (wpre) |
13889 | + wpre->blks = file_inode(h_file)->i_blocks; | |
13890 | + if (do_ready) | |
13891 | + au_unpin(&pin); | |
13892 | + di_read_unlock(dentry, /*flags*/0); | |
13893 | + | |
13894 | +out_fi: | |
13895 | + fi_write_unlock(file); | |
13896 | +out: | |
13897 | + return h_file; | |
13898 | +} | |
13899 | + | |
13900 | +static void au_write_post(struct inode *inode, struct file *h_file, | |
13901 | + struct au_write_pre *wpre, ssize_t written) | |
13902 | +{ | |
13903 | + struct inode *h_inode; | |
13904 | + | |
13905 | + au_cpup_attr_timesizes(inode); | |
5afbbe0d | 13906 | + AuDebugOn(au_ibtop(inode) != wpre->btop); |
b912730e AM |
13907 | + h_inode = file_inode(h_file); |
13908 | + inode->i_mode = h_inode->i_mode; | |
13909 | + ii_write_unlock(inode); | |
13910 | + fput(h_file); | |
13911 | + | |
13912 | + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */ | |
13913 | + if (written > 0) | |
5afbbe0d | 13914 | + au_fhsm_wrote(inode->i_sb, wpre->btop, |
b912730e AM |
13915 | + /*force*/h_inode->i_blocks > wpre->blks); |
13916 | +} | |
13917 | + | |
13918 | +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count, | |
13919 | + loff_t *ppos) | |
13920 | +{ | |
13921 | + ssize_t err; | |
13922 | + struct inode *inode; | |
13923 | + struct file *h_file; | |
13924 | + struct super_block *sb; | |
13925 | + | |
13926 | + inode = file_inode(file); | |
13927 | + sb = inode->i_sb; | |
13928 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
13929 | + | |
521ced18 | 13930 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
13931 | + err = PTR_ERR(h_file); |
13932 | + if (IS_ERR(h_file)) | |
13933 | + goto out; | |
9dbd164d AM |
13934 | + |
13935 | + /* filedata may be obsoleted by concurrent copyup, but no problem */ | |
4a4d8108 AM |
13936 | + err = vfsub_read_u(h_file, buf, count, ppos); |
13937 | + /* todo: necessary? */ | |
13938 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 13939 | + au_read_post(inode, h_file); |
1308ab2a | 13940 | + |
4f0767ce | 13941 | +out: |
dece6358 AM |
13942 | + si_read_unlock(sb); |
13943 | + return err; | |
13944 | +} | |
1facf9fc | 13945 | + |
e49829fe JR |
13946 | +/* |
13947 | + * todo: very ugly | |
13948 | + * it locks both of i_mutex and si_rwsem for read in safe. | |
13949 | + * if the plink maintenance mode continues forever (that is the problem), | |
13950 | + * may loop forever. | |
13951 | + */ | |
13952 | +static void au_mtx_and_read_lock(struct inode *inode) | |
13953 | +{ | |
13954 | + int err; | |
13955 | + struct super_block *sb = inode->i_sb; | |
13956 | + | |
13957 | + while (1) { | |
febd17d6 | 13958 | + inode_lock(inode); |
e49829fe JR |
13959 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
13960 | + if (!err) | |
13961 | + break; | |
febd17d6 | 13962 | + inode_unlock(inode); |
e49829fe JR |
13963 | + si_read_lock(sb, AuLock_NOPLMW); |
13964 | + si_read_unlock(sb); | |
13965 | + } | |
13966 | +} | |
13967 | + | |
4a4d8108 AM |
13968 | +static ssize_t aufs_write(struct file *file, const char __user *ubuf, |
13969 | + size_t count, loff_t *ppos) | |
dece6358 | 13970 | +{ |
4a4d8108 | 13971 | + ssize_t err; |
b912730e AM |
13972 | + struct au_write_pre wpre; |
13973 | + struct inode *inode; | |
4a4d8108 AM |
13974 | + struct file *h_file; |
13975 | + char __user *buf = (char __user *)ubuf; | |
1facf9fc | 13976 | + |
b912730e | 13977 | + inode = file_inode(file); |
e49829fe | 13978 | + au_mtx_and_read_lock(inode); |
1facf9fc | 13979 | + |
521ced18 | 13980 | + wpre.lsc = 0; |
b912730e AM |
13981 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13982 | + err = PTR_ERR(h_file); | |
13983 | + if (IS_ERR(h_file)) | |
9dbd164d | 13984 | + goto out; |
9dbd164d | 13985 | + |
4a4d8108 | 13986 | + err = vfsub_write_u(h_file, buf, count, ppos); |
b912730e | 13987 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 13988 | + |
4f0767ce | 13989 | +out: |
b912730e | 13990 | + si_read_unlock(inode->i_sb); |
febd17d6 | 13991 | + inode_unlock(inode); |
dece6358 AM |
13992 | + return err; |
13993 | +} | |
1facf9fc | 13994 | + |
076b876e AM |
13995 | +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio, |
13996 | + struct iov_iter *iov_iter) | |
dece6358 | 13997 | +{ |
4a4d8108 AM |
13998 | + ssize_t err; |
13999 | + struct file *file; | |
076b876e | 14000 | + ssize_t (*iter)(struct kiocb *, struct iov_iter *); |
1facf9fc | 14001 | + |
4a4d8108 AM |
14002 | + err = security_file_permission(h_file, rw); |
14003 | + if (unlikely(err)) | |
14004 | + goto out; | |
1facf9fc | 14005 | + |
4a4d8108 | 14006 | + err = -ENOSYS; |
076b876e | 14007 | + iter = NULL; |
5527c038 | 14008 | + if (rw == MAY_READ) |
076b876e | 14009 | + iter = h_file->f_op->read_iter; |
5527c038 | 14010 | + else if (rw == MAY_WRITE) |
076b876e | 14011 | + iter = h_file->f_op->write_iter; |
076b876e AM |
14012 | + |
14013 | + file = kio->ki_filp; | |
14014 | + kio->ki_filp = h_file; | |
14015 | + if (iter) { | |
2cbb1c4b | 14016 | + lockdep_off(); |
076b876e AM |
14017 | + err = iter(kio, iov_iter); |
14018 | + lockdep_on(); | |
4a4d8108 AM |
14019 | + } else |
14020 | + /* currently there is no such fs */ | |
14021 | + WARN_ON_ONCE(1); | |
076b876e | 14022 | + kio->ki_filp = file; |
1facf9fc | 14023 | + |
4f0767ce | 14024 | +out: |
dece6358 AM |
14025 | + return err; |
14026 | +} | |
1facf9fc | 14027 | + |
076b876e | 14028 | +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1facf9fc | 14029 | +{ |
4a4d8108 AM |
14030 | + ssize_t err; |
14031 | + struct file *file, *h_file; | |
b912730e | 14032 | + struct inode *inode; |
dece6358 | 14033 | + struct super_block *sb; |
1facf9fc | 14034 | + |
4a4d8108 | 14035 | + file = kio->ki_filp; |
b912730e AM |
14036 | + inode = file_inode(file); |
14037 | + sb = inode->i_sb; | |
e49829fe | 14038 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 14039 | + |
521ced18 | 14040 | + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0); |
b912730e AM |
14041 | + err = PTR_ERR(h_file); |
14042 | + if (IS_ERR(h_file)) | |
14043 | + goto out; | |
9dbd164d | 14044 | + |
5afbbe0d AM |
14045 | + if (au_test_loopback_kthread()) { |
14046 | + au_warn_loopback(h_file->f_path.dentry->d_sb); | |
14047 | + if (file->f_mapping != h_file->f_mapping) { | |
14048 | + file->f_mapping = h_file->f_mapping; | |
14049 | + smp_mb(); /* unnecessary? */ | |
14050 | + } | |
14051 | + } | |
14052 | + fi_read_unlock(file); | |
14053 | + | |
076b876e | 14054 | + err = au_do_iter(h_file, MAY_READ, kio, iov_iter); |
4a4d8108 AM |
14055 | + /* todo: necessary? */ |
14056 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 14057 | + au_read_post(inode, h_file); |
1facf9fc | 14058 | + |
4f0767ce | 14059 | +out: |
4a4d8108 | 14060 | + si_read_unlock(sb); |
1308ab2a | 14061 | + return err; |
14062 | +} | |
1facf9fc | 14063 | + |
076b876e | 14064 | +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1308ab2a | 14065 | +{ |
4a4d8108 | 14066 | + ssize_t err; |
b912730e AM |
14067 | + struct au_write_pre wpre; |
14068 | + struct inode *inode; | |
4a4d8108 | 14069 | + struct file *file, *h_file; |
1308ab2a | 14070 | + |
4a4d8108 | 14071 | + file = kio->ki_filp; |
b912730e | 14072 | + inode = file_inode(file); |
e49829fe JR |
14073 | + au_mtx_and_read_lock(inode); |
14074 | + | |
521ced18 | 14075 | + wpre.lsc = 0; |
b912730e AM |
14076 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
14077 | + err = PTR_ERR(h_file); | |
14078 | + if (IS_ERR(h_file)) | |
9dbd164d | 14079 | + goto out; |
9dbd164d | 14080 | + |
076b876e | 14081 | + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter); |
b912730e | 14082 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 14083 | + |
4f0767ce | 14084 | +out: |
b912730e | 14085 | + si_read_unlock(inode->i_sb); |
febd17d6 | 14086 | + inode_unlock(inode); |
dece6358 | 14087 | + return err; |
1facf9fc | 14088 | +} |
14089 | + | |
4a4d8108 AM |
14090 | +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, |
14091 | + struct pipe_inode_info *pipe, size_t len, | |
14092 | + unsigned int flags) | |
1facf9fc | 14093 | +{ |
4a4d8108 AM |
14094 | + ssize_t err; |
14095 | + struct file *h_file; | |
b912730e | 14096 | + struct inode *inode; |
dece6358 | 14097 | + struct super_block *sb; |
1facf9fc | 14098 | + |
b912730e AM |
14099 | + inode = file_inode(file); |
14100 | + sb = inode->i_sb; | |
e49829fe | 14101 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 14102 | + |
521ced18 | 14103 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
14104 | + err = PTR_ERR(h_file); |
14105 | + if (IS_ERR(h_file)) | |
dece6358 | 14106 | + goto out; |
1facf9fc | 14107 | + |
4a4d8108 AM |
14108 | + err = vfsub_splice_to(h_file, ppos, pipe, len, flags); |
14109 | + /* todo: necessasry? */ | |
14110 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 14111 | + au_read_post(inode, h_file); |
1facf9fc | 14112 | + |
4f0767ce | 14113 | +out: |
4a4d8108 | 14114 | + si_read_unlock(sb); |
dece6358 | 14115 | + return err; |
1facf9fc | 14116 | +} |
14117 | + | |
4a4d8108 AM |
14118 | +static ssize_t |
14119 | +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos, | |
14120 | + size_t len, unsigned int flags) | |
1facf9fc | 14121 | +{ |
4a4d8108 | 14122 | + ssize_t err; |
b912730e AM |
14123 | + struct au_write_pre wpre; |
14124 | + struct inode *inode; | |
076b876e | 14125 | + struct file *h_file; |
1facf9fc | 14126 | + |
b912730e | 14127 | + inode = file_inode(file); |
e49829fe | 14128 | + au_mtx_and_read_lock(inode); |
9dbd164d | 14129 | + |
521ced18 | 14130 | + wpre.lsc = 0; |
b912730e AM |
14131 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
14132 | + err = PTR_ERR(h_file); | |
14133 | + if (IS_ERR(h_file)) | |
9dbd164d | 14134 | + goto out; |
9dbd164d | 14135 | + |
4a4d8108 | 14136 | + err = vfsub_splice_from(pipe, h_file, ppos, len, flags); |
b912730e | 14137 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 14138 | + |
4f0767ce | 14139 | +out: |
b912730e | 14140 | + si_read_unlock(inode->i_sb); |
febd17d6 | 14141 | + inode_unlock(inode); |
4a4d8108 AM |
14142 | + return err; |
14143 | +} | |
1facf9fc | 14144 | + |
38d290e6 JR |
14145 | +static long aufs_fallocate(struct file *file, int mode, loff_t offset, |
14146 | + loff_t len) | |
14147 | +{ | |
14148 | + long err; | |
b912730e | 14149 | + struct au_write_pre wpre; |
38d290e6 JR |
14150 | + struct inode *inode; |
14151 | + struct file *h_file; | |
14152 | + | |
b912730e | 14153 | + inode = file_inode(file); |
38d290e6 JR |
14154 | + au_mtx_and_read_lock(inode); |
14155 | + | |
521ced18 | 14156 | + wpre.lsc = 0; |
b912730e AM |
14157 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
14158 | + err = PTR_ERR(h_file); | |
14159 | + if (IS_ERR(h_file)) | |
38d290e6 | 14160 | + goto out; |
38d290e6 JR |
14161 | + |
14162 | + lockdep_off(); | |
03673fb0 | 14163 | + err = vfs_fallocate(h_file, mode, offset, len); |
38d290e6 | 14164 | + lockdep_on(); |
b912730e | 14165 | + au_write_post(inode, h_file, &wpre, /*written*/1); |
38d290e6 JR |
14166 | + |
14167 | +out: | |
b912730e | 14168 | + si_read_unlock(inode->i_sb); |
febd17d6 | 14169 | + inode_unlock(inode); |
38d290e6 JR |
14170 | + return err; |
14171 | +} | |
14172 | + | |
521ced18 JR |
14173 | +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos, |
14174 | + struct file *dst, loff_t dst_pos, | |
14175 | + size_t len, unsigned int flags) | |
14176 | +{ | |
14177 | + ssize_t err; | |
14178 | + struct au_write_pre wpre; | |
14179 | + enum { SRC, DST }; | |
14180 | + struct { | |
14181 | + struct inode *inode; | |
14182 | + struct file *h_file; | |
14183 | + struct super_block *h_sb; | |
14184 | + } a[2]; | |
14185 | +#define a_src a[SRC] | |
14186 | +#define a_dst a[DST] | |
14187 | + | |
14188 | + err = -EINVAL; | |
14189 | + a_src.inode = file_inode(src); | |
14190 | + if (unlikely(!S_ISREG(a_src.inode->i_mode))) | |
14191 | + goto out; | |
14192 | + a_dst.inode = file_inode(dst); | |
14193 | + if (unlikely(!S_ISREG(a_dst.inode->i_mode))) | |
14194 | + goto out; | |
14195 | + | |
14196 | + au_mtx_and_read_lock(a_dst.inode); | |
14197 | + /* | |
14198 | + * in order to match the order in di_write_lock2_{child,parent}(), | |
14199 | + * use f_path.dentry for this comparision. | |
14200 | + */ | |
14201 | + if (src->f_path.dentry < dst->f_path.dentry) { | |
14202 | + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1); | |
14203 | + err = PTR_ERR(a_src.h_file); | |
14204 | + if (IS_ERR(a_src.h_file)) | |
14205 | + goto out_si; | |
14206 | + | |
14207 | + wpre.lsc = AuLsc_FI_2; | |
14208 | + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre); | |
14209 | + err = PTR_ERR(a_dst.h_file); | |
14210 | + if (IS_ERR(a_dst.h_file)) { | |
14211 | + au_read_post(a_src.inode, a_src.h_file); | |
14212 | + goto out_si; | |
14213 | + } | |
14214 | + } else { | |
14215 | + wpre.lsc = AuLsc_FI_1; | |
14216 | + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre); | |
14217 | + err = PTR_ERR(a_dst.h_file); | |
14218 | + if (IS_ERR(a_dst.h_file)) | |
14219 | + goto out_si; | |
14220 | + | |
14221 | + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2); | |
14222 | + err = PTR_ERR(a_src.h_file); | |
14223 | + if (IS_ERR(a_src.h_file)) { | |
14224 | + au_write_post(a_dst.inode, a_dst.h_file, &wpre, | |
14225 | + /*written*/0); | |
14226 | + goto out_si; | |
14227 | + } | |
14228 | + } | |
14229 | + | |
14230 | + err = -EXDEV; | |
14231 | + a_src.h_sb = file_inode(a_src.h_file)->i_sb; | |
14232 | + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb; | |
14233 | + if (unlikely(a_src.h_sb != a_dst.h_sb)) { | |
14234 | + AuDbgFile(src); | |
14235 | + AuDbgFile(dst); | |
14236 | + goto out_file; | |
14237 | + } | |
14238 | + | |
14239 | + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file, | |
14240 | + dst_pos, len, flags); | |
14241 | + | |
14242 | +out_file: | |
14243 | + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err); | |
14244 | + fi_read_unlock(src); | |
14245 | + au_read_post(a_src.inode, a_src.h_file); | |
14246 | +out_si: | |
14247 | + si_read_unlock(a_dst.inode->i_sb); | |
14248 | + inode_unlock(a_dst.inode); | |
14249 | +out: | |
14250 | + return err; | |
14251 | +#undef a_src | |
14252 | +#undef a_dst | |
14253 | +} | |
14254 | + | |
4a4d8108 AM |
14255 | +/* ---------------------------------------------------------------------- */ |
14256 | + | |
9dbd164d AM |
14257 | +/* |
14258 | + * The locking order around current->mmap_sem. | |
14259 | + * - in most and regular cases | |
14260 | + * file I/O syscall -- aufs_read() or something | |
14261 | + * -- si_rwsem for read -- mmap_sem | |
14262 | + * (Note that [fdi]i_rwsem are released before mmap_sem). | |
14263 | + * - in mmap case | |
14264 | + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem | |
14265 | + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for | |
14266 | + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in | |
14267 | + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though. | |
14268 | + * It means that when aufs acquires si_rwsem for write, the process should never | |
14269 | + * acquire mmap_sem. | |
14270 | + * | |
392086de | 14271 | + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a |
9dbd164d AM |
14272 | + * problem either since any directory is not able to be mmap-ed. |
14273 | + * The similar scenario is applied to aufs_readlink() too. | |
14274 | + */ | |
14275 | + | |
38d290e6 | 14276 | +#if 0 /* stop calling security_file_mmap() */ |
2dfbb274 AM |
14277 | +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */ |
14278 | +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b) | |
14279 | + | |
14280 | +static unsigned long au_arch_prot_conv(unsigned long flags) | |
14281 | +{ | |
14282 | + /* currently ppc64 only */ | |
14283 | +#ifdef CONFIG_PPC64 | |
14284 | + /* cf. linux/arch/powerpc/include/asm/mman.h */ | |
14285 | + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO); | |
14286 | + return AuConv_VM_PROT(flags, SAO); | |
14287 | +#else | |
14288 | + AuDebugOn(arch_calc_vm_prot_bits(-1)); | |
14289 | + return 0; | |
14290 | +#endif | |
14291 | +} | |
14292 | + | |
14293 | +static unsigned long au_prot_conv(unsigned long flags) | |
14294 | +{ | |
14295 | + return AuConv_VM_PROT(flags, READ) | |
14296 | + | AuConv_VM_PROT(flags, WRITE) | |
14297 | + | AuConv_VM_PROT(flags, EXEC) | |
14298 | + | au_arch_prot_conv(flags); | |
14299 | +} | |
14300 | + | |
14301 | +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */ | |
14302 | +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b) | |
14303 | + | |
14304 | +static unsigned long au_flag_conv(unsigned long flags) | |
14305 | +{ | |
14306 | + return AuConv_VM_MAP(flags, GROWSDOWN) | |
14307 | + | AuConv_VM_MAP(flags, DENYWRITE) | |
2dfbb274 AM |
14308 | + | AuConv_VM_MAP(flags, LOCKED); |
14309 | +} | |
38d290e6 | 14310 | +#endif |
2dfbb274 | 14311 | + |
9dbd164d | 14312 | +static int aufs_mmap(struct file *file, struct vm_area_struct *vma) |
dece6358 | 14313 | +{ |
4a4d8108 | 14314 | + int err; |
4a4d8108 | 14315 | + const unsigned char wlock |
9dbd164d | 14316 | + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED); |
4a4d8108 | 14317 | + struct super_block *sb; |
9dbd164d | 14318 | + struct file *h_file; |
b912730e | 14319 | + struct inode *inode; |
9dbd164d AM |
14320 | + |
14321 | + AuDbgVmRegion(file, vma); | |
1308ab2a | 14322 | + |
b912730e AM |
14323 | + inode = file_inode(file); |
14324 | + sb = inode->i_sb; | |
9dbd164d | 14325 | + lockdep_off(); |
e49829fe | 14326 | + si_read_lock(sb, AuLock_NOPLMW); |
4a4d8108 | 14327 | + |
b912730e | 14328 | + h_file = au_write_pre(file, wlock, /*wpre*/NULL); |
9dbd164d | 14329 | + lockdep_on(); |
b912730e AM |
14330 | + err = PTR_ERR(h_file); |
14331 | + if (IS_ERR(h_file)) | |
14332 | + goto out; | |
1308ab2a | 14333 | + |
b912730e AM |
14334 | + err = 0; |
14335 | + au_set_mmapped(file); | |
9dbd164d | 14336 | + au_vm_file_reset(vma, h_file); |
38d290e6 JR |
14337 | + /* |
14338 | + * we cannot call security_mmap_file() here since it may acquire | |
14339 | + * mmap_sem or i_mutex. | |
14340 | + * | |
14341 | + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags), | |
14342 | + * au_flag_conv(vma->vm_flags)); | |
14343 | + */ | |
9dbd164d | 14344 | + if (!err) |
521ced18 | 14345 | + err = call_mmap(h_file, vma); |
b912730e AM |
14346 | + if (!err) { |
14347 | + au_vm_prfile_set(vma, file); | |
14348 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
14349 | + goto out_fput; /* success */ | |
14350 | + } | |
2cbb1c4b JR |
14351 | + au_unset_mmapped(file); |
14352 | + au_vm_file_reset(vma, file); | |
b912730e | 14353 | + |
2cbb1c4b | 14354 | +out_fput: |
9dbd164d | 14355 | + lockdep_off(); |
b912730e AM |
14356 | + ii_write_unlock(inode); |
14357 | + lockdep_on(); | |
14358 | + fput(h_file); | |
4f0767ce | 14359 | +out: |
b912730e | 14360 | + lockdep_off(); |
9dbd164d AM |
14361 | + si_read_unlock(sb); |
14362 | + lockdep_on(); | |
14363 | + AuTraceErr(err); | |
4a4d8108 AM |
14364 | + return err; |
14365 | +} | |
14366 | + | |
14367 | +/* ---------------------------------------------------------------------- */ | |
14368 | + | |
1e00d052 AM |
14369 | +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end, |
14370 | + int datasync) | |
4a4d8108 AM |
14371 | +{ |
14372 | + int err; | |
b912730e | 14373 | + struct au_write_pre wpre; |
4a4d8108 AM |
14374 | + struct inode *inode; |
14375 | + struct file *h_file; | |
4a4d8108 AM |
14376 | + |
14377 | + err = 0; /* -EBADF; */ /* posix? */ | |
14378 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
b912730e | 14379 | + goto out; |
4a4d8108 | 14380 | + |
b912730e AM |
14381 | + inode = file_inode(file); |
14382 | + au_mtx_and_read_lock(inode); | |
14383 | + | |
521ced18 | 14384 | + wpre.lsc = 0; |
b912730e AM |
14385 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
14386 | + err = PTR_ERR(h_file); | |
14387 | + if (IS_ERR(h_file)) | |
4a4d8108 | 14388 | + goto out_unlock; |
4a4d8108 | 14389 | + |
53392da6 | 14390 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
b912730e | 14391 | + au_write_post(inode, h_file, &wpre, /*written*/0); |
4a4d8108 | 14392 | + |
4f0767ce | 14393 | +out_unlock: |
b912730e | 14394 | + si_read_unlock(inode->i_sb); |
febd17d6 | 14395 | + inode_unlock(inode); |
b912730e | 14396 | +out: |
4a4d8108 | 14397 | + return err; |
dece6358 AM |
14398 | +} |
14399 | + | |
4a4d8108 | 14400 | +static int aufs_fasync(int fd, struct file *file, int flag) |
dece6358 | 14401 | +{ |
4a4d8108 AM |
14402 | + int err; |
14403 | + struct file *h_file; | |
4a4d8108 | 14404 | + struct super_block *sb; |
1308ab2a | 14405 | + |
b912730e | 14406 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 14407 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 14408 | + |
521ced18 | 14409 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
14410 | + err = PTR_ERR(h_file); |
14411 | + if (IS_ERR(h_file)) | |
4a4d8108 AM |
14412 | + goto out; |
14413 | + | |
523b37e3 | 14414 | + if (h_file->f_op->fasync) |
4a4d8108 | 14415 | + err = h_file->f_op->fasync(fd, h_file, flag); |
b912730e | 14416 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 14417 | + |
4f0767ce | 14418 | +out: |
4a4d8108 | 14419 | + si_read_unlock(sb); |
1308ab2a | 14420 | + return err; |
dece6358 | 14421 | +} |
4a4d8108 | 14422 | + |
febd17d6 JR |
14423 | +static int aufs_setfl(struct file *file, unsigned long arg) |
14424 | +{ | |
14425 | + int err; | |
14426 | + struct file *h_file; | |
14427 | + struct super_block *sb; | |
14428 | + | |
14429 | + sb = file->f_path.dentry->d_sb; | |
14430 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
14431 | + | |
521ced18 | 14432 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
febd17d6 JR |
14433 | + err = PTR_ERR(h_file); |
14434 | + if (IS_ERR(h_file)) | |
14435 | + goto out; | |
14436 | + | |
14437 | + arg |= vfsub_file_flags(file) & FASYNC; /* stop calling h_file->fasync */ | |
14438 | + err = setfl(/*unused fd*/-1, h_file, arg); | |
14439 | + fput(h_file); /* instead of au_read_post() */ | |
14440 | + | |
14441 | +out: | |
14442 | + si_read_unlock(sb); | |
14443 | + return err; | |
14444 | +} | |
14445 | + | |
4a4d8108 AM |
14446 | +/* ---------------------------------------------------------------------- */ |
14447 | + | |
14448 | +/* no one supports this operation, currently */ | |
14449 | +#if 0 | |
14450 | +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset, | |
2000de60 | 14451 | + size_t len, loff_t *pos, int more) |
4a4d8108 AM |
14452 | +{ |
14453 | +} | |
14454 | +#endif | |
14455 | + | |
14456 | +/* ---------------------------------------------------------------------- */ | |
14457 | + | |
14458 | +const struct file_operations aufs_file_fop = { | |
14459 | + .owner = THIS_MODULE, | |
2cbb1c4b | 14460 | + |
027c5e7a | 14461 | + .llseek = default_llseek, |
4a4d8108 AM |
14462 | + |
14463 | + .read = aufs_read, | |
14464 | + .write = aufs_write, | |
076b876e AM |
14465 | + .read_iter = aufs_read_iter, |
14466 | + .write_iter = aufs_write_iter, | |
14467 | + | |
4a4d8108 AM |
14468 | +#ifdef CONFIG_AUFS_POLL |
14469 | + .poll = aufs_poll, | |
14470 | +#endif | |
14471 | + .unlocked_ioctl = aufs_ioctl_nondir, | |
b752ccd1 | 14472 | +#ifdef CONFIG_COMPAT |
c2b27bf2 | 14473 | + .compat_ioctl = aufs_compat_ioctl_nondir, |
b752ccd1 | 14474 | +#endif |
4a4d8108 AM |
14475 | + .mmap = aufs_mmap, |
14476 | + .open = aufs_open_nondir, | |
14477 | + .flush = aufs_flush_nondir, | |
14478 | + .release = aufs_release_nondir, | |
14479 | + .fsync = aufs_fsync_nondir, | |
4a4d8108 AM |
14480 | + .fasync = aufs_fasync, |
14481 | + /* .sendpage = aufs_sendpage, */ | |
febd17d6 | 14482 | + .setfl = aufs_setfl, |
4a4d8108 AM |
14483 | + .splice_write = aufs_splice_write, |
14484 | + .splice_read = aufs_splice_read, | |
14485 | +#if 0 | |
14486 | + .aio_splice_write = aufs_aio_splice_write, | |
38d290e6 | 14487 | + .aio_splice_read = aufs_aio_splice_read, |
4a4d8108 | 14488 | +#endif |
521ced18 JR |
14489 | + .fallocate = aufs_fallocate, |
14490 | + .copy_file_range = aufs_copy_file_range | |
4a4d8108 | 14491 | +}; |
7f207e10 AM |
14492 | diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h |
14493 | --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 14494 | +++ linux/fs/aufs/fstype.h 2017-05-06 22:16:52.778220093 +0200 |
b912730e | 14495 | @@ -0,0 +1,400 @@ |
4a4d8108 | 14496 | +/* |
a2654f78 | 14497 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
14498 | + * |
14499 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14500 | + * it under the terms of the GNU General Public License as published by | |
14501 | + * the Free Software Foundation; either version 2 of the License, or | |
14502 | + * (at your option) any later version. | |
14503 | + * | |
14504 | + * This program is distributed in the hope that it will be useful, | |
14505 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14506 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14507 | + * GNU General Public License for more details. | |
14508 | + * | |
14509 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14510 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
14511 | + */ |
14512 | + | |
14513 | +/* | |
14514 | + * judging filesystem type | |
14515 | + */ | |
14516 | + | |
14517 | +#ifndef __AUFS_FSTYPE_H__ | |
14518 | +#define __AUFS_FSTYPE_H__ | |
14519 | + | |
14520 | +#ifdef __KERNEL__ | |
14521 | + | |
14522 | +#include <linux/fs.h> | |
14523 | +#include <linux/magic.h> | |
b912730e | 14524 | +#include <linux/nfs_fs.h> |
b95c5147 | 14525 | +#include <linux/romfs_fs.h> |
4a4d8108 AM |
14526 | + |
14527 | +static inline int au_test_aufs(struct super_block *sb) | |
14528 | +{ | |
14529 | + return sb->s_magic == AUFS_SUPER_MAGIC; | |
14530 | +} | |
14531 | + | |
14532 | +static inline const char *au_sbtype(struct super_block *sb) | |
14533 | +{ | |
14534 | + return sb->s_type->name; | |
14535 | +} | |
1308ab2a | 14536 | + |
14537 | +static inline int au_test_iso9660(struct super_block *sb __maybe_unused) | |
14538 | +{ | |
f0c0a007 | 14539 | +#if IS_ENABLED(CONFIG_ISO9660_FS) |
2000de60 | 14540 | + return sb->s_magic == ISOFS_SUPER_MAGIC; |
dece6358 AM |
14541 | +#else |
14542 | + return 0; | |
14543 | +#endif | |
14544 | +} | |
14545 | + | |
1308ab2a | 14546 | +static inline int au_test_romfs(struct super_block *sb __maybe_unused) |
dece6358 | 14547 | +{ |
f0c0a007 | 14548 | +#if IS_ENABLED(CONFIG_ROMFS_FS) |
2000de60 | 14549 | + return sb->s_magic == ROMFS_MAGIC; |
dece6358 AM |
14550 | +#else |
14551 | + return 0; | |
14552 | +#endif | |
14553 | +} | |
14554 | + | |
1308ab2a | 14555 | +static inline int au_test_cramfs(struct super_block *sb __maybe_unused) |
dece6358 | 14556 | +{ |
f0c0a007 | 14557 | +#if IS_ENABLED(CONFIG_CRAMFS) |
1308ab2a | 14558 | + return sb->s_magic == CRAMFS_MAGIC; |
14559 | +#endif | |
14560 | + return 0; | |
14561 | +} | |
14562 | + | |
14563 | +static inline int au_test_nfs(struct super_block *sb __maybe_unused) | |
14564 | +{ | |
f0c0a007 | 14565 | +#if IS_ENABLED(CONFIG_NFS_FS) |
1308ab2a | 14566 | + return sb->s_magic == NFS_SUPER_MAGIC; |
dece6358 AM |
14567 | +#else |
14568 | + return 0; | |
14569 | +#endif | |
14570 | +} | |
14571 | + | |
1308ab2a | 14572 | +static inline int au_test_fuse(struct super_block *sb __maybe_unused) |
dece6358 | 14573 | +{ |
f0c0a007 | 14574 | +#if IS_ENABLED(CONFIG_FUSE_FS) |
1308ab2a | 14575 | + return sb->s_magic == FUSE_SUPER_MAGIC; |
dece6358 AM |
14576 | +#else |
14577 | + return 0; | |
14578 | +#endif | |
14579 | +} | |
14580 | + | |
1308ab2a | 14581 | +static inline int au_test_xfs(struct super_block *sb __maybe_unused) |
dece6358 | 14582 | +{ |
f0c0a007 | 14583 | +#if IS_ENABLED(CONFIG_XFS_FS) |
1308ab2a | 14584 | + return sb->s_magic == XFS_SB_MAGIC; |
dece6358 AM |
14585 | +#else |
14586 | + return 0; | |
14587 | +#endif | |
14588 | +} | |
14589 | + | |
1308ab2a | 14590 | +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused) |
dece6358 | 14591 | +{ |
1308ab2a | 14592 | +#ifdef CONFIG_TMPFS |
14593 | + return sb->s_magic == TMPFS_MAGIC; | |
14594 | +#else | |
14595 | + return 0; | |
dece6358 | 14596 | +#endif |
dece6358 AM |
14597 | +} |
14598 | + | |
1308ab2a | 14599 | +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused) |
1facf9fc | 14600 | +{ |
f0c0a007 | 14601 | +#if IS_ENABLED(CONFIG_ECRYPT_FS) |
1308ab2a | 14602 | + return !strcmp(au_sbtype(sb), "ecryptfs"); |
14603 | +#else | |
14604 | + return 0; | |
14605 | +#endif | |
1facf9fc | 14606 | +} |
14607 | + | |
1308ab2a | 14608 | +static inline int au_test_ramfs(struct super_block *sb) |
14609 | +{ | |
14610 | + return sb->s_magic == RAMFS_MAGIC; | |
14611 | +} | |
14612 | + | |
14613 | +static inline int au_test_ubifs(struct super_block *sb __maybe_unused) | |
14614 | +{ | |
f0c0a007 | 14615 | +#if IS_ENABLED(CONFIG_UBIFS_FS) |
1308ab2a | 14616 | + return sb->s_magic == UBIFS_SUPER_MAGIC; |
14617 | +#else | |
14618 | + return 0; | |
14619 | +#endif | |
14620 | +} | |
14621 | + | |
14622 | +static inline int au_test_procfs(struct super_block *sb __maybe_unused) | |
14623 | +{ | |
14624 | +#ifdef CONFIG_PROC_FS | |
14625 | + return sb->s_magic == PROC_SUPER_MAGIC; | |
14626 | +#else | |
14627 | + return 0; | |
14628 | +#endif | |
14629 | +} | |
14630 | + | |
14631 | +static inline int au_test_sysfs(struct super_block *sb __maybe_unused) | |
14632 | +{ | |
14633 | +#ifdef CONFIG_SYSFS | |
14634 | + return sb->s_magic == SYSFS_MAGIC; | |
14635 | +#else | |
14636 | + return 0; | |
14637 | +#endif | |
14638 | +} | |
14639 | + | |
14640 | +static inline int au_test_configfs(struct super_block *sb __maybe_unused) | |
14641 | +{ | |
f0c0a007 | 14642 | +#if IS_ENABLED(CONFIG_CONFIGFS_FS) |
1308ab2a | 14643 | + return sb->s_magic == CONFIGFS_MAGIC; |
14644 | +#else | |
14645 | + return 0; | |
14646 | +#endif | |
14647 | +} | |
14648 | + | |
14649 | +static inline int au_test_minix(struct super_block *sb __maybe_unused) | |
14650 | +{ | |
f0c0a007 | 14651 | +#if IS_ENABLED(CONFIG_MINIX_FS) |
1308ab2a | 14652 | + return sb->s_magic == MINIX3_SUPER_MAGIC |
14653 | + || sb->s_magic == MINIX2_SUPER_MAGIC | |
14654 | + || sb->s_magic == MINIX2_SUPER_MAGIC2 | |
14655 | + || sb->s_magic == MINIX_SUPER_MAGIC | |
14656 | + || sb->s_magic == MINIX_SUPER_MAGIC2; | |
14657 | +#else | |
14658 | + return 0; | |
14659 | +#endif | |
14660 | +} | |
14661 | + | |
1308ab2a | 14662 | +static inline int au_test_fat(struct super_block *sb __maybe_unused) |
14663 | +{ | |
f0c0a007 | 14664 | +#if IS_ENABLED(CONFIG_FAT_FS) |
1308ab2a | 14665 | + return sb->s_magic == MSDOS_SUPER_MAGIC; |
14666 | +#else | |
14667 | + return 0; | |
14668 | +#endif | |
14669 | +} | |
14670 | + | |
14671 | +static inline int au_test_msdos(struct super_block *sb) | |
14672 | +{ | |
14673 | + return au_test_fat(sb); | |
14674 | +} | |
14675 | + | |
14676 | +static inline int au_test_vfat(struct super_block *sb) | |
14677 | +{ | |
14678 | + return au_test_fat(sb); | |
14679 | +} | |
14680 | + | |
14681 | +static inline int au_test_securityfs(struct super_block *sb __maybe_unused) | |
14682 | +{ | |
14683 | +#ifdef CONFIG_SECURITYFS | |
14684 | + return sb->s_magic == SECURITYFS_MAGIC; | |
14685 | +#else | |
14686 | + return 0; | |
14687 | +#endif | |
14688 | +} | |
14689 | + | |
14690 | +static inline int au_test_squashfs(struct super_block *sb __maybe_unused) | |
14691 | +{ | |
f0c0a007 | 14692 | +#if IS_ENABLED(CONFIG_SQUASHFS) |
1308ab2a | 14693 | + return sb->s_magic == SQUASHFS_MAGIC; |
14694 | +#else | |
14695 | + return 0; | |
14696 | +#endif | |
14697 | +} | |
14698 | + | |
14699 | +static inline int au_test_btrfs(struct super_block *sb __maybe_unused) | |
14700 | +{ | |
f0c0a007 | 14701 | +#if IS_ENABLED(CONFIG_BTRFS_FS) |
1308ab2a | 14702 | + return sb->s_magic == BTRFS_SUPER_MAGIC; |
14703 | +#else | |
14704 | + return 0; | |
14705 | +#endif | |
14706 | +} | |
14707 | + | |
14708 | +static inline int au_test_xenfs(struct super_block *sb __maybe_unused) | |
14709 | +{ | |
f0c0a007 | 14710 | +#if IS_ENABLED(CONFIG_XENFS) |
1308ab2a | 14711 | + return sb->s_magic == XENFS_SUPER_MAGIC; |
14712 | +#else | |
14713 | + return 0; | |
14714 | +#endif | |
14715 | +} | |
14716 | + | |
14717 | +static inline int au_test_debugfs(struct super_block *sb __maybe_unused) | |
14718 | +{ | |
14719 | +#ifdef CONFIG_DEBUG_FS | |
14720 | + return sb->s_magic == DEBUGFS_MAGIC; | |
14721 | +#else | |
14722 | + return 0; | |
14723 | +#endif | |
14724 | +} | |
14725 | + | |
14726 | +static inline int au_test_nilfs(struct super_block *sb __maybe_unused) | |
14727 | +{ | |
f0c0a007 | 14728 | +#if IS_ENABLED(CONFIG_NILFS) |
1308ab2a | 14729 | + return sb->s_magic == NILFS_SUPER_MAGIC; |
14730 | +#else | |
14731 | + return 0; | |
14732 | +#endif | |
14733 | +} | |
14734 | + | |
4a4d8108 AM |
14735 | +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused) |
14736 | +{ | |
f0c0a007 | 14737 | +#if IS_ENABLED(CONFIG_HFSPLUS_FS) |
4a4d8108 AM |
14738 | + return sb->s_magic == HFSPLUS_SUPER_MAGIC; |
14739 | +#else | |
14740 | + return 0; | |
14741 | +#endif | |
14742 | +} | |
14743 | + | |
1308ab2a | 14744 | +/* ---------------------------------------------------------------------- */ |
14745 | +/* | |
14746 | + * they can't be an aufs branch. | |
14747 | + */ | |
14748 | +static inline int au_test_fs_unsuppoted(struct super_block *sb) | |
14749 | +{ | |
14750 | + return | |
14751 | +#ifndef CONFIG_AUFS_BR_RAMFS | |
14752 | + au_test_ramfs(sb) || | |
14753 | +#endif | |
14754 | + au_test_procfs(sb) | |
14755 | + || au_test_sysfs(sb) | |
14756 | + || au_test_configfs(sb) | |
14757 | + || au_test_debugfs(sb) | |
14758 | + || au_test_securityfs(sb) | |
14759 | + || au_test_xenfs(sb) | |
14760 | + || au_test_ecryptfs(sb) | |
14761 | + /* || !strcmp(au_sbtype(sb), "unionfs") */ | |
14762 | + || au_test_aufs(sb); /* will be supported in next version */ | |
14763 | +} | |
14764 | + | |
1308ab2a | 14765 | +static inline int au_test_fs_remote(struct super_block *sb) |
14766 | +{ | |
14767 | + return !au_test_tmpfs(sb) | |
14768 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14769 | + && !au_test_ramfs(sb) | |
14770 | +#endif | |
14771 | + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV); | |
14772 | +} | |
14773 | + | |
14774 | +/* ---------------------------------------------------------------------- */ | |
14775 | + | |
14776 | +/* | |
14777 | + * Note: these functions (below) are created after reading ->getattr() in all | |
14778 | + * filesystems under linux/fs. it means we have to do so in every update... | |
14779 | + */ | |
14780 | + | |
14781 | +/* | |
14782 | + * some filesystems require getattr to refresh the inode attributes before | |
14783 | + * referencing. | |
14784 | + * in most cases, we can rely on the inode attribute in NFS (or every remote fs) | |
14785 | + * and leave the work for d_revalidate() | |
14786 | + */ | |
14787 | +static inline int au_test_fs_refresh_iattr(struct super_block *sb) | |
14788 | +{ | |
14789 | + return au_test_nfs(sb) | |
14790 | + || au_test_fuse(sb) | |
1308ab2a | 14791 | + /* || au_test_btrfs(sb) */ /* untested */ |
1308ab2a | 14792 | + ; |
14793 | +} | |
14794 | + | |
14795 | +/* | |
14796 | + * filesystems which don't maintain i_size or i_blocks. | |
14797 | + */ | |
14798 | +static inline int au_test_fs_bad_iattr_size(struct super_block *sb) | |
14799 | +{ | |
14800 | + return au_test_xfs(sb) | |
4a4d8108 AM |
14801 | + || au_test_btrfs(sb) |
14802 | + || au_test_ubifs(sb) | |
14803 | + || au_test_hfsplus(sb) /* maintained, but incorrect */ | |
1308ab2a | 14804 | + /* || au_test_minix(sb) */ /* untested */ |
14805 | + ; | |
14806 | +} | |
14807 | + | |
14808 | +/* | |
14809 | + * filesystems which don't store the correct value in some of their inode | |
14810 | + * attributes. | |
14811 | + */ | |
14812 | +static inline int au_test_fs_bad_iattr(struct super_block *sb) | |
14813 | +{ | |
14814 | + return au_test_fs_bad_iattr_size(sb) | |
1308ab2a | 14815 | + || au_test_fat(sb) |
14816 | + || au_test_msdos(sb) | |
14817 | + || au_test_vfat(sb); | |
1facf9fc | 14818 | +} |
14819 | + | |
14820 | +/* they don't check i_nlink in link(2) */ | |
14821 | +static inline int au_test_fs_no_limit_nlink(struct super_block *sb) | |
14822 | +{ | |
14823 | + return au_test_tmpfs(sb) | |
14824 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14825 | + || au_test_ramfs(sb) | |
14826 | +#endif | |
4a4d8108 | 14827 | + || au_test_ubifs(sb) |
4a4d8108 | 14828 | + || au_test_hfsplus(sb); |
1facf9fc | 14829 | +} |
14830 | + | |
14831 | +/* | |
14832 | + * filesystems which sets S_NOATIME and S_NOCMTIME. | |
14833 | + */ | |
14834 | +static inline int au_test_fs_notime(struct super_block *sb) | |
14835 | +{ | |
14836 | + return au_test_nfs(sb) | |
14837 | + || au_test_fuse(sb) | |
dece6358 | 14838 | + || au_test_ubifs(sb) |
1facf9fc | 14839 | + ; |
14840 | +} | |
14841 | + | |
1facf9fc | 14842 | +/* temporary support for i#1 in cramfs */ |
14843 | +static inline int au_test_fs_unique_ino(struct inode *inode) | |
14844 | +{ | |
14845 | + if (au_test_cramfs(inode->i_sb)) | |
14846 | + return inode->i_ino != 1; | |
14847 | + return 1; | |
14848 | +} | |
14849 | + | |
14850 | +/* ---------------------------------------------------------------------- */ | |
14851 | + | |
14852 | +/* | |
14853 | + * the filesystem where the xino files placed must support i/o after unlink and | |
14854 | + * maintain i_size and i_blocks. | |
14855 | + */ | |
14856 | +static inline int au_test_fs_bad_xino(struct super_block *sb) | |
14857 | +{ | |
14858 | + return au_test_fs_remote(sb) | |
14859 | + || au_test_fs_bad_iattr_size(sb) | |
1facf9fc | 14860 | + /* don't want unnecessary work for xino */ |
14861 | + || au_test_aufs(sb) | |
1308ab2a | 14862 | + || au_test_ecryptfs(sb) |
14863 | + || au_test_nilfs(sb); | |
1facf9fc | 14864 | +} |
14865 | + | |
14866 | +static inline int au_test_fs_trunc_xino(struct super_block *sb) | |
14867 | +{ | |
14868 | + return au_test_tmpfs(sb) | |
14869 | + || au_test_ramfs(sb); | |
14870 | +} | |
14871 | + | |
14872 | +/* | |
14873 | + * test if the @sb is real-readonly. | |
14874 | + */ | |
14875 | +static inline int au_test_fs_rr(struct super_block *sb) | |
14876 | +{ | |
14877 | + return au_test_squashfs(sb) | |
14878 | + || au_test_iso9660(sb) | |
14879 | + || au_test_cramfs(sb) | |
14880 | + || au_test_romfs(sb); | |
14881 | +} | |
14882 | + | |
b912730e AM |
14883 | +/* |
14884 | + * test if the @inode is nfs with 'noacl' option | |
14885 | + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.' | |
14886 | + */ | |
14887 | +static inline int au_test_nfs_noacl(struct inode *inode) | |
14888 | +{ | |
14889 | + return au_test_nfs(inode->i_sb) | |
14890 | + /* && IS_POSIXACL(inode) */ | |
14891 | + && !nfs_server_capable(inode, NFS_CAP_ACLS); | |
14892 | +} | |
14893 | + | |
1facf9fc | 14894 | +#endif /* __KERNEL__ */ |
14895 | +#endif /* __AUFS_FSTYPE_H__ */ | |
7f207e10 AM |
14896 | diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c |
14897 | --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 14898 | +++ linux/fs/aufs/hfsnotify.c 2017-05-06 22:16:52.778220093 +0200 |
5afbbe0d | 14899 | @@ -0,0 +1,287 @@ |
1facf9fc | 14900 | +/* |
a2654f78 | 14901 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 14902 | + * |
14903 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14904 | + * it under the terms of the GNU General Public License as published by | |
14905 | + * the Free Software Foundation; either version 2 of the License, or | |
14906 | + * (at your option) any later version. | |
dece6358 AM |
14907 | + * |
14908 | + * This program is distributed in the hope that it will be useful, | |
14909 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14910 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14911 | + * GNU General Public License for more details. | |
14912 | + * | |
14913 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14914 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 14915 | + */ |
14916 | + | |
14917 | +/* | |
4a4d8108 | 14918 | + * fsnotify for the lower directories |
1facf9fc | 14919 | + */ |
14920 | + | |
14921 | +#include "aufs.h" | |
14922 | + | |
4a4d8108 AM |
14923 | +/* FS_IN_IGNORED is unnecessary */ |
14924 | +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE | |
14925 | + | FS_CREATE | FS_EVENT_ON_CHILD); | |
7f207e10 | 14926 | +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq); |
7eafdf33 | 14927 | +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0); |
1facf9fc | 14928 | + |
0c5527e5 | 14929 | +static void au_hfsn_free_mark(struct fsnotify_mark *mark) |
1facf9fc | 14930 | +{ |
0c5527e5 AM |
14931 | + struct au_hnotify *hn = container_of(mark, struct au_hnotify, |
14932 | + hn_mark); | |
5afbbe0d | 14933 | + /* AuDbg("here\n"); */ |
f0c0a007 | 14934 | + au_cache_dfree_hnotify(hn); |
076b876e | 14935 | + smp_mb__before_atomic(); |
1716fcea AM |
14936 | + if (atomic64_dec_and_test(&au_hfsn_ifree)) |
14937 | + wake_up(&au_hfsn_wq); | |
4a4d8108 | 14938 | +} |
1facf9fc | 14939 | + |
027c5e7a | 14940 | +static int au_hfsn_alloc(struct au_hinode *hinode) |
4a4d8108 | 14941 | +{ |
1716fcea | 14942 | + int err; |
027c5e7a AM |
14943 | + struct au_hnotify *hn; |
14944 | + struct super_block *sb; | |
14945 | + struct au_branch *br; | |
0c5527e5 | 14946 | + struct fsnotify_mark *mark; |
027c5e7a | 14947 | + aufs_bindex_t bindex; |
1facf9fc | 14948 | + |
027c5e7a AM |
14949 | + hn = hinode->hi_notify; |
14950 | + sb = hn->hn_aufs_inode->i_sb; | |
14951 | + bindex = au_br_index(sb, hinode->hi_id); | |
14952 | + br = au_sbr(sb, bindex); | |
1716fcea AM |
14953 | + AuDebugOn(!br->br_hfsn); |
14954 | + | |
0c5527e5 AM |
14955 | + mark = &hn->hn_mark; |
14956 | + fsnotify_init_mark(mark, au_hfsn_free_mark); | |
14957 | + mark->mask = AuHfsnMask; | |
7f207e10 AM |
14958 | + /* |
14959 | + * by udba rename or rmdir, aufs assign a new inode to the known | |
14960 | + * h_inode, so specify 1 to allow dups. | |
14961 | + */ | |
c1595e42 | 14962 | + lockdep_off(); |
1716fcea | 14963 | + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode, |
027c5e7a | 14964 | + /*mnt*/NULL, /*allow_dups*/1); |
c1595e42 | 14965 | + lockdep_on(); |
1716fcea AM |
14966 | + |
14967 | + return err; | |
1facf9fc | 14968 | +} |
14969 | + | |
7eafdf33 | 14970 | +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn) |
1facf9fc | 14971 | +{ |
0c5527e5 | 14972 | + struct fsnotify_mark *mark; |
7eafdf33 | 14973 | + unsigned long long ull; |
1716fcea | 14974 | + struct fsnotify_group *group; |
7eafdf33 AM |
14975 | + |
14976 | + ull = atomic64_inc_return(&au_hfsn_ifree); | |
14977 | + BUG_ON(!ull); | |
953406b4 | 14978 | + |
0c5527e5 | 14979 | + mark = &hn->hn_mark; |
1716fcea AM |
14980 | + spin_lock(&mark->lock); |
14981 | + group = mark->group; | |
14982 | + fsnotify_get_group(group); | |
14983 | + spin_unlock(&mark->lock); | |
c1595e42 | 14984 | + lockdep_off(); |
1716fcea | 14985 | + fsnotify_destroy_mark(mark, group); |
5afbbe0d | 14986 | + fsnotify_put_mark(mark); |
1716fcea | 14987 | + fsnotify_put_group(group); |
c1595e42 | 14988 | + lockdep_on(); |
7f207e10 | 14989 | + |
7eafdf33 AM |
14990 | + /* free hn by myself */ |
14991 | + return 0; | |
1facf9fc | 14992 | +} |
14993 | + | |
14994 | +/* ---------------------------------------------------------------------- */ | |
14995 | + | |
4a4d8108 | 14996 | +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set) |
1facf9fc | 14997 | +{ |
0c5527e5 | 14998 | + struct fsnotify_mark *mark; |
1facf9fc | 14999 | + |
0c5527e5 AM |
15000 | + mark = &hinode->hi_notify->hn_mark; |
15001 | + spin_lock(&mark->lock); | |
1facf9fc | 15002 | + if (do_set) { |
0c5527e5 AM |
15003 | + AuDebugOn(mark->mask & AuHfsnMask); |
15004 | + mark->mask |= AuHfsnMask; | |
1facf9fc | 15005 | + } else { |
0c5527e5 AM |
15006 | + AuDebugOn(!(mark->mask & AuHfsnMask)); |
15007 | + mark->mask &= ~AuHfsnMask; | |
1facf9fc | 15008 | + } |
0c5527e5 | 15009 | + spin_unlock(&mark->lock); |
4a4d8108 | 15010 | + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */ |
1facf9fc | 15011 | +} |
15012 | + | |
4a4d8108 | 15013 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15014 | + |
4a4d8108 AM |
15015 | +/* #define AuDbgHnotify */ |
15016 | +#ifdef AuDbgHnotify | |
15017 | +static char *au_hfsn_name(u32 mask) | |
15018 | +{ | |
15019 | +#ifdef CONFIG_AUFS_DEBUG | |
c06a8ce3 AM |
15020 | +#define test_ret(flag) \ |
15021 | + do { \ | |
15022 | + if (mask & flag) \ | |
15023 | + return #flag; \ | |
15024 | + } while (0) | |
4a4d8108 AM |
15025 | + test_ret(FS_ACCESS); |
15026 | + test_ret(FS_MODIFY); | |
15027 | + test_ret(FS_ATTRIB); | |
15028 | + test_ret(FS_CLOSE_WRITE); | |
15029 | + test_ret(FS_CLOSE_NOWRITE); | |
15030 | + test_ret(FS_OPEN); | |
15031 | + test_ret(FS_MOVED_FROM); | |
15032 | + test_ret(FS_MOVED_TO); | |
15033 | + test_ret(FS_CREATE); | |
15034 | + test_ret(FS_DELETE); | |
15035 | + test_ret(FS_DELETE_SELF); | |
15036 | + test_ret(FS_MOVE_SELF); | |
15037 | + test_ret(FS_UNMOUNT); | |
15038 | + test_ret(FS_Q_OVERFLOW); | |
15039 | + test_ret(FS_IN_IGNORED); | |
b912730e | 15040 | + test_ret(FS_ISDIR); |
4a4d8108 AM |
15041 | + test_ret(FS_IN_ONESHOT); |
15042 | + test_ret(FS_EVENT_ON_CHILD); | |
15043 | + return ""; | |
15044 | +#undef test_ret | |
15045 | +#else | |
15046 | + return "??"; | |
15047 | +#endif | |
1facf9fc | 15048 | +} |
4a4d8108 | 15049 | +#endif |
1facf9fc | 15050 | + |
15051 | +/* ---------------------------------------------------------------------- */ | |
15052 | + | |
1716fcea AM |
15053 | +static void au_hfsn_free_group(struct fsnotify_group *group) |
15054 | +{ | |
15055 | + struct au_br_hfsnotify *hfsn = group->private; | |
15056 | + | |
5afbbe0d | 15057 | + /* AuDbg("here\n"); */ |
f0c0a007 | 15058 | + au_delayed_kfree(hfsn); |
1716fcea AM |
15059 | +} |
15060 | + | |
4a4d8108 | 15061 | +static int au_hfsn_handle_event(struct fsnotify_group *group, |
fb47a38f | 15062 | + struct inode *inode, |
0c5527e5 AM |
15063 | + struct fsnotify_mark *inode_mark, |
15064 | + struct fsnotify_mark *vfsmount_mark, | |
a2654f78 | 15065 | + u32 mask, const void *data, int data_type, |
fb47a38f | 15066 | + const unsigned char *file_name, u32 cookie) |
1facf9fc | 15067 | +{ |
15068 | + int err; | |
4a4d8108 AM |
15069 | + struct au_hnotify *hnotify; |
15070 | + struct inode *h_dir, *h_inode; | |
fb47a38f | 15071 | + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name)); |
4a4d8108 | 15072 | + |
fb47a38f | 15073 | + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE); |
1facf9fc | 15074 | + |
15075 | + err = 0; | |
0c5527e5 | 15076 | + /* if FS_UNMOUNT happens, there must be another bug */ |
4a4d8108 | 15077 | + AuDebugOn(mask & FS_UNMOUNT); |
0c5527e5 | 15078 | + if (mask & (FS_IN_IGNORED | FS_UNMOUNT)) |
1facf9fc | 15079 | + goto out; |
1facf9fc | 15080 | + |
fb47a38f JR |
15081 | + h_dir = inode; |
15082 | + h_inode = NULL; | |
4a4d8108 | 15083 | +#ifdef AuDbgHnotify |
392086de | 15084 | + au_debug_on(); |
4a4d8108 AM |
15085 | + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1 |
15086 | + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) { | |
15087 | + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n", | |
15088 | + h_dir->i_ino, mask, au_hfsn_name(mask), | |
15089 | + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0); | |
15090 | + /* WARN_ON(1); */ | |
1facf9fc | 15091 | + } |
392086de | 15092 | + au_debug_off(); |
1facf9fc | 15093 | +#endif |
4a4d8108 | 15094 | + |
0c5527e5 AM |
15095 | + AuDebugOn(!inode_mark); |
15096 | + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark); | |
15097 | + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode); | |
1facf9fc | 15098 | + |
4a4d8108 AM |
15099 | +out: |
15100 | + return err; | |
15101 | +} | |
1facf9fc | 15102 | + |
4a4d8108 | 15103 | +static struct fsnotify_ops au_hfsn_ops = { |
1716fcea AM |
15104 | + .handle_event = au_hfsn_handle_event, |
15105 | + .free_group_priv = au_hfsn_free_group | |
4a4d8108 AM |
15106 | +}; |
15107 | + | |
15108 | +/* ---------------------------------------------------------------------- */ | |
15109 | + | |
027c5e7a AM |
15110 | +static void au_hfsn_fin_br(struct au_branch *br) |
15111 | +{ | |
1716fcea | 15112 | + struct au_br_hfsnotify *hfsn; |
027c5e7a | 15113 | + |
1716fcea | 15114 | + hfsn = br->br_hfsn; |
c1595e42 JR |
15115 | + if (hfsn) { |
15116 | + lockdep_off(); | |
1716fcea | 15117 | + fsnotify_put_group(hfsn->hfsn_group); |
c1595e42 JR |
15118 | + lockdep_on(); |
15119 | + } | |
027c5e7a AM |
15120 | +} |
15121 | + | |
1716fcea | 15122 | +static int au_hfsn_init_br(struct au_branch *br, int perm) |
4a4d8108 AM |
15123 | +{ |
15124 | + int err; | |
1716fcea AM |
15125 | + struct fsnotify_group *group; |
15126 | + struct au_br_hfsnotify *hfsn; | |
1facf9fc | 15127 | + |
4a4d8108 | 15128 | + err = 0; |
1716fcea AM |
15129 | + br->br_hfsn = NULL; |
15130 | + if (!au_br_hnotifyable(perm)) | |
027c5e7a | 15131 | + goto out; |
027c5e7a | 15132 | + |
1716fcea AM |
15133 | + err = -ENOMEM; |
15134 | + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS); | |
15135 | + if (unlikely(!hfsn)) | |
027c5e7a AM |
15136 | + goto out; |
15137 | + | |
1716fcea AM |
15138 | + err = 0; |
15139 | + group = fsnotify_alloc_group(&au_hfsn_ops); | |
15140 | + if (IS_ERR(group)) { | |
15141 | + err = PTR_ERR(group); | |
0c5527e5 | 15142 | + pr_err("fsnotify_alloc_group() failed, %d\n", err); |
1716fcea | 15143 | + goto out_hfsn; |
4a4d8108 | 15144 | + } |
1facf9fc | 15145 | + |
1716fcea AM |
15146 | + group->private = hfsn; |
15147 | + hfsn->hfsn_group = group; | |
15148 | + br->br_hfsn = hfsn; | |
15149 | + goto out; /* success */ | |
15150 | + | |
15151 | +out_hfsn: | |
f0c0a007 | 15152 | + au_delayed_kfree(hfsn); |
027c5e7a | 15153 | +out: |
1716fcea AM |
15154 | + return err; |
15155 | +} | |
15156 | + | |
15157 | +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
15158 | +{ | |
15159 | + int err; | |
15160 | + | |
15161 | + err = 0; | |
15162 | + if (!br->br_hfsn) | |
15163 | + err = au_hfsn_init_br(br, perm); | |
15164 | + | |
1facf9fc | 15165 | + return err; |
15166 | +} | |
15167 | + | |
7eafdf33 AM |
15168 | +/* ---------------------------------------------------------------------- */ |
15169 | + | |
15170 | +static void au_hfsn_fin(void) | |
15171 | +{ | |
15172 | + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree)); | |
15173 | + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree)); | |
15174 | +} | |
15175 | + | |
4a4d8108 AM |
15176 | +const struct au_hnotify_op au_hnotify_op = { |
15177 | + .ctl = au_hfsn_ctl, | |
15178 | + .alloc = au_hfsn_alloc, | |
15179 | + .free = au_hfsn_free, | |
1facf9fc | 15180 | + |
7eafdf33 AM |
15181 | + .fin = au_hfsn_fin, |
15182 | + | |
027c5e7a AM |
15183 | + .reset_br = au_hfsn_reset_br, |
15184 | + .fin_br = au_hfsn_fin_br, | |
15185 | + .init_br = au_hfsn_init_br | |
4a4d8108 | 15186 | +}; |
7f207e10 AM |
15187 | diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c |
15188 | --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 15189 | +++ linux/fs/aufs/hfsplus.c 2017-05-06 22:16:52.778220093 +0200 |
523b37e3 | 15190 | @@ -0,0 +1,56 @@ |
4a4d8108 | 15191 | +/* |
a2654f78 | 15192 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
4a4d8108 AM |
15193 | + * |
15194 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15195 | + * it under the terms of the GNU General Public License as published by | |
15196 | + * the Free Software Foundation; either version 2 of the License, or | |
15197 | + * (at your option) any later version. | |
15198 | + * | |
15199 | + * This program is distributed in the hope that it will be useful, | |
15200 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15201 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15202 | + * GNU General Public License for more details. | |
15203 | + * | |
15204 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15205 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 15206 | + */ |
1facf9fc | 15207 | + |
4a4d8108 AM |
15208 | +/* |
15209 | + * special support for filesystems which aqucires an inode mutex | |
15210 | + * at final closing a file, eg, hfsplus. | |
15211 | + * | |
15212 | + * This trick is very simple and stupid, just to open the file before really | |
15213 | + * neceeary open to tell hfsplus that this is not the final closing. | |
15214 | + * The caller should call au_h_open_pre() after acquiring the inode mutex, | |
15215 | + * and au_h_open_post() after releasing it. | |
15216 | + */ | |
1facf9fc | 15217 | + |
4a4d8108 | 15218 | +#include "aufs.h" |
1facf9fc | 15219 | + |
392086de AM |
15220 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
15221 | + int force_wr) | |
4a4d8108 AM |
15222 | +{ |
15223 | + struct file *h_file; | |
15224 | + struct dentry *h_dentry; | |
1facf9fc | 15225 | + |
4a4d8108 AM |
15226 | + h_dentry = au_h_dptr(dentry, bindex); |
15227 | + AuDebugOn(!h_dentry); | |
5527c038 | 15228 | + AuDebugOn(d_is_negative(h_dentry)); |
4a4d8108 AM |
15229 | + |
15230 | + h_file = NULL; | |
15231 | + if (au_test_hfsplus(h_dentry->d_sb) | |
7e9cd9fe | 15232 | + && d_is_reg(h_dentry)) |
4a4d8108 AM |
15233 | + h_file = au_h_open(dentry, bindex, |
15234 | + O_RDONLY | O_NOATIME | O_LARGEFILE, | |
392086de | 15235 | + /*file*/NULL, force_wr); |
4a4d8108 | 15236 | + return h_file; |
1facf9fc | 15237 | +} |
15238 | + | |
4a4d8108 AM |
15239 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
15240 | + struct file *h_file) | |
15241 | +{ | |
15242 | + if (h_file) { | |
15243 | + fput(h_file); | |
15244 | + au_sbr_put(dentry->d_sb, bindex); | |
15245 | + } | |
15246 | +} | |
7f207e10 AM |
15247 | diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c |
15248 | --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 15249 | +++ linux/fs/aufs/hnotify.c 2017-05-06 22:16:52.778220093 +0200 |
f0c0a007 | 15250 | @@ -0,0 +1,723 @@ |
e49829fe | 15251 | +/* |
a2654f78 | 15252 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
e49829fe JR |
15253 | + * |
15254 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15255 | + * it under the terms of the GNU General Public License as published by | |
15256 | + * the Free Software Foundation; either version 2 of the License, or | |
15257 | + * (at your option) any later version. | |
15258 | + * | |
15259 | + * This program is distributed in the hope that it will be useful, | |
15260 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15261 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15262 | + * GNU General Public License for more details. | |
15263 | + * | |
15264 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15265 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
15266 | + */ |
15267 | + | |
15268 | +/* | |
7f207e10 | 15269 | + * abstraction to notify the direct changes on lower directories |
e49829fe JR |
15270 | + */ |
15271 | + | |
15272 | +#include "aufs.h" | |
15273 | + | |
027c5e7a | 15274 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode) |
e49829fe JR |
15275 | +{ |
15276 | + int err; | |
7f207e10 | 15277 | + struct au_hnotify *hn; |
1facf9fc | 15278 | + |
4a4d8108 AM |
15279 | + err = -ENOMEM; |
15280 | + hn = au_cache_alloc_hnotify(); | |
15281 | + if (hn) { | |
15282 | + hn->hn_aufs_inode = inode; | |
027c5e7a AM |
15283 | + hinode->hi_notify = hn; |
15284 | + err = au_hnotify_op.alloc(hinode); | |
15285 | + AuTraceErr(err); | |
15286 | + if (unlikely(err)) { | |
15287 | + hinode->hi_notify = NULL; | |
f0c0a007 | 15288 | + au_cache_dfree_hnotify(hn); |
4a4d8108 AM |
15289 | + /* |
15290 | + * The upper dir was removed by udba, but the same named | |
15291 | + * dir left. In this case, aufs assignes a new inode | |
15292 | + * number and set the monitor again. | |
15293 | + * For the lower dir, the old monitnor is still left. | |
15294 | + */ | |
15295 | + if (err == -EEXIST) | |
15296 | + err = 0; | |
15297 | + } | |
1308ab2a | 15298 | + } |
1308ab2a | 15299 | + |
027c5e7a | 15300 | + AuTraceErr(err); |
1308ab2a | 15301 | + return err; |
dece6358 | 15302 | +} |
1facf9fc | 15303 | + |
4a4d8108 | 15304 | +void au_hn_free(struct au_hinode *hinode) |
dece6358 | 15305 | +{ |
4a4d8108 | 15306 | + struct au_hnotify *hn; |
1facf9fc | 15307 | + |
4a4d8108 AM |
15308 | + hn = hinode->hi_notify; |
15309 | + if (hn) { | |
4a4d8108 | 15310 | + hinode->hi_notify = NULL; |
7eafdf33 | 15311 | + if (au_hnotify_op.free(hinode, hn)) |
f0c0a007 | 15312 | + au_cache_dfree_hnotify(hn); |
4a4d8108 AM |
15313 | + } |
15314 | +} | |
dece6358 | 15315 | + |
4a4d8108 | 15316 | +/* ---------------------------------------------------------------------- */ |
dece6358 | 15317 | + |
4a4d8108 AM |
15318 | +void au_hn_ctl(struct au_hinode *hinode, int do_set) |
15319 | +{ | |
15320 | + if (hinode->hi_notify) | |
15321 | + au_hnotify_op.ctl(hinode, do_set); | |
15322 | +} | |
15323 | + | |
15324 | +void au_hn_reset(struct inode *inode, unsigned int flags) | |
15325 | +{ | |
5afbbe0d | 15326 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
15327 | + struct inode *hi; |
15328 | + struct dentry *iwhdentry; | |
1facf9fc | 15329 | + |
5afbbe0d AM |
15330 | + bbot = au_ibbot(inode); |
15331 | + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) { | |
4a4d8108 AM |
15332 | + hi = au_h_iptr(inode, bindex); |
15333 | + if (!hi) | |
15334 | + continue; | |
1308ab2a | 15335 | + |
febd17d6 | 15336 | + /* inode_lock_nested(hi, AuLsc_I_CHILD); */ |
4a4d8108 AM |
15337 | + iwhdentry = au_hi_wh(inode, bindex); |
15338 | + if (iwhdentry) | |
15339 | + dget(iwhdentry); | |
15340 | + au_igrab(hi); | |
15341 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
15342 | + au_set_h_iptr(inode, bindex, au_igrab(hi), | |
15343 | + flags & ~AuHi_XINO); | |
15344 | + iput(hi); | |
15345 | + dput(iwhdentry); | |
febd17d6 | 15346 | + /* inode_unlock(hi); */ |
1facf9fc | 15347 | + } |
1facf9fc | 15348 | +} |
15349 | + | |
1308ab2a | 15350 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15351 | + |
4a4d8108 | 15352 | +static int hn_xino(struct inode *inode, struct inode *h_inode) |
1facf9fc | 15353 | +{ |
4a4d8108 | 15354 | + int err; |
5afbbe0d | 15355 | + aufs_bindex_t bindex, bbot, bfound, btop; |
4a4d8108 | 15356 | + struct inode *h_i; |
1facf9fc | 15357 | + |
4a4d8108 AM |
15358 | + err = 0; |
15359 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 15360 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
15361 | + goto out; |
15362 | + } | |
1facf9fc | 15363 | + |
4a4d8108 | 15364 | + bfound = -1; |
5afbbe0d AM |
15365 | + bbot = au_ibbot(inode); |
15366 | + btop = au_ibtop(inode); | |
4a4d8108 | 15367 | +#if 0 /* reserved for future use */ |
5afbbe0d | 15368 | + if (bindex == bbot) { |
4a4d8108 AM |
15369 | + /* keep this ino in rename case */ |
15370 | + goto out; | |
15371 | + } | |
15372 | +#endif | |
5afbbe0d | 15373 | + for (bindex = btop; bindex <= bbot; bindex++) |
4a4d8108 AM |
15374 | + if (au_h_iptr(inode, bindex) == h_inode) { |
15375 | + bfound = bindex; | |
15376 | + break; | |
15377 | + } | |
15378 | + if (bfound < 0) | |
1308ab2a | 15379 | + goto out; |
1facf9fc | 15380 | + |
5afbbe0d | 15381 | + for (bindex = btop; bindex <= bbot; bindex++) { |
4a4d8108 AM |
15382 | + h_i = au_h_iptr(inode, bindex); |
15383 | + if (!h_i) | |
15384 | + continue; | |
1facf9fc | 15385 | + |
4a4d8108 AM |
15386 | + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0); |
15387 | + /* ignore this error */ | |
15388 | + /* bad action? */ | |
1facf9fc | 15389 | + } |
1facf9fc | 15390 | + |
4a4d8108 | 15391 | + /* children inode number will be broken */ |
1facf9fc | 15392 | + |
4f0767ce | 15393 | +out: |
4a4d8108 AM |
15394 | + AuTraceErr(err); |
15395 | + return err; | |
1facf9fc | 15396 | +} |
15397 | + | |
4a4d8108 | 15398 | +static int hn_gen_tree(struct dentry *dentry) |
1facf9fc | 15399 | +{ |
4a4d8108 AM |
15400 | + int err, i, j, ndentry; |
15401 | + struct au_dcsub_pages dpages; | |
15402 | + struct au_dpage *dpage; | |
15403 | + struct dentry **dentries; | |
1facf9fc | 15404 | + |
4a4d8108 AM |
15405 | + err = au_dpages_init(&dpages, GFP_NOFS); |
15406 | + if (unlikely(err)) | |
15407 | + goto out; | |
15408 | + err = au_dcsub_pages(&dpages, dentry, NULL, NULL); | |
15409 | + if (unlikely(err)) | |
15410 | + goto out_dpages; | |
1facf9fc | 15411 | + |
4a4d8108 AM |
15412 | + for (i = 0; i < dpages.ndpage; i++) { |
15413 | + dpage = dpages.dpages + i; | |
15414 | + dentries = dpage->dentries; | |
15415 | + ndentry = dpage->ndentry; | |
15416 | + for (j = 0; j < ndentry; j++) { | |
15417 | + struct dentry *d; | |
15418 | + | |
15419 | + d = dentries[j]; | |
15420 | + if (IS_ROOT(d)) | |
15421 | + continue; | |
15422 | + | |
4a4d8108 | 15423 | + au_digen_dec(d); |
5527c038 | 15424 | + if (d_really_is_positive(d)) |
4a4d8108 AM |
15425 | + /* todo: reset children xino? |
15426 | + cached children only? */ | |
5527c038 | 15427 | + au_iigen_dec(d_inode(d)); |
1308ab2a | 15428 | + } |
dece6358 | 15429 | + } |
1facf9fc | 15430 | + |
4f0767ce | 15431 | +out_dpages: |
4a4d8108 | 15432 | + au_dpages_free(&dpages); |
dece6358 | 15433 | + |
027c5e7a | 15434 | +#if 0 |
4a4d8108 AM |
15435 | + /* discard children */ |
15436 | + dentry_unhash(dentry); | |
15437 | + dput(dentry); | |
027c5e7a | 15438 | +#endif |
4f0767ce | 15439 | +out: |
dece6358 AM |
15440 | + return err; |
15441 | +} | |
15442 | + | |
1308ab2a | 15443 | +/* |
4a4d8108 | 15444 | + * return 0 if processed. |
1308ab2a | 15445 | + */ |
4a4d8108 AM |
15446 | +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode, |
15447 | + const unsigned int isdir) | |
dece6358 | 15448 | +{ |
1308ab2a | 15449 | + int err; |
4a4d8108 AM |
15450 | + struct dentry *d; |
15451 | + struct qstr *dname; | |
1facf9fc | 15452 | + |
4a4d8108 AM |
15453 | + err = 1; |
15454 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 15455 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
15456 | + err = 0; |
15457 | + goto out; | |
15458 | + } | |
dece6358 | 15459 | + |
4a4d8108 AM |
15460 | + if (!isdir) { |
15461 | + AuDebugOn(!name); | |
15462 | + au_iigen_dec(inode); | |
027c5e7a | 15463 | + spin_lock(&inode->i_lock); |
c1595e42 | 15464 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 15465 | + spin_lock(&d->d_lock); |
4a4d8108 AM |
15466 | + dname = &d->d_name; |
15467 | + if (dname->len != nlen | |
027c5e7a AM |
15468 | + && memcmp(dname->name, name, nlen)) { |
15469 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 15470 | + continue; |
027c5e7a | 15471 | + } |
4a4d8108 | 15472 | + err = 0; |
4a4d8108 AM |
15473 | + au_digen_dec(d); |
15474 | + spin_unlock(&d->d_lock); | |
15475 | + break; | |
1facf9fc | 15476 | + } |
027c5e7a | 15477 | + spin_unlock(&inode->i_lock); |
1308ab2a | 15478 | + } else { |
027c5e7a | 15479 | + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR); |
c1595e42 | 15480 | + d = d_find_any_alias(inode); |
4a4d8108 AM |
15481 | + if (!d) { |
15482 | + au_iigen_dec(inode); | |
15483 | + goto out; | |
15484 | + } | |
1facf9fc | 15485 | + |
027c5e7a | 15486 | + spin_lock(&d->d_lock); |
4a4d8108 | 15487 | + dname = &d->d_name; |
027c5e7a AM |
15488 | + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) { |
15489 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 15490 | + err = hn_gen_tree(d); |
027c5e7a AM |
15491 | + spin_lock(&d->d_lock); |
15492 | + } | |
15493 | + spin_unlock(&d->d_lock); | |
4a4d8108 AM |
15494 | + dput(d); |
15495 | + } | |
1facf9fc | 15496 | + |
4f0767ce | 15497 | +out: |
4a4d8108 | 15498 | + AuTraceErr(err); |
1308ab2a | 15499 | + return err; |
15500 | +} | |
dece6358 | 15501 | + |
4a4d8108 | 15502 | +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir) |
1facf9fc | 15503 | +{ |
4a4d8108 | 15504 | + int err; |
1facf9fc | 15505 | + |
5527c038 | 15506 | + if (IS_ROOT(dentry)) { |
0c3ec466 | 15507 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
15508 | + return 0; |
15509 | + } | |
1308ab2a | 15510 | + |
4a4d8108 AM |
15511 | + err = 0; |
15512 | + if (!isdir) { | |
4a4d8108 | 15513 | + au_digen_dec(dentry); |
5527c038 JR |
15514 | + if (d_really_is_positive(dentry)) |
15515 | + au_iigen_dec(d_inode(dentry)); | |
4a4d8108 | 15516 | + } else { |
027c5e7a | 15517 | + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR); |
5527c038 | 15518 | + if (d_really_is_positive(dentry)) |
4a4d8108 AM |
15519 | + err = hn_gen_tree(dentry); |
15520 | + } | |
15521 | + | |
15522 | + AuTraceErr(err); | |
15523 | + return err; | |
1facf9fc | 15524 | +} |
15525 | + | |
4a4d8108 | 15526 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15527 | + |
4a4d8108 AM |
15528 | +/* hnotify job flags */ |
15529 | +#define AuHnJob_XINO0 1 | |
15530 | +#define AuHnJob_GEN (1 << 1) | |
15531 | +#define AuHnJob_DIRENT (1 << 2) | |
15532 | +#define AuHnJob_ISDIR (1 << 3) | |
15533 | +#define AuHnJob_TRYXINO0 (1 << 4) | |
15534 | +#define AuHnJob_MNTPNT (1 << 5) | |
15535 | +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name) | |
7f207e10 AM |
15536 | +#define au_fset_hnjob(flags, name) \ |
15537 | + do { (flags) |= AuHnJob_##name; } while (0) | |
15538 | +#define au_fclr_hnjob(flags, name) \ | |
15539 | + do { (flags) &= ~AuHnJob_##name; } while (0) | |
1facf9fc | 15540 | + |
4a4d8108 AM |
15541 | +enum { |
15542 | + AuHn_CHILD, | |
15543 | + AuHn_PARENT, | |
15544 | + AuHnLast | |
15545 | +}; | |
1facf9fc | 15546 | + |
4a4d8108 AM |
15547 | +struct au_hnotify_args { |
15548 | + struct inode *h_dir, *dir, *h_child_inode; | |
15549 | + u32 mask; | |
15550 | + unsigned int flags[AuHnLast]; | |
15551 | + unsigned int h_child_nlen; | |
15552 | + char h_child_name[]; | |
15553 | +}; | |
1facf9fc | 15554 | + |
4a4d8108 AM |
15555 | +struct hn_job_args { |
15556 | + unsigned int flags; | |
15557 | + struct inode *inode, *h_inode, *dir, *h_dir; | |
15558 | + struct dentry *dentry; | |
15559 | + char *h_name; | |
15560 | + int h_nlen; | |
15561 | +}; | |
1308ab2a | 15562 | + |
4a4d8108 AM |
15563 | +static int hn_job(struct hn_job_args *a) |
15564 | +{ | |
15565 | + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR); | |
076b876e | 15566 | + int e; |
1308ab2a | 15567 | + |
4a4d8108 AM |
15568 | + /* reset xino */ |
15569 | + if (au_ftest_hnjob(a->flags, XINO0) && a->inode) | |
15570 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ | |
1308ab2a | 15571 | + |
4a4d8108 AM |
15572 | + if (au_ftest_hnjob(a->flags, TRYXINO0) |
15573 | + && a->inode | |
15574 | + && a->h_inode) { | |
febd17d6 | 15575 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
38d290e6 JR |
15576 | + if (!a->h_inode->i_nlink |
15577 | + && !(a->h_inode->i_state & I_LINKABLE)) | |
4a4d8108 | 15578 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ |
febd17d6 | 15579 | + inode_unlock(a->h_inode); |
1308ab2a | 15580 | + } |
1facf9fc | 15581 | + |
4a4d8108 AM |
15582 | + /* make the generation obsolete */ |
15583 | + if (au_ftest_hnjob(a->flags, GEN)) { | |
076b876e | 15584 | + e = -1; |
4a4d8108 | 15585 | + if (a->inode) |
076b876e | 15586 | + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode, |
4a4d8108 | 15587 | + isdir); |
076b876e | 15588 | + if (e && a->dentry) |
4a4d8108 AM |
15589 | + hn_gen_by_name(a->dentry, isdir); |
15590 | + /* ignore this error */ | |
1facf9fc | 15591 | + } |
1facf9fc | 15592 | + |
4a4d8108 AM |
15593 | + /* make dir entries obsolete */ |
15594 | + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) { | |
15595 | + struct au_vdir *vdir; | |
1facf9fc | 15596 | + |
4a4d8108 AM |
15597 | + vdir = au_ivdir(a->inode); |
15598 | + if (vdir) | |
15599 | + vdir->vd_jiffy = 0; | |
15600 | + /* IMustLock(a->inode); */ | |
15601 | + /* a->inode->i_version++; */ | |
15602 | + } | |
1facf9fc | 15603 | + |
4a4d8108 AM |
15604 | + /* can do nothing but warn */ |
15605 | + if (au_ftest_hnjob(a->flags, MNTPNT) | |
15606 | + && a->dentry | |
15607 | + && d_mountpoint(a->dentry)) | |
523b37e3 | 15608 | + pr_warn("mount-point %pd is removed or renamed\n", a->dentry); |
1facf9fc | 15609 | + |
4a4d8108 | 15610 | + return 0; |
1308ab2a | 15611 | +} |
1facf9fc | 15612 | + |
1308ab2a | 15613 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15614 | + |
4a4d8108 AM |
15615 | +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen, |
15616 | + struct inode *dir) | |
1308ab2a | 15617 | +{ |
4a4d8108 AM |
15618 | + struct dentry *dentry, *d, *parent; |
15619 | + struct qstr *dname; | |
1308ab2a | 15620 | + |
c1595e42 | 15621 | + parent = d_find_any_alias(dir); |
4a4d8108 AM |
15622 | + if (!parent) |
15623 | + return NULL; | |
1308ab2a | 15624 | + |
4a4d8108 | 15625 | + dentry = NULL; |
027c5e7a | 15626 | + spin_lock(&parent->d_lock); |
c1595e42 | 15627 | + list_for_each_entry(d, &parent->d_subdirs, d_child) { |
523b37e3 | 15628 | + /* AuDbg("%pd\n", d); */ |
027c5e7a | 15629 | + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED); |
4a4d8108 AM |
15630 | + dname = &d->d_name; |
15631 | + if (dname->len != nlen || memcmp(dname->name, name, nlen)) | |
027c5e7a AM |
15632 | + goto cont_unlock; |
15633 | + if (au_di(d)) | |
15634 | + au_digen_dec(d); | |
15635 | + else | |
15636 | + goto cont_unlock; | |
c1595e42 | 15637 | + if (au_dcount(d) > 0) { |
027c5e7a | 15638 | + dentry = dget_dlock(d); |
4a4d8108 | 15639 | + spin_unlock(&d->d_lock); |
027c5e7a | 15640 | + break; |
dece6358 | 15641 | + } |
1facf9fc | 15642 | + |
f6b6e03d | 15643 | +cont_unlock: |
027c5e7a | 15644 | + spin_unlock(&d->d_lock); |
1308ab2a | 15645 | + } |
027c5e7a | 15646 | + spin_unlock(&parent->d_lock); |
4a4d8108 | 15647 | + dput(parent); |
1facf9fc | 15648 | + |
4a4d8108 AM |
15649 | + if (dentry) |
15650 | + di_write_lock_child(dentry); | |
1308ab2a | 15651 | + |
4a4d8108 AM |
15652 | + return dentry; |
15653 | +} | |
dece6358 | 15654 | + |
4a4d8108 AM |
15655 | +static struct inode *lookup_wlock_by_ino(struct super_block *sb, |
15656 | + aufs_bindex_t bindex, ino_t h_ino) | |
15657 | +{ | |
15658 | + struct inode *inode; | |
15659 | + ino_t ino; | |
15660 | + int err; | |
15661 | + | |
15662 | + inode = NULL; | |
15663 | + err = au_xino_read(sb, bindex, h_ino, &ino); | |
15664 | + if (!err && ino) | |
15665 | + inode = ilookup(sb, ino); | |
15666 | + if (!inode) | |
15667 | + goto out; | |
15668 | + | |
15669 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 15670 | + pr_warn("wrong root branch\n"); |
4a4d8108 AM |
15671 | + iput(inode); |
15672 | + inode = NULL; | |
15673 | + goto out; | |
1308ab2a | 15674 | + } |
15675 | + | |
4a4d8108 | 15676 | + ii_write_lock_child(inode); |
1308ab2a | 15677 | + |
4f0767ce | 15678 | +out: |
4a4d8108 | 15679 | + return inode; |
dece6358 AM |
15680 | +} |
15681 | + | |
4a4d8108 | 15682 | +static void au_hn_bh(void *_args) |
1facf9fc | 15683 | +{ |
4a4d8108 AM |
15684 | + struct au_hnotify_args *a = _args; |
15685 | + struct super_block *sb; | |
5afbbe0d | 15686 | + aufs_bindex_t bindex, bbot, bfound; |
4a4d8108 | 15687 | + unsigned char xino, try_iput; |
1facf9fc | 15688 | + int err; |
1308ab2a | 15689 | + struct inode *inode; |
4a4d8108 AM |
15690 | + ino_t h_ino; |
15691 | + struct hn_job_args args; | |
15692 | + struct dentry *dentry; | |
15693 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 15694 | + |
4a4d8108 AM |
15695 | + AuDebugOn(!_args); |
15696 | + AuDebugOn(!a->h_dir); | |
15697 | + AuDebugOn(!a->dir); | |
15698 | + AuDebugOn(!a->mask); | |
15699 | + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n", | |
15700 | + a->mask, a->dir->i_ino, a->h_dir->i_ino, | |
15701 | + a->h_child_inode ? a->h_child_inode->i_ino : 0); | |
1facf9fc | 15702 | + |
4a4d8108 AM |
15703 | + inode = NULL; |
15704 | + dentry = NULL; | |
15705 | + /* | |
15706 | + * do not lock a->dir->i_mutex here | |
15707 | + * because of d_revalidate() may cause a deadlock. | |
15708 | + */ | |
15709 | + sb = a->dir->i_sb; | |
15710 | + AuDebugOn(!sb); | |
15711 | + sbinfo = au_sbi(sb); | |
15712 | + AuDebugOn(!sbinfo); | |
7f207e10 | 15713 | + si_write_lock(sb, AuLock_NOPLMW); |
1facf9fc | 15714 | + |
4a4d8108 AM |
15715 | + ii_read_lock_parent(a->dir); |
15716 | + bfound = -1; | |
5afbbe0d AM |
15717 | + bbot = au_ibbot(a->dir); |
15718 | + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++) | |
4a4d8108 AM |
15719 | + if (au_h_iptr(a->dir, bindex) == a->h_dir) { |
15720 | + bfound = bindex; | |
15721 | + break; | |
15722 | + } | |
15723 | + ii_read_unlock(a->dir); | |
15724 | + if (unlikely(bfound < 0)) | |
15725 | + goto out; | |
1facf9fc | 15726 | + |
4a4d8108 AM |
15727 | + xino = !!au_opt_test(au_mntflags(sb), XINO); |
15728 | + h_ino = 0; | |
15729 | + if (a->h_child_inode) | |
15730 | + h_ino = a->h_child_inode->i_ino; | |
1facf9fc | 15731 | + |
4a4d8108 AM |
15732 | + if (a->h_child_nlen |
15733 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN) | |
15734 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT))) | |
15735 | + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen, | |
15736 | + a->dir); | |
15737 | + try_iput = 0; | |
5527c038 JR |
15738 | + if (dentry && d_really_is_positive(dentry)) |
15739 | + inode = d_inode(dentry); | |
4a4d8108 AM |
15740 | + if (xino && !inode && h_ino |
15741 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0) | |
15742 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0) | |
15743 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) { | |
15744 | + inode = lookup_wlock_by_ino(sb, bfound, h_ino); | |
15745 | + try_iput = 1; | |
f0c0a007 | 15746 | + } |
1facf9fc | 15747 | + |
4a4d8108 AM |
15748 | + args.flags = a->flags[AuHn_CHILD]; |
15749 | + args.dentry = dentry; | |
15750 | + args.inode = inode; | |
15751 | + args.h_inode = a->h_child_inode; | |
15752 | + args.dir = a->dir; | |
15753 | + args.h_dir = a->h_dir; | |
15754 | + args.h_name = a->h_child_name; | |
15755 | + args.h_nlen = a->h_child_nlen; | |
15756 | + err = hn_job(&args); | |
15757 | + if (dentry) { | |
027c5e7a | 15758 | + if (au_di(dentry)) |
4a4d8108 AM |
15759 | + di_write_unlock(dentry); |
15760 | + dput(dentry); | |
15761 | + } | |
15762 | + if (inode && try_iput) { | |
15763 | + ii_write_unlock(inode); | |
15764 | + iput(inode); | |
15765 | + } | |
1facf9fc | 15766 | + |
4a4d8108 AM |
15767 | + ii_write_lock_parent(a->dir); |
15768 | + args.flags = a->flags[AuHn_PARENT]; | |
15769 | + args.dentry = NULL; | |
15770 | + args.inode = a->dir; | |
15771 | + args.h_inode = a->h_dir; | |
15772 | + args.dir = NULL; | |
15773 | + args.h_dir = NULL; | |
15774 | + args.h_name = NULL; | |
15775 | + args.h_nlen = 0; | |
15776 | + err = hn_job(&args); | |
15777 | + ii_write_unlock(a->dir); | |
1facf9fc | 15778 | + |
4f0767ce | 15779 | +out: |
4a4d8108 AM |
15780 | + iput(a->h_child_inode); |
15781 | + iput(a->h_dir); | |
15782 | + iput(a->dir); | |
027c5e7a AM |
15783 | + si_write_unlock(sb); |
15784 | + au_nwt_done(&sbinfo->si_nowait); | |
f0c0a007 | 15785 | + au_delayed_kfree(a); |
dece6358 | 15786 | +} |
1facf9fc | 15787 | + |
4a4d8108 AM |
15788 | +/* ---------------------------------------------------------------------- */ |
15789 | + | |
15790 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
15791 | + struct qstr *h_child_qstr, struct inode *h_child_inode) | |
dece6358 | 15792 | +{ |
4a4d8108 | 15793 | + int err, len; |
53392da6 | 15794 | + unsigned int flags[AuHnLast], f; |
4a4d8108 AM |
15795 | + unsigned char isdir, isroot, wh; |
15796 | + struct inode *dir; | |
15797 | + struct au_hnotify_args *args; | |
15798 | + char *p, *h_child_name; | |
dece6358 | 15799 | + |
1308ab2a | 15800 | + err = 0; |
4a4d8108 AM |
15801 | + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode); |
15802 | + dir = igrab(hnotify->hn_aufs_inode); | |
15803 | + if (!dir) | |
15804 | + goto out; | |
1facf9fc | 15805 | + |
4a4d8108 AM |
15806 | + isroot = (dir->i_ino == AUFS_ROOT_INO); |
15807 | + wh = 0; | |
15808 | + h_child_name = (void *)h_child_qstr->name; | |
15809 | + len = h_child_qstr->len; | |
15810 | + if (h_child_name) { | |
15811 | + if (len > AUFS_WH_PFX_LEN | |
15812 | + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
15813 | + h_child_name += AUFS_WH_PFX_LEN; | |
15814 | + len -= AUFS_WH_PFX_LEN; | |
15815 | + wh = 1; | |
15816 | + } | |
1facf9fc | 15817 | + } |
dece6358 | 15818 | + |
4a4d8108 AM |
15819 | + isdir = 0; |
15820 | + if (h_child_inode) | |
15821 | + isdir = !!S_ISDIR(h_child_inode->i_mode); | |
15822 | + flags[AuHn_PARENT] = AuHnJob_ISDIR; | |
15823 | + flags[AuHn_CHILD] = 0; | |
15824 | + if (isdir) | |
15825 | + flags[AuHn_CHILD] = AuHnJob_ISDIR; | |
15826 | + au_fset_hnjob(flags[AuHn_PARENT], DIRENT); | |
15827 | + au_fset_hnjob(flags[AuHn_CHILD], GEN); | |
15828 | + switch (mask & FS_EVENTS_POSS_ON_CHILD) { | |
15829 | + case FS_MOVED_FROM: | |
15830 | + case FS_MOVED_TO: | |
15831 | + au_fset_hnjob(flags[AuHn_CHILD], XINO0); | |
15832 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
15833 | + /*FALLTHROUGH*/ | |
15834 | + case FS_CREATE: | |
fb47a38f | 15835 | + AuDebugOn(!h_child_name); |
4a4d8108 | 15836 | + break; |
1facf9fc | 15837 | + |
4a4d8108 AM |
15838 | + case FS_DELETE: |
15839 | + /* | |
15840 | + * aufs never be able to get this child inode. | |
15841 | + * revalidation should be in d_revalidate() | |
15842 | + * by checking i_nlink, i_generation or d_unhashed(). | |
15843 | + */ | |
15844 | + AuDebugOn(!h_child_name); | |
15845 | + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0); | |
15846 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
15847 | + break; | |
dece6358 | 15848 | + |
4a4d8108 AM |
15849 | + default: |
15850 | + AuDebugOn(1); | |
15851 | + } | |
1308ab2a | 15852 | + |
4a4d8108 AM |
15853 | + if (wh) |
15854 | + h_child_inode = NULL; | |
1308ab2a | 15855 | + |
4a4d8108 AM |
15856 | + err = -ENOMEM; |
15857 | + /* iput() and kfree() will be called in au_hnotify() */ | |
4a4d8108 | 15858 | + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS); |
4a4d8108 AM |
15859 | + if (unlikely(!args)) { |
15860 | + AuErr1("no memory\n"); | |
15861 | + iput(dir); | |
15862 | + goto out; | |
15863 | + } | |
15864 | + args->flags[AuHn_PARENT] = flags[AuHn_PARENT]; | |
15865 | + args->flags[AuHn_CHILD] = flags[AuHn_CHILD]; | |
15866 | + args->mask = mask; | |
15867 | + args->dir = dir; | |
15868 | + args->h_dir = igrab(h_dir); | |
15869 | + if (h_child_inode) | |
15870 | + h_child_inode = igrab(h_child_inode); /* can be NULL */ | |
15871 | + args->h_child_inode = h_child_inode; | |
15872 | + args->h_child_nlen = len; | |
15873 | + if (len) { | |
15874 | + p = (void *)args; | |
15875 | + p += sizeof(*args); | |
15876 | + memcpy(p, h_child_name, len); | |
15877 | + p[len] = 0; | |
1308ab2a | 15878 | + } |
1308ab2a | 15879 | + |
38d290e6 | 15880 | + /* NFS fires the event for silly-renamed one from kworker */ |
53392da6 | 15881 | + f = 0; |
38d290e6 JR |
15882 | + if (!dir->i_nlink |
15883 | + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE))) | |
53392da6 AM |
15884 | + f = AuWkq_NEST; |
15885 | + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f); | |
4a4d8108 AM |
15886 | + if (unlikely(err)) { |
15887 | + pr_err("wkq %d\n", err); | |
15888 | + iput(args->h_child_inode); | |
15889 | + iput(args->h_dir); | |
15890 | + iput(args->dir); | |
f0c0a007 | 15891 | + au_delayed_kfree(args); |
1facf9fc | 15892 | + } |
1facf9fc | 15893 | + |
4a4d8108 | 15894 | +out: |
1facf9fc | 15895 | + return err; |
15896 | +} | |
15897 | + | |
027c5e7a AM |
15898 | +/* ---------------------------------------------------------------------- */ |
15899 | + | |
15900 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
15901 | +{ | |
15902 | + int err; | |
15903 | + | |
15904 | + AuDebugOn(!(udba & AuOptMask_UDBA)); | |
15905 | + | |
15906 | + err = 0; | |
15907 | + if (au_hnotify_op.reset_br) | |
15908 | + err = au_hnotify_op.reset_br(udba, br, perm); | |
15909 | + | |
15910 | + return err; | |
15911 | +} | |
15912 | + | |
15913 | +int au_hnotify_init_br(struct au_branch *br, int perm) | |
15914 | +{ | |
15915 | + int err; | |
15916 | + | |
15917 | + err = 0; | |
15918 | + if (au_hnotify_op.init_br) | |
15919 | + err = au_hnotify_op.init_br(br, perm); | |
15920 | + | |
15921 | + return err; | |
15922 | +} | |
15923 | + | |
15924 | +void au_hnotify_fin_br(struct au_branch *br) | |
15925 | +{ | |
15926 | + if (au_hnotify_op.fin_br) | |
15927 | + au_hnotify_op.fin_br(br); | |
15928 | +} | |
15929 | + | |
4a4d8108 AM |
15930 | +static void au_hn_destroy_cache(void) |
15931 | +{ | |
f0c0a007 AM |
15932 | + struct au_cache *cp; |
15933 | + | |
15934 | + flush_delayed_work(&au_dfree.dwork); | |
15935 | + cp = au_dfree.cache + AuCache_HNOTIFY; | |
15936 | + AuDebugOn(!llist_empty(&cp->llist)); | |
15937 | + kmem_cache_destroy(cp->cache); | |
15938 | + cp->cache = NULL; | |
4a4d8108 | 15939 | +} |
1308ab2a | 15940 | + |
f0c0a007 AM |
15941 | +AU_CACHE_DFREE_FUNC(hnotify, HNOTIFY, hn_lnode); |
15942 | + | |
4a4d8108 | 15943 | +int __init au_hnotify_init(void) |
1facf9fc | 15944 | +{ |
1308ab2a | 15945 | + int err; |
f0c0a007 | 15946 | + struct au_cache *cp; |
1308ab2a | 15947 | + |
4a4d8108 | 15948 | + err = -ENOMEM; |
f0c0a007 AM |
15949 | + cp = au_dfree.cache + AuCache_HNOTIFY; |
15950 | + cp->cache = AuCache(au_hnotify); | |
15951 | + if (cp->cache) { | |
027c5e7a AM |
15952 | + err = 0; |
15953 | + if (au_hnotify_op.init) | |
15954 | + err = au_hnotify_op.init(); | |
4a4d8108 AM |
15955 | + if (unlikely(err)) |
15956 | + au_hn_destroy_cache(); | |
1308ab2a | 15957 | + } |
1308ab2a | 15958 | + AuTraceErr(err); |
4a4d8108 | 15959 | + return err; |
1308ab2a | 15960 | +} |
15961 | + | |
4a4d8108 | 15962 | +void au_hnotify_fin(void) |
1308ab2a | 15963 | +{ |
f0c0a007 AM |
15964 | + struct au_cache *cp; |
15965 | + | |
027c5e7a AM |
15966 | + if (au_hnotify_op.fin) |
15967 | + au_hnotify_op.fin(); | |
f0c0a007 | 15968 | + |
4a4d8108 | 15969 | + /* cf. au_cache_fin() */ |
f0c0a007 AM |
15970 | + cp = au_dfree.cache + AuCache_HNOTIFY; |
15971 | + if (cp->cache) | |
4a4d8108 | 15972 | + au_hn_destroy_cache(); |
dece6358 | 15973 | +} |
7f207e10 AM |
15974 | diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c |
15975 | --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 15976 | +++ linux/fs/aufs/iinfo.c 2017-05-06 22:16:52.778220093 +0200 |
e2f27e51 | 15977 | @@ -0,0 +1,285 @@ |
dece6358 | 15978 | +/* |
a2654f78 | 15979 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
dece6358 AM |
15980 | + * |
15981 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15982 | + * it under the terms of the GNU General Public License as published by | |
15983 | + * the Free Software Foundation; either version 2 of the License, or | |
15984 | + * (at your option) any later version. | |
15985 | + * | |
15986 | + * This program is distributed in the hope that it will be useful, | |
15987 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15988 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15989 | + * GNU General Public License for more details. | |
15990 | + * | |
15991 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15992 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 15993 | + */ |
1facf9fc | 15994 | + |
dece6358 | 15995 | +/* |
4a4d8108 | 15996 | + * inode private data |
dece6358 | 15997 | + */ |
1facf9fc | 15998 | + |
1308ab2a | 15999 | +#include "aufs.h" |
1facf9fc | 16000 | + |
4a4d8108 | 16001 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 16002 | +{ |
4a4d8108 | 16003 | + struct inode *h_inode; |
5afbbe0d | 16004 | + struct au_hinode *hinode; |
1facf9fc | 16005 | + |
4a4d8108 | 16006 | + IiMustAnyLock(inode); |
1facf9fc | 16007 | + |
5afbbe0d AM |
16008 | + hinode = au_hinode(au_ii(inode), bindex); |
16009 | + h_inode = hinode->hi_inode; | |
4a4d8108 AM |
16010 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); |
16011 | + return h_inode; | |
16012 | +} | |
1facf9fc | 16013 | + |
4a4d8108 AM |
16014 | +/* todo: hard/soft set? */ |
16015 | +void au_hiput(struct au_hinode *hinode) | |
16016 | +{ | |
16017 | + au_hn_free(hinode); | |
16018 | + dput(hinode->hi_whdentry); | |
16019 | + iput(hinode->hi_inode); | |
16020 | +} | |
1facf9fc | 16021 | + |
4a4d8108 AM |
16022 | +unsigned int au_hi_flags(struct inode *inode, int isdir) |
16023 | +{ | |
16024 | + unsigned int flags; | |
16025 | + const unsigned int mnt_flags = au_mntflags(inode->i_sb); | |
1facf9fc | 16026 | + |
4a4d8108 AM |
16027 | + flags = 0; |
16028 | + if (au_opt_test(mnt_flags, XINO)) | |
16029 | + au_fset_hi(flags, XINO); | |
16030 | + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY)) | |
16031 | + au_fset_hi(flags, HNOTIFY); | |
16032 | + return flags; | |
1facf9fc | 16033 | +} |
16034 | + | |
4a4d8108 AM |
16035 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
16036 | + struct inode *h_inode, unsigned int flags) | |
1308ab2a | 16037 | +{ |
4a4d8108 AM |
16038 | + struct au_hinode *hinode; |
16039 | + struct inode *hi; | |
16040 | + struct au_iinfo *iinfo = au_ii(inode); | |
1facf9fc | 16041 | + |
4a4d8108 | 16042 | + IiMustWriteLock(inode); |
dece6358 | 16043 | + |
5afbbe0d | 16044 | + hinode = au_hinode(iinfo, bindex); |
4a4d8108 AM |
16045 | + hi = hinode->hi_inode; |
16046 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); | |
16047 | + | |
16048 | + if (hi) | |
16049 | + au_hiput(hinode); | |
16050 | + hinode->hi_inode = h_inode; | |
16051 | + if (h_inode) { | |
16052 | + int err; | |
16053 | + struct super_block *sb = inode->i_sb; | |
16054 | + struct au_branch *br; | |
16055 | + | |
027c5e7a AM |
16056 | + AuDebugOn(inode->i_mode |
16057 | + && (h_inode->i_mode & S_IFMT) | |
16058 | + != (inode->i_mode & S_IFMT)); | |
5afbbe0d | 16059 | + if (bindex == iinfo->ii_btop) |
4a4d8108 AM |
16060 | + au_cpup_igen(inode, h_inode); |
16061 | + br = au_sbr(sb, bindex); | |
16062 | + hinode->hi_id = br->br_id; | |
16063 | + if (au_ftest_hi(flags, XINO)) { | |
16064 | + err = au_xino_write(sb, bindex, h_inode->i_ino, | |
16065 | + inode->i_ino); | |
16066 | + if (unlikely(err)) | |
16067 | + AuIOErr1("failed au_xino_write() %d\n", err); | |
16068 | + } | |
16069 | + | |
16070 | + if (au_ftest_hi(flags, HNOTIFY) | |
16071 | + && au_br_hnotifyable(br->br_perm)) { | |
027c5e7a | 16072 | + err = au_hn_alloc(hinode, inode); |
4a4d8108 AM |
16073 | + if (unlikely(err)) |
16074 | + AuIOErr1("au_hn_alloc() %d\n", err); | |
1308ab2a | 16075 | + } |
16076 | + } | |
4a4d8108 | 16077 | +} |
dece6358 | 16078 | + |
4a4d8108 AM |
16079 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, |
16080 | + struct dentry *h_wh) | |
16081 | +{ | |
16082 | + struct au_hinode *hinode; | |
dece6358 | 16083 | + |
4a4d8108 AM |
16084 | + IiMustWriteLock(inode); |
16085 | + | |
5afbbe0d | 16086 | + hinode = au_hinode(au_ii(inode), bindex); |
4a4d8108 AM |
16087 | + AuDebugOn(hinode->hi_whdentry); |
16088 | + hinode->hi_whdentry = h_wh; | |
1facf9fc | 16089 | +} |
16090 | + | |
537831f9 | 16091 | +void au_update_iigen(struct inode *inode, int half) |
1308ab2a | 16092 | +{ |
537831f9 AM |
16093 | + struct au_iinfo *iinfo; |
16094 | + struct au_iigen *iigen; | |
16095 | + unsigned int sigen; | |
16096 | + | |
16097 | + sigen = au_sigen(inode->i_sb); | |
16098 | + iinfo = au_ii(inode); | |
16099 | + iigen = &iinfo->ii_generation; | |
be52b249 | 16100 | + spin_lock(&iigen->ig_spin); |
537831f9 AM |
16101 | + iigen->ig_generation = sigen; |
16102 | + if (half) | |
16103 | + au_ig_fset(iigen->ig_flags, HALF_REFRESHED); | |
16104 | + else | |
16105 | + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED); | |
be52b249 | 16106 | + spin_unlock(&iigen->ig_spin); |
4a4d8108 | 16107 | +} |
1facf9fc | 16108 | + |
4a4d8108 AM |
16109 | +/* it may be called at remount time, too */ |
16110 | +void au_update_ibrange(struct inode *inode, int do_put_zero) | |
16111 | +{ | |
16112 | + struct au_iinfo *iinfo; | |
5afbbe0d | 16113 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 16114 | + |
5afbbe0d | 16115 | + AuDebugOn(au_is_bad_inode(inode)); |
4a4d8108 | 16116 | + IiMustWriteLock(inode); |
1facf9fc | 16117 | + |
5afbbe0d AM |
16118 | + iinfo = au_ii(inode); |
16119 | + if (do_put_zero && iinfo->ii_btop >= 0) { | |
16120 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; | |
4a4d8108 AM |
16121 | + bindex++) { |
16122 | + struct inode *h_i; | |
1facf9fc | 16123 | + |
5afbbe0d | 16124 | + h_i = au_hinode(iinfo, bindex)->hi_inode; |
38d290e6 JR |
16125 | + if (h_i |
16126 | + && !h_i->i_nlink | |
16127 | + && !(h_i->i_state & I_LINKABLE)) | |
027c5e7a AM |
16128 | + au_set_h_iptr(inode, bindex, NULL, 0); |
16129 | + } | |
4a4d8108 AM |
16130 | + } |
16131 | + | |
5afbbe0d AM |
16132 | + iinfo->ii_btop = -1; |
16133 | + iinfo->ii_bbot = -1; | |
16134 | + bbot = au_sbbot(inode->i_sb); | |
16135 | + for (bindex = 0; bindex <= bbot; bindex++) | |
16136 | + if (au_hinode(iinfo, bindex)->hi_inode) { | |
16137 | + iinfo->ii_btop = bindex; | |
4a4d8108 | 16138 | + break; |
027c5e7a | 16139 | + } |
5afbbe0d AM |
16140 | + if (iinfo->ii_btop >= 0) |
16141 | + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--) | |
16142 | + if (au_hinode(iinfo, bindex)->hi_inode) { | |
16143 | + iinfo->ii_bbot = bindex; | |
027c5e7a AM |
16144 | + break; |
16145 | + } | |
5afbbe0d | 16146 | + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot); |
1308ab2a | 16147 | +} |
1facf9fc | 16148 | + |
dece6358 | 16149 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16150 | + |
4a4d8108 | 16151 | +void au_icntnr_init_once(void *_c) |
dece6358 | 16152 | +{ |
4a4d8108 AM |
16153 | + struct au_icntnr *c = _c; |
16154 | + struct au_iinfo *iinfo = &c->iinfo; | |
1facf9fc | 16155 | + |
be52b249 | 16156 | + spin_lock_init(&iinfo->ii_generation.ig_spin); |
4a4d8108 AM |
16157 | + au_rw_init(&iinfo->ii_rwsem); |
16158 | + inode_init_once(&c->vfs_inode); | |
16159 | +} | |
1facf9fc | 16160 | + |
5afbbe0d AM |
16161 | +void au_hinode_init(struct au_hinode *hinode) |
16162 | +{ | |
16163 | + hinode->hi_inode = NULL; | |
16164 | + hinode->hi_id = -1; | |
16165 | + au_hn_init(hinode); | |
16166 | + hinode->hi_whdentry = NULL; | |
16167 | +} | |
16168 | + | |
4a4d8108 AM |
16169 | +int au_iinfo_init(struct inode *inode) |
16170 | +{ | |
16171 | + struct au_iinfo *iinfo; | |
16172 | + struct super_block *sb; | |
5afbbe0d | 16173 | + struct au_hinode *hi; |
4a4d8108 | 16174 | + int nbr, i; |
1facf9fc | 16175 | + |
4a4d8108 AM |
16176 | + sb = inode->i_sb; |
16177 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
5afbbe0d | 16178 | + nbr = au_sbbot(sb) + 1; |
4a4d8108 AM |
16179 | + if (unlikely(nbr <= 0)) |
16180 | + nbr = 1; | |
5afbbe0d AM |
16181 | + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS); |
16182 | + if (hi) { | |
7f207e10 | 16183 | + au_ninodes_inc(sb); |
5afbbe0d AM |
16184 | + |
16185 | + iinfo->ii_hinode = hi; | |
16186 | + for (i = 0; i < nbr; i++, hi++) | |
16187 | + au_hinode_init(hi); | |
1facf9fc | 16188 | + |
537831f9 | 16189 | + iinfo->ii_generation.ig_generation = au_sigen(sb); |
5afbbe0d AM |
16190 | + iinfo->ii_btop = -1; |
16191 | + iinfo->ii_bbot = -1; | |
4a4d8108 AM |
16192 | + iinfo->ii_vdir = NULL; |
16193 | + return 0; | |
1308ab2a | 16194 | + } |
4a4d8108 AM |
16195 | + return -ENOMEM; |
16196 | +} | |
1facf9fc | 16197 | + |
e2f27e51 | 16198 | +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink) |
4a4d8108 | 16199 | +{ |
5afbbe0d | 16200 | + int err, i; |
4a4d8108 | 16201 | + struct au_hinode *hip; |
1facf9fc | 16202 | + |
4a4d8108 AM |
16203 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
16204 | + | |
16205 | + err = -ENOMEM; | |
e2f27e51 AM |
16206 | + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS, |
16207 | + may_shrink); | |
4a4d8108 AM |
16208 | + if (hip) { |
16209 | + iinfo->ii_hinode = hip; | |
5afbbe0d AM |
16210 | + i = iinfo->ii_bbot + 1; |
16211 | + hip += i; | |
16212 | + for (; i < nbr; i++, hip++) | |
16213 | + au_hinode_init(hip); | |
4a4d8108 | 16214 | + err = 0; |
1308ab2a | 16215 | + } |
4a4d8108 | 16216 | + |
1308ab2a | 16217 | + return err; |
1facf9fc | 16218 | +} |
16219 | + | |
4a4d8108 | 16220 | +void au_iinfo_fin(struct inode *inode) |
1facf9fc | 16221 | +{ |
4a4d8108 AM |
16222 | + struct au_iinfo *iinfo; |
16223 | + struct au_hinode *hi; | |
16224 | + struct super_block *sb; | |
5afbbe0d | 16225 | + aufs_bindex_t bindex, bbot; |
b752ccd1 | 16226 | + const unsigned char unlinked = !inode->i_nlink; |
1308ab2a | 16227 | + |
5afbbe0d | 16228 | + AuDebugOn(au_is_bad_inode(inode)); |
1308ab2a | 16229 | + |
b752ccd1 | 16230 | + sb = inode->i_sb; |
7f207e10 | 16231 | + au_ninodes_dec(sb); |
b752ccd1 AM |
16232 | + if (si_pid_test(sb)) |
16233 | + au_xino_delete_inode(inode, unlinked); | |
16234 | + else { | |
16235 | + /* | |
16236 | + * it is safe to hide the dependency between sbinfo and | |
16237 | + * sb->s_umount. | |
16238 | + */ | |
16239 | + lockdep_off(); | |
16240 | + si_noflush_read_lock(sb); | |
16241 | + au_xino_delete_inode(inode, unlinked); | |
16242 | + si_read_unlock(sb); | |
16243 | + lockdep_on(); | |
16244 | + } | |
16245 | + | |
5afbbe0d | 16246 | + iinfo = au_ii(inode); |
4a4d8108 | 16247 | + if (iinfo->ii_vdir) |
f0c0a007 | 16248 | + au_vdir_free(iinfo->ii_vdir, /*atonce*/0); |
1308ab2a | 16249 | + |
5afbbe0d | 16250 | + bindex = iinfo->ii_btop; |
b752ccd1 | 16251 | + if (bindex >= 0) { |
5afbbe0d AM |
16252 | + hi = au_hinode(iinfo, bindex); |
16253 | + bbot = iinfo->ii_bbot; | |
16254 | + while (bindex++ <= bbot) { | |
b752ccd1 | 16255 | + if (hi->hi_inode) |
4a4d8108 | 16256 | + au_hiput(hi); |
4a4d8108 AM |
16257 | + hi++; |
16258 | + } | |
16259 | + } | |
f0c0a007 | 16260 | + au_delayed_kfree(iinfo->ii_hinode); |
4a4d8108 | 16261 | + AuRwDestroy(&iinfo->ii_rwsem); |
dece6358 | 16262 | +} |
7f207e10 AM |
16263 | diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c |
16264 | --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
16265 | +++ linux/fs/aufs/inode.c 2017-05-06 22:16:52.781553511 +0200 |
16266 | @@ -0,0 +1,527 @@ | |
4a4d8108 | 16267 | +/* |
a2654f78 | 16268 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
16269 | + * |
16270 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16271 | + * it under the terms of the GNU General Public License as published by | |
16272 | + * the Free Software Foundation; either version 2 of the License, or | |
16273 | + * (at your option) any later version. | |
16274 | + * | |
16275 | + * This program is distributed in the hope that it will be useful, | |
16276 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16277 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16278 | + * GNU General Public License for more details. | |
16279 | + * | |
16280 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16281 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 16282 | + */ |
1facf9fc | 16283 | + |
4a4d8108 AM |
16284 | +/* |
16285 | + * inode functions | |
16286 | + */ | |
1facf9fc | 16287 | + |
4a4d8108 | 16288 | +#include "aufs.h" |
1308ab2a | 16289 | + |
4a4d8108 AM |
16290 | +struct inode *au_igrab(struct inode *inode) |
16291 | +{ | |
16292 | + if (inode) { | |
16293 | + AuDebugOn(!atomic_read(&inode->i_count)); | |
027c5e7a | 16294 | + ihold(inode); |
1facf9fc | 16295 | + } |
4a4d8108 AM |
16296 | + return inode; |
16297 | +} | |
1facf9fc | 16298 | + |
4a4d8108 AM |
16299 | +static void au_refresh_hinode_attr(struct inode *inode, int do_version) |
16300 | +{ | |
16301 | + au_cpup_attr_all(inode, /*force*/0); | |
537831f9 | 16302 | + au_update_iigen(inode, /*half*/1); |
4a4d8108 AM |
16303 | + if (do_version) |
16304 | + inode->i_version++; | |
dece6358 | 16305 | +} |
1facf9fc | 16306 | + |
027c5e7a | 16307 | +static int au_ii_refresh(struct inode *inode, int *update) |
dece6358 | 16308 | +{ |
e2f27e51 | 16309 | + int err, e, nbr; |
027c5e7a | 16310 | + umode_t type; |
4a4d8108 | 16311 | + aufs_bindex_t bindex, new_bindex; |
1308ab2a | 16312 | + struct super_block *sb; |
4a4d8108 | 16313 | + struct au_iinfo *iinfo; |
027c5e7a | 16314 | + struct au_hinode *p, *q, tmp; |
1facf9fc | 16315 | + |
5afbbe0d | 16316 | + AuDebugOn(au_is_bad_inode(inode)); |
4a4d8108 | 16317 | + IiMustWriteLock(inode); |
1facf9fc | 16318 | + |
027c5e7a | 16319 | + *update = 0; |
4a4d8108 | 16320 | + sb = inode->i_sb; |
e2f27e51 | 16321 | + nbr = au_sbbot(sb) + 1; |
027c5e7a | 16322 | + type = inode->i_mode & S_IFMT; |
4a4d8108 | 16323 | + iinfo = au_ii(inode); |
e2f27e51 | 16324 | + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0); |
4a4d8108 | 16325 | + if (unlikely(err)) |
1308ab2a | 16326 | + goto out; |
1facf9fc | 16327 | + |
5afbbe0d AM |
16328 | + AuDebugOn(iinfo->ii_btop < 0); |
16329 | + p = au_hinode(iinfo, iinfo->ii_btop); | |
16330 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; | |
4a4d8108 AM |
16331 | + bindex++, p++) { |
16332 | + if (!p->hi_inode) | |
16333 | + continue; | |
1facf9fc | 16334 | + |
027c5e7a | 16335 | + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT)); |
4a4d8108 AM |
16336 | + new_bindex = au_br_index(sb, p->hi_id); |
16337 | + if (new_bindex == bindex) | |
16338 | + continue; | |
1facf9fc | 16339 | + |
4a4d8108 | 16340 | + if (new_bindex < 0) { |
027c5e7a | 16341 | + *update = 1; |
4a4d8108 AM |
16342 | + au_hiput(p); |
16343 | + p->hi_inode = NULL; | |
16344 | + continue; | |
1308ab2a | 16345 | + } |
4a4d8108 | 16346 | + |
5afbbe0d AM |
16347 | + if (new_bindex < iinfo->ii_btop) |
16348 | + iinfo->ii_btop = new_bindex; | |
16349 | + if (iinfo->ii_bbot < new_bindex) | |
16350 | + iinfo->ii_bbot = new_bindex; | |
4a4d8108 | 16351 | + /* swap two lower inode, and loop again */ |
5afbbe0d | 16352 | + q = au_hinode(iinfo, new_bindex); |
4a4d8108 AM |
16353 | + tmp = *q; |
16354 | + *q = *p; | |
16355 | + *p = tmp; | |
16356 | + if (tmp.hi_inode) { | |
16357 | + bindex--; | |
16358 | + p--; | |
1308ab2a | 16359 | + } |
16360 | + } | |
4a4d8108 | 16361 | + au_update_ibrange(inode, /*do_put_zero*/0); |
e2f27e51 | 16362 | + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */ |
4a4d8108 AM |
16363 | + e = au_dy_irefresh(inode); |
16364 | + if (unlikely(e && !err)) | |
16365 | + err = e; | |
1facf9fc | 16366 | + |
4f0767ce | 16367 | +out: |
027c5e7a AM |
16368 | + AuTraceErr(err); |
16369 | + return err; | |
16370 | +} | |
16371 | + | |
b95c5147 AM |
16372 | +void au_refresh_iop(struct inode *inode, int force_getattr) |
16373 | +{ | |
16374 | + int type; | |
16375 | + struct au_sbinfo *sbi = au_sbi(inode->i_sb); | |
16376 | + const struct inode_operations *iop | |
16377 | + = force_getattr ? aufs_iop : sbi->si_iop_array; | |
16378 | + | |
16379 | + if (inode->i_op == iop) | |
16380 | + return; | |
16381 | + | |
16382 | + switch (inode->i_mode & S_IFMT) { | |
16383 | + case S_IFDIR: | |
16384 | + type = AuIop_DIR; | |
16385 | + break; | |
16386 | + case S_IFLNK: | |
16387 | + type = AuIop_SYMLINK; | |
16388 | + break; | |
16389 | + default: | |
16390 | + type = AuIop_OTHER; | |
16391 | + break; | |
16392 | + } | |
16393 | + | |
16394 | + inode->i_op = iop + type; | |
16395 | + /* unnecessary smp_wmb() */ | |
16396 | +} | |
16397 | + | |
027c5e7a AM |
16398 | +int au_refresh_hinode_self(struct inode *inode) |
16399 | +{ | |
16400 | + int err, update; | |
16401 | + | |
16402 | + err = au_ii_refresh(inode, &update); | |
16403 | + if (!err) | |
16404 | + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode)); | |
16405 | + | |
16406 | + AuTraceErr(err); | |
4a4d8108 AM |
16407 | + return err; |
16408 | +} | |
1facf9fc | 16409 | + |
4a4d8108 AM |
16410 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry) |
16411 | +{ | |
027c5e7a | 16412 | + int err, e, update; |
4a4d8108 | 16413 | + unsigned int flags; |
027c5e7a | 16414 | + umode_t mode; |
5afbbe0d | 16415 | + aufs_bindex_t bindex, bbot; |
027c5e7a | 16416 | + unsigned char isdir; |
4a4d8108 AM |
16417 | + struct au_hinode *p; |
16418 | + struct au_iinfo *iinfo; | |
1facf9fc | 16419 | + |
027c5e7a | 16420 | + err = au_ii_refresh(inode, &update); |
4a4d8108 AM |
16421 | + if (unlikely(err)) |
16422 | + goto out; | |
16423 | + | |
16424 | + update = 0; | |
16425 | + iinfo = au_ii(inode); | |
5afbbe0d | 16426 | + p = au_hinode(iinfo, iinfo->ii_btop); |
027c5e7a AM |
16427 | + mode = (inode->i_mode & S_IFMT); |
16428 | + isdir = S_ISDIR(mode); | |
4a4d8108 | 16429 | + flags = au_hi_flags(inode, isdir); |
5afbbe0d AM |
16430 | + bbot = au_dbbot(dentry); |
16431 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) { | |
5527c038 | 16432 | + struct inode *h_i, *h_inode; |
4a4d8108 AM |
16433 | + struct dentry *h_d; |
16434 | + | |
16435 | + h_d = au_h_dptr(dentry, bindex); | |
5527c038 | 16436 | + if (!h_d || d_is_negative(h_d)) |
4a4d8108 AM |
16437 | + continue; |
16438 | + | |
5527c038 JR |
16439 | + h_inode = d_inode(h_d); |
16440 | + AuDebugOn(mode != (h_inode->i_mode & S_IFMT)); | |
5afbbe0d | 16441 | + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) { |
4a4d8108 AM |
16442 | + h_i = au_h_iptr(inode, bindex); |
16443 | + if (h_i) { | |
5527c038 | 16444 | + if (h_i == h_inode) |
4a4d8108 AM |
16445 | + continue; |
16446 | + err = -EIO; | |
16447 | + break; | |
16448 | + } | |
16449 | + } | |
5afbbe0d AM |
16450 | + if (bindex < iinfo->ii_btop) |
16451 | + iinfo->ii_btop = bindex; | |
16452 | + if (iinfo->ii_bbot < bindex) | |
16453 | + iinfo->ii_bbot = bindex; | |
5527c038 | 16454 | + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags); |
4a4d8108 | 16455 | + update = 1; |
1308ab2a | 16456 | + } |
4a4d8108 AM |
16457 | + au_update_ibrange(inode, /*do_put_zero*/0); |
16458 | + e = au_dy_irefresh(inode); | |
16459 | + if (unlikely(e && !err)) | |
16460 | + err = e; | |
027c5e7a AM |
16461 | + if (!err) |
16462 | + au_refresh_hinode_attr(inode, update && isdir); | |
4a4d8108 | 16463 | + |
4f0767ce | 16464 | +out: |
4a4d8108 | 16465 | + AuTraceErr(err); |
1308ab2a | 16466 | + return err; |
dece6358 AM |
16467 | +} |
16468 | + | |
4a4d8108 | 16469 | +static int set_inode(struct inode *inode, struct dentry *dentry) |
dece6358 | 16470 | +{ |
4a4d8108 AM |
16471 | + int err; |
16472 | + unsigned int flags; | |
16473 | + umode_t mode; | |
5afbbe0d | 16474 | + aufs_bindex_t bindex, btop, btail; |
4a4d8108 AM |
16475 | + unsigned char isdir; |
16476 | + struct dentry *h_dentry; | |
16477 | + struct inode *h_inode; | |
16478 | + struct au_iinfo *iinfo; | |
b95c5147 | 16479 | + struct inode_operations *iop; |
dece6358 | 16480 | + |
4a4d8108 | 16481 | + IiMustWriteLock(inode); |
dece6358 | 16482 | + |
4a4d8108 AM |
16483 | + err = 0; |
16484 | + isdir = 0; | |
b95c5147 | 16485 | + iop = au_sbi(inode->i_sb)->si_iop_array; |
5afbbe0d AM |
16486 | + btop = au_dbtop(dentry); |
16487 | + h_dentry = au_h_dptr(dentry, btop); | |
5527c038 | 16488 | + h_inode = d_inode(h_dentry); |
4a4d8108 AM |
16489 | + mode = h_inode->i_mode; |
16490 | + switch (mode & S_IFMT) { | |
16491 | + case S_IFREG: | |
16492 | + btail = au_dbtail(dentry); | |
b95c5147 | 16493 | + inode->i_op = iop + AuIop_OTHER; |
4a4d8108 | 16494 | + inode->i_fop = &aufs_file_fop; |
5afbbe0d | 16495 | + err = au_dy_iaop(inode, btop, h_inode); |
4a4d8108 AM |
16496 | + if (unlikely(err)) |
16497 | + goto out; | |
16498 | + break; | |
16499 | + case S_IFDIR: | |
16500 | + isdir = 1; | |
16501 | + btail = au_dbtaildir(dentry); | |
b95c5147 | 16502 | + inode->i_op = iop + AuIop_DIR; |
4a4d8108 AM |
16503 | + inode->i_fop = &aufs_dir_fop; |
16504 | + break; | |
16505 | + case S_IFLNK: | |
16506 | + btail = au_dbtail(dentry); | |
b95c5147 | 16507 | + inode->i_op = iop + AuIop_SYMLINK; |
4a4d8108 AM |
16508 | + break; |
16509 | + case S_IFBLK: | |
16510 | + case S_IFCHR: | |
16511 | + case S_IFIFO: | |
16512 | + case S_IFSOCK: | |
16513 | + btail = au_dbtail(dentry); | |
b95c5147 | 16514 | + inode->i_op = iop + AuIop_OTHER; |
38d290e6 | 16515 | + init_special_inode(inode, mode, h_inode->i_rdev); |
4a4d8108 AM |
16516 | + break; |
16517 | + default: | |
16518 | + AuIOErr("Unknown file type 0%o\n", mode); | |
16519 | + err = -EIO; | |
1308ab2a | 16520 | + goto out; |
4a4d8108 | 16521 | + } |
dece6358 | 16522 | + |
4a4d8108 AM |
16523 | + /* do not set hnotify for whiteouted dirs (SHWH mode) */ |
16524 | + flags = au_hi_flags(inode, isdir); | |
16525 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH) | |
16526 | + && au_ftest_hi(flags, HNOTIFY) | |
16527 | + && dentry->d_name.len > AUFS_WH_PFX_LEN | |
16528 | + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) | |
16529 | + au_fclr_hi(flags, HNOTIFY); | |
16530 | + iinfo = au_ii(inode); | |
5afbbe0d AM |
16531 | + iinfo->ii_btop = btop; |
16532 | + iinfo->ii_bbot = btail; | |
16533 | + for (bindex = btop; bindex <= btail; bindex++) { | |
4a4d8108 AM |
16534 | + h_dentry = au_h_dptr(dentry, bindex); |
16535 | + if (h_dentry) | |
16536 | + au_set_h_iptr(inode, bindex, | |
5527c038 | 16537 | + au_igrab(d_inode(h_dentry)), flags); |
4a4d8108 AM |
16538 | + } |
16539 | + au_cpup_attr_all(inode, /*force*/1); | |
c1595e42 JR |
16540 | + /* |
16541 | + * to force calling aufs_get_acl() every time, | |
16542 | + * do not call cache_no_acl() for aufs inode. | |
16543 | + */ | |
dece6358 | 16544 | + |
4f0767ce | 16545 | +out: |
4a4d8108 AM |
16546 | + return err; |
16547 | +} | |
dece6358 | 16548 | + |
027c5e7a AM |
16549 | +/* |
16550 | + * successful returns with iinfo write_locked | |
16551 | + * minus: errno | |
16552 | + * zero: success, matched | |
16553 | + * plus: no error, but unmatched | |
16554 | + */ | |
16555 | +static int reval_inode(struct inode *inode, struct dentry *dentry) | |
4a4d8108 AM |
16556 | +{ |
16557 | + int err; | |
cfc41e69 | 16558 | + unsigned int gen, igflags; |
5afbbe0d | 16559 | + aufs_bindex_t bindex, bbot; |
4a4d8108 | 16560 | + struct inode *h_inode, *h_dinode; |
5527c038 | 16561 | + struct dentry *h_dentry; |
dece6358 | 16562 | + |
4a4d8108 AM |
16563 | + /* |
16564 | + * before this function, if aufs got any iinfo lock, it must be only | |
16565 | + * one, the parent dir. | |
16566 | + * it can happen by UDBA and the obsoleted inode number. | |
16567 | + */ | |
16568 | + err = -EIO; | |
16569 | + if (unlikely(inode->i_ino == parent_ino(dentry))) | |
16570 | + goto out; | |
16571 | + | |
027c5e7a | 16572 | + err = 1; |
4a4d8108 | 16573 | + ii_write_lock_new_child(inode); |
5afbbe0d | 16574 | + h_dentry = au_h_dptr(dentry, au_dbtop(dentry)); |
5527c038 | 16575 | + h_dinode = d_inode(h_dentry); |
5afbbe0d AM |
16576 | + bbot = au_ibbot(inode); |
16577 | + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) { | |
4a4d8108 | 16578 | + h_inode = au_h_iptr(inode, bindex); |
537831f9 AM |
16579 | + if (!h_inode || h_inode != h_dinode) |
16580 | + continue; | |
16581 | + | |
16582 | + err = 0; | |
cfc41e69 | 16583 | + gen = au_iigen(inode, &igflags); |
537831f9 | 16584 | + if (gen == au_digen(dentry) |
cfc41e69 | 16585 | + && !au_ig_ftest(igflags, HALF_REFRESHED)) |
4a4d8108 | 16586 | + break; |
537831f9 AM |
16587 | + |
16588 | + /* fully refresh inode using dentry */ | |
16589 | + err = au_refresh_hinode(inode, dentry); | |
16590 | + if (!err) | |
16591 | + au_update_iigen(inode, /*half*/0); | |
16592 | + break; | |
1facf9fc | 16593 | + } |
dece6358 | 16594 | + |
4a4d8108 AM |
16595 | + if (unlikely(err)) |
16596 | + ii_write_unlock(inode); | |
4f0767ce | 16597 | +out: |
1facf9fc | 16598 | + return err; |
16599 | +} | |
1facf9fc | 16600 | + |
4a4d8108 AM |
16601 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
16602 | + unsigned int d_type, ino_t *ino) | |
1facf9fc | 16603 | +{ |
521ced18 JR |
16604 | + int err, idx; |
16605 | + const int isnondir = d_type != DT_DIR; | |
1facf9fc | 16606 | + |
b752ccd1 | 16607 | + /* prevent hardlinked inode number from race condition */ |
521ced18 JR |
16608 | + if (isnondir) { |
16609 | + err = au_xinondir_enter(sb, bindex, h_ino, &idx); | |
16610 | + if (unlikely(err)) | |
16611 | + goto out; | |
4a4d8108 | 16612 | + } |
521ced18 | 16613 | + |
4a4d8108 AM |
16614 | + err = au_xino_read(sb, bindex, h_ino, ino); |
16615 | + if (unlikely(err)) | |
521ced18 | 16616 | + goto out_xinondir; |
1308ab2a | 16617 | + |
4a4d8108 AM |
16618 | + if (!*ino) { |
16619 | + err = -EIO; | |
16620 | + *ino = au_xino_new_ino(sb); | |
16621 | + if (unlikely(!*ino)) | |
521ced18 | 16622 | + goto out_xinondir; |
4a4d8108 AM |
16623 | + err = au_xino_write(sb, bindex, h_ino, *ino); |
16624 | + if (unlikely(err)) | |
521ced18 | 16625 | + goto out_xinondir; |
1308ab2a | 16626 | + } |
1facf9fc | 16627 | + |
521ced18 JR |
16628 | +out_xinondir: |
16629 | + if (isnondir && idx >= 0) | |
16630 | + au_xinondir_leave(sb, bindex, h_ino, idx); | |
4f0767ce | 16631 | +out: |
1facf9fc | 16632 | + return err; |
16633 | +} | |
16634 | + | |
4a4d8108 AM |
16635 | +/* successful returns with iinfo write_locked */ |
16636 | +/* todo: return with unlocked? */ | |
16637 | +struct inode *au_new_inode(struct dentry *dentry, int must_new) | |
1facf9fc | 16638 | +{ |
5527c038 | 16639 | + struct inode *inode, *h_inode; |
4a4d8108 AM |
16640 | + struct dentry *h_dentry; |
16641 | + struct super_block *sb; | |
16642 | + ino_t h_ino, ino; | |
521ced18 | 16643 | + int err, idx, hlinked; |
5afbbe0d | 16644 | + aufs_bindex_t btop; |
1facf9fc | 16645 | + |
4a4d8108 | 16646 | + sb = dentry->d_sb; |
5afbbe0d AM |
16647 | + btop = au_dbtop(dentry); |
16648 | + h_dentry = au_h_dptr(dentry, btop); | |
5527c038 JR |
16649 | + h_inode = d_inode(h_dentry); |
16650 | + h_ino = h_inode->i_ino; | |
521ced18 | 16651 | + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1; |
b752ccd1 | 16652 | + |
521ced18 | 16653 | +new_ino: |
b752ccd1 AM |
16654 | + /* |
16655 | + * stop 'race'-ing between hardlinks under different | |
16656 | + * parents. | |
16657 | + */ | |
521ced18 JR |
16658 | + if (hlinked) { |
16659 | + err = au_xinondir_enter(sb, btop, h_ino, &idx); | |
16660 | + inode = ERR_PTR(err); | |
16661 | + if (unlikely(err)) | |
16662 | + goto out; | |
16663 | + } | |
b752ccd1 | 16664 | + |
5afbbe0d | 16665 | + err = au_xino_read(sb, btop, h_ino, &ino); |
4a4d8108 AM |
16666 | + inode = ERR_PTR(err); |
16667 | + if (unlikely(err)) | |
521ced18 | 16668 | + goto out_xinondir; |
b752ccd1 | 16669 | + |
4a4d8108 AM |
16670 | + if (!ino) { |
16671 | + ino = au_xino_new_ino(sb); | |
16672 | + if (unlikely(!ino)) { | |
16673 | + inode = ERR_PTR(-EIO); | |
521ced18 | 16674 | + goto out_xinondir; |
dece6358 AM |
16675 | + } |
16676 | + } | |
1facf9fc | 16677 | + |
4a4d8108 AM |
16678 | + AuDbg("i%lu\n", (unsigned long)ino); |
16679 | + inode = au_iget_locked(sb, ino); | |
16680 | + err = PTR_ERR(inode); | |
16681 | + if (IS_ERR(inode)) | |
521ced18 | 16682 | + goto out_xinondir; |
1facf9fc | 16683 | + |
4a4d8108 AM |
16684 | + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW)); |
16685 | + if (inode->i_state & I_NEW) { | |
16686 | + ii_write_lock_new_child(inode); | |
16687 | + err = set_inode(inode, dentry); | |
16688 | + if (!err) { | |
16689 | + unlock_new_inode(inode); | |
521ced18 | 16690 | + goto out_xinondir; /* success */ |
4a4d8108 | 16691 | + } |
1308ab2a | 16692 | + |
027c5e7a AM |
16693 | + /* |
16694 | + * iget_failed() calls iput(), but we need to call | |
16695 | + * ii_write_unlock() after iget_failed(). so dirty hack for | |
16696 | + * i_count. | |
16697 | + */ | |
16698 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 16699 | + iget_failed(inode); |
027c5e7a | 16700 | + ii_write_unlock(inode); |
5afbbe0d | 16701 | + au_xino_write(sb, btop, h_ino, /*ino*/0); |
027c5e7a AM |
16702 | + /* ignore this error */ |
16703 | + goto out_iput; | |
16704 | + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) { | |
b752ccd1 AM |
16705 | + /* |
16706 | + * horrible race condition between lookup, readdir and copyup | |
16707 | + * (or something). | |
16708 | + */ | |
521ced18 JR |
16709 | + if (hlinked && idx >= 0) |
16710 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
027c5e7a AM |
16711 | + err = reval_inode(inode, dentry); |
16712 | + if (unlikely(err < 0)) { | |
521ced18 | 16713 | + hlinked = 0; |
027c5e7a AM |
16714 | + goto out_iput; |
16715 | + } | |
521ced18 | 16716 | + if (!err) |
4a4d8108 | 16717 | + goto out; /* success */ |
521ced18 JR |
16718 | + else if (hlinked && idx >= 0) { |
16719 | + err = au_xinondir_enter(sb, btop, h_ino, &idx); | |
16720 | + if (unlikely(err)) { | |
16721 | + iput(inode); | |
16722 | + inode = ERR_PTR(err); | |
16723 | + goto out; | |
16724 | + } | |
16725 | + } | |
4a4d8108 AM |
16726 | + } |
16727 | + | |
5527c038 | 16728 | + if (unlikely(au_test_fs_unique_ino(h_inode))) |
4a4d8108 | 16729 | + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir," |
523b37e3 | 16730 | + " b%d, %s, %pd, hi%lu, i%lu.\n", |
5afbbe0d | 16731 | + btop, au_sbtype(h_dentry->d_sb), dentry, |
4a4d8108 AM |
16732 | + (unsigned long)h_ino, (unsigned long)ino); |
16733 | + ino = 0; | |
5afbbe0d | 16734 | + err = au_xino_write(sb, btop, h_ino, /*ino*/0); |
4a4d8108 AM |
16735 | + if (!err) { |
16736 | + iput(inode); | |
521ced18 JR |
16737 | + if (hlinked && idx >= 0) |
16738 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
4a4d8108 AM |
16739 | + goto new_ino; |
16740 | + } | |
1308ab2a | 16741 | + |
4f0767ce | 16742 | +out_iput: |
4a4d8108 | 16743 | + iput(inode); |
4a4d8108 | 16744 | + inode = ERR_PTR(err); |
521ced18 JR |
16745 | +out_xinondir: |
16746 | + if (hlinked && idx >= 0) | |
16747 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
4f0767ce | 16748 | +out: |
4a4d8108 | 16749 | + return inode; |
1facf9fc | 16750 | +} |
16751 | + | |
4a4d8108 | 16752 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16753 | + |
4a4d8108 AM |
16754 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, |
16755 | + struct inode *inode) | |
16756 | +{ | |
16757 | + int err; | |
076b876e | 16758 | + struct inode *hi; |
1facf9fc | 16759 | + |
4a4d8108 | 16760 | + err = au_br_rdonly(au_sbr(sb, bindex)); |
1facf9fc | 16761 | + |
4a4d8108 AM |
16762 | + /* pseudo-link after flushed may happen out of bounds */ |
16763 | + if (!err | |
16764 | + && inode | |
5afbbe0d AM |
16765 | + && au_ibtop(inode) <= bindex |
16766 | + && bindex <= au_ibbot(inode)) { | |
4a4d8108 AM |
16767 | + /* |
16768 | + * permission check is unnecessary since vfsub routine | |
16769 | + * will be called later | |
16770 | + */ | |
076b876e | 16771 | + hi = au_h_iptr(inode, bindex); |
4a4d8108 AM |
16772 | + if (hi) |
16773 | + err = IS_IMMUTABLE(hi) ? -EROFS : 0; | |
1facf9fc | 16774 | + } |
16775 | + | |
4a4d8108 AM |
16776 | + return err; |
16777 | +} | |
dece6358 | 16778 | + |
4a4d8108 AM |
16779 | +int au_test_h_perm(struct inode *h_inode, int mask) |
16780 | +{ | |
2dfbb274 | 16781 | + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) |
4a4d8108 AM |
16782 | + return 0; |
16783 | + return inode_permission(h_inode, mask); | |
16784 | +} | |
1facf9fc | 16785 | + |
4a4d8108 AM |
16786 | +int au_test_h_perm_sio(struct inode *h_inode, int mask) |
16787 | +{ | |
16788 | + if (au_test_nfs(h_inode->i_sb) | |
16789 | + && (mask & MAY_WRITE) | |
16790 | + && S_ISDIR(h_inode->i_mode)) | |
16791 | + mask |= MAY_READ; /* force permission check */ | |
16792 | + return au_test_h_perm(h_inode, mask); | |
1facf9fc | 16793 | +} |
7f207e10 AM |
16794 | diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h |
16795 | --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 16796 | +++ linux/fs/aufs/inode.h 2017-05-06 22:16:52.781553511 +0200 |
a2654f78 | 16797 | @@ -0,0 +1,692 @@ |
4a4d8108 | 16798 | +/* |
a2654f78 | 16799 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
16800 | + * |
16801 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16802 | + * it under the terms of the GNU General Public License as published by | |
16803 | + * the Free Software Foundation; either version 2 of the License, or | |
16804 | + * (at your option) any later version. | |
16805 | + * | |
16806 | + * This program is distributed in the hope that it will be useful, | |
16807 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16808 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16809 | + * GNU General Public License for more details. | |
16810 | + * | |
16811 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16812 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 16813 | + */ |
1facf9fc | 16814 | + |
1308ab2a | 16815 | +/* |
4a4d8108 | 16816 | + * inode operations |
1308ab2a | 16817 | + */ |
dece6358 | 16818 | + |
4a4d8108 AM |
16819 | +#ifndef __AUFS_INODE_H__ |
16820 | +#define __AUFS_INODE_H__ | |
dece6358 | 16821 | + |
4a4d8108 | 16822 | +#ifdef __KERNEL__ |
1308ab2a | 16823 | + |
4a4d8108 | 16824 | +#include <linux/fsnotify.h> |
4a4d8108 | 16825 | +#include "rwsem.h" |
1308ab2a | 16826 | + |
4a4d8108 | 16827 | +struct vfsmount; |
1facf9fc | 16828 | + |
4a4d8108 AM |
16829 | +struct au_hnotify { |
16830 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16831 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
7f207e10 | 16832 | + /* never use fsnotify_add_vfsmount_mark() */ |
0c5527e5 | 16833 | + struct fsnotify_mark hn_mark; |
4a4d8108 | 16834 | +#endif |
f0c0a007 AM |
16835 | + union { |
16836 | + struct inode *hn_aufs_inode; /* no get/put */ | |
16837 | + struct llist_node hn_lnode; /* delayed free */ | |
16838 | + }; | |
4a4d8108 AM |
16839 | +#endif |
16840 | +} ____cacheline_aligned_in_smp; | |
1facf9fc | 16841 | + |
4a4d8108 AM |
16842 | +struct au_hinode { |
16843 | + struct inode *hi_inode; | |
16844 | + aufs_bindex_t hi_id; | |
16845 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16846 | + struct au_hnotify *hi_notify; | |
16847 | +#endif | |
dece6358 | 16848 | + |
4a4d8108 AM |
16849 | + /* reference to the copied-up whiteout with get/put */ |
16850 | + struct dentry *hi_whdentry; | |
16851 | +}; | |
dece6358 | 16852 | + |
537831f9 AM |
16853 | +/* ig_flags */ |
16854 | +#define AuIG_HALF_REFRESHED 1 | |
16855 | +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name) | |
16856 | +#define au_ig_fset(flags, name) \ | |
16857 | + do { (flags) |= AuIG_##name; } while (0) | |
16858 | +#define au_ig_fclr(flags, name) \ | |
16859 | + do { (flags) &= ~AuIG_##name; } while (0) | |
16860 | + | |
16861 | +struct au_iigen { | |
be52b249 | 16862 | + spinlock_t ig_spin; |
537831f9 AM |
16863 | + __u32 ig_generation, ig_flags; |
16864 | +}; | |
16865 | + | |
4a4d8108 AM |
16866 | +struct au_vdir; |
16867 | +struct au_iinfo { | |
7a9e40b8 | 16868 | + struct au_iigen ii_generation; |
4a4d8108 | 16869 | + struct super_block *ii_hsb1; /* no get/put */ |
1facf9fc | 16870 | + |
4a4d8108 | 16871 | + struct au_rwsem ii_rwsem; |
5afbbe0d | 16872 | + aufs_bindex_t ii_btop, ii_bbot; |
4a4d8108 AM |
16873 | + __u32 ii_higen; |
16874 | + struct au_hinode *ii_hinode; | |
16875 | + struct au_vdir *ii_vdir; | |
16876 | +}; | |
1facf9fc | 16877 | + |
4a4d8108 AM |
16878 | +struct au_icntnr { |
16879 | + struct au_iinfo iinfo; | |
16880 | + struct inode vfs_inode; | |
f0c0a007 AM |
16881 | + union { |
16882 | + struct hlist_node plink; | |
16883 | + struct llist_node lnode; /* delayed free */ | |
16884 | + }; | |
4a4d8108 | 16885 | +} ____cacheline_aligned_in_smp; |
1308ab2a | 16886 | + |
4a4d8108 AM |
16887 | +/* au_pin flags */ |
16888 | +#define AuPin_DI_LOCKED 1 | |
16889 | +#define AuPin_MNT_WRITE (1 << 1) | |
16890 | +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name) | |
7f207e10 AM |
16891 | +#define au_fset_pin(flags, name) \ |
16892 | + do { (flags) |= AuPin_##name; } while (0) | |
16893 | +#define au_fclr_pin(flags, name) \ | |
16894 | + do { (flags) &= ~AuPin_##name; } while (0) | |
4a4d8108 AM |
16895 | + |
16896 | +struct au_pin { | |
16897 | + /* input */ | |
16898 | + struct dentry *dentry; | |
16899 | + unsigned int udba; | |
16900 | + unsigned char lsc_di, lsc_hi, flags; | |
16901 | + aufs_bindex_t bindex; | |
16902 | + | |
16903 | + /* output */ | |
16904 | + struct dentry *parent; | |
16905 | + struct au_hinode *hdir; | |
16906 | + struct vfsmount *h_mnt; | |
86dc4139 AM |
16907 | + |
16908 | + /* temporary unlock/relock for copyup */ | |
16909 | + struct dentry *h_dentry, *h_parent; | |
16910 | + struct au_branch *br; | |
16911 | + struct task_struct *task; | |
4a4d8108 | 16912 | +}; |
1facf9fc | 16913 | + |
86dc4139 | 16914 | +void au_pin_hdir_unlock(struct au_pin *p); |
c1595e42 | 16915 | +int au_pin_hdir_lock(struct au_pin *p); |
86dc4139 | 16916 | +int au_pin_hdir_relock(struct au_pin *p); |
86dc4139 AM |
16917 | +void au_pin_hdir_acquire_nest(struct au_pin *p); |
16918 | +void au_pin_hdir_release(struct au_pin *p); | |
16919 | + | |
1308ab2a | 16920 | +/* ---------------------------------------------------------------------- */ |
16921 | + | |
4a4d8108 | 16922 | +static inline struct au_iinfo *au_ii(struct inode *inode) |
1facf9fc | 16923 | +{ |
5afbbe0d AM |
16924 | + BUG_ON(is_bad_inode(inode)); |
16925 | + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
4a4d8108 | 16926 | +} |
1facf9fc | 16927 | + |
4a4d8108 | 16928 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16929 | + |
4a4d8108 AM |
16930 | +/* inode.c */ |
16931 | +struct inode *au_igrab(struct inode *inode); | |
b95c5147 | 16932 | +void au_refresh_iop(struct inode *inode, int force_getattr); |
027c5e7a | 16933 | +int au_refresh_hinode_self(struct inode *inode); |
4a4d8108 AM |
16934 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry); |
16935 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
16936 | + unsigned int d_type, ino_t *ino); | |
16937 | +struct inode *au_new_inode(struct dentry *dentry, int must_new); | |
16938 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, | |
16939 | + struct inode *inode); | |
16940 | +int au_test_h_perm(struct inode *h_inode, int mask); | |
16941 | +int au_test_h_perm_sio(struct inode *h_inode, int mask); | |
1facf9fc | 16942 | + |
4a4d8108 AM |
16943 | +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, |
16944 | + ino_t h_ino, unsigned int d_type, ino_t *ino) | |
16945 | +{ | |
16946 | +#ifdef CONFIG_AUFS_SHWH | |
16947 | + return au_ino(sb, bindex, h_ino, d_type, ino); | |
16948 | +#else | |
16949 | + return 0; | |
16950 | +#endif | |
16951 | +} | |
1facf9fc | 16952 | + |
4a4d8108 | 16953 | +/* i_op.c */ |
b95c5147 AM |
16954 | +enum { |
16955 | + AuIop_SYMLINK, | |
16956 | + AuIop_DIR, | |
16957 | + AuIop_OTHER, | |
16958 | + AuIop_Last | |
16959 | +}; | |
16960 | +extern struct inode_operations aufs_iop[AuIop_Last], | |
16961 | + aufs_iop_nogetattr[AuIop_Last]; | |
1308ab2a | 16962 | + |
4a4d8108 AM |
16963 | +/* au_wr_dir flags */ |
16964 | +#define AuWrDir_ADD_ENTRY 1 | |
7e9cd9fe AM |
16965 | +#define AuWrDir_ISDIR (1 << 1) |
16966 | +#define AuWrDir_TMPFILE (1 << 2) | |
4a4d8108 | 16967 | +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name) |
7f207e10 AM |
16968 | +#define au_fset_wrdir(flags, name) \ |
16969 | + do { (flags) |= AuWrDir_##name; } while (0) | |
16970 | +#define au_fclr_wrdir(flags, name) \ | |
16971 | + do { (flags) &= ~AuWrDir_##name; } while (0) | |
1facf9fc | 16972 | + |
4a4d8108 AM |
16973 | +struct au_wr_dir_args { |
16974 | + aufs_bindex_t force_btgt; | |
16975 | + unsigned char flags; | |
16976 | +}; | |
16977 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
16978 | + struct au_wr_dir_args *args); | |
dece6358 | 16979 | + |
4a4d8108 AM |
16980 | +struct dentry *au_pinned_h_parent(struct au_pin *pin); |
16981 | +void au_pin_init(struct au_pin *pin, struct dentry *dentry, | |
16982 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
16983 | + unsigned int udba, unsigned char flags); | |
16984 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
16985 | + unsigned int udba, unsigned char flags) __must_check; | |
16986 | +int au_do_pin(struct au_pin *pin) __must_check; | |
16987 | +void au_unpin(struct au_pin *pin); | |
c1595e42 JR |
16988 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen); |
16989 | + | |
16990 | +#define AuIcpup_DID_CPUP 1 | |
16991 | +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name) | |
16992 | +#define au_fset_icpup(flags, name) \ | |
16993 | + do { (flags) |= AuIcpup_##name; } while (0) | |
16994 | +#define au_fclr_icpup(flags, name) \ | |
16995 | + do { (flags) &= ~AuIcpup_##name; } while (0) | |
16996 | + | |
16997 | +struct au_icpup_args { | |
16998 | + unsigned char flags; | |
16999 | + unsigned char pin_flags; | |
17000 | + aufs_bindex_t btgt; | |
17001 | + unsigned int udba; | |
17002 | + struct au_pin pin; | |
17003 | + struct path h_path; | |
17004 | + struct inode *h_inode; | |
17005 | +}; | |
17006 | + | |
17007 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, | |
17008 | + struct au_icpup_args *a); | |
17009 | + | |
a2654f78 AM |
17010 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path, |
17011 | + int locked); | |
1facf9fc | 17012 | + |
4a4d8108 AM |
17013 | +/* i_op_add.c */ |
17014 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
17015 | + struct dentry *h_parent, int isdir); | |
7eafdf33 AM |
17016 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
17017 | + dev_t dev); | |
4a4d8108 | 17018 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname); |
7eafdf33 | 17019 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 17020 | + bool want_excl); |
b912730e AM |
17021 | +struct vfsub_aopen_args; |
17022 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, | |
17023 | + struct vfsub_aopen_args *args); | |
38d290e6 | 17024 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode); |
4a4d8108 AM |
17025 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, |
17026 | + struct dentry *dentry); | |
7eafdf33 | 17027 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
1facf9fc | 17028 | + |
4a4d8108 AM |
17029 | +/* i_op_del.c */ |
17030 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup); | |
17031 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
17032 | + struct dentry *h_parent, int isdir); | |
17033 | +int aufs_unlink(struct inode *dir, struct dentry *dentry); | |
17034 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry); | |
1308ab2a | 17035 | + |
4a4d8108 AM |
17036 | +/* i_op_ren.c */ |
17037 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt); | |
17038 | +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry, | |
f2c43d5f AM |
17039 | + struct inode *dir, struct dentry *dentry, |
17040 | + unsigned int flags); | |
1facf9fc | 17041 | + |
4a4d8108 AM |
17042 | +/* iinfo.c */ |
17043 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex); | |
17044 | +void au_hiput(struct au_hinode *hinode); | |
17045 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, | |
17046 | + struct dentry *h_wh); | |
17047 | +unsigned int au_hi_flags(struct inode *inode, int isdir); | |
1308ab2a | 17048 | + |
4a4d8108 AM |
17049 | +/* hinode flags */ |
17050 | +#define AuHi_XINO 1 | |
17051 | +#define AuHi_HNOTIFY (1 << 1) | |
17052 | +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name) | |
7f207e10 AM |
17053 | +#define au_fset_hi(flags, name) \ |
17054 | + do { (flags) |= AuHi_##name; } while (0) | |
17055 | +#define au_fclr_hi(flags, name) \ | |
17056 | + do { (flags) &= ~AuHi_##name; } while (0) | |
1facf9fc | 17057 | + |
4a4d8108 AM |
17058 | +#ifndef CONFIG_AUFS_HNOTIFY |
17059 | +#undef AuHi_HNOTIFY | |
17060 | +#define AuHi_HNOTIFY 0 | |
17061 | +#endif | |
1facf9fc | 17062 | + |
4a4d8108 AM |
17063 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
17064 | + struct inode *h_inode, unsigned int flags); | |
1facf9fc | 17065 | + |
537831f9 | 17066 | +void au_update_iigen(struct inode *inode, int half); |
4a4d8108 | 17067 | +void au_update_ibrange(struct inode *inode, int do_put_zero); |
1facf9fc | 17068 | + |
4a4d8108 | 17069 | +void au_icntnr_init_once(void *_c); |
5afbbe0d | 17070 | +void au_hinode_init(struct au_hinode *hinode); |
4a4d8108 AM |
17071 | +int au_iinfo_init(struct inode *inode); |
17072 | +void au_iinfo_fin(struct inode *inode); | |
e2f27e51 | 17073 | +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink); |
1308ab2a | 17074 | + |
e49829fe | 17075 | +#ifdef CONFIG_PROC_FS |
4a4d8108 | 17076 | +/* plink.c */ |
e49829fe | 17077 | +int au_plink_maint(struct super_block *sb, int flags); |
7e9cd9fe | 17078 | +struct au_sbinfo; |
e49829fe JR |
17079 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo); |
17080 | +int au_plink_maint_enter(struct super_block *sb); | |
4a4d8108 AM |
17081 | +#ifdef CONFIG_AUFS_DEBUG |
17082 | +void au_plink_list(struct super_block *sb); | |
17083 | +#else | |
17084 | +AuStubVoid(au_plink_list, struct super_block *sb) | |
17085 | +#endif | |
17086 | +int au_plink_test(struct inode *inode); | |
17087 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex); | |
17088 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
17089 | + struct dentry *h_dentry); | |
e49829fe JR |
17090 | +void au_plink_put(struct super_block *sb, int verbose); |
17091 | +void au_plink_clean(struct super_block *sb, int verbose); | |
4a4d8108 | 17092 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id); |
e49829fe JR |
17093 | +#else |
17094 | +AuStubInt0(au_plink_maint, struct super_block *sb, int flags); | |
17095 | +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo); | |
17096 | +AuStubInt0(au_plink_maint_enter, struct super_block *sb); | |
17097 | +AuStubVoid(au_plink_list, struct super_block *sb); | |
17098 | +AuStubInt0(au_plink_test, struct inode *inode); | |
17099 | +AuStub(struct dentry *, au_plink_lkup, return NULL, | |
17100 | + struct inode *inode, aufs_bindex_t bindex); | |
17101 | +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex, | |
17102 | + struct dentry *h_dentry); | |
17103 | +AuStubVoid(au_plink_put, struct super_block *sb, int verbose); | |
17104 | +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose); | |
17105 | +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id); | |
17106 | +#endif /* CONFIG_PROC_FS */ | |
1facf9fc | 17107 | + |
c1595e42 JR |
17108 | +#ifdef CONFIG_AUFS_XATTR |
17109 | +/* xattr.c */ | |
7e9cd9fe AM |
17110 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
17111 | + unsigned int verbose); | |
c1595e42 | 17112 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size); |
f2c43d5f | 17113 | +void au_xattr_init(struct super_block *sb); |
c1595e42 JR |
17114 | +#else |
17115 | +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe | 17116 | + int ignore_flags, unsigned int verbose); |
f2c43d5f | 17117 | +AuStubVoid(au_xattr_init, struct super_block *sb); |
c1595e42 JR |
17118 | +#endif |
17119 | + | |
17120 | +#ifdef CONFIG_FS_POSIX_ACL | |
17121 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type); | |
17122 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
17123 | +#endif | |
17124 | + | |
17125 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) | |
17126 | +enum { | |
17127 | + AU_XATTR_SET, | |
c1595e42 JR |
17128 | + AU_ACL_SET |
17129 | +}; | |
17130 | + | |
f2c43d5f | 17131 | +struct au_sxattr { |
c1595e42 JR |
17132 | + int type; |
17133 | + union { | |
17134 | + struct { | |
17135 | + const char *name; | |
17136 | + const void *value; | |
17137 | + size_t size; | |
17138 | + int flags; | |
17139 | + } set; | |
17140 | + struct { | |
c1595e42 JR |
17141 | + struct posix_acl *acl; |
17142 | + int type; | |
17143 | + } acl_set; | |
17144 | + } u; | |
17145 | +}; | |
f2c43d5f AM |
17146 | +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode, |
17147 | + struct au_sxattr *arg); | |
c1595e42 JR |
17148 | +#endif |
17149 | + | |
4a4d8108 | 17150 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 17151 | + |
4a4d8108 AM |
17152 | +/* lock subclass for iinfo */ |
17153 | +enum { | |
17154 | + AuLsc_II_CHILD, /* child first */ | |
17155 | + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */ | |
17156 | + AuLsc_II_CHILD3, /* copyup dirs */ | |
17157 | + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */ | |
17158 | + AuLsc_II_PARENT2, | |
17159 | + AuLsc_II_PARENT3, /* copyup dirs */ | |
17160 | + AuLsc_II_NEW_CHILD | |
17161 | +}; | |
1308ab2a | 17162 | + |
1facf9fc | 17163 | +/* |
4a4d8108 AM |
17164 | + * ii_read_lock_child, ii_write_lock_child, |
17165 | + * ii_read_lock_child2, ii_write_lock_child2, | |
17166 | + * ii_read_lock_child3, ii_write_lock_child3, | |
17167 | + * ii_read_lock_parent, ii_write_lock_parent, | |
17168 | + * ii_read_lock_parent2, ii_write_lock_parent2, | |
17169 | + * ii_read_lock_parent3, ii_write_lock_parent3, | |
17170 | + * ii_read_lock_new_child, ii_write_lock_new_child, | |
1facf9fc | 17171 | + */ |
4a4d8108 AM |
17172 | +#define AuReadLockFunc(name, lsc) \ |
17173 | +static inline void ii_read_lock_##name(struct inode *i) \ | |
17174 | +{ \ | |
17175 | + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
17176 | +} | |
17177 | + | |
17178 | +#define AuWriteLockFunc(name, lsc) \ | |
17179 | +static inline void ii_write_lock_##name(struct inode *i) \ | |
17180 | +{ \ | |
17181 | + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
17182 | +} | |
17183 | + | |
17184 | +#define AuRWLockFuncs(name, lsc) \ | |
17185 | + AuReadLockFunc(name, lsc) \ | |
17186 | + AuWriteLockFunc(name, lsc) | |
17187 | + | |
17188 | +AuRWLockFuncs(child, CHILD); | |
17189 | +AuRWLockFuncs(child2, CHILD2); | |
17190 | +AuRWLockFuncs(child3, CHILD3); | |
17191 | +AuRWLockFuncs(parent, PARENT); | |
17192 | +AuRWLockFuncs(parent2, PARENT2); | |
17193 | +AuRWLockFuncs(parent3, PARENT3); | |
17194 | +AuRWLockFuncs(new_child, NEW_CHILD); | |
17195 | + | |
17196 | +#undef AuReadLockFunc | |
17197 | +#undef AuWriteLockFunc | |
17198 | +#undef AuRWLockFuncs | |
1facf9fc | 17199 | + |
17200 | +/* | |
4a4d8108 | 17201 | + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock |
1facf9fc | 17202 | + */ |
4a4d8108 | 17203 | +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem); |
1facf9fc | 17204 | + |
4a4d8108 AM |
17205 | +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem) |
17206 | +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem) | |
17207 | +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 17208 | + |
4a4d8108 | 17209 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 17210 | + |
027c5e7a AM |
17211 | +static inline void au_icntnr_init(struct au_icntnr *c) |
17212 | +{ | |
17213 | +#ifdef CONFIG_AUFS_DEBUG | |
17214 | + c->vfs_inode.i_mode = 0; | |
17215 | +#endif | |
17216 | +} | |
17217 | + | |
cfc41e69 | 17218 | +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags) |
4a4d8108 | 17219 | +{ |
537831f9 AM |
17220 | + unsigned int gen; |
17221 | + struct au_iinfo *iinfo; | |
be52b249 | 17222 | + struct au_iigen *iigen; |
537831f9 AM |
17223 | + |
17224 | + iinfo = au_ii(inode); | |
be52b249 AM |
17225 | + iigen = &iinfo->ii_generation; |
17226 | + spin_lock(&iigen->ig_spin); | |
cfc41e69 AM |
17227 | + if (igflags) |
17228 | + *igflags = iigen->ig_flags; | |
be52b249 AM |
17229 | + gen = iigen->ig_generation; |
17230 | + spin_unlock(&iigen->ig_spin); | |
537831f9 AM |
17231 | + |
17232 | + return gen; | |
4a4d8108 | 17233 | +} |
1308ab2a | 17234 | + |
4a4d8108 AM |
17235 | +/* tiny test for inode number */ |
17236 | +/* tmpfs generation is too rough */ | |
17237 | +static inline int au_test_higen(struct inode *inode, struct inode *h_inode) | |
17238 | +{ | |
17239 | + struct au_iinfo *iinfo; | |
1308ab2a | 17240 | + |
4a4d8108 AM |
17241 | + iinfo = au_ii(inode); |
17242 | + AuRwMustAnyLock(&iinfo->ii_rwsem); | |
17243 | + return !(iinfo->ii_hsb1 == h_inode->i_sb | |
17244 | + && iinfo->ii_higen == h_inode->i_generation); | |
17245 | +} | |
1308ab2a | 17246 | + |
4a4d8108 AM |
17247 | +static inline void au_iigen_dec(struct inode *inode) |
17248 | +{ | |
537831f9 | 17249 | + struct au_iinfo *iinfo; |
be52b249 | 17250 | + struct au_iigen *iigen; |
537831f9 AM |
17251 | + |
17252 | + iinfo = au_ii(inode); | |
be52b249 AM |
17253 | + iigen = &iinfo->ii_generation; |
17254 | + spin_lock(&iigen->ig_spin); | |
17255 | + iigen->ig_generation--; | |
17256 | + spin_unlock(&iigen->ig_spin); | |
027c5e7a AM |
17257 | +} |
17258 | + | |
17259 | +static inline int au_iigen_test(struct inode *inode, unsigned int sigen) | |
17260 | +{ | |
17261 | + int err; | |
17262 | + | |
17263 | + err = 0; | |
537831f9 | 17264 | + if (unlikely(inode && au_iigen(inode, NULL) != sigen)) |
027c5e7a AM |
17265 | + err = -EIO; |
17266 | + | |
17267 | + return err; | |
4a4d8108 | 17268 | +} |
1308ab2a | 17269 | + |
4a4d8108 | 17270 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 17271 | + |
5afbbe0d AM |
17272 | +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo, |
17273 | + aufs_bindex_t bindex) | |
17274 | +{ | |
17275 | + return iinfo->ii_hinode + bindex; | |
17276 | +} | |
17277 | + | |
17278 | +static inline int au_is_bad_inode(struct inode *inode) | |
17279 | +{ | |
17280 | + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0)); | |
17281 | +} | |
17282 | + | |
4a4d8108 AM |
17283 | +static inline aufs_bindex_t au_ii_br_id(struct inode *inode, |
17284 | + aufs_bindex_t bindex) | |
17285 | +{ | |
17286 | + IiMustAnyLock(inode); | |
5afbbe0d | 17287 | + return au_hinode(au_ii(inode), bindex)->hi_id; |
4a4d8108 | 17288 | +} |
1308ab2a | 17289 | + |
5afbbe0d | 17290 | +static inline aufs_bindex_t au_ibtop(struct inode *inode) |
4a4d8108 AM |
17291 | +{ |
17292 | + IiMustAnyLock(inode); | |
5afbbe0d | 17293 | + return au_ii(inode)->ii_btop; |
4a4d8108 | 17294 | +} |
1308ab2a | 17295 | + |
5afbbe0d | 17296 | +static inline aufs_bindex_t au_ibbot(struct inode *inode) |
4a4d8108 AM |
17297 | +{ |
17298 | + IiMustAnyLock(inode); | |
5afbbe0d | 17299 | + return au_ii(inode)->ii_bbot; |
4a4d8108 | 17300 | +} |
1308ab2a | 17301 | + |
4a4d8108 AM |
17302 | +static inline struct au_vdir *au_ivdir(struct inode *inode) |
17303 | +{ | |
17304 | + IiMustAnyLock(inode); | |
17305 | + return au_ii(inode)->ii_vdir; | |
17306 | +} | |
1308ab2a | 17307 | + |
4a4d8108 AM |
17308 | +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex) |
17309 | +{ | |
17310 | + IiMustAnyLock(inode); | |
5afbbe0d | 17311 | + return au_hinode(au_ii(inode), bindex)->hi_whdentry; |
4a4d8108 | 17312 | +} |
1308ab2a | 17313 | + |
5afbbe0d | 17314 | +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 17315 | +{ |
4a4d8108 | 17316 | + IiMustWriteLock(inode); |
5afbbe0d | 17317 | + au_ii(inode)->ii_btop = bindex; |
4a4d8108 | 17318 | +} |
1308ab2a | 17319 | + |
5afbbe0d | 17320 | +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex) |
4a4d8108 AM |
17321 | +{ |
17322 | + IiMustWriteLock(inode); | |
5afbbe0d | 17323 | + au_ii(inode)->ii_bbot = bindex; |
1308ab2a | 17324 | +} |
17325 | + | |
4a4d8108 AM |
17326 | +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir) |
17327 | +{ | |
17328 | + IiMustWriteLock(inode); | |
17329 | + au_ii(inode)->ii_vdir = vdir; | |
17330 | +} | |
1facf9fc | 17331 | + |
4a4d8108 | 17332 | +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 17333 | +{ |
4a4d8108 | 17334 | + IiMustAnyLock(inode); |
5afbbe0d | 17335 | + return au_hinode(au_ii(inode), bindex); |
4a4d8108 | 17336 | +} |
dece6358 | 17337 | + |
4a4d8108 | 17338 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 17339 | + |
4a4d8108 AM |
17340 | +static inline struct dentry *au_pinned_parent(struct au_pin *pin) |
17341 | +{ | |
17342 | + if (pin) | |
17343 | + return pin->parent; | |
17344 | + return NULL; | |
1facf9fc | 17345 | +} |
17346 | + | |
4a4d8108 | 17347 | +static inline struct inode *au_pinned_h_dir(struct au_pin *pin) |
1facf9fc | 17348 | +{ |
4a4d8108 AM |
17349 | + if (pin && pin->hdir) |
17350 | + return pin->hdir->hi_inode; | |
17351 | + return NULL; | |
1308ab2a | 17352 | +} |
1facf9fc | 17353 | + |
4a4d8108 AM |
17354 | +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin) |
17355 | +{ | |
17356 | + if (pin) | |
17357 | + return pin->hdir; | |
17358 | + return NULL; | |
17359 | +} | |
1facf9fc | 17360 | + |
4a4d8108 | 17361 | +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry) |
1308ab2a | 17362 | +{ |
4a4d8108 AM |
17363 | + if (pin) |
17364 | + pin->dentry = dentry; | |
17365 | +} | |
1308ab2a | 17366 | + |
4a4d8108 AM |
17367 | +static inline void au_pin_set_parent_lflag(struct au_pin *pin, |
17368 | + unsigned char lflag) | |
17369 | +{ | |
17370 | + if (pin) { | |
7f207e10 | 17371 | + if (lflag) |
4a4d8108 | 17372 | + au_fset_pin(pin->flags, DI_LOCKED); |
7f207e10 | 17373 | + else |
4a4d8108 | 17374 | + au_fclr_pin(pin->flags, DI_LOCKED); |
1308ab2a | 17375 | + } |
4a4d8108 AM |
17376 | +} |
17377 | + | |
7e9cd9fe | 17378 | +#if 0 /* reserved */ |
4a4d8108 AM |
17379 | +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent) |
17380 | +{ | |
17381 | + if (pin) { | |
17382 | + dput(pin->parent); | |
17383 | + pin->parent = dget(parent); | |
1facf9fc | 17384 | + } |
4a4d8108 | 17385 | +} |
7e9cd9fe | 17386 | +#endif |
1facf9fc | 17387 | + |
4a4d8108 AM |
17388 | +/* ---------------------------------------------------------------------- */ |
17389 | + | |
027c5e7a | 17390 | +struct au_branch; |
4a4d8108 AM |
17391 | +#ifdef CONFIG_AUFS_HNOTIFY |
17392 | +struct au_hnotify_op { | |
17393 | + void (*ctl)(struct au_hinode *hinode, int do_set); | |
027c5e7a | 17394 | + int (*alloc)(struct au_hinode *hinode); |
7eafdf33 AM |
17395 | + |
17396 | + /* | |
17397 | + * if it returns true, the the caller should free hinode->hi_notify, | |
17398 | + * otherwise ->free() frees it. | |
17399 | + */ | |
17400 | + int (*free)(struct au_hinode *hinode, | |
17401 | + struct au_hnotify *hn) __must_check; | |
4a4d8108 AM |
17402 | + |
17403 | + void (*fin)(void); | |
17404 | + int (*init)(void); | |
027c5e7a AM |
17405 | + |
17406 | + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm); | |
17407 | + void (*fin_br)(struct au_branch *br); | |
17408 | + int (*init_br)(struct au_branch *br, int perm); | |
4a4d8108 AM |
17409 | +}; |
17410 | + | |
17411 | +/* hnotify.c */ | |
027c5e7a | 17412 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode); |
4a4d8108 AM |
17413 | +void au_hn_free(struct au_hinode *hinode); |
17414 | +void au_hn_ctl(struct au_hinode *hinode, int do_set); | |
17415 | +void au_hn_reset(struct inode *inode, unsigned int flags); | |
17416 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
17417 | + struct qstr *h_child_qstr, struct inode *h_child_inode); | |
027c5e7a AM |
17418 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm); |
17419 | +int au_hnotify_init_br(struct au_branch *br, int perm); | |
17420 | +void au_hnotify_fin_br(struct au_branch *br); | |
4a4d8108 AM |
17421 | +int __init au_hnotify_init(void); |
17422 | +void au_hnotify_fin(void); | |
17423 | + | |
7f207e10 | 17424 | +/* hfsnotify.c */ |
4a4d8108 AM |
17425 | +extern const struct au_hnotify_op au_hnotify_op; |
17426 | + | |
17427 | +static inline | |
17428 | +void au_hn_init(struct au_hinode *hinode) | |
17429 | +{ | |
17430 | + hinode->hi_notify = NULL; | |
1308ab2a | 17431 | +} |
17432 | + | |
53392da6 AM |
17433 | +static inline struct au_hnotify *au_hn(struct au_hinode *hinode) |
17434 | +{ | |
17435 | + return hinode->hi_notify; | |
17436 | +} | |
17437 | + | |
4a4d8108 | 17438 | +#else |
c1595e42 JR |
17439 | +AuStub(int, au_hn_alloc, return -EOPNOTSUPP, |
17440 | + struct au_hinode *hinode __maybe_unused, | |
17441 | + struct inode *inode __maybe_unused) | |
17442 | +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode) | |
4a4d8108 AM |
17443 | +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused) |
17444 | +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused, | |
17445 | + int do_set __maybe_unused) | |
17446 | +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused, | |
17447 | + unsigned int flags __maybe_unused) | |
027c5e7a AM |
17448 | +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused, |
17449 | + struct au_branch *br __maybe_unused, | |
17450 | + int perm __maybe_unused) | |
17451 | +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused, | |
17452 | + int perm __maybe_unused) | |
17453 | +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused) | |
4a4d8108 AM |
17454 | +AuStubInt0(__init au_hnotify_init, void) |
17455 | +AuStubVoid(au_hnotify_fin, void) | |
17456 | +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused) | |
17457 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
17458 | + | |
17459 | +static inline void au_hn_suspend(struct au_hinode *hdir) | |
17460 | +{ | |
17461 | + au_hn_ctl(hdir, /*do_set*/0); | |
1308ab2a | 17462 | +} |
17463 | + | |
4a4d8108 | 17464 | +static inline void au_hn_resume(struct au_hinode *hdir) |
1308ab2a | 17465 | +{ |
4a4d8108 AM |
17466 | + au_hn_ctl(hdir, /*do_set*/1); |
17467 | +} | |
1308ab2a | 17468 | + |
5afbbe0d | 17469 | +static inline void au_hn_inode_lock(struct au_hinode *hdir) |
4a4d8108 | 17470 | +{ |
febd17d6 | 17471 | + inode_lock(hdir->hi_inode); |
4a4d8108 AM |
17472 | + au_hn_suspend(hdir); |
17473 | +} | |
dece6358 | 17474 | + |
5afbbe0d | 17475 | +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir, |
4a4d8108 AM |
17476 | + unsigned int sc __maybe_unused) |
17477 | +{ | |
febd17d6 | 17478 | + inode_lock_nested(hdir->hi_inode, sc); |
4a4d8108 | 17479 | + au_hn_suspend(hdir); |
1facf9fc | 17480 | +} |
1facf9fc | 17481 | + |
5afbbe0d | 17482 | +static inline void au_hn_inode_unlock(struct au_hinode *hdir) |
4a4d8108 AM |
17483 | +{ |
17484 | + au_hn_resume(hdir); | |
febd17d6 | 17485 | + inode_unlock(hdir->hi_inode); |
4a4d8108 AM |
17486 | +} |
17487 | + | |
17488 | +#endif /* __KERNEL__ */ | |
17489 | +#endif /* __AUFS_INODE_H__ */ | |
7f207e10 AM |
17490 | diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c |
17491 | --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 17492 | +++ linux/fs/aufs/ioctl.c 2017-05-06 22:16:52.781553511 +0200 |
c1595e42 | 17493 | @@ -0,0 +1,219 @@ |
4a4d8108 | 17494 | +/* |
a2654f78 | 17495 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
17496 | + * |
17497 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17498 | + * it under the terms of the GNU General Public License as published by | |
17499 | + * the Free Software Foundation; either version 2 of the License, or | |
17500 | + * (at your option) any later version. | |
17501 | + * | |
17502 | + * This program is distributed in the hope that it will be useful, | |
17503 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17504 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17505 | + * GNU General Public License for more details. | |
17506 | + * | |
17507 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17508 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
17509 | + */ |
17510 | + | |
17511 | +/* | |
17512 | + * ioctl | |
17513 | + * plink-management and readdir in userspace. | |
17514 | + * assist the pathconf(3) wrapper library. | |
c2b27bf2 | 17515 | + * move-down |
076b876e | 17516 | + * File-based Hierarchical Storage Management. |
4a4d8108 AM |
17517 | + */ |
17518 | + | |
c2b27bf2 AM |
17519 | +#include <linux/compat.h> |
17520 | +#include <linux/file.h> | |
4a4d8108 AM |
17521 | +#include "aufs.h" |
17522 | + | |
1e00d052 | 17523 | +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg) |
4a4d8108 AM |
17524 | +{ |
17525 | + int err, fd; | |
5afbbe0d | 17526 | + aufs_bindex_t wbi, bindex, bbot; |
4a4d8108 AM |
17527 | + struct file *h_file; |
17528 | + struct super_block *sb; | |
17529 | + struct dentry *root; | |
1e00d052 AM |
17530 | + struct au_branch *br; |
17531 | + struct aufs_wbr_fd wbrfd = { | |
17532 | + .oflags = au_dir_roflags, | |
17533 | + .brid = -1 | |
17534 | + }; | |
17535 | + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY | |
17536 | + | O_NOATIME | O_CLOEXEC; | |
4a4d8108 | 17537 | + |
1e00d052 AM |
17538 | + AuDebugOn(wbrfd.oflags & ~valid); |
17539 | + | |
17540 | + if (arg) { | |
17541 | + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd)); | |
17542 | + if (unlikely(err)) { | |
17543 | + err = -EFAULT; | |
17544 | + goto out; | |
17545 | + } | |
17546 | + | |
17547 | + err = -EINVAL; | |
17548 | + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid); | |
17549 | + wbrfd.oflags |= au_dir_roflags; | |
17550 | + AuDbg("0%o\n", wbrfd.oflags); | |
17551 | + if (unlikely(wbrfd.oflags & ~valid)) | |
17552 | + goto out; | |
17553 | + } | |
17554 | + | |
2000de60 | 17555 | + fd = get_unused_fd_flags(0); |
1e00d052 AM |
17556 | + err = fd; |
17557 | + if (unlikely(fd < 0)) | |
4a4d8108 | 17558 | + goto out; |
4a4d8108 | 17559 | + |
1e00d052 | 17560 | + h_file = ERR_PTR(-EINVAL); |
4a4d8108 | 17561 | + wbi = 0; |
1e00d052 | 17562 | + br = NULL; |
4a4d8108 AM |
17563 | + sb = path->dentry->d_sb; |
17564 | + root = sb->s_root; | |
17565 | + aufs_read_lock(root, AuLock_IR); | |
5afbbe0d | 17566 | + bbot = au_sbbot(sb); |
1e00d052 AM |
17567 | + if (wbrfd.brid >= 0) { |
17568 | + wbi = au_br_index(sb, wbrfd.brid); | |
5afbbe0d | 17569 | + if (unlikely(wbi < 0 || wbi > bbot)) |
1e00d052 AM |
17570 | + goto out_unlock; |
17571 | + } | |
17572 | + | |
17573 | + h_file = ERR_PTR(-ENOENT); | |
17574 | + br = au_sbr(sb, wbi); | |
17575 | + if (!au_br_writable(br->br_perm)) { | |
17576 | + if (arg) | |
17577 | + goto out_unlock; | |
17578 | + | |
17579 | + bindex = wbi + 1; | |
17580 | + wbi = -1; | |
5afbbe0d | 17581 | + for (; bindex <= bbot; bindex++) { |
1e00d052 AM |
17582 | + br = au_sbr(sb, bindex); |
17583 | + if (au_br_writable(br->br_perm)) { | |
4a4d8108 | 17584 | + wbi = bindex; |
1e00d052 | 17585 | + br = au_sbr(sb, wbi); |
4a4d8108 AM |
17586 | + break; |
17587 | + } | |
17588 | + } | |
4a4d8108 AM |
17589 | + } |
17590 | + AuDbg("wbi %d\n", wbi); | |
1e00d052 | 17591 | + if (wbi >= 0) |
392086de AM |
17592 | + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL, |
17593 | + /*force_wr*/0); | |
1e00d052 AM |
17594 | + |
17595 | +out_unlock: | |
4a4d8108 AM |
17596 | + aufs_read_unlock(root, AuLock_IR); |
17597 | + err = PTR_ERR(h_file); | |
17598 | + if (IS_ERR(h_file)) | |
17599 | + goto out_fd; | |
17600 | + | |
5afbbe0d | 17601 | + au_br_put(br); /* cf. au_h_open() */ |
4a4d8108 AM |
17602 | + fd_install(fd, h_file); |
17603 | + err = fd; | |
17604 | + goto out; /* success */ | |
17605 | + | |
4f0767ce | 17606 | +out_fd: |
4a4d8108 | 17607 | + put_unused_fd(fd); |
4f0767ce | 17608 | +out: |
1e00d052 | 17609 | + AuTraceErr(err); |
4a4d8108 AM |
17610 | + return err; |
17611 | +} | |
17612 | + | |
17613 | +/* ---------------------------------------------------------------------- */ | |
17614 | + | |
17615 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg) | |
17616 | +{ | |
17617 | + long err; | |
c1595e42 | 17618 | + struct dentry *dentry; |
4a4d8108 AM |
17619 | + |
17620 | + switch (cmd) { | |
4a4d8108 AM |
17621 | + case AUFS_CTL_RDU: |
17622 | + case AUFS_CTL_RDU_INO: | |
17623 | + err = au_rdu_ioctl(file, cmd, arg); | |
17624 | + break; | |
17625 | + | |
17626 | + case AUFS_CTL_WBR_FD: | |
1e00d052 | 17627 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17628 | + break; |
17629 | + | |
027c5e7a AM |
17630 | + case AUFS_CTL_IBUSY: |
17631 | + err = au_ibusy_ioctl(file, arg); | |
17632 | + break; | |
17633 | + | |
076b876e AM |
17634 | + case AUFS_CTL_BRINFO: |
17635 | + err = au_brinfo_ioctl(file, arg); | |
17636 | + break; | |
17637 | + | |
17638 | + case AUFS_CTL_FHSM_FD: | |
2000de60 | 17639 | + dentry = file->f_path.dentry; |
c1595e42 JR |
17640 | + if (IS_ROOT(dentry)) |
17641 | + err = au_fhsm_fd(dentry->d_sb, arg); | |
17642 | + else | |
17643 | + err = -ENOTTY; | |
076b876e AM |
17644 | + break; |
17645 | + | |
4a4d8108 AM |
17646 | + default: |
17647 | + /* do not call the lower */ | |
17648 | + AuDbg("0x%x\n", cmd); | |
17649 | + err = -ENOTTY; | |
17650 | + } | |
17651 | + | |
17652 | + AuTraceErr(err); | |
17653 | + return err; | |
17654 | +} | |
17655 | + | |
17656 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg) | |
17657 | +{ | |
17658 | + long err; | |
17659 | + | |
17660 | + switch (cmd) { | |
c2b27bf2 | 17661 | + case AUFS_CTL_MVDOWN: |
2000de60 | 17662 | + err = au_mvdown(file->f_path.dentry, (void __user *)arg); |
c2b27bf2 AM |
17663 | + break; |
17664 | + | |
4a4d8108 | 17665 | + case AUFS_CTL_WBR_FD: |
1e00d052 | 17666 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17667 | + break; |
17668 | + | |
17669 | + default: | |
17670 | + /* do not call the lower */ | |
17671 | + AuDbg("0x%x\n", cmd); | |
17672 | + err = -ENOTTY; | |
17673 | + } | |
17674 | + | |
17675 | + AuTraceErr(err); | |
17676 | + return err; | |
17677 | +} | |
b752ccd1 AM |
17678 | + |
17679 | +#ifdef CONFIG_COMPAT | |
17680 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
17681 | + unsigned long arg) | |
17682 | +{ | |
17683 | + long err; | |
17684 | + | |
17685 | + switch (cmd) { | |
17686 | + case AUFS_CTL_RDU: | |
17687 | + case AUFS_CTL_RDU_INO: | |
17688 | + err = au_rdu_compat_ioctl(file, cmd, arg); | |
17689 | + break; | |
17690 | + | |
027c5e7a AM |
17691 | + case AUFS_CTL_IBUSY: |
17692 | + err = au_ibusy_compat_ioctl(file, arg); | |
17693 | + break; | |
17694 | + | |
076b876e AM |
17695 | + case AUFS_CTL_BRINFO: |
17696 | + err = au_brinfo_compat_ioctl(file, arg); | |
17697 | + break; | |
17698 | + | |
b752ccd1 AM |
17699 | + default: |
17700 | + err = aufs_ioctl_dir(file, cmd, arg); | |
17701 | + } | |
17702 | + | |
17703 | + AuTraceErr(err); | |
17704 | + return err; | |
17705 | +} | |
17706 | + | |
b752ccd1 AM |
17707 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
17708 | + unsigned long arg) | |
17709 | +{ | |
17710 | + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg)); | |
17711 | +} | |
17712 | +#endif | |
7f207e10 AM |
17713 | diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c |
17714 | --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
17715 | +++ linux/fs/aufs/i_op_add.c 2017-05-06 22:16:52.778220093 +0200 |
17716 | @@ -0,0 +1,920 @@ | |
4a4d8108 | 17717 | +/* |
a2654f78 | 17718 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
17719 | + * |
17720 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17721 | + * it under the terms of the GNU General Public License as published by | |
17722 | + * the Free Software Foundation; either version 2 of the License, or | |
17723 | + * (at your option) any later version. | |
17724 | + * | |
17725 | + * This program is distributed in the hope that it will be useful, | |
17726 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17727 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17728 | + * GNU General Public License for more details. | |
17729 | + * | |
17730 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17731 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
17732 | + */ |
17733 | + | |
17734 | +/* | |
17735 | + * inode operations (add entry) | |
17736 | + */ | |
17737 | + | |
17738 | +#include "aufs.h" | |
17739 | + | |
17740 | +/* | |
17741 | + * final procedure of adding a new entry, except link(2). | |
17742 | + * remove whiteout, instantiate, copyup the parent dir's times and size | |
17743 | + * and update version. | |
17744 | + * if it failed, re-create the removed whiteout. | |
17745 | + */ | |
17746 | +static int epilog(struct inode *dir, aufs_bindex_t bindex, | |
17747 | + struct dentry *wh_dentry, struct dentry *dentry) | |
17748 | +{ | |
17749 | + int err, rerr; | |
17750 | + aufs_bindex_t bwh; | |
17751 | + struct path h_path; | |
076b876e | 17752 | + struct super_block *sb; |
4a4d8108 AM |
17753 | + struct inode *inode, *h_dir; |
17754 | + struct dentry *wh; | |
17755 | + | |
17756 | + bwh = -1; | |
076b876e | 17757 | + sb = dir->i_sb; |
4a4d8108 | 17758 | + if (wh_dentry) { |
5527c038 | 17759 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
4a4d8108 AM |
17760 | + IMustLock(h_dir); |
17761 | + AuDebugOn(au_h_iptr(dir, bindex) != h_dir); | |
17762 | + bwh = au_dbwh(dentry); | |
17763 | + h_path.dentry = wh_dentry; | |
076b876e | 17764 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
4a4d8108 AM |
17765 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, |
17766 | + dentry); | |
17767 | + if (unlikely(err)) | |
17768 | + goto out; | |
17769 | + } | |
17770 | + | |
17771 | + inode = au_new_inode(dentry, /*must_new*/1); | |
17772 | + if (!IS_ERR(inode)) { | |
17773 | + d_instantiate(dentry, inode); | |
5527c038 | 17774 | + dir = d_inode(dentry->d_parent); /* dir inode is locked */ |
4a4d8108 | 17775 | + IMustLock(dir); |
b912730e | 17776 | + au_dir_ts(dir, bindex); |
4a4d8108 | 17777 | + dir->i_version++; |
076b876e | 17778 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
4a4d8108 AM |
17779 | + return 0; /* success */ |
17780 | + } | |
17781 | + | |
17782 | + err = PTR_ERR(inode); | |
17783 | + if (!wh_dentry) | |
17784 | + goto out; | |
17785 | + | |
17786 | + /* revert */ | |
17787 | + /* dir inode is locked */ | |
17788 | + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent); | |
17789 | + rerr = PTR_ERR(wh); | |
17790 | + if (IS_ERR(wh)) { | |
523b37e3 AM |
17791 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", |
17792 | + dentry, err, rerr); | |
4a4d8108 AM |
17793 | + err = -EIO; |
17794 | + } else | |
17795 | + dput(wh); | |
17796 | + | |
4f0767ce | 17797 | +out: |
4a4d8108 AM |
17798 | + return err; |
17799 | +} | |
17800 | + | |
027c5e7a AM |
17801 | +static int au_d_may_add(struct dentry *dentry) |
17802 | +{ | |
17803 | + int err; | |
17804 | + | |
17805 | + err = 0; | |
17806 | + if (unlikely(d_unhashed(dentry))) | |
17807 | + err = -ENOENT; | |
5527c038 | 17808 | + if (unlikely(d_really_is_positive(dentry))) |
027c5e7a AM |
17809 | + err = -EEXIST; |
17810 | + return err; | |
17811 | +} | |
17812 | + | |
4a4d8108 AM |
17813 | +/* |
17814 | + * simple tests for the adding inode operations. | |
17815 | + * following the checks in vfs, plus the parent-child relationship. | |
17816 | + */ | |
17817 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
17818 | + struct dentry *h_parent, int isdir) | |
17819 | +{ | |
17820 | + int err; | |
17821 | + umode_t h_mode; | |
17822 | + struct dentry *h_dentry; | |
17823 | + struct inode *h_inode; | |
17824 | + | |
17825 | + err = -ENAMETOOLONG; | |
17826 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17827 | + goto out; | |
17828 | + | |
17829 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 17830 | + if (d_really_is_negative(dentry)) { |
4a4d8108 | 17831 | + err = -EEXIST; |
5527c038 | 17832 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
17833 | + goto out; |
17834 | + } else { | |
17835 | + /* rename(2) case */ | |
17836 | + err = -EIO; | |
5527c038 JR |
17837 | + if (unlikely(d_is_negative(h_dentry))) |
17838 | + goto out; | |
17839 | + h_inode = d_inode(h_dentry); | |
17840 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 AM |
17841 | + goto out; |
17842 | + | |
17843 | + h_mode = h_inode->i_mode; | |
17844 | + if (!isdir) { | |
17845 | + err = -EISDIR; | |
17846 | + if (unlikely(S_ISDIR(h_mode))) | |
17847 | + goto out; | |
17848 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
17849 | + err = -ENOTDIR; | |
17850 | + goto out; | |
17851 | + } | |
17852 | + } | |
17853 | + | |
17854 | + err = 0; | |
17855 | + /* expected parent dir is locked */ | |
17856 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
17857 | + err = -EIO; | |
17858 | + | |
4f0767ce | 17859 | +out: |
4a4d8108 AM |
17860 | + AuTraceErr(err); |
17861 | + return err; | |
17862 | +} | |
17863 | + | |
17864 | +/* | |
17865 | + * initial procedure of adding a new entry. | |
17866 | + * prepare writable branch and the parent dir, lock it, | |
17867 | + * and lookup whiteout for the new entry. | |
17868 | + */ | |
17869 | +static struct dentry* | |
17870 | +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt, | |
17871 | + struct dentry *src_dentry, struct au_pin *pin, | |
17872 | + struct au_wr_dir_args *wr_dir_args) | |
17873 | +{ | |
17874 | + struct dentry *wh_dentry, *h_parent; | |
17875 | + struct super_block *sb; | |
17876 | + struct au_branch *br; | |
17877 | + int err; | |
17878 | + unsigned int udba; | |
17879 | + aufs_bindex_t bcpup; | |
17880 | + | |
523b37e3 | 17881 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17882 | + |
17883 | + err = au_wr_dir(dentry, src_dentry, wr_dir_args); | |
17884 | + bcpup = err; | |
17885 | + wh_dentry = ERR_PTR(err); | |
17886 | + if (unlikely(err < 0)) | |
17887 | + goto out; | |
17888 | + | |
17889 | + sb = dentry->d_sb; | |
17890 | + udba = au_opt_udba(sb); | |
17891 | + err = au_pin(pin, dentry, bcpup, udba, | |
17892 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17893 | + wh_dentry = ERR_PTR(err); | |
17894 | + if (unlikely(err)) | |
17895 | + goto out; | |
17896 | + | |
17897 | + h_parent = au_pinned_h_parent(pin); | |
17898 | + if (udba != AuOpt_UDBA_NONE | |
5afbbe0d | 17899 | + && au_dbtop(dentry) == bcpup) |
4a4d8108 AM |
17900 | + err = au_may_add(dentry, bcpup, h_parent, |
17901 | + au_ftest_wrdir(wr_dir_args->flags, ISDIR)); | |
17902 | + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17903 | + err = -ENAMETOOLONG; | |
17904 | + wh_dentry = ERR_PTR(err); | |
17905 | + if (unlikely(err)) | |
17906 | + goto out_unpin; | |
17907 | + | |
17908 | + br = au_sbr(sb, bcpup); | |
17909 | + if (dt) { | |
17910 | + struct path tmp = { | |
17911 | + .dentry = h_parent, | |
86dc4139 | 17912 | + .mnt = au_br_mnt(br) |
4a4d8108 AM |
17913 | + }; |
17914 | + au_dtime_store(dt, au_pinned_parent(pin), &tmp); | |
17915 | + } | |
17916 | + | |
17917 | + wh_dentry = NULL; | |
17918 | + if (bcpup != au_dbwh(dentry)) | |
17919 | + goto out; /* success */ | |
17920 | + | |
2000de60 JR |
17921 | + /* |
17922 | + * ENAMETOOLONG here means that if we allowed create such name, then it | |
17923 | + * would not be able to removed in the future. So we don't allow such | |
17924 | + * name here and we don't handle ENAMETOOLONG differently here. | |
17925 | + */ | |
4a4d8108 AM |
17926 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br); |
17927 | + | |
4f0767ce | 17928 | +out_unpin: |
4a4d8108 AM |
17929 | + if (IS_ERR(wh_dentry)) |
17930 | + au_unpin(pin); | |
4f0767ce | 17931 | +out: |
4a4d8108 AM |
17932 | + return wh_dentry; |
17933 | +} | |
17934 | + | |
17935 | +/* ---------------------------------------------------------------------- */ | |
17936 | + | |
17937 | +enum { Mknod, Symlink, Creat }; | |
17938 | +struct simple_arg { | |
17939 | + int type; | |
17940 | + union { | |
17941 | + struct { | |
b912730e AM |
17942 | + umode_t mode; |
17943 | + bool want_excl; | |
17944 | + bool try_aopen; | |
17945 | + struct vfsub_aopen_args *aopen; | |
4a4d8108 AM |
17946 | + } c; |
17947 | + struct { | |
17948 | + const char *symname; | |
17949 | + } s; | |
17950 | + struct { | |
7eafdf33 | 17951 | + umode_t mode; |
4a4d8108 AM |
17952 | + dev_t dev; |
17953 | + } m; | |
17954 | + } u; | |
17955 | +}; | |
17956 | + | |
17957 | +static int add_simple(struct inode *dir, struct dentry *dentry, | |
17958 | + struct simple_arg *arg) | |
17959 | +{ | |
076b876e | 17960 | + int err, rerr; |
5afbbe0d | 17961 | + aufs_bindex_t btop; |
4a4d8108 | 17962 | + unsigned char created; |
b912730e AM |
17963 | + const unsigned char try_aopen |
17964 | + = (arg->type == Creat && arg->u.c.try_aopen); | |
4a4d8108 AM |
17965 | + struct dentry *wh_dentry, *parent; |
17966 | + struct inode *h_dir; | |
b912730e AM |
17967 | + struct super_block *sb; |
17968 | + struct au_branch *br; | |
c2b27bf2 AM |
17969 | + /* to reuduce stack size */ |
17970 | + struct { | |
17971 | + struct au_dtime dt; | |
17972 | + struct au_pin pin; | |
17973 | + struct path h_path; | |
17974 | + struct au_wr_dir_args wr_dir_args; | |
17975 | + } *a; | |
4a4d8108 | 17976 | + |
523b37e3 | 17977 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17978 | + IMustLock(dir); |
17979 | + | |
c2b27bf2 AM |
17980 | + err = -ENOMEM; |
17981 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
17982 | + if (unlikely(!a)) | |
17983 | + goto out; | |
17984 | + a->wr_dir_args.force_btgt = -1; | |
17985 | + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY; | |
17986 | + | |
4a4d8108 | 17987 | + parent = dentry->d_parent; /* dir inode is locked */ |
b912730e AM |
17988 | + if (!try_aopen) { |
17989 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); | |
17990 | + if (unlikely(err)) | |
17991 | + goto out_free; | |
17992 | + } | |
027c5e7a AM |
17993 | + err = au_d_may_add(dentry); |
17994 | + if (unlikely(err)) | |
17995 | + goto out_unlock; | |
b912730e AM |
17996 | + if (!try_aopen) |
17997 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
17998 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, |
17999 | + &a->pin, &a->wr_dir_args); | |
4a4d8108 AM |
18000 | + err = PTR_ERR(wh_dentry); |
18001 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 18002 | + goto out_parent; |
4a4d8108 | 18003 | + |
5afbbe0d | 18004 | + btop = au_dbtop(dentry); |
b912730e | 18005 | + sb = dentry->d_sb; |
5afbbe0d AM |
18006 | + br = au_sbr(sb, btop); |
18007 | + a->h_path.dentry = au_h_dptr(dentry, btop); | |
b912730e | 18008 | + a->h_path.mnt = au_br_mnt(br); |
c2b27bf2 | 18009 | + h_dir = au_pinned_h_dir(&a->pin); |
4a4d8108 AM |
18010 | + switch (arg->type) { |
18011 | + case Creat: | |
b912730e AM |
18012 | + err = 0; |
18013 | + if (!try_aopen || !h_dir->i_op->atomic_open) | |
18014 | + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode, | |
18015 | + arg->u.c.want_excl); | |
18016 | + else | |
18017 | + err = vfsub_atomic_open(h_dir, a->h_path.dentry, | |
18018 | + arg->u.c.aopen, br); | |
4a4d8108 AM |
18019 | + break; |
18020 | + case Symlink: | |
c2b27bf2 | 18021 | + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname); |
4a4d8108 AM |
18022 | + break; |
18023 | + case Mknod: | |
c2b27bf2 AM |
18024 | + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode, |
18025 | + arg->u.m.dev); | |
4a4d8108 AM |
18026 | + break; |
18027 | + default: | |
18028 | + BUG(); | |
18029 | + } | |
18030 | + created = !err; | |
18031 | + if (!err) | |
5afbbe0d | 18032 | + err = epilog(dir, btop, wh_dentry, dentry); |
4a4d8108 AM |
18033 | + |
18034 | + /* revert */ | |
5527c038 | 18035 | + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) { |
523b37e3 AM |
18036 | + /* no delegation since it is just created */ |
18037 | + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL, | |
18038 | + /*force*/0); | |
4a4d8108 | 18039 | + if (rerr) { |
523b37e3 AM |
18040 | + AuIOErr("%pd revert failure(%d, %d)\n", |
18041 | + dentry, err, rerr); | |
4a4d8108 AM |
18042 | + err = -EIO; |
18043 | + } | |
c2b27bf2 | 18044 | + au_dtime_revert(&a->dt); |
4a4d8108 AM |
18045 | + } |
18046 | + | |
b912730e AM |
18047 | + if (!err && try_aopen && !h_dir->i_op->atomic_open) |
18048 | + *arg->u.c.aopen->opened |= FILE_CREATED; | |
18049 | + | |
c2b27bf2 | 18050 | + au_unpin(&a->pin); |
4a4d8108 AM |
18051 | + dput(wh_dentry); |
18052 | + | |
027c5e7a | 18053 | +out_parent: |
b912730e AM |
18054 | + if (!try_aopen) |
18055 | + di_write_unlock(parent); | |
027c5e7a | 18056 | +out_unlock: |
4a4d8108 | 18057 | + if (unlikely(err)) { |
5afbbe0d | 18058 | + au_update_dbtop(dentry); |
4a4d8108 AM |
18059 | + d_drop(dentry); |
18060 | + } | |
b912730e AM |
18061 | + if (!try_aopen) |
18062 | + aufs_read_unlock(dentry, AuLock_DW); | |
c2b27bf2 | 18063 | +out_free: |
f0c0a007 | 18064 | + au_delayed_kfree(a); |
027c5e7a | 18065 | +out: |
4a4d8108 AM |
18066 | + return err; |
18067 | +} | |
18068 | + | |
7eafdf33 AM |
18069 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
18070 | + dev_t dev) | |
4a4d8108 AM |
18071 | +{ |
18072 | + struct simple_arg arg = { | |
18073 | + .type = Mknod, | |
18074 | + .u.m = { | |
18075 | + .mode = mode, | |
18076 | + .dev = dev | |
18077 | + } | |
18078 | + }; | |
18079 | + return add_simple(dir, dentry, &arg); | |
18080 | +} | |
18081 | + | |
18082 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |
18083 | +{ | |
18084 | + struct simple_arg arg = { | |
18085 | + .type = Symlink, | |
18086 | + .u.s.symname = symname | |
18087 | + }; | |
18088 | + return add_simple(dir, dentry, &arg); | |
18089 | +} | |
18090 | + | |
7eafdf33 | 18091 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 18092 | + bool want_excl) |
4a4d8108 AM |
18093 | +{ |
18094 | + struct simple_arg arg = { | |
18095 | + .type = Creat, | |
18096 | + .u.c = { | |
b4510431 AM |
18097 | + .mode = mode, |
18098 | + .want_excl = want_excl | |
4a4d8108 AM |
18099 | + } |
18100 | + }; | |
18101 | + return add_simple(dir, dentry, &arg); | |
18102 | +} | |
18103 | + | |
b912730e AM |
18104 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, |
18105 | + struct vfsub_aopen_args *aopen_args) | |
18106 | +{ | |
18107 | + struct simple_arg arg = { | |
18108 | + .type = Creat, | |
18109 | + .u.c = { | |
18110 | + .mode = aopen_args->create_mode, | |
18111 | + .want_excl = aopen_args->open_flag & O_EXCL, | |
18112 | + .try_aopen = true, | |
18113 | + .aopen = aopen_args | |
18114 | + } | |
18115 | + }; | |
18116 | + return add_simple(dir, dentry, &arg); | |
18117 | +} | |
18118 | + | |
38d290e6 JR |
18119 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
18120 | +{ | |
18121 | + int err; | |
18122 | + aufs_bindex_t bindex; | |
18123 | + struct super_block *sb; | |
18124 | + struct dentry *parent, *h_parent, *h_dentry; | |
18125 | + struct inode *h_dir, *inode; | |
18126 | + struct vfsmount *h_mnt; | |
18127 | + struct au_wr_dir_args wr_dir_args = { | |
18128 | + .force_btgt = -1, | |
18129 | + .flags = AuWrDir_TMPFILE | |
18130 | + }; | |
18131 | + | |
18132 | + /* copy-up may happen */ | |
febd17d6 | 18133 | + inode_lock(dir); |
38d290e6 JR |
18134 | + |
18135 | + sb = dir->i_sb; | |
18136 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
18137 | + if (unlikely(err)) | |
18138 | + goto out; | |
18139 | + | |
18140 | + err = au_di_init(dentry); | |
18141 | + if (unlikely(err)) | |
18142 | + goto out_si; | |
18143 | + | |
18144 | + err = -EBUSY; | |
18145 | + parent = d_find_any_alias(dir); | |
18146 | + AuDebugOn(!parent); | |
18147 | + di_write_lock_parent(parent); | |
5527c038 | 18148 | + if (unlikely(d_inode(parent) != dir)) |
38d290e6 JR |
18149 | + goto out_parent; |
18150 | + | |
18151 | + err = au_digen_test(parent, au_sigen(sb)); | |
18152 | + if (unlikely(err)) | |
18153 | + goto out_parent; | |
18154 | + | |
5afbbe0d AM |
18155 | + bindex = au_dbtop(parent); |
18156 | + au_set_dbtop(dentry, bindex); | |
18157 | + au_set_dbbot(dentry, bindex); | |
38d290e6 JR |
18158 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
18159 | + bindex = err; | |
18160 | + if (unlikely(err < 0)) | |
18161 | + goto out_parent; | |
18162 | + | |
18163 | + err = -EOPNOTSUPP; | |
18164 | + h_dir = au_h_iptr(dir, bindex); | |
18165 | + if (unlikely(!h_dir->i_op->tmpfile)) | |
18166 | + goto out_parent; | |
18167 | + | |
18168 | + h_mnt = au_sbr_mnt(sb, bindex); | |
18169 | + err = vfsub_mnt_want_write(h_mnt); | |
18170 | + if (unlikely(err)) | |
18171 | + goto out_parent; | |
18172 | + | |
18173 | + h_parent = au_h_dptr(parent, bindex); | |
521ced18 JR |
18174 | + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0); |
18175 | + if (IS_ERR(h_dentry)) { | |
18176 | + err = PTR_ERR(h_dentry); | |
38d290e6 | 18177 | + goto out_mnt; |
521ced18 | 18178 | + } |
38d290e6 | 18179 | + |
5afbbe0d AM |
18180 | + au_set_dbtop(dentry, bindex); |
18181 | + au_set_dbbot(dentry, bindex); | |
38d290e6 JR |
18182 | + au_set_h_dptr(dentry, bindex, dget(h_dentry)); |
18183 | + inode = au_new_inode(dentry, /*must_new*/1); | |
18184 | + if (IS_ERR(inode)) { | |
18185 | + err = PTR_ERR(inode); | |
18186 | + au_set_h_dptr(dentry, bindex, NULL); | |
5afbbe0d AM |
18187 | + au_set_dbtop(dentry, -1); |
18188 | + au_set_dbbot(dentry, -1); | |
38d290e6 JR |
18189 | + } else { |
18190 | + if (!inode->i_nlink) | |
18191 | + set_nlink(inode, 1); | |
18192 | + d_tmpfile(dentry, inode); | |
18193 | + au_di(dentry)->di_tmpfile = 1; | |
18194 | + | |
18195 | + /* update without i_mutex */ | |
5afbbe0d | 18196 | + if (au_ibtop(dir) == au_dbtop(dentry)) |
38d290e6 JR |
18197 | + au_cpup_attr_timesizes(dir); |
18198 | + } | |
38d290e6 | 18199 | + dput(h_dentry); |
521ced18 | 18200 | + |
38d290e6 JR |
18201 | +out_mnt: |
18202 | + vfsub_mnt_drop_write(h_mnt); | |
18203 | +out_parent: | |
18204 | + di_write_unlock(parent); | |
18205 | + dput(parent); | |
18206 | + di_write_unlock(dentry); | |
5afbbe0d | 18207 | + if (unlikely(err)) { |
38d290e6 JR |
18208 | + au_di_fin(dentry); |
18209 | + dentry->d_fsdata = NULL; | |
18210 | + } | |
18211 | +out_si: | |
18212 | + si_read_unlock(sb); | |
18213 | +out: | |
febd17d6 | 18214 | + inode_unlock(dir); |
38d290e6 JR |
18215 | + return err; |
18216 | +} | |
18217 | + | |
4a4d8108 AM |
18218 | +/* ---------------------------------------------------------------------- */ |
18219 | + | |
18220 | +struct au_link_args { | |
18221 | + aufs_bindex_t bdst, bsrc; | |
18222 | + struct au_pin pin; | |
18223 | + struct path h_path; | |
18224 | + struct dentry *src_parent, *parent; | |
18225 | +}; | |
18226 | + | |
18227 | +static int au_cpup_before_link(struct dentry *src_dentry, | |
18228 | + struct au_link_args *a) | |
18229 | +{ | |
18230 | + int err; | |
18231 | + struct dentry *h_src_dentry; | |
c2b27bf2 AM |
18232 | + struct au_cp_generic cpg = { |
18233 | + .dentry = src_dentry, | |
18234 | + .bdst = a->bdst, | |
18235 | + .bsrc = a->bsrc, | |
18236 | + .len = -1, | |
18237 | + .pin = &a->pin, | |
18238 | + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */ | |
18239 | + }; | |
4a4d8108 AM |
18240 | + |
18241 | + di_read_lock_parent(a->src_parent, AuLock_IR); | |
18242 | + err = au_test_and_cpup_dirs(src_dentry, a->bdst); | |
18243 | + if (unlikely(err)) | |
18244 | + goto out; | |
18245 | + | |
18246 | + h_src_dentry = au_h_dptr(src_dentry, a->bsrc); | |
4a4d8108 AM |
18247 | + err = au_pin(&a->pin, src_dentry, a->bdst, |
18248 | + au_opt_udba(src_dentry->d_sb), | |
18249 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
18250 | + if (unlikely(err)) | |
18251 | + goto out; | |
367653fa | 18252 | + |
c2b27bf2 | 18253 | + err = au_sio_cpup_simple(&cpg); |
4a4d8108 AM |
18254 | + au_unpin(&a->pin); |
18255 | + | |
4f0767ce | 18256 | +out: |
4a4d8108 AM |
18257 | + di_read_unlock(a->src_parent, AuLock_IR); |
18258 | + return err; | |
18259 | +} | |
18260 | + | |
86dc4139 AM |
18261 | +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry, |
18262 | + struct au_link_args *a) | |
4a4d8108 AM |
18263 | +{ |
18264 | + int err; | |
18265 | + unsigned char plink; | |
5afbbe0d | 18266 | + aufs_bindex_t bbot; |
4a4d8108 | 18267 | + struct dentry *h_src_dentry; |
523b37e3 | 18268 | + struct inode *h_inode, *inode, *delegated; |
4a4d8108 AM |
18269 | + struct super_block *sb; |
18270 | + struct file *h_file; | |
18271 | + | |
18272 | + plink = 0; | |
18273 | + h_inode = NULL; | |
18274 | + sb = src_dentry->d_sb; | |
5527c038 | 18275 | + inode = d_inode(src_dentry); |
5afbbe0d | 18276 | + if (au_ibtop(inode) <= a->bdst) |
4a4d8108 AM |
18277 | + h_inode = au_h_iptr(inode, a->bdst); |
18278 | + if (!h_inode || !h_inode->i_nlink) { | |
18279 | + /* copyup src_dentry as the name of dentry. */ | |
5afbbe0d AM |
18280 | + bbot = au_dbbot(dentry); |
18281 | + if (bbot < a->bsrc) | |
18282 | + au_set_dbbot(dentry, a->bsrc); | |
86dc4139 AM |
18283 | + au_set_h_dptr(dentry, a->bsrc, |
18284 | + dget(au_h_dptr(src_dentry, a->bsrc))); | |
18285 | + dget(a->h_path.dentry); | |
18286 | + au_set_h_dptr(dentry, a->bdst, NULL); | |
c1595e42 JR |
18287 | + AuDbg("temporary d_inode...\n"); |
18288 | + spin_lock(&dentry->d_lock); | |
5527c038 | 18289 | + dentry->d_inode = d_inode(src_dentry); /* tmp */ |
c1595e42 | 18290 | + spin_unlock(&dentry->d_lock); |
392086de | 18291 | + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0); |
86dc4139 | 18292 | + if (IS_ERR(h_file)) |
4a4d8108 | 18293 | + err = PTR_ERR(h_file); |
86dc4139 | 18294 | + else { |
c2b27bf2 AM |
18295 | + struct au_cp_generic cpg = { |
18296 | + .dentry = dentry, | |
18297 | + .bdst = a->bdst, | |
18298 | + .bsrc = -1, | |
18299 | + .len = -1, | |
18300 | + .pin = &a->pin, | |
18301 | + .flags = AuCpup_KEEPLINO | |
18302 | + }; | |
18303 | + err = au_sio_cpup_simple(&cpg); | |
86dc4139 AM |
18304 | + au_h_open_post(dentry, a->bsrc, h_file); |
18305 | + if (!err) { | |
18306 | + dput(a->h_path.dentry); | |
18307 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
18308 | + } else | |
18309 | + au_set_h_dptr(dentry, a->bdst, | |
18310 | + a->h_path.dentry); | |
18311 | + } | |
c1595e42 | 18312 | + spin_lock(&dentry->d_lock); |
86dc4139 | 18313 | + dentry->d_inode = NULL; /* restore */ |
c1595e42 JR |
18314 | + spin_unlock(&dentry->d_lock); |
18315 | + AuDbg("temporary d_inode...done\n"); | |
86dc4139 | 18316 | + au_set_h_dptr(dentry, a->bsrc, NULL); |
5afbbe0d | 18317 | + au_set_dbbot(dentry, bbot); |
4a4d8108 AM |
18318 | + } else { |
18319 | + /* the inode of src_dentry already exists on a.bdst branch */ | |
18320 | + h_src_dentry = d_find_alias(h_inode); | |
18321 | + if (!h_src_dentry && au_plink_test(inode)) { | |
18322 | + plink = 1; | |
18323 | + h_src_dentry = au_plink_lkup(inode, a->bdst); | |
18324 | + err = PTR_ERR(h_src_dentry); | |
18325 | + if (IS_ERR(h_src_dentry)) | |
18326 | + goto out; | |
18327 | + | |
5527c038 | 18328 | + if (unlikely(d_is_negative(h_src_dentry))) { |
4a4d8108 AM |
18329 | + dput(h_src_dentry); |
18330 | + h_src_dentry = NULL; | |
18331 | + } | |
18332 | + | |
18333 | + } | |
18334 | + if (h_src_dentry) { | |
523b37e3 | 18335 | + delegated = NULL; |
4a4d8108 | 18336 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
18337 | + &a->h_path, &delegated); |
18338 | + if (unlikely(err == -EWOULDBLOCK)) { | |
18339 | + pr_warn("cannot retry for NFSv4 delegation" | |
18340 | + " for an internal link\n"); | |
18341 | + iput(delegated); | |
18342 | + } | |
4a4d8108 AM |
18343 | + dput(h_src_dentry); |
18344 | + } else { | |
18345 | + AuIOErr("no dentry found for hi%lu on b%d\n", | |
18346 | + h_inode->i_ino, a->bdst); | |
18347 | + err = -EIO; | |
18348 | + } | |
18349 | + } | |
18350 | + | |
18351 | + if (!err && !plink) | |
18352 | + au_plink_append(inode, a->bdst, a->h_path.dentry); | |
18353 | + | |
18354 | +out: | |
2cbb1c4b | 18355 | + AuTraceErr(err); |
4a4d8108 AM |
18356 | + return err; |
18357 | +} | |
18358 | + | |
18359 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, | |
18360 | + struct dentry *dentry) | |
18361 | +{ | |
18362 | + int err, rerr; | |
18363 | + struct au_dtime dt; | |
18364 | + struct au_link_args *a; | |
18365 | + struct dentry *wh_dentry, *h_src_dentry; | |
523b37e3 | 18366 | + struct inode *inode, *delegated; |
4a4d8108 AM |
18367 | + struct super_block *sb; |
18368 | + struct au_wr_dir_args wr_dir_args = { | |
18369 | + /* .force_btgt = -1, */ | |
18370 | + .flags = AuWrDir_ADD_ENTRY | |
18371 | + }; | |
18372 | + | |
18373 | + IMustLock(dir); | |
5527c038 | 18374 | + inode = d_inode(src_dentry); |
4a4d8108 AM |
18375 | + IMustLock(inode); |
18376 | + | |
4a4d8108 AM |
18377 | + err = -ENOMEM; |
18378 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
18379 | + if (unlikely(!a)) | |
18380 | + goto out; | |
18381 | + | |
18382 | + a->parent = dentry->d_parent; /* dir inode is locked */ | |
027c5e7a AM |
18383 | + err = aufs_read_and_write_lock2(dentry, src_dentry, |
18384 | + AuLock_NOPLM | AuLock_GEN); | |
e49829fe JR |
18385 | + if (unlikely(err)) |
18386 | + goto out_kfree; | |
38d290e6 | 18387 | + err = au_d_linkable(src_dentry); |
027c5e7a AM |
18388 | + if (unlikely(err)) |
18389 | + goto out_unlock; | |
18390 | + err = au_d_may_add(dentry); | |
18391 | + if (unlikely(err)) | |
18392 | + goto out_unlock; | |
e49829fe | 18393 | + |
4a4d8108 | 18394 | + a->src_parent = dget_parent(src_dentry); |
5afbbe0d | 18395 | + wr_dir_args.force_btgt = au_ibtop(inode); |
4a4d8108 AM |
18396 | + |
18397 | + di_write_lock_parent(a->parent); | |
18398 | + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt); | |
18399 | + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin, | |
18400 | + &wr_dir_args); | |
18401 | + err = PTR_ERR(wh_dentry); | |
18402 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 18403 | + goto out_parent; |
4a4d8108 AM |
18404 | + |
18405 | + err = 0; | |
18406 | + sb = dentry->d_sb; | |
5afbbe0d | 18407 | + a->bdst = au_dbtop(dentry); |
4a4d8108 AM |
18408 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); |
18409 | + a->h_path.mnt = au_sbr_mnt(sb, a->bdst); | |
5afbbe0d | 18410 | + a->bsrc = au_ibtop(inode); |
2cbb1c4b | 18411 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); |
38d290e6 JR |
18412 | + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile) |
18413 | + h_src_dentry = dget(au_hi_wh(inode, a->bsrc)); | |
2cbb1c4b | 18414 | + if (!h_src_dentry) { |
5afbbe0d | 18415 | + a->bsrc = au_dbtop(src_dentry); |
2cbb1c4b JR |
18416 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); |
18417 | + AuDebugOn(!h_src_dentry); | |
38d290e6 JR |
18418 | + } else if (IS_ERR(h_src_dentry)) { |
18419 | + err = PTR_ERR(h_src_dentry); | |
2cbb1c4b | 18420 | + goto out_parent; |
38d290e6 | 18421 | + } |
2cbb1c4b | 18422 | + |
f2c43d5f AM |
18423 | + /* |
18424 | + * aufs doesn't touch the credential so | |
18425 | + * security_dentry_create_files_as() is unnecrssary. | |
18426 | + */ | |
4a4d8108 AM |
18427 | + if (au_opt_test(au_mntflags(sb), PLINK)) { |
18428 | + if (a->bdst < a->bsrc | |
18429 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) | |
86dc4139 | 18430 | + err = au_cpup_or_link(src_dentry, dentry, a); |
523b37e3 AM |
18431 | + else { |
18432 | + delegated = NULL; | |
4a4d8108 | 18433 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
18434 | + &a->h_path, &delegated); |
18435 | + if (unlikely(err == -EWOULDBLOCK)) { | |
18436 | + pr_warn("cannot retry for NFSv4 delegation" | |
18437 | + " for an internal link\n"); | |
18438 | + iput(delegated); | |
18439 | + } | |
18440 | + } | |
2cbb1c4b | 18441 | + dput(h_src_dentry); |
4a4d8108 AM |
18442 | + } else { |
18443 | + /* | |
18444 | + * copyup src_dentry to the branch we process, | |
18445 | + * and then link(2) to it. | |
18446 | + */ | |
2cbb1c4b | 18447 | + dput(h_src_dentry); |
4a4d8108 AM |
18448 | + if (a->bdst < a->bsrc |
18449 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) { | |
18450 | + au_unpin(&a->pin); | |
18451 | + di_write_unlock(a->parent); | |
18452 | + err = au_cpup_before_link(src_dentry, a); | |
18453 | + di_write_lock_parent(a->parent); | |
18454 | + if (!err) | |
18455 | + err = au_pin(&a->pin, dentry, a->bdst, | |
18456 | + au_opt_udba(sb), | |
18457 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
18458 | + if (unlikely(err)) | |
18459 | + goto out_wh; | |
18460 | + } | |
18461 | + if (!err) { | |
18462 | + h_src_dentry = au_h_dptr(src_dentry, a->bdst); | |
18463 | + err = -ENOENT; | |
5527c038 | 18464 | + if (h_src_dentry && d_is_positive(h_src_dentry)) { |
523b37e3 | 18465 | + delegated = NULL; |
4a4d8108 AM |
18466 | + err = vfsub_link(h_src_dentry, |
18467 | + au_pinned_h_dir(&a->pin), | |
523b37e3 AM |
18468 | + &a->h_path, &delegated); |
18469 | + if (unlikely(err == -EWOULDBLOCK)) { | |
18470 | + pr_warn("cannot retry" | |
18471 | + " for NFSv4 delegation" | |
18472 | + " for an internal link\n"); | |
18473 | + iput(delegated); | |
18474 | + } | |
18475 | + } | |
4a4d8108 AM |
18476 | + } |
18477 | + } | |
18478 | + if (unlikely(err)) | |
18479 | + goto out_unpin; | |
18480 | + | |
18481 | + if (wh_dentry) { | |
18482 | + a->h_path.dentry = wh_dentry; | |
18483 | + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path, | |
18484 | + dentry); | |
18485 | + if (unlikely(err)) | |
18486 | + goto out_revert; | |
18487 | + } | |
18488 | + | |
b912730e | 18489 | + au_dir_ts(dir, a->bdst); |
4a4d8108 | 18490 | + dir->i_version++; |
4a4d8108 AM |
18491 | + inc_nlink(inode); |
18492 | + inode->i_ctime = dir->i_ctime; | |
027c5e7a AM |
18493 | + d_instantiate(dentry, au_igrab(inode)); |
18494 | + if (d_unhashed(a->h_path.dentry)) | |
4a4d8108 AM |
18495 | + /* some filesystem calls d_drop() */ |
18496 | + d_drop(dentry); | |
076b876e AM |
18497 | + /* some filesystems consume an inode even hardlink */ |
18498 | + au_fhsm_wrote(sb, a->bdst, /*force*/0); | |
4a4d8108 AM |
18499 | + goto out_unpin; /* success */ |
18500 | + | |
4f0767ce | 18501 | +out_revert: |
523b37e3 AM |
18502 | + /* no delegation since it is just created */ |
18503 | + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, | |
18504 | + /*delegated*/NULL, /*force*/0); | |
027c5e7a | 18505 | + if (unlikely(rerr)) { |
523b37e3 | 18506 | + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr); |
027c5e7a AM |
18507 | + err = -EIO; |
18508 | + } | |
4a4d8108 | 18509 | + au_dtime_revert(&dt); |
4f0767ce | 18510 | +out_unpin: |
4a4d8108 | 18511 | + au_unpin(&a->pin); |
4f0767ce | 18512 | +out_wh: |
4a4d8108 | 18513 | + dput(wh_dentry); |
027c5e7a AM |
18514 | +out_parent: |
18515 | + di_write_unlock(a->parent); | |
18516 | + dput(a->src_parent); | |
4f0767ce | 18517 | +out_unlock: |
4a4d8108 | 18518 | + if (unlikely(err)) { |
5afbbe0d | 18519 | + au_update_dbtop(dentry); |
4a4d8108 AM |
18520 | + d_drop(dentry); |
18521 | + } | |
4a4d8108 | 18522 | + aufs_read_and_write_unlock2(dentry, src_dentry); |
e49829fe | 18523 | +out_kfree: |
f0c0a007 | 18524 | + au_delayed_kfree(a); |
4f0767ce | 18525 | +out: |
86dc4139 | 18526 | + AuTraceErr(err); |
4a4d8108 AM |
18527 | + return err; |
18528 | +} | |
18529 | + | |
7eafdf33 | 18530 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
4a4d8108 AM |
18531 | +{ |
18532 | + int err, rerr; | |
18533 | + aufs_bindex_t bindex; | |
18534 | + unsigned char diropq; | |
18535 | + struct path h_path; | |
18536 | + struct dentry *wh_dentry, *parent, *opq_dentry; | |
febd17d6 | 18537 | + struct inode *h_inode; |
4a4d8108 AM |
18538 | + struct super_block *sb; |
18539 | + struct { | |
18540 | + struct au_pin pin; | |
18541 | + struct au_dtime dt; | |
18542 | + } *a; /* reduce the stack usage */ | |
18543 | + struct au_wr_dir_args wr_dir_args = { | |
18544 | + .force_btgt = -1, | |
18545 | + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR | |
18546 | + }; | |
18547 | + | |
18548 | + IMustLock(dir); | |
18549 | + | |
18550 | + err = -ENOMEM; | |
18551 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
18552 | + if (unlikely(!a)) | |
18553 | + goto out; | |
18554 | + | |
027c5e7a AM |
18555 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
18556 | + if (unlikely(err)) | |
18557 | + goto out_free; | |
18558 | + err = au_d_may_add(dentry); | |
18559 | + if (unlikely(err)) | |
18560 | + goto out_unlock; | |
18561 | + | |
4a4d8108 AM |
18562 | + parent = dentry->d_parent; /* dir inode is locked */ |
18563 | + di_write_lock_parent(parent); | |
18564 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, | |
18565 | + &a->pin, &wr_dir_args); | |
18566 | + err = PTR_ERR(wh_dentry); | |
18567 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 18568 | + goto out_parent; |
4a4d8108 AM |
18569 | + |
18570 | + sb = dentry->d_sb; | |
5afbbe0d | 18571 | + bindex = au_dbtop(dentry); |
4a4d8108 AM |
18572 | + h_path.dentry = au_h_dptr(dentry, bindex); |
18573 | + h_path.mnt = au_sbr_mnt(sb, bindex); | |
18574 | + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode); | |
18575 | + if (unlikely(err)) | |
027c5e7a | 18576 | + goto out_unpin; |
4a4d8108 AM |
18577 | + |
18578 | + /* make the dir opaque */ | |
18579 | + diropq = 0; | |
febd17d6 | 18580 | + h_inode = d_inode(h_path.dentry); |
4a4d8108 AM |
18581 | + if (wh_dentry |
18582 | + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) { | |
febd17d6 | 18583 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
4a4d8108 | 18584 | + opq_dentry = au_diropq_create(dentry, bindex); |
febd17d6 | 18585 | + inode_unlock(h_inode); |
4a4d8108 AM |
18586 | + err = PTR_ERR(opq_dentry); |
18587 | + if (IS_ERR(opq_dentry)) | |
18588 | + goto out_dir; | |
18589 | + dput(opq_dentry); | |
18590 | + diropq = 1; | |
18591 | + } | |
18592 | + | |
18593 | + err = epilog(dir, bindex, wh_dentry, dentry); | |
18594 | + if (!err) { | |
18595 | + inc_nlink(dir); | |
027c5e7a | 18596 | + goto out_unpin; /* success */ |
4a4d8108 AM |
18597 | + } |
18598 | + | |
18599 | + /* revert */ | |
18600 | + if (diropq) { | |
18601 | + AuLabel(revert opq); | |
febd17d6 | 18602 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
4a4d8108 | 18603 | + rerr = au_diropq_remove(dentry, bindex); |
febd17d6 | 18604 | + inode_unlock(h_inode); |
4a4d8108 | 18605 | + if (rerr) { |
523b37e3 AM |
18606 | + AuIOErr("%pd reverting diropq failed(%d, %d)\n", |
18607 | + dentry, err, rerr); | |
4a4d8108 AM |
18608 | + err = -EIO; |
18609 | + } | |
18610 | + } | |
18611 | + | |
4f0767ce | 18612 | +out_dir: |
4a4d8108 AM |
18613 | + AuLabel(revert dir); |
18614 | + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path); | |
18615 | + if (rerr) { | |
523b37e3 AM |
18616 | + AuIOErr("%pd reverting dir failed(%d, %d)\n", |
18617 | + dentry, err, rerr); | |
4a4d8108 AM |
18618 | + err = -EIO; |
18619 | + } | |
4a4d8108 | 18620 | + au_dtime_revert(&a->dt); |
027c5e7a | 18621 | +out_unpin: |
4a4d8108 AM |
18622 | + au_unpin(&a->pin); |
18623 | + dput(wh_dentry); | |
027c5e7a AM |
18624 | +out_parent: |
18625 | + di_write_unlock(parent); | |
18626 | +out_unlock: | |
4a4d8108 | 18627 | + if (unlikely(err)) { |
5afbbe0d | 18628 | + au_update_dbtop(dentry); |
4a4d8108 AM |
18629 | + d_drop(dentry); |
18630 | + } | |
4a4d8108 | 18631 | + aufs_read_unlock(dentry, AuLock_DW); |
027c5e7a | 18632 | +out_free: |
f0c0a007 | 18633 | + au_delayed_kfree(a); |
4f0767ce | 18634 | +out: |
4a4d8108 AM |
18635 | + return err; |
18636 | +} | |
7f207e10 AM |
18637 | diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c |
18638 | --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
18639 | +++ linux/fs/aufs/i_op.c 2017-05-06 22:16:52.778220093 +0200 |
18640 | @@ -0,0 +1,1452 @@ | |
4a4d8108 | 18641 | +/* |
a2654f78 | 18642 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
18643 | + * |
18644 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18645 | + * it under the terms of the GNU General Public License as published by | |
18646 | + * the Free Software Foundation; either version 2 of the License, or | |
18647 | + * (at your option) any later version. | |
18648 | + * | |
18649 | + * This program is distributed in the hope that it will be useful, | |
18650 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18651 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18652 | + * GNU General Public License for more details. | |
18653 | + * | |
18654 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18655 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18656 | + */ |
1facf9fc | 18657 | + |
1308ab2a | 18658 | +/* |
4a4d8108 | 18659 | + * inode operations (except add/del/rename) |
1308ab2a | 18660 | + */ |
4a4d8108 AM |
18661 | + |
18662 | +#include <linux/device_cgroup.h> | |
18663 | +#include <linux/fs_stack.h> | |
4a4d8108 AM |
18664 | +#include <linux/namei.h> |
18665 | +#include <linux/security.h> | |
4a4d8108 AM |
18666 | +#include "aufs.h" |
18667 | + | |
1e00d052 | 18668 | +static int h_permission(struct inode *h_inode, int mask, |
79b8bda9 | 18669 | + struct path *h_path, int brperm) |
1facf9fc | 18670 | +{ |
1308ab2a | 18671 | + int err; |
4a4d8108 | 18672 | + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); |
1facf9fc | 18673 | + |
e2f27e51 AM |
18674 | + err = -EPERM; |
18675 | + if (write_mask && IS_IMMUTABLE(h_inode)) | |
18676 | + goto out; | |
18677 | + | |
4a4d8108 | 18678 | + err = -EACCES; |
e2f27e51 AM |
18679 | + if (((mask & MAY_EXEC) |
18680 | + && S_ISREG(h_inode->i_mode) | |
18681 | + && (path_noexec(h_path) | |
18682 | + || !(h_inode->i_mode & S_IXUGO)))) | |
4a4d8108 AM |
18683 | + goto out; |
18684 | + | |
18685 | + /* | |
18686 | + * - skip the lower fs test in the case of write to ro branch. | |
18687 | + * - nfs dir permission write check is optimized, but a policy for | |
18688 | + * link/rename requires a real check. | |
b912730e AM |
18689 | + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.' |
18690 | + * in this case, generic_permission() returns -EOPNOTSUPP. | |
4a4d8108 AM |
18691 | + */ |
18692 | + if ((write_mask && !au_br_writable(brperm)) | |
18693 | + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode) | |
18694 | + && write_mask && !(mask & MAY_READ)) | |
18695 | + || !h_inode->i_op->permission) { | |
18696 | + /* AuLabel(generic_permission); */ | |
b912730e | 18697 | + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */ |
1e00d052 | 18698 | + err = generic_permission(h_inode, mask); |
b912730e AM |
18699 | + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode)) |
18700 | + err = h_inode->i_op->permission(h_inode, mask); | |
18701 | + AuTraceErr(err); | |
1308ab2a | 18702 | + } else { |
4a4d8108 | 18703 | + /* AuLabel(h_inode->permission); */ |
1e00d052 | 18704 | + err = h_inode->i_op->permission(h_inode, mask); |
4a4d8108 AM |
18705 | + AuTraceErr(err); |
18706 | + } | |
1facf9fc | 18707 | + |
4a4d8108 AM |
18708 | + if (!err) |
18709 | + err = devcgroup_inode_permission(h_inode, mask); | |
7f207e10 | 18710 | + if (!err) |
4a4d8108 | 18711 | + err = security_inode_permission(h_inode, mask); |
4a4d8108 AM |
18712 | + |
18713 | +#if 0 | |
18714 | + if (!err) { | |
18715 | + /* todo: do we need to call ima_path_check()? */ | |
18716 | + struct path h_path = { | |
18717 | + .dentry = | |
18718 | + .mnt = h_mnt | |
18719 | + }; | |
18720 | + err = ima_path_check(&h_path, | |
18721 | + mask & (MAY_READ | MAY_WRITE | MAY_EXEC), | |
18722 | + IMA_COUNT_LEAVE); | |
1308ab2a | 18723 | + } |
4a4d8108 | 18724 | +#endif |
dece6358 | 18725 | + |
4f0767ce | 18726 | +out: |
1308ab2a | 18727 | + return err; |
18728 | +} | |
dece6358 | 18729 | + |
1e00d052 | 18730 | +static int aufs_permission(struct inode *inode, int mask) |
1308ab2a | 18731 | +{ |
18732 | + int err; | |
5afbbe0d | 18733 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
18734 | + const unsigned char isdir = !!S_ISDIR(inode->i_mode), |
18735 | + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); | |
18736 | + struct inode *h_inode; | |
18737 | + struct super_block *sb; | |
18738 | + struct au_branch *br; | |
1facf9fc | 18739 | + |
027c5e7a | 18740 | + /* todo: support rcu-walk? */ |
1e00d052 | 18741 | + if (mask & MAY_NOT_BLOCK) |
027c5e7a AM |
18742 | + return -ECHILD; |
18743 | + | |
4a4d8108 AM |
18744 | + sb = inode->i_sb; |
18745 | + si_read_lock(sb, AuLock_FLUSH); | |
18746 | + ii_read_lock_child(inode); | |
027c5e7a AM |
18747 | +#if 0 |
18748 | + err = au_iigen_test(inode, au_sigen(sb)); | |
18749 | + if (unlikely(err)) | |
18750 | + goto out; | |
18751 | +#endif | |
dece6358 | 18752 | + |
076b876e AM |
18753 | + if (!isdir |
18754 | + || write_mask | |
18755 | + || au_opt_test(au_mntflags(sb), DIRPERM1)) { | |
4a4d8108 | 18756 | + err = au_busy_or_stale(); |
5afbbe0d | 18757 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
4a4d8108 AM |
18758 | + if (unlikely(!h_inode |
18759 | + || (h_inode->i_mode & S_IFMT) | |
18760 | + != (inode->i_mode & S_IFMT))) | |
18761 | + goto out; | |
1facf9fc | 18762 | + |
4a4d8108 | 18763 | + err = 0; |
5afbbe0d | 18764 | + bindex = au_ibtop(inode); |
4a4d8108 | 18765 | + br = au_sbr(sb, bindex); |
79b8bda9 | 18766 | + err = h_permission(h_inode, mask, &br->br_path, br->br_perm); |
4a4d8108 AM |
18767 | + if (write_mask |
18768 | + && !err | |
18769 | + && !special_file(h_inode->i_mode)) { | |
18770 | + /* test whether the upper writable branch exists */ | |
18771 | + err = -EROFS; | |
18772 | + for (; bindex >= 0; bindex--) | |
18773 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
18774 | + err = 0; | |
18775 | + break; | |
18776 | + } | |
18777 | + } | |
18778 | + goto out; | |
18779 | + } | |
dece6358 | 18780 | + |
4a4d8108 | 18781 | + /* non-write to dir */ |
1308ab2a | 18782 | + err = 0; |
5afbbe0d AM |
18783 | + bbot = au_ibbot(inode); |
18784 | + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) { | |
4a4d8108 AM |
18785 | + h_inode = au_h_iptr(inode, bindex); |
18786 | + if (h_inode) { | |
18787 | + err = au_busy_or_stale(); | |
18788 | + if (unlikely(!S_ISDIR(h_inode->i_mode))) | |
18789 | + break; | |
18790 | + | |
18791 | + br = au_sbr(sb, bindex); | |
79b8bda9 | 18792 | + err = h_permission(h_inode, mask, &br->br_path, |
4a4d8108 AM |
18793 | + br->br_perm); |
18794 | + } | |
18795 | + } | |
1308ab2a | 18796 | + |
4f0767ce | 18797 | +out: |
4a4d8108 AM |
18798 | + ii_read_unlock(inode); |
18799 | + si_read_unlock(sb); | |
1308ab2a | 18800 | + return err; |
18801 | +} | |
18802 | + | |
4a4d8108 | 18803 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18804 | + |
4a4d8108 | 18805 | +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry, |
b4510431 | 18806 | + unsigned int flags) |
4a4d8108 AM |
18807 | +{ |
18808 | + struct dentry *ret, *parent; | |
b752ccd1 | 18809 | + struct inode *inode; |
4a4d8108 | 18810 | + struct super_block *sb; |
1716fcea | 18811 | + int err, npositive; |
dece6358 | 18812 | + |
4a4d8108 | 18813 | + IMustLock(dir); |
1308ab2a | 18814 | + |
537831f9 AM |
18815 | + /* todo: support rcu-walk? */ |
18816 | + ret = ERR_PTR(-ECHILD); | |
18817 | + if (flags & LOOKUP_RCU) | |
18818 | + goto out; | |
18819 | + | |
18820 | + ret = ERR_PTR(-ENAMETOOLONG); | |
18821 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
18822 | + goto out; | |
18823 | + | |
4a4d8108 | 18824 | + sb = dir->i_sb; |
7f207e10 AM |
18825 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
18826 | + ret = ERR_PTR(err); | |
18827 | + if (unlikely(err)) | |
18828 | + goto out; | |
18829 | + | |
4a4d8108 AM |
18830 | + err = au_di_init(dentry); |
18831 | + ret = ERR_PTR(err); | |
18832 | + if (unlikely(err)) | |
7f207e10 | 18833 | + goto out_si; |
1308ab2a | 18834 | + |
9dbd164d | 18835 | + inode = NULL; |
027c5e7a | 18836 | + npositive = 0; /* suppress a warning */ |
4a4d8108 AM |
18837 | + parent = dentry->d_parent; /* dir inode is locked */ |
18838 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a AM |
18839 | + err = au_alive_dir(parent); |
18840 | + if (!err) | |
18841 | + err = au_digen_test(parent, au_sigen(sb)); | |
18842 | + if (!err) { | |
5afbbe0d AM |
18843 | + /* regardless LOOKUP_CREATE, always ALLOW_NEG */ |
18844 | + npositive = au_lkup_dentry(dentry, au_dbtop(parent), | |
18845 | + AuLkup_ALLOW_NEG); | |
027c5e7a AM |
18846 | + err = npositive; |
18847 | + } | |
4a4d8108 | 18848 | + di_read_unlock(parent, AuLock_IR); |
4a4d8108 AM |
18849 | + ret = ERR_PTR(err); |
18850 | + if (unlikely(err < 0)) | |
18851 | + goto out_unlock; | |
1308ab2a | 18852 | + |
4a4d8108 | 18853 | + if (npositive) { |
b752ccd1 | 18854 | + inode = au_new_inode(dentry, /*must_new*/0); |
c1595e42 JR |
18855 | + if (IS_ERR(inode)) { |
18856 | + ret = (void *)inode; | |
18857 | + inode = NULL; | |
18858 | + goto out_unlock; | |
18859 | + } | |
9dbd164d | 18860 | + } |
4a4d8108 | 18861 | + |
c1595e42 JR |
18862 | + if (inode) |
18863 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 18864 | + ret = d_splice_alias(inode, dentry); |
537831f9 AM |
18865 | +#if 0 |
18866 | + if (unlikely(d_need_lookup(dentry))) { | |
18867 | + spin_lock(&dentry->d_lock); | |
18868 | + dentry->d_flags &= ~DCACHE_NEED_LOOKUP; | |
18869 | + spin_unlock(&dentry->d_lock); | |
18870 | + } else | |
18871 | +#endif | |
c1595e42 | 18872 | + if (inode) { |
2000de60 | 18873 | + if (!IS_ERR(ret)) { |
c1595e42 | 18874 | + iput(inode); |
2000de60 JR |
18875 | + if (ret && ret != dentry) |
18876 | + ii_write_unlock(inode); | |
18877 | + } else { | |
c1595e42 JR |
18878 | + ii_write_unlock(inode); |
18879 | + iput(inode); | |
18880 | + inode = NULL; | |
18881 | + } | |
7f207e10 | 18882 | + } |
1facf9fc | 18883 | + |
4f0767ce | 18884 | +out_unlock: |
4a4d8108 | 18885 | + di_write_unlock(dentry); |
7f207e10 | 18886 | +out_si: |
4a4d8108 | 18887 | + si_read_unlock(sb); |
7f207e10 | 18888 | +out: |
4a4d8108 AM |
18889 | + return ret; |
18890 | +} | |
1facf9fc | 18891 | + |
4a4d8108 | 18892 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18893 | + |
b912730e AM |
18894 | +struct aopen_node { |
18895 | + struct hlist_node hlist; | |
18896 | + struct file *file, *h_file; | |
18897 | +}; | |
18898 | + | |
18899 | +static int au_do_aopen(struct inode *inode, struct file *file) | |
18900 | +{ | |
18901 | + struct au_sphlhead *aopen; | |
18902 | + struct aopen_node *node; | |
18903 | + struct au_do_open_args args = { | |
18904 | + .no_lock = 1, | |
18905 | + .open = au_do_open_nondir | |
18906 | + }; | |
18907 | + | |
18908 | + aopen = &au_sbi(inode->i_sb)->si_aopen; | |
18909 | + spin_lock(&aopen->spin); | |
18910 | + hlist_for_each_entry(node, &aopen->head, hlist) | |
18911 | + if (node->file == file) { | |
18912 | + args.h_file = node->h_file; | |
18913 | + break; | |
18914 | + } | |
18915 | + spin_unlock(&aopen->spin); | |
18916 | + /* AuDebugOn(!args.h_file); */ | |
18917 | + | |
18918 | + return au_do_open(file, &args); | |
18919 | +} | |
18920 | + | |
18921 | +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry, | |
18922 | + struct file *file, unsigned int open_flag, | |
18923 | + umode_t create_mode, int *opened) | |
18924 | +{ | |
18925 | + int err, h_opened = *opened; | |
5afbbe0d | 18926 | + unsigned int lkup_flags; |
f0c0a007 | 18927 | + struct dentry *parent, *d; |
b912730e AM |
18928 | + struct au_sphlhead *aopen; |
18929 | + struct vfsub_aopen_args args = { | |
18930 | + .open_flag = open_flag, | |
18931 | + .create_mode = create_mode, | |
18932 | + .opened = &h_opened | |
18933 | + }; | |
18934 | + struct aopen_node aopen_node = { | |
18935 | + .file = file | |
18936 | + }; | |
18937 | + | |
18938 | + IMustLock(dir); | |
5afbbe0d | 18939 | + AuDbg("open_flag 0%o\n", open_flag); |
b912730e AM |
18940 | + AuDbgDentry(dentry); |
18941 | + | |
18942 | + err = 0; | |
18943 | + if (!au_di(dentry)) { | |
5afbbe0d AM |
18944 | + lkup_flags = LOOKUP_OPEN; |
18945 | + if (open_flag & O_CREAT) | |
18946 | + lkup_flags |= LOOKUP_CREATE; | |
18947 | + d = aufs_lookup(dir, dentry, lkup_flags); | |
b912730e AM |
18948 | + if (IS_ERR(d)) { |
18949 | + err = PTR_ERR(d); | |
5afbbe0d | 18950 | + AuTraceErr(err); |
b912730e AM |
18951 | + goto out; |
18952 | + } else if (d) { | |
18953 | + /* | |
18954 | + * obsoleted dentry found. | |
18955 | + * another error will be returned later. | |
18956 | + */ | |
18957 | + d_drop(d); | |
b912730e | 18958 | + AuDbgDentry(d); |
5afbbe0d | 18959 | + dput(d); |
b912730e AM |
18960 | + } |
18961 | + AuDbgDentry(dentry); | |
18962 | + } | |
18963 | + | |
18964 | + if (d_is_positive(dentry) | |
18965 | + || d_unhashed(dentry) | |
18966 | + || d_unlinked(dentry) | |
18967 | + || !(open_flag & O_CREAT)) | |
18968 | + goto out_no_open; | |
18969 | + | |
18970 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); | |
18971 | + if (unlikely(err)) | |
18972 | + goto out; | |
18973 | + | |
18974 | + parent = dentry->d_parent; /* dir is locked */ | |
18975 | + di_write_lock_parent(parent); | |
5afbbe0d | 18976 | + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG); |
b912730e AM |
18977 | + if (unlikely(err)) |
18978 | + goto out_unlock; | |
18979 | + | |
18980 | + AuDbgDentry(dentry); | |
18981 | + if (d_is_positive(dentry)) | |
18982 | + goto out_unlock; | |
18983 | + | |
18984 | + args.file = get_empty_filp(); | |
18985 | + err = PTR_ERR(args.file); | |
18986 | + if (IS_ERR(args.file)) | |
18987 | + goto out_unlock; | |
18988 | + | |
18989 | + args.file->f_flags = file->f_flags; | |
18990 | + err = au_aopen_or_create(dir, dentry, &args); | |
18991 | + AuTraceErr(err); | |
18992 | + AuDbgFile(args.file); | |
18993 | + if (unlikely(err < 0)) { | |
18994 | + if (h_opened & FILE_OPENED) | |
18995 | + fput(args.file); | |
18996 | + else | |
18997 | + put_filp(args.file); | |
18998 | + goto out_unlock; | |
18999 | + } | |
19000 | + | |
19001 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
19002 | + *opened |= FILE_CREATED; | |
19003 | + if (h_opened & FILE_OPENED) | |
19004 | + aopen_node.h_file = args.file; | |
19005 | + else { | |
19006 | + put_filp(args.file); | |
19007 | + args.file = NULL; | |
19008 | + } | |
19009 | + aopen = &au_sbi(dir->i_sb)->si_aopen; | |
19010 | + au_sphl_add(&aopen_node.hlist, aopen); | |
19011 | + err = finish_open(file, dentry, au_do_aopen, opened); | |
19012 | + au_sphl_del(&aopen_node.hlist, aopen); | |
19013 | + AuTraceErr(err); | |
19014 | + AuDbgFile(file); | |
19015 | + if (aopen_node.h_file) | |
19016 | + fput(aopen_node.h_file); | |
19017 | + | |
19018 | +out_unlock: | |
19019 | + di_write_unlock(parent); | |
19020 | + aufs_read_unlock(dentry, AuLock_DW); | |
19021 | + AuDbgDentry(dentry); | |
f0c0a007 | 19022 | + if (unlikely(err < 0)) |
b912730e AM |
19023 | + goto out; |
19024 | +out_no_open: | |
f0c0a007 | 19025 | + if (err >= 0 && !(*opened & FILE_CREATED)) { |
b912730e AM |
19026 | + AuLabel(out_no_open); |
19027 | + dget(dentry); | |
19028 | + err = finish_no_open(file, dentry); | |
19029 | + } | |
19030 | +out: | |
19031 | + AuDbg("%pd%s%s\n", dentry, | |
19032 | + (*opened & FILE_CREATED) ? " created" : "", | |
19033 | + (*opened & FILE_OPENED) ? " opened" : ""); | |
19034 | + AuTraceErr(err); | |
19035 | + return err; | |
19036 | +} | |
19037 | + | |
19038 | + | |
19039 | +/* ---------------------------------------------------------------------- */ | |
19040 | + | |
4a4d8108 AM |
19041 | +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent, |
19042 | + const unsigned char add_entry, aufs_bindex_t bcpup, | |
5afbbe0d | 19043 | + aufs_bindex_t btop) |
4a4d8108 AM |
19044 | +{ |
19045 | + int err; | |
19046 | + struct dentry *h_parent; | |
19047 | + struct inode *h_dir; | |
1facf9fc | 19048 | + |
027c5e7a | 19049 | + if (add_entry) |
5527c038 | 19050 | + IMustLock(d_inode(parent)); |
027c5e7a | 19051 | + else |
4a4d8108 AM |
19052 | + di_write_lock_parent(parent); |
19053 | + | |
19054 | + err = 0; | |
19055 | + if (!au_h_dptr(parent, bcpup)) { | |
5afbbe0d | 19056 | + if (btop > bcpup) |
c2b27bf2 | 19057 | + err = au_cpup_dirs(dentry, bcpup); |
5afbbe0d | 19058 | + else if (btop < bcpup) |
4a4d8108 AM |
19059 | + err = au_cpdown_dirs(dentry, bcpup); |
19060 | + else | |
c2b27bf2 | 19061 | + BUG(); |
4a4d8108 | 19062 | + } |
38d290e6 | 19063 | + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) { |
4a4d8108 | 19064 | + h_parent = au_h_dptr(parent, bcpup); |
5527c038 | 19065 | + h_dir = d_inode(h_parent); |
febd17d6 | 19066 | + inode_lock_nested(h_dir, AuLsc_I_PARENT); |
7e9cd9fe | 19067 | + err = au_lkup_neg(dentry, bcpup, /*wh*/0); |
4a4d8108 | 19068 | + /* todo: no unlock here */ |
febd17d6 | 19069 | + inode_unlock(h_dir); |
027c5e7a AM |
19070 | + |
19071 | + AuDbg("bcpup %d\n", bcpup); | |
19072 | + if (!err) { | |
5527c038 | 19073 | + if (d_really_is_negative(dentry)) |
5afbbe0d | 19074 | + au_set_h_dptr(dentry, btop, NULL); |
4a4d8108 AM |
19075 | + au_update_dbrange(dentry, /*do_put_zero*/0); |
19076 | + } | |
1308ab2a | 19077 | + } |
1facf9fc | 19078 | + |
4a4d8108 AM |
19079 | + if (!add_entry) |
19080 | + di_write_unlock(parent); | |
19081 | + if (!err) | |
19082 | + err = bcpup; /* success */ | |
1308ab2a | 19083 | + |
027c5e7a | 19084 | + AuTraceErr(err); |
4a4d8108 AM |
19085 | + return err; |
19086 | +} | |
1facf9fc | 19087 | + |
4a4d8108 AM |
19088 | +/* |
19089 | + * decide the branch and the parent dir where we will create a new entry. | |
19090 | + * returns new bindex or an error. | |
19091 | + * copyup the parent dir if needed. | |
19092 | + */ | |
19093 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
19094 | + struct au_wr_dir_args *args) | |
19095 | +{ | |
19096 | + int err; | |
392086de | 19097 | + unsigned int flags; |
5afbbe0d | 19098 | + aufs_bindex_t bcpup, btop, src_btop; |
86dc4139 AM |
19099 | + const unsigned char add_entry |
19100 | + = au_ftest_wrdir(args->flags, ADD_ENTRY) | |
38d290e6 | 19101 | + | au_ftest_wrdir(args->flags, TMPFILE); |
4a4d8108 AM |
19102 | + struct super_block *sb; |
19103 | + struct dentry *parent; | |
19104 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 19105 | + |
4a4d8108 AM |
19106 | + sb = dentry->d_sb; |
19107 | + sbinfo = au_sbi(sb); | |
19108 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
19109 | + btop = au_dbtop(dentry); |
19110 | + bcpup = btop; | |
4a4d8108 AM |
19111 | + if (args->force_btgt < 0) { |
19112 | + if (src_dentry) { | |
5afbbe0d AM |
19113 | + src_btop = au_dbtop(src_dentry); |
19114 | + if (src_btop < btop) | |
19115 | + bcpup = src_btop; | |
4a4d8108 | 19116 | + } else if (add_entry) { |
392086de AM |
19117 | + flags = 0; |
19118 | + if (au_ftest_wrdir(args->flags, ISDIR)) | |
19119 | + au_fset_wbr(flags, DIR); | |
19120 | + err = AuWbrCreate(sbinfo, dentry, flags); | |
4a4d8108 AM |
19121 | + bcpup = err; |
19122 | + } | |
1facf9fc | 19123 | + |
5527c038 | 19124 | + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) { |
4a4d8108 AM |
19125 | + if (add_entry) |
19126 | + err = AuWbrCopyup(sbinfo, dentry); | |
19127 | + else { | |
19128 | + if (!IS_ROOT(dentry)) { | |
19129 | + di_read_lock_parent(parent, !AuLock_IR); | |
19130 | + err = AuWbrCopyup(sbinfo, dentry); | |
19131 | + di_read_unlock(parent, !AuLock_IR); | |
19132 | + } else | |
19133 | + err = AuWbrCopyup(sbinfo, dentry); | |
19134 | + } | |
19135 | + bcpup = err; | |
19136 | + if (unlikely(err < 0)) | |
19137 | + goto out; | |
19138 | + } | |
19139 | + } else { | |
19140 | + bcpup = args->force_btgt; | |
5527c038 | 19141 | + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry))); |
1308ab2a | 19142 | + } |
027c5e7a | 19143 | + |
5afbbe0d | 19144 | + AuDbg("btop %d, bcpup %d\n", btop, bcpup); |
4a4d8108 | 19145 | + err = bcpup; |
5afbbe0d | 19146 | + if (bcpup == btop) |
4a4d8108 | 19147 | + goto out; /* success */ |
4a4d8108 AM |
19148 | + |
19149 | + /* copyup the new parent into the branch we process */ | |
5afbbe0d | 19150 | + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop); |
027c5e7a | 19151 | + if (err >= 0) { |
5527c038 | 19152 | + if (d_really_is_negative(dentry)) { |
5afbbe0d AM |
19153 | + au_set_h_dptr(dentry, btop, NULL); |
19154 | + au_set_dbtop(dentry, bcpup); | |
19155 | + au_set_dbbot(dentry, bcpup); | |
027c5e7a | 19156 | + } |
38d290e6 JR |
19157 | + AuDebugOn(add_entry |
19158 | + && !au_ftest_wrdir(args->flags, TMPFILE) | |
19159 | + && !au_h_dptr(dentry, bcpup)); | |
027c5e7a | 19160 | + } |
86dc4139 AM |
19161 | + |
19162 | +out: | |
19163 | + dput(parent); | |
19164 | + return err; | |
19165 | +} | |
19166 | + | |
19167 | +/* ---------------------------------------------------------------------- */ | |
19168 | + | |
19169 | +void au_pin_hdir_unlock(struct au_pin *p) | |
19170 | +{ | |
19171 | + if (p->hdir) | |
5afbbe0d | 19172 | + au_hn_inode_unlock(p->hdir); |
86dc4139 AM |
19173 | +} |
19174 | + | |
c1595e42 | 19175 | +int au_pin_hdir_lock(struct au_pin *p) |
86dc4139 AM |
19176 | +{ |
19177 | + int err; | |
19178 | + | |
19179 | + err = 0; | |
19180 | + if (!p->hdir) | |
19181 | + goto out; | |
19182 | + | |
19183 | + /* even if an error happens later, keep this lock */ | |
5afbbe0d | 19184 | + au_hn_inode_lock_nested(p->hdir, p->lsc_hi); |
86dc4139 AM |
19185 | + |
19186 | + err = -EBUSY; | |
5527c038 | 19187 | + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent))) |
86dc4139 AM |
19188 | + goto out; |
19189 | + | |
19190 | + err = 0; | |
19191 | + if (p->h_dentry) | |
19192 | + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode, | |
19193 | + p->h_parent, p->br); | |
19194 | + | |
19195 | +out: | |
19196 | + return err; | |
19197 | +} | |
19198 | + | |
19199 | +int au_pin_hdir_relock(struct au_pin *p) | |
19200 | +{ | |
19201 | + int err, i; | |
19202 | + struct inode *h_i; | |
19203 | + struct dentry *h_d[] = { | |
19204 | + p->h_dentry, | |
19205 | + p->h_parent | |
19206 | + }; | |
19207 | + | |
19208 | + err = au_pin_hdir_lock(p); | |
19209 | + if (unlikely(err)) | |
19210 | + goto out; | |
19211 | + | |
19212 | + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) { | |
19213 | + if (!h_d[i]) | |
19214 | + continue; | |
5527c038 JR |
19215 | + if (d_is_positive(h_d[i])) { |
19216 | + h_i = d_inode(h_d[i]); | |
86dc4139 | 19217 | + err = !h_i->i_nlink; |
5527c038 | 19218 | + } |
86dc4139 AM |
19219 | + } |
19220 | + | |
19221 | +out: | |
19222 | + return err; | |
19223 | +} | |
19224 | + | |
5afbbe0d | 19225 | +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task) |
86dc4139 | 19226 | +{ |
5afbbe0d AM |
19227 | +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER) |
19228 | + p->hdir->hi_inode->i_rwsem.owner = task; | |
86dc4139 AM |
19229 | +#endif |
19230 | +} | |
19231 | + | |
19232 | +void au_pin_hdir_acquire_nest(struct au_pin *p) | |
19233 | +{ | |
19234 | + if (p->hdir) { | |
5afbbe0d | 19235 | + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map, |
86dc4139 AM |
19236 | + p->lsc_hi, 0, NULL, _RET_IP_); |
19237 | + au_pin_hdir_set_owner(p, current); | |
19238 | + } | |
dece6358 | 19239 | +} |
1facf9fc | 19240 | + |
86dc4139 AM |
19241 | +void au_pin_hdir_release(struct au_pin *p) |
19242 | +{ | |
19243 | + if (p->hdir) { | |
19244 | + au_pin_hdir_set_owner(p, p->task); | |
5afbbe0d | 19245 | + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_); |
86dc4139 AM |
19246 | + } |
19247 | +} | |
1308ab2a | 19248 | + |
4a4d8108 | 19249 | +struct dentry *au_pinned_h_parent(struct au_pin *pin) |
1308ab2a | 19250 | +{ |
4a4d8108 AM |
19251 | + if (pin && pin->parent) |
19252 | + return au_h_dptr(pin->parent, pin->bindex); | |
19253 | + return NULL; | |
dece6358 | 19254 | +} |
1facf9fc | 19255 | + |
4a4d8108 | 19256 | +void au_unpin(struct au_pin *p) |
dece6358 | 19257 | +{ |
86dc4139 AM |
19258 | + if (p->hdir) |
19259 | + au_pin_hdir_unlock(p); | |
e49829fe | 19260 | + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE)) |
b4510431 | 19261 | + vfsub_mnt_drop_write(p->h_mnt); |
4a4d8108 AM |
19262 | + if (!p->hdir) |
19263 | + return; | |
1facf9fc | 19264 | + |
4a4d8108 AM |
19265 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
19266 | + di_read_unlock(p->parent, AuLock_IR); | |
19267 | + iput(p->hdir->hi_inode); | |
19268 | + dput(p->parent); | |
19269 | + p->parent = NULL; | |
19270 | + p->hdir = NULL; | |
19271 | + p->h_mnt = NULL; | |
86dc4139 | 19272 | + /* do not clear p->task */ |
4a4d8108 | 19273 | +} |
1308ab2a | 19274 | + |
4a4d8108 AM |
19275 | +int au_do_pin(struct au_pin *p) |
19276 | +{ | |
19277 | + int err; | |
19278 | + struct super_block *sb; | |
4a4d8108 AM |
19279 | + struct inode *h_dir; |
19280 | + | |
19281 | + err = 0; | |
19282 | + sb = p->dentry->d_sb; | |
86dc4139 | 19283 | + p->br = au_sbr(sb, p->bindex); |
4a4d8108 AM |
19284 | + if (IS_ROOT(p->dentry)) { |
19285 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { | |
86dc4139 | 19286 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 19287 | + err = vfsub_mnt_want_write(p->h_mnt); |
4a4d8108 AM |
19288 | + if (unlikely(err)) { |
19289 | + au_fclr_pin(p->flags, MNT_WRITE); | |
19290 | + goto out_err; | |
19291 | + } | |
19292 | + } | |
dece6358 | 19293 | + goto out; |
1facf9fc | 19294 | + } |
19295 | + | |
86dc4139 | 19296 | + p->h_dentry = NULL; |
5afbbe0d | 19297 | + if (p->bindex <= au_dbbot(p->dentry)) |
86dc4139 | 19298 | + p->h_dentry = au_h_dptr(p->dentry, p->bindex); |
dece6358 | 19299 | + |
4a4d8108 AM |
19300 | + p->parent = dget_parent(p->dentry); |
19301 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) | |
19302 | + di_read_lock(p->parent, AuLock_IR, p->lsc_di); | |
dece6358 | 19303 | + |
4a4d8108 | 19304 | + h_dir = NULL; |
86dc4139 | 19305 | + p->h_parent = au_h_dptr(p->parent, p->bindex); |
5527c038 | 19306 | + p->hdir = au_hi(d_inode(p->parent), p->bindex); |
4a4d8108 AM |
19307 | + if (p->hdir) |
19308 | + h_dir = p->hdir->hi_inode; | |
dece6358 | 19309 | + |
b752ccd1 AM |
19310 | + /* |
19311 | + * udba case, or | |
19312 | + * if DI_LOCKED is not set, then p->parent may be different | |
19313 | + * and h_parent can be NULL. | |
19314 | + */ | |
86dc4139 | 19315 | + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) { |
e49829fe | 19316 | + err = -EBUSY; |
4a4d8108 AM |
19317 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
19318 | + di_read_unlock(p->parent, AuLock_IR); | |
19319 | + dput(p->parent); | |
19320 | + p->parent = NULL; | |
19321 | + goto out_err; | |
19322 | + } | |
1308ab2a | 19323 | + |
4a4d8108 | 19324 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { |
86dc4139 | 19325 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 19326 | + err = vfsub_mnt_want_write(p->h_mnt); |
dece6358 | 19327 | + if (unlikely(err)) { |
4a4d8108 | 19328 | + au_fclr_pin(p->flags, MNT_WRITE); |
86dc4139 AM |
19329 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
19330 | + di_read_unlock(p->parent, AuLock_IR); | |
19331 | + dput(p->parent); | |
19332 | + p->parent = NULL; | |
19333 | + goto out_err; | |
dece6358 AM |
19334 | + } |
19335 | + } | |
4a4d8108 | 19336 | + |
86dc4139 AM |
19337 | + au_igrab(h_dir); |
19338 | + err = au_pin_hdir_lock(p); | |
19339 | + if (!err) | |
19340 | + goto out; /* success */ | |
19341 | + | |
076b876e AM |
19342 | + au_unpin(p); |
19343 | + | |
4f0767ce | 19344 | +out_err: |
4a4d8108 AM |
19345 | + pr_err("err %d\n", err); |
19346 | + err = au_busy_or_stale(); | |
4f0767ce | 19347 | +out: |
1facf9fc | 19348 | + return err; |
19349 | +} | |
19350 | + | |
4a4d8108 AM |
19351 | +void au_pin_init(struct au_pin *p, struct dentry *dentry, |
19352 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
19353 | + unsigned int udba, unsigned char flags) | |
19354 | +{ | |
19355 | + p->dentry = dentry; | |
19356 | + p->udba = udba; | |
19357 | + p->lsc_di = lsc_di; | |
19358 | + p->lsc_hi = lsc_hi; | |
19359 | + p->flags = flags; | |
19360 | + p->bindex = bindex; | |
19361 | + | |
19362 | + p->parent = NULL; | |
19363 | + p->hdir = NULL; | |
19364 | + p->h_mnt = NULL; | |
86dc4139 AM |
19365 | + |
19366 | + p->h_dentry = NULL; | |
19367 | + p->h_parent = NULL; | |
19368 | + p->br = NULL; | |
19369 | + p->task = current; | |
4a4d8108 AM |
19370 | +} |
19371 | + | |
19372 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
19373 | + unsigned int udba, unsigned char flags) | |
19374 | +{ | |
19375 | + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2, | |
19376 | + udba, flags); | |
19377 | + return au_do_pin(pin); | |
19378 | +} | |
19379 | + | |
dece6358 AM |
19380 | +/* ---------------------------------------------------------------------- */ |
19381 | + | |
1308ab2a | 19382 | +/* |
4a4d8108 AM |
19383 | + * ->setattr() and ->getattr() are called in various cases. |
19384 | + * chmod, stat: dentry is revalidated. | |
19385 | + * fchmod, fstat: file and dentry are not revalidated, additionally they may be | |
19386 | + * unhashed. | |
19387 | + * for ->setattr(), ia->ia_file is passed from ftruncate only. | |
1308ab2a | 19388 | + */ |
027c5e7a | 19389 | +/* todo: consolidate with do_refresh() and simple_reval_dpath() */ |
c1595e42 | 19390 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen) |
1facf9fc | 19391 | +{ |
4a4d8108 | 19392 | + int err; |
4a4d8108 | 19393 | + struct dentry *parent; |
1facf9fc | 19394 | + |
1308ab2a | 19395 | + err = 0; |
027c5e7a | 19396 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 AM |
19397 | + parent = dget_parent(dentry); |
19398 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 19399 | + err = au_refresh_dentry(dentry, parent); |
4a4d8108 AM |
19400 | + di_read_unlock(parent, AuLock_IR); |
19401 | + dput(parent); | |
dece6358 | 19402 | + } |
1facf9fc | 19403 | + |
4a4d8108 | 19404 | + AuTraceErr(err); |
1308ab2a | 19405 | + return err; |
19406 | +} | |
dece6358 | 19407 | + |
c1595e42 JR |
19408 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, |
19409 | + struct au_icpup_args *a) | |
1308ab2a | 19410 | +{ |
19411 | + int err; | |
4a4d8108 | 19412 | + loff_t sz; |
5afbbe0d | 19413 | + aufs_bindex_t btop, ibtop; |
4a4d8108 AM |
19414 | + struct dentry *hi_wh, *parent; |
19415 | + struct inode *inode; | |
4a4d8108 AM |
19416 | + struct au_wr_dir_args wr_dir_args = { |
19417 | + .force_btgt = -1, | |
19418 | + .flags = 0 | |
19419 | + }; | |
19420 | + | |
2000de60 | 19421 | + if (d_is_dir(dentry)) |
4a4d8108 AM |
19422 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
19423 | + /* plink or hi_wh() case */ | |
5afbbe0d | 19424 | + btop = au_dbtop(dentry); |
5527c038 | 19425 | + inode = d_inode(dentry); |
5afbbe0d AM |
19426 | + ibtop = au_ibtop(inode); |
19427 | + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode)) | |
19428 | + wr_dir_args.force_btgt = ibtop; | |
4a4d8108 AM |
19429 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
19430 | + if (unlikely(err < 0)) | |
19431 | + goto out; | |
19432 | + a->btgt = err; | |
5afbbe0d | 19433 | + if (err != btop) |
4a4d8108 AM |
19434 | + au_fset_icpup(a->flags, DID_CPUP); |
19435 | + | |
19436 | + err = 0; | |
19437 | + a->pin_flags = AuPin_MNT_WRITE; | |
19438 | + parent = NULL; | |
19439 | + if (!IS_ROOT(dentry)) { | |
19440 | + au_fset_pin(a->pin_flags, DI_LOCKED); | |
19441 | + parent = dget_parent(dentry); | |
19442 | + di_write_lock_parent(parent); | |
19443 | + } | |
19444 | + | |
19445 | + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags); | |
19446 | + if (unlikely(err)) | |
19447 | + goto out_parent; | |
19448 | + | |
4a4d8108 | 19449 | + sz = -1; |
5afbbe0d | 19450 | + a->h_path.dentry = au_h_dptr(dentry, btop); |
5527c038 | 19451 | + a->h_inode = d_inode(a->h_path.dentry); |
c1595e42 | 19452 | + if (ia && (ia->ia_valid & ATTR_SIZE)) { |
febd17d6 | 19453 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
c1595e42 JR |
19454 | + if (ia->ia_size < i_size_read(a->h_inode)) |
19455 | + sz = ia->ia_size; | |
febd17d6 | 19456 | + inode_unlock(a->h_inode); |
c1595e42 | 19457 | + } |
4a4d8108 | 19458 | + |
4a4d8108 | 19459 | + hi_wh = NULL; |
027c5e7a | 19460 | + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) { |
4a4d8108 AM |
19461 | + hi_wh = au_hi_wh(inode, a->btgt); |
19462 | + if (!hi_wh) { | |
c2b27bf2 AM |
19463 | + struct au_cp_generic cpg = { |
19464 | + .dentry = dentry, | |
19465 | + .bdst = a->btgt, | |
19466 | + .bsrc = -1, | |
19467 | + .len = sz, | |
19468 | + .pin = &a->pin | |
19469 | + }; | |
19470 | + err = au_sio_cpup_wh(&cpg, /*file*/NULL); | |
4a4d8108 AM |
19471 | + if (unlikely(err)) |
19472 | + goto out_unlock; | |
19473 | + hi_wh = au_hi_wh(inode, a->btgt); | |
19474 | + /* todo: revalidate hi_wh? */ | |
19475 | + } | |
19476 | + } | |
19477 | + | |
19478 | + if (parent) { | |
19479 | + au_pin_set_parent_lflag(&a->pin, /*lflag*/0); | |
19480 | + di_downgrade_lock(parent, AuLock_IR); | |
19481 | + dput(parent); | |
19482 | + parent = NULL; | |
19483 | + } | |
19484 | + if (!au_ftest_icpup(a->flags, DID_CPUP)) | |
19485 | + goto out; /* success */ | |
19486 | + | |
19487 | + if (!d_unhashed(dentry)) { | |
c2b27bf2 AM |
19488 | + struct au_cp_generic cpg = { |
19489 | + .dentry = dentry, | |
19490 | + .bdst = a->btgt, | |
5afbbe0d | 19491 | + .bsrc = btop, |
c2b27bf2 AM |
19492 | + .len = sz, |
19493 | + .pin = &a->pin, | |
19494 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
19495 | + }; | |
19496 | + err = au_sio_cpup_simple(&cpg); | |
4a4d8108 AM |
19497 | + if (!err) |
19498 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
19499 | + } else if (!hi_wh) | |
19500 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
19501 | + else | |
19502 | + a->h_path.dentry = hi_wh; /* do not dget here */ | |
1308ab2a | 19503 | + |
4f0767ce | 19504 | +out_unlock: |
5527c038 | 19505 | + a->h_inode = d_inode(a->h_path.dentry); |
86dc4139 | 19506 | + if (!err) |
dece6358 | 19507 | + goto out; /* success */ |
4a4d8108 | 19508 | + au_unpin(&a->pin); |
4f0767ce | 19509 | +out_parent: |
4a4d8108 AM |
19510 | + if (parent) { |
19511 | + di_write_unlock(parent); | |
19512 | + dput(parent); | |
19513 | + } | |
4f0767ce | 19514 | +out: |
86dc4139 | 19515 | + if (!err) |
febd17d6 | 19516 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
1facf9fc | 19517 | + return err; |
19518 | +} | |
19519 | + | |
4a4d8108 | 19520 | +static int aufs_setattr(struct dentry *dentry, struct iattr *ia) |
1facf9fc | 19521 | +{ |
4a4d8108 | 19522 | + int err; |
523b37e3 | 19523 | + struct inode *inode, *delegated; |
4a4d8108 AM |
19524 | + struct super_block *sb; |
19525 | + struct file *file; | |
19526 | + struct au_icpup_args *a; | |
1facf9fc | 19527 | + |
5527c038 | 19528 | + inode = d_inode(dentry); |
4a4d8108 | 19529 | + IMustLock(inode); |
dece6358 | 19530 | + |
f2c43d5f AM |
19531 | + err = setattr_prepare(dentry, ia); |
19532 | + if (unlikely(err)) | |
19533 | + goto out; | |
19534 | + | |
4a4d8108 AM |
19535 | + err = -ENOMEM; |
19536 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
19537 | + if (unlikely(!a)) | |
19538 | + goto out; | |
1facf9fc | 19539 | + |
4a4d8108 AM |
19540 | + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
19541 | + ia->ia_valid &= ~ATTR_MODE; | |
dece6358 | 19542 | + |
4a4d8108 AM |
19543 | + file = NULL; |
19544 | + sb = dentry->d_sb; | |
e49829fe JR |
19545 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
19546 | + if (unlikely(err)) | |
19547 | + goto out_kfree; | |
19548 | + | |
4a4d8108 AM |
19549 | + if (ia->ia_valid & ATTR_FILE) { |
19550 | + /* currently ftruncate(2) only */ | |
7e9cd9fe | 19551 | + AuDebugOn(!d_is_reg(dentry)); |
4a4d8108 | 19552 | + file = ia->ia_file; |
521ced18 JR |
19553 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, |
19554 | + /*fi_lsc*/0); | |
4a4d8108 AM |
19555 | + if (unlikely(err)) |
19556 | + goto out_si; | |
19557 | + ia->ia_file = au_hf_top(file); | |
19558 | + a->udba = AuOpt_UDBA_NONE; | |
19559 | + } else { | |
19560 | + /* fchmod() doesn't pass ia_file */ | |
19561 | + a->udba = au_opt_udba(sb); | |
027c5e7a AM |
19562 | + di_write_lock_child(dentry); |
19563 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
4a4d8108 AM |
19564 | + if (d_unhashed(dentry)) |
19565 | + a->udba = AuOpt_UDBA_NONE; | |
4a4d8108 AM |
19566 | + if (a->udba != AuOpt_UDBA_NONE) { |
19567 | + AuDebugOn(IS_ROOT(dentry)); | |
19568 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
19569 | + if (unlikely(err)) | |
19570 | + goto out_dentry; | |
19571 | + } | |
dece6358 | 19572 | + } |
dece6358 | 19573 | + |
4a4d8108 AM |
19574 | + err = au_pin_and_icpup(dentry, ia, a); |
19575 | + if (unlikely(err < 0)) | |
19576 | + goto out_dentry; | |
19577 | + if (au_ftest_icpup(a->flags, DID_CPUP)) { | |
19578 | + ia->ia_file = NULL; | |
19579 | + ia->ia_valid &= ~ATTR_FILE; | |
1308ab2a | 19580 | + } |
dece6358 | 19581 | + |
4a4d8108 AM |
19582 | + a->h_path.mnt = au_sbr_mnt(sb, a->btgt); |
19583 | + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME)) | |
19584 | + == (ATTR_MODE | ATTR_CTIME)) { | |
7eafdf33 | 19585 | + err = security_path_chmod(&a->h_path, ia->ia_mode); |
4a4d8108 AM |
19586 | + if (unlikely(err)) |
19587 | + goto out_unlock; | |
19588 | + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID)) | |
19589 | + && (ia->ia_valid & ATTR_CTIME)) { | |
86dc4139 | 19590 | + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid); |
4a4d8108 AM |
19591 | + if (unlikely(err)) |
19592 | + goto out_unlock; | |
19593 | + } | |
dece6358 | 19594 | + |
4a4d8108 AM |
19595 | + if (ia->ia_valid & ATTR_SIZE) { |
19596 | + struct file *f; | |
1308ab2a | 19597 | + |
953406b4 | 19598 | + if (ia->ia_size < i_size_read(inode)) |
4a4d8108 | 19599 | + /* unmap only */ |
953406b4 | 19600 | + truncate_setsize(inode, ia->ia_size); |
1308ab2a | 19601 | + |
4a4d8108 AM |
19602 | + f = NULL; |
19603 | + if (ia->ia_valid & ATTR_FILE) | |
19604 | + f = ia->ia_file; | |
febd17d6 | 19605 | + inode_unlock(a->h_inode); |
4a4d8108 | 19606 | + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f); |
febd17d6 | 19607 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
523b37e3 AM |
19608 | + } else { |
19609 | + delegated = NULL; | |
19610 | + while (1) { | |
19611 | + err = vfsub_notify_change(&a->h_path, ia, &delegated); | |
19612 | + if (delegated) { | |
19613 | + err = break_deleg_wait(&delegated); | |
19614 | + if (!err) | |
19615 | + continue; | |
19616 | + } | |
19617 | + break; | |
19618 | + } | |
19619 | + } | |
8cdd5066 JR |
19620 | + /* |
19621 | + * regardless aufs 'acl' option setting. | |
19622 | + * why don't all acl-aware fs call this func from their ->setattr()? | |
19623 | + */ | |
19624 | + if (!err && (ia->ia_valid & ATTR_MODE)) | |
19625 | + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode); | |
4a4d8108 AM |
19626 | + if (!err) |
19627 | + au_cpup_attr_changeable(inode); | |
1308ab2a | 19628 | + |
4f0767ce | 19629 | +out_unlock: |
febd17d6 | 19630 | + inode_unlock(a->h_inode); |
4a4d8108 | 19631 | + au_unpin(&a->pin); |
027c5e7a | 19632 | + if (unlikely(err)) |
5afbbe0d | 19633 | + au_update_dbtop(dentry); |
4f0767ce | 19634 | +out_dentry: |
4a4d8108 AM |
19635 | + di_write_unlock(dentry); |
19636 | + if (file) { | |
19637 | + fi_write_unlock(file); | |
19638 | + ia->ia_file = file; | |
19639 | + ia->ia_valid |= ATTR_FILE; | |
19640 | + } | |
4f0767ce | 19641 | +out_si: |
4a4d8108 | 19642 | + si_read_unlock(sb); |
e49829fe | 19643 | +out_kfree: |
f0c0a007 | 19644 | + au_delayed_kfree(a); |
4f0767ce | 19645 | +out: |
4a4d8108 AM |
19646 | + AuTraceErr(err); |
19647 | + return err; | |
1facf9fc | 19648 | +} |
19649 | + | |
c1595e42 JR |
19650 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) |
19651 | +static int au_h_path_to_set_attr(struct dentry *dentry, | |
19652 | + struct au_icpup_args *a, struct path *h_path) | |
19653 | +{ | |
19654 | + int err; | |
19655 | + struct super_block *sb; | |
19656 | + | |
19657 | + sb = dentry->d_sb; | |
19658 | + a->udba = au_opt_udba(sb); | |
19659 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
19660 | + if (d_unhashed(dentry)) | |
19661 | + a->udba = AuOpt_UDBA_NONE; | |
19662 | + if (a->udba != AuOpt_UDBA_NONE) { | |
19663 | + AuDebugOn(IS_ROOT(dentry)); | |
19664 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
19665 | + if (unlikely(err)) | |
19666 | + goto out; | |
19667 | + } | |
19668 | + err = au_pin_and_icpup(dentry, /*ia*/NULL, a); | |
19669 | + if (unlikely(err < 0)) | |
19670 | + goto out; | |
19671 | + | |
19672 | + h_path->dentry = a->h_path.dentry; | |
19673 | + h_path->mnt = au_sbr_mnt(sb, a->btgt); | |
19674 | + | |
19675 | +out: | |
19676 | + return err; | |
19677 | +} | |
19678 | + | |
f2c43d5f AM |
19679 | +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode, |
19680 | + struct au_sxattr *arg) | |
c1595e42 JR |
19681 | +{ |
19682 | + int err; | |
19683 | + struct path h_path; | |
19684 | + struct super_block *sb; | |
19685 | + struct au_icpup_args *a; | |
5afbbe0d | 19686 | + struct inode *h_inode; |
c1595e42 | 19687 | + |
c1595e42 JR |
19688 | + IMustLock(inode); |
19689 | + | |
19690 | + err = -ENOMEM; | |
19691 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
19692 | + if (unlikely(!a)) | |
19693 | + goto out; | |
19694 | + | |
19695 | + sb = dentry->d_sb; | |
19696 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19697 | + if (unlikely(err)) | |
19698 | + goto out_kfree; | |
19699 | + | |
19700 | + h_path.dentry = NULL; /* silence gcc */ | |
19701 | + di_write_lock_child(dentry); | |
19702 | + err = au_h_path_to_set_attr(dentry, a, &h_path); | |
19703 | + if (unlikely(err)) | |
19704 | + goto out_di; | |
19705 | + | |
febd17d6 | 19706 | + inode_unlock(a->h_inode); |
c1595e42 JR |
19707 | + switch (arg->type) { |
19708 | + case AU_XATTR_SET: | |
5afbbe0d | 19709 | + AuDebugOn(d_is_negative(h_path.dentry)); |
c1595e42 JR |
19710 | + err = vfsub_setxattr(h_path.dentry, |
19711 | + arg->u.set.name, arg->u.set.value, | |
19712 | + arg->u.set.size, arg->u.set.flags); | |
19713 | + break; | |
c1595e42 JR |
19714 | + case AU_ACL_SET: |
19715 | + err = -EOPNOTSUPP; | |
5527c038 | 19716 | + h_inode = d_inode(h_path.dentry); |
c1595e42 | 19717 | + if (h_inode->i_op->set_acl) |
f2c43d5f | 19718 | + /* this will call posix_acl_update_mode */ |
c1595e42 JR |
19719 | + err = h_inode->i_op->set_acl(h_inode, |
19720 | + arg->u.acl_set.acl, | |
19721 | + arg->u.acl_set.type); | |
19722 | + break; | |
19723 | + } | |
19724 | + if (!err) | |
19725 | + au_cpup_attr_timesizes(inode); | |
19726 | + | |
19727 | + au_unpin(&a->pin); | |
19728 | + if (unlikely(err)) | |
5afbbe0d | 19729 | + au_update_dbtop(dentry); |
c1595e42 JR |
19730 | + |
19731 | +out_di: | |
19732 | + di_write_unlock(dentry); | |
19733 | + si_read_unlock(sb); | |
19734 | +out_kfree: | |
f0c0a007 | 19735 | + au_delayed_kfree(a); |
c1595e42 JR |
19736 | +out: |
19737 | + AuTraceErr(err); | |
19738 | + return err; | |
19739 | +} | |
19740 | +#endif | |
19741 | + | |
4a4d8108 AM |
19742 | +static void au_refresh_iattr(struct inode *inode, struct kstat *st, |
19743 | + unsigned int nlink) | |
1facf9fc | 19744 | +{ |
9dbd164d AM |
19745 | + unsigned int n; |
19746 | + | |
4a4d8108 | 19747 | + inode->i_mode = st->mode; |
86dc4139 AM |
19748 | + /* don't i_[ug]id_write() here */ |
19749 | + inode->i_uid = st->uid; | |
19750 | + inode->i_gid = st->gid; | |
4a4d8108 AM |
19751 | + inode->i_atime = st->atime; |
19752 | + inode->i_mtime = st->mtime; | |
19753 | + inode->i_ctime = st->ctime; | |
1facf9fc | 19754 | + |
4a4d8108 AM |
19755 | + au_cpup_attr_nlink(inode, /*force*/0); |
19756 | + if (S_ISDIR(inode->i_mode)) { | |
9dbd164d AM |
19757 | + n = inode->i_nlink; |
19758 | + n -= nlink; | |
19759 | + n += st->nlink; | |
f6b6e03d | 19760 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 19761 | + /* 0 can happen */ |
92d182d2 | 19762 | + set_nlink(inode, n); |
4a4d8108 | 19763 | + } |
1facf9fc | 19764 | + |
4a4d8108 AM |
19765 | + spin_lock(&inode->i_lock); |
19766 | + inode->i_blocks = st->blocks; | |
19767 | + i_size_write(inode, st->size); | |
19768 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 19769 | +} |
19770 | + | |
c1595e42 | 19771 | +/* |
f2c43d5f | 19772 | + * common routine for aufs_getattr() and au_getxattr(). |
c1595e42 JR |
19773 | + * returns zero or negative (an error). |
19774 | + * @dentry will be read-locked in success. | |
19775 | + */ | |
a2654f78 AM |
19776 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path, |
19777 | + int locked) | |
1facf9fc | 19778 | +{ |
4a4d8108 | 19779 | + int err; |
076b876e | 19780 | + unsigned int mnt_flags, sigen; |
c1595e42 | 19781 | + unsigned char udba_none; |
4a4d8108 | 19782 | + aufs_bindex_t bindex; |
4a4d8108 AM |
19783 | + struct super_block *sb, *h_sb; |
19784 | + struct inode *inode; | |
1facf9fc | 19785 | + |
c1595e42 JR |
19786 | + h_path->mnt = NULL; |
19787 | + h_path->dentry = NULL; | |
19788 | + | |
19789 | + err = 0; | |
4a4d8108 | 19790 | + sb = dentry->d_sb; |
4a4d8108 AM |
19791 | + mnt_flags = au_mntflags(sb); |
19792 | + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE); | |
1facf9fc | 19793 | + |
a2654f78 AM |
19794 | + if (unlikely(locked)) |
19795 | + goto body; /* skip locking dinfo */ | |
19796 | + | |
4a4d8108 | 19797 | + /* support fstat(2) */ |
027c5e7a | 19798 | + if (!d_unlinked(dentry) && !udba_none) { |
076b876e | 19799 | + sigen = au_sigen(sb); |
027c5e7a AM |
19800 | + err = au_digen_test(dentry, sigen); |
19801 | + if (!err) { | |
4a4d8108 | 19802 | + di_read_lock_child(dentry, AuLock_IR); |
027c5e7a | 19803 | + err = au_dbrange_test(dentry); |
c1595e42 JR |
19804 | + if (unlikely(err)) { |
19805 | + di_read_unlock(dentry, AuLock_IR); | |
19806 | + goto out; | |
19807 | + } | |
027c5e7a | 19808 | + } else { |
4a4d8108 AM |
19809 | + AuDebugOn(IS_ROOT(dentry)); |
19810 | + di_write_lock_child(dentry); | |
027c5e7a AM |
19811 | + err = au_dbrange_test(dentry); |
19812 | + if (!err) | |
19813 | + err = au_reval_for_attr(dentry, sigen); | |
c1595e42 JR |
19814 | + if (!err) |
19815 | + di_downgrade_lock(dentry, AuLock_IR); | |
19816 | + else { | |
19817 | + di_write_unlock(dentry); | |
19818 | + goto out; | |
19819 | + } | |
4a4d8108 AM |
19820 | + } |
19821 | + } else | |
19822 | + di_read_lock_child(dentry, AuLock_IR); | |
1facf9fc | 19823 | + |
a2654f78 | 19824 | +body: |
5527c038 | 19825 | + inode = d_inode(dentry); |
5afbbe0d | 19826 | + bindex = au_ibtop(inode); |
c1595e42 JR |
19827 | + h_path->mnt = au_sbr_mnt(sb, bindex); |
19828 | + h_sb = h_path->mnt->mnt_sb; | |
19829 | + if (!force | |
19830 | + && !au_test_fs_bad_iattr(h_sb) | |
19831 | + && udba_none) | |
19832 | + goto out; /* success */ | |
1facf9fc | 19833 | + |
5afbbe0d | 19834 | + if (au_dbtop(dentry) == bindex) |
c1595e42 | 19835 | + h_path->dentry = au_h_dptr(dentry, bindex); |
4a4d8108 | 19836 | + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) { |
c1595e42 JR |
19837 | + h_path->dentry = au_plink_lkup(inode, bindex); |
19838 | + if (IS_ERR(h_path->dentry)) | |
19839 | + /* pretending success */ | |
19840 | + h_path->dentry = NULL; | |
19841 | + else | |
19842 | + dput(h_path->dentry); | |
4a4d8108 | 19843 | + } |
c1595e42 JR |
19844 | + |
19845 | +out: | |
19846 | + return err; | |
19847 | +} | |
19848 | + | |
521ced18 JR |
19849 | +static int aufs_getattr(const struct path *path, struct kstat *st, |
19850 | + u32 request, unsigned int query) | |
c1595e42 JR |
19851 | +{ |
19852 | + int err; | |
19853 | + unsigned char positive; | |
19854 | + struct path h_path; | |
521ced18 | 19855 | + struct dentry *dentry; |
c1595e42 JR |
19856 | + struct inode *inode; |
19857 | + struct super_block *sb; | |
19858 | + | |
521ced18 | 19859 | + dentry = path->dentry; |
5527c038 | 19860 | + inode = d_inode(dentry); |
c1595e42 JR |
19861 | + sb = dentry->d_sb; |
19862 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19863 | + if (unlikely(err)) | |
19864 | + goto out; | |
a2654f78 | 19865 | + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0); |
c1595e42 JR |
19866 | + if (unlikely(err)) |
19867 | + goto out_si; | |
c06a8ce3 | 19868 | + if (unlikely(!h_path.dentry)) |
c1595e42 | 19869 | + /* illegally overlapped or something */ |
4a4d8108 AM |
19870 | + goto out_fill; /* pretending success */ |
19871 | + | |
5527c038 | 19872 | + positive = d_is_positive(h_path.dentry); |
4a4d8108 | 19873 | + if (positive) |
521ced18 JR |
19874 | + /* no vfsub version */ |
19875 | + err = vfs_getattr(&h_path, st, request, query); | |
4a4d8108 AM |
19876 | + if (!err) { |
19877 | + if (positive) | |
c06a8ce3 | 19878 | + au_refresh_iattr(inode, st, |
5527c038 | 19879 | + d_inode(h_path.dentry)->i_nlink); |
4a4d8108 | 19880 | + goto out_fill; /* success */ |
1facf9fc | 19881 | + } |
7f207e10 | 19882 | + AuTraceErr(err); |
c1595e42 | 19883 | + goto out_di; |
4a4d8108 | 19884 | + |
4f0767ce | 19885 | +out_fill: |
4a4d8108 | 19886 | + generic_fillattr(inode, st); |
c1595e42 | 19887 | +out_di: |
4a4d8108 | 19888 | + di_read_unlock(dentry, AuLock_IR); |
c1595e42 | 19889 | +out_si: |
4a4d8108 | 19890 | + si_read_unlock(sb); |
7f207e10 AM |
19891 | +out: |
19892 | + AuTraceErr(err); | |
4a4d8108 | 19893 | + return err; |
1facf9fc | 19894 | +} |
19895 | + | |
19896 | +/* ---------------------------------------------------------------------- */ | |
19897 | + | |
febd17d6 JR |
19898 | +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode, |
19899 | + struct delayed_call *done) | |
4a4d8108 | 19900 | +{ |
c2c0f25c | 19901 | + const char *ret; |
c2c0f25c | 19902 | + struct dentry *h_dentry; |
febd17d6 | 19903 | + struct inode *h_inode; |
4a4d8108 | 19904 | + int err; |
c2c0f25c | 19905 | + aufs_bindex_t bindex; |
1facf9fc | 19906 | + |
79b8bda9 | 19907 | + ret = NULL; /* suppress a warning */ |
febd17d6 JR |
19908 | + err = -ECHILD; |
19909 | + if (!dentry) | |
19910 | + goto out; | |
19911 | + | |
027c5e7a AM |
19912 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
19913 | + if (unlikely(err)) | |
c2c0f25c | 19914 | + goto out; |
027c5e7a AM |
19915 | + |
19916 | + err = au_d_hashed_positive(dentry); | |
c2c0f25c AM |
19917 | + if (unlikely(err)) |
19918 | + goto out_unlock; | |
19919 | + | |
19920 | + err = -EINVAL; | |
19921 | + inode = d_inode(dentry); | |
5afbbe0d | 19922 | + bindex = au_ibtop(inode); |
c2c0f25c | 19923 | + h_inode = au_h_iptr(inode, bindex); |
febd17d6 | 19924 | + if (unlikely(!h_inode->i_op->get_link)) |
c2c0f25c AM |
19925 | + goto out_unlock; |
19926 | + | |
19927 | + err = -EBUSY; | |
19928 | + h_dentry = NULL; | |
5afbbe0d | 19929 | + if (au_dbtop(dentry) <= bindex) { |
c2c0f25c AM |
19930 | + h_dentry = au_h_dptr(dentry, bindex); |
19931 | + if (h_dentry) | |
19932 | + dget(h_dentry); | |
027c5e7a | 19933 | + } |
c2c0f25c AM |
19934 | + if (!h_dentry) { |
19935 | + h_dentry = d_find_any_alias(h_inode); | |
19936 | + if (IS_ERR(h_dentry)) { | |
19937 | + err = PTR_ERR(h_dentry); | |
febd17d6 | 19938 | + goto out_unlock; |
c2c0f25c AM |
19939 | + } |
19940 | + } | |
19941 | + if (unlikely(!h_dentry)) | |
febd17d6 | 19942 | + goto out_unlock; |
1facf9fc | 19943 | + |
c2c0f25c | 19944 | + err = 0; |
febd17d6 | 19945 | + AuDbg("%pf\n", h_inode->i_op->get_link); |
c2c0f25c | 19946 | + AuDbgDentry(h_dentry); |
f2c43d5f | 19947 | + ret = vfs_get_link(h_dentry, done); |
c2c0f25c | 19948 | + dput(h_dentry); |
febd17d6 JR |
19949 | + if (IS_ERR(ret)) |
19950 | + err = PTR_ERR(ret); | |
c2c0f25c | 19951 | + |
c2c0f25c AM |
19952 | +out_unlock: |
19953 | + aufs_read_unlock(dentry, AuLock_IR); | |
4f0767ce | 19954 | +out: |
c2c0f25c AM |
19955 | + if (unlikely(err)) |
19956 | + ret = ERR_PTR(err); | |
19957 | + AuTraceErrPtr(ret); | |
19958 | + return ret; | |
4a4d8108 | 19959 | +} |
1facf9fc | 19960 | + |
4a4d8108 | 19961 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19962 | + |
e2f27e51 AM |
19963 | +static int au_is_special(struct inode *inode) |
19964 | +{ | |
19965 | + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK)); | |
19966 | +} | |
19967 | + | |
0c3ec466 | 19968 | +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags) |
4a4d8108 | 19969 | +{ |
0c3ec466 | 19970 | + int err; |
e2f27e51 | 19971 | + aufs_bindex_t bindex; |
0c3ec466 AM |
19972 | + struct super_block *sb; |
19973 | + struct inode *h_inode; | |
e2f27e51 | 19974 | + struct vfsmount *h_mnt; |
0c3ec466 AM |
19975 | + |
19976 | + sb = inode->i_sb; | |
e2f27e51 AM |
19977 | + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode), |
19978 | + "unexpected s_flags 0x%lx", sb->s_flags); | |
19979 | + | |
0c3ec466 AM |
19980 | + /* mmap_sem might be acquired already, cf. aufs_mmap() */ |
19981 | + lockdep_off(); | |
19982 | + si_read_lock(sb, AuLock_FLUSH); | |
19983 | + ii_write_lock_child(inode); | |
19984 | + lockdep_on(); | |
e2f27e51 AM |
19985 | + |
19986 | + err = 0; | |
19987 | + bindex = au_ibtop(inode); | |
19988 | + h_inode = au_h_iptr(inode, bindex); | |
19989 | + if (!au_test_ro(sb, bindex, inode)) { | |
19990 | + h_mnt = au_sbr_mnt(sb, bindex); | |
19991 | + err = vfsub_mnt_want_write(h_mnt); | |
19992 | + if (!err) { | |
19993 | + err = vfsub_update_time(h_inode, ts, flags); | |
19994 | + vfsub_mnt_drop_write(h_mnt); | |
19995 | + } | |
19996 | + } else if (au_is_special(h_inode)) { | |
19997 | + /* | |
19998 | + * Never copy-up here. | |
19999 | + * These special files may already be opened and used for | |
20000 | + * communicating. If we copied it up, then the communication | |
20001 | + * would be corrupted. | |
20002 | + */ | |
20003 | + AuWarn1("timestamps for i%lu are ignored " | |
20004 | + "since it is on readonly branch (hi%lu).\n", | |
20005 | + inode->i_ino, h_inode->i_ino); | |
20006 | + } else if (flags & ~S_ATIME) { | |
20007 | + err = -EIO; | |
20008 | + AuIOErr1("unexpected flags 0x%x\n", flags); | |
20009 | + AuDebugOn(1); | |
20010 | + } | |
20011 | + | |
0c3ec466 | 20012 | + lockdep_off(); |
38d290e6 JR |
20013 | + if (!err) |
20014 | + au_cpup_attr_timesizes(inode); | |
0c3ec466 AM |
20015 | + ii_write_unlock(inode); |
20016 | + si_read_unlock(sb); | |
20017 | + lockdep_on(); | |
38d290e6 JR |
20018 | + |
20019 | + if (!err && (flags & S_VERSION)) | |
20020 | + inode_inc_iversion(inode); | |
20021 | + | |
0c3ec466 | 20022 | + return err; |
4a4d8108 | 20023 | +} |
1facf9fc | 20024 | + |
4a4d8108 | 20025 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 20026 | + |
b95c5147 AM |
20027 | +/* no getattr version will be set by module.c:aufs_init() */ |
20028 | +struct inode_operations aufs_iop_nogetattr[AuIop_Last], | |
20029 | + aufs_iop[] = { | |
20030 | + [AuIop_SYMLINK] = { | |
20031 | + .permission = aufs_permission, | |
c1595e42 | 20032 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
20033 | + .get_acl = aufs_get_acl, |
20034 | + .set_acl = aufs_set_acl, /* unsupport for symlink? */ | |
c1595e42 JR |
20035 | +#endif |
20036 | + | |
b95c5147 AM |
20037 | + .setattr = aufs_setattr, |
20038 | + .getattr = aufs_getattr, | |
0c3ec466 | 20039 | + |
c1595e42 | 20040 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 20041 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
20042 | +#endif |
20043 | + | |
febd17d6 | 20044 | + .get_link = aufs_get_link, |
0c3ec466 | 20045 | + |
b95c5147 AM |
20046 | + /* .update_time = aufs_update_time */ |
20047 | + }, | |
20048 | + [AuIop_DIR] = { | |
20049 | + .create = aufs_create, | |
20050 | + .lookup = aufs_lookup, | |
20051 | + .link = aufs_link, | |
20052 | + .unlink = aufs_unlink, | |
20053 | + .symlink = aufs_symlink, | |
20054 | + .mkdir = aufs_mkdir, | |
20055 | + .rmdir = aufs_rmdir, | |
20056 | + .mknod = aufs_mknod, | |
20057 | + .rename = aufs_rename, | |
20058 | + | |
20059 | + .permission = aufs_permission, | |
c1595e42 | 20060 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
20061 | + .get_acl = aufs_get_acl, |
20062 | + .set_acl = aufs_set_acl, | |
c1595e42 JR |
20063 | +#endif |
20064 | + | |
b95c5147 AM |
20065 | + .setattr = aufs_setattr, |
20066 | + .getattr = aufs_getattr, | |
0c3ec466 | 20067 | + |
c1595e42 | 20068 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 20069 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
20070 | +#endif |
20071 | + | |
b95c5147 AM |
20072 | + .update_time = aufs_update_time, |
20073 | + .atomic_open = aufs_atomic_open, | |
20074 | + .tmpfile = aufs_tmpfile | |
20075 | + }, | |
20076 | + [AuIop_OTHER] = { | |
20077 | + .permission = aufs_permission, | |
c1595e42 | 20078 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
20079 | + .get_acl = aufs_get_acl, |
20080 | + .set_acl = aufs_set_acl, | |
c1595e42 JR |
20081 | +#endif |
20082 | + | |
b95c5147 AM |
20083 | + .setattr = aufs_setattr, |
20084 | + .getattr = aufs_getattr, | |
0c3ec466 | 20085 | + |
c1595e42 | 20086 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 20087 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
20088 | +#endif |
20089 | + | |
b95c5147 AM |
20090 | + .update_time = aufs_update_time |
20091 | + } | |
4a4d8108 | 20092 | +}; |
7f207e10 AM |
20093 | diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c |
20094 | --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 20095 | +++ linux/fs/aufs/i_op_del.c 2017-05-06 22:16:52.778220093 +0200 |
5afbbe0d | 20096 | @@ -0,0 +1,511 @@ |
1facf9fc | 20097 | +/* |
a2654f78 | 20098 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 20099 | + * |
20100 | + * This program, aufs is free software; you can redistribute it and/or modify | |
20101 | + * it under the terms of the GNU General Public License as published by | |
20102 | + * the Free Software Foundation; either version 2 of the License, or | |
20103 | + * (at your option) any later version. | |
dece6358 AM |
20104 | + * |
20105 | + * This program is distributed in the hope that it will be useful, | |
20106 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20107 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20108 | + * GNU General Public License for more details. | |
20109 | + * | |
20110 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 20111 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 20112 | + */ |
20113 | + | |
20114 | +/* | |
4a4d8108 | 20115 | + * inode operations (del entry) |
1308ab2a | 20116 | + */ |
dece6358 | 20117 | + |
1308ab2a | 20118 | +#include "aufs.h" |
dece6358 | 20119 | + |
4a4d8108 AM |
20120 | +/* |
20121 | + * decide if a new whiteout for @dentry is necessary or not. | |
20122 | + * when it is necessary, prepare the parent dir for the upper branch whose | |
20123 | + * branch index is @bcpup for creation. the actual creation of the whiteout will | |
20124 | + * be done by caller. | |
20125 | + * return value: | |
20126 | + * 0: wh is unnecessary | |
20127 | + * plus: wh is necessary | |
20128 | + * minus: error | |
20129 | + */ | |
20130 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup) | |
1308ab2a | 20131 | +{ |
4a4d8108 | 20132 | + int need_wh, err; |
5afbbe0d | 20133 | + aufs_bindex_t btop; |
4a4d8108 | 20134 | + struct super_block *sb; |
dece6358 | 20135 | + |
4a4d8108 | 20136 | + sb = dentry->d_sb; |
5afbbe0d | 20137 | + btop = au_dbtop(dentry); |
4a4d8108 | 20138 | + if (*bcpup < 0) { |
5afbbe0d AM |
20139 | + *bcpup = btop; |
20140 | + if (au_test_ro(sb, btop, d_inode(dentry))) { | |
4a4d8108 AM |
20141 | + err = AuWbrCopyup(au_sbi(sb), dentry); |
20142 | + *bcpup = err; | |
20143 | + if (unlikely(err < 0)) | |
20144 | + goto out; | |
20145 | + } | |
20146 | + } else | |
5afbbe0d | 20147 | + AuDebugOn(btop < *bcpup |
5527c038 | 20148 | + || au_test_ro(sb, *bcpup, d_inode(dentry))); |
5afbbe0d | 20149 | + AuDbg("bcpup %d, btop %d\n", *bcpup, btop); |
1308ab2a | 20150 | + |
5afbbe0d | 20151 | + if (*bcpup != btop) { |
4a4d8108 AM |
20152 | + err = au_cpup_dirs(dentry, *bcpup); |
20153 | + if (unlikely(err)) | |
20154 | + goto out; | |
20155 | + need_wh = 1; | |
20156 | + } else { | |
027c5e7a | 20157 | + struct au_dinfo *dinfo, *tmp; |
4a4d8108 | 20158 | + |
027c5e7a AM |
20159 | + need_wh = -ENOMEM; |
20160 | + dinfo = au_di(dentry); | |
20161 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
20162 | + if (tmp) { | |
20163 | + au_di_cp(tmp, dinfo); | |
20164 | + au_di_swap(tmp, dinfo); | |
20165 | + /* returns the number of positive dentries */ | |
5afbbe0d AM |
20166 | + need_wh = au_lkup_dentry(dentry, btop + 1, |
20167 | + /* AuLkup_IGNORE_PERM */ 0); | |
027c5e7a AM |
20168 | + au_di_swap(tmp, dinfo); |
20169 | + au_rw_write_unlock(&tmp->di_rwsem); | |
20170 | + au_di_free(tmp); | |
4a4d8108 AM |
20171 | + } |
20172 | + } | |
20173 | + AuDbg("need_wh %d\n", need_wh); | |
20174 | + err = need_wh; | |
20175 | + | |
4f0767ce | 20176 | +out: |
4a4d8108 | 20177 | + return err; |
1facf9fc | 20178 | +} |
20179 | + | |
4a4d8108 AM |
20180 | +/* |
20181 | + * simple tests for the del-entry operations. | |
20182 | + * following the checks in vfs, plus the parent-child relationship. | |
20183 | + */ | |
20184 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
20185 | + struct dentry *h_parent, int isdir) | |
1facf9fc | 20186 | +{ |
4a4d8108 AM |
20187 | + int err; |
20188 | + umode_t h_mode; | |
20189 | + struct dentry *h_dentry, *h_latest; | |
1308ab2a | 20190 | + struct inode *h_inode; |
1facf9fc | 20191 | + |
4a4d8108 | 20192 | + h_dentry = au_h_dptr(dentry, bindex); |
5527c038 | 20193 | + if (d_really_is_positive(dentry)) { |
4a4d8108 | 20194 | + err = -ENOENT; |
5527c038 JR |
20195 | + if (unlikely(d_is_negative(h_dentry))) |
20196 | + goto out; | |
20197 | + h_inode = d_inode(h_dentry); | |
20198 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 | 20199 | + goto out; |
1facf9fc | 20200 | + |
4a4d8108 AM |
20201 | + h_mode = h_inode->i_mode; |
20202 | + if (!isdir) { | |
20203 | + err = -EISDIR; | |
20204 | + if (unlikely(S_ISDIR(h_mode))) | |
20205 | + goto out; | |
20206 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
20207 | + err = -ENOTDIR; | |
20208 | + goto out; | |
20209 | + } | |
20210 | + } else { | |
20211 | + /* rename(2) case */ | |
20212 | + err = -EIO; | |
5527c038 | 20213 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
20214 | + goto out; |
20215 | + } | |
1facf9fc | 20216 | + |
4a4d8108 AM |
20217 | + err = -ENOENT; |
20218 | + /* expected parent dir is locked */ | |
20219 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
20220 | + goto out; | |
20221 | + err = 0; | |
20222 | + | |
20223 | + /* | |
20224 | + * rmdir a dir may break the consistency on some filesystem. | |
20225 | + * let's try heavy test. | |
20226 | + */ | |
20227 | + err = -EACCES; | |
076b876e | 20228 | + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1) |
5527c038 | 20229 | + && au_test_h_perm(d_inode(h_parent), |
076b876e | 20230 | + MAY_EXEC | MAY_WRITE))) |
4a4d8108 AM |
20231 | + goto out; |
20232 | + | |
076b876e | 20233 | + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent); |
4a4d8108 AM |
20234 | + err = -EIO; |
20235 | + if (IS_ERR(h_latest)) | |
20236 | + goto out; | |
20237 | + if (h_latest == h_dentry) | |
20238 | + err = 0; | |
20239 | + dput(h_latest); | |
20240 | + | |
4f0767ce | 20241 | +out: |
4a4d8108 | 20242 | + return err; |
1308ab2a | 20243 | +} |
1facf9fc | 20244 | + |
4a4d8108 AM |
20245 | +/* |
20246 | + * decide the branch where we operate for @dentry. the branch index will be set | |
20247 | + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent | |
20248 | + * dir for reverting. | |
20249 | + * when a new whiteout is necessary, create it. | |
20250 | + */ | |
20251 | +static struct dentry* | |
20252 | +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup, | |
20253 | + struct au_dtime *dt, struct au_pin *pin) | |
1308ab2a | 20254 | +{ |
4a4d8108 AM |
20255 | + struct dentry *wh_dentry; |
20256 | + struct super_block *sb; | |
20257 | + struct path h_path; | |
20258 | + int err, need_wh; | |
20259 | + unsigned int udba; | |
20260 | + aufs_bindex_t bcpup; | |
dece6358 | 20261 | + |
4a4d8108 AM |
20262 | + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup); |
20263 | + wh_dentry = ERR_PTR(need_wh); | |
20264 | + if (unlikely(need_wh < 0)) | |
20265 | + goto out; | |
20266 | + | |
20267 | + sb = dentry->d_sb; | |
20268 | + udba = au_opt_udba(sb); | |
20269 | + bcpup = *rbcpup; | |
20270 | + err = au_pin(pin, dentry, bcpup, udba, | |
20271 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
20272 | + wh_dentry = ERR_PTR(err); | |
20273 | + if (unlikely(err)) | |
20274 | + goto out; | |
20275 | + | |
20276 | + h_path.dentry = au_pinned_h_parent(pin); | |
20277 | + if (udba != AuOpt_UDBA_NONE | |
5afbbe0d | 20278 | + && au_dbtop(dentry) == bcpup) { |
4a4d8108 AM |
20279 | + err = au_may_del(dentry, bcpup, h_path.dentry, isdir); |
20280 | + wh_dentry = ERR_PTR(err); | |
20281 | + if (unlikely(err)) | |
20282 | + goto out_unpin; | |
20283 | + } | |
20284 | + | |
20285 | + h_path.mnt = au_sbr_mnt(sb, bcpup); | |
20286 | + au_dtime_store(dt, au_pinned_parent(pin), &h_path); | |
20287 | + wh_dentry = NULL; | |
20288 | + if (!need_wh) | |
20289 | + goto out; /* success, no need to create whiteout */ | |
20290 | + | |
20291 | + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry); | |
20292 | + if (IS_ERR(wh_dentry)) | |
20293 | + goto out_unpin; | |
20294 | + | |
20295 | + /* returns with the parent is locked and wh_dentry is dget-ed */ | |
20296 | + goto out; /* success */ | |
20297 | + | |
4f0767ce | 20298 | +out_unpin: |
4a4d8108 | 20299 | + au_unpin(pin); |
4f0767ce | 20300 | +out: |
4a4d8108 | 20301 | + return wh_dentry; |
1facf9fc | 20302 | +} |
20303 | + | |
4a4d8108 AM |
20304 | +/* |
20305 | + * when removing a dir, rename it to a unique temporary whiteout-ed name first | |
20306 | + * in order to be revertible and save time for removing many child whiteouts | |
20307 | + * under the dir. | |
20308 | + * returns 1 when there are too many child whiteout and caller should remove | |
20309 | + * them asynchronously. returns 0 when the number of children is enough small to | |
20310 | + * remove now or the branch fs is a remote fs. | |
20311 | + * otherwise return an error. | |
20312 | + */ | |
20313 | +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex, | |
20314 | + struct au_nhash *whlist, struct inode *dir) | |
1facf9fc | 20315 | +{ |
4a4d8108 AM |
20316 | + int rmdir_later, err, dirwh; |
20317 | + struct dentry *h_dentry; | |
20318 | + struct super_block *sb; | |
5527c038 | 20319 | + struct inode *inode; |
4a4d8108 AM |
20320 | + |
20321 | + sb = dentry->d_sb; | |
20322 | + SiMustAnyLock(sb); | |
20323 | + h_dentry = au_h_dptr(dentry, bindex); | |
20324 | + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex)); | |
20325 | + if (unlikely(err)) | |
20326 | + goto out; | |
20327 | + | |
20328 | + /* stop monitoring */ | |
5527c038 JR |
20329 | + inode = d_inode(dentry); |
20330 | + au_hn_free(au_hi(inode, bindex)); | |
4a4d8108 AM |
20331 | + |
20332 | + if (!au_test_fs_remote(h_dentry->d_sb)) { | |
20333 | + dirwh = au_sbi(sb)->si_dirwh; | |
20334 | + rmdir_later = (dirwh <= 1); | |
20335 | + if (!rmdir_later) | |
20336 | + rmdir_later = au_nhash_test_longer_wh(whlist, bindex, | |
20337 | + dirwh); | |
20338 | + if (rmdir_later) | |
20339 | + return rmdir_later; | |
20340 | + } | |
1facf9fc | 20341 | + |
4a4d8108 AM |
20342 | + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist); |
20343 | + if (unlikely(err)) { | |
523b37e3 AM |
20344 | + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n", |
20345 | + h_dentry, bindex, err); | |
4a4d8108 AM |
20346 | + err = 0; |
20347 | + } | |
dece6358 | 20348 | + |
4f0767ce | 20349 | +out: |
4a4d8108 AM |
20350 | + AuTraceErr(err); |
20351 | + return err; | |
20352 | +} | |
1308ab2a | 20353 | + |
4a4d8108 AM |
20354 | +/* |
20355 | + * final procedure for deleting a entry. | |
20356 | + * maintain dentry and iattr. | |
20357 | + */ | |
20358 | +static void epilog(struct inode *dir, struct dentry *dentry, | |
20359 | + aufs_bindex_t bindex) | |
20360 | +{ | |
20361 | + struct inode *inode; | |
1308ab2a | 20362 | + |
5527c038 | 20363 | + inode = d_inode(dentry); |
4a4d8108 AM |
20364 | + d_drop(dentry); |
20365 | + inode->i_ctime = dir->i_ctime; | |
1308ab2a | 20366 | + |
b912730e | 20367 | + au_dir_ts(dir, bindex); |
4a4d8108 | 20368 | + dir->i_version++; |
1facf9fc | 20369 | +} |
20370 | + | |
4a4d8108 AM |
20371 | +/* |
20372 | + * when an error happened, remove the created whiteout and revert everything. | |
20373 | + */ | |
7f207e10 AM |
20374 | +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex, |
20375 | + aufs_bindex_t bwh, struct dentry *wh_dentry, | |
20376 | + struct dentry *dentry, struct au_dtime *dt) | |
1facf9fc | 20377 | +{ |
4a4d8108 AM |
20378 | + int rerr; |
20379 | + struct path h_path = { | |
20380 | + .dentry = wh_dentry, | |
7f207e10 | 20381 | + .mnt = au_sbr_mnt(dir->i_sb, bindex) |
4a4d8108 | 20382 | + }; |
dece6358 | 20383 | + |
7f207e10 | 20384 | + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry); |
4a4d8108 AM |
20385 | + if (!rerr) { |
20386 | + au_set_dbwh(dentry, bwh); | |
20387 | + au_dtime_revert(dt); | |
20388 | + return 0; | |
20389 | + } | |
dece6358 | 20390 | + |
523b37e3 | 20391 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr); |
4a4d8108 | 20392 | + return -EIO; |
1facf9fc | 20393 | +} |
20394 | + | |
4a4d8108 | 20395 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20396 | + |
4a4d8108 | 20397 | +int aufs_unlink(struct inode *dir, struct dentry *dentry) |
1308ab2a | 20398 | +{ |
4a4d8108 | 20399 | + int err; |
5afbbe0d | 20400 | + aufs_bindex_t bwh, bindex, btop; |
523b37e3 | 20401 | + struct inode *inode, *h_dir, *delegated; |
4a4d8108 | 20402 | + struct dentry *parent, *wh_dentry; |
c2b27bf2 AM |
20403 | + /* to reuduce stack size */ |
20404 | + struct { | |
20405 | + struct au_dtime dt; | |
20406 | + struct au_pin pin; | |
20407 | + struct path h_path; | |
20408 | + } *a; | |
1facf9fc | 20409 | + |
4a4d8108 | 20410 | + IMustLock(dir); |
027c5e7a | 20411 | + |
c2b27bf2 AM |
20412 | + err = -ENOMEM; |
20413 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
20414 | + if (unlikely(!a)) | |
20415 | + goto out; | |
20416 | + | |
027c5e7a AM |
20417 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
20418 | + if (unlikely(err)) | |
c2b27bf2 | 20419 | + goto out_free; |
027c5e7a AM |
20420 | + err = au_d_hashed_positive(dentry); |
20421 | + if (unlikely(err)) | |
20422 | + goto out_unlock; | |
5527c038 | 20423 | + inode = d_inode(dentry); |
4a4d8108 | 20424 | + IMustLock(inode); |
027c5e7a | 20425 | + err = -EISDIR; |
2000de60 | 20426 | + if (unlikely(d_is_dir(dentry))) |
027c5e7a | 20427 | + goto out_unlock; /* possible? */ |
1facf9fc | 20428 | + |
5afbbe0d | 20429 | + btop = au_dbtop(dentry); |
4a4d8108 AM |
20430 | + bwh = au_dbwh(dentry); |
20431 | + bindex = -1; | |
027c5e7a AM |
20432 | + parent = dentry->d_parent; /* dir inode is locked */ |
20433 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
20434 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt, |
20435 | + &a->pin); | |
4a4d8108 AM |
20436 | + err = PTR_ERR(wh_dentry); |
20437 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20438 | + goto out_parent; |
1facf9fc | 20439 | + |
5afbbe0d AM |
20440 | + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop); |
20441 | + a->h_path.dentry = au_h_dptr(dentry, btop); | |
c2b27bf2 | 20442 | + dget(a->h_path.dentry); |
5afbbe0d | 20443 | + if (bindex == btop) { |
c2b27bf2 | 20444 | + h_dir = au_pinned_h_dir(&a->pin); |
523b37e3 AM |
20445 | + delegated = NULL; |
20446 | + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0); | |
20447 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20448 | + pr_warn("cannot retry for NFSv4 delegation" | |
20449 | + " for an internal unlink\n"); | |
20450 | + iput(delegated); | |
20451 | + } | |
4a4d8108 AM |
20452 | + } else { |
20453 | + /* dir inode is locked */ | |
5527c038 | 20454 | + h_dir = d_inode(wh_dentry->d_parent); |
4a4d8108 AM |
20455 | + IMustLock(h_dir); |
20456 | + err = 0; | |
20457 | + } | |
dece6358 | 20458 | + |
4a4d8108 | 20459 | + if (!err) { |
7f207e10 | 20460 | + vfsub_drop_nlink(inode); |
4a4d8108 AM |
20461 | + epilog(dir, dentry, bindex); |
20462 | + | |
20463 | + /* update target timestamps */ | |
5afbbe0d | 20464 | + if (bindex == btop) { |
c2b27bf2 AM |
20465 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); |
20466 | + /*ignore*/ | |
5527c038 | 20467 | + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
4a4d8108 AM |
20468 | + } else |
20469 | + /* todo: this timestamp may be reverted later */ | |
20470 | + inode->i_ctime = h_dir->i_ctime; | |
027c5e7a | 20471 | + goto out_unpin; /* success */ |
1facf9fc | 20472 | + } |
20473 | + | |
4a4d8108 AM |
20474 | + /* revert */ |
20475 | + if (wh_dentry) { | |
20476 | + int rerr; | |
20477 | + | |
c2b27bf2 AM |
20478 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
20479 | + &a->dt); | |
4a4d8108 AM |
20480 | + if (rerr) |
20481 | + err = rerr; | |
dece6358 | 20482 | + } |
1facf9fc | 20483 | + |
027c5e7a | 20484 | +out_unpin: |
c2b27bf2 | 20485 | + au_unpin(&a->pin); |
4a4d8108 | 20486 | + dput(wh_dentry); |
c2b27bf2 | 20487 | + dput(a->h_path.dentry); |
027c5e7a | 20488 | +out_parent: |
4a4d8108 | 20489 | + di_write_unlock(parent); |
027c5e7a | 20490 | +out_unlock: |
4a4d8108 | 20491 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 | 20492 | +out_free: |
f0c0a007 | 20493 | + au_delayed_kfree(a); |
027c5e7a | 20494 | +out: |
4a4d8108 | 20495 | + return err; |
dece6358 AM |
20496 | +} |
20497 | + | |
4a4d8108 | 20498 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry) |
1308ab2a | 20499 | +{ |
4a4d8108 | 20500 | + int err, rmdir_later; |
5afbbe0d | 20501 | + aufs_bindex_t bwh, bindex, btop; |
4a4d8108 AM |
20502 | + struct inode *inode; |
20503 | + struct dentry *parent, *wh_dentry, *h_dentry; | |
20504 | + struct au_whtmp_rmdir *args; | |
c2b27bf2 AM |
20505 | + /* to reuduce stack size */ |
20506 | + struct { | |
20507 | + struct au_dtime dt; | |
20508 | + struct au_pin pin; | |
20509 | + } *a; | |
1facf9fc | 20510 | + |
4a4d8108 | 20511 | + IMustLock(dir); |
027c5e7a | 20512 | + |
c2b27bf2 AM |
20513 | + err = -ENOMEM; |
20514 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
20515 | + if (unlikely(!a)) | |
20516 | + goto out; | |
20517 | + | |
027c5e7a AM |
20518 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); |
20519 | + if (unlikely(err)) | |
c2b27bf2 | 20520 | + goto out_free; |
53392da6 AM |
20521 | + err = au_alive_dir(dentry); |
20522 | + if (unlikely(err)) | |
027c5e7a | 20523 | + goto out_unlock; |
5527c038 | 20524 | + inode = d_inode(dentry); |
4a4d8108 | 20525 | + IMustLock(inode); |
027c5e7a | 20526 | + err = -ENOTDIR; |
2000de60 | 20527 | + if (unlikely(!d_is_dir(dentry))) |
027c5e7a | 20528 | + goto out_unlock; /* possible? */ |
dece6358 | 20529 | + |
4a4d8108 AM |
20530 | + err = -ENOMEM; |
20531 | + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS); | |
20532 | + if (unlikely(!args)) | |
20533 | + goto out_unlock; | |
dece6358 | 20534 | + |
4a4d8108 AM |
20535 | + parent = dentry->d_parent; /* dir inode is locked */ |
20536 | + di_write_lock_parent(parent); | |
20537 | + err = au_test_empty(dentry, &args->whlist); | |
20538 | + if (unlikely(err)) | |
027c5e7a | 20539 | + goto out_parent; |
1facf9fc | 20540 | + |
5afbbe0d | 20541 | + btop = au_dbtop(dentry); |
4a4d8108 AM |
20542 | + bwh = au_dbwh(dentry); |
20543 | + bindex = -1; | |
c2b27bf2 AM |
20544 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt, |
20545 | + &a->pin); | |
4a4d8108 AM |
20546 | + err = PTR_ERR(wh_dentry); |
20547 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20548 | + goto out_parent; |
1facf9fc | 20549 | + |
5afbbe0d | 20550 | + h_dentry = au_h_dptr(dentry, btop); |
4a4d8108 AM |
20551 | + dget(h_dentry); |
20552 | + rmdir_later = 0; | |
5afbbe0d AM |
20553 | + if (bindex == btop) { |
20554 | + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir); | |
4a4d8108 AM |
20555 | + if (err > 0) { |
20556 | + rmdir_later = err; | |
20557 | + err = 0; | |
20558 | + } | |
20559 | + } else { | |
20560 | + /* stop monitoring */ | |
5afbbe0d | 20561 | + au_hn_free(au_hi(inode, btop)); |
4a4d8108 AM |
20562 | + |
20563 | + /* dir inode is locked */ | |
5527c038 | 20564 | + IMustLock(d_inode(wh_dentry->d_parent)); |
1facf9fc | 20565 | + err = 0; |
20566 | + } | |
20567 | + | |
4a4d8108 | 20568 | + if (!err) { |
027c5e7a | 20569 | + vfsub_dead_dir(inode); |
4a4d8108 AM |
20570 | + au_set_dbdiropq(dentry, -1); |
20571 | + epilog(dir, dentry, bindex); | |
1308ab2a | 20572 | + |
4a4d8108 | 20573 | + if (rmdir_later) { |
5afbbe0d | 20574 | + au_whtmp_kick_rmdir(dir, btop, h_dentry, args); |
4a4d8108 AM |
20575 | + args = NULL; |
20576 | + } | |
1308ab2a | 20577 | + |
4a4d8108 | 20578 | + goto out_unpin; /* success */ |
1facf9fc | 20579 | + } |
20580 | + | |
4a4d8108 AM |
20581 | + /* revert */ |
20582 | + AuLabel(revert); | |
20583 | + if (wh_dentry) { | |
20584 | + int rerr; | |
1308ab2a | 20585 | + |
c2b27bf2 AM |
20586 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
20587 | + &a->dt); | |
4a4d8108 AM |
20588 | + if (rerr) |
20589 | + err = rerr; | |
1facf9fc | 20590 | + } |
20591 | + | |
4f0767ce | 20592 | +out_unpin: |
c2b27bf2 | 20593 | + au_unpin(&a->pin); |
4a4d8108 AM |
20594 | + dput(wh_dentry); |
20595 | + dput(h_dentry); | |
027c5e7a | 20596 | +out_parent: |
4a4d8108 AM |
20597 | + di_write_unlock(parent); |
20598 | + if (args) | |
20599 | + au_whtmp_rmdir_free(args); | |
4f0767ce | 20600 | +out_unlock: |
4a4d8108 | 20601 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 | 20602 | +out_free: |
f0c0a007 | 20603 | + au_delayed_kfree(a); |
4f0767ce | 20604 | +out: |
4a4d8108 AM |
20605 | + AuTraceErr(err); |
20606 | + return err; | |
dece6358 | 20607 | +} |
7f207e10 AM |
20608 | diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c |
20609 | --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 20610 | +++ linux/fs/aufs/i_op_ren.c 2017-05-06 22:16:52.778220093 +0200 |
f2c43d5f | 20611 | @@ -0,0 +1,1165 @@ |
1facf9fc | 20612 | +/* |
a2654f78 | 20613 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 20614 | + * |
20615 | + * This program, aufs is free software; you can redistribute it and/or modify | |
20616 | + * it under the terms of the GNU General Public License as published by | |
20617 | + * the Free Software Foundation; either version 2 of the License, or | |
20618 | + * (at your option) any later version. | |
dece6358 AM |
20619 | + * |
20620 | + * This program is distributed in the hope that it will be useful, | |
20621 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20622 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20623 | + * GNU General Public License for more details. | |
20624 | + * | |
20625 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 20626 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 20627 | + */ |
20628 | + | |
20629 | +/* | |
4a4d8108 AM |
20630 | + * inode operation (rename entry) |
20631 | + * todo: this is crazy monster | |
1facf9fc | 20632 | + */ |
20633 | + | |
20634 | +#include "aufs.h" | |
20635 | + | |
4a4d8108 AM |
20636 | +enum { AuSRC, AuDST, AuSrcDst }; |
20637 | +enum { AuPARENT, AuCHILD, AuParentChild }; | |
1facf9fc | 20638 | + |
f2c43d5f AM |
20639 | +#define AuRen_ISDIR_SRC 1 |
20640 | +#define AuRen_ISDIR_DST (1 << 1) | |
20641 | +#define AuRen_ISSAMEDIR (1 << 2) | |
20642 | +#define AuRen_WHSRC (1 << 3) | |
20643 | +#define AuRen_WHDST (1 << 4) | |
20644 | +#define AuRen_MNT_WRITE (1 << 5) | |
20645 | +#define AuRen_DT_DSTDIR (1 << 6) | |
20646 | +#define AuRen_DIROPQ_SRC (1 << 7) | |
20647 | +#define AuRen_DIROPQ_DST (1 << 8) | |
4a4d8108 | 20648 | +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name) |
7f207e10 AM |
20649 | +#define au_fset_ren(flags, name) \ |
20650 | + do { (flags) |= AuRen_##name; } while (0) | |
20651 | +#define au_fclr_ren(flags, name) \ | |
20652 | + do { (flags) &= ~AuRen_##name; } while (0) | |
1facf9fc | 20653 | + |
4a4d8108 AM |
20654 | +struct au_ren_args { |
20655 | + struct { | |
20656 | + struct dentry *dentry, *h_dentry, *parent, *h_parent, | |
20657 | + *wh_dentry; | |
20658 | + struct inode *dir, *inode; | |
f2c43d5f | 20659 | + struct au_hinode *hdir, *hinode; |
4a4d8108 | 20660 | + struct au_dtime dt[AuParentChild]; |
f2c43d5f | 20661 | + aufs_bindex_t btop, bdiropq; |
4a4d8108 | 20662 | + } sd[AuSrcDst]; |
1facf9fc | 20663 | + |
4a4d8108 AM |
20664 | +#define src_dentry sd[AuSRC].dentry |
20665 | +#define src_dir sd[AuSRC].dir | |
20666 | +#define src_inode sd[AuSRC].inode | |
20667 | +#define src_h_dentry sd[AuSRC].h_dentry | |
20668 | +#define src_parent sd[AuSRC].parent | |
20669 | +#define src_h_parent sd[AuSRC].h_parent | |
20670 | +#define src_wh_dentry sd[AuSRC].wh_dentry | |
20671 | +#define src_hdir sd[AuSRC].hdir | |
f2c43d5f | 20672 | +#define src_hinode sd[AuSRC].hinode |
4a4d8108 AM |
20673 | +#define src_h_dir sd[AuSRC].hdir->hi_inode |
20674 | +#define src_dt sd[AuSRC].dt | |
5afbbe0d | 20675 | +#define src_btop sd[AuSRC].btop |
f2c43d5f | 20676 | +#define src_bdiropq sd[AuSRC].bdiropq |
1facf9fc | 20677 | + |
4a4d8108 AM |
20678 | +#define dst_dentry sd[AuDST].dentry |
20679 | +#define dst_dir sd[AuDST].dir | |
20680 | +#define dst_inode sd[AuDST].inode | |
20681 | +#define dst_h_dentry sd[AuDST].h_dentry | |
20682 | +#define dst_parent sd[AuDST].parent | |
20683 | +#define dst_h_parent sd[AuDST].h_parent | |
20684 | +#define dst_wh_dentry sd[AuDST].wh_dentry | |
20685 | +#define dst_hdir sd[AuDST].hdir | |
f2c43d5f | 20686 | +#define dst_hinode sd[AuDST].hinode |
4a4d8108 AM |
20687 | +#define dst_h_dir sd[AuDST].hdir->hi_inode |
20688 | +#define dst_dt sd[AuDST].dt | |
5afbbe0d | 20689 | +#define dst_btop sd[AuDST].btop |
f2c43d5f | 20690 | +#define dst_bdiropq sd[AuDST].bdiropq |
4a4d8108 AM |
20691 | + |
20692 | + struct dentry *h_trap; | |
20693 | + struct au_branch *br; | |
4a4d8108 AM |
20694 | + struct path h_path; |
20695 | + struct au_nhash whlist; | |
f2c43d5f | 20696 | + aufs_bindex_t btgt, src_bwh; |
1facf9fc | 20697 | + |
f2c43d5f AM |
20698 | + struct { |
20699 | + unsigned short auren_flags; | |
20700 | + unsigned char flags; /* syscall parameter */ | |
20701 | + unsigned char exchange; | |
20702 | + } __packed; | |
1facf9fc | 20703 | + |
4a4d8108 AM |
20704 | + struct au_whtmp_rmdir *thargs; |
20705 | + struct dentry *h_dst; | |
20706 | +}; | |
1308ab2a | 20707 | + |
4a4d8108 | 20708 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 20709 | + |
4a4d8108 AM |
20710 | +/* |
20711 | + * functions for reverting. | |
20712 | + * when an error happened in a single rename systemcall, we should revert | |
79b8bda9 | 20713 | + * everything as if nothing happened. |
4a4d8108 AM |
20714 | + * we don't need to revert the copied-up/down the parent dir since they are |
20715 | + * harmless. | |
20716 | + */ | |
1facf9fc | 20717 | + |
4a4d8108 AM |
20718 | +#define RevertFailure(fmt, ...) do { \ |
20719 | + AuIOErr("revert failure: " fmt " (%d, %d)\n", \ | |
20720 | + ##__VA_ARGS__, err, rerr); \ | |
20721 | + err = -EIO; \ | |
20722 | +} while (0) | |
1facf9fc | 20723 | + |
f2c43d5f | 20724 | +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx) |
1facf9fc | 20725 | +{ |
4a4d8108 | 20726 | + int rerr; |
f2c43d5f AM |
20727 | + struct dentry *d; |
20728 | +#define src_or_dst(member) a->sd[idx].member | |
1facf9fc | 20729 | + |
f2c43d5f AM |
20730 | + d = src_or_dst(dentry); /* {src,dst}_dentry */ |
20731 | + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD); | |
20732 | + rerr = au_diropq_remove(d, a->btgt); | |
20733 | + au_hn_inode_unlock(src_or_dst(hinode)); | |
20734 | + au_set_dbdiropq(d, src_or_dst(bdiropq)); | |
4a4d8108 | 20735 | + if (rerr) |
f2c43d5f AM |
20736 | + RevertFailure("remove diropq %pd", d); |
20737 | + | |
20738 | +#undef src_or_dst_ | |
20739 | +} | |
20740 | + | |
20741 | +static void au_ren_rev_diropq(int err, struct au_ren_args *a) | |
20742 | +{ | |
20743 | + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC)) | |
20744 | + au_ren_do_rev_diropq(err, a, AuSRC); | |
20745 | + if (au_ftest_ren(a->auren_flags, DIROPQ_DST)) | |
20746 | + au_ren_do_rev_diropq(err, a, AuDST); | |
4a4d8108 | 20747 | +} |
1facf9fc | 20748 | + |
4a4d8108 AM |
20749 | +static void au_ren_rev_rename(int err, struct au_ren_args *a) |
20750 | +{ | |
20751 | + int rerr; | |
523b37e3 | 20752 | + struct inode *delegated; |
1facf9fc | 20753 | + |
b4510431 AM |
20754 | + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, |
20755 | + a->src_h_parent); | |
4a4d8108 AM |
20756 | + rerr = PTR_ERR(a->h_path.dentry); |
20757 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 20758 | + RevertFailure("lkup one %pd", a->src_dentry); |
4a4d8108 | 20759 | + return; |
1facf9fc | 20760 | + } |
20761 | + | |
523b37e3 | 20762 | + delegated = NULL; |
4a4d8108 AM |
20763 | + rerr = vfsub_rename(a->dst_h_dir, |
20764 | + au_h_dptr(a->src_dentry, a->btgt), | |
f2c43d5f | 20765 | + a->src_h_dir, &a->h_path, &delegated, a->flags); |
523b37e3 AM |
20766 | + if (unlikely(rerr == -EWOULDBLOCK)) { |
20767 | + pr_warn("cannot retry for NFSv4 delegation" | |
20768 | + " for an internal rename\n"); | |
20769 | + iput(delegated); | |
20770 | + } | |
4a4d8108 AM |
20771 | + d_drop(a->h_path.dentry); |
20772 | + dput(a->h_path.dentry); | |
20773 | + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */ | |
20774 | + if (rerr) | |
523b37e3 | 20775 | + RevertFailure("rename %pd", a->src_dentry); |
1facf9fc | 20776 | +} |
20777 | + | |
4a4d8108 | 20778 | +static void au_ren_rev_whtmp(int err, struct au_ren_args *a) |
1facf9fc | 20779 | +{ |
4a4d8108 | 20780 | + int rerr; |
523b37e3 | 20781 | + struct inode *delegated; |
dece6358 | 20782 | + |
b4510431 AM |
20783 | + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, |
20784 | + a->dst_h_parent); | |
4a4d8108 AM |
20785 | + rerr = PTR_ERR(a->h_path.dentry); |
20786 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 20787 | + RevertFailure("lkup one %pd", a->dst_dentry); |
4a4d8108 AM |
20788 | + return; |
20789 | + } | |
5527c038 | 20790 | + if (d_is_positive(a->h_path.dentry)) { |
4a4d8108 AM |
20791 | + d_drop(a->h_path.dentry); |
20792 | + dput(a->h_path.dentry); | |
20793 | + return; | |
dece6358 AM |
20794 | + } |
20795 | + | |
523b37e3 AM |
20796 | + delegated = NULL; |
20797 | + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path, | |
f2c43d5f | 20798 | + &delegated, a->flags); |
523b37e3 AM |
20799 | + if (unlikely(rerr == -EWOULDBLOCK)) { |
20800 | + pr_warn("cannot retry for NFSv4 delegation" | |
20801 | + " for an internal rename\n"); | |
20802 | + iput(delegated); | |
20803 | + } | |
4a4d8108 AM |
20804 | + d_drop(a->h_path.dentry); |
20805 | + dput(a->h_path.dentry); | |
20806 | + if (!rerr) | |
20807 | + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst)); | |
20808 | + else | |
523b37e3 | 20809 | + RevertFailure("rename %pd", a->h_dst); |
4a4d8108 | 20810 | +} |
1308ab2a | 20811 | + |
4a4d8108 AM |
20812 | +static void au_ren_rev_whsrc(int err, struct au_ren_args *a) |
20813 | +{ | |
20814 | + int rerr; | |
1308ab2a | 20815 | + |
4a4d8108 AM |
20816 | + a->h_path.dentry = a->src_wh_dentry; |
20817 | + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry); | |
027c5e7a | 20818 | + au_set_dbwh(a->src_dentry, a->src_bwh); |
4a4d8108 | 20819 | + if (rerr) |
523b37e3 | 20820 | + RevertFailure("unlink %pd", a->src_wh_dentry); |
4a4d8108 | 20821 | +} |
4a4d8108 | 20822 | +#undef RevertFailure |
1facf9fc | 20823 | + |
1308ab2a | 20824 | +/* ---------------------------------------------------------------------- */ |
20825 | + | |
4a4d8108 AM |
20826 | +/* |
20827 | + * when we have to copyup the renaming entry, do it with the rename-target name | |
20828 | + * in order to minimize the cost (the later actual rename is unnecessary). | |
20829 | + * otherwise rename it on the target branch. | |
20830 | + */ | |
20831 | +static int au_ren_or_cpup(struct au_ren_args *a) | |
1facf9fc | 20832 | +{ |
dece6358 | 20833 | + int err; |
4a4d8108 | 20834 | + struct dentry *d; |
523b37e3 | 20835 | + struct inode *delegated; |
1facf9fc | 20836 | + |
4a4d8108 | 20837 | + d = a->src_dentry; |
5afbbe0d | 20838 | + if (au_dbtop(d) == a->btgt) { |
4a4d8108 | 20839 | + a->h_path.dentry = a->dst_h_dentry; |
5afbbe0d | 20840 | + AuDebugOn(au_dbtop(d) != a->btgt); |
523b37e3 | 20841 | + delegated = NULL; |
4a4d8108 | 20842 | + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt), |
f2c43d5f AM |
20843 | + a->dst_h_dir, &a->h_path, &delegated, |
20844 | + a->flags); | |
523b37e3 AM |
20845 | + if (unlikely(err == -EWOULDBLOCK)) { |
20846 | + pr_warn("cannot retry for NFSv4 delegation" | |
20847 | + " for an internal rename\n"); | |
20848 | + iput(delegated); | |
20849 | + } | |
c2b27bf2 | 20850 | + } else |
86dc4139 | 20851 | + BUG(); |
1308ab2a | 20852 | + |
027c5e7a AM |
20853 | + if (!err && a->h_dst) |
20854 | + /* it will be set to dinfo later */ | |
20855 | + dget(a->h_dst); | |
1facf9fc | 20856 | + |
dece6358 AM |
20857 | + return err; |
20858 | +} | |
1facf9fc | 20859 | + |
4a4d8108 AM |
20860 | +/* cf. aufs_rmdir() */ |
20861 | +static int au_ren_del_whtmp(struct au_ren_args *a) | |
dece6358 | 20862 | +{ |
4a4d8108 AM |
20863 | + int err; |
20864 | + struct inode *dir; | |
1facf9fc | 20865 | + |
4a4d8108 AM |
20866 | + dir = a->dst_dir; |
20867 | + SiMustAnyLock(dir->i_sb); | |
20868 | + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt, | |
20869 | + au_sbi(dir->i_sb)->si_dirwh) | |
20870 | + || au_test_fs_remote(a->h_dst->d_sb)) { | |
20871 | + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist); | |
20872 | + if (unlikely(err)) | |
523b37e3 AM |
20873 | + pr_warn("failed removing whtmp dir %pd (%d), " |
20874 | + "ignored.\n", a->h_dst, err); | |
4a4d8108 AM |
20875 | + } else { |
20876 | + au_nhash_wh_free(&a->thargs->whlist); | |
20877 | + a->thargs->whlist = a->whlist; | |
20878 | + a->whlist.nh_num = 0; | |
20879 | + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs); | |
20880 | + dput(a->h_dst); | |
20881 | + a->thargs = NULL; | |
20882 | + } | |
20883 | + | |
20884 | + return 0; | |
1308ab2a | 20885 | +} |
1facf9fc | 20886 | + |
4a4d8108 | 20887 | +/* make it 'opaque' dir. */ |
f2c43d5f | 20888 | +static int au_ren_do_diropq(struct au_ren_args *a, int idx) |
4a4d8108 AM |
20889 | +{ |
20890 | + int err; | |
f2c43d5f AM |
20891 | + struct dentry *d, *diropq; |
20892 | +#define src_or_dst(member) a->sd[idx].member | |
1facf9fc | 20893 | + |
4a4d8108 | 20894 | + err = 0; |
f2c43d5f AM |
20895 | + d = src_or_dst(dentry); /* {src,dst}_dentry */ |
20896 | + src_or_dst(bdiropq) = au_dbdiropq(d); | |
20897 | + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt); | |
20898 | + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD); | |
20899 | + diropq = au_diropq_create(d, a->btgt); | |
20900 | + au_hn_inode_unlock(src_or_dst(hinode)); | |
4a4d8108 AM |
20901 | + if (IS_ERR(diropq)) |
20902 | + err = PTR_ERR(diropq); | |
076b876e AM |
20903 | + else |
20904 | + dput(diropq); | |
1facf9fc | 20905 | + |
f2c43d5f | 20906 | +#undef src_or_dst_ |
4a4d8108 AM |
20907 | + return err; |
20908 | +} | |
1facf9fc | 20909 | + |
f2c43d5f | 20910 | +static int au_ren_diropq(struct au_ren_args *a) |
4a4d8108 AM |
20911 | +{ |
20912 | + int err; | |
f2c43d5f AM |
20913 | + unsigned char always; |
20914 | + struct dentry *d; | |
1facf9fc | 20915 | + |
f2c43d5f AM |
20916 | + err = 0; |
20917 | + d = a->dst_dentry; /* already renamed on the branch */ | |
20918 | + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ); | |
20919 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) | |
20920 | + && a->btgt != au_dbdiropq(a->src_dentry) | |
20921 | + && (a->dst_wh_dentry | |
20922 | + || a->btgt <= au_dbdiropq(d) | |
20923 | + /* hide the lower to keep xino */ | |
20924 | + /* the lowers may not be a dir, but we hide them anyway */ | |
20925 | + || a->btgt < au_dbbot(d) | |
20926 | + || always)) { | |
20927 | + AuDbg("here\n"); | |
20928 | + err = au_ren_do_diropq(a, AuSRC); | |
20929 | + if (unlikely(err)) | |
4a4d8108 | 20930 | + goto out; |
f2c43d5f | 20931 | + au_fset_ren(a->auren_flags, DIROPQ_SRC); |
4a4d8108 | 20932 | + } |
f2c43d5f AM |
20933 | + if (!a->exchange) |
20934 | + goto out; /* success */ | |
1facf9fc | 20935 | + |
f2c43d5f AM |
20936 | + d = a->src_dentry; /* already renamed on the branch */ |
20937 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) | |
20938 | + && a->btgt != au_dbdiropq(a->dst_dentry) | |
20939 | + && (a->btgt < au_dbdiropq(d) | |
20940 | + || a->btgt < au_dbbot(d) | |
20941 | + || always)) { | |
20942 | + AuDbgDentry(a->src_dentry); | |
20943 | + AuDbgDentry(a->dst_dentry); | |
20944 | + err = au_ren_do_diropq(a, AuDST); | |
4a4d8108 | 20945 | + if (unlikely(err)) |
f2c43d5f AM |
20946 | + goto out_rev_src; |
20947 | + au_fset_ren(a->auren_flags, DIROPQ_DST); | |
20948 | + } | |
20949 | + goto out; /* success */ | |
dece6358 | 20950 | + |
f2c43d5f AM |
20951 | +out_rev_src: |
20952 | + AuDbg("err %d, reverting src\n", err); | |
20953 | + au_ren_rev_diropq(err, a); | |
20954 | +out: | |
20955 | + return err; | |
20956 | +} | |
20957 | + | |
20958 | +static int do_rename(struct au_ren_args *a) | |
20959 | +{ | |
20960 | + int err; | |
20961 | + struct dentry *d, *h_d; | |
20962 | + | |
20963 | + if (!a->exchange) { | |
20964 | + /* prepare workqueue args for asynchronous rmdir */ | |
20965 | + h_d = a->dst_h_dentry; | |
20966 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) | |
20967 | + && d_is_positive(h_d)) { | |
20968 | + err = -ENOMEM; | |
20969 | + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, | |
20970 | + GFP_NOFS); | |
20971 | + if (unlikely(!a->thargs)) | |
20972 | + goto out; | |
20973 | + a->h_dst = dget(h_d); | |
20974 | + } | |
20975 | + | |
20976 | + /* create whiteout for src_dentry */ | |
20977 | + if (au_ftest_ren(a->auren_flags, WHSRC)) { | |
20978 | + a->src_bwh = au_dbwh(a->src_dentry); | |
20979 | + AuDebugOn(a->src_bwh >= 0); | |
20980 | + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt, | |
20981 | + a->src_h_parent); | |
20982 | + err = PTR_ERR(a->src_wh_dentry); | |
20983 | + if (IS_ERR(a->src_wh_dentry)) | |
20984 | + goto out_thargs; | |
20985 | + } | |
20986 | + | |
20987 | + /* lookup whiteout for dentry */ | |
20988 | + if (au_ftest_ren(a->auren_flags, WHDST)) { | |
20989 | + h_d = au_wh_lkup(a->dst_h_parent, | |
20990 | + &a->dst_dentry->d_name, a->br); | |
20991 | + err = PTR_ERR(h_d); | |
20992 | + if (IS_ERR(h_d)) | |
20993 | + goto out_whsrc; | |
20994 | + if (d_is_negative(h_d)) | |
20995 | + dput(h_d); | |
20996 | + else | |
20997 | + a->dst_wh_dentry = h_d; | |
20998 | + } | |
20999 | + | |
21000 | + /* rename dentry to tmpwh */ | |
21001 | + if (a->thargs) { | |
21002 | + err = au_whtmp_ren(a->dst_h_dentry, a->br); | |
21003 | + if (unlikely(err)) | |
21004 | + goto out_whdst; | |
21005 | + | |
21006 | + d = a->dst_dentry; | |
21007 | + au_set_h_dptr(d, a->btgt, NULL); | |
21008 | + err = au_lkup_neg(d, a->btgt, /*wh*/0); | |
21009 | + if (unlikely(err)) | |
21010 | + goto out_whtmp; | |
21011 | + a->dst_h_dentry = au_h_dptr(d, a->btgt); | |
21012 | + } | |
4a4d8108 | 21013 | + } |
1facf9fc | 21014 | + |
5afbbe0d | 21015 | + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt); |
1facf9fc | 21016 | + |
4a4d8108 | 21017 | + /* rename by vfs_rename or cpup */ |
4a4d8108 AM |
21018 | + err = au_ren_or_cpup(a); |
21019 | + if (unlikely(err)) | |
21020 | + /* leave the copied-up one */ | |
21021 | + goto out_whtmp; | |
1308ab2a | 21022 | + |
4a4d8108 | 21023 | + /* make dir opaque */ |
f2c43d5f AM |
21024 | + err = au_ren_diropq(a); |
21025 | + if (unlikely(err)) | |
21026 | + goto out_rename; | |
1308ab2a | 21027 | + |
4a4d8108 | 21028 | + /* update target timestamps */ |
f2c43d5f AM |
21029 | + if (a->exchange) { |
21030 | + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt); | |
21031 | + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt); | |
21032 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
21033 | + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; | |
21034 | + } | |
5afbbe0d | 21035 | + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt); |
4a4d8108 AM |
21036 | + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt); |
21037 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
5527c038 | 21038 | + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
1facf9fc | 21039 | + |
f2c43d5f AM |
21040 | + if (!a->exchange) { |
21041 | + /* remove whiteout for dentry */ | |
21042 | + if (a->dst_wh_dentry) { | |
21043 | + a->h_path.dentry = a->dst_wh_dentry; | |
21044 | + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path, | |
21045 | + a->dst_dentry); | |
21046 | + if (unlikely(err)) | |
21047 | + goto out_diropq; | |
21048 | + } | |
1facf9fc | 21049 | + |
f2c43d5f AM |
21050 | + /* remove whtmp */ |
21051 | + if (a->thargs) | |
21052 | + au_ren_del_whtmp(a); /* ignore this error */ | |
1308ab2a | 21053 | + |
f2c43d5f AM |
21054 | + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0); |
21055 | + } | |
4a4d8108 AM |
21056 | + err = 0; |
21057 | + goto out_success; | |
21058 | + | |
4f0767ce | 21059 | +out_diropq: |
f2c43d5f | 21060 | + au_ren_rev_diropq(err, a); |
4f0767ce | 21061 | +out_rename: |
7e9cd9fe | 21062 | + au_ren_rev_rename(err, a); |
027c5e7a | 21063 | + dput(a->h_dst); |
4f0767ce | 21064 | +out_whtmp: |
4a4d8108 AM |
21065 | + if (a->thargs) |
21066 | + au_ren_rev_whtmp(err, a); | |
4f0767ce | 21067 | +out_whdst: |
4a4d8108 AM |
21068 | + dput(a->dst_wh_dentry); |
21069 | + a->dst_wh_dentry = NULL; | |
4f0767ce | 21070 | +out_whsrc: |
4a4d8108 AM |
21071 | + if (a->src_wh_dentry) |
21072 | + au_ren_rev_whsrc(err, a); | |
4f0767ce | 21073 | +out_success: |
4a4d8108 AM |
21074 | + dput(a->src_wh_dentry); |
21075 | + dput(a->dst_wh_dentry); | |
4f0767ce | 21076 | +out_thargs: |
4a4d8108 AM |
21077 | + if (a->thargs) { |
21078 | + dput(a->h_dst); | |
21079 | + au_whtmp_rmdir_free(a->thargs); | |
21080 | + a->thargs = NULL; | |
21081 | + } | |
4f0767ce | 21082 | +out: |
4a4d8108 | 21083 | + return err; |
dece6358 | 21084 | +} |
1facf9fc | 21085 | + |
1308ab2a | 21086 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 21087 | + |
4a4d8108 AM |
21088 | +/* |
21089 | + * test if @dentry dir can be rename destination or not. | |
21090 | + * success means, it is a logically empty dir. | |
21091 | + */ | |
21092 | +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist) | |
1308ab2a | 21093 | +{ |
4a4d8108 | 21094 | + return au_test_empty(dentry, whlist); |
1308ab2a | 21095 | +} |
1facf9fc | 21096 | + |
4a4d8108 AM |
21097 | +/* |
21098 | + * test if @dentry dir can be rename source or not. | |
21099 | + * if it can, return 0 and @children is filled. | |
21100 | + * success means, | |
21101 | + * - it is a logically empty dir. | |
21102 | + * - or, it exists on writable branch and has no children including whiteouts | |
21103 | + * on the lower branch. | |
21104 | + */ | |
21105 | +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt) | |
21106 | +{ | |
21107 | + int err; | |
21108 | + unsigned int rdhash; | |
5afbbe0d | 21109 | + aufs_bindex_t btop; |
1facf9fc | 21110 | + |
5afbbe0d AM |
21111 | + btop = au_dbtop(dentry); |
21112 | + if (btop != btgt) { | |
4a4d8108 | 21113 | + struct au_nhash whlist; |
dece6358 | 21114 | + |
4a4d8108 AM |
21115 | + SiMustAnyLock(dentry->d_sb); |
21116 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; | |
21117 | + if (!rdhash) | |
21118 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, | |
21119 | + dentry)); | |
21120 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
21121 | + if (unlikely(err)) | |
21122 | + goto out; | |
21123 | + err = au_test_empty(dentry, &whlist); | |
21124 | + au_nhash_wh_free(&whlist); | |
21125 | + goto out; | |
21126 | + } | |
dece6358 | 21127 | + |
5afbbe0d | 21128 | + if (btop == au_dbtaildir(dentry)) |
4a4d8108 | 21129 | + return 0; /* success */ |
dece6358 | 21130 | + |
4a4d8108 | 21131 | + err = au_test_empty_lower(dentry); |
1facf9fc | 21132 | + |
4f0767ce | 21133 | +out: |
4a4d8108 AM |
21134 | + if (err == -ENOTEMPTY) { |
21135 | + AuWarn1("renaming dir who has child(ren) on multiple branches," | |
21136 | + " is not supported\n"); | |
21137 | + err = -EXDEV; | |
21138 | + } | |
21139 | + return err; | |
21140 | +} | |
1308ab2a | 21141 | + |
4a4d8108 AM |
21142 | +/* side effect: sets whlist and h_dentry */ |
21143 | +static int au_ren_may_dir(struct au_ren_args *a) | |
1308ab2a | 21144 | +{ |
4a4d8108 AM |
21145 | + int err; |
21146 | + unsigned int rdhash; | |
21147 | + struct dentry *d; | |
1facf9fc | 21148 | + |
4a4d8108 AM |
21149 | + d = a->dst_dentry; |
21150 | + SiMustAnyLock(d->d_sb); | |
1facf9fc | 21151 | + |
4a4d8108 | 21152 | + err = 0; |
f2c43d5f | 21153 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) { |
4a4d8108 AM |
21154 | + rdhash = au_sbi(d->d_sb)->si_rdhash; |
21155 | + if (!rdhash) | |
21156 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d)); | |
21157 | + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS); | |
21158 | + if (unlikely(err)) | |
21159 | + goto out; | |
1308ab2a | 21160 | + |
f2c43d5f AM |
21161 | + if (!a->exchange) { |
21162 | + au_set_dbtop(d, a->dst_btop); | |
21163 | + err = may_rename_dstdir(d, &a->whlist); | |
21164 | + au_set_dbtop(d, a->btgt); | |
21165 | + } else | |
21166 | + err = may_rename_srcdir(d, a->btgt); | |
4a4d8108 | 21167 | + } |
5afbbe0d | 21168 | + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d)); |
4a4d8108 AM |
21169 | + if (unlikely(err)) |
21170 | + goto out; | |
21171 | + | |
21172 | + d = a->src_dentry; | |
5afbbe0d | 21173 | + a->src_h_dentry = au_h_dptr(d, au_dbtop(d)); |
f2c43d5f | 21174 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) { |
4a4d8108 AM |
21175 | + err = may_rename_srcdir(d, a->btgt); |
21176 | + if (unlikely(err)) { | |
21177 | + au_nhash_wh_free(&a->whlist); | |
21178 | + a->whlist.nh_num = 0; | |
21179 | + } | |
21180 | + } | |
4f0767ce | 21181 | +out: |
4a4d8108 | 21182 | + return err; |
1facf9fc | 21183 | +} |
21184 | + | |
4a4d8108 | 21185 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 21186 | + |
4a4d8108 AM |
21187 | +/* |
21188 | + * simple tests for rename. | |
21189 | + * following the checks in vfs, plus the parent-child relationship. | |
21190 | + */ | |
21191 | +static int au_may_ren(struct au_ren_args *a) | |
21192 | +{ | |
21193 | + int err, isdir; | |
21194 | + struct inode *h_inode; | |
1facf9fc | 21195 | + |
5afbbe0d | 21196 | + if (a->src_btop == a->btgt) { |
4a4d8108 | 21197 | + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent, |
f2c43d5f | 21198 | + au_ftest_ren(a->auren_flags, ISDIR_SRC)); |
4a4d8108 AM |
21199 | + if (unlikely(err)) |
21200 | + goto out; | |
21201 | + err = -EINVAL; | |
21202 | + if (unlikely(a->src_h_dentry == a->h_trap)) | |
21203 | + goto out; | |
21204 | + } | |
1facf9fc | 21205 | + |
4a4d8108 | 21206 | + err = 0; |
5afbbe0d | 21207 | + if (a->dst_btop != a->btgt) |
4a4d8108 | 21208 | + goto out; |
1facf9fc | 21209 | + |
027c5e7a AM |
21210 | + err = -ENOTEMPTY; |
21211 | + if (unlikely(a->dst_h_dentry == a->h_trap)) | |
21212 | + goto out; | |
21213 | + | |
4a4d8108 | 21214 | + err = -EIO; |
f2c43d5f | 21215 | + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST); |
5527c038 JR |
21216 | + if (d_really_is_negative(a->dst_dentry)) { |
21217 | + if (d_is_negative(a->dst_h_dentry)) | |
21218 | + err = au_may_add(a->dst_dentry, a->btgt, | |
21219 | + a->dst_h_parent, isdir); | |
4a4d8108 | 21220 | + } else { |
5527c038 | 21221 | + if (unlikely(d_is_negative(a->dst_h_dentry))) |
4a4d8108 | 21222 | + goto out; |
5527c038 JR |
21223 | + h_inode = d_inode(a->dst_h_dentry); |
21224 | + if (h_inode->i_nlink) | |
21225 | + err = au_may_del(a->dst_dentry, a->btgt, | |
21226 | + a->dst_h_parent, isdir); | |
4a4d8108 | 21227 | + } |
1facf9fc | 21228 | + |
4f0767ce | 21229 | +out: |
4a4d8108 AM |
21230 | + if (unlikely(err == -ENOENT || err == -EEXIST)) |
21231 | + err = -EIO; | |
21232 | + AuTraceErr(err); | |
21233 | + return err; | |
21234 | +} | |
1facf9fc | 21235 | + |
1308ab2a | 21236 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 21237 | + |
4a4d8108 AM |
21238 | +/* |
21239 | + * locking order | |
21240 | + * (VFS) | |
21241 | + * - src_dir and dir by lock_rename() | |
21242 | + * - inode if exitsts | |
21243 | + * (aufs) | |
21244 | + * - lock all | |
21245 | + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls, | |
21246 | + * + si_read_lock | |
21247 | + * + di_write_lock2_child() | |
21248 | + * + di_write_lock_child() | |
21249 | + * + ii_write_lock_child() | |
21250 | + * + di_write_lock_child2() | |
21251 | + * + ii_write_lock_child2() | |
21252 | + * + src_parent and parent | |
21253 | + * + di_write_lock_parent() | |
21254 | + * + ii_write_lock_parent() | |
21255 | + * + di_write_lock_parent2() | |
21256 | + * + ii_write_lock_parent2() | |
21257 | + * + lower src_dir and dir by vfsub_lock_rename() | |
21258 | + * + verify the every relationships between child and parent. if any | |
21259 | + * of them failed, unlock all and return -EBUSY. | |
21260 | + */ | |
21261 | +static void au_ren_unlock(struct au_ren_args *a) | |
1308ab2a | 21262 | +{ |
4a4d8108 AM |
21263 | + vfsub_unlock_rename(a->src_h_parent, a->src_hdir, |
21264 | + a->dst_h_parent, a->dst_hdir); | |
f2c43d5f | 21265 | + if (au_ftest_ren(a->auren_flags, MNT_WRITE)) |
86dc4139 | 21266 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
1308ab2a | 21267 | +} |
21268 | + | |
4a4d8108 | 21269 | +static int au_ren_lock(struct au_ren_args *a) |
1308ab2a | 21270 | +{ |
4a4d8108 AM |
21271 | + int err; |
21272 | + unsigned int udba; | |
1308ab2a | 21273 | + |
4a4d8108 AM |
21274 | + err = 0; |
21275 | + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt); | |
21276 | + a->src_hdir = au_hi(a->src_dir, a->btgt); | |
21277 | + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt); | |
21278 | + a->dst_hdir = au_hi(a->dst_dir, a->btgt); | |
86dc4139 AM |
21279 | + |
21280 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); | |
21281 | + if (unlikely(err)) | |
21282 | + goto out; | |
f2c43d5f | 21283 | + au_fset_ren(a->auren_flags, MNT_WRITE); |
4a4d8108 AM |
21284 | + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir, |
21285 | + a->dst_h_parent, a->dst_hdir); | |
21286 | + udba = au_opt_udba(a->src_dentry->d_sb); | |
5527c038 JR |
21287 | + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent) |
21288 | + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent))) | |
4a4d8108 | 21289 | + err = au_busy_or_stale(); |
5afbbe0d | 21290 | + if (!err && au_dbtop(a->src_dentry) == a->btgt) |
4a4d8108 | 21291 | + err = au_h_verify(a->src_h_dentry, udba, |
5527c038 | 21292 | + d_inode(a->src_h_parent), a->src_h_parent, |
4a4d8108 | 21293 | + a->br); |
5afbbe0d | 21294 | + if (!err && au_dbtop(a->dst_dentry) == a->btgt) |
4a4d8108 | 21295 | + err = au_h_verify(a->dst_h_dentry, udba, |
5527c038 | 21296 | + d_inode(a->dst_h_parent), a->dst_h_parent, |
4a4d8108 | 21297 | + a->br); |
86dc4139 | 21298 | + if (!err) |
4a4d8108 | 21299 | + goto out; /* success */ |
4a4d8108 AM |
21300 | + |
21301 | + err = au_busy_or_stale(); | |
4a4d8108 | 21302 | + au_ren_unlock(a); |
86dc4139 | 21303 | + |
4f0767ce | 21304 | +out: |
4a4d8108 | 21305 | + return err; |
1facf9fc | 21306 | +} |
21307 | + | |
21308 | +/* ---------------------------------------------------------------------- */ | |
21309 | + | |
4a4d8108 | 21310 | +static void au_ren_refresh_dir(struct au_ren_args *a) |
1facf9fc | 21311 | +{ |
4a4d8108 | 21312 | + struct inode *dir; |
dece6358 | 21313 | + |
4a4d8108 AM |
21314 | + dir = a->dst_dir; |
21315 | + dir->i_version++; | |
f2c43d5f | 21316 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) { |
4a4d8108 AM |
21317 | + /* is this updating defined in POSIX? */ |
21318 | + au_cpup_attr_timesizes(a->src_inode); | |
21319 | + au_cpup_attr_nlink(dir, /*force*/1); | |
4a4d8108 | 21320 | + } |
b912730e | 21321 | + au_dir_ts(dir, a->btgt); |
dece6358 | 21322 | + |
f2c43d5f AM |
21323 | + if (a->exchange) { |
21324 | + dir = a->src_dir; | |
21325 | + dir->i_version++; | |
21326 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) { | |
21327 | + /* is this updating defined in POSIX? */ | |
21328 | + au_cpup_attr_timesizes(a->dst_inode); | |
21329 | + au_cpup_attr_nlink(dir, /*force*/1); | |
21330 | + } | |
21331 | + au_dir_ts(dir, a->btgt); | |
21332 | + } | |
21333 | + | |
21334 | + if (au_ftest_ren(a->auren_flags, ISSAMEDIR)) | |
4a4d8108 | 21335 | + return; |
dece6358 | 21336 | + |
4a4d8108 AM |
21337 | + dir = a->src_dir; |
21338 | + dir->i_version++; | |
f2c43d5f | 21339 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) |
4a4d8108 | 21340 | + au_cpup_attr_nlink(dir, /*force*/1); |
b912730e | 21341 | + au_dir_ts(dir, a->btgt); |
1facf9fc | 21342 | +} |
21343 | + | |
4a4d8108 | 21344 | +static void au_ren_refresh(struct au_ren_args *a) |
1facf9fc | 21345 | +{ |
5afbbe0d | 21346 | + aufs_bindex_t bbot, bindex; |
4a4d8108 AM |
21347 | + struct dentry *d, *h_d; |
21348 | + struct inode *i, *h_i; | |
21349 | + struct super_block *sb; | |
dece6358 | 21350 | + |
027c5e7a AM |
21351 | + d = a->dst_dentry; |
21352 | + d_drop(d); | |
21353 | + if (a->h_dst) | |
21354 | + /* already dget-ed by au_ren_or_cpup() */ | |
21355 | + au_set_h_dptr(d, a->btgt, a->h_dst); | |
21356 | + | |
21357 | + i = a->dst_inode; | |
21358 | + if (i) { | |
f2c43d5f AM |
21359 | + if (!a->exchange) { |
21360 | + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) | |
21361 | + vfsub_drop_nlink(i); | |
21362 | + else { | |
21363 | + vfsub_dead_dir(i); | |
21364 | + au_cpup_attr_timesizes(i); | |
21365 | + } | |
21366 | + au_update_dbrange(d, /*do_put_zero*/1); | |
21367 | + } else | |
21368 | + au_cpup_attr_nlink(i, /*force*/1); | |
027c5e7a | 21369 | + } else { |
5afbbe0d AM |
21370 | + bbot = a->btgt; |
21371 | + for (bindex = au_dbtop(d); bindex < bbot; bindex++) | |
027c5e7a | 21372 | + au_set_h_dptr(d, bindex, NULL); |
5afbbe0d AM |
21373 | + bbot = au_dbbot(d); |
21374 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) | |
027c5e7a AM |
21375 | + au_set_h_dptr(d, bindex, NULL); |
21376 | + au_update_dbrange(d, /*do_put_zero*/0); | |
21377 | + } | |
21378 | + | |
4a4d8108 | 21379 | + d = a->src_dentry; |
f2c43d5f AM |
21380 | + if (!a->exchange) { |
21381 | + au_set_dbwh(d, -1); | |
21382 | + bbot = au_dbbot(d); | |
21383 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) { | |
21384 | + h_d = au_h_dptr(d, bindex); | |
21385 | + if (h_d) | |
21386 | + au_set_h_dptr(d, bindex, NULL); | |
21387 | + } | |
21388 | + au_set_dbbot(d, a->btgt); | |
4a4d8108 | 21389 | + |
f2c43d5f AM |
21390 | + sb = d->d_sb; |
21391 | + i = a->src_inode; | |
21392 | + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i)) | |
21393 | + return; /* success */ | |
4a4d8108 | 21394 | + |
f2c43d5f AM |
21395 | + bbot = au_ibbot(i); |
21396 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) { | |
21397 | + h_i = au_h_iptr(i, bindex); | |
21398 | + if (h_i) { | |
21399 | + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0); | |
21400 | + /* ignore this error */ | |
21401 | + au_set_h_iptr(i, bindex, NULL, 0); | |
21402 | + } | |
4a4d8108 | 21403 | + } |
f2c43d5f | 21404 | + au_set_ibbot(i, a->btgt); |
4a4d8108 | 21405 | + } |
f2c43d5f | 21406 | + d_drop(a->src_dentry); |
1308ab2a | 21407 | +} |
dece6358 | 21408 | + |
4a4d8108 AM |
21409 | +/* ---------------------------------------------------------------------- */ |
21410 | + | |
21411 | +/* mainly for link(2) and rename(2) */ | |
21412 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt) | |
1308ab2a | 21413 | +{ |
4a4d8108 AM |
21414 | + aufs_bindex_t bdiropq, bwh; |
21415 | + struct dentry *parent; | |
21416 | + struct au_branch *br; | |
21417 | + | |
21418 | + parent = dentry->d_parent; | |
5527c038 | 21419 | + IMustLock(d_inode(parent)); /* dir is locked */ |
4a4d8108 AM |
21420 | + |
21421 | + bdiropq = au_dbdiropq(parent); | |
21422 | + bwh = au_dbwh(dentry); | |
21423 | + br = au_sbr(dentry->d_sb, btgt); | |
21424 | + if (au_br_rdonly(br) | |
21425 | + || (0 <= bdiropq && bdiropq < btgt) | |
21426 | + || (0 <= bwh && bwh < btgt)) | |
21427 | + btgt = -1; | |
21428 | + | |
21429 | + AuDbg("btgt %d\n", btgt); | |
21430 | + return btgt; | |
1facf9fc | 21431 | +} |
21432 | + | |
5afbbe0d | 21433 | +/* sets src_btop, dst_btop and btgt */ |
4a4d8108 | 21434 | +static int au_ren_wbr(struct au_ren_args *a) |
1facf9fc | 21435 | +{ |
4a4d8108 AM |
21436 | + int err; |
21437 | + struct au_wr_dir_args wr_dir_args = { | |
21438 | + /* .force_btgt = -1, */ | |
21439 | + .flags = AuWrDir_ADD_ENTRY | |
21440 | + }; | |
dece6358 | 21441 | + |
5afbbe0d AM |
21442 | + a->src_btop = au_dbtop(a->src_dentry); |
21443 | + a->dst_btop = au_dbtop(a->dst_dentry); | |
f2c43d5f AM |
21444 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) |
21445 | + || au_ftest_ren(a->auren_flags, ISDIR_DST)) | |
4a4d8108 | 21446 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
5afbbe0d AM |
21447 | + wr_dir_args.force_btgt = a->src_btop; |
21448 | + if (a->dst_inode && a->dst_btop < a->src_btop) | |
21449 | + wr_dir_args.force_btgt = a->dst_btop; | |
4a4d8108 AM |
21450 | + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt); |
21451 | + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args); | |
21452 | + a->btgt = err; | |
f2c43d5f AM |
21453 | + if (a->exchange) |
21454 | + au_update_dbtop(a->dst_dentry); | |
dece6358 | 21455 | + |
4a4d8108 | 21456 | + return err; |
1facf9fc | 21457 | +} |
21458 | + | |
4a4d8108 | 21459 | +static void au_ren_dt(struct au_ren_args *a) |
1facf9fc | 21460 | +{ |
4a4d8108 AM |
21461 | + a->h_path.dentry = a->src_h_parent; |
21462 | + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path); | |
f2c43d5f | 21463 | + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) { |
4a4d8108 AM |
21464 | + a->h_path.dentry = a->dst_h_parent; |
21465 | + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path); | |
21466 | + } | |
1facf9fc | 21467 | + |
f2c43d5f AM |
21468 | + au_fclr_ren(a->auren_flags, DT_DSTDIR); |
21469 | + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC) | |
21470 | + && !a->exchange) | |
4a4d8108 | 21471 | + return; |
dece6358 | 21472 | + |
4a4d8108 AM |
21473 | + a->h_path.dentry = a->src_h_dentry; |
21474 | + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path); | |
5527c038 | 21475 | + if (d_is_positive(a->dst_h_dentry)) { |
f2c43d5f | 21476 | + au_fset_ren(a->auren_flags, DT_DSTDIR); |
4a4d8108 AM |
21477 | + a->h_path.dentry = a->dst_h_dentry; |
21478 | + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path); | |
21479 | + } | |
1308ab2a | 21480 | +} |
dece6358 | 21481 | + |
4a4d8108 | 21482 | +static void au_ren_rev_dt(int err, struct au_ren_args *a) |
1308ab2a | 21483 | +{ |
4a4d8108 | 21484 | + struct dentry *h_d; |
febd17d6 | 21485 | + struct inode *h_inode; |
4a4d8108 AM |
21486 | + |
21487 | + au_dtime_revert(a->src_dt + AuPARENT); | |
f2c43d5f | 21488 | + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) |
4a4d8108 AM |
21489 | + au_dtime_revert(a->dst_dt + AuPARENT); |
21490 | + | |
f2c43d5f | 21491 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) { |
4a4d8108 | 21492 | + h_d = a->src_dt[AuCHILD].dt_h_path.dentry; |
febd17d6 JR |
21493 | + h_inode = d_inode(h_d); |
21494 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); | |
4a4d8108 | 21495 | + au_dtime_revert(a->src_dt + AuCHILD); |
febd17d6 | 21496 | + inode_unlock(h_inode); |
4a4d8108 | 21497 | + |
f2c43d5f | 21498 | + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) { |
4a4d8108 | 21499 | + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry; |
febd17d6 JR |
21500 | + h_inode = d_inode(h_d); |
21501 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); | |
4a4d8108 | 21502 | + au_dtime_revert(a->dst_dt + AuCHILD); |
febd17d6 | 21503 | + inode_unlock(h_inode); |
1facf9fc | 21504 | + } |
21505 | + } | |
21506 | +} | |
21507 | + | |
4a4d8108 AM |
21508 | +/* ---------------------------------------------------------------------- */ |
21509 | + | |
21510 | +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, | |
f2c43d5f AM |
21511 | + struct inode *_dst_dir, struct dentry *_dst_dentry, |
21512 | + unsigned int _flags) | |
1facf9fc | 21513 | +{ |
f2c43d5f | 21514 | + int err, lock_flags; |
4a4d8108 AM |
21515 | + /* reduce stack space */ |
21516 | + struct au_ren_args *a; | |
f2c43d5f | 21517 | + struct au_pin pin; |
4a4d8108 | 21518 | + |
f2c43d5f | 21519 | + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags); |
4a4d8108 AM |
21520 | + IMustLock(_src_dir); |
21521 | + IMustLock(_dst_dir); | |
21522 | + | |
f2c43d5f AM |
21523 | + err = -EINVAL; |
21524 | + if (unlikely(_flags & RENAME_WHITEOUT)) | |
21525 | + goto out; | |
21526 | + | |
4a4d8108 AM |
21527 | + err = -ENOMEM; |
21528 | + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE); | |
21529 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
21530 | + if (unlikely(!a)) | |
21531 | + goto out; | |
21532 | + | |
f2c43d5f AM |
21533 | + a->flags = _flags; |
21534 | + a->exchange = _flags & RENAME_EXCHANGE; | |
4a4d8108 AM |
21535 | + a->src_dir = _src_dir; |
21536 | + a->src_dentry = _src_dentry; | |
5527c038 JR |
21537 | + a->src_inode = NULL; |
21538 | + if (d_really_is_positive(a->src_dentry)) | |
21539 | + a->src_inode = d_inode(a->src_dentry); | |
4a4d8108 AM |
21540 | + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */ |
21541 | + a->dst_dir = _dst_dir; | |
21542 | + a->dst_dentry = _dst_dentry; | |
5527c038 JR |
21543 | + a->dst_inode = NULL; |
21544 | + if (d_really_is_positive(a->dst_dentry)) | |
21545 | + a->dst_inode = d_inode(a->dst_dentry); | |
4a4d8108 AM |
21546 | + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */ |
21547 | + if (a->dst_inode) { | |
f2c43d5f AM |
21548 | + /* |
21549 | + * if EXCHANGE && src is non-dir && dst is dir, | |
21550 | + * dst is not locked. | |
21551 | + */ | |
21552 | + /* IMustLock(a->dst_inode); */ | |
4a4d8108 | 21553 | + au_igrab(a->dst_inode); |
1facf9fc | 21554 | + } |
1facf9fc | 21555 | + |
4a4d8108 | 21556 | + err = -ENOTDIR; |
f2c43d5f | 21557 | + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN; |
2000de60 | 21558 | + if (d_is_dir(a->src_dentry)) { |
f2c43d5f AM |
21559 | + au_fset_ren(a->auren_flags, ISDIR_SRC); |
21560 | + if (unlikely(!a->exchange | |
21561 | + && d_really_is_positive(a->dst_dentry) | |
2000de60 | 21562 | + && !d_is_dir(a->dst_dentry))) |
4a4d8108 | 21563 | + goto out_free; |
f2c43d5f AM |
21564 | + lock_flags |= AuLock_DIRS; |
21565 | + } | |
21566 | + if (a->dst_inode && d_is_dir(a->dst_dentry)) { | |
21567 | + au_fset_ren(a->auren_flags, ISDIR_DST); | |
21568 | + if (unlikely(!a->exchange | |
21569 | + && d_really_is_positive(a->src_dentry) | |
21570 | + && !d_is_dir(a->src_dentry))) | |
21571 | + goto out_free; | |
21572 | + lock_flags |= AuLock_DIRS; | |
b95c5147 | 21573 | + } |
f2c43d5f | 21574 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, lock_flags); |
e49829fe JR |
21575 | + if (unlikely(err)) |
21576 | + goto out_free; | |
1facf9fc | 21577 | + |
027c5e7a AM |
21578 | + err = au_d_hashed_positive(a->src_dentry); |
21579 | + if (unlikely(err)) | |
21580 | + goto out_unlock; | |
21581 | + err = -ENOENT; | |
21582 | + if (a->dst_inode) { | |
21583 | + /* | |
f2c43d5f | 21584 | + * If it is a dir, VFS unhash it before this |
027c5e7a AM |
21585 | + * function. It means we cannot rely upon d_unhashed(). |
21586 | + */ | |
21587 | + if (unlikely(!a->dst_inode->i_nlink)) | |
21588 | + goto out_unlock; | |
f2c43d5f | 21589 | + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) { |
027c5e7a | 21590 | + err = au_d_hashed_positive(a->dst_dentry); |
f2c43d5f | 21591 | + if (unlikely(err && !a->exchange)) |
027c5e7a AM |
21592 | + goto out_unlock; |
21593 | + } else if (unlikely(IS_DEADDIR(a->dst_inode))) | |
21594 | + goto out_unlock; | |
21595 | + } else if (unlikely(d_unhashed(a->dst_dentry))) | |
21596 | + goto out_unlock; | |
21597 | + | |
7eafdf33 AM |
21598 | + /* |
21599 | + * is it possible? | |
79b8bda9 | 21600 | + * yes, it happened (in linux-3.3-rcN) but I don't know why. |
7eafdf33 AM |
21601 | + * there may exist a problem somewhere else. |
21602 | + */ | |
21603 | + err = -EINVAL; | |
5527c038 | 21604 | + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry))) |
7eafdf33 AM |
21605 | + goto out_unlock; |
21606 | + | |
f2c43d5f | 21607 | + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */ |
4a4d8108 | 21608 | + di_write_lock_parent(a->dst_parent); |
1facf9fc | 21609 | + |
4a4d8108 AM |
21610 | + /* which branch we process */ |
21611 | + err = au_ren_wbr(a); | |
21612 | + if (unlikely(err < 0)) | |
027c5e7a | 21613 | + goto out_parent; |
4a4d8108 | 21614 | + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt); |
86dc4139 | 21615 | + a->h_path.mnt = au_br_mnt(a->br); |
1facf9fc | 21616 | + |
4a4d8108 AM |
21617 | + /* are they available to be renamed */ |
21618 | + err = au_ren_may_dir(a); | |
21619 | + if (unlikely(err)) | |
21620 | + goto out_children; | |
1facf9fc | 21621 | + |
4a4d8108 | 21622 | + /* prepare the writable parent dir on the same branch */ |
5afbbe0d | 21623 | + if (a->dst_btop == a->btgt) { |
f2c43d5f | 21624 | + au_fset_ren(a->auren_flags, WHDST); |
4a4d8108 AM |
21625 | + } else { |
21626 | + err = au_cpup_dirs(a->dst_dentry, a->btgt); | |
21627 | + if (unlikely(err)) | |
21628 | + goto out_children; | |
21629 | + } | |
1facf9fc | 21630 | + |
f2c43d5f AM |
21631 | + err = 0; |
21632 | + if (!a->exchange) { | |
21633 | + if (a->src_dir != a->dst_dir) { | |
21634 | + /* | |
21635 | + * this temporary unlock is safe, | |
21636 | + * because both dir->i_mutex are locked. | |
21637 | + */ | |
21638 | + di_write_unlock(a->dst_parent); | |
21639 | + di_write_lock_parent(a->src_parent); | |
21640 | + err = au_wr_dir_need_wh(a->src_dentry, | |
21641 | + au_ftest_ren(a->auren_flags, | |
21642 | + ISDIR_SRC), | |
21643 | + &a->btgt); | |
21644 | + di_write_unlock(a->src_parent); | |
21645 | + di_write_lock2_parent(a->src_parent, a->dst_parent, | |
21646 | + /*isdir*/1); | |
21647 | + au_fclr_ren(a->auren_flags, ISSAMEDIR); | |
21648 | + } else | |
21649 | + err = au_wr_dir_need_wh(a->src_dentry, | |
21650 | + au_ftest_ren(a->auren_flags, | |
21651 | + ISDIR_SRC), | |
21652 | + &a->btgt); | |
21653 | + } | |
4a4d8108 AM |
21654 | + if (unlikely(err < 0)) |
21655 | + goto out_children; | |
21656 | + if (err) | |
f2c43d5f | 21657 | + au_fset_ren(a->auren_flags, WHSRC); |
1facf9fc | 21658 | + |
86dc4139 | 21659 | + /* cpup src */ |
5afbbe0d | 21660 | + if (a->src_btop != a->btgt) { |
86dc4139 AM |
21661 | + err = au_pin(&pin, a->src_dentry, a->btgt, |
21662 | + au_opt_udba(a->src_dentry->d_sb), | |
21663 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
367653fa | 21664 | + if (!err) { |
c2b27bf2 AM |
21665 | + struct au_cp_generic cpg = { |
21666 | + .dentry = a->src_dentry, | |
21667 | + .bdst = a->btgt, | |
5afbbe0d | 21668 | + .bsrc = a->src_btop, |
c2b27bf2 AM |
21669 | + .len = -1, |
21670 | + .pin = &pin, | |
21671 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
21672 | + }; | |
5afbbe0d | 21673 | + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop); |
c2b27bf2 | 21674 | + err = au_sio_cpup_simple(&cpg); |
367653fa | 21675 | + au_unpin(&pin); |
86dc4139 | 21676 | + } |
86dc4139 AM |
21677 | + if (unlikely(err)) |
21678 | + goto out_children; | |
5afbbe0d | 21679 | + a->src_btop = a->btgt; |
86dc4139 | 21680 | + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt); |
f2c43d5f AM |
21681 | + if (!a->exchange) |
21682 | + au_fset_ren(a->auren_flags, WHSRC); | |
21683 | + } | |
21684 | + | |
21685 | + /* cpup dst */ | |
21686 | + if (a->exchange && a->dst_inode | |
21687 | + && a->dst_btop != a->btgt) { | |
21688 | + err = au_pin(&pin, a->dst_dentry, a->btgt, | |
21689 | + au_opt_udba(a->dst_dentry->d_sb), | |
21690 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
21691 | + if (!err) { | |
21692 | + struct au_cp_generic cpg = { | |
21693 | + .dentry = a->dst_dentry, | |
21694 | + .bdst = a->btgt, | |
21695 | + .bsrc = a->dst_btop, | |
21696 | + .len = -1, | |
21697 | + .pin = &pin, | |
21698 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
21699 | + }; | |
21700 | + err = au_sio_cpup_simple(&cpg); | |
21701 | + au_unpin(&pin); | |
21702 | + } | |
21703 | + if (unlikely(err)) | |
21704 | + goto out_children; | |
21705 | + a->dst_btop = a->btgt; | |
21706 | + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt); | |
86dc4139 AM |
21707 | + } |
21708 | + | |
4a4d8108 AM |
21709 | + /* lock them all */ |
21710 | + err = au_ren_lock(a); | |
21711 | + if (unlikely(err)) | |
86dc4139 | 21712 | + /* leave the copied-up one */ |
4a4d8108 | 21713 | + goto out_children; |
1facf9fc | 21714 | + |
f2c43d5f AM |
21715 | + if (!a->exchange) { |
21716 | + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE)) | |
21717 | + err = au_may_ren(a); | |
21718 | + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
21719 | + err = -ENAMETOOLONG; | |
21720 | + if (unlikely(err)) | |
21721 | + goto out_hdir; | |
21722 | + } | |
1facf9fc | 21723 | + |
4a4d8108 AM |
21724 | + /* store timestamps to be revertible */ |
21725 | + au_ren_dt(a); | |
1facf9fc | 21726 | + |
4a4d8108 AM |
21727 | + /* here we go */ |
21728 | + err = do_rename(a); | |
21729 | + if (unlikely(err)) | |
21730 | + goto out_dt; | |
21731 | + | |
21732 | + /* update dir attributes */ | |
21733 | + au_ren_refresh_dir(a); | |
21734 | + | |
21735 | + /* dput/iput all lower dentries */ | |
21736 | + au_ren_refresh(a); | |
21737 | + | |
21738 | + goto out_hdir; /* success */ | |
21739 | + | |
4f0767ce | 21740 | +out_dt: |
4a4d8108 | 21741 | + au_ren_rev_dt(err, a); |
4f0767ce | 21742 | +out_hdir: |
4a4d8108 | 21743 | + au_ren_unlock(a); |
4f0767ce | 21744 | +out_children: |
4a4d8108 | 21745 | + au_nhash_wh_free(&a->whlist); |
5afbbe0d AM |
21746 | + if (err && a->dst_inode && a->dst_btop != a->btgt) { |
21747 | + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt); | |
027c5e7a | 21748 | + au_set_h_dptr(a->dst_dentry, a->btgt, NULL); |
5afbbe0d | 21749 | + au_set_dbtop(a->dst_dentry, a->dst_btop); |
4a4d8108 | 21750 | + } |
027c5e7a | 21751 | +out_parent: |
f2c43d5f AM |
21752 | + if (!err) { |
21753 | + if (!a->exchange) | |
21754 | + d_move(a->src_dentry, a->dst_dentry); | |
21755 | + else | |
21756 | + d_exchange(a->src_dentry, a->dst_dentry); | |
21757 | + } else { | |
5afbbe0d | 21758 | + au_update_dbtop(a->dst_dentry); |
027c5e7a AM |
21759 | + if (!a->dst_inode) |
21760 | + d_drop(a->dst_dentry); | |
21761 | + } | |
f2c43d5f | 21762 | + if (au_ftest_ren(a->auren_flags, ISSAMEDIR)) |
4a4d8108 AM |
21763 | + di_write_unlock(a->dst_parent); |
21764 | + else | |
21765 | + di_write_unlock2(a->src_parent, a->dst_parent); | |
027c5e7a | 21766 | +out_unlock: |
4a4d8108 | 21767 | + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry); |
4f0767ce | 21768 | +out_free: |
4a4d8108 AM |
21769 | + iput(a->dst_inode); |
21770 | + if (a->thargs) | |
21771 | + au_whtmp_rmdir_free(a->thargs); | |
f0c0a007 | 21772 | + au_delayed_kfree(a); |
4f0767ce | 21773 | +out: |
4a4d8108 AM |
21774 | + AuTraceErr(err); |
21775 | + return err; | |
1308ab2a | 21776 | +} |
7f207e10 AM |
21777 | diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig |
21778 | --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 21779 | +++ linux/fs/aufs/Kconfig 2017-05-06 22:16:52.774886674 +0200 |
c1595e42 | 21780 | @@ -0,0 +1,185 @@ |
4a4d8108 AM |
21781 | +config AUFS_FS |
21782 | + tristate "Aufs (Advanced multi layered unification filesystem) support" | |
4a4d8108 AM |
21783 | + help |
21784 | + Aufs is a stackable unification filesystem such as Unionfs, | |
21785 | + which unifies several directories and provides a merged single | |
21786 | + directory. | |
21787 | + In the early days, aufs was entirely re-designed and | |
21788 | + re-implemented Unionfs Version 1.x series. Introducing many | |
21789 | + original ideas, approaches and improvements, it becomes totally | |
21790 | + different from Unionfs while keeping the basic features. | |
1facf9fc | 21791 | + |
4a4d8108 AM |
21792 | +if AUFS_FS |
21793 | +choice | |
21794 | + prompt "Maximum number of branches" | |
21795 | + default AUFS_BRANCH_MAX_127 | |
21796 | + help | |
21797 | + Specifies the maximum number of branches (or member directories) | |
21798 | + in a single aufs. The larger value consumes more system | |
21799 | + resources and has a minor impact to performance. | |
21800 | +config AUFS_BRANCH_MAX_127 | |
21801 | + bool "127" | |
21802 | + help | |
21803 | + Specifies the maximum number of branches (or member directories) | |
21804 | + in a single aufs. The larger value consumes more system | |
21805 | + resources and has a minor impact to performance. | |
21806 | +config AUFS_BRANCH_MAX_511 | |
21807 | + bool "511" | |
21808 | + help | |
21809 | + Specifies the maximum number of branches (or member directories) | |
21810 | + in a single aufs. The larger value consumes more system | |
21811 | + resources and has a minor impact to performance. | |
21812 | +config AUFS_BRANCH_MAX_1023 | |
21813 | + bool "1023" | |
21814 | + help | |
21815 | + Specifies the maximum number of branches (or member directories) | |
21816 | + in a single aufs. The larger value consumes more system | |
21817 | + resources and has a minor impact to performance. | |
21818 | +config AUFS_BRANCH_MAX_32767 | |
21819 | + bool "32767" | |
21820 | + help | |
21821 | + Specifies the maximum number of branches (or member directories) | |
21822 | + in a single aufs. The larger value consumes more system | |
21823 | + resources and has a minor impact to performance. | |
21824 | +endchoice | |
1facf9fc | 21825 | + |
e49829fe JR |
21826 | +config AUFS_SBILIST |
21827 | + bool | |
21828 | + depends on AUFS_MAGIC_SYSRQ || PROC_FS | |
21829 | + default y | |
21830 | + help | |
21831 | + Automatic configuration for internal use. | |
21832 | + When aufs supports Magic SysRq or /proc, enabled automatically. | |
21833 | + | |
4a4d8108 AM |
21834 | +config AUFS_HNOTIFY |
21835 | + bool "Detect direct branch access (bypassing aufs)" | |
21836 | + help | |
21837 | + If you want to modify files on branches directly, eg. bypassing aufs, | |
21838 | + and want aufs to detect the changes of them fully, then enable this | |
21839 | + option and use 'udba=notify' mount option. | |
7f207e10 | 21840 | + Currently there is only one available configuration, "fsnotify". |
4a4d8108 AM |
21841 | + It will have a negative impact to the performance. |
21842 | + See detail in aufs.5. | |
dece6358 | 21843 | + |
4a4d8108 AM |
21844 | +choice |
21845 | + prompt "method" if AUFS_HNOTIFY | |
21846 | + default AUFS_HFSNOTIFY | |
21847 | +config AUFS_HFSNOTIFY | |
21848 | + bool "fsnotify" | |
21849 | + select FSNOTIFY | |
4a4d8108 | 21850 | +endchoice |
1facf9fc | 21851 | + |
4a4d8108 AM |
21852 | +config AUFS_EXPORT |
21853 | + bool "NFS-exportable aufs" | |
2cbb1c4b | 21854 | + depends on EXPORTFS |
4a4d8108 AM |
21855 | + help |
21856 | + If you want to export your mounted aufs via NFS, then enable this | |
21857 | + option. There are several requirements for this configuration. | |
21858 | + See detail in aufs.5. | |
1facf9fc | 21859 | + |
4a4d8108 AM |
21860 | +config AUFS_INO_T_64 |
21861 | + bool | |
21862 | + depends on AUFS_EXPORT | |
21863 | + depends on 64BIT && !(ALPHA || S390) | |
21864 | + default y | |
21865 | + help | |
21866 | + Automatic configuration for internal use. | |
21867 | + /* typedef unsigned long/int __kernel_ino_t */ | |
21868 | + /* alpha and s390x are int */ | |
1facf9fc | 21869 | + |
c1595e42 JR |
21870 | +config AUFS_XATTR |
21871 | + bool "support for XATTR/EA (including Security Labels)" | |
21872 | + help | |
21873 | + If your branch fs supports XATTR/EA and you want to make them | |
21874 | + available in aufs too, then enable this opsion and specify the | |
21875 | + branch attributes for EA. | |
21876 | + See detail in aufs.5. | |
21877 | + | |
076b876e AM |
21878 | +config AUFS_FHSM |
21879 | + bool "File-based Hierarchical Storage Management" | |
21880 | + help | |
21881 | + Hierarchical Storage Management (or HSM) is a well-known feature | |
21882 | + in the storage world. Aufs provides this feature as file-based. | |
21883 | + with multiple branches. | |
21884 | + These multiple branches are prioritized, ie. the topmost one | |
21885 | + should be the fastest drive and be used heavily. | |
21886 | + | |
4a4d8108 AM |
21887 | +config AUFS_RDU |
21888 | + bool "Readdir in userspace" | |
21889 | + help | |
21890 | + Aufs has two methods to provide a merged view for a directory, | |
21891 | + by a user-space library and by kernel-space natively. The latter | |
21892 | + is always enabled but sometimes large and slow. | |
21893 | + If you enable this option, install the library in aufs2-util | |
21894 | + package, and set some environment variables for your readdir(3), | |
21895 | + then the work will be handled in user-space which generally | |
21896 | + shows better performance in most cases. | |
21897 | + See detail in aufs.5. | |
1facf9fc | 21898 | + |
4a4d8108 AM |
21899 | +config AUFS_SHWH |
21900 | + bool "Show whiteouts" | |
21901 | + help | |
21902 | + If you want to make the whiteouts in aufs visible, then enable | |
21903 | + this option and specify 'shwh' mount option. Although it may | |
21904 | + sounds like philosophy or something, but in technically it | |
21905 | + simply shows the name of whiteout with keeping its behaviour. | |
1facf9fc | 21906 | + |
4a4d8108 AM |
21907 | +config AUFS_BR_RAMFS |
21908 | + bool "Ramfs (initramfs/rootfs) as an aufs branch" | |
21909 | + help | |
21910 | + If you want to use ramfs as an aufs branch fs, then enable this | |
21911 | + option. Generally tmpfs is recommended. | |
21912 | + Aufs prohibited them to be a branch fs by default, because | |
21913 | + initramfs becomes unusable after switch_root or something | |
21914 | + generally. If you sets initramfs as an aufs branch and boot your | |
21915 | + system by switch_root, you will meet a problem easily since the | |
21916 | + files in initramfs may be inaccessible. | |
21917 | + Unless you are going to use ramfs as an aufs branch fs without | |
21918 | + switch_root or something, leave it N. | |
1facf9fc | 21919 | + |
4a4d8108 AM |
21920 | +config AUFS_BR_FUSE |
21921 | + bool "Fuse fs as an aufs branch" | |
21922 | + depends on FUSE_FS | |
21923 | + select AUFS_POLL | |
21924 | + help | |
21925 | + If you want to use fuse-based userspace filesystem as an aufs | |
21926 | + branch fs, then enable this option. | |
21927 | + It implements the internal poll(2) operation which is | |
21928 | + implemented by fuse only (curretnly). | |
1facf9fc | 21929 | + |
4a4d8108 AM |
21930 | +config AUFS_POLL |
21931 | + bool | |
21932 | + help | |
21933 | + Automatic configuration for internal use. | |
1facf9fc | 21934 | + |
4a4d8108 AM |
21935 | +config AUFS_BR_HFSPLUS |
21936 | + bool "Hfsplus as an aufs branch" | |
21937 | + depends on HFSPLUS_FS | |
21938 | + default y | |
21939 | + help | |
21940 | + If you want to use hfsplus fs as an aufs branch fs, then enable | |
21941 | + this option. This option introduces a small overhead at | |
21942 | + copying-up a file on hfsplus. | |
1facf9fc | 21943 | + |
4a4d8108 AM |
21944 | +config AUFS_BDEV_LOOP |
21945 | + bool | |
21946 | + depends on BLK_DEV_LOOP | |
21947 | + default y | |
21948 | + help | |
21949 | + Automatic configuration for internal use. | |
21950 | + Convert =[ym] into =y. | |
1308ab2a | 21951 | + |
4a4d8108 AM |
21952 | +config AUFS_DEBUG |
21953 | + bool "Debug aufs" | |
21954 | + help | |
21955 | + Enable this to compile aufs internal debug code. | |
21956 | + It will have a negative impact to the performance. | |
21957 | + | |
21958 | +config AUFS_MAGIC_SYSRQ | |
21959 | + bool | |
21960 | + depends on AUFS_DEBUG && MAGIC_SYSRQ | |
21961 | + default y | |
21962 | + help | |
21963 | + Automatic configuration for internal use. | |
21964 | + When aufs supports Magic SysRq, enabled automatically. | |
21965 | +endif | |
7f207e10 AM |
21966 | diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c |
21967 | --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 21968 | +++ linux/fs/aufs/loop.c 2017-05-06 22:16:52.781553511 +0200 |
e2f27e51 | 21969 | @@ -0,0 +1,147 @@ |
1facf9fc | 21970 | +/* |
a2654f78 | 21971 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 21972 | + * |
21973 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21974 | + * it under the terms of the GNU General Public License as published by | |
21975 | + * the Free Software Foundation; either version 2 of the License, or | |
21976 | + * (at your option) any later version. | |
dece6358 AM |
21977 | + * |
21978 | + * This program is distributed in the hope that it will be useful, | |
21979 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21980 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21981 | + * GNU General Public License for more details. | |
21982 | + * | |
21983 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21984 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21985 | + */ |
21986 | + | |
21987 | +/* | |
21988 | + * support for loopback block device as a branch | |
21989 | + */ | |
21990 | + | |
1facf9fc | 21991 | +#include "aufs.h" |
21992 | + | |
392086de AM |
21993 | +/* added into drivers/block/loop.c */ |
21994 | +static struct file *(*backing_file_func)(struct super_block *sb); | |
21995 | + | |
1facf9fc | 21996 | +/* |
21997 | + * test if two lower dentries have overlapping branches. | |
21998 | + */ | |
b752ccd1 | 21999 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding) |
1facf9fc | 22000 | +{ |
b752ccd1 | 22001 | + struct super_block *h_sb; |
392086de AM |
22002 | + struct file *backing_file; |
22003 | + | |
22004 | + if (unlikely(!backing_file_func)) { | |
22005 | + /* don't load "loop" module here */ | |
22006 | + backing_file_func = symbol_get(loop_backing_file); | |
22007 | + if (unlikely(!backing_file_func)) | |
22008 | + /* "loop" module is not loaded */ | |
22009 | + return 0; | |
22010 | + } | |
1facf9fc | 22011 | + |
b752ccd1 | 22012 | + h_sb = h_adding->d_sb; |
392086de AM |
22013 | + backing_file = backing_file_func(h_sb); |
22014 | + if (!backing_file) | |
1facf9fc | 22015 | + return 0; |
22016 | + | |
2000de60 | 22017 | + h_adding = backing_file->f_path.dentry; |
b752ccd1 AM |
22018 | + /* |
22019 | + * h_adding can be local NFS. | |
22020 | + * in this case aufs cannot detect the loop. | |
22021 | + */ | |
22022 | + if (unlikely(h_adding->d_sb == sb)) | |
1facf9fc | 22023 | + return 1; |
b752ccd1 | 22024 | + return !!au_test_subdir(h_adding, sb->s_root); |
1facf9fc | 22025 | +} |
22026 | + | |
22027 | +/* true if a kernel thread named 'loop[0-9].*' accesses a file */ | |
22028 | +int au_test_loopback_kthread(void) | |
22029 | +{ | |
b752ccd1 AM |
22030 | + int ret; |
22031 | + struct task_struct *tsk = current; | |
a2a7ad62 | 22032 | + char c, comm[sizeof(tsk->comm)]; |
b752ccd1 AM |
22033 | + |
22034 | + ret = 0; | |
22035 | + if (tsk->flags & PF_KTHREAD) { | |
a2a7ad62 AM |
22036 | + get_task_comm(comm, tsk); |
22037 | + c = comm[4]; | |
b752ccd1 | 22038 | + ret = ('0' <= c && c <= '9' |
a2a7ad62 | 22039 | + && !strncmp(comm, "loop", 4)); |
b752ccd1 | 22040 | + } |
1facf9fc | 22041 | + |
b752ccd1 | 22042 | + return ret; |
1facf9fc | 22043 | +} |
87a755f4 AM |
22044 | + |
22045 | +/* ---------------------------------------------------------------------- */ | |
22046 | + | |
22047 | +#define au_warn_loopback_step 16 | |
22048 | +static int au_warn_loopback_nelem = au_warn_loopback_step; | |
22049 | +static unsigned long *au_warn_loopback_array; | |
22050 | + | |
22051 | +void au_warn_loopback(struct super_block *h_sb) | |
22052 | +{ | |
22053 | + int i, new_nelem; | |
22054 | + unsigned long *a, magic; | |
22055 | + static DEFINE_SPINLOCK(spin); | |
22056 | + | |
22057 | + magic = h_sb->s_magic; | |
22058 | + spin_lock(&spin); | |
22059 | + a = au_warn_loopback_array; | |
22060 | + for (i = 0; i < au_warn_loopback_nelem && *a; i++) | |
22061 | + if (a[i] == magic) { | |
22062 | + spin_unlock(&spin); | |
22063 | + return; | |
22064 | + } | |
22065 | + | |
22066 | + /* h_sb is new to us, print it */ | |
22067 | + if (i < au_warn_loopback_nelem) { | |
22068 | + a[i] = magic; | |
22069 | + goto pr; | |
22070 | + } | |
22071 | + | |
22072 | + /* expand the array */ | |
22073 | + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step; | |
22074 | + a = au_kzrealloc(au_warn_loopback_array, | |
22075 | + au_warn_loopback_nelem * sizeof(unsigned long), | |
e2f27e51 AM |
22076 | + new_nelem * sizeof(unsigned long), GFP_ATOMIC, |
22077 | + /*may_shrink*/0); | |
87a755f4 AM |
22078 | + if (a) { |
22079 | + au_warn_loopback_nelem = new_nelem; | |
22080 | + au_warn_loopback_array = a; | |
22081 | + a[i] = magic; | |
22082 | + goto pr; | |
22083 | + } | |
22084 | + | |
22085 | + spin_unlock(&spin); | |
22086 | + AuWarn1("realloc failed, ignored\n"); | |
22087 | + return; | |
22088 | + | |
22089 | +pr: | |
22090 | + spin_unlock(&spin); | |
0c3ec466 AM |
22091 | + pr_warn("you may want to try another patch for loopback file " |
22092 | + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic); | |
87a755f4 AM |
22093 | +} |
22094 | + | |
22095 | +int au_loopback_init(void) | |
22096 | +{ | |
22097 | + int err; | |
22098 | + struct super_block *sb __maybe_unused; | |
22099 | + | |
79b8bda9 | 22100 | + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long)); |
87a755f4 AM |
22101 | + |
22102 | + err = 0; | |
22103 | + au_warn_loopback_array = kcalloc(au_warn_loopback_step, | |
22104 | + sizeof(unsigned long), GFP_NOFS); | |
22105 | + if (unlikely(!au_warn_loopback_array)) | |
22106 | + err = -ENOMEM; | |
22107 | + | |
22108 | + return err; | |
22109 | +} | |
22110 | + | |
22111 | +void au_loopback_fin(void) | |
22112 | +{ | |
79b8bda9 AM |
22113 | + if (backing_file_func) |
22114 | + symbol_put(loop_backing_file); | |
f0c0a007 | 22115 | + au_delayed_kfree(au_warn_loopback_array); |
87a755f4 | 22116 | +} |
7f207e10 AM |
22117 | diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h |
22118 | --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 22119 | +++ linux/fs/aufs/loop.h 2017-05-06 22:16:52.781553511 +0200 |
523b37e3 | 22120 | @@ -0,0 +1,52 @@ |
1facf9fc | 22121 | +/* |
a2654f78 | 22122 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 22123 | + * |
22124 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22125 | + * it under the terms of the GNU General Public License as published by | |
22126 | + * the Free Software Foundation; either version 2 of the License, or | |
22127 | + * (at your option) any later version. | |
dece6358 AM |
22128 | + * |
22129 | + * This program is distributed in the hope that it will be useful, | |
22130 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22131 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22132 | + * GNU General Public License for more details. | |
22133 | + * | |
22134 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22135 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22136 | + */ |
22137 | + | |
22138 | +/* | |
22139 | + * support for loopback mount as a branch | |
22140 | + */ | |
22141 | + | |
22142 | +#ifndef __AUFS_LOOP_H__ | |
22143 | +#define __AUFS_LOOP_H__ | |
22144 | + | |
22145 | +#ifdef __KERNEL__ | |
22146 | + | |
dece6358 AM |
22147 | +struct dentry; |
22148 | +struct super_block; | |
1facf9fc | 22149 | + |
22150 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
392086de AM |
22151 | +/* drivers/block/loop.c */ |
22152 | +struct file *loop_backing_file(struct super_block *sb); | |
22153 | + | |
1facf9fc | 22154 | +/* loop.c */ |
b752ccd1 | 22155 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding); |
1facf9fc | 22156 | +int au_test_loopback_kthread(void); |
87a755f4 AM |
22157 | +void au_warn_loopback(struct super_block *h_sb); |
22158 | + | |
22159 | +int au_loopback_init(void); | |
22160 | +void au_loopback_fin(void); | |
1facf9fc | 22161 | +#else |
4a4d8108 | 22162 | +AuStubInt0(au_test_loopback_overlap, struct super_block *sb, |
b752ccd1 | 22163 | + struct dentry *h_adding) |
4a4d8108 | 22164 | +AuStubInt0(au_test_loopback_kthread, void) |
87a755f4 AM |
22165 | +AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
22166 | + | |
22167 | +AuStubInt0(au_loopback_init, void) | |
22168 | +AuStubVoid(au_loopback_fin, void) | |
1facf9fc | 22169 | +#endif /* BLK_DEV_LOOP */ |
22170 | + | |
22171 | +#endif /* __KERNEL__ */ | |
22172 | +#endif /* __AUFS_LOOP_H__ */ | |
7f207e10 AM |
22173 | diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk |
22174 | --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 22175 | +++ linux/fs/aufs/magic.mk 2017-05-06 22:16:52.781553511 +0200 |
7e9cd9fe | 22176 | @@ -0,0 +1,30 @@ |
1facf9fc | 22177 | + |
22178 | +# defined in ${srctree}/fs/fuse/inode.c | |
22179 | +# tristate | |
22180 | +ifdef CONFIG_FUSE_FS | |
22181 | +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546 | |
22182 | +endif | |
22183 | + | |
1facf9fc | 22184 | +# defined in ${srctree}/fs/xfs/xfs_sb.h |
22185 | +# tristate | |
22186 | +ifdef CONFIG_XFS_FS | |
22187 | +ccflags-y += -DXFS_SB_MAGIC=0x58465342 | |
22188 | +endif | |
22189 | + | |
22190 | +# defined in ${srctree}/fs/configfs/mount.c | |
22191 | +# tristate | |
22192 | +ifdef CONFIG_CONFIGFS_FS | |
22193 | +ccflags-y += -DCONFIGFS_MAGIC=0x62656570 | |
22194 | +endif | |
22195 | + | |
1facf9fc | 22196 | +# defined in ${srctree}/fs/ubifs/ubifs.h |
22197 | +# tristate | |
22198 | +ifdef CONFIG_UBIFS_FS | |
22199 | +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905 | |
22200 | +endif | |
4a4d8108 AM |
22201 | + |
22202 | +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h | |
22203 | +# tristate | |
22204 | +ifdef CONFIG_HFSPLUS_FS | |
22205 | +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b | |
22206 | +endif | |
7f207e10 AM |
22207 | diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile |
22208 | --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 22209 | +++ linux/fs/aufs/Makefile 2017-05-06 22:16:52.774886674 +0200 |
c1595e42 | 22210 | @@ -0,0 +1,44 @@ |
4a4d8108 AM |
22211 | + |
22212 | +include ${src}/magic.mk | |
22213 | +ifeq (${CONFIG_AUFS_FS},m) | |
22214 | +include ${src}/conf.mk | |
22215 | +endif | |
22216 | +-include ${src}/priv_def.mk | |
22217 | + | |
22218 | +# cf. include/linux/kernel.h | |
22219 | +# enable pr_debug | |
22220 | +ccflags-y += -DDEBUG | |
f6c5ef8b AM |
22221 | +# sparse requires the full pathname |
22222 | +ifdef M | |
523b37e3 | 22223 | +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h |
f6c5ef8b | 22224 | +else |
523b37e3 | 22225 | +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h |
f6c5ef8b | 22226 | +endif |
4a4d8108 AM |
22227 | + |
22228 | +obj-$(CONFIG_AUFS_FS) += aufs.o | |
22229 | +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \ | |
22230 | + wkq.o vfsub.o dcsub.o \ | |
e49829fe | 22231 | + cpup.o whout.o wbr_policy.o \ |
4a4d8108 AM |
22232 | + dinfo.o dentry.o \ |
22233 | + dynop.o \ | |
22234 | + finfo.o file.o f_op.o \ | |
22235 | + dir.o vdir.o \ | |
22236 | + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \ | |
c2b27bf2 | 22237 | + mvdown.o ioctl.o |
4a4d8108 AM |
22238 | + |
22239 | +# all are boolean | |
e49829fe | 22240 | +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o |
4a4d8108 AM |
22241 | +aufs-$(CONFIG_SYSFS) += sysfs.o |
22242 | +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o | |
22243 | +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o | |
22244 | +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o | |
22245 | +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o | |
4a4d8108 | 22246 | +aufs-$(CONFIG_AUFS_EXPORT) += export.o |
c1595e42 JR |
22247 | +aufs-$(CONFIG_AUFS_XATTR) += xattr.o |
22248 | +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o | |
076b876e | 22249 | +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o |
4a4d8108 AM |
22250 | +aufs-$(CONFIG_AUFS_POLL) += poll.o |
22251 | +aufs-$(CONFIG_AUFS_RDU) += rdu.o | |
4a4d8108 AM |
22252 | +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o |
22253 | +aufs-$(CONFIG_AUFS_DEBUG) += debug.o | |
22254 | +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o | |
7f207e10 AM |
22255 | diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c |
22256 | --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 22257 | +++ linux/fs/aufs/module.c 2017-05-06 22:16:52.781553511 +0200 |
e2f27e51 | 22258 | @@ -0,0 +1,333 @@ |
1facf9fc | 22259 | +/* |
a2654f78 | 22260 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 22261 | + * |
22262 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22263 | + * it under the terms of the GNU General Public License as published by | |
22264 | + * the Free Software Foundation; either version 2 of the License, or | |
22265 | + * (at your option) any later version. | |
dece6358 AM |
22266 | + * |
22267 | + * This program is distributed in the hope that it will be useful, | |
22268 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22269 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22270 | + * GNU General Public License for more details. | |
22271 | + * | |
22272 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22273 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22274 | + */ |
22275 | + | |
22276 | +/* | |
22277 | + * module global variables and operations | |
22278 | + */ | |
22279 | + | |
22280 | +#include <linux/module.h> | |
22281 | +#include <linux/seq_file.h> | |
22282 | +#include "aufs.h" | |
22283 | + | |
e2f27e51 AM |
22284 | +/* shrinkable realloc */ |
22285 | +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink) | |
1facf9fc | 22286 | +{ |
e2f27e51 AM |
22287 | + size_t sz; |
22288 | + int diff; | |
1facf9fc | 22289 | + |
e2f27e51 AM |
22290 | + sz = 0; |
22291 | + diff = -1; | |
22292 | + if (p) { | |
22293 | +#if 0 /* unused */ | |
22294 | + if (!new_sz) { | |
22295 | + au_delayed_kfree(p); | |
22296 | + p = NULL; | |
22297 | + goto out; | |
22298 | + } | |
22299 | +#else | |
22300 | + AuDebugOn(!new_sz); | |
22301 | +#endif | |
22302 | + sz = ksize(p); | |
22303 | + diff = au_kmidx_sub(sz, new_sz); | |
22304 | + } | |
22305 | + if (sz && !diff) | |
22306 | + goto out; | |
22307 | + | |
22308 | + if (sz < new_sz) | |
22309 | + /* expand or SLOB */ | |
22310 | + p = krealloc(p, new_sz, gfp); | |
22311 | + else if (new_sz < sz && may_shrink) { | |
22312 | + /* shrink */ | |
22313 | + void *q; | |
22314 | + | |
22315 | + q = kmalloc(new_sz, gfp); | |
22316 | + if (q) { | |
22317 | + if (p) { | |
22318 | + memcpy(q, p, new_sz); | |
22319 | + au_delayed_kfree(p); | |
22320 | + } | |
22321 | + p = q; | |
22322 | + } else | |
22323 | + p = NULL; | |
22324 | + } | |
22325 | + | |
22326 | +out: | |
22327 | + return p; | |
22328 | +} | |
22329 | + | |
22330 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp, | |
22331 | + int may_shrink) | |
22332 | +{ | |
22333 | + p = au_krealloc(p, new_sz, gfp, may_shrink); | |
22334 | + if (p && new_sz > nused) | |
1facf9fc | 22335 | + memset(p + nused, 0, new_sz - nused); |
22336 | + return p; | |
22337 | +} | |
22338 | + | |
22339 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 22340 | +/* |
22341 | + * aufs caches | |
22342 | + */ | |
f0c0a007 AM |
22343 | + |
22344 | +struct au_dfree au_dfree; | |
22345 | + | |
22346 | +/* delayed free */ | |
22347 | +static void au_do_dfree(struct work_struct *work __maybe_unused) | |
22348 | +{ | |
22349 | + struct llist_head *head; | |
22350 | + struct llist_node *node, *next; | |
22351 | + | |
22352 | +#define AU_CACHE_DFREE_DO_BODY(name, idx, lnode) do { \ | |
22353 | + head = &au_dfree.cache[AuCache_##idx].llist; \ | |
22354 | + node = llist_del_all(head); \ | |
22355 | + for (; node; node = next) { \ | |
e2f27e51 AM |
22356 | + struct au_##name *p \ |
22357 | + = llist_entry(node, struct au_##name, \ | |
22358 | + lnode); \ | |
f0c0a007 AM |
22359 | + next = llist_next(node); \ |
22360 | + au_cache_free_##name(p); \ | |
22361 | + } \ | |
22362 | + } while (0) | |
22363 | + | |
22364 | + AU_CACHE_DFREE_DO_BODY(dinfo, DINFO, di_lnode); | |
22365 | + AU_CACHE_DFREE_DO_BODY(icntnr, ICNTNR, lnode); | |
22366 | + AU_CACHE_DFREE_DO_BODY(finfo, FINFO, fi_lnode); | |
22367 | + AU_CACHE_DFREE_DO_BODY(vdir, VDIR, vd_lnode); | |
22368 | + AU_CACHE_DFREE_DO_BODY(vdir_dehstr, DEHSTR, lnode); | |
22369 | +#ifdef CONFIG_AUFS_HNOTIFY | |
22370 | + AU_CACHE_DFREE_DO_BODY(hnotify, HNOTIFY, hn_lnode); | |
22371 | +#endif | |
22372 | + | |
22373 | +#define AU_DFREE_DO_BODY(llist, func) do { \ | |
22374 | + node = llist_del_all(llist); \ | |
22375 | + for (; node; node = next) { \ | |
22376 | + next = llist_next(node); \ | |
22377 | + func(node); \ | |
22378 | + } \ | |
22379 | + } while (0) | |
22380 | + | |
22381 | + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_KFREE, kfree); | |
22382 | + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_FREE_PAGE, au_free_page); | |
22383 | + | |
22384 | +#undef AU_CACHE_DFREE_DO_BODY | |
22385 | +#undef AU_DFREE_DO_BODY | |
22386 | +} | |
22387 | + | |
22388 | +AU_CACHE_DFREE_FUNC(dinfo, DINFO, di_lnode); | |
22389 | +AU_CACHE_DFREE_FUNC(icntnr, ICNTNR, lnode); | |
22390 | +AU_CACHE_DFREE_FUNC(finfo, FINFO, fi_lnode); | |
22391 | +AU_CACHE_DFREE_FUNC(vdir, VDIR, vd_lnode); | |
22392 | +AU_CACHE_DFREE_FUNC(vdir_dehstr, DEHSTR, lnode); | |
5afbbe0d AM |
22393 | + |
22394 | +static void au_cache_fin(void) | |
22395 | +{ | |
22396 | + int i; | |
f0c0a007 | 22397 | + struct au_cache *cp; |
5afbbe0d AM |
22398 | + |
22399 | + /* | |
22400 | + * Make sure all delayed rcu free inodes are flushed before we | |
22401 | + * destroy cache. | |
22402 | + */ | |
22403 | + rcu_barrier(); | |
22404 | + | |
22405 | + /* excluding AuCache_HNOTIFY */ | |
22406 | + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last); | |
f0c0a007 | 22407 | + flush_delayed_work(&au_dfree.dwork); |
5afbbe0d | 22408 | + for (i = 0; i < AuCache_HNOTIFY; i++) { |
f0c0a007 AM |
22409 | + cp = au_dfree.cache + i; |
22410 | + AuDebugOn(!llist_empty(&cp->llist)); | |
22411 | + kmem_cache_destroy(cp->cache); | |
22412 | + cp->cache = NULL; | |
5afbbe0d AM |
22413 | + } |
22414 | +} | |
22415 | + | |
1facf9fc | 22416 | +static int __init au_cache_init(void) |
22417 | +{ | |
f0c0a007 AM |
22418 | + struct au_cache *cp; |
22419 | + | |
22420 | + cp = au_dfree.cache; | |
22421 | + cp[AuCache_DINFO].cache = AuCacheCtor(au_dinfo, au_di_init_once); | |
22422 | + if (cp[AuCache_DINFO].cache) | |
027c5e7a | 22423 | + /* SLAB_DESTROY_BY_RCU */ |
f0c0a007 AM |
22424 | + cp[AuCache_ICNTNR].cache = AuCacheCtor(au_icntnr, |
22425 | + au_icntnr_init_once); | |
22426 | + if (cp[AuCache_ICNTNR].cache) | |
22427 | + cp[AuCache_FINFO].cache = AuCacheCtor(au_finfo, | |
22428 | + au_fi_init_once); | |
22429 | + if (cp[AuCache_FINFO].cache) | |
22430 | + cp[AuCache_VDIR].cache = AuCache(au_vdir); | |
22431 | + if (cp[AuCache_VDIR].cache) | |
22432 | + cp[AuCache_DEHSTR].cache = AuCache(au_vdir_dehstr); | |
22433 | + if (cp[AuCache_DEHSTR].cache) | |
1facf9fc | 22434 | + return 0; |
22435 | + | |
5afbbe0d | 22436 | + au_cache_fin(); |
1facf9fc | 22437 | + return -ENOMEM; |
22438 | +} | |
22439 | + | |
1facf9fc | 22440 | +/* ---------------------------------------------------------------------- */ |
22441 | + | |
22442 | +int au_dir_roflags; | |
22443 | + | |
e49829fe | 22444 | +#ifdef CONFIG_AUFS_SBILIST |
1e00d052 AM |
22445 | +/* |
22446 | + * iterate_supers_type() doesn't protect us from | |
22447 | + * remounting (branch management) | |
22448 | + */ | |
5afbbe0d | 22449 | +struct au_sphlhead au_sbilist; |
e49829fe JR |
22450 | +#endif |
22451 | + | |
1facf9fc | 22452 | +/* |
22453 | + * functions for module interface. | |
22454 | + */ | |
22455 | +MODULE_LICENSE("GPL"); | |
22456 | +/* MODULE_LICENSE("GPL v2"); */ | |
dece6358 | 22457 | +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>"); |
1facf9fc | 22458 | +MODULE_DESCRIPTION(AUFS_NAME |
22459 | + " -- Advanced multi layered unification filesystem"); | |
22460 | +MODULE_VERSION(AUFS_VERSION); | |
c06a8ce3 | 22461 | +MODULE_ALIAS_FS(AUFS_NAME); |
1facf9fc | 22462 | + |
1facf9fc | 22463 | +/* this module parameter has no meaning when SYSFS is disabled */ |
22464 | +int sysaufs_brs = 1; | |
22465 | +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN"); | |
22466 | +module_param_named(brs, sysaufs_brs, int, S_IRUGO); | |
22467 | + | |
076b876e | 22468 | +/* this module parameter has no meaning when USER_NS is disabled */ |
8cdd5066 | 22469 | +bool au_userns; |
076b876e AM |
22470 | +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns"); |
22471 | +module_param_named(allow_userns, au_userns, bool, S_IRUGO); | |
22472 | + | |
1facf9fc | 22473 | +/* ---------------------------------------------------------------------- */ |
22474 | + | |
22475 | +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */ | |
22476 | + | |
22477 | +int au_seq_path(struct seq_file *seq, struct path *path) | |
22478 | +{ | |
79b8bda9 AM |
22479 | + int err; |
22480 | + | |
22481 | + err = seq_path(seq, path, au_esc_chars); | |
22482 | + if (err > 0) | |
22483 | + err = 0; | |
22484 | + else if (err < 0) | |
22485 | + err = -ENOMEM; | |
22486 | + | |
22487 | + return err; | |
1facf9fc | 22488 | +} |
22489 | + | |
22490 | +/* ---------------------------------------------------------------------- */ | |
22491 | + | |
22492 | +static int __init aufs_init(void) | |
22493 | +{ | |
22494 | + int err, i; | |
22495 | + char *p; | |
f0c0a007 | 22496 | + struct au_cache *cp; |
1facf9fc | 22497 | + |
22498 | + p = au_esc_chars; | |
22499 | + for (i = 1; i <= ' '; i++) | |
22500 | + *p++ = i; | |
22501 | + *p++ = '\\'; | |
22502 | + *p++ = '\x7f'; | |
22503 | + *p = 0; | |
22504 | + | |
22505 | + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE); | |
22506 | + | |
b95c5147 AM |
22507 | + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop)); |
22508 | + for (i = 0; i < AuIop_Last; i++) | |
22509 | + aufs_iop_nogetattr[i].getattr = NULL; | |
22510 | + | |
f0c0a007 AM |
22511 | + /* First, initialize au_dfree */ |
22512 | + for (i = 0; i < AuCache_Last; i++) { /* including hnotify */ | |
22513 | + cp = au_dfree.cache + i; | |
22514 | + cp->cache = NULL; | |
22515 | + init_llist_head(&cp->llist); | |
22516 | + } | |
22517 | + for (i = 0; i < AU_DFREE_Last; i++) | |
22518 | + init_llist_head(au_dfree.llist + i); | |
22519 | + INIT_DELAYED_WORK(&au_dfree.dwork, au_do_dfree); | |
22520 | + | |
e49829fe | 22521 | + au_sbilist_init(); |
1facf9fc | 22522 | + sysaufs_brs_init(); |
22523 | + au_debug_init(); | |
4a4d8108 | 22524 | + au_dy_init(); |
1facf9fc | 22525 | + err = sysaufs_init(); |
22526 | + if (unlikely(err)) | |
22527 | + goto out; | |
e49829fe | 22528 | + err = au_procfs_init(); |
4f0767ce | 22529 | + if (unlikely(err)) |
953406b4 | 22530 | + goto out_sysaufs; |
e49829fe JR |
22531 | + err = au_wkq_init(); |
22532 | + if (unlikely(err)) | |
22533 | + goto out_procfs; | |
87a755f4 | 22534 | + err = au_loopback_init(); |
1facf9fc | 22535 | + if (unlikely(err)) |
22536 | + goto out_wkq; | |
87a755f4 AM |
22537 | + err = au_hnotify_init(); |
22538 | + if (unlikely(err)) | |
22539 | + goto out_loopback; | |
1facf9fc | 22540 | + err = au_sysrq_init(); |
22541 | + if (unlikely(err)) | |
22542 | + goto out_hin; | |
22543 | + err = au_cache_init(); | |
22544 | + if (unlikely(err)) | |
22545 | + goto out_sysrq; | |
076b876e AM |
22546 | + |
22547 | + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0; | |
1facf9fc | 22548 | + err = register_filesystem(&aufs_fs_type); |
22549 | + if (unlikely(err)) | |
22550 | + goto out_cache; | |
076b876e | 22551 | + |
4a4d8108 AM |
22552 | + /* since we define pr_fmt, call printk directly */ |
22553 | + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n"); | |
1facf9fc | 22554 | + goto out; /* success */ |
22555 | + | |
4f0767ce | 22556 | +out_cache: |
1facf9fc | 22557 | + au_cache_fin(); |
4f0767ce | 22558 | +out_sysrq: |
1facf9fc | 22559 | + au_sysrq_fin(); |
4f0767ce | 22560 | +out_hin: |
4a4d8108 | 22561 | + au_hnotify_fin(); |
87a755f4 AM |
22562 | +out_loopback: |
22563 | + au_loopback_fin(); | |
4f0767ce | 22564 | +out_wkq: |
1facf9fc | 22565 | + au_wkq_fin(); |
e49829fe JR |
22566 | +out_procfs: |
22567 | + au_procfs_fin(); | |
4f0767ce | 22568 | +out_sysaufs: |
1facf9fc | 22569 | + sysaufs_fin(); |
4a4d8108 | 22570 | + au_dy_fin(); |
f0c0a007 | 22571 | + flush_delayed_work(&au_dfree.dwork); |
4f0767ce | 22572 | +out: |
1facf9fc | 22573 | + return err; |
22574 | +} | |
22575 | + | |
22576 | +static void __exit aufs_exit(void) | |
22577 | +{ | |
22578 | + unregister_filesystem(&aufs_fs_type); | |
22579 | + au_cache_fin(); | |
22580 | + au_sysrq_fin(); | |
4a4d8108 | 22581 | + au_hnotify_fin(); |
87a755f4 | 22582 | + au_loopback_fin(); |
1facf9fc | 22583 | + au_wkq_fin(); |
e49829fe | 22584 | + au_procfs_fin(); |
1facf9fc | 22585 | + sysaufs_fin(); |
4a4d8108 | 22586 | + au_dy_fin(); |
f0c0a007 | 22587 | + flush_delayed_work(&au_dfree.dwork); |
1facf9fc | 22588 | +} |
22589 | + | |
22590 | +module_init(aufs_init); | |
22591 | +module_exit(aufs_exit); | |
7f207e10 AM |
22592 | diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h |
22593 | --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 22594 | +++ linux/fs/aufs/module.h 2017-05-06 22:16:52.781553511 +0200 |
e2f27e51 | 22595 | @@ -0,0 +1,156 @@ |
1facf9fc | 22596 | +/* |
a2654f78 | 22597 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 22598 | + * |
22599 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22600 | + * it under the terms of the GNU General Public License as published by | |
22601 | + * the Free Software Foundation; either version 2 of the License, or | |
22602 | + * (at your option) any later version. | |
dece6358 AM |
22603 | + * |
22604 | + * This program is distributed in the hope that it will be useful, | |
22605 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22606 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22607 | + * GNU General Public License for more details. | |
22608 | + * | |
22609 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22610 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22611 | + */ |
22612 | + | |
22613 | +/* | |
22614 | + * module initialization and module-global | |
22615 | + */ | |
22616 | + | |
22617 | +#ifndef __AUFS_MODULE_H__ | |
22618 | +#define __AUFS_MODULE_H__ | |
22619 | + | |
22620 | +#ifdef __KERNEL__ | |
22621 | + | |
22622 | +#include <linux/slab.h> | |
f0c0a007 | 22623 | +#include "debug.h" |
1facf9fc | 22624 | + |
dece6358 AM |
22625 | +struct path; |
22626 | +struct seq_file; | |
22627 | + | |
1facf9fc | 22628 | +/* module parameters */ |
1facf9fc | 22629 | +extern int sysaufs_brs; |
8cdd5066 | 22630 | +extern bool au_userns; |
1facf9fc | 22631 | + |
22632 | +/* ---------------------------------------------------------------------- */ | |
22633 | + | |
22634 | +extern int au_dir_roflags; | |
22635 | + | |
e2f27e51 AM |
22636 | +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink); |
22637 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp, | |
22638 | + int may_shrink); | |
22639 | + | |
22640 | +static inline int au_kmidx_sub(size_t sz, size_t new_sz) | |
22641 | +{ | |
22642 | +#ifndef CONFIG_SLOB | |
22643 | + return kmalloc_index(sz) - kmalloc_index(new_sz); | |
22644 | +#else | |
22645 | + return -1; /* SLOB is untested */ | |
22646 | +#endif | |
22647 | +} | |
22648 | + | |
1facf9fc | 22649 | +int au_seq_path(struct seq_file *seq, struct path *path); |
22650 | + | |
e49829fe JR |
22651 | +#ifdef CONFIG_PROC_FS |
22652 | +/* procfs.c */ | |
22653 | +int __init au_procfs_init(void); | |
22654 | +void au_procfs_fin(void); | |
22655 | +#else | |
22656 | +AuStubInt0(au_procfs_init, void); | |
22657 | +AuStubVoid(au_procfs_fin, void); | |
22658 | +#endif | |
22659 | + | |
4f0767ce JR |
22660 | +/* ---------------------------------------------------------------------- */ |
22661 | + | |
f0c0a007 | 22662 | +/* kmem cache and delayed free */ |
1facf9fc | 22663 | +enum { |
22664 | + AuCache_DINFO, | |
22665 | + AuCache_ICNTNR, | |
22666 | + AuCache_FINFO, | |
22667 | + AuCache_VDIR, | |
22668 | + AuCache_DEHSTR, | |
7eafdf33 | 22669 | + AuCache_HNOTIFY, /* must be last */ |
1facf9fc | 22670 | + AuCache_Last |
22671 | +}; | |
22672 | + | |
f0c0a007 AM |
22673 | +enum { |
22674 | + AU_DFREE_KFREE, | |
22675 | + AU_DFREE_FREE_PAGE, | |
22676 | + AU_DFREE_Last | |
22677 | +}; | |
22678 | + | |
22679 | +struct au_cache { | |
22680 | + struct kmem_cache *cache; | |
22681 | + struct llist_head llist; /* delayed free */ | |
22682 | +}; | |
22683 | + | |
22684 | +/* | |
22685 | + * in order to reduce the cost of the internal timer, consolidate all the | |
22686 | + * delayed free works into a single delayed_work. | |
22687 | + */ | |
22688 | +struct au_dfree { | |
22689 | + struct au_cache cache[AuCache_Last]; | |
22690 | + struct llist_head llist[AU_DFREE_Last]; | |
22691 | + struct delayed_work dwork; | |
22692 | +}; | |
22693 | + | |
22694 | +extern struct au_dfree au_dfree; | |
22695 | + | |
4a4d8108 AM |
22696 | +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD) |
22697 | +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags) | |
22698 | +#define AuCacheCtor(type, ctor) \ | |
22699 | + kmem_cache_create(#type, sizeof(struct type), \ | |
22700 | + __alignof__(struct type), AuCacheFlags, ctor) | |
1facf9fc | 22701 | + |
f0c0a007 AM |
22702 | +#define AU_DFREE_DELAY msecs_to_jiffies(10) |
22703 | +#define AU_DFREE_BODY(lnode, llist) do { \ | |
22704 | + if (llist_add(lnode, llist)) \ | |
22705 | + schedule_delayed_work(&au_dfree.dwork, \ | |
22706 | + AU_DFREE_DELAY); \ | |
22707 | + } while (0) | |
22708 | +#define AU_CACHE_DFREE_FUNC(name, idx, lnode) \ | |
22709 | + void au_cache_dfree_##name(struct au_##name *p) \ | |
22710 | + { \ | |
22711 | + struct au_cache *cp = au_dfree.cache + AuCache_##idx; \ | |
22712 | + AU_DFREE_BODY(&p->lnode, &cp->llist); \ | |
22713 | + } | |
1facf9fc | 22714 | + |
22715 | +#define AuCacheFuncs(name, index) \ | |
4a4d8108 | 22716 | +static inline struct au_##name *au_cache_alloc_##name(void) \ |
f0c0a007 | 22717 | +{ return kmem_cache_alloc(au_dfree.cache[AuCache_##index].cache, GFP_NOFS); } \ |
4a4d8108 | 22718 | +static inline void au_cache_free_##name(struct au_##name *p) \ |
f0c0a007 AM |
22719 | +{ kmem_cache_free(au_dfree.cache[AuCache_##index].cache, p); } \ |
22720 | +void au_cache_dfree_##name(struct au_##name *p) | |
1facf9fc | 22721 | + |
22722 | +AuCacheFuncs(dinfo, DINFO); | |
22723 | +AuCacheFuncs(icntnr, ICNTNR); | |
22724 | +AuCacheFuncs(finfo, FINFO); | |
22725 | +AuCacheFuncs(vdir, VDIR); | |
4a4d8108 AM |
22726 | +AuCacheFuncs(vdir_dehstr, DEHSTR); |
22727 | +#ifdef CONFIG_AUFS_HNOTIFY | |
22728 | +AuCacheFuncs(hnotify, HNOTIFY); | |
22729 | +#endif | |
1facf9fc | 22730 | + |
f0c0a007 AM |
22731 | +static inline void au_delayed_kfree(const void *p) |
22732 | +{ | |
22733 | + AuDebugOn(!p); | |
22734 | + AuDebugOn(ksize(p) < sizeof(struct llist_node)); | |
22735 | + | |
22736 | + AU_DFREE_BODY((void *)p, au_dfree.llist + AU_DFREE_KFREE); | |
22737 | +} | |
22738 | + | |
22739 | +/* cast only */ | |
22740 | +static inline void au_free_page(void *p) | |
22741 | +{ | |
22742 | + free_page((unsigned long)p); | |
22743 | +} | |
22744 | + | |
22745 | +static inline void au_delayed_free_page(unsigned long addr) | |
22746 | +{ | |
22747 | + AU_DFREE_BODY((void *)addr, au_dfree.llist + AU_DFREE_FREE_PAGE); | |
22748 | +} | |
22749 | + | |
4a4d8108 AM |
22750 | +#endif /* __KERNEL__ */ |
22751 | +#endif /* __AUFS_MODULE_H__ */ | |
c2b27bf2 AM |
22752 | diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c |
22753 | --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 22754 | +++ linux/fs/aufs/mvdown.c 2017-05-06 22:16:52.781553511 +0200 |
5afbbe0d | 22755 | @@ -0,0 +1,704 @@ |
c2b27bf2 | 22756 | +/* |
a2654f78 | 22757 | + * Copyright (C) 2011-2017 Junjiro R. Okajima |
c2b27bf2 AM |
22758 | + * |
22759 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22760 | + * it under the terms of the GNU General Public License as published by | |
22761 | + * the Free Software Foundation; either version 2 of the License, or | |
22762 | + * (at your option) any later version. | |
22763 | + * | |
22764 | + * This program is distributed in the hope that it will be useful, | |
22765 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22766 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22767 | + * GNU General Public License for more details. | |
22768 | + * | |
22769 | + * You should have received a copy of the GNU General Public License | |
523b37e3 AM |
22770 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
22771 | + */ | |
22772 | + | |
22773 | +/* | |
22774 | + * move-down, opposite of copy-up | |
c2b27bf2 AM |
22775 | + */ |
22776 | + | |
22777 | +#include "aufs.h" | |
22778 | + | |
c2b27bf2 AM |
22779 | +struct au_mvd_args { |
22780 | + struct { | |
c2b27bf2 AM |
22781 | + struct super_block *h_sb; |
22782 | + struct dentry *h_parent; | |
22783 | + struct au_hinode *hdir; | |
392086de | 22784 | + struct inode *h_dir, *h_inode; |
c1595e42 | 22785 | + struct au_pin pin; |
c2b27bf2 AM |
22786 | + } info[AUFS_MVDOWN_NARRAY]; |
22787 | + | |
22788 | + struct aufs_mvdown mvdown; | |
22789 | + struct dentry *dentry, *parent; | |
22790 | + struct inode *inode, *dir; | |
22791 | + struct super_block *sb; | |
22792 | + aufs_bindex_t bopq, bwh, bfound; | |
22793 | + unsigned char rename_lock; | |
c2b27bf2 AM |
22794 | +}; |
22795 | + | |
392086de | 22796 | +#define mvd_errno mvdown.au_errno |
076b876e AM |
22797 | +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex |
22798 | +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid | |
22799 | +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex | |
22800 | +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid | |
c2b27bf2 | 22801 | + |
392086de AM |
22802 | +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb |
22803 | +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent | |
22804 | +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir | |
22805 | +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir | |
22806 | +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode | |
c1595e42 | 22807 | +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin |
392086de AM |
22808 | + |
22809 | +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb | |
22810 | +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent | |
22811 | +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir | |
22812 | +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir | |
22813 | +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode | |
c1595e42 | 22814 | +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin |
c2b27bf2 AM |
22815 | + |
22816 | +#define AU_MVD_PR(flag, ...) do { \ | |
22817 | + if (flag) \ | |
22818 | + pr_err(__VA_ARGS__); \ | |
22819 | + } while (0) | |
22820 | + | |
076b876e AM |
22821 | +static int find_lower_writable(struct au_mvd_args *a) |
22822 | +{ | |
22823 | + struct super_block *sb; | |
5afbbe0d | 22824 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
22825 | + struct au_branch *br; |
22826 | + | |
22827 | + sb = a->sb; | |
22828 | + bindex = a->mvd_bsrc; | |
5afbbe0d | 22829 | + bbot = au_sbbot(sb); |
076b876e | 22830 | + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER) |
5afbbe0d | 22831 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e AM |
22832 | + br = au_sbr(sb, bindex); |
22833 | + if (au_br_fhsm(br->br_perm) | |
22834 | + && (!(au_br_sb(br)->s_flags & MS_RDONLY))) | |
22835 | + return bindex; | |
22836 | + } | |
22837 | + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) | |
5afbbe0d | 22838 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e AM |
22839 | + br = au_sbr(sb, bindex); |
22840 | + if (!au_br_rdonly(br)) | |
22841 | + return bindex; | |
22842 | + } | |
22843 | + else | |
5afbbe0d | 22844 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e AM |
22845 | + br = au_sbr(sb, bindex); |
22846 | + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) { | |
22847 | + if (au_br_rdonly(br)) | |
22848 | + a->mvdown.flags | |
22849 | + |= AUFS_MVDOWN_ROLOWER_R; | |
22850 | + return bindex; | |
22851 | + } | |
22852 | + } | |
22853 | + | |
22854 | + return -1; | |
22855 | +} | |
22856 | + | |
c2b27bf2 | 22857 | +/* make the parent dir on bdst */ |
392086de | 22858 | +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22859 | +{ |
22860 | + int err; | |
22861 | + | |
22862 | + err = 0; | |
22863 | + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc); | |
22864 | + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst); | |
22865 | + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc); | |
22866 | + a->mvd_h_dst_parent = NULL; | |
5afbbe0d | 22867 | + if (au_dbbot(a->parent) >= a->mvd_bdst) |
c2b27bf2 AM |
22868 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); |
22869 | + if (!a->mvd_h_dst_parent) { | |
22870 | + err = au_cpdown_dirs(a->dentry, a->mvd_bdst); | |
22871 | + if (unlikely(err)) { | |
392086de | 22872 | + AU_MVD_PR(dmsg, "cpdown_dirs failed\n"); |
c2b27bf2 AM |
22873 | + goto out; |
22874 | + } | |
22875 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
22876 | + } | |
22877 | + | |
22878 | +out: | |
22879 | + AuTraceErr(err); | |
22880 | + return err; | |
22881 | +} | |
22882 | + | |
22883 | +/* lock them all */ | |
392086de | 22884 | +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22885 | +{ |
22886 | + int err; | |
22887 | + struct dentry *h_trap; | |
22888 | + | |
22889 | + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc); | |
22890 | + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst); | |
c1595e42 JR |
22891 | + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst, |
22892 | + au_opt_udba(a->sb), | |
22893 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22894 | + AuTraceErr(err); | |
22895 | + if (unlikely(err)) { | |
22896 | + AU_MVD_PR(dmsg, "pin_dst failed\n"); | |
22897 | + goto out; | |
22898 | + } | |
22899 | + | |
c2b27bf2 AM |
22900 | + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) { |
22901 | + a->rename_lock = 0; | |
c1595e42 JR |
22902 | + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, |
22903 | + AuLsc_DI_PARENT, AuLsc_I_PARENT3, | |
22904 | + au_opt_udba(a->sb), | |
22905 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22906 | + err = au_do_pin(&a->mvd_pin_src); | |
22907 | + AuTraceErr(err); | |
5527c038 | 22908 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
22909 | + if (unlikely(err)) { |
22910 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
22911 | + goto out_dst; | |
22912 | + } | |
22913 | + goto out; /* success */ | |
c2b27bf2 AM |
22914 | + } |
22915 | + | |
c2b27bf2 | 22916 | + a->rename_lock = 1; |
c1595e42 JR |
22917 | + au_pin_hdir_unlock(&a->mvd_pin_dst); |
22918 | + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, | |
22919 | + au_opt_udba(a->sb), | |
22920 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22921 | + AuTraceErr(err); | |
5527c038 | 22922 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
22923 | + if (unlikely(err)) { |
22924 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
22925 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22926 | + goto out_dst; | |
22927 | + } | |
22928 | + au_pin_hdir_unlock(&a->mvd_pin_src); | |
c2b27bf2 AM |
22929 | + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
22930 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
22931 | + if (h_trap) { | |
22932 | + err = (h_trap != a->mvd_h_src_parent); | |
22933 | + if (err) | |
22934 | + err = (h_trap != a->mvd_h_dst_parent); | |
22935 | + } | |
22936 | + BUG_ON(err); /* it should never happen */ | |
c1595e42 JR |
22937 | + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) { |
22938 | + err = -EBUSY; | |
22939 | + AuTraceErr(err); | |
22940 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, | |
22941 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
22942 | + au_pin_hdir_lock(&a->mvd_pin_src); | |
22943 | + au_unpin(&a->mvd_pin_src); | |
22944 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22945 | + goto out_dst; | |
22946 | + } | |
22947 | + goto out; /* success */ | |
c2b27bf2 | 22948 | + |
c1595e42 JR |
22949 | +out_dst: |
22950 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
22951 | +out: |
22952 | + AuTraceErr(err); | |
22953 | + return err; | |
22954 | +} | |
22955 | + | |
392086de | 22956 | +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 | 22957 | +{ |
c1595e42 JR |
22958 | + if (!a->rename_lock) |
22959 | + au_unpin(&a->mvd_pin_src); | |
22960 | + else { | |
c2b27bf2 AM |
22961 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
22962 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
c1595e42 JR |
22963 | + au_pin_hdir_lock(&a->mvd_pin_src); |
22964 | + au_unpin(&a->mvd_pin_src); | |
22965 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22966 | + } | |
22967 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
22968 | +} |
22969 | + | |
22970 | +/* copy-down the file */ | |
392086de | 22971 | +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22972 | +{ |
22973 | + int err; | |
22974 | + struct au_cp_generic cpg = { | |
22975 | + .dentry = a->dentry, | |
22976 | + .bdst = a->mvd_bdst, | |
22977 | + .bsrc = a->mvd_bsrc, | |
22978 | + .len = -1, | |
c1595e42 | 22979 | + .pin = &a->mvd_pin_dst, |
c2b27bf2 AM |
22980 | + .flags = AuCpup_DTIME | AuCpup_HOPEN |
22981 | + }; | |
22982 | + | |
22983 | + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst); | |
392086de AM |
22984 | + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER) |
22985 | + au_fset_cpup(cpg.flags, OVERWRITE); | |
22986 | + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER) | |
22987 | + au_fset_cpup(cpg.flags, RWDST); | |
c2b27bf2 AM |
22988 | + err = au_sio_cpdown_simple(&cpg); |
22989 | + if (unlikely(err)) | |
392086de | 22990 | + AU_MVD_PR(dmsg, "cpdown failed\n"); |
c2b27bf2 AM |
22991 | + |
22992 | + AuTraceErr(err); | |
22993 | + return err; | |
22994 | +} | |
22995 | + | |
22996 | +/* | |
22997 | + * unlink the whiteout on bdst if exist which may be created by UDBA while we | |
22998 | + * were sleeping | |
22999 | + */ | |
392086de | 23000 | +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
23001 | +{ |
23002 | + int err; | |
23003 | + struct path h_path; | |
23004 | + struct au_branch *br; | |
523b37e3 | 23005 | + struct inode *delegated; |
c2b27bf2 AM |
23006 | + |
23007 | + br = au_sbr(a->sb, a->mvd_bdst); | |
23008 | + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br); | |
23009 | + err = PTR_ERR(h_path.dentry); | |
23010 | + if (IS_ERR(h_path.dentry)) { | |
392086de | 23011 | + AU_MVD_PR(dmsg, "wh_lkup failed\n"); |
c2b27bf2 AM |
23012 | + goto out; |
23013 | + } | |
23014 | + | |
23015 | + err = 0; | |
5527c038 | 23016 | + if (d_is_positive(h_path.dentry)) { |
c2b27bf2 | 23017 | + h_path.mnt = au_br_mnt(br); |
523b37e3 | 23018 | + delegated = NULL; |
5527c038 | 23019 | + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path, |
523b37e3 AM |
23020 | + &delegated, /*force*/0); |
23021 | + if (unlikely(err == -EWOULDBLOCK)) { | |
23022 | + pr_warn("cannot retry for NFSv4 delegation" | |
23023 | + " for an internal unlink\n"); | |
23024 | + iput(delegated); | |
23025 | + } | |
c2b27bf2 | 23026 | + if (unlikely(err)) |
392086de | 23027 | + AU_MVD_PR(dmsg, "wh_unlink failed\n"); |
c2b27bf2 AM |
23028 | + } |
23029 | + dput(h_path.dentry); | |
23030 | + | |
23031 | +out: | |
23032 | + AuTraceErr(err); | |
23033 | + return err; | |
23034 | +} | |
23035 | + | |
23036 | +/* | |
23037 | + * unlink the topmost h_dentry | |
c2b27bf2 | 23038 | + */ |
392086de | 23039 | +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
23040 | +{ |
23041 | + int err; | |
23042 | + struct path h_path; | |
523b37e3 | 23043 | + struct inode *delegated; |
c2b27bf2 AM |
23044 | + |
23045 | + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc); | |
23046 | + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc); | |
523b37e3 AM |
23047 | + delegated = NULL; |
23048 | + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0); | |
23049 | + if (unlikely(err == -EWOULDBLOCK)) { | |
23050 | + pr_warn("cannot retry for NFSv4 delegation" | |
23051 | + " for an internal unlink\n"); | |
23052 | + iput(delegated); | |
23053 | + } | |
c2b27bf2 | 23054 | + if (unlikely(err)) |
392086de | 23055 | + AU_MVD_PR(dmsg, "unlink failed\n"); |
c2b27bf2 AM |
23056 | + |
23057 | + AuTraceErr(err); | |
23058 | + return err; | |
23059 | +} | |
23060 | + | |
076b876e AM |
23061 | +/* Since mvdown succeeded, we ignore an error of this function */ |
23062 | +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a) | |
23063 | +{ | |
23064 | + int err; | |
23065 | + struct au_branch *br; | |
23066 | + | |
23067 | + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED; | |
23068 | + br = au_sbr(a->sb, a->mvd_bsrc); | |
23069 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs); | |
23070 | + if (!err) { | |
23071 | + br = au_sbr(a->sb, a->mvd_bdst); | |
23072 | + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id; | |
23073 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs); | |
23074 | + } | |
23075 | + if (!err) | |
23076 | + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED; | |
23077 | + else | |
23078 | + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err); | |
23079 | +} | |
23080 | + | |
c2b27bf2 AM |
23081 | +/* |
23082 | + * copy-down the file and unlink the bsrc file. | |
23083 | + * - unlink the bdst whout if exist | |
23084 | + * - copy-down the file (with whtmp name and rename) | |
23085 | + * - unlink the bsrc file | |
23086 | + */ | |
392086de | 23087 | +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
23088 | +{ |
23089 | + int err; | |
23090 | + | |
392086de | 23091 | + err = au_do_mkdir(dmsg, a); |
c2b27bf2 | 23092 | + if (!err) |
392086de | 23093 | + err = au_do_lock(dmsg, a); |
c2b27bf2 AM |
23094 | + if (unlikely(err)) |
23095 | + goto out; | |
23096 | + | |
23097 | + /* | |
23098 | + * do not revert the activities we made on bdst since they should be | |
23099 | + * harmless in aufs. | |
23100 | + */ | |
23101 | + | |
392086de | 23102 | + err = au_do_cpdown(dmsg, a); |
c2b27bf2 | 23103 | + if (!err) |
392086de AM |
23104 | + err = au_do_unlink_wh(dmsg, a); |
23105 | + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
23106 | + err = au_do_unlink(dmsg, a); | |
c2b27bf2 AM |
23107 | + if (unlikely(err)) |
23108 | + goto out_unlock; | |
23109 | + | |
c1595e42 JR |
23110 | + AuDbg("%pd2, 0x%x, %d --> %d\n", |
23111 | + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst); | |
076b876e AM |
23112 | + if (find_lower_writable(a) < 0) |
23113 | + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM; | |
23114 | + | |
23115 | + if (a->mvdown.flags & AUFS_MVDOWN_STFS) | |
23116 | + au_do_stfs(dmsg, a); | |
23117 | + | |
c2b27bf2 | 23118 | + /* maintain internal array */ |
392086de AM |
23119 | + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) { |
23120 | + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL); | |
5afbbe0d | 23121 | + au_set_dbtop(a->dentry, a->mvd_bdst); |
392086de | 23122 | + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0); |
5afbbe0d | 23123 | + au_set_ibtop(a->inode, a->mvd_bdst); |
79b8bda9 AM |
23124 | + } else { |
23125 | + /* hide the lower */ | |
23126 | + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL); | |
5afbbe0d | 23127 | + au_set_dbbot(a->dentry, a->mvd_bsrc); |
79b8bda9 | 23128 | + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0); |
5afbbe0d | 23129 | + au_set_ibbot(a->inode, a->mvd_bsrc); |
392086de | 23130 | + } |
5afbbe0d AM |
23131 | + if (au_dbbot(a->dentry) < a->mvd_bdst) |
23132 | + au_set_dbbot(a->dentry, a->mvd_bdst); | |
23133 | + if (au_ibbot(a->inode) < a->mvd_bdst) | |
23134 | + au_set_ibbot(a->inode, a->mvd_bdst); | |
c2b27bf2 AM |
23135 | + |
23136 | +out_unlock: | |
392086de | 23137 | + au_do_unlock(dmsg, a); |
c2b27bf2 AM |
23138 | +out: |
23139 | + AuTraceErr(err); | |
23140 | + return err; | |
23141 | +} | |
23142 | + | |
23143 | +/* ---------------------------------------------------------------------- */ | |
23144 | + | |
c2b27bf2 | 23145 | +/* make sure the file is idle */ |
392086de | 23146 | +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
23147 | +{ |
23148 | + int err, plinked; | |
c2b27bf2 AM |
23149 | + |
23150 | + err = 0; | |
c2b27bf2 | 23151 | + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK); |
5afbbe0d | 23152 | + if (au_dbtop(a->dentry) == a->mvd_bsrc |
c1595e42 | 23153 | + && au_dcount(a->dentry) == 1 |
c2b27bf2 | 23154 | + && atomic_read(&a->inode->i_count) == 1 |
392086de | 23155 | + /* && a->mvd_h_src_inode->i_nlink == 1 */ |
c2b27bf2 AM |
23156 | + && (!plinked || !au_plink_test(a->inode)) |
23157 | + && a->inode->i_nlink == 1) | |
23158 | + goto out; | |
23159 | + | |
23160 | + err = -EBUSY; | |
392086de | 23161 | + AU_MVD_PR(dmsg, |
c1595e42 | 23162 | + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n", |
5afbbe0d | 23163 | + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry), |
c2b27bf2 | 23164 | + atomic_read(&a->inode->i_count), a->inode->i_nlink, |
392086de | 23165 | + a->mvd_h_src_inode->i_nlink, |
c2b27bf2 AM |
23166 | + plinked, plinked ? au_plink_test(a->inode) : 0); |
23167 | + | |
23168 | +out: | |
23169 | + AuTraceErr(err); | |
23170 | + return err; | |
23171 | +} | |
23172 | + | |
23173 | +/* make sure the parent dir is fine */ | |
392086de | 23174 | +static int au_mvd_args_parent(const unsigned char dmsg, |
c2b27bf2 AM |
23175 | + struct au_mvd_args *a) |
23176 | +{ | |
23177 | + int err; | |
23178 | + aufs_bindex_t bindex; | |
23179 | + | |
23180 | + err = 0; | |
23181 | + if (unlikely(au_alive_dir(a->parent))) { | |
23182 | + err = -ENOENT; | |
392086de | 23183 | + AU_MVD_PR(dmsg, "parent dir is dead\n"); |
c2b27bf2 AM |
23184 | + goto out; |
23185 | + } | |
23186 | + | |
23187 | + a->bopq = au_dbdiropq(a->parent); | |
23188 | + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst); | |
23189 | + AuDbg("b%d\n", bindex); | |
23190 | + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst) | |
23191 | + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) { | |
23192 | + err = -EINVAL; | |
392086de AM |
23193 | + a->mvd_errno = EAU_MVDOWN_OPAQUE; |
23194 | + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n", | |
c2b27bf2 AM |
23195 | + a->bopq, a->mvd_bdst); |
23196 | + } | |
23197 | + | |
23198 | +out: | |
23199 | + AuTraceErr(err); | |
23200 | + return err; | |
23201 | +} | |
23202 | + | |
392086de | 23203 | +static int au_mvd_args_intermediate(const unsigned char dmsg, |
c2b27bf2 AM |
23204 | + struct au_mvd_args *a) |
23205 | +{ | |
23206 | + int err; | |
23207 | + struct au_dinfo *dinfo, *tmp; | |
23208 | + | |
23209 | + /* lookup the next lower positive entry */ | |
23210 | + err = -ENOMEM; | |
23211 | + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP); | |
23212 | + if (unlikely(!tmp)) | |
23213 | + goto out; | |
23214 | + | |
23215 | + a->bfound = -1; | |
23216 | + a->bwh = -1; | |
23217 | + dinfo = au_di(a->dentry); | |
23218 | + au_di_cp(tmp, dinfo); | |
23219 | + au_di_swap(tmp, dinfo); | |
23220 | + | |
23221 | + /* returns the number of positive dentries */ | |
5afbbe0d AM |
23222 | + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, |
23223 | + /* AuLkup_IGNORE_PERM */ 0); | |
c2b27bf2 AM |
23224 | + if (!err) |
23225 | + a->bwh = au_dbwh(a->dentry); | |
23226 | + else if (err > 0) | |
5afbbe0d | 23227 | + a->bfound = au_dbtop(a->dentry); |
c2b27bf2 AM |
23228 | + |
23229 | + au_di_swap(tmp, dinfo); | |
23230 | + au_rw_write_unlock(&tmp->di_rwsem); | |
23231 | + au_di_free(tmp); | |
23232 | + if (unlikely(err < 0)) | |
392086de | 23233 | + AU_MVD_PR(dmsg, "failed look-up lower\n"); |
c2b27bf2 AM |
23234 | + |
23235 | + /* | |
23236 | + * here, we have these cases. | |
23237 | + * bfound == -1 | |
23238 | + * no positive dentry under bsrc. there are more sub-cases. | |
23239 | + * bwh < 0 | |
23240 | + * there no whiteout, we can safely move-down. | |
23241 | + * bwh <= bsrc | |
23242 | + * impossible | |
23243 | + * bsrc < bwh && bwh < bdst | |
23244 | + * there is a whiteout on RO branch. cannot proceed. | |
23245 | + * bwh == bdst | |
23246 | + * there is a whiteout on the RW target branch. it should | |
23247 | + * be removed. | |
23248 | + * bdst < bwh | |
23249 | + * there is a whiteout somewhere unrelated branch. | |
23250 | + * -1 < bfound && bfound <= bsrc | |
23251 | + * impossible. | |
23252 | + * bfound < bdst | |
23253 | + * found, but it is on RO branch between bsrc and bdst. cannot | |
23254 | + * proceed. | |
23255 | + * bfound == bdst | |
23256 | + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return | |
23257 | + * error. | |
23258 | + * bdst < bfound | |
23259 | + * found, after we create the file on bdst, it will be hidden. | |
23260 | + */ | |
23261 | + | |
23262 | + AuDebugOn(a->bfound == -1 | |
23263 | + && a->bwh != -1 | |
23264 | + && a->bwh <= a->mvd_bsrc); | |
23265 | + AuDebugOn(-1 < a->bfound | |
23266 | + && a->bfound <= a->mvd_bsrc); | |
23267 | + | |
23268 | + err = -EINVAL; | |
23269 | + if (a->bfound == -1 | |
23270 | + && a->mvd_bsrc < a->bwh | |
23271 | + && a->bwh != -1 | |
23272 | + && a->bwh < a->mvd_bdst) { | |
392086de AM |
23273 | + a->mvd_errno = EAU_MVDOWN_WHITEOUT; |
23274 | + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n", | |
c2b27bf2 AM |
23275 | + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh); |
23276 | + goto out; | |
23277 | + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) { | |
392086de AM |
23278 | + a->mvd_errno = EAU_MVDOWN_UPPER; |
23279 | + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n", | |
c2b27bf2 AM |
23280 | + a->mvd_bdst, a->bfound); |
23281 | + goto out; | |
23282 | + } | |
23283 | + | |
23284 | + err = 0; /* success */ | |
23285 | + | |
23286 | +out: | |
23287 | + AuTraceErr(err); | |
23288 | + return err; | |
23289 | +} | |
23290 | + | |
392086de | 23291 | +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
23292 | +{ |
23293 | + int err; | |
23294 | + | |
392086de AM |
23295 | + err = 0; |
23296 | + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER) | |
23297 | + && a->bfound == a->mvd_bdst) | |
23298 | + err = -EEXIST; | |
c2b27bf2 AM |
23299 | + AuTraceErr(err); |
23300 | + return err; | |
23301 | +} | |
23302 | + | |
392086de | 23303 | +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
23304 | +{ |
23305 | + int err; | |
23306 | + struct au_branch *br; | |
23307 | + | |
23308 | + err = -EISDIR; | |
23309 | + if (unlikely(S_ISDIR(a->inode->i_mode))) | |
23310 | + goto out; | |
23311 | + | |
23312 | + err = -EINVAL; | |
392086de | 23313 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER)) |
5afbbe0d | 23314 | + a->mvd_bsrc = au_ibtop(a->inode); |
392086de AM |
23315 | + else { |
23316 | + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid); | |
23317 | + if (unlikely(a->mvd_bsrc < 0 | |
5afbbe0d AM |
23318 | + || (a->mvd_bsrc < au_dbtop(a->dentry) |
23319 | + || au_dbbot(a->dentry) < a->mvd_bsrc | |
392086de | 23320 | + || !au_h_dptr(a->dentry, a->mvd_bsrc)) |
5afbbe0d AM |
23321 | + || (a->mvd_bsrc < au_ibtop(a->inode) |
23322 | + || au_ibbot(a->inode) < a->mvd_bsrc | |
392086de AM |
23323 | + || !au_h_iptr(a->inode, a->mvd_bsrc)))) { |
23324 | + a->mvd_errno = EAU_MVDOWN_NOUPPER; | |
23325 | + AU_MVD_PR(dmsg, "no upper\n"); | |
23326 | + goto out; | |
23327 | + } | |
23328 | + } | |
5afbbe0d | 23329 | + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) { |
392086de AM |
23330 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; |
23331 | + AU_MVD_PR(dmsg, "on the bottom\n"); | |
c2b27bf2 AM |
23332 | + goto out; |
23333 | + } | |
392086de | 23334 | + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc); |
c2b27bf2 AM |
23335 | + br = au_sbr(a->sb, a->mvd_bsrc); |
23336 | + err = au_br_rdonly(br); | |
392086de AM |
23337 | + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) { |
23338 | + if (unlikely(err)) | |
23339 | + goto out; | |
23340 | + } else if (!(vfsub_native_ro(a->mvd_h_src_inode) | |
23341 | + || IS_APPEND(a->mvd_h_src_inode))) { | |
23342 | + if (err) | |
23343 | + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R; | |
23344 | + /* go on */ | |
23345 | + } else | |
c2b27bf2 AM |
23346 | + goto out; |
23347 | + | |
23348 | + err = -EINVAL; | |
392086de AM |
23349 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) { |
23350 | + a->mvd_bdst = find_lower_writable(a); | |
23351 | + if (unlikely(a->mvd_bdst < 0)) { | |
23352 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; | |
23353 | + AU_MVD_PR(dmsg, "no writable lower branch\n"); | |
23354 | + goto out; | |
23355 | + } | |
23356 | + } else { | |
23357 | + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid); | |
23358 | + if (unlikely(a->mvd_bdst < 0 | |
5afbbe0d | 23359 | + || au_sbbot(a->sb) < a->mvd_bdst)) { |
392086de AM |
23360 | + a->mvd_errno = EAU_MVDOWN_NOLOWERBR; |
23361 | + AU_MVD_PR(dmsg, "no lower brid\n"); | |
23362 | + goto out; | |
23363 | + } | |
c2b27bf2 AM |
23364 | + } |
23365 | + | |
392086de | 23366 | + err = au_mvd_args_busy(dmsg, a); |
c2b27bf2 | 23367 | + if (!err) |
392086de | 23368 | + err = au_mvd_args_parent(dmsg, a); |
c2b27bf2 | 23369 | + if (!err) |
392086de | 23370 | + err = au_mvd_args_intermediate(dmsg, a); |
c2b27bf2 | 23371 | + if (!err) |
392086de | 23372 | + err = au_mvd_args_exist(dmsg, a); |
c2b27bf2 AM |
23373 | + if (!err) |
23374 | + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst); | |
23375 | + | |
23376 | +out: | |
23377 | + AuTraceErr(err); | |
23378 | + return err; | |
23379 | +} | |
23380 | + | |
23381 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg) | |
23382 | +{ | |
392086de AM |
23383 | + int err, e; |
23384 | + unsigned char dmsg; | |
23385 | + struct au_mvd_args *args; | |
79b8bda9 | 23386 | + struct inode *inode; |
c2b27bf2 | 23387 | + |
79b8bda9 | 23388 | + inode = d_inode(dentry); |
c2b27bf2 AM |
23389 | + err = -EPERM; |
23390 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
23391 | + goto out; | |
23392 | + | |
392086de AM |
23393 | + err = -ENOMEM; |
23394 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
23395 | + if (unlikely(!args)) | |
23396 | + goto out; | |
23397 | + | |
23398 | + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown)); | |
23399 | + if (!err) | |
23400 | + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg)); | |
c2b27bf2 AM |
23401 | + if (unlikely(err)) { |
23402 | + err = -EFAULT; | |
392086de AM |
23403 | + AuTraceErr(err); |
23404 | + goto out_free; | |
c2b27bf2 | 23405 | + } |
392086de AM |
23406 | + AuDbg("flags 0x%x\n", args->mvdown.flags); |
23407 | + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R); | |
23408 | + args->mvdown.au_errno = 0; | |
23409 | + args->dentry = dentry; | |
79b8bda9 | 23410 | + args->inode = inode; |
392086de | 23411 | + args->sb = dentry->d_sb; |
c2b27bf2 | 23412 | + |
392086de AM |
23413 | + err = -ENOENT; |
23414 | + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG); | |
23415 | + args->parent = dget_parent(dentry); | |
5527c038 | 23416 | + args->dir = d_inode(args->parent); |
febd17d6 | 23417 | + inode_lock_nested(args->dir, I_MUTEX_PARENT); |
392086de AM |
23418 | + dput(args->parent); |
23419 | + if (unlikely(args->parent != dentry->d_parent)) { | |
23420 | + AU_MVD_PR(dmsg, "parent dir is moved\n"); | |
c2b27bf2 AM |
23421 | + goto out_dir; |
23422 | + } | |
23423 | + | |
febd17d6 | 23424 | + inode_lock_nested(inode, I_MUTEX_CHILD); |
b95c5147 | 23425 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW); |
c2b27bf2 AM |
23426 | + if (unlikely(err)) |
23427 | + goto out_inode; | |
23428 | + | |
392086de AM |
23429 | + di_write_lock_parent(args->parent); |
23430 | + err = au_mvd_args(dmsg, args); | |
c2b27bf2 AM |
23431 | + if (unlikely(err)) |
23432 | + goto out_parent; | |
23433 | + | |
392086de | 23434 | + err = au_do_mvdown(dmsg, args); |
c2b27bf2 AM |
23435 | + if (unlikely(err)) |
23436 | + goto out_parent; | |
c2b27bf2 | 23437 | + |
392086de | 23438 | + au_cpup_attr_timesizes(args->dir); |
79b8bda9 AM |
23439 | + au_cpup_attr_timesizes(inode); |
23440 | + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
23441 | + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst)); | |
c2b27bf2 AM |
23442 | + /* au_digen_dec(dentry); */ |
23443 | + | |
23444 | +out_parent: | |
392086de | 23445 | + di_write_unlock(args->parent); |
c2b27bf2 AM |
23446 | + aufs_read_unlock(dentry, AuLock_DW); |
23447 | +out_inode: | |
febd17d6 | 23448 | + inode_unlock(inode); |
c2b27bf2 | 23449 | +out_dir: |
febd17d6 | 23450 | + inode_unlock(args->dir); |
392086de AM |
23451 | +out_free: |
23452 | + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown)); | |
23453 | + if (unlikely(e)) | |
23454 | + err = -EFAULT; | |
f0c0a007 | 23455 | + au_delayed_kfree(args); |
c2b27bf2 AM |
23456 | +out: |
23457 | + AuTraceErr(err); | |
23458 | + return err; | |
23459 | +} | |
23460 | diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c | |
23461 | --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 23462 | +++ linux/fs/aufs/opts.c 2017-05-06 22:16:52.781553511 +0200 |
a2654f78 | 23463 | @@ -0,0 +1,1848 @@ |
1facf9fc | 23464 | +/* |
a2654f78 | 23465 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 23466 | + * |
23467 | + * This program, aufs is free software; you can redistribute it and/or modify | |
23468 | + * it under the terms of the GNU General Public License as published by | |
23469 | + * the Free Software Foundation; either version 2 of the License, or | |
23470 | + * (at your option) any later version. | |
dece6358 AM |
23471 | + * |
23472 | + * This program is distributed in the hope that it will be useful, | |
23473 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23474 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23475 | + * GNU General Public License for more details. | |
23476 | + * | |
23477 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 23478 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 23479 | + */ |
23480 | + | |
23481 | +/* | |
23482 | + * mount options/flags | |
23483 | + */ | |
23484 | + | |
dece6358 | 23485 | +#include <linux/namei.h> |
1facf9fc | 23486 | +#include <linux/types.h> /* a distribution requires */ |
23487 | +#include <linux/parser.h> | |
23488 | +#include "aufs.h" | |
23489 | + | |
23490 | +/* ---------------------------------------------------------------------- */ | |
23491 | + | |
23492 | +enum { | |
23493 | + Opt_br, | |
7e9cd9fe AM |
23494 | + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend, |
23495 | + Opt_idel, Opt_imod, | |
23496 | + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, | |
dece6358 | 23497 | + Opt_rdblk_def, Opt_rdhash_def, |
7e9cd9fe | 23498 | + Opt_xino, Opt_noxino, |
1facf9fc | 23499 | + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino, |
23500 | + Opt_trunc_xino_path, Opt_itrunc_xino, | |
23501 | + Opt_trunc_xib, Opt_notrunc_xib, | |
dece6358 | 23502 | + Opt_shwh, Opt_noshwh, |
1facf9fc | 23503 | + Opt_plink, Opt_noplink, Opt_list_plink, |
23504 | + Opt_udba, | |
4a4d8108 | 23505 | + Opt_dio, Opt_nodio, |
1facf9fc | 23506 | + Opt_diropq_a, Opt_diropq_w, |
23507 | + Opt_warn_perm, Opt_nowarn_perm, | |
23508 | + Opt_wbr_copyup, Opt_wbr_create, | |
076b876e | 23509 | + Opt_fhsm_sec, |
1facf9fc | 23510 | + Opt_verbose, Opt_noverbose, |
23511 | + Opt_sum, Opt_nosum, Opt_wsum, | |
076b876e | 23512 | + Opt_dirperm1, Opt_nodirperm1, |
c1595e42 | 23513 | + Opt_acl, Opt_noacl, |
1facf9fc | 23514 | + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err |
23515 | +}; | |
23516 | + | |
23517 | +static match_table_t options = { | |
23518 | + {Opt_br, "br=%s"}, | |
23519 | + {Opt_br, "br:%s"}, | |
23520 | + | |
23521 | + {Opt_add, "add=%d:%s"}, | |
23522 | + {Opt_add, "add:%d:%s"}, | |
23523 | + {Opt_add, "ins=%d:%s"}, | |
23524 | + {Opt_add, "ins:%d:%s"}, | |
23525 | + {Opt_append, "append=%s"}, | |
23526 | + {Opt_append, "append:%s"}, | |
23527 | + {Opt_prepend, "prepend=%s"}, | |
23528 | + {Opt_prepend, "prepend:%s"}, | |
23529 | + | |
23530 | + {Opt_del, "del=%s"}, | |
23531 | + {Opt_del, "del:%s"}, | |
23532 | + /* {Opt_idel, "idel:%d"}, */ | |
23533 | + {Opt_mod, "mod=%s"}, | |
23534 | + {Opt_mod, "mod:%s"}, | |
23535 | + /* {Opt_imod, "imod:%d:%s"}, */ | |
23536 | + | |
23537 | + {Opt_dirwh, "dirwh=%d"}, | |
23538 | + | |
23539 | + {Opt_xino, "xino=%s"}, | |
23540 | + {Opt_noxino, "noxino"}, | |
23541 | + {Opt_trunc_xino, "trunc_xino"}, | |
23542 | + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"}, | |
23543 | + {Opt_notrunc_xino, "notrunc_xino"}, | |
23544 | + {Opt_trunc_xino_path, "trunc_xino=%s"}, | |
23545 | + {Opt_itrunc_xino, "itrunc_xino=%d"}, | |
23546 | + /* {Opt_zxino, "zxino=%s"}, */ | |
23547 | + {Opt_trunc_xib, "trunc_xib"}, | |
23548 | + {Opt_notrunc_xib, "notrunc_xib"}, | |
23549 | + | |
e49829fe | 23550 | +#ifdef CONFIG_PROC_FS |
1facf9fc | 23551 | + {Opt_plink, "plink"}, |
e49829fe JR |
23552 | +#else |
23553 | + {Opt_ignore_silent, "plink"}, | |
23554 | +#endif | |
23555 | + | |
1facf9fc | 23556 | + {Opt_noplink, "noplink"}, |
e49829fe | 23557 | + |
1facf9fc | 23558 | +#ifdef CONFIG_AUFS_DEBUG |
23559 | + {Opt_list_plink, "list_plink"}, | |
23560 | +#endif | |
23561 | + | |
23562 | + {Opt_udba, "udba=%s"}, | |
23563 | + | |
4a4d8108 AM |
23564 | + {Opt_dio, "dio"}, |
23565 | + {Opt_nodio, "nodio"}, | |
23566 | + | |
076b876e AM |
23567 | +#ifdef CONFIG_AUFS_FHSM |
23568 | + {Opt_fhsm_sec, "fhsm_sec=%d"}, | |
23569 | +#else | |
23570 | + {Opt_ignore_silent, "fhsm_sec=%d"}, | |
23571 | +#endif | |
23572 | + | |
1facf9fc | 23573 | + {Opt_diropq_a, "diropq=always"}, |
23574 | + {Opt_diropq_a, "diropq=a"}, | |
23575 | + {Opt_diropq_w, "diropq=whiteouted"}, | |
23576 | + {Opt_diropq_w, "diropq=w"}, | |
23577 | + | |
23578 | + {Opt_warn_perm, "warn_perm"}, | |
23579 | + {Opt_nowarn_perm, "nowarn_perm"}, | |
23580 | + | |
23581 | + /* keep them temporary */ | |
1facf9fc | 23582 | + {Opt_ignore_silent, "nodlgt"}, |
1facf9fc | 23583 | + {Opt_ignore_silent, "clean_plink"}, |
23584 | + | |
dece6358 AM |
23585 | +#ifdef CONFIG_AUFS_SHWH |
23586 | + {Opt_shwh, "shwh"}, | |
23587 | +#endif | |
23588 | + {Opt_noshwh, "noshwh"}, | |
23589 | + | |
076b876e AM |
23590 | + {Opt_dirperm1, "dirperm1"}, |
23591 | + {Opt_nodirperm1, "nodirperm1"}, | |
23592 | + | |
1facf9fc | 23593 | + {Opt_verbose, "verbose"}, |
23594 | + {Opt_verbose, "v"}, | |
23595 | + {Opt_noverbose, "noverbose"}, | |
23596 | + {Opt_noverbose, "quiet"}, | |
23597 | + {Opt_noverbose, "q"}, | |
23598 | + {Opt_noverbose, "silent"}, | |
23599 | + | |
23600 | + {Opt_sum, "sum"}, | |
23601 | + {Opt_nosum, "nosum"}, | |
23602 | + {Opt_wsum, "wsum"}, | |
23603 | + | |
23604 | + {Opt_rdcache, "rdcache=%d"}, | |
23605 | + {Opt_rdblk, "rdblk=%d"}, | |
dece6358 | 23606 | + {Opt_rdblk_def, "rdblk=def"}, |
1facf9fc | 23607 | + {Opt_rdhash, "rdhash=%d"}, |
dece6358 | 23608 | + {Opt_rdhash_def, "rdhash=def"}, |
1facf9fc | 23609 | + |
23610 | + {Opt_wbr_create, "create=%s"}, | |
23611 | + {Opt_wbr_create, "create_policy=%s"}, | |
23612 | + {Opt_wbr_copyup, "cpup=%s"}, | |
23613 | + {Opt_wbr_copyup, "copyup=%s"}, | |
23614 | + {Opt_wbr_copyup, "copyup_policy=%s"}, | |
23615 | + | |
c1595e42 JR |
23616 | + /* generic VFS flag */ |
23617 | +#ifdef CONFIG_FS_POSIX_ACL | |
23618 | + {Opt_acl, "acl"}, | |
23619 | + {Opt_noacl, "noacl"}, | |
23620 | +#else | |
23621 | + {Opt_ignore_silent, "acl"}, | |
23622 | + {Opt_ignore_silent, "noacl"}, | |
23623 | +#endif | |
23624 | + | |
1facf9fc | 23625 | + /* internal use for the scripts */ |
23626 | + {Opt_ignore_silent, "si=%s"}, | |
23627 | + | |
23628 | + {Opt_br, "dirs=%s"}, | |
23629 | + {Opt_ignore, "debug=%d"}, | |
23630 | + {Opt_ignore, "delete=whiteout"}, | |
23631 | + {Opt_ignore, "delete=all"}, | |
23632 | + {Opt_ignore, "imap=%s"}, | |
23633 | + | |
1308ab2a | 23634 | + /* temporary workaround, due to old mount(8)? */ |
23635 | + {Opt_ignore_silent, "relatime"}, | |
23636 | + | |
1facf9fc | 23637 | + {Opt_err, NULL} |
23638 | +}; | |
23639 | + | |
23640 | +/* ---------------------------------------------------------------------- */ | |
23641 | + | |
076b876e | 23642 | +static const char *au_parser_pattern(int val, match_table_t tbl) |
1facf9fc | 23643 | +{ |
076b876e AM |
23644 | + struct match_token *p; |
23645 | + | |
23646 | + p = tbl; | |
23647 | + while (p->pattern) { | |
23648 | + if (p->token == val) | |
23649 | + return p->pattern; | |
23650 | + p++; | |
1facf9fc | 23651 | + } |
23652 | + BUG(); | |
23653 | + return "??"; | |
23654 | +} | |
23655 | + | |
076b876e AM |
23656 | +static const char *au_optstr(int *val, match_table_t tbl) |
23657 | +{ | |
23658 | + struct match_token *p; | |
23659 | + int v; | |
23660 | + | |
23661 | + v = *val; | |
2000de60 JR |
23662 | + if (!v) |
23663 | + goto out; | |
076b876e | 23664 | + p = tbl; |
2000de60 JR |
23665 | + while (p->pattern) { |
23666 | + if (p->token | |
23667 | + && (v & p->token) == p->token) { | |
076b876e AM |
23668 | + *val &= ~p->token; |
23669 | + return p->pattern; | |
23670 | + } | |
23671 | + p++; | |
23672 | + } | |
2000de60 JR |
23673 | + |
23674 | +out: | |
076b876e AM |
23675 | + return NULL; |
23676 | +} | |
23677 | + | |
1facf9fc | 23678 | +/* ---------------------------------------------------------------------- */ |
23679 | + | |
1e00d052 | 23680 | +static match_table_t brperm = { |
1facf9fc | 23681 | + {AuBrPerm_RO, AUFS_BRPERM_RO}, |
23682 | + {AuBrPerm_RR, AUFS_BRPERM_RR}, | |
23683 | + {AuBrPerm_RW, AUFS_BRPERM_RW}, | |
1e00d052 AM |
23684 | + {0, NULL} |
23685 | +}; | |
1facf9fc | 23686 | + |
86dc4139 | 23687 | +static match_table_t brattr = { |
076b876e AM |
23688 | + /* general */ |
23689 | + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG}, | |
23690 | + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL}, | |
c1595e42 | 23691 | + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */ |
86dc4139 | 23692 | + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN}, |
2000de60 | 23693 | +#ifdef CONFIG_AUFS_FHSM |
076b876e | 23694 | + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM}, |
2000de60 JR |
23695 | +#endif |
23696 | +#ifdef CONFIG_AUFS_XATTR | |
c1595e42 JR |
23697 | + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX}, |
23698 | + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC}, | |
23699 | + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS}, | |
23700 | + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR}, | |
23701 | + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR}, | |
23702 | + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH}, | |
2000de60 | 23703 | +#endif |
076b876e AM |
23704 | + |
23705 | + /* ro/rr branch */ | |
1e00d052 | 23706 | + {AuBrRAttr_WH, AUFS_BRRATTR_WH}, |
076b876e AM |
23707 | + |
23708 | + /* rw branch */ | |
23709 | + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO}, | |
1e00d052 | 23710 | + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH}, |
076b876e | 23711 | + |
1e00d052 | 23712 | + {0, NULL} |
1facf9fc | 23713 | +}; |
23714 | + | |
1e00d052 AM |
23715 | +static int br_attr_val(char *str, match_table_t table, substring_t args[]) |
23716 | +{ | |
23717 | + int attr, v; | |
23718 | + char *p; | |
23719 | + | |
23720 | + attr = 0; | |
23721 | + do { | |
23722 | + p = strchr(str, '+'); | |
23723 | + if (p) | |
23724 | + *p = 0; | |
23725 | + v = match_token(str, table, args); | |
076b876e AM |
23726 | + if (v) { |
23727 | + if (v & AuBrAttr_CMOO_Mask) | |
23728 | + attr &= ~AuBrAttr_CMOO_Mask; | |
1e00d052 | 23729 | + attr |= v; |
076b876e | 23730 | + } else { |
1e00d052 AM |
23731 | + if (p) |
23732 | + *p = '+'; | |
0c3ec466 | 23733 | + pr_warn("ignored branch attribute %s\n", str); |
1e00d052 AM |
23734 | + break; |
23735 | + } | |
23736 | + if (p) | |
23737 | + str = p + 1; | |
23738 | + } while (p); | |
23739 | + | |
23740 | + return attr; | |
23741 | +} | |
23742 | + | |
076b876e AM |
23743 | +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm) |
23744 | +{ | |
23745 | + int sz; | |
23746 | + const char *p; | |
23747 | + char *q; | |
23748 | + | |
076b876e AM |
23749 | + q = str->a; |
23750 | + *q = 0; | |
23751 | + p = au_optstr(&perm, brattr); | |
23752 | + if (p) { | |
23753 | + sz = strlen(p); | |
23754 | + memcpy(q, p, sz + 1); | |
23755 | + q += sz; | |
23756 | + } else | |
23757 | + goto out; | |
23758 | + | |
23759 | + do { | |
23760 | + p = au_optstr(&perm, brattr); | |
23761 | + if (p) { | |
23762 | + *q++ = '+'; | |
23763 | + sz = strlen(p); | |
23764 | + memcpy(q, p, sz + 1); | |
23765 | + q += sz; | |
23766 | + } | |
23767 | + } while (p); | |
23768 | + | |
23769 | +out: | |
c1595e42 | 23770 | + return q - str->a; |
076b876e AM |
23771 | +} |
23772 | + | |
4a4d8108 | 23773 | +static int noinline_for_stack br_perm_val(char *perm) |
1facf9fc | 23774 | +{ |
076b876e AM |
23775 | + int val, bad, sz; |
23776 | + char *p; | |
1facf9fc | 23777 | + substring_t args[MAX_OPT_ARGS]; |
076b876e | 23778 | + au_br_perm_str_t attr; |
1facf9fc | 23779 | + |
1e00d052 AM |
23780 | + p = strchr(perm, '+'); |
23781 | + if (p) | |
23782 | + *p = 0; | |
23783 | + val = match_token(perm, brperm, args); | |
23784 | + if (!val) { | |
23785 | + if (p) | |
23786 | + *p = '+'; | |
0c3ec466 | 23787 | + pr_warn("ignored branch permission %s\n", perm); |
1e00d052 AM |
23788 | + val = AuBrPerm_RO; |
23789 | + goto out; | |
23790 | + } | |
23791 | + if (!p) | |
23792 | + goto out; | |
23793 | + | |
076b876e AM |
23794 | + val |= br_attr_val(p + 1, brattr, args); |
23795 | + | |
23796 | + bad = 0; | |
86dc4139 | 23797 | + switch (val & AuBrPerm_Mask) { |
1e00d052 AM |
23798 | + case AuBrPerm_RO: |
23799 | + case AuBrPerm_RR: | |
076b876e AM |
23800 | + bad = val & AuBrWAttr_Mask; |
23801 | + val &= ~AuBrWAttr_Mask; | |
1e00d052 AM |
23802 | + break; |
23803 | + case AuBrPerm_RW: | |
076b876e AM |
23804 | + bad = val & AuBrRAttr_Mask; |
23805 | + val &= ~AuBrRAttr_Mask; | |
1e00d052 AM |
23806 | + break; |
23807 | + } | |
c1595e42 JR |
23808 | + |
23809 | + /* | |
23810 | + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs | |
23811 | + * does not treat it as an error, just warning. | |
23812 | + * this is a tiny guard for the user operation. | |
23813 | + */ | |
23814 | + if (val & AuBrAttr_UNPIN) { | |
23815 | + bad |= AuBrAttr_UNPIN; | |
23816 | + val &= ~AuBrAttr_UNPIN; | |
23817 | + } | |
23818 | + | |
076b876e AM |
23819 | + if (unlikely(bad)) { |
23820 | + sz = au_do_optstr_br_attr(&attr, bad); | |
23821 | + AuDebugOn(!sz); | |
23822 | + pr_warn("ignored branch attribute %s\n", attr.a); | |
23823 | + } | |
1e00d052 AM |
23824 | + |
23825 | +out: | |
1facf9fc | 23826 | + return val; |
23827 | +} | |
23828 | + | |
076b876e | 23829 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm) |
1facf9fc | 23830 | +{ |
076b876e AM |
23831 | + au_br_perm_str_t attr; |
23832 | + const char *p; | |
23833 | + char *q; | |
1e00d052 AM |
23834 | + int sz; |
23835 | + | |
076b876e AM |
23836 | + q = str->a; |
23837 | + p = au_optstr(&perm, brperm); | |
23838 | + AuDebugOn(!p || !*p); | |
23839 | + sz = strlen(p); | |
23840 | + memcpy(q, p, sz + 1); | |
23841 | + q += sz; | |
1e00d052 | 23842 | + |
076b876e AM |
23843 | + sz = au_do_optstr_br_attr(&attr, perm); |
23844 | + if (sz) { | |
23845 | + *q++ = '+'; | |
23846 | + memcpy(q, attr.a, sz + 1); | |
1e00d052 AM |
23847 | + } |
23848 | + | |
076b876e | 23849 | + AuDebugOn(strlen(str->a) >= sizeof(str->a)); |
1facf9fc | 23850 | +} |
23851 | + | |
23852 | +/* ---------------------------------------------------------------------- */ | |
23853 | + | |
23854 | +static match_table_t udbalevel = { | |
23855 | + {AuOpt_UDBA_REVAL, "reval"}, | |
23856 | + {AuOpt_UDBA_NONE, "none"}, | |
4a4d8108 AM |
23857 | +#ifdef CONFIG_AUFS_HNOTIFY |
23858 | + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */ | |
23859 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
23860 | + {AuOpt_UDBA_HNOTIFY, "fsnotify"}, | |
4a4d8108 | 23861 | +#endif |
1facf9fc | 23862 | +#endif |
23863 | + {-1, NULL} | |
23864 | +}; | |
23865 | + | |
4a4d8108 | 23866 | +static int noinline_for_stack udba_val(char *str) |
1facf9fc | 23867 | +{ |
23868 | + substring_t args[MAX_OPT_ARGS]; | |
23869 | + | |
7f207e10 | 23870 | + return match_token(str, udbalevel, args); |
1facf9fc | 23871 | +} |
23872 | + | |
23873 | +const char *au_optstr_udba(int udba) | |
23874 | +{ | |
076b876e | 23875 | + return au_parser_pattern(udba, udbalevel); |
1facf9fc | 23876 | +} |
23877 | + | |
23878 | +/* ---------------------------------------------------------------------- */ | |
23879 | + | |
23880 | +static match_table_t au_wbr_create_policy = { | |
23881 | + {AuWbrCreate_TDP, "tdp"}, | |
23882 | + {AuWbrCreate_TDP, "top-down-parent"}, | |
23883 | + {AuWbrCreate_RR, "rr"}, | |
23884 | + {AuWbrCreate_RR, "round-robin"}, | |
23885 | + {AuWbrCreate_MFS, "mfs"}, | |
23886 | + {AuWbrCreate_MFS, "most-free-space"}, | |
23887 | + {AuWbrCreate_MFSV, "mfs:%d"}, | |
23888 | + {AuWbrCreate_MFSV, "most-free-space:%d"}, | |
23889 | + | |
f2c43d5f AM |
23890 | + /* top-down regardless the parent, and then mfs */ |
23891 | + {AuWbrCreate_TDMFS, "tdmfs:%d"}, | |
23892 | + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"}, | |
23893 | + | |
1facf9fc | 23894 | + {AuWbrCreate_MFSRR, "mfsrr:%d"}, |
23895 | + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"}, | |
23896 | + {AuWbrCreate_PMFS, "pmfs"}, | |
23897 | + {AuWbrCreate_PMFSV, "pmfs:%d"}, | |
392086de AM |
23898 | + {AuWbrCreate_PMFSRR, "pmfsrr:%d"}, |
23899 | + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"}, | |
1facf9fc | 23900 | + |
23901 | + {-1, NULL} | |
23902 | +}; | |
23903 | + | |
1facf9fc | 23904 | +static int au_wbr_mfs_wmark(substring_t *arg, char *str, |
23905 | + struct au_opt_wbr_create *create) | |
23906 | +{ | |
23907 | + int err; | |
23908 | + unsigned long long ull; | |
23909 | + | |
23910 | + err = 0; | |
a2654f78 | 23911 | + if (!match_u64(arg, &ull)) |
1facf9fc | 23912 | + create->mfsrr_watermark = ull; |
23913 | + else { | |
4a4d8108 | 23914 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 23915 | + err = -EINVAL; |
23916 | + } | |
23917 | + | |
23918 | + return err; | |
23919 | +} | |
23920 | + | |
23921 | +static int au_wbr_mfs_sec(substring_t *arg, char *str, | |
23922 | + struct au_opt_wbr_create *create) | |
23923 | +{ | |
23924 | + int n, err; | |
23925 | + | |
23926 | + err = 0; | |
027c5e7a | 23927 | + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC) |
1facf9fc | 23928 | + create->mfs_second = n; |
23929 | + else { | |
4a4d8108 | 23930 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 23931 | + err = -EINVAL; |
23932 | + } | |
23933 | + | |
23934 | + return err; | |
23935 | +} | |
23936 | + | |
4a4d8108 AM |
23937 | +static int noinline_for_stack |
23938 | +au_wbr_create_val(char *str, struct au_opt_wbr_create *create) | |
1facf9fc | 23939 | +{ |
23940 | + int err, e; | |
23941 | + substring_t args[MAX_OPT_ARGS]; | |
23942 | + | |
23943 | + err = match_token(str, au_wbr_create_policy, args); | |
23944 | + create->wbr_create = err; | |
23945 | + switch (err) { | |
23946 | + case AuWbrCreate_MFSRRV: | |
f2c43d5f | 23947 | + case AuWbrCreate_TDMFSV: |
392086de | 23948 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 23949 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
23950 | + if (!e) | |
23951 | + e = au_wbr_mfs_sec(&args[1], str, create); | |
23952 | + if (unlikely(e)) | |
23953 | + err = e; | |
23954 | + break; | |
23955 | + case AuWbrCreate_MFSRR: | |
f2c43d5f | 23956 | + case AuWbrCreate_TDMFS: |
392086de | 23957 | + case AuWbrCreate_PMFSRR: |
1facf9fc | 23958 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
23959 | + if (unlikely(e)) { | |
23960 | + err = e; | |
23961 | + break; | |
23962 | + } | |
23963 | + /*FALLTHROUGH*/ | |
23964 | + case AuWbrCreate_MFS: | |
23965 | + case AuWbrCreate_PMFS: | |
027c5e7a | 23966 | + create->mfs_second = AUFS_MFS_DEF_SEC; |
1facf9fc | 23967 | + break; |
23968 | + case AuWbrCreate_MFSV: | |
23969 | + case AuWbrCreate_PMFSV: | |
23970 | + e = au_wbr_mfs_sec(&args[0], str, create); | |
23971 | + if (unlikely(e)) | |
23972 | + err = e; | |
23973 | + break; | |
23974 | + } | |
23975 | + | |
23976 | + return err; | |
23977 | +} | |
23978 | + | |
23979 | +const char *au_optstr_wbr_create(int wbr_create) | |
23980 | +{ | |
076b876e | 23981 | + return au_parser_pattern(wbr_create, au_wbr_create_policy); |
1facf9fc | 23982 | +} |
23983 | + | |
23984 | +static match_table_t au_wbr_copyup_policy = { | |
23985 | + {AuWbrCopyup_TDP, "tdp"}, | |
23986 | + {AuWbrCopyup_TDP, "top-down-parent"}, | |
23987 | + {AuWbrCopyup_BUP, "bup"}, | |
23988 | + {AuWbrCopyup_BUP, "bottom-up-parent"}, | |
23989 | + {AuWbrCopyup_BU, "bu"}, | |
23990 | + {AuWbrCopyup_BU, "bottom-up"}, | |
23991 | + {-1, NULL} | |
23992 | +}; | |
23993 | + | |
4a4d8108 | 23994 | +static int noinline_for_stack au_wbr_copyup_val(char *str) |
1facf9fc | 23995 | +{ |
23996 | + substring_t args[MAX_OPT_ARGS]; | |
23997 | + | |
23998 | + return match_token(str, au_wbr_copyup_policy, args); | |
23999 | +} | |
24000 | + | |
24001 | +const char *au_optstr_wbr_copyup(int wbr_copyup) | |
24002 | +{ | |
076b876e | 24003 | + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy); |
1facf9fc | 24004 | +} |
24005 | + | |
24006 | +/* ---------------------------------------------------------------------- */ | |
24007 | + | |
24008 | +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY; | |
24009 | + | |
24010 | +static void dump_opts(struct au_opts *opts) | |
24011 | +{ | |
24012 | +#ifdef CONFIG_AUFS_DEBUG | |
24013 | + /* reduce stack space */ | |
24014 | + union { | |
24015 | + struct au_opt_add *add; | |
24016 | + struct au_opt_del *del; | |
24017 | + struct au_opt_mod *mod; | |
24018 | + struct au_opt_xino *xino; | |
24019 | + struct au_opt_xino_itrunc *xino_itrunc; | |
24020 | + struct au_opt_wbr_create *create; | |
24021 | + } u; | |
24022 | + struct au_opt *opt; | |
24023 | + | |
24024 | + opt = opts->opt; | |
24025 | + while (opt->type != Opt_tail) { | |
24026 | + switch (opt->type) { | |
24027 | + case Opt_add: | |
24028 | + u.add = &opt->add; | |
24029 | + AuDbg("add {b%d, %s, 0x%x, %p}\n", | |
24030 | + u.add->bindex, u.add->pathname, u.add->perm, | |
24031 | + u.add->path.dentry); | |
24032 | + break; | |
24033 | + case Opt_del: | |
24034 | + case Opt_idel: | |
24035 | + u.del = &opt->del; | |
24036 | + AuDbg("del {%s, %p}\n", | |
24037 | + u.del->pathname, u.del->h_path.dentry); | |
24038 | + break; | |
24039 | + case Opt_mod: | |
24040 | + case Opt_imod: | |
24041 | + u.mod = &opt->mod; | |
24042 | + AuDbg("mod {%s, 0x%x, %p}\n", | |
24043 | + u.mod->path, u.mod->perm, u.mod->h_root); | |
24044 | + break; | |
24045 | + case Opt_append: | |
24046 | + u.add = &opt->add; | |
24047 | + AuDbg("append {b%d, %s, 0x%x, %p}\n", | |
24048 | + u.add->bindex, u.add->pathname, u.add->perm, | |
24049 | + u.add->path.dentry); | |
24050 | + break; | |
24051 | + case Opt_prepend: | |
24052 | + u.add = &opt->add; | |
24053 | + AuDbg("prepend {b%d, %s, 0x%x, %p}\n", | |
24054 | + u.add->bindex, u.add->pathname, u.add->perm, | |
24055 | + u.add->path.dentry); | |
24056 | + break; | |
24057 | + case Opt_dirwh: | |
24058 | + AuDbg("dirwh %d\n", opt->dirwh); | |
24059 | + break; | |
24060 | + case Opt_rdcache: | |
24061 | + AuDbg("rdcache %d\n", opt->rdcache); | |
24062 | + break; | |
24063 | + case Opt_rdblk: | |
24064 | + AuDbg("rdblk %u\n", opt->rdblk); | |
24065 | + break; | |
dece6358 AM |
24066 | + case Opt_rdblk_def: |
24067 | + AuDbg("rdblk_def\n"); | |
24068 | + break; | |
1facf9fc | 24069 | + case Opt_rdhash: |
24070 | + AuDbg("rdhash %u\n", opt->rdhash); | |
24071 | + break; | |
dece6358 AM |
24072 | + case Opt_rdhash_def: |
24073 | + AuDbg("rdhash_def\n"); | |
24074 | + break; | |
1facf9fc | 24075 | + case Opt_xino: |
24076 | + u.xino = &opt->xino; | |
523b37e3 | 24077 | + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file); |
1facf9fc | 24078 | + break; |
24079 | + case Opt_trunc_xino: | |
24080 | + AuLabel(trunc_xino); | |
24081 | + break; | |
24082 | + case Opt_notrunc_xino: | |
24083 | + AuLabel(notrunc_xino); | |
24084 | + break; | |
24085 | + case Opt_trunc_xino_path: | |
24086 | + case Opt_itrunc_xino: | |
24087 | + u.xino_itrunc = &opt->xino_itrunc; | |
24088 | + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex); | |
24089 | + break; | |
1facf9fc | 24090 | + case Opt_noxino: |
24091 | + AuLabel(noxino); | |
24092 | + break; | |
24093 | + case Opt_trunc_xib: | |
24094 | + AuLabel(trunc_xib); | |
24095 | + break; | |
24096 | + case Opt_notrunc_xib: | |
24097 | + AuLabel(notrunc_xib); | |
24098 | + break; | |
dece6358 AM |
24099 | + case Opt_shwh: |
24100 | + AuLabel(shwh); | |
24101 | + break; | |
24102 | + case Opt_noshwh: | |
24103 | + AuLabel(noshwh); | |
24104 | + break; | |
076b876e AM |
24105 | + case Opt_dirperm1: |
24106 | + AuLabel(dirperm1); | |
24107 | + break; | |
24108 | + case Opt_nodirperm1: | |
24109 | + AuLabel(nodirperm1); | |
24110 | + break; | |
1facf9fc | 24111 | + case Opt_plink: |
24112 | + AuLabel(plink); | |
24113 | + break; | |
24114 | + case Opt_noplink: | |
24115 | + AuLabel(noplink); | |
24116 | + break; | |
24117 | + case Opt_list_plink: | |
24118 | + AuLabel(list_plink); | |
24119 | + break; | |
24120 | + case Opt_udba: | |
24121 | + AuDbg("udba %d, %s\n", | |
24122 | + opt->udba, au_optstr_udba(opt->udba)); | |
24123 | + break; | |
4a4d8108 AM |
24124 | + case Opt_dio: |
24125 | + AuLabel(dio); | |
24126 | + break; | |
24127 | + case Opt_nodio: | |
24128 | + AuLabel(nodio); | |
24129 | + break; | |
1facf9fc | 24130 | + case Opt_diropq_a: |
24131 | + AuLabel(diropq_a); | |
24132 | + break; | |
24133 | + case Opt_diropq_w: | |
24134 | + AuLabel(diropq_w); | |
24135 | + break; | |
24136 | + case Opt_warn_perm: | |
24137 | + AuLabel(warn_perm); | |
24138 | + break; | |
24139 | + case Opt_nowarn_perm: | |
24140 | + AuLabel(nowarn_perm); | |
24141 | + break; | |
1facf9fc | 24142 | + case Opt_verbose: |
24143 | + AuLabel(verbose); | |
24144 | + break; | |
24145 | + case Opt_noverbose: | |
24146 | + AuLabel(noverbose); | |
24147 | + break; | |
24148 | + case Opt_sum: | |
24149 | + AuLabel(sum); | |
24150 | + break; | |
24151 | + case Opt_nosum: | |
24152 | + AuLabel(nosum); | |
24153 | + break; | |
24154 | + case Opt_wsum: | |
24155 | + AuLabel(wsum); | |
24156 | + break; | |
24157 | + case Opt_wbr_create: | |
24158 | + u.create = &opt->wbr_create; | |
24159 | + AuDbg("create %d, %s\n", u.create->wbr_create, | |
24160 | + au_optstr_wbr_create(u.create->wbr_create)); | |
24161 | + switch (u.create->wbr_create) { | |
24162 | + case AuWbrCreate_MFSV: | |
24163 | + case AuWbrCreate_PMFSV: | |
24164 | + AuDbg("%d sec\n", u.create->mfs_second); | |
24165 | + break; | |
24166 | + case AuWbrCreate_MFSRR: | |
f2c43d5f | 24167 | + case AuWbrCreate_TDMFS: |
1facf9fc | 24168 | + AuDbg("%llu watermark\n", |
24169 | + u.create->mfsrr_watermark); | |
24170 | + break; | |
24171 | + case AuWbrCreate_MFSRRV: | |
f2c43d5f | 24172 | + case AuWbrCreate_TDMFSV: |
392086de | 24173 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 24174 | + AuDbg("%llu watermark, %d sec\n", |
24175 | + u.create->mfsrr_watermark, | |
24176 | + u.create->mfs_second); | |
24177 | + break; | |
24178 | + } | |
24179 | + break; | |
24180 | + case Opt_wbr_copyup: | |
24181 | + AuDbg("copyup %d, %s\n", opt->wbr_copyup, | |
24182 | + au_optstr_wbr_copyup(opt->wbr_copyup)); | |
24183 | + break; | |
076b876e AM |
24184 | + case Opt_fhsm_sec: |
24185 | + AuDbg("fhsm_sec %u\n", opt->fhsm_second); | |
24186 | + break; | |
c1595e42 JR |
24187 | + case Opt_acl: |
24188 | + AuLabel(acl); | |
24189 | + break; | |
24190 | + case Opt_noacl: | |
24191 | + AuLabel(noacl); | |
24192 | + break; | |
1facf9fc | 24193 | + default: |
24194 | + BUG(); | |
24195 | + } | |
24196 | + opt++; | |
24197 | + } | |
24198 | +#endif | |
24199 | +} | |
24200 | + | |
24201 | +void au_opts_free(struct au_opts *opts) | |
24202 | +{ | |
24203 | + struct au_opt *opt; | |
24204 | + | |
24205 | + opt = opts->opt; | |
24206 | + while (opt->type != Opt_tail) { | |
24207 | + switch (opt->type) { | |
24208 | + case Opt_add: | |
24209 | + case Opt_append: | |
24210 | + case Opt_prepend: | |
24211 | + path_put(&opt->add.path); | |
24212 | + break; | |
24213 | + case Opt_del: | |
24214 | + case Opt_idel: | |
24215 | + path_put(&opt->del.h_path); | |
24216 | + break; | |
24217 | + case Opt_mod: | |
24218 | + case Opt_imod: | |
24219 | + dput(opt->mod.h_root); | |
24220 | + break; | |
24221 | + case Opt_xino: | |
24222 | + fput(opt->xino.file); | |
24223 | + break; | |
24224 | + } | |
24225 | + opt++; | |
24226 | + } | |
24227 | +} | |
24228 | + | |
24229 | +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags, | |
24230 | + aufs_bindex_t bindex) | |
24231 | +{ | |
24232 | + int err; | |
24233 | + struct au_opt_add *add = &opt->add; | |
24234 | + char *p; | |
24235 | + | |
24236 | + add->bindex = bindex; | |
1e00d052 | 24237 | + add->perm = AuBrPerm_RO; |
1facf9fc | 24238 | + add->pathname = opt_str; |
24239 | + p = strchr(opt_str, '='); | |
24240 | + if (p) { | |
24241 | + *p++ = 0; | |
24242 | + if (*p) | |
24243 | + add->perm = br_perm_val(p); | |
24244 | + } | |
24245 | + | |
24246 | + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path); | |
24247 | + if (!err) { | |
24248 | + if (!p) { | |
24249 | + add->perm = AuBrPerm_RO; | |
24250 | + if (au_test_fs_rr(add->path.dentry->d_sb)) | |
24251 | + add->perm = AuBrPerm_RR; | |
24252 | + else if (!bindex && !(sb_flags & MS_RDONLY)) | |
24253 | + add->perm = AuBrPerm_RW; | |
24254 | + } | |
24255 | + opt->type = Opt_add; | |
24256 | + goto out; | |
24257 | + } | |
4a4d8108 | 24258 | + pr_err("lookup failed %s (%d)\n", add->pathname, err); |
1facf9fc | 24259 | + err = -EINVAL; |
24260 | + | |
4f0767ce | 24261 | +out: |
1facf9fc | 24262 | + return err; |
24263 | +} | |
24264 | + | |
24265 | +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[]) | |
24266 | +{ | |
24267 | + int err; | |
24268 | + | |
24269 | + del->pathname = args[0].from; | |
24270 | + AuDbg("del path %s\n", del->pathname); | |
24271 | + | |
24272 | + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path); | |
24273 | + if (unlikely(err)) | |
4a4d8108 | 24274 | + pr_err("lookup failed %s (%d)\n", del->pathname, err); |
1facf9fc | 24275 | + |
24276 | + return err; | |
24277 | +} | |
24278 | + | |
24279 | +#if 0 /* reserved for future use */ | |
24280 | +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex, | |
24281 | + struct au_opt_del *del, substring_t args[]) | |
24282 | +{ | |
24283 | + int err; | |
24284 | + struct dentry *root; | |
24285 | + | |
24286 | + err = -EINVAL; | |
24287 | + root = sb->s_root; | |
24288 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 24289 | + if (bindex < 0 || au_sbbot(sb) < bindex) { |
4a4d8108 | 24290 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 24291 | + goto out; |
24292 | + } | |
24293 | + | |
24294 | + err = 0; | |
24295 | + del->h_path.dentry = dget(au_h_dptr(root, bindex)); | |
24296 | + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex)); | |
24297 | + | |
4f0767ce | 24298 | +out: |
1facf9fc | 24299 | + aufs_read_unlock(root, !AuLock_IR); |
24300 | + return err; | |
24301 | +} | |
24302 | +#endif | |
24303 | + | |
4a4d8108 AM |
24304 | +static int noinline_for_stack |
24305 | +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[]) | |
1facf9fc | 24306 | +{ |
24307 | + int err; | |
24308 | + struct path path; | |
24309 | + char *p; | |
24310 | + | |
24311 | + err = -EINVAL; | |
24312 | + mod->path = args[0].from; | |
24313 | + p = strchr(mod->path, '='); | |
24314 | + if (unlikely(!p)) { | |
4a4d8108 | 24315 | + pr_err("no permssion %s\n", args[0].from); |
1facf9fc | 24316 | + goto out; |
24317 | + } | |
24318 | + | |
24319 | + *p++ = 0; | |
24320 | + err = vfsub_kern_path(mod->path, lkup_dirflags, &path); | |
24321 | + if (unlikely(err)) { | |
4a4d8108 | 24322 | + pr_err("lookup failed %s (%d)\n", mod->path, err); |
1facf9fc | 24323 | + goto out; |
24324 | + } | |
24325 | + | |
24326 | + mod->perm = br_perm_val(p); | |
24327 | + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p); | |
24328 | + mod->h_root = dget(path.dentry); | |
24329 | + path_put(&path); | |
24330 | + | |
4f0767ce | 24331 | +out: |
1facf9fc | 24332 | + return err; |
24333 | +} | |
24334 | + | |
24335 | +#if 0 /* reserved for future use */ | |
24336 | +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex, | |
24337 | + struct au_opt_mod *mod, substring_t args[]) | |
24338 | +{ | |
24339 | + int err; | |
24340 | + struct dentry *root; | |
24341 | + | |
24342 | + err = -EINVAL; | |
24343 | + root = sb->s_root; | |
24344 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 24345 | + if (bindex < 0 || au_sbbot(sb) < bindex) { |
4a4d8108 | 24346 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 24347 | + goto out; |
24348 | + } | |
24349 | + | |
24350 | + err = 0; | |
24351 | + mod->perm = br_perm_val(args[1].from); | |
24352 | + AuDbg("mod path %s, perm 0x%x, %s\n", | |
24353 | + mod->path, mod->perm, args[1].from); | |
24354 | + mod->h_root = dget(au_h_dptr(root, bindex)); | |
24355 | + | |
4f0767ce | 24356 | +out: |
1facf9fc | 24357 | + aufs_read_unlock(root, !AuLock_IR); |
24358 | + return err; | |
24359 | +} | |
24360 | +#endif | |
24361 | + | |
24362 | +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino, | |
24363 | + substring_t args[]) | |
24364 | +{ | |
24365 | + int err; | |
24366 | + struct file *file; | |
24367 | + | |
24368 | + file = au_xino_create(sb, args[0].from, /*silent*/0); | |
24369 | + err = PTR_ERR(file); | |
24370 | + if (IS_ERR(file)) | |
24371 | + goto out; | |
24372 | + | |
24373 | + err = -EINVAL; | |
2000de60 | 24374 | + if (unlikely(file->f_path.dentry->d_sb == sb)) { |
1facf9fc | 24375 | + fput(file); |
4a4d8108 | 24376 | + pr_err("%s must be outside\n", args[0].from); |
1facf9fc | 24377 | + goto out; |
24378 | + } | |
24379 | + | |
24380 | + err = 0; | |
24381 | + xino->file = file; | |
24382 | + xino->path = args[0].from; | |
24383 | + | |
4f0767ce | 24384 | +out: |
1facf9fc | 24385 | + return err; |
24386 | +} | |
24387 | + | |
4a4d8108 AM |
24388 | +static int noinline_for_stack |
24389 | +au_opts_parse_xino_itrunc_path(struct super_block *sb, | |
24390 | + struct au_opt_xino_itrunc *xino_itrunc, | |
24391 | + substring_t args[]) | |
1facf9fc | 24392 | +{ |
24393 | + int err; | |
5afbbe0d | 24394 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 24395 | + struct path path; |
24396 | + struct dentry *root; | |
24397 | + | |
24398 | + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path); | |
24399 | + if (unlikely(err)) { | |
4a4d8108 | 24400 | + pr_err("lookup failed %s (%d)\n", args[0].from, err); |
1facf9fc | 24401 | + goto out; |
24402 | + } | |
24403 | + | |
24404 | + xino_itrunc->bindex = -1; | |
24405 | + root = sb->s_root; | |
24406 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d AM |
24407 | + bbot = au_sbbot(sb); |
24408 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
1facf9fc | 24409 | + if (au_h_dptr(root, bindex) == path.dentry) { |
24410 | + xino_itrunc->bindex = bindex; | |
24411 | + break; | |
24412 | + } | |
24413 | + } | |
24414 | + aufs_read_unlock(root, !AuLock_IR); | |
24415 | + path_put(&path); | |
24416 | + | |
24417 | + if (unlikely(xino_itrunc->bindex < 0)) { | |
4a4d8108 | 24418 | + pr_err("no such branch %s\n", args[0].from); |
1facf9fc | 24419 | + err = -EINVAL; |
24420 | + } | |
24421 | + | |
4f0767ce | 24422 | +out: |
1facf9fc | 24423 | + return err; |
24424 | +} | |
24425 | + | |
24426 | +/* called without aufs lock */ | |
24427 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts) | |
24428 | +{ | |
24429 | + int err, n, token; | |
24430 | + aufs_bindex_t bindex; | |
24431 | + unsigned char skipped; | |
24432 | + struct dentry *root; | |
24433 | + struct au_opt *opt, *opt_tail; | |
24434 | + char *opt_str; | |
24435 | + /* reduce the stack space */ | |
24436 | + union { | |
24437 | + struct au_opt_xino_itrunc *xino_itrunc; | |
24438 | + struct au_opt_wbr_create *create; | |
24439 | + } u; | |
24440 | + struct { | |
24441 | + substring_t args[MAX_OPT_ARGS]; | |
24442 | + } *a; | |
24443 | + | |
24444 | + err = -ENOMEM; | |
24445 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
24446 | + if (unlikely(!a)) | |
24447 | + goto out; | |
24448 | + | |
24449 | + root = sb->s_root; | |
24450 | + err = 0; | |
24451 | + bindex = 0; | |
24452 | + opt = opts->opt; | |
24453 | + opt_tail = opt + opts->max_opt - 1; | |
24454 | + opt->type = Opt_tail; | |
24455 | + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) { | |
24456 | + err = -EINVAL; | |
24457 | + skipped = 0; | |
24458 | + token = match_token(opt_str, options, a->args); | |
24459 | + switch (token) { | |
24460 | + case Opt_br: | |
24461 | + err = 0; | |
24462 | + while (!err && (opt_str = strsep(&a->args[0].from, ":")) | |
24463 | + && *opt_str) { | |
24464 | + err = opt_add(opt, opt_str, opts->sb_flags, | |
24465 | + bindex++); | |
24466 | + if (unlikely(!err && ++opt > opt_tail)) { | |
24467 | + err = -E2BIG; | |
24468 | + break; | |
24469 | + } | |
24470 | + opt->type = Opt_tail; | |
24471 | + skipped = 1; | |
24472 | + } | |
24473 | + break; | |
24474 | + case Opt_add: | |
24475 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 24476 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 24477 | + break; |
24478 | + } | |
24479 | + bindex = n; | |
24480 | + err = opt_add(opt, a->args[1].from, opts->sb_flags, | |
24481 | + bindex); | |
24482 | + if (!err) | |
24483 | + opt->type = token; | |
24484 | + break; | |
24485 | + case Opt_append: | |
24486 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
24487 | + /*dummy bindex*/1); | |
24488 | + if (!err) | |
24489 | + opt->type = token; | |
24490 | + break; | |
24491 | + case Opt_prepend: | |
24492 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
24493 | + /*bindex*/0); | |
24494 | + if (!err) | |
24495 | + opt->type = token; | |
24496 | + break; | |
24497 | + case Opt_del: | |
24498 | + err = au_opts_parse_del(&opt->del, a->args); | |
24499 | + if (!err) | |
24500 | + opt->type = token; | |
24501 | + break; | |
24502 | +#if 0 /* reserved for future use */ | |
24503 | + case Opt_idel: | |
24504 | + del->pathname = "(indexed)"; | |
24505 | + if (unlikely(match_int(&args[0], &n))) { | |
4a4d8108 | 24506 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 24507 | + break; |
24508 | + } | |
24509 | + err = au_opts_parse_idel(sb, n, &opt->del, a->args); | |
24510 | + if (!err) | |
24511 | + opt->type = token; | |
24512 | + break; | |
24513 | +#endif | |
24514 | + case Opt_mod: | |
24515 | + err = au_opts_parse_mod(&opt->mod, a->args); | |
24516 | + if (!err) | |
24517 | + opt->type = token; | |
24518 | + break; | |
24519 | +#ifdef IMOD /* reserved for future use */ | |
24520 | + case Opt_imod: | |
24521 | + u.mod->path = "(indexed)"; | |
24522 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 24523 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 24524 | + break; |
24525 | + } | |
24526 | + err = au_opts_parse_imod(sb, n, &opt->mod, a->args); | |
24527 | + if (!err) | |
24528 | + opt->type = token; | |
24529 | + break; | |
24530 | +#endif | |
24531 | + case Opt_xino: | |
24532 | + err = au_opts_parse_xino(sb, &opt->xino, a->args); | |
24533 | + if (!err) | |
24534 | + opt->type = token; | |
24535 | + break; | |
24536 | + | |
24537 | + case Opt_trunc_xino_path: | |
24538 | + err = au_opts_parse_xino_itrunc_path | |
24539 | + (sb, &opt->xino_itrunc, a->args); | |
24540 | + if (!err) | |
24541 | + opt->type = token; | |
24542 | + break; | |
24543 | + | |
24544 | + case Opt_itrunc_xino: | |
24545 | + u.xino_itrunc = &opt->xino_itrunc; | |
24546 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 24547 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 24548 | + break; |
24549 | + } | |
24550 | + u.xino_itrunc->bindex = n; | |
24551 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 24552 | + if (n < 0 || au_sbbot(sb) < n) { |
4a4d8108 | 24553 | + pr_err("out of bounds, %d\n", n); |
1facf9fc | 24554 | + aufs_read_unlock(root, !AuLock_IR); |
24555 | + break; | |
24556 | + } | |
24557 | + aufs_read_unlock(root, !AuLock_IR); | |
24558 | + err = 0; | |
24559 | + opt->type = token; | |
24560 | + break; | |
24561 | + | |
24562 | + case Opt_dirwh: | |
24563 | + if (unlikely(match_int(&a->args[0], &opt->dirwh))) | |
24564 | + break; | |
24565 | + err = 0; | |
24566 | + opt->type = token; | |
24567 | + break; | |
24568 | + | |
24569 | + case Opt_rdcache: | |
027c5e7a AM |
24570 | + if (unlikely(match_int(&a->args[0], &n))) { |
24571 | + pr_err("bad integer in %s\n", opt_str); | |
1facf9fc | 24572 | + break; |
027c5e7a AM |
24573 | + } |
24574 | + if (unlikely(n > AUFS_RDCACHE_MAX)) { | |
24575 | + pr_err("rdcache must be smaller than %d\n", | |
24576 | + AUFS_RDCACHE_MAX); | |
24577 | + break; | |
24578 | + } | |
24579 | + opt->rdcache = n; | |
1facf9fc | 24580 | + err = 0; |
24581 | + opt->type = token; | |
24582 | + break; | |
24583 | + case Opt_rdblk: | |
24584 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 24585 | + || n < 0 |
1facf9fc | 24586 | + || n > KMALLOC_MAX_SIZE)) { |
4a4d8108 | 24587 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 24588 | + break; |
24589 | + } | |
1308ab2a | 24590 | + if (unlikely(n && n < NAME_MAX)) { |
4a4d8108 AM |
24591 | + pr_err("rdblk must be larger than %d\n", |
24592 | + NAME_MAX); | |
1facf9fc | 24593 | + break; |
24594 | + } | |
24595 | + opt->rdblk = n; | |
24596 | + err = 0; | |
24597 | + opt->type = token; | |
24598 | + break; | |
24599 | + case Opt_rdhash: | |
24600 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 24601 | + || n < 0 |
1facf9fc | 24602 | + || n * sizeof(struct hlist_head) |
24603 | + > KMALLOC_MAX_SIZE)) { | |
4a4d8108 | 24604 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 24605 | + break; |
24606 | + } | |
24607 | + opt->rdhash = n; | |
24608 | + err = 0; | |
24609 | + opt->type = token; | |
24610 | + break; | |
24611 | + | |
24612 | + case Opt_trunc_xino: | |
24613 | + case Opt_notrunc_xino: | |
24614 | + case Opt_noxino: | |
24615 | + case Opt_trunc_xib: | |
24616 | + case Opt_notrunc_xib: | |
dece6358 AM |
24617 | + case Opt_shwh: |
24618 | + case Opt_noshwh: | |
076b876e AM |
24619 | + case Opt_dirperm1: |
24620 | + case Opt_nodirperm1: | |
1facf9fc | 24621 | + case Opt_plink: |
24622 | + case Opt_noplink: | |
24623 | + case Opt_list_plink: | |
4a4d8108 AM |
24624 | + case Opt_dio: |
24625 | + case Opt_nodio: | |
1facf9fc | 24626 | + case Opt_diropq_a: |
24627 | + case Opt_diropq_w: | |
24628 | + case Opt_warn_perm: | |
24629 | + case Opt_nowarn_perm: | |
1facf9fc | 24630 | + case Opt_verbose: |
24631 | + case Opt_noverbose: | |
24632 | + case Opt_sum: | |
24633 | + case Opt_nosum: | |
24634 | + case Opt_wsum: | |
dece6358 AM |
24635 | + case Opt_rdblk_def: |
24636 | + case Opt_rdhash_def: | |
c1595e42 JR |
24637 | + case Opt_acl: |
24638 | + case Opt_noacl: | |
1facf9fc | 24639 | + err = 0; |
24640 | + opt->type = token; | |
24641 | + break; | |
24642 | + | |
24643 | + case Opt_udba: | |
24644 | + opt->udba = udba_val(a->args[0].from); | |
24645 | + if (opt->udba >= 0) { | |
24646 | + err = 0; | |
24647 | + opt->type = token; | |
24648 | + } else | |
4a4d8108 | 24649 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 24650 | + break; |
24651 | + | |
24652 | + case Opt_wbr_create: | |
24653 | + u.create = &opt->wbr_create; | |
24654 | + u.create->wbr_create | |
24655 | + = au_wbr_create_val(a->args[0].from, u.create); | |
24656 | + if (u.create->wbr_create >= 0) { | |
24657 | + err = 0; | |
24658 | + opt->type = token; | |
24659 | + } else | |
4a4d8108 | 24660 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 24661 | + break; |
24662 | + case Opt_wbr_copyup: | |
24663 | + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from); | |
24664 | + if (opt->wbr_copyup >= 0) { | |
24665 | + err = 0; | |
24666 | + opt->type = token; | |
24667 | + } else | |
4a4d8108 | 24668 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 24669 | + break; |
24670 | + | |
076b876e AM |
24671 | + case Opt_fhsm_sec: |
24672 | + if (unlikely(match_int(&a->args[0], &n) | |
24673 | + || n < 0)) { | |
24674 | + pr_err("bad integer in %s\n", opt_str); | |
24675 | + break; | |
24676 | + } | |
24677 | + if (sysaufs_brs) { | |
24678 | + opt->fhsm_second = n; | |
24679 | + opt->type = token; | |
24680 | + } else | |
24681 | + pr_warn("ignored %s\n", opt_str); | |
24682 | + err = 0; | |
24683 | + break; | |
24684 | + | |
1facf9fc | 24685 | + case Opt_ignore: |
0c3ec466 | 24686 | + pr_warn("ignored %s\n", opt_str); |
1facf9fc | 24687 | + /*FALLTHROUGH*/ |
24688 | + case Opt_ignore_silent: | |
24689 | + skipped = 1; | |
24690 | + err = 0; | |
24691 | + break; | |
24692 | + case Opt_err: | |
4a4d8108 | 24693 | + pr_err("unknown option %s\n", opt_str); |
1facf9fc | 24694 | + break; |
24695 | + } | |
24696 | + | |
24697 | + if (!err && !skipped) { | |
24698 | + if (unlikely(++opt > opt_tail)) { | |
24699 | + err = -E2BIG; | |
24700 | + opt--; | |
24701 | + opt->type = Opt_tail; | |
24702 | + break; | |
24703 | + } | |
24704 | + opt->type = Opt_tail; | |
24705 | + } | |
24706 | + } | |
24707 | + | |
f0c0a007 | 24708 | + au_delayed_kfree(a); |
1facf9fc | 24709 | + dump_opts(opts); |
24710 | + if (unlikely(err)) | |
24711 | + au_opts_free(opts); | |
24712 | + | |
4f0767ce | 24713 | +out: |
1facf9fc | 24714 | + return err; |
24715 | +} | |
24716 | + | |
24717 | +static int au_opt_wbr_create(struct super_block *sb, | |
24718 | + struct au_opt_wbr_create *create) | |
24719 | +{ | |
24720 | + int err; | |
24721 | + struct au_sbinfo *sbinfo; | |
24722 | + | |
dece6358 AM |
24723 | + SiMustWriteLock(sb); |
24724 | + | |
1facf9fc | 24725 | + err = 1; /* handled */ |
24726 | + sbinfo = au_sbi(sb); | |
24727 | + if (sbinfo->si_wbr_create_ops->fin) { | |
24728 | + err = sbinfo->si_wbr_create_ops->fin(sb); | |
24729 | + if (!err) | |
24730 | + err = 1; | |
24731 | + } | |
24732 | + | |
24733 | + sbinfo->si_wbr_create = create->wbr_create; | |
24734 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create; | |
24735 | + switch (create->wbr_create) { | |
24736 | + case AuWbrCreate_MFSRRV: | |
24737 | + case AuWbrCreate_MFSRR: | |
f2c43d5f AM |
24738 | + case AuWbrCreate_TDMFS: |
24739 | + case AuWbrCreate_TDMFSV: | |
392086de AM |
24740 | + case AuWbrCreate_PMFSRR: |
24741 | + case AuWbrCreate_PMFSRRV: | |
1facf9fc | 24742 | + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark; |
24743 | + /*FALLTHROUGH*/ | |
24744 | + case AuWbrCreate_MFS: | |
24745 | + case AuWbrCreate_MFSV: | |
24746 | + case AuWbrCreate_PMFS: | |
24747 | + case AuWbrCreate_PMFSV: | |
e49829fe JR |
24748 | + sbinfo->si_wbr_mfs.mfs_expire |
24749 | + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC); | |
1facf9fc | 24750 | + break; |
24751 | + } | |
24752 | + | |
24753 | + if (sbinfo->si_wbr_create_ops->init) | |
24754 | + sbinfo->si_wbr_create_ops->init(sb); /* ignore */ | |
24755 | + | |
24756 | + return err; | |
24757 | +} | |
24758 | + | |
24759 | +/* | |
24760 | + * returns, | |
24761 | + * plus: processed without an error | |
24762 | + * zero: unprocessed | |
24763 | + */ | |
24764 | +static int au_opt_simple(struct super_block *sb, struct au_opt *opt, | |
24765 | + struct au_opts *opts) | |
24766 | +{ | |
24767 | + int err; | |
24768 | + struct au_sbinfo *sbinfo; | |
24769 | + | |
dece6358 AM |
24770 | + SiMustWriteLock(sb); |
24771 | + | |
1facf9fc | 24772 | + err = 1; /* handled */ |
24773 | + sbinfo = au_sbi(sb); | |
24774 | + switch (opt->type) { | |
24775 | + case Opt_udba: | |
24776 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; | |
24777 | + sbinfo->si_mntflags |= opt->udba; | |
24778 | + opts->given_udba |= opt->udba; | |
24779 | + break; | |
24780 | + | |
24781 | + case Opt_plink: | |
24782 | + au_opt_set(sbinfo->si_mntflags, PLINK); | |
24783 | + break; | |
24784 | + case Opt_noplink: | |
24785 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
e49829fe | 24786 | + au_plink_put(sb, /*verbose*/1); |
1facf9fc | 24787 | + au_opt_clr(sbinfo->si_mntflags, PLINK); |
24788 | + break; | |
24789 | + case Opt_list_plink: | |
24790 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
24791 | + au_plink_list(sb); | |
24792 | + break; | |
24793 | + | |
4a4d8108 AM |
24794 | + case Opt_dio: |
24795 | + au_opt_set(sbinfo->si_mntflags, DIO); | |
24796 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
24797 | + break; | |
24798 | + case Opt_nodio: | |
24799 | + au_opt_clr(sbinfo->si_mntflags, DIO); | |
24800 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
24801 | + break; | |
24802 | + | |
076b876e AM |
24803 | + case Opt_fhsm_sec: |
24804 | + au_fhsm_set(sbinfo, opt->fhsm_second); | |
24805 | + break; | |
24806 | + | |
1facf9fc | 24807 | + case Opt_diropq_a: |
24808 | + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
24809 | + break; | |
24810 | + case Opt_diropq_w: | |
24811 | + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
24812 | + break; | |
24813 | + | |
24814 | + case Opt_warn_perm: | |
24815 | + au_opt_set(sbinfo->si_mntflags, WARN_PERM); | |
24816 | + break; | |
24817 | + case Opt_nowarn_perm: | |
24818 | + au_opt_clr(sbinfo->si_mntflags, WARN_PERM); | |
24819 | + break; | |
24820 | + | |
1facf9fc | 24821 | + case Opt_verbose: |
24822 | + au_opt_set(sbinfo->si_mntflags, VERBOSE); | |
24823 | + break; | |
24824 | + case Opt_noverbose: | |
24825 | + au_opt_clr(sbinfo->si_mntflags, VERBOSE); | |
24826 | + break; | |
24827 | + | |
24828 | + case Opt_sum: | |
24829 | + au_opt_set(sbinfo->si_mntflags, SUM); | |
24830 | + break; | |
24831 | + case Opt_wsum: | |
24832 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
24833 | + au_opt_set(sbinfo->si_mntflags, SUM_W); | |
24834 | + case Opt_nosum: | |
24835 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
24836 | + au_opt_clr(sbinfo->si_mntflags, SUM_W); | |
24837 | + break; | |
24838 | + | |
24839 | + case Opt_wbr_create: | |
24840 | + err = au_opt_wbr_create(sb, &opt->wbr_create); | |
24841 | + break; | |
24842 | + case Opt_wbr_copyup: | |
24843 | + sbinfo->si_wbr_copyup = opt->wbr_copyup; | |
24844 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup; | |
24845 | + break; | |
24846 | + | |
24847 | + case Opt_dirwh: | |
24848 | + sbinfo->si_dirwh = opt->dirwh; | |
24849 | + break; | |
24850 | + | |
24851 | + case Opt_rdcache: | |
e49829fe JR |
24852 | + sbinfo->si_rdcache |
24853 | + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC); | |
1facf9fc | 24854 | + break; |
24855 | + case Opt_rdblk: | |
24856 | + sbinfo->si_rdblk = opt->rdblk; | |
24857 | + break; | |
dece6358 AM |
24858 | + case Opt_rdblk_def: |
24859 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; | |
24860 | + break; | |
1facf9fc | 24861 | + case Opt_rdhash: |
24862 | + sbinfo->si_rdhash = opt->rdhash; | |
24863 | + break; | |
dece6358 AM |
24864 | + case Opt_rdhash_def: |
24865 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
24866 | + break; | |
24867 | + | |
24868 | + case Opt_shwh: | |
24869 | + au_opt_set(sbinfo->si_mntflags, SHWH); | |
24870 | + break; | |
24871 | + case Opt_noshwh: | |
24872 | + au_opt_clr(sbinfo->si_mntflags, SHWH); | |
24873 | + break; | |
1facf9fc | 24874 | + |
076b876e AM |
24875 | + case Opt_dirperm1: |
24876 | + au_opt_set(sbinfo->si_mntflags, DIRPERM1); | |
24877 | + break; | |
24878 | + case Opt_nodirperm1: | |
24879 | + au_opt_clr(sbinfo->si_mntflags, DIRPERM1); | |
24880 | + break; | |
24881 | + | |
1facf9fc | 24882 | + case Opt_trunc_xino: |
24883 | + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO); | |
24884 | + break; | |
24885 | + case Opt_notrunc_xino: | |
24886 | + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO); | |
24887 | + break; | |
24888 | + | |
24889 | + case Opt_trunc_xino_path: | |
24890 | + case Opt_itrunc_xino: | |
24891 | + err = au_xino_trunc(sb, opt->xino_itrunc.bindex); | |
24892 | + if (!err) | |
24893 | + err = 1; | |
24894 | + break; | |
24895 | + | |
24896 | + case Opt_trunc_xib: | |
24897 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
24898 | + break; | |
24899 | + case Opt_notrunc_xib: | |
24900 | + au_fclr_opts(opts->flags, TRUNC_XIB); | |
24901 | + break; | |
24902 | + | |
c1595e42 JR |
24903 | + case Opt_acl: |
24904 | + sb->s_flags |= MS_POSIXACL; | |
24905 | + break; | |
24906 | + case Opt_noacl: | |
24907 | + sb->s_flags &= ~MS_POSIXACL; | |
24908 | + break; | |
24909 | + | |
1facf9fc | 24910 | + default: |
24911 | + err = 0; | |
24912 | + break; | |
24913 | + } | |
24914 | + | |
24915 | + return err; | |
24916 | +} | |
24917 | + | |
24918 | +/* | |
24919 | + * returns tri-state. | |
24920 | + * plus: processed without an error | |
24921 | + * zero: unprocessed | |
24922 | + * minus: error | |
24923 | + */ | |
24924 | +static int au_opt_br(struct super_block *sb, struct au_opt *opt, | |
24925 | + struct au_opts *opts) | |
24926 | +{ | |
24927 | + int err, do_refresh; | |
24928 | + | |
24929 | + err = 0; | |
24930 | + switch (opt->type) { | |
24931 | + case Opt_append: | |
5afbbe0d | 24932 | + opt->add.bindex = au_sbbot(sb) + 1; |
1facf9fc | 24933 | + if (opt->add.bindex < 0) |
24934 | + opt->add.bindex = 0; | |
24935 | + goto add; | |
24936 | + case Opt_prepend: | |
24937 | + opt->add.bindex = 0; | |
f6b6e03d | 24938 | + add: /* indented label */ |
1facf9fc | 24939 | + case Opt_add: |
24940 | + err = au_br_add(sb, &opt->add, | |
24941 | + au_ftest_opts(opts->flags, REMOUNT)); | |
24942 | + if (!err) { | |
24943 | + err = 1; | |
027c5e7a | 24944 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24945 | + } |
24946 | + break; | |
24947 | + | |
24948 | + case Opt_del: | |
24949 | + case Opt_idel: | |
24950 | + err = au_br_del(sb, &opt->del, | |
24951 | + au_ftest_opts(opts->flags, REMOUNT)); | |
24952 | + if (!err) { | |
24953 | + err = 1; | |
24954 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
027c5e7a | 24955 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24956 | + } |
24957 | + break; | |
24958 | + | |
24959 | + case Opt_mod: | |
24960 | + case Opt_imod: | |
24961 | + err = au_br_mod(sb, &opt->mod, | |
24962 | + au_ftest_opts(opts->flags, REMOUNT), | |
24963 | + &do_refresh); | |
24964 | + if (!err) { | |
24965 | + err = 1; | |
027c5e7a AM |
24966 | + if (do_refresh) |
24967 | + au_fset_opts(opts->flags, REFRESH); | |
1facf9fc | 24968 | + } |
24969 | + break; | |
24970 | + } | |
24971 | + | |
24972 | + return err; | |
24973 | +} | |
24974 | + | |
24975 | +static int au_opt_xino(struct super_block *sb, struct au_opt *opt, | |
24976 | + struct au_opt_xino **opt_xino, | |
24977 | + struct au_opts *opts) | |
24978 | +{ | |
24979 | + int err; | |
5afbbe0d | 24980 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 24981 | + struct dentry *root, *parent, *h_root; |
24982 | + | |
24983 | + err = 0; | |
24984 | + switch (opt->type) { | |
24985 | + case Opt_xino: | |
24986 | + err = au_xino_set(sb, &opt->xino, | |
24987 | + !!au_ftest_opts(opts->flags, REMOUNT)); | |
24988 | + if (unlikely(err)) | |
24989 | + break; | |
24990 | + | |
24991 | + *opt_xino = &opt->xino; | |
24992 | + au_xino_brid_set(sb, -1); | |
24993 | + | |
24994 | + /* safe d_parent access */ | |
2000de60 | 24995 | + parent = opt->xino.file->f_path.dentry->d_parent; |
1facf9fc | 24996 | + root = sb->s_root; |
5afbbe0d AM |
24997 | + bbot = au_sbbot(sb); |
24998 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
1facf9fc | 24999 | + h_root = au_h_dptr(root, bindex); |
25000 | + if (h_root == parent) { | |
25001 | + au_xino_brid_set(sb, au_sbr_id(sb, bindex)); | |
25002 | + break; | |
25003 | + } | |
25004 | + } | |
25005 | + break; | |
25006 | + | |
25007 | + case Opt_noxino: | |
25008 | + au_xino_clr(sb); | |
25009 | + au_xino_brid_set(sb, -1); | |
25010 | + *opt_xino = (void *)-1; | |
25011 | + break; | |
25012 | + } | |
25013 | + | |
25014 | + return err; | |
25015 | +} | |
25016 | + | |
25017 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
25018 | + unsigned int pending) | |
25019 | +{ | |
076b876e | 25020 | + int err, fhsm; |
5afbbe0d | 25021 | + aufs_bindex_t bindex, bbot; |
79b8bda9 | 25022 | + unsigned char do_plink, skip, do_free, can_no_dreval; |
1facf9fc | 25023 | + struct au_branch *br; |
25024 | + struct au_wbr *wbr; | |
79b8bda9 | 25025 | + struct dentry *root, *dentry; |
1facf9fc | 25026 | + struct inode *dir, *h_dir; |
25027 | + struct au_sbinfo *sbinfo; | |
25028 | + struct au_hinode *hdir; | |
25029 | + | |
dece6358 AM |
25030 | + SiMustAnyLock(sb); |
25031 | + | |
1facf9fc | 25032 | + sbinfo = au_sbi(sb); |
25033 | + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA)); | |
25034 | + | |
dece6358 AM |
25035 | + if (!(sb_flags & MS_RDONLY)) { |
25036 | + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0)))) | |
0c3ec466 | 25037 | + pr_warn("first branch should be rw\n"); |
dece6358 | 25038 | + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH))) |
febd17d6 | 25039 | + pr_warn_once("shwh should be used with ro\n"); |
dece6358 | 25040 | + } |
1facf9fc | 25041 | + |
4a4d8108 | 25042 | + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY) |
1facf9fc | 25043 | + && !au_opt_test(sbinfo->si_mntflags, XINO)) |
febd17d6 | 25044 | + pr_warn_once("udba=*notify requires xino\n"); |
1facf9fc | 25045 | + |
076b876e | 25046 | + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1)) |
febd17d6 JR |
25047 | + pr_warn_once("dirperm1 breaks the protection" |
25048 | + " by the permission bits on the lower branch\n"); | |
076b876e | 25049 | + |
1facf9fc | 25050 | + err = 0; |
076b876e | 25051 | + fhsm = 0; |
1facf9fc | 25052 | + root = sb->s_root; |
5527c038 | 25053 | + dir = d_inode(root); |
1facf9fc | 25054 | + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK); |
79b8bda9 AM |
25055 | + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending), |
25056 | + UDBA_NONE); | |
5afbbe0d AM |
25057 | + bbot = au_sbbot(sb); |
25058 | + for (bindex = 0; !err && bindex <= bbot; bindex++) { | |
1facf9fc | 25059 | + skip = 0; |
25060 | + h_dir = au_h_iptr(dir, bindex); | |
25061 | + br = au_sbr(sb, bindex); | |
1facf9fc | 25062 | + |
c1595e42 JR |
25063 | + if ((br->br_perm & AuBrAttr_ICEX) |
25064 | + && !h_dir->i_op->listxattr) | |
25065 | + br->br_perm &= ~AuBrAttr_ICEX; | |
25066 | +#if 0 | |
25067 | + if ((br->br_perm & AuBrAttr_ICEX_SEC) | |
25068 | + && (au_br_sb(br)->s_flags & MS_NOSEC)) | |
25069 | + br->br_perm &= ~AuBrAttr_ICEX_SEC; | |
25070 | +#endif | |
25071 | + | |
25072 | + do_free = 0; | |
1facf9fc | 25073 | + wbr = br->br_wbr; |
25074 | + if (wbr) | |
25075 | + wbr_wh_read_lock(wbr); | |
25076 | + | |
1e00d052 | 25077 | + if (!au_br_writable(br->br_perm)) { |
1facf9fc | 25078 | + do_free = !!wbr; |
25079 | + skip = (!wbr | |
25080 | + || (!wbr->wbr_whbase | |
25081 | + && !wbr->wbr_plink | |
25082 | + && !wbr->wbr_orph)); | |
1e00d052 | 25083 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 25084 | + /* skip = (!br->br_whbase && !br->br_orph); */ |
25085 | + skip = (!wbr || !wbr->wbr_whbase); | |
25086 | + if (skip && wbr) { | |
25087 | + if (do_plink) | |
25088 | + skip = !!wbr->wbr_plink; | |
25089 | + else | |
25090 | + skip = !wbr->wbr_plink; | |
25091 | + } | |
1e00d052 | 25092 | + } else { |
1facf9fc | 25093 | + /* skip = (br->br_whbase && br->br_ohph); */ |
25094 | + skip = (wbr && wbr->wbr_whbase); | |
25095 | + if (skip) { | |
25096 | + if (do_plink) | |
25097 | + skip = !!wbr->wbr_plink; | |
25098 | + else | |
25099 | + skip = !wbr->wbr_plink; | |
25100 | + } | |
1facf9fc | 25101 | + } |
25102 | + if (wbr) | |
25103 | + wbr_wh_read_unlock(wbr); | |
25104 | + | |
79b8bda9 AM |
25105 | + if (can_no_dreval) { |
25106 | + dentry = br->br_path.dentry; | |
25107 | + spin_lock(&dentry->d_lock); | |
25108 | + if (dentry->d_flags & | |
25109 | + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE)) | |
25110 | + can_no_dreval = 0; | |
25111 | + spin_unlock(&dentry->d_lock); | |
25112 | + } | |
25113 | + | |
076b876e AM |
25114 | + if (au_br_fhsm(br->br_perm)) { |
25115 | + fhsm++; | |
25116 | + AuDebugOn(!br->br_fhsm); | |
25117 | + } | |
25118 | + | |
1facf9fc | 25119 | + if (skip) |
25120 | + continue; | |
25121 | + | |
25122 | + hdir = au_hi(dir, bindex); | |
5afbbe0d | 25123 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 25124 | + if (wbr) |
25125 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 25126 | + err = au_wh_init(br, sb); |
1facf9fc | 25127 | + if (wbr) |
25128 | + wbr_wh_write_unlock(wbr); | |
5afbbe0d | 25129 | + au_hn_inode_unlock(hdir); |
1facf9fc | 25130 | + |
25131 | + if (!err && do_free) { | |
f0c0a007 AM |
25132 | + if (wbr) |
25133 | + au_delayed_kfree(wbr); | |
1facf9fc | 25134 | + br->br_wbr = NULL; |
25135 | + } | |
25136 | + } | |
25137 | + | |
79b8bda9 AM |
25138 | + if (can_no_dreval) |
25139 | + au_fset_si(sbinfo, NO_DREVAL); | |
25140 | + else | |
25141 | + au_fclr_si(sbinfo, NO_DREVAL); | |
25142 | + | |
c1595e42 | 25143 | + if (fhsm >= 2) { |
076b876e | 25144 | + au_fset_si(sbinfo, FHSM); |
5afbbe0d | 25145 | + for (bindex = bbot; bindex >= 0; bindex--) { |
c1595e42 JR |
25146 | + br = au_sbr(sb, bindex); |
25147 | + if (au_br_fhsm(br->br_perm)) { | |
25148 | + au_fhsm_set_bottom(sb, bindex); | |
25149 | + break; | |
25150 | + } | |
25151 | + } | |
25152 | + } else { | |
076b876e | 25153 | + au_fclr_si(sbinfo, FHSM); |
c1595e42 JR |
25154 | + au_fhsm_set_bottom(sb, -1); |
25155 | + } | |
076b876e | 25156 | + |
1facf9fc | 25157 | + return err; |
25158 | +} | |
25159 | + | |
25160 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts) | |
25161 | +{ | |
25162 | + int err; | |
25163 | + unsigned int tmp; | |
5afbbe0d | 25164 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 25165 | + struct au_opt *opt; |
25166 | + struct au_opt_xino *opt_xino, xino; | |
25167 | + struct au_sbinfo *sbinfo; | |
027c5e7a | 25168 | + struct au_branch *br; |
076b876e | 25169 | + struct inode *dir; |
1facf9fc | 25170 | + |
dece6358 AM |
25171 | + SiMustWriteLock(sb); |
25172 | + | |
1facf9fc | 25173 | + err = 0; |
25174 | + opt_xino = NULL; | |
25175 | + opt = opts->opt; | |
25176 | + while (err >= 0 && opt->type != Opt_tail) | |
25177 | + err = au_opt_simple(sb, opt++, opts); | |
25178 | + if (err > 0) | |
25179 | + err = 0; | |
25180 | + else if (unlikely(err < 0)) | |
25181 | + goto out; | |
25182 | + | |
25183 | + /* disable xino and udba temporary */ | |
25184 | + sbinfo = au_sbi(sb); | |
25185 | + tmp = sbinfo->si_mntflags; | |
25186 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
25187 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL); | |
25188 | + | |
25189 | + opt = opts->opt; | |
25190 | + while (err >= 0 && opt->type != Opt_tail) | |
25191 | + err = au_opt_br(sb, opt++, opts); | |
25192 | + if (err > 0) | |
25193 | + err = 0; | |
25194 | + else if (unlikely(err < 0)) | |
25195 | + goto out; | |
25196 | + | |
5afbbe0d AM |
25197 | + bbot = au_sbbot(sb); |
25198 | + if (unlikely(bbot < 0)) { | |
1facf9fc | 25199 | + err = -EINVAL; |
4a4d8108 | 25200 | + pr_err("no branches\n"); |
1facf9fc | 25201 | + goto out; |
25202 | + } | |
25203 | + | |
25204 | + if (au_opt_test(tmp, XINO)) | |
25205 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
25206 | + opt = opts->opt; | |
25207 | + while (!err && opt->type != Opt_tail) | |
25208 | + err = au_opt_xino(sb, opt++, &opt_xino, opts); | |
25209 | + if (unlikely(err)) | |
25210 | + goto out; | |
25211 | + | |
25212 | + err = au_opts_verify(sb, sb->s_flags, tmp); | |
25213 | + if (unlikely(err)) | |
25214 | + goto out; | |
25215 | + | |
25216 | + /* restore xino */ | |
25217 | + if (au_opt_test(tmp, XINO) && !opt_xino) { | |
25218 | + xino.file = au_xino_def(sb); | |
25219 | + err = PTR_ERR(xino.file); | |
25220 | + if (IS_ERR(xino.file)) | |
25221 | + goto out; | |
25222 | + | |
25223 | + err = au_xino_set(sb, &xino, /*remount*/0); | |
25224 | + fput(xino.file); | |
25225 | + if (unlikely(err)) | |
25226 | + goto out; | |
25227 | + } | |
25228 | + | |
25229 | + /* restore udba */ | |
027c5e7a | 25230 | + tmp &= AuOptMask_UDBA; |
1facf9fc | 25231 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; |
027c5e7a | 25232 | + sbinfo->si_mntflags |= tmp; |
5afbbe0d AM |
25233 | + bbot = au_sbbot(sb); |
25234 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
027c5e7a AM |
25235 | + br = au_sbr(sb, bindex); |
25236 | + err = au_hnotify_reset_br(tmp, br, br->br_perm); | |
25237 | + if (unlikely(err)) | |
25238 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", | |
25239 | + bindex, err); | |
25240 | + /* go on even if err */ | |
25241 | + } | |
4a4d8108 | 25242 | + if (au_opt_test(tmp, UDBA_HNOTIFY)) { |
5527c038 | 25243 | + dir = d_inode(sb->s_root); |
4a4d8108 | 25244 | + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO); |
1facf9fc | 25245 | + } |
25246 | + | |
4f0767ce | 25247 | +out: |
1facf9fc | 25248 | + return err; |
25249 | +} | |
25250 | + | |
25251 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts) | |
25252 | +{ | |
25253 | + int err, rerr; | |
79b8bda9 | 25254 | + unsigned char no_dreval; |
1facf9fc | 25255 | + struct inode *dir; |
25256 | + struct au_opt_xino *opt_xino; | |
25257 | + struct au_opt *opt; | |
25258 | + struct au_sbinfo *sbinfo; | |
25259 | + | |
dece6358 AM |
25260 | + SiMustWriteLock(sb); |
25261 | + | |
79b8bda9 | 25262 | + err = 0; |
5527c038 | 25263 | + dir = d_inode(sb->s_root); |
1facf9fc | 25264 | + sbinfo = au_sbi(sb); |
1facf9fc | 25265 | + opt_xino = NULL; |
25266 | + opt = opts->opt; | |
25267 | + while (err >= 0 && opt->type != Opt_tail) { | |
25268 | + err = au_opt_simple(sb, opt, opts); | |
25269 | + if (!err) | |
25270 | + err = au_opt_br(sb, opt, opts); | |
25271 | + if (!err) | |
25272 | + err = au_opt_xino(sb, opt, &opt_xino, opts); | |
25273 | + opt++; | |
25274 | + } | |
25275 | + if (err > 0) | |
25276 | + err = 0; | |
25277 | + AuTraceErr(err); | |
25278 | + /* go on even err */ | |
25279 | + | |
79b8bda9 | 25280 | + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL); |
1facf9fc | 25281 | + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0); |
25282 | + if (unlikely(rerr && !err)) | |
25283 | + err = rerr; | |
25284 | + | |
79b8bda9 | 25285 | + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL)) |
b95c5147 | 25286 | + au_fset_opts(opts->flags, REFRESH_IDOP); |
79b8bda9 | 25287 | + |
1facf9fc | 25288 | + if (au_ftest_opts(opts->flags, TRUNC_XIB)) { |
25289 | + rerr = au_xib_trunc(sb); | |
25290 | + if (unlikely(rerr && !err)) | |
25291 | + err = rerr; | |
25292 | + } | |
25293 | + | |
25294 | + /* will be handled by the caller */ | |
027c5e7a | 25295 | + if (!au_ftest_opts(opts->flags, REFRESH) |
79b8bda9 AM |
25296 | + && (opts->given_udba |
25297 | + || au_opt_test(sbinfo->si_mntflags, XINO) | |
b95c5147 | 25298 | + || au_ftest_opts(opts->flags, REFRESH_IDOP) |
79b8bda9 | 25299 | + )) |
027c5e7a | 25300 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 25301 | + |
25302 | + AuDbg("status 0x%x\n", opts->flags); | |
25303 | + return err; | |
25304 | +} | |
25305 | + | |
25306 | +/* ---------------------------------------------------------------------- */ | |
25307 | + | |
25308 | +unsigned int au_opt_udba(struct super_block *sb) | |
25309 | +{ | |
25310 | + return au_mntflags(sb) & AuOptMask_UDBA; | |
25311 | +} | |
7f207e10 AM |
25312 | diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h |
25313 | --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 25314 | +++ linux/fs/aufs/opts.h 2017-05-06 22:16:52.781553511 +0200 |
f2c43d5f | 25315 | @@ -0,0 +1,213 @@ |
1facf9fc | 25316 | +/* |
a2654f78 | 25317 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 25318 | + * |
25319 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25320 | + * it under the terms of the GNU General Public License as published by | |
25321 | + * the Free Software Foundation; either version 2 of the License, or | |
25322 | + * (at your option) any later version. | |
dece6358 AM |
25323 | + * |
25324 | + * This program is distributed in the hope that it will be useful, | |
25325 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25326 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25327 | + * GNU General Public License for more details. | |
25328 | + * | |
25329 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25330 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25331 | + */ |
25332 | + | |
25333 | +/* | |
25334 | + * mount options/flags | |
25335 | + */ | |
25336 | + | |
25337 | +#ifndef __AUFS_OPTS_H__ | |
25338 | +#define __AUFS_OPTS_H__ | |
25339 | + | |
25340 | +#ifdef __KERNEL__ | |
25341 | + | |
dece6358 | 25342 | +#include <linux/path.h> |
1facf9fc | 25343 | + |
dece6358 AM |
25344 | +struct file; |
25345 | +struct super_block; | |
25346 | + | |
1facf9fc | 25347 | +/* ---------------------------------------------------------------------- */ |
25348 | + | |
25349 | +/* mount flags */ | |
25350 | +#define AuOpt_XINO 1 /* external inode number bitmap | |
25351 | + and translation table */ | |
25352 | +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */ | |
25353 | +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */ | |
25354 | +#define AuOpt_UDBA_REVAL (1 << 3) | |
4a4d8108 | 25355 | +#define AuOpt_UDBA_HNOTIFY (1 << 4) |
dece6358 AM |
25356 | +#define AuOpt_SHWH (1 << 5) /* show whiteout */ |
25357 | +#define AuOpt_PLINK (1 << 6) /* pseudo-link */ | |
076b876e AM |
25358 | +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm |
25359 | + bits */ | |
dece6358 AM |
25360 | +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */ |
25361 | +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */ | |
25362 | +#define AuOpt_SUM_W (1 << 11) /* unimplemented */ | |
25363 | +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */ | |
25364 | +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */ | |
4a4d8108 | 25365 | +#define AuOpt_DIO (1 << 14) /* direct io */ |
1facf9fc | 25366 | + |
4a4d8108 AM |
25367 | +#ifndef CONFIG_AUFS_HNOTIFY |
25368 | +#undef AuOpt_UDBA_HNOTIFY | |
25369 | +#define AuOpt_UDBA_HNOTIFY 0 | |
1facf9fc | 25370 | +#endif |
dece6358 AM |
25371 | +#ifndef CONFIG_AUFS_SHWH |
25372 | +#undef AuOpt_SHWH | |
25373 | +#define AuOpt_SHWH 0 | |
25374 | +#endif | |
1facf9fc | 25375 | + |
25376 | +#define AuOpt_Def (AuOpt_XINO \ | |
25377 | + | AuOpt_UDBA_REVAL \ | |
25378 | + | AuOpt_PLINK \ | |
25379 | + /* | AuOpt_DIRPERM1 */ \ | |
25380 | + | AuOpt_WARN_PERM) | |
25381 | +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \ | |
25382 | + | AuOpt_UDBA_REVAL \ | |
4a4d8108 | 25383 | + | AuOpt_UDBA_HNOTIFY) |
1facf9fc | 25384 | + |
25385 | +#define au_opt_test(flags, name) (flags & AuOpt_##name) | |
25386 | +#define au_opt_set(flags, name) do { \ | |
25387 | + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \ | |
25388 | + ((flags) |= AuOpt_##name); \ | |
25389 | +} while (0) | |
25390 | +#define au_opt_set_udba(flags, name) do { \ | |
25391 | + (flags) &= ~AuOptMask_UDBA; \ | |
25392 | + ((flags) |= AuOpt_##name); \ | |
25393 | +} while (0) | |
7f207e10 AM |
25394 | +#define au_opt_clr(flags, name) do { \ |
25395 | + ((flags) &= ~AuOpt_##name); \ | |
25396 | +} while (0) | |
1facf9fc | 25397 | + |
e49829fe JR |
25398 | +static inline unsigned int au_opts_plink(unsigned int mntflags) |
25399 | +{ | |
25400 | +#ifdef CONFIG_PROC_FS | |
25401 | + return mntflags; | |
25402 | +#else | |
25403 | + return mntflags & ~AuOpt_PLINK; | |
25404 | +#endif | |
25405 | +} | |
25406 | + | |
1facf9fc | 25407 | +/* ---------------------------------------------------------------------- */ |
25408 | + | |
25409 | +/* policies to select one among multiple writable branches */ | |
25410 | +enum { | |
25411 | + AuWbrCreate_TDP, /* top down parent */ | |
25412 | + AuWbrCreate_RR, /* round robin */ | |
25413 | + AuWbrCreate_MFS, /* most free space */ | |
25414 | + AuWbrCreate_MFSV, /* mfs with seconds */ | |
25415 | + AuWbrCreate_MFSRR, /* mfs then rr */ | |
25416 | + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */ | |
f2c43d5f AM |
25417 | + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */ |
25418 | + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */ | |
1facf9fc | 25419 | + AuWbrCreate_PMFS, /* parent and mfs */ |
25420 | + AuWbrCreate_PMFSV, /* parent and mfs with seconds */ | |
392086de AM |
25421 | + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */ |
25422 | + AuWbrCreate_PMFSRRV, /* plus seconds */ | |
1facf9fc | 25423 | + |
25424 | + AuWbrCreate_Def = AuWbrCreate_TDP | |
25425 | +}; | |
25426 | + | |
25427 | +enum { | |
25428 | + AuWbrCopyup_TDP, /* top down parent */ | |
25429 | + AuWbrCopyup_BUP, /* bottom up parent */ | |
25430 | + AuWbrCopyup_BU, /* bottom up */ | |
25431 | + | |
25432 | + AuWbrCopyup_Def = AuWbrCopyup_TDP | |
25433 | +}; | |
25434 | + | |
25435 | +/* ---------------------------------------------------------------------- */ | |
25436 | + | |
25437 | +struct au_opt_add { | |
25438 | + aufs_bindex_t bindex; | |
25439 | + char *pathname; | |
25440 | + int perm; | |
25441 | + struct path path; | |
25442 | +}; | |
25443 | + | |
25444 | +struct au_opt_del { | |
25445 | + char *pathname; | |
25446 | + struct path h_path; | |
25447 | +}; | |
25448 | + | |
25449 | +struct au_opt_mod { | |
25450 | + char *path; | |
25451 | + int perm; | |
25452 | + struct dentry *h_root; | |
25453 | +}; | |
25454 | + | |
25455 | +struct au_opt_xino { | |
25456 | + char *path; | |
25457 | + struct file *file; | |
25458 | +}; | |
25459 | + | |
25460 | +struct au_opt_xino_itrunc { | |
25461 | + aufs_bindex_t bindex; | |
25462 | +}; | |
25463 | + | |
25464 | +struct au_opt_wbr_create { | |
25465 | + int wbr_create; | |
25466 | + int mfs_second; | |
25467 | + unsigned long long mfsrr_watermark; | |
25468 | +}; | |
25469 | + | |
25470 | +struct au_opt { | |
25471 | + int type; | |
25472 | + union { | |
25473 | + struct au_opt_xino xino; | |
25474 | + struct au_opt_xino_itrunc xino_itrunc; | |
25475 | + struct au_opt_add add; | |
25476 | + struct au_opt_del del; | |
25477 | + struct au_opt_mod mod; | |
25478 | + int dirwh; | |
25479 | + int rdcache; | |
25480 | + unsigned int rdblk; | |
25481 | + unsigned int rdhash; | |
25482 | + int udba; | |
25483 | + struct au_opt_wbr_create wbr_create; | |
25484 | + int wbr_copyup; | |
076b876e | 25485 | + unsigned int fhsm_second; |
1facf9fc | 25486 | + }; |
25487 | +}; | |
25488 | + | |
25489 | +/* opts flags */ | |
25490 | +#define AuOpts_REMOUNT 1 | |
027c5e7a AM |
25491 | +#define AuOpts_REFRESH (1 << 1) |
25492 | +#define AuOpts_TRUNC_XIB (1 << 2) | |
25493 | +#define AuOpts_REFRESH_DYAOP (1 << 3) | |
b95c5147 | 25494 | +#define AuOpts_REFRESH_IDOP (1 << 4) |
1facf9fc | 25495 | +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name) |
7f207e10 AM |
25496 | +#define au_fset_opts(flags, name) \ |
25497 | + do { (flags) |= AuOpts_##name; } while (0) | |
25498 | +#define au_fclr_opts(flags, name) \ | |
25499 | + do { (flags) &= ~AuOpts_##name; } while (0) | |
1facf9fc | 25500 | + |
25501 | +struct au_opts { | |
25502 | + struct au_opt *opt; | |
25503 | + int max_opt; | |
25504 | + | |
25505 | + unsigned int given_udba; | |
25506 | + unsigned int flags; | |
25507 | + unsigned long sb_flags; | |
25508 | +}; | |
25509 | + | |
25510 | +/* ---------------------------------------------------------------------- */ | |
25511 | + | |
7e9cd9fe | 25512 | +/* opts.c */ |
076b876e | 25513 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm); |
1facf9fc | 25514 | +const char *au_optstr_udba(int udba); |
25515 | +const char *au_optstr_wbr_copyup(int wbr_copyup); | |
25516 | +const char *au_optstr_wbr_create(int wbr_create); | |
25517 | + | |
25518 | +void au_opts_free(struct au_opts *opts); | |
25519 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts); | |
25520 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
25521 | + unsigned int pending); | |
25522 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts); | |
25523 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts); | |
25524 | + | |
25525 | +unsigned int au_opt_udba(struct super_block *sb); | |
25526 | + | |
1facf9fc | 25527 | +#endif /* __KERNEL__ */ |
25528 | +#endif /* __AUFS_OPTS_H__ */ | |
7f207e10 AM |
25529 | diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c |
25530 | --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 25531 | +++ linux/fs/aufs/plink.c 2017-05-06 22:16:52.781553511 +0200 |
f0c0a007 | 25532 | @@ -0,0 +1,514 @@ |
1facf9fc | 25533 | +/* |
a2654f78 | 25534 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 25535 | + * |
25536 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25537 | + * it under the terms of the GNU General Public License as published by | |
25538 | + * the Free Software Foundation; either version 2 of the License, or | |
25539 | + * (at your option) any later version. | |
dece6358 AM |
25540 | + * |
25541 | + * This program is distributed in the hope that it will be useful, | |
25542 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25543 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25544 | + * GNU General Public License for more details. | |
25545 | + * | |
25546 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25547 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25548 | + */ |
25549 | + | |
25550 | +/* | |
25551 | + * pseudo-link | |
25552 | + */ | |
25553 | + | |
25554 | +#include "aufs.h" | |
25555 | + | |
25556 | +/* | |
e49829fe | 25557 | + * the pseudo-link maintenance mode. |
1facf9fc | 25558 | + * during a user process maintains the pseudo-links, |
25559 | + * prohibit adding a new plink and branch manipulation. | |
e49829fe JR |
25560 | + * |
25561 | + * Flags | |
25562 | + * NOPLM: | |
25563 | + * For entry functions which will handle plink, and i_mutex is already held | |
25564 | + * in VFS. | |
25565 | + * They cannot wait and should return an error at once. | |
25566 | + * Callers has to check the error. | |
25567 | + * NOPLMW: | |
25568 | + * For entry functions which will handle plink, but i_mutex is not held | |
25569 | + * in VFS. | |
25570 | + * They can wait the plink maintenance mode to finish. | |
25571 | + * | |
25572 | + * They behave like F_SETLK and F_SETLKW. | |
25573 | + * If the caller never handle plink, then both flags are unnecessary. | |
1facf9fc | 25574 | + */ |
e49829fe JR |
25575 | + |
25576 | +int au_plink_maint(struct super_block *sb, int flags) | |
1facf9fc | 25577 | +{ |
e49829fe JR |
25578 | + int err; |
25579 | + pid_t pid, ppid; | |
f0c0a007 | 25580 | + struct task_struct *parent, *prev; |
e49829fe | 25581 | + struct au_sbinfo *sbi; |
dece6358 AM |
25582 | + |
25583 | + SiMustAnyLock(sb); | |
25584 | + | |
e49829fe JR |
25585 | + err = 0; |
25586 | + if (!au_opt_test(au_mntflags(sb), PLINK)) | |
25587 | + goto out; | |
25588 | + | |
25589 | + sbi = au_sbi(sb); | |
25590 | + pid = sbi->si_plink_maint_pid; | |
25591 | + if (!pid || pid == current->pid) | |
25592 | + goto out; | |
25593 | + | |
25594 | + /* todo: it highly depends upon /sbin/mount.aufs */ | |
f0c0a007 AM |
25595 | + prev = NULL; |
25596 | + parent = current; | |
25597 | + ppid = 0; | |
e49829fe | 25598 | + rcu_read_lock(); |
f0c0a007 AM |
25599 | + while (1) { |
25600 | + parent = rcu_dereference(parent->real_parent); | |
25601 | + if (parent == prev) | |
25602 | + break; | |
25603 | + ppid = task_pid_vnr(parent); | |
25604 | + if (pid == ppid) { | |
25605 | + rcu_read_unlock(); | |
25606 | + goto out; | |
25607 | + } | |
25608 | + prev = parent; | |
25609 | + } | |
e49829fe | 25610 | + rcu_read_unlock(); |
e49829fe JR |
25611 | + |
25612 | + if (au_ftest_lock(flags, NOPLMW)) { | |
027c5e7a AM |
25613 | + /* if there is no i_mutex lock in VFS, we don't need to wait */ |
25614 | + /* AuDebugOn(!lockdep_depth(current)); */ | |
e49829fe JR |
25615 | + while (sbi->si_plink_maint_pid) { |
25616 | + si_read_unlock(sb); | |
25617 | + /* gave up wake_up_bit() */ | |
25618 | + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid); | |
25619 | + | |
25620 | + if (au_ftest_lock(flags, FLUSH)) | |
25621 | + au_nwt_flush(&sbi->si_nowait); | |
25622 | + si_noflush_read_lock(sb); | |
25623 | + } | |
25624 | + } else if (au_ftest_lock(flags, NOPLM)) { | |
25625 | + AuDbg("ppid %d, pid %d\n", ppid, pid); | |
25626 | + err = -EAGAIN; | |
25627 | + } | |
25628 | + | |
25629 | +out: | |
25630 | + return err; | |
4a4d8108 AM |
25631 | +} |
25632 | + | |
e49829fe | 25633 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo) |
4a4d8108 | 25634 | +{ |
4a4d8108 | 25635 | + spin_lock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 25636 | + sbinfo->si_plink_maint_pid = 0; |
4a4d8108 | 25637 | + spin_unlock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 25638 | + wake_up_all(&sbinfo->si_plink_wq); |
4a4d8108 AM |
25639 | +} |
25640 | + | |
e49829fe | 25641 | +int au_plink_maint_enter(struct super_block *sb) |
4a4d8108 AM |
25642 | +{ |
25643 | + int err; | |
4a4d8108 AM |
25644 | + struct au_sbinfo *sbinfo; |
25645 | + | |
25646 | + err = 0; | |
4a4d8108 AM |
25647 | + sbinfo = au_sbi(sb); |
25648 | + /* make sure i am the only one in this fs */ | |
e49829fe JR |
25649 | + si_write_lock(sb, AuLock_FLUSH); |
25650 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
25651 | + spin_lock(&sbinfo->si_plink_maint_lock); | |
25652 | + if (!sbinfo->si_plink_maint_pid) | |
25653 | + sbinfo->si_plink_maint_pid = current->pid; | |
25654 | + else | |
25655 | + err = -EBUSY; | |
25656 | + spin_unlock(&sbinfo->si_plink_maint_lock); | |
25657 | + } | |
4a4d8108 AM |
25658 | + si_write_unlock(sb); |
25659 | + | |
25660 | + return err; | |
1facf9fc | 25661 | +} |
25662 | + | |
25663 | +/* ---------------------------------------------------------------------- */ | |
25664 | + | |
1facf9fc | 25665 | +#ifdef CONFIG_AUFS_DEBUG |
25666 | +void au_plink_list(struct super_block *sb) | |
25667 | +{ | |
86dc4139 | 25668 | + int i; |
1facf9fc | 25669 | + struct au_sbinfo *sbinfo; |
86dc4139 | 25670 | + struct hlist_head *plink_hlist; |
5afbbe0d | 25671 | + struct au_icntnr *icntnr; |
1facf9fc | 25672 | + |
dece6358 AM |
25673 | + SiMustAnyLock(sb); |
25674 | + | |
1facf9fc | 25675 | + sbinfo = au_sbi(sb); |
25676 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25677 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25678 | + |
86dc4139 AM |
25679 | + for (i = 0; i < AuPlink_NHASH; i++) { |
25680 | + plink_hlist = &sbinfo->si_plink[i].head; | |
25681 | + rcu_read_lock(); | |
5afbbe0d AM |
25682 | + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink) |
25683 | + AuDbg("%lu\n", icntnr->vfs_inode.i_ino); | |
86dc4139 AM |
25684 | + rcu_read_unlock(); |
25685 | + } | |
1facf9fc | 25686 | +} |
25687 | +#endif | |
25688 | + | |
25689 | +/* is the inode pseudo-linked? */ | |
25690 | +int au_plink_test(struct inode *inode) | |
25691 | +{ | |
86dc4139 | 25692 | + int found, i; |
1facf9fc | 25693 | + struct au_sbinfo *sbinfo; |
86dc4139 | 25694 | + struct hlist_head *plink_hlist; |
5afbbe0d | 25695 | + struct au_icntnr *icntnr; |
1facf9fc | 25696 | + |
25697 | + sbinfo = au_sbi(inode->i_sb); | |
dece6358 | 25698 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
1facf9fc | 25699 | + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK)); |
e49829fe | 25700 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
1facf9fc | 25701 | + |
25702 | + found = 0; | |
86dc4139 AM |
25703 | + i = au_plink_hash(inode->i_ino); |
25704 | + plink_hlist = &sbinfo->si_plink[i].head; | |
4a4d8108 | 25705 | + rcu_read_lock(); |
5afbbe0d AM |
25706 | + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink) |
25707 | + if (&icntnr->vfs_inode == inode) { | |
1facf9fc | 25708 | + found = 1; |
25709 | + break; | |
25710 | + } | |
4a4d8108 | 25711 | + rcu_read_unlock(); |
1facf9fc | 25712 | + return found; |
25713 | +} | |
25714 | + | |
25715 | +/* ---------------------------------------------------------------------- */ | |
25716 | + | |
25717 | +/* | |
25718 | + * generate a name for plink. | |
25719 | + * the file will be stored under AUFS_WH_PLINKDIR. | |
25720 | + */ | |
25721 | +/* 20 is max digits length of ulong 64 */ | |
25722 | +#define PLINK_NAME_LEN ((20 + 1) * 2) | |
25723 | + | |
25724 | +static int plink_name(char *name, int len, struct inode *inode, | |
25725 | + aufs_bindex_t bindex) | |
25726 | +{ | |
25727 | + int rlen; | |
25728 | + struct inode *h_inode; | |
25729 | + | |
25730 | + h_inode = au_h_iptr(inode, bindex); | |
25731 | + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino); | |
25732 | + return rlen; | |
25733 | +} | |
25734 | + | |
7f207e10 AM |
25735 | +struct au_do_plink_lkup_args { |
25736 | + struct dentry **errp; | |
25737 | + struct qstr *tgtname; | |
25738 | + struct dentry *h_parent; | |
25739 | + struct au_branch *br; | |
25740 | +}; | |
25741 | + | |
25742 | +static struct dentry *au_do_plink_lkup(struct qstr *tgtname, | |
25743 | + struct dentry *h_parent, | |
25744 | + struct au_branch *br) | |
25745 | +{ | |
25746 | + struct dentry *h_dentry; | |
febd17d6 | 25747 | + struct inode *h_inode; |
7f207e10 | 25748 | + |
febd17d6 JR |
25749 | + h_inode = d_inode(h_parent); |
25750 | + inode_lock_nested(h_inode, AuLsc_I_CHILD2); | |
b4510431 | 25751 | + h_dentry = vfsub_lkup_one(tgtname, h_parent); |
febd17d6 | 25752 | + inode_unlock(h_inode); |
7f207e10 AM |
25753 | + return h_dentry; |
25754 | +} | |
25755 | + | |
25756 | +static void au_call_do_plink_lkup(void *args) | |
25757 | +{ | |
25758 | + struct au_do_plink_lkup_args *a = args; | |
25759 | + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br); | |
25760 | +} | |
25761 | + | |
1facf9fc | 25762 | +/* lookup the plink-ed @inode under the branch at @bindex */ |
25763 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex) | |
25764 | +{ | |
25765 | + struct dentry *h_dentry, *h_parent; | |
25766 | + struct au_branch *br; | |
7f207e10 | 25767 | + int wkq_err; |
1facf9fc | 25768 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 25769 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 25770 | + |
e49829fe JR |
25771 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
25772 | + | |
1facf9fc | 25773 | + br = au_sbr(inode->i_sb, bindex); |
25774 | + h_parent = br->br_wbr->wbr_plink; | |
1facf9fc | 25775 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
25776 | + | |
2dfbb274 | 25777 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
7f207e10 AM |
25778 | + struct au_do_plink_lkup_args args = { |
25779 | + .errp = &h_dentry, | |
25780 | + .tgtname = &tgtname, | |
25781 | + .h_parent = h_parent, | |
25782 | + .br = br | |
25783 | + }; | |
25784 | + | |
25785 | + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args); | |
25786 | + if (unlikely(wkq_err)) | |
25787 | + h_dentry = ERR_PTR(wkq_err); | |
25788 | + } else | |
25789 | + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br); | |
25790 | + | |
1facf9fc | 25791 | + return h_dentry; |
25792 | +} | |
25793 | + | |
25794 | +/* create a pseudo-link */ | |
25795 | +static int do_whplink(struct qstr *tgt, struct dentry *h_parent, | |
25796 | + struct dentry *h_dentry, struct au_branch *br) | |
25797 | +{ | |
25798 | + int err; | |
25799 | + struct path h_path = { | |
86dc4139 | 25800 | + .mnt = au_br_mnt(br) |
1facf9fc | 25801 | + }; |
523b37e3 | 25802 | + struct inode *h_dir, *delegated; |
1facf9fc | 25803 | + |
5527c038 | 25804 | + h_dir = d_inode(h_parent); |
febd17d6 | 25805 | + inode_lock_nested(h_dir, AuLsc_I_CHILD2); |
4f0767ce | 25806 | +again: |
b4510431 | 25807 | + h_path.dentry = vfsub_lkup_one(tgt, h_parent); |
1facf9fc | 25808 | + err = PTR_ERR(h_path.dentry); |
25809 | + if (IS_ERR(h_path.dentry)) | |
25810 | + goto out; | |
25811 | + | |
25812 | + err = 0; | |
25813 | + /* wh.plink dir is not monitored */ | |
7f207e10 | 25814 | + /* todo: is it really safe? */ |
5527c038 JR |
25815 | + if (d_is_positive(h_path.dentry) |
25816 | + && d_inode(h_path.dentry) != d_inode(h_dentry)) { | |
523b37e3 AM |
25817 | + delegated = NULL; |
25818 | + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0); | |
25819 | + if (unlikely(err == -EWOULDBLOCK)) { | |
25820 | + pr_warn("cannot retry for NFSv4 delegation" | |
25821 | + " for an internal unlink\n"); | |
25822 | + iput(delegated); | |
25823 | + } | |
1facf9fc | 25824 | + dput(h_path.dentry); |
25825 | + h_path.dentry = NULL; | |
25826 | + if (!err) | |
25827 | + goto again; | |
25828 | + } | |
5527c038 | 25829 | + if (!err && d_is_negative(h_path.dentry)) { |
523b37e3 AM |
25830 | + delegated = NULL; |
25831 | + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated); | |
25832 | + if (unlikely(err == -EWOULDBLOCK)) { | |
25833 | + pr_warn("cannot retry for NFSv4 delegation" | |
25834 | + " for an internal link\n"); | |
25835 | + iput(delegated); | |
25836 | + } | |
25837 | + } | |
1facf9fc | 25838 | + dput(h_path.dentry); |
25839 | + | |
4f0767ce | 25840 | +out: |
febd17d6 | 25841 | + inode_unlock(h_dir); |
1facf9fc | 25842 | + return err; |
25843 | +} | |
25844 | + | |
25845 | +struct do_whplink_args { | |
25846 | + int *errp; | |
25847 | + struct qstr *tgt; | |
25848 | + struct dentry *h_parent; | |
25849 | + struct dentry *h_dentry; | |
25850 | + struct au_branch *br; | |
25851 | +}; | |
25852 | + | |
25853 | +static void call_do_whplink(void *args) | |
25854 | +{ | |
25855 | + struct do_whplink_args *a = args; | |
25856 | + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br); | |
25857 | +} | |
25858 | + | |
25859 | +static int whplink(struct dentry *h_dentry, struct inode *inode, | |
25860 | + aufs_bindex_t bindex, struct au_branch *br) | |
25861 | +{ | |
25862 | + int err, wkq_err; | |
25863 | + struct au_wbr *wbr; | |
25864 | + struct dentry *h_parent; | |
1facf9fc | 25865 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 25866 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 25867 | + |
25868 | + wbr = au_sbr(inode->i_sb, bindex)->br_wbr; | |
25869 | + h_parent = wbr->wbr_plink; | |
1facf9fc | 25870 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
25871 | + | |
25872 | + /* always superio. */ | |
2dfbb274 | 25873 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
1facf9fc | 25874 | + struct do_whplink_args args = { |
25875 | + .errp = &err, | |
25876 | + .tgt = &tgtname, | |
25877 | + .h_parent = h_parent, | |
25878 | + .h_dentry = h_dentry, | |
25879 | + .br = br | |
25880 | + }; | |
25881 | + wkq_err = au_wkq_wait(call_do_whplink, &args); | |
25882 | + if (unlikely(wkq_err)) | |
25883 | + err = wkq_err; | |
25884 | + } else | |
25885 | + err = do_whplink(&tgtname, h_parent, h_dentry, br); | |
1facf9fc | 25886 | + |
25887 | + return err; | |
25888 | +} | |
25889 | + | |
1facf9fc | 25890 | +/* |
25891 | + * create a new pseudo-link for @h_dentry on @bindex. | |
25892 | + * the linked inode is held in aufs @inode. | |
25893 | + */ | |
25894 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
25895 | + struct dentry *h_dentry) | |
25896 | +{ | |
25897 | + struct super_block *sb; | |
25898 | + struct au_sbinfo *sbinfo; | |
86dc4139 | 25899 | + struct hlist_head *plink_hlist; |
5afbbe0d | 25900 | + struct au_icntnr *icntnr; |
86dc4139 AM |
25901 | + struct au_sphlhead *sphl; |
25902 | + int found, err, cnt, i; | |
1facf9fc | 25903 | + |
25904 | + sb = inode->i_sb; | |
25905 | + sbinfo = au_sbi(sb); | |
25906 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25907 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25908 | + |
86dc4139 | 25909 | + found = au_plink_test(inode); |
4a4d8108 | 25910 | + if (found) |
1facf9fc | 25911 | + return; |
4a4d8108 | 25912 | + |
86dc4139 AM |
25913 | + i = au_plink_hash(inode->i_ino); |
25914 | + sphl = sbinfo->si_plink + i; | |
25915 | + plink_hlist = &sphl->head; | |
5afbbe0d | 25916 | + au_igrab(inode); |
1facf9fc | 25917 | + |
86dc4139 | 25918 | + spin_lock(&sphl->spin); |
5afbbe0d AM |
25919 | + hlist_for_each_entry(icntnr, plink_hlist, plink) { |
25920 | + if (&icntnr->vfs_inode == inode) { | |
4a4d8108 AM |
25921 | + found = 1; |
25922 | + break; | |
25923 | + } | |
1facf9fc | 25924 | + } |
5afbbe0d AM |
25925 | + if (!found) { |
25926 | + icntnr = container_of(inode, struct au_icntnr, vfs_inode); | |
25927 | + hlist_add_head_rcu(&icntnr->plink, plink_hlist); | |
25928 | + } | |
86dc4139 | 25929 | + spin_unlock(&sphl->spin); |
4a4d8108 | 25930 | + if (!found) { |
86dc4139 AM |
25931 | + cnt = au_sphl_count(sphl); |
25932 | +#define msg "unexpectedly unblanced or too many pseudo-links" | |
25933 | + if (cnt > AUFS_PLINK_WARN) | |
25934 | + AuWarn1(msg ", %d\n", cnt); | |
25935 | +#undef msg | |
1facf9fc | 25936 | + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex)); |
5afbbe0d AM |
25937 | + if (unlikely(err)) { |
25938 | + pr_warn("err %d, damaged pseudo link.\n", err); | |
25939 | + au_sphl_del_rcu(&icntnr->plink, sphl); | |
25940 | + iput(&icntnr->vfs_inode); | |
4a4d8108 | 25941 | + } |
5afbbe0d AM |
25942 | + } else |
25943 | + iput(&icntnr->vfs_inode); | |
1facf9fc | 25944 | +} |
25945 | + | |
25946 | +/* free all plinks */ | |
e49829fe | 25947 | +void au_plink_put(struct super_block *sb, int verbose) |
1facf9fc | 25948 | +{ |
86dc4139 | 25949 | + int i, warned; |
1facf9fc | 25950 | + struct au_sbinfo *sbinfo; |
86dc4139 AM |
25951 | + struct hlist_head *plink_hlist; |
25952 | + struct hlist_node *tmp; | |
5afbbe0d | 25953 | + struct au_icntnr *icntnr; |
1facf9fc | 25954 | + |
dece6358 AM |
25955 | + SiMustWriteLock(sb); |
25956 | + | |
1facf9fc | 25957 | + sbinfo = au_sbi(sb); |
25958 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25959 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25960 | + |
1facf9fc | 25961 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
25962 | + warned = 0; |
25963 | + for (i = 0; i < AuPlink_NHASH; i++) { | |
25964 | + plink_hlist = &sbinfo->si_plink[i].head; | |
25965 | + if (!warned && verbose && !hlist_empty(plink_hlist)) { | |
25966 | + pr_warn("pseudo-link is not flushed"); | |
25967 | + warned = 1; | |
25968 | + } | |
5afbbe0d AM |
25969 | + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) |
25970 | + iput(&icntnr->vfs_inode); | |
86dc4139 AM |
25971 | + INIT_HLIST_HEAD(plink_hlist); |
25972 | + } | |
1facf9fc | 25973 | +} |
25974 | + | |
e49829fe JR |
25975 | +void au_plink_clean(struct super_block *sb, int verbose) |
25976 | +{ | |
25977 | + struct dentry *root; | |
25978 | + | |
25979 | + root = sb->s_root; | |
25980 | + aufs_write_lock(root); | |
25981 | + if (au_opt_test(au_mntflags(sb), PLINK)) | |
25982 | + au_plink_put(sb, verbose); | |
25983 | + aufs_write_unlock(root); | |
25984 | +} | |
25985 | + | |
86dc4139 AM |
25986 | +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id) |
25987 | +{ | |
25988 | + int do_put; | |
5afbbe0d | 25989 | + aufs_bindex_t btop, bbot, bindex; |
86dc4139 AM |
25990 | + |
25991 | + do_put = 0; | |
5afbbe0d AM |
25992 | + btop = au_ibtop(inode); |
25993 | + bbot = au_ibbot(inode); | |
25994 | + if (btop >= 0) { | |
25995 | + for (bindex = btop; bindex <= bbot; bindex++) { | |
86dc4139 AM |
25996 | + if (!au_h_iptr(inode, bindex) |
25997 | + || au_ii_br_id(inode, bindex) != br_id) | |
25998 | + continue; | |
25999 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
26000 | + do_put = 1; | |
26001 | + break; | |
26002 | + } | |
26003 | + if (do_put) | |
5afbbe0d | 26004 | + for (bindex = btop; bindex <= bbot; bindex++) |
86dc4139 AM |
26005 | + if (au_h_iptr(inode, bindex)) { |
26006 | + do_put = 0; | |
26007 | + break; | |
26008 | + } | |
26009 | + } else | |
26010 | + do_put = 1; | |
26011 | + | |
26012 | + return do_put; | |
26013 | +} | |
26014 | + | |
1facf9fc | 26015 | +/* free the plinks on a branch specified by @br_id */ |
26016 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id) | |
26017 | +{ | |
26018 | + struct au_sbinfo *sbinfo; | |
86dc4139 AM |
26019 | + struct hlist_head *plink_hlist; |
26020 | + struct hlist_node *tmp; | |
5afbbe0d | 26021 | + struct au_icntnr *icntnr; |
1facf9fc | 26022 | + struct inode *inode; |
86dc4139 | 26023 | + int i, do_put; |
1facf9fc | 26024 | + |
dece6358 AM |
26025 | + SiMustWriteLock(sb); |
26026 | + | |
1facf9fc | 26027 | + sbinfo = au_sbi(sb); |
26028 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 26029 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 26030 | + |
1facf9fc | 26031 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
26032 | + for (i = 0; i < AuPlink_NHASH; i++) { |
26033 | + plink_hlist = &sbinfo->si_plink[i].head; | |
5afbbe0d AM |
26034 | + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) { |
26035 | + inode = au_igrab(&icntnr->vfs_inode); | |
86dc4139 AM |
26036 | + ii_write_lock_child(inode); |
26037 | + do_put = au_plink_do_half_refresh(inode, br_id); | |
5afbbe0d AM |
26038 | + if (do_put) { |
26039 | + hlist_del(&icntnr->plink); | |
26040 | + iput(inode); | |
26041 | + } | |
86dc4139 AM |
26042 | + ii_write_unlock(inode); |
26043 | + iput(inode); | |
dece6358 | 26044 | + } |
dece6358 AM |
26045 | + } |
26046 | +} | |
7f207e10 AM |
26047 | diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c |
26048 | --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 26049 | +++ linux/fs/aufs/poll.c 2017-05-06 22:16:52.781553511 +0200 |
b912730e | 26050 | @@ -0,0 +1,52 @@ |
dece6358 | 26051 | +/* |
a2654f78 | 26052 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
dece6358 AM |
26053 | + * |
26054 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26055 | + * it under the terms of the GNU General Public License as published by | |
26056 | + * the Free Software Foundation; either version 2 of the License, or | |
26057 | + * (at your option) any later version. | |
26058 | + * | |
26059 | + * This program is distributed in the hope that it will be useful, | |
26060 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26061 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26062 | + * GNU General Public License for more details. | |
26063 | + * | |
26064 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26065 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 AM |
26066 | + */ |
26067 | + | |
1308ab2a | 26068 | +/* |
26069 | + * poll operation | |
26070 | + * There is only one filesystem which implements ->poll operation, currently. | |
26071 | + */ | |
26072 | + | |
26073 | +#include "aufs.h" | |
26074 | + | |
26075 | +unsigned int aufs_poll(struct file *file, poll_table *wait) | |
26076 | +{ | |
26077 | + unsigned int mask; | |
26078 | + int err; | |
26079 | + struct file *h_file; | |
1308ab2a | 26080 | + struct super_block *sb; |
26081 | + | |
26082 | + /* We should pretend an error happened. */ | |
26083 | + mask = POLLERR /* | POLLIN | POLLOUT */; | |
b912730e | 26084 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 26085 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 26086 | + |
521ced18 | 26087 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
26088 | + err = PTR_ERR(h_file); |
26089 | + if (IS_ERR(h_file)) | |
1308ab2a | 26090 | + goto out; |
26091 | + | |
26092 | + /* it is not an error if h_file has no operation */ | |
26093 | + mask = DEFAULT_POLLMASK; | |
523b37e3 | 26094 | + if (h_file->f_op->poll) |
1308ab2a | 26095 | + mask = h_file->f_op->poll(h_file, wait); |
b912730e | 26096 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 26097 | + |
4f0767ce | 26098 | +out: |
1308ab2a | 26099 | + si_read_unlock(sb); |
26100 | + AuTraceErr((int)mask); | |
26101 | + return mask; | |
26102 | +} | |
c1595e42 JR |
26103 | diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c |
26104 | --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 26105 | +++ linux/fs/aufs/posix_acl.c 2017-05-06 22:16:52.781553511 +0200 |
a2654f78 | 26106 | @@ -0,0 +1,102 @@ |
c1595e42 | 26107 | +/* |
a2654f78 | 26108 | + * Copyright (C) 2014-2017 Junjiro R. Okajima |
c1595e42 JR |
26109 | + * |
26110 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26111 | + * it under the terms of the GNU General Public License as published by | |
26112 | + * the Free Software Foundation; either version 2 of the License, or | |
26113 | + * (at your option) any later version. | |
26114 | + * | |
26115 | + * This program is distributed in the hope that it will be useful, | |
26116 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26117 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26118 | + * GNU General Public License for more details. | |
26119 | + * | |
26120 | + * You should have received a copy of the GNU General Public License | |
26121 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
26122 | + */ | |
26123 | + | |
26124 | +/* | |
26125 | + * posix acl operations | |
26126 | + */ | |
26127 | + | |
26128 | +#include <linux/fs.h> | |
c1595e42 JR |
26129 | +#include "aufs.h" |
26130 | + | |
26131 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type) | |
26132 | +{ | |
26133 | + struct posix_acl *acl; | |
26134 | + int err; | |
26135 | + aufs_bindex_t bindex; | |
26136 | + struct inode *h_inode; | |
26137 | + struct super_block *sb; | |
26138 | + | |
26139 | + acl = NULL; | |
26140 | + sb = inode->i_sb; | |
26141 | + si_read_lock(sb, AuLock_FLUSH); | |
26142 | + ii_read_lock_child(inode); | |
26143 | + if (!(sb->s_flags & MS_POSIXACL)) | |
26144 | + goto out; | |
26145 | + | |
5afbbe0d | 26146 | + bindex = au_ibtop(inode); |
c1595e42 JR |
26147 | + h_inode = au_h_iptr(inode, bindex); |
26148 | + if (unlikely(!h_inode | |
26149 | + || ((h_inode->i_mode & S_IFMT) | |
26150 | + != (inode->i_mode & S_IFMT)))) { | |
26151 | + err = au_busy_or_stale(); | |
26152 | + acl = ERR_PTR(err); | |
26153 | + goto out; | |
26154 | + } | |
26155 | + | |
26156 | + /* always topmost only */ | |
26157 | + acl = get_acl(h_inode, type); | |
a2654f78 AM |
26158 | + if (!IS_ERR_OR_NULL(acl)) |
26159 | + set_cached_acl(inode, type, acl); | |
c1595e42 JR |
26160 | + |
26161 | +out: | |
26162 | + ii_read_unlock(inode); | |
26163 | + si_read_unlock(sb); | |
26164 | + | |
26165 | + AuTraceErrPtr(acl); | |
26166 | + return acl; | |
26167 | +} | |
26168 | + | |
26169 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |
26170 | +{ | |
26171 | + int err; | |
26172 | + ssize_t ssz; | |
26173 | + struct dentry *dentry; | |
f2c43d5f | 26174 | + struct au_sxattr arg = { |
c1595e42 JR |
26175 | + .type = AU_ACL_SET, |
26176 | + .u.acl_set = { | |
26177 | + .acl = acl, | |
26178 | + .type = type | |
26179 | + }, | |
26180 | + }; | |
26181 | + | |
5afbbe0d AM |
26182 | + IMustLock(inode); |
26183 | + | |
c1595e42 JR |
26184 | + if (inode->i_ino == AUFS_ROOT_INO) |
26185 | + dentry = dget(inode->i_sb->s_root); | |
26186 | + else { | |
26187 | + dentry = d_find_alias(inode); | |
26188 | + if (!dentry) | |
26189 | + dentry = d_find_any_alias(inode); | |
26190 | + if (!dentry) { | |
26191 | + pr_warn("cannot handle this inode, " | |
26192 | + "please report to aufs-users ML\n"); | |
26193 | + err = -ENOENT; | |
26194 | + goto out; | |
26195 | + } | |
26196 | + } | |
26197 | + | |
f2c43d5f | 26198 | + ssz = au_sxattr(dentry, inode, &arg); |
c1595e42 JR |
26199 | + dput(dentry); |
26200 | + err = ssz; | |
a2654f78 | 26201 | + if (ssz >= 0) { |
c1595e42 | 26202 | + err = 0; |
a2654f78 AM |
26203 | + set_cached_acl(inode, type, acl); |
26204 | + } | |
c1595e42 JR |
26205 | + |
26206 | +out: | |
c1595e42 JR |
26207 | + return err; |
26208 | +} | |
7f207e10 AM |
26209 | diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c |
26210 | --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 26211 | +++ linux/fs/aufs/procfs.c 2017-05-06 22:16:52.781553511 +0200 |
523b37e3 | 26212 | @@ -0,0 +1,169 @@ |
e49829fe | 26213 | +/* |
a2654f78 | 26214 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
e49829fe JR |
26215 | + * |
26216 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26217 | + * it under the terms of the GNU General Public License as published by | |
26218 | + * the Free Software Foundation; either version 2 of the License, or | |
26219 | + * (at your option) any later version. | |
26220 | + * | |
26221 | + * This program is distributed in the hope that it will be useful, | |
26222 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26223 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26224 | + * GNU General Public License for more details. | |
26225 | + * | |
26226 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26227 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
26228 | + */ |
26229 | + | |
26230 | +/* | |
26231 | + * procfs interfaces | |
26232 | + */ | |
26233 | + | |
26234 | +#include <linux/proc_fs.h> | |
26235 | +#include "aufs.h" | |
26236 | + | |
26237 | +static int au_procfs_plm_release(struct inode *inode, struct file *file) | |
26238 | +{ | |
26239 | + struct au_sbinfo *sbinfo; | |
26240 | + | |
26241 | + sbinfo = file->private_data; | |
26242 | + if (sbinfo) { | |
26243 | + au_plink_maint_leave(sbinfo); | |
26244 | + kobject_put(&sbinfo->si_kobj); | |
26245 | + } | |
26246 | + | |
26247 | + return 0; | |
26248 | +} | |
26249 | + | |
26250 | +static void au_procfs_plm_write_clean(struct file *file) | |
26251 | +{ | |
26252 | + struct au_sbinfo *sbinfo; | |
26253 | + | |
26254 | + sbinfo = file->private_data; | |
26255 | + if (sbinfo) | |
26256 | + au_plink_clean(sbinfo->si_sb, /*verbose*/0); | |
26257 | +} | |
26258 | + | |
26259 | +static int au_procfs_plm_write_si(struct file *file, unsigned long id) | |
26260 | +{ | |
26261 | + int err; | |
26262 | + struct super_block *sb; | |
26263 | + struct au_sbinfo *sbinfo; | |
26264 | + | |
26265 | + err = -EBUSY; | |
26266 | + if (unlikely(file->private_data)) | |
26267 | + goto out; | |
26268 | + | |
26269 | + sb = NULL; | |
53392da6 | 26270 | + /* don't use au_sbilist_lock() here */ |
e49829fe | 26271 | + spin_lock(&au_sbilist.spin); |
5afbbe0d | 26272 | + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list) |
e49829fe JR |
26273 | + if (id == sysaufs_si_id(sbinfo)) { |
26274 | + kobject_get(&sbinfo->si_kobj); | |
26275 | + sb = sbinfo->si_sb; | |
26276 | + break; | |
26277 | + } | |
26278 | + spin_unlock(&au_sbilist.spin); | |
26279 | + | |
26280 | + err = -EINVAL; | |
26281 | + if (unlikely(!sb)) | |
26282 | + goto out; | |
26283 | + | |
26284 | + err = au_plink_maint_enter(sb); | |
26285 | + if (!err) | |
26286 | + /* keep kobject_get() */ | |
26287 | + file->private_data = sbinfo; | |
26288 | + else | |
26289 | + kobject_put(&sbinfo->si_kobj); | |
26290 | +out: | |
26291 | + return err; | |
26292 | +} | |
26293 | + | |
26294 | +/* | |
26295 | + * Accept a valid "si=xxxx" only. | |
26296 | + * Once it is accepted successfully, accept "clean" too. | |
26297 | + */ | |
26298 | +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf, | |
26299 | + size_t count, loff_t *ppos) | |
26300 | +{ | |
26301 | + ssize_t err; | |
26302 | + unsigned long id; | |
26303 | + /* last newline is allowed */ | |
26304 | + char buf[3 + sizeof(unsigned long) * 2 + 1]; | |
26305 | + | |
26306 | + err = -EACCES; | |
26307 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
26308 | + goto out; | |
26309 | + | |
26310 | + err = -EINVAL; | |
26311 | + if (unlikely(count > sizeof(buf))) | |
26312 | + goto out; | |
26313 | + | |
26314 | + err = copy_from_user(buf, ubuf, count); | |
26315 | + if (unlikely(err)) { | |
26316 | + err = -EFAULT; | |
26317 | + goto out; | |
26318 | + } | |
26319 | + buf[count] = 0; | |
26320 | + | |
26321 | + err = -EINVAL; | |
26322 | + if (!strcmp("clean", buf)) { | |
26323 | + au_procfs_plm_write_clean(file); | |
26324 | + goto out_success; | |
26325 | + } else if (unlikely(strncmp("si=", buf, 3))) | |
26326 | + goto out; | |
26327 | + | |
9dbd164d | 26328 | + err = kstrtoul(buf + 3, 16, &id); |
e49829fe JR |
26329 | + if (unlikely(err)) |
26330 | + goto out; | |
26331 | + | |
26332 | + err = au_procfs_plm_write_si(file, id); | |
26333 | + if (unlikely(err)) | |
26334 | + goto out; | |
26335 | + | |
26336 | +out_success: | |
26337 | + err = count; /* success */ | |
26338 | +out: | |
26339 | + return err; | |
26340 | +} | |
26341 | + | |
26342 | +static const struct file_operations au_procfs_plm_fop = { | |
26343 | + .write = au_procfs_plm_write, | |
26344 | + .release = au_procfs_plm_release, | |
26345 | + .owner = THIS_MODULE | |
26346 | +}; | |
26347 | + | |
26348 | +/* ---------------------------------------------------------------------- */ | |
26349 | + | |
26350 | +static struct proc_dir_entry *au_procfs_dir; | |
26351 | + | |
26352 | +void au_procfs_fin(void) | |
26353 | +{ | |
26354 | + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir); | |
26355 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
26356 | +} | |
26357 | + | |
26358 | +int __init au_procfs_init(void) | |
26359 | +{ | |
26360 | + int err; | |
26361 | + struct proc_dir_entry *entry; | |
26362 | + | |
26363 | + err = -ENOMEM; | |
26364 | + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL); | |
26365 | + if (unlikely(!au_procfs_dir)) | |
26366 | + goto out; | |
26367 | + | |
26368 | + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR, | |
26369 | + au_procfs_dir, &au_procfs_plm_fop); | |
26370 | + if (unlikely(!entry)) | |
26371 | + goto out_dir; | |
26372 | + | |
26373 | + err = 0; | |
26374 | + goto out; /* success */ | |
26375 | + | |
26376 | + | |
26377 | +out_dir: | |
26378 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
26379 | +out: | |
26380 | + return err; | |
26381 | +} | |
7f207e10 AM |
26382 | diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c |
26383 | --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 26384 | +++ linux/fs/aufs/rdu.c 2017-05-06 22:16:52.781553511 +0200 |
5afbbe0d | 26385 | @@ -0,0 +1,381 @@ |
1308ab2a | 26386 | +/* |
a2654f78 | 26387 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1308ab2a | 26388 | + * |
26389 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26390 | + * it under the terms of the GNU General Public License as published by | |
26391 | + * the Free Software Foundation; either version 2 of the License, or | |
26392 | + * (at your option) any later version. | |
26393 | + * | |
26394 | + * This program is distributed in the hope that it will be useful, | |
26395 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26396 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26397 | + * GNU General Public License for more details. | |
26398 | + * | |
26399 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26400 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1308ab2a | 26401 | + */ |
26402 | + | |
26403 | +/* | |
26404 | + * readdir in userspace. | |
26405 | + */ | |
26406 | + | |
b752ccd1 | 26407 | +#include <linux/compat.h> |
4a4d8108 | 26408 | +#include <linux/fs_stack.h> |
1308ab2a | 26409 | +#include <linux/security.h> |
1308ab2a | 26410 | +#include "aufs.h" |
26411 | + | |
26412 | +/* bits for struct aufs_rdu.flags */ | |
26413 | +#define AuRdu_CALLED 1 | |
26414 | +#define AuRdu_CONT (1 << 1) | |
26415 | +#define AuRdu_FULL (1 << 2) | |
26416 | +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name) | |
7f207e10 AM |
26417 | +#define au_fset_rdu(flags, name) \ |
26418 | + do { (flags) |= AuRdu_##name; } while (0) | |
26419 | +#define au_fclr_rdu(flags, name) \ | |
26420 | + do { (flags) &= ~AuRdu_##name; } while (0) | |
1308ab2a | 26421 | + |
26422 | +struct au_rdu_arg { | |
392086de | 26423 | + struct dir_context ctx; |
1308ab2a | 26424 | + struct aufs_rdu *rdu; |
26425 | + union au_rdu_ent_ul ent; | |
26426 | + unsigned long end; | |
26427 | + | |
26428 | + struct super_block *sb; | |
26429 | + int err; | |
26430 | +}; | |
26431 | + | |
392086de | 26432 | +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen, |
1308ab2a | 26433 | + loff_t offset, u64 h_ino, unsigned int d_type) |
26434 | +{ | |
26435 | + int err, len; | |
392086de | 26436 | + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx); |
1308ab2a | 26437 | + struct aufs_rdu *rdu = arg->rdu; |
26438 | + struct au_rdu_ent ent; | |
26439 | + | |
26440 | + err = 0; | |
26441 | + arg->err = 0; | |
26442 | + au_fset_rdu(rdu->cookie.flags, CALLED); | |
26443 | + len = au_rdu_len(nlen); | |
26444 | + if (arg->ent.ul + len < arg->end) { | |
26445 | + ent.ino = h_ino; | |
26446 | + ent.bindex = rdu->cookie.bindex; | |
26447 | + ent.type = d_type; | |
26448 | + ent.nlen = nlen; | |
4a4d8108 AM |
26449 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) |
26450 | + ent.type = DT_UNKNOWN; | |
1308ab2a | 26451 | + |
9dbd164d | 26452 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 26453 | + err = -EFAULT; |
26454 | + if (copy_to_user(arg->ent.e, &ent, sizeof(ent))) | |
26455 | + goto out; | |
26456 | + if (copy_to_user(arg->ent.e->name, name, nlen)) | |
26457 | + goto out; | |
26458 | + /* the terminating NULL */ | |
26459 | + if (__put_user(0, arg->ent.e->name + nlen)) | |
26460 | + goto out; | |
26461 | + err = 0; | |
26462 | + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */ | |
26463 | + arg->ent.ul += len; | |
26464 | + rdu->rent++; | |
26465 | + } else { | |
26466 | + err = -EFAULT; | |
26467 | + au_fset_rdu(rdu->cookie.flags, FULL); | |
26468 | + rdu->full = 1; | |
26469 | + rdu->tail = arg->ent; | |
26470 | + } | |
26471 | + | |
4f0767ce | 26472 | +out: |
1308ab2a | 26473 | + /* AuTraceErr(err); */ |
26474 | + return err; | |
26475 | +} | |
26476 | + | |
26477 | +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg) | |
26478 | +{ | |
26479 | + int err; | |
26480 | + loff_t offset; | |
26481 | + struct au_rdu_cookie *cookie = &arg->rdu->cookie; | |
26482 | + | |
92d182d2 | 26483 | + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */ |
1308ab2a | 26484 | + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET); |
26485 | + err = offset; | |
26486 | + if (unlikely(offset != cookie->h_pos)) | |
26487 | + goto out; | |
26488 | + | |
26489 | + err = 0; | |
26490 | + do { | |
26491 | + arg->err = 0; | |
26492 | + au_fclr_rdu(cookie->flags, CALLED); | |
26493 | + /* smp_mb(); */ | |
392086de | 26494 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1308ab2a | 26495 | + if (err >= 0) |
26496 | + err = arg->err; | |
26497 | + } while (!err | |
26498 | + && au_ftest_rdu(cookie->flags, CALLED) | |
26499 | + && !au_ftest_rdu(cookie->flags, FULL)); | |
26500 | + cookie->h_pos = h_file->f_pos; | |
26501 | + | |
4f0767ce | 26502 | +out: |
1308ab2a | 26503 | + AuTraceErr(err); |
26504 | + return err; | |
26505 | +} | |
26506 | + | |
26507 | +static int au_rdu(struct file *file, struct aufs_rdu *rdu) | |
26508 | +{ | |
26509 | + int err; | |
5afbbe0d | 26510 | + aufs_bindex_t bbot; |
392086de AM |
26511 | + struct au_rdu_arg arg = { |
26512 | + .ctx = { | |
2000de60 | 26513 | + .actor = au_rdu_fill |
392086de AM |
26514 | + } |
26515 | + }; | |
1308ab2a | 26516 | + struct dentry *dentry; |
26517 | + struct inode *inode; | |
26518 | + struct file *h_file; | |
26519 | + struct au_rdu_cookie *cookie = &rdu->cookie; | |
26520 | + | |
26521 | + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz); | |
26522 | + if (unlikely(err)) { | |
26523 | + err = -EFAULT; | |
26524 | + AuTraceErr(err); | |
26525 | + goto out; | |
26526 | + } | |
26527 | + rdu->rent = 0; | |
26528 | + rdu->tail = rdu->ent; | |
26529 | + rdu->full = 0; | |
26530 | + arg.rdu = rdu; | |
26531 | + arg.ent = rdu->ent; | |
26532 | + arg.end = arg.ent.ul; | |
26533 | + arg.end += rdu->sz; | |
26534 | + | |
26535 | + err = -ENOTDIR; | |
5afbbe0d | 26536 | + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared)) |
1308ab2a | 26537 | + goto out; |
26538 | + | |
26539 | + err = security_file_permission(file, MAY_READ); | |
26540 | + AuTraceErr(err); | |
26541 | + if (unlikely(err)) | |
26542 | + goto out; | |
26543 | + | |
2000de60 | 26544 | + dentry = file->f_path.dentry; |
5527c038 | 26545 | + inode = d_inode(dentry); |
5afbbe0d | 26546 | + inode_lock_shared(inode); |
1308ab2a | 26547 | + |
26548 | + arg.sb = inode->i_sb; | |
e49829fe JR |
26549 | + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM); |
26550 | + if (unlikely(err)) | |
26551 | + goto out_mtx; | |
027c5e7a AM |
26552 | + err = au_alive_dir(dentry); |
26553 | + if (unlikely(err)) | |
26554 | + goto out_si; | |
e49829fe | 26555 | + /* todo: reval? */ |
1308ab2a | 26556 | + fi_read_lock(file); |
26557 | + | |
26558 | + err = -EAGAIN; | |
26559 | + if (unlikely(au_ftest_rdu(cookie->flags, CONT) | |
26560 | + && cookie->generation != au_figen(file))) | |
26561 | + goto out_unlock; | |
26562 | + | |
26563 | + err = 0; | |
26564 | + if (!rdu->blk) { | |
26565 | + rdu->blk = au_sbi(arg.sb)->si_rdblk; | |
26566 | + if (!rdu->blk) | |
26567 | + rdu->blk = au_dir_size(file, /*dentry*/NULL); | |
26568 | + } | |
5afbbe0d AM |
26569 | + bbot = au_fbtop(file); |
26570 | + if (cookie->bindex < bbot) | |
26571 | + cookie->bindex = bbot; | |
26572 | + bbot = au_fbbot_dir(file); | |
26573 | + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */ | |
26574 | + for (; !err && cookie->bindex <= bbot; | |
1308ab2a | 26575 | + cookie->bindex++, cookie->h_pos = 0) { |
4a4d8108 | 26576 | + h_file = au_hf_dir(file, cookie->bindex); |
1308ab2a | 26577 | + if (!h_file) |
26578 | + continue; | |
26579 | + | |
26580 | + au_fclr_rdu(cookie->flags, FULL); | |
26581 | + err = au_rdu_do(h_file, &arg); | |
26582 | + AuTraceErr(err); | |
26583 | + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err)) | |
26584 | + break; | |
26585 | + } | |
26586 | + AuDbg("rent %llu\n", rdu->rent); | |
26587 | + | |
26588 | + if (!err && !au_ftest_rdu(cookie->flags, CONT)) { | |
26589 | + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH); | |
26590 | + au_fset_rdu(cookie->flags, CONT); | |
26591 | + cookie->generation = au_figen(file); | |
26592 | + } | |
26593 | + | |
26594 | + ii_read_lock_child(inode); | |
5afbbe0d | 26595 | + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode))); |
1308ab2a | 26596 | + ii_read_unlock(inode); |
26597 | + | |
4f0767ce | 26598 | +out_unlock: |
1308ab2a | 26599 | + fi_read_unlock(file); |
027c5e7a | 26600 | +out_si: |
1308ab2a | 26601 | + si_read_unlock(arg.sb); |
4f0767ce | 26602 | +out_mtx: |
5afbbe0d | 26603 | + inode_unlock_shared(inode); |
4f0767ce | 26604 | +out: |
1308ab2a | 26605 | + AuTraceErr(err); |
26606 | + return err; | |
26607 | +} | |
26608 | + | |
26609 | +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu) | |
26610 | +{ | |
26611 | + int err; | |
26612 | + ino_t ino; | |
26613 | + unsigned long long nent; | |
26614 | + union au_rdu_ent_ul *u; | |
26615 | + struct au_rdu_ent ent; | |
26616 | + struct super_block *sb; | |
26617 | + | |
26618 | + err = 0; | |
26619 | + nent = rdu->nent; | |
26620 | + u = &rdu->ent; | |
2000de60 | 26621 | + sb = file->f_path.dentry->d_sb; |
1308ab2a | 26622 | + si_read_lock(sb, AuLock_FLUSH); |
26623 | + while (nent-- > 0) { | |
9dbd164d | 26624 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 26625 | + err = copy_from_user(&ent, u->e, sizeof(ent)); |
4a4d8108 AM |
26626 | + if (!err) |
26627 | + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino)); | |
1308ab2a | 26628 | + if (unlikely(err)) { |
26629 | + err = -EFAULT; | |
26630 | + AuTraceErr(err); | |
26631 | + break; | |
26632 | + } | |
26633 | + | |
26634 | + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */ | |
26635 | + if (!ent.wh) | |
26636 | + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino); | |
26637 | + else | |
26638 | + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type, | |
26639 | + &ino); | |
26640 | + if (unlikely(err)) { | |
26641 | + AuTraceErr(err); | |
26642 | + break; | |
26643 | + } | |
26644 | + | |
26645 | + err = __put_user(ino, &u->e->ino); | |
26646 | + if (unlikely(err)) { | |
26647 | + err = -EFAULT; | |
26648 | + AuTraceErr(err); | |
26649 | + break; | |
26650 | + } | |
26651 | + u->ul += au_rdu_len(ent.nlen); | |
26652 | + } | |
26653 | + si_read_unlock(sb); | |
26654 | + | |
26655 | + return err; | |
26656 | +} | |
26657 | + | |
26658 | +/* ---------------------------------------------------------------------- */ | |
26659 | + | |
26660 | +static int au_rdu_verify(struct aufs_rdu *rdu) | |
26661 | +{ | |
b752ccd1 | 26662 | + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | " |
1308ab2a | 26663 | + "%llu, b%d, 0x%x, g%u}\n", |
b752ccd1 | 26664 | + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ], |
1308ab2a | 26665 | + rdu->blk, |
26666 | + rdu->rent, rdu->shwh, rdu->full, | |
26667 | + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags, | |
26668 | + rdu->cookie.generation); | |
dece6358 | 26669 | + |
b752ccd1 | 26670 | + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu)) |
1308ab2a | 26671 | + return 0; |
dece6358 | 26672 | + |
b752ccd1 AM |
26673 | + AuDbg("%u:%u\n", |
26674 | + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu)); | |
1308ab2a | 26675 | + return -EINVAL; |
26676 | +} | |
26677 | + | |
26678 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
dece6358 | 26679 | +{ |
1308ab2a | 26680 | + long err, e; |
26681 | + struct aufs_rdu rdu; | |
26682 | + void __user *p = (void __user *)arg; | |
dece6358 | 26683 | + |
1308ab2a | 26684 | + err = copy_from_user(&rdu, p, sizeof(rdu)); |
26685 | + if (unlikely(err)) { | |
26686 | + err = -EFAULT; | |
26687 | + AuTraceErr(err); | |
26688 | + goto out; | |
26689 | + } | |
26690 | + err = au_rdu_verify(&rdu); | |
dece6358 AM |
26691 | + if (unlikely(err)) |
26692 | + goto out; | |
26693 | + | |
1308ab2a | 26694 | + switch (cmd) { |
26695 | + case AUFS_CTL_RDU: | |
26696 | + err = au_rdu(file, &rdu); | |
26697 | + if (unlikely(err)) | |
26698 | + break; | |
dece6358 | 26699 | + |
1308ab2a | 26700 | + e = copy_to_user(p, &rdu, sizeof(rdu)); |
26701 | + if (unlikely(e)) { | |
26702 | + err = -EFAULT; | |
26703 | + AuTraceErr(err); | |
26704 | + } | |
26705 | + break; | |
26706 | + case AUFS_CTL_RDU_INO: | |
26707 | + err = au_rdu_ino(file, &rdu); | |
26708 | + break; | |
26709 | + | |
26710 | + default: | |
4a4d8108 | 26711 | + /* err = -ENOTTY; */ |
1308ab2a | 26712 | + err = -EINVAL; |
26713 | + } | |
dece6358 | 26714 | + |
4f0767ce | 26715 | +out: |
1308ab2a | 26716 | + AuTraceErr(err); |
26717 | + return err; | |
1facf9fc | 26718 | +} |
b752ccd1 AM |
26719 | + |
26720 | +#ifdef CONFIG_COMPAT | |
26721 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
26722 | +{ | |
26723 | + long err, e; | |
26724 | + struct aufs_rdu rdu; | |
26725 | + void __user *p = compat_ptr(arg); | |
26726 | + | |
26727 | + /* todo: get_user()? */ | |
26728 | + err = copy_from_user(&rdu, p, sizeof(rdu)); | |
26729 | + if (unlikely(err)) { | |
26730 | + err = -EFAULT; | |
26731 | + AuTraceErr(err); | |
26732 | + goto out; | |
26733 | + } | |
26734 | + rdu.ent.e = compat_ptr(rdu.ent.ul); | |
26735 | + err = au_rdu_verify(&rdu); | |
26736 | + if (unlikely(err)) | |
26737 | + goto out; | |
26738 | + | |
26739 | + switch (cmd) { | |
26740 | + case AUFS_CTL_RDU: | |
26741 | + err = au_rdu(file, &rdu); | |
26742 | + if (unlikely(err)) | |
26743 | + break; | |
26744 | + | |
26745 | + rdu.ent.ul = ptr_to_compat(rdu.ent.e); | |
26746 | + rdu.tail.ul = ptr_to_compat(rdu.tail.e); | |
26747 | + e = copy_to_user(p, &rdu, sizeof(rdu)); | |
26748 | + if (unlikely(e)) { | |
26749 | + err = -EFAULT; | |
26750 | + AuTraceErr(err); | |
26751 | + } | |
26752 | + break; | |
26753 | + case AUFS_CTL_RDU_INO: | |
26754 | + err = au_rdu_ino(file, &rdu); | |
26755 | + break; | |
26756 | + | |
26757 | + default: | |
26758 | + /* err = -ENOTTY; */ | |
26759 | + err = -EINVAL; | |
26760 | + } | |
26761 | + | |
4f0767ce | 26762 | +out: |
b752ccd1 AM |
26763 | + AuTraceErr(err); |
26764 | + return err; | |
26765 | +} | |
26766 | +#endif | |
7f207e10 AM |
26767 | diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h |
26768 | --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 26769 | +++ linux/fs/aufs/rwsem.h 2017-05-06 22:16:52.781553511 +0200 |
5afbbe0d | 26770 | @@ -0,0 +1,198 @@ |
1facf9fc | 26771 | +/* |
a2654f78 | 26772 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 26773 | + * |
26774 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26775 | + * it under the terms of the GNU General Public License as published by | |
26776 | + * the Free Software Foundation; either version 2 of the License, or | |
26777 | + * (at your option) any later version. | |
dece6358 AM |
26778 | + * |
26779 | + * This program is distributed in the hope that it will be useful, | |
26780 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26781 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26782 | + * GNU General Public License for more details. | |
26783 | + * | |
26784 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26785 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26786 | + */ |
26787 | + | |
26788 | +/* | |
26789 | + * simple read-write semaphore wrappers | |
26790 | + */ | |
26791 | + | |
26792 | +#ifndef __AUFS_RWSEM_H__ | |
26793 | +#define __AUFS_RWSEM_H__ | |
26794 | + | |
26795 | +#ifdef __KERNEL__ | |
26796 | + | |
4a4d8108 | 26797 | +#include "debug.h" |
dece6358 AM |
26798 | + |
26799 | +struct au_rwsem { | |
26800 | + struct rw_semaphore rwsem; | |
26801 | +#ifdef CONFIG_AUFS_DEBUG | |
26802 | + /* just for debugging, not almighty counter */ | |
26803 | + atomic_t rcnt, wcnt; | |
26804 | +#endif | |
26805 | +}; | |
26806 | + | |
5afbbe0d AM |
26807 | +#ifdef CONFIG_LOCKDEP |
26808 | +#define au_lockdep_set_name(rw) \ | |
26809 | + lockdep_set_class_and_name(&(rw)->rwsem, \ | |
26810 | + /*original key*/(rw)->rwsem.dep_map.key, \ | |
26811 | + /*name*/#rw) | |
26812 | +#else | |
26813 | +#define au_lockdep_set_name(rw) do {} while (0) | |
26814 | +#endif | |
26815 | + | |
dece6358 AM |
26816 | +#ifdef CONFIG_AUFS_DEBUG |
26817 | +#define AuDbgCntInit(rw) do { \ | |
26818 | + atomic_set(&(rw)->rcnt, 0); \ | |
26819 | + atomic_set(&(rw)->wcnt, 0); \ | |
26820 | + smp_mb(); /* atomic set */ \ | |
26821 | +} while (0) | |
26822 | + | |
5afbbe0d AM |
26823 | +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt) |
26824 | +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt) | |
26825 | +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0) | |
26826 | +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt) | |
26827 | +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt) | |
26828 | +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt) | |
26829 | +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt) | |
dece6358 | 26830 | +#else |
5afbbe0d | 26831 | +#define AuDbgCnt(rw, cnt) 0 |
dece6358 AM |
26832 | +#define AuDbgCntInit(rw) do {} while (0) |
26833 | +#define AuDbgRcntInc(rw) do {} while (0) | |
26834 | +#define AuDbgRcntDec(rw) do {} while (0) | |
26835 | +#define AuDbgWcntInc(rw) do {} while (0) | |
26836 | +#define AuDbgWcntDec(rw) do {} while (0) | |
26837 | +#endif /* CONFIG_AUFS_DEBUG */ | |
26838 | + | |
26839 | +/* to debug easier, do not make them inlined functions */ | |
5afbbe0d | 26840 | +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem)) |
dece6358 | 26841 | +/* rwsem_is_locked() is unusable */ |
5afbbe0d AM |
26842 | +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0) |
26843 | +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0) | |
26844 | +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \ | |
26845 | + && AuDbgCnt(rw, wcnt) <= 0) | |
26846 | +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \ | |
26847 | + || AuDbgCnt(rw, wcnt)) | |
26848 | + | |
26849 | +#define au_rw_init(rw) do { \ | |
26850 | + AuDbgCntInit(rw); \ | |
26851 | + init_rwsem(&(rw)->rwsem); \ | |
26852 | + au_lockdep_set_name(rw); \ | |
26853 | + } while (0) | |
dece6358 | 26854 | + |
5afbbe0d AM |
26855 | +#define au_rw_init_wlock(rw) do { \ |
26856 | + au_rw_init(rw); \ | |
26857 | + down_write(&(rw)->rwsem); \ | |
26858 | + AuDbgWcntInc(rw); \ | |
26859 | + } while (0) | |
dece6358 | 26860 | + |
5afbbe0d AM |
26861 | +#define au_rw_init_wlock_nested(rw, lsc) do { \ |
26862 | + au_rw_init(rw); \ | |
26863 | + down_write_nested(&(rw)->rwsem, lsc); \ | |
26864 | + AuDbgWcntInc(rw); \ | |
26865 | + } while (0) | |
dece6358 AM |
26866 | + |
26867 | +static inline void au_rw_read_lock(struct au_rwsem *rw) | |
26868 | +{ | |
26869 | + down_read(&rw->rwsem); | |
26870 | + AuDbgRcntInc(rw); | |
26871 | +} | |
26872 | + | |
26873 | +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc) | |
26874 | +{ | |
26875 | + down_read_nested(&rw->rwsem, lsc); | |
26876 | + AuDbgRcntInc(rw); | |
26877 | +} | |
26878 | + | |
26879 | +static inline void au_rw_read_unlock(struct au_rwsem *rw) | |
26880 | +{ | |
26881 | + AuRwMustReadLock(rw); | |
26882 | + AuDbgRcntDec(rw); | |
26883 | + up_read(&rw->rwsem); | |
26884 | +} | |
26885 | + | |
26886 | +static inline void au_rw_dgrade_lock(struct au_rwsem *rw) | |
26887 | +{ | |
26888 | + AuRwMustWriteLock(rw); | |
26889 | + AuDbgRcntInc(rw); | |
26890 | + AuDbgWcntDec(rw); | |
26891 | + downgrade_write(&rw->rwsem); | |
26892 | +} | |
26893 | + | |
26894 | +static inline void au_rw_write_lock(struct au_rwsem *rw) | |
26895 | +{ | |
26896 | + down_write(&rw->rwsem); | |
26897 | + AuDbgWcntInc(rw); | |
26898 | +} | |
26899 | + | |
26900 | +static inline void au_rw_write_lock_nested(struct au_rwsem *rw, | |
26901 | + unsigned int lsc) | |
26902 | +{ | |
26903 | + down_write_nested(&rw->rwsem, lsc); | |
26904 | + AuDbgWcntInc(rw); | |
26905 | +} | |
1facf9fc | 26906 | + |
dece6358 AM |
26907 | +static inline void au_rw_write_unlock(struct au_rwsem *rw) |
26908 | +{ | |
26909 | + AuRwMustWriteLock(rw); | |
26910 | + AuDbgWcntDec(rw); | |
26911 | + up_write(&rw->rwsem); | |
26912 | +} | |
26913 | + | |
26914 | +/* why is not _nested version defined */ | |
26915 | +static inline int au_rw_read_trylock(struct au_rwsem *rw) | |
26916 | +{ | |
076b876e AM |
26917 | + int ret; |
26918 | + | |
26919 | + ret = down_read_trylock(&rw->rwsem); | |
dece6358 AM |
26920 | + if (ret) |
26921 | + AuDbgRcntInc(rw); | |
26922 | + return ret; | |
26923 | +} | |
26924 | + | |
26925 | +static inline int au_rw_write_trylock(struct au_rwsem *rw) | |
26926 | +{ | |
076b876e AM |
26927 | + int ret; |
26928 | + | |
26929 | + ret = down_write_trylock(&rw->rwsem); | |
dece6358 AM |
26930 | + if (ret) |
26931 | + AuDbgWcntInc(rw); | |
26932 | + return ret; | |
26933 | +} | |
26934 | + | |
5afbbe0d | 26935 | +#undef AuDbgCntDec |
dece6358 AM |
26936 | +#undef AuDbgRcntInc |
26937 | +#undef AuDbgRcntDec | |
dece6358 | 26938 | +#undef AuDbgWcntDec |
1facf9fc | 26939 | + |
26940 | +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
26941 | +static inline void prefix##_read_lock(param) \ | |
dece6358 | 26942 | +{ au_rw_read_lock(rwsem); } \ |
1facf9fc | 26943 | +static inline void prefix##_write_lock(param) \ |
dece6358 | 26944 | +{ au_rw_write_lock(rwsem); } \ |
1facf9fc | 26945 | +static inline int prefix##_read_trylock(param) \ |
dece6358 | 26946 | +{ return au_rw_read_trylock(rwsem); } \ |
1facf9fc | 26947 | +static inline int prefix##_write_trylock(param) \ |
dece6358 | 26948 | +{ return au_rw_write_trylock(rwsem); } |
1facf9fc | 26949 | +/* why is not _nested version defined */ |
26950 | +/* static inline void prefix##_read_trylock_nested(param, lsc) | |
dece6358 | 26951 | +{ au_rw_read_trylock_nested(rwsem, lsc)); } |
1facf9fc | 26952 | +static inline void prefix##_write_trylock_nestd(param, lsc) |
dece6358 | 26953 | +{ au_rw_write_trylock_nested(rwsem, lsc); } */ |
1facf9fc | 26954 | + |
26955 | +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \ | |
26956 | +static inline void prefix##_read_unlock(param) \ | |
dece6358 | 26957 | +{ au_rw_read_unlock(rwsem); } \ |
1facf9fc | 26958 | +static inline void prefix##_write_unlock(param) \ |
dece6358 | 26959 | +{ au_rw_write_unlock(rwsem); } \ |
1facf9fc | 26960 | +static inline void prefix##_downgrade_lock(param) \ |
dece6358 | 26961 | +{ au_rw_dgrade_lock(rwsem); } |
1facf9fc | 26962 | + |
26963 | +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \ | |
26964 | + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
26965 | + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) | |
26966 | + | |
26967 | +#endif /* __KERNEL__ */ | |
26968 | +#endif /* __AUFS_RWSEM_H__ */ | |
7f207e10 AM |
26969 | diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c |
26970 | --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 26971 | +++ linux/fs/aufs/sbinfo.c 2017-05-06 22:16:52.781553511 +0200 |
a2654f78 | 26972 | @@ -0,0 +1,304 @@ |
1facf9fc | 26973 | +/* |
a2654f78 | 26974 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 26975 | + * |
26976 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26977 | + * it under the terms of the GNU General Public License as published by | |
26978 | + * the Free Software Foundation; either version 2 of the License, or | |
26979 | + * (at your option) any later version. | |
dece6358 AM |
26980 | + * |
26981 | + * This program is distributed in the hope that it will be useful, | |
26982 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26983 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26984 | + * GNU General Public License for more details. | |
26985 | + * | |
26986 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26987 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26988 | + */ |
26989 | + | |
26990 | +/* | |
26991 | + * superblock private data | |
26992 | + */ | |
26993 | + | |
26994 | +#include "aufs.h" | |
26995 | + | |
26996 | +/* | |
26997 | + * they are necessary regardless sysfs is disabled. | |
26998 | + */ | |
26999 | +void au_si_free(struct kobject *kobj) | |
27000 | +{ | |
86dc4139 | 27001 | + int i; |
1facf9fc | 27002 | + struct au_sbinfo *sbinfo; |
b752ccd1 | 27003 | + char *locked __maybe_unused; /* debug only */ |
1facf9fc | 27004 | + |
27005 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
86dc4139 AM |
27006 | + for (i = 0; i < AuPlink_NHASH; i++) |
27007 | + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head)); | |
f0c0a007 | 27008 | + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len)); |
5afbbe0d AM |
27009 | + |
27010 | + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes)); | |
27011 | + percpu_counter_destroy(&sbinfo->si_ninodes); | |
27012 | + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles)); | |
27013 | + percpu_counter_destroy(&sbinfo->si_nfiles); | |
1facf9fc | 27014 | + |
e49829fe | 27015 | + au_rw_write_lock(&sbinfo->si_rwsem); |
1facf9fc | 27016 | + au_br_free(sbinfo); |
e49829fe | 27017 | + au_rw_write_unlock(&sbinfo->si_rwsem); |
b752ccd1 | 27018 | + |
f0c0a007 | 27019 | + au_delayed_kfree(sbinfo->si_branch); |
1facf9fc | 27020 | + mutex_destroy(&sbinfo->si_xib_mtx); |
dece6358 | 27021 | + AuRwDestroy(&sbinfo->si_rwsem); |
1facf9fc | 27022 | + |
f0c0a007 | 27023 | + au_delayed_kfree(sbinfo); |
1facf9fc | 27024 | +} |
27025 | + | |
27026 | +int au_si_alloc(struct super_block *sb) | |
27027 | +{ | |
86dc4139 | 27028 | + int err, i; |
1facf9fc | 27029 | + struct au_sbinfo *sbinfo; |
27030 | + | |
27031 | + err = -ENOMEM; | |
4a4d8108 | 27032 | + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS); |
1facf9fc | 27033 | + if (unlikely(!sbinfo)) |
27034 | + goto out; | |
27035 | + | |
27036 | + /* will be reallocated separately */ | |
27037 | + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS); | |
27038 | + if (unlikely(!sbinfo->si_branch)) | |
febd17d6 | 27039 | + goto out_sbinfo; |
1facf9fc | 27040 | + |
1facf9fc | 27041 | + err = sysaufs_si_init(sbinfo); |
27042 | + if (unlikely(err)) | |
27043 | + goto out_br; | |
27044 | + | |
27045 | + au_nwt_init(&sbinfo->si_nowait); | |
dece6358 | 27046 | + au_rw_init_wlock(&sbinfo->si_rwsem); |
b752ccd1 | 27047 | + |
5afbbe0d AM |
27048 | + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS); |
27049 | + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS); | |
7f207e10 | 27050 | + |
5afbbe0d | 27051 | + sbinfo->si_bbot = -1; |
392086de | 27052 | + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2; |
1facf9fc | 27053 | + |
27054 | + sbinfo->si_wbr_copyup = AuWbrCopyup_Def; | |
27055 | + sbinfo->si_wbr_create = AuWbrCreate_Def; | |
4a4d8108 AM |
27056 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup; |
27057 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create; | |
1facf9fc | 27058 | + |
076b876e AM |
27059 | + au_fhsm_init(sbinfo); |
27060 | + | |
e49829fe | 27061 | + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def); |
1facf9fc | 27062 | + |
392086de AM |
27063 | + sbinfo->si_xino_jiffy = jiffies; |
27064 | + sbinfo->si_xino_expire | |
27065 | + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC); | |
1facf9fc | 27066 | + mutex_init(&sbinfo->si_xib_mtx); |
1facf9fc | 27067 | + sbinfo->si_xino_brid = -1; |
27068 | + /* leave si_xib_last_pindex and si_xib_next_bit */ | |
27069 | + | |
b912730e AM |
27070 | + au_sphl_init(&sbinfo->si_aopen); |
27071 | + | |
e49829fe | 27072 | + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC); |
1facf9fc | 27073 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; |
27074 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
27075 | + sbinfo->si_dirwh = AUFS_DIRWH_DEF; | |
27076 | + | |
86dc4139 AM |
27077 | + for (i = 0; i < AuPlink_NHASH; i++) |
27078 | + au_sphl_init(sbinfo->si_plink + i); | |
1facf9fc | 27079 | + init_waitqueue_head(&sbinfo->si_plink_wq); |
4a4d8108 | 27080 | + spin_lock_init(&sbinfo->si_plink_maint_lock); |
1facf9fc | 27081 | + |
523b37e3 AM |
27082 | + au_sphl_init(&sbinfo->si_files); |
27083 | + | |
b95c5147 AM |
27084 | + /* with getattr by default */ |
27085 | + sbinfo->si_iop_array = aufs_iop; | |
27086 | + | |
1facf9fc | 27087 | + /* leave other members for sysaufs and si_mnt. */ |
27088 | + sbinfo->si_sb = sb; | |
27089 | + sb->s_fs_info = sbinfo; | |
b752ccd1 | 27090 | + si_pid_set(sb); |
1facf9fc | 27091 | + return 0; /* success */ |
27092 | + | |
4f0767ce | 27093 | +out_br: |
f0c0a007 | 27094 | + au_delayed_kfree(sbinfo->si_branch); |
4f0767ce | 27095 | +out_sbinfo: |
f0c0a007 | 27096 | + au_delayed_kfree(sbinfo); |
4f0767ce | 27097 | +out: |
1facf9fc | 27098 | + return err; |
27099 | +} | |
27100 | + | |
e2f27e51 | 27101 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink) |
1facf9fc | 27102 | +{ |
27103 | + int err, sz; | |
27104 | + struct au_branch **brp; | |
27105 | + | |
dece6358 AM |
27106 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
27107 | + | |
1facf9fc | 27108 | + err = -ENOMEM; |
5afbbe0d | 27109 | + sz = sizeof(*brp) * (sbinfo->si_bbot + 1); |
1facf9fc | 27110 | + if (unlikely(!sz)) |
27111 | + sz = sizeof(*brp); | |
e2f27e51 AM |
27112 | + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS, |
27113 | + may_shrink); | |
1facf9fc | 27114 | + if (brp) { |
27115 | + sbinfo->si_branch = brp; | |
27116 | + err = 0; | |
27117 | + } | |
27118 | + | |
27119 | + return err; | |
27120 | +} | |
27121 | + | |
27122 | +/* ---------------------------------------------------------------------- */ | |
27123 | + | |
27124 | +unsigned int au_sigen_inc(struct super_block *sb) | |
27125 | +{ | |
27126 | + unsigned int gen; | |
5527c038 | 27127 | + struct inode *inode; |
1facf9fc | 27128 | + |
dece6358 AM |
27129 | + SiMustWriteLock(sb); |
27130 | + | |
1facf9fc | 27131 | + gen = ++au_sbi(sb)->si_generation; |
27132 | + au_update_digen(sb->s_root); | |
5527c038 JR |
27133 | + inode = d_inode(sb->s_root); |
27134 | + au_update_iigen(inode, /*half*/0); | |
27135 | + inode->i_version++; | |
1facf9fc | 27136 | + return gen; |
27137 | +} | |
27138 | + | |
27139 | +aufs_bindex_t au_new_br_id(struct super_block *sb) | |
27140 | +{ | |
27141 | + aufs_bindex_t br_id; | |
27142 | + int i; | |
27143 | + struct au_sbinfo *sbinfo; | |
27144 | + | |
dece6358 AM |
27145 | + SiMustWriteLock(sb); |
27146 | + | |
1facf9fc | 27147 | + sbinfo = au_sbi(sb); |
27148 | + for (i = 0; i <= AUFS_BRANCH_MAX; i++) { | |
27149 | + br_id = ++sbinfo->si_last_br_id; | |
7f207e10 | 27150 | + AuDebugOn(br_id < 0); |
1facf9fc | 27151 | + if (br_id && au_br_index(sb, br_id) < 0) |
27152 | + return br_id; | |
27153 | + } | |
27154 | + | |
27155 | + return -1; | |
27156 | +} | |
27157 | + | |
27158 | +/* ---------------------------------------------------------------------- */ | |
27159 | + | |
e49829fe JR |
27160 | +/* it is ok that new 'nwt' tasks are appended while we are sleeping */ |
27161 | +int si_read_lock(struct super_block *sb, int flags) | |
27162 | +{ | |
27163 | + int err; | |
27164 | + | |
27165 | + err = 0; | |
27166 | + if (au_ftest_lock(flags, FLUSH)) | |
27167 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
27168 | + | |
27169 | + si_noflush_read_lock(sb); | |
27170 | + err = au_plink_maint(sb, flags); | |
27171 | + if (unlikely(err)) | |
27172 | + si_read_unlock(sb); | |
27173 | + | |
27174 | + return err; | |
27175 | +} | |
27176 | + | |
27177 | +int si_write_lock(struct super_block *sb, int flags) | |
27178 | +{ | |
27179 | + int err; | |
27180 | + | |
27181 | + if (au_ftest_lock(flags, FLUSH)) | |
27182 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
27183 | + | |
27184 | + si_noflush_write_lock(sb); | |
27185 | + err = au_plink_maint(sb, flags); | |
27186 | + if (unlikely(err)) | |
27187 | + si_write_unlock(sb); | |
27188 | + | |
27189 | + return err; | |
27190 | +} | |
27191 | + | |
1facf9fc | 27192 | +/* dentry and super_block lock. call at entry point */ |
e49829fe | 27193 | +int aufs_read_lock(struct dentry *dentry, int flags) |
1facf9fc | 27194 | +{ |
e49829fe | 27195 | + int err; |
027c5e7a | 27196 | + struct super_block *sb; |
e49829fe | 27197 | + |
027c5e7a AM |
27198 | + sb = dentry->d_sb; |
27199 | + err = si_read_lock(sb, flags); | |
27200 | + if (unlikely(err)) | |
27201 | + goto out; | |
27202 | + | |
27203 | + if (au_ftest_lock(flags, DW)) | |
27204 | + di_write_lock_child(dentry); | |
27205 | + else | |
27206 | + di_read_lock_child(dentry, flags); | |
27207 | + | |
27208 | + if (au_ftest_lock(flags, GEN)) { | |
27209 | + err = au_digen_test(dentry, au_sigen(sb)); | |
79b8bda9 AM |
27210 | + if (!au_opt_test(au_mntflags(sb), UDBA_NONE)) |
27211 | + AuDebugOn(!err && au_dbrange_test(dentry)); | |
27212 | + else if (!err) | |
27213 | + err = au_dbrange_test(dentry); | |
027c5e7a AM |
27214 | + if (unlikely(err)) |
27215 | + aufs_read_unlock(dentry, flags); | |
e49829fe JR |
27216 | + } |
27217 | + | |
027c5e7a | 27218 | +out: |
e49829fe | 27219 | + return err; |
1facf9fc | 27220 | +} |
27221 | + | |
27222 | +void aufs_read_unlock(struct dentry *dentry, int flags) | |
27223 | +{ | |
27224 | + if (au_ftest_lock(flags, DW)) | |
27225 | + di_write_unlock(dentry); | |
27226 | + else | |
27227 | + di_read_unlock(dentry, flags); | |
27228 | + si_read_unlock(dentry->d_sb); | |
27229 | +} | |
27230 | + | |
27231 | +void aufs_write_lock(struct dentry *dentry) | |
27232 | +{ | |
e49829fe | 27233 | + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW); |
1facf9fc | 27234 | + di_write_lock_child(dentry); |
27235 | +} | |
27236 | + | |
27237 | +void aufs_write_unlock(struct dentry *dentry) | |
27238 | +{ | |
27239 | + di_write_unlock(dentry); | |
27240 | + si_write_unlock(dentry->d_sb); | |
27241 | +} | |
27242 | + | |
e49829fe | 27243 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags) |
1facf9fc | 27244 | +{ |
e49829fe | 27245 | + int err; |
027c5e7a AM |
27246 | + unsigned int sigen; |
27247 | + struct super_block *sb; | |
e49829fe | 27248 | + |
027c5e7a AM |
27249 | + sb = d1->d_sb; |
27250 | + err = si_read_lock(sb, flags); | |
27251 | + if (unlikely(err)) | |
27252 | + goto out; | |
27253 | + | |
b95c5147 | 27254 | + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS)); |
027c5e7a AM |
27255 | + |
27256 | + if (au_ftest_lock(flags, GEN)) { | |
27257 | + sigen = au_sigen(sb); | |
27258 | + err = au_digen_test(d1, sigen); | |
27259 | + AuDebugOn(!err && au_dbrange_test(d1)); | |
27260 | + if (!err) { | |
27261 | + err = au_digen_test(d2, sigen); | |
27262 | + AuDebugOn(!err && au_dbrange_test(d2)); | |
27263 | + } | |
27264 | + if (unlikely(err)) | |
27265 | + aufs_read_and_write_unlock2(d1, d2); | |
27266 | + } | |
27267 | + | |
27268 | +out: | |
e49829fe | 27269 | + return err; |
1facf9fc | 27270 | +} |
27271 | + | |
27272 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2) | |
27273 | +{ | |
27274 | + di_write_unlock2(d1, d2); | |
27275 | + si_read_unlock(d1->d_sb); | |
27276 | +} | |
7f207e10 AM |
27277 | diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h |
27278 | --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 27279 | +++ linux/fs/aufs/spl.h 2017-05-06 22:16:52.781553511 +0200 |
f0c0a007 | 27280 | @@ -0,0 +1,113 @@ |
1facf9fc | 27281 | +/* |
a2654f78 | 27282 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 27283 | + * |
27284 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27285 | + * it under the terms of the GNU General Public License as published by | |
27286 | + * the Free Software Foundation; either version 2 of the License, or | |
27287 | + * (at your option) any later version. | |
dece6358 AM |
27288 | + * |
27289 | + * This program is distributed in the hope that it will be useful, | |
27290 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27291 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27292 | + * GNU General Public License for more details. | |
27293 | + * | |
27294 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27295 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27296 | + */ |
27297 | + | |
27298 | +/* | |
27299 | + * simple list protected by a spinlock | |
27300 | + */ | |
27301 | + | |
27302 | +#ifndef __AUFS_SPL_H__ | |
27303 | +#define __AUFS_SPL_H__ | |
27304 | + | |
27305 | +#ifdef __KERNEL__ | |
27306 | + | |
f0c0a007 | 27307 | +#if 0 |
1facf9fc | 27308 | +struct au_splhead { |
27309 | + spinlock_t spin; | |
27310 | + struct list_head head; | |
27311 | +}; | |
27312 | + | |
27313 | +static inline void au_spl_init(struct au_splhead *spl) | |
27314 | +{ | |
27315 | + spin_lock_init(&spl->spin); | |
27316 | + INIT_LIST_HEAD(&spl->head); | |
27317 | +} | |
27318 | + | |
27319 | +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl) | |
27320 | +{ | |
27321 | + spin_lock(&spl->spin); | |
27322 | + list_add(list, &spl->head); | |
27323 | + spin_unlock(&spl->spin); | |
27324 | +} | |
27325 | + | |
27326 | +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl) | |
27327 | +{ | |
27328 | + spin_lock(&spl->spin); | |
27329 | + list_del(list); | |
27330 | + spin_unlock(&spl->spin); | |
27331 | +} | |
27332 | + | |
4a4d8108 AM |
27333 | +static inline void au_spl_del_rcu(struct list_head *list, |
27334 | + struct au_splhead *spl) | |
27335 | +{ | |
27336 | + spin_lock(&spl->spin); | |
27337 | + list_del_rcu(list); | |
27338 | + spin_unlock(&spl->spin); | |
27339 | +} | |
f0c0a007 | 27340 | +#endif |
4a4d8108 | 27341 | + |
86dc4139 AM |
27342 | +/* ---------------------------------------------------------------------- */ |
27343 | + | |
27344 | +struct au_sphlhead { | |
27345 | + spinlock_t spin; | |
27346 | + struct hlist_head head; | |
27347 | +}; | |
27348 | + | |
27349 | +static inline void au_sphl_init(struct au_sphlhead *sphl) | |
27350 | +{ | |
27351 | + spin_lock_init(&sphl->spin); | |
27352 | + INIT_HLIST_HEAD(&sphl->head); | |
27353 | +} | |
27354 | + | |
27355 | +static inline void au_sphl_add(struct hlist_node *hlist, | |
27356 | + struct au_sphlhead *sphl) | |
27357 | +{ | |
27358 | + spin_lock(&sphl->spin); | |
27359 | + hlist_add_head(hlist, &sphl->head); | |
27360 | + spin_unlock(&sphl->spin); | |
27361 | +} | |
27362 | + | |
27363 | +static inline void au_sphl_del(struct hlist_node *hlist, | |
27364 | + struct au_sphlhead *sphl) | |
27365 | +{ | |
27366 | + spin_lock(&sphl->spin); | |
27367 | + hlist_del(hlist); | |
27368 | + spin_unlock(&sphl->spin); | |
27369 | +} | |
27370 | + | |
27371 | +static inline void au_sphl_del_rcu(struct hlist_node *hlist, | |
27372 | + struct au_sphlhead *sphl) | |
27373 | +{ | |
27374 | + spin_lock(&sphl->spin); | |
27375 | + hlist_del_rcu(hlist); | |
27376 | + spin_unlock(&sphl->spin); | |
27377 | +} | |
27378 | + | |
27379 | +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl) | |
27380 | +{ | |
27381 | + unsigned long cnt; | |
27382 | + struct hlist_node *pos; | |
27383 | + | |
27384 | + cnt = 0; | |
27385 | + spin_lock(&sphl->spin); | |
27386 | + hlist_for_each(pos, &sphl->head) | |
27387 | + cnt++; | |
27388 | + spin_unlock(&sphl->spin); | |
27389 | + return cnt; | |
27390 | +} | |
27391 | + | |
1facf9fc | 27392 | +#endif /* __KERNEL__ */ |
27393 | +#endif /* __AUFS_SPL_H__ */ | |
7f207e10 AM |
27394 | diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c |
27395 | --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 27396 | +++ linux/fs/aufs/super.c 2017-05-06 22:16:52.781553511 +0200 |
a2654f78 | 27397 | @@ -0,0 +1,1044 @@ |
1facf9fc | 27398 | +/* |
a2654f78 | 27399 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 27400 | + * |
27401 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27402 | + * it under the terms of the GNU General Public License as published by | |
27403 | + * the Free Software Foundation; either version 2 of the License, or | |
27404 | + * (at your option) any later version. | |
dece6358 AM |
27405 | + * |
27406 | + * This program is distributed in the hope that it will be useful, | |
27407 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27408 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27409 | + * GNU General Public License for more details. | |
27410 | + * | |
27411 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27412 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27413 | + */ |
27414 | + | |
27415 | +/* | |
27416 | + * mount and super_block operations | |
27417 | + */ | |
27418 | + | |
f6c5ef8b | 27419 | +#include <linux/mm.h> |
1facf9fc | 27420 | +#include <linux/seq_file.h> |
27421 | +#include <linux/statfs.h> | |
7f207e10 | 27422 | +#include <linux/vmalloc.h> |
1facf9fc | 27423 | +#include "aufs.h" |
27424 | + | |
27425 | +/* | |
27426 | + * super_operations | |
27427 | + */ | |
27428 | +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused) | |
27429 | +{ | |
27430 | + struct au_icntnr *c; | |
27431 | + | |
27432 | + c = au_cache_alloc_icntnr(); | |
27433 | + if (c) { | |
027c5e7a | 27434 | + au_icntnr_init(c); |
1facf9fc | 27435 | + c->vfs_inode.i_version = 1; /* sigen(sb); */ |
27436 | + c->iinfo.ii_hinode = NULL; | |
27437 | + return &c->vfs_inode; | |
27438 | + } | |
27439 | + return NULL; | |
27440 | +} | |
27441 | + | |
027c5e7a AM |
27442 | +static void aufs_destroy_inode_cb(struct rcu_head *head) |
27443 | +{ | |
27444 | + struct inode *inode = container_of(head, struct inode, i_rcu); | |
27445 | + | |
f0c0a007 | 27446 | + au_cache_dfree_icntnr(container_of(inode, struct au_icntnr, vfs_inode)); |
027c5e7a AM |
27447 | +} |
27448 | + | |
1facf9fc | 27449 | +static void aufs_destroy_inode(struct inode *inode) |
27450 | +{ | |
5afbbe0d AM |
27451 | + if (!au_is_bad_inode(inode)) |
27452 | + au_iinfo_fin(inode); | |
027c5e7a | 27453 | + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb); |
1facf9fc | 27454 | +} |
27455 | + | |
27456 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino) | |
27457 | +{ | |
27458 | + struct inode *inode; | |
27459 | + int err; | |
27460 | + | |
27461 | + inode = iget_locked(sb, ino); | |
27462 | + if (unlikely(!inode)) { | |
27463 | + inode = ERR_PTR(-ENOMEM); | |
27464 | + goto out; | |
27465 | + } | |
27466 | + if (!(inode->i_state & I_NEW)) | |
27467 | + goto out; | |
27468 | + | |
27469 | + err = au_xigen_new(inode); | |
27470 | + if (!err) | |
27471 | + err = au_iinfo_init(inode); | |
27472 | + if (!err) | |
27473 | + inode->i_version++; | |
27474 | + else { | |
27475 | + iget_failed(inode); | |
27476 | + inode = ERR_PTR(err); | |
27477 | + } | |
27478 | + | |
4f0767ce | 27479 | +out: |
1facf9fc | 27480 | + /* never return NULL */ |
27481 | + AuDebugOn(!inode); | |
27482 | + AuTraceErrPtr(inode); | |
27483 | + return inode; | |
27484 | +} | |
27485 | + | |
27486 | +/* lock free root dinfo */ | |
27487 | +static int au_show_brs(struct seq_file *seq, struct super_block *sb) | |
27488 | +{ | |
27489 | + int err; | |
5afbbe0d | 27490 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 27491 | + struct path path; |
4a4d8108 | 27492 | + struct au_hdentry *hdp; |
1facf9fc | 27493 | + struct au_branch *br; |
076b876e | 27494 | + au_br_perm_str_t perm; |
1facf9fc | 27495 | + |
27496 | + err = 0; | |
5afbbe0d AM |
27497 | + bbot = au_sbbot(sb); |
27498 | + bindex = 0; | |
27499 | + hdp = au_hdentry(au_di(sb->s_root), bindex); | |
27500 | + for (; !err && bindex <= bbot; bindex++, hdp++) { | |
1facf9fc | 27501 | + br = au_sbr(sb, bindex); |
86dc4139 | 27502 | + path.mnt = au_br_mnt(br); |
5afbbe0d | 27503 | + path.dentry = hdp->hd_dentry; |
1facf9fc | 27504 | + err = au_seq_path(seq, &path); |
79b8bda9 | 27505 | + if (!err) { |
076b876e | 27506 | + au_optstr_br_perm(&perm, br->br_perm); |
79b8bda9 | 27507 | + seq_printf(seq, "=%s", perm.a); |
5afbbe0d | 27508 | + if (bindex != bbot) |
79b8bda9 | 27509 | + seq_putc(seq, ':'); |
1e00d052 | 27510 | + } |
1facf9fc | 27511 | + } |
79b8bda9 AM |
27512 | + if (unlikely(err || seq_has_overflowed(seq))) |
27513 | + err = -E2BIG; | |
1facf9fc | 27514 | + |
27515 | + return err; | |
27516 | +} | |
27517 | + | |
f2c43d5f AM |
27518 | +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat, |
27519 | + const char *append) | |
27520 | +{ | |
27521 | + char *p; | |
27522 | + | |
27523 | + p = fmt; | |
27524 | + while (*pat != ':') | |
27525 | + *p++ = *pat++; | |
27526 | + *p++ = *pat++; | |
27527 | + strcpy(p, append); | |
27528 | + AuDebugOn(strlen(fmt) >= len); | |
27529 | +} | |
27530 | + | |
1facf9fc | 27531 | +static void au_show_wbr_create(struct seq_file *m, int v, |
27532 | + struct au_sbinfo *sbinfo) | |
27533 | +{ | |
27534 | + const char *pat; | |
f2c43d5f AM |
27535 | + char fmt[32]; |
27536 | + struct au_wbr_mfs *mfs; | |
1facf9fc | 27537 | + |
dece6358 AM |
27538 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
27539 | + | |
c2b27bf2 | 27540 | + seq_puts(m, ",create="); |
1facf9fc | 27541 | + pat = au_optstr_wbr_create(v); |
f2c43d5f | 27542 | + mfs = &sbinfo->si_wbr_mfs; |
1facf9fc | 27543 | + switch (v) { |
27544 | + case AuWbrCreate_TDP: | |
27545 | + case AuWbrCreate_RR: | |
27546 | + case AuWbrCreate_MFS: | |
27547 | + case AuWbrCreate_PMFS: | |
c2b27bf2 | 27548 | + seq_puts(m, pat); |
1facf9fc | 27549 | + break; |
f2c43d5f AM |
27550 | + case AuWbrCreate_MFSRR: |
27551 | + case AuWbrCreate_TDMFS: | |
27552 | + case AuWbrCreate_PMFSRR: | |
27553 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu"); | |
27554 | + seq_printf(m, fmt, mfs->mfsrr_watermark); | |
1facf9fc | 27555 | + break; |
f2c43d5f | 27556 | + case AuWbrCreate_MFSV: |
1facf9fc | 27557 | + case AuWbrCreate_PMFSV: |
f2c43d5f AM |
27558 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu"); |
27559 | + seq_printf(m, fmt, | |
27560 | + jiffies_to_msecs(mfs->mfs_expire) | |
e49829fe | 27561 | + / MSEC_PER_SEC); |
1facf9fc | 27562 | + break; |
1facf9fc | 27563 | + case AuWbrCreate_MFSRRV: |
f2c43d5f | 27564 | + case AuWbrCreate_TDMFSV: |
392086de | 27565 | + case AuWbrCreate_PMFSRRV: |
f2c43d5f AM |
27566 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu"); |
27567 | + seq_printf(m, fmt, mfs->mfsrr_watermark, | |
27568 | + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC); | |
392086de | 27569 | + break; |
f2c43d5f AM |
27570 | + default: |
27571 | + BUG(); | |
1facf9fc | 27572 | + } |
27573 | +} | |
27574 | + | |
7eafdf33 | 27575 | +static int au_show_xino(struct seq_file *seq, struct super_block *sb) |
1facf9fc | 27576 | +{ |
27577 | +#ifdef CONFIG_SYSFS | |
27578 | + return 0; | |
27579 | +#else | |
27580 | + int err; | |
27581 | + const int len = sizeof(AUFS_XINO_FNAME) - 1; | |
27582 | + aufs_bindex_t bindex, brid; | |
1facf9fc | 27583 | + struct qstr *name; |
27584 | + struct file *f; | |
27585 | + struct dentry *d, *h_root; | |
27586 | + | |
dece6358 AM |
27587 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
27588 | + | |
1facf9fc | 27589 | + err = 0; |
1facf9fc | 27590 | + f = au_sbi(sb)->si_xib; |
27591 | + if (!f) | |
27592 | + goto out; | |
27593 | + | |
27594 | + /* stop printing the default xino path on the first writable branch */ | |
27595 | + h_root = NULL; | |
27596 | + brid = au_xino_brid(sb); | |
27597 | + if (brid >= 0) { | |
27598 | + bindex = au_br_index(sb, brid); | |
5afbbe0d | 27599 | + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry; |
1facf9fc | 27600 | + } |
2000de60 | 27601 | + d = f->f_path.dentry; |
1facf9fc | 27602 | + name = &d->d_name; |
27603 | + /* safe ->d_parent because the file is unlinked */ | |
27604 | + if (d->d_parent == h_root | |
27605 | + && name->len == len | |
27606 | + && !memcmp(name->name, AUFS_XINO_FNAME, len)) | |
27607 | + goto out; | |
27608 | + | |
27609 | + seq_puts(seq, ",xino="); | |
27610 | + err = au_xino_path(seq, f); | |
27611 | + | |
4f0767ce | 27612 | +out: |
1facf9fc | 27613 | + return err; |
27614 | +#endif | |
27615 | +} | |
27616 | + | |
27617 | +/* seq_file will re-call me in case of too long string */ | |
7eafdf33 | 27618 | +static int aufs_show_options(struct seq_file *m, struct dentry *dentry) |
1facf9fc | 27619 | +{ |
027c5e7a | 27620 | + int err; |
1facf9fc | 27621 | + unsigned int mnt_flags, v; |
27622 | + struct super_block *sb; | |
27623 | + struct au_sbinfo *sbinfo; | |
27624 | + | |
27625 | +#define AuBool(name, str) do { \ | |
27626 | + v = au_opt_test(mnt_flags, name); \ | |
27627 | + if (v != au_opt_test(AuOpt_Def, name)) \ | |
27628 | + seq_printf(m, ",%s" #str, v ? "" : "no"); \ | |
27629 | +} while (0) | |
27630 | + | |
27631 | +#define AuStr(name, str) do { \ | |
27632 | + v = mnt_flags & AuOptMask_##name; \ | |
27633 | + if (v != (AuOpt_Def & AuOptMask_##name)) \ | |
27634 | + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \ | |
27635 | +} while (0) | |
27636 | + | |
27637 | +#define AuUInt(name, str, val) do { \ | |
27638 | + if (val != AUFS_##name##_DEF) \ | |
27639 | + seq_printf(m, "," #str "=%u", val); \ | |
27640 | +} while (0) | |
27641 | + | |
7eafdf33 | 27642 | + sb = dentry->d_sb; |
c1595e42 JR |
27643 | + if (sb->s_flags & MS_POSIXACL) |
27644 | + seq_puts(m, ",acl"); | |
27645 | + | |
27646 | + /* lock free root dinfo */ | |
1facf9fc | 27647 | + si_noflush_read_lock(sb); |
27648 | + sbinfo = au_sbi(sb); | |
27649 | + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo)); | |
27650 | + | |
27651 | + mnt_flags = au_mntflags(sb); | |
27652 | + if (au_opt_test(mnt_flags, XINO)) { | |
7eafdf33 | 27653 | + err = au_show_xino(m, sb); |
1facf9fc | 27654 | + if (unlikely(err)) |
27655 | + goto out; | |
27656 | + } else | |
27657 | + seq_puts(m, ",noxino"); | |
27658 | + | |
27659 | + AuBool(TRUNC_XINO, trunc_xino); | |
27660 | + AuStr(UDBA, udba); | |
dece6358 | 27661 | + AuBool(SHWH, shwh); |
1facf9fc | 27662 | + AuBool(PLINK, plink); |
4a4d8108 | 27663 | + AuBool(DIO, dio); |
076b876e | 27664 | + AuBool(DIRPERM1, dirperm1); |
1facf9fc | 27665 | + |
27666 | + v = sbinfo->si_wbr_create; | |
27667 | + if (v != AuWbrCreate_Def) | |
27668 | + au_show_wbr_create(m, v, sbinfo); | |
27669 | + | |
27670 | + v = sbinfo->si_wbr_copyup; | |
27671 | + if (v != AuWbrCopyup_Def) | |
27672 | + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v)); | |
27673 | + | |
27674 | + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ); | |
27675 | + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ)) | |
27676 | + seq_printf(m, ",diropq=%c", v ? 'a' : 'w'); | |
27677 | + | |
27678 | + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh); | |
27679 | + | |
027c5e7a AM |
27680 | + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC; |
27681 | + AuUInt(RDCACHE, rdcache, v); | |
1facf9fc | 27682 | + |
27683 | + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk); | |
27684 | + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash); | |
27685 | + | |
076b876e AM |
27686 | + au_fhsm_show(m, sbinfo); |
27687 | + | |
1facf9fc | 27688 | + AuBool(SUM, sum); |
27689 | + /* AuBool(SUM_W, wsum); */ | |
27690 | + AuBool(WARN_PERM, warn_perm); | |
27691 | + AuBool(VERBOSE, verbose); | |
27692 | + | |
4f0767ce | 27693 | +out: |
1facf9fc | 27694 | + /* be sure to print "br:" last */ |
27695 | + if (!sysaufs_brs) { | |
27696 | + seq_puts(m, ",br:"); | |
27697 | + au_show_brs(m, sb); | |
27698 | + } | |
27699 | + si_read_unlock(sb); | |
27700 | + return 0; | |
27701 | + | |
1facf9fc | 27702 | +#undef AuBool |
27703 | +#undef AuStr | |
4a4d8108 | 27704 | +#undef AuUInt |
1facf9fc | 27705 | +} |
27706 | + | |
27707 | +/* ---------------------------------------------------------------------- */ | |
27708 | + | |
27709 | +/* sum mode which returns the summation for statfs(2) */ | |
27710 | + | |
27711 | +static u64 au_add_till_max(u64 a, u64 b) | |
27712 | +{ | |
27713 | + u64 old; | |
27714 | + | |
27715 | + old = a; | |
27716 | + a += b; | |
92d182d2 AM |
27717 | + if (old <= a) |
27718 | + return a; | |
27719 | + return ULLONG_MAX; | |
27720 | +} | |
27721 | + | |
27722 | +static u64 au_mul_till_max(u64 a, long mul) | |
27723 | +{ | |
27724 | + u64 old; | |
27725 | + | |
27726 | + old = a; | |
27727 | + a *= mul; | |
27728 | + if (old <= a) | |
1facf9fc | 27729 | + return a; |
27730 | + return ULLONG_MAX; | |
27731 | +} | |
27732 | + | |
27733 | +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf) | |
27734 | +{ | |
27735 | + int err; | |
92d182d2 | 27736 | + long bsize, factor; |
1facf9fc | 27737 | + u64 blocks, bfree, bavail, files, ffree; |
5afbbe0d | 27738 | + aufs_bindex_t bbot, bindex, i; |
1facf9fc | 27739 | + unsigned char shared; |
7f207e10 | 27740 | + struct path h_path; |
1facf9fc | 27741 | + struct super_block *h_sb; |
27742 | + | |
92d182d2 AM |
27743 | + err = 0; |
27744 | + bsize = LONG_MAX; | |
27745 | + files = 0; | |
27746 | + ffree = 0; | |
1facf9fc | 27747 | + blocks = 0; |
27748 | + bfree = 0; | |
27749 | + bavail = 0; | |
5afbbe0d AM |
27750 | + bbot = au_sbbot(sb); |
27751 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
7f207e10 AM |
27752 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
27753 | + h_sb = h_path.mnt->mnt_sb; | |
1facf9fc | 27754 | + shared = 0; |
92d182d2 | 27755 | + for (i = 0; !shared && i < bindex; i++) |
1facf9fc | 27756 | + shared = (au_sbr_sb(sb, i) == h_sb); |
27757 | + if (shared) | |
27758 | + continue; | |
27759 | + | |
27760 | + /* sb->s_root for NFS is unreliable */ | |
7f207e10 AM |
27761 | + h_path.dentry = h_path.mnt->mnt_root; |
27762 | + err = vfs_statfs(&h_path, buf); | |
1facf9fc | 27763 | + if (unlikely(err)) |
27764 | + goto out; | |
27765 | + | |
92d182d2 AM |
27766 | + if (bsize > buf->f_bsize) { |
27767 | + /* | |
27768 | + * we will reduce bsize, so we have to expand blocks | |
27769 | + * etc. to match them again | |
27770 | + */ | |
27771 | + factor = (bsize / buf->f_bsize); | |
27772 | + blocks = au_mul_till_max(blocks, factor); | |
27773 | + bfree = au_mul_till_max(bfree, factor); | |
27774 | + bavail = au_mul_till_max(bavail, factor); | |
27775 | + bsize = buf->f_bsize; | |
27776 | + } | |
27777 | + | |
27778 | + factor = (buf->f_bsize / bsize); | |
27779 | + blocks = au_add_till_max(blocks, | |
27780 | + au_mul_till_max(buf->f_blocks, factor)); | |
27781 | + bfree = au_add_till_max(bfree, | |
27782 | + au_mul_till_max(buf->f_bfree, factor)); | |
27783 | + bavail = au_add_till_max(bavail, | |
27784 | + au_mul_till_max(buf->f_bavail, factor)); | |
1facf9fc | 27785 | + files = au_add_till_max(files, buf->f_files); |
27786 | + ffree = au_add_till_max(ffree, buf->f_ffree); | |
27787 | + } | |
27788 | + | |
92d182d2 | 27789 | + buf->f_bsize = bsize; |
1facf9fc | 27790 | + buf->f_blocks = blocks; |
27791 | + buf->f_bfree = bfree; | |
27792 | + buf->f_bavail = bavail; | |
27793 | + buf->f_files = files; | |
27794 | + buf->f_ffree = ffree; | |
92d182d2 | 27795 | + buf->f_frsize = 0; |
1facf9fc | 27796 | + |
4f0767ce | 27797 | +out: |
1facf9fc | 27798 | + return err; |
27799 | +} | |
27800 | + | |
27801 | +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf) | |
27802 | +{ | |
27803 | + int err; | |
7f207e10 | 27804 | + struct path h_path; |
1facf9fc | 27805 | + struct super_block *sb; |
27806 | + | |
27807 | + /* lock free root dinfo */ | |
27808 | + sb = dentry->d_sb; | |
27809 | + si_noflush_read_lock(sb); | |
7f207e10 | 27810 | + if (!au_opt_test(au_mntflags(sb), SUM)) { |
1facf9fc | 27811 | + /* sb->s_root for NFS is unreliable */ |
7f207e10 AM |
27812 | + h_path.mnt = au_sbr_mnt(sb, 0); |
27813 | + h_path.dentry = h_path.mnt->mnt_root; | |
27814 | + err = vfs_statfs(&h_path, buf); | |
27815 | + } else | |
1facf9fc | 27816 | + err = au_statfs_sum(sb, buf); |
27817 | + si_read_unlock(sb); | |
27818 | + | |
27819 | + if (!err) { | |
27820 | + buf->f_type = AUFS_SUPER_MAGIC; | |
4a4d8108 | 27821 | + buf->f_namelen = AUFS_MAX_NAMELEN; |
1facf9fc | 27822 | + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid)); |
27823 | + } | |
27824 | + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */ | |
27825 | + | |
27826 | + return err; | |
27827 | +} | |
27828 | + | |
27829 | +/* ---------------------------------------------------------------------- */ | |
27830 | + | |
537831f9 AM |
27831 | +static int aufs_sync_fs(struct super_block *sb, int wait) |
27832 | +{ | |
27833 | + int err, e; | |
5afbbe0d | 27834 | + aufs_bindex_t bbot, bindex; |
537831f9 AM |
27835 | + struct au_branch *br; |
27836 | + struct super_block *h_sb; | |
27837 | + | |
27838 | + err = 0; | |
27839 | + si_noflush_read_lock(sb); | |
5afbbe0d AM |
27840 | + bbot = au_sbbot(sb); |
27841 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
537831f9 AM |
27842 | + br = au_sbr(sb, bindex); |
27843 | + if (!au_br_writable(br->br_perm)) | |
27844 | + continue; | |
27845 | + | |
27846 | + h_sb = au_sbr_sb(sb, bindex); | |
a2654f78 AM |
27847 | + e = vfsub_sync_filesystem(h_sb, wait); |
27848 | + if (unlikely(e && !err)) | |
27849 | + err = e; | |
27850 | + /* go on even if an error happens */ | |
537831f9 AM |
27851 | + } |
27852 | + si_read_unlock(sb); | |
27853 | + | |
27854 | + return err; | |
27855 | +} | |
27856 | + | |
27857 | +/* ---------------------------------------------------------------------- */ | |
27858 | + | |
1facf9fc | 27859 | +/* final actions when unmounting a file system */ |
27860 | +static void aufs_put_super(struct super_block *sb) | |
27861 | +{ | |
27862 | + struct au_sbinfo *sbinfo; | |
27863 | + | |
27864 | + sbinfo = au_sbi(sb); | |
27865 | + if (!sbinfo) | |
27866 | + return; | |
27867 | + | |
1facf9fc | 27868 | + dbgaufs_si_fin(sbinfo); |
27869 | + kobject_put(&sbinfo->si_kobj); | |
27870 | +} | |
27871 | + | |
27872 | +/* ---------------------------------------------------------------------- */ | |
27873 | + | |
79b8bda9 AM |
27874 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, |
27875 | + struct super_block *sb, void *arg) | |
7f207e10 AM |
27876 | +{ |
27877 | + void *array; | |
076b876e | 27878 | + unsigned long long n, sz; |
7f207e10 AM |
27879 | + |
27880 | + array = NULL; | |
27881 | + n = 0; | |
27882 | + if (!*hint) | |
27883 | + goto out; | |
27884 | + | |
27885 | + if (*hint > ULLONG_MAX / sizeof(array)) { | |
27886 | + array = ERR_PTR(-EMFILE); | |
27887 | + pr_err("hint %llu\n", *hint); | |
27888 | + goto out; | |
27889 | + } | |
27890 | + | |
076b876e AM |
27891 | + sz = sizeof(array) * *hint; |
27892 | + array = kzalloc(sz, GFP_NOFS); | |
7f207e10 | 27893 | + if (unlikely(!array)) |
076b876e | 27894 | + array = vzalloc(sz); |
7f207e10 AM |
27895 | + if (unlikely(!array)) { |
27896 | + array = ERR_PTR(-ENOMEM); | |
27897 | + goto out; | |
27898 | + } | |
27899 | + | |
79b8bda9 | 27900 | + n = cb(sb, array, *hint, arg); |
7f207e10 AM |
27901 | + AuDebugOn(n > *hint); |
27902 | + | |
27903 | +out: | |
27904 | + *hint = n; | |
27905 | + return array; | |
27906 | +} | |
27907 | + | |
79b8bda9 | 27908 | +static unsigned long long au_iarray_cb(struct super_block *sb, void *a, |
7f207e10 AM |
27909 | + unsigned long long max __maybe_unused, |
27910 | + void *arg) | |
27911 | +{ | |
27912 | + unsigned long long n; | |
27913 | + struct inode **p, *inode; | |
27914 | + struct list_head *head; | |
27915 | + | |
27916 | + n = 0; | |
27917 | + p = a; | |
27918 | + head = arg; | |
79b8bda9 | 27919 | + spin_lock(&sb->s_inode_list_lock); |
7f207e10 | 27920 | + list_for_each_entry(inode, head, i_sb_list) { |
5afbbe0d AM |
27921 | + if (!au_is_bad_inode(inode) |
27922 | + && au_ii(inode)->ii_btop >= 0) { | |
2cbb1c4b JR |
27923 | + spin_lock(&inode->i_lock); |
27924 | + if (atomic_read(&inode->i_count)) { | |
27925 | + au_igrab(inode); | |
27926 | + *p++ = inode; | |
27927 | + n++; | |
27928 | + AuDebugOn(n > max); | |
27929 | + } | |
27930 | + spin_unlock(&inode->i_lock); | |
7f207e10 AM |
27931 | + } |
27932 | + } | |
79b8bda9 | 27933 | + spin_unlock(&sb->s_inode_list_lock); |
7f207e10 AM |
27934 | + |
27935 | + return n; | |
27936 | +} | |
27937 | + | |
27938 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max) | |
27939 | +{ | |
5afbbe0d | 27940 | + *max = au_ninodes(sb); |
79b8bda9 | 27941 | + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes); |
7f207e10 AM |
27942 | +} |
27943 | + | |
27944 | +void au_iarray_free(struct inode **a, unsigned long long max) | |
27945 | +{ | |
27946 | + unsigned long long ull; | |
27947 | + | |
27948 | + for (ull = 0; ull < max; ull++) | |
27949 | + iput(a[ull]); | |
be52b249 | 27950 | + kvfree(a); |
7f207e10 AM |
27951 | +} |
27952 | + | |
27953 | +/* ---------------------------------------------------------------------- */ | |
27954 | + | |
1facf9fc | 27955 | +/* |
27956 | + * refresh dentry and inode at remount time. | |
27957 | + */ | |
027c5e7a AM |
27958 | +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */ |
27959 | +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags, | |
27960 | + struct dentry *parent) | |
1facf9fc | 27961 | +{ |
27962 | + int err; | |
1facf9fc | 27963 | + |
27964 | + di_write_lock_child(dentry); | |
1facf9fc | 27965 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a AM |
27966 | + err = au_refresh_dentry(dentry, parent); |
27967 | + if (!err && dir_flags) | |
5527c038 | 27968 | + au_hn_reset(d_inode(dentry), dir_flags); |
1facf9fc | 27969 | + di_read_unlock(parent, AuLock_IR); |
1facf9fc | 27970 | + di_write_unlock(dentry); |
27971 | + | |
27972 | + return err; | |
27973 | +} | |
27974 | + | |
027c5e7a AM |
27975 | +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen, |
27976 | + struct au_sbinfo *sbinfo, | |
b95c5147 | 27977 | + const unsigned int dir_flags, unsigned int do_idop) |
1facf9fc | 27978 | +{ |
027c5e7a AM |
27979 | + int err; |
27980 | + struct dentry *parent; | |
027c5e7a AM |
27981 | + |
27982 | + err = 0; | |
27983 | + parent = dget_parent(dentry); | |
27984 | + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) { | |
5527c038 JR |
27985 | + if (d_really_is_positive(dentry)) { |
27986 | + if (!d_is_dir(dentry)) | |
027c5e7a AM |
27987 | + err = au_do_refresh(dentry, /*dir_flags*/0, |
27988 | + parent); | |
27989 | + else { | |
27990 | + err = au_do_refresh(dentry, dir_flags, parent); | |
27991 | + if (unlikely(err)) | |
27992 | + au_fset_si(sbinfo, FAILED_REFRESH_DIR); | |
27993 | + } | |
27994 | + } else | |
27995 | + err = au_do_refresh(dentry, /*dir_flags*/0, parent); | |
27996 | + AuDbgDentry(dentry); | |
27997 | + } | |
27998 | + dput(parent); | |
27999 | + | |
79b8bda9 | 28000 | + if (!err) { |
b95c5147 | 28001 | + if (do_idop) |
79b8bda9 AM |
28002 | + au_refresh_dop(dentry, /*force_reval*/0); |
28003 | + } else | |
28004 | + au_refresh_dop(dentry, /*force_reval*/1); | |
28005 | + | |
027c5e7a AM |
28006 | + AuTraceErr(err); |
28007 | + return err; | |
1facf9fc | 28008 | +} |
28009 | + | |
b95c5147 | 28010 | +static int au_refresh_d(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 28011 | +{ |
28012 | + int err, i, j, ndentry, e; | |
027c5e7a | 28013 | + unsigned int sigen; |
1facf9fc | 28014 | + struct au_dcsub_pages dpages; |
28015 | + struct au_dpage *dpage; | |
027c5e7a AM |
28016 | + struct dentry **dentries, *d; |
28017 | + struct au_sbinfo *sbinfo; | |
28018 | + struct dentry *root = sb->s_root; | |
5527c038 | 28019 | + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1); |
1facf9fc | 28020 | + |
b95c5147 | 28021 | + if (do_idop) |
79b8bda9 AM |
28022 | + au_refresh_dop(root, /*force_reval*/0); |
28023 | + | |
027c5e7a AM |
28024 | + err = au_dpages_init(&dpages, GFP_NOFS); |
28025 | + if (unlikely(err)) | |
1facf9fc | 28026 | + goto out; |
027c5e7a AM |
28027 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); |
28028 | + if (unlikely(err)) | |
1facf9fc | 28029 | + goto out_dpages; |
1facf9fc | 28030 | + |
027c5e7a AM |
28031 | + sigen = au_sigen(sb); |
28032 | + sbinfo = au_sbi(sb); | |
28033 | + for (i = 0; i < dpages.ndpage; i++) { | |
1facf9fc | 28034 | + dpage = dpages.dpages + i; |
28035 | + dentries = dpage->dentries; | |
28036 | + ndentry = dpage->ndentry; | |
027c5e7a | 28037 | + for (j = 0; j < ndentry; j++) { |
1facf9fc | 28038 | + d = dentries[j]; |
79b8bda9 | 28039 | + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags, |
b95c5147 | 28040 | + do_idop); |
027c5e7a AM |
28041 | + if (unlikely(e && !err)) |
28042 | + err = e; | |
28043 | + /* go on even err */ | |
1facf9fc | 28044 | + } |
28045 | + } | |
28046 | + | |
4f0767ce | 28047 | +out_dpages: |
1facf9fc | 28048 | + au_dpages_free(&dpages); |
4f0767ce | 28049 | +out: |
1facf9fc | 28050 | + return err; |
28051 | +} | |
28052 | + | |
b95c5147 | 28053 | +static int au_refresh_i(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 28054 | +{ |
027c5e7a AM |
28055 | + int err, e; |
28056 | + unsigned int sigen; | |
28057 | + unsigned long long max, ull; | |
28058 | + struct inode *inode, **array; | |
1facf9fc | 28059 | + |
027c5e7a AM |
28060 | + array = au_iarray_alloc(sb, &max); |
28061 | + err = PTR_ERR(array); | |
28062 | + if (IS_ERR(array)) | |
28063 | + goto out; | |
1facf9fc | 28064 | + |
28065 | + err = 0; | |
027c5e7a AM |
28066 | + sigen = au_sigen(sb); |
28067 | + for (ull = 0; ull < max; ull++) { | |
28068 | + inode = array[ull]; | |
076b876e AM |
28069 | + if (unlikely(!inode)) |
28070 | + break; | |
b95c5147 AM |
28071 | + |
28072 | + e = 0; | |
28073 | + ii_write_lock_child(inode); | |
537831f9 | 28074 | + if (au_iigen(inode, NULL) != sigen) { |
027c5e7a | 28075 | + e = au_refresh_hinode_self(inode); |
1facf9fc | 28076 | + if (unlikely(e)) { |
b95c5147 | 28077 | + au_refresh_iop(inode, /*force_getattr*/1); |
027c5e7a | 28078 | + pr_err("error %d, i%lu\n", e, inode->i_ino); |
1facf9fc | 28079 | + if (!err) |
28080 | + err = e; | |
28081 | + /* go on even if err */ | |
28082 | + } | |
28083 | + } | |
b95c5147 AM |
28084 | + if (!e && do_idop) |
28085 | + au_refresh_iop(inode, /*force_getattr*/0); | |
28086 | + ii_write_unlock(inode); | |
1facf9fc | 28087 | + } |
28088 | + | |
027c5e7a | 28089 | + au_iarray_free(array, max); |
1facf9fc | 28090 | + |
4f0767ce | 28091 | +out: |
1facf9fc | 28092 | + return err; |
28093 | +} | |
28094 | + | |
b95c5147 | 28095 | +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 28096 | +{ |
027c5e7a AM |
28097 | + int err, e; |
28098 | + unsigned int udba; | |
5afbbe0d | 28099 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 28100 | + struct dentry *root; |
28101 | + struct inode *inode; | |
027c5e7a | 28102 | + struct au_branch *br; |
79b8bda9 | 28103 | + struct au_sbinfo *sbi; |
1facf9fc | 28104 | + |
28105 | + au_sigen_inc(sb); | |
79b8bda9 AM |
28106 | + sbi = au_sbi(sb); |
28107 | + au_fclr_si(sbi, FAILED_REFRESH_DIR); | |
1facf9fc | 28108 | + |
28109 | + root = sb->s_root; | |
28110 | + DiMustNoWaiters(root); | |
5527c038 | 28111 | + inode = d_inode(root); |
1facf9fc | 28112 | + IiMustNoWaiters(inode); |
1facf9fc | 28113 | + |
027c5e7a | 28114 | + udba = au_opt_udba(sb); |
5afbbe0d AM |
28115 | + bbot = au_sbbot(sb); |
28116 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
027c5e7a AM |
28117 | + br = au_sbr(sb, bindex); |
28118 | + err = au_hnotify_reset_br(udba, br, br->br_perm); | |
1facf9fc | 28119 | + if (unlikely(err)) |
027c5e7a AM |
28120 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", |
28121 | + bindex, err); | |
28122 | + /* go on even if err */ | |
1facf9fc | 28123 | + } |
027c5e7a | 28124 | + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1)); |
1facf9fc | 28125 | + |
b95c5147 | 28126 | + if (do_idop) { |
79b8bda9 AM |
28127 | + if (au_ftest_si(sbi, NO_DREVAL)) { |
28128 | + AuDebugOn(sb->s_d_op == &aufs_dop_noreval); | |
28129 | + sb->s_d_op = &aufs_dop_noreval; | |
b95c5147 AM |
28130 | + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr); |
28131 | + sbi->si_iop_array = aufs_iop_nogetattr; | |
79b8bda9 AM |
28132 | + } else { |
28133 | + AuDebugOn(sb->s_d_op == &aufs_dop); | |
28134 | + sb->s_d_op = &aufs_dop; | |
b95c5147 AM |
28135 | + AuDebugOn(sbi->si_iop_array == aufs_iop); |
28136 | + sbi->si_iop_array = aufs_iop; | |
79b8bda9 | 28137 | + } |
b95c5147 AM |
28138 | + pr_info("reset to %pf and %pf\n", |
28139 | + sb->s_d_op, sbi->si_iop_array); | |
79b8bda9 AM |
28140 | + } |
28141 | + | |
027c5e7a | 28142 | + di_write_unlock(root); |
b95c5147 AM |
28143 | + err = au_refresh_d(sb, do_idop); |
28144 | + e = au_refresh_i(sb, do_idop); | |
027c5e7a AM |
28145 | + if (unlikely(e && !err)) |
28146 | + err = e; | |
1facf9fc | 28147 | + /* aufs_write_lock() calls ..._child() */ |
28148 | + di_write_lock_child(root); | |
027c5e7a AM |
28149 | + |
28150 | + au_cpup_attr_all(inode, /*force*/1); | |
28151 | + | |
28152 | + if (unlikely(err)) | |
28153 | + AuIOErr("refresh failed, ignored, %d\n", err); | |
1facf9fc | 28154 | +} |
28155 | + | |
28156 | +/* stop extra interpretation of errno in mount(8), and strange error messages */ | |
28157 | +static int cvt_err(int err) | |
28158 | +{ | |
28159 | + AuTraceErr(err); | |
28160 | + | |
28161 | + switch (err) { | |
28162 | + case -ENOENT: | |
28163 | + case -ENOTDIR: | |
28164 | + case -EEXIST: | |
28165 | + case -EIO: | |
28166 | + err = -EINVAL; | |
28167 | + } | |
28168 | + return err; | |
28169 | +} | |
28170 | + | |
28171 | +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data) | |
28172 | +{ | |
4a4d8108 AM |
28173 | + int err, do_dx; |
28174 | + unsigned int mntflags; | |
be52b249 AM |
28175 | + struct au_opts opts = { |
28176 | + .opt = NULL | |
28177 | + }; | |
1facf9fc | 28178 | + struct dentry *root; |
28179 | + struct inode *inode; | |
28180 | + struct au_sbinfo *sbinfo; | |
28181 | + | |
28182 | + err = 0; | |
28183 | + root = sb->s_root; | |
28184 | + if (!data || !*data) { | |
e49829fe JR |
28185 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
28186 | + if (!err) { | |
28187 | + di_write_lock_child(root); | |
28188 | + err = au_opts_verify(sb, *flags, /*pending*/0); | |
28189 | + aufs_write_unlock(root); | |
28190 | + } | |
1facf9fc | 28191 | + goto out; |
28192 | + } | |
28193 | + | |
28194 | + err = -ENOMEM; | |
1facf9fc | 28195 | + opts.opt = (void *)__get_free_page(GFP_NOFS); |
28196 | + if (unlikely(!opts.opt)) | |
28197 | + goto out; | |
28198 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
28199 | + opts.flags = AuOpts_REMOUNT; | |
28200 | + opts.sb_flags = *flags; | |
28201 | + | |
28202 | + /* parse it before aufs lock */ | |
28203 | + err = au_opts_parse(sb, data, &opts); | |
28204 | + if (unlikely(err)) | |
28205 | + goto out_opts; | |
28206 | + | |
28207 | + sbinfo = au_sbi(sb); | |
5527c038 | 28208 | + inode = d_inode(root); |
febd17d6 | 28209 | + inode_lock(inode); |
e49829fe JR |
28210 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
28211 | + if (unlikely(err)) | |
28212 | + goto out_mtx; | |
28213 | + di_write_lock_child(root); | |
1facf9fc | 28214 | + |
28215 | + /* au_opts_remount() may return an error */ | |
28216 | + err = au_opts_remount(sb, &opts); | |
28217 | + au_opts_free(&opts); | |
28218 | + | |
027c5e7a | 28219 | + if (au_ftest_opts(opts.flags, REFRESH)) |
b95c5147 | 28220 | + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP)); |
1facf9fc | 28221 | + |
4a4d8108 AM |
28222 | + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) { |
28223 | + mntflags = au_mntflags(sb); | |
28224 | + do_dx = !!au_opt_test(mntflags, DIO); | |
28225 | + au_dy_arefresh(do_dx); | |
28226 | + } | |
28227 | + | |
076b876e | 28228 | + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */ |
1facf9fc | 28229 | + aufs_write_unlock(root); |
953406b4 | 28230 | + |
e49829fe | 28231 | +out_mtx: |
febd17d6 | 28232 | + inode_unlock(inode); |
4f0767ce | 28233 | +out_opts: |
f0c0a007 | 28234 | + au_delayed_free_page((unsigned long)opts.opt); |
4f0767ce | 28235 | +out: |
1facf9fc | 28236 | + err = cvt_err(err); |
28237 | + AuTraceErr(err); | |
28238 | + return err; | |
28239 | +} | |
28240 | + | |
4a4d8108 | 28241 | +static const struct super_operations aufs_sop = { |
1facf9fc | 28242 | + .alloc_inode = aufs_alloc_inode, |
28243 | + .destroy_inode = aufs_destroy_inode, | |
b752ccd1 | 28244 | + /* always deleting, no clearing */ |
1facf9fc | 28245 | + .drop_inode = generic_delete_inode, |
28246 | + .show_options = aufs_show_options, | |
28247 | + .statfs = aufs_statfs, | |
28248 | + .put_super = aufs_put_super, | |
537831f9 | 28249 | + .sync_fs = aufs_sync_fs, |
1facf9fc | 28250 | + .remount_fs = aufs_remount_fs |
28251 | +}; | |
28252 | + | |
28253 | +/* ---------------------------------------------------------------------- */ | |
28254 | + | |
28255 | +static int alloc_root(struct super_block *sb) | |
28256 | +{ | |
28257 | + int err; | |
28258 | + struct inode *inode; | |
28259 | + struct dentry *root; | |
28260 | + | |
28261 | + err = -ENOMEM; | |
28262 | + inode = au_iget_locked(sb, AUFS_ROOT_INO); | |
28263 | + err = PTR_ERR(inode); | |
28264 | + if (IS_ERR(inode)) | |
28265 | + goto out; | |
28266 | + | |
b95c5147 | 28267 | + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */ |
1facf9fc | 28268 | + inode->i_fop = &aufs_dir_fop; |
28269 | + inode->i_mode = S_IFDIR; | |
9dbd164d | 28270 | + set_nlink(inode, 2); |
1facf9fc | 28271 | + unlock_new_inode(inode); |
28272 | + | |
92d182d2 | 28273 | + root = d_make_root(inode); |
1facf9fc | 28274 | + if (unlikely(!root)) |
92d182d2 | 28275 | + goto out; |
1facf9fc | 28276 | + err = PTR_ERR(root); |
28277 | + if (IS_ERR(root)) | |
92d182d2 | 28278 | + goto out; |
1facf9fc | 28279 | + |
4a4d8108 | 28280 | + err = au_di_init(root); |
1facf9fc | 28281 | + if (!err) { |
28282 | + sb->s_root = root; | |
28283 | + return 0; /* success */ | |
28284 | + } | |
28285 | + dput(root); | |
1facf9fc | 28286 | + |
4f0767ce | 28287 | +out: |
1facf9fc | 28288 | + return err; |
1facf9fc | 28289 | +} |
28290 | + | |
28291 | +static int aufs_fill_super(struct super_block *sb, void *raw_data, | |
28292 | + int silent __maybe_unused) | |
28293 | +{ | |
28294 | + int err; | |
be52b249 AM |
28295 | + struct au_opts opts = { |
28296 | + .opt = NULL | |
28297 | + }; | |
79b8bda9 | 28298 | + struct au_sbinfo *sbinfo; |
1facf9fc | 28299 | + struct dentry *root; |
28300 | + struct inode *inode; | |
28301 | + char *arg = raw_data; | |
28302 | + | |
28303 | + if (unlikely(!arg || !*arg)) { | |
28304 | + err = -EINVAL; | |
4a4d8108 | 28305 | + pr_err("no arg\n"); |
1facf9fc | 28306 | + goto out; |
28307 | + } | |
28308 | + | |
28309 | + err = -ENOMEM; | |
1facf9fc | 28310 | + opts.opt = (void *)__get_free_page(GFP_NOFS); |
28311 | + if (unlikely(!opts.opt)) | |
28312 | + goto out; | |
28313 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
28314 | + opts.sb_flags = sb->s_flags; | |
28315 | + | |
28316 | + err = au_si_alloc(sb); | |
28317 | + if (unlikely(err)) | |
28318 | + goto out_opts; | |
79b8bda9 | 28319 | + sbinfo = au_sbi(sb); |
1facf9fc | 28320 | + |
28321 | + /* all timestamps always follow the ones on the branch */ | |
28322 | + sb->s_flags |= MS_NOATIME | MS_NODIRATIME; | |
28323 | + sb->s_op = &aufs_sop; | |
027c5e7a | 28324 | + sb->s_d_op = &aufs_dop; |
1facf9fc | 28325 | + sb->s_magic = AUFS_SUPER_MAGIC; |
28326 | + sb->s_maxbytes = 0; | |
c1595e42 | 28327 | + sb->s_stack_depth = 1; |
1facf9fc | 28328 | + au_export_init(sb); |
f2c43d5f | 28329 | + au_xattr_init(sb); |
1facf9fc | 28330 | + |
28331 | + err = alloc_root(sb); | |
28332 | + if (unlikely(err)) { | |
28333 | + si_write_unlock(sb); | |
28334 | + goto out_info; | |
28335 | + } | |
28336 | + root = sb->s_root; | |
5527c038 | 28337 | + inode = d_inode(root); |
1facf9fc | 28338 | + |
28339 | + /* | |
28340 | + * actually we can parse options regardless aufs lock here. | |
28341 | + * but at remount time, parsing must be done before aufs lock. | |
28342 | + * so we follow the same rule. | |
28343 | + */ | |
28344 | + ii_write_lock_parent(inode); | |
28345 | + aufs_write_unlock(root); | |
28346 | + err = au_opts_parse(sb, arg, &opts); | |
28347 | + if (unlikely(err)) | |
28348 | + goto out_root; | |
28349 | + | |
28350 | + /* lock vfs_inode first, then aufs. */ | |
febd17d6 | 28351 | + inode_lock(inode); |
1facf9fc | 28352 | + aufs_write_lock(root); |
28353 | + err = au_opts_mount(sb, &opts); | |
28354 | + au_opts_free(&opts); | |
79b8bda9 AM |
28355 | + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) { |
28356 | + sb->s_d_op = &aufs_dop_noreval; | |
28357 | + pr_info("%pf\n", sb->s_d_op); | |
28358 | + au_refresh_dop(root, /*force_reval*/0); | |
b95c5147 AM |
28359 | + sbinfo->si_iop_array = aufs_iop_nogetattr; |
28360 | + au_refresh_iop(inode, /*force_getattr*/0); | |
79b8bda9 | 28361 | + } |
1facf9fc | 28362 | + aufs_write_unlock(root); |
febd17d6 | 28363 | + inode_unlock(inode); |
4a4d8108 AM |
28364 | + if (!err) |
28365 | + goto out_opts; /* success */ | |
1facf9fc | 28366 | + |
4f0767ce | 28367 | +out_root: |
1facf9fc | 28368 | + dput(root); |
28369 | + sb->s_root = NULL; | |
4f0767ce | 28370 | +out_info: |
79b8bda9 AM |
28371 | + dbgaufs_si_fin(sbinfo); |
28372 | + kobject_put(&sbinfo->si_kobj); | |
1facf9fc | 28373 | + sb->s_fs_info = NULL; |
4f0767ce | 28374 | +out_opts: |
f0c0a007 | 28375 | + au_delayed_free_page((unsigned long)opts.opt); |
4f0767ce | 28376 | +out: |
1facf9fc | 28377 | + AuTraceErr(err); |
28378 | + err = cvt_err(err); | |
28379 | + AuTraceErr(err); | |
28380 | + return err; | |
28381 | +} | |
28382 | + | |
28383 | +/* ---------------------------------------------------------------------- */ | |
28384 | + | |
027c5e7a AM |
28385 | +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags, |
28386 | + const char *dev_name __maybe_unused, | |
28387 | + void *raw_data) | |
1facf9fc | 28388 | +{ |
027c5e7a | 28389 | + struct dentry *root; |
1facf9fc | 28390 | + struct super_block *sb; |
28391 | + | |
28392 | + /* all timestamps always follow the ones on the branch */ | |
28393 | + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */ | |
027c5e7a AM |
28394 | + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super); |
28395 | + if (IS_ERR(root)) | |
28396 | + goto out; | |
28397 | + | |
28398 | + sb = root->d_sb; | |
28399 | + si_write_lock(sb, !AuLock_FLUSH); | |
28400 | + sysaufs_brs_add(sb, 0); | |
28401 | + si_write_unlock(sb); | |
28402 | + au_sbilist_add(sb); | |
28403 | + | |
28404 | +out: | |
28405 | + return root; | |
1facf9fc | 28406 | +} |
28407 | + | |
e49829fe JR |
28408 | +static void aufs_kill_sb(struct super_block *sb) |
28409 | +{ | |
28410 | + struct au_sbinfo *sbinfo; | |
28411 | + | |
28412 | + sbinfo = au_sbi(sb); | |
28413 | + if (sbinfo) { | |
28414 | + au_sbilist_del(sb); | |
28415 | + aufs_write_lock(sb->s_root); | |
076b876e | 28416 | + au_fhsm_fin(sb); |
e49829fe JR |
28417 | + if (sbinfo->si_wbr_create_ops->fin) |
28418 | + sbinfo->si_wbr_create_ops->fin(sb); | |
28419 | + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) { | |
28420 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE); | |
b95c5147 | 28421 | + au_remount_refresh(sb, /*do_idop*/0); |
e49829fe JR |
28422 | + } |
28423 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
28424 | + au_plink_put(sb, /*verbose*/1); | |
28425 | + au_xino_clr(sb); | |
1e00d052 | 28426 | + sbinfo->si_sb = NULL; |
e49829fe | 28427 | + aufs_write_unlock(sb->s_root); |
e49829fe JR |
28428 | + au_nwt_flush(&sbinfo->si_nowait); |
28429 | + } | |
98d9a5b1 | 28430 | + kill_anon_super(sb); |
e49829fe JR |
28431 | +} |
28432 | + | |
1facf9fc | 28433 | +struct file_system_type aufs_fs_type = { |
28434 | + .name = AUFS_FSTYPE, | |
c06a8ce3 AM |
28435 | + /* a race between rename and others */ |
28436 | + .fs_flags = FS_RENAME_DOES_D_MOVE, | |
027c5e7a | 28437 | + .mount = aufs_mount, |
e49829fe | 28438 | + .kill_sb = aufs_kill_sb, |
1facf9fc | 28439 | + /* no need to __module_get() and module_put(). */ |
28440 | + .owner = THIS_MODULE, | |
28441 | +}; | |
7f207e10 AM |
28442 | diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h |
28443 | --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 28444 | +++ linux/fs/aufs/super.h 2017-05-06 22:16:52.781553511 +0200 |
a2654f78 | 28445 | @@ -0,0 +1,617 @@ |
1facf9fc | 28446 | +/* |
a2654f78 | 28447 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 28448 | + * |
28449 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28450 | + * it under the terms of the GNU General Public License as published by | |
28451 | + * the Free Software Foundation; either version 2 of the License, or | |
28452 | + * (at your option) any later version. | |
dece6358 AM |
28453 | + * |
28454 | + * This program is distributed in the hope that it will be useful, | |
28455 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28456 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28457 | + * GNU General Public License for more details. | |
28458 | + * | |
28459 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28460 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28461 | + */ |
28462 | + | |
28463 | +/* | |
28464 | + * super_block operations | |
28465 | + */ | |
28466 | + | |
28467 | +#ifndef __AUFS_SUPER_H__ | |
28468 | +#define __AUFS_SUPER_H__ | |
28469 | + | |
28470 | +#ifdef __KERNEL__ | |
28471 | + | |
28472 | +#include <linux/fs.h> | |
5527c038 | 28473 | +#include <linux/kobject.h> |
1facf9fc | 28474 | +#include "rwsem.h" |
28475 | +#include "spl.h" | |
28476 | +#include "wkq.h" | |
28477 | + | |
1facf9fc | 28478 | +/* policies to select one among multiple writable branches */ |
28479 | +struct au_wbr_copyup_operations { | |
28480 | + int (*copyup)(struct dentry *dentry); | |
28481 | +}; | |
28482 | + | |
392086de AM |
28483 | +#define AuWbr_DIR 1 /* target is a dir */ |
28484 | +#define AuWbr_PARENT (1 << 1) /* always require a parent */ | |
28485 | + | |
28486 | +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name) | |
28487 | +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; } | |
28488 | +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; } | |
28489 | + | |
1facf9fc | 28490 | +struct au_wbr_create_operations { |
392086de | 28491 | + int (*create)(struct dentry *dentry, unsigned int flags); |
1facf9fc | 28492 | + int (*init)(struct super_block *sb); |
28493 | + int (*fin)(struct super_block *sb); | |
28494 | +}; | |
28495 | + | |
28496 | +struct au_wbr_mfs { | |
28497 | + struct mutex mfs_lock; /* protect this structure */ | |
28498 | + unsigned long mfs_jiffy; | |
28499 | + unsigned long mfs_expire; | |
28500 | + aufs_bindex_t mfs_bindex; | |
28501 | + | |
28502 | + unsigned long long mfsrr_bytes; | |
28503 | + unsigned long long mfsrr_watermark; | |
28504 | +}; | |
28505 | + | |
86dc4139 AM |
28506 | +#define AuPlink_NHASH 100 |
28507 | +static inline int au_plink_hash(ino_t ino) | |
28508 | +{ | |
28509 | + return ino % AuPlink_NHASH; | |
28510 | +} | |
28511 | + | |
076b876e AM |
28512 | +/* File-based Hierarchical Storage Management */ |
28513 | +struct au_fhsm { | |
28514 | +#ifdef CONFIG_AUFS_FHSM | |
28515 | + /* allow only one process who can receive the notification */ | |
28516 | + spinlock_t fhsm_spin; | |
28517 | + pid_t fhsm_pid; | |
28518 | + wait_queue_head_t fhsm_wqh; | |
28519 | + atomic_t fhsm_readable; | |
28520 | + | |
c1595e42 | 28521 | + /* these are protected by si_rwsem */ |
076b876e | 28522 | + unsigned long fhsm_expire; |
c1595e42 | 28523 | + aufs_bindex_t fhsm_bottom; |
076b876e AM |
28524 | +#endif |
28525 | +}; | |
28526 | + | |
1facf9fc | 28527 | +struct au_branch; |
28528 | +struct au_sbinfo { | |
28529 | + /* nowait tasks in the system-wide workqueue */ | |
28530 | + struct au_nowait_tasks si_nowait; | |
28531 | + | |
b752ccd1 AM |
28532 | + /* |
28533 | + * tried sb->s_umount, but failed due to the dependecy between i_mutex. | |
28534 | + * rwsem for au_sbinfo is necessary. | |
28535 | + */ | |
dece6358 | 28536 | + struct au_rwsem si_rwsem; |
1facf9fc | 28537 | + |
7f207e10 | 28538 | + /* |
523b37e3 AM |
28539 | + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from |
28540 | + * remount. | |
7f207e10 | 28541 | + */ |
5afbbe0d | 28542 | + struct percpu_counter si_ninodes, si_nfiles; |
7f207e10 | 28543 | + |
1facf9fc | 28544 | + /* branch management */ |
28545 | + unsigned int si_generation; | |
28546 | + | |
2000de60 | 28547 | + /* see AuSi_ flags */ |
1facf9fc | 28548 | + unsigned char au_si_status; |
28549 | + | |
5afbbe0d | 28550 | + aufs_bindex_t si_bbot; |
7f207e10 AM |
28551 | + |
28552 | + /* dirty trick to keep br_id plus */ | |
28553 | + unsigned int si_last_br_id : | |
28554 | + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1; | |
1facf9fc | 28555 | + struct au_branch **si_branch; |
28556 | + | |
28557 | + /* policy to select a writable branch */ | |
28558 | + unsigned char si_wbr_copyup; | |
28559 | + unsigned char si_wbr_create; | |
28560 | + struct au_wbr_copyup_operations *si_wbr_copyup_ops; | |
28561 | + struct au_wbr_create_operations *si_wbr_create_ops; | |
28562 | + | |
28563 | + /* round robin */ | |
28564 | + atomic_t si_wbr_rr_next; | |
28565 | + | |
28566 | + /* most free space */ | |
28567 | + struct au_wbr_mfs si_wbr_mfs; | |
28568 | + | |
076b876e AM |
28569 | + /* File-based Hierarchical Storage Management */ |
28570 | + struct au_fhsm si_fhsm; | |
28571 | + | |
1facf9fc | 28572 | + /* mount flags */ |
28573 | + /* include/asm-ia64/siginfo.h defines a macro named si_flags */ | |
28574 | + unsigned int si_mntflags; | |
28575 | + | |
28576 | + /* external inode number (bitmap and translation table) */ | |
5527c038 JR |
28577 | + vfs_readf_t si_xread; |
28578 | + vfs_writef_t si_xwrite; | |
1facf9fc | 28579 | + struct file *si_xib; |
28580 | + struct mutex si_xib_mtx; /* protect xib members */ | |
28581 | + unsigned long *si_xib_buf; | |
28582 | + unsigned long si_xib_last_pindex; | |
28583 | + int si_xib_next_bit; | |
28584 | + aufs_bindex_t si_xino_brid; | |
392086de AM |
28585 | + unsigned long si_xino_jiffy; |
28586 | + unsigned long si_xino_expire; | |
1facf9fc | 28587 | + /* reserved for future use */ |
28588 | + /* unsigned long long si_xib_limit; */ /* Max xib file size */ | |
28589 | + | |
28590 | +#ifdef CONFIG_AUFS_EXPORT | |
28591 | + /* i_generation */ | |
28592 | + struct file *si_xigen; | |
28593 | + atomic_t si_xigen_next; | |
28594 | +#endif | |
28595 | + | |
b912730e AM |
28596 | + /* dirty trick to suppoer atomic_open */ |
28597 | + struct au_sphlhead si_aopen; | |
28598 | + | |
1facf9fc | 28599 | + /* vdir parameters */ |
e49829fe | 28600 | + unsigned long si_rdcache; /* max cache time in jiffies */ |
1facf9fc | 28601 | + unsigned int si_rdblk; /* deblk size */ |
28602 | + unsigned int si_rdhash; /* hash size */ | |
28603 | + | |
28604 | + /* | |
28605 | + * If the number of whiteouts are larger than si_dirwh, leave all of | |
28606 | + * them after au_whtmp_ren to reduce the cost of rmdir(2). | |
28607 | + * future fsck.aufs or kernel thread will remove them later. | |
28608 | + * Otherwise, remove all whiteouts and the dir in rmdir(2). | |
28609 | + */ | |
28610 | + unsigned int si_dirwh; | |
28611 | + | |
1facf9fc | 28612 | + /* pseudo_link list */ |
86dc4139 | 28613 | + struct au_sphlhead si_plink[AuPlink_NHASH]; |
1facf9fc | 28614 | + wait_queue_head_t si_plink_wq; |
4a4d8108 | 28615 | + spinlock_t si_plink_maint_lock; |
e49829fe | 28616 | + pid_t si_plink_maint_pid; |
1facf9fc | 28617 | + |
523b37e3 AM |
28618 | + /* file list */ |
28619 | + struct au_sphlhead si_files; | |
28620 | + | |
b95c5147 AM |
28621 | + /* with/without getattr, brother of sb->s_d_op */ |
28622 | + struct inode_operations *si_iop_array; | |
28623 | + | |
1facf9fc | 28624 | + /* |
28625 | + * sysfs and lifetime management. | |
28626 | + * this is not a small structure and it may be a waste of memory in case | |
28627 | + * of sysfs is disabled, particulary when many aufs-es are mounted. | |
28628 | + * but using sysfs is majority. | |
28629 | + */ | |
28630 | + struct kobject si_kobj; | |
28631 | +#ifdef CONFIG_DEBUG_FS | |
86dc4139 AM |
28632 | + struct dentry *si_dbgaufs; |
28633 | + struct dentry *si_dbgaufs_plink; | |
28634 | + struct dentry *si_dbgaufs_xib; | |
1facf9fc | 28635 | +#ifdef CONFIG_AUFS_EXPORT |
28636 | + struct dentry *si_dbgaufs_xigen; | |
28637 | +#endif | |
28638 | +#endif | |
28639 | + | |
e49829fe | 28640 | +#ifdef CONFIG_AUFS_SBILIST |
5afbbe0d | 28641 | + struct hlist_node si_list; |
e49829fe JR |
28642 | +#endif |
28643 | + | |
1facf9fc | 28644 | + /* dirty, necessary for unmounting, sysfs and sysrq */ |
28645 | + struct super_block *si_sb; | |
28646 | +}; | |
28647 | + | |
dece6358 AM |
28648 | +/* sbinfo status flags */ |
28649 | +/* | |
28650 | + * set true when refresh_dirs() failed at remount time. | |
28651 | + * then try refreshing dirs at access time again. | |
28652 | + * if it is false, refreshing dirs at access time is unnecesary | |
28653 | + */ | |
027c5e7a | 28654 | +#define AuSi_FAILED_REFRESH_DIR 1 |
076b876e | 28655 | +#define AuSi_FHSM (1 << 1) /* fhsm is active now */ |
79b8bda9 | 28656 | +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */ |
076b876e AM |
28657 | + |
28658 | +#ifndef CONFIG_AUFS_FHSM | |
28659 | +#undef AuSi_FHSM | |
28660 | +#define AuSi_FHSM 0 | |
28661 | +#endif | |
28662 | + | |
dece6358 AM |
28663 | +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi, |
28664 | + unsigned int flag) | |
28665 | +{ | |
28666 | + AuRwMustAnyLock(&sbi->si_rwsem); | |
28667 | + return sbi->au_si_status & flag; | |
28668 | +} | |
28669 | +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name) | |
28670 | +#define au_fset_si(sbinfo, name) do { \ | |
28671 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
28672 | + (sbinfo)->au_si_status |= AuSi_##name; \ | |
28673 | +} while (0) | |
28674 | +#define au_fclr_si(sbinfo, name) do { \ | |
28675 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
28676 | + (sbinfo)->au_si_status &= ~AuSi_##name; \ | |
28677 | +} while (0) | |
28678 | + | |
1facf9fc | 28679 | +/* ---------------------------------------------------------------------- */ |
28680 | + | |
28681 | +/* policy to select one among writable branches */ | |
4a4d8108 AM |
28682 | +#define AuWbrCopyup(sbinfo, ...) \ |
28683 | + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__)) | |
28684 | +#define AuWbrCreate(sbinfo, ...) \ | |
28685 | + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__)) | |
1facf9fc | 28686 | + |
28687 | +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */ | |
28688 | +#define AuLock_DW 1 /* write-lock dentry */ | |
28689 | +#define AuLock_IR (1 << 1) /* read-lock inode */ | |
28690 | +#define AuLock_IW (1 << 2) /* write-lock inode */ | |
28691 | +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */ | |
b95c5147 | 28692 | +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */ |
f2c43d5f | 28693 | + /* except RENAME_EXCHANGE */ |
e49829fe JR |
28694 | +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */ |
28695 | +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */ | |
027c5e7a | 28696 | +#define AuLock_GEN (1 << 7) /* test digen/iigen */ |
1facf9fc | 28697 | +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name) |
7f207e10 AM |
28698 | +#define au_fset_lock(flags, name) \ |
28699 | + do { (flags) |= AuLock_##name; } while (0) | |
28700 | +#define au_fclr_lock(flags, name) \ | |
28701 | + do { (flags) &= ~AuLock_##name; } while (0) | |
1facf9fc | 28702 | + |
28703 | +/* ---------------------------------------------------------------------- */ | |
28704 | + | |
28705 | +/* super.c */ | |
28706 | +extern struct file_system_type aufs_fs_type; | |
28707 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino); | |
79b8bda9 AM |
28708 | +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array, |
28709 | + unsigned long long max, void *arg); | |
79b8bda9 AM |
28710 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, |
28711 | + struct super_block *sb, void *arg); | |
7f207e10 AM |
28712 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max); |
28713 | +void au_iarray_free(struct inode **a, unsigned long long max); | |
1facf9fc | 28714 | + |
28715 | +/* sbinfo.c */ | |
28716 | +void au_si_free(struct kobject *kobj); | |
28717 | +int au_si_alloc(struct super_block *sb); | |
e2f27e51 | 28718 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink); |
1facf9fc | 28719 | + |
28720 | +unsigned int au_sigen_inc(struct super_block *sb); | |
28721 | +aufs_bindex_t au_new_br_id(struct super_block *sb); | |
28722 | + | |
e49829fe JR |
28723 | +int si_read_lock(struct super_block *sb, int flags); |
28724 | +int si_write_lock(struct super_block *sb, int flags); | |
28725 | +int aufs_read_lock(struct dentry *dentry, int flags); | |
1facf9fc | 28726 | +void aufs_read_unlock(struct dentry *dentry, int flags); |
28727 | +void aufs_write_lock(struct dentry *dentry); | |
28728 | +void aufs_write_unlock(struct dentry *dentry); | |
e49829fe | 28729 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags); |
1facf9fc | 28730 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2); |
28731 | + | |
28732 | +/* wbr_policy.c */ | |
28733 | +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[]; | |
28734 | +extern struct au_wbr_create_operations au_wbr_create_ops[]; | |
28735 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
c2b27bf2 | 28736 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex); |
5afbbe0d | 28737 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop); |
c2b27bf2 AM |
28738 | + |
28739 | +/* mvdown.c */ | |
28740 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg); | |
1facf9fc | 28741 | + |
076b876e AM |
28742 | +#ifdef CONFIG_AUFS_FHSM |
28743 | +/* fhsm.c */ | |
28744 | + | |
28745 | +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm) | |
28746 | +{ | |
28747 | + pid_t pid; | |
28748 | + | |
28749 | + spin_lock(&fhsm->fhsm_spin); | |
28750 | + pid = fhsm->fhsm_pid; | |
28751 | + spin_unlock(&fhsm->fhsm_spin); | |
28752 | + | |
28753 | + return pid; | |
28754 | +} | |
28755 | + | |
28756 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force); | |
28757 | +void au_fhsm_wrote_all(struct super_block *sb, int force); | |
28758 | +int au_fhsm_fd(struct super_block *sb, int oflags); | |
28759 | +int au_fhsm_br_alloc(struct au_branch *br); | |
c1595e42 | 28760 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex); |
076b876e AM |
28761 | +void au_fhsm_fin(struct super_block *sb); |
28762 | +void au_fhsm_init(struct au_sbinfo *sbinfo); | |
28763 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec); | |
28764 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo); | |
28765 | +#else | |
28766 | +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex, | |
28767 | + int force) | |
28768 | +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force) | |
28769 | +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags) | |
c1595e42 JR |
28770 | +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm) |
28771 | +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br) | |
28772 | +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex) | |
076b876e AM |
28773 | +AuStubVoid(au_fhsm_fin, struct super_block *sb) |
28774 | +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo) | |
28775 | +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec) | |
28776 | +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo) | |
28777 | +#endif | |
28778 | + | |
1facf9fc | 28779 | +/* ---------------------------------------------------------------------- */ |
28780 | + | |
28781 | +static inline struct au_sbinfo *au_sbi(struct super_block *sb) | |
28782 | +{ | |
28783 | + return sb->s_fs_info; | |
28784 | +} | |
28785 | + | |
28786 | +/* ---------------------------------------------------------------------- */ | |
28787 | + | |
28788 | +#ifdef CONFIG_AUFS_EXPORT | |
a2a7ad62 | 28789 | +int au_test_nfsd(void); |
1facf9fc | 28790 | +void au_export_init(struct super_block *sb); |
b752ccd1 | 28791 | +void au_xigen_inc(struct inode *inode); |
1facf9fc | 28792 | +int au_xigen_new(struct inode *inode); |
28793 | +int au_xigen_set(struct super_block *sb, struct file *base); | |
28794 | +void au_xigen_clr(struct super_block *sb); | |
28795 | + | |
28796 | +static inline int au_busy_or_stale(void) | |
28797 | +{ | |
b752ccd1 | 28798 | + if (!au_test_nfsd()) |
1facf9fc | 28799 | + return -EBUSY; |
28800 | + return -ESTALE; | |
28801 | +} | |
28802 | +#else | |
b752ccd1 | 28803 | +AuStubInt0(au_test_nfsd, void) |
a2a7ad62 | 28804 | +AuStubVoid(au_export_init, struct super_block *sb) |
b752ccd1 | 28805 | +AuStubVoid(au_xigen_inc, struct inode *inode) |
4a4d8108 AM |
28806 | +AuStubInt0(au_xigen_new, struct inode *inode) |
28807 | +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base) | |
28808 | +AuStubVoid(au_xigen_clr, struct super_block *sb) | |
c1595e42 | 28809 | +AuStub(int, au_busy_or_stale, return -EBUSY, void) |
1facf9fc | 28810 | +#endif /* CONFIG_AUFS_EXPORT */ |
28811 | + | |
28812 | +/* ---------------------------------------------------------------------- */ | |
28813 | + | |
e49829fe JR |
28814 | +#ifdef CONFIG_AUFS_SBILIST |
28815 | +/* module.c */ | |
5afbbe0d | 28816 | +extern struct au_sphlhead au_sbilist; |
e49829fe JR |
28817 | + |
28818 | +static inline void au_sbilist_init(void) | |
28819 | +{ | |
5afbbe0d | 28820 | + au_sphl_init(&au_sbilist); |
e49829fe JR |
28821 | +} |
28822 | + | |
28823 | +static inline void au_sbilist_add(struct super_block *sb) | |
28824 | +{ | |
5afbbe0d | 28825 | + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist); |
e49829fe JR |
28826 | +} |
28827 | + | |
28828 | +static inline void au_sbilist_del(struct super_block *sb) | |
28829 | +{ | |
5afbbe0d | 28830 | + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist); |
e49829fe | 28831 | +} |
53392da6 AM |
28832 | + |
28833 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
28834 | +static inline void au_sbilist_lock(void) | |
28835 | +{ | |
28836 | + spin_lock(&au_sbilist.spin); | |
28837 | +} | |
28838 | + | |
28839 | +static inline void au_sbilist_unlock(void) | |
28840 | +{ | |
28841 | + spin_unlock(&au_sbilist.spin); | |
28842 | +} | |
28843 | +#define AuGFP_SBILIST GFP_ATOMIC | |
28844 | +#else | |
28845 | +AuStubVoid(au_sbilist_lock, void) | |
28846 | +AuStubVoid(au_sbilist_unlock, void) | |
28847 | +#define AuGFP_SBILIST GFP_NOFS | |
28848 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ | |
e49829fe JR |
28849 | +#else |
28850 | +AuStubVoid(au_sbilist_init, void) | |
c1595e42 JR |
28851 | +AuStubVoid(au_sbilist_add, struct super_block *sb) |
28852 | +AuStubVoid(au_sbilist_del, struct super_block *sb) | |
53392da6 AM |
28853 | +AuStubVoid(au_sbilist_lock, void) |
28854 | +AuStubVoid(au_sbilist_unlock, void) | |
28855 | +#define AuGFP_SBILIST GFP_NOFS | |
e49829fe JR |
28856 | +#endif |
28857 | + | |
28858 | +/* ---------------------------------------------------------------------- */ | |
28859 | + | |
1facf9fc | 28860 | +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo) |
28861 | +{ | |
dece6358 | 28862 | + /* |
c1595e42 | 28863 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
28864 | + * so the tiny check for si_rwsem is unnecessary. |
28865 | + */ | |
28866 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
1facf9fc | 28867 | +#ifdef CONFIG_DEBUG_FS |
28868 | + sbinfo->si_dbgaufs = NULL; | |
86dc4139 | 28869 | + sbinfo->si_dbgaufs_plink = NULL; |
1facf9fc | 28870 | + sbinfo->si_dbgaufs_xib = NULL; |
28871 | +#ifdef CONFIG_AUFS_EXPORT | |
28872 | + sbinfo->si_dbgaufs_xigen = NULL; | |
28873 | +#endif | |
28874 | +#endif | |
28875 | +} | |
28876 | + | |
28877 | +/* ---------------------------------------------------------------------- */ | |
28878 | + | |
a2654f78 AM |
28879 | +/* current->atomic_flags */ |
28880 | +/* this value should never corrupt the ones defined in linux/sched.h */ | |
28881 | +#define PFA_AUFS 7 | |
28882 | + | |
28883 | +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */ | |
28884 | +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */ | |
28885 | +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */ | |
b752ccd1 AM |
28886 | + |
28887 | +static inline int si_pid_test(struct super_block *sb) | |
28888 | +{ | |
a2654f78 | 28889 | + return !!task_test_aufs(current); |
b752ccd1 AM |
28890 | +} |
28891 | + | |
28892 | +static inline void si_pid_clr(struct super_block *sb) | |
28893 | +{ | |
a2654f78 AM |
28894 | + AuDebugOn(!task_test_aufs(current)); |
28895 | + task_clear_aufs(current); | |
b752ccd1 AM |
28896 | +} |
28897 | + | |
a2654f78 AM |
28898 | +static inline void si_pid_set(struct super_block *sb) |
28899 | +{ | |
28900 | + AuDebugOn(task_test_aufs(current)); | |
28901 | + task_set_aufs(current); | |
28902 | +} | |
febd17d6 | 28903 | + |
b752ccd1 AM |
28904 | +/* ---------------------------------------------------------------------- */ |
28905 | + | |
1facf9fc | 28906 | +/* lock superblock. mainly for entry point functions */ |
28907 | +/* | |
b752ccd1 AM |
28908 | + * __si_read_lock, __si_write_lock, |
28909 | + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock | |
1facf9fc | 28910 | + */ |
b752ccd1 | 28911 | +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem); |
1facf9fc | 28912 | + |
dece6358 AM |
28913 | +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem) |
28914 | +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem) | |
28915 | +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem) | |
28916 | + | |
b752ccd1 AM |
28917 | +static inline void si_noflush_read_lock(struct super_block *sb) |
28918 | +{ | |
28919 | + __si_read_lock(sb); | |
28920 | + si_pid_set(sb); | |
28921 | +} | |
28922 | + | |
28923 | +static inline int si_noflush_read_trylock(struct super_block *sb) | |
28924 | +{ | |
076b876e AM |
28925 | + int locked; |
28926 | + | |
28927 | + locked = __si_read_trylock(sb); | |
b752ccd1 AM |
28928 | + if (locked) |
28929 | + si_pid_set(sb); | |
28930 | + return locked; | |
28931 | +} | |
28932 | + | |
28933 | +static inline void si_noflush_write_lock(struct super_block *sb) | |
28934 | +{ | |
28935 | + __si_write_lock(sb); | |
28936 | + si_pid_set(sb); | |
28937 | +} | |
28938 | + | |
28939 | +static inline int si_noflush_write_trylock(struct super_block *sb) | |
28940 | +{ | |
076b876e AM |
28941 | + int locked; |
28942 | + | |
28943 | + locked = __si_write_trylock(sb); | |
b752ccd1 AM |
28944 | + if (locked) |
28945 | + si_pid_set(sb); | |
28946 | + return locked; | |
28947 | +} | |
28948 | + | |
7e9cd9fe | 28949 | +#if 0 /* reserved */ |
1facf9fc | 28950 | +static inline int si_read_trylock(struct super_block *sb, int flags) |
28951 | +{ | |
28952 | + if (au_ftest_lock(flags, FLUSH)) | |
28953 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28954 | + return si_noflush_read_trylock(sb); | |
28955 | +} | |
e49829fe | 28956 | +#endif |
1facf9fc | 28957 | + |
b752ccd1 AM |
28958 | +static inline void si_read_unlock(struct super_block *sb) |
28959 | +{ | |
28960 | + si_pid_clr(sb); | |
28961 | + __si_read_unlock(sb); | |
28962 | +} | |
28963 | + | |
7e9cd9fe | 28964 | +#if 0 /* reserved */ |
1facf9fc | 28965 | +static inline int si_write_trylock(struct super_block *sb, int flags) |
28966 | +{ | |
28967 | + if (au_ftest_lock(flags, FLUSH)) | |
28968 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28969 | + return si_noflush_write_trylock(sb); | |
28970 | +} | |
b752ccd1 AM |
28971 | +#endif |
28972 | + | |
28973 | +static inline void si_write_unlock(struct super_block *sb) | |
28974 | +{ | |
28975 | + si_pid_clr(sb); | |
28976 | + __si_write_unlock(sb); | |
28977 | +} | |
28978 | + | |
7e9cd9fe | 28979 | +#if 0 /* reserved */ |
b752ccd1 AM |
28980 | +static inline void si_downgrade_lock(struct super_block *sb) |
28981 | +{ | |
28982 | + __si_downgrade_lock(sb); | |
28983 | +} | |
28984 | +#endif | |
1facf9fc | 28985 | + |
28986 | +/* ---------------------------------------------------------------------- */ | |
28987 | + | |
5afbbe0d | 28988 | +static inline aufs_bindex_t au_sbbot(struct super_block *sb) |
1facf9fc | 28989 | +{ |
dece6358 | 28990 | + SiMustAnyLock(sb); |
5afbbe0d | 28991 | + return au_sbi(sb)->si_bbot; |
1facf9fc | 28992 | +} |
28993 | + | |
28994 | +static inline unsigned int au_mntflags(struct super_block *sb) | |
28995 | +{ | |
dece6358 | 28996 | + SiMustAnyLock(sb); |
1facf9fc | 28997 | + return au_sbi(sb)->si_mntflags; |
28998 | +} | |
28999 | + | |
29000 | +static inline unsigned int au_sigen(struct super_block *sb) | |
29001 | +{ | |
dece6358 | 29002 | + SiMustAnyLock(sb); |
1facf9fc | 29003 | + return au_sbi(sb)->si_generation; |
29004 | +} | |
29005 | + | |
5afbbe0d AM |
29006 | +static inline unsigned long long au_ninodes(struct super_block *sb) |
29007 | +{ | |
29008 | + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes); | |
29009 | + | |
29010 | + BUG_ON(n < 0); | |
29011 | + return n; | |
29012 | +} | |
29013 | + | |
7f207e10 AM |
29014 | +static inline void au_ninodes_inc(struct super_block *sb) |
29015 | +{ | |
5afbbe0d | 29016 | + percpu_counter_inc(&au_sbi(sb)->si_ninodes); |
7f207e10 AM |
29017 | +} |
29018 | + | |
29019 | +static inline void au_ninodes_dec(struct super_block *sb) | |
29020 | +{ | |
5afbbe0d AM |
29021 | + percpu_counter_dec(&au_sbi(sb)->si_ninodes); |
29022 | +} | |
29023 | + | |
29024 | +static inline unsigned long long au_nfiles(struct super_block *sb) | |
29025 | +{ | |
29026 | + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles); | |
29027 | + | |
29028 | + BUG_ON(n < 0); | |
29029 | + return n; | |
7f207e10 AM |
29030 | +} |
29031 | + | |
29032 | +static inline void au_nfiles_inc(struct super_block *sb) | |
29033 | +{ | |
5afbbe0d | 29034 | + percpu_counter_inc(&au_sbi(sb)->si_nfiles); |
7f207e10 AM |
29035 | +} |
29036 | + | |
29037 | +static inline void au_nfiles_dec(struct super_block *sb) | |
29038 | +{ | |
5afbbe0d | 29039 | + percpu_counter_dec(&au_sbi(sb)->si_nfiles); |
7f207e10 AM |
29040 | +} |
29041 | + | |
1facf9fc | 29042 | +static inline struct au_branch *au_sbr(struct super_block *sb, |
29043 | + aufs_bindex_t bindex) | |
29044 | +{ | |
dece6358 | 29045 | + SiMustAnyLock(sb); |
1facf9fc | 29046 | + return au_sbi(sb)->si_branch[0 + bindex]; |
29047 | +} | |
29048 | + | |
29049 | +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid) | |
29050 | +{ | |
dece6358 | 29051 | + SiMustWriteLock(sb); |
1facf9fc | 29052 | + au_sbi(sb)->si_xino_brid = brid; |
29053 | +} | |
29054 | + | |
29055 | +static inline aufs_bindex_t au_xino_brid(struct super_block *sb) | |
29056 | +{ | |
dece6358 | 29057 | + SiMustAnyLock(sb); |
1facf9fc | 29058 | + return au_sbi(sb)->si_xino_brid; |
29059 | +} | |
29060 | + | |
29061 | +#endif /* __KERNEL__ */ | |
29062 | +#endif /* __AUFS_SUPER_H__ */ | |
7f207e10 AM |
29063 | diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c |
29064 | --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 29065 | +++ linux/fs/aufs/sysaufs.c 2017-05-06 22:16:52.781553511 +0200 |
523b37e3 | 29066 | @@ -0,0 +1,104 @@ |
1facf9fc | 29067 | +/* |
a2654f78 | 29068 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 29069 | + * |
29070 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29071 | + * it under the terms of the GNU General Public License as published by | |
29072 | + * the Free Software Foundation; either version 2 of the License, or | |
29073 | + * (at your option) any later version. | |
dece6358 AM |
29074 | + * |
29075 | + * This program is distributed in the hope that it will be useful, | |
29076 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29077 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29078 | + * GNU General Public License for more details. | |
29079 | + * | |
29080 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29081 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29082 | + */ |
29083 | + | |
29084 | +/* | |
29085 | + * sysfs interface and lifetime management | |
29086 | + * they are necessary regardless sysfs is disabled. | |
29087 | + */ | |
29088 | + | |
1facf9fc | 29089 | +#include <linux/random.h> |
1facf9fc | 29090 | +#include "aufs.h" |
29091 | + | |
29092 | +unsigned long sysaufs_si_mask; | |
e49829fe | 29093 | +struct kset *sysaufs_kset; |
1facf9fc | 29094 | + |
29095 | +#define AuSiAttr(_name) { \ | |
29096 | + .attr = { .name = __stringify(_name), .mode = 0444 }, \ | |
29097 | + .show = sysaufs_si_##_name, \ | |
29098 | +} | |
29099 | + | |
29100 | +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path); | |
29101 | +struct attribute *sysaufs_si_attrs[] = { | |
29102 | + &sysaufs_si_attr_xi_path.attr, | |
29103 | + NULL, | |
29104 | +}; | |
29105 | + | |
4a4d8108 | 29106 | +static const struct sysfs_ops au_sbi_ops = { |
1facf9fc | 29107 | + .show = sysaufs_si_show |
29108 | +}; | |
29109 | + | |
29110 | +static struct kobj_type au_sbi_ktype = { | |
29111 | + .release = au_si_free, | |
29112 | + .sysfs_ops = &au_sbi_ops, | |
29113 | + .default_attrs = sysaufs_si_attrs | |
29114 | +}; | |
29115 | + | |
29116 | +/* ---------------------------------------------------------------------- */ | |
29117 | + | |
29118 | +int sysaufs_si_init(struct au_sbinfo *sbinfo) | |
29119 | +{ | |
29120 | + int err; | |
29121 | + | |
e49829fe | 29122 | + sbinfo->si_kobj.kset = sysaufs_kset; |
1facf9fc | 29123 | + /* cf. sysaufs_name() */ |
29124 | + err = kobject_init_and_add | |
e49829fe | 29125 | + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL, |
1facf9fc | 29126 | + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo)); |
29127 | + | |
29128 | + dbgaufs_si_null(sbinfo); | |
29129 | + if (!err) { | |
29130 | + err = dbgaufs_si_init(sbinfo); | |
29131 | + if (unlikely(err)) | |
29132 | + kobject_put(&sbinfo->si_kobj); | |
29133 | + } | |
29134 | + return err; | |
29135 | +} | |
29136 | + | |
29137 | +void sysaufs_fin(void) | |
29138 | +{ | |
29139 | + dbgaufs_fin(); | |
e49829fe JR |
29140 | + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
29141 | + kset_unregister(sysaufs_kset); | |
1facf9fc | 29142 | +} |
29143 | + | |
29144 | +int __init sysaufs_init(void) | |
29145 | +{ | |
29146 | + int err; | |
29147 | + | |
29148 | + do { | |
29149 | + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask)); | |
29150 | + } while (!sysaufs_si_mask); | |
29151 | + | |
4a4d8108 | 29152 | + err = -EINVAL; |
e49829fe JR |
29153 | + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj); |
29154 | + if (unlikely(!sysaufs_kset)) | |
4a4d8108 | 29155 | + goto out; |
e49829fe JR |
29156 | + err = PTR_ERR(sysaufs_kset); |
29157 | + if (IS_ERR(sysaufs_kset)) | |
1facf9fc | 29158 | + goto out; |
e49829fe | 29159 | + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
1facf9fc | 29160 | + if (unlikely(err)) { |
e49829fe | 29161 | + kset_unregister(sysaufs_kset); |
1facf9fc | 29162 | + goto out; |
29163 | + } | |
29164 | + | |
29165 | + err = dbgaufs_init(); | |
29166 | + if (unlikely(err)) | |
29167 | + sysaufs_fin(); | |
4f0767ce | 29168 | +out: |
1facf9fc | 29169 | + return err; |
29170 | +} | |
7f207e10 AM |
29171 | diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h |
29172 | --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 29173 | +++ linux/fs/aufs/sysaufs.h 2017-05-06 22:16:52.781553511 +0200 |
c1595e42 | 29174 | @@ -0,0 +1,101 @@ |
1facf9fc | 29175 | +/* |
a2654f78 | 29176 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 29177 | + * |
29178 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29179 | + * it under the terms of the GNU General Public License as published by | |
29180 | + * the Free Software Foundation; either version 2 of the License, or | |
29181 | + * (at your option) any later version. | |
dece6358 AM |
29182 | + * |
29183 | + * This program is distributed in the hope that it will be useful, | |
29184 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29185 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29186 | + * GNU General Public License for more details. | |
29187 | + * | |
29188 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29189 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29190 | + */ |
29191 | + | |
29192 | +/* | |
29193 | + * sysfs interface and mount lifetime management | |
29194 | + */ | |
29195 | + | |
29196 | +#ifndef __SYSAUFS_H__ | |
29197 | +#define __SYSAUFS_H__ | |
29198 | + | |
29199 | +#ifdef __KERNEL__ | |
29200 | + | |
1facf9fc | 29201 | +#include <linux/sysfs.h> |
1facf9fc | 29202 | +#include "module.h" |
29203 | + | |
dece6358 AM |
29204 | +struct super_block; |
29205 | +struct au_sbinfo; | |
29206 | + | |
1facf9fc | 29207 | +struct sysaufs_si_attr { |
29208 | + struct attribute attr; | |
29209 | + int (*show)(struct seq_file *seq, struct super_block *sb); | |
29210 | +}; | |
29211 | + | |
29212 | +/* ---------------------------------------------------------------------- */ | |
29213 | + | |
29214 | +/* sysaufs.c */ | |
29215 | +extern unsigned long sysaufs_si_mask; | |
e49829fe | 29216 | +extern struct kset *sysaufs_kset; |
1facf9fc | 29217 | +extern struct attribute *sysaufs_si_attrs[]; |
29218 | +int sysaufs_si_init(struct au_sbinfo *sbinfo); | |
29219 | +int __init sysaufs_init(void); | |
29220 | +void sysaufs_fin(void); | |
29221 | + | |
29222 | +/* ---------------------------------------------------------------------- */ | |
29223 | + | |
29224 | +/* some people doesn't like to show a pointer in kernel */ | |
29225 | +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo) | |
29226 | +{ | |
29227 | + return sysaufs_si_mask ^ (unsigned long)sbinfo; | |
29228 | +} | |
29229 | + | |
29230 | +#define SysaufsSiNamePrefix "si_" | |
29231 | +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16) | |
29232 | +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name) | |
29233 | +{ | |
29234 | + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx", | |
29235 | + sysaufs_si_id(sbinfo)); | |
29236 | +} | |
29237 | + | |
29238 | +struct au_branch; | |
29239 | +#ifdef CONFIG_SYSFS | |
29240 | +/* sysfs.c */ | |
29241 | +extern struct attribute_group *sysaufs_attr_group; | |
29242 | + | |
29243 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb); | |
29244 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
29245 | + char *buf); | |
076b876e AM |
29246 | +long au_brinfo_ioctl(struct file *file, unsigned long arg); |
29247 | +#ifdef CONFIG_COMPAT | |
29248 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg); | |
29249 | +#endif | |
1facf9fc | 29250 | + |
29251 | +void sysaufs_br_init(struct au_branch *br); | |
29252 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
29253 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
29254 | + | |
29255 | +#define sysaufs_brs_init() do {} while (0) | |
29256 | + | |
29257 | +#else | |
29258 | +#define sysaufs_attr_group NULL | |
29259 | + | |
4a4d8108 | 29260 | +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb) |
c1595e42 JR |
29261 | +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj, |
29262 | + struct attribute *attr, char *buf) | |
4a4d8108 AM |
29263 | +AuStubVoid(sysaufs_br_init, struct au_branch *br) |
29264 | +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
29265 | +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) | |
1facf9fc | 29266 | + |
29267 | +static inline void sysaufs_brs_init(void) | |
29268 | +{ | |
29269 | + sysaufs_brs = 0; | |
29270 | +} | |
29271 | + | |
29272 | +#endif /* CONFIG_SYSFS */ | |
29273 | + | |
29274 | +#endif /* __KERNEL__ */ | |
29275 | +#endif /* __SYSAUFS_H__ */ | |
7f207e10 AM |
29276 | diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c |
29277 | --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 29278 | +++ linux/fs/aufs/sysfs.c 2017-05-06 22:16:52.781553511 +0200 |
79b8bda9 | 29279 | @@ -0,0 +1,376 @@ |
1facf9fc | 29280 | +/* |
a2654f78 | 29281 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 29282 | + * |
29283 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29284 | + * it under the terms of the GNU General Public License as published by | |
29285 | + * the Free Software Foundation; either version 2 of the License, or | |
29286 | + * (at your option) any later version. | |
dece6358 AM |
29287 | + * |
29288 | + * This program is distributed in the hope that it will be useful, | |
29289 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29290 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29291 | + * GNU General Public License for more details. | |
29292 | + * | |
29293 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29294 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29295 | + */ |
29296 | + | |
29297 | +/* | |
29298 | + * sysfs interface | |
29299 | + */ | |
29300 | + | |
076b876e | 29301 | +#include <linux/compat.h> |
1facf9fc | 29302 | +#include <linux/seq_file.h> |
1facf9fc | 29303 | +#include "aufs.h" |
29304 | + | |
4a4d8108 AM |
29305 | +#ifdef CONFIG_AUFS_FS_MODULE |
29306 | +/* this entry violates the "one line per file" policy of sysfs */ | |
29307 | +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr, | |
29308 | + char *buf) | |
29309 | +{ | |
29310 | + ssize_t err; | |
29311 | + static char *conf = | |
29312 | +/* this file is generated at compiling */ | |
29313 | +#include "conf.str" | |
29314 | + ; | |
29315 | + | |
29316 | + err = snprintf(buf, PAGE_SIZE, conf); | |
29317 | + if (unlikely(err >= PAGE_SIZE)) | |
29318 | + err = -EFBIG; | |
29319 | + return err; | |
29320 | +} | |
29321 | + | |
29322 | +static struct kobj_attribute au_config_attr = __ATTR_RO(config); | |
29323 | +#endif | |
29324 | + | |
1facf9fc | 29325 | +static struct attribute *au_attr[] = { |
4a4d8108 AM |
29326 | +#ifdef CONFIG_AUFS_FS_MODULE |
29327 | + &au_config_attr.attr, | |
29328 | +#endif | |
1facf9fc | 29329 | + NULL, /* need to NULL terminate the list of attributes */ |
29330 | +}; | |
29331 | + | |
29332 | +static struct attribute_group sysaufs_attr_group_body = { | |
29333 | + .attrs = au_attr | |
29334 | +}; | |
29335 | + | |
29336 | +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body; | |
29337 | + | |
29338 | +/* ---------------------------------------------------------------------- */ | |
29339 | + | |
29340 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb) | |
29341 | +{ | |
29342 | + int err; | |
29343 | + | |
dece6358 AM |
29344 | + SiMustAnyLock(sb); |
29345 | + | |
1facf9fc | 29346 | + err = 0; |
29347 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
29348 | + err = au_xino_path(seq, au_sbi(sb)->si_xib); | |
29349 | + seq_putc(seq, '\n'); | |
29350 | + } | |
29351 | + return err; | |
29352 | +} | |
29353 | + | |
29354 | +/* | |
29355 | + * the lifetime of branch is independent from the entry under sysfs. | |
29356 | + * sysfs handles the lifetime of the entry, and never call ->show() after it is | |
29357 | + * unlinked. | |
29358 | + */ | |
29359 | +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb, | |
392086de | 29360 | + aufs_bindex_t bindex, int idx) |
1facf9fc | 29361 | +{ |
1e00d052 | 29362 | + int err; |
1facf9fc | 29363 | + struct path path; |
29364 | + struct dentry *root; | |
29365 | + struct au_branch *br; | |
076b876e | 29366 | + au_br_perm_str_t perm; |
1facf9fc | 29367 | + |
29368 | + AuDbg("b%d\n", bindex); | |
29369 | + | |
1e00d052 | 29370 | + err = 0; |
1facf9fc | 29371 | + root = sb->s_root; |
29372 | + di_read_lock_parent(root, !AuLock_IR); | |
29373 | + br = au_sbr(sb, bindex); | |
392086de AM |
29374 | + |
29375 | + switch (idx) { | |
29376 | + case AuBrSysfs_BR: | |
29377 | + path.mnt = au_br_mnt(br); | |
29378 | + path.dentry = au_h_dptr(root, bindex); | |
79b8bda9 AM |
29379 | + err = au_seq_path(seq, &path); |
29380 | + if (!err) { | |
29381 | + au_optstr_br_perm(&perm, br->br_perm); | |
29382 | + seq_printf(seq, "=%s\n", perm.a); | |
29383 | + } | |
392086de AM |
29384 | + break; |
29385 | + case AuBrSysfs_BRID: | |
79b8bda9 | 29386 | + seq_printf(seq, "%d\n", br->br_id); |
392086de AM |
29387 | + break; |
29388 | + } | |
076b876e | 29389 | + di_read_unlock(root, !AuLock_IR); |
79b8bda9 | 29390 | + if (unlikely(err || seq_has_overflowed(seq))) |
076b876e | 29391 | + err = -E2BIG; |
392086de | 29392 | + |
1e00d052 | 29393 | + return err; |
1facf9fc | 29394 | +} |
29395 | + | |
29396 | +/* ---------------------------------------------------------------------- */ | |
29397 | + | |
29398 | +static struct seq_file *au_seq(char *p, ssize_t len) | |
29399 | +{ | |
29400 | + struct seq_file *seq; | |
29401 | + | |
29402 | + seq = kzalloc(sizeof(*seq), GFP_NOFS); | |
29403 | + if (seq) { | |
29404 | + /* mutex_init(&seq.lock); */ | |
29405 | + seq->buf = p; | |
29406 | + seq->size = len; | |
29407 | + return seq; /* success */ | |
29408 | + } | |
29409 | + | |
29410 | + seq = ERR_PTR(-ENOMEM); | |
29411 | + return seq; | |
29412 | +} | |
29413 | + | |
392086de AM |
29414 | +#define SysaufsBr_PREFIX "br" |
29415 | +#define SysaufsBrid_PREFIX "brid" | |
1facf9fc | 29416 | + |
29417 | +/* todo: file size may exceed PAGE_SIZE */ | |
29418 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
1308ab2a | 29419 | + char *buf) |
1facf9fc | 29420 | +{ |
29421 | + ssize_t err; | |
392086de | 29422 | + int idx; |
1facf9fc | 29423 | + long l; |
5afbbe0d | 29424 | + aufs_bindex_t bbot; |
1facf9fc | 29425 | + struct au_sbinfo *sbinfo; |
29426 | + struct super_block *sb; | |
29427 | + struct seq_file *seq; | |
29428 | + char *name; | |
29429 | + struct attribute **cattr; | |
29430 | + | |
29431 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
29432 | + sb = sbinfo->si_sb; | |
1308ab2a | 29433 | + |
29434 | + /* | |
29435 | + * prevent a race condition between sysfs and aufs. | |
29436 | + * for instance, sysfs_file_read() calls sysfs_get_active_two() which | |
29437 | + * prohibits maintaining the sysfs entries. | |
29438 | + * hew we acquire read lock after sysfs_get_active_two(). | |
29439 | + * on the other hand, the remount process may maintain the sysfs/aufs | |
29440 | + * entries after acquiring write lock. | |
29441 | + * it can cause a deadlock. | |
29442 | + * simply we gave up processing read here. | |
29443 | + */ | |
29444 | + err = -EBUSY; | |
29445 | + if (unlikely(!si_noflush_read_trylock(sb))) | |
29446 | + goto out; | |
1facf9fc | 29447 | + |
29448 | + seq = au_seq(buf, PAGE_SIZE); | |
29449 | + err = PTR_ERR(seq); | |
29450 | + if (IS_ERR(seq)) | |
1308ab2a | 29451 | + goto out_unlock; |
1facf9fc | 29452 | + |
29453 | + name = (void *)attr->name; | |
29454 | + cattr = sysaufs_si_attrs; | |
29455 | + while (*cattr) { | |
29456 | + if (!strcmp(name, (*cattr)->name)) { | |
29457 | + err = container_of(*cattr, struct sysaufs_si_attr, attr) | |
29458 | + ->show(seq, sb); | |
29459 | + goto out_seq; | |
29460 | + } | |
29461 | + cattr++; | |
29462 | + } | |
29463 | + | |
392086de AM |
29464 | + if (!strncmp(name, SysaufsBrid_PREFIX, |
29465 | + sizeof(SysaufsBrid_PREFIX) - 1)) { | |
29466 | + idx = AuBrSysfs_BRID; | |
29467 | + name += sizeof(SysaufsBrid_PREFIX) - 1; | |
29468 | + } else if (!strncmp(name, SysaufsBr_PREFIX, | |
29469 | + sizeof(SysaufsBr_PREFIX) - 1)) { | |
29470 | + idx = AuBrSysfs_BR; | |
1facf9fc | 29471 | + name += sizeof(SysaufsBr_PREFIX) - 1; |
392086de AM |
29472 | + } else |
29473 | + BUG(); | |
29474 | + | |
29475 | + err = kstrtol(name, 10, &l); | |
29476 | + if (!err) { | |
5afbbe0d AM |
29477 | + bbot = au_sbbot(sb); |
29478 | + if (l <= bbot) | |
392086de AM |
29479 | + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx); |
29480 | + else | |
29481 | + err = -ENOENT; | |
1facf9fc | 29482 | + } |
1facf9fc | 29483 | + |
4f0767ce | 29484 | +out_seq: |
1facf9fc | 29485 | + if (!err) { |
29486 | + err = seq->count; | |
29487 | + /* sysfs limit */ | |
29488 | + if (unlikely(err == PAGE_SIZE)) | |
29489 | + err = -EFBIG; | |
29490 | + } | |
f0c0a007 | 29491 | + au_delayed_kfree(seq); |
4f0767ce | 29492 | +out_unlock: |
1facf9fc | 29493 | + si_read_unlock(sb); |
4f0767ce | 29494 | +out: |
1facf9fc | 29495 | + return err; |
29496 | +} | |
29497 | + | |
29498 | +/* ---------------------------------------------------------------------- */ | |
29499 | + | |
076b876e AM |
29500 | +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg) |
29501 | +{ | |
29502 | + int err; | |
29503 | + int16_t brid; | |
5afbbe0d | 29504 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
29505 | + size_t sz; |
29506 | + char *buf; | |
29507 | + struct seq_file *seq; | |
29508 | + struct au_branch *br; | |
29509 | + | |
29510 | + si_read_lock(sb, AuLock_FLUSH); | |
5afbbe0d AM |
29511 | + bbot = au_sbbot(sb); |
29512 | + err = bbot + 1; | |
076b876e AM |
29513 | + if (!arg) |
29514 | + goto out; | |
29515 | + | |
29516 | + err = -ENOMEM; | |
29517 | + buf = (void *)__get_free_page(GFP_NOFS); | |
29518 | + if (unlikely(!buf)) | |
29519 | + goto out; | |
29520 | + | |
29521 | + seq = au_seq(buf, PAGE_SIZE); | |
29522 | + err = PTR_ERR(seq); | |
29523 | + if (IS_ERR(seq)) | |
29524 | + goto out_buf; | |
29525 | + | |
29526 | + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path); | |
5afbbe0d | 29527 | + for (bindex = 0; bindex <= bbot; bindex++, arg++) { |
076b876e AM |
29528 | + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg)); |
29529 | + if (unlikely(err)) | |
29530 | + break; | |
29531 | + | |
29532 | + br = au_sbr(sb, bindex); | |
29533 | + brid = br->br_id; | |
29534 | + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id)); | |
29535 | + err = __put_user(brid, &arg->id); | |
29536 | + if (unlikely(err)) | |
29537 | + break; | |
29538 | + | |
29539 | + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm)); | |
29540 | + err = __put_user(br->br_perm, &arg->perm); | |
29541 | + if (unlikely(err)) | |
29542 | + break; | |
29543 | + | |
79b8bda9 AM |
29544 | + err = au_seq_path(seq, &br->br_path); |
29545 | + if (unlikely(err)) | |
29546 | + break; | |
29547 | + seq_putc(seq, '\0'); | |
29548 | + if (!seq_has_overflowed(seq)) { | |
076b876e AM |
29549 | + err = copy_to_user(arg->path, seq->buf, seq->count); |
29550 | + seq->count = 0; | |
29551 | + if (unlikely(err)) | |
29552 | + break; | |
29553 | + } else { | |
29554 | + err = -E2BIG; | |
29555 | + goto out_seq; | |
29556 | + } | |
29557 | + } | |
29558 | + if (unlikely(err)) | |
29559 | + err = -EFAULT; | |
29560 | + | |
29561 | +out_seq: | |
f0c0a007 | 29562 | + au_delayed_kfree(seq); |
076b876e | 29563 | +out_buf: |
f0c0a007 | 29564 | + au_delayed_free_page((unsigned long)buf); |
076b876e AM |
29565 | +out: |
29566 | + si_read_unlock(sb); | |
29567 | + return err; | |
29568 | +} | |
29569 | + | |
29570 | +long au_brinfo_ioctl(struct file *file, unsigned long arg) | |
29571 | +{ | |
2000de60 | 29572 | + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg); |
076b876e AM |
29573 | +} |
29574 | + | |
29575 | +#ifdef CONFIG_COMPAT | |
29576 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg) | |
29577 | +{ | |
2000de60 | 29578 | + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg)); |
076b876e AM |
29579 | +} |
29580 | +#endif | |
29581 | + | |
29582 | +/* ---------------------------------------------------------------------- */ | |
29583 | + | |
1facf9fc | 29584 | +void sysaufs_br_init(struct au_branch *br) |
29585 | +{ | |
392086de AM |
29586 | + int i; |
29587 | + struct au_brsysfs *br_sysfs; | |
29588 | + struct attribute *attr; | |
4a4d8108 | 29589 | + |
392086de AM |
29590 | + br_sysfs = br->br_sysfs; |
29591 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
29592 | + attr = &br_sysfs->attr; | |
29593 | + sysfs_attr_init(attr); | |
29594 | + attr->name = br_sysfs->name; | |
29595 | + attr->mode = S_IRUGO; | |
29596 | + br_sysfs++; | |
29597 | + } | |
1facf9fc | 29598 | +} |
29599 | + | |
29600 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
29601 | +{ | |
29602 | + struct au_branch *br; | |
29603 | + struct kobject *kobj; | |
392086de AM |
29604 | + struct au_brsysfs *br_sysfs; |
29605 | + int i; | |
5afbbe0d | 29606 | + aufs_bindex_t bbot; |
1facf9fc | 29607 | + |
29608 | + dbgaufs_brs_del(sb, bindex); | |
29609 | + | |
29610 | + if (!sysaufs_brs) | |
29611 | + return; | |
29612 | + | |
29613 | + kobj = &au_sbi(sb)->si_kobj; | |
5afbbe0d AM |
29614 | + bbot = au_sbbot(sb); |
29615 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 29616 | + br = au_sbr(sb, bindex); |
392086de AM |
29617 | + br_sysfs = br->br_sysfs; |
29618 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
29619 | + sysfs_remove_file(kobj, &br_sysfs->attr); | |
29620 | + br_sysfs++; | |
29621 | + } | |
1facf9fc | 29622 | + } |
29623 | +} | |
29624 | + | |
29625 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
29626 | +{ | |
392086de | 29627 | + int err, i; |
5afbbe0d | 29628 | + aufs_bindex_t bbot; |
1facf9fc | 29629 | + struct kobject *kobj; |
29630 | + struct au_branch *br; | |
392086de | 29631 | + struct au_brsysfs *br_sysfs; |
1facf9fc | 29632 | + |
29633 | + dbgaufs_brs_add(sb, bindex); | |
29634 | + | |
29635 | + if (!sysaufs_brs) | |
29636 | + return; | |
29637 | + | |
29638 | + kobj = &au_sbi(sb)->si_kobj; | |
5afbbe0d AM |
29639 | + bbot = au_sbbot(sb); |
29640 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 29641 | + br = au_sbr(sb, bindex); |
392086de AM |
29642 | + br_sysfs = br->br_sysfs; |
29643 | + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name), | |
29644 | + SysaufsBr_PREFIX "%d", bindex); | |
29645 | + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name), | |
29646 | + SysaufsBrid_PREFIX "%d", bindex); | |
29647 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
29648 | + err = sysfs_create_file(kobj, &br_sysfs->attr); | |
29649 | + if (unlikely(err)) | |
29650 | + pr_warn("failed %s under sysfs(%d)\n", | |
29651 | + br_sysfs->name, err); | |
29652 | + br_sysfs++; | |
29653 | + } | |
1facf9fc | 29654 | + } |
29655 | +} | |
7f207e10 AM |
29656 | diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c |
29657 | --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 29658 | +++ linux/fs/aufs/sysrq.c 2017-05-06 22:16:52.781553511 +0200 |
076b876e | 29659 | @@ -0,0 +1,157 @@ |
1facf9fc | 29660 | +/* |
a2654f78 | 29661 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 29662 | + * |
29663 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29664 | + * it under the terms of the GNU General Public License as published by | |
29665 | + * the Free Software Foundation; either version 2 of the License, or | |
29666 | + * (at your option) any later version. | |
dece6358 AM |
29667 | + * |
29668 | + * This program is distributed in the hope that it will be useful, | |
29669 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29670 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29671 | + * GNU General Public License for more details. | |
29672 | + * | |
29673 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29674 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29675 | + */ |
29676 | + | |
29677 | +/* | |
29678 | + * magic sysrq hanlder | |
29679 | + */ | |
29680 | + | |
1facf9fc | 29681 | +/* #include <linux/sysrq.h> */ |
027c5e7a | 29682 | +#include <linux/writeback.h> |
1facf9fc | 29683 | +#include "aufs.h" |
29684 | + | |
29685 | +/* ---------------------------------------------------------------------- */ | |
29686 | + | |
29687 | +static void sysrq_sb(struct super_block *sb) | |
29688 | +{ | |
29689 | + char *plevel; | |
29690 | + struct au_sbinfo *sbinfo; | |
29691 | + struct file *file; | |
523b37e3 AM |
29692 | + struct au_sphlhead *files; |
29693 | + struct au_finfo *finfo; | |
1facf9fc | 29694 | + |
29695 | + plevel = au_plevel; | |
29696 | + au_plevel = KERN_WARNING; | |
1facf9fc | 29697 | + |
4a4d8108 | 29698 | + /* since we define pr_fmt, call printk directly */ |
c06a8ce3 AM |
29699 | +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str) |
29700 | + | |
29701 | + sbinfo = au_sbi(sb); | |
4a4d8108 | 29702 | + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo)); |
c06a8ce3 | 29703 | + pr("superblock\n"); |
1facf9fc | 29704 | + au_dpri_sb(sb); |
027c5e7a AM |
29705 | + |
29706 | +#if 0 | |
c06a8ce3 | 29707 | + pr("root dentry\n"); |
1facf9fc | 29708 | + au_dpri_dentry(sb->s_root); |
c06a8ce3 | 29709 | + pr("root inode\n"); |
5527c038 | 29710 | + au_dpri_inode(d_inode(sb->s_root)); |
027c5e7a AM |
29711 | +#endif |
29712 | + | |
1facf9fc | 29713 | +#if 0 |
027c5e7a AM |
29714 | + do { |
29715 | + int err, i, j, ndentry; | |
29716 | + struct au_dcsub_pages dpages; | |
29717 | + struct au_dpage *dpage; | |
29718 | + | |
29719 | + err = au_dpages_init(&dpages, GFP_ATOMIC); | |
29720 | + if (unlikely(err)) | |
29721 | + break; | |
29722 | + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL); | |
29723 | + if (!err) | |
29724 | + for (i = 0; i < dpages.ndpage; i++) { | |
29725 | + dpage = dpages.dpages + i; | |
29726 | + ndentry = dpage->ndentry; | |
29727 | + for (j = 0; j < ndentry; j++) | |
29728 | + au_dpri_dentry(dpage->dentries[j]); | |
29729 | + } | |
29730 | + au_dpages_free(&dpages); | |
29731 | + } while (0); | |
29732 | +#endif | |
29733 | + | |
29734 | +#if 1 | |
29735 | + { | |
29736 | + struct inode *i; | |
076b876e | 29737 | + |
c06a8ce3 | 29738 | + pr("isolated inode\n"); |
79b8bda9 | 29739 | + spin_lock(&sb->s_inode_list_lock); |
2cbb1c4b JR |
29740 | + list_for_each_entry(i, &sb->s_inodes, i_sb_list) { |
29741 | + spin_lock(&i->i_lock); | |
b4510431 | 29742 | + if (1 || hlist_empty(&i->i_dentry)) |
027c5e7a | 29743 | + au_dpri_inode(i); |
2cbb1c4b JR |
29744 | + spin_unlock(&i->i_lock); |
29745 | + } | |
79b8bda9 | 29746 | + spin_unlock(&sb->s_inode_list_lock); |
027c5e7a | 29747 | + } |
1facf9fc | 29748 | +#endif |
c06a8ce3 | 29749 | + pr("files\n"); |
523b37e3 AM |
29750 | + files = &au_sbi(sb)->si_files; |
29751 | + spin_lock(&files->spin); | |
29752 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
4a4d8108 | 29753 | + umode_t mode; |
076b876e | 29754 | + |
523b37e3 | 29755 | + file = finfo->fi_file; |
c06a8ce3 | 29756 | + mode = file_inode(file)->i_mode; |
38d290e6 | 29757 | + if (!special_file(mode)) |
1facf9fc | 29758 | + au_dpri_file(file); |
523b37e3 AM |
29759 | + } |
29760 | + spin_unlock(&files->spin); | |
c06a8ce3 | 29761 | + pr("done\n"); |
1facf9fc | 29762 | + |
c06a8ce3 | 29763 | +#undef pr |
1facf9fc | 29764 | + au_plevel = plevel; |
1facf9fc | 29765 | +} |
29766 | + | |
29767 | +/* ---------------------------------------------------------------------- */ | |
29768 | + | |
29769 | +/* module parameter */ | |
29770 | +static char *aufs_sysrq_key = "a"; | |
29771 | +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO); | |
29772 | +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME); | |
29773 | + | |
0c5527e5 | 29774 | +static void au_sysrq(int key __maybe_unused) |
1facf9fc | 29775 | +{ |
1facf9fc | 29776 | + struct au_sbinfo *sbinfo; |
29777 | + | |
027c5e7a | 29778 | + lockdep_off(); |
53392da6 | 29779 | + au_sbilist_lock(); |
5afbbe0d | 29780 | + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list) |
1facf9fc | 29781 | + sysrq_sb(sbinfo->si_sb); |
53392da6 | 29782 | + au_sbilist_unlock(); |
027c5e7a | 29783 | + lockdep_on(); |
1facf9fc | 29784 | +} |
29785 | + | |
29786 | +static struct sysrq_key_op au_sysrq_op = { | |
29787 | + .handler = au_sysrq, | |
29788 | + .help_msg = "Aufs", | |
29789 | + .action_msg = "Aufs", | |
29790 | + .enable_mask = SYSRQ_ENABLE_DUMP | |
29791 | +}; | |
29792 | + | |
29793 | +/* ---------------------------------------------------------------------- */ | |
29794 | + | |
29795 | +int __init au_sysrq_init(void) | |
29796 | +{ | |
29797 | + int err; | |
29798 | + char key; | |
29799 | + | |
29800 | + err = -1; | |
29801 | + key = *aufs_sysrq_key; | |
29802 | + if ('a' <= key && key <= 'z') | |
29803 | + err = register_sysrq_key(key, &au_sysrq_op); | |
29804 | + if (unlikely(err)) | |
4a4d8108 | 29805 | + pr_err("err %d, sysrq=%c\n", err, key); |
1facf9fc | 29806 | + return err; |
29807 | +} | |
29808 | + | |
29809 | +void au_sysrq_fin(void) | |
29810 | +{ | |
29811 | + int err; | |
076b876e | 29812 | + |
1facf9fc | 29813 | + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op); |
29814 | + if (unlikely(err)) | |
4a4d8108 | 29815 | + pr_err("err %d (ignored)\n", err); |
1facf9fc | 29816 | +} |
7f207e10 AM |
29817 | diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c |
29818 | --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 29819 | +++ linux/fs/aufs/vdir.c 2017-05-06 22:16:52.781553511 +0200 |
e2f27e51 | 29820 | @@ -0,0 +1,900 @@ |
1facf9fc | 29821 | +/* |
a2654f78 | 29822 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 29823 | + * |
29824 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29825 | + * it under the terms of the GNU General Public License as published by | |
29826 | + * the Free Software Foundation; either version 2 of the License, or | |
29827 | + * (at your option) any later version. | |
dece6358 AM |
29828 | + * |
29829 | + * This program is distributed in the hope that it will be useful, | |
29830 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29831 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29832 | + * GNU General Public License for more details. | |
29833 | + * | |
29834 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29835 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29836 | + */ |
29837 | + | |
29838 | +/* | |
29839 | + * virtual or vertical directory | |
29840 | + */ | |
29841 | + | |
29842 | +#include "aufs.h" | |
29843 | + | |
dece6358 | 29844 | +static unsigned int calc_size(int nlen) |
1facf9fc | 29845 | +{ |
dece6358 | 29846 | + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t)); |
1facf9fc | 29847 | +} |
29848 | + | |
29849 | +static int set_deblk_end(union au_vdir_deblk_p *p, | |
29850 | + union au_vdir_deblk_p *deblk_end) | |
29851 | +{ | |
29852 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) { | |
29853 | + p->de->de_str.len = 0; | |
29854 | + /* smp_mb(); */ | |
29855 | + return 0; | |
29856 | + } | |
29857 | + return -1; /* error */ | |
29858 | +} | |
29859 | + | |
29860 | +/* returns true or false */ | |
29861 | +static int is_deblk_end(union au_vdir_deblk_p *p, | |
29862 | + union au_vdir_deblk_p *deblk_end) | |
29863 | +{ | |
29864 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) | |
29865 | + return !p->de->de_str.len; | |
29866 | + return 1; | |
29867 | +} | |
29868 | + | |
29869 | +static unsigned char *last_deblk(struct au_vdir *vdir) | |
29870 | +{ | |
29871 | + return vdir->vd_deblk[vdir->vd_nblk - 1]; | |
29872 | +} | |
29873 | + | |
29874 | +/* ---------------------------------------------------------------------- */ | |
29875 | + | |
79b8bda9 | 29876 | +/* estimate the appropriate size for name hash table */ |
1308ab2a | 29877 | +unsigned int au_rdhash_est(loff_t sz) |
29878 | +{ | |
29879 | + unsigned int n; | |
29880 | + | |
29881 | + n = UINT_MAX; | |
29882 | + sz >>= 10; | |
29883 | + if (sz < n) | |
29884 | + n = sz; | |
29885 | + if (sz < AUFS_RDHASH_DEF) | |
29886 | + n = AUFS_RDHASH_DEF; | |
4a4d8108 | 29887 | + /* pr_info("n %u\n", n); */ |
1308ab2a | 29888 | + return n; |
29889 | +} | |
29890 | + | |
1facf9fc | 29891 | +/* |
29892 | + * the allocated memory has to be freed by | |
dece6358 | 29893 | + * au_nhash_wh_free() or au_nhash_de_free(). |
1facf9fc | 29894 | + */ |
dece6358 | 29895 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp) |
1facf9fc | 29896 | +{ |
1facf9fc | 29897 | + struct hlist_head *head; |
dece6358 | 29898 | + unsigned int u; |
076b876e | 29899 | + size_t sz; |
1facf9fc | 29900 | + |
076b876e AM |
29901 | + sz = sizeof(*nhash->nh_head) * num_hash; |
29902 | + head = kmalloc(sz, gfp); | |
dece6358 AM |
29903 | + if (head) { |
29904 | + nhash->nh_num = num_hash; | |
29905 | + nhash->nh_head = head; | |
29906 | + for (u = 0; u < num_hash; u++) | |
1facf9fc | 29907 | + INIT_HLIST_HEAD(head++); |
dece6358 | 29908 | + return 0; /* success */ |
1facf9fc | 29909 | + } |
1facf9fc | 29910 | + |
dece6358 | 29911 | + return -ENOMEM; |
1facf9fc | 29912 | +} |
29913 | + | |
dece6358 AM |
29914 | +static void nhash_count(struct hlist_head *head) |
29915 | +{ | |
29916 | +#if 0 | |
29917 | + unsigned long n; | |
29918 | + struct hlist_node *pos; | |
29919 | + | |
29920 | + n = 0; | |
29921 | + hlist_for_each(pos, head) | |
29922 | + n++; | |
4a4d8108 | 29923 | + pr_info("%lu\n", n); |
dece6358 AM |
29924 | +#endif |
29925 | +} | |
29926 | + | |
29927 | +static void au_nhash_wh_do_free(struct hlist_head *head) | |
1facf9fc | 29928 | +{ |
c06a8ce3 AM |
29929 | + struct au_vdir_wh *pos; |
29930 | + struct hlist_node *node; | |
1facf9fc | 29931 | + |
c06a8ce3 | 29932 | + hlist_for_each_entry_safe(pos, node, head, wh_hash) |
f0c0a007 | 29933 | + au_delayed_kfree(pos); |
1facf9fc | 29934 | +} |
29935 | + | |
dece6358 | 29936 | +static void au_nhash_de_do_free(struct hlist_head *head) |
1facf9fc | 29937 | +{ |
c06a8ce3 AM |
29938 | + struct au_vdir_dehstr *pos; |
29939 | + struct hlist_node *node; | |
1facf9fc | 29940 | + |
c06a8ce3 | 29941 | + hlist_for_each_entry_safe(pos, node, head, hash) |
f0c0a007 | 29942 | + au_cache_dfree_vdir_dehstr(pos); |
1facf9fc | 29943 | +} |
29944 | + | |
dece6358 AM |
29945 | +static void au_nhash_do_free(struct au_nhash *nhash, |
29946 | + void (*free)(struct hlist_head *head)) | |
1facf9fc | 29947 | +{ |
1308ab2a | 29948 | + unsigned int n; |
1facf9fc | 29949 | + struct hlist_head *head; |
1facf9fc | 29950 | + |
dece6358 | 29951 | + n = nhash->nh_num; |
1308ab2a | 29952 | + if (!n) |
29953 | + return; | |
29954 | + | |
dece6358 | 29955 | + head = nhash->nh_head; |
1308ab2a | 29956 | + while (n-- > 0) { |
dece6358 AM |
29957 | + nhash_count(head); |
29958 | + free(head++); | |
1facf9fc | 29959 | + } |
f0c0a007 | 29960 | + au_delayed_kfree(nhash->nh_head); |
1facf9fc | 29961 | +} |
29962 | + | |
dece6358 | 29963 | +void au_nhash_wh_free(struct au_nhash *whlist) |
1facf9fc | 29964 | +{ |
dece6358 AM |
29965 | + au_nhash_do_free(whlist, au_nhash_wh_do_free); |
29966 | +} | |
1facf9fc | 29967 | + |
dece6358 AM |
29968 | +static void au_nhash_de_free(struct au_nhash *delist) |
29969 | +{ | |
29970 | + au_nhash_do_free(delist, au_nhash_de_do_free); | |
1facf9fc | 29971 | +} |
29972 | + | |
29973 | +/* ---------------------------------------------------------------------- */ | |
29974 | + | |
29975 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, | |
29976 | + int limit) | |
29977 | +{ | |
29978 | + int num; | |
29979 | + unsigned int u, n; | |
29980 | + struct hlist_head *head; | |
c06a8ce3 | 29981 | + struct au_vdir_wh *pos; |
1facf9fc | 29982 | + |
29983 | + num = 0; | |
29984 | + n = whlist->nh_num; | |
29985 | + head = whlist->nh_head; | |
1308ab2a | 29986 | + for (u = 0; u < n; u++, head++) |
c06a8ce3 AM |
29987 | + hlist_for_each_entry(pos, head, wh_hash) |
29988 | + if (pos->wh_bindex == btgt && ++num > limit) | |
1facf9fc | 29989 | + return 1; |
1facf9fc | 29990 | + return 0; |
29991 | +} | |
29992 | + | |
29993 | +static struct hlist_head *au_name_hash(struct au_nhash *nhash, | |
dece6358 | 29994 | + unsigned char *name, |
1facf9fc | 29995 | + unsigned int len) |
29996 | +{ | |
dece6358 AM |
29997 | + unsigned int v; |
29998 | + /* const unsigned int magic_bit = 12; */ | |
29999 | + | |
1308ab2a | 30000 | + AuDebugOn(!nhash->nh_num || !nhash->nh_head); |
30001 | + | |
dece6358 | 30002 | + v = 0; |
f0c0a007 AM |
30003 | + if (len > 8) |
30004 | + len = 8; | |
dece6358 AM |
30005 | + while (len--) |
30006 | + v += *name++; | |
30007 | + /* v = hash_long(v, magic_bit); */ | |
30008 | + v %= nhash->nh_num; | |
30009 | + return nhash->nh_head + v; | |
30010 | +} | |
30011 | + | |
30012 | +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name, | |
30013 | + int nlen) | |
30014 | +{ | |
30015 | + return str->len == nlen && !memcmp(str->name, name, nlen); | |
1facf9fc | 30016 | +} |
30017 | + | |
30018 | +/* returns found or not */ | |
dece6358 | 30019 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen) |
1facf9fc | 30020 | +{ |
30021 | + struct hlist_head *head; | |
c06a8ce3 | 30022 | + struct au_vdir_wh *pos; |
1facf9fc | 30023 | + struct au_vdir_destr *str; |
30024 | + | |
dece6358 | 30025 | + head = au_name_hash(whlist, name, nlen); |
c06a8ce3 AM |
30026 | + hlist_for_each_entry(pos, head, wh_hash) { |
30027 | + str = &pos->wh_str; | |
1facf9fc | 30028 | + AuDbg("%.*s\n", str->len, str->name); |
dece6358 AM |
30029 | + if (au_nhash_test_name(str, name, nlen)) |
30030 | + return 1; | |
30031 | + } | |
30032 | + return 0; | |
30033 | +} | |
30034 | + | |
30035 | +/* returns found(true) or not */ | |
30036 | +static int test_known(struct au_nhash *delist, char *name, int nlen) | |
30037 | +{ | |
30038 | + struct hlist_head *head; | |
c06a8ce3 | 30039 | + struct au_vdir_dehstr *pos; |
dece6358 AM |
30040 | + struct au_vdir_destr *str; |
30041 | + | |
30042 | + head = au_name_hash(delist, name, nlen); | |
c06a8ce3 AM |
30043 | + hlist_for_each_entry(pos, head, hash) { |
30044 | + str = pos->str; | |
dece6358 AM |
30045 | + AuDbg("%.*s\n", str->len, str->name); |
30046 | + if (au_nhash_test_name(str, name, nlen)) | |
1facf9fc | 30047 | + return 1; |
30048 | + } | |
30049 | + return 0; | |
30050 | +} | |
30051 | + | |
dece6358 AM |
30052 | +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino, |
30053 | + unsigned char d_type) | |
30054 | +{ | |
30055 | +#ifdef CONFIG_AUFS_SHWH | |
30056 | + wh->wh_ino = ino; | |
30057 | + wh->wh_type = d_type; | |
30058 | +#endif | |
30059 | +} | |
30060 | + | |
30061 | +/* ---------------------------------------------------------------------- */ | |
30062 | + | |
30063 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
30064 | + unsigned int d_type, aufs_bindex_t bindex, | |
30065 | + unsigned char shwh) | |
1facf9fc | 30066 | +{ |
30067 | + int err; | |
30068 | + struct au_vdir_destr *str; | |
30069 | + struct au_vdir_wh *wh; | |
30070 | + | |
dece6358 | 30071 | + AuDbg("%.*s\n", nlen, name); |
1308ab2a | 30072 | + AuDebugOn(!whlist->nh_num || !whlist->nh_head); |
30073 | + | |
1facf9fc | 30074 | + err = -ENOMEM; |
dece6358 | 30075 | + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS); |
1facf9fc | 30076 | + if (unlikely(!wh)) |
30077 | + goto out; | |
30078 | + | |
30079 | + err = 0; | |
30080 | + wh->wh_bindex = bindex; | |
dece6358 AM |
30081 | + if (shwh) |
30082 | + au_shwh_init_wh(wh, ino, d_type); | |
1facf9fc | 30083 | + str = &wh->wh_str; |
dece6358 AM |
30084 | + str->len = nlen; |
30085 | + memcpy(str->name, name, nlen); | |
30086 | + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen)); | |
1facf9fc | 30087 | + /* smp_mb(); */ |
30088 | + | |
4f0767ce | 30089 | +out: |
1facf9fc | 30090 | + return err; |
30091 | +} | |
30092 | + | |
1facf9fc | 30093 | +static int append_deblk(struct au_vdir *vdir) |
30094 | +{ | |
30095 | + int err; | |
dece6358 | 30096 | + unsigned long ul; |
1facf9fc | 30097 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; |
30098 | + union au_vdir_deblk_p p, deblk_end; | |
30099 | + unsigned char **o; | |
30100 | + | |
30101 | + err = -ENOMEM; | |
e2f27e51 AM |
30102 | + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1), |
30103 | + GFP_NOFS, /*may_shrink*/0); | |
1facf9fc | 30104 | + if (unlikely(!o)) |
30105 | + goto out; | |
30106 | + | |
30107 | + vdir->vd_deblk = o; | |
30108 | + p.deblk = kmalloc(deblk_sz, GFP_NOFS); | |
30109 | + if (p.deblk) { | |
30110 | + ul = vdir->vd_nblk++; | |
30111 | + vdir->vd_deblk[ul] = p.deblk; | |
30112 | + vdir->vd_last.ul = ul; | |
30113 | + vdir->vd_last.p.deblk = p.deblk; | |
30114 | + deblk_end.deblk = p.deblk + deblk_sz; | |
30115 | + err = set_deblk_end(&p, &deblk_end); | |
30116 | + } | |
30117 | + | |
4f0767ce | 30118 | +out: |
1facf9fc | 30119 | + return err; |
30120 | +} | |
30121 | + | |
dece6358 AM |
30122 | +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino, |
30123 | + unsigned int d_type, struct au_nhash *delist) | |
30124 | +{ | |
30125 | + int err; | |
30126 | + unsigned int sz; | |
30127 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; | |
30128 | + union au_vdir_deblk_p p, *room, deblk_end; | |
30129 | + struct au_vdir_dehstr *dehstr; | |
30130 | + | |
30131 | + p.deblk = last_deblk(vdir); | |
30132 | + deblk_end.deblk = p.deblk + deblk_sz; | |
30133 | + room = &vdir->vd_last.p; | |
30134 | + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk | |
30135 | + || !is_deblk_end(room, &deblk_end)); | |
30136 | + | |
30137 | + sz = calc_size(nlen); | |
30138 | + if (unlikely(sz > deblk_end.deblk - room->deblk)) { | |
30139 | + err = append_deblk(vdir); | |
30140 | + if (unlikely(err)) | |
30141 | + goto out; | |
30142 | + | |
30143 | + p.deblk = last_deblk(vdir); | |
30144 | + deblk_end.deblk = p.deblk + deblk_sz; | |
30145 | + /* smp_mb(); */ | |
30146 | + AuDebugOn(room->deblk != p.deblk); | |
30147 | + } | |
30148 | + | |
30149 | + err = -ENOMEM; | |
4a4d8108 | 30150 | + dehstr = au_cache_alloc_vdir_dehstr(); |
dece6358 AM |
30151 | + if (unlikely(!dehstr)) |
30152 | + goto out; | |
30153 | + | |
30154 | + dehstr->str = &room->de->de_str; | |
30155 | + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen)); | |
30156 | + room->de->de_ino = ino; | |
30157 | + room->de->de_type = d_type; | |
30158 | + room->de->de_str.len = nlen; | |
30159 | + memcpy(room->de->de_str.name, name, nlen); | |
30160 | + | |
30161 | + err = 0; | |
30162 | + room->deblk += sz; | |
30163 | + if (unlikely(set_deblk_end(room, &deblk_end))) | |
30164 | + err = append_deblk(vdir); | |
30165 | + /* smp_mb(); */ | |
30166 | + | |
4f0767ce | 30167 | +out: |
dece6358 AM |
30168 | + return err; |
30169 | +} | |
30170 | + | |
30171 | +/* ---------------------------------------------------------------------- */ | |
30172 | + | |
f0c0a007 | 30173 | +void au_vdir_free(struct au_vdir *vdir, int atonce) |
dece6358 AM |
30174 | +{ |
30175 | + unsigned char **deblk; | |
30176 | + | |
30177 | + deblk = vdir->vd_deblk; | |
f0c0a007 AM |
30178 | + if (!atonce) { |
30179 | + while (vdir->vd_nblk--) | |
30180 | + au_delayed_kfree(*deblk++); | |
30181 | + au_delayed_kfree(vdir->vd_deblk); | |
30182 | + au_cache_dfree_vdir(vdir); | |
30183 | + } else { | |
30184 | + /* not delayed */ | |
30185 | + while (vdir->vd_nblk--) | |
30186 | + kfree(*deblk++); | |
30187 | + kfree(vdir->vd_deblk); | |
30188 | + au_cache_free_vdir(vdir); | |
30189 | + } | |
dece6358 AM |
30190 | +} |
30191 | + | |
1308ab2a | 30192 | +static struct au_vdir *alloc_vdir(struct file *file) |
1facf9fc | 30193 | +{ |
30194 | + struct au_vdir *vdir; | |
1308ab2a | 30195 | + struct super_block *sb; |
1facf9fc | 30196 | + int err; |
30197 | + | |
2000de60 | 30198 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
30199 | + SiMustAnyLock(sb); |
30200 | + | |
1facf9fc | 30201 | + err = -ENOMEM; |
30202 | + vdir = au_cache_alloc_vdir(); | |
30203 | + if (unlikely(!vdir)) | |
30204 | + goto out; | |
30205 | + | |
30206 | + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS); | |
30207 | + if (unlikely(!vdir->vd_deblk)) | |
30208 | + goto out_free; | |
30209 | + | |
30210 | + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk; | |
1308ab2a | 30211 | + if (!vdir->vd_deblk_sz) { |
79b8bda9 | 30212 | + /* estimate the appropriate size for deblk */ |
1308ab2a | 30213 | + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL); |
4a4d8108 | 30214 | + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */ |
1308ab2a | 30215 | + } |
1facf9fc | 30216 | + vdir->vd_nblk = 0; |
30217 | + vdir->vd_version = 0; | |
30218 | + vdir->vd_jiffy = 0; | |
30219 | + err = append_deblk(vdir); | |
30220 | + if (!err) | |
30221 | + return vdir; /* success */ | |
30222 | + | |
f0c0a007 | 30223 | + au_delayed_kfree(vdir->vd_deblk); |
1facf9fc | 30224 | + |
4f0767ce | 30225 | +out_free: |
f0c0a007 | 30226 | + au_cache_dfree_vdir(vdir); |
4f0767ce | 30227 | +out: |
1facf9fc | 30228 | + vdir = ERR_PTR(err); |
30229 | + return vdir; | |
30230 | +} | |
30231 | + | |
30232 | +static int reinit_vdir(struct au_vdir *vdir) | |
30233 | +{ | |
30234 | + int err; | |
30235 | + union au_vdir_deblk_p p, deblk_end; | |
30236 | + | |
30237 | + while (vdir->vd_nblk > 1) { | |
f0c0a007 | 30238 | + au_delayed_kfree(vdir->vd_deblk[vdir->vd_nblk - 1]); |
1facf9fc | 30239 | + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */ |
30240 | + vdir->vd_nblk--; | |
30241 | + } | |
30242 | + p.deblk = vdir->vd_deblk[0]; | |
30243 | + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz; | |
30244 | + err = set_deblk_end(&p, &deblk_end); | |
30245 | + /* keep vd_dblk_sz */ | |
30246 | + vdir->vd_last.ul = 0; | |
30247 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
30248 | + vdir->vd_version = 0; | |
30249 | + vdir->vd_jiffy = 0; | |
30250 | + /* smp_mb(); */ | |
30251 | + return err; | |
30252 | +} | |
30253 | + | |
30254 | +/* ---------------------------------------------------------------------- */ | |
30255 | + | |
1facf9fc | 30256 | +#define AuFillVdir_CALLED 1 |
30257 | +#define AuFillVdir_WHABLE (1 << 1) | |
dece6358 | 30258 | +#define AuFillVdir_SHWH (1 << 2) |
1facf9fc | 30259 | +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name) |
7f207e10 AM |
30260 | +#define au_fset_fillvdir(flags, name) \ |
30261 | + do { (flags) |= AuFillVdir_##name; } while (0) | |
30262 | +#define au_fclr_fillvdir(flags, name) \ | |
30263 | + do { (flags) &= ~AuFillVdir_##name; } while (0) | |
1facf9fc | 30264 | + |
dece6358 AM |
30265 | +#ifndef CONFIG_AUFS_SHWH |
30266 | +#undef AuFillVdir_SHWH | |
30267 | +#define AuFillVdir_SHWH 0 | |
30268 | +#endif | |
30269 | + | |
1facf9fc | 30270 | +struct fillvdir_arg { |
392086de | 30271 | + struct dir_context ctx; |
1facf9fc | 30272 | + struct file *file; |
30273 | + struct au_vdir *vdir; | |
dece6358 AM |
30274 | + struct au_nhash delist; |
30275 | + struct au_nhash whlist; | |
1facf9fc | 30276 | + aufs_bindex_t bindex; |
30277 | + unsigned int flags; | |
30278 | + int err; | |
30279 | +}; | |
30280 | + | |
392086de | 30281 | +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen, |
1facf9fc | 30282 | + loff_t offset __maybe_unused, u64 h_ino, |
30283 | + unsigned int d_type) | |
30284 | +{ | |
392086de | 30285 | + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx); |
1facf9fc | 30286 | + char *name = (void *)__name; |
30287 | + struct super_block *sb; | |
1facf9fc | 30288 | + ino_t ino; |
dece6358 | 30289 | + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH); |
1facf9fc | 30290 | + |
1facf9fc | 30291 | + arg->err = 0; |
2000de60 | 30292 | + sb = arg->file->f_path.dentry->d_sb; |
1facf9fc | 30293 | + au_fset_fillvdir(arg->flags, CALLED); |
30294 | + /* smp_mb(); */ | |
dece6358 | 30295 | + if (nlen <= AUFS_WH_PFX_LEN |
1facf9fc | 30296 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { |
dece6358 AM |
30297 | + if (test_known(&arg->delist, name, nlen) |
30298 | + || au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
30299 | + goto out; /* already exists or whiteouted */ | |
1facf9fc | 30300 | + |
dece6358 | 30301 | + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino); |
4a4d8108 AM |
30302 | + if (!arg->err) { |
30303 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) | |
30304 | + d_type = DT_UNKNOWN; | |
dece6358 AM |
30305 | + arg->err = append_de(arg->vdir, name, nlen, ino, |
30306 | + d_type, &arg->delist); | |
4a4d8108 | 30307 | + } |
1facf9fc | 30308 | + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) { |
30309 | + name += AUFS_WH_PFX_LEN; | |
dece6358 AM |
30310 | + nlen -= AUFS_WH_PFX_LEN; |
30311 | + if (au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
30312 | + goto out; /* already whiteouted */ | |
1facf9fc | 30313 | + |
dece6358 AM |
30314 | + if (shwh) |
30315 | + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type, | |
30316 | + &ino); | |
4a4d8108 AM |
30317 | + if (!arg->err) { |
30318 | + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN) | |
30319 | + d_type = DT_UNKNOWN; | |
1facf9fc | 30320 | + arg->err = au_nhash_append_wh |
dece6358 AM |
30321 | + (&arg->whlist, name, nlen, ino, d_type, |
30322 | + arg->bindex, shwh); | |
4a4d8108 | 30323 | + } |
1facf9fc | 30324 | + } |
30325 | + | |
4f0767ce | 30326 | +out: |
1facf9fc | 30327 | + if (!arg->err) |
30328 | + arg->vdir->vd_jiffy = jiffies; | |
30329 | + /* smp_mb(); */ | |
30330 | + AuTraceErr(arg->err); | |
30331 | + return arg->err; | |
30332 | +} | |
30333 | + | |
dece6358 AM |
30334 | +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir, |
30335 | + struct au_nhash *whlist, struct au_nhash *delist) | |
30336 | +{ | |
30337 | +#ifdef CONFIG_AUFS_SHWH | |
30338 | + int err; | |
30339 | + unsigned int nh, u; | |
30340 | + struct hlist_head *head; | |
c06a8ce3 AM |
30341 | + struct au_vdir_wh *pos; |
30342 | + struct hlist_node *n; | |
dece6358 AM |
30343 | + char *p, *o; |
30344 | + struct au_vdir_destr *destr; | |
30345 | + | |
30346 | + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH)); | |
30347 | + | |
30348 | + err = -ENOMEM; | |
537831f9 | 30349 | + o = p = (void *)__get_free_page(GFP_NOFS); |
dece6358 AM |
30350 | + if (unlikely(!p)) |
30351 | + goto out; | |
30352 | + | |
30353 | + err = 0; | |
30354 | + nh = whlist->nh_num; | |
30355 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
30356 | + p += AUFS_WH_PFX_LEN; | |
30357 | + for (u = 0; u < nh; u++) { | |
30358 | + head = whlist->nh_head + u; | |
c06a8ce3 AM |
30359 | + hlist_for_each_entry_safe(pos, n, head, wh_hash) { |
30360 | + destr = &pos->wh_str; | |
dece6358 AM |
30361 | + memcpy(p, destr->name, destr->len); |
30362 | + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN, | |
c06a8ce3 | 30363 | + pos->wh_ino, pos->wh_type, delist); |
dece6358 AM |
30364 | + if (unlikely(err)) |
30365 | + break; | |
30366 | + } | |
30367 | + } | |
30368 | + | |
f0c0a007 | 30369 | + au_delayed_free_page((unsigned long)o); |
dece6358 | 30370 | + |
4f0767ce | 30371 | +out: |
dece6358 AM |
30372 | + AuTraceErr(err); |
30373 | + return err; | |
30374 | +#else | |
30375 | + return 0; | |
30376 | +#endif | |
30377 | +} | |
30378 | + | |
1facf9fc | 30379 | +static int au_do_read_vdir(struct fillvdir_arg *arg) |
30380 | +{ | |
30381 | + int err; | |
dece6358 | 30382 | + unsigned int rdhash; |
1facf9fc | 30383 | + loff_t offset; |
5afbbe0d | 30384 | + aufs_bindex_t bbot, bindex, btop; |
dece6358 | 30385 | + unsigned char shwh; |
1facf9fc | 30386 | + struct file *hf, *file; |
30387 | + struct super_block *sb; | |
30388 | + | |
1facf9fc | 30389 | + file = arg->file; |
2000de60 | 30390 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
30391 | + SiMustAnyLock(sb); |
30392 | + | |
30393 | + rdhash = au_sbi(sb)->si_rdhash; | |
1308ab2a | 30394 | + if (!rdhash) |
30395 | + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL)); | |
dece6358 AM |
30396 | + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS); |
30397 | + if (unlikely(err)) | |
1facf9fc | 30398 | + goto out; |
dece6358 AM |
30399 | + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS); |
30400 | + if (unlikely(err)) | |
1facf9fc | 30401 | + goto out_delist; |
30402 | + | |
30403 | + err = 0; | |
30404 | + arg->flags = 0; | |
dece6358 AM |
30405 | + shwh = 0; |
30406 | + if (au_opt_test(au_mntflags(sb), SHWH)) { | |
30407 | + shwh = 1; | |
30408 | + au_fset_fillvdir(arg->flags, SHWH); | |
30409 | + } | |
5afbbe0d AM |
30410 | + btop = au_fbtop(file); |
30411 | + bbot = au_fbbot_dir(file); | |
30412 | + for (bindex = btop; !err && bindex <= bbot; bindex++) { | |
4a4d8108 | 30413 | + hf = au_hf_dir(file, bindex); |
1facf9fc | 30414 | + if (!hf) |
30415 | + continue; | |
30416 | + | |
30417 | + offset = vfsub_llseek(hf, 0, SEEK_SET); | |
30418 | + err = offset; | |
30419 | + if (unlikely(offset)) | |
30420 | + break; | |
30421 | + | |
30422 | + arg->bindex = bindex; | |
30423 | + au_fclr_fillvdir(arg->flags, WHABLE); | |
dece6358 | 30424 | + if (shwh |
5afbbe0d | 30425 | + || (bindex != bbot |
dece6358 | 30426 | + && au_br_whable(au_sbr_perm(sb, bindex)))) |
1facf9fc | 30427 | + au_fset_fillvdir(arg->flags, WHABLE); |
30428 | + do { | |
30429 | + arg->err = 0; | |
30430 | + au_fclr_fillvdir(arg->flags, CALLED); | |
30431 | + /* smp_mb(); */ | |
392086de | 30432 | + err = vfsub_iterate_dir(hf, &arg->ctx); |
1facf9fc | 30433 | + if (err >= 0) |
30434 | + err = arg->err; | |
30435 | + } while (!err && au_ftest_fillvdir(arg->flags, CALLED)); | |
392086de AM |
30436 | + |
30437 | + /* | |
30438 | + * dir_relax() may be good for concurrency, but aufs should not | |
30439 | + * use it since it will cause a lockdep problem. | |
30440 | + */ | |
1facf9fc | 30441 | + } |
dece6358 AM |
30442 | + |
30443 | + if (!err && shwh) | |
30444 | + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist); | |
30445 | + | |
30446 | + au_nhash_wh_free(&arg->whlist); | |
1facf9fc | 30447 | + |
4f0767ce | 30448 | +out_delist: |
dece6358 | 30449 | + au_nhash_de_free(&arg->delist); |
4f0767ce | 30450 | +out: |
1facf9fc | 30451 | + return err; |
30452 | +} | |
30453 | + | |
30454 | +static int read_vdir(struct file *file, int may_read) | |
30455 | +{ | |
30456 | + int err; | |
30457 | + unsigned long expire; | |
30458 | + unsigned char do_read; | |
392086de AM |
30459 | + struct fillvdir_arg arg = { |
30460 | + .ctx = { | |
2000de60 | 30461 | + .actor = fillvdir |
392086de AM |
30462 | + } |
30463 | + }; | |
1facf9fc | 30464 | + struct inode *inode; |
30465 | + struct au_vdir *vdir, *allocated; | |
30466 | + | |
30467 | + err = 0; | |
c06a8ce3 | 30468 | + inode = file_inode(file); |
1facf9fc | 30469 | + IMustLock(inode); |
5afbbe0d | 30470 | + IiMustWriteLock(inode); |
dece6358 AM |
30471 | + SiMustAnyLock(inode->i_sb); |
30472 | + | |
1facf9fc | 30473 | + allocated = NULL; |
30474 | + do_read = 0; | |
30475 | + expire = au_sbi(inode->i_sb)->si_rdcache; | |
30476 | + vdir = au_ivdir(inode); | |
30477 | + if (!vdir) { | |
30478 | + do_read = 1; | |
1308ab2a | 30479 | + vdir = alloc_vdir(file); |
1facf9fc | 30480 | + err = PTR_ERR(vdir); |
30481 | + if (IS_ERR(vdir)) | |
30482 | + goto out; | |
30483 | + err = 0; | |
30484 | + allocated = vdir; | |
30485 | + } else if (may_read | |
30486 | + && (inode->i_version != vdir->vd_version | |
30487 | + || time_after(jiffies, vdir->vd_jiffy + expire))) { | |
30488 | + do_read = 1; | |
30489 | + err = reinit_vdir(vdir); | |
30490 | + if (unlikely(err)) | |
30491 | + goto out; | |
30492 | + } | |
30493 | + | |
30494 | + if (!do_read) | |
30495 | + return 0; /* success */ | |
30496 | + | |
30497 | + arg.file = file; | |
30498 | + arg.vdir = vdir; | |
30499 | + err = au_do_read_vdir(&arg); | |
30500 | + if (!err) { | |
392086de | 30501 | + /* file->f_pos = 0; */ /* todo: ctx->pos? */ |
1facf9fc | 30502 | + vdir->vd_version = inode->i_version; |
30503 | + vdir->vd_last.ul = 0; | |
30504 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
30505 | + if (allocated) | |
30506 | + au_set_ivdir(inode, allocated); | |
30507 | + } else if (allocated) | |
f0c0a007 | 30508 | + au_vdir_free(allocated, /*atonce*/0); |
1facf9fc | 30509 | + |
4f0767ce | 30510 | +out: |
1facf9fc | 30511 | + return err; |
30512 | +} | |
30513 | + | |
30514 | +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src) | |
30515 | +{ | |
30516 | + int err, rerr; | |
30517 | + unsigned long ul, n; | |
30518 | + const unsigned int deblk_sz = src->vd_deblk_sz; | |
30519 | + | |
30520 | + AuDebugOn(tgt->vd_nblk != 1); | |
30521 | + | |
30522 | + err = -ENOMEM; | |
30523 | + if (tgt->vd_nblk < src->vd_nblk) { | |
30524 | + unsigned char **p; | |
30525 | + | |
e2f27e51 AM |
30526 | + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk, |
30527 | + GFP_NOFS, /*may_shrink*/0); | |
1facf9fc | 30528 | + if (unlikely(!p)) |
30529 | + goto out; | |
30530 | + tgt->vd_deblk = p; | |
30531 | + } | |
30532 | + | |
1308ab2a | 30533 | + if (tgt->vd_deblk_sz != deblk_sz) { |
30534 | + unsigned char *p; | |
30535 | + | |
30536 | + tgt->vd_deblk_sz = deblk_sz; | |
e2f27e51 AM |
30537 | + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS, |
30538 | + /*may_shrink*/1); | |
1308ab2a | 30539 | + if (unlikely(!p)) |
30540 | + goto out; | |
30541 | + tgt->vd_deblk[0] = p; | |
30542 | + } | |
1facf9fc | 30543 | + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz); |
1facf9fc | 30544 | + tgt->vd_version = src->vd_version; |
30545 | + tgt->vd_jiffy = src->vd_jiffy; | |
30546 | + | |
30547 | + n = src->vd_nblk; | |
30548 | + for (ul = 1; ul < n; ul++) { | |
dece6358 AM |
30549 | + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz, |
30550 | + GFP_NOFS); | |
30551 | + if (unlikely(!tgt->vd_deblk[ul])) | |
1facf9fc | 30552 | + goto out; |
1308ab2a | 30553 | + tgt->vd_nblk++; |
1facf9fc | 30554 | + } |
1308ab2a | 30555 | + tgt->vd_nblk = n; |
30556 | + tgt->vd_last.ul = tgt->vd_last.ul; | |
30557 | + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul]; | |
30558 | + tgt->vd_last.p.deblk += src->vd_last.p.deblk | |
30559 | + - src->vd_deblk[src->vd_last.ul]; | |
1facf9fc | 30560 | + /* smp_mb(); */ |
30561 | + return 0; /* success */ | |
30562 | + | |
4f0767ce | 30563 | +out: |
1facf9fc | 30564 | + rerr = reinit_vdir(tgt); |
30565 | + BUG_ON(rerr); | |
30566 | + return err; | |
30567 | +} | |
30568 | + | |
30569 | +int au_vdir_init(struct file *file) | |
30570 | +{ | |
30571 | + int err; | |
30572 | + struct inode *inode; | |
30573 | + struct au_vdir *vdir_cache, *allocated; | |
30574 | + | |
392086de | 30575 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 30576 | + err = read_vdir(file, !file->f_pos); |
30577 | + if (unlikely(err)) | |
30578 | + goto out; | |
30579 | + | |
30580 | + allocated = NULL; | |
30581 | + vdir_cache = au_fvdir_cache(file); | |
30582 | + if (!vdir_cache) { | |
1308ab2a | 30583 | + vdir_cache = alloc_vdir(file); |
1facf9fc | 30584 | + err = PTR_ERR(vdir_cache); |
30585 | + if (IS_ERR(vdir_cache)) | |
30586 | + goto out; | |
30587 | + allocated = vdir_cache; | |
30588 | + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) { | |
392086de | 30589 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 30590 | + err = reinit_vdir(vdir_cache); |
30591 | + if (unlikely(err)) | |
30592 | + goto out; | |
30593 | + } else | |
30594 | + return 0; /* success */ | |
30595 | + | |
c06a8ce3 | 30596 | + inode = file_inode(file); |
1facf9fc | 30597 | + err = copy_vdir(vdir_cache, au_ivdir(inode)); |
30598 | + if (!err) { | |
30599 | + file->f_version = inode->i_version; | |
30600 | + if (allocated) | |
30601 | + au_set_fvdir_cache(file, allocated); | |
30602 | + } else if (allocated) | |
f0c0a007 | 30603 | + au_vdir_free(allocated, /*atonce*/0); |
1facf9fc | 30604 | + |
4f0767ce | 30605 | +out: |
1facf9fc | 30606 | + return err; |
30607 | +} | |
30608 | + | |
30609 | +static loff_t calc_offset(struct au_vdir *vdir) | |
30610 | +{ | |
30611 | + loff_t offset; | |
30612 | + union au_vdir_deblk_p p; | |
30613 | + | |
30614 | + p.deblk = vdir->vd_deblk[vdir->vd_last.ul]; | |
30615 | + offset = vdir->vd_last.p.deblk - p.deblk; | |
30616 | + offset += vdir->vd_deblk_sz * vdir->vd_last.ul; | |
30617 | + return offset; | |
30618 | +} | |
30619 | + | |
30620 | +/* returns true or false */ | |
392086de | 30621 | +static int seek_vdir(struct file *file, struct dir_context *ctx) |
1facf9fc | 30622 | +{ |
30623 | + int valid; | |
30624 | + unsigned int deblk_sz; | |
30625 | + unsigned long ul, n; | |
30626 | + loff_t offset; | |
30627 | + union au_vdir_deblk_p p, deblk_end; | |
30628 | + struct au_vdir *vdir_cache; | |
30629 | + | |
30630 | + valid = 1; | |
30631 | + vdir_cache = au_fvdir_cache(file); | |
30632 | + offset = calc_offset(vdir_cache); | |
30633 | + AuDbg("offset %lld\n", offset); | |
392086de | 30634 | + if (ctx->pos == offset) |
1facf9fc | 30635 | + goto out; |
30636 | + | |
30637 | + vdir_cache->vd_last.ul = 0; | |
30638 | + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0]; | |
392086de | 30639 | + if (!ctx->pos) |
1facf9fc | 30640 | + goto out; |
30641 | + | |
30642 | + valid = 0; | |
30643 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
392086de | 30644 | + ul = div64_u64(ctx->pos, deblk_sz); |
1facf9fc | 30645 | + AuDbg("ul %lu\n", ul); |
30646 | + if (ul >= vdir_cache->vd_nblk) | |
30647 | + goto out; | |
30648 | + | |
30649 | + n = vdir_cache->vd_nblk; | |
30650 | + for (; ul < n; ul++) { | |
30651 | + p.deblk = vdir_cache->vd_deblk[ul]; | |
30652 | + deblk_end.deblk = p.deblk + deblk_sz; | |
30653 | + offset = ul; | |
30654 | + offset *= deblk_sz; | |
392086de | 30655 | + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) { |
1facf9fc | 30656 | + unsigned int l; |
30657 | + | |
30658 | + l = calc_size(p.de->de_str.len); | |
30659 | + offset += l; | |
30660 | + p.deblk += l; | |
30661 | + } | |
30662 | + if (!is_deblk_end(&p, &deblk_end)) { | |
30663 | + valid = 1; | |
30664 | + vdir_cache->vd_last.ul = ul; | |
30665 | + vdir_cache->vd_last.p = p; | |
30666 | + break; | |
30667 | + } | |
30668 | + } | |
30669 | + | |
4f0767ce | 30670 | +out: |
1facf9fc | 30671 | + /* smp_mb(); */ |
30672 | + AuTraceErr(!valid); | |
30673 | + return valid; | |
30674 | +} | |
30675 | + | |
392086de | 30676 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx) |
1facf9fc | 30677 | +{ |
1facf9fc | 30678 | + unsigned int l, deblk_sz; |
30679 | + union au_vdir_deblk_p deblk_end; | |
30680 | + struct au_vdir *vdir_cache; | |
30681 | + struct au_vdir_de *de; | |
30682 | + | |
30683 | + vdir_cache = au_fvdir_cache(file); | |
392086de | 30684 | + if (!seek_vdir(file, ctx)) |
1facf9fc | 30685 | + return 0; |
30686 | + | |
30687 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
30688 | + while (1) { | |
30689 | + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
30690 | + deblk_end.deblk += deblk_sz; | |
30691 | + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) { | |
30692 | + de = vdir_cache->vd_last.p.de; | |
30693 | + AuDbg("%.*s, off%lld, i%lu, dt%d\n", | |
392086de | 30694 | + de->de_str.len, de->de_str.name, ctx->pos, |
1facf9fc | 30695 | + (unsigned long)de->de_ino, de->de_type); |
392086de AM |
30696 | + if (unlikely(!dir_emit(ctx, de->de_str.name, |
30697 | + de->de_str.len, de->de_ino, | |
30698 | + de->de_type))) { | |
1facf9fc | 30699 | + /* todo: ignore the error caused by udba? */ |
30700 | + /* return err; */ | |
30701 | + return 0; | |
30702 | + } | |
30703 | + | |
30704 | + l = calc_size(de->de_str.len); | |
30705 | + vdir_cache->vd_last.p.deblk += l; | |
392086de | 30706 | + ctx->pos += l; |
1facf9fc | 30707 | + } |
30708 | + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) { | |
30709 | + vdir_cache->vd_last.ul++; | |
30710 | + vdir_cache->vd_last.p.deblk | |
30711 | + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
392086de | 30712 | + ctx->pos = deblk_sz * vdir_cache->vd_last.ul; |
1facf9fc | 30713 | + continue; |
30714 | + } | |
30715 | + break; | |
30716 | + } | |
30717 | + | |
30718 | + /* smp_mb(); */ | |
30719 | + return 0; | |
30720 | +} | |
7f207e10 AM |
30721 | diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c |
30722 | --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 30723 | +++ linux/fs/aufs/vfsub.c 2017-05-06 22:16:52.781553511 +0200 |
a2654f78 | 30724 | @@ -0,0 +1,899 @@ |
1facf9fc | 30725 | +/* |
a2654f78 | 30726 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 30727 | + * |
30728 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30729 | + * it under the terms of the GNU General Public License as published by | |
30730 | + * the Free Software Foundation; either version 2 of the License, or | |
30731 | + * (at your option) any later version. | |
dece6358 AM |
30732 | + * |
30733 | + * This program is distributed in the hope that it will be useful, | |
30734 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30735 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30736 | + * GNU General Public License for more details. | |
30737 | + * | |
30738 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30739 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30740 | + */ |
30741 | + | |
30742 | +/* | |
30743 | + * sub-routines for VFS | |
30744 | + */ | |
30745 | + | |
dece6358 | 30746 | +#include <linux/namei.h> |
8cdd5066 | 30747 | +#include <linux/nsproxy.h> |
dece6358 AM |
30748 | +#include <linux/security.h> |
30749 | +#include <linux/splice.h> | |
f2c43d5f | 30750 | +#ifdef CONFIG_AUFS_BR_FUSE |
8cdd5066 | 30751 | +#include "../fs/mount.h" |
f2c43d5f | 30752 | +#endif |
1facf9fc | 30753 | +#include "aufs.h" |
30754 | + | |
8cdd5066 JR |
30755 | +#ifdef CONFIG_AUFS_BR_FUSE |
30756 | +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb) | |
30757 | +{ | |
30758 | + struct nsproxy *ns; | |
30759 | + | |
30760 | + if (!au_test_fuse(h_sb) || !au_userns) | |
30761 | + return 0; | |
30762 | + | |
30763 | + ns = current->nsproxy; | |
30764 | + /* no {get,put}_nsproxy(ns) */ | |
30765 | + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES; | |
30766 | +} | |
30767 | +#endif | |
30768 | + | |
a2654f78 AM |
30769 | +int vfsub_sync_filesystem(struct super_block *h_sb, int wait) |
30770 | +{ | |
30771 | + int err; | |
30772 | + | |
30773 | + lockdep_off(); | |
30774 | + down_read(&h_sb->s_umount); | |
30775 | + err = __sync_filesystem(h_sb, wait); | |
30776 | + up_read(&h_sb->s_umount); | |
30777 | + lockdep_on(); | |
30778 | + | |
30779 | + return err; | |
30780 | +} | |
30781 | + | |
8cdd5066 JR |
30782 | +/* ---------------------------------------------------------------------- */ |
30783 | + | |
1facf9fc | 30784 | +int vfsub_update_h_iattr(struct path *h_path, int *did) |
30785 | +{ | |
30786 | + int err; | |
30787 | + struct kstat st; | |
30788 | + struct super_block *h_sb; | |
30789 | + | |
30790 | + /* for remote fs, leave work for its getattr or d_revalidate */ | |
30791 | + /* for bad i_attr fs, handle them in aufs_getattr() */ | |
30792 | + /* still some fs may acquire i_mutex. we need to skip them */ | |
30793 | + err = 0; | |
30794 | + if (!did) | |
30795 | + did = &err; | |
30796 | + h_sb = h_path->dentry->d_sb; | |
30797 | + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb)); | |
30798 | + if (*did) | |
521ced18 | 30799 | + err = vfsub_getattr(h_path, &st); |
1facf9fc | 30800 | + |
30801 | + return err; | |
30802 | +} | |
30803 | + | |
30804 | +/* ---------------------------------------------------------------------- */ | |
30805 | + | |
4a4d8108 | 30806 | +struct file *vfsub_dentry_open(struct path *path, int flags) |
1308ab2a | 30807 | +{ |
30808 | + struct file *file; | |
30809 | + | |
b4510431 | 30810 | + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */, |
7f207e10 | 30811 | + current_cred()); |
2cbb1c4b JR |
30812 | + if (!IS_ERR_OR_NULL(file) |
30813 | + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | |
5527c038 | 30814 | + i_readcount_inc(d_inode(path->dentry)); |
4a4d8108 | 30815 | + |
1308ab2a | 30816 | + return file; |
30817 | +} | |
30818 | + | |
1facf9fc | 30819 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode) |
30820 | +{ | |
30821 | + struct file *file; | |
30822 | + | |
2cbb1c4b | 30823 | + lockdep_off(); |
7f207e10 | 30824 | + file = filp_open(path, |
2cbb1c4b | 30825 | + oflags /* | __FMODE_NONOTIFY */, |
7f207e10 | 30826 | + mode); |
2cbb1c4b | 30827 | + lockdep_on(); |
1facf9fc | 30828 | + if (IS_ERR(file)) |
30829 | + goto out; | |
30830 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30831 | + | |
4f0767ce | 30832 | +out: |
1facf9fc | 30833 | + return file; |
30834 | +} | |
30835 | + | |
b912730e AM |
30836 | +/* |
30837 | + * Ideally this function should call VFS:do_last() in order to keep all its | |
30838 | + * checkings. But it is very hard for aufs to regenerate several VFS internal | |
30839 | + * structure such as nameidata. This is a second (or third) best approach. | |
30840 | + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open(). | |
30841 | + */ | |
30842 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
30843 | + struct vfsub_aopen_args *args, struct au_branch *br) | |
30844 | +{ | |
30845 | + int err; | |
30846 | + struct file *file = args->file; | |
30847 | + /* copied from linux/fs/namei.c:atomic_open() */ | |
30848 | + struct dentry *const DENTRY_NOT_SET = (void *)-1UL; | |
30849 | + | |
30850 | + IMustLock(dir); | |
30851 | + AuDebugOn(!dir->i_op->atomic_open); | |
30852 | + | |
30853 | + err = au_br_test_oflag(args->open_flag, br); | |
30854 | + if (unlikely(err)) | |
30855 | + goto out; | |
30856 | + | |
30857 | + args->file->f_path.dentry = DENTRY_NOT_SET; | |
30858 | + args->file->f_path.mnt = au_br_mnt(br); | |
30859 | + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag, | |
30860 | + args->create_mode, args->opened); | |
30861 | + if (err >= 0) { | |
30862 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
30863 | + if (*args->opened & FILE_CREATED) | |
30864 | + fsnotify_create(dir, dentry); | |
30865 | + } else | |
30866 | + goto out; | |
30867 | + | |
30868 | + | |
30869 | + if (!err) { | |
30870 | + /* todo: call VFS:may_open() here */ | |
30871 | + err = open_check_o_direct(file); | |
30872 | + /* todo: ima_file_check() too? */ | |
30873 | + if (!err && (args->open_flag & __FMODE_EXEC)) | |
30874 | + err = deny_write_access(file); | |
30875 | + if (unlikely(err)) | |
30876 | + /* note that the file is created and still opened */ | |
30877 | + goto out; | |
30878 | + } | |
30879 | + | |
5afbbe0d | 30880 | + au_br_get(br); |
b912730e AM |
30881 | + fsnotify_open(file); |
30882 | + | |
30883 | +out: | |
30884 | + return err; | |
30885 | +} | |
30886 | + | |
1facf9fc | 30887 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path) |
30888 | +{ | |
30889 | + int err; | |
30890 | + | |
1facf9fc | 30891 | + err = kern_path(name, flags, path); |
5527c038 | 30892 | + if (!err && d_is_positive(path->dentry)) |
1facf9fc | 30893 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ |
30894 | + return err; | |
30895 | +} | |
30896 | + | |
febd17d6 JR |
30897 | +struct dentry *vfsub_lookup_one_len_unlocked(const char *name, |
30898 | + struct dentry *parent, int len) | |
30899 | +{ | |
30900 | + struct path path = { | |
30901 | + .mnt = NULL | |
30902 | + }; | |
30903 | + | |
30904 | + path.dentry = lookup_one_len_unlocked(name, parent, len); | |
30905 | + if (IS_ERR(path.dentry)) | |
30906 | + goto out; | |
30907 | + if (d_is_positive(path.dentry)) | |
30908 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ | |
30909 | + | |
30910 | +out: | |
30911 | + AuTraceErrPtr(path.dentry); | |
30912 | + return path.dentry; | |
30913 | +} | |
30914 | + | |
1facf9fc | 30915 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
30916 | + int len) | |
30917 | +{ | |
30918 | + struct path path = { | |
30919 | + .mnt = NULL | |
30920 | + }; | |
30921 | + | |
1308ab2a | 30922 | + /* VFS checks it too, but by WARN_ON_ONCE() */ |
5527c038 | 30923 | + IMustLock(d_inode(parent)); |
1facf9fc | 30924 | + |
30925 | + path.dentry = lookup_one_len(name, parent, len); | |
30926 | + if (IS_ERR(path.dentry)) | |
30927 | + goto out; | |
5527c038 | 30928 | + if (d_is_positive(path.dentry)) |
1facf9fc | 30929 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ |
30930 | + | |
4f0767ce | 30931 | +out: |
4a4d8108 | 30932 | + AuTraceErrPtr(path.dentry); |
1facf9fc | 30933 | + return path.dentry; |
30934 | +} | |
30935 | + | |
b4510431 | 30936 | +void vfsub_call_lkup_one(void *args) |
2cbb1c4b | 30937 | +{ |
b4510431 AM |
30938 | + struct vfsub_lkup_one_args *a = args; |
30939 | + *a->errp = vfsub_lkup_one(a->name, a->parent); | |
2cbb1c4b JR |
30940 | +} |
30941 | + | |
1facf9fc | 30942 | +/* ---------------------------------------------------------------------- */ |
30943 | + | |
30944 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30945 | + struct dentry *d2, struct au_hinode *hdir2) | |
30946 | +{ | |
30947 | + struct dentry *d; | |
30948 | + | |
2cbb1c4b | 30949 | + lockdep_off(); |
1facf9fc | 30950 | + d = lock_rename(d1, d2); |
2cbb1c4b | 30951 | + lockdep_on(); |
4a4d8108 | 30952 | + au_hn_suspend(hdir1); |
1facf9fc | 30953 | + if (hdir1 != hdir2) |
4a4d8108 | 30954 | + au_hn_suspend(hdir2); |
1facf9fc | 30955 | + |
30956 | + return d; | |
30957 | +} | |
30958 | + | |
30959 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30960 | + struct dentry *d2, struct au_hinode *hdir2) | |
30961 | +{ | |
4a4d8108 | 30962 | + au_hn_resume(hdir1); |
1facf9fc | 30963 | + if (hdir1 != hdir2) |
4a4d8108 | 30964 | + au_hn_resume(hdir2); |
2cbb1c4b | 30965 | + lockdep_off(); |
1facf9fc | 30966 | + unlock_rename(d1, d2); |
2cbb1c4b | 30967 | + lockdep_on(); |
1facf9fc | 30968 | +} |
30969 | + | |
30970 | +/* ---------------------------------------------------------------------- */ | |
30971 | + | |
b4510431 | 30972 | +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl) |
1facf9fc | 30973 | +{ |
30974 | + int err; | |
30975 | + struct dentry *d; | |
30976 | + | |
30977 | + IMustLock(dir); | |
30978 | + | |
30979 | + d = path->dentry; | |
30980 | + path->dentry = d->d_parent; | |
b752ccd1 | 30981 | + err = security_path_mknod(path, d, mode, 0); |
1facf9fc | 30982 | + path->dentry = d; |
30983 | + if (unlikely(err)) | |
30984 | + goto out; | |
30985 | + | |
c1595e42 | 30986 | + lockdep_off(); |
b4510431 | 30987 | + err = vfs_create(dir, path->dentry, mode, want_excl); |
c1595e42 | 30988 | + lockdep_on(); |
1facf9fc | 30989 | + if (!err) { |
30990 | + struct path tmp = *path; | |
30991 | + int did; | |
30992 | + | |
30993 | + vfsub_update_h_iattr(&tmp, &did); | |
30994 | + if (did) { | |
30995 | + tmp.dentry = path->dentry->d_parent; | |
30996 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30997 | + } | |
30998 | + /*ignore*/ | |
30999 | + } | |
31000 | + | |
4f0767ce | 31001 | +out: |
1facf9fc | 31002 | + return err; |
31003 | +} | |
31004 | + | |
31005 | +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname) | |
31006 | +{ | |
31007 | + int err; | |
31008 | + struct dentry *d; | |
31009 | + | |
31010 | + IMustLock(dir); | |
31011 | + | |
31012 | + d = path->dentry; | |
31013 | + path->dentry = d->d_parent; | |
b752ccd1 | 31014 | + err = security_path_symlink(path, d, symname); |
1facf9fc | 31015 | + path->dentry = d; |
31016 | + if (unlikely(err)) | |
31017 | + goto out; | |
31018 | + | |
c1595e42 | 31019 | + lockdep_off(); |
1facf9fc | 31020 | + err = vfs_symlink(dir, path->dentry, symname); |
c1595e42 | 31021 | + lockdep_on(); |
1facf9fc | 31022 | + if (!err) { |
31023 | + struct path tmp = *path; | |
31024 | + int did; | |
31025 | + | |
31026 | + vfsub_update_h_iattr(&tmp, &did); | |
31027 | + if (did) { | |
31028 | + tmp.dentry = path->dentry->d_parent; | |
31029 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
31030 | + } | |
31031 | + /*ignore*/ | |
31032 | + } | |
31033 | + | |
4f0767ce | 31034 | +out: |
1facf9fc | 31035 | + return err; |
31036 | +} | |
31037 | + | |
31038 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev) | |
31039 | +{ | |
31040 | + int err; | |
31041 | + struct dentry *d; | |
31042 | + | |
31043 | + IMustLock(dir); | |
31044 | + | |
31045 | + d = path->dentry; | |
31046 | + path->dentry = d->d_parent; | |
027c5e7a | 31047 | + err = security_path_mknod(path, d, mode, new_encode_dev(dev)); |
1facf9fc | 31048 | + path->dentry = d; |
31049 | + if (unlikely(err)) | |
31050 | + goto out; | |
31051 | + | |
c1595e42 | 31052 | + lockdep_off(); |
1facf9fc | 31053 | + err = vfs_mknod(dir, path->dentry, mode, dev); |
c1595e42 | 31054 | + lockdep_on(); |
1facf9fc | 31055 | + if (!err) { |
31056 | + struct path tmp = *path; | |
31057 | + int did; | |
31058 | + | |
31059 | + vfsub_update_h_iattr(&tmp, &did); | |
31060 | + if (did) { | |
31061 | + tmp.dentry = path->dentry->d_parent; | |
31062 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
31063 | + } | |
31064 | + /*ignore*/ | |
31065 | + } | |
31066 | + | |
4f0767ce | 31067 | +out: |
1facf9fc | 31068 | + return err; |
31069 | +} | |
31070 | + | |
31071 | +static int au_test_nlink(struct inode *inode) | |
31072 | +{ | |
31073 | + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */ | |
31074 | + | |
31075 | + if (!au_test_fs_no_limit_nlink(inode->i_sb) | |
31076 | + || inode->i_nlink < link_max) | |
31077 | + return 0; | |
31078 | + return -EMLINK; | |
31079 | +} | |
31080 | + | |
523b37e3 AM |
31081 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path, |
31082 | + struct inode **delegated_inode) | |
1facf9fc | 31083 | +{ |
31084 | + int err; | |
31085 | + struct dentry *d; | |
31086 | + | |
31087 | + IMustLock(dir); | |
31088 | + | |
5527c038 | 31089 | + err = au_test_nlink(d_inode(src_dentry)); |
1facf9fc | 31090 | + if (unlikely(err)) |
31091 | + return err; | |
31092 | + | |
b4510431 | 31093 | + /* we don't call may_linkat() */ |
1facf9fc | 31094 | + d = path->dentry; |
31095 | + path->dentry = d->d_parent; | |
b752ccd1 | 31096 | + err = security_path_link(src_dentry, path, d); |
1facf9fc | 31097 | + path->dentry = d; |
31098 | + if (unlikely(err)) | |
31099 | + goto out; | |
31100 | + | |
2cbb1c4b | 31101 | + lockdep_off(); |
523b37e3 | 31102 | + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode); |
2cbb1c4b | 31103 | + lockdep_on(); |
1facf9fc | 31104 | + if (!err) { |
31105 | + struct path tmp = *path; | |
31106 | + int did; | |
31107 | + | |
31108 | + /* fuse has different memory inode for the same inumber */ | |
31109 | + vfsub_update_h_iattr(&tmp, &did); | |
31110 | + if (did) { | |
31111 | + tmp.dentry = path->dentry->d_parent; | |
31112 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
31113 | + tmp.dentry = src_dentry; | |
31114 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
31115 | + } | |
31116 | + /*ignore*/ | |
31117 | + } | |
31118 | + | |
4f0767ce | 31119 | +out: |
1facf9fc | 31120 | + return err; |
31121 | +} | |
31122 | + | |
31123 | +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry, | |
523b37e3 | 31124 | + struct inode *dir, struct path *path, |
f2c43d5f | 31125 | + struct inode **delegated_inode, unsigned int flags) |
1facf9fc | 31126 | +{ |
31127 | + int err; | |
31128 | + struct path tmp = { | |
31129 | + .mnt = path->mnt | |
31130 | + }; | |
31131 | + struct dentry *d; | |
31132 | + | |
31133 | + IMustLock(dir); | |
31134 | + IMustLock(src_dir); | |
31135 | + | |
31136 | + d = path->dentry; | |
31137 | + path->dentry = d->d_parent; | |
31138 | + tmp.dentry = src_dentry->d_parent; | |
38d290e6 | 31139 | + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0); |
1facf9fc | 31140 | + path->dentry = d; |
31141 | + if (unlikely(err)) | |
31142 | + goto out; | |
31143 | + | |
2cbb1c4b | 31144 | + lockdep_off(); |
523b37e3 | 31145 | + err = vfs_rename(src_dir, src_dentry, dir, path->dentry, |
f2c43d5f | 31146 | + delegated_inode, flags); |
2cbb1c4b | 31147 | + lockdep_on(); |
1facf9fc | 31148 | + if (!err) { |
31149 | + int did; | |
31150 | + | |
31151 | + tmp.dentry = d->d_parent; | |
31152 | + vfsub_update_h_iattr(&tmp, &did); | |
31153 | + if (did) { | |
31154 | + tmp.dentry = src_dentry; | |
31155 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
31156 | + tmp.dentry = src_dentry->d_parent; | |
31157 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
31158 | + } | |
31159 | + /*ignore*/ | |
31160 | + } | |
31161 | + | |
4f0767ce | 31162 | +out: |
1facf9fc | 31163 | + return err; |
31164 | +} | |
31165 | + | |
31166 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode) | |
31167 | +{ | |
31168 | + int err; | |
31169 | + struct dentry *d; | |
31170 | + | |
31171 | + IMustLock(dir); | |
31172 | + | |
31173 | + d = path->dentry; | |
31174 | + path->dentry = d->d_parent; | |
b752ccd1 | 31175 | + err = security_path_mkdir(path, d, mode); |
1facf9fc | 31176 | + path->dentry = d; |
31177 | + if (unlikely(err)) | |
31178 | + goto out; | |
31179 | + | |
c1595e42 | 31180 | + lockdep_off(); |
1facf9fc | 31181 | + err = vfs_mkdir(dir, path->dentry, mode); |
c1595e42 | 31182 | + lockdep_on(); |
1facf9fc | 31183 | + if (!err) { |
31184 | + struct path tmp = *path; | |
31185 | + int did; | |
31186 | + | |
31187 | + vfsub_update_h_iattr(&tmp, &did); | |
31188 | + if (did) { | |
31189 | + tmp.dentry = path->dentry->d_parent; | |
31190 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
31191 | + } | |
31192 | + /*ignore*/ | |
31193 | + } | |
31194 | + | |
4f0767ce | 31195 | +out: |
1facf9fc | 31196 | + return err; |
31197 | +} | |
31198 | + | |
31199 | +int vfsub_rmdir(struct inode *dir, struct path *path) | |
31200 | +{ | |
31201 | + int err; | |
31202 | + struct dentry *d; | |
31203 | + | |
31204 | + IMustLock(dir); | |
31205 | + | |
31206 | + d = path->dentry; | |
31207 | + path->dentry = d->d_parent; | |
b752ccd1 | 31208 | + err = security_path_rmdir(path, d); |
1facf9fc | 31209 | + path->dentry = d; |
31210 | + if (unlikely(err)) | |
31211 | + goto out; | |
31212 | + | |
2cbb1c4b | 31213 | + lockdep_off(); |
1facf9fc | 31214 | + err = vfs_rmdir(dir, path->dentry); |
2cbb1c4b | 31215 | + lockdep_on(); |
1facf9fc | 31216 | + if (!err) { |
31217 | + struct path tmp = { | |
31218 | + .dentry = path->dentry->d_parent, | |
31219 | + .mnt = path->mnt | |
31220 | + }; | |
31221 | + | |
31222 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
31223 | + } | |
31224 | + | |
4f0767ce | 31225 | +out: |
1facf9fc | 31226 | + return err; |
31227 | +} | |
31228 | + | |
31229 | +/* ---------------------------------------------------------------------- */ | |
31230 | + | |
9dbd164d | 31231 | +/* todo: support mmap_sem? */ |
1facf9fc | 31232 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, |
31233 | + loff_t *ppos) | |
31234 | +{ | |
31235 | + ssize_t err; | |
31236 | + | |
2cbb1c4b | 31237 | + lockdep_off(); |
1facf9fc | 31238 | + err = vfs_read(file, ubuf, count, ppos); |
2cbb1c4b | 31239 | + lockdep_on(); |
1facf9fc | 31240 | + if (err >= 0) |
31241 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
31242 | + return err; | |
31243 | +} | |
31244 | + | |
31245 | +/* todo: kernel_read()? */ | |
31246 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
31247 | + loff_t *ppos) | |
31248 | +{ | |
31249 | + ssize_t err; | |
31250 | + mm_segment_t oldfs; | |
b752ccd1 AM |
31251 | + union { |
31252 | + void *k; | |
31253 | + char __user *u; | |
31254 | + } buf; | |
1facf9fc | 31255 | + |
b752ccd1 | 31256 | + buf.k = kbuf; |
1facf9fc | 31257 | + oldfs = get_fs(); |
31258 | + set_fs(KERNEL_DS); | |
b752ccd1 | 31259 | + err = vfsub_read_u(file, buf.u, count, ppos); |
1facf9fc | 31260 | + set_fs(oldfs); |
31261 | + return err; | |
31262 | +} | |
31263 | + | |
31264 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
31265 | + loff_t *ppos) | |
31266 | +{ | |
31267 | + ssize_t err; | |
31268 | + | |
2cbb1c4b | 31269 | + lockdep_off(); |
1facf9fc | 31270 | + err = vfs_write(file, ubuf, count, ppos); |
2cbb1c4b | 31271 | + lockdep_on(); |
1facf9fc | 31272 | + if (err >= 0) |
31273 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
31274 | + return err; | |
31275 | +} | |
31276 | + | |
31277 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos) | |
31278 | +{ | |
31279 | + ssize_t err; | |
31280 | + mm_segment_t oldfs; | |
b752ccd1 AM |
31281 | + union { |
31282 | + void *k; | |
31283 | + const char __user *u; | |
31284 | + } buf; | |
1facf9fc | 31285 | + |
b752ccd1 | 31286 | + buf.k = kbuf; |
1facf9fc | 31287 | + oldfs = get_fs(); |
31288 | + set_fs(KERNEL_DS); | |
b752ccd1 | 31289 | + err = vfsub_write_u(file, buf.u, count, ppos); |
1facf9fc | 31290 | + set_fs(oldfs); |
31291 | + return err; | |
31292 | +} | |
31293 | + | |
4a4d8108 AM |
31294 | +int vfsub_flush(struct file *file, fl_owner_t id) |
31295 | +{ | |
31296 | + int err; | |
31297 | + | |
31298 | + err = 0; | |
523b37e3 | 31299 | + if (file->f_op->flush) { |
2000de60 | 31300 | + if (!au_test_nfs(file->f_path.dentry->d_sb)) |
2cbb1c4b JR |
31301 | + err = file->f_op->flush(file, id); |
31302 | + else { | |
31303 | + lockdep_off(); | |
31304 | + err = file->f_op->flush(file, id); | |
31305 | + lockdep_on(); | |
31306 | + } | |
4a4d8108 AM |
31307 | + if (!err) |
31308 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); | |
31309 | + /*ignore*/ | |
31310 | + } | |
31311 | + return err; | |
31312 | +} | |
31313 | + | |
392086de | 31314 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx) |
1facf9fc | 31315 | +{ |
31316 | + int err; | |
31317 | + | |
523b37e3 | 31318 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 31319 | + |
2cbb1c4b | 31320 | + lockdep_off(); |
392086de | 31321 | + err = iterate_dir(file, ctx); |
2cbb1c4b | 31322 | + lockdep_on(); |
1facf9fc | 31323 | + if (err >= 0) |
31324 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
31325 | + return err; | |
31326 | +} | |
31327 | + | |
31328 | +long vfsub_splice_to(struct file *in, loff_t *ppos, | |
31329 | + struct pipe_inode_info *pipe, size_t len, | |
31330 | + unsigned int flags) | |
31331 | +{ | |
31332 | + long err; | |
31333 | + | |
2cbb1c4b | 31334 | + lockdep_off(); |
0fc653ad | 31335 | + err = do_splice_to(in, ppos, pipe, len, flags); |
2cbb1c4b | 31336 | + lockdep_on(); |
4a4d8108 | 31337 | + file_accessed(in); |
1facf9fc | 31338 | + if (err >= 0) |
31339 | + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/ | |
31340 | + return err; | |
31341 | +} | |
31342 | + | |
31343 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
31344 | + loff_t *ppos, size_t len, unsigned int flags) | |
31345 | +{ | |
31346 | + long err; | |
31347 | + | |
2cbb1c4b | 31348 | + lockdep_off(); |
0fc653ad | 31349 | + err = do_splice_from(pipe, out, ppos, len, flags); |
2cbb1c4b | 31350 | + lockdep_on(); |
1facf9fc | 31351 | + if (err >= 0) |
31352 | + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/ | |
31353 | + return err; | |
31354 | +} | |
31355 | + | |
53392da6 AM |
31356 | +int vfsub_fsync(struct file *file, struct path *path, int datasync) |
31357 | +{ | |
31358 | + int err; | |
31359 | + | |
31360 | + /* file can be NULL */ | |
31361 | + lockdep_off(); | |
31362 | + err = vfs_fsync(file, datasync); | |
31363 | + lockdep_on(); | |
31364 | + if (!err) { | |
31365 | + if (!path) { | |
31366 | + AuDebugOn(!file); | |
31367 | + path = &file->f_path; | |
31368 | + } | |
31369 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ | |
31370 | + } | |
31371 | + return err; | |
31372 | +} | |
31373 | + | |
1facf9fc | 31374 | +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */ |
31375 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, | |
31376 | + struct file *h_file) | |
31377 | +{ | |
31378 | + int err; | |
31379 | + struct inode *h_inode; | |
c06a8ce3 | 31380 | + struct super_block *h_sb; |
1facf9fc | 31381 | + |
1facf9fc | 31382 | + if (!h_file) { |
c06a8ce3 AM |
31383 | + err = vfsub_truncate(h_path, length); |
31384 | + goto out; | |
1facf9fc | 31385 | + } |
31386 | + | |
5527c038 | 31387 | + h_inode = d_inode(h_path->dentry); |
c06a8ce3 AM |
31388 | + h_sb = h_inode->i_sb; |
31389 | + lockdep_off(); | |
31390 | + sb_start_write(h_sb); | |
31391 | + lockdep_on(); | |
1facf9fc | 31392 | + err = locks_verify_truncate(h_inode, h_file, length); |
31393 | + if (!err) | |
953406b4 | 31394 | + err = security_path_truncate(h_path); |
2cbb1c4b JR |
31395 | + if (!err) { |
31396 | + lockdep_off(); | |
1facf9fc | 31397 | + err = do_truncate(h_path->dentry, length, attr, h_file); |
2cbb1c4b JR |
31398 | + lockdep_on(); |
31399 | + } | |
c06a8ce3 AM |
31400 | + lockdep_off(); |
31401 | + sb_end_write(h_sb); | |
31402 | + lockdep_on(); | |
1facf9fc | 31403 | + |
4f0767ce | 31404 | +out: |
1facf9fc | 31405 | + return err; |
31406 | +} | |
31407 | + | |
31408 | +/* ---------------------------------------------------------------------- */ | |
31409 | + | |
31410 | +struct au_vfsub_mkdir_args { | |
31411 | + int *errp; | |
31412 | + struct inode *dir; | |
31413 | + struct path *path; | |
31414 | + int mode; | |
31415 | +}; | |
31416 | + | |
31417 | +static void au_call_vfsub_mkdir(void *args) | |
31418 | +{ | |
31419 | + struct au_vfsub_mkdir_args *a = args; | |
31420 | + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode); | |
31421 | +} | |
31422 | + | |
31423 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode) | |
31424 | +{ | |
31425 | + int err, do_sio, wkq_err; | |
31426 | + | |
31427 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
31428 | + if (!do_sio) { |
31429 | + lockdep_off(); | |
1facf9fc | 31430 | + err = vfsub_mkdir(dir, path, mode); |
c1595e42 JR |
31431 | + lockdep_on(); |
31432 | + } else { | |
1facf9fc | 31433 | + struct au_vfsub_mkdir_args args = { |
31434 | + .errp = &err, | |
31435 | + .dir = dir, | |
31436 | + .path = path, | |
31437 | + .mode = mode | |
31438 | + }; | |
31439 | + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args); | |
31440 | + if (unlikely(wkq_err)) | |
31441 | + err = wkq_err; | |
31442 | + } | |
31443 | + | |
31444 | + return err; | |
31445 | +} | |
31446 | + | |
31447 | +struct au_vfsub_rmdir_args { | |
31448 | + int *errp; | |
31449 | + struct inode *dir; | |
31450 | + struct path *path; | |
31451 | +}; | |
31452 | + | |
31453 | +static void au_call_vfsub_rmdir(void *args) | |
31454 | +{ | |
31455 | + struct au_vfsub_rmdir_args *a = args; | |
31456 | + *a->errp = vfsub_rmdir(a->dir, a->path); | |
31457 | +} | |
31458 | + | |
31459 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path) | |
31460 | +{ | |
31461 | + int err, do_sio, wkq_err; | |
31462 | + | |
31463 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
31464 | + if (!do_sio) { |
31465 | + lockdep_off(); | |
1facf9fc | 31466 | + err = vfsub_rmdir(dir, path); |
c1595e42 JR |
31467 | + lockdep_on(); |
31468 | + } else { | |
1facf9fc | 31469 | + struct au_vfsub_rmdir_args args = { |
31470 | + .errp = &err, | |
31471 | + .dir = dir, | |
31472 | + .path = path | |
31473 | + }; | |
31474 | + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args); | |
31475 | + if (unlikely(wkq_err)) | |
31476 | + err = wkq_err; | |
31477 | + } | |
31478 | + | |
31479 | + return err; | |
31480 | +} | |
31481 | + | |
31482 | +/* ---------------------------------------------------------------------- */ | |
31483 | + | |
31484 | +struct notify_change_args { | |
31485 | + int *errp; | |
31486 | + struct path *path; | |
31487 | + struct iattr *ia; | |
523b37e3 | 31488 | + struct inode **delegated_inode; |
1facf9fc | 31489 | +}; |
31490 | + | |
31491 | +static void call_notify_change(void *args) | |
31492 | +{ | |
31493 | + struct notify_change_args *a = args; | |
31494 | + struct inode *h_inode; | |
31495 | + | |
5527c038 | 31496 | + h_inode = d_inode(a->path->dentry); |
1facf9fc | 31497 | + IMustLock(h_inode); |
31498 | + | |
31499 | + *a->errp = -EPERM; | |
31500 | + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) { | |
c1595e42 | 31501 | + lockdep_off(); |
523b37e3 AM |
31502 | + *a->errp = notify_change(a->path->dentry, a->ia, |
31503 | + a->delegated_inode); | |
c1595e42 | 31504 | + lockdep_on(); |
1facf9fc | 31505 | + if (!*a->errp) |
31506 | + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/ | |
31507 | + } | |
31508 | + AuTraceErr(*a->errp); | |
31509 | +} | |
31510 | + | |
523b37e3 AM |
31511 | +int vfsub_notify_change(struct path *path, struct iattr *ia, |
31512 | + struct inode **delegated_inode) | |
1facf9fc | 31513 | +{ |
31514 | + int err; | |
31515 | + struct notify_change_args args = { | |
523b37e3 AM |
31516 | + .errp = &err, |
31517 | + .path = path, | |
31518 | + .ia = ia, | |
31519 | + .delegated_inode = delegated_inode | |
1facf9fc | 31520 | + }; |
31521 | + | |
31522 | + call_notify_change(&args); | |
31523 | + | |
31524 | + return err; | |
31525 | +} | |
31526 | + | |
523b37e3 AM |
31527 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
31528 | + struct inode **delegated_inode) | |
1facf9fc | 31529 | +{ |
31530 | + int err, wkq_err; | |
31531 | + struct notify_change_args args = { | |
523b37e3 AM |
31532 | + .errp = &err, |
31533 | + .path = path, | |
31534 | + .ia = ia, | |
31535 | + .delegated_inode = delegated_inode | |
1facf9fc | 31536 | + }; |
31537 | + | |
31538 | + wkq_err = au_wkq_wait(call_notify_change, &args); | |
31539 | + if (unlikely(wkq_err)) | |
31540 | + err = wkq_err; | |
31541 | + | |
31542 | + return err; | |
31543 | +} | |
31544 | + | |
31545 | +/* ---------------------------------------------------------------------- */ | |
31546 | + | |
31547 | +struct unlink_args { | |
31548 | + int *errp; | |
31549 | + struct inode *dir; | |
31550 | + struct path *path; | |
523b37e3 | 31551 | + struct inode **delegated_inode; |
1facf9fc | 31552 | +}; |
31553 | + | |
31554 | +static void call_unlink(void *args) | |
31555 | +{ | |
31556 | + struct unlink_args *a = args; | |
31557 | + struct dentry *d = a->path->dentry; | |
31558 | + struct inode *h_inode; | |
31559 | + const int stop_sillyrename = (au_test_nfs(d->d_sb) | |
c1595e42 | 31560 | + && au_dcount(d) == 1); |
1facf9fc | 31561 | + |
31562 | + IMustLock(a->dir); | |
31563 | + | |
31564 | + a->path->dentry = d->d_parent; | |
31565 | + *a->errp = security_path_unlink(a->path, d); | |
31566 | + a->path->dentry = d; | |
31567 | + if (unlikely(*a->errp)) | |
31568 | + return; | |
31569 | + | |
31570 | + if (!stop_sillyrename) | |
31571 | + dget(d); | |
5527c038 JR |
31572 | + h_inode = NULL; |
31573 | + if (d_is_positive(d)) { | |
31574 | + h_inode = d_inode(d); | |
027c5e7a | 31575 | + ihold(h_inode); |
5527c038 | 31576 | + } |
1facf9fc | 31577 | + |
2cbb1c4b | 31578 | + lockdep_off(); |
523b37e3 | 31579 | + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode); |
2cbb1c4b | 31580 | + lockdep_on(); |
1facf9fc | 31581 | + if (!*a->errp) { |
31582 | + struct path tmp = { | |
31583 | + .dentry = d->d_parent, | |
31584 | + .mnt = a->path->mnt | |
31585 | + }; | |
31586 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
31587 | + } | |
31588 | + | |
31589 | + if (!stop_sillyrename) | |
31590 | + dput(d); | |
31591 | + if (h_inode) | |
31592 | + iput(h_inode); | |
31593 | + | |
31594 | + AuTraceErr(*a->errp); | |
31595 | +} | |
31596 | + | |
31597 | +/* | |
31598 | + * @dir: must be locked. | |
31599 | + * @dentry: target dentry. | |
31600 | + */ | |
523b37e3 AM |
31601 | +int vfsub_unlink(struct inode *dir, struct path *path, |
31602 | + struct inode **delegated_inode, int force) | |
1facf9fc | 31603 | +{ |
31604 | + int err; | |
31605 | + struct unlink_args args = { | |
523b37e3 AM |
31606 | + .errp = &err, |
31607 | + .dir = dir, | |
31608 | + .path = path, | |
31609 | + .delegated_inode = delegated_inode | |
1facf9fc | 31610 | + }; |
31611 | + | |
31612 | + if (!force) | |
31613 | + call_unlink(&args); | |
31614 | + else { | |
31615 | + int wkq_err; | |
31616 | + | |
31617 | + wkq_err = au_wkq_wait(call_unlink, &args); | |
31618 | + if (unlikely(wkq_err)) | |
31619 | + err = wkq_err; | |
31620 | + } | |
31621 | + | |
31622 | + return err; | |
31623 | +} | |
7f207e10 AM |
31624 | diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h |
31625 | --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
31626 | +++ linux/fs/aufs/vfsub.h 2017-05-06 22:16:52.781553511 +0200 |
31627 | @@ -0,0 +1,353 @@ | |
1facf9fc | 31628 | +/* |
a2654f78 | 31629 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 31630 | + * |
31631 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31632 | + * it under the terms of the GNU General Public License as published by | |
31633 | + * the Free Software Foundation; either version 2 of the License, or | |
31634 | + * (at your option) any later version. | |
dece6358 AM |
31635 | + * |
31636 | + * This program is distributed in the hope that it will be useful, | |
31637 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31638 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31639 | + * GNU General Public License for more details. | |
31640 | + * | |
31641 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31642 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31643 | + */ |
31644 | + | |
31645 | +/* | |
31646 | + * sub-routines for VFS | |
31647 | + */ | |
31648 | + | |
31649 | +#ifndef __AUFS_VFSUB_H__ | |
31650 | +#define __AUFS_VFSUB_H__ | |
31651 | + | |
31652 | +#ifdef __KERNEL__ | |
31653 | + | |
31654 | +#include <linux/fs.h> | |
b4510431 | 31655 | +#include <linux/mount.h> |
8cdd5066 | 31656 | +#include <linux/posix_acl.h> |
c1595e42 | 31657 | +#include <linux/xattr.h> |
7f207e10 | 31658 | +#include "debug.h" |
1facf9fc | 31659 | + |
7f207e10 | 31660 | +/* copied from linux/fs/internal.h */ |
2cbb1c4b | 31661 | +/* todo: BAD approach!! */ |
c06a8ce3 | 31662 | +extern void __mnt_drop_write(struct vfsmount *); |
b912730e | 31663 | +extern int open_check_o_direct(struct file *f); |
7f207e10 AM |
31664 | + |
31665 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 31666 | + |
31667 | +/* lock subclass for lower inode */ | |
31668 | +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */ | |
31669 | +/* reduce? gave up. */ | |
31670 | +enum { | |
c1595e42 | 31671 | + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */ |
1facf9fc | 31672 | + AuLsc_I_PARENT, /* lower inode, parent first */ |
31673 | + AuLsc_I_PARENT2, /* copyup dirs */ | |
dece6358 | 31674 | + AuLsc_I_PARENT3, /* copyup wh */ |
1facf9fc | 31675 | + AuLsc_I_CHILD, |
31676 | + AuLsc_I_CHILD2, | |
31677 | + AuLsc_I_End | |
31678 | +}; | |
31679 | + | |
31680 | +/* to debug easier, do not make them inlined functions */ | |
31681 | +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx)) | |
febd17d6 | 31682 | +#define IMustLock(i) AuDebugOn(!inode_is_locked(i)) |
1facf9fc | 31683 | + |
31684 | +/* ---------------------------------------------------------------------- */ | |
31685 | + | |
7f207e10 AM |
31686 | +static inline void vfsub_drop_nlink(struct inode *inode) |
31687 | +{ | |
31688 | + AuDebugOn(!inode->i_nlink); | |
31689 | + drop_nlink(inode); | |
31690 | +} | |
31691 | + | |
027c5e7a AM |
31692 | +static inline void vfsub_dead_dir(struct inode *inode) |
31693 | +{ | |
31694 | + AuDebugOn(!S_ISDIR(inode->i_mode)); | |
31695 | + inode->i_flags |= S_DEAD; | |
31696 | + clear_nlink(inode); | |
31697 | +} | |
31698 | + | |
392086de AM |
31699 | +static inline int vfsub_native_ro(struct inode *inode) |
31700 | +{ | |
31701 | + return (inode->i_sb->s_flags & MS_RDONLY) | |
31702 | + || IS_RDONLY(inode) | |
31703 | + /* || IS_APPEND(inode) */ | |
31704 | + || IS_IMMUTABLE(inode); | |
31705 | +} | |
31706 | + | |
8cdd5066 JR |
31707 | +#ifdef CONFIG_AUFS_BR_FUSE |
31708 | +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb); | |
31709 | +#else | |
31710 | +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb); | |
31711 | +#endif | |
31712 | + | |
a2654f78 AM |
31713 | +int vfsub_sync_filesystem(struct super_block *h_sb, int wait); |
31714 | + | |
7f207e10 AM |
31715 | +/* ---------------------------------------------------------------------- */ |
31716 | + | |
31717 | +int vfsub_update_h_iattr(struct path *h_path, int *did); | |
31718 | +struct file *vfsub_dentry_open(struct path *path, int flags); | |
31719 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode); | |
b912730e AM |
31720 | +struct vfsub_aopen_args { |
31721 | + struct file *file; | |
31722 | + unsigned int open_flag; | |
31723 | + umode_t create_mode; | |
31724 | + int *opened; | |
31725 | +}; | |
31726 | +struct au_branch; | |
31727 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
31728 | + struct vfsub_aopen_args *args, struct au_branch *br); | |
1facf9fc | 31729 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path); |
b4510431 | 31730 | + |
febd17d6 JR |
31731 | +struct dentry *vfsub_lookup_one_len_unlocked(const char *name, |
31732 | + struct dentry *parent, int len); | |
1facf9fc | 31733 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
31734 | + int len); | |
b4510431 AM |
31735 | + |
31736 | +struct vfsub_lkup_one_args { | |
31737 | + struct dentry **errp; | |
31738 | + struct qstr *name; | |
31739 | + struct dentry *parent; | |
31740 | +}; | |
31741 | + | |
31742 | +static inline struct dentry *vfsub_lkup_one(struct qstr *name, | |
31743 | + struct dentry *parent) | |
31744 | +{ | |
31745 | + return vfsub_lookup_one_len(name->name, parent, name->len); | |
31746 | +} | |
31747 | + | |
31748 | +void vfsub_call_lkup_one(void *args); | |
31749 | + | |
31750 | +/* ---------------------------------------------------------------------- */ | |
31751 | + | |
31752 | +static inline int vfsub_mnt_want_write(struct vfsmount *mnt) | |
31753 | +{ | |
31754 | + int err; | |
076b876e | 31755 | + |
b4510431 AM |
31756 | + lockdep_off(); |
31757 | + err = mnt_want_write(mnt); | |
31758 | + lockdep_on(); | |
31759 | + return err; | |
31760 | +} | |
31761 | + | |
31762 | +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt) | |
31763 | +{ | |
31764 | + lockdep_off(); | |
31765 | + mnt_drop_write(mnt); | |
31766 | + lockdep_on(); | |
31767 | +} | |
1facf9fc | 31768 | + |
7e9cd9fe | 31769 | +#if 0 /* reserved */ |
c06a8ce3 AM |
31770 | +static inline void vfsub_mnt_drop_write_file(struct file *file) |
31771 | +{ | |
31772 | + lockdep_off(); | |
31773 | + mnt_drop_write_file(file); | |
31774 | + lockdep_on(); | |
31775 | +} | |
7e9cd9fe | 31776 | +#endif |
c06a8ce3 | 31777 | + |
1facf9fc | 31778 | +/* ---------------------------------------------------------------------- */ |
31779 | + | |
31780 | +struct au_hinode; | |
31781 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
31782 | + struct dentry *d2, struct au_hinode *hdir2); | |
31783 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
31784 | + struct dentry *d2, struct au_hinode *hdir2); | |
31785 | + | |
537831f9 AM |
31786 | +int vfsub_create(struct inode *dir, struct path *path, int mode, |
31787 | + bool want_excl); | |
1facf9fc | 31788 | +int vfsub_symlink(struct inode *dir, struct path *path, |
31789 | + const char *symname); | |
31790 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev); | |
31791 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, | |
523b37e3 | 31792 | + struct path *path, struct inode **delegated_inode); |
1facf9fc | 31793 | +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry, |
523b37e3 | 31794 | + struct inode *hdir, struct path *path, |
f2c43d5f | 31795 | + struct inode **delegated_inode, unsigned int flags); |
1facf9fc | 31796 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode); |
31797 | +int vfsub_rmdir(struct inode *dir, struct path *path); | |
31798 | + | |
31799 | +/* ---------------------------------------------------------------------- */ | |
31800 | + | |
31801 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, | |
31802 | + loff_t *ppos); | |
31803 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
31804 | + loff_t *ppos); | |
31805 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
31806 | + loff_t *ppos); | |
31807 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, | |
31808 | + loff_t *ppos); | |
4a4d8108 | 31809 | +int vfsub_flush(struct file *file, fl_owner_t id); |
392086de AM |
31810 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx); |
31811 | + | |
c06a8ce3 AM |
31812 | +static inline loff_t vfsub_f_size_read(struct file *file) |
31813 | +{ | |
31814 | + return i_size_read(file_inode(file)); | |
31815 | +} | |
31816 | + | |
4a4d8108 AM |
31817 | +static inline unsigned int vfsub_file_flags(struct file *file) |
31818 | +{ | |
31819 | + unsigned int flags; | |
31820 | + | |
31821 | + spin_lock(&file->f_lock); | |
31822 | + flags = file->f_flags; | |
31823 | + spin_unlock(&file->f_lock); | |
31824 | + | |
31825 | + return flags; | |
31826 | +} | |
1308ab2a | 31827 | + |
f0c0a007 AM |
31828 | +static inline int vfsub_file_execed(struct file *file) |
31829 | +{ | |
31830 | + /* todo: direct access f_flags */ | |
31831 | + return !!(vfsub_file_flags(file) & __FMODE_EXEC); | |
31832 | +} | |
31833 | + | |
7e9cd9fe | 31834 | +#if 0 /* reserved */ |
1facf9fc | 31835 | +static inline void vfsub_file_accessed(struct file *h_file) |
31836 | +{ | |
31837 | + file_accessed(h_file); | |
31838 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/ | |
31839 | +} | |
7e9cd9fe | 31840 | +#endif |
1facf9fc | 31841 | + |
79b8bda9 | 31842 | +#if 0 /* reserved */ |
1facf9fc | 31843 | +static inline void vfsub_touch_atime(struct vfsmount *h_mnt, |
31844 | + struct dentry *h_dentry) | |
31845 | +{ | |
31846 | + struct path h_path = { | |
31847 | + .dentry = h_dentry, | |
31848 | + .mnt = h_mnt | |
31849 | + }; | |
92d182d2 | 31850 | + touch_atime(&h_path); |
1facf9fc | 31851 | + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/ |
31852 | +} | |
79b8bda9 | 31853 | +#endif |
1facf9fc | 31854 | + |
0c3ec466 AM |
31855 | +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts, |
31856 | + int flags) | |
31857 | +{ | |
5afbbe0d | 31858 | + return update_time(h_inode, ts, flags); |
0c3ec466 AM |
31859 | + /* no vfsub_update_h_iattr() since we don't have struct path */ |
31860 | +} | |
31861 | + | |
8cdd5066 JR |
31862 | +#ifdef CONFIG_FS_POSIX_ACL |
31863 | +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode) | |
31864 | +{ | |
31865 | + int err; | |
31866 | + | |
31867 | + err = posix_acl_chmod(h_inode, h_mode); | |
31868 | + if (err == -EOPNOTSUPP) | |
31869 | + err = 0; | |
31870 | + return err; | |
31871 | +} | |
31872 | +#else | |
31873 | +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode); | |
31874 | +#endif | |
31875 | + | |
4a4d8108 AM |
31876 | +long vfsub_splice_to(struct file *in, loff_t *ppos, |
31877 | + struct pipe_inode_info *pipe, size_t len, | |
31878 | + unsigned int flags); | |
31879 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
31880 | + loff_t *ppos, size_t len, unsigned int flags); | |
c06a8ce3 AM |
31881 | + |
31882 | +static inline long vfsub_truncate(struct path *path, loff_t length) | |
31883 | +{ | |
31884 | + long err; | |
076b876e | 31885 | + |
c06a8ce3 AM |
31886 | + lockdep_off(); |
31887 | + err = vfs_truncate(path, length); | |
31888 | + lockdep_on(); | |
31889 | + return err; | |
31890 | +} | |
31891 | + | |
4a4d8108 AM |
31892 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, |
31893 | + struct file *h_file); | |
53392da6 | 31894 | +int vfsub_fsync(struct file *file, struct path *path, int datasync); |
4a4d8108 | 31895 | + |
521ced18 JR |
31896 | +/* |
31897 | + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such | |
31898 | + * ioctl. | |
31899 | + */ | |
31900 | +static inline int vfsub_clone_file_range(struct file *src, struct file *dst, | |
31901 | + u64 len) | |
31902 | +{ | |
31903 | + int err; | |
31904 | + | |
31905 | + lockdep_off(); | |
31906 | + err = vfs_clone_file_range(src, 0, dst, 0, len); | |
31907 | + lockdep_on(); | |
31908 | + | |
31909 | + return err; | |
31910 | +} | |
31911 | + | |
31912 | +/* copy_file_range(2) is a systemcall */ | |
31913 | +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos, | |
31914 | + struct file *dst, loff_t dst_pos, | |
31915 | + size_t len, unsigned int flags) | |
31916 | +{ | |
31917 | + ssize_t ssz; | |
31918 | + | |
31919 | + lockdep_off(); | |
31920 | + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags); | |
31921 | + lockdep_on(); | |
31922 | + | |
31923 | + return ssz; | |
31924 | +} | |
31925 | + | |
1facf9fc | 31926 | +/* ---------------------------------------------------------------------- */ |
31927 | + | |
31928 | +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin) | |
31929 | +{ | |
31930 | + loff_t err; | |
31931 | + | |
2cbb1c4b | 31932 | + lockdep_off(); |
1facf9fc | 31933 | + err = vfs_llseek(file, offset, origin); |
2cbb1c4b | 31934 | + lockdep_on(); |
1facf9fc | 31935 | + return err; |
31936 | +} | |
31937 | + | |
31938 | +/* ---------------------------------------------------------------------- */ | |
31939 | + | |
4a4d8108 AM |
31940 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode); |
31941 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path); | |
523b37e3 AM |
31942 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
31943 | + struct inode **delegated_inode); | |
31944 | +int vfsub_notify_change(struct path *path, struct iattr *ia, | |
31945 | + struct inode **delegated_inode); | |
31946 | +int vfsub_unlink(struct inode *dir, struct path *path, | |
31947 | + struct inode **delegated_inode, int force); | |
4a4d8108 | 31948 | + |
521ced18 JR |
31949 | +static inline int vfsub_getattr(const struct path *path, struct kstat *st) |
31950 | +{ | |
31951 | + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); | |
31952 | +} | |
31953 | + | |
c1595e42 JR |
31954 | +/* ---------------------------------------------------------------------- */ |
31955 | + | |
31956 | +static inline int vfsub_setxattr(struct dentry *dentry, const char *name, | |
31957 | + const void *value, size_t size, int flags) | |
31958 | +{ | |
31959 | + int err; | |
31960 | + | |
31961 | + lockdep_off(); | |
31962 | + err = vfs_setxattr(dentry, name, value, size, flags); | |
31963 | + lockdep_on(); | |
31964 | + | |
31965 | + return err; | |
31966 | +} | |
31967 | + | |
31968 | +static inline int vfsub_removexattr(struct dentry *dentry, const char *name) | |
31969 | +{ | |
31970 | + int err; | |
31971 | + | |
31972 | + lockdep_off(); | |
31973 | + err = vfs_removexattr(dentry, name); | |
31974 | + lockdep_on(); | |
31975 | + | |
31976 | + return err; | |
31977 | +} | |
31978 | + | |
1facf9fc | 31979 | +#endif /* __KERNEL__ */ |
31980 | +#endif /* __AUFS_VFSUB_H__ */ | |
7f207e10 AM |
31981 | diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c |
31982 | --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 31983 | +++ linux/fs/aufs/wbr_policy.c 2017-05-06 22:16:52.784886929 +0200 |
f2c43d5f | 31984 | @@ -0,0 +1,830 @@ |
1facf9fc | 31985 | +/* |
a2654f78 | 31986 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 31987 | + * |
31988 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31989 | + * it under the terms of the GNU General Public License as published by | |
31990 | + * the Free Software Foundation; either version 2 of the License, or | |
31991 | + * (at your option) any later version. | |
dece6358 AM |
31992 | + * |
31993 | + * This program is distributed in the hope that it will be useful, | |
31994 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31995 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31996 | + * GNU General Public License for more details. | |
31997 | + * | |
31998 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31999 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32000 | + */ |
32001 | + | |
32002 | +/* | |
32003 | + * policies for selecting one among multiple writable branches | |
32004 | + */ | |
32005 | + | |
32006 | +#include <linux/statfs.h> | |
32007 | +#include "aufs.h" | |
32008 | + | |
32009 | +/* subset of cpup_attr() */ | |
32010 | +static noinline_for_stack | |
32011 | +int au_cpdown_attr(struct path *h_path, struct dentry *h_src) | |
32012 | +{ | |
32013 | + int err, sbits; | |
32014 | + struct iattr ia; | |
32015 | + struct inode *h_isrc; | |
32016 | + | |
5527c038 | 32017 | + h_isrc = d_inode(h_src); |
1facf9fc | 32018 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID; |
32019 | + ia.ia_mode = h_isrc->i_mode; | |
32020 | + ia.ia_uid = h_isrc->i_uid; | |
32021 | + ia.ia_gid = h_isrc->i_gid; | |
32022 | + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID)); | |
5527c038 | 32023 | + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags); |
523b37e3 AM |
32024 | + /* no delegation since it is just created */ |
32025 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 32026 | + |
32027 | + /* is this nfs only? */ | |
32028 | + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) { | |
32029 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
32030 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 32031 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); |
1facf9fc | 32032 | + } |
32033 | + | |
32034 | + return err; | |
32035 | +} | |
32036 | + | |
32037 | +#define AuCpdown_PARENT_OPQ 1 | |
32038 | +#define AuCpdown_WHED (1 << 1) | |
32039 | +#define AuCpdown_MADE_DIR (1 << 2) | |
32040 | +#define AuCpdown_DIROPQ (1 << 3) | |
32041 | +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name) | |
7f207e10 AM |
32042 | +#define au_fset_cpdown(flags, name) \ |
32043 | + do { (flags) |= AuCpdown_##name; } while (0) | |
32044 | +#define au_fclr_cpdown(flags, name) \ | |
32045 | + do { (flags) &= ~AuCpdown_##name; } while (0) | |
1facf9fc | 32046 | + |
1facf9fc | 32047 | +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst, |
c2b27bf2 | 32048 | + unsigned int *flags) |
1facf9fc | 32049 | +{ |
32050 | + int err; | |
32051 | + struct dentry *opq_dentry; | |
32052 | + | |
32053 | + opq_dentry = au_diropq_create(dentry, bdst); | |
32054 | + err = PTR_ERR(opq_dentry); | |
32055 | + if (IS_ERR(opq_dentry)) | |
32056 | + goto out; | |
32057 | + dput(opq_dentry); | |
c2b27bf2 | 32058 | + au_fset_cpdown(*flags, DIROPQ); |
1facf9fc | 32059 | + |
4f0767ce | 32060 | +out: |
1facf9fc | 32061 | + return err; |
32062 | +} | |
32063 | + | |
32064 | +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent, | |
32065 | + struct inode *dir, aufs_bindex_t bdst) | |
32066 | +{ | |
32067 | + int err; | |
32068 | + struct path h_path; | |
32069 | + struct au_branch *br; | |
32070 | + | |
32071 | + br = au_sbr(dentry->d_sb, bdst); | |
32072 | + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br); | |
32073 | + err = PTR_ERR(h_path.dentry); | |
32074 | + if (IS_ERR(h_path.dentry)) | |
32075 | + goto out; | |
32076 | + | |
32077 | + err = 0; | |
5527c038 | 32078 | + if (d_is_positive(h_path.dentry)) { |
86dc4139 | 32079 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 32080 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path, |
32081 | + dentry); | |
32082 | + } | |
32083 | + dput(h_path.dentry); | |
32084 | + | |
4f0767ce | 32085 | +out: |
1facf9fc | 32086 | + return err; |
32087 | +} | |
32088 | + | |
32089 | +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 32090 | + struct au_pin *pin, |
1facf9fc | 32091 | + struct dentry *h_parent, void *arg) |
32092 | +{ | |
32093 | + int err, rerr; | |
5afbbe0d | 32094 | + aufs_bindex_t bopq, btop; |
1facf9fc | 32095 | + struct path h_path; |
32096 | + struct dentry *parent; | |
32097 | + struct inode *h_dir, *h_inode, *inode, *dir; | |
c2b27bf2 | 32098 | + unsigned int *flags = arg; |
1facf9fc | 32099 | + |
5afbbe0d | 32100 | + btop = au_dbtop(dentry); |
1facf9fc | 32101 | + /* dentry is di-locked */ |
32102 | + parent = dget_parent(dentry); | |
5527c038 JR |
32103 | + dir = d_inode(parent); |
32104 | + h_dir = d_inode(h_parent); | |
1facf9fc | 32105 | + AuDebugOn(h_dir != au_h_iptr(dir, bdst)); |
32106 | + IMustLock(h_dir); | |
32107 | + | |
86dc4139 | 32108 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); |
1facf9fc | 32109 | + if (unlikely(err < 0)) |
32110 | + goto out; | |
32111 | + h_path.dentry = au_h_dptr(dentry, bdst); | |
32112 | + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst); | |
32113 | + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, | |
32114 | + S_IRWXU | S_IRUGO | S_IXUGO); | |
32115 | + if (unlikely(err)) | |
32116 | + goto out_put; | |
c2b27bf2 | 32117 | + au_fset_cpdown(*flags, MADE_DIR); |
1facf9fc | 32118 | + |
1facf9fc | 32119 | + bopq = au_dbdiropq(dentry); |
c2b27bf2 AM |
32120 | + au_fclr_cpdown(*flags, WHED); |
32121 | + au_fclr_cpdown(*flags, DIROPQ); | |
1facf9fc | 32122 | + if (au_dbwh(dentry) == bdst) |
c2b27bf2 AM |
32123 | + au_fset_cpdown(*flags, WHED); |
32124 | + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst) | |
32125 | + au_fset_cpdown(*flags, PARENT_OPQ); | |
5527c038 | 32126 | + h_inode = d_inode(h_path.dentry); |
febd17d6 | 32127 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
c2b27bf2 AM |
32128 | + if (au_ftest_cpdown(*flags, WHED)) { |
32129 | + err = au_cpdown_dir_opq(dentry, bdst, flags); | |
1facf9fc | 32130 | + if (unlikely(err)) { |
febd17d6 | 32131 | + inode_unlock(h_inode); |
1facf9fc | 32132 | + goto out_dir; |
32133 | + } | |
32134 | + } | |
32135 | + | |
5afbbe0d | 32136 | + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop)); |
febd17d6 | 32137 | + inode_unlock(h_inode); |
1facf9fc | 32138 | + if (unlikely(err)) |
32139 | + goto out_opq; | |
32140 | + | |
c2b27bf2 | 32141 | + if (au_ftest_cpdown(*flags, WHED)) { |
1facf9fc | 32142 | + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst); |
32143 | + if (unlikely(err)) | |
32144 | + goto out_opq; | |
32145 | + } | |
32146 | + | |
5527c038 | 32147 | + inode = d_inode(dentry); |
5afbbe0d AM |
32148 | + if (au_ibbot(inode) < bdst) |
32149 | + au_set_ibbot(inode, bdst); | |
1facf9fc | 32150 | + au_set_h_iptr(inode, bdst, au_igrab(h_inode), |
32151 | + au_hi_flags(inode, /*isdir*/1)); | |
076b876e | 32152 | + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0); |
1facf9fc | 32153 | + goto out; /* success */ |
32154 | + | |
32155 | + /* revert */ | |
4f0767ce | 32156 | +out_opq: |
c2b27bf2 | 32157 | + if (au_ftest_cpdown(*flags, DIROPQ)) { |
febd17d6 | 32158 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
1facf9fc | 32159 | + rerr = au_diropq_remove(dentry, bdst); |
febd17d6 | 32160 | + inode_unlock(h_inode); |
1facf9fc | 32161 | + if (unlikely(rerr)) { |
523b37e3 AM |
32162 | + AuIOErr("failed removing diropq for %pd b%d (%d)\n", |
32163 | + dentry, bdst, rerr); | |
1facf9fc | 32164 | + err = -EIO; |
32165 | + goto out; | |
32166 | + } | |
32167 | + } | |
4f0767ce | 32168 | +out_dir: |
c2b27bf2 | 32169 | + if (au_ftest_cpdown(*flags, MADE_DIR)) { |
1facf9fc | 32170 | + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path); |
32171 | + if (unlikely(rerr)) { | |
523b37e3 AM |
32172 | + AuIOErr("failed removing %pd b%d (%d)\n", |
32173 | + dentry, bdst, rerr); | |
1facf9fc | 32174 | + err = -EIO; |
32175 | + } | |
32176 | + } | |
4f0767ce | 32177 | +out_put: |
1facf9fc | 32178 | + au_set_h_dptr(dentry, bdst, NULL); |
5afbbe0d AM |
32179 | + if (au_dbbot(dentry) == bdst) |
32180 | + au_update_dbbot(dentry); | |
4f0767ce | 32181 | +out: |
1facf9fc | 32182 | + dput(parent); |
32183 | + return err; | |
32184 | +} | |
32185 | + | |
32186 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
32187 | +{ | |
32188 | + int err; | |
c2b27bf2 | 32189 | + unsigned int flags; |
1facf9fc | 32190 | + |
c2b27bf2 AM |
32191 | + flags = 0; |
32192 | + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags); | |
1facf9fc | 32193 | + |
32194 | + return err; | |
32195 | +} | |
32196 | + | |
32197 | +/* ---------------------------------------------------------------------- */ | |
32198 | + | |
32199 | +/* policies for create */ | |
32200 | + | |
c2b27bf2 | 32201 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex) |
4a4d8108 AM |
32202 | +{ |
32203 | + int err, i, j, ndentry; | |
32204 | + aufs_bindex_t bopq; | |
32205 | + struct au_dcsub_pages dpages; | |
32206 | + struct au_dpage *dpage; | |
32207 | + struct dentry **dentries, *parent, *d; | |
32208 | + | |
32209 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
32210 | + if (unlikely(err)) | |
32211 | + goto out; | |
32212 | + parent = dget_parent(dentry); | |
027c5e7a | 32213 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0); |
4a4d8108 AM |
32214 | + if (unlikely(err)) |
32215 | + goto out_free; | |
32216 | + | |
32217 | + err = bindex; | |
32218 | + for (i = 0; i < dpages.ndpage; i++) { | |
32219 | + dpage = dpages.dpages + i; | |
32220 | + dentries = dpage->dentries; | |
32221 | + ndentry = dpage->ndentry; | |
32222 | + for (j = 0; j < ndentry; j++) { | |
32223 | + d = dentries[j]; | |
32224 | + di_read_lock_parent2(d, !AuLock_IR); | |
32225 | + bopq = au_dbdiropq(d); | |
32226 | + di_read_unlock(d, !AuLock_IR); | |
32227 | + if (bopq >= 0 && bopq < err) | |
32228 | + err = bopq; | |
32229 | + } | |
32230 | + } | |
32231 | + | |
32232 | +out_free: | |
32233 | + dput(parent); | |
32234 | + au_dpages_free(&dpages); | |
32235 | +out: | |
32236 | + return err; | |
32237 | +} | |
32238 | + | |
1facf9fc | 32239 | +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex) |
32240 | +{ | |
32241 | + for (; bindex >= 0; bindex--) | |
32242 | + if (!au_br_rdonly(au_sbr(sb, bindex))) | |
32243 | + return bindex; | |
32244 | + return -EROFS; | |
32245 | +} | |
32246 | + | |
32247 | +/* top down parent */ | |
392086de AM |
32248 | +static int au_wbr_create_tdp(struct dentry *dentry, |
32249 | + unsigned int flags __maybe_unused) | |
1facf9fc | 32250 | +{ |
32251 | + int err; | |
5afbbe0d | 32252 | + aufs_bindex_t btop, bindex; |
1facf9fc | 32253 | + struct super_block *sb; |
32254 | + struct dentry *parent, *h_parent; | |
32255 | + | |
32256 | + sb = dentry->d_sb; | |
5afbbe0d AM |
32257 | + btop = au_dbtop(dentry); |
32258 | + err = btop; | |
32259 | + if (!au_br_rdonly(au_sbr(sb, btop))) | |
1facf9fc | 32260 | + goto out; |
32261 | + | |
32262 | + err = -EROFS; | |
32263 | + parent = dget_parent(dentry); | |
5afbbe0d | 32264 | + for (bindex = au_dbtop(parent); bindex < btop; bindex++) { |
1facf9fc | 32265 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 32266 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 32267 | + continue; |
32268 | + | |
32269 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
32270 | + err = bindex; | |
32271 | + break; | |
32272 | + } | |
32273 | + } | |
32274 | + dput(parent); | |
32275 | + | |
32276 | + /* bottom up here */ | |
4a4d8108 | 32277 | + if (unlikely(err < 0)) { |
5afbbe0d | 32278 | + err = au_wbr_bu(sb, btop - 1); |
4a4d8108 AM |
32279 | + if (err >= 0) |
32280 | + err = au_wbr_nonopq(dentry, err); | |
32281 | + } | |
1facf9fc | 32282 | + |
4f0767ce | 32283 | +out: |
1facf9fc | 32284 | + AuDbg("b%d\n", err); |
32285 | + return err; | |
32286 | +} | |
32287 | + | |
32288 | +/* ---------------------------------------------------------------------- */ | |
32289 | + | |
32290 | +/* an exception for the policy other than tdp */ | |
32291 | +static int au_wbr_create_exp(struct dentry *dentry) | |
32292 | +{ | |
32293 | + int err; | |
32294 | + aufs_bindex_t bwh, bdiropq; | |
32295 | + struct dentry *parent; | |
32296 | + | |
32297 | + err = -1; | |
32298 | + bwh = au_dbwh(dentry); | |
32299 | + parent = dget_parent(dentry); | |
32300 | + bdiropq = au_dbdiropq(parent); | |
32301 | + if (bwh >= 0) { | |
32302 | + if (bdiropq >= 0) | |
32303 | + err = min(bdiropq, bwh); | |
32304 | + else | |
32305 | + err = bwh; | |
32306 | + AuDbg("%d\n", err); | |
32307 | + } else if (bdiropq >= 0) { | |
32308 | + err = bdiropq; | |
32309 | + AuDbg("%d\n", err); | |
32310 | + } | |
32311 | + dput(parent); | |
32312 | + | |
4a4d8108 AM |
32313 | + if (err >= 0) |
32314 | + err = au_wbr_nonopq(dentry, err); | |
32315 | + | |
1facf9fc | 32316 | + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err))) |
32317 | + err = -1; | |
32318 | + | |
32319 | + AuDbg("%d\n", err); | |
32320 | + return err; | |
32321 | +} | |
32322 | + | |
32323 | +/* ---------------------------------------------------------------------- */ | |
32324 | + | |
32325 | +/* round robin */ | |
32326 | +static int au_wbr_create_init_rr(struct super_block *sb) | |
32327 | +{ | |
32328 | + int err; | |
32329 | + | |
5afbbe0d | 32330 | + err = au_wbr_bu(sb, au_sbbot(sb)); |
1facf9fc | 32331 | + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */ |
dece6358 | 32332 | + /* smp_mb(); */ |
1facf9fc | 32333 | + |
32334 | + AuDbg("b%d\n", err); | |
32335 | + return err; | |
32336 | +} | |
32337 | + | |
392086de | 32338 | +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 32339 | +{ |
32340 | + int err, nbr; | |
32341 | + unsigned int u; | |
5afbbe0d | 32342 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 32343 | + struct super_block *sb; |
32344 | + atomic_t *next; | |
32345 | + | |
32346 | + err = au_wbr_create_exp(dentry); | |
32347 | + if (err >= 0) | |
32348 | + goto out; | |
32349 | + | |
32350 | + sb = dentry->d_sb; | |
32351 | + next = &au_sbi(sb)->si_wbr_rr_next; | |
5afbbe0d AM |
32352 | + bbot = au_sbbot(sb); |
32353 | + nbr = bbot + 1; | |
32354 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
392086de | 32355 | + if (!au_ftest_wbr(flags, DIR)) { |
1facf9fc | 32356 | + err = atomic_dec_return(next) + 1; |
32357 | + /* modulo for 0 is meaningless */ | |
32358 | + if (unlikely(!err)) | |
32359 | + err = atomic_dec_return(next) + 1; | |
32360 | + } else | |
32361 | + err = atomic_read(next); | |
32362 | + AuDbg("%d\n", err); | |
32363 | + u = err; | |
32364 | + err = u % nbr; | |
32365 | + AuDbg("%d\n", err); | |
32366 | + if (!au_br_rdonly(au_sbr(sb, err))) | |
32367 | + break; | |
32368 | + err = -EROFS; | |
32369 | + } | |
32370 | + | |
4a4d8108 AM |
32371 | + if (err >= 0) |
32372 | + err = au_wbr_nonopq(dentry, err); | |
32373 | + | |
4f0767ce | 32374 | +out: |
1facf9fc | 32375 | + AuDbg("%d\n", err); |
32376 | + return err; | |
32377 | +} | |
32378 | + | |
32379 | +/* ---------------------------------------------------------------------- */ | |
32380 | + | |
32381 | +/* most free space */ | |
392086de | 32382 | +static void au_mfs(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 32383 | +{ |
32384 | + struct super_block *sb; | |
32385 | + struct au_branch *br; | |
32386 | + struct au_wbr_mfs *mfs; | |
392086de | 32387 | + struct dentry *h_parent; |
5afbbe0d | 32388 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 32389 | + int err; |
32390 | + unsigned long long b, bavail; | |
7f207e10 | 32391 | + struct path h_path; |
1facf9fc | 32392 | + /* reduce the stack usage */ |
32393 | + struct kstatfs *st; | |
32394 | + | |
32395 | + st = kmalloc(sizeof(*st), GFP_NOFS); | |
32396 | + if (unlikely(!st)) { | |
32397 | + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM); | |
32398 | + return; | |
32399 | + } | |
32400 | + | |
32401 | + bavail = 0; | |
32402 | + sb = dentry->d_sb; | |
32403 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
dece6358 | 32404 | + MtxMustLock(&mfs->mfs_lock); |
1facf9fc | 32405 | + mfs->mfs_bindex = -EROFS; |
32406 | + mfs->mfsrr_bytes = 0; | |
392086de AM |
32407 | + if (!parent) { |
32408 | + bindex = 0; | |
5afbbe0d | 32409 | + bbot = au_sbbot(sb); |
392086de | 32410 | + } else { |
5afbbe0d AM |
32411 | + bindex = au_dbtop(parent); |
32412 | + bbot = au_dbtaildir(parent); | |
392086de AM |
32413 | + } |
32414 | + | |
5afbbe0d | 32415 | + for (; bindex <= bbot; bindex++) { |
392086de AM |
32416 | + if (parent) { |
32417 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 32418 | + if (!h_parent || d_is_negative(h_parent)) |
392086de AM |
32419 | + continue; |
32420 | + } | |
1facf9fc | 32421 | + br = au_sbr(sb, bindex); |
32422 | + if (au_br_rdonly(br)) | |
32423 | + continue; | |
32424 | + | |
32425 | + /* sb->s_root for NFS is unreliable */ | |
86dc4139 | 32426 | + h_path.mnt = au_br_mnt(br); |
7f207e10 AM |
32427 | + h_path.dentry = h_path.mnt->mnt_root; |
32428 | + err = vfs_statfs(&h_path, st); | |
1facf9fc | 32429 | + if (unlikely(err)) { |
32430 | + AuWarn1("failed statfs, b%d, %d\n", bindex, err); | |
32431 | + continue; | |
32432 | + } | |
32433 | + | |
32434 | + /* when the available size is equal, select the lower one */ | |
32435 | + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail) | |
32436 | + || sizeof(b) < sizeof(st->f_bsize)); | |
32437 | + b = st->f_bavail * st->f_bsize; | |
32438 | + br->br_wbr->wbr_bytes = b; | |
32439 | + if (b >= bavail) { | |
32440 | + bavail = b; | |
32441 | + mfs->mfs_bindex = bindex; | |
32442 | + mfs->mfs_jiffy = jiffies; | |
32443 | + } | |
32444 | + } | |
32445 | + | |
32446 | + mfs->mfsrr_bytes = bavail; | |
32447 | + AuDbg("b%d\n", mfs->mfs_bindex); | |
f0c0a007 | 32448 | + au_delayed_kfree(st); |
1facf9fc | 32449 | +} |
32450 | + | |
392086de | 32451 | +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 32452 | +{ |
32453 | + int err; | |
392086de | 32454 | + struct dentry *parent; |
1facf9fc | 32455 | + struct super_block *sb; |
32456 | + struct au_wbr_mfs *mfs; | |
32457 | + | |
32458 | + err = au_wbr_create_exp(dentry); | |
32459 | + if (err >= 0) | |
32460 | + goto out; | |
32461 | + | |
32462 | + sb = dentry->d_sb; | |
392086de AM |
32463 | + parent = NULL; |
32464 | + if (au_ftest_wbr(flags, PARENT)) | |
32465 | + parent = dget_parent(dentry); | |
1facf9fc | 32466 | + mfs = &au_sbi(sb)->si_wbr_mfs; |
32467 | + mutex_lock(&mfs->mfs_lock); | |
32468 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
32469 | + || mfs->mfs_bindex < 0 | |
32470 | + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex))) | |
392086de | 32471 | + au_mfs(dentry, parent); |
1facf9fc | 32472 | + mutex_unlock(&mfs->mfs_lock); |
32473 | + err = mfs->mfs_bindex; | |
392086de | 32474 | + dput(parent); |
1facf9fc | 32475 | + |
4a4d8108 AM |
32476 | + if (err >= 0) |
32477 | + err = au_wbr_nonopq(dentry, err); | |
32478 | + | |
4f0767ce | 32479 | +out: |
1facf9fc | 32480 | + AuDbg("b%d\n", err); |
32481 | + return err; | |
32482 | +} | |
32483 | + | |
32484 | +static int au_wbr_create_init_mfs(struct super_block *sb) | |
32485 | +{ | |
32486 | + struct au_wbr_mfs *mfs; | |
32487 | + | |
32488 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
32489 | + mutex_init(&mfs->mfs_lock); | |
32490 | + mfs->mfs_jiffy = 0; | |
32491 | + mfs->mfs_bindex = -EROFS; | |
32492 | + | |
32493 | + return 0; | |
32494 | +} | |
32495 | + | |
32496 | +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused) | |
32497 | +{ | |
32498 | + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock); | |
32499 | + return 0; | |
32500 | +} | |
32501 | + | |
32502 | +/* ---------------------------------------------------------------------- */ | |
32503 | + | |
f2c43d5f AM |
32504 | +/* top down regardless parent, and then mfs */ |
32505 | +static int au_wbr_create_tdmfs(struct dentry *dentry, | |
32506 | + unsigned int flags __maybe_unused) | |
32507 | +{ | |
32508 | + int err; | |
32509 | + aufs_bindex_t bwh, btail, bindex, bfound, bmfs; | |
32510 | + unsigned long long watermark; | |
32511 | + struct super_block *sb; | |
32512 | + struct au_wbr_mfs *mfs; | |
32513 | + struct au_branch *br; | |
32514 | + struct dentry *parent; | |
32515 | + | |
32516 | + sb = dentry->d_sb; | |
32517 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
32518 | + mutex_lock(&mfs->mfs_lock); | |
32519 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
32520 | + || mfs->mfs_bindex < 0) | |
32521 | + au_mfs(dentry, /*parent*/NULL); | |
32522 | + watermark = mfs->mfsrr_watermark; | |
32523 | + bmfs = mfs->mfs_bindex; | |
32524 | + mutex_unlock(&mfs->mfs_lock); | |
32525 | + | |
32526 | + /* another style of au_wbr_create_exp() */ | |
32527 | + bwh = au_dbwh(dentry); | |
32528 | + parent = dget_parent(dentry); | |
32529 | + btail = au_dbtaildir(parent); | |
32530 | + if (bwh >= 0 && bwh < btail) | |
32531 | + btail = bwh; | |
32532 | + | |
32533 | + err = au_wbr_nonopq(dentry, btail); | |
32534 | + if (unlikely(err < 0)) | |
32535 | + goto out; | |
32536 | + btail = err; | |
32537 | + bfound = -1; | |
32538 | + for (bindex = 0; bindex <= btail; bindex++) { | |
32539 | + br = au_sbr(sb, bindex); | |
32540 | + if (au_br_rdonly(br)) | |
32541 | + continue; | |
32542 | + if (br->br_wbr->wbr_bytes > watermark) { | |
32543 | + bfound = bindex; | |
32544 | + break; | |
32545 | + } | |
32546 | + } | |
32547 | + err = bfound; | |
32548 | + if (err < 0) | |
32549 | + err = bmfs; | |
32550 | + | |
32551 | +out: | |
32552 | + dput(parent); | |
32553 | + AuDbg("b%d\n", err); | |
32554 | + return err; | |
32555 | +} | |
32556 | + | |
32557 | +/* ---------------------------------------------------------------------- */ | |
32558 | + | |
1facf9fc | 32559 | +/* most free space and then round robin */ |
392086de | 32560 | +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 32561 | +{ |
32562 | + int err; | |
32563 | + struct au_wbr_mfs *mfs; | |
32564 | + | |
392086de | 32565 | + err = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 32566 | + if (err >= 0) { |
32567 | + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs; | |
dece6358 | 32568 | + mutex_lock(&mfs->mfs_lock); |
1facf9fc | 32569 | + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark) |
392086de | 32570 | + err = au_wbr_create_rr(dentry, flags); |
dece6358 | 32571 | + mutex_unlock(&mfs->mfs_lock); |
1facf9fc | 32572 | + } |
32573 | + | |
32574 | + AuDbg("b%d\n", err); | |
32575 | + return err; | |
32576 | +} | |
32577 | + | |
32578 | +static int au_wbr_create_init_mfsrr(struct super_block *sb) | |
32579 | +{ | |
32580 | + int err; | |
32581 | + | |
32582 | + au_wbr_create_init_mfs(sb); /* ignore */ | |
32583 | + err = au_wbr_create_init_rr(sb); | |
32584 | + | |
32585 | + return err; | |
32586 | +} | |
32587 | + | |
32588 | +/* ---------------------------------------------------------------------- */ | |
32589 | + | |
32590 | +/* top down parent and most free space */ | |
392086de | 32591 | +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 32592 | +{ |
32593 | + int err, e2; | |
32594 | + unsigned long long b; | |
5afbbe0d | 32595 | + aufs_bindex_t bindex, btop, bbot; |
1facf9fc | 32596 | + struct super_block *sb; |
32597 | + struct dentry *parent, *h_parent; | |
32598 | + struct au_branch *br; | |
32599 | + | |
392086de | 32600 | + err = au_wbr_create_tdp(dentry, flags); |
1facf9fc | 32601 | + if (unlikely(err < 0)) |
32602 | + goto out; | |
32603 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
32604 | + btop = au_dbtop(parent); |
32605 | + bbot = au_dbtaildir(parent); | |
32606 | + if (btop == bbot) | |
1facf9fc | 32607 | + goto out_parent; /* success */ |
32608 | + | |
392086de | 32609 | + e2 = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 32610 | + if (e2 < 0) |
32611 | + goto out_parent; /* success */ | |
32612 | + | |
32613 | + /* when the available size is equal, select upper one */ | |
32614 | + sb = dentry->d_sb; | |
32615 | + br = au_sbr(sb, err); | |
32616 | + b = br->br_wbr->wbr_bytes; | |
32617 | + AuDbg("b%d, %llu\n", err, b); | |
32618 | + | |
5afbbe0d | 32619 | + for (bindex = btop; bindex <= bbot; bindex++) { |
1facf9fc | 32620 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 32621 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 32622 | + continue; |
32623 | + | |
32624 | + br = au_sbr(sb, bindex); | |
32625 | + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) { | |
32626 | + b = br->br_wbr->wbr_bytes; | |
32627 | + err = bindex; | |
32628 | + AuDbg("b%d, %llu\n", err, b); | |
32629 | + } | |
32630 | + } | |
32631 | + | |
4a4d8108 AM |
32632 | + if (err >= 0) |
32633 | + err = au_wbr_nonopq(dentry, err); | |
32634 | + | |
4f0767ce | 32635 | +out_parent: |
1facf9fc | 32636 | + dput(parent); |
4f0767ce | 32637 | +out: |
1facf9fc | 32638 | + AuDbg("b%d\n", err); |
32639 | + return err; | |
32640 | +} | |
32641 | + | |
32642 | +/* ---------------------------------------------------------------------- */ | |
32643 | + | |
392086de AM |
32644 | +/* |
32645 | + * - top down parent | |
32646 | + * - most free space with parent | |
32647 | + * - most free space round-robin regardless parent | |
32648 | + */ | |
32649 | +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags) | |
32650 | +{ | |
32651 | + int err; | |
32652 | + unsigned long long watermark; | |
32653 | + struct super_block *sb; | |
32654 | + struct au_branch *br; | |
32655 | + struct au_wbr_mfs *mfs; | |
32656 | + | |
32657 | + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT); | |
32658 | + if (unlikely(err < 0)) | |
32659 | + goto out; | |
32660 | + | |
32661 | + sb = dentry->d_sb; | |
32662 | + br = au_sbr(sb, err); | |
32663 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
32664 | + mutex_lock(&mfs->mfs_lock); | |
32665 | + watermark = mfs->mfsrr_watermark; | |
32666 | + mutex_unlock(&mfs->mfs_lock); | |
32667 | + if (br->br_wbr->wbr_bytes < watermark) | |
32668 | + /* regardless the parent dir */ | |
32669 | + err = au_wbr_create_mfsrr(dentry, flags); | |
32670 | + | |
32671 | +out: | |
32672 | + AuDbg("b%d\n", err); | |
32673 | + return err; | |
32674 | +} | |
32675 | + | |
32676 | +/* ---------------------------------------------------------------------- */ | |
32677 | + | |
1facf9fc | 32678 | +/* policies for copyup */ |
32679 | + | |
32680 | +/* top down parent */ | |
32681 | +static int au_wbr_copyup_tdp(struct dentry *dentry) | |
32682 | +{ | |
392086de | 32683 | + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0); |
1facf9fc | 32684 | +} |
32685 | + | |
32686 | +/* bottom up parent */ | |
32687 | +static int au_wbr_copyup_bup(struct dentry *dentry) | |
32688 | +{ | |
32689 | + int err; | |
5afbbe0d | 32690 | + aufs_bindex_t bindex, btop; |
1facf9fc | 32691 | + struct dentry *parent, *h_parent; |
32692 | + struct super_block *sb; | |
32693 | + | |
32694 | + err = -EROFS; | |
32695 | + sb = dentry->d_sb; | |
32696 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
32697 | + btop = au_dbtop(parent); |
32698 | + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) { | |
1facf9fc | 32699 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 32700 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 32701 | + continue; |
32702 | + | |
32703 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
32704 | + err = bindex; | |
32705 | + break; | |
32706 | + } | |
32707 | + } | |
32708 | + dput(parent); | |
32709 | + | |
32710 | + /* bottom up here */ | |
32711 | + if (unlikely(err < 0)) | |
5afbbe0d | 32712 | + err = au_wbr_bu(sb, btop - 1); |
1facf9fc | 32713 | + |
32714 | + AuDbg("b%d\n", err); | |
32715 | + return err; | |
32716 | +} | |
32717 | + | |
32718 | +/* bottom up */ | |
5afbbe0d | 32719 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop) |
1facf9fc | 32720 | +{ |
32721 | + int err; | |
32722 | + | |
5afbbe0d | 32723 | + err = au_wbr_bu(dentry->d_sb, btop); |
4a4d8108 | 32724 | + AuDbg("b%d\n", err); |
5afbbe0d | 32725 | + if (err > btop) |
4a4d8108 | 32726 | + err = au_wbr_nonopq(dentry, err); |
1facf9fc | 32727 | + |
32728 | + AuDbg("b%d\n", err); | |
32729 | + return err; | |
32730 | +} | |
32731 | + | |
076b876e AM |
32732 | +static int au_wbr_copyup_bu(struct dentry *dentry) |
32733 | +{ | |
32734 | + int err; | |
5afbbe0d | 32735 | + aufs_bindex_t btop; |
076b876e | 32736 | + |
5afbbe0d AM |
32737 | + btop = au_dbtop(dentry); |
32738 | + err = au_wbr_do_copyup_bu(dentry, btop); | |
076b876e AM |
32739 | + return err; |
32740 | +} | |
32741 | + | |
1facf9fc | 32742 | +/* ---------------------------------------------------------------------- */ |
32743 | + | |
32744 | +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = { | |
32745 | + [AuWbrCopyup_TDP] = { | |
32746 | + .copyup = au_wbr_copyup_tdp | |
32747 | + }, | |
32748 | + [AuWbrCopyup_BUP] = { | |
32749 | + .copyup = au_wbr_copyup_bup | |
32750 | + }, | |
32751 | + [AuWbrCopyup_BU] = { | |
32752 | + .copyup = au_wbr_copyup_bu | |
32753 | + } | |
32754 | +}; | |
32755 | + | |
32756 | +struct au_wbr_create_operations au_wbr_create_ops[] = { | |
32757 | + [AuWbrCreate_TDP] = { | |
32758 | + .create = au_wbr_create_tdp | |
32759 | + }, | |
32760 | + [AuWbrCreate_RR] = { | |
32761 | + .create = au_wbr_create_rr, | |
32762 | + .init = au_wbr_create_init_rr | |
32763 | + }, | |
32764 | + [AuWbrCreate_MFS] = { | |
32765 | + .create = au_wbr_create_mfs, | |
32766 | + .init = au_wbr_create_init_mfs, | |
32767 | + .fin = au_wbr_create_fin_mfs | |
32768 | + }, | |
32769 | + [AuWbrCreate_MFSV] = { | |
32770 | + .create = au_wbr_create_mfs, | |
32771 | + .init = au_wbr_create_init_mfs, | |
32772 | + .fin = au_wbr_create_fin_mfs | |
32773 | + }, | |
32774 | + [AuWbrCreate_MFSRR] = { | |
32775 | + .create = au_wbr_create_mfsrr, | |
32776 | + .init = au_wbr_create_init_mfsrr, | |
32777 | + .fin = au_wbr_create_fin_mfs | |
32778 | + }, | |
32779 | + [AuWbrCreate_MFSRRV] = { | |
32780 | + .create = au_wbr_create_mfsrr, | |
32781 | + .init = au_wbr_create_init_mfsrr, | |
32782 | + .fin = au_wbr_create_fin_mfs | |
32783 | + }, | |
f2c43d5f AM |
32784 | + [AuWbrCreate_TDMFS] = { |
32785 | + .create = au_wbr_create_tdmfs, | |
32786 | + .init = au_wbr_create_init_mfs, | |
32787 | + .fin = au_wbr_create_fin_mfs | |
32788 | + }, | |
32789 | + [AuWbrCreate_TDMFSV] = { | |
32790 | + .create = au_wbr_create_tdmfs, | |
32791 | + .init = au_wbr_create_init_mfs, | |
32792 | + .fin = au_wbr_create_fin_mfs | |
32793 | + }, | |
1facf9fc | 32794 | + [AuWbrCreate_PMFS] = { |
32795 | + .create = au_wbr_create_pmfs, | |
32796 | + .init = au_wbr_create_init_mfs, | |
32797 | + .fin = au_wbr_create_fin_mfs | |
32798 | + }, | |
32799 | + [AuWbrCreate_PMFSV] = { | |
32800 | + .create = au_wbr_create_pmfs, | |
32801 | + .init = au_wbr_create_init_mfs, | |
32802 | + .fin = au_wbr_create_fin_mfs | |
392086de AM |
32803 | + }, |
32804 | + [AuWbrCreate_PMFSRR] = { | |
32805 | + .create = au_wbr_create_pmfsrr, | |
32806 | + .init = au_wbr_create_init_mfsrr, | |
32807 | + .fin = au_wbr_create_fin_mfs | |
32808 | + }, | |
32809 | + [AuWbrCreate_PMFSRRV] = { | |
32810 | + .create = au_wbr_create_pmfsrr, | |
32811 | + .init = au_wbr_create_init_mfsrr, | |
32812 | + .fin = au_wbr_create_fin_mfs | |
1facf9fc | 32813 | + } |
32814 | +}; | |
7f207e10 AM |
32815 | diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c |
32816 | --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 32817 | +++ linux/fs/aufs/whout.c 2017-05-06 22:16:52.784886929 +0200 |
f2c43d5f | 32818 | @@ -0,0 +1,1061 @@ |
1facf9fc | 32819 | +/* |
a2654f78 | 32820 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 32821 | + * |
32822 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32823 | + * it under the terms of the GNU General Public License as published by | |
32824 | + * the Free Software Foundation; either version 2 of the License, or | |
32825 | + * (at your option) any later version. | |
dece6358 AM |
32826 | + * |
32827 | + * This program is distributed in the hope that it will be useful, | |
32828 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32829 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32830 | + * GNU General Public License for more details. | |
32831 | + * | |
32832 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32833 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32834 | + */ |
32835 | + | |
32836 | +/* | |
32837 | + * whiteout for logical deletion and opaque directory | |
32838 | + */ | |
32839 | + | |
1facf9fc | 32840 | +#include "aufs.h" |
32841 | + | |
32842 | +#define WH_MASK S_IRUGO | |
32843 | + | |
32844 | +/* | |
32845 | + * If a directory contains this file, then it is opaque. We start with the | |
32846 | + * .wh. flag so that it is blocked by lookup. | |
32847 | + */ | |
0c3ec466 AM |
32848 | +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ, |
32849 | + sizeof(AUFS_WH_DIROPQ) - 1); | |
1facf9fc | 32850 | + |
32851 | +/* | |
32852 | + * generate whiteout name, which is NOT terminated by NULL. | |
32853 | + * @name: original d_name.name | |
32854 | + * @len: original d_name.len | |
32855 | + * @wh: whiteout qstr | |
32856 | + * returns zero when succeeds, otherwise error. | |
32857 | + * succeeded value as wh->name should be freed by kfree(). | |
32858 | + */ | |
32859 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name) | |
32860 | +{ | |
32861 | + char *p; | |
32862 | + | |
32863 | + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN)) | |
32864 | + return -ENAMETOOLONG; | |
32865 | + | |
32866 | + wh->len = name->len + AUFS_WH_PFX_LEN; | |
32867 | + p = kmalloc(wh->len, GFP_NOFS); | |
32868 | + wh->name = p; | |
32869 | + if (p) { | |
32870 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
32871 | + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len); | |
32872 | + /* smp_mb(); */ | |
32873 | + return 0; | |
32874 | + } | |
32875 | + return -ENOMEM; | |
32876 | +} | |
32877 | + | |
32878 | +/* ---------------------------------------------------------------------- */ | |
32879 | + | |
32880 | +/* | |
32881 | + * test if the @wh_name exists under @h_parent. | |
32882 | + * @try_sio specifies the necessary of super-io. | |
32883 | + */ | |
076b876e | 32884 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio) |
1facf9fc | 32885 | +{ |
32886 | + int err; | |
32887 | + struct dentry *wh_dentry; | |
1facf9fc | 32888 | + |
1facf9fc | 32889 | + if (!try_sio) |
b4510431 | 32890 | + wh_dentry = vfsub_lkup_one(wh_name, h_parent); |
1facf9fc | 32891 | + else |
076b876e | 32892 | + wh_dentry = au_sio_lkup_one(wh_name, h_parent); |
1facf9fc | 32893 | + err = PTR_ERR(wh_dentry); |
2000de60 JR |
32894 | + if (IS_ERR(wh_dentry)) { |
32895 | + if (err == -ENAMETOOLONG) | |
32896 | + err = 0; | |
1facf9fc | 32897 | + goto out; |
2000de60 | 32898 | + } |
1facf9fc | 32899 | + |
32900 | + err = 0; | |
5527c038 | 32901 | + if (d_is_negative(wh_dentry)) |
1facf9fc | 32902 | + goto out_wh; /* success */ |
32903 | + | |
32904 | + err = 1; | |
7e9cd9fe | 32905 | + if (d_is_reg(wh_dentry)) |
1facf9fc | 32906 | + goto out_wh; /* success */ |
32907 | + | |
32908 | + err = -EIO; | |
523b37e3 | 32909 | + AuIOErr("%pd Invalid whiteout entry type 0%o.\n", |
5527c038 | 32910 | + wh_dentry, d_inode(wh_dentry)->i_mode); |
1facf9fc | 32911 | + |
4f0767ce | 32912 | +out_wh: |
1facf9fc | 32913 | + dput(wh_dentry); |
4f0767ce | 32914 | +out: |
1facf9fc | 32915 | + return err; |
32916 | +} | |
32917 | + | |
32918 | +/* | |
32919 | + * test if the @h_dentry sets opaque or not. | |
32920 | + */ | |
076b876e | 32921 | +int au_diropq_test(struct dentry *h_dentry) |
1facf9fc | 32922 | +{ |
32923 | + int err; | |
32924 | + struct inode *h_dir; | |
32925 | + | |
5527c038 | 32926 | + h_dir = d_inode(h_dentry); |
076b876e | 32927 | + err = au_wh_test(h_dentry, &diropq_name, |
1facf9fc | 32928 | + au_test_h_perm_sio(h_dir, MAY_EXEC)); |
32929 | + return err; | |
32930 | +} | |
32931 | + | |
32932 | +/* | |
32933 | + * returns a negative dentry whose name is unique and temporary. | |
32934 | + */ | |
32935 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, | |
32936 | + struct qstr *prefix) | |
32937 | +{ | |
1facf9fc | 32938 | + struct dentry *dentry; |
32939 | + int i; | |
027c5e7a | 32940 | + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1], |
4a4d8108 | 32941 | + *name, *p; |
027c5e7a | 32942 | + /* strict atomic_t is unnecessary here */ |
1facf9fc | 32943 | + static unsigned short cnt; |
32944 | + struct qstr qs; | |
32945 | + | |
4a4d8108 AM |
32946 | + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN); |
32947 | + | |
1facf9fc | 32948 | + name = defname; |
027c5e7a AM |
32949 | + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1; |
32950 | + if (unlikely(prefix->len > DNAME_INLINE_LEN)) { | |
1facf9fc | 32951 | + dentry = ERR_PTR(-ENAMETOOLONG); |
4a4d8108 | 32952 | + if (unlikely(qs.len > NAME_MAX)) |
1facf9fc | 32953 | + goto out; |
32954 | + dentry = ERR_PTR(-ENOMEM); | |
32955 | + name = kmalloc(qs.len + 1, GFP_NOFS); | |
32956 | + if (unlikely(!name)) | |
32957 | + goto out; | |
32958 | + } | |
32959 | + | |
32960 | + /* doubly whiteout-ed */ | |
32961 | + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2); | |
32962 | + p = name + AUFS_WH_PFX_LEN * 2; | |
32963 | + memcpy(p, prefix->name, prefix->len); | |
32964 | + p += prefix->len; | |
32965 | + *p++ = '.'; | |
4a4d8108 | 32966 | + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN); |
1facf9fc | 32967 | + |
32968 | + qs.name = name; | |
32969 | + for (i = 0; i < 3; i++) { | |
b752ccd1 | 32970 | + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++); |
076b876e | 32971 | + dentry = au_sio_lkup_one(&qs, h_parent); |
5527c038 | 32972 | + if (IS_ERR(dentry) || d_is_negative(dentry)) |
1facf9fc | 32973 | + goto out_name; |
32974 | + dput(dentry); | |
32975 | + } | |
0c3ec466 | 32976 | + /* pr_warn("could not get random name\n"); */ |
1facf9fc | 32977 | + dentry = ERR_PTR(-EEXIST); |
32978 | + AuDbg("%.*s\n", AuLNPair(&qs)); | |
32979 | + BUG(); | |
32980 | + | |
4f0767ce | 32981 | +out_name: |
1facf9fc | 32982 | + if (name != defname) |
f0c0a007 | 32983 | + au_delayed_kfree(name); |
4f0767ce | 32984 | +out: |
4a4d8108 | 32985 | + AuTraceErrPtr(dentry); |
1facf9fc | 32986 | + return dentry; |
1facf9fc | 32987 | +} |
32988 | + | |
32989 | +/* | |
32990 | + * rename the @h_dentry on @br to the whiteouted temporary name. | |
32991 | + */ | |
32992 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br) | |
32993 | +{ | |
32994 | + int err; | |
32995 | + struct path h_path = { | |
86dc4139 | 32996 | + .mnt = au_br_mnt(br) |
1facf9fc | 32997 | + }; |
523b37e3 | 32998 | + struct inode *h_dir, *delegated; |
1facf9fc | 32999 | + struct dentry *h_parent; |
33000 | + | |
33001 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ | |
5527c038 | 33002 | + h_dir = d_inode(h_parent); |
1facf9fc | 33003 | + IMustLock(h_dir); |
33004 | + | |
33005 | + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name); | |
33006 | + err = PTR_ERR(h_path.dentry); | |
33007 | + if (IS_ERR(h_path.dentry)) | |
33008 | + goto out; | |
33009 | + | |
33010 | + /* under the same dir, no need to lock_rename() */ | |
523b37e3 | 33011 | + delegated = NULL; |
f2c43d5f AM |
33012 | + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated, |
33013 | + /*flags*/0); | |
1facf9fc | 33014 | + AuTraceErr(err); |
523b37e3 AM |
33015 | + if (unlikely(err == -EWOULDBLOCK)) { |
33016 | + pr_warn("cannot retry for NFSv4 delegation" | |
33017 | + " for an internal rename\n"); | |
33018 | + iput(delegated); | |
33019 | + } | |
1facf9fc | 33020 | + dput(h_path.dentry); |
33021 | + | |
4f0767ce | 33022 | +out: |
4a4d8108 | 33023 | + AuTraceErr(err); |
1facf9fc | 33024 | + return err; |
33025 | +} | |
33026 | + | |
33027 | +/* ---------------------------------------------------------------------- */ | |
33028 | +/* | |
33029 | + * functions for removing a whiteout | |
33030 | + */ | |
33031 | + | |
33032 | +static int do_unlink_wh(struct inode *h_dir, struct path *h_path) | |
33033 | +{ | |
523b37e3 AM |
33034 | + int err, force; |
33035 | + struct inode *delegated; | |
1facf9fc | 33036 | + |
33037 | + /* | |
33038 | + * forces superio when the dir has a sticky bit. | |
33039 | + * this may be a violation of unix fs semantics. | |
33040 | + */ | |
33041 | + force = (h_dir->i_mode & S_ISVTX) | |
5527c038 | 33042 | + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid); |
523b37e3 AM |
33043 | + delegated = NULL; |
33044 | + err = vfsub_unlink(h_dir, h_path, &delegated, force); | |
33045 | + if (unlikely(err == -EWOULDBLOCK)) { | |
33046 | + pr_warn("cannot retry for NFSv4 delegation" | |
33047 | + " for an internal unlink\n"); | |
33048 | + iput(delegated); | |
33049 | + } | |
33050 | + return err; | |
1facf9fc | 33051 | +} |
33052 | + | |
33053 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
33054 | + struct dentry *dentry) | |
33055 | +{ | |
33056 | + int err; | |
33057 | + | |
33058 | + err = do_unlink_wh(h_dir, h_path); | |
33059 | + if (!err && dentry) | |
33060 | + au_set_dbwh(dentry, -1); | |
33061 | + | |
33062 | + return err; | |
33063 | +} | |
33064 | + | |
33065 | +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh, | |
33066 | + struct au_branch *br) | |
33067 | +{ | |
33068 | + int err; | |
33069 | + struct path h_path = { | |
86dc4139 | 33070 | + .mnt = au_br_mnt(br) |
1facf9fc | 33071 | + }; |
33072 | + | |
33073 | + err = 0; | |
b4510431 | 33074 | + h_path.dentry = vfsub_lkup_one(wh, h_parent); |
1facf9fc | 33075 | + if (IS_ERR(h_path.dentry)) |
33076 | + err = PTR_ERR(h_path.dentry); | |
33077 | + else { | |
5527c038 JR |
33078 | + if (d_is_reg(h_path.dentry)) |
33079 | + err = do_unlink_wh(d_inode(h_parent), &h_path); | |
1facf9fc | 33080 | + dput(h_path.dentry); |
33081 | + } | |
33082 | + | |
33083 | + return err; | |
33084 | +} | |
33085 | + | |
33086 | +/* ---------------------------------------------------------------------- */ | |
33087 | +/* | |
33088 | + * initialize/clean whiteout for a branch | |
33089 | + */ | |
33090 | + | |
33091 | +static void au_wh_clean(struct inode *h_dir, struct path *whpath, | |
33092 | + const int isdir) | |
33093 | +{ | |
33094 | + int err; | |
523b37e3 | 33095 | + struct inode *delegated; |
1facf9fc | 33096 | + |
5527c038 | 33097 | + if (d_is_negative(whpath->dentry)) |
1facf9fc | 33098 | + return; |
33099 | + | |
86dc4139 AM |
33100 | + if (isdir) |
33101 | + err = vfsub_rmdir(h_dir, whpath); | |
523b37e3 AM |
33102 | + else { |
33103 | + delegated = NULL; | |
33104 | + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0); | |
33105 | + if (unlikely(err == -EWOULDBLOCK)) { | |
33106 | + pr_warn("cannot retry for NFSv4 delegation" | |
33107 | + " for an internal unlink\n"); | |
33108 | + iput(delegated); | |
33109 | + } | |
33110 | + } | |
1facf9fc | 33111 | + if (unlikely(err)) |
523b37e3 AM |
33112 | + pr_warn("failed removing %pd (%d), ignored.\n", |
33113 | + whpath->dentry, err); | |
1facf9fc | 33114 | +} |
33115 | + | |
33116 | +static int test_linkable(struct dentry *h_root) | |
33117 | +{ | |
5527c038 | 33118 | + struct inode *h_dir = d_inode(h_root); |
1facf9fc | 33119 | + |
33120 | + if (h_dir->i_op->link) | |
33121 | + return 0; | |
33122 | + | |
523b37e3 AM |
33123 | + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n", |
33124 | + h_root, au_sbtype(h_root->d_sb)); | |
1facf9fc | 33125 | + return -ENOSYS; |
33126 | +} | |
33127 | + | |
33128 | +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */ | |
33129 | +static int au_whdir(struct inode *h_dir, struct path *path) | |
33130 | +{ | |
33131 | + int err; | |
33132 | + | |
33133 | + err = -EEXIST; | |
5527c038 | 33134 | + if (d_is_negative(path->dentry)) { |
1facf9fc | 33135 | + int mode = S_IRWXU; |
33136 | + | |
33137 | + if (au_test_nfs(path->dentry->d_sb)) | |
33138 | + mode |= S_IXUGO; | |
86dc4139 | 33139 | + err = vfsub_mkdir(h_dir, path, mode); |
2000de60 | 33140 | + } else if (d_is_dir(path->dentry)) |
1facf9fc | 33141 | + err = 0; |
33142 | + else | |
523b37e3 | 33143 | + pr_err("unknown %pd exists\n", path->dentry); |
1facf9fc | 33144 | + |
33145 | + return err; | |
33146 | +} | |
33147 | + | |
33148 | +struct au_wh_base { | |
33149 | + const struct qstr *name; | |
33150 | + struct dentry *dentry; | |
33151 | +}; | |
33152 | + | |
33153 | +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[], | |
33154 | + struct path *h_path) | |
33155 | +{ | |
33156 | + h_path->dentry = base[AuBrWh_BASE].dentry; | |
33157 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
33158 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
33159 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
33160 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
33161 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
33162 | +} | |
33163 | + | |
33164 | +/* | |
33165 | + * returns tri-state, | |
c1595e42 | 33166 | + * minus: error, caller should print the message |
1facf9fc | 33167 | + * zero: succuess |
c1595e42 | 33168 | + * plus: error, caller should NOT print the message |
1facf9fc | 33169 | + */ |
33170 | +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr, | |
33171 | + int do_plink, struct au_wh_base base[], | |
33172 | + struct path *h_path) | |
33173 | +{ | |
33174 | + int err; | |
33175 | + struct inode *h_dir; | |
33176 | + | |
5527c038 | 33177 | + h_dir = d_inode(h_root); |
1facf9fc | 33178 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
33179 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
33180 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
33181 | + if (do_plink) { | |
33182 | + err = test_linkable(h_root); | |
33183 | + if (unlikely(err)) { | |
33184 | + err = 1; | |
33185 | + goto out; | |
33186 | + } | |
33187 | + | |
33188 | + err = au_whdir(h_dir, h_path); | |
33189 | + if (unlikely(err)) | |
33190 | + goto out; | |
33191 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
33192 | + } else | |
33193 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
33194 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
33195 | + err = au_whdir(h_dir, h_path); | |
33196 | + if (unlikely(err)) | |
33197 | + goto out; | |
33198 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
33199 | + | |
4f0767ce | 33200 | +out: |
1facf9fc | 33201 | + return err; |
33202 | +} | |
33203 | + | |
33204 | +/* | |
33205 | + * for the moment, aufs supports the branch filesystem which does not support | |
33206 | + * link(2). testing on FAT which does not support i_op->setattr() fully either, | |
33207 | + * copyup failed. finally, such filesystem will not be used as the writable | |
33208 | + * branch. | |
33209 | + * | |
33210 | + * returns tri-state, see above. | |
33211 | + */ | |
33212 | +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr, | |
33213 | + int do_plink, struct au_wh_base base[], | |
33214 | + struct path *h_path) | |
33215 | +{ | |
33216 | + int err; | |
33217 | + struct inode *h_dir; | |
33218 | + | |
1308ab2a | 33219 | + WbrWhMustWriteLock(wbr); |
33220 | + | |
1facf9fc | 33221 | + err = test_linkable(h_root); |
33222 | + if (unlikely(err)) { | |
33223 | + err = 1; | |
33224 | + goto out; | |
33225 | + } | |
33226 | + | |
33227 | + /* | |
33228 | + * todo: should this create be done in /sbin/mount.aufs helper? | |
33229 | + */ | |
33230 | + err = -EEXIST; | |
5527c038 JR |
33231 | + h_dir = d_inode(h_root); |
33232 | + if (d_is_negative(base[AuBrWh_BASE].dentry)) { | |
86dc4139 AM |
33233 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
33234 | + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true); | |
7e9cd9fe | 33235 | + } else if (d_is_reg(base[AuBrWh_BASE].dentry)) |
1facf9fc | 33236 | + err = 0; |
33237 | + else | |
523b37e3 | 33238 | + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry); |
1facf9fc | 33239 | + if (unlikely(err)) |
33240 | + goto out; | |
33241 | + | |
33242 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
33243 | + if (do_plink) { | |
33244 | + err = au_whdir(h_dir, h_path); | |
33245 | + if (unlikely(err)) | |
33246 | + goto out; | |
33247 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
33248 | + } else | |
33249 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
33250 | + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry); | |
33251 | + | |
33252 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
33253 | + err = au_whdir(h_dir, h_path); | |
33254 | + if (unlikely(err)) | |
33255 | + goto out; | |
33256 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
33257 | + | |
4f0767ce | 33258 | +out: |
1facf9fc | 33259 | + return err; |
33260 | +} | |
33261 | + | |
33262 | +/* | |
33263 | + * initialize the whiteout base file/dir for @br. | |
33264 | + */ | |
86dc4139 | 33265 | +int au_wh_init(struct au_branch *br, struct super_block *sb) |
1facf9fc | 33266 | +{ |
33267 | + int err, i; | |
33268 | + const unsigned char do_plink | |
33269 | + = !!au_opt_test(au_mntflags(sb), PLINK); | |
1facf9fc | 33270 | + struct inode *h_dir; |
86dc4139 AM |
33271 | + struct path path = br->br_path; |
33272 | + struct dentry *h_root = path.dentry; | |
1facf9fc | 33273 | + struct au_wbr *wbr = br->br_wbr; |
33274 | + static const struct qstr base_name[] = { | |
0c3ec466 AM |
33275 | + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME, |
33276 | + sizeof(AUFS_BASE_NAME) - 1), | |
33277 | + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME, | |
33278 | + sizeof(AUFS_PLINKDIR_NAME) - 1), | |
33279 | + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME, | |
33280 | + sizeof(AUFS_ORPHDIR_NAME) - 1) | |
1facf9fc | 33281 | + }; |
33282 | + struct au_wh_base base[] = { | |
33283 | + [AuBrWh_BASE] = { | |
33284 | + .name = base_name + AuBrWh_BASE, | |
33285 | + .dentry = NULL | |
33286 | + }, | |
33287 | + [AuBrWh_PLINK] = { | |
33288 | + .name = base_name + AuBrWh_PLINK, | |
33289 | + .dentry = NULL | |
33290 | + }, | |
33291 | + [AuBrWh_ORPH] = { | |
33292 | + .name = base_name + AuBrWh_ORPH, | |
33293 | + .dentry = NULL | |
33294 | + } | |
33295 | + }; | |
33296 | + | |
1308ab2a | 33297 | + if (wbr) |
33298 | + WbrWhMustWriteLock(wbr); | |
1facf9fc | 33299 | + |
1facf9fc | 33300 | + for (i = 0; i < AuBrWh_Last; i++) { |
33301 | + /* doubly whiteouted */ | |
33302 | + struct dentry *d; | |
33303 | + | |
33304 | + d = au_wh_lkup(h_root, (void *)base[i].name, br); | |
33305 | + err = PTR_ERR(d); | |
33306 | + if (IS_ERR(d)) | |
33307 | + goto out; | |
33308 | + | |
33309 | + base[i].dentry = d; | |
33310 | + AuDebugOn(wbr | |
33311 | + && wbr->wbr_wh[i] | |
33312 | + && wbr->wbr_wh[i] != base[i].dentry); | |
33313 | + } | |
33314 | + | |
33315 | + if (wbr) | |
33316 | + for (i = 0; i < AuBrWh_Last; i++) { | |
33317 | + dput(wbr->wbr_wh[i]); | |
33318 | + wbr->wbr_wh[i] = NULL; | |
33319 | + } | |
33320 | + | |
33321 | + err = 0; | |
1e00d052 | 33322 | + if (!au_br_writable(br->br_perm)) { |
5527c038 | 33323 | + h_dir = d_inode(h_root); |
1facf9fc | 33324 | + au_wh_init_ro(h_dir, base, &path); |
1e00d052 | 33325 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 33326 | + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path); |
33327 | + if (err > 0) | |
33328 | + goto out; | |
33329 | + else if (err) | |
33330 | + goto out_err; | |
1e00d052 | 33331 | + } else { |
1facf9fc | 33332 | + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path); |
33333 | + if (err > 0) | |
33334 | + goto out; | |
33335 | + else if (err) | |
33336 | + goto out_err; | |
1facf9fc | 33337 | + } |
33338 | + goto out; /* success */ | |
33339 | + | |
4f0767ce | 33340 | +out_err: |
523b37e3 AM |
33341 | + pr_err("an error(%d) on the writable branch %pd(%s)\n", |
33342 | + err, h_root, au_sbtype(h_root->d_sb)); | |
4f0767ce | 33343 | +out: |
1facf9fc | 33344 | + for (i = 0; i < AuBrWh_Last; i++) |
33345 | + dput(base[i].dentry); | |
33346 | + return err; | |
33347 | +} | |
33348 | + | |
33349 | +/* ---------------------------------------------------------------------- */ | |
33350 | +/* | |
33351 | + * whiteouts are all hard-linked usually. | |
33352 | + * when its link count reaches a ceiling, we create a new whiteout base | |
33353 | + * asynchronously. | |
33354 | + */ | |
33355 | + | |
33356 | +struct reinit_br_wh { | |
33357 | + struct super_block *sb; | |
33358 | + struct au_branch *br; | |
33359 | +}; | |
33360 | + | |
33361 | +static void reinit_br_wh(void *arg) | |
33362 | +{ | |
33363 | + int err; | |
33364 | + aufs_bindex_t bindex; | |
33365 | + struct path h_path; | |
33366 | + struct reinit_br_wh *a = arg; | |
33367 | + struct au_wbr *wbr; | |
523b37e3 | 33368 | + struct inode *dir, *delegated; |
1facf9fc | 33369 | + struct dentry *h_root; |
33370 | + struct au_hinode *hdir; | |
33371 | + | |
33372 | + err = 0; | |
33373 | + wbr = a->br->br_wbr; | |
33374 | + /* big aufs lock */ | |
33375 | + si_noflush_write_lock(a->sb); | |
33376 | + if (!au_br_writable(a->br->br_perm)) | |
33377 | + goto out; | |
33378 | + bindex = au_br_index(a->sb, a->br->br_id); | |
33379 | + if (unlikely(bindex < 0)) | |
33380 | + goto out; | |
33381 | + | |
1308ab2a | 33382 | + di_read_lock_parent(a->sb->s_root, AuLock_IR); |
5527c038 | 33383 | + dir = d_inode(a->sb->s_root); |
1facf9fc | 33384 | + hdir = au_hi(dir, bindex); |
33385 | + h_root = au_h_dptr(a->sb->s_root, bindex); | |
86dc4139 | 33386 | + AuDebugOn(h_root != au_br_dentry(a->br)); |
1facf9fc | 33387 | + |
5afbbe0d | 33388 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 33389 | + wbr_wh_write_lock(wbr); |
33390 | + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode, | |
33391 | + h_root, a->br); | |
33392 | + if (!err) { | |
86dc4139 AM |
33393 | + h_path.dentry = wbr->wbr_whbase; |
33394 | + h_path.mnt = au_br_mnt(a->br); | |
523b37e3 AM |
33395 | + delegated = NULL; |
33396 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, | |
33397 | + /*force*/0); | |
33398 | + if (unlikely(err == -EWOULDBLOCK)) { | |
33399 | + pr_warn("cannot retry for NFSv4 delegation" | |
33400 | + " for an internal unlink\n"); | |
33401 | + iput(delegated); | |
33402 | + } | |
1facf9fc | 33403 | + } else { |
523b37e3 | 33404 | + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase); |
1facf9fc | 33405 | + err = 0; |
33406 | + } | |
33407 | + dput(wbr->wbr_whbase); | |
33408 | + wbr->wbr_whbase = NULL; | |
33409 | + if (!err) | |
86dc4139 | 33410 | + err = au_wh_init(a->br, a->sb); |
1facf9fc | 33411 | + wbr_wh_write_unlock(wbr); |
5afbbe0d | 33412 | + au_hn_inode_unlock(hdir); |
1308ab2a | 33413 | + di_read_unlock(a->sb->s_root, AuLock_IR); |
076b876e AM |
33414 | + if (!err) |
33415 | + au_fhsm_wrote(a->sb, bindex, /*force*/0); | |
1facf9fc | 33416 | + |
4f0767ce | 33417 | +out: |
1facf9fc | 33418 | + if (wbr) |
33419 | + atomic_dec(&wbr->wbr_wh_running); | |
5afbbe0d | 33420 | + au_br_put(a->br); |
1facf9fc | 33421 | + si_write_unlock(a->sb); |
027c5e7a | 33422 | + au_nwt_done(&au_sbi(a->sb)->si_nowait); |
f0c0a007 | 33423 | + au_delayed_kfree(arg); |
1facf9fc | 33424 | + if (unlikely(err)) |
33425 | + AuIOErr("err %d\n", err); | |
33426 | +} | |
33427 | + | |
33428 | +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br) | |
33429 | +{ | |
33430 | + int do_dec, wkq_err; | |
33431 | + struct reinit_br_wh *arg; | |
33432 | + | |
33433 | + do_dec = 1; | |
33434 | + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1) | |
33435 | + goto out; | |
33436 | + | |
33437 | + /* ignore ENOMEM */ | |
33438 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
33439 | + if (arg) { | |
33440 | + /* | |
33441 | + * dec(wh_running), kfree(arg) and dec(br_count) | |
33442 | + * in reinit function | |
33443 | + */ | |
33444 | + arg->sb = sb; | |
33445 | + arg->br = br; | |
5afbbe0d | 33446 | + au_br_get(br); |
53392da6 | 33447 | + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0); |
1facf9fc | 33448 | + if (unlikely(wkq_err)) { |
33449 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
5afbbe0d | 33450 | + au_br_put(br); |
f0c0a007 | 33451 | + au_delayed_kfree(arg); |
1facf9fc | 33452 | + } |
33453 | + do_dec = 0; | |
33454 | + } | |
33455 | + | |
4f0767ce | 33456 | +out: |
1facf9fc | 33457 | + if (do_dec) |
33458 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
33459 | +} | |
33460 | + | |
33461 | +/* ---------------------------------------------------------------------- */ | |
33462 | + | |
33463 | +/* | |
33464 | + * create the whiteout @wh. | |
33465 | + */ | |
33466 | +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex, | |
33467 | + struct dentry *wh) | |
33468 | +{ | |
33469 | + int err; | |
33470 | + struct path h_path = { | |
33471 | + .dentry = wh | |
33472 | + }; | |
33473 | + struct au_branch *br; | |
33474 | + struct au_wbr *wbr; | |
33475 | + struct dentry *h_parent; | |
523b37e3 | 33476 | + struct inode *h_dir, *delegated; |
1facf9fc | 33477 | + |
33478 | + h_parent = wh->d_parent; /* dir inode is locked */ | |
5527c038 | 33479 | + h_dir = d_inode(h_parent); |
1facf9fc | 33480 | + IMustLock(h_dir); |
33481 | + | |
33482 | + br = au_sbr(sb, bindex); | |
86dc4139 | 33483 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 33484 | + wbr = br->br_wbr; |
33485 | + wbr_wh_read_lock(wbr); | |
33486 | + if (wbr->wbr_whbase) { | |
523b37e3 AM |
33487 | + delegated = NULL; |
33488 | + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated); | |
33489 | + if (unlikely(err == -EWOULDBLOCK)) { | |
33490 | + pr_warn("cannot retry for NFSv4 delegation" | |
33491 | + " for an internal link\n"); | |
33492 | + iput(delegated); | |
33493 | + } | |
1facf9fc | 33494 | + if (!err || err != -EMLINK) |
33495 | + goto out; | |
33496 | + | |
33497 | + /* link count full. re-initialize br_whbase. */ | |
33498 | + kick_reinit_br_wh(sb, br); | |
33499 | + } | |
33500 | + | |
33501 | + /* return this error in this context */ | |
b4510431 | 33502 | + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true); |
076b876e AM |
33503 | + if (!err) |
33504 | + au_fhsm_wrote(sb, bindex, /*force*/0); | |
1facf9fc | 33505 | + |
4f0767ce | 33506 | +out: |
1facf9fc | 33507 | + wbr_wh_read_unlock(wbr); |
33508 | + return err; | |
33509 | +} | |
33510 | + | |
33511 | +/* ---------------------------------------------------------------------- */ | |
33512 | + | |
33513 | +/* | |
33514 | + * create or remove the diropq. | |
33515 | + */ | |
33516 | +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex, | |
33517 | + unsigned int flags) | |
33518 | +{ | |
33519 | + struct dentry *opq_dentry, *h_dentry; | |
33520 | + struct super_block *sb; | |
33521 | + struct au_branch *br; | |
33522 | + int err; | |
33523 | + | |
33524 | + sb = dentry->d_sb; | |
33525 | + br = au_sbr(sb, bindex); | |
33526 | + h_dentry = au_h_dptr(dentry, bindex); | |
b4510431 | 33527 | + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry); |
1facf9fc | 33528 | + if (IS_ERR(opq_dentry)) |
33529 | + goto out; | |
33530 | + | |
33531 | + if (au_ftest_diropq(flags, CREATE)) { | |
33532 | + err = link_or_create_wh(sb, bindex, opq_dentry); | |
33533 | + if (!err) { | |
33534 | + au_set_dbdiropq(dentry, bindex); | |
33535 | + goto out; /* success */ | |
33536 | + } | |
33537 | + } else { | |
33538 | + struct path tmp = { | |
33539 | + .dentry = opq_dentry, | |
86dc4139 | 33540 | + .mnt = au_br_mnt(br) |
1facf9fc | 33541 | + }; |
5527c038 | 33542 | + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp); |
1facf9fc | 33543 | + if (!err) |
33544 | + au_set_dbdiropq(dentry, -1); | |
33545 | + } | |
33546 | + dput(opq_dentry); | |
33547 | + opq_dentry = ERR_PTR(err); | |
33548 | + | |
4f0767ce | 33549 | +out: |
1facf9fc | 33550 | + return opq_dentry; |
33551 | +} | |
33552 | + | |
33553 | +struct do_diropq_args { | |
33554 | + struct dentry **errp; | |
33555 | + struct dentry *dentry; | |
33556 | + aufs_bindex_t bindex; | |
33557 | + unsigned int flags; | |
33558 | +}; | |
33559 | + | |
33560 | +static void call_do_diropq(void *args) | |
33561 | +{ | |
33562 | + struct do_diropq_args *a = args; | |
33563 | + *a->errp = do_diropq(a->dentry, a->bindex, a->flags); | |
33564 | +} | |
33565 | + | |
33566 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
33567 | + unsigned int flags) | |
33568 | +{ | |
33569 | + struct dentry *diropq, *h_dentry; | |
33570 | + | |
33571 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 33572 | + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE)) |
1facf9fc | 33573 | + diropq = do_diropq(dentry, bindex, flags); |
33574 | + else { | |
33575 | + int wkq_err; | |
33576 | + struct do_diropq_args args = { | |
33577 | + .errp = &diropq, | |
33578 | + .dentry = dentry, | |
33579 | + .bindex = bindex, | |
33580 | + .flags = flags | |
33581 | + }; | |
33582 | + | |
33583 | + wkq_err = au_wkq_wait(call_do_diropq, &args); | |
33584 | + if (unlikely(wkq_err)) | |
33585 | + diropq = ERR_PTR(wkq_err); | |
33586 | + } | |
33587 | + | |
33588 | + return diropq; | |
33589 | +} | |
33590 | + | |
33591 | +/* ---------------------------------------------------------------------- */ | |
33592 | + | |
33593 | +/* | |
33594 | + * lookup whiteout dentry. | |
33595 | + * @h_parent: lower parent dentry which must exist and be locked | |
33596 | + * @base_name: name of dentry which will be whiteouted | |
33597 | + * returns dentry for whiteout. | |
33598 | + */ | |
33599 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
33600 | + struct au_branch *br) | |
33601 | +{ | |
33602 | + int err; | |
33603 | + struct qstr wh_name; | |
33604 | + struct dentry *wh_dentry; | |
33605 | + | |
33606 | + err = au_wh_name_alloc(&wh_name, base_name); | |
33607 | + wh_dentry = ERR_PTR(err); | |
33608 | + if (!err) { | |
b4510431 | 33609 | + wh_dentry = vfsub_lkup_one(&wh_name, h_parent); |
f0c0a007 | 33610 | + au_delayed_kfree(wh_name.name); |
1facf9fc | 33611 | + } |
33612 | + return wh_dentry; | |
33613 | +} | |
33614 | + | |
33615 | +/* | |
33616 | + * link/create a whiteout for @dentry on @bindex. | |
33617 | + */ | |
33618 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
33619 | + struct dentry *h_parent) | |
33620 | +{ | |
33621 | + struct dentry *wh_dentry; | |
33622 | + struct super_block *sb; | |
33623 | + int err; | |
33624 | + | |
33625 | + sb = dentry->d_sb; | |
33626 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex)); | |
5527c038 | 33627 | + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) { |
1facf9fc | 33628 | + err = link_or_create_wh(sb, bindex, wh_dentry); |
076b876e | 33629 | + if (!err) { |
1facf9fc | 33630 | + au_set_dbwh(dentry, bindex); |
076b876e AM |
33631 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
33632 | + } else { | |
1facf9fc | 33633 | + dput(wh_dentry); |
33634 | + wh_dentry = ERR_PTR(err); | |
33635 | + } | |
33636 | + } | |
33637 | + | |
33638 | + return wh_dentry; | |
33639 | +} | |
33640 | + | |
33641 | +/* ---------------------------------------------------------------------- */ | |
33642 | + | |
33643 | +/* Delete all whiteouts in this directory on branch bindex. */ | |
33644 | +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist, | |
33645 | + aufs_bindex_t bindex, struct au_branch *br) | |
33646 | +{ | |
33647 | + int err; | |
33648 | + unsigned long ul, n; | |
33649 | + struct qstr wh_name; | |
33650 | + char *p; | |
33651 | + struct hlist_head *head; | |
c06a8ce3 | 33652 | + struct au_vdir_wh *pos; |
1facf9fc | 33653 | + struct au_vdir_destr *str; |
33654 | + | |
33655 | + err = -ENOMEM; | |
537831f9 | 33656 | + p = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 33657 | + wh_name.name = p; |
33658 | + if (unlikely(!wh_name.name)) | |
33659 | + goto out; | |
33660 | + | |
33661 | + err = 0; | |
33662 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
33663 | + p += AUFS_WH_PFX_LEN; | |
33664 | + n = whlist->nh_num; | |
33665 | + head = whlist->nh_head; | |
33666 | + for (ul = 0; !err && ul < n; ul++, head++) { | |
c06a8ce3 AM |
33667 | + hlist_for_each_entry(pos, head, wh_hash) { |
33668 | + if (pos->wh_bindex != bindex) | |
1facf9fc | 33669 | + continue; |
33670 | + | |
c06a8ce3 | 33671 | + str = &pos->wh_str; |
1facf9fc | 33672 | + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) { |
33673 | + memcpy(p, str->name, str->len); | |
33674 | + wh_name.len = AUFS_WH_PFX_LEN + str->len; | |
33675 | + err = unlink_wh_name(h_dentry, &wh_name, br); | |
33676 | + if (!err) | |
33677 | + continue; | |
33678 | + break; | |
33679 | + } | |
33680 | + AuIOErr("whiteout name too long %.*s\n", | |
33681 | + str->len, str->name); | |
33682 | + err = -EIO; | |
33683 | + break; | |
33684 | + } | |
33685 | + } | |
f0c0a007 | 33686 | + au_delayed_free_page((unsigned long)wh_name.name); |
1facf9fc | 33687 | + |
4f0767ce | 33688 | +out: |
1facf9fc | 33689 | + return err; |
33690 | +} | |
33691 | + | |
33692 | +struct del_wh_children_args { | |
33693 | + int *errp; | |
33694 | + struct dentry *h_dentry; | |
1308ab2a | 33695 | + struct au_nhash *whlist; |
1facf9fc | 33696 | + aufs_bindex_t bindex; |
33697 | + struct au_branch *br; | |
33698 | +}; | |
33699 | + | |
33700 | +static void call_del_wh_children(void *args) | |
33701 | +{ | |
33702 | + struct del_wh_children_args *a = args; | |
1308ab2a | 33703 | + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br); |
1facf9fc | 33704 | +} |
33705 | + | |
33706 | +/* ---------------------------------------------------------------------- */ | |
33707 | + | |
33708 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp) | |
33709 | +{ | |
33710 | + struct au_whtmp_rmdir *whtmp; | |
dece6358 | 33711 | + int err; |
1308ab2a | 33712 | + unsigned int rdhash; |
dece6358 AM |
33713 | + |
33714 | + SiMustAnyLock(sb); | |
1facf9fc | 33715 | + |
be52b249 | 33716 | + whtmp = kzalloc(sizeof(*whtmp), gfp); |
dece6358 AM |
33717 | + if (unlikely(!whtmp)) { |
33718 | + whtmp = ERR_PTR(-ENOMEM); | |
1facf9fc | 33719 | + goto out; |
dece6358 | 33720 | + } |
1facf9fc | 33721 | + |
1308ab2a | 33722 | + /* no estimation for dir size */ |
33723 | + rdhash = au_sbi(sb)->si_rdhash; | |
33724 | + if (!rdhash) | |
33725 | + rdhash = AUFS_RDHASH_DEF; | |
33726 | + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp); | |
33727 | + if (unlikely(err)) { | |
f0c0a007 | 33728 | + au_delayed_kfree(whtmp); |
1308ab2a | 33729 | + whtmp = ERR_PTR(err); |
33730 | + } | |
dece6358 | 33731 | + |
4f0767ce | 33732 | +out: |
dece6358 | 33733 | + return whtmp; |
1facf9fc | 33734 | +} |
33735 | + | |
33736 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp) | |
33737 | +{ | |
027c5e7a | 33738 | + if (whtmp->br) |
5afbbe0d | 33739 | + au_br_put(whtmp->br); |
1facf9fc | 33740 | + dput(whtmp->wh_dentry); |
33741 | + iput(whtmp->dir); | |
dece6358 | 33742 | + au_nhash_wh_free(&whtmp->whlist); |
f0c0a007 | 33743 | + au_delayed_kfree(whtmp); |
1facf9fc | 33744 | +} |
33745 | + | |
33746 | +/* | |
33747 | + * rmdir the whiteouted temporary named dir @h_dentry. | |
33748 | + * @whlist: whiteouted children. | |
33749 | + */ | |
33750 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
33751 | + struct dentry *wh_dentry, struct au_nhash *whlist) | |
33752 | +{ | |
33753 | + int err; | |
2000de60 | 33754 | + unsigned int h_nlink; |
1facf9fc | 33755 | + struct path h_tmp; |
33756 | + struct inode *wh_inode, *h_dir; | |
33757 | + struct au_branch *br; | |
33758 | + | |
5527c038 | 33759 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
1facf9fc | 33760 | + IMustLock(h_dir); |
33761 | + | |
33762 | + br = au_sbr(dir->i_sb, bindex); | |
5527c038 | 33763 | + wh_inode = d_inode(wh_dentry); |
febd17d6 | 33764 | + inode_lock_nested(wh_inode, AuLsc_I_CHILD); |
1facf9fc | 33765 | + |
33766 | + /* | |
33767 | + * someone else might change some whiteouts while we were sleeping. | |
33768 | + * it means this whlist may have an obsoleted entry. | |
33769 | + */ | |
33770 | + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE)) | |
33771 | + err = del_wh_children(wh_dentry, whlist, bindex, br); | |
33772 | + else { | |
33773 | + int wkq_err; | |
33774 | + struct del_wh_children_args args = { | |
33775 | + .errp = &err, | |
33776 | + .h_dentry = wh_dentry, | |
1308ab2a | 33777 | + .whlist = whlist, |
1facf9fc | 33778 | + .bindex = bindex, |
33779 | + .br = br | |
33780 | + }; | |
33781 | + | |
33782 | + wkq_err = au_wkq_wait(call_del_wh_children, &args); | |
33783 | + if (unlikely(wkq_err)) | |
33784 | + err = wkq_err; | |
33785 | + } | |
febd17d6 | 33786 | + inode_unlock(wh_inode); |
1facf9fc | 33787 | + |
33788 | + if (!err) { | |
33789 | + h_tmp.dentry = wh_dentry; | |
86dc4139 | 33790 | + h_tmp.mnt = au_br_mnt(br); |
2000de60 | 33791 | + h_nlink = h_dir->i_nlink; |
1facf9fc | 33792 | + err = vfsub_rmdir(h_dir, &h_tmp); |
2000de60 JR |
33793 | + /* some fs doesn't change the parent nlink in some cases */ |
33794 | + h_nlink -= h_dir->i_nlink; | |
1facf9fc | 33795 | + } |
33796 | + | |
33797 | + if (!err) { | |
5afbbe0d | 33798 | + if (au_ibtop(dir) == bindex) { |
7f207e10 | 33799 | + /* todo: dir->i_mutex is necessary */ |
1facf9fc | 33800 | + au_cpup_attr_timesizes(dir); |
2000de60 JR |
33801 | + if (h_nlink) |
33802 | + vfsub_drop_nlink(dir); | |
1facf9fc | 33803 | + } |
33804 | + return 0; /* success */ | |
33805 | + } | |
33806 | + | |
523b37e3 | 33807 | + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err); |
1facf9fc | 33808 | + return err; |
33809 | +} | |
33810 | + | |
33811 | +static void call_rmdir_whtmp(void *args) | |
33812 | +{ | |
33813 | + int err; | |
e49829fe | 33814 | + aufs_bindex_t bindex; |
1facf9fc | 33815 | + struct au_whtmp_rmdir *a = args; |
33816 | + struct super_block *sb; | |
33817 | + struct dentry *h_parent; | |
33818 | + struct inode *h_dir; | |
1facf9fc | 33819 | + struct au_hinode *hdir; |
33820 | + | |
33821 | + /* rmdir by nfsd may cause deadlock with this i_mutex */ | |
febd17d6 | 33822 | + /* inode_lock(a->dir); */ |
e49829fe | 33823 | + err = -EROFS; |
1facf9fc | 33824 | + sb = a->dir->i_sb; |
e49829fe JR |
33825 | + si_read_lock(sb, !AuLock_FLUSH); |
33826 | + if (!au_br_writable(a->br->br_perm)) | |
33827 | + goto out; | |
33828 | + bindex = au_br_index(sb, a->br->br_id); | |
33829 | + if (unlikely(bindex < 0)) | |
1facf9fc | 33830 | + goto out; |
33831 | + | |
33832 | + err = -EIO; | |
1facf9fc | 33833 | + ii_write_lock_parent(a->dir); |
33834 | + h_parent = dget_parent(a->wh_dentry); | |
5527c038 | 33835 | + h_dir = d_inode(h_parent); |
e49829fe | 33836 | + hdir = au_hi(a->dir, bindex); |
86dc4139 AM |
33837 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); |
33838 | + if (unlikely(err)) | |
33839 | + goto out_mnt; | |
5afbbe0d | 33840 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
e49829fe JR |
33841 | + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent, |
33842 | + a->br); | |
86dc4139 AM |
33843 | + if (!err) |
33844 | + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist); | |
5afbbe0d | 33845 | + au_hn_inode_unlock(hdir); |
86dc4139 AM |
33846 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
33847 | + | |
33848 | +out_mnt: | |
1facf9fc | 33849 | + dput(h_parent); |
33850 | + ii_write_unlock(a->dir); | |
4f0767ce | 33851 | +out: |
febd17d6 | 33852 | + /* inode_unlock(a->dir); */ |
1facf9fc | 33853 | + au_whtmp_rmdir_free(a); |
027c5e7a AM |
33854 | + si_read_unlock(sb); |
33855 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
1facf9fc | 33856 | + if (unlikely(err)) |
33857 | + AuIOErr("err %d\n", err); | |
33858 | +} | |
33859 | + | |
33860 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
33861 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args) | |
33862 | +{ | |
33863 | + int wkq_err; | |
e49829fe | 33864 | + struct super_block *sb; |
1facf9fc | 33865 | + |
33866 | + IMustLock(dir); | |
33867 | + | |
33868 | + /* all post-process will be done in do_rmdir_whtmp(). */ | |
e49829fe | 33869 | + sb = dir->i_sb; |
1facf9fc | 33870 | + args->dir = au_igrab(dir); |
e49829fe | 33871 | + args->br = au_sbr(sb, bindex); |
5afbbe0d | 33872 | + au_br_get(args->br); |
1facf9fc | 33873 | + args->wh_dentry = dget(wh_dentry); |
53392da6 | 33874 | + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0); |
1facf9fc | 33875 | + if (unlikely(wkq_err)) { |
523b37e3 | 33876 | + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err); |
1facf9fc | 33877 | + au_whtmp_rmdir_free(args); |
33878 | + } | |
33879 | +} | |
7f207e10 AM |
33880 | diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h |
33881 | --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 33882 | +++ linux/fs/aufs/whout.h 2017-05-06 22:16:52.784886929 +0200 |
076b876e | 33883 | @@ -0,0 +1,85 @@ |
1facf9fc | 33884 | +/* |
a2654f78 | 33885 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 33886 | + * |
33887 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33888 | + * it under the terms of the GNU General Public License as published by | |
33889 | + * the Free Software Foundation; either version 2 of the License, or | |
33890 | + * (at your option) any later version. | |
dece6358 AM |
33891 | + * |
33892 | + * This program is distributed in the hope that it will be useful, | |
33893 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33894 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33895 | + * GNU General Public License for more details. | |
33896 | + * | |
33897 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33898 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33899 | + */ |
33900 | + | |
33901 | +/* | |
33902 | + * whiteout for logical deletion and opaque directory | |
33903 | + */ | |
33904 | + | |
33905 | +#ifndef __AUFS_WHOUT_H__ | |
33906 | +#define __AUFS_WHOUT_H__ | |
33907 | + | |
33908 | +#ifdef __KERNEL__ | |
33909 | + | |
1facf9fc | 33910 | +#include "dir.h" |
33911 | + | |
33912 | +/* whout.c */ | |
33913 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name); | |
076b876e AM |
33914 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio); |
33915 | +int au_diropq_test(struct dentry *h_dentry); | |
7e9cd9fe | 33916 | +struct au_branch; |
1facf9fc | 33917 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, |
33918 | + struct qstr *prefix); | |
33919 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br); | |
33920 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
33921 | + struct dentry *dentry); | |
86dc4139 | 33922 | +int au_wh_init(struct au_branch *br, struct super_block *sb); |
1facf9fc | 33923 | + |
33924 | +/* diropq flags */ | |
33925 | +#define AuDiropq_CREATE 1 | |
33926 | +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name) | |
7f207e10 AM |
33927 | +#define au_fset_diropq(flags, name) \ |
33928 | + do { (flags) |= AuDiropq_##name; } while (0) | |
33929 | +#define au_fclr_diropq(flags, name) \ | |
33930 | + do { (flags) &= ~AuDiropq_##name; } while (0) | |
1facf9fc | 33931 | + |
33932 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
33933 | + unsigned int flags); | |
33934 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
33935 | + struct au_branch *br); | |
33936 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
33937 | + struct dentry *h_parent); | |
33938 | + | |
33939 | +/* real rmdir for the whiteout-ed dir */ | |
33940 | +struct au_whtmp_rmdir { | |
33941 | + struct inode *dir; | |
e49829fe | 33942 | + struct au_branch *br; |
1facf9fc | 33943 | + struct dentry *wh_dentry; |
dece6358 | 33944 | + struct au_nhash whlist; |
1facf9fc | 33945 | +}; |
33946 | + | |
33947 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp); | |
33948 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp); | |
33949 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
33950 | + struct dentry *wh_dentry, struct au_nhash *whlist); | |
33951 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
33952 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args); | |
33953 | + | |
33954 | +/* ---------------------------------------------------------------------- */ | |
33955 | + | |
33956 | +static inline struct dentry *au_diropq_create(struct dentry *dentry, | |
33957 | + aufs_bindex_t bindex) | |
33958 | +{ | |
33959 | + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE); | |
33960 | +} | |
33961 | + | |
33962 | +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex) | |
33963 | +{ | |
33964 | + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE)); | |
33965 | +} | |
33966 | + | |
33967 | +#endif /* __KERNEL__ */ | |
33968 | +#endif /* __AUFS_WHOUT_H__ */ | |
7f207e10 AM |
33969 | diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c |
33970 | --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 33971 | +++ linux/fs/aufs/wkq.c 2017-05-06 22:16:52.784886929 +0200 |
f0c0a007 | 33972 | @@ -0,0 +1,213 @@ |
1facf9fc | 33973 | +/* |
a2654f78 | 33974 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 33975 | + * |
33976 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33977 | + * it under the terms of the GNU General Public License as published by | |
33978 | + * the Free Software Foundation; either version 2 of the License, or | |
33979 | + * (at your option) any later version. | |
dece6358 AM |
33980 | + * |
33981 | + * This program is distributed in the hope that it will be useful, | |
33982 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33983 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33984 | + * GNU General Public License for more details. | |
33985 | + * | |
33986 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33987 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33988 | + */ |
33989 | + | |
33990 | +/* | |
33991 | + * workqueue for asynchronous/super-io operations | |
33992 | + * todo: try new dredential scheme | |
33993 | + */ | |
33994 | + | |
dece6358 | 33995 | +#include <linux/module.h> |
1facf9fc | 33996 | +#include "aufs.h" |
33997 | + | |
9dbd164d | 33998 | +/* internal workqueue named AUFS_WKQ_NAME */ |
b752ccd1 | 33999 | + |
9dbd164d | 34000 | +static struct workqueue_struct *au_wkq; |
1facf9fc | 34001 | + |
34002 | +struct au_wkinfo { | |
34003 | + struct work_struct wk; | |
7f207e10 | 34004 | + struct kobject *kobj; |
1facf9fc | 34005 | + |
34006 | + unsigned int flags; /* see wkq.h */ | |
34007 | + | |
34008 | + au_wkq_func_t func; | |
34009 | + void *args; | |
34010 | + | |
1facf9fc | 34011 | + struct completion *comp; |
34012 | +}; | |
34013 | + | |
34014 | +/* ---------------------------------------------------------------------- */ | |
34015 | + | |
1facf9fc | 34016 | +static void wkq_func(struct work_struct *wk) |
34017 | +{ | |
34018 | + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk); | |
34019 | + | |
2dfbb274 | 34020 | + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)); |
7f207e10 AM |
34021 | + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY); |
34022 | + | |
1facf9fc | 34023 | + wkinfo->func(wkinfo->args); |
1facf9fc | 34024 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) |
34025 | + complete(wkinfo->comp); | |
34026 | + else { | |
7f207e10 | 34027 | + kobject_put(wkinfo->kobj); |
9dbd164d | 34028 | + module_put(THIS_MODULE); /* todo: ?? */ |
f0c0a007 | 34029 | + au_delayed_kfree(wkinfo); |
1facf9fc | 34030 | + } |
34031 | +} | |
34032 | + | |
34033 | +/* | |
34034 | + * Since struct completion is large, try allocating it dynamically. | |
34035 | + */ | |
c2b27bf2 | 34036 | +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */ |
1facf9fc | 34037 | +#define AuWkqCompDeclare(name) struct completion *comp = NULL |
34038 | + | |
34039 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
34040 | +{ | |
34041 | + *comp = kmalloc(sizeof(**comp), GFP_NOFS); | |
34042 | + if (*comp) { | |
34043 | + init_completion(*comp); | |
34044 | + wkinfo->comp = *comp; | |
34045 | + return 0; | |
34046 | + } | |
34047 | + return -ENOMEM; | |
34048 | +} | |
34049 | + | |
34050 | +static void au_wkq_comp_free(struct completion *comp) | |
34051 | +{ | |
f0c0a007 | 34052 | + au_delayed_kfree(comp); |
1facf9fc | 34053 | +} |
34054 | + | |
34055 | +#else | |
34056 | + | |
34057 | +/* no braces */ | |
34058 | +#define AuWkqCompDeclare(name) \ | |
34059 | + DECLARE_COMPLETION_ONSTACK(_ ## name); \ | |
34060 | + struct completion *comp = &_ ## name | |
34061 | + | |
34062 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
34063 | +{ | |
34064 | + wkinfo->comp = *comp; | |
34065 | + return 0; | |
34066 | +} | |
34067 | + | |
34068 | +static void au_wkq_comp_free(struct completion *comp __maybe_unused) | |
34069 | +{ | |
34070 | + /* empty */ | |
34071 | +} | |
34072 | +#endif /* 4KSTACKS */ | |
34073 | + | |
53392da6 | 34074 | +static void au_wkq_run(struct au_wkinfo *wkinfo) |
1facf9fc | 34075 | +{ |
53392da6 AM |
34076 | + if (au_ftest_wkq(wkinfo->flags, NEST)) { |
34077 | + if (au_wkq_test()) { | |
38d290e6 JR |
34078 | + AuWarn1("wkq from wkq, unless silly-rename on NFS," |
34079 | + " due to a dead dir by UDBA?\n"); | |
53392da6 AM |
34080 | + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT)); |
34081 | + } | |
34082 | + } else | |
34083 | + au_dbg_verify_kthread(); | |
34084 | + | |
34085 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) { | |
a1f66529 | 34086 | + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func); |
9dbd164d | 34087 | + queue_work(au_wkq, &wkinfo->wk); |
4a4d8108 AM |
34088 | + } else { |
34089 | + INIT_WORK(&wkinfo->wk, wkq_func); | |
34090 | + schedule_work(&wkinfo->wk); | |
34091 | + } | |
1facf9fc | 34092 | +} |
34093 | + | |
7f207e10 AM |
34094 | +/* |
34095 | + * Be careful. It is easy to make deadlock happen. | |
34096 | + * processA: lock, wkq and wait | |
34097 | + * processB: wkq and wait, lock in wkq | |
34098 | + * --> deadlock | |
34099 | + */ | |
b752ccd1 | 34100 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args) |
1facf9fc | 34101 | +{ |
34102 | + int err; | |
34103 | + AuWkqCompDeclare(comp); | |
34104 | + struct au_wkinfo wkinfo = { | |
b752ccd1 | 34105 | + .flags = flags, |
1facf9fc | 34106 | + .func = func, |
34107 | + .args = args | |
34108 | + }; | |
34109 | + | |
34110 | + err = au_wkq_comp_alloc(&wkinfo, &comp); | |
34111 | + if (!err) { | |
53392da6 | 34112 | + au_wkq_run(&wkinfo); |
1facf9fc | 34113 | + /* no timeout, no interrupt */ |
34114 | + wait_for_completion(wkinfo.comp); | |
34115 | + au_wkq_comp_free(comp); | |
4a4d8108 | 34116 | + destroy_work_on_stack(&wkinfo.wk); |
1facf9fc | 34117 | + } |
34118 | + | |
34119 | + return err; | |
34120 | + | |
34121 | +} | |
34122 | + | |
027c5e7a AM |
34123 | +/* |
34124 | + * Note: dget/dput() in func for aufs dentries are not supported. It will be a | |
34125 | + * problem in a concurrent umounting. | |
34126 | + */ | |
53392da6 AM |
34127 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
34128 | + unsigned int flags) | |
1facf9fc | 34129 | +{ |
34130 | + int err; | |
34131 | + struct au_wkinfo *wkinfo; | |
34132 | + | |
f0c0a007 | 34133 | + atomic_inc(&au_sbi(sb)->si_nowait.nw_len); |
1facf9fc | 34134 | + |
34135 | + /* | |
34136 | + * wkq_func() must free this wkinfo. | |
34137 | + * it highly depends upon the implementation of workqueue. | |
34138 | + */ | |
34139 | + err = 0; | |
34140 | + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS); | |
34141 | + if (wkinfo) { | |
7f207e10 | 34142 | + wkinfo->kobj = &au_sbi(sb)->si_kobj; |
53392da6 | 34143 | + wkinfo->flags = flags & ~AuWkq_WAIT; |
1facf9fc | 34144 | + wkinfo->func = func; |
34145 | + wkinfo->args = args; | |
34146 | + wkinfo->comp = NULL; | |
7f207e10 | 34147 | + kobject_get(wkinfo->kobj); |
9dbd164d | 34148 | + __module_get(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 34149 | + |
53392da6 | 34150 | + au_wkq_run(wkinfo); |
1facf9fc | 34151 | + } else { |
34152 | + err = -ENOMEM; | |
e49829fe | 34153 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 34154 | + } |
34155 | + | |
34156 | + return err; | |
34157 | +} | |
34158 | + | |
34159 | +/* ---------------------------------------------------------------------- */ | |
34160 | + | |
34161 | +void au_nwt_init(struct au_nowait_tasks *nwt) | |
34162 | +{ | |
f0c0a007 AM |
34163 | + atomic_set(&nwt->nw_len, 0); |
34164 | + /* smp_mb(); */ /* atomic_set */ | |
1facf9fc | 34165 | + init_waitqueue_head(&nwt->nw_wq); |
34166 | +} | |
34167 | + | |
34168 | +void au_wkq_fin(void) | |
34169 | +{ | |
9dbd164d | 34170 | + destroy_workqueue(au_wkq); |
1facf9fc | 34171 | +} |
34172 | + | |
34173 | +int __init au_wkq_init(void) | |
34174 | +{ | |
9dbd164d | 34175 | + int err; |
b752ccd1 AM |
34176 | + |
34177 | + err = 0; | |
86dc4139 | 34178 | + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE); |
9dbd164d AM |
34179 | + if (IS_ERR(au_wkq)) |
34180 | + err = PTR_ERR(au_wkq); | |
34181 | + else if (!au_wkq) | |
34182 | + err = -ENOMEM; | |
b752ccd1 AM |
34183 | + |
34184 | + return err; | |
1facf9fc | 34185 | +} |
7f207e10 AM |
34186 | diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h |
34187 | --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 34188 | +++ linux/fs/aufs/wkq.h 2017-05-06 22:16:52.784886929 +0200 |
f0c0a007 | 34189 | @@ -0,0 +1,93 @@ |
1facf9fc | 34190 | +/* |
a2654f78 | 34191 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 34192 | + * |
34193 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34194 | + * it under the terms of the GNU General Public License as published by | |
34195 | + * the Free Software Foundation; either version 2 of the License, or | |
34196 | + * (at your option) any later version. | |
dece6358 AM |
34197 | + * |
34198 | + * This program is distributed in the hope that it will be useful, | |
34199 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34200 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34201 | + * GNU General Public License for more details. | |
34202 | + * | |
34203 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 34204 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 34205 | + */ |
34206 | + | |
34207 | +/* | |
34208 | + * workqueue for asynchronous/super-io operations | |
34209 | + * todo: try new credentials management scheme | |
34210 | + */ | |
34211 | + | |
34212 | +#ifndef __AUFS_WKQ_H__ | |
34213 | +#define __AUFS_WKQ_H__ | |
34214 | + | |
34215 | +#ifdef __KERNEL__ | |
34216 | + | |
5afbbe0d AM |
34217 | +#include <linux/percpu_counter.h> |
34218 | + | |
dece6358 AM |
34219 | +struct super_block; |
34220 | + | |
1facf9fc | 34221 | +/* ---------------------------------------------------------------------- */ |
34222 | + | |
34223 | +/* | |
34224 | + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue | |
34225 | + */ | |
34226 | +struct au_nowait_tasks { | |
f0c0a007 | 34227 | + atomic_t nw_len; |
1facf9fc | 34228 | + wait_queue_head_t nw_wq; |
34229 | +}; | |
34230 | + | |
34231 | +/* ---------------------------------------------------------------------- */ | |
34232 | + | |
34233 | +typedef void (*au_wkq_func_t)(void *args); | |
34234 | + | |
34235 | +/* wkq flags */ | |
34236 | +#define AuWkq_WAIT 1 | |
9dbd164d | 34237 | +#define AuWkq_NEST (1 << 1) |
1facf9fc | 34238 | +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name) |
7f207e10 AM |
34239 | +#define au_fset_wkq(flags, name) \ |
34240 | + do { (flags) |= AuWkq_##name; } while (0) | |
34241 | +#define au_fclr_wkq(flags, name) \ | |
34242 | + do { (flags) &= ~AuWkq_##name; } while (0) | |
1facf9fc | 34243 | + |
9dbd164d AM |
34244 | +#ifndef CONFIG_AUFS_HNOTIFY |
34245 | +#undef AuWkq_NEST | |
34246 | +#define AuWkq_NEST 0 | |
34247 | +#endif | |
34248 | + | |
1facf9fc | 34249 | +/* wkq.c */ |
b752ccd1 | 34250 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args); |
53392da6 AM |
34251 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
34252 | + unsigned int flags); | |
1facf9fc | 34253 | +void au_nwt_init(struct au_nowait_tasks *nwt); |
34254 | +int __init au_wkq_init(void); | |
34255 | +void au_wkq_fin(void); | |
34256 | + | |
34257 | +/* ---------------------------------------------------------------------- */ | |
34258 | + | |
53392da6 AM |
34259 | +static inline int au_wkq_test(void) |
34260 | +{ | |
34261 | + return current->flags & PF_WQ_WORKER; | |
34262 | +} | |
34263 | + | |
b752ccd1 | 34264 | +static inline int au_wkq_wait(au_wkq_func_t func, void *args) |
1facf9fc | 34265 | +{ |
b752ccd1 | 34266 | + return au_wkq_do_wait(AuWkq_WAIT, func, args); |
1facf9fc | 34267 | +} |
34268 | + | |
34269 | +static inline void au_nwt_done(struct au_nowait_tasks *nwt) | |
34270 | +{ | |
f0c0a007 | 34271 | + if (atomic_dec_and_test(&nwt->nw_len)) |
1facf9fc | 34272 | + wake_up_all(&nwt->nw_wq); |
34273 | +} | |
34274 | + | |
34275 | +static inline int au_nwt_flush(struct au_nowait_tasks *nwt) | |
34276 | +{ | |
f0c0a007 | 34277 | + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len)); |
1facf9fc | 34278 | + return 0; |
34279 | +} | |
34280 | + | |
34281 | +#endif /* __KERNEL__ */ | |
34282 | +#endif /* __AUFS_WKQ_H__ */ | |
c1595e42 JR |
34283 | diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c |
34284 | --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 34285 | +++ linux/fs/aufs/xattr.c 2017-05-06 22:16:52.784886929 +0200 |
a2654f78 | 34286 | @@ -0,0 +1,357 @@ |
c1595e42 | 34287 | +/* |
a2654f78 | 34288 | + * Copyright (C) 2014-2017 Junjiro R. Okajima |
c1595e42 JR |
34289 | + * |
34290 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34291 | + * it under the terms of the GNU General Public License as published by | |
34292 | + * the Free Software Foundation; either version 2 of the License, or | |
34293 | + * (at your option) any later version. | |
34294 | + * | |
34295 | + * This program is distributed in the hope that it will be useful, | |
34296 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34297 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34298 | + * GNU General Public License for more details. | |
34299 | + * | |
34300 | + * You should have received a copy of the GNU General Public License | |
34301 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
34302 | + */ | |
34303 | + | |
34304 | +/* | |
34305 | + * handling xattr functions | |
34306 | + */ | |
34307 | + | |
a2654f78 AM |
34308 | +#include <linux/fs.h> |
34309 | +#include <linux/posix_acl_xattr.h> | |
c1595e42 JR |
34310 | +#include <linux/xattr.h> |
34311 | +#include "aufs.h" | |
34312 | + | |
34313 | +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags) | |
34314 | +{ | |
34315 | + if (!ignore_flags) | |
34316 | + goto out; | |
34317 | + switch (err) { | |
34318 | + case -ENOMEM: | |
34319 | + case -EDQUOT: | |
34320 | + goto out; | |
34321 | + } | |
34322 | + | |
34323 | + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) { | |
34324 | + err = 0; | |
34325 | + goto out; | |
34326 | + } | |
34327 | + | |
34328 | +#define cmp(brattr, prefix) do { \ | |
34329 | + if (!strncmp(name, XATTR_##prefix##_PREFIX, \ | |
34330 | + XATTR_##prefix##_PREFIX_LEN)) { \ | |
34331 | + if (ignore_flags & AuBrAttr_ICEX_##brattr) \ | |
34332 | + err = 0; \ | |
34333 | + goto out; \ | |
34334 | + } \ | |
34335 | + } while (0) | |
34336 | + | |
34337 | + cmp(SEC, SECURITY); | |
34338 | + cmp(SYS, SYSTEM); | |
34339 | + cmp(TR, TRUSTED); | |
34340 | + cmp(USR, USER); | |
34341 | +#undef cmp | |
34342 | + | |
34343 | + if (ignore_flags & AuBrAttr_ICEX_OTH) | |
34344 | + err = 0; | |
34345 | + | |
34346 | +out: | |
34347 | + return err; | |
34348 | +} | |
34349 | + | |
34350 | +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1; | |
34351 | + | |
34352 | +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe AM |
34353 | + char *name, char **buf, unsigned int ignore_flags, |
34354 | + unsigned int verbose) | |
c1595e42 JR |
34355 | +{ |
34356 | + int err; | |
34357 | + ssize_t ssz; | |
34358 | + struct inode *h_idst; | |
34359 | + | |
34360 | + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS); | |
34361 | + err = ssz; | |
34362 | + if (unlikely(err <= 0)) { | |
c1595e42 JR |
34363 | + if (err == -ENODATA |
34364 | + || (err == -EOPNOTSUPP | |
b912730e | 34365 | + && ((ignore_flags & au_xattr_out_of_list) |
5527c038 | 34366 | + || (au_test_nfs_noacl(d_inode(h_src)) |
b912730e AM |
34367 | + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) |
34368 | + || !strcmp(name, | |
34369 | + XATTR_NAME_POSIX_ACL_DEFAULT)))) | |
34370 | + )) | |
c1595e42 | 34371 | + err = 0; |
b912730e AM |
34372 | + if (err && (verbose || au_debug_test())) |
34373 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
34374 | + goto out; |
34375 | + } | |
34376 | + | |
34377 | + /* unlock it temporary */ | |
5527c038 | 34378 | + h_idst = d_inode(h_dst); |
febd17d6 | 34379 | + inode_unlock(h_idst); |
c1595e42 | 34380 | + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0); |
febd17d6 | 34381 | + inode_lock_nested(h_idst, AuLsc_I_CHILD2); |
c1595e42 | 34382 | + if (unlikely(err)) { |
7e9cd9fe AM |
34383 | + if (verbose || au_debug_test()) |
34384 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
34385 | + err = au_xattr_ignore(err, name, ignore_flags); |
34386 | + } | |
34387 | + | |
34388 | +out: | |
34389 | + return err; | |
34390 | +} | |
34391 | + | |
7e9cd9fe AM |
34392 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
34393 | + unsigned int verbose) | |
c1595e42 JR |
34394 | +{ |
34395 | + int err, unlocked, acl_access, acl_default; | |
34396 | + ssize_t ssz; | |
34397 | + struct inode *h_isrc, *h_idst; | |
34398 | + char *value, *p, *o, *e; | |
34399 | + | |
34400 | + /* try stopping to update the source inode while we are referencing */ | |
7e9cd9fe | 34401 | + /* there should not be the parent-child relationship between them */ |
5527c038 JR |
34402 | + h_isrc = d_inode(h_src); |
34403 | + h_idst = d_inode(h_dst); | |
febd17d6 JR |
34404 | + inode_unlock(h_idst); |
34405 | + inode_lock_nested(h_isrc, AuLsc_I_CHILD); | |
34406 | + inode_lock_nested(h_idst, AuLsc_I_CHILD2); | |
c1595e42 JR |
34407 | + unlocked = 0; |
34408 | + | |
34409 | + /* some filesystems don't list POSIX ACL, for example tmpfs */ | |
34410 | + ssz = vfs_listxattr(h_src, NULL, 0); | |
34411 | + err = ssz; | |
34412 | + if (unlikely(err < 0)) { | |
34413 | + AuTraceErr(err); | |
34414 | + if (err == -ENODATA | |
34415 | + || err == -EOPNOTSUPP) | |
34416 | + err = 0; /* ignore */ | |
34417 | + goto out; | |
34418 | + } | |
34419 | + | |
34420 | + err = 0; | |
34421 | + p = NULL; | |
34422 | + o = NULL; | |
34423 | + if (ssz) { | |
34424 | + err = -ENOMEM; | |
34425 | + p = kmalloc(ssz, GFP_NOFS); | |
34426 | + o = p; | |
34427 | + if (unlikely(!p)) | |
34428 | + goto out; | |
34429 | + err = vfs_listxattr(h_src, p, ssz); | |
34430 | + } | |
febd17d6 | 34431 | + inode_unlock(h_isrc); |
c1595e42 JR |
34432 | + unlocked = 1; |
34433 | + AuDbg("err %d, ssz %zd\n", err, ssz); | |
34434 | + if (unlikely(err < 0)) | |
34435 | + goto out_free; | |
34436 | + | |
34437 | + err = 0; | |
34438 | + e = p + ssz; | |
34439 | + value = NULL; | |
34440 | + acl_access = 0; | |
34441 | + acl_default = 0; | |
34442 | + while (!err && p < e) { | |
34443 | + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS, | |
34444 | + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1); | |
34445 | + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT, | |
34446 | + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) | |
34447 | + - 1); | |
7e9cd9fe AM |
34448 | + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags, |
34449 | + verbose); | |
c1595e42 JR |
34450 | + p += strlen(p) + 1; |
34451 | + } | |
34452 | + AuTraceErr(err); | |
34453 | + ignore_flags |= au_xattr_out_of_list; | |
34454 | + if (!err && !acl_access) { | |
34455 | + err = au_do_cpup_xattr(h_dst, h_src, | |
34456 | + XATTR_NAME_POSIX_ACL_ACCESS, &value, | |
7e9cd9fe | 34457 | + ignore_flags, verbose); |
c1595e42 JR |
34458 | + AuTraceErr(err); |
34459 | + } | |
34460 | + if (!err && !acl_default) { | |
34461 | + err = au_do_cpup_xattr(h_dst, h_src, | |
34462 | + XATTR_NAME_POSIX_ACL_DEFAULT, &value, | |
7e9cd9fe | 34463 | + ignore_flags, verbose); |
c1595e42 JR |
34464 | + AuTraceErr(err); |
34465 | + } | |
34466 | + | |
f0c0a007 AM |
34467 | + if (value) |
34468 | + au_delayed_kfree(value); | |
c1595e42 JR |
34469 | + |
34470 | +out_free: | |
f0c0a007 AM |
34471 | + if (o) |
34472 | + au_delayed_kfree(o); | |
c1595e42 JR |
34473 | +out: |
34474 | + if (!unlocked) | |
febd17d6 | 34475 | + inode_unlock(h_isrc); |
c1595e42 JR |
34476 | + AuTraceErr(err); |
34477 | + return err; | |
34478 | +} | |
34479 | + | |
34480 | +/* ---------------------------------------------------------------------- */ | |
34481 | + | |
a2654f78 AM |
34482 | +static int au_smack_reentering(struct super_block *sb) |
34483 | +{ | |
34484 | +#if IS_ENABLED(CONFIG_SECURITY_SMACK) | |
34485 | + /* | |
34486 | + * as a part of lookup, smack_d_instantiate() is called, and it calls | |
34487 | + * i_op->getxattr(). ouch. | |
34488 | + */ | |
34489 | + return si_pid_test(sb); | |
34490 | +#else | |
34491 | + return 0; | |
34492 | +#endif | |
34493 | +} | |
34494 | + | |
c1595e42 JR |
34495 | +enum { |
34496 | + AU_XATTR_LIST, | |
34497 | + AU_XATTR_GET | |
34498 | +}; | |
34499 | + | |
34500 | +struct au_lgxattr { | |
34501 | + int type; | |
34502 | + union { | |
34503 | + struct { | |
34504 | + char *list; | |
34505 | + size_t size; | |
34506 | + } list; | |
34507 | + struct { | |
34508 | + const char *name; | |
34509 | + void *value; | |
34510 | + size_t size; | |
34511 | + } get; | |
34512 | + } u; | |
34513 | +}; | |
34514 | + | |
34515 | +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg) | |
34516 | +{ | |
34517 | + ssize_t err; | |
a2654f78 | 34518 | + int reenter; |
c1595e42 JR |
34519 | + struct path h_path; |
34520 | + struct super_block *sb; | |
34521 | + | |
34522 | + sb = dentry->d_sb; | |
a2654f78 AM |
34523 | + reenter = au_smack_reentering(sb); |
34524 | + if (!reenter) { | |
34525 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
34526 | + if (unlikely(err)) | |
34527 | + goto out; | |
34528 | + } | |
34529 | + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter); | |
c1595e42 JR |
34530 | + if (unlikely(err)) |
34531 | + goto out_si; | |
34532 | + if (unlikely(!h_path.dentry)) | |
34533 | + /* illegally overlapped or something */ | |
34534 | + goto out_di; /* pretending success */ | |
34535 | + | |
34536 | + /* always topmost entry only */ | |
34537 | + switch (arg->type) { | |
34538 | + case AU_XATTR_LIST: | |
34539 | + err = vfs_listxattr(h_path.dentry, | |
34540 | + arg->u.list.list, arg->u.list.size); | |
34541 | + break; | |
34542 | + case AU_XATTR_GET: | |
5afbbe0d | 34543 | + AuDebugOn(d_is_negative(h_path.dentry)); |
c1595e42 JR |
34544 | + err = vfs_getxattr(h_path.dentry, |
34545 | + arg->u.get.name, arg->u.get.value, | |
34546 | + arg->u.get.size); | |
34547 | + break; | |
34548 | + } | |
34549 | + | |
34550 | +out_di: | |
a2654f78 AM |
34551 | + if (!reenter) |
34552 | + di_read_unlock(dentry, AuLock_IR); | |
c1595e42 | 34553 | +out_si: |
a2654f78 AM |
34554 | + if (!reenter) |
34555 | + si_read_unlock(sb); | |
c1595e42 JR |
34556 | +out: |
34557 | + AuTraceErr(err); | |
34558 | + return err; | |
34559 | +} | |
34560 | + | |
34561 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size) | |
34562 | +{ | |
34563 | + struct au_lgxattr arg = { | |
34564 | + .type = AU_XATTR_LIST, | |
34565 | + .u.list = { | |
34566 | + .list = list, | |
34567 | + .size = size | |
34568 | + }, | |
34569 | + }; | |
34570 | + | |
34571 | + return au_lgxattr(dentry, &arg); | |
34572 | +} | |
34573 | + | |
f2c43d5f AM |
34574 | +static ssize_t au_getxattr(struct dentry *dentry, |
34575 | + struct inode *inode __maybe_unused, | |
34576 | + const char *name, void *value, size_t size) | |
c1595e42 JR |
34577 | +{ |
34578 | + struct au_lgxattr arg = { | |
34579 | + .type = AU_XATTR_GET, | |
34580 | + .u.get = { | |
34581 | + .name = name, | |
34582 | + .value = value, | |
34583 | + .size = size | |
34584 | + }, | |
34585 | + }; | |
34586 | + | |
34587 | + return au_lgxattr(dentry, &arg); | |
34588 | +} | |
34589 | + | |
f2c43d5f AM |
34590 | +static int au_setxattr(struct dentry *dentry, struct inode *inode, |
34591 | + const char *name, const void *value, size_t size, | |
34592 | + int flags) | |
c1595e42 | 34593 | +{ |
f2c43d5f | 34594 | + struct au_sxattr arg = { |
c1595e42 JR |
34595 | + .type = AU_XATTR_SET, |
34596 | + .u.set = { | |
34597 | + .name = name, | |
34598 | + .value = value, | |
34599 | + .size = size, | |
34600 | + .flags = flags | |
34601 | + }, | |
34602 | + }; | |
34603 | + | |
f2c43d5f | 34604 | + return au_sxattr(dentry, inode, &arg); |
c1595e42 JR |
34605 | +} |
34606 | + | |
34607 | +/* ---------------------------------------------------------------------- */ | |
34608 | + | |
f2c43d5f AM |
34609 | +static int au_xattr_get(const struct xattr_handler *handler, |
34610 | + struct dentry *dentry, struct inode *inode, | |
34611 | + const char *name, void *buffer, size_t size) | |
c1595e42 | 34612 | +{ |
f2c43d5f | 34613 | + return au_getxattr(dentry, inode, name, buffer, size); |
c1595e42 JR |
34614 | +} |
34615 | + | |
f2c43d5f AM |
34616 | +static int au_xattr_set(const struct xattr_handler *handler, |
34617 | + struct dentry *dentry, struct inode *inode, | |
34618 | + const char *name, const void *value, size_t size, | |
34619 | + int flags) | |
c1595e42 | 34620 | +{ |
f2c43d5f | 34621 | + return au_setxattr(dentry, inode, name, value, size, flags); |
c1595e42 JR |
34622 | +} |
34623 | + | |
34624 | +static const struct xattr_handler au_xattr_handler = { | |
f2c43d5f AM |
34625 | + .name = "", |
34626 | + .prefix = "", | |
c1595e42 JR |
34627 | + .get = au_xattr_get, |
34628 | + .set = au_xattr_set | |
c1595e42 JR |
34629 | +}; |
34630 | + | |
34631 | +static const struct xattr_handler *au_xattr_handlers[] = { | |
a2654f78 AM |
34632 | +#ifdef CONFIG_FS_POSIX_ACL |
34633 | + &posix_acl_access_xattr_handler, | |
34634 | + &posix_acl_default_xattr_handler, | |
34635 | +#endif | |
34636 | + &au_xattr_handler, /* must be last */ | |
f2c43d5f | 34637 | + NULL |
c1595e42 JR |
34638 | +}; |
34639 | + | |
34640 | +void au_xattr_init(struct super_block *sb) | |
34641 | +{ | |
f2c43d5f | 34642 | + sb->s_xattr = au_xattr_handlers; |
c1595e42 | 34643 | +} |
7f207e10 AM |
34644 | diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c |
34645 | --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 JR |
34646 | +++ linux/fs/aufs/xino.c 2017-05-06 22:16:52.784886929 +0200 |
34647 | @@ -0,0 +1,1415 @@ | |
1facf9fc | 34648 | +/* |
a2654f78 | 34649 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 34650 | + * |
34651 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34652 | + * it under the terms of the GNU General Public License as published by | |
34653 | + * the Free Software Foundation; either version 2 of the License, or | |
34654 | + * (at your option) any later version. | |
dece6358 AM |
34655 | + * |
34656 | + * This program is distributed in the hope that it will be useful, | |
34657 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34658 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34659 | + * GNU General Public License for more details. | |
34660 | + * | |
34661 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 34662 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 34663 | + */ |
34664 | + | |
34665 | +/* | |
34666 | + * external inode number translation table and bitmap | |
34667 | + */ | |
34668 | + | |
34669 | +#include <linux/seq_file.h> | |
392086de | 34670 | +#include <linux/statfs.h> |
1facf9fc | 34671 | +#include "aufs.h" |
34672 | + | |
9dbd164d | 34673 | +/* todo: unnecessary to support mmap_sem since kernel-space? */ |
5527c038 | 34674 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size, |
1facf9fc | 34675 | + loff_t *pos) |
34676 | +{ | |
34677 | + ssize_t err; | |
34678 | + mm_segment_t oldfs; | |
b752ccd1 AM |
34679 | + union { |
34680 | + void *k; | |
34681 | + char __user *u; | |
34682 | + } buf; | |
1facf9fc | 34683 | + |
b752ccd1 | 34684 | + buf.k = kbuf; |
1facf9fc | 34685 | + oldfs = get_fs(); |
34686 | + set_fs(KERNEL_DS); | |
34687 | + do { | |
34688 | + /* todo: signal_pending? */ | |
b752ccd1 | 34689 | + err = func(file, buf.u, size, pos); |
1facf9fc | 34690 | + } while (err == -EAGAIN || err == -EINTR); |
34691 | + set_fs(oldfs); | |
34692 | + | |
34693 | +#if 0 /* reserved for future use */ | |
34694 | + if (err > 0) | |
2000de60 | 34695 | + fsnotify_access(file->f_path.dentry); |
1facf9fc | 34696 | +#endif |
34697 | + | |
34698 | + return err; | |
34699 | +} | |
34700 | + | |
34701 | +/* ---------------------------------------------------------------------- */ | |
34702 | + | |
be52b249 AM |
34703 | +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf, |
34704 | + size_t size, loff_t *pos); | |
34705 | + | |
5527c038 | 34706 | +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf, |
1facf9fc | 34707 | + size_t size, loff_t *pos) |
34708 | +{ | |
34709 | + ssize_t err; | |
34710 | + mm_segment_t oldfs; | |
b752ccd1 AM |
34711 | + union { |
34712 | + void *k; | |
34713 | + const char __user *u; | |
34714 | + } buf; | |
be52b249 AM |
34715 | + int i; |
34716 | + const int prevent_endless = 10; | |
1facf9fc | 34717 | + |
be52b249 | 34718 | + i = 0; |
b752ccd1 | 34719 | + buf.k = kbuf; |
1facf9fc | 34720 | + oldfs = get_fs(); |
34721 | + set_fs(KERNEL_DS); | |
1facf9fc | 34722 | + do { |
b752ccd1 | 34723 | + err = func(file, buf.u, size, pos); |
be52b249 AM |
34724 | + if (err == -EINTR |
34725 | + && !au_wkq_test() | |
34726 | + && fatal_signal_pending(current)) { | |
34727 | + set_fs(oldfs); | |
34728 | + err = xino_fwrite_wkq(func, file, kbuf, size, pos); | |
34729 | + BUG_ON(err == -EINTR); | |
34730 | + oldfs = get_fs(); | |
34731 | + set_fs(KERNEL_DS); | |
34732 | + } | |
34733 | + } while (i++ < prevent_endless | |
34734 | + && (err == -EAGAIN || err == -EINTR)); | |
1facf9fc | 34735 | + set_fs(oldfs); |
34736 | + | |
34737 | +#if 0 /* reserved for future use */ | |
34738 | + if (err > 0) | |
2000de60 | 34739 | + fsnotify_modify(file->f_path.dentry); |
1facf9fc | 34740 | +#endif |
34741 | + | |
34742 | + return err; | |
34743 | +} | |
34744 | + | |
34745 | +struct do_xino_fwrite_args { | |
34746 | + ssize_t *errp; | |
5527c038 | 34747 | + vfs_writef_t func; |
1facf9fc | 34748 | + struct file *file; |
34749 | + void *buf; | |
34750 | + size_t size; | |
34751 | + loff_t *pos; | |
34752 | +}; | |
34753 | + | |
34754 | +static void call_do_xino_fwrite(void *args) | |
34755 | +{ | |
34756 | + struct do_xino_fwrite_args *a = args; | |
34757 | + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos); | |
34758 | +} | |
34759 | + | |
be52b249 AM |
34760 | +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf, |
34761 | + size_t size, loff_t *pos) | |
34762 | +{ | |
34763 | + ssize_t err; | |
34764 | + int wkq_err; | |
34765 | + struct do_xino_fwrite_args args = { | |
34766 | + .errp = &err, | |
34767 | + .func = func, | |
34768 | + .file = file, | |
34769 | + .buf = buf, | |
34770 | + .size = size, | |
34771 | + .pos = pos | |
34772 | + }; | |
34773 | + | |
34774 | + /* | |
34775 | + * it breaks RLIMIT_FSIZE and normal user's limit, | |
34776 | + * users should care about quota and real 'filesystem full.' | |
34777 | + */ | |
34778 | + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args); | |
34779 | + if (unlikely(wkq_err)) | |
34780 | + err = wkq_err; | |
34781 | + | |
34782 | + return err; | |
34783 | +} | |
34784 | + | |
5527c038 JR |
34785 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
34786 | + size_t size, loff_t *pos) | |
1facf9fc | 34787 | +{ |
34788 | + ssize_t err; | |
34789 | + | |
b752ccd1 AM |
34790 | + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) { |
34791 | + lockdep_off(); | |
34792 | + err = do_xino_fwrite(func, file, buf, size, pos); | |
34793 | + lockdep_on(); | |
be52b249 AM |
34794 | + } else |
34795 | + err = xino_fwrite_wkq(func, file, buf, size, pos); | |
1facf9fc | 34796 | + |
34797 | + return err; | |
34798 | +} | |
34799 | + | |
34800 | +/* ---------------------------------------------------------------------- */ | |
34801 | + | |
34802 | +/* | |
34803 | + * create a new xinofile at the same place/path as @base_file. | |
34804 | + */ | |
34805 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src) | |
34806 | +{ | |
34807 | + struct file *file; | |
4a4d8108 | 34808 | + struct dentry *base, *parent; |
523b37e3 | 34809 | + struct inode *dir, *delegated; |
1facf9fc | 34810 | + struct qstr *name; |
1308ab2a | 34811 | + struct path path; |
4a4d8108 | 34812 | + int err; |
1facf9fc | 34813 | + |
2000de60 | 34814 | + base = base_file->f_path.dentry; |
1facf9fc | 34815 | + parent = base->d_parent; /* dir inode is locked */ |
5527c038 | 34816 | + dir = d_inode(parent); |
1facf9fc | 34817 | + IMustLock(dir); |
34818 | + | |
34819 | + file = ERR_PTR(-EINVAL); | |
34820 | + name = &base->d_name; | |
4a4d8108 AM |
34821 | + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len); |
34822 | + if (IS_ERR(path.dentry)) { | |
34823 | + file = (void *)path.dentry; | |
523b37e3 AM |
34824 | + pr_err("%pd lookup err %ld\n", |
34825 | + base, PTR_ERR(path.dentry)); | |
1facf9fc | 34826 | + goto out; |
34827 | + } | |
34828 | + | |
34829 | + /* no need to mnt_want_write() since we call dentry_open() later */ | |
4a4d8108 | 34830 | + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL); |
1facf9fc | 34831 | + if (unlikely(err)) { |
34832 | + file = ERR_PTR(err); | |
523b37e3 | 34833 | + pr_err("%pd create err %d\n", base, err); |
1facf9fc | 34834 | + goto out_dput; |
34835 | + } | |
34836 | + | |
c06a8ce3 | 34837 | + path.mnt = base_file->f_path.mnt; |
4a4d8108 | 34838 | + file = vfsub_dentry_open(&path, |
7f207e10 | 34839 | + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 34840 | + /* | __FMODE_NONOTIFY */); |
1facf9fc | 34841 | + if (IS_ERR(file)) { |
523b37e3 | 34842 | + pr_err("%pd open err %ld\n", base, PTR_ERR(file)); |
1facf9fc | 34843 | + goto out_dput; |
34844 | + } | |
34845 | + | |
523b37e3 AM |
34846 | + delegated = NULL; |
34847 | + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0); | |
34848 | + if (unlikely(err == -EWOULDBLOCK)) { | |
34849 | + pr_warn("cannot retry for NFSv4 delegation" | |
34850 | + " for an internal unlink\n"); | |
34851 | + iput(delegated); | |
34852 | + } | |
1facf9fc | 34853 | + if (unlikely(err)) { |
523b37e3 | 34854 | + pr_err("%pd unlink err %d\n", base, err); |
1facf9fc | 34855 | + goto out_fput; |
34856 | + } | |
34857 | + | |
34858 | + if (copy_src) { | |
34859 | + /* no one can touch copy_src xino */ | |
c06a8ce3 | 34860 | + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src)); |
1facf9fc | 34861 | + if (unlikely(err)) { |
523b37e3 | 34862 | + pr_err("%pd copy err %d\n", base, err); |
1facf9fc | 34863 | + goto out_fput; |
34864 | + } | |
34865 | + } | |
34866 | + goto out_dput; /* success */ | |
34867 | + | |
4f0767ce | 34868 | +out_fput: |
1facf9fc | 34869 | + fput(file); |
34870 | + file = ERR_PTR(err); | |
4f0767ce | 34871 | +out_dput: |
4a4d8108 | 34872 | + dput(path.dentry); |
4f0767ce | 34873 | +out: |
1facf9fc | 34874 | + return file; |
34875 | +} | |
34876 | + | |
34877 | +struct au_xino_lock_dir { | |
34878 | + struct au_hinode *hdir; | |
34879 | + struct dentry *parent; | |
febd17d6 | 34880 | + struct inode *dir; |
1facf9fc | 34881 | +}; |
34882 | + | |
34883 | +static void au_xino_lock_dir(struct super_block *sb, struct file *xino, | |
34884 | + struct au_xino_lock_dir *ldir) | |
34885 | +{ | |
34886 | + aufs_bindex_t brid, bindex; | |
34887 | + | |
34888 | + ldir->hdir = NULL; | |
34889 | + bindex = -1; | |
34890 | + brid = au_xino_brid(sb); | |
34891 | + if (brid >= 0) | |
34892 | + bindex = au_br_index(sb, brid); | |
34893 | + if (bindex >= 0) { | |
5527c038 | 34894 | + ldir->hdir = au_hi(d_inode(sb->s_root), bindex); |
5afbbe0d | 34895 | + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT); |
1facf9fc | 34896 | + } else { |
2000de60 | 34897 | + ldir->parent = dget_parent(xino->f_path.dentry); |
febd17d6 JR |
34898 | + ldir->dir = d_inode(ldir->parent); |
34899 | + inode_lock_nested(ldir->dir, AuLsc_I_PARENT); | |
1facf9fc | 34900 | + } |
34901 | +} | |
34902 | + | |
34903 | +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir) | |
34904 | +{ | |
34905 | + if (ldir->hdir) | |
5afbbe0d | 34906 | + au_hn_inode_unlock(ldir->hdir); |
1facf9fc | 34907 | + else { |
febd17d6 | 34908 | + inode_unlock(ldir->dir); |
1facf9fc | 34909 | + dput(ldir->parent); |
34910 | + } | |
34911 | +} | |
34912 | + | |
34913 | +/* ---------------------------------------------------------------------- */ | |
34914 | + | |
34915 | +/* trucate xino files asynchronously */ | |
34916 | + | |
34917 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex) | |
34918 | +{ | |
34919 | + int err; | |
392086de AM |
34920 | + unsigned long jiffy; |
34921 | + blkcnt_t blocks; | |
5afbbe0d | 34922 | + aufs_bindex_t bi, bbot; |
392086de | 34923 | + struct kstatfs *st; |
1facf9fc | 34924 | + struct au_branch *br; |
34925 | + struct file *new_xino, *file; | |
34926 | + struct super_block *h_sb; | |
34927 | + struct au_xino_lock_dir ldir; | |
34928 | + | |
392086de | 34929 | + err = -ENOMEM; |
be52b249 | 34930 | + st = kmalloc(sizeof(*st), GFP_NOFS); |
392086de AM |
34931 | + if (unlikely(!st)) |
34932 | + goto out; | |
34933 | + | |
1facf9fc | 34934 | + err = -EINVAL; |
5afbbe0d AM |
34935 | + bbot = au_sbbot(sb); |
34936 | + if (unlikely(bindex < 0 || bbot < bindex)) | |
392086de | 34937 | + goto out_st; |
1facf9fc | 34938 | + br = au_sbr(sb, bindex); |
34939 | + file = br->br_xino.xi_file; | |
34940 | + if (!file) | |
392086de AM |
34941 | + goto out_st; |
34942 | + | |
34943 | + err = vfs_statfs(&file->f_path, st); | |
34944 | + if (unlikely(err)) | |
34945 | + AuErr1("statfs err %d, ignored\n", err); | |
34946 | + jiffy = jiffies; | |
34947 | + blocks = file_inode(file)->i_blocks; | |
34948 | + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
34949 | + bindex, (u64)blocks, st->f_bfree, st->f_blocks); | |
1facf9fc | 34950 | + |
34951 | + au_xino_lock_dir(sb, file, &ldir); | |
34952 | + /* mnt_want_write() is unnecessary here */ | |
34953 | + new_xino = au_xino_create2(file, file); | |
34954 | + au_xino_unlock_dir(&ldir); | |
34955 | + err = PTR_ERR(new_xino); | |
392086de AM |
34956 | + if (IS_ERR(new_xino)) { |
34957 | + pr_err("err %d, ignored\n", err); | |
34958 | + goto out_st; | |
34959 | + } | |
1facf9fc | 34960 | + err = 0; |
34961 | + fput(file); | |
34962 | + br->br_xino.xi_file = new_xino; | |
34963 | + | |
86dc4139 | 34964 | + h_sb = au_br_sb(br); |
5afbbe0d | 34965 | + for (bi = 0; bi <= bbot; bi++) { |
1facf9fc | 34966 | + if (unlikely(bi == bindex)) |
34967 | + continue; | |
34968 | + br = au_sbr(sb, bi); | |
86dc4139 | 34969 | + if (au_br_sb(br) != h_sb) |
1facf9fc | 34970 | + continue; |
34971 | + | |
34972 | + fput(br->br_xino.xi_file); | |
34973 | + br->br_xino.xi_file = new_xino; | |
34974 | + get_file(new_xino); | |
34975 | + } | |
34976 | + | |
392086de AM |
34977 | + err = vfs_statfs(&new_xino->f_path, st); |
34978 | + if (!err) { | |
34979 | + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
34980 | + bindex, (u64)file_inode(new_xino)->i_blocks, | |
34981 | + st->f_bfree, st->f_blocks); | |
34982 | + if (file_inode(new_xino)->i_blocks < blocks) | |
34983 | + au_sbi(sb)->si_xino_jiffy = jiffy; | |
34984 | + } else | |
34985 | + AuErr1("statfs err %d, ignored\n", err); | |
34986 | + | |
34987 | +out_st: | |
f0c0a007 | 34988 | + au_delayed_kfree(st); |
4f0767ce | 34989 | +out: |
1facf9fc | 34990 | + return err; |
34991 | +} | |
34992 | + | |
34993 | +struct xino_do_trunc_args { | |
34994 | + struct super_block *sb; | |
34995 | + struct au_branch *br; | |
34996 | +}; | |
34997 | + | |
34998 | +static void xino_do_trunc(void *_args) | |
34999 | +{ | |
35000 | + struct xino_do_trunc_args *args = _args; | |
35001 | + struct super_block *sb; | |
35002 | + struct au_branch *br; | |
35003 | + struct inode *dir; | |
35004 | + int err; | |
35005 | + aufs_bindex_t bindex; | |
35006 | + | |
35007 | + err = 0; | |
35008 | + sb = args->sb; | |
5527c038 | 35009 | + dir = d_inode(sb->s_root); |
1facf9fc | 35010 | + br = args->br; |
35011 | + | |
35012 | + si_noflush_write_lock(sb); | |
35013 | + ii_read_lock_parent(dir); | |
35014 | + bindex = au_br_index(sb, br->br_id); | |
35015 | + err = au_xino_trunc(sb, bindex); | |
1facf9fc | 35016 | + ii_read_unlock(dir); |
35017 | + if (unlikely(err)) | |
392086de | 35018 | + pr_warn("err b%d, (%d)\n", bindex, err); |
1facf9fc | 35019 | + atomic_dec(&br->br_xino_running); |
5afbbe0d | 35020 | + au_br_put(br); |
1facf9fc | 35021 | + si_write_unlock(sb); |
027c5e7a | 35022 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
f0c0a007 | 35023 | + au_delayed_kfree(args); |
1facf9fc | 35024 | +} |
35025 | + | |
392086de AM |
35026 | +static int xino_trunc_test(struct super_block *sb, struct au_branch *br) |
35027 | +{ | |
35028 | + int err; | |
35029 | + struct kstatfs st; | |
35030 | + struct au_sbinfo *sbinfo; | |
35031 | + | |
35032 | + /* todo: si_xino_expire and the ratio should be customizable */ | |
35033 | + sbinfo = au_sbi(sb); | |
35034 | + if (time_before(jiffies, | |
35035 | + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire)) | |
35036 | + return 0; | |
35037 | + | |
35038 | + /* truncation border */ | |
35039 | + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st); | |
35040 | + if (unlikely(err)) { | |
35041 | + AuErr1("statfs err %d, ignored\n", err); | |
35042 | + return 0; | |
35043 | + } | |
35044 | + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC) | |
35045 | + return 0; | |
35046 | + | |
35047 | + return 1; | |
35048 | +} | |
35049 | + | |
1facf9fc | 35050 | +static void xino_try_trunc(struct super_block *sb, struct au_branch *br) |
35051 | +{ | |
35052 | + struct xino_do_trunc_args *args; | |
35053 | + int wkq_err; | |
35054 | + | |
392086de | 35055 | + if (!xino_trunc_test(sb, br)) |
1facf9fc | 35056 | + return; |
35057 | + | |
35058 | + if (atomic_inc_return(&br->br_xino_running) > 1) | |
35059 | + goto out; | |
35060 | + | |
35061 | + /* lock and kfree() will be called in trunc_xino() */ | |
35062 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
35063 | + if (unlikely(!args)) { | |
35064 | + AuErr1("no memory\n"); | |
f0c0a007 | 35065 | + goto out; |
1facf9fc | 35066 | + } |
35067 | + | |
5afbbe0d | 35068 | + au_br_get(br); |
1facf9fc | 35069 | + args->sb = sb; |
35070 | + args->br = br; | |
53392da6 | 35071 | + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0); |
1facf9fc | 35072 | + if (!wkq_err) |
35073 | + return; /* success */ | |
35074 | + | |
4a4d8108 | 35075 | + pr_err("wkq %d\n", wkq_err); |
5afbbe0d | 35076 | + au_br_put(br); |
f0c0a007 | 35077 | + au_delayed_kfree(args); |
1facf9fc | 35078 | + |
4f0767ce | 35079 | +out: |
e49829fe | 35080 | + atomic_dec(&br->br_xino_running); |
1facf9fc | 35081 | +} |
35082 | + | |
35083 | +/* ---------------------------------------------------------------------- */ | |
35084 | + | |
5527c038 | 35085 | +static int au_xino_do_write(vfs_writef_t write, struct file *file, |
1facf9fc | 35086 | + ino_t h_ino, ino_t ino) |
35087 | +{ | |
35088 | + loff_t pos; | |
35089 | + ssize_t sz; | |
35090 | + | |
35091 | + pos = h_ino; | |
35092 | + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) { | |
35093 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
35094 | + return -EFBIG; | |
35095 | + } | |
35096 | + pos *= sizeof(ino); | |
35097 | + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos); | |
35098 | + if (sz == sizeof(ino)) | |
35099 | + return 0; /* success */ | |
35100 | + | |
35101 | + AuIOErr("write failed (%zd)\n", sz); | |
35102 | + return -EIO; | |
35103 | +} | |
35104 | + | |
35105 | +/* | |
35106 | + * write @ino to the xinofile for the specified branch{@sb, @bindex} | |
35107 | + * at the position of @h_ino. | |
35108 | + * even if @ino is zero, it is written to the xinofile and means no entry. | |
35109 | + * if the size of the xino file on a specific filesystem exceeds the watermark, | |
35110 | + * try truncating it. | |
35111 | + */ | |
35112 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
35113 | + ino_t ino) | |
35114 | +{ | |
35115 | + int err; | |
35116 | + unsigned int mnt_flags; | |
35117 | + struct au_branch *br; | |
35118 | + | |
35119 | + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max) | |
35120 | + || ((loff_t)-1) > 0); | |
dece6358 | 35121 | + SiMustAnyLock(sb); |
1facf9fc | 35122 | + |
35123 | + mnt_flags = au_mntflags(sb); | |
35124 | + if (!au_opt_test(mnt_flags, XINO)) | |
35125 | + return 0; | |
35126 | + | |
35127 | + br = au_sbr(sb, bindex); | |
35128 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
35129 | + h_ino, ino); | |
35130 | + if (!err) { | |
35131 | + if (au_opt_test(mnt_flags, TRUNC_XINO) | |
86dc4139 | 35132 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
1facf9fc | 35133 | + xino_try_trunc(sb, br); |
35134 | + return 0; /* success */ | |
35135 | + } | |
35136 | + | |
35137 | + AuIOErr("write failed (%d)\n", err); | |
35138 | + return -EIO; | |
35139 | +} | |
35140 | + | |
35141 | +/* ---------------------------------------------------------------------- */ | |
35142 | + | |
35143 | +/* aufs inode number bitmap */ | |
35144 | + | |
35145 | +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE; | |
35146 | +static ino_t xib_calc_ino(unsigned long pindex, int bit) | |
35147 | +{ | |
35148 | + ino_t ino; | |
35149 | + | |
35150 | + AuDebugOn(bit < 0 || page_bits <= bit); | |
35151 | + ino = AUFS_FIRST_INO + pindex * page_bits + bit; | |
35152 | + return ino; | |
35153 | +} | |
35154 | + | |
35155 | +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit) | |
35156 | +{ | |
35157 | + AuDebugOn(ino < AUFS_FIRST_INO); | |
35158 | + ino -= AUFS_FIRST_INO; | |
35159 | + *pindex = ino / page_bits; | |
35160 | + *bit = ino % page_bits; | |
35161 | +} | |
35162 | + | |
35163 | +static int xib_pindex(struct super_block *sb, unsigned long pindex) | |
35164 | +{ | |
35165 | + int err; | |
35166 | + loff_t pos; | |
35167 | + ssize_t sz; | |
35168 | + struct au_sbinfo *sbinfo; | |
35169 | + struct file *xib; | |
35170 | + unsigned long *p; | |
35171 | + | |
35172 | + sbinfo = au_sbi(sb); | |
35173 | + MtxMustLock(&sbinfo->si_xib_mtx); | |
35174 | + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE | |
35175 | + || !au_opt_test(sbinfo->si_mntflags, XINO)); | |
35176 | + | |
35177 | + if (pindex == sbinfo->si_xib_last_pindex) | |
35178 | + return 0; | |
35179 | + | |
35180 | + xib = sbinfo->si_xib; | |
35181 | + p = sbinfo->si_xib_buf; | |
35182 | + pos = sbinfo->si_xib_last_pindex; | |
35183 | + pos *= PAGE_SIZE; | |
35184 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
35185 | + if (unlikely(sz != PAGE_SIZE)) | |
35186 | + goto out; | |
35187 | + | |
35188 | + pos = pindex; | |
35189 | + pos *= PAGE_SIZE; | |
c06a8ce3 | 35190 | + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE) |
1facf9fc | 35191 | + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos); |
35192 | + else { | |
35193 | + memset(p, 0, PAGE_SIZE); | |
35194 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
35195 | + } | |
35196 | + if (sz == PAGE_SIZE) { | |
35197 | + sbinfo->si_xib_last_pindex = pindex; | |
35198 | + return 0; /* success */ | |
35199 | + } | |
35200 | + | |
4f0767ce | 35201 | +out: |
b752ccd1 AM |
35202 | + AuIOErr1("write failed (%zd)\n", sz); |
35203 | + err = sz; | |
35204 | + if (sz >= 0) | |
35205 | + err = -EIO; | |
35206 | + return err; | |
35207 | +} | |
35208 | + | |
35209 | +/* ---------------------------------------------------------------------- */ | |
35210 | + | |
35211 | +static void au_xib_clear_bit(struct inode *inode) | |
35212 | +{ | |
35213 | + int err, bit; | |
35214 | + unsigned long pindex; | |
35215 | + struct super_block *sb; | |
35216 | + struct au_sbinfo *sbinfo; | |
35217 | + | |
35218 | + AuDebugOn(inode->i_nlink); | |
35219 | + | |
35220 | + sb = inode->i_sb; | |
35221 | + xib_calc_bit(inode->i_ino, &pindex, &bit); | |
35222 | + AuDebugOn(page_bits <= bit); | |
35223 | + sbinfo = au_sbi(sb); | |
35224 | + mutex_lock(&sbinfo->si_xib_mtx); | |
35225 | + err = xib_pindex(sb, pindex); | |
35226 | + if (!err) { | |
35227 | + clear_bit(bit, sbinfo->si_xib_buf); | |
35228 | + sbinfo->si_xib_next_bit = bit; | |
35229 | + } | |
35230 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
35231 | +} | |
35232 | + | |
35233 | +/* for s_op->delete_inode() */ | |
35234 | +void au_xino_delete_inode(struct inode *inode, const int unlinked) | |
35235 | +{ | |
35236 | + int err; | |
35237 | + unsigned int mnt_flags; | |
5afbbe0d | 35238 | + aufs_bindex_t bindex, bbot, bi; |
b752ccd1 AM |
35239 | + unsigned char try_trunc; |
35240 | + struct au_iinfo *iinfo; | |
35241 | + struct super_block *sb; | |
35242 | + struct au_hinode *hi; | |
35243 | + struct inode *h_inode; | |
35244 | + struct au_branch *br; | |
5527c038 | 35245 | + vfs_writef_t xwrite; |
b752ccd1 | 35246 | + |
5afbbe0d AM |
35247 | + AuDebugOn(au_is_bad_inode(inode)); |
35248 | + | |
b752ccd1 AM |
35249 | + sb = inode->i_sb; |
35250 | + mnt_flags = au_mntflags(sb); | |
35251 | + if (!au_opt_test(mnt_flags, XINO) | |
35252 | + || inode->i_ino == AUFS_ROOT_INO) | |
35253 | + return; | |
35254 | + | |
35255 | + if (unlinked) { | |
35256 | + au_xigen_inc(inode); | |
35257 | + au_xib_clear_bit(inode); | |
35258 | + } | |
35259 | + | |
35260 | + iinfo = au_ii(inode); | |
5afbbe0d | 35261 | + bindex = iinfo->ii_btop; |
b752ccd1 AM |
35262 | + if (bindex < 0) |
35263 | + return; | |
1facf9fc | 35264 | + |
b752ccd1 AM |
35265 | + xwrite = au_sbi(sb)->si_xwrite; |
35266 | + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO); | |
5afbbe0d AM |
35267 | + hi = au_hinode(iinfo, bindex); |
35268 | + bbot = iinfo->ii_bbot; | |
35269 | + for (; bindex <= bbot; bindex++, hi++) { | |
b752ccd1 AM |
35270 | + h_inode = hi->hi_inode; |
35271 | + if (!h_inode | |
35272 | + || (!unlinked && h_inode->i_nlink)) | |
35273 | + continue; | |
1facf9fc | 35274 | + |
b752ccd1 AM |
35275 | + /* inode may not be revalidated */ |
35276 | + bi = au_br_index(sb, hi->hi_id); | |
35277 | + if (bi < 0) | |
35278 | + continue; | |
1facf9fc | 35279 | + |
b752ccd1 AM |
35280 | + br = au_sbr(sb, bi); |
35281 | + err = au_xino_do_write(xwrite, br->br_xino.xi_file, | |
35282 | + h_inode->i_ino, /*ino*/0); | |
35283 | + if (!err && try_trunc | |
86dc4139 | 35284 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
b752ccd1 | 35285 | + xino_try_trunc(sb, br); |
1facf9fc | 35286 | + } |
1facf9fc | 35287 | +} |
35288 | + | |
35289 | +/* get an unused inode number from bitmap */ | |
35290 | +ino_t au_xino_new_ino(struct super_block *sb) | |
35291 | +{ | |
35292 | + ino_t ino; | |
35293 | + unsigned long *p, pindex, ul, pend; | |
35294 | + struct au_sbinfo *sbinfo; | |
35295 | + struct file *file; | |
35296 | + int free_bit, err; | |
35297 | + | |
35298 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
35299 | + return iunique(sb, AUFS_FIRST_INO); | |
35300 | + | |
35301 | + sbinfo = au_sbi(sb); | |
35302 | + mutex_lock(&sbinfo->si_xib_mtx); | |
35303 | + p = sbinfo->si_xib_buf; | |
35304 | + free_bit = sbinfo->si_xib_next_bit; | |
35305 | + if (free_bit < page_bits && !test_bit(free_bit, p)) | |
35306 | + goto out; /* success */ | |
35307 | + free_bit = find_first_zero_bit(p, page_bits); | |
35308 | + if (free_bit < page_bits) | |
35309 | + goto out; /* success */ | |
35310 | + | |
35311 | + pindex = sbinfo->si_xib_last_pindex; | |
35312 | + for (ul = pindex - 1; ul < ULONG_MAX; ul--) { | |
35313 | + err = xib_pindex(sb, ul); | |
35314 | + if (unlikely(err)) | |
35315 | + goto out_err; | |
35316 | + free_bit = find_first_zero_bit(p, page_bits); | |
35317 | + if (free_bit < page_bits) | |
35318 | + goto out; /* success */ | |
35319 | + } | |
35320 | + | |
35321 | + file = sbinfo->si_xib; | |
c06a8ce3 | 35322 | + pend = vfsub_f_size_read(file) / PAGE_SIZE; |
1facf9fc | 35323 | + for (ul = pindex + 1; ul <= pend; ul++) { |
35324 | + err = xib_pindex(sb, ul); | |
35325 | + if (unlikely(err)) | |
35326 | + goto out_err; | |
35327 | + free_bit = find_first_zero_bit(p, page_bits); | |
35328 | + if (free_bit < page_bits) | |
35329 | + goto out; /* success */ | |
35330 | + } | |
35331 | + BUG(); | |
35332 | + | |
4f0767ce | 35333 | +out: |
1facf9fc | 35334 | + set_bit(free_bit, p); |
7f207e10 | 35335 | + sbinfo->si_xib_next_bit = free_bit + 1; |
1facf9fc | 35336 | + pindex = sbinfo->si_xib_last_pindex; |
35337 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
35338 | + ino = xib_calc_ino(pindex, free_bit); | |
35339 | + AuDbg("i%lu\n", (unsigned long)ino); | |
35340 | + return ino; | |
4f0767ce | 35341 | +out_err: |
1facf9fc | 35342 | + mutex_unlock(&sbinfo->si_xib_mtx); |
35343 | + AuDbg("i0\n"); | |
35344 | + return 0; | |
35345 | +} | |
35346 | + | |
35347 | +/* | |
35348 | + * read @ino from xinofile for the specified branch{@sb, @bindex} | |
35349 | + * at the position of @h_ino. | |
35350 | + * if @ino does not exist and @do_new is true, get new one. | |
35351 | + */ | |
35352 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
35353 | + ino_t *ino) | |
35354 | +{ | |
35355 | + int err; | |
35356 | + ssize_t sz; | |
35357 | + loff_t pos; | |
35358 | + struct file *file; | |
35359 | + struct au_sbinfo *sbinfo; | |
35360 | + | |
35361 | + *ino = 0; | |
35362 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
35363 | + return 0; /* no xino */ | |
35364 | + | |
35365 | + err = 0; | |
35366 | + sbinfo = au_sbi(sb); | |
35367 | + pos = h_ino; | |
35368 | + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) { | |
35369 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
35370 | + return -EFBIG; | |
35371 | + } | |
35372 | + pos *= sizeof(*ino); | |
35373 | + | |
35374 | + file = au_sbr(sb, bindex)->br_xino.xi_file; | |
c06a8ce3 | 35375 | + if (vfsub_f_size_read(file) < pos + sizeof(*ino)) |
1facf9fc | 35376 | + return 0; /* no ino */ |
35377 | + | |
35378 | + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos); | |
35379 | + if (sz == sizeof(*ino)) | |
35380 | + return 0; /* success */ | |
35381 | + | |
35382 | + err = sz; | |
35383 | + if (unlikely(sz >= 0)) { | |
35384 | + err = -EIO; | |
35385 | + AuIOErr("xino read error (%zd)\n", sz); | |
35386 | + } | |
35387 | + | |
35388 | + return err; | |
35389 | +} | |
35390 | + | |
35391 | +/* ---------------------------------------------------------------------- */ | |
35392 | + | |
35393 | +/* create and set a new xino file */ | |
35394 | + | |
35395 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent) | |
35396 | +{ | |
35397 | + struct file *file; | |
35398 | + struct dentry *h_parent, *d; | |
b912730e | 35399 | + struct inode *h_dir, *inode; |
1facf9fc | 35400 | + int err; |
35401 | + | |
35402 | + /* | |
35403 | + * at mount-time, and the xino file is the default path, | |
4a4d8108 | 35404 | + * hnotify is disabled so we have no notify events to ignore. |
1facf9fc | 35405 | + * when a user specified the xino, we cannot get au_hdir to be ignored. |
35406 | + */ | |
7f207e10 | 35407 | + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 35408 | + /* | __FMODE_NONOTIFY */, |
1facf9fc | 35409 | + S_IRUGO | S_IWUGO); |
35410 | + if (IS_ERR(file)) { | |
35411 | + if (!silent) | |
4a4d8108 | 35412 | + pr_err("open %s(%ld)\n", fname, PTR_ERR(file)); |
1facf9fc | 35413 | + return file; |
35414 | + } | |
35415 | + | |
35416 | + /* keep file count */ | |
b912730e AM |
35417 | + err = 0; |
35418 | + inode = file_inode(file); | |
2000de60 | 35419 | + h_parent = dget_parent(file->f_path.dentry); |
5527c038 | 35420 | + h_dir = d_inode(h_parent); |
febd17d6 | 35421 | + inode_lock_nested(h_dir, AuLsc_I_PARENT); |
1facf9fc | 35422 | + /* mnt_want_write() is unnecessary here */ |
523b37e3 | 35423 | + /* no delegation since it is just created */ |
b912730e AM |
35424 | + if (inode->i_nlink) |
35425 | + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, | |
35426 | + /*force*/0); | |
febd17d6 | 35427 | + inode_unlock(h_dir); |
1facf9fc | 35428 | + dput(h_parent); |
35429 | + if (unlikely(err)) { | |
35430 | + if (!silent) | |
4a4d8108 | 35431 | + pr_err("unlink %s(%d)\n", fname, err); |
1facf9fc | 35432 | + goto out; |
35433 | + } | |
35434 | + | |
35435 | + err = -EINVAL; | |
2000de60 | 35436 | + d = file->f_path.dentry; |
1facf9fc | 35437 | + if (unlikely(sb == d->d_sb)) { |
35438 | + if (!silent) | |
4a4d8108 | 35439 | + pr_err("%s must be outside\n", fname); |
1facf9fc | 35440 | + goto out; |
35441 | + } | |
35442 | + if (unlikely(au_test_fs_bad_xino(d->d_sb))) { | |
35443 | + if (!silent) | |
4a4d8108 AM |
35444 | + pr_err("xino doesn't support %s(%s)\n", |
35445 | + fname, au_sbtype(d->d_sb)); | |
1facf9fc | 35446 | + goto out; |
35447 | + } | |
35448 | + return file; /* success */ | |
35449 | + | |
4f0767ce | 35450 | +out: |
1facf9fc | 35451 | + fput(file); |
35452 | + file = ERR_PTR(err); | |
35453 | + return file; | |
35454 | +} | |
35455 | + | |
35456 | +/* | |
35457 | + * find another branch who is on the same filesystem of the specified | |
5afbbe0d | 35458 | + * branch{@btgt}. search until @bbot. |
1facf9fc | 35459 | + */ |
35460 | +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt, | |
5afbbe0d | 35461 | + aufs_bindex_t bbot) |
1facf9fc | 35462 | +{ |
35463 | + aufs_bindex_t bindex; | |
35464 | + struct super_block *tgt_sb = au_sbr_sb(sb, btgt); | |
35465 | + | |
35466 | + for (bindex = 0; bindex < btgt; bindex++) | |
35467 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
35468 | + return bindex; | |
5afbbe0d | 35469 | + for (bindex++; bindex <= bbot; bindex++) |
1facf9fc | 35470 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) |
35471 | + return bindex; | |
35472 | + return -1; | |
35473 | +} | |
35474 | + | |
35475 | +/* ---------------------------------------------------------------------- */ | |
35476 | + | |
35477 | +/* | |
35478 | + * initialize the xinofile for the specified branch @br | |
35479 | + * at the place/path where @base_file indicates. | |
35480 | + * test whether another branch is on the same filesystem or not, | |
35481 | + * if @do_test is true. | |
35482 | + */ | |
35483 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino, | |
35484 | + struct file *base_file, int do_test) | |
35485 | +{ | |
35486 | + int err; | |
35487 | + ino_t ino; | |
5afbbe0d | 35488 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 35489 | + struct au_branch *shared_br, *b; |
35490 | + struct file *file; | |
35491 | + struct super_block *tgt_sb; | |
35492 | + | |
35493 | + shared_br = NULL; | |
5afbbe0d | 35494 | + bbot = au_sbbot(sb); |
1facf9fc | 35495 | + if (do_test) { |
86dc4139 | 35496 | + tgt_sb = au_br_sb(br); |
5afbbe0d | 35497 | + for (bindex = 0; bindex <= bbot; bindex++) { |
1facf9fc | 35498 | + b = au_sbr(sb, bindex); |
86dc4139 | 35499 | + if (tgt_sb == au_br_sb(b)) { |
1facf9fc | 35500 | + shared_br = b; |
35501 | + break; | |
35502 | + } | |
35503 | + } | |
35504 | + } | |
35505 | + | |
35506 | + if (!shared_br || !shared_br->br_xino.xi_file) { | |
35507 | + struct au_xino_lock_dir ldir; | |
35508 | + | |
35509 | + au_xino_lock_dir(sb, base_file, &ldir); | |
35510 | + /* mnt_want_write() is unnecessary here */ | |
35511 | + file = au_xino_create2(base_file, NULL); | |
35512 | + au_xino_unlock_dir(&ldir); | |
35513 | + err = PTR_ERR(file); | |
35514 | + if (IS_ERR(file)) | |
35515 | + goto out; | |
35516 | + br->br_xino.xi_file = file; | |
35517 | + } else { | |
35518 | + br->br_xino.xi_file = shared_br->br_xino.xi_file; | |
35519 | + get_file(br->br_xino.xi_file); | |
35520 | + } | |
35521 | + | |
35522 | + ino = AUFS_ROOT_INO; | |
35523 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
35524 | + h_ino, ino); | |
b752ccd1 AM |
35525 | + if (unlikely(err)) { |
35526 | + fput(br->br_xino.xi_file); | |
35527 | + br->br_xino.xi_file = NULL; | |
35528 | + } | |
1facf9fc | 35529 | + |
4f0767ce | 35530 | +out: |
1facf9fc | 35531 | + return err; |
35532 | +} | |
35533 | + | |
35534 | +/* ---------------------------------------------------------------------- */ | |
35535 | + | |
35536 | +/* trucate a xino bitmap file */ | |
35537 | + | |
35538 | +/* todo: slow */ | |
35539 | +static int do_xib_restore(struct super_block *sb, struct file *file, void *page) | |
35540 | +{ | |
35541 | + int err, bit; | |
35542 | + ssize_t sz; | |
35543 | + unsigned long pindex; | |
35544 | + loff_t pos, pend; | |
35545 | + struct au_sbinfo *sbinfo; | |
5527c038 | 35546 | + vfs_readf_t func; |
1facf9fc | 35547 | + ino_t *ino; |
35548 | + unsigned long *p; | |
35549 | + | |
35550 | + err = 0; | |
35551 | + sbinfo = au_sbi(sb); | |
dece6358 | 35552 | + MtxMustLock(&sbinfo->si_xib_mtx); |
1facf9fc | 35553 | + p = sbinfo->si_xib_buf; |
35554 | + func = sbinfo->si_xread; | |
c06a8ce3 | 35555 | + pend = vfsub_f_size_read(file); |
1facf9fc | 35556 | + pos = 0; |
35557 | + while (pos < pend) { | |
35558 | + sz = xino_fread(func, file, page, PAGE_SIZE, &pos); | |
35559 | + err = sz; | |
35560 | + if (unlikely(sz <= 0)) | |
35561 | + goto out; | |
35562 | + | |
35563 | + err = 0; | |
35564 | + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) { | |
35565 | + if (unlikely(*ino < AUFS_FIRST_INO)) | |
35566 | + continue; | |
35567 | + | |
35568 | + xib_calc_bit(*ino, &pindex, &bit); | |
35569 | + AuDebugOn(page_bits <= bit); | |
35570 | + err = xib_pindex(sb, pindex); | |
35571 | + if (!err) | |
35572 | + set_bit(bit, p); | |
35573 | + else | |
35574 | + goto out; | |
35575 | + } | |
35576 | + } | |
35577 | + | |
4f0767ce | 35578 | +out: |
1facf9fc | 35579 | + return err; |
35580 | +} | |
35581 | + | |
35582 | +static int xib_restore(struct super_block *sb) | |
35583 | +{ | |
35584 | + int err; | |
5afbbe0d | 35585 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 35586 | + void *page; |
35587 | + | |
35588 | + err = -ENOMEM; | |
35589 | + page = (void *)__get_free_page(GFP_NOFS); | |
35590 | + if (unlikely(!page)) | |
35591 | + goto out; | |
35592 | + | |
35593 | + err = 0; | |
5afbbe0d AM |
35594 | + bbot = au_sbbot(sb); |
35595 | + for (bindex = 0; !err && bindex <= bbot; bindex++) | |
1facf9fc | 35596 | + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) |
35597 | + err = do_xib_restore | |
35598 | + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page); | |
35599 | + else | |
35600 | + AuDbg("b%d\n", bindex); | |
f0c0a007 | 35601 | + au_delayed_free_page((unsigned long)page); |
1facf9fc | 35602 | + |
4f0767ce | 35603 | +out: |
1facf9fc | 35604 | + return err; |
35605 | +} | |
35606 | + | |
35607 | +int au_xib_trunc(struct super_block *sb) | |
35608 | +{ | |
35609 | + int err; | |
35610 | + ssize_t sz; | |
35611 | + loff_t pos; | |
35612 | + struct au_xino_lock_dir ldir; | |
35613 | + struct au_sbinfo *sbinfo; | |
35614 | + unsigned long *p; | |
35615 | + struct file *file; | |
35616 | + | |
dece6358 AM |
35617 | + SiMustWriteLock(sb); |
35618 | + | |
1facf9fc | 35619 | + err = 0; |
35620 | + sbinfo = au_sbi(sb); | |
35621 | + if (!au_opt_test(sbinfo->si_mntflags, XINO)) | |
35622 | + goto out; | |
35623 | + | |
35624 | + file = sbinfo->si_xib; | |
c06a8ce3 | 35625 | + if (vfsub_f_size_read(file) <= PAGE_SIZE) |
1facf9fc | 35626 | + goto out; |
35627 | + | |
35628 | + au_xino_lock_dir(sb, file, &ldir); | |
35629 | + /* mnt_want_write() is unnecessary here */ | |
35630 | + file = au_xino_create2(sbinfo->si_xib, NULL); | |
35631 | + au_xino_unlock_dir(&ldir); | |
35632 | + err = PTR_ERR(file); | |
35633 | + if (IS_ERR(file)) | |
35634 | + goto out; | |
35635 | + fput(sbinfo->si_xib); | |
35636 | + sbinfo->si_xib = file; | |
35637 | + | |
35638 | + p = sbinfo->si_xib_buf; | |
35639 | + memset(p, 0, PAGE_SIZE); | |
35640 | + pos = 0; | |
35641 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos); | |
35642 | + if (unlikely(sz != PAGE_SIZE)) { | |
35643 | + err = sz; | |
35644 | + AuIOErr("err %d\n", err); | |
35645 | + if (sz >= 0) | |
35646 | + err = -EIO; | |
35647 | + goto out; | |
35648 | + } | |
35649 | + | |
35650 | + mutex_lock(&sbinfo->si_xib_mtx); | |
35651 | + /* mnt_want_write() is unnecessary here */ | |
35652 | + err = xib_restore(sb); | |
35653 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
35654 | + | |
35655 | +out: | |
35656 | + return err; | |
35657 | +} | |
35658 | + | |
35659 | +/* ---------------------------------------------------------------------- */ | |
35660 | + | |
35661 | +/* | |
35662 | + * xino mount option handlers | |
35663 | + */ | |
1facf9fc | 35664 | + |
35665 | +/* xino bitmap */ | |
35666 | +static void xino_clear_xib(struct super_block *sb) | |
35667 | +{ | |
35668 | + struct au_sbinfo *sbinfo; | |
35669 | + | |
dece6358 AM |
35670 | + SiMustWriteLock(sb); |
35671 | + | |
1facf9fc | 35672 | + sbinfo = au_sbi(sb); |
35673 | + sbinfo->si_xread = NULL; | |
35674 | + sbinfo->si_xwrite = NULL; | |
35675 | + if (sbinfo->si_xib) | |
35676 | + fput(sbinfo->si_xib); | |
35677 | + sbinfo->si_xib = NULL; | |
f0c0a007 AM |
35678 | + if (sbinfo->si_xib_buf) |
35679 | + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf); | |
1facf9fc | 35680 | + sbinfo->si_xib_buf = NULL; |
35681 | +} | |
35682 | + | |
35683 | +static int au_xino_set_xib(struct super_block *sb, struct file *base) | |
35684 | +{ | |
35685 | + int err; | |
35686 | + loff_t pos; | |
35687 | + struct au_sbinfo *sbinfo; | |
35688 | + struct file *file; | |
35689 | + | |
dece6358 AM |
35690 | + SiMustWriteLock(sb); |
35691 | + | |
1facf9fc | 35692 | + sbinfo = au_sbi(sb); |
35693 | + file = au_xino_create2(base, sbinfo->si_xib); | |
35694 | + err = PTR_ERR(file); | |
35695 | + if (IS_ERR(file)) | |
35696 | + goto out; | |
35697 | + if (sbinfo->si_xib) | |
35698 | + fput(sbinfo->si_xib); | |
35699 | + sbinfo->si_xib = file; | |
5527c038 JR |
35700 | + sbinfo->si_xread = vfs_readf(file); |
35701 | + sbinfo->si_xwrite = vfs_writef(file); | |
1facf9fc | 35702 | + |
35703 | + err = -ENOMEM; | |
35704 | + if (!sbinfo->si_xib_buf) | |
35705 | + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS); | |
35706 | + if (unlikely(!sbinfo->si_xib_buf)) | |
35707 | + goto out_unset; | |
35708 | + | |
35709 | + sbinfo->si_xib_last_pindex = 0; | |
35710 | + sbinfo->si_xib_next_bit = 0; | |
c06a8ce3 | 35711 | + if (vfsub_f_size_read(file) < PAGE_SIZE) { |
1facf9fc | 35712 | + pos = 0; |
35713 | + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf, | |
35714 | + PAGE_SIZE, &pos); | |
35715 | + if (unlikely(err != PAGE_SIZE)) | |
35716 | + goto out_free; | |
35717 | + } | |
35718 | + err = 0; | |
35719 | + goto out; /* success */ | |
35720 | + | |
4f0767ce | 35721 | +out_free: |
f0c0a007 AM |
35722 | + if (sbinfo->si_xib_buf) |
35723 | + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf); | |
b752ccd1 AM |
35724 | + sbinfo->si_xib_buf = NULL; |
35725 | + if (err >= 0) | |
35726 | + err = -EIO; | |
4f0767ce | 35727 | +out_unset: |
b752ccd1 AM |
35728 | + fput(sbinfo->si_xib); |
35729 | + sbinfo->si_xib = NULL; | |
35730 | + sbinfo->si_xread = NULL; | |
35731 | + sbinfo->si_xwrite = NULL; | |
4f0767ce | 35732 | +out: |
b752ccd1 | 35733 | + return err; |
1facf9fc | 35734 | +} |
35735 | + | |
b752ccd1 AM |
35736 | +/* xino for each branch */ |
35737 | +static void xino_clear_br(struct super_block *sb) | |
35738 | +{ | |
5afbbe0d | 35739 | + aufs_bindex_t bindex, bbot; |
b752ccd1 | 35740 | + struct au_branch *br; |
1facf9fc | 35741 | + |
5afbbe0d AM |
35742 | + bbot = au_sbbot(sb); |
35743 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
b752ccd1 AM |
35744 | + br = au_sbr(sb, bindex); |
35745 | + if (!br || !br->br_xino.xi_file) | |
35746 | + continue; | |
35747 | + | |
35748 | + fput(br->br_xino.xi_file); | |
35749 | + br->br_xino.xi_file = NULL; | |
35750 | + } | |
35751 | +} | |
35752 | + | |
35753 | +static int au_xino_set_br(struct super_block *sb, struct file *base) | |
1facf9fc | 35754 | +{ |
35755 | + int err; | |
b752ccd1 | 35756 | + ino_t ino; |
5afbbe0d | 35757 | + aufs_bindex_t bindex, bbot, bshared; |
b752ccd1 AM |
35758 | + struct { |
35759 | + struct file *old, *new; | |
35760 | + } *fpair, *p; | |
35761 | + struct au_branch *br; | |
35762 | + struct inode *inode; | |
5527c038 | 35763 | + vfs_writef_t writef; |
1facf9fc | 35764 | + |
b752ccd1 AM |
35765 | + SiMustWriteLock(sb); |
35766 | + | |
35767 | + err = -ENOMEM; | |
5afbbe0d AM |
35768 | + bbot = au_sbbot(sb); |
35769 | + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS); | |
b752ccd1 | 35770 | + if (unlikely(!fpair)) |
1facf9fc | 35771 | + goto out; |
35772 | + | |
5527c038 | 35773 | + inode = d_inode(sb->s_root); |
b752ccd1 AM |
35774 | + ino = AUFS_ROOT_INO; |
35775 | + writef = au_sbi(sb)->si_xwrite; | |
5afbbe0d | 35776 | + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) { |
b752ccd1 AM |
35777 | + bshared = is_sb_shared(sb, bindex, bindex - 1); |
35778 | + if (bshared >= 0) { | |
35779 | + /* shared xino */ | |
35780 | + *p = fpair[bshared]; | |
35781 | + get_file(p->new); | |
35782 | + } | |
35783 | + | |
35784 | + if (!p->new) { | |
35785 | + /* new xino */ | |
5afbbe0d | 35786 | + br = au_sbr(sb, bindex); |
b752ccd1 AM |
35787 | + p->old = br->br_xino.xi_file; |
35788 | + p->new = au_xino_create2(base, br->br_xino.xi_file); | |
35789 | + err = PTR_ERR(p->new); | |
35790 | + if (IS_ERR(p->new)) { | |
35791 | + p->new = NULL; | |
35792 | + goto out_pair; | |
35793 | + } | |
35794 | + } | |
35795 | + | |
35796 | + err = au_xino_do_write(writef, p->new, | |
35797 | + au_h_iptr(inode, bindex)->i_ino, ino); | |
35798 | + if (unlikely(err)) | |
35799 | + goto out_pair; | |
35800 | + } | |
35801 | + | |
5afbbe0d | 35802 | + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) { |
b752ccd1 AM |
35803 | + br = au_sbr(sb, bindex); |
35804 | + if (br->br_xino.xi_file) | |
35805 | + fput(br->br_xino.xi_file); | |
35806 | + get_file(p->new); | |
35807 | + br->br_xino.xi_file = p->new; | |
35808 | + } | |
1facf9fc | 35809 | + |
4f0767ce | 35810 | +out_pair: |
5afbbe0d | 35811 | + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) |
b752ccd1 AM |
35812 | + if (p->new) |
35813 | + fput(p->new); | |
35814 | + else | |
35815 | + break; | |
f0c0a007 | 35816 | + au_delayed_kfree(fpair); |
4f0767ce | 35817 | +out: |
1facf9fc | 35818 | + return err; |
35819 | +} | |
b752ccd1 AM |
35820 | + |
35821 | +void au_xino_clr(struct super_block *sb) | |
35822 | +{ | |
35823 | + struct au_sbinfo *sbinfo; | |
35824 | + | |
35825 | + au_xigen_clr(sb); | |
35826 | + xino_clear_xib(sb); | |
35827 | + xino_clear_br(sb); | |
35828 | + sbinfo = au_sbi(sb); | |
35829 | + /* lvalue, do not call au_mntflags() */ | |
35830 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
35831 | +} | |
35832 | + | |
35833 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount) | |
35834 | +{ | |
35835 | + int err, skip; | |
35836 | + struct dentry *parent, *cur_parent; | |
35837 | + struct qstr *dname, *cur_name; | |
35838 | + struct file *cur_xino; | |
35839 | + struct inode *dir; | |
35840 | + struct au_sbinfo *sbinfo; | |
35841 | + | |
35842 | + SiMustWriteLock(sb); | |
35843 | + | |
35844 | + err = 0; | |
35845 | + sbinfo = au_sbi(sb); | |
2000de60 | 35846 | + parent = dget_parent(xino->file->f_path.dentry); |
b752ccd1 AM |
35847 | + if (remount) { |
35848 | + skip = 0; | |
2000de60 | 35849 | + dname = &xino->file->f_path.dentry->d_name; |
b752ccd1 AM |
35850 | + cur_xino = sbinfo->si_xib; |
35851 | + if (cur_xino) { | |
2000de60 JR |
35852 | + cur_parent = dget_parent(cur_xino->f_path.dentry); |
35853 | + cur_name = &cur_xino->f_path.dentry->d_name; | |
b752ccd1 | 35854 | + skip = (cur_parent == parent |
38d290e6 | 35855 | + && au_qstreq(dname, cur_name)); |
b752ccd1 AM |
35856 | + dput(cur_parent); |
35857 | + } | |
35858 | + if (skip) | |
35859 | + goto out; | |
35860 | + } | |
35861 | + | |
35862 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
5527c038 | 35863 | + dir = d_inode(parent); |
febd17d6 | 35864 | + inode_lock_nested(dir, AuLsc_I_PARENT); |
b752ccd1 AM |
35865 | + /* mnt_want_write() is unnecessary here */ |
35866 | + err = au_xino_set_xib(sb, xino->file); | |
35867 | + if (!err) | |
35868 | + err = au_xigen_set(sb, xino->file); | |
35869 | + if (!err) | |
35870 | + err = au_xino_set_br(sb, xino->file); | |
febd17d6 | 35871 | + inode_unlock(dir); |
b752ccd1 AM |
35872 | + if (!err) |
35873 | + goto out; /* success */ | |
35874 | + | |
35875 | + /* reset all */ | |
35876 | + AuIOErr("failed creating xino(%d).\n", err); | |
c1595e42 JR |
35877 | + au_xigen_clr(sb); |
35878 | + xino_clear_xib(sb); | |
b752ccd1 | 35879 | + |
4f0767ce | 35880 | +out: |
b752ccd1 AM |
35881 | + dput(parent); |
35882 | + return err; | |
35883 | +} | |
35884 | + | |
35885 | +/* ---------------------------------------------------------------------- */ | |
35886 | + | |
35887 | +/* | |
35888 | + * create a xinofile at the default place/path. | |
35889 | + */ | |
35890 | +struct file *au_xino_def(struct super_block *sb) | |
35891 | +{ | |
35892 | + struct file *file; | |
35893 | + char *page, *p; | |
35894 | + struct au_branch *br; | |
35895 | + struct super_block *h_sb; | |
35896 | + struct path path; | |
5afbbe0d | 35897 | + aufs_bindex_t bbot, bindex, bwr; |
b752ccd1 AM |
35898 | + |
35899 | + br = NULL; | |
5afbbe0d | 35900 | + bbot = au_sbbot(sb); |
b752ccd1 | 35901 | + bwr = -1; |
5afbbe0d | 35902 | + for (bindex = 0; bindex <= bbot; bindex++) { |
b752ccd1 AM |
35903 | + br = au_sbr(sb, bindex); |
35904 | + if (au_br_writable(br->br_perm) | |
86dc4139 | 35905 | + && !au_test_fs_bad_xino(au_br_sb(br))) { |
b752ccd1 AM |
35906 | + bwr = bindex; |
35907 | + break; | |
35908 | + } | |
35909 | + } | |
35910 | + | |
7f207e10 AM |
35911 | + if (bwr >= 0) { |
35912 | + file = ERR_PTR(-ENOMEM); | |
537831f9 | 35913 | + page = (void *)__get_free_page(GFP_NOFS); |
7f207e10 AM |
35914 | + if (unlikely(!page)) |
35915 | + goto out; | |
86dc4139 | 35916 | + path.mnt = au_br_mnt(br); |
7f207e10 AM |
35917 | + path.dentry = au_h_dptr(sb->s_root, bwr); |
35918 | + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME)); | |
35919 | + file = (void *)p; | |
35920 | + if (!IS_ERR(p)) { | |
35921 | + strcat(p, "/" AUFS_XINO_FNAME); | |
35922 | + AuDbg("%s\n", p); | |
35923 | + file = au_xino_create(sb, p, /*silent*/0); | |
35924 | + if (!IS_ERR(file)) | |
35925 | + au_xino_brid_set(sb, br->br_id); | |
35926 | + } | |
f0c0a007 | 35927 | + au_delayed_free_page((unsigned long)page); |
7f207e10 AM |
35928 | + } else { |
35929 | + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0); | |
35930 | + if (IS_ERR(file)) | |
35931 | + goto out; | |
2000de60 | 35932 | + h_sb = file->f_path.dentry->d_sb; |
7f207e10 AM |
35933 | + if (unlikely(au_test_fs_bad_xino(h_sb))) { |
35934 | + pr_err("xino doesn't support %s(%s)\n", | |
35935 | + AUFS_XINO_DEFPATH, au_sbtype(h_sb)); | |
35936 | + fput(file); | |
35937 | + file = ERR_PTR(-EINVAL); | |
35938 | + } | |
35939 | + if (!IS_ERR(file)) | |
35940 | + au_xino_brid_set(sb, -1); | |
35941 | + } | |
0c5527e5 | 35942 | + |
7f207e10 AM |
35943 | +out: |
35944 | + return file; | |
35945 | +} | |
35946 | + | |
35947 | +/* ---------------------------------------------------------------------- */ | |
35948 | + | |
35949 | +int au_xino_path(struct seq_file *seq, struct file *file) | |
35950 | +{ | |
35951 | + int err; | |
35952 | + | |
35953 | + err = au_seq_path(seq, &file->f_path); | |
79b8bda9 | 35954 | + if (unlikely(err)) |
7f207e10 AM |
35955 | + goto out; |
35956 | + | |
7f207e10 AM |
35957 | +#define Deleted "\\040(deleted)" |
35958 | + seq->count -= sizeof(Deleted) - 1; | |
35959 | + AuDebugOn(memcmp(seq->buf + seq->count, Deleted, | |
35960 | + sizeof(Deleted) - 1)); | |
35961 | +#undef Deleted | |
35962 | + | |
35963 | +out: | |
35964 | + return err; | |
35965 | +} | |
521ced18 JR |
35966 | + |
35967 | +/* ---------------------------------------------------------------------- */ | |
35968 | + | |
35969 | +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex, | |
35970 | + ino_t h_ino, int idx) | |
35971 | +{ | |
35972 | + struct au_xino_file *xino; | |
35973 | + | |
35974 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); | |
35975 | + xino = &au_sbr(sb, bindex)->br_xino; | |
35976 | + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx); | |
35977 | + | |
35978 | + spin_lock(&xino->xi_nondir.spin); | |
35979 | + AuDebugOn(xino->xi_nondir.array[idx] != h_ino); | |
35980 | + xino->xi_nondir.array[idx] = 0; | |
35981 | + spin_unlock(&xino->xi_nondir.spin); | |
35982 | + wake_up_all(&xino->xi_nondir.wqh); | |
35983 | +} | |
35984 | + | |
35985 | +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino) | |
35986 | +{ | |
35987 | + int found, total, i; | |
35988 | + | |
35989 | + found = -1; | |
35990 | + total = xino->xi_nondir.total; | |
35991 | + for (i = 0; i < total; i++) { | |
35992 | + if (xino->xi_nondir.array[i] != h_ino) | |
35993 | + continue; | |
35994 | + found = i; | |
35995 | + break; | |
35996 | + } | |
35997 | + | |
35998 | + return found; | |
35999 | +} | |
36000 | + | |
36001 | +static int au_xinondir_expand(struct au_xino_file *xino) | |
36002 | +{ | |
36003 | + int err, sz; | |
36004 | + ino_t *p; | |
36005 | + | |
36006 | + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX); | |
36007 | + | |
36008 | + err = -ENOMEM; | |
36009 | + sz = xino->xi_nondir.total * sizeof(ino_t); | |
36010 | + if (unlikely(sz > KMALLOC_MAX_SIZE / 2)) | |
36011 | + goto out; | |
36012 | + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC, | |
36013 | + /*may_shrink*/0); | |
36014 | + if (p) { | |
36015 | + xino->xi_nondir.array = p; | |
36016 | + xino->xi_nondir.total <<= 1; | |
36017 | + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total); | |
36018 | + err = 0; | |
36019 | + } | |
36020 | + | |
36021 | +out: | |
36022 | + return err; | |
36023 | +} | |
36024 | + | |
36025 | +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
36026 | + int *idx) | |
36027 | +{ | |
36028 | + int err, found, empty; | |
36029 | + struct au_xino_file *xino; | |
36030 | + | |
36031 | + err = 0; | |
36032 | + *idx = -1; | |
36033 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
36034 | + goto out; /* no xino */ | |
36035 | + | |
36036 | + xino = &au_sbr(sb, bindex)->br_xino; | |
36037 | + | |
36038 | +again: | |
36039 | + spin_lock(&xino->xi_nondir.spin); | |
36040 | + found = au_xinondir_find(xino, h_ino); | |
36041 | + if (found == -1) { | |
36042 | + empty = au_xinondir_find(xino, /*h_ino*/0); | |
36043 | + if (empty == -1) { | |
36044 | + empty = xino->xi_nondir.total; | |
36045 | + err = au_xinondir_expand(xino); | |
36046 | + if (unlikely(err)) | |
36047 | + goto out_unlock; | |
36048 | + } | |
36049 | + xino->xi_nondir.array[empty] = h_ino; | |
36050 | + *idx = empty; | |
36051 | + } else { | |
36052 | + spin_unlock(&xino->xi_nondir.spin); | |
36053 | + wait_event(xino->xi_nondir.wqh, | |
36054 | + xino->xi_nondir.array[found] != h_ino); | |
36055 | + goto again; | |
36056 | + } | |
36057 | + | |
36058 | +out_unlock: | |
36059 | + spin_unlock(&xino->xi_nondir.spin); | |
36060 | +out: | |
36061 | + return err; | |
36062 | +} | |
537831f9 AM |
36063 | diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h |
36064 | --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100 | |
521ced18 | 36065 | +++ linux/include/uapi/linux/aufs_type.h 2017-05-06 22:16:52.784886929 +0200 |
c1595e42 | 36066 | @@ -0,0 +1,419 @@ |
7f207e10 | 36067 | +/* |
a2654f78 | 36068 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
7f207e10 AM |
36069 | + * |
36070 | + * This program, aufs is free software; you can redistribute it and/or modify | |
36071 | + * it under the terms of the GNU General Public License as published by | |
36072 | + * the Free Software Foundation; either version 2 of the License, or | |
36073 | + * (at your option) any later version. | |
36074 | + * | |
36075 | + * This program is distributed in the hope that it will be useful, | |
36076 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
36077 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36078 | + * GNU General Public License for more details. | |
36079 | + * | |
36080 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 36081 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
36082 | + */ |
36083 | + | |
36084 | +#ifndef __AUFS_TYPE_H__ | |
36085 | +#define __AUFS_TYPE_H__ | |
36086 | + | |
f6c5ef8b AM |
36087 | +#define AUFS_NAME "aufs" |
36088 | + | |
9dbd164d | 36089 | +#ifdef __KERNEL__ |
f6c5ef8b AM |
36090 | +/* |
36091 | + * define it before including all other headers. | |
36092 | + * sched.h may use pr_* macros before defining "current", so define the | |
36093 | + * no-current version first, and re-define later. | |
36094 | + */ | |
36095 | +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__ | |
36096 | +#include <linux/sched.h> | |
36097 | +#undef pr_fmt | |
a2a7ad62 AM |
36098 | +#define pr_fmt(fmt) \ |
36099 | + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \ | |
36100 | + (int)sizeof(current->comm), current->comm, current->pid | |
9dbd164d AM |
36101 | +#else |
36102 | +#include <stdint.h> | |
36103 | +#include <sys/types.h> | |
f6c5ef8b | 36104 | +#endif /* __KERNEL__ */ |
7f207e10 | 36105 | + |
f6c5ef8b AM |
36106 | +#include <linux/limits.h> |
36107 | + | |
521ced18 | 36108 | +#define AUFS_VERSION "4.x-rcN-20170410" |
7f207e10 AM |
36109 | + |
36110 | +/* todo? move this to linux-2.6.19/include/magic.h */ | |
36111 | +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's') | |
36112 | + | |
36113 | +/* ---------------------------------------------------------------------- */ | |
36114 | + | |
36115 | +#ifdef CONFIG_AUFS_BRANCH_MAX_127 | |
9dbd164d | 36116 | +typedef int8_t aufs_bindex_t; |
7f207e10 AM |
36117 | +#define AUFS_BRANCH_MAX 127 |
36118 | +#else | |
9dbd164d | 36119 | +typedef int16_t aufs_bindex_t; |
7f207e10 AM |
36120 | +#ifdef CONFIG_AUFS_BRANCH_MAX_511 |
36121 | +#define AUFS_BRANCH_MAX 511 | |
36122 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023) | |
36123 | +#define AUFS_BRANCH_MAX 1023 | |
36124 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767) | |
36125 | +#define AUFS_BRANCH_MAX 32767 | |
36126 | +#endif | |
36127 | +#endif | |
36128 | + | |
36129 | +#ifdef __KERNEL__ | |
36130 | +#ifndef AUFS_BRANCH_MAX | |
36131 | +#error unknown CONFIG_AUFS_BRANCH_MAX value | |
36132 | +#endif | |
36133 | +#endif /* __KERNEL__ */ | |
36134 | + | |
36135 | +/* ---------------------------------------------------------------------- */ | |
36136 | + | |
7f207e10 AM |
36137 | +#define AUFS_FSTYPE AUFS_NAME |
36138 | + | |
36139 | +#define AUFS_ROOT_INO 2 | |
36140 | +#define AUFS_FIRST_INO 11 | |
36141 | + | |
36142 | +#define AUFS_WH_PFX ".wh." | |
36143 | +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1) | |
36144 | +#define AUFS_WH_TMP_LEN 4 | |
86dc4139 | 36145 | +/* a limit for rmdir/rename a dir and copyup */ |
7f207e10 AM |
36146 | +#define AUFS_MAX_NAMELEN (NAME_MAX \ |
36147 | + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\ | |
36148 | + - 1 /* dot */\ | |
36149 | + - AUFS_WH_TMP_LEN) /* hex */ | |
36150 | +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino" | |
36151 | +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME | |
392086de AM |
36152 | +#define AUFS_XINO_DEF_SEC 30 /* seconds */ |
36153 | +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */ | |
7f207e10 AM |
36154 | +#define AUFS_DIRWH_DEF 3 |
36155 | +#define AUFS_RDCACHE_DEF 10 /* seconds */ | |
027c5e7a | 36156 | +#define AUFS_RDCACHE_MAX 3600 /* seconds */ |
7f207e10 AM |
36157 | +#define AUFS_RDBLK_DEF 512 /* bytes */ |
36158 | +#define AUFS_RDHASH_DEF 32 | |
36159 | +#define AUFS_WKQ_NAME AUFS_NAME "d" | |
027c5e7a AM |
36160 | +#define AUFS_MFS_DEF_SEC 30 /* seconds */ |
36161 | +#define AUFS_MFS_MAX_SEC 3600 /* seconds */ | |
076b876e | 36162 | +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */ |
86dc4139 | 36163 | +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */ |
7f207e10 AM |
36164 | + |
36165 | +/* pseudo-link maintenace under /proc */ | |
36166 | +#define AUFS_PLINK_MAINT_NAME "plink_maint" | |
36167 | +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME | |
36168 | +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME | |
36169 | + | |
36170 | +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */ | |
36171 | +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME | |
36172 | + | |
36173 | +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME | |
36174 | +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk" | |
36175 | +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph" | |
36176 | + | |
36177 | +/* doubly whiteouted */ | |
36178 | +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME | |
36179 | +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME | |
36180 | +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME | |
36181 | + | |
1e00d052 | 36182 | +/* branch permissions and attributes */ |
7f207e10 AM |
36183 | +#define AUFS_BRPERM_RW "rw" |
36184 | +#define AUFS_BRPERM_RO "ro" | |
36185 | +#define AUFS_BRPERM_RR "rr" | |
076b876e AM |
36186 | +#define AUFS_BRATTR_COO_REG "coo_reg" |
36187 | +#define AUFS_BRATTR_COO_ALL "coo_all" | |
36188 | +#define AUFS_BRATTR_FHSM "fhsm" | |
36189 | +#define AUFS_BRATTR_UNPIN "unpin" | |
c1595e42 JR |
36190 | +#define AUFS_BRATTR_ICEX "icex" |
36191 | +#define AUFS_BRATTR_ICEX_SEC "icexsec" | |
36192 | +#define AUFS_BRATTR_ICEX_SYS "icexsys" | |
36193 | +#define AUFS_BRATTR_ICEX_TR "icextr" | |
36194 | +#define AUFS_BRATTR_ICEX_USR "icexusr" | |
36195 | +#define AUFS_BRATTR_ICEX_OTH "icexoth" | |
1e00d052 AM |
36196 | +#define AUFS_BRRATTR_WH "wh" |
36197 | +#define AUFS_BRWATTR_NLWH "nolwh" | |
076b876e AM |
36198 | +#define AUFS_BRWATTR_MOO "moo" |
36199 | + | |
36200 | +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */ | |
36201 | +#define AuBrPerm_RO (1 << 1) /* readonly */ | |
36202 | +#define AuBrPerm_RR (1 << 2) /* natively readonly */ | |
36203 | +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR) | |
36204 | + | |
36205 | +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */ | |
36206 | +#define AuBrAttr_COO_ALL (1 << 4) | |
36207 | +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL) | |
36208 | + | |
36209 | +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */ | |
36210 | +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of | |
c1595e42 JR |
36211 | + branch. meaningless since |
36212 | + linux-3.18-rc1 */ | |
36213 | + | |
36214 | +/* ignore error in copying XATTR */ | |
36215 | +#define AuBrAttr_ICEX_SEC (1 << 7) | |
36216 | +#define AuBrAttr_ICEX_SYS (1 << 8) | |
36217 | +#define AuBrAttr_ICEX_TR (1 << 9) | |
36218 | +#define AuBrAttr_ICEX_USR (1 << 10) | |
36219 | +#define AuBrAttr_ICEX_OTH (1 << 11) | |
36220 | +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \ | |
36221 | + | AuBrAttr_ICEX_SYS \ | |
36222 | + | AuBrAttr_ICEX_TR \ | |
36223 | + | AuBrAttr_ICEX_USR \ | |
36224 | + | AuBrAttr_ICEX_OTH) | |
36225 | + | |
36226 | +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */ | |
076b876e AM |
36227 | +#define AuBrRAttr_Mask AuBrRAttr_WH |
36228 | + | |
c1595e42 JR |
36229 | +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */ |
36230 | +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */ | |
076b876e AM |
36231 | +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO) |
36232 | + | |
36233 | +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO) | |
36234 | + | |
c1595e42 | 36235 | +/* #warning test userspace */ |
076b876e AM |
36236 | +#ifdef __KERNEL__ |
36237 | +#ifndef CONFIG_AUFS_FHSM | |
36238 | +#undef AuBrAttr_FHSM | |
36239 | +#define AuBrAttr_FHSM 0 | |
36240 | +#endif | |
c1595e42 JR |
36241 | +#ifndef CONFIG_AUFS_XATTR |
36242 | +#undef AuBrAttr_ICEX | |
36243 | +#define AuBrAttr_ICEX 0 | |
36244 | +#undef AuBrAttr_ICEX_SEC | |
36245 | +#define AuBrAttr_ICEX_SEC 0 | |
36246 | +#undef AuBrAttr_ICEX_SYS | |
36247 | +#define AuBrAttr_ICEX_SYS 0 | |
36248 | +#undef AuBrAttr_ICEX_TR | |
36249 | +#define AuBrAttr_ICEX_TR 0 | |
36250 | +#undef AuBrAttr_ICEX_USR | |
36251 | +#define AuBrAttr_ICEX_USR 0 | |
36252 | +#undef AuBrAttr_ICEX_OTH | |
36253 | +#define AuBrAttr_ICEX_OTH 0 | |
36254 | +#endif | |
076b876e AM |
36255 | +#endif |
36256 | + | |
36257 | +/* the longest combination */ | |
c1595e42 JR |
36258 | +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */ |
36259 | +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \ | |
36260 | + "+" AUFS_BRATTR_COO_REG \ | |
36261 | + "+" AUFS_BRATTR_FHSM \ | |
36262 | + "+" AUFS_BRATTR_UNPIN \ | |
7e9cd9fe AM |
36263 | + "+" AUFS_BRATTR_ICEX_SEC \ |
36264 | + "+" AUFS_BRATTR_ICEX_SYS \ | |
36265 | + "+" AUFS_BRATTR_ICEX_USR \ | |
36266 | + "+" AUFS_BRATTR_ICEX_OTH \ | |
076b876e AM |
36267 | + "+" AUFS_BRWATTR_NLWH) |
36268 | + | |
36269 | +typedef struct { | |
36270 | + char a[AuBrPermStrSz]; | |
36271 | +} au_br_perm_str_t; | |
36272 | + | |
36273 | +static inline int au_br_writable(int brperm) | |
36274 | +{ | |
36275 | + return brperm & AuBrPerm_RW; | |
36276 | +} | |
36277 | + | |
36278 | +static inline int au_br_whable(int brperm) | |
36279 | +{ | |
36280 | + return brperm & (AuBrPerm_RW | AuBrRAttr_WH); | |
36281 | +} | |
36282 | + | |
36283 | +static inline int au_br_wh_linkable(int brperm) | |
36284 | +{ | |
36285 | + return !(brperm & AuBrWAttr_NoLinkWH); | |
36286 | +} | |
36287 | + | |
36288 | +static inline int au_br_cmoo(int brperm) | |
36289 | +{ | |
36290 | + return brperm & AuBrAttr_CMOO_Mask; | |
36291 | +} | |
36292 | + | |
36293 | +static inline int au_br_fhsm(int brperm) | |
36294 | +{ | |
36295 | + return brperm & AuBrAttr_FHSM; | |
36296 | +} | |
7f207e10 AM |
36297 | + |
36298 | +/* ---------------------------------------------------------------------- */ | |
36299 | + | |
36300 | +/* ioctl */ | |
36301 | +enum { | |
36302 | + /* readdir in userspace */ | |
36303 | + AuCtl_RDU, | |
36304 | + AuCtl_RDU_INO, | |
36305 | + | |
076b876e AM |
36306 | + AuCtl_WBR_FD, /* pathconf wrapper */ |
36307 | + AuCtl_IBUSY, /* busy inode */ | |
36308 | + AuCtl_MVDOWN, /* move-down */ | |
36309 | + AuCtl_BR, /* info about branches */ | |
36310 | + AuCtl_FHSM_FD /* connection for fhsm */ | |
7f207e10 AM |
36311 | +}; |
36312 | + | |
36313 | +/* borrowed from linux/include/linux/kernel.h */ | |
36314 | +#ifndef ALIGN | |
36315 | +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) | |
36316 | +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | |
36317 | +#endif | |
36318 | + | |
36319 | +/* borrowed from linux/include/linux/compiler-gcc3.h */ | |
36320 | +#ifndef __aligned | |
36321 | +#define __aligned(x) __attribute__((aligned(x))) | |
53392da6 AM |
36322 | +#endif |
36323 | + | |
36324 | +#ifdef __KERNEL__ | |
36325 | +#ifndef __packed | |
7f207e10 AM |
36326 | +#define __packed __attribute__((packed)) |
36327 | +#endif | |
53392da6 | 36328 | +#endif |
7f207e10 AM |
36329 | + |
36330 | +struct au_rdu_cookie { | |
9dbd164d AM |
36331 | + uint64_t h_pos; |
36332 | + int16_t bindex; | |
36333 | + uint8_t flags; | |
36334 | + uint8_t pad; | |
36335 | + uint32_t generation; | |
7f207e10 AM |
36336 | +} __aligned(8); |
36337 | + | |
36338 | +struct au_rdu_ent { | |
9dbd164d AM |
36339 | + uint64_t ino; |
36340 | + int16_t bindex; | |
36341 | + uint8_t type; | |
36342 | + uint8_t nlen; | |
36343 | + uint8_t wh; | |
7f207e10 AM |
36344 | + char name[0]; |
36345 | +} __aligned(8); | |
36346 | + | |
36347 | +static inline int au_rdu_len(int nlen) | |
36348 | +{ | |
36349 | + /* include the terminating NULL */ | |
36350 | + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1, | |
9dbd164d | 36351 | + sizeof(uint64_t)); |
7f207e10 AM |
36352 | +} |
36353 | + | |
36354 | +union au_rdu_ent_ul { | |
36355 | + struct au_rdu_ent __user *e; | |
9dbd164d | 36356 | + uint64_t ul; |
7f207e10 AM |
36357 | +}; |
36358 | + | |
36359 | +enum { | |
36360 | + AufsCtlRduV_SZ, | |
36361 | + AufsCtlRduV_End | |
36362 | +}; | |
36363 | + | |
36364 | +struct aufs_rdu { | |
36365 | + /* input */ | |
36366 | + union { | |
9dbd164d AM |
36367 | + uint64_t sz; /* AuCtl_RDU */ |
36368 | + uint64_t nent; /* AuCtl_RDU_INO */ | |
7f207e10 AM |
36369 | + }; |
36370 | + union au_rdu_ent_ul ent; | |
9dbd164d | 36371 | + uint16_t verify[AufsCtlRduV_End]; |
7f207e10 AM |
36372 | + |
36373 | + /* input/output */ | |
9dbd164d | 36374 | + uint32_t blk; |
7f207e10 AM |
36375 | + |
36376 | + /* output */ | |
36377 | + union au_rdu_ent_ul tail; | |
36378 | + /* number of entries which were added in a single call */ | |
9dbd164d AM |
36379 | + uint64_t rent; |
36380 | + uint8_t full; | |
36381 | + uint8_t shwh; | |
7f207e10 AM |
36382 | + |
36383 | + struct au_rdu_cookie cookie; | |
36384 | +} __aligned(8); | |
36385 | + | |
1e00d052 AM |
36386 | +/* ---------------------------------------------------------------------- */ |
36387 | + | |
36388 | +struct aufs_wbr_fd { | |
9dbd164d AM |
36389 | + uint32_t oflags; |
36390 | + int16_t brid; | |
1e00d052 AM |
36391 | +} __aligned(8); |
36392 | + | |
36393 | +/* ---------------------------------------------------------------------- */ | |
36394 | + | |
027c5e7a | 36395 | +struct aufs_ibusy { |
9dbd164d AM |
36396 | + uint64_t ino, h_ino; |
36397 | + int16_t bindex; | |
027c5e7a AM |
36398 | +} __aligned(8); |
36399 | + | |
1e00d052 AM |
36400 | +/* ---------------------------------------------------------------------- */ |
36401 | + | |
392086de AM |
36402 | +/* error code for move-down */ |
36403 | +/* the actual message strings are implemented in aufs-util.git */ | |
36404 | +enum { | |
36405 | + EAU_MVDOWN_OPAQUE = 1, | |
36406 | + EAU_MVDOWN_WHITEOUT, | |
36407 | + EAU_MVDOWN_UPPER, | |
36408 | + EAU_MVDOWN_BOTTOM, | |
36409 | + EAU_MVDOWN_NOUPPER, | |
36410 | + EAU_MVDOWN_NOLOWERBR, | |
36411 | + EAU_Last | |
36412 | +}; | |
36413 | + | |
c2b27bf2 | 36414 | +/* flags for move-down */ |
392086de AM |
36415 | +#define AUFS_MVDOWN_DMSG 1 |
36416 | +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */ | |
36417 | +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */ | |
36418 | +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */ | |
36419 | +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */ | |
36420 | +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */ | |
36421 | +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */ | |
36422 | +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */ | |
36423 | +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */ | |
076b876e AM |
36424 | +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */ |
36425 | +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */ | |
36426 | +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */ | |
36427 | +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */ | |
c2b27bf2 | 36428 | + |
076b876e | 36429 | +/* index for move-down */ |
392086de AM |
36430 | +enum { |
36431 | + AUFS_MVDOWN_UPPER, | |
36432 | + AUFS_MVDOWN_LOWER, | |
36433 | + AUFS_MVDOWN_NARRAY | |
36434 | +}; | |
36435 | + | |
076b876e AM |
36436 | +/* |
36437 | + * additional info of move-down | |
36438 | + * number of free blocks and inodes. | |
36439 | + * subset of struct kstatfs, but smaller and always 64bit. | |
36440 | + */ | |
36441 | +struct aufs_stfs { | |
36442 | + uint64_t f_blocks; | |
36443 | + uint64_t f_bavail; | |
36444 | + uint64_t f_files; | |
36445 | + uint64_t f_ffree; | |
36446 | +}; | |
36447 | + | |
36448 | +struct aufs_stbr { | |
36449 | + int16_t brid; /* optional input */ | |
36450 | + int16_t bindex; /* output */ | |
36451 | + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */ | |
36452 | +} __aligned(8); | |
36453 | + | |
c2b27bf2 | 36454 | +struct aufs_mvdown { |
076b876e AM |
36455 | + uint32_t flags; /* input/output */ |
36456 | + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */ | |
36457 | + int8_t au_errno; /* output */ | |
36458 | +} __aligned(8); | |
36459 | + | |
36460 | +/* ---------------------------------------------------------------------- */ | |
36461 | + | |
36462 | +union aufs_brinfo { | |
36463 | + /* PATH_MAX may differ between kernel-space and user-space */ | |
36464 | + char _spacer[4096]; | |
392086de | 36465 | + struct { |
076b876e AM |
36466 | + int16_t id; |
36467 | + int perm; | |
36468 | + char path[0]; | |
36469 | + }; | |
c2b27bf2 AM |
36470 | +} __aligned(8); |
36471 | + | |
36472 | +/* ---------------------------------------------------------------------- */ | |
36473 | + | |
7f207e10 AM |
36474 | +#define AuCtlType 'A' |
36475 | +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu) | |
36476 | +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu) | |
1e00d052 AM |
36477 | +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \ |
36478 | + struct aufs_wbr_fd) | |
027c5e7a | 36479 | +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy) |
392086de AM |
36480 | +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \ |
36481 | + struct aufs_mvdown) | |
076b876e AM |
36482 | +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo) |
36483 | +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int) | |
7f207e10 AM |
36484 | + |
36485 | +#endif /* __AUFS_TYPE_H__ */ | |
a2654f78 | 36486 | aufs4.x-rcN loopback patch |
5527c038 JR |
36487 | |
36488 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c | |
521ced18 | 36489 | index cf39138..29b33b2 100644 |
5527c038 JR |
36490 | --- a/drivers/block/loop.c |
36491 | +++ b/drivers/block/loop.c | |
e2f27e51 | 36492 | @@ -551,7 +551,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) |
5527c038 JR |
36493 | } |
36494 | ||
36495 | struct switch_request { | |
36496 | - struct file *file; | |
36497 | + struct file *file, *virt_file; | |
36498 | struct completion wait; | |
36499 | }; | |
36500 | ||
e2f27e51 | 36501 | @@ -577,6 +577,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) |
5527c038 JR |
36502 | mapping = file->f_mapping; |
36503 | mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); | |
36504 | lo->lo_backing_file = file; | |
36505 | + lo->lo_backing_virt_file = p->virt_file; | |
36506 | lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ? | |
36507 | mapping->host->i_bdev->bd_block_size : PAGE_SIZE; | |
36508 | lo->old_gfp_mask = mapping_gfp_mask(mapping); | |
e2f27e51 | 36509 | @@ -589,11 +590,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) |
5527c038 JR |
36510 | * First it needs to flush existing IO, it does this by sending a magic |
36511 | * BIO down the pipe. The completion of this BIO does the actual switch. | |
36512 | */ | |
36513 | -static int loop_switch(struct loop_device *lo, struct file *file) | |
36514 | +static int loop_switch(struct loop_device *lo, struct file *file, | |
36515 | + struct file *virt_file) | |
36516 | { | |
36517 | struct switch_request w; | |
36518 | ||
36519 | w.file = file; | |
36520 | + w.virt_file = virt_file; | |
36521 | ||
36522 | /* freeze queue and wait for completion of scheduled requests */ | |
36523 | blk_mq_freeze_queue(lo->lo_queue); | |
e2f27e51 | 36524 | @@ -612,7 +615,16 @@ static int loop_switch(struct loop_device *lo, struct file *file) |
5527c038 JR |
36525 | */ |
36526 | static int loop_flush(struct loop_device *lo) | |
36527 | { | |
36528 | - return loop_switch(lo, NULL); | |
36529 | + return loop_switch(lo, NULL, NULL); | |
36530 | +} | |
36531 | + | |
36532 | +static struct file *loop_real_file(struct file *file) | |
36533 | +{ | |
36534 | + struct file *f = NULL; | |
36535 | + | |
36536 | + if (file->f_path.dentry->d_sb->s_op->real_loop) | |
36537 | + f = file->f_path.dentry->d_sb->s_op->real_loop(file); | |
36538 | + return f; | |
36539 | } | |
36540 | ||
c2c0f25c | 36541 | static void loop_reread_partitions(struct loop_device *lo, |
e2f27e51 | 36542 | @@ -649,6 +661,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
36543 | unsigned int arg) |
36544 | { | |
36545 | struct file *file, *old_file; | |
36546 | + struct file *f, *virt_file = NULL, *old_virt_file; | |
36547 | struct inode *inode; | |
36548 | int error; | |
36549 | ||
e2f27e51 | 36550 | @@ -665,9 +678,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
36551 | file = fget(arg); |
36552 | if (!file) | |
36553 | goto out; | |
36554 | + f = loop_real_file(file); | |
36555 | + if (f) { | |
36556 | + virt_file = file; | |
36557 | + file = f; | |
36558 | + get_file(file); | |
36559 | + } | |
36560 | ||
36561 | inode = file->f_mapping->host; | |
36562 | old_file = lo->lo_backing_file; | |
36563 | + old_virt_file = lo->lo_backing_virt_file; | |
36564 | ||
36565 | error = -EINVAL; | |
36566 | ||
e2f27e51 | 36567 | @@ -679,17 +699,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
36568 | goto out_putf; |
36569 | ||
36570 | /* and ... switch */ | |
36571 | - error = loop_switch(lo, file); | |
36572 | + error = loop_switch(lo, file, virt_file); | |
36573 | if (error) | |
36574 | goto out_putf; | |
36575 | ||
36576 | fput(old_file); | |
36577 | + if (old_virt_file) | |
36578 | + fput(old_virt_file); | |
36579 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) | |
c2c0f25c | 36580 | loop_reread_partitions(lo, bdev); |
5527c038 JR |
36581 | return 0; |
36582 | ||
36583 | out_putf: | |
36584 | fput(file); | |
36585 | + if (virt_file) | |
36586 | + fput(virt_file); | |
36587 | out: | |
36588 | return error; | |
36589 | } | |
e2f27e51 | 36590 | @@ -876,7 +900,7 @@ static int loop_prepare_queue(struct loop_device *lo) |
5527c038 JR |
36591 | static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
36592 | struct block_device *bdev, unsigned int arg) | |
36593 | { | |
36594 | - struct file *file, *f; | |
36595 | + struct file *file, *f, *virt_file = NULL; | |
36596 | struct inode *inode; | |
36597 | struct address_space *mapping; | |
36598 | unsigned lo_blocksize; | |
e2f27e51 | 36599 | @@ -891,6 +915,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
36600 | file = fget(arg); |
36601 | if (!file) | |
36602 | goto out; | |
36603 | + f = loop_real_file(file); | |
36604 | + if (f) { | |
36605 | + virt_file = file; | |
36606 | + file = f; | |
36607 | + get_file(file); | |
36608 | + } | |
36609 | ||
36610 | error = -EBUSY; | |
36611 | if (lo->lo_state != Lo_unbound) | |
e2f27e51 | 36612 | @@ -943,6 +973,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
36613 | lo->lo_device = bdev; |
36614 | lo->lo_flags = lo_flags; | |
36615 | lo->lo_backing_file = file; | |
36616 | + lo->lo_backing_virt_file = virt_file; | |
36617 | lo->transfer = NULL; | |
36618 | lo->ioctl = NULL; | |
36619 | lo->lo_sizelimit = 0; | |
e2f27e51 | 36620 | @@ -975,6 +1006,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
36621 | |
36622 | out_putf: | |
36623 | fput(file); | |
36624 | + if (virt_file) | |
36625 | + fput(virt_file); | |
36626 | out: | |
36627 | /* This is safe: open() is still holding a reference. */ | |
36628 | module_put(THIS_MODULE); | |
a2654f78 | 36629 | @@ -1021,6 +1054,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, |
5527c038 JR |
36630 | static int loop_clr_fd(struct loop_device *lo) |
36631 | { | |
36632 | struct file *filp = lo->lo_backing_file; | |
36633 | + struct file *virt_filp = lo->lo_backing_virt_file; | |
36634 | gfp_t gfp = lo->old_gfp_mask; | |
36635 | struct block_device *bdev = lo->lo_device; | |
36636 | ||
e2f27e51 | 36637 | @@ -1052,6 +1086,7 @@ static int loop_clr_fd(struct loop_device *lo) |
5527c038 JR |
36638 | spin_lock_irq(&lo->lo_lock); |
36639 | lo->lo_state = Lo_rundown; | |
36640 | lo->lo_backing_file = NULL; | |
36641 | + lo->lo_backing_virt_file = NULL; | |
36642 | spin_unlock_irq(&lo->lo_lock); | |
36643 | ||
36644 | loop_release_xfer(lo); | |
e2f27e51 | 36645 | @@ -1096,6 +1131,8 @@ static int loop_clr_fd(struct loop_device *lo) |
5527c038 JR |
36646 | * bd_mutex which is usually taken before lo_ctl_mutex. |
36647 | */ | |
36648 | fput(filp); | |
36649 | + if (virt_filp) | |
36650 | + fput(virt_filp); | |
36651 | return 0; | |
36652 | } | |
36653 | ||
36654 | diff --git a/drivers/block/loop.h b/drivers/block/loop.h | |
be52b249 | 36655 | index fb2237c..c3888c5 100644 |
5527c038 JR |
36656 | --- a/drivers/block/loop.h |
36657 | +++ b/drivers/block/loop.h | |
36658 | @@ -46,7 +46,7 @@ struct loop_device { | |
36659 | int (*ioctl)(struct loop_device *, int cmd, | |
36660 | unsigned long arg); | |
36661 | ||
36662 | - struct file * lo_backing_file; | |
36663 | + struct file * lo_backing_file, *lo_backing_virt_file; | |
36664 | struct block_device *lo_device; | |
36665 | unsigned lo_blocksize; | |
36666 | void *key_data; | |
36667 | diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c | |
521ced18 | 36668 | index 7e03507..f31af1d 100644 |
5527c038 JR |
36669 | --- a/fs/aufs/f_op.c |
36670 | +++ b/fs/aufs/f_op.c | |
521ced18 | 36671 | @@ -360,7 +360,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
5527c038 JR |
36672 | if (IS_ERR(h_file)) |
36673 | goto out; | |
36674 | ||
36675 | - if (au_test_loopback_kthread()) { | |
36676 | + if (0 && au_test_loopback_kthread()) { | |
36677 | au_warn_loopback(h_file->f_path.dentry->d_sb); | |
36678 | if (file->f_mapping != h_file->f_mapping) { | |
36679 | file->f_mapping = h_file->f_mapping; | |
36680 | diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c | |
a2654f78 | 36681 | index 61e9197..9910bea 100644 |
5527c038 JR |
36682 | --- a/fs/aufs/loop.c |
36683 | +++ b/fs/aufs/loop.c | |
e2f27e51 | 36684 | @@ -132,3 +132,19 @@ void au_loopback_fin(void) |
79b8bda9 | 36685 | symbol_put(loop_backing_file); |
f0c0a007 | 36686 | au_delayed_kfree(au_warn_loopback_array); |
5527c038 JR |
36687 | } |
36688 | + | |
36689 | +/* ---------------------------------------------------------------------- */ | |
36690 | + | |
36691 | +/* support the loopback block device insude aufs */ | |
36692 | + | |
36693 | +struct file *aufs_real_loop(struct file *file) | |
36694 | +{ | |
36695 | + struct file *f; | |
36696 | + | |
36697 | + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb)); | |
36698 | + fi_read_lock(file); | |
36699 | + f = au_hf_top(file); | |
36700 | + fi_read_unlock(file); | |
36701 | + AuDebugOn(!f); | |
36702 | + return f; | |
36703 | +} | |
36704 | diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h | |
a2654f78 | 36705 | index e2df495..36e5052 100644 |
5527c038 JR |
36706 | --- a/fs/aufs/loop.h |
36707 | +++ b/fs/aufs/loop.h | |
a2654f78 | 36708 | @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb); |
5527c038 JR |
36709 | |
36710 | int au_loopback_init(void); | |
36711 | void au_loopback_fin(void); | |
36712 | + | |
36713 | +struct file *aufs_real_loop(struct file *file); | |
36714 | #else | |
36715 | +AuStub(struct file *, loop_backing_file, return NULL) | |
36716 | + | |
36717 | AuStubInt0(au_test_loopback_overlap, struct super_block *sb, | |
36718 | struct dentry *h_adding) | |
36719 | AuStubInt0(au_test_loopback_kthread, void) | |
a2654f78 | 36720 | @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
5527c038 JR |
36721 | |
36722 | AuStubInt0(au_loopback_init, void) | |
36723 | AuStubVoid(au_loopback_fin, void) | |
36724 | + | |
36725 | +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file) | |
36726 | #endif /* BLK_DEV_LOOP */ | |
36727 | ||
36728 | #endif /* __KERNEL__ */ | |
36729 | diff --git a/fs/aufs/super.c b/fs/aufs/super.c | |
a2654f78 | 36730 | index 0e9bbc3..b90d52f 100644 |
5527c038 JR |
36731 | --- a/fs/aufs/super.c |
36732 | +++ b/fs/aufs/super.c | |
a2654f78 | 36733 | @@ -837,7 +837,10 @@ static const struct super_operations aufs_sop = { |
5527c038 JR |
36734 | .statfs = aufs_statfs, |
36735 | .put_super = aufs_put_super, | |
36736 | .sync_fs = aufs_sync_fs, | |
36737 | - .remount_fs = aufs_remount_fs | |
36738 | + .remount_fs = aufs_remount_fs, | |
36739 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
36740 | + .real_loop = aufs_real_loop | |
36741 | +#endif | |
36742 | }; | |
36743 | ||
36744 | /* ---------------------------------------------------------------------- */ | |
36745 | diff --git a/include/linux/fs.h b/include/linux/fs.h | |
521ced18 | 36746 | index 3668627..2cbc8fe 100644 |
5527c038 JR |
36747 | --- a/include/linux/fs.h |
36748 | +++ b/include/linux/fs.h | |
521ced18 | 36749 | @@ -1810,6 +1810,10 @@ struct super_operations { |
5527c038 JR |
36750 | struct shrink_control *); |
36751 | long (*free_cached_objects)(struct super_block *, | |
36752 | struct shrink_control *); | |
36753 | +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE) | |
36754 | + /* and aufs */ | |
36755 | + struct file *(*real_loop)(struct file *); | |
36756 | +#endif | |
36757 | }; | |
36758 | ||
36759 | /* |