]>
Commit | Line | Data |
---|---|---|
5527c038 | 1 | aufs4.x-rcN kbuild patch |
7f207e10 AM |
2 | |
3 | diff --git a/fs/Kconfig b/fs/Kconfig | |
5527c038 | 4 | index 011f433..b1083f6 100644 |
7f207e10 AM |
5 | --- a/fs/Kconfig |
6 | +++ b/fs/Kconfig | |
5527c038 JR |
7 | @@ -218,6 +218,7 @@ source "fs/pstore/Kconfig" |
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 | |
5527c038 | 16 | index cb92fd4..8c2df12 100644 |
7f207e10 AM |
17 | --- a/fs/Makefile |
18 | +++ b/fs/Makefile | |
5527c038 | 19 | @@ -127,3 +127,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 |
5527c038 | 25 | index 1a0006a..ddad01a 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 |
5527c038 | 36 | aufs4.x-rcN base patch |
7f207e10 | 37 | |
c1595e42 | 38 | diff --git a/MAINTAINERS b/MAINTAINERS |
5527c038 | 39 | index d8afd29..feac5ea 100644 |
c1595e42 JR |
40 | --- a/MAINTAINERS |
41 | +++ b/MAINTAINERS | |
5527c038 | 42 | @@ -1880,6 +1880,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 |
5527c038 | 63 | index d7173cb..0160952 100644 |
392086de AM |
64 | --- a/drivers/block/loop.c |
65 | +++ b/drivers/block/loop.c | |
5527c038 | 66 | @@ -540,6 +540,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 | +} | |
86 | +EXPORT_SYMBOL(loop_backing_file); | |
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 |
5527c038 | 92 | index 37b5afd..bc261e2 100644 |
c1595e42 JR |
93 | --- a/fs/dcache.c |
94 | +++ b/fs/dcache.c | |
5527c038 | 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 | { | |
5527c038 JR |
104 | diff --git a/fs/read_write.c b/fs/read_write.c |
105 | index 819ef3f..fd0414e 100644 | |
106 | --- a/fs/read_write.c | |
107 | +++ b/fs/read_write.c | |
108 | @@ -494,6 +494,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count, | |
109 | } | |
110 | EXPORT_SYMBOL(__vfs_write); | |
111 | ||
112 | +vfs_readf_t vfs_readf(struct file *file) | |
113 | +{ | |
114 | + const struct file_operations *fop = file->f_op; | |
115 | + | |
116 | + if (fop->read) | |
117 | + return fop->read; | |
118 | + if (fop->read_iter) | |
119 | + return new_sync_read; | |
120 | + return ERR_PTR(-ENOSYS); | |
121 | +} | |
122 | + | |
123 | +vfs_writef_t vfs_writef(struct file *file) | |
124 | +{ | |
125 | + const struct file_operations *fop = file->f_op; | |
126 | + | |
127 | + if (fop->write) | |
128 | + return fop->write; | |
129 | + if (fop->write_iter) | |
130 | + return new_sync_write; | |
131 | + return ERR_PTR(-ENOSYS); | |
132 | +} | |
133 | + | |
134 | ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos) | |
135 | { | |
136 | mm_segment_t old_fs; | |
7f207e10 | 137 | diff --git a/fs/splice.c b/fs/splice.c |
5527c038 | 138 | index bfe62ae..fa5eee5 100644 |
7f207e10 AM |
139 | --- a/fs/splice.c |
140 | +++ b/fs/splice.c | |
5527c038 | 141 | @@ -1101,8 +1101,8 @@ EXPORT_SYMBOL(generic_splice_sendpage); |
7f207e10 AM |
142 | /* |
143 | * Attempt to initiate a splice from pipe to file. | |
144 | */ | |
145 | -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
146 | - loff_t *ppos, size_t len, unsigned int flags) | |
147 | +long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
148 | + loff_t *ppos, size_t len, unsigned int flags) | |
149 | { | |
150 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, | |
151 | loff_t *, size_t, unsigned int); | |
5527c038 | 152 | @@ -1118,9 +1118,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
7f207e10 AM |
153 | /* |
154 | * Attempt to initiate a splice from a file to a pipe. | |
155 | */ | |
156 | -static long do_splice_to(struct file *in, loff_t *ppos, | |
157 | - struct pipe_inode_info *pipe, size_t len, | |
158 | - unsigned int flags) | |
159 | +long do_splice_to(struct file *in, loff_t *ppos, | |
160 | + struct pipe_inode_info *pipe, size_t len, | |
161 | + unsigned int flags) | |
162 | { | |
163 | ssize_t (*splice_read)(struct file *, loff_t *, | |
164 | struct pipe_inode_info *, size_t, unsigned int); | |
b912730e AM |
165 | diff --git a/include/linux/file.h b/include/linux/file.h |
166 | index f87d308..9a290b3 100644 | |
167 | --- a/include/linux/file.h | |
168 | +++ b/include/linux/file.h | |
169 | @@ -19,6 +19,7 @@ struct dentry; | |
170 | struct path; | |
171 | extern struct file *alloc_file(struct path *, fmode_t mode, | |
172 | const struct file_operations *fop); | |
173 | +extern struct file *get_empty_filp(void); | |
174 | ||
175 | static inline void fput_light(struct file *file, int fput_needed) | |
176 | { | |
5527c038 JR |
177 | diff --git a/include/linux/fs.h b/include/linux/fs.h |
178 | index 35ec87e..3229f97 100644 | |
179 | --- a/include/linux/fs.h | |
180 | +++ b/include/linux/fs.h | |
181 | @@ -1649,6 +1649,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, | |
182 | struct iovec *fast_pointer, | |
183 | struct iovec **ret_pointer); | |
184 | ||
185 | +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *); | |
186 | +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t, | |
187 | + loff_t *); | |
188 | +vfs_readf_t vfs_readf(struct file *file); | |
189 | +vfs_writef_t vfs_writef(struct file *file); | |
190 | + | |
191 | extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *); | |
192 | extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *); | |
193 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); | |
1e00d052 | 194 | diff --git a/include/linux/splice.h b/include/linux/splice.h |
076b876e | 195 | index da2751d..2e0fca6 100644 |
1e00d052 AM |
196 | --- a/include/linux/splice.h |
197 | +++ b/include/linux/splice.h | |
076b876e | 198 | @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *); |
4b3da204 AM |
199 | extern void spd_release_page(struct splice_pipe_desc *, unsigned int); |
200 | ||
201 | extern const struct pipe_buf_operations page_cache_pipe_buf_ops; | |
1e00d052 AM |
202 | + |
203 | +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
204 | + loff_t *ppos, size_t len, unsigned int flags); | |
205 | +extern long do_splice_to(struct file *in, loff_t *ppos, | |
206 | + struct pipe_inode_info *pipe, size_t len, | |
207 | + unsigned int flags); | |
208 | #endif | |
5527c038 | 209 | aufs4.x-rcN mmap patch |
fb47a38f JR |
210 | |
211 | diff --git a/fs/buffer.c b/fs/buffer.c | |
5527c038 | 212 | index c7a5602..8c50a22 100644 |
fb47a38f JR |
213 | --- a/fs/buffer.c |
214 | +++ b/fs/buffer.c | |
c1595e42 | 215 | @@ -2450,7 +2450,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, |
fb47a38f JR |
216 | * Update file times before taking page lock. We may end up failing the |
217 | * fault so this update may be superfluous but who really cares... | |
218 | */ | |
219 | - file_update_time(vma->vm_file); | |
220 | + vma_file_update_time(vma); | |
221 | ||
222 | ret = __block_page_mkwrite(vma, vmf, get_block); | |
223 | sb_end_pagefault(sb); | |
c1595e42 | 224 | diff --git a/fs/proc/base.c b/fs/proc/base.c |
5527c038 | 225 | index 093ca14..fc1ac03 100644 |
c1595e42 JR |
226 | --- a/fs/proc/base.c |
227 | +++ b/fs/proc/base.c | |
5527c038 | 228 | @@ -1744,7 +1744,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path) |
c1595e42 JR |
229 | down_read(&mm->mmap_sem); |
230 | vma = find_exact_vma(mm, vm_start, vm_end); | |
231 | if (vma && vma->vm_file) { | |
232 | - *path = vma->vm_file->f_path; | |
233 | + *path = vma_pr_or_file(vma)->f_path; | |
234 | path_get(path); | |
235 | rc = 0; | |
236 | } | |
fb47a38f | 237 | diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c |
076b876e | 238 | index d4a3574..1397181 100644 |
fb47a38f JR |
239 | --- a/fs/proc/nommu.c |
240 | +++ b/fs/proc/nommu.c | |
076b876e | 241 | @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region) |
fb47a38f JR |
242 | file = region->vm_file; |
243 | ||
244 | if (file) { | |
245 | - struct inode *inode = file_inode(region->vm_file); | |
246 | + struct inode *inode; | |
076b876e | 247 | + |
fb47a38f JR |
248 | + file = vmr_pr_or_file(region); |
249 | + inode = file_inode(file); | |
250 | dev = inode->i_sb->s_dev; | |
251 | ino = inode->i_ino; | |
252 | } | |
253 | diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c | |
7e9cd9fe | 254 | index 6dee68d..9afa35d 100644 |
fb47a38f JR |
255 | --- a/fs/proc/task_mmu.c |
256 | +++ b/fs/proc/task_mmu.c | |
7e9cd9fe | 257 | @@ -279,7 +279,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) |
fb47a38f JR |
258 | const char *name = NULL; |
259 | ||
260 | if (file) { | |
261 | - struct inode *inode = file_inode(vma->vm_file); | |
262 | + struct inode *inode; | |
076b876e | 263 | + |
fb47a38f JR |
264 | + file = vma_pr_or_file(vma); |
265 | + inode = file_inode(file); | |
266 | dev = inode->i_sb->s_dev; | |
267 | ino = inode->i_ino; | |
268 | pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; | |
7e9cd9fe | 269 | @@ -1479,7 +1482,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid) |
076b876e AM |
270 | struct proc_maps_private *proc_priv = &numa_priv->proc_maps; |
271 | struct vm_area_struct *vma = v; | |
272 | struct numa_maps *md = &numa_priv->md; | |
273 | - struct file *file = vma->vm_file; | |
274 | + struct file *file = vma_pr_or_file(vma); | |
076b876e | 275 | struct mm_struct *mm = vma->vm_mm; |
7e9cd9fe AM |
276 | struct mm_walk walk = { |
277 | .hugetlb_entry = gather_hugetlb_stats, | |
fb47a38f | 278 | diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c |
b912730e | 279 | index 599ec2e..1740207 100644 |
fb47a38f JR |
280 | --- a/fs/proc/task_nommu.c |
281 | +++ b/fs/proc/task_nommu.c | |
c1595e42 | 282 | @@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma, |
fb47a38f JR |
283 | file = vma->vm_file; |
284 | ||
285 | if (file) { | |
286 | - struct inode *inode = file_inode(vma->vm_file); | |
287 | + struct inode *inode; | |
076b876e | 288 | + |
b912730e | 289 | + file = vma_pr_or_file(vma); |
fb47a38f JR |
290 | + inode = file_inode(file); |
291 | dev = inode->i_sb->s_dev; | |
292 | ino = inode->i_ino; | |
293 | pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT; | |
294 | diff --git a/include/linux/mm.h b/include/linux/mm.h | |
5527c038 | 295 | index 0755b9f..2ee5500 100644 |
fb47a38f JR |
296 | --- a/include/linux/mm.h |
297 | +++ b/include/linux/mm.h | |
5527c038 | 298 | @@ -1172,6 +1172,28 @@ static inline int fixup_user_fault(struct task_struct *tsk, |
fb47a38f JR |
299 | } |
300 | #endif | |
301 | ||
076b876e AM |
302 | +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int); |
303 | +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[], | |
304 | + int); | |
305 | +extern void vma_do_get_file(struct vm_area_struct *, const char[], int); | |
306 | +extern void vma_do_fput(struct vm_area_struct *, const char[], int); | |
fb47a38f | 307 | + |
fb47a38f JR |
308 | +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \ |
309 | + __LINE__) | |
310 | +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \ | |
311 | + __LINE__) | |
312 | +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__) | |
313 | +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__) | |
b912730e AM |
314 | + |
315 | +#ifndef CONFIG_MMU | |
076b876e AM |
316 | +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int); |
317 | +extern void vmr_do_fput(struct vm_region *, const char[], int); | |
318 | + | |
319 | +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \ | |
320 | + __LINE__) | |
321 | +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__) | |
b912730e | 322 | +#endif /* !CONFIG_MMU */ |
fb47a38f JR |
323 | + |
324 | extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write); | |
325 | extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, | |
326 | void *buf, int len, int write); | |
327 | diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h | |
5527c038 | 328 | index 8d37e26..ce89d4c 100644 |
fb47a38f JR |
329 | --- a/include/linux/mm_types.h |
330 | +++ b/include/linux/mm_types.h | |
7e9cd9fe | 331 | @@ -241,6 +241,7 @@ struct vm_region { |
fb47a38f JR |
332 | unsigned long vm_top; /* region allocated to here */ |
333 | unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */ | |
334 | struct file *vm_file; /* the backing file or NULL */ | |
335 | + struct file *vm_prfile; /* the virtual backing file or NULL */ | |
336 | ||
337 | int vm_usage; /* region usage count (access under nommu_region_sem) */ | |
338 | bool vm_icache_flushed : 1; /* true if the icache has been flushed for | |
7e9cd9fe | 339 | @@ -305,6 +306,7 @@ struct vm_area_struct { |
fb47a38f JR |
340 | unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE |
341 | units, *not* PAGE_CACHE_SIZE */ | |
342 | struct file * vm_file; /* File we map to (can be NULL). */ | |
343 | + struct file *vm_prfile; /* shadow of vm_file */ | |
344 | void * vm_private_data; /* was vm_pte (shared mem) */ | |
345 | ||
346 | #ifndef CONFIG_MMU | |
347 | diff --git a/kernel/fork.c b/kernel/fork.c | |
5527c038 | 348 | index 03c1eaa..7e215ba 100644 |
fb47a38f JR |
349 | --- a/kernel/fork.c |
350 | +++ b/kernel/fork.c | |
5527c038 | 351 | @@ -456,7 +456,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) |
fb47a38f JR |
352 | struct inode *inode = file_inode(file); |
353 | struct address_space *mapping = file->f_mapping; | |
354 | ||
355 | - get_file(file); | |
356 | + vma_get_file(tmp); | |
357 | if (tmp->vm_flags & VM_DENYWRITE) | |
358 | atomic_dec(&inode->i_writecount); | |
2000de60 | 359 | i_mmap_lock_write(mapping); |
076b876e | 360 | diff --git a/mm/Makefile b/mm/Makefile |
5527c038 | 361 | index 98c4eae..3f0c9b9 100644 |
076b876e AM |
362 | --- a/mm/Makefile |
363 | +++ b/mm/Makefile | |
7e9cd9fe | 364 | @@ -21,7 +21,7 @@ obj-y := filemap.o mempool.o oom_kill.o \ |
076b876e | 365 | mm_init.o mmu_context.o percpu.o slab_common.o \ |
c1595e42 | 366 | compaction.o vmacache.o \ |
076b876e | 367 | interval_tree.o list_lru.o workingset.o \ |
7e9cd9fe AM |
368 | - debug.o $(mmu-y) |
369 | + prfile.o debug.o $(mmu-y) | |
076b876e AM |
370 | |
371 | obj-y += init-mm.o | |
372 | ||
fb47a38f | 373 | diff --git a/mm/filemap.c b/mm/filemap.c |
5527c038 | 374 | index 6bf5e42..a863d0f 100644 |
fb47a38f JR |
375 | --- a/mm/filemap.c |
376 | +++ b/mm/filemap.c | |
5527c038 | 377 | @@ -2062,7 +2062,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) |
fb47a38f JR |
378 | int ret = VM_FAULT_LOCKED; |
379 | ||
380 | sb_start_pagefault(inode->i_sb); | |
381 | - file_update_time(vma->vm_file); | |
382 | + vma_file_update_time(vma); | |
383 | lock_page(page); | |
384 | if (page->mapping != inode->i_mapping) { | |
385 | unlock_page(page); | |
fb47a38f | 386 | diff --git a/mm/madvise.c b/mm/madvise.c |
7e9cd9fe | 387 | index d551475..1ebf71b 100644 |
fb47a38f JR |
388 | --- a/mm/madvise.c |
389 | +++ b/mm/madvise.c | |
7e9cd9fe | 390 | @@ -320,12 +320,12 @@ static long madvise_remove(struct vm_area_struct *vma, |
fb47a38f JR |
391 | * vma's reference to the file) can go away as soon as we drop |
392 | * mmap_sem. | |
393 | */ | |
394 | - get_file(f); | |
395 | + vma_get_file(vma); | |
396 | up_read(¤t->mm->mmap_sem); | |
03673fb0 | 397 | error = vfs_fallocate(f, |
fb47a38f JR |
398 | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, |
399 | offset, end - start); | |
400 | - fput(f); | |
401 | + vma_fput(vma); | |
402 | down_read(¤t->mm->mmap_sem); | |
403 | return error; | |
404 | } | |
405 | diff --git a/mm/memory.c b/mm/memory.c | |
5527c038 | 406 | index 22e037e..62096a2 100644 |
fb47a38f JR |
407 | --- a/mm/memory.c |
408 | +++ b/mm/memory.c | |
5527c038 | 409 | @@ -2034,7 +2034,7 @@ static inline int wp_page_reuse(struct mm_struct *mm, |
fb47a38f | 410 | } |
7e9cd9fe | 411 | |
b912730e AM |
412 | if (!page_mkwrite) |
413 | - file_update_time(vma->vm_file); | |
414 | + vma_file_update_time(vma); | |
415 | } | |
416 | ||
417 | return VM_FAULT_WRITE; | |
fb47a38f | 418 | diff --git a/mm/mmap.c b/mm/mmap.c |
5527c038 | 419 | index bb50cac..1ab5e596 100644 |
fb47a38f JR |
420 | --- a/mm/mmap.c |
421 | +++ b/mm/mmap.c | |
7e9cd9fe | 422 | @@ -274,7 +274,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma) |
fb47a38f JR |
423 | if (vma->vm_ops && vma->vm_ops->close) |
424 | vma->vm_ops->close(vma); | |
425 | if (vma->vm_file) | |
426 | - fput(vma->vm_file); | |
427 | + vma_fput(vma); | |
428 | mpol_put(vma_policy(vma)); | |
429 | kmem_cache_free(vm_area_cachep, vma); | |
430 | return next; | |
7e9cd9fe | 431 | @@ -886,7 +886,7 @@ again: remove_next = 1 + (end > next->vm_end); |
fb47a38f JR |
432 | if (remove_next) { |
433 | if (file) { | |
434 | uprobe_munmap(next, next->vm_start, next->vm_end); | |
435 | - fput(file); | |
436 | + vma_fput(vma); | |
437 | } | |
438 | if (next->anon_vma) | |
439 | anon_vma_merge(vma, next); | |
7e9cd9fe | 440 | @@ -1671,8 +1671,8 @@ out: |
35939ee7 JR |
441 | return addr; |
442 | ||
fb47a38f | 443 | unmap_and_free_vma: |
fb47a38f JR |
444 | + vma_fput(vma); |
445 | vma->vm_file = NULL; | |
446 | - fput(file); | |
447 | ||
448 | /* Undo any partial mapping done by a device driver. */ | |
449 | unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); | |
7e9cd9fe | 450 | @@ -2473,7 +2473,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
451 | goto out_free_mpol; |
452 | ||
453 | if (new->vm_file) | |
454 | - get_file(new->vm_file); | |
455 | + vma_get_file(new); | |
456 | ||
457 | if (new->vm_ops && new->vm_ops->open) | |
458 | new->vm_ops->open(new); | |
7e9cd9fe | 459 | @@ -2492,7 +2492,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
460 | if (new->vm_ops && new->vm_ops->close) |
461 | new->vm_ops->close(new); | |
462 | if (new->vm_file) | |
463 | - fput(new->vm_file); | |
464 | + vma_fput(new); | |
465 | unlink_anon_vmas(new); | |
466 | out_free_mpol: | |
467 | mpol_put(vma_policy(new)); | |
7e9cd9fe AM |
468 | @@ -2635,7 +2635,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
469 | struct vm_area_struct *vma; | |
470 | unsigned long populate = 0; | |
471 | unsigned long ret = -EINVAL; | |
472 | - struct file *file; | |
473 | ||
474 | pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. " | |
475 | "See Documentation/vm/remap_file_pages.txt.\n", | |
476 | @@ -2679,10 +2678,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, | |
477 | munlock_vma_pages_range(vma, start, start + size); | |
478 | } | |
479 | ||
480 | - file = get_file(vma->vm_file); | |
481 | + vma_get_file(vma); | |
482 | ret = do_mmap_pgoff(vma->vm_file, start, size, | |
483 | prot, flags, pgoff, &populate); | |
484 | - fput(file); | |
485 | + vma_fput(vma); | |
486 | out: | |
487 | up_write(&mm->mmap_sem); | |
488 | if (populate) | |
5527c038 | 489 | @@ -2949,7 +2948,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, |
fb47a38f JR |
490 | if (anon_vma_clone(new_vma, vma)) |
491 | goto out_free_mempol; | |
492 | if (new_vma->vm_file) | |
493 | - get_file(new_vma->vm_file); | |
494 | + vma_get_file(new_vma); | |
495 | if (new_vma->vm_ops && new_vma->vm_ops->open) | |
496 | new_vma->vm_ops->open(new_vma); | |
497 | vma_link(mm, new_vma, prev, rb_link, rb_parent); | |
498 | diff --git a/mm/msync.c b/mm/msync.c | |
7e9cd9fe | 499 | index bb04d53..5c24c54 100644 |
fb47a38f JR |
500 | --- a/mm/msync.c |
501 | +++ b/mm/msync.c | |
7e9cd9fe | 502 | @@ -84,10 +84,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) |
fb47a38f JR |
503 | start = vma->vm_end; |
504 | if ((flags & MS_SYNC) && file && | |
505 | (vma->vm_flags & VM_SHARED)) { | |
506 | - get_file(file); | |
507 | + vma_get_file(vma); | |
508 | up_read(&mm->mmap_sem); | |
7e9cd9fe | 509 | error = vfs_fsync_range(file, fstart, fend, 1); |
fb47a38f JR |
510 | - fput(file); |
511 | + vma_fput(vma); | |
512 | if (error || start >= end) | |
513 | goto out; | |
514 | down_read(&mm->mmap_sem); | |
515 | diff --git a/mm/nommu.c b/mm/nommu.c | |
5527c038 | 516 | index e544508..dd6f74a 100644 |
fb47a38f JR |
517 | --- a/mm/nommu.c |
518 | +++ b/mm/nommu.c | |
7e9cd9fe | 519 | @@ -693,7 +693,7 @@ static void __put_nommu_region(struct vm_region *region) |
fb47a38f JR |
520 | up_write(&nommu_region_sem); |
521 | ||
522 | if (region->vm_file) | |
523 | - fput(region->vm_file); | |
524 | + vmr_fput(region); | |
525 | ||
526 | /* IO memory and memory shared directly out of the pagecache | |
527 | * from ramfs/tmpfs mustn't be released here */ | |
7e9cd9fe | 528 | @@ -858,7 +858,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) |
fb47a38f JR |
529 | if (vma->vm_ops && vma->vm_ops->close) |
530 | vma->vm_ops->close(vma); | |
531 | if (vma->vm_file) | |
532 | - fput(vma->vm_file); | |
533 | + vma_fput(vma); | |
534 | put_nommu_region(vma->vm_region); | |
535 | kmem_cache_free(vm_area_cachep, vma); | |
536 | } | |
7e9cd9fe | 537 | @@ -1398,7 +1398,7 @@ unsigned long do_mmap_pgoff(struct file *file, |
fb47a38f JR |
538 | goto error_just_free; |
539 | } | |
540 | } | |
541 | - fput(region->vm_file); | |
542 | + vmr_fput(region); | |
543 | kmem_cache_free(vm_region_jar, region); | |
544 | region = pregion; | |
545 | result = start; | |
7e9cd9fe | 546 | @@ -1474,10 +1474,10 @@ error_just_free: |
fb47a38f JR |
547 | up_write(&nommu_region_sem); |
548 | error: | |
549 | if (region->vm_file) | |
550 | - fput(region->vm_file); | |
551 | + vmr_fput(region); | |
552 | kmem_cache_free(vm_region_jar, region); | |
553 | if (vma->vm_file) | |
554 | - fput(vma->vm_file); | |
555 | + vma_fput(vma); | |
556 | kmem_cache_free(vm_area_cachep, vma); | |
557 | kleave(" = %d", ret); | |
558 | return ret; | |
076b876e AM |
559 | diff --git a/mm/prfile.c b/mm/prfile.c |
560 | new file mode 100644 | |
b912730e | 561 | index 0000000..6aa5ab5 |
076b876e AM |
562 | --- /dev/null |
563 | +++ b/mm/prfile.c | |
564 | @@ -0,0 +1,86 @@ | |
565 | +/* | |
566 | + * Mainly for aufs which mmap(2) diffrent file and wants to print different path | |
567 | + * in /proc/PID/maps. | |
568 | + * Call these functions via macros defined in linux/mm.h. | |
569 | + * | |
570 | + * See Documentation/filesystems/aufs/design/06mmap.txt | |
571 | + * | |
572 | + * Copyright (c) 2014 Junjro R. Okajima | |
573 | + * Copyright (c) 2014 Ian Campbell | |
574 | + */ | |
575 | + | |
576 | +#include <linux/mm.h> | |
577 | +#include <linux/file.h> | |
578 | +#include <linux/fs.h> | |
579 | + | |
580 | +/* #define PRFILE_TRACE */ | |
581 | +static inline void prfile_trace(struct file *f, struct file *pr, | |
582 | + const char func[], int line, const char func2[]) | |
583 | +{ | |
584 | +#ifdef PRFILE_TRACE | |
585 | + if (pr) | |
586 | + pr_info("%s:%d: %s, %p\n", func, line, func2, | |
7e9cd9fe | 587 | + f ? (char *)f->f_path.dentry->d_name.name : "(null)"); |
076b876e AM |
588 | +#endif |
589 | +} | |
590 | + | |
076b876e AM |
591 | +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[], |
592 | + int line) | |
593 | +{ | |
594 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
595 | + | |
596 | + prfile_trace(f, pr, func, line, __func__); | |
597 | + file_update_time(f); | |
598 | + if (f && pr) | |
599 | + file_update_time(pr); | |
600 | +} | |
601 | + | |
602 | +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[], | |
603 | + int line) | |
604 | +{ | |
605 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
606 | + | |
607 | + prfile_trace(f, pr, func, line, __func__); | |
608 | + return (f && pr) ? pr : f; | |
609 | +} | |
610 | + | |
611 | +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line) | |
612 | +{ | |
613 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
614 | + | |
615 | + prfile_trace(f, pr, func, line, __func__); | |
616 | + get_file(f); | |
617 | + if (f && pr) | |
618 | + get_file(pr); | |
619 | +} | |
620 | + | |
621 | +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line) | |
622 | +{ | |
623 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
624 | + | |
625 | + prfile_trace(f, pr, func, line, __func__); | |
626 | + fput(f); | |
627 | + if (f && pr) | |
628 | + fput(pr); | |
629 | +} | |
b912730e AM |
630 | + |
631 | +#ifndef CONFIG_MMU | |
076b876e AM |
632 | +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[], |
633 | + int line) | |
634 | +{ | |
635 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
636 | + | |
637 | + prfile_trace(f, pr, func, line, __func__); | |
638 | + return (f && pr) ? pr : f; | |
639 | +} | |
640 | + | |
641 | +void vmr_do_fput(struct vm_region *region, const char func[], int line) | |
642 | +{ | |
643 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
644 | + | |
645 | + prfile_trace(f, pr, func, line, __func__); | |
646 | + fput(f); | |
647 | + if (f && pr) | |
648 | + fput(pr); | |
649 | +} | |
b912730e | 650 | +#endif /* !CONFIG_MMU */ |
5527c038 | 651 | aufs4.x-rcN standalone patch |
7f207e10 | 652 | |
c1595e42 | 653 | diff --git a/fs/dcache.c b/fs/dcache.c |
5527c038 | 654 | index bc261e2..8d7951d 100644 |
c1595e42 JR |
655 | --- a/fs/dcache.c |
656 | +++ b/fs/dcache.c | |
5527c038 | 657 | @@ -1269,6 +1269,7 @@ rename_retry: |
c1595e42 JR |
658 | seq = 1; |
659 | goto again; | |
660 | } | |
661 | +EXPORT_SYMBOL(d_walk); | |
662 | ||
663 | /* | |
664 | * Search for at least 1 mount point in the dentry's subdirs. | |
b912730e | 665 | diff --git a/fs/file_table.c b/fs/file_table.c |
5527c038 | 666 | index 294174d..3cea027 100644 |
b912730e AM |
667 | --- a/fs/file_table.c |
668 | +++ b/fs/file_table.c | |
669 | @@ -147,6 +147,7 @@ over: | |
670 | } | |
671 | return ERR_PTR(-ENFILE); | |
672 | } | |
673 | +EXPORT_SYMBOL(get_empty_filp); | |
674 | ||
675 | /** | |
676 | * alloc_file - allocate and initialize a 'struct file' | |
677 | @@ -308,6 +309,7 @@ void put_filp(struct file *file) | |
678 | file_free(file); | |
679 | } | |
680 | } | |
681 | +EXPORT_SYMBOL(put_filp); | |
682 | ||
683 | void __init files_init(unsigned long mempages) | |
684 | { | |
1e00d052 | 685 | diff --git a/fs/inode.c b/fs/inode.c |
5527c038 | 686 | index ea37cd1..58f5f58 100644 |
1e00d052 AM |
687 | --- a/fs/inode.c |
688 | +++ b/fs/inode.c | |
7e9cd9fe | 689 | @@ -58,6 +58,7 @@ static struct hlist_head *inode_hashtable __read_mostly; |
4b3da204 | 690 | static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); |
2cbb1c4b JR |
691 | |
692 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock); | |
2cbb1c4b | 693 | +EXPORT_SYMBOL(inode_sb_list_lock); |
7f207e10 AM |
694 | |
695 | /* | |
4b3da204 | 696 | * Empty aops. Can be used for the cases where the user does not |
7f207e10 | 697 | diff --git a/fs/namespace.c b/fs/namespace.c |
5527c038 | 698 | index 1b9e111..d45b81b 100644 |
7f207e10 AM |
699 | --- a/fs/namespace.c |
700 | +++ b/fs/namespace.c | |
7e9cd9fe | 701 | @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt) |
c06a8ce3 AM |
702 | mnt_dec_writers(real_mount(mnt)); |
703 | preempt_enable(); | |
704 | } | |
705 | +EXPORT_SYMBOL_GPL(__mnt_drop_write); | |
706 | ||
707 | /** | |
708 | * mnt_drop_write - give up write access to a mount | |
5527c038 | 709 | @@ -1768,6 +1769,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, |
7f207e10 AM |
710 | } |
711 | return 0; | |
712 | } | |
713 | +EXPORT_SYMBOL(iterate_mounts); | |
714 | ||
7eafdf33 | 715 | static void cleanup_group_ids(struct mount *mnt, struct mount *end) |
7f207e10 AM |
716 | { |
717 | diff --git a/fs/notify/group.c b/fs/notify/group.c | |
c1595e42 | 718 | index d16b62c..06ca6bc 100644 |
7f207e10 AM |
719 | --- a/fs/notify/group.c |
720 | +++ b/fs/notify/group.c | |
721 | @@ -22,6 +22,7 @@ | |
722 | #include <linux/srcu.h> | |
723 | #include <linux/rculist.h> | |
724 | #include <linux/wait.h> | |
725 | +#include <linux/module.h> | |
726 | ||
727 | #include <linux/fsnotify_backend.h> | |
728 | #include "fsnotify.h" | |
fb47a38f | 729 | @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group) |
1716fcea AM |
730 | { |
731 | atomic_inc(&group->refcnt); | |
732 | } | |
733 | +EXPORT_SYMBOL(fsnotify_get_group); | |
734 | ||
735 | /* | |
736 | * Drop a reference to a group. Free it if it's through. | |
fb47a38f | 737 | @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group) |
7f207e10 | 738 | if (atomic_dec_and_test(&group->refcnt)) |
1716fcea | 739 | fsnotify_final_destroy_group(group); |
7f207e10 AM |
740 | } |
741 | +EXPORT_SYMBOL(fsnotify_put_group); | |
742 | ||
743 | /* | |
744 | * Create a new fsnotify_group and hold a reference for the group returned. | |
fb47a38f | 745 | @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) |
7f207e10 AM |
746 | |
747 | return group; | |
748 | } | |
749 | +EXPORT_SYMBOL(fsnotify_alloc_group); | |
1716fcea AM |
750 | |
751 | int fsnotify_fasync(int fd, struct file *file, int on) | |
752 | { | |
7f207e10 | 753 | diff --git a/fs/notify/mark.c b/fs/notify/mark.c |
2000de60 | 754 | index 92e48c7..d2c4b68 100644 |
7f207e10 AM |
755 | --- a/fs/notify/mark.c |
756 | +++ b/fs/notify/mark.c | |
392086de | 757 | @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) |
7f207e10 | 758 | mark->free_mark(mark); |
1716fcea | 759 | } |
7f207e10 AM |
760 | } |
761 | +EXPORT_SYMBOL(fsnotify_put_mark); | |
762 | ||
2000de60 JR |
763 | /* Calculate mask of events for a list of marks */ |
764 | u32 fsnotify_recalc_mask(struct hlist_head *head) | |
765 | @@ -202,6 +203,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark, | |
1716fcea AM |
766 | fsnotify_destroy_mark_locked(mark, group); |
767 | mutex_unlock(&group->mark_mutex); | |
7f207e10 AM |
768 | } |
769 | +EXPORT_SYMBOL(fsnotify_destroy_mark); | |
770 | ||
2000de60 JR |
771 | /* |
772 | * Destroy all marks in the given list. The marks must be already detached from | |
773 | @@ -376,6 +378,7 @@ err: | |
7f207e10 AM |
774 | |
775 | return ret; | |
776 | } | |
777 | +EXPORT_SYMBOL(fsnotify_add_mark); | |
778 | ||
1716fcea AM |
779 | int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group, |
780 | struct inode *inode, struct vfsmount *mnt, int allow_dups) | |
2000de60 | 781 | @@ -455,6 +458,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark, |
7f207e10 AM |
782 | atomic_set(&mark->refcnt, 1); |
783 | mark->free_mark = free_mark; | |
784 | } | |
785 | +EXPORT_SYMBOL(fsnotify_init_mark); | |
786 | ||
787 | static int fsnotify_mark_destroy(void *ignored) | |
788 | { | |
789 | diff --git a/fs/open.c b/fs/open.c | |
5527c038 | 790 | index 98e5a52..a94e2e7 100644 |
7f207e10 AM |
791 | --- a/fs/open.c |
792 | +++ b/fs/open.c | |
523b37e3 | 793 | @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, |
7f207e10 AM |
794 | mutex_unlock(&dentry->d_inode->i_mutex); |
795 | return ret; | |
796 | } | |
797 | +EXPORT_SYMBOL(do_truncate); | |
798 | ||
1716fcea | 799 | long vfs_truncate(struct path *path, loff_t length) |
7f207e10 | 800 | { |
5527c038 | 801 | @@ -676,6 +677,7 @@ int open_check_o_direct(struct file *f) |
b912730e AM |
802 | } |
803 | return 0; | |
804 | } | |
805 | +EXPORT_SYMBOL(open_check_o_direct); | |
806 | ||
807 | static int do_dentry_open(struct file *f, | |
808 | int (*open)(struct inode *, struct file *), | |
5527c038 JR |
809 | diff --git a/fs/read_write.c b/fs/read_write.c |
810 | index fd0414e..8ace6ec 100644 | |
811 | --- a/fs/read_write.c | |
812 | +++ b/fs/read_write.c | |
813 | @@ -504,6 +504,7 @@ vfs_readf_t vfs_readf(struct file *file) | |
814 | return new_sync_read; | |
815 | return ERR_PTR(-ENOSYS); | |
816 | } | |
817 | +EXPORT_SYMBOL(vfs_readf); | |
818 | ||
819 | vfs_writef_t vfs_writef(struct file *file) | |
820 | { | |
821 | @@ -515,6 +516,7 @@ vfs_writef_t vfs_writef(struct file *file) | |
822 | return new_sync_write; | |
823 | return ERR_PTR(-ENOSYS); | |
824 | } | |
825 | +EXPORT_SYMBOL(vfs_writef); | |
826 | ||
827 | ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos) | |
828 | { | |
7f207e10 | 829 | diff --git a/fs/splice.c b/fs/splice.c |
5527c038 | 830 | index fa5eee5..bfb3324 100644 |
7f207e10 AM |
831 | --- a/fs/splice.c |
832 | +++ b/fs/splice.c | |
5527c038 | 833 | @@ -1114,6 +1114,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
392086de AM |
834 | |
835 | return splice_write(pipe, out, ppos, len, flags); | |
7f207e10 AM |
836 | } |
837 | +EXPORT_SYMBOL(do_splice_from); | |
838 | ||
839 | /* | |
840 | * Attempt to initiate a splice from a file to a pipe. | |
5527c038 | 841 | @@ -1140,6 +1141,7 @@ long do_splice_to(struct file *in, loff_t *ppos, |
7f207e10 AM |
842 | |
843 | return splice_read(in, ppos, pipe, len, flags); | |
844 | } | |
845 | +EXPORT_SYMBOL(do_splice_to); | |
846 | ||
847 | /** | |
848 | * splice_direct_to_actor - splices data directly between two non-pipes | |
c1595e42 | 849 | diff --git a/fs/xattr.c b/fs/xattr.c |
2000de60 | 850 | index 4ef6985..6bb6303 100644 |
c1595e42 JR |
851 | --- a/fs/xattr.c |
852 | +++ b/fs/xattr.c | |
853 | @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, | |
854 | *xattr_value = value; | |
855 | return error; | |
856 | } | |
857 | +EXPORT_SYMBOL(vfs_getxattr_alloc); | |
858 | ||
859 | /* Compare an extended attribute value with the given value */ | |
860 | int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name, | |
7f207e10 | 861 | diff --git a/security/commoncap.c b/security/commoncap.c |
5527c038 | 862 | index f2875cd..ebf06ec 100644 |
7f207e10 AM |
863 | --- a/security/commoncap.c |
864 | +++ b/security/commoncap.c | |
7e9cd9fe | 865 | @@ -975,9 +975,11 @@ int cap_mmap_addr(unsigned long addr) |
94337f0d | 866 | } |
7f207e10 AM |
867 | return ret; |
868 | } | |
0c3ec466 AM |
869 | +EXPORT_SYMBOL(cap_mmap_addr); |
870 | ||
871 | int cap_mmap_file(struct file *file, unsigned long reqprot, | |
872 | unsigned long prot, unsigned long flags) | |
873 | { | |
874 | return 0; | |
875 | } | |
876 | +EXPORT_SYMBOL(cap_mmap_file); | |
7f207e10 | 877 | diff --git a/security/device_cgroup.c b/security/device_cgroup.c |
c1595e42 | 878 | index 188c1d2..426d9af 100644 |
7f207e10 AM |
879 | --- a/security/device_cgroup.c |
880 | +++ b/security/device_cgroup.c | |
f6c5ef8b AM |
881 | @@ -7,6 +7,7 @@ |
882 | #include <linux/device_cgroup.h> | |
883 | #include <linux/cgroup.h> | |
884 | #include <linux/ctype.h> | |
885 | +#include <linux/export.h> | |
886 | #include <linux/list.h> | |
887 | #include <linux/uaccess.h> | |
888 | #include <linux/seq_file.h> | |
076b876e | 889 | @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask) |
537831f9 AM |
890 | return __devcgroup_check_permission(type, imajor(inode), iminor(inode), |
891 | access); | |
7f207e10 | 892 | } |
2cbb1c4b | 893 | +EXPORT_SYMBOL(__devcgroup_inode_permission); |
7f207e10 AM |
894 | |
895 | int devcgroup_inode_mknod(int mode, dev_t dev) | |
896 | { | |
897 | diff --git a/security/security.c b/security/security.c | |
5527c038 | 898 | index 8e9b1f4..c1c7cd1 100644 |
7f207e10 AM |
899 | --- a/security/security.c |
900 | +++ b/security/security.c | |
7e9cd9fe | 901 | @@ -430,6 +430,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry) |
7f207e10 AM |
902 | return 0; |
903 | return security_ops->path_rmdir(dir, dentry); | |
904 | } | |
905 | +EXPORT_SYMBOL(security_path_rmdir); | |
906 | ||
907 | int security_path_unlink(struct path *dir, struct dentry *dentry) | |
908 | { | |
7e9cd9fe | 909 | @@ -446,6 +447,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry, |
7f207e10 AM |
910 | return 0; |
911 | return security_ops->path_symlink(dir, dentry, old_name); | |
912 | } | |
913 | +EXPORT_SYMBOL(security_path_symlink); | |
914 | ||
915 | int security_path_link(struct dentry *old_dentry, struct path *new_dir, | |
916 | struct dentry *new_dentry) | |
7e9cd9fe | 917 | @@ -454,6 +456,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir, |
7f207e10 AM |
918 | return 0; |
919 | return security_ops->path_link(old_dentry, new_dir, new_dentry); | |
920 | } | |
921 | +EXPORT_SYMBOL(security_path_link); | |
922 | ||
923 | int security_path_rename(struct path *old_dir, struct dentry *old_dentry, | |
38d290e6 | 924 | struct path *new_dir, struct dentry *new_dentry, |
7e9cd9fe | 925 | @@ -481,6 +484,7 @@ int security_path_truncate(struct path *path) |
7f207e10 AM |
926 | return 0; |
927 | return security_ops->path_truncate(path); | |
928 | } | |
929 | +EXPORT_SYMBOL(security_path_truncate); | |
930 | ||
7eafdf33 AM |
931 | int security_path_chmod(struct path *path, umode_t mode) |
932 | { | |
7e9cd9fe | 933 | @@ -488,6 +492,7 @@ int security_path_chmod(struct path *path, umode_t mode) |
7f207e10 | 934 | return 0; |
7eafdf33 | 935 | return security_ops->path_chmod(path, mode); |
7f207e10 AM |
936 | } |
937 | +EXPORT_SYMBOL(security_path_chmod); | |
938 | ||
537831f9 | 939 | int security_path_chown(struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 940 | { |
7e9cd9fe | 941 | @@ -495,6 +500,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 AM |
942 | return 0; |
943 | return security_ops->path_chown(path, uid, gid); | |
944 | } | |
945 | +EXPORT_SYMBOL(security_path_chown); | |
946 | ||
947 | int security_path_chroot(struct path *path) | |
948 | { | |
7e9cd9fe | 949 | @@ -580,6 +586,7 @@ int security_inode_readlink(struct dentry *dentry) |
7f207e10 AM |
950 | return 0; |
951 | return security_ops->inode_readlink(dentry); | |
952 | } | |
953 | +EXPORT_SYMBOL(security_inode_readlink); | |
954 | ||
955 | int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd) | |
956 | { | |
7e9cd9fe | 957 | @@ -594,6 +601,7 @@ int security_inode_permission(struct inode *inode, int mask) |
7f207e10 | 958 | return 0; |
1e00d052 | 959 | return security_ops->inode_permission(inode, mask); |
7f207e10 AM |
960 | } |
961 | +EXPORT_SYMBOL(security_inode_permission); | |
962 | ||
1e00d052 | 963 | int security_inode_setattr(struct dentry *dentry, struct iattr *attr) |
7f207e10 | 964 | { |
7e9cd9fe | 965 | @@ -716,6 +724,7 @@ int security_file_permission(struct file *file, int mask) |
7f207e10 AM |
966 | |
967 | return fsnotify_perm(file, mask); | |
968 | } | |
969 | +EXPORT_SYMBOL(security_file_permission); | |
970 | ||
971 | int security_file_alloc(struct file *file) | |
972 | { | |
7e9cd9fe | 973 | @@ -775,6 +784,7 @@ int security_mmap_file(struct file *file, unsigned long prot, |
7f207e10 AM |
974 | return ret; |
975 | return ima_file_mmap(file, prot); | |
976 | } | |
0c3ec466 | 977 | +EXPORT_SYMBOL(security_mmap_file); |
7f207e10 | 978 | |
0c3ec466 AM |
979 | int security_mmap_addr(unsigned long addr) |
980 | { | |
7f207e10 AM |
981 | diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs |
982 | --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 983 | +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-06-28 17:35:44.344717109 +0200 |
86dc4139 | 984 | @@ -0,0 +1,50 @@ |
7f207e10 AM |
985 | +What: /debug/aufs/si_<id>/ |
986 | +Date: March 2009 | |
f6b6e03d | 987 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
988 | +Description: |
989 | + Under /debug/aufs, a directory named si_<id> is created | |
990 | + per aufs mount, where <id> is a unique id generated | |
991 | + internally. | |
1facf9fc | 992 | + |
86dc4139 AM |
993 | +What: /debug/aufs/si_<id>/plink |
994 | +Date: Apr 2013 | |
f6b6e03d | 995 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
86dc4139 AM |
996 | +Description: |
997 | + It has three lines and shows the information about the | |
998 | + pseudo-link. The first line is a single number | |
999 | + representing a number of buckets. The second line is a | |
1000 | + number of pseudo-links per buckets (separated by a | |
1001 | + blank). The last line is a single number representing a | |
1002 | + total number of psedo-links. | |
1003 | + When the aufs mount option 'noplink' is specified, it | |
1004 | + will show "1\n0\n0\n". | |
1005 | + | |
7f207e10 AM |
1006 | +What: /debug/aufs/si_<id>/xib |
1007 | +Date: March 2009 | |
f6b6e03d | 1008 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1009 | +Description: |
1010 | + It shows the consumed blocks by xib (External Inode Number | |
1011 | + Bitmap), its block size and file size. | |
1012 | + When the aufs mount option 'noxino' is specified, it | |
1013 | + will be empty. About XINO files, see the aufs manual. | |
1014 | + | |
1015 | +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN | |
1016 | +Date: March 2009 | |
f6b6e03d | 1017 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1018 | +Description: |
1019 | + It shows the consumed blocks by xino (External Inode Number | |
1020 | + Translation Table), its link count, block size and file | |
1021 | + size. | |
1022 | + When the aufs mount option 'noxino' is specified, it | |
1023 | + will be empty. About XINO files, see the aufs manual. | |
1024 | + | |
1025 | +What: /debug/aufs/si_<id>/xigen | |
1026 | +Date: March 2009 | |
f6b6e03d | 1027 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1028 | +Description: |
1029 | + It shows the consumed blocks by xigen (External Inode | |
1030 | + Generation Table), its block size and file size. | |
1031 | + If CONFIG_AUFS_EXPORT is disabled, this entry will not | |
1032 | + be created. | |
1033 | + When the aufs mount option 'noxino' is specified, it | |
1034 | + will be empty. About XINO files, see the aufs manual. | |
1035 | diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs | |
1036 | --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1037 | +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-06-28 17:35:44.344717109 +0200 |
392086de | 1038 | @@ -0,0 +1,31 @@ |
7f207e10 AM |
1039 | +What: /sys/fs/aufs/si_<id>/ |
1040 | +Date: March 2009 | |
f6b6e03d | 1041 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1042 | +Description: |
1043 | + Under /sys/fs/aufs, a directory named si_<id> is created | |
1044 | + per aufs mount, where <id> is a unique id generated | |
1045 | + internally. | |
1046 | + | |
1047 | +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN | |
1048 | +Date: March 2009 | |
f6b6e03d | 1049 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1050 | +Description: |
1051 | + It shows the abolute path of a member directory (which | |
1052 | + is called branch) in aufs, and its permission. | |
1053 | + | |
392086de AM |
1054 | +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN |
1055 | +Date: July 2013 | |
f6b6e03d | 1056 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
392086de AM |
1057 | +Description: |
1058 | + It shows the id of a member directory (which is called | |
1059 | + branch) in aufs. | |
1060 | + | |
7f207e10 AM |
1061 | +What: /sys/fs/aufs/si_<id>/xi_path |
1062 | +Date: March 2009 | |
f6b6e03d | 1063 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1064 | +Description: |
1065 | + It shows the abolute path of XINO (External Inode Number | |
1066 | + Bitmap, Translation Table and Generation Table) file | |
1067 | + even if it is the default path. | |
1068 | + When the aufs mount option 'noxino' is specified, it | |
1069 | + will be empty. About XINO files, see the aufs manual. | |
53392da6 AM |
1070 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt |
1071 | --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1072 | +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-06-28 17:35:44.344717109 +0200 |
7e9cd9fe | 1073 | @@ -0,0 +1,170 @@ |
53392da6 | 1074 | + |
2000de60 | 1075 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1076 | +# |
1077 | +# This program is free software; you can redistribute it and/or modify | |
1078 | +# it under the terms of the GNU General Public License as published by | |
1079 | +# the Free Software Foundation; either version 2 of the License, or | |
1080 | +# (at your option) any later version. | |
1081 | +# | |
1082 | +# This program is distributed in the hope that it will be useful, | |
1083 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1084 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1085 | +# GNU General Public License for more details. | |
1086 | +# | |
1087 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1088 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1089 | + |
1090 | +Introduction | |
1091 | +---------------------------------------- | |
1092 | + | |
1093 | +aufs [ei ju: ef es] | [a u f s] | |
1094 | +1. abbrev. for "advanced multi-layered unification filesystem". | |
1095 | +2. abbrev. for "another unionfs". | |
1096 | +3. abbrev. for "auf das" in German which means "on the" in English. | |
1097 | + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E). | |
1098 | + But "Filesystem aufs Filesystem" is hard to understand. | |
1099 | + | |
1100 | +AUFS is a filesystem with features: | |
1101 | +- multi layered stackable unification filesystem, the member directory | |
1102 | + is called as a branch. | |
1103 | +- branch permission and attribute, 'readonly', 'real-readonly', | |
7e9cd9fe | 1104 | + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their |
53392da6 AM |
1105 | + combination. |
1106 | +- internal "file copy-on-write". | |
1107 | +- logical deletion, whiteout. | |
1108 | +- dynamic branch manipulation, adding, deleting and changing permission. | |
1109 | +- allow bypassing aufs, user's direct branch access. | |
1110 | +- external inode number translation table and bitmap which maintains the | |
1111 | + persistent aufs inode number. | |
1112 | +- seekable directory, including NFS readdir. | |
1113 | +- file mapping, mmap and sharing pages. | |
1114 | +- pseudo-link, hardlink over branches. | |
1115 | +- loopback mounted filesystem as a branch. | |
1116 | +- several policies to select one among multiple writable branches. | |
1117 | +- revert a single systemcall when an error occurs in aufs. | |
1118 | +- and more... | |
1119 | + | |
1120 | + | |
1121 | +Multi Layered Stackable Unification Filesystem | |
1122 | +---------------------------------------------------------------------- | |
1123 | +Most people already knows what it is. | |
1124 | +It is a filesystem which unifies several directories and provides a | |
1125 | +merged single directory. When users access a file, the access will be | |
1126 | +passed/re-directed/converted (sorry, I am not sure which English word is | |
1127 | +correct) to the real file on the member filesystem. The member | |
1128 | +filesystem is called 'lower filesystem' or 'branch' and has a mode | |
1129 | +'readonly' and 'readwrite.' And the deletion for a file on the lower | |
1130 | +readonly branch is handled by creating 'whiteout' on the upper writable | |
1131 | +branch. | |
1132 | + | |
1133 | +On LKML, there have been discussions about UnionMount (Jan Blunck, | |
1134 | +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took | |
1135 | +different approaches to implement the merged-view. | |
1136 | +The former tries putting it into VFS, and the latter implements as a | |
1137 | +separate filesystem. | |
1138 | +(If I misunderstand about these implementations, please let me know and | |
1139 | +I shall correct it. Because it is a long time ago when I read their | |
1140 | +source files last time). | |
1141 | + | |
1142 | +UnionMount's approach will be able to small, but may be hard to share | |
1143 | +branches between several UnionMount since the whiteout in it is | |
1144 | +implemented in the inode on branch filesystem and always | |
1145 | +shared. According to Bharata's post, readdir does not seems to be | |
1146 | +finished yet. | |
1147 | +There are several missing features known in this implementations such as | |
1148 | +- for users, the inode number may change silently. eg. copy-up. | |
1149 | +- link(2) may break by copy-up. | |
1150 | +- read(2) may get an obsoleted filedata (fstat(2) too). | |
1151 | +- fcntl(F_SETLK) may be broken by copy-up. | |
1152 | +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after | |
1153 | + open(O_RDWR). | |
1154 | + | |
7e9cd9fe AM |
1155 | +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was |
1156 | +merged into mainline. This is another implementation of UnionMount as a | |
1157 | +separated filesystem. All the limitations and known problems which | |
1158 | +UnionMount are equally inherited to "overlay" filesystem. | |
1159 | + | |
1160 | +Unionfs has a longer history. When I started implementing a stackable | |
1161 | +filesystem (Aug 2005), it already existed. It has virtual super_block, | |
1162 | +inode, dentry and file objects and they have an array pointing lower | |
1163 | +same kind objects. After contributing many patches for Unionfs, I | |
1164 | +re-started my project AUFS (Jun 2006). | |
53392da6 AM |
1165 | + |
1166 | +In AUFS, the structure of filesystem resembles to Unionfs, but I | |
1167 | +implemented my own ideas, approaches and enhancements and it became | |
1168 | +totally different one. | |
1169 | + | |
1170 | +Comparing DM snapshot and fs based implementation | |
1171 | +- the number of bytes to be copied between devices is much smaller. | |
1172 | +- the type of filesystem must be one and only. | |
1173 | +- the fs must be writable, no readonly fs, even for the lower original | |
1174 | + device. so the compression fs will not be usable. but if we use | |
1175 | + loopback mount, we may address this issue. | |
1176 | + for instance, | |
1177 | + mount /cdrom/squashfs.img /sq | |
1178 | + losetup /sq/ext2.img | |
1179 | + losetup /somewhere/cow | |
1180 | + dmsetup "snapshot /dev/loop0 /dev/loop1 ..." | |
1181 | +- it will be difficult (or needs more operations) to extract the | |
1182 | + difference between the original device and COW. | |
1183 | +- DM snapshot-merge may help a lot when users try merging. in the | |
1184 | + fs-layer union, users will use rsync(1). | |
1185 | + | |
7e9cd9fe AM |
1186 | +You may want to read my old paper "Filesystems in LiveCD" |
1187 | +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf). | |
53392da6 | 1188 | + |
7e9cd9fe AM |
1189 | + |
1190 | +Several characters/aspects/persona of aufs | |
53392da6 AM |
1191 | +---------------------------------------------------------------------- |
1192 | + | |
7e9cd9fe | 1193 | +Aufs has several characters, aspects or persona. |
53392da6 AM |
1194 | +1. a filesystem, callee of VFS helper |
1195 | +2. sub-VFS, caller of VFS helper for branches | |
1196 | +3. a virtual filesystem which maintains persistent inode number | |
1197 | +4. reader/writer of files on branches such like an application | |
1198 | + | |
1199 | +1. Callee of VFS Helper | |
1200 | +As an ordinary linux filesystem, aufs is a callee of VFS. For instance, | |
1201 | +unlink(2) from an application reaches sys_unlink() kernel function and | |
1202 | +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it | |
1203 | +calls filesystem specific unlink operation. Actually aufs implements the | |
1204 | +unlink operation but it behaves like a redirector. | |
1205 | + | |
1206 | +2. Caller of VFS Helper for Branches | |
1207 | +aufs_unlink() passes the unlink request to the branch filesystem as if | |
1208 | +it were called from VFS. So the called unlink operation of the branch | |
1209 | +filesystem acts as usual. As a caller of VFS helper, aufs should handle | |
1210 | +every necessary pre/post operation for the branch filesystem. | |
1211 | +- acquire the lock for the parent dir on a branch | |
1212 | +- lookup in a branch | |
1213 | +- revalidate dentry on a branch | |
1214 | +- mnt_want_write() for a branch | |
1215 | +- vfs_unlink() for a branch | |
1216 | +- mnt_drop_write() for a branch | |
1217 | +- release the lock on a branch | |
1218 | + | |
1219 | +3. Persistent Inode Number | |
1220 | +One of the most important issue for a filesystem is to maintain inode | |
1221 | +numbers. This is particularly important to support exporting a | |
1222 | +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a | |
1223 | +backend block device for its own. But some storage is necessary to | |
7e9cd9fe AM |
1224 | +keep and maintain the inode numbers. It may be a large space and may not |
1225 | +suit to keep in memory. Aufs rents some space from its first writable | |
1226 | +branch filesystem (by default) and creates file(s) on it. These files | |
1227 | +are created by aufs internally and removed soon (currently) keeping | |
1228 | +opened. | |
53392da6 AM |
1229 | +Note: Because these files are removed, they are totally gone after |
1230 | + unmounting aufs. It means the inode numbers are not persistent | |
1231 | + across unmount or reboot. I have a plan to make them really | |
1232 | + persistent which will be important for aufs on NFS server. | |
1233 | + | |
1234 | +4. Read/Write Files Internally (copy-on-write) | |
1235 | +Because a branch can be readonly, when you write a file on it, aufs will | |
1236 | +"copy-up" it to the upper writable branch internally. And then write the | |
1237 | +originally requested thing to the file. Generally kernel doesn't | |
1238 | +open/read/write file actively. In aufs, even a single write may cause a | |
1239 | +internal "file copy". This behaviour is very similar to cp(1) command. | |
1240 | + | |
1241 | +Some people may think it is better to pass such work to user space | |
1242 | +helper, instead of doing in kernel space. Actually I am still thinking | |
1243 | +about it. But currently I have implemented it in kernel space. | |
1244 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt | |
1245 | --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1246 | +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-06-28 17:35:44.344717109 +0200 |
7e9cd9fe | 1247 | @@ -0,0 +1,258 @@ |
53392da6 | 1248 | + |
2000de60 | 1249 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1250 | +# |
1251 | +# This program is free software; you can redistribute it and/or modify | |
1252 | +# it under the terms of the GNU General Public License as published by | |
1253 | +# the Free Software Foundation; either version 2 of the License, or | |
1254 | +# (at your option) any later version. | |
1255 | +# | |
1256 | +# This program is distributed in the hope that it will be useful, | |
1257 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1258 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1259 | +# GNU General Public License for more details. | |
1260 | +# | |
1261 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1262 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1263 | + |
1264 | +Basic Aufs Internal Structure | |
1265 | + | |
1266 | +Superblock/Inode/Dentry/File Objects | |
1267 | +---------------------------------------------------------------------- | |
1268 | +As like an ordinary filesystem, aufs has its own | |
1269 | +superblock/inode/dentry/file objects. All these objects have a | |
1270 | +dynamically allocated array and store the same kind of pointers to the | |
1271 | +lower filesystem, branch. | |
1272 | +For example, when you build a union with one readwrite branch and one | |
1273 | +readonly, mounted /au, /rw and /ro respectively. | |
1274 | +- /au = /rw + /ro | |
1275 | +- /ro/fileA exists but /rw/fileA | |
1276 | + | |
1277 | +Aufs lookup operation finds /ro/fileA and gets dentry for that. These | |
1278 | +pointers are stored in a aufs dentry. The array in aufs dentry will be, | |
7e9cd9fe | 1279 | +- [0] = NULL (because /rw/fileA doesn't exist) |
53392da6 AM |
1280 | +- [1] = /ro/fileA |
1281 | + | |
1282 | +This style of an array is essentially same to the aufs | |
1283 | +superblock/inode/dentry/file objects. | |
1284 | + | |
1285 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1286 | +branches dynamically, these objects has its own generation. When |
1287 | +branches are changed, the generation in aufs superblock is | |
1288 | +incremented. And a generation in other object are compared when it is | |
1289 | +accessed. When a generation in other objects are obsoleted, aufs | |
1290 | +refreshes the internal array. | |
53392da6 AM |
1291 | + |
1292 | + | |
1293 | +Superblock | |
1294 | +---------------------------------------------------------------------- | |
1295 | +Additionally aufs superblock has some data for policies to select one | |
1296 | +among multiple writable branches, XIB files, pseudo-links and kobject. | |
1297 | +See below in detail. | |
7e9cd9fe AM |
1298 | +About the policies which supports copy-down a directory, see |
1299 | +wbr_policy.txt too. | |
53392da6 AM |
1300 | + |
1301 | + | |
1302 | +Branch and XINO(External Inode Number Translation Table) | |
1303 | +---------------------------------------------------------------------- | |
1304 | +Every branch has its own xino (external inode number translation table) | |
1305 | +file. The xino file is created and unlinked by aufs internally. When two | |
1306 | +members of a union exist on the same filesystem, they share the single | |
1307 | +xino file. | |
1308 | +The struct of a xino file is simple, just a sequence of aufs inode | |
1309 | +numbers which is indexed by the lower inode number. | |
1310 | +In the above sample, assume the inode number of /ro/fileA is i111 and | |
1311 | +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as | |
1312 | +4(8) bytes at 111 * 4(8) bytes offset in the xino file. | |
1313 | + | |
1314 | +When the inode numbers are not contiguous, the xino file will be sparse | |
1315 | +which has a hole in it and doesn't consume as much disk space as it | |
1316 | +might appear. If your branch filesystem consumes disk space for such | |
1317 | +holes, then you should specify 'xino=' option at mounting aufs. | |
1318 | + | |
7e9cd9fe AM |
1319 | +Aufs has a mount option to free the disk blocks for such holes in XINO |
1320 | +files on tmpfs or ramdisk. But it is not so effective actually. If you | |
1321 | +meet a problem of disk shortage due to XINO files, then you should try | |
1322 | +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git. | |
1323 | +The patch localizes the assignment inumbers per tmpfs-mount and avoid | |
1324 | +the holes in XINO files. | |
1325 | + | |
53392da6 | 1326 | +Also a writable branch has three kinds of "whiteout bases". All these |
7e9cd9fe | 1327 | +are existed when the branch is joined to aufs, and their names are |
53392da6 AM |
1328 | +whiteout-ed doubly, so that users will never see their names in aufs |
1329 | +hierarchy. | |
7e9cd9fe | 1330 | +1. a regular file which will be hardlinked to all whiteouts. |
53392da6 | 1331 | +2. a directory to store a pseudo-link. |
7e9cd9fe | 1332 | +3. a directory to store an "orphan"-ed file temporary. |
53392da6 AM |
1333 | + |
1334 | +1. Whiteout Base | |
1335 | + When you remove a file on a readonly branch, aufs handles it as a | |
1336 | + logical deletion and creates a whiteout on the upper writable branch | |
1337 | + as a hardlink of this file in order not to consume inode on the | |
1338 | + writable branch. | |
1339 | +2. Pseudo-link Dir | |
1340 | + See below, Pseudo-link. | |
1341 | +3. Step-Parent Dir | |
1342 | + When "fileC" exists on the lower readonly branch only and it is | |
1343 | + opened and removed with its parent dir, and then user writes | |
1344 | + something into it, then aufs copies-up fileC to this | |
1345 | + directory. Because there is no other dir to store fileC. After | |
1346 | + creating a file under this dir, the file is unlinked. | |
1347 | + | |
1348 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1349 | +dynamically, a branch has its own id. When the branch order changes, |
1350 | +aufs finds the new index by searching the branch id. | |
53392da6 AM |
1351 | + |
1352 | + | |
1353 | +Pseudo-link | |
1354 | +---------------------------------------------------------------------- | |
1355 | +Assume "fileA" exists on the lower readonly branch only and it is | |
1356 | +hardlinked to "fileB" on the branch. When you write something to fileA, | |
1357 | +aufs copies-up it to the upper writable branch. Additionally aufs | |
1358 | +creates a hardlink under the Pseudo-link Directory of the writable | |
1359 | +branch. The inode of a pseudo-link is kept in aufs super_block as a | |
1360 | +simple list. If fileB is read after unlinking fileA, aufs returns | |
1361 | +filedata from the pseudo-link instead of the lower readonly | |
1362 | +branch. Because the pseudo-link is based upon the inode, to keep the | |
7e9cd9fe | 1363 | +inode number by xino (see above) is essentially necessary. |
53392da6 AM |
1364 | + |
1365 | +All the hardlinks under the Pseudo-link Directory of the writable branch | |
1366 | +should be restored in a proper location later. Aufs provides a utility | |
1367 | +to do this. The userspace helpers executed at remounting and unmounting | |
1368 | +aufs by default. | |
1369 | +During this utility is running, it puts aufs into the pseudo-link | |
1370 | +maintenance mode. In this mode, only the process which began the | |
1371 | +maintenance mode (and its child processes) is allowed to operate in | |
1372 | +aufs. Some other processes which are not related to the pseudo-link will | |
1373 | +be allowed to run too, but the rest have to return an error or wait | |
1374 | +until the maintenance mode ends. If a process already acquires an inode | |
1375 | +mutex (in VFS), it has to return an error. | |
1376 | + | |
1377 | + | |
1378 | +XIB(external inode number bitmap) | |
1379 | +---------------------------------------------------------------------- | |
1380 | +Addition to the xino file per a branch, aufs has an external inode number | |
7e9cd9fe AM |
1381 | +bitmap in a superblock object. It is also an internal file such like a |
1382 | +xino file. | |
53392da6 AM |
1383 | +It is a simple bitmap to mark whether the aufs inode number is in-use or |
1384 | +not. | |
1385 | +To reduce the file I/O, aufs prepares a single memory page to cache xib. | |
1386 | + | |
7e9cd9fe | 1387 | +As well as XINO files, aufs has a feature to truncate/refresh XIB to |
53392da6 AM |
1388 | +reduce the number of consumed disk blocks for these files. |
1389 | + | |
1390 | + | |
1391 | +Virtual or Vertical Dir, and Readdir in Userspace | |
1392 | +---------------------------------------------------------------------- | |
1393 | +In order to support multiple layers (branches), aufs readdir operation | |
1394 | +constructs a virtual dir block on memory. For readdir, aufs calls | |
1395 | +vfs_readdir() internally for each dir on branches, merges their entries | |
1396 | +with eliminating the whiteout-ed ones, and sets it to file (dir) | |
1397 | +object. So the file object has its entry list until it is closed. The | |
1398 | +entry list will be updated when the file position is zero and becomes | |
7e9cd9fe | 1399 | +obsoleted. This decision is made in aufs automatically. |
53392da6 AM |
1400 | + |
1401 | +The dynamically allocated memory block for the name of entries has a | |
1402 | +unit of 512 bytes (by default) and stores the names contiguously (no | |
1403 | +padding). Another block for each entry is handled by kmem_cache too. | |
1404 | +During building dir blocks, aufs creates hash list and judging whether | |
1405 | +the entry is whiteouted by its upper branch or already listed. | |
1406 | +The merged result is cached in the corresponding inode object and | |
1407 | +maintained by a customizable life-time option. | |
1408 | + | |
1409 | +Some people may call it can be a security hole or invite DoS attack | |
1410 | +since the opened and once readdir-ed dir (file object) holds its entry | |
1411 | +list and becomes a pressure for system memory. But I'd say it is similar | |
1412 | +to files under /proc or /sys. The virtual files in them also holds a | |
1413 | +memory page (generally) while they are opened. When an idea to reduce | |
1414 | +memory for them is introduced, it will be applied to aufs too. | |
1415 | +For those who really hate this situation, I've developed readdir(3) | |
1416 | +library which operates this merging in userspace. You just need to set | |
1417 | +LD_PRELOAD environment variable, and aufs will not consume no memory in | |
1418 | +kernel space for readdir(3). | |
1419 | + | |
1420 | + | |
1421 | +Workqueue | |
1422 | +---------------------------------------------------------------------- | |
1423 | +Aufs sometimes requires privilege access to a branch. For instance, | |
1424 | +in copy-up/down operation. When a user process is going to make changes | |
1425 | +to a file which exists in the lower readonly branch only, and the mode | |
1426 | +of one of ancestor directories may not be writable by a user | |
1427 | +process. Here aufs copy-up the file with its ancestors and they may | |
1428 | +require privilege to set its owner/group/mode/etc. | |
1429 | +This is a typical case of a application character of aufs (see | |
1430 | +Introduction). | |
1431 | + | |
1432 | +Aufs uses workqueue synchronously for this case. It creates its own | |
1433 | +workqueue. The workqueue is a kernel thread and has privilege. Aufs | |
1434 | +passes the request to call mkdir or write (for example), and wait for | |
1435 | +its completion. This approach solves a problem of a signal handler | |
1436 | +simply. | |
1437 | +If aufs didn't adopt the workqueue and changed the privilege of the | |
7e9cd9fe AM |
1438 | +process, then the process may receive the unexpected SIGXFSZ or other |
1439 | +signals. | |
53392da6 AM |
1440 | + |
1441 | +Also aufs uses the system global workqueue ("events" kernel thread) too | |
1442 | +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a | |
1443 | +whiteout base and etc. This is unrelated to a privilege. | |
1444 | +Most of aufs operation tries acquiring a rw_semaphore for aufs | |
1445 | +superblock at the beginning, at the same time waits for the completion | |
1446 | +of all queued asynchronous tasks. | |
1447 | + | |
1448 | + | |
1449 | +Whiteout | |
1450 | +---------------------------------------------------------------------- | |
1451 | +The whiteout in aufs is very similar to Unionfs's. That is represented | |
1452 | +by its filename. UnionMount takes an approach of a file mode, but I am | |
1453 | +afraid several utilities (find(1) or something) will have to support it. | |
1454 | + | |
1455 | +Basically the whiteout represents "logical deletion" which stops aufs to | |
1456 | +lookup further, but also it represents "dir is opaque" which also stop | |
7e9cd9fe | 1457 | +further lookup. |
53392da6 AM |
1458 | + |
1459 | +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively. | |
1460 | +In order to make several functions in a single systemcall to be | |
1461 | +revertible, aufs adopts an approach to rename a directory to a temporary | |
1462 | +unique whiteouted name. | |
1463 | +For example, in rename(2) dir where the target dir already existed, aufs | |
1464 | +renames the target dir to a temporary unique whiteouted name before the | |
7e9cd9fe | 1465 | +actual rename on a branch, and then handles other actions (make it opaque, |
53392da6 AM |
1466 | +update the attributes, etc). If an error happens in these actions, aufs |
1467 | +simply renames the whiteouted name back and returns an error. If all are | |
1468 | +succeeded, aufs registers a function to remove the whiteouted unique | |
1469 | +temporary name completely and asynchronously to the system global | |
1470 | +workqueue. | |
1471 | + | |
1472 | + | |
1473 | +Copy-up | |
1474 | +---------------------------------------------------------------------- | |
1475 | +It is a well-known feature or concept. | |
1476 | +When user modifies a file on a readonly branch, aufs operate "copy-up" | |
1477 | +internally and makes change to the new file on the upper writable branch. | |
1478 | +When the trigger systemcall does not update the timestamps of the parent | |
1479 | +dir, aufs reverts it after copy-up. | |
c2b27bf2 AM |
1480 | + |
1481 | + | |
1482 | +Move-down (aufs3.9 and later) | |
1483 | +---------------------------------------------------------------------- | |
1484 | +"Copy-up" is one of the essential feature in aufs. It copies a file from | |
1485 | +the lower readonly branch to the upper writable branch when a user | |
1486 | +changes something about the file. | |
1487 | +"Move-down" is an opposite action of copy-up. Basically this action is | |
1488 | +ran manually instead of automatically and internally. | |
076b876e AM |
1489 | +For desgin and implementation, aufs has to consider these issues. |
1490 | +- whiteout for the file may exist on the lower branch. | |
1491 | +- ancestor directories may not exist on the lower branch. | |
1492 | +- diropq for the ancestor directories may exist on the upper branch. | |
1493 | +- free space on the lower branch will reduce. | |
1494 | +- another access to the file may happen during moving-down, including | |
7e9cd9fe | 1495 | + UDBA (see "Revalidate Dentry and UDBA"). |
076b876e AM |
1496 | +- the file should not be hard-linked nor pseudo-linked. they should be |
1497 | + handled by auplink utility later. | |
c2b27bf2 AM |
1498 | + |
1499 | +Sometimes users want to move-down a file from the upper writable branch | |
1500 | +to the lower readonly or writable branch. For instance, | |
1501 | +- the free space of the upper writable branch is going to run out. | |
1502 | +- create a new intermediate branch between the upper and lower branch. | |
1503 | +- etc. | |
1504 | + | |
1505 | +For this purpose, use "aumvdown" command in aufs-util.git. | |
b912730e AM |
1506 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt |
1507 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1508 | +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2015-06-28 17:35:44.344717109 +0200 |
b912730e AM |
1509 | @@ -0,0 +1,85 @@ |
1510 | + | |
1511 | +# Copyright (C) 2015 Junjiro R. Okajima | |
1512 | +# | |
1513 | +# This program is free software; you can redistribute it and/or modify | |
1514 | +# it under the terms of the GNU General Public License as published by | |
1515 | +# the Free Software Foundation; either version 2 of the License, or | |
1516 | +# (at your option) any later version. | |
1517 | +# | |
1518 | +# This program is distributed in the hope that it will be useful, | |
1519 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1520 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1521 | +# GNU General Public License for more details. | |
1522 | +# | |
1523 | +# You should have received a copy of the GNU General Public License | |
1524 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1525 | + | |
1526 | +Support for a branch who has its ->atomic_open() | |
1527 | +---------------------------------------------------------------------- | |
1528 | +The filesystems who implement its ->atomic_open() are not majority. For | |
1529 | +example NFSv4 does, and aufs should call NFSv4 ->atomic_open, | |
1530 | +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than | |
1531 | +->atomic_open(), NFSv4 returns an error for this open(2). While I am not | |
1532 | +sure whether all filesystems who have ->atomic_open() behave like this, | |
1533 | +but NFSv4 surely returns the error. | |
1534 | + | |
1535 | +In order to support ->atomic_open() for aufs, there are a few | |
1536 | +approaches. | |
1537 | + | |
1538 | +A. Introduce aufs_atomic_open() | |
1539 | + - calls one of VFS:do_last(), lookup_open() or atomic_open() for | |
1540 | + branch fs. | |
1541 | +B. Introduce aufs_atomic_open() calling create, open and chmod. this is | |
1542 | + an aufs user Pip Cet's approach | |
1543 | + - calls aufs_create(), VFS finish_open() and notify_change(). | |
1544 | + - pass fake-mode to finish_open(), and then correct the mode by | |
1545 | + notify_change(). | |
1546 | +C. Extend aufs_open() to call branch fs's ->atomic_open() | |
1547 | + - no aufs_atomic_open(). | |
1548 | + - aufs_lookup() registers the TID to an aufs internal object. | |
1549 | + - aufs_create() does nothing when the matching TID is registered, but | |
1550 | + registers the mode. | |
1551 | + - aufs_open() calls branch fs's ->atomic_open() when the matching | |
1552 | + TID is registered. | |
1553 | +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's | |
1554 | + credential | |
1555 | + - no aufs_atomic_open(). | |
1556 | + - aufs_create() registers the TID to an internal object. this info | |
1557 | + represents "this process created this file just now." | |
1558 | + - when aufs gets EACCES from branch fs's ->open(), then confirm the | |
1559 | + registered TID and re-try open() with superuser's credential. | |
1560 | + | |
1561 | +Pros and cons for each approach. | |
1562 | + | |
1563 | +A. | |
1564 | + - straightforward but highly depends upon VFS internal. | |
1565 | + - the atomic behavaiour is kept. | |
1566 | + - some of parameters such as nameidata are hard to reproduce for | |
1567 | + branch fs. | |
1568 | + - large overhead. | |
1569 | +B. | |
1570 | + - easy to implement. | |
1571 | + - the atomic behavaiour is lost. | |
1572 | +C. | |
1573 | + - the atomic behavaiour is kept. | |
1574 | + - dirty and tricky. | |
1575 | + - VFS checks whether the file is created correctly after calling | |
1576 | + ->create(), which means this approach doesn't work. | |
1577 | +D. | |
1578 | + - easy to implement. | |
1579 | + - the atomic behavaiour is lost. | |
1580 | + - to open a file with superuser's credential and give it to a user | |
1581 | + process is a bad idea, since the file object keeps the credential | |
1582 | + in it. It may affect LSM or something. This approach doesn't work | |
1583 | + either. | |
1584 | + | |
1585 | +The approach A is ideal, but it hard to implement. So here is a | |
1586 | +variation of A, which is to be implemented. | |
1587 | + | |
1588 | +A-1. Introduce aufs_atomic_open() | |
1589 | + - calls branch fs ->atomic_open() if exists. otherwise calls | |
1590 | + vfs_create() and finish_open(). | |
1591 | + - the demerit is that the several checks after branch fs | |
1592 | + ->atomic_open() are lost. in the ordinary case, the checks are | |
1593 | + done by VFS:do_last(), lookup_open() and atomic_open(). some can | |
1594 | + be implemented in aufs, but not all I am afraid. | |
53392da6 AM |
1595 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt |
1596 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1597 | +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-06-28 17:35:44.344717109 +0200 |
7e9cd9fe | 1598 | @@ -0,0 +1,113 @@ |
53392da6 | 1599 | + |
2000de60 | 1600 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1601 | +# |
1602 | +# This program is free software; you can redistribute it and/or modify | |
1603 | +# it under the terms of the GNU General Public License as published by | |
1604 | +# the Free Software Foundation; either version 2 of the License, or | |
1605 | +# (at your option) any later version. | |
1606 | +# | |
1607 | +# This program is distributed in the hope that it will be useful, | |
1608 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1609 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1610 | +# GNU General Public License for more details. | |
1611 | +# | |
1612 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1613 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1614 | + |
1615 | +Lookup in a Branch | |
1616 | +---------------------------------------------------------------------- | |
1617 | +Since aufs has a character of sub-VFS (see Introduction), it operates | |
7e9cd9fe AM |
1618 | +lookup for branches as VFS does. It may be a heavy work. But almost all |
1619 | +lookup operation in aufs is the simplest case, ie. lookup only an entry | |
1620 | +directly connected to its parent. Digging down the directory hierarchy | |
1621 | +is unnecessary. VFS has a function lookup_one_len() for that use, and | |
1622 | +aufs calls it. | |
1623 | + | |
1624 | +When a branch is a remote filesystem, aufs basically relies upon its | |
53392da6 AM |
1625 | +->d_revalidate(), also aufs forces the hardest revalidate tests for |
1626 | +them. | |
1627 | +For d_revalidate, aufs implements three levels of revalidate tests. See | |
1628 | +"Revalidate Dentry and UDBA" in detail. | |
1629 | + | |
1630 | + | |
076b876e AM |
1631 | +Test Only the Highest One for the Directory Permission (dirperm1 option) |
1632 | +---------------------------------------------------------------------- | |
1633 | +Let's try case study. | |
1634 | +- aufs has two branches, upper readwrite and lower readonly. | |
1635 | + /au = /rw + /ro | |
1636 | +- "dirA" exists under /ro, but /rw. and its mode is 0700. | |
1637 | +- user invoked "chmod a+rx /au/dirA" | |
1638 | +- the internal copy-up is activated and "/rw/dirA" is created and its | |
7e9cd9fe | 1639 | + permission bits are set to world readable. |
076b876e AM |
1640 | +- then "/au/dirA" becomes world readable? |
1641 | + | |
1642 | +In this case, /ro/dirA is still 0700 since it exists in readonly branch, | |
1643 | +or it may be a natively readonly filesystem. If aufs respects the lower | |
1644 | +branch, it should not respond readdir request from other users. But user | |
1645 | +allowed it by chmod. Should really aufs rejects showing the entries | |
1646 | +under /ro/dirA? | |
1647 | + | |
7e9cd9fe AM |
1648 | +To be honest, I don't have a good solution for this case. So aufs |
1649 | +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to | |
1650 | +users. | |
076b876e AM |
1651 | +When dirperm1 is specified, aufs checks only the highest one for the |
1652 | +directory permission, and shows the entries. Otherwise, as usual, checks | |
1653 | +every dir existing on all branches and rejects the request. | |
1654 | + | |
1655 | +As a side effect, dirperm1 option improves the performance of aufs | |
1656 | +because the number of permission check is reduced when the number of | |
1657 | +branch is many. | |
1658 | + | |
1659 | + | |
53392da6 AM |
1660 | +Revalidate Dentry and UDBA (User's Direct Branch Access) |
1661 | +---------------------------------------------------------------------- | |
1662 | +Generally VFS helpers re-validate a dentry as a part of lookup. | |
1663 | +0. digging down the directory hierarchy. | |
1664 | +1. lock the parent dir by its i_mutex. | |
1665 | +2. lookup the final (child) entry. | |
1666 | +3. revalidate it. | |
1667 | +4. call the actual operation (create, unlink, etc.) | |
1668 | +5. unlock the parent dir | |
1669 | + | |
1670 | +If the filesystem implements its ->d_revalidate() (step 3), then it is | |
1671 | +called. Actually aufs implements it and checks the dentry on a branch is | |
1672 | +still valid. | |
1673 | +But it is not enough. Because aufs has to release the lock for the | |
1674 | +parent dir on a branch at the end of ->lookup() (step 2) and | |
1675 | +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still | |
1676 | +held by VFS. | |
1677 | +If the file on a branch is changed directly, eg. bypassing aufs, after | |
1678 | +aufs released the lock, then the subsequent operation may cause | |
1679 | +something unpleasant result. | |
1680 | + | |
1681 | +This situation is a result of VFS architecture, ->lookup() and | |
1682 | +->d_revalidate() is separated. But I never say it is wrong. It is a good | |
1683 | +design from VFS's point of view. It is just not suitable for sub-VFS | |
1684 | +character in aufs. | |
1685 | + | |
1686 | +Aufs supports such case by three level of revalidation which is | |
1687 | +selectable by user. | |
1688 | +1. Simple Revalidate | |
1689 | + Addition to the native flow in VFS's, confirm the child-parent | |
1690 | + relationship on the branch just after locking the parent dir on the | |
1691 | + branch in the "actual operation" (step 4). When this validation | |
1692 | + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still | |
1693 | + checks the validation of the dentry on branches. | |
1694 | +2. Monitor Changes Internally by Inotify/Fsnotify | |
1695 | + Addition to above, in the "actual operation" (step 4) aufs re-lookup | |
1696 | + the dentry on the branch, and returns EBUSY if it finds different | |
1697 | + dentry. | |
1698 | + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches | |
1699 | + during it is in cache. When the event is notified, aufs registers a | |
1700 | + function to kernel 'events' thread by schedule_work(). And the | |
1701 | + function sets some special status to the cached aufs dentry and inode | |
1702 | + private data. If they are not cached, then aufs has nothing to | |
1703 | + do. When the same file is accessed through aufs (step 0-3) later, | |
1704 | + aufs will detect the status and refresh all necessary data. | |
1705 | + In this mode, aufs has to ignore the event which is fired by aufs | |
1706 | + itself. | |
1707 | +3. No Extra Validation | |
1708 | + This is the simplest test and doesn't add any additional revalidation | |
7e9cd9fe | 1709 | + test, and skip the revalidation in step 4. It is useful and improves |
53392da6 AM |
1710 | + aufs performance when system surely hide the aufs branches from user, |
1711 | + by over-mounting something (or another method). | |
1712 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt | |
1713 | --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1714 | +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-06-28 17:35:44.344717109 +0200 |
7e9cd9fe | 1715 | @@ -0,0 +1,74 @@ |
53392da6 | 1716 | + |
2000de60 | 1717 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1718 | +# |
1719 | +# This program is free software; you can redistribute it and/or modify | |
1720 | +# it under the terms of the GNU General Public License as published by | |
1721 | +# the Free Software Foundation; either version 2 of the License, or | |
1722 | +# (at your option) any later version. | |
1723 | +# | |
1724 | +# This program is distributed in the hope that it will be useful, | |
1725 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1726 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1727 | +# GNU General Public License for more details. | |
1728 | +# | |
1729 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1730 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1731 | + |
1732 | +Branch Manipulation | |
1733 | + | |
1734 | +Since aufs supports dynamic branch manipulation, ie. add/remove a branch | |
1735 | +and changing its permission/attribute, there are a lot of works to do. | |
1736 | + | |
1737 | + | |
1738 | +Add a Branch | |
1739 | +---------------------------------------------------------------------- | |
1740 | +o Confirm the adding dir exists outside of aufs, including loopback | |
7e9cd9fe | 1741 | + mount, and its various attributes. |
53392da6 AM |
1742 | +o Initialize the xino file and whiteout bases if necessary. |
1743 | + See struct.txt. | |
1744 | + | |
1745 | +o Check the owner/group/mode of the directory | |
1746 | + When the owner/group/mode of the adding directory differs from the | |
1747 | + existing branch, aufs issues a warning because it may impose a | |
1748 | + security risk. | |
1749 | + For example, when a upper writable branch has a world writable empty | |
1750 | + top directory, a malicious user can create any files on the writable | |
1751 | + branch directly, like copy-up and modify manually. If something like | |
1752 | + /etc/{passwd,shadow} exists on the lower readonly branch but the upper | |
1753 | + writable branch, and the writable branch is world-writable, then a | |
1754 | + malicious guy may create /etc/passwd on the writable branch directly | |
1755 | + and the infected file will be valid in aufs. | |
7e9cd9fe | 1756 | + I am afraid it can be a security issue, but aufs can do nothing except |
53392da6 AM |
1757 | + producing a warning. |
1758 | + | |
1759 | + | |
1760 | +Delete a Branch | |
1761 | +---------------------------------------------------------------------- | |
1762 | +o Confirm the deleting branch is not busy | |
1763 | + To be general, there is one merit to adopt "remount" interface to | |
1764 | + manipulate branches. It is to discard caches. At deleting a branch, | |
1765 | + aufs checks the still cached (and connected) dentries and inodes. If | |
1766 | + there are any, then they are all in-use. An inode without its | |
1767 | + corresponding dentry can be alive alone (for example, inotify/fsnotify case). | |
1768 | + | |
1769 | + For the cached one, aufs checks whether the same named entry exists on | |
1770 | + other branches. | |
1771 | + If the cached one is a directory, because aufs provides a merged view | |
1772 | + to users, as long as one dir is left on any branch aufs can show the | |
1773 | + dir to users. In this case, the branch can be removed from aufs. | |
1774 | + Otherwise aufs rejects deleting the branch. | |
1775 | + | |
1776 | + If any file on the deleting branch is opened by aufs, then aufs | |
1777 | + rejects deleting. | |
1778 | + | |
1779 | + | |
1780 | +Modify the Permission of a Branch | |
1781 | +---------------------------------------------------------------------- | |
1782 | +o Re-initialize or remove the xino file and whiteout bases if necessary. | |
1783 | + See struct.txt. | |
1784 | + | |
1785 | +o rw --> ro: Confirm the modifying branch is not busy | |
1786 | + Aufs rejects the request if any of these conditions are true. | |
1787 | + - a file on the branch is mmap-ed. | |
1788 | + - a regular file on the branch is opened for write and there is no | |
1789 | + same named entry on the upper branch. | |
1790 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt | |
1791 | --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1792 | +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-06-28 17:35:44.344717109 +0200 |
523b37e3 | 1793 | @@ -0,0 +1,64 @@ |
53392da6 | 1794 | + |
2000de60 | 1795 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1796 | +# |
1797 | +# This program is free software; you can redistribute it and/or modify | |
1798 | +# it under the terms of the GNU General Public License as published by | |
1799 | +# the Free Software Foundation; either version 2 of the License, or | |
1800 | +# (at your option) any later version. | |
1801 | +# | |
1802 | +# This program is distributed in the hope that it will be useful, | |
1803 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1804 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1805 | +# GNU General Public License for more details. | |
1806 | +# | |
1807 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1808 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1809 | + |
1810 | +Policies to Select One among Multiple Writable Branches | |
1811 | +---------------------------------------------------------------------- | |
1812 | +When the number of writable branch is more than one, aufs has to decide | |
1813 | +the target branch for file creation or copy-up. By default, the highest | |
1814 | +writable branch which has the parent (or ancestor) dir of the target | |
1815 | +file is chosen (top-down-parent policy). | |
1816 | +By user's request, aufs implements some other policies to select the | |
7e9cd9fe AM |
1817 | +writable branch, for file creation several policies, round-robin, |
1818 | +most-free-space, and other policies. For copy-up, top-down-parent, | |
1819 | +bottom-up-parent, bottom-up and others. | |
53392da6 AM |
1820 | + |
1821 | +As expected, the round-robin policy selects the branch in circular. When | |
1822 | +you have two writable branches and creates 10 new files, 5 files will be | |
1823 | +created for each branch. mkdir(2) systemcall is an exception. When you | |
1824 | +create 10 new directories, all will be created on the same branch. | |
1825 | +And the most-free-space policy selects the one which has most free | |
1826 | +space among the writable branches. The amount of free space will be | |
1827 | +checked by aufs internally, and users can specify its time interval. | |
1828 | + | |
1829 | +The policies for copy-up is more simple, | |
1830 | +top-down-parent is equivalent to the same named on in create policy, | |
1831 | +bottom-up-parent selects the writable branch where the parent dir | |
1832 | +exists and the nearest upper one from the copyup-source, | |
1833 | +bottom-up selects the nearest upper writable branch from the | |
1834 | +copyup-source, regardless the existence of the parent dir. | |
1835 | + | |
1836 | +There are some rules or exceptions to apply these policies. | |
1837 | +- If there is a readonly branch above the policy-selected branch and | |
1838 | + the parent dir is marked as opaque (a variation of whiteout), or the | |
1839 | + target (creating) file is whiteout-ed on the upper readonly branch, | |
1840 | + then the result of the policy is ignored and the target file will be | |
1841 | + created on the nearest upper writable branch than the readonly branch. | |
1842 | +- If there is a writable branch above the policy-selected branch and | |
1843 | + the parent dir is marked as opaque or the target file is whiteouted | |
1844 | + on the branch, then the result of the policy is ignored and the target | |
1845 | + file will be created on the highest one among the upper writable | |
1846 | + branches who has diropq or whiteout. In case of whiteout, aufs removes | |
1847 | + it as usual. | |
1848 | +- link(2) and rename(2) systemcalls are exceptions in every policy. | |
1849 | + They try selecting the branch where the source exists as possible | |
1850 | + since copyup a large file will take long time. If it can't be, | |
1851 | + ie. the branch where the source exists is readonly, then they will | |
1852 | + follow the copyup policy. | |
1853 | +- There is an exception for rename(2) when the target exists. | |
1854 | + If the rename target exists, aufs compares the index of the branches | |
1855 | + where the source and the target exists and selects the higher | |
1856 | + one. If the selected branch is readonly, then aufs follows the | |
1857 | + copyup policy. | |
076b876e AM |
1858 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt |
1859 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1860 | +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-06-28 17:35:44.344717109 +0200 |
076b876e AM |
1861 | @@ -0,0 +1,120 @@ |
1862 | + | |
2000de60 | 1863 | +# Copyright (C) 2011-2015 Junjiro R. Okajima |
076b876e AM |
1864 | +# |
1865 | +# This program is free software; you can redistribute it and/or modify | |
1866 | +# it under the terms of the GNU General Public License as published by | |
1867 | +# the Free Software Foundation; either version 2 of the License, or | |
1868 | +# (at your option) any later version. | |
1869 | +# | |
1870 | +# This program is distributed in the hope that it will be useful, | |
1871 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1872 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1873 | +# GNU General Public License for more details. | |
1874 | +# | |
1875 | +# You should have received a copy of the GNU General Public License | |
1876 | +# along with this program; if not, write to the Free Software | |
1877 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1878 | + | |
1879 | + | |
1880 | +File-based Hierarchical Storage Management (FHSM) | |
1881 | +---------------------------------------------------------------------- | |
1882 | +Hierarchical Storage Management (or HSM) is a well-known feature in the | |
1883 | +storage world. Aufs provides this feature as file-based with multiple | |
7e9cd9fe | 1884 | +writable branches, based upon the principle of "Colder, the Lower". |
076b876e | 1885 | +Here the word "colder" means that the less used files, and "lower" means |
7e9cd9fe | 1886 | +that the position in the order of the stacked branches vertically. |
076b876e AM |
1887 | +These multiple writable branches are prioritized, ie. the topmost one |
1888 | +should be the fastest drive and be used heavily. | |
1889 | + | |
1890 | +o Characters in aufs FHSM story | |
1891 | +- aufs itself and a new branch attribute. | |
1892 | +- a new ioctl interface to move-down and to establish a connection with | |
1893 | + the daemon ("move-down" is a converse of "copy-up"). | |
1894 | +- userspace tool and daemon. | |
1895 | + | |
1896 | +The userspace daemon establishes a connection with aufs and waits for | |
1897 | +the notification. The notified information is very similar to struct | |
1898 | +statfs containing the number of consumed blocks and inodes. | |
1899 | +When the consumed blocks/inodes of a branch exceeds the user-specified | |
1900 | +upper watermark, the daemon activates its move-down process until the | |
1901 | +consumed blocks/inodes reaches the user-specified lower watermark. | |
1902 | + | |
1903 | +The actual move-down is done by aufs based upon the request from | |
1904 | +user-space since we need to maintain the inode number and the internal | |
1905 | +pointer arrays in aufs. | |
1906 | + | |
1907 | +Currently aufs FHSM handles the regular files only. Additionally they | |
1908 | +must not be hard-linked nor pseudo-linked. | |
1909 | + | |
1910 | + | |
1911 | +o Cowork of aufs and the user-space daemon | |
1912 | + During the userspace daemon established the connection, aufs sends a | |
1913 | + small notification to it whenever aufs writes something into the | |
1914 | + writable branch. But it may cost high since aufs issues statfs(2) | |
1915 | + internally. So user can specify a new option to cache the | |
1916 | + info. Actually the notification is controlled by these factors. | |
1917 | + + the specified cache time. | |
1918 | + + classified as "force" by aufs internally. | |
1919 | + Until the specified time expires, aufs doesn't send the info | |
1920 | + except the forced cases. When aufs decide forcing, the info is always | |
1921 | + notified to userspace. | |
1922 | + For example, the number of free inodes is generally large enough and | |
1923 | + the shortage of it happens rarely. So aufs doesn't force the | |
1924 | + notification when creating a new file, directory and others. This is | |
1925 | + the typical case which aufs doesn't force. | |
1926 | + When aufs writes the actual filedata and the files consumes any of new | |
1927 | + blocks, the aufs forces notifying. | |
1928 | + | |
1929 | + | |
1930 | +o Interfaces in aufs | |
1931 | +- New branch attribute. | |
1932 | + + fhsm | |
1933 | + Specifies that the branch is managed by FHSM feature. In other word, | |
1934 | + participant in the FHSM. | |
1935 | + When nofhsm is set to the branch, it will not be the source/target | |
1936 | + branch of the move-down operation. This attribute is set | |
1937 | + independently from coo and moo attributes, and if you want full | |
1938 | + FHSM, you should specify them as well. | |
1939 | +- New mount option. | |
1940 | + + fhsm_sec | |
1941 | + Specifies a second to suppress many less important info to be | |
1942 | + notified. | |
1943 | +- New ioctl. | |
1944 | + + AUFS_CTL_FHSM_FD | |
1945 | + create a new file descriptor which userspace can read the notification | |
1946 | + (a subset of struct statfs) from aufs. | |
1947 | +- Module parameter 'brs' | |
1948 | + It has to be set to 1. Otherwise the new mount option 'fhsm' will not | |
1949 | + be set. | |
1950 | +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs | |
1951 | + When there are two or more branches with fhsm attributes, | |
1952 | + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs | |
1953 | + terminates it. As a result of remounting and branch-manipulation, the | |
1954 | + number of branches with fhsm attribute can be one. In this case, | |
1955 | + /sbin/mount.aufs will terminate the user-space daemon. | |
1956 | + | |
1957 | + | |
1958 | +Finally the operation is done as these steps in kernel-space. | |
1959 | +- make sure that, | |
1960 | + + no one else is using the file. | |
1961 | + + the file is not hard-linked. | |
1962 | + + the file is not pseudo-linked. | |
1963 | + + the file is a regular file. | |
1964 | + + the parent dir is not opaqued. | |
1965 | +- find the target writable branch. | |
1966 | +- make sure the file is not whiteout-ed by the upper (than the target) | |
1967 | + branch. | |
1968 | +- make the parent dir on the target branch. | |
1969 | +- mutex lock the inode on the branch. | |
1970 | +- unlink the whiteout on the target branch (if exists). | |
1971 | +- lookup and create the whiteout-ed temporary name on the target branch. | |
1972 | +- copy the file as the whiteout-ed temporary name on the target branch. | |
1973 | +- rename the whiteout-ed temporary name to the original name. | |
1974 | +- unlink the file on the source branch. | |
1975 | +- maintain the internal pointer array and the external inode number | |
1976 | + table (XINO). | |
1977 | +- maintain the timestamps and other attributes of the parent dir and the | |
1978 | + file. | |
1979 | + | |
1980 | +And of course, in every step, an error may happen. So the operation | |
1981 | +should restore the original file state after an error happens. | |
53392da6 AM |
1982 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt |
1983 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 1984 | +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-06-28 17:35:44.344717109 +0200 |
b912730e | 1985 | @@ -0,0 +1,72 @@ |
53392da6 | 1986 | + |
2000de60 | 1987 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1988 | +# |
1989 | +# This program is free software; you can redistribute it and/or modify | |
1990 | +# it under the terms of the GNU General Public License as published by | |
1991 | +# the Free Software Foundation; either version 2 of the License, or | |
1992 | +# (at your option) any later version. | |
1993 | +# | |
1994 | +# This program is distributed in the hope that it will be useful, | |
1995 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1996 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1997 | +# GNU General Public License for more details. | |
1998 | +# | |
1999 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2000 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2001 | + |
2002 | +mmap(2) -- File Memory Mapping | |
2003 | +---------------------------------------------------------------------- | |
2004 | +In aufs, the file-mapped pages are handled by a branch fs directly, no | |
2005 | +interaction with aufs. It means aufs_mmap() calls the branch fs's | |
2006 | +->mmap(). | |
2007 | +This approach is simple and good, but there is one problem. | |
7e9cd9fe | 2008 | +Under /proc, several entries show the mmapped files by its path (with |
53392da6 AM |
2009 | +device and inode number), and the printed path will be the path on the |
2010 | +branch fs's instead of virtual aufs's. | |
2011 | +This is not a problem in most cases, but some utilities lsof(1) (and its | |
2012 | +user) may expect the path on aufs. | |
2013 | + | |
2014 | +To address this issue, aufs adds a new member called vm_prfile in struct | |
2015 | +vm_area_struct (and struct vm_region). The original vm_file points to | |
2016 | +the file on the branch fs in order to handle everything correctly as | |
2017 | +usual. The new vm_prfile points to a virtual file in aufs, and the | |
2018 | +show-functions in procfs refers to vm_prfile if it is set. | |
2019 | +Also we need to maintain several other places where touching vm_file | |
2020 | +such like | |
2021 | +- fork()/clone() copies vma and the reference count of vm_file is | |
2022 | + incremented. | |
2023 | +- merging vma maintains the ref count too. | |
2024 | + | |
7e9cd9fe | 2025 | +This is not a good approach. It just fakes the printed path. But it |
53392da6 AM |
2026 | +leaves all behaviour around f_mapping unchanged. This is surely an |
2027 | +advantage. | |
2028 | +Actually aufs had adopted another complicated approach which calls | |
2029 | +generic_file_mmap() and handles struct vm_operations_struct. In this | |
2030 | +approach, aufs met a hard problem and I could not solve it without | |
2031 | +switching the approach. | |
b912730e AM |
2032 | + |
2033 | +There may be one more another approach which is | |
2034 | +- bind-mount the branch-root onto the aufs-root internally | |
2035 | +- grab the new vfsmount (ie. struct mount) | |
2036 | +- lazy-umount the branch-root internally | |
2037 | +- in open(2) the aufs-file, open the branch-file with the hidden | |
2038 | + vfsmount (instead of the original branch's vfsmount) | |
2039 | +- ideally this "bind-mount and lazy-umount" should be done atomically, | |
2040 | + but it may be possible from userspace by the mount helper. | |
2041 | + | |
2042 | +Adding the internal hidden vfsmount and using it in opening a file, the | |
2043 | +file path under /proc will be printed correctly. This approach looks | |
2044 | +smarter, but is not possible I am afraid. | |
2045 | +- aufs-root may be bind-mount later. when it happens, another hidden | |
2046 | + vfsmount will be required. | |
2047 | +- it is hard to get the chance to bind-mount and lazy-umount | |
2048 | + + in kernel-space, FS can have vfsmount in open(2) via | |
2049 | + file->f_path, and aufs can know its vfsmount. But several locks are | |
2050 | + already acquired, and if aufs tries to bind-mount and lazy-umount | |
2051 | + here, then it may cause a deadlock. | |
2052 | + + in user-space, bind-mount doesn't invoke the mount helper. | |
2053 | +- since /proc shows dev and ino, aufs has to give vma these info. it | |
2054 | + means a new member vm_prinode will be necessary. this is essentially | |
2055 | + equivalent to vm_prfile described above. | |
2056 | + | |
2057 | +I have to give up this "looks-smater" approach. | |
c1595e42 JR |
2058 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt |
2059 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 2060 | +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-06-28 17:35:44.344717109 +0200 |
c1595e42 JR |
2061 | @@ -0,0 +1,96 @@ |
2062 | + | |
2000de60 | 2063 | +# Copyright (C) 2014-2015 Junjiro R. Okajima |
c1595e42 JR |
2064 | +# |
2065 | +# This program is free software; you can redistribute it and/or modify | |
2066 | +# it under the terms of the GNU General Public License as published by | |
2067 | +# the Free Software Foundation; either version 2 of the License, or | |
2068 | +# (at your option) any later version. | |
2069 | +# | |
2070 | +# This program is distributed in the hope that it will be useful, | |
2071 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2072 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2073 | +# GNU General Public License for more details. | |
2074 | +# | |
2075 | +# You should have received a copy of the GNU General Public License | |
2076 | +# along with this program; if not, write to the Free Software | |
2077 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2078 | + | |
2079 | + | |
2080 | +Listing XATTR/EA and getting the value | |
2081 | +---------------------------------------------------------------------- | |
2082 | +For the inode standard attributes (owner, group, timestamps, etc.), aufs | |
2083 | +shows the values from the topmost existing file. This behaviour is good | |
7e9cd9fe | 2084 | +for the non-dir entries since the bahaviour exactly matches the shown |
c1595e42 JR |
2085 | +information. But for the directories, aufs considers all the same named |
2086 | +entries on the lower branches. Which means, if one of the lower entry | |
2087 | +rejects readdir call, then aufs returns an error even if the topmost | |
2088 | +entry allows it. This behaviour is necessary to respect the branch fs's | |
2089 | +security, but can make users confused since the user-visible standard | |
2090 | +attributes don't match the behaviour. | |
2091 | +To address this issue, aufs has a mount option called dirperm1 which | |
2092 | +checks the permission for the topmost entry only, and ignores the lower | |
2093 | +entry's permission. | |
2094 | + | |
2095 | +A similar issue can happen around XATTR. | |
2096 | +getxattr(2) and listxattr(2) families behave as if dirperm1 option is | |
7e9cd9fe AM |
2097 | +always set. Otherwise these very unpleasant situation would happen. |
2098 | +- listxattr(2) may return the duplicated entries. | |
c1595e42 JR |
2099 | +- users may not be able to remove or reset the XATTR forever, |
2100 | + | |
2101 | + | |
2102 | +XATTR/EA support in the internal (copy,move)-(up,down) | |
2103 | +---------------------------------------------------------------------- | |
7e9cd9fe | 2104 | +Generally the extended attributes of inode are categorized as these. |
c1595e42 JR |
2105 | +- "security" for LSM and capability. |
2106 | +- "system" for posix ACL, 'acl' mount option is required for the branch | |
2107 | + fs generally. | |
2108 | +- "trusted" for userspace, CAP_SYS_ADMIN is required. | |
2109 | +- "user" for userspace, 'user_xattr' mount option is required for the | |
2110 | + branch fs generally. | |
2111 | + | |
2112 | +Moreover there are some other categories. Aufs handles these rather | |
2113 | +unpopular categories as the ordinary ones, ie. there is no special | |
2114 | +condition nor exception. | |
2115 | + | |
2116 | +In copy-up, the support for XATTR on the dst branch may differ from the | |
2117 | +src branch. In this case, the copy-up operation will get an error and | |
7e9cd9fe AM |
2118 | +the original user operation which triggered the copy-up will fail. It |
2119 | +can happen that even all copy-up will fail. | |
c1595e42 JR |
2120 | +When both of src and dst branches support XATTR and if an error occurs |
2121 | +during copying XATTR, then the copy-up should fail obviously. That is a | |
2122 | +good reason and aufs should return an error to userspace. But when only | |
7e9cd9fe | 2123 | +the src branch support that XATTR, aufs should not return an error. |
c1595e42 JR |
2124 | +For example, the src branch supports ACL but the dst branch doesn't |
2125 | +because the dst branch may natively un-support it or temporary | |
2126 | +un-support it due to "noacl" mount option. Of course, the dst branch fs | |
2127 | +may NOT return an error even if the XATTR is not supported. It is | |
2128 | +totally up to the branch fs. | |
2129 | + | |
2130 | +Anyway when the aufs internal copy-up gets an error from the dst branch | |
2131 | +fs, then aufs tries removing the just copied entry and returns the error | |
2132 | +to the userspace. The worst case of this situation will be all copy-up | |
2133 | +will fail. | |
2134 | + | |
2135 | +For the copy-up operation, there two basic approaches. | |
2136 | +- copy the specified XATTR only (by category above), and return the | |
7e9cd9fe | 2137 | + error unconditionally if it happens. |
c1595e42 JR |
2138 | +- copy all XATTR, and ignore the error on the specified category only. |
2139 | + | |
2140 | +In order to support XATTR and to implement the correct behaviour, aufs | |
7e9cd9fe AM |
2141 | +chooses the latter approach and introduces some new branch attributes, |
2142 | +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth". | |
c1595e42 | 2143 | +They correspond to the XATTR namespaces (see above). Additionally, to be |
7e9cd9fe AM |
2144 | +convenient, "icex" is also provided which means all "icex*" attributes |
2145 | +are set (here the word "icex" stands for "ignore copy-error on XATTR"). | |
c1595e42 JR |
2146 | + |
2147 | +The meaning of these attributes is to ignore the error from setting | |
2148 | +XATTR on that branch. | |
2149 | +Note that aufs tries copying all XATTR unconditionally, and ignores the | |
2150 | +error from the dst branch according to the specified attributes. | |
2151 | + | |
2152 | +Some XATTR may have its default value. The default value may come from | |
2153 | +the parent dir or the environment. If the default value is set at the | |
2154 | +file creating-time, it will be overwritten by copy-up. | |
2155 | +Some contradiction may happen I am afraid. | |
2156 | +Do we need another attribute to stop copying XATTR? I am unsure. For | |
2157 | +now, aufs implements the branch attributes to ignore the error. | |
53392da6 AM |
2158 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt |
2159 | --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 2160 | +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-06-28 17:35:44.344717109 +0200 |
523b37e3 | 2161 | @@ -0,0 +1,58 @@ |
53392da6 | 2162 | + |
2000de60 | 2163 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
2164 | +# |
2165 | +# This program is free software; you can redistribute it and/or modify | |
2166 | +# it under the terms of the GNU General Public License as published by | |
2167 | +# the Free Software Foundation; either version 2 of the License, or | |
2168 | +# (at your option) any later version. | |
2169 | +# | |
2170 | +# This program is distributed in the hope that it will be useful, | |
2171 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2172 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2173 | +# GNU General Public License for more details. | |
2174 | +# | |
2175 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2176 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2177 | + |
2178 | +Export Aufs via NFS | |
2179 | +---------------------------------------------------------------------- | |
2180 | +Here is an approach. | |
2181 | +- like xino/xib, add a new file 'xigen' which stores aufs inode | |
2182 | + generation. | |
2183 | +- iget_locked(): initialize aufs inode generation for a new inode, and | |
2184 | + store it in xigen file. | |
2185 | +- destroy_inode(): increment aufs inode generation and store it in xigen | |
2186 | + file. it is necessary even if it is not unlinked, because any data of | |
2187 | + inode may be changed by UDBA. | |
2188 | +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise | |
2189 | + build file handle by | |
2190 | + + branch id (4 bytes) | |
2191 | + + superblock generation (4 bytes) | |
2192 | + + inode number (4 or 8 bytes) | |
2193 | + + parent dir inode number (4 or 8 bytes) | |
2194 | + + inode generation (4 bytes)) | |
2195 | + + return value of exportfs_encode_fh() for the parent on a branch (4 | |
2196 | + bytes) | |
2197 | + + file handle for a branch (by exportfs_encode_fh()) | |
2198 | +- fh_to_dentry(): | |
2199 | + + find the index of a branch from its id in handle, and check it is | |
2200 | + still exist in aufs. | |
2201 | + + 1st level: get the inode number from handle and search it in cache. | |
7e9cd9fe AM |
2202 | + + 2nd level: if not found in cache, get the parent inode number from |
2203 | + the handle and search it in cache. and then open the found parent | |
2204 | + dir, find the matching inode number by vfs_readdir() and get its | |
2205 | + name, and call lookup_one_len() for the target dentry. | |
53392da6 AM |
2206 | + + 3rd level: if the parent dir is not cached, call |
2207 | + exportfs_decode_fh() for a branch and get the parent on a branch, | |
2208 | + build a pathname of it, convert it a pathname in aufs, call | |
2209 | + path_lookup(). now aufs gets a parent dir dentry, then handle it as | |
2210 | + the 2nd level. | |
2211 | + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount | |
2212 | + for every branch, but not itself. to get this, (currently) aufs | |
2213 | + searches in current->nsproxy->mnt_ns list. it may not be a good | |
2214 | + idea, but I didn't get other approach. | |
2215 | + + test the generation of the gotten inode. | |
2216 | +- every inode operation: they may get EBUSY due to UDBA. in this case, | |
2217 | + convert it into ESTALE for NFSD. | |
2218 | +- readdir(): call lockdep_on/off() because filldir in NFSD calls | |
2219 | + lookup_one_len(), vfs_getattr(), encode_fh() and others. | |
2220 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt | |
2221 | --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 2222 | +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-06-28 17:35:44.344717109 +0200 |
523b37e3 | 2223 | @@ -0,0 +1,52 @@ |
53392da6 | 2224 | + |
2000de60 | 2225 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
2226 | +# |
2227 | +# This program is free software; you can redistribute it and/or modify | |
2228 | +# it under the terms of the GNU General Public License as published by | |
2229 | +# the Free Software Foundation; either version 2 of the License, or | |
2230 | +# (at your option) any later version. | |
2231 | +# | |
2232 | +# This program is distributed in the hope that it will be useful, | |
2233 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2234 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2235 | +# GNU General Public License for more details. | |
2236 | +# | |
2237 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2238 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2239 | + |
2240 | +Show Whiteout Mode (shwh) | |
2241 | +---------------------------------------------------------------------- | |
2242 | +Generally aufs hides the name of whiteouts. But in some cases, to show | |
2243 | +them is very useful for users. For instance, creating a new middle layer | |
2244 | +(branch) by merging existing layers. | |
2245 | + | |
2246 | +(borrowing aufs1 HOW-TO from a user, Michael Towers) | |
2247 | +When you have three branches, | |
2248 | +- Bottom: 'system', squashfs (underlying base system), read-only | |
2249 | +- Middle: 'mods', squashfs, read-only | |
2250 | +- Top: 'overlay', ram (tmpfs), read-write | |
2251 | + | |
2252 | +The top layer is loaded at boot time and saved at shutdown, to preserve | |
2253 | +the changes made to the system during the session. | |
2254 | +When larger changes have been made, or smaller changes have accumulated, | |
2255 | +the size of the saved top layer data grows. At this point, it would be | |
2256 | +nice to be able to merge the two overlay branches ('mods' and 'overlay') | |
2257 | +and rewrite the 'mods' squashfs, clearing the top layer and thus | |
2258 | +restoring save and load speed. | |
2259 | + | |
2260 | +This merging is simplified by the use of another aufs mount, of just the | |
2261 | +two overlay branches using the 'shwh' option. | |
2262 | +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \ | |
2263 | + aufs /livesys/merge_union | |
2264 | + | |
2265 | +A merged view of these two branches is then available at | |
2266 | +/livesys/merge_union, and the new feature is that the whiteouts are | |
2267 | +visible! | |
2268 | +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable | |
2269 | +writing to all branches. Also the default mode for all branches is 'ro'. | |
2270 | +It is now possible to save the combined contents of the two overlay | |
2271 | +branches to a new squashfs, e.g.: | |
2272 | +# mksquashfs /livesys/merge_union /path/to/newmods.squash | |
2273 | + | |
2274 | +This new squashfs archive can be stored on the boot device and the | |
2275 | +initramfs will use it to replace the old one at the next boot. | |
2276 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt | |
2277 | --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 2278 | +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-06-28 17:35:44.344717109 +0200 |
7e9cd9fe | 2279 | @@ -0,0 +1,47 @@ |
53392da6 | 2280 | + |
2000de60 | 2281 | +# Copyright (C) 2010-2015 Junjiro R. Okajima |
53392da6 AM |
2282 | +# |
2283 | +# This program is free software; you can redistribute it and/or modify | |
2284 | +# it under the terms of the GNU General Public License as published by | |
2285 | +# the Free Software Foundation; either version 2 of the License, or | |
2286 | +# (at your option) any later version. | |
2287 | +# | |
2288 | +# This program is distributed in the hope that it will be useful, | |
2289 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2290 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2291 | +# GNU General Public License for more details. | |
2292 | +# | |
2293 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2294 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2295 | + |
2296 | +Dynamically customizable FS operations | |
2297 | +---------------------------------------------------------------------- | |
2298 | +Generally FS operations (struct inode_operations, struct | |
2299 | +address_space_operations, struct file_operations, etc.) are defined as | |
2300 | +"static const", but it never means that FS have only one set of | |
2301 | +operation. Some FS have multiple sets of them. For instance, ext2 has | |
2302 | +three sets, one for XIP, for NOBH, and for normal. | |
2303 | +Since aufs overrides and redirects these operations, sometimes aufs has | |
7e9cd9fe | 2304 | +to change its behaviour according to the branch FS type. More importantly |
53392da6 AM |
2305 | +VFS acts differently if a function (member in the struct) is set or |
2306 | +not. It means aufs should have several sets of operations and select one | |
2307 | +among them according to the branch FS definition. | |
2308 | + | |
7e9cd9fe | 2309 | +In order to solve this problem and not to affect the behaviour of VFS, |
53392da6 | 2310 | +aufs defines these operations dynamically. For instance, aufs defines |
7e9cd9fe AM |
2311 | +dummy direct_IO function for struct address_space_operations, but it may |
2312 | +not be set to the address_space_operations actually. When the branch FS | |
2313 | +doesn't have it, aufs doesn't set it to its address_space_operations | |
2314 | +while the function definition itself is still alive. So the behaviour | |
2315 | +itself will not change, and it will return an error when direct_IO is | |
2316 | +not set. | |
53392da6 AM |
2317 | + |
2318 | +The lifetime of these dynamically generated operation object is | |
2319 | +maintained by aufs branch object. When the branch is removed from aufs, | |
2320 | +the reference counter of the object is decremented. When it reaches | |
2321 | +zero, the dynamically generated operation object will be freed. | |
2322 | + | |
7e9cd9fe AM |
2323 | +This approach is designed to support AIO (io_submit), Direct I/O and |
2324 | +XIP (DAX) mainly. | |
2325 | +Currently this approach is applied to address_space_operations for | |
2326 | +regular files only. | |
53392da6 AM |
2327 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README |
2328 | --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
2329 | +++ linux/Documentation/filesystems/aufs/README 2015-06-28 17:35:44.344717109 +0200 |
2330 | @@ -0,0 +1,383 @@ | |
53392da6 | 2331 | + |
5527c038 | 2332 | +Aufs4 -- advanced multi layered unification filesystem version 4.x |
53392da6 AM |
2333 | +http://aufs.sf.net |
2334 | +Junjiro R. Okajima | |
2335 | + | |
2336 | + | |
2337 | +0. Introduction | |
2338 | +---------------------------------------- | |
2339 | +In the early days, aufs was entirely re-designed and re-implemented | |
7e9cd9fe | 2340 | +Unionfs Version 1.x series. Adding many original ideas, approaches, |
53392da6 AM |
2341 | +improvements and implementations, it becomes totally different from |
2342 | +Unionfs while keeping the basic features. | |
2343 | +Recently, Unionfs Version 2.x series begin taking some of the same | |
2344 | +approaches to aufs1's. | |
2345 | +Unionfs is being developed by Professor Erez Zadok at Stony Brook | |
2346 | +University and his team. | |
2347 | + | |
5527c038 | 2348 | +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3. |
53392da6 AM |
2349 | +If you want older kernel version support, try aufs2-2.6.git or |
2350 | +aufs2-standalone.git repository, aufs1 from CVS on SourceForge. | |
2351 | + | |
2352 | +Note: it becomes clear that "Aufs was rejected. Let's give it up." | |
38d290e6 JR |
2353 | + According to Christoph Hellwig, linux rejects all union-type |
2354 | + filesystems but UnionMount. | |
53392da6 AM |
2355 | +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2> |
2356 | + | |
38d290e6 JR |
2357 | +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and |
2358 | + UnionMount, and he pointed out an issue around a directory mutex | |
2359 | + lock and aufs addressed it. But it is still unsure whether aufs will | |
2360 | + be merged (or any other union solution). | |
076b876e | 2361 | +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1> |
38d290e6 | 2362 | + |
53392da6 AM |
2363 | + |
2364 | +1. Features | |
2365 | +---------------------------------------- | |
2366 | +- unite several directories into a single virtual filesystem. The member | |
2367 | + directory is called as a branch. | |
2368 | +- you can specify the permission flags to the branch, which are 'readonly', | |
2369 | + 'readwrite' and 'whiteout-able.' | |
2370 | +- by upper writable branch, internal copyup and whiteout, files/dirs on | |
2371 | + readonly branch are modifiable logically. | |
2372 | +- dynamic branch manipulation, add, del. | |
2373 | +- etc... | |
2374 | + | |
7e9cd9fe AM |
2375 | +Also there are many enhancements in aufs, such as: |
2376 | +- test only the highest one for the directory permission (dirperm1) | |
2377 | +- copyup on open (coo=) | |
2378 | +- 'move' policy for copy-up between two writable branches, after | |
2379 | + checking free space. | |
2380 | +- xattr, acl | |
53392da6 AM |
2381 | +- readdir(3) in userspace. |
2382 | +- keep inode number by external inode number table | |
2383 | +- keep the timestamps of file/dir in internal copyup operation | |
2384 | +- seekable directory, supporting NFS readdir. | |
2385 | +- whiteout is hardlinked in order to reduce the consumption of inodes | |
2386 | + on branch | |
2387 | +- do not copyup, nor create a whiteout when it is unnecessary | |
2388 | +- revert a single systemcall when an error occurs in aufs | |
2389 | +- remount interface instead of ioctl | |
2390 | +- maintain /etc/mtab by an external command, /sbin/mount.aufs. | |
2391 | +- loopback mounted filesystem as a branch | |
2392 | +- kernel thread for removing the dir who has a plenty of whiteouts | |
2393 | +- support copyup sparse file (a file which has a 'hole' in it) | |
2394 | +- default permission flags for branches | |
2395 | +- selectable permission flags for ro branch, whether whiteout can | |
2396 | + exist or not | |
2397 | +- export via NFS. | |
2398 | +- support <sysfs>/fs/aufs and <debugfs>/aufs. | |
2399 | +- support multiple writable branches, some policies to select one | |
2400 | + among multiple writable branches. | |
2401 | +- a new semantics for link(2) and rename(2) to support multiple | |
2402 | + writable branches. | |
2403 | +- no glibc changes are required. | |
2404 | +- pseudo hardlink (hardlink over branches) | |
2405 | +- allow a direct access manually to a file on branch, e.g. bypassing aufs. | |
2406 | + including NFS or remote filesystem branch. | |
2407 | +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX. | |
2408 | +- and more... | |
2409 | + | |
5527c038 | 2410 | +Currently these features are dropped temporary from aufs4. |
53392da6 | 2411 | +See design/08plan.txt in detail. |
53392da6 AM |
2412 | +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs |
2413 | + (robr) | |
2414 | +- statistics of aufs thread (/sys/fs/aufs/stat) | |
53392da6 AM |
2415 | + |
2416 | +Features or just an idea in the future (see also design/*.txt), | |
2417 | +- reorder the branch index without del/re-add. | |
2418 | +- permanent xino files for NFSD | |
2419 | +- an option for refreshing the opened files after add/del branches | |
53392da6 AM |
2420 | +- light version, without branch manipulation. (unnecessary?) |
2421 | +- copyup in userspace | |
2422 | +- inotify in userspace | |
2423 | +- readv/writev | |
53392da6 AM |
2424 | + |
2425 | + | |
2426 | +2. Download | |
2427 | +---------------------------------------- | |
5527c038 JR |
2428 | +There are three GIT trees for aufs4, aufs4-linux.git, |
2429 | +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in | |
1e00d052 | 2430 | +"aufs-util.git." |
5527c038 JR |
2431 | +While the aufs-util is always necessary, you need either of aufs4-linux |
2432 | +or aufs4-standalone. | |
1e00d052 | 2433 | + |
5527c038 | 2434 | +The aufs4-linux tree includes the whole linux mainline GIT tree, |
1e00d052 AM |
2435 | +git://git.kernel.org/.../torvalds/linux.git. |
2436 | +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot | |
5527c038 | 2437 | +build aufs4 as an external kernel module. |
2000de60 | 2438 | +Several extra patches are not included in this tree. Only |
5527c038 | 2439 | +aufs4-standalone tree contains them. They are describe in the later |
2000de60 | 2440 | +section "Configuration and Compilation." |
1e00d052 | 2441 | + |
5527c038 | 2442 | +On the other hand, the aufs4-standalone tree has only aufs source files |
53392da6 | 2443 | +and necessary patches, and you can select CONFIG_AUFS_FS=m. |
2000de60 | 2444 | +But you need to apply all aufs patches manually. |
53392da6 | 2445 | + |
5527c038 JR |
2446 | +You will find GIT branches whose name is in form of "aufs4.x" where "x" |
2447 | +represents the linux kernel version, "linux-4.x". For instance, | |
2448 | +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use | |
2449 | +"aufs4.x-rcN" branch. | |
1e00d052 | 2450 | + |
5527c038 | 2451 | +o aufs4-linux tree |
1e00d052 | 2452 | +$ git clone --reference /your/linux/git/tree \ |
5527c038 | 2453 | + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git |
1e00d052 | 2454 | +- if you don't have linux GIT tree, then remove "--reference ..." |
5527c038 JR |
2455 | +$ cd aufs4-linux.git |
2456 | +$ git checkout origin/aufs4.0 | |
53392da6 | 2457 | + |
2000de60 JR |
2458 | +Or You may want to directly git-pull aufs into your linux GIT tree, and |
2459 | +leave the patch-work to GIT. | |
2460 | +$ cd /your/linux/git/tree | |
5527c038 JR |
2461 | +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git |
2462 | +$ git fetch aufs4 | |
2463 | +$ git checkout -b my4.0 v4.0 | |
2464 | +$ (add your local change...) | |
2465 | +$ git pull aufs4 aufs4.0 | |
2466 | +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch. | |
2000de60 | 2467 | +- you may need to solve some conflicts between your_changes and |
5527c038 JR |
2468 | + aufs4.0. in this case, git-rerere is recommended so that you can |
2469 | + solve the similar conflicts automatically when you upgrade to 4.1 or | |
2000de60 JR |
2470 | + later in the future. |
2471 | + | |
5527c038 JR |
2472 | +o aufs4-standalone tree |
2473 | +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git | |
2474 | +$ cd aufs4-standalone.git | |
2475 | +$ git checkout origin/aufs4.0 | |
53392da6 AM |
2476 | + |
2477 | +o aufs-util tree | |
5527c038 JR |
2478 | +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git |
2479 | +- note that the public aufs-util.git is on SourceForge instead of | |
2480 | + GitHUB. | |
53392da6 | 2481 | +$ cd aufs-util.git |
5527c038 | 2482 | +$ git checkout origin/aufs4.0 |
53392da6 | 2483 | + |
5527c038 JR |
2484 | +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY. |
2485 | +The minor version number, 'x' in '4.x', of aufs may not always | |
9dbd164d AM |
2486 | +follow the minor version number of the kernel. |
2487 | +Because changes in the kernel that cause the use of a new | |
2488 | +minor version number do not always require changes to aufs-util. | |
2489 | + | |
2490 | +Since aufs-util has its own minor version number, you may not be | |
2491 | +able to find a GIT branch in aufs-util for your kernel's | |
2492 | +exact minor version number. | |
2493 | +In this case, you should git-checkout the branch for the | |
53392da6 | 2494 | +nearest lower number. |
9dbd164d AM |
2495 | + |
2496 | +For (an unreleased) example: | |
5527c038 JR |
2497 | +If you are using "linux-4.10" and the "aufs4.10" branch |
2498 | +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8" | |
9dbd164d AM |
2499 | +or something numerically smaller is the branch for your kernel. |
2500 | + | |
53392da6 AM |
2501 | +Also you can view all branches by |
2502 | + $ git branch -a | |
2503 | + | |
2504 | + | |
2505 | +3. Configuration and Compilation | |
2506 | +---------------------------------------- | |
2507 | +Make sure you have git-checkout'ed the correct branch. | |
2508 | + | |
5527c038 | 2509 | +For aufs4-linux tree, |
c06a8ce3 | 2510 | +- enable CONFIG_AUFS_FS. |
1e00d052 AM |
2511 | +- set other aufs configurations if necessary. |
2512 | + | |
5527c038 | 2513 | +For aufs4-standalone tree, |
53392da6 AM |
2514 | +There are several ways to build. |
2515 | + | |
2516 | +1. | |
5527c038 JR |
2517 | +- apply ./aufs4-kbuild.patch to your kernel source files. |
2518 | +- apply ./aufs4-base.patch too. | |
2519 | +- apply ./aufs4-mmap.patch too. | |
2520 | +- apply ./aufs4-standalone.patch too, if you have a plan to set | |
2521 | + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch. | |
537831f9 AM |
2522 | +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your |
2523 | + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild. | |
c06a8ce3 | 2524 | +- enable CONFIG_AUFS_FS, you can select either |
53392da6 AM |
2525 | + =m or =y. |
2526 | +- and build your kernel as usual. | |
2527 | +- install the built kernel. | |
c06a8ce3 AM |
2528 | + Note: Since linux-3.9, every filesystem module requires an alias |
2529 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2530 | + modules.aliases file if you set CONFIG_AUFS_FS=m. | |
7eafdf33 AM |
2531 | +- install the header files too by "make headers_install" to the |
2532 | + directory where you specify. By default, it is $PWD/usr. | |
b4510431 | 2533 | + "make help" shows a brief note for headers_install. |
53392da6 AM |
2534 | +- and reboot your system. |
2535 | + | |
2536 | +2. | |
2537 | +- module only (CONFIG_AUFS_FS=m). | |
5527c038 JR |
2538 | +- apply ./aufs4-base.patch to your kernel source files. |
2539 | +- apply ./aufs4-mmap.patch too. | |
2540 | +- apply ./aufs4-standalone.patch too. | |
53392da6 AM |
2541 | +- build your kernel, don't forget "make headers_install", and reboot. |
2542 | +- edit ./config.mk and set other aufs configurations if necessary. | |
b4510431 | 2543 | + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes |
53392da6 AM |
2544 | + every aufs configurations. |
2545 | +- build the module by simple "make". | |
c06a8ce3 AM |
2546 | + Note: Since linux-3.9, every filesystem module requires an alias |
2547 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2548 | + modules.aliases file. | |
53392da6 AM |
2549 | +- you can specify ${KDIR} make variable which points to your kernel |
2550 | + source tree. | |
2551 | +- install the files | |
2552 | + + run "make install" to install the aufs module, or copy the built | |
b4510431 AM |
2553 | + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply). |
2554 | + + run "make install_headers" (instead of headers_install) to install | |
2555 | + the modified aufs header file (you can specify DESTDIR which is | |
2556 | + available in aufs standalone version's Makefile only), or copy | |
2557 | + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever | |
2558 | + you like manually. By default, the target directory is $PWD/usr. | |
5527c038 | 2559 | +- no need to apply aufs4-kbuild.patch, nor copying source files to your |
53392da6 AM |
2560 | + kernel source tree. |
2561 | + | |
b4510431 | 2562 | +Note: The header file aufs_type.h is necessary to build aufs-util |
53392da6 AM |
2563 | + as well as "make headers_install" in the kernel source tree. |
2564 | + headers_install is subject to be forgotten, but it is essentially | |
2565 | + necessary, not only for building aufs-util. | |
2566 | + You may not meet problems without headers_install in some older | |
2567 | + version though. | |
2568 | + | |
2569 | +And then, | |
2570 | +- read README in aufs-util, build and install it | |
9dbd164d AM |
2571 | +- note that your distribution may contain an obsoleted version of |
2572 | + aufs_type.h in /usr/include/linux or something. When you build aufs | |
2573 | + utilities, make sure that your compiler refers the correct aufs header | |
2574 | + file which is built by "make headers_install." | |
53392da6 AM |
2575 | +- if you want to use readdir(3) in userspace or pathconf(3) wrapper, |
2576 | + then run "make install_ulib" too. And refer to the aufs manual in | |
2577 | + detail. | |
2578 | + | |
5527c038 | 2579 | +There several other patches in aufs4-standalone.git. They are all |
38d290e6 | 2580 | +optional. When you meet some problems, they will help you. |
5527c038 | 2581 | +- aufs4-loopback.patch |
38d290e6 JR |
2582 | + Supports a nested loopback mount in a branch-fs. This patch is |
2583 | + unnecessary until aufs produces a message like "you may want to try | |
2584 | + another patch for loopback file". | |
2585 | +- vfs-ino.patch | |
2586 | + Modifies a system global kernel internal function get_next_ino() in | |
2587 | + order to stop assigning 0 for an inode-number. Not directly related to | |
2588 | + aufs, but recommended generally. | |
2589 | +- tmpfs-idr.patch | |
2590 | + Keeps the tmpfs inode number as the lowest value. Effective to reduce | |
2591 | + the size of aufs XINO files for tmpfs branch. Also it prevents the | |
2592 | + duplication of inode number, which is important for backup tools and | |
2593 | + other utilities. When you find aufs XINO files for tmpfs branch | |
2594 | + growing too much, try this patch. | |
2595 | + | |
53392da6 AM |
2596 | + |
2597 | +4. Usage | |
2598 | +---------------------------------------- | |
2599 | +At first, make sure aufs-util are installed, and please read the aufs | |
2600 | +manual, aufs.5 in aufs-util.git tree. | |
2601 | +$ man -l aufs.5 | |
2602 | + | |
2603 | +And then, | |
2604 | +$ mkdir /tmp/rw /tmp/aufs | |
2605 | +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs | |
2606 | + | |
2607 | +Here is another example. The result is equivalent. | |
2608 | +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs | |
2609 | + Or | |
2610 | +# mount -t aufs -o br:/tmp/rw none /tmp/aufs | |
2611 | +# mount -o remount,append:${HOME} /tmp/aufs | |
2612 | + | |
2613 | +Then, you can see whole tree of your home dir through /tmp/aufs. If | |
2614 | +you modify a file under /tmp/aufs, the one on your home directory is | |
2615 | +not affected, instead the same named file will be newly created under | |
2616 | +/tmp/rw. And all of your modification to a file will be applied to | |
2617 | +the one under /tmp/rw. This is called the file based Copy on Write | |
2618 | +(COW) method. | |
2619 | +Aufs mount options are described in aufs.5. | |
2620 | +If you run chroot or something and make your aufs as a root directory, | |
2621 | +then you need to customize the shutdown script. See the aufs manual in | |
2622 | +detail. | |
2623 | + | |
2624 | +Additionally, there are some sample usages of aufs which are a | |
2625 | +diskless system with network booting, and LiveCD over NFS. | |
2626 | +See sample dir in CVS tree on SourceForge. | |
2627 | + | |
2628 | + | |
2629 | +5. Contact | |
2630 | +---------------------------------------- | |
2631 | +When you have any problems or strange behaviour in aufs, please let me | |
2632 | +know with: | |
2633 | +- /proc/mounts (instead of the output of mount(8)) | |
2634 | +- /sys/module/aufs/* | |
2635 | +- /sys/fs/aufs/* (if you have them) | |
2636 | +- /debug/aufs/* (if you have them) | |
2637 | +- linux kernel version | |
2638 | + if your kernel is not plain, for example modified by distributor, | |
2639 | + the url where i can download its source is necessary too. | |
2640 | +- aufs version which was printed at loading the module or booting the | |
2641 | + system, instead of the date you downloaded. | |
2642 | +- configuration (define/undefine CONFIG_AUFS_xxx) | |
2643 | +- kernel configuration or /proc/config.gz (if you have it) | |
2644 | +- behaviour which you think to be incorrect | |
2645 | +- actual operation, reproducible one is better | |
2646 | +- mailto: aufs-users at lists.sourceforge.net | |
2647 | + | |
2648 | +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches, | |
2649 | +and Feature Requests) on SourceForge. Please join and write to | |
2650 | +aufs-users ML. | |
2651 | + | |
2652 | + | |
2653 | +6. Acknowledgements | |
2654 | +---------------------------------------- | |
2655 | +Thanks to everyone who have tried and are using aufs, whoever | |
2656 | +have reported a bug or any feedback. | |
2657 | + | |
2658 | +Especially donators: | |
2659 | +Tomas Matejicek(slax.org) made a donation (much more than once). | |
2660 | + Since Apr 2010, Tomas M (the author of Slax and Linux Live | |
2661 | + scripts) is making "doubling" donations. | |
2662 | + Unfortunately I cannot list all of the donators, but I really | |
b4510431 | 2663 | + appreciate. |
53392da6 AM |
2664 | + It ends Aug 2010, but the ordinary donation URL is still available. |
2665 | + <http://sourceforge.net/donate/index.php?group_id=167503> | |
2666 | +Dai Itasaka made a donation (2007/8). | |
2667 | +Chuck Smith made a donation (2008/4, 10 and 12). | |
2668 | +Henk Schoneveld made a donation (2008/9). | |
2669 | +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10). | |
2670 | +Francois Dupoux made a donation (2008/11). | |
2671 | +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public | |
2672 | + aufs2 GIT tree (2009/2). | |
2673 | +William Grant made a donation (2009/3). | |
2674 | +Patrick Lane made a donation (2009/4). | |
2675 | +The Mail Archive (mail-archive.com) made donations (2009/5). | |
2676 | +Nippy Networks (Ed Wildgoose) made a donation (2009/7). | |
2677 | +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11). | |
2678 | +Pavel Pronskiy made a donation (2011/2). | |
2679 | +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy | |
2680 | + Networks (Ed Wildgoose) made a donation for hardware (2011/3). | |
537831f9 AM |
2681 | +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and |
2682 | +11). | |
1e00d052 | 2683 | +Sam Liddicott made a donation (2011/9). |
86dc4139 AM |
2684 | +Era Scarecrow made a donation (2013/4). |
2685 | +Bor Ratajc made a donation (2013/4). | |
2686 | +Alessandro Gorreta made a donation (2013/4). | |
2687 | +POIRETTE Marc made a donation (2013/4). | |
2688 | +Alessandro Gorreta made a donation (2013/4). | |
2689 | +lauri kasvandik made a donation (2013/5). | |
392086de | 2690 | +"pemasu from Finland" made a donation (2013/7). |
523b37e3 AM |
2691 | +The Parted Magic Project made a donation (2013/9 and 11). |
2692 | +Pavel Barta made a donation (2013/10). | |
38d290e6 | 2693 | +Nikolay Pertsev made a donation (2014/5). |
076b876e AM |
2694 | +James B made a donation (2014/7). |
2695 | +Stefano Di Biase made a donation (2014/8). | |
2000de60 | 2696 | +Daniel Epellei made a donation (2015/1). |
53392da6 AM |
2697 | + |
2698 | +Thank you very much. | |
2699 | +Donations are always, including future donations, very important and | |
2700 | +helpful for me to keep on developing aufs. | |
2701 | + | |
2702 | + | |
2703 | +7. | |
2704 | +---------------------------------------- | |
2705 | +If you are an experienced user, no explanation is needed. Aufs is | |
2706 | +just a linux filesystem. | |
2707 | + | |
2708 | + | |
2709 | +Enjoy! | |
2710 | + | |
2711 | +# Local variables: ; | |
2712 | +# mode: text; | |
2713 | +# End: ; | |
7f207e10 AM |
2714 | diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h |
2715 | --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 2716 | +++ linux/fs/aufs/aufs.h 2015-06-28 17:35:44.344717109 +0200 |
523b37e3 | 2717 | @@ -0,0 +1,59 @@ |
7f207e10 | 2718 | +/* |
2000de60 | 2719 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
7f207e10 AM |
2720 | + * |
2721 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2722 | + * it under the terms of the GNU General Public License as published by | |
2723 | + * the Free Software Foundation; either version 2 of the License, or | |
2724 | + * (at your option) any later version. | |
2725 | + * | |
2726 | + * This program is distributed in the hope that it will be useful, | |
2727 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2728 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2729 | + * GNU General Public License for more details. | |
2730 | + * | |
2731 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2732 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2733 | + */ |
2734 | + | |
2735 | +/* | |
2736 | + * all header files | |
2737 | + */ | |
2738 | + | |
2739 | +#ifndef __AUFS_H__ | |
2740 | +#define __AUFS_H__ | |
2741 | + | |
2742 | +#ifdef __KERNEL__ | |
2743 | + | |
2744 | +#define AuStub(type, name, body, ...) \ | |
2745 | + static inline type name(__VA_ARGS__) { body; } | |
2746 | + | |
2747 | +#define AuStubVoid(name, ...) \ | |
2748 | + AuStub(void, name, , __VA_ARGS__) | |
2749 | +#define AuStubInt0(name, ...) \ | |
2750 | + AuStub(int, name, return 0, __VA_ARGS__) | |
2751 | + | |
2752 | +#include "debug.h" | |
2753 | + | |
2754 | +#include "branch.h" | |
2755 | +#include "cpup.h" | |
2756 | +#include "dcsub.h" | |
2757 | +#include "dbgaufs.h" | |
2758 | +#include "dentry.h" | |
2759 | +#include "dir.h" | |
2760 | +#include "dynop.h" | |
2761 | +#include "file.h" | |
2762 | +#include "fstype.h" | |
2763 | +#include "inode.h" | |
2764 | +#include "loop.h" | |
2765 | +#include "module.h" | |
7f207e10 AM |
2766 | +#include "opts.h" |
2767 | +#include "rwsem.h" | |
2768 | +#include "spl.h" | |
2769 | +#include "super.h" | |
2770 | +#include "sysaufs.h" | |
2771 | +#include "vfsub.h" | |
2772 | +#include "whout.h" | |
2773 | +#include "wkq.h" | |
2774 | + | |
2775 | +#endif /* __KERNEL__ */ | |
2776 | +#endif /* __AUFS_H__ */ | |
2777 | diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c | |
2778 | --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
2779 | +++ linux/fs/aufs/branch.c 2015-06-28 17:36:09.025073697 +0200 |
2780 | @@ -0,0 +1,1414 @@ | |
7f207e10 | 2781 | +/* |
2000de60 | 2782 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
7f207e10 AM |
2783 | + * |
2784 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2785 | + * it under the terms of the GNU General Public License as published by | |
2786 | + * the Free Software Foundation; either version 2 of the License, or | |
2787 | + * (at your option) any later version. | |
2788 | + * | |
2789 | + * This program is distributed in the hope that it will be useful, | |
2790 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2791 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2792 | + * GNU General Public License for more details. | |
2793 | + * | |
2794 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2795 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2796 | + */ |
2797 | + | |
2798 | +/* | |
2799 | + * branch management | |
2800 | + */ | |
2801 | + | |
027c5e7a | 2802 | +#include <linux/compat.h> |
7f207e10 AM |
2803 | +#include <linux/statfs.h> |
2804 | +#include "aufs.h" | |
2805 | + | |
2806 | +/* | |
2807 | + * free a single branch | |
1facf9fc | 2808 | + */ |
2809 | +static void au_br_do_free(struct au_branch *br) | |
2810 | +{ | |
2811 | + int i; | |
2812 | + struct au_wbr *wbr; | |
4a4d8108 | 2813 | + struct au_dykey **key; |
1facf9fc | 2814 | + |
027c5e7a AM |
2815 | + au_hnotify_fin_br(br); |
2816 | + | |
1facf9fc | 2817 | + if (br->br_xino.xi_file) |
2818 | + fput(br->br_xino.xi_file); | |
2819 | + mutex_destroy(&br->br_xino.xi_nondir_mtx); | |
2820 | + | |
2821 | + AuDebugOn(atomic_read(&br->br_count)); | |
2822 | + | |
2823 | + wbr = br->br_wbr; | |
2824 | + if (wbr) { | |
2825 | + for (i = 0; i < AuBrWh_Last; i++) | |
2826 | + dput(wbr->wbr_wh[i]); | |
2827 | + AuDebugOn(atomic_read(&wbr->wbr_wh_running)); | |
dece6358 | 2828 | + AuRwDestroy(&wbr->wbr_wh_rwsem); |
1facf9fc | 2829 | + } |
2830 | + | |
076b876e AM |
2831 | + if (br->br_fhsm) { |
2832 | + au_br_fhsm_fin(br->br_fhsm); | |
2833 | + kfree(br->br_fhsm); | |
2834 | + } | |
2835 | + | |
4a4d8108 AM |
2836 | + key = br->br_dykey; |
2837 | + for (i = 0; i < AuBrDynOp; i++, key++) | |
2838 | + if (*key) | |
2839 | + au_dy_put(*key); | |
2840 | + else | |
2841 | + break; | |
2842 | + | |
537831f9 AM |
2843 | + /* recursive lock, s_umount of branch's */ |
2844 | + lockdep_off(); | |
86dc4139 | 2845 | + path_put(&br->br_path); |
537831f9 | 2846 | + lockdep_on(); |
1facf9fc | 2847 | + kfree(wbr); |
2848 | + kfree(br); | |
2849 | +} | |
2850 | + | |
2851 | +/* | |
2852 | + * frees all branches | |
2853 | + */ | |
2854 | +void au_br_free(struct au_sbinfo *sbinfo) | |
2855 | +{ | |
2856 | + aufs_bindex_t bmax; | |
2857 | + struct au_branch **br; | |
2858 | + | |
dece6358 AM |
2859 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
2860 | + | |
1facf9fc | 2861 | + bmax = sbinfo->si_bend + 1; |
2862 | + br = sbinfo->si_branch; | |
2863 | + while (bmax--) | |
2864 | + au_br_do_free(*br++); | |
2865 | +} | |
2866 | + | |
2867 | +/* | |
2868 | + * find the index of a branch which is specified by @br_id. | |
2869 | + */ | |
2870 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id) | |
2871 | +{ | |
2872 | + aufs_bindex_t bindex, bend; | |
2873 | + | |
2874 | + bend = au_sbend(sb); | |
2875 | + for (bindex = 0; bindex <= bend; bindex++) | |
2876 | + if (au_sbr_id(sb, bindex) == br_id) | |
2877 | + return bindex; | |
2878 | + return -1; | |
2879 | +} | |
2880 | + | |
2881 | +/* ---------------------------------------------------------------------- */ | |
2882 | + | |
2883 | +/* | |
2884 | + * add a branch | |
2885 | + */ | |
2886 | + | |
b752ccd1 AM |
2887 | +static int test_overlap(struct super_block *sb, struct dentry *h_adding, |
2888 | + struct dentry *h_root) | |
1facf9fc | 2889 | +{ |
b752ccd1 AM |
2890 | + if (unlikely(h_adding == h_root |
2891 | + || au_test_loopback_overlap(sb, h_adding))) | |
1facf9fc | 2892 | + return 1; |
b752ccd1 AM |
2893 | + if (h_adding->d_sb != h_root->d_sb) |
2894 | + return 0; | |
2895 | + return au_test_subdir(h_adding, h_root) | |
2896 | + || au_test_subdir(h_root, h_adding); | |
1facf9fc | 2897 | +} |
2898 | + | |
2899 | +/* | |
2900 | + * returns a newly allocated branch. @new_nbranch is a number of branches | |
2901 | + * after adding a branch. | |
2902 | + */ | |
2903 | +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch, | |
2904 | + int perm) | |
2905 | +{ | |
2906 | + struct au_branch *add_branch; | |
2907 | + struct dentry *root; | |
5527c038 | 2908 | + struct inode *inode; |
4a4d8108 | 2909 | + int err; |
1facf9fc | 2910 | + |
4a4d8108 | 2911 | + err = -ENOMEM; |
1facf9fc | 2912 | + root = sb->s_root; |
2913 | + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS); | |
2914 | + if (unlikely(!add_branch)) | |
2915 | + goto out; | |
2916 | + | |
027c5e7a AM |
2917 | + err = au_hnotify_init_br(add_branch, perm); |
2918 | + if (unlikely(err)) | |
2919 | + goto out_br; | |
2920 | + | |
1facf9fc | 2921 | + add_branch->br_wbr = NULL; |
2922 | + if (au_br_writable(perm)) { | |
2923 | + /* may be freed separately at changing the branch permission */ | |
2924 | + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr), | |
2925 | + GFP_NOFS); | |
2926 | + if (unlikely(!add_branch->br_wbr)) | |
027c5e7a | 2927 | + goto out_hnotify; |
1facf9fc | 2928 | + } |
2929 | + | |
076b876e AM |
2930 | + add_branch->br_fhsm = NULL; |
2931 | + if (au_br_fhsm(perm)) { | |
2932 | + err = au_fhsm_br_alloc(add_branch); | |
2933 | + if (unlikely(err)) | |
2934 | + goto out_wbr; | |
2935 | + } | |
2936 | + | |
4a4d8108 AM |
2937 | + err = au_sbr_realloc(au_sbi(sb), new_nbranch); |
2938 | + if (!err) | |
2939 | + err = au_di_realloc(au_di(root), new_nbranch); | |
5527c038 JR |
2940 | + if (!err) { |
2941 | + inode = d_inode(root); | |
2942 | + err = au_ii_realloc(au_ii(inode), new_nbranch); | |
2943 | + } | |
4a4d8108 AM |
2944 | + if (!err) |
2945 | + return add_branch; /* success */ | |
1facf9fc | 2946 | + |
076b876e | 2947 | +out_wbr: |
1facf9fc | 2948 | + kfree(add_branch->br_wbr); |
027c5e7a AM |
2949 | +out_hnotify: |
2950 | + au_hnotify_fin_br(add_branch); | |
4f0767ce | 2951 | +out_br: |
1facf9fc | 2952 | + kfree(add_branch); |
4f0767ce | 2953 | +out: |
4a4d8108 | 2954 | + return ERR_PTR(err); |
1facf9fc | 2955 | +} |
2956 | + | |
2957 | +/* | |
2958 | + * test if the branch permission is legal or not. | |
2959 | + */ | |
2960 | +static int test_br(struct inode *inode, int brperm, char *path) | |
2961 | +{ | |
2962 | + int err; | |
2963 | + | |
4a4d8108 AM |
2964 | + err = (au_br_writable(brperm) && IS_RDONLY(inode)); |
2965 | + if (!err) | |
2966 | + goto out; | |
1facf9fc | 2967 | + |
4a4d8108 AM |
2968 | + err = -EINVAL; |
2969 | + pr_err("write permission for readonly mount or inode, %s\n", path); | |
2970 | + | |
4f0767ce | 2971 | +out: |
1facf9fc | 2972 | + return err; |
2973 | +} | |
2974 | + | |
2975 | +/* | |
2976 | + * returns: | |
2977 | + * 0: success, the caller will add it | |
2978 | + * plus: success, it is already unified, the caller should ignore it | |
2979 | + * minus: error | |
2980 | + */ | |
2981 | +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
2982 | +{ | |
2983 | + int err; | |
2984 | + aufs_bindex_t bend, bindex; | |
5527c038 | 2985 | + struct dentry *root, *h_dentry; |
1facf9fc | 2986 | + struct inode *inode, *h_inode; |
2987 | + | |
2988 | + root = sb->s_root; | |
2989 | + bend = au_sbend(sb); | |
2990 | + if (unlikely(bend >= 0 | |
2991 | + && au_find_dbindex(root, add->path.dentry) >= 0)) { | |
2992 | + err = 1; | |
2993 | + if (!remount) { | |
2994 | + err = -EINVAL; | |
4a4d8108 | 2995 | + pr_err("%s duplicated\n", add->pathname); |
1facf9fc | 2996 | + } |
2997 | + goto out; | |
2998 | + } | |
2999 | + | |
3000 | + err = -ENOSPC; /* -E2BIG; */ | |
3001 | + if (unlikely(AUFS_BRANCH_MAX <= add->bindex | |
3002 | + || AUFS_BRANCH_MAX - 1 <= bend)) { | |
4a4d8108 | 3003 | + pr_err("number of branches exceeded %s\n", add->pathname); |
1facf9fc | 3004 | + goto out; |
3005 | + } | |
3006 | + | |
3007 | + err = -EDOM; | |
3008 | + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) { | |
4a4d8108 | 3009 | + pr_err("bad index %d\n", add->bindex); |
1facf9fc | 3010 | + goto out; |
3011 | + } | |
3012 | + | |
5527c038 | 3013 | + inode = d_inode(add->path.dentry); |
1facf9fc | 3014 | + err = -ENOENT; |
3015 | + if (unlikely(!inode->i_nlink)) { | |
4a4d8108 | 3016 | + pr_err("no existence %s\n", add->pathname); |
1facf9fc | 3017 | + goto out; |
3018 | + } | |
3019 | + | |
3020 | + err = -EINVAL; | |
3021 | + if (unlikely(inode->i_sb == sb)) { | |
4a4d8108 | 3022 | + pr_err("%s must be outside\n", add->pathname); |
1facf9fc | 3023 | + goto out; |
3024 | + } | |
3025 | + | |
3026 | + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) { | |
4a4d8108 AM |
3027 | + pr_err("unsupported filesystem, %s (%s)\n", |
3028 | + add->pathname, au_sbtype(inode->i_sb)); | |
1facf9fc | 3029 | + goto out; |
3030 | + } | |
3031 | + | |
c1595e42 JR |
3032 | + if (unlikely(inode->i_sb->s_stack_depth)) { |
3033 | + pr_err("already stacked, %s (%s)\n", | |
3034 | + add->pathname, au_sbtype(inode->i_sb)); | |
3035 | + goto out; | |
3036 | + } | |
3037 | + | |
5527c038 | 3038 | + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname); |
1facf9fc | 3039 | + if (unlikely(err)) |
3040 | + goto out; | |
3041 | + | |
3042 | + if (bend < 0) | |
3043 | + return 0; /* success */ | |
3044 | + | |
3045 | + err = -EINVAL; | |
3046 | + for (bindex = 0; bindex <= bend; bindex++) | |
3047 | + if (unlikely(test_overlap(sb, add->path.dentry, | |
3048 | + au_h_dptr(root, bindex)))) { | |
4a4d8108 | 3049 | + pr_err("%s is overlapped\n", add->pathname); |
1facf9fc | 3050 | + goto out; |
3051 | + } | |
3052 | + | |
3053 | + err = 0; | |
3054 | + if (au_opt_test(au_mntflags(sb), WARN_PERM)) { | |
5527c038 JR |
3055 | + h_dentry = au_h_dptr(root, 0); |
3056 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 3057 | + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO) |
0c3ec466 AM |
3058 | + || !uid_eq(h_inode->i_uid, inode->i_uid) |
3059 | + || !gid_eq(h_inode->i_gid, inode->i_gid)) | |
3060 | + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n", | |
3061 | + add->pathname, | |
3062 | + i_uid_read(inode), i_gid_read(inode), | |
3063 | + (inode->i_mode & S_IALLUGO), | |
3064 | + i_uid_read(h_inode), i_gid_read(h_inode), | |
3065 | + (h_inode->i_mode & S_IALLUGO)); | |
1facf9fc | 3066 | + } |
3067 | + | |
4f0767ce | 3068 | +out: |
1facf9fc | 3069 | + return err; |
3070 | +} | |
3071 | + | |
3072 | +/* | |
3073 | + * initialize or clean the whiteouts for an adding branch | |
3074 | + */ | |
3075 | +static int au_br_init_wh(struct super_block *sb, struct au_branch *br, | |
86dc4139 | 3076 | + int new_perm) |
1facf9fc | 3077 | +{ |
3078 | + int err, old_perm; | |
3079 | + aufs_bindex_t bindex; | |
3080 | + struct mutex *h_mtx; | |
3081 | + struct au_wbr *wbr; | |
3082 | + struct au_hinode *hdir; | |
5527c038 | 3083 | + struct dentry *h_dentry; |
1facf9fc | 3084 | + |
86dc4139 AM |
3085 | + err = vfsub_mnt_want_write(au_br_mnt(br)); |
3086 | + if (unlikely(err)) | |
3087 | + goto out; | |
3088 | + | |
1facf9fc | 3089 | + wbr = br->br_wbr; |
3090 | + old_perm = br->br_perm; | |
3091 | + br->br_perm = new_perm; | |
3092 | + hdir = NULL; | |
3093 | + h_mtx = NULL; | |
3094 | + bindex = au_br_index(sb, br->br_id); | |
3095 | + if (0 <= bindex) { | |
5527c038 | 3096 | + hdir = au_hi(d_inode(sb->s_root), bindex); |
4a4d8108 | 3097 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 3098 | + } else { |
5527c038 JR |
3099 | + h_dentry = au_br_dentry(br); |
3100 | + h_mtx = &d_inode(h_dentry)->i_mutex; | |
1facf9fc | 3101 | + mutex_lock_nested(h_mtx, AuLsc_I_PARENT); |
3102 | + } | |
3103 | + if (!wbr) | |
86dc4139 | 3104 | + err = au_wh_init(br, sb); |
1facf9fc | 3105 | + else { |
3106 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 3107 | + err = au_wh_init(br, sb); |
1facf9fc | 3108 | + wbr_wh_write_unlock(wbr); |
3109 | + } | |
3110 | + if (hdir) | |
4a4d8108 | 3111 | + au_hn_imtx_unlock(hdir); |
1facf9fc | 3112 | + else |
3113 | + mutex_unlock(h_mtx); | |
86dc4139 | 3114 | + vfsub_mnt_drop_write(au_br_mnt(br)); |
1facf9fc | 3115 | + br->br_perm = old_perm; |
3116 | + | |
3117 | + if (!err && wbr && !au_br_writable(new_perm)) { | |
3118 | + kfree(wbr); | |
3119 | + br->br_wbr = NULL; | |
3120 | + } | |
3121 | + | |
86dc4139 | 3122 | +out: |
1facf9fc | 3123 | + return err; |
3124 | +} | |
3125 | + | |
3126 | +static int au_wbr_init(struct au_branch *br, struct super_block *sb, | |
86dc4139 | 3127 | + int perm) |
1facf9fc | 3128 | +{ |
3129 | + int err; | |
4a4d8108 | 3130 | + struct kstatfs kst; |
1facf9fc | 3131 | + struct au_wbr *wbr; |
3132 | + | |
3133 | + wbr = br->br_wbr; | |
dece6358 | 3134 | + au_rw_init(&wbr->wbr_wh_rwsem); |
1facf9fc | 3135 | + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh)); |
3136 | + atomic_set(&wbr->wbr_wh_running, 0); | |
3137 | + wbr->wbr_bytes = 0; | |
3138 | + | |
4a4d8108 AM |
3139 | + /* |
3140 | + * a limit for rmdir/rename a dir | |
523b37e3 | 3141 | + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h |
4a4d8108 | 3142 | + */ |
86dc4139 | 3143 | + err = vfs_statfs(&br->br_path, &kst); |
4a4d8108 AM |
3144 | + if (unlikely(err)) |
3145 | + goto out; | |
3146 | + err = -EINVAL; | |
3147 | + if (kst.f_namelen >= NAME_MAX) | |
86dc4139 | 3148 | + err = au_br_init_wh(sb, br, perm); |
4a4d8108 | 3149 | + else |
523b37e3 AM |
3150 | + pr_err("%pd(%s), unsupported namelen %ld\n", |
3151 | + au_br_dentry(br), | |
86dc4139 | 3152 | + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen); |
1facf9fc | 3153 | + |
4f0767ce | 3154 | +out: |
1facf9fc | 3155 | + return err; |
3156 | +} | |
3157 | + | |
c1595e42 | 3158 | +/* initialize a new branch */ |
1facf9fc | 3159 | +static int au_br_init(struct au_branch *br, struct super_block *sb, |
3160 | + struct au_opt_add *add) | |
3161 | +{ | |
3162 | + int err; | |
5527c038 | 3163 | + struct inode *h_inode; |
1facf9fc | 3164 | + |
3165 | + err = 0; | |
3166 | + memset(&br->br_xino, 0, sizeof(br->br_xino)); | |
3167 | + mutex_init(&br->br_xino.xi_nondir_mtx); | |
3168 | + br->br_perm = add->perm; | |
86dc4139 | 3169 | + br->br_path = add->path; /* set first, path_get() later */ |
4a4d8108 AM |
3170 | + spin_lock_init(&br->br_dykey_lock); |
3171 | + memset(br->br_dykey, 0, sizeof(br->br_dykey)); | |
1facf9fc | 3172 | + atomic_set(&br->br_count, 0); |
1facf9fc | 3173 | + atomic_set(&br->br_xino_running, 0); |
3174 | + br->br_id = au_new_br_id(sb); | |
7f207e10 | 3175 | + AuDebugOn(br->br_id < 0); |
1facf9fc | 3176 | + |
3177 | + if (au_br_writable(add->perm)) { | |
86dc4139 | 3178 | + err = au_wbr_init(br, sb, add->perm); |
1facf9fc | 3179 | + if (unlikely(err)) |
b752ccd1 | 3180 | + goto out_err; |
1facf9fc | 3181 | + } |
3182 | + | |
3183 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
5527c038 JR |
3184 | + h_inode = d_inode(add->path.dentry); |
3185 | + err = au_xino_br(sb, br, h_inode->i_ino, | |
1facf9fc | 3186 | + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1); |
3187 | + if (unlikely(err)) { | |
3188 | + AuDebugOn(br->br_xino.xi_file); | |
b752ccd1 | 3189 | + goto out_err; |
1facf9fc | 3190 | + } |
3191 | + } | |
3192 | + | |
3193 | + sysaufs_br_init(br); | |
86dc4139 | 3194 | + path_get(&br->br_path); |
b752ccd1 | 3195 | + goto out; /* success */ |
1facf9fc | 3196 | + |
4f0767ce | 3197 | +out_err: |
86dc4139 | 3198 | + memset(&br->br_path, 0, sizeof(br->br_path)); |
4f0767ce | 3199 | +out: |
1facf9fc | 3200 | + return err; |
3201 | +} | |
3202 | + | |
3203 | +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex, | |
3204 | + struct au_branch *br, aufs_bindex_t bend, | |
3205 | + aufs_bindex_t amount) | |
3206 | +{ | |
3207 | + struct au_branch **brp; | |
3208 | + | |
dece6358 AM |
3209 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3210 | + | |
1facf9fc | 3211 | + brp = sbinfo->si_branch + bindex; |
3212 | + memmove(brp + 1, brp, sizeof(*brp) * amount); | |
3213 | + *brp = br; | |
3214 | + sbinfo->si_bend++; | |
3215 | + if (unlikely(bend < 0)) | |
3216 | + sbinfo->si_bend = 0; | |
3217 | +} | |
3218 | + | |
3219 | +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex, | |
3220 | + aufs_bindex_t bend, aufs_bindex_t amount) | |
3221 | +{ | |
3222 | + struct au_hdentry *hdp; | |
3223 | + | |
1308ab2a | 3224 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3225 | + | |
1facf9fc | 3226 | + hdp = dinfo->di_hdentry + bindex; |
3227 | + memmove(hdp + 1, hdp, sizeof(*hdp) * amount); | |
3228 | + au_h_dentry_init(hdp); | |
3229 | + dinfo->di_bend++; | |
3230 | + if (unlikely(bend < 0)) | |
3231 | + dinfo->di_bstart = 0; | |
3232 | +} | |
3233 | + | |
3234 | +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex, | |
3235 | + aufs_bindex_t bend, aufs_bindex_t amount) | |
3236 | +{ | |
3237 | + struct au_hinode *hip; | |
3238 | + | |
1308ab2a | 3239 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3240 | + | |
1facf9fc | 3241 | + hip = iinfo->ii_hinode + bindex; |
3242 | + memmove(hip + 1, hip, sizeof(*hip) * amount); | |
3243 | + hip->hi_inode = NULL; | |
4a4d8108 | 3244 | + au_hn_init(hip); |
1facf9fc | 3245 | + iinfo->ii_bend++; |
3246 | + if (unlikely(bend < 0)) | |
3247 | + iinfo->ii_bstart = 0; | |
3248 | +} | |
3249 | + | |
86dc4139 AM |
3250 | +static void au_br_do_add(struct super_block *sb, struct au_branch *br, |
3251 | + aufs_bindex_t bindex) | |
1facf9fc | 3252 | +{ |
86dc4139 | 3253 | + struct dentry *root, *h_dentry; |
5527c038 | 3254 | + struct inode *root_inode, *h_inode; |
1facf9fc | 3255 | + aufs_bindex_t bend, amount; |
3256 | + | |
3257 | + root = sb->s_root; | |
5527c038 | 3258 | + root_inode = d_inode(root); |
1facf9fc | 3259 | + bend = au_sbend(sb); |
3260 | + amount = bend + 1 - bindex; | |
86dc4139 | 3261 | + h_dentry = au_br_dentry(br); |
53392da6 | 3262 | + au_sbilist_lock(); |
1facf9fc | 3263 | + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount); |
3264 | + au_br_do_add_hdp(au_di(root), bindex, bend, amount); | |
3265 | + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount); | |
3266 | + au_set_h_dptr(root, bindex, dget(h_dentry)); | |
5527c038 JR |
3267 | + h_inode = d_inode(h_dentry); |
3268 | + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0); | |
53392da6 | 3269 | + au_sbilist_unlock(); |
1facf9fc | 3270 | +} |
3271 | + | |
3272 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3273 | +{ | |
3274 | + int err; | |
1facf9fc | 3275 | + aufs_bindex_t bend, add_bindex; |
3276 | + struct dentry *root, *h_dentry; | |
3277 | + struct inode *root_inode; | |
3278 | + struct au_branch *add_branch; | |
3279 | + | |
3280 | + root = sb->s_root; | |
5527c038 | 3281 | + root_inode = d_inode(root); |
1facf9fc | 3282 | + IMustLock(root_inode); |
3283 | + err = test_add(sb, add, remount); | |
3284 | + if (unlikely(err < 0)) | |
3285 | + goto out; | |
3286 | + if (err) { | |
3287 | + err = 0; | |
3288 | + goto out; /* success */ | |
3289 | + } | |
3290 | + | |
3291 | + bend = au_sbend(sb); | |
3292 | + add_branch = au_br_alloc(sb, bend + 2, add->perm); | |
3293 | + err = PTR_ERR(add_branch); | |
3294 | + if (IS_ERR(add_branch)) | |
3295 | + goto out; | |
3296 | + | |
3297 | + err = au_br_init(add_branch, sb, add); | |
3298 | + if (unlikely(err)) { | |
3299 | + au_br_do_free(add_branch); | |
3300 | + goto out; | |
3301 | + } | |
3302 | + | |
3303 | + add_bindex = add->bindex; | |
1facf9fc | 3304 | + if (!remount) |
86dc4139 | 3305 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3306 | + else { |
3307 | + sysaufs_brs_del(sb, add_bindex); | |
86dc4139 | 3308 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3309 | + sysaufs_brs_add(sb, add_bindex); |
3310 | + } | |
3311 | + | |
86dc4139 | 3312 | + h_dentry = add->path.dentry; |
1308ab2a | 3313 | + if (!add_bindex) { |
1facf9fc | 3314 | + au_cpup_attr_all(root_inode, /*force*/1); |
1308ab2a | 3315 | + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes; |
3316 | + } else | |
5527c038 | 3317 | + au_add_nlink(root_inode, d_inode(h_dentry)); |
1facf9fc | 3318 | + |
3319 | + /* | |
4a4d8108 | 3320 | + * this test/set prevents aufs from handling unnecesary notify events |
027c5e7a | 3321 | + * of xino files, in case of re-adding a writable branch which was |
1facf9fc | 3322 | + * once detached from aufs. |
3323 | + */ | |
3324 | + if (au_xino_brid(sb) < 0 | |
3325 | + && au_br_writable(add_branch->br_perm) | |
3326 | + && !au_test_fs_bad_xino(h_dentry->d_sb) | |
3327 | + && add_branch->br_xino.xi_file | |
2000de60 | 3328 | + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry) |
1facf9fc | 3329 | + au_xino_brid_set(sb, add_branch->br_id); |
3330 | + | |
4f0767ce | 3331 | +out: |
1facf9fc | 3332 | + return err; |
3333 | +} | |
3334 | + | |
3335 | +/* ---------------------------------------------------------------------- */ | |
3336 | + | |
076b876e AM |
3337 | +static unsigned long long au_farray_cb(void *a, |
3338 | + unsigned long long max __maybe_unused, | |
3339 | + void *arg) | |
3340 | +{ | |
3341 | + unsigned long long n; | |
3342 | + struct file **p, *f; | |
3343 | + struct au_sphlhead *files; | |
3344 | + struct au_finfo *finfo; | |
3345 | + struct super_block *sb = arg; | |
3346 | + | |
3347 | + n = 0; | |
3348 | + p = a; | |
3349 | + files = &au_sbi(sb)->si_files; | |
3350 | + spin_lock(&files->spin); | |
3351 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
3352 | + f = finfo->fi_file; | |
3353 | + if (file_count(f) | |
3354 | + && !special_file(file_inode(f)->i_mode)) { | |
3355 | + get_file(f); | |
3356 | + *p++ = f; | |
3357 | + n++; | |
3358 | + AuDebugOn(n > max); | |
3359 | + } | |
3360 | + } | |
3361 | + spin_unlock(&files->spin); | |
3362 | + | |
3363 | + return n; | |
3364 | +} | |
3365 | + | |
3366 | +static struct file **au_farray_alloc(struct super_block *sb, | |
3367 | + unsigned long long *max) | |
3368 | +{ | |
3369 | + *max = atomic_long_read(&au_sbi(sb)->si_nfiles); | |
3370 | + return au_array_alloc(max, au_farray_cb, sb); | |
3371 | +} | |
3372 | + | |
3373 | +static void au_farray_free(struct file **a, unsigned long long max) | |
3374 | +{ | |
3375 | + unsigned long long ull; | |
3376 | + | |
3377 | + for (ull = 0; ull < max; ull++) | |
3378 | + if (a[ull]) | |
3379 | + fput(a[ull]); | |
3380 | + au_array_free(a); | |
3381 | +} | |
3382 | + | |
3383 | +/* ---------------------------------------------------------------------- */ | |
3384 | + | |
1facf9fc | 3385 | +/* |
3386 | + * delete a branch | |
3387 | + */ | |
3388 | + | |
3389 | +/* to show the line number, do not make it inlined function */ | |
4a4d8108 | 3390 | +#define AuVerbose(do_info, fmt, ...) do { \ |
1facf9fc | 3391 | + if (do_info) \ |
4a4d8108 | 3392 | + pr_info(fmt, ##__VA_ARGS__); \ |
1facf9fc | 3393 | +} while (0) |
3394 | + | |
027c5e7a AM |
3395 | +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart, |
3396 | + aufs_bindex_t bend) | |
3397 | +{ | |
3398 | + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend; | |
3399 | +} | |
3400 | + | |
3401 | +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart, | |
3402 | + aufs_bindex_t bend) | |
3403 | +{ | |
5527c038 | 3404 | + return au_test_ibusy(d_inode(dentry), bstart, bend); |
027c5e7a AM |
3405 | +} |
3406 | + | |
1facf9fc | 3407 | +/* |
3408 | + * test if the branch is deletable or not. | |
3409 | + */ | |
3410 | +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex, | |
b752ccd1 | 3411 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3412 | +{ |
3413 | + int err, i, j, ndentry; | |
3414 | + aufs_bindex_t bstart, bend; | |
1facf9fc | 3415 | + struct au_dcsub_pages dpages; |
3416 | + struct au_dpage *dpage; | |
3417 | + struct dentry *d; | |
1facf9fc | 3418 | + |
3419 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
3420 | + if (unlikely(err)) | |
3421 | + goto out; | |
3422 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); | |
3423 | + if (unlikely(err)) | |
3424 | + goto out_dpages; | |
3425 | + | |
1facf9fc | 3426 | + for (i = 0; !err && i < dpages.ndpage; i++) { |
3427 | + dpage = dpages.dpages + i; | |
3428 | + ndentry = dpage->ndentry; | |
3429 | + for (j = 0; !err && j < ndentry; j++) { | |
3430 | + d = dpage->dentries[j]; | |
c1595e42 | 3431 | + AuDebugOn(au_dcount(d) <= 0); |
027c5e7a | 3432 | + if (!au_digen_test(d, sigen)) { |
1facf9fc | 3433 | + di_read_lock_child(d, AuLock_IR); |
027c5e7a AM |
3434 | + if (unlikely(au_dbrange_test(d))) { |
3435 | + di_read_unlock(d, AuLock_IR); | |
3436 | + continue; | |
3437 | + } | |
3438 | + } else { | |
1facf9fc | 3439 | + di_write_lock_child(d); |
027c5e7a AM |
3440 | + if (unlikely(au_dbrange_test(d))) { |
3441 | + di_write_unlock(d); | |
3442 | + continue; | |
3443 | + } | |
1facf9fc | 3444 | + err = au_reval_dpath(d, sigen); |
3445 | + if (!err) | |
3446 | + di_downgrade_lock(d, AuLock_IR); | |
3447 | + else { | |
3448 | + di_write_unlock(d); | |
3449 | + break; | |
3450 | + } | |
3451 | + } | |
3452 | + | |
027c5e7a | 3453 | + /* AuDbgDentry(d); */ |
1facf9fc | 3454 | + bstart = au_dbstart(d); |
3455 | + bend = au_dbend(d); | |
3456 | + if (bstart <= bindex | |
3457 | + && bindex <= bend | |
3458 | + && au_h_dptr(d, bindex) | |
027c5e7a | 3459 | + && au_test_dbusy(d, bstart, bend)) { |
1facf9fc | 3460 | + err = -EBUSY; |
523b37e3 | 3461 | + AuVerbose(verbose, "busy %pd\n", d); |
027c5e7a | 3462 | + AuDbgDentry(d); |
1facf9fc | 3463 | + } |
3464 | + di_read_unlock(d, AuLock_IR); | |
3465 | + } | |
3466 | + } | |
3467 | + | |
4f0767ce | 3468 | +out_dpages: |
1facf9fc | 3469 | + au_dpages_free(&dpages); |
4f0767ce | 3470 | +out: |
1facf9fc | 3471 | + return err; |
3472 | +} | |
3473 | + | |
3474 | +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex, | |
b752ccd1 | 3475 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3476 | +{ |
3477 | + int err; | |
7f207e10 AM |
3478 | + unsigned long long max, ull; |
3479 | + struct inode *i, **array; | |
1facf9fc | 3480 | + aufs_bindex_t bstart, bend; |
1facf9fc | 3481 | + |
7f207e10 AM |
3482 | + array = au_iarray_alloc(sb, &max); |
3483 | + err = PTR_ERR(array); | |
3484 | + if (IS_ERR(array)) | |
3485 | + goto out; | |
3486 | + | |
1facf9fc | 3487 | + err = 0; |
7f207e10 AM |
3488 | + AuDbg("b%d\n", bindex); |
3489 | + for (ull = 0; !err && ull < max; ull++) { | |
3490 | + i = array[ull]; | |
076b876e AM |
3491 | + if (unlikely(!i)) |
3492 | + break; | |
7f207e10 | 3493 | + if (i->i_ino == AUFS_ROOT_INO) |
1facf9fc | 3494 | + continue; |
3495 | + | |
7f207e10 | 3496 | + /* AuDbgInode(i); */ |
537831f9 | 3497 | + if (au_iigen(i, NULL) == sigen) |
1facf9fc | 3498 | + ii_read_lock_child(i); |
3499 | + else { | |
3500 | + ii_write_lock_child(i); | |
027c5e7a AM |
3501 | + err = au_refresh_hinode_self(i); |
3502 | + au_iigen_dec(i); | |
1facf9fc | 3503 | + if (!err) |
3504 | + ii_downgrade_lock(i); | |
3505 | + else { | |
3506 | + ii_write_unlock(i); | |
3507 | + break; | |
3508 | + } | |
3509 | + } | |
3510 | + | |
3511 | + bstart = au_ibstart(i); | |
3512 | + bend = au_ibend(i); | |
3513 | + if (bstart <= bindex | |
3514 | + && bindex <= bend | |
3515 | + && au_h_iptr(i, bindex) | |
027c5e7a | 3516 | + && au_test_ibusy(i, bstart, bend)) { |
1facf9fc | 3517 | + err = -EBUSY; |
3518 | + AuVerbose(verbose, "busy i%lu\n", i->i_ino); | |
7f207e10 | 3519 | + AuDbgInode(i); |
1facf9fc | 3520 | + } |
3521 | + ii_read_unlock(i); | |
3522 | + } | |
7f207e10 | 3523 | + au_iarray_free(array, max); |
1facf9fc | 3524 | + |
7f207e10 | 3525 | +out: |
1facf9fc | 3526 | + return err; |
3527 | +} | |
3528 | + | |
b752ccd1 AM |
3529 | +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex, |
3530 | + const unsigned int verbose) | |
1facf9fc | 3531 | +{ |
3532 | + int err; | |
3533 | + unsigned int sigen; | |
3534 | + | |
3535 | + sigen = au_sigen(root->d_sb); | |
3536 | + DiMustNoWaiters(root); | |
5527c038 | 3537 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 3538 | + di_write_unlock(root); |
b752ccd1 | 3539 | + err = test_dentry_busy(root, bindex, sigen, verbose); |
1facf9fc | 3540 | + if (!err) |
b752ccd1 | 3541 | + err = test_inode_busy(root->d_sb, bindex, sigen, verbose); |
1facf9fc | 3542 | + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */ |
3543 | + | |
3544 | + return err; | |
3545 | +} | |
3546 | + | |
076b876e AM |
3547 | +static int test_dir_busy(struct file *file, aufs_bindex_t br_id, |
3548 | + struct file **to_free, int *idx) | |
3549 | +{ | |
3550 | + int err; | |
c1595e42 | 3551 | + unsigned char matched, root; |
076b876e AM |
3552 | + aufs_bindex_t bindex, bend; |
3553 | + struct au_fidir *fidir; | |
3554 | + struct au_hfile *hfile; | |
3555 | + | |
3556 | + err = 0; | |
2000de60 | 3557 | + root = IS_ROOT(file->f_path.dentry); |
c1595e42 JR |
3558 | + if (root) { |
3559 | + get_file(file); | |
3560 | + to_free[*idx] = file; | |
3561 | + (*idx)++; | |
3562 | + goto out; | |
3563 | + } | |
3564 | + | |
076b876e | 3565 | + matched = 0; |
076b876e AM |
3566 | + fidir = au_fi(file)->fi_hdir; |
3567 | + AuDebugOn(!fidir); | |
3568 | + bend = au_fbend_dir(file); | |
3569 | + for (bindex = au_fbstart(file); bindex <= bend; bindex++) { | |
3570 | + hfile = fidir->fd_hfile + bindex; | |
3571 | + if (!hfile->hf_file) | |
3572 | + continue; | |
3573 | + | |
c1595e42 | 3574 | + if (hfile->hf_br->br_id == br_id) { |
076b876e | 3575 | + matched = 1; |
076b876e | 3576 | + break; |
c1595e42 | 3577 | + } |
076b876e | 3578 | + } |
c1595e42 | 3579 | + if (matched) |
076b876e AM |
3580 | + err = -EBUSY; |
3581 | + | |
3582 | +out: | |
3583 | + return err; | |
3584 | +} | |
3585 | + | |
3586 | +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id, | |
3587 | + struct file **to_free, int opened) | |
3588 | +{ | |
3589 | + int err, idx; | |
3590 | + unsigned long long ull, max; | |
3591 | + aufs_bindex_t bstart; | |
3592 | + struct file *file, **array; | |
076b876e AM |
3593 | + struct dentry *root; |
3594 | + struct au_hfile *hfile; | |
3595 | + | |
3596 | + array = au_farray_alloc(sb, &max); | |
3597 | + err = PTR_ERR(array); | |
3598 | + if (IS_ERR(array)) | |
3599 | + goto out; | |
3600 | + | |
3601 | + err = 0; | |
3602 | + idx = 0; | |
3603 | + root = sb->s_root; | |
3604 | + di_write_unlock(root); | |
3605 | + for (ull = 0; ull < max; ull++) { | |
3606 | + file = array[ull]; | |
3607 | + if (unlikely(!file)) | |
3608 | + break; | |
3609 | + | |
3610 | + /* AuDbg("%pD\n", file); */ | |
3611 | + fi_read_lock(file); | |
3612 | + bstart = au_fbstart(file); | |
2000de60 | 3613 | + if (!d_is_dir(file->f_path.dentry)) { |
076b876e AM |
3614 | + hfile = &au_fi(file)->fi_htop; |
3615 | + if (hfile->hf_br->br_id == br_id) | |
3616 | + err = -EBUSY; | |
3617 | + } else | |
3618 | + err = test_dir_busy(file, br_id, to_free, &idx); | |
3619 | + fi_read_unlock(file); | |
3620 | + if (unlikely(err)) | |
3621 | + break; | |
3622 | + } | |
3623 | + di_write_lock_child(root); | |
3624 | + au_farray_free(array, max); | |
3625 | + AuDebugOn(idx > opened); | |
3626 | + | |
3627 | +out: | |
3628 | + return err; | |
3629 | +} | |
3630 | + | |
3631 | +static void br_del_file(struct file **to_free, unsigned long long opened, | |
3632 | + aufs_bindex_t br_id) | |
3633 | +{ | |
3634 | + unsigned long long ull; | |
3635 | + aufs_bindex_t bindex, bstart, bend, bfound; | |
3636 | + struct file *file; | |
3637 | + struct au_fidir *fidir; | |
3638 | + struct au_hfile *hfile; | |
3639 | + | |
3640 | + for (ull = 0; ull < opened; ull++) { | |
3641 | + file = to_free[ull]; | |
3642 | + if (unlikely(!file)) | |
3643 | + break; | |
3644 | + | |
3645 | + /* AuDbg("%pD\n", file); */ | |
2000de60 | 3646 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
076b876e AM |
3647 | + bfound = -1; |
3648 | + fidir = au_fi(file)->fi_hdir; | |
3649 | + AuDebugOn(!fidir); | |
3650 | + fi_write_lock(file); | |
3651 | + bstart = au_fbstart(file); | |
3652 | + bend = au_fbend_dir(file); | |
3653 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
3654 | + hfile = fidir->fd_hfile + bindex; | |
3655 | + if (!hfile->hf_file) | |
3656 | + continue; | |
3657 | + | |
3658 | + if (hfile->hf_br->br_id == br_id) { | |
3659 | + bfound = bindex; | |
3660 | + break; | |
3661 | + } | |
3662 | + } | |
3663 | + AuDebugOn(bfound < 0); | |
3664 | + au_set_h_fptr(file, bfound, NULL); | |
3665 | + if (bfound == bstart) { | |
3666 | + for (bstart++; bstart <= bend; bstart++) | |
3667 | + if (au_hf_dir(file, bstart)) { | |
3668 | + au_set_fbstart(file, bstart); | |
3669 | + break; | |
3670 | + } | |
3671 | + } | |
3672 | + fi_write_unlock(file); | |
3673 | + } | |
3674 | +} | |
3675 | + | |
1facf9fc | 3676 | +static void au_br_do_del_brp(struct au_sbinfo *sbinfo, |
3677 | + const aufs_bindex_t bindex, | |
3678 | + const aufs_bindex_t bend) | |
3679 | +{ | |
3680 | + struct au_branch **brp, **p; | |
3681 | + | |
dece6358 AM |
3682 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3683 | + | |
1facf9fc | 3684 | + brp = sbinfo->si_branch + bindex; |
3685 | + if (bindex < bend) | |
3686 | + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex)); | |
3687 | + sbinfo->si_branch[0 + bend] = NULL; | |
3688 | + sbinfo->si_bend--; | |
3689 | + | |
53392da6 | 3690 | + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3691 | + if (p) |
3692 | + sbinfo->si_branch = p; | |
4a4d8108 | 3693 | + /* harmless error */ |
1facf9fc | 3694 | +} |
3695 | + | |
3696 | +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex, | |
3697 | + const aufs_bindex_t bend) | |
3698 | +{ | |
3699 | + struct au_hdentry *hdp, *p; | |
3700 | + | |
1308ab2a | 3701 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3702 | + | |
4a4d8108 | 3703 | + hdp = dinfo->di_hdentry; |
1facf9fc | 3704 | + if (bindex < bend) |
4a4d8108 AM |
3705 | + memmove(hdp + bindex, hdp + bindex + 1, |
3706 | + sizeof(*hdp) * (bend - bindex)); | |
3707 | + hdp[0 + bend].hd_dentry = NULL; | |
1facf9fc | 3708 | + dinfo->di_bend--; |
3709 | + | |
53392da6 | 3710 | + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3711 | + if (p) |
3712 | + dinfo->di_hdentry = p; | |
4a4d8108 | 3713 | + /* harmless error */ |
1facf9fc | 3714 | +} |
3715 | + | |
3716 | +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex, | |
3717 | + const aufs_bindex_t bend) | |
3718 | +{ | |
3719 | + struct au_hinode *hip, *p; | |
3720 | + | |
1308ab2a | 3721 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3722 | + | |
1facf9fc | 3723 | + hip = iinfo->ii_hinode + bindex; |
3724 | + if (bindex < bend) | |
3725 | + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex)); | |
3726 | + iinfo->ii_hinode[0 + bend].hi_inode = NULL; | |
4a4d8108 | 3727 | + au_hn_init(iinfo->ii_hinode + bend); |
1facf9fc | 3728 | + iinfo->ii_bend--; |
3729 | + | |
53392da6 | 3730 | + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3731 | + if (p) |
3732 | + iinfo->ii_hinode = p; | |
4a4d8108 | 3733 | + /* harmless error */ |
1facf9fc | 3734 | +} |
3735 | + | |
3736 | +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex, | |
3737 | + struct au_branch *br) | |
3738 | +{ | |
3739 | + aufs_bindex_t bend; | |
3740 | + struct au_sbinfo *sbinfo; | |
53392da6 AM |
3741 | + struct dentry *root, *h_root; |
3742 | + struct inode *inode, *h_inode; | |
3743 | + struct au_hinode *hinode; | |
1facf9fc | 3744 | + |
dece6358 AM |
3745 | + SiMustWriteLock(sb); |
3746 | + | |
1facf9fc | 3747 | + root = sb->s_root; |
5527c038 | 3748 | + inode = d_inode(root); |
1facf9fc | 3749 | + sbinfo = au_sbi(sb); |
3750 | + bend = sbinfo->si_bend; | |
3751 | + | |
53392da6 AM |
3752 | + h_root = au_h_dptr(root, bindex); |
3753 | + hinode = au_hi(inode, bindex); | |
3754 | + h_inode = au_igrab(hinode->hi_inode); | |
3755 | + au_hiput(hinode); | |
1facf9fc | 3756 | + |
53392da6 | 3757 | + au_sbilist_lock(); |
1facf9fc | 3758 | + au_br_do_del_brp(sbinfo, bindex, bend); |
3759 | + au_br_do_del_hdp(au_di(root), bindex, bend); | |
3760 | + au_br_do_del_hip(au_ii(inode), bindex, bend); | |
53392da6 AM |
3761 | + au_sbilist_unlock(); |
3762 | + | |
3763 | + dput(h_root); | |
3764 | + iput(h_inode); | |
3765 | + au_br_do_free(br); | |
1facf9fc | 3766 | +} |
3767 | + | |
076b876e AM |
3768 | +static unsigned long long empty_cb(void *array, unsigned long long max, |
3769 | + void *arg) | |
3770 | +{ | |
3771 | + return max; | |
3772 | +} | |
3773 | + | |
1facf9fc | 3774 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount) |
3775 | +{ | |
3776 | + int err, rerr, i; | |
076b876e | 3777 | + unsigned long long opened; |
1facf9fc | 3778 | + unsigned int mnt_flags; |
3779 | + aufs_bindex_t bindex, bend, br_id; | |
3780 | + unsigned char do_wh, verbose; | |
3781 | + struct au_branch *br; | |
3782 | + struct au_wbr *wbr; | |
076b876e AM |
3783 | + struct dentry *root; |
3784 | + struct file **to_free; | |
1facf9fc | 3785 | + |
3786 | + err = 0; | |
076b876e AM |
3787 | + opened = 0; |
3788 | + to_free = NULL; | |
3789 | + root = sb->s_root; | |
3790 | + bindex = au_find_dbindex(root, del->h_path.dentry); | |
1facf9fc | 3791 | + if (bindex < 0) { |
3792 | + if (remount) | |
3793 | + goto out; /* success */ | |
3794 | + err = -ENOENT; | |
4a4d8108 | 3795 | + pr_err("%s no such branch\n", del->pathname); |
1facf9fc | 3796 | + goto out; |
3797 | + } | |
3798 | + AuDbg("bindex b%d\n", bindex); | |
3799 | + | |
3800 | + err = -EBUSY; | |
3801 | + mnt_flags = au_mntflags(sb); | |
3802 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
3803 | + bend = au_sbend(sb); | |
3804 | + if (unlikely(!bend)) { | |
3805 | + AuVerbose(verbose, "no more branches left\n"); | |
3806 | + goto out; | |
3807 | + } | |
3808 | + br = au_sbr(sb, bindex); | |
86dc4139 | 3809 | + AuDebugOn(!path_equal(&br->br_path, &del->h_path)); |
076b876e AM |
3810 | + |
3811 | + br_id = br->br_id; | |
3812 | + opened = atomic_read(&br->br_count); | |
3813 | + if (unlikely(opened)) { | |
3814 | + to_free = au_array_alloc(&opened, empty_cb, NULL); | |
3815 | + err = PTR_ERR(to_free); | |
3816 | + if (IS_ERR(to_free)) | |
3817 | + goto out; | |
3818 | + | |
3819 | + err = test_file_busy(sb, br_id, to_free, opened); | |
3820 | + if (unlikely(err)) { | |
3821 | + AuVerbose(verbose, "%llu file(s) opened\n", opened); | |
3822 | + goto out; | |
3823 | + } | |
1facf9fc | 3824 | + } |
3825 | + | |
3826 | + wbr = br->br_wbr; | |
3827 | + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph); | |
3828 | + if (do_wh) { | |
1308ab2a | 3829 | + /* instead of WbrWhMustWriteLock(wbr) */ |
3830 | + SiMustWriteLock(sb); | |
1facf9fc | 3831 | + for (i = 0; i < AuBrWh_Last; i++) { |
3832 | + dput(wbr->wbr_wh[i]); | |
3833 | + wbr->wbr_wh[i] = NULL; | |
3834 | + } | |
3835 | + } | |
3836 | + | |
076b876e | 3837 | + err = test_children_busy(root, bindex, verbose); |
1facf9fc | 3838 | + if (unlikely(err)) { |
3839 | + if (do_wh) | |
3840 | + goto out_wh; | |
3841 | + goto out; | |
3842 | + } | |
3843 | + | |
3844 | + err = 0; | |
076b876e AM |
3845 | + if (to_free) { |
3846 | + /* | |
3847 | + * now we confirmed the branch is deletable. | |
3848 | + * let's free the remaining opened dirs on the branch. | |
3849 | + */ | |
3850 | + di_write_unlock(root); | |
3851 | + br_del_file(to_free, opened, br_id); | |
3852 | + di_write_lock_child(root); | |
3853 | + } | |
3854 | + | |
1facf9fc | 3855 | + if (!remount) |
3856 | + au_br_do_del(sb, bindex, br); | |
3857 | + else { | |
3858 | + sysaufs_brs_del(sb, bindex); | |
3859 | + au_br_do_del(sb, bindex, br); | |
3860 | + sysaufs_brs_add(sb, bindex); | |
3861 | + } | |
3862 | + | |
1308ab2a | 3863 | + if (!bindex) { |
5527c038 | 3864 | + au_cpup_attr_all(d_inode(root), /*force*/1); |
1308ab2a | 3865 | + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes; |
3866 | + } else | |
5527c038 | 3867 | + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry)); |
1facf9fc | 3868 | + if (au_opt_test(mnt_flags, PLINK)) |
3869 | + au_plink_half_refresh(sb, br_id); | |
3870 | + | |
b752ccd1 | 3871 | + if (au_xino_brid(sb) == br_id) |
1facf9fc | 3872 | + au_xino_brid_set(sb, -1); |
3873 | + goto out; /* success */ | |
3874 | + | |
4f0767ce | 3875 | +out_wh: |
1facf9fc | 3876 | + /* revert */ |
86dc4139 | 3877 | + rerr = au_br_init_wh(sb, br, br->br_perm); |
1facf9fc | 3878 | + if (rerr) |
0c3ec466 AM |
3879 | + pr_warn("failed re-creating base whiteout, %s. (%d)\n", |
3880 | + del->pathname, rerr); | |
4f0767ce | 3881 | +out: |
076b876e AM |
3882 | + if (to_free) |
3883 | + au_farray_free(to_free, opened); | |
1facf9fc | 3884 | + return err; |
3885 | +} | |
3886 | + | |
3887 | +/* ---------------------------------------------------------------------- */ | |
3888 | + | |
027c5e7a AM |
3889 | +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg) |
3890 | +{ | |
3891 | + int err; | |
3892 | + aufs_bindex_t bstart, bend; | |
3893 | + struct aufs_ibusy ibusy; | |
3894 | + struct inode *inode, *h_inode; | |
3895 | + | |
3896 | + err = -EPERM; | |
3897 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
3898 | + goto out; | |
3899 | + | |
3900 | + err = copy_from_user(&ibusy, arg, sizeof(ibusy)); | |
3901 | + if (!err) | |
3902 | + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino)); | |
3903 | + if (unlikely(err)) { | |
3904 | + err = -EFAULT; | |
3905 | + AuTraceErr(err); | |
3906 | + goto out; | |
3907 | + } | |
3908 | + | |
3909 | + err = -EINVAL; | |
3910 | + si_read_lock(sb, AuLock_FLUSH); | |
3911 | + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb))) | |
3912 | + goto out_unlock; | |
3913 | + | |
3914 | + err = 0; | |
3915 | + ibusy.h_ino = 0; /* invalid */ | |
3916 | + inode = ilookup(sb, ibusy.ino); | |
3917 | + if (!inode | |
3918 | + || inode->i_ino == AUFS_ROOT_INO | |
3919 | + || is_bad_inode(inode)) | |
3920 | + goto out_unlock; | |
3921 | + | |
3922 | + ii_read_lock_child(inode); | |
3923 | + bstart = au_ibstart(inode); | |
3924 | + bend = au_ibend(inode); | |
3925 | + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) { | |
3926 | + h_inode = au_h_iptr(inode, ibusy.bindex); | |
3927 | + if (h_inode && au_test_ibusy(inode, bstart, bend)) | |
3928 | + ibusy.h_ino = h_inode->i_ino; | |
3929 | + } | |
3930 | + ii_read_unlock(inode); | |
3931 | + iput(inode); | |
3932 | + | |
3933 | +out_unlock: | |
3934 | + si_read_unlock(sb); | |
3935 | + if (!err) { | |
3936 | + err = __put_user(ibusy.h_ino, &arg->h_ino); | |
3937 | + if (unlikely(err)) { | |
3938 | + err = -EFAULT; | |
3939 | + AuTraceErr(err); | |
3940 | + } | |
3941 | + } | |
3942 | +out: | |
3943 | + return err; | |
3944 | +} | |
3945 | + | |
3946 | +long au_ibusy_ioctl(struct file *file, unsigned long arg) | |
3947 | +{ | |
2000de60 | 3948 | + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg); |
027c5e7a AM |
3949 | +} |
3950 | + | |
3951 | +#ifdef CONFIG_COMPAT | |
3952 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg) | |
3953 | +{ | |
2000de60 | 3954 | + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg)); |
027c5e7a AM |
3955 | +} |
3956 | +#endif | |
3957 | + | |
3958 | +/* ---------------------------------------------------------------------- */ | |
3959 | + | |
1facf9fc | 3960 | +/* |
3961 | + * change a branch permission | |
3962 | + */ | |
3963 | + | |
dece6358 AM |
3964 | +static void au_warn_ima(void) |
3965 | +{ | |
3966 | +#ifdef CONFIG_IMA | |
1308ab2a | 3967 | + /* since it doesn't support mark_files_ro() */ |
027c5e7a | 3968 | + AuWarn1("RW -> RO makes IMA to produce wrong message\n"); |
dece6358 AM |
3969 | +#endif |
3970 | +} | |
3971 | + | |
1facf9fc | 3972 | +static int do_need_sigen_inc(int a, int b) |
3973 | +{ | |
3974 | + return au_br_whable(a) && !au_br_whable(b); | |
3975 | +} | |
3976 | + | |
3977 | +static int need_sigen_inc(int old, int new) | |
3978 | +{ | |
3979 | + return do_need_sigen_inc(old, new) | |
3980 | + || do_need_sigen_inc(new, old); | |
3981 | +} | |
3982 | + | |
3983 | +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex) | |
3984 | +{ | |
7f207e10 | 3985 | + int err, do_warn; |
027c5e7a | 3986 | + unsigned int mnt_flags; |
7f207e10 | 3987 | + unsigned long long ull, max; |
e49829fe | 3988 | + aufs_bindex_t br_id; |
38d290e6 | 3989 | + unsigned char verbose, writer; |
7f207e10 | 3990 | + struct file *file, *hf, **array; |
e49829fe | 3991 | + struct au_hfile *hfile; |
1facf9fc | 3992 | + |
027c5e7a AM |
3993 | + mnt_flags = au_mntflags(sb); |
3994 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
3995 | + | |
7f207e10 AM |
3996 | + array = au_farray_alloc(sb, &max); |
3997 | + err = PTR_ERR(array); | |
3998 | + if (IS_ERR(array)) | |
1facf9fc | 3999 | + goto out; |
4000 | + | |
7f207e10 | 4001 | + do_warn = 0; |
e49829fe | 4002 | + br_id = au_sbr_id(sb, bindex); |
7f207e10 AM |
4003 | + for (ull = 0; ull < max; ull++) { |
4004 | + file = array[ull]; | |
076b876e AM |
4005 | + if (unlikely(!file)) |
4006 | + break; | |
1facf9fc | 4007 | + |
523b37e3 | 4008 | + /* AuDbg("%pD\n", file); */ |
1facf9fc | 4009 | + fi_read_lock(file); |
4010 | + if (unlikely(au_test_mmapped(file))) { | |
4011 | + err = -EBUSY; | |
523b37e3 | 4012 | + AuVerbose(verbose, "mmapped %pD\n", file); |
7f207e10 | 4013 | + AuDbgFile(file); |
1facf9fc | 4014 | + FiMustNoWaiters(file); |
4015 | + fi_read_unlock(file); | |
7f207e10 | 4016 | + goto out_array; |
1facf9fc | 4017 | + } |
4018 | + | |
e49829fe JR |
4019 | + hfile = &au_fi(file)->fi_htop; |
4020 | + hf = hfile->hf_file; | |
7e9cd9fe | 4021 | + if (!d_is_reg(file->f_path.dentry) |
1facf9fc | 4022 | + || !(file->f_mode & FMODE_WRITE) |
e49829fe | 4023 | + || hfile->hf_br->br_id != br_id |
7f207e10 AM |
4024 | + || !(hf->f_mode & FMODE_WRITE)) |
4025 | + array[ull] = NULL; | |
4026 | + else { | |
4027 | + do_warn = 1; | |
4028 | + get_file(file); | |
1facf9fc | 4029 | + } |
4030 | + | |
1facf9fc | 4031 | + FiMustNoWaiters(file); |
4032 | + fi_read_unlock(file); | |
7f207e10 AM |
4033 | + fput(file); |
4034 | + } | |
1facf9fc | 4035 | + |
4036 | + err = 0; | |
7f207e10 | 4037 | + if (do_warn) |
dece6358 | 4038 | + au_warn_ima(); |
7f207e10 AM |
4039 | + |
4040 | + for (ull = 0; ull < max; ull++) { | |
4041 | + file = array[ull]; | |
4042 | + if (!file) | |
4043 | + continue; | |
4044 | + | |
1facf9fc | 4045 | + /* todo: already flushed? */ |
523b37e3 AM |
4046 | + /* |
4047 | + * fs/super.c:mark_files_ro() is gone, but aufs keeps its | |
4048 | + * approach which resets f_mode and calls mnt_drop_write() and | |
4049 | + * file_release_write() for each file, because the branch | |
4050 | + * attribute in aufs world is totally different from the native | |
4051 | + * fs rw/ro mode. | |
4052 | + */ | |
7f207e10 AM |
4053 | + /* fi_read_lock(file); */ |
4054 | + hfile = &au_fi(file)->fi_htop; | |
4055 | + hf = hfile->hf_file; | |
4056 | + /* fi_read_unlock(file); */ | |
027c5e7a | 4057 | + spin_lock(&hf->f_lock); |
38d290e6 JR |
4058 | + writer = !!(hf->f_mode & FMODE_WRITER); |
4059 | + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER); | |
027c5e7a | 4060 | + spin_unlock(&hf->f_lock); |
38d290e6 JR |
4061 | + if (writer) { |
4062 | + put_write_access(file_inode(hf)); | |
c06a8ce3 | 4063 | + __mnt_drop_write(hf->f_path.mnt); |
1facf9fc | 4064 | + } |
4065 | + } | |
4066 | + | |
7f207e10 AM |
4067 | +out_array: |
4068 | + au_farray_free(array, max); | |
4f0767ce | 4069 | +out: |
7f207e10 | 4070 | + AuTraceErr(err); |
1facf9fc | 4071 | + return err; |
4072 | +} | |
4073 | + | |
4074 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4075 | + int *do_refresh) |
1facf9fc | 4076 | +{ |
4077 | + int err, rerr; | |
4078 | + aufs_bindex_t bindex; | |
4079 | + struct dentry *root; | |
4080 | + struct au_branch *br; | |
076b876e | 4081 | + struct au_br_fhsm *bf; |
1facf9fc | 4082 | + |
4083 | + root = sb->s_root; | |
1facf9fc | 4084 | + bindex = au_find_dbindex(root, mod->h_root); |
4085 | + if (bindex < 0) { | |
4086 | + if (remount) | |
4087 | + return 0; /* success */ | |
4088 | + err = -ENOENT; | |
4a4d8108 | 4089 | + pr_err("%s no such branch\n", mod->path); |
1facf9fc | 4090 | + goto out; |
4091 | + } | |
4092 | + AuDbg("bindex b%d\n", bindex); | |
4093 | + | |
5527c038 | 4094 | + err = test_br(d_inode(mod->h_root), mod->perm, mod->path); |
1facf9fc | 4095 | + if (unlikely(err)) |
4096 | + goto out; | |
4097 | + | |
4098 | + br = au_sbr(sb, bindex); | |
86dc4139 | 4099 | + AuDebugOn(mod->h_root != au_br_dentry(br)); |
1facf9fc | 4100 | + if (br->br_perm == mod->perm) |
4101 | + return 0; /* success */ | |
4102 | + | |
076b876e AM |
4103 | + /* pre-allocate for non-fhsm --> fhsm */ |
4104 | + bf = NULL; | |
4105 | + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) { | |
4106 | + err = au_fhsm_br_alloc(br); | |
4107 | + if (unlikely(err)) | |
4108 | + goto out; | |
4109 | + bf = br->br_fhsm; | |
4110 | + br->br_fhsm = NULL; | |
4111 | + } | |
4112 | + | |
1facf9fc | 4113 | + if (au_br_writable(br->br_perm)) { |
4114 | + /* remove whiteout base */ | |
86dc4139 | 4115 | + err = au_br_init_wh(sb, br, mod->perm); |
1facf9fc | 4116 | + if (unlikely(err)) |
076b876e | 4117 | + goto out_bf; |
1facf9fc | 4118 | + |
4119 | + if (!au_br_writable(mod->perm)) { | |
4120 | + /* rw --> ro, file might be mmapped */ | |
4121 | + DiMustNoWaiters(root); | |
5527c038 | 4122 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 4123 | + di_write_unlock(root); |
4124 | + err = au_br_mod_files_ro(sb, bindex); | |
4125 | + /* aufs_write_lock() calls ..._child() */ | |
4126 | + di_write_lock_child(root); | |
4127 | + | |
4128 | + if (unlikely(err)) { | |
4129 | + rerr = -ENOMEM; | |
4130 | + br->br_wbr = kmalloc(sizeof(*br->br_wbr), | |
4131 | + GFP_NOFS); | |
86dc4139 AM |
4132 | + if (br->br_wbr) |
4133 | + rerr = au_wbr_init(br, sb, br->br_perm); | |
1facf9fc | 4134 | + if (unlikely(rerr)) { |
4135 | + AuIOErr("nested error %d (%d)\n", | |
4136 | + rerr, err); | |
4137 | + br->br_perm = mod->perm; | |
4138 | + } | |
4139 | + } | |
4140 | + } | |
4141 | + } else if (au_br_writable(mod->perm)) { | |
4142 | + /* ro --> rw */ | |
4143 | + err = -ENOMEM; | |
4144 | + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS); | |
4145 | + if (br->br_wbr) { | |
86dc4139 | 4146 | + err = au_wbr_init(br, sb, mod->perm); |
1facf9fc | 4147 | + if (unlikely(err)) { |
4148 | + kfree(br->br_wbr); | |
4149 | + br->br_wbr = NULL; | |
4150 | + } | |
4151 | + } | |
4152 | + } | |
076b876e AM |
4153 | + if (unlikely(err)) |
4154 | + goto out_bf; | |
4155 | + | |
4156 | + if (au_br_fhsm(br->br_perm)) { | |
4157 | + if (!au_br_fhsm(mod->perm)) { | |
4158 | + /* fhsm --> non-fhsm */ | |
4159 | + au_br_fhsm_fin(br->br_fhsm); | |
4160 | + kfree(br->br_fhsm); | |
4161 | + br->br_fhsm = NULL; | |
4162 | + } | |
4163 | + } else if (au_br_fhsm(mod->perm)) | |
4164 | + /* non-fhsm --> fhsm */ | |
4165 | + br->br_fhsm = bf; | |
4166 | + | |
076b876e AM |
4167 | + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm); |
4168 | + br->br_perm = mod->perm; | |
4169 | + goto out; /* success */ | |
1facf9fc | 4170 | + |
076b876e AM |
4171 | +out_bf: |
4172 | + kfree(bf); | |
4173 | +out: | |
4174 | + AuTraceErr(err); | |
4175 | + return err; | |
4176 | +} | |
4177 | + | |
4178 | +/* ---------------------------------------------------------------------- */ | |
4179 | + | |
4180 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs) | |
4181 | +{ | |
4182 | + int err; | |
4183 | + struct kstatfs kstfs; | |
4184 | + | |
4185 | + err = vfs_statfs(&br->br_path, &kstfs); | |
1facf9fc | 4186 | + if (!err) { |
076b876e AM |
4187 | + stfs->f_blocks = kstfs.f_blocks; |
4188 | + stfs->f_bavail = kstfs.f_bavail; | |
4189 | + stfs->f_files = kstfs.f_files; | |
4190 | + stfs->f_ffree = kstfs.f_ffree; | |
1facf9fc | 4191 | + } |
4192 | + | |
1facf9fc | 4193 | + return err; |
4194 | +} | |
7f207e10 AM |
4195 | diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h |
4196 | --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 4197 | +++ linux/fs/aufs/branch.h 2015-06-28 17:36:09.025073697 +0200 |
b912730e | 4198 | @@ -0,0 +1,279 @@ |
1facf9fc | 4199 | +/* |
2000de60 | 4200 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 4201 | + * |
4202 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4203 | + * it under the terms of the GNU General Public License as published by | |
4204 | + * the Free Software Foundation; either version 2 of the License, or | |
4205 | + * (at your option) any later version. | |
dece6358 AM |
4206 | + * |
4207 | + * This program is distributed in the hope that it will be useful, | |
4208 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4209 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4210 | + * GNU General Public License for more details. | |
4211 | + * | |
4212 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4213 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4214 | + */ |
4215 | + | |
4216 | +/* | |
4217 | + * branch filesystems and xino for them | |
4218 | + */ | |
4219 | + | |
4220 | +#ifndef __AUFS_BRANCH_H__ | |
4221 | +#define __AUFS_BRANCH_H__ | |
4222 | + | |
4223 | +#ifdef __KERNEL__ | |
4224 | + | |
1facf9fc | 4225 | +#include <linux/mount.h> |
4a4d8108 | 4226 | +#include "dynop.h" |
1facf9fc | 4227 | +#include "rwsem.h" |
4228 | +#include "super.h" | |
4229 | + | |
4230 | +/* ---------------------------------------------------------------------- */ | |
4231 | + | |
4232 | +/* a xino file */ | |
4233 | +struct au_xino_file { | |
4234 | + struct file *xi_file; | |
4235 | + struct mutex xi_nondir_mtx; | |
4236 | + | |
4237 | + /* todo: make xino files an array to support huge inode number */ | |
4238 | + | |
4239 | +#ifdef CONFIG_DEBUG_FS | |
4240 | + struct dentry *xi_dbgaufs; | |
4241 | +#endif | |
4242 | +}; | |
4243 | + | |
076b876e AM |
4244 | +/* File-based Hierarchical Storage Management */ |
4245 | +struct au_br_fhsm { | |
4246 | +#ifdef CONFIG_AUFS_FHSM | |
4247 | + struct mutex bf_lock; | |
4248 | + unsigned long bf_jiffy; | |
4249 | + struct aufs_stfs bf_stfs; | |
4250 | + int bf_readable; | |
4251 | +#endif | |
4252 | +}; | |
4253 | + | |
1facf9fc | 4254 | +/* members for writable branch only */ |
4255 | +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last}; | |
4256 | +struct au_wbr { | |
dece6358 | 4257 | + struct au_rwsem wbr_wh_rwsem; |
1facf9fc | 4258 | + struct dentry *wbr_wh[AuBrWh_Last]; |
4a4d8108 | 4259 | + atomic_t wbr_wh_running; |
1facf9fc | 4260 | +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */ |
4261 | +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */ | |
4262 | +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */ | |
4263 | + | |
4264 | + /* mfs mode */ | |
4265 | + unsigned long long wbr_bytes; | |
4266 | +}; | |
4267 | + | |
4a4d8108 AM |
4268 | +/* ext2 has 3 types of operations at least, ext3 has 4 */ |
4269 | +#define AuBrDynOp (AuDyLast * 4) | |
4270 | + | |
1716fcea AM |
4271 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
4272 | +/* support for asynchronous destruction */ | |
4273 | +struct au_br_hfsnotify { | |
4274 | + struct fsnotify_group *hfsn_group; | |
4275 | +}; | |
4276 | +#endif | |
4277 | + | |
392086de AM |
4278 | +/* sysfs entries */ |
4279 | +struct au_brsysfs { | |
4280 | + char name[16]; | |
4281 | + struct attribute attr; | |
4282 | +}; | |
4283 | + | |
4284 | +enum { | |
4285 | + AuBrSysfs_BR, | |
4286 | + AuBrSysfs_BRID, | |
4287 | + AuBrSysfs_Last | |
4288 | +}; | |
4289 | + | |
1facf9fc | 4290 | +/* protected by superblock rwsem */ |
4291 | +struct au_branch { | |
4292 | + struct au_xino_file br_xino; | |
4293 | + | |
4294 | + aufs_bindex_t br_id; | |
4295 | + | |
4296 | + int br_perm; | |
86dc4139 | 4297 | + struct path br_path; |
4a4d8108 AM |
4298 | + spinlock_t br_dykey_lock; |
4299 | + struct au_dykey *br_dykey[AuBrDynOp]; | |
1facf9fc | 4300 | + atomic_t br_count; |
4301 | + | |
4302 | + struct au_wbr *br_wbr; | |
076b876e | 4303 | + struct au_br_fhsm *br_fhsm; |
1facf9fc | 4304 | + |
4305 | + /* xino truncation */ | |
1facf9fc | 4306 | + atomic_t br_xino_running; |
4307 | + | |
027c5e7a | 4308 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
1716fcea | 4309 | + struct au_br_hfsnotify *br_hfsn; |
027c5e7a AM |
4310 | +#endif |
4311 | + | |
1facf9fc | 4312 | +#ifdef CONFIG_SYSFS |
392086de AM |
4313 | + /* entries under sysfs per mount-point */ |
4314 | + struct au_brsysfs br_sysfs[AuBrSysfs_Last]; | |
1facf9fc | 4315 | +#endif |
4316 | +}; | |
4317 | + | |
4318 | +/* ---------------------------------------------------------------------- */ | |
4319 | + | |
86dc4139 AM |
4320 | +static inline struct vfsmount *au_br_mnt(struct au_branch *br) |
4321 | +{ | |
4322 | + return br->br_path.mnt; | |
4323 | +} | |
4324 | + | |
4325 | +static inline struct dentry *au_br_dentry(struct au_branch *br) | |
4326 | +{ | |
4327 | + return br->br_path.dentry; | |
4328 | +} | |
4329 | + | |
4330 | +static inline struct super_block *au_br_sb(struct au_branch *br) | |
4331 | +{ | |
4332 | + return au_br_mnt(br)->mnt_sb; | |
4333 | +} | |
4334 | + | |
1facf9fc | 4335 | +static inline int au_br_rdonly(struct au_branch *br) |
4336 | +{ | |
86dc4139 | 4337 | + return ((au_br_sb(br)->s_flags & MS_RDONLY) |
1facf9fc | 4338 | + || !au_br_writable(br->br_perm)) |
4339 | + ? -EROFS : 0; | |
4340 | +} | |
4341 | + | |
4a4d8108 | 4342 | +static inline int au_br_hnotifyable(int brperm __maybe_unused) |
1facf9fc | 4343 | +{ |
4a4d8108 | 4344 | +#ifdef CONFIG_AUFS_HNOTIFY |
1e00d052 | 4345 | + return !(brperm & AuBrPerm_RR); |
1facf9fc | 4346 | +#else |
4347 | + return 0; | |
4348 | +#endif | |
4349 | +} | |
4350 | + | |
b912730e AM |
4351 | +static inline int au_br_test_oflag(int oflag, struct au_branch *br) |
4352 | +{ | |
4353 | + int err, exec_flag; | |
4354 | + | |
4355 | + err = 0; | |
4356 | + exec_flag = oflag & __FMODE_EXEC; | |
4357 | + if (unlikely(exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))) | |
4358 | + err = -EACCES; | |
4359 | + | |
4360 | + return err; | |
4361 | +} | |
4362 | + | |
1facf9fc | 4363 | +/* ---------------------------------------------------------------------- */ |
4364 | + | |
4365 | +/* branch.c */ | |
4366 | +struct au_sbinfo; | |
4367 | +void au_br_free(struct au_sbinfo *sinfo); | |
4368 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id); | |
4369 | +struct au_opt_add; | |
4370 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount); | |
4371 | +struct au_opt_del; | |
4372 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount); | |
027c5e7a AM |
4373 | +long au_ibusy_ioctl(struct file *file, unsigned long arg); |
4374 | +#ifdef CONFIG_COMPAT | |
4375 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg); | |
4376 | +#endif | |
1facf9fc | 4377 | +struct au_opt_mod; |
4378 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4379 | + int *do_refresh); |
076b876e AM |
4380 | +struct aufs_stfs; |
4381 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs); | |
1facf9fc | 4382 | + |
4383 | +/* xino.c */ | |
4384 | +static const loff_t au_loff_max = LLONG_MAX; | |
4385 | + | |
4386 | +int au_xib_trunc(struct super_block *sb); | |
5527c038 | 4387 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size, |
1facf9fc | 4388 | + loff_t *pos); |
5527c038 JR |
4389 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
4390 | + size_t size, loff_t *pos); | |
1facf9fc | 4391 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src); |
4392 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent); | |
4393 | +ino_t au_xino_new_ino(struct super_block *sb); | |
b752ccd1 | 4394 | +void au_xino_delete_inode(struct inode *inode, const int unlinked); |
1facf9fc | 4395 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
4396 | + ino_t ino); | |
4397 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4398 | + ino_t *ino); | |
4399 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino, | |
4400 | + struct file *base_file, int do_test); | |
4401 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex); | |
4402 | + | |
4403 | +struct au_opt_xino; | |
4404 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount); | |
4405 | +void au_xino_clr(struct super_block *sb); | |
4406 | +struct file *au_xino_def(struct super_block *sb); | |
4407 | +int au_xino_path(struct seq_file *seq, struct file *file); | |
4408 | + | |
4409 | +/* ---------------------------------------------------------------------- */ | |
4410 | + | |
4411 | +/* Superblock to branch */ | |
4412 | +static inline | |
4413 | +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex) | |
4414 | +{ | |
4415 | + return au_sbr(sb, bindex)->br_id; | |
4416 | +} | |
4417 | + | |
4418 | +static inline | |
4419 | +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex) | |
4420 | +{ | |
86dc4139 | 4421 | + return au_br_mnt(au_sbr(sb, bindex)); |
1facf9fc | 4422 | +} |
4423 | + | |
4424 | +static inline | |
4425 | +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex) | |
4426 | +{ | |
86dc4139 | 4427 | + return au_br_sb(au_sbr(sb, bindex)); |
1facf9fc | 4428 | +} |
4429 | + | |
4430 | +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex) | |
4431 | +{ | |
e49829fe | 4432 | + atomic_dec(&au_sbr(sb, bindex)->br_count); |
1facf9fc | 4433 | +} |
4434 | + | |
4435 | +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex) | |
4436 | +{ | |
4437 | + return au_sbr(sb, bindex)->br_perm; | |
4438 | +} | |
4439 | + | |
4440 | +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex) | |
4441 | +{ | |
4442 | + return au_br_whable(au_sbr_perm(sb, bindex)); | |
4443 | +} | |
4444 | + | |
4445 | +/* ---------------------------------------------------------------------- */ | |
4446 | + | |
4447 | +/* | |
4448 | + * wbr_wh_read_lock, wbr_wh_write_lock | |
4449 | + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock | |
4450 | + */ | |
4451 | +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem); | |
4452 | + | |
dece6358 AM |
4453 | +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem) |
4454 | +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem) | |
4455 | +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem) | |
4456 | + | |
076b876e AM |
4457 | +/* ---------------------------------------------------------------------- */ |
4458 | + | |
4459 | +#ifdef CONFIG_AUFS_FHSM | |
4460 | +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm) | |
4461 | +{ | |
4462 | + mutex_init(&brfhsm->bf_lock); | |
4463 | + brfhsm->bf_jiffy = 0; | |
4464 | + brfhsm->bf_readable = 0; | |
4465 | +} | |
4466 | + | |
4467 | +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm) | |
4468 | +{ | |
4469 | + mutex_destroy(&brfhsm->bf_lock); | |
4470 | +} | |
4471 | +#else | |
4472 | +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm) | |
4473 | +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm) | |
4474 | +#endif | |
4475 | + | |
1facf9fc | 4476 | +#endif /* __KERNEL__ */ |
4477 | +#endif /* __AUFS_BRANCH_H__ */ | |
7f207e10 AM |
4478 | diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk |
4479 | --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 4480 | +++ linux/fs/aufs/conf.mk 2015-06-28 17:35:44.348050491 +0200 |
c1595e42 | 4481 | @@ -0,0 +1,38 @@ |
4a4d8108 AM |
4482 | + |
4483 | +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS} | |
4484 | + | |
4485 | +define AuConf | |
4486 | +ifdef ${1} | |
4487 | +AuConfStr += ${1}=${${1}} | |
4488 | +endif | |
4489 | +endef | |
4490 | + | |
b752ccd1 | 4491 | +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \ |
e49829fe | 4492 | + SBILIST \ |
7f207e10 | 4493 | + HNOTIFY HFSNOTIFY \ |
4a4d8108 | 4494 | + EXPORT INO_T_64 \ |
c1595e42 | 4495 | + XATTR \ |
076b876e | 4496 | + FHSM \ |
4a4d8108 | 4497 | + RDU \ |
4a4d8108 AM |
4498 | + SHWH \ |
4499 | + BR_RAMFS \ | |
4500 | + BR_FUSE POLL \ | |
4501 | + BR_HFSPLUS \ | |
4502 | + BDEV_LOOP \ | |
b752ccd1 AM |
4503 | + DEBUG MAGIC_SYSRQ |
4504 | +$(foreach i, ${AuConfAll}, \ | |
4a4d8108 AM |
4505 | + $(eval $(call AuConf,CONFIG_AUFS_${i}))) |
4506 | + | |
4507 | +AuConfName = ${obj}/conf.str | |
4508 | +${AuConfName}.tmp: FORCE | |
4509 | + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@ | |
4510 | +${AuConfName}: ${AuConfName}.tmp | |
4511 | + @diff -q $< $@ > /dev/null 2>&1 || { \ | |
4512 | + echo ' GEN ' $@; \ | |
4513 | + cp -p $< $@; \ | |
4514 | + } | |
4515 | +FORCE: | |
4516 | +clean-files += ${AuConfName} ${AuConfName}.tmp | |
4517 | +${obj}/sysfs.o: ${AuConfName} | |
b752ccd1 AM |
4518 | + |
4519 | +-include ${srctree}/${src}/conf_priv.mk | |
7f207e10 AM |
4520 | diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c |
4521 | --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
4522 | +++ linux/fs/aufs/cpup.c 2015-06-28 17:36:09.025073697 +0200 |
4523 | @@ -0,0 +1,1319 @@ | |
1facf9fc | 4524 | +/* |
2000de60 | 4525 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 4526 | + * |
4527 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4528 | + * it under the terms of the GNU General Public License as published by | |
4529 | + * the Free Software Foundation; either version 2 of the License, or | |
4530 | + * (at your option) any later version. | |
dece6358 AM |
4531 | + * |
4532 | + * This program is distributed in the hope that it will be useful, | |
4533 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4534 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4535 | + * GNU General Public License for more details. | |
4536 | + * | |
4537 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4538 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4539 | + */ |
4540 | + | |
4541 | +/* | |
4542 | + * copy-up functions, see wbr_policy.c for copy-down | |
4543 | + */ | |
4544 | + | |
4545 | +#include <linux/fs_stack.h> | |
dece6358 | 4546 | +#include <linux/mm.h> |
1facf9fc | 4547 | +#include "aufs.h" |
4548 | + | |
86dc4139 | 4549 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags) |
1facf9fc | 4550 | +{ |
4551 | + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE | |
367653fa | 4552 | + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT; |
1facf9fc | 4553 | + |
86dc4139 AM |
4554 | + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags)); |
4555 | + | |
4556 | + dst->i_flags |= iflags & ~mask; | |
1facf9fc | 4557 | + if (au_test_fs_notime(dst->i_sb)) |
4558 | + dst->i_flags |= S_NOATIME | S_NOCMTIME; | |
4559 | +} | |
4560 | + | |
4561 | +void au_cpup_attr_timesizes(struct inode *inode) | |
4562 | +{ | |
4563 | + struct inode *h_inode; | |
4564 | + | |
4565 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4566 | + fsstack_copy_attr_times(inode, h_inode); | |
4a4d8108 | 4567 | + fsstack_copy_inode_size(inode, h_inode); |
1facf9fc | 4568 | +} |
4569 | + | |
4570 | +void au_cpup_attr_nlink(struct inode *inode, int force) | |
4571 | +{ | |
4572 | + struct inode *h_inode; | |
4573 | + struct super_block *sb; | |
4574 | + aufs_bindex_t bindex, bend; | |
4575 | + | |
4576 | + sb = inode->i_sb; | |
4577 | + bindex = au_ibstart(inode); | |
4578 | + h_inode = au_h_iptr(inode, bindex); | |
4579 | + if (!force | |
4580 | + && !S_ISDIR(h_inode->i_mode) | |
4581 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4582 | + && au_plink_test(inode)) | |
4583 | + return; | |
4584 | + | |
7eafdf33 AM |
4585 | + /* |
4586 | + * 0 can happen in revalidating. | |
38d290e6 JR |
4587 | + * h_inode->i_mutex may not be held here, but it is harmless since once |
4588 | + * i_nlink reaches 0, it will never become positive except O_TMPFILE | |
4589 | + * case. | |
4590 | + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause | |
4591 | + * the incorrect link count. | |
7eafdf33 | 4592 | + */ |
92d182d2 | 4593 | + set_nlink(inode, h_inode->i_nlink); |
1facf9fc | 4594 | + |
4595 | + /* | |
4596 | + * fewer nlink makes find(1) noisy, but larger nlink doesn't. | |
4597 | + * it may includes whplink directory. | |
4598 | + */ | |
4599 | + if (S_ISDIR(h_inode->i_mode)) { | |
4600 | + bend = au_ibend(inode); | |
4601 | + for (bindex++; bindex <= bend; bindex++) { | |
4602 | + h_inode = au_h_iptr(inode, bindex); | |
4603 | + if (h_inode) | |
4604 | + au_add_nlink(inode, h_inode); | |
4605 | + } | |
4606 | + } | |
4607 | +} | |
4608 | + | |
4609 | +void au_cpup_attr_changeable(struct inode *inode) | |
4610 | +{ | |
4611 | + struct inode *h_inode; | |
4612 | + | |
4613 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4614 | + inode->i_mode = h_inode->i_mode; | |
4615 | + inode->i_uid = h_inode->i_uid; | |
4616 | + inode->i_gid = h_inode->i_gid; | |
4617 | + au_cpup_attr_timesizes(inode); | |
86dc4139 | 4618 | + au_cpup_attr_flags(inode, h_inode->i_flags); |
1facf9fc | 4619 | +} |
4620 | + | |
4621 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode) | |
4622 | +{ | |
4623 | + struct au_iinfo *iinfo = au_ii(inode); | |
4624 | + | |
1308ab2a | 4625 | + IiMustWriteLock(inode); |
4626 | + | |
1facf9fc | 4627 | + iinfo->ii_higen = h_inode->i_generation; |
4628 | + iinfo->ii_hsb1 = h_inode->i_sb; | |
4629 | +} | |
4630 | + | |
4631 | +void au_cpup_attr_all(struct inode *inode, int force) | |
4632 | +{ | |
4633 | + struct inode *h_inode; | |
4634 | + | |
4635 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4636 | + au_cpup_attr_changeable(inode); | |
4637 | + if (inode->i_nlink > 0) | |
4638 | + au_cpup_attr_nlink(inode, force); | |
4639 | + inode->i_rdev = h_inode->i_rdev; | |
4640 | + inode->i_blkbits = h_inode->i_blkbits; | |
4641 | + au_cpup_igen(inode, h_inode); | |
4642 | +} | |
4643 | + | |
4644 | +/* ---------------------------------------------------------------------- */ | |
4645 | + | |
4646 | +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */ | |
4647 | + | |
4648 | +/* keep the timestamps of the parent dir when cpup */ | |
4649 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
4650 | + struct path *h_path) | |
4651 | +{ | |
4652 | + struct inode *h_inode; | |
4653 | + | |
4654 | + dt->dt_dentry = dentry; | |
4655 | + dt->dt_h_path = *h_path; | |
5527c038 | 4656 | + h_inode = d_inode(h_path->dentry); |
1facf9fc | 4657 | + dt->dt_atime = h_inode->i_atime; |
4658 | + dt->dt_mtime = h_inode->i_mtime; | |
4659 | + /* smp_mb(); */ | |
4660 | +} | |
4661 | + | |
4662 | +void au_dtime_revert(struct au_dtime *dt) | |
4663 | +{ | |
4664 | + struct iattr attr; | |
4665 | + int err; | |
4666 | + | |
4667 | + attr.ia_atime = dt->dt_atime; | |
4668 | + attr.ia_mtime = dt->dt_mtime; | |
4669 | + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET | |
4670 | + | ATTR_ATIME | ATTR_ATIME_SET; | |
4671 | + | |
523b37e3 AM |
4672 | + /* no delegation since this is a directory */ |
4673 | + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL); | |
1facf9fc | 4674 | + if (unlikely(err)) |
0c3ec466 | 4675 | + pr_warn("restoring timestamps failed(%d). ignored\n", err); |
1facf9fc | 4676 | +} |
4677 | + | |
4678 | +/* ---------------------------------------------------------------------- */ | |
4679 | + | |
86dc4139 AM |
4680 | +/* internal use only */ |
4681 | +struct au_cpup_reg_attr { | |
4682 | + int valid; | |
4683 | + struct kstat st; | |
4684 | + unsigned int iflags; /* inode->i_flags */ | |
4685 | +}; | |
4686 | + | |
1facf9fc | 4687 | +static noinline_for_stack |
86dc4139 AM |
4688 | +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src, |
4689 | + struct au_cpup_reg_attr *h_src_attr) | |
1facf9fc | 4690 | +{ |
c1595e42 | 4691 | + int err, sbits, icex; |
7e9cd9fe AM |
4692 | + unsigned int mnt_flags; |
4693 | + unsigned char verbose; | |
1facf9fc | 4694 | + struct iattr ia; |
4695 | + struct path h_path; | |
1308ab2a | 4696 | + struct inode *h_isrc, *h_idst; |
86dc4139 | 4697 | + struct kstat *h_st; |
c1595e42 | 4698 | + struct au_branch *br; |
1facf9fc | 4699 | + |
4700 | + h_path.dentry = au_h_dptr(dst, bindex); | |
5527c038 | 4701 | + h_idst = d_inode(h_path.dentry); |
c1595e42 JR |
4702 | + br = au_sbr(dst->d_sb, bindex); |
4703 | + h_path.mnt = au_br_mnt(br); | |
5527c038 | 4704 | + h_isrc = d_inode(h_src); |
1308ab2a | 4705 | + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID |
1facf9fc | 4706 | + | ATTR_ATIME | ATTR_MTIME |
4707 | + | ATTR_ATIME_SET | ATTR_MTIME_SET; | |
86dc4139 AM |
4708 | + if (h_src_attr && h_src_attr->valid) { |
4709 | + h_st = &h_src_attr->st; | |
4710 | + ia.ia_uid = h_st->uid; | |
4711 | + ia.ia_gid = h_st->gid; | |
4712 | + ia.ia_atime = h_st->atime; | |
4713 | + ia.ia_mtime = h_st->mtime; | |
4714 | + if (h_idst->i_mode != h_st->mode | |
4715 | + && !S_ISLNK(h_idst->i_mode)) { | |
4716 | + ia.ia_valid |= ATTR_MODE; | |
4717 | + ia.ia_mode = h_st->mode; | |
4718 | + } | |
4719 | + sbits = !!(h_st->mode & (S_ISUID | S_ISGID)); | |
4720 | + au_cpup_attr_flags(h_idst, h_src_attr->iflags); | |
4721 | + } else { | |
4722 | + ia.ia_uid = h_isrc->i_uid; | |
4723 | + ia.ia_gid = h_isrc->i_gid; | |
4724 | + ia.ia_atime = h_isrc->i_atime; | |
4725 | + ia.ia_mtime = h_isrc->i_mtime; | |
4726 | + if (h_idst->i_mode != h_isrc->i_mode | |
4727 | + && !S_ISLNK(h_idst->i_mode)) { | |
4728 | + ia.ia_valid |= ATTR_MODE; | |
4729 | + ia.ia_mode = h_isrc->i_mode; | |
4730 | + } | |
4731 | + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID)); | |
4732 | + au_cpup_attr_flags(h_idst, h_isrc->i_flags); | |
1308ab2a | 4733 | + } |
523b37e3 AM |
4734 | + /* no delegation since it is just created */ |
4735 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 4736 | + |
4737 | + /* is this nfs only? */ | |
4738 | + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) { | |
4739 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
4740 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 4741 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); |
1facf9fc | 4742 | + } |
4743 | + | |
c1595e42 | 4744 | + icex = br->br_perm & AuBrAttr_ICEX; |
7e9cd9fe AM |
4745 | + if (!err) { |
4746 | + mnt_flags = au_mntflags(dst->d_sb); | |
4747 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
4748 | + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose); | |
4749 | + } | |
c1595e42 | 4750 | + |
1facf9fc | 4751 | + return err; |
4752 | +} | |
4753 | + | |
4754 | +/* ---------------------------------------------------------------------- */ | |
4755 | + | |
4756 | +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len, | |
4757 | + char *buf, unsigned long blksize) | |
4758 | +{ | |
4759 | + int err; | |
4760 | + size_t sz, rbytes, wbytes; | |
4761 | + unsigned char all_zero; | |
4762 | + char *p, *zp; | |
4763 | + struct mutex *h_mtx; | |
4764 | + /* reduce stack usage */ | |
4765 | + struct iattr *ia; | |
4766 | + | |
4767 | + zp = page_address(ZERO_PAGE(0)); | |
4768 | + if (unlikely(!zp)) | |
4769 | + return -ENOMEM; /* possible? */ | |
4770 | + | |
4771 | + err = 0; | |
4772 | + all_zero = 0; | |
4773 | + while (len) { | |
4774 | + AuDbg("len %lld\n", len); | |
4775 | + sz = blksize; | |
4776 | + if (len < blksize) | |
4777 | + sz = len; | |
4778 | + | |
4779 | + rbytes = 0; | |
4780 | + /* todo: signal_pending? */ | |
4781 | + while (!rbytes || err == -EAGAIN || err == -EINTR) { | |
4782 | + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos); | |
4783 | + err = rbytes; | |
4784 | + } | |
4785 | + if (unlikely(err < 0)) | |
4786 | + break; | |
4787 | + | |
4788 | + all_zero = 0; | |
4789 | + if (len >= rbytes && rbytes == blksize) | |
4790 | + all_zero = !memcmp(buf, zp, rbytes); | |
4791 | + if (!all_zero) { | |
4792 | + wbytes = rbytes; | |
4793 | + p = buf; | |
4794 | + while (wbytes) { | |
4795 | + size_t b; | |
4796 | + | |
4797 | + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos); | |
4798 | + err = b; | |
4799 | + /* todo: signal_pending? */ | |
4800 | + if (unlikely(err == -EAGAIN || err == -EINTR)) | |
4801 | + continue; | |
4802 | + if (unlikely(err < 0)) | |
4803 | + break; | |
4804 | + wbytes -= b; | |
4805 | + p += b; | |
4806 | + } | |
392086de AM |
4807 | + if (unlikely(err < 0)) |
4808 | + break; | |
1facf9fc | 4809 | + } else { |
4810 | + loff_t res; | |
4811 | + | |
4812 | + AuLabel(hole); | |
4813 | + res = vfsub_llseek(dst, rbytes, SEEK_CUR); | |
4814 | + err = res; | |
4815 | + if (unlikely(res < 0)) | |
4816 | + break; | |
4817 | + } | |
4818 | + len -= rbytes; | |
4819 | + err = 0; | |
4820 | + } | |
4821 | + | |
4822 | + /* the last block may be a hole */ | |
4823 | + if (!err && all_zero) { | |
4824 | + AuLabel(last hole); | |
4825 | + | |
4826 | + err = 1; | |
2000de60 | 4827 | + if (au_test_nfs(dst->f_path.dentry->d_sb)) { |
1facf9fc | 4828 | + /* nfs requires this step to make last hole */ |
4829 | + /* is this only nfs? */ | |
4830 | + do { | |
4831 | + /* todo: signal_pending? */ | |
4832 | + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos); | |
4833 | + } while (err == -EAGAIN || err == -EINTR); | |
4834 | + if (err == 1) | |
4835 | + dst->f_pos--; | |
4836 | + } | |
4837 | + | |
4838 | + if (err == 1) { | |
4839 | + ia = (void *)buf; | |
4840 | + ia->ia_size = dst->f_pos; | |
4841 | + ia->ia_valid = ATTR_SIZE | ATTR_FILE; | |
4842 | + ia->ia_file = dst; | |
c06a8ce3 | 4843 | + h_mtx = &file_inode(dst)->i_mutex; |
1facf9fc | 4844 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2); |
523b37e3 AM |
4845 | + /* no delegation since it is just created */ |
4846 | + err = vfsub_notify_change(&dst->f_path, ia, | |
4847 | + /*delegated*/NULL); | |
1facf9fc | 4848 | + mutex_unlock(h_mtx); |
4849 | + } | |
4850 | + } | |
4851 | + | |
4852 | + return err; | |
4853 | +} | |
4854 | + | |
4855 | +int au_copy_file(struct file *dst, struct file *src, loff_t len) | |
4856 | +{ | |
4857 | + int err; | |
4858 | + unsigned long blksize; | |
4859 | + unsigned char do_kfree; | |
4860 | + char *buf; | |
4861 | + | |
4862 | + err = -ENOMEM; | |
2000de60 | 4863 | + blksize = dst->f_path.dentry->d_sb->s_blocksize; |
1facf9fc | 4864 | + if (!blksize || PAGE_SIZE < blksize) |
4865 | + blksize = PAGE_SIZE; | |
4866 | + AuDbg("blksize %lu\n", blksize); | |
4867 | + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *)); | |
4868 | + if (do_kfree) | |
4869 | + buf = kmalloc(blksize, GFP_NOFS); | |
4870 | + else | |
4871 | + buf = (void *)__get_free_page(GFP_NOFS); | |
4872 | + if (unlikely(!buf)) | |
4873 | + goto out; | |
4874 | + | |
4875 | + if (len > (1 << 22)) | |
4876 | + AuDbg("copying a large file %lld\n", (long long)len); | |
4877 | + | |
4878 | + src->f_pos = 0; | |
4879 | + dst->f_pos = 0; | |
4880 | + err = au_do_copy_file(dst, src, len, buf, blksize); | |
4881 | + if (do_kfree) | |
4882 | + kfree(buf); | |
4883 | + else | |
4884 | + free_page((unsigned long)buf); | |
4885 | + | |
4f0767ce | 4886 | +out: |
1facf9fc | 4887 | + return err; |
4888 | +} | |
4889 | + | |
4890 | +/* | |
4891 | + * to support a sparse file which is opened with O_APPEND, | |
4892 | + * we need to close the file. | |
4893 | + */ | |
c2b27bf2 | 4894 | +static int au_cp_regular(struct au_cp_generic *cpg) |
1facf9fc | 4895 | +{ |
4896 | + int err, i; | |
4897 | + enum { SRC, DST }; | |
4898 | + struct { | |
4899 | + aufs_bindex_t bindex; | |
4900 | + unsigned int flags; | |
4901 | + struct dentry *dentry; | |
392086de | 4902 | + int force_wr; |
1facf9fc | 4903 | + struct file *file; |
523b37e3 | 4904 | + void *label; |
1facf9fc | 4905 | + } *f, file[] = { |
4906 | + { | |
c2b27bf2 | 4907 | + .bindex = cpg->bsrc, |
1facf9fc | 4908 | + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE, |
523b37e3 | 4909 | + .label = &&out |
1facf9fc | 4910 | + }, |
4911 | + { | |
c2b27bf2 | 4912 | + .bindex = cpg->bdst, |
1facf9fc | 4913 | + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE, |
392086de | 4914 | + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST), |
523b37e3 | 4915 | + .label = &&out_src |
1facf9fc | 4916 | + } |
4917 | + }; | |
4918 | + struct super_block *sb; | |
4919 | + | |
4920 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 4921 | + sb = cpg->dentry->d_sb; |
1facf9fc | 4922 | + f = file; |
4923 | + for (i = 0; i < 2; i++, f++) { | |
c2b27bf2 AM |
4924 | + f->dentry = au_h_dptr(cpg->dentry, f->bindex); |
4925 | + f->file = au_h_open(cpg->dentry, f->bindex, f->flags, | |
392086de | 4926 | + /*file*/NULL, f->force_wr); |
1facf9fc | 4927 | + err = PTR_ERR(f->file); |
4928 | + if (IS_ERR(f->file)) | |
4929 | + goto *f->label; | |
1facf9fc | 4930 | + } |
4931 | + | |
4932 | + /* try stopping to update while we copyup */ | |
5527c038 | 4933 | + IMustLock(d_inode(file[SRC].dentry)); |
c2b27bf2 | 4934 | + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len); |
1facf9fc | 4935 | + |
1facf9fc | 4936 | + fput(file[DST].file); |
4937 | + au_sbr_put(sb, file[DST].bindex); | |
523b37e3 | 4938 | + |
4f0767ce | 4939 | +out_src: |
1facf9fc | 4940 | + fput(file[SRC].file); |
4941 | + au_sbr_put(sb, file[SRC].bindex); | |
4f0767ce | 4942 | +out: |
1facf9fc | 4943 | + return err; |
4944 | +} | |
4945 | + | |
c2b27bf2 | 4946 | +static int au_do_cpup_regular(struct au_cp_generic *cpg, |
86dc4139 | 4947 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 4948 | +{ |
4949 | + int err, rerr; | |
4950 | + loff_t l; | |
86dc4139 | 4951 | + struct path h_path; |
38d290e6 | 4952 | + struct inode *h_src_inode, *h_dst_inode; |
1facf9fc | 4953 | + |
4954 | + err = 0; | |
5527c038 | 4955 | + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc); |
86dc4139 | 4956 | + l = i_size_read(h_src_inode); |
c2b27bf2 AM |
4957 | + if (cpg->len == -1 || l < cpg->len) |
4958 | + cpg->len = l; | |
4959 | + if (cpg->len) { | |
86dc4139 AM |
4960 | + /* try stopping to update while we are referencing */ |
4961 | + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD); | |
c2b27bf2 | 4962 | + au_pin_hdir_unlock(cpg->pin); |
1facf9fc | 4963 | + |
c2b27bf2 AM |
4964 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
4965 | + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc); | |
86dc4139 | 4966 | + h_src_attr->iflags = h_src_inode->i_flags; |
5527c038 JR |
4967 | + if (!au_test_nfs(h_src_inode->i_sb)) |
4968 | + err = vfs_getattr(&h_path, &h_src_attr->st); | |
4969 | + else { | |
4970 | + mutex_unlock(&h_src_inode->i_mutex); | |
4971 | + err = vfs_getattr(&h_path, &h_src_attr->st); | |
4972 | + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD); | |
4973 | + } | |
86dc4139 AM |
4974 | + if (unlikely(err)) { |
4975 | + mutex_unlock(&h_src_inode->i_mutex); | |
4976 | + goto out; | |
4977 | + } | |
4978 | + h_src_attr->valid = 1; | |
c2b27bf2 | 4979 | + err = au_cp_regular(cpg); |
86dc4139 | 4980 | + mutex_unlock(&h_src_inode->i_mutex); |
c2b27bf2 | 4981 | + rerr = au_pin_hdir_relock(cpg->pin); |
86dc4139 AM |
4982 | + if (!err && rerr) |
4983 | + err = rerr; | |
1facf9fc | 4984 | + } |
38d290e6 JR |
4985 | + if (!err && (h_src_inode->i_state & I_LINKABLE)) { |
4986 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst); | |
5527c038 | 4987 | + h_dst_inode = d_inode(h_path.dentry); |
38d290e6 JR |
4988 | + spin_lock(&h_dst_inode->i_lock); |
4989 | + h_dst_inode->i_state |= I_LINKABLE; | |
4990 | + spin_unlock(&h_dst_inode->i_lock); | |
4991 | + } | |
1facf9fc | 4992 | + |
4f0767ce | 4993 | +out: |
1facf9fc | 4994 | + return err; |
4995 | +} | |
4996 | + | |
4997 | +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src, | |
4998 | + struct inode *h_dir) | |
4999 | +{ | |
5000 | + int err, symlen; | |
5001 | + mm_segment_t old_fs; | |
b752ccd1 AM |
5002 | + union { |
5003 | + char *k; | |
5004 | + char __user *u; | |
5005 | + } sym; | |
5527c038 JR |
5006 | + struct inode *h_inode = d_inode(h_src); |
5007 | + const struct inode_operations *h_iop = h_inode->i_op; | |
1facf9fc | 5008 | + |
5009 | + err = -ENOSYS; | |
5527c038 | 5010 | + if (unlikely(!h_iop->readlink)) |
1facf9fc | 5011 | + goto out; |
5012 | + | |
5013 | + err = -ENOMEM; | |
537831f9 | 5014 | + sym.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 5015 | + if (unlikely(!sym.k)) |
1facf9fc | 5016 | + goto out; |
5017 | + | |
9dbd164d | 5018 | + /* unnecessary to support mmap_sem since symlink is not mmap-able */ |
1facf9fc | 5019 | + old_fs = get_fs(); |
5020 | + set_fs(KERNEL_DS); | |
5527c038 | 5021 | + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX); |
1facf9fc | 5022 | + err = symlen; |
5023 | + set_fs(old_fs); | |
5024 | + | |
5025 | + if (symlen > 0) { | |
b752ccd1 AM |
5026 | + sym.k[symlen] = 0; |
5027 | + err = vfsub_symlink(h_dir, h_path, sym.k); | |
1facf9fc | 5028 | + } |
537831f9 | 5029 | + free_page((unsigned long)sym.k); |
1facf9fc | 5030 | + |
4f0767ce | 5031 | +out: |
1facf9fc | 5032 | + return err; |
5033 | +} | |
5034 | + | |
1facf9fc | 5035 | +static noinline_for_stack |
c2b27bf2 | 5036 | +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent, |
86dc4139 | 5037 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5038 | +{ |
5039 | + int err; | |
5040 | + umode_t mode; | |
5041 | + unsigned int mnt_flags; | |
076b876e | 5042 | + unsigned char isdir, isreg, force; |
c2b27bf2 | 5043 | + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5044 | + struct au_dtime dt; |
5045 | + struct path h_path; | |
5046 | + struct dentry *h_src, *h_dst, *h_parent; | |
5527c038 | 5047 | + struct inode *h_inode, *h_dir, *dir, *inode; |
1facf9fc | 5048 | + struct super_block *sb; |
5049 | + | |
5050 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5051 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 JR |
5052 | + h_inode = d_inode(h_src); |
5053 | + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc)); | |
1facf9fc | 5054 | + |
5055 | + /* try stopping to be referenced while we are creating */ | |
c2b27bf2 AM |
5056 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); |
5057 | + if (au_ftest_cpup(cpg->flags, RENAME)) | |
86dc4139 AM |
5058 | + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX, |
5059 | + AUFS_WH_PFX_LEN)); | |
1facf9fc | 5060 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5061 | + h_dir = d_inode(h_parent); |
1facf9fc | 5062 | + IMustLock(h_dir); |
5063 | + AuDebugOn(h_parent != h_dst->d_parent); | |
5064 | + | |
c2b27bf2 AM |
5065 | + sb = cpg->dentry->d_sb; |
5066 | + h_path.mnt = au_sbr_mnt(sb, cpg->bdst); | |
1facf9fc | 5067 | + if (do_dt) { |
5068 | + h_path.dentry = h_parent; | |
5069 | + au_dtime_store(&dt, dst_parent, &h_path); | |
5070 | + } | |
5071 | + h_path.dentry = h_dst; | |
5072 | + | |
076b876e | 5073 | + isreg = 0; |
1facf9fc | 5074 | + isdir = 0; |
5075 | + mode = h_inode->i_mode; | |
5076 | + switch (mode & S_IFMT) { | |
5077 | + case S_IFREG: | |
076b876e | 5078 | + isreg = 1; |
b4510431 AM |
5079 | + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR, |
5080 | + /*want_excl*/true); | |
1facf9fc | 5081 | + if (!err) |
c2b27bf2 | 5082 | + err = au_do_cpup_regular(cpg, h_src_attr); |
1facf9fc | 5083 | + break; |
5084 | + case S_IFDIR: | |
5085 | + isdir = 1; | |
5086 | + err = vfsub_mkdir(h_dir, &h_path, mode); | |
5087 | + if (!err) { | |
5088 | + /* | |
5089 | + * strange behaviour from the users view, | |
5090 | + * particularry setattr case | |
5091 | + */ | |
5527c038 JR |
5092 | + dir = d_inode(dst_parent); |
5093 | + if (au_ibstart(dir) == cpg->bdst) | |
5094 | + au_cpup_attr_nlink(dir, /*force*/1); | |
5095 | + inode = d_inode(cpg->dentry); | |
5096 | + au_cpup_attr_nlink(inode, /*force*/1); | |
1facf9fc | 5097 | + } |
5098 | + break; | |
5099 | + case S_IFLNK: | |
5100 | + err = au_do_cpup_symlink(&h_path, h_src, h_dir); | |
5101 | + break; | |
5102 | + case S_IFCHR: | |
5103 | + case S_IFBLK: | |
5104 | + AuDebugOn(!capable(CAP_MKNOD)); | |
5105 | + /*FALLTHROUGH*/ | |
5106 | + case S_IFIFO: | |
5107 | + case S_IFSOCK: | |
5108 | + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev); | |
5109 | + break; | |
5110 | + default: | |
5111 | + AuIOErr("Unknown inode type 0%o\n", mode); | |
5112 | + err = -EIO; | |
5113 | + } | |
5114 | + | |
5115 | + mnt_flags = au_mntflags(sb); | |
5116 | + if (!au_opt_test(mnt_flags, UDBA_NONE) | |
5117 | + && !isdir | |
5118 | + && au_opt_test(mnt_flags, XINO) | |
38d290e6 JR |
5119 | + && (h_inode->i_nlink == 1 |
5120 | + || (h_inode->i_state & I_LINKABLE)) | |
1facf9fc | 5121 | + /* todo: unnecessary? */ |
5527c038 | 5122 | + /* && d_inode(cpg->dentry)->i_nlink == 1 */ |
c2b27bf2 AM |
5123 | + && cpg->bdst < cpg->bsrc |
5124 | + && !au_ftest_cpup(cpg->flags, KEEPLINO)) | |
5125 | + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0); | |
1facf9fc | 5126 | + /* ignore this error */ |
5127 | + | |
076b876e AM |
5128 | + if (!err) { |
5129 | + force = 0; | |
5130 | + if (isreg) { | |
5131 | + force = !!cpg->len; | |
5132 | + if (cpg->len == -1) | |
5133 | + force = !!i_size_read(h_inode); | |
5134 | + } | |
5135 | + au_fhsm_wrote(sb, cpg->bdst, force); | |
5136 | + } | |
5137 | + | |
1facf9fc | 5138 | + if (do_dt) |
5139 | + au_dtime_revert(&dt); | |
5140 | + return err; | |
5141 | +} | |
5142 | + | |
392086de | 5143 | +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path) |
86dc4139 AM |
5144 | +{ |
5145 | + int err; | |
392086de | 5146 | + struct dentry *dentry, *h_dentry, *h_parent, *parent; |
86dc4139 | 5147 | + struct inode *h_dir; |
392086de | 5148 | + aufs_bindex_t bdst; |
86dc4139 | 5149 | + |
392086de AM |
5150 | + dentry = cpg->dentry; |
5151 | + bdst = cpg->bdst; | |
5152 | + h_dentry = au_h_dptr(dentry, bdst); | |
5153 | + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) { | |
5154 | + dget(h_dentry); | |
5155 | + au_set_h_dptr(dentry, bdst, NULL); | |
5156 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); | |
5157 | + if (!err) | |
5158 | + h_path->dentry = dget(au_h_dptr(dentry, bdst)); | |
86dc4139 | 5159 | + au_set_h_dptr(dentry, bdst, h_dentry); |
392086de AM |
5160 | + } else { |
5161 | + err = 0; | |
5162 | + parent = dget_parent(dentry); | |
5163 | + h_parent = au_h_dptr(parent, bdst); | |
5164 | + dput(parent); | |
5165 | + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
5166 | + if (IS_ERR(h_path->dentry)) | |
5167 | + err = PTR_ERR(h_path->dentry); | |
86dc4139 | 5168 | + } |
392086de AM |
5169 | + if (unlikely(err)) |
5170 | + goto out; | |
86dc4139 | 5171 | + |
86dc4139 | 5172 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ |
5527c038 | 5173 | + h_dir = d_inode(h_parent); |
86dc4139 | 5174 | + IMustLock(h_dir); |
523b37e3 AM |
5175 | + AuDbg("%pd %pd\n", h_dentry, h_path->dentry); |
5176 | + /* no delegation since it is just created */ | |
5177 | + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL); | |
86dc4139 AM |
5178 | + dput(h_path->dentry); |
5179 | + | |
5180 | +out: | |
5181 | + return err; | |
5182 | +} | |
5183 | + | |
1facf9fc | 5184 | +/* |
5185 | + * copyup the @dentry from @bsrc to @bdst. | |
5186 | + * the caller must set the both of lower dentries. | |
5187 | + * @len is for truncating when it is -1 copyup the entire file. | |
5188 | + * in link/rename cases, @dst_parent may be different from the real one. | |
c2b27bf2 | 5189 | + * basic->bsrc can be larger than basic->bdst. |
1facf9fc | 5190 | + */ |
c2b27bf2 | 5191 | +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5192 | +{ |
5193 | + int err, rerr; | |
5194 | + aufs_bindex_t old_ibstart; | |
5195 | + unsigned char isdir, plink; | |
1facf9fc | 5196 | + struct dentry *h_src, *h_dst, *h_parent; |
5527c038 | 5197 | + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode; |
1facf9fc | 5198 | + struct super_block *sb; |
86dc4139 | 5199 | + struct au_branch *br; |
c2b27bf2 AM |
5200 | + /* to reuduce stack size */ |
5201 | + struct { | |
5202 | + struct au_dtime dt; | |
5203 | + struct path h_path; | |
5204 | + struct au_cpup_reg_attr h_src_attr; | |
5205 | + } *a; | |
1facf9fc | 5206 | + |
c2b27bf2 AM |
5207 | + err = -ENOMEM; |
5208 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
5209 | + if (unlikely(!a)) | |
5210 | + goto out; | |
5211 | + a->h_src_attr.valid = 0; | |
1facf9fc | 5212 | + |
c2b27bf2 AM |
5213 | + sb = cpg->dentry->d_sb; |
5214 | + br = au_sbr(sb, cpg->bdst); | |
5215 | + a->h_path.mnt = au_br_mnt(br); | |
5216 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); | |
1facf9fc | 5217 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5218 | + h_dir = d_inode(h_parent); |
1facf9fc | 5219 | + IMustLock(h_dir); |
5220 | + | |
c2b27bf2 | 5221 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5222 | + inode = d_inode(cpg->dentry); |
1facf9fc | 5223 | + |
5224 | + if (!dst_parent) | |
c2b27bf2 | 5225 | + dst_parent = dget_parent(cpg->dentry); |
1facf9fc | 5226 | + else |
5227 | + dget(dst_parent); | |
5228 | + | |
5229 | + plink = !!au_opt_test(au_mntflags(sb), PLINK); | |
c2b27bf2 | 5230 | + dst_inode = au_h_iptr(inode, cpg->bdst); |
1facf9fc | 5231 | + if (dst_inode) { |
5232 | + if (unlikely(!plink)) { | |
5233 | + err = -EIO; | |
027c5e7a AM |
5234 | + AuIOErr("hi%lu(i%lu) exists on b%d " |
5235 | + "but plink is disabled\n", | |
c2b27bf2 AM |
5236 | + dst_inode->i_ino, inode->i_ino, cpg->bdst); |
5237 | + goto out_parent; | |
1facf9fc | 5238 | + } |
5239 | + | |
5240 | + if (dst_inode->i_nlink) { | |
c2b27bf2 | 5241 | + const int do_dt = au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5242 | + |
c2b27bf2 | 5243 | + h_src = au_plink_lkup(inode, cpg->bdst); |
1facf9fc | 5244 | + err = PTR_ERR(h_src); |
5245 | + if (IS_ERR(h_src)) | |
c2b27bf2 | 5246 | + goto out_parent; |
5527c038 | 5247 | + if (unlikely(d_is_negative(h_src))) { |
1facf9fc | 5248 | + err = -EIO; |
5249 | + AuIOErr("i%lu exists on a upper branch " | |
027c5e7a AM |
5250 | + "but not pseudo-linked\n", |
5251 | + inode->i_ino); | |
1facf9fc | 5252 | + dput(h_src); |
c2b27bf2 | 5253 | + goto out_parent; |
1facf9fc | 5254 | + } |
5255 | + | |
5256 | + if (do_dt) { | |
c2b27bf2 AM |
5257 | + a->h_path.dentry = h_parent; |
5258 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
1facf9fc | 5259 | + } |
86dc4139 | 5260 | + |
c2b27bf2 | 5261 | + a->h_path.dentry = h_dst; |
523b37e3 AM |
5262 | + delegated = NULL; |
5263 | + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated); | |
c2b27bf2 | 5264 | + if (!err && au_ftest_cpup(cpg->flags, RENAME)) |
392086de | 5265 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
1facf9fc | 5266 | + if (do_dt) |
c2b27bf2 | 5267 | + au_dtime_revert(&a->dt); |
523b37e3 AM |
5268 | + if (unlikely(err == -EWOULDBLOCK)) { |
5269 | + pr_warn("cannot retry for NFSv4 delegation" | |
5270 | + " for an internal link\n"); | |
5271 | + iput(delegated); | |
5272 | + } | |
1facf9fc | 5273 | + dput(h_src); |
c2b27bf2 | 5274 | + goto out_parent; |
1facf9fc | 5275 | + } else |
5276 | + /* todo: cpup_wh_file? */ | |
5277 | + /* udba work */ | |
4a4d8108 | 5278 | + au_update_ibrange(inode, /*do_put_zero*/1); |
1facf9fc | 5279 | + } |
5280 | + | |
86dc4139 | 5281 | + isdir = S_ISDIR(inode->i_mode); |
1facf9fc | 5282 | + old_ibstart = au_ibstart(inode); |
c2b27bf2 | 5283 | + err = cpup_entry(cpg, dst_parent, &a->h_src_attr); |
1facf9fc | 5284 | + if (unlikely(err)) |
86dc4139 | 5285 | + goto out_rev; |
5527c038 | 5286 | + dst_inode = d_inode(h_dst); |
1facf9fc | 5287 | + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2); |
86dc4139 | 5288 | + /* todo: necessary? */ |
c2b27bf2 | 5289 | + /* au_pin_hdir_unlock(cpg->pin); */ |
1facf9fc | 5290 | + |
c2b27bf2 | 5291 | + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr); |
86dc4139 AM |
5292 | + if (unlikely(err)) { |
5293 | + /* todo: necessary? */ | |
c2b27bf2 | 5294 | + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */ |
86dc4139 AM |
5295 | + mutex_unlock(&dst_inode->i_mutex); |
5296 | + goto out_rev; | |
5297 | + } | |
5298 | + | |
c2b27bf2 | 5299 | + if (cpg->bdst < old_ibstart) { |
86dc4139 | 5300 | + if (S_ISREG(inode->i_mode)) { |
c2b27bf2 | 5301 | + err = au_dy_iaop(inode, cpg->bdst, dst_inode); |
86dc4139 | 5302 | + if (unlikely(err)) { |
c2b27bf2 AM |
5303 | + /* ignore an error */ |
5304 | + /* au_pin_hdir_relock(cpg->pin); */ | |
86dc4139 AM |
5305 | + mutex_unlock(&dst_inode->i_mutex); |
5306 | + goto out_rev; | |
4a4d8108 | 5307 | + } |
4a4d8108 | 5308 | + } |
c2b27bf2 AM |
5309 | + au_set_ibstart(inode, cpg->bdst); |
5310 | + } else | |
5311 | + au_set_ibend(inode, cpg->bdst); | |
5312 | + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode), | |
86dc4139 AM |
5313 | + au_hi_flags(inode, isdir)); |
5314 | + | |
5315 | + /* todo: necessary? */ | |
c2b27bf2 | 5316 | + /* err = au_pin_hdir_relock(cpg->pin); */ |
86dc4139 AM |
5317 | + mutex_unlock(&dst_inode->i_mutex); |
5318 | + if (unlikely(err)) | |
5319 | + goto out_rev; | |
5320 | + | |
5527c038 | 5321 | + src_inode = d_inode(h_src); |
86dc4139 | 5322 | + if (!isdir |
5527c038 JR |
5323 | + && (src_inode->i_nlink > 1 |
5324 | + || src_inode->i_state & I_LINKABLE) | |
86dc4139 | 5325 | + && plink) |
c2b27bf2 | 5326 | + au_plink_append(inode, cpg->bdst, h_dst); |
86dc4139 | 5327 | + |
c2b27bf2 AM |
5328 | + if (au_ftest_cpup(cpg->flags, RENAME)) { |
5329 | + a->h_path.dentry = h_dst; | |
392086de | 5330 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
86dc4139 AM |
5331 | + } |
5332 | + if (!err) | |
c2b27bf2 | 5333 | + goto out_parent; /* success */ |
1facf9fc | 5334 | + |
5335 | + /* revert */ | |
4a4d8108 | 5336 | +out_rev: |
c2b27bf2 AM |
5337 | + a->h_path.dentry = h_parent; |
5338 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
5339 | + a->h_path.dentry = h_dst; | |
86dc4139 | 5340 | + rerr = 0; |
5527c038 | 5341 | + if (d_is_positive(h_dst)) { |
523b37e3 AM |
5342 | + if (!isdir) { |
5343 | + /* no delegation since it is just created */ | |
5344 | + rerr = vfsub_unlink(h_dir, &a->h_path, | |
5345 | + /*delegated*/NULL, /*force*/0); | |
5346 | + } else | |
c2b27bf2 | 5347 | + rerr = vfsub_rmdir(h_dir, &a->h_path); |
86dc4139 | 5348 | + } |
c2b27bf2 | 5349 | + au_dtime_revert(&a->dt); |
1facf9fc | 5350 | + if (rerr) { |
5351 | + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr); | |
5352 | + err = -EIO; | |
5353 | + } | |
c2b27bf2 | 5354 | +out_parent: |
1facf9fc | 5355 | + dput(dst_parent); |
c2b27bf2 AM |
5356 | + kfree(a); |
5357 | +out: | |
1facf9fc | 5358 | + return err; |
5359 | +} | |
5360 | + | |
7e9cd9fe | 5361 | +#if 0 /* reserved */ |
1facf9fc | 5362 | +struct au_cpup_single_args { |
5363 | + int *errp; | |
c2b27bf2 | 5364 | + struct au_cp_generic *cpg; |
1facf9fc | 5365 | + struct dentry *dst_parent; |
5366 | +}; | |
5367 | + | |
5368 | +static void au_call_cpup_single(void *args) | |
5369 | +{ | |
5370 | + struct au_cpup_single_args *a = args; | |
86dc4139 | 5371 | + |
c2b27bf2 AM |
5372 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5373 | + *a->errp = au_cpup_single(a->cpg, a->dst_parent); | |
5374 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5375 | +} |
c2b27bf2 | 5376 | +#endif |
1facf9fc | 5377 | + |
53392da6 AM |
5378 | +/* |
5379 | + * prevent SIGXFSZ in copy-up. | |
5380 | + * testing CAP_MKNOD is for generic fs, | |
5381 | + * but CAP_FSETID is for xfs only, currently. | |
5382 | + */ | |
86dc4139 | 5383 | +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode) |
53392da6 AM |
5384 | +{ |
5385 | + int do_sio; | |
86dc4139 AM |
5386 | + struct super_block *sb; |
5387 | + struct inode *h_dir; | |
53392da6 AM |
5388 | + |
5389 | + do_sio = 0; | |
86dc4139 | 5390 | + sb = au_pinned_parent(pin)->d_sb; |
53392da6 AM |
5391 | + if (!au_wkq_test() |
5392 | + && (!au_sbi(sb)->si_plink_maint_pid | |
5393 | + || au_plink_maint(sb, AuLock_NOPLM))) { | |
5394 | + switch (mode & S_IFMT) { | |
5395 | + case S_IFREG: | |
5396 | + /* no condition about RLIMIT_FSIZE and the file size */ | |
5397 | + do_sio = 1; | |
5398 | + break; | |
5399 | + case S_IFCHR: | |
5400 | + case S_IFBLK: | |
5401 | + do_sio = !capable(CAP_MKNOD); | |
5402 | + break; | |
5403 | + } | |
5404 | + if (!do_sio) | |
5405 | + do_sio = ((mode & (S_ISUID | S_ISGID)) | |
5406 | + && !capable(CAP_FSETID)); | |
86dc4139 AM |
5407 | + /* this workaround may be removed in the future */ |
5408 | + if (!do_sio) { | |
5409 | + h_dir = au_pinned_h_dir(pin); | |
5410 | + do_sio = h_dir->i_mode & S_ISVTX; | |
5411 | + } | |
53392da6 AM |
5412 | + } |
5413 | + | |
5414 | + return do_sio; | |
5415 | +} | |
5416 | + | |
7e9cd9fe | 5417 | +#if 0 /* reserved */ |
c2b27bf2 | 5418 | +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5419 | +{ |
5420 | + int err, wkq_err; | |
1facf9fc | 5421 | + struct dentry *h_dentry; |
5422 | + | |
c2b27bf2 | 5423 | + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5424 | + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode)) |
c2b27bf2 | 5425 | + err = au_cpup_single(cpg, dst_parent); |
1facf9fc | 5426 | + else { |
5427 | + struct au_cpup_single_args args = { | |
5428 | + .errp = &err, | |
c2b27bf2 AM |
5429 | + .cpg = cpg, |
5430 | + .dst_parent = dst_parent | |
1facf9fc | 5431 | + }; |
5432 | + wkq_err = au_wkq_wait(au_call_cpup_single, &args); | |
5433 | + if (unlikely(wkq_err)) | |
5434 | + err = wkq_err; | |
5435 | + } | |
5436 | + | |
5437 | + return err; | |
5438 | +} | |
c2b27bf2 | 5439 | +#endif |
1facf9fc | 5440 | + |
5441 | +/* | |
5442 | + * copyup the @dentry from the first active lower branch to @bdst, | |
5443 | + * using au_cpup_single(). | |
5444 | + */ | |
c2b27bf2 | 5445 | +static int au_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5446 | +{ |
5447 | + int err; | |
c2b27bf2 AM |
5448 | + unsigned int flags_orig; |
5449 | + struct dentry *dentry; | |
5450 | + | |
5451 | + AuDebugOn(cpg->bsrc < 0); | |
1facf9fc | 5452 | + |
c2b27bf2 | 5453 | + dentry = cpg->dentry; |
86dc4139 | 5454 | + DiMustWriteLock(dentry); |
1facf9fc | 5455 | + |
c2b27bf2 | 5456 | + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1); |
1facf9fc | 5457 | + if (!err) { |
c2b27bf2 AM |
5458 | + flags_orig = cpg->flags; |
5459 | + au_fset_cpup(cpg->flags, RENAME); | |
5460 | + err = au_cpup_single(cpg, NULL); | |
5461 | + cpg->flags = flags_orig; | |
1facf9fc | 5462 | + if (!err) |
5463 | + return 0; /* success */ | |
5464 | + | |
5465 | + /* revert */ | |
c2b27bf2 AM |
5466 | + au_set_h_dptr(dentry, cpg->bdst, NULL); |
5467 | + au_set_dbstart(dentry, cpg->bsrc); | |
1facf9fc | 5468 | + } |
5469 | + | |
5470 | + return err; | |
5471 | +} | |
5472 | + | |
5473 | +struct au_cpup_simple_args { | |
5474 | + int *errp; | |
c2b27bf2 | 5475 | + struct au_cp_generic *cpg; |
1facf9fc | 5476 | +}; |
5477 | + | |
5478 | +static void au_call_cpup_simple(void *args) | |
5479 | +{ | |
5480 | + struct au_cpup_simple_args *a = args; | |
86dc4139 | 5481 | + |
c2b27bf2 AM |
5482 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5483 | + *a->errp = au_cpup_simple(a->cpg); | |
5484 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5485 | +} |
5486 | + | |
c2b27bf2 | 5487 | +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5488 | +{ |
5489 | + int err, wkq_err; | |
c2b27bf2 AM |
5490 | + struct dentry *dentry, *parent; |
5491 | + struct file *h_file; | |
1facf9fc | 5492 | + struct inode *h_dir; |
5493 | + | |
c2b27bf2 AM |
5494 | + dentry = cpg->dentry; |
5495 | + h_file = NULL; | |
5496 | + if (au_ftest_cpup(cpg->flags, HOPEN)) { | |
5497 | + AuDebugOn(cpg->bsrc < 0); | |
392086de | 5498 | + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0); |
c2b27bf2 AM |
5499 | + err = PTR_ERR(h_file); |
5500 | + if (IS_ERR(h_file)) | |
5501 | + goto out; | |
5502 | + } | |
5503 | + | |
1facf9fc | 5504 | + parent = dget_parent(dentry); |
5527c038 | 5505 | + h_dir = au_h_iptr(d_inode(parent), cpg->bdst); |
53392da6 | 5506 | + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE) |
5527c038 | 5507 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 5508 | + err = au_cpup_simple(cpg); |
1facf9fc | 5509 | + else { |
5510 | + struct au_cpup_simple_args args = { | |
5511 | + .errp = &err, | |
c2b27bf2 | 5512 | + .cpg = cpg |
1facf9fc | 5513 | + }; |
5514 | + wkq_err = au_wkq_wait(au_call_cpup_simple, &args); | |
5515 | + if (unlikely(wkq_err)) | |
5516 | + err = wkq_err; | |
5517 | + } | |
5518 | + | |
5519 | + dput(parent); | |
c2b27bf2 AM |
5520 | + if (h_file) |
5521 | + au_h_open_post(dentry, cpg->bsrc, h_file); | |
5522 | + | |
5523 | +out: | |
1facf9fc | 5524 | + return err; |
5525 | +} | |
5526 | + | |
c2b27bf2 | 5527 | +int au_sio_cpup_simple(struct au_cp_generic *cpg) |
367653fa | 5528 | +{ |
c2b27bf2 AM |
5529 | + aufs_bindex_t bsrc, bend; |
5530 | + struct dentry *dentry, *h_dentry; | |
367653fa | 5531 | + |
c2b27bf2 AM |
5532 | + if (cpg->bsrc < 0) { |
5533 | + dentry = cpg->dentry; | |
5534 | + bend = au_dbend(dentry); | |
5535 | + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) { | |
5536 | + h_dentry = au_h_dptr(dentry, bsrc); | |
5537 | + if (h_dentry) { | |
5527c038 | 5538 | + AuDebugOn(d_is_negative(h_dentry)); |
c2b27bf2 AM |
5539 | + break; |
5540 | + } | |
5541 | + } | |
5542 | + AuDebugOn(bsrc > bend); | |
5543 | + cpg->bsrc = bsrc; | |
367653fa | 5544 | + } |
c2b27bf2 AM |
5545 | + AuDebugOn(cpg->bsrc <= cpg->bdst); |
5546 | + return au_do_sio_cpup_simple(cpg); | |
5547 | +} | |
367653fa | 5548 | + |
c2b27bf2 AM |
5549 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg) |
5550 | +{ | |
5551 | + AuDebugOn(cpg->bdst <= cpg->bsrc); | |
5552 | + return au_do_sio_cpup_simple(cpg); | |
367653fa AM |
5553 | +} |
5554 | + | |
1facf9fc | 5555 | +/* ---------------------------------------------------------------------- */ |
5556 | + | |
5557 | +/* | |
5558 | + * copyup the deleted file for writing. | |
5559 | + */ | |
c2b27bf2 AM |
5560 | +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry, |
5561 | + struct file *file) | |
1facf9fc | 5562 | +{ |
5563 | + int err; | |
c2b27bf2 AM |
5564 | + unsigned int flags_orig; |
5565 | + aufs_bindex_t bsrc_orig; | |
1facf9fc | 5566 | + struct dentry *h_d_dst, *h_d_start; |
c2b27bf2 | 5567 | + struct au_dinfo *dinfo; |
4a4d8108 | 5568 | + struct au_hdentry *hdp; |
1facf9fc | 5569 | + |
c2b27bf2 | 5570 | + dinfo = au_di(cpg->dentry); |
1308ab2a | 5571 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
5572 | + | |
c2b27bf2 AM |
5573 | + bsrc_orig = cpg->bsrc; |
5574 | + cpg->bsrc = dinfo->di_bstart; | |
4a4d8108 | 5575 | + hdp = dinfo->di_hdentry; |
c2b27bf2 AM |
5576 | + h_d_dst = hdp[0 + cpg->bdst].hd_dentry; |
5577 | + dinfo->di_bstart = cpg->bdst; | |
5578 | + hdp[0 + cpg->bdst].hd_dentry = wh_dentry; | |
86dc4139 | 5579 | + h_d_start = NULL; |
027c5e7a | 5580 | + if (file) { |
c2b27bf2 | 5581 | + h_d_start = hdp[0 + cpg->bsrc].hd_dentry; |
2000de60 | 5582 | + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry; |
027c5e7a | 5583 | + } |
c2b27bf2 AM |
5584 | + flags_orig = cpg->flags; |
5585 | + cpg->flags = !AuCpup_DTIME; | |
5586 | + err = au_cpup_single(cpg, /*h_parent*/NULL); | |
5587 | + cpg->flags = flags_orig; | |
027c5e7a AM |
5588 | + if (file) { |
5589 | + if (!err) | |
5590 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 5591 | + hdp[0 + cpg->bsrc].hd_dentry = h_d_start; |
1facf9fc | 5592 | + } |
c2b27bf2 AM |
5593 | + hdp[0 + cpg->bdst].hd_dentry = h_d_dst; |
5594 | + dinfo->di_bstart = cpg->bsrc; | |
5595 | + cpg->bsrc = bsrc_orig; | |
1facf9fc | 5596 | + |
5597 | + return err; | |
5598 | +} | |
5599 | + | |
c2b27bf2 | 5600 | +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5601 | +{ |
5602 | + int err; | |
c2b27bf2 | 5603 | + aufs_bindex_t bdst; |
1facf9fc | 5604 | + struct au_dtime dt; |
c2b27bf2 | 5605 | + struct dentry *dentry, *parent, *h_parent, *wh_dentry; |
1facf9fc | 5606 | + struct au_branch *br; |
5607 | + struct path h_path; | |
5608 | + | |
c2b27bf2 AM |
5609 | + dentry = cpg->dentry; |
5610 | + bdst = cpg->bdst; | |
1facf9fc | 5611 | + br = au_sbr(dentry->d_sb, bdst); |
5612 | + parent = dget_parent(dentry); | |
5613 | + h_parent = au_h_dptr(parent, bdst); | |
5614 | + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
5615 | + err = PTR_ERR(wh_dentry); | |
5616 | + if (IS_ERR(wh_dentry)) | |
5617 | + goto out; | |
5618 | + | |
5619 | + h_path.dentry = h_parent; | |
86dc4139 | 5620 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 5621 | + au_dtime_store(&dt, parent, &h_path); |
c2b27bf2 | 5622 | + err = au_do_cpup_wh(cpg, wh_dentry, file); |
1facf9fc | 5623 | + if (unlikely(err)) |
5624 | + goto out_wh; | |
5625 | + | |
5626 | + dget(wh_dentry); | |
5627 | + h_path.dentry = wh_dentry; | |
2000de60 | 5628 | + if (!d_is_dir(wh_dentry)) { |
523b37e3 | 5629 | + /* no delegation since it is just created */ |
5527c038 | 5630 | + err = vfsub_unlink(d_inode(h_parent), &h_path, |
523b37e3 AM |
5631 | + /*delegated*/NULL, /*force*/0); |
5632 | + } else | |
5527c038 | 5633 | + err = vfsub_rmdir(d_inode(h_parent), &h_path); |
1facf9fc | 5634 | + if (unlikely(err)) { |
523b37e3 AM |
5635 | + AuIOErr("failed remove copied-up tmp file %pd(%d)\n", |
5636 | + wh_dentry, err); | |
1facf9fc | 5637 | + err = -EIO; |
5638 | + } | |
5639 | + au_dtime_revert(&dt); | |
5527c038 | 5640 | + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry); |
1facf9fc | 5641 | + |
4f0767ce | 5642 | +out_wh: |
1facf9fc | 5643 | + dput(wh_dentry); |
4f0767ce | 5644 | +out: |
1facf9fc | 5645 | + dput(parent); |
5646 | + return err; | |
5647 | +} | |
5648 | + | |
5649 | +struct au_cpup_wh_args { | |
5650 | + int *errp; | |
c2b27bf2 | 5651 | + struct au_cp_generic *cpg; |
1facf9fc | 5652 | + struct file *file; |
5653 | +}; | |
5654 | + | |
5655 | +static void au_call_cpup_wh(void *args) | |
5656 | +{ | |
5657 | + struct au_cpup_wh_args *a = args; | |
86dc4139 | 5658 | + |
c2b27bf2 AM |
5659 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5660 | + *a->errp = au_cpup_wh(a->cpg, a->file); | |
5661 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5662 | +} |
5663 | + | |
c2b27bf2 | 5664 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5665 | +{ |
5666 | + int err, wkq_err; | |
c2b27bf2 | 5667 | + aufs_bindex_t bdst; |
c1595e42 | 5668 | + struct dentry *dentry, *parent, *h_orph, *h_parent; |
86dc4139 | 5669 | + struct inode *dir, *h_dir, *h_tmpdir; |
1facf9fc | 5670 | + struct au_wbr *wbr; |
c2b27bf2 | 5671 | + struct au_pin wh_pin, *pin_orig; |
1facf9fc | 5672 | + |
c2b27bf2 AM |
5673 | + dentry = cpg->dentry; |
5674 | + bdst = cpg->bdst; | |
1facf9fc | 5675 | + parent = dget_parent(dentry); |
5527c038 | 5676 | + dir = d_inode(parent); |
1facf9fc | 5677 | + h_orph = NULL; |
5678 | + h_parent = NULL; | |
5679 | + h_dir = au_igrab(au_h_iptr(dir, bdst)); | |
5680 | + h_tmpdir = h_dir; | |
c2b27bf2 | 5681 | + pin_orig = NULL; |
1facf9fc | 5682 | + if (!h_dir->i_nlink) { |
5683 | + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr; | |
5684 | + h_orph = wbr->wbr_orph; | |
5685 | + | |
5686 | + h_parent = dget(au_h_dptr(parent, bdst)); | |
1facf9fc | 5687 | + au_set_h_dptr(parent, bdst, dget(h_orph)); |
5527c038 | 5688 | + h_tmpdir = d_inode(h_orph); |
1facf9fc | 5689 | + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0); |
5690 | + | |
dece6358 | 5691 | + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3); |
4a4d8108 | 5692 | + /* todo: au_h_open_pre()? */ |
86dc4139 | 5693 | + |
c2b27bf2 | 5694 | + pin_orig = cpg->pin; |
86dc4139 | 5695 | + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT, |
c2b27bf2 AM |
5696 | + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED); |
5697 | + cpg->pin = &wh_pin; | |
1facf9fc | 5698 | + } |
5699 | + | |
53392da6 | 5700 | + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE) |
5527c038 | 5701 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 5702 | + err = au_cpup_wh(cpg, file); |
1facf9fc | 5703 | + else { |
5704 | + struct au_cpup_wh_args args = { | |
5705 | + .errp = &err, | |
c2b27bf2 AM |
5706 | + .cpg = cpg, |
5707 | + .file = file | |
1facf9fc | 5708 | + }; |
5709 | + wkq_err = au_wkq_wait(au_call_cpup_wh, &args); | |
5710 | + if (unlikely(wkq_err)) | |
5711 | + err = wkq_err; | |
5712 | + } | |
5713 | + | |
5714 | + if (h_orph) { | |
5715 | + mutex_unlock(&h_tmpdir->i_mutex); | |
4a4d8108 | 5716 | + /* todo: au_h_open_post()? */ |
1facf9fc | 5717 | + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0); |
1facf9fc | 5718 | + au_set_h_dptr(parent, bdst, h_parent); |
c2b27bf2 AM |
5719 | + AuDebugOn(!pin_orig); |
5720 | + cpg->pin = pin_orig; | |
1facf9fc | 5721 | + } |
5722 | + iput(h_dir); | |
5723 | + dput(parent); | |
5724 | + | |
5725 | + return err; | |
5726 | +} | |
5727 | + | |
5728 | +/* ---------------------------------------------------------------------- */ | |
5729 | + | |
5730 | +/* | |
5731 | + * generic routine for both of copy-up and copy-down. | |
5732 | + */ | |
5733 | +/* cf. revalidate function in file.c */ | |
5734 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
5735 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5736 | + struct au_pin *pin, |
1facf9fc | 5737 | + struct dentry *h_parent, void *arg), |
5738 | + void *arg) | |
5739 | +{ | |
5740 | + int err; | |
5741 | + struct au_pin pin; | |
5527c038 | 5742 | + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry; |
1facf9fc | 5743 | + |
5744 | + err = 0; | |
5745 | + parent = dget_parent(dentry); | |
5746 | + if (IS_ROOT(parent)) | |
5747 | + goto out; | |
5748 | + | |
5749 | + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2, | |
5750 | + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE); | |
5751 | + | |
5752 | + /* do not use au_dpage */ | |
5753 | + real_parent = parent; | |
5754 | + while (1) { | |
5755 | + dput(parent); | |
5756 | + parent = dget_parent(dentry); | |
5757 | + h_parent = au_h_dptr(parent, bdst); | |
5758 | + if (h_parent) | |
5759 | + goto out; /* success */ | |
5760 | + | |
5761 | + /* find top dir which is necessary to cpup */ | |
5762 | + do { | |
5763 | + d = parent; | |
5764 | + dput(parent); | |
5765 | + parent = dget_parent(d); | |
5766 | + di_read_lock_parent3(parent, !AuLock_IR); | |
5767 | + h_parent = au_h_dptr(parent, bdst); | |
5768 | + di_read_unlock(parent, !AuLock_IR); | |
5769 | + } while (!h_parent); | |
5770 | + | |
5771 | + if (d != real_parent) | |
5772 | + di_write_lock_child3(d); | |
5773 | + | |
5774 | + /* somebody else might create while we were sleeping */ | |
5527c038 JR |
5775 | + h_dentry = au_h_dptr(d, bdst); |
5776 | + if (!h_dentry || d_is_negative(h_dentry)) { | |
5777 | + if (h_dentry) | |
1facf9fc | 5778 | + au_update_dbstart(d); |
5779 | + | |
5780 | + au_pin_set_dentry(&pin, d); | |
5781 | + err = au_do_pin(&pin); | |
5782 | + if (!err) { | |
86dc4139 | 5783 | + err = cp(d, bdst, &pin, h_parent, arg); |
1facf9fc | 5784 | + au_unpin(&pin); |
5785 | + } | |
5786 | + } | |
5787 | + | |
5788 | + if (d != real_parent) | |
5789 | + di_write_unlock(d); | |
5790 | + if (unlikely(err)) | |
5791 | + break; | |
5792 | + } | |
5793 | + | |
4f0767ce | 5794 | +out: |
1facf9fc | 5795 | + dput(parent); |
5796 | + return err; | |
5797 | +} | |
5798 | + | |
5799 | +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5800 | + struct au_pin *pin, |
2000de60 | 5801 | + struct dentry *h_parent __maybe_unused, |
1facf9fc | 5802 | + void *arg __maybe_unused) |
5803 | +{ | |
c2b27bf2 AM |
5804 | + struct au_cp_generic cpg = { |
5805 | + .dentry = dentry, | |
5806 | + .bdst = bdst, | |
5807 | + .bsrc = -1, | |
5808 | + .len = 0, | |
5809 | + .pin = pin, | |
5810 | + .flags = AuCpup_DTIME | |
5811 | + }; | |
5812 | + return au_sio_cpup_simple(&cpg); | |
1facf9fc | 5813 | +} |
5814 | + | |
5815 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
5816 | +{ | |
5817 | + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL); | |
5818 | +} | |
5819 | + | |
5820 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
5821 | +{ | |
5822 | + int err; | |
5823 | + struct dentry *parent; | |
5824 | + struct inode *dir; | |
5825 | + | |
5826 | + parent = dget_parent(dentry); | |
5527c038 | 5827 | + dir = d_inode(parent); |
1facf9fc | 5828 | + err = 0; |
5829 | + if (au_h_iptr(dir, bdst)) | |
5830 | + goto out; | |
5831 | + | |
5832 | + di_read_unlock(parent, AuLock_IR); | |
5833 | + di_write_lock_parent(parent); | |
5834 | + /* someone else might change our inode while we were sleeping */ | |
5835 | + if (!au_h_iptr(dir, bdst)) | |
5836 | + err = au_cpup_dirs(dentry, bdst); | |
5837 | + di_downgrade_lock(parent, AuLock_IR); | |
5838 | + | |
4f0767ce | 5839 | +out: |
1facf9fc | 5840 | + dput(parent); |
5841 | + return err; | |
5842 | +} | |
7f207e10 AM |
5843 | diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h |
5844 | --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 5845 | +++ linux/fs/aufs/cpup.h 2015-06-28 17:35:44.348050491 +0200 |
523b37e3 | 5846 | @@ -0,0 +1,94 @@ |
1facf9fc | 5847 | +/* |
2000de60 | 5848 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 5849 | + * |
5850 | + * This program, aufs is free software; you can redistribute it and/or modify | |
5851 | + * it under the terms of the GNU General Public License as published by | |
5852 | + * the Free Software Foundation; either version 2 of the License, or | |
5853 | + * (at your option) any later version. | |
dece6358 AM |
5854 | + * |
5855 | + * This program is distributed in the hope that it will be useful, | |
5856 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5857 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
5858 | + * GNU General Public License for more details. | |
5859 | + * | |
5860 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 5861 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 5862 | + */ |
5863 | + | |
5864 | +/* | |
5865 | + * copy-up/down functions | |
5866 | + */ | |
5867 | + | |
5868 | +#ifndef __AUFS_CPUP_H__ | |
5869 | +#define __AUFS_CPUP_H__ | |
5870 | + | |
5871 | +#ifdef __KERNEL__ | |
5872 | + | |
dece6358 | 5873 | +#include <linux/path.h> |
1facf9fc | 5874 | + |
dece6358 AM |
5875 | +struct inode; |
5876 | +struct file; | |
86dc4139 | 5877 | +struct au_pin; |
dece6358 | 5878 | + |
86dc4139 | 5879 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags); |
1facf9fc | 5880 | +void au_cpup_attr_timesizes(struct inode *inode); |
5881 | +void au_cpup_attr_nlink(struct inode *inode, int force); | |
5882 | +void au_cpup_attr_changeable(struct inode *inode); | |
5883 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode); | |
5884 | +void au_cpup_attr_all(struct inode *inode, int force); | |
5885 | + | |
5886 | +/* ---------------------------------------------------------------------- */ | |
5887 | + | |
c2b27bf2 AM |
5888 | +struct au_cp_generic { |
5889 | + struct dentry *dentry; | |
5890 | + aufs_bindex_t bdst, bsrc; | |
5891 | + loff_t len; | |
5892 | + struct au_pin *pin; | |
5893 | + unsigned int flags; | |
5894 | +}; | |
5895 | + | |
1facf9fc | 5896 | +/* cpup flags */ |
392086de AM |
5897 | +#define AuCpup_DTIME 1 /* do dtime_store/revert */ |
5898 | +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino, | |
5899 | + for link(2) */ | |
5900 | +#define AuCpup_RENAME (1 << 2) /* rename after cpup */ | |
5901 | +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in | |
5902 | + cpup */ | |
5903 | +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the | |
5904 | + existing entry */ | |
5905 | +#define AuCpup_RWDST (1 << 5) /* force write target even if | |
5906 | + the branch is marked as RO */ | |
c2b27bf2 | 5907 | + |
1facf9fc | 5908 | +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name) |
7f207e10 AM |
5909 | +#define au_fset_cpup(flags, name) \ |
5910 | + do { (flags) |= AuCpup_##name; } while (0) | |
5911 | +#define au_fclr_cpup(flags, name) \ | |
5912 | + do { (flags) &= ~AuCpup_##name; } while (0) | |
1facf9fc | 5913 | + |
5914 | +int au_copy_file(struct file *dst, struct file *src, loff_t len); | |
c2b27bf2 AM |
5915 | +int au_sio_cpup_simple(struct au_cp_generic *cpg); |
5916 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg); | |
5917 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file); | |
1facf9fc | 5918 | + |
5919 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
5920 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5921 | + struct au_pin *pin, |
1facf9fc | 5922 | + struct dentry *h_parent, void *arg), |
5923 | + void *arg); | |
5924 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
5925 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
5926 | + | |
5927 | +/* ---------------------------------------------------------------------- */ | |
5928 | + | |
5929 | +/* keep timestamps when copyup */ | |
5930 | +struct au_dtime { | |
5931 | + struct dentry *dt_dentry; | |
5932 | + struct path dt_h_path; | |
5933 | + struct timespec dt_atime, dt_mtime; | |
5934 | +}; | |
5935 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
5936 | + struct path *h_path); | |
5937 | +void au_dtime_revert(struct au_dtime *dt); | |
5938 | + | |
5939 | +#endif /* __KERNEL__ */ | |
5940 | +#endif /* __AUFS_CPUP_H__ */ | |
7f207e10 AM |
5941 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c |
5942 | --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 5943 | +++ linux/fs/aufs/dbgaufs.c 2015-06-28 17:35:44.348050491 +0200 |
523b37e3 | 5944 | @@ -0,0 +1,432 @@ |
1facf9fc | 5945 | +/* |
2000de60 | 5946 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 5947 | + * |
5948 | + * This program, aufs is free software; you can redistribute it and/or modify | |
5949 | + * it under the terms of the GNU General Public License as published by | |
5950 | + * the Free Software Foundation; either version 2 of the License, or | |
5951 | + * (at your option) any later version. | |
dece6358 AM |
5952 | + * |
5953 | + * This program is distributed in the hope that it will be useful, | |
5954 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5955 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
5956 | + * GNU General Public License for more details. | |
5957 | + * | |
5958 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 5959 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 5960 | + */ |
5961 | + | |
5962 | +/* | |
5963 | + * debugfs interface | |
5964 | + */ | |
5965 | + | |
5966 | +#include <linux/debugfs.h> | |
5967 | +#include "aufs.h" | |
5968 | + | |
5969 | +#ifndef CONFIG_SYSFS | |
5970 | +#error DEBUG_FS depends upon SYSFS | |
5971 | +#endif | |
5972 | + | |
5973 | +static struct dentry *dbgaufs; | |
5974 | +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH; | |
5975 | + | |
5976 | +/* 20 is max digits length of ulong 64 */ | |
5977 | +struct dbgaufs_arg { | |
5978 | + int n; | |
5979 | + char a[20 * 4]; | |
5980 | +}; | |
5981 | + | |
5982 | +/* | |
5983 | + * common function for all XINO files | |
5984 | + */ | |
5985 | +static int dbgaufs_xi_release(struct inode *inode __maybe_unused, | |
5986 | + struct file *file) | |
5987 | +{ | |
5988 | + kfree(file->private_data); | |
5989 | + return 0; | |
5990 | +} | |
5991 | + | |
5992 | +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt) | |
5993 | +{ | |
5994 | + int err; | |
5995 | + struct kstat st; | |
5996 | + struct dbgaufs_arg *p; | |
5997 | + | |
5998 | + err = -ENOMEM; | |
5999 | + p = kmalloc(sizeof(*p), GFP_NOFS); | |
6000 | + if (unlikely(!p)) | |
6001 | + goto out; | |
6002 | + | |
6003 | + err = 0; | |
6004 | + p->n = 0; | |
6005 | + file->private_data = p; | |
6006 | + if (!xf) | |
6007 | + goto out; | |
6008 | + | |
c06a8ce3 | 6009 | + err = vfs_getattr(&xf->f_path, &st); |
1facf9fc | 6010 | + if (!err) { |
6011 | + if (do_fcnt) | |
6012 | + p->n = snprintf | |
6013 | + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n", | |
6014 | + (long)file_count(xf), st.blocks, st.blksize, | |
6015 | + (long long)st.size); | |
6016 | + else | |
6017 | + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n", | |
6018 | + st.blocks, st.blksize, | |
6019 | + (long long)st.size); | |
6020 | + AuDebugOn(p->n >= sizeof(p->a)); | |
6021 | + } else { | |
6022 | + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err); | |
6023 | + err = 0; | |
6024 | + } | |
6025 | + | |
4f0767ce | 6026 | +out: |
1facf9fc | 6027 | + return err; |
6028 | + | |
6029 | +} | |
6030 | + | |
6031 | +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf, | |
6032 | + size_t count, loff_t *ppos) | |
6033 | +{ | |
6034 | + struct dbgaufs_arg *p; | |
6035 | + | |
6036 | + p = file->private_data; | |
6037 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6038 | +} | |
6039 | + | |
6040 | +/* ---------------------------------------------------------------------- */ | |
6041 | + | |
86dc4139 AM |
6042 | +struct dbgaufs_plink_arg { |
6043 | + int n; | |
6044 | + char a[]; | |
6045 | +}; | |
6046 | + | |
6047 | +static int dbgaufs_plink_release(struct inode *inode __maybe_unused, | |
6048 | + struct file *file) | |
6049 | +{ | |
6050 | + free_page((unsigned long)file->private_data); | |
6051 | + return 0; | |
6052 | +} | |
6053 | + | |
6054 | +static int dbgaufs_plink_open(struct inode *inode, struct file *file) | |
6055 | +{ | |
6056 | + int err, i, limit; | |
6057 | + unsigned long n, sum; | |
6058 | + struct dbgaufs_plink_arg *p; | |
6059 | + struct au_sbinfo *sbinfo; | |
6060 | + struct super_block *sb; | |
6061 | + struct au_sphlhead *sphl; | |
6062 | + | |
6063 | + err = -ENOMEM; | |
6064 | + p = (void *)get_zeroed_page(GFP_NOFS); | |
6065 | + if (unlikely(!p)) | |
6066 | + goto out; | |
6067 | + | |
6068 | + err = -EFBIG; | |
6069 | + sbinfo = inode->i_private; | |
6070 | + sb = sbinfo->si_sb; | |
6071 | + si_noflush_read_lock(sb); | |
6072 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
6073 | + limit = PAGE_SIZE - sizeof(p->n); | |
6074 | + | |
6075 | + /* the number of buckets */ | |
6076 | + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH); | |
6077 | + p->n += n; | |
6078 | + limit -= n; | |
6079 | + | |
6080 | + sum = 0; | |
6081 | + for (i = 0, sphl = sbinfo->si_plink; | |
6082 | + i < AuPlink_NHASH; | |
6083 | + i++, sphl++) { | |
6084 | + n = au_sphl_count(sphl); | |
6085 | + sum += n; | |
6086 | + | |
6087 | + n = snprintf(p->a + p->n, limit, "%lu ", n); | |
6088 | + p->n += n; | |
6089 | + limit -= n; | |
6090 | + if (unlikely(limit <= 0)) | |
6091 | + goto out_free; | |
6092 | + } | |
6093 | + p->a[p->n - 1] = '\n'; | |
6094 | + | |
6095 | + /* the sum of plinks */ | |
6096 | + n = snprintf(p->a + p->n, limit, "%lu\n", sum); | |
6097 | + p->n += n; | |
6098 | + limit -= n; | |
6099 | + if (unlikely(limit <= 0)) | |
6100 | + goto out_free; | |
6101 | + } else { | |
6102 | +#define str "1\n0\n0\n" | |
6103 | + p->n = sizeof(str) - 1; | |
6104 | + strcpy(p->a, str); | |
6105 | +#undef str | |
6106 | + } | |
6107 | + si_read_unlock(sb); | |
6108 | + | |
6109 | + err = 0; | |
6110 | + file->private_data = p; | |
6111 | + goto out; /* success */ | |
6112 | + | |
6113 | +out_free: | |
6114 | + free_page((unsigned long)p); | |
6115 | +out: | |
6116 | + return err; | |
6117 | +} | |
6118 | + | |
6119 | +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf, | |
6120 | + size_t count, loff_t *ppos) | |
6121 | +{ | |
6122 | + struct dbgaufs_plink_arg *p; | |
6123 | + | |
6124 | + p = file->private_data; | |
6125 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6126 | +} | |
6127 | + | |
6128 | +static const struct file_operations dbgaufs_plink_fop = { | |
6129 | + .owner = THIS_MODULE, | |
6130 | + .open = dbgaufs_plink_open, | |
6131 | + .release = dbgaufs_plink_release, | |
6132 | + .read = dbgaufs_plink_read | |
6133 | +}; | |
6134 | + | |
6135 | +/* ---------------------------------------------------------------------- */ | |
6136 | + | |
1facf9fc | 6137 | +static int dbgaufs_xib_open(struct inode *inode, struct file *file) |
6138 | +{ | |
6139 | + int err; | |
6140 | + struct au_sbinfo *sbinfo; | |
6141 | + struct super_block *sb; | |
6142 | + | |
6143 | + sbinfo = inode->i_private; | |
6144 | + sb = sbinfo->si_sb; | |
6145 | + si_noflush_read_lock(sb); | |
6146 | + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0); | |
6147 | + si_read_unlock(sb); | |
6148 | + return err; | |
6149 | +} | |
6150 | + | |
6151 | +static const struct file_operations dbgaufs_xib_fop = { | |
4a4d8108 | 6152 | + .owner = THIS_MODULE, |
1facf9fc | 6153 | + .open = dbgaufs_xib_open, |
6154 | + .release = dbgaufs_xi_release, | |
6155 | + .read = dbgaufs_xi_read | |
6156 | +}; | |
6157 | + | |
6158 | +/* ---------------------------------------------------------------------- */ | |
6159 | + | |
6160 | +#define DbgaufsXi_PREFIX "xi" | |
6161 | + | |
6162 | +static int dbgaufs_xino_open(struct inode *inode, struct file *file) | |
6163 | +{ | |
6164 | + int err; | |
6165 | + long l; | |
6166 | + struct au_sbinfo *sbinfo; | |
6167 | + struct super_block *sb; | |
6168 | + struct file *xf; | |
6169 | + struct qstr *name; | |
6170 | + | |
6171 | + err = -ENOENT; | |
6172 | + xf = NULL; | |
2000de60 | 6173 | + name = &file->f_path.dentry->d_name; |
1facf9fc | 6174 | + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX) |
6175 | + || memcmp(name->name, DbgaufsXi_PREFIX, | |
6176 | + sizeof(DbgaufsXi_PREFIX) - 1))) | |
6177 | + goto out; | |
9dbd164d | 6178 | + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l); |
1facf9fc | 6179 | + if (unlikely(err)) |
6180 | + goto out; | |
6181 | + | |
6182 | + sbinfo = inode->i_private; | |
6183 | + sb = sbinfo->si_sb; | |
6184 | + si_noflush_read_lock(sb); | |
6185 | + if (l <= au_sbend(sb)) { | |
6186 | + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file; | |
6187 | + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1); | |
6188 | + } else | |
6189 | + err = -ENOENT; | |
6190 | + si_read_unlock(sb); | |
6191 | + | |
4f0767ce | 6192 | +out: |
1facf9fc | 6193 | + return err; |
6194 | +} | |
6195 | + | |
6196 | +static const struct file_operations dbgaufs_xino_fop = { | |
4a4d8108 | 6197 | + .owner = THIS_MODULE, |
1facf9fc | 6198 | + .open = dbgaufs_xino_open, |
6199 | + .release = dbgaufs_xi_release, | |
6200 | + .read = dbgaufs_xi_read | |
6201 | +}; | |
6202 | + | |
6203 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
6204 | +{ | |
6205 | + aufs_bindex_t bend; | |
6206 | + struct au_branch *br; | |
6207 | + struct au_xino_file *xi; | |
6208 | + | |
6209 | + if (!au_sbi(sb)->si_dbgaufs) | |
6210 | + return; | |
6211 | + | |
6212 | + bend = au_sbend(sb); | |
6213 | + for (; bindex <= bend; bindex++) { | |
6214 | + br = au_sbr(sb, bindex); | |
6215 | + xi = &br->br_xino; | |
c06a8ce3 AM |
6216 | + debugfs_remove(xi->xi_dbgaufs); |
6217 | + xi->xi_dbgaufs = NULL; | |
1facf9fc | 6218 | + } |
6219 | +} | |
6220 | + | |
6221 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
6222 | +{ | |
6223 | + struct au_sbinfo *sbinfo; | |
6224 | + struct dentry *parent; | |
6225 | + struct au_branch *br; | |
6226 | + struct au_xino_file *xi; | |
6227 | + aufs_bindex_t bend; | |
6228 | + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */ | |
6229 | + | |
6230 | + sbinfo = au_sbi(sb); | |
6231 | + parent = sbinfo->si_dbgaufs; | |
6232 | + if (!parent) | |
6233 | + return; | |
6234 | + | |
6235 | + bend = au_sbend(sb); | |
6236 | + for (; bindex <= bend; bindex++) { | |
6237 | + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex); | |
6238 | + br = au_sbr(sb, bindex); | |
6239 | + xi = &br->br_xino; | |
6240 | + AuDebugOn(xi->xi_dbgaufs); | |
6241 | + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent, | |
6242 | + sbinfo, &dbgaufs_xino_fop); | |
6243 | + /* ignore an error */ | |
6244 | + if (unlikely(!xi->xi_dbgaufs)) | |
6245 | + AuWarn1("failed %s under debugfs\n", name); | |
6246 | + } | |
6247 | +} | |
6248 | + | |
6249 | +/* ---------------------------------------------------------------------- */ | |
6250 | + | |
6251 | +#ifdef CONFIG_AUFS_EXPORT | |
6252 | +static int dbgaufs_xigen_open(struct inode *inode, struct file *file) | |
6253 | +{ | |
6254 | + int err; | |
6255 | + struct au_sbinfo *sbinfo; | |
6256 | + struct super_block *sb; | |
6257 | + | |
6258 | + sbinfo = inode->i_private; | |
6259 | + sb = sbinfo->si_sb; | |
6260 | + si_noflush_read_lock(sb); | |
6261 | + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0); | |
6262 | + si_read_unlock(sb); | |
6263 | + return err; | |
6264 | +} | |
6265 | + | |
6266 | +static const struct file_operations dbgaufs_xigen_fop = { | |
4a4d8108 | 6267 | + .owner = THIS_MODULE, |
1facf9fc | 6268 | + .open = dbgaufs_xigen_open, |
6269 | + .release = dbgaufs_xi_release, | |
6270 | + .read = dbgaufs_xi_read | |
6271 | +}; | |
6272 | + | |
6273 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6274 | +{ | |
6275 | + int err; | |
6276 | + | |
dece6358 | 6277 | + /* |
c1595e42 | 6278 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6279 | + * so the tiny check for si_rwsem is unnecessary. |
6280 | + */ | |
6281 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6282 | + | |
1facf9fc | 6283 | + err = -EIO; |
6284 | + sbinfo->si_dbgaufs_xigen = debugfs_create_file | |
6285 | + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6286 | + &dbgaufs_xigen_fop); | |
6287 | + if (sbinfo->si_dbgaufs_xigen) | |
6288 | + err = 0; | |
6289 | + | |
6290 | + return err; | |
6291 | +} | |
6292 | +#else | |
6293 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6294 | +{ | |
6295 | + return 0; | |
6296 | +} | |
6297 | +#endif /* CONFIG_AUFS_EXPORT */ | |
6298 | + | |
6299 | +/* ---------------------------------------------------------------------- */ | |
6300 | + | |
6301 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo) | |
6302 | +{ | |
dece6358 | 6303 | + /* |
7e9cd9fe | 6304 | + * This function is a dynamic '__fin' function actually, |
dece6358 AM |
6305 | + * so the tiny check for si_rwsem is unnecessary. |
6306 | + */ | |
6307 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6308 | + | |
1facf9fc | 6309 | + debugfs_remove_recursive(sbinfo->si_dbgaufs); |
6310 | + sbinfo->si_dbgaufs = NULL; | |
6311 | + kobject_put(&sbinfo->si_kobj); | |
6312 | +} | |
6313 | + | |
6314 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo) | |
6315 | +{ | |
6316 | + int err; | |
6317 | + char name[SysaufsSiNameLen]; | |
6318 | + | |
dece6358 | 6319 | + /* |
c1595e42 | 6320 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6321 | + * so the tiny check for si_rwsem is unnecessary. |
6322 | + */ | |
6323 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6324 | + | |
1facf9fc | 6325 | + err = -ENOENT; |
6326 | + if (!dbgaufs) { | |
6327 | + AuErr1("/debug/aufs is uninitialized\n"); | |
6328 | + goto out; | |
6329 | + } | |
6330 | + | |
6331 | + err = -EIO; | |
6332 | + sysaufs_name(sbinfo, name); | |
6333 | + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs); | |
6334 | + if (unlikely(!sbinfo->si_dbgaufs)) | |
6335 | + goto out; | |
6336 | + kobject_get(&sbinfo->si_kobj); | |
6337 | + | |
6338 | + sbinfo->si_dbgaufs_xib = debugfs_create_file | |
6339 | + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6340 | + &dbgaufs_xib_fop); | |
6341 | + if (unlikely(!sbinfo->si_dbgaufs_xib)) | |
6342 | + goto out_dir; | |
6343 | + | |
86dc4139 AM |
6344 | + sbinfo->si_dbgaufs_plink = debugfs_create_file |
6345 | + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6346 | + &dbgaufs_plink_fop); | |
6347 | + if (unlikely(!sbinfo->si_dbgaufs_plink)) | |
6348 | + goto out_dir; | |
6349 | + | |
1facf9fc | 6350 | + err = dbgaufs_xigen_init(sbinfo); |
6351 | + if (!err) | |
6352 | + goto out; /* success */ | |
6353 | + | |
4f0767ce | 6354 | +out_dir: |
1facf9fc | 6355 | + dbgaufs_si_fin(sbinfo); |
4f0767ce | 6356 | +out: |
1facf9fc | 6357 | + return err; |
6358 | +} | |
6359 | + | |
6360 | +/* ---------------------------------------------------------------------- */ | |
6361 | + | |
6362 | +void dbgaufs_fin(void) | |
6363 | +{ | |
6364 | + debugfs_remove(dbgaufs); | |
6365 | +} | |
6366 | + | |
6367 | +int __init dbgaufs_init(void) | |
6368 | +{ | |
6369 | + int err; | |
6370 | + | |
6371 | + err = -EIO; | |
6372 | + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL); | |
6373 | + if (dbgaufs) | |
6374 | + err = 0; | |
6375 | + return err; | |
6376 | +} | |
7f207e10 AM |
6377 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h |
6378 | --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 6379 | +++ linux/fs/aufs/dbgaufs.h 2015-06-28 17:35:44.348050491 +0200 |
523b37e3 | 6380 | @@ -0,0 +1,48 @@ |
1facf9fc | 6381 | +/* |
2000de60 | 6382 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6383 | + * |
6384 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6385 | + * it under the terms of the GNU General Public License as published by | |
6386 | + * the Free Software Foundation; either version 2 of the License, or | |
6387 | + * (at your option) any later version. | |
dece6358 AM |
6388 | + * |
6389 | + * This program is distributed in the hope that it will be useful, | |
6390 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6391 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6392 | + * GNU General Public License for more details. | |
6393 | + * | |
6394 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6395 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6396 | + */ |
6397 | + | |
6398 | +/* | |
6399 | + * debugfs interface | |
6400 | + */ | |
6401 | + | |
6402 | +#ifndef __DBGAUFS_H__ | |
6403 | +#define __DBGAUFS_H__ | |
6404 | + | |
6405 | +#ifdef __KERNEL__ | |
6406 | + | |
dece6358 | 6407 | +struct super_block; |
1facf9fc | 6408 | +struct au_sbinfo; |
dece6358 | 6409 | + |
1facf9fc | 6410 | +#ifdef CONFIG_DEBUG_FS |
6411 | +/* dbgaufs.c */ | |
6412 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
6413 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
6414 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo); | |
6415 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo); | |
6416 | +void dbgaufs_fin(void); | |
6417 | +int __init dbgaufs_init(void); | |
1facf9fc | 6418 | +#else |
4a4d8108 AM |
6419 | +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) |
6420 | +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
6421 | +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo) | |
6422 | +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo) | |
6423 | +AuStubVoid(dbgaufs_fin, void) | |
6424 | +AuStubInt0(__init dbgaufs_init, void) | |
1facf9fc | 6425 | +#endif /* CONFIG_DEBUG_FS */ |
6426 | + | |
6427 | +#endif /* __KERNEL__ */ | |
6428 | +#endif /* __DBGAUFS_H__ */ | |
7f207e10 AM |
6429 | diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c |
6430 | --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 6431 | +++ linux/fs/aufs/dcsub.c 2015-06-28 17:35:44.348050491 +0200 |
c1595e42 | 6432 | @@ -0,0 +1,224 @@ |
1facf9fc | 6433 | +/* |
2000de60 | 6434 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6435 | + * |
6436 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6437 | + * it under the terms of the GNU General Public License as published by | |
6438 | + * the Free Software Foundation; either version 2 of the License, or | |
6439 | + * (at your option) any later version. | |
dece6358 AM |
6440 | + * |
6441 | + * This program is distributed in the hope that it will be useful, | |
6442 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6443 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6444 | + * GNU General Public License for more details. | |
6445 | + * | |
6446 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6447 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6448 | + */ |
6449 | + | |
6450 | +/* | |
6451 | + * sub-routines for dentry cache | |
6452 | + */ | |
6453 | + | |
6454 | +#include "aufs.h" | |
6455 | + | |
6456 | +static void au_dpage_free(struct au_dpage *dpage) | |
6457 | +{ | |
6458 | + int i; | |
6459 | + struct dentry **p; | |
6460 | + | |
6461 | + p = dpage->dentries; | |
6462 | + for (i = 0; i < dpage->ndentry; i++) | |
6463 | + dput(*p++); | |
6464 | + free_page((unsigned long)dpage->dentries); | |
6465 | +} | |
6466 | + | |
6467 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp) | |
6468 | +{ | |
6469 | + int err; | |
6470 | + void *p; | |
6471 | + | |
6472 | + err = -ENOMEM; | |
6473 | + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp); | |
6474 | + if (unlikely(!dpages->dpages)) | |
6475 | + goto out; | |
6476 | + | |
6477 | + p = (void *)__get_free_page(gfp); | |
6478 | + if (unlikely(!p)) | |
6479 | + goto out_dpages; | |
6480 | + | |
6481 | + dpages->dpages[0].ndentry = 0; | |
6482 | + dpages->dpages[0].dentries = p; | |
6483 | + dpages->ndpage = 1; | |
6484 | + return 0; /* success */ | |
6485 | + | |
4f0767ce | 6486 | +out_dpages: |
1facf9fc | 6487 | + kfree(dpages->dpages); |
4f0767ce | 6488 | +out: |
1facf9fc | 6489 | + return err; |
6490 | +} | |
6491 | + | |
6492 | +void au_dpages_free(struct au_dcsub_pages *dpages) | |
6493 | +{ | |
6494 | + int i; | |
6495 | + struct au_dpage *p; | |
6496 | + | |
6497 | + p = dpages->dpages; | |
6498 | + for (i = 0; i < dpages->ndpage; i++) | |
6499 | + au_dpage_free(p++); | |
6500 | + kfree(dpages->dpages); | |
6501 | +} | |
6502 | + | |
6503 | +static int au_dpages_append(struct au_dcsub_pages *dpages, | |
6504 | + struct dentry *dentry, gfp_t gfp) | |
6505 | +{ | |
6506 | + int err, sz; | |
6507 | + struct au_dpage *dpage; | |
6508 | + void *p; | |
6509 | + | |
6510 | + dpage = dpages->dpages + dpages->ndpage - 1; | |
6511 | + sz = PAGE_SIZE / sizeof(dentry); | |
6512 | + if (unlikely(dpage->ndentry >= sz)) { | |
6513 | + AuLabel(new dpage); | |
6514 | + err = -ENOMEM; | |
6515 | + sz = dpages->ndpage * sizeof(*dpages->dpages); | |
6516 | + p = au_kzrealloc(dpages->dpages, sz, | |
6517 | + sz + sizeof(*dpages->dpages), gfp); | |
6518 | + if (unlikely(!p)) | |
6519 | + goto out; | |
6520 | + | |
6521 | + dpages->dpages = p; | |
6522 | + dpage = dpages->dpages + dpages->ndpage; | |
6523 | + p = (void *)__get_free_page(gfp); | |
6524 | + if (unlikely(!p)) | |
6525 | + goto out; | |
6526 | + | |
6527 | + dpage->ndentry = 0; | |
6528 | + dpage->dentries = p; | |
6529 | + dpages->ndpage++; | |
6530 | + } | |
6531 | + | |
c1595e42 | 6532 | + AuDebugOn(au_dcount(dentry) <= 0); |
027c5e7a | 6533 | + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry); |
1facf9fc | 6534 | + return 0; /* success */ |
6535 | + | |
4f0767ce | 6536 | +out: |
1facf9fc | 6537 | + return err; |
6538 | +} | |
6539 | + | |
c1595e42 JR |
6540 | +/* todo: BAD approach */ |
6541 | +/* copied from linux/fs/dcache.c */ | |
6542 | +enum d_walk_ret { | |
6543 | + D_WALK_CONTINUE, | |
6544 | + D_WALK_QUIT, | |
6545 | + D_WALK_NORETRY, | |
6546 | + D_WALK_SKIP, | |
6547 | +}; | |
6548 | + | |
6549 | +extern void d_walk(struct dentry *parent, void *data, | |
6550 | + enum d_walk_ret (*enter)(void *, struct dentry *), | |
6551 | + void (*finish)(void *)); | |
6552 | + | |
6553 | +struct ac_dpages_arg { | |
1facf9fc | 6554 | + int err; |
c1595e42 JR |
6555 | + struct au_dcsub_pages *dpages; |
6556 | + struct super_block *sb; | |
6557 | + au_dpages_test test; | |
6558 | + void *arg; | |
6559 | +}; | |
1facf9fc | 6560 | + |
c1595e42 JR |
6561 | +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry) |
6562 | +{ | |
6563 | + enum d_walk_ret ret; | |
6564 | + struct ac_dpages_arg *arg = _arg; | |
1facf9fc | 6565 | + |
c1595e42 JR |
6566 | + ret = D_WALK_CONTINUE; |
6567 | + if (dentry->d_sb == arg->sb | |
6568 | + && !IS_ROOT(dentry) | |
6569 | + && au_dcount(dentry) > 0 | |
6570 | + && au_di(dentry) | |
6571 | + && (!arg->test || arg->test(dentry, arg->arg))) { | |
6572 | + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC); | |
6573 | + if (unlikely(arg->err)) | |
6574 | + ret = D_WALK_QUIT; | |
1facf9fc | 6575 | + } |
6576 | + | |
c1595e42 JR |
6577 | + return ret; |
6578 | +} | |
027c5e7a | 6579 | + |
c1595e42 JR |
6580 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, |
6581 | + au_dpages_test test, void *arg) | |
6582 | +{ | |
6583 | + struct ac_dpages_arg args = { | |
6584 | + .err = 0, | |
6585 | + .dpages = dpages, | |
6586 | + .sb = root->d_sb, | |
6587 | + .test = test, | |
6588 | + .arg = arg | |
6589 | + }; | |
027c5e7a | 6590 | + |
c1595e42 JR |
6591 | + d_walk(root, &args, au_call_dpages_append, NULL); |
6592 | + | |
6593 | + return args.err; | |
1facf9fc | 6594 | +} |
6595 | + | |
6596 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6597 | + int do_include, au_dpages_test test, void *arg) | |
6598 | +{ | |
6599 | + int err; | |
6600 | + | |
6601 | + err = 0; | |
027c5e7a AM |
6602 | + write_seqlock(&rename_lock); |
6603 | + spin_lock(&dentry->d_lock); | |
6604 | + if (do_include | |
c1595e42 | 6605 | + && au_dcount(dentry) > 0 |
027c5e7a | 6606 | + && (!test || test(dentry, arg))) |
1facf9fc | 6607 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6608 | + spin_unlock(&dentry->d_lock); |
6609 | + if (unlikely(err)) | |
6610 | + goto out; | |
6611 | + | |
6612 | + /* | |
523b37e3 | 6613 | + * RCU for vfsmount is unnecessary since this is a traverse in a single |
027c5e7a AM |
6614 | + * mount |
6615 | + */ | |
1facf9fc | 6616 | + while (!IS_ROOT(dentry)) { |
027c5e7a AM |
6617 | + dentry = dentry->d_parent; /* rename_lock is locked */ |
6618 | + spin_lock(&dentry->d_lock); | |
c1595e42 | 6619 | + if (au_dcount(dentry) > 0 |
027c5e7a | 6620 | + && (!test || test(dentry, arg))) |
1facf9fc | 6621 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6622 | + spin_unlock(&dentry->d_lock); |
6623 | + if (unlikely(err)) | |
6624 | + break; | |
1facf9fc | 6625 | + } |
6626 | + | |
4f0767ce | 6627 | +out: |
027c5e7a | 6628 | + write_sequnlock(&rename_lock); |
1facf9fc | 6629 | + return err; |
6630 | +} | |
6631 | + | |
027c5e7a AM |
6632 | +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg) |
6633 | +{ | |
6634 | + return au_di(dentry) && dentry->d_sb == arg; | |
6635 | +} | |
6636 | + | |
6637 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, | |
6638 | + struct dentry *dentry, int do_include) | |
6639 | +{ | |
6640 | + return au_dcsub_pages_rev(dpages, dentry, do_include, | |
6641 | + au_dcsub_dpages_aufs, dentry->d_sb); | |
6642 | +} | |
6643 | + | |
4a4d8108 | 6644 | +int au_test_subdir(struct dentry *d1, struct dentry *d2) |
1facf9fc | 6645 | +{ |
4a4d8108 AM |
6646 | + struct path path[2] = { |
6647 | + { | |
6648 | + .dentry = d1 | |
6649 | + }, | |
6650 | + { | |
6651 | + .dentry = d2 | |
6652 | + } | |
6653 | + }; | |
1facf9fc | 6654 | + |
4a4d8108 | 6655 | + return path_is_under(path + 0, path + 1); |
1facf9fc | 6656 | +} |
7f207e10 AM |
6657 | diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h |
6658 | --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
6659 | +++ linux/fs/aufs/dcsub.h 2015-06-28 17:36:09.025073697 +0200 |
6660 | @@ -0,0 +1,136 @@ | |
1facf9fc | 6661 | +/* |
2000de60 | 6662 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6663 | + * |
6664 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6665 | + * it under the terms of the GNU General Public License as published by | |
6666 | + * the Free Software Foundation; either version 2 of the License, or | |
6667 | + * (at your option) any later version. | |
dece6358 AM |
6668 | + * |
6669 | + * This program is distributed in the hope that it will be useful, | |
6670 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6671 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6672 | + * GNU General Public License for more details. | |
6673 | + * | |
6674 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6675 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6676 | + */ |
6677 | + | |
6678 | +/* | |
6679 | + * sub-routines for dentry cache | |
6680 | + */ | |
6681 | + | |
6682 | +#ifndef __AUFS_DCSUB_H__ | |
6683 | +#define __AUFS_DCSUB_H__ | |
6684 | + | |
6685 | +#ifdef __KERNEL__ | |
6686 | + | |
7f207e10 | 6687 | +#include <linux/dcache.h> |
027c5e7a | 6688 | +#include <linux/fs.h> |
dece6358 | 6689 | + |
1facf9fc | 6690 | +struct au_dpage { |
6691 | + int ndentry; | |
6692 | + struct dentry **dentries; | |
6693 | +}; | |
6694 | + | |
6695 | +struct au_dcsub_pages { | |
6696 | + int ndpage; | |
6697 | + struct au_dpage *dpages; | |
6698 | +}; | |
6699 | + | |
6700 | +/* ---------------------------------------------------------------------- */ | |
6701 | + | |
7f207e10 | 6702 | +/* dcsub.c */ |
1facf9fc | 6703 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp); |
6704 | +void au_dpages_free(struct au_dcsub_pages *dpages); | |
6705 | +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg); | |
6706 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, | |
6707 | + au_dpages_test test, void *arg); | |
6708 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6709 | + int do_include, au_dpages_test test, void *arg); | |
027c5e7a AM |
6710 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, |
6711 | + struct dentry *dentry, int do_include); | |
4a4d8108 | 6712 | +int au_test_subdir(struct dentry *d1, struct dentry *d2); |
1facf9fc | 6713 | + |
7f207e10 AM |
6714 | +/* ---------------------------------------------------------------------- */ |
6715 | + | |
523b37e3 AM |
6716 | +/* |
6717 | + * todo: in linux-3.13, several similar (but faster) helpers are added to | |
6718 | + * include/linux/dcache.h. Try them (in the future). | |
6719 | + */ | |
6720 | + | |
027c5e7a AM |
6721 | +static inline int au_d_hashed_positive(struct dentry *d) |
6722 | +{ | |
6723 | + int err; | |
5527c038 | 6724 | + struct inode *inode = d_inode(d); |
076b876e | 6725 | + |
027c5e7a | 6726 | + err = 0; |
5527c038 JR |
6727 | + if (unlikely(d_unhashed(d) |
6728 | + || d_is_negative(d) | |
6729 | + || !inode->i_nlink)) | |
027c5e7a AM |
6730 | + err = -ENOENT; |
6731 | + return err; | |
6732 | +} | |
6733 | + | |
38d290e6 JR |
6734 | +static inline int au_d_linkable(struct dentry *d) |
6735 | +{ | |
6736 | + int err; | |
5527c038 | 6737 | + struct inode *inode = d_inode(d); |
076b876e | 6738 | + |
38d290e6 JR |
6739 | + err = au_d_hashed_positive(d); |
6740 | + if (err | |
5527c038 | 6741 | + && d_is_positive(d) |
38d290e6 JR |
6742 | + && (inode->i_state & I_LINKABLE)) |
6743 | + err = 0; | |
6744 | + return err; | |
6745 | +} | |
6746 | + | |
027c5e7a AM |
6747 | +static inline int au_d_alive(struct dentry *d) |
6748 | +{ | |
6749 | + int err; | |
6750 | + struct inode *inode; | |
076b876e | 6751 | + |
027c5e7a AM |
6752 | + err = 0; |
6753 | + if (!IS_ROOT(d)) | |
6754 | + err = au_d_hashed_positive(d); | |
6755 | + else { | |
5527c038 JR |
6756 | + inode = d_inode(d); |
6757 | + if (unlikely(d_unlinked(d) | |
6758 | + || d_is_negative(d) | |
6759 | + || !inode->i_nlink)) | |
027c5e7a AM |
6760 | + err = -ENOENT; |
6761 | + } | |
6762 | + return err; | |
6763 | +} | |
6764 | + | |
6765 | +static inline int au_alive_dir(struct dentry *d) | |
7f207e10 | 6766 | +{ |
027c5e7a | 6767 | + int err; |
076b876e | 6768 | + |
027c5e7a | 6769 | + err = au_d_alive(d); |
5527c038 | 6770 | + if (unlikely(err || IS_DEADDIR(d_inode(d)))) |
027c5e7a AM |
6771 | + err = -ENOENT; |
6772 | + return err; | |
7f207e10 AM |
6773 | +} |
6774 | + | |
38d290e6 JR |
6775 | +static inline int au_qstreq(struct qstr *a, struct qstr *b) |
6776 | +{ | |
6777 | + return a->len == b->len | |
6778 | + && !memcmp(a->name, b->name, a->len); | |
6779 | +} | |
6780 | + | |
7e9cd9fe AM |
6781 | +/* |
6782 | + * by the commit | |
6783 | + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without | |
6784 | + * taking d_lock | |
6785 | + * the type of d_lockref.count became int, but the inlined function d_count() | |
6786 | + * still returns unsigned int. | |
6787 | + * I don't know why. Maybe it is for every d_count() users? | |
6788 | + * Anyway au_dcount() lives on. | |
6789 | + */ | |
c1595e42 JR |
6790 | +static inline int au_dcount(struct dentry *d) |
6791 | +{ | |
6792 | + return (int)d_count(d); | |
6793 | +} | |
6794 | + | |
1facf9fc | 6795 | +#endif /* __KERNEL__ */ |
6796 | +#endif /* __AUFS_DCSUB_H__ */ | |
7f207e10 AM |
6797 | diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c |
6798 | --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
6799 | +++ linux/fs/aufs/debug.c 2015-06-28 17:36:09.025073697 +0200 |
6800 | @@ -0,0 +1,440 @@ | |
1facf9fc | 6801 | +/* |
2000de60 | 6802 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6803 | + * |
6804 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6805 | + * it under the terms of the GNU General Public License as published by | |
6806 | + * the Free Software Foundation; either version 2 of the License, or | |
6807 | + * (at your option) any later version. | |
dece6358 AM |
6808 | + * |
6809 | + * This program is distributed in the hope that it will be useful, | |
6810 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6811 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6812 | + * GNU General Public License for more details. | |
6813 | + * | |
6814 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6815 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6816 | + */ |
6817 | + | |
6818 | +/* | |
6819 | + * debug print functions | |
6820 | + */ | |
6821 | + | |
6822 | +#include "aufs.h" | |
6823 | + | |
392086de AM |
6824 | +/* Returns 0, or -errno. arg is in kp->arg. */ |
6825 | +static int param_atomic_t_set(const char *val, const struct kernel_param *kp) | |
6826 | +{ | |
6827 | + int err, n; | |
6828 | + | |
6829 | + err = kstrtoint(val, 0, &n); | |
6830 | + if (!err) { | |
6831 | + if (n > 0) | |
6832 | + au_debug_on(); | |
6833 | + else | |
6834 | + au_debug_off(); | |
6835 | + } | |
6836 | + return err; | |
6837 | +} | |
6838 | + | |
6839 | +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
6840 | +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp) | |
6841 | +{ | |
6842 | + atomic_t *a; | |
6843 | + | |
6844 | + a = kp->arg; | |
6845 | + return sprintf(buffer, "%d", atomic_read(a)); | |
6846 | +} | |
6847 | + | |
6848 | +static struct kernel_param_ops param_ops_atomic_t = { | |
6849 | + .set = param_atomic_t_set, | |
6850 | + .get = param_atomic_t_get | |
6851 | + /* void (*free)(void *arg) */ | |
6852 | +}; | |
6853 | + | |
6854 | +atomic_t aufs_debug = ATOMIC_INIT(0); | |
1facf9fc | 6855 | +MODULE_PARM_DESC(debug, "debug print"); |
392086de | 6856 | +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP); |
1facf9fc | 6857 | + |
c1595e42 | 6858 | +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */ |
1facf9fc | 6859 | +char *au_plevel = KERN_DEBUG; |
e49829fe JR |
6860 | +#define dpri(fmt, ...) do { \ |
6861 | + if ((au_plevel \ | |
6862 | + && strcmp(au_plevel, KERN_DEBUG)) \ | |
6863 | + || au_debug_test()) \ | |
6864 | + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \ | |
1facf9fc | 6865 | +} while (0) |
6866 | + | |
6867 | +/* ---------------------------------------------------------------------- */ | |
6868 | + | |
6869 | +void au_dpri_whlist(struct au_nhash *whlist) | |
6870 | +{ | |
6871 | + unsigned long ul, n; | |
6872 | + struct hlist_head *head; | |
c06a8ce3 | 6873 | + struct au_vdir_wh *pos; |
1facf9fc | 6874 | + |
6875 | + n = whlist->nh_num; | |
6876 | + head = whlist->nh_head; | |
6877 | + for (ul = 0; ul < n; ul++) { | |
c06a8ce3 | 6878 | + hlist_for_each_entry(pos, head, wh_hash) |
1facf9fc | 6879 | + dpri("b%d, %.*s, %d\n", |
c06a8ce3 AM |
6880 | + pos->wh_bindex, |
6881 | + pos->wh_str.len, pos->wh_str.name, | |
6882 | + pos->wh_str.len); | |
1facf9fc | 6883 | + head++; |
6884 | + } | |
6885 | +} | |
6886 | + | |
6887 | +void au_dpri_vdir(struct au_vdir *vdir) | |
6888 | +{ | |
6889 | + unsigned long ul; | |
6890 | + union au_vdir_deblk_p p; | |
6891 | + unsigned char *o; | |
6892 | + | |
6893 | + if (!vdir || IS_ERR(vdir)) { | |
6894 | + dpri("err %ld\n", PTR_ERR(vdir)); | |
6895 | + return; | |
6896 | + } | |
6897 | + | |
6898 | + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n", | |
6899 | + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk, | |
6900 | + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version); | |
6901 | + for (ul = 0; ul < vdir->vd_nblk; ul++) { | |
6902 | + p.deblk = vdir->vd_deblk[ul]; | |
6903 | + o = p.deblk; | |
6904 | + dpri("[%lu]: %p\n", ul, o); | |
6905 | + } | |
6906 | +} | |
6907 | + | |
53392da6 | 6908 | +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn, |
1facf9fc | 6909 | + struct dentry *wh) |
6910 | +{ | |
6911 | + char *n = NULL; | |
6912 | + int l = 0; | |
6913 | + | |
6914 | + if (!inode || IS_ERR(inode)) { | |
6915 | + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode)); | |
6916 | + return -1; | |
6917 | + } | |
6918 | + | |
c2b27bf2 | 6919 | + /* the type of i_blocks depends upon CONFIG_LBDAF */ |
1facf9fc | 6920 | + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long) |
6921 | + && sizeof(inode->i_blocks) != sizeof(u64)); | |
6922 | + if (wh) { | |
6923 | + n = (void *)wh->d_name.name; | |
6924 | + l = wh->d_name.len; | |
6925 | + } | |
6926 | + | |
53392da6 AM |
6927 | + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu," |
6928 | + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n", | |
6929 | + bindex, inode, | |
1facf9fc | 6930 | + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??", |
6931 | + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode, | |
6932 | + i_size_read(inode), (unsigned long long)inode->i_blocks, | |
53392da6 | 6933 | + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff, |
1facf9fc | 6934 | + inode->i_mapping ? inode->i_mapping->nrpages : 0, |
b752ccd1 AM |
6935 | + inode->i_state, inode->i_flags, inode->i_version, |
6936 | + inode->i_generation, | |
1facf9fc | 6937 | + l ? ", wh " : "", l, n); |
6938 | + return 0; | |
6939 | +} | |
6940 | + | |
6941 | +void au_dpri_inode(struct inode *inode) | |
6942 | +{ | |
6943 | + struct au_iinfo *iinfo; | |
6944 | + aufs_bindex_t bindex; | |
53392da6 | 6945 | + int err, hn; |
1facf9fc | 6946 | + |
53392da6 | 6947 | + err = do_pri_inode(-1, inode, -1, NULL); |
1facf9fc | 6948 | + if (err || !au_test_aufs(inode->i_sb)) |
6949 | + return; | |
6950 | + | |
6951 | + iinfo = au_ii(inode); | |
6952 | + if (!iinfo) | |
6953 | + return; | |
6954 | + dpri("i-1: bstart %d, bend %d, gen %d\n", | |
537831f9 | 6955 | + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL)); |
1facf9fc | 6956 | + if (iinfo->ii_bstart < 0) |
6957 | + return; | |
53392da6 AM |
6958 | + hn = 0; |
6959 | + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) { | |
6960 | + hn = !!au_hn(iinfo->ii_hinode + bindex); | |
6961 | + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn, | |
1facf9fc | 6962 | + iinfo->ii_hinode[0 + bindex].hi_whdentry); |
53392da6 | 6963 | + } |
1facf9fc | 6964 | +} |
6965 | + | |
2cbb1c4b JR |
6966 | +void au_dpri_dalias(struct inode *inode) |
6967 | +{ | |
6968 | + struct dentry *d; | |
6969 | + | |
6970 | + spin_lock(&inode->i_lock); | |
c1595e42 | 6971 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) |
2cbb1c4b JR |
6972 | + au_dpri_dentry(d); |
6973 | + spin_unlock(&inode->i_lock); | |
6974 | +} | |
6975 | + | |
1facf9fc | 6976 | +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry) |
6977 | +{ | |
6978 | + struct dentry *wh = NULL; | |
53392da6 | 6979 | + int hn; |
076b876e | 6980 | + struct au_iinfo *iinfo; |
1facf9fc | 6981 | + |
6982 | + if (!dentry || IS_ERR(dentry)) { | |
6983 | + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry)); | |
6984 | + return -1; | |
6985 | + } | |
6986 | + /* do not call dget_parent() here */ | |
027c5e7a | 6987 | + /* note: access d_xxx without d_lock */ |
523b37e3 AM |
6988 | + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n", |
6989 | + bindex, dentry, dentry, | |
1facf9fc | 6990 | + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??", |
c1595e42 | 6991 | + au_dcount(dentry), dentry->d_flags, |
523b37e3 | 6992 | + d_unhashed(dentry) ? "un" : ""); |
53392da6 | 6993 | + hn = -1; |
5527c038 JR |
6994 | + if (bindex >= 0 |
6995 | + && d_is_positive(dentry) | |
6996 | + && au_test_aufs(dentry->d_sb)) { | |
6997 | + iinfo = au_ii(d_inode(dentry)); | |
53392da6 AM |
6998 | + if (iinfo) { |
6999 | + hn = !!au_hn(iinfo->ii_hinode + bindex); | |
1facf9fc | 7000 | + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry; |
53392da6 | 7001 | + } |
1facf9fc | 7002 | + } |
5527c038 | 7003 | + do_pri_inode(bindex, d_inode(dentry), hn, wh); |
1facf9fc | 7004 | + return 0; |
7005 | +} | |
7006 | + | |
7007 | +void au_dpri_dentry(struct dentry *dentry) | |
7008 | +{ | |
7009 | + struct au_dinfo *dinfo; | |
7010 | + aufs_bindex_t bindex; | |
7011 | + int err; | |
4a4d8108 | 7012 | + struct au_hdentry *hdp; |
1facf9fc | 7013 | + |
7014 | + err = do_pri_dentry(-1, dentry); | |
7015 | + if (err || !au_test_aufs(dentry->d_sb)) | |
7016 | + return; | |
7017 | + | |
7018 | + dinfo = au_di(dentry); | |
7019 | + if (!dinfo) | |
7020 | + return; | |
38d290e6 | 7021 | + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n", |
1facf9fc | 7022 | + dinfo->di_bstart, dinfo->di_bend, |
38d290e6 JR |
7023 | + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry), |
7024 | + dinfo->di_tmpfile); | |
1facf9fc | 7025 | + if (dinfo->di_bstart < 0) |
7026 | + return; | |
4a4d8108 | 7027 | + hdp = dinfo->di_hdentry; |
1facf9fc | 7028 | + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++) |
4a4d8108 | 7029 | + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry); |
1facf9fc | 7030 | +} |
7031 | + | |
7032 | +static int do_pri_file(aufs_bindex_t bindex, struct file *file) | |
7033 | +{ | |
7034 | + char a[32]; | |
7035 | + | |
7036 | + if (!file || IS_ERR(file)) { | |
7037 | + dpri("f%d: err %ld\n", bindex, PTR_ERR(file)); | |
7038 | + return -1; | |
7039 | + } | |
7040 | + a[0] = 0; | |
7041 | + if (bindex < 0 | |
b912730e | 7042 | + && !IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7043 | + && au_test_aufs(file->f_path.dentry->d_sb) |
1facf9fc | 7044 | + && au_fi(file)) |
e49829fe | 7045 | + snprintf(a, sizeof(a), ", gen %d, mmapped %d", |
2cbb1c4b | 7046 | + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped)); |
b752ccd1 | 7047 | + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n", |
1facf9fc | 7048 | + bindex, file->f_mode, file->f_flags, (long)file_count(file), |
b752ccd1 | 7049 | + file->f_version, file->f_pos, a); |
b912730e | 7050 | + if (!IS_ERR_OR_NULL(file->f_path.dentry)) |
2000de60 | 7051 | + do_pri_dentry(bindex, file->f_path.dentry); |
1facf9fc | 7052 | + return 0; |
7053 | +} | |
7054 | + | |
7055 | +void au_dpri_file(struct file *file) | |
7056 | +{ | |
7057 | + struct au_finfo *finfo; | |
4a4d8108 AM |
7058 | + struct au_fidir *fidir; |
7059 | + struct au_hfile *hfile; | |
1facf9fc | 7060 | + aufs_bindex_t bindex; |
7061 | + int err; | |
7062 | + | |
7063 | + err = do_pri_file(-1, file); | |
2000de60 | 7064 | + if (err |
b912730e | 7065 | + || IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7066 | + || !au_test_aufs(file->f_path.dentry->d_sb)) |
1facf9fc | 7067 | + return; |
7068 | + | |
7069 | + finfo = au_fi(file); | |
7070 | + if (!finfo) | |
7071 | + return; | |
4a4d8108 | 7072 | + if (finfo->fi_btop < 0) |
1facf9fc | 7073 | + return; |
4a4d8108 AM |
7074 | + fidir = finfo->fi_hdir; |
7075 | + if (!fidir) | |
7076 | + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file); | |
7077 | + else | |
e49829fe JR |
7078 | + for (bindex = finfo->fi_btop; |
7079 | + bindex >= 0 && bindex <= fidir->fd_bbot; | |
4a4d8108 AM |
7080 | + bindex++) { |
7081 | + hfile = fidir->fd_hfile + bindex; | |
7082 | + do_pri_file(bindex, hfile ? hfile->hf_file : NULL); | |
7083 | + } | |
1facf9fc | 7084 | +} |
7085 | + | |
7086 | +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br) | |
7087 | +{ | |
7088 | + struct vfsmount *mnt; | |
7089 | + struct super_block *sb; | |
7090 | + | |
7091 | + if (!br || IS_ERR(br)) | |
7092 | + goto out; | |
86dc4139 | 7093 | + mnt = au_br_mnt(br); |
1facf9fc | 7094 | + if (!mnt || IS_ERR(mnt)) |
7095 | + goto out; | |
7096 | + sb = mnt->mnt_sb; | |
7097 | + if (!sb || IS_ERR(sb)) | |
7098 | + goto out; | |
7099 | + | |
1e00d052 | 7100 | + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, " |
b752ccd1 | 7101 | + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, " |
1facf9fc | 7102 | + "xino %d\n", |
1e00d052 AM |
7103 | + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count), |
7104 | + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev), | |
b752ccd1 | 7105 | + sb->s_flags, sb->s_count, |
1facf9fc | 7106 | + atomic_read(&sb->s_active), !!br->br_xino.xi_file); |
7107 | + return 0; | |
7108 | + | |
4f0767ce | 7109 | +out: |
1facf9fc | 7110 | + dpri("s%d: err %ld\n", bindex, PTR_ERR(br)); |
7111 | + return -1; | |
7112 | +} | |
7113 | + | |
7114 | +void au_dpri_sb(struct super_block *sb) | |
7115 | +{ | |
7116 | + struct au_sbinfo *sbinfo; | |
7117 | + aufs_bindex_t bindex; | |
7118 | + int err; | |
7119 | + /* to reuduce stack size */ | |
7120 | + struct { | |
7121 | + struct vfsmount mnt; | |
7122 | + struct au_branch fake; | |
7123 | + } *a; | |
7124 | + | |
7125 | + /* this function can be called from magic sysrq */ | |
7126 | + a = kzalloc(sizeof(*a), GFP_ATOMIC); | |
7127 | + if (unlikely(!a)) { | |
7128 | + dpri("no memory\n"); | |
7129 | + return; | |
7130 | + } | |
7131 | + | |
7132 | + a->mnt.mnt_sb = sb; | |
7133 | + a->fake.br_perm = 0; | |
86dc4139 | 7134 | + a->fake.br_path.mnt = &a->mnt; |
1facf9fc | 7135 | + a->fake.br_xino.xi_file = NULL; |
7136 | + atomic_set(&a->fake.br_count, 0); | |
7137 | + smp_mb(); /* atomic_set */ | |
7138 | + err = do_pri_br(-1, &a->fake); | |
7139 | + kfree(a); | |
7140 | + dpri("dev 0x%x\n", sb->s_dev); | |
7141 | + if (err || !au_test_aufs(sb)) | |
7142 | + return; | |
7143 | + | |
7144 | + sbinfo = au_sbi(sb); | |
7145 | + if (!sbinfo) | |
7146 | + return; | |
7147 | + dpri("nw %d, gen %u, kobj %d\n", | |
7148 | + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation, | |
7149 | + atomic_read(&sbinfo->si_kobj.kref.refcount)); | |
7150 | + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++) | |
7151 | + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]); | |
7152 | +} | |
7153 | + | |
7154 | +/* ---------------------------------------------------------------------- */ | |
7155 | + | |
027c5e7a AM |
7156 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line) |
7157 | +{ | |
5527c038 | 7158 | + struct inode *h_inode, *inode = d_inode(dentry); |
027c5e7a AM |
7159 | + struct dentry *h_dentry; |
7160 | + aufs_bindex_t bindex, bend, bi; | |
7161 | + | |
7162 | + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */) | |
7163 | + return; | |
7164 | + | |
7165 | + bend = au_dbend(dentry); | |
7166 | + bi = au_ibend(inode); | |
7167 | + if (bi < bend) | |
7168 | + bend = bi; | |
7169 | + bindex = au_dbstart(dentry); | |
7170 | + bi = au_ibstart(inode); | |
7171 | + if (bi > bindex) | |
7172 | + bindex = bi; | |
7173 | + | |
7174 | + for (; bindex <= bend; bindex++) { | |
7175 | + h_dentry = au_h_dptr(dentry, bindex); | |
7176 | + if (!h_dentry) | |
7177 | + continue; | |
7178 | + h_inode = au_h_iptr(inode, bindex); | |
5527c038 | 7179 | + if (unlikely(h_inode != d_inode(h_dentry))) { |
392086de | 7180 | + au_debug_on(); |
027c5e7a AM |
7181 | + AuDbg("b%d, %s:%d\n", bindex, func, line); |
7182 | + AuDbgDentry(dentry); | |
7183 | + AuDbgInode(inode); | |
392086de | 7184 | + au_debug_off(); |
027c5e7a AM |
7185 | + BUG(); |
7186 | + } | |
7187 | + } | |
7188 | +} | |
7189 | + | |
1facf9fc | 7190 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen) |
7191 | +{ | |
7192 | + int err, i, j; | |
7193 | + struct au_dcsub_pages dpages; | |
7194 | + struct au_dpage *dpage; | |
7195 | + struct dentry **dentries; | |
7196 | + | |
7197 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
7198 | + AuDebugOn(err); | |
027c5e7a | 7199 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1); |
1facf9fc | 7200 | + AuDebugOn(err); |
7201 | + for (i = dpages.ndpage - 1; !err && i >= 0; i--) { | |
7202 | + dpage = dpages.dpages + i; | |
7203 | + dentries = dpage->dentries; | |
7204 | + for (j = dpage->ndentry - 1; !err && j >= 0; j--) | |
027c5e7a | 7205 | + AuDebugOn(au_digen_test(dentries[j], sigen)); |
1facf9fc | 7206 | + } |
7207 | + au_dpages_free(&dpages); | |
7208 | +} | |
7209 | + | |
1facf9fc | 7210 | +void au_dbg_verify_kthread(void) |
7211 | +{ | |
53392da6 | 7212 | + if (au_wkq_test()) { |
1facf9fc | 7213 | + au_dbg_blocked(); |
1e00d052 AM |
7214 | + /* |
7215 | + * It may be recursive, but udba=notify between two aufs mounts, | |
7216 | + * where a single ro branch is shared, is not a problem. | |
7217 | + */ | |
7218 | + /* WARN_ON(1); */ | |
1facf9fc | 7219 | + } |
7220 | +} | |
7221 | + | |
7222 | +/* ---------------------------------------------------------------------- */ | |
7223 | + | |
1facf9fc | 7224 | +int __init au_debug_init(void) |
7225 | +{ | |
7226 | + aufs_bindex_t bindex; | |
7227 | + struct au_vdir_destr destr; | |
7228 | + | |
7229 | + bindex = -1; | |
7230 | + AuDebugOn(bindex >= 0); | |
7231 | + | |
7232 | + destr.len = -1; | |
7233 | + AuDebugOn(destr.len < NAME_MAX); | |
7234 | + | |
7235 | +#ifdef CONFIG_4KSTACKS | |
0c3ec466 | 7236 | + pr_warn("CONFIG_4KSTACKS is defined.\n"); |
1facf9fc | 7237 | +#endif |
7238 | + | |
1facf9fc | 7239 | + return 0; |
7240 | +} | |
7f207e10 AM |
7241 | diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h |
7242 | --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
7243 | +++ linux/fs/aufs/debug.h 2015-06-28 17:35:44.348050491 +0200 |
7244 | @@ -0,0 +1,225 @@ | |
1facf9fc | 7245 | +/* |
2000de60 | 7246 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 7247 | + * |
7248 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7249 | + * it under the terms of the GNU General Public License as published by | |
7250 | + * the Free Software Foundation; either version 2 of the License, or | |
7251 | + * (at your option) any later version. | |
dece6358 AM |
7252 | + * |
7253 | + * This program is distributed in the hope that it will be useful, | |
7254 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7255 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7256 | + * GNU General Public License for more details. | |
7257 | + * | |
7258 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7259 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7260 | + */ |
7261 | + | |
7262 | +/* | |
7263 | + * debug print functions | |
7264 | + */ | |
7265 | + | |
7266 | +#ifndef __AUFS_DEBUG_H__ | |
7267 | +#define __AUFS_DEBUG_H__ | |
7268 | + | |
7269 | +#ifdef __KERNEL__ | |
7270 | + | |
392086de | 7271 | +#include <linux/atomic.h> |
4a4d8108 AM |
7272 | +#include <linux/module.h> |
7273 | +#include <linux/kallsyms.h> | |
1facf9fc | 7274 | +#include <linux/sysrq.h> |
4a4d8108 | 7275 | + |
1facf9fc | 7276 | +#ifdef CONFIG_AUFS_DEBUG |
7277 | +#define AuDebugOn(a) BUG_ON(a) | |
7278 | + | |
7279 | +/* module parameter */ | |
392086de AM |
7280 | +extern atomic_t aufs_debug; |
7281 | +static inline void au_debug_on(void) | |
1facf9fc | 7282 | +{ |
392086de AM |
7283 | + atomic_inc(&aufs_debug); |
7284 | +} | |
7285 | +static inline void au_debug_off(void) | |
7286 | +{ | |
7287 | + atomic_dec_if_positive(&aufs_debug); | |
1facf9fc | 7288 | +} |
7289 | + | |
7290 | +static inline int au_debug_test(void) | |
7291 | +{ | |
392086de | 7292 | + return atomic_read(&aufs_debug) > 0; |
1facf9fc | 7293 | +} |
7294 | +#else | |
7295 | +#define AuDebugOn(a) do {} while (0) | |
392086de AM |
7296 | +AuStubVoid(au_debug_on, void) |
7297 | +AuStubVoid(au_debug_off, void) | |
4a4d8108 | 7298 | +AuStubInt0(au_debug_test, void) |
1facf9fc | 7299 | +#endif /* CONFIG_AUFS_DEBUG */ |
7300 | + | |
392086de AM |
7301 | +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t) |
7302 | + | |
1facf9fc | 7303 | +/* ---------------------------------------------------------------------- */ |
7304 | + | |
7305 | +/* debug print */ | |
7306 | + | |
4a4d8108 | 7307 | +#define AuDbg(fmt, ...) do { \ |
1facf9fc | 7308 | + if (au_debug_test()) \ |
4a4d8108 | 7309 | + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \ |
1facf9fc | 7310 | +} while (0) |
4a4d8108 AM |
7311 | +#define AuLabel(l) AuDbg(#l "\n") |
7312 | +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__) | |
7313 | +#define AuWarn1(fmt, ...) do { \ | |
1facf9fc | 7314 | + static unsigned char _c; \ |
7315 | + if (!_c++) \ | |
0c3ec466 | 7316 | + pr_warn(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7317 | +} while (0) |
7318 | + | |
4a4d8108 | 7319 | +#define AuErr1(fmt, ...) do { \ |
1facf9fc | 7320 | + static unsigned char _c; \ |
7321 | + if (!_c++) \ | |
4a4d8108 | 7322 | + pr_err(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7323 | +} while (0) |
7324 | + | |
4a4d8108 | 7325 | +#define AuIOErr1(fmt, ...) do { \ |
1facf9fc | 7326 | + static unsigned char _c; \ |
7327 | + if (!_c++) \ | |
4a4d8108 | 7328 | + AuIOErr(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7329 | +} while (0) |
7330 | + | |
7331 | +#define AuUnsupportMsg "This operation is not supported." \ | |
7332 | + " Please report this application to aufs-users ML." | |
4a4d8108 AM |
7333 | +#define AuUnsupport(fmt, ...) do { \ |
7334 | + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \ | |
1facf9fc | 7335 | + dump_stack(); \ |
7336 | +} while (0) | |
7337 | + | |
7338 | +#define AuTraceErr(e) do { \ | |
7339 | + if (unlikely((e) < 0)) \ | |
7340 | + AuDbg("err %d\n", (int)(e)); \ | |
7341 | +} while (0) | |
7342 | + | |
7343 | +#define AuTraceErrPtr(p) do { \ | |
7344 | + if (IS_ERR(p)) \ | |
7345 | + AuDbg("err %ld\n", PTR_ERR(p)); \ | |
7346 | +} while (0) | |
7347 | + | |
7348 | +/* dirty macros for debug print, use with "%.*s" and caution */ | |
7349 | +#define AuLNPair(qstr) (qstr)->len, (qstr)->name | |
1facf9fc | 7350 | + |
7351 | +/* ---------------------------------------------------------------------- */ | |
7352 | + | |
dece6358 | 7353 | +struct dentry; |
1facf9fc | 7354 | +#ifdef CONFIG_AUFS_DEBUG |
c1595e42 | 7355 | +extern struct mutex au_dbg_mtx; |
1facf9fc | 7356 | +extern char *au_plevel; |
7357 | +struct au_nhash; | |
7358 | +void au_dpri_whlist(struct au_nhash *whlist); | |
7359 | +struct au_vdir; | |
7360 | +void au_dpri_vdir(struct au_vdir *vdir); | |
dece6358 | 7361 | +struct inode; |
1facf9fc | 7362 | +void au_dpri_inode(struct inode *inode); |
2cbb1c4b | 7363 | +void au_dpri_dalias(struct inode *inode); |
1facf9fc | 7364 | +void au_dpri_dentry(struct dentry *dentry); |
dece6358 | 7365 | +struct file; |
1facf9fc | 7366 | +void au_dpri_file(struct file *filp); |
dece6358 | 7367 | +struct super_block; |
1facf9fc | 7368 | +void au_dpri_sb(struct super_block *sb); |
7369 | + | |
027c5e7a AM |
7370 | +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__) |
7371 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line); | |
1facf9fc | 7372 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen); |
1facf9fc | 7373 | +void au_dbg_verify_kthread(void); |
7374 | + | |
7375 | +int __init au_debug_init(void); | |
7e9cd9fe | 7376 | + |
1facf9fc | 7377 | +#define AuDbgWhlist(w) do { \ |
c1595e42 | 7378 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7379 | + AuDbg(#w "\n"); \ |
7380 | + au_dpri_whlist(w); \ | |
c1595e42 | 7381 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7382 | +} while (0) |
7383 | + | |
7384 | +#define AuDbgVdir(v) do { \ | |
c1595e42 | 7385 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7386 | + AuDbg(#v "\n"); \ |
7387 | + au_dpri_vdir(v); \ | |
c1595e42 | 7388 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7389 | +} while (0) |
7390 | + | |
7391 | +#define AuDbgInode(i) do { \ | |
c1595e42 | 7392 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7393 | + AuDbg(#i "\n"); \ |
7394 | + au_dpri_inode(i); \ | |
c1595e42 | 7395 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7396 | +} while (0) |
7397 | + | |
2cbb1c4b | 7398 | +#define AuDbgDAlias(i) do { \ |
c1595e42 | 7399 | + mutex_lock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7400 | + AuDbg(#i "\n"); \ |
7401 | + au_dpri_dalias(i); \ | |
c1595e42 | 7402 | + mutex_unlock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7403 | +} while (0) |
7404 | + | |
1facf9fc | 7405 | +#define AuDbgDentry(d) do { \ |
c1595e42 | 7406 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7407 | + AuDbg(#d "\n"); \ |
7408 | + au_dpri_dentry(d); \ | |
c1595e42 | 7409 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7410 | +} while (0) |
7411 | + | |
7412 | +#define AuDbgFile(f) do { \ | |
c1595e42 | 7413 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7414 | + AuDbg(#f "\n"); \ |
7415 | + au_dpri_file(f); \ | |
c1595e42 | 7416 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7417 | +} while (0) |
7418 | + | |
7419 | +#define AuDbgSb(sb) do { \ | |
c1595e42 | 7420 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7421 | + AuDbg(#sb "\n"); \ |
7422 | + au_dpri_sb(sb); \ | |
c1595e42 | 7423 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7424 | +} while (0) |
7425 | + | |
4a4d8108 AM |
7426 | +#define AuDbgSym(addr) do { \ |
7427 | + char sym[KSYM_SYMBOL_LEN]; \ | |
7428 | + sprint_symbol(sym, (unsigned long)addr); \ | |
7429 | + AuDbg("%s\n", sym); \ | |
7430 | +} while (0) | |
1facf9fc | 7431 | +#else |
027c5e7a | 7432 | +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry) |
4a4d8108 AM |
7433 | +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen) |
7434 | +AuStubVoid(au_dbg_verify_kthread, void) | |
7435 | +AuStubInt0(__init au_debug_init, void) | |
1facf9fc | 7436 | + |
1facf9fc | 7437 | +#define AuDbgWhlist(w) do {} while (0) |
7438 | +#define AuDbgVdir(v) do {} while (0) | |
7439 | +#define AuDbgInode(i) do {} while (0) | |
2cbb1c4b | 7440 | +#define AuDbgDAlias(i) do {} while (0) |
1facf9fc | 7441 | +#define AuDbgDentry(d) do {} while (0) |
7442 | +#define AuDbgFile(f) do {} while (0) | |
7443 | +#define AuDbgSb(sb) do {} while (0) | |
4a4d8108 | 7444 | +#define AuDbgSym(addr) do {} while (0) |
1facf9fc | 7445 | +#endif /* CONFIG_AUFS_DEBUG */ |
7446 | + | |
7447 | +/* ---------------------------------------------------------------------- */ | |
7448 | + | |
7449 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
7450 | +int __init au_sysrq_init(void); | |
7451 | +void au_sysrq_fin(void); | |
7452 | + | |
7453 | +#ifdef CONFIG_HW_CONSOLE | |
7454 | +#define au_dbg_blocked() do { \ | |
7455 | + WARN_ON(1); \ | |
0c5527e5 | 7456 | + handle_sysrq('w'); \ |
1facf9fc | 7457 | +} while (0) |
7458 | +#else | |
4a4d8108 | 7459 | +AuStubVoid(au_dbg_blocked, void) |
1facf9fc | 7460 | +#endif |
7461 | + | |
7462 | +#else | |
4a4d8108 AM |
7463 | +AuStubInt0(__init au_sysrq_init, void) |
7464 | +AuStubVoid(au_sysrq_fin, void) | |
7465 | +AuStubVoid(au_dbg_blocked, void) | |
1facf9fc | 7466 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ |
7467 | + | |
7468 | +#endif /* __KERNEL__ */ | |
7469 | +#endif /* __AUFS_DEBUG_H__ */ | |
7f207e10 AM |
7470 | diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c |
7471 | --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
7472 | +++ linux/fs/aufs/dentry.c 2015-06-28 17:36:09.025073697 +0200 |
7473 | @@ -0,0 +1,1105 @@ | |
1facf9fc | 7474 | +/* |
2000de60 | 7475 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 7476 | + * |
7477 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7478 | + * it under the terms of the GNU General Public License as published by | |
7479 | + * the Free Software Foundation; either version 2 of the License, or | |
7480 | + * (at your option) any later version. | |
dece6358 AM |
7481 | + * |
7482 | + * This program is distributed in the hope that it will be useful, | |
7483 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7484 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7485 | + * GNU General Public License for more details. | |
7486 | + * | |
7487 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7488 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7489 | + */ |
7490 | + | |
7491 | +/* | |
7492 | + * lookup and dentry operations | |
7493 | + */ | |
7494 | + | |
dece6358 | 7495 | +#include <linux/namei.h> |
1facf9fc | 7496 | +#include "aufs.h" |
7497 | + | |
1facf9fc | 7498 | +#define AuLkup_ALLOW_NEG 1 |
076b876e | 7499 | +#define AuLkup_IGNORE_PERM (1 << 1) |
1facf9fc | 7500 | +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name) |
7f207e10 AM |
7501 | +#define au_fset_lkup(flags, name) \ |
7502 | + do { (flags) |= AuLkup_##name; } while (0) | |
7503 | +#define au_fclr_lkup(flags, name) \ | |
7504 | + do { (flags) &= ~AuLkup_##name; } while (0) | |
1facf9fc | 7505 | + |
7506 | +struct au_do_lookup_args { | |
7507 | + unsigned int flags; | |
7508 | + mode_t type; | |
1facf9fc | 7509 | +}; |
7510 | + | |
7511 | +/* | |
7512 | + * returns positive/negative dentry, NULL or an error. | |
7513 | + * NULL means whiteout-ed or not-found. | |
7514 | + */ | |
7515 | +static struct dentry* | |
7516 | +au_do_lookup(struct dentry *h_parent, struct dentry *dentry, | |
7517 | + aufs_bindex_t bindex, struct qstr *wh_name, | |
7518 | + struct au_do_lookup_args *args) | |
7519 | +{ | |
7520 | + struct dentry *h_dentry; | |
2000de60 | 7521 | + struct inode *h_inode; |
1facf9fc | 7522 | + struct au_branch *br; |
7523 | + int wh_found, opq; | |
7524 | + unsigned char wh_able; | |
7525 | + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG); | |
076b876e AM |
7526 | + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags, |
7527 | + IGNORE_PERM); | |
1facf9fc | 7528 | + |
1facf9fc | 7529 | + wh_found = 0; |
7530 | + br = au_sbr(dentry->d_sb, bindex); | |
7531 | + wh_able = !!au_br_whable(br->br_perm); | |
7532 | + if (wh_able) | |
076b876e | 7533 | + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0); |
1facf9fc | 7534 | + h_dentry = ERR_PTR(wh_found); |
7535 | + if (!wh_found) | |
7536 | + goto real_lookup; | |
7537 | + if (unlikely(wh_found < 0)) | |
7538 | + goto out; | |
7539 | + | |
7540 | + /* We found a whiteout */ | |
7541 | + /* au_set_dbend(dentry, bindex); */ | |
7542 | + au_set_dbwh(dentry, bindex); | |
7543 | + if (!allow_neg) | |
7544 | + return NULL; /* success */ | |
7545 | + | |
4f0767ce | 7546 | +real_lookup: |
076b876e AM |
7547 | + if (!ignore_perm) |
7548 | + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
7549 | + else | |
7550 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); | |
2000de60 JR |
7551 | + if (IS_ERR(h_dentry)) { |
7552 | + if (PTR_ERR(h_dentry) == -ENAMETOOLONG | |
7553 | + && !allow_neg) | |
7554 | + h_dentry = NULL; | |
1facf9fc | 7555 | + goto out; |
2000de60 | 7556 | + } |
1facf9fc | 7557 | + |
5527c038 JR |
7558 | + h_inode = d_inode(h_dentry); |
7559 | + if (d_is_negative(h_dentry)) { | |
1facf9fc | 7560 | + if (!allow_neg) |
7561 | + goto out_neg; | |
7562 | + } else if (wh_found | |
7563 | + || (args->type && args->type != (h_inode->i_mode & S_IFMT))) | |
7564 | + goto out_neg; | |
7565 | + | |
7566 | + if (au_dbend(dentry) <= bindex) | |
7567 | + au_set_dbend(dentry, bindex); | |
7568 | + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry)) | |
7569 | + au_set_dbstart(dentry, bindex); | |
7570 | + au_set_h_dptr(dentry, bindex, h_dentry); | |
7571 | + | |
2000de60 JR |
7572 | + if (!d_is_dir(h_dentry) |
7573 | + || !wh_able | |
5527c038 | 7574 | + || (d_really_is_positive(dentry) && !d_is_dir(dentry))) |
1facf9fc | 7575 | + goto out; /* success */ |
7576 | + | |
7577 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); | |
076b876e | 7578 | + opq = au_diropq_test(h_dentry); |
1facf9fc | 7579 | + mutex_unlock(&h_inode->i_mutex); |
7580 | + if (opq > 0) | |
7581 | + au_set_dbdiropq(dentry, bindex); | |
7582 | + else if (unlikely(opq < 0)) { | |
7583 | + au_set_h_dptr(dentry, bindex, NULL); | |
7584 | + h_dentry = ERR_PTR(opq); | |
7585 | + } | |
7586 | + goto out; | |
7587 | + | |
4f0767ce | 7588 | +out_neg: |
1facf9fc | 7589 | + dput(h_dentry); |
7590 | + h_dentry = NULL; | |
4f0767ce | 7591 | +out: |
1facf9fc | 7592 | + return h_dentry; |
7593 | +} | |
7594 | + | |
dece6358 AM |
7595 | +static int au_test_shwh(struct super_block *sb, const struct qstr *name) |
7596 | +{ | |
7597 | + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH) | |
7598 | + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))) | |
7599 | + return -EPERM; | |
7600 | + return 0; | |
7601 | +} | |
7602 | + | |
1facf9fc | 7603 | +/* |
7604 | + * returns the number of lower positive dentries, | |
7605 | + * otherwise an error. | |
7606 | + * can be called at unlinking with @type is zero. | |
7607 | + */ | |
537831f9 | 7608 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type) |
1facf9fc | 7609 | +{ |
7610 | + int npositive, err; | |
7611 | + aufs_bindex_t bindex, btail, bdiropq; | |
076b876e | 7612 | + unsigned char isdir, dirperm1; |
1facf9fc | 7613 | + struct qstr whname; |
7614 | + struct au_do_lookup_args args = { | |
b4510431 | 7615 | + .flags = 0, |
537831f9 | 7616 | + .type = type |
1facf9fc | 7617 | + }; |
7618 | + const struct qstr *name = &dentry->d_name; | |
7619 | + struct dentry *parent; | |
076b876e | 7620 | + struct super_block *sb; |
1facf9fc | 7621 | + |
076b876e AM |
7622 | + sb = dentry->d_sb; |
7623 | + err = au_test_shwh(sb, name); | |
dece6358 | 7624 | + if (unlikely(err)) |
1facf9fc | 7625 | + goto out; |
7626 | + | |
7627 | + err = au_wh_name_alloc(&whname, name); | |
7628 | + if (unlikely(err)) | |
7629 | + goto out; | |
7630 | + | |
2000de60 | 7631 | + isdir = !!d_is_dir(dentry); |
1facf9fc | 7632 | + if (!type) |
7633 | + au_fset_lkup(args.flags, ALLOW_NEG); | |
076b876e | 7634 | + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1); |
1facf9fc | 7635 | + |
7636 | + npositive = 0; | |
4a4d8108 | 7637 | + parent = dget_parent(dentry); |
1facf9fc | 7638 | + btail = au_dbtaildir(parent); |
7639 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
7640 | + struct dentry *h_parent, *h_dentry; | |
7641 | + struct inode *h_inode, *h_dir; | |
7642 | + | |
7643 | + h_dentry = au_h_dptr(dentry, bindex); | |
7644 | + if (h_dentry) { | |
5527c038 | 7645 | + if (d_is_positive(h_dentry)) |
1facf9fc | 7646 | + npositive++; |
7647 | + if (type != S_IFDIR) | |
7648 | + break; | |
7649 | + continue; | |
7650 | + } | |
7651 | + h_parent = au_h_dptr(parent, bindex); | |
2000de60 | 7652 | + if (!h_parent || !d_is_dir(h_parent)) |
1facf9fc | 7653 | + continue; |
7654 | + | |
5527c038 | 7655 | + h_dir = d_inode(h_parent); |
1facf9fc | 7656 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); |
7657 | + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname, | |
7658 | + &args); | |
7659 | + mutex_unlock(&h_dir->i_mutex); | |
7660 | + err = PTR_ERR(h_dentry); | |
7661 | + if (IS_ERR(h_dentry)) | |
4a4d8108 | 7662 | + goto out_parent; |
2000de60 JR |
7663 | + if (h_dentry) |
7664 | + au_fclr_lkup(args.flags, ALLOW_NEG); | |
076b876e AM |
7665 | + if (dirperm1) |
7666 | + au_fset_lkup(args.flags, IGNORE_PERM); | |
1facf9fc | 7667 | + |
7668 | + if (au_dbwh(dentry) >= 0) | |
7669 | + break; | |
7670 | + if (!h_dentry) | |
7671 | + continue; | |
5527c038 | 7672 | + if (d_is_negative(h_dentry)) |
1facf9fc | 7673 | + continue; |
5527c038 | 7674 | + h_inode = d_inode(h_dentry); |
1facf9fc | 7675 | + npositive++; |
7676 | + if (!args.type) | |
7677 | + args.type = h_inode->i_mode & S_IFMT; | |
7678 | + if (args.type != S_IFDIR) | |
7679 | + break; | |
7680 | + else if (isdir) { | |
7681 | + /* the type of lower may be different */ | |
7682 | + bdiropq = au_dbdiropq(dentry); | |
7683 | + if (bdiropq >= 0 && bdiropq <= bindex) | |
7684 | + break; | |
7685 | + } | |
7686 | + } | |
7687 | + | |
7688 | + if (npositive) { | |
7689 | + AuLabel(positive); | |
7690 | + au_update_dbstart(dentry); | |
7691 | + } | |
7692 | + err = npositive; | |
076b876e | 7693 | + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE) |
027c5e7a | 7694 | + && au_dbstart(dentry) < 0)) { |
1facf9fc | 7695 | + err = -EIO; |
523b37e3 AM |
7696 | + AuIOErr("both of real entry and whiteout found, %pd, err %d\n", |
7697 | + dentry, err); | |
027c5e7a | 7698 | + } |
1facf9fc | 7699 | + |
4f0767ce | 7700 | +out_parent: |
4a4d8108 | 7701 | + dput(parent); |
1facf9fc | 7702 | + kfree(whname.name); |
4f0767ce | 7703 | +out: |
1facf9fc | 7704 | + return err; |
7705 | +} | |
7706 | + | |
076b876e | 7707 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent) |
1facf9fc | 7708 | +{ |
7709 | + struct dentry *dentry; | |
7710 | + int wkq_err; | |
7711 | + | |
5527c038 | 7712 | + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC)) |
b4510431 | 7713 | + dentry = vfsub_lkup_one(name, parent); |
1facf9fc | 7714 | + else { |
b4510431 AM |
7715 | + struct vfsub_lkup_one_args args = { |
7716 | + .errp = &dentry, | |
7717 | + .name = name, | |
7718 | + .parent = parent | |
1facf9fc | 7719 | + }; |
7720 | + | |
b4510431 | 7721 | + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args); |
1facf9fc | 7722 | + if (unlikely(wkq_err)) |
7723 | + dentry = ERR_PTR(wkq_err); | |
7724 | + } | |
7725 | + | |
7726 | + return dentry; | |
7727 | +} | |
7728 | + | |
7729 | +/* | |
7730 | + * lookup @dentry on @bindex which should be negative. | |
7731 | + */ | |
86dc4139 | 7732 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh) |
1facf9fc | 7733 | +{ |
7734 | + int err; | |
7735 | + struct dentry *parent, *h_parent, *h_dentry; | |
86dc4139 | 7736 | + struct au_branch *br; |
1facf9fc | 7737 | + |
1facf9fc | 7738 | + parent = dget_parent(dentry); |
7739 | + h_parent = au_h_dptr(parent, bindex); | |
86dc4139 AM |
7740 | + br = au_sbr(dentry->d_sb, bindex); |
7741 | + if (wh) | |
7742 | + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
7743 | + else | |
076b876e | 7744 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); |
1facf9fc | 7745 | + err = PTR_ERR(h_dentry); |
7746 | + if (IS_ERR(h_dentry)) | |
7747 | + goto out; | |
5527c038 | 7748 | + if (unlikely(d_is_positive(h_dentry))) { |
1facf9fc | 7749 | + err = -EIO; |
523b37e3 | 7750 | + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex); |
1facf9fc | 7751 | + dput(h_dentry); |
7752 | + goto out; | |
7753 | + } | |
7754 | + | |
4a4d8108 | 7755 | + err = 0; |
1facf9fc | 7756 | + if (bindex < au_dbstart(dentry)) |
7757 | + au_set_dbstart(dentry, bindex); | |
7758 | + if (au_dbend(dentry) < bindex) | |
7759 | + au_set_dbend(dentry, bindex); | |
7760 | + au_set_h_dptr(dentry, bindex, h_dentry); | |
1facf9fc | 7761 | + |
4f0767ce | 7762 | +out: |
1facf9fc | 7763 | + dput(parent); |
7764 | + return err; | |
7765 | +} | |
7766 | + | |
7767 | +/* ---------------------------------------------------------------------- */ | |
7768 | + | |
7769 | +/* subset of struct inode */ | |
7770 | +struct au_iattr { | |
7771 | + unsigned long i_ino; | |
7772 | + /* unsigned int i_nlink; */ | |
0c3ec466 AM |
7773 | + kuid_t i_uid; |
7774 | + kgid_t i_gid; | |
1facf9fc | 7775 | + u64 i_version; |
7776 | +/* | |
7777 | + loff_t i_size; | |
7778 | + blkcnt_t i_blocks; | |
7779 | +*/ | |
7780 | + umode_t i_mode; | |
7781 | +}; | |
7782 | + | |
7783 | +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode) | |
7784 | +{ | |
7785 | + ia->i_ino = h_inode->i_ino; | |
7786 | + /* ia->i_nlink = h_inode->i_nlink; */ | |
7787 | + ia->i_uid = h_inode->i_uid; | |
7788 | + ia->i_gid = h_inode->i_gid; | |
7789 | + ia->i_version = h_inode->i_version; | |
7790 | +/* | |
7791 | + ia->i_size = h_inode->i_size; | |
7792 | + ia->i_blocks = h_inode->i_blocks; | |
7793 | +*/ | |
7794 | + ia->i_mode = (h_inode->i_mode & S_IFMT); | |
7795 | +} | |
7796 | + | |
7797 | +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode) | |
7798 | +{ | |
7799 | + return ia->i_ino != h_inode->i_ino | |
7800 | + /* || ia->i_nlink != h_inode->i_nlink */ | |
0c3ec466 | 7801 | + || !uid_eq(ia->i_uid, h_inode->i_uid) |
2dfbb274 | 7802 | + || !gid_eq(ia->i_gid, h_inode->i_gid) |
1facf9fc | 7803 | + || ia->i_version != h_inode->i_version |
7804 | +/* | |
7805 | + || ia->i_size != h_inode->i_size | |
7806 | + || ia->i_blocks != h_inode->i_blocks | |
7807 | +*/ | |
7808 | + || ia->i_mode != (h_inode->i_mode & S_IFMT); | |
7809 | +} | |
7810 | + | |
7811 | +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent, | |
7812 | + struct au_branch *br) | |
7813 | +{ | |
7814 | + int err; | |
7815 | + struct au_iattr ia; | |
7816 | + struct inode *h_inode; | |
7817 | + struct dentry *h_d; | |
7818 | + struct super_block *h_sb; | |
7819 | + | |
7820 | + err = 0; | |
7821 | + memset(&ia, -1, sizeof(ia)); | |
7822 | + h_sb = h_dentry->d_sb; | |
5527c038 JR |
7823 | + h_inode = NULL; |
7824 | + if (d_is_positive(h_dentry)) { | |
7825 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 7826 | + au_iattr_save(&ia, h_inode); |
5527c038 | 7827 | + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb)) |
1facf9fc | 7828 | + /* nfs d_revalidate may return 0 for negative dentry */ |
7829 | + /* fuse d_revalidate always return 0 for negative dentry */ | |
7830 | + goto out; | |
7831 | + | |
7832 | + /* main purpose is namei.c:cached_lookup() and d_revalidate */ | |
b4510431 | 7833 | + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent); |
1facf9fc | 7834 | + err = PTR_ERR(h_d); |
7835 | + if (IS_ERR(h_d)) | |
7836 | + goto out; | |
7837 | + | |
7838 | + err = 0; | |
7839 | + if (unlikely(h_d != h_dentry | |
5527c038 | 7840 | + || d_inode(h_d) != h_inode |
1facf9fc | 7841 | + || (h_inode && au_iattr_test(&ia, h_inode)))) |
7842 | + err = au_busy_or_stale(); | |
7843 | + dput(h_d); | |
7844 | + | |
4f0767ce | 7845 | +out: |
1facf9fc | 7846 | + AuTraceErr(err); |
7847 | + return err; | |
7848 | +} | |
7849 | + | |
7850 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, | |
7851 | + struct dentry *h_parent, struct au_branch *br) | |
7852 | +{ | |
7853 | + int err; | |
7854 | + | |
7855 | + err = 0; | |
027c5e7a AM |
7856 | + if (udba == AuOpt_UDBA_REVAL |
7857 | + && !au_test_fs_remote(h_dentry->d_sb)) { | |
1facf9fc | 7858 | + IMustLock(h_dir); |
5527c038 | 7859 | + err = (d_inode(h_dentry->d_parent) != h_dir); |
027c5e7a | 7860 | + } else if (udba != AuOpt_UDBA_NONE) |
1facf9fc | 7861 | + err = au_h_verify_dentry(h_dentry, h_parent, br); |
7862 | + | |
7863 | + return err; | |
7864 | +} | |
7865 | + | |
7866 | +/* ---------------------------------------------------------------------- */ | |
7867 | + | |
027c5e7a | 7868 | +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 7869 | +{ |
027c5e7a | 7870 | + int err; |
1facf9fc | 7871 | + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq; |
027c5e7a AM |
7872 | + struct au_hdentry tmp, *p, *q; |
7873 | + struct au_dinfo *dinfo; | |
7874 | + struct super_block *sb; | |
1facf9fc | 7875 | + |
027c5e7a | 7876 | + DiMustWriteLock(dentry); |
1308ab2a | 7877 | + |
027c5e7a AM |
7878 | + sb = dentry->d_sb; |
7879 | + dinfo = au_di(dentry); | |
1facf9fc | 7880 | + bend = dinfo->di_bend; |
7881 | + bwh = dinfo->di_bwh; | |
7882 | + bdiropq = dinfo->di_bdiropq; | |
027c5e7a | 7883 | + p = dinfo->di_hdentry + dinfo->di_bstart; |
1facf9fc | 7884 | + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) { |
027c5e7a | 7885 | + if (!p->hd_dentry) |
1facf9fc | 7886 | + continue; |
7887 | + | |
027c5e7a AM |
7888 | + new_bindex = au_br_index(sb, p->hd_id); |
7889 | + if (new_bindex == bindex) | |
1facf9fc | 7890 | + continue; |
1facf9fc | 7891 | + |
1facf9fc | 7892 | + if (dinfo->di_bwh == bindex) |
7893 | + bwh = new_bindex; | |
7894 | + if (dinfo->di_bdiropq == bindex) | |
7895 | + bdiropq = new_bindex; | |
7896 | + if (new_bindex < 0) { | |
7897 | + au_hdput(p); | |
7898 | + p->hd_dentry = NULL; | |
7899 | + continue; | |
7900 | + } | |
7901 | + | |
7902 | + /* swap two lower dentries, and loop again */ | |
7903 | + q = dinfo->di_hdentry + new_bindex; | |
7904 | + tmp = *q; | |
7905 | + *q = *p; | |
7906 | + *p = tmp; | |
7907 | + if (tmp.hd_dentry) { | |
7908 | + bindex--; | |
7909 | + p--; | |
7910 | + } | |
7911 | + } | |
7912 | + | |
1facf9fc | 7913 | + dinfo->di_bwh = -1; |
7914 | + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh)) | |
7915 | + dinfo->di_bwh = bwh; | |
7916 | + | |
7917 | + dinfo->di_bdiropq = -1; | |
7918 | + if (bdiropq >= 0 | |
7919 | + && bdiropq <= au_sbend(sb) | |
7920 | + && au_sbr_whable(sb, bdiropq)) | |
7921 | + dinfo->di_bdiropq = bdiropq; | |
7922 | + | |
027c5e7a AM |
7923 | + err = -EIO; |
7924 | + dinfo->di_bstart = -1; | |
7925 | + dinfo->di_bend = -1; | |
1facf9fc | 7926 | + bend = au_dbend(parent); |
7927 | + p = dinfo->di_hdentry; | |
7928 | + for (bindex = 0; bindex <= bend; bindex++, p++) | |
7929 | + if (p->hd_dentry) { | |
7930 | + dinfo->di_bstart = bindex; | |
7931 | + break; | |
7932 | + } | |
7933 | + | |
027c5e7a AM |
7934 | + if (dinfo->di_bstart >= 0) { |
7935 | + p = dinfo->di_hdentry + bend; | |
7936 | + for (bindex = bend; bindex >= 0; bindex--, p--) | |
7937 | + if (p->hd_dentry) { | |
7938 | + dinfo->di_bend = bindex; | |
7939 | + err = 0; | |
7940 | + break; | |
7941 | + } | |
7942 | + } | |
7943 | + | |
7944 | + return err; | |
1facf9fc | 7945 | +} |
7946 | + | |
027c5e7a | 7947 | +static void au_do_hide(struct dentry *dentry) |
1facf9fc | 7948 | +{ |
027c5e7a | 7949 | + struct inode *inode; |
1facf9fc | 7950 | + |
5527c038 JR |
7951 | + if (d_really_is_positive(dentry)) { |
7952 | + inode = d_inode(dentry); | |
7953 | + if (!d_is_dir(dentry)) { | |
027c5e7a AM |
7954 | + if (inode->i_nlink && !d_unhashed(dentry)) |
7955 | + drop_nlink(inode); | |
7956 | + } else { | |
7957 | + clear_nlink(inode); | |
7958 | + /* stop next lookup */ | |
7959 | + inode->i_flags |= S_DEAD; | |
7960 | + } | |
7961 | + smp_mb(); /* necessary? */ | |
7962 | + } | |
7963 | + d_drop(dentry); | |
7964 | +} | |
1308ab2a | 7965 | + |
027c5e7a AM |
7966 | +static int au_hide_children(struct dentry *parent) |
7967 | +{ | |
7968 | + int err, i, j, ndentry; | |
7969 | + struct au_dcsub_pages dpages; | |
7970 | + struct au_dpage *dpage; | |
7971 | + struct dentry *dentry; | |
1facf9fc | 7972 | + |
027c5e7a | 7973 | + err = au_dpages_init(&dpages, GFP_NOFS); |
1facf9fc | 7974 | + if (unlikely(err)) |
7975 | + goto out; | |
027c5e7a AM |
7976 | + err = au_dcsub_pages(&dpages, parent, NULL, NULL); |
7977 | + if (unlikely(err)) | |
7978 | + goto out_dpages; | |
1facf9fc | 7979 | + |
027c5e7a AM |
7980 | + /* in reverse order */ |
7981 | + for (i = dpages.ndpage - 1; i >= 0; i--) { | |
7982 | + dpage = dpages.dpages + i; | |
7983 | + ndentry = dpage->ndentry; | |
7984 | + for (j = ndentry - 1; j >= 0; j--) { | |
7985 | + dentry = dpage->dentries[j]; | |
7986 | + if (dentry != parent) | |
7987 | + au_do_hide(dentry); | |
7988 | + } | |
7989 | + } | |
1facf9fc | 7990 | + |
027c5e7a AM |
7991 | +out_dpages: |
7992 | + au_dpages_free(&dpages); | |
4f0767ce | 7993 | +out: |
027c5e7a | 7994 | + return err; |
1facf9fc | 7995 | +} |
7996 | + | |
027c5e7a | 7997 | +static void au_hide(struct dentry *dentry) |
1facf9fc | 7998 | +{ |
027c5e7a | 7999 | + int err; |
1facf9fc | 8000 | + |
027c5e7a | 8001 | + AuDbgDentry(dentry); |
2000de60 | 8002 | + if (d_is_dir(dentry)) { |
027c5e7a AM |
8003 | + /* shrink_dcache_parent(dentry); */ |
8004 | + err = au_hide_children(dentry); | |
8005 | + if (unlikely(err)) | |
523b37e3 AM |
8006 | + AuIOErr("%pd, failed hiding children, ignored %d\n", |
8007 | + dentry, err); | |
027c5e7a AM |
8008 | + } |
8009 | + au_do_hide(dentry); | |
8010 | +} | |
1facf9fc | 8011 | + |
027c5e7a AM |
8012 | +/* |
8013 | + * By adding a dirty branch, a cached dentry may be affected in various ways. | |
8014 | + * | |
8015 | + * a dirty branch is added | |
8016 | + * - on the top of layers | |
8017 | + * - in the middle of layers | |
8018 | + * - to the bottom of layers | |
8019 | + * | |
8020 | + * on the added branch there exists | |
8021 | + * - a whiteout | |
8022 | + * - a diropq | |
8023 | + * - a same named entry | |
8024 | + * + exist | |
8025 | + * * negative --> positive | |
8026 | + * * positive --> positive | |
8027 | + * - type is unchanged | |
8028 | + * - type is changed | |
8029 | + * + doesn't exist | |
8030 | + * * negative --> negative | |
8031 | + * * positive --> negative (rejected by au_br_del() for non-dir case) | |
8032 | + * - none | |
8033 | + */ | |
8034 | +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo, | |
8035 | + struct au_dinfo *tmp) | |
8036 | +{ | |
8037 | + int err; | |
8038 | + aufs_bindex_t bindex, bend; | |
8039 | + struct { | |
8040 | + struct dentry *dentry; | |
8041 | + struct inode *inode; | |
8042 | + mode_t mode; | |
8043 | + } orig_h, tmp_h; | |
8044 | + struct au_hdentry *hd; | |
8045 | + struct inode *inode, *h_inode; | |
8046 | + struct dentry *h_dentry; | |
8047 | + | |
8048 | + err = 0; | |
8049 | + AuDebugOn(dinfo->di_bstart < 0); | |
027c5e7a | 8050 | + orig_h.mode = 0; |
5527c038 JR |
8051 | + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry; |
8052 | + orig_h.inode = NULL; | |
8053 | + if (d_is_positive(orig_h.dentry)) { | |
8054 | + orig_h.inode = d_inode(orig_h.dentry); | |
027c5e7a | 8055 | + orig_h.mode = orig_h.inode->i_mode & S_IFMT; |
5527c038 | 8056 | + } |
027c5e7a AM |
8057 | + memset(&tmp_h, 0, sizeof(tmp_h)); |
8058 | + if (tmp->di_bstart >= 0) { | |
8059 | + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry; | |
5527c038 JR |
8060 | + tmp_h.inode = NULL; |
8061 | + if (d_is_positive(tmp_h.dentry)) { | |
8062 | + tmp_h.inode = d_inode(tmp_h.dentry); | |
027c5e7a | 8063 | + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT; |
5527c038 | 8064 | + } |
027c5e7a AM |
8065 | + } |
8066 | + | |
5527c038 JR |
8067 | + inode = NULL; |
8068 | + if (d_really_is_positive(dentry)) | |
8069 | + inode = d_inode(dentry); | |
027c5e7a AM |
8070 | + if (!orig_h.inode) { |
8071 | + AuDbg("nagative originally\n"); | |
8072 | + if (inode) { | |
8073 | + au_hide(dentry); | |
8074 | + goto out; | |
8075 | + } | |
8076 | + AuDebugOn(inode); | |
8077 | + AuDebugOn(dinfo->di_bstart != dinfo->di_bend); | |
8078 | + AuDebugOn(dinfo->di_bdiropq != -1); | |
8079 | + | |
8080 | + if (!tmp_h.inode) { | |
8081 | + AuDbg("negative --> negative\n"); | |
8082 | + /* should have only one negative lower */ | |
8083 | + if (tmp->di_bstart >= 0 | |
8084 | + && tmp->di_bstart < dinfo->di_bstart) { | |
8085 | + AuDebugOn(tmp->di_bstart != tmp->di_bend); | |
8086 | + AuDebugOn(dinfo->di_bstart != dinfo->di_bend); | |
8087 | + au_set_h_dptr(dentry, dinfo->di_bstart, NULL); | |
8088 | + au_di_cp(dinfo, tmp); | |
8089 | + hd = tmp->di_hdentry + tmp->di_bstart; | |
8090 | + au_set_h_dptr(dentry, tmp->di_bstart, | |
8091 | + dget(hd->hd_dentry)); | |
8092 | + } | |
8093 | + au_dbg_verify_dinode(dentry); | |
8094 | + } else { | |
8095 | + AuDbg("negative --> positive\n"); | |
8096 | + /* | |
8097 | + * similar to the behaviour of creating with bypassing | |
8098 | + * aufs. | |
8099 | + * unhash it in order to force an error in the | |
8100 | + * succeeding create operation. | |
8101 | + * we should not set S_DEAD here. | |
8102 | + */ | |
8103 | + d_drop(dentry); | |
8104 | + /* au_di_swap(tmp, dinfo); */ | |
8105 | + au_dbg_verify_dinode(dentry); | |
8106 | + } | |
8107 | + } else { | |
8108 | + AuDbg("positive originally\n"); | |
8109 | + /* inode may be NULL */ | |
8110 | + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode); | |
8111 | + if (!tmp_h.inode) { | |
8112 | + AuDbg("positive --> negative\n"); | |
8113 | + /* or bypassing aufs */ | |
8114 | + au_hide(dentry); | |
8115 | + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart) | |
8116 | + dinfo->di_bwh = tmp->di_bwh; | |
8117 | + if (inode) | |
8118 | + err = au_refresh_hinode_self(inode); | |
8119 | + au_dbg_verify_dinode(dentry); | |
8120 | + } else if (orig_h.mode == tmp_h.mode) { | |
8121 | + AuDbg("positive --> positive, same type\n"); | |
8122 | + if (!S_ISDIR(orig_h.mode) | |
8123 | + && dinfo->di_bstart > tmp->di_bstart) { | |
8124 | + /* | |
8125 | + * similar to the behaviour of removing and | |
8126 | + * creating. | |
8127 | + */ | |
8128 | + au_hide(dentry); | |
8129 | + if (inode) | |
8130 | + err = au_refresh_hinode_self(inode); | |
8131 | + au_dbg_verify_dinode(dentry); | |
8132 | + } else { | |
8133 | + /* fill empty slots */ | |
8134 | + if (dinfo->di_bstart > tmp->di_bstart) | |
8135 | + dinfo->di_bstart = tmp->di_bstart; | |
8136 | + if (dinfo->di_bend < tmp->di_bend) | |
8137 | + dinfo->di_bend = tmp->di_bend; | |
8138 | + dinfo->di_bwh = tmp->di_bwh; | |
8139 | + dinfo->di_bdiropq = tmp->di_bdiropq; | |
8140 | + hd = tmp->di_hdentry; | |
8141 | + bend = dinfo->di_bend; | |
8142 | + for (bindex = tmp->di_bstart; bindex <= bend; | |
8143 | + bindex++) { | |
8144 | + if (au_h_dptr(dentry, bindex)) | |
8145 | + continue; | |
8146 | + h_dentry = hd[bindex].hd_dentry; | |
8147 | + if (!h_dentry) | |
8148 | + continue; | |
5527c038 JR |
8149 | + AuDebugOn(d_is_negative(h_dentry)); |
8150 | + h_inode = d_inode(h_dentry); | |
027c5e7a AM |
8151 | + AuDebugOn(orig_h.mode |
8152 | + != (h_inode->i_mode | |
8153 | + & S_IFMT)); | |
8154 | + au_set_h_dptr(dentry, bindex, | |
8155 | + dget(h_dentry)); | |
8156 | + } | |
8157 | + err = au_refresh_hinode(inode, dentry); | |
8158 | + au_dbg_verify_dinode(dentry); | |
8159 | + } | |
8160 | + } else { | |
8161 | + AuDbg("positive --> positive, different type\n"); | |
8162 | + /* similar to the behaviour of removing and creating */ | |
8163 | + au_hide(dentry); | |
8164 | + if (inode) | |
8165 | + err = au_refresh_hinode_self(inode); | |
8166 | + au_dbg_verify_dinode(dentry); | |
8167 | + } | |
8168 | + } | |
8169 | + | |
8170 | +out: | |
8171 | + return err; | |
8172 | +} | |
8173 | + | |
8174 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent) | |
8175 | +{ | |
8176 | + int err, ebrange; | |
8177 | + unsigned int sigen; | |
8178 | + struct au_dinfo *dinfo, *tmp; | |
8179 | + struct super_block *sb; | |
8180 | + struct inode *inode; | |
8181 | + | |
8182 | + DiMustWriteLock(dentry); | |
8183 | + AuDebugOn(IS_ROOT(dentry)); | |
5527c038 | 8184 | + AuDebugOn(d_really_is_negative(parent)); |
027c5e7a AM |
8185 | + |
8186 | + sb = dentry->d_sb; | |
027c5e7a AM |
8187 | + sigen = au_sigen(sb); |
8188 | + err = au_digen_test(parent, sigen); | |
8189 | + if (unlikely(err)) | |
8190 | + goto out; | |
8191 | + | |
8192 | + dinfo = au_di(dentry); | |
8193 | + err = au_di_realloc(dinfo, au_sbend(sb) + 1); | |
8194 | + if (unlikely(err)) | |
8195 | + goto out; | |
8196 | + ebrange = au_dbrange_test(dentry); | |
8197 | + if (!ebrange) | |
8198 | + ebrange = au_do_refresh_hdentry(dentry, parent); | |
8199 | + | |
38d290e6 | 8200 | + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) { |
027c5e7a | 8201 | + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0); |
5527c038 JR |
8202 | + if (d_really_is_positive(dentry)) { |
8203 | + inode = d_inode(dentry); | |
027c5e7a | 8204 | + err = au_refresh_hinode_self(inode); |
5527c038 | 8205 | + } |
027c5e7a AM |
8206 | + au_dbg_verify_dinode(dentry); |
8207 | + if (!err) | |
8208 | + goto out_dgen; /* success */ | |
8209 | + goto out; | |
8210 | + } | |
8211 | + | |
8212 | + /* temporary dinfo */ | |
8213 | + AuDbgDentry(dentry); | |
8214 | + err = -ENOMEM; | |
8215 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
8216 | + if (unlikely(!tmp)) | |
8217 | + goto out; | |
8218 | + au_di_swap(tmp, dinfo); | |
8219 | + /* returns the number of positive dentries */ | |
8220 | + /* | |
8221 | + * if current working dir is removed, it returns an error. | |
8222 | + * but the dentry is legal. | |
8223 | + */ | |
537831f9 | 8224 | + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0); |
027c5e7a AM |
8225 | + AuDbgDentry(dentry); |
8226 | + au_di_swap(tmp, dinfo); | |
8227 | + if (err == -ENOENT) | |
8228 | + err = 0; | |
8229 | + if (err >= 0) { | |
8230 | + /* compare/refresh by dinfo */ | |
8231 | + AuDbgDentry(dentry); | |
8232 | + err = au_refresh_by_dinfo(dentry, dinfo, tmp); | |
8233 | + au_dbg_verify_dinode(dentry); | |
8234 | + AuTraceErr(err); | |
8235 | + } | |
8236 | + au_rw_write_unlock(&tmp->di_rwsem); | |
8237 | + au_di_free(tmp); | |
8238 | + if (unlikely(err)) | |
8239 | + goto out; | |
8240 | + | |
8241 | +out_dgen: | |
8242 | + au_update_digen(dentry); | |
8243 | +out: | |
8244 | + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) { | |
523b37e3 | 8245 | + AuIOErr("failed refreshing %pd, %d\n", dentry, err); |
027c5e7a AM |
8246 | + AuDbgDentry(dentry); |
8247 | + } | |
8248 | + AuTraceErr(err); | |
8249 | + return err; | |
8250 | +} | |
8251 | + | |
b4510431 AM |
8252 | +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags, |
8253 | + struct dentry *dentry, aufs_bindex_t bindex) | |
027c5e7a AM |
8254 | +{ |
8255 | + int err, valid; | |
027c5e7a AM |
8256 | + |
8257 | + err = 0; | |
8258 | + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE)) | |
8259 | + goto out; | |
027c5e7a AM |
8260 | + |
8261 | + AuDbg("b%d\n", bindex); | |
b4510431 AM |
8262 | + /* |
8263 | + * gave up supporting LOOKUP_CREATE/OPEN for lower fs, | |
8264 | + * due to whiteout and branch permission. | |
8265 | + */ | |
8266 | + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE | |
8267 | + | LOOKUP_FOLLOW | LOOKUP_EXCL); | |
8268 | + /* it may return tri-state */ | |
8269 | + valid = h_dentry->d_op->d_revalidate(h_dentry, flags); | |
1facf9fc | 8270 | + |
8271 | + if (unlikely(valid < 0)) | |
8272 | + err = valid; | |
8273 | + else if (!valid) | |
8274 | + err = -EINVAL; | |
8275 | + | |
4f0767ce | 8276 | +out: |
1facf9fc | 8277 | + AuTraceErr(err); |
8278 | + return err; | |
8279 | +} | |
8280 | + | |
8281 | +/* todo: remove this */ | |
8282 | +static int h_d_revalidate(struct dentry *dentry, struct inode *inode, | |
b4510431 | 8283 | + unsigned int flags, int do_udba) |
1facf9fc | 8284 | +{ |
8285 | + int err; | |
8286 | + umode_t mode, h_mode; | |
8287 | + aufs_bindex_t bindex, btail, bstart, ibs, ibe; | |
38d290e6 | 8288 | + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile; |
4a4d8108 | 8289 | + struct inode *h_inode, *h_cached_inode; |
1facf9fc | 8290 | + struct dentry *h_dentry; |
8291 | + struct qstr *name, *h_name; | |
8292 | + | |
8293 | + err = 0; | |
8294 | + plus = 0; | |
8295 | + mode = 0; | |
1facf9fc | 8296 | + ibs = -1; |
8297 | + ibe = -1; | |
8298 | + unhashed = !!d_unhashed(dentry); | |
8299 | + is_root = !!IS_ROOT(dentry); | |
8300 | + name = &dentry->d_name; | |
38d290e6 | 8301 | + tmpfile = au_di(dentry)->di_tmpfile; |
1facf9fc | 8302 | + |
8303 | + /* | |
7f207e10 AM |
8304 | + * Theoretically, REVAL test should be unnecessary in case of |
8305 | + * {FS,I}NOTIFY. | |
8306 | + * But {fs,i}notify doesn't fire some necessary events, | |
1facf9fc | 8307 | + * IN_ATTRIB for atime/nlink/pageio |
1facf9fc | 8308 | + * Let's do REVAL test too. |
8309 | + */ | |
8310 | + if (do_udba && inode) { | |
8311 | + mode = (inode->i_mode & S_IFMT); | |
8312 | + plus = (inode->i_nlink > 0); | |
1facf9fc | 8313 | + ibs = au_ibstart(inode); |
8314 | + ibe = au_ibend(inode); | |
8315 | + } | |
8316 | + | |
8317 | + bstart = au_dbstart(dentry); | |
8318 | + btail = bstart; | |
8319 | + if (inode && S_ISDIR(inode->i_mode)) | |
8320 | + btail = au_dbtaildir(dentry); | |
8321 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
8322 | + h_dentry = au_h_dptr(dentry, bindex); | |
8323 | + if (!h_dentry) | |
8324 | + continue; | |
8325 | + | |
523b37e3 AM |
8326 | + AuDbg("b%d, %pd\n", bindex, h_dentry); |
8327 | + h_nfs = !!au_test_nfs(h_dentry->d_sb); | |
027c5e7a | 8328 | + spin_lock(&h_dentry->d_lock); |
1facf9fc | 8329 | + h_name = &h_dentry->d_name; |
8330 | + if (unlikely(do_udba | |
8331 | + && !is_root | |
523b37e3 AM |
8332 | + && ((!h_nfs |
8333 | + && (unhashed != !!d_unhashed(h_dentry) | |
38d290e6 JR |
8334 | + || (!tmpfile |
8335 | + && !au_qstreq(name, h_name)) | |
8336 | + )) | |
523b37e3 AM |
8337 | + || (h_nfs |
8338 | + && !(flags & LOOKUP_OPEN) | |
8339 | + && (h_dentry->d_flags | |
8340 | + & DCACHE_NFSFS_RENAMED))) | |
1facf9fc | 8341 | + )) { |
38d290e6 JR |
8342 | + int h_unhashed; |
8343 | + | |
8344 | + h_unhashed = d_unhashed(h_dentry); | |
027c5e7a | 8345 | + spin_unlock(&h_dentry->d_lock); |
38d290e6 JR |
8346 | + AuDbg("unhash 0x%x 0x%x, %pd %pd\n", |
8347 | + unhashed, h_unhashed, dentry, h_dentry); | |
1facf9fc | 8348 | + goto err; |
8349 | + } | |
027c5e7a | 8350 | + spin_unlock(&h_dentry->d_lock); |
1facf9fc | 8351 | + |
b4510431 | 8352 | + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex); |
1facf9fc | 8353 | + if (unlikely(err)) |
8354 | + /* do not goto err, to keep the errno */ | |
8355 | + break; | |
8356 | + | |
8357 | + /* todo: plink too? */ | |
8358 | + if (!do_udba) | |
8359 | + continue; | |
8360 | + | |
8361 | + /* UDBA tests */ | |
5527c038 | 8362 | + if (unlikely(!!inode != d_is_positive(h_dentry))) |
1facf9fc | 8363 | + goto err; |
8364 | + | |
5527c038 JR |
8365 | + h_inode = NULL; |
8366 | + if (d_is_positive(h_dentry)) | |
8367 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8368 | + h_plus = plus; |
8369 | + h_mode = mode; | |
8370 | + h_cached_inode = h_inode; | |
8371 | + if (h_inode) { | |
8372 | + h_mode = (h_inode->i_mode & S_IFMT); | |
8373 | + h_plus = (h_inode->i_nlink > 0); | |
8374 | + } | |
8375 | + if (inode && ibs <= bindex && bindex <= ibe) | |
8376 | + h_cached_inode = au_h_iptr(inode, bindex); | |
8377 | + | |
523b37e3 | 8378 | + if (!h_nfs) { |
38d290e6 | 8379 | + if (unlikely(plus != h_plus && !tmpfile)) |
523b37e3 AM |
8380 | + goto err; |
8381 | + } else { | |
8382 | + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED) | |
8383 | + && !is_root | |
8384 | + && !IS_ROOT(h_dentry) | |
8385 | + && unhashed != d_unhashed(h_dentry))) | |
8386 | + goto err; | |
8387 | + } | |
8388 | + if (unlikely(mode != h_mode | |
1facf9fc | 8389 | + || h_cached_inode != h_inode)) |
8390 | + goto err; | |
8391 | + continue; | |
8392 | + | |
f6b6e03d | 8393 | +err: |
1facf9fc | 8394 | + err = -EINVAL; |
8395 | + break; | |
8396 | + } | |
8397 | + | |
523b37e3 | 8398 | + AuTraceErr(err); |
1facf9fc | 8399 | + return err; |
8400 | +} | |
8401 | + | |
027c5e7a | 8402 | +/* todo: consolidate with do_refresh() and au_reval_for_attr() */ |
1facf9fc | 8403 | +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen) |
8404 | +{ | |
8405 | + int err; | |
8406 | + struct dentry *parent; | |
1facf9fc | 8407 | + |
027c5e7a | 8408 | + if (!au_digen_test(dentry, sigen)) |
1facf9fc | 8409 | + return 0; |
8410 | + | |
8411 | + parent = dget_parent(dentry); | |
8412 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 8413 | + AuDebugOn(au_digen_test(parent, sigen)); |
1facf9fc | 8414 | + au_dbg_verify_gen(parent, sigen); |
027c5e7a | 8415 | + err = au_refresh_dentry(dentry, parent); |
1facf9fc | 8416 | + di_read_unlock(parent, AuLock_IR); |
8417 | + dput(parent); | |
027c5e7a | 8418 | + AuTraceErr(err); |
1facf9fc | 8419 | + return err; |
8420 | +} | |
8421 | + | |
8422 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen) | |
8423 | +{ | |
8424 | + int err; | |
8425 | + struct dentry *d, *parent; | |
1facf9fc | 8426 | + |
027c5e7a | 8427 | + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR)) |
1facf9fc | 8428 | + return simple_reval_dpath(dentry, sigen); |
8429 | + | |
8430 | + /* slow loop, keep it simple and stupid */ | |
8431 | + /* cf: au_cpup_dirs() */ | |
8432 | + err = 0; | |
8433 | + parent = NULL; | |
027c5e7a | 8434 | + while (au_digen_test(dentry, sigen)) { |
1facf9fc | 8435 | + d = dentry; |
8436 | + while (1) { | |
8437 | + dput(parent); | |
8438 | + parent = dget_parent(d); | |
027c5e7a | 8439 | + if (!au_digen_test(parent, sigen)) |
1facf9fc | 8440 | + break; |
8441 | + d = parent; | |
8442 | + } | |
8443 | + | |
1facf9fc | 8444 | + if (d != dentry) |
027c5e7a | 8445 | + di_write_lock_child2(d); |
1facf9fc | 8446 | + |
8447 | + /* someone might update our dentry while we were sleeping */ | |
027c5e7a AM |
8448 | + if (au_digen_test(d, sigen)) { |
8449 | + /* | |
8450 | + * todo: consolidate with simple_reval_dpath(), | |
8451 | + * do_refresh() and au_reval_for_attr(). | |
8452 | + */ | |
1facf9fc | 8453 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a | 8454 | + err = au_refresh_dentry(d, parent); |
1facf9fc | 8455 | + di_read_unlock(parent, AuLock_IR); |
8456 | + } | |
8457 | + | |
8458 | + if (d != dentry) | |
8459 | + di_write_unlock(d); | |
8460 | + dput(parent); | |
8461 | + if (unlikely(err)) | |
8462 | + break; | |
8463 | + } | |
8464 | + | |
8465 | + return err; | |
8466 | +} | |
8467 | + | |
8468 | +/* | |
8469 | + * if valid returns 1, otherwise 0. | |
8470 | + */ | |
b4510431 | 8471 | +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags) |
1facf9fc | 8472 | +{ |
8473 | + int valid, err; | |
8474 | + unsigned int sigen; | |
8475 | + unsigned char do_udba; | |
8476 | + struct super_block *sb; | |
8477 | + struct inode *inode; | |
8478 | + | |
027c5e7a | 8479 | + /* todo: support rcu-walk? */ |
b4510431 | 8480 | + if (flags & LOOKUP_RCU) |
027c5e7a AM |
8481 | + return -ECHILD; |
8482 | + | |
8483 | + valid = 0; | |
8484 | + if (unlikely(!au_di(dentry))) | |
8485 | + goto out; | |
8486 | + | |
e49829fe | 8487 | + valid = 1; |
1facf9fc | 8488 | + sb = dentry->d_sb; |
e49829fe JR |
8489 | + /* |
8490 | + * todo: very ugly | |
8491 | + * i_mutex of parent dir may be held, | |
8492 | + * but we should not return 'invalid' due to busy. | |
8493 | + */ | |
8494 | + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM); | |
8495 | + if (unlikely(err)) { | |
8496 | + valid = err; | |
027c5e7a | 8497 | + AuTraceErr(err); |
e49829fe JR |
8498 | + goto out; |
8499 | + } | |
5527c038 JR |
8500 | + inode = NULL; |
8501 | + if (d_really_is_positive(dentry)) | |
8502 | + inode = d_inode(dentry); | |
c1595e42 JR |
8503 | + if (unlikely(inode && is_bad_inode(inode))) { |
8504 | + err = -EINVAL; | |
8505 | + AuTraceErr(err); | |
8506 | + goto out_dgrade; | |
8507 | + } | |
027c5e7a AM |
8508 | + if (unlikely(au_dbrange_test(dentry))) { |
8509 | + err = -EINVAL; | |
8510 | + AuTraceErr(err); | |
8511 | + goto out_dgrade; | |
1facf9fc | 8512 | + } |
027c5e7a AM |
8513 | + |
8514 | + sigen = au_sigen(sb); | |
8515 | + if (au_digen_test(dentry, sigen)) { | |
1facf9fc | 8516 | + AuDebugOn(IS_ROOT(dentry)); |
027c5e7a AM |
8517 | + err = au_reval_dpath(dentry, sigen); |
8518 | + if (unlikely(err)) { | |
8519 | + AuTraceErr(err); | |
1facf9fc | 8520 | + goto out_dgrade; |
027c5e7a | 8521 | + } |
1facf9fc | 8522 | + } |
8523 | + di_downgrade_lock(dentry, AuLock_IR); | |
8524 | + | |
1facf9fc | 8525 | + err = -EINVAL; |
c1595e42 | 8526 | + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY)) |
523b37e3 | 8527 | + && inode |
38d290e6 | 8528 | + && !(inode->i_state && I_LINKABLE) |
523b37e3 | 8529 | + && (IS_DEADDIR(inode) || !inode->i_nlink)) |
027c5e7a AM |
8530 | + goto out_inval; |
8531 | + | |
1facf9fc | 8532 | + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE); |
8533 | + if (do_udba && inode) { | |
8534 | + aufs_bindex_t bstart = au_ibstart(inode); | |
027c5e7a | 8535 | + struct inode *h_inode; |
1facf9fc | 8536 | + |
027c5e7a AM |
8537 | + if (bstart >= 0) { |
8538 | + h_inode = au_h_iptr(inode, bstart); | |
8539 | + if (h_inode && au_test_higen(inode, h_inode)) | |
8540 | + goto out_inval; | |
8541 | + } | |
1facf9fc | 8542 | + } |
8543 | + | |
b4510431 | 8544 | + err = h_d_revalidate(dentry, inode, flags, do_udba); |
027c5e7a | 8545 | + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) { |
1facf9fc | 8546 | + err = -EIO; |
523b37e3 AM |
8547 | + AuDbg("both of real entry and whiteout found, %p, err %d\n", |
8548 | + dentry, err); | |
027c5e7a | 8549 | + } |
e49829fe | 8550 | + goto out_inval; |
1facf9fc | 8551 | + |
4f0767ce | 8552 | +out_dgrade: |
1facf9fc | 8553 | + di_downgrade_lock(dentry, AuLock_IR); |
e49829fe | 8554 | +out_inval: |
1facf9fc | 8555 | + aufs_read_unlock(dentry, AuLock_IR); |
8556 | + AuTraceErr(err); | |
8557 | + valid = !err; | |
e49829fe | 8558 | +out: |
027c5e7a | 8559 | + if (!valid) { |
523b37e3 | 8560 | + AuDbg("%pd invalid, %d\n", dentry, valid); |
027c5e7a AM |
8561 | + d_drop(dentry); |
8562 | + } | |
1facf9fc | 8563 | + return valid; |
8564 | +} | |
8565 | + | |
8566 | +static void aufs_d_release(struct dentry *dentry) | |
8567 | +{ | |
027c5e7a | 8568 | + if (au_di(dentry)) { |
4a4d8108 AM |
8569 | + au_di_fin(dentry); |
8570 | + au_hn_di_reinit(dentry); | |
1facf9fc | 8571 | + } |
1facf9fc | 8572 | +} |
8573 | + | |
4a4d8108 | 8574 | +const struct dentry_operations aufs_dop = { |
c06a8ce3 AM |
8575 | + .d_revalidate = aufs_d_revalidate, |
8576 | + .d_weak_revalidate = aufs_d_revalidate, | |
8577 | + .d_release = aufs_d_release | |
1facf9fc | 8578 | +}; |
7f207e10 AM |
8579 | diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h |
8580 | --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 8581 | +++ linux/fs/aufs/dentry.h 2015-06-28 17:35:44.348050491 +0200 |
076b876e | 8582 | @@ -0,0 +1,233 @@ |
1facf9fc | 8583 | +/* |
2000de60 | 8584 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 8585 | + * |
8586 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8587 | + * it under the terms of the GNU General Public License as published by | |
8588 | + * the Free Software Foundation; either version 2 of the License, or | |
8589 | + * (at your option) any later version. | |
dece6358 AM |
8590 | + * |
8591 | + * This program is distributed in the hope that it will be useful, | |
8592 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8593 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8594 | + * GNU General Public License for more details. | |
8595 | + * | |
8596 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8597 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8598 | + */ |
8599 | + | |
8600 | +/* | |
8601 | + * lookup and dentry operations | |
8602 | + */ | |
8603 | + | |
8604 | +#ifndef __AUFS_DENTRY_H__ | |
8605 | +#define __AUFS_DENTRY_H__ | |
8606 | + | |
8607 | +#ifdef __KERNEL__ | |
8608 | + | |
dece6358 | 8609 | +#include <linux/dcache.h> |
1facf9fc | 8610 | +#include "rwsem.h" |
8611 | + | |
1facf9fc | 8612 | +struct au_hdentry { |
8613 | + struct dentry *hd_dentry; | |
027c5e7a | 8614 | + aufs_bindex_t hd_id; |
1facf9fc | 8615 | +}; |
8616 | + | |
8617 | +struct au_dinfo { | |
8618 | + atomic_t di_generation; | |
8619 | + | |
dece6358 | 8620 | + struct au_rwsem di_rwsem; |
1facf9fc | 8621 | + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq; |
38d290e6 | 8622 | + unsigned char di_tmpfile; /* to allow the different name */ |
1facf9fc | 8623 | + struct au_hdentry *di_hdentry; |
4a4d8108 | 8624 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 8625 | + |
8626 | +/* ---------------------------------------------------------------------- */ | |
8627 | + | |
8628 | +/* dentry.c */ | |
4a4d8108 | 8629 | +extern const struct dentry_operations aufs_dop; |
1facf9fc | 8630 | +struct au_branch; |
076b876e | 8631 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent); |
1facf9fc | 8632 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, |
8633 | + struct dentry *h_parent, struct au_branch *br); | |
8634 | + | |
537831f9 | 8635 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type); |
86dc4139 | 8636 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh); |
027c5e7a | 8637 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent); |
1facf9fc | 8638 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen); |
8639 | + | |
8640 | +/* dinfo.c */ | |
4a4d8108 | 8641 | +void au_di_init_once(void *_di); |
027c5e7a AM |
8642 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc); |
8643 | +void au_di_free(struct au_dinfo *dinfo); | |
8644 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b); | |
8645 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src); | |
4a4d8108 AM |
8646 | +int au_di_init(struct dentry *dentry); |
8647 | +void au_di_fin(struct dentry *dentry); | |
1facf9fc | 8648 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr); |
8649 | + | |
8650 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc); | |
8651 | +void di_read_unlock(struct dentry *d, int flags); | |
8652 | +void di_downgrade_lock(struct dentry *d, int flags); | |
8653 | +void di_write_lock(struct dentry *d, unsigned int lsc); | |
8654 | +void di_write_unlock(struct dentry *d); | |
8655 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir); | |
8656 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir); | |
8657 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2); | |
8658 | + | |
8659 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex); | |
2cbb1c4b | 8660 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex); |
1facf9fc | 8661 | +aufs_bindex_t au_dbtail(struct dentry *dentry); |
8662 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry); | |
8663 | + | |
8664 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
8665 | + struct dentry *h_dentry); | |
027c5e7a AM |
8666 | +int au_digen_test(struct dentry *dentry, unsigned int sigen); |
8667 | +int au_dbrange_test(struct dentry *dentry); | |
1facf9fc | 8668 | +void au_update_digen(struct dentry *dentry); |
8669 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero); | |
8670 | +void au_update_dbstart(struct dentry *dentry); | |
8671 | +void au_update_dbend(struct dentry *dentry); | |
8672 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry); | |
8673 | + | |
8674 | +/* ---------------------------------------------------------------------- */ | |
8675 | + | |
8676 | +static inline struct au_dinfo *au_di(struct dentry *dentry) | |
8677 | +{ | |
8678 | + return dentry->d_fsdata; | |
8679 | +} | |
8680 | + | |
8681 | +/* ---------------------------------------------------------------------- */ | |
8682 | + | |
8683 | +/* lock subclass for dinfo */ | |
8684 | +enum { | |
8685 | + AuLsc_DI_CHILD, /* child first */ | |
4a4d8108 | 8686 | + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */ |
1facf9fc | 8687 | + AuLsc_DI_CHILD3, /* copyup dirs */ |
8688 | + AuLsc_DI_PARENT, | |
8689 | + AuLsc_DI_PARENT2, | |
027c5e7a AM |
8690 | + AuLsc_DI_PARENT3, |
8691 | + AuLsc_DI_TMP /* temp for replacing dinfo */ | |
1facf9fc | 8692 | +}; |
8693 | + | |
8694 | +/* | |
8695 | + * di_read_lock_child, di_write_lock_child, | |
8696 | + * di_read_lock_child2, di_write_lock_child2, | |
8697 | + * di_read_lock_child3, di_write_lock_child3, | |
8698 | + * di_read_lock_parent, di_write_lock_parent, | |
8699 | + * di_read_lock_parent2, di_write_lock_parent2, | |
8700 | + * di_read_lock_parent3, di_write_lock_parent3, | |
8701 | + */ | |
8702 | +#define AuReadLockFunc(name, lsc) \ | |
8703 | +static inline void di_read_lock_##name(struct dentry *d, int flags) \ | |
8704 | +{ di_read_lock(d, flags, AuLsc_DI_##lsc); } | |
8705 | + | |
8706 | +#define AuWriteLockFunc(name, lsc) \ | |
8707 | +static inline void di_write_lock_##name(struct dentry *d) \ | |
8708 | +{ di_write_lock(d, AuLsc_DI_##lsc); } | |
8709 | + | |
8710 | +#define AuRWLockFuncs(name, lsc) \ | |
8711 | + AuReadLockFunc(name, lsc) \ | |
8712 | + AuWriteLockFunc(name, lsc) | |
8713 | + | |
8714 | +AuRWLockFuncs(child, CHILD); | |
8715 | +AuRWLockFuncs(child2, CHILD2); | |
8716 | +AuRWLockFuncs(child3, CHILD3); | |
8717 | +AuRWLockFuncs(parent, PARENT); | |
8718 | +AuRWLockFuncs(parent2, PARENT2); | |
8719 | +AuRWLockFuncs(parent3, PARENT3); | |
8720 | + | |
8721 | +#undef AuReadLockFunc | |
8722 | +#undef AuWriteLockFunc | |
8723 | +#undef AuRWLockFuncs | |
8724 | + | |
8725 | +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem) | |
dece6358 AM |
8726 | +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem) |
8727 | +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem) | |
1facf9fc | 8728 | + |
8729 | +/* ---------------------------------------------------------------------- */ | |
8730 | + | |
8731 | +/* todo: memory barrier? */ | |
8732 | +static inline unsigned int au_digen(struct dentry *d) | |
8733 | +{ | |
8734 | + return atomic_read(&au_di(d)->di_generation); | |
8735 | +} | |
8736 | + | |
8737 | +static inline void au_h_dentry_init(struct au_hdentry *hdentry) | |
8738 | +{ | |
8739 | + hdentry->hd_dentry = NULL; | |
8740 | +} | |
8741 | + | |
8742 | +static inline void au_hdput(struct au_hdentry *hd) | |
8743 | +{ | |
4a4d8108 AM |
8744 | + if (hd) |
8745 | + dput(hd->hd_dentry); | |
1facf9fc | 8746 | +} |
8747 | + | |
8748 | +static inline aufs_bindex_t au_dbstart(struct dentry *dentry) | |
8749 | +{ | |
1308ab2a | 8750 | + DiMustAnyLock(dentry); |
1facf9fc | 8751 | + return au_di(dentry)->di_bstart; |
8752 | +} | |
8753 | + | |
8754 | +static inline aufs_bindex_t au_dbend(struct dentry *dentry) | |
8755 | +{ | |
1308ab2a | 8756 | + DiMustAnyLock(dentry); |
1facf9fc | 8757 | + return au_di(dentry)->di_bend; |
8758 | +} | |
8759 | + | |
8760 | +static inline aufs_bindex_t au_dbwh(struct dentry *dentry) | |
8761 | +{ | |
1308ab2a | 8762 | + DiMustAnyLock(dentry); |
1facf9fc | 8763 | + return au_di(dentry)->di_bwh; |
8764 | +} | |
8765 | + | |
8766 | +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry) | |
8767 | +{ | |
1308ab2a | 8768 | + DiMustAnyLock(dentry); |
1facf9fc | 8769 | + return au_di(dentry)->di_bdiropq; |
8770 | +} | |
8771 | + | |
8772 | +/* todo: hard/soft set? */ | |
8773 | +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex) | |
8774 | +{ | |
1308ab2a | 8775 | + DiMustWriteLock(dentry); |
1facf9fc | 8776 | + au_di(dentry)->di_bstart = bindex; |
8777 | +} | |
8778 | + | |
8779 | +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex) | |
8780 | +{ | |
1308ab2a | 8781 | + DiMustWriteLock(dentry); |
1facf9fc | 8782 | + au_di(dentry)->di_bend = bindex; |
8783 | +} | |
8784 | + | |
8785 | +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex) | |
8786 | +{ | |
1308ab2a | 8787 | + DiMustWriteLock(dentry); |
1facf9fc | 8788 | + /* dbwh can be outside of bstart - bend range */ |
8789 | + au_di(dentry)->di_bwh = bindex; | |
8790 | +} | |
8791 | + | |
8792 | +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex) | |
8793 | +{ | |
1308ab2a | 8794 | + DiMustWriteLock(dentry); |
1facf9fc | 8795 | + au_di(dentry)->di_bdiropq = bindex; |
8796 | +} | |
8797 | + | |
8798 | +/* ---------------------------------------------------------------------- */ | |
8799 | + | |
4a4d8108 | 8800 | +#ifdef CONFIG_AUFS_HNOTIFY |
1facf9fc | 8801 | +static inline void au_digen_dec(struct dentry *d) |
8802 | +{ | |
e49829fe | 8803 | + atomic_dec(&au_di(d)->di_generation); |
1facf9fc | 8804 | +} |
8805 | + | |
4a4d8108 | 8806 | +static inline void au_hn_di_reinit(struct dentry *dentry) |
1facf9fc | 8807 | +{ |
8808 | + dentry->d_fsdata = NULL; | |
8809 | +} | |
8810 | +#else | |
4a4d8108 AM |
8811 | +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused) |
8812 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
1facf9fc | 8813 | + |
8814 | +#endif /* __KERNEL__ */ | |
8815 | +#endif /* __AUFS_DENTRY_H__ */ | |
7f207e10 AM |
8816 | diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c |
8817 | --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
8818 | +++ linux/fs/aufs/dinfo.c 2015-06-28 17:36:09.025073697 +0200 |
8819 | @@ -0,0 +1,550 @@ | |
1facf9fc | 8820 | +/* |
2000de60 | 8821 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 8822 | + * |
8823 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8824 | + * it under the terms of the GNU General Public License as published by | |
8825 | + * the Free Software Foundation; either version 2 of the License, or | |
8826 | + * (at your option) any later version. | |
dece6358 AM |
8827 | + * |
8828 | + * This program is distributed in the hope that it will be useful, | |
8829 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8830 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8831 | + * GNU General Public License for more details. | |
8832 | + * | |
8833 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8834 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8835 | + */ |
8836 | + | |
8837 | +/* | |
8838 | + * dentry private data | |
8839 | + */ | |
8840 | + | |
8841 | +#include "aufs.h" | |
8842 | + | |
e49829fe | 8843 | +void au_di_init_once(void *_dinfo) |
4a4d8108 | 8844 | +{ |
e49829fe JR |
8845 | + struct au_dinfo *dinfo = _dinfo; |
8846 | + static struct lock_class_key aufs_di; | |
4a4d8108 | 8847 | + |
e49829fe JR |
8848 | + au_rw_init(&dinfo->di_rwsem); |
8849 | + au_rw_class(&dinfo->di_rwsem, &aufs_di); | |
4a4d8108 AM |
8850 | +} |
8851 | + | |
027c5e7a | 8852 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc) |
1facf9fc | 8853 | +{ |
8854 | + struct au_dinfo *dinfo; | |
027c5e7a | 8855 | + int nbr, i; |
1facf9fc | 8856 | + |
8857 | + dinfo = au_cache_alloc_dinfo(); | |
8858 | + if (unlikely(!dinfo)) | |
8859 | + goto out; | |
8860 | + | |
1facf9fc | 8861 | + nbr = au_sbend(sb) + 1; |
8862 | + if (nbr <= 0) | |
8863 | + nbr = 1; | |
8864 | + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS); | |
027c5e7a AM |
8865 | + if (dinfo->di_hdentry) { |
8866 | + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc); | |
8867 | + dinfo->di_bstart = -1; | |
8868 | + dinfo->di_bend = -1; | |
8869 | + dinfo->di_bwh = -1; | |
8870 | + dinfo->di_bdiropq = -1; | |
38d290e6 | 8871 | + dinfo->di_tmpfile = 0; |
027c5e7a AM |
8872 | + for (i = 0; i < nbr; i++) |
8873 | + dinfo->di_hdentry[i].hd_id = -1; | |
8874 | + goto out; | |
8875 | + } | |
1facf9fc | 8876 | + |
1facf9fc | 8877 | + au_cache_free_dinfo(dinfo); |
027c5e7a AM |
8878 | + dinfo = NULL; |
8879 | + | |
4f0767ce | 8880 | +out: |
027c5e7a | 8881 | + return dinfo; |
1facf9fc | 8882 | +} |
8883 | + | |
027c5e7a | 8884 | +void au_di_free(struct au_dinfo *dinfo) |
4a4d8108 | 8885 | +{ |
4a4d8108 AM |
8886 | + struct au_hdentry *p; |
8887 | + aufs_bindex_t bend, bindex; | |
8888 | + | |
8889 | + /* dentry may not be revalidated */ | |
027c5e7a | 8890 | + bindex = dinfo->di_bstart; |
4a4d8108 | 8891 | + if (bindex >= 0) { |
027c5e7a AM |
8892 | + bend = dinfo->di_bend; |
8893 | + p = dinfo->di_hdentry + bindex; | |
4a4d8108 AM |
8894 | + while (bindex++ <= bend) |
8895 | + au_hdput(p++); | |
8896 | + } | |
027c5e7a AM |
8897 | + kfree(dinfo->di_hdentry); |
8898 | + au_cache_free_dinfo(dinfo); | |
8899 | +} | |
8900 | + | |
8901 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b) | |
8902 | +{ | |
8903 | + struct au_hdentry *p; | |
8904 | + aufs_bindex_t bi; | |
8905 | + | |
8906 | + AuRwMustWriteLock(&a->di_rwsem); | |
8907 | + AuRwMustWriteLock(&b->di_rwsem); | |
8908 | + | |
8909 | +#define DiSwap(v, name) \ | |
8910 | + do { \ | |
8911 | + v = a->di_##name; \ | |
8912 | + a->di_##name = b->di_##name; \ | |
8913 | + b->di_##name = v; \ | |
8914 | + } while (0) | |
8915 | + | |
8916 | + DiSwap(p, hdentry); | |
8917 | + DiSwap(bi, bstart); | |
8918 | + DiSwap(bi, bend); | |
8919 | + DiSwap(bi, bwh); | |
8920 | + DiSwap(bi, bdiropq); | |
8921 | + /* smp_mb(); */ | |
8922 | + | |
8923 | +#undef DiSwap | |
8924 | +} | |
8925 | + | |
8926 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src) | |
8927 | +{ | |
8928 | + AuRwMustWriteLock(&dst->di_rwsem); | |
8929 | + AuRwMustWriteLock(&src->di_rwsem); | |
8930 | + | |
8931 | + dst->di_bstart = src->di_bstart; | |
8932 | + dst->di_bend = src->di_bend; | |
8933 | + dst->di_bwh = src->di_bwh; | |
8934 | + dst->di_bdiropq = src->di_bdiropq; | |
8935 | + /* smp_mb(); */ | |
8936 | +} | |
8937 | + | |
8938 | +int au_di_init(struct dentry *dentry) | |
8939 | +{ | |
8940 | + int err; | |
8941 | + struct super_block *sb; | |
8942 | + struct au_dinfo *dinfo; | |
8943 | + | |
8944 | + err = 0; | |
8945 | + sb = dentry->d_sb; | |
8946 | + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD); | |
8947 | + if (dinfo) { | |
8948 | + atomic_set(&dinfo->di_generation, au_sigen(sb)); | |
8949 | + /* smp_mb(); */ /* atomic_set */ | |
8950 | + dentry->d_fsdata = dinfo; | |
8951 | + } else | |
8952 | + err = -ENOMEM; | |
8953 | + | |
8954 | + return err; | |
8955 | +} | |
8956 | + | |
8957 | +void au_di_fin(struct dentry *dentry) | |
8958 | +{ | |
8959 | + struct au_dinfo *dinfo; | |
8960 | + | |
8961 | + dinfo = au_di(dentry); | |
8962 | + AuRwDestroy(&dinfo->di_rwsem); | |
8963 | + au_di_free(dinfo); | |
4a4d8108 AM |
8964 | +} |
8965 | + | |
1facf9fc | 8966 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr) |
8967 | +{ | |
8968 | + int err, sz; | |
8969 | + struct au_hdentry *hdp; | |
8970 | + | |
1308ab2a | 8971 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
8972 | + | |
1facf9fc | 8973 | + err = -ENOMEM; |
8974 | + sz = sizeof(*hdp) * (dinfo->di_bend + 1); | |
8975 | + if (!sz) | |
8976 | + sz = sizeof(*hdp); | |
8977 | + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS); | |
8978 | + if (hdp) { | |
8979 | + dinfo->di_hdentry = hdp; | |
8980 | + err = 0; | |
8981 | + } | |
8982 | + | |
8983 | + return err; | |
8984 | +} | |
8985 | + | |
8986 | +/* ---------------------------------------------------------------------- */ | |
8987 | + | |
8988 | +static void do_ii_write_lock(struct inode *inode, unsigned int lsc) | |
8989 | +{ | |
8990 | + switch (lsc) { | |
8991 | + case AuLsc_DI_CHILD: | |
8992 | + ii_write_lock_child(inode); | |
8993 | + break; | |
8994 | + case AuLsc_DI_CHILD2: | |
8995 | + ii_write_lock_child2(inode); | |
8996 | + break; | |
8997 | + case AuLsc_DI_CHILD3: | |
8998 | + ii_write_lock_child3(inode); | |
8999 | + break; | |
9000 | + case AuLsc_DI_PARENT: | |
9001 | + ii_write_lock_parent(inode); | |
9002 | + break; | |
9003 | + case AuLsc_DI_PARENT2: | |
9004 | + ii_write_lock_parent2(inode); | |
9005 | + break; | |
9006 | + case AuLsc_DI_PARENT3: | |
9007 | + ii_write_lock_parent3(inode); | |
9008 | + break; | |
9009 | + default: | |
9010 | + BUG(); | |
9011 | + } | |
9012 | +} | |
9013 | + | |
9014 | +static void do_ii_read_lock(struct inode *inode, unsigned int lsc) | |
9015 | +{ | |
9016 | + switch (lsc) { | |
9017 | + case AuLsc_DI_CHILD: | |
9018 | + ii_read_lock_child(inode); | |
9019 | + break; | |
9020 | + case AuLsc_DI_CHILD2: | |
9021 | + ii_read_lock_child2(inode); | |
9022 | + break; | |
9023 | + case AuLsc_DI_CHILD3: | |
9024 | + ii_read_lock_child3(inode); | |
9025 | + break; | |
9026 | + case AuLsc_DI_PARENT: | |
9027 | + ii_read_lock_parent(inode); | |
9028 | + break; | |
9029 | + case AuLsc_DI_PARENT2: | |
9030 | + ii_read_lock_parent2(inode); | |
9031 | + break; | |
9032 | + case AuLsc_DI_PARENT3: | |
9033 | + ii_read_lock_parent3(inode); | |
9034 | + break; | |
9035 | + default: | |
9036 | + BUG(); | |
9037 | + } | |
9038 | +} | |
9039 | + | |
9040 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc) | |
9041 | +{ | |
5527c038 JR |
9042 | + struct inode *inode; |
9043 | + | |
dece6358 | 9044 | + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9045 | + if (d_really_is_positive(d)) { |
9046 | + inode = d_inode(d); | |
1facf9fc | 9047 | + if (au_ftest_lock(flags, IW)) |
5527c038 | 9048 | + do_ii_write_lock(inode, lsc); |
1facf9fc | 9049 | + else if (au_ftest_lock(flags, IR)) |
5527c038 | 9050 | + do_ii_read_lock(inode, lsc); |
1facf9fc | 9051 | + } |
9052 | +} | |
9053 | + | |
9054 | +void di_read_unlock(struct dentry *d, int flags) | |
9055 | +{ | |
5527c038 JR |
9056 | + struct inode *inode; |
9057 | + | |
9058 | + if (d_really_is_positive(d)) { | |
9059 | + inode = d_inode(d); | |
027c5e7a AM |
9060 | + if (au_ftest_lock(flags, IW)) { |
9061 | + au_dbg_verify_dinode(d); | |
5527c038 | 9062 | + ii_write_unlock(inode); |
027c5e7a AM |
9063 | + } else if (au_ftest_lock(flags, IR)) { |
9064 | + au_dbg_verify_dinode(d); | |
5527c038 | 9065 | + ii_read_unlock(inode); |
027c5e7a | 9066 | + } |
1facf9fc | 9067 | + } |
dece6358 | 9068 | + au_rw_read_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9069 | +} |
9070 | + | |
9071 | +void di_downgrade_lock(struct dentry *d, int flags) | |
9072 | +{ | |
5527c038 JR |
9073 | + if (d_really_is_positive(d) && au_ftest_lock(flags, IR)) |
9074 | + ii_downgrade_lock(d_inode(d)); | |
dece6358 | 9075 | + au_rw_dgrade_lock(&au_di(d)->di_rwsem); |
1facf9fc | 9076 | +} |
9077 | + | |
9078 | +void di_write_lock(struct dentry *d, unsigned int lsc) | |
9079 | +{ | |
dece6358 | 9080 | + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9081 | + if (d_really_is_positive(d)) |
9082 | + do_ii_write_lock(d_inode(d), lsc); | |
1facf9fc | 9083 | +} |
9084 | + | |
9085 | +void di_write_unlock(struct dentry *d) | |
9086 | +{ | |
027c5e7a | 9087 | + au_dbg_verify_dinode(d); |
5527c038 JR |
9088 | + if (d_really_is_positive(d)) |
9089 | + ii_write_unlock(d_inode(d)); | |
dece6358 | 9090 | + au_rw_write_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9091 | +} |
9092 | + | |
9093 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir) | |
9094 | +{ | |
9095 | + AuDebugOn(d1 == d2 | |
5527c038 | 9096 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9097 | + || d1->d_sb != d2->d_sb); |
9098 | + | |
9099 | + if (isdir && au_test_subdir(d1, d2)) { | |
9100 | + di_write_lock_child(d1); | |
9101 | + di_write_lock_child2(d2); | |
9102 | + } else { | |
9103 | + /* there should be no races */ | |
9104 | + di_write_lock_child(d2); | |
9105 | + di_write_lock_child2(d1); | |
9106 | + } | |
9107 | +} | |
9108 | + | |
9109 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir) | |
9110 | +{ | |
9111 | + AuDebugOn(d1 == d2 | |
5527c038 | 9112 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9113 | + || d1->d_sb != d2->d_sb); |
9114 | + | |
9115 | + if (isdir && au_test_subdir(d1, d2)) { | |
9116 | + di_write_lock_parent(d1); | |
9117 | + di_write_lock_parent2(d2); | |
9118 | + } else { | |
9119 | + /* there should be no races */ | |
9120 | + di_write_lock_parent(d2); | |
9121 | + di_write_lock_parent2(d1); | |
9122 | + } | |
9123 | +} | |
9124 | + | |
9125 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2) | |
9126 | +{ | |
9127 | + di_write_unlock(d1); | |
5527c038 | 9128 | + if (d_inode(d1) == d_inode(d2)) |
dece6358 | 9129 | + au_rw_write_unlock(&au_di(d2)->di_rwsem); |
1facf9fc | 9130 | + else |
9131 | + di_write_unlock(d2); | |
9132 | +} | |
9133 | + | |
9134 | +/* ---------------------------------------------------------------------- */ | |
9135 | + | |
9136 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex) | |
9137 | +{ | |
9138 | + struct dentry *d; | |
9139 | + | |
1308ab2a | 9140 | + DiMustAnyLock(dentry); |
9141 | + | |
1facf9fc | 9142 | + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry)) |
9143 | + return NULL; | |
9144 | + AuDebugOn(bindex < 0); | |
9145 | + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry; | |
c1595e42 | 9146 | + AuDebugOn(d && au_dcount(d) <= 0); |
1facf9fc | 9147 | + return d; |
9148 | +} | |
9149 | + | |
2cbb1c4b JR |
9150 | +/* |
9151 | + * extended version of au_h_dptr(). | |
38d290e6 JR |
9152 | + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or |
9153 | + * error. | |
2cbb1c4b JR |
9154 | + */ |
9155 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex) | |
9156 | +{ | |
9157 | + struct dentry *h_dentry; | |
9158 | + struct inode *inode, *h_inode; | |
9159 | + | |
5527c038 | 9160 | + AuDebugOn(d_really_is_negative(dentry)); |
2cbb1c4b JR |
9161 | + |
9162 | + h_dentry = NULL; | |
9163 | + if (au_dbstart(dentry) <= bindex | |
9164 | + && bindex <= au_dbend(dentry)) | |
9165 | + h_dentry = au_h_dptr(dentry, bindex); | |
38d290e6 | 9166 | + if (h_dentry && !au_d_linkable(h_dentry)) { |
2cbb1c4b JR |
9167 | + dget(h_dentry); |
9168 | + goto out; /* success */ | |
9169 | + } | |
9170 | + | |
5527c038 | 9171 | + inode = d_inode(dentry); |
2cbb1c4b JR |
9172 | + AuDebugOn(bindex < au_ibstart(inode)); |
9173 | + AuDebugOn(au_ibend(inode) < bindex); | |
9174 | + h_inode = au_h_iptr(inode, bindex); | |
9175 | + h_dentry = d_find_alias(h_inode); | |
9176 | + if (h_dentry) { | |
9177 | + if (!IS_ERR(h_dentry)) { | |
38d290e6 | 9178 | + if (!au_d_linkable(h_dentry)) |
2cbb1c4b JR |
9179 | + goto out; /* success */ |
9180 | + dput(h_dentry); | |
9181 | + } else | |
9182 | + goto out; | |
9183 | + } | |
9184 | + | |
9185 | + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) { | |
9186 | + h_dentry = au_plink_lkup(inode, bindex); | |
9187 | + AuDebugOn(!h_dentry); | |
9188 | + if (!IS_ERR(h_dentry)) { | |
9189 | + if (!au_d_hashed_positive(h_dentry)) | |
9190 | + goto out; /* success */ | |
9191 | + dput(h_dentry); | |
9192 | + h_dentry = NULL; | |
9193 | + } | |
9194 | + } | |
9195 | + | |
9196 | +out: | |
9197 | + AuDbgDentry(h_dentry); | |
9198 | + return h_dentry; | |
9199 | +} | |
9200 | + | |
1facf9fc | 9201 | +aufs_bindex_t au_dbtail(struct dentry *dentry) |
9202 | +{ | |
9203 | + aufs_bindex_t bend, bwh; | |
9204 | + | |
9205 | + bend = au_dbend(dentry); | |
9206 | + if (0 <= bend) { | |
9207 | + bwh = au_dbwh(dentry); | |
9208 | + if (!bwh) | |
9209 | + return bwh; | |
9210 | + if (0 < bwh && bwh < bend) | |
9211 | + return bwh - 1; | |
9212 | + } | |
9213 | + return bend; | |
9214 | +} | |
9215 | + | |
9216 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry) | |
9217 | +{ | |
9218 | + aufs_bindex_t bend, bopq; | |
9219 | + | |
9220 | + bend = au_dbtail(dentry); | |
9221 | + if (0 <= bend) { | |
9222 | + bopq = au_dbdiropq(dentry); | |
9223 | + if (0 <= bopq && bopq < bend) | |
9224 | + bend = bopq; | |
9225 | + } | |
9226 | + return bend; | |
9227 | +} | |
9228 | + | |
9229 | +/* ---------------------------------------------------------------------- */ | |
9230 | + | |
9231 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9232 | + struct dentry *h_dentry) | |
9233 | +{ | |
9234 | + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex; | |
027c5e7a | 9235 | + struct au_branch *br; |
1facf9fc | 9236 | + |
1308ab2a | 9237 | + DiMustWriteLock(dentry); |
9238 | + | |
4a4d8108 | 9239 | + au_hdput(hd); |
1facf9fc | 9240 | + hd->hd_dentry = h_dentry; |
027c5e7a AM |
9241 | + if (h_dentry) { |
9242 | + br = au_sbr(dentry->d_sb, bindex); | |
9243 | + hd->hd_id = br->br_id; | |
9244 | + } | |
9245 | +} | |
9246 | + | |
9247 | +int au_dbrange_test(struct dentry *dentry) | |
9248 | +{ | |
9249 | + int err; | |
9250 | + aufs_bindex_t bstart, bend; | |
9251 | + | |
9252 | + err = 0; | |
9253 | + bstart = au_dbstart(dentry); | |
9254 | + bend = au_dbend(dentry); | |
9255 | + if (bstart >= 0) | |
9256 | + AuDebugOn(bend < 0 && bstart > bend); | |
9257 | + else { | |
9258 | + err = -EIO; | |
9259 | + AuDebugOn(bend >= 0); | |
9260 | + } | |
9261 | + | |
9262 | + return err; | |
9263 | +} | |
9264 | + | |
9265 | +int au_digen_test(struct dentry *dentry, unsigned int sigen) | |
9266 | +{ | |
9267 | + int err; | |
9268 | + | |
9269 | + err = 0; | |
9270 | + if (unlikely(au_digen(dentry) != sigen | |
5527c038 | 9271 | + || au_iigen_test(d_inode(dentry), sigen))) |
027c5e7a AM |
9272 | + err = -EIO; |
9273 | + | |
9274 | + return err; | |
1facf9fc | 9275 | +} |
9276 | + | |
9277 | +void au_update_digen(struct dentry *dentry) | |
9278 | +{ | |
9279 | + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb)); | |
9280 | + /* smp_mb(); */ /* atomic_set */ | |
9281 | +} | |
9282 | + | |
9283 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero) | |
9284 | +{ | |
9285 | + struct au_dinfo *dinfo; | |
9286 | + struct dentry *h_d; | |
4a4d8108 | 9287 | + struct au_hdentry *hdp; |
1facf9fc | 9288 | + |
1308ab2a | 9289 | + DiMustWriteLock(dentry); |
9290 | + | |
1facf9fc | 9291 | + dinfo = au_di(dentry); |
9292 | + if (!dinfo || dinfo->di_bstart < 0) | |
9293 | + return; | |
9294 | + | |
4a4d8108 | 9295 | + hdp = dinfo->di_hdentry; |
1facf9fc | 9296 | + if (do_put_zero) { |
9297 | + aufs_bindex_t bindex, bend; | |
9298 | + | |
9299 | + bend = dinfo->di_bend; | |
9300 | + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) { | |
4a4d8108 | 9301 | + h_d = hdp[0 + bindex].hd_dentry; |
5527c038 | 9302 | + if (h_d && d_is_negative(h_d)) |
1facf9fc | 9303 | + au_set_h_dptr(dentry, bindex, NULL); |
9304 | + } | |
9305 | + } | |
9306 | + | |
9307 | + dinfo->di_bstart = -1; | |
9308 | + while (++dinfo->di_bstart <= dinfo->di_bend) | |
4a4d8108 | 9309 | + if (hdp[0 + dinfo->di_bstart].hd_dentry) |
1facf9fc | 9310 | + break; |
9311 | + if (dinfo->di_bstart > dinfo->di_bend) { | |
9312 | + dinfo->di_bstart = -1; | |
9313 | + dinfo->di_bend = -1; | |
9314 | + return; | |
9315 | + } | |
9316 | + | |
9317 | + dinfo->di_bend++; | |
9318 | + while (0 <= --dinfo->di_bend) | |
4a4d8108 | 9319 | + if (hdp[0 + dinfo->di_bend].hd_dentry) |
1facf9fc | 9320 | + break; |
9321 | + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0); | |
9322 | +} | |
9323 | + | |
9324 | +void au_update_dbstart(struct dentry *dentry) | |
9325 | +{ | |
9326 | + aufs_bindex_t bindex, bend; | |
9327 | + struct dentry *h_dentry; | |
9328 | + | |
9329 | + bend = au_dbend(dentry); | |
9330 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) { | |
9331 | + h_dentry = au_h_dptr(dentry, bindex); | |
9332 | + if (!h_dentry) | |
9333 | + continue; | |
5527c038 | 9334 | + if (d_is_positive(h_dentry)) { |
1facf9fc | 9335 | + au_set_dbstart(dentry, bindex); |
9336 | + return; | |
9337 | + } | |
9338 | + au_set_h_dptr(dentry, bindex, NULL); | |
9339 | + } | |
9340 | +} | |
9341 | + | |
9342 | +void au_update_dbend(struct dentry *dentry) | |
9343 | +{ | |
9344 | + aufs_bindex_t bindex, bstart; | |
9345 | + struct dentry *h_dentry; | |
9346 | + | |
9347 | + bstart = au_dbstart(dentry); | |
7f207e10 | 9348 | + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) { |
1facf9fc | 9349 | + h_dentry = au_h_dptr(dentry, bindex); |
9350 | + if (!h_dentry) | |
9351 | + continue; | |
5527c038 | 9352 | + if (d_is_positive(h_dentry)) { |
1facf9fc | 9353 | + au_set_dbend(dentry, bindex); |
9354 | + return; | |
9355 | + } | |
9356 | + au_set_h_dptr(dentry, bindex, NULL); | |
9357 | + } | |
9358 | +} | |
9359 | + | |
9360 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry) | |
9361 | +{ | |
9362 | + aufs_bindex_t bindex, bend; | |
9363 | + | |
9364 | + bend = au_dbend(dentry); | |
9365 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) | |
9366 | + if (au_h_dptr(dentry, bindex) == h_dentry) | |
9367 | + return bindex; | |
9368 | + return -1; | |
9369 | +} | |
7f207e10 AM |
9370 | diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c |
9371 | --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
9372 | +++ linux/fs/aufs/dir.c 2015-06-28 17:36:09.025073697 +0200 |
9373 | @@ -0,0 +1,753 @@ | |
1facf9fc | 9374 | +/* |
2000de60 | 9375 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 9376 | + * |
9377 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9378 | + * it under the terms of the GNU General Public License as published by | |
9379 | + * the Free Software Foundation; either version 2 of the License, or | |
9380 | + * (at your option) any later version. | |
dece6358 AM |
9381 | + * |
9382 | + * This program is distributed in the hope that it will be useful, | |
9383 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9384 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9385 | + * GNU General Public License for more details. | |
9386 | + * | |
9387 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9388 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9389 | + */ |
9390 | + | |
9391 | +/* | |
9392 | + * directory operations | |
9393 | + */ | |
9394 | + | |
9395 | +#include <linux/fs_stack.h> | |
9396 | +#include "aufs.h" | |
9397 | + | |
9398 | +void au_add_nlink(struct inode *dir, struct inode *h_dir) | |
9399 | +{ | |
9dbd164d AM |
9400 | + unsigned int nlink; |
9401 | + | |
1facf9fc | 9402 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9403 | + | |
9dbd164d AM |
9404 | + nlink = dir->i_nlink; |
9405 | + nlink += h_dir->i_nlink - 2; | |
1facf9fc | 9406 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9407 | + nlink += 2; |
f6b6e03d | 9408 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 9409 | + /* 0 can happen in revaliding */ |
92d182d2 | 9410 | + set_nlink(dir, nlink); |
1facf9fc | 9411 | +} |
9412 | + | |
9413 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir) | |
9414 | +{ | |
9dbd164d AM |
9415 | + unsigned int nlink; |
9416 | + | |
1facf9fc | 9417 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9418 | + | |
9dbd164d AM |
9419 | + nlink = dir->i_nlink; |
9420 | + nlink -= h_dir->i_nlink - 2; | |
1facf9fc | 9421 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9422 | + nlink -= 2; |
f6b6e03d | 9423 | + smp_mb(); /* for i_nlink */ |
92d182d2 | 9424 | + /* nlink == 0 means the branch-fs is broken */ |
9dbd164d | 9425 | + set_nlink(dir, nlink); |
1facf9fc | 9426 | +} |
9427 | + | |
1308ab2a | 9428 | +loff_t au_dir_size(struct file *file, struct dentry *dentry) |
9429 | +{ | |
9430 | + loff_t sz; | |
9431 | + aufs_bindex_t bindex, bend; | |
9432 | + struct file *h_file; | |
9433 | + struct dentry *h_dentry; | |
9434 | + | |
9435 | + sz = 0; | |
9436 | + if (file) { | |
2000de60 | 9437 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
1308ab2a | 9438 | + |
4a4d8108 | 9439 | + bend = au_fbend_dir(file); |
1308ab2a | 9440 | + for (bindex = au_fbstart(file); |
9441 | + bindex <= bend && sz < KMALLOC_MAX_SIZE; | |
9442 | + bindex++) { | |
4a4d8108 | 9443 | + h_file = au_hf_dir(file, bindex); |
c06a8ce3 AM |
9444 | + if (h_file && file_inode(h_file)) |
9445 | + sz += vfsub_f_size_read(h_file); | |
1308ab2a | 9446 | + } |
9447 | + } else { | |
9448 | + AuDebugOn(!dentry); | |
2000de60 | 9449 | + AuDebugOn(!d_is_dir(dentry)); |
1308ab2a | 9450 | + |
9451 | + bend = au_dbtaildir(dentry); | |
9452 | + for (bindex = au_dbstart(dentry); | |
9453 | + bindex <= bend && sz < KMALLOC_MAX_SIZE; | |
9454 | + bindex++) { | |
9455 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 JR |
9456 | + if (h_dentry && d_is_positive(h_dentry)) |
9457 | + sz += i_size_read(d_inode(h_dentry)); | |
1308ab2a | 9458 | + } |
9459 | + } | |
9460 | + if (sz < KMALLOC_MAX_SIZE) | |
9461 | + sz = roundup_pow_of_two(sz); | |
9462 | + if (sz > KMALLOC_MAX_SIZE) | |
9463 | + sz = KMALLOC_MAX_SIZE; | |
9464 | + else if (sz < NAME_MAX) { | |
9465 | + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX); | |
9466 | + sz = AUFS_RDBLK_DEF; | |
9467 | + } | |
9468 | + return sz; | |
9469 | +} | |
9470 | + | |
b912730e AM |
9471 | +struct au_dir_ts_arg { |
9472 | + struct dentry *dentry; | |
9473 | + aufs_bindex_t brid; | |
9474 | +}; | |
9475 | + | |
9476 | +static void au_do_dir_ts(void *arg) | |
9477 | +{ | |
9478 | + struct au_dir_ts_arg *a = arg; | |
9479 | + struct au_dtime dt; | |
9480 | + struct path h_path; | |
9481 | + struct inode *dir, *h_dir; | |
9482 | + struct super_block *sb; | |
9483 | + struct au_branch *br; | |
9484 | + struct au_hinode *hdir; | |
9485 | + int err; | |
9486 | + aufs_bindex_t bstart, bindex; | |
9487 | + | |
9488 | + sb = a->dentry->d_sb; | |
5527c038 | 9489 | + if (d_really_is_negative(a->dentry)) |
b912730e | 9490 | + goto out; |
b912730e AM |
9491 | + aufs_read_lock(a->dentry, AuLock_DW | AuLock_DIR); /* noflush */ |
9492 | + | |
5527c038 JR |
9493 | + /* no dir->i_mutex lock */ |
9494 | + dir = d_inode(a->dentry); | |
b912730e AM |
9495 | + bstart = au_ibstart(dir); |
9496 | + bindex = au_br_index(sb, a->brid); | |
9497 | + if (bindex < bstart) | |
9498 | + goto out_unlock; | |
9499 | + | |
9500 | + br = au_sbr(sb, bindex); | |
9501 | + h_path.dentry = au_h_dptr(a->dentry, bindex); | |
9502 | + if (!h_path.dentry) | |
9503 | + goto out_unlock; | |
9504 | + h_path.mnt = au_br_mnt(br); | |
9505 | + au_dtime_store(&dt, a->dentry, &h_path); | |
9506 | + | |
9507 | + br = au_sbr(sb, bstart); | |
9508 | + if (!au_br_writable(br->br_perm)) | |
9509 | + goto out_unlock; | |
9510 | + h_path.dentry = au_h_dptr(a->dentry, bstart); | |
9511 | + h_path.mnt = au_br_mnt(br); | |
9512 | + err = vfsub_mnt_want_write(h_path.mnt); | |
9513 | + if (err) | |
9514 | + goto out_unlock; | |
9515 | + hdir = au_hi(dir, bstart); | |
9516 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); | |
9517 | + h_dir = au_h_iptr(dir, bstart); | |
9518 | + if (h_dir->i_nlink | |
9519 | + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) { | |
9520 | + dt.dt_h_path = h_path; | |
9521 | + au_dtime_revert(&dt); | |
9522 | + } | |
9523 | + au_hn_imtx_unlock(hdir); | |
9524 | + vfsub_mnt_drop_write(h_path.mnt); | |
9525 | + au_cpup_attr_timesizes(dir); | |
9526 | + | |
9527 | +out_unlock: | |
9528 | + aufs_read_unlock(a->dentry, AuLock_DW); | |
9529 | +out: | |
9530 | + dput(a->dentry); | |
9531 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
9532 | + kfree(arg); | |
9533 | +} | |
9534 | + | |
9535 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex) | |
9536 | +{ | |
9537 | + int perm, wkq_err; | |
9538 | + aufs_bindex_t bstart; | |
9539 | + struct au_dir_ts_arg *arg; | |
9540 | + struct dentry *dentry; | |
9541 | + struct super_block *sb; | |
9542 | + | |
9543 | + IMustLock(dir); | |
9544 | + | |
9545 | + dentry = d_find_any_alias(dir); | |
9546 | + AuDebugOn(!dentry); | |
9547 | + sb = dentry->d_sb; | |
9548 | + bstart = au_ibstart(dir); | |
9549 | + if (bstart == bindex) { | |
9550 | + au_cpup_attr_timesizes(dir); | |
9551 | + goto out; | |
9552 | + } | |
9553 | + | |
9554 | + perm = au_sbr_perm(sb, bstart); | |
9555 | + if (!au_br_writable(perm)) | |
9556 | + goto out; | |
9557 | + | |
9558 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
9559 | + if (!arg) | |
9560 | + goto out; | |
9561 | + | |
9562 | + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */ | |
9563 | + arg->brid = au_sbr_id(sb, bindex); | |
9564 | + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0); | |
9565 | + if (unlikely(wkq_err)) { | |
9566 | + pr_err("wkq %d\n", wkq_err); | |
9567 | + dput(dentry); | |
9568 | + kfree(arg); | |
9569 | + } | |
9570 | + | |
9571 | +out: | |
9572 | + dput(dentry); | |
9573 | +} | |
9574 | + | |
1facf9fc | 9575 | +/* ---------------------------------------------------------------------- */ |
9576 | + | |
9577 | +static int reopen_dir(struct file *file) | |
9578 | +{ | |
9579 | + int err; | |
9580 | + unsigned int flags; | |
9581 | + aufs_bindex_t bindex, btail, bstart; | |
9582 | + struct dentry *dentry, *h_dentry; | |
9583 | + struct file *h_file; | |
9584 | + | |
9585 | + /* open all lower dirs */ | |
2000de60 | 9586 | + dentry = file->f_path.dentry; |
1facf9fc | 9587 | + bstart = au_dbstart(dentry); |
9588 | + for (bindex = au_fbstart(file); bindex < bstart; bindex++) | |
9589 | + au_set_h_fptr(file, bindex, NULL); | |
9590 | + au_set_fbstart(file, bstart); | |
9591 | + | |
9592 | + btail = au_dbtaildir(dentry); | |
4a4d8108 | 9593 | + for (bindex = au_fbend_dir(file); btail < bindex; bindex--) |
1facf9fc | 9594 | + au_set_h_fptr(file, bindex, NULL); |
4a4d8108 | 9595 | + au_set_fbend_dir(file, btail); |
1facf9fc | 9596 | + |
4a4d8108 | 9597 | + flags = vfsub_file_flags(file); |
1facf9fc | 9598 | + for (bindex = bstart; bindex <= btail; bindex++) { |
9599 | + h_dentry = au_h_dptr(dentry, bindex); | |
9600 | + if (!h_dentry) | |
9601 | + continue; | |
4a4d8108 | 9602 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 9603 | + if (h_file) |
9604 | + continue; | |
9605 | + | |
392086de | 9606 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9607 | + err = PTR_ERR(h_file); |
9608 | + if (IS_ERR(h_file)) | |
9609 | + goto out; /* close all? */ | |
9610 | + au_set_h_fptr(file, bindex, h_file); | |
9611 | + } | |
9612 | + au_update_figen(file); | |
9613 | + /* todo: necessary? */ | |
9614 | + /* file->f_ra = h_file->f_ra; */ | |
9615 | + err = 0; | |
9616 | + | |
4f0767ce | 9617 | +out: |
1facf9fc | 9618 | + return err; |
9619 | +} | |
9620 | + | |
b912730e | 9621 | +static int do_open_dir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 9622 | +{ |
9623 | + int err; | |
9624 | + aufs_bindex_t bindex, btail; | |
9625 | + struct dentry *dentry, *h_dentry; | |
1facf9fc | 9626 | + |
1308ab2a | 9627 | + FiMustWriteLock(file); |
b912730e | 9628 | + AuDebugOn(h_file); |
1308ab2a | 9629 | + |
523b37e3 | 9630 | + err = 0; |
2000de60 | 9631 | + dentry = file->f_path.dentry; |
5527c038 | 9632 | + file->f_version = d_inode(dentry)->i_version; |
1facf9fc | 9633 | + bindex = au_dbstart(dentry); |
9634 | + au_set_fbstart(file, bindex); | |
9635 | + btail = au_dbtaildir(dentry); | |
4a4d8108 | 9636 | + au_set_fbend_dir(file, btail); |
1facf9fc | 9637 | + for (; !err && bindex <= btail; bindex++) { |
9638 | + h_dentry = au_h_dptr(dentry, bindex); | |
9639 | + if (!h_dentry) | |
9640 | + continue; | |
9641 | + | |
392086de | 9642 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9643 | + if (IS_ERR(h_file)) { |
9644 | + err = PTR_ERR(h_file); | |
9645 | + break; | |
9646 | + } | |
9647 | + au_set_h_fptr(file, bindex, h_file); | |
9648 | + } | |
9649 | + au_update_figen(file); | |
9650 | + /* todo: necessary? */ | |
9651 | + /* file->f_ra = h_file->f_ra; */ | |
9652 | + if (!err) | |
9653 | + return 0; /* success */ | |
9654 | + | |
9655 | + /* close all */ | |
9656 | + for (bindex = au_fbstart(file); bindex <= btail; bindex++) | |
9657 | + au_set_h_fptr(file, bindex, NULL); | |
9658 | + au_set_fbstart(file, -1); | |
4a4d8108 AM |
9659 | + au_set_fbend_dir(file, -1); |
9660 | + | |
1facf9fc | 9661 | + return err; |
9662 | +} | |
9663 | + | |
9664 | +static int aufs_open_dir(struct inode *inode __maybe_unused, | |
9665 | + struct file *file) | |
9666 | +{ | |
4a4d8108 AM |
9667 | + int err; |
9668 | + struct super_block *sb; | |
9669 | + struct au_fidir *fidir; | |
9670 | + | |
9671 | + err = -ENOMEM; | |
2000de60 | 9672 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 9673 | + si_read_lock(sb, AuLock_FLUSH); |
e49829fe | 9674 | + fidir = au_fidir_alloc(sb); |
4a4d8108 | 9675 | + if (fidir) { |
b912730e AM |
9676 | + struct au_do_open_args args = { |
9677 | + .open = do_open_dir, | |
9678 | + .fidir = fidir | |
9679 | + }; | |
9680 | + err = au_do_open(file, &args); | |
4a4d8108 AM |
9681 | + if (unlikely(err)) |
9682 | + kfree(fidir); | |
9683 | + } | |
9684 | + si_read_unlock(sb); | |
9685 | + return err; | |
1facf9fc | 9686 | +} |
9687 | + | |
9688 | +static int aufs_release_dir(struct inode *inode __maybe_unused, | |
9689 | + struct file *file) | |
9690 | +{ | |
9691 | + struct au_vdir *vdir_cache; | |
4a4d8108 AM |
9692 | + struct au_finfo *finfo; |
9693 | + struct au_fidir *fidir; | |
9694 | + aufs_bindex_t bindex, bend; | |
1facf9fc | 9695 | + |
4a4d8108 AM |
9696 | + finfo = au_fi(file); |
9697 | + fidir = finfo->fi_hdir; | |
9698 | + if (fidir) { | |
076b876e | 9699 | + au_sphl_del(&finfo->fi_hlist, |
2000de60 | 9700 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); |
4a4d8108 AM |
9701 | + vdir_cache = fidir->fd_vdir_cache; /* lock-free */ |
9702 | + if (vdir_cache) | |
9703 | + au_vdir_free(vdir_cache); | |
9704 | + | |
9705 | + bindex = finfo->fi_btop; | |
9706 | + if (bindex >= 0) { | |
9707 | + /* | |
9708 | + * calls fput() instead of filp_close(), | |
9709 | + * since no dnotify or lock for the lower file. | |
9710 | + */ | |
9711 | + bend = fidir->fd_bbot; | |
9712 | + for (; bindex <= bend; bindex++) | |
9713 | + au_set_h_fptr(file, bindex, NULL); | |
9714 | + } | |
9715 | + kfree(fidir); | |
9716 | + finfo->fi_hdir = NULL; | |
1facf9fc | 9717 | + } |
1facf9fc | 9718 | + au_finfo_fin(file); |
1facf9fc | 9719 | + return 0; |
9720 | +} | |
9721 | + | |
9722 | +/* ---------------------------------------------------------------------- */ | |
9723 | + | |
4a4d8108 AM |
9724 | +static int au_do_flush_dir(struct file *file, fl_owner_t id) |
9725 | +{ | |
9726 | + int err; | |
9727 | + aufs_bindex_t bindex, bend; | |
9728 | + struct file *h_file; | |
9729 | + | |
9730 | + err = 0; | |
9731 | + bend = au_fbend_dir(file); | |
9732 | + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) { | |
9733 | + h_file = au_hf_dir(file, bindex); | |
9734 | + if (h_file) | |
9735 | + err = vfsub_flush(h_file, id); | |
9736 | + } | |
9737 | + return err; | |
9738 | +} | |
9739 | + | |
9740 | +static int aufs_flush_dir(struct file *file, fl_owner_t id) | |
9741 | +{ | |
9742 | + return au_do_flush(file, id, au_do_flush_dir); | |
9743 | +} | |
9744 | + | |
9745 | +/* ---------------------------------------------------------------------- */ | |
9746 | + | |
1facf9fc | 9747 | +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync) |
9748 | +{ | |
9749 | + int err; | |
9750 | + aufs_bindex_t bend, bindex; | |
9751 | + struct inode *inode; | |
9752 | + struct super_block *sb; | |
9753 | + | |
9754 | + err = 0; | |
9755 | + sb = dentry->d_sb; | |
5527c038 | 9756 | + inode = d_inode(dentry); |
1facf9fc | 9757 | + IMustLock(inode); |
9758 | + bend = au_dbend(dentry); | |
9759 | + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) { | |
9760 | + struct path h_path; | |
1facf9fc | 9761 | + |
9762 | + if (au_test_ro(sb, bindex, inode)) | |
9763 | + continue; | |
9764 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
9765 | + if (!h_path.dentry) | |
9766 | + continue; | |
1facf9fc | 9767 | + |
1facf9fc | 9768 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
53392da6 | 9769 | + err = vfsub_fsync(NULL, &h_path, datasync); |
1facf9fc | 9770 | + } |
9771 | + | |
9772 | + return err; | |
9773 | +} | |
9774 | + | |
9775 | +static int au_do_fsync_dir(struct file *file, int datasync) | |
9776 | +{ | |
9777 | + int err; | |
9778 | + aufs_bindex_t bend, bindex; | |
9779 | + struct file *h_file; | |
9780 | + struct super_block *sb; | |
9781 | + struct inode *inode; | |
1facf9fc | 9782 | + |
9783 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1); | |
9784 | + if (unlikely(err)) | |
9785 | + goto out; | |
9786 | + | |
c06a8ce3 | 9787 | + inode = file_inode(file); |
b912730e | 9788 | + sb = inode->i_sb; |
4a4d8108 | 9789 | + bend = au_fbend_dir(file); |
1facf9fc | 9790 | + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) { |
4a4d8108 | 9791 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 9792 | + if (!h_file || au_test_ro(sb, bindex, inode)) |
9793 | + continue; | |
9794 | + | |
53392da6 | 9795 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
1facf9fc | 9796 | + } |
9797 | + | |
4f0767ce | 9798 | +out: |
1facf9fc | 9799 | + return err; |
9800 | +} | |
9801 | + | |
9802 | +/* | |
9803 | + * @file may be NULL | |
9804 | + */ | |
1e00d052 AM |
9805 | +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end, |
9806 | + int datasync) | |
1facf9fc | 9807 | +{ |
9808 | + int err; | |
b752ccd1 | 9809 | + struct dentry *dentry; |
5527c038 | 9810 | + struct inode *inode; |
1facf9fc | 9811 | + struct super_block *sb; |
1e00d052 | 9812 | + struct mutex *mtx; |
1facf9fc | 9813 | + |
9814 | + err = 0; | |
2000de60 | 9815 | + dentry = file->f_path.dentry; |
5527c038 JR |
9816 | + inode = d_inode(dentry); |
9817 | + mtx = &inode->i_mutex; | |
1e00d052 | 9818 | + mutex_lock(mtx); |
1facf9fc | 9819 | + sb = dentry->d_sb; |
9820 | + si_noflush_read_lock(sb); | |
9821 | + if (file) | |
9822 | + err = au_do_fsync_dir(file, datasync); | |
9823 | + else { | |
9824 | + di_write_lock_child(dentry); | |
9825 | + err = au_do_fsync_dir_no_file(dentry, datasync); | |
9826 | + } | |
5527c038 | 9827 | + au_cpup_attr_timesizes(inode); |
1facf9fc | 9828 | + di_write_unlock(dentry); |
9829 | + if (file) | |
9830 | + fi_write_unlock(file); | |
9831 | + | |
9832 | + si_read_unlock(sb); | |
1e00d052 | 9833 | + mutex_unlock(mtx); |
1facf9fc | 9834 | + return err; |
9835 | +} | |
9836 | + | |
9837 | +/* ---------------------------------------------------------------------- */ | |
9838 | + | |
392086de | 9839 | +static int aufs_iterate(struct file *file, struct dir_context *ctx) |
1facf9fc | 9840 | +{ |
9841 | + int err; | |
9842 | + struct dentry *dentry; | |
9dbd164d | 9843 | + struct inode *inode, *h_inode; |
1facf9fc | 9844 | + struct super_block *sb; |
9845 | + | |
523b37e3 | 9846 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 9847 | + |
2000de60 | 9848 | + dentry = file->f_path.dentry; |
5527c038 | 9849 | + inode = d_inode(dentry); |
1facf9fc | 9850 | + IMustLock(inode); |
9851 | + | |
9852 | + sb = dentry->d_sb; | |
9853 | + si_read_lock(sb, AuLock_FLUSH); | |
9854 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1); | |
9855 | + if (unlikely(err)) | |
9856 | + goto out; | |
027c5e7a AM |
9857 | + err = au_alive_dir(dentry); |
9858 | + if (!err) | |
9859 | + err = au_vdir_init(file); | |
1facf9fc | 9860 | + di_downgrade_lock(dentry, AuLock_IR); |
9861 | + if (unlikely(err)) | |
9862 | + goto out_unlock; | |
9863 | + | |
9dbd164d | 9864 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); |
b752ccd1 | 9865 | + if (!au_test_nfsd()) { |
392086de | 9866 | + err = au_vdir_fill_de(file, ctx); |
9dbd164d | 9867 | + fsstack_copy_attr_atime(inode, h_inode); |
1facf9fc | 9868 | + } else { |
9869 | + /* | |
9870 | + * nfsd filldir may call lookup_one_len(), vfs_getattr(), | |
9871 | + * encode_fh() and others. | |
9872 | + */ | |
9dbd164d | 9873 | + atomic_inc(&h_inode->i_count); |
1facf9fc | 9874 | + di_read_unlock(dentry, AuLock_IR); |
9875 | + si_read_unlock(sb); | |
392086de | 9876 | + err = au_vdir_fill_de(file, ctx); |
1facf9fc | 9877 | + fsstack_copy_attr_atime(inode, h_inode); |
9878 | + fi_write_unlock(file); | |
9dbd164d | 9879 | + iput(h_inode); |
1facf9fc | 9880 | + |
9881 | + AuTraceErr(err); | |
9882 | + return err; | |
9883 | + } | |
9884 | + | |
4f0767ce | 9885 | +out_unlock: |
1facf9fc | 9886 | + di_read_unlock(dentry, AuLock_IR); |
9887 | + fi_write_unlock(file); | |
4f0767ce | 9888 | +out: |
1facf9fc | 9889 | + si_read_unlock(sb); |
9890 | + return err; | |
9891 | +} | |
9892 | + | |
9893 | +/* ---------------------------------------------------------------------- */ | |
9894 | + | |
9895 | +#define AuTestEmpty_WHONLY 1 | |
dece6358 AM |
9896 | +#define AuTestEmpty_CALLED (1 << 1) |
9897 | +#define AuTestEmpty_SHWH (1 << 2) | |
1facf9fc | 9898 | +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name) |
7f207e10 AM |
9899 | +#define au_fset_testempty(flags, name) \ |
9900 | + do { (flags) |= AuTestEmpty_##name; } while (0) | |
9901 | +#define au_fclr_testempty(flags, name) \ | |
9902 | + do { (flags) &= ~AuTestEmpty_##name; } while (0) | |
1facf9fc | 9903 | + |
dece6358 AM |
9904 | +#ifndef CONFIG_AUFS_SHWH |
9905 | +#undef AuTestEmpty_SHWH | |
9906 | +#define AuTestEmpty_SHWH 0 | |
9907 | +#endif | |
9908 | + | |
1facf9fc | 9909 | +struct test_empty_arg { |
392086de | 9910 | + struct dir_context ctx; |
1308ab2a | 9911 | + struct au_nhash *whlist; |
1facf9fc | 9912 | + unsigned int flags; |
9913 | + int err; | |
9914 | + aufs_bindex_t bindex; | |
9915 | +}; | |
9916 | + | |
392086de AM |
9917 | +static int test_empty_cb(struct dir_context *ctx, const char *__name, |
9918 | + int namelen, loff_t offset __maybe_unused, u64 ino, | |
dece6358 | 9919 | + unsigned int d_type) |
1facf9fc | 9920 | +{ |
392086de AM |
9921 | + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg, |
9922 | + ctx); | |
1facf9fc | 9923 | + char *name = (void *)__name; |
9924 | + | |
9925 | + arg->err = 0; | |
9926 | + au_fset_testempty(arg->flags, CALLED); | |
9927 | + /* smp_mb(); */ | |
9928 | + if (name[0] == '.' | |
9929 | + && (namelen == 1 || (name[1] == '.' && namelen == 2))) | |
9930 | + goto out; /* success */ | |
9931 | + | |
9932 | + if (namelen <= AUFS_WH_PFX_LEN | |
9933 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
9934 | + if (au_ftest_testempty(arg->flags, WHONLY) | |
1308ab2a | 9935 | + && !au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 9936 | + arg->err = -ENOTEMPTY; |
9937 | + goto out; | |
9938 | + } | |
9939 | + | |
9940 | + name += AUFS_WH_PFX_LEN; | |
9941 | + namelen -= AUFS_WH_PFX_LEN; | |
1308ab2a | 9942 | + if (!au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 9943 | + arg->err = au_nhash_append_wh |
1308ab2a | 9944 | + (arg->whlist, name, namelen, ino, d_type, arg->bindex, |
dece6358 | 9945 | + au_ftest_testempty(arg->flags, SHWH)); |
1facf9fc | 9946 | + |
4f0767ce | 9947 | +out: |
1facf9fc | 9948 | + /* smp_mb(); */ |
9949 | + AuTraceErr(arg->err); | |
9950 | + return arg->err; | |
9951 | +} | |
9952 | + | |
9953 | +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
9954 | +{ | |
9955 | + int err; | |
9956 | + struct file *h_file; | |
9957 | + | |
9958 | + h_file = au_h_open(dentry, arg->bindex, | |
9959 | + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE, | |
392086de | 9960 | + /*file*/NULL, /*force_wr*/0); |
1facf9fc | 9961 | + err = PTR_ERR(h_file); |
9962 | + if (IS_ERR(h_file)) | |
9963 | + goto out; | |
9964 | + | |
9965 | + err = 0; | |
9966 | + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE) | |
c06a8ce3 | 9967 | + && !file_inode(h_file)->i_nlink) |
1facf9fc | 9968 | + goto out_put; |
9969 | + | |
9970 | + do { | |
9971 | + arg->err = 0; | |
9972 | + au_fclr_testempty(arg->flags, CALLED); | |
9973 | + /* smp_mb(); */ | |
392086de | 9974 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1facf9fc | 9975 | + if (err >= 0) |
9976 | + err = arg->err; | |
9977 | + } while (!err && au_ftest_testempty(arg->flags, CALLED)); | |
9978 | + | |
4f0767ce | 9979 | +out_put: |
1facf9fc | 9980 | + fput(h_file); |
9981 | + au_sbr_put(dentry->d_sb, arg->bindex); | |
4f0767ce | 9982 | +out: |
1facf9fc | 9983 | + return err; |
9984 | +} | |
9985 | + | |
9986 | +struct do_test_empty_args { | |
9987 | + int *errp; | |
9988 | + struct dentry *dentry; | |
9989 | + struct test_empty_arg *arg; | |
9990 | +}; | |
9991 | + | |
9992 | +static void call_do_test_empty(void *args) | |
9993 | +{ | |
9994 | + struct do_test_empty_args *a = args; | |
9995 | + *a->errp = do_test_empty(a->dentry, a->arg); | |
9996 | +} | |
9997 | + | |
9998 | +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
9999 | +{ | |
10000 | + int err, wkq_err; | |
10001 | + struct dentry *h_dentry; | |
10002 | + struct inode *h_inode; | |
10003 | + | |
10004 | + h_dentry = au_h_dptr(dentry, arg->bindex); | |
5527c038 | 10005 | + h_inode = d_inode(h_dentry); |
53392da6 | 10006 | + /* todo: i_mode changes anytime? */ |
1facf9fc | 10007 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
10008 | + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ); | |
10009 | + mutex_unlock(&h_inode->i_mutex); | |
10010 | + if (!err) | |
10011 | + err = do_test_empty(dentry, arg); | |
10012 | + else { | |
10013 | + struct do_test_empty_args args = { | |
10014 | + .errp = &err, | |
10015 | + .dentry = dentry, | |
10016 | + .arg = arg | |
10017 | + }; | |
10018 | + unsigned int flags = arg->flags; | |
10019 | + | |
10020 | + wkq_err = au_wkq_wait(call_do_test_empty, &args); | |
10021 | + if (unlikely(wkq_err)) | |
10022 | + err = wkq_err; | |
10023 | + arg->flags = flags; | |
10024 | + } | |
10025 | + | |
10026 | + return err; | |
10027 | +} | |
10028 | + | |
10029 | +int au_test_empty_lower(struct dentry *dentry) | |
10030 | +{ | |
10031 | + int err; | |
1308ab2a | 10032 | + unsigned int rdhash; |
1facf9fc | 10033 | + aufs_bindex_t bindex, bstart, btail; |
1308ab2a | 10034 | + struct au_nhash whlist; |
392086de AM |
10035 | + struct test_empty_arg arg = { |
10036 | + .ctx = { | |
2000de60 | 10037 | + .actor = test_empty_cb |
392086de AM |
10038 | + } |
10039 | + }; | |
076b876e | 10040 | + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg); |
1facf9fc | 10041 | + |
dece6358 AM |
10042 | + SiMustAnyLock(dentry->d_sb); |
10043 | + | |
1308ab2a | 10044 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; |
10045 | + if (!rdhash) | |
10046 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry)); | |
10047 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
dece6358 | 10048 | + if (unlikely(err)) |
1facf9fc | 10049 | + goto out; |
10050 | + | |
1facf9fc | 10051 | + arg.flags = 0; |
1308ab2a | 10052 | + arg.whlist = &whlist; |
10053 | + bstart = au_dbstart(dentry); | |
dece6358 AM |
10054 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10055 | + au_fset_testempty(arg.flags, SHWH); | |
076b876e AM |
10056 | + test_empty = do_test_empty; |
10057 | + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)) | |
10058 | + test_empty = sio_test_empty; | |
1facf9fc | 10059 | + arg.bindex = bstart; |
076b876e | 10060 | + err = test_empty(dentry, &arg); |
1facf9fc | 10061 | + if (unlikely(err)) |
10062 | + goto out_whlist; | |
10063 | + | |
10064 | + au_fset_testempty(arg.flags, WHONLY); | |
10065 | + btail = au_dbtaildir(dentry); | |
10066 | + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) { | |
10067 | + struct dentry *h_dentry; | |
10068 | + | |
10069 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10070 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10071 | + arg.bindex = bindex; |
076b876e | 10072 | + err = test_empty(dentry, &arg); |
1facf9fc | 10073 | + } |
10074 | + } | |
10075 | + | |
4f0767ce | 10076 | +out_whlist: |
1308ab2a | 10077 | + au_nhash_wh_free(&whlist); |
4f0767ce | 10078 | +out: |
1facf9fc | 10079 | + return err; |
10080 | +} | |
10081 | + | |
10082 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist) | |
10083 | +{ | |
10084 | + int err; | |
392086de AM |
10085 | + struct test_empty_arg arg = { |
10086 | + .ctx = { | |
2000de60 | 10087 | + .actor = test_empty_cb |
392086de AM |
10088 | + } |
10089 | + }; | |
1facf9fc | 10090 | + aufs_bindex_t bindex, btail; |
10091 | + | |
10092 | + err = 0; | |
1308ab2a | 10093 | + arg.whlist = whlist; |
1facf9fc | 10094 | + arg.flags = AuTestEmpty_WHONLY; |
dece6358 AM |
10095 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10096 | + au_fset_testempty(arg.flags, SHWH); | |
1facf9fc | 10097 | + btail = au_dbtaildir(dentry); |
10098 | + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) { | |
10099 | + struct dentry *h_dentry; | |
10100 | + | |
10101 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10102 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10103 | + arg.bindex = bindex; |
10104 | + err = sio_test_empty(dentry, &arg); | |
10105 | + } | |
10106 | + } | |
10107 | + | |
10108 | + return err; | |
10109 | +} | |
10110 | + | |
10111 | +/* ---------------------------------------------------------------------- */ | |
10112 | + | |
10113 | +const struct file_operations aufs_dir_fop = { | |
4a4d8108 | 10114 | + .owner = THIS_MODULE, |
027c5e7a | 10115 | + .llseek = default_llseek, |
1facf9fc | 10116 | + .read = generic_read_dir, |
392086de | 10117 | + .iterate = aufs_iterate, |
1facf9fc | 10118 | + .unlocked_ioctl = aufs_ioctl_dir, |
b752ccd1 AM |
10119 | +#ifdef CONFIG_COMPAT |
10120 | + .compat_ioctl = aufs_compat_ioctl_dir, | |
10121 | +#endif | |
1facf9fc | 10122 | + .open = aufs_open_dir, |
10123 | + .release = aufs_release_dir, | |
4a4d8108 | 10124 | + .flush = aufs_flush_dir, |
1facf9fc | 10125 | + .fsync = aufs_fsync_dir |
10126 | +}; | |
7f207e10 AM |
10127 | diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h |
10128 | --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 10129 | +++ linux/fs/aufs/dir.h 2015-06-28 17:35:44.348050491 +0200 |
b912730e | 10130 | @@ -0,0 +1,131 @@ |
1facf9fc | 10131 | +/* |
2000de60 | 10132 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 10133 | + * |
10134 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10135 | + * it under the terms of the GNU General Public License as published by | |
10136 | + * the Free Software Foundation; either version 2 of the License, or | |
10137 | + * (at your option) any later version. | |
dece6358 AM |
10138 | + * |
10139 | + * This program is distributed in the hope that it will be useful, | |
10140 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10141 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10142 | + * GNU General Public License for more details. | |
10143 | + * | |
10144 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10145 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10146 | + */ |
10147 | + | |
10148 | +/* | |
10149 | + * directory operations | |
10150 | + */ | |
10151 | + | |
10152 | +#ifndef __AUFS_DIR_H__ | |
10153 | +#define __AUFS_DIR_H__ | |
10154 | + | |
10155 | +#ifdef __KERNEL__ | |
10156 | + | |
10157 | +#include <linux/fs.h> | |
1facf9fc | 10158 | + |
10159 | +/* ---------------------------------------------------------------------- */ | |
10160 | + | |
10161 | +/* need to be faster and smaller */ | |
10162 | + | |
10163 | +struct au_nhash { | |
dece6358 AM |
10164 | + unsigned int nh_num; |
10165 | + struct hlist_head *nh_head; | |
1facf9fc | 10166 | +}; |
10167 | + | |
10168 | +struct au_vdir_destr { | |
10169 | + unsigned char len; | |
10170 | + unsigned char name[0]; | |
10171 | +} __packed; | |
10172 | + | |
10173 | +struct au_vdir_dehstr { | |
10174 | + struct hlist_node hash; | |
10175 | + struct au_vdir_destr *str; | |
4a4d8108 | 10176 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10177 | + |
10178 | +struct au_vdir_de { | |
10179 | + ino_t de_ino; | |
10180 | + unsigned char de_type; | |
10181 | + /* caution: packed */ | |
10182 | + struct au_vdir_destr de_str; | |
10183 | +} __packed; | |
10184 | + | |
10185 | +struct au_vdir_wh { | |
10186 | + struct hlist_node wh_hash; | |
dece6358 AM |
10187 | +#ifdef CONFIG_AUFS_SHWH |
10188 | + ino_t wh_ino; | |
1facf9fc | 10189 | + aufs_bindex_t wh_bindex; |
dece6358 AM |
10190 | + unsigned char wh_type; |
10191 | +#else | |
10192 | + aufs_bindex_t wh_bindex; | |
10193 | +#endif | |
10194 | + /* caution: packed */ | |
1facf9fc | 10195 | + struct au_vdir_destr wh_str; |
10196 | +} __packed; | |
10197 | + | |
10198 | +union au_vdir_deblk_p { | |
10199 | + unsigned char *deblk; | |
10200 | + struct au_vdir_de *de; | |
10201 | +}; | |
10202 | + | |
10203 | +struct au_vdir { | |
10204 | + unsigned char **vd_deblk; | |
10205 | + unsigned long vd_nblk; | |
1facf9fc | 10206 | + struct { |
10207 | + unsigned long ul; | |
10208 | + union au_vdir_deblk_p p; | |
10209 | + } vd_last; | |
10210 | + | |
10211 | + unsigned long vd_version; | |
dece6358 | 10212 | + unsigned int vd_deblk_sz; |
1facf9fc | 10213 | + unsigned long vd_jiffy; |
4a4d8108 | 10214 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10215 | + |
10216 | +/* ---------------------------------------------------------------------- */ | |
10217 | + | |
10218 | +/* dir.c */ | |
10219 | +extern const struct file_operations aufs_dir_fop; | |
10220 | +void au_add_nlink(struct inode *dir, struct inode *h_dir); | |
10221 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir); | |
1308ab2a | 10222 | +loff_t au_dir_size(struct file *file, struct dentry *dentry); |
b912730e | 10223 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc); |
1facf9fc | 10224 | +int au_test_empty_lower(struct dentry *dentry); |
10225 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist); | |
10226 | + | |
10227 | +/* vdir.c */ | |
1308ab2a | 10228 | +unsigned int au_rdhash_est(loff_t sz); |
dece6358 AM |
10229 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp); |
10230 | +void au_nhash_wh_free(struct au_nhash *whlist); | |
1facf9fc | 10231 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, |
10232 | + int limit); | |
dece6358 AM |
10233 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen); |
10234 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
10235 | + unsigned int d_type, aufs_bindex_t bindex, | |
10236 | + unsigned char shwh); | |
1facf9fc | 10237 | +void au_vdir_free(struct au_vdir *vdir); |
10238 | +int au_vdir_init(struct file *file); | |
392086de | 10239 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx); |
1facf9fc | 10240 | + |
10241 | +/* ioctl.c */ | |
10242 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg); | |
10243 | + | |
1308ab2a | 10244 | +#ifdef CONFIG_AUFS_RDU |
10245 | +/* rdu.c */ | |
10246 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
10247 | +#ifdef CONFIG_COMPAT |
10248 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, | |
10249 | + unsigned long arg); | |
10250 | +#endif | |
1308ab2a | 10251 | +#else |
c1595e42 JR |
10252 | +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file, |
10253 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10254 | +#ifdef CONFIG_COMPAT |
c1595e42 JR |
10255 | +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file, |
10256 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10257 | +#endif |
1308ab2a | 10258 | +#endif |
10259 | + | |
1facf9fc | 10260 | +#endif /* __KERNEL__ */ |
10261 | +#endif /* __AUFS_DIR_H__ */ | |
7f207e10 AM |
10262 | diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c |
10263 | --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 10264 | +++ linux/fs/aufs/dynop.c 2015-06-28 17:35:44.348050491 +0200 |
7e9cd9fe | 10265 | @@ -0,0 +1,369 @@ |
1facf9fc | 10266 | +/* |
2000de60 | 10267 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
1facf9fc | 10268 | + * |
10269 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10270 | + * it under the terms of the GNU General Public License as published by | |
10271 | + * the Free Software Foundation; either version 2 of the License, or | |
10272 | + * (at your option) any later version. | |
dece6358 AM |
10273 | + * |
10274 | + * This program is distributed in the hope that it will be useful, | |
10275 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10276 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10277 | + * GNU General Public License for more details. | |
10278 | + * | |
10279 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10280 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10281 | + */ |
10282 | + | |
10283 | +/* | |
4a4d8108 | 10284 | + * dynamically customizable operations for regular files |
1facf9fc | 10285 | + */ |
10286 | + | |
1facf9fc | 10287 | +#include "aufs.h" |
10288 | + | |
4a4d8108 | 10289 | +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop) |
1facf9fc | 10290 | + |
4a4d8108 AM |
10291 | +/* |
10292 | + * How large will these lists be? | |
10293 | + * Usually just a few elements, 20-30 at most for each, I guess. | |
10294 | + */ | |
10295 | +static struct au_splhead dynop[AuDyLast]; | |
10296 | + | |
10297 | +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op) | |
1facf9fc | 10298 | +{ |
4a4d8108 AM |
10299 | + struct au_dykey *key, *tmp; |
10300 | + struct list_head *head; | |
1facf9fc | 10301 | + |
4a4d8108 AM |
10302 | + key = NULL; |
10303 | + head = &spl->head; | |
10304 | + rcu_read_lock(); | |
10305 | + list_for_each_entry_rcu(tmp, head, dk_list) | |
10306 | + if (tmp->dk_op.dy_hop == h_op) { | |
10307 | + key = tmp; | |
10308 | + kref_get(&key->dk_kref); | |
10309 | + break; | |
10310 | + } | |
10311 | + rcu_read_unlock(); | |
10312 | + | |
10313 | + return key; | |
1facf9fc | 10314 | +} |
10315 | + | |
4a4d8108 | 10316 | +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key) |
1facf9fc | 10317 | +{ |
4a4d8108 AM |
10318 | + struct au_dykey **k, *found; |
10319 | + const void *h_op = key->dk_op.dy_hop; | |
10320 | + int i; | |
1facf9fc | 10321 | + |
4a4d8108 AM |
10322 | + found = NULL; |
10323 | + k = br->br_dykey; | |
10324 | + for (i = 0; i < AuBrDynOp; i++) | |
10325 | + if (k[i]) { | |
10326 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10327 | + found = k[i]; | |
10328 | + break; | |
10329 | + } | |
10330 | + } else | |
10331 | + break; | |
10332 | + if (!found) { | |
10333 | + spin_lock(&br->br_dykey_lock); | |
10334 | + for (; i < AuBrDynOp; i++) | |
10335 | + if (k[i]) { | |
10336 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10337 | + found = k[i]; | |
10338 | + break; | |
10339 | + } | |
10340 | + } else { | |
10341 | + k[i] = key; | |
10342 | + break; | |
10343 | + } | |
10344 | + spin_unlock(&br->br_dykey_lock); | |
10345 | + BUG_ON(i == AuBrDynOp); /* expand the array */ | |
10346 | + } | |
10347 | + | |
10348 | + return found; | |
1facf9fc | 10349 | +} |
10350 | + | |
4a4d8108 AM |
10351 | +/* kref_get() if @key is already added */ |
10352 | +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key) | |
10353 | +{ | |
10354 | + struct au_dykey *tmp, *found; | |
10355 | + struct list_head *head; | |
10356 | + const void *h_op = key->dk_op.dy_hop; | |
1facf9fc | 10357 | + |
4a4d8108 AM |
10358 | + found = NULL; |
10359 | + head = &spl->head; | |
10360 | + spin_lock(&spl->spin); | |
10361 | + list_for_each_entry(tmp, head, dk_list) | |
10362 | + if (tmp->dk_op.dy_hop == h_op) { | |
10363 | + kref_get(&tmp->dk_kref); | |
10364 | + found = tmp; | |
10365 | + break; | |
10366 | + } | |
10367 | + if (!found) | |
10368 | + list_add_rcu(&key->dk_list, head); | |
10369 | + spin_unlock(&spl->spin); | |
1facf9fc | 10370 | + |
4a4d8108 AM |
10371 | + if (!found) |
10372 | + DyPrSym(key); | |
10373 | + return found; | |
10374 | +} | |
10375 | + | |
10376 | +static void dy_free_rcu(struct rcu_head *rcu) | |
1facf9fc | 10377 | +{ |
4a4d8108 AM |
10378 | + struct au_dykey *key; |
10379 | + | |
10380 | + key = container_of(rcu, struct au_dykey, dk_rcu); | |
10381 | + DyPrSym(key); | |
10382 | + kfree(key); | |
1facf9fc | 10383 | +} |
10384 | + | |
4a4d8108 AM |
10385 | +static void dy_free(struct kref *kref) |
10386 | +{ | |
10387 | + struct au_dykey *key; | |
10388 | + struct au_splhead *spl; | |
1facf9fc | 10389 | + |
4a4d8108 AM |
10390 | + key = container_of(kref, struct au_dykey, dk_kref); |
10391 | + spl = dynop + key->dk_op.dy_type; | |
10392 | + au_spl_del_rcu(&key->dk_list, spl); | |
10393 | + call_rcu(&key->dk_rcu, dy_free_rcu); | |
10394 | +} | |
10395 | + | |
10396 | +void au_dy_put(struct au_dykey *key) | |
1facf9fc | 10397 | +{ |
4a4d8108 AM |
10398 | + kref_put(&key->dk_kref, dy_free); |
10399 | +} | |
1facf9fc | 10400 | + |
4a4d8108 AM |
10401 | +/* ---------------------------------------------------------------------- */ |
10402 | + | |
10403 | +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *)) | |
10404 | + | |
10405 | +#ifdef CONFIG_AUFS_DEBUG | |
10406 | +#define DyDbgDeclare(cnt) unsigned int cnt = 0 | |
4f0767ce | 10407 | +#define DyDbgInc(cnt) do { cnt++; } while (0) |
4a4d8108 AM |
10408 | +#else |
10409 | +#define DyDbgDeclare(cnt) do {} while (0) | |
10410 | +#define DyDbgInc(cnt) do {} while (0) | |
10411 | +#endif | |
10412 | + | |
10413 | +#define DySet(func, dst, src, h_op, h_sb) do { \ | |
10414 | + DyDbgInc(cnt); \ | |
10415 | + if (h_op->func) { \ | |
10416 | + if (src.func) \ | |
10417 | + dst.func = src.func; \ | |
10418 | + else \ | |
10419 | + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \ | |
10420 | + } \ | |
10421 | +} while (0) | |
10422 | + | |
10423 | +#define DySetForce(func, dst, src) do { \ | |
10424 | + AuDebugOn(!src.func); \ | |
10425 | + DyDbgInc(cnt); \ | |
10426 | + dst.func = src.func; \ | |
10427 | +} while (0) | |
10428 | + | |
10429 | +#define DySetAop(func) \ | |
10430 | + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb) | |
10431 | +#define DySetAopForce(func) \ | |
10432 | + DySetForce(func, dyaop->da_op, aufs_aop) | |
10433 | + | |
10434 | +static void dy_aop(struct au_dykey *key, const void *h_op, | |
10435 | + struct super_block *h_sb __maybe_unused) | |
10436 | +{ | |
10437 | + struct au_dyaop *dyaop = (void *)key; | |
10438 | + const struct address_space_operations *h_aop = h_op; | |
10439 | + DyDbgDeclare(cnt); | |
10440 | + | |
10441 | + AuDbg("%s\n", au_sbtype(h_sb)); | |
10442 | + | |
10443 | + DySetAop(writepage); | |
10444 | + DySetAopForce(readpage); /* force */ | |
4a4d8108 AM |
10445 | + DySetAop(writepages); |
10446 | + DySetAop(set_page_dirty); | |
10447 | + DySetAop(readpages); | |
10448 | + DySetAop(write_begin); | |
10449 | + DySetAop(write_end); | |
10450 | + DySetAop(bmap); | |
10451 | + DySetAop(invalidatepage); | |
10452 | + DySetAop(releasepage); | |
027c5e7a | 10453 | + DySetAop(freepage); |
7e9cd9fe | 10454 | + /* this one will be changed according to an aufs mount option */ |
4a4d8108 | 10455 | + DySetAop(direct_IO); |
4a4d8108 AM |
10456 | + DySetAop(migratepage); |
10457 | + DySetAop(launder_page); | |
10458 | + DySetAop(is_partially_uptodate); | |
392086de | 10459 | + DySetAop(is_dirty_writeback); |
4a4d8108 | 10460 | + DySetAop(error_remove_page); |
b4510431 AM |
10461 | + DySetAop(swap_activate); |
10462 | + DySetAop(swap_deactivate); | |
4a4d8108 AM |
10463 | + |
10464 | + DyDbgSize(cnt, *h_aop); | |
4a4d8108 AM |
10465 | +} |
10466 | + | |
4a4d8108 AM |
10467 | +/* ---------------------------------------------------------------------- */ |
10468 | + | |
10469 | +static void dy_bug(struct kref *kref) | |
10470 | +{ | |
10471 | + BUG(); | |
10472 | +} | |
10473 | + | |
10474 | +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br) | |
10475 | +{ | |
10476 | + struct au_dykey *key, *old; | |
10477 | + struct au_splhead *spl; | |
b752ccd1 | 10478 | + struct op { |
4a4d8108 | 10479 | + unsigned int sz; |
b752ccd1 AM |
10480 | + void (*set)(struct au_dykey *key, const void *h_op, |
10481 | + struct super_block *h_sb __maybe_unused); | |
10482 | + }; | |
10483 | + static const struct op a[] = { | |
4a4d8108 AM |
10484 | + [AuDy_AOP] = { |
10485 | + .sz = sizeof(struct au_dyaop), | |
b752ccd1 | 10486 | + .set = dy_aop |
4a4d8108 | 10487 | + } |
b752ccd1 AM |
10488 | + }; |
10489 | + const struct op *p; | |
4a4d8108 AM |
10490 | + |
10491 | + spl = dynop + op->dy_type; | |
10492 | + key = dy_gfind_get(spl, op->dy_hop); | |
10493 | + if (key) | |
10494 | + goto out_add; /* success */ | |
10495 | + | |
10496 | + p = a + op->dy_type; | |
10497 | + key = kzalloc(p->sz, GFP_NOFS); | |
10498 | + if (unlikely(!key)) { | |
10499 | + key = ERR_PTR(-ENOMEM); | |
10500 | + goto out; | |
10501 | + } | |
10502 | + | |
10503 | + key->dk_op.dy_hop = op->dy_hop; | |
10504 | + kref_init(&key->dk_kref); | |
86dc4139 | 10505 | + p->set(key, op->dy_hop, au_br_sb(br)); |
4a4d8108 AM |
10506 | + old = dy_gadd(spl, key); |
10507 | + if (old) { | |
10508 | + kfree(key); | |
10509 | + key = old; | |
10510 | + } | |
10511 | + | |
10512 | +out_add: | |
10513 | + old = dy_bradd(br, key); | |
10514 | + if (old) | |
10515 | + /* its ref-count should never be zero here */ | |
10516 | + kref_put(&key->dk_kref, dy_bug); | |
10517 | +out: | |
10518 | + return key; | |
10519 | +} | |
10520 | + | |
10521 | +/* ---------------------------------------------------------------------- */ | |
10522 | +/* | |
10523 | + * Aufs prohibits O_DIRECT by defaut even if the branch supports it. | |
c1595e42 | 10524 | + * This behaviour is necessary to return an error from open(O_DIRECT) instead |
4a4d8108 AM |
10525 | + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes |
10526 | + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error. | |
10527 | + * See the aufs manual in detail. | |
4a4d8108 AM |
10528 | + */ |
10529 | +static void dy_adx(struct au_dyaop *dyaop, int do_dx) | |
10530 | +{ | |
7e9cd9fe | 10531 | + if (!do_dx) |
4a4d8108 | 10532 | + dyaop->da_op.direct_IO = NULL; |
7e9cd9fe | 10533 | + else |
4a4d8108 | 10534 | + dyaop->da_op.direct_IO = aufs_aop.direct_IO; |
4a4d8108 AM |
10535 | +} |
10536 | + | |
10537 | +static struct au_dyaop *dy_aget(struct au_branch *br, | |
10538 | + const struct address_space_operations *h_aop, | |
10539 | + int do_dx) | |
10540 | +{ | |
10541 | + struct au_dyaop *dyaop; | |
10542 | + struct au_dynop op; | |
10543 | + | |
10544 | + op.dy_type = AuDy_AOP; | |
10545 | + op.dy_haop = h_aop; | |
10546 | + dyaop = (void *)dy_get(&op, br); | |
10547 | + if (IS_ERR(dyaop)) | |
10548 | + goto out; | |
10549 | + dy_adx(dyaop, do_dx); | |
10550 | + | |
10551 | +out: | |
10552 | + return dyaop; | |
10553 | +} | |
10554 | + | |
10555 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
10556 | + struct inode *h_inode) | |
10557 | +{ | |
10558 | + int err, do_dx; | |
10559 | + struct super_block *sb; | |
10560 | + struct au_branch *br; | |
10561 | + struct au_dyaop *dyaop; | |
10562 | + | |
10563 | + AuDebugOn(!S_ISREG(h_inode->i_mode)); | |
10564 | + IiMustWriteLock(inode); | |
10565 | + | |
10566 | + sb = inode->i_sb; | |
10567 | + br = au_sbr(sb, bindex); | |
10568 | + do_dx = !!au_opt_test(au_mntflags(sb), DIO); | |
10569 | + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx); | |
10570 | + err = PTR_ERR(dyaop); | |
10571 | + if (IS_ERR(dyaop)) | |
10572 | + /* unnecessary to call dy_fput() */ | |
10573 | + goto out; | |
10574 | + | |
10575 | + err = 0; | |
10576 | + inode->i_mapping->a_ops = &dyaop->da_op; | |
10577 | + | |
10578 | +out: | |
10579 | + return err; | |
10580 | +} | |
10581 | + | |
b752ccd1 AM |
10582 | +/* |
10583 | + * Is it safe to replace a_ops during the inode/file is in operation? | |
10584 | + * Yes, I hope so. | |
10585 | + */ | |
10586 | +int au_dy_irefresh(struct inode *inode) | |
10587 | +{ | |
10588 | + int err; | |
10589 | + aufs_bindex_t bstart; | |
10590 | + struct inode *h_inode; | |
10591 | + | |
10592 | + err = 0; | |
10593 | + if (S_ISREG(inode->i_mode)) { | |
10594 | + bstart = au_ibstart(inode); | |
10595 | + h_inode = au_h_iptr(inode, bstart); | |
10596 | + err = au_dy_iaop(inode, bstart, h_inode); | |
10597 | + } | |
10598 | + return err; | |
10599 | +} | |
10600 | + | |
4a4d8108 AM |
10601 | +void au_dy_arefresh(int do_dx) |
10602 | +{ | |
10603 | + struct au_splhead *spl; | |
10604 | + struct list_head *head; | |
10605 | + struct au_dykey *key; | |
10606 | + | |
10607 | + spl = dynop + AuDy_AOP; | |
10608 | + head = &spl->head; | |
10609 | + spin_lock(&spl->spin); | |
10610 | + list_for_each_entry(key, head, dk_list) | |
10611 | + dy_adx((void *)key, do_dx); | |
10612 | + spin_unlock(&spl->spin); | |
10613 | +} | |
10614 | + | |
4a4d8108 AM |
10615 | +/* ---------------------------------------------------------------------- */ |
10616 | + | |
10617 | +void __init au_dy_init(void) | |
10618 | +{ | |
10619 | + int i; | |
10620 | + | |
10621 | + /* make sure that 'struct au_dykey *' can be any type */ | |
10622 | + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key)); | |
4a4d8108 AM |
10623 | + |
10624 | + for (i = 0; i < AuDyLast; i++) | |
10625 | + au_spl_init(dynop + i); | |
10626 | +} | |
10627 | + | |
10628 | +void au_dy_fin(void) | |
10629 | +{ | |
10630 | + int i; | |
10631 | + | |
10632 | + for (i = 0; i < AuDyLast; i++) | |
10633 | + WARN_ON(!list_empty(&dynop[i].head)); | |
10634 | +} | |
7f207e10 AM |
10635 | diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h |
10636 | --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 10637 | +++ linux/fs/aufs/dynop.h 2015-06-28 17:35:44.348050491 +0200 |
7e9cd9fe | 10638 | @@ -0,0 +1,74 @@ |
4a4d8108 | 10639 | +/* |
2000de60 | 10640 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
4a4d8108 AM |
10641 | + * |
10642 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10643 | + * it under the terms of the GNU General Public License as published by | |
10644 | + * the Free Software Foundation; either version 2 of the License, or | |
10645 | + * (at your option) any later version. | |
10646 | + * | |
10647 | + * This program is distributed in the hope that it will be useful, | |
10648 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10649 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10650 | + * GNU General Public License for more details. | |
10651 | + * | |
10652 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10653 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
10654 | + */ |
10655 | + | |
10656 | +/* | |
10657 | + * dynamically customizable operations (for regular files only) | |
10658 | + */ | |
10659 | + | |
10660 | +#ifndef __AUFS_DYNOP_H__ | |
10661 | +#define __AUFS_DYNOP_H__ | |
10662 | + | |
10663 | +#ifdef __KERNEL__ | |
10664 | + | |
7e9cd9fe AM |
10665 | +#include <linux/fs.h> |
10666 | +#include <linux/kref.h> | |
4a4d8108 | 10667 | + |
2cbb1c4b | 10668 | +enum {AuDy_AOP, AuDyLast}; |
4a4d8108 AM |
10669 | + |
10670 | +struct au_dynop { | |
10671 | + int dy_type; | |
10672 | + union { | |
10673 | + const void *dy_hop; | |
10674 | + const struct address_space_operations *dy_haop; | |
4a4d8108 AM |
10675 | + }; |
10676 | +}; | |
10677 | + | |
10678 | +struct au_dykey { | |
10679 | + union { | |
10680 | + struct list_head dk_list; | |
10681 | + struct rcu_head dk_rcu; | |
10682 | + }; | |
10683 | + struct au_dynop dk_op; | |
10684 | + | |
10685 | + /* | |
10686 | + * during I am in the branch local array, kref is gotten. when the | |
10687 | + * branch is removed, kref is put. | |
10688 | + */ | |
10689 | + struct kref dk_kref; | |
10690 | +}; | |
10691 | + | |
10692 | +/* stop unioning since their sizes are very different from each other */ | |
10693 | +struct au_dyaop { | |
10694 | + struct au_dykey da_key; | |
10695 | + struct address_space_operations da_op; /* not const */ | |
4a4d8108 AM |
10696 | +}; |
10697 | + | |
4a4d8108 AM |
10698 | +/* ---------------------------------------------------------------------- */ |
10699 | + | |
10700 | +/* dynop.c */ | |
10701 | +struct au_branch; | |
10702 | +void au_dy_put(struct au_dykey *key); | |
10703 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
10704 | + struct inode *h_inode); | |
b752ccd1 | 10705 | +int au_dy_irefresh(struct inode *inode); |
4a4d8108 | 10706 | +void au_dy_arefresh(int do_dio); |
4a4d8108 AM |
10707 | + |
10708 | +void __init au_dy_init(void); | |
10709 | +void au_dy_fin(void); | |
10710 | + | |
4a4d8108 AM |
10711 | +#endif /* __KERNEL__ */ |
10712 | +#endif /* __AUFS_DYNOP_H__ */ | |
7f207e10 AM |
10713 | diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c |
10714 | --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
10715 | +++ linux/fs/aufs/export.c 2015-06-28 17:36:09.025073697 +0200 |
10716 | @@ -0,0 +1,832 @@ | |
4a4d8108 | 10717 | +/* |
2000de60 | 10718 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
10719 | + * |
10720 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10721 | + * it under the terms of the GNU General Public License as published by | |
10722 | + * the Free Software Foundation; either version 2 of the License, or | |
10723 | + * (at your option) any later version. | |
10724 | + * | |
10725 | + * This program is distributed in the hope that it will be useful, | |
10726 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10727 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10728 | + * GNU General Public License for more details. | |
10729 | + * | |
10730 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10731 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
10732 | + */ |
10733 | + | |
10734 | +/* | |
10735 | + * export via nfs | |
10736 | + */ | |
10737 | + | |
10738 | +#include <linux/exportfs.h> | |
7eafdf33 | 10739 | +#include <linux/fs_struct.h> |
4a4d8108 AM |
10740 | +#include <linux/namei.h> |
10741 | +#include <linux/nsproxy.h> | |
10742 | +#include <linux/random.h> | |
10743 | +#include <linux/writeback.h> | |
7eafdf33 | 10744 | +#include "../fs/mount.h" |
4a4d8108 AM |
10745 | +#include "aufs.h" |
10746 | + | |
10747 | +union conv { | |
10748 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10749 | + __u32 a[2]; | |
10750 | +#else | |
10751 | + __u32 a[1]; | |
10752 | +#endif | |
10753 | + ino_t ino; | |
10754 | +}; | |
10755 | + | |
10756 | +static ino_t decode_ino(__u32 *a) | |
10757 | +{ | |
10758 | + union conv u; | |
10759 | + | |
10760 | + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a)); | |
10761 | + u.a[0] = a[0]; | |
10762 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10763 | + u.a[1] = a[1]; | |
10764 | +#endif | |
10765 | + return u.ino; | |
10766 | +} | |
10767 | + | |
10768 | +static void encode_ino(__u32 *a, ino_t ino) | |
10769 | +{ | |
10770 | + union conv u; | |
10771 | + | |
10772 | + u.ino = ino; | |
10773 | + a[0] = u.a[0]; | |
10774 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10775 | + a[1] = u.a[1]; | |
10776 | +#endif | |
10777 | +} | |
10778 | + | |
10779 | +/* NFS file handle */ | |
10780 | +enum { | |
10781 | + Fh_br_id, | |
10782 | + Fh_sigen, | |
10783 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10784 | + /* support 64bit inode number */ | |
10785 | + Fh_ino1, | |
10786 | + Fh_ino2, | |
10787 | + Fh_dir_ino1, | |
10788 | + Fh_dir_ino2, | |
10789 | +#else | |
10790 | + Fh_ino1, | |
10791 | + Fh_dir_ino1, | |
10792 | +#endif | |
10793 | + Fh_igen, | |
10794 | + Fh_h_type, | |
10795 | + Fh_tail, | |
10796 | + | |
10797 | + Fh_ino = Fh_ino1, | |
10798 | + Fh_dir_ino = Fh_dir_ino1 | |
10799 | +}; | |
10800 | + | |
10801 | +static int au_test_anon(struct dentry *dentry) | |
10802 | +{ | |
027c5e7a | 10803 | + /* note: read d_flags without d_lock */ |
4a4d8108 AM |
10804 | + return !!(dentry->d_flags & DCACHE_DISCONNECTED); |
10805 | +} | |
10806 | + | |
a2a7ad62 AM |
10807 | +int au_test_nfsd(void) |
10808 | +{ | |
10809 | + int ret; | |
10810 | + struct task_struct *tsk = current; | |
10811 | + char comm[sizeof(tsk->comm)]; | |
10812 | + | |
10813 | + ret = 0; | |
10814 | + if (tsk->flags & PF_KTHREAD) { | |
10815 | + get_task_comm(comm, tsk); | |
10816 | + ret = !strcmp(comm, "nfsd"); | |
10817 | + } | |
10818 | + | |
10819 | + return ret; | |
10820 | +} | |
10821 | + | |
4a4d8108 AM |
10822 | +/* ---------------------------------------------------------------------- */ |
10823 | +/* inode generation external table */ | |
10824 | + | |
b752ccd1 | 10825 | +void au_xigen_inc(struct inode *inode) |
4a4d8108 | 10826 | +{ |
4a4d8108 AM |
10827 | + loff_t pos; |
10828 | + ssize_t sz; | |
10829 | + __u32 igen; | |
10830 | + struct super_block *sb; | |
10831 | + struct au_sbinfo *sbinfo; | |
10832 | + | |
4a4d8108 | 10833 | + sb = inode->i_sb; |
b752ccd1 | 10834 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); |
1facf9fc | 10835 | + |
b752ccd1 | 10836 | + sbinfo = au_sbi(sb); |
1facf9fc | 10837 | + pos = inode->i_ino; |
10838 | + pos *= sizeof(igen); | |
10839 | + igen = inode->i_generation + 1; | |
1facf9fc | 10840 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen, |
10841 | + sizeof(igen), &pos); | |
10842 | + if (sz == sizeof(igen)) | |
b752ccd1 | 10843 | + return; /* success */ |
1facf9fc | 10844 | + |
b752ccd1 | 10845 | + if (unlikely(sz >= 0)) |
1facf9fc | 10846 | + AuIOErr("xigen error (%zd)\n", sz); |
1facf9fc | 10847 | +} |
10848 | + | |
10849 | +int au_xigen_new(struct inode *inode) | |
10850 | +{ | |
10851 | + int err; | |
10852 | + loff_t pos; | |
10853 | + ssize_t sz; | |
10854 | + struct super_block *sb; | |
10855 | + struct au_sbinfo *sbinfo; | |
10856 | + struct file *file; | |
10857 | + | |
10858 | + err = 0; | |
10859 | + /* todo: dirty, at mount time */ | |
10860 | + if (inode->i_ino == AUFS_ROOT_INO) | |
10861 | + goto out; | |
10862 | + sb = inode->i_sb; | |
dece6358 | 10863 | + SiMustAnyLock(sb); |
1facf9fc | 10864 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) |
10865 | + goto out; | |
10866 | + | |
10867 | + err = -EFBIG; | |
10868 | + pos = inode->i_ino; | |
10869 | + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) { | |
10870 | + AuIOErr1("too large i%lld\n", pos); | |
10871 | + goto out; | |
10872 | + } | |
10873 | + pos *= sizeof(inode->i_generation); | |
10874 | + | |
10875 | + err = 0; | |
10876 | + sbinfo = au_sbi(sb); | |
10877 | + file = sbinfo->si_xigen; | |
10878 | + BUG_ON(!file); | |
10879 | + | |
c06a8ce3 | 10880 | + if (vfsub_f_size_read(file) |
1facf9fc | 10881 | + < pos + sizeof(inode->i_generation)) { |
10882 | + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next); | |
10883 | + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation, | |
10884 | + sizeof(inode->i_generation), &pos); | |
10885 | + } else | |
10886 | + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation, | |
10887 | + sizeof(inode->i_generation), &pos); | |
10888 | + if (sz == sizeof(inode->i_generation)) | |
10889 | + goto out; /* success */ | |
10890 | + | |
10891 | + err = sz; | |
10892 | + if (unlikely(sz >= 0)) { | |
10893 | + err = -EIO; | |
10894 | + AuIOErr("xigen error (%zd)\n", sz); | |
10895 | + } | |
10896 | + | |
4f0767ce | 10897 | +out: |
1facf9fc | 10898 | + return err; |
10899 | +} | |
10900 | + | |
10901 | +int au_xigen_set(struct super_block *sb, struct file *base) | |
10902 | +{ | |
10903 | + int err; | |
10904 | + struct au_sbinfo *sbinfo; | |
10905 | + struct file *file; | |
10906 | + | |
dece6358 AM |
10907 | + SiMustWriteLock(sb); |
10908 | + | |
1facf9fc | 10909 | + sbinfo = au_sbi(sb); |
10910 | + file = au_xino_create2(base, sbinfo->si_xigen); | |
10911 | + err = PTR_ERR(file); | |
10912 | + if (IS_ERR(file)) | |
10913 | + goto out; | |
10914 | + err = 0; | |
10915 | + if (sbinfo->si_xigen) | |
10916 | + fput(sbinfo->si_xigen); | |
10917 | + sbinfo->si_xigen = file; | |
10918 | + | |
4f0767ce | 10919 | +out: |
1facf9fc | 10920 | + return err; |
10921 | +} | |
10922 | + | |
10923 | +void au_xigen_clr(struct super_block *sb) | |
10924 | +{ | |
10925 | + struct au_sbinfo *sbinfo; | |
10926 | + | |
dece6358 AM |
10927 | + SiMustWriteLock(sb); |
10928 | + | |
1facf9fc | 10929 | + sbinfo = au_sbi(sb); |
10930 | + if (sbinfo->si_xigen) { | |
10931 | + fput(sbinfo->si_xigen); | |
10932 | + sbinfo->si_xigen = NULL; | |
10933 | + } | |
10934 | +} | |
10935 | + | |
10936 | +/* ---------------------------------------------------------------------- */ | |
10937 | + | |
10938 | +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino, | |
10939 | + ino_t dir_ino) | |
10940 | +{ | |
10941 | + struct dentry *dentry, *d; | |
10942 | + struct inode *inode; | |
10943 | + unsigned int sigen; | |
10944 | + | |
10945 | + dentry = NULL; | |
10946 | + inode = ilookup(sb, ino); | |
10947 | + if (!inode) | |
10948 | + goto out; | |
10949 | + | |
10950 | + dentry = ERR_PTR(-ESTALE); | |
10951 | + sigen = au_sigen(sb); | |
10952 | + if (unlikely(is_bad_inode(inode) | |
10953 | + || IS_DEADDIR(inode) | |
537831f9 | 10954 | + || sigen != au_iigen(inode, NULL))) |
1facf9fc | 10955 | + goto out_iput; |
10956 | + | |
10957 | + dentry = NULL; | |
10958 | + if (!dir_ino || S_ISDIR(inode->i_mode)) | |
10959 | + dentry = d_find_alias(inode); | |
10960 | + else { | |
027c5e7a | 10961 | + spin_lock(&inode->i_lock); |
c1595e42 | 10962 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 10963 | + spin_lock(&d->d_lock); |
1facf9fc | 10964 | + if (!au_test_anon(d) |
5527c038 | 10965 | + && d_inode(d->d_parent)->i_ino == dir_ino) { |
027c5e7a AM |
10966 | + dentry = dget_dlock(d); |
10967 | + spin_unlock(&d->d_lock); | |
1facf9fc | 10968 | + break; |
10969 | + } | |
027c5e7a AM |
10970 | + spin_unlock(&d->d_lock); |
10971 | + } | |
10972 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 10973 | + } |
027c5e7a | 10974 | + if (unlikely(dentry && au_digen_test(dentry, sigen))) { |
2cbb1c4b | 10975 | + /* need to refresh */ |
1facf9fc | 10976 | + dput(dentry); |
2cbb1c4b | 10977 | + dentry = NULL; |
1facf9fc | 10978 | + } |
10979 | + | |
4f0767ce | 10980 | +out_iput: |
1facf9fc | 10981 | + iput(inode); |
4f0767ce | 10982 | +out: |
2cbb1c4b | 10983 | + AuTraceErrPtr(dentry); |
1facf9fc | 10984 | + return dentry; |
10985 | +} | |
10986 | + | |
10987 | +/* ---------------------------------------------------------------------- */ | |
10988 | + | |
10989 | +/* todo: dirty? */ | |
10990 | +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */ | |
4a4d8108 AM |
10991 | + |
10992 | +struct au_compare_mnt_args { | |
10993 | + /* input */ | |
10994 | + struct super_block *sb; | |
10995 | + | |
10996 | + /* output */ | |
10997 | + struct vfsmount *mnt; | |
10998 | +}; | |
10999 | + | |
11000 | +static int au_compare_mnt(struct vfsmount *mnt, void *arg) | |
11001 | +{ | |
11002 | + struct au_compare_mnt_args *a = arg; | |
11003 | + | |
11004 | + if (mnt->mnt_sb != a->sb) | |
11005 | + return 0; | |
11006 | + a->mnt = mntget(mnt); | |
11007 | + return 1; | |
11008 | +} | |
11009 | + | |
1facf9fc | 11010 | +static struct vfsmount *au_mnt_get(struct super_block *sb) |
11011 | +{ | |
4a4d8108 | 11012 | + int err; |
7eafdf33 | 11013 | + struct path root; |
4a4d8108 AM |
11014 | + struct au_compare_mnt_args args = { |
11015 | + .sb = sb | |
11016 | + }; | |
1facf9fc | 11017 | + |
7eafdf33 | 11018 | + get_fs_root(current->fs, &root); |
523b37e3 | 11019 | + rcu_read_lock(); |
7eafdf33 | 11020 | + err = iterate_mounts(au_compare_mnt, &args, root.mnt); |
523b37e3 | 11021 | + rcu_read_unlock(); |
7eafdf33 | 11022 | + path_put(&root); |
4a4d8108 AM |
11023 | + AuDebugOn(!err); |
11024 | + AuDebugOn(!args.mnt); | |
11025 | + return args.mnt; | |
1facf9fc | 11026 | +} |
11027 | + | |
11028 | +struct au_nfsd_si_lock { | |
4a4d8108 | 11029 | + unsigned int sigen; |
027c5e7a | 11030 | + aufs_bindex_t bindex, br_id; |
1facf9fc | 11031 | + unsigned char force_lock; |
11032 | +}; | |
11033 | + | |
027c5e7a AM |
11034 | +static int si_nfsd_read_lock(struct super_block *sb, |
11035 | + struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 11036 | +{ |
027c5e7a | 11037 | + int err; |
1facf9fc | 11038 | + aufs_bindex_t bindex; |
11039 | + | |
11040 | + si_read_lock(sb, AuLock_FLUSH); | |
11041 | + | |
11042 | + /* branch id may be wrapped around */ | |
027c5e7a | 11043 | + err = 0; |
1facf9fc | 11044 | + bindex = au_br_index(sb, nsi_lock->br_id); |
11045 | + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb)) | |
11046 | + goto out; /* success */ | |
11047 | + | |
027c5e7a AM |
11048 | + err = -ESTALE; |
11049 | + bindex = -1; | |
1facf9fc | 11050 | + if (!nsi_lock->force_lock) |
11051 | + si_read_unlock(sb); | |
1facf9fc | 11052 | + |
4f0767ce | 11053 | +out: |
027c5e7a AM |
11054 | + nsi_lock->bindex = bindex; |
11055 | + return err; | |
1facf9fc | 11056 | +} |
11057 | + | |
11058 | +struct find_name_by_ino { | |
392086de | 11059 | + struct dir_context ctx; |
1facf9fc | 11060 | + int called, found; |
11061 | + ino_t ino; | |
11062 | + char *name; | |
11063 | + int namelen; | |
11064 | +}; | |
11065 | + | |
11066 | +static int | |
392086de AM |
11067 | +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen, |
11068 | + loff_t offset, u64 ino, unsigned int d_type) | |
1facf9fc | 11069 | +{ |
392086de AM |
11070 | + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino, |
11071 | + ctx); | |
1facf9fc | 11072 | + |
11073 | + a->called++; | |
11074 | + if (a->ino != ino) | |
11075 | + return 0; | |
11076 | + | |
11077 | + memcpy(a->name, name, namelen); | |
11078 | + a->namelen = namelen; | |
11079 | + a->found = 1; | |
11080 | + return 1; | |
11081 | +} | |
11082 | + | |
11083 | +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino, | |
11084 | + struct au_nfsd_si_lock *nsi_lock) | |
11085 | +{ | |
11086 | + struct dentry *dentry, *parent; | |
11087 | + struct file *file; | |
11088 | + struct inode *dir; | |
392086de AM |
11089 | + struct find_name_by_ino arg = { |
11090 | + .ctx = { | |
2000de60 | 11091 | + .actor = find_name_by_ino |
392086de AM |
11092 | + } |
11093 | + }; | |
1facf9fc | 11094 | + int err; |
11095 | + | |
11096 | + parent = path->dentry; | |
11097 | + if (nsi_lock) | |
11098 | + si_read_unlock(parent->d_sb); | |
4a4d8108 | 11099 | + file = vfsub_dentry_open(path, au_dir_roflags); |
1facf9fc | 11100 | + dentry = (void *)file; |
11101 | + if (IS_ERR(file)) | |
11102 | + goto out; | |
11103 | + | |
11104 | + dentry = ERR_PTR(-ENOMEM); | |
537831f9 | 11105 | + arg.name = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 11106 | + if (unlikely(!arg.name)) |
11107 | + goto out_file; | |
11108 | + arg.ino = ino; | |
11109 | + arg.found = 0; | |
11110 | + do { | |
11111 | + arg.called = 0; | |
11112 | + /* smp_mb(); */ | |
392086de | 11113 | + err = vfsub_iterate_dir(file, &arg.ctx); |
1facf9fc | 11114 | + } while (!err && !arg.found && arg.called); |
11115 | + dentry = ERR_PTR(err); | |
11116 | + if (unlikely(err)) | |
11117 | + goto out_name; | |
1716fcea AM |
11118 | + /* instead of ENOENT */ |
11119 | + dentry = ERR_PTR(-ESTALE); | |
1facf9fc | 11120 | + if (!arg.found) |
11121 | + goto out_name; | |
11122 | + | |
b4510431 | 11123 | + /* do not call vfsub_lkup_one() */ |
5527c038 | 11124 | + dir = d_inode(parent); |
1facf9fc | 11125 | + mutex_lock(&dir->i_mutex); |
11126 | + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen); | |
11127 | + mutex_unlock(&dir->i_mutex); | |
11128 | + AuTraceErrPtr(dentry); | |
11129 | + if (IS_ERR(dentry)) | |
11130 | + goto out_name; | |
11131 | + AuDebugOn(au_test_anon(dentry)); | |
5527c038 | 11132 | + if (unlikely(d_really_is_negative(dentry))) { |
1facf9fc | 11133 | + dput(dentry); |
11134 | + dentry = ERR_PTR(-ENOENT); | |
11135 | + } | |
11136 | + | |
4f0767ce | 11137 | +out_name: |
537831f9 | 11138 | + free_page((unsigned long)arg.name); |
4f0767ce | 11139 | +out_file: |
1facf9fc | 11140 | + fput(file); |
4f0767ce | 11141 | +out: |
1facf9fc | 11142 | + if (unlikely(nsi_lock |
11143 | + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0)) | |
11144 | + if (!IS_ERR(dentry)) { | |
11145 | + dput(dentry); | |
11146 | + dentry = ERR_PTR(-ESTALE); | |
11147 | + } | |
11148 | + AuTraceErrPtr(dentry); | |
11149 | + return dentry; | |
11150 | +} | |
11151 | + | |
11152 | +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino, | |
11153 | + ino_t dir_ino, | |
11154 | + struct au_nfsd_si_lock *nsi_lock) | |
11155 | +{ | |
11156 | + struct dentry *dentry; | |
11157 | + struct path path; | |
11158 | + | |
11159 | + if (dir_ino != AUFS_ROOT_INO) { | |
11160 | + path.dentry = decode_by_ino(sb, dir_ino, 0); | |
11161 | + dentry = path.dentry; | |
11162 | + if (!path.dentry || IS_ERR(path.dentry)) | |
11163 | + goto out; | |
11164 | + AuDebugOn(au_test_anon(path.dentry)); | |
11165 | + } else | |
11166 | + path.dentry = dget(sb->s_root); | |
11167 | + | |
11168 | + path.mnt = au_mnt_get(sb); | |
11169 | + dentry = au_lkup_by_ino(&path, ino, nsi_lock); | |
11170 | + path_put(&path); | |
11171 | + | |
4f0767ce | 11172 | +out: |
1facf9fc | 11173 | + AuTraceErrPtr(dentry); |
11174 | + return dentry; | |
11175 | +} | |
11176 | + | |
11177 | +/* ---------------------------------------------------------------------- */ | |
11178 | + | |
11179 | +static int h_acceptable(void *expv, struct dentry *dentry) | |
11180 | +{ | |
11181 | + return 1; | |
11182 | +} | |
11183 | + | |
11184 | +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath, | |
11185 | + char *buf, int len, struct super_block *sb) | |
11186 | +{ | |
11187 | + char *p; | |
11188 | + int n; | |
11189 | + struct path path; | |
11190 | + | |
11191 | + p = d_path(h_rootpath, buf, len); | |
11192 | + if (IS_ERR(p)) | |
11193 | + goto out; | |
11194 | + n = strlen(p); | |
11195 | + | |
11196 | + path.mnt = h_rootpath->mnt; | |
11197 | + path.dentry = h_parent; | |
11198 | + p = d_path(&path, buf, len); | |
11199 | + if (IS_ERR(p)) | |
11200 | + goto out; | |
11201 | + if (n != 1) | |
11202 | + p += n; | |
11203 | + | |
11204 | + path.mnt = au_mnt_get(sb); | |
11205 | + path.dentry = sb->s_root; | |
11206 | + p = d_path(&path, buf, len - strlen(p)); | |
11207 | + mntput(path.mnt); | |
11208 | + if (IS_ERR(p)) | |
11209 | + goto out; | |
11210 | + if (n != 1) | |
11211 | + p[strlen(p)] = '/'; | |
11212 | + | |
4f0767ce | 11213 | +out: |
1facf9fc | 11214 | + AuTraceErrPtr(p); |
11215 | + return p; | |
11216 | +} | |
11217 | + | |
11218 | +static | |
027c5e7a AM |
11219 | +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh, |
11220 | + int fh_len, struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 11221 | +{ |
11222 | + struct dentry *dentry, *h_parent, *root; | |
11223 | + struct super_block *h_sb; | |
11224 | + char *pathname, *p; | |
11225 | + struct vfsmount *h_mnt; | |
11226 | + struct au_branch *br; | |
11227 | + int err; | |
11228 | + struct path path; | |
11229 | + | |
027c5e7a | 11230 | + br = au_sbr(sb, nsi_lock->bindex); |
86dc4139 | 11231 | + h_mnt = au_br_mnt(br); |
1facf9fc | 11232 | + h_sb = h_mnt->mnt_sb; |
11233 | + /* todo: call lower fh_to_dentry()? fh_to_parent()? */ | |
11234 | + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail), | |
11235 | + fh_len - Fh_tail, fh[Fh_h_type], | |
11236 | + h_acceptable, /*context*/NULL); | |
11237 | + dentry = h_parent; | |
11238 | + if (unlikely(!h_parent || IS_ERR(h_parent))) { | |
11239 | + AuWarn1("%s decode_fh failed, %ld\n", | |
11240 | + au_sbtype(h_sb), PTR_ERR(h_parent)); | |
11241 | + goto out; | |
11242 | + } | |
11243 | + dentry = NULL; | |
11244 | + if (unlikely(au_test_anon(h_parent))) { | |
11245 | + AuWarn1("%s decode_fh returned a disconnected dentry\n", | |
11246 | + au_sbtype(h_sb)); | |
11247 | + goto out_h_parent; | |
11248 | + } | |
11249 | + | |
11250 | + dentry = ERR_PTR(-ENOMEM); | |
11251 | + pathname = (void *)__get_free_page(GFP_NOFS); | |
11252 | + if (unlikely(!pathname)) | |
11253 | + goto out_h_parent; | |
11254 | + | |
11255 | + root = sb->s_root; | |
11256 | + path.mnt = h_mnt; | |
11257 | + di_read_lock_parent(root, !AuLock_IR); | |
027c5e7a | 11258 | + path.dentry = au_h_dptr(root, nsi_lock->bindex); |
1facf9fc | 11259 | + di_read_unlock(root, !AuLock_IR); |
11260 | + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb); | |
11261 | + dentry = (void *)p; | |
11262 | + if (IS_ERR(p)) | |
11263 | + goto out_pathname; | |
11264 | + | |
11265 | + si_read_unlock(sb); | |
11266 | + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | |
11267 | + dentry = ERR_PTR(err); | |
11268 | + if (unlikely(err)) | |
11269 | + goto out_relock; | |
11270 | + | |
11271 | + dentry = ERR_PTR(-ENOENT); | |
11272 | + AuDebugOn(au_test_anon(path.dentry)); | |
5527c038 | 11273 | + if (unlikely(d_really_is_negative(path.dentry))) |
1facf9fc | 11274 | + goto out_path; |
11275 | + | |
5527c038 | 11276 | + if (ino != d_inode(path.dentry)->i_ino) |
1facf9fc | 11277 | + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL); |
11278 | + else | |
11279 | + dentry = dget(path.dentry); | |
11280 | + | |
4f0767ce | 11281 | +out_path: |
1facf9fc | 11282 | + path_put(&path); |
4f0767ce | 11283 | +out_relock: |
1facf9fc | 11284 | + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0)) |
11285 | + if (!IS_ERR(dentry)) { | |
11286 | + dput(dentry); | |
11287 | + dentry = ERR_PTR(-ESTALE); | |
11288 | + } | |
4f0767ce | 11289 | +out_pathname: |
1facf9fc | 11290 | + free_page((unsigned long)pathname); |
4f0767ce | 11291 | +out_h_parent: |
1facf9fc | 11292 | + dput(h_parent); |
4f0767ce | 11293 | +out: |
1facf9fc | 11294 | + AuTraceErrPtr(dentry); |
11295 | + return dentry; | |
11296 | +} | |
11297 | + | |
11298 | +/* ---------------------------------------------------------------------- */ | |
11299 | + | |
11300 | +static struct dentry * | |
11301 | +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, | |
11302 | + int fh_type) | |
11303 | +{ | |
11304 | + struct dentry *dentry; | |
11305 | + __u32 *fh = fid->raw; | |
027c5e7a | 11306 | + struct au_branch *br; |
1facf9fc | 11307 | + ino_t ino, dir_ino; |
1facf9fc | 11308 | + struct au_nfsd_si_lock nsi_lock = { |
1facf9fc | 11309 | + .force_lock = 0 |
11310 | + }; | |
11311 | + | |
1facf9fc | 11312 | + dentry = ERR_PTR(-ESTALE); |
4a4d8108 AM |
11313 | + /* it should never happen, but the file handle is unreliable */ |
11314 | + if (unlikely(fh_len < Fh_tail)) | |
11315 | + goto out; | |
11316 | + nsi_lock.sigen = fh[Fh_sigen]; | |
11317 | + nsi_lock.br_id = fh[Fh_br_id]; | |
11318 | + | |
1facf9fc | 11319 | + /* branch id may be wrapped around */ |
027c5e7a AM |
11320 | + br = NULL; |
11321 | + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock))) | |
1facf9fc | 11322 | + goto out; |
11323 | + nsi_lock.force_lock = 1; | |
11324 | + | |
11325 | + /* is this inode still cached? */ | |
11326 | + ino = decode_ino(fh + Fh_ino); | |
4a4d8108 AM |
11327 | + /* it should never happen */ |
11328 | + if (unlikely(ino == AUFS_ROOT_INO)) | |
11329 | + goto out; | |
11330 | + | |
1facf9fc | 11331 | + dir_ino = decode_ino(fh + Fh_dir_ino); |
11332 | + dentry = decode_by_ino(sb, ino, dir_ino); | |
11333 | + if (IS_ERR(dentry)) | |
11334 | + goto out_unlock; | |
11335 | + if (dentry) | |
11336 | + goto accept; | |
11337 | + | |
11338 | + /* is the parent dir cached? */ | |
027c5e7a AM |
11339 | + br = au_sbr(sb, nsi_lock.bindex); |
11340 | + atomic_inc(&br->br_count); | |
1facf9fc | 11341 | + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock); |
11342 | + if (IS_ERR(dentry)) | |
11343 | + goto out_unlock; | |
11344 | + if (dentry) | |
11345 | + goto accept; | |
11346 | + | |
11347 | + /* lookup path */ | |
027c5e7a | 11348 | + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock); |
1facf9fc | 11349 | + if (IS_ERR(dentry)) |
11350 | + goto out_unlock; | |
11351 | + if (unlikely(!dentry)) | |
11352 | + /* todo?: make it ESTALE */ | |
11353 | + goto out_unlock; | |
11354 | + | |
4f0767ce | 11355 | +accept: |
027c5e7a | 11356 | + if (!au_digen_test(dentry, au_sigen(sb)) |
5527c038 | 11357 | + && d_inode(dentry)->i_generation == fh[Fh_igen]) |
1facf9fc | 11358 | + goto out_unlock; /* success */ |
11359 | + | |
11360 | + dput(dentry); | |
11361 | + dentry = ERR_PTR(-ESTALE); | |
4f0767ce | 11362 | +out_unlock: |
027c5e7a AM |
11363 | + if (br) |
11364 | + atomic_dec(&br->br_count); | |
1facf9fc | 11365 | + si_read_unlock(sb); |
4f0767ce | 11366 | +out: |
1facf9fc | 11367 | + AuTraceErrPtr(dentry); |
11368 | + return dentry; | |
11369 | +} | |
11370 | + | |
11371 | +#if 0 /* reserved for future use */ | |
11372 | +/* support subtreecheck option */ | |
11373 | +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid, | |
11374 | + int fh_len, int fh_type) | |
11375 | +{ | |
11376 | + struct dentry *parent; | |
11377 | + __u32 *fh = fid->raw; | |
11378 | + ino_t dir_ino; | |
11379 | + | |
11380 | + dir_ino = decode_ino(fh + Fh_dir_ino); | |
11381 | + parent = decode_by_ino(sb, dir_ino, 0); | |
11382 | + if (IS_ERR(parent)) | |
11383 | + goto out; | |
11384 | + if (!parent) | |
11385 | + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]), | |
11386 | + dir_ino, fh, fh_len); | |
11387 | + | |
4f0767ce | 11388 | +out: |
1facf9fc | 11389 | + AuTraceErrPtr(parent); |
11390 | + return parent; | |
11391 | +} | |
11392 | +#endif | |
11393 | + | |
11394 | +/* ---------------------------------------------------------------------- */ | |
11395 | + | |
0c3ec466 AM |
11396 | +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, |
11397 | + struct inode *dir) | |
1facf9fc | 11398 | +{ |
11399 | + int err; | |
0c3ec466 | 11400 | + aufs_bindex_t bindex; |
1facf9fc | 11401 | + struct super_block *sb, *h_sb; |
0c3ec466 AM |
11402 | + struct dentry *dentry, *parent, *h_parent; |
11403 | + struct inode *h_dir; | |
1facf9fc | 11404 | + struct au_branch *br; |
11405 | + | |
1facf9fc | 11406 | + err = -ENOSPC; |
11407 | + if (unlikely(*max_len <= Fh_tail)) { | |
11408 | + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len); | |
11409 | + goto out; | |
11410 | + } | |
11411 | + | |
11412 | + err = FILEID_ROOT; | |
0c3ec466 AM |
11413 | + if (inode->i_ino == AUFS_ROOT_INO) { |
11414 | + AuDebugOn(inode->i_ino != AUFS_ROOT_INO); | |
1facf9fc | 11415 | + goto out; |
11416 | + } | |
11417 | + | |
1facf9fc | 11418 | + h_parent = NULL; |
0c3ec466 AM |
11419 | + sb = inode->i_sb; |
11420 | + err = si_read_lock(sb, AuLock_FLUSH); | |
027c5e7a AM |
11421 | + if (unlikely(err)) |
11422 | + goto out; | |
11423 | + | |
1facf9fc | 11424 | +#ifdef CONFIG_AUFS_DEBUG |
11425 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) | |
11426 | + AuWarn1("NFS-exporting requires xino\n"); | |
11427 | +#endif | |
027c5e7a | 11428 | + err = -EIO; |
0c3ec466 AM |
11429 | + parent = NULL; |
11430 | + ii_read_lock_child(inode); | |
11431 | + bindex = au_ibstart(inode); | |
11432 | + if (!dir) { | |
c1595e42 | 11433 | + dentry = d_find_any_alias(inode); |
0c3ec466 AM |
11434 | + if (unlikely(!dentry)) |
11435 | + goto out_unlock; | |
11436 | + AuDebugOn(au_test_anon(dentry)); | |
11437 | + parent = dget_parent(dentry); | |
11438 | + dput(dentry); | |
11439 | + if (unlikely(!parent)) | |
11440 | + goto out_unlock; | |
5527c038 JR |
11441 | + if (d_really_is_positive(parent)) |
11442 | + dir = d_inode(parent); | |
1facf9fc | 11443 | + } |
0c3ec466 AM |
11444 | + |
11445 | + ii_read_lock_parent(dir); | |
11446 | + h_dir = au_h_iptr(dir, bindex); | |
11447 | + ii_read_unlock(dir); | |
11448 | + if (unlikely(!h_dir)) | |
11449 | + goto out_parent; | |
c1595e42 | 11450 | + h_parent = d_find_any_alias(h_dir); |
1facf9fc | 11451 | + if (unlikely(!h_parent)) |
0c3ec466 | 11452 | + goto out_hparent; |
1facf9fc | 11453 | + |
11454 | + err = -EPERM; | |
11455 | + br = au_sbr(sb, bindex); | |
86dc4139 | 11456 | + h_sb = au_br_sb(br); |
1facf9fc | 11457 | + if (unlikely(!h_sb->s_export_op)) { |
11458 | + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb)); | |
0c3ec466 | 11459 | + goto out_hparent; |
1facf9fc | 11460 | + } |
11461 | + | |
11462 | + fh[Fh_br_id] = br->br_id; | |
11463 | + fh[Fh_sigen] = au_sigen(sb); | |
11464 | + encode_ino(fh + Fh_ino, inode->i_ino); | |
0c3ec466 | 11465 | + encode_ino(fh + Fh_dir_ino, dir->i_ino); |
1facf9fc | 11466 | + fh[Fh_igen] = inode->i_generation; |
11467 | + | |
11468 | + *max_len -= Fh_tail; | |
11469 | + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail), | |
11470 | + max_len, | |
11471 | + /*connectable or subtreecheck*/0); | |
11472 | + err = fh[Fh_h_type]; | |
11473 | + *max_len += Fh_tail; | |
11474 | + /* todo: macros? */ | |
1716fcea | 11475 | + if (err != FILEID_INVALID) |
1facf9fc | 11476 | + err = 99; |
11477 | + else | |
11478 | + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb)); | |
11479 | + | |
0c3ec466 | 11480 | +out_hparent: |
1facf9fc | 11481 | + dput(h_parent); |
0c3ec466 | 11482 | +out_parent: |
1facf9fc | 11483 | + dput(parent); |
0c3ec466 AM |
11484 | +out_unlock: |
11485 | + ii_read_unlock(inode); | |
11486 | + si_read_unlock(sb); | |
4f0767ce | 11487 | +out: |
1facf9fc | 11488 | + if (unlikely(err < 0)) |
1716fcea | 11489 | + err = FILEID_INVALID; |
1facf9fc | 11490 | + return err; |
11491 | +} | |
11492 | + | |
11493 | +/* ---------------------------------------------------------------------- */ | |
11494 | + | |
4a4d8108 AM |
11495 | +static int aufs_commit_metadata(struct inode *inode) |
11496 | +{ | |
11497 | + int err; | |
11498 | + aufs_bindex_t bindex; | |
11499 | + struct super_block *sb; | |
11500 | + struct inode *h_inode; | |
11501 | + int (*f)(struct inode *inode); | |
11502 | + | |
11503 | + sb = inode->i_sb; | |
e49829fe | 11504 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 AM |
11505 | + ii_write_lock_child(inode); |
11506 | + bindex = au_ibstart(inode); | |
11507 | + AuDebugOn(bindex < 0); | |
11508 | + h_inode = au_h_iptr(inode, bindex); | |
11509 | + | |
11510 | + f = h_inode->i_sb->s_export_op->commit_metadata; | |
11511 | + if (f) | |
11512 | + err = f(h_inode); | |
11513 | + else { | |
11514 | + struct writeback_control wbc = { | |
11515 | + .sync_mode = WB_SYNC_ALL, | |
11516 | + .nr_to_write = 0 /* metadata only */ | |
11517 | + }; | |
11518 | + | |
11519 | + err = sync_inode(h_inode, &wbc); | |
11520 | + } | |
11521 | + | |
11522 | + au_cpup_attr_timesizes(inode); | |
11523 | + ii_write_unlock(inode); | |
11524 | + si_read_unlock(sb); | |
11525 | + return err; | |
11526 | +} | |
11527 | + | |
11528 | +/* ---------------------------------------------------------------------- */ | |
11529 | + | |
1facf9fc | 11530 | +static struct export_operations aufs_export_op = { |
4a4d8108 | 11531 | + .fh_to_dentry = aufs_fh_to_dentry, |
1facf9fc | 11532 | + /* .fh_to_parent = aufs_fh_to_parent, */ |
4a4d8108 AM |
11533 | + .encode_fh = aufs_encode_fh, |
11534 | + .commit_metadata = aufs_commit_metadata | |
1facf9fc | 11535 | +}; |
11536 | + | |
11537 | +void au_export_init(struct super_block *sb) | |
11538 | +{ | |
11539 | + struct au_sbinfo *sbinfo; | |
11540 | + __u32 u; | |
11541 | + | |
11542 | + sb->s_export_op = &aufs_export_op; | |
11543 | + sbinfo = au_sbi(sb); | |
11544 | + sbinfo->si_xigen = NULL; | |
11545 | + get_random_bytes(&u, sizeof(u)); | |
11546 | + BUILD_BUG_ON(sizeof(u) != sizeof(int)); | |
11547 | + atomic_set(&sbinfo->si_xigen_next, u); | |
11548 | +} | |
076b876e AM |
11549 | diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c |
11550 | --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 11551 | +++ linux/fs/aufs/fhsm.c 2015-06-28 17:35:44.348050491 +0200 |
c1595e42 | 11552 | @@ -0,0 +1,426 @@ |
076b876e | 11553 | +/* |
2000de60 | 11554 | + * Copyright (C) 2011-2015 Junjiro R. Okajima |
076b876e AM |
11555 | + * |
11556 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11557 | + * it under the terms of the GNU General Public License as published by | |
11558 | + * the Free Software Foundation; either version 2 of the License, or | |
11559 | + * (at your option) any later version. | |
11560 | + * | |
11561 | + * This program is distributed in the hope that it will be useful, | |
11562 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11563 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11564 | + * GNU General Public License for more details. | |
11565 | + * | |
11566 | + * You should have received a copy of the GNU General Public License | |
11567 | + * along with this program; if not, write to the Free Software | |
11568 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
11569 | + */ | |
11570 | + | |
11571 | +/* | |
11572 | + * File-based Hierarchy Storage Management | |
11573 | + */ | |
11574 | + | |
11575 | +#include <linux/anon_inodes.h> | |
11576 | +#include <linux/poll.h> | |
11577 | +#include <linux/seq_file.h> | |
11578 | +#include <linux/statfs.h> | |
11579 | +#include "aufs.h" | |
11580 | + | |
c1595e42 JR |
11581 | +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb) |
11582 | +{ | |
11583 | + struct au_sbinfo *sbinfo; | |
11584 | + struct au_fhsm *fhsm; | |
11585 | + | |
11586 | + SiMustAnyLock(sb); | |
11587 | + | |
11588 | + sbinfo = au_sbi(sb); | |
11589 | + fhsm = &sbinfo->si_fhsm; | |
11590 | + AuDebugOn(!fhsm); | |
11591 | + return fhsm->fhsm_bottom; | |
11592 | +} | |
11593 | + | |
11594 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex) | |
11595 | +{ | |
11596 | + struct au_sbinfo *sbinfo; | |
11597 | + struct au_fhsm *fhsm; | |
11598 | + | |
11599 | + SiMustWriteLock(sb); | |
11600 | + | |
11601 | + sbinfo = au_sbi(sb); | |
11602 | + fhsm = &sbinfo->si_fhsm; | |
11603 | + AuDebugOn(!fhsm); | |
11604 | + fhsm->fhsm_bottom = bindex; | |
11605 | +} | |
11606 | + | |
11607 | +/* ---------------------------------------------------------------------- */ | |
11608 | + | |
076b876e AM |
11609 | +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br) |
11610 | +{ | |
11611 | + struct au_br_fhsm *bf; | |
11612 | + | |
11613 | + bf = br->br_fhsm; | |
11614 | + MtxMustLock(&bf->bf_lock); | |
11615 | + | |
11616 | + return !bf->bf_readable | |
11617 | + || time_after(jiffies, | |
11618 | + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire); | |
11619 | +} | |
11620 | + | |
11621 | +/* ---------------------------------------------------------------------- */ | |
11622 | + | |
11623 | +static void au_fhsm_notify(struct super_block *sb, int val) | |
11624 | +{ | |
11625 | + struct au_sbinfo *sbinfo; | |
11626 | + struct au_fhsm *fhsm; | |
11627 | + | |
11628 | + SiMustAnyLock(sb); | |
11629 | + | |
11630 | + sbinfo = au_sbi(sb); | |
11631 | + fhsm = &sbinfo->si_fhsm; | |
11632 | + if (au_fhsm_pid(fhsm) | |
11633 | + && atomic_read(&fhsm->fhsm_readable) != -1) { | |
11634 | + atomic_set(&fhsm->fhsm_readable, val); | |
11635 | + if (val) | |
11636 | + wake_up(&fhsm->fhsm_wqh); | |
11637 | + } | |
11638 | +} | |
11639 | + | |
11640 | +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex, | |
11641 | + struct aufs_stfs *rstfs, int do_lock, int do_notify) | |
11642 | +{ | |
11643 | + int err; | |
11644 | + struct au_branch *br; | |
11645 | + struct au_br_fhsm *bf; | |
11646 | + | |
11647 | + br = au_sbr(sb, bindex); | |
11648 | + AuDebugOn(au_br_rdonly(br)); | |
11649 | + bf = br->br_fhsm; | |
11650 | + AuDebugOn(!bf); | |
11651 | + | |
11652 | + if (do_lock) | |
11653 | + mutex_lock(&bf->bf_lock); | |
11654 | + else | |
11655 | + MtxMustLock(&bf->bf_lock); | |
11656 | + | |
11657 | + /* sb->s_root for NFS is unreliable */ | |
11658 | + err = au_br_stfs(br, &bf->bf_stfs); | |
11659 | + if (unlikely(err)) { | |
11660 | + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err); | |
11661 | + goto out; | |
11662 | + } | |
11663 | + | |
11664 | + bf->bf_jiffy = jiffies; | |
11665 | + bf->bf_readable = 1; | |
11666 | + if (do_notify) | |
11667 | + au_fhsm_notify(sb, /*val*/1); | |
11668 | + if (rstfs) | |
11669 | + *rstfs = bf->bf_stfs; | |
11670 | + | |
11671 | +out: | |
11672 | + if (do_lock) | |
11673 | + mutex_unlock(&bf->bf_lock); | |
11674 | + au_fhsm_notify(sb, /*val*/1); | |
11675 | + | |
11676 | + return err; | |
11677 | +} | |
11678 | + | |
11679 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force) | |
11680 | +{ | |
11681 | + int err; | |
076b876e AM |
11682 | + struct au_sbinfo *sbinfo; |
11683 | + struct au_fhsm *fhsm; | |
11684 | + struct au_branch *br; | |
11685 | + struct au_br_fhsm *bf; | |
11686 | + | |
11687 | + AuDbg("b%d, force %d\n", bindex, force); | |
11688 | + SiMustAnyLock(sb); | |
11689 | + | |
11690 | + sbinfo = au_sbi(sb); | |
11691 | + fhsm = &sbinfo->si_fhsm; | |
c1595e42 JR |
11692 | + if (!au_ftest_si(sbinfo, FHSM) |
11693 | + || fhsm->fhsm_bottom == bindex) | |
076b876e AM |
11694 | + return; |
11695 | + | |
11696 | + br = au_sbr(sb, bindex); | |
11697 | + bf = br->br_fhsm; | |
11698 | + AuDebugOn(!bf); | |
11699 | + mutex_lock(&bf->bf_lock); | |
11700 | + if (force | |
11701 | + || au_fhsm_pid(fhsm) | |
11702 | + || au_fhsm_test_jiffy(sbinfo, br)) | |
11703 | + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0, | |
11704 | + /*do_notify*/1); | |
11705 | + mutex_unlock(&bf->bf_lock); | |
11706 | +} | |
11707 | + | |
11708 | +void au_fhsm_wrote_all(struct super_block *sb, int force) | |
11709 | +{ | |
11710 | + aufs_bindex_t bindex, bend; | |
11711 | + struct au_branch *br; | |
11712 | + | |
11713 | + /* exclude the bottom */ | |
c1595e42 | 11714 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11715 | + for (bindex = 0; bindex < bend; bindex++) { |
11716 | + br = au_sbr(sb, bindex); | |
11717 | + if (au_br_fhsm(br->br_perm)) | |
11718 | + au_fhsm_wrote(sb, bindex, force); | |
11719 | + } | |
11720 | +} | |
11721 | + | |
11722 | +/* ---------------------------------------------------------------------- */ | |
11723 | + | |
11724 | +static unsigned int au_fhsm_poll(struct file *file, | |
11725 | + struct poll_table_struct *wait) | |
11726 | +{ | |
11727 | + unsigned int mask; | |
11728 | + struct au_sbinfo *sbinfo; | |
11729 | + struct au_fhsm *fhsm; | |
11730 | + | |
11731 | + mask = 0; | |
11732 | + sbinfo = file->private_data; | |
11733 | + fhsm = &sbinfo->si_fhsm; | |
11734 | + poll_wait(file, &fhsm->fhsm_wqh, wait); | |
11735 | + if (atomic_read(&fhsm->fhsm_readable)) | |
11736 | + mask = POLLIN /* | POLLRDNORM */; | |
11737 | + | |
11738 | + AuTraceErr((int)mask); | |
11739 | + return mask; | |
11740 | +} | |
11741 | + | |
11742 | +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr, | |
11743 | + struct aufs_stfs *stfs, __s16 brid) | |
11744 | +{ | |
11745 | + int err; | |
11746 | + | |
11747 | + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs)); | |
11748 | + if (!err) | |
11749 | + err = __put_user(brid, &stbr->brid); | |
11750 | + if (unlikely(err)) | |
11751 | + err = -EFAULT; | |
11752 | + | |
11753 | + return err; | |
11754 | +} | |
11755 | + | |
11756 | +static ssize_t au_fhsm_do_read(struct super_block *sb, | |
11757 | + struct aufs_stbr __user *stbr, size_t count) | |
11758 | +{ | |
11759 | + ssize_t err; | |
11760 | + int nstbr; | |
11761 | + aufs_bindex_t bindex, bend; | |
11762 | + struct au_branch *br; | |
11763 | + struct au_br_fhsm *bf; | |
11764 | + | |
11765 | + /* except the bottom branch */ | |
11766 | + err = 0; | |
11767 | + nstbr = 0; | |
c1595e42 | 11768 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11769 | + for (bindex = 0; !err && bindex < bend; bindex++) { |
11770 | + br = au_sbr(sb, bindex); | |
11771 | + if (!au_br_fhsm(br->br_perm)) | |
11772 | + continue; | |
11773 | + | |
11774 | + bf = br->br_fhsm; | |
11775 | + mutex_lock(&bf->bf_lock); | |
11776 | + if (bf->bf_readable) { | |
11777 | + err = -EFAULT; | |
11778 | + if (count >= sizeof(*stbr)) | |
11779 | + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs, | |
11780 | + br->br_id); | |
11781 | + if (!err) { | |
11782 | + bf->bf_readable = 0; | |
11783 | + count -= sizeof(*stbr); | |
11784 | + nstbr++; | |
11785 | + } | |
11786 | + } | |
11787 | + mutex_unlock(&bf->bf_lock); | |
11788 | + } | |
11789 | + if (!err) | |
11790 | + err = sizeof(*stbr) * nstbr; | |
11791 | + | |
11792 | + return err; | |
11793 | +} | |
11794 | + | |
11795 | +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count, | |
11796 | + loff_t *pos) | |
11797 | +{ | |
11798 | + ssize_t err; | |
11799 | + int readable; | |
11800 | + aufs_bindex_t nfhsm, bindex, bend; | |
11801 | + struct au_sbinfo *sbinfo; | |
11802 | + struct au_fhsm *fhsm; | |
11803 | + struct au_branch *br; | |
11804 | + struct super_block *sb; | |
11805 | + | |
11806 | + err = 0; | |
11807 | + sbinfo = file->private_data; | |
11808 | + fhsm = &sbinfo->si_fhsm; | |
11809 | +need_data: | |
11810 | + spin_lock_irq(&fhsm->fhsm_wqh.lock); | |
11811 | + if (!atomic_read(&fhsm->fhsm_readable)) { | |
11812 | + if (vfsub_file_flags(file) & O_NONBLOCK) | |
11813 | + err = -EAGAIN; | |
11814 | + else | |
11815 | + err = wait_event_interruptible_locked_irq | |
11816 | + (fhsm->fhsm_wqh, | |
11817 | + atomic_read(&fhsm->fhsm_readable)); | |
11818 | + } | |
11819 | + spin_unlock_irq(&fhsm->fhsm_wqh.lock); | |
11820 | + if (unlikely(err)) | |
11821 | + goto out; | |
11822 | + | |
11823 | + /* sb may already be dead */ | |
11824 | + au_rw_read_lock(&sbinfo->si_rwsem); | |
11825 | + readable = atomic_read(&fhsm->fhsm_readable); | |
11826 | + if (readable > 0) { | |
11827 | + sb = sbinfo->si_sb; | |
11828 | + AuDebugOn(!sb); | |
11829 | + /* exclude the bottom branch */ | |
11830 | + nfhsm = 0; | |
c1595e42 | 11831 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11832 | + for (bindex = 0; bindex < bend; bindex++) { |
11833 | + br = au_sbr(sb, bindex); | |
11834 | + if (au_br_fhsm(br->br_perm)) | |
11835 | + nfhsm++; | |
11836 | + } | |
11837 | + err = -EMSGSIZE; | |
11838 | + if (nfhsm * sizeof(struct aufs_stbr) <= count) { | |
11839 | + atomic_set(&fhsm->fhsm_readable, 0); | |
11840 | + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf, | |
11841 | + count); | |
11842 | + } | |
11843 | + } | |
11844 | + au_rw_read_unlock(&sbinfo->si_rwsem); | |
11845 | + if (!readable) | |
11846 | + goto need_data; | |
11847 | + | |
11848 | +out: | |
11849 | + return err; | |
11850 | +} | |
11851 | + | |
11852 | +static int au_fhsm_release(struct inode *inode, struct file *file) | |
11853 | +{ | |
11854 | + struct au_sbinfo *sbinfo; | |
11855 | + struct au_fhsm *fhsm; | |
11856 | + | |
11857 | + /* sb may already be dead */ | |
11858 | + sbinfo = file->private_data; | |
11859 | + fhsm = &sbinfo->si_fhsm; | |
11860 | + spin_lock(&fhsm->fhsm_spin); | |
11861 | + fhsm->fhsm_pid = 0; | |
11862 | + spin_unlock(&fhsm->fhsm_spin); | |
11863 | + kobject_put(&sbinfo->si_kobj); | |
11864 | + | |
11865 | + return 0; | |
11866 | +} | |
11867 | + | |
11868 | +static const struct file_operations au_fhsm_fops = { | |
11869 | + .owner = THIS_MODULE, | |
11870 | + .llseek = noop_llseek, | |
11871 | + .read = au_fhsm_read, | |
11872 | + .poll = au_fhsm_poll, | |
11873 | + .release = au_fhsm_release | |
11874 | +}; | |
11875 | + | |
11876 | +int au_fhsm_fd(struct super_block *sb, int oflags) | |
11877 | +{ | |
11878 | + int err, fd; | |
11879 | + struct au_sbinfo *sbinfo; | |
11880 | + struct au_fhsm *fhsm; | |
11881 | + | |
11882 | + err = -EPERM; | |
11883 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
11884 | + goto out; | |
11885 | + | |
11886 | + err = -EINVAL; | |
11887 | + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK))) | |
11888 | + goto out; | |
11889 | + | |
11890 | + err = 0; | |
11891 | + sbinfo = au_sbi(sb); | |
11892 | + fhsm = &sbinfo->si_fhsm; | |
11893 | + spin_lock(&fhsm->fhsm_spin); | |
11894 | + if (!fhsm->fhsm_pid) | |
11895 | + fhsm->fhsm_pid = current->pid; | |
11896 | + else | |
11897 | + err = -EBUSY; | |
11898 | + spin_unlock(&fhsm->fhsm_spin); | |
11899 | + if (unlikely(err)) | |
11900 | + goto out; | |
11901 | + | |
11902 | + oflags |= O_RDONLY; | |
11903 | + /* oflags |= FMODE_NONOTIFY; */ | |
11904 | + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags); | |
11905 | + err = fd; | |
11906 | + if (unlikely(fd < 0)) | |
11907 | + goto out_pid; | |
11908 | + | |
11909 | + /* succeed reglardless 'fhsm' status */ | |
11910 | + kobject_get(&sbinfo->si_kobj); | |
11911 | + si_noflush_read_lock(sb); | |
11912 | + if (au_ftest_si(sbinfo, FHSM)) | |
11913 | + au_fhsm_wrote_all(sb, /*force*/0); | |
11914 | + si_read_unlock(sb); | |
11915 | + goto out; /* success */ | |
11916 | + | |
11917 | +out_pid: | |
11918 | + spin_lock(&fhsm->fhsm_spin); | |
11919 | + fhsm->fhsm_pid = 0; | |
11920 | + spin_unlock(&fhsm->fhsm_spin); | |
11921 | +out: | |
11922 | + AuTraceErr(err); | |
11923 | + return err; | |
11924 | +} | |
11925 | + | |
11926 | +/* ---------------------------------------------------------------------- */ | |
11927 | + | |
11928 | +int au_fhsm_br_alloc(struct au_branch *br) | |
11929 | +{ | |
11930 | + int err; | |
11931 | + | |
11932 | + err = 0; | |
11933 | + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS); | |
11934 | + if (br->br_fhsm) | |
11935 | + au_br_fhsm_init(br->br_fhsm); | |
11936 | + else | |
11937 | + err = -ENOMEM; | |
11938 | + | |
11939 | + return err; | |
11940 | +} | |
11941 | + | |
11942 | +/* ---------------------------------------------------------------------- */ | |
11943 | + | |
11944 | +void au_fhsm_fin(struct super_block *sb) | |
11945 | +{ | |
11946 | + au_fhsm_notify(sb, /*val*/-1); | |
11947 | +} | |
11948 | + | |
11949 | +void au_fhsm_init(struct au_sbinfo *sbinfo) | |
11950 | +{ | |
11951 | + struct au_fhsm *fhsm; | |
11952 | + | |
11953 | + fhsm = &sbinfo->si_fhsm; | |
11954 | + spin_lock_init(&fhsm->fhsm_spin); | |
11955 | + init_waitqueue_head(&fhsm->fhsm_wqh); | |
11956 | + atomic_set(&fhsm->fhsm_readable, 0); | |
11957 | + fhsm->fhsm_expire | |
11958 | + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC); | |
c1595e42 | 11959 | + fhsm->fhsm_bottom = -1; |
076b876e AM |
11960 | +} |
11961 | + | |
11962 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec) | |
11963 | +{ | |
11964 | + sbinfo->si_fhsm.fhsm_expire | |
11965 | + = msecs_to_jiffies(sec * MSEC_PER_SEC); | |
11966 | +} | |
11967 | + | |
11968 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo) | |
11969 | +{ | |
11970 | + unsigned int u; | |
11971 | + | |
11972 | + if (!au_ftest_si(sbinfo, FHSM)) | |
11973 | + return; | |
11974 | + | |
11975 | + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC; | |
11976 | + if (u != AUFS_FHSM_CACHE_DEF_SEC) | |
11977 | + seq_printf(seq, ",fhsm_sec=%u", u); | |
11978 | +} | |
7f207e10 AM |
11979 | diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c |
11980 | --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
11981 | +++ linux/fs/aufs/file.c 2015-06-28 17:36:09.025073697 +0200 |
11982 | @@ -0,0 +1,841 @@ | |
1facf9fc | 11983 | +/* |
2000de60 | 11984 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 11985 | + * |
11986 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11987 | + * it under the terms of the GNU General Public License as published by | |
11988 | + * the Free Software Foundation; either version 2 of the License, or | |
11989 | + * (at your option) any later version. | |
dece6358 AM |
11990 | + * |
11991 | + * This program is distributed in the hope that it will be useful, | |
11992 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11993 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11994 | + * GNU General Public License for more details. | |
11995 | + * | |
11996 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 11997 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 11998 | + */ |
11999 | + | |
12000 | +/* | |
4a4d8108 | 12001 | + * handling file/dir, and address_space operation |
1facf9fc | 12002 | + */ |
12003 | + | |
7eafdf33 AM |
12004 | +#ifdef CONFIG_AUFS_DEBUG |
12005 | +#include <linux/migrate.h> | |
12006 | +#endif | |
4a4d8108 | 12007 | +#include <linux/pagemap.h> |
1facf9fc | 12008 | +#include "aufs.h" |
12009 | + | |
4a4d8108 AM |
12010 | +/* drop flags for writing */ |
12011 | +unsigned int au_file_roflags(unsigned int flags) | |
12012 | +{ | |
12013 | + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC); | |
12014 | + flags |= O_RDONLY | O_NOATIME; | |
12015 | + return flags; | |
12016 | +} | |
12017 | + | |
12018 | +/* common functions to regular file and dir */ | |
12019 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 12020 | + struct file *file, int force_wr) |
1facf9fc | 12021 | +{ |
1308ab2a | 12022 | + struct file *h_file; |
4a4d8108 AM |
12023 | + struct dentry *h_dentry; |
12024 | + struct inode *h_inode; | |
12025 | + struct super_block *sb; | |
12026 | + struct au_branch *br; | |
12027 | + struct path h_path; | |
b912730e | 12028 | + int err; |
1facf9fc | 12029 | + |
4a4d8108 AM |
12030 | + /* a race condition can happen between open and unlink/rmdir */ |
12031 | + h_file = ERR_PTR(-ENOENT); | |
12032 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 12033 | + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry))) |
4a4d8108 | 12034 | + goto out; |
5527c038 | 12035 | + h_inode = d_inode(h_dentry); |
027c5e7a AM |
12036 | + spin_lock(&h_dentry->d_lock); |
12037 | + err = (!d_unhashed(dentry) && d_unlinked(h_dentry)) | |
5527c038 | 12038 | + /* || !d_inode(dentry)->i_nlink */ |
027c5e7a AM |
12039 | + ; |
12040 | + spin_unlock(&h_dentry->d_lock); | |
12041 | + if (unlikely(err)) | |
4a4d8108 | 12042 | + goto out; |
1facf9fc | 12043 | + |
4a4d8108 AM |
12044 | + sb = dentry->d_sb; |
12045 | + br = au_sbr(sb, bindex); | |
b912730e AM |
12046 | + err = au_br_test_oflag(flags, br); |
12047 | + h_file = ERR_PTR(err); | |
12048 | + if (unlikely(err)) | |
027c5e7a | 12049 | + goto out; |
1facf9fc | 12050 | + |
4a4d8108 | 12051 | + /* drop flags for writing */ |
5527c038 | 12052 | + if (au_test_ro(sb, bindex, d_inode(dentry))) { |
392086de AM |
12053 | + if (force_wr && !(flags & O_WRONLY)) |
12054 | + force_wr = 0; | |
4a4d8108 | 12055 | + flags = au_file_roflags(flags); |
392086de AM |
12056 | + if (force_wr) { |
12057 | + h_file = ERR_PTR(-EROFS); | |
12058 | + flags = au_file_roflags(flags); | |
12059 | + if (unlikely(vfsub_native_ro(h_inode) | |
12060 | + || IS_APPEND(h_inode))) | |
12061 | + goto out; | |
12062 | + flags &= ~O_ACCMODE; | |
12063 | + flags |= O_WRONLY; | |
12064 | + } | |
12065 | + } | |
4a4d8108 AM |
12066 | + flags &= ~O_CREAT; |
12067 | + atomic_inc(&br->br_count); | |
12068 | + h_path.dentry = h_dentry; | |
86dc4139 | 12069 | + h_path.mnt = au_br_mnt(br); |
38d290e6 | 12070 | + h_file = vfsub_dentry_open(&h_path, flags); |
4a4d8108 AM |
12071 | + if (IS_ERR(h_file)) |
12072 | + goto out_br; | |
dece6358 | 12073 | + |
b912730e | 12074 | + if (flags & __FMODE_EXEC) { |
4a4d8108 AM |
12075 | + err = deny_write_access(h_file); |
12076 | + if (unlikely(err)) { | |
12077 | + fput(h_file); | |
12078 | + h_file = ERR_PTR(err); | |
12079 | + goto out_br; | |
12080 | + } | |
12081 | + } | |
953406b4 | 12082 | + fsnotify_open(h_file); |
4a4d8108 | 12083 | + goto out; /* success */ |
1facf9fc | 12084 | + |
4f0767ce | 12085 | +out_br: |
4a4d8108 | 12086 | + atomic_dec(&br->br_count); |
4f0767ce | 12087 | +out: |
4a4d8108 AM |
12088 | + return h_file; |
12089 | +} | |
1308ab2a | 12090 | + |
076b876e AM |
12091 | +static int au_cmoo(struct dentry *dentry) |
12092 | +{ | |
12093 | + int err, cmoo; | |
12094 | + unsigned int udba; | |
12095 | + struct path h_path; | |
12096 | + struct au_pin pin; | |
12097 | + struct au_cp_generic cpg = { | |
12098 | + .dentry = dentry, | |
12099 | + .bdst = -1, | |
12100 | + .bsrc = -1, | |
12101 | + .len = -1, | |
12102 | + .pin = &pin, | |
12103 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
12104 | + }; | |
7e9cd9fe | 12105 | + struct inode *delegated; |
076b876e AM |
12106 | + struct super_block *sb; |
12107 | + struct au_sbinfo *sbinfo; | |
12108 | + struct au_fhsm *fhsm; | |
12109 | + pid_t pid; | |
12110 | + struct au_branch *br; | |
12111 | + struct dentry *parent; | |
12112 | + struct au_hinode *hdir; | |
12113 | + | |
12114 | + DiMustWriteLock(dentry); | |
5527c038 | 12115 | + IiMustWriteLock(d_inode(dentry)); |
076b876e AM |
12116 | + |
12117 | + err = 0; | |
12118 | + if (IS_ROOT(dentry)) | |
12119 | + goto out; | |
12120 | + cpg.bsrc = au_dbstart(dentry); | |
12121 | + if (!cpg.bsrc) | |
12122 | + goto out; | |
12123 | + | |
12124 | + sb = dentry->d_sb; | |
12125 | + sbinfo = au_sbi(sb); | |
12126 | + fhsm = &sbinfo->si_fhsm; | |
12127 | + pid = au_fhsm_pid(fhsm); | |
12128 | + if (pid | |
12129 | + && (current->pid == pid | |
12130 | + || current->real_parent->pid == pid)) | |
12131 | + goto out; | |
12132 | + | |
12133 | + br = au_sbr(sb, cpg.bsrc); | |
12134 | + cmoo = au_br_cmoo(br->br_perm); | |
12135 | + if (!cmoo) | |
12136 | + goto out; | |
7e9cd9fe | 12137 | + if (!d_is_reg(dentry)) |
076b876e AM |
12138 | + cmoo &= AuBrAttr_COO_ALL; |
12139 | + if (!cmoo) | |
12140 | + goto out; | |
12141 | + | |
12142 | + parent = dget_parent(dentry); | |
12143 | + di_write_lock_parent(parent); | |
12144 | + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1); | |
12145 | + cpg.bdst = err; | |
12146 | + if (unlikely(err < 0)) { | |
12147 | + err = 0; /* there is no upper writable branch */ | |
12148 | + goto out_dgrade; | |
12149 | + } | |
12150 | + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst); | |
12151 | + | |
12152 | + /* do not respect the coo attrib for the target branch */ | |
12153 | + err = au_cpup_dirs(dentry, cpg.bdst); | |
12154 | + if (unlikely(err)) | |
12155 | + goto out_dgrade; | |
12156 | + | |
12157 | + di_downgrade_lock(parent, AuLock_IR); | |
12158 | + udba = au_opt_udba(sb); | |
12159 | + err = au_pin(&pin, dentry, cpg.bdst, udba, | |
12160 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12161 | + if (unlikely(err)) | |
12162 | + goto out_parent; | |
12163 | + | |
12164 | + err = au_sio_cpup_simple(&cpg); | |
12165 | + au_unpin(&pin); | |
12166 | + if (unlikely(err)) | |
12167 | + goto out_parent; | |
12168 | + if (!(cmoo & AuBrWAttr_MOO)) | |
12169 | + goto out_parent; /* success */ | |
12170 | + | |
12171 | + err = au_pin(&pin, dentry, cpg.bsrc, udba, | |
12172 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12173 | + if (unlikely(err)) | |
12174 | + goto out_parent; | |
12175 | + | |
12176 | + h_path.mnt = au_br_mnt(br); | |
12177 | + h_path.dentry = au_h_dptr(dentry, cpg.bsrc); | |
5527c038 | 12178 | + hdir = au_hi(d_inode(parent), cpg.bsrc); |
076b876e AM |
12179 | + delegated = NULL; |
12180 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1); | |
12181 | + au_unpin(&pin); | |
12182 | + /* todo: keep h_dentry or not? */ | |
12183 | + if (unlikely(err == -EWOULDBLOCK)) { | |
12184 | + pr_warn("cannot retry for NFSv4 delegation" | |
12185 | + " for an internal unlink\n"); | |
12186 | + iput(delegated); | |
12187 | + } | |
12188 | + if (unlikely(err)) { | |
12189 | + pr_err("unlink %pd after coo failed (%d), ignored\n", | |
12190 | + dentry, err); | |
12191 | + err = 0; | |
12192 | + } | |
12193 | + goto out_parent; /* success */ | |
12194 | + | |
12195 | +out_dgrade: | |
12196 | + di_downgrade_lock(parent, AuLock_IR); | |
12197 | +out_parent: | |
12198 | + di_read_unlock(parent, AuLock_IR); | |
12199 | + dput(parent); | |
12200 | +out: | |
12201 | + AuTraceErr(err); | |
12202 | + return err; | |
12203 | +} | |
12204 | + | |
b912730e | 12205 | +int au_do_open(struct file *file, struct au_do_open_args *args) |
1facf9fc | 12206 | +{ |
b912730e | 12207 | + int err, no_lock = args->no_lock; |
1facf9fc | 12208 | + struct dentry *dentry; |
076b876e | 12209 | + struct au_finfo *finfo; |
1308ab2a | 12210 | + |
b912730e AM |
12211 | + if (!no_lock) |
12212 | + err = au_finfo_init(file, args->fidir); | |
12213 | + else { | |
12214 | + lockdep_off(); | |
12215 | + err = au_finfo_init(file, args->fidir); | |
12216 | + lockdep_on(); | |
12217 | + } | |
4a4d8108 AM |
12218 | + if (unlikely(err)) |
12219 | + goto out; | |
1facf9fc | 12220 | + |
2000de60 | 12221 | + dentry = file->f_path.dentry; |
b912730e AM |
12222 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
12223 | + if (!no_lock) { | |
12224 | + di_write_lock_child(dentry); | |
12225 | + err = au_cmoo(dentry); | |
12226 | + di_downgrade_lock(dentry, AuLock_IR); | |
12227 | + if (!err) | |
12228 | + err = args->open(file, vfsub_file_flags(file), NULL); | |
12229 | + di_read_unlock(dentry, AuLock_IR); | |
12230 | + } else { | |
12231 | + err = au_cmoo(dentry); | |
12232 | + if (!err) | |
12233 | + err = args->open(file, vfsub_file_flags(file), | |
12234 | + args->h_file); | |
12235 | + if (!err && au_fbstart(file) != au_dbstart(dentry)) | |
12236 | + /* | |
12237 | + * cmoo happens after h_file was opened. | |
12238 | + * need to refresh file later. | |
12239 | + */ | |
12240 | + atomic_dec(&au_fi(file)->fi_generation); | |
12241 | + } | |
1facf9fc | 12242 | + |
076b876e AM |
12243 | + finfo = au_fi(file); |
12244 | + if (!err) { | |
12245 | + finfo->fi_file = file; | |
12246 | + au_sphl_add(&finfo->fi_hlist, | |
2000de60 | 12247 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); |
076b876e | 12248 | + } |
b912730e AM |
12249 | + if (!no_lock) |
12250 | + fi_write_unlock(file); | |
12251 | + else { | |
12252 | + lockdep_off(); | |
12253 | + fi_write_unlock(file); | |
12254 | + lockdep_on(); | |
12255 | + } | |
4a4d8108 | 12256 | + if (unlikely(err)) { |
076b876e | 12257 | + finfo->fi_hdir = NULL; |
4a4d8108 | 12258 | + au_finfo_fin(file); |
1308ab2a | 12259 | + } |
4a4d8108 | 12260 | + |
4f0767ce | 12261 | +out: |
1308ab2a | 12262 | + return err; |
12263 | +} | |
dece6358 | 12264 | + |
4a4d8108 | 12265 | +int au_reopen_nondir(struct file *file) |
1308ab2a | 12266 | +{ |
4a4d8108 AM |
12267 | + int err; |
12268 | + aufs_bindex_t bstart; | |
12269 | + struct dentry *dentry; | |
12270 | + struct file *h_file, *h_file_tmp; | |
1308ab2a | 12271 | + |
2000de60 | 12272 | + dentry = file->f_path.dentry; |
4a4d8108 AM |
12273 | + bstart = au_dbstart(dentry); |
12274 | + h_file_tmp = NULL; | |
12275 | + if (au_fbstart(file) == bstart) { | |
12276 | + h_file = au_hf_top(file); | |
12277 | + if (file->f_mode == h_file->f_mode) | |
12278 | + return 0; /* success */ | |
12279 | + h_file_tmp = h_file; | |
12280 | + get_file(h_file_tmp); | |
12281 | + au_set_h_fptr(file, bstart, NULL); | |
12282 | + } | |
12283 | + AuDebugOn(au_fi(file)->fi_hdir); | |
86dc4139 AM |
12284 | + /* |
12285 | + * it can happen | |
12286 | + * file exists on both of rw and ro | |
12287 | + * open --> dbstart and fbstart are both 0 | |
12288 | + * prepend a branch as rw, "rw" become ro | |
12289 | + * remove rw/file | |
12290 | + * delete the top branch, "rw" becomes rw again | |
12291 | + * --> dbstart is 1, fbstart is still 0 | |
12292 | + * write --> fbstart is 0 but dbstart is 1 | |
12293 | + */ | |
12294 | + /* AuDebugOn(au_fbstart(file) < bstart); */ | |
1308ab2a | 12295 | + |
4a4d8108 | 12296 | + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC, |
392086de | 12297 | + file, /*force_wr*/0); |
4a4d8108 | 12298 | + err = PTR_ERR(h_file); |
86dc4139 AM |
12299 | + if (IS_ERR(h_file)) { |
12300 | + if (h_file_tmp) { | |
12301 | + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count); | |
12302 | + au_set_h_fptr(file, bstart, h_file_tmp); | |
12303 | + h_file_tmp = NULL; | |
12304 | + } | |
4a4d8108 | 12305 | + goto out; /* todo: close all? */ |
86dc4139 | 12306 | + } |
4a4d8108 AM |
12307 | + |
12308 | + err = 0; | |
12309 | + au_set_fbstart(file, bstart); | |
12310 | + au_set_h_fptr(file, bstart, h_file); | |
12311 | + au_update_figen(file); | |
12312 | + /* todo: necessary? */ | |
12313 | + /* file->f_ra = h_file->f_ra; */ | |
12314 | + | |
4f0767ce | 12315 | +out: |
4a4d8108 AM |
12316 | + if (h_file_tmp) |
12317 | + fput(h_file_tmp); | |
12318 | + return err; | |
1facf9fc | 12319 | +} |
12320 | + | |
1308ab2a | 12321 | +/* ---------------------------------------------------------------------- */ |
12322 | + | |
4a4d8108 AM |
12323 | +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt, |
12324 | + struct dentry *hi_wh) | |
1facf9fc | 12325 | +{ |
4a4d8108 AM |
12326 | + int err; |
12327 | + aufs_bindex_t bstart; | |
12328 | + struct au_dinfo *dinfo; | |
12329 | + struct dentry *h_dentry; | |
12330 | + struct au_hdentry *hdp; | |
1facf9fc | 12331 | + |
2000de60 | 12332 | + dinfo = au_di(file->f_path.dentry); |
4a4d8108 | 12333 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
dece6358 | 12334 | + |
4a4d8108 AM |
12335 | + bstart = dinfo->di_bstart; |
12336 | + dinfo->di_bstart = btgt; | |
12337 | + hdp = dinfo->di_hdentry; | |
12338 | + h_dentry = hdp[0 + btgt].hd_dentry; | |
12339 | + hdp[0 + btgt].hd_dentry = hi_wh; | |
12340 | + err = au_reopen_nondir(file); | |
12341 | + hdp[0 + btgt].hd_dentry = h_dentry; | |
12342 | + dinfo->di_bstart = bstart; | |
1facf9fc | 12343 | + |
1facf9fc | 12344 | + return err; |
12345 | +} | |
12346 | + | |
4a4d8108 | 12347 | +static int au_ready_to_write_wh(struct file *file, loff_t len, |
86dc4139 | 12348 | + aufs_bindex_t bcpup, struct au_pin *pin) |
1facf9fc | 12349 | +{ |
4a4d8108 | 12350 | + int err; |
027c5e7a | 12351 | + struct inode *inode, *h_inode; |
c2b27bf2 AM |
12352 | + struct dentry *h_dentry, *hi_wh; |
12353 | + struct au_cp_generic cpg = { | |
2000de60 | 12354 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12355 | + .bdst = bcpup, |
12356 | + .bsrc = -1, | |
12357 | + .len = len, | |
12358 | + .pin = pin | |
12359 | + }; | |
1facf9fc | 12360 | + |
c2b27bf2 | 12361 | + au_update_dbstart(cpg.dentry); |
5527c038 | 12362 | + inode = d_inode(cpg.dentry); |
027c5e7a | 12363 | + h_inode = NULL; |
c2b27bf2 AM |
12364 | + if (au_dbstart(cpg.dentry) <= bcpup |
12365 | + && au_dbend(cpg.dentry) >= bcpup) { | |
12366 | + h_dentry = au_h_dptr(cpg.dentry, bcpup); | |
5527c038 JR |
12367 | + if (h_dentry && d_is_positive(h_dentry)) |
12368 | + h_inode = d_inode(h_dentry); | |
027c5e7a | 12369 | + } |
4a4d8108 | 12370 | + hi_wh = au_hi_wh(inode, bcpup); |
027c5e7a | 12371 | + if (!hi_wh && !h_inode) |
c2b27bf2 | 12372 | + err = au_sio_cpup_wh(&cpg, file); |
4a4d8108 AM |
12373 | + else |
12374 | + /* already copied-up after unlink */ | |
12375 | + err = au_reopen_wh(file, bcpup, hi_wh); | |
1facf9fc | 12376 | + |
4a4d8108 | 12377 | + if (!err |
38d290e6 JR |
12378 | + && (inode->i_nlink > 1 |
12379 | + || (inode->i_state & I_LINKABLE)) | |
c2b27bf2 AM |
12380 | + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK)) |
12381 | + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup)); | |
1308ab2a | 12382 | + |
dece6358 | 12383 | + return err; |
1facf9fc | 12384 | +} |
12385 | + | |
4a4d8108 AM |
12386 | +/* |
12387 | + * prepare the @file for writing. | |
12388 | + */ | |
12389 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin) | |
1facf9fc | 12390 | +{ |
4a4d8108 | 12391 | + int err; |
c2b27bf2 | 12392 | + aufs_bindex_t dbstart; |
c1595e42 | 12393 | + struct dentry *parent; |
86dc4139 | 12394 | + struct inode *inode; |
1facf9fc | 12395 | + struct super_block *sb; |
4a4d8108 | 12396 | + struct file *h_file; |
c2b27bf2 | 12397 | + struct au_cp_generic cpg = { |
2000de60 | 12398 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12399 | + .bdst = -1, |
12400 | + .bsrc = -1, | |
12401 | + .len = len, | |
12402 | + .pin = pin, | |
12403 | + .flags = AuCpup_DTIME | |
12404 | + }; | |
1facf9fc | 12405 | + |
c2b27bf2 | 12406 | + sb = cpg.dentry->d_sb; |
5527c038 | 12407 | + inode = d_inode(cpg.dentry); |
c2b27bf2 AM |
12408 | + cpg.bsrc = au_fbstart(file); |
12409 | + err = au_test_ro(sb, cpg.bsrc, inode); | |
4a4d8108 | 12410 | + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) { |
c2b27bf2 AM |
12411 | + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE, |
12412 | + /*flags*/0); | |
1facf9fc | 12413 | + goto out; |
4a4d8108 | 12414 | + } |
1facf9fc | 12415 | + |
027c5e7a | 12416 | + /* need to cpup or reopen */ |
c2b27bf2 | 12417 | + parent = dget_parent(cpg.dentry); |
4a4d8108 | 12418 | + di_write_lock_parent(parent); |
c2b27bf2 AM |
12419 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12420 | + cpg.bdst = err; | |
4a4d8108 AM |
12421 | + if (unlikely(err < 0)) |
12422 | + goto out_dgrade; | |
12423 | + err = 0; | |
12424 | + | |
c2b27bf2 AM |
12425 | + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) { |
12426 | + err = au_cpup_dirs(cpg.dentry, cpg.bdst); | |
1facf9fc | 12427 | + if (unlikely(err)) |
4a4d8108 AM |
12428 | + goto out_dgrade; |
12429 | + } | |
12430 | + | |
c2b27bf2 | 12431 | + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 AM |
12432 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
12433 | + if (unlikely(err)) | |
12434 | + goto out_dgrade; | |
12435 | + | |
c2b27bf2 | 12436 | + dbstart = au_dbstart(cpg.dentry); |
c1595e42 | 12437 | + if (dbstart <= cpg.bdst) |
c2b27bf2 | 12438 | + cpg.bsrc = cpg.bdst; |
027c5e7a | 12439 | + |
c2b27bf2 AM |
12440 | + if (dbstart <= cpg.bdst /* just reopen */ |
12441 | + || !d_unhashed(cpg.dentry) /* copyup and reopen */ | |
027c5e7a | 12442 | + ) { |
392086de | 12443 | + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0); |
86dc4139 | 12444 | + if (IS_ERR(h_file)) |
027c5e7a | 12445 | + err = PTR_ERR(h_file); |
86dc4139 | 12446 | + else { |
027c5e7a | 12447 | + di_downgrade_lock(parent, AuLock_IR); |
c2b27bf2 AM |
12448 | + if (dbstart > cpg.bdst) |
12449 | + err = au_sio_cpup_simple(&cpg); | |
027c5e7a AM |
12450 | + if (!err) |
12451 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 12452 | + au_h_open_post(cpg.dentry, cpg.bsrc, h_file); |
027c5e7a | 12453 | + } |
027c5e7a AM |
12454 | + } else { /* copyup as wh and reopen */ |
12455 | + /* | |
12456 | + * since writable hfsplus branch is not supported, | |
12457 | + * h_open_pre/post() are unnecessary. | |
12458 | + */ | |
c2b27bf2 | 12459 | + err = au_ready_to_write_wh(file, len, cpg.bdst, pin); |
4a4d8108 | 12460 | + di_downgrade_lock(parent, AuLock_IR); |
4a4d8108 | 12461 | + } |
4a4d8108 AM |
12462 | + |
12463 | + if (!err) { | |
12464 | + au_pin_set_parent_lflag(pin, /*lflag*/0); | |
12465 | + goto out_dput; /* success */ | |
12466 | + } | |
12467 | + au_unpin(pin); | |
12468 | + goto out_unlock; | |
1facf9fc | 12469 | + |
4f0767ce | 12470 | +out_dgrade: |
4a4d8108 | 12471 | + di_downgrade_lock(parent, AuLock_IR); |
4f0767ce | 12472 | +out_unlock: |
4a4d8108 | 12473 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12474 | +out_dput: |
4a4d8108 | 12475 | + dput(parent); |
4f0767ce | 12476 | +out: |
1facf9fc | 12477 | + return err; |
12478 | +} | |
12479 | + | |
4a4d8108 AM |
12480 | +/* ---------------------------------------------------------------------- */ |
12481 | + | |
12482 | +int au_do_flush(struct file *file, fl_owner_t id, | |
12483 | + int (*flush)(struct file *file, fl_owner_t id)) | |
1facf9fc | 12484 | +{ |
4a4d8108 | 12485 | + int err; |
1facf9fc | 12486 | + struct super_block *sb; |
4a4d8108 | 12487 | + struct inode *inode; |
1facf9fc | 12488 | + |
c06a8ce3 AM |
12489 | + inode = file_inode(file); |
12490 | + sb = inode->i_sb; | |
4a4d8108 AM |
12491 | + si_noflush_read_lock(sb); |
12492 | + fi_read_lock(file); | |
b752ccd1 | 12493 | + ii_read_lock_child(inode); |
1facf9fc | 12494 | + |
4a4d8108 AM |
12495 | + err = flush(file, id); |
12496 | + au_cpup_attr_timesizes(inode); | |
1facf9fc | 12497 | + |
b752ccd1 | 12498 | + ii_read_unlock(inode); |
4a4d8108 | 12499 | + fi_read_unlock(file); |
1308ab2a | 12500 | + si_read_unlock(sb); |
dece6358 | 12501 | + return err; |
1facf9fc | 12502 | +} |
12503 | + | |
4a4d8108 AM |
12504 | +/* ---------------------------------------------------------------------- */ |
12505 | + | |
12506 | +static int au_file_refresh_by_inode(struct file *file, int *need_reopen) | |
1facf9fc | 12507 | +{ |
4a4d8108 | 12508 | + int err; |
4a4d8108 AM |
12509 | + struct au_pin pin; |
12510 | + struct au_finfo *finfo; | |
c2b27bf2 | 12511 | + struct dentry *parent, *hi_wh; |
4a4d8108 | 12512 | + struct inode *inode; |
1facf9fc | 12513 | + struct super_block *sb; |
c2b27bf2 | 12514 | + struct au_cp_generic cpg = { |
2000de60 | 12515 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12516 | + .bdst = -1, |
12517 | + .bsrc = -1, | |
12518 | + .len = -1, | |
12519 | + .pin = &pin, | |
12520 | + .flags = AuCpup_DTIME | |
12521 | + }; | |
1facf9fc | 12522 | + |
4a4d8108 AM |
12523 | + FiMustWriteLock(file); |
12524 | + | |
12525 | + err = 0; | |
12526 | + finfo = au_fi(file); | |
c2b27bf2 | 12527 | + sb = cpg.dentry->d_sb; |
5527c038 | 12528 | + inode = d_inode(cpg.dentry); |
c2b27bf2 AM |
12529 | + cpg.bdst = au_ibstart(inode); |
12530 | + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry)) | |
1308ab2a | 12531 | + goto out; |
dece6358 | 12532 | + |
c2b27bf2 AM |
12533 | + parent = dget_parent(cpg.dentry); |
12534 | + if (au_test_ro(sb, cpg.bdst, inode)) { | |
4a4d8108 | 12535 | + di_read_lock_parent(parent, !AuLock_IR); |
c2b27bf2 AM |
12536 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12537 | + cpg.bdst = err; | |
4a4d8108 AM |
12538 | + di_read_unlock(parent, !AuLock_IR); |
12539 | + if (unlikely(err < 0)) | |
12540 | + goto out_parent; | |
12541 | + err = 0; | |
1facf9fc | 12542 | + } |
1facf9fc | 12543 | + |
4a4d8108 | 12544 | + di_read_lock_parent(parent, AuLock_IR); |
c2b27bf2 | 12545 | + hi_wh = au_hi_wh(inode, cpg.bdst); |
7f207e10 AM |
12546 | + if (!S_ISDIR(inode->i_mode) |
12547 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4a4d8108 | 12548 | + && au_plink_test(inode) |
c2b27bf2 AM |
12549 | + && !d_unhashed(cpg.dentry) |
12550 | + && cpg.bdst < au_dbstart(cpg.dentry)) { | |
12551 | + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst); | |
4a4d8108 AM |
12552 | + if (unlikely(err)) |
12553 | + goto out_unlock; | |
12554 | + | |
12555 | + /* always superio. */ | |
c2b27bf2 | 12556 | + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 | 12557 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
367653fa | 12558 | + if (!err) { |
c2b27bf2 | 12559 | + err = au_sio_cpup_simple(&cpg); |
367653fa AM |
12560 | + au_unpin(&pin); |
12561 | + } | |
4a4d8108 AM |
12562 | + } else if (hi_wh) { |
12563 | + /* already copied-up after unlink */ | |
c2b27bf2 | 12564 | + err = au_reopen_wh(file, cpg.bdst, hi_wh); |
4a4d8108 AM |
12565 | + *need_reopen = 0; |
12566 | + } | |
1facf9fc | 12567 | + |
4f0767ce | 12568 | +out_unlock: |
4a4d8108 | 12569 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12570 | +out_parent: |
4a4d8108 | 12571 | + dput(parent); |
4f0767ce | 12572 | +out: |
1308ab2a | 12573 | + return err; |
dece6358 | 12574 | +} |
1facf9fc | 12575 | + |
4a4d8108 | 12576 | +static void au_do_refresh_dir(struct file *file) |
dece6358 | 12577 | +{ |
4a4d8108 AM |
12578 | + aufs_bindex_t bindex, bend, new_bindex, brid; |
12579 | + struct au_hfile *p, tmp, *q; | |
12580 | + struct au_finfo *finfo; | |
1308ab2a | 12581 | + struct super_block *sb; |
4a4d8108 | 12582 | + struct au_fidir *fidir; |
1facf9fc | 12583 | + |
4a4d8108 | 12584 | + FiMustWriteLock(file); |
1facf9fc | 12585 | + |
2000de60 | 12586 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 AM |
12587 | + finfo = au_fi(file); |
12588 | + fidir = finfo->fi_hdir; | |
12589 | + AuDebugOn(!fidir); | |
12590 | + p = fidir->fd_hfile + finfo->fi_btop; | |
12591 | + brid = p->hf_br->br_id; | |
12592 | + bend = fidir->fd_bbot; | |
12593 | + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) { | |
12594 | + if (!p->hf_file) | |
12595 | + continue; | |
1308ab2a | 12596 | + |
4a4d8108 AM |
12597 | + new_bindex = au_br_index(sb, p->hf_br->br_id); |
12598 | + if (new_bindex == bindex) | |
12599 | + continue; | |
12600 | + if (new_bindex < 0) { | |
12601 | + au_set_h_fptr(file, bindex, NULL); | |
12602 | + continue; | |
12603 | + } | |
1308ab2a | 12604 | + |
4a4d8108 AM |
12605 | + /* swap two lower inode, and loop again */ |
12606 | + q = fidir->fd_hfile + new_bindex; | |
12607 | + tmp = *q; | |
12608 | + *q = *p; | |
12609 | + *p = tmp; | |
12610 | + if (tmp.hf_file) { | |
12611 | + bindex--; | |
12612 | + p--; | |
12613 | + } | |
12614 | + } | |
1308ab2a | 12615 | + |
4a4d8108 | 12616 | + p = fidir->fd_hfile; |
2000de60 | 12617 | + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) { |
4a4d8108 AM |
12618 | + bend = au_sbend(sb); |
12619 | + for (finfo->fi_btop = 0; finfo->fi_btop <= bend; | |
12620 | + finfo->fi_btop++, p++) | |
12621 | + if (p->hf_file) { | |
c06a8ce3 | 12622 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12623 | + break; |
c1595e42 | 12624 | + au_hfput(p, file); |
4a4d8108 AM |
12625 | + } |
12626 | + } else { | |
12627 | + bend = au_br_index(sb, brid); | |
12628 | + for (finfo->fi_btop = 0; finfo->fi_btop < bend; | |
12629 | + finfo->fi_btop++, p++) | |
12630 | + if (p->hf_file) | |
12631 | + au_hfput(p, file); | |
12632 | + bend = au_sbend(sb); | |
12633 | + } | |
1308ab2a | 12634 | + |
4a4d8108 AM |
12635 | + p = fidir->fd_hfile + bend; |
12636 | + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop; | |
12637 | + fidir->fd_bbot--, p--) | |
12638 | + if (p->hf_file) { | |
c06a8ce3 | 12639 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12640 | + break; |
c1595e42 | 12641 | + au_hfput(p, file); |
4a4d8108 AM |
12642 | + } |
12643 | + AuDebugOn(fidir->fd_bbot < finfo->fi_btop); | |
1308ab2a | 12644 | +} |
12645 | + | |
4a4d8108 AM |
12646 | +/* |
12647 | + * after branch manipulating, refresh the file. | |
12648 | + */ | |
12649 | +static int refresh_file(struct file *file, int (*reopen)(struct file *file)) | |
1facf9fc | 12650 | +{ |
4a4d8108 AM |
12651 | + int err, need_reopen; |
12652 | + aufs_bindex_t bend, bindex; | |
12653 | + struct dentry *dentry; | |
1308ab2a | 12654 | + struct au_finfo *finfo; |
4a4d8108 | 12655 | + struct au_hfile *hfile; |
1facf9fc | 12656 | + |
2000de60 | 12657 | + dentry = file->f_path.dentry; |
1308ab2a | 12658 | + finfo = au_fi(file); |
4a4d8108 AM |
12659 | + if (!finfo->fi_hdir) { |
12660 | + hfile = &finfo->fi_htop; | |
12661 | + AuDebugOn(!hfile->hf_file); | |
12662 | + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id); | |
12663 | + AuDebugOn(bindex < 0); | |
12664 | + if (bindex != finfo->fi_btop) | |
12665 | + au_set_fbstart(file, bindex); | |
12666 | + } else { | |
12667 | + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1); | |
12668 | + if (unlikely(err)) | |
12669 | + goto out; | |
12670 | + au_do_refresh_dir(file); | |
12671 | + } | |
1facf9fc | 12672 | + |
4a4d8108 AM |
12673 | + err = 0; |
12674 | + need_reopen = 1; | |
12675 | + if (!au_test_mmapped(file)) | |
12676 | + err = au_file_refresh_by_inode(file, &need_reopen); | |
027c5e7a | 12677 | + if (!err && need_reopen && !d_unlinked(dentry)) |
4a4d8108 AM |
12678 | + err = reopen(file); |
12679 | + if (!err) { | |
12680 | + au_update_figen(file); | |
12681 | + goto out; /* success */ | |
12682 | + } | |
12683 | + | |
12684 | + /* error, close all lower files */ | |
12685 | + if (finfo->fi_hdir) { | |
12686 | + bend = au_fbend_dir(file); | |
12687 | + for (bindex = au_fbstart(file); bindex <= bend; bindex++) | |
12688 | + au_set_h_fptr(file, bindex, NULL); | |
12689 | + } | |
1facf9fc | 12690 | + |
4f0767ce | 12691 | +out: |
1facf9fc | 12692 | + return err; |
12693 | +} | |
12694 | + | |
4a4d8108 AM |
12695 | +/* common function to regular file and dir */ |
12696 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
12697 | + int wlock) | |
dece6358 | 12698 | +{ |
1308ab2a | 12699 | + int err; |
4a4d8108 AM |
12700 | + unsigned int sigen, figen; |
12701 | + aufs_bindex_t bstart; | |
12702 | + unsigned char pseudo_link; | |
12703 | + struct dentry *dentry; | |
12704 | + struct inode *inode; | |
1facf9fc | 12705 | + |
4a4d8108 | 12706 | + err = 0; |
2000de60 | 12707 | + dentry = file->f_path.dentry; |
5527c038 | 12708 | + inode = d_inode(dentry); |
4a4d8108 AM |
12709 | + sigen = au_sigen(dentry->d_sb); |
12710 | + fi_write_lock(file); | |
12711 | + figen = au_figen(file); | |
12712 | + di_write_lock_child(dentry); | |
12713 | + bstart = au_dbstart(dentry); | |
12714 | + pseudo_link = (bstart != au_ibstart(inode)); | |
12715 | + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) { | |
12716 | + if (!wlock) { | |
12717 | + di_downgrade_lock(dentry, AuLock_IR); | |
12718 | + fi_downgrade_lock(file); | |
12719 | + } | |
12720 | + goto out; /* success */ | |
12721 | + } | |
dece6358 | 12722 | + |
4a4d8108 | 12723 | + AuDbg("sigen %d, figen %d\n", sigen, figen); |
027c5e7a | 12724 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 | 12725 | + err = au_reval_dpath(dentry, sigen); |
027c5e7a | 12726 | + AuDebugOn(!err && au_digen_test(dentry, sigen)); |
4a4d8108 | 12727 | + } |
dece6358 | 12728 | + |
027c5e7a AM |
12729 | + if (!err) |
12730 | + err = refresh_file(file, reopen); | |
4a4d8108 AM |
12731 | + if (!err) { |
12732 | + if (!wlock) { | |
12733 | + di_downgrade_lock(dentry, AuLock_IR); | |
12734 | + fi_downgrade_lock(file); | |
12735 | + } | |
12736 | + } else { | |
12737 | + di_write_unlock(dentry); | |
12738 | + fi_write_unlock(file); | |
12739 | + } | |
1facf9fc | 12740 | + |
4f0767ce | 12741 | +out: |
1308ab2a | 12742 | + return err; |
12743 | +} | |
1facf9fc | 12744 | + |
4a4d8108 AM |
12745 | +/* ---------------------------------------------------------------------- */ |
12746 | + | |
12747 | +/* cf. aufs_nopage() */ | |
12748 | +/* for madvise(2) */ | |
12749 | +static int aufs_readpage(struct file *file __maybe_unused, struct page *page) | |
1308ab2a | 12750 | +{ |
4a4d8108 AM |
12751 | + unlock_page(page); |
12752 | + return 0; | |
12753 | +} | |
1facf9fc | 12754 | + |
4a4d8108 | 12755 | +/* it will never be called, but necessary to support O_DIRECT */ |
5527c038 JR |
12756 | +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, |
12757 | + loff_t offset) | |
4a4d8108 | 12758 | +{ BUG(); return 0; } |
1facf9fc | 12759 | + |
4a4d8108 AM |
12760 | +/* they will never be called. */ |
12761 | +#ifdef CONFIG_AUFS_DEBUG | |
12762 | +static int aufs_write_begin(struct file *file, struct address_space *mapping, | |
12763 | + loff_t pos, unsigned len, unsigned flags, | |
12764 | + struct page **pagep, void **fsdata) | |
12765 | +{ AuUnsupport(); return 0; } | |
12766 | +static int aufs_write_end(struct file *file, struct address_space *mapping, | |
12767 | + loff_t pos, unsigned len, unsigned copied, | |
12768 | + struct page *page, void *fsdata) | |
12769 | +{ AuUnsupport(); return 0; } | |
12770 | +static int aufs_writepage(struct page *page, struct writeback_control *wbc) | |
12771 | +{ AuUnsupport(); return 0; } | |
1308ab2a | 12772 | + |
4a4d8108 AM |
12773 | +static int aufs_set_page_dirty(struct page *page) |
12774 | +{ AuUnsupport(); return 0; } | |
392086de AM |
12775 | +static void aufs_invalidatepage(struct page *page, unsigned int offset, |
12776 | + unsigned int length) | |
4a4d8108 AM |
12777 | +{ AuUnsupport(); } |
12778 | +static int aufs_releasepage(struct page *page, gfp_t gfp) | |
12779 | +{ AuUnsupport(); return 0; } | |
12780 | +static int aufs_migratepage(struct address_space *mapping, struct page *newpage, | |
7eafdf33 | 12781 | + struct page *page, enum migrate_mode mode) |
4a4d8108 AM |
12782 | +{ AuUnsupport(); return 0; } |
12783 | +static int aufs_launder_page(struct page *page) | |
12784 | +{ AuUnsupport(); return 0; } | |
12785 | +static int aufs_is_partially_uptodate(struct page *page, | |
38d290e6 JR |
12786 | + unsigned long from, |
12787 | + unsigned long count) | |
4a4d8108 | 12788 | +{ AuUnsupport(); return 0; } |
392086de AM |
12789 | +static void aufs_is_dirty_writeback(struct page *page, bool *dirty, |
12790 | + bool *writeback) | |
12791 | +{ AuUnsupport(); } | |
4a4d8108 AM |
12792 | +static int aufs_error_remove_page(struct address_space *mapping, |
12793 | + struct page *page) | |
12794 | +{ AuUnsupport(); return 0; } | |
b4510431 AM |
12795 | +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file, |
12796 | + sector_t *span) | |
12797 | +{ AuUnsupport(); return 0; } | |
12798 | +static void aufs_swap_deactivate(struct file *file) | |
12799 | +{ AuUnsupport(); } | |
4a4d8108 AM |
12800 | +#endif /* CONFIG_AUFS_DEBUG */ |
12801 | + | |
12802 | +const struct address_space_operations aufs_aop = { | |
12803 | + .readpage = aufs_readpage, | |
12804 | + .direct_IO = aufs_direct_IO, | |
4a4d8108 AM |
12805 | +#ifdef CONFIG_AUFS_DEBUG |
12806 | + .writepage = aufs_writepage, | |
4a4d8108 AM |
12807 | + /* no writepages, because of writepage */ |
12808 | + .set_page_dirty = aufs_set_page_dirty, | |
12809 | + /* no readpages, because of readpage */ | |
12810 | + .write_begin = aufs_write_begin, | |
12811 | + .write_end = aufs_write_end, | |
12812 | + /* no bmap, no block device */ | |
12813 | + .invalidatepage = aufs_invalidatepage, | |
12814 | + .releasepage = aufs_releasepage, | |
12815 | + .migratepage = aufs_migratepage, | |
12816 | + .launder_page = aufs_launder_page, | |
12817 | + .is_partially_uptodate = aufs_is_partially_uptodate, | |
392086de | 12818 | + .is_dirty_writeback = aufs_is_dirty_writeback, |
b4510431 AM |
12819 | + .error_remove_page = aufs_error_remove_page, |
12820 | + .swap_activate = aufs_swap_activate, | |
12821 | + .swap_deactivate = aufs_swap_deactivate | |
4a4d8108 | 12822 | +#endif /* CONFIG_AUFS_DEBUG */ |
dece6358 | 12823 | +}; |
7f207e10 AM |
12824 | diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h |
12825 | --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 12826 | +++ linux/fs/aufs/file.h 2015-06-28 17:35:44.348050491 +0200 |
b912730e | 12827 | @@ -0,0 +1,291 @@ |
4a4d8108 | 12828 | +/* |
2000de60 | 12829 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
12830 | + * |
12831 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12832 | + * it under the terms of the GNU General Public License as published by | |
12833 | + * the Free Software Foundation; either version 2 of the License, or | |
12834 | + * (at your option) any later version. | |
12835 | + * | |
12836 | + * This program is distributed in the hope that it will be useful, | |
12837 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12838 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12839 | + * GNU General Public License for more details. | |
12840 | + * | |
12841 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12842 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 12843 | + */ |
1facf9fc | 12844 | + |
4a4d8108 AM |
12845 | +/* |
12846 | + * file operations | |
12847 | + */ | |
1facf9fc | 12848 | + |
4a4d8108 AM |
12849 | +#ifndef __AUFS_FILE_H__ |
12850 | +#define __AUFS_FILE_H__ | |
1facf9fc | 12851 | + |
4a4d8108 | 12852 | +#ifdef __KERNEL__ |
1facf9fc | 12853 | + |
2cbb1c4b | 12854 | +#include <linux/file.h> |
4a4d8108 AM |
12855 | +#include <linux/fs.h> |
12856 | +#include <linux/poll.h> | |
4a4d8108 | 12857 | +#include "rwsem.h" |
1facf9fc | 12858 | + |
4a4d8108 AM |
12859 | +struct au_branch; |
12860 | +struct au_hfile { | |
12861 | + struct file *hf_file; | |
12862 | + struct au_branch *hf_br; | |
12863 | +}; | |
1facf9fc | 12864 | + |
4a4d8108 AM |
12865 | +struct au_vdir; |
12866 | +struct au_fidir { | |
12867 | + aufs_bindex_t fd_bbot; | |
12868 | + aufs_bindex_t fd_nent; | |
12869 | + struct au_vdir *fd_vdir_cache; | |
12870 | + struct au_hfile fd_hfile[]; | |
12871 | +}; | |
1facf9fc | 12872 | + |
4a4d8108 | 12873 | +static inline int au_fidir_sz(int nent) |
dece6358 | 12874 | +{ |
4f0767ce JR |
12875 | + AuDebugOn(nent < 0); |
12876 | + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent; | |
4a4d8108 | 12877 | +} |
1facf9fc | 12878 | + |
4a4d8108 AM |
12879 | +struct au_finfo { |
12880 | + atomic_t fi_generation; | |
dece6358 | 12881 | + |
4a4d8108 AM |
12882 | + struct au_rwsem fi_rwsem; |
12883 | + aufs_bindex_t fi_btop; | |
12884 | + | |
12885 | + /* do not union them */ | |
12886 | + struct { /* for non-dir */ | |
12887 | + struct au_hfile fi_htop; | |
2cbb1c4b | 12888 | + atomic_t fi_mmapped; |
4a4d8108 AM |
12889 | + }; |
12890 | + struct au_fidir *fi_hdir; /* for dir only */ | |
523b37e3 AM |
12891 | + |
12892 | + struct hlist_node fi_hlist; | |
12893 | + struct file *fi_file; /* very ugly */ | |
4a4d8108 | 12894 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 12895 | + |
4a4d8108 | 12896 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12897 | + |
4a4d8108 AM |
12898 | +/* file.c */ |
12899 | +extern const struct address_space_operations aufs_aop; | |
12900 | +unsigned int au_file_roflags(unsigned int flags); | |
12901 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 12902 | + struct file *file, int force_wr); |
b912730e AM |
12903 | +struct au_do_open_args { |
12904 | + int no_lock; | |
12905 | + int (*open)(struct file *file, int flags, | |
12906 | + struct file *h_file); | |
12907 | + struct au_fidir *fidir; | |
12908 | + struct file *h_file; | |
12909 | +}; | |
12910 | +int au_do_open(struct file *file, struct au_do_open_args *args); | |
4a4d8108 AM |
12911 | +int au_reopen_nondir(struct file *file); |
12912 | +struct au_pin; | |
12913 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin); | |
12914 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
12915 | + int wlock); | |
12916 | +int au_do_flush(struct file *file, fl_owner_t id, | |
12917 | + int (*flush)(struct file *file, fl_owner_t id)); | |
1facf9fc | 12918 | + |
4a4d8108 AM |
12919 | +/* poll.c */ |
12920 | +#ifdef CONFIG_AUFS_POLL | |
12921 | +unsigned int aufs_poll(struct file *file, poll_table *wait); | |
12922 | +#endif | |
1facf9fc | 12923 | + |
4a4d8108 AM |
12924 | +#ifdef CONFIG_AUFS_BR_HFSPLUS |
12925 | +/* hfsplus.c */ | |
392086de AM |
12926 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
12927 | + int force_wr); | |
4a4d8108 AM |
12928 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
12929 | + struct file *h_file); | |
12930 | +#else | |
c1595e42 JR |
12931 | +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry, |
12932 | + aufs_bindex_t bindex, int force_wr) | |
4a4d8108 AM |
12933 | +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex, |
12934 | + struct file *h_file); | |
12935 | +#endif | |
1facf9fc | 12936 | + |
4a4d8108 AM |
12937 | +/* f_op.c */ |
12938 | +extern const struct file_operations aufs_file_fop; | |
b912730e | 12939 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file); |
4a4d8108 | 12940 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file); |
b912730e | 12941 | +struct file *au_read_pre(struct file *file, int keep_fi); |
4a4d8108 | 12942 | + |
4a4d8108 AM |
12943 | +/* finfo.c */ |
12944 | +void au_hfput(struct au_hfile *hf, struct file *file); | |
12945 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, | |
12946 | + struct file *h_file); | |
1facf9fc | 12947 | + |
4a4d8108 | 12948 | +void au_update_figen(struct file *file); |
4a4d8108 AM |
12949 | +struct au_fidir *au_fidir_alloc(struct super_block *sb); |
12950 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr); | |
1facf9fc | 12951 | + |
4a4d8108 AM |
12952 | +void au_fi_init_once(void *_fi); |
12953 | +void au_finfo_fin(struct file *file); | |
12954 | +int au_finfo_init(struct file *file, struct au_fidir *fidir); | |
1facf9fc | 12955 | + |
4a4d8108 AM |
12956 | +/* ioctl.c */ |
12957 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
12958 | +#ifdef CONFIG_COMPAT |
12959 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
12960 | + unsigned long arg); | |
c2b27bf2 AM |
12961 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
12962 | + unsigned long arg); | |
b752ccd1 | 12963 | +#endif |
1facf9fc | 12964 | + |
4a4d8108 | 12965 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12966 | + |
4a4d8108 AM |
12967 | +static inline struct au_finfo *au_fi(struct file *file) |
12968 | +{ | |
38d290e6 | 12969 | + return file->private_data; |
4a4d8108 | 12970 | +} |
1facf9fc | 12971 | + |
4a4d8108 | 12972 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12973 | + |
4a4d8108 AM |
12974 | +/* |
12975 | + * fi_read_lock, fi_write_lock, | |
12976 | + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock | |
12977 | + */ | |
12978 | +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem); | |
1308ab2a | 12979 | + |
4a4d8108 AM |
12980 | +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem) |
12981 | +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem) | |
12982 | +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem) | |
1facf9fc | 12983 | + |
1308ab2a | 12984 | +/* ---------------------------------------------------------------------- */ |
12985 | + | |
4a4d8108 AM |
12986 | +/* todo: hard/soft set? */ |
12987 | +static inline aufs_bindex_t au_fbstart(struct file *file) | |
dece6358 | 12988 | +{ |
4a4d8108 AM |
12989 | + FiMustAnyLock(file); |
12990 | + return au_fi(file)->fi_btop; | |
12991 | +} | |
dece6358 | 12992 | + |
4a4d8108 AM |
12993 | +static inline aufs_bindex_t au_fbend_dir(struct file *file) |
12994 | +{ | |
12995 | + FiMustAnyLock(file); | |
12996 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12997 | + return au_fi(file)->fi_hdir->fd_bbot; | |
12998 | +} | |
1facf9fc | 12999 | + |
4a4d8108 AM |
13000 | +static inline struct au_vdir *au_fvdir_cache(struct file *file) |
13001 | +{ | |
13002 | + FiMustAnyLock(file); | |
13003 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13004 | + return au_fi(file)->fi_hdir->fd_vdir_cache; | |
13005 | +} | |
1facf9fc | 13006 | + |
4a4d8108 AM |
13007 | +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex) |
13008 | +{ | |
13009 | + FiMustWriteLock(file); | |
13010 | + au_fi(file)->fi_btop = bindex; | |
13011 | +} | |
1facf9fc | 13012 | + |
4a4d8108 AM |
13013 | +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex) |
13014 | +{ | |
13015 | + FiMustWriteLock(file); | |
13016 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13017 | + au_fi(file)->fi_hdir->fd_bbot = bindex; | |
13018 | +} | |
1308ab2a | 13019 | + |
4a4d8108 AM |
13020 | +static inline void au_set_fvdir_cache(struct file *file, |
13021 | + struct au_vdir *vdir_cache) | |
13022 | +{ | |
13023 | + FiMustWriteLock(file); | |
13024 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13025 | + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache; | |
13026 | +} | |
dece6358 | 13027 | + |
4a4d8108 AM |
13028 | +static inline struct file *au_hf_top(struct file *file) |
13029 | +{ | |
13030 | + FiMustAnyLock(file); | |
13031 | + AuDebugOn(au_fi(file)->fi_hdir); | |
13032 | + return au_fi(file)->fi_htop.hf_file; | |
13033 | +} | |
1facf9fc | 13034 | + |
4a4d8108 AM |
13035 | +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex) |
13036 | +{ | |
13037 | + FiMustAnyLock(file); | |
13038 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13039 | + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file; | |
dece6358 AM |
13040 | +} |
13041 | + | |
4a4d8108 AM |
13042 | +/* todo: memory barrier? */ |
13043 | +static inline unsigned int au_figen(struct file *f) | |
dece6358 | 13044 | +{ |
4a4d8108 AM |
13045 | + return atomic_read(&au_fi(f)->fi_generation); |
13046 | +} | |
dece6358 | 13047 | + |
2cbb1c4b JR |
13048 | +static inline void au_set_mmapped(struct file *f) |
13049 | +{ | |
13050 | + if (atomic_inc_return(&au_fi(f)->fi_mmapped)) | |
13051 | + return; | |
0c3ec466 | 13052 | + pr_warn("fi_mmapped wrapped around\n"); |
2cbb1c4b JR |
13053 | + while (!atomic_inc_return(&au_fi(f)->fi_mmapped)) |
13054 | + ; | |
13055 | +} | |
13056 | + | |
13057 | +static inline void au_unset_mmapped(struct file *f) | |
13058 | +{ | |
13059 | + atomic_dec(&au_fi(f)->fi_mmapped); | |
13060 | +} | |
13061 | + | |
4a4d8108 AM |
13062 | +static inline int au_test_mmapped(struct file *f) |
13063 | +{ | |
2cbb1c4b JR |
13064 | + return atomic_read(&au_fi(f)->fi_mmapped); |
13065 | +} | |
13066 | + | |
13067 | +/* customize vma->vm_file */ | |
13068 | + | |
13069 | +static inline void au_do_vm_file_reset(struct vm_area_struct *vma, | |
13070 | + struct file *file) | |
13071 | +{ | |
53392da6 AM |
13072 | + struct file *f; |
13073 | + | |
13074 | + f = vma->vm_file; | |
2cbb1c4b JR |
13075 | + get_file(file); |
13076 | + vma->vm_file = file; | |
53392da6 | 13077 | + fput(f); |
2cbb1c4b JR |
13078 | +} |
13079 | + | |
13080 | +#ifdef CONFIG_MMU | |
13081 | +#define AuDbgVmRegion(file, vma) do {} while (0) | |
13082 | + | |
13083 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
13084 | + struct file *file) | |
13085 | +{ | |
13086 | + au_do_vm_file_reset(vma, file); | |
13087 | +} | |
13088 | +#else | |
13089 | +#define AuDbgVmRegion(file, vma) \ | |
13090 | + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file)) | |
13091 | + | |
13092 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
13093 | + struct file *file) | |
13094 | +{ | |
53392da6 AM |
13095 | + struct file *f; |
13096 | + | |
2cbb1c4b | 13097 | + au_do_vm_file_reset(vma, file); |
53392da6 | 13098 | + f = vma->vm_region->vm_file; |
2cbb1c4b JR |
13099 | + get_file(file); |
13100 | + vma->vm_region->vm_file = file; | |
53392da6 | 13101 | + fput(f); |
2cbb1c4b JR |
13102 | +} |
13103 | +#endif /* CONFIG_MMU */ | |
13104 | + | |
13105 | +/* handle vma->vm_prfile */ | |
fb47a38f | 13106 | +static inline void au_vm_prfile_set(struct vm_area_struct *vma, |
2cbb1c4b JR |
13107 | + struct file *file) |
13108 | +{ | |
2cbb1c4b JR |
13109 | + get_file(file); |
13110 | + vma->vm_prfile = file; | |
13111 | +#ifndef CONFIG_MMU | |
13112 | + get_file(file); | |
13113 | + vma->vm_region->vm_prfile = file; | |
13114 | +#endif | |
fb47a38f | 13115 | +} |
1308ab2a | 13116 | + |
4a4d8108 AM |
13117 | +#endif /* __KERNEL__ */ |
13118 | +#endif /* __AUFS_FILE_H__ */ | |
7f207e10 AM |
13119 | diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c |
13120 | --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 13121 | +++ linux/fs/aufs/finfo.c 2015-06-28 17:35:44.348050491 +0200 |
b912730e | 13122 | @@ -0,0 +1,157 @@ |
4a4d8108 | 13123 | +/* |
2000de60 | 13124 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
13125 | + * |
13126 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13127 | + * it under the terms of the GNU General Public License as published by | |
13128 | + * the Free Software Foundation; either version 2 of the License, or | |
13129 | + * (at your option) any later version. | |
13130 | + * | |
13131 | + * This program is distributed in the hope that it will be useful, | |
13132 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13133 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13134 | + * GNU General Public License for more details. | |
13135 | + * | |
13136 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13137 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 13138 | + */ |
1308ab2a | 13139 | + |
4a4d8108 AM |
13140 | +/* |
13141 | + * file private data | |
13142 | + */ | |
1facf9fc | 13143 | + |
4a4d8108 | 13144 | +#include "aufs.h" |
1facf9fc | 13145 | + |
4a4d8108 AM |
13146 | +void au_hfput(struct au_hfile *hf, struct file *file) |
13147 | +{ | |
13148 | + /* todo: direct access f_flags */ | |
2cbb1c4b | 13149 | + if (vfsub_file_flags(file) & __FMODE_EXEC) |
4a4d8108 AM |
13150 | + allow_write_access(hf->hf_file); |
13151 | + fput(hf->hf_file); | |
13152 | + hf->hf_file = NULL; | |
e49829fe | 13153 | + atomic_dec(&hf->hf_br->br_count); |
4a4d8108 AM |
13154 | + hf->hf_br = NULL; |
13155 | +} | |
1facf9fc | 13156 | + |
4a4d8108 AM |
13157 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val) |
13158 | +{ | |
13159 | + struct au_finfo *finfo = au_fi(file); | |
13160 | + struct au_hfile *hf; | |
13161 | + struct au_fidir *fidir; | |
13162 | + | |
13163 | + fidir = finfo->fi_hdir; | |
13164 | + if (!fidir) { | |
13165 | + AuDebugOn(finfo->fi_btop != bindex); | |
13166 | + hf = &finfo->fi_htop; | |
13167 | + } else | |
13168 | + hf = fidir->fd_hfile + bindex; | |
13169 | + | |
13170 | + if (hf && hf->hf_file) | |
13171 | + au_hfput(hf, file); | |
13172 | + if (val) { | |
13173 | + FiMustWriteLock(file); | |
b912730e | 13174 | + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry)); |
4a4d8108 | 13175 | + hf->hf_file = val; |
2000de60 | 13176 | + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex); |
1308ab2a | 13177 | + } |
4a4d8108 | 13178 | +} |
1facf9fc | 13179 | + |
4a4d8108 AM |
13180 | +void au_update_figen(struct file *file) |
13181 | +{ | |
2000de60 | 13182 | + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry)); |
4a4d8108 | 13183 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 13184 | +} |
13185 | + | |
4a4d8108 AM |
13186 | +/* ---------------------------------------------------------------------- */ |
13187 | + | |
4a4d8108 AM |
13188 | +struct au_fidir *au_fidir_alloc(struct super_block *sb) |
13189 | +{ | |
13190 | + struct au_fidir *fidir; | |
13191 | + int nbr; | |
13192 | + | |
13193 | + nbr = au_sbend(sb) + 1; | |
13194 | + if (nbr < 2) | |
13195 | + nbr = 2; /* initial allocate for 2 branches */ | |
13196 | + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS); | |
13197 | + if (fidir) { | |
13198 | + fidir->fd_bbot = -1; | |
13199 | + fidir->fd_nent = nbr; | |
13200 | + fidir->fd_vdir_cache = NULL; | |
13201 | + } | |
13202 | + | |
13203 | + return fidir; | |
13204 | +} | |
13205 | + | |
13206 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr) | |
13207 | +{ | |
13208 | + int err; | |
13209 | + struct au_fidir *fidir, *p; | |
13210 | + | |
13211 | + AuRwMustWriteLock(&finfo->fi_rwsem); | |
13212 | + fidir = finfo->fi_hdir; | |
13213 | + AuDebugOn(!fidir); | |
13214 | + | |
13215 | + err = -ENOMEM; | |
13216 | + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr), | |
13217 | + GFP_NOFS); | |
13218 | + if (p) { | |
13219 | + p->fd_nent = nbr; | |
13220 | + finfo->fi_hdir = p; | |
13221 | + err = 0; | |
13222 | + } | |
1facf9fc | 13223 | + |
dece6358 | 13224 | + return err; |
1facf9fc | 13225 | +} |
1308ab2a | 13226 | + |
13227 | +/* ---------------------------------------------------------------------- */ | |
13228 | + | |
4a4d8108 | 13229 | +void au_finfo_fin(struct file *file) |
1308ab2a | 13230 | +{ |
4a4d8108 AM |
13231 | + struct au_finfo *finfo; |
13232 | + | |
2000de60 | 13233 | + au_nfiles_dec(file->f_path.dentry->d_sb); |
7f207e10 | 13234 | + |
4a4d8108 AM |
13235 | + finfo = au_fi(file); |
13236 | + AuDebugOn(finfo->fi_hdir); | |
13237 | + AuRwDestroy(&finfo->fi_rwsem); | |
13238 | + au_cache_free_finfo(finfo); | |
1308ab2a | 13239 | +} |
1308ab2a | 13240 | + |
e49829fe | 13241 | +void au_fi_init_once(void *_finfo) |
4a4d8108 | 13242 | +{ |
e49829fe | 13243 | + struct au_finfo *finfo = _finfo; |
2cbb1c4b | 13244 | + static struct lock_class_key aufs_fi; |
1308ab2a | 13245 | + |
e49829fe JR |
13246 | + au_rw_init(&finfo->fi_rwsem); |
13247 | + au_rw_class(&finfo->fi_rwsem, &aufs_fi); | |
4a4d8108 | 13248 | +} |
1308ab2a | 13249 | + |
4a4d8108 AM |
13250 | +int au_finfo_init(struct file *file, struct au_fidir *fidir) |
13251 | +{ | |
1716fcea | 13252 | + int err; |
4a4d8108 AM |
13253 | + struct au_finfo *finfo; |
13254 | + struct dentry *dentry; | |
13255 | + | |
13256 | + err = -ENOMEM; | |
2000de60 | 13257 | + dentry = file->f_path.dentry; |
4a4d8108 AM |
13258 | + finfo = au_cache_alloc_finfo(); |
13259 | + if (unlikely(!finfo)) | |
13260 | + goto out; | |
13261 | + | |
13262 | + err = 0; | |
7f207e10 | 13263 | + au_nfiles_inc(dentry->d_sb); |
1716fcea AM |
13264 | + /* verbose coding for lock class name */ |
13265 | + if (!fidir) | |
13266 | + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO); | |
13267 | + else | |
13268 | + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO); | |
4a4d8108 AM |
13269 | + au_rw_write_lock(&finfo->fi_rwsem); |
13270 | + finfo->fi_btop = -1; | |
13271 | + finfo->fi_hdir = fidir; | |
13272 | + atomic_set(&finfo->fi_generation, au_digen(dentry)); | |
13273 | + /* smp_mb(); */ /* atomic_set */ | |
13274 | + | |
13275 | + file->private_data = finfo; | |
13276 | + | |
13277 | +out: | |
13278 | + return err; | |
13279 | +} | |
7f207e10 AM |
13280 | diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c |
13281 | --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
13282 | +++ linux/fs/aufs/f_op.c 2015-06-28 17:36:09.025073697 +0200 |
13283 | @@ -0,0 +1,738 @@ | |
dece6358 | 13284 | +/* |
2000de60 | 13285 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
dece6358 AM |
13286 | + * |
13287 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13288 | + * it under the terms of the GNU General Public License as published by | |
13289 | + * the Free Software Foundation; either version 2 of the License, or | |
13290 | + * (at your option) any later version. | |
13291 | + * | |
13292 | + * This program is distributed in the hope that it will be useful, | |
13293 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13294 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13295 | + * GNU General Public License for more details. | |
13296 | + * | |
13297 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13298 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 13299 | + */ |
1facf9fc | 13300 | + |
13301 | +/* | |
4a4d8108 | 13302 | + * file and vm operations |
1facf9fc | 13303 | + */ |
dece6358 | 13304 | + |
86dc4139 | 13305 | +#include <linux/aio.h> |
4a4d8108 AM |
13306 | +#include <linux/fs_stack.h> |
13307 | +#include <linux/mman.h> | |
4a4d8108 | 13308 | +#include <linux/security.h> |
dece6358 AM |
13309 | +#include "aufs.h" |
13310 | + | |
b912730e | 13311 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 13312 | +{ |
4a4d8108 AM |
13313 | + int err; |
13314 | + aufs_bindex_t bindex; | |
4a4d8108 AM |
13315 | + struct dentry *dentry; |
13316 | + struct au_finfo *finfo; | |
38d290e6 | 13317 | + struct inode *h_inode; |
4a4d8108 AM |
13318 | + |
13319 | + FiMustWriteLock(file); | |
13320 | + | |
523b37e3 | 13321 | + err = 0; |
2000de60 | 13322 | + dentry = file->f_path.dentry; |
b912730e | 13323 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
4a4d8108 AM |
13324 | + finfo = au_fi(file); |
13325 | + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop)); | |
2cbb1c4b | 13326 | + atomic_set(&finfo->fi_mmapped, 0); |
4a4d8108 | 13327 | + bindex = au_dbstart(dentry); |
b912730e AM |
13328 | + if (!h_file) |
13329 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); | |
13330 | + else | |
13331 | + get_file(h_file); | |
4a4d8108 AM |
13332 | + if (IS_ERR(h_file)) |
13333 | + err = PTR_ERR(h_file); | |
13334 | + else { | |
38d290e6 JR |
13335 | + if ((flags & __O_TMPFILE) |
13336 | + && !(flags & O_EXCL)) { | |
13337 | + h_inode = file_inode(h_file); | |
13338 | + spin_lock(&h_inode->i_lock); | |
13339 | + h_inode->i_state |= I_LINKABLE; | |
13340 | + spin_unlock(&h_inode->i_lock); | |
13341 | + } | |
4a4d8108 AM |
13342 | + au_set_fbstart(file, bindex); |
13343 | + au_set_h_fptr(file, bindex, h_file); | |
13344 | + au_update_figen(file); | |
13345 | + /* todo: necessary? */ | |
13346 | + /* file->f_ra = h_file->f_ra; */ | |
13347 | + } | |
027c5e7a | 13348 | + |
4a4d8108 | 13349 | + return err; |
1facf9fc | 13350 | +} |
13351 | + | |
4a4d8108 AM |
13352 | +static int aufs_open_nondir(struct inode *inode __maybe_unused, |
13353 | + struct file *file) | |
1facf9fc | 13354 | +{ |
4a4d8108 | 13355 | + int err; |
1308ab2a | 13356 | + struct super_block *sb; |
b912730e AM |
13357 | + struct au_do_open_args args = { |
13358 | + .open = au_do_open_nondir | |
13359 | + }; | |
1facf9fc | 13360 | + |
523b37e3 AM |
13361 | + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n", |
13362 | + file, vfsub_file_flags(file), file->f_mode); | |
1facf9fc | 13363 | + |
2000de60 | 13364 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 13365 | + si_read_lock(sb, AuLock_FLUSH); |
b912730e | 13366 | + err = au_do_open(file, &args); |
4a4d8108 AM |
13367 | + si_read_unlock(sb); |
13368 | + return err; | |
13369 | +} | |
1facf9fc | 13370 | + |
4a4d8108 AM |
13371 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file) |
13372 | +{ | |
13373 | + struct au_finfo *finfo; | |
13374 | + aufs_bindex_t bindex; | |
1facf9fc | 13375 | + |
4a4d8108 | 13376 | + finfo = au_fi(file); |
2000de60 JR |
13377 | + au_sphl_del(&finfo->fi_hlist, |
13378 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
4a4d8108 | 13379 | + bindex = finfo->fi_btop; |
b4510431 | 13380 | + if (bindex >= 0) |
4a4d8108 | 13381 | + au_set_h_fptr(file, bindex, NULL); |
7f207e10 | 13382 | + |
4a4d8108 AM |
13383 | + au_finfo_fin(file); |
13384 | + return 0; | |
1facf9fc | 13385 | +} |
13386 | + | |
4a4d8108 AM |
13387 | +/* ---------------------------------------------------------------------- */ |
13388 | + | |
13389 | +static int au_do_flush_nondir(struct file *file, fl_owner_t id) | |
dece6358 | 13390 | +{ |
1308ab2a | 13391 | + int err; |
4a4d8108 AM |
13392 | + struct file *h_file; |
13393 | + | |
13394 | + err = 0; | |
13395 | + h_file = au_hf_top(file); | |
13396 | + if (h_file) | |
13397 | + err = vfsub_flush(h_file, id); | |
13398 | + return err; | |
13399 | +} | |
13400 | + | |
13401 | +static int aufs_flush_nondir(struct file *file, fl_owner_t id) | |
13402 | +{ | |
13403 | + return au_do_flush(file, id, au_do_flush_nondir); | |
13404 | +} | |
13405 | + | |
13406 | +/* ---------------------------------------------------------------------- */ | |
9dbd164d AM |
13407 | +/* |
13408 | + * read and write functions acquire [fdi]_rwsem once, but release before | |
13409 | + * mmap_sem. This is because to stop a race condition between mmap(2). | |
13410 | + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping | |
13411 | + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in | |
13412 | + * read functions after [fdi]_rwsem are released, but it should be harmless. | |
13413 | + */ | |
4a4d8108 | 13414 | + |
b912730e AM |
13415 | +/* Callers should call au_read_post() or fput() in the end */ |
13416 | +struct file *au_read_pre(struct file *file, int keep_fi) | |
4a4d8108 | 13417 | +{ |
4a4d8108 | 13418 | + struct file *h_file; |
b912730e | 13419 | + int err; |
1facf9fc | 13420 | + |
4a4d8108 | 13421 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0); |
b912730e AM |
13422 | + if (!err) { |
13423 | + di_read_unlock(file->f_path.dentry, AuLock_IR); | |
13424 | + h_file = au_hf_top(file); | |
13425 | + get_file(h_file); | |
13426 | + if (!keep_fi) | |
13427 | + fi_read_unlock(file); | |
13428 | + } else | |
13429 | + h_file = ERR_PTR(err); | |
13430 | + | |
13431 | + return h_file; | |
13432 | +} | |
13433 | + | |
13434 | +static void au_read_post(struct inode *inode, struct file *h_file) | |
13435 | +{ | |
13436 | + /* update without lock, I don't think it a problem */ | |
13437 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
13438 | + fput(h_file); | |
13439 | +} | |
13440 | + | |
13441 | +struct au_write_pre { | |
13442 | + blkcnt_t blks; | |
13443 | + aufs_bindex_t bstart; | |
13444 | +}; | |
13445 | + | |
13446 | +/* | |
13447 | + * return with iinfo is write-locked | |
13448 | + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the | |
13449 | + * end | |
13450 | + */ | |
13451 | +static struct file *au_write_pre(struct file *file, int do_ready, | |
13452 | + struct au_write_pre *wpre) | |
13453 | +{ | |
13454 | + struct file *h_file; | |
13455 | + struct dentry *dentry; | |
13456 | + int err; | |
13457 | + struct au_pin pin; | |
13458 | + | |
13459 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); | |
13460 | + h_file = ERR_PTR(err); | |
dece6358 AM |
13461 | + if (unlikely(err)) |
13462 | + goto out; | |
1facf9fc | 13463 | + |
b912730e AM |
13464 | + dentry = file->f_path.dentry; |
13465 | + if (do_ready) { | |
13466 | + err = au_ready_to_write(file, -1, &pin); | |
13467 | + if (unlikely(err)) { | |
13468 | + h_file = ERR_PTR(err); | |
13469 | + di_write_unlock(dentry); | |
13470 | + goto out_fi; | |
13471 | + } | |
13472 | + } | |
13473 | + | |
13474 | + di_downgrade_lock(dentry, /*flags*/0); | |
13475 | + if (wpre) | |
13476 | + wpre->bstart = au_fbstart(file); | |
4a4d8108 | 13477 | + h_file = au_hf_top(file); |
9dbd164d | 13478 | + get_file(h_file); |
b912730e AM |
13479 | + if (wpre) |
13480 | + wpre->blks = file_inode(h_file)->i_blocks; | |
13481 | + if (do_ready) | |
13482 | + au_unpin(&pin); | |
13483 | + di_read_unlock(dentry, /*flags*/0); | |
13484 | + | |
13485 | +out_fi: | |
13486 | + fi_write_unlock(file); | |
13487 | +out: | |
13488 | + return h_file; | |
13489 | +} | |
13490 | + | |
13491 | +static void au_write_post(struct inode *inode, struct file *h_file, | |
13492 | + struct au_write_pre *wpre, ssize_t written) | |
13493 | +{ | |
13494 | + struct inode *h_inode; | |
13495 | + | |
13496 | + au_cpup_attr_timesizes(inode); | |
13497 | + AuDebugOn(au_ibstart(inode) != wpre->bstart); | |
13498 | + h_inode = file_inode(h_file); | |
13499 | + inode->i_mode = h_inode->i_mode; | |
13500 | + ii_write_unlock(inode); | |
13501 | + fput(h_file); | |
13502 | + | |
13503 | + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */ | |
13504 | + if (written > 0) | |
13505 | + au_fhsm_wrote(inode->i_sb, wpre->bstart, | |
13506 | + /*force*/h_inode->i_blocks > wpre->blks); | |
13507 | +} | |
13508 | + | |
13509 | +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count, | |
13510 | + loff_t *ppos) | |
13511 | +{ | |
13512 | + ssize_t err; | |
13513 | + struct inode *inode; | |
13514 | + struct file *h_file; | |
13515 | + struct super_block *sb; | |
13516 | + | |
13517 | + inode = file_inode(file); | |
13518 | + sb = inode->i_sb; | |
13519 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
13520 | + | |
13521 | + h_file = au_read_pre(file, /*keep_fi*/0); | |
13522 | + err = PTR_ERR(h_file); | |
13523 | + if (IS_ERR(h_file)) | |
13524 | + goto out; | |
9dbd164d AM |
13525 | + |
13526 | + /* filedata may be obsoleted by concurrent copyup, but no problem */ | |
4a4d8108 AM |
13527 | + err = vfsub_read_u(h_file, buf, count, ppos); |
13528 | + /* todo: necessary? */ | |
13529 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 13530 | + au_read_post(inode, h_file); |
1308ab2a | 13531 | + |
4f0767ce | 13532 | +out: |
dece6358 AM |
13533 | + si_read_unlock(sb); |
13534 | + return err; | |
13535 | +} | |
1facf9fc | 13536 | + |
e49829fe JR |
13537 | +/* |
13538 | + * todo: very ugly | |
13539 | + * it locks both of i_mutex and si_rwsem for read in safe. | |
13540 | + * if the plink maintenance mode continues forever (that is the problem), | |
13541 | + * may loop forever. | |
13542 | + */ | |
13543 | +static void au_mtx_and_read_lock(struct inode *inode) | |
13544 | +{ | |
13545 | + int err; | |
13546 | + struct super_block *sb = inode->i_sb; | |
13547 | + | |
13548 | + while (1) { | |
13549 | + mutex_lock(&inode->i_mutex); | |
13550 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
13551 | + if (!err) | |
13552 | + break; | |
13553 | + mutex_unlock(&inode->i_mutex); | |
13554 | + si_read_lock(sb, AuLock_NOPLMW); | |
13555 | + si_read_unlock(sb); | |
13556 | + } | |
13557 | +} | |
13558 | + | |
4a4d8108 AM |
13559 | +static ssize_t aufs_write(struct file *file, const char __user *ubuf, |
13560 | + size_t count, loff_t *ppos) | |
dece6358 | 13561 | +{ |
4a4d8108 | 13562 | + ssize_t err; |
b912730e AM |
13563 | + struct au_write_pre wpre; |
13564 | + struct inode *inode; | |
4a4d8108 AM |
13565 | + struct file *h_file; |
13566 | + char __user *buf = (char __user *)ubuf; | |
1facf9fc | 13567 | + |
b912730e | 13568 | + inode = file_inode(file); |
e49829fe | 13569 | + au_mtx_and_read_lock(inode); |
1facf9fc | 13570 | + |
b912730e AM |
13571 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13572 | + err = PTR_ERR(h_file); | |
13573 | + if (IS_ERR(h_file)) | |
9dbd164d | 13574 | + goto out; |
9dbd164d | 13575 | + |
4a4d8108 | 13576 | + err = vfsub_write_u(h_file, buf, count, ppos); |
b912730e | 13577 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 13578 | + |
4f0767ce | 13579 | +out: |
b912730e | 13580 | + si_read_unlock(inode->i_sb); |
4a4d8108 | 13581 | + mutex_unlock(&inode->i_mutex); |
dece6358 AM |
13582 | + return err; |
13583 | +} | |
1facf9fc | 13584 | + |
076b876e AM |
13585 | +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio, |
13586 | + struct iov_iter *iov_iter) | |
dece6358 | 13587 | +{ |
4a4d8108 AM |
13588 | + ssize_t err; |
13589 | + struct file *file; | |
076b876e | 13590 | + ssize_t (*iter)(struct kiocb *, struct iov_iter *); |
1facf9fc | 13591 | + |
4a4d8108 AM |
13592 | + err = security_file_permission(h_file, rw); |
13593 | + if (unlikely(err)) | |
13594 | + goto out; | |
1facf9fc | 13595 | + |
4a4d8108 | 13596 | + err = -ENOSYS; |
076b876e | 13597 | + iter = NULL; |
5527c038 | 13598 | + if (rw == MAY_READ) |
076b876e | 13599 | + iter = h_file->f_op->read_iter; |
5527c038 | 13600 | + else if (rw == MAY_WRITE) |
076b876e | 13601 | + iter = h_file->f_op->write_iter; |
076b876e AM |
13602 | + |
13603 | + file = kio->ki_filp; | |
13604 | + kio->ki_filp = h_file; | |
13605 | + if (iter) { | |
2cbb1c4b | 13606 | + lockdep_off(); |
076b876e AM |
13607 | + err = iter(kio, iov_iter); |
13608 | + lockdep_on(); | |
4a4d8108 AM |
13609 | + } else |
13610 | + /* currently there is no such fs */ | |
13611 | + WARN_ON_ONCE(1); | |
076b876e | 13612 | + kio->ki_filp = file; |
1facf9fc | 13613 | + |
4f0767ce | 13614 | +out: |
dece6358 AM |
13615 | + return err; |
13616 | +} | |
1facf9fc | 13617 | + |
076b876e | 13618 | +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1facf9fc | 13619 | +{ |
4a4d8108 AM |
13620 | + ssize_t err; |
13621 | + struct file *file, *h_file; | |
b912730e | 13622 | + struct inode *inode; |
dece6358 | 13623 | + struct super_block *sb; |
1facf9fc | 13624 | + |
4a4d8108 | 13625 | + file = kio->ki_filp; |
b912730e AM |
13626 | + inode = file_inode(file); |
13627 | + sb = inode->i_sb; | |
e49829fe | 13628 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 13629 | + |
b912730e AM |
13630 | + h_file = au_read_pre(file, /*keep_fi*/0); |
13631 | + err = PTR_ERR(h_file); | |
13632 | + if (IS_ERR(h_file)) | |
13633 | + goto out; | |
9dbd164d | 13634 | + |
076b876e | 13635 | + err = au_do_iter(h_file, MAY_READ, kio, iov_iter); |
4a4d8108 AM |
13636 | + /* todo: necessary? */ |
13637 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 13638 | + au_read_post(inode, h_file); |
1facf9fc | 13639 | + |
4f0767ce | 13640 | +out: |
4a4d8108 | 13641 | + si_read_unlock(sb); |
1308ab2a | 13642 | + return err; |
13643 | +} | |
1facf9fc | 13644 | + |
076b876e | 13645 | +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1308ab2a | 13646 | +{ |
4a4d8108 | 13647 | + ssize_t err; |
b912730e AM |
13648 | + struct au_write_pre wpre; |
13649 | + struct inode *inode; | |
4a4d8108 | 13650 | + struct file *file, *h_file; |
1308ab2a | 13651 | + |
4a4d8108 | 13652 | + file = kio->ki_filp; |
b912730e | 13653 | + inode = file_inode(file); |
e49829fe JR |
13654 | + au_mtx_and_read_lock(inode); |
13655 | + | |
b912730e AM |
13656 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13657 | + err = PTR_ERR(h_file); | |
13658 | + if (IS_ERR(h_file)) | |
9dbd164d | 13659 | + goto out; |
9dbd164d | 13660 | + |
076b876e | 13661 | + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter); |
b912730e | 13662 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 13663 | + |
4f0767ce | 13664 | +out: |
b912730e | 13665 | + si_read_unlock(inode->i_sb); |
4a4d8108 | 13666 | + mutex_unlock(&inode->i_mutex); |
dece6358 | 13667 | + return err; |
1facf9fc | 13668 | +} |
13669 | + | |
4a4d8108 AM |
13670 | +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, |
13671 | + struct pipe_inode_info *pipe, size_t len, | |
13672 | + unsigned int flags) | |
1facf9fc | 13673 | +{ |
4a4d8108 AM |
13674 | + ssize_t err; |
13675 | + struct file *h_file; | |
b912730e | 13676 | + struct inode *inode; |
dece6358 | 13677 | + struct super_block *sb; |
1facf9fc | 13678 | + |
b912730e AM |
13679 | + inode = file_inode(file); |
13680 | + sb = inode->i_sb; | |
e49829fe | 13681 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e AM |
13682 | + |
13683 | + h_file = au_read_pre(file, /*keep_fi*/1); | |
13684 | + err = PTR_ERR(h_file); | |
13685 | + if (IS_ERR(h_file)) | |
dece6358 | 13686 | + goto out; |
1facf9fc | 13687 | + |
4a4d8108 | 13688 | + if (au_test_loopback_kthread()) { |
2000de60 | 13689 | + au_warn_loopback(h_file->f_path.dentry->d_sb); |
87a755f4 AM |
13690 | + if (file->f_mapping != h_file->f_mapping) { |
13691 | + file->f_mapping = h_file->f_mapping; | |
13692 | + smp_mb(); /* unnecessary? */ | |
13693 | + } | |
1308ab2a | 13694 | + } |
9dbd164d AM |
13695 | + fi_read_unlock(file); |
13696 | + | |
4a4d8108 AM |
13697 | + err = vfsub_splice_to(h_file, ppos, pipe, len, flags); |
13698 | + /* todo: necessasry? */ | |
13699 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 13700 | + au_read_post(inode, h_file); |
1facf9fc | 13701 | + |
4f0767ce | 13702 | +out: |
4a4d8108 | 13703 | + si_read_unlock(sb); |
dece6358 | 13704 | + return err; |
1facf9fc | 13705 | +} |
13706 | + | |
4a4d8108 AM |
13707 | +static ssize_t |
13708 | +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos, | |
13709 | + size_t len, unsigned int flags) | |
1facf9fc | 13710 | +{ |
4a4d8108 | 13711 | + ssize_t err; |
b912730e AM |
13712 | + struct au_write_pre wpre; |
13713 | + struct inode *inode; | |
076b876e | 13714 | + struct file *h_file; |
1facf9fc | 13715 | + |
b912730e | 13716 | + inode = file_inode(file); |
e49829fe | 13717 | + au_mtx_and_read_lock(inode); |
9dbd164d | 13718 | + |
b912730e AM |
13719 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13720 | + err = PTR_ERR(h_file); | |
13721 | + if (IS_ERR(h_file)) | |
9dbd164d | 13722 | + goto out; |
9dbd164d | 13723 | + |
4a4d8108 | 13724 | + err = vfsub_splice_from(pipe, h_file, ppos, len, flags); |
b912730e | 13725 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 13726 | + |
4f0767ce | 13727 | +out: |
b912730e | 13728 | + si_read_unlock(inode->i_sb); |
4a4d8108 AM |
13729 | + mutex_unlock(&inode->i_mutex); |
13730 | + return err; | |
13731 | +} | |
1facf9fc | 13732 | + |
38d290e6 JR |
13733 | +static long aufs_fallocate(struct file *file, int mode, loff_t offset, |
13734 | + loff_t len) | |
13735 | +{ | |
13736 | + long err; | |
b912730e | 13737 | + struct au_write_pre wpre; |
38d290e6 JR |
13738 | + struct inode *inode; |
13739 | + struct file *h_file; | |
13740 | + | |
b912730e | 13741 | + inode = file_inode(file); |
38d290e6 JR |
13742 | + au_mtx_and_read_lock(inode); |
13743 | + | |
b912730e AM |
13744 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13745 | + err = PTR_ERR(h_file); | |
13746 | + if (IS_ERR(h_file)) | |
38d290e6 | 13747 | + goto out; |
38d290e6 JR |
13748 | + |
13749 | + lockdep_off(); | |
03673fb0 | 13750 | + err = vfs_fallocate(h_file, mode, offset, len); |
38d290e6 | 13751 | + lockdep_on(); |
b912730e | 13752 | + au_write_post(inode, h_file, &wpre, /*written*/1); |
38d290e6 JR |
13753 | + |
13754 | +out: | |
b912730e | 13755 | + si_read_unlock(inode->i_sb); |
38d290e6 JR |
13756 | + mutex_unlock(&inode->i_mutex); |
13757 | + return err; | |
13758 | +} | |
13759 | + | |
4a4d8108 AM |
13760 | +/* ---------------------------------------------------------------------- */ |
13761 | + | |
9dbd164d AM |
13762 | +/* |
13763 | + * The locking order around current->mmap_sem. | |
13764 | + * - in most and regular cases | |
13765 | + * file I/O syscall -- aufs_read() or something | |
13766 | + * -- si_rwsem for read -- mmap_sem | |
13767 | + * (Note that [fdi]i_rwsem are released before mmap_sem). | |
13768 | + * - in mmap case | |
13769 | + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem | |
13770 | + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for | |
13771 | + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in | |
13772 | + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though. | |
13773 | + * It means that when aufs acquires si_rwsem for write, the process should never | |
13774 | + * acquire mmap_sem. | |
13775 | + * | |
392086de | 13776 | + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a |
9dbd164d AM |
13777 | + * problem either since any directory is not able to be mmap-ed. |
13778 | + * The similar scenario is applied to aufs_readlink() too. | |
13779 | + */ | |
13780 | + | |
38d290e6 | 13781 | +#if 0 /* stop calling security_file_mmap() */ |
2dfbb274 AM |
13782 | +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */ |
13783 | +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b) | |
13784 | + | |
13785 | +static unsigned long au_arch_prot_conv(unsigned long flags) | |
13786 | +{ | |
13787 | + /* currently ppc64 only */ | |
13788 | +#ifdef CONFIG_PPC64 | |
13789 | + /* cf. linux/arch/powerpc/include/asm/mman.h */ | |
13790 | + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO); | |
13791 | + return AuConv_VM_PROT(flags, SAO); | |
13792 | +#else | |
13793 | + AuDebugOn(arch_calc_vm_prot_bits(-1)); | |
13794 | + return 0; | |
13795 | +#endif | |
13796 | +} | |
13797 | + | |
13798 | +static unsigned long au_prot_conv(unsigned long flags) | |
13799 | +{ | |
13800 | + return AuConv_VM_PROT(flags, READ) | |
13801 | + | AuConv_VM_PROT(flags, WRITE) | |
13802 | + | AuConv_VM_PROT(flags, EXEC) | |
13803 | + | au_arch_prot_conv(flags); | |
13804 | +} | |
13805 | + | |
13806 | +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */ | |
13807 | +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b) | |
13808 | + | |
13809 | +static unsigned long au_flag_conv(unsigned long flags) | |
13810 | +{ | |
13811 | + return AuConv_VM_MAP(flags, GROWSDOWN) | |
13812 | + | AuConv_VM_MAP(flags, DENYWRITE) | |
2dfbb274 AM |
13813 | + | AuConv_VM_MAP(flags, LOCKED); |
13814 | +} | |
38d290e6 | 13815 | +#endif |
2dfbb274 | 13816 | + |
9dbd164d | 13817 | +static int aufs_mmap(struct file *file, struct vm_area_struct *vma) |
dece6358 | 13818 | +{ |
4a4d8108 | 13819 | + int err; |
4a4d8108 | 13820 | + const unsigned char wlock |
9dbd164d | 13821 | + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED); |
4a4d8108 | 13822 | + struct super_block *sb; |
9dbd164d | 13823 | + struct file *h_file; |
b912730e | 13824 | + struct inode *inode; |
9dbd164d AM |
13825 | + |
13826 | + AuDbgVmRegion(file, vma); | |
1308ab2a | 13827 | + |
b912730e AM |
13828 | + inode = file_inode(file); |
13829 | + sb = inode->i_sb; | |
9dbd164d | 13830 | + lockdep_off(); |
e49829fe | 13831 | + si_read_lock(sb, AuLock_NOPLMW); |
4a4d8108 | 13832 | + |
b912730e | 13833 | + h_file = au_write_pre(file, wlock, /*wpre*/NULL); |
9dbd164d | 13834 | + lockdep_on(); |
b912730e AM |
13835 | + err = PTR_ERR(h_file); |
13836 | + if (IS_ERR(h_file)) | |
13837 | + goto out; | |
1308ab2a | 13838 | + |
b912730e AM |
13839 | + err = 0; |
13840 | + au_set_mmapped(file); | |
9dbd164d | 13841 | + au_vm_file_reset(vma, h_file); |
38d290e6 JR |
13842 | + /* |
13843 | + * we cannot call security_mmap_file() here since it may acquire | |
13844 | + * mmap_sem or i_mutex. | |
13845 | + * | |
13846 | + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags), | |
13847 | + * au_flag_conv(vma->vm_flags)); | |
13848 | + */ | |
9dbd164d AM |
13849 | + if (!err) |
13850 | + err = h_file->f_op->mmap(h_file, vma); | |
b912730e AM |
13851 | + if (!err) { |
13852 | + au_vm_prfile_set(vma, file); | |
13853 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
13854 | + goto out_fput; /* success */ | |
13855 | + } | |
2cbb1c4b JR |
13856 | + au_unset_mmapped(file); |
13857 | + au_vm_file_reset(vma, file); | |
b912730e | 13858 | + |
2cbb1c4b | 13859 | +out_fput: |
9dbd164d | 13860 | + lockdep_off(); |
b912730e AM |
13861 | + ii_write_unlock(inode); |
13862 | + lockdep_on(); | |
13863 | + fput(h_file); | |
4f0767ce | 13864 | +out: |
b912730e | 13865 | + lockdep_off(); |
9dbd164d AM |
13866 | + si_read_unlock(sb); |
13867 | + lockdep_on(); | |
13868 | + AuTraceErr(err); | |
4a4d8108 AM |
13869 | + return err; |
13870 | +} | |
13871 | + | |
13872 | +/* ---------------------------------------------------------------------- */ | |
13873 | + | |
1e00d052 AM |
13874 | +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end, |
13875 | + int datasync) | |
4a4d8108 AM |
13876 | +{ |
13877 | + int err; | |
b912730e | 13878 | + struct au_write_pre wpre; |
4a4d8108 AM |
13879 | + struct inode *inode; |
13880 | + struct file *h_file; | |
4a4d8108 AM |
13881 | + |
13882 | + err = 0; /* -EBADF; */ /* posix? */ | |
13883 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
b912730e | 13884 | + goto out; |
4a4d8108 | 13885 | + |
b912730e AM |
13886 | + inode = file_inode(file); |
13887 | + au_mtx_and_read_lock(inode); | |
13888 | + | |
13889 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); | |
13890 | + err = PTR_ERR(h_file); | |
13891 | + if (IS_ERR(h_file)) | |
4a4d8108 | 13892 | + goto out_unlock; |
4a4d8108 | 13893 | + |
53392da6 | 13894 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
b912730e | 13895 | + au_write_post(inode, h_file, &wpre, /*written*/0); |
4a4d8108 | 13896 | + |
4f0767ce | 13897 | +out_unlock: |
b912730e | 13898 | + si_read_unlock(inode->i_sb); |
1e00d052 | 13899 | + mutex_unlock(&inode->i_mutex); |
b912730e | 13900 | +out: |
4a4d8108 | 13901 | + return err; |
dece6358 AM |
13902 | +} |
13903 | + | |
4a4d8108 AM |
13904 | +/* no one supports this operation, currently */ |
13905 | +#if 0 | |
13906 | +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync) | |
dece6358 | 13907 | +{ |
4a4d8108 | 13908 | + int err; |
b912730e | 13909 | + struct au_write_pre wpre; |
4a4d8108 AM |
13910 | + struct inode *inode; |
13911 | + struct file *file, *h_file; | |
1308ab2a | 13912 | + |
4a4d8108 AM |
13913 | + err = 0; /* -EBADF; */ /* posix? */ |
13914 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
13915 | + goto out; | |
1308ab2a | 13916 | + |
b912730e AM |
13917 | + file = kio->ki_filp; |
13918 | + inode = file_inode(file); | |
13919 | + au_mtx_and_read_lock(inode); | |
13920 | + | |
13921 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); | |
13922 | + err = PTR_ERR(h_file); | |
13923 | + if (IS_ERR(h_file)) | |
4a4d8108 | 13924 | + goto out_unlock; |
1308ab2a | 13925 | + |
4a4d8108 AM |
13926 | + err = -ENOSYS; |
13927 | + h_file = au_hf_top(file); | |
523b37e3 | 13928 | + if (h_file->f_op->aio_fsync) { |
4a4d8108 | 13929 | + struct mutex *h_mtx; |
1308ab2a | 13930 | + |
c06a8ce3 | 13931 | + h_mtx = &file_inode(h_file)->i_mutex; |
4a4d8108 AM |
13932 | + if (!is_sync_kiocb(kio)) { |
13933 | + get_file(h_file); | |
13934 | + fput(file); | |
13935 | + } | |
13936 | + kio->ki_filp = h_file; | |
13937 | + err = h_file->f_op->aio_fsync(kio, datasync); | |
13938 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
13939 | + if (!err) | |
13940 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); | |
13941 | + /*ignore*/ | |
4a4d8108 AM |
13942 | + mutex_unlock(h_mtx); |
13943 | + } | |
b912730e | 13944 | + au_write_post(inode, h_file, &wpre, /*written*/0); |
1308ab2a | 13945 | + |
4f0767ce | 13946 | +out_unlock: |
e49829fe | 13947 | + si_read_unlock(inode->sb); |
4a4d8108 | 13948 | + mutex_unlock(&inode->i_mutex); |
b912730e | 13949 | +out: |
4a4d8108 | 13950 | + return err; |
dece6358 | 13951 | +} |
4a4d8108 | 13952 | +#endif |
dece6358 | 13953 | + |
4a4d8108 | 13954 | +static int aufs_fasync(int fd, struct file *file, int flag) |
dece6358 | 13955 | +{ |
4a4d8108 AM |
13956 | + int err; |
13957 | + struct file *h_file; | |
4a4d8108 | 13958 | + struct super_block *sb; |
1308ab2a | 13959 | + |
b912730e | 13960 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 13961 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e AM |
13962 | + |
13963 | + h_file = au_read_pre(file, /*keep_fi*/0); | |
13964 | + err = PTR_ERR(h_file); | |
13965 | + if (IS_ERR(h_file)) | |
4a4d8108 AM |
13966 | + goto out; |
13967 | + | |
523b37e3 | 13968 | + if (h_file->f_op->fasync) |
4a4d8108 | 13969 | + err = h_file->f_op->fasync(fd, h_file, flag); |
b912730e | 13970 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 13971 | + |
4f0767ce | 13972 | +out: |
4a4d8108 | 13973 | + si_read_unlock(sb); |
1308ab2a | 13974 | + return err; |
dece6358 | 13975 | +} |
4a4d8108 AM |
13976 | + |
13977 | +/* ---------------------------------------------------------------------- */ | |
13978 | + | |
13979 | +/* no one supports this operation, currently */ | |
13980 | +#if 0 | |
13981 | +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset, | |
2000de60 | 13982 | + size_t len, loff_t *pos, int more) |
4a4d8108 AM |
13983 | +{ |
13984 | +} | |
13985 | +#endif | |
13986 | + | |
13987 | +/* ---------------------------------------------------------------------- */ | |
13988 | + | |
13989 | +const struct file_operations aufs_file_fop = { | |
13990 | + .owner = THIS_MODULE, | |
2cbb1c4b | 13991 | + |
027c5e7a | 13992 | + .llseek = default_llseek, |
4a4d8108 AM |
13993 | + |
13994 | + .read = aufs_read, | |
13995 | + .write = aufs_write, | |
076b876e AM |
13996 | + .read_iter = aufs_read_iter, |
13997 | + .write_iter = aufs_write_iter, | |
13998 | + | |
4a4d8108 AM |
13999 | +#ifdef CONFIG_AUFS_POLL |
14000 | + .poll = aufs_poll, | |
14001 | +#endif | |
14002 | + .unlocked_ioctl = aufs_ioctl_nondir, | |
b752ccd1 | 14003 | +#ifdef CONFIG_COMPAT |
c2b27bf2 | 14004 | + .compat_ioctl = aufs_compat_ioctl_nondir, |
b752ccd1 | 14005 | +#endif |
4a4d8108 AM |
14006 | + .mmap = aufs_mmap, |
14007 | + .open = aufs_open_nondir, | |
14008 | + .flush = aufs_flush_nondir, | |
14009 | + .release = aufs_release_nondir, | |
14010 | + .fsync = aufs_fsync_nondir, | |
14011 | + /* .aio_fsync = aufs_aio_fsync_nondir, */ | |
14012 | + .fasync = aufs_fasync, | |
14013 | + /* .sendpage = aufs_sendpage, */ | |
14014 | + .splice_write = aufs_splice_write, | |
14015 | + .splice_read = aufs_splice_read, | |
14016 | +#if 0 | |
14017 | + .aio_splice_write = aufs_aio_splice_write, | |
38d290e6 | 14018 | + .aio_splice_read = aufs_aio_splice_read, |
4a4d8108 | 14019 | +#endif |
38d290e6 | 14020 | + .fallocate = aufs_fallocate |
4a4d8108 | 14021 | +}; |
7f207e10 AM |
14022 | diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h |
14023 | --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 14024 | +++ linux/fs/aufs/fstype.h 2015-06-28 17:35:44.348050491 +0200 |
b912730e | 14025 | @@ -0,0 +1,400 @@ |
4a4d8108 | 14026 | +/* |
2000de60 | 14027 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
14028 | + * |
14029 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14030 | + * it under the terms of the GNU General Public License as published by | |
14031 | + * the Free Software Foundation; either version 2 of the License, or | |
14032 | + * (at your option) any later version. | |
14033 | + * | |
14034 | + * This program is distributed in the hope that it will be useful, | |
14035 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14036 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14037 | + * GNU General Public License for more details. | |
14038 | + * | |
14039 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14040 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
14041 | + */ |
14042 | + | |
14043 | +/* | |
14044 | + * judging filesystem type | |
14045 | + */ | |
14046 | + | |
14047 | +#ifndef __AUFS_FSTYPE_H__ | |
14048 | +#define __AUFS_FSTYPE_H__ | |
14049 | + | |
14050 | +#ifdef __KERNEL__ | |
14051 | + | |
14052 | +#include <linux/fs.h> | |
14053 | +#include <linux/magic.h> | |
14054 | +#include <linux/romfs_fs.h> | |
b912730e | 14055 | +#include <linux/nfs_fs.h> |
4a4d8108 AM |
14056 | + |
14057 | +static inline int au_test_aufs(struct super_block *sb) | |
14058 | +{ | |
14059 | + return sb->s_magic == AUFS_SUPER_MAGIC; | |
14060 | +} | |
14061 | + | |
14062 | +static inline const char *au_sbtype(struct super_block *sb) | |
14063 | +{ | |
14064 | + return sb->s_type->name; | |
14065 | +} | |
1308ab2a | 14066 | + |
14067 | +static inline int au_test_iso9660(struct super_block *sb __maybe_unused) | |
14068 | +{ | |
2000de60 JR |
14069 | +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE) |
14070 | + return sb->s_magic == ISOFS_SUPER_MAGIC; | |
dece6358 AM |
14071 | +#else |
14072 | + return 0; | |
14073 | +#endif | |
14074 | +} | |
14075 | + | |
1308ab2a | 14076 | +static inline int au_test_romfs(struct super_block *sb __maybe_unused) |
dece6358 | 14077 | +{ |
2000de60 JR |
14078 | +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE) |
14079 | + return sb->s_magic == ROMFS_MAGIC; | |
dece6358 AM |
14080 | +#else |
14081 | + return 0; | |
14082 | +#endif | |
14083 | +} | |
14084 | + | |
1308ab2a | 14085 | +static inline int au_test_cramfs(struct super_block *sb __maybe_unused) |
dece6358 | 14086 | +{ |
1308ab2a | 14087 | +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE) |
14088 | + return sb->s_magic == CRAMFS_MAGIC; | |
14089 | +#endif | |
14090 | + return 0; | |
14091 | +} | |
14092 | + | |
14093 | +static inline int au_test_nfs(struct super_block *sb __maybe_unused) | |
14094 | +{ | |
14095 | +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE) | |
14096 | + return sb->s_magic == NFS_SUPER_MAGIC; | |
dece6358 AM |
14097 | +#else |
14098 | + return 0; | |
14099 | +#endif | |
14100 | +} | |
14101 | + | |
1308ab2a | 14102 | +static inline int au_test_fuse(struct super_block *sb __maybe_unused) |
dece6358 | 14103 | +{ |
1308ab2a | 14104 | +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE) |
14105 | + return sb->s_magic == FUSE_SUPER_MAGIC; | |
dece6358 AM |
14106 | +#else |
14107 | + return 0; | |
14108 | +#endif | |
14109 | +} | |
14110 | + | |
1308ab2a | 14111 | +static inline int au_test_xfs(struct super_block *sb __maybe_unused) |
dece6358 | 14112 | +{ |
1308ab2a | 14113 | +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE) |
14114 | + return sb->s_magic == XFS_SB_MAGIC; | |
dece6358 AM |
14115 | +#else |
14116 | + return 0; | |
14117 | +#endif | |
14118 | +} | |
14119 | + | |
1308ab2a | 14120 | +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused) |
dece6358 | 14121 | +{ |
1308ab2a | 14122 | +#ifdef CONFIG_TMPFS |
14123 | + return sb->s_magic == TMPFS_MAGIC; | |
14124 | +#else | |
14125 | + return 0; | |
dece6358 | 14126 | +#endif |
dece6358 AM |
14127 | +} |
14128 | + | |
1308ab2a | 14129 | +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused) |
1facf9fc | 14130 | +{ |
1308ab2a | 14131 | +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE) |
14132 | + return !strcmp(au_sbtype(sb), "ecryptfs"); | |
14133 | +#else | |
14134 | + return 0; | |
14135 | +#endif | |
1facf9fc | 14136 | +} |
14137 | + | |
1308ab2a | 14138 | +static inline int au_test_ramfs(struct super_block *sb) |
14139 | +{ | |
14140 | + return sb->s_magic == RAMFS_MAGIC; | |
14141 | +} | |
14142 | + | |
14143 | +static inline int au_test_ubifs(struct super_block *sb __maybe_unused) | |
14144 | +{ | |
14145 | +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE) | |
14146 | + return sb->s_magic == UBIFS_SUPER_MAGIC; | |
14147 | +#else | |
14148 | + return 0; | |
14149 | +#endif | |
14150 | +} | |
14151 | + | |
14152 | +static inline int au_test_procfs(struct super_block *sb __maybe_unused) | |
14153 | +{ | |
14154 | +#ifdef CONFIG_PROC_FS | |
14155 | + return sb->s_magic == PROC_SUPER_MAGIC; | |
14156 | +#else | |
14157 | + return 0; | |
14158 | +#endif | |
14159 | +} | |
14160 | + | |
14161 | +static inline int au_test_sysfs(struct super_block *sb __maybe_unused) | |
14162 | +{ | |
14163 | +#ifdef CONFIG_SYSFS | |
14164 | + return sb->s_magic == SYSFS_MAGIC; | |
14165 | +#else | |
14166 | + return 0; | |
14167 | +#endif | |
14168 | +} | |
14169 | + | |
14170 | +static inline int au_test_configfs(struct super_block *sb __maybe_unused) | |
14171 | +{ | |
14172 | +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE) | |
14173 | + return sb->s_magic == CONFIGFS_MAGIC; | |
14174 | +#else | |
14175 | + return 0; | |
14176 | +#endif | |
14177 | +} | |
14178 | + | |
14179 | +static inline int au_test_minix(struct super_block *sb __maybe_unused) | |
14180 | +{ | |
14181 | +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE) | |
14182 | + return sb->s_magic == MINIX3_SUPER_MAGIC | |
14183 | + || sb->s_magic == MINIX2_SUPER_MAGIC | |
14184 | + || sb->s_magic == MINIX2_SUPER_MAGIC2 | |
14185 | + || sb->s_magic == MINIX_SUPER_MAGIC | |
14186 | + || sb->s_magic == MINIX_SUPER_MAGIC2; | |
14187 | +#else | |
14188 | + return 0; | |
14189 | +#endif | |
14190 | +} | |
14191 | + | |
1308ab2a | 14192 | +static inline int au_test_fat(struct super_block *sb __maybe_unused) |
14193 | +{ | |
14194 | +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE) | |
14195 | + return sb->s_magic == MSDOS_SUPER_MAGIC; | |
14196 | +#else | |
14197 | + return 0; | |
14198 | +#endif | |
14199 | +} | |
14200 | + | |
14201 | +static inline int au_test_msdos(struct super_block *sb) | |
14202 | +{ | |
14203 | + return au_test_fat(sb); | |
14204 | +} | |
14205 | + | |
14206 | +static inline int au_test_vfat(struct super_block *sb) | |
14207 | +{ | |
14208 | + return au_test_fat(sb); | |
14209 | +} | |
14210 | + | |
14211 | +static inline int au_test_securityfs(struct super_block *sb __maybe_unused) | |
14212 | +{ | |
14213 | +#ifdef CONFIG_SECURITYFS | |
14214 | + return sb->s_magic == SECURITYFS_MAGIC; | |
14215 | +#else | |
14216 | + return 0; | |
14217 | +#endif | |
14218 | +} | |
14219 | + | |
14220 | +static inline int au_test_squashfs(struct super_block *sb __maybe_unused) | |
14221 | +{ | |
14222 | +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE) | |
14223 | + return sb->s_magic == SQUASHFS_MAGIC; | |
14224 | +#else | |
14225 | + return 0; | |
14226 | +#endif | |
14227 | +} | |
14228 | + | |
14229 | +static inline int au_test_btrfs(struct super_block *sb __maybe_unused) | |
14230 | +{ | |
14231 | +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE) | |
14232 | + return sb->s_magic == BTRFS_SUPER_MAGIC; | |
14233 | +#else | |
14234 | + return 0; | |
14235 | +#endif | |
14236 | +} | |
14237 | + | |
14238 | +static inline int au_test_xenfs(struct super_block *sb __maybe_unused) | |
14239 | +{ | |
14240 | +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE) | |
14241 | + return sb->s_magic == XENFS_SUPER_MAGIC; | |
14242 | +#else | |
14243 | + return 0; | |
14244 | +#endif | |
14245 | +} | |
14246 | + | |
14247 | +static inline int au_test_debugfs(struct super_block *sb __maybe_unused) | |
14248 | +{ | |
14249 | +#ifdef CONFIG_DEBUG_FS | |
14250 | + return sb->s_magic == DEBUGFS_MAGIC; | |
14251 | +#else | |
14252 | + return 0; | |
14253 | +#endif | |
14254 | +} | |
14255 | + | |
14256 | +static inline int au_test_nilfs(struct super_block *sb __maybe_unused) | |
14257 | +{ | |
14258 | +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE) | |
14259 | + return sb->s_magic == NILFS_SUPER_MAGIC; | |
14260 | +#else | |
14261 | + return 0; | |
14262 | +#endif | |
14263 | +} | |
14264 | + | |
4a4d8108 AM |
14265 | +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused) |
14266 | +{ | |
14267 | +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE) | |
14268 | + return sb->s_magic == HFSPLUS_SUPER_MAGIC; | |
14269 | +#else | |
14270 | + return 0; | |
14271 | +#endif | |
14272 | +} | |
14273 | + | |
1308ab2a | 14274 | +/* ---------------------------------------------------------------------- */ |
14275 | +/* | |
14276 | + * they can't be an aufs branch. | |
14277 | + */ | |
14278 | +static inline int au_test_fs_unsuppoted(struct super_block *sb) | |
14279 | +{ | |
14280 | + return | |
14281 | +#ifndef CONFIG_AUFS_BR_RAMFS | |
14282 | + au_test_ramfs(sb) || | |
14283 | +#endif | |
14284 | + au_test_procfs(sb) | |
14285 | + || au_test_sysfs(sb) | |
14286 | + || au_test_configfs(sb) | |
14287 | + || au_test_debugfs(sb) | |
14288 | + || au_test_securityfs(sb) | |
14289 | + || au_test_xenfs(sb) | |
14290 | + || au_test_ecryptfs(sb) | |
14291 | + /* || !strcmp(au_sbtype(sb), "unionfs") */ | |
14292 | + || au_test_aufs(sb); /* will be supported in next version */ | |
14293 | +} | |
14294 | + | |
1308ab2a | 14295 | +static inline int au_test_fs_remote(struct super_block *sb) |
14296 | +{ | |
14297 | + return !au_test_tmpfs(sb) | |
14298 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14299 | + && !au_test_ramfs(sb) | |
14300 | +#endif | |
14301 | + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV); | |
14302 | +} | |
14303 | + | |
14304 | +/* ---------------------------------------------------------------------- */ | |
14305 | + | |
14306 | +/* | |
14307 | + * Note: these functions (below) are created after reading ->getattr() in all | |
14308 | + * filesystems under linux/fs. it means we have to do so in every update... | |
14309 | + */ | |
14310 | + | |
14311 | +/* | |
14312 | + * some filesystems require getattr to refresh the inode attributes before | |
14313 | + * referencing. | |
14314 | + * in most cases, we can rely on the inode attribute in NFS (or every remote fs) | |
14315 | + * and leave the work for d_revalidate() | |
14316 | + */ | |
14317 | +static inline int au_test_fs_refresh_iattr(struct super_block *sb) | |
14318 | +{ | |
14319 | + return au_test_nfs(sb) | |
14320 | + || au_test_fuse(sb) | |
1308ab2a | 14321 | + /* || au_test_btrfs(sb) */ /* untested */ |
1308ab2a | 14322 | + ; |
14323 | +} | |
14324 | + | |
14325 | +/* | |
14326 | + * filesystems which don't maintain i_size or i_blocks. | |
14327 | + */ | |
14328 | +static inline int au_test_fs_bad_iattr_size(struct super_block *sb) | |
14329 | +{ | |
14330 | + return au_test_xfs(sb) | |
4a4d8108 AM |
14331 | + || au_test_btrfs(sb) |
14332 | + || au_test_ubifs(sb) | |
14333 | + || au_test_hfsplus(sb) /* maintained, but incorrect */ | |
1308ab2a | 14334 | + /* || au_test_minix(sb) */ /* untested */ |
14335 | + ; | |
14336 | +} | |
14337 | + | |
14338 | +/* | |
14339 | + * filesystems which don't store the correct value in some of their inode | |
14340 | + * attributes. | |
14341 | + */ | |
14342 | +static inline int au_test_fs_bad_iattr(struct super_block *sb) | |
14343 | +{ | |
14344 | + return au_test_fs_bad_iattr_size(sb) | |
1308ab2a | 14345 | + || au_test_fat(sb) |
14346 | + || au_test_msdos(sb) | |
14347 | + || au_test_vfat(sb); | |
1facf9fc | 14348 | +} |
14349 | + | |
14350 | +/* they don't check i_nlink in link(2) */ | |
14351 | +static inline int au_test_fs_no_limit_nlink(struct super_block *sb) | |
14352 | +{ | |
14353 | + return au_test_tmpfs(sb) | |
14354 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14355 | + || au_test_ramfs(sb) | |
14356 | +#endif | |
4a4d8108 | 14357 | + || au_test_ubifs(sb) |
4a4d8108 | 14358 | + || au_test_hfsplus(sb); |
1facf9fc | 14359 | +} |
14360 | + | |
14361 | +/* | |
14362 | + * filesystems which sets S_NOATIME and S_NOCMTIME. | |
14363 | + */ | |
14364 | +static inline int au_test_fs_notime(struct super_block *sb) | |
14365 | +{ | |
14366 | + return au_test_nfs(sb) | |
14367 | + || au_test_fuse(sb) | |
dece6358 | 14368 | + || au_test_ubifs(sb) |
1facf9fc | 14369 | + ; |
14370 | +} | |
14371 | + | |
1facf9fc | 14372 | +/* temporary support for i#1 in cramfs */ |
14373 | +static inline int au_test_fs_unique_ino(struct inode *inode) | |
14374 | +{ | |
14375 | + if (au_test_cramfs(inode->i_sb)) | |
14376 | + return inode->i_ino != 1; | |
14377 | + return 1; | |
14378 | +} | |
14379 | + | |
14380 | +/* ---------------------------------------------------------------------- */ | |
14381 | + | |
14382 | +/* | |
14383 | + * the filesystem where the xino files placed must support i/o after unlink and | |
14384 | + * maintain i_size and i_blocks. | |
14385 | + */ | |
14386 | +static inline int au_test_fs_bad_xino(struct super_block *sb) | |
14387 | +{ | |
14388 | + return au_test_fs_remote(sb) | |
14389 | + || au_test_fs_bad_iattr_size(sb) | |
1facf9fc | 14390 | + /* don't want unnecessary work for xino */ |
14391 | + || au_test_aufs(sb) | |
1308ab2a | 14392 | + || au_test_ecryptfs(sb) |
14393 | + || au_test_nilfs(sb); | |
1facf9fc | 14394 | +} |
14395 | + | |
14396 | +static inline int au_test_fs_trunc_xino(struct super_block *sb) | |
14397 | +{ | |
14398 | + return au_test_tmpfs(sb) | |
14399 | + || au_test_ramfs(sb); | |
14400 | +} | |
14401 | + | |
14402 | +/* | |
14403 | + * test if the @sb is real-readonly. | |
14404 | + */ | |
14405 | +static inline int au_test_fs_rr(struct super_block *sb) | |
14406 | +{ | |
14407 | + return au_test_squashfs(sb) | |
14408 | + || au_test_iso9660(sb) | |
14409 | + || au_test_cramfs(sb) | |
14410 | + || au_test_romfs(sb); | |
14411 | +} | |
14412 | + | |
b912730e AM |
14413 | +/* |
14414 | + * test if the @inode is nfs with 'noacl' option | |
14415 | + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.' | |
14416 | + */ | |
14417 | +static inline int au_test_nfs_noacl(struct inode *inode) | |
14418 | +{ | |
14419 | + return au_test_nfs(inode->i_sb) | |
14420 | + /* && IS_POSIXACL(inode) */ | |
14421 | + && !nfs_server_capable(inode, NFS_CAP_ACLS); | |
14422 | +} | |
14423 | + | |
1facf9fc | 14424 | +#endif /* __KERNEL__ */ |
14425 | +#endif /* __AUFS_FSTYPE_H__ */ | |
7f207e10 AM |
14426 | diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c |
14427 | --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 14428 | +++ linux/fs/aufs/hfsnotify.c 2015-06-28 17:35:44.348050491 +0200 |
c1595e42 | 14429 | @@ -0,0 +1,288 @@ |
1facf9fc | 14430 | +/* |
2000de60 | 14431 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 14432 | + * |
14433 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14434 | + * it under the terms of the GNU General Public License as published by | |
14435 | + * the Free Software Foundation; either version 2 of the License, or | |
14436 | + * (at your option) any later version. | |
dece6358 AM |
14437 | + * |
14438 | + * This program is distributed in the hope that it will be useful, | |
14439 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14440 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14441 | + * GNU General Public License for more details. | |
14442 | + * | |
14443 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14444 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 14445 | + */ |
14446 | + | |
14447 | +/* | |
4a4d8108 | 14448 | + * fsnotify for the lower directories |
1facf9fc | 14449 | + */ |
14450 | + | |
14451 | +#include "aufs.h" | |
14452 | + | |
4a4d8108 AM |
14453 | +/* FS_IN_IGNORED is unnecessary */ |
14454 | +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE | |
14455 | + | FS_CREATE | FS_EVENT_ON_CHILD); | |
7f207e10 | 14456 | +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq); |
7eafdf33 | 14457 | +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0); |
1facf9fc | 14458 | + |
0c5527e5 | 14459 | +static void au_hfsn_free_mark(struct fsnotify_mark *mark) |
1facf9fc | 14460 | +{ |
0c5527e5 AM |
14461 | + struct au_hnotify *hn = container_of(mark, struct au_hnotify, |
14462 | + hn_mark); | |
4a4d8108 | 14463 | + AuDbg("here\n"); |
7eafdf33 | 14464 | + au_cache_free_hnotify(hn); |
076b876e | 14465 | + smp_mb__before_atomic(); |
1716fcea AM |
14466 | + if (atomic64_dec_and_test(&au_hfsn_ifree)) |
14467 | + wake_up(&au_hfsn_wq); | |
4a4d8108 | 14468 | +} |
1facf9fc | 14469 | + |
027c5e7a | 14470 | +static int au_hfsn_alloc(struct au_hinode *hinode) |
4a4d8108 | 14471 | +{ |
1716fcea | 14472 | + int err; |
027c5e7a AM |
14473 | + struct au_hnotify *hn; |
14474 | + struct super_block *sb; | |
14475 | + struct au_branch *br; | |
0c5527e5 | 14476 | + struct fsnotify_mark *mark; |
027c5e7a | 14477 | + aufs_bindex_t bindex; |
1facf9fc | 14478 | + |
027c5e7a AM |
14479 | + hn = hinode->hi_notify; |
14480 | + sb = hn->hn_aufs_inode->i_sb; | |
14481 | + bindex = au_br_index(sb, hinode->hi_id); | |
14482 | + br = au_sbr(sb, bindex); | |
1716fcea AM |
14483 | + AuDebugOn(!br->br_hfsn); |
14484 | + | |
0c5527e5 AM |
14485 | + mark = &hn->hn_mark; |
14486 | + fsnotify_init_mark(mark, au_hfsn_free_mark); | |
14487 | + mark->mask = AuHfsnMask; | |
7f207e10 AM |
14488 | + /* |
14489 | + * by udba rename or rmdir, aufs assign a new inode to the known | |
14490 | + * h_inode, so specify 1 to allow dups. | |
14491 | + */ | |
c1595e42 | 14492 | + lockdep_off(); |
1716fcea | 14493 | + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode, |
027c5e7a | 14494 | + /*mnt*/NULL, /*allow_dups*/1); |
1716fcea AM |
14495 | + /* even if err */ |
14496 | + fsnotify_put_mark(mark); | |
c1595e42 | 14497 | + lockdep_on(); |
1716fcea AM |
14498 | + |
14499 | + return err; | |
1facf9fc | 14500 | +} |
14501 | + | |
7eafdf33 | 14502 | +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn) |
1facf9fc | 14503 | +{ |
0c5527e5 | 14504 | + struct fsnotify_mark *mark; |
7eafdf33 | 14505 | + unsigned long long ull; |
1716fcea | 14506 | + struct fsnotify_group *group; |
7eafdf33 AM |
14507 | + |
14508 | + ull = atomic64_inc_return(&au_hfsn_ifree); | |
14509 | + BUG_ON(!ull); | |
953406b4 | 14510 | + |
0c5527e5 | 14511 | + mark = &hn->hn_mark; |
1716fcea AM |
14512 | + spin_lock(&mark->lock); |
14513 | + group = mark->group; | |
14514 | + fsnotify_get_group(group); | |
14515 | + spin_unlock(&mark->lock); | |
c1595e42 | 14516 | + lockdep_off(); |
1716fcea AM |
14517 | + fsnotify_destroy_mark(mark, group); |
14518 | + fsnotify_put_group(group); | |
c1595e42 | 14519 | + lockdep_on(); |
7f207e10 | 14520 | + |
7eafdf33 AM |
14521 | + /* free hn by myself */ |
14522 | + return 0; | |
1facf9fc | 14523 | +} |
14524 | + | |
14525 | +/* ---------------------------------------------------------------------- */ | |
14526 | + | |
4a4d8108 | 14527 | +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set) |
1facf9fc | 14528 | +{ |
0c5527e5 | 14529 | + struct fsnotify_mark *mark; |
1facf9fc | 14530 | + |
0c5527e5 AM |
14531 | + mark = &hinode->hi_notify->hn_mark; |
14532 | + spin_lock(&mark->lock); | |
1facf9fc | 14533 | + if (do_set) { |
0c5527e5 AM |
14534 | + AuDebugOn(mark->mask & AuHfsnMask); |
14535 | + mark->mask |= AuHfsnMask; | |
1facf9fc | 14536 | + } else { |
0c5527e5 AM |
14537 | + AuDebugOn(!(mark->mask & AuHfsnMask)); |
14538 | + mark->mask &= ~AuHfsnMask; | |
1facf9fc | 14539 | + } |
0c5527e5 | 14540 | + spin_unlock(&mark->lock); |
4a4d8108 | 14541 | + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */ |
1facf9fc | 14542 | +} |
14543 | + | |
4a4d8108 | 14544 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 14545 | + |
4a4d8108 AM |
14546 | +/* #define AuDbgHnotify */ |
14547 | +#ifdef AuDbgHnotify | |
14548 | +static char *au_hfsn_name(u32 mask) | |
14549 | +{ | |
14550 | +#ifdef CONFIG_AUFS_DEBUG | |
c06a8ce3 AM |
14551 | +#define test_ret(flag) \ |
14552 | + do { \ | |
14553 | + if (mask & flag) \ | |
14554 | + return #flag; \ | |
14555 | + } while (0) | |
4a4d8108 AM |
14556 | + test_ret(FS_ACCESS); |
14557 | + test_ret(FS_MODIFY); | |
14558 | + test_ret(FS_ATTRIB); | |
14559 | + test_ret(FS_CLOSE_WRITE); | |
14560 | + test_ret(FS_CLOSE_NOWRITE); | |
14561 | + test_ret(FS_OPEN); | |
14562 | + test_ret(FS_MOVED_FROM); | |
14563 | + test_ret(FS_MOVED_TO); | |
14564 | + test_ret(FS_CREATE); | |
14565 | + test_ret(FS_DELETE); | |
14566 | + test_ret(FS_DELETE_SELF); | |
14567 | + test_ret(FS_MOVE_SELF); | |
14568 | + test_ret(FS_UNMOUNT); | |
14569 | + test_ret(FS_Q_OVERFLOW); | |
14570 | + test_ret(FS_IN_IGNORED); | |
b912730e | 14571 | + test_ret(FS_ISDIR); |
4a4d8108 AM |
14572 | + test_ret(FS_IN_ONESHOT); |
14573 | + test_ret(FS_EVENT_ON_CHILD); | |
14574 | + return ""; | |
14575 | +#undef test_ret | |
14576 | +#else | |
14577 | + return "??"; | |
14578 | +#endif | |
1facf9fc | 14579 | +} |
4a4d8108 | 14580 | +#endif |
1facf9fc | 14581 | + |
14582 | +/* ---------------------------------------------------------------------- */ | |
14583 | + | |
1716fcea AM |
14584 | +static void au_hfsn_free_group(struct fsnotify_group *group) |
14585 | +{ | |
14586 | + struct au_br_hfsnotify *hfsn = group->private; | |
14587 | + | |
14588 | + AuDbg("here\n"); | |
14589 | + kfree(hfsn); | |
14590 | +} | |
14591 | + | |
4a4d8108 | 14592 | +static int au_hfsn_handle_event(struct fsnotify_group *group, |
fb47a38f | 14593 | + struct inode *inode, |
0c5527e5 AM |
14594 | + struct fsnotify_mark *inode_mark, |
14595 | + struct fsnotify_mark *vfsmount_mark, | |
fb47a38f JR |
14596 | + u32 mask, void *data, int data_type, |
14597 | + const unsigned char *file_name, u32 cookie) | |
1facf9fc | 14598 | +{ |
14599 | + int err; | |
4a4d8108 AM |
14600 | + struct au_hnotify *hnotify; |
14601 | + struct inode *h_dir, *h_inode; | |
fb47a38f | 14602 | + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name)); |
4a4d8108 | 14603 | + |
fb47a38f | 14604 | + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE); |
1facf9fc | 14605 | + |
14606 | + err = 0; | |
0c5527e5 | 14607 | + /* if FS_UNMOUNT happens, there must be another bug */ |
4a4d8108 | 14608 | + AuDebugOn(mask & FS_UNMOUNT); |
0c5527e5 | 14609 | + if (mask & (FS_IN_IGNORED | FS_UNMOUNT)) |
1facf9fc | 14610 | + goto out; |
1facf9fc | 14611 | + |
fb47a38f JR |
14612 | + h_dir = inode; |
14613 | + h_inode = NULL; | |
4a4d8108 | 14614 | +#ifdef AuDbgHnotify |
392086de | 14615 | + au_debug_on(); |
4a4d8108 AM |
14616 | + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1 |
14617 | + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) { | |
14618 | + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n", | |
14619 | + h_dir->i_ino, mask, au_hfsn_name(mask), | |
14620 | + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0); | |
14621 | + /* WARN_ON(1); */ | |
1facf9fc | 14622 | + } |
392086de | 14623 | + au_debug_off(); |
1facf9fc | 14624 | +#endif |
4a4d8108 | 14625 | + |
0c5527e5 AM |
14626 | + AuDebugOn(!inode_mark); |
14627 | + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark); | |
14628 | + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode); | |
1facf9fc | 14629 | + |
4a4d8108 AM |
14630 | +out: |
14631 | + return err; | |
14632 | +} | |
1facf9fc | 14633 | + |
4a4d8108 | 14634 | +static struct fsnotify_ops au_hfsn_ops = { |
1716fcea AM |
14635 | + .handle_event = au_hfsn_handle_event, |
14636 | + .free_group_priv = au_hfsn_free_group | |
4a4d8108 AM |
14637 | +}; |
14638 | + | |
14639 | +/* ---------------------------------------------------------------------- */ | |
14640 | + | |
027c5e7a AM |
14641 | +static void au_hfsn_fin_br(struct au_branch *br) |
14642 | +{ | |
1716fcea | 14643 | + struct au_br_hfsnotify *hfsn; |
027c5e7a | 14644 | + |
1716fcea | 14645 | + hfsn = br->br_hfsn; |
c1595e42 JR |
14646 | + if (hfsn) { |
14647 | + lockdep_off(); | |
1716fcea | 14648 | + fsnotify_put_group(hfsn->hfsn_group); |
c1595e42 JR |
14649 | + lockdep_on(); |
14650 | + } | |
027c5e7a AM |
14651 | +} |
14652 | + | |
1716fcea | 14653 | +static int au_hfsn_init_br(struct au_branch *br, int perm) |
4a4d8108 AM |
14654 | +{ |
14655 | + int err; | |
1716fcea AM |
14656 | + struct fsnotify_group *group; |
14657 | + struct au_br_hfsnotify *hfsn; | |
1facf9fc | 14658 | + |
4a4d8108 | 14659 | + err = 0; |
1716fcea AM |
14660 | + br->br_hfsn = NULL; |
14661 | + if (!au_br_hnotifyable(perm)) | |
027c5e7a | 14662 | + goto out; |
027c5e7a | 14663 | + |
1716fcea AM |
14664 | + err = -ENOMEM; |
14665 | + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS); | |
14666 | + if (unlikely(!hfsn)) | |
027c5e7a AM |
14667 | + goto out; |
14668 | + | |
1716fcea AM |
14669 | + err = 0; |
14670 | + group = fsnotify_alloc_group(&au_hfsn_ops); | |
14671 | + if (IS_ERR(group)) { | |
14672 | + err = PTR_ERR(group); | |
0c5527e5 | 14673 | + pr_err("fsnotify_alloc_group() failed, %d\n", err); |
1716fcea | 14674 | + goto out_hfsn; |
4a4d8108 | 14675 | + } |
1facf9fc | 14676 | + |
1716fcea AM |
14677 | + group->private = hfsn; |
14678 | + hfsn->hfsn_group = group; | |
14679 | + br->br_hfsn = hfsn; | |
14680 | + goto out; /* success */ | |
14681 | + | |
14682 | +out_hfsn: | |
14683 | + kfree(hfsn); | |
027c5e7a | 14684 | +out: |
1716fcea AM |
14685 | + return err; |
14686 | +} | |
14687 | + | |
14688 | +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
14689 | +{ | |
14690 | + int err; | |
14691 | + | |
14692 | + err = 0; | |
14693 | + if (!br->br_hfsn) | |
14694 | + err = au_hfsn_init_br(br, perm); | |
14695 | + | |
1facf9fc | 14696 | + return err; |
14697 | +} | |
14698 | + | |
7eafdf33 AM |
14699 | +/* ---------------------------------------------------------------------- */ |
14700 | + | |
14701 | +static void au_hfsn_fin(void) | |
14702 | +{ | |
14703 | + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree)); | |
14704 | + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree)); | |
14705 | +} | |
14706 | + | |
4a4d8108 AM |
14707 | +const struct au_hnotify_op au_hnotify_op = { |
14708 | + .ctl = au_hfsn_ctl, | |
14709 | + .alloc = au_hfsn_alloc, | |
14710 | + .free = au_hfsn_free, | |
1facf9fc | 14711 | + |
7eafdf33 AM |
14712 | + .fin = au_hfsn_fin, |
14713 | + | |
027c5e7a AM |
14714 | + .reset_br = au_hfsn_reset_br, |
14715 | + .fin_br = au_hfsn_fin_br, | |
14716 | + .init_br = au_hfsn_init_br | |
4a4d8108 | 14717 | +}; |
7f207e10 AM |
14718 | diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c |
14719 | --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 14720 | +++ linux/fs/aufs/hfsplus.c 2015-06-28 17:36:09.025073697 +0200 |
523b37e3 | 14721 | @@ -0,0 +1,56 @@ |
4a4d8108 | 14722 | +/* |
2000de60 | 14723 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
4a4d8108 AM |
14724 | + * |
14725 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14726 | + * it under the terms of the GNU General Public License as published by | |
14727 | + * the Free Software Foundation; either version 2 of the License, or | |
14728 | + * (at your option) any later version. | |
14729 | + * | |
14730 | + * This program is distributed in the hope that it will be useful, | |
14731 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14732 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14733 | + * GNU General Public License for more details. | |
14734 | + * | |
14735 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14736 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 14737 | + */ |
1facf9fc | 14738 | + |
4a4d8108 AM |
14739 | +/* |
14740 | + * special support for filesystems which aqucires an inode mutex | |
14741 | + * at final closing a file, eg, hfsplus. | |
14742 | + * | |
14743 | + * This trick is very simple and stupid, just to open the file before really | |
14744 | + * neceeary open to tell hfsplus that this is not the final closing. | |
14745 | + * The caller should call au_h_open_pre() after acquiring the inode mutex, | |
14746 | + * and au_h_open_post() after releasing it. | |
14747 | + */ | |
1facf9fc | 14748 | + |
4a4d8108 | 14749 | +#include "aufs.h" |
1facf9fc | 14750 | + |
392086de AM |
14751 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
14752 | + int force_wr) | |
4a4d8108 AM |
14753 | +{ |
14754 | + struct file *h_file; | |
14755 | + struct dentry *h_dentry; | |
1facf9fc | 14756 | + |
4a4d8108 AM |
14757 | + h_dentry = au_h_dptr(dentry, bindex); |
14758 | + AuDebugOn(!h_dentry); | |
5527c038 | 14759 | + AuDebugOn(d_is_negative(h_dentry)); |
4a4d8108 AM |
14760 | + |
14761 | + h_file = NULL; | |
14762 | + if (au_test_hfsplus(h_dentry->d_sb) | |
7e9cd9fe | 14763 | + && d_is_reg(h_dentry)) |
4a4d8108 AM |
14764 | + h_file = au_h_open(dentry, bindex, |
14765 | + O_RDONLY | O_NOATIME | O_LARGEFILE, | |
392086de | 14766 | + /*file*/NULL, force_wr); |
4a4d8108 | 14767 | + return h_file; |
1facf9fc | 14768 | +} |
14769 | + | |
4a4d8108 AM |
14770 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
14771 | + struct file *h_file) | |
14772 | +{ | |
14773 | + if (h_file) { | |
14774 | + fput(h_file); | |
14775 | + au_sbr_put(dentry->d_sb, bindex); | |
14776 | + } | |
14777 | +} | |
7f207e10 AM |
14778 | diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c |
14779 | --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
14780 | +++ linux/fs/aufs/hnotify.c 2015-06-28 17:36:09.025073697 +0200 |
14781 | @@ -0,0 +1,710 @@ | |
e49829fe | 14782 | +/* |
2000de60 | 14783 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
e49829fe JR |
14784 | + * |
14785 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14786 | + * it under the terms of the GNU General Public License as published by | |
14787 | + * the Free Software Foundation; either version 2 of the License, or | |
14788 | + * (at your option) any later version. | |
14789 | + * | |
14790 | + * This program is distributed in the hope that it will be useful, | |
14791 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14792 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14793 | + * GNU General Public License for more details. | |
14794 | + * | |
14795 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14796 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
14797 | + */ |
14798 | + | |
14799 | +/* | |
7f207e10 | 14800 | + * abstraction to notify the direct changes on lower directories |
e49829fe JR |
14801 | + */ |
14802 | + | |
14803 | +#include "aufs.h" | |
14804 | + | |
027c5e7a | 14805 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode) |
e49829fe JR |
14806 | +{ |
14807 | + int err; | |
7f207e10 | 14808 | + struct au_hnotify *hn; |
1facf9fc | 14809 | + |
4a4d8108 AM |
14810 | + err = -ENOMEM; |
14811 | + hn = au_cache_alloc_hnotify(); | |
14812 | + if (hn) { | |
14813 | + hn->hn_aufs_inode = inode; | |
027c5e7a AM |
14814 | + hinode->hi_notify = hn; |
14815 | + err = au_hnotify_op.alloc(hinode); | |
14816 | + AuTraceErr(err); | |
14817 | + if (unlikely(err)) { | |
14818 | + hinode->hi_notify = NULL; | |
4a4d8108 AM |
14819 | + au_cache_free_hnotify(hn); |
14820 | + /* | |
14821 | + * The upper dir was removed by udba, but the same named | |
14822 | + * dir left. In this case, aufs assignes a new inode | |
14823 | + * number and set the monitor again. | |
14824 | + * For the lower dir, the old monitnor is still left. | |
14825 | + */ | |
14826 | + if (err == -EEXIST) | |
14827 | + err = 0; | |
14828 | + } | |
1308ab2a | 14829 | + } |
1308ab2a | 14830 | + |
027c5e7a | 14831 | + AuTraceErr(err); |
1308ab2a | 14832 | + return err; |
dece6358 | 14833 | +} |
1facf9fc | 14834 | + |
4a4d8108 | 14835 | +void au_hn_free(struct au_hinode *hinode) |
dece6358 | 14836 | +{ |
4a4d8108 | 14837 | + struct au_hnotify *hn; |
1facf9fc | 14838 | + |
4a4d8108 AM |
14839 | + hn = hinode->hi_notify; |
14840 | + if (hn) { | |
4a4d8108 | 14841 | + hinode->hi_notify = NULL; |
7eafdf33 AM |
14842 | + if (au_hnotify_op.free(hinode, hn)) |
14843 | + au_cache_free_hnotify(hn); | |
4a4d8108 AM |
14844 | + } |
14845 | +} | |
dece6358 | 14846 | + |
4a4d8108 | 14847 | +/* ---------------------------------------------------------------------- */ |
dece6358 | 14848 | + |
4a4d8108 AM |
14849 | +void au_hn_ctl(struct au_hinode *hinode, int do_set) |
14850 | +{ | |
14851 | + if (hinode->hi_notify) | |
14852 | + au_hnotify_op.ctl(hinode, do_set); | |
14853 | +} | |
14854 | + | |
14855 | +void au_hn_reset(struct inode *inode, unsigned int flags) | |
14856 | +{ | |
14857 | + aufs_bindex_t bindex, bend; | |
14858 | + struct inode *hi; | |
14859 | + struct dentry *iwhdentry; | |
1facf9fc | 14860 | + |
1308ab2a | 14861 | + bend = au_ibend(inode); |
4a4d8108 AM |
14862 | + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) { |
14863 | + hi = au_h_iptr(inode, bindex); | |
14864 | + if (!hi) | |
14865 | + continue; | |
1308ab2a | 14866 | + |
4a4d8108 AM |
14867 | + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */ |
14868 | + iwhdentry = au_hi_wh(inode, bindex); | |
14869 | + if (iwhdentry) | |
14870 | + dget(iwhdentry); | |
14871 | + au_igrab(hi); | |
14872 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
14873 | + au_set_h_iptr(inode, bindex, au_igrab(hi), | |
14874 | + flags & ~AuHi_XINO); | |
14875 | + iput(hi); | |
14876 | + dput(iwhdentry); | |
14877 | + /* mutex_unlock(&hi->i_mutex); */ | |
1facf9fc | 14878 | + } |
1facf9fc | 14879 | +} |
14880 | + | |
1308ab2a | 14881 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 14882 | + |
4a4d8108 | 14883 | +static int hn_xino(struct inode *inode, struct inode *h_inode) |
1facf9fc | 14884 | +{ |
4a4d8108 AM |
14885 | + int err; |
14886 | + aufs_bindex_t bindex, bend, bfound, bstart; | |
14887 | + struct inode *h_i; | |
1facf9fc | 14888 | + |
4a4d8108 AM |
14889 | + err = 0; |
14890 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 14891 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
14892 | + goto out; |
14893 | + } | |
1facf9fc | 14894 | + |
4a4d8108 AM |
14895 | + bfound = -1; |
14896 | + bend = au_ibend(inode); | |
14897 | + bstart = au_ibstart(inode); | |
14898 | +#if 0 /* reserved for future use */ | |
14899 | + if (bindex == bend) { | |
14900 | + /* keep this ino in rename case */ | |
14901 | + goto out; | |
14902 | + } | |
14903 | +#endif | |
14904 | + for (bindex = bstart; bindex <= bend; bindex++) | |
14905 | + if (au_h_iptr(inode, bindex) == h_inode) { | |
14906 | + bfound = bindex; | |
14907 | + break; | |
14908 | + } | |
14909 | + if (bfound < 0) | |
1308ab2a | 14910 | + goto out; |
1facf9fc | 14911 | + |
4a4d8108 AM |
14912 | + for (bindex = bstart; bindex <= bend; bindex++) { |
14913 | + h_i = au_h_iptr(inode, bindex); | |
14914 | + if (!h_i) | |
14915 | + continue; | |
1facf9fc | 14916 | + |
4a4d8108 AM |
14917 | + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0); |
14918 | + /* ignore this error */ | |
14919 | + /* bad action? */ | |
1facf9fc | 14920 | + } |
1facf9fc | 14921 | + |
4a4d8108 | 14922 | + /* children inode number will be broken */ |
1facf9fc | 14923 | + |
4f0767ce | 14924 | +out: |
4a4d8108 AM |
14925 | + AuTraceErr(err); |
14926 | + return err; | |
1facf9fc | 14927 | +} |
14928 | + | |
4a4d8108 | 14929 | +static int hn_gen_tree(struct dentry *dentry) |
1facf9fc | 14930 | +{ |
4a4d8108 AM |
14931 | + int err, i, j, ndentry; |
14932 | + struct au_dcsub_pages dpages; | |
14933 | + struct au_dpage *dpage; | |
14934 | + struct dentry **dentries; | |
1facf9fc | 14935 | + |
4a4d8108 AM |
14936 | + err = au_dpages_init(&dpages, GFP_NOFS); |
14937 | + if (unlikely(err)) | |
14938 | + goto out; | |
14939 | + err = au_dcsub_pages(&dpages, dentry, NULL, NULL); | |
14940 | + if (unlikely(err)) | |
14941 | + goto out_dpages; | |
1facf9fc | 14942 | + |
4a4d8108 AM |
14943 | + for (i = 0; i < dpages.ndpage; i++) { |
14944 | + dpage = dpages.dpages + i; | |
14945 | + dentries = dpage->dentries; | |
14946 | + ndentry = dpage->ndentry; | |
14947 | + for (j = 0; j < ndentry; j++) { | |
14948 | + struct dentry *d; | |
14949 | + | |
14950 | + d = dentries[j]; | |
14951 | + if (IS_ROOT(d)) | |
14952 | + continue; | |
14953 | + | |
4a4d8108 | 14954 | + au_digen_dec(d); |
5527c038 | 14955 | + if (d_really_is_positive(d)) |
4a4d8108 AM |
14956 | + /* todo: reset children xino? |
14957 | + cached children only? */ | |
5527c038 | 14958 | + au_iigen_dec(d_inode(d)); |
1308ab2a | 14959 | + } |
dece6358 | 14960 | + } |
1facf9fc | 14961 | + |
4f0767ce | 14962 | +out_dpages: |
4a4d8108 | 14963 | + au_dpages_free(&dpages); |
dece6358 | 14964 | + |
027c5e7a | 14965 | +#if 0 |
4a4d8108 AM |
14966 | + /* discard children */ |
14967 | + dentry_unhash(dentry); | |
14968 | + dput(dentry); | |
027c5e7a | 14969 | +#endif |
4f0767ce | 14970 | +out: |
dece6358 AM |
14971 | + return err; |
14972 | +} | |
14973 | + | |
1308ab2a | 14974 | +/* |
4a4d8108 | 14975 | + * return 0 if processed. |
1308ab2a | 14976 | + */ |
4a4d8108 AM |
14977 | +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode, |
14978 | + const unsigned int isdir) | |
dece6358 | 14979 | +{ |
1308ab2a | 14980 | + int err; |
4a4d8108 AM |
14981 | + struct dentry *d; |
14982 | + struct qstr *dname; | |
1facf9fc | 14983 | + |
4a4d8108 AM |
14984 | + err = 1; |
14985 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 14986 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
14987 | + err = 0; |
14988 | + goto out; | |
14989 | + } | |
dece6358 | 14990 | + |
4a4d8108 AM |
14991 | + if (!isdir) { |
14992 | + AuDebugOn(!name); | |
14993 | + au_iigen_dec(inode); | |
027c5e7a | 14994 | + spin_lock(&inode->i_lock); |
c1595e42 | 14995 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 14996 | + spin_lock(&d->d_lock); |
4a4d8108 AM |
14997 | + dname = &d->d_name; |
14998 | + if (dname->len != nlen | |
027c5e7a AM |
14999 | + && memcmp(dname->name, name, nlen)) { |
15000 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 15001 | + continue; |
027c5e7a | 15002 | + } |
4a4d8108 | 15003 | + err = 0; |
4a4d8108 AM |
15004 | + au_digen_dec(d); |
15005 | + spin_unlock(&d->d_lock); | |
15006 | + break; | |
1facf9fc | 15007 | + } |
027c5e7a | 15008 | + spin_unlock(&inode->i_lock); |
1308ab2a | 15009 | + } else { |
027c5e7a | 15010 | + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR); |
c1595e42 | 15011 | + d = d_find_any_alias(inode); |
4a4d8108 AM |
15012 | + if (!d) { |
15013 | + au_iigen_dec(inode); | |
15014 | + goto out; | |
15015 | + } | |
1facf9fc | 15016 | + |
027c5e7a | 15017 | + spin_lock(&d->d_lock); |
4a4d8108 | 15018 | + dname = &d->d_name; |
027c5e7a AM |
15019 | + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) { |
15020 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 15021 | + err = hn_gen_tree(d); |
027c5e7a AM |
15022 | + spin_lock(&d->d_lock); |
15023 | + } | |
15024 | + spin_unlock(&d->d_lock); | |
4a4d8108 AM |
15025 | + dput(d); |
15026 | + } | |
1facf9fc | 15027 | + |
4f0767ce | 15028 | +out: |
4a4d8108 | 15029 | + AuTraceErr(err); |
1308ab2a | 15030 | + return err; |
15031 | +} | |
dece6358 | 15032 | + |
4a4d8108 | 15033 | +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir) |
1facf9fc | 15034 | +{ |
4a4d8108 | 15035 | + int err; |
1facf9fc | 15036 | + |
5527c038 | 15037 | + if (IS_ROOT(dentry)) { |
0c3ec466 | 15038 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
15039 | + return 0; |
15040 | + } | |
1308ab2a | 15041 | + |
4a4d8108 AM |
15042 | + err = 0; |
15043 | + if (!isdir) { | |
4a4d8108 | 15044 | + au_digen_dec(dentry); |
5527c038 JR |
15045 | + if (d_really_is_positive(dentry)) |
15046 | + au_iigen_dec(d_inode(dentry)); | |
4a4d8108 | 15047 | + } else { |
027c5e7a | 15048 | + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR); |
5527c038 | 15049 | + if (d_really_is_positive(dentry)) |
4a4d8108 AM |
15050 | + err = hn_gen_tree(dentry); |
15051 | + } | |
15052 | + | |
15053 | + AuTraceErr(err); | |
15054 | + return err; | |
1facf9fc | 15055 | +} |
15056 | + | |
4a4d8108 | 15057 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15058 | + |
4a4d8108 AM |
15059 | +/* hnotify job flags */ |
15060 | +#define AuHnJob_XINO0 1 | |
15061 | +#define AuHnJob_GEN (1 << 1) | |
15062 | +#define AuHnJob_DIRENT (1 << 2) | |
15063 | +#define AuHnJob_ISDIR (1 << 3) | |
15064 | +#define AuHnJob_TRYXINO0 (1 << 4) | |
15065 | +#define AuHnJob_MNTPNT (1 << 5) | |
15066 | +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name) | |
7f207e10 AM |
15067 | +#define au_fset_hnjob(flags, name) \ |
15068 | + do { (flags) |= AuHnJob_##name; } while (0) | |
15069 | +#define au_fclr_hnjob(flags, name) \ | |
15070 | + do { (flags) &= ~AuHnJob_##name; } while (0) | |
1facf9fc | 15071 | + |
4a4d8108 AM |
15072 | +enum { |
15073 | + AuHn_CHILD, | |
15074 | + AuHn_PARENT, | |
15075 | + AuHnLast | |
15076 | +}; | |
1facf9fc | 15077 | + |
4a4d8108 AM |
15078 | +struct au_hnotify_args { |
15079 | + struct inode *h_dir, *dir, *h_child_inode; | |
15080 | + u32 mask; | |
15081 | + unsigned int flags[AuHnLast]; | |
15082 | + unsigned int h_child_nlen; | |
15083 | + char h_child_name[]; | |
15084 | +}; | |
1facf9fc | 15085 | + |
4a4d8108 AM |
15086 | +struct hn_job_args { |
15087 | + unsigned int flags; | |
15088 | + struct inode *inode, *h_inode, *dir, *h_dir; | |
15089 | + struct dentry *dentry; | |
15090 | + char *h_name; | |
15091 | + int h_nlen; | |
15092 | +}; | |
1308ab2a | 15093 | + |
4a4d8108 AM |
15094 | +static int hn_job(struct hn_job_args *a) |
15095 | +{ | |
15096 | + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR); | |
076b876e | 15097 | + int e; |
1308ab2a | 15098 | + |
4a4d8108 AM |
15099 | + /* reset xino */ |
15100 | + if (au_ftest_hnjob(a->flags, XINO0) && a->inode) | |
15101 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ | |
1308ab2a | 15102 | + |
4a4d8108 AM |
15103 | + if (au_ftest_hnjob(a->flags, TRYXINO0) |
15104 | + && a->inode | |
15105 | + && a->h_inode) { | |
15106 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
38d290e6 JR |
15107 | + if (!a->h_inode->i_nlink |
15108 | + && !(a->h_inode->i_state & I_LINKABLE)) | |
4a4d8108 AM |
15109 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ |
15110 | + mutex_unlock(&a->h_inode->i_mutex); | |
1308ab2a | 15111 | + } |
1facf9fc | 15112 | + |
4a4d8108 AM |
15113 | + /* make the generation obsolete */ |
15114 | + if (au_ftest_hnjob(a->flags, GEN)) { | |
076b876e | 15115 | + e = -1; |
4a4d8108 | 15116 | + if (a->inode) |
076b876e | 15117 | + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode, |
4a4d8108 | 15118 | + isdir); |
076b876e | 15119 | + if (e && a->dentry) |
4a4d8108 AM |
15120 | + hn_gen_by_name(a->dentry, isdir); |
15121 | + /* ignore this error */ | |
1facf9fc | 15122 | + } |
1facf9fc | 15123 | + |
4a4d8108 AM |
15124 | + /* make dir entries obsolete */ |
15125 | + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) { | |
15126 | + struct au_vdir *vdir; | |
1facf9fc | 15127 | + |
4a4d8108 AM |
15128 | + vdir = au_ivdir(a->inode); |
15129 | + if (vdir) | |
15130 | + vdir->vd_jiffy = 0; | |
15131 | + /* IMustLock(a->inode); */ | |
15132 | + /* a->inode->i_version++; */ | |
15133 | + } | |
1facf9fc | 15134 | + |
4a4d8108 AM |
15135 | + /* can do nothing but warn */ |
15136 | + if (au_ftest_hnjob(a->flags, MNTPNT) | |
15137 | + && a->dentry | |
15138 | + && d_mountpoint(a->dentry)) | |
523b37e3 | 15139 | + pr_warn("mount-point %pd is removed or renamed\n", a->dentry); |
1facf9fc | 15140 | + |
4a4d8108 | 15141 | + return 0; |
1308ab2a | 15142 | +} |
1facf9fc | 15143 | + |
1308ab2a | 15144 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15145 | + |
4a4d8108 AM |
15146 | +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen, |
15147 | + struct inode *dir) | |
1308ab2a | 15148 | +{ |
4a4d8108 AM |
15149 | + struct dentry *dentry, *d, *parent; |
15150 | + struct qstr *dname; | |
1308ab2a | 15151 | + |
c1595e42 | 15152 | + parent = d_find_any_alias(dir); |
4a4d8108 AM |
15153 | + if (!parent) |
15154 | + return NULL; | |
1308ab2a | 15155 | + |
4a4d8108 | 15156 | + dentry = NULL; |
027c5e7a | 15157 | + spin_lock(&parent->d_lock); |
c1595e42 | 15158 | + list_for_each_entry(d, &parent->d_subdirs, d_child) { |
523b37e3 | 15159 | + /* AuDbg("%pd\n", d); */ |
027c5e7a | 15160 | + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED); |
4a4d8108 AM |
15161 | + dname = &d->d_name; |
15162 | + if (dname->len != nlen || memcmp(dname->name, name, nlen)) | |
027c5e7a AM |
15163 | + goto cont_unlock; |
15164 | + if (au_di(d)) | |
15165 | + au_digen_dec(d); | |
15166 | + else | |
15167 | + goto cont_unlock; | |
c1595e42 | 15168 | + if (au_dcount(d) > 0) { |
027c5e7a | 15169 | + dentry = dget_dlock(d); |
4a4d8108 | 15170 | + spin_unlock(&d->d_lock); |
027c5e7a | 15171 | + break; |
dece6358 | 15172 | + } |
1facf9fc | 15173 | + |
f6b6e03d | 15174 | +cont_unlock: |
027c5e7a | 15175 | + spin_unlock(&d->d_lock); |
1308ab2a | 15176 | + } |
027c5e7a | 15177 | + spin_unlock(&parent->d_lock); |
4a4d8108 | 15178 | + dput(parent); |
1facf9fc | 15179 | + |
4a4d8108 AM |
15180 | + if (dentry) |
15181 | + di_write_lock_child(dentry); | |
1308ab2a | 15182 | + |
4a4d8108 AM |
15183 | + return dentry; |
15184 | +} | |
dece6358 | 15185 | + |
4a4d8108 AM |
15186 | +static struct inode *lookup_wlock_by_ino(struct super_block *sb, |
15187 | + aufs_bindex_t bindex, ino_t h_ino) | |
15188 | +{ | |
15189 | + struct inode *inode; | |
15190 | + ino_t ino; | |
15191 | + int err; | |
15192 | + | |
15193 | + inode = NULL; | |
15194 | + err = au_xino_read(sb, bindex, h_ino, &ino); | |
15195 | + if (!err && ino) | |
15196 | + inode = ilookup(sb, ino); | |
15197 | + if (!inode) | |
15198 | + goto out; | |
15199 | + | |
15200 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 15201 | + pr_warn("wrong root branch\n"); |
4a4d8108 AM |
15202 | + iput(inode); |
15203 | + inode = NULL; | |
15204 | + goto out; | |
1308ab2a | 15205 | + } |
15206 | + | |
4a4d8108 | 15207 | + ii_write_lock_child(inode); |
1308ab2a | 15208 | + |
4f0767ce | 15209 | +out: |
4a4d8108 | 15210 | + return inode; |
dece6358 AM |
15211 | +} |
15212 | + | |
4a4d8108 | 15213 | +static void au_hn_bh(void *_args) |
1facf9fc | 15214 | +{ |
4a4d8108 AM |
15215 | + struct au_hnotify_args *a = _args; |
15216 | + struct super_block *sb; | |
15217 | + aufs_bindex_t bindex, bend, bfound; | |
15218 | + unsigned char xino, try_iput; | |
1facf9fc | 15219 | + int err; |
1308ab2a | 15220 | + struct inode *inode; |
4a4d8108 AM |
15221 | + ino_t h_ino; |
15222 | + struct hn_job_args args; | |
15223 | + struct dentry *dentry; | |
15224 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 15225 | + |
4a4d8108 AM |
15226 | + AuDebugOn(!_args); |
15227 | + AuDebugOn(!a->h_dir); | |
15228 | + AuDebugOn(!a->dir); | |
15229 | + AuDebugOn(!a->mask); | |
15230 | + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n", | |
15231 | + a->mask, a->dir->i_ino, a->h_dir->i_ino, | |
15232 | + a->h_child_inode ? a->h_child_inode->i_ino : 0); | |
1facf9fc | 15233 | + |
4a4d8108 AM |
15234 | + inode = NULL; |
15235 | + dentry = NULL; | |
15236 | + /* | |
15237 | + * do not lock a->dir->i_mutex here | |
15238 | + * because of d_revalidate() may cause a deadlock. | |
15239 | + */ | |
15240 | + sb = a->dir->i_sb; | |
15241 | + AuDebugOn(!sb); | |
15242 | + sbinfo = au_sbi(sb); | |
15243 | + AuDebugOn(!sbinfo); | |
7f207e10 | 15244 | + si_write_lock(sb, AuLock_NOPLMW); |
1facf9fc | 15245 | + |
4a4d8108 AM |
15246 | + ii_read_lock_parent(a->dir); |
15247 | + bfound = -1; | |
15248 | + bend = au_ibend(a->dir); | |
15249 | + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++) | |
15250 | + if (au_h_iptr(a->dir, bindex) == a->h_dir) { | |
15251 | + bfound = bindex; | |
15252 | + break; | |
15253 | + } | |
15254 | + ii_read_unlock(a->dir); | |
15255 | + if (unlikely(bfound < 0)) | |
15256 | + goto out; | |
1facf9fc | 15257 | + |
4a4d8108 AM |
15258 | + xino = !!au_opt_test(au_mntflags(sb), XINO); |
15259 | + h_ino = 0; | |
15260 | + if (a->h_child_inode) | |
15261 | + h_ino = a->h_child_inode->i_ino; | |
1facf9fc | 15262 | + |
4a4d8108 AM |
15263 | + if (a->h_child_nlen |
15264 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN) | |
15265 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT))) | |
15266 | + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen, | |
15267 | + a->dir); | |
15268 | + try_iput = 0; | |
5527c038 JR |
15269 | + if (dentry && d_really_is_positive(dentry)) |
15270 | + inode = d_inode(dentry); | |
4a4d8108 AM |
15271 | + if (xino && !inode && h_ino |
15272 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0) | |
15273 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0) | |
15274 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) { | |
15275 | + inode = lookup_wlock_by_ino(sb, bfound, h_ino); | |
15276 | + try_iput = 1; | |
15277 | + } | |
1facf9fc | 15278 | + |
4a4d8108 AM |
15279 | + args.flags = a->flags[AuHn_CHILD]; |
15280 | + args.dentry = dentry; | |
15281 | + args.inode = inode; | |
15282 | + args.h_inode = a->h_child_inode; | |
15283 | + args.dir = a->dir; | |
15284 | + args.h_dir = a->h_dir; | |
15285 | + args.h_name = a->h_child_name; | |
15286 | + args.h_nlen = a->h_child_nlen; | |
15287 | + err = hn_job(&args); | |
15288 | + if (dentry) { | |
027c5e7a | 15289 | + if (au_di(dentry)) |
4a4d8108 AM |
15290 | + di_write_unlock(dentry); |
15291 | + dput(dentry); | |
15292 | + } | |
15293 | + if (inode && try_iput) { | |
15294 | + ii_write_unlock(inode); | |
15295 | + iput(inode); | |
15296 | + } | |
1facf9fc | 15297 | + |
4a4d8108 AM |
15298 | + ii_write_lock_parent(a->dir); |
15299 | + args.flags = a->flags[AuHn_PARENT]; | |
15300 | + args.dentry = NULL; | |
15301 | + args.inode = a->dir; | |
15302 | + args.h_inode = a->h_dir; | |
15303 | + args.dir = NULL; | |
15304 | + args.h_dir = NULL; | |
15305 | + args.h_name = NULL; | |
15306 | + args.h_nlen = 0; | |
15307 | + err = hn_job(&args); | |
15308 | + ii_write_unlock(a->dir); | |
1facf9fc | 15309 | + |
4f0767ce | 15310 | +out: |
4a4d8108 AM |
15311 | + iput(a->h_child_inode); |
15312 | + iput(a->h_dir); | |
15313 | + iput(a->dir); | |
027c5e7a AM |
15314 | + si_write_unlock(sb); |
15315 | + au_nwt_done(&sbinfo->si_nowait); | |
1308ab2a | 15316 | + kfree(a); |
dece6358 | 15317 | +} |
1facf9fc | 15318 | + |
4a4d8108 AM |
15319 | +/* ---------------------------------------------------------------------- */ |
15320 | + | |
15321 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
15322 | + struct qstr *h_child_qstr, struct inode *h_child_inode) | |
dece6358 | 15323 | +{ |
4a4d8108 | 15324 | + int err, len; |
53392da6 | 15325 | + unsigned int flags[AuHnLast], f; |
4a4d8108 AM |
15326 | + unsigned char isdir, isroot, wh; |
15327 | + struct inode *dir; | |
15328 | + struct au_hnotify_args *args; | |
15329 | + char *p, *h_child_name; | |
dece6358 | 15330 | + |
1308ab2a | 15331 | + err = 0; |
4a4d8108 AM |
15332 | + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode); |
15333 | + dir = igrab(hnotify->hn_aufs_inode); | |
15334 | + if (!dir) | |
15335 | + goto out; | |
1facf9fc | 15336 | + |
4a4d8108 AM |
15337 | + isroot = (dir->i_ino == AUFS_ROOT_INO); |
15338 | + wh = 0; | |
15339 | + h_child_name = (void *)h_child_qstr->name; | |
15340 | + len = h_child_qstr->len; | |
15341 | + if (h_child_name) { | |
15342 | + if (len > AUFS_WH_PFX_LEN | |
15343 | + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
15344 | + h_child_name += AUFS_WH_PFX_LEN; | |
15345 | + len -= AUFS_WH_PFX_LEN; | |
15346 | + wh = 1; | |
15347 | + } | |
1facf9fc | 15348 | + } |
dece6358 | 15349 | + |
4a4d8108 AM |
15350 | + isdir = 0; |
15351 | + if (h_child_inode) | |
15352 | + isdir = !!S_ISDIR(h_child_inode->i_mode); | |
15353 | + flags[AuHn_PARENT] = AuHnJob_ISDIR; | |
15354 | + flags[AuHn_CHILD] = 0; | |
15355 | + if (isdir) | |
15356 | + flags[AuHn_CHILD] = AuHnJob_ISDIR; | |
15357 | + au_fset_hnjob(flags[AuHn_PARENT], DIRENT); | |
15358 | + au_fset_hnjob(flags[AuHn_CHILD], GEN); | |
15359 | + switch (mask & FS_EVENTS_POSS_ON_CHILD) { | |
15360 | + case FS_MOVED_FROM: | |
15361 | + case FS_MOVED_TO: | |
15362 | + au_fset_hnjob(flags[AuHn_CHILD], XINO0); | |
15363 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
15364 | + /*FALLTHROUGH*/ | |
15365 | + case FS_CREATE: | |
fb47a38f | 15366 | + AuDebugOn(!h_child_name); |
4a4d8108 | 15367 | + break; |
1facf9fc | 15368 | + |
4a4d8108 AM |
15369 | + case FS_DELETE: |
15370 | + /* | |
15371 | + * aufs never be able to get this child inode. | |
15372 | + * revalidation should be in d_revalidate() | |
15373 | + * by checking i_nlink, i_generation or d_unhashed(). | |
15374 | + */ | |
15375 | + AuDebugOn(!h_child_name); | |
15376 | + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0); | |
15377 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
15378 | + break; | |
dece6358 | 15379 | + |
4a4d8108 AM |
15380 | + default: |
15381 | + AuDebugOn(1); | |
15382 | + } | |
1308ab2a | 15383 | + |
4a4d8108 AM |
15384 | + if (wh) |
15385 | + h_child_inode = NULL; | |
1308ab2a | 15386 | + |
4a4d8108 AM |
15387 | + err = -ENOMEM; |
15388 | + /* iput() and kfree() will be called in au_hnotify() */ | |
4a4d8108 | 15389 | + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS); |
4a4d8108 AM |
15390 | + if (unlikely(!args)) { |
15391 | + AuErr1("no memory\n"); | |
15392 | + iput(dir); | |
15393 | + goto out; | |
15394 | + } | |
15395 | + args->flags[AuHn_PARENT] = flags[AuHn_PARENT]; | |
15396 | + args->flags[AuHn_CHILD] = flags[AuHn_CHILD]; | |
15397 | + args->mask = mask; | |
15398 | + args->dir = dir; | |
15399 | + args->h_dir = igrab(h_dir); | |
15400 | + if (h_child_inode) | |
15401 | + h_child_inode = igrab(h_child_inode); /* can be NULL */ | |
15402 | + args->h_child_inode = h_child_inode; | |
15403 | + args->h_child_nlen = len; | |
15404 | + if (len) { | |
15405 | + p = (void *)args; | |
15406 | + p += sizeof(*args); | |
15407 | + memcpy(p, h_child_name, len); | |
15408 | + p[len] = 0; | |
1308ab2a | 15409 | + } |
1308ab2a | 15410 | + |
38d290e6 | 15411 | + /* NFS fires the event for silly-renamed one from kworker */ |
53392da6 | 15412 | + f = 0; |
38d290e6 JR |
15413 | + if (!dir->i_nlink |
15414 | + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE))) | |
53392da6 AM |
15415 | + f = AuWkq_NEST; |
15416 | + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f); | |
4a4d8108 AM |
15417 | + if (unlikely(err)) { |
15418 | + pr_err("wkq %d\n", err); | |
15419 | + iput(args->h_child_inode); | |
15420 | + iput(args->h_dir); | |
15421 | + iput(args->dir); | |
15422 | + kfree(args); | |
1facf9fc | 15423 | + } |
1facf9fc | 15424 | + |
4a4d8108 | 15425 | +out: |
1facf9fc | 15426 | + return err; |
15427 | +} | |
15428 | + | |
027c5e7a AM |
15429 | +/* ---------------------------------------------------------------------- */ |
15430 | + | |
15431 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
15432 | +{ | |
15433 | + int err; | |
15434 | + | |
15435 | + AuDebugOn(!(udba & AuOptMask_UDBA)); | |
15436 | + | |
15437 | + err = 0; | |
15438 | + if (au_hnotify_op.reset_br) | |
15439 | + err = au_hnotify_op.reset_br(udba, br, perm); | |
15440 | + | |
15441 | + return err; | |
15442 | +} | |
15443 | + | |
15444 | +int au_hnotify_init_br(struct au_branch *br, int perm) | |
15445 | +{ | |
15446 | + int err; | |
15447 | + | |
15448 | + err = 0; | |
15449 | + if (au_hnotify_op.init_br) | |
15450 | + err = au_hnotify_op.init_br(br, perm); | |
15451 | + | |
15452 | + return err; | |
15453 | +} | |
15454 | + | |
15455 | +void au_hnotify_fin_br(struct au_branch *br) | |
15456 | +{ | |
15457 | + if (au_hnotify_op.fin_br) | |
15458 | + au_hnotify_op.fin_br(br); | |
15459 | +} | |
15460 | + | |
4a4d8108 AM |
15461 | +static void au_hn_destroy_cache(void) |
15462 | +{ | |
15463 | + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]); | |
15464 | + au_cachep[AuCache_HNOTIFY] = NULL; | |
15465 | +} | |
1308ab2a | 15466 | + |
4a4d8108 | 15467 | +int __init au_hnotify_init(void) |
1facf9fc | 15468 | +{ |
1308ab2a | 15469 | + int err; |
1308ab2a | 15470 | + |
4a4d8108 AM |
15471 | + err = -ENOMEM; |
15472 | + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify); | |
15473 | + if (au_cachep[AuCache_HNOTIFY]) { | |
027c5e7a AM |
15474 | + err = 0; |
15475 | + if (au_hnotify_op.init) | |
15476 | + err = au_hnotify_op.init(); | |
4a4d8108 AM |
15477 | + if (unlikely(err)) |
15478 | + au_hn_destroy_cache(); | |
1308ab2a | 15479 | + } |
1308ab2a | 15480 | + AuTraceErr(err); |
4a4d8108 | 15481 | + return err; |
1308ab2a | 15482 | +} |
15483 | + | |
4a4d8108 | 15484 | +void au_hnotify_fin(void) |
1308ab2a | 15485 | +{ |
027c5e7a AM |
15486 | + if (au_hnotify_op.fin) |
15487 | + au_hnotify_op.fin(); | |
4a4d8108 AM |
15488 | + /* cf. au_cache_fin() */ |
15489 | + if (au_cachep[AuCache_HNOTIFY]) | |
15490 | + au_hn_destroy_cache(); | |
dece6358 | 15491 | +} |
7f207e10 AM |
15492 | diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c |
15493 | --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 15494 | +++ linux/fs/aufs/iinfo.c 2015-06-28 17:35:44.348050491 +0200 |
38d290e6 | 15495 | @@ -0,0 +1,277 @@ |
dece6358 | 15496 | +/* |
2000de60 | 15497 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
dece6358 AM |
15498 | + * |
15499 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15500 | + * it under the terms of the GNU General Public License as published by | |
15501 | + * the Free Software Foundation; either version 2 of the License, or | |
15502 | + * (at your option) any later version. | |
15503 | + * | |
15504 | + * This program is distributed in the hope that it will be useful, | |
15505 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15506 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15507 | + * GNU General Public License for more details. | |
15508 | + * | |
15509 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15510 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 15511 | + */ |
1facf9fc | 15512 | + |
dece6358 | 15513 | +/* |
4a4d8108 | 15514 | + * inode private data |
dece6358 | 15515 | + */ |
1facf9fc | 15516 | + |
1308ab2a | 15517 | +#include "aufs.h" |
1facf9fc | 15518 | + |
4a4d8108 | 15519 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 15520 | +{ |
4a4d8108 | 15521 | + struct inode *h_inode; |
1facf9fc | 15522 | + |
4a4d8108 | 15523 | + IiMustAnyLock(inode); |
1facf9fc | 15524 | + |
4a4d8108 AM |
15525 | + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode; |
15526 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); | |
15527 | + return h_inode; | |
15528 | +} | |
1facf9fc | 15529 | + |
4a4d8108 AM |
15530 | +/* todo: hard/soft set? */ |
15531 | +void au_hiput(struct au_hinode *hinode) | |
15532 | +{ | |
15533 | + au_hn_free(hinode); | |
15534 | + dput(hinode->hi_whdentry); | |
15535 | + iput(hinode->hi_inode); | |
15536 | +} | |
1facf9fc | 15537 | + |
4a4d8108 AM |
15538 | +unsigned int au_hi_flags(struct inode *inode, int isdir) |
15539 | +{ | |
15540 | + unsigned int flags; | |
15541 | + const unsigned int mnt_flags = au_mntflags(inode->i_sb); | |
1facf9fc | 15542 | + |
4a4d8108 AM |
15543 | + flags = 0; |
15544 | + if (au_opt_test(mnt_flags, XINO)) | |
15545 | + au_fset_hi(flags, XINO); | |
15546 | + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY)) | |
15547 | + au_fset_hi(flags, HNOTIFY); | |
15548 | + return flags; | |
1facf9fc | 15549 | +} |
15550 | + | |
4a4d8108 AM |
15551 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
15552 | + struct inode *h_inode, unsigned int flags) | |
1308ab2a | 15553 | +{ |
4a4d8108 AM |
15554 | + struct au_hinode *hinode; |
15555 | + struct inode *hi; | |
15556 | + struct au_iinfo *iinfo = au_ii(inode); | |
1facf9fc | 15557 | + |
4a4d8108 | 15558 | + IiMustWriteLock(inode); |
dece6358 | 15559 | + |
4a4d8108 AM |
15560 | + hinode = iinfo->ii_hinode + bindex; |
15561 | + hi = hinode->hi_inode; | |
15562 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); | |
15563 | + | |
15564 | + if (hi) | |
15565 | + au_hiput(hinode); | |
15566 | + hinode->hi_inode = h_inode; | |
15567 | + if (h_inode) { | |
15568 | + int err; | |
15569 | + struct super_block *sb = inode->i_sb; | |
15570 | + struct au_branch *br; | |
15571 | + | |
027c5e7a AM |
15572 | + AuDebugOn(inode->i_mode |
15573 | + && (h_inode->i_mode & S_IFMT) | |
15574 | + != (inode->i_mode & S_IFMT)); | |
4a4d8108 AM |
15575 | + if (bindex == iinfo->ii_bstart) |
15576 | + au_cpup_igen(inode, h_inode); | |
15577 | + br = au_sbr(sb, bindex); | |
15578 | + hinode->hi_id = br->br_id; | |
15579 | + if (au_ftest_hi(flags, XINO)) { | |
15580 | + err = au_xino_write(sb, bindex, h_inode->i_ino, | |
15581 | + inode->i_ino); | |
15582 | + if (unlikely(err)) | |
15583 | + AuIOErr1("failed au_xino_write() %d\n", err); | |
15584 | + } | |
15585 | + | |
15586 | + if (au_ftest_hi(flags, HNOTIFY) | |
15587 | + && au_br_hnotifyable(br->br_perm)) { | |
027c5e7a | 15588 | + err = au_hn_alloc(hinode, inode); |
4a4d8108 AM |
15589 | + if (unlikely(err)) |
15590 | + AuIOErr1("au_hn_alloc() %d\n", err); | |
1308ab2a | 15591 | + } |
15592 | + } | |
4a4d8108 | 15593 | +} |
dece6358 | 15594 | + |
4a4d8108 AM |
15595 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, |
15596 | + struct dentry *h_wh) | |
15597 | +{ | |
15598 | + struct au_hinode *hinode; | |
dece6358 | 15599 | + |
4a4d8108 AM |
15600 | + IiMustWriteLock(inode); |
15601 | + | |
15602 | + hinode = au_ii(inode)->ii_hinode + bindex; | |
15603 | + AuDebugOn(hinode->hi_whdentry); | |
15604 | + hinode->hi_whdentry = h_wh; | |
1facf9fc | 15605 | +} |
15606 | + | |
537831f9 | 15607 | +void au_update_iigen(struct inode *inode, int half) |
1308ab2a | 15608 | +{ |
537831f9 AM |
15609 | + struct au_iinfo *iinfo; |
15610 | + struct au_iigen *iigen; | |
15611 | + unsigned int sigen; | |
15612 | + | |
15613 | + sigen = au_sigen(inode->i_sb); | |
15614 | + iinfo = au_ii(inode); | |
15615 | + iigen = &iinfo->ii_generation; | |
15616 | + spin_lock(&iinfo->ii_genspin); | |
15617 | + iigen->ig_generation = sigen; | |
15618 | + if (half) | |
15619 | + au_ig_fset(iigen->ig_flags, HALF_REFRESHED); | |
15620 | + else | |
15621 | + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED); | |
15622 | + spin_unlock(&iinfo->ii_genspin); | |
4a4d8108 | 15623 | +} |
1facf9fc | 15624 | + |
4a4d8108 AM |
15625 | +/* it may be called at remount time, too */ |
15626 | +void au_update_ibrange(struct inode *inode, int do_put_zero) | |
15627 | +{ | |
15628 | + struct au_iinfo *iinfo; | |
027c5e7a | 15629 | + aufs_bindex_t bindex, bend; |
1facf9fc | 15630 | + |
4a4d8108 | 15631 | + iinfo = au_ii(inode); |
027c5e7a | 15632 | + if (!iinfo) |
4a4d8108 | 15633 | + return; |
1facf9fc | 15634 | + |
4a4d8108 | 15635 | + IiMustWriteLock(inode); |
1facf9fc | 15636 | + |
027c5e7a | 15637 | + if (do_put_zero && iinfo->ii_bstart >= 0) { |
4a4d8108 AM |
15638 | + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; |
15639 | + bindex++) { | |
15640 | + struct inode *h_i; | |
1facf9fc | 15641 | + |
4a4d8108 | 15642 | + h_i = iinfo->ii_hinode[0 + bindex].hi_inode; |
38d290e6 JR |
15643 | + if (h_i |
15644 | + && !h_i->i_nlink | |
15645 | + && !(h_i->i_state & I_LINKABLE)) | |
027c5e7a AM |
15646 | + au_set_h_iptr(inode, bindex, NULL, 0); |
15647 | + } | |
4a4d8108 AM |
15648 | + } |
15649 | + | |
027c5e7a AM |
15650 | + iinfo->ii_bstart = -1; |
15651 | + iinfo->ii_bend = -1; | |
15652 | + bend = au_sbend(inode->i_sb); | |
15653 | + for (bindex = 0; bindex <= bend; bindex++) | |
15654 | + if (iinfo->ii_hinode[0 + bindex].hi_inode) { | |
15655 | + iinfo->ii_bstart = bindex; | |
4a4d8108 | 15656 | + break; |
027c5e7a AM |
15657 | + } |
15658 | + if (iinfo->ii_bstart >= 0) | |
15659 | + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--) | |
15660 | + if (iinfo->ii_hinode[0 + bindex].hi_inode) { | |
15661 | + iinfo->ii_bend = bindex; | |
15662 | + break; | |
15663 | + } | |
15664 | + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend); | |
1308ab2a | 15665 | +} |
1facf9fc | 15666 | + |
dece6358 | 15667 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15668 | + |
4a4d8108 | 15669 | +void au_icntnr_init_once(void *_c) |
dece6358 | 15670 | +{ |
4a4d8108 AM |
15671 | + struct au_icntnr *c = _c; |
15672 | + struct au_iinfo *iinfo = &c->iinfo; | |
e49829fe | 15673 | + static struct lock_class_key aufs_ii; |
1facf9fc | 15674 | + |
537831f9 | 15675 | + spin_lock_init(&iinfo->ii_genspin); |
4a4d8108 | 15676 | + au_rw_init(&iinfo->ii_rwsem); |
e49829fe | 15677 | + au_rw_class(&iinfo->ii_rwsem, &aufs_ii); |
4a4d8108 AM |
15678 | + inode_init_once(&c->vfs_inode); |
15679 | +} | |
1facf9fc | 15680 | + |
4a4d8108 AM |
15681 | +int au_iinfo_init(struct inode *inode) |
15682 | +{ | |
15683 | + struct au_iinfo *iinfo; | |
15684 | + struct super_block *sb; | |
15685 | + int nbr, i; | |
1facf9fc | 15686 | + |
4a4d8108 AM |
15687 | + sb = inode->i_sb; |
15688 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
15689 | + nbr = au_sbend(sb) + 1; | |
15690 | + if (unlikely(nbr <= 0)) | |
15691 | + nbr = 1; | |
15692 | + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS); | |
15693 | + if (iinfo->ii_hinode) { | |
7f207e10 | 15694 | + au_ninodes_inc(sb); |
4a4d8108 AM |
15695 | + for (i = 0; i < nbr; i++) |
15696 | + iinfo->ii_hinode[i].hi_id = -1; | |
1facf9fc | 15697 | + |
537831f9 | 15698 | + iinfo->ii_generation.ig_generation = au_sigen(sb); |
4a4d8108 AM |
15699 | + iinfo->ii_bstart = -1; |
15700 | + iinfo->ii_bend = -1; | |
15701 | + iinfo->ii_vdir = NULL; | |
15702 | + return 0; | |
1308ab2a | 15703 | + } |
4a4d8108 AM |
15704 | + return -ENOMEM; |
15705 | +} | |
1facf9fc | 15706 | + |
4a4d8108 AM |
15707 | +int au_ii_realloc(struct au_iinfo *iinfo, int nbr) |
15708 | +{ | |
15709 | + int err, sz; | |
15710 | + struct au_hinode *hip; | |
1facf9fc | 15711 | + |
4a4d8108 AM |
15712 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
15713 | + | |
15714 | + err = -ENOMEM; | |
15715 | + sz = sizeof(*hip) * (iinfo->ii_bend + 1); | |
15716 | + if (!sz) | |
15717 | + sz = sizeof(*hip); | |
15718 | + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS); | |
15719 | + if (hip) { | |
15720 | + iinfo->ii_hinode = hip; | |
15721 | + err = 0; | |
1308ab2a | 15722 | + } |
4a4d8108 | 15723 | + |
1308ab2a | 15724 | + return err; |
1facf9fc | 15725 | +} |
15726 | + | |
4a4d8108 | 15727 | +void au_iinfo_fin(struct inode *inode) |
1facf9fc | 15728 | +{ |
4a4d8108 AM |
15729 | + struct au_iinfo *iinfo; |
15730 | + struct au_hinode *hi; | |
15731 | + struct super_block *sb; | |
b752ccd1 AM |
15732 | + aufs_bindex_t bindex, bend; |
15733 | + const unsigned char unlinked = !inode->i_nlink; | |
1308ab2a | 15734 | + |
4a4d8108 AM |
15735 | + iinfo = au_ii(inode); |
15736 | + /* bad_inode case */ | |
15737 | + if (!iinfo) | |
15738 | + return; | |
1308ab2a | 15739 | + |
b752ccd1 | 15740 | + sb = inode->i_sb; |
7f207e10 | 15741 | + au_ninodes_dec(sb); |
b752ccd1 AM |
15742 | + if (si_pid_test(sb)) |
15743 | + au_xino_delete_inode(inode, unlinked); | |
15744 | + else { | |
15745 | + /* | |
15746 | + * it is safe to hide the dependency between sbinfo and | |
15747 | + * sb->s_umount. | |
15748 | + */ | |
15749 | + lockdep_off(); | |
15750 | + si_noflush_read_lock(sb); | |
15751 | + au_xino_delete_inode(inode, unlinked); | |
15752 | + si_read_unlock(sb); | |
15753 | + lockdep_on(); | |
15754 | + } | |
15755 | + | |
4a4d8108 AM |
15756 | + if (iinfo->ii_vdir) |
15757 | + au_vdir_free(iinfo->ii_vdir); | |
1308ab2a | 15758 | + |
b752ccd1 AM |
15759 | + bindex = iinfo->ii_bstart; |
15760 | + if (bindex >= 0) { | |
15761 | + hi = iinfo->ii_hinode + bindex; | |
4a4d8108 | 15762 | + bend = iinfo->ii_bend; |
b752ccd1 AM |
15763 | + while (bindex++ <= bend) { |
15764 | + if (hi->hi_inode) | |
4a4d8108 | 15765 | + au_hiput(hi); |
4a4d8108 AM |
15766 | + hi++; |
15767 | + } | |
15768 | + } | |
4a4d8108 | 15769 | + kfree(iinfo->ii_hinode); |
027c5e7a | 15770 | + iinfo->ii_hinode = NULL; |
4a4d8108 | 15771 | + AuRwDestroy(&iinfo->ii_rwsem); |
dece6358 | 15772 | +} |
7f207e10 AM |
15773 | diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c |
15774 | --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
15775 | +++ linux/fs/aufs/inode.c 2015-06-28 17:36:09.025073697 +0200 |
15776 | @@ -0,0 +1,500 @@ | |
4a4d8108 | 15777 | +/* |
2000de60 | 15778 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
15779 | + * |
15780 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15781 | + * it under the terms of the GNU General Public License as published by | |
15782 | + * the Free Software Foundation; either version 2 of the License, or | |
15783 | + * (at your option) any later version. | |
15784 | + * | |
15785 | + * This program is distributed in the hope that it will be useful, | |
15786 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15787 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15788 | + * GNU General Public License for more details. | |
15789 | + * | |
15790 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15791 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 15792 | + */ |
1facf9fc | 15793 | + |
4a4d8108 AM |
15794 | +/* |
15795 | + * inode functions | |
15796 | + */ | |
1facf9fc | 15797 | + |
4a4d8108 | 15798 | +#include "aufs.h" |
1308ab2a | 15799 | + |
4a4d8108 AM |
15800 | +struct inode *au_igrab(struct inode *inode) |
15801 | +{ | |
15802 | + if (inode) { | |
15803 | + AuDebugOn(!atomic_read(&inode->i_count)); | |
027c5e7a | 15804 | + ihold(inode); |
1facf9fc | 15805 | + } |
4a4d8108 AM |
15806 | + return inode; |
15807 | +} | |
1facf9fc | 15808 | + |
4a4d8108 AM |
15809 | +static void au_refresh_hinode_attr(struct inode *inode, int do_version) |
15810 | +{ | |
15811 | + au_cpup_attr_all(inode, /*force*/0); | |
537831f9 | 15812 | + au_update_iigen(inode, /*half*/1); |
4a4d8108 AM |
15813 | + if (do_version) |
15814 | + inode->i_version++; | |
dece6358 | 15815 | +} |
1facf9fc | 15816 | + |
027c5e7a | 15817 | +static int au_ii_refresh(struct inode *inode, int *update) |
dece6358 | 15818 | +{ |
4a4d8108 | 15819 | + int err, e; |
027c5e7a | 15820 | + umode_t type; |
4a4d8108 | 15821 | + aufs_bindex_t bindex, new_bindex; |
1308ab2a | 15822 | + struct super_block *sb; |
4a4d8108 | 15823 | + struct au_iinfo *iinfo; |
027c5e7a | 15824 | + struct au_hinode *p, *q, tmp; |
1facf9fc | 15825 | + |
4a4d8108 | 15826 | + IiMustWriteLock(inode); |
1facf9fc | 15827 | + |
027c5e7a | 15828 | + *update = 0; |
4a4d8108 | 15829 | + sb = inode->i_sb; |
027c5e7a | 15830 | + type = inode->i_mode & S_IFMT; |
4a4d8108 AM |
15831 | + iinfo = au_ii(inode); |
15832 | + err = au_ii_realloc(iinfo, au_sbend(sb) + 1); | |
15833 | + if (unlikely(err)) | |
1308ab2a | 15834 | + goto out; |
1facf9fc | 15835 | + |
027c5e7a | 15836 | + AuDebugOn(iinfo->ii_bstart < 0); |
4a4d8108 | 15837 | + p = iinfo->ii_hinode + iinfo->ii_bstart; |
4a4d8108 AM |
15838 | + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; |
15839 | + bindex++, p++) { | |
15840 | + if (!p->hi_inode) | |
15841 | + continue; | |
1facf9fc | 15842 | + |
027c5e7a | 15843 | + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT)); |
4a4d8108 AM |
15844 | + new_bindex = au_br_index(sb, p->hi_id); |
15845 | + if (new_bindex == bindex) | |
15846 | + continue; | |
1facf9fc | 15847 | + |
4a4d8108 | 15848 | + if (new_bindex < 0) { |
027c5e7a | 15849 | + *update = 1; |
4a4d8108 AM |
15850 | + au_hiput(p); |
15851 | + p->hi_inode = NULL; | |
15852 | + continue; | |
1308ab2a | 15853 | + } |
4a4d8108 AM |
15854 | + |
15855 | + if (new_bindex < iinfo->ii_bstart) | |
15856 | + iinfo->ii_bstart = new_bindex; | |
15857 | + if (iinfo->ii_bend < new_bindex) | |
15858 | + iinfo->ii_bend = new_bindex; | |
15859 | + /* swap two lower inode, and loop again */ | |
15860 | + q = iinfo->ii_hinode + new_bindex; | |
15861 | + tmp = *q; | |
15862 | + *q = *p; | |
15863 | + *p = tmp; | |
15864 | + if (tmp.hi_inode) { | |
15865 | + bindex--; | |
15866 | + p--; | |
1308ab2a | 15867 | + } |
15868 | + } | |
4a4d8108 AM |
15869 | + au_update_ibrange(inode, /*do_put_zero*/0); |
15870 | + e = au_dy_irefresh(inode); | |
15871 | + if (unlikely(e && !err)) | |
15872 | + err = e; | |
1facf9fc | 15873 | + |
4f0767ce | 15874 | +out: |
027c5e7a AM |
15875 | + AuTraceErr(err); |
15876 | + return err; | |
15877 | +} | |
15878 | + | |
15879 | +int au_refresh_hinode_self(struct inode *inode) | |
15880 | +{ | |
15881 | + int err, update; | |
15882 | + | |
15883 | + err = au_ii_refresh(inode, &update); | |
15884 | + if (!err) | |
15885 | + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode)); | |
15886 | + | |
15887 | + AuTraceErr(err); | |
4a4d8108 AM |
15888 | + return err; |
15889 | +} | |
1facf9fc | 15890 | + |
4a4d8108 AM |
15891 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry) |
15892 | +{ | |
027c5e7a | 15893 | + int err, e, update; |
4a4d8108 | 15894 | + unsigned int flags; |
027c5e7a | 15895 | + umode_t mode; |
4a4d8108 | 15896 | + aufs_bindex_t bindex, bend; |
027c5e7a | 15897 | + unsigned char isdir; |
4a4d8108 AM |
15898 | + struct au_hinode *p; |
15899 | + struct au_iinfo *iinfo; | |
1facf9fc | 15900 | + |
027c5e7a | 15901 | + err = au_ii_refresh(inode, &update); |
4a4d8108 AM |
15902 | + if (unlikely(err)) |
15903 | + goto out; | |
15904 | + | |
15905 | + update = 0; | |
15906 | + iinfo = au_ii(inode); | |
15907 | + p = iinfo->ii_hinode + iinfo->ii_bstart; | |
027c5e7a AM |
15908 | + mode = (inode->i_mode & S_IFMT); |
15909 | + isdir = S_ISDIR(mode); | |
4a4d8108 AM |
15910 | + flags = au_hi_flags(inode, isdir); |
15911 | + bend = au_dbend(dentry); | |
15912 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) { | |
5527c038 | 15913 | + struct inode *h_i, *h_inode; |
4a4d8108 AM |
15914 | + struct dentry *h_d; |
15915 | + | |
15916 | + h_d = au_h_dptr(dentry, bindex); | |
5527c038 | 15917 | + if (!h_d || d_is_negative(h_d)) |
4a4d8108 AM |
15918 | + continue; |
15919 | + | |
5527c038 JR |
15920 | + h_inode = d_inode(h_d); |
15921 | + AuDebugOn(mode != (h_inode->i_mode & S_IFMT)); | |
4a4d8108 AM |
15922 | + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) { |
15923 | + h_i = au_h_iptr(inode, bindex); | |
15924 | + if (h_i) { | |
5527c038 | 15925 | + if (h_i == h_inode) |
4a4d8108 AM |
15926 | + continue; |
15927 | + err = -EIO; | |
15928 | + break; | |
15929 | + } | |
15930 | + } | |
15931 | + if (bindex < iinfo->ii_bstart) | |
15932 | + iinfo->ii_bstart = bindex; | |
15933 | + if (iinfo->ii_bend < bindex) | |
15934 | + iinfo->ii_bend = bindex; | |
5527c038 | 15935 | + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags); |
4a4d8108 | 15936 | + update = 1; |
1308ab2a | 15937 | + } |
4a4d8108 AM |
15938 | + au_update_ibrange(inode, /*do_put_zero*/0); |
15939 | + e = au_dy_irefresh(inode); | |
15940 | + if (unlikely(e && !err)) | |
15941 | + err = e; | |
027c5e7a AM |
15942 | + if (!err) |
15943 | + au_refresh_hinode_attr(inode, update && isdir); | |
4a4d8108 | 15944 | + |
4f0767ce | 15945 | +out: |
4a4d8108 | 15946 | + AuTraceErr(err); |
1308ab2a | 15947 | + return err; |
dece6358 AM |
15948 | +} |
15949 | + | |
4a4d8108 | 15950 | +static int set_inode(struct inode *inode, struct dentry *dentry) |
dece6358 | 15951 | +{ |
4a4d8108 AM |
15952 | + int err; |
15953 | + unsigned int flags; | |
15954 | + umode_t mode; | |
15955 | + aufs_bindex_t bindex, bstart, btail; | |
15956 | + unsigned char isdir; | |
15957 | + struct dentry *h_dentry; | |
15958 | + struct inode *h_inode; | |
15959 | + struct au_iinfo *iinfo; | |
dece6358 | 15960 | + |
4a4d8108 | 15961 | + IiMustWriteLock(inode); |
dece6358 | 15962 | + |
4a4d8108 AM |
15963 | + err = 0; |
15964 | + isdir = 0; | |
15965 | + bstart = au_dbstart(dentry); | |
5527c038 JR |
15966 | + h_dentry = au_h_dptr(dentry, bstart); |
15967 | + h_inode = d_inode(h_dentry); | |
4a4d8108 AM |
15968 | + mode = h_inode->i_mode; |
15969 | + switch (mode & S_IFMT) { | |
15970 | + case S_IFREG: | |
15971 | + btail = au_dbtail(dentry); | |
15972 | + inode->i_op = &aufs_iop; | |
15973 | + inode->i_fop = &aufs_file_fop; | |
15974 | + err = au_dy_iaop(inode, bstart, h_inode); | |
15975 | + if (unlikely(err)) | |
15976 | + goto out; | |
15977 | + break; | |
15978 | + case S_IFDIR: | |
15979 | + isdir = 1; | |
15980 | + btail = au_dbtaildir(dentry); | |
15981 | + inode->i_op = &aufs_dir_iop; | |
15982 | + inode->i_fop = &aufs_dir_fop; | |
15983 | + break; | |
15984 | + case S_IFLNK: | |
15985 | + btail = au_dbtail(dentry); | |
15986 | + inode->i_op = &aufs_symlink_iop; | |
15987 | + break; | |
15988 | + case S_IFBLK: | |
15989 | + case S_IFCHR: | |
15990 | + case S_IFIFO: | |
15991 | + case S_IFSOCK: | |
15992 | + btail = au_dbtail(dentry); | |
15993 | + inode->i_op = &aufs_iop; | |
38d290e6 | 15994 | + init_special_inode(inode, mode, h_inode->i_rdev); |
4a4d8108 AM |
15995 | + break; |
15996 | + default: | |
15997 | + AuIOErr("Unknown file type 0%o\n", mode); | |
15998 | + err = -EIO; | |
1308ab2a | 15999 | + goto out; |
4a4d8108 | 16000 | + } |
dece6358 | 16001 | + |
4a4d8108 AM |
16002 | + /* do not set hnotify for whiteouted dirs (SHWH mode) */ |
16003 | + flags = au_hi_flags(inode, isdir); | |
16004 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH) | |
16005 | + && au_ftest_hi(flags, HNOTIFY) | |
16006 | + && dentry->d_name.len > AUFS_WH_PFX_LEN | |
16007 | + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) | |
16008 | + au_fclr_hi(flags, HNOTIFY); | |
16009 | + iinfo = au_ii(inode); | |
16010 | + iinfo->ii_bstart = bstart; | |
16011 | + iinfo->ii_bend = btail; | |
16012 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
16013 | + h_dentry = au_h_dptr(dentry, bindex); | |
16014 | + if (h_dentry) | |
16015 | + au_set_h_iptr(inode, bindex, | |
5527c038 | 16016 | + au_igrab(d_inode(h_dentry)), flags); |
4a4d8108 AM |
16017 | + } |
16018 | + au_cpup_attr_all(inode, /*force*/1); | |
c1595e42 JR |
16019 | + /* |
16020 | + * to force calling aufs_get_acl() every time, | |
16021 | + * do not call cache_no_acl() for aufs inode. | |
16022 | + */ | |
dece6358 | 16023 | + |
4f0767ce | 16024 | +out: |
4a4d8108 AM |
16025 | + return err; |
16026 | +} | |
dece6358 | 16027 | + |
027c5e7a AM |
16028 | +/* |
16029 | + * successful returns with iinfo write_locked | |
16030 | + * minus: errno | |
16031 | + * zero: success, matched | |
16032 | + * plus: no error, but unmatched | |
16033 | + */ | |
16034 | +static int reval_inode(struct inode *inode, struct dentry *dentry) | |
4a4d8108 AM |
16035 | +{ |
16036 | + int err; | |
537831f9 AM |
16037 | + unsigned int gen; |
16038 | + struct au_iigen iigen; | |
4a4d8108 AM |
16039 | + aufs_bindex_t bindex, bend; |
16040 | + struct inode *h_inode, *h_dinode; | |
5527c038 | 16041 | + struct dentry *h_dentry; |
dece6358 | 16042 | + |
4a4d8108 AM |
16043 | + /* |
16044 | + * before this function, if aufs got any iinfo lock, it must be only | |
16045 | + * one, the parent dir. | |
16046 | + * it can happen by UDBA and the obsoleted inode number. | |
16047 | + */ | |
16048 | + err = -EIO; | |
16049 | + if (unlikely(inode->i_ino == parent_ino(dentry))) | |
16050 | + goto out; | |
16051 | + | |
027c5e7a | 16052 | + err = 1; |
4a4d8108 | 16053 | + ii_write_lock_new_child(inode); |
5527c038 JR |
16054 | + h_dentry = au_h_dptr(dentry, au_dbstart(dentry)); |
16055 | + h_dinode = d_inode(h_dentry); | |
4a4d8108 AM |
16056 | + bend = au_ibend(inode); |
16057 | + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) { | |
16058 | + h_inode = au_h_iptr(inode, bindex); | |
537831f9 AM |
16059 | + if (!h_inode || h_inode != h_dinode) |
16060 | + continue; | |
16061 | + | |
16062 | + err = 0; | |
16063 | + gen = au_iigen(inode, &iigen); | |
16064 | + if (gen == au_digen(dentry) | |
16065 | + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED)) | |
4a4d8108 | 16066 | + break; |
537831f9 AM |
16067 | + |
16068 | + /* fully refresh inode using dentry */ | |
16069 | + err = au_refresh_hinode(inode, dentry); | |
16070 | + if (!err) | |
16071 | + au_update_iigen(inode, /*half*/0); | |
16072 | + break; | |
1facf9fc | 16073 | + } |
dece6358 | 16074 | + |
4a4d8108 AM |
16075 | + if (unlikely(err)) |
16076 | + ii_write_unlock(inode); | |
4f0767ce | 16077 | +out: |
1facf9fc | 16078 | + return err; |
16079 | +} | |
1facf9fc | 16080 | + |
4a4d8108 AM |
16081 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
16082 | + unsigned int d_type, ino_t *ino) | |
1facf9fc | 16083 | +{ |
4a4d8108 AM |
16084 | + int err; |
16085 | + struct mutex *mtx; | |
1facf9fc | 16086 | + |
b752ccd1 | 16087 | + /* prevent hardlinked inode number from race condition */ |
4a4d8108 | 16088 | + mtx = NULL; |
b752ccd1 | 16089 | + if (d_type != DT_DIR) { |
4a4d8108 AM |
16090 | + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx; |
16091 | + mutex_lock(mtx); | |
16092 | + } | |
16093 | + err = au_xino_read(sb, bindex, h_ino, ino); | |
16094 | + if (unlikely(err)) | |
16095 | + goto out; | |
1308ab2a | 16096 | + |
4a4d8108 AM |
16097 | + if (!*ino) { |
16098 | + err = -EIO; | |
16099 | + *ino = au_xino_new_ino(sb); | |
16100 | + if (unlikely(!*ino)) | |
1facf9fc | 16101 | + goto out; |
4a4d8108 AM |
16102 | + err = au_xino_write(sb, bindex, h_ino, *ino); |
16103 | + if (unlikely(err)) | |
1308ab2a | 16104 | + goto out; |
1308ab2a | 16105 | + } |
1facf9fc | 16106 | + |
4f0767ce | 16107 | +out: |
b752ccd1 | 16108 | + if (mtx) |
4a4d8108 | 16109 | + mutex_unlock(mtx); |
1facf9fc | 16110 | + return err; |
16111 | +} | |
16112 | + | |
4a4d8108 AM |
16113 | +/* successful returns with iinfo write_locked */ |
16114 | +/* todo: return with unlocked? */ | |
16115 | +struct inode *au_new_inode(struct dentry *dentry, int must_new) | |
1facf9fc | 16116 | +{ |
5527c038 | 16117 | + struct inode *inode, *h_inode; |
4a4d8108 AM |
16118 | + struct dentry *h_dentry; |
16119 | + struct super_block *sb; | |
b752ccd1 | 16120 | + struct mutex *mtx; |
4a4d8108 | 16121 | + ino_t h_ino, ino; |
1716fcea | 16122 | + int err; |
4a4d8108 | 16123 | + aufs_bindex_t bstart; |
1facf9fc | 16124 | + |
4a4d8108 AM |
16125 | + sb = dentry->d_sb; |
16126 | + bstart = au_dbstart(dentry); | |
16127 | + h_dentry = au_h_dptr(dentry, bstart); | |
5527c038 JR |
16128 | + h_inode = d_inode(h_dentry); |
16129 | + h_ino = h_inode->i_ino; | |
b752ccd1 AM |
16130 | + |
16131 | + /* | |
16132 | + * stop 'race'-ing between hardlinks under different | |
16133 | + * parents. | |
16134 | + */ | |
16135 | + mtx = NULL; | |
2000de60 | 16136 | + if (!d_is_dir(h_dentry)) |
b752ccd1 AM |
16137 | + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx; |
16138 | + | |
4f0767ce | 16139 | +new_ino: |
b752ccd1 AM |
16140 | + if (mtx) |
16141 | + mutex_lock(mtx); | |
4a4d8108 AM |
16142 | + err = au_xino_read(sb, bstart, h_ino, &ino); |
16143 | + inode = ERR_PTR(err); | |
16144 | + if (unlikely(err)) | |
16145 | + goto out; | |
b752ccd1 | 16146 | + |
4a4d8108 AM |
16147 | + if (!ino) { |
16148 | + ino = au_xino_new_ino(sb); | |
16149 | + if (unlikely(!ino)) { | |
16150 | + inode = ERR_PTR(-EIO); | |
dece6358 AM |
16151 | + goto out; |
16152 | + } | |
16153 | + } | |
1facf9fc | 16154 | + |
4a4d8108 AM |
16155 | + AuDbg("i%lu\n", (unsigned long)ino); |
16156 | + inode = au_iget_locked(sb, ino); | |
16157 | + err = PTR_ERR(inode); | |
16158 | + if (IS_ERR(inode)) | |
1facf9fc | 16159 | + goto out; |
1facf9fc | 16160 | + |
4a4d8108 AM |
16161 | + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW)); |
16162 | + if (inode->i_state & I_NEW) { | |
1716fcea | 16163 | + /* verbose coding for lock class name */ |
2000de60 | 16164 | + if (unlikely(d_is_symlink(h_dentry))) |
1716fcea AM |
16165 | + au_rw_class(&au_ii(inode)->ii_rwsem, |
16166 | + au_lc_key + AuLcSymlink_IIINFO); | |
2000de60 | 16167 | + else if (unlikely(d_is_dir(h_dentry))) |
1716fcea AM |
16168 | + au_rw_class(&au_ii(inode)->ii_rwsem, |
16169 | + au_lc_key + AuLcDir_IIINFO); | |
16170 | + else /* likely */ | |
16171 | + au_rw_class(&au_ii(inode)->ii_rwsem, | |
16172 | + au_lc_key + AuLcNonDir_IIINFO); | |
2dfbb274 | 16173 | + |
4a4d8108 AM |
16174 | + ii_write_lock_new_child(inode); |
16175 | + err = set_inode(inode, dentry); | |
16176 | + if (!err) { | |
16177 | + unlock_new_inode(inode); | |
16178 | + goto out; /* success */ | |
16179 | + } | |
1308ab2a | 16180 | + |
027c5e7a AM |
16181 | + /* |
16182 | + * iget_failed() calls iput(), but we need to call | |
16183 | + * ii_write_unlock() after iget_failed(). so dirty hack for | |
16184 | + * i_count. | |
16185 | + */ | |
16186 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 16187 | + iget_failed(inode); |
027c5e7a AM |
16188 | + ii_write_unlock(inode); |
16189 | + au_xino_write(sb, bstart, h_ino, /*ino*/0); | |
16190 | + /* ignore this error */ | |
16191 | + goto out_iput; | |
16192 | + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) { | |
b752ccd1 AM |
16193 | + /* |
16194 | + * horrible race condition between lookup, readdir and copyup | |
16195 | + * (or something). | |
16196 | + */ | |
16197 | + if (mtx) | |
16198 | + mutex_unlock(mtx); | |
027c5e7a AM |
16199 | + err = reval_inode(inode, dentry); |
16200 | + if (unlikely(err < 0)) { | |
16201 | + mtx = NULL; | |
16202 | + goto out_iput; | |
16203 | + } | |
16204 | + | |
b752ccd1 AM |
16205 | + if (!err) { |
16206 | + mtx = NULL; | |
4a4d8108 | 16207 | + goto out; /* success */ |
b752ccd1 AM |
16208 | + } else if (mtx) |
16209 | + mutex_lock(mtx); | |
4a4d8108 AM |
16210 | + } |
16211 | + | |
5527c038 | 16212 | + if (unlikely(au_test_fs_unique_ino(h_inode))) |
4a4d8108 | 16213 | + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir," |
523b37e3 AM |
16214 | + " b%d, %s, %pd, hi%lu, i%lu.\n", |
16215 | + bstart, au_sbtype(h_dentry->d_sb), dentry, | |
4a4d8108 AM |
16216 | + (unsigned long)h_ino, (unsigned long)ino); |
16217 | + ino = 0; | |
16218 | + err = au_xino_write(sb, bstart, h_ino, /*ino*/0); | |
16219 | + if (!err) { | |
16220 | + iput(inode); | |
b752ccd1 AM |
16221 | + if (mtx) |
16222 | + mutex_unlock(mtx); | |
4a4d8108 AM |
16223 | + goto new_ino; |
16224 | + } | |
1308ab2a | 16225 | + |
4f0767ce | 16226 | +out_iput: |
4a4d8108 | 16227 | + iput(inode); |
4a4d8108 | 16228 | + inode = ERR_PTR(err); |
4f0767ce | 16229 | +out: |
b752ccd1 AM |
16230 | + if (mtx) |
16231 | + mutex_unlock(mtx); | |
4a4d8108 | 16232 | + return inode; |
1facf9fc | 16233 | +} |
16234 | + | |
4a4d8108 | 16235 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16236 | + |
4a4d8108 AM |
16237 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, |
16238 | + struct inode *inode) | |
16239 | +{ | |
16240 | + int err; | |
076b876e | 16241 | + struct inode *hi; |
1facf9fc | 16242 | + |
4a4d8108 | 16243 | + err = au_br_rdonly(au_sbr(sb, bindex)); |
1facf9fc | 16244 | + |
4a4d8108 AM |
16245 | + /* pseudo-link after flushed may happen out of bounds */ |
16246 | + if (!err | |
16247 | + && inode | |
16248 | + && au_ibstart(inode) <= bindex | |
16249 | + && bindex <= au_ibend(inode)) { | |
16250 | + /* | |
16251 | + * permission check is unnecessary since vfsub routine | |
16252 | + * will be called later | |
16253 | + */ | |
076b876e | 16254 | + hi = au_h_iptr(inode, bindex); |
4a4d8108 AM |
16255 | + if (hi) |
16256 | + err = IS_IMMUTABLE(hi) ? -EROFS : 0; | |
1facf9fc | 16257 | + } |
16258 | + | |
4a4d8108 AM |
16259 | + return err; |
16260 | +} | |
dece6358 | 16261 | + |
4a4d8108 AM |
16262 | +int au_test_h_perm(struct inode *h_inode, int mask) |
16263 | +{ | |
2dfbb274 | 16264 | + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) |
4a4d8108 AM |
16265 | + return 0; |
16266 | + return inode_permission(h_inode, mask); | |
16267 | +} | |
1facf9fc | 16268 | + |
4a4d8108 AM |
16269 | +int au_test_h_perm_sio(struct inode *h_inode, int mask) |
16270 | +{ | |
16271 | + if (au_test_nfs(h_inode->i_sb) | |
16272 | + && (mask & MAY_WRITE) | |
16273 | + && S_ISDIR(h_inode->i_mode)) | |
16274 | + mask |= MAY_READ; /* force permission check */ | |
16275 | + return au_test_h_perm(h_inode, mask); | |
1facf9fc | 16276 | +} |
7f207e10 AM |
16277 | diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h |
16278 | --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 16279 | +++ linux/fs/aufs/inode.h 2015-06-28 17:35:44.348050491 +0200 |
b912730e | 16280 | @@ -0,0 +1,673 @@ |
4a4d8108 | 16281 | +/* |
2000de60 | 16282 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
16283 | + * |
16284 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16285 | + * it under the terms of the GNU General Public License as published by | |
16286 | + * the Free Software Foundation; either version 2 of the License, or | |
16287 | + * (at your option) any later version. | |
16288 | + * | |
16289 | + * This program is distributed in the hope that it will be useful, | |
16290 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16291 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16292 | + * GNU General Public License for more details. | |
16293 | + * | |
16294 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16295 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 16296 | + */ |
1facf9fc | 16297 | + |
1308ab2a | 16298 | +/* |
4a4d8108 | 16299 | + * inode operations |
1308ab2a | 16300 | + */ |
dece6358 | 16301 | + |
4a4d8108 AM |
16302 | +#ifndef __AUFS_INODE_H__ |
16303 | +#define __AUFS_INODE_H__ | |
dece6358 | 16304 | + |
4a4d8108 | 16305 | +#ifdef __KERNEL__ |
1308ab2a | 16306 | + |
4a4d8108 | 16307 | +#include <linux/fsnotify.h> |
4a4d8108 | 16308 | +#include "rwsem.h" |
1308ab2a | 16309 | + |
4a4d8108 | 16310 | +struct vfsmount; |
1facf9fc | 16311 | + |
4a4d8108 AM |
16312 | +struct au_hnotify { |
16313 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16314 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
7f207e10 | 16315 | + /* never use fsnotify_add_vfsmount_mark() */ |
0c5527e5 | 16316 | + struct fsnotify_mark hn_mark; |
4a4d8108 | 16317 | +#endif |
7f207e10 | 16318 | + struct inode *hn_aufs_inode; /* no get/put */ |
4a4d8108 AM |
16319 | +#endif |
16320 | +} ____cacheline_aligned_in_smp; | |
1facf9fc | 16321 | + |
4a4d8108 AM |
16322 | +struct au_hinode { |
16323 | + struct inode *hi_inode; | |
16324 | + aufs_bindex_t hi_id; | |
16325 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16326 | + struct au_hnotify *hi_notify; | |
16327 | +#endif | |
dece6358 | 16328 | + |
4a4d8108 AM |
16329 | + /* reference to the copied-up whiteout with get/put */ |
16330 | + struct dentry *hi_whdentry; | |
16331 | +}; | |
dece6358 | 16332 | + |
537831f9 AM |
16333 | +/* ig_flags */ |
16334 | +#define AuIG_HALF_REFRESHED 1 | |
16335 | +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name) | |
16336 | +#define au_ig_fset(flags, name) \ | |
16337 | + do { (flags) |= AuIG_##name; } while (0) | |
16338 | +#define au_ig_fclr(flags, name) \ | |
16339 | + do { (flags) &= ~AuIG_##name; } while (0) | |
16340 | + | |
16341 | +struct au_iigen { | |
16342 | + __u32 ig_generation, ig_flags; | |
16343 | +}; | |
16344 | + | |
4a4d8108 AM |
16345 | +struct au_vdir; |
16346 | +struct au_iinfo { | |
537831f9 | 16347 | + spinlock_t ii_genspin; |
7a9e40b8 | 16348 | + struct au_iigen ii_generation; |
4a4d8108 | 16349 | + struct super_block *ii_hsb1; /* no get/put */ |
1facf9fc | 16350 | + |
4a4d8108 AM |
16351 | + struct au_rwsem ii_rwsem; |
16352 | + aufs_bindex_t ii_bstart, ii_bend; | |
16353 | + __u32 ii_higen; | |
16354 | + struct au_hinode *ii_hinode; | |
16355 | + struct au_vdir *ii_vdir; | |
16356 | +}; | |
1facf9fc | 16357 | + |
4a4d8108 AM |
16358 | +struct au_icntnr { |
16359 | + struct au_iinfo iinfo; | |
16360 | + struct inode vfs_inode; | |
16361 | +} ____cacheline_aligned_in_smp; | |
1308ab2a | 16362 | + |
4a4d8108 AM |
16363 | +/* au_pin flags */ |
16364 | +#define AuPin_DI_LOCKED 1 | |
16365 | +#define AuPin_MNT_WRITE (1 << 1) | |
16366 | +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name) | |
7f207e10 AM |
16367 | +#define au_fset_pin(flags, name) \ |
16368 | + do { (flags) |= AuPin_##name; } while (0) | |
16369 | +#define au_fclr_pin(flags, name) \ | |
16370 | + do { (flags) &= ~AuPin_##name; } while (0) | |
4a4d8108 AM |
16371 | + |
16372 | +struct au_pin { | |
16373 | + /* input */ | |
16374 | + struct dentry *dentry; | |
16375 | + unsigned int udba; | |
16376 | + unsigned char lsc_di, lsc_hi, flags; | |
16377 | + aufs_bindex_t bindex; | |
16378 | + | |
16379 | + /* output */ | |
16380 | + struct dentry *parent; | |
16381 | + struct au_hinode *hdir; | |
16382 | + struct vfsmount *h_mnt; | |
86dc4139 AM |
16383 | + |
16384 | + /* temporary unlock/relock for copyup */ | |
16385 | + struct dentry *h_dentry, *h_parent; | |
16386 | + struct au_branch *br; | |
16387 | + struct task_struct *task; | |
4a4d8108 | 16388 | +}; |
1facf9fc | 16389 | + |
86dc4139 | 16390 | +void au_pin_hdir_unlock(struct au_pin *p); |
c1595e42 | 16391 | +int au_pin_hdir_lock(struct au_pin *p); |
86dc4139 AM |
16392 | +int au_pin_hdir_relock(struct au_pin *p); |
16393 | +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task); | |
16394 | +void au_pin_hdir_acquire_nest(struct au_pin *p); | |
16395 | +void au_pin_hdir_release(struct au_pin *p); | |
16396 | + | |
1308ab2a | 16397 | +/* ---------------------------------------------------------------------- */ |
16398 | + | |
4a4d8108 | 16399 | +static inline struct au_iinfo *au_ii(struct inode *inode) |
1facf9fc | 16400 | +{ |
4a4d8108 | 16401 | + struct au_iinfo *iinfo; |
1facf9fc | 16402 | + |
4a4d8108 AM |
16403 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); |
16404 | + if (iinfo->ii_hinode) | |
16405 | + return iinfo; | |
16406 | + return NULL; /* debugging bad_inode case */ | |
16407 | +} | |
1facf9fc | 16408 | + |
4a4d8108 | 16409 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16410 | + |
4a4d8108 AM |
16411 | +/* inode.c */ |
16412 | +struct inode *au_igrab(struct inode *inode); | |
027c5e7a | 16413 | +int au_refresh_hinode_self(struct inode *inode); |
4a4d8108 AM |
16414 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry); |
16415 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
16416 | + unsigned int d_type, ino_t *ino); | |
16417 | +struct inode *au_new_inode(struct dentry *dentry, int must_new); | |
16418 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, | |
16419 | + struct inode *inode); | |
16420 | +int au_test_h_perm(struct inode *h_inode, int mask); | |
16421 | +int au_test_h_perm_sio(struct inode *h_inode, int mask); | |
1facf9fc | 16422 | + |
4a4d8108 AM |
16423 | +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, |
16424 | + ino_t h_ino, unsigned int d_type, ino_t *ino) | |
16425 | +{ | |
16426 | +#ifdef CONFIG_AUFS_SHWH | |
16427 | + return au_ino(sb, bindex, h_ino, d_type, ino); | |
16428 | +#else | |
16429 | + return 0; | |
16430 | +#endif | |
16431 | +} | |
1facf9fc | 16432 | + |
4a4d8108 AM |
16433 | +/* i_op.c */ |
16434 | +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop; | |
1308ab2a | 16435 | + |
4a4d8108 AM |
16436 | +/* au_wr_dir flags */ |
16437 | +#define AuWrDir_ADD_ENTRY 1 | |
7e9cd9fe AM |
16438 | +#define AuWrDir_ISDIR (1 << 1) |
16439 | +#define AuWrDir_TMPFILE (1 << 2) | |
4a4d8108 | 16440 | +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name) |
7f207e10 AM |
16441 | +#define au_fset_wrdir(flags, name) \ |
16442 | + do { (flags) |= AuWrDir_##name; } while (0) | |
16443 | +#define au_fclr_wrdir(flags, name) \ | |
16444 | + do { (flags) &= ~AuWrDir_##name; } while (0) | |
1facf9fc | 16445 | + |
4a4d8108 AM |
16446 | +struct au_wr_dir_args { |
16447 | + aufs_bindex_t force_btgt; | |
16448 | + unsigned char flags; | |
16449 | +}; | |
16450 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
16451 | + struct au_wr_dir_args *args); | |
dece6358 | 16452 | + |
4a4d8108 AM |
16453 | +struct dentry *au_pinned_h_parent(struct au_pin *pin); |
16454 | +void au_pin_init(struct au_pin *pin, struct dentry *dentry, | |
16455 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
16456 | + unsigned int udba, unsigned char flags); | |
16457 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
16458 | + unsigned int udba, unsigned char flags) __must_check; | |
16459 | +int au_do_pin(struct au_pin *pin) __must_check; | |
16460 | +void au_unpin(struct au_pin *pin); | |
c1595e42 JR |
16461 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen); |
16462 | + | |
16463 | +#define AuIcpup_DID_CPUP 1 | |
16464 | +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name) | |
16465 | +#define au_fset_icpup(flags, name) \ | |
16466 | + do { (flags) |= AuIcpup_##name; } while (0) | |
16467 | +#define au_fclr_icpup(flags, name) \ | |
16468 | + do { (flags) &= ~AuIcpup_##name; } while (0) | |
16469 | + | |
16470 | +struct au_icpup_args { | |
16471 | + unsigned char flags; | |
16472 | + unsigned char pin_flags; | |
16473 | + aufs_bindex_t btgt; | |
16474 | + unsigned int udba; | |
16475 | + struct au_pin pin; | |
16476 | + struct path h_path; | |
16477 | + struct inode *h_inode; | |
16478 | +}; | |
16479 | + | |
16480 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, | |
16481 | + struct au_icpup_args *a); | |
16482 | + | |
16483 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path); | |
1facf9fc | 16484 | + |
4a4d8108 AM |
16485 | +/* i_op_add.c */ |
16486 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
16487 | + struct dentry *h_parent, int isdir); | |
7eafdf33 AM |
16488 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
16489 | + dev_t dev); | |
4a4d8108 | 16490 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname); |
7eafdf33 | 16491 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 16492 | + bool want_excl); |
b912730e AM |
16493 | +struct vfsub_aopen_args; |
16494 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, | |
16495 | + struct vfsub_aopen_args *args); | |
38d290e6 | 16496 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode); |
4a4d8108 AM |
16497 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, |
16498 | + struct dentry *dentry); | |
7eafdf33 | 16499 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
1facf9fc | 16500 | + |
4a4d8108 AM |
16501 | +/* i_op_del.c */ |
16502 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup); | |
16503 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
16504 | + struct dentry *h_parent, int isdir); | |
16505 | +int aufs_unlink(struct inode *dir, struct dentry *dentry); | |
16506 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry); | |
1308ab2a | 16507 | + |
4a4d8108 AM |
16508 | +/* i_op_ren.c */ |
16509 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt); | |
16510 | +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry, | |
16511 | + struct inode *dir, struct dentry *dentry); | |
1facf9fc | 16512 | + |
4a4d8108 AM |
16513 | +/* iinfo.c */ |
16514 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex); | |
16515 | +void au_hiput(struct au_hinode *hinode); | |
16516 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, | |
16517 | + struct dentry *h_wh); | |
16518 | +unsigned int au_hi_flags(struct inode *inode, int isdir); | |
1308ab2a | 16519 | + |
4a4d8108 AM |
16520 | +/* hinode flags */ |
16521 | +#define AuHi_XINO 1 | |
16522 | +#define AuHi_HNOTIFY (1 << 1) | |
16523 | +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name) | |
7f207e10 AM |
16524 | +#define au_fset_hi(flags, name) \ |
16525 | + do { (flags) |= AuHi_##name; } while (0) | |
16526 | +#define au_fclr_hi(flags, name) \ | |
16527 | + do { (flags) &= ~AuHi_##name; } while (0) | |
1facf9fc | 16528 | + |
4a4d8108 AM |
16529 | +#ifndef CONFIG_AUFS_HNOTIFY |
16530 | +#undef AuHi_HNOTIFY | |
16531 | +#define AuHi_HNOTIFY 0 | |
16532 | +#endif | |
1facf9fc | 16533 | + |
4a4d8108 AM |
16534 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
16535 | + struct inode *h_inode, unsigned int flags); | |
1facf9fc | 16536 | + |
537831f9 | 16537 | +void au_update_iigen(struct inode *inode, int half); |
4a4d8108 | 16538 | +void au_update_ibrange(struct inode *inode, int do_put_zero); |
1facf9fc | 16539 | + |
4a4d8108 AM |
16540 | +void au_icntnr_init_once(void *_c); |
16541 | +int au_iinfo_init(struct inode *inode); | |
16542 | +void au_iinfo_fin(struct inode *inode); | |
16543 | +int au_ii_realloc(struct au_iinfo *iinfo, int nbr); | |
1308ab2a | 16544 | + |
e49829fe | 16545 | +#ifdef CONFIG_PROC_FS |
4a4d8108 | 16546 | +/* plink.c */ |
e49829fe | 16547 | +int au_plink_maint(struct super_block *sb, int flags); |
7e9cd9fe | 16548 | +struct au_sbinfo; |
e49829fe JR |
16549 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo); |
16550 | +int au_plink_maint_enter(struct super_block *sb); | |
4a4d8108 AM |
16551 | +#ifdef CONFIG_AUFS_DEBUG |
16552 | +void au_plink_list(struct super_block *sb); | |
16553 | +#else | |
16554 | +AuStubVoid(au_plink_list, struct super_block *sb) | |
16555 | +#endif | |
16556 | +int au_plink_test(struct inode *inode); | |
16557 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex); | |
16558 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
16559 | + struct dentry *h_dentry); | |
e49829fe JR |
16560 | +void au_plink_put(struct super_block *sb, int verbose); |
16561 | +void au_plink_clean(struct super_block *sb, int verbose); | |
4a4d8108 | 16562 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id); |
e49829fe JR |
16563 | +#else |
16564 | +AuStubInt0(au_plink_maint, struct super_block *sb, int flags); | |
16565 | +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo); | |
16566 | +AuStubInt0(au_plink_maint_enter, struct super_block *sb); | |
16567 | +AuStubVoid(au_plink_list, struct super_block *sb); | |
16568 | +AuStubInt0(au_plink_test, struct inode *inode); | |
16569 | +AuStub(struct dentry *, au_plink_lkup, return NULL, | |
16570 | + struct inode *inode, aufs_bindex_t bindex); | |
16571 | +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex, | |
16572 | + struct dentry *h_dentry); | |
16573 | +AuStubVoid(au_plink_put, struct super_block *sb, int verbose); | |
16574 | +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose); | |
16575 | +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id); | |
16576 | +#endif /* CONFIG_PROC_FS */ | |
1facf9fc | 16577 | + |
c1595e42 JR |
16578 | +#ifdef CONFIG_AUFS_XATTR |
16579 | +/* xattr.c */ | |
7e9cd9fe AM |
16580 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
16581 | + unsigned int verbose); | |
c1595e42 JR |
16582 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size); |
16583 | +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value, | |
16584 | + size_t size); | |
16585 | +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value, | |
16586 | + size_t size, int flags); | |
16587 | +int aufs_removexattr(struct dentry *dentry, const char *name); | |
16588 | + | |
16589 | +/* void au_xattr_init(struct super_block *sb); */ | |
16590 | +#else | |
16591 | +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe | 16592 | + int ignore_flags, unsigned int verbose); |
c1595e42 JR |
16593 | +/* AuStubVoid(au_xattr_init, struct super_block *sb); */ |
16594 | +#endif | |
16595 | + | |
16596 | +#ifdef CONFIG_FS_POSIX_ACL | |
16597 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type); | |
16598 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
16599 | +#endif | |
16600 | + | |
16601 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) | |
16602 | +enum { | |
16603 | + AU_XATTR_SET, | |
16604 | + AU_XATTR_REMOVE, | |
16605 | + AU_ACL_SET | |
16606 | +}; | |
16607 | + | |
16608 | +struct au_srxattr { | |
16609 | + int type; | |
16610 | + union { | |
16611 | + struct { | |
16612 | + const char *name; | |
16613 | + const void *value; | |
16614 | + size_t size; | |
16615 | + int flags; | |
16616 | + } set; | |
16617 | + struct { | |
16618 | + const char *name; | |
16619 | + } remove; | |
16620 | + struct { | |
16621 | + struct posix_acl *acl; | |
16622 | + int type; | |
16623 | + } acl_set; | |
16624 | + } u; | |
16625 | +}; | |
16626 | +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg); | |
16627 | +#endif | |
16628 | + | |
4a4d8108 | 16629 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16630 | + |
4a4d8108 AM |
16631 | +/* lock subclass for iinfo */ |
16632 | +enum { | |
16633 | + AuLsc_II_CHILD, /* child first */ | |
16634 | + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */ | |
16635 | + AuLsc_II_CHILD3, /* copyup dirs */ | |
16636 | + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */ | |
16637 | + AuLsc_II_PARENT2, | |
16638 | + AuLsc_II_PARENT3, /* copyup dirs */ | |
16639 | + AuLsc_II_NEW_CHILD | |
16640 | +}; | |
1308ab2a | 16641 | + |
1facf9fc | 16642 | +/* |
4a4d8108 AM |
16643 | + * ii_read_lock_child, ii_write_lock_child, |
16644 | + * ii_read_lock_child2, ii_write_lock_child2, | |
16645 | + * ii_read_lock_child3, ii_write_lock_child3, | |
16646 | + * ii_read_lock_parent, ii_write_lock_parent, | |
16647 | + * ii_read_lock_parent2, ii_write_lock_parent2, | |
16648 | + * ii_read_lock_parent3, ii_write_lock_parent3, | |
16649 | + * ii_read_lock_new_child, ii_write_lock_new_child, | |
1facf9fc | 16650 | + */ |
4a4d8108 AM |
16651 | +#define AuReadLockFunc(name, lsc) \ |
16652 | +static inline void ii_read_lock_##name(struct inode *i) \ | |
16653 | +{ \ | |
16654 | + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
16655 | +} | |
16656 | + | |
16657 | +#define AuWriteLockFunc(name, lsc) \ | |
16658 | +static inline void ii_write_lock_##name(struct inode *i) \ | |
16659 | +{ \ | |
16660 | + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
16661 | +} | |
16662 | + | |
16663 | +#define AuRWLockFuncs(name, lsc) \ | |
16664 | + AuReadLockFunc(name, lsc) \ | |
16665 | + AuWriteLockFunc(name, lsc) | |
16666 | + | |
16667 | +AuRWLockFuncs(child, CHILD); | |
16668 | +AuRWLockFuncs(child2, CHILD2); | |
16669 | +AuRWLockFuncs(child3, CHILD3); | |
16670 | +AuRWLockFuncs(parent, PARENT); | |
16671 | +AuRWLockFuncs(parent2, PARENT2); | |
16672 | +AuRWLockFuncs(parent3, PARENT3); | |
16673 | +AuRWLockFuncs(new_child, NEW_CHILD); | |
16674 | + | |
16675 | +#undef AuReadLockFunc | |
16676 | +#undef AuWriteLockFunc | |
16677 | +#undef AuRWLockFuncs | |
1facf9fc | 16678 | + |
16679 | +/* | |
4a4d8108 | 16680 | + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock |
1facf9fc | 16681 | + */ |
4a4d8108 | 16682 | +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem); |
1facf9fc | 16683 | + |
4a4d8108 AM |
16684 | +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem) |
16685 | +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem) | |
16686 | +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 16687 | + |
4a4d8108 | 16688 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16689 | + |
027c5e7a AM |
16690 | +static inline void au_icntnr_init(struct au_icntnr *c) |
16691 | +{ | |
16692 | +#ifdef CONFIG_AUFS_DEBUG | |
16693 | + c->vfs_inode.i_mode = 0; | |
16694 | +#endif | |
16695 | +} | |
16696 | + | |
537831f9 | 16697 | +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen) |
4a4d8108 | 16698 | +{ |
537831f9 AM |
16699 | + unsigned int gen; |
16700 | + struct au_iinfo *iinfo; | |
16701 | + | |
16702 | + iinfo = au_ii(inode); | |
16703 | + spin_lock(&iinfo->ii_genspin); | |
16704 | + if (iigen) | |
16705 | + *iigen = iinfo->ii_generation; | |
16706 | + gen = iinfo->ii_generation.ig_generation; | |
16707 | + spin_unlock(&iinfo->ii_genspin); | |
16708 | + | |
16709 | + return gen; | |
4a4d8108 | 16710 | +} |
1308ab2a | 16711 | + |
4a4d8108 AM |
16712 | +/* tiny test for inode number */ |
16713 | +/* tmpfs generation is too rough */ | |
16714 | +static inline int au_test_higen(struct inode *inode, struct inode *h_inode) | |
16715 | +{ | |
16716 | + struct au_iinfo *iinfo; | |
1308ab2a | 16717 | + |
4a4d8108 AM |
16718 | + iinfo = au_ii(inode); |
16719 | + AuRwMustAnyLock(&iinfo->ii_rwsem); | |
16720 | + return !(iinfo->ii_hsb1 == h_inode->i_sb | |
16721 | + && iinfo->ii_higen == h_inode->i_generation); | |
16722 | +} | |
1308ab2a | 16723 | + |
4a4d8108 AM |
16724 | +static inline void au_iigen_dec(struct inode *inode) |
16725 | +{ | |
537831f9 AM |
16726 | + struct au_iinfo *iinfo; |
16727 | + | |
16728 | + iinfo = au_ii(inode); | |
16729 | + spin_lock(&iinfo->ii_genspin); | |
16730 | + iinfo->ii_generation.ig_generation--; | |
16731 | + spin_unlock(&iinfo->ii_genspin); | |
027c5e7a AM |
16732 | +} |
16733 | + | |
16734 | +static inline int au_iigen_test(struct inode *inode, unsigned int sigen) | |
16735 | +{ | |
16736 | + int err; | |
16737 | + | |
16738 | + err = 0; | |
537831f9 | 16739 | + if (unlikely(inode && au_iigen(inode, NULL) != sigen)) |
027c5e7a AM |
16740 | + err = -EIO; |
16741 | + | |
16742 | + return err; | |
4a4d8108 | 16743 | +} |
1308ab2a | 16744 | + |
4a4d8108 | 16745 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16746 | + |
4a4d8108 AM |
16747 | +static inline aufs_bindex_t au_ii_br_id(struct inode *inode, |
16748 | + aufs_bindex_t bindex) | |
16749 | +{ | |
16750 | + IiMustAnyLock(inode); | |
16751 | + return au_ii(inode)->ii_hinode[0 + bindex].hi_id; | |
16752 | +} | |
1308ab2a | 16753 | + |
4a4d8108 AM |
16754 | +static inline aufs_bindex_t au_ibstart(struct inode *inode) |
16755 | +{ | |
16756 | + IiMustAnyLock(inode); | |
16757 | + return au_ii(inode)->ii_bstart; | |
16758 | +} | |
1308ab2a | 16759 | + |
4a4d8108 AM |
16760 | +static inline aufs_bindex_t au_ibend(struct inode *inode) |
16761 | +{ | |
16762 | + IiMustAnyLock(inode); | |
16763 | + return au_ii(inode)->ii_bend; | |
16764 | +} | |
1308ab2a | 16765 | + |
4a4d8108 AM |
16766 | +static inline struct au_vdir *au_ivdir(struct inode *inode) |
16767 | +{ | |
16768 | + IiMustAnyLock(inode); | |
16769 | + return au_ii(inode)->ii_vdir; | |
16770 | +} | |
1308ab2a | 16771 | + |
4a4d8108 AM |
16772 | +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex) |
16773 | +{ | |
16774 | + IiMustAnyLock(inode); | |
16775 | + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry; | |
16776 | +} | |
1308ab2a | 16777 | + |
4a4d8108 | 16778 | +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 16779 | +{ |
4a4d8108 AM |
16780 | + IiMustWriteLock(inode); |
16781 | + au_ii(inode)->ii_bstart = bindex; | |
16782 | +} | |
1308ab2a | 16783 | + |
4a4d8108 AM |
16784 | +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex) |
16785 | +{ | |
16786 | + IiMustWriteLock(inode); | |
16787 | + au_ii(inode)->ii_bend = bindex; | |
1308ab2a | 16788 | +} |
16789 | + | |
4a4d8108 AM |
16790 | +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir) |
16791 | +{ | |
16792 | + IiMustWriteLock(inode); | |
16793 | + au_ii(inode)->ii_vdir = vdir; | |
16794 | +} | |
1facf9fc | 16795 | + |
4a4d8108 | 16796 | +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 16797 | +{ |
4a4d8108 AM |
16798 | + IiMustAnyLock(inode); |
16799 | + return au_ii(inode)->ii_hinode + bindex; | |
16800 | +} | |
dece6358 | 16801 | + |
4a4d8108 | 16802 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16803 | + |
4a4d8108 AM |
16804 | +static inline struct dentry *au_pinned_parent(struct au_pin *pin) |
16805 | +{ | |
16806 | + if (pin) | |
16807 | + return pin->parent; | |
16808 | + return NULL; | |
1facf9fc | 16809 | +} |
16810 | + | |
4a4d8108 | 16811 | +static inline struct inode *au_pinned_h_dir(struct au_pin *pin) |
1facf9fc | 16812 | +{ |
4a4d8108 AM |
16813 | + if (pin && pin->hdir) |
16814 | + return pin->hdir->hi_inode; | |
16815 | + return NULL; | |
1308ab2a | 16816 | +} |
1facf9fc | 16817 | + |
4a4d8108 AM |
16818 | +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin) |
16819 | +{ | |
16820 | + if (pin) | |
16821 | + return pin->hdir; | |
16822 | + return NULL; | |
16823 | +} | |
1facf9fc | 16824 | + |
4a4d8108 | 16825 | +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry) |
1308ab2a | 16826 | +{ |
4a4d8108 AM |
16827 | + if (pin) |
16828 | + pin->dentry = dentry; | |
16829 | +} | |
1308ab2a | 16830 | + |
4a4d8108 AM |
16831 | +static inline void au_pin_set_parent_lflag(struct au_pin *pin, |
16832 | + unsigned char lflag) | |
16833 | +{ | |
16834 | + if (pin) { | |
7f207e10 | 16835 | + if (lflag) |
4a4d8108 | 16836 | + au_fset_pin(pin->flags, DI_LOCKED); |
7f207e10 | 16837 | + else |
4a4d8108 | 16838 | + au_fclr_pin(pin->flags, DI_LOCKED); |
1308ab2a | 16839 | + } |
4a4d8108 AM |
16840 | +} |
16841 | + | |
7e9cd9fe | 16842 | +#if 0 /* reserved */ |
4a4d8108 AM |
16843 | +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent) |
16844 | +{ | |
16845 | + if (pin) { | |
16846 | + dput(pin->parent); | |
16847 | + pin->parent = dget(parent); | |
1facf9fc | 16848 | + } |
4a4d8108 | 16849 | +} |
7e9cd9fe | 16850 | +#endif |
1facf9fc | 16851 | + |
4a4d8108 AM |
16852 | +/* ---------------------------------------------------------------------- */ |
16853 | + | |
027c5e7a | 16854 | +struct au_branch; |
4a4d8108 AM |
16855 | +#ifdef CONFIG_AUFS_HNOTIFY |
16856 | +struct au_hnotify_op { | |
16857 | + void (*ctl)(struct au_hinode *hinode, int do_set); | |
027c5e7a | 16858 | + int (*alloc)(struct au_hinode *hinode); |
7eafdf33 AM |
16859 | + |
16860 | + /* | |
16861 | + * if it returns true, the the caller should free hinode->hi_notify, | |
16862 | + * otherwise ->free() frees it. | |
16863 | + */ | |
16864 | + int (*free)(struct au_hinode *hinode, | |
16865 | + struct au_hnotify *hn) __must_check; | |
4a4d8108 AM |
16866 | + |
16867 | + void (*fin)(void); | |
16868 | + int (*init)(void); | |
027c5e7a AM |
16869 | + |
16870 | + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm); | |
16871 | + void (*fin_br)(struct au_branch *br); | |
16872 | + int (*init_br)(struct au_branch *br, int perm); | |
4a4d8108 AM |
16873 | +}; |
16874 | + | |
16875 | +/* hnotify.c */ | |
027c5e7a | 16876 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode); |
4a4d8108 AM |
16877 | +void au_hn_free(struct au_hinode *hinode); |
16878 | +void au_hn_ctl(struct au_hinode *hinode, int do_set); | |
16879 | +void au_hn_reset(struct inode *inode, unsigned int flags); | |
16880 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
16881 | + struct qstr *h_child_qstr, struct inode *h_child_inode); | |
027c5e7a AM |
16882 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm); |
16883 | +int au_hnotify_init_br(struct au_branch *br, int perm); | |
16884 | +void au_hnotify_fin_br(struct au_branch *br); | |
4a4d8108 AM |
16885 | +int __init au_hnotify_init(void); |
16886 | +void au_hnotify_fin(void); | |
16887 | + | |
7f207e10 | 16888 | +/* hfsnotify.c */ |
4a4d8108 AM |
16889 | +extern const struct au_hnotify_op au_hnotify_op; |
16890 | + | |
16891 | +static inline | |
16892 | +void au_hn_init(struct au_hinode *hinode) | |
16893 | +{ | |
16894 | + hinode->hi_notify = NULL; | |
1308ab2a | 16895 | +} |
16896 | + | |
53392da6 AM |
16897 | +static inline struct au_hnotify *au_hn(struct au_hinode *hinode) |
16898 | +{ | |
16899 | + return hinode->hi_notify; | |
16900 | +} | |
16901 | + | |
4a4d8108 | 16902 | +#else |
c1595e42 JR |
16903 | +AuStub(int, au_hn_alloc, return -EOPNOTSUPP, |
16904 | + struct au_hinode *hinode __maybe_unused, | |
16905 | + struct inode *inode __maybe_unused) | |
16906 | +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode) | |
4a4d8108 AM |
16907 | +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused) |
16908 | +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused, | |
16909 | + int do_set __maybe_unused) | |
16910 | +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused, | |
16911 | + unsigned int flags __maybe_unused) | |
027c5e7a AM |
16912 | +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused, |
16913 | + struct au_branch *br __maybe_unused, | |
16914 | + int perm __maybe_unused) | |
16915 | +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused, | |
16916 | + int perm __maybe_unused) | |
16917 | +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused) | |
4a4d8108 AM |
16918 | +AuStubInt0(__init au_hnotify_init, void) |
16919 | +AuStubVoid(au_hnotify_fin, void) | |
16920 | +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused) | |
16921 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
16922 | + | |
16923 | +static inline void au_hn_suspend(struct au_hinode *hdir) | |
16924 | +{ | |
16925 | + au_hn_ctl(hdir, /*do_set*/0); | |
1308ab2a | 16926 | +} |
16927 | + | |
4a4d8108 | 16928 | +static inline void au_hn_resume(struct au_hinode *hdir) |
1308ab2a | 16929 | +{ |
4a4d8108 AM |
16930 | + au_hn_ctl(hdir, /*do_set*/1); |
16931 | +} | |
1308ab2a | 16932 | + |
4a4d8108 AM |
16933 | +static inline void au_hn_imtx_lock(struct au_hinode *hdir) |
16934 | +{ | |
16935 | + mutex_lock(&hdir->hi_inode->i_mutex); | |
16936 | + au_hn_suspend(hdir); | |
16937 | +} | |
dece6358 | 16938 | + |
4a4d8108 AM |
16939 | +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir, |
16940 | + unsigned int sc __maybe_unused) | |
16941 | +{ | |
16942 | + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc); | |
16943 | + au_hn_suspend(hdir); | |
1facf9fc | 16944 | +} |
1facf9fc | 16945 | + |
4a4d8108 AM |
16946 | +static inline void au_hn_imtx_unlock(struct au_hinode *hdir) |
16947 | +{ | |
16948 | + au_hn_resume(hdir); | |
16949 | + mutex_unlock(&hdir->hi_inode->i_mutex); | |
16950 | +} | |
16951 | + | |
16952 | +#endif /* __KERNEL__ */ | |
16953 | +#endif /* __AUFS_INODE_H__ */ | |
7f207e10 AM |
16954 | diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c |
16955 | --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 16956 | +++ linux/fs/aufs/ioctl.c 2015-06-28 17:35:44.348050491 +0200 |
c1595e42 | 16957 | @@ -0,0 +1,219 @@ |
4a4d8108 | 16958 | +/* |
2000de60 | 16959 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
16960 | + * |
16961 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16962 | + * it under the terms of the GNU General Public License as published by | |
16963 | + * the Free Software Foundation; either version 2 of the License, or | |
16964 | + * (at your option) any later version. | |
16965 | + * | |
16966 | + * This program is distributed in the hope that it will be useful, | |
16967 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16968 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16969 | + * GNU General Public License for more details. | |
16970 | + * | |
16971 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16972 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
16973 | + */ |
16974 | + | |
16975 | +/* | |
16976 | + * ioctl | |
16977 | + * plink-management and readdir in userspace. | |
16978 | + * assist the pathconf(3) wrapper library. | |
c2b27bf2 | 16979 | + * move-down |
076b876e | 16980 | + * File-based Hierarchical Storage Management. |
4a4d8108 AM |
16981 | + */ |
16982 | + | |
c2b27bf2 AM |
16983 | +#include <linux/compat.h> |
16984 | +#include <linux/file.h> | |
4a4d8108 AM |
16985 | +#include "aufs.h" |
16986 | + | |
1e00d052 | 16987 | +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg) |
4a4d8108 AM |
16988 | +{ |
16989 | + int err, fd; | |
16990 | + aufs_bindex_t wbi, bindex, bend; | |
16991 | + struct file *h_file; | |
16992 | + struct super_block *sb; | |
16993 | + struct dentry *root; | |
1e00d052 AM |
16994 | + struct au_branch *br; |
16995 | + struct aufs_wbr_fd wbrfd = { | |
16996 | + .oflags = au_dir_roflags, | |
16997 | + .brid = -1 | |
16998 | + }; | |
16999 | + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY | |
17000 | + | O_NOATIME | O_CLOEXEC; | |
4a4d8108 | 17001 | + |
1e00d052 AM |
17002 | + AuDebugOn(wbrfd.oflags & ~valid); |
17003 | + | |
17004 | + if (arg) { | |
17005 | + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd)); | |
17006 | + if (unlikely(err)) { | |
17007 | + err = -EFAULT; | |
17008 | + goto out; | |
17009 | + } | |
17010 | + | |
17011 | + err = -EINVAL; | |
17012 | + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid); | |
17013 | + wbrfd.oflags |= au_dir_roflags; | |
17014 | + AuDbg("0%o\n", wbrfd.oflags); | |
17015 | + if (unlikely(wbrfd.oflags & ~valid)) | |
17016 | + goto out; | |
17017 | + } | |
17018 | + | |
2000de60 | 17019 | + fd = get_unused_fd_flags(0); |
1e00d052 AM |
17020 | + err = fd; |
17021 | + if (unlikely(fd < 0)) | |
4a4d8108 | 17022 | + goto out; |
4a4d8108 | 17023 | + |
1e00d052 | 17024 | + h_file = ERR_PTR(-EINVAL); |
4a4d8108 | 17025 | + wbi = 0; |
1e00d052 | 17026 | + br = NULL; |
4a4d8108 AM |
17027 | + sb = path->dentry->d_sb; |
17028 | + root = sb->s_root; | |
17029 | + aufs_read_lock(root, AuLock_IR); | |
1e00d052 AM |
17030 | + bend = au_sbend(sb); |
17031 | + if (wbrfd.brid >= 0) { | |
17032 | + wbi = au_br_index(sb, wbrfd.brid); | |
17033 | + if (unlikely(wbi < 0 || wbi > bend)) | |
17034 | + goto out_unlock; | |
17035 | + } | |
17036 | + | |
17037 | + h_file = ERR_PTR(-ENOENT); | |
17038 | + br = au_sbr(sb, wbi); | |
17039 | + if (!au_br_writable(br->br_perm)) { | |
17040 | + if (arg) | |
17041 | + goto out_unlock; | |
17042 | + | |
17043 | + bindex = wbi + 1; | |
17044 | + wbi = -1; | |
17045 | + for (; bindex <= bend; bindex++) { | |
17046 | + br = au_sbr(sb, bindex); | |
17047 | + if (au_br_writable(br->br_perm)) { | |
4a4d8108 | 17048 | + wbi = bindex; |
1e00d052 | 17049 | + br = au_sbr(sb, wbi); |
4a4d8108 AM |
17050 | + break; |
17051 | + } | |
17052 | + } | |
4a4d8108 AM |
17053 | + } |
17054 | + AuDbg("wbi %d\n", wbi); | |
1e00d052 | 17055 | + if (wbi >= 0) |
392086de AM |
17056 | + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL, |
17057 | + /*force_wr*/0); | |
1e00d052 AM |
17058 | + |
17059 | +out_unlock: | |
4a4d8108 AM |
17060 | + aufs_read_unlock(root, AuLock_IR); |
17061 | + err = PTR_ERR(h_file); | |
17062 | + if (IS_ERR(h_file)) | |
17063 | + goto out_fd; | |
17064 | + | |
1e00d052 | 17065 | + atomic_dec(&br->br_count); /* cf. au_h_open() */ |
4a4d8108 AM |
17066 | + fd_install(fd, h_file); |
17067 | + err = fd; | |
17068 | + goto out; /* success */ | |
17069 | + | |
4f0767ce | 17070 | +out_fd: |
4a4d8108 | 17071 | + put_unused_fd(fd); |
4f0767ce | 17072 | +out: |
1e00d052 | 17073 | + AuTraceErr(err); |
4a4d8108 AM |
17074 | + return err; |
17075 | +} | |
17076 | + | |
17077 | +/* ---------------------------------------------------------------------- */ | |
17078 | + | |
17079 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg) | |
17080 | +{ | |
17081 | + long err; | |
c1595e42 | 17082 | + struct dentry *dentry; |
4a4d8108 AM |
17083 | + |
17084 | + switch (cmd) { | |
4a4d8108 AM |
17085 | + case AUFS_CTL_RDU: |
17086 | + case AUFS_CTL_RDU_INO: | |
17087 | + err = au_rdu_ioctl(file, cmd, arg); | |
17088 | + break; | |
17089 | + | |
17090 | + case AUFS_CTL_WBR_FD: | |
1e00d052 | 17091 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17092 | + break; |
17093 | + | |
027c5e7a AM |
17094 | + case AUFS_CTL_IBUSY: |
17095 | + err = au_ibusy_ioctl(file, arg); | |
17096 | + break; | |
17097 | + | |
076b876e AM |
17098 | + case AUFS_CTL_BRINFO: |
17099 | + err = au_brinfo_ioctl(file, arg); | |
17100 | + break; | |
17101 | + | |
17102 | + case AUFS_CTL_FHSM_FD: | |
2000de60 | 17103 | + dentry = file->f_path.dentry; |
c1595e42 JR |
17104 | + if (IS_ROOT(dentry)) |
17105 | + err = au_fhsm_fd(dentry->d_sb, arg); | |
17106 | + else | |
17107 | + err = -ENOTTY; | |
076b876e AM |
17108 | + break; |
17109 | + | |
4a4d8108 AM |
17110 | + default: |
17111 | + /* do not call the lower */ | |
17112 | + AuDbg("0x%x\n", cmd); | |
17113 | + err = -ENOTTY; | |
17114 | + } | |
17115 | + | |
17116 | + AuTraceErr(err); | |
17117 | + return err; | |
17118 | +} | |
17119 | + | |
17120 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg) | |
17121 | +{ | |
17122 | + long err; | |
17123 | + | |
17124 | + switch (cmd) { | |
c2b27bf2 | 17125 | + case AUFS_CTL_MVDOWN: |
2000de60 | 17126 | + err = au_mvdown(file->f_path.dentry, (void __user *)arg); |
c2b27bf2 AM |
17127 | + break; |
17128 | + | |
4a4d8108 | 17129 | + case AUFS_CTL_WBR_FD: |
1e00d052 | 17130 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17131 | + break; |
17132 | + | |
17133 | + default: | |
17134 | + /* do not call the lower */ | |
17135 | + AuDbg("0x%x\n", cmd); | |
17136 | + err = -ENOTTY; | |
17137 | + } | |
17138 | + | |
17139 | + AuTraceErr(err); | |
17140 | + return err; | |
17141 | +} | |
b752ccd1 AM |
17142 | + |
17143 | +#ifdef CONFIG_COMPAT | |
17144 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
17145 | + unsigned long arg) | |
17146 | +{ | |
17147 | + long err; | |
17148 | + | |
17149 | + switch (cmd) { | |
17150 | + case AUFS_CTL_RDU: | |
17151 | + case AUFS_CTL_RDU_INO: | |
17152 | + err = au_rdu_compat_ioctl(file, cmd, arg); | |
17153 | + break; | |
17154 | + | |
027c5e7a AM |
17155 | + case AUFS_CTL_IBUSY: |
17156 | + err = au_ibusy_compat_ioctl(file, arg); | |
17157 | + break; | |
17158 | + | |
076b876e AM |
17159 | + case AUFS_CTL_BRINFO: |
17160 | + err = au_brinfo_compat_ioctl(file, arg); | |
17161 | + break; | |
17162 | + | |
b752ccd1 AM |
17163 | + default: |
17164 | + err = aufs_ioctl_dir(file, cmd, arg); | |
17165 | + } | |
17166 | + | |
17167 | + AuTraceErr(err); | |
17168 | + return err; | |
17169 | +} | |
17170 | + | |
b752ccd1 AM |
17171 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
17172 | + unsigned long arg) | |
17173 | +{ | |
17174 | + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg)); | |
17175 | +} | |
17176 | +#endif | |
7f207e10 AM |
17177 | diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c |
17178 | --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
17179 | +++ linux/fs/aufs/i_op_add.c 2015-06-28 17:36:09.025073697 +0200 |
17180 | @@ -0,0 +1,932 @@ | |
4a4d8108 | 17181 | +/* |
2000de60 | 17182 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
17183 | + * |
17184 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17185 | + * it under the terms of the GNU General Public License as published by | |
17186 | + * the Free Software Foundation; either version 2 of the License, or | |
17187 | + * (at your option) any later version. | |
17188 | + * | |
17189 | + * This program is distributed in the hope that it will be useful, | |
17190 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17191 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17192 | + * GNU General Public License for more details. | |
17193 | + * | |
17194 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17195 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
17196 | + */ |
17197 | + | |
17198 | +/* | |
17199 | + * inode operations (add entry) | |
17200 | + */ | |
17201 | + | |
17202 | +#include "aufs.h" | |
17203 | + | |
17204 | +/* | |
17205 | + * final procedure of adding a new entry, except link(2). | |
17206 | + * remove whiteout, instantiate, copyup the parent dir's times and size | |
17207 | + * and update version. | |
17208 | + * if it failed, re-create the removed whiteout. | |
17209 | + */ | |
17210 | +static int epilog(struct inode *dir, aufs_bindex_t bindex, | |
17211 | + struct dentry *wh_dentry, struct dentry *dentry) | |
17212 | +{ | |
17213 | + int err, rerr; | |
17214 | + aufs_bindex_t bwh; | |
17215 | + struct path h_path; | |
076b876e | 17216 | + struct super_block *sb; |
4a4d8108 AM |
17217 | + struct inode *inode, *h_dir; |
17218 | + struct dentry *wh; | |
17219 | + | |
17220 | + bwh = -1; | |
076b876e | 17221 | + sb = dir->i_sb; |
4a4d8108 | 17222 | + if (wh_dentry) { |
5527c038 | 17223 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
4a4d8108 AM |
17224 | + IMustLock(h_dir); |
17225 | + AuDebugOn(au_h_iptr(dir, bindex) != h_dir); | |
17226 | + bwh = au_dbwh(dentry); | |
17227 | + h_path.dentry = wh_dentry; | |
076b876e | 17228 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
4a4d8108 AM |
17229 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, |
17230 | + dentry); | |
17231 | + if (unlikely(err)) | |
17232 | + goto out; | |
17233 | + } | |
17234 | + | |
17235 | + inode = au_new_inode(dentry, /*must_new*/1); | |
17236 | + if (!IS_ERR(inode)) { | |
17237 | + d_instantiate(dentry, inode); | |
5527c038 | 17238 | + dir = d_inode(dentry->d_parent); /* dir inode is locked */ |
4a4d8108 | 17239 | + IMustLock(dir); |
b912730e | 17240 | + au_dir_ts(dir, bindex); |
4a4d8108 | 17241 | + dir->i_version++; |
076b876e | 17242 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
4a4d8108 AM |
17243 | + return 0; /* success */ |
17244 | + } | |
17245 | + | |
17246 | + err = PTR_ERR(inode); | |
17247 | + if (!wh_dentry) | |
17248 | + goto out; | |
17249 | + | |
17250 | + /* revert */ | |
17251 | + /* dir inode is locked */ | |
17252 | + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent); | |
17253 | + rerr = PTR_ERR(wh); | |
17254 | + if (IS_ERR(wh)) { | |
523b37e3 AM |
17255 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", |
17256 | + dentry, err, rerr); | |
4a4d8108 AM |
17257 | + err = -EIO; |
17258 | + } else | |
17259 | + dput(wh); | |
17260 | + | |
4f0767ce | 17261 | +out: |
4a4d8108 AM |
17262 | + return err; |
17263 | +} | |
17264 | + | |
027c5e7a AM |
17265 | +static int au_d_may_add(struct dentry *dentry) |
17266 | +{ | |
17267 | + int err; | |
17268 | + | |
17269 | + err = 0; | |
17270 | + if (unlikely(d_unhashed(dentry))) | |
17271 | + err = -ENOENT; | |
5527c038 | 17272 | + if (unlikely(d_really_is_positive(dentry))) |
027c5e7a AM |
17273 | + err = -EEXIST; |
17274 | + return err; | |
17275 | +} | |
17276 | + | |
4a4d8108 AM |
17277 | +/* |
17278 | + * simple tests for the adding inode operations. | |
17279 | + * following the checks in vfs, plus the parent-child relationship. | |
17280 | + */ | |
17281 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
17282 | + struct dentry *h_parent, int isdir) | |
17283 | +{ | |
17284 | + int err; | |
17285 | + umode_t h_mode; | |
17286 | + struct dentry *h_dentry; | |
17287 | + struct inode *h_inode; | |
17288 | + | |
17289 | + err = -ENAMETOOLONG; | |
17290 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17291 | + goto out; | |
17292 | + | |
17293 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 17294 | + if (d_really_is_negative(dentry)) { |
4a4d8108 | 17295 | + err = -EEXIST; |
5527c038 | 17296 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
17297 | + goto out; |
17298 | + } else { | |
17299 | + /* rename(2) case */ | |
17300 | + err = -EIO; | |
5527c038 JR |
17301 | + if (unlikely(d_is_negative(h_dentry))) |
17302 | + goto out; | |
17303 | + h_inode = d_inode(h_dentry); | |
17304 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 AM |
17305 | + goto out; |
17306 | + | |
17307 | + h_mode = h_inode->i_mode; | |
17308 | + if (!isdir) { | |
17309 | + err = -EISDIR; | |
17310 | + if (unlikely(S_ISDIR(h_mode))) | |
17311 | + goto out; | |
17312 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
17313 | + err = -ENOTDIR; | |
17314 | + goto out; | |
17315 | + } | |
17316 | + } | |
17317 | + | |
17318 | + err = 0; | |
17319 | + /* expected parent dir is locked */ | |
17320 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
17321 | + err = -EIO; | |
17322 | + | |
4f0767ce | 17323 | +out: |
4a4d8108 AM |
17324 | + AuTraceErr(err); |
17325 | + return err; | |
17326 | +} | |
17327 | + | |
17328 | +/* | |
17329 | + * initial procedure of adding a new entry. | |
17330 | + * prepare writable branch and the parent dir, lock it, | |
17331 | + * and lookup whiteout for the new entry. | |
17332 | + */ | |
17333 | +static struct dentry* | |
17334 | +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt, | |
17335 | + struct dentry *src_dentry, struct au_pin *pin, | |
17336 | + struct au_wr_dir_args *wr_dir_args) | |
17337 | +{ | |
17338 | + struct dentry *wh_dentry, *h_parent; | |
17339 | + struct super_block *sb; | |
17340 | + struct au_branch *br; | |
17341 | + int err; | |
17342 | + unsigned int udba; | |
17343 | + aufs_bindex_t bcpup; | |
17344 | + | |
523b37e3 | 17345 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17346 | + |
17347 | + err = au_wr_dir(dentry, src_dentry, wr_dir_args); | |
17348 | + bcpup = err; | |
17349 | + wh_dentry = ERR_PTR(err); | |
17350 | + if (unlikely(err < 0)) | |
17351 | + goto out; | |
17352 | + | |
17353 | + sb = dentry->d_sb; | |
17354 | + udba = au_opt_udba(sb); | |
17355 | + err = au_pin(pin, dentry, bcpup, udba, | |
17356 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17357 | + wh_dentry = ERR_PTR(err); | |
17358 | + if (unlikely(err)) | |
17359 | + goto out; | |
17360 | + | |
17361 | + h_parent = au_pinned_h_parent(pin); | |
17362 | + if (udba != AuOpt_UDBA_NONE | |
17363 | + && au_dbstart(dentry) == bcpup) | |
17364 | + err = au_may_add(dentry, bcpup, h_parent, | |
17365 | + au_ftest_wrdir(wr_dir_args->flags, ISDIR)); | |
17366 | + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17367 | + err = -ENAMETOOLONG; | |
17368 | + wh_dentry = ERR_PTR(err); | |
17369 | + if (unlikely(err)) | |
17370 | + goto out_unpin; | |
17371 | + | |
17372 | + br = au_sbr(sb, bcpup); | |
17373 | + if (dt) { | |
17374 | + struct path tmp = { | |
17375 | + .dentry = h_parent, | |
86dc4139 | 17376 | + .mnt = au_br_mnt(br) |
4a4d8108 AM |
17377 | + }; |
17378 | + au_dtime_store(dt, au_pinned_parent(pin), &tmp); | |
17379 | + } | |
17380 | + | |
17381 | + wh_dentry = NULL; | |
17382 | + if (bcpup != au_dbwh(dentry)) | |
17383 | + goto out; /* success */ | |
17384 | + | |
2000de60 JR |
17385 | + /* |
17386 | + * ENAMETOOLONG here means that if we allowed create such name, then it | |
17387 | + * would not be able to removed in the future. So we don't allow such | |
17388 | + * name here and we don't handle ENAMETOOLONG differently here. | |
17389 | + */ | |
4a4d8108 AM |
17390 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br); |
17391 | + | |
4f0767ce | 17392 | +out_unpin: |
4a4d8108 AM |
17393 | + if (IS_ERR(wh_dentry)) |
17394 | + au_unpin(pin); | |
4f0767ce | 17395 | +out: |
4a4d8108 AM |
17396 | + return wh_dentry; |
17397 | +} | |
17398 | + | |
17399 | +/* ---------------------------------------------------------------------- */ | |
17400 | + | |
17401 | +enum { Mknod, Symlink, Creat }; | |
17402 | +struct simple_arg { | |
17403 | + int type; | |
17404 | + union { | |
17405 | + struct { | |
b912730e AM |
17406 | + umode_t mode; |
17407 | + bool want_excl; | |
17408 | + bool try_aopen; | |
17409 | + struct vfsub_aopen_args *aopen; | |
4a4d8108 AM |
17410 | + } c; |
17411 | + struct { | |
17412 | + const char *symname; | |
17413 | + } s; | |
17414 | + struct { | |
7eafdf33 | 17415 | + umode_t mode; |
4a4d8108 AM |
17416 | + dev_t dev; |
17417 | + } m; | |
17418 | + } u; | |
17419 | +}; | |
17420 | + | |
17421 | +static int add_simple(struct inode *dir, struct dentry *dentry, | |
17422 | + struct simple_arg *arg) | |
17423 | +{ | |
076b876e | 17424 | + int err, rerr; |
4a4d8108 AM |
17425 | + aufs_bindex_t bstart; |
17426 | + unsigned char created; | |
b912730e AM |
17427 | + const unsigned char try_aopen |
17428 | + = (arg->type == Creat && arg->u.c.try_aopen); | |
4a4d8108 AM |
17429 | + struct dentry *wh_dentry, *parent; |
17430 | + struct inode *h_dir; | |
b912730e AM |
17431 | + struct super_block *sb; |
17432 | + struct au_branch *br; | |
c2b27bf2 AM |
17433 | + /* to reuduce stack size */ |
17434 | + struct { | |
17435 | + struct au_dtime dt; | |
17436 | + struct au_pin pin; | |
17437 | + struct path h_path; | |
17438 | + struct au_wr_dir_args wr_dir_args; | |
17439 | + } *a; | |
4a4d8108 | 17440 | + |
523b37e3 | 17441 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17442 | + IMustLock(dir); |
17443 | + | |
c2b27bf2 AM |
17444 | + err = -ENOMEM; |
17445 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
17446 | + if (unlikely(!a)) | |
17447 | + goto out; | |
17448 | + a->wr_dir_args.force_btgt = -1; | |
17449 | + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY; | |
17450 | + | |
4a4d8108 | 17451 | + parent = dentry->d_parent; /* dir inode is locked */ |
b912730e AM |
17452 | + if (!try_aopen) { |
17453 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); | |
17454 | + if (unlikely(err)) | |
17455 | + goto out_free; | |
17456 | + } | |
027c5e7a AM |
17457 | + err = au_d_may_add(dentry); |
17458 | + if (unlikely(err)) | |
17459 | + goto out_unlock; | |
b912730e AM |
17460 | + if (!try_aopen) |
17461 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
17462 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, |
17463 | + &a->pin, &a->wr_dir_args); | |
4a4d8108 AM |
17464 | + err = PTR_ERR(wh_dentry); |
17465 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 17466 | + goto out_parent; |
4a4d8108 AM |
17467 | + |
17468 | + bstart = au_dbstart(dentry); | |
b912730e AM |
17469 | + sb = dentry->d_sb; |
17470 | + br = au_sbr(sb, bstart); | |
c2b27bf2 | 17471 | + a->h_path.dentry = au_h_dptr(dentry, bstart); |
b912730e | 17472 | + a->h_path.mnt = au_br_mnt(br); |
c2b27bf2 | 17473 | + h_dir = au_pinned_h_dir(&a->pin); |
4a4d8108 AM |
17474 | + switch (arg->type) { |
17475 | + case Creat: | |
b912730e AM |
17476 | + err = 0; |
17477 | + if (!try_aopen || !h_dir->i_op->atomic_open) | |
17478 | + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode, | |
17479 | + arg->u.c.want_excl); | |
17480 | + else | |
17481 | + err = vfsub_atomic_open(h_dir, a->h_path.dentry, | |
17482 | + arg->u.c.aopen, br); | |
4a4d8108 AM |
17483 | + break; |
17484 | + case Symlink: | |
c2b27bf2 | 17485 | + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname); |
4a4d8108 AM |
17486 | + break; |
17487 | + case Mknod: | |
c2b27bf2 AM |
17488 | + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode, |
17489 | + arg->u.m.dev); | |
4a4d8108 AM |
17490 | + break; |
17491 | + default: | |
17492 | + BUG(); | |
17493 | + } | |
17494 | + created = !err; | |
17495 | + if (!err) | |
17496 | + err = epilog(dir, bstart, wh_dentry, dentry); | |
17497 | + | |
17498 | + /* revert */ | |
5527c038 | 17499 | + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) { |
523b37e3 AM |
17500 | + /* no delegation since it is just created */ |
17501 | + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL, | |
17502 | + /*force*/0); | |
4a4d8108 | 17503 | + if (rerr) { |
523b37e3 AM |
17504 | + AuIOErr("%pd revert failure(%d, %d)\n", |
17505 | + dentry, err, rerr); | |
4a4d8108 AM |
17506 | + err = -EIO; |
17507 | + } | |
c2b27bf2 | 17508 | + au_dtime_revert(&a->dt); |
4a4d8108 AM |
17509 | + } |
17510 | + | |
b912730e AM |
17511 | + if (!err && try_aopen && !h_dir->i_op->atomic_open) |
17512 | + *arg->u.c.aopen->opened |= FILE_CREATED; | |
17513 | + | |
c2b27bf2 | 17514 | + au_unpin(&a->pin); |
4a4d8108 AM |
17515 | + dput(wh_dentry); |
17516 | + | |
027c5e7a | 17517 | +out_parent: |
b912730e AM |
17518 | + if (!try_aopen) |
17519 | + di_write_unlock(parent); | |
027c5e7a | 17520 | +out_unlock: |
4a4d8108 AM |
17521 | + if (unlikely(err)) { |
17522 | + au_update_dbstart(dentry); | |
17523 | + d_drop(dentry); | |
17524 | + } | |
b912730e AM |
17525 | + if (!try_aopen) |
17526 | + aufs_read_unlock(dentry, AuLock_DW); | |
c2b27bf2 AM |
17527 | +out_free: |
17528 | + kfree(a); | |
027c5e7a | 17529 | +out: |
4a4d8108 AM |
17530 | + return err; |
17531 | +} | |
17532 | + | |
7eafdf33 AM |
17533 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
17534 | + dev_t dev) | |
4a4d8108 AM |
17535 | +{ |
17536 | + struct simple_arg arg = { | |
17537 | + .type = Mknod, | |
17538 | + .u.m = { | |
17539 | + .mode = mode, | |
17540 | + .dev = dev | |
17541 | + } | |
17542 | + }; | |
17543 | + return add_simple(dir, dentry, &arg); | |
17544 | +} | |
17545 | + | |
17546 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |
17547 | +{ | |
17548 | + struct simple_arg arg = { | |
17549 | + .type = Symlink, | |
17550 | + .u.s.symname = symname | |
17551 | + }; | |
17552 | + return add_simple(dir, dentry, &arg); | |
17553 | +} | |
17554 | + | |
7eafdf33 | 17555 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 17556 | + bool want_excl) |
4a4d8108 AM |
17557 | +{ |
17558 | + struct simple_arg arg = { | |
17559 | + .type = Creat, | |
17560 | + .u.c = { | |
b4510431 AM |
17561 | + .mode = mode, |
17562 | + .want_excl = want_excl | |
4a4d8108 AM |
17563 | + } |
17564 | + }; | |
17565 | + return add_simple(dir, dentry, &arg); | |
17566 | +} | |
17567 | + | |
b912730e AM |
17568 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, |
17569 | + struct vfsub_aopen_args *aopen_args) | |
17570 | +{ | |
17571 | + struct simple_arg arg = { | |
17572 | + .type = Creat, | |
17573 | + .u.c = { | |
17574 | + .mode = aopen_args->create_mode, | |
17575 | + .want_excl = aopen_args->open_flag & O_EXCL, | |
17576 | + .try_aopen = true, | |
17577 | + .aopen = aopen_args | |
17578 | + } | |
17579 | + }; | |
17580 | + return add_simple(dir, dentry, &arg); | |
17581 | +} | |
17582 | + | |
38d290e6 JR |
17583 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
17584 | +{ | |
17585 | + int err; | |
17586 | + aufs_bindex_t bindex; | |
17587 | + struct super_block *sb; | |
17588 | + struct dentry *parent, *h_parent, *h_dentry; | |
17589 | + struct inode *h_dir, *inode; | |
17590 | + struct vfsmount *h_mnt; | |
17591 | + struct au_wr_dir_args wr_dir_args = { | |
17592 | + .force_btgt = -1, | |
17593 | + .flags = AuWrDir_TMPFILE | |
17594 | + }; | |
17595 | + | |
17596 | + /* copy-up may happen */ | |
17597 | + mutex_lock(&dir->i_mutex); | |
17598 | + | |
17599 | + sb = dir->i_sb; | |
17600 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
17601 | + if (unlikely(err)) | |
17602 | + goto out; | |
17603 | + | |
17604 | + err = au_di_init(dentry); | |
17605 | + if (unlikely(err)) | |
17606 | + goto out_si; | |
17607 | + | |
17608 | + err = -EBUSY; | |
17609 | + parent = d_find_any_alias(dir); | |
17610 | + AuDebugOn(!parent); | |
17611 | + di_write_lock_parent(parent); | |
5527c038 | 17612 | + if (unlikely(d_inode(parent) != dir)) |
38d290e6 JR |
17613 | + goto out_parent; |
17614 | + | |
17615 | + err = au_digen_test(parent, au_sigen(sb)); | |
17616 | + if (unlikely(err)) | |
17617 | + goto out_parent; | |
17618 | + | |
17619 | + bindex = au_dbstart(parent); | |
17620 | + au_set_dbstart(dentry, bindex); | |
17621 | + au_set_dbend(dentry, bindex); | |
17622 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); | |
17623 | + bindex = err; | |
17624 | + if (unlikely(err < 0)) | |
17625 | + goto out_parent; | |
17626 | + | |
17627 | + err = -EOPNOTSUPP; | |
17628 | + h_dir = au_h_iptr(dir, bindex); | |
17629 | + if (unlikely(!h_dir->i_op->tmpfile)) | |
17630 | + goto out_parent; | |
17631 | + | |
17632 | + h_mnt = au_sbr_mnt(sb, bindex); | |
17633 | + err = vfsub_mnt_want_write(h_mnt); | |
17634 | + if (unlikely(err)) | |
17635 | + goto out_parent; | |
17636 | + | |
17637 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 17638 | + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC); |
38d290e6 JR |
17639 | + if (unlikely(err)) |
17640 | + goto out_mnt; | |
17641 | + | |
17642 | + err = -ENOMEM; | |
17643 | + h_dentry = d_alloc(h_parent, &dentry->d_name); | |
17644 | + if (unlikely(!h_dentry)) | |
17645 | + goto out_mnt; | |
17646 | + | |
17647 | + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode); | |
17648 | + if (unlikely(err)) | |
17649 | + goto out_dentry; | |
17650 | + | |
17651 | + au_set_dbstart(dentry, bindex); | |
17652 | + au_set_dbend(dentry, bindex); | |
17653 | + au_set_h_dptr(dentry, bindex, dget(h_dentry)); | |
17654 | + inode = au_new_inode(dentry, /*must_new*/1); | |
17655 | + if (IS_ERR(inode)) { | |
17656 | + err = PTR_ERR(inode); | |
17657 | + au_set_h_dptr(dentry, bindex, NULL); | |
17658 | + au_set_dbstart(dentry, -1); | |
17659 | + au_set_dbend(dentry, -1); | |
17660 | + } else { | |
17661 | + if (!inode->i_nlink) | |
17662 | + set_nlink(inode, 1); | |
17663 | + d_tmpfile(dentry, inode); | |
17664 | + au_di(dentry)->di_tmpfile = 1; | |
17665 | + | |
17666 | + /* update without i_mutex */ | |
17667 | + if (au_ibstart(dir) == au_dbstart(dentry)) | |
17668 | + au_cpup_attr_timesizes(dir); | |
17669 | + } | |
17670 | + | |
17671 | +out_dentry: | |
17672 | + dput(h_dentry); | |
17673 | +out_mnt: | |
17674 | + vfsub_mnt_drop_write(h_mnt); | |
17675 | +out_parent: | |
17676 | + di_write_unlock(parent); | |
17677 | + dput(parent); | |
17678 | + di_write_unlock(dentry); | |
17679 | + if (!err) | |
17680 | +#if 0 | |
17681 | + /* verbose coding for lock class name */ | |
17682 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
17683 | + au_lc_key + AuLcNonDir_DIINFO); | |
17684 | +#else | |
17685 | + ; | |
17686 | +#endif | |
17687 | + else { | |
17688 | + au_di_fin(dentry); | |
17689 | + dentry->d_fsdata = NULL; | |
17690 | + } | |
17691 | +out_si: | |
17692 | + si_read_unlock(sb); | |
17693 | +out: | |
17694 | + mutex_unlock(&dir->i_mutex); | |
17695 | + return err; | |
17696 | +} | |
17697 | + | |
4a4d8108 AM |
17698 | +/* ---------------------------------------------------------------------- */ |
17699 | + | |
17700 | +struct au_link_args { | |
17701 | + aufs_bindex_t bdst, bsrc; | |
17702 | + struct au_pin pin; | |
17703 | + struct path h_path; | |
17704 | + struct dentry *src_parent, *parent; | |
17705 | +}; | |
17706 | + | |
17707 | +static int au_cpup_before_link(struct dentry *src_dentry, | |
17708 | + struct au_link_args *a) | |
17709 | +{ | |
17710 | + int err; | |
17711 | + struct dentry *h_src_dentry; | |
c2b27bf2 AM |
17712 | + struct au_cp_generic cpg = { |
17713 | + .dentry = src_dentry, | |
17714 | + .bdst = a->bdst, | |
17715 | + .bsrc = a->bsrc, | |
17716 | + .len = -1, | |
17717 | + .pin = &a->pin, | |
17718 | + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */ | |
17719 | + }; | |
4a4d8108 AM |
17720 | + |
17721 | + di_read_lock_parent(a->src_parent, AuLock_IR); | |
17722 | + err = au_test_and_cpup_dirs(src_dentry, a->bdst); | |
17723 | + if (unlikely(err)) | |
17724 | + goto out; | |
17725 | + | |
17726 | + h_src_dentry = au_h_dptr(src_dentry, a->bsrc); | |
4a4d8108 AM |
17727 | + err = au_pin(&a->pin, src_dentry, a->bdst, |
17728 | + au_opt_udba(src_dentry->d_sb), | |
17729 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17730 | + if (unlikely(err)) | |
17731 | + goto out; | |
367653fa | 17732 | + |
c2b27bf2 | 17733 | + err = au_sio_cpup_simple(&cpg); |
4a4d8108 AM |
17734 | + au_unpin(&a->pin); |
17735 | + | |
4f0767ce | 17736 | +out: |
4a4d8108 AM |
17737 | + di_read_unlock(a->src_parent, AuLock_IR); |
17738 | + return err; | |
17739 | +} | |
17740 | + | |
86dc4139 AM |
17741 | +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry, |
17742 | + struct au_link_args *a) | |
4a4d8108 AM |
17743 | +{ |
17744 | + int err; | |
17745 | + unsigned char plink; | |
86dc4139 | 17746 | + aufs_bindex_t bend; |
4a4d8108 | 17747 | + struct dentry *h_src_dentry; |
523b37e3 | 17748 | + struct inode *h_inode, *inode, *delegated; |
4a4d8108 AM |
17749 | + struct super_block *sb; |
17750 | + struct file *h_file; | |
17751 | + | |
17752 | + plink = 0; | |
17753 | + h_inode = NULL; | |
17754 | + sb = src_dentry->d_sb; | |
5527c038 | 17755 | + inode = d_inode(src_dentry); |
4a4d8108 AM |
17756 | + if (au_ibstart(inode) <= a->bdst) |
17757 | + h_inode = au_h_iptr(inode, a->bdst); | |
17758 | + if (!h_inode || !h_inode->i_nlink) { | |
17759 | + /* copyup src_dentry as the name of dentry. */ | |
86dc4139 AM |
17760 | + bend = au_dbend(dentry); |
17761 | + if (bend < a->bsrc) | |
17762 | + au_set_dbend(dentry, a->bsrc); | |
17763 | + au_set_h_dptr(dentry, a->bsrc, | |
17764 | + dget(au_h_dptr(src_dentry, a->bsrc))); | |
17765 | + dget(a->h_path.dentry); | |
17766 | + au_set_h_dptr(dentry, a->bdst, NULL); | |
c1595e42 JR |
17767 | + AuDbg("temporary d_inode...\n"); |
17768 | + spin_lock(&dentry->d_lock); | |
5527c038 | 17769 | + dentry->d_inode = d_inode(src_dentry); /* tmp */ |
c1595e42 | 17770 | + spin_unlock(&dentry->d_lock); |
392086de | 17771 | + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0); |
86dc4139 | 17772 | + if (IS_ERR(h_file)) |
4a4d8108 | 17773 | + err = PTR_ERR(h_file); |
86dc4139 | 17774 | + else { |
c2b27bf2 AM |
17775 | + struct au_cp_generic cpg = { |
17776 | + .dentry = dentry, | |
17777 | + .bdst = a->bdst, | |
17778 | + .bsrc = -1, | |
17779 | + .len = -1, | |
17780 | + .pin = &a->pin, | |
17781 | + .flags = AuCpup_KEEPLINO | |
17782 | + }; | |
17783 | + err = au_sio_cpup_simple(&cpg); | |
86dc4139 AM |
17784 | + au_h_open_post(dentry, a->bsrc, h_file); |
17785 | + if (!err) { | |
17786 | + dput(a->h_path.dentry); | |
17787 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
17788 | + } else | |
17789 | + au_set_h_dptr(dentry, a->bdst, | |
17790 | + a->h_path.dentry); | |
17791 | + } | |
c1595e42 | 17792 | + spin_lock(&dentry->d_lock); |
86dc4139 | 17793 | + dentry->d_inode = NULL; /* restore */ |
c1595e42 JR |
17794 | + spin_unlock(&dentry->d_lock); |
17795 | + AuDbg("temporary d_inode...done\n"); | |
86dc4139 AM |
17796 | + au_set_h_dptr(dentry, a->bsrc, NULL); |
17797 | + au_set_dbend(dentry, bend); | |
4a4d8108 AM |
17798 | + } else { |
17799 | + /* the inode of src_dentry already exists on a.bdst branch */ | |
17800 | + h_src_dentry = d_find_alias(h_inode); | |
17801 | + if (!h_src_dentry && au_plink_test(inode)) { | |
17802 | + plink = 1; | |
17803 | + h_src_dentry = au_plink_lkup(inode, a->bdst); | |
17804 | + err = PTR_ERR(h_src_dentry); | |
17805 | + if (IS_ERR(h_src_dentry)) | |
17806 | + goto out; | |
17807 | + | |
5527c038 | 17808 | + if (unlikely(d_is_negative(h_src_dentry))) { |
4a4d8108 AM |
17809 | + dput(h_src_dentry); |
17810 | + h_src_dentry = NULL; | |
17811 | + } | |
17812 | + | |
17813 | + } | |
17814 | + if (h_src_dentry) { | |
523b37e3 | 17815 | + delegated = NULL; |
4a4d8108 | 17816 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
17817 | + &a->h_path, &delegated); |
17818 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17819 | + pr_warn("cannot retry for NFSv4 delegation" | |
17820 | + " for an internal link\n"); | |
17821 | + iput(delegated); | |
17822 | + } | |
4a4d8108 AM |
17823 | + dput(h_src_dentry); |
17824 | + } else { | |
17825 | + AuIOErr("no dentry found for hi%lu on b%d\n", | |
17826 | + h_inode->i_ino, a->bdst); | |
17827 | + err = -EIO; | |
17828 | + } | |
17829 | + } | |
17830 | + | |
17831 | + if (!err && !plink) | |
17832 | + au_plink_append(inode, a->bdst, a->h_path.dentry); | |
17833 | + | |
17834 | +out: | |
2cbb1c4b | 17835 | + AuTraceErr(err); |
4a4d8108 AM |
17836 | + return err; |
17837 | +} | |
17838 | + | |
17839 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, | |
17840 | + struct dentry *dentry) | |
17841 | +{ | |
17842 | + int err, rerr; | |
17843 | + struct au_dtime dt; | |
17844 | + struct au_link_args *a; | |
17845 | + struct dentry *wh_dentry, *h_src_dentry; | |
523b37e3 | 17846 | + struct inode *inode, *delegated; |
4a4d8108 AM |
17847 | + struct super_block *sb; |
17848 | + struct au_wr_dir_args wr_dir_args = { | |
17849 | + /* .force_btgt = -1, */ | |
17850 | + .flags = AuWrDir_ADD_ENTRY | |
17851 | + }; | |
17852 | + | |
17853 | + IMustLock(dir); | |
5527c038 | 17854 | + inode = d_inode(src_dentry); |
4a4d8108 AM |
17855 | + IMustLock(inode); |
17856 | + | |
4a4d8108 AM |
17857 | + err = -ENOMEM; |
17858 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
17859 | + if (unlikely(!a)) | |
17860 | + goto out; | |
17861 | + | |
17862 | + a->parent = dentry->d_parent; /* dir inode is locked */ | |
027c5e7a AM |
17863 | + err = aufs_read_and_write_lock2(dentry, src_dentry, |
17864 | + AuLock_NOPLM | AuLock_GEN); | |
e49829fe JR |
17865 | + if (unlikely(err)) |
17866 | + goto out_kfree; | |
38d290e6 | 17867 | + err = au_d_linkable(src_dentry); |
027c5e7a AM |
17868 | + if (unlikely(err)) |
17869 | + goto out_unlock; | |
17870 | + err = au_d_may_add(dentry); | |
17871 | + if (unlikely(err)) | |
17872 | + goto out_unlock; | |
e49829fe | 17873 | + |
4a4d8108 | 17874 | + a->src_parent = dget_parent(src_dentry); |
2cbb1c4b | 17875 | + wr_dir_args.force_btgt = au_ibstart(inode); |
4a4d8108 AM |
17876 | + |
17877 | + di_write_lock_parent(a->parent); | |
17878 | + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt); | |
17879 | + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin, | |
17880 | + &wr_dir_args); | |
17881 | + err = PTR_ERR(wh_dentry); | |
17882 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 17883 | + goto out_parent; |
4a4d8108 AM |
17884 | + |
17885 | + err = 0; | |
17886 | + sb = dentry->d_sb; | |
17887 | + a->bdst = au_dbstart(dentry); | |
17888 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
17889 | + a->h_path.mnt = au_sbr_mnt(sb, a->bdst); | |
2cbb1c4b JR |
17890 | + a->bsrc = au_ibstart(inode); |
17891 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); | |
38d290e6 JR |
17892 | + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile) |
17893 | + h_src_dentry = dget(au_hi_wh(inode, a->bsrc)); | |
2cbb1c4b JR |
17894 | + if (!h_src_dentry) { |
17895 | + a->bsrc = au_dbstart(src_dentry); | |
17896 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); | |
17897 | + AuDebugOn(!h_src_dentry); | |
38d290e6 JR |
17898 | + } else if (IS_ERR(h_src_dentry)) { |
17899 | + err = PTR_ERR(h_src_dentry); | |
2cbb1c4b | 17900 | + goto out_parent; |
38d290e6 | 17901 | + } |
2cbb1c4b | 17902 | + |
4a4d8108 AM |
17903 | + if (au_opt_test(au_mntflags(sb), PLINK)) { |
17904 | + if (a->bdst < a->bsrc | |
17905 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) | |
86dc4139 | 17906 | + err = au_cpup_or_link(src_dentry, dentry, a); |
523b37e3 AM |
17907 | + else { |
17908 | + delegated = NULL; | |
4a4d8108 | 17909 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
17910 | + &a->h_path, &delegated); |
17911 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17912 | + pr_warn("cannot retry for NFSv4 delegation" | |
17913 | + " for an internal link\n"); | |
17914 | + iput(delegated); | |
17915 | + } | |
17916 | + } | |
2cbb1c4b | 17917 | + dput(h_src_dentry); |
4a4d8108 AM |
17918 | + } else { |
17919 | + /* | |
17920 | + * copyup src_dentry to the branch we process, | |
17921 | + * and then link(2) to it. | |
17922 | + */ | |
2cbb1c4b | 17923 | + dput(h_src_dentry); |
4a4d8108 AM |
17924 | + if (a->bdst < a->bsrc |
17925 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) { | |
17926 | + au_unpin(&a->pin); | |
17927 | + di_write_unlock(a->parent); | |
17928 | + err = au_cpup_before_link(src_dentry, a); | |
17929 | + di_write_lock_parent(a->parent); | |
17930 | + if (!err) | |
17931 | + err = au_pin(&a->pin, dentry, a->bdst, | |
17932 | + au_opt_udba(sb), | |
17933 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17934 | + if (unlikely(err)) | |
17935 | + goto out_wh; | |
17936 | + } | |
17937 | + if (!err) { | |
17938 | + h_src_dentry = au_h_dptr(src_dentry, a->bdst); | |
17939 | + err = -ENOENT; | |
5527c038 | 17940 | + if (h_src_dentry && d_is_positive(h_src_dentry)) { |
523b37e3 | 17941 | + delegated = NULL; |
4a4d8108 AM |
17942 | + err = vfsub_link(h_src_dentry, |
17943 | + au_pinned_h_dir(&a->pin), | |
523b37e3 AM |
17944 | + &a->h_path, &delegated); |
17945 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17946 | + pr_warn("cannot retry" | |
17947 | + " for NFSv4 delegation" | |
17948 | + " for an internal link\n"); | |
17949 | + iput(delegated); | |
17950 | + } | |
17951 | + } | |
4a4d8108 AM |
17952 | + } |
17953 | + } | |
17954 | + if (unlikely(err)) | |
17955 | + goto out_unpin; | |
17956 | + | |
17957 | + if (wh_dentry) { | |
17958 | + a->h_path.dentry = wh_dentry; | |
17959 | + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path, | |
17960 | + dentry); | |
17961 | + if (unlikely(err)) | |
17962 | + goto out_revert; | |
17963 | + } | |
17964 | + | |
b912730e | 17965 | + au_dir_ts(dir, a->bdst); |
4a4d8108 | 17966 | + dir->i_version++; |
4a4d8108 AM |
17967 | + inc_nlink(inode); |
17968 | + inode->i_ctime = dir->i_ctime; | |
027c5e7a AM |
17969 | + d_instantiate(dentry, au_igrab(inode)); |
17970 | + if (d_unhashed(a->h_path.dentry)) | |
4a4d8108 AM |
17971 | + /* some filesystem calls d_drop() */ |
17972 | + d_drop(dentry); | |
076b876e AM |
17973 | + /* some filesystems consume an inode even hardlink */ |
17974 | + au_fhsm_wrote(sb, a->bdst, /*force*/0); | |
4a4d8108 AM |
17975 | + goto out_unpin; /* success */ |
17976 | + | |
4f0767ce | 17977 | +out_revert: |
523b37e3 AM |
17978 | + /* no delegation since it is just created */ |
17979 | + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, | |
17980 | + /*delegated*/NULL, /*force*/0); | |
027c5e7a | 17981 | + if (unlikely(rerr)) { |
523b37e3 | 17982 | + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr); |
027c5e7a AM |
17983 | + err = -EIO; |
17984 | + } | |
4a4d8108 | 17985 | + au_dtime_revert(&dt); |
4f0767ce | 17986 | +out_unpin: |
4a4d8108 | 17987 | + au_unpin(&a->pin); |
4f0767ce | 17988 | +out_wh: |
4a4d8108 | 17989 | + dput(wh_dentry); |
027c5e7a AM |
17990 | +out_parent: |
17991 | + di_write_unlock(a->parent); | |
17992 | + dput(a->src_parent); | |
4f0767ce | 17993 | +out_unlock: |
4a4d8108 AM |
17994 | + if (unlikely(err)) { |
17995 | + au_update_dbstart(dentry); | |
17996 | + d_drop(dentry); | |
17997 | + } | |
4a4d8108 | 17998 | + aufs_read_and_write_unlock2(dentry, src_dentry); |
e49829fe | 17999 | +out_kfree: |
4a4d8108 | 18000 | + kfree(a); |
4f0767ce | 18001 | +out: |
86dc4139 | 18002 | + AuTraceErr(err); |
4a4d8108 AM |
18003 | + return err; |
18004 | +} | |
18005 | + | |
7eafdf33 | 18006 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
4a4d8108 AM |
18007 | +{ |
18008 | + int err, rerr; | |
18009 | + aufs_bindex_t bindex; | |
18010 | + unsigned char diropq; | |
18011 | + struct path h_path; | |
18012 | + struct dentry *wh_dentry, *parent, *opq_dentry; | |
18013 | + struct mutex *h_mtx; | |
18014 | + struct super_block *sb; | |
18015 | + struct { | |
18016 | + struct au_pin pin; | |
18017 | + struct au_dtime dt; | |
18018 | + } *a; /* reduce the stack usage */ | |
18019 | + struct au_wr_dir_args wr_dir_args = { | |
18020 | + .force_btgt = -1, | |
18021 | + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR | |
18022 | + }; | |
18023 | + | |
18024 | + IMustLock(dir); | |
18025 | + | |
18026 | + err = -ENOMEM; | |
18027 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
18028 | + if (unlikely(!a)) | |
18029 | + goto out; | |
18030 | + | |
027c5e7a AM |
18031 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
18032 | + if (unlikely(err)) | |
18033 | + goto out_free; | |
18034 | + err = au_d_may_add(dentry); | |
18035 | + if (unlikely(err)) | |
18036 | + goto out_unlock; | |
18037 | + | |
4a4d8108 AM |
18038 | + parent = dentry->d_parent; /* dir inode is locked */ |
18039 | + di_write_lock_parent(parent); | |
18040 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, | |
18041 | + &a->pin, &wr_dir_args); | |
18042 | + err = PTR_ERR(wh_dentry); | |
18043 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 18044 | + goto out_parent; |
4a4d8108 AM |
18045 | + |
18046 | + sb = dentry->d_sb; | |
18047 | + bindex = au_dbstart(dentry); | |
18048 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
18049 | + h_path.mnt = au_sbr_mnt(sb, bindex); | |
18050 | + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode); | |
18051 | + if (unlikely(err)) | |
027c5e7a | 18052 | + goto out_unpin; |
4a4d8108 AM |
18053 | + |
18054 | + /* make the dir opaque */ | |
18055 | + diropq = 0; | |
5527c038 | 18056 | + h_mtx = &d_inode(h_path.dentry)->i_mutex; |
4a4d8108 AM |
18057 | + if (wh_dentry |
18058 | + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) { | |
18059 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
18060 | + opq_dentry = au_diropq_create(dentry, bindex); | |
18061 | + mutex_unlock(h_mtx); | |
18062 | + err = PTR_ERR(opq_dentry); | |
18063 | + if (IS_ERR(opq_dentry)) | |
18064 | + goto out_dir; | |
18065 | + dput(opq_dentry); | |
18066 | + diropq = 1; | |
18067 | + } | |
18068 | + | |
18069 | + err = epilog(dir, bindex, wh_dentry, dentry); | |
18070 | + if (!err) { | |
18071 | + inc_nlink(dir); | |
027c5e7a | 18072 | + goto out_unpin; /* success */ |
4a4d8108 AM |
18073 | + } |
18074 | + | |
18075 | + /* revert */ | |
18076 | + if (diropq) { | |
18077 | + AuLabel(revert opq); | |
18078 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
18079 | + rerr = au_diropq_remove(dentry, bindex); | |
18080 | + mutex_unlock(h_mtx); | |
18081 | + if (rerr) { | |
523b37e3 AM |
18082 | + AuIOErr("%pd reverting diropq failed(%d, %d)\n", |
18083 | + dentry, err, rerr); | |
4a4d8108 AM |
18084 | + err = -EIO; |
18085 | + } | |
18086 | + } | |
18087 | + | |
4f0767ce | 18088 | +out_dir: |
4a4d8108 AM |
18089 | + AuLabel(revert dir); |
18090 | + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path); | |
18091 | + if (rerr) { | |
523b37e3 AM |
18092 | + AuIOErr("%pd reverting dir failed(%d, %d)\n", |
18093 | + dentry, err, rerr); | |
4a4d8108 AM |
18094 | + err = -EIO; |
18095 | + } | |
4a4d8108 | 18096 | + au_dtime_revert(&a->dt); |
027c5e7a | 18097 | +out_unpin: |
4a4d8108 AM |
18098 | + au_unpin(&a->pin); |
18099 | + dput(wh_dentry); | |
027c5e7a AM |
18100 | +out_parent: |
18101 | + di_write_unlock(parent); | |
18102 | +out_unlock: | |
4a4d8108 AM |
18103 | + if (unlikely(err)) { |
18104 | + au_update_dbstart(dentry); | |
18105 | + d_drop(dentry); | |
18106 | + } | |
4a4d8108 | 18107 | + aufs_read_unlock(dentry, AuLock_DW); |
027c5e7a | 18108 | +out_free: |
4a4d8108 | 18109 | + kfree(a); |
4f0767ce | 18110 | +out: |
4a4d8108 AM |
18111 | + return err; |
18112 | +} | |
7f207e10 AM |
18113 | diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c |
18114 | --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
18115 | +++ linux/fs/aufs/i_op.c 2015-06-28 17:36:09.025073697 +0200 |
18116 | @@ -0,0 +1,1447 @@ | |
4a4d8108 | 18117 | +/* |
2000de60 | 18118 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
18119 | + * |
18120 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18121 | + * it under the terms of the GNU General Public License as published by | |
18122 | + * the Free Software Foundation; either version 2 of the License, or | |
18123 | + * (at your option) any later version. | |
18124 | + * | |
18125 | + * This program is distributed in the hope that it will be useful, | |
18126 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18127 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18128 | + * GNU General Public License for more details. | |
18129 | + * | |
18130 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18131 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18132 | + */ |
1facf9fc | 18133 | + |
1308ab2a | 18134 | +/* |
4a4d8108 | 18135 | + * inode operations (except add/del/rename) |
1308ab2a | 18136 | + */ |
4a4d8108 AM |
18137 | + |
18138 | +#include <linux/device_cgroup.h> | |
18139 | +#include <linux/fs_stack.h> | |
92d182d2 | 18140 | +#include <linux/mm.h> |
4a4d8108 AM |
18141 | +#include <linux/namei.h> |
18142 | +#include <linux/security.h> | |
4a4d8108 AM |
18143 | +#include "aufs.h" |
18144 | + | |
1e00d052 | 18145 | +static int h_permission(struct inode *h_inode, int mask, |
4a4d8108 | 18146 | + struct vfsmount *h_mnt, int brperm) |
1facf9fc | 18147 | +{ |
1308ab2a | 18148 | + int err; |
4a4d8108 | 18149 | + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); |
1facf9fc | 18150 | + |
4a4d8108 AM |
18151 | + err = -EACCES; |
18152 | + if ((write_mask && IS_IMMUTABLE(h_inode)) | |
18153 | + || ((mask & MAY_EXEC) | |
18154 | + && S_ISREG(h_inode->i_mode) | |
18155 | + && ((h_mnt->mnt_flags & MNT_NOEXEC) | |
18156 | + || !(h_inode->i_mode & S_IXUGO)))) | |
18157 | + goto out; | |
18158 | + | |
18159 | + /* | |
18160 | + * - skip the lower fs test in the case of write to ro branch. | |
18161 | + * - nfs dir permission write check is optimized, but a policy for | |
18162 | + * link/rename requires a real check. | |
b912730e AM |
18163 | + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.' |
18164 | + * in this case, generic_permission() returns -EOPNOTSUPP. | |
4a4d8108 AM |
18165 | + */ |
18166 | + if ((write_mask && !au_br_writable(brperm)) | |
18167 | + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode) | |
18168 | + && write_mask && !(mask & MAY_READ)) | |
18169 | + || !h_inode->i_op->permission) { | |
18170 | + /* AuLabel(generic_permission); */ | |
b912730e | 18171 | + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */ |
1e00d052 | 18172 | + err = generic_permission(h_inode, mask); |
b912730e AM |
18173 | + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode)) |
18174 | + err = h_inode->i_op->permission(h_inode, mask); | |
18175 | + AuTraceErr(err); | |
1308ab2a | 18176 | + } else { |
4a4d8108 | 18177 | + /* AuLabel(h_inode->permission); */ |
1e00d052 | 18178 | + err = h_inode->i_op->permission(h_inode, mask); |
4a4d8108 AM |
18179 | + AuTraceErr(err); |
18180 | + } | |
1facf9fc | 18181 | + |
4a4d8108 AM |
18182 | + if (!err) |
18183 | + err = devcgroup_inode_permission(h_inode, mask); | |
7f207e10 | 18184 | + if (!err) |
4a4d8108 | 18185 | + err = security_inode_permission(h_inode, mask); |
4a4d8108 AM |
18186 | + |
18187 | +#if 0 | |
18188 | + if (!err) { | |
18189 | + /* todo: do we need to call ima_path_check()? */ | |
18190 | + struct path h_path = { | |
18191 | + .dentry = | |
18192 | + .mnt = h_mnt | |
18193 | + }; | |
18194 | + err = ima_path_check(&h_path, | |
18195 | + mask & (MAY_READ | MAY_WRITE | MAY_EXEC), | |
18196 | + IMA_COUNT_LEAVE); | |
1308ab2a | 18197 | + } |
4a4d8108 | 18198 | +#endif |
dece6358 | 18199 | + |
4f0767ce | 18200 | +out: |
1308ab2a | 18201 | + return err; |
18202 | +} | |
dece6358 | 18203 | + |
1e00d052 | 18204 | +static int aufs_permission(struct inode *inode, int mask) |
1308ab2a | 18205 | +{ |
18206 | + int err; | |
4a4d8108 AM |
18207 | + aufs_bindex_t bindex, bend; |
18208 | + const unsigned char isdir = !!S_ISDIR(inode->i_mode), | |
18209 | + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); | |
18210 | + struct inode *h_inode; | |
18211 | + struct super_block *sb; | |
18212 | + struct au_branch *br; | |
1facf9fc | 18213 | + |
027c5e7a | 18214 | + /* todo: support rcu-walk? */ |
1e00d052 | 18215 | + if (mask & MAY_NOT_BLOCK) |
027c5e7a AM |
18216 | + return -ECHILD; |
18217 | + | |
4a4d8108 AM |
18218 | + sb = inode->i_sb; |
18219 | + si_read_lock(sb, AuLock_FLUSH); | |
18220 | + ii_read_lock_child(inode); | |
027c5e7a AM |
18221 | +#if 0 |
18222 | + err = au_iigen_test(inode, au_sigen(sb)); | |
18223 | + if (unlikely(err)) | |
18224 | + goto out; | |
18225 | +#endif | |
dece6358 | 18226 | + |
076b876e AM |
18227 | + if (!isdir |
18228 | + || write_mask | |
18229 | + || au_opt_test(au_mntflags(sb), DIRPERM1)) { | |
4a4d8108 AM |
18230 | + err = au_busy_or_stale(); |
18231 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
18232 | + if (unlikely(!h_inode | |
18233 | + || (h_inode->i_mode & S_IFMT) | |
18234 | + != (inode->i_mode & S_IFMT))) | |
18235 | + goto out; | |
1facf9fc | 18236 | + |
4a4d8108 AM |
18237 | + err = 0; |
18238 | + bindex = au_ibstart(inode); | |
18239 | + br = au_sbr(sb, bindex); | |
86dc4139 | 18240 | + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm); |
4a4d8108 AM |
18241 | + if (write_mask |
18242 | + && !err | |
18243 | + && !special_file(h_inode->i_mode)) { | |
18244 | + /* test whether the upper writable branch exists */ | |
18245 | + err = -EROFS; | |
18246 | + for (; bindex >= 0; bindex--) | |
18247 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
18248 | + err = 0; | |
18249 | + break; | |
18250 | + } | |
18251 | + } | |
18252 | + goto out; | |
18253 | + } | |
dece6358 | 18254 | + |
4a4d8108 | 18255 | + /* non-write to dir */ |
1308ab2a | 18256 | + err = 0; |
4a4d8108 AM |
18257 | + bend = au_ibend(inode); |
18258 | + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) { | |
18259 | + h_inode = au_h_iptr(inode, bindex); | |
18260 | + if (h_inode) { | |
18261 | + err = au_busy_or_stale(); | |
18262 | + if (unlikely(!S_ISDIR(h_inode->i_mode))) | |
18263 | + break; | |
18264 | + | |
18265 | + br = au_sbr(sb, bindex); | |
86dc4139 | 18266 | + err = h_permission(h_inode, mask, au_br_mnt(br), |
4a4d8108 AM |
18267 | + br->br_perm); |
18268 | + } | |
18269 | + } | |
1308ab2a | 18270 | + |
4f0767ce | 18271 | +out: |
4a4d8108 AM |
18272 | + ii_read_unlock(inode); |
18273 | + si_read_unlock(sb); | |
1308ab2a | 18274 | + return err; |
18275 | +} | |
18276 | + | |
4a4d8108 | 18277 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18278 | + |
4a4d8108 | 18279 | +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry, |
b4510431 | 18280 | + unsigned int flags) |
4a4d8108 AM |
18281 | +{ |
18282 | + struct dentry *ret, *parent; | |
b752ccd1 | 18283 | + struct inode *inode; |
4a4d8108 | 18284 | + struct super_block *sb; |
1716fcea | 18285 | + int err, npositive; |
dece6358 | 18286 | + |
4a4d8108 | 18287 | + IMustLock(dir); |
1308ab2a | 18288 | + |
537831f9 AM |
18289 | + /* todo: support rcu-walk? */ |
18290 | + ret = ERR_PTR(-ECHILD); | |
18291 | + if (flags & LOOKUP_RCU) | |
18292 | + goto out; | |
18293 | + | |
18294 | + ret = ERR_PTR(-ENAMETOOLONG); | |
18295 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
18296 | + goto out; | |
18297 | + | |
4a4d8108 | 18298 | + sb = dir->i_sb; |
7f207e10 AM |
18299 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
18300 | + ret = ERR_PTR(err); | |
18301 | + if (unlikely(err)) | |
18302 | + goto out; | |
18303 | + | |
4a4d8108 AM |
18304 | + err = au_di_init(dentry); |
18305 | + ret = ERR_PTR(err); | |
18306 | + if (unlikely(err)) | |
7f207e10 | 18307 | + goto out_si; |
1308ab2a | 18308 | + |
9dbd164d | 18309 | + inode = NULL; |
027c5e7a | 18310 | + npositive = 0; /* suppress a warning */ |
4a4d8108 AM |
18311 | + parent = dentry->d_parent; /* dir inode is locked */ |
18312 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a AM |
18313 | + err = au_alive_dir(parent); |
18314 | + if (!err) | |
18315 | + err = au_digen_test(parent, au_sigen(sb)); | |
18316 | + if (!err) { | |
18317 | + npositive = au_lkup_dentry(dentry, au_dbstart(parent), | |
537831f9 | 18318 | + /*type*/0); |
027c5e7a AM |
18319 | + err = npositive; |
18320 | + } | |
4a4d8108 | 18321 | + di_read_unlock(parent, AuLock_IR); |
4a4d8108 AM |
18322 | + ret = ERR_PTR(err); |
18323 | + if (unlikely(err < 0)) | |
18324 | + goto out_unlock; | |
1308ab2a | 18325 | + |
4a4d8108 | 18326 | + if (npositive) { |
b752ccd1 | 18327 | + inode = au_new_inode(dentry, /*must_new*/0); |
c1595e42 JR |
18328 | + if (IS_ERR(inode)) { |
18329 | + ret = (void *)inode; | |
18330 | + inode = NULL; | |
18331 | + goto out_unlock; | |
18332 | + } | |
9dbd164d | 18333 | + } |
4a4d8108 | 18334 | + |
c1595e42 JR |
18335 | + if (inode) |
18336 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 18337 | + ret = d_splice_alias(inode, dentry); |
537831f9 AM |
18338 | +#if 0 |
18339 | + if (unlikely(d_need_lookup(dentry))) { | |
18340 | + spin_lock(&dentry->d_lock); | |
18341 | + dentry->d_flags &= ~DCACHE_NEED_LOOKUP; | |
18342 | + spin_unlock(&dentry->d_lock); | |
18343 | + } else | |
18344 | +#endif | |
c1595e42 | 18345 | + if (inode) { |
2000de60 | 18346 | + if (!IS_ERR(ret)) { |
c1595e42 | 18347 | + iput(inode); |
2000de60 JR |
18348 | + if (ret && ret != dentry) |
18349 | + ii_write_unlock(inode); | |
18350 | + } else { | |
c1595e42 JR |
18351 | + ii_write_unlock(inode); |
18352 | + iput(inode); | |
18353 | + inode = NULL; | |
18354 | + } | |
7f207e10 | 18355 | + } |
1facf9fc | 18356 | + |
4f0767ce | 18357 | +out_unlock: |
4a4d8108 | 18358 | + di_write_unlock(dentry); |
2dfbb274 | 18359 | + if (inode) { |
1716fcea AM |
18360 | + /* verbose coding for lock class name */ |
18361 | + if (unlikely(S_ISLNK(inode->i_mode))) | |
18362 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18363 | + au_lc_key + AuLcSymlink_DIINFO); | |
18364 | + else if (unlikely(S_ISDIR(inode->i_mode))) | |
18365 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18366 | + au_lc_key + AuLcDir_DIINFO); | |
18367 | + else /* likely */ | |
18368 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18369 | + au_lc_key + AuLcNonDir_DIINFO); | |
9dbd164d | 18370 | + } |
7f207e10 | 18371 | +out_si: |
4a4d8108 | 18372 | + si_read_unlock(sb); |
7f207e10 | 18373 | +out: |
4a4d8108 AM |
18374 | + return ret; |
18375 | +} | |
1facf9fc | 18376 | + |
4a4d8108 | 18377 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18378 | + |
b912730e AM |
18379 | +struct aopen_node { |
18380 | + struct hlist_node hlist; | |
18381 | + struct file *file, *h_file; | |
18382 | +}; | |
18383 | + | |
18384 | +static int au_do_aopen(struct inode *inode, struct file *file) | |
18385 | +{ | |
18386 | + struct au_sphlhead *aopen; | |
18387 | + struct aopen_node *node; | |
18388 | + struct au_do_open_args args = { | |
18389 | + .no_lock = 1, | |
18390 | + .open = au_do_open_nondir | |
18391 | + }; | |
18392 | + | |
18393 | + aopen = &au_sbi(inode->i_sb)->si_aopen; | |
18394 | + spin_lock(&aopen->spin); | |
18395 | + hlist_for_each_entry(node, &aopen->head, hlist) | |
18396 | + if (node->file == file) { | |
18397 | + args.h_file = node->h_file; | |
18398 | + break; | |
18399 | + } | |
18400 | + spin_unlock(&aopen->spin); | |
18401 | + /* AuDebugOn(!args.h_file); */ | |
18402 | + | |
18403 | + return au_do_open(file, &args); | |
18404 | +} | |
18405 | + | |
18406 | +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry, | |
18407 | + struct file *file, unsigned int open_flag, | |
18408 | + umode_t create_mode, int *opened) | |
18409 | +{ | |
18410 | + int err, h_opened = *opened; | |
18411 | + struct dentry *parent; | |
18412 | + struct dentry *d; | |
18413 | + struct au_sphlhead *aopen; | |
18414 | + struct vfsub_aopen_args args = { | |
18415 | + .open_flag = open_flag, | |
18416 | + .create_mode = create_mode, | |
18417 | + .opened = &h_opened | |
18418 | + }; | |
18419 | + struct aopen_node aopen_node = { | |
18420 | + .file = file | |
18421 | + }; | |
18422 | + | |
18423 | + IMustLock(dir); | |
18424 | + AuDbg("open_flag 0x%x\n", open_flag); | |
18425 | + AuDbgDentry(dentry); | |
18426 | + | |
18427 | + err = 0; | |
18428 | + if (!au_di(dentry)) { | |
18429 | + d = aufs_lookup(dir, dentry, /*flags*/0); | |
18430 | + if (IS_ERR(d)) { | |
18431 | + err = PTR_ERR(d); | |
18432 | + goto out; | |
18433 | + } else if (d) { | |
18434 | + /* | |
18435 | + * obsoleted dentry found. | |
18436 | + * another error will be returned later. | |
18437 | + */ | |
18438 | + d_drop(d); | |
18439 | + dput(d); | |
18440 | + AuDbgDentry(d); | |
18441 | + } | |
18442 | + AuDbgDentry(dentry); | |
18443 | + } | |
18444 | + | |
18445 | + if (d_is_positive(dentry) | |
18446 | + || d_unhashed(dentry) | |
18447 | + || d_unlinked(dentry) | |
18448 | + || !(open_flag & O_CREAT)) | |
18449 | + goto out_no_open; | |
18450 | + | |
18451 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); | |
18452 | + if (unlikely(err)) | |
18453 | + goto out; | |
18454 | + | |
18455 | + parent = dentry->d_parent; /* dir is locked */ | |
18456 | + di_write_lock_parent(parent); | |
18457 | + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0); | |
18458 | + if (unlikely(err)) | |
18459 | + goto out_unlock; | |
18460 | + | |
18461 | + AuDbgDentry(dentry); | |
18462 | + if (d_is_positive(dentry)) | |
18463 | + goto out_unlock; | |
18464 | + | |
18465 | + args.file = get_empty_filp(); | |
18466 | + err = PTR_ERR(args.file); | |
18467 | + if (IS_ERR(args.file)) | |
18468 | + goto out_unlock; | |
18469 | + | |
18470 | + args.file->f_flags = file->f_flags; | |
18471 | + err = au_aopen_or_create(dir, dentry, &args); | |
18472 | + AuTraceErr(err); | |
18473 | + AuDbgFile(args.file); | |
18474 | + if (unlikely(err < 0)) { | |
18475 | + if (h_opened & FILE_OPENED) | |
18476 | + fput(args.file); | |
18477 | + else | |
18478 | + put_filp(args.file); | |
18479 | + goto out_unlock; | |
18480 | + } | |
18481 | + | |
18482 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
18483 | + *opened |= FILE_CREATED; | |
18484 | + if (h_opened & FILE_OPENED) | |
18485 | + aopen_node.h_file = args.file; | |
18486 | + else { | |
18487 | + put_filp(args.file); | |
18488 | + args.file = NULL; | |
18489 | + } | |
18490 | + aopen = &au_sbi(dir->i_sb)->si_aopen; | |
18491 | + au_sphl_add(&aopen_node.hlist, aopen); | |
18492 | + err = finish_open(file, dentry, au_do_aopen, opened); | |
18493 | + au_sphl_del(&aopen_node.hlist, aopen); | |
18494 | + AuTraceErr(err); | |
18495 | + AuDbgFile(file); | |
18496 | + if (aopen_node.h_file) | |
18497 | + fput(aopen_node.h_file); | |
18498 | + | |
18499 | +out_unlock: | |
18500 | + di_write_unlock(parent); | |
18501 | + aufs_read_unlock(dentry, AuLock_DW); | |
18502 | + AuDbgDentry(dentry); | |
18503 | + if (unlikely(err)) | |
18504 | + goto out; | |
18505 | +out_no_open: | |
18506 | + if (!err && !(*opened & FILE_CREATED)) { | |
18507 | + AuLabel(out_no_open); | |
18508 | + dget(dentry); | |
18509 | + err = finish_no_open(file, dentry); | |
18510 | + } | |
18511 | +out: | |
18512 | + AuDbg("%pd%s%s\n", dentry, | |
18513 | + (*opened & FILE_CREATED) ? " created" : "", | |
18514 | + (*opened & FILE_OPENED) ? " opened" : ""); | |
18515 | + AuTraceErr(err); | |
18516 | + return err; | |
18517 | +} | |
18518 | + | |
18519 | + | |
18520 | +/* ---------------------------------------------------------------------- */ | |
18521 | + | |
4a4d8108 AM |
18522 | +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent, |
18523 | + const unsigned char add_entry, aufs_bindex_t bcpup, | |
18524 | + aufs_bindex_t bstart) | |
18525 | +{ | |
18526 | + int err; | |
18527 | + struct dentry *h_parent; | |
18528 | + struct inode *h_dir; | |
1facf9fc | 18529 | + |
027c5e7a | 18530 | + if (add_entry) |
5527c038 | 18531 | + IMustLock(d_inode(parent)); |
027c5e7a | 18532 | + else |
4a4d8108 AM |
18533 | + di_write_lock_parent(parent); |
18534 | + | |
18535 | + err = 0; | |
18536 | + if (!au_h_dptr(parent, bcpup)) { | |
c2b27bf2 AM |
18537 | + if (bstart > bcpup) |
18538 | + err = au_cpup_dirs(dentry, bcpup); | |
18539 | + else if (bstart < bcpup) | |
4a4d8108 AM |
18540 | + err = au_cpdown_dirs(dentry, bcpup); |
18541 | + else | |
c2b27bf2 | 18542 | + BUG(); |
4a4d8108 | 18543 | + } |
38d290e6 | 18544 | + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) { |
4a4d8108 | 18545 | + h_parent = au_h_dptr(parent, bcpup); |
5527c038 | 18546 | + h_dir = d_inode(h_parent); |
4a4d8108 | 18547 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); |
7e9cd9fe | 18548 | + err = au_lkup_neg(dentry, bcpup, /*wh*/0); |
4a4d8108 AM |
18549 | + /* todo: no unlock here */ |
18550 | + mutex_unlock(&h_dir->i_mutex); | |
027c5e7a AM |
18551 | + |
18552 | + AuDbg("bcpup %d\n", bcpup); | |
18553 | + if (!err) { | |
5527c038 | 18554 | + if (d_really_is_negative(dentry)) |
027c5e7a | 18555 | + au_set_h_dptr(dentry, bstart, NULL); |
4a4d8108 AM |
18556 | + au_update_dbrange(dentry, /*do_put_zero*/0); |
18557 | + } | |
1308ab2a | 18558 | + } |
1facf9fc | 18559 | + |
4a4d8108 AM |
18560 | + if (!add_entry) |
18561 | + di_write_unlock(parent); | |
18562 | + if (!err) | |
18563 | + err = bcpup; /* success */ | |
1308ab2a | 18564 | + |
027c5e7a | 18565 | + AuTraceErr(err); |
4a4d8108 AM |
18566 | + return err; |
18567 | +} | |
1facf9fc | 18568 | + |
4a4d8108 AM |
18569 | +/* |
18570 | + * decide the branch and the parent dir where we will create a new entry. | |
18571 | + * returns new bindex or an error. | |
18572 | + * copyup the parent dir if needed. | |
18573 | + */ | |
18574 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
18575 | + struct au_wr_dir_args *args) | |
18576 | +{ | |
18577 | + int err; | |
392086de | 18578 | + unsigned int flags; |
4a4d8108 | 18579 | + aufs_bindex_t bcpup, bstart, src_bstart; |
86dc4139 AM |
18580 | + const unsigned char add_entry |
18581 | + = au_ftest_wrdir(args->flags, ADD_ENTRY) | |
38d290e6 | 18582 | + | au_ftest_wrdir(args->flags, TMPFILE); |
4a4d8108 AM |
18583 | + struct super_block *sb; |
18584 | + struct dentry *parent; | |
18585 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 18586 | + |
4a4d8108 AM |
18587 | + sb = dentry->d_sb; |
18588 | + sbinfo = au_sbi(sb); | |
18589 | + parent = dget_parent(dentry); | |
18590 | + bstart = au_dbstart(dentry); | |
18591 | + bcpup = bstart; | |
18592 | + if (args->force_btgt < 0) { | |
18593 | + if (src_dentry) { | |
18594 | + src_bstart = au_dbstart(src_dentry); | |
18595 | + if (src_bstart < bstart) | |
18596 | + bcpup = src_bstart; | |
18597 | + } else if (add_entry) { | |
392086de AM |
18598 | + flags = 0; |
18599 | + if (au_ftest_wrdir(args->flags, ISDIR)) | |
18600 | + au_fset_wbr(flags, DIR); | |
18601 | + err = AuWbrCreate(sbinfo, dentry, flags); | |
4a4d8108 AM |
18602 | + bcpup = err; |
18603 | + } | |
1facf9fc | 18604 | + |
5527c038 | 18605 | + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) { |
4a4d8108 AM |
18606 | + if (add_entry) |
18607 | + err = AuWbrCopyup(sbinfo, dentry); | |
18608 | + else { | |
18609 | + if (!IS_ROOT(dentry)) { | |
18610 | + di_read_lock_parent(parent, !AuLock_IR); | |
18611 | + err = AuWbrCopyup(sbinfo, dentry); | |
18612 | + di_read_unlock(parent, !AuLock_IR); | |
18613 | + } else | |
18614 | + err = AuWbrCopyup(sbinfo, dentry); | |
18615 | + } | |
18616 | + bcpup = err; | |
18617 | + if (unlikely(err < 0)) | |
18618 | + goto out; | |
18619 | + } | |
18620 | + } else { | |
18621 | + bcpup = args->force_btgt; | |
5527c038 | 18622 | + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry))); |
1308ab2a | 18623 | + } |
027c5e7a | 18624 | + |
4a4d8108 AM |
18625 | + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup); |
18626 | + err = bcpup; | |
18627 | + if (bcpup == bstart) | |
18628 | + goto out; /* success */ | |
4a4d8108 AM |
18629 | + |
18630 | + /* copyup the new parent into the branch we process */ | |
18631 | + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart); | |
027c5e7a | 18632 | + if (err >= 0) { |
5527c038 | 18633 | + if (d_really_is_negative(dentry)) { |
027c5e7a AM |
18634 | + au_set_h_dptr(dentry, bstart, NULL); |
18635 | + au_set_dbstart(dentry, bcpup); | |
18636 | + au_set_dbend(dentry, bcpup); | |
18637 | + } | |
38d290e6 JR |
18638 | + AuDebugOn(add_entry |
18639 | + && !au_ftest_wrdir(args->flags, TMPFILE) | |
18640 | + && !au_h_dptr(dentry, bcpup)); | |
027c5e7a | 18641 | + } |
86dc4139 AM |
18642 | + |
18643 | +out: | |
18644 | + dput(parent); | |
18645 | + return err; | |
18646 | +} | |
18647 | + | |
18648 | +/* ---------------------------------------------------------------------- */ | |
18649 | + | |
18650 | +void au_pin_hdir_unlock(struct au_pin *p) | |
18651 | +{ | |
18652 | + if (p->hdir) | |
18653 | + au_hn_imtx_unlock(p->hdir); | |
18654 | +} | |
18655 | + | |
c1595e42 | 18656 | +int au_pin_hdir_lock(struct au_pin *p) |
86dc4139 AM |
18657 | +{ |
18658 | + int err; | |
18659 | + | |
18660 | + err = 0; | |
18661 | + if (!p->hdir) | |
18662 | + goto out; | |
18663 | + | |
18664 | + /* even if an error happens later, keep this lock */ | |
18665 | + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi); | |
18666 | + | |
18667 | + err = -EBUSY; | |
5527c038 | 18668 | + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent))) |
86dc4139 AM |
18669 | + goto out; |
18670 | + | |
18671 | + err = 0; | |
18672 | + if (p->h_dentry) | |
18673 | + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode, | |
18674 | + p->h_parent, p->br); | |
18675 | + | |
18676 | +out: | |
18677 | + return err; | |
18678 | +} | |
18679 | + | |
18680 | +int au_pin_hdir_relock(struct au_pin *p) | |
18681 | +{ | |
18682 | + int err, i; | |
18683 | + struct inode *h_i; | |
18684 | + struct dentry *h_d[] = { | |
18685 | + p->h_dentry, | |
18686 | + p->h_parent | |
18687 | + }; | |
18688 | + | |
18689 | + err = au_pin_hdir_lock(p); | |
18690 | + if (unlikely(err)) | |
18691 | + goto out; | |
18692 | + | |
18693 | + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) { | |
18694 | + if (!h_d[i]) | |
18695 | + continue; | |
5527c038 JR |
18696 | + if (d_is_positive(h_d[i])) { |
18697 | + h_i = d_inode(h_d[i]); | |
86dc4139 | 18698 | + err = !h_i->i_nlink; |
5527c038 | 18699 | + } |
86dc4139 AM |
18700 | + } |
18701 | + | |
18702 | +out: | |
18703 | + return err; | |
18704 | +} | |
18705 | + | |
18706 | +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task) | |
18707 | +{ | |
18708 | +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP) | |
18709 | + p->hdir->hi_inode->i_mutex.owner = task; | |
18710 | +#endif | |
18711 | +} | |
18712 | + | |
18713 | +void au_pin_hdir_acquire_nest(struct au_pin *p) | |
18714 | +{ | |
18715 | + if (p->hdir) { | |
18716 | + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map, | |
18717 | + p->lsc_hi, 0, NULL, _RET_IP_); | |
18718 | + au_pin_hdir_set_owner(p, current); | |
18719 | + } | |
dece6358 | 18720 | +} |
1facf9fc | 18721 | + |
86dc4139 AM |
18722 | +void au_pin_hdir_release(struct au_pin *p) |
18723 | +{ | |
18724 | + if (p->hdir) { | |
18725 | + au_pin_hdir_set_owner(p, p->task); | |
18726 | + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_); | |
18727 | + } | |
18728 | +} | |
1308ab2a | 18729 | + |
4a4d8108 | 18730 | +struct dentry *au_pinned_h_parent(struct au_pin *pin) |
1308ab2a | 18731 | +{ |
4a4d8108 AM |
18732 | + if (pin && pin->parent) |
18733 | + return au_h_dptr(pin->parent, pin->bindex); | |
18734 | + return NULL; | |
dece6358 | 18735 | +} |
1facf9fc | 18736 | + |
4a4d8108 | 18737 | +void au_unpin(struct au_pin *p) |
dece6358 | 18738 | +{ |
86dc4139 AM |
18739 | + if (p->hdir) |
18740 | + au_pin_hdir_unlock(p); | |
e49829fe | 18741 | + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE)) |
b4510431 | 18742 | + vfsub_mnt_drop_write(p->h_mnt); |
4a4d8108 AM |
18743 | + if (!p->hdir) |
18744 | + return; | |
1facf9fc | 18745 | + |
4a4d8108 AM |
18746 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18747 | + di_read_unlock(p->parent, AuLock_IR); | |
18748 | + iput(p->hdir->hi_inode); | |
18749 | + dput(p->parent); | |
18750 | + p->parent = NULL; | |
18751 | + p->hdir = NULL; | |
18752 | + p->h_mnt = NULL; | |
86dc4139 | 18753 | + /* do not clear p->task */ |
4a4d8108 | 18754 | +} |
1308ab2a | 18755 | + |
4a4d8108 AM |
18756 | +int au_do_pin(struct au_pin *p) |
18757 | +{ | |
18758 | + int err; | |
18759 | + struct super_block *sb; | |
4a4d8108 AM |
18760 | + struct inode *h_dir; |
18761 | + | |
18762 | + err = 0; | |
18763 | + sb = p->dentry->d_sb; | |
86dc4139 | 18764 | + p->br = au_sbr(sb, p->bindex); |
4a4d8108 AM |
18765 | + if (IS_ROOT(p->dentry)) { |
18766 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { | |
86dc4139 | 18767 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 18768 | + err = vfsub_mnt_want_write(p->h_mnt); |
4a4d8108 AM |
18769 | + if (unlikely(err)) { |
18770 | + au_fclr_pin(p->flags, MNT_WRITE); | |
18771 | + goto out_err; | |
18772 | + } | |
18773 | + } | |
dece6358 | 18774 | + goto out; |
1facf9fc | 18775 | + } |
18776 | + | |
86dc4139 | 18777 | + p->h_dentry = NULL; |
4a4d8108 | 18778 | + if (p->bindex <= au_dbend(p->dentry)) |
86dc4139 | 18779 | + p->h_dentry = au_h_dptr(p->dentry, p->bindex); |
dece6358 | 18780 | + |
4a4d8108 AM |
18781 | + p->parent = dget_parent(p->dentry); |
18782 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) | |
18783 | + di_read_lock(p->parent, AuLock_IR, p->lsc_di); | |
dece6358 | 18784 | + |
4a4d8108 | 18785 | + h_dir = NULL; |
86dc4139 | 18786 | + p->h_parent = au_h_dptr(p->parent, p->bindex); |
5527c038 | 18787 | + p->hdir = au_hi(d_inode(p->parent), p->bindex); |
4a4d8108 AM |
18788 | + if (p->hdir) |
18789 | + h_dir = p->hdir->hi_inode; | |
dece6358 | 18790 | + |
b752ccd1 AM |
18791 | + /* |
18792 | + * udba case, or | |
18793 | + * if DI_LOCKED is not set, then p->parent may be different | |
18794 | + * and h_parent can be NULL. | |
18795 | + */ | |
86dc4139 | 18796 | + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) { |
e49829fe | 18797 | + err = -EBUSY; |
4a4d8108 AM |
18798 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18799 | + di_read_unlock(p->parent, AuLock_IR); | |
18800 | + dput(p->parent); | |
18801 | + p->parent = NULL; | |
18802 | + goto out_err; | |
18803 | + } | |
1308ab2a | 18804 | + |
4a4d8108 | 18805 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { |
86dc4139 | 18806 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 18807 | + err = vfsub_mnt_want_write(p->h_mnt); |
dece6358 | 18808 | + if (unlikely(err)) { |
4a4d8108 | 18809 | + au_fclr_pin(p->flags, MNT_WRITE); |
86dc4139 AM |
18810 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18811 | + di_read_unlock(p->parent, AuLock_IR); | |
18812 | + dput(p->parent); | |
18813 | + p->parent = NULL; | |
18814 | + goto out_err; | |
dece6358 AM |
18815 | + } |
18816 | + } | |
4a4d8108 | 18817 | + |
86dc4139 AM |
18818 | + au_igrab(h_dir); |
18819 | + err = au_pin_hdir_lock(p); | |
18820 | + if (!err) | |
18821 | + goto out; /* success */ | |
18822 | + | |
076b876e AM |
18823 | + au_unpin(p); |
18824 | + | |
4f0767ce | 18825 | +out_err: |
4a4d8108 AM |
18826 | + pr_err("err %d\n", err); |
18827 | + err = au_busy_or_stale(); | |
4f0767ce | 18828 | +out: |
1facf9fc | 18829 | + return err; |
18830 | +} | |
18831 | + | |
4a4d8108 AM |
18832 | +void au_pin_init(struct au_pin *p, struct dentry *dentry, |
18833 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
18834 | + unsigned int udba, unsigned char flags) | |
18835 | +{ | |
18836 | + p->dentry = dentry; | |
18837 | + p->udba = udba; | |
18838 | + p->lsc_di = lsc_di; | |
18839 | + p->lsc_hi = lsc_hi; | |
18840 | + p->flags = flags; | |
18841 | + p->bindex = bindex; | |
18842 | + | |
18843 | + p->parent = NULL; | |
18844 | + p->hdir = NULL; | |
18845 | + p->h_mnt = NULL; | |
86dc4139 AM |
18846 | + |
18847 | + p->h_dentry = NULL; | |
18848 | + p->h_parent = NULL; | |
18849 | + p->br = NULL; | |
18850 | + p->task = current; | |
4a4d8108 AM |
18851 | +} |
18852 | + | |
18853 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
18854 | + unsigned int udba, unsigned char flags) | |
18855 | +{ | |
18856 | + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2, | |
18857 | + udba, flags); | |
18858 | + return au_do_pin(pin); | |
18859 | +} | |
18860 | + | |
dece6358 AM |
18861 | +/* ---------------------------------------------------------------------- */ |
18862 | + | |
1308ab2a | 18863 | +/* |
4a4d8108 AM |
18864 | + * ->setattr() and ->getattr() are called in various cases. |
18865 | + * chmod, stat: dentry is revalidated. | |
18866 | + * fchmod, fstat: file and dentry are not revalidated, additionally they may be | |
18867 | + * unhashed. | |
18868 | + * for ->setattr(), ia->ia_file is passed from ftruncate only. | |
1308ab2a | 18869 | + */ |
027c5e7a | 18870 | +/* todo: consolidate with do_refresh() and simple_reval_dpath() */ |
c1595e42 | 18871 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen) |
1facf9fc | 18872 | +{ |
4a4d8108 | 18873 | + int err; |
4a4d8108 | 18874 | + struct dentry *parent; |
1facf9fc | 18875 | + |
1308ab2a | 18876 | + err = 0; |
027c5e7a | 18877 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 AM |
18878 | + parent = dget_parent(dentry); |
18879 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 18880 | + err = au_refresh_dentry(dentry, parent); |
4a4d8108 AM |
18881 | + di_read_unlock(parent, AuLock_IR); |
18882 | + dput(parent); | |
dece6358 | 18883 | + } |
1facf9fc | 18884 | + |
4a4d8108 | 18885 | + AuTraceErr(err); |
1308ab2a | 18886 | + return err; |
18887 | +} | |
dece6358 | 18888 | + |
c1595e42 JR |
18889 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, |
18890 | + struct au_icpup_args *a) | |
1308ab2a | 18891 | +{ |
18892 | + int err; | |
4a4d8108 | 18893 | + loff_t sz; |
e49829fe | 18894 | + aufs_bindex_t bstart, ibstart; |
4a4d8108 AM |
18895 | + struct dentry *hi_wh, *parent; |
18896 | + struct inode *inode; | |
4a4d8108 AM |
18897 | + struct au_wr_dir_args wr_dir_args = { |
18898 | + .force_btgt = -1, | |
18899 | + .flags = 0 | |
18900 | + }; | |
18901 | + | |
2000de60 | 18902 | + if (d_is_dir(dentry)) |
4a4d8108 AM |
18903 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
18904 | + /* plink or hi_wh() case */ | |
2000de60 | 18905 | + bstart = au_dbstart(dentry); |
5527c038 | 18906 | + inode = d_inode(dentry); |
e49829fe | 18907 | + ibstart = au_ibstart(inode); |
027c5e7a | 18908 | + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode)) |
e49829fe | 18909 | + wr_dir_args.force_btgt = ibstart; |
4a4d8108 AM |
18910 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
18911 | + if (unlikely(err < 0)) | |
18912 | + goto out; | |
18913 | + a->btgt = err; | |
18914 | + if (err != bstart) | |
18915 | + au_fset_icpup(a->flags, DID_CPUP); | |
18916 | + | |
18917 | + err = 0; | |
18918 | + a->pin_flags = AuPin_MNT_WRITE; | |
18919 | + parent = NULL; | |
18920 | + if (!IS_ROOT(dentry)) { | |
18921 | + au_fset_pin(a->pin_flags, DI_LOCKED); | |
18922 | + parent = dget_parent(dentry); | |
18923 | + di_write_lock_parent(parent); | |
18924 | + } | |
18925 | + | |
18926 | + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags); | |
18927 | + if (unlikely(err)) | |
18928 | + goto out_parent; | |
18929 | + | |
18930 | + a->h_path.dentry = au_h_dptr(dentry, bstart); | |
4a4d8108 | 18931 | + sz = -1; |
5527c038 | 18932 | + a->h_inode = d_inode(a->h_path.dentry); |
c1595e42 JR |
18933 | + if (ia && (ia->ia_valid & ATTR_SIZE)) { |
18934 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
18935 | + if (ia->ia_size < i_size_read(a->h_inode)) | |
18936 | + sz = ia->ia_size; | |
18937 | + mutex_unlock(&a->h_inode->i_mutex); | |
18938 | + } | |
4a4d8108 | 18939 | + |
4a4d8108 | 18940 | + hi_wh = NULL; |
027c5e7a | 18941 | + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) { |
4a4d8108 AM |
18942 | + hi_wh = au_hi_wh(inode, a->btgt); |
18943 | + if (!hi_wh) { | |
c2b27bf2 AM |
18944 | + struct au_cp_generic cpg = { |
18945 | + .dentry = dentry, | |
18946 | + .bdst = a->btgt, | |
18947 | + .bsrc = -1, | |
18948 | + .len = sz, | |
18949 | + .pin = &a->pin | |
18950 | + }; | |
18951 | + err = au_sio_cpup_wh(&cpg, /*file*/NULL); | |
4a4d8108 AM |
18952 | + if (unlikely(err)) |
18953 | + goto out_unlock; | |
18954 | + hi_wh = au_hi_wh(inode, a->btgt); | |
18955 | + /* todo: revalidate hi_wh? */ | |
18956 | + } | |
18957 | + } | |
18958 | + | |
18959 | + if (parent) { | |
18960 | + au_pin_set_parent_lflag(&a->pin, /*lflag*/0); | |
18961 | + di_downgrade_lock(parent, AuLock_IR); | |
18962 | + dput(parent); | |
18963 | + parent = NULL; | |
18964 | + } | |
18965 | + if (!au_ftest_icpup(a->flags, DID_CPUP)) | |
18966 | + goto out; /* success */ | |
18967 | + | |
18968 | + if (!d_unhashed(dentry)) { | |
c2b27bf2 AM |
18969 | + struct au_cp_generic cpg = { |
18970 | + .dentry = dentry, | |
18971 | + .bdst = a->btgt, | |
18972 | + .bsrc = bstart, | |
18973 | + .len = sz, | |
18974 | + .pin = &a->pin, | |
18975 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
18976 | + }; | |
18977 | + err = au_sio_cpup_simple(&cpg); | |
4a4d8108 AM |
18978 | + if (!err) |
18979 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
18980 | + } else if (!hi_wh) | |
18981 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
18982 | + else | |
18983 | + a->h_path.dentry = hi_wh; /* do not dget here */ | |
1308ab2a | 18984 | + |
4f0767ce | 18985 | +out_unlock: |
5527c038 | 18986 | + a->h_inode = d_inode(a->h_path.dentry); |
86dc4139 | 18987 | + if (!err) |
dece6358 | 18988 | + goto out; /* success */ |
4a4d8108 | 18989 | + au_unpin(&a->pin); |
4f0767ce | 18990 | +out_parent: |
4a4d8108 AM |
18991 | + if (parent) { |
18992 | + di_write_unlock(parent); | |
18993 | + dput(parent); | |
18994 | + } | |
4f0767ce | 18995 | +out: |
86dc4139 AM |
18996 | + if (!err) |
18997 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
1facf9fc | 18998 | + return err; |
18999 | +} | |
19000 | + | |
4a4d8108 | 19001 | +static int aufs_setattr(struct dentry *dentry, struct iattr *ia) |
1facf9fc | 19002 | +{ |
4a4d8108 | 19003 | + int err; |
523b37e3 | 19004 | + struct inode *inode, *delegated; |
4a4d8108 AM |
19005 | + struct super_block *sb; |
19006 | + struct file *file; | |
19007 | + struct au_icpup_args *a; | |
1facf9fc | 19008 | + |
5527c038 | 19009 | + inode = d_inode(dentry); |
4a4d8108 | 19010 | + IMustLock(inode); |
dece6358 | 19011 | + |
4a4d8108 AM |
19012 | + err = -ENOMEM; |
19013 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
19014 | + if (unlikely(!a)) | |
19015 | + goto out; | |
1facf9fc | 19016 | + |
4a4d8108 AM |
19017 | + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
19018 | + ia->ia_valid &= ~ATTR_MODE; | |
dece6358 | 19019 | + |
4a4d8108 AM |
19020 | + file = NULL; |
19021 | + sb = dentry->d_sb; | |
e49829fe JR |
19022 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
19023 | + if (unlikely(err)) | |
19024 | + goto out_kfree; | |
19025 | + | |
4a4d8108 AM |
19026 | + if (ia->ia_valid & ATTR_FILE) { |
19027 | + /* currently ftruncate(2) only */ | |
7e9cd9fe | 19028 | + AuDebugOn(!d_is_reg(dentry)); |
4a4d8108 AM |
19029 | + file = ia->ia_file; |
19030 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); | |
19031 | + if (unlikely(err)) | |
19032 | + goto out_si; | |
19033 | + ia->ia_file = au_hf_top(file); | |
19034 | + a->udba = AuOpt_UDBA_NONE; | |
19035 | + } else { | |
19036 | + /* fchmod() doesn't pass ia_file */ | |
19037 | + a->udba = au_opt_udba(sb); | |
027c5e7a AM |
19038 | + di_write_lock_child(dentry); |
19039 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
4a4d8108 AM |
19040 | + if (d_unhashed(dentry)) |
19041 | + a->udba = AuOpt_UDBA_NONE; | |
4a4d8108 AM |
19042 | + if (a->udba != AuOpt_UDBA_NONE) { |
19043 | + AuDebugOn(IS_ROOT(dentry)); | |
19044 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
19045 | + if (unlikely(err)) | |
19046 | + goto out_dentry; | |
19047 | + } | |
dece6358 | 19048 | + } |
dece6358 | 19049 | + |
4a4d8108 AM |
19050 | + err = au_pin_and_icpup(dentry, ia, a); |
19051 | + if (unlikely(err < 0)) | |
19052 | + goto out_dentry; | |
19053 | + if (au_ftest_icpup(a->flags, DID_CPUP)) { | |
19054 | + ia->ia_file = NULL; | |
19055 | + ia->ia_valid &= ~ATTR_FILE; | |
1308ab2a | 19056 | + } |
dece6358 | 19057 | + |
4a4d8108 AM |
19058 | + a->h_path.mnt = au_sbr_mnt(sb, a->btgt); |
19059 | + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME)) | |
19060 | + == (ATTR_MODE | ATTR_CTIME)) { | |
7eafdf33 | 19061 | + err = security_path_chmod(&a->h_path, ia->ia_mode); |
4a4d8108 AM |
19062 | + if (unlikely(err)) |
19063 | + goto out_unlock; | |
19064 | + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID)) | |
19065 | + && (ia->ia_valid & ATTR_CTIME)) { | |
86dc4139 | 19066 | + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid); |
4a4d8108 AM |
19067 | + if (unlikely(err)) |
19068 | + goto out_unlock; | |
19069 | + } | |
dece6358 | 19070 | + |
4a4d8108 AM |
19071 | + if (ia->ia_valid & ATTR_SIZE) { |
19072 | + struct file *f; | |
1308ab2a | 19073 | + |
953406b4 | 19074 | + if (ia->ia_size < i_size_read(inode)) |
4a4d8108 | 19075 | + /* unmap only */ |
953406b4 | 19076 | + truncate_setsize(inode, ia->ia_size); |
1308ab2a | 19077 | + |
4a4d8108 AM |
19078 | + f = NULL; |
19079 | + if (ia->ia_valid & ATTR_FILE) | |
19080 | + f = ia->ia_file; | |
19081 | + mutex_unlock(&a->h_inode->i_mutex); | |
19082 | + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f); | |
19083 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
523b37e3 AM |
19084 | + } else { |
19085 | + delegated = NULL; | |
19086 | + while (1) { | |
19087 | + err = vfsub_notify_change(&a->h_path, ia, &delegated); | |
19088 | + if (delegated) { | |
19089 | + err = break_deleg_wait(&delegated); | |
19090 | + if (!err) | |
19091 | + continue; | |
19092 | + } | |
19093 | + break; | |
19094 | + } | |
19095 | + } | |
4a4d8108 AM |
19096 | + if (!err) |
19097 | + au_cpup_attr_changeable(inode); | |
1308ab2a | 19098 | + |
4f0767ce | 19099 | +out_unlock: |
4a4d8108 AM |
19100 | + mutex_unlock(&a->h_inode->i_mutex); |
19101 | + au_unpin(&a->pin); | |
027c5e7a AM |
19102 | + if (unlikely(err)) |
19103 | + au_update_dbstart(dentry); | |
4f0767ce | 19104 | +out_dentry: |
4a4d8108 AM |
19105 | + di_write_unlock(dentry); |
19106 | + if (file) { | |
19107 | + fi_write_unlock(file); | |
19108 | + ia->ia_file = file; | |
19109 | + ia->ia_valid |= ATTR_FILE; | |
19110 | + } | |
4f0767ce | 19111 | +out_si: |
4a4d8108 | 19112 | + si_read_unlock(sb); |
e49829fe | 19113 | +out_kfree: |
4a4d8108 | 19114 | + kfree(a); |
4f0767ce | 19115 | +out: |
4a4d8108 AM |
19116 | + AuTraceErr(err); |
19117 | + return err; | |
1facf9fc | 19118 | +} |
19119 | + | |
c1595e42 JR |
19120 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) |
19121 | +static int au_h_path_to_set_attr(struct dentry *dentry, | |
19122 | + struct au_icpup_args *a, struct path *h_path) | |
19123 | +{ | |
19124 | + int err; | |
19125 | + struct super_block *sb; | |
19126 | + | |
19127 | + sb = dentry->d_sb; | |
19128 | + a->udba = au_opt_udba(sb); | |
19129 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
19130 | + if (d_unhashed(dentry)) | |
19131 | + a->udba = AuOpt_UDBA_NONE; | |
19132 | + if (a->udba != AuOpt_UDBA_NONE) { | |
19133 | + AuDebugOn(IS_ROOT(dentry)); | |
19134 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
19135 | + if (unlikely(err)) | |
19136 | + goto out; | |
19137 | + } | |
19138 | + err = au_pin_and_icpup(dentry, /*ia*/NULL, a); | |
19139 | + if (unlikely(err < 0)) | |
19140 | + goto out; | |
19141 | + | |
19142 | + h_path->dentry = a->h_path.dentry; | |
19143 | + h_path->mnt = au_sbr_mnt(sb, a->btgt); | |
19144 | + | |
19145 | +out: | |
19146 | + return err; | |
19147 | +} | |
19148 | + | |
19149 | +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg) | |
19150 | +{ | |
19151 | + int err; | |
19152 | + struct path h_path; | |
19153 | + struct super_block *sb; | |
19154 | + struct au_icpup_args *a; | |
19155 | + struct inode *inode, *h_inode; | |
19156 | + | |
5527c038 | 19157 | + inode = d_inode(dentry); |
c1595e42 JR |
19158 | + IMustLock(inode); |
19159 | + | |
19160 | + err = -ENOMEM; | |
19161 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
19162 | + if (unlikely(!a)) | |
19163 | + goto out; | |
19164 | + | |
19165 | + sb = dentry->d_sb; | |
19166 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19167 | + if (unlikely(err)) | |
19168 | + goto out_kfree; | |
19169 | + | |
19170 | + h_path.dentry = NULL; /* silence gcc */ | |
19171 | + di_write_lock_child(dentry); | |
19172 | + err = au_h_path_to_set_attr(dentry, a, &h_path); | |
19173 | + if (unlikely(err)) | |
19174 | + goto out_di; | |
19175 | + | |
19176 | + mutex_unlock(&a->h_inode->i_mutex); | |
19177 | + switch (arg->type) { | |
19178 | + case AU_XATTR_SET: | |
19179 | + err = vfsub_setxattr(h_path.dentry, | |
19180 | + arg->u.set.name, arg->u.set.value, | |
19181 | + arg->u.set.size, arg->u.set.flags); | |
19182 | + break; | |
19183 | + case AU_XATTR_REMOVE: | |
19184 | + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name); | |
19185 | + break; | |
19186 | + case AU_ACL_SET: | |
19187 | + err = -EOPNOTSUPP; | |
5527c038 | 19188 | + h_inode = d_inode(h_path.dentry); |
c1595e42 JR |
19189 | + if (h_inode->i_op->set_acl) |
19190 | + err = h_inode->i_op->set_acl(h_inode, | |
19191 | + arg->u.acl_set.acl, | |
19192 | + arg->u.acl_set.type); | |
19193 | + break; | |
19194 | + } | |
19195 | + if (!err) | |
19196 | + au_cpup_attr_timesizes(inode); | |
19197 | + | |
19198 | + au_unpin(&a->pin); | |
19199 | + if (unlikely(err)) | |
19200 | + au_update_dbstart(dentry); | |
19201 | + | |
19202 | +out_di: | |
19203 | + di_write_unlock(dentry); | |
19204 | + si_read_unlock(sb); | |
19205 | +out_kfree: | |
19206 | + kfree(a); | |
19207 | +out: | |
19208 | + AuTraceErr(err); | |
19209 | + return err; | |
19210 | +} | |
19211 | +#endif | |
19212 | + | |
4a4d8108 AM |
19213 | +static void au_refresh_iattr(struct inode *inode, struct kstat *st, |
19214 | + unsigned int nlink) | |
1facf9fc | 19215 | +{ |
9dbd164d AM |
19216 | + unsigned int n; |
19217 | + | |
4a4d8108 | 19218 | + inode->i_mode = st->mode; |
86dc4139 AM |
19219 | + /* don't i_[ug]id_write() here */ |
19220 | + inode->i_uid = st->uid; | |
19221 | + inode->i_gid = st->gid; | |
4a4d8108 AM |
19222 | + inode->i_atime = st->atime; |
19223 | + inode->i_mtime = st->mtime; | |
19224 | + inode->i_ctime = st->ctime; | |
1facf9fc | 19225 | + |
4a4d8108 AM |
19226 | + au_cpup_attr_nlink(inode, /*force*/0); |
19227 | + if (S_ISDIR(inode->i_mode)) { | |
9dbd164d AM |
19228 | + n = inode->i_nlink; |
19229 | + n -= nlink; | |
19230 | + n += st->nlink; | |
f6b6e03d | 19231 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 19232 | + /* 0 can happen */ |
92d182d2 | 19233 | + set_nlink(inode, n); |
4a4d8108 | 19234 | + } |
1facf9fc | 19235 | + |
4a4d8108 AM |
19236 | + spin_lock(&inode->i_lock); |
19237 | + inode->i_blocks = st->blocks; | |
19238 | + i_size_write(inode, st->size); | |
19239 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 19240 | +} |
19241 | + | |
c1595e42 JR |
19242 | +/* |
19243 | + * common routine for aufs_getattr() and aufs_getxattr(). | |
19244 | + * returns zero or negative (an error). | |
19245 | + * @dentry will be read-locked in success. | |
19246 | + */ | |
19247 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path) | |
1facf9fc | 19248 | +{ |
4a4d8108 | 19249 | + int err; |
076b876e | 19250 | + unsigned int mnt_flags, sigen; |
c1595e42 | 19251 | + unsigned char udba_none; |
4a4d8108 | 19252 | + aufs_bindex_t bindex; |
4a4d8108 AM |
19253 | + struct super_block *sb, *h_sb; |
19254 | + struct inode *inode; | |
1facf9fc | 19255 | + |
c1595e42 JR |
19256 | + h_path->mnt = NULL; |
19257 | + h_path->dentry = NULL; | |
19258 | + | |
19259 | + err = 0; | |
4a4d8108 | 19260 | + sb = dentry->d_sb; |
4a4d8108 AM |
19261 | + mnt_flags = au_mntflags(sb); |
19262 | + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE); | |
1facf9fc | 19263 | + |
4a4d8108 | 19264 | + /* support fstat(2) */ |
027c5e7a | 19265 | + if (!d_unlinked(dentry) && !udba_none) { |
076b876e | 19266 | + sigen = au_sigen(sb); |
027c5e7a AM |
19267 | + err = au_digen_test(dentry, sigen); |
19268 | + if (!err) { | |
4a4d8108 | 19269 | + di_read_lock_child(dentry, AuLock_IR); |
027c5e7a | 19270 | + err = au_dbrange_test(dentry); |
c1595e42 JR |
19271 | + if (unlikely(err)) { |
19272 | + di_read_unlock(dentry, AuLock_IR); | |
19273 | + goto out; | |
19274 | + } | |
027c5e7a | 19275 | + } else { |
4a4d8108 AM |
19276 | + AuDebugOn(IS_ROOT(dentry)); |
19277 | + di_write_lock_child(dentry); | |
027c5e7a AM |
19278 | + err = au_dbrange_test(dentry); |
19279 | + if (!err) | |
19280 | + err = au_reval_for_attr(dentry, sigen); | |
c1595e42 JR |
19281 | + if (!err) |
19282 | + di_downgrade_lock(dentry, AuLock_IR); | |
19283 | + else { | |
19284 | + di_write_unlock(dentry); | |
19285 | + goto out; | |
19286 | + } | |
4a4d8108 AM |
19287 | + } |
19288 | + } else | |
19289 | + di_read_lock_child(dentry, AuLock_IR); | |
1facf9fc | 19290 | + |
5527c038 | 19291 | + inode = d_inode(dentry); |
4a4d8108 | 19292 | + bindex = au_ibstart(inode); |
c1595e42 JR |
19293 | + h_path->mnt = au_sbr_mnt(sb, bindex); |
19294 | + h_sb = h_path->mnt->mnt_sb; | |
19295 | + if (!force | |
19296 | + && !au_test_fs_bad_iattr(h_sb) | |
19297 | + && udba_none) | |
19298 | + goto out; /* success */ | |
1facf9fc | 19299 | + |
4a4d8108 | 19300 | + if (au_dbstart(dentry) == bindex) |
c1595e42 | 19301 | + h_path->dentry = au_h_dptr(dentry, bindex); |
4a4d8108 | 19302 | + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) { |
c1595e42 JR |
19303 | + h_path->dentry = au_plink_lkup(inode, bindex); |
19304 | + if (IS_ERR(h_path->dentry)) | |
19305 | + /* pretending success */ | |
19306 | + h_path->dentry = NULL; | |
19307 | + else | |
19308 | + dput(h_path->dentry); | |
4a4d8108 | 19309 | + } |
c1595e42 JR |
19310 | + |
19311 | +out: | |
19312 | + return err; | |
19313 | +} | |
19314 | + | |
19315 | +static int aufs_getattr(struct vfsmount *mnt __maybe_unused, | |
19316 | + struct dentry *dentry, struct kstat *st) | |
19317 | +{ | |
19318 | + int err; | |
19319 | + unsigned char positive; | |
19320 | + struct path h_path; | |
19321 | + struct inode *inode; | |
19322 | + struct super_block *sb; | |
19323 | + | |
5527c038 | 19324 | + inode = d_inode(dentry); |
c1595e42 JR |
19325 | + sb = dentry->d_sb; |
19326 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19327 | + if (unlikely(err)) | |
19328 | + goto out; | |
19329 | + err = au_h_path_getattr(dentry, /*force*/0, &h_path); | |
19330 | + if (unlikely(err)) | |
19331 | + goto out_si; | |
c06a8ce3 | 19332 | + if (unlikely(!h_path.dentry)) |
c1595e42 | 19333 | + /* illegally overlapped or something */ |
4a4d8108 AM |
19334 | + goto out_fill; /* pretending success */ |
19335 | + | |
5527c038 | 19336 | + positive = d_is_positive(h_path.dentry); |
4a4d8108 | 19337 | + if (positive) |
c06a8ce3 | 19338 | + err = vfs_getattr(&h_path, st); |
4a4d8108 AM |
19339 | + if (!err) { |
19340 | + if (positive) | |
c06a8ce3 | 19341 | + au_refresh_iattr(inode, st, |
5527c038 | 19342 | + d_inode(h_path.dentry)->i_nlink); |
4a4d8108 | 19343 | + goto out_fill; /* success */ |
1facf9fc | 19344 | + } |
7f207e10 | 19345 | + AuTraceErr(err); |
c1595e42 | 19346 | + goto out_di; |
4a4d8108 | 19347 | + |
4f0767ce | 19348 | +out_fill: |
4a4d8108 | 19349 | + generic_fillattr(inode, st); |
c1595e42 | 19350 | +out_di: |
4a4d8108 | 19351 | + di_read_unlock(dentry, AuLock_IR); |
c1595e42 | 19352 | +out_si: |
4a4d8108 | 19353 | + si_read_unlock(sb); |
7f207e10 AM |
19354 | +out: |
19355 | + AuTraceErr(err); | |
4a4d8108 | 19356 | + return err; |
1facf9fc | 19357 | +} |
19358 | + | |
19359 | +/* ---------------------------------------------------------------------- */ | |
19360 | + | |
4a4d8108 AM |
19361 | +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf, |
19362 | + int bufsiz) | |
1facf9fc | 19363 | +{ |
19364 | + int err; | |
4a4d8108 AM |
19365 | + struct super_block *sb; |
19366 | + struct dentry *h_dentry; | |
5527c038 | 19367 | + struct inode *inode, *h_inode; |
1facf9fc | 19368 | + |
4a4d8108 AM |
19369 | + err = -EINVAL; |
19370 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 JR |
19371 | + h_inode = d_inode(h_dentry); |
19372 | + if (unlikely(!h_inode->i_op->readlink)) | |
4a4d8108 | 19373 | + goto out; |
1facf9fc | 19374 | + |
4a4d8108 AM |
19375 | + err = security_inode_readlink(h_dentry); |
19376 | + if (unlikely(err)) | |
dece6358 | 19377 | + goto out; |
1facf9fc | 19378 | + |
4a4d8108 | 19379 | + sb = dentry->d_sb; |
5527c038 JR |
19380 | + inode = d_inode(dentry); |
19381 | + if (!au_test_ro(sb, bindex, inode)) { | |
4a4d8108 | 19382 | + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry); |
5527c038 | 19383 | + fsstack_copy_attr_atime(inode, h_inode); |
1facf9fc | 19384 | + } |
5527c038 | 19385 | + err = h_inode->i_op->readlink(h_dentry, buf, bufsiz); |
1facf9fc | 19386 | + |
4f0767ce | 19387 | +out: |
4a4d8108 AM |
19388 | + return err; |
19389 | +} | |
1facf9fc | 19390 | + |
4a4d8108 AM |
19391 | +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz) |
19392 | +{ | |
19393 | + int err; | |
1facf9fc | 19394 | + |
027c5e7a AM |
19395 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
19396 | + if (unlikely(err)) | |
19397 | + goto out; | |
19398 | + err = au_d_hashed_positive(dentry); | |
19399 | + if (!err) | |
19400 | + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz); | |
4a4d8108 | 19401 | + aufs_read_unlock(dentry, AuLock_IR); |
1facf9fc | 19402 | + |
027c5e7a | 19403 | +out: |
4a4d8108 AM |
19404 | + return err; |
19405 | +} | |
1facf9fc | 19406 | + |
4a4d8108 AM |
19407 | +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd) |
19408 | +{ | |
19409 | + int err; | |
4a4d8108 | 19410 | + mm_segment_t old_fs; |
b752ccd1 AM |
19411 | + union { |
19412 | + char *k; | |
19413 | + char __user *u; | |
19414 | + } buf; | |
1facf9fc | 19415 | + |
4a4d8108 | 19416 | + err = -ENOMEM; |
537831f9 | 19417 | + buf.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 19418 | + if (unlikely(!buf.k)) |
4a4d8108 | 19419 | + goto out; |
1facf9fc | 19420 | + |
027c5e7a AM |
19421 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
19422 | + if (unlikely(err)) | |
19423 | + goto out_name; | |
19424 | + | |
19425 | + err = au_d_hashed_positive(dentry); | |
19426 | + if (!err) { | |
19427 | + old_fs = get_fs(); | |
19428 | + set_fs(KERNEL_DS); | |
19429 | + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX); | |
19430 | + set_fs(old_fs); | |
19431 | + } | |
4a4d8108 | 19432 | + aufs_read_unlock(dentry, AuLock_IR); |
1facf9fc | 19433 | + |
4a4d8108 | 19434 | + if (err >= 0) { |
b752ccd1 | 19435 | + buf.k[err] = 0; |
4a4d8108 | 19436 | + /* will be freed by put_link */ |
b752ccd1 | 19437 | + nd_set_link(nd, buf.k); |
4a4d8108 | 19438 | + return NULL; /* success */ |
1308ab2a | 19439 | + } |
1facf9fc | 19440 | + |
027c5e7a | 19441 | +out_name: |
537831f9 | 19442 | + free_page((unsigned long)buf.k); |
4f0767ce | 19443 | +out: |
4a4d8108 AM |
19444 | + AuTraceErr(err); |
19445 | + return ERR_PTR(err); | |
19446 | +} | |
1facf9fc | 19447 | + |
4a4d8108 AM |
19448 | +static void aufs_put_link(struct dentry *dentry __maybe_unused, |
19449 | + struct nameidata *nd, void *cookie __maybe_unused) | |
19450 | +{ | |
537831f9 AM |
19451 | + char *p; |
19452 | + | |
19453 | + p = nd_get_link(nd); | |
19454 | + if (!IS_ERR_OR_NULL(p)) | |
19455 | + free_page((unsigned long)p); | |
4a4d8108 | 19456 | +} |
1facf9fc | 19457 | + |
4a4d8108 | 19458 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19459 | + |
0c3ec466 | 19460 | +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags) |
4a4d8108 | 19461 | +{ |
0c3ec466 AM |
19462 | + int err; |
19463 | + struct super_block *sb; | |
19464 | + struct inode *h_inode; | |
19465 | + | |
19466 | + sb = inode->i_sb; | |
19467 | + /* mmap_sem might be acquired already, cf. aufs_mmap() */ | |
19468 | + lockdep_off(); | |
19469 | + si_read_lock(sb, AuLock_FLUSH); | |
19470 | + ii_write_lock_child(inode); | |
19471 | + lockdep_on(); | |
19472 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
19473 | + err = vfsub_update_time(h_inode, ts, flags); | |
19474 | + lockdep_off(); | |
38d290e6 JR |
19475 | + if (!err) |
19476 | + au_cpup_attr_timesizes(inode); | |
0c3ec466 AM |
19477 | + ii_write_unlock(inode); |
19478 | + si_read_unlock(sb); | |
19479 | + lockdep_on(); | |
38d290e6 JR |
19480 | + |
19481 | + if (!err && (flags & S_VERSION)) | |
19482 | + inode_inc_iversion(inode); | |
19483 | + | |
0c3ec466 | 19484 | + return err; |
4a4d8108 | 19485 | +} |
1facf9fc | 19486 | + |
4a4d8108 | 19487 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19488 | + |
4a4d8108 AM |
19489 | +struct inode_operations aufs_symlink_iop = { |
19490 | + .permission = aufs_permission, | |
c1595e42 JR |
19491 | +#ifdef CONFIG_FS_POSIX_ACL |
19492 | + .get_acl = aufs_get_acl, | |
19493 | + .set_acl = aufs_set_acl, /* unsupport for symlink? */ | |
19494 | +#endif | |
19495 | + | |
4a4d8108 AM |
19496 | + .setattr = aufs_setattr, |
19497 | + .getattr = aufs_getattr, | |
0c3ec466 | 19498 | + |
c1595e42 JR |
19499 | +#ifdef CONFIG_AUFS_XATTR |
19500 | + .setxattr = aufs_setxattr, | |
19501 | + .getxattr = aufs_getxattr, | |
19502 | + .listxattr = aufs_listxattr, | |
19503 | + .removexattr = aufs_removexattr, | |
19504 | +#endif | |
19505 | + | |
4a4d8108 AM |
19506 | + .readlink = aufs_readlink, |
19507 | + .follow_link = aufs_follow_link, | |
0c3ec466 AM |
19508 | + .put_link = aufs_put_link, |
19509 | + | |
19510 | + /* .update_time = aufs_update_time */ | |
4a4d8108 AM |
19511 | +}; |
19512 | + | |
19513 | +struct inode_operations aufs_dir_iop = { | |
19514 | + .create = aufs_create, | |
19515 | + .lookup = aufs_lookup, | |
19516 | + .link = aufs_link, | |
19517 | + .unlink = aufs_unlink, | |
19518 | + .symlink = aufs_symlink, | |
19519 | + .mkdir = aufs_mkdir, | |
19520 | + .rmdir = aufs_rmdir, | |
19521 | + .mknod = aufs_mknod, | |
19522 | + .rename = aufs_rename, | |
19523 | + | |
19524 | + .permission = aufs_permission, | |
c1595e42 JR |
19525 | +#ifdef CONFIG_FS_POSIX_ACL |
19526 | + .get_acl = aufs_get_acl, | |
19527 | + .set_acl = aufs_set_acl, | |
19528 | +#endif | |
19529 | + | |
4a4d8108 | 19530 | + .setattr = aufs_setattr, |
0c3ec466 AM |
19531 | + .getattr = aufs_getattr, |
19532 | + | |
c1595e42 JR |
19533 | +#ifdef CONFIG_AUFS_XATTR |
19534 | + .setxattr = aufs_setxattr, | |
19535 | + .getxattr = aufs_getxattr, | |
19536 | + .listxattr = aufs_listxattr, | |
19537 | + .removexattr = aufs_removexattr, | |
19538 | +#endif | |
19539 | + | |
38d290e6 | 19540 | + .update_time = aufs_update_time, |
b912730e | 19541 | + .atomic_open = aufs_atomic_open, |
38d290e6 | 19542 | + .tmpfile = aufs_tmpfile |
4a4d8108 AM |
19543 | +}; |
19544 | + | |
19545 | +struct inode_operations aufs_iop = { | |
19546 | + .permission = aufs_permission, | |
c1595e42 JR |
19547 | +#ifdef CONFIG_FS_POSIX_ACL |
19548 | + .get_acl = aufs_get_acl, | |
19549 | + .set_acl = aufs_set_acl, | |
19550 | +#endif | |
19551 | + | |
4a4d8108 AM |
19552 | + .setattr = aufs_setattr, |
19553 | + .getattr = aufs_getattr, | |
0c3ec466 | 19554 | + |
c1595e42 JR |
19555 | +#ifdef CONFIG_AUFS_XATTR |
19556 | + .setxattr = aufs_setxattr, | |
19557 | + .getxattr = aufs_getxattr, | |
19558 | + .listxattr = aufs_listxattr, | |
19559 | + .removexattr = aufs_removexattr, | |
19560 | +#endif | |
19561 | + | |
0c3ec466 | 19562 | + .update_time = aufs_update_time |
4a4d8108 | 19563 | +}; |
7f207e10 AM |
19564 | diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c |
19565 | --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
19566 | +++ linux/fs/aufs/i_op_del.c 2015-06-28 17:36:09.025073697 +0200 |
19567 | @@ -0,0 +1,510 @@ | |
1facf9fc | 19568 | +/* |
2000de60 | 19569 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 19570 | + * |
19571 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19572 | + * it under the terms of the GNU General Public License as published by | |
19573 | + * the Free Software Foundation; either version 2 of the License, or | |
19574 | + * (at your option) any later version. | |
dece6358 AM |
19575 | + * |
19576 | + * This program is distributed in the hope that it will be useful, | |
19577 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19578 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19579 | + * GNU General Public License for more details. | |
19580 | + * | |
19581 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19582 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 19583 | + */ |
19584 | + | |
19585 | +/* | |
4a4d8108 | 19586 | + * inode operations (del entry) |
1308ab2a | 19587 | + */ |
dece6358 | 19588 | + |
1308ab2a | 19589 | +#include "aufs.h" |
dece6358 | 19590 | + |
4a4d8108 AM |
19591 | +/* |
19592 | + * decide if a new whiteout for @dentry is necessary or not. | |
19593 | + * when it is necessary, prepare the parent dir for the upper branch whose | |
19594 | + * branch index is @bcpup for creation. the actual creation of the whiteout will | |
19595 | + * be done by caller. | |
19596 | + * return value: | |
19597 | + * 0: wh is unnecessary | |
19598 | + * plus: wh is necessary | |
19599 | + * minus: error | |
19600 | + */ | |
19601 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup) | |
1308ab2a | 19602 | +{ |
4a4d8108 AM |
19603 | + int need_wh, err; |
19604 | + aufs_bindex_t bstart; | |
19605 | + struct super_block *sb; | |
dece6358 | 19606 | + |
4a4d8108 AM |
19607 | + sb = dentry->d_sb; |
19608 | + bstart = au_dbstart(dentry); | |
19609 | + if (*bcpup < 0) { | |
19610 | + *bcpup = bstart; | |
5527c038 | 19611 | + if (au_test_ro(sb, bstart, d_inode(dentry))) { |
4a4d8108 AM |
19612 | + err = AuWbrCopyup(au_sbi(sb), dentry); |
19613 | + *bcpup = err; | |
19614 | + if (unlikely(err < 0)) | |
19615 | + goto out; | |
19616 | + } | |
19617 | + } else | |
19618 | + AuDebugOn(bstart < *bcpup | |
5527c038 | 19619 | + || au_test_ro(sb, *bcpup, d_inode(dentry))); |
4a4d8108 | 19620 | + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart); |
1308ab2a | 19621 | + |
4a4d8108 AM |
19622 | + if (*bcpup != bstart) { |
19623 | + err = au_cpup_dirs(dentry, *bcpup); | |
19624 | + if (unlikely(err)) | |
19625 | + goto out; | |
19626 | + need_wh = 1; | |
19627 | + } else { | |
027c5e7a | 19628 | + struct au_dinfo *dinfo, *tmp; |
4a4d8108 | 19629 | + |
027c5e7a AM |
19630 | + need_wh = -ENOMEM; |
19631 | + dinfo = au_di(dentry); | |
19632 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
19633 | + if (tmp) { | |
19634 | + au_di_cp(tmp, dinfo); | |
19635 | + au_di_swap(tmp, dinfo); | |
19636 | + /* returns the number of positive dentries */ | |
537831f9 | 19637 | + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0); |
027c5e7a AM |
19638 | + au_di_swap(tmp, dinfo); |
19639 | + au_rw_write_unlock(&tmp->di_rwsem); | |
19640 | + au_di_free(tmp); | |
4a4d8108 AM |
19641 | + } |
19642 | + } | |
19643 | + AuDbg("need_wh %d\n", need_wh); | |
19644 | + err = need_wh; | |
19645 | + | |
4f0767ce | 19646 | +out: |
4a4d8108 | 19647 | + return err; |
1facf9fc | 19648 | +} |
19649 | + | |
4a4d8108 AM |
19650 | +/* |
19651 | + * simple tests for the del-entry operations. | |
19652 | + * following the checks in vfs, plus the parent-child relationship. | |
19653 | + */ | |
19654 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
19655 | + struct dentry *h_parent, int isdir) | |
1facf9fc | 19656 | +{ |
4a4d8108 AM |
19657 | + int err; |
19658 | + umode_t h_mode; | |
19659 | + struct dentry *h_dentry, *h_latest; | |
1308ab2a | 19660 | + struct inode *h_inode; |
1facf9fc | 19661 | + |
4a4d8108 | 19662 | + h_dentry = au_h_dptr(dentry, bindex); |
5527c038 | 19663 | + if (d_really_is_positive(dentry)) { |
4a4d8108 | 19664 | + err = -ENOENT; |
5527c038 JR |
19665 | + if (unlikely(d_is_negative(h_dentry))) |
19666 | + goto out; | |
19667 | + h_inode = d_inode(h_dentry); | |
19668 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 | 19669 | + goto out; |
1facf9fc | 19670 | + |
4a4d8108 AM |
19671 | + h_mode = h_inode->i_mode; |
19672 | + if (!isdir) { | |
19673 | + err = -EISDIR; | |
19674 | + if (unlikely(S_ISDIR(h_mode))) | |
19675 | + goto out; | |
19676 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
19677 | + err = -ENOTDIR; | |
19678 | + goto out; | |
19679 | + } | |
19680 | + } else { | |
19681 | + /* rename(2) case */ | |
19682 | + err = -EIO; | |
5527c038 | 19683 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
19684 | + goto out; |
19685 | + } | |
1facf9fc | 19686 | + |
4a4d8108 AM |
19687 | + err = -ENOENT; |
19688 | + /* expected parent dir is locked */ | |
19689 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
19690 | + goto out; | |
19691 | + err = 0; | |
19692 | + | |
19693 | + /* | |
19694 | + * rmdir a dir may break the consistency on some filesystem. | |
19695 | + * let's try heavy test. | |
19696 | + */ | |
19697 | + err = -EACCES; | |
076b876e | 19698 | + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1) |
5527c038 | 19699 | + && au_test_h_perm(d_inode(h_parent), |
076b876e | 19700 | + MAY_EXEC | MAY_WRITE))) |
4a4d8108 AM |
19701 | + goto out; |
19702 | + | |
076b876e | 19703 | + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent); |
4a4d8108 AM |
19704 | + err = -EIO; |
19705 | + if (IS_ERR(h_latest)) | |
19706 | + goto out; | |
19707 | + if (h_latest == h_dentry) | |
19708 | + err = 0; | |
19709 | + dput(h_latest); | |
19710 | + | |
4f0767ce | 19711 | +out: |
4a4d8108 | 19712 | + return err; |
1308ab2a | 19713 | +} |
1facf9fc | 19714 | + |
4a4d8108 AM |
19715 | +/* |
19716 | + * decide the branch where we operate for @dentry. the branch index will be set | |
19717 | + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent | |
19718 | + * dir for reverting. | |
19719 | + * when a new whiteout is necessary, create it. | |
19720 | + */ | |
19721 | +static struct dentry* | |
19722 | +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup, | |
19723 | + struct au_dtime *dt, struct au_pin *pin) | |
1308ab2a | 19724 | +{ |
4a4d8108 AM |
19725 | + struct dentry *wh_dentry; |
19726 | + struct super_block *sb; | |
19727 | + struct path h_path; | |
19728 | + int err, need_wh; | |
19729 | + unsigned int udba; | |
19730 | + aufs_bindex_t bcpup; | |
dece6358 | 19731 | + |
4a4d8108 AM |
19732 | + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup); |
19733 | + wh_dentry = ERR_PTR(need_wh); | |
19734 | + if (unlikely(need_wh < 0)) | |
19735 | + goto out; | |
19736 | + | |
19737 | + sb = dentry->d_sb; | |
19738 | + udba = au_opt_udba(sb); | |
19739 | + bcpup = *rbcpup; | |
19740 | + err = au_pin(pin, dentry, bcpup, udba, | |
19741 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
19742 | + wh_dentry = ERR_PTR(err); | |
19743 | + if (unlikely(err)) | |
19744 | + goto out; | |
19745 | + | |
19746 | + h_path.dentry = au_pinned_h_parent(pin); | |
19747 | + if (udba != AuOpt_UDBA_NONE | |
19748 | + && au_dbstart(dentry) == bcpup) { | |
19749 | + err = au_may_del(dentry, bcpup, h_path.dentry, isdir); | |
19750 | + wh_dentry = ERR_PTR(err); | |
19751 | + if (unlikely(err)) | |
19752 | + goto out_unpin; | |
19753 | + } | |
19754 | + | |
19755 | + h_path.mnt = au_sbr_mnt(sb, bcpup); | |
19756 | + au_dtime_store(dt, au_pinned_parent(pin), &h_path); | |
19757 | + wh_dentry = NULL; | |
19758 | + if (!need_wh) | |
19759 | + goto out; /* success, no need to create whiteout */ | |
19760 | + | |
19761 | + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry); | |
19762 | + if (IS_ERR(wh_dentry)) | |
19763 | + goto out_unpin; | |
19764 | + | |
19765 | + /* returns with the parent is locked and wh_dentry is dget-ed */ | |
19766 | + goto out; /* success */ | |
19767 | + | |
4f0767ce | 19768 | +out_unpin: |
4a4d8108 | 19769 | + au_unpin(pin); |
4f0767ce | 19770 | +out: |
4a4d8108 | 19771 | + return wh_dentry; |
1facf9fc | 19772 | +} |
19773 | + | |
4a4d8108 AM |
19774 | +/* |
19775 | + * when removing a dir, rename it to a unique temporary whiteout-ed name first | |
19776 | + * in order to be revertible and save time for removing many child whiteouts | |
19777 | + * under the dir. | |
19778 | + * returns 1 when there are too many child whiteout and caller should remove | |
19779 | + * them asynchronously. returns 0 when the number of children is enough small to | |
19780 | + * remove now or the branch fs is a remote fs. | |
19781 | + * otherwise return an error. | |
19782 | + */ | |
19783 | +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex, | |
19784 | + struct au_nhash *whlist, struct inode *dir) | |
1facf9fc | 19785 | +{ |
4a4d8108 AM |
19786 | + int rmdir_later, err, dirwh; |
19787 | + struct dentry *h_dentry; | |
19788 | + struct super_block *sb; | |
5527c038 | 19789 | + struct inode *inode; |
4a4d8108 AM |
19790 | + |
19791 | + sb = dentry->d_sb; | |
19792 | + SiMustAnyLock(sb); | |
19793 | + h_dentry = au_h_dptr(dentry, bindex); | |
19794 | + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex)); | |
19795 | + if (unlikely(err)) | |
19796 | + goto out; | |
19797 | + | |
19798 | + /* stop monitoring */ | |
5527c038 JR |
19799 | + inode = d_inode(dentry); |
19800 | + au_hn_free(au_hi(inode, bindex)); | |
4a4d8108 AM |
19801 | + |
19802 | + if (!au_test_fs_remote(h_dentry->d_sb)) { | |
19803 | + dirwh = au_sbi(sb)->si_dirwh; | |
19804 | + rmdir_later = (dirwh <= 1); | |
19805 | + if (!rmdir_later) | |
19806 | + rmdir_later = au_nhash_test_longer_wh(whlist, bindex, | |
19807 | + dirwh); | |
19808 | + if (rmdir_later) | |
19809 | + return rmdir_later; | |
19810 | + } | |
1facf9fc | 19811 | + |
4a4d8108 AM |
19812 | + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist); |
19813 | + if (unlikely(err)) { | |
523b37e3 AM |
19814 | + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n", |
19815 | + h_dentry, bindex, err); | |
4a4d8108 AM |
19816 | + err = 0; |
19817 | + } | |
dece6358 | 19818 | + |
4f0767ce | 19819 | +out: |
4a4d8108 AM |
19820 | + AuTraceErr(err); |
19821 | + return err; | |
19822 | +} | |
1308ab2a | 19823 | + |
4a4d8108 AM |
19824 | +/* |
19825 | + * final procedure for deleting a entry. | |
19826 | + * maintain dentry and iattr. | |
19827 | + */ | |
19828 | +static void epilog(struct inode *dir, struct dentry *dentry, | |
19829 | + aufs_bindex_t bindex) | |
19830 | +{ | |
19831 | + struct inode *inode; | |
1308ab2a | 19832 | + |
5527c038 | 19833 | + inode = d_inode(dentry); |
4a4d8108 AM |
19834 | + d_drop(dentry); |
19835 | + inode->i_ctime = dir->i_ctime; | |
1308ab2a | 19836 | + |
b912730e | 19837 | + au_dir_ts(dir, bindex); |
4a4d8108 | 19838 | + dir->i_version++; |
1facf9fc | 19839 | +} |
19840 | + | |
4a4d8108 AM |
19841 | +/* |
19842 | + * when an error happened, remove the created whiteout and revert everything. | |
19843 | + */ | |
7f207e10 AM |
19844 | +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex, |
19845 | + aufs_bindex_t bwh, struct dentry *wh_dentry, | |
19846 | + struct dentry *dentry, struct au_dtime *dt) | |
1facf9fc | 19847 | +{ |
4a4d8108 AM |
19848 | + int rerr; |
19849 | + struct path h_path = { | |
19850 | + .dentry = wh_dentry, | |
7f207e10 | 19851 | + .mnt = au_sbr_mnt(dir->i_sb, bindex) |
4a4d8108 | 19852 | + }; |
dece6358 | 19853 | + |
7f207e10 | 19854 | + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry); |
4a4d8108 AM |
19855 | + if (!rerr) { |
19856 | + au_set_dbwh(dentry, bwh); | |
19857 | + au_dtime_revert(dt); | |
19858 | + return 0; | |
19859 | + } | |
dece6358 | 19860 | + |
523b37e3 | 19861 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr); |
4a4d8108 | 19862 | + return -EIO; |
1facf9fc | 19863 | +} |
19864 | + | |
4a4d8108 | 19865 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19866 | + |
4a4d8108 | 19867 | +int aufs_unlink(struct inode *dir, struct dentry *dentry) |
1308ab2a | 19868 | +{ |
4a4d8108 AM |
19869 | + int err; |
19870 | + aufs_bindex_t bwh, bindex, bstart; | |
523b37e3 | 19871 | + struct inode *inode, *h_dir, *delegated; |
4a4d8108 | 19872 | + struct dentry *parent, *wh_dentry; |
c2b27bf2 AM |
19873 | + /* to reuduce stack size */ |
19874 | + struct { | |
19875 | + struct au_dtime dt; | |
19876 | + struct au_pin pin; | |
19877 | + struct path h_path; | |
19878 | + } *a; | |
1facf9fc | 19879 | + |
4a4d8108 | 19880 | + IMustLock(dir); |
027c5e7a | 19881 | + |
c2b27bf2 AM |
19882 | + err = -ENOMEM; |
19883 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19884 | + if (unlikely(!a)) | |
19885 | + goto out; | |
19886 | + | |
027c5e7a AM |
19887 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
19888 | + if (unlikely(err)) | |
c2b27bf2 | 19889 | + goto out_free; |
027c5e7a AM |
19890 | + err = au_d_hashed_positive(dentry); |
19891 | + if (unlikely(err)) | |
19892 | + goto out_unlock; | |
5527c038 | 19893 | + inode = d_inode(dentry); |
4a4d8108 | 19894 | + IMustLock(inode); |
027c5e7a | 19895 | + err = -EISDIR; |
2000de60 | 19896 | + if (unlikely(d_is_dir(dentry))) |
027c5e7a | 19897 | + goto out_unlock; /* possible? */ |
1facf9fc | 19898 | + |
4a4d8108 AM |
19899 | + bstart = au_dbstart(dentry); |
19900 | + bwh = au_dbwh(dentry); | |
19901 | + bindex = -1; | |
027c5e7a AM |
19902 | + parent = dentry->d_parent; /* dir inode is locked */ |
19903 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
19904 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt, |
19905 | + &a->pin); | |
4a4d8108 AM |
19906 | + err = PTR_ERR(wh_dentry); |
19907 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 19908 | + goto out_parent; |
1facf9fc | 19909 | + |
c2b27bf2 AM |
19910 | + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart); |
19911 | + a->h_path.dentry = au_h_dptr(dentry, bstart); | |
19912 | + dget(a->h_path.dentry); | |
4a4d8108 | 19913 | + if (bindex == bstart) { |
c2b27bf2 | 19914 | + h_dir = au_pinned_h_dir(&a->pin); |
523b37e3 AM |
19915 | + delegated = NULL; |
19916 | + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0); | |
19917 | + if (unlikely(err == -EWOULDBLOCK)) { | |
19918 | + pr_warn("cannot retry for NFSv4 delegation" | |
19919 | + " for an internal unlink\n"); | |
19920 | + iput(delegated); | |
19921 | + } | |
4a4d8108 AM |
19922 | + } else { |
19923 | + /* dir inode is locked */ | |
5527c038 | 19924 | + h_dir = d_inode(wh_dentry->d_parent); |
4a4d8108 AM |
19925 | + IMustLock(h_dir); |
19926 | + err = 0; | |
19927 | + } | |
dece6358 | 19928 | + |
4a4d8108 | 19929 | + if (!err) { |
7f207e10 | 19930 | + vfsub_drop_nlink(inode); |
4a4d8108 AM |
19931 | + epilog(dir, dentry, bindex); |
19932 | + | |
19933 | + /* update target timestamps */ | |
19934 | + if (bindex == bstart) { | |
c2b27bf2 AM |
19935 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); |
19936 | + /*ignore*/ | |
5527c038 | 19937 | + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
4a4d8108 AM |
19938 | + } else |
19939 | + /* todo: this timestamp may be reverted later */ | |
19940 | + inode->i_ctime = h_dir->i_ctime; | |
027c5e7a | 19941 | + goto out_unpin; /* success */ |
1facf9fc | 19942 | + } |
19943 | + | |
4a4d8108 AM |
19944 | + /* revert */ |
19945 | + if (wh_dentry) { | |
19946 | + int rerr; | |
19947 | + | |
c2b27bf2 AM |
19948 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
19949 | + &a->dt); | |
4a4d8108 AM |
19950 | + if (rerr) |
19951 | + err = rerr; | |
dece6358 | 19952 | + } |
1facf9fc | 19953 | + |
027c5e7a | 19954 | +out_unpin: |
c2b27bf2 | 19955 | + au_unpin(&a->pin); |
4a4d8108 | 19956 | + dput(wh_dentry); |
c2b27bf2 | 19957 | + dput(a->h_path.dentry); |
027c5e7a | 19958 | +out_parent: |
4a4d8108 | 19959 | + di_write_unlock(parent); |
027c5e7a | 19960 | +out_unlock: |
4a4d8108 | 19961 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 AM |
19962 | +out_free: |
19963 | + kfree(a); | |
027c5e7a | 19964 | +out: |
4a4d8108 | 19965 | + return err; |
dece6358 AM |
19966 | +} |
19967 | + | |
4a4d8108 | 19968 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry) |
1308ab2a | 19969 | +{ |
4a4d8108 AM |
19970 | + int err, rmdir_later; |
19971 | + aufs_bindex_t bwh, bindex, bstart; | |
4a4d8108 AM |
19972 | + struct inode *inode; |
19973 | + struct dentry *parent, *wh_dentry, *h_dentry; | |
19974 | + struct au_whtmp_rmdir *args; | |
c2b27bf2 AM |
19975 | + /* to reuduce stack size */ |
19976 | + struct { | |
19977 | + struct au_dtime dt; | |
19978 | + struct au_pin pin; | |
19979 | + } *a; | |
1facf9fc | 19980 | + |
4a4d8108 | 19981 | + IMustLock(dir); |
027c5e7a | 19982 | + |
c2b27bf2 AM |
19983 | + err = -ENOMEM; |
19984 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19985 | + if (unlikely(!a)) | |
19986 | + goto out; | |
19987 | + | |
027c5e7a AM |
19988 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); |
19989 | + if (unlikely(err)) | |
c2b27bf2 | 19990 | + goto out_free; |
53392da6 AM |
19991 | + err = au_alive_dir(dentry); |
19992 | + if (unlikely(err)) | |
027c5e7a | 19993 | + goto out_unlock; |
5527c038 | 19994 | + inode = d_inode(dentry); |
4a4d8108 | 19995 | + IMustLock(inode); |
027c5e7a | 19996 | + err = -ENOTDIR; |
2000de60 | 19997 | + if (unlikely(!d_is_dir(dentry))) |
027c5e7a | 19998 | + goto out_unlock; /* possible? */ |
dece6358 | 19999 | + |
4a4d8108 AM |
20000 | + err = -ENOMEM; |
20001 | + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS); | |
20002 | + if (unlikely(!args)) | |
20003 | + goto out_unlock; | |
dece6358 | 20004 | + |
4a4d8108 AM |
20005 | + parent = dentry->d_parent; /* dir inode is locked */ |
20006 | + di_write_lock_parent(parent); | |
20007 | + err = au_test_empty(dentry, &args->whlist); | |
20008 | + if (unlikely(err)) | |
027c5e7a | 20009 | + goto out_parent; |
1facf9fc | 20010 | + |
4a4d8108 AM |
20011 | + bstart = au_dbstart(dentry); |
20012 | + bwh = au_dbwh(dentry); | |
20013 | + bindex = -1; | |
c2b27bf2 AM |
20014 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt, |
20015 | + &a->pin); | |
4a4d8108 AM |
20016 | + err = PTR_ERR(wh_dentry); |
20017 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20018 | + goto out_parent; |
1facf9fc | 20019 | + |
4a4d8108 AM |
20020 | + h_dentry = au_h_dptr(dentry, bstart); |
20021 | + dget(h_dentry); | |
20022 | + rmdir_later = 0; | |
20023 | + if (bindex == bstart) { | |
20024 | + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir); | |
20025 | + if (err > 0) { | |
20026 | + rmdir_later = err; | |
20027 | + err = 0; | |
20028 | + } | |
20029 | + } else { | |
20030 | + /* stop monitoring */ | |
20031 | + au_hn_free(au_hi(inode, bstart)); | |
20032 | + | |
20033 | + /* dir inode is locked */ | |
5527c038 | 20034 | + IMustLock(d_inode(wh_dentry->d_parent)); |
1facf9fc | 20035 | + err = 0; |
20036 | + } | |
20037 | + | |
4a4d8108 | 20038 | + if (!err) { |
027c5e7a | 20039 | + vfsub_dead_dir(inode); |
4a4d8108 AM |
20040 | + au_set_dbdiropq(dentry, -1); |
20041 | + epilog(dir, dentry, bindex); | |
1308ab2a | 20042 | + |
4a4d8108 AM |
20043 | + if (rmdir_later) { |
20044 | + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args); | |
20045 | + args = NULL; | |
20046 | + } | |
1308ab2a | 20047 | + |
4a4d8108 | 20048 | + goto out_unpin; /* success */ |
1facf9fc | 20049 | + } |
20050 | + | |
4a4d8108 AM |
20051 | + /* revert */ |
20052 | + AuLabel(revert); | |
20053 | + if (wh_dentry) { | |
20054 | + int rerr; | |
1308ab2a | 20055 | + |
c2b27bf2 AM |
20056 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
20057 | + &a->dt); | |
4a4d8108 AM |
20058 | + if (rerr) |
20059 | + err = rerr; | |
1facf9fc | 20060 | + } |
20061 | + | |
4f0767ce | 20062 | +out_unpin: |
c2b27bf2 | 20063 | + au_unpin(&a->pin); |
4a4d8108 AM |
20064 | + dput(wh_dentry); |
20065 | + dput(h_dentry); | |
027c5e7a | 20066 | +out_parent: |
4a4d8108 AM |
20067 | + di_write_unlock(parent); |
20068 | + if (args) | |
20069 | + au_whtmp_rmdir_free(args); | |
4f0767ce | 20070 | +out_unlock: |
4a4d8108 | 20071 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 AM |
20072 | +out_free: |
20073 | + kfree(a); | |
4f0767ce | 20074 | +out: |
4a4d8108 AM |
20075 | + AuTraceErr(err); |
20076 | + return err; | |
dece6358 | 20077 | +} |
7f207e10 AM |
20078 | diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c |
20079 | --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
20080 | +++ linux/fs/aufs/i_op_ren.c 2015-06-28 17:36:09.025073697 +0200 |
20081 | @@ -0,0 +1,1017 @@ | |
1facf9fc | 20082 | +/* |
2000de60 | 20083 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 20084 | + * |
20085 | + * This program, aufs is free software; you can redistribute it and/or modify | |
20086 | + * it under the terms of the GNU General Public License as published by | |
20087 | + * the Free Software Foundation; either version 2 of the License, or | |
20088 | + * (at your option) any later version. | |
dece6358 AM |
20089 | + * |
20090 | + * This program is distributed in the hope that it will be useful, | |
20091 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20092 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20093 | + * GNU General Public License for more details. | |
20094 | + * | |
20095 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 20096 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 20097 | + */ |
20098 | + | |
20099 | +/* | |
4a4d8108 AM |
20100 | + * inode operation (rename entry) |
20101 | + * todo: this is crazy monster | |
1facf9fc | 20102 | + */ |
20103 | + | |
20104 | +#include "aufs.h" | |
20105 | + | |
4a4d8108 AM |
20106 | +enum { AuSRC, AuDST, AuSrcDst }; |
20107 | +enum { AuPARENT, AuCHILD, AuParentChild }; | |
1facf9fc | 20108 | + |
4a4d8108 AM |
20109 | +#define AuRen_ISDIR 1 |
20110 | +#define AuRen_ISSAMEDIR (1 << 1) | |
20111 | +#define AuRen_WHSRC (1 << 2) | |
20112 | +#define AuRen_WHDST (1 << 3) | |
20113 | +#define AuRen_MNT_WRITE (1 << 4) | |
20114 | +#define AuRen_DT_DSTDIR (1 << 5) | |
20115 | +#define AuRen_DIROPQ (1 << 6) | |
4a4d8108 | 20116 | +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name) |
7f207e10 AM |
20117 | +#define au_fset_ren(flags, name) \ |
20118 | + do { (flags) |= AuRen_##name; } while (0) | |
20119 | +#define au_fclr_ren(flags, name) \ | |
20120 | + do { (flags) &= ~AuRen_##name; } while (0) | |
1facf9fc | 20121 | + |
4a4d8108 AM |
20122 | +struct au_ren_args { |
20123 | + struct { | |
20124 | + struct dentry *dentry, *h_dentry, *parent, *h_parent, | |
20125 | + *wh_dentry; | |
20126 | + struct inode *dir, *inode; | |
20127 | + struct au_hinode *hdir; | |
20128 | + struct au_dtime dt[AuParentChild]; | |
20129 | + aufs_bindex_t bstart; | |
20130 | + } sd[AuSrcDst]; | |
1facf9fc | 20131 | + |
4a4d8108 AM |
20132 | +#define src_dentry sd[AuSRC].dentry |
20133 | +#define src_dir sd[AuSRC].dir | |
20134 | +#define src_inode sd[AuSRC].inode | |
20135 | +#define src_h_dentry sd[AuSRC].h_dentry | |
20136 | +#define src_parent sd[AuSRC].parent | |
20137 | +#define src_h_parent sd[AuSRC].h_parent | |
20138 | +#define src_wh_dentry sd[AuSRC].wh_dentry | |
20139 | +#define src_hdir sd[AuSRC].hdir | |
20140 | +#define src_h_dir sd[AuSRC].hdir->hi_inode | |
20141 | +#define src_dt sd[AuSRC].dt | |
20142 | +#define src_bstart sd[AuSRC].bstart | |
1facf9fc | 20143 | + |
4a4d8108 AM |
20144 | +#define dst_dentry sd[AuDST].dentry |
20145 | +#define dst_dir sd[AuDST].dir | |
20146 | +#define dst_inode sd[AuDST].inode | |
20147 | +#define dst_h_dentry sd[AuDST].h_dentry | |
20148 | +#define dst_parent sd[AuDST].parent | |
20149 | +#define dst_h_parent sd[AuDST].h_parent | |
20150 | +#define dst_wh_dentry sd[AuDST].wh_dentry | |
20151 | +#define dst_hdir sd[AuDST].hdir | |
20152 | +#define dst_h_dir sd[AuDST].hdir->hi_inode | |
20153 | +#define dst_dt sd[AuDST].dt | |
20154 | +#define dst_bstart sd[AuDST].bstart | |
20155 | + | |
20156 | + struct dentry *h_trap; | |
20157 | + struct au_branch *br; | |
20158 | + struct au_hinode *src_hinode; | |
20159 | + struct path h_path; | |
20160 | + struct au_nhash whlist; | |
027c5e7a | 20161 | + aufs_bindex_t btgt, src_bwh, src_bdiropq; |
1facf9fc | 20162 | + |
1308ab2a | 20163 | + unsigned int flags; |
1facf9fc | 20164 | + |
4a4d8108 AM |
20165 | + struct au_whtmp_rmdir *thargs; |
20166 | + struct dentry *h_dst; | |
20167 | +}; | |
1308ab2a | 20168 | + |
4a4d8108 | 20169 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 20170 | + |
4a4d8108 AM |
20171 | +/* |
20172 | + * functions for reverting. | |
20173 | + * when an error happened in a single rename systemcall, we should revert | |
20174 | + * everything as if nothing happend. | |
20175 | + * we don't need to revert the copied-up/down the parent dir since they are | |
20176 | + * harmless. | |
20177 | + */ | |
1facf9fc | 20178 | + |
4a4d8108 AM |
20179 | +#define RevertFailure(fmt, ...) do { \ |
20180 | + AuIOErr("revert failure: " fmt " (%d, %d)\n", \ | |
20181 | + ##__VA_ARGS__, err, rerr); \ | |
20182 | + err = -EIO; \ | |
20183 | +} while (0) | |
1facf9fc | 20184 | + |
4a4d8108 | 20185 | +static void au_ren_rev_diropq(int err, struct au_ren_args *a) |
1facf9fc | 20186 | +{ |
4a4d8108 | 20187 | + int rerr; |
1facf9fc | 20188 | + |
4a4d8108 AM |
20189 | + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD); |
20190 | + rerr = au_diropq_remove(a->src_dentry, a->btgt); | |
20191 | + au_hn_imtx_unlock(a->src_hinode); | |
027c5e7a | 20192 | + au_set_dbdiropq(a->src_dentry, a->src_bdiropq); |
4a4d8108 | 20193 | + if (rerr) |
523b37e3 | 20194 | + RevertFailure("remove diropq %pd", a->src_dentry); |
4a4d8108 | 20195 | +} |
1facf9fc | 20196 | + |
4a4d8108 AM |
20197 | +static void au_ren_rev_rename(int err, struct au_ren_args *a) |
20198 | +{ | |
20199 | + int rerr; | |
523b37e3 | 20200 | + struct inode *delegated; |
1facf9fc | 20201 | + |
b4510431 AM |
20202 | + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, |
20203 | + a->src_h_parent); | |
4a4d8108 AM |
20204 | + rerr = PTR_ERR(a->h_path.dentry); |
20205 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 20206 | + RevertFailure("lkup one %pd", a->src_dentry); |
4a4d8108 | 20207 | + return; |
1facf9fc | 20208 | + } |
20209 | + | |
523b37e3 | 20210 | + delegated = NULL; |
4a4d8108 AM |
20211 | + rerr = vfsub_rename(a->dst_h_dir, |
20212 | + au_h_dptr(a->src_dentry, a->btgt), | |
523b37e3 AM |
20213 | + a->src_h_dir, &a->h_path, &delegated); |
20214 | + if (unlikely(rerr == -EWOULDBLOCK)) { | |
20215 | + pr_warn("cannot retry for NFSv4 delegation" | |
20216 | + " for an internal rename\n"); | |
20217 | + iput(delegated); | |
20218 | + } | |
4a4d8108 AM |
20219 | + d_drop(a->h_path.dentry); |
20220 | + dput(a->h_path.dentry); | |
20221 | + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */ | |
20222 | + if (rerr) | |
523b37e3 | 20223 | + RevertFailure("rename %pd", a->src_dentry); |
1facf9fc | 20224 | +} |
20225 | + | |
4a4d8108 | 20226 | +static void au_ren_rev_whtmp(int err, struct au_ren_args *a) |
1facf9fc | 20227 | +{ |
4a4d8108 | 20228 | + int rerr; |
523b37e3 | 20229 | + struct inode *delegated; |
dece6358 | 20230 | + |
b4510431 AM |
20231 | + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, |
20232 | + a->dst_h_parent); | |
4a4d8108 AM |
20233 | + rerr = PTR_ERR(a->h_path.dentry); |
20234 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 20235 | + RevertFailure("lkup one %pd", a->dst_dentry); |
4a4d8108 AM |
20236 | + return; |
20237 | + } | |
5527c038 | 20238 | + if (d_is_positive(a->h_path.dentry)) { |
4a4d8108 AM |
20239 | + d_drop(a->h_path.dentry); |
20240 | + dput(a->h_path.dentry); | |
20241 | + return; | |
dece6358 AM |
20242 | + } |
20243 | + | |
523b37e3 AM |
20244 | + delegated = NULL; |
20245 | + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path, | |
20246 | + &delegated); | |
20247 | + if (unlikely(rerr == -EWOULDBLOCK)) { | |
20248 | + pr_warn("cannot retry for NFSv4 delegation" | |
20249 | + " for an internal rename\n"); | |
20250 | + iput(delegated); | |
20251 | + } | |
4a4d8108 AM |
20252 | + d_drop(a->h_path.dentry); |
20253 | + dput(a->h_path.dentry); | |
20254 | + if (!rerr) | |
20255 | + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst)); | |
20256 | + else | |
523b37e3 | 20257 | + RevertFailure("rename %pd", a->h_dst); |
4a4d8108 | 20258 | +} |
1308ab2a | 20259 | + |
4a4d8108 AM |
20260 | +static void au_ren_rev_whsrc(int err, struct au_ren_args *a) |
20261 | +{ | |
20262 | + int rerr; | |
1308ab2a | 20263 | + |
4a4d8108 AM |
20264 | + a->h_path.dentry = a->src_wh_dentry; |
20265 | + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry); | |
027c5e7a | 20266 | + au_set_dbwh(a->src_dentry, a->src_bwh); |
4a4d8108 | 20267 | + if (rerr) |
523b37e3 | 20268 | + RevertFailure("unlink %pd", a->src_wh_dentry); |
4a4d8108 | 20269 | +} |
4a4d8108 | 20270 | +#undef RevertFailure |
1facf9fc | 20271 | + |
1308ab2a | 20272 | +/* ---------------------------------------------------------------------- */ |
20273 | + | |
4a4d8108 AM |
20274 | +/* |
20275 | + * when we have to copyup the renaming entry, do it with the rename-target name | |
20276 | + * in order to minimize the cost (the later actual rename is unnecessary). | |
20277 | + * otherwise rename it on the target branch. | |
20278 | + */ | |
20279 | +static int au_ren_or_cpup(struct au_ren_args *a) | |
1facf9fc | 20280 | +{ |
dece6358 | 20281 | + int err; |
4a4d8108 | 20282 | + struct dentry *d; |
523b37e3 | 20283 | + struct inode *delegated; |
1facf9fc | 20284 | + |
4a4d8108 AM |
20285 | + d = a->src_dentry; |
20286 | + if (au_dbstart(d) == a->btgt) { | |
20287 | + a->h_path.dentry = a->dst_h_dentry; | |
20288 | + if (au_ftest_ren(a->flags, DIROPQ) | |
20289 | + && au_dbdiropq(d) == a->btgt) | |
20290 | + au_fclr_ren(a->flags, DIROPQ); | |
20291 | + AuDebugOn(au_dbstart(d) != a->btgt); | |
523b37e3 | 20292 | + delegated = NULL; |
4a4d8108 | 20293 | + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt), |
523b37e3 AM |
20294 | + a->dst_h_dir, &a->h_path, &delegated); |
20295 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20296 | + pr_warn("cannot retry for NFSv4 delegation" | |
20297 | + " for an internal rename\n"); | |
20298 | + iput(delegated); | |
20299 | + } | |
c2b27bf2 | 20300 | + } else |
86dc4139 | 20301 | + BUG(); |
1308ab2a | 20302 | + |
027c5e7a AM |
20303 | + if (!err && a->h_dst) |
20304 | + /* it will be set to dinfo later */ | |
20305 | + dget(a->h_dst); | |
1facf9fc | 20306 | + |
dece6358 AM |
20307 | + return err; |
20308 | +} | |
1facf9fc | 20309 | + |
4a4d8108 AM |
20310 | +/* cf. aufs_rmdir() */ |
20311 | +static int au_ren_del_whtmp(struct au_ren_args *a) | |
dece6358 | 20312 | +{ |
4a4d8108 AM |
20313 | + int err; |
20314 | + struct inode *dir; | |
1facf9fc | 20315 | + |
4a4d8108 AM |
20316 | + dir = a->dst_dir; |
20317 | + SiMustAnyLock(dir->i_sb); | |
20318 | + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt, | |
20319 | + au_sbi(dir->i_sb)->si_dirwh) | |
20320 | + || au_test_fs_remote(a->h_dst->d_sb)) { | |
20321 | + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist); | |
20322 | + if (unlikely(err)) | |
523b37e3 AM |
20323 | + pr_warn("failed removing whtmp dir %pd (%d), " |
20324 | + "ignored.\n", a->h_dst, err); | |
4a4d8108 AM |
20325 | + } else { |
20326 | + au_nhash_wh_free(&a->thargs->whlist); | |
20327 | + a->thargs->whlist = a->whlist; | |
20328 | + a->whlist.nh_num = 0; | |
20329 | + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs); | |
20330 | + dput(a->h_dst); | |
20331 | + a->thargs = NULL; | |
20332 | + } | |
20333 | + | |
20334 | + return 0; | |
1308ab2a | 20335 | +} |
1facf9fc | 20336 | + |
4a4d8108 AM |
20337 | +/* make it 'opaque' dir. */ |
20338 | +static int au_ren_diropq(struct au_ren_args *a) | |
20339 | +{ | |
20340 | + int err; | |
20341 | + struct dentry *diropq; | |
1facf9fc | 20342 | + |
4a4d8108 | 20343 | + err = 0; |
027c5e7a | 20344 | + a->src_bdiropq = au_dbdiropq(a->src_dentry); |
4a4d8108 AM |
20345 | + a->src_hinode = au_hi(a->src_inode, a->btgt); |
20346 | + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD); | |
20347 | + diropq = au_diropq_create(a->src_dentry, a->btgt); | |
20348 | + au_hn_imtx_unlock(a->src_hinode); | |
20349 | + if (IS_ERR(diropq)) | |
20350 | + err = PTR_ERR(diropq); | |
076b876e AM |
20351 | + else |
20352 | + dput(diropq); | |
1facf9fc | 20353 | + |
4a4d8108 AM |
20354 | + return err; |
20355 | +} | |
1facf9fc | 20356 | + |
4a4d8108 AM |
20357 | +static int do_rename(struct au_ren_args *a) |
20358 | +{ | |
20359 | + int err; | |
20360 | + struct dentry *d, *h_d; | |
1facf9fc | 20361 | + |
4a4d8108 AM |
20362 | + /* prepare workqueue args for asynchronous rmdir */ |
20363 | + h_d = a->dst_h_dentry; | |
5527c038 | 20364 | + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) { |
4a4d8108 AM |
20365 | + err = -ENOMEM; |
20366 | + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS); | |
20367 | + if (unlikely(!a->thargs)) | |
20368 | + goto out; | |
20369 | + a->h_dst = dget(h_d); | |
20370 | + } | |
1facf9fc | 20371 | + |
4a4d8108 AM |
20372 | + /* create whiteout for src_dentry */ |
20373 | + if (au_ftest_ren(a->flags, WHSRC)) { | |
027c5e7a AM |
20374 | + a->src_bwh = au_dbwh(a->src_dentry); |
20375 | + AuDebugOn(a->src_bwh >= 0); | |
4a4d8108 AM |
20376 | + a->src_wh_dentry |
20377 | + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent); | |
20378 | + err = PTR_ERR(a->src_wh_dentry); | |
20379 | + if (IS_ERR(a->src_wh_dentry)) | |
20380 | + goto out_thargs; | |
20381 | + } | |
1facf9fc | 20382 | + |
4a4d8108 AM |
20383 | + /* lookup whiteout for dentry */ |
20384 | + if (au_ftest_ren(a->flags, WHDST)) { | |
20385 | + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name, | |
20386 | + a->br); | |
20387 | + err = PTR_ERR(h_d); | |
20388 | + if (IS_ERR(h_d)) | |
20389 | + goto out_whsrc; | |
5527c038 | 20390 | + if (d_is_negative(h_d)) |
4a4d8108 AM |
20391 | + dput(h_d); |
20392 | + else | |
20393 | + a->dst_wh_dentry = h_d; | |
20394 | + } | |
1facf9fc | 20395 | + |
4a4d8108 AM |
20396 | + /* rename dentry to tmpwh */ |
20397 | + if (a->thargs) { | |
20398 | + err = au_whtmp_ren(a->dst_h_dentry, a->br); | |
20399 | + if (unlikely(err)) | |
20400 | + goto out_whdst; | |
dece6358 | 20401 | + |
4a4d8108 AM |
20402 | + d = a->dst_dentry; |
20403 | + au_set_h_dptr(d, a->btgt, NULL); | |
86dc4139 | 20404 | + err = au_lkup_neg(d, a->btgt, /*wh*/0); |
4a4d8108 AM |
20405 | + if (unlikely(err)) |
20406 | + goto out_whtmp; | |
20407 | + a->dst_h_dentry = au_h_dptr(d, a->btgt); | |
20408 | + } | |
1facf9fc | 20409 | + |
5527c038 | 20410 | + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_bstart != a->btgt); |
1facf9fc | 20411 | + |
4a4d8108 AM |
20412 | + /* rename by vfs_rename or cpup */ |
20413 | + d = a->dst_dentry; | |
20414 | + if (au_ftest_ren(a->flags, ISDIR) | |
20415 | + && (a->dst_wh_dentry | |
20416 | + || au_dbdiropq(d) == a->btgt | |
20417 | + /* hide the lower to keep xino */ | |
20418 | + || a->btgt < au_dbend(d) | |
20419 | + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ))) | |
20420 | + au_fset_ren(a->flags, DIROPQ); | |
20421 | + err = au_ren_or_cpup(a); | |
20422 | + if (unlikely(err)) | |
20423 | + /* leave the copied-up one */ | |
20424 | + goto out_whtmp; | |
1308ab2a | 20425 | + |
4a4d8108 AM |
20426 | + /* make dir opaque */ |
20427 | + if (au_ftest_ren(a->flags, DIROPQ)) { | |
20428 | + err = au_ren_diropq(a); | |
20429 | + if (unlikely(err)) | |
20430 | + goto out_rename; | |
20431 | + } | |
1308ab2a | 20432 | + |
4a4d8108 AM |
20433 | + /* update target timestamps */ |
20434 | + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt); | |
20435 | + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt); | |
20436 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
5527c038 | 20437 | + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
1facf9fc | 20438 | + |
4a4d8108 AM |
20439 | + /* remove whiteout for dentry */ |
20440 | + if (a->dst_wh_dentry) { | |
20441 | + a->h_path.dentry = a->dst_wh_dentry; | |
20442 | + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path, | |
20443 | + a->dst_dentry); | |
20444 | + if (unlikely(err)) | |
20445 | + goto out_diropq; | |
20446 | + } | |
1facf9fc | 20447 | + |
4a4d8108 AM |
20448 | + /* remove whtmp */ |
20449 | + if (a->thargs) | |
20450 | + au_ren_del_whtmp(a); /* ignore this error */ | |
1308ab2a | 20451 | + |
076b876e | 20452 | + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0); |
4a4d8108 AM |
20453 | + err = 0; |
20454 | + goto out_success; | |
20455 | + | |
4f0767ce | 20456 | +out_diropq: |
4a4d8108 AM |
20457 | + if (au_ftest_ren(a->flags, DIROPQ)) |
20458 | + au_ren_rev_diropq(err, a); | |
4f0767ce | 20459 | +out_rename: |
7e9cd9fe | 20460 | + au_ren_rev_rename(err, a); |
027c5e7a | 20461 | + dput(a->h_dst); |
4f0767ce | 20462 | +out_whtmp: |
4a4d8108 AM |
20463 | + if (a->thargs) |
20464 | + au_ren_rev_whtmp(err, a); | |
4f0767ce | 20465 | +out_whdst: |
4a4d8108 AM |
20466 | + dput(a->dst_wh_dentry); |
20467 | + a->dst_wh_dentry = NULL; | |
4f0767ce | 20468 | +out_whsrc: |
4a4d8108 AM |
20469 | + if (a->src_wh_dentry) |
20470 | + au_ren_rev_whsrc(err, a); | |
4f0767ce | 20471 | +out_success: |
4a4d8108 AM |
20472 | + dput(a->src_wh_dentry); |
20473 | + dput(a->dst_wh_dentry); | |
4f0767ce | 20474 | +out_thargs: |
4a4d8108 AM |
20475 | + if (a->thargs) { |
20476 | + dput(a->h_dst); | |
20477 | + au_whtmp_rmdir_free(a->thargs); | |
20478 | + a->thargs = NULL; | |
20479 | + } | |
4f0767ce | 20480 | +out: |
4a4d8108 | 20481 | + return err; |
dece6358 | 20482 | +} |
1facf9fc | 20483 | + |
1308ab2a | 20484 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20485 | + |
4a4d8108 AM |
20486 | +/* |
20487 | + * test if @dentry dir can be rename destination or not. | |
20488 | + * success means, it is a logically empty dir. | |
20489 | + */ | |
20490 | +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist) | |
1308ab2a | 20491 | +{ |
4a4d8108 | 20492 | + return au_test_empty(dentry, whlist); |
1308ab2a | 20493 | +} |
1facf9fc | 20494 | + |
4a4d8108 AM |
20495 | +/* |
20496 | + * test if @dentry dir can be rename source or not. | |
20497 | + * if it can, return 0 and @children is filled. | |
20498 | + * success means, | |
20499 | + * - it is a logically empty dir. | |
20500 | + * - or, it exists on writable branch and has no children including whiteouts | |
20501 | + * on the lower branch. | |
20502 | + */ | |
20503 | +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt) | |
20504 | +{ | |
20505 | + int err; | |
20506 | + unsigned int rdhash; | |
20507 | + aufs_bindex_t bstart; | |
1facf9fc | 20508 | + |
4a4d8108 AM |
20509 | + bstart = au_dbstart(dentry); |
20510 | + if (bstart != btgt) { | |
20511 | + struct au_nhash whlist; | |
dece6358 | 20512 | + |
4a4d8108 AM |
20513 | + SiMustAnyLock(dentry->d_sb); |
20514 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; | |
20515 | + if (!rdhash) | |
20516 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, | |
20517 | + dentry)); | |
20518 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
20519 | + if (unlikely(err)) | |
20520 | + goto out; | |
20521 | + err = au_test_empty(dentry, &whlist); | |
20522 | + au_nhash_wh_free(&whlist); | |
20523 | + goto out; | |
20524 | + } | |
dece6358 | 20525 | + |
4a4d8108 AM |
20526 | + if (bstart == au_dbtaildir(dentry)) |
20527 | + return 0; /* success */ | |
dece6358 | 20528 | + |
4a4d8108 | 20529 | + err = au_test_empty_lower(dentry); |
1facf9fc | 20530 | + |
4f0767ce | 20531 | +out: |
4a4d8108 AM |
20532 | + if (err == -ENOTEMPTY) { |
20533 | + AuWarn1("renaming dir who has child(ren) on multiple branches," | |
20534 | + " is not supported\n"); | |
20535 | + err = -EXDEV; | |
20536 | + } | |
20537 | + return err; | |
20538 | +} | |
1308ab2a | 20539 | + |
4a4d8108 AM |
20540 | +/* side effect: sets whlist and h_dentry */ |
20541 | +static int au_ren_may_dir(struct au_ren_args *a) | |
1308ab2a | 20542 | +{ |
4a4d8108 AM |
20543 | + int err; |
20544 | + unsigned int rdhash; | |
20545 | + struct dentry *d; | |
1facf9fc | 20546 | + |
4a4d8108 AM |
20547 | + d = a->dst_dentry; |
20548 | + SiMustAnyLock(d->d_sb); | |
1facf9fc | 20549 | + |
4a4d8108 AM |
20550 | + err = 0; |
20551 | + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) { | |
20552 | + rdhash = au_sbi(d->d_sb)->si_rdhash; | |
20553 | + if (!rdhash) | |
20554 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d)); | |
20555 | + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS); | |
20556 | + if (unlikely(err)) | |
20557 | + goto out; | |
1308ab2a | 20558 | + |
4a4d8108 AM |
20559 | + au_set_dbstart(d, a->dst_bstart); |
20560 | + err = may_rename_dstdir(d, &a->whlist); | |
20561 | + au_set_dbstart(d, a->btgt); | |
20562 | + } | |
20563 | + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d)); | |
20564 | + if (unlikely(err)) | |
20565 | + goto out; | |
20566 | + | |
20567 | + d = a->src_dentry; | |
20568 | + a->src_h_dentry = au_h_dptr(d, au_dbstart(d)); | |
20569 | + if (au_ftest_ren(a->flags, ISDIR)) { | |
20570 | + err = may_rename_srcdir(d, a->btgt); | |
20571 | + if (unlikely(err)) { | |
20572 | + au_nhash_wh_free(&a->whlist); | |
20573 | + a->whlist.nh_num = 0; | |
20574 | + } | |
20575 | + } | |
4f0767ce | 20576 | +out: |
4a4d8108 | 20577 | + return err; |
1facf9fc | 20578 | +} |
20579 | + | |
4a4d8108 | 20580 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20581 | + |
4a4d8108 AM |
20582 | +/* |
20583 | + * simple tests for rename. | |
20584 | + * following the checks in vfs, plus the parent-child relationship. | |
20585 | + */ | |
20586 | +static int au_may_ren(struct au_ren_args *a) | |
20587 | +{ | |
20588 | + int err, isdir; | |
20589 | + struct inode *h_inode; | |
1facf9fc | 20590 | + |
4a4d8108 AM |
20591 | + if (a->src_bstart == a->btgt) { |
20592 | + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent, | |
20593 | + au_ftest_ren(a->flags, ISDIR)); | |
20594 | + if (unlikely(err)) | |
20595 | + goto out; | |
20596 | + err = -EINVAL; | |
20597 | + if (unlikely(a->src_h_dentry == a->h_trap)) | |
20598 | + goto out; | |
20599 | + } | |
1facf9fc | 20600 | + |
4a4d8108 AM |
20601 | + err = 0; |
20602 | + if (a->dst_bstart != a->btgt) | |
20603 | + goto out; | |
1facf9fc | 20604 | + |
027c5e7a AM |
20605 | + err = -ENOTEMPTY; |
20606 | + if (unlikely(a->dst_h_dentry == a->h_trap)) | |
20607 | + goto out; | |
20608 | + | |
4a4d8108 | 20609 | + err = -EIO; |
4a4d8108 | 20610 | + isdir = !!au_ftest_ren(a->flags, ISDIR); |
5527c038 JR |
20611 | + if (d_really_is_negative(a->dst_dentry)) { |
20612 | + if (d_is_negative(a->dst_h_dentry)) | |
20613 | + err = au_may_add(a->dst_dentry, a->btgt, | |
20614 | + a->dst_h_parent, isdir); | |
4a4d8108 | 20615 | + } else { |
5527c038 | 20616 | + if (unlikely(d_is_negative(a->dst_h_dentry))) |
4a4d8108 | 20617 | + goto out; |
5527c038 JR |
20618 | + h_inode = d_inode(a->dst_h_dentry); |
20619 | + if (h_inode->i_nlink) | |
20620 | + err = au_may_del(a->dst_dentry, a->btgt, | |
20621 | + a->dst_h_parent, isdir); | |
4a4d8108 | 20622 | + } |
1facf9fc | 20623 | + |
4f0767ce | 20624 | +out: |
4a4d8108 AM |
20625 | + if (unlikely(err == -ENOENT || err == -EEXIST)) |
20626 | + err = -EIO; | |
20627 | + AuTraceErr(err); | |
20628 | + return err; | |
20629 | +} | |
1facf9fc | 20630 | + |
1308ab2a | 20631 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20632 | + |
4a4d8108 AM |
20633 | +/* |
20634 | + * locking order | |
20635 | + * (VFS) | |
20636 | + * - src_dir and dir by lock_rename() | |
20637 | + * - inode if exitsts | |
20638 | + * (aufs) | |
20639 | + * - lock all | |
20640 | + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls, | |
20641 | + * + si_read_lock | |
20642 | + * + di_write_lock2_child() | |
20643 | + * + di_write_lock_child() | |
20644 | + * + ii_write_lock_child() | |
20645 | + * + di_write_lock_child2() | |
20646 | + * + ii_write_lock_child2() | |
20647 | + * + src_parent and parent | |
20648 | + * + di_write_lock_parent() | |
20649 | + * + ii_write_lock_parent() | |
20650 | + * + di_write_lock_parent2() | |
20651 | + * + ii_write_lock_parent2() | |
20652 | + * + lower src_dir and dir by vfsub_lock_rename() | |
20653 | + * + verify the every relationships between child and parent. if any | |
20654 | + * of them failed, unlock all and return -EBUSY. | |
20655 | + */ | |
20656 | +static void au_ren_unlock(struct au_ren_args *a) | |
1308ab2a | 20657 | +{ |
4a4d8108 AM |
20658 | + vfsub_unlock_rename(a->src_h_parent, a->src_hdir, |
20659 | + a->dst_h_parent, a->dst_hdir); | |
86dc4139 AM |
20660 | + if (au_ftest_ren(a->flags, MNT_WRITE)) |
20661 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); | |
1308ab2a | 20662 | +} |
20663 | + | |
4a4d8108 | 20664 | +static int au_ren_lock(struct au_ren_args *a) |
1308ab2a | 20665 | +{ |
4a4d8108 AM |
20666 | + int err; |
20667 | + unsigned int udba; | |
1308ab2a | 20668 | + |
4a4d8108 AM |
20669 | + err = 0; |
20670 | + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt); | |
20671 | + a->src_hdir = au_hi(a->src_dir, a->btgt); | |
20672 | + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt); | |
20673 | + a->dst_hdir = au_hi(a->dst_dir, a->btgt); | |
86dc4139 AM |
20674 | + |
20675 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); | |
20676 | + if (unlikely(err)) | |
20677 | + goto out; | |
20678 | + au_fset_ren(a->flags, MNT_WRITE); | |
4a4d8108 AM |
20679 | + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir, |
20680 | + a->dst_h_parent, a->dst_hdir); | |
20681 | + udba = au_opt_udba(a->src_dentry->d_sb); | |
5527c038 JR |
20682 | + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent) |
20683 | + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent))) | |
4a4d8108 AM |
20684 | + err = au_busy_or_stale(); |
20685 | + if (!err && au_dbstart(a->src_dentry) == a->btgt) | |
20686 | + err = au_h_verify(a->src_h_dentry, udba, | |
5527c038 | 20687 | + d_inode(a->src_h_parent), a->src_h_parent, |
4a4d8108 AM |
20688 | + a->br); |
20689 | + if (!err && au_dbstart(a->dst_dentry) == a->btgt) | |
20690 | + err = au_h_verify(a->dst_h_dentry, udba, | |
5527c038 | 20691 | + d_inode(a->dst_h_parent), a->dst_h_parent, |
4a4d8108 | 20692 | + a->br); |
86dc4139 | 20693 | + if (!err) |
4a4d8108 | 20694 | + goto out; /* success */ |
4a4d8108 AM |
20695 | + |
20696 | + err = au_busy_or_stale(); | |
4a4d8108 | 20697 | + au_ren_unlock(a); |
86dc4139 | 20698 | + |
4f0767ce | 20699 | +out: |
4a4d8108 | 20700 | + return err; |
1facf9fc | 20701 | +} |
20702 | + | |
20703 | +/* ---------------------------------------------------------------------- */ | |
20704 | + | |
4a4d8108 | 20705 | +static void au_ren_refresh_dir(struct au_ren_args *a) |
1facf9fc | 20706 | +{ |
4a4d8108 | 20707 | + struct inode *dir; |
dece6358 | 20708 | + |
4a4d8108 AM |
20709 | + dir = a->dst_dir; |
20710 | + dir->i_version++; | |
20711 | + if (au_ftest_ren(a->flags, ISDIR)) { | |
20712 | + /* is this updating defined in POSIX? */ | |
20713 | + au_cpup_attr_timesizes(a->src_inode); | |
20714 | + au_cpup_attr_nlink(dir, /*force*/1); | |
4a4d8108 | 20715 | + } |
027c5e7a | 20716 | + |
b912730e | 20717 | + au_dir_ts(dir, a->btgt); |
dece6358 | 20718 | + |
4a4d8108 AM |
20719 | + if (au_ftest_ren(a->flags, ISSAMEDIR)) |
20720 | + return; | |
dece6358 | 20721 | + |
4a4d8108 AM |
20722 | + dir = a->src_dir; |
20723 | + dir->i_version++; | |
20724 | + if (au_ftest_ren(a->flags, ISDIR)) | |
20725 | + au_cpup_attr_nlink(dir, /*force*/1); | |
b912730e | 20726 | + au_dir_ts(dir, a->btgt); |
1facf9fc | 20727 | +} |
20728 | + | |
4a4d8108 | 20729 | +static void au_ren_refresh(struct au_ren_args *a) |
1facf9fc | 20730 | +{ |
4a4d8108 AM |
20731 | + aufs_bindex_t bend, bindex; |
20732 | + struct dentry *d, *h_d; | |
20733 | + struct inode *i, *h_i; | |
20734 | + struct super_block *sb; | |
dece6358 | 20735 | + |
027c5e7a AM |
20736 | + d = a->dst_dentry; |
20737 | + d_drop(d); | |
20738 | + if (a->h_dst) | |
20739 | + /* already dget-ed by au_ren_or_cpup() */ | |
20740 | + au_set_h_dptr(d, a->btgt, a->h_dst); | |
20741 | + | |
20742 | + i = a->dst_inode; | |
20743 | + if (i) { | |
20744 | + if (!au_ftest_ren(a->flags, ISDIR)) | |
20745 | + vfsub_drop_nlink(i); | |
20746 | + else { | |
20747 | + vfsub_dead_dir(i); | |
20748 | + au_cpup_attr_timesizes(i); | |
20749 | + } | |
20750 | + au_update_dbrange(d, /*do_put_zero*/1); | |
20751 | + } else { | |
20752 | + bend = a->btgt; | |
20753 | + for (bindex = au_dbstart(d); bindex < bend; bindex++) | |
20754 | + au_set_h_dptr(d, bindex, NULL); | |
20755 | + bend = au_dbend(d); | |
20756 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) | |
20757 | + au_set_h_dptr(d, bindex, NULL); | |
20758 | + au_update_dbrange(d, /*do_put_zero*/0); | |
20759 | + } | |
20760 | + | |
4a4d8108 AM |
20761 | + d = a->src_dentry; |
20762 | + au_set_dbwh(d, -1); | |
20763 | + bend = au_dbend(d); | |
20764 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) { | |
20765 | + h_d = au_h_dptr(d, bindex); | |
20766 | + if (h_d) | |
20767 | + au_set_h_dptr(d, bindex, NULL); | |
20768 | + } | |
20769 | + au_set_dbend(d, a->btgt); | |
20770 | + | |
20771 | + sb = d->d_sb; | |
20772 | + i = a->src_inode; | |
20773 | + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i)) | |
20774 | + return; /* success */ | |
20775 | + | |
20776 | + bend = au_ibend(i); | |
20777 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) { | |
20778 | + h_i = au_h_iptr(i, bindex); | |
20779 | + if (h_i) { | |
20780 | + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0); | |
20781 | + /* ignore this error */ | |
20782 | + au_set_h_iptr(i, bindex, NULL, 0); | |
20783 | + } | |
20784 | + } | |
20785 | + au_set_ibend(i, a->btgt); | |
1308ab2a | 20786 | +} |
dece6358 | 20787 | + |
4a4d8108 AM |
20788 | +/* ---------------------------------------------------------------------- */ |
20789 | + | |
20790 | +/* mainly for link(2) and rename(2) */ | |
20791 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt) | |
1308ab2a | 20792 | +{ |
4a4d8108 AM |
20793 | + aufs_bindex_t bdiropq, bwh; |
20794 | + struct dentry *parent; | |
20795 | + struct au_branch *br; | |
20796 | + | |
20797 | + parent = dentry->d_parent; | |
5527c038 | 20798 | + IMustLock(d_inode(parent)); /* dir is locked */ |
4a4d8108 AM |
20799 | + |
20800 | + bdiropq = au_dbdiropq(parent); | |
20801 | + bwh = au_dbwh(dentry); | |
20802 | + br = au_sbr(dentry->d_sb, btgt); | |
20803 | + if (au_br_rdonly(br) | |
20804 | + || (0 <= bdiropq && bdiropq < btgt) | |
20805 | + || (0 <= bwh && bwh < btgt)) | |
20806 | + btgt = -1; | |
20807 | + | |
20808 | + AuDbg("btgt %d\n", btgt); | |
20809 | + return btgt; | |
1facf9fc | 20810 | +} |
20811 | + | |
4a4d8108 AM |
20812 | +/* sets src_bstart, dst_bstart and btgt */ |
20813 | +static int au_ren_wbr(struct au_ren_args *a) | |
1facf9fc | 20814 | +{ |
4a4d8108 AM |
20815 | + int err; |
20816 | + struct au_wr_dir_args wr_dir_args = { | |
20817 | + /* .force_btgt = -1, */ | |
20818 | + .flags = AuWrDir_ADD_ENTRY | |
20819 | + }; | |
dece6358 | 20820 | + |
4a4d8108 AM |
20821 | + a->src_bstart = au_dbstart(a->src_dentry); |
20822 | + a->dst_bstart = au_dbstart(a->dst_dentry); | |
20823 | + if (au_ftest_ren(a->flags, ISDIR)) | |
20824 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); | |
20825 | + wr_dir_args.force_btgt = a->src_bstart; | |
20826 | + if (a->dst_inode && a->dst_bstart < a->src_bstart) | |
20827 | + wr_dir_args.force_btgt = a->dst_bstart; | |
20828 | + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt); | |
20829 | + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args); | |
20830 | + a->btgt = err; | |
dece6358 | 20831 | + |
4a4d8108 | 20832 | + return err; |
1facf9fc | 20833 | +} |
20834 | + | |
4a4d8108 | 20835 | +static void au_ren_dt(struct au_ren_args *a) |
1facf9fc | 20836 | +{ |
4a4d8108 AM |
20837 | + a->h_path.dentry = a->src_h_parent; |
20838 | + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path); | |
20839 | + if (!au_ftest_ren(a->flags, ISSAMEDIR)) { | |
20840 | + a->h_path.dentry = a->dst_h_parent; | |
20841 | + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path); | |
20842 | + } | |
1facf9fc | 20843 | + |
4a4d8108 AM |
20844 | + au_fclr_ren(a->flags, DT_DSTDIR); |
20845 | + if (!au_ftest_ren(a->flags, ISDIR)) | |
20846 | + return; | |
dece6358 | 20847 | + |
4a4d8108 AM |
20848 | + a->h_path.dentry = a->src_h_dentry; |
20849 | + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path); | |
5527c038 | 20850 | + if (d_is_positive(a->dst_h_dentry)) { |
4a4d8108 AM |
20851 | + au_fset_ren(a->flags, DT_DSTDIR); |
20852 | + a->h_path.dentry = a->dst_h_dentry; | |
20853 | + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path); | |
20854 | + } | |
1308ab2a | 20855 | +} |
dece6358 | 20856 | + |
4a4d8108 | 20857 | +static void au_ren_rev_dt(int err, struct au_ren_args *a) |
1308ab2a | 20858 | +{ |
4a4d8108 AM |
20859 | + struct dentry *h_d; |
20860 | + struct mutex *h_mtx; | |
20861 | + | |
20862 | + au_dtime_revert(a->src_dt + AuPARENT); | |
20863 | + if (!au_ftest_ren(a->flags, ISSAMEDIR)) | |
20864 | + au_dtime_revert(a->dst_dt + AuPARENT); | |
20865 | + | |
20866 | + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) { | |
20867 | + h_d = a->src_dt[AuCHILD].dt_h_path.dentry; | |
5527c038 | 20868 | + h_mtx = &d_inode(h_d)->i_mutex; |
4a4d8108 AM |
20869 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); |
20870 | + au_dtime_revert(a->src_dt + AuCHILD); | |
20871 | + mutex_unlock(h_mtx); | |
20872 | + | |
20873 | + if (au_ftest_ren(a->flags, DT_DSTDIR)) { | |
20874 | + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry; | |
5527c038 | 20875 | + h_mtx = &d_inode(h_d)->i_mutex; |
4a4d8108 AM |
20876 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); |
20877 | + au_dtime_revert(a->dst_dt + AuCHILD); | |
20878 | + mutex_unlock(h_mtx); | |
1facf9fc | 20879 | + } |
20880 | + } | |
20881 | +} | |
20882 | + | |
4a4d8108 AM |
20883 | +/* ---------------------------------------------------------------------- */ |
20884 | + | |
20885 | +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, | |
20886 | + struct inode *_dst_dir, struct dentry *_dst_dentry) | |
1facf9fc | 20887 | +{ |
e49829fe | 20888 | + int err, flags; |
4a4d8108 AM |
20889 | + /* reduce stack space */ |
20890 | + struct au_ren_args *a; | |
20891 | + | |
523b37e3 | 20892 | + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry); |
4a4d8108 AM |
20893 | + IMustLock(_src_dir); |
20894 | + IMustLock(_dst_dir); | |
20895 | + | |
20896 | + err = -ENOMEM; | |
20897 | + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE); | |
20898 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
20899 | + if (unlikely(!a)) | |
20900 | + goto out; | |
20901 | + | |
20902 | + a->src_dir = _src_dir; | |
20903 | + a->src_dentry = _src_dentry; | |
5527c038 JR |
20904 | + a->src_inode = NULL; |
20905 | + if (d_really_is_positive(a->src_dentry)) | |
20906 | + a->src_inode = d_inode(a->src_dentry); | |
4a4d8108 AM |
20907 | + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */ |
20908 | + a->dst_dir = _dst_dir; | |
20909 | + a->dst_dentry = _dst_dentry; | |
5527c038 JR |
20910 | + a->dst_inode = NULL; |
20911 | + if (d_really_is_positive(a->dst_dentry)) | |
20912 | + a->dst_inode = d_inode(a->dst_dentry); | |
4a4d8108 AM |
20913 | + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */ |
20914 | + if (a->dst_inode) { | |
20915 | + IMustLock(a->dst_inode); | |
20916 | + au_igrab(a->dst_inode); | |
1facf9fc | 20917 | + } |
1facf9fc | 20918 | + |
4a4d8108 | 20919 | + err = -ENOTDIR; |
027c5e7a | 20920 | + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN; |
2000de60 | 20921 | + if (d_is_dir(a->src_dentry)) { |
4a4d8108 | 20922 | + au_fset_ren(a->flags, ISDIR); |
5527c038 | 20923 | + if (unlikely(d_really_is_positive(a->dst_dentry) |
2000de60 | 20924 | + && !d_is_dir(a->dst_dentry))) |
4a4d8108 | 20925 | + goto out_free; |
e49829fe JR |
20926 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
20927 | + AuLock_DIR | flags); | |
4a4d8108 | 20928 | + } else |
e49829fe JR |
20929 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
20930 | + flags); | |
20931 | + if (unlikely(err)) | |
20932 | + goto out_free; | |
1facf9fc | 20933 | + |
027c5e7a AM |
20934 | + err = au_d_hashed_positive(a->src_dentry); |
20935 | + if (unlikely(err)) | |
20936 | + goto out_unlock; | |
20937 | + err = -ENOENT; | |
20938 | + if (a->dst_inode) { | |
20939 | + /* | |
20940 | + * If it is a dir, VFS unhash dst_dentry before this | |
20941 | + * function. It means we cannot rely upon d_unhashed(). | |
20942 | + */ | |
20943 | + if (unlikely(!a->dst_inode->i_nlink)) | |
20944 | + goto out_unlock; | |
20945 | + if (!S_ISDIR(a->dst_inode->i_mode)) { | |
20946 | + err = au_d_hashed_positive(a->dst_dentry); | |
20947 | + if (unlikely(err)) | |
20948 | + goto out_unlock; | |
20949 | + } else if (unlikely(IS_DEADDIR(a->dst_inode))) | |
20950 | + goto out_unlock; | |
20951 | + } else if (unlikely(d_unhashed(a->dst_dentry))) | |
20952 | + goto out_unlock; | |
20953 | + | |
7eafdf33 AM |
20954 | + /* |
20955 | + * is it possible? | |
20956 | + * yes, it happend (in linux-3.3-rcN) but I don't know why. | |
20957 | + * there may exist a problem somewhere else. | |
20958 | + */ | |
20959 | + err = -EINVAL; | |
5527c038 | 20960 | + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry))) |
7eafdf33 AM |
20961 | + goto out_unlock; |
20962 | + | |
4a4d8108 AM |
20963 | + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */ |
20964 | + di_write_lock_parent(a->dst_parent); | |
1facf9fc | 20965 | + |
4a4d8108 AM |
20966 | + /* which branch we process */ |
20967 | + err = au_ren_wbr(a); | |
20968 | + if (unlikely(err < 0)) | |
027c5e7a | 20969 | + goto out_parent; |
4a4d8108 | 20970 | + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt); |
86dc4139 | 20971 | + a->h_path.mnt = au_br_mnt(a->br); |
1facf9fc | 20972 | + |
4a4d8108 AM |
20973 | + /* are they available to be renamed */ |
20974 | + err = au_ren_may_dir(a); | |
20975 | + if (unlikely(err)) | |
20976 | + goto out_children; | |
1facf9fc | 20977 | + |
4a4d8108 AM |
20978 | + /* prepare the writable parent dir on the same branch */ |
20979 | + if (a->dst_bstart == a->btgt) { | |
20980 | + au_fset_ren(a->flags, WHDST); | |
20981 | + } else { | |
20982 | + err = au_cpup_dirs(a->dst_dentry, a->btgt); | |
20983 | + if (unlikely(err)) | |
20984 | + goto out_children; | |
20985 | + } | |
1facf9fc | 20986 | + |
4a4d8108 AM |
20987 | + if (a->src_dir != a->dst_dir) { |
20988 | + /* | |
20989 | + * this temporary unlock is safe, | |
20990 | + * because both dir->i_mutex are locked. | |
20991 | + */ | |
20992 | + di_write_unlock(a->dst_parent); | |
20993 | + di_write_lock_parent(a->src_parent); | |
20994 | + err = au_wr_dir_need_wh(a->src_dentry, | |
20995 | + au_ftest_ren(a->flags, ISDIR), | |
20996 | + &a->btgt); | |
20997 | + di_write_unlock(a->src_parent); | |
20998 | + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1); | |
20999 | + au_fclr_ren(a->flags, ISSAMEDIR); | |
21000 | + } else | |
21001 | + err = au_wr_dir_need_wh(a->src_dentry, | |
21002 | + au_ftest_ren(a->flags, ISDIR), | |
21003 | + &a->btgt); | |
21004 | + if (unlikely(err < 0)) | |
21005 | + goto out_children; | |
21006 | + if (err) | |
21007 | + au_fset_ren(a->flags, WHSRC); | |
1facf9fc | 21008 | + |
86dc4139 AM |
21009 | + /* cpup src */ |
21010 | + if (a->src_bstart != a->btgt) { | |
86dc4139 AM |
21011 | + struct au_pin pin; |
21012 | + | |
21013 | + err = au_pin(&pin, a->src_dentry, a->btgt, | |
21014 | + au_opt_udba(a->src_dentry->d_sb), | |
21015 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
367653fa | 21016 | + if (!err) { |
c2b27bf2 AM |
21017 | + struct au_cp_generic cpg = { |
21018 | + .dentry = a->src_dentry, | |
21019 | + .bdst = a->btgt, | |
21020 | + .bsrc = a->src_bstart, | |
21021 | + .len = -1, | |
21022 | + .pin = &pin, | |
21023 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
21024 | + }; | |
367653fa | 21025 | + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart); |
c2b27bf2 | 21026 | + err = au_sio_cpup_simple(&cpg); |
367653fa | 21027 | + au_unpin(&pin); |
86dc4139 | 21028 | + } |
86dc4139 AM |
21029 | + if (unlikely(err)) |
21030 | + goto out_children; | |
21031 | + a->src_bstart = a->btgt; | |
21032 | + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt); | |
21033 | + au_fset_ren(a->flags, WHSRC); | |
21034 | + } | |
21035 | + | |
4a4d8108 AM |
21036 | + /* lock them all */ |
21037 | + err = au_ren_lock(a); | |
21038 | + if (unlikely(err)) | |
86dc4139 | 21039 | + /* leave the copied-up one */ |
4a4d8108 | 21040 | + goto out_children; |
1facf9fc | 21041 | + |
4a4d8108 AM |
21042 | + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE)) |
21043 | + err = au_may_ren(a); | |
21044 | + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
21045 | + err = -ENAMETOOLONG; | |
21046 | + if (unlikely(err)) | |
21047 | + goto out_hdir; | |
1facf9fc | 21048 | + |
4a4d8108 AM |
21049 | + /* store timestamps to be revertible */ |
21050 | + au_ren_dt(a); | |
1facf9fc | 21051 | + |
4a4d8108 AM |
21052 | + /* here we go */ |
21053 | + err = do_rename(a); | |
21054 | + if (unlikely(err)) | |
21055 | + goto out_dt; | |
21056 | + | |
21057 | + /* update dir attributes */ | |
21058 | + au_ren_refresh_dir(a); | |
21059 | + | |
21060 | + /* dput/iput all lower dentries */ | |
21061 | + au_ren_refresh(a); | |
21062 | + | |
21063 | + goto out_hdir; /* success */ | |
21064 | + | |
4f0767ce | 21065 | +out_dt: |
4a4d8108 | 21066 | + au_ren_rev_dt(err, a); |
4f0767ce | 21067 | +out_hdir: |
4a4d8108 | 21068 | + au_ren_unlock(a); |
4f0767ce | 21069 | +out_children: |
4a4d8108 | 21070 | + au_nhash_wh_free(&a->whlist); |
027c5e7a AM |
21071 | + if (err && a->dst_inode && a->dst_bstart != a->btgt) { |
21072 | + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt); | |
21073 | + au_set_h_dptr(a->dst_dentry, a->btgt, NULL); | |
21074 | + au_set_dbstart(a->dst_dentry, a->dst_bstart); | |
4a4d8108 | 21075 | + } |
027c5e7a | 21076 | +out_parent: |
4a4d8108 AM |
21077 | + if (!err) |
21078 | + d_move(a->src_dentry, a->dst_dentry); | |
027c5e7a AM |
21079 | + else { |
21080 | + au_update_dbstart(a->dst_dentry); | |
21081 | + if (!a->dst_inode) | |
21082 | + d_drop(a->dst_dentry); | |
21083 | + } | |
4a4d8108 AM |
21084 | + if (au_ftest_ren(a->flags, ISSAMEDIR)) |
21085 | + di_write_unlock(a->dst_parent); | |
21086 | + else | |
21087 | + di_write_unlock2(a->src_parent, a->dst_parent); | |
027c5e7a | 21088 | +out_unlock: |
4a4d8108 | 21089 | + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry); |
4f0767ce | 21090 | +out_free: |
4a4d8108 AM |
21091 | + iput(a->dst_inode); |
21092 | + if (a->thargs) | |
21093 | + au_whtmp_rmdir_free(a->thargs); | |
21094 | + kfree(a); | |
4f0767ce | 21095 | +out: |
4a4d8108 AM |
21096 | + AuTraceErr(err); |
21097 | + return err; | |
1308ab2a | 21098 | +} |
7f207e10 AM |
21099 | diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig |
21100 | --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21101 | +++ linux/fs/aufs/Kconfig 2015-06-28 17:35:44.344717109 +0200 |
c1595e42 | 21102 | @@ -0,0 +1,185 @@ |
4a4d8108 AM |
21103 | +config AUFS_FS |
21104 | + tristate "Aufs (Advanced multi layered unification filesystem) support" | |
4a4d8108 AM |
21105 | + help |
21106 | + Aufs is a stackable unification filesystem such as Unionfs, | |
21107 | + which unifies several directories and provides a merged single | |
21108 | + directory. | |
21109 | + In the early days, aufs was entirely re-designed and | |
21110 | + re-implemented Unionfs Version 1.x series. Introducing many | |
21111 | + original ideas, approaches and improvements, it becomes totally | |
21112 | + different from Unionfs while keeping the basic features. | |
1facf9fc | 21113 | + |
4a4d8108 AM |
21114 | +if AUFS_FS |
21115 | +choice | |
21116 | + prompt "Maximum number of branches" | |
21117 | + default AUFS_BRANCH_MAX_127 | |
21118 | + help | |
21119 | + Specifies the maximum number of branches (or member directories) | |
21120 | + in a single aufs. The larger value consumes more system | |
21121 | + resources and has a minor impact to performance. | |
21122 | +config AUFS_BRANCH_MAX_127 | |
21123 | + bool "127" | |
21124 | + help | |
21125 | + Specifies the maximum number of branches (or member directories) | |
21126 | + in a single aufs. The larger value consumes more system | |
21127 | + resources and has a minor impact to performance. | |
21128 | +config AUFS_BRANCH_MAX_511 | |
21129 | + bool "511" | |
21130 | + help | |
21131 | + Specifies the maximum number of branches (or member directories) | |
21132 | + in a single aufs. The larger value consumes more system | |
21133 | + resources and has a minor impact to performance. | |
21134 | +config AUFS_BRANCH_MAX_1023 | |
21135 | + bool "1023" | |
21136 | + help | |
21137 | + Specifies the maximum number of branches (or member directories) | |
21138 | + in a single aufs. The larger value consumes more system | |
21139 | + resources and has a minor impact to performance. | |
21140 | +config AUFS_BRANCH_MAX_32767 | |
21141 | + bool "32767" | |
21142 | + help | |
21143 | + Specifies the maximum number of branches (or member directories) | |
21144 | + in a single aufs. The larger value consumes more system | |
21145 | + resources and has a minor impact to performance. | |
21146 | +endchoice | |
1facf9fc | 21147 | + |
e49829fe JR |
21148 | +config AUFS_SBILIST |
21149 | + bool | |
21150 | + depends on AUFS_MAGIC_SYSRQ || PROC_FS | |
21151 | + default y | |
21152 | + help | |
21153 | + Automatic configuration for internal use. | |
21154 | + When aufs supports Magic SysRq or /proc, enabled automatically. | |
21155 | + | |
4a4d8108 AM |
21156 | +config AUFS_HNOTIFY |
21157 | + bool "Detect direct branch access (bypassing aufs)" | |
21158 | + help | |
21159 | + If you want to modify files on branches directly, eg. bypassing aufs, | |
21160 | + and want aufs to detect the changes of them fully, then enable this | |
21161 | + option and use 'udba=notify' mount option. | |
7f207e10 | 21162 | + Currently there is only one available configuration, "fsnotify". |
4a4d8108 AM |
21163 | + It will have a negative impact to the performance. |
21164 | + See detail in aufs.5. | |
dece6358 | 21165 | + |
4a4d8108 AM |
21166 | +choice |
21167 | + prompt "method" if AUFS_HNOTIFY | |
21168 | + default AUFS_HFSNOTIFY | |
21169 | +config AUFS_HFSNOTIFY | |
21170 | + bool "fsnotify" | |
21171 | + select FSNOTIFY | |
4a4d8108 | 21172 | +endchoice |
1facf9fc | 21173 | + |
4a4d8108 AM |
21174 | +config AUFS_EXPORT |
21175 | + bool "NFS-exportable aufs" | |
2cbb1c4b | 21176 | + depends on EXPORTFS |
4a4d8108 AM |
21177 | + help |
21178 | + If you want to export your mounted aufs via NFS, then enable this | |
21179 | + option. There are several requirements for this configuration. | |
21180 | + See detail in aufs.5. | |
1facf9fc | 21181 | + |
4a4d8108 AM |
21182 | +config AUFS_INO_T_64 |
21183 | + bool | |
21184 | + depends on AUFS_EXPORT | |
21185 | + depends on 64BIT && !(ALPHA || S390) | |
21186 | + default y | |
21187 | + help | |
21188 | + Automatic configuration for internal use. | |
21189 | + /* typedef unsigned long/int __kernel_ino_t */ | |
21190 | + /* alpha and s390x are int */ | |
1facf9fc | 21191 | + |
c1595e42 JR |
21192 | +config AUFS_XATTR |
21193 | + bool "support for XATTR/EA (including Security Labels)" | |
21194 | + help | |
21195 | + If your branch fs supports XATTR/EA and you want to make them | |
21196 | + available in aufs too, then enable this opsion and specify the | |
21197 | + branch attributes for EA. | |
21198 | + See detail in aufs.5. | |
21199 | + | |
076b876e AM |
21200 | +config AUFS_FHSM |
21201 | + bool "File-based Hierarchical Storage Management" | |
21202 | + help | |
21203 | + Hierarchical Storage Management (or HSM) is a well-known feature | |
21204 | + in the storage world. Aufs provides this feature as file-based. | |
21205 | + with multiple branches. | |
21206 | + These multiple branches are prioritized, ie. the topmost one | |
21207 | + should be the fastest drive and be used heavily. | |
21208 | + | |
4a4d8108 AM |
21209 | +config AUFS_RDU |
21210 | + bool "Readdir in userspace" | |
21211 | + help | |
21212 | + Aufs has two methods to provide a merged view for a directory, | |
21213 | + by a user-space library and by kernel-space natively. The latter | |
21214 | + is always enabled but sometimes large and slow. | |
21215 | + If you enable this option, install the library in aufs2-util | |
21216 | + package, and set some environment variables for your readdir(3), | |
21217 | + then the work will be handled in user-space which generally | |
21218 | + shows better performance in most cases. | |
21219 | + See detail in aufs.5. | |
1facf9fc | 21220 | + |
4a4d8108 AM |
21221 | +config AUFS_SHWH |
21222 | + bool "Show whiteouts" | |
21223 | + help | |
21224 | + If you want to make the whiteouts in aufs visible, then enable | |
21225 | + this option and specify 'shwh' mount option. Although it may | |
21226 | + sounds like philosophy or something, but in technically it | |
21227 | + simply shows the name of whiteout with keeping its behaviour. | |
1facf9fc | 21228 | + |
4a4d8108 AM |
21229 | +config AUFS_BR_RAMFS |
21230 | + bool "Ramfs (initramfs/rootfs) as an aufs branch" | |
21231 | + help | |
21232 | + If you want to use ramfs as an aufs branch fs, then enable this | |
21233 | + option. Generally tmpfs is recommended. | |
21234 | + Aufs prohibited them to be a branch fs by default, because | |
21235 | + initramfs becomes unusable after switch_root or something | |
21236 | + generally. If you sets initramfs as an aufs branch and boot your | |
21237 | + system by switch_root, you will meet a problem easily since the | |
21238 | + files in initramfs may be inaccessible. | |
21239 | + Unless you are going to use ramfs as an aufs branch fs without | |
21240 | + switch_root or something, leave it N. | |
1facf9fc | 21241 | + |
4a4d8108 AM |
21242 | +config AUFS_BR_FUSE |
21243 | + bool "Fuse fs as an aufs branch" | |
21244 | + depends on FUSE_FS | |
21245 | + select AUFS_POLL | |
21246 | + help | |
21247 | + If you want to use fuse-based userspace filesystem as an aufs | |
21248 | + branch fs, then enable this option. | |
21249 | + It implements the internal poll(2) operation which is | |
21250 | + implemented by fuse only (curretnly). | |
1facf9fc | 21251 | + |
4a4d8108 AM |
21252 | +config AUFS_POLL |
21253 | + bool | |
21254 | + help | |
21255 | + Automatic configuration for internal use. | |
1facf9fc | 21256 | + |
4a4d8108 AM |
21257 | +config AUFS_BR_HFSPLUS |
21258 | + bool "Hfsplus as an aufs branch" | |
21259 | + depends on HFSPLUS_FS | |
21260 | + default y | |
21261 | + help | |
21262 | + If you want to use hfsplus fs as an aufs branch fs, then enable | |
21263 | + this option. This option introduces a small overhead at | |
21264 | + copying-up a file on hfsplus. | |
1facf9fc | 21265 | + |
4a4d8108 AM |
21266 | +config AUFS_BDEV_LOOP |
21267 | + bool | |
21268 | + depends on BLK_DEV_LOOP | |
21269 | + default y | |
21270 | + help | |
21271 | + Automatic configuration for internal use. | |
21272 | + Convert =[ym] into =y. | |
1308ab2a | 21273 | + |
4a4d8108 AM |
21274 | +config AUFS_DEBUG |
21275 | + bool "Debug aufs" | |
21276 | + help | |
21277 | + Enable this to compile aufs internal debug code. | |
21278 | + It will have a negative impact to the performance. | |
21279 | + | |
21280 | +config AUFS_MAGIC_SYSRQ | |
21281 | + bool | |
21282 | + depends on AUFS_DEBUG && MAGIC_SYSRQ | |
21283 | + default y | |
21284 | + help | |
21285 | + Automatic configuration for internal use. | |
21286 | + When aufs supports Magic SysRq, enabled automatically. | |
21287 | +endif | |
7f207e10 AM |
21288 | diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c |
21289 | --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21290 | +++ linux/fs/aufs/loop.c 2015-06-28 17:35:44.348050491 +0200 |
523b37e3 | 21291 | @@ -0,0 +1,145 @@ |
1facf9fc | 21292 | +/* |
2000de60 | 21293 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21294 | + * |
21295 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21296 | + * it under the terms of the GNU General Public License as published by | |
21297 | + * the Free Software Foundation; either version 2 of the License, or | |
21298 | + * (at your option) any later version. | |
dece6358 AM |
21299 | + * |
21300 | + * This program is distributed in the hope that it will be useful, | |
21301 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21302 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21303 | + * GNU General Public License for more details. | |
21304 | + * | |
21305 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21306 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21307 | + */ |
21308 | + | |
21309 | +/* | |
21310 | + * support for loopback block device as a branch | |
21311 | + */ | |
21312 | + | |
1facf9fc | 21313 | +#include "aufs.h" |
21314 | + | |
392086de AM |
21315 | +/* added into drivers/block/loop.c */ |
21316 | +static struct file *(*backing_file_func)(struct super_block *sb); | |
21317 | + | |
1facf9fc | 21318 | +/* |
21319 | + * test if two lower dentries have overlapping branches. | |
21320 | + */ | |
b752ccd1 | 21321 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding) |
1facf9fc | 21322 | +{ |
b752ccd1 | 21323 | + struct super_block *h_sb; |
392086de AM |
21324 | + struct file *backing_file; |
21325 | + | |
21326 | + if (unlikely(!backing_file_func)) { | |
21327 | + /* don't load "loop" module here */ | |
21328 | + backing_file_func = symbol_get(loop_backing_file); | |
21329 | + if (unlikely(!backing_file_func)) | |
21330 | + /* "loop" module is not loaded */ | |
21331 | + return 0; | |
21332 | + } | |
1facf9fc | 21333 | + |
b752ccd1 | 21334 | + h_sb = h_adding->d_sb; |
392086de AM |
21335 | + backing_file = backing_file_func(h_sb); |
21336 | + if (!backing_file) | |
1facf9fc | 21337 | + return 0; |
21338 | + | |
2000de60 | 21339 | + h_adding = backing_file->f_path.dentry; |
b752ccd1 AM |
21340 | + /* |
21341 | + * h_adding can be local NFS. | |
21342 | + * in this case aufs cannot detect the loop. | |
21343 | + */ | |
21344 | + if (unlikely(h_adding->d_sb == sb)) | |
1facf9fc | 21345 | + return 1; |
b752ccd1 | 21346 | + return !!au_test_subdir(h_adding, sb->s_root); |
1facf9fc | 21347 | +} |
21348 | + | |
21349 | +/* true if a kernel thread named 'loop[0-9].*' accesses a file */ | |
21350 | +int au_test_loopback_kthread(void) | |
21351 | +{ | |
b752ccd1 AM |
21352 | + int ret; |
21353 | + struct task_struct *tsk = current; | |
a2a7ad62 | 21354 | + char c, comm[sizeof(tsk->comm)]; |
b752ccd1 AM |
21355 | + |
21356 | + ret = 0; | |
21357 | + if (tsk->flags & PF_KTHREAD) { | |
a2a7ad62 AM |
21358 | + get_task_comm(comm, tsk); |
21359 | + c = comm[4]; | |
b752ccd1 | 21360 | + ret = ('0' <= c && c <= '9' |
a2a7ad62 | 21361 | + && !strncmp(comm, "loop", 4)); |
b752ccd1 | 21362 | + } |
1facf9fc | 21363 | + |
b752ccd1 | 21364 | + return ret; |
1facf9fc | 21365 | +} |
87a755f4 AM |
21366 | + |
21367 | +/* ---------------------------------------------------------------------- */ | |
21368 | + | |
21369 | +#define au_warn_loopback_step 16 | |
21370 | +static int au_warn_loopback_nelem = au_warn_loopback_step; | |
21371 | +static unsigned long *au_warn_loopback_array; | |
21372 | + | |
21373 | +void au_warn_loopback(struct super_block *h_sb) | |
21374 | +{ | |
21375 | + int i, new_nelem; | |
21376 | + unsigned long *a, magic; | |
21377 | + static DEFINE_SPINLOCK(spin); | |
21378 | + | |
21379 | + magic = h_sb->s_magic; | |
21380 | + spin_lock(&spin); | |
21381 | + a = au_warn_loopback_array; | |
21382 | + for (i = 0; i < au_warn_loopback_nelem && *a; i++) | |
21383 | + if (a[i] == magic) { | |
21384 | + spin_unlock(&spin); | |
21385 | + return; | |
21386 | + } | |
21387 | + | |
21388 | + /* h_sb is new to us, print it */ | |
21389 | + if (i < au_warn_loopback_nelem) { | |
21390 | + a[i] = magic; | |
21391 | + goto pr; | |
21392 | + } | |
21393 | + | |
21394 | + /* expand the array */ | |
21395 | + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step; | |
21396 | + a = au_kzrealloc(au_warn_loopback_array, | |
21397 | + au_warn_loopback_nelem * sizeof(unsigned long), | |
21398 | + new_nelem * sizeof(unsigned long), GFP_ATOMIC); | |
21399 | + if (a) { | |
21400 | + au_warn_loopback_nelem = new_nelem; | |
21401 | + au_warn_loopback_array = a; | |
21402 | + a[i] = magic; | |
21403 | + goto pr; | |
21404 | + } | |
21405 | + | |
21406 | + spin_unlock(&spin); | |
21407 | + AuWarn1("realloc failed, ignored\n"); | |
21408 | + return; | |
21409 | + | |
21410 | +pr: | |
21411 | + spin_unlock(&spin); | |
0c3ec466 AM |
21412 | + pr_warn("you may want to try another patch for loopback file " |
21413 | + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic); | |
87a755f4 AM |
21414 | +} |
21415 | + | |
21416 | +int au_loopback_init(void) | |
21417 | +{ | |
21418 | + int err; | |
21419 | + struct super_block *sb __maybe_unused; | |
21420 | + | |
21421 | + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long)); | |
21422 | + | |
21423 | + err = 0; | |
21424 | + au_warn_loopback_array = kcalloc(au_warn_loopback_step, | |
21425 | + sizeof(unsigned long), GFP_NOFS); | |
21426 | + if (unlikely(!au_warn_loopback_array)) | |
21427 | + err = -ENOMEM; | |
21428 | + | |
21429 | + return err; | |
21430 | +} | |
21431 | + | |
21432 | +void au_loopback_fin(void) | |
21433 | +{ | |
392086de | 21434 | + symbol_put(loop_backing_file); |
87a755f4 AM |
21435 | + kfree(au_warn_loopback_array); |
21436 | +} | |
7f207e10 AM |
21437 | diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h |
21438 | --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21439 | +++ linux/fs/aufs/loop.h 2015-06-28 17:35:44.348050491 +0200 |
523b37e3 | 21440 | @@ -0,0 +1,52 @@ |
1facf9fc | 21441 | +/* |
2000de60 | 21442 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21443 | + * |
21444 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21445 | + * it under the terms of the GNU General Public License as published by | |
21446 | + * the Free Software Foundation; either version 2 of the License, or | |
21447 | + * (at your option) any later version. | |
dece6358 AM |
21448 | + * |
21449 | + * This program is distributed in the hope that it will be useful, | |
21450 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21451 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21452 | + * GNU General Public License for more details. | |
21453 | + * | |
21454 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21455 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21456 | + */ |
21457 | + | |
21458 | +/* | |
21459 | + * support for loopback mount as a branch | |
21460 | + */ | |
21461 | + | |
21462 | +#ifndef __AUFS_LOOP_H__ | |
21463 | +#define __AUFS_LOOP_H__ | |
21464 | + | |
21465 | +#ifdef __KERNEL__ | |
21466 | + | |
dece6358 AM |
21467 | +struct dentry; |
21468 | +struct super_block; | |
1facf9fc | 21469 | + |
21470 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
392086de AM |
21471 | +/* drivers/block/loop.c */ |
21472 | +struct file *loop_backing_file(struct super_block *sb); | |
21473 | + | |
1facf9fc | 21474 | +/* loop.c */ |
b752ccd1 | 21475 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding); |
1facf9fc | 21476 | +int au_test_loopback_kthread(void); |
87a755f4 AM |
21477 | +void au_warn_loopback(struct super_block *h_sb); |
21478 | + | |
21479 | +int au_loopback_init(void); | |
21480 | +void au_loopback_fin(void); | |
1facf9fc | 21481 | +#else |
4a4d8108 | 21482 | +AuStubInt0(au_test_loopback_overlap, struct super_block *sb, |
b752ccd1 | 21483 | + struct dentry *h_adding) |
4a4d8108 | 21484 | +AuStubInt0(au_test_loopback_kthread, void) |
87a755f4 AM |
21485 | +AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
21486 | + | |
21487 | +AuStubInt0(au_loopback_init, void) | |
21488 | +AuStubVoid(au_loopback_fin, void) | |
1facf9fc | 21489 | +#endif /* BLK_DEV_LOOP */ |
21490 | + | |
21491 | +#endif /* __KERNEL__ */ | |
21492 | +#endif /* __AUFS_LOOP_H__ */ | |
7f207e10 AM |
21493 | diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk |
21494 | --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21495 | +++ linux/fs/aufs/magic.mk 2015-06-28 17:35:44.348050491 +0200 |
7e9cd9fe | 21496 | @@ -0,0 +1,30 @@ |
1facf9fc | 21497 | + |
21498 | +# defined in ${srctree}/fs/fuse/inode.c | |
21499 | +# tristate | |
21500 | +ifdef CONFIG_FUSE_FS | |
21501 | +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546 | |
21502 | +endif | |
21503 | + | |
1facf9fc | 21504 | +# defined in ${srctree}/fs/xfs/xfs_sb.h |
21505 | +# tristate | |
21506 | +ifdef CONFIG_XFS_FS | |
21507 | +ccflags-y += -DXFS_SB_MAGIC=0x58465342 | |
21508 | +endif | |
21509 | + | |
21510 | +# defined in ${srctree}/fs/configfs/mount.c | |
21511 | +# tristate | |
21512 | +ifdef CONFIG_CONFIGFS_FS | |
21513 | +ccflags-y += -DCONFIGFS_MAGIC=0x62656570 | |
21514 | +endif | |
21515 | + | |
1facf9fc | 21516 | +# defined in ${srctree}/fs/ubifs/ubifs.h |
21517 | +# tristate | |
21518 | +ifdef CONFIG_UBIFS_FS | |
21519 | +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905 | |
21520 | +endif | |
4a4d8108 AM |
21521 | + |
21522 | +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h | |
21523 | +# tristate | |
21524 | +ifdef CONFIG_HFSPLUS_FS | |
21525 | +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b | |
21526 | +endif | |
7f207e10 AM |
21527 | diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile |
21528 | --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21529 | +++ linux/fs/aufs/Makefile 2015-06-28 17:35:44.344717109 +0200 |
c1595e42 | 21530 | @@ -0,0 +1,44 @@ |
4a4d8108 AM |
21531 | + |
21532 | +include ${src}/magic.mk | |
21533 | +ifeq (${CONFIG_AUFS_FS},m) | |
21534 | +include ${src}/conf.mk | |
21535 | +endif | |
21536 | +-include ${src}/priv_def.mk | |
21537 | + | |
21538 | +# cf. include/linux/kernel.h | |
21539 | +# enable pr_debug | |
21540 | +ccflags-y += -DDEBUG | |
f6c5ef8b AM |
21541 | +# sparse requires the full pathname |
21542 | +ifdef M | |
523b37e3 | 21543 | +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h |
f6c5ef8b | 21544 | +else |
523b37e3 | 21545 | +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h |
f6c5ef8b | 21546 | +endif |
4a4d8108 AM |
21547 | + |
21548 | +obj-$(CONFIG_AUFS_FS) += aufs.o | |
21549 | +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \ | |
21550 | + wkq.o vfsub.o dcsub.o \ | |
e49829fe | 21551 | + cpup.o whout.o wbr_policy.o \ |
4a4d8108 AM |
21552 | + dinfo.o dentry.o \ |
21553 | + dynop.o \ | |
21554 | + finfo.o file.o f_op.o \ | |
21555 | + dir.o vdir.o \ | |
21556 | + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \ | |
c2b27bf2 | 21557 | + mvdown.o ioctl.o |
4a4d8108 AM |
21558 | + |
21559 | +# all are boolean | |
e49829fe | 21560 | +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o |
4a4d8108 AM |
21561 | +aufs-$(CONFIG_SYSFS) += sysfs.o |
21562 | +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o | |
21563 | +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o | |
21564 | +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o | |
21565 | +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o | |
4a4d8108 | 21566 | +aufs-$(CONFIG_AUFS_EXPORT) += export.o |
c1595e42 JR |
21567 | +aufs-$(CONFIG_AUFS_XATTR) += xattr.o |
21568 | +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o | |
076b876e | 21569 | +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o |
4a4d8108 AM |
21570 | +aufs-$(CONFIG_AUFS_POLL) += poll.o |
21571 | +aufs-$(CONFIG_AUFS_RDU) += rdu.o | |
4a4d8108 AM |
21572 | +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o |
21573 | +aufs-$(CONFIG_AUFS_DEBUG) += debug.o | |
21574 | +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o | |
7f207e10 AM |
21575 | diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c |
21576 | --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21577 | +++ linux/fs/aufs/module.c 2015-06-28 17:35:44.348050491 +0200 |
076b876e | 21578 | @@ -0,0 +1,210 @@ |
1facf9fc | 21579 | +/* |
2000de60 | 21580 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21581 | + * |
21582 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21583 | + * it under the terms of the GNU General Public License as published by | |
21584 | + * the Free Software Foundation; either version 2 of the License, or | |
21585 | + * (at your option) any later version. | |
dece6358 AM |
21586 | + * |
21587 | + * This program is distributed in the hope that it will be useful, | |
21588 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21589 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21590 | + * GNU General Public License for more details. | |
21591 | + * | |
21592 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21593 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21594 | + */ |
21595 | + | |
21596 | +/* | |
21597 | + * module global variables and operations | |
21598 | + */ | |
21599 | + | |
21600 | +#include <linux/module.h> | |
21601 | +#include <linux/seq_file.h> | |
21602 | +#include "aufs.h" | |
21603 | + | |
21604 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp) | |
21605 | +{ | |
21606 | + if (new_sz <= nused) | |
21607 | + return p; | |
21608 | + | |
21609 | + p = krealloc(p, new_sz, gfp); | |
21610 | + if (p) | |
21611 | + memset(p + nused, 0, new_sz - nused); | |
21612 | + return p; | |
21613 | +} | |
21614 | + | |
21615 | +/* ---------------------------------------------------------------------- */ | |
21616 | + | |
21617 | +/* | |
21618 | + * aufs caches | |
21619 | + */ | |
21620 | +struct kmem_cache *au_cachep[AuCache_Last]; | |
21621 | +static int __init au_cache_init(void) | |
21622 | +{ | |
4a4d8108 | 21623 | + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once); |
1facf9fc | 21624 | + if (au_cachep[AuCache_DINFO]) |
027c5e7a | 21625 | + /* SLAB_DESTROY_BY_RCU */ |
4a4d8108 AM |
21626 | + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr, |
21627 | + au_icntnr_init_once); | |
1facf9fc | 21628 | + if (au_cachep[AuCache_ICNTNR]) |
4a4d8108 AM |
21629 | + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo, |
21630 | + au_fi_init_once); | |
1facf9fc | 21631 | + if (au_cachep[AuCache_FINFO]) |
21632 | + au_cachep[AuCache_VDIR] = AuCache(au_vdir); | |
21633 | + if (au_cachep[AuCache_VDIR]) | |
21634 | + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr); | |
21635 | + if (au_cachep[AuCache_DEHSTR]) | |
21636 | + return 0; | |
21637 | + | |
21638 | + return -ENOMEM; | |
21639 | +} | |
21640 | + | |
21641 | +static void au_cache_fin(void) | |
21642 | +{ | |
21643 | + int i; | |
4a4d8108 | 21644 | + |
537831f9 AM |
21645 | + /* |
21646 | + * Make sure all delayed rcu free inodes are flushed before we | |
21647 | + * destroy cache. | |
21648 | + */ | |
21649 | + rcu_barrier(); | |
21650 | + | |
7eafdf33 AM |
21651 | + /* excluding AuCache_HNOTIFY */ |
21652 | + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last); | |
21653 | + for (i = 0; i < AuCache_HNOTIFY; i++) | |
1facf9fc | 21654 | + if (au_cachep[i]) { |
21655 | + kmem_cache_destroy(au_cachep[i]); | |
21656 | + au_cachep[i] = NULL; | |
21657 | + } | |
21658 | +} | |
21659 | + | |
21660 | +/* ---------------------------------------------------------------------- */ | |
21661 | + | |
21662 | +int au_dir_roflags; | |
21663 | + | |
e49829fe | 21664 | +#ifdef CONFIG_AUFS_SBILIST |
1e00d052 AM |
21665 | +/* |
21666 | + * iterate_supers_type() doesn't protect us from | |
21667 | + * remounting (branch management) | |
21668 | + */ | |
e49829fe JR |
21669 | +struct au_splhead au_sbilist; |
21670 | +#endif | |
21671 | + | |
9dbd164d AM |
21672 | +struct lock_class_key au_lc_key[AuLcKey_Last]; |
21673 | + | |
1facf9fc | 21674 | +/* |
21675 | + * functions for module interface. | |
21676 | + */ | |
21677 | +MODULE_LICENSE("GPL"); | |
21678 | +/* MODULE_LICENSE("GPL v2"); */ | |
dece6358 | 21679 | +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>"); |
1facf9fc | 21680 | +MODULE_DESCRIPTION(AUFS_NAME |
21681 | + " -- Advanced multi layered unification filesystem"); | |
21682 | +MODULE_VERSION(AUFS_VERSION); | |
c06a8ce3 | 21683 | +MODULE_ALIAS_FS(AUFS_NAME); |
1facf9fc | 21684 | + |
1facf9fc | 21685 | +/* this module parameter has no meaning when SYSFS is disabled */ |
21686 | +int sysaufs_brs = 1; | |
21687 | +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN"); | |
21688 | +module_param_named(brs, sysaufs_brs, int, S_IRUGO); | |
21689 | + | |
076b876e AM |
21690 | +/* this module parameter has no meaning when USER_NS is disabled */ |
21691 | +static bool au_userns; | |
21692 | +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns"); | |
21693 | +module_param_named(allow_userns, au_userns, bool, S_IRUGO); | |
21694 | + | |
1facf9fc | 21695 | +/* ---------------------------------------------------------------------- */ |
21696 | + | |
21697 | +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */ | |
21698 | + | |
21699 | +int au_seq_path(struct seq_file *seq, struct path *path) | |
21700 | +{ | |
21701 | + return seq_path(seq, path, au_esc_chars); | |
21702 | +} | |
21703 | + | |
21704 | +/* ---------------------------------------------------------------------- */ | |
21705 | + | |
21706 | +static int __init aufs_init(void) | |
21707 | +{ | |
21708 | + int err, i; | |
21709 | + char *p; | |
21710 | + | |
21711 | + p = au_esc_chars; | |
21712 | + for (i = 1; i <= ' '; i++) | |
21713 | + *p++ = i; | |
21714 | + *p++ = '\\'; | |
21715 | + *p++ = '\x7f'; | |
21716 | + *p = 0; | |
21717 | + | |
21718 | + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE); | |
21719 | + | |
e49829fe | 21720 | + au_sbilist_init(); |
1facf9fc | 21721 | + sysaufs_brs_init(); |
21722 | + au_debug_init(); | |
4a4d8108 | 21723 | + au_dy_init(); |
1facf9fc | 21724 | + err = sysaufs_init(); |
21725 | + if (unlikely(err)) | |
21726 | + goto out; | |
e49829fe | 21727 | + err = au_procfs_init(); |
4f0767ce | 21728 | + if (unlikely(err)) |
953406b4 | 21729 | + goto out_sysaufs; |
e49829fe JR |
21730 | + err = au_wkq_init(); |
21731 | + if (unlikely(err)) | |
21732 | + goto out_procfs; | |
87a755f4 | 21733 | + err = au_loopback_init(); |
1facf9fc | 21734 | + if (unlikely(err)) |
21735 | + goto out_wkq; | |
87a755f4 AM |
21736 | + err = au_hnotify_init(); |
21737 | + if (unlikely(err)) | |
21738 | + goto out_loopback; | |
1facf9fc | 21739 | + err = au_sysrq_init(); |
21740 | + if (unlikely(err)) | |
21741 | + goto out_hin; | |
21742 | + err = au_cache_init(); | |
21743 | + if (unlikely(err)) | |
21744 | + goto out_sysrq; | |
076b876e AM |
21745 | + |
21746 | + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0; | |
1facf9fc | 21747 | + err = register_filesystem(&aufs_fs_type); |
21748 | + if (unlikely(err)) | |
21749 | + goto out_cache; | |
076b876e | 21750 | + |
4a4d8108 AM |
21751 | + /* since we define pr_fmt, call printk directly */ |
21752 | + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n"); | |
1facf9fc | 21753 | + goto out; /* success */ |
21754 | + | |
4f0767ce | 21755 | +out_cache: |
1facf9fc | 21756 | + au_cache_fin(); |
4f0767ce | 21757 | +out_sysrq: |
1facf9fc | 21758 | + au_sysrq_fin(); |
4f0767ce | 21759 | +out_hin: |
4a4d8108 | 21760 | + au_hnotify_fin(); |
87a755f4 AM |
21761 | +out_loopback: |
21762 | + au_loopback_fin(); | |
4f0767ce | 21763 | +out_wkq: |
1facf9fc | 21764 | + au_wkq_fin(); |
e49829fe JR |
21765 | +out_procfs: |
21766 | + au_procfs_fin(); | |
4f0767ce | 21767 | +out_sysaufs: |
1facf9fc | 21768 | + sysaufs_fin(); |
4a4d8108 | 21769 | + au_dy_fin(); |
4f0767ce | 21770 | +out: |
1facf9fc | 21771 | + return err; |
21772 | +} | |
21773 | + | |
21774 | +static void __exit aufs_exit(void) | |
21775 | +{ | |
21776 | + unregister_filesystem(&aufs_fs_type); | |
21777 | + au_cache_fin(); | |
21778 | + au_sysrq_fin(); | |
4a4d8108 | 21779 | + au_hnotify_fin(); |
87a755f4 | 21780 | + au_loopback_fin(); |
1facf9fc | 21781 | + au_wkq_fin(); |
e49829fe | 21782 | + au_procfs_fin(); |
1facf9fc | 21783 | + sysaufs_fin(); |
4a4d8108 | 21784 | + au_dy_fin(); |
1facf9fc | 21785 | +} |
21786 | + | |
21787 | +module_init(aufs_init); | |
21788 | +module_exit(aufs_exit); | |
7f207e10 AM |
21789 | diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h |
21790 | --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21791 | +++ linux/fs/aufs/module.h 2015-06-28 17:35:44.348050491 +0200 |
523b37e3 | 21792 | @@ -0,0 +1,104 @@ |
1facf9fc | 21793 | +/* |
2000de60 | 21794 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21795 | + * |
21796 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21797 | + * it under the terms of the GNU General Public License as published by | |
21798 | + * the Free Software Foundation; either version 2 of the License, or | |
21799 | + * (at your option) any later version. | |
dece6358 AM |
21800 | + * |
21801 | + * This program is distributed in the hope that it will be useful, | |
21802 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21803 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21804 | + * GNU General Public License for more details. | |
21805 | + * | |
21806 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21807 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21808 | + */ |
21809 | + | |
21810 | +/* | |
21811 | + * module initialization and module-global | |
21812 | + */ | |
21813 | + | |
21814 | +#ifndef __AUFS_MODULE_H__ | |
21815 | +#define __AUFS_MODULE_H__ | |
21816 | + | |
21817 | +#ifdef __KERNEL__ | |
21818 | + | |
21819 | +#include <linux/slab.h> | |
21820 | + | |
dece6358 AM |
21821 | +struct path; |
21822 | +struct seq_file; | |
21823 | + | |
1facf9fc | 21824 | +/* module parameters */ |
1facf9fc | 21825 | +extern int sysaufs_brs; |
21826 | + | |
21827 | +/* ---------------------------------------------------------------------- */ | |
21828 | + | |
21829 | +extern int au_dir_roflags; | |
21830 | + | |
9dbd164d AM |
21831 | +enum { |
21832 | + AuLcNonDir_FIINFO, | |
21833 | + AuLcNonDir_DIINFO, | |
21834 | + AuLcNonDir_IIINFO, | |
21835 | + | |
21836 | + AuLcDir_FIINFO, | |
21837 | + AuLcDir_DIINFO, | |
21838 | + AuLcDir_IIINFO, | |
21839 | + | |
21840 | + AuLcSymlink_DIINFO, | |
21841 | + AuLcSymlink_IIINFO, | |
21842 | + | |
21843 | + AuLcKey_Last | |
21844 | +}; | |
21845 | +extern struct lock_class_key au_lc_key[AuLcKey_Last]; | |
21846 | + | |
1facf9fc | 21847 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp); |
21848 | +int au_seq_path(struct seq_file *seq, struct path *path); | |
21849 | + | |
e49829fe JR |
21850 | +#ifdef CONFIG_PROC_FS |
21851 | +/* procfs.c */ | |
21852 | +int __init au_procfs_init(void); | |
21853 | +void au_procfs_fin(void); | |
21854 | +#else | |
21855 | +AuStubInt0(au_procfs_init, void); | |
21856 | +AuStubVoid(au_procfs_fin, void); | |
21857 | +#endif | |
21858 | + | |
4f0767ce JR |
21859 | +/* ---------------------------------------------------------------------- */ |
21860 | + | |
21861 | +/* kmem cache */ | |
1facf9fc | 21862 | +enum { |
21863 | + AuCache_DINFO, | |
21864 | + AuCache_ICNTNR, | |
21865 | + AuCache_FINFO, | |
21866 | + AuCache_VDIR, | |
21867 | + AuCache_DEHSTR, | |
7eafdf33 | 21868 | + AuCache_HNOTIFY, /* must be last */ |
1facf9fc | 21869 | + AuCache_Last |
21870 | +}; | |
21871 | + | |
4a4d8108 AM |
21872 | +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD) |
21873 | +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags) | |
21874 | +#define AuCacheCtor(type, ctor) \ | |
21875 | + kmem_cache_create(#type, sizeof(struct type), \ | |
21876 | + __alignof__(struct type), AuCacheFlags, ctor) | |
1facf9fc | 21877 | + |
21878 | +extern struct kmem_cache *au_cachep[]; | |
21879 | + | |
21880 | +#define AuCacheFuncs(name, index) \ | |
4a4d8108 | 21881 | +static inline struct au_##name *au_cache_alloc_##name(void) \ |
1facf9fc | 21882 | +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \ |
4a4d8108 | 21883 | +static inline void au_cache_free_##name(struct au_##name *p) \ |
1facf9fc | 21884 | +{ kmem_cache_free(au_cachep[AuCache_##index], p); } |
21885 | + | |
21886 | +AuCacheFuncs(dinfo, DINFO); | |
21887 | +AuCacheFuncs(icntnr, ICNTNR); | |
21888 | +AuCacheFuncs(finfo, FINFO); | |
21889 | +AuCacheFuncs(vdir, VDIR); | |
4a4d8108 AM |
21890 | +AuCacheFuncs(vdir_dehstr, DEHSTR); |
21891 | +#ifdef CONFIG_AUFS_HNOTIFY | |
21892 | +AuCacheFuncs(hnotify, HNOTIFY); | |
21893 | +#endif | |
1facf9fc | 21894 | + |
4a4d8108 AM |
21895 | +#endif /* __KERNEL__ */ |
21896 | +#endif /* __AUFS_MODULE_H__ */ | |
c2b27bf2 AM |
21897 | diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c |
21898 | --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 21899 | +++ linux/fs/aufs/mvdown.c 2015-06-28 17:36:09.025073697 +0200 |
c1595e42 | 21900 | @@ -0,0 +1,694 @@ |
c2b27bf2 | 21901 | +/* |
2000de60 | 21902 | + * Copyright (C) 2011-2015 Junjiro R. Okajima |
c2b27bf2 AM |
21903 | + * |
21904 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21905 | + * it under the terms of the GNU General Public License as published by | |
21906 | + * the Free Software Foundation; either version 2 of the License, or | |
21907 | + * (at your option) any later version. | |
21908 | + * | |
21909 | + * This program is distributed in the hope that it will be useful, | |
21910 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21911 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21912 | + * GNU General Public License for more details. | |
21913 | + * | |
21914 | + * You should have received a copy of the GNU General Public License | |
523b37e3 AM |
21915 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21916 | + */ | |
21917 | + | |
21918 | +/* | |
21919 | + * move-down, opposite of copy-up | |
c2b27bf2 AM |
21920 | + */ |
21921 | + | |
21922 | +#include "aufs.h" | |
21923 | + | |
c2b27bf2 AM |
21924 | +struct au_mvd_args { |
21925 | + struct { | |
c2b27bf2 AM |
21926 | + struct super_block *h_sb; |
21927 | + struct dentry *h_parent; | |
21928 | + struct au_hinode *hdir; | |
392086de | 21929 | + struct inode *h_dir, *h_inode; |
c1595e42 | 21930 | + struct au_pin pin; |
c2b27bf2 AM |
21931 | + } info[AUFS_MVDOWN_NARRAY]; |
21932 | + | |
21933 | + struct aufs_mvdown mvdown; | |
21934 | + struct dentry *dentry, *parent; | |
21935 | + struct inode *inode, *dir; | |
21936 | + struct super_block *sb; | |
21937 | + aufs_bindex_t bopq, bwh, bfound; | |
21938 | + unsigned char rename_lock; | |
c2b27bf2 AM |
21939 | +}; |
21940 | + | |
392086de | 21941 | +#define mvd_errno mvdown.au_errno |
076b876e AM |
21942 | +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex |
21943 | +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid | |
21944 | +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex | |
21945 | +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid | |
c2b27bf2 | 21946 | + |
392086de AM |
21947 | +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb |
21948 | +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent | |
21949 | +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir | |
21950 | +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir | |
21951 | +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode | |
c1595e42 | 21952 | +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin |
392086de AM |
21953 | + |
21954 | +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb | |
21955 | +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent | |
21956 | +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir | |
21957 | +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir | |
21958 | +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode | |
c1595e42 | 21959 | +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin |
c2b27bf2 AM |
21960 | + |
21961 | +#define AU_MVD_PR(flag, ...) do { \ | |
21962 | + if (flag) \ | |
21963 | + pr_err(__VA_ARGS__); \ | |
21964 | + } while (0) | |
21965 | + | |
076b876e AM |
21966 | +static int find_lower_writable(struct au_mvd_args *a) |
21967 | +{ | |
21968 | + struct super_block *sb; | |
21969 | + aufs_bindex_t bindex, bend; | |
21970 | + struct au_branch *br; | |
21971 | + | |
21972 | + sb = a->sb; | |
21973 | + bindex = a->mvd_bsrc; | |
21974 | + bend = au_sbend(sb); | |
21975 | + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER) | |
21976 | + for (bindex++; bindex <= bend; bindex++) { | |
21977 | + br = au_sbr(sb, bindex); | |
21978 | + if (au_br_fhsm(br->br_perm) | |
21979 | + && (!(au_br_sb(br)->s_flags & MS_RDONLY))) | |
21980 | + return bindex; | |
21981 | + } | |
21982 | + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) | |
21983 | + for (bindex++; bindex <= bend; bindex++) { | |
21984 | + br = au_sbr(sb, bindex); | |
21985 | + if (!au_br_rdonly(br)) | |
21986 | + return bindex; | |
21987 | + } | |
21988 | + else | |
21989 | + for (bindex++; bindex <= bend; bindex++) { | |
21990 | + br = au_sbr(sb, bindex); | |
21991 | + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) { | |
21992 | + if (au_br_rdonly(br)) | |
21993 | + a->mvdown.flags | |
21994 | + |= AUFS_MVDOWN_ROLOWER_R; | |
21995 | + return bindex; | |
21996 | + } | |
21997 | + } | |
21998 | + | |
21999 | + return -1; | |
22000 | +} | |
22001 | + | |
c2b27bf2 | 22002 | +/* make the parent dir on bdst */ |
392086de | 22003 | +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22004 | +{ |
22005 | + int err; | |
22006 | + | |
22007 | + err = 0; | |
22008 | + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc); | |
22009 | + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst); | |
22010 | + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc); | |
22011 | + a->mvd_h_dst_parent = NULL; | |
22012 | + if (au_dbend(a->parent) >= a->mvd_bdst) | |
22013 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
22014 | + if (!a->mvd_h_dst_parent) { | |
22015 | + err = au_cpdown_dirs(a->dentry, a->mvd_bdst); | |
22016 | + if (unlikely(err)) { | |
392086de | 22017 | + AU_MVD_PR(dmsg, "cpdown_dirs failed\n"); |
c2b27bf2 AM |
22018 | + goto out; |
22019 | + } | |
22020 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
22021 | + } | |
22022 | + | |
22023 | +out: | |
22024 | + AuTraceErr(err); | |
22025 | + return err; | |
22026 | +} | |
22027 | + | |
22028 | +/* lock them all */ | |
392086de | 22029 | +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22030 | +{ |
22031 | + int err; | |
22032 | + struct dentry *h_trap; | |
22033 | + | |
22034 | + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc); | |
22035 | + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst); | |
c1595e42 JR |
22036 | + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst, |
22037 | + au_opt_udba(a->sb), | |
22038 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22039 | + AuTraceErr(err); | |
22040 | + if (unlikely(err)) { | |
22041 | + AU_MVD_PR(dmsg, "pin_dst failed\n"); | |
22042 | + goto out; | |
22043 | + } | |
22044 | + | |
c2b27bf2 AM |
22045 | + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) { |
22046 | + a->rename_lock = 0; | |
c1595e42 JR |
22047 | + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, |
22048 | + AuLsc_DI_PARENT, AuLsc_I_PARENT3, | |
22049 | + au_opt_udba(a->sb), | |
22050 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22051 | + err = au_do_pin(&a->mvd_pin_src); | |
22052 | + AuTraceErr(err); | |
5527c038 | 22053 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
22054 | + if (unlikely(err)) { |
22055 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
22056 | + goto out_dst; | |
22057 | + } | |
22058 | + goto out; /* success */ | |
c2b27bf2 AM |
22059 | + } |
22060 | + | |
c2b27bf2 | 22061 | + a->rename_lock = 1; |
c1595e42 JR |
22062 | + au_pin_hdir_unlock(&a->mvd_pin_dst); |
22063 | + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, | |
22064 | + au_opt_udba(a->sb), | |
22065 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22066 | + AuTraceErr(err); | |
5527c038 | 22067 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
22068 | + if (unlikely(err)) { |
22069 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
22070 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22071 | + goto out_dst; | |
22072 | + } | |
22073 | + au_pin_hdir_unlock(&a->mvd_pin_src); | |
c2b27bf2 AM |
22074 | + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
22075 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
22076 | + if (h_trap) { | |
22077 | + err = (h_trap != a->mvd_h_src_parent); | |
22078 | + if (err) | |
22079 | + err = (h_trap != a->mvd_h_dst_parent); | |
22080 | + } | |
22081 | + BUG_ON(err); /* it should never happen */ | |
c1595e42 JR |
22082 | + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) { |
22083 | + err = -EBUSY; | |
22084 | + AuTraceErr(err); | |
22085 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, | |
22086 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
22087 | + au_pin_hdir_lock(&a->mvd_pin_src); | |
22088 | + au_unpin(&a->mvd_pin_src); | |
22089 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22090 | + goto out_dst; | |
22091 | + } | |
22092 | + goto out; /* success */ | |
c2b27bf2 | 22093 | + |
c1595e42 JR |
22094 | +out_dst: |
22095 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
22096 | +out: |
22097 | + AuTraceErr(err); | |
22098 | + return err; | |
22099 | +} | |
22100 | + | |
392086de | 22101 | +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 | 22102 | +{ |
c1595e42 JR |
22103 | + if (!a->rename_lock) |
22104 | + au_unpin(&a->mvd_pin_src); | |
22105 | + else { | |
c2b27bf2 AM |
22106 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
22107 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
c1595e42 JR |
22108 | + au_pin_hdir_lock(&a->mvd_pin_src); |
22109 | + au_unpin(&a->mvd_pin_src); | |
22110 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22111 | + } | |
22112 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
22113 | +} |
22114 | + | |
22115 | +/* copy-down the file */ | |
392086de | 22116 | +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22117 | +{ |
22118 | + int err; | |
22119 | + struct au_cp_generic cpg = { | |
22120 | + .dentry = a->dentry, | |
22121 | + .bdst = a->mvd_bdst, | |
22122 | + .bsrc = a->mvd_bsrc, | |
22123 | + .len = -1, | |
c1595e42 | 22124 | + .pin = &a->mvd_pin_dst, |
c2b27bf2 AM |
22125 | + .flags = AuCpup_DTIME | AuCpup_HOPEN |
22126 | + }; | |
22127 | + | |
22128 | + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst); | |
392086de AM |
22129 | + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER) |
22130 | + au_fset_cpup(cpg.flags, OVERWRITE); | |
22131 | + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER) | |
22132 | + au_fset_cpup(cpg.flags, RWDST); | |
c2b27bf2 AM |
22133 | + err = au_sio_cpdown_simple(&cpg); |
22134 | + if (unlikely(err)) | |
392086de | 22135 | + AU_MVD_PR(dmsg, "cpdown failed\n"); |
c2b27bf2 AM |
22136 | + |
22137 | + AuTraceErr(err); | |
22138 | + return err; | |
22139 | +} | |
22140 | + | |
22141 | +/* | |
22142 | + * unlink the whiteout on bdst if exist which may be created by UDBA while we | |
22143 | + * were sleeping | |
22144 | + */ | |
392086de | 22145 | +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22146 | +{ |
22147 | + int err; | |
22148 | + struct path h_path; | |
22149 | + struct au_branch *br; | |
523b37e3 | 22150 | + struct inode *delegated; |
c2b27bf2 AM |
22151 | + |
22152 | + br = au_sbr(a->sb, a->mvd_bdst); | |
22153 | + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br); | |
22154 | + err = PTR_ERR(h_path.dentry); | |
22155 | + if (IS_ERR(h_path.dentry)) { | |
392086de | 22156 | + AU_MVD_PR(dmsg, "wh_lkup failed\n"); |
c2b27bf2 AM |
22157 | + goto out; |
22158 | + } | |
22159 | + | |
22160 | + err = 0; | |
5527c038 | 22161 | + if (d_is_positive(h_path.dentry)) { |
c2b27bf2 | 22162 | + h_path.mnt = au_br_mnt(br); |
523b37e3 | 22163 | + delegated = NULL; |
5527c038 | 22164 | + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path, |
523b37e3 AM |
22165 | + &delegated, /*force*/0); |
22166 | + if (unlikely(err == -EWOULDBLOCK)) { | |
22167 | + pr_warn("cannot retry for NFSv4 delegation" | |
22168 | + " for an internal unlink\n"); | |
22169 | + iput(delegated); | |
22170 | + } | |
c2b27bf2 | 22171 | + if (unlikely(err)) |
392086de | 22172 | + AU_MVD_PR(dmsg, "wh_unlink failed\n"); |
c2b27bf2 AM |
22173 | + } |
22174 | + dput(h_path.dentry); | |
22175 | + | |
22176 | +out: | |
22177 | + AuTraceErr(err); | |
22178 | + return err; | |
22179 | +} | |
22180 | + | |
22181 | +/* | |
22182 | + * unlink the topmost h_dentry | |
c2b27bf2 | 22183 | + */ |
392086de | 22184 | +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22185 | +{ |
22186 | + int err; | |
22187 | + struct path h_path; | |
523b37e3 | 22188 | + struct inode *delegated; |
c2b27bf2 AM |
22189 | + |
22190 | + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc); | |
22191 | + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc); | |
523b37e3 AM |
22192 | + delegated = NULL; |
22193 | + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0); | |
22194 | + if (unlikely(err == -EWOULDBLOCK)) { | |
22195 | + pr_warn("cannot retry for NFSv4 delegation" | |
22196 | + " for an internal unlink\n"); | |
22197 | + iput(delegated); | |
22198 | + } | |
c2b27bf2 | 22199 | + if (unlikely(err)) |
392086de | 22200 | + AU_MVD_PR(dmsg, "unlink failed\n"); |
c2b27bf2 AM |
22201 | + |
22202 | + AuTraceErr(err); | |
22203 | + return err; | |
22204 | +} | |
22205 | + | |
076b876e AM |
22206 | +/* Since mvdown succeeded, we ignore an error of this function */ |
22207 | +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a) | |
22208 | +{ | |
22209 | + int err; | |
22210 | + struct au_branch *br; | |
22211 | + | |
22212 | + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED; | |
22213 | + br = au_sbr(a->sb, a->mvd_bsrc); | |
22214 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs); | |
22215 | + if (!err) { | |
22216 | + br = au_sbr(a->sb, a->mvd_bdst); | |
22217 | + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id; | |
22218 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs); | |
22219 | + } | |
22220 | + if (!err) | |
22221 | + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED; | |
22222 | + else | |
22223 | + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err); | |
22224 | +} | |
22225 | + | |
c2b27bf2 AM |
22226 | +/* |
22227 | + * copy-down the file and unlink the bsrc file. | |
22228 | + * - unlink the bdst whout if exist | |
22229 | + * - copy-down the file (with whtmp name and rename) | |
22230 | + * - unlink the bsrc file | |
22231 | + */ | |
392086de | 22232 | +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22233 | +{ |
22234 | + int err; | |
22235 | + | |
392086de | 22236 | + err = au_do_mkdir(dmsg, a); |
c2b27bf2 | 22237 | + if (!err) |
392086de | 22238 | + err = au_do_lock(dmsg, a); |
c2b27bf2 AM |
22239 | + if (unlikely(err)) |
22240 | + goto out; | |
22241 | + | |
22242 | + /* | |
22243 | + * do not revert the activities we made on bdst since they should be | |
22244 | + * harmless in aufs. | |
22245 | + */ | |
22246 | + | |
392086de | 22247 | + err = au_do_cpdown(dmsg, a); |
c2b27bf2 | 22248 | + if (!err) |
392086de AM |
22249 | + err = au_do_unlink_wh(dmsg, a); |
22250 | + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
22251 | + err = au_do_unlink(dmsg, a); | |
c2b27bf2 AM |
22252 | + if (unlikely(err)) |
22253 | + goto out_unlock; | |
22254 | + | |
c1595e42 JR |
22255 | + AuDbg("%pd2, 0x%x, %d --> %d\n", |
22256 | + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst); | |
076b876e AM |
22257 | + if (find_lower_writable(a) < 0) |
22258 | + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM; | |
22259 | + | |
22260 | + if (a->mvdown.flags & AUFS_MVDOWN_STFS) | |
22261 | + au_do_stfs(dmsg, a); | |
22262 | + | |
c2b27bf2 | 22263 | + /* maintain internal array */ |
392086de AM |
22264 | + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) { |
22265 | + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL); | |
22266 | + au_set_dbstart(a->dentry, a->mvd_bdst); | |
22267 | + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0); | |
22268 | + au_set_ibstart(a->inode, a->mvd_bdst); | |
22269 | + } | |
c2b27bf2 AM |
22270 | + if (au_dbend(a->dentry) < a->mvd_bdst) |
22271 | + au_set_dbend(a->dentry, a->mvd_bdst); | |
c2b27bf2 AM |
22272 | + if (au_ibend(a->inode) < a->mvd_bdst) |
22273 | + au_set_ibend(a->inode, a->mvd_bdst); | |
22274 | + | |
22275 | +out_unlock: | |
392086de | 22276 | + au_do_unlock(dmsg, a); |
c2b27bf2 AM |
22277 | +out: |
22278 | + AuTraceErr(err); | |
22279 | + return err; | |
22280 | +} | |
22281 | + | |
22282 | +/* ---------------------------------------------------------------------- */ | |
22283 | + | |
c2b27bf2 | 22284 | +/* make sure the file is idle */ |
392086de | 22285 | +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22286 | +{ |
22287 | + int err, plinked; | |
c2b27bf2 AM |
22288 | + |
22289 | + err = 0; | |
c2b27bf2 AM |
22290 | + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK); |
22291 | + if (au_dbstart(a->dentry) == a->mvd_bsrc | |
c1595e42 | 22292 | + && au_dcount(a->dentry) == 1 |
c2b27bf2 | 22293 | + && atomic_read(&a->inode->i_count) == 1 |
392086de | 22294 | + /* && a->mvd_h_src_inode->i_nlink == 1 */ |
c2b27bf2 AM |
22295 | + && (!plinked || !au_plink_test(a->inode)) |
22296 | + && a->inode->i_nlink == 1) | |
22297 | + goto out; | |
22298 | + | |
22299 | + err = -EBUSY; | |
392086de | 22300 | + AU_MVD_PR(dmsg, |
c1595e42 JR |
22301 | + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n", |
22302 | + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry), | |
c2b27bf2 | 22303 | + atomic_read(&a->inode->i_count), a->inode->i_nlink, |
392086de | 22304 | + a->mvd_h_src_inode->i_nlink, |
c2b27bf2 AM |
22305 | + plinked, plinked ? au_plink_test(a->inode) : 0); |
22306 | + | |
22307 | +out: | |
22308 | + AuTraceErr(err); | |
22309 | + return err; | |
22310 | +} | |
22311 | + | |
22312 | +/* make sure the parent dir is fine */ | |
392086de | 22313 | +static int au_mvd_args_parent(const unsigned char dmsg, |
c2b27bf2 AM |
22314 | + struct au_mvd_args *a) |
22315 | +{ | |
22316 | + int err; | |
22317 | + aufs_bindex_t bindex; | |
22318 | + | |
22319 | + err = 0; | |
22320 | + if (unlikely(au_alive_dir(a->parent))) { | |
22321 | + err = -ENOENT; | |
392086de | 22322 | + AU_MVD_PR(dmsg, "parent dir is dead\n"); |
c2b27bf2 AM |
22323 | + goto out; |
22324 | + } | |
22325 | + | |
22326 | + a->bopq = au_dbdiropq(a->parent); | |
22327 | + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst); | |
22328 | + AuDbg("b%d\n", bindex); | |
22329 | + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst) | |
22330 | + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) { | |
22331 | + err = -EINVAL; | |
392086de AM |
22332 | + a->mvd_errno = EAU_MVDOWN_OPAQUE; |
22333 | + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n", | |
c2b27bf2 AM |
22334 | + a->bopq, a->mvd_bdst); |
22335 | + } | |
22336 | + | |
22337 | +out: | |
22338 | + AuTraceErr(err); | |
22339 | + return err; | |
22340 | +} | |
22341 | + | |
392086de | 22342 | +static int au_mvd_args_intermediate(const unsigned char dmsg, |
c2b27bf2 AM |
22343 | + struct au_mvd_args *a) |
22344 | +{ | |
22345 | + int err; | |
22346 | + struct au_dinfo *dinfo, *tmp; | |
22347 | + | |
22348 | + /* lookup the next lower positive entry */ | |
22349 | + err = -ENOMEM; | |
22350 | + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP); | |
22351 | + if (unlikely(!tmp)) | |
22352 | + goto out; | |
22353 | + | |
22354 | + a->bfound = -1; | |
22355 | + a->bwh = -1; | |
22356 | + dinfo = au_di(a->dentry); | |
22357 | + au_di_cp(tmp, dinfo); | |
22358 | + au_di_swap(tmp, dinfo); | |
22359 | + | |
22360 | + /* returns the number of positive dentries */ | |
22361 | + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0); | |
22362 | + if (!err) | |
22363 | + a->bwh = au_dbwh(a->dentry); | |
22364 | + else if (err > 0) | |
22365 | + a->bfound = au_dbstart(a->dentry); | |
22366 | + | |
22367 | + au_di_swap(tmp, dinfo); | |
22368 | + au_rw_write_unlock(&tmp->di_rwsem); | |
22369 | + au_di_free(tmp); | |
22370 | + if (unlikely(err < 0)) | |
392086de | 22371 | + AU_MVD_PR(dmsg, "failed look-up lower\n"); |
c2b27bf2 AM |
22372 | + |
22373 | + /* | |
22374 | + * here, we have these cases. | |
22375 | + * bfound == -1 | |
22376 | + * no positive dentry under bsrc. there are more sub-cases. | |
22377 | + * bwh < 0 | |
22378 | + * there no whiteout, we can safely move-down. | |
22379 | + * bwh <= bsrc | |
22380 | + * impossible | |
22381 | + * bsrc < bwh && bwh < bdst | |
22382 | + * there is a whiteout on RO branch. cannot proceed. | |
22383 | + * bwh == bdst | |
22384 | + * there is a whiteout on the RW target branch. it should | |
22385 | + * be removed. | |
22386 | + * bdst < bwh | |
22387 | + * there is a whiteout somewhere unrelated branch. | |
22388 | + * -1 < bfound && bfound <= bsrc | |
22389 | + * impossible. | |
22390 | + * bfound < bdst | |
22391 | + * found, but it is on RO branch between bsrc and bdst. cannot | |
22392 | + * proceed. | |
22393 | + * bfound == bdst | |
22394 | + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return | |
22395 | + * error. | |
22396 | + * bdst < bfound | |
22397 | + * found, after we create the file on bdst, it will be hidden. | |
22398 | + */ | |
22399 | + | |
22400 | + AuDebugOn(a->bfound == -1 | |
22401 | + && a->bwh != -1 | |
22402 | + && a->bwh <= a->mvd_bsrc); | |
22403 | + AuDebugOn(-1 < a->bfound | |
22404 | + && a->bfound <= a->mvd_bsrc); | |
22405 | + | |
22406 | + err = -EINVAL; | |
22407 | + if (a->bfound == -1 | |
22408 | + && a->mvd_bsrc < a->bwh | |
22409 | + && a->bwh != -1 | |
22410 | + && a->bwh < a->mvd_bdst) { | |
392086de AM |
22411 | + a->mvd_errno = EAU_MVDOWN_WHITEOUT; |
22412 | + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n", | |
c2b27bf2 AM |
22413 | + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh); |
22414 | + goto out; | |
22415 | + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) { | |
392086de AM |
22416 | + a->mvd_errno = EAU_MVDOWN_UPPER; |
22417 | + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n", | |
c2b27bf2 AM |
22418 | + a->mvd_bdst, a->bfound); |
22419 | + goto out; | |
22420 | + } | |
22421 | + | |
22422 | + err = 0; /* success */ | |
22423 | + | |
22424 | +out: | |
22425 | + AuTraceErr(err); | |
22426 | + return err; | |
22427 | +} | |
22428 | + | |
392086de | 22429 | +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22430 | +{ |
22431 | + int err; | |
22432 | + | |
392086de AM |
22433 | + err = 0; |
22434 | + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER) | |
22435 | + && a->bfound == a->mvd_bdst) | |
22436 | + err = -EEXIST; | |
c2b27bf2 AM |
22437 | + AuTraceErr(err); |
22438 | + return err; | |
22439 | +} | |
22440 | + | |
392086de | 22441 | +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22442 | +{ |
22443 | + int err; | |
22444 | + struct au_branch *br; | |
22445 | + | |
22446 | + err = -EISDIR; | |
22447 | + if (unlikely(S_ISDIR(a->inode->i_mode))) | |
22448 | + goto out; | |
22449 | + | |
22450 | + err = -EINVAL; | |
392086de AM |
22451 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER)) |
22452 | + a->mvd_bsrc = au_ibstart(a->inode); | |
22453 | + else { | |
22454 | + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid); | |
22455 | + if (unlikely(a->mvd_bsrc < 0 | |
22456 | + || (a->mvd_bsrc < au_dbstart(a->dentry) | |
22457 | + || au_dbend(a->dentry) < a->mvd_bsrc | |
22458 | + || !au_h_dptr(a->dentry, a->mvd_bsrc)) | |
22459 | + || (a->mvd_bsrc < au_ibstart(a->inode) | |
22460 | + || au_ibend(a->inode) < a->mvd_bsrc | |
22461 | + || !au_h_iptr(a->inode, a->mvd_bsrc)))) { | |
22462 | + a->mvd_errno = EAU_MVDOWN_NOUPPER; | |
22463 | + AU_MVD_PR(dmsg, "no upper\n"); | |
22464 | + goto out; | |
22465 | + } | |
22466 | + } | |
c2b27bf2 | 22467 | + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) { |
392086de AM |
22468 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; |
22469 | + AU_MVD_PR(dmsg, "on the bottom\n"); | |
c2b27bf2 AM |
22470 | + goto out; |
22471 | + } | |
392086de | 22472 | + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc); |
c2b27bf2 AM |
22473 | + br = au_sbr(a->sb, a->mvd_bsrc); |
22474 | + err = au_br_rdonly(br); | |
392086de AM |
22475 | + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) { |
22476 | + if (unlikely(err)) | |
22477 | + goto out; | |
22478 | + } else if (!(vfsub_native_ro(a->mvd_h_src_inode) | |
22479 | + || IS_APPEND(a->mvd_h_src_inode))) { | |
22480 | + if (err) | |
22481 | + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R; | |
22482 | + /* go on */ | |
22483 | + } else | |
c2b27bf2 AM |
22484 | + goto out; |
22485 | + | |
22486 | + err = -EINVAL; | |
392086de AM |
22487 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) { |
22488 | + a->mvd_bdst = find_lower_writable(a); | |
22489 | + if (unlikely(a->mvd_bdst < 0)) { | |
22490 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; | |
22491 | + AU_MVD_PR(dmsg, "no writable lower branch\n"); | |
22492 | + goto out; | |
22493 | + } | |
22494 | + } else { | |
22495 | + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid); | |
22496 | + if (unlikely(a->mvd_bdst < 0 | |
22497 | + || au_sbend(a->sb) < a->mvd_bdst)) { | |
22498 | + a->mvd_errno = EAU_MVDOWN_NOLOWERBR; | |
22499 | + AU_MVD_PR(dmsg, "no lower brid\n"); | |
22500 | + goto out; | |
22501 | + } | |
c2b27bf2 AM |
22502 | + } |
22503 | + | |
392086de | 22504 | + err = au_mvd_args_busy(dmsg, a); |
c2b27bf2 | 22505 | + if (!err) |
392086de | 22506 | + err = au_mvd_args_parent(dmsg, a); |
c2b27bf2 | 22507 | + if (!err) |
392086de | 22508 | + err = au_mvd_args_intermediate(dmsg, a); |
c2b27bf2 | 22509 | + if (!err) |
392086de | 22510 | + err = au_mvd_args_exist(dmsg, a); |
c2b27bf2 AM |
22511 | + if (!err) |
22512 | + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst); | |
22513 | + | |
22514 | +out: | |
22515 | + AuTraceErr(err); | |
22516 | + return err; | |
22517 | +} | |
22518 | + | |
22519 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg) | |
22520 | +{ | |
392086de AM |
22521 | + int err, e; |
22522 | + unsigned char dmsg; | |
22523 | + struct au_mvd_args *args; | |
c2b27bf2 AM |
22524 | + |
22525 | + err = -EPERM; | |
22526 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
22527 | + goto out; | |
22528 | + | |
392086de AM |
22529 | + err = -ENOMEM; |
22530 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
22531 | + if (unlikely(!args)) | |
22532 | + goto out; | |
22533 | + | |
22534 | + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown)); | |
22535 | + if (!err) | |
22536 | + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg)); | |
c2b27bf2 AM |
22537 | + if (unlikely(err)) { |
22538 | + err = -EFAULT; | |
392086de AM |
22539 | + AuTraceErr(err); |
22540 | + goto out_free; | |
c2b27bf2 | 22541 | + } |
392086de AM |
22542 | + AuDbg("flags 0x%x\n", args->mvdown.flags); |
22543 | + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R); | |
22544 | + args->mvdown.au_errno = 0; | |
22545 | + args->dentry = dentry; | |
5527c038 | 22546 | + args->inode = d_inode(dentry); |
392086de | 22547 | + args->sb = dentry->d_sb; |
c2b27bf2 | 22548 | + |
392086de AM |
22549 | + err = -ENOENT; |
22550 | + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG); | |
22551 | + args->parent = dget_parent(dentry); | |
5527c038 | 22552 | + args->dir = d_inode(args->parent); |
392086de AM |
22553 | + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT); |
22554 | + dput(args->parent); | |
22555 | + if (unlikely(args->parent != dentry->d_parent)) { | |
22556 | + AU_MVD_PR(dmsg, "parent dir is moved\n"); | |
c2b27bf2 AM |
22557 | + goto out_dir; |
22558 | + } | |
22559 | + | |
392086de | 22560 | + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD); |
c2b27bf2 AM |
22561 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH); |
22562 | + if (unlikely(err)) | |
22563 | + goto out_inode; | |
22564 | + | |
392086de AM |
22565 | + di_write_lock_parent(args->parent); |
22566 | + err = au_mvd_args(dmsg, args); | |
c2b27bf2 AM |
22567 | + if (unlikely(err)) |
22568 | + goto out_parent; | |
22569 | + | |
392086de | 22570 | + err = au_do_mvdown(dmsg, args); |
c2b27bf2 AM |
22571 | + if (unlikely(err)) |
22572 | + goto out_parent; | |
c2b27bf2 | 22573 | + |
392086de AM |
22574 | + au_cpup_attr_timesizes(args->dir); |
22575 | + au_cpup_attr_timesizes(args->inode); | |
22576 | + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst)); | |
c2b27bf2 AM |
22577 | + /* au_digen_dec(dentry); */ |
22578 | + | |
22579 | +out_parent: | |
392086de | 22580 | + di_write_unlock(args->parent); |
c2b27bf2 AM |
22581 | + aufs_read_unlock(dentry, AuLock_DW); |
22582 | +out_inode: | |
392086de | 22583 | + mutex_unlock(&args->inode->i_mutex); |
c2b27bf2 | 22584 | +out_dir: |
392086de AM |
22585 | + mutex_unlock(&args->dir->i_mutex); |
22586 | +out_free: | |
22587 | + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown)); | |
22588 | + if (unlikely(e)) | |
22589 | + err = -EFAULT; | |
22590 | + kfree(args); | |
c2b27bf2 AM |
22591 | +out: |
22592 | + AuTraceErr(err); | |
22593 | + return err; | |
22594 | +} | |
22595 | diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c | |
22596 | --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
22597 | +++ linux/fs/aufs/opts.c 2015-06-28 17:36:09.028407078 +0200 |
22598 | @@ -0,0 +1,1835 @@ | |
1facf9fc | 22599 | +/* |
2000de60 | 22600 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 22601 | + * |
22602 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22603 | + * it under the terms of the GNU General Public License as published by | |
22604 | + * the Free Software Foundation; either version 2 of the License, or | |
22605 | + * (at your option) any later version. | |
dece6358 AM |
22606 | + * |
22607 | + * This program is distributed in the hope that it will be useful, | |
22608 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22609 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22610 | + * GNU General Public License for more details. | |
22611 | + * | |
22612 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22613 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22614 | + */ |
22615 | + | |
22616 | +/* | |
22617 | + * mount options/flags | |
22618 | + */ | |
22619 | + | |
dece6358 | 22620 | +#include <linux/namei.h> |
1facf9fc | 22621 | +#include <linux/types.h> /* a distribution requires */ |
22622 | +#include <linux/parser.h> | |
22623 | +#include "aufs.h" | |
22624 | + | |
22625 | +/* ---------------------------------------------------------------------- */ | |
22626 | + | |
22627 | +enum { | |
22628 | + Opt_br, | |
7e9cd9fe AM |
22629 | + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend, |
22630 | + Opt_idel, Opt_imod, | |
22631 | + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, | |
dece6358 | 22632 | + Opt_rdblk_def, Opt_rdhash_def, |
7e9cd9fe | 22633 | + Opt_xino, Opt_noxino, |
1facf9fc | 22634 | + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino, |
22635 | + Opt_trunc_xino_path, Opt_itrunc_xino, | |
22636 | + Opt_trunc_xib, Opt_notrunc_xib, | |
dece6358 | 22637 | + Opt_shwh, Opt_noshwh, |
1facf9fc | 22638 | + Opt_plink, Opt_noplink, Opt_list_plink, |
22639 | + Opt_udba, | |
4a4d8108 | 22640 | + Opt_dio, Opt_nodio, |
1facf9fc | 22641 | + Opt_diropq_a, Opt_diropq_w, |
22642 | + Opt_warn_perm, Opt_nowarn_perm, | |
22643 | + Opt_wbr_copyup, Opt_wbr_create, | |
076b876e | 22644 | + Opt_fhsm_sec, |
1facf9fc | 22645 | + Opt_verbose, Opt_noverbose, |
22646 | + Opt_sum, Opt_nosum, Opt_wsum, | |
076b876e | 22647 | + Opt_dirperm1, Opt_nodirperm1, |
c1595e42 | 22648 | + Opt_acl, Opt_noacl, |
1facf9fc | 22649 | + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err |
22650 | +}; | |
22651 | + | |
22652 | +static match_table_t options = { | |
22653 | + {Opt_br, "br=%s"}, | |
22654 | + {Opt_br, "br:%s"}, | |
22655 | + | |
22656 | + {Opt_add, "add=%d:%s"}, | |
22657 | + {Opt_add, "add:%d:%s"}, | |
22658 | + {Opt_add, "ins=%d:%s"}, | |
22659 | + {Opt_add, "ins:%d:%s"}, | |
22660 | + {Opt_append, "append=%s"}, | |
22661 | + {Opt_append, "append:%s"}, | |
22662 | + {Opt_prepend, "prepend=%s"}, | |
22663 | + {Opt_prepend, "prepend:%s"}, | |
22664 | + | |
22665 | + {Opt_del, "del=%s"}, | |
22666 | + {Opt_del, "del:%s"}, | |
22667 | + /* {Opt_idel, "idel:%d"}, */ | |
22668 | + {Opt_mod, "mod=%s"}, | |
22669 | + {Opt_mod, "mod:%s"}, | |
22670 | + /* {Opt_imod, "imod:%d:%s"}, */ | |
22671 | + | |
22672 | + {Opt_dirwh, "dirwh=%d"}, | |
22673 | + | |
22674 | + {Opt_xino, "xino=%s"}, | |
22675 | + {Opt_noxino, "noxino"}, | |
22676 | + {Opt_trunc_xino, "trunc_xino"}, | |
22677 | + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"}, | |
22678 | + {Opt_notrunc_xino, "notrunc_xino"}, | |
22679 | + {Opt_trunc_xino_path, "trunc_xino=%s"}, | |
22680 | + {Opt_itrunc_xino, "itrunc_xino=%d"}, | |
22681 | + /* {Opt_zxino, "zxino=%s"}, */ | |
22682 | + {Opt_trunc_xib, "trunc_xib"}, | |
22683 | + {Opt_notrunc_xib, "notrunc_xib"}, | |
22684 | + | |
e49829fe | 22685 | +#ifdef CONFIG_PROC_FS |
1facf9fc | 22686 | + {Opt_plink, "plink"}, |
e49829fe JR |
22687 | +#else |
22688 | + {Opt_ignore_silent, "plink"}, | |
22689 | +#endif | |
22690 | + | |
1facf9fc | 22691 | + {Opt_noplink, "noplink"}, |
e49829fe | 22692 | + |
1facf9fc | 22693 | +#ifdef CONFIG_AUFS_DEBUG |
22694 | + {Opt_list_plink, "list_plink"}, | |
22695 | +#endif | |
22696 | + | |
22697 | + {Opt_udba, "udba=%s"}, | |
22698 | + | |
4a4d8108 AM |
22699 | + {Opt_dio, "dio"}, |
22700 | + {Opt_nodio, "nodio"}, | |
22701 | + | |
076b876e AM |
22702 | +#ifdef CONFIG_AUFS_FHSM |
22703 | + {Opt_fhsm_sec, "fhsm_sec=%d"}, | |
22704 | +#else | |
22705 | + {Opt_ignore_silent, "fhsm_sec=%d"}, | |
22706 | +#endif | |
22707 | + | |
1facf9fc | 22708 | + {Opt_diropq_a, "diropq=always"}, |
22709 | + {Opt_diropq_a, "diropq=a"}, | |
22710 | + {Opt_diropq_w, "diropq=whiteouted"}, | |
22711 | + {Opt_diropq_w, "diropq=w"}, | |
22712 | + | |
22713 | + {Opt_warn_perm, "warn_perm"}, | |
22714 | + {Opt_nowarn_perm, "nowarn_perm"}, | |
22715 | + | |
22716 | + /* keep them temporary */ | |
1facf9fc | 22717 | + {Opt_ignore_silent, "nodlgt"}, |
1facf9fc | 22718 | + {Opt_ignore_silent, "clean_plink"}, |
22719 | + | |
dece6358 AM |
22720 | +#ifdef CONFIG_AUFS_SHWH |
22721 | + {Opt_shwh, "shwh"}, | |
22722 | +#endif | |
22723 | + {Opt_noshwh, "noshwh"}, | |
22724 | + | |
076b876e AM |
22725 | + {Opt_dirperm1, "dirperm1"}, |
22726 | + {Opt_nodirperm1, "nodirperm1"}, | |
22727 | + | |
1facf9fc | 22728 | + {Opt_verbose, "verbose"}, |
22729 | + {Opt_verbose, "v"}, | |
22730 | + {Opt_noverbose, "noverbose"}, | |
22731 | + {Opt_noverbose, "quiet"}, | |
22732 | + {Opt_noverbose, "q"}, | |
22733 | + {Opt_noverbose, "silent"}, | |
22734 | + | |
22735 | + {Opt_sum, "sum"}, | |
22736 | + {Opt_nosum, "nosum"}, | |
22737 | + {Opt_wsum, "wsum"}, | |
22738 | + | |
22739 | + {Opt_rdcache, "rdcache=%d"}, | |
22740 | + {Opt_rdblk, "rdblk=%d"}, | |
dece6358 | 22741 | + {Opt_rdblk_def, "rdblk=def"}, |
1facf9fc | 22742 | + {Opt_rdhash, "rdhash=%d"}, |
dece6358 | 22743 | + {Opt_rdhash_def, "rdhash=def"}, |
1facf9fc | 22744 | + |
22745 | + {Opt_wbr_create, "create=%s"}, | |
22746 | + {Opt_wbr_create, "create_policy=%s"}, | |
22747 | + {Opt_wbr_copyup, "cpup=%s"}, | |
22748 | + {Opt_wbr_copyup, "copyup=%s"}, | |
22749 | + {Opt_wbr_copyup, "copyup_policy=%s"}, | |
22750 | + | |
c1595e42 JR |
22751 | + /* generic VFS flag */ |
22752 | +#ifdef CONFIG_FS_POSIX_ACL | |
22753 | + {Opt_acl, "acl"}, | |
22754 | + {Opt_noacl, "noacl"}, | |
22755 | +#else | |
22756 | + {Opt_ignore_silent, "acl"}, | |
22757 | + {Opt_ignore_silent, "noacl"}, | |
22758 | +#endif | |
22759 | + | |
1facf9fc | 22760 | + /* internal use for the scripts */ |
22761 | + {Opt_ignore_silent, "si=%s"}, | |
22762 | + | |
22763 | + {Opt_br, "dirs=%s"}, | |
22764 | + {Opt_ignore, "debug=%d"}, | |
22765 | + {Opt_ignore, "delete=whiteout"}, | |
22766 | + {Opt_ignore, "delete=all"}, | |
22767 | + {Opt_ignore, "imap=%s"}, | |
22768 | + | |
1308ab2a | 22769 | + /* temporary workaround, due to old mount(8)? */ |
22770 | + {Opt_ignore_silent, "relatime"}, | |
22771 | + | |
1facf9fc | 22772 | + {Opt_err, NULL} |
22773 | +}; | |
22774 | + | |
22775 | +/* ---------------------------------------------------------------------- */ | |
22776 | + | |
076b876e | 22777 | +static const char *au_parser_pattern(int val, match_table_t tbl) |
1facf9fc | 22778 | +{ |
076b876e AM |
22779 | + struct match_token *p; |
22780 | + | |
22781 | + p = tbl; | |
22782 | + while (p->pattern) { | |
22783 | + if (p->token == val) | |
22784 | + return p->pattern; | |
22785 | + p++; | |
1facf9fc | 22786 | + } |
22787 | + BUG(); | |
22788 | + return "??"; | |
22789 | +} | |
22790 | + | |
076b876e AM |
22791 | +static const char *au_optstr(int *val, match_table_t tbl) |
22792 | +{ | |
22793 | + struct match_token *p; | |
22794 | + int v; | |
22795 | + | |
22796 | + v = *val; | |
2000de60 JR |
22797 | + if (!v) |
22798 | + goto out; | |
076b876e | 22799 | + p = tbl; |
2000de60 JR |
22800 | + while (p->pattern) { |
22801 | + if (p->token | |
22802 | + && (v & p->token) == p->token) { | |
076b876e AM |
22803 | + *val &= ~p->token; |
22804 | + return p->pattern; | |
22805 | + } | |
22806 | + p++; | |
22807 | + } | |
2000de60 JR |
22808 | + |
22809 | +out: | |
076b876e AM |
22810 | + return NULL; |
22811 | +} | |
22812 | + | |
1facf9fc | 22813 | +/* ---------------------------------------------------------------------- */ |
22814 | + | |
1e00d052 | 22815 | +static match_table_t brperm = { |
1facf9fc | 22816 | + {AuBrPerm_RO, AUFS_BRPERM_RO}, |
22817 | + {AuBrPerm_RR, AUFS_BRPERM_RR}, | |
22818 | + {AuBrPerm_RW, AUFS_BRPERM_RW}, | |
1e00d052 AM |
22819 | + {0, NULL} |
22820 | +}; | |
1facf9fc | 22821 | + |
86dc4139 | 22822 | +static match_table_t brattr = { |
076b876e AM |
22823 | + /* general */ |
22824 | + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG}, | |
22825 | + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL}, | |
c1595e42 | 22826 | + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */ |
86dc4139 | 22827 | + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN}, |
2000de60 | 22828 | +#ifdef CONFIG_AUFS_FHSM |
076b876e | 22829 | + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM}, |
2000de60 JR |
22830 | +#endif |
22831 | +#ifdef CONFIG_AUFS_XATTR | |
c1595e42 JR |
22832 | + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX}, |
22833 | + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC}, | |
22834 | + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS}, | |
22835 | + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR}, | |
22836 | + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR}, | |
22837 | + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH}, | |
2000de60 | 22838 | +#endif |
076b876e AM |
22839 | + |
22840 | + /* ro/rr branch */ | |
1e00d052 | 22841 | + {AuBrRAttr_WH, AUFS_BRRATTR_WH}, |
076b876e AM |
22842 | + |
22843 | + /* rw branch */ | |
22844 | + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO}, | |
1e00d052 | 22845 | + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH}, |
076b876e | 22846 | + |
1e00d052 | 22847 | + {0, NULL} |
1facf9fc | 22848 | +}; |
22849 | + | |
1e00d052 AM |
22850 | +static int br_attr_val(char *str, match_table_t table, substring_t args[]) |
22851 | +{ | |
22852 | + int attr, v; | |
22853 | + char *p; | |
22854 | + | |
22855 | + attr = 0; | |
22856 | + do { | |
22857 | + p = strchr(str, '+'); | |
22858 | + if (p) | |
22859 | + *p = 0; | |
22860 | + v = match_token(str, table, args); | |
076b876e AM |
22861 | + if (v) { |
22862 | + if (v & AuBrAttr_CMOO_Mask) | |
22863 | + attr &= ~AuBrAttr_CMOO_Mask; | |
1e00d052 | 22864 | + attr |= v; |
076b876e | 22865 | + } else { |
1e00d052 AM |
22866 | + if (p) |
22867 | + *p = '+'; | |
0c3ec466 | 22868 | + pr_warn("ignored branch attribute %s\n", str); |
1e00d052 AM |
22869 | + break; |
22870 | + } | |
22871 | + if (p) | |
22872 | + str = p + 1; | |
22873 | + } while (p); | |
22874 | + | |
22875 | + return attr; | |
22876 | +} | |
22877 | + | |
076b876e AM |
22878 | +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm) |
22879 | +{ | |
22880 | + int sz; | |
22881 | + const char *p; | |
22882 | + char *q; | |
22883 | + | |
076b876e AM |
22884 | + q = str->a; |
22885 | + *q = 0; | |
22886 | + p = au_optstr(&perm, brattr); | |
22887 | + if (p) { | |
22888 | + sz = strlen(p); | |
22889 | + memcpy(q, p, sz + 1); | |
22890 | + q += sz; | |
22891 | + } else | |
22892 | + goto out; | |
22893 | + | |
22894 | + do { | |
22895 | + p = au_optstr(&perm, brattr); | |
22896 | + if (p) { | |
22897 | + *q++ = '+'; | |
22898 | + sz = strlen(p); | |
22899 | + memcpy(q, p, sz + 1); | |
22900 | + q += sz; | |
22901 | + } | |
22902 | + } while (p); | |
22903 | + | |
22904 | +out: | |
c1595e42 | 22905 | + return q - str->a; |
076b876e AM |
22906 | +} |
22907 | + | |
4a4d8108 | 22908 | +static int noinline_for_stack br_perm_val(char *perm) |
1facf9fc | 22909 | +{ |
076b876e AM |
22910 | + int val, bad, sz; |
22911 | + char *p; | |
1facf9fc | 22912 | + substring_t args[MAX_OPT_ARGS]; |
076b876e | 22913 | + au_br_perm_str_t attr; |
1facf9fc | 22914 | + |
1e00d052 AM |
22915 | + p = strchr(perm, '+'); |
22916 | + if (p) | |
22917 | + *p = 0; | |
22918 | + val = match_token(perm, brperm, args); | |
22919 | + if (!val) { | |
22920 | + if (p) | |
22921 | + *p = '+'; | |
0c3ec466 | 22922 | + pr_warn("ignored branch permission %s\n", perm); |
1e00d052 AM |
22923 | + val = AuBrPerm_RO; |
22924 | + goto out; | |
22925 | + } | |
22926 | + if (!p) | |
22927 | + goto out; | |
22928 | + | |
076b876e AM |
22929 | + val |= br_attr_val(p + 1, brattr, args); |
22930 | + | |
22931 | + bad = 0; | |
86dc4139 | 22932 | + switch (val & AuBrPerm_Mask) { |
1e00d052 AM |
22933 | + case AuBrPerm_RO: |
22934 | + case AuBrPerm_RR: | |
076b876e AM |
22935 | + bad = val & AuBrWAttr_Mask; |
22936 | + val &= ~AuBrWAttr_Mask; | |
1e00d052 AM |
22937 | + break; |
22938 | + case AuBrPerm_RW: | |
076b876e AM |
22939 | + bad = val & AuBrRAttr_Mask; |
22940 | + val &= ~AuBrRAttr_Mask; | |
1e00d052 AM |
22941 | + break; |
22942 | + } | |
c1595e42 JR |
22943 | + |
22944 | + /* | |
22945 | + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs | |
22946 | + * does not treat it as an error, just warning. | |
22947 | + * this is a tiny guard for the user operation. | |
22948 | + */ | |
22949 | + if (val & AuBrAttr_UNPIN) { | |
22950 | + bad |= AuBrAttr_UNPIN; | |
22951 | + val &= ~AuBrAttr_UNPIN; | |
22952 | + } | |
22953 | + | |
076b876e AM |
22954 | + if (unlikely(bad)) { |
22955 | + sz = au_do_optstr_br_attr(&attr, bad); | |
22956 | + AuDebugOn(!sz); | |
22957 | + pr_warn("ignored branch attribute %s\n", attr.a); | |
22958 | + } | |
1e00d052 AM |
22959 | + |
22960 | +out: | |
1facf9fc | 22961 | + return val; |
22962 | +} | |
22963 | + | |
076b876e | 22964 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm) |
1facf9fc | 22965 | +{ |
076b876e AM |
22966 | + au_br_perm_str_t attr; |
22967 | + const char *p; | |
22968 | + char *q; | |
1e00d052 AM |
22969 | + int sz; |
22970 | + | |
076b876e AM |
22971 | + q = str->a; |
22972 | + p = au_optstr(&perm, brperm); | |
22973 | + AuDebugOn(!p || !*p); | |
22974 | + sz = strlen(p); | |
22975 | + memcpy(q, p, sz + 1); | |
22976 | + q += sz; | |
1e00d052 | 22977 | + |
076b876e AM |
22978 | + sz = au_do_optstr_br_attr(&attr, perm); |
22979 | + if (sz) { | |
22980 | + *q++ = '+'; | |
22981 | + memcpy(q, attr.a, sz + 1); | |
1e00d052 AM |
22982 | + } |
22983 | + | |
076b876e | 22984 | + AuDebugOn(strlen(str->a) >= sizeof(str->a)); |
1facf9fc | 22985 | +} |
22986 | + | |
22987 | +/* ---------------------------------------------------------------------- */ | |
22988 | + | |
22989 | +static match_table_t udbalevel = { | |
22990 | + {AuOpt_UDBA_REVAL, "reval"}, | |
22991 | + {AuOpt_UDBA_NONE, "none"}, | |
4a4d8108 AM |
22992 | +#ifdef CONFIG_AUFS_HNOTIFY |
22993 | + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */ | |
22994 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
22995 | + {AuOpt_UDBA_HNOTIFY, "fsnotify"}, | |
4a4d8108 | 22996 | +#endif |
1facf9fc | 22997 | +#endif |
22998 | + {-1, NULL} | |
22999 | +}; | |
23000 | + | |
4a4d8108 | 23001 | +static int noinline_for_stack udba_val(char *str) |
1facf9fc | 23002 | +{ |
23003 | + substring_t args[MAX_OPT_ARGS]; | |
23004 | + | |
7f207e10 | 23005 | + return match_token(str, udbalevel, args); |
1facf9fc | 23006 | +} |
23007 | + | |
23008 | +const char *au_optstr_udba(int udba) | |
23009 | +{ | |
076b876e | 23010 | + return au_parser_pattern(udba, udbalevel); |
1facf9fc | 23011 | +} |
23012 | + | |
23013 | +/* ---------------------------------------------------------------------- */ | |
23014 | + | |
23015 | +static match_table_t au_wbr_create_policy = { | |
23016 | + {AuWbrCreate_TDP, "tdp"}, | |
23017 | + {AuWbrCreate_TDP, "top-down-parent"}, | |
23018 | + {AuWbrCreate_RR, "rr"}, | |
23019 | + {AuWbrCreate_RR, "round-robin"}, | |
23020 | + {AuWbrCreate_MFS, "mfs"}, | |
23021 | + {AuWbrCreate_MFS, "most-free-space"}, | |
23022 | + {AuWbrCreate_MFSV, "mfs:%d"}, | |
23023 | + {AuWbrCreate_MFSV, "most-free-space:%d"}, | |
23024 | + | |
23025 | + {AuWbrCreate_MFSRR, "mfsrr:%d"}, | |
23026 | + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"}, | |
23027 | + {AuWbrCreate_PMFS, "pmfs"}, | |
23028 | + {AuWbrCreate_PMFSV, "pmfs:%d"}, | |
392086de AM |
23029 | + {AuWbrCreate_PMFSRR, "pmfsrr:%d"}, |
23030 | + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"}, | |
1facf9fc | 23031 | + |
23032 | + {-1, NULL} | |
23033 | +}; | |
23034 | + | |
dece6358 AM |
23035 | +/* |
23036 | + * cf. linux/lib/parser.c and cmdline.c | |
23037 | + * gave up calling memparse() since it uses simple_strtoull() instead of | |
9dbd164d | 23038 | + * kstrto...(). |
dece6358 | 23039 | + */ |
4a4d8108 AM |
23040 | +static int noinline_for_stack |
23041 | +au_match_ull(substring_t *s, unsigned long long *result) | |
1facf9fc | 23042 | +{ |
23043 | + int err; | |
23044 | + unsigned int len; | |
23045 | + char a[32]; | |
23046 | + | |
23047 | + err = -ERANGE; | |
23048 | + len = s->to - s->from; | |
23049 | + if (len + 1 <= sizeof(a)) { | |
23050 | + memcpy(a, s->from, len); | |
23051 | + a[len] = '\0'; | |
9dbd164d | 23052 | + err = kstrtoull(a, 0, result); |
1facf9fc | 23053 | + } |
23054 | + return err; | |
23055 | +} | |
23056 | + | |
23057 | +static int au_wbr_mfs_wmark(substring_t *arg, char *str, | |
23058 | + struct au_opt_wbr_create *create) | |
23059 | +{ | |
23060 | + int err; | |
23061 | + unsigned long long ull; | |
23062 | + | |
23063 | + err = 0; | |
23064 | + if (!au_match_ull(arg, &ull)) | |
23065 | + create->mfsrr_watermark = ull; | |
23066 | + else { | |
4a4d8108 | 23067 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 23068 | + err = -EINVAL; |
23069 | + } | |
23070 | + | |
23071 | + return err; | |
23072 | +} | |
23073 | + | |
23074 | +static int au_wbr_mfs_sec(substring_t *arg, char *str, | |
23075 | + struct au_opt_wbr_create *create) | |
23076 | +{ | |
23077 | + int n, err; | |
23078 | + | |
23079 | + err = 0; | |
027c5e7a | 23080 | + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC) |
1facf9fc | 23081 | + create->mfs_second = n; |
23082 | + else { | |
4a4d8108 | 23083 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 23084 | + err = -EINVAL; |
23085 | + } | |
23086 | + | |
23087 | + return err; | |
23088 | +} | |
23089 | + | |
4a4d8108 AM |
23090 | +static int noinline_for_stack |
23091 | +au_wbr_create_val(char *str, struct au_opt_wbr_create *create) | |
1facf9fc | 23092 | +{ |
23093 | + int err, e; | |
23094 | + substring_t args[MAX_OPT_ARGS]; | |
23095 | + | |
23096 | + err = match_token(str, au_wbr_create_policy, args); | |
23097 | + create->wbr_create = err; | |
23098 | + switch (err) { | |
23099 | + case AuWbrCreate_MFSRRV: | |
392086de | 23100 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 23101 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
23102 | + if (!e) | |
23103 | + e = au_wbr_mfs_sec(&args[1], str, create); | |
23104 | + if (unlikely(e)) | |
23105 | + err = e; | |
23106 | + break; | |
23107 | + case AuWbrCreate_MFSRR: | |
392086de | 23108 | + case AuWbrCreate_PMFSRR: |
1facf9fc | 23109 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
23110 | + if (unlikely(e)) { | |
23111 | + err = e; | |
23112 | + break; | |
23113 | + } | |
23114 | + /*FALLTHROUGH*/ | |
23115 | + case AuWbrCreate_MFS: | |
23116 | + case AuWbrCreate_PMFS: | |
027c5e7a | 23117 | + create->mfs_second = AUFS_MFS_DEF_SEC; |
1facf9fc | 23118 | + break; |
23119 | + case AuWbrCreate_MFSV: | |
23120 | + case AuWbrCreate_PMFSV: | |
23121 | + e = au_wbr_mfs_sec(&args[0], str, create); | |
23122 | + if (unlikely(e)) | |
23123 | + err = e; | |
23124 | + break; | |
23125 | + } | |
23126 | + | |
23127 | + return err; | |
23128 | +} | |
23129 | + | |
23130 | +const char *au_optstr_wbr_create(int wbr_create) | |
23131 | +{ | |
076b876e | 23132 | + return au_parser_pattern(wbr_create, au_wbr_create_policy); |
1facf9fc | 23133 | +} |
23134 | + | |
23135 | +static match_table_t au_wbr_copyup_policy = { | |
23136 | + {AuWbrCopyup_TDP, "tdp"}, | |
23137 | + {AuWbrCopyup_TDP, "top-down-parent"}, | |
23138 | + {AuWbrCopyup_BUP, "bup"}, | |
23139 | + {AuWbrCopyup_BUP, "bottom-up-parent"}, | |
23140 | + {AuWbrCopyup_BU, "bu"}, | |
23141 | + {AuWbrCopyup_BU, "bottom-up"}, | |
23142 | + {-1, NULL} | |
23143 | +}; | |
23144 | + | |
4a4d8108 | 23145 | +static int noinline_for_stack au_wbr_copyup_val(char *str) |
1facf9fc | 23146 | +{ |
23147 | + substring_t args[MAX_OPT_ARGS]; | |
23148 | + | |
23149 | + return match_token(str, au_wbr_copyup_policy, args); | |
23150 | +} | |
23151 | + | |
23152 | +const char *au_optstr_wbr_copyup(int wbr_copyup) | |
23153 | +{ | |
076b876e | 23154 | + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy); |
1facf9fc | 23155 | +} |
23156 | + | |
23157 | +/* ---------------------------------------------------------------------- */ | |
23158 | + | |
23159 | +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY; | |
23160 | + | |
23161 | +static void dump_opts(struct au_opts *opts) | |
23162 | +{ | |
23163 | +#ifdef CONFIG_AUFS_DEBUG | |
23164 | + /* reduce stack space */ | |
23165 | + union { | |
23166 | + struct au_opt_add *add; | |
23167 | + struct au_opt_del *del; | |
23168 | + struct au_opt_mod *mod; | |
23169 | + struct au_opt_xino *xino; | |
23170 | + struct au_opt_xino_itrunc *xino_itrunc; | |
23171 | + struct au_opt_wbr_create *create; | |
23172 | + } u; | |
23173 | + struct au_opt *opt; | |
23174 | + | |
23175 | + opt = opts->opt; | |
23176 | + while (opt->type != Opt_tail) { | |
23177 | + switch (opt->type) { | |
23178 | + case Opt_add: | |
23179 | + u.add = &opt->add; | |
23180 | + AuDbg("add {b%d, %s, 0x%x, %p}\n", | |
23181 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23182 | + u.add->path.dentry); | |
23183 | + break; | |
23184 | + case Opt_del: | |
23185 | + case Opt_idel: | |
23186 | + u.del = &opt->del; | |
23187 | + AuDbg("del {%s, %p}\n", | |
23188 | + u.del->pathname, u.del->h_path.dentry); | |
23189 | + break; | |
23190 | + case Opt_mod: | |
23191 | + case Opt_imod: | |
23192 | + u.mod = &opt->mod; | |
23193 | + AuDbg("mod {%s, 0x%x, %p}\n", | |
23194 | + u.mod->path, u.mod->perm, u.mod->h_root); | |
23195 | + break; | |
23196 | + case Opt_append: | |
23197 | + u.add = &opt->add; | |
23198 | + AuDbg("append {b%d, %s, 0x%x, %p}\n", | |
23199 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23200 | + u.add->path.dentry); | |
23201 | + break; | |
23202 | + case Opt_prepend: | |
23203 | + u.add = &opt->add; | |
23204 | + AuDbg("prepend {b%d, %s, 0x%x, %p}\n", | |
23205 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23206 | + u.add->path.dentry); | |
23207 | + break; | |
23208 | + case Opt_dirwh: | |
23209 | + AuDbg("dirwh %d\n", opt->dirwh); | |
23210 | + break; | |
23211 | + case Opt_rdcache: | |
23212 | + AuDbg("rdcache %d\n", opt->rdcache); | |
23213 | + break; | |
23214 | + case Opt_rdblk: | |
23215 | + AuDbg("rdblk %u\n", opt->rdblk); | |
23216 | + break; | |
dece6358 AM |
23217 | + case Opt_rdblk_def: |
23218 | + AuDbg("rdblk_def\n"); | |
23219 | + break; | |
1facf9fc | 23220 | + case Opt_rdhash: |
23221 | + AuDbg("rdhash %u\n", opt->rdhash); | |
23222 | + break; | |
dece6358 AM |
23223 | + case Opt_rdhash_def: |
23224 | + AuDbg("rdhash_def\n"); | |
23225 | + break; | |
1facf9fc | 23226 | + case Opt_xino: |
23227 | + u.xino = &opt->xino; | |
523b37e3 | 23228 | + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file); |
1facf9fc | 23229 | + break; |
23230 | + case Opt_trunc_xino: | |
23231 | + AuLabel(trunc_xino); | |
23232 | + break; | |
23233 | + case Opt_notrunc_xino: | |
23234 | + AuLabel(notrunc_xino); | |
23235 | + break; | |
23236 | + case Opt_trunc_xino_path: | |
23237 | + case Opt_itrunc_xino: | |
23238 | + u.xino_itrunc = &opt->xino_itrunc; | |
23239 | + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex); | |
23240 | + break; | |
1facf9fc | 23241 | + case Opt_noxino: |
23242 | + AuLabel(noxino); | |
23243 | + break; | |
23244 | + case Opt_trunc_xib: | |
23245 | + AuLabel(trunc_xib); | |
23246 | + break; | |
23247 | + case Opt_notrunc_xib: | |
23248 | + AuLabel(notrunc_xib); | |
23249 | + break; | |
dece6358 AM |
23250 | + case Opt_shwh: |
23251 | + AuLabel(shwh); | |
23252 | + break; | |
23253 | + case Opt_noshwh: | |
23254 | + AuLabel(noshwh); | |
23255 | + break; | |
076b876e AM |
23256 | + case Opt_dirperm1: |
23257 | + AuLabel(dirperm1); | |
23258 | + break; | |
23259 | + case Opt_nodirperm1: | |
23260 | + AuLabel(nodirperm1); | |
23261 | + break; | |
1facf9fc | 23262 | + case Opt_plink: |
23263 | + AuLabel(plink); | |
23264 | + break; | |
23265 | + case Opt_noplink: | |
23266 | + AuLabel(noplink); | |
23267 | + break; | |
23268 | + case Opt_list_plink: | |
23269 | + AuLabel(list_plink); | |
23270 | + break; | |
23271 | + case Opt_udba: | |
23272 | + AuDbg("udba %d, %s\n", | |
23273 | + opt->udba, au_optstr_udba(opt->udba)); | |
23274 | + break; | |
4a4d8108 AM |
23275 | + case Opt_dio: |
23276 | + AuLabel(dio); | |
23277 | + break; | |
23278 | + case Opt_nodio: | |
23279 | + AuLabel(nodio); | |
23280 | + break; | |
1facf9fc | 23281 | + case Opt_diropq_a: |
23282 | + AuLabel(diropq_a); | |
23283 | + break; | |
23284 | + case Opt_diropq_w: | |
23285 | + AuLabel(diropq_w); | |
23286 | + break; | |
23287 | + case Opt_warn_perm: | |
23288 | + AuLabel(warn_perm); | |
23289 | + break; | |
23290 | + case Opt_nowarn_perm: | |
23291 | + AuLabel(nowarn_perm); | |
23292 | + break; | |
1facf9fc | 23293 | + case Opt_verbose: |
23294 | + AuLabel(verbose); | |
23295 | + break; | |
23296 | + case Opt_noverbose: | |
23297 | + AuLabel(noverbose); | |
23298 | + break; | |
23299 | + case Opt_sum: | |
23300 | + AuLabel(sum); | |
23301 | + break; | |
23302 | + case Opt_nosum: | |
23303 | + AuLabel(nosum); | |
23304 | + break; | |
23305 | + case Opt_wsum: | |
23306 | + AuLabel(wsum); | |
23307 | + break; | |
23308 | + case Opt_wbr_create: | |
23309 | + u.create = &opt->wbr_create; | |
23310 | + AuDbg("create %d, %s\n", u.create->wbr_create, | |
23311 | + au_optstr_wbr_create(u.create->wbr_create)); | |
23312 | + switch (u.create->wbr_create) { | |
23313 | + case AuWbrCreate_MFSV: | |
23314 | + case AuWbrCreate_PMFSV: | |
23315 | + AuDbg("%d sec\n", u.create->mfs_second); | |
23316 | + break; | |
23317 | + case AuWbrCreate_MFSRR: | |
23318 | + AuDbg("%llu watermark\n", | |
23319 | + u.create->mfsrr_watermark); | |
23320 | + break; | |
23321 | + case AuWbrCreate_MFSRRV: | |
392086de | 23322 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 23323 | + AuDbg("%llu watermark, %d sec\n", |
23324 | + u.create->mfsrr_watermark, | |
23325 | + u.create->mfs_second); | |
23326 | + break; | |
23327 | + } | |
23328 | + break; | |
23329 | + case Opt_wbr_copyup: | |
23330 | + AuDbg("copyup %d, %s\n", opt->wbr_copyup, | |
23331 | + au_optstr_wbr_copyup(opt->wbr_copyup)); | |
23332 | + break; | |
076b876e AM |
23333 | + case Opt_fhsm_sec: |
23334 | + AuDbg("fhsm_sec %u\n", opt->fhsm_second); | |
23335 | + break; | |
c1595e42 JR |
23336 | + case Opt_acl: |
23337 | + AuLabel(acl); | |
23338 | + break; | |
23339 | + case Opt_noacl: | |
23340 | + AuLabel(noacl); | |
23341 | + break; | |
1facf9fc | 23342 | + default: |
23343 | + BUG(); | |
23344 | + } | |
23345 | + opt++; | |
23346 | + } | |
23347 | +#endif | |
23348 | +} | |
23349 | + | |
23350 | +void au_opts_free(struct au_opts *opts) | |
23351 | +{ | |
23352 | + struct au_opt *opt; | |
23353 | + | |
23354 | + opt = opts->opt; | |
23355 | + while (opt->type != Opt_tail) { | |
23356 | + switch (opt->type) { | |
23357 | + case Opt_add: | |
23358 | + case Opt_append: | |
23359 | + case Opt_prepend: | |
23360 | + path_put(&opt->add.path); | |
23361 | + break; | |
23362 | + case Opt_del: | |
23363 | + case Opt_idel: | |
23364 | + path_put(&opt->del.h_path); | |
23365 | + break; | |
23366 | + case Opt_mod: | |
23367 | + case Opt_imod: | |
23368 | + dput(opt->mod.h_root); | |
23369 | + break; | |
23370 | + case Opt_xino: | |
23371 | + fput(opt->xino.file); | |
23372 | + break; | |
23373 | + } | |
23374 | + opt++; | |
23375 | + } | |
23376 | +} | |
23377 | + | |
23378 | +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags, | |
23379 | + aufs_bindex_t bindex) | |
23380 | +{ | |
23381 | + int err; | |
23382 | + struct au_opt_add *add = &opt->add; | |
23383 | + char *p; | |
23384 | + | |
23385 | + add->bindex = bindex; | |
1e00d052 | 23386 | + add->perm = AuBrPerm_RO; |
1facf9fc | 23387 | + add->pathname = opt_str; |
23388 | + p = strchr(opt_str, '='); | |
23389 | + if (p) { | |
23390 | + *p++ = 0; | |
23391 | + if (*p) | |
23392 | + add->perm = br_perm_val(p); | |
23393 | + } | |
23394 | + | |
23395 | + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path); | |
23396 | + if (!err) { | |
23397 | + if (!p) { | |
23398 | + add->perm = AuBrPerm_RO; | |
23399 | + if (au_test_fs_rr(add->path.dentry->d_sb)) | |
23400 | + add->perm = AuBrPerm_RR; | |
23401 | + else if (!bindex && !(sb_flags & MS_RDONLY)) | |
23402 | + add->perm = AuBrPerm_RW; | |
23403 | + } | |
23404 | + opt->type = Opt_add; | |
23405 | + goto out; | |
23406 | + } | |
4a4d8108 | 23407 | + pr_err("lookup failed %s (%d)\n", add->pathname, err); |
1facf9fc | 23408 | + err = -EINVAL; |
23409 | + | |
4f0767ce | 23410 | +out: |
1facf9fc | 23411 | + return err; |
23412 | +} | |
23413 | + | |
23414 | +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[]) | |
23415 | +{ | |
23416 | + int err; | |
23417 | + | |
23418 | + del->pathname = args[0].from; | |
23419 | + AuDbg("del path %s\n", del->pathname); | |
23420 | + | |
23421 | + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path); | |
23422 | + if (unlikely(err)) | |
4a4d8108 | 23423 | + pr_err("lookup failed %s (%d)\n", del->pathname, err); |
1facf9fc | 23424 | + |
23425 | + return err; | |
23426 | +} | |
23427 | + | |
23428 | +#if 0 /* reserved for future use */ | |
23429 | +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex, | |
23430 | + struct au_opt_del *del, substring_t args[]) | |
23431 | +{ | |
23432 | + int err; | |
23433 | + struct dentry *root; | |
23434 | + | |
23435 | + err = -EINVAL; | |
23436 | + root = sb->s_root; | |
23437 | + aufs_read_lock(root, AuLock_FLUSH); | |
23438 | + if (bindex < 0 || au_sbend(sb) < bindex) { | |
4a4d8108 | 23439 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 23440 | + goto out; |
23441 | + } | |
23442 | + | |
23443 | + err = 0; | |
23444 | + del->h_path.dentry = dget(au_h_dptr(root, bindex)); | |
23445 | + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex)); | |
23446 | + | |
4f0767ce | 23447 | +out: |
1facf9fc | 23448 | + aufs_read_unlock(root, !AuLock_IR); |
23449 | + return err; | |
23450 | +} | |
23451 | +#endif | |
23452 | + | |
4a4d8108 AM |
23453 | +static int noinline_for_stack |
23454 | +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[]) | |
1facf9fc | 23455 | +{ |
23456 | + int err; | |
23457 | + struct path path; | |
23458 | + char *p; | |
23459 | + | |
23460 | + err = -EINVAL; | |
23461 | + mod->path = args[0].from; | |
23462 | + p = strchr(mod->path, '='); | |
23463 | + if (unlikely(!p)) { | |
4a4d8108 | 23464 | + pr_err("no permssion %s\n", args[0].from); |
1facf9fc | 23465 | + goto out; |
23466 | + } | |
23467 | + | |
23468 | + *p++ = 0; | |
23469 | + err = vfsub_kern_path(mod->path, lkup_dirflags, &path); | |
23470 | + if (unlikely(err)) { | |
4a4d8108 | 23471 | + pr_err("lookup failed %s (%d)\n", mod->path, err); |
1facf9fc | 23472 | + goto out; |
23473 | + } | |
23474 | + | |
23475 | + mod->perm = br_perm_val(p); | |
23476 | + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p); | |
23477 | + mod->h_root = dget(path.dentry); | |
23478 | + path_put(&path); | |
23479 | + | |
4f0767ce | 23480 | +out: |
1facf9fc | 23481 | + return err; |
23482 | +} | |
23483 | + | |
23484 | +#if 0 /* reserved for future use */ | |
23485 | +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex, | |
23486 | + struct au_opt_mod *mod, substring_t args[]) | |
23487 | +{ | |
23488 | + int err; | |
23489 | + struct dentry *root; | |
23490 | + | |
23491 | + err = -EINVAL; | |
23492 | + root = sb->s_root; | |
23493 | + aufs_read_lock(root, AuLock_FLUSH); | |
23494 | + if (bindex < 0 || au_sbend(sb) < bindex) { | |
4a4d8108 | 23495 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 23496 | + goto out; |
23497 | + } | |
23498 | + | |
23499 | + err = 0; | |
23500 | + mod->perm = br_perm_val(args[1].from); | |
23501 | + AuDbg("mod path %s, perm 0x%x, %s\n", | |
23502 | + mod->path, mod->perm, args[1].from); | |
23503 | + mod->h_root = dget(au_h_dptr(root, bindex)); | |
23504 | + | |
4f0767ce | 23505 | +out: |
1facf9fc | 23506 | + aufs_read_unlock(root, !AuLock_IR); |
23507 | + return err; | |
23508 | +} | |
23509 | +#endif | |
23510 | + | |
23511 | +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino, | |
23512 | + substring_t args[]) | |
23513 | +{ | |
23514 | + int err; | |
23515 | + struct file *file; | |
23516 | + | |
23517 | + file = au_xino_create(sb, args[0].from, /*silent*/0); | |
23518 | + err = PTR_ERR(file); | |
23519 | + if (IS_ERR(file)) | |
23520 | + goto out; | |
23521 | + | |
23522 | + err = -EINVAL; | |
2000de60 | 23523 | + if (unlikely(file->f_path.dentry->d_sb == sb)) { |
1facf9fc | 23524 | + fput(file); |
4a4d8108 | 23525 | + pr_err("%s must be outside\n", args[0].from); |
1facf9fc | 23526 | + goto out; |
23527 | + } | |
23528 | + | |
23529 | + err = 0; | |
23530 | + xino->file = file; | |
23531 | + xino->path = args[0].from; | |
23532 | + | |
4f0767ce | 23533 | +out: |
1facf9fc | 23534 | + return err; |
23535 | +} | |
23536 | + | |
4a4d8108 AM |
23537 | +static int noinline_for_stack |
23538 | +au_opts_parse_xino_itrunc_path(struct super_block *sb, | |
23539 | + struct au_opt_xino_itrunc *xino_itrunc, | |
23540 | + substring_t args[]) | |
1facf9fc | 23541 | +{ |
23542 | + int err; | |
23543 | + aufs_bindex_t bend, bindex; | |
23544 | + struct path path; | |
23545 | + struct dentry *root; | |
23546 | + | |
23547 | + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path); | |
23548 | + if (unlikely(err)) { | |
4a4d8108 | 23549 | + pr_err("lookup failed %s (%d)\n", args[0].from, err); |
1facf9fc | 23550 | + goto out; |
23551 | + } | |
23552 | + | |
23553 | + xino_itrunc->bindex = -1; | |
23554 | + root = sb->s_root; | |
23555 | + aufs_read_lock(root, AuLock_FLUSH); | |
23556 | + bend = au_sbend(sb); | |
23557 | + for (bindex = 0; bindex <= bend; bindex++) { | |
23558 | + if (au_h_dptr(root, bindex) == path.dentry) { | |
23559 | + xino_itrunc->bindex = bindex; | |
23560 | + break; | |
23561 | + } | |
23562 | + } | |
23563 | + aufs_read_unlock(root, !AuLock_IR); | |
23564 | + path_put(&path); | |
23565 | + | |
23566 | + if (unlikely(xino_itrunc->bindex < 0)) { | |
4a4d8108 | 23567 | + pr_err("no such branch %s\n", args[0].from); |
1facf9fc | 23568 | + err = -EINVAL; |
23569 | + } | |
23570 | + | |
4f0767ce | 23571 | +out: |
1facf9fc | 23572 | + return err; |
23573 | +} | |
23574 | + | |
23575 | +/* called without aufs lock */ | |
23576 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts) | |
23577 | +{ | |
23578 | + int err, n, token; | |
23579 | + aufs_bindex_t bindex; | |
23580 | + unsigned char skipped; | |
23581 | + struct dentry *root; | |
23582 | + struct au_opt *opt, *opt_tail; | |
23583 | + char *opt_str; | |
23584 | + /* reduce the stack space */ | |
23585 | + union { | |
23586 | + struct au_opt_xino_itrunc *xino_itrunc; | |
23587 | + struct au_opt_wbr_create *create; | |
23588 | + } u; | |
23589 | + struct { | |
23590 | + substring_t args[MAX_OPT_ARGS]; | |
23591 | + } *a; | |
23592 | + | |
23593 | + err = -ENOMEM; | |
23594 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
23595 | + if (unlikely(!a)) | |
23596 | + goto out; | |
23597 | + | |
23598 | + root = sb->s_root; | |
23599 | + err = 0; | |
23600 | + bindex = 0; | |
23601 | + opt = opts->opt; | |
23602 | + opt_tail = opt + opts->max_opt - 1; | |
23603 | + opt->type = Opt_tail; | |
23604 | + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) { | |
23605 | + err = -EINVAL; | |
23606 | + skipped = 0; | |
23607 | + token = match_token(opt_str, options, a->args); | |
23608 | + switch (token) { | |
23609 | + case Opt_br: | |
23610 | + err = 0; | |
23611 | + while (!err && (opt_str = strsep(&a->args[0].from, ":")) | |
23612 | + && *opt_str) { | |
23613 | + err = opt_add(opt, opt_str, opts->sb_flags, | |
23614 | + bindex++); | |
23615 | + if (unlikely(!err && ++opt > opt_tail)) { | |
23616 | + err = -E2BIG; | |
23617 | + break; | |
23618 | + } | |
23619 | + opt->type = Opt_tail; | |
23620 | + skipped = 1; | |
23621 | + } | |
23622 | + break; | |
23623 | + case Opt_add: | |
23624 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23625 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23626 | + break; |
23627 | + } | |
23628 | + bindex = n; | |
23629 | + err = opt_add(opt, a->args[1].from, opts->sb_flags, | |
23630 | + bindex); | |
23631 | + if (!err) | |
23632 | + opt->type = token; | |
23633 | + break; | |
23634 | + case Opt_append: | |
23635 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
23636 | + /*dummy bindex*/1); | |
23637 | + if (!err) | |
23638 | + opt->type = token; | |
23639 | + break; | |
23640 | + case Opt_prepend: | |
23641 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
23642 | + /*bindex*/0); | |
23643 | + if (!err) | |
23644 | + opt->type = token; | |
23645 | + break; | |
23646 | + case Opt_del: | |
23647 | + err = au_opts_parse_del(&opt->del, a->args); | |
23648 | + if (!err) | |
23649 | + opt->type = token; | |
23650 | + break; | |
23651 | +#if 0 /* reserved for future use */ | |
23652 | + case Opt_idel: | |
23653 | + del->pathname = "(indexed)"; | |
23654 | + if (unlikely(match_int(&args[0], &n))) { | |
4a4d8108 | 23655 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23656 | + break; |
23657 | + } | |
23658 | + err = au_opts_parse_idel(sb, n, &opt->del, a->args); | |
23659 | + if (!err) | |
23660 | + opt->type = token; | |
23661 | + break; | |
23662 | +#endif | |
23663 | + case Opt_mod: | |
23664 | + err = au_opts_parse_mod(&opt->mod, a->args); | |
23665 | + if (!err) | |
23666 | + opt->type = token; | |
23667 | + break; | |
23668 | +#ifdef IMOD /* reserved for future use */ | |
23669 | + case Opt_imod: | |
23670 | + u.mod->path = "(indexed)"; | |
23671 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23672 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23673 | + break; |
23674 | + } | |
23675 | + err = au_opts_parse_imod(sb, n, &opt->mod, a->args); | |
23676 | + if (!err) | |
23677 | + opt->type = token; | |
23678 | + break; | |
23679 | +#endif | |
23680 | + case Opt_xino: | |
23681 | + err = au_opts_parse_xino(sb, &opt->xino, a->args); | |
23682 | + if (!err) | |
23683 | + opt->type = token; | |
23684 | + break; | |
23685 | + | |
23686 | + case Opt_trunc_xino_path: | |
23687 | + err = au_opts_parse_xino_itrunc_path | |
23688 | + (sb, &opt->xino_itrunc, a->args); | |
23689 | + if (!err) | |
23690 | + opt->type = token; | |
23691 | + break; | |
23692 | + | |
23693 | + case Opt_itrunc_xino: | |
23694 | + u.xino_itrunc = &opt->xino_itrunc; | |
23695 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23696 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23697 | + break; |
23698 | + } | |
23699 | + u.xino_itrunc->bindex = n; | |
23700 | + aufs_read_lock(root, AuLock_FLUSH); | |
23701 | + if (n < 0 || au_sbend(sb) < n) { | |
4a4d8108 | 23702 | + pr_err("out of bounds, %d\n", n); |
1facf9fc | 23703 | + aufs_read_unlock(root, !AuLock_IR); |
23704 | + break; | |
23705 | + } | |
23706 | + aufs_read_unlock(root, !AuLock_IR); | |
23707 | + err = 0; | |
23708 | + opt->type = token; | |
23709 | + break; | |
23710 | + | |
23711 | + case Opt_dirwh: | |
23712 | + if (unlikely(match_int(&a->args[0], &opt->dirwh))) | |
23713 | + break; | |
23714 | + err = 0; | |
23715 | + opt->type = token; | |
23716 | + break; | |
23717 | + | |
23718 | + case Opt_rdcache: | |
027c5e7a AM |
23719 | + if (unlikely(match_int(&a->args[0], &n))) { |
23720 | + pr_err("bad integer in %s\n", opt_str); | |
1facf9fc | 23721 | + break; |
027c5e7a AM |
23722 | + } |
23723 | + if (unlikely(n > AUFS_RDCACHE_MAX)) { | |
23724 | + pr_err("rdcache must be smaller than %d\n", | |
23725 | + AUFS_RDCACHE_MAX); | |
23726 | + break; | |
23727 | + } | |
23728 | + opt->rdcache = n; | |
1facf9fc | 23729 | + err = 0; |
23730 | + opt->type = token; | |
23731 | + break; | |
23732 | + case Opt_rdblk: | |
23733 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 23734 | + || n < 0 |
1facf9fc | 23735 | + || n > KMALLOC_MAX_SIZE)) { |
4a4d8108 | 23736 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23737 | + break; |
23738 | + } | |
1308ab2a | 23739 | + if (unlikely(n && n < NAME_MAX)) { |
4a4d8108 AM |
23740 | + pr_err("rdblk must be larger than %d\n", |
23741 | + NAME_MAX); | |
1facf9fc | 23742 | + break; |
23743 | + } | |
23744 | + opt->rdblk = n; | |
23745 | + err = 0; | |
23746 | + opt->type = token; | |
23747 | + break; | |
23748 | + case Opt_rdhash: | |
23749 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 23750 | + || n < 0 |
1facf9fc | 23751 | + || n * sizeof(struct hlist_head) |
23752 | + > KMALLOC_MAX_SIZE)) { | |
4a4d8108 | 23753 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23754 | + break; |
23755 | + } | |
23756 | + opt->rdhash = n; | |
23757 | + err = 0; | |
23758 | + opt->type = token; | |
23759 | + break; | |
23760 | + | |
23761 | + case Opt_trunc_xino: | |
23762 | + case Opt_notrunc_xino: | |
23763 | + case Opt_noxino: | |
23764 | + case Opt_trunc_xib: | |
23765 | + case Opt_notrunc_xib: | |
dece6358 AM |
23766 | + case Opt_shwh: |
23767 | + case Opt_noshwh: | |
076b876e AM |
23768 | + case Opt_dirperm1: |
23769 | + case Opt_nodirperm1: | |
1facf9fc | 23770 | + case Opt_plink: |
23771 | + case Opt_noplink: | |
23772 | + case Opt_list_plink: | |
4a4d8108 AM |
23773 | + case Opt_dio: |
23774 | + case Opt_nodio: | |
1facf9fc | 23775 | + case Opt_diropq_a: |
23776 | + case Opt_diropq_w: | |
23777 | + case Opt_warn_perm: | |
23778 | + case Opt_nowarn_perm: | |
1facf9fc | 23779 | + case Opt_verbose: |
23780 | + case Opt_noverbose: | |
23781 | + case Opt_sum: | |
23782 | + case Opt_nosum: | |
23783 | + case Opt_wsum: | |
dece6358 AM |
23784 | + case Opt_rdblk_def: |
23785 | + case Opt_rdhash_def: | |
c1595e42 JR |
23786 | + case Opt_acl: |
23787 | + case Opt_noacl: | |
1facf9fc | 23788 | + err = 0; |
23789 | + opt->type = token; | |
23790 | + break; | |
23791 | + | |
23792 | + case Opt_udba: | |
23793 | + opt->udba = udba_val(a->args[0].from); | |
23794 | + if (opt->udba >= 0) { | |
23795 | + err = 0; | |
23796 | + opt->type = token; | |
23797 | + } else | |
4a4d8108 | 23798 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23799 | + break; |
23800 | + | |
23801 | + case Opt_wbr_create: | |
23802 | + u.create = &opt->wbr_create; | |
23803 | + u.create->wbr_create | |
23804 | + = au_wbr_create_val(a->args[0].from, u.create); | |
23805 | + if (u.create->wbr_create >= 0) { | |
23806 | + err = 0; | |
23807 | + opt->type = token; | |
23808 | + } else | |
4a4d8108 | 23809 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23810 | + break; |
23811 | + case Opt_wbr_copyup: | |
23812 | + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from); | |
23813 | + if (opt->wbr_copyup >= 0) { | |
23814 | + err = 0; | |
23815 | + opt->type = token; | |
23816 | + } else | |
4a4d8108 | 23817 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23818 | + break; |
23819 | + | |
076b876e AM |
23820 | + case Opt_fhsm_sec: |
23821 | + if (unlikely(match_int(&a->args[0], &n) | |
23822 | + || n < 0)) { | |
23823 | + pr_err("bad integer in %s\n", opt_str); | |
23824 | + break; | |
23825 | + } | |
23826 | + if (sysaufs_brs) { | |
23827 | + opt->fhsm_second = n; | |
23828 | + opt->type = token; | |
23829 | + } else | |
23830 | + pr_warn("ignored %s\n", opt_str); | |
23831 | + err = 0; | |
23832 | + break; | |
23833 | + | |
1facf9fc | 23834 | + case Opt_ignore: |
0c3ec466 | 23835 | + pr_warn("ignored %s\n", opt_str); |
1facf9fc | 23836 | + /*FALLTHROUGH*/ |
23837 | + case Opt_ignore_silent: | |
23838 | + skipped = 1; | |
23839 | + err = 0; | |
23840 | + break; | |
23841 | + case Opt_err: | |
4a4d8108 | 23842 | + pr_err("unknown option %s\n", opt_str); |
1facf9fc | 23843 | + break; |
23844 | + } | |
23845 | + | |
23846 | + if (!err && !skipped) { | |
23847 | + if (unlikely(++opt > opt_tail)) { | |
23848 | + err = -E2BIG; | |
23849 | + opt--; | |
23850 | + opt->type = Opt_tail; | |
23851 | + break; | |
23852 | + } | |
23853 | + opt->type = Opt_tail; | |
23854 | + } | |
23855 | + } | |
23856 | + | |
23857 | + kfree(a); | |
23858 | + dump_opts(opts); | |
23859 | + if (unlikely(err)) | |
23860 | + au_opts_free(opts); | |
23861 | + | |
4f0767ce | 23862 | +out: |
1facf9fc | 23863 | + return err; |
23864 | +} | |
23865 | + | |
23866 | +static int au_opt_wbr_create(struct super_block *sb, | |
23867 | + struct au_opt_wbr_create *create) | |
23868 | +{ | |
23869 | + int err; | |
23870 | + struct au_sbinfo *sbinfo; | |
23871 | + | |
dece6358 AM |
23872 | + SiMustWriteLock(sb); |
23873 | + | |
1facf9fc | 23874 | + err = 1; /* handled */ |
23875 | + sbinfo = au_sbi(sb); | |
23876 | + if (sbinfo->si_wbr_create_ops->fin) { | |
23877 | + err = sbinfo->si_wbr_create_ops->fin(sb); | |
23878 | + if (!err) | |
23879 | + err = 1; | |
23880 | + } | |
23881 | + | |
23882 | + sbinfo->si_wbr_create = create->wbr_create; | |
23883 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create; | |
23884 | + switch (create->wbr_create) { | |
23885 | + case AuWbrCreate_MFSRRV: | |
23886 | + case AuWbrCreate_MFSRR: | |
392086de AM |
23887 | + case AuWbrCreate_PMFSRR: |
23888 | + case AuWbrCreate_PMFSRRV: | |
1facf9fc | 23889 | + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark; |
23890 | + /*FALLTHROUGH*/ | |
23891 | + case AuWbrCreate_MFS: | |
23892 | + case AuWbrCreate_MFSV: | |
23893 | + case AuWbrCreate_PMFS: | |
23894 | + case AuWbrCreate_PMFSV: | |
e49829fe JR |
23895 | + sbinfo->si_wbr_mfs.mfs_expire |
23896 | + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC); | |
1facf9fc | 23897 | + break; |
23898 | + } | |
23899 | + | |
23900 | + if (sbinfo->si_wbr_create_ops->init) | |
23901 | + sbinfo->si_wbr_create_ops->init(sb); /* ignore */ | |
23902 | + | |
23903 | + return err; | |
23904 | +} | |
23905 | + | |
23906 | +/* | |
23907 | + * returns, | |
23908 | + * plus: processed without an error | |
23909 | + * zero: unprocessed | |
23910 | + */ | |
23911 | +static int au_opt_simple(struct super_block *sb, struct au_opt *opt, | |
23912 | + struct au_opts *opts) | |
23913 | +{ | |
23914 | + int err; | |
23915 | + struct au_sbinfo *sbinfo; | |
23916 | + | |
dece6358 AM |
23917 | + SiMustWriteLock(sb); |
23918 | + | |
1facf9fc | 23919 | + err = 1; /* handled */ |
23920 | + sbinfo = au_sbi(sb); | |
23921 | + switch (opt->type) { | |
23922 | + case Opt_udba: | |
23923 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; | |
23924 | + sbinfo->si_mntflags |= opt->udba; | |
23925 | + opts->given_udba |= opt->udba; | |
23926 | + break; | |
23927 | + | |
23928 | + case Opt_plink: | |
23929 | + au_opt_set(sbinfo->si_mntflags, PLINK); | |
23930 | + break; | |
23931 | + case Opt_noplink: | |
23932 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
e49829fe | 23933 | + au_plink_put(sb, /*verbose*/1); |
1facf9fc | 23934 | + au_opt_clr(sbinfo->si_mntflags, PLINK); |
23935 | + break; | |
23936 | + case Opt_list_plink: | |
23937 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
23938 | + au_plink_list(sb); | |
23939 | + break; | |
23940 | + | |
4a4d8108 AM |
23941 | + case Opt_dio: |
23942 | + au_opt_set(sbinfo->si_mntflags, DIO); | |
23943 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
23944 | + break; | |
23945 | + case Opt_nodio: | |
23946 | + au_opt_clr(sbinfo->si_mntflags, DIO); | |
23947 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
23948 | + break; | |
23949 | + | |
076b876e AM |
23950 | + case Opt_fhsm_sec: |
23951 | + au_fhsm_set(sbinfo, opt->fhsm_second); | |
23952 | + break; | |
23953 | + | |
1facf9fc | 23954 | + case Opt_diropq_a: |
23955 | + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
23956 | + break; | |
23957 | + case Opt_diropq_w: | |
23958 | + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
23959 | + break; | |
23960 | + | |
23961 | + case Opt_warn_perm: | |
23962 | + au_opt_set(sbinfo->si_mntflags, WARN_PERM); | |
23963 | + break; | |
23964 | + case Opt_nowarn_perm: | |
23965 | + au_opt_clr(sbinfo->si_mntflags, WARN_PERM); | |
23966 | + break; | |
23967 | + | |
1facf9fc | 23968 | + case Opt_verbose: |
23969 | + au_opt_set(sbinfo->si_mntflags, VERBOSE); | |
23970 | + break; | |
23971 | + case Opt_noverbose: | |
23972 | + au_opt_clr(sbinfo->si_mntflags, VERBOSE); | |
23973 | + break; | |
23974 | + | |
23975 | + case Opt_sum: | |
23976 | + au_opt_set(sbinfo->si_mntflags, SUM); | |
23977 | + break; | |
23978 | + case Opt_wsum: | |
23979 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
23980 | + au_opt_set(sbinfo->si_mntflags, SUM_W); | |
23981 | + case Opt_nosum: | |
23982 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
23983 | + au_opt_clr(sbinfo->si_mntflags, SUM_W); | |
23984 | + break; | |
23985 | + | |
23986 | + case Opt_wbr_create: | |
23987 | + err = au_opt_wbr_create(sb, &opt->wbr_create); | |
23988 | + break; | |
23989 | + case Opt_wbr_copyup: | |
23990 | + sbinfo->si_wbr_copyup = opt->wbr_copyup; | |
23991 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup; | |
23992 | + break; | |
23993 | + | |
23994 | + case Opt_dirwh: | |
23995 | + sbinfo->si_dirwh = opt->dirwh; | |
23996 | + break; | |
23997 | + | |
23998 | + case Opt_rdcache: | |
e49829fe JR |
23999 | + sbinfo->si_rdcache |
24000 | + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC); | |
1facf9fc | 24001 | + break; |
24002 | + case Opt_rdblk: | |
24003 | + sbinfo->si_rdblk = opt->rdblk; | |
24004 | + break; | |
dece6358 AM |
24005 | + case Opt_rdblk_def: |
24006 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; | |
24007 | + break; | |
1facf9fc | 24008 | + case Opt_rdhash: |
24009 | + sbinfo->si_rdhash = opt->rdhash; | |
24010 | + break; | |
dece6358 AM |
24011 | + case Opt_rdhash_def: |
24012 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
24013 | + break; | |
24014 | + | |
24015 | + case Opt_shwh: | |
24016 | + au_opt_set(sbinfo->si_mntflags, SHWH); | |
24017 | + break; | |
24018 | + case Opt_noshwh: | |
24019 | + au_opt_clr(sbinfo->si_mntflags, SHWH); | |
24020 | + break; | |
1facf9fc | 24021 | + |
076b876e AM |
24022 | + case Opt_dirperm1: |
24023 | + au_opt_set(sbinfo->si_mntflags, DIRPERM1); | |
24024 | + break; | |
24025 | + case Opt_nodirperm1: | |
24026 | + au_opt_clr(sbinfo->si_mntflags, DIRPERM1); | |
24027 | + break; | |
24028 | + | |
1facf9fc | 24029 | + case Opt_trunc_xino: |
24030 | + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO); | |
24031 | + break; | |
24032 | + case Opt_notrunc_xino: | |
24033 | + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO); | |
24034 | + break; | |
24035 | + | |
24036 | + case Opt_trunc_xino_path: | |
24037 | + case Opt_itrunc_xino: | |
24038 | + err = au_xino_trunc(sb, opt->xino_itrunc.bindex); | |
24039 | + if (!err) | |
24040 | + err = 1; | |
24041 | + break; | |
24042 | + | |
24043 | + case Opt_trunc_xib: | |
24044 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
24045 | + break; | |
24046 | + case Opt_notrunc_xib: | |
24047 | + au_fclr_opts(opts->flags, TRUNC_XIB); | |
24048 | + break; | |
24049 | + | |
c1595e42 JR |
24050 | + case Opt_acl: |
24051 | + sb->s_flags |= MS_POSIXACL; | |
24052 | + break; | |
24053 | + case Opt_noacl: | |
24054 | + sb->s_flags &= ~MS_POSIXACL; | |
24055 | + break; | |
24056 | + | |
1facf9fc | 24057 | + default: |
24058 | + err = 0; | |
24059 | + break; | |
24060 | + } | |
24061 | + | |
24062 | + return err; | |
24063 | +} | |
24064 | + | |
24065 | +/* | |
24066 | + * returns tri-state. | |
24067 | + * plus: processed without an error | |
24068 | + * zero: unprocessed | |
24069 | + * minus: error | |
24070 | + */ | |
24071 | +static int au_opt_br(struct super_block *sb, struct au_opt *opt, | |
24072 | + struct au_opts *opts) | |
24073 | +{ | |
24074 | + int err, do_refresh; | |
24075 | + | |
24076 | + err = 0; | |
24077 | + switch (opt->type) { | |
24078 | + case Opt_append: | |
24079 | + opt->add.bindex = au_sbend(sb) + 1; | |
24080 | + if (opt->add.bindex < 0) | |
24081 | + opt->add.bindex = 0; | |
24082 | + goto add; | |
24083 | + case Opt_prepend: | |
24084 | + opt->add.bindex = 0; | |
f6b6e03d | 24085 | + add: /* indented label */ |
1facf9fc | 24086 | + case Opt_add: |
24087 | + err = au_br_add(sb, &opt->add, | |
24088 | + au_ftest_opts(opts->flags, REMOUNT)); | |
24089 | + if (!err) { | |
24090 | + err = 1; | |
027c5e7a | 24091 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24092 | + } |
24093 | + break; | |
24094 | + | |
24095 | + case Opt_del: | |
24096 | + case Opt_idel: | |
24097 | + err = au_br_del(sb, &opt->del, | |
24098 | + au_ftest_opts(opts->flags, REMOUNT)); | |
24099 | + if (!err) { | |
24100 | + err = 1; | |
24101 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
027c5e7a | 24102 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24103 | + } |
24104 | + break; | |
24105 | + | |
24106 | + case Opt_mod: | |
24107 | + case Opt_imod: | |
24108 | + err = au_br_mod(sb, &opt->mod, | |
24109 | + au_ftest_opts(opts->flags, REMOUNT), | |
24110 | + &do_refresh); | |
24111 | + if (!err) { | |
24112 | + err = 1; | |
027c5e7a AM |
24113 | + if (do_refresh) |
24114 | + au_fset_opts(opts->flags, REFRESH); | |
1facf9fc | 24115 | + } |
24116 | + break; | |
24117 | + } | |
24118 | + | |
24119 | + return err; | |
24120 | +} | |
24121 | + | |
24122 | +static int au_opt_xino(struct super_block *sb, struct au_opt *opt, | |
24123 | + struct au_opt_xino **opt_xino, | |
24124 | + struct au_opts *opts) | |
24125 | +{ | |
24126 | + int err; | |
24127 | + aufs_bindex_t bend, bindex; | |
24128 | + struct dentry *root, *parent, *h_root; | |
24129 | + | |
24130 | + err = 0; | |
24131 | + switch (opt->type) { | |
24132 | + case Opt_xino: | |
24133 | + err = au_xino_set(sb, &opt->xino, | |
24134 | + !!au_ftest_opts(opts->flags, REMOUNT)); | |
24135 | + if (unlikely(err)) | |
24136 | + break; | |
24137 | + | |
24138 | + *opt_xino = &opt->xino; | |
24139 | + au_xino_brid_set(sb, -1); | |
24140 | + | |
24141 | + /* safe d_parent access */ | |
2000de60 | 24142 | + parent = opt->xino.file->f_path.dentry->d_parent; |
1facf9fc | 24143 | + root = sb->s_root; |
24144 | + bend = au_sbend(sb); | |
24145 | + for (bindex = 0; bindex <= bend; bindex++) { | |
24146 | + h_root = au_h_dptr(root, bindex); | |
24147 | + if (h_root == parent) { | |
24148 | + au_xino_brid_set(sb, au_sbr_id(sb, bindex)); | |
24149 | + break; | |
24150 | + } | |
24151 | + } | |
24152 | + break; | |
24153 | + | |
24154 | + case Opt_noxino: | |
24155 | + au_xino_clr(sb); | |
24156 | + au_xino_brid_set(sb, -1); | |
24157 | + *opt_xino = (void *)-1; | |
24158 | + break; | |
24159 | + } | |
24160 | + | |
24161 | + return err; | |
24162 | +} | |
24163 | + | |
24164 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
24165 | + unsigned int pending) | |
24166 | +{ | |
076b876e | 24167 | + int err, fhsm; |
1facf9fc | 24168 | + aufs_bindex_t bindex, bend; |
24169 | + unsigned char do_plink, skip, do_free; | |
24170 | + struct au_branch *br; | |
24171 | + struct au_wbr *wbr; | |
24172 | + struct dentry *root; | |
24173 | + struct inode *dir, *h_dir; | |
24174 | + struct au_sbinfo *sbinfo; | |
24175 | + struct au_hinode *hdir; | |
24176 | + | |
dece6358 AM |
24177 | + SiMustAnyLock(sb); |
24178 | + | |
1facf9fc | 24179 | + sbinfo = au_sbi(sb); |
24180 | + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA)); | |
24181 | + | |
dece6358 AM |
24182 | + if (!(sb_flags & MS_RDONLY)) { |
24183 | + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0)))) | |
0c3ec466 | 24184 | + pr_warn("first branch should be rw\n"); |
dece6358 | 24185 | + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH))) |
0c3ec466 | 24186 | + pr_warn("shwh should be used with ro\n"); |
dece6358 | 24187 | + } |
1facf9fc | 24188 | + |
4a4d8108 | 24189 | + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY) |
1facf9fc | 24190 | + && !au_opt_test(sbinfo->si_mntflags, XINO)) |
0c3ec466 | 24191 | + pr_warn("udba=*notify requires xino\n"); |
1facf9fc | 24192 | + |
076b876e AM |
24193 | + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1)) |
24194 | + pr_warn("dirperm1 breaks the protection" | |
24195 | + " by the permission bits on the lower branch\n"); | |
24196 | + | |
1facf9fc | 24197 | + err = 0; |
076b876e | 24198 | + fhsm = 0; |
1facf9fc | 24199 | + root = sb->s_root; |
5527c038 | 24200 | + dir = d_inode(root); |
1facf9fc | 24201 | + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK); |
24202 | + bend = au_sbend(sb); | |
24203 | + for (bindex = 0; !err && bindex <= bend; bindex++) { | |
24204 | + skip = 0; | |
24205 | + h_dir = au_h_iptr(dir, bindex); | |
24206 | + br = au_sbr(sb, bindex); | |
1facf9fc | 24207 | + |
c1595e42 JR |
24208 | + if ((br->br_perm & AuBrAttr_ICEX) |
24209 | + && !h_dir->i_op->listxattr) | |
24210 | + br->br_perm &= ~AuBrAttr_ICEX; | |
24211 | +#if 0 | |
24212 | + if ((br->br_perm & AuBrAttr_ICEX_SEC) | |
24213 | + && (au_br_sb(br)->s_flags & MS_NOSEC)) | |
24214 | + br->br_perm &= ~AuBrAttr_ICEX_SEC; | |
24215 | +#endif | |
24216 | + | |
24217 | + do_free = 0; | |
1facf9fc | 24218 | + wbr = br->br_wbr; |
24219 | + if (wbr) | |
24220 | + wbr_wh_read_lock(wbr); | |
24221 | + | |
1e00d052 | 24222 | + if (!au_br_writable(br->br_perm)) { |
1facf9fc | 24223 | + do_free = !!wbr; |
24224 | + skip = (!wbr | |
24225 | + || (!wbr->wbr_whbase | |
24226 | + && !wbr->wbr_plink | |
24227 | + && !wbr->wbr_orph)); | |
1e00d052 | 24228 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 24229 | + /* skip = (!br->br_whbase && !br->br_orph); */ |
24230 | + skip = (!wbr || !wbr->wbr_whbase); | |
24231 | + if (skip && wbr) { | |
24232 | + if (do_plink) | |
24233 | + skip = !!wbr->wbr_plink; | |
24234 | + else | |
24235 | + skip = !wbr->wbr_plink; | |
24236 | + } | |
1e00d052 | 24237 | + } else { |
1facf9fc | 24238 | + /* skip = (br->br_whbase && br->br_ohph); */ |
24239 | + skip = (wbr && wbr->wbr_whbase); | |
24240 | + if (skip) { | |
24241 | + if (do_plink) | |
24242 | + skip = !!wbr->wbr_plink; | |
24243 | + else | |
24244 | + skip = !wbr->wbr_plink; | |
24245 | + } | |
1facf9fc | 24246 | + } |
24247 | + if (wbr) | |
24248 | + wbr_wh_read_unlock(wbr); | |
24249 | + | |
076b876e AM |
24250 | + if (au_br_fhsm(br->br_perm)) { |
24251 | + fhsm++; | |
24252 | + AuDebugOn(!br->br_fhsm); | |
24253 | + } | |
24254 | + | |
1facf9fc | 24255 | + if (skip) |
24256 | + continue; | |
24257 | + | |
24258 | + hdir = au_hi(dir, bindex); | |
4a4d8108 | 24259 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 24260 | + if (wbr) |
24261 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 24262 | + err = au_wh_init(br, sb); |
1facf9fc | 24263 | + if (wbr) |
24264 | + wbr_wh_write_unlock(wbr); | |
4a4d8108 | 24265 | + au_hn_imtx_unlock(hdir); |
1facf9fc | 24266 | + |
24267 | + if (!err && do_free) { | |
24268 | + kfree(wbr); | |
24269 | + br->br_wbr = NULL; | |
24270 | + } | |
24271 | + } | |
24272 | + | |
c1595e42 | 24273 | + if (fhsm >= 2) { |
076b876e | 24274 | + au_fset_si(sbinfo, FHSM); |
c1595e42 JR |
24275 | + for (bindex = bend; bindex >= 0; bindex--) { |
24276 | + br = au_sbr(sb, bindex); | |
24277 | + if (au_br_fhsm(br->br_perm)) { | |
24278 | + au_fhsm_set_bottom(sb, bindex); | |
24279 | + break; | |
24280 | + } | |
24281 | + } | |
24282 | + } else { | |
076b876e | 24283 | + au_fclr_si(sbinfo, FHSM); |
c1595e42 JR |
24284 | + au_fhsm_set_bottom(sb, -1); |
24285 | + } | |
076b876e | 24286 | + |
1facf9fc | 24287 | + return err; |
24288 | +} | |
24289 | + | |
24290 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts) | |
24291 | +{ | |
24292 | + int err; | |
24293 | + unsigned int tmp; | |
027c5e7a | 24294 | + aufs_bindex_t bindex, bend; |
1facf9fc | 24295 | + struct au_opt *opt; |
24296 | + struct au_opt_xino *opt_xino, xino; | |
24297 | + struct au_sbinfo *sbinfo; | |
027c5e7a | 24298 | + struct au_branch *br; |
076b876e | 24299 | + struct inode *dir; |
1facf9fc | 24300 | + |
dece6358 AM |
24301 | + SiMustWriteLock(sb); |
24302 | + | |
1facf9fc | 24303 | + err = 0; |
24304 | + opt_xino = NULL; | |
24305 | + opt = opts->opt; | |
24306 | + while (err >= 0 && opt->type != Opt_tail) | |
24307 | + err = au_opt_simple(sb, opt++, opts); | |
24308 | + if (err > 0) | |
24309 | + err = 0; | |
24310 | + else if (unlikely(err < 0)) | |
24311 | + goto out; | |
24312 | + | |
24313 | + /* disable xino and udba temporary */ | |
24314 | + sbinfo = au_sbi(sb); | |
24315 | + tmp = sbinfo->si_mntflags; | |
24316 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
24317 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL); | |
24318 | + | |
24319 | + opt = opts->opt; | |
24320 | + while (err >= 0 && opt->type != Opt_tail) | |
24321 | + err = au_opt_br(sb, opt++, opts); | |
24322 | + if (err > 0) | |
24323 | + err = 0; | |
24324 | + else if (unlikely(err < 0)) | |
24325 | + goto out; | |
24326 | + | |
24327 | + bend = au_sbend(sb); | |
24328 | + if (unlikely(bend < 0)) { | |
24329 | + err = -EINVAL; | |
4a4d8108 | 24330 | + pr_err("no branches\n"); |
1facf9fc | 24331 | + goto out; |
24332 | + } | |
24333 | + | |
24334 | + if (au_opt_test(tmp, XINO)) | |
24335 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
24336 | + opt = opts->opt; | |
24337 | + while (!err && opt->type != Opt_tail) | |
24338 | + err = au_opt_xino(sb, opt++, &opt_xino, opts); | |
24339 | + if (unlikely(err)) | |
24340 | + goto out; | |
24341 | + | |
24342 | + err = au_opts_verify(sb, sb->s_flags, tmp); | |
24343 | + if (unlikely(err)) | |
24344 | + goto out; | |
24345 | + | |
24346 | + /* restore xino */ | |
24347 | + if (au_opt_test(tmp, XINO) && !opt_xino) { | |
24348 | + xino.file = au_xino_def(sb); | |
24349 | + err = PTR_ERR(xino.file); | |
24350 | + if (IS_ERR(xino.file)) | |
24351 | + goto out; | |
24352 | + | |
24353 | + err = au_xino_set(sb, &xino, /*remount*/0); | |
24354 | + fput(xino.file); | |
24355 | + if (unlikely(err)) | |
24356 | + goto out; | |
24357 | + } | |
24358 | + | |
24359 | + /* restore udba */ | |
027c5e7a | 24360 | + tmp &= AuOptMask_UDBA; |
1facf9fc | 24361 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; |
027c5e7a AM |
24362 | + sbinfo->si_mntflags |= tmp; |
24363 | + bend = au_sbend(sb); | |
24364 | + for (bindex = 0; bindex <= bend; bindex++) { | |
24365 | + br = au_sbr(sb, bindex); | |
24366 | + err = au_hnotify_reset_br(tmp, br, br->br_perm); | |
24367 | + if (unlikely(err)) | |
24368 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", | |
24369 | + bindex, err); | |
24370 | + /* go on even if err */ | |
24371 | + } | |
4a4d8108 | 24372 | + if (au_opt_test(tmp, UDBA_HNOTIFY)) { |
5527c038 | 24373 | + dir = d_inode(sb->s_root); |
4a4d8108 | 24374 | + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO); |
1facf9fc | 24375 | + } |
24376 | + | |
4f0767ce | 24377 | +out: |
1facf9fc | 24378 | + return err; |
24379 | +} | |
24380 | + | |
24381 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts) | |
24382 | +{ | |
24383 | + int err, rerr; | |
24384 | + struct inode *dir; | |
24385 | + struct au_opt_xino *opt_xino; | |
24386 | + struct au_opt *opt; | |
24387 | + struct au_sbinfo *sbinfo; | |
24388 | + | |
dece6358 AM |
24389 | + SiMustWriteLock(sb); |
24390 | + | |
5527c038 | 24391 | + dir = d_inode(sb->s_root); |
1facf9fc | 24392 | + sbinfo = au_sbi(sb); |
24393 | + err = 0; | |
24394 | + opt_xino = NULL; | |
24395 | + opt = opts->opt; | |
24396 | + while (err >= 0 && opt->type != Opt_tail) { | |
24397 | + err = au_opt_simple(sb, opt, opts); | |
24398 | + if (!err) | |
24399 | + err = au_opt_br(sb, opt, opts); | |
24400 | + if (!err) | |
24401 | + err = au_opt_xino(sb, opt, &opt_xino, opts); | |
24402 | + opt++; | |
24403 | + } | |
24404 | + if (err > 0) | |
24405 | + err = 0; | |
24406 | + AuTraceErr(err); | |
24407 | + /* go on even err */ | |
24408 | + | |
24409 | + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0); | |
24410 | + if (unlikely(rerr && !err)) | |
24411 | + err = rerr; | |
24412 | + | |
24413 | + if (au_ftest_opts(opts->flags, TRUNC_XIB)) { | |
24414 | + rerr = au_xib_trunc(sb); | |
24415 | + if (unlikely(rerr && !err)) | |
24416 | + err = rerr; | |
24417 | + } | |
24418 | + | |
24419 | + /* will be handled by the caller */ | |
027c5e7a | 24420 | + if (!au_ftest_opts(opts->flags, REFRESH) |
1facf9fc | 24421 | + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO))) |
027c5e7a | 24422 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24423 | + |
24424 | + AuDbg("status 0x%x\n", opts->flags); | |
24425 | + return err; | |
24426 | +} | |
24427 | + | |
24428 | +/* ---------------------------------------------------------------------- */ | |
24429 | + | |
24430 | +unsigned int au_opt_udba(struct super_block *sb) | |
24431 | +{ | |
24432 | + return au_mntflags(sb) & AuOptMask_UDBA; | |
24433 | +} | |
7f207e10 AM |
24434 | diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h |
24435 | --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
24436 | +++ linux/fs/aufs/opts.h 2015-06-28 17:35:44.351383872 +0200 |
24437 | @@ -0,0 +1,210 @@ | |
1facf9fc | 24438 | +/* |
2000de60 | 24439 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 24440 | + * |
24441 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24442 | + * it under the terms of the GNU General Public License as published by | |
24443 | + * the Free Software Foundation; either version 2 of the License, or | |
24444 | + * (at your option) any later version. | |
dece6358 AM |
24445 | + * |
24446 | + * This program is distributed in the hope that it will be useful, | |
24447 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24448 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24449 | + * GNU General Public License for more details. | |
24450 | + * | |
24451 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24452 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24453 | + */ |
24454 | + | |
24455 | +/* | |
24456 | + * mount options/flags | |
24457 | + */ | |
24458 | + | |
24459 | +#ifndef __AUFS_OPTS_H__ | |
24460 | +#define __AUFS_OPTS_H__ | |
24461 | + | |
24462 | +#ifdef __KERNEL__ | |
24463 | + | |
dece6358 | 24464 | +#include <linux/path.h> |
1facf9fc | 24465 | + |
dece6358 AM |
24466 | +struct file; |
24467 | +struct super_block; | |
24468 | + | |
1facf9fc | 24469 | +/* ---------------------------------------------------------------------- */ |
24470 | + | |
24471 | +/* mount flags */ | |
24472 | +#define AuOpt_XINO 1 /* external inode number bitmap | |
24473 | + and translation table */ | |
24474 | +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */ | |
24475 | +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */ | |
24476 | +#define AuOpt_UDBA_REVAL (1 << 3) | |
4a4d8108 | 24477 | +#define AuOpt_UDBA_HNOTIFY (1 << 4) |
dece6358 AM |
24478 | +#define AuOpt_SHWH (1 << 5) /* show whiteout */ |
24479 | +#define AuOpt_PLINK (1 << 6) /* pseudo-link */ | |
076b876e AM |
24480 | +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm |
24481 | + bits */ | |
dece6358 AM |
24482 | +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */ |
24483 | +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */ | |
24484 | +#define AuOpt_SUM_W (1 << 11) /* unimplemented */ | |
24485 | +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */ | |
24486 | +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */ | |
4a4d8108 | 24487 | +#define AuOpt_DIO (1 << 14) /* direct io */ |
1facf9fc | 24488 | + |
4a4d8108 AM |
24489 | +#ifndef CONFIG_AUFS_HNOTIFY |
24490 | +#undef AuOpt_UDBA_HNOTIFY | |
24491 | +#define AuOpt_UDBA_HNOTIFY 0 | |
1facf9fc | 24492 | +#endif |
dece6358 AM |
24493 | +#ifndef CONFIG_AUFS_SHWH |
24494 | +#undef AuOpt_SHWH | |
24495 | +#define AuOpt_SHWH 0 | |
24496 | +#endif | |
1facf9fc | 24497 | + |
24498 | +#define AuOpt_Def (AuOpt_XINO \ | |
24499 | + | AuOpt_UDBA_REVAL \ | |
24500 | + | AuOpt_PLINK \ | |
24501 | + /* | AuOpt_DIRPERM1 */ \ | |
24502 | + | AuOpt_WARN_PERM) | |
24503 | +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \ | |
24504 | + | AuOpt_UDBA_REVAL \ | |
4a4d8108 | 24505 | + | AuOpt_UDBA_HNOTIFY) |
1facf9fc | 24506 | + |
24507 | +#define au_opt_test(flags, name) (flags & AuOpt_##name) | |
24508 | +#define au_opt_set(flags, name) do { \ | |
24509 | + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \ | |
24510 | + ((flags) |= AuOpt_##name); \ | |
24511 | +} while (0) | |
24512 | +#define au_opt_set_udba(flags, name) do { \ | |
24513 | + (flags) &= ~AuOptMask_UDBA; \ | |
24514 | + ((flags) |= AuOpt_##name); \ | |
24515 | +} while (0) | |
7f207e10 AM |
24516 | +#define au_opt_clr(flags, name) do { \ |
24517 | + ((flags) &= ~AuOpt_##name); \ | |
24518 | +} while (0) | |
1facf9fc | 24519 | + |
e49829fe JR |
24520 | +static inline unsigned int au_opts_plink(unsigned int mntflags) |
24521 | +{ | |
24522 | +#ifdef CONFIG_PROC_FS | |
24523 | + return mntflags; | |
24524 | +#else | |
24525 | + return mntflags & ~AuOpt_PLINK; | |
24526 | +#endif | |
24527 | +} | |
24528 | + | |
1facf9fc | 24529 | +/* ---------------------------------------------------------------------- */ |
24530 | + | |
24531 | +/* policies to select one among multiple writable branches */ | |
24532 | +enum { | |
24533 | + AuWbrCreate_TDP, /* top down parent */ | |
24534 | + AuWbrCreate_RR, /* round robin */ | |
24535 | + AuWbrCreate_MFS, /* most free space */ | |
24536 | + AuWbrCreate_MFSV, /* mfs with seconds */ | |
24537 | + AuWbrCreate_MFSRR, /* mfs then rr */ | |
24538 | + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */ | |
24539 | + AuWbrCreate_PMFS, /* parent and mfs */ | |
24540 | + AuWbrCreate_PMFSV, /* parent and mfs with seconds */ | |
392086de AM |
24541 | + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */ |
24542 | + AuWbrCreate_PMFSRRV, /* plus seconds */ | |
1facf9fc | 24543 | + |
24544 | + AuWbrCreate_Def = AuWbrCreate_TDP | |
24545 | +}; | |
24546 | + | |
24547 | +enum { | |
24548 | + AuWbrCopyup_TDP, /* top down parent */ | |
24549 | + AuWbrCopyup_BUP, /* bottom up parent */ | |
24550 | + AuWbrCopyup_BU, /* bottom up */ | |
24551 | + | |
24552 | + AuWbrCopyup_Def = AuWbrCopyup_TDP | |
24553 | +}; | |
24554 | + | |
24555 | +/* ---------------------------------------------------------------------- */ | |
24556 | + | |
24557 | +struct au_opt_add { | |
24558 | + aufs_bindex_t bindex; | |
24559 | + char *pathname; | |
24560 | + int perm; | |
24561 | + struct path path; | |
24562 | +}; | |
24563 | + | |
24564 | +struct au_opt_del { | |
24565 | + char *pathname; | |
24566 | + struct path h_path; | |
24567 | +}; | |
24568 | + | |
24569 | +struct au_opt_mod { | |
24570 | + char *path; | |
24571 | + int perm; | |
24572 | + struct dentry *h_root; | |
24573 | +}; | |
24574 | + | |
24575 | +struct au_opt_xino { | |
24576 | + char *path; | |
24577 | + struct file *file; | |
24578 | +}; | |
24579 | + | |
24580 | +struct au_opt_xino_itrunc { | |
24581 | + aufs_bindex_t bindex; | |
24582 | +}; | |
24583 | + | |
24584 | +struct au_opt_wbr_create { | |
24585 | + int wbr_create; | |
24586 | + int mfs_second; | |
24587 | + unsigned long long mfsrr_watermark; | |
24588 | +}; | |
24589 | + | |
24590 | +struct au_opt { | |
24591 | + int type; | |
24592 | + union { | |
24593 | + struct au_opt_xino xino; | |
24594 | + struct au_opt_xino_itrunc xino_itrunc; | |
24595 | + struct au_opt_add add; | |
24596 | + struct au_opt_del del; | |
24597 | + struct au_opt_mod mod; | |
24598 | + int dirwh; | |
24599 | + int rdcache; | |
24600 | + unsigned int rdblk; | |
24601 | + unsigned int rdhash; | |
24602 | + int udba; | |
24603 | + struct au_opt_wbr_create wbr_create; | |
24604 | + int wbr_copyup; | |
076b876e | 24605 | + unsigned int fhsm_second; |
1facf9fc | 24606 | + }; |
24607 | +}; | |
24608 | + | |
24609 | +/* opts flags */ | |
24610 | +#define AuOpts_REMOUNT 1 | |
027c5e7a AM |
24611 | +#define AuOpts_REFRESH (1 << 1) |
24612 | +#define AuOpts_TRUNC_XIB (1 << 2) | |
24613 | +#define AuOpts_REFRESH_DYAOP (1 << 3) | |
1facf9fc | 24614 | +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name) |
7f207e10 AM |
24615 | +#define au_fset_opts(flags, name) \ |
24616 | + do { (flags) |= AuOpts_##name; } while (0) | |
24617 | +#define au_fclr_opts(flags, name) \ | |
24618 | + do { (flags) &= ~AuOpts_##name; } while (0) | |
1facf9fc | 24619 | + |
24620 | +struct au_opts { | |
24621 | + struct au_opt *opt; | |
24622 | + int max_opt; | |
24623 | + | |
24624 | + unsigned int given_udba; | |
24625 | + unsigned int flags; | |
24626 | + unsigned long sb_flags; | |
24627 | +}; | |
24628 | + | |
24629 | +/* ---------------------------------------------------------------------- */ | |
24630 | + | |
7e9cd9fe | 24631 | +/* opts.c */ |
076b876e | 24632 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm); |
1facf9fc | 24633 | +const char *au_optstr_udba(int udba); |
24634 | +const char *au_optstr_wbr_copyup(int wbr_copyup); | |
24635 | +const char *au_optstr_wbr_create(int wbr_create); | |
24636 | + | |
24637 | +void au_opts_free(struct au_opts *opts); | |
24638 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts); | |
24639 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
24640 | + unsigned int pending); | |
24641 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts); | |
24642 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts); | |
24643 | + | |
24644 | +unsigned int au_opt_udba(struct super_block *sb); | |
24645 | + | |
1facf9fc | 24646 | +#endif /* __KERNEL__ */ |
24647 | +#endif /* __AUFS_OPTS_H__ */ | |
7f207e10 AM |
24648 | diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c |
24649 | --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
24650 | +++ linux/fs/aufs/plink.c 2015-06-28 17:36:09.028407078 +0200 |
24651 | @@ -0,0 +1,528 @@ | |
1facf9fc | 24652 | +/* |
2000de60 | 24653 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 24654 | + * |
24655 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24656 | + * it under the terms of the GNU General Public License as published by | |
24657 | + * the Free Software Foundation; either version 2 of the License, or | |
24658 | + * (at your option) any later version. | |
dece6358 AM |
24659 | + * |
24660 | + * This program is distributed in the hope that it will be useful, | |
24661 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24662 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24663 | + * GNU General Public License for more details. | |
24664 | + * | |
24665 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24666 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24667 | + */ |
24668 | + | |
24669 | +/* | |
24670 | + * pseudo-link | |
24671 | + */ | |
24672 | + | |
24673 | +#include "aufs.h" | |
24674 | + | |
24675 | +/* | |
e49829fe | 24676 | + * the pseudo-link maintenance mode. |
1facf9fc | 24677 | + * during a user process maintains the pseudo-links, |
24678 | + * prohibit adding a new plink and branch manipulation. | |
e49829fe JR |
24679 | + * |
24680 | + * Flags | |
24681 | + * NOPLM: | |
24682 | + * For entry functions which will handle plink, and i_mutex is already held | |
24683 | + * in VFS. | |
24684 | + * They cannot wait and should return an error at once. | |
24685 | + * Callers has to check the error. | |
24686 | + * NOPLMW: | |
24687 | + * For entry functions which will handle plink, but i_mutex is not held | |
24688 | + * in VFS. | |
24689 | + * They can wait the plink maintenance mode to finish. | |
24690 | + * | |
24691 | + * They behave like F_SETLK and F_SETLKW. | |
24692 | + * If the caller never handle plink, then both flags are unnecessary. | |
1facf9fc | 24693 | + */ |
e49829fe JR |
24694 | + |
24695 | +int au_plink_maint(struct super_block *sb, int flags) | |
1facf9fc | 24696 | +{ |
e49829fe JR |
24697 | + int err; |
24698 | + pid_t pid, ppid; | |
24699 | + struct au_sbinfo *sbi; | |
dece6358 AM |
24700 | + |
24701 | + SiMustAnyLock(sb); | |
24702 | + | |
e49829fe JR |
24703 | + err = 0; |
24704 | + if (!au_opt_test(au_mntflags(sb), PLINK)) | |
24705 | + goto out; | |
24706 | + | |
24707 | + sbi = au_sbi(sb); | |
24708 | + pid = sbi->si_plink_maint_pid; | |
24709 | + if (!pid || pid == current->pid) | |
24710 | + goto out; | |
24711 | + | |
24712 | + /* todo: it highly depends upon /sbin/mount.aufs */ | |
24713 | + rcu_read_lock(); | |
24714 | + ppid = task_pid_vnr(rcu_dereference(current->real_parent)); | |
24715 | + rcu_read_unlock(); | |
24716 | + if (pid == ppid) | |
24717 | + goto out; | |
24718 | + | |
24719 | + if (au_ftest_lock(flags, NOPLMW)) { | |
027c5e7a AM |
24720 | + /* if there is no i_mutex lock in VFS, we don't need to wait */ |
24721 | + /* AuDebugOn(!lockdep_depth(current)); */ | |
e49829fe JR |
24722 | + while (sbi->si_plink_maint_pid) { |
24723 | + si_read_unlock(sb); | |
24724 | + /* gave up wake_up_bit() */ | |
24725 | + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid); | |
24726 | + | |
24727 | + if (au_ftest_lock(flags, FLUSH)) | |
24728 | + au_nwt_flush(&sbi->si_nowait); | |
24729 | + si_noflush_read_lock(sb); | |
24730 | + } | |
24731 | + } else if (au_ftest_lock(flags, NOPLM)) { | |
24732 | + AuDbg("ppid %d, pid %d\n", ppid, pid); | |
24733 | + err = -EAGAIN; | |
24734 | + } | |
24735 | + | |
24736 | +out: | |
24737 | + return err; | |
4a4d8108 AM |
24738 | +} |
24739 | + | |
e49829fe | 24740 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo) |
4a4d8108 | 24741 | +{ |
4a4d8108 | 24742 | + spin_lock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 24743 | + sbinfo->si_plink_maint_pid = 0; |
4a4d8108 | 24744 | + spin_unlock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 24745 | + wake_up_all(&sbinfo->si_plink_wq); |
4a4d8108 AM |
24746 | +} |
24747 | + | |
e49829fe | 24748 | +int au_plink_maint_enter(struct super_block *sb) |
4a4d8108 AM |
24749 | +{ |
24750 | + int err; | |
4a4d8108 AM |
24751 | + struct au_sbinfo *sbinfo; |
24752 | + | |
24753 | + err = 0; | |
4a4d8108 AM |
24754 | + sbinfo = au_sbi(sb); |
24755 | + /* make sure i am the only one in this fs */ | |
e49829fe JR |
24756 | + si_write_lock(sb, AuLock_FLUSH); |
24757 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
24758 | + spin_lock(&sbinfo->si_plink_maint_lock); | |
24759 | + if (!sbinfo->si_plink_maint_pid) | |
24760 | + sbinfo->si_plink_maint_pid = current->pid; | |
24761 | + else | |
24762 | + err = -EBUSY; | |
24763 | + spin_unlock(&sbinfo->si_plink_maint_lock); | |
24764 | + } | |
4a4d8108 AM |
24765 | + si_write_unlock(sb); |
24766 | + | |
24767 | + return err; | |
1facf9fc | 24768 | +} |
24769 | + | |
24770 | +/* ---------------------------------------------------------------------- */ | |
24771 | + | |
1facf9fc | 24772 | +#ifdef CONFIG_AUFS_DEBUG |
24773 | +void au_plink_list(struct super_block *sb) | |
24774 | +{ | |
86dc4139 | 24775 | + int i; |
1facf9fc | 24776 | + struct au_sbinfo *sbinfo; |
86dc4139 | 24777 | + struct hlist_head *plink_hlist; |
1facf9fc | 24778 | + struct pseudo_link *plink; |
24779 | + | |
dece6358 AM |
24780 | + SiMustAnyLock(sb); |
24781 | + | |
1facf9fc | 24782 | + sbinfo = au_sbi(sb); |
24783 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 24784 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 24785 | + |
86dc4139 AM |
24786 | + for (i = 0; i < AuPlink_NHASH; i++) { |
24787 | + plink_hlist = &sbinfo->si_plink[i].head; | |
24788 | + rcu_read_lock(); | |
24789 | + hlist_for_each_entry_rcu(plink, plink_hlist, hlist) | |
24790 | + AuDbg("%lu\n", plink->inode->i_ino); | |
24791 | + rcu_read_unlock(); | |
24792 | + } | |
1facf9fc | 24793 | +} |
24794 | +#endif | |
24795 | + | |
24796 | +/* is the inode pseudo-linked? */ | |
24797 | +int au_plink_test(struct inode *inode) | |
24798 | +{ | |
86dc4139 | 24799 | + int found, i; |
1facf9fc | 24800 | + struct au_sbinfo *sbinfo; |
86dc4139 | 24801 | + struct hlist_head *plink_hlist; |
1facf9fc | 24802 | + struct pseudo_link *plink; |
24803 | + | |
24804 | + sbinfo = au_sbi(inode->i_sb); | |
dece6358 | 24805 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
1facf9fc | 24806 | + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK)); |
e49829fe | 24807 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
1facf9fc | 24808 | + |
24809 | + found = 0; | |
86dc4139 AM |
24810 | + i = au_plink_hash(inode->i_ino); |
24811 | + plink_hlist = &sbinfo->si_plink[i].head; | |
4a4d8108 | 24812 | + rcu_read_lock(); |
86dc4139 | 24813 | + hlist_for_each_entry_rcu(plink, plink_hlist, hlist) |
1facf9fc | 24814 | + if (plink->inode == inode) { |
24815 | + found = 1; | |
24816 | + break; | |
24817 | + } | |
4a4d8108 | 24818 | + rcu_read_unlock(); |
1facf9fc | 24819 | + return found; |
24820 | +} | |
24821 | + | |
24822 | +/* ---------------------------------------------------------------------- */ | |
24823 | + | |
24824 | +/* | |
24825 | + * generate a name for plink. | |
24826 | + * the file will be stored under AUFS_WH_PLINKDIR. | |
24827 | + */ | |
24828 | +/* 20 is max digits length of ulong 64 */ | |
24829 | +#define PLINK_NAME_LEN ((20 + 1) * 2) | |
24830 | + | |
24831 | +static int plink_name(char *name, int len, struct inode *inode, | |
24832 | + aufs_bindex_t bindex) | |
24833 | +{ | |
24834 | + int rlen; | |
24835 | + struct inode *h_inode; | |
24836 | + | |
24837 | + h_inode = au_h_iptr(inode, bindex); | |
24838 | + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino); | |
24839 | + return rlen; | |
24840 | +} | |
24841 | + | |
7f207e10 AM |
24842 | +struct au_do_plink_lkup_args { |
24843 | + struct dentry **errp; | |
24844 | + struct qstr *tgtname; | |
24845 | + struct dentry *h_parent; | |
24846 | + struct au_branch *br; | |
24847 | +}; | |
24848 | + | |
24849 | +static struct dentry *au_do_plink_lkup(struct qstr *tgtname, | |
24850 | + struct dentry *h_parent, | |
24851 | + struct au_branch *br) | |
24852 | +{ | |
24853 | + struct dentry *h_dentry; | |
24854 | + struct mutex *h_mtx; | |
24855 | + | |
5527c038 | 24856 | + h_mtx = &d_inode(h_parent)->i_mutex; |
7f207e10 | 24857 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2); |
b4510431 | 24858 | + h_dentry = vfsub_lkup_one(tgtname, h_parent); |
7f207e10 AM |
24859 | + mutex_unlock(h_mtx); |
24860 | + return h_dentry; | |
24861 | +} | |
24862 | + | |
24863 | +static void au_call_do_plink_lkup(void *args) | |
24864 | +{ | |
24865 | + struct au_do_plink_lkup_args *a = args; | |
24866 | + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br); | |
24867 | +} | |
24868 | + | |
1facf9fc | 24869 | +/* lookup the plink-ed @inode under the branch at @bindex */ |
24870 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex) | |
24871 | +{ | |
24872 | + struct dentry *h_dentry, *h_parent; | |
24873 | + struct au_branch *br; | |
7f207e10 | 24874 | + int wkq_err; |
1facf9fc | 24875 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 24876 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 24877 | + |
e49829fe JR |
24878 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
24879 | + | |
1facf9fc | 24880 | + br = au_sbr(inode->i_sb, bindex); |
24881 | + h_parent = br->br_wbr->wbr_plink; | |
1facf9fc | 24882 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
24883 | + | |
2dfbb274 | 24884 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
7f207e10 AM |
24885 | + struct au_do_plink_lkup_args args = { |
24886 | + .errp = &h_dentry, | |
24887 | + .tgtname = &tgtname, | |
24888 | + .h_parent = h_parent, | |
24889 | + .br = br | |
24890 | + }; | |
24891 | + | |
24892 | + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args); | |
24893 | + if (unlikely(wkq_err)) | |
24894 | + h_dentry = ERR_PTR(wkq_err); | |
24895 | + } else | |
24896 | + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br); | |
24897 | + | |
1facf9fc | 24898 | + return h_dentry; |
24899 | +} | |
24900 | + | |
24901 | +/* create a pseudo-link */ | |
24902 | +static int do_whplink(struct qstr *tgt, struct dentry *h_parent, | |
24903 | + struct dentry *h_dentry, struct au_branch *br) | |
24904 | +{ | |
24905 | + int err; | |
24906 | + struct path h_path = { | |
86dc4139 | 24907 | + .mnt = au_br_mnt(br) |
1facf9fc | 24908 | + }; |
523b37e3 | 24909 | + struct inode *h_dir, *delegated; |
1facf9fc | 24910 | + |
5527c038 | 24911 | + h_dir = d_inode(h_parent); |
7f207e10 | 24912 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2); |
4f0767ce | 24913 | +again: |
b4510431 | 24914 | + h_path.dentry = vfsub_lkup_one(tgt, h_parent); |
1facf9fc | 24915 | + err = PTR_ERR(h_path.dentry); |
24916 | + if (IS_ERR(h_path.dentry)) | |
24917 | + goto out; | |
24918 | + | |
24919 | + err = 0; | |
24920 | + /* wh.plink dir is not monitored */ | |
7f207e10 | 24921 | + /* todo: is it really safe? */ |
5527c038 JR |
24922 | + if (d_is_positive(h_path.dentry) |
24923 | + && d_inode(h_path.dentry) != d_inode(h_dentry)) { | |
523b37e3 AM |
24924 | + delegated = NULL; |
24925 | + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0); | |
24926 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24927 | + pr_warn("cannot retry for NFSv4 delegation" | |
24928 | + " for an internal unlink\n"); | |
24929 | + iput(delegated); | |
24930 | + } | |
1facf9fc | 24931 | + dput(h_path.dentry); |
24932 | + h_path.dentry = NULL; | |
24933 | + if (!err) | |
24934 | + goto again; | |
24935 | + } | |
5527c038 | 24936 | + if (!err && d_is_negative(h_path.dentry)) { |
523b37e3 AM |
24937 | + delegated = NULL; |
24938 | + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated); | |
24939 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24940 | + pr_warn("cannot retry for NFSv4 delegation" | |
24941 | + " for an internal link\n"); | |
24942 | + iput(delegated); | |
24943 | + } | |
24944 | + } | |
1facf9fc | 24945 | + dput(h_path.dentry); |
24946 | + | |
4f0767ce | 24947 | +out: |
7f207e10 | 24948 | + mutex_unlock(&h_dir->i_mutex); |
1facf9fc | 24949 | + return err; |
24950 | +} | |
24951 | + | |
24952 | +struct do_whplink_args { | |
24953 | + int *errp; | |
24954 | + struct qstr *tgt; | |
24955 | + struct dentry *h_parent; | |
24956 | + struct dentry *h_dentry; | |
24957 | + struct au_branch *br; | |
24958 | +}; | |
24959 | + | |
24960 | +static void call_do_whplink(void *args) | |
24961 | +{ | |
24962 | + struct do_whplink_args *a = args; | |
24963 | + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br); | |
24964 | +} | |
24965 | + | |
24966 | +static int whplink(struct dentry *h_dentry, struct inode *inode, | |
24967 | + aufs_bindex_t bindex, struct au_branch *br) | |
24968 | +{ | |
24969 | + int err, wkq_err; | |
24970 | + struct au_wbr *wbr; | |
24971 | + struct dentry *h_parent; | |
1facf9fc | 24972 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 24973 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 24974 | + |
24975 | + wbr = au_sbr(inode->i_sb, bindex)->br_wbr; | |
24976 | + h_parent = wbr->wbr_plink; | |
1facf9fc | 24977 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
24978 | + | |
24979 | + /* always superio. */ | |
2dfbb274 | 24980 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
1facf9fc | 24981 | + struct do_whplink_args args = { |
24982 | + .errp = &err, | |
24983 | + .tgt = &tgtname, | |
24984 | + .h_parent = h_parent, | |
24985 | + .h_dentry = h_dentry, | |
24986 | + .br = br | |
24987 | + }; | |
24988 | + wkq_err = au_wkq_wait(call_do_whplink, &args); | |
24989 | + if (unlikely(wkq_err)) | |
24990 | + err = wkq_err; | |
24991 | + } else | |
24992 | + err = do_whplink(&tgtname, h_parent, h_dentry, br); | |
1facf9fc | 24993 | + |
24994 | + return err; | |
24995 | +} | |
24996 | + | |
24997 | +/* free a single plink */ | |
24998 | +static void do_put_plink(struct pseudo_link *plink, int do_del) | |
24999 | +{ | |
1facf9fc | 25000 | + if (do_del) |
86dc4139 | 25001 | + hlist_del(&plink->hlist); |
4a4d8108 AM |
25002 | + iput(plink->inode); |
25003 | + kfree(plink); | |
25004 | +} | |
25005 | + | |
25006 | +static void do_put_plink_rcu(struct rcu_head *rcu) | |
25007 | +{ | |
25008 | + struct pseudo_link *plink; | |
25009 | + | |
25010 | + plink = container_of(rcu, struct pseudo_link, rcu); | |
25011 | + iput(plink->inode); | |
1facf9fc | 25012 | + kfree(plink); |
25013 | +} | |
25014 | + | |
25015 | +/* | |
25016 | + * create a new pseudo-link for @h_dentry on @bindex. | |
25017 | + * the linked inode is held in aufs @inode. | |
25018 | + */ | |
25019 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
25020 | + struct dentry *h_dentry) | |
25021 | +{ | |
25022 | + struct super_block *sb; | |
25023 | + struct au_sbinfo *sbinfo; | |
86dc4139 | 25024 | + struct hlist_head *plink_hlist; |
4a4d8108 | 25025 | + struct pseudo_link *plink, *tmp; |
86dc4139 AM |
25026 | + struct au_sphlhead *sphl; |
25027 | + int found, err, cnt, i; | |
1facf9fc | 25028 | + |
25029 | + sb = inode->i_sb; | |
25030 | + sbinfo = au_sbi(sb); | |
25031 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25032 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25033 | + |
86dc4139 | 25034 | + found = au_plink_test(inode); |
4a4d8108 | 25035 | + if (found) |
1facf9fc | 25036 | + return; |
4a4d8108 | 25037 | + |
86dc4139 AM |
25038 | + i = au_plink_hash(inode->i_ino); |
25039 | + sphl = sbinfo->si_plink + i; | |
25040 | + plink_hlist = &sphl->head; | |
4a4d8108 AM |
25041 | + tmp = kmalloc(sizeof(*plink), GFP_NOFS); |
25042 | + if (tmp) | |
25043 | + tmp->inode = au_igrab(inode); | |
25044 | + else { | |
25045 | + err = -ENOMEM; | |
25046 | + goto out; | |
1facf9fc | 25047 | + } |
25048 | + | |
86dc4139 AM |
25049 | + spin_lock(&sphl->spin); |
25050 | + hlist_for_each_entry(plink, plink_hlist, hlist) { | |
4a4d8108 AM |
25051 | + if (plink->inode == inode) { |
25052 | + found = 1; | |
25053 | + break; | |
25054 | + } | |
1facf9fc | 25055 | + } |
4a4d8108 | 25056 | + if (!found) |
86dc4139 AM |
25057 | + hlist_add_head_rcu(&tmp->hlist, plink_hlist); |
25058 | + spin_unlock(&sphl->spin); | |
4a4d8108 | 25059 | + if (!found) { |
86dc4139 AM |
25060 | + cnt = au_sphl_count(sphl); |
25061 | +#define msg "unexpectedly unblanced or too many pseudo-links" | |
25062 | + if (cnt > AUFS_PLINK_WARN) | |
25063 | + AuWarn1(msg ", %d\n", cnt); | |
25064 | +#undef msg | |
1facf9fc | 25065 | + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex)); |
4a4d8108 AM |
25066 | + } else { |
25067 | + do_put_plink(tmp, 0); | |
25068 | + return; | |
1facf9fc | 25069 | + } |
25070 | + | |
4a4d8108 | 25071 | +out: |
1facf9fc | 25072 | + if (unlikely(err)) { |
0c3ec466 | 25073 | + pr_warn("err %d, damaged pseudo link.\n", err); |
4a4d8108 | 25074 | + if (tmp) { |
86dc4139 | 25075 | + au_sphl_del_rcu(&tmp->hlist, sphl); |
4a4d8108 AM |
25076 | + call_rcu(&tmp->rcu, do_put_plink_rcu); |
25077 | + } | |
1facf9fc | 25078 | + } |
25079 | +} | |
25080 | + | |
25081 | +/* free all plinks */ | |
e49829fe | 25082 | +void au_plink_put(struct super_block *sb, int verbose) |
1facf9fc | 25083 | +{ |
86dc4139 | 25084 | + int i, warned; |
1facf9fc | 25085 | + struct au_sbinfo *sbinfo; |
86dc4139 AM |
25086 | + struct hlist_head *plink_hlist; |
25087 | + struct hlist_node *tmp; | |
25088 | + struct pseudo_link *plink; | |
1facf9fc | 25089 | + |
dece6358 AM |
25090 | + SiMustWriteLock(sb); |
25091 | + | |
1facf9fc | 25092 | + sbinfo = au_sbi(sb); |
25093 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25094 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25095 | + |
1facf9fc | 25096 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
25097 | + warned = 0; |
25098 | + for (i = 0; i < AuPlink_NHASH; i++) { | |
25099 | + plink_hlist = &sbinfo->si_plink[i].head; | |
25100 | + if (!warned && verbose && !hlist_empty(plink_hlist)) { | |
25101 | + pr_warn("pseudo-link is not flushed"); | |
25102 | + warned = 1; | |
25103 | + } | |
25104 | + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) | |
25105 | + do_put_plink(plink, 0); | |
25106 | + INIT_HLIST_HEAD(plink_hlist); | |
25107 | + } | |
1facf9fc | 25108 | +} |
25109 | + | |
e49829fe JR |
25110 | +void au_plink_clean(struct super_block *sb, int verbose) |
25111 | +{ | |
25112 | + struct dentry *root; | |
25113 | + | |
25114 | + root = sb->s_root; | |
25115 | + aufs_write_lock(root); | |
25116 | + if (au_opt_test(au_mntflags(sb), PLINK)) | |
25117 | + au_plink_put(sb, verbose); | |
25118 | + aufs_write_unlock(root); | |
25119 | +} | |
25120 | + | |
86dc4139 AM |
25121 | +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id) |
25122 | +{ | |
25123 | + int do_put; | |
25124 | + aufs_bindex_t bstart, bend, bindex; | |
25125 | + | |
25126 | + do_put = 0; | |
25127 | + bstart = au_ibstart(inode); | |
25128 | + bend = au_ibend(inode); | |
25129 | + if (bstart >= 0) { | |
25130 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
25131 | + if (!au_h_iptr(inode, bindex) | |
25132 | + || au_ii_br_id(inode, bindex) != br_id) | |
25133 | + continue; | |
25134 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
25135 | + do_put = 1; | |
25136 | + break; | |
25137 | + } | |
25138 | + if (do_put) | |
25139 | + for (bindex = bstart; bindex <= bend; bindex++) | |
25140 | + if (au_h_iptr(inode, bindex)) { | |
25141 | + do_put = 0; | |
25142 | + break; | |
25143 | + } | |
25144 | + } else | |
25145 | + do_put = 1; | |
25146 | + | |
25147 | + return do_put; | |
25148 | +} | |
25149 | + | |
1facf9fc | 25150 | +/* free the plinks on a branch specified by @br_id */ |
25151 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id) | |
25152 | +{ | |
25153 | + struct au_sbinfo *sbinfo; | |
86dc4139 AM |
25154 | + struct hlist_head *plink_hlist; |
25155 | + struct hlist_node *tmp; | |
25156 | + struct pseudo_link *plink; | |
1facf9fc | 25157 | + struct inode *inode; |
86dc4139 | 25158 | + int i, do_put; |
1facf9fc | 25159 | + |
dece6358 AM |
25160 | + SiMustWriteLock(sb); |
25161 | + | |
1facf9fc | 25162 | + sbinfo = au_sbi(sb); |
25163 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25164 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25165 | + |
1facf9fc | 25166 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
25167 | + for (i = 0; i < AuPlink_NHASH; i++) { |
25168 | + plink_hlist = &sbinfo->si_plink[i].head; | |
25169 | + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) { | |
25170 | + inode = au_igrab(plink->inode); | |
25171 | + ii_write_lock_child(inode); | |
25172 | + do_put = au_plink_do_half_refresh(inode, br_id); | |
dece6358 AM |
25173 | + if (do_put) |
25174 | + do_put_plink(plink, 1); | |
86dc4139 AM |
25175 | + ii_write_unlock(inode); |
25176 | + iput(inode); | |
dece6358 | 25177 | + } |
dece6358 AM |
25178 | + } |
25179 | +} | |
7f207e10 AM |
25180 | diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c |
25181 | --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 25182 | +++ linux/fs/aufs/poll.c 2015-06-28 17:35:44.351383872 +0200 |
b912730e | 25183 | @@ -0,0 +1,52 @@ |
dece6358 | 25184 | +/* |
2000de60 | 25185 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
dece6358 AM |
25186 | + * |
25187 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25188 | + * it under the terms of the GNU General Public License as published by | |
25189 | + * the Free Software Foundation; either version 2 of the License, or | |
25190 | + * (at your option) any later version. | |
25191 | + * | |
25192 | + * This program is distributed in the hope that it will be useful, | |
25193 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25194 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25195 | + * GNU General Public License for more details. | |
25196 | + * | |
25197 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25198 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 AM |
25199 | + */ |
25200 | + | |
1308ab2a | 25201 | +/* |
25202 | + * poll operation | |
25203 | + * There is only one filesystem which implements ->poll operation, currently. | |
25204 | + */ | |
25205 | + | |
25206 | +#include "aufs.h" | |
25207 | + | |
25208 | +unsigned int aufs_poll(struct file *file, poll_table *wait) | |
25209 | +{ | |
25210 | + unsigned int mask; | |
25211 | + int err; | |
25212 | + struct file *h_file; | |
1308ab2a | 25213 | + struct super_block *sb; |
25214 | + | |
25215 | + /* We should pretend an error happened. */ | |
25216 | + mask = POLLERR /* | POLLIN | POLLOUT */; | |
b912730e | 25217 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 25218 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e AM |
25219 | + |
25220 | + h_file = au_read_pre(file, /*keep_fi*/0); | |
25221 | + err = PTR_ERR(h_file); | |
25222 | + if (IS_ERR(h_file)) | |
1308ab2a | 25223 | + goto out; |
25224 | + | |
25225 | + /* it is not an error if h_file has no operation */ | |
25226 | + mask = DEFAULT_POLLMASK; | |
523b37e3 | 25227 | + if (h_file->f_op->poll) |
1308ab2a | 25228 | + mask = h_file->f_op->poll(h_file, wait); |
b912730e | 25229 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 25230 | + |
4f0767ce | 25231 | +out: |
1308ab2a | 25232 | + si_read_unlock(sb); |
25233 | + AuTraceErr((int)mask); | |
25234 | + return mask; | |
25235 | +} | |
c1595e42 JR |
25236 | diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c |
25237 | --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 25238 | +++ linux/fs/aufs/posix_acl.c 2015-06-28 17:35:44.351383872 +0200 |
c1595e42 JR |
25239 | @@ -0,0 +1,99 @@ |
25240 | +/* | |
2000de60 | 25241 | + * Copyright (C) 2014-2015 Junjiro R. Okajima |
c1595e42 JR |
25242 | + * |
25243 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25244 | + * it under the terms of the GNU General Public License as published by | |
25245 | + * the Free Software Foundation; either version 2 of the License, or | |
25246 | + * (at your option) any later version. | |
25247 | + * | |
25248 | + * This program is distributed in the hope that it will be useful, | |
25249 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25250 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25251 | + * GNU General Public License for more details. | |
25252 | + * | |
25253 | + * You should have received a copy of the GNU General Public License | |
25254 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25255 | + */ | |
25256 | + | |
25257 | +/* | |
25258 | + * posix acl operations | |
25259 | + */ | |
25260 | + | |
25261 | +#include <linux/fs.h> | |
25262 | +#include <linux/posix_acl.h> | |
25263 | +#include "aufs.h" | |
25264 | + | |
25265 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type) | |
25266 | +{ | |
25267 | + struct posix_acl *acl; | |
25268 | + int err; | |
25269 | + aufs_bindex_t bindex; | |
25270 | + struct inode *h_inode; | |
25271 | + struct super_block *sb; | |
25272 | + | |
25273 | + acl = NULL; | |
25274 | + sb = inode->i_sb; | |
25275 | + si_read_lock(sb, AuLock_FLUSH); | |
25276 | + ii_read_lock_child(inode); | |
25277 | + if (!(sb->s_flags & MS_POSIXACL)) | |
25278 | + goto out; | |
25279 | + | |
25280 | + bindex = au_ibstart(inode); | |
25281 | + h_inode = au_h_iptr(inode, bindex); | |
25282 | + if (unlikely(!h_inode | |
25283 | + || ((h_inode->i_mode & S_IFMT) | |
25284 | + != (inode->i_mode & S_IFMT)))) { | |
25285 | + err = au_busy_or_stale(); | |
25286 | + acl = ERR_PTR(err); | |
25287 | + goto out; | |
25288 | + } | |
25289 | + | |
25290 | + /* always topmost only */ | |
25291 | + acl = get_acl(h_inode, type); | |
25292 | + | |
25293 | +out: | |
25294 | + ii_read_unlock(inode); | |
25295 | + si_read_unlock(sb); | |
25296 | + | |
25297 | + AuTraceErrPtr(acl); | |
25298 | + return acl; | |
25299 | +} | |
25300 | + | |
25301 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |
25302 | +{ | |
25303 | + int err; | |
25304 | + ssize_t ssz; | |
25305 | + struct dentry *dentry; | |
25306 | + struct au_srxattr arg = { | |
25307 | + .type = AU_ACL_SET, | |
25308 | + .u.acl_set = { | |
25309 | + .acl = acl, | |
25310 | + .type = type | |
25311 | + }, | |
25312 | + }; | |
25313 | + | |
25314 | + mutex_lock(&inode->i_mutex); | |
25315 | + if (inode->i_ino == AUFS_ROOT_INO) | |
25316 | + dentry = dget(inode->i_sb->s_root); | |
25317 | + else { | |
25318 | + dentry = d_find_alias(inode); | |
25319 | + if (!dentry) | |
25320 | + dentry = d_find_any_alias(inode); | |
25321 | + if (!dentry) { | |
25322 | + pr_warn("cannot handle this inode, " | |
25323 | + "please report to aufs-users ML\n"); | |
25324 | + err = -ENOENT; | |
25325 | + goto out; | |
25326 | + } | |
25327 | + } | |
25328 | + | |
25329 | + ssz = au_srxattr(dentry, &arg); | |
25330 | + dput(dentry); | |
25331 | + err = ssz; | |
25332 | + if (ssz >= 0) | |
25333 | + err = 0; | |
25334 | + | |
25335 | +out: | |
25336 | + mutex_unlock(&inode->i_mutex); | |
25337 | + return err; | |
25338 | +} | |
7f207e10 AM |
25339 | diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c |
25340 | --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 25341 | +++ linux/fs/aufs/procfs.c 2015-06-28 17:35:44.351383872 +0200 |
523b37e3 | 25342 | @@ -0,0 +1,169 @@ |
e49829fe | 25343 | +/* |
2000de60 | 25344 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
e49829fe JR |
25345 | + * |
25346 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25347 | + * it under the terms of the GNU General Public License as published by | |
25348 | + * the Free Software Foundation; either version 2 of the License, or | |
25349 | + * (at your option) any later version. | |
25350 | + * | |
25351 | + * This program is distributed in the hope that it will be useful, | |
25352 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25353 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25354 | + * GNU General Public License for more details. | |
25355 | + * | |
25356 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25357 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
25358 | + */ |
25359 | + | |
25360 | +/* | |
25361 | + * procfs interfaces | |
25362 | + */ | |
25363 | + | |
25364 | +#include <linux/proc_fs.h> | |
25365 | +#include "aufs.h" | |
25366 | + | |
25367 | +static int au_procfs_plm_release(struct inode *inode, struct file *file) | |
25368 | +{ | |
25369 | + struct au_sbinfo *sbinfo; | |
25370 | + | |
25371 | + sbinfo = file->private_data; | |
25372 | + if (sbinfo) { | |
25373 | + au_plink_maint_leave(sbinfo); | |
25374 | + kobject_put(&sbinfo->si_kobj); | |
25375 | + } | |
25376 | + | |
25377 | + return 0; | |
25378 | +} | |
25379 | + | |
25380 | +static void au_procfs_plm_write_clean(struct file *file) | |
25381 | +{ | |
25382 | + struct au_sbinfo *sbinfo; | |
25383 | + | |
25384 | + sbinfo = file->private_data; | |
25385 | + if (sbinfo) | |
25386 | + au_plink_clean(sbinfo->si_sb, /*verbose*/0); | |
25387 | +} | |
25388 | + | |
25389 | +static int au_procfs_plm_write_si(struct file *file, unsigned long id) | |
25390 | +{ | |
25391 | + int err; | |
25392 | + struct super_block *sb; | |
25393 | + struct au_sbinfo *sbinfo; | |
25394 | + | |
25395 | + err = -EBUSY; | |
25396 | + if (unlikely(file->private_data)) | |
25397 | + goto out; | |
25398 | + | |
25399 | + sb = NULL; | |
53392da6 | 25400 | + /* don't use au_sbilist_lock() here */ |
e49829fe JR |
25401 | + spin_lock(&au_sbilist.spin); |
25402 | + list_for_each_entry(sbinfo, &au_sbilist.head, si_list) | |
25403 | + if (id == sysaufs_si_id(sbinfo)) { | |
25404 | + kobject_get(&sbinfo->si_kobj); | |
25405 | + sb = sbinfo->si_sb; | |
25406 | + break; | |
25407 | + } | |
25408 | + spin_unlock(&au_sbilist.spin); | |
25409 | + | |
25410 | + err = -EINVAL; | |
25411 | + if (unlikely(!sb)) | |
25412 | + goto out; | |
25413 | + | |
25414 | + err = au_plink_maint_enter(sb); | |
25415 | + if (!err) | |
25416 | + /* keep kobject_get() */ | |
25417 | + file->private_data = sbinfo; | |
25418 | + else | |
25419 | + kobject_put(&sbinfo->si_kobj); | |
25420 | +out: | |
25421 | + return err; | |
25422 | +} | |
25423 | + | |
25424 | +/* | |
25425 | + * Accept a valid "si=xxxx" only. | |
25426 | + * Once it is accepted successfully, accept "clean" too. | |
25427 | + */ | |
25428 | +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf, | |
25429 | + size_t count, loff_t *ppos) | |
25430 | +{ | |
25431 | + ssize_t err; | |
25432 | + unsigned long id; | |
25433 | + /* last newline is allowed */ | |
25434 | + char buf[3 + sizeof(unsigned long) * 2 + 1]; | |
25435 | + | |
25436 | + err = -EACCES; | |
25437 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
25438 | + goto out; | |
25439 | + | |
25440 | + err = -EINVAL; | |
25441 | + if (unlikely(count > sizeof(buf))) | |
25442 | + goto out; | |
25443 | + | |
25444 | + err = copy_from_user(buf, ubuf, count); | |
25445 | + if (unlikely(err)) { | |
25446 | + err = -EFAULT; | |
25447 | + goto out; | |
25448 | + } | |
25449 | + buf[count] = 0; | |
25450 | + | |
25451 | + err = -EINVAL; | |
25452 | + if (!strcmp("clean", buf)) { | |
25453 | + au_procfs_plm_write_clean(file); | |
25454 | + goto out_success; | |
25455 | + } else if (unlikely(strncmp("si=", buf, 3))) | |
25456 | + goto out; | |
25457 | + | |
9dbd164d | 25458 | + err = kstrtoul(buf + 3, 16, &id); |
e49829fe JR |
25459 | + if (unlikely(err)) |
25460 | + goto out; | |
25461 | + | |
25462 | + err = au_procfs_plm_write_si(file, id); | |
25463 | + if (unlikely(err)) | |
25464 | + goto out; | |
25465 | + | |
25466 | +out_success: | |
25467 | + err = count; /* success */ | |
25468 | +out: | |
25469 | + return err; | |
25470 | +} | |
25471 | + | |
25472 | +static const struct file_operations au_procfs_plm_fop = { | |
25473 | + .write = au_procfs_plm_write, | |
25474 | + .release = au_procfs_plm_release, | |
25475 | + .owner = THIS_MODULE | |
25476 | +}; | |
25477 | + | |
25478 | +/* ---------------------------------------------------------------------- */ | |
25479 | + | |
25480 | +static struct proc_dir_entry *au_procfs_dir; | |
25481 | + | |
25482 | +void au_procfs_fin(void) | |
25483 | +{ | |
25484 | + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir); | |
25485 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
25486 | +} | |
25487 | + | |
25488 | +int __init au_procfs_init(void) | |
25489 | +{ | |
25490 | + int err; | |
25491 | + struct proc_dir_entry *entry; | |
25492 | + | |
25493 | + err = -ENOMEM; | |
25494 | + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL); | |
25495 | + if (unlikely(!au_procfs_dir)) | |
25496 | + goto out; | |
25497 | + | |
25498 | + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR, | |
25499 | + au_procfs_dir, &au_procfs_plm_fop); | |
25500 | + if (unlikely(!entry)) | |
25501 | + goto out_dir; | |
25502 | + | |
25503 | + err = 0; | |
25504 | + goto out; /* success */ | |
25505 | + | |
25506 | + | |
25507 | +out_dir: | |
25508 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
25509 | +out: | |
25510 | + return err; | |
25511 | +} | |
7f207e10 AM |
25512 | diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c |
25513 | --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 25514 | +++ linux/fs/aufs/rdu.c 2015-06-28 17:36:09.028407078 +0200 |
523b37e3 | 25515 | @@ -0,0 +1,388 @@ |
1308ab2a | 25516 | +/* |
2000de60 | 25517 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1308ab2a | 25518 | + * |
25519 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25520 | + * it under the terms of the GNU General Public License as published by | |
25521 | + * the Free Software Foundation; either version 2 of the License, or | |
25522 | + * (at your option) any later version. | |
25523 | + * | |
25524 | + * This program is distributed in the hope that it will be useful, | |
25525 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25526 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25527 | + * GNU General Public License for more details. | |
25528 | + * | |
25529 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25530 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1308ab2a | 25531 | + */ |
25532 | + | |
25533 | +/* | |
25534 | + * readdir in userspace. | |
25535 | + */ | |
25536 | + | |
b752ccd1 | 25537 | +#include <linux/compat.h> |
4a4d8108 | 25538 | +#include <linux/fs_stack.h> |
1308ab2a | 25539 | +#include <linux/security.h> |
1308ab2a | 25540 | +#include "aufs.h" |
25541 | + | |
25542 | +/* bits for struct aufs_rdu.flags */ | |
25543 | +#define AuRdu_CALLED 1 | |
25544 | +#define AuRdu_CONT (1 << 1) | |
25545 | +#define AuRdu_FULL (1 << 2) | |
25546 | +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name) | |
7f207e10 AM |
25547 | +#define au_fset_rdu(flags, name) \ |
25548 | + do { (flags) |= AuRdu_##name; } while (0) | |
25549 | +#define au_fclr_rdu(flags, name) \ | |
25550 | + do { (flags) &= ~AuRdu_##name; } while (0) | |
1308ab2a | 25551 | + |
25552 | +struct au_rdu_arg { | |
392086de | 25553 | + struct dir_context ctx; |
1308ab2a | 25554 | + struct aufs_rdu *rdu; |
25555 | + union au_rdu_ent_ul ent; | |
25556 | + unsigned long end; | |
25557 | + | |
25558 | + struct super_block *sb; | |
25559 | + int err; | |
25560 | +}; | |
25561 | + | |
392086de | 25562 | +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen, |
1308ab2a | 25563 | + loff_t offset, u64 h_ino, unsigned int d_type) |
25564 | +{ | |
25565 | + int err, len; | |
392086de | 25566 | + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx); |
1308ab2a | 25567 | + struct aufs_rdu *rdu = arg->rdu; |
25568 | + struct au_rdu_ent ent; | |
25569 | + | |
25570 | + err = 0; | |
25571 | + arg->err = 0; | |
25572 | + au_fset_rdu(rdu->cookie.flags, CALLED); | |
25573 | + len = au_rdu_len(nlen); | |
25574 | + if (arg->ent.ul + len < arg->end) { | |
25575 | + ent.ino = h_ino; | |
25576 | + ent.bindex = rdu->cookie.bindex; | |
25577 | + ent.type = d_type; | |
25578 | + ent.nlen = nlen; | |
4a4d8108 AM |
25579 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) |
25580 | + ent.type = DT_UNKNOWN; | |
1308ab2a | 25581 | + |
9dbd164d | 25582 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 25583 | + err = -EFAULT; |
25584 | + if (copy_to_user(arg->ent.e, &ent, sizeof(ent))) | |
25585 | + goto out; | |
25586 | + if (copy_to_user(arg->ent.e->name, name, nlen)) | |
25587 | + goto out; | |
25588 | + /* the terminating NULL */ | |
25589 | + if (__put_user(0, arg->ent.e->name + nlen)) | |
25590 | + goto out; | |
25591 | + err = 0; | |
25592 | + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */ | |
25593 | + arg->ent.ul += len; | |
25594 | + rdu->rent++; | |
25595 | + } else { | |
25596 | + err = -EFAULT; | |
25597 | + au_fset_rdu(rdu->cookie.flags, FULL); | |
25598 | + rdu->full = 1; | |
25599 | + rdu->tail = arg->ent; | |
25600 | + } | |
25601 | + | |
4f0767ce | 25602 | +out: |
1308ab2a | 25603 | + /* AuTraceErr(err); */ |
25604 | + return err; | |
25605 | +} | |
25606 | + | |
25607 | +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg) | |
25608 | +{ | |
25609 | + int err; | |
25610 | + loff_t offset; | |
25611 | + struct au_rdu_cookie *cookie = &arg->rdu->cookie; | |
25612 | + | |
92d182d2 | 25613 | + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */ |
1308ab2a | 25614 | + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET); |
25615 | + err = offset; | |
25616 | + if (unlikely(offset != cookie->h_pos)) | |
25617 | + goto out; | |
25618 | + | |
25619 | + err = 0; | |
25620 | + do { | |
25621 | + arg->err = 0; | |
25622 | + au_fclr_rdu(cookie->flags, CALLED); | |
25623 | + /* smp_mb(); */ | |
392086de | 25624 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1308ab2a | 25625 | + if (err >= 0) |
25626 | + err = arg->err; | |
25627 | + } while (!err | |
25628 | + && au_ftest_rdu(cookie->flags, CALLED) | |
25629 | + && !au_ftest_rdu(cookie->flags, FULL)); | |
25630 | + cookie->h_pos = h_file->f_pos; | |
25631 | + | |
4f0767ce | 25632 | +out: |
1308ab2a | 25633 | + AuTraceErr(err); |
25634 | + return err; | |
25635 | +} | |
25636 | + | |
25637 | +static int au_rdu(struct file *file, struct aufs_rdu *rdu) | |
25638 | +{ | |
25639 | + int err; | |
25640 | + aufs_bindex_t bend; | |
392086de AM |
25641 | + struct au_rdu_arg arg = { |
25642 | + .ctx = { | |
2000de60 | 25643 | + .actor = au_rdu_fill |
392086de AM |
25644 | + } |
25645 | + }; | |
1308ab2a | 25646 | + struct dentry *dentry; |
25647 | + struct inode *inode; | |
25648 | + struct file *h_file; | |
25649 | + struct au_rdu_cookie *cookie = &rdu->cookie; | |
25650 | + | |
25651 | + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz); | |
25652 | + if (unlikely(err)) { | |
25653 | + err = -EFAULT; | |
25654 | + AuTraceErr(err); | |
25655 | + goto out; | |
25656 | + } | |
25657 | + rdu->rent = 0; | |
25658 | + rdu->tail = rdu->ent; | |
25659 | + rdu->full = 0; | |
25660 | + arg.rdu = rdu; | |
25661 | + arg.ent = rdu->ent; | |
25662 | + arg.end = arg.ent.ul; | |
25663 | + arg.end += rdu->sz; | |
25664 | + | |
25665 | + err = -ENOTDIR; | |
523b37e3 | 25666 | + if (unlikely(!file->f_op->iterate)) |
1308ab2a | 25667 | + goto out; |
25668 | + | |
25669 | + err = security_file_permission(file, MAY_READ); | |
25670 | + AuTraceErr(err); | |
25671 | + if (unlikely(err)) | |
25672 | + goto out; | |
25673 | + | |
2000de60 | 25674 | + dentry = file->f_path.dentry; |
5527c038 | 25675 | + inode = d_inode(dentry); |
1308ab2a | 25676 | +#if 1 |
25677 | + mutex_lock(&inode->i_mutex); | |
25678 | +#else | |
25679 | + err = mutex_lock_killable(&inode->i_mutex); | |
25680 | + AuTraceErr(err); | |
25681 | + if (unlikely(err)) | |
25682 | + goto out; | |
25683 | +#endif | |
1308ab2a | 25684 | + |
25685 | + arg.sb = inode->i_sb; | |
e49829fe JR |
25686 | + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM); |
25687 | + if (unlikely(err)) | |
25688 | + goto out_mtx; | |
027c5e7a AM |
25689 | + err = au_alive_dir(dentry); |
25690 | + if (unlikely(err)) | |
25691 | + goto out_si; | |
e49829fe | 25692 | + /* todo: reval? */ |
1308ab2a | 25693 | + fi_read_lock(file); |
25694 | + | |
25695 | + err = -EAGAIN; | |
25696 | + if (unlikely(au_ftest_rdu(cookie->flags, CONT) | |
25697 | + && cookie->generation != au_figen(file))) | |
25698 | + goto out_unlock; | |
25699 | + | |
25700 | + err = 0; | |
25701 | + if (!rdu->blk) { | |
25702 | + rdu->blk = au_sbi(arg.sb)->si_rdblk; | |
25703 | + if (!rdu->blk) | |
25704 | + rdu->blk = au_dir_size(file, /*dentry*/NULL); | |
25705 | + } | |
25706 | + bend = au_fbstart(file); | |
25707 | + if (cookie->bindex < bend) | |
25708 | + cookie->bindex = bend; | |
4a4d8108 | 25709 | + bend = au_fbend_dir(file); |
1308ab2a | 25710 | + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */ |
25711 | + for (; !err && cookie->bindex <= bend; | |
25712 | + cookie->bindex++, cookie->h_pos = 0) { | |
4a4d8108 | 25713 | + h_file = au_hf_dir(file, cookie->bindex); |
1308ab2a | 25714 | + if (!h_file) |
25715 | + continue; | |
25716 | + | |
25717 | + au_fclr_rdu(cookie->flags, FULL); | |
25718 | + err = au_rdu_do(h_file, &arg); | |
25719 | + AuTraceErr(err); | |
25720 | + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err)) | |
25721 | + break; | |
25722 | + } | |
25723 | + AuDbg("rent %llu\n", rdu->rent); | |
25724 | + | |
25725 | + if (!err && !au_ftest_rdu(cookie->flags, CONT)) { | |
25726 | + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH); | |
25727 | + au_fset_rdu(cookie->flags, CONT); | |
25728 | + cookie->generation = au_figen(file); | |
25729 | + } | |
25730 | + | |
25731 | + ii_read_lock_child(inode); | |
25732 | + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode))); | |
25733 | + ii_read_unlock(inode); | |
25734 | + | |
4f0767ce | 25735 | +out_unlock: |
1308ab2a | 25736 | + fi_read_unlock(file); |
027c5e7a | 25737 | +out_si: |
1308ab2a | 25738 | + si_read_unlock(arg.sb); |
4f0767ce | 25739 | +out_mtx: |
1308ab2a | 25740 | + mutex_unlock(&inode->i_mutex); |
4f0767ce | 25741 | +out: |
1308ab2a | 25742 | + AuTraceErr(err); |
25743 | + return err; | |
25744 | +} | |
25745 | + | |
25746 | +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu) | |
25747 | +{ | |
25748 | + int err; | |
25749 | + ino_t ino; | |
25750 | + unsigned long long nent; | |
25751 | + union au_rdu_ent_ul *u; | |
25752 | + struct au_rdu_ent ent; | |
25753 | + struct super_block *sb; | |
25754 | + | |
25755 | + err = 0; | |
25756 | + nent = rdu->nent; | |
25757 | + u = &rdu->ent; | |
2000de60 | 25758 | + sb = file->f_path.dentry->d_sb; |
1308ab2a | 25759 | + si_read_lock(sb, AuLock_FLUSH); |
25760 | + while (nent-- > 0) { | |
9dbd164d | 25761 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 25762 | + err = copy_from_user(&ent, u->e, sizeof(ent)); |
4a4d8108 AM |
25763 | + if (!err) |
25764 | + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino)); | |
1308ab2a | 25765 | + if (unlikely(err)) { |
25766 | + err = -EFAULT; | |
25767 | + AuTraceErr(err); | |
25768 | + break; | |
25769 | + } | |
25770 | + | |
25771 | + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */ | |
25772 | + if (!ent.wh) | |
25773 | + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino); | |
25774 | + else | |
25775 | + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type, | |
25776 | + &ino); | |
25777 | + if (unlikely(err)) { | |
25778 | + AuTraceErr(err); | |
25779 | + break; | |
25780 | + } | |
25781 | + | |
25782 | + err = __put_user(ino, &u->e->ino); | |
25783 | + if (unlikely(err)) { | |
25784 | + err = -EFAULT; | |
25785 | + AuTraceErr(err); | |
25786 | + break; | |
25787 | + } | |
25788 | + u->ul += au_rdu_len(ent.nlen); | |
25789 | + } | |
25790 | + si_read_unlock(sb); | |
25791 | + | |
25792 | + return err; | |
25793 | +} | |
25794 | + | |
25795 | +/* ---------------------------------------------------------------------- */ | |
25796 | + | |
25797 | +static int au_rdu_verify(struct aufs_rdu *rdu) | |
25798 | +{ | |
b752ccd1 | 25799 | + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | " |
1308ab2a | 25800 | + "%llu, b%d, 0x%x, g%u}\n", |
b752ccd1 | 25801 | + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ], |
1308ab2a | 25802 | + rdu->blk, |
25803 | + rdu->rent, rdu->shwh, rdu->full, | |
25804 | + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags, | |
25805 | + rdu->cookie.generation); | |
dece6358 | 25806 | + |
b752ccd1 | 25807 | + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu)) |
1308ab2a | 25808 | + return 0; |
dece6358 | 25809 | + |
b752ccd1 AM |
25810 | + AuDbg("%u:%u\n", |
25811 | + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu)); | |
1308ab2a | 25812 | + return -EINVAL; |
25813 | +} | |
25814 | + | |
25815 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
dece6358 | 25816 | +{ |
1308ab2a | 25817 | + long err, e; |
25818 | + struct aufs_rdu rdu; | |
25819 | + void __user *p = (void __user *)arg; | |
dece6358 | 25820 | + |
1308ab2a | 25821 | + err = copy_from_user(&rdu, p, sizeof(rdu)); |
25822 | + if (unlikely(err)) { | |
25823 | + err = -EFAULT; | |
25824 | + AuTraceErr(err); | |
25825 | + goto out; | |
25826 | + } | |
25827 | + err = au_rdu_verify(&rdu); | |
dece6358 AM |
25828 | + if (unlikely(err)) |
25829 | + goto out; | |
25830 | + | |
1308ab2a | 25831 | + switch (cmd) { |
25832 | + case AUFS_CTL_RDU: | |
25833 | + err = au_rdu(file, &rdu); | |
25834 | + if (unlikely(err)) | |
25835 | + break; | |
dece6358 | 25836 | + |
1308ab2a | 25837 | + e = copy_to_user(p, &rdu, sizeof(rdu)); |
25838 | + if (unlikely(e)) { | |
25839 | + err = -EFAULT; | |
25840 | + AuTraceErr(err); | |
25841 | + } | |
25842 | + break; | |
25843 | + case AUFS_CTL_RDU_INO: | |
25844 | + err = au_rdu_ino(file, &rdu); | |
25845 | + break; | |
25846 | + | |
25847 | + default: | |
4a4d8108 | 25848 | + /* err = -ENOTTY; */ |
1308ab2a | 25849 | + err = -EINVAL; |
25850 | + } | |
dece6358 | 25851 | + |
4f0767ce | 25852 | +out: |
1308ab2a | 25853 | + AuTraceErr(err); |
25854 | + return err; | |
1facf9fc | 25855 | +} |
b752ccd1 AM |
25856 | + |
25857 | +#ifdef CONFIG_COMPAT | |
25858 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
25859 | +{ | |
25860 | + long err, e; | |
25861 | + struct aufs_rdu rdu; | |
25862 | + void __user *p = compat_ptr(arg); | |
25863 | + | |
25864 | + /* todo: get_user()? */ | |
25865 | + err = copy_from_user(&rdu, p, sizeof(rdu)); | |
25866 | + if (unlikely(err)) { | |
25867 | + err = -EFAULT; | |
25868 | + AuTraceErr(err); | |
25869 | + goto out; | |
25870 | + } | |
25871 | + rdu.ent.e = compat_ptr(rdu.ent.ul); | |
25872 | + err = au_rdu_verify(&rdu); | |
25873 | + if (unlikely(err)) | |
25874 | + goto out; | |
25875 | + | |
25876 | + switch (cmd) { | |
25877 | + case AUFS_CTL_RDU: | |
25878 | + err = au_rdu(file, &rdu); | |
25879 | + if (unlikely(err)) | |
25880 | + break; | |
25881 | + | |
25882 | + rdu.ent.ul = ptr_to_compat(rdu.ent.e); | |
25883 | + rdu.tail.ul = ptr_to_compat(rdu.tail.e); | |
25884 | + e = copy_to_user(p, &rdu, sizeof(rdu)); | |
25885 | + if (unlikely(e)) { | |
25886 | + err = -EFAULT; | |
25887 | + AuTraceErr(err); | |
25888 | + } | |
25889 | + break; | |
25890 | + case AUFS_CTL_RDU_INO: | |
25891 | + err = au_rdu_ino(file, &rdu); | |
25892 | + break; | |
25893 | + | |
25894 | + default: | |
25895 | + /* err = -ENOTTY; */ | |
25896 | + err = -EINVAL; | |
25897 | + } | |
25898 | + | |
4f0767ce | 25899 | +out: |
b752ccd1 AM |
25900 | + AuTraceErr(err); |
25901 | + return err; | |
25902 | +} | |
25903 | +#endif | |
7f207e10 AM |
25904 | diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h |
25905 | --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 25906 | +++ linux/fs/aufs/rwsem.h 2015-06-28 17:35:44.351383872 +0200 |
076b876e | 25907 | @@ -0,0 +1,191 @@ |
1facf9fc | 25908 | +/* |
2000de60 | 25909 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 25910 | + * |
25911 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25912 | + * it under the terms of the GNU General Public License as published by | |
25913 | + * the Free Software Foundation; either version 2 of the License, or | |
25914 | + * (at your option) any later version. | |
dece6358 AM |
25915 | + * |
25916 | + * This program is distributed in the hope that it will be useful, | |
25917 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25918 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25919 | + * GNU General Public License for more details. | |
25920 | + * | |
25921 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25922 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25923 | + */ |
25924 | + | |
25925 | +/* | |
25926 | + * simple read-write semaphore wrappers | |
25927 | + */ | |
25928 | + | |
25929 | +#ifndef __AUFS_RWSEM_H__ | |
25930 | +#define __AUFS_RWSEM_H__ | |
25931 | + | |
25932 | +#ifdef __KERNEL__ | |
25933 | + | |
4a4d8108 | 25934 | +#include "debug.h" |
dece6358 AM |
25935 | + |
25936 | +struct au_rwsem { | |
25937 | + struct rw_semaphore rwsem; | |
25938 | +#ifdef CONFIG_AUFS_DEBUG | |
25939 | + /* just for debugging, not almighty counter */ | |
25940 | + atomic_t rcnt, wcnt; | |
25941 | +#endif | |
25942 | +}; | |
25943 | + | |
25944 | +#ifdef CONFIG_AUFS_DEBUG | |
25945 | +#define AuDbgCntInit(rw) do { \ | |
25946 | + atomic_set(&(rw)->rcnt, 0); \ | |
25947 | + atomic_set(&(rw)->wcnt, 0); \ | |
25948 | + smp_mb(); /* atomic set */ \ | |
25949 | +} while (0) | |
25950 | + | |
e49829fe | 25951 | +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt) |
dece6358 | 25952 | +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0) |
e49829fe | 25953 | +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt) |
dece6358 AM |
25954 | +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0) |
25955 | +#else | |
25956 | +#define AuDbgCntInit(rw) do {} while (0) | |
25957 | +#define AuDbgRcntInc(rw) do {} while (0) | |
25958 | +#define AuDbgRcntDec(rw) do {} while (0) | |
25959 | +#define AuDbgWcntInc(rw) do {} while (0) | |
25960 | +#define AuDbgWcntDec(rw) do {} while (0) | |
25961 | +#endif /* CONFIG_AUFS_DEBUG */ | |
25962 | + | |
25963 | +/* to debug easier, do not make them inlined functions */ | |
25964 | +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list)) | |
25965 | +/* rwsem_is_locked() is unusable */ | |
25966 | +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0) | |
25967 | +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0) | |
25968 | +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \ | |
25969 | + && atomic_read(&(rw)->wcnt) <= 0) | |
25970 | +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \ | |
25971 | + || atomic_read(&(rw)->wcnt)) | |
25972 | + | |
e49829fe JR |
25973 | +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key) |
25974 | + | |
dece6358 AM |
25975 | +static inline void au_rw_init(struct au_rwsem *rw) |
25976 | +{ | |
25977 | + AuDbgCntInit(rw); | |
25978 | + init_rwsem(&rw->rwsem); | |
25979 | +} | |
25980 | + | |
25981 | +static inline void au_rw_init_wlock(struct au_rwsem *rw) | |
25982 | +{ | |
25983 | + au_rw_init(rw); | |
25984 | + down_write(&rw->rwsem); | |
25985 | + AuDbgWcntInc(rw); | |
25986 | +} | |
25987 | + | |
25988 | +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw, | |
25989 | + unsigned int lsc) | |
25990 | +{ | |
25991 | + au_rw_init(rw); | |
25992 | + down_write_nested(&rw->rwsem, lsc); | |
25993 | + AuDbgWcntInc(rw); | |
25994 | +} | |
25995 | + | |
25996 | +static inline void au_rw_read_lock(struct au_rwsem *rw) | |
25997 | +{ | |
25998 | + down_read(&rw->rwsem); | |
25999 | + AuDbgRcntInc(rw); | |
26000 | +} | |
26001 | + | |
26002 | +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc) | |
26003 | +{ | |
26004 | + down_read_nested(&rw->rwsem, lsc); | |
26005 | + AuDbgRcntInc(rw); | |
26006 | +} | |
26007 | + | |
26008 | +static inline void au_rw_read_unlock(struct au_rwsem *rw) | |
26009 | +{ | |
26010 | + AuRwMustReadLock(rw); | |
26011 | + AuDbgRcntDec(rw); | |
26012 | + up_read(&rw->rwsem); | |
26013 | +} | |
26014 | + | |
26015 | +static inline void au_rw_dgrade_lock(struct au_rwsem *rw) | |
26016 | +{ | |
26017 | + AuRwMustWriteLock(rw); | |
26018 | + AuDbgRcntInc(rw); | |
26019 | + AuDbgWcntDec(rw); | |
26020 | + downgrade_write(&rw->rwsem); | |
26021 | +} | |
26022 | + | |
26023 | +static inline void au_rw_write_lock(struct au_rwsem *rw) | |
26024 | +{ | |
26025 | + down_write(&rw->rwsem); | |
26026 | + AuDbgWcntInc(rw); | |
26027 | +} | |
26028 | + | |
26029 | +static inline void au_rw_write_lock_nested(struct au_rwsem *rw, | |
26030 | + unsigned int lsc) | |
26031 | +{ | |
26032 | + down_write_nested(&rw->rwsem, lsc); | |
26033 | + AuDbgWcntInc(rw); | |
26034 | +} | |
1facf9fc | 26035 | + |
dece6358 AM |
26036 | +static inline void au_rw_write_unlock(struct au_rwsem *rw) |
26037 | +{ | |
26038 | + AuRwMustWriteLock(rw); | |
26039 | + AuDbgWcntDec(rw); | |
26040 | + up_write(&rw->rwsem); | |
26041 | +} | |
26042 | + | |
26043 | +/* why is not _nested version defined */ | |
26044 | +static inline int au_rw_read_trylock(struct au_rwsem *rw) | |
26045 | +{ | |
076b876e AM |
26046 | + int ret; |
26047 | + | |
26048 | + ret = down_read_trylock(&rw->rwsem); | |
dece6358 AM |
26049 | + if (ret) |
26050 | + AuDbgRcntInc(rw); | |
26051 | + return ret; | |
26052 | +} | |
26053 | + | |
26054 | +static inline int au_rw_write_trylock(struct au_rwsem *rw) | |
26055 | +{ | |
076b876e AM |
26056 | + int ret; |
26057 | + | |
26058 | + ret = down_write_trylock(&rw->rwsem); | |
dece6358 AM |
26059 | + if (ret) |
26060 | + AuDbgWcntInc(rw); | |
26061 | + return ret; | |
26062 | +} | |
26063 | + | |
26064 | +#undef AuDbgCntInit | |
26065 | +#undef AuDbgRcntInc | |
26066 | +#undef AuDbgRcntDec | |
26067 | +#undef AuDbgWcntInc | |
26068 | +#undef AuDbgWcntDec | |
1facf9fc | 26069 | + |
26070 | +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
26071 | +static inline void prefix##_read_lock(param) \ | |
dece6358 | 26072 | +{ au_rw_read_lock(rwsem); } \ |
1facf9fc | 26073 | +static inline void prefix##_write_lock(param) \ |
dece6358 | 26074 | +{ au_rw_write_lock(rwsem); } \ |
1facf9fc | 26075 | +static inline int prefix##_read_trylock(param) \ |
dece6358 | 26076 | +{ return au_rw_read_trylock(rwsem); } \ |
1facf9fc | 26077 | +static inline int prefix##_write_trylock(param) \ |
dece6358 | 26078 | +{ return au_rw_write_trylock(rwsem); } |
1facf9fc | 26079 | +/* why is not _nested version defined */ |
26080 | +/* static inline void prefix##_read_trylock_nested(param, lsc) | |
dece6358 | 26081 | +{ au_rw_read_trylock_nested(rwsem, lsc)); } |
1facf9fc | 26082 | +static inline void prefix##_write_trylock_nestd(param, lsc) |
dece6358 | 26083 | +{ au_rw_write_trylock_nested(rwsem, lsc); } */ |
1facf9fc | 26084 | + |
26085 | +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \ | |
26086 | +static inline void prefix##_read_unlock(param) \ | |
dece6358 | 26087 | +{ au_rw_read_unlock(rwsem); } \ |
1facf9fc | 26088 | +static inline void prefix##_write_unlock(param) \ |
dece6358 | 26089 | +{ au_rw_write_unlock(rwsem); } \ |
1facf9fc | 26090 | +static inline void prefix##_downgrade_lock(param) \ |
dece6358 | 26091 | +{ au_rw_dgrade_lock(rwsem); } |
1facf9fc | 26092 | + |
26093 | +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \ | |
26094 | + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
26095 | + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) | |
26096 | + | |
26097 | +#endif /* __KERNEL__ */ | |
26098 | +#endif /* __AUFS_RWSEM_H__ */ | |
7f207e10 AM |
26099 | diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c |
26100 | --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
26101 | +++ linux/fs/aufs/sbinfo.c 2015-06-28 17:36:09.028407078 +0200 |
26102 | @@ -0,0 +1,356 @@ | |
1facf9fc | 26103 | +/* |
2000de60 | 26104 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 26105 | + * |
26106 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26107 | + * it under the terms of the GNU General Public License as published by | |
26108 | + * the Free Software Foundation; either version 2 of the License, or | |
26109 | + * (at your option) any later version. | |
dece6358 AM |
26110 | + * |
26111 | + * This program is distributed in the hope that it will be useful, | |
26112 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26113 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26114 | + * GNU General Public License for more details. | |
26115 | + * | |
26116 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26117 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26118 | + */ |
26119 | + | |
26120 | +/* | |
26121 | + * superblock private data | |
26122 | + */ | |
26123 | + | |
26124 | +#include "aufs.h" | |
26125 | + | |
26126 | +/* | |
26127 | + * they are necessary regardless sysfs is disabled. | |
26128 | + */ | |
26129 | +void au_si_free(struct kobject *kobj) | |
26130 | +{ | |
86dc4139 | 26131 | + int i; |
1facf9fc | 26132 | + struct au_sbinfo *sbinfo; |
b752ccd1 | 26133 | + char *locked __maybe_unused; /* debug only */ |
1facf9fc | 26134 | + |
26135 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
86dc4139 AM |
26136 | + for (i = 0; i < AuPlink_NHASH; i++) |
26137 | + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head)); | |
e49829fe | 26138 | + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len)); |
1facf9fc | 26139 | + |
e49829fe | 26140 | + au_rw_write_lock(&sbinfo->si_rwsem); |
1facf9fc | 26141 | + au_br_free(sbinfo); |
e49829fe | 26142 | + au_rw_write_unlock(&sbinfo->si_rwsem); |
b752ccd1 AM |
26143 | + |
26144 | + AuDebugOn(radix_tree_gang_lookup | |
26145 | + (&sbinfo->au_si_pid.tree, (void **)&locked, | |
26146 | + /*first_index*/PID_MAX_DEFAULT - 1, | |
26147 | + /*max_items*/sizeof(locked)/sizeof(*locked))); | |
26148 | + | |
1facf9fc | 26149 | + kfree(sbinfo->si_branch); |
b752ccd1 | 26150 | + kfree(sbinfo->au_si_pid.bitmap); |
1facf9fc | 26151 | + mutex_destroy(&sbinfo->si_xib_mtx); |
dece6358 | 26152 | + AuRwDestroy(&sbinfo->si_rwsem); |
1facf9fc | 26153 | + |
26154 | + kfree(sbinfo); | |
26155 | +} | |
26156 | + | |
26157 | +int au_si_alloc(struct super_block *sb) | |
26158 | +{ | |
86dc4139 | 26159 | + int err, i; |
1facf9fc | 26160 | + struct au_sbinfo *sbinfo; |
e49829fe | 26161 | + static struct lock_class_key aufs_si; |
1facf9fc | 26162 | + |
26163 | + err = -ENOMEM; | |
4a4d8108 | 26164 | + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS); |
1facf9fc | 26165 | + if (unlikely(!sbinfo)) |
26166 | + goto out; | |
26167 | + | |
b752ccd1 AM |
26168 | + BUILD_BUG_ON(sizeof(unsigned long) != |
26169 | + sizeof(*sbinfo->au_si_pid.bitmap)); | |
26170 | + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT), | |
26171 | + sizeof(*sbinfo->au_si_pid.bitmap), | |
26172 | + GFP_NOFS); | |
26173 | + if (unlikely(!sbinfo->au_si_pid.bitmap)) | |
26174 | + goto out_sbinfo; | |
26175 | + | |
1facf9fc | 26176 | + /* will be reallocated separately */ |
26177 | + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS); | |
26178 | + if (unlikely(!sbinfo->si_branch)) | |
b752ccd1 | 26179 | + goto out_pidmap; |
1facf9fc | 26180 | + |
1facf9fc | 26181 | + err = sysaufs_si_init(sbinfo); |
26182 | + if (unlikely(err)) | |
26183 | + goto out_br; | |
26184 | + | |
26185 | + au_nwt_init(&sbinfo->si_nowait); | |
dece6358 | 26186 | + au_rw_init_wlock(&sbinfo->si_rwsem); |
e49829fe | 26187 | + au_rw_class(&sbinfo->si_rwsem, &aufs_si); |
b752ccd1 AM |
26188 | + spin_lock_init(&sbinfo->au_si_pid.tree_lock); |
26189 | + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL); | |
26190 | + | |
7f207e10 | 26191 | + atomic_long_set(&sbinfo->si_ninodes, 0); |
7f207e10 AM |
26192 | + atomic_long_set(&sbinfo->si_nfiles, 0); |
26193 | + | |
1facf9fc | 26194 | + sbinfo->si_bend = -1; |
392086de | 26195 | + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2; |
1facf9fc | 26196 | + |
26197 | + sbinfo->si_wbr_copyup = AuWbrCopyup_Def; | |
26198 | + sbinfo->si_wbr_create = AuWbrCreate_Def; | |
4a4d8108 AM |
26199 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup; |
26200 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create; | |
1facf9fc | 26201 | + |
076b876e AM |
26202 | + au_fhsm_init(sbinfo); |
26203 | + | |
e49829fe | 26204 | + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def); |
1facf9fc | 26205 | + |
392086de AM |
26206 | + sbinfo->si_xino_jiffy = jiffies; |
26207 | + sbinfo->si_xino_expire | |
26208 | + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC); | |
1facf9fc | 26209 | + mutex_init(&sbinfo->si_xib_mtx); |
1facf9fc | 26210 | + sbinfo->si_xino_brid = -1; |
26211 | + /* leave si_xib_last_pindex and si_xib_next_bit */ | |
26212 | + | |
b912730e AM |
26213 | + au_sphl_init(&sbinfo->si_aopen); |
26214 | + | |
e49829fe | 26215 | + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC); |
1facf9fc | 26216 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; |
26217 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
26218 | + sbinfo->si_dirwh = AUFS_DIRWH_DEF; | |
26219 | + | |
86dc4139 AM |
26220 | + for (i = 0; i < AuPlink_NHASH; i++) |
26221 | + au_sphl_init(sbinfo->si_plink + i); | |
1facf9fc | 26222 | + init_waitqueue_head(&sbinfo->si_plink_wq); |
4a4d8108 | 26223 | + spin_lock_init(&sbinfo->si_plink_maint_lock); |
1facf9fc | 26224 | + |
523b37e3 AM |
26225 | + au_sphl_init(&sbinfo->si_files); |
26226 | + | |
1facf9fc | 26227 | + /* leave other members for sysaufs and si_mnt. */ |
26228 | + sbinfo->si_sb = sb; | |
26229 | + sb->s_fs_info = sbinfo; | |
b752ccd1 | 26230 | + si_pid_set(sb); |
1facf9fc | 26231 | + return 0; /* success */ |
26232 | + | |
4f0767ce | 26233 | +out_br: |
1facf9fc | 26234 | + kfree(sbinfo->si_branch); |
4f0767ce | 26235 | +out_pidmap: |
b752ccd1 | 26236 | + kfree(sbinfo->au_si_pid.bitmap); |
4f0767ce | 26237 | +out_sbinfo: |
1facf9fc | 26238 | + kfree(sbinfo); |
4f0767ce | 26239 | +out: |
1facf9fc | 26240 | + return err; |
26241 | +} | |
26242 | + | |
26243 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr) | |
26244 | +{ | |
26245 | + int err, sz; | |
26246 | + struct au_branch **brp; | |
26247 | + | |
dece6358 AM |
26248 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
26249 | + | |
1facf9fc | 26250 | + err = -ENOMEM; |
26251 | + sz = sizeof(*brp) * (sbinfo->si_bend + 1); | |
26252 | + if (unlikely(!sz)) | |
26253 | + sz = sizeof(*brp); | |
26254 | + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS); | |
26255 | + if (brp) { | |
26256 | + sbinfo->si_branch = brp; | |
26257 | + err = 0; | |
26258 | + } | |
26259 | + | |
26260 | + return err; | |
26261 | +} | |
26262 | + | |
26263 | +/* ---------------------------------------------------------------------- */ | |
26264 | + | |
26265 | +unsigned int au_sigen_inc(struct super_block *sb) | |
26266 | +{ | |
26267 | + unsigned int gen; | |
5527c038 | 26268 | + struct inode *inode; |
1facf9fc | 26269 | + |
dece6358 AM |
26270 | + SiMustWriteLock(sb); |
26271 | + | |
1facf9fc | 26272 | + gen = ++au_sbi(sb)->si_generation; |
26273 | + au_update_digen(sb->s_root); | |
5527c038 JR |
26274 | + inode = d_inode(sb->s_root); |
26275 | + au_update_iigen(inode, /*half*/0); | |
26276 | + inode->i_version++; | |
1facf9fc | 26277 | + return gen; |
26278 | +} | |
26279 | + | |
26280 | +aufs_bindex_t au_new_br_id(struct super_block *sb) | |
26281 | +{ | |
26282 | + aufs_bindex_t br_id; | |
26283 | + int i; | |
26284 | + struct au_sbinfo *sbinfo; | |
26285 | + | |
dece6358 AM |
26286 | + SiMustWriteLock(sb); |
26287 | + | |
1facf9fc | 26288 | + sbinfo = au_sbi(sb); |
26289 | + for (i = 0; i <= AUFS_BRANCH_MAX; i++) { | |
26290 | + br_id = ++sbinfo->si_last_br_id; | |
7f207e10 | 26291 | + AuDebugOn(br_id < 0); |
1facf9fc | 26292 | + if (br_id && au_br_index(sb, br_id) < 0) |
26293 | + return br_id; | |
26294 | + } | |
26295 | + | |
26296 | + return -1; | |
26297 | +} | |
26298 | + | |
26299 | +/* ---------------------------------------------------------------------- */ | |
26300 | + | |
e49829fe JR |
26301 | +/* it is ok that new 'nwt' tasks are appended while we are sleeping */ |
26302 | +int si_read_lock(struct super_block *sb, int flags) | |
26303 | +{ | |
26304 | + int err; | |
26305 | + | |
26306 | + err = 0; | |
26307 | + if (au_ftest_lock(flags, FLUSH)) | |
26308 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
26309 | + | |
26310 | + si_noflush_read_lock(sb); | |
26311 | + err = au_plink_maint(sb, flags); | |
26312 | + if (unlikely(err)) | |
26313 | + si_read_unlock(sb); | |
26314 | + | |
26315 | + return err; | |
26316 | +} | |
26317 | + | |
26318 | +int si_write_lock(struct super_block *sb, int flags) | |
26319 | +{ | |
26320 | + int err; | |
26321 | + | |
26322 | + if (au_ftest_lock(flags, FLUSH)) | |
26323 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
26324 | + | |
26325 | + si_noflush_write_lock(sb); | |
26326 | + err = au_plink_maint(sb, flags); | |
26327 | + if (unlikely(err)) | |
26328 | + si_write_unlock(sb); | |
26329 | + | |
26330 | + return err; | |
26331 | +} | |
26332 | + | |
1facf9fc | 26333 | +/* dentry and super_block lock. call at entry point */ |
e49829fe | 26334 | +int aufs_read_lock(struct dentry *dentry, int flags) |
1facf9fc | 26335 | +{ |
e49829fe | 26336 | + int err; |
027c5e7a | 26337 | + struct super_block *sb; |
e49829fe | 26338 | + |
027c5e7a AM |
26339 | + sb = dentry->d_sb; |
26340 | + err = si_read_lock(sb, flags); | |
26341 | + if (unlikely(err)) | |
26342 | + goto out; | |
26343 | + | |
26344 | + if (au_ftest_lock(flags, DW)) | |
26345 | + di_write_lock_child(dentry); | |
26346 | + else | |
26347 | + di_read_lock_child(dentry, flags); | |
26348 | + | |
26349 | + if (au_ftest_lock(flags, GEN)) { | |
26350 | + err = au_digen_test(dentry, au_sigen(sb)); | |
26351 | + AuDebugOn(!err && au_dbrange_test(dentry)); | |
26352 | + if (unlikely(err)) | |
26353 | + aufs_read_unlock(dentry, flags); | |
e49829fe JR |
26354 | + } |
26355 | + | |
027c5e7a | 26356 | +out: |
e49829fe | 26357 | + return err; |
1facf9fc | 26358 | +} |
26359 | + | |
26360 | +void aufs_read_unlock(struct dentry *dentry, int flags) | |
26361 | +{ | |
26362 | + if (au_ftest_lock(flags, DW)) | |
26363 | + di_write_unlock(dentry); | |
26364 | + else | |
26365 | + di_read_unlock(dentry, flags); | |
26366 | + si_read_unlock(dentry->d_sb); | |
26367 | +} | |
26368 | + | |
26369 | +void aufs_write_lock(struct dentry *dentry) | |
26370 | +{ | |
e49829fe | 26371 | + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW); |
1facf9fc | 26372 | + di_write_lock_child(dentry); |
26373 | +} | |
26374 | + | |
26375 | +void aufs_write_unlock(struct dentry *dentry) | |
26376 | +{ | |
26377 | + di_write_unlock(dentry); | |
26378 | + si_write_unlock(dentry->d_sb); | |
26379 | +} | |
26380 | + | |
e49829fe | 26381 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags) |
1facf9fc | 26382 | +{ |
e49829fe | 26383 | + int err; |
027c5e7a AM |
26384 | + unsigned int sigen; |
26385 | + struct super_block *sb; | |
e49829fe | 26386 | + |
027c5e7a AM |
26387 | + sb = d1->d_sb; |
26388 | + err = si_read_lock(sb, flags); | |
26389 | + if (unlikely(err)) | |
26390 | + goto out; | |
26391 | + | |
26392 | + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR)); | |
26393 | + | |
26394 | + if (au_ftest_lock(flags, GEN)) { | |
26395 | + sigen = au_sigen(sb); | |
26396 | + err = au_digen_test(d1, sigen); | |
26397 | + AuDebugOn(!err && au_dbrange_test(d1)); | |
26398 | + if (!err) { | |
26399 | + err = au_digen_test(d2, sigen); | |
26400 | + AuDebugOn(!err && au_dbrange_test(d2)); | |
26401 | + } | |
26402 | + if (unlikely(err)) | |
26403 | + aufs_read_and_write_unlock2(d1, d2); | |
26404 | + } | |
26405 | + | |
26406 | +out: | |
e49829fe | 26407 | + return err; |
1facf9fc | 26408 | +} |
26409 | + | |
26410 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2) | |
26411 | +{ | |
26412 | + di_write_unlock2(d1, d2); | |
26413 | + si_read_unlock(d1->d_sb); | |
26414 | +} | |
b752ccd1 AM |
26415 | + |
26416 | +/* ---------------------------------------------------------------------- */ | |
26417 | + | |
26418 | +int si_pid_test_slow(struct super_block *sb) | |
26419 | +{ | |
26420 | + void *p; | |
26421 | + | |
26422 | + rcu_read_lock(); | |
26423 | + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid); | |
26424 | + rcu_read_unlock(); | |
26425 | + | |
027c5e7a | 26426 | + return (long)!!p; |
b752ccd1 AM |
26427 | +} |
26428 | + | |
26429 | +void si_pid_set_slow(struct super_block *sb) | |
26430 | +{ | |
26431 | + int err; | |
26432 | + struct au_sbinfo *sbinfo; | |
26433 | + | |
26434 | + AuDebugOn(si_pid_test_slow(sb)); | |
26435 | + | |
26436 | + sbinfo = au_sbi(sb); | |
26437 | + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL); | |
26438 | + AuDebugOn(err); | |
26439 | + spin_lock(&sbinfo->au_si_pid.tree_lock); | |
26440 | + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid, | |
027c5e7a | 26441 | + /*any valid ptr*/sb); |
b752ccd1 AM |
26442 | + spin_unlock(&sbinfo->au_si_pid.tree_lock); |
26443 | + AuDebugOn(err); | |
26444 | + radix_tree_preload_end(); | |
26445 | +} | |
26446 | + | |
26447 | +void si_pid_clr_slow(struct super_block *sb) | |
26448 | +{ | |
26449 | + void *p; | |
26450 | + struct au_sbinfo *sbinfo; | |
26451 | + | |
26452 | + AuDebugOn(!si_pid_test_slow(sb)); | |
26453 | + | |
26454 | + sbinfo = au_sbi(sb); | |
26455 | + spin_lock(&sbinfo->au_si_pid.tree_lock); | |
26456 | + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid); | |
26457 | + spin_unlock(&sbinfo->au_si_pid.tree_lock); | |
b752ccd1 | 26458 | +} |
7f207e10 AM |
26459 | diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h |
26460 | --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 26461 | +++ linux/fs/aufs/spl.h 2015-06-28 17:35:44.351383872 +0200 |
523b37e3 | 26462 | @@ -0,0 +1,111 @@ |
1facf9fc | 26463 | +/* |
2000de60 | 26464 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 26465 | + * |
26466 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26467 | + * it under the terms of the GNU General Public License as published by | |
26468 | + * the Free Software Foundation; either version 2 of the License, or | |
26469 | + * (at your option) any later version. | |
dece6358 AM |
26470 | + * |
26471 | + * This program is distributed in the hope that it will be useful, | |
26472 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26473 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26474 | + * GNU General Public License for more details. | |
26475 | + * | |
26476 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26477 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26478 | + */ |
26479 | + | |
26480 | +/* | |
26481 | + * simple list protected by a spinlock | |
26482 | + */ | |
26483 | + | |
26484 | +#ifndef __AUFS_SPL_H__ | |
26485 | +#define __AUFS_SPL_H__ | |
26486 | + | |
26487 | +#ifdef __KERNEL__ | |
26488 | + | |
1facf9fc | 26489 | +struct au_splhead { |
26490 | + spinlock_t spin; | |
26491 | + struct list_head head; | |
26492 | +}; | |
26493 | + | |
26494 | +static inline void au_spl_init(struct au_splhead *spl) | |
26495 | +{ | |
26496 | + spin_lock_init(&spl->spin); | |
26497 | + INIT_LIST_HEAD(&spl->head); | |
26498 | +} | |
26499 | + | |
26500 | +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl) | |
26501 | +{ | |
26502 | + spin_lock(&spl->spin); | |
26503 | + list_add(list, &spl->head); | |
26504 | + spin_unlock(&spl->spin); | |
26505 | +} | |
26506 | + | |
26507 | +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl) | |
26508 | +{ | |
26509 | + spin_lock(&spl->spin); | |
26510 | + list_del(list); | |
26511 | + spin_unlock(&spl->spin); | |
26512 | +} | |
26513 | + | |
4a4d8108 AM |
26514 | +static inline void au_spl_del_rcu(struct list_head *list, |
26515 | + struct au_splhead *spl) | |
26516 | +{ | |
26517 | + spin_lock(&spl->spin); | |
26518 | + list_del_rcu(list); | |
26519 | + spin_unlock(&spl->spin); | |
26520 | +} | |
26521 | + | |
86dc4139 AM |
26522 | +/* ---------------------------------------------------------------------- */ |
26523 | + | |
26524 | +struct au_sphlhead { | |
26525 | + spinlock_t spin; | |
26526 | + struct hlist_head head; | |
26527 | +}; | |
26528 | + | |
26529 | +static inline void au_sphl_init(struct au_sphlhead *sphl) | |
26530 | +{ | |
26531 | + spin_lock_init(&sphl->spin); | |
26532 | + INIT_HLIST_HEAD(&sphl->head); | |
26533 | +} | |
26534 | + | |
26535 | +static inline void au_sphl_add(struct hlist_node *hlist, | |
26536 | + struct au_sphlhead *sphl) | |
26537 | +{ | |
26538 | + spin_lock(&sphl->spin); | |
26539 | + hlist_add_head(hlist, &sphl->head); | |
26540 | + spin_unlock(&sphl->spin); | |
26541 | +} | |
26542 | + | |
26543 | +static inline void au_sphl_del(struct hlist_node *hlist, | |
26544 | + struct au_sphlhead *sphl) | |
26545 | +{ | |
26546 | + spin_lock(&sphl->spin); | |
26547 | + hlist_del(hlist); | |
26548 | + spin_unlock(&sphl->spin); | |
26549 | +} | |
26550 | + | |
26551 | +static inline void au_sphl_del_rcu(struct hlist_node *hlist, | |
26552 | + struct au_sphlhead *sphl) | |
26553 | +{ | |
26554 | + spin_lock(&sphl->spin); | |
26555 | + hlist_del_rcu(hlist); | |
26556 | + spin_unlock(&sphl->spin); | |
26557 | +} | |
26558 | + | |
26559 | +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl) | |
26560 | +{ | |
26561 | + unsigned long cnt; | |
26562 | + struct hlist_node *pos; | |
26563 | + | |
26564 | + cnt = 0; | |
26565 | + spin_lock(&sphl->spin); | |
26566 | + hlist_for_each(pos, &sphl->head) | |
26567 | + cnt++; | |
26568 | + spin_unlock(&sphl->spin); | |
26569 | + return cnt; | |
26570 | +} | |
26571 | + | |
1facf9fc | 26572 | +#endif /* __KERNEL__ */ |
26573 | +#endif /* __AUFS_SPL_H__ */ | |
7f207e10 AM |
26574 | diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c |
26575 | --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
26576 | +++ linux/fs/aufs/super.c 2015-06-28 17:36:09.028407078 +0200 |
26577 | @@ -0,0 +1,1004 @@ | |
1facf9fc | 26578 | +/* |
2000de60 | 26579 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 26580 | + * |
26581 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26582 | + * it under the terms of the GNU General Public License as published by | |
26583 | + * the Free Software Foundation; either version 2 of the License, or | |
26584 | + * (at your option) any later version. | |
dece6358 AM |
26585 | + * |
26586 | + * This program is distributed in the hope that it will be useful, | |
26587 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26588 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26589 | + * GNU General Public License for more details. | |
26590 | + * | |
26591 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26592 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26593 | + */ |
26594 | + | |
26595 | +/* | |
26596 | + * mount and super_block operations | |
26597 | + */ | |
26598 | + | |
f6c5ef8b | 26599 | +#include <linux/mm.h> |
1facf9fc | 26600 | +#include <linux/seq_file.h> |
26601 | +#include <linux/statfs.h> | |
7f207e10 | 26602 | +#include <linux/vmalloc.h> |
1facf9fc | 26603 | +#include "aufs.h" |
26604 | + | |
26605 | +/* | |
26606 | + * super_operations | |
26607 | + */ | |
26608 | +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused) | |
26609 | +{ | |
26610 | + struct au_icntnr *c; | |
26611 | + | |
26612 | + c = au_cache_alloc_icntnr(); | |
26613 | + if (c) { | |
027c5e7a | 26614 | + au_icntnr_init(c); |
1facf9fc | 26615 | + c->vfs_inode.i_version = 1; /* sigen(sb); */ |
26616 | + c->iinfo.ii_hinode = NULL; | |
26617 | + return &c->vfs_inode; | |
26618 | + } | |
26619 | + return NULL; | |
26620 | +} | |
26621 | + | |
027c5e7a AM |
26622 | +static void aufs_destroy_inode_cb(struct rcu_head *head) |
26623 | +{ | |
26624 | + struct inode *inode = container_of(head, struct inode, i_rcu); | |
26625 | + | |
b4510431 | 26626 | + INIT_HLIST_HEAD(&inode->i_dentry); |
027c5e7a AM |
26627 | + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode)); |
26628 | +} | |
26629 | + | |
1facf9fc | 26630 | +static void aufs_destroy_inode(struct inode *inode) |
26631 | +{ | |
26632 | + au_iinfo_fin(inode); | |
027c5e7a | 26633 | + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb); |
1facf9fc | 26634 | +} |
26635 | + | |
26636 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino) | |
26637 | +{ | |
26638 | + struct inode *inode; | |
26639 | + int err; | |
26640 | + | |
26641 | + inode = iget_locked(sb, ino); | |
26642 | + if (unlikely(!inode)) { | |
26643 | + inode = ERR_PTR(-ENOMEM); | |
26644 | + goto out; | |
26645 | + } | |
26646 | + if (!(inode->i_state & I_NEW)) | |
26647 | + goto out; | |
26648 | + | |
26649 | + err = au_xigen_new(inode); | |
26650 | + if (!err) | |
26651 | + err = au_iinfo_init(inode); | |
26652 | + if (!err) | |
26653 | + inode->i_version++; | |
26654 | + else { | |
26655 | + iget_failed(inode); | |
26656 | + inode = ERR_PTR(err); | |
26657 | + } | |
26658 | + | |
4f0767ce | 26659 | +out: |
1facf9fc | 26660 | + /* never return NULL */ |
26661 | + AuDebugOn(!inode); | |
26662 | + AuTraceErrPtr(inode); | |
26663 | + return inode; | |
26664 | +} | |
26665 | + | |
26666 | +/* lock free root dinfo */ | |
26667 | +static int au_show_brs(struct seq_file *seq, struct super_block *sb) | |
26668 | +{ | |
26669 | + int err; | |
26670 | + aufs_bindex_t bindex, bend; | |
26671 | + struct path path; | |
4a4d8108 | 26672 | + struct au_hdentry *hdp; |
1facf9fc | 26673 | + struct au_branch *br; |
076b876e | 26674 | + au_br_perm_str_t perm; |
1facf9fc | 26675 | + |
26676 | + err = 0; | |
26677 | + bend = au_sbend(sb); | |
4a4d8108 | 26678 | + hdp = au_di(sb->s_root)->di_hdentry; |
1facf9fc | 26679 | + for (bindex = 0; !err && bindex <= bend; bindex++) { |
26680 | + br = au_sbr(sb, bindex); | |
86dc4139 | 26681 | + path.mnt = au_br_mnt(br); |
4a4d8108 | 26682 | + path.dentry = hdp[bindex].hd_dentry; |
1facf9fc | 26683 | + err = au_seq_path(seq, &path); |
1e00d052 | 26684 | + if (err > 0) { |
076b876e AM |
26685 | + au_optstr_br_perm(&perm, br->br_perm); |
26686 | + err = seq_printf(seq, "=%s", perm.a); | |
26687 | + if (err == -1) | |
26688 | + err = -E2BIG; | |
1e00d052 | 26689 | + } |
1facf9fc | 26690 | + if (!err && bindex != bend) |
26691 | + err = seq_putc(seq, ':'); | |
26692 | + } | |
26693 | + | |
26694 | + return err; | |
26695 | +} | |
26696 | + | |
26697 | +static void au_show_wbr_create(struct seq_file *m, int v, | |
26698 | + struct au_sbinfo *sbinfo) | |
26699 | +{ | |
26700 | + const char *pat; | |
26701 | + | |
dece6358 AM |
26702 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
26703 | + | |
c2b27bf2 | 26704 | + seq_puts(m, ",create="); |
1facf9fc | 26705 | + pat = au_optstr_wbr_create(v); |
26706 | + switch (v) { | |
26707 | + case AuWbrCreate_TDP: | |
26708 | + case AuWbrCreate_RR: | |
26709 | + case AuWbrCreate_MFS: | |
26710 | + case AuWbrCreate_PMFS: | |
c2b27bf2 | 26711 | + seq_puts(m, pat); |
1facf9fc | 26712 | + break; |
26713 | + case AuWbrCreate_MFSV: | |
26714 | + seq_printf(m, /*pat*/"mfs:%lu", | |
e49829fe JR |
26715 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26716 | + / MSEC_PER_SEC); | |
1facf9fc | 26717 | + break; |
26718 | + case AuWbrCreate_PMFSV: | |
26719 | + seq_printf(m, /*pat*/"pmfs:%lu", | |
e49829fe JR |
26720 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26721 | + / MSEC_PER_SEC); | |
1facf9fc | 26722 | + break; |
26723 | + case AuWbrCreate_MFSRR: | |
26724 | + seq_printf(m, /*pat*/"mfsrr:%llu", | |
26725 | + sbinfo->si_wbr_mfs.mfsrr_watermark); | |
26726 | + break; | |
26727 | + case AuWbrCreate_MFSRRV: | |
26728 | + seq_printf(m, /*pat*/"mfsrr:%llu:%lu", | |
26729 | + sbinfo->si_wbr_mfs.mfsrr_watermark, | |
e49829fe JR |
26730 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26731 | + / MSEC_PER_SEC); | |
1facf9fc | 26732 | + break; |
392086de AM |
26733 | + case AuWbrCreate_PMFSRR: |
26734 | + seq_printf(m, /*pat*/"pmfsrr:%llu", | |
26735 | + sbinfo->si_wbr_mfs.mfsrr_watermark); | |
26736 | + break; | |
26737 | + case AuWbrCreate_PMFSRRV: | |
26738 | + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu", | |
26739 | + sbinfo->si_wbr_mfs.mfsrr_watermark, | |
26740 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) | |
26741 | + / MSEC_PER_SEC); | |
26742 | + break; | |
1facf9fc | 26743 | + } |
26744 | +} | |
26745 | + | |
7eafdf33 | 26746 | +static int au_show_xino(struct seq_file *seq, struct super_block *sb) |
1facf9fc | 26747 | +{ |
26748 | +#ifdef CONFIG_SYSFS | |
26749 | + return 0; | |
26750 | +#else | |
26751 | + int err; | |
26752 | + const int len = sizeof(AUFS_XINO_FNAME) - 1; | |
26753 | + aufs_bindex_t bindex, brid; | |
1facf9fc | 26754 | + struct qstr *name; |
26755 | + struct file *f; | |
26756 | + struct dentry *d, *h_root; | |
4a4d8108 | 26757 | + struct au_hdentry *hdp; |
1facf9fc | 26758 | + |
dece6358 AM |
26759 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
26760 | + | |
1facf9fc | 26761 | + err = 0; |
1facf9fc | 26762 | + f = au_sbi(sb)->si_xib; |
26763 | + if (!f) | |
26764 | + goto out; | |
26765 | + | |
26766 | + /* stop printing the default xino path on the first writable branch */ | |
26767 | + h_root = NULL; | |
26768 | + brid = au_xino_brid(sb); | |
26769 | + if (brid >= 0) { | |
26770 | + bindex = au_br_index(sb, brid); | |
4a4d8108 AM |
26771 | + hdp = au_di(sb->s_root)->di_hdentry; |
26772 | + h_root = hdp[0 + bindex].hd_dentry; | |
1facf9fc | 26773 | + } |
2000de60 | 26774 | + d = f->f_path.dentry; |
1facf9fc | 26775 | + name = &d->d_name; |
26776 | + /* safe ->d_parent because the file is unlinked */ | |
26777 | + if (d->d_parent == h_root | |
26778 | + && name->len == len | |
26779 | + && !memcmp(name->name, AUFS_XINO_FNAME, len)) | |
26780 | + goto out; | |
26781 | + | |
26782 | + seq_puts(seq, ",xino="); | |
26783 | + err = au_xino_path(seq, f); | |
26784 | + | |
4f0767ce | 26785 | +out: |
1facf9fc | 26786 | + return err; |
26787 | +#endif | |
26788 | +} | |
26789 | + | |
26790 | +/* seq_file will re-call me in case of too long string */ | |
7eafdf33 | 26791 | +static int aufs_show_options(struct seq_file *m, struct dentry *dentry) |
1facf9fc | 26792 | +{ |
027c5e7a | 26793 | + int err; |
1facf9fc | 26794 | + unsigned int mnt_flags, v; |
26795 | + struct super_block *sb; | |
26796 | + struct au_sbinfo *sbinfo; | |
26797 | + | |
26798 | +#define AuBool(name, str) do { \ | |
26799 | + v = au_opt_test(mnt_flags, name); \ | |
26800 | + if (v != au_opt_test(AuOpt_Def, name)) \ | |
26801 | + seq_printf(m, ",%s" #str, v ? "" : "no"); \ | |
26802 | +} while (0) | |
26803 | + | |
26804 | +#define AuStr(name, str) do { \ | |
26805 | + v = mnt_flags & AuOptMask_##name; \ | |
26806 | + if (v != (AuOpt_Def & AuOptMask_##name)) \ | |
26807 | + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \ | |
26808 | +} while (0) | |
26809 | + | |
26810 | +#define AuUInt(name, str, val) do { \ | |
26811 | + if (val != AUFS_##name##_DEF) \ | |
26812 | + seq_printf(m, "," #str "=%u", val); \ | |
26813 | +} while (0) | |
26814 | + | |
7eafdf33 | 26815 | + sb = dentry->d_sb; |
c1595e42 JR |
26816 | + if (sb->s_flags & MS_POSIXACL) |
26817 | + seq_puts(m, ",acl"); | |
26818 | + | |
26819 | + /* lock free root dinfo */ | |
1facf9fc | 26820 | + si_noflush_read_lock(sb); |
26821 | + sbinfo = au_sbi(sb); | |
26822 | + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo)); | |
26823 | + | |
26824 | + mnt_flags = au_mntflags(sb); | |
26825 | + if (au_opt_test(mnt_flags, XINO)) { | |
7eafdf33 | 26826 | + err = au_show_xino(m, sb); |
1facf9fc | 26827 | + if (unlikely(err)) |
26828 | + goto out; | |
26829 | + } else | |
26830 | + seq_puts(m, ",noxino"); | |
26831 | + | |
26832 | + AuBool(TRUNC_XINO, trunc_xino); | |
26833 | + AuStr(UDBA, udba); | |
dece6358 | 26834 | + AuBool(SHWH, shwh); |
1facf9fc | 26835 | + AuBool(PLINK, plink); |
4a4d8108 | 26836 | + AuBool(DIO, dio); |
076b876e | 26837 | + AuBool(DIRPERM1, dirperm1); |
1facf9fc | 26838 | + |
26839 | + v = sbinfo->si_wbr_create; | |
26840 | + if (v != AuWbrCreate_Def) | |
26841 | + au_show_wbr_create(m, v, sbinfo); | |
26842 | + | |
26843 | + v = sbinfo->si_wbr_copyup; | |
26844 | + if (v != AuWbrCopyup_Def) | |
26845 | + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v)); | |
26846 | + | |
26847 | + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ); | |
26848 | + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ)) | |
26849 | + seq_printf(m, ",diropq=%c", v ? 'a' : 'w'); | |
26850 | + | |
26851 | + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh); | |
26852 | + | |
027c5e7a AM |
26853 | + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC; |
26854 | + AuUInt(RDCACHE, rdcache, v); | |
1facf9fc | 26855 | + |
26856 | + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk); | |
26857 | + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash); | |
26858 | + | |
076b876e AM |
26859 | + au_fhsm_show(m, sbinfo); |
26860 | + | |
1facf9fc | 26861 | + AuBool(SUM, sum); |
26862 | + /* AuBool(SUM_W, wsum); */ | |
26863 | + AuBool(WARN_PERM, warn_perm); | |
26864 | + AuBool(VERBOSE, verbose); | |
26865 | + | |
4f0767ce | 26866 | +out: |
1facf9fc | 26867 | + /* be sure to print "br:" last */ |
26868 | + if (!sysaufs_brs) { | |
26869 | + seq_puts(m, ",br:"); | |
26870 | + au_show_brs(m, sb); | |
26871 | + } | |
26872 | + si_read_unlock(sb); | |
26873 | + return 0; | |
26874 | + | |
1facf9fc | 26875 | +#undef AuBool |
26876 | +#undef AuStr | |
4a4d8108 | 26877 | +#undef AuUInt |
1facf9fc | 26878 | +} |
26879 | + | |
26880 | +/* ---------------------------------------------------------------------- */ | |
26881 | + | |
26882 | +/* sum mode which returns the summation for statfs(2) */ | |
26883 | + | |
26884 | +static u64 au_add_till_max(u64 a, u64 b) | |
26885 | +{ | |
26886 | + u64 old; | |
26887 | + | |
26888 | + old = a; | |
26889 | + a += b; | |
92d182d2 AM |
26890 | + if (old <= a) |
26891 | + return a; | |
26892 | + return ULLONG_MAX; | |
26893 | +} | |
26894 | + | |
26895 | +static u64 au_mul_till_max(u64 a, long mul) | |
26896 | +{ | |
26897 | + u64 old; | |
26898 | + | |
26899 | + old = a; | |
26900 | + a *= mul; | |
26901 | + if (old <= a) | |
1facf9fc | 26902 | + return a; |
26903 | + return ULLONG_MAX; | |
26904 | +} | |
26905 | + | |
26906 | +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf) | |
26907 | +{ | |
26908 | + int err; | |
92d182d2 | 26909 | + long bsize, factor; |
1facf9fc | 26910 | + u64 blocks, bfree, bavail, files, ffree; |
26911 | + aufs_bindex_t bend, bindex, i; | |
26912 | + unsigned char shared; | |
7f207e10 | 26913 | + struct path h_path; |
1facf9fc | 26914 | + struct super_block *h_sb; |
26915 | + | |
92d182d2 AM |
26916 | + err = 0; |
26917 | + bsize = LONG_MAX; | |
26918 | + files = 0; | |
26919 | + ffree = 0; | |
1facf9fc | 26920 | + blocks = 0; |
26921 | + bfree = 0; | |
26922 | + bavail = 0; | |
1facf9fc | 26923 | + bend = au_sbend(sb); |
92d182d2 | 26924 | + for (bindex = 0; bindex <= bend; bindex++) { |
7f207e10 AM |
26925 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
26926 | + h_sb = h_path.mnt->mnt_sb; | |
1facf9fc | 26927 | + shared = 0; |
92d182d2 | 26928 | + for (i = 0; !shared && i < bindex; i++) |
1facf9fc | 26929 | + shared = (au_sbr_sb(sb, i) == h_sb); |
26930 | + if (shared) | |
26931 | + continue; | |
26932 | + | |
26933 | + /* sb->s_root for NFS is unreliable */ | |
7f207e10 AM |
26934 | + h_path.dentry = h_path.mnt->mnt_root; |
26935 | + err = vfs_statfs(&h_path, buf); | |
1facf9fc | 26936 | + if (unlikely(err)) |
26937 | + goto out; | |
26938 | + | |
92d182d2 AM |
26939 | + if (bsize > buf->f_bsize) { |
26940 | + /* | |
26941 | + * we will reduce bsize, so we have to expand blocks | |
26942 | + * etc. to match them again | |
26943 | + */ | |
26944 | + factor = (bsize / buf->f_bsize); | |
26945 | + blocks = au_mul_till_max(blocks, factor); | |
26946 | + bfree = au_mul_till_max(bfree, factor); | |
26947 | + bavail = au_mul_till_max(bavail, factor); | |
26948 | + bsize = buf->f_bsize; | |
26949 | + } | |
26950 | + | |
26951 | + factor = (buf->f_bsize / bsize); | |
26952 | + blocks = au_add_till_max(blocks, | |
26953 | + au_mul_till_max(buf->f_blocks, factor)); | |
26954 | + bfree = au_add_till_max(bfree, | |
26955 | + au_mul_till_max(buf->f_bfree, factor)); | |
26956 | + bavail = au_add_till_max(bavail, | |
26957 | + au_mul_till_max(buf->f_bavail, factor)); | |
1facf9fc | 26958 | + files = au_add_till_max(files, buf->f_files); |
26959 | + ffree = au_add_till_max(ffree, buf->f_ffree); | |
26960 | + } | |
26961 | + | |
92d182d2 | 26962 | + buf->f_bsize = bsize; |
1facf9fc | 26963 | + buf->f_blocks = blocks; |
26964 | + buf->f_bfree = bfree; | |
26965 | + buf->f_bavail = bavail; | |
26966 | + buf->f_files = files; | |
26967 | + buf->f_ffree = ffree; | |
92d182d2 | 26968 | + buf->f_frsize = 0; |
1facf9fc | 26969 | + |
4f0767ce | 26970 | +out: |
1facf9fc | 26971 | + return err; |
26972 | +} | |
26973 | + | |
26974 | +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf) | |
26975 | +{ | |
26976 | + int err; | |
7f207e10 | 26977 | + struct path h_path; |
1facf9fc | 26978 | + struct super_block *sb; |
26979 | + | |
26980 | + /* lock free root dinfo */ | |
26981 | + sb = dentry->d_sb; | |
26982 | + si_noflush_read_lock(sb); | |
7f207e10 | 26983 | + if (!au_opt_test(au_mntflags(sb), SUM)) { |
1facf9fc | 26984 | + /* sb->s_root for NFS is unreliable */ |
7f207e10 AM |
26985 | + h_path.mnt = au_sbr_mnt(sb, 0); |
26986 | + h_path.dentry = h_path.mnt->mnt_root; | |
26987 | + err = vfs_statfs(&h_path, buf); | |
26988 | + } else | |
1facf9fc | 26989 | + err = au_statfs_sum(sb, buf); |
26990 | + si_read_unlock(sb); | |
26991 | + | |
26992 | + if (!err) { | |
26993 | + buf->f_type = AUFS_SUPER_MAGIC; | |
4a4d8108 | 26994 | + buf->f_namelen = AUFS_MAX_NAMELEN; |
1facf9fc | 26995 | + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid)); |
26996 | + } | |
26997 | + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */ | |
26998 | + | |
26999 | + return err; | |
27000 | +} | |
27001 | + | |
27002 | +/* ---------------------------------------------------------------------- */ | |
27003 | + | |
537831f9 AM |
27004 | +static int aufs_sync_fs(struct super_block *sb, int wait) |
27005 | +{ | |
27006 | + int err, e; | |
27007 | + aufs_bindex_t bend, bindex; | |
27008 | + struct au_branch *br; | |
27009 | + struct super_block *h_sb; | |
27010 | + | |
27011 | + err = 0; | |
27012 | + si_noflush_read_lock(sb); | |
27013 | + bend = au_sbend(sb); | |
27014 | + for (bindex = 0; bindex <= bend; bindex++) { | |
27015 | + br = au_sbr(sb, bindex); | |
27016 | + if (!au_br_writable(br->br_perm)) | |
27017 | + continue; | |
27018 | + | |
27019 | + h_sb = au_sbr_sb(sb, bindex); | |
27020 | + if (h_sb->s_op->sync_fs) { | |
27021 | + e = h_sb->s_op->sync_fs(h_sb, wait); | |
27022 | + if (unlikely(e && !err)) | |
27023 | + err = e; | |
27024 | + /* go on even if an error happens */ | |
27025 | + } | |
27026 | + } | |
27027 | + si_read_unlock(sb); | |
27028 | + | |
27029 | + return err; | |
27030 | +} | |
27031 | + | |
27032 | +/* ---------------------------------------------------------------------- */ | |
27033 | + | |
1facf9fc | 27034 | +/* final actions when unmounting a file system */ |
27035 | +static void aufs_put_super(struct super_block *sb) | |
27036 | +{ | |
27037 | + struct au_sbinfo *sbinfo; | |
27038 | + | |
27039 | + sbinfo = au_sbi(sb); | |
27040 | + if (!sbinfo) | |
27041 | + return; | |
27042 | + | |
1facf9fc | 27043 | + dbgaufs_si_fin(sbinfo); |
27044 | + kobject_put(&sbinfo->si_kobj); | |
27045 | +} | |
27046 | + | |
27047 | +/* ---------------------------------------------------------------------- */ | |
27048 | + | |
7f207e10 AM |
27049 | +void au_array_free(void *array) |
27050 | +{ | |
27051 | + if (array) { | |
27052 | + if (!is_vmalloc_addr(array)) | |
27053 | + kfree(array); | |
27054 | + else | |
27055 | + vfree(array); | |
27056 | + } | |
27057 | +} | |
27058 | + | |
27059 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg) | |
27060 | +{ | |
27061 | + void *array; | |
076b876e | 27062 | + unsigned long long n, sz; |
7f207e10 AM |
27063 | + |
27064 | + array = NULL; | |
27065 | + n = 0; | |
27066 | + if (!*hint) | |
27067 | + goto out; | |
27068 | + | |
27069 | + if (*hint > ULLONG_MAX / sizeof(array)) { | |
27070 | + array = ERR_PTR(-EMFILE); | |
27071 | + pr_err("hint %llu\n", *hint); | |
27072 | + goto out; | |
27073 | + } | |
27074 | + | |
076b876e AM |
27075 | + sz = sizeof(array) * *hint; |
27076 | + array = kzalloc(sz, GFP_NOFS); | |
7f207e10 | 27077 | + if (unlikely(!array)) |
076b876e | 27078 | + array = vzalloc(sz); |
7f207e10 AM |
27079 | + if (unlikely(!array)) { |
27080 | + array = ERR_PTR(-ENOMEM); | |
27081 | + goto out; | |
27082 | + } | |
27083 | + | |
27084 | + n = cb(array, *hint, arg); | |
27085 | + AuDebugOn(n > *hint); | |
27086 | + | |
27087 | +out: | |
27088 | + *hint = n; | |
27089 | + return array; | |
27090 | +} | |
27091 | + | |
27092 | +static unsigned long long au_iarray_cb(void *a, | |
27093 | + unsigned long long max __maybe_unused, | |
27094 | + void *arg) | |
27095 | +{ | |
27096 | + unsigned long long n; | |
27097 | + struct inode **p, *inode; | |
27098 | + struct list_head *head; | |
27099 | + | |
27100 | + n = 0; | |
27101 | + p = a; | |
27102 | + head = arg; | |
2cbb1c4b | 27103 | + spin_lock(&inode_sb_list_lock); |
7f207e10 AM |
27104 | + list_for_each_entry(inode, head, i_sb_list) { |
27105 | + if (!is_bad_inode(inode) | |
27106 | + && au_ii(inode)->ii_bstart >= 0) { | |
2cbb1c4b JR |
27107 | + spin_lock(&inode->i_lock); |
27108 | + if (atomic_read(&inode->i_count)) { | |
27109 | + au_igrab(inode); | |
27110 | + *p++ = inode; | |
27111 | + n++; | |
27112 | + AuDebugOn(n > max); | |
27113 | + } | |
27114 | + spin_unlock(&inode->i_lock); | |
7f207e10 AM |
27115 | + } |
27116 | + } | |
2cbb1c4b | 27117 | + spin_unlock(&inode_sb_list_lock); |
7f207e10 AM |
27118 | + |
27119 | + return n; | |
27120 | +} | |
27121 | + | |
27122 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max) | |
27123 | +{ | |
27124 | + *max = atomic_long_read(&au_sbi(sb)->si_ninodes); | |
27125 | + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes); | |
27126 | +} | |
27127 | + | |
27128 | +void au_iarray_free(struct inode **a, unsigned long long max) | |
27129 | +{ | |
27130 | + unsigned long long ull; | |
27131 | + | |
27132 | + for (ull = 0; ull < max; ull++) | |
27133 | + iput(a[ull]); | |
27134 | + au_array_free(a); | |
27135 | +} | |
27136 | + | |
27137 | +/* ---------------------------------------------------------------------- */ | |
27138 | + | |
1facf9fc | 27139 | +/* |
27140 | + * refresh dentry and inode at remount time. | |
27141 | + */ | |
027c5e7a AM |
27142 | +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */ |
27143 | +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags, | |
27144 | + struct dentry *parent) | |
1facf9fc | 27145 | +{ |
27146 | + int err; | |
1facf9fc | 27147 | + |
27148 | + di_write_lock_child(dentry); | |
1facf9fc | 27149 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a AM |
27150 | + err = au_refresh_dentry(dentry, parent); |
27151 | + if (!err && dir_flags) | |
5527c038 | 27152 | + au_hn_reset(d_inode(dentry), dir_flags); |
1facf9fc | 27153 | + di_read_unlock(parent, AuLock_IR); |
1facf9fc | 27154 | + di_write_unlock(dentry); |
27155 | + | |
27156 | + return err; | |
27157 | +} | |
27158 | + | |
027c5e7a AM |
27159 | +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen, |
27160 | + struct au_sbinfo *sbinfo, | |
27161 | + const unsigned int dir_flags) | |
1facf9fc | 27162 | +{ |
027c5e7a AM |
27163 | + int err; |
27164 | + struct dentry *parent; | |
027c5e7a AM |
27165 | + |
27166 | + err = 0; | |
27167 | + parent = dget_parent(dentry); | |
27168 | + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) { | |
5527c038 JR |
27169 | + if (d_really_is_positive(dentry)) { |
27170 | + if (!d_is_dir(dentry)) | |
027c5e7a AM |
27171 | + err = au_do_refresh(dentry, /*dir_flags*/0, |
27172 | + parent); | |
27173 | + else { | |
27174 | + err = au_do_refresh(dentry, dir_flags, parent); | |
27175 | + if (unlikely(err)) | |
27176 | + au_fset_si(sbinfo, FAILED_REFRESH_DIR); | |
27177 | + } | |
27178 | + } else | |
27179 | + err = au_do_refresh(dentry, /*dir_flags*/0, parent); | |
27180 | + AuDbgDentry(dentry); | |
27181 | + } | |
27182 | + dput(parent); | |
27183 | + | |
27184 | + AuTraceErr(err); | |
27185 | + return err; | |
1facf9fc | 27186 | +} |
27187 | + | |
027c5e7a | 27188 | +static int au_refresh_d(struct super_block *sb) |
1facf9fc | 27189 | +{ |
27190 | + int err, i, j, ndentry, e; | |
027c5e7a | 27191 | + unsigned int sigen; |
1facf9fc | 27192 | + struct au_dcsub_pages dpages; |
27193 | + struct au_dpage *dpage; | |
027c5e7a AM |
27194 | + struct dentry **dentries, *d; |
27195 | + struct au_sbinfo *sbinfo; | |
27196 | + struct dentry *root = sb->s_root; | |
5527c038 | 27197 | + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1); |
1facf9fc | 27198 | + |
027c5e7a AM |
27199 | + err = au_dpages_init(&dpages, GFP_NOFS); |
27200 | + if (unlikely(err)) | |
1facf9fc | 27201 | + goto out; |
027c5e7a AM |
27202 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); |
27203 | + if (unlikely(err)) | |
1facf9fc | 27204 | + goto out_dpages; |
1facf9fc | 27205 | + |
027c5e7a AM |
27206 | + sigen = au_sigen(sb); |
27207 | + sbinfo = au_sbi(sb); | |
27208 | + for (i = 0; i < dpages.ndpage; i++) { | |
1facf9fc | 27209 | + dpage = dpages.dpages + i; |
27210 | + dentries = dpage->dentries; | |
27211 | + ndentry = dpage->ndentry; | |
027c5e7a | 27212 | + for (j = 0; j < ndentry; j++) { |
1facf9fc | 27213 | + d = dentries[j]; |
027c5e7a AM |
27214 | + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags); |
27215 | + if (unlikely(e && !err)) | |
27216 | + err = e; | |
27217 | + /* go on even err */ | |
1facf9fc | 27218 | + } |
27219 | + } | |
27220 | + | |
4f0767ce | 27221 | +out_dpages: |
1facf9fc | 27222 | + au_dpages_free(&dpages); |
4f0767ce | 27223 | +out: |
1facf9fc | 27224 | + return err; |
27225 | +} | |
27226 | + | |
027c5e7a | 27227 | +static int au_refresh_i(struct super_block *sb) |
1facf9fc | 27228 | +{ |
027c5e7a AM |
27229 | + int err, e; |
27230 | + unsigned int sigen; | |
27231 | + unsigned long long max, ull; | |
27232 | + struct inode *inode, **array; | |
1facf9fc | 27233 | + |
027c5e7a AM |
27234 | + array = au_iarray_alloc(sb, &max); |
27235 | + err = PTR_ERR(array); | |
27236 | + if (IS_ERR(array)) | |
27237 | + goto out; | |
1facf9fc | 27238 | + |
27239 | + err = 0; | |
027c5e7a AM |
27240 | + sigen = au_sigen(sb); |
27241 | + for (ull = 0; ull < max; ull++) { | |
27242 | + inode = array[ull]; | |
076b876e AM |
27243 | + if (unlikely(!inode)) |
27244 | + break; | |
537831f9 | 27245 | + if (au_iigen(inode, NULL) != sigen) { |
1facf9fc | 27246 | + ii_write_lock_child(inode); |
027c5e7a | 27247 | + e = au_refresh_hinode_self(inode); |
1facf9fc | 27248 | + ii_write_unlock(inode); |
27249 | + if (unlikely(e)) { | |
027c5e7a | 27250 | + pr_err("error %d, i%lu\n", e, inode->i_ino); |
1facf9fc | 27251 | + if (!err) |
27252 | + err = e; | |
27253 | + /* go on even if err */ | |
27254 | + } | |
27255 | + } | |
1facf9fc | 27256 | + } |
27257 | + | |
027c5e7a | 27258 | + au_iarray_free(array, max); |
1facf9fc | 27259 | + |
4f0767ce | 27260 | +out: |
1facf9fc | 27261 | + return err; |
27262 | +} | |
27263 | + | |
027c5e7a | 27264 | +static void au_remount_refresh(struct super_block *sb) |
1facf9fc | 27265 | +{ |
027c5e7a AM |
27266 | + int err, e; |
27267 | + unsigned int udba; | |
27268 | + aufs_bindex_t bindex, bend; | |
1facf9fc | 27269 | + struct dentry *root; |
27270 | + struct inode *inode; | |
027c5e7a | 27271 | + struct au_branch *br; |
1facf9fc | 27272 | + |
27273 | + au_sigen_inc(sb); | |
027c5e7a | 27274 | + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR); |
1facf9fc | 27275 | + |
27276 | + root = sb->s_root; | |
27277 | + DiMustNoWaiters(root); | |
5527c038 | 27278 | + inode = d_inode(root); |
1facf9fc | 27279 | + IiMustNoWaiters(inode); |
1facf9fc | 27280 | + |
027c5e7a AM |
27281 | + udba = au_opt_udba(sb); |
27282 | + bend = au_sbend(sb); | |
27283 | + for (bindex = 0; bindex <= bend; bindex++) { | |
27284 | + br = au_sbr(sb, bindex); | |
27285 | + err = au_hnotify_reset_br(udba, br, br->br_perm); | |
1facf9fc | 27286 | + if (unlikely(err)) |
027c5e7a AM |
27287 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", |
27288 | + bindex, err); | |
27289 | + /* go on even if err */ | |
1facf9fc | 27290 | + } |
027c5e7a | 27291 | + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1)); |
1facf9fc | 27292 | + |
027c5e7a AM |
27293 | + di_write_unlock(root); |
27294 | + err = au_refresh_d(sb); | |
27295 | + e = au_refresh_i(sb); | |
27296 | + if (unlikely(e && !err)) | |
27297 | + err = e; | |
1facf9fc | 27298 | + /* aufs_write_lock() calls ..._child() */ |
27299 | + di_write_lock_child(root); | |
027c5e7a AM |
27300 | + |
27301 | + au_cpup_attr_all(inode, /*force*/1); | |
27302 | + | |
27303 | + if (unlikely(err)) | |
27304 | + AuIOErr("refresh failed, ignored, %d\n", err); | |
1facf9fc | 27305 | +} |
27306 | + | |
27307 | +/* stop extra interpretation of errno in mount(8), and strange error messages */ | |
27308 | +static int cvt_err(int err) | |
27309 | +{ | |
27310 | + AuTraceErr(err); | |
27311 | + | |
27312 | + switch (err) { | |
27313 | + case -ENOENT: | |
27314 | + case -ENOTDIR: | |
27315 | + case -EEXIST: | |
27316 | + case -EIO: | |
27317 | + err = -EINVAL; | |
27318 | + } | |
27319 | + return err; | |
27320 | +} | |
27321 | + | |
27322 | +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data) | |
27323 | +{ | |
4a4d8108 AM |
27324 | + int err, do_dx; |
27325 | + unsigned int mntflags; | |
1facf9fc | 27326 | + struct au_opts opts; |
27327 | + struct dentry *root; | |
27328 | + struct inode *inode; | |
27329 | + struct au_sbinfo *sbinfo; | |
27330 | + | |
27331 | + err = 0; | |
27332 | + root = sb->s_root; | |
27333 | + if (!data || !*data) { | |
e49829fe JR |
27334 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
27335 | + if (!err) { | |
27336 | + di_write_lock_child(root); | |
27337 | + err = au_opts_verify(sb, *flags, /*pending*/0); | |
27338 | + aufs_write_unlock(root); | |
27339 | + } | |
1facf9fc | 27340 | + goto out; |
27341 | + } | |
27342 | + | |
27343 | + err = -ENOMEM; | |
27344 | + memset(&opts, 0, sizeof(opts)); | |
27345 | + opts.opt = (void *)__get_free_page(GFP_NOFS); | |
27346 | + if (unlikely(!opts.opt)) | |
27347 | + goto out; | |
27348 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
27349 | + opts.flags = AuOpts_REMOUNT; | |
27350 | + opts.sb_flags = *flags; | |
27351 | + | |
27352 | + /* parse it before aufs lock */ | |
27353 | + err = au_opts_parse(sb, data, &opts); | |
27354 | + if (unlikely(err)) | |
27355 | + goto out_opts; | |
27356 | + | |
27357 | + sbinfo = au_sbi(sb); | |
5527c038 | 27358 | + inode = d_inode(root); |
1facf9fc | 27359 | + mutex_lock(&inode->i_mutex); |
e49829fe JR |
27360 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
27361 | + if (unlikely(err)) | |
27362 | + goto out_mtx; | |
27363 | + di_write_lock_child(root); | |
1facf9fc | 27364 | + |
27365 | + /* au_opts_remount() may return an error */ | |
27366 | + err = au_opts_remount(sb, &opts); | |
27367 | + au_opts_free(&opts); | |
27368 | + | |
027c5e7a AM |
27369 | + if (au_ftest_opts(opts.flags, REFRESH)) |
27370 | + au_remount_refresh(sb); | |
1facf9fc | 27371 | + |
4a4d8108 AM |
27372 | + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) { |
27373 | + mntflags = au_mntflags(sb); | |
27374 | + do_dx = !!au_opt_test(mntflags, DIO); | |
27375 | + au_dy_arefresh(do_dx); | |
27376 | + } | |
27377 | + | |
076b876e | 27378 | + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */ |
1facf9fc | 27379 | + aufs_write_unlock(root); |
953406b4 | 27380 | + |
e49829fe JR |
27381 | +out_mtx: |
27382 | + mutex_unlock(&inode->i_mutex); | |
4f0767ce | 27383 | +out_opts: |
1facf9fc | 27384 | + free_page((unsigned long)opts.opt); |
4f0767ce | 27385 | +out: |
1facf9fc | 27386 | + err = cvt_err(err); |
27387 | + AuTraceErr(err); | |
27388 | + return err; | |
27389 | +} | |
27390 | + | |
4a4d8108 | 27391 | +static const struct super_operations aufs_sop = { |
1facf9fc | 27392 | + .alloc_inode = aufs_alloc_inode, |
27393 | + .destroy_inode = aufs_destroy_inode, | |
b752ccd1 | 27394 | + /* always deleting, no clearing */ |
1facf9fc | 27395 | + .drop_inode = generic_delete_inode, |
27396 | + .show_options = aufs_show_options, | |
27397 | + .statfs = aufs_statfs, | |
27398 | + .put_super = aufs_put_super, | |
537831f9 | 27399 | + .sync_fs = aufs_sync_fs, |
1facf9fc | 27400 | + .remount_fs = aufs_remount_fs |
27401 | +}; | |
27402 | + | |
27403 | +/* ---------------------------------------------------------------------- */ | |
27404 | + | |
27405 | +static int alloc_root(struct super_block *sb) | |
27406 | +{ | |
27407 | + int err; | |
27408 | + struct inode *inode; | |
27409 | + struct dentry *root; | |
27410 | + | |
27411 | + err = -ENOMEM; | |
27412 | + inode = au_iget_locked(sb, AUFS_ROOT_INO); | |
27413 | + err = PTR_ERR(inode); | |
27414 | + if (IS_ERR(inode)) | |
27415 | + goto out; | |
27416 | + | |
27417 | + inode->i_op = &aufs_dir_iop; | |
27418 | + inode->i_fop = &aufs_dir_fop; | |
27419 | + inode->i_mode = S_IFDIR; | |
9dbd164d | 27420 | + set_nlink(inode, 2); |
1facf9fc | 27421 | + unlock_new_inode(inode); |
27422 | + | |
92d182d2 | 27423 | + root = d_make_root(inode); |
1facf9fc | 27424 | + if (unlikely(!root)) |
92d182d2 | 27425 | + goto out; |
1facf9fc | 27426 | + err = PTR_ERR(root); |
27427 | + if (IS_ERR(root)) | |
92d182d2 | 27428 | + goto out; |
1facf9fc | 27429 | + |
4a4d8108 | 27430 | + err = au_di_init(root); |
1facf9fc | 27431 | + if (!err) { |
27432 | + sb->s_root = root; | |
27433 | + return 0; /* success */ | |
27434 | + } | |
27435 | + dput(root); | |
1facf9fc | 27436 | + |
4f0767ce | 27437 | +out: |
1facf9fc | 27438 | + return err; |
1facf9fc | 27439 | +} |
27440 | + | |
27441 | +static int aufs_fill_super(struct super_block *sb, void *raw_data, | |
27442 | + int silent __maybe_unused) | |
27443 | +{ | |
27444 | + int err; | |
27445 | + struct au_opts opts; | |
27446 | + struct dentry *root; | |
27447 | + struct inode *inode; | |
27448 | + char *arg = raw_data; | |
27449 | + | |
27450 | + if (unlikely(!arg || !*arg)) { | |
27451 | + err = -EINVAL; | |
4a4d8108 | 27452 | + pr_err("no arg\n"); |
1facf9fc | 27453 | + goto out; |
27454 | + } | |
27455 | + | |
27456 | + err = -ENOMEM; | |
27457 | + memset(&opts, 0, sizeof(opts)); | |
27458 | + opts.opt = (void *)__get_free_page(GFP_NOFS); | |
27459 | + if (unlikely(!opts.opt)) | |
27460 | + goto out; | |
27461 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
27462 | + opts.sb_flags = sb->s_flags; | |
27463 | + | |
27464 | + err = au_si_alloc(sb); | |
27465 | + if (unlikely(err)) | |
27466 | + goto out_opts; | |
27467 | + | |
27468 | + /* all timestamps always follow the ones on the branch */ | |
27469 | + sb->s_flags |= MS_NOATIME | MS_NODIRATIME; | |
27470 | + sb->s_op = &aufs_sop; | |
027c5e7a | 27471 | + sb->s_d_op = &aufs_dop; |
1facf9fc | 27472 | + sb->s_magic = AUFS_SUPER_MAGIC; |
27473 | + sb->s_maxbytes = 0; | |
c1595e42 | 27474 | + sb->s_stack_depth = 1; |
1facf9fc | 27475 | + au_export_init(sb); |
c1595e42 | 27476 | + /* au_xattr_init(sb); */ |
1facf9fc | 27477 | + |
27478 | + err = alloc_root(sb); | |
27479 | + if (unlikely(err)) { | |
27480 | + si_write_unlock(sb); | |
27481 | + goto out_info; | |
27482 | + } | |
27483 | + root = sb->s_root; | |
5527c038 | 27484 | + inode = d_inode(root); |
1facf9fc | 27485 | + |
27486 | + /* | |
27487 | + * actually we can parse options regardless aufs lock here. | |
27488 | + * but at remount time, parsing must be done before aufs lock. | |
27489 | + * so we follow the same rule. | |
27490 | + */ | |
27491 | + ii_write_lock_parent(inode); | |
27492 | + aufs_write_unlock(root); | |
27493 | + err = au_opts_parse(sb, arg, &opts); | |
27494 | + if (unlikely(err)) | |
27495 | + goto out_root; | |
27496 | + | |
27497 | + /* lock vfs_inode first, then aufs. */ | |
27498 | + mutex_lock(&inode->i_mutex); | |
1facf9fc | 27499 | + aufs_write_lock(root); |
27500 | + err = au_opts_mount(sb, &opts); | |
27501 | + au_opts_free(&opts); | |
1facf9fc | 27502 | + aufs_write_unlock(root); |
27503 | + mutex_unlock(&inode->i_mutex); | |
4a4d8108 AM |
27504 | + if (!err) |
27505 | + goto out_opts; /* success */ | |
1facf9fc | 27506 | + |
4f0767ce | 27507 | +out_root: |
1facf9fc | 27508 | + dput(root); |
27509 | + sb->s_root = NULL; | |
4f0767ce | 27510 | +out_info: |
2cbb1c4b | 27511 | + dbgaufs_si_fin(au_sbi(sb)); |
1facf9fc | 27512 | + kobject_put(&au_sbi(sb)->si_kobj); |
27513 | + sb->s_fs_info = NULL; | |
4f0767ce | 27514 | +out_opts: |
1facf9fc | 27515 | + free_page((unsigned long)opts.opt); |
4f0767ce | 27516 | +out: |
1facf9fc | 27517 | + AuTraceErr(err); |
27518 | + err = cvt_err(err); | |
27519 | + AuTraceErr(err); | |
27520 | + return err; | |
27521 | +} | |
27522 | + | |
27523 | +/* ---------------------------------------------------------------------- */ | |
27524 | + | |
027c5e7a AM |
27525 | +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags, |
27526 | + const char *dev_name __maybe_unused, | |
27527 | + void *raw_data) | |
1facf9fc | 27528 | +{ |
027c5e7a | 27529 | + struct dentry *root; |
1facf9fc | 27530 | + struct super_block *sb; |
27531 | + | |
27532 | + /* all timestamps always follow the ones on the branch */ | |
27533 | + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */ | |
027c5e7a AM |
27534 | + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super); |
27535 | + if (IS_ERR(root)) | |
27536 | + goto out; | |
27537 | + | |
27538 | + sb = root->d_sb; | |
27539 | + si_write_lock(sb, !AuLock_FLUSH); | |
27540 | + sysaufs_brs_add(sb, 0); | |
27541 | + si_write_unlock(sb); | |
27542 | + au_sbilist_add(sb); | |
27543 | + | |
27544 | +out: | |
27545 | + return root; | |
1facf9fc | 27546 | +} |
27547 | + | |
e49829fe JR |
27548 | +static void aufs_kill_sb(struct super_block *sb) |
27549 | +{ | |
27550 | + struct au_sbinfo *sbinfo; | |
27551 | + | |
27552 | + sbinfo = au_sbi(sb); | |
27553 | + if (sbinfo) { | |
27554 | + au_sbilist_del(sb); | |
27555 | + aufs_write_lock(sb->s_root); | |
076b876e | 27556 | + au_fhsm_fin(sb); |
e49829fe JR |
27557 | + if (sbinfo->si_wbr_create_ops->fin) |
27558 | + sbinfo->si_wbr_create_ops->fin(sb); | |
27559 | + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) { | |
27560 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE); | |
027c5e7a | 27561 | + au_remount_refresh(sb); |
e49829fe JR |
27562 | + } |
27563 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
27564 | + au_plink_put(sb, /*verbose*/1); | |
27565 | + au_xino_clr(sb); | |
1e00d052 | 27566 | + sbinfo->si_sb = NULL; |
e49829fe | 27567 | + aufs_write_unlock(sb->s_root); |
e49829fe JR |
27568 | + au_nwt_flush(&sbinfo->si_nowait); |
27569 | + } | |
98d9a5b1 | 27570 | + kill_anon_super(sb); |
e49829fe JR |
27571 | +} |
27572 | + | |
1facf9fc | 27573 | +struct file_system_type aufs_fs_type = { |
27574 | + .name = AUFS_FSTYPE, | |
c06a8ce3 AM |
27575 | + /* a race between rename and others */ |
27576 | + .fs_flags = FS_RENAME_DOES_D_MOVE, | |
027c5e7a | 27577 | + .mount = aufs_mount, |
e49829fe | 27578 | + .kill_sb = aufs_kill_sb, |
1facf9fc | 27579 | + /* no need to __module_get() and module_put(). */ |
27580 | + .owner = THIS_MODULE, | |
27581 | +}; | |
7f207e10 AM |
27582 | diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h |
27583 | --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
27584 | +++ linux/fs/aufs/super.h 2015-06-28 17:36:09.028407078 +0200 |
27585 | @@ -0,0 +1,635 @@ | |
1facf9fc | 27586 | +/* |
2000de60 | 27587 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 27588 | + * |
27589 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27590 | + * it under the terms of the GNU General Public License as published by | |
27591 | + * the Free Software Foundation; either version 2 of the License, or | |
27592 | + * (at your option) any later version. | |
dece6358 AM |
27593 | + * |
27594 | + * This program is distributed in the hope that it will be useful, | |
27595 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27596 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27597 | + * GNU General Public License for more details. | |
27598 | + * | |
27599 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27600 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27601 | + */ |
27602 | + | |
27603 | +/* | |
27604 | + * super_block operations | |
27605 | + */ | |
27606 | + | |
27607 | +#ifndef __AUFS_SUPER_H__ | |
27608 | +#define __AUFS_SUPER_H__ | |
27609 | + | |
27610 | +#ifdef __KERNEL__ | |
27611 | + | |
27612 | +#include <linux/fs.h> | |
5527c038 | 27613 | +#include <linux/kobject.h> |
1facf9fc | 27614 | +#include "rwsem.h" |
27615 | +#include "spl.h" | |
27616 | +#include "wkq.h" | |
27617 | + | |
1facf9fc | 27618 | +/* policies to select one among multiple writable branches */ |
27619 | +struct au_wbr_copyup_operations { | |
27620 | + int (*copyup)(struct dentry *dentry); | |
27621 | +}; | |
27622 | + | |
392086de AM |
27623 | +#define AuWbr_DIR 1 /* target is a dir */ |
27624 | +#define AuWbr_PARENT (1 << 1) /* always require a parent */ | |
27625 | + | |
27626 | +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name) | |
27627 | +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; } | |
27628 | +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; } | |
27629 | + | |
1facf9fc | 27630 | +struct au_wbr_create_operations { |
392086de | 27631 | + int (*create)(struct dentry *dentry, unsigned int flags); |
1facf9fc | 27632 | + int (*init)(struct super_block *sb); |
27633 | + int (*fin)(struct super_block *sb); | |
27634 | +}; | |
27635 | + | |
27636 | +struct au_wbr_mfs { | |
27637 | + struct mutex mfs_lock; /* protect this structure */ | |
27638 | + unsigned long mfs_jiffy; | |
27639 | + unsigned long mfs_expire; | |
27640 | + aufs_bindex_t mfs_bindex; | |
27641 | + | |
27642 | + unsigned long long mfsrr_bytes; | |
27643 | + unsigned long long mfsrr_watermark; | |
27644 | +}; | |
27645 | + | |
86dc4139 AM |
27646 | +struct pseudo_link { |
27647 | + union { | |
27648 | + struct hlist_node hlist; | |
27649 | + struct rcu_head rcu; | |
27650 | + }; | |
27651 | + struct inode *inode; | |
27652 | +}; | |
27653 | + | |
27654 | +#define AuPlink_NHASH 100 | |
27655 | +static inline int au_plink_hash(ino_t ino) | |
27656 | +{ | |
27657 | + return ino % AuPlink_NHASH; | |
27658 | +} | |
27659 | + | |
076b876e AM |
27660 | +/* File-based Hierarchical Storage Management */ |
27661 | +struct au_fhsm { | |
27662 | +#ifdef CONFIG_AUFS_FHSM | |
27663 | + /* allow only one process who can receive the notification */ | |
27664 | + spinlock_t fhsm_spin; | |
27665 | + pid_t fhsm_pid; | |
27666 | + wait_queue_head_t fhsm_wqh; | |
27667 | + atomic_t fhsm_readable; | |
27668 | + | |
c1595e42 | 27669 | + /* these are protected by si_rwsem */ |
076b876e | 27670 | + unsigned long fhsm_expire; |
c1595e42 | 27671 | + aufs_bindex_t fhsm_bottom; |
076b876e AM |
27672 | +#endif |
27673 | +}; | |
27674 | + | |
1facf9fc | 27675 | +struct au_branch; |
27676 | +struct au_sbinfo { | |
27677 | + /* nowait tasks in the system-wide workqueue */ | |
27678 | + struct au_nowait_tasks si_nowait; | |
27679 | + | |
b752ccd1 AM |
27680 | + /* |
27681 | + * tried sb->s_umount, but failed due to the dependecy between i_mutex. | |
27682 | + * rwsem for au_sbinfo is necessary. | |
27683 | + */ | |
dece6358 | 27684 | + struct au_rwsem si_rwsem; |
1facf9fc | 27685 | + |
b752ccd1 AM |
27686 | + /* prevent recursive locking in deleting inode */ |
27687 | + struct { | |
27688 | + unsigned long *bitmap; | |
27689 | + spinlock_t tree_lock; | |
27690 | + struct radix_tree_root tree; | |
27691 | + } au_si_pid; | |
27692 | + | |
7f207e10 | 27693 | + /* |
523b37e3 AM |
27694 | + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from |
27695 | + * remount. | |
7f207e10 AM |
27696 | + */ |
27697 | + atomic_long_t si_ninodes, si_nfiles; | |
27698 | + | |
1facf9fc | 27699 | + /* branch management */ |
27700 | + unsigned int si_generation; | |
27701 | + | |
2000de60 | 27702 | + /* see AuSi_ flags */ |
1facf9fc | 27703 | + unsigned char au_si_status; |
27704 | + | |
27705 | + aufs_bindex_t si_bend; | |
7f207e10 AM |
27706 | + |
27707 | + /* dirty trick to keep br_id plus */ | |
27708 | + unsigned int si_last_br_id : | |
27709 | + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1; | |
1facf9fc | 27710 | + struct au_branch **si_branch; |
27711 | + | |
27712 | + /* policy to select a writable branch */ | |
27713 | + unsigned char si_wbr_copyup; | |
27714 | + unsigned char si_wbr_create; | |
27715 | + struct au_wbr_copyup_operations *si_wbr_copyup_ops; | |
27716 | + struct au_wbr_create_operations *si_wbr_create_ops; | |
27717 | + | |
27718 | + /* round robin */ | |
27719 | + atomic_t si_wbr_rr_next; | |
27720 | + | |
27721 | + /* most free space */ | |
27722 | + struct au_wbr_mfs si_wbr_mfs; | |
27723 | + | |
076b876e AM |
27724 | + /* File-based Hierarchical Storage Management */ |
27725 | + struct au_fhsm si_fhsm; | |
27726 | + | |
1facf9fc | 27727 | + /* mount flags */ |
27728 | + /* include/asm-ia64/siginfo.h defines a macro named si_flags */ | |
27729 | + unsigned int si_mntflags; | |
27730 | + | |
27731 | + /* external inode number (bitmap and translation table) */ | |
5527c038 JR |
27732 | + vfs_readf_t si_xread; |
27733 | + vfs_writef_t si_xwrite; | |
1facf9fc | 27734 | + struct file *si_xib; |
27735 | + struct mutex si_xib_mtx; /* protect xib members */ | |
27736 | + unsigned long *si_xib_buf; | |
27737 | + unsigned long si_xib_last_pindex; | |
27738 | + int si_xib_next_bit; | |
27739 | + aufs_bindex_t si_xino_brid; | |
392086de AM |
27740 | + unsigned long si_xino_jiffy; |
27741 | + unsigned long si_xino_expire; | |
1facf9fc | 27742 | + /* reserved for future use */ |
27743 | + /* unsigned long long si_xib_limit; */ /* Max xib file size */ | |
27744 | + | |
27745 | +#ifdef CONFIG_AUFS_EXPORT | |
27746 | + /* i_generation */ | |
27747 | + struct file *si_xigen; | |
27748 | + atomic_t si_xigen_next; | |
27749 | +#endif | |
27750 | + | |
b912730e AM |
27751 | + /* dirty trick to suppoer atomic_open */ |
27752 | + struct au_sphlhead si_aopen; | |
27753 | + | |
1facf9fc | 27754 | + /* vdir parameters */ |
e49829fe | 27755 | + unsigned long si_rdcache; /* max cache time in jiffies */ |
1facf9fc | 27756 | + unsigned int si_rdblk; /* deblk size */ |
27757 | + unsigned int si_rdhash; /* hash size */ | |
27758 | + | |
27759 | + /* | |
27760 | + * If the number of whiteouts are larger than si_dirwh, leave all of | |
27761 | + * them after au_whtmp_ren to reduce the cost of rmdir(2). | |
27762 | + * future fsck.aufs or kernel thread will remove them later. | |
27763 | + * Otherwise, remove all whiteouts and the dir in rmdir(2). | |
27764 | + */ | |
27765 | + unsigned int si_dirwh; | |
27766 | + | |
1facf9fc | 27767 | + /* pseudo_link list */ |
86dc4139 | 27768 | + struct au_sphlhead si_plink[AuPlink_NHASH]; |
1facf9fc | 27769 | + wait_queue_head_t si_plink_wq; |
4a4d8108 | 27770 | + spinlock_t si_plink_maint_lock; |
e49829fe | 27771 | + pid_t si_plink_maint_pid; |
1facf9fc | 27772 | + |
523b37e3 AM |
27773 | + /* file list */ |
27774 | + struct au_sphlhead si_files; | |
27775 | + | |
1facf9fc | 27776 | + /* |
27777 | + * sysfs and lifetime management. | |
27778 | + * this is not a small structure and it may be a waste of memory in case | |
27779 | + * of sysfs is disabled, particulary when many aufs-es are mounted. | |
27780 | + * but using sysfs is majority. | |
27781 | + */ | |
27782 | + struct kobject si_kobj; | |
27783 | +#ifdef CONFIG_DEBUG_FS | |
86dc4139 AM |
27784 | + struct dentry *si_dbgaufs; |
27785 | + struct dentry *si_dbgaufs_plink; | |
27786 | + struct dentry *si_dbgaufs_xib; | |
1facf9fc | 27787 | +#ifdef CONFIG_AUFS_EXPORT |
27788 | + struct dentry *si_dbgaufs_xigen; | |
27789 | +#endif | |
27790 | +#endif | |
27791 | + | |
e49829fe JR |
27792 | +#ifdef CONFIG_AUFS_SBILIST |
27793 | + struct list_head si_list; | |
27794 | +#endif | |
27795 | + | |
1facf9fc | 27796 | + /* dirty, necessary for unmounting, sysfs and sysrq */ |
27797 | + struct super_block *si_sb; | |
27798 | +}; | |
27799 | + | |
dece6358 AM |
27800 | +/* sbinfo status flags */ |
27801 | +/* | |
27802 | + * set true when refresh_dirs() failed at remount time. | |
27803 | + * then try refreshing dirs at access time again. | |
27804 | + * if it is false, refreshing dirs at access time is unnecesary | |
27805 | + */ | |
027c5e7a | 27806 | +#define AuSi_FAILED_REFRESH_DIR 1 |
076b876e AM |
27807 | + |
27808 | +#define AuSi_FHSM (1 << 1) /* fhsm is active now */ | |
27809 | + | |
27810 | +#ifndef CONFIG_AUFS_FHSM | |
27811 | +#undef AuSi_FHSM | |
27812 | +#define AuSi_FHSM 0 | |
27813 | +#endif | |
27814 | + | |
dece6358 AM |
27815 | +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi, |
27816 | + unsigned int flag) | |
27817 | +{ | |
27818 | + AuRwMustAnyLock(&sbi->si_rwsem); | |
27819 | + return sbi->au_si_status & flag; | |
27820 | +} | |
27821 | +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name) | |
27822 | +#define au_fset_si(sbinfo, name) do { \ | |
27823 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
27824 | + (sbinfo)->au_si_status |= AuSi_##name; \ | |
27825 | +} while (0) | |
27826 | +#define au_fclr_si(sbinfo, name) do { \ | |
27827 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
27828 | + (sbinfo)->au_si_status &= ~AuSi_##name; \ | |
27829 | +} while (0) | |
27830 | + | |
1facf9fc | 27831 | +/* ---------------------------------------------------------------------- */ |
27832 | + | |
27833 | +/* policy to select one among writable branches */ | |
4a4d8108 AM |
27834 | +#define AuWbrCopyup(sbinfo, ...) \ |
27835 | + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__)) | |
27836 | +#define AuWbrCreate(sbinfo, ...) \ | |
27837 | + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__)) | |
1facf9fc | 27838 | + |
27839 | +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */ | |
27840 | +#define AuLock_DW 1 /* write-lock dentry */ | |
27841 | +#define AuLock_IR (1 << 1) /* read-lock inode */ | |
27842 | +#define AuLock_IW (1 << 2) /* write-lock inode */ | |
27843 | +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */ | |
27844 | +#define AuLock_DIR (1 << 4) /* target is a dir */ | |
e49829fe JR |
27845 | +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */ |
27846 | +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */ | |
027c5e7a | 27847 | +#define AuLock_GEN (1 << 7) /* test digen/iigen */ |
1facf9fc | 27848 | +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name) |
7f207e10 AM |
27849 | +#define au_fset_lock(flags, name) \ |
27850 | + do { (flags) |= AuLock_##name; } while (0) | |
27851 | +#define au_fclr_lock(flags, name) \ | |
27852 | + do { (flags) &= ~AuLock_##name; } while (0) | |
1facf9fc | 27853 | + |
27854 | +/* ---------------------------------------------------------------------- */ | |
27855 | + | |
27856 | +/* super.c */ | |
27857 | +extern struct file_system_type aufs_fs_type; | |
27858 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino); | |
7f207e10 AM |
27859 | +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max, |
27860 | + void *arg); | |
27861 | +void au_array_free(void *array); | |
27862 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg); | |
27863 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max); | |
27864 | +void au_iarray_free(struct inode **a, unsigned long long max); | |
1facf9fc | 27865 | + |
27866 | +/* sbinfo.c */ | |
27867 | +void au_si_free(struct kobject *kobj); | |
27868 | +int au_si_alloc(struct super_block *sb); | |
27869 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr); | |
27870 | + | |
27871 | +unsigned int au_sigen_inc(struct super_block *sb); | |
27872 | +aufs_bindex_t au_new_br_id(struct super_block *sb); | |
27873 | + | |
e49829fe JR |
27874 | +int si_read_lock(struct super_block *sb, int flags); |
27875 | +int si_write_lock(struct super_block *sb, int flags); | |
27876 | +int aufs_read_lock(struct dentry *dentry, int flags); | |
1facf9fc | 27877 | +void aufs_read_unlock(struct dentry *dentry, int flags); |
27878 | +void aufs_write_lock(struct dentry *dentry); | |
27879 | +void aufs_write_unlock(struct dentry *dentry); | |
e49829fe | 27880 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags); |
1facf9fc | 27881 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2); |
27882 | + | |
b752ccd1 AM |
27883 | +int si_pid_test_slow(struct super_block *sb); |
27884 | +void si_pid_set_slow(struct super_block *sb); | |
27885 | +void si_pid_clr_slow(struct super_block *sb); | |
27886 | + | |
1facf9fc | 27887 | +/* wbr_policy.c */ |
27888 | +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[]; | |
27889 | +extern struct au_wbr_create_operations au_wbr_create_ops[]; | |
27890 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
c2b27bf2 | 27891 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex); |
076b876e | 27892 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart); |
c2b27bf2 AM |
27893 | + |
27894 | +/* mvdown.c */ | |
27895 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg); | |
1facf9fc | 27896 | + |
076b876e AM |
27897 | +#ifdef CONFIG_AUFS_FHSM |
27898 | +/* fhsm.c */ | |
27899 | + | |
27900 | +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm) | |
27901 | +{ | |
27902 | + pid_t pid; | |
27903 | + | |
27904 | + spin_lock(&fhsm->fhsm_spin); | |
27905 | + pid = fhsm->fhsm_pid; | |
27906 | + spin_unlock(&fhsm->fhsm_spin); | |
27907 | + | |
27908 | + return pid; | |
27909 | +} | |
27910 | + | |
27911 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force); | |
27912 | +void au_fhsm_wrote_all(struct super_block *sb, int force); | |
27913 | +int au_fhsm_fd(struct super_block *sb, int oflags); | |
27914 | +int au_fhsm_br_alloc(struct au_branch *br); | |
c1595e42 | 27915 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex); |
076b876e AM |
27916 | +void au_fhsm_fin(struct super_block *sb); |
27917 | +void au_fhsm_init(struct au_sbinfo *sbinfo); | |
27918 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec); | |
27919 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo); | |
27920 | +#else | |
27921 | +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex, | |
27922 | + int force) | |
27923 | +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force) | |
27924 | +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags) | |
c1595e42 JR |
27925 | +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm) |
27926 | +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br) | |
27927 | +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex) | |
076b876e AM |
27928 | +AuStubVoid(au_fhsm_fin, struct super_block *sb) |
27929 | +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo) | |
27930 | +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec) | |
27931 | +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo) | |
27932 | +#endif | |
27933 | + | |
1facf9fc | 27934 | +/* ---------------------------------------------------------------------- */ |
27935 | + | |
27936 | +static inline struct au_sbinfo *au_sbi(struct super_block *sb) | |
27937 | +{ | |
27938 | + return sb->s_fs_info; | |
27939 | +} | |
27940 | + | |
27941 | +/* ---------------------------------------------------------------------- */ | |
27942 | + | |
27943 | +#ifdef CONFIG_AUFS_EXPORT | |
a2a7ad62 | 27944 | +int au_test_nfsd(void); |
1facf9fc | 27945 | +void au_export_init(struct super_block *sb); |
b752ccd1 | 27946 | +void au_xigen_inc(struct inode *inode); |
1facf9fc | 27947 | +int au_xigen_new(struct inode *inode); |
27948 | +int au_xigen_set(struct super_block *sb, struct file *base); | |
27949 | +void au_xigen_clr(struct super_block *sb); | |
27950 | + | |
27951 | +static inline int au_busy_or_stale(void) | |
27952 | +{ | |
b752ccd1 | 27953 | + if (!au_test_nfsd()) |
1facf9fc | 27954 | + return -EBUSY; |
27955 | + return -ESTALE; | |
27956 | +} | |
27957 | +#else | |
b752ccd1 | 27958 | +AuStubInt0(au_test_nfsd, void) |
a2a7ad62 | 27959 | +AuStubVoid(au_export_init, struct super_block *sb) |
b752ccd1 | 27960 | +AuStubVoid(au_xigen_inc, struct inode *inode) |
4a4d8108 AM |
27961 | +AuStubInt0(au_xigen_new, struct inode *inode) |
27962 | +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base) | |
27963 | +AuStubVoid(au_xigen_clr, struct super_block *sb) | |
c1595e42 | 27964 | +AuStub(int, au_busy_or_stale, return -EBUSY, void) |
1facf9fc | 27965 | +#endif /* CONFIG_AUFS_EXPORT */ |
27966 | + | |
27967 | +/* ---------------------------------------------------------------------- */ | |
27968 | + | |
e49829fe JR |
27969 | +#ifdef CONFIG_AUFS_SBILIST |
27970 | +/* module.c */ | |
27971 | +extern struct au_splhead au_sbilist; | |
27972 | + | |
27973 | +static inline void au_sbilist_init(void) | |
27974 | +{ | |
27975 | + au_spl_init(&au_sbilist); | |
27976 | +} | |
27977 | + | |
27978 | +static inline void au_sbilist_add(struct super_block *sb) | |
27979 | +{ | |
27980 | + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist); | |
27981 | +} | |
27982 | + | |
27983 | +static inline void au_sbilist_del(struct super_block *sb) | |
27984 | +{ | |
27985 | + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist); | |
27986 | +} | |
53392da6 AM |
27987 | + |
27988 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
27989 | +static inline void au_sbilist_lock(void) | |
27990 | +{ | |
27991 | + spin_lock(&au_sbilist.spin); | |
27992 | +} | |
27993 | + | |
27994 | +static inline void au_sbilist_unlock(void) | |
27995 | +{ | |
27996 | + spin_unlock(&au_sbilist.spin); | |
27997 | +} | |
27998 | +#define AuGFP_SBILIST GFP_ATOMIC | |
27999 | +#else | |
28000 | +AuStubVoid(au_sbilist_lock, void) | |
28001 | +AuStubVoid(au_sbilist_unlock, void) | |
28002 | +#define AuGFP_SBILIST GFP_NOFS | |
28003 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ | |
e49829fe JR |
28004 | +#else |
28005 | +AuStubVoid(au_sbilist_init, void) | |
c1595e42 JR |
28006 | +AuStubVoid(au_sbilist_add, struct super_block *sb) |
28007 | +AuStubVoid(au_sbilist_del, struct super_block *sb) | |
53392da6 AM |
28008 | +AuStubVoid(au_sbilist_lock, void) |
28009 | +AuStubVoid(au_sbilist_unlock, void) | |
28010 | +#define AuGFP_SBILIST GFP_NOFS | |
e49829fe JR |
28011 | +#endif |
28012 | + | |
28013 | +/* ---------------------------------------------------------------------- */ | |
28014 | + | |
1facf9fc | 28015 | +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo) |
28016 | +{ | |
dece6358 | 28017 | + /* |
c1595e42 | 28018 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
28019 | + * so the tiny check for si_rwsem is unnecessary. |
28020 | + */ | |
28021 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
1facf9fc | 28022 | +#ifdef CONFIG_DEBUG_FS |
28023 | + sbinfo->si_dbgaufs = NULL; | |
86dc4139 | 28024 | + sbinfo->si_dbgaufs_plink = NULL; |
1facf9fc | 28025 | + sbinfo->si_dbgaufs_xib = NULL; |
28026 | +#ifdef CONFIG_AUFS_EXPORT | |
28027 | + sbinfo->si_dbgaufs_xigen = NULL; | |
28028 | +#endif | |
28029 | +#endif | |
28030 | +} | |
28031 | + | |
28032 | +/* ---------------------------------------------------------------------- */ | |
28033 | + | |
b752ccd1 AM |
28034 | +static inline pid_t si_pid_bit(void) |
28035 | +{ | |
28036 | + /* the origin of pid is 1, but the bitmap's is 0 */ | |
28037 | + return current->pid - 1; | |
28038 | +} | |
28039 | + | |
28040 | +static inline int si_pid_test(struct super_block *sb) | |
28041 | +{ | |
076b876e AM |
28042 | + pid_t bit; |
28043 | + | |
28044 | + bit = si_pid_bit(); | |
b752ccd1 AM |
28045 | + if (bit < PID_MAX_DEFAULT) |
28046 | + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
c1595e42 | 28047 | + return si_pid_test_slow(sb); |
b752ccd1 AM |
28048 | +} |
28049 | + | |
28050 | +static inline void si_pid_set(struct super_block *sb) | |
28051 | +{ | |
076b876e AM |
28052 | + pid_t bit; |
28053 | + | |
28054 | + bit = si_pid_bit(); | |
b752ccd1 AM |
28055 | + if (bit < PID_MAX_DEFAULT) { |
28056 | + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap)); | |
28057 | + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
28058 | + /* smp_mb(); */ | |
28059 | + } else | |
28060 | + si_pid_set_slow(sb); | |
28061 | +} | |
28062 | + | |
28063 | +static inline void si_pid_clr(struct super_block *sb) | |
28064 | +{ | |
076b876e AM |
28065 | + pid_t bit; |
28066 | + | |
28067 | + bit = si_pid_bit(); | |
b752ccd1 AM |
28068 | + if (bit < PID_MAX_DEFAULT) { |
28069 | + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap)); | |
28070 | + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
28071 | + /* smp_mb(); */ | |
28072 | + } else | |
28073 | + si_pid_clr_slow(sb); | |
28074 | +} | |
28075 | + | |
28076 | +/* ---------------------------------------------------------------------- */ | |
28077 | + | |
1facf9fc | 28078 | +/* lock superblock. mainly for entry point functions */ |
28079 | +/* | |
b752ccd1 AM |
28080 | + * __si_read_lock, __si_write_lock, |
28081 | + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock | |
1facf9fc | 28082 | + */ |
b752ccd1 | 28083 | +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem); |
1facf9fc | 28084 | + |
dece6358 AM |
28085 | +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem) |
28086 | +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem) | |
28087 | +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem) | |
28088 | + | |
b752ccd1 AM |
28089 | +static inline void si_noflush_read_lock(struct super_block *sb) |
28090 | +{ | |
28091 | + __si_read_lock(sb); | |
28092 | + si_pid_set(sb); | |
28093 | +} | |
28094 | + | |
28095 | +static inline int si_noflush_read_trylock(struct super_block *sb) | |
28096 | +{ | |
076b876e AM |
28097 | + int locked; |
28098 | + | |
28099 | + locked = __si_read_trylock(sb); | |
b752ccd1 AM |
28100 | + if (locked) |
28101 | + si_pid_set(sb); | |
28102 | + return locked; | |
28103 | +} | |
28104 | + | |
28105 | +static inline void si_noflush_write_lock(struct super_block *sb) | |
28106 | +{ | |
28107 | + __si_write_lock(sb); | |
28108 | + si_pid_set(sb); | |
28109 | +} | |
28110 | + | |
28111 | +static inline int si_noflush_write_trylock(struct super_block *sb) | |
28112 | +{ | |
076b876e AM |
28113 | + int locked; |
28114 | + | |
28115 | + locked = __si_write_trylock(sb); | |
b752ccd1 AM |
28116 | + if (locked) |
28117 | + si_pid_set(sb); | |
28118 | + return locked; | |
28119 | +} | |
28120 | + | |
7e9cd9fe | 28121 | +#if 0 /* reserved */ |
1facf9fc | 28122 | +static inline int si_read_trylock(struct super_block *sb, int flags) |
28123 | +{ | |
28124 | + if (au_ftest_lock(flags, FLUSH)) | |
28125 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28126 | + return si_noflush_read_trylock(sb); | |
28127 | +} | |
e49829fe | 28128 | +#endif |
1facf9fc | 28129 | + |
b752ccd1 AM |
28130 | +static inline void si_read_unlock(struct super_block *sb) |
28131 | +{ | |
28132 | + si_pid_clr(sb); | |
28133 | + __si_read_unlock(sb); | |
28134 | +} | |
28135 | + | |
7e9cd9fe | 28136 | +#if 0 /* reserved */ |
1facf9fc | 28137 | +static inline int si_write_trylock(struct super_block *sb, int flags) |
28138 | +{ | |
28139 | + if (au_ftest_lock(flags, FLUSH)) | |
28140 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28141 | + return si_noflush_write_trylock(sb); | |
28142 | +} | |
b752ccd1 AM |
28143 | +#endif |
28144 | + | |
28145 | +static inline void si_write_unlock(struct super_block *sb) | |
28146 | +{ | |
28147 | + si_pid_clr(sb); | |
28148 | + __si_write_unlock(sb); | |
28149 | +} | |
28150 | + | |
7e9cd9fe | 28151 | +#if 0 /* reserved */ |
b752ccd1 AM |
28152 | +static inline void si_downgrade_lock(struct super_block *sb) |
28153 | +{ | |
28154 | + __si_downgrade_lock(sb); | |
28155 | +} | |
28156 | +#endif | |
1facf9fc | 28157 | + |
28158 | +/* ---------------------------------------------------------------------- */ | |
28159 | + | |
28160 | +static inline aufs_bindex_t au_sbend(struct super_block *sb) | |
28161 | +{ | |
dece6358 | 28162 | + SiMustAnyLock(sb); |
1facf9fc | 28163 | + return au_sbi(sb)->si_bend; |
28164 | +} | |
28165 | + | |
28166 | +static inline unsigned int au_mntflags(struct super_block *sb) | |
28167 | +{ | |
dece6358 | 28168 | + SiMustAnyLock(sb); |
1facf9fc | 28169 | + return au_sbi(sb)->si_mntflags; |
28170 | +} | |
28171 | + | |
28172 | +static inline unsigned int au_sigen(struct super_block *sb) | |
28173 | +{ | |
dece6358 | 28174 | + SiMustAnyLock(sb); |
1facf9fc | 28175 | + return au_sbi(sb)->si_generation; |
28176 | +} | |
28177 | + | |
7f207e10 AM |
28178 | +static inline void au_ninodes_inc(struct super_block *sb) |
28179 | +{ | |
28180 | + atomic_long_inc(&au_sbi(sb)->si_ninodes); | |
28181 | +} | |
28182 | + | |
28183 | +static inline void au_ninodes_dec(struct super_block *sb) | |
28184 | +{ | |
28185 | + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes)); | |
28186 | + atomic_long_dec(&au_sbi(sb)->si_ninodes); | |
28187 | +} | |
28188 | + | |
28189 | +static inline void au_nfiles_inc(struct super_block *sb) | |
28190 | +{ | |
28191 | + atomic_long_inc(&au_sbi(sb)->si_nfiles); | |
28192 | +} | |
28193 | + | |
28194 | +static inline void au_nfiles_dec(struct super_block *sb) | |
28195 | +{ | |
28196 | + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles)); | |
28197 | + atomic_long_dec(&au_sbi(sb)->si_nfiles); | |
28198 | +} | |
28199 | + | |
1facf9fc | 28200 | +static inline struct au_branch *au_sbr(struct super_block *sb, |
28201 | + aufs_bindex_t bindex) | |
28202 | +{ | |
dece6358 | 28203 | + SiMustAnyLock(sb); |
1facf9fc | 28204 | + return au_sbi(sb)->si_branch[0 + bindex]; |
28205 | +} | |
28206 | + | |
28207 | +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid) | |
28208 | +{ | |
dece6358 | 28209 | + SiMustWriteLock(sb); |
1facf9fc | 28210 | + au_sbi(sb)->si_xino_brid = brid; |
28211 | +} | |
28212 | + | |
28213 | +static inline aufs_bindex_t au_xino_brid(struct super_block *sb) | |
28214 | +{ | |
dece6358 | 28215 | + SiMustAnyLock(sb); |
1facf9fc | 28216 | + return au_sbi(sb)->si_xino_brid; |
28217 | +} | |
28218 | + | |
28219 | +#endif /* __KERNEL__ */ | |
28220 | +#endif /* __AUFS_SUPER_H__ */ | |
7f207e10 AM |
28221 | diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c |
28222 | --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 28223 | +++ linux/fs/aufs/sysaufs.c 2015-06-28 17:35:44.351383872 +0200 |
523b37e3 | 28224 | @@ -0,0 +1,104 @@ |
1facf9fc | 28225 | +/* |
2000de60 | 28226 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28227 | + * |
28228 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28229 | + * it under the terms of the GNU General Public License as published by | |
28230 | + * the Free Software Foundation; either version 2 of the License, or | |
28231 | + * (at your option) any later version. | |
dece6358 AM |
28232 | + * |
28233 | + * This program is distributed in the hope that it will be useful, | |
28234 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28235 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28236 | + * GNU General Public License for more details. | |
28237 | + * | |
28238 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28239 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28240 | + */ |
28241 | + | |
28242 | +/* | |
28243 | + * sysfs interface and lifetime management | |
28244 | + * they are necessary regardless sysfs is disabled. | |
28245 | + */ | |
28246 | + | |
1facf9fc | 28247 | +#include <linux/random.h> |
1facf9fc | 28248 | +#include "aufs.h" |
28249 | + | |
28250 | +unsigned long sysaufs_si_mask; | |
e49829fe | 28251 | +struct kset *sysaufs_kset; |
1facf9fc | 28252 | + |
28253 | +#define AuSiAttr(_name) { \ | |
28254 | + .attr = { .name = __stringify(_name), .mode = 0444 }, \ | |
28255 | + .show = sysaufs_si_##_name, \ | |
28256 | +} | |
28257 | + | |
28258 | +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path); | |
28259 | +struct attribute *sysaufs_si_attrs[] = { | |
28260 | + &sysaufs_si_attr_xi_path.attr, | |
28261 | + NULL, | |
28262 | +}; | |
28263 | + | |
4a4d8108 | 28264 | +static const struct sysfs_ops au_sbi_ops = { |
1facf9fc | 28265 | + .show = sysaufs_si_show |
28266 | +}; | |
28267 | + | |
28268 | +static struct kobj_type au_sbi_ktype = { | |
28269 | + .release = au_si_free, | |
28270 | + .sysfs_ops = &au_sbi_ops, | |
28271 | + .default_attrs = sysaufs_si_attrs | |
28272 | +}; | |
28273 | + | |
28274 | +/* ---------------------------------------------------------------------- */ | |
28275 | + | |
28276 | +int sysaufs_si_init(struct au_sbinfo *sbinfo) | |
28277 | +{ | |
28278 | + int err; | |
28279 | + | |
e49829fe | 28280 | + sbinfo->si_kobj.kset = sysaufs_kset; |
1facf9fc | 28281 | + /* cf. sysaufs_name() */ |
28282 | + err = kobject_init_and_add | |
e49829fe | 28283 | + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL, |
1facf9fc | 28284 | + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo)); |
28285 | + | |
28286 | + dbgaufs_si_null(sbinfo); | |
28287 | + if (!err) { | |
28288 | + err = dbgaufs_si_init(sbinfo); | |
28289 | + if (unlikely(err)) | |
28290 | + kobject_put(&sbinfo->si_kobj); | |
28291 | + } | |
28292 | + return err; | |
28293 | +} | |
28294 | + | |
28295 | +void sysaufs_fin(void) | |
28296 | +{ | |
28297 | + dbgaufs_fin(); | |
e49829fe JR |
28298 | + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
28299 | + kset_unregister(sysaufs_kset); | |
1facf9fc | 28300 | +} |
28301 | + | |
28302 | +int __init sysaufs_init(void) | |
28303 | +{ | |
28304 | + int err; | |
28305 | + | |
28306 | + do { | |
28307 | + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask)); | |
28308 | + } while (!sysaufs_si_mask); | |
28309 | + | |
4a4d8108 | 28310 | + err = -EINVAL; |
e49829fe JR |
28311 | + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj); |
28312 | + if (unlikely(!sysaufs_kset)) | |
4a4d8108 | 28313 | + goto out; |
e49829fe JR |
28314 | + err = PTR_ERR(sysaufs_kset); |
28315 | + if (IS_ERR(sysaufs_kset)) | |
1facf9fc | 28316 | + goto out; |
e49829fe | 28317 | + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
1facf9fc | 28318 | + if (unlikely(err)) { |
e49829fe | 28319 | + kset_unregister(sysaufs_kset); |
1facf9fc | 28320 | + goto out; |
28321 | + } | |
28322 | + | |
28323 | + err = dbgaufs_init(); | |
28324 | + if (unlikely(err)) | |
28325 | + sysaufs_fin(); | |
4f0767ce | 28326 | +out: |
1facf9fc | 28327 | + return err; |
28328 | +} | |
7f207e10 AM |
28329 | diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h |
28330 | --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 28331 | +++ linux/fs/aufs/sysaufs.h 2015-06-28 17:35:44.351383872 +0200 |
c1595e42 | 28332 | @@ -0,0 +1,101 @@ |
1facf9fc | 28333 | +/* |
2000de60 | 28334 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28335 | + * |
28336 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28337 | + * it under the terms of the GNU General Public License as published by | |
28338 | + * the Free Software Foundation; either version 2 of the License, or | |
28339 | + * (at your option) any later version. | |
dece6358 AM |
28340 | + * |
28341 | + * This program is distributed in the hope that it will be useful, | |
28342 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28343 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28344 | + * GNU General Public License for more details. | |
28345 | + * | |
28346 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28347 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28348 | + */ |
28349 | + | |
28350 | +/* | |
28351 | + * sysfs interface and mount lifetime management | |
28352 | + */ | |
28353 | + | |
28354 | +#ifndef __SYSAUFS_H__ | |
28355 | +#define __SYSAUFS_H__ | |
28356 | + | |
28357 | +#ifdef __KERNEL__ | |
28358 | + | |
1facf9fc | 28359 | +#include <linux/sysfs.h> |
1facf9fc | 28360 | +#include "module.h" |
28361 | + | |
dece6358 AM |
28362 | +struct super_block; |
28363 | +struct au_sbinfo; | |
28364 | + | |
1facf9fc | 28365 | +struct sysaufs_si_attr { |
28366 | + struct attribute attr; | |
28367 | + int (*show)(struct seq_file *seq, struct super_block *sb); | |
28368 | +}; | |
28369 | + | |
28370 | +/* ---------------------------------------------------------------------- */ | |
28371 | + | |
28372 | +/* sysaufs.c */ | |
28373 | +extern unsigned long sysaufs_si_mask; | |
e49829fe | 28374 | +extern struct kset *sysaufs_kset; |
1facf9fc | 28375 | +extern struct attribute *sysaufs_si_attrs[]; |
28376 | +int sysaufs_si_init(struct au_sbinfo *sbinfo); | |
28377 | +int __init sysaufs_init(void); | |
28378 | +void sysaufs_fin(void); | |
28379 | + | |
28380 | +/* ---------------------------------------------------------------------- */ | |
28381 | + | |
28382 | +/* some people doesn't like to show a pointer in kernel */ | |
28383 | +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo) | |
28384 | +{ | |
28385 | + return sysaufs_si_mask ^ (unsigned long)sbinfo; | |
28386 | +} | |
28387 | + | |
28388 | +#define SysaufsSiNamePrefix "si_" | |
28389 | +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16) | |
28390 | +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name) | |
28391 | +{ | |
28392 | + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx", | |
28393 | + sysaufs_si_id(sbinfo)); | |
28394 | +} | |
28395 | + | |
28396 | +struct au_branch; | |
28397 | +#ifdef CONFIG_SYSFS | |
28398 | +/* sysfs.c */ | |
28399 | +extern struct attribute_group *sysaufs_attr_group; | |
28400 | + | |
28401 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb); | |
28402 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
28403 | + char *buf); | |
076b876e AM |
28404 | +long au_brinfo_ioctl(struct file *file, unsigned long arg); |
28405 | +#ifdef CONFIG_COMPAT | |
28406 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg); | |
28407 | +#endif | |
1facf9fc | 28408 | + |
28409 | +void sysaufs_br_init(struct au_branch *br); | |
28410 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
28411 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
28412 | + | |
28413 | +#define sysaufs_brs_init() do {} while (0) | |
28414 | + | |
28415 | +#else | |
28416 | +#define sysaufs_attr_group NULL | |
28417 | + | |
4a4d8108 | 28418 | +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb) |
c1595e42 JR |
28419 | +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj, |
28420 | + struct attribute *attr, char *buf) | |
4a4d8108 AM |
28421 | +AuStubVoid(sysaufs_br_init, struct au_branch *br) |
28422 | +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
28423 | +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) | |
1facf9fc | 28424 | + |
28425 | +static inline void sysaufs_brs_init(void) | |
28426 | +{ | |
28427 | + sysaufs_brs = 0; | |
28428 | +} | |
28429 | + | |
28430 | +#endif /* CONFIG_SYSFS */ | |
28431 | + | |
28432 | +#endif /* __KERNEL__ */ | |
28433 | +#endif /* __SYSAUFS_H__ */ | |
7f207e10 AM |
28434 | diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c |
28435 | --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 28436 | +++ linux/fs/aufs/sysfs.c 2015-06-28 17:35:44.351383872 +0200 |
076b876e | 28437 | @@ -0,0 +1,372 @@ |
1facf9fc | 28438 | +/* |
2000de60 | 28439 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28440 | + * |
28441 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28442 | + * it under the terms of the GNU General Public License as published by | |
28443 | + * the Free Software Foundation; either version 2 of the License, or | |
28444 | + * (at your option) any later version. | |
dece6358 AM |
28445 | + * |
28446 | + * This program is distributed in the hope that it will be useful, | |
28447 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28448 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28449 | + * GNU General Public License for more details. | |
28450 | + * | |
28451 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28452 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28453 | + */ |
28454 | + | |
28455 | +/* | |
28456 | + * sysfs interface | |
28457 | + */ | |
28458 | + | |
076b876e | 28459 | +#include <linux/compat.h> |
1facf9fc | 28460 | +#include <linux/seq_file.h> |
1facf9fc | 28461 | +#include "aufs.h" |
28462 | + | |
4a4d8108 AM |
28463 | +#ifdef CONFIG_AUFS_FS_MODULE |
28464 | +/* this entry violates the "one line per file" policy of sysfs */ | |
28465 | +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr, | |
28466 | + char *buf) | |
28467 | +{ | |
28468 | + ssize_t err; | |
28469 | + static char *conf = | |
28470 | +/* this file is generated at compiling */ | |
28471 | +#include "conf.str" | |
28472 | + ; | |
28473 | + | |
28474 | + err = snprintf(buf, PAGE_SIZE, conf); | |
28475 | + if (unlikely(err >= PAGE_SIZE)) | |
28476 | + err = -EFBIG; | |
28477 | + return err; | |
28478 | +} | |
28479 | + | |
28480 | +static struct kobj_attribute au_config_attr = __ATTR_RO(config); | |
28481 | +#endif | |
28482 | + | |
1facf9fc | 28483 | +static struct attribute *au_attr[] = { |
4a4d8108 AM |
28484 | +#ifdef CONFIG_AUFS_FS_MODULE |
28485 | + &au_config_attr.attr, | |
28486 | +#endif | |
1facf9fc | 28487 | + NULL, /* need to NULL terminate the list of attributes */ |
28488 | +}; | |
28489 | + | |
28490 | +static struct attribute_group sysaufs_attr_group_body = { | |
28491 | + .attrs = au_attr | |
28492 | +}; | |
28493 | + | |
28494 | +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body; | |
28495 | + | |
28496 | +/* ---------------------------------------------------------------------- */ | |
28497 | + | |
28498 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb) | |
28499 | +{ | |
28500 | + int err; | |
28501 | + | |
dece6358 AM |
28502 | + SiMustAnyLock(sb); |
28503 | + | |
1facf9fc | 28504 | + err = 0; |
28505 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
28506 | + err = au_xino_path(seq, au_sbi(sb)->si_xib); | |
28507 | + seq_putc(seq, '\n'); | |
28508 | + } | |
28509 | + return err; | |
28510 | +} | |
28511 | + | |
28512 | +/* | |
28513 | + * the lifetime of branch is independent from the entry under sysfs. | |
28514 | + * sysfs handles the lifetime of the entry, and never call ->show() after it is | |
28515 | + * unlinked. | |
28516 | + */ | |
28517 | +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb, | |
392086de | 28518 | + aufs_bindex_t bindex, int idx) |
1facf9fc | 28519 | +{ |
1e00d052 | 28520 | + int err; |
1facf9fc | 28521 | + struct path path; |
28522 | + struct dentry *root; | |
28523 | + struct au_branch *br; | |
076b876e | 28524 | + au_br_perm_str_t perm; |
1facf9fc | 28525 | + |
28526 | + AuDbg("b%d\n", bindex); | |
28527 | + | |
1e00d052 | 28528 | + err = 0; |
1facf9fc | 28529 | + root = sb->s_root; |
28530 | + di_read_lock_parent(root, !AuLock_IR); | |
28531 | + br = au_sbr(sb, bindex); | |
392086de AM |
28532 | + |
28533 | + switch (idx) { | |
28534 | + case AuBrSysfs_BR: | |
28535 | + path.mnt = au_br_mnt(br); | |
28536 | + path.dentry = au_h_dptr(root, bindex); | |
28537 | + au_seq_path(seq, &path); | |
076b876e AM |
28538 | + au_optstr_br_perm(&perm, br->br_perm); |
28539 | + err = seq_printf(seq, "=%s\n", perm.a); | |
392086de AM |
28540 | + break; |
28541 | + case AuBrSysfs_BRID: | |
28542 | + err = seq_printf(seq, "%d\n", br->br_id); | |
392086de AM |
28543 | + break; |
28544 | + } | |
076b876e AM |
28545 | + di_read_unlock(root, !AuLock_IR); |
28546 | + if (err == -1) | |
28547 | + err = -E2BIG; | |
392086de | 28548 | + |
1e00d052 | 28549 | + return err; |
1facf9fc | 28550 | +} |
28551 | + | |
28552 | +/* ---------------------------------------------------------------------- */ | |
28553 | + | |
28554 | +static struct seq_file *au_seq(char *p, ssize_t len) | |
28555 | +{ | |
28556 | + struct seq_file *seq; | |
28557 | + | |
28558 | + seq = kzalloc(sizeof(*seq), GFP_NOFS); | |
28559 | + if (seq) { | |
28560 | + /* mutex_init(&seq.lock); */ | |
28561 | + seq->buf = p; | |
28562 | + seq->size = len; | |
28563 | + return seq; /* success */ | |
28564 | + } | |
28565 | + | |
28566 | + seq = ERR_PTR(-ENOMEM); | |
28567 | + return seq; | |
28568 | +} | |
28569 | + | |
392086de AM |
28570 | +#define SysaufsBr_PREFIX "br" |
28571 | +#define SysaufsBrid_PREFIX "brid" | |
1facf9fc | 28572 | + |
28573 | +/* todo: file size may exceed PAGE_SIZE */ | |
28574 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
1308ab2a | 28575 | + char *buf) |
1facf9fc | 28576 | +{ |
28577 | + ssize_t err; | |
392086de | 28578 | + int idx; |
1facf9fc | 28579 | + long l; |
28580 | + aufs_bindex_t bend; | |
28581 | + struct au_sbinfo *sbinfo; | |
28582 | + struct super_block *sb; | |
28583 | + struct seq_file *seq; | |
28584 | + char *name; | |
28585 | + struct attribute **cattr; | |
28586 | + | |
28587 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
28588 | + sb = sbinfo->si_sb; | |
1308ab2a | 28589 | + |
28590 | + /* | |
28591 | + * prevent a race condition between sysfs and aufs. | |
28592 | + * for instance, sysfs_file_read() calls sysfs_get_active_two() which | |
28593 | + * prohibits maintaining the sysfs entries. | |
28594 | + * hew we acquire read lock after sysfs_get_active_two(). | |
28595 | + * on the other hand, the remount process may maintain the sysfs/aufs | |
28596 | + * entries after acquiring write lock. | |
28597 | + * it can cause a deadlock. | |
28598 | + * simply we gave up processing read here. | |
28599 | + */ | |
28600 | + err = -EBUSY; | |
28601 | + if (unlikely(!si_noflush_read_trylock(sb))) | |
28602 | + goto out; | |
1facf9fc | 28603 | + |
28604 | + seq = au_seq(buf, PAGE_SIZE); | |
28605 | + err = PTR_ERR(seq); | |
28606 | + if (IS_ERR(seq)) | |
1308ab2a | 28607 | + goto out_unlock; |
1facf9fc | 28608 | + |
28609 | + name = (void *)attr->name; | |
28610 | + cattr = sysaufs_si_attrs; | |
28611 | + while (*cattr) { | |
28612 | + if (!strcmp(name, (*cattr)->name)) { | |
28613 | + err = container_of(*cattr, struct sysaufs_si_attr, attr) | |
28614 | + ->show(seq, sb); | |
28615 | + goto out_seq; | |
28616 | + } | |
28617 | + cattr++; | |
28618 | + } | |
28619 | + | |
392086de AM |
28620 | + if (!strncmp(name, SysaufsBrid_PREFIX, |
28621 | + sizeof(SysaufsBrid_PREFIX) - 1)) { | |
28622 | + idx = AuBrSysfs_BRID; | |
28623 | + name += sizeof(SysaufsBrid_PREFIX) - 1; | |
28624 | + } else if (!strncmp(name, SysaufsBr_PREFIX, | |
28625 | + sizeof(SysaufsBr_PREFIX) - 1)) { | |
28626 | + idx = AuBrSysfs_BR; | |
1facf9fc | 28627 | + name += sizeof(SysaufsBr_PREFIX) - 1; |
392086de AM |
28628 | + } else |
28629 | + BUG(); | |
28630 | + | |
28631 | + err = kstrtol(name, 10, &l); | |
28632 | + if (!err) { | |
28633 | + bend = au_sbend(sb); | |
28634 | + if (l <= bend) | |
28635 | + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx); | |
28636 | + else | |
28637 | + err = -ENOENT; | |
1facf9fc | 28638 | + } |
1facf9fc | 28639 | + |
4f0767ce | 28640 | +out_seq: |
1facf9fc | 28641 | + if (!err) { |
28642 | + err = seq->count; | |
28643 | + /* sysfs limit */ | |
28644 | + if (unlikely(err == PAGE_SIZE)) | |
28645 | + err = -EFBIG; | |
28646 | + } | |
28647 | + kfree(seq); | |
4f0767ce | 28648 | +out_unlock: |
1facf9fc | 28649 | + si_read_unlock(sb); |
4f0767ce | 28650 | +out: |
1facf9fc | 28651 | + return err; |
28652 | +} | |
28653 | + | |
28654 | +/* ---------------------------------------------------------------------- */ | |
28655 | + | |
076b876e AM |
28656 | +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg) |
28657 | +{ | |
28658 | + int err; | |
28659 | + int16_t brid; | |
28660 | + aufs_bindex_t bindex, bend; | |
28661 | + size_t sz; | |
28662 | + char *buf; | |
28663 | + struct seq_file *seq; | |
28664 | + struct au_branch *br; | |
28665 | + | |
28666 | + si_read_lock(sb, AuLock_FLUSH); | |
28667 | + bend = au_sbend(sb); | |
28668 | + err = bend + 1; | |
28669 | + if (!arg) | |
28670 | + goto out; | |
28671 | + | |
28672 | + err = -ENOMEM; | |
28673 | + buf = (void *)__get_free_page(GFP_NOFS); | |
28674 | + if (unlikely(!buf)) | |
28675 | + goto out; | |
28676 | + | |
28677 | + seq = au_seq(buf, PAGE_SIZE); | |
28678 | + err = PTR_ERR(seq); | |
28679 | + if (IS_ERR(seq)) | |
28680 | + goto out_buf; | |
28681 | + | |
28682 | + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path); | |
28683 | + for (bindex = 0; bindex <= bend; bindex++, arg++) { | |
28684 | + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg)); | |
28685 | + if (unlikely(err)) | |
28686 | + break; | |
28687 | + | |
28688 | + br = au_sbr(sb, bindex); | |
28689 | + brid = br->br_id; | |
28690 | + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id)); | |
28691 | + err = __put_user(brid, &arg->id); | |
28692 | + if (unlikely(err)) | |
28693 | + break; | |
28694 | + | |
28695 | + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm)); | |
28696 | + err = __put_user(br->br_perm, &arg->perm); | |
28697 | + if (unlikely(err)) | |
28698 | + break; | |
28699 | + | |
28700 | + au_seq_path(seq, &br->br_path); | |
28701 | + err = seq_putc(seq, '\0'); | |
28702 | + if (!err && seq->count <= sz) { | |
28703 | + err = copy_to_user(arg->path, seq->buf, seq->count); | |
28704 | + seq->count = 0; | |
28705 | + if (unlikely(err)) | |
28706 | + break; | |
28707 | + } else { | |
28708 | + err = -E2BIG; | |
28709 | + goto out_seq; | |
28710 | + } | |
28711 | + } | |
28712 | + if (unlikely(err)) | |
28713 | + err = -EFAULT; | |
28714 | + | |
28715 | +out_seq: | |
28716 | + kfree(seq); | |
28717 | +out_buf: | |
28718 | + free_page((unsigned long)buf); | |
28719 | +out: | |
28720 | + si_read_unlock(sb); | |
28721 | + return err; | |
28722 | +} | |
28723 | + | |
28724 | +long au_brinfo_ioctl(struct file *file, unsigned long arg) | |
28725 | +{ | |
2000de60 | 28726 | + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg); |
076b876e AM |
28727 | +} |
28728 | + | |
28729 | +#ifdef CONFIG_COMPAT | |
28730 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg) | |
28731 | +{ | |
2000de60 | 28732 | + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg)); |
076b876e AM |
28733 | +} |
28734 | +#endif | |
28735 | + | |
28736 | +/* ---------------------------------------------------------------------- */ | |
28737 | + | |
1facf9fc | 28738 | +void sysaufs_br_init(struct au_branch *br) |
28739 | +{ | |
392086de AM |
28740 | + int i; |
28741 | + struct au_brsysfs *br_sysfs; | |
28742 | + struct attribute *attr; | |
4a4d8108 | 28743 | + |
392086de AM |
28744 | + br_sysfs = br->br_sysfs; |
28745 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28746 | + attr = &br_sysfs->attr; | |
28747 | + sysfs_attr_init(attr); | |
28748 | + attr->name = br_sysfs->name; | |
28749 | + attr->mode = S_IRUGO; | |
28750 | + br_sysfs++; | |
28751 | + } | |
1facf9fc | 28752 | +} |
28753 | + | |
28754 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
28755 | +{ | |
28756 | + struct au_branch *br; | |
28757 | + struct kobject *kobj; | |
392086de AM |
28758 | + struct au_brsysfs *br_sysfs; |
28759 | + int i; | |
1facf9fc | 28760 | + aufs_bindex_t bend; |
28761 | + | |
28762 | + dbgaufs_brs_del(sb, bindex); | |
28763 | + | |
28764 | + if (!sysaufs_brs) | |
28765 | + return; | |
28766 | + | |
28767 | + kobj = &au_sbi(sb)->si_kobj; | |
28768 | + bend = au_sbend(sb); | |
28769 | + for (; bindex <= bend; bindex++) { | |
28770 | + br = au_sbr(sb, bindex); | |
392086de AM |
28771 | + br_sysfs = br->br_sysfs; |
28772 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28773 | + sysfs_remove_file(kobj, &br_sysfs->attr); | |
28774 | + br_sysfs++; | |
28775 | + } | |
1facf9fc | 28776 | + } |
28777 | +} | |
28778 | + | |
28779 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
28780 | +{ | |
392086de | 28781 | + int err, i; |
1facf9fc | 28782 | + aufs_bindex_t bend; |
28783 | + struct kobject *kobj; | |
28784 | + struct au_branch *br; | |
392086de | 28785 | + struct au_brsysfs *br_sysfs; |
1facf9fc | 28786 | + |
28787 | + dbgaufs_brs_add(sb, bindex); | |
28788 | + | |
28789 | + if (!sysaufs_brs) | |
28790 | + return; | |
28791 | + | |
28792 | + kobj = &au_sbi(sb)->si_kobj; | |
28793 | + bend = au_sbend(sb); | |
28794 | + for (; bindex <= bend; bindex++) { | |
28795 | + br = au_sbr(sb, bindex); | |
392086de AM |
28796 | + br_sysfs = br->br_sysfs; |
28797 | + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name), | |
28798 | + SysaufsBr_PREFIX "%d", bindex); | |
28799 | + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name), | |
28800 | + SysaufsBrid_PREFIX "%d", bindex); | |
28801 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28802 | + err = sysfs_create_file(kobj, &br_sysfs->attr); | |
28803 | + if (unlikely(err)) | |
28804 | + pr_warn("failed %s under sysfs(%d)\n", | |
28805 | + br_sysfs->name, err); | |
28806 | + br_sysfs++; | |
28807 | + } | |
1facf9fc | 28808 | + } |
28809 | +} | |
7f207e10 AM |
28810 | diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c |
28811 | --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 28812 | +++ linux/fs/aufs/sysrq.c 2015-06-28 17:36:09.028407078 +0200 |
076b876e | 28813 | @@ -0,0 +1,157 @@ |
1facf9fc | 28814 | +/* |
2000de60 | 28815 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28816 | + * |
28817 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28818 | + * it under the terms of the GNU General Public License as published by | |
28819 | + * the Free Software Foundation; either version 2 of the License, or | |
28820 | + * (at your option) any later version. | |
dece6358 AM |
28821 | + * |
28822 | + * This program is distributed in the hope that it will be useful, | |
28823 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28824 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28825 | + * GNU General Public License for more details. | |
28826 | + * | |
28827 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28828 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28829 | + */ |
28830 | + | |
28831 | +/* | |
28832 | + * magic sysrq hanlder | |
28833 | + */ | |
28834 | + | |
1facf9fc | 28835 | +/* #include <linux/sysrq.h> */ |
027c5e7a | 28836 | +#include <linux/writeback.h> |
1facf9fc | 28837 | +#include "aufs.h" |
28838 | + | |
28839 | +/* ---------------------------------------------------------------------- */ | |
28840 | + | |
28841 | +static void sysrq_sb(struct super_block *sb) | |
28842 | +{ | |
28843 | + char *plevel; | |
28844 | + struct au_sbinfo *sbinfo; | |
28845 | + struct file *file; | |
523b37e3 AM |
28846 | + struct au_sphlhead *files; |
28847 | + struct au_finfo *finfo; | |
1facf9fc | 28848 | + |
28849 | + plevel = au_plevel; | |
28850 | + au_plevel = KERN_WARNING; | |
1facf9fc | 28851 | + |
4a4d8108 | 28852 | + /* since we define pr_fmt, call printk directly */ |
c06a8ce3 AM |
28853 | +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str) |
28854 | + | |
28855 | + sbinfo = au_sbi(sb); | |
4a4d8108 | 28856 | + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo)); |
c06a8ce3 | 28857 | + pr("superblock\n"); |
1facf9fc | 28858 | + au_dpri_sb(sb); |
027c5e7a AM |
28859 | + |
28860 | +#if 0 | |
c06a8ce3 | 28861 | + pr("root dentry\n"); |
1facf9fc | 28862 | + au_dpri_dentry(sb->s_root); |
c06a8ce3 | 28863 | + pr("root inode\n"); |
5527c038 | 28864 | + au_dpri_inode(d_inode(sb->s_root)); |
027c5e7a AM |
28865 | +#endif |
28866 | + | |
1facf9fc | 28867 | +#if 0 |
027c5e7a AM |
28868 | + do { |
28869 | + int err, i, j, ndentry; | |
28870 | + struct au_dcsub_pages dpages; | |
28871 | + struct au_dpage *dpage; | |
28872 | + | |
28873 | + err = au_dpages_init(&dpages, GFP_ATOMIC); | |
28874 | + if (unlikely(err)) | |
28875 | + break; | |
28876 | + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL); | |
28877 | + if (!err) | |
28878 | + for (i = 0; i < dpages.ndpage; i++) { | |
28879 | + dpage = dpages.dpages + i; | |
28880 | + ndentry = dpage->ndentry; | |
28881 | + for (j = 0; j < ndentry; j++) | |
28882 | + au_dpri_dentry(dpage->dentries[j]); | |
28883 | + } | |
28884 | + au_dpages_free(&dpages); | |
28885 | + } while (0); | |
28886 | +#endif | |
28887 | + | |
28888 | +#if 1 | |
28889 | + { | |
28890 | + struct inode *i; | |
076b876e | 28891 | + |
c06a8ce3 | 28892 | + pr("isolated inode\n"); |
2cbb1c4b JR |
28893 | + spin_lock(&inode_sb_list_lock); |
28894 | + list_for_each_entry(i, &sb->s_inodes, i_sb_list) { | |
28895 | + spin_lock(&i->i_lock); | |
b4510431 | 28896 | + if (1 || hlist_empty(&i->i_dentry)) |
027c5e7a | 28897 | + au_dpri_inode(i); |
2cbb1c4b JR |
28898 | + spin_unlock(&i->i_lock); |
28899 | + } | |
28900 | + spin_unlock(&inode_sb_list_lock); | |
027c5e7a | 28901 | + } |
1facf9fc | 28902 | +#endif |
c06a8ce3 | 28903 | + pr("files\n"); |
523b37e3 AM |
28904 | + files = &au_sbi(sb)->si_files; |
28905 | + spin_lock(&files->spin); | |
28906 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
4a4d8108 | 28907 | + umode_t mode; |
076b876e | 28908 | + |
523b37e3 | 28909 | + file = finfo->fi_file; |
c06a8ce3 | 28910 | + mode = file_inode(file)->i_mode; |
38d290e6 | 28911 | + if (!special_file(mode)) |
1facf9fc | 28912 | + au_dpri_file(file); |
523b37e3 AM |
28913 | + } |
28914 | + spin_unlock(&files->spin); | |
c06a8ce3 | 28915 | + pr("done\n"); |
1facf9fc | 28916 | + |
c06a8ce3 | 28917 | +#undef pr |
1facf9fc | 28918 | + au_plevel = plevel; |
1facf9fc | 28919 | +} |
28920 | + | |
28921 | +/* ---------------------------------------------------------------------- */ | |
28922 | + | |
28923 | +/* module parameter */ | |
28924 | +static char *aufs_sysrq_key = "a"; | |
28925 | +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO); | |
28926 | +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME); | |
28927 | + | |
0c5527e5 | 28928 | +static void au_sysrq(int key __maybe_unused) |
1facf9fc | 28929 | +{ |
1facf9fc | 28930 | + struct au_sbinfo *sbinfo; |
28931 | + | |
027c5e7a | 28932 | + lockdep_off(); |
53392da6 | 28933 | + au_sbilist_lock(); |
e49829fe | 28934 | + list_for_each_entry(sbinfo, &au_sbilist.head, si_list) |
1facf9fc | 28935 | + sysrq_sb(sbinfo->si_sb); |
53392da6 | 28936 | + au_sbilist_unlock(); |
027c5e7a | 28937 | + lockdep_on(); |
1facf9fc | 28938 | +} |
28939 | + | |
28940 | +static struct sysrq_key_op au_sysrq_op = { | |
28941 | + .handler = au_sysrq, | |
28942 | + .help_msg = "Aufs", | |
28943 | + .action_msg = "Aufs", | |
28944 | + .enable_mask = SYSRQ_ENABLE_DUMP | |
28945 | +}; | |
28946 | + | |
28947 | +/* ---------------------------------------------------------------------- */ | |
28948 | + | |
28949 | +int __init au_sysrq_init(void) | |
28950 | +{ | |
28951 | + int err; | |
28952 | + char key; | |
28953 | + | |
28954 | + err = -1; | |
28955 | + key = *aufs_sysrq_key; | |
28956 | + if ('a' <= key && key <= 'z') | |
28957 | + err = register_sysrq_key(key, &au_sysrq_op); | |
28958 | + if (unlikely(err)) | |
4a4d8108 | 28959 | + pr_err("err %d, sysrq=%c\n", err, key); |
1facf9fc | 28960 | + return err; |
28961 | +} | |
28962 | + | |
28963 | +void au_sysrq_fin(void) | |
28964 | +{ | |
28965 | + int err; | |
076b876e | 28966 | + |
1facf9fc | 28967 | + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op); |
28968 | + if (unlikely(err)) | |
4a4d8108 | 28969 | + pr_err("err %d (ignored)\n", err); |
1facf9fc | 28970 | +} |
7f207e10 AM |
28971 | diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c |
28972 | --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 28973 | +++ linux/fs/aufs/vdir.c 2015-06-28 17:35:44.351383872 +0200 |
b912730e | 28974 | @@ -0,0 +1,888 @@ |
1facf9fc | 28975 | +/* |
2000de60 | 28976 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28977 | + * |
28978 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28979 | + * it under the terms of the GNU General Public License as published by | |
28980 | + * the Free Software Foundation; either version 2 of the License, or | |
28981 | + * (at your option) any later version. | |
dece6358 AM |
28982 | + * |
28983 | + * This program is distributed in the hope that it will be useful, | |
28984 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28985 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28986 | + * GNU General Public License for more details. | |
28987 | + * | |
28988 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28989 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28990 | + */ |
28991 | + | |
28992 | +/* | |
28993 | + * virtual or vertical directory | |
28994 | + */ | |
28995 | + | |
28996 | +#include "aufs.h" | |
28997 | + | |
dece6358 | 28998 | +static unsigned int calc_size(int nlen) |
1facf9fc | 28999 | +{ |
dece6358 | 29000 | + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t)); |
1facf9fc | 29001 | +} |
29002 | + | |
29003 | +static int set_deblk_end(union au_vdir_deblk_p *p, | |
29004 | + union au_vdir_deblk_p *deblk_end) | |
29005 | +{ | |
29006 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) { | |
29007 | + p->de->de_str.len = 0; | |
29008 | + /* smp_mb(); */ | |
29009 | + return 0; | |
29010 | + } | |
29011 | + return -1; /* error */ | |
29012 | +} | |
29013 | + | |
29014 | +/* returns true or false */ | |
29015 | +static int is_deblk_end(union au_vdir_deblk_p *p, | |
29016 | + union au_vdir_deblk_p *deblk_end) | |
29017 | +{ | |
29018 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) | |
29019 | + return !p->de->de_str.len; | |
29020 | + return 1; | |
29021 | +} | |
29022 | + | |
29023 | +static unsigned char *last_deblk(struct au_vdir *vdir) | |
29024 | +{ | |
29025 | + return vdir->vd_deblk[vdir->vd_nblk - 1]; | |
29026 | +} | |
29027 | + | |
29028 | +/* ---------------------------------------------------------------------- */ | |
29029 | + | |
1308ab2a | 29030 | +/* estimate the apropriate size for name hash table */ |
29031 | +unsigned int au_rdhash_est(loff_t sz) | |
29032 | +{ | |
29033 | + unsigned int n; | |
29034 | + | |
29035 | + n = UINT_MAX; | |
29036 | + sz >>= 10; | |
29037 | + if (sz < n) | |
29038 | + n = sz; | |
29039 | + if (sz < AUFS_RDHASH_DEF) | |
29040 | + n = AUFS_RDHASH_DEF; | |
4a4d8108 | 29041 | + /* pr_info("n %u\n", n); */ |
1308ab2a | 29042 | + return n; |
29043 | +} | |
29044 | + | |
1facf9fc | 29045 | +/* |
29046 | + * the allocated memory has to be freed by | |
dece6358 | 29047 | + * au_nhash_wh_free() or au_nhash_de_free(). |
1facf9fc | 29048 | + */ |
dece6358 | 29049 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp) |
1facf9fc | 29050 | +{ |
1facf9fc | 29051 | + struct hlist_head *head; |
dece6358 | 29052 | + unsigned int u; |
076b876e | 29053 | + size_t sz; |
1facf9fc | 29054 | + |
076b876e AM |
29055 | + sz = sizeof(*nhash->nh_head) * num_hash; |
29056 | + head = kmalloc(sz, gfp); | |
dece6358 AM |
29057 | + if (head) { |
29058 | + nhash->nh_num = num_hash; | |
29059 | + nhash->nh_head = head; | |
29060 | + for (u = 0; u < num_hash; u++) | |
1facf9fc | 29061 | + INIT_HLIST_HEAD(head++); |
dece6358 | 29062 | + return 0; /* success */ |
1facf9fc | 29063 | + } |
1facf9fc | 29064 | + |
dece6358 | 29065 | + return -ENOMEM; |
1facf9fc | 29066 | +} |
29067 | + | |
dece6358 AM |
29068 | +static void nhash_count(struct hlist_head *head) |
29069 | +{ | |
29070 | +#if 0 | |
29071 | + unsigned long n; | |
29072 | + struct hlist_node *pos; | |
29073 | + | |
29074 | + n = 0; | |
29075 | + hlist_for_each(pos, head) | |
29076 | + n++; | |
4a4d8108 | 29077 | + pr_info("%lu\n", n); |
dece6358 AM |
29078 | +#endif |
29079 | +} | |
29080 | + | |
29081 | +static void au_nhash_wh_do_free(struct hlist_head *head) | |
1facf9fc | 29082 | +{ |
c06a8ce3 AM |
29083 | + struct au_vdir_wh *pos; |
29084 | + struct hlist_node *node; | |
1facf9fc | 29085 | + |
c06a8ce3 AM |
29086 | + hlist_for_each_entry_safe(pos, node, head, wh_hash) |
29087 | + kfree(pos); | |
1facf9fc | 29088 | +} |
29089 | + | |
dece6358 | 29090 | +static void au_nhash_de_do_free(struct hlist_head *head) |
1facf9fc | 29091 | +{ |
c06a8ce3 AM |
29092 | + struct au_vdir_dehstr *pos; |
29093 | + struct hlist_node *node; | |
1facf9fc | 29094 | + |
c06a8ce3 AM |
29095 | + hlist_for_each_entry_safe(pos, node, head, hash) |
29096 | + au_cache_free_vdir_dehstr(pos); | |
1facf9fc | 29097 | +} |
29098 | + | |
dece6358 AM |
29099 | +static void au_nhash_do_free(struct au_nhash *nhash, |
29100 | + void (*free)(struct hlist_head *head)) | |
1facf9fc | 29101 | +{ |
1308ab2a | 29102 | + unsigned int n; |
1facf9fc | 29103 | + struct hlist_head *head; |
1facf9fc | 29104 | + |
dece6358 | 29105 | + n = nhash->nh_num; |
1308ab2a | 29106 | + if (!n) |
29107 | + return; | |
29108 | + | |
dece6358 | 29109 | + head = nhash->nh_head; |
1308ab2a | 29110 | + while (n-- > 0) { |
dece6358 AM |
29111 | + nhash_count(head); |
29112 | + free(head++); | |
1facf9fc | 29113 | + } |
dece6358 | 29114 | + kfree(nhash->nh_head); |
1facf9fc | 29115 | +} |
29116 | + | |
dece6358 | 29117 | +void au_nhash_wh_free(struct au_nhash *whlist) |
1facf9fc | 29118 | +{ |
dece6358 AM |
29119 | + au_nhash_do_free(whlist, au_nhash_wh_do_free); |
29120 | +} | |
1facf9fc | 29121 | + |
dece6358 AM |
29122 | +static void au_nhash_de_free(struct au_nhash *delist) |
29123 | +{ | |
29124 | + au_nhash_do_free(delist, au_nhash_de_do_free); | |
1facf9fc | 29125 | +} |
29126 | + | |
29127 | +/* ---------------------------------------------------------------------- */ | |
29128 | + | |
29129 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, | |
29130 | + int limit) | |
29131 | +{ | |
29132 | + int num; | |
29133 | + unsigned int u, n; | |
29134 | + struct hlist_head *head; | |
c06a8ce3 | 29135 | + struct au_vdir_wh *pos; |
1facf9fc | 29136 | + |
29137 | + num = 0; | |
29138 | + n = whlist->nh_num; | |
29139 | + head = whlist->nh_head; | |
1308ab2a | 29140 | + for (u = 0; u < n; u++, head++) |
c06a8ce3 AM |
29141 | + hlist_for_each_entry(pos, head, wh_hash) |
29142 | + if (pos->wh_bindex == btgt && ++num > limit) | |
1facf9fc | 29143 | + return 1; |
1facf9fc | 29144 | + return 0; |
29145 | +} | |
29146 | + | |
29147 | +static struct hlist_head *au_name_hash(struct au_nhash *nhash, | |
dece6358 | 29148 | + unsigned char *name, |
1facf9fc | 29149 | + unsigned int len) |
29150 | +{ | |
dece6358 AM |
29151 | + unsigned int v; |
29152 | + /* const unsigned int magic_bit = 12; */ | |
29153 | + | |
1308ab2a | 29154 | + AuDebugOn(!nhash->nh_num || !nhash->nh_head); |
29155 | + | |
dece6358 AM |
29156 | + v = 0; |
29157 | + while (len--) | |
29158 | + v += *name++; | |
29159 | + /* v = hash_long(v, magic_bit); */ | |
29160 | + v %= nhash->nh_num; | |
29161 | + return nhash->nh_head + v; | |
29162 | +} | |
29163 | + | |
29164 | +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name, | |
29165 | + int nlen) | |
29166 | +{ | |
29167 | + return str->len == nlen && !memcmp(str->name, name, nlen); | |
1facf9fc | 29168 | +} |
29169 | + | |
29170 | +/* returns found or not */ | |
dece6358 | 29171 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen) |
1facf9fc | 29172 | +{ |
29173 | + struct hlist_head *head; | |
c06a8ce3 | 29174 | + struct au_vdir_wh *pos; |
1facf9fc | 29175 | + struct au_vdir_destr *str; |
29176 | + | |
dece6358 | 29177 | + head = au_name_hash(whlist, name, nlen); |
c06a8ce3 AM |
29178 | + hlist_for_each_entry(pos, head, wh_hash) { |
29179 | + str = &pos->wh_str; | |
1facf9fc | 29180 | + AuDbg("%.*s\n", str->len, str->name); |
dece6358 AM |
29181 | + if (au_nhash_test_name(str, name, nlen)) |
29182 | + return 1; | |
29183 | + } | |
29184 | + return 0; | |
29185 | +} | |
29186 | + | |
29187 | +/* returns found(true) or not */ | |
29188 | +static int test_known(struct au_nhash *delist, char *name, int nlen) | |
29189 | +{ | |
29190 | + struct hlist_head *head; | |
c06a8ce3 | 29191 | + struct au_vdir_dehstr *pos; |
dece6358 AM |
29192 | + struct au_vdir_destr *str; |
29193 | + | |
29194 | + head = au_name_hash(delist, name, nlen); | |
c06a8ce3 AM |
29195 | + hlist_for_each_entry(pos, head, hash) { |
29196 | + str = pos->str; | |
dece6358 AM |
29197 | + AuDbg("%.*s\n", str->len, str->name); |
29198 | + if (au_nhash_test_name(str, name, nlen)) | |
1facf9fc | 29199 | + return 1; |
29200 | + } | |
29201 | + return 0; | |
29202 | +} | |
29203 | + | |
dece6358 AM |
29204 | +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino, |
29205 | + unsigned char d_type) | |
29206 | +{ | |
29207 | +#ifdef CONFIG_AUFS_SHWH | |
29208 | + wh->wh_ino = ino; | |
29209 | + wh->wh_type = d_type; | |
29210 | +#endif | |
29211 | +} | |
29212 | + | |
29213 | +/* ---------------------------------------------------------------------- */ | |
29214 | + | |
29215 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
29216 | + unsigned int d_type, aufs_bindex_t bindex, | |
29217 | + unsigned char shwh) | |
1facf9fc | 29218 | +{ |
29219 | + int err; | |
29220 | + struct au_vdir_destr *str; | |
29221 | + struct au_vdir_wh *wh; | |
29222 | + | |
dece6358 | 29223 | + AuDbg("%.*s\n", nlen, name); |
1308ab2a | 29224 | + AuDebugOn(!whlist->nh_num || !whlist->nh_head); |
29225 | + | |
1facf9fc | 29226 | + err = -ENOMEM; |
dece6358 | 29227 | + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS); |
1facf9fc | 29228 | + if (unlikely(!wh)) |
29229 | + goto out; | |
29230 | + | |
29231 | + err = 0; | |
29232 | + wh->wh_bindex = bindex; | |
dece6358 AM |
29233 | + if (shwh) |
29234 | + au_shwh_init_wh(wh, ino, d_type); | |
1facf9fc | 29235 | + str = &wh->wh_str; |
dece6358 AM |
29236 | + str->len = nlen; |
29237 | + memcpy(str->name, name, nlen); | |
29238 | + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen)); | |
1facf9fc | 29239 | + /* smp_mb(); */ |
29240 | + | |
4f0767ce | 29241 | +out: |
1facf9fc | 29242 | + return err; |
29243 | +} | |
29244 | + | |
1facf9fc | 29245 | +static int append_deblk(struct au_vdir *vdir) |
29246 | +{ | |
29247 | + int err; | |
dece6358 | 29248 | + unsigned long ul; |
1facf9fc | 29249 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; |
29250 | + union au_vdir_deblk_p p, deblk_end; | |
29251 | + unsigned char **o; | |
29252 | + | |
29253 | + err = -ENOMEM; | |
dece6358 AM |
29254 | + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1), |
29255 | + GFP_NOFS); | |
1facf9fc | 29256 | + if (unlikely(!o)) |
29257 | + goto out; | |
29258 | + | |
29259 | + vdir->vd_deblk = o; | |
29260 | + p.deblk = kmalloc(deblk_sz, GFP_NOFS); | |
29261 | + if (p.deblk) { | |
29262 | + ul = vdir->vd_nblk++; | |
29263 | + vdir->vd_deblk[ul] = p.deblk; | |
29264 | + vdir->vd_last.ul = ul; | |
29265 | + vdir->vd_last.p.deblk = p.deblk; | |
29266 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29267 | + err = set_deblk_end(&p, &deblk_end); | |
29268 | + } | |
29269 | + | |
4f0767ce | 29270 | +out: |
1facf9fc | 29271 | + return err; |
29272 | +} | |
29273 | + | |
dece6358 AM |
29274 | +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino, |
29275 | + unsigned int d_type, struct au_nhash *delist) | |
29276 | +{ | |
29277 | + int err; | |
29278 | + unsigned int sz; | |
29279 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; | |
29280 | + union au_vdir_deblk_p p, *room, deblk_end; | |
29281 | + struct au_vdir_dehstr *dehstr; | |
29282 | + | |
29283 | + p.deblk = last_deblk(vdir); | |
29284 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29285 | + room = &vdir->vd_last.p; | |
29286 | + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk | |
29287 | + || !is_deblk_end(room, &deblk_end)); | |
29288 | + | |
29289 | + sz = calc_size(nlen); | |
29290 | + if (unlikely(sz > deblk_end.deblk - room->deblk)) { | |
29291 | + err = append_deblk(vdir); | |
29292 | + if (unlikely(err)) | |
29293 | + goto out; | |
29294 | + | |
29295 | + p.deblk = last_deblk(vdir); | |
29296 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29297 | + /* smp_mb(); */ | |
29298 | + AuDebugOn(room->deblk != p.deblk); | |
29299 | + } | |
29300 | + | |
29301 | + err = -ENOMEM; | |
4a4d8108 | 29302 | + dehstr = au_cache_alloc_vdir_dehstr(); |
dece6358 AM |
29303 | + if (unlikely(!dehstr)) |
29304 | + goto out; | |
29305 | + | |
29306 | + dehstr->str = &room->de->de_str; | |
29307 | + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen)); | |
29308 | + room->de->de_ino = ino; | |
29309 | + room->de->de_type = d_type; | |
29310 | + room->de->de_str.len = nlen; | |
29311 | + memcpy(room->de->de_str.name, name, nlen); | |
29312 | + | |
29313 | + err = 0; | |
29314 | + room->deblk += sz; | |
29315 | + if (unlikely(set_deblk_end(room, &deblk_end))) | |
29316 | + err = append_deblk(vdir); | |
29317 | + /* smp_mb(); */ | |
29318 | + | |
4f0767ce | 29319 | +out: |
dece6358 AM |
29320 | + return err; |
29321 | +} | |
29322 | + | |
29323 | +/* ---------------------------------------------------------------------- */ | |
29324 | + | |
29325 | +void au_vdir_free(struct au_vdir *vdir) | |
29326 | +{ | |
29327 | + unsigned char **deblk; | |
29328 | + | |
29329 | + deblk = vdir->vd_deblk; | |
29330 | + while (vdir->vd_nblk--) | |
29331 | + kfree(*deblk++); | |
29332 | + kfree(vdir->vd_deblk); | |
29333 | + au_cache_free_vdir(vdir); | |
29334 | +} | |
29335 | + | |
1308ab2a | 29336 | +static struct au_vdir *alloc_vdir(struct file *file) |
1facf9fc | 29337 | +{ |
29338 | + struct au_vdir *vdir; | |
1308ab2a | 29339 | + struct super_block *sb; |
1facf9fc | 29340 | + int err; |
29341 | + | |
2000de60 | 29342 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
29343 | + SiMustAnyLock(sb); |
29344 | + | |
1facf9fc | 29345 | + err = -ENOMEM; |
29346 | + vdir = au_cache_alloc_vdir(); | |
29347 | + if (unlikely(!vdir)) | |
29348 | + goto out; | |
29349 | + | |
29350 | + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS); | |
29351 | + if (unlikely(!vdir->vd_deblk)) | |
29352 | + goto out_free; | |
29353 | + | |
29354 | + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk; | |
1308ab2a | 29355 | + if (!vdir->vd_deblk_sz) { |
29356 | + /* estimate the apropriate size for deblk */ | |
29357 | + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL); | |
4a4d8108 | 29358 | + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */ |
1308ab2a | 29359 | + } |
1facf9fc | 29360 | + vdir->vd_nblk = 0; |
29361 | + vdir->vd_version = 0; | |
29362 | + vdir->vd_jiffy = 0; | |
29363 | + err = append_deblk(vdir); | |
29364 | + if (!err) | |
29365 | + return vdir; /* success */ | |
29366 | + | |
29367 | + kfree(vdir->vd_deblk); | |
29368 | + | |
4f0767ce | 29369 | +out_free: |
1facf9fc | 29370 | + au_cache_free_vdir(vdir); |
4f0767ce | 29371 | +out: |
1facf9fc | 29372 | + vdir = ERR_PTR(err); |
29373 | + return vdir; | |
29374 | +} | |
29375 | + | |
29376 | +static int reinit_vdir(struct au_vdir *vdir) | |
29377 | +{ | |
29378 | + int err; | |
29379 | + union au_vdir_deblk_p p, deblk_end; | |
29380 | + | |
29381 | + while (vdir->vd_nblk > 1) { | |
29382 | + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]); | |
29383 | + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */ | |
29384 | + vdir->vd_nblk--; | |
29385 | + } | |
29386 | + p.deblk = vdir->vd_deblk[0]; | |
29387 | + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz; | |
29388 | + err = set_deblk_end(&p, &deblk_end); | |
29389 | + /* keep vd_dblk_sz */ | |
29390 | + vdir->vd_last.ul = 0; | |
29391 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
29392 | + vdir->vd_version = 0; | |
29393 | + vdir->vd_jiffy = 0; | |
29394 | + /* smp_mb(); */ | |
29395 | + return err; | |
29396 | +} | |
29397 | + | |
29398 | +/* ---------------------------------------------------------------------- */ | |
29399 | + | |
1facf9fc | 29400 | +#define AuFillVdir_CALLED 1 |
29401 | +#define AuFillVdir_WHABLE (1 << 1) | |
dece6358 | 29402 | +#define AuFillVdir_SHWH (1 << 2) |
1facf9fc | 29403 | +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name) |
7f207e10 AM |
29404 | +#define au_fset_fillvdir(flags, name) \ |
29405 | + do { (flags) |= AuFillVdir_##name; } while (0) | |
29406 | +#define au_fclr_fillvdir(flags, name) \ | |
29407 | + do { (flags) &= ~AuFillVdir_##name; } while (0) | |
1facf9fc | 29408 | + |
dece6358 AM |
29409 | +#ifndef CONFIG_AUFS_SHWH |
29410 | +#undef AuFillVdir_SHWH | |
29411 | +#define AuFillVdir_SHWH 0 | |
29412 | +#endif | |
29413 | + | |
1facf9fc | 29414 | +struct fillvdir_arg { |
392086de | 29415 | + struct dir_context ctx; |
1facf9fc | 29416 | + struct file *file; |
29417 | + struct au_vdir *vdir; | |
dece6358 AM |
29418 | + struct au_nhash delist; |
29419 | + struct au_nhash whlist; | |
1facf9fc | 29420 | + aufs_bindex_t bindex; |
29421 | + unsigned int flags; | |
29422 | + int err; | |
29423 | +}; | |
29424 | + | |
392086de | 29425 | +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen, |
1facf9fc | 29426 | + loff_t offset __maybe_unused, u64 h_ino, |
29427 | + unsigned int d_type) | |
29428 | +{ | |
392086de | 29429 | + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx); |
1facf9fc | 29430 | + char *name = (void *)__name; |
29431 | + struct super_block *sb; | |
1facf9fc | 29432 | + ino_t ino; |
dece6358 | 29433 | + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH); |
1facf9fc | 29434 | + |
1facf9fc | 29435 | + arg->err = 0; |
2000de60 | 29436 | + sb = arg->file->f_path.dentry->d_sb; |
1facf9fc | 29437 | + au_fset_fillvdir(arg->flags, CALLED); |
29438 | + /* smp_mb(); */ | |
dece6358 | 29439 | + if (nlen <= AUFS_WH_PFX_LEN |
1facf9fc | 29440 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { |
dece6358 AM |
29441 | + if (test_known(&arg->delist, name, nlen) |
29442 | + || au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
29443 | + goto out; /* already exists or whiteouted */ | |
1facf9fc | 29444 | + |
dece6358 | 29445 | + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino); |
4a4d8108 AM |
29446 | + if (!arg->err) { |
29447 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) | |
29448 | + d_type = DT_UNKNOWN; | |
dece6358 AM |
29449 | + arg->err = append_de(arg->vdir, name, nlen, ino, |
29450 | + d_type, &arg->delist); | |
4a4d8108 | 29451 | + } |
1facf9fc | 29452 | + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) { |
29453 | + name += AUFS_WH_PFX_LEN; | |
dece6358 AM |
29454 | + nlen -= AUFS_WH_PFX_LEN; |
29455 | + if (au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
29456 | + goto out; /* already whiteouted */ | |
1facf9fc | 29457 | + |
dece6358 AM |
29458 | + if (shwh) |
29459 | + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type, | |
29460 | + &ino); | |
4a4d8108 AM |
29461 | + if (!arg->err) { |
29462 | + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN) | |
29463 | + d_type = DT_UNKNOWN; | |
1facf9fc | 29464 | + arg->err = au_nhash_append_wh |
dece6358 AM |
29465 | + (&arg->whlist, name, nlen, ino, d_type, |
29466 | + arg->bindex, shwh); | |
4a4d8108 | 29467 | + } |
1facf9fc | 29468 | + } |
29469 | + | |
4f0767ce | 29470 | +out: |
1facf9fc | 29471 | + if (!arg->err) |
29472 | + arg->vdir->vd_jiffy = jiffies; | |
29473 | + /* smp_mb(); */ | |
29474 | + AuTraceErr(arg->err); | |
29475 | + return arg->err; | |
29476 | +} | |
29477 | + | |
dece6358 AM |
29478 | +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir, |
29479 | + struct au_nhash *whlist, struct au_nhash *delist) | |
29480 | +{ | |
29481 | +#ifdef CONFIG_AUFS_SHWH | |
29482 | + int err; | |
29483 | + unsigned int nh, u; | |
29484 | + struct hlist_head *head; | |
c06a8ce3 AM |
29485 | + struct au_vdir_wh *pos; |
29486 | + struct hlist_node *n; | |
dece6358 AM |
29487 | + char *p, *o; |
29488 | + struct au_vdir_destr *destr; | |
29489 | + | |
29490 | + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH)); | |
29491 | + | |
29492 | + err = -ENOMEM; | |
537831f9 | 29493 | + o = p = (void *)__get_free_page(GFP_NOFS); |
dece6358 AM |
29494 | + if (unlikely(!p)) |
29495 | + goto out; | |
29496 | + | |
29497 | + err = 0; | |
29498 | + nh = whlist->nh_num; | |
29499 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
29500 | + p += AUFS_WH_PFX_LEN; | |
29501 | + for (u = 0; u < nh; u++) { | |
29502 | + head = whlist->nh_head + u; | |
c06a8ce3 AM |
29503 | + hlist_for_each_entry_safe(pos, n, head, wh_hash) { |
29504 | + destr = &pos->wh_str; | |
dece6358 AM |
29505 | + memcpy(p, destr->name, destr->len); |
29506 | + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN, | |
c06a8ce3 | 29507 | + pos->wh_ino, pos->wh_type, delist); |
dece6358 AM |
29508 | + if (unlikely(err)) |
29509 | + break; | |
29510 | + } | |
29511 | + } | |
29512 | + | |
537831f9 | 29513 | + free_page((unsigned long)o); |
dece6358 | 29514 | + |
4f0767ce | 29515 | +out: |
dece6358 AM |
29516 | + AuTraceErr(err); |
29517 | + return err; | |
29518 | +#else | |
29519 | + return 0; | |
29520 | +#endif | |
29521 | +} | |
29522 | + | |
1facf9fc | 29523 | +static int au_do_read_vdir(struct fillvdir_arg *arg) |
29524 | +{ | |
29525 | + int err; | |
dece6358 | 29526 | + unsigned int rdhash; |
1facf9fc | 29527 | + loff_t offset; |
dece6358 AM |
29528 | + aufs_bindex_t bend, bindex, bstart; |
29529 | + unsigned char shwh; | |
1facf9fc | 29530 | + struct file *hf, *file; |
29531 | + struct super_block *sb; | |
29532 | + | |
1facf9fc | 29533 | + file = arg->file; |
2000de60 | 29534 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
29535 | + SiMustAnyLock(sb); |
29536 | + | |
29537 | + rdhash = au_sbi(sb)->si_rdhash; | |
1308ab2a | 29538 | + if (!rdhash) |
29539 | + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL)); | |
dece6358 AM |
29540 | + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS); |
29541 | + if (unlikely(err)) | |
1facf9fc | 29542 | + goto out; |
dece6358 AM |
29543 | + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS); |
29544 | + if (unlikely(err)) | |
1facf9fc | 29545 | + goto out_delist; |
29546 | + | |
29547 | + err = 0; | |
29548 | + arg->flags = 0; | |
dece6358 AM |
29549 | + shwh = 0; |
29550 | + if (au_opt_test(au_mntflags(sb), SHWH)) { | |
29551 | + shwh = 1; | |
29552 | + au_fset_fillvdir(arg->flags, SHWH); | |
29553 | + } | |
29554 | + bstart = au_fbstart(file); | |
4a4d8108 | 29555 | + bend = au_fbend_dir(file); |
dece6358 | 29556 | + for (bindex = bstart; !err && bindex <= bend; bindex++) { |
4a4d8108 | 29557 | + hf = au_hf_dir(file, bindex); |
1facf9fc | 29558 | + if (!hf) |
29559 | + continue; | |
29560 | + | |
29561 | + offset = vfsub_llseek(hf, 0, SEEK_SET); | |
29562 | + err = offset; | |
29563 | + if (unlikely(offset)) | |
29564 | + break; | |
29565 | + | |
29566 | + arg->bindex = bindex; | |
29567 | + au_fclr_fillvdir(arg->flags, WHABLE); | |
dece6358 AM |
29568 | + if (shwh |
29569 | + || (bindex != bend | |
29570 | + && au_br_whable(au_sbr_perm(sb, bindex)))) | |
1facf9fc | 29571 | + au_fset_fillvdir(arg->flags, WHABLE); |
29572 | + do { | |
29573 | + arg->err = 0; | |
29574 | + au_fclr_fillvdir(arg->flags, CALLED); | |
29575 | + /* smp_mb(); */ | |
392086de | 29576 | + err = vfsub_iterate_dir(hf, &arg->ctx); |
1facf9fc | 29577 | + if (err >= 0) |
29578 | + err = arg->err; | |
29579 | + } while (!err && au_ftest_fillvdir(arg->flags, CALLED)); | |
392086de AM |
29580 | + |
29581 | + /* | |
29582 | + * dir_relax() may be good for concurrency, but aufs should not | |
29583 | + * use it since it will cause a lockdep problem. | |
29584 | + */ | |
1facf9fc | 29585 | + } |
dece6358 AM |
29586 | + |
29587 | + if (!err && shwh) | |
29588 | + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist); | |
29589 | + | |
29590 | + au_nhash_wh_free(&arg->whlist); | |
1facf9fc | 29591 | + |
4f0767ce | 29592 | +out_delist: |
dece6358 | 29593 | + au_nhash_de_free(&arg->delist); |
4f0767ce | 29594 | +out: |
1facf9fc | 29595 | + return err; |
29596 | +} | |
29597 | + | |
29598 | +static int read_vdir(struct file *file, int may_read) | |
29599 | +{ | |
29600 | + int err; | |
29601 | + unsigned long expire; | |
29602 | + unsigned char do_read; | |
392086de AM |
29603 | + struct fillvdir_arg arg = { |
29604 | + .ctx = { | |
2000de60 | 29605 | + .actor = fillvdir |
392086de AM |
29606 | + } |
29607 | + }; | |
1facf9fc | 29608 | + struct inode *inode; |
29609 | + struct au_vdir *vdir, *allocated; | |
29610 | + | |
29611 | + err = 0; | |
c06a8ce3 | 29612 | + inode = file_inode(file); |
1facf9fc | 29613 | + IMustLock(inode); |
dece6358 AM |
29614 | + SiMustAnyLock(inode->i_sb); |
29615 | + | |
1facf9fc | 29616 | + allocated = NULL; |
29617 | + do_read = 0; | |
29618 | + expire = au_sbi(inode->i_sb)->si_rdcache; | |
29619 | + vdir = au_ivdir(inode); | |
29620 | + if (!vdir) { | |
29621 | + do_read = 1; | |
1308ab2a | 29622 | + vdir = alloc_vdir(file); |
1facf9fc | 29623 | + err = PTR_ERR(vdir); |
29624 | + if (IS_ERR(vdir)) | |
29625 | + goto out; | |
29626 | + err = 0; | |
29627 | + allocated = vdir; | |
29628 | + } else if (may_read | |
29629 | + && (inode->i_version != vdir->vd_version | |
29630 | + || time_after(jiffies, vdir->vd_jiffy + expire))) { | |
29631 | + do_read = 1; | |
29632 | + err = reinit_vdir(vdir); | |
29633 | + if (unlikely(err)) | |
29634 | + goto out; | |
29635 | + } | |
29636 | + | |
29637 | + if (!do_read) | |
29638 | + return 0; /* success */ | |
29639 | + | |
29640 | + arg.file = file; | |
29641 | + arg.vdir = vdir; | |
29642 | + err = au_do_read_vdir(&arg); | |
29643 | + if (!err) { | |
392086de | 29644 | + /* file->f_pos = 0; */ /* todo: ctx->pos? */ |
1facf9fc | 29645 | + vdir->vd_version = inode->i_version; |
29646 | + vdir->vd_last.ul = 0; | |
29647 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
29648 | + if (allocated) | |
29649 | + au_set_ivdir(inode, allocated); | |
29650 | + } else if (allocated) | |
29651 | + au_vdir_free(allocated); | |
29652 | + | |
4f0767ce | 29653 | +out: |
1facf9fc | 29654 | + return err; |
29655 | +} | |
29656 | + | |
29657 | +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src) | |
29658 | +{ | |
29659 | + int err, rerr; | |
29660 | + unsigned long ul, n; | |
29661 | + const unsigned int deblk_sz = src->vd_deblk_sz; | |
29662 | + | |
29663 | + AuDebugOn(tgt->vd_nblk != 1); | |
29664 | + | |
29665 | + err = -ENOMEM; | |
29666 | + if (tgt->vd_nblk < src->vd_nblk) { | |
29667 | + unsigned char **p; | |
29668 | + | |
dece6358 AM |
29669 | + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk, |
29670 | + GFP_NOFS); | |
1facf9fc | 29671 | + if (unlikely(!p)) |
29672 | + goto out; | |
29673 | + tgt->vd_deblk = p; | |
29674 | + } | |
29675 | + | |
1308ab2a | 29676 | + if (tgt->vd_deblk_sz != deblk_sz) { |
29677 | + unsigned char *p; | |
29678 | + | |
29679 | + tgt->vd_deblk_sz = deblk_sz; | |
29680 | + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS); | |
29681 | + if (unlikely(!p)) | |
29682 | + goto out; | |
29683 | + tgt->vd_deblk[0] = p; | |
29684 | + } | |
1facf9fc | 29685 | + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz); |
1facf9fc | 29686 | + tgt->vd_version = src->vd_version; |
29687 | + tgt->vd_jiffy = src->vd_jiffy; | |
29688 | + | |
29689 | + n = src->vd_nblk; | |
29690 | + for (ul = 1; ul < n; ul++) { | |
dece6358 AM |
29691 | + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz, |
29692 | + GFP_NOFS); | |
29693 | + if (unlikely(!tgt->vd_deblk[ul])) | |
1facf9fc | 29694 | + goto out; |
1308ab2a | 29695 | + tgt->vd_nblk++; |
1facf9fc | 29696 | + } |
1308ab2a | 29697 | + tgt->vd_nblk = n; |
29698 | + tgt->vd_last.ul = tgt->vd_last.ul; | |
29699 | + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul]; | |
29700 | + tgt->vd_last.p.deblk += src->vd_last.p.deblk | |
29701 | + - src->vd_deblk[src->vd_last.ul]; | |
1facf9fc | 29702 | + /* smp_mb(); */ |
29703 | + return 0; /* success */ | |
29704 | + | |
4f0767ce | 29705 | +out: |
1facf9fc | 29706 | + rerr = reinit_vdir(tgt); |
29707 | + BUG_ON(rerr); | |
29708 | + return err; | |
29709 | +} | |
29710 | + | |
29711 | +int au_vdir_init(struct file *file) | |
29712 | +{ | |
29713 | + int err; | |
29714 | + struct inode *inode; | |
29715 | + struct au_vdir *vdir_cache, *allocated; | |
29716 | + | |
392086de | 29717 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 29718 | + err = read_vdir(file, !file->f_pos); |
29719 | + if (unlikely(err)) | |
29720 | + goto out; | |
29721 | + | |
29722 | + allocated = NULL; | |
29723 | + vdir_cache = au_fvdir_cache(file); | |
29724 | + if (!vdir_cache) { | |
1308ab2a | 29725 | + vdir_cache = alloc_vdir(file); |
1facf9fc | 29726 | + err = PTR_ERR(vdir_cache); |
29727 | + if (IS_ERR(vdir_cache)) | |
29728 | + goto out; | |
29729 | + allocated = vdir_cache; | |
29730 | + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) { | |
392086de | 29731 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 29732 | + err = reinit_vdir(vdir_cache); |
29733 | + if (unlikely(err)) | |
29734 | + goto out; | |
29735 | + } else | |
29736 | + return 0; /* success */ | |
29737 | + | |
c06a8ce3 | 29738 | + inode = file_inode(file); |
1facf9fc | 29739 | + err = copy_vdir(vdir_cache, au_ivdir(inode)); |
29740 | + if (!err) { | |
29741 | + file->f_version = inode->i_version; | |
29742 | + if (allocated) | |
29743 | + au_set_fvdir_cache(file, allocated); | |
29744 | + } else if (allocated) | |
29745 | + au_vdir_free(allocated); | |
29746 | + | |
4f0767ce | 29747 | +out: |
1facf9fc | 29748 | + return err; |
29749 | +} | |
29750 | + | |
29751 | +static loff_t calc_offset(struct au_vdir *vdir) | |
29752 | +{ | |
29753 | + loff_t offset; | |
29754 | + union au_vdir_deblk_p p; | |
29755 | + | |
29756 | + p.deblk = vdir->vd_deblk[vdir->vd_last.ul]; | |
29757 | + offset = vdir->vd_last.p.deblk - p.deblk; | |
29758 | + offset += vdir->vd_deblk_sz * vdir->vd_last.ul; | |
29759 | + return offset; | |
29760 | +} | |
29761 | + | |
29762 | +/* returns true or false */ | |
392086de | 29763 | +static int seek_vdir(struct file *file, struct dir_context *ctx) |
1facf9fc | 29764 | +{ |
29765 | + int valid; | |
29766 | + unsigned int deblk_sz; | |
29767 | + unsigned long ul, n; | |
29768 | + loff_t offset; | |
29769 | + union au_vdir_deblk_p p, deblk_end; | |
29770 | + struct au_vdir *vdir_cache; | |
29771 | + | |
29772 | + valid = 1; | |
29773 | + vdir_cache = au_fvdir_cache(file); | |
29774 | + offset = calc_offset(vdir_cache); | |
29775 | + AuDbg("offset %lld\n", offset); | |
392086de | 29776 | + if (ctx->pos == offset) |
1facf9fc | 29777 | + goto out; |
29778 | + | |
29779 | + vdir_cache->vd_last.ul = 0; | |
29780 | + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0]; | |
392086de | 29781 | + if (!ctx->pos) |
1facf9fc | 29782 | + goto out; |
29783 | + | |
29784 | + valid = 0; | |
29785 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
392086de | 29786 | + ul = div64_u64(ctx->pos, deblk_sz); |
1facf9fc | 29787 | + AuDbg("ul %lu\n", ul); |
29788 | + if (ul >= vdir_cache->vd_nblk) | |
29789 | + goto out; | |
29790 | + | |
29791 | + n = vdir_cache->vd_nblk; | |
29792 | + for (; ul < n; ul++) { | |
29793 | + p.deblk = vdir_cache->vd_deblk[ul]; | |
29794 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29795 | + offset = ul; | |
29796 | + offset *= deblk_sz; | |
392086de | 29797 | + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) { |
1facf9fc | 29798 | + unsigned int l; |
29799 | + | |
29800 | + l = calc_size(p.de->de_str.len); | |
29801 | + offset += l; | |
29802 | + p.deblk += l; | |
29803 | + } | |
29804 | + if (!is_deblk_end(&p, &deblk_end)) { | |
29805 | + valid = 1; | |
29806 | + vdir_cache->vd_last.ul = ul; | |
29807 | + vdir_cache->vd_last.p = p; | |
29808 | + break; | |
29809 | + } | |
29810 | + } | |
29811 | + | |
4f0767ce | 29812 | +out: |
1facf9fc | 29813 | + /* smp_mb(); */ |
29814 | + AuTraceErr(!valid); | |
29815 | + return valid; | |
29816 | +} | |
29817 | + | |
392086de | 29818 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx) |
1facf9fc | 29819 | +{ |
1facf9fc | 29820 | + unsigned int l, deblk_sz; |
29821 | + union au_vdir_deblk_p deblk_end; | |
29822 | + struct au_vdir *vdir_cache; | |
29823 | + struct au_vdir_de *de; | |
29824 | + | |
29825 | + vdir_cache = au_fvdir_cache(file); | |
392086de | 29826 | + if (!seek_vdir(file, ctx)) |
1facf9fc | 29827 | + return 0; |
29828 | + | |
29829 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
29830 | + while (1) { | |
29831 | + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
29832 | + deblk_end.deblk += deblk_sz; | |
29833 | + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) { | |
29834 | + de = vdir_cache->vd_last.p.de; | |
29835 | + AuDbg("%.*s, off%lld, i%lu, dt%d\n", | |
392086de | 29836 | + de->de_str.len, de->de_str.name, ctx->pos, |
1facf9fc | 29837 | + (unsigned long)de->de_ino, de->de_type); |
392086de AM |
29838 | + if (unlikely(!dir_emit(ctx, de->de_str.name, |
29839 | + de->de_str.len, de->de_ino, | |
29840 | + de->de_type))) { | |
1facf9fc | 29841 | + /* todo: ignore the error caused by udba? */ |
29842 | + /* return err; */ | |
29843 | + return 0; | |
29844 | + } | |
29845 | + | |
29846 | + l = calc_size(de->de_str.len); | |
29847 | + vdir_cache->vd_last.p.deblk += l; | |
392086de | 29848 | + ctx->pos += l; |
1facf9fc | 29849 | + } |
29850 | + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) { | |
29851 | + vdir_cache->vd_last.ul++; | |
29852 | + vdir_cache->vd_last.p.deblk | |
29853 | + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
392086de | 29854 | + ctx->pos = deblk_sz * vdir_cache->vd_last.ul; |
1facf9fc | 29855 | + continue; |
29856 | + } | |
29857 | + break; | |
29858 | + } | |
29859 | + | |
29860 | + /* smp_mb(); */ | |
29861 | + return 0; | |
29862 | +} | |
7f207e10 AM |
29863 | diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c |
29864 | --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
29865 | +++ linux/fs/aufs/vfsub.c 2015-06-28 17:36:09.028407078 +0200 |
29866 | @@ -0,0 +1,848 @@ | |
1facf9fc | 29867 | +/* |
2000de60 | 29868 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 29869 | + * |
29870 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29871 | + * it under the terms of the GNU General Public License as published by | |
29872 | + * the Free Software Foundation; either version 2 of the License, or | |
29873 | + * (at your option) any later version. | |
dece6358 AM |
29874 | + * |
29875 | + * This program is distributed in the hope that it will be useful, | |
29876 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29877 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29878 | + * GNU General Public License for more details. | |
29879 | + * | |
29880 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29881 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29882 | + */ |
29883 | + | |
29884 | +/* | |
29885 | + * sub-routines for VFS | |
29886 | + */ | |
29887 | + | |
dece6358 AM |
29888 | +#include <linux/namei.h> |
29889 | +#include <linux/security.h> | |
29890 | +#include <linux/splice.h> | |
1facf9fc | 29891 | +#include "aufs.h" |
29892 | + | |
29893 | +int vfsub_update_h_iattr(struct path *h_path, int *did) | |
29894 | +{ | |
29895 | + int err; | |
29896 | + struct kstat st; | |
29897 | + struct super_block *h_sb; | |
29898 | + | |
29899 | + /* for remote fs, leave work for its getattr or d_revalidate */ | |
29900 | + /* for bad i_attr fs, handle them in aufs_getattr() */ | |
29901 | + /* still some fs may acquire i_mutex. we need to skip them */ | |
29902 | + err = 0; | |
29903 | + if (!did) | |
29904 | + did = &err; | |
29905 | + h_sb = h_path->dentry->d_sb; | |
29906 | + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb)); | |
29907 | + if (*did) | |
c06a8ce3 | 29908 | + err = vfs_getattr(h_path, &st); |
1facf9fc | 29909 | + |
29910 | + return err; | |
29911 | +} | |
29912 | + | |
29913 | +/* ---------------------------------------------------------------------- */ | |
29914 | + | |
4a4d8108 | 29915 | +struct file *vfsub_dentry_open(struct path *path, int flags) |
1308ab2a | 29916 | +{ |
29917 | + struct file *file; | |
29918 | + | |
b4510431 | 29919 | + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */, |
7f207e10 | 29920 | + current_cred()); |
2cbb1c4b JR |
29921 | + if (!IS_ERR_OR_NULL(file) |
29922 | + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | |
5527c038 | 29923 | + i_readcount_inc(d_inode(path->dentry)); |
4a4d8108 | 29924 | + |
1308ab2a | 29925 | + return file; |
29926 | +} | |
29927 | + | |
1facf9fc | 29928 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode) |
29929 | +{ | |
29930 | + struct file *file; | |
29931 | + | |
2cbb1c4b | 29932 | + lockdep_off(); |
7f207e10 | 29933 | + file = filp_open(path, |
2cbb1c4b | 29934 | + oflags /* | __FMODE_NONOTIFY */, |
7f207e10 | 29935 | + mode); |
2cbb1c4b | 29936 | + lockdep_on(); |
1facf9fc | 29937 | + if (IS_ERR(file)) |
29938 | + goto out; | |
29939 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
29940 | + | |
4f0767ce | 29941 | +out: |
1facf9fc | 29942 | + return file; |
29943 | +} | |
29944 | + | |
b912730e AM |
29945 | +/* |
29946 | + * Ideally this function should call VFS:do_last() in order to keep all its | |
29947 | + * checkings. But it is very hard for aufs to regenerate several VFS internal | |
29948 | + * structure such as nameidata. This is a second (or third) best approach. | |
29949 | + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open(). | |
29950 | + */ | |
29951 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
29952 | + struct vfsub_aopen_args *args, struct au_branch *br) | |
29953 | +{ | |
29954 | + int err; | |
29955 | + struct file *file = args->file; | |
29956 | + /* copied from linux/fs/namei.c:atomic_open() */ | |
29957 | + struct dentry *const DENTRY_NOT_SET = (void *)-1UL; | |
29958 | + | |
29959 | + IMustLock(dir); | |
29960 | + AuDebugOn(!dir->i_op->atomic_open); | |
29961 | + | |
29962 | + err = au_br_test_oflag(args->open_flag, br); | |
29963 | + if (unlikely(err)) | |
29964 | + goto out; | |
29965 | + | |
29966 | + args->file->f_path.dentry = DENTRY_NOT_SET; | |
29967 | + args->file->f_path.mnt = au_br_mnt(br); | |
29968 | + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag, | |
29969 | + args->create_mode, args->opened); | |
29970 | + if (err >= 0) { | |
29971 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
29972 | + if (*args->opened & FILE_CREATED) | |
29973 | + fsnotify_create(dir, dentry); | |
29974 | + } else | |
29975 | + goto out; | |
29976 | + | |
29977 | + | |
29978 | + if (!err) { | |
29979 | + /* todo: call VFS:may_open() here */ | |
29980 | + err = open_check_o_direct(file); | |
29981 | + /* todo: ima_file_check() too? */ | |
29982 | + if (!err && (args->open_flag & __FMODE_EXEC)) | |
29983 | + err = deny_write_access(file); | |
29984 | + if (unlikely(err)) | |
29985 | + /* note that the file is created and still opened */ | |
29986 | + goto out; | |
29987 | + } | |
29988 | + | |
29989 | + atomic_inc(&br->br_count); | |
29990 | + fsnotify_open(file); | |
29991 | + | |
29992 | +out: | |
29993 | + return err; | |
29994 | +} | |
29995 | + | |
1facf9fc | 29996 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path) |
29997 | +{ | |
29998 | + int err; | |
29999 | + | |
1facf9fc | 30000 | + err = kern_path(name, flags, path); |
5527c038 | 30001 | + if (!err && d_is_positive(path->dentry)) |
1facf9fc | 30002 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ |
30003 | + return err; | |
30004 | +} | |
30005 | + | |
30006 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, | |
30007 | + int len) | |
30008 | +{ | |
30009 | + struct path path = { | |
30010 | + .mnt = NULL | |
30011 | + }; | |
30012 | + | |
1308ab2a | 30013 | + /* VFS checks it too, but by WARN_ON_ONCE() */ |
5527c038 | 30014 | + IMustLock(d_inode(parent)); |
1facf9fc | 30015 | + |
30016 | + path.dentry = lookup_one_len(name, parent, len); | |
30017 | + if (IS_ERR(path.dentry)) | |
30018 | + goto out; | |
5527c038 | 30019 | + if (d_is_positive(path.dentry)) |
1facf9fc | 30020 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ |
30021 | + | |
4f0767ce | 30022 | +out: |
4a4d8108 | 30023 | + AuTraceErrPtr(path.dentry); |
1facf9fc | 30024 | + return path.dentry; |
30025 | +} | |
30026 | + | |
b4510431 | 30027 | +void vfsub_call_lkup_one(void *args) |
2cbb1c4b | 30028 | +{ |
b4510431 AM |
30029 | + struct vfsub_lkup_one_args *a = args; |
30030 | + *a->errp = vfsub_lkup_one(a->name, a->parent); | |
2cbb1c4b JR |
30031 | +} |
30032 | + | |
1facf9fc | 30033 | +/* ---------------------------------------------------------------------- */ |
30034 | + | |
30035 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30036 | + struct dentry *d2, struct au_hinode *hdir2) | |
30037 | +{ | |
30038 | + struct dentry *d; | |
30039 | + | |
2cbb1c4b | 30040 | + lockdep_off(); |
1facf9fc | 30041 | + d = lock_rename(d1, d2); |
2cbb1c4b | 30042 | + lockdep_on(); |
4a4d8108 | 30043 | + au_hn_suspend(hdir1); |
1facf9fc | 30044 | + if (hdir1 != hdir2) |
4a4d8108 | 30045 | + au_hn_suspend(hdir2); |
1facf9fc | 30046 | + |
30047 | + return d; | |
30048 | +} | |
30049 | + | |
30050 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30051 | + struct dentry *d2, struct au_hinode *hdir2) | |
30052 | +{ | |
4a4d8108 | 30053 | + au_hn_resume(hdir1); |
1facf9fc | 30054 | + if (hdir1 != hdir2) |
4a4d8108 | 30055 | + au_hn_resume(hdir2); |
2cbb1c4b | 30056 | + lockdep_off(); |
1facf9fc | 30057 | + unlock_rename(d1, d2); |
2cbb1c4b | 30058 | + lockdep_on(); |
1facf9fc | 30059 | +} |
30060 | + | |
30061 | +/* ---------------------------------------------------------------------- */ | |
30062 | + | |
b4510431 | 30063 | +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl) |
1facf9fc | 30064 | +{ |
30065 | + int err; | |
30066 | + struct dentry *d; | |
30067 | + | |
30068 | + IMustLock(dir); | |
30069 | + | |
30070 | + d = path->dentry; | |
30071 | + path->dentry = d->d_parent; | |
b752ccd1 | 30072 | + err = security_path_mknod(path, d, mode, 0); |
1facf9fc | 30073 | + path->dentry = d; |
30074 | + if (unlikely(err)) | |
30075 | + goto out; | |
30076 | + | |
c1595e42 | 30077 | + lockdep_off(); |
b4510431 | 30078 | + err = vfs_create(dir, path->dentry, mode, want_excl); |
c1595e42 | 30079 | + lockdep_on(); |
1facf9fc | 30080 | + if (!err) { |
30081 | + struct path tmp = *path; | |
30082 | + int did; | |
30083 | + | |
30084 | + vfsub_update_h_iattr(&tmp, &did); | |
30085 | + if (did) { | |
30086 | + tmp.dentry = path->dentry->d_parent; | |
30087 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30088 | + } | |
30089 | + /*ignore*/ | |
30090 | + } | |
30091 | + | |
4f0767ce | 30092 | +out: |
1facf9fc | 30093 | + return err; |
30094 | +} | |
30095 | + | |
30096 | +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname) | |
30097 | +{ | |
30098 | + int err; | |
30099 | + struct dentry *d; | |
30100 | + | |
30101 | + IMustLock(dir); | |
30102 | + | |
30103 | + d = path->dentry; | |
30104 | + path->dentry = d->d_parent; | |
b752ccd1 | 30105 | + err = security_path_symlink(path, d, symname); |
1facf9fc | 30106 | + path->dentry = d; |
30107 | + if (unlikely(err)) | |
30108 | + goto out; | |
30109 | + | |
c1595e42 | 30110 | + lockdep_off(); |
1facf9fc | 30111 | + err = vfs_symlink(dir, path->dentry, symname); |
c1595e42 | 30112 | + lockdep_on(); |
1facf9fc | 30113 | + if (!err) { |
30114 | + struct path tmp = *path; | |
30115 | + int did; | |
30116 | + | |
30117 | + vfsub_update_h_iattr(&tmp, &did); | |
30118 | + if (did) { | |
30119 | + tmp.dentry = path->dentry->d_parent; | |
30120 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30121 | + } | |
30122 | + /*ignore*/ | |
30123 | + } | |
30124 | + | |
4f0767ce | 30125 | +out: |
1facf9fc | 30126 | + return err; |
30127 | +} | |
30128 | + | |
30129 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev) | |
30130 | +{ | |
30131 | + int err; | |
30132 | + struct dentry *d; | |
30133 | + | |
30134 | + IMustLock(dir); | |
30135 | + | |
30136 | + d = path->dentry; | |
30137 | + path->dentry = d->d_parent; | |
027c5e7a | 30138 | + err = security_path_mknod(path, d, mode, new_encode_dev(dev)); |
1facf9fc | 30139 | + path->dentry = d; |
30140 | + if (unlikely(err)) | |
30141 | + goto out; | |
30142 | + | |
c1595e42 | 30143 | + lockdep_off(); |
1facf9fc | 30144 | + err = vfs_mknod(dir, path->dentry, mode, dev); |
c1595e42 | 30145 | + lockdep_on(); |
1facf9fc | 30146 | + if (!err) { |
30147 | + struct path tmp = *path; | |
30148 | + int did; | |
30149 | + | |
30150 | + vfsub_update_h_iattr(&tmp, &did); | |
30151 | + if (did) { | |
30152 | + tmp.dentry = path->dentry->d_parent; | |
30153 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30154 | + } | |
30155 | + /*ignore*/ | |
30156 | + } | |
30157 | + | |
4f0767ce | 30158 | +out: |
1facf9fc | 30159 | + return err; |
30160 | +} | |
30161 | + | |
30162 | +static int au_test_nlink(struct inode *inode) | |
30163 | +{ | |
30164 | + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */ | |
30165 | + | |
30166 | + if (!au_test_fs_no_limit_nlink(inode->i_sb) | |
30167 | + || inode->i_nlink < link_max) | |
30168 | + return 0; | |
30169 | + return -EMLINK; | |
30170 | +} | |
30171 | + | |
523b37e3 AM |
30172 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path, |
30173 | + struct inode **delegated_inode) | |
1facf9fc | 30174 | +{ |
30175 | + int err; | |
30176 | + struct dentry *d; | |
30177 | + | |
30178 | + IMustLock(dir); | |
30179 | + | |
5527c038 | 30180 | + err = au_test_nlink(d_inode(src_dentry)); |
1facf9fc | 30181 | + if (unlikely(err)) |
30182 | + return err; | |
30183 | + | |
b4510431 | 30184 | + /* we don't call may_linkat() */ |
1facf9fc | 30185 | + d = path->dentry; |
30186 | + path->dentry = d->d_parent; | |
b752ccd1 | 30187 | + err = security_path_link(src_dentry, path, d); |
1facf9fc | 30188 | + path->dentry = d; |
30189 | + if (unlikely(err)) | |
30190 | + goto out; | |
30191 | + | |
2cbb1c4b | 30192 | + lockdep_off(); |
523b37e3 | 30193 | + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode); |
2cbb1c4b | 30194 | + lockdep_on(); |
1facf9fc | 30195 | + if (!err) { |
30196 | + struct path tmp = *path; | |
30197 | + int did; | |
30198 | + | |
30199 | + /* fuse has different memory inode for the same inumber */ | |
30200 | + vfsub_update_h_iattr(&tmp, &did); | |
30201 | + if (did) { | |
30202 | + tmp.dentry = path->dentry->d_parent; | |
30203 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30204 | + tmp.dentry = src_dentry; | |
30205 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30206 | + } | |
30207 | + /*ignore*/ | |
30208 | + } | |
30209 | + | |
4f0767ce | 30210 | +out: |
1facf9fc | 30211 | + return err; |
30212 | +} | |
30213 | + | |
30214 | +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry, | |
523b37e3 AM |
30215 | + struct inode *dir, struct path *path, |
30216 | + struct inode **delegated_inode) | |
1facf9fc | 30217 | +{ |
30218 | + int err; | |
30219 | + struct path tmp = { | |
30220 | + .mnt = path->mnt | |
30221 | + }; | |
30222 | + struct dentry *d; | |
30223 | + | |
30224 | + IMustLock(dir); | |
30225 | + IMustLock(src_dir); | |
30226 | + | |
30227 | + d = path->dentry; | |
30228 | + path->dentry = d->d_parent; | |
30229 | + tmp.dentry = src_dentry->d_parent; | |
38d290e6 | 30230 | + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0); |
1facf9fc | 30231 | + path->dentry = d; |
30232 | + if (unlikely(err)) | |
30233 | + goto out; | |
30234 | + | |
2cbb1c4b | 30235 | + lockdep_off(); |
523b37e3 | 30236 | + err = vfs_rename(src_dir, src_dentry, dir, path->dentry, |
38d290e6 | 30237 | + delegated_inode, /*flags*/0); |
2cbb1c4b | 30238 | + lockdep_on(); |
1facf9fc | 30239 | + if (!err) { |
30240 | + int did; | |
30241 | + | |
30242 | + tmp.dentry = d->d_parent; | |
30243 | + vfsub_update_h_iattr(&tmp, &did); | |
30244 | + if (did) { | |
30245 | + tmp.dentry = src_dentry; | |
30246 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30247 | + tmp.dentry = src_dentry->d_parent; | |
30248 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30249 | + } | |
30250 | + /*ignore*/ | |
30251 | + } | |
30252 | + | |
4f0767ce | 30253 | +out: |
1facf9fc | 30254 | + return err; |
30255 | +} | |
30256 | + | |
30257 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode) | |
30258 | +{ | |
30259 | + int err; | |
30260 | + struct dentry *d; | |
30261 | + | |
30262 | + IMustLock(dir); | |
30263 | + | |
30264 | + d = path->dentry; | |
30265 | + path->dentry = d->d_parent; | |
b752ccd1 | 30266 | + err = security_path_mkdir(path, d, mode); |
1facf9fc | 30267 | + path->dentry = d; |
30268 | + if (unlikely(err)) | |
30269 | + goto out; | |
30270 | + | |
c1595e42 | 30271 | + lockdep_off(); |
1facf9fc | 30272 | + err = vfs_mkdir(dir, path->dentry, mode); |
c1595e42 | 30273 | + lockdep_on(); |
1facf9fc | 30274 | + if (!err) { |
30275 | + struct path tmp = *path; | |
30276 | + int did; | |
30277 | + | |
30278 | + vfsub_update_h_iattr(&tmp, &did); | |
30279 | + if (did) { | |
30280 | + tmp.dentry = path->dentry->d_parent; | |
30281 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30282 | + } | |
30283 | + /*ignore*/ | |
30284 | + } | |
30285 | + | |
4f0767ce | 30286 | +out: |
1facf9fc | 30287 | + return err; |
30288 | +} | |
30289 | + | |
30290 | +int vfsub_rmdir(struct inode *dir, struct path *path) | |
30291 | +{ | |
30292 | + int err; | |
30293 | + struct dentry *d; | |
30294 | + | |
30295 | + IMustLock(dir); | |
30296 | + | |
30297 | + d = path->dentry; | |
30298 | + path->dentry = d->d_parent; | |
b752ccd1 | 30299 | + err = security_path_rmdir(path, d); |
1facf9fc | 30300 | + path->dentry = d; |
30301 | + if (unlikely(err)) | |
30302 | + goto out; | |
30303 | + | |
2cbb1c4b | 30304 | + lockdep_off(); |
1facf9fc | 30305 | + err = vfs_rmdir(dir, path->dentry); |
2cbb1c4b | 30306 | + lockdep_on(); |
1facf9fc | 30307 | + if (!err) { |
30308 | + struct path tmp = { | |
30309 | + .dentry = path->dentry->d_parent, | |
30310 | + .mnt = path->mnt | |
30311 | + }; | |
30312 | + | |
30313 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
30314 | + } | |
30315 | + | |
4f0767ce | 30316 | +out: |
1facf9fc | 30317 | + return err; |
30318 | +} | |
30319 | + | |
30320 | +/* ---------------------------------------------------------------------- */ | |
30321 | + | |
9dbd164d | 30322 | +/* todo: support mmap_sem? */ |
1facf9fc | 30323 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, |
30324 | + loff_t *ppos) | |
30325 | +{ | |
30326 | + ssize_t err; | |
30327 | + | |
2cbb1c4b | 30328 | + lockdep_off(); |
1facf9fc | 30329 | + err = vfs_read(file, ubuf, count, ppos); |
2cbb1c4b | 30330 | + lockdep_on(); |
1facf9fc | 30331 | + if (err >= 0) |
30332 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30333 | + return err; | |
30334 | +} | |
30335 | + | |
30336 | +/* todo: kernel_read()? */ | |
30337 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
30338 | + loff_t *ppos) | |
30339 | +{ | |
30340 | + ssize_t err; | |
30341 | + mm_segment_t oldfs; | |
b752ccd1 AM |
30342 | + union { |
30343 | + void *k; | |
30344 | + char __user *u; | |
30345 | + } buf; | |
1facf9fc | 30346 | + |
b752ccd1 | 30347 | + buf.k = kbuf; |
1facf9fc | 30348 | + oldfs = get_fs(); |
30349 | + set_fs(KERNEL_DS); | |
b752ccd1 | 30350 | + err = vfsub_read_u(file, buf.u, count, ppos); |
1facf9fc | 30351 | + set_fs(oldfs); |
30352 | + return err; | |
30353 | +} | |
30354 | + | |
30355 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
30356 | + loff_t *ppos) | |
30357 | +{ | |
30358 | + ssize_t err; | |
30359 | + | |
2cbb1c4b | 30360 | + lockdep_off(); |
1facf9fc | 30361 | + err = vfs_write(file, ubuf, count, ppos); |
2cbb1c4b | 30362 | + lockdep_on(); |
1facf9fc | 30363 | + if (err >= 0) |
30364 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30365 | + return err; | |
30366 | +} | |
30367 | + | |
30368 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos) | |
30369 | +{ | |
30370 | + ssize_t err; | |
30371 | + mm_segment_t oldfs; | |
b752ccd1 AM |
30372 | + union { |
30373 | + void *k; | |
30374 | + const char __user *u; | |
30375 | + } buf; | |
1facf9fc | 30376 | + |
b752ccd1 | 30377 | + buf.k = kbuf; |
1facf9fc | 30378 | + oldfs = get_fs(); |
30379 | + set_fs(KERNEL_DS); | |
b752ccd1 | 30380 | + err = vfsub_write_u(file, buf.u, count, ppos); |
1facf9fc | 30381 | + set_fs(oldfs); |
30382 | + return err; | |
30383 | +} | |
30384 | + | |
4a4d8108 AM |
30385 | +int vfsub_flush(struct file *file, fl_owner_t id) |
30386 | +{ | |
30387 | + int err; | |
30388 | + | |
30389 | + err = 0; | |
523b37e3 | 30390 | + if (file->f_op->flush) { |
2000de60 | 30391 | + if (!au_test_nfs(file->f_path.dentry->d_sb)) |
2cbb1c4b JR |
30392 | + err = file->f_op->flush(file, id); |
30393 | + else { | |
30394 | + lockdep_off(); | |
30395 | + err = file->f_op->flush(file, id); | |
30396 | + lockdep_on(); | |
30397 | + } | |
4a4d8108 AM |
30398 | + if (!err) |
30399 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); | |
30400 | + /*ignore*/ | |
30401 | + } | |
30402 | + return err; | |
30403 | +} | |
30404 | + | |
392086de | 30405 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx) |
1facf9fc | 30406 | +{ |
30407 | + int err; | |
30408 | + | |
523b37e3 | 30409 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 30410 | + |
2cbb1c4b | 30411 | + lockdep_off(); |
392086de | 30412 | + err = iterate_dir(file, ctx); |
2cbb1c4b | 30413 | + lockdep_on(); |
1facf9fc | 30414 | + if (err >= 0) |
30415 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30416 | + return err; | |
30417 | +} | |
30418 | + | |
30419 | +long vfsub_splice_to(struct file *in, loff_t *ppos, | |
30420 | + struct pipe_inode_info *pipe, size_t len, | |
30421 | + unsigned int flags) | |
30422 | +{ | |
30423 | + long err; | |
30424 | + | |
2cbb1c4b | 30425 | + lockdep_off(); |
0fc653ad | 30426 | + err = do_splice_to(in, ppos, pipe, len, flags); |
2cbb1c4b | 30427 | + lockdep_on(); |
4a4d8108 | 30428 | + file_accessed(in); |
1facf9fc | 30429 | + if (err >= 0) |
30430 | + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/ | |
30431 | + return err; | |
30432 | +} | |
30433 | + | |
30434 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
30435 | + loff_t *ppos, size_t len, unsigned int flags) | |
30436 | +{ | |
30437 | + long err; | |
30438 | + | |
2cbb1c4b | 30439 | + lockdep_off(); |
0fc653ad | 30440 | + err = do_splice_from(pipe, out, ppos, len, flags); |
2cbb1c4b | 30441 | + lockdep_on(); |
1facf9fc | 30442 | + if (err >= 0) |
30443 | + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/ | |
30444 | + return err; | |
30445 | +} | |
30446 | + | |
53392da6 AM |
30447 | +int vfsub_fsync(struct file *file, struct path *path, int datasync) |
30448 | +{ | |
30449 | + int err; | |
30450 | + | |
30451 | + /* file can be NULL */ | |
30452 | + lockdep_off(); | |
30453 | + err = vfs_fsync(file, datasync); | |
30454 | + lockdep_on(); | |
30455 | + if (!err) { | |
30456 | + if (!path) { | |
30457 | + AuDebugOn(!file); | |
30458 | + path = &file->f_path; | |
30459 | + } | |
30460 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ | |
30461 | + } | |
30462 | + return err; | |
30463 | +} | |
30464 | + | |
1facf9fc | 30465 | +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */ |
30466 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, | |
30467 | + struct file *h_file) | |
30468 | +{ | |
30469 | + int err; | |
30470 | + struct inode *h_inode; | |
c06a8ce3 | 30471 | + struct super_block *h_sb; |
1facf9fc | 30472 | + |
1facf9fc | 30473 | + if (!h_file) { |
c06a8ce3 AM |
30474 | + err = vfsub_truncate(h_path, length); |
30475 | + goto out; | |
1facf9fc | 30476 | + } |
30477 | + | |
5527c038 | 30478 | + h_inode = d_inode(h_path->dentry); |
c06a8ce3 AM |
30479 | + h_sb = h_inode->i_sb; |
30480 | + lockdep_off(); | |
30481 | + sb_start_write(h_sb); | |
30482 | + lockdep_on(); | |
1facf9fc | 30483 | + err = locks_verify_truncate(h_inode, h_file, length); |
30484 | + if (!err) | |
953406b4 | 30485 | + err = security_path_truncate(h_path); |
2cbb1c4b JR |
30486 | + if (!err) { |
30487 | + lockdep_off(); | |
1facf9fc | 30488 | + err = do_truncate(h_path->dentry, length, attr, h_file); |
2cbb1c4b JR |
30489 | + lockdep_on(); |
30490 | + } | |
c06a8ce3 AM |
30491 | + lockdep_off(); |
30492 | + sb_end_write(h_sb); | |
30493 | + lockdep_on(); | |
1facf9fc | 30494 | + |
4f0767ce | 30495 | +out: |
1facf9fc | 30496 | + return err; |
30497 | +} | |
30498 | + | |
30499 | +/* ---------------------------------------------------------------------- */ | |
30500 | + | |
30501 | +struct au_vfsub_mkdir_args { | |
30502 | + int *errp; | |
30503 | + struct inode *dir; | |
30504 | + struct path *path; | |
30505 | + int mode; | |
30506 | +}; | |
30507 | + | |
30508 | +static void au_call_vfsub_mkdir(void *args) | |
30509 | +{ | |
30510 | + struct au_vfsub_mkdir_args *a = args; | |
30511 | + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode); | |
30512 | +} | |
30513 | + | |
30514 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode) | |
30515 | +{ | |
30516 | + int err, do_sio, wkq_err; | |
30517 | + | |
30518 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
30519 | + if (!do_sio) { |
30520 | + lockdep_off(); | |
1facf9fc | 30521 | + err = vfsub_mkdir(dir, path, mode); |
c1595e42 JR |
30522 | + lockdep_on(); |
30523 | + } else { | |
1facf9fc | 30524 | + struct au_vfsub_mkdir_args args = { |
30525 | + .errp = &err, | |
30526 | + .dir = dir, | |
30527 | + .path = path, | |
30528 | + .mode = mode | |
30529 | + }; | |
30530 | + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args); | |
30531 | + if (unlikely(wkq_err)) | |
30532 | + err = wkq_err; | |
30533 | + } | |
30534 | + | |
30535 | + return err; | |
30536 | +} | |
30537 | + | |
30538 | +struct au_vfsub_rmdir_args { | |
30539 | + int *errp; | |
30540 | + struct inode *dir; | |
30541 | + struct path *path; | |
30542 | +}; | |
30543 | + | |
30544 | +static void au_call_vfsub_rmdir(void *args) | |
30545 | +{ | |
30546 | + struct au_vfsub_rmdir_args *a = args; | |
30547 | + *a->errp = vfsub_rmdir(a->dir, a->path); | |
30548 | +} | |
30549 | + | |
30550 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path) | |
30551 | +{ | |
30552 | + int err, do_sio, wkq_err; | |
30553 | + | |
30554 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
30555 | + if (!do_sio) { |
30556 | + lockdep_off(); | |
1facf9fc | 30557 | + err = vfsub_rmdir(dir, path); |
c1595e42 JR |
30558 | + lockdep_on(); |
30559 | + } else { | |
1facf9fc | 30560 | + struct au_vfsub_rmdir_args args = { |
30561 | + .errp = &err, | |
30562 | + .dir = dir, | |
30563 | + .path = path | |
30564 | + }; | |
30565 | + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args); | |
30566 | + if (unlikely(wkq_err)) | |
30567 | + err = wkq_err; | |
30568 | + } | |
30569 | + | |
30570 | + return err; | |
30571 | +} | |
30572 | + | |
30573 | +/* ---------------------------------------------------------------------- */ | |
30574 | + | |
30575 | +struct notify_change_args { | |
30576 | + int *errp; | |
30577 | + struct path *path; | |
30578 | + struct iattr *ia; | |
523b37e3 | 30579 | + struct inode **delegated_inode; |
1facf9fc | 30580 | +}; |
30581 | + | |
30582 | +static void call_notify_change(void *args) | |
30583 | +{ | |
30584 | + struct notify_change_args *a = args; | |
30585 | + struct inode *h_inode; | |
30586 | + | |
5527c038 | 30587 | + h_inode = d_inode(a->path->dentry); |
1facf9fc | 30588 | + IMustLock(h_inode); |
30589 | + | |
30590 | + *a->errp = -EPERM; | |
30591 | + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) { | |
c1595e42 | 30592 | + lockdep_off(); |
523b37e3 AM |
30593 | + *a->errp = notify_change(a->path->dentry, a->ia, |
30594 | + a->delegated_inode); | |
c1595e42 | 30595 | + lockdep_on(); |
1facf9fc | 30596 | + if (!*a->errp) |
30597 | + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/ | |
30598 | + } | |
30599 | + AuTraceErr(*a->errp); | |
30600 | +} | |
30601 | + | |
523b37e3 AM |
30602 | +int vfsub_notify_change(struct path *path, struct iattr *ia, |
30603 | + struct inode **delegated_inode) | |
1facf9fc | 30604 | +{ |
30605 | + int err; | |
30606 | + struct notify_change_args args = { | |
523b37e3 AM |
30607 | + .errp = &err, |
30608 | + .path = path, | |
30609 | + .ia = ia, | |
30610 | + .delegated_inode = delegated_inode | |
1facf9fc | 30611 | + }; |
30612 | + | |
30613 | + call_notify_change(&args); | |
30614 | + | |
30615 | + return err; | |
30616 | +} | |
30617 | + | |
523b37e3 AM |
30618 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
30619 | + struct inode **delegated_inode) | |
1facf9fc | 30620 | +{ |
30621 | + int err, wkq_err; | |
30622 | + struct notify_change_args args = { | |
523b37e3 AM |
30623 | + .errp = &err, |
30624 | + .path = path, | |
30625 | + .ia = ia, | |
30626 | + .delegated_inode = delegated_inode | |
1facf9fc | 30627 | + }; |
30628 | + | |
30629 | + wkq_err = au_wkq_wait(call_notify_change, &args); | |
30630 | + if (unlikely(wkq_err)) | |
30631 | + err = wkq_err; | |
30632 | + | |
30633 | + return err; | |
30634 | +} | |
30635 | + | |
30636 | +/* ---------------------------------------------------------------------- */ | |
30637 | + | |
30638 | +struct unlink_args { | |
30639 | + int *errp; | |
30640 | + struct inode *dir; | |
30641 | + struct path *path; | |
523b37e3 | 30642 | + struct inode **delegated_inode; |
1facf9fc | 30643 | +}; |
30644 | + | |
30645 | +static void call_unlink(void *args) | |
30646 | +{ | |
30647 | + struct unlink_args *a = args; | |
30648 | + struct dentry *d = a->path->dentry; | |
30649 | + struct inode *h_inode; | |
30650 | + const int stop_sillyrename = (au_test_nfs(d->d_sb) | |
c1595e42 | 30651 | + && au_dcount(d) == 1); |
1facf9fc | 30652 | + |
30653 | + IMustLock(a->dir); | |
30654 | + | |
30655 | + a->path->dentry = d->d_parent; | |
30656 | + *a->errp = security_path_unlink(a->path, d); | |
30657 | + a->path->dentry = d; | |
30658 | + if (unlikely(*a->errp)) | |
30659 | + return; | |
30660 | + | |
30661 | + if (!stop_sillyrename) | |
30662 | + dget(d); | |
5527c038 JR |
30663 | + h_inode = NULL; |
30664 | + if (d_is_positive(d)) { | |
30665 | + h_inode = d_inode(d); | |
027c5e7a | 30666 | + ihold(h_inode); |
5527c038 | 30667 | + } |
1facf9fc | 30668 | + |
2cbb1c4b | 30669 | + lockdep_off(); |
523b37e3 | 30670 | + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode); |
2cbb1c4b | 30671 | + lockdep_on(); |
1facf9fc | 30672 | + if (!*a->errp) { |
30673 | + struct path tmp = { | |
30674 | + .dentry = d->d_parent, | |
30675 | + .mnt = a->path->mnt | |
30676 | + }; | |
30677 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
30678 | + } | |
30679 | + | |
30680 | + if (!stop_sillyrename) | |
30681 | + dput(d); | |
30682 | + if (h_inode) | |
30683 | + iput(h_inode); | |
30684 | + | |
30685 | + AuTraceErr(*a->errp); | |
30686 | +} | |
30687 | + | |
30688 | +/* | |
30689 | + * @dir: must be locked. | |
30690 | + * @dentry: target dentry. | |
30691 | + */ | |
523b37e3 AM |
30692 | +int vfsub_unlink(struct inode *dir, struct path *path, |
30693 | + struct inode **delegated_inode, int force) | |
1facf9fc | 30694 | +{ |
30695 | + int err; | |
30696 | + struct unlink_args args = { | |
523b37e3 AM |
30697 | + .errp = &err, |
30698 | + .dir = dir, | |
30699 | + .path = path, | |
30700 | + .delegated_inode = delegated_inode | |
1facf9fc | 30701 | + }; |
30702 | + | |
30703 | + if (!force) | |
30704 | + call_unlink(&args); | |
30705 | + else { | |
30706 | + int wkq_err; | |
30707 | + | |
30708 | + wkq_err = au_wkq_wait(call_unlink, &args); | |
30709 | + if (unlikely(wkq_err)) | |
30710 | + err = wkq_err; | |
30711 | + } | |
30712 | + | |
30713 | + return err; | |
30714 | +} | |
7f207e10 AM |
30715 | diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h |
30716 | --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 30717 | +++ linux/fs/aufs/vfsub.h 2015-06-28 17:35:44.351383872 +0200 |
b912730e | 30718 | @@ -0,0 +1,286 @@ |
1facf9fc | 30719 | +/* |
2000de60 | 30720 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 30721 | + * |
30722 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30723 | + * it under the terms of the GNU General Public License as published by | |
30724 | + * the Free Software Foundation; either version 2 of the License, or | |
30725 | + * (at your option) any later version. | |
dece6358 AM |
30726 | + * |
30727 | + * This program is distributed in the hope that it will be useful, | |
30728 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30729 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30730 | + * GNU General Public License for more details. | |
30731 | + * | |
30732 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30733 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30734 | + */ |
30735 | + | |
30736 | +/* | |
30737 | + * sub-routines for VFS | |
30738 | + */ | |
30739 | + | |
30740 | +#ifndef __AUFS_VFSUB_H__ | |
30741 | +#define __AUFS_VFSUB_H__ | |
30742 | + | |
30743 | +#ifdef __KERNEL__ | |
30744 | + | |
30745 | +#include <linux/fs.h> | |
b4510431 | 30746 | +#include <linux/mount.h> |
c1595e42 | 30747 | +#include <linux/xattr.h> |
7f207e10 | 30748 | +#include "debug.h" |
1facf9fc | 30749 | + |
7f207e10 | 30750 | +/* copied from linux/fs/internal.h */ |
2cbb1c4b | 30751 | +/* todo: BAD approach!! */ |
c06a8ce3 | 30752 | +extern void __mnt_drop_write(struct vfsmount *); |
2cbb1c4b | 30753 | +extern spinlock_t inode_sb_list_lock; |
b912730e | 30754 | +extern int open_check_o_direct(struct file *f); |
7f207e10 AM |
30755 | + |
30756 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 30757 | + |
30758 | +/* lock subclass for lower inode */ | |
30759 | +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */ | |
30760 | +/* reduce? gave up. */ | |
30761 | +enum { | |
c1595e42 | 30762 | + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */ |
1facf9fc | 30763 | + AuLsc_I_PARENT, /* lower inode, parent first */ |
30764 | + AuLsc_I_PARENT2, /* copyup dirs */ | |
dece6358 | 30765 | + AuLsc_I_PARENT3, /* copyup wh */ |
1facf9fc | 30766 | + AuLsc_I_CHILD, |
30767 | + AuLsc_I_CHILD2, | |
30768 | + AuLsc_I_End | |
30769 | +}; | |
30770 | + | |
30771 | +/* to debug easier, do not make them inlined functions */ | |
30772 | +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx)) | |
30773 | +#define IMustLock(i) MtxMustLock(&(i)->i_mutex) | |
30774 | + | |
30775 | +/* ---------------------------------------------------------------------- */ | |
30776 | + | |
7f207e10 AM |
30777 | +static inline void vfsub_drop_nlink(struct inode *inode) |
30778 | +{ | |
30779 | + AuDebugOn(!inode->i_nlink); | |
30780 | + drop_nlink(inode); | |
30781 | +} | |
30782 | + | |
027c5e7a AM |
30783 | +static inline void vfsub_dead_dir(struct inode *inode) |
30784 | +{ | |
30785 | + AuDebugOn(!S_ISDIR(inode->i_mode)); | |
30786 | + inode->i_flags |= S_DEAD; | |
30787 | + clear_nlink(inode); | |
30788 | +} | |
30789 | + | |
392086de AM |
30790 | +static inline int vfsub_native_ro(struct inode *inode) |
30791 | +{ | |
30792 | + return (inode->i_sb->s_flags & MS_RDONLY) | |
30793 | + || IS_RDONLY(inode) | |
30794 | + /* || IS_APPEND(inode) */ | |
30795 | + || IS_IMMUTABLE(inode); | |
30796 | +} | |
30797 | + | |
7f207e10 AM |
30798 | +/* ---------------------------------------------------------------------- */ |
30799 | + | |
30800 | +int vfsub_update_h_iattr(struct path *h_path, int *did); | |
30801 | +struct file *vfsub_dentry_open(struct path *path, int flags); | |
30802 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode); | |
b912730e AM |
30803 | +struct vfsub_aopen_args { |
30804 | + struct file *file; | |
30805 | + unsigned int open_flag; | |
30806 | + umode_t create_mode; | |
30807 | + int *opened; | |
30808 | +}; | |
30809 | +struct au_branch; | |
30810 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
30811 | + struct vfsub_aopen_args *args, struct au_branch *br); | |
1facf9fc | 30812 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path); |
b4510431 | 30813 | + |
1facf9fc | 30814 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
30815 | + int len); | |
b4510431 AM |
30816 | + |
30817 | +struct vfsub_lkup_one_args { | |
30818 | + struct dentry **errp; | |
30819 | + struct qstr *name; | |
30820 | + struct dentry *parent; | |
30821 | +}; | |
30822 | + | |
30823 | +static inline struct dentry *vfsub_lkup_one(struct qstr *name, | |
30824 | + struct dentry *parent) | |
30825 | +{ | |
30826 | + return vfsub_lookup_one_len(name->name, parent, name->len); | |
30827 | +} | |
30828 | + | |
30829 | +void vfsub_call_lkup_one(void *args); | |
30830 | + | |
30831 | +/* ---------------------------------------------------------------------- */ | |
30832 | + | |
30833 | +static inline int vfsub_mnt_want_write(struct vfsmount *mnt) | |
30834 | +{ | |
30835 | + int err; | |
076b876e | 30836 | + |
b4510431 AM |
30837 | + lockdep_off(); |
30838 | + err = mnt_want_write(mnt); | |
30839 | + lockdep_on(); | |
30840 | + return err; | |
30841 | +} | |
30842 | + | |
30843 | +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt) | |
30844 | +{ | |
30845 | + lockdep_off(); | |
30846 | + mnt_drop_write(mnt); | |
30847 | + lockdep_on(); | |
30848 | +} | |
1facf9fc | 30849 | + |
7e9cd9fe | 30850 | +#if 0 /* reserved */ |
c06a8ce3 AM |
30851 | +static inline void vfsub_mnt_drop_write_file(struct file *file) |
30852 | +{ | |
30853 | + lockdep_off(); | |
30854 | + mnt_drop_write_file(file); | |
30855 | + lockdep_on(); | |
30856 | +} | |
7e9cd9fe | 30857 | +#endif |
c06a8ce3 | 30858 | + |
1facf9fc | 30859 | +/* ---------------------------------------------------------------------- */ |
30860 | + | |
30861 | +struct au_hinode; | |
30862 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30863 | + struct dentry *d2, struct au_hinode *hdir2); | |
30864 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30865 | + struct dentry *d2, struct au_hinode *hdir2); | |
30866 | + | |
537831f9 AM |
30867 | +int vfsub_create(struct inode *dir, struct path *path, int mode, |
30868 | + bool want_excl); | |
1facf9fc | 30869 | +int vfsub_symlink(struct inode *dir, struct path *path, |
30870 | + const char *symname); | |
30871 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev); | |
30872 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, | |
523b37e3 | 30873 | + struct path *path, struct inode **delegated_inode); |
1facf9fc | 30874 | +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry, |
523b37e3 AM |
30875 | + struct inode *hdir, struct path *path, |
30876 | + struct inode **delegated_inode); | |
1facf9fc | 30877 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode); |
30878 | +int vfsub_rmdir(struct inode *dir, struct path *path); | |
30879 | + | |
30880 | +/* ---------------------------------------------------------------------- */ | |
30881 | + | |
30882 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, | |
30883 | + loff_t *ppos); | |
30884 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
30885 | + loff_t *ppos); | |
30886 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
30887 | + loff_t *ppos); | |
30888 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, | |
30889 | + loff_t *ppos); | |
4a4d8108 | 30890 | +int vfsub_flush(struct file *file, fl_owner_t id); |
392086de AM |
30891 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx); |
30892 | + | |
c06a8ce3 AM |
30893 | +static inline loff_t vfsub_f_size_read(struct file *file) |
30894 | +{ | |
30895 | + return i_size_read(file_inode(file)); | |
30896 | +} | |
30897 | + | |
4a4d8108 AM |
30898 | +static inline unsigned int vfsub_file_flags(struct file *file) |
30899 | +{ | |
30900 | + unsigned int flags; | |
30901 | + | |
30902 | + spin_lock(&file->f_lock); | |
30903 | + flags = file->f_flags; | |
30904 | + spin_unlock(&file->f_lock); | |
30905 | + | |
30906 | + return flags; | |
30907 | +} | |
1308ab2a | 30908 | + |
7e9cd9fe | 30909 | +#if 0 /* reserved */ |
1facf9fc | 30910 | +static inline void vfsub_file_accessed(struct file *h_file) |
30911 | +{ | |
30912 | + file_accessed(h_file); | |
30913 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/ | |
30914 | +} | |
7e9cd9fe | 30915 | +#endif |
1facf9fc | 30916 | + |
30917 | +static inline void vfsub_touch_atime(struct vfsmount *h_mnt, | |
30918 | + struct dentry *h_dentry) | |
30919 | +{ | |
30920 | + struct path h_path = { | |
30921 | + .dentry = h_dentry, | |
30922 | + .mnt = h_mnt | |
30923 | + }; | |
92d182d2 | 30924 | + touch_atime(&h_path); |
1facf9fc | 30925 | + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/ |
30926 | +} | |
30927 | + | |
0c3ec466 AM |
30928 | +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts, |
30929 | + int flags) | |
30930 | +{ | |
7e9cd9fe | 30931 | + return generic_update_time(h_inode, ts, flags); |
0c3ec466 AM |
30932 | + /* no vfsub_update_h_iattr() since we don't have struct path */ |
30933 | +} | |
30934 | + | |
4a4d8108 AM |
30935 | +long vfsub_splice_to(struct file *in, loff_t *ppos, |
30936 | + struct pipe_inode_info *pipe, size_t len, | |
30937 | + unsigned int flags); | |
30938 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
30939 | + loff_t *ppos, size_t len, unsigned int flags); | |
c06a8ce3 AM |
30940 | + |
30941 | +static inline long vfsub_truncate(struct path *path, loff_t length) | |
30942 | +{ | |
30943 | + long err; | |
076b876e | 30944 | + |
c06a8ce3 AM |
30945 | + lockdep_off(); |
30946 | + err = vfs_truncate(path, length); | |
30947 | + lockdep_on(); | |
30948 | + return err; | |
30949 | +} | |
30950 | + | |
4a4d8108 AM |
30951 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, |
30952 | + struct file *h_file); | |
53392da6 | 30953 | +int vfsub_fsync(struct file *file, struct path *path, int datasync); |
4a4d8108 | 30954 | + |
1facf9fc | 30955 | +/* ---------------------------------------------------------------------- */ |
30956 | + | |
30957 | +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin) | |
30958 | +{ | |
30959 | + loff_t err; | |
30960 | + | |
2cbb1c4b | 30961 | + lockdep_off(); |
1facf9fc | 30962 | + err = vfs_llseek(file, offset, origin); |
2cbb1c4b | 30963 | + lockdep_on(); |
1facf9fc | 30964 | + return err; |
30965 | +} | |
30966 | + | |
30967 | +/* ---------------------------------------------------------------------- */ | |
30968 | + | |
4a4d8108 AM |
30969 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode); |
30970 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path); | |
523b37e3 AM |
30971 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
30972 | + struct inode **delegated_inode); | |
30973 | +int vfsub_notify_change(struct path *path, struct iattr *ia, | |
30974 | + struct inode **delegated_inode); | |
30975 | +int vfsub_unlink(struct inode *dir, struct path *path, | |
30976 | + struct inode **delegated_inode, int force); | |
4a4d8108 | 30977 | + |
c1595e42 JR |
30978 | +/* ---------------------------------------------------------------------- */ |
30979 | + | |
30980 | +static inline int vfsub_setxattr(struct dentry *dentry, const char *name, | |
30981 | + const void *value, size_t size, int flags) | |
30982 | +{ | |
30983 | + int err; | |
30984 | + | |
30985 | + lockdep_off(); | |
30986 | + err = vfs_setxattr(dentry, name, value, size, flags); | |
30987 | + lockdep_on(); | |
30988 | + | |
30989 | + return err; | |
30990 | +} | |
30991 | + | |
30992 | +static inline int vfsub_removexattr(struct dentry *dentry, const char *name) | |
30993 | +{ | |
30994 | + int err; | |
30995 | + | |
30996 | + lockdep_off(); | |
30997 | + err = vfs_removexattr(dentry, name); | |
30998 | + lockdep_on(); | |
30999 | + | |
31000 | + return err; | |
31001 | +} | |
31002 | + | |
1facf9fc | 31003 | +#endif /* __KERNEL__ */ |
31004 | +#endif /* __AUFS_VFSUB_H__ */ | |
7f207e10 AM |
31005 | diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c |
31006 | --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 31007 | +++ linux/fs/aufs/wbr_policy.c 2015-06-28 17:36:09.028407078 +0200 |
076b876e | 31008 | @@ -0,0 +1,765 @@ |
1facf9fc | 31009 | +/* |
2000de60 | 31010 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 31011 | + * |
31012 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31013 | + * it under the terms of the GNU General Public License as published by | |
31014 | + * the Free Software Foundation; either version 2 of the License, or | |
31015 | + * (at your option) any later version. | |
dece6358 AM |
31016 | + * |
31017 | + * This program is distributed in the hope that it will be useful, | |
31018 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31019 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31020 | + * GNU General Public License for more details. | |
31021 | + * | |
31022 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31023 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31024 | + */ |
31025 | + | |
31026 | +/* | |
31027 | + * policies for selecting one among multiple writable branches | |
31028 | + */ | |
31029 | + | |
31030 | +#include <linux/statfs.h> | |
31031 | +#include "aufs.h" | |
31032 | + | |
31033 | +/* subset of cpup_attr() */ | |
31034 | +static noinline_for_stack | |
31035 | +int au_cpdown_attr(struct path *h_path, struct dentry *h_src) | |
31036 | +{ | |
31037 | + int err, sbits; | |
31038 | + struct iattr ia; | |
31039 | + struct inode *h_isrc; | |
31040 | + | |
5527c038 | 31041 | + h_isrc = d_inode(h_src); |
1facf9fc | 31042 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID; |
31043 | + ia.ia_mode = h_isrc->i_mode; | |
31044 | + ia.ia_uid = h_isrc->i_uid; | |
31045 | + ia.ia_gid = h_isrc->i_gid; | |
31046 | + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID)); | |
5527c038 | 31047 | + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags); |
523b37e3 AM |
31048 | + /* no delegation since it is just created */ |
31049 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 31050 | + |
31051 | + /* is this nfs only? */ | |
31052 | + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) { | |
31053 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
31054 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 31055 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); |
1facf9fc | 31056 | + } |
31057 | + | |
31058 | + return err; | |
31059 | +} | |
31060 | + | |
31061 | +#define AuCpdown_PARENT_OPQ 1 | |
31062 | +#define AuCpdown_WHED (1 << 1) | |
31063 | +#define AuCpdown_MADE_DIR (1 << 2) | |
31064 | +#define AuCpdown_DIROPQ (1 << 3) | |
31065 | +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name) | |
7f207e10 AM |
31066 | +#define au_fset_cpdown(flags, name) \ |
31067 | + do { (flags) |= AuCpdown_##name; } while (0) | |
31068 | +#define au_fclr_cpdown(flags, name) \ | |
31069 | + do { (flags) &= ~AuCpdown_##name; } while (0) | |
1facf9fc | 31070 | + |
1facf9fc | 31071 | +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst, |
c2b27bf2 | 31072 | + unsigned int *flags) |
1facf9fc | 31073 | +{ |
31074 | + int err; | |
31075 | + struct dentry *opq_dentry; | |
31076 | + | |
31077 | + opq_dentry = au_diropq_create(dentry, bdst); | |
31078 | + err = PTR_ERR(opq_dentry); | |
31079 | + if (IS_ERR(opq_dentry)) | |
31080 | + goto out; | |
31081 | + dput(opq_dentry); | |
c2b27bf2 | 31082 | + au_fset_cpdown(*flags, DIROPQ); |
1facf9fc | 31083 | + |
4f0767ce | 31084 | +out: |
1facf9fc | 31085 | + return err; |
31086 | +} | |
31087 | + | |
31088 | +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent, | |
31089 | + struct inode *dir, aufs_bindex_t bdst) | |
31090 | +{ | |
31091 | + int err; | |
31092 | + struct path h_path; | |
31093 | + struct au_branch *br; | |
31094 | + | |
31095 | + br = au_sbr(dentry->d_sb, bdst); | |
31096 | + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br); | |
31097 | + err = PTR_ERR(h_path.dentry); | |
31098 | + if (IS_ERR(h_path.dentry)) | |
31099 | + goto out; | |
31100 | + | |
31101 | + err = 0; | |
5527c038 | 31102 | + if (d_is_positive(h_path.dentry)) { |
86dc4139 | 31103 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 31104 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path, |
31105 | + dentry); | |
31106 | + } | |
31107 | + dput(h_path.dentry); | |
31108 | + | |
4f0767ce | 31109 | +out: |
1facf9fc | 31110 | + return err; |
31111 | +} | |
31112 | + | |
31113 | +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 31114 | + struct au_pin *pin, |
1facf9fc | 31115 | + struct dentry *h_parent, void *arg) |
31116 | +{ | |
31117 | + int err, rerr; | |
4a4d8108 | 31118 | + aufs_bindex_t bopq, bstart; |
1facf9fc | 31119 | + struct path h_path; |
31120 | + struct dentry *parent; | |
31121 | + struct inode *h_dir, *h_inode, *inode, *dir; | |
c2b27bf2 | 31122 | + unsigned int *flags = arg; |
1facf9fc | 31123 | + |
31124 | + bstart = au_dbstart(dentry); | |
31125 | + /* dentry is di-locked */ | |
31126 | + parent = dget_parent(dentry); | |
5527c038 JR |
31127 | + dir = d_inode(parent); |
31128 | + h_dir = d_inode(h_parent); | |
1facf9fc | 31129 | + AuDebugOn(h_dir != au_h_iptr(dir, bdst)); |
31130 | + IMustLock(h_dir); | |
31131 | + | |
86dc4139 | 31132 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); |
1facf9fc | 31133 | + if (unlikely(err < 0)) |
31134 | + goto out; | |
31135 | + h_path.dentry = au_h_dptr(dentry, bdst); | |
31136 | + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst); | |
31137 | + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, | |
31138 | + S_IRWXU | S_IRUGO | S_IXUGO); | |
31139 | + if (unlikely(err)) | |
31140 | + goto out_put; | |
c2b27bf2 | 31141 | + au_fset_cpdown(*flags, MADE_DIR); |
1facf9fc | 31142 | + |
1facf9fc | 31143 | + bopq = au_dbdiropq(dentry); |
c2b27bf2 AM |
31144 | + au_fclr_cpdown(*flags, WHED); |
31145 | + au_fclr_cpdown(*flags, DIROPQ); | |
1facf9fc | 31146 | + if (au_dbwh(dentry) == bdst) |
c2b27bf2 AM |
31147 | + au_fset_cpdown(*flags, WHED); |
31148 | + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst) | |
31149 | + au_fset_cpdown(*flags, PARENT_OPQ); | |
5527c038 | 31150 | + h_inode = d_inode(h_path.dentry); |
1facf9fc | 31151 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
c2b27bf2 AM |
31152 | + if (au_ftest_cpdown(*flags, WHED)) { |
31153 | + err = au_cpdown_dir_opq(dentry, bdst, flags); | |
1facf9fc | 31154 | + if (unlikely(err)) { |
31155 | + mutex_unlock(&h_inode->i_mutex); | |
31156 | + goto out_dir; | |
31157 | + } | |
31158 | + } | |
31159 | + | |
31160 | + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart)); | |
31161 | + mutex_unlock(&h_inode->i_mutex); | |
31162 | + if (unlikely(err)) | |
31163 | + goto out_opq; | |
31164 | + | |
c2b27bf2 | 31165 | + if (au_ftest_cpdown(*flags, WHED)) { |
1facf9fc | 31166 | + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst); |
31167 | + if (unlikely(err)) | |
31168 | + goto out_opq; | |
31169 | + } | |
31170 | + | |
5527c038 | 31171 | + inode = d_inode(dentry); |
1facf9fc | 31172 | + if (au_ibend(inode) < bdst) |
31173 | + au_set_ibend(inode, bdst); | |
31174 | + au_set_h_iptr(inode, bdst, au_igrab(h_inode), | |
31175 | + au_hi_flags(inode, /*isdir*/1)); | |
076b876e | 31176 | + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0); |
1facf9fc | 31177 | + goto out; /* success */ |
31178 | + | |
31179 | + /* revert */ | |
4f0767ce | 31180 | +out_opq: |
c2b27bf2 | 31181 | + if (au_ftest_cpdown(*flags, DIROPQ)) { |
1facf9fc | 31182 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
31183 | + rerr = au_diropq_remove(dentry, bdst); | |
31184 | + mutex_unlock(&h_inode->i_mutex); | |
31185 | + if (unlikely(rerr)) { | |
523b37e3 AM |
31186 | + AuIOErr("failed removing diropq for %pd b%d (%d)\n", |
31187 | + dentry, bdst, rerr); | |
1facf9fc | 31188 | + err = -EIO; |
31189 | + goto out; | |
31190 | + } | |
31191 | + } | |
4f0767ce | 31192 | +out_dir: |
c2b27bf2 | 31193 | + if (au_ftest_cpdown(*flags, MADE_DIR)) { |
1facf9fc | 31194 | + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path); |
31195 | + if (unlikely(rerr)) { | |
523b37e3 AM |
31196 | + AuIOErr("failed removing %pd b%d (%d)\n", |
31197 | + dentry, bdst, rerr); | |
1facf9fc | 31198 | + err = -EIO; |
31199 | + } | |
31200 | + } | |
4f0767ce | 31201 | +out_put: |
1facf9fc | 31202 | + au_set_h_dptr(dentry, bdst, NULL); |
31203 | + if (au_dbend(dentry) == bdst) | |
31204 | + au_update_dbend(dentry); | |
4f0767ce | 31205 | +out: |
1facf9fc | 31206 | + dput(parent); |
31207 | + return err; | |
31208 | +} | |
31209 | + | |
31210 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
31211 | +{ | |
31212 | + int err; | |
c2b27bf2 | 31213 | + unsigned int flags; |
1facf9fc | 31214 | + |
c2b27bf2 AM |
31215 | + flags = 0; |
31216 | + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags); | |
1facf9fc | 31217 | + |
31218 | + return err; | |
31219 | +} | |
31220 | + | |
31221 | +/* ---------------------------------------------------------------------- */ | |
31222 | + | |
31223 | +/* policies for create */ | |
31224 | + | |
c2b27bf2 | 31225 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex) |
4a4d8108 AM |
31226 | +{ |
31227 | + int err, i, j, ndentry; | |
31228 | + aufs_bindex_t bopq; | |
31229 | + struct au_dcsub_pages dpages; | |
31230 | + struct au_dpage *dpage; | |
31231 | + struct dentry **dentries, *parent, *d; | |
31232 | + | |
31233 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
31234 | + if (unlikely(err)) | |
31235 | + goto out; | |
31236 | + parent = dget_parent(dentry); | |
027c5e7a | 31237 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0); |
4a4d8108 AM |
31238 | + if (unlikely(err)) |
31239 | + goto out_free; | |
31240 | + | |
31241 | + err = bindex; | |
31242 | + for (i = 0; i < dpages.ndpage; i++) { | |
31243 | + dpage = dpages.dpages + i; | |
31244 | + dentries = dpage->dentries; | |
31245 | + ndentry = dpage->ndentry; | |
31246 | + for (j = 0; j < ndentry; j++) { | |
31247 | + d = dentries[j]; | |
31248 | + di_read_lock_parent2(d, !AuLock_IR); | |
31249 | + bopq = au_dbdiropq(d); | |
31250 | + di_read_unlock(d, !AuLock_IR); | |
31251 | + if (bopq >= 0 && bopq < err) | |
31252 | + err = bopq; | |
31253 | + } | |
31254 | + } | |
31255 | + | |
31256 | +out_free: | |
31257 | + dput(parent); | |
31258 | + au_dpages_free(&dpages); | |
31259 | +out: | |
31260 | + return err; | |
31261 | +} | |
31262 | + | |
1facf9fc | 31263 | +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex) |
31264 | +{ | |
31265 | + for (; bindex >= 0; bindex--) | |
31266 | + if (!au_br_rdonly(au_sbr(sb, bindex))) | |
31267 | + return bindex; | |
31268 | + return -EROFS; | |
31269 | +} | |
31270 | + | |
31271 | +/* top down parent */ | |
392086de AM |
31272 | +static int au_wbr_create_tdp(struct dentry *dentry, |
31273 | + unsigned int flags __maybe_unused) | |
1facf9fc | 31274 | +{ |
31275 | + int err; | |
31276 | + aufs_bindex_t bstart, bindex; | |
31277 | + struct super_block *sb; | |
31278 | + struct dentry *parent, *h_parent; | |
31279 | + | |
31280 | + sb = dentry->d_sb; | |
31281 | + bstart = au_dbstart(dentry); | |
31282 | + err = bstart; | |
31283 | + if (!au_br_rdonly(au_sbr(sb, bstart))) | |
31284 | + goto out; | |
31285 | + | |
31286 | + err = -EROFS; | |
31287 | + parent = dget_parent(dentry); | |
31288 | + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) { | |
31289 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31290 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 31291 | + continue; |
31292 | + | |
31293 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
31294 | + err = bindex; | |
31295 | + break; | |
31296 | + } | |
31297 | + } | |
31298 | + dput(parent); | |
31299 | + | |
31300 | + /* bottom up here */ | |
4a4d8108 | 31301 | + if (unlikely(err < 0)) { |
1facf9fc | 31302 | + err = au_wbr_bu(sb, bstart - 1); |
4a4d8108 AM |
31303 | + if (err >= 0) |
31304 | + err = au_wbr_nonopq(dentry, err); | |
31305 | + } | |
1facf9fc | 31306 | + |
4f0767ce | 31307 | +out: |
1facf9fc | 31308 | + AuDbg("b%d\n", err); |
31309 | + return err; | |
31310 | +} | |
31311 | + | |
31312 | +/* ---------------------------------------------------------------------- */ | |
31313 | + | |
31314 | +/* an exception for the policy other than tdp */ | |
31315 | +static int au_wbr_create_exp(struct dentry *dentry) | |
31316 | +{ | |
31317 | + int err; | |
31318 | + aufs_bindex_t bwh, bdiropq; | |
31319 | + struct dentry *parent; | |
31320 | + | |
31321 | + err = -1; | |
31322 | + bwh = au_dbwh(dentry); | |
31323 | + parent = dget_parent(dentry); | |
31324 | + bdiropq = au_dbdiropq(parent); | |
31325 | + if (bwh >= 0) { | |
31326 | + if (bdiropq >= 0) | |
31327 | + err = min(bdiropq, bwh); | |
31328 | + else | |
31329 | + err = bwh; | |
31330 | + AuDbg("%d\n", err); | |
31331 | + } else if (bdiropq >= 0) { | |
31332 | + err = bdiropq; | |
31333 | + AuDbg("%d\n", err); | |
31334 | + } | |
31335 | + dput(parent); | |
31336 | + | |
4a4d8108 AM |
31337 | + if (err >= 0) |
31338 | + err = au_wbr_nonopq(dentry, err); | |
31339 | + | |
1facf9fc | 31340 | + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err))) |
31341 | + err = -1; | |
31342 | + | |
31343 | + AuDbg("%d\n", err); | |
31344 | + return err; | |
31345 | +} | |
31346 | + | |
31347 | +/* ---------------------------------------------------------------------- */ | |
31348 | + | |
31349 | +/* round robin */ | |
31350 | +static int au_wbr_create_init_rr(struct super_block *sb) | |
31351 | +{ | |
31352 | + int err; | |
31353 | + | |
31354 | + err = au_wbr_bu(sb, au_sbend(sb)); | |
31355 | + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */ | |
dece6358 | 31356 | + /* smp_mb(); */ |
1facf9fc | 31357 | + |
31358 | + AuDbg("b%d\n", err); | |
31359 | + return err; | |
31360 | +} | |
31361 | + | |
392086de | 31362 | +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31363 | +{ |
31364 | + int err, nbr; | |
31365 | + unsigned int u; | |
31366 | + aufs_bindex_t bindex, bend; | |
31367 | + struct super_block *sb; | |
31368 | + atomic_t *next; | |
31369 | + | |
31370 | + err = au_wbr_create_exp(dentry); | |
31371 | + if (err >= 0) | |
31372 | + goto out; | |
31373 | + | |
31374 | + sb = dentry->d_sb; | |
31375 | + next = &au_sbi(sb)->si_wbr_rr_next; | |
31376 | + bend = au_sbend(sb); | |
31377 | + nbr = bend + 1; | |
31378 | + for (bindex = 0; bindex <= bend; bindex++) { | |
392086de | 31379 | + if (!au_ftest_wbr(flags, DIR)) { |
1facf9fc | 31380 | + err = atomic_dec_return(next) + 1; |
31381 | + /* modulo for 0 is meaningless */ | |
31382 | + if (unlikely(!err)) | |
31383 | + err = atomic_dec_return(next) + 1; | |
31384 | + } else | |
31385 | + err = atomic_read(next); | |
31386 | + AuDbg("%d\n", err); | |
31387 | + u = err; | |
31388 | + err = u % nbr; | |
31389 | + AuDbg("%d\n", err); | |
31390 | + if (!au_br_rdonly(au_sbr(sb, err))) | |
31391 | + break; | |
31392 | + err = -EROFS; | |
31393 | + } | |
31394 | + | |
4a4d8108 AM |
31395 | + if (err >= 0) |
31396 | + err = au_wbr_nonopq(dentry, err); | |
31397 | + | |
4f0767ce | 31398 | +out: |
1facf9fc | 31399 | + AuDbg("%d\n", err); |
31400 | + return err; | |
31401 | +} | |
31402 | + | |
31403 | +/* ---------------------------------------------------------------------- */ | |
31404 | + | |
31405 | +/* most free space */ | |
392086de | 31406 | +static void au_mfs(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 31407 | +{ |
31408 | + struct super_block *sb; | |
31409 | + struct au_branch *br; | |
31410 | + struct au_wbr_mfs *mfs; | |
392086de | 31411 | + struct dentry *h_parent; |
1facf9fc | 31412 | + aufs_bindex_t bindex, bend; |
31413 | + int err; | |
31414 | + unsigned long long b, bavail; | |
7f207e10 | 31415 | + struct path h_path; |
1facf9fc | 31416 | + /* reduce the stack usage */ |
31417 | + struct kstatfs *st; | |
31418 | + | |
31419 | + st = kmalloc(sizeof(*st), GFP_NOFS); | |
31420 | + if (unlikely(!st)) { | |
31421 | + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM); | |
31422 | + return; | |
31423 | + } | |
31424 | + | |
31425 | + bavail = 0; | |
31426 | + sb = dentry->d_sb; | |
31427 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
dece6358 | 31428 | + MtxMustLock(&mfs->mfs_lock); |
1facf9fc | 31429 | + mfs->mfs_bindex = -EROFS; |
31430 | + mfs->mfsrr_bytes = 0; | |
392086de AM |
31431 | + if (!parent) { |
31432 | + bindex = 0; | |
31433 | + bend = au_sbend(sb); | |
31434 | + } else { | |
31435 | + bindex = au_dbstart(parent); | |
31436 | + bend = au_dbtaildir(parent); | |
31437 | + } | |
31438 | + | |
31439 | + for (; bindex <= bend; bindex++) { | |
31440 | + if (parent) { | |
31441 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31442 | + if (!h_parent || d_is_negative(h_parent)) |
392086de AM |
31443 | + continue; |
31444 | + } | |
1facf9fc | 31445 | + br = au_sbr(sb, bindex); |
31446 | + if (au_br_rdonly(br)) | |
31447 | + continue; | |
31448 | + | |
31449 | + /* sb->s_root for NFS is unreliable */ | |
86dc4139 | 31450 | + h_path.mnt = au_br_mnt(br); |
7f207e10 AM |
31451 | + h_path.dentry = h_path.mnt->mnt_root; |
31452 | + err = vfs_statfs(&h_path, st); | |
1facf9fc | 31453 | + if (unlikely(err)) { |
31454 | + AuWarn1("failed statfs, b%d, %d\n", bindex, err); | |
31455 | + continue; | |
31456 | + } | |
31457 | + | |
31458 | + /* when the available size is equal, select the lower one */ | |
31459 | + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail) | |
31460 | + || sizeof(b) < sizeof(st->f_bsize)); | |
31461 | + b = st->f_bavail * st->f_bsize; | |
31462 | + br->br_wbr->wbr_bytes = b; | |
31463 | + if (b >= bavail) { | |
31464 | + bavail = b; | |
31465 | + mfs->mfs_bindex = bindex; | |
31466 | + mfs->mfs_jiffy = jiffies; | |
31467 | + } | |
31468 | + } | |
31469 | + | |
31470 | + mfs->mfsrr_bytes = bavail; | |
31471 | + AuDbg("b%d\n", mfs->mfs_bindex); | |
31472 | + kfree(st); | |
31473 | +} | |
31474 | + | |
392086de | 31475 | +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31476 | +{ |
31477 | + int err; | |
392086de | 31478 | + struct dentry *parent; |
1facf9fc | 31479 | + struct super_block *sb; |
31480 | + struct au_wbr_mfs *mfs; | |
31481 | + | |
31482 | + err = au_wbr_create_exp(dentry); | |
31483 | + if (err >= 0) | |
31484 | + goto out; | |
31485 | + | |
31486 | + sb = dentry->d_sb; | |
392086de AM |
31487 | + parent = NULL; |
31488 | + if (au_ftest_wbr(flags, PARENT)) | |
31489 | + parent = dget_parent(dentry); | |
1facf9fc | 31490 | + mfs = &au_sbi(sb)->si_wbr_mfs; |
31491 | + mutex_lock(&mfs->mfs_lock); | |
31492 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
31493 | + || mfs->mfs_bindex < 0 | |
31494 | + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex))) | |
392086de | 31495 | + au_mfs(dentry, parent); |
1facf9fc | 31496 | + mutex_unlock(&mfs->mfs_lock); |
31497 | + err = mfs->mfs_bindex; | |
392086de | 31498 | + dput(parent); |
1facf9fc | 31499 | + |
4a4d8108 AM |
31500 | + if (err >= 0) |
31501 | + err = au_wbr_nonopq(dentry, err); | |
31502 | + | |
4f0767ce | 31503 | +out: |
1facf9fc | 31504 | + AuDbg("b%d\n", err); |
31505 | + return err; | |
31506 | +} | |
31507 | + | |
31508 | +static int au_wbr_create_init_mfs(struct super_block *sb) | |
31509 | +{ | |
31510 | + struct au_wbr_mfs *mfs; | |
31511 | + | |
31512 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
31513 | + mutex_init(&mfs->mfs_lock); | |
31514 | + mfs->mfs_jiffy = 0; | |
31515 | + mfs->mfs_bindex = -EROFS; | |
31516 | + | |
31517 | + return 0; | |
31518 | +} | |
31519 | + | |
31520 | +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused) | |
31521 | +{ | |
31522 | + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock); | |
31523 | + return 0; | |
31524 | +} | |
31525 | + | |
31526 | +/* ---------------------------------------------------------------------- */ | |
31527 | + | |
31528 | +/* most free space and then round robin */ | |
392086de | 31529 | +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31530 | +{ |
31531 | + int err; | |
31532 | + struct au_wbr_mfs *mfs; | |
31533 | + | |
392086de | 31534 | + err = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 31535 | + if (err >= 0) { |
31536 | + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs; | |
dece6358 | 31537 | + mutex_lock(&mfs->mfs_lock); |
1facf9fc | 31538 | + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark) |
392086de | 31539 | + err = au_wbr_create_rr(dentry, flags); |
dece6358 | 31540 | + mutex_unlock(&mfs->mfs_lock); |
1facf9fc | 31541 | + } |
31542 | + | |
31543 | + AuDbg("b%d\n", err); | |
31544 | + return err; | |
31545 | +} | |
31546 | + | |
31547 | +static int au_wbr_create_init_mfsrr(struct super_block *sb) | |
31548 | +{ | |
31549 | + int err; | |
31550 | + | |
31551 | + au_wbr_create_init_mfs(sb); /* ignore */ | |
31552 | + err = au_wbr_create_init_rr(sb); | |
31553 | + | |
31554 | + return err; | |
31555 | +} | |
31556 | + | |
31557 | +/* ---------------------------------------------------------------------- */ | |
31558 | + | |
31559 | +/* top down parent and most free space */ | |
392086de | 31560 | +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31561 | +{ |
31562 | + int err, e2; | |
31563 | + unsigned long long b; | |
31564 | + aufs_bindex_t bindex, bstart, bend; | |
31565 | + struct super_block *sb; | |
31566 | + struct dentry *parent, *h_parent; | |
31567 | + struct au_branch *br; | |
31568 | + | |
392086de | 31569 | + err = au_wbr_create_tdp(dentry, flags); |
1facf9fc | 31570 | + if (unlikely(err < 0)) |
31571 | + goto out; | |
31572 | + parent = dget_parent(dentry); | |
31573 | + bstart = au_dbstart(parent); | |
31574 | + bend = au_dbtaildir(parent); | |
31575 | + if (bstart == bend) | |
31576 | + goto out_parent; /* success */ | |
31577 | + | |
392086de | 31578 | + e2 = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 31579 | + if (e2 < 0) |
31580 | + goto out_parent; /* success */ | |
31581 | + | |
31582 | + /* when the available size is equal, select upper one */ | |
31583 | + sb = dentry->d_sb; | |
31584 | + br = au_sbr(sb, err); | |
31585 | + b = br->br_wbr->wbr_bytes; | |
31586 | + AuDbg("b%d, %llu\n", err, b); | |
31587 | + | |
31588 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
31589 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31590 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 31591 | + continue; |
31592 | + | |
31593 | + br = au_sbr(sb, bindex); | |
31594 | + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) { | |
31595 | + b = br->br_wbr->wbr_bytes; | |
31596 | + err = bindex; | |
31597 | + AuDbg("b%d, %llu\n", err, b); | |
31598 | + } | |
31599 | + } | |
31600 | + | |
4a4d8108 AM |
31601 | + if (err >= 0) |
31602 | + err = au_wbr_nonopq(dentry, err); | |
31603 | + | |
4f0767ce | 31604 | +out_parent: |
1facf9fc | 31605 | + dput(parent); |
4f0767ce | 31606 | +out: |
1facf9fc | 31607 | + AuDbg("b%d\n", err); |
31608 | + return err; | |
31609 | +} | |
31610 | + | |
31611 | +/* ---------------------------------------------------------------------- */ | |
31612 | + | |
392086de AM |
31613 | +/* |
31614 | + * - top down parent | |
31615 | + * - most free space with parent | |
31616 | + * - most free space round-robin regardless parent | |
31617 | + */ | |
31618 | +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags) | |
31619 | +{ | |
31620 | + int err; | |
31621 | + unsigned long long watermark; | |
31622 | + struct super_block *sb; | |
31623 | + struct au_branch *br; | |
31624 | + struct au_wbr_mfs *mfs; | |
31625 | + | |
31626 | + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT); | |
31627 | + if (unlikely(err < 0)) | |
31628 | + goto out; | |
31629 | + | |
31630 | + sb = dentry->d_sb; | |
31631 | + br = au_sbr(sb, err); | |
31632 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
31633 | + mutex_lock(&mfs->mfs_lock); | |
31634 | + watermark = mfs->mfsrr_watermark; | |
31635 | + mutex_unlock(&mfs->mfs_lock); | |
31636 | + if (br->br_wbr->wbr_bytes < watermark) | |
31637 | + /* regardless the parent dir */ | |
31638 | + err = au_wbr_create_mfsrr(dentry, flags); | |
31639 | + | |
31640 | +out: | |
31641 | + AuDbg("b%d\n", err); | |
31642 | + return err; | |
31643 | +} | |
31644 | + | |
31645 | +/* ---------------------------------------------------------------------- */ | |
31646 | + | |
1facf9fc | 31647 | +/* policies for copyup */ |
31648 | + | |
31649 | +/* top down parent */ | |
31650 | +static int au_wbr_copyup_tdp(struct dentry *dentry) | |
31651 | +{ | |
392086de | 31652 | + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0); |
1facf9fc | 31653 | +} |
31654 | + | |
31655 | +/* bottom up parent */ | |
31656 | +static int au_wbr_copyup_bup(struct dentry *dentry) | |
31657 | +{ | |
31658 | + int err; | |
31659 | + aufs_bindex_t bindex, bstart; | |
31660 | + struct dentry *parent, *h_parent; | |
31661 | + struct super_block *sb; | |
31662 | + | |
31663 | + err = -EROFS; | |
31664 | + sb = dentry->d_sb; | |
31665 | + parent = dget_parent(dentry); | |
31666 | + bstart = au_dbstart(parent); | |
31667 | + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) { | |
31668 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31669 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 31670 | + continue; |
31671 | + | |
31672 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
31673 | + err = bindex; | |
31674 | + break; | |
31675 | + } | |
31676 | + } | |
31677 | + dput(parent); | |
31678 | + | |
31679 | + /* bottom up here */ | |
31680 | + if (unlikely(err < 0)) | |
31681 | + err = au_wbr_bu(sb, bstart - 1); | |
31682 | + | |
31683 | + AuDbg("b%d\n", err); | |
31684 | + return err; | |
31685 | +} | |
31686 | + | |
31687 | +/* bottom up */ | |
076b876e | 31688 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart) |
1facf9fc | 31689 | +{ |
31690 | + int err; | |
31691 | + | |
4a4d8108 AM |
31692 | + err = au_wbr_bu(dentry->d_sb, bstart); |
31693 | + AuDbg("b%d\n", err); | |
31694 | + if (err > bstart) | |
31695 | + err = au_wbr_nonopq(dentry, err); | |
1facf9fc | 31696 | + |
31697 | + AuDbg("b%d\n", err); | |
31698 | + return err; | |
31699 | +} | |
31700 | + | |
076b876e AM |
31701 | +static int au_wbr_copyup_bu(struct dentry *dentry) |
31702 | +{ | |
31703 | + int err; | |
31704 | + aufs_bindex_t bstart; | |
31705 | + | |
31706 | + bstart = au_dbstart(dentry); | |
31707 | + err = au_wbr_do_copyup_bu(dentry, bstart); | |
31708 | + return err; | |
31709 | +} | |
31710 | + | |
1facf9fc | 31711 | +/* ---------------------------------------------------------------------- */ |
31712 | + | |
31713 | +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = { | |
31714 | + [AuWbrCopyup_TDP] = { | |
31715 | + .copyup = au_wbr_copyup_tdp | |
31716 | + }, | |
31717 | + [AuWbrCopyup_BUP] = { | |
31718 | + .copyup = au_wbr_copyup_bup | |
31719 | + }, | |
31720 | + [AuWbrCopyup_BU] = { | |
31721 | + .copyup = au_wbr_copyup_bu | |
31722 | + } | |
31723 | +}; | |
31724 | + | |
31725 | +struct au_wbr_create_operations au_wbr_create_ops[] = { | |
31726 | + [AuWbrCreate_TDP] = { | |
31727 | + .create = au_wbr_create_tdp | |
31728 | + }, | |
31729 | + [AuWbrCreate_RR] = { | |
31730 | + .create = au_wbr_create_rr, | |
31731 | + .init = au_wbr_create_init_rr | |
31732 | + }, | |
31733 | + [AuWbrCreate_MFS] = { | |
31734 | + .create = au_wbr_create_mfs, | |
31735 | + .init = au_wbr_create_init_mfs, | |
31736 | + .fin = au_wbr_create_fin_mfs | |
31737 | + }, | |
31738 | + [AuWbrCreate_MFSV] = { | |
31739 | + .create = au_wbr_create_mfs, | |
31740 | + .init = au_wbr_create_init_mfs, | |
31741 | + .fin = au_wbr_create_fin_mfs | |
31742 | + }, | |
31743 | + [AuWbrCreate_MFSRR] = { | |
31744 | + .create = au_wbr_create_mfsrr, | |
31745 | + .init = au_wbr_create_init_mfsrr, | |
31746 | + .fin = au_wbr_create_fin_mfs | |
31747 | + }, | |
31748 | + [AuWbrCreate_MFSRRV] = { | |
31749 | + .create = au_wbr_create_mfsrr, | |
31750 | + .init = au_wbr_create_init_mfsrr, | |
31751 | + .fin = au_wbr_create_fin_mfs | |
31752 | + }, | |
31753 | + [AuWbrCreate_PMFS] = { | |
31754 | + .create = au_wbr_create_pmfs, | |
31755 | + .init = au_wbr_create_init_mfs, | |
31756 | + .fin = au_wbr_create_fin_mfs | |
31757 | + }, | |
31758 | + [AuWbrCreate_PMFSV] = { | |
31759 | + .create = au_wbr_create_pmfs, | |
31760 | + .init = au_wbr_create_init_mfs, | |
31761 | + .fin = au_wbr_create_fin_mfs | |
392086de AM |
31762 | + }, |
31763 | + [AuWbrCreate_PMFSRR] = { | |
31764 | + .create = au_wbr_create_pmfsrr, | |
31765 | + .init = au_wbr_create_init_mfsrr, | |
31766 | + .fin = au_wbr_create_fin_mfs | |
31767 | + }, | |
31768 | + [AuWbrCreate_PMFSRRV] = { | |
31769 | + .create = au_wbr_create_pmfsrr, | |
31770 | + .init = au_wbr_create_init_mfsrr, | |
31771 | + .fin = au_wbr_create_fin_mfs | |
1facf9fc | 31772 | + } |
31773 | +}; | |
7f207e10 AM |
31774 | diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c |
31775 | --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
31776 | +++ linux/fs/aufs/whout.c 2015-06-28 17:36:09.028407078 +0200 |
31777 | @@ -0,0 +1,1063 @@ | |
1facf9fc | 31778 | +/* |
2000de60 | 31779 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 31780 | + * |
31781 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31782 | + * it under the terms of the GNU General Public License as published by | |
31783 | + * the Free Software Foundation; either version 2 of the License, or | |
31784 | + * (at your option) any later version. | |
dece6358 AM |
31785 | + * |
31786 | + * This program is distributed in the hope that it will be useful, | |
31787 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31788 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31789 | + * GNU General Public License for more details. | |
31790 | + * | |
31791 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31792 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31793 | + */ |
31794 | + | |
31795 | +/* | |
31796 | + * whiteout for logical deletion and opaque directory | |
31797 | + */ | |
31798 | + | |
1facf9fc | 31799 | +#include "aufs.h" |
31800 | + | |
31801 | +#define WH_MASK S_IRUGO | |
31802 | + | |
31803 | +/* | |
31804 | + * If a directory contains this file, then it is opaque. We start with the | |
31805 | + * .wh. flag so that it is blocked by lookup. | |
31806 | + */ | |
0c3ec466 AM |
31807 | +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ, |
31808 | + sizeof(AUFS_WH_DIROPQ) - 1); | |
1facf9fc | 31809 | + |
31810 | +/* | |
31811 | + * generate whiteout name, which is NOT terminated by NULL. | |
31812 | + * @name: original d_name.name | |
31813 | + * @len: original d_name.len | |
31814 | + * @wh: whiteout qstr | |
31815 | + * returns zero when succeeds, otherwise error. | |
31816 | + * succeeded value as wh->name should be freed by kfree(). | |
31817 | + */ | |
31818 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name) | |
31819 | +{ | |
31820 | + char *p; | |
31821 | + | |
31822 | + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN)) | |
31823 | + return -ENAMETOOLONG; | |
31824 | + | |
31825 | + wh->len = name->len + AUFS_WH_PFX_LEN; | |
31826 | + p = kmalloc(wh->len, GFP_NOFS); | |
31827 | + wh->name = p; | |
31828 | + if (p) { | |
31829 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
31830 | + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len); | |
31831 | + /* smp_mb(); */ | |
31832 | + return 0; | |
31833 | + } | |
31834 | + return -ENOMEM; | |
31835 | +} | |
31836 | + | |
31837 | +/* ---------------------------------------------------------------------- */ | |
31838 | + | |
31839 | +/* | |
31840 | + * test if the @wh_name exists under @h_parent. | |
31841 | + * @try_sio specifies the necessary of super-io. | |
31842 | + */ | |
076b876e | 31843 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio) |
1facf9fc | 31844 | +{ |
31845 | + int err; | |
31846 | + struct dentry *wh_dentry; | |
1facf9fc | 31847 | + |
1facf9fc | 31848 | + if (!try_sio) |
b4510431 | 31849 | + wh_dentry = vfsub_lkup_one(wh_name, h_parent); |
1facf9fc | 31850 | + else |
076b876e | 31851 | + wh_dentry = au_sio_lkup_one(wh_name, h_parent); |
1facf9fc | 31852 | + err = PTR_ERR(wh_dentry); |
2000de60 JR |
31853 | + if (IS_ERR(wh_dentry)) { |
31854 | + if (err == -ENAMETOOLONG) | |
31855 | + err = 0; | |
1facf9fc | 31856 | + goto out; |
2000de60 | 31857 | + } |
1facf9fc | 31858 | + |
31859 | + err = 0; | |
5527c038 | 31860 | + if (d_is_negative(wh_dentry)) |
1facf9fc | 31861 | + goto out_wh; /* success */ |
31862 | + | |
31863 | + err = 1; | |
7e9cd9fe | 31864 | + if (d_is_reg(wh_dentry)) |
1facf9fc | 31865 | + goto out_wh; /* success */ |
31866 | + | |
31867 | + err = -EIO; | |
523b37e3 | 31868 | + AuIOErr("%pd Invalid whiteout entry type 0%o.\n", |
5527c038 | 31869 | + wh_dentry, d_inode(wh_dentry)->i_mode); |
1facf9fc | 31870 | + |
4f0767ce | 31871 | +out_wh: |
1facf9fc | 31872 | + dput(wh_dentry); |
4f0767ce | 31873 | +out: |
1facf9fc | 31874 | + return err; |
31875 | +} | |
31876 | + | |
31877 | +/* | |
31878 | + * test if the @h_dentry sets opaque or not. | |
31879 | + */ | |
076b876e | 31880 | +int au_diropq_test(struct dentry *h_dentry) |
1facf9fc | 31881 | +{ |
31882 | + int err; | |
31883 | + struct inode *h_dir; | |
31884 | + | |
5527c038 | 31885 | + h_dir = d_inode(h_dentry); |
076b876e | 31886 | + err = au_wh_test(h_dentry, &diropq_name, |
1facf9fc | 31887 | + au_test_h_perm_sio(h_dir, MAY_EXEC)); |
31888 | + return err; | |
31889 | +} | |
31890 | + | |
31891 | +/* | |
31892 | + * returns a negative dentry whose name is unique and temporary. | |
31893 | + */ | |
31894 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, | |
31895 | + struct qstr *prefix) | |
31896 | +{ | |
1facf9fc | 31897 | + struct dentry *dentry; |
31898 | + int i; | |
027c5e7a | 31899 | + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1], |
4a4d8108 | 31900 | + *name, *p; |
027c5e7a | 31901 | + /* strict atomic_t is unnecessary here */ |
1facf9fc | 31902 | + static unsigned short cnt; |
31903 | + struct qstr qs; | |
31904 | + | |
4a4d8108 AM |
31905 | + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN); |
31906 | + | |
1facf9fc | 31907 | + name = defname; |
027c5e7a AM |
31908 | + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1; |
31909 | + if (unlikely(prefix->len > DNAME_INLINE_LEN)) { | |
1facf9fc | 31910 | + dentry = ERR_PTR(-ENAMETOOLONG); |
4a4d8108 | 31911 | + if (unlikely(qs.len > NAME_MAX)) |
1facf9fc | 31912 | + goto out; |
31913 | + dentry = ERR_PTR(-ENOMEM); | |
31914 | + name = kmalloc(qs.len + 1, GFP_NOFS); | |
31915 | + if (unlikely(!name)) | |
31916 | + goto out; | |
31917 | + } | |
31918 | + | |
31919 | + /* doubly whiteout-ed */ | |
31920 | + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2); | |
31921 | + p = name + AUFS_WH_PFX_LEN * 2; | |
31922 | + memcpy(p, prefix->name, prefix->len); | |
31923 | + p += prefix->len; | |
31924 | + *p++ = '.'; | |
4a4d8108 | 31925 | + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN); |
1facf9fc | 31926 | + |
31927 | + qs.name = name; | |
31928 | + for (i = 0; i < 3; i++) { | |
b752ccd1 | 31929 | + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++); |
076b876e | 31930 | + dentry = au_sio_lkup_one(&qs, h_parent); |
5527c038 | 31931 | + if (IS_ERR(dentry) || d_is_negative(dentry)) |
1facf9fc | 31932 | + goto out_name; |
31933 | + dput(dentry); | |
31934 | + } | |
0c3ec466 | 31935 | + /* pr_warn("could not get random name\n"); */ |
1facf9fc | 31936 | + dentry = ERR_PTR(-EEXIST); |
31937 | + AuDbg("%.*s\n", AuLNPair(&qs)); | |
31938 | + BUG(); | |
31939 | + | |
4f0767ce | 31940 | +out_name: |
1facf9fc | 31941 | + if (name != defname) |
31942 | + kfree(name); | |
4f0767ce | 31943 | +out: |
4a4d8108 | 31944 | + AuTraceErrPtr(dentry); |
1facf9fc | 31945 | + return dentry; |
1facf9fc | 31946 | +} |
31947 | + | |
31948 | +/* | |
31949 | + * rename the @h_dentry on @br to the whiteouted temporary name. | |
31950 | + */ | |
31951 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br) | |
31952 | +{ | |
31953 | + int err; | |
31954 | + struct path h_path = { | |
86dc4139 | 31955 | + .mnt = au_br_mnt(br) |
1facf9fc | 31956 | + }; |
523b37e3 | 31957 | + struct inode *h_dir, *delegated; |
1facf9fc | 31958 | + struct dentry *h_parent; |
31959 | + | |
31960 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ | |
5527c038 | 31961 | + h_dir = d_inode(h_parent); |
1facf9fc | 31962 | + IMustLock(h_dir); |
31963 | + | |
31964 | + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name); | |
31965 | + err = PTR_ERR(h_path.dentry); | |
31966 | + if (IS_ERR(h_path.dentry)) | |
31967 | + goto out; | |
31968 | + | |
31969 | + /* under the same dir, no need to lock_rename() */ | |
523b37e3 AM |
31970 | + delegated = NULL; |
31971 | + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated); | |
1facf9fc | 31972 | + AuTraceErr(err); |
523b37e3 AM |
31973 | + if (unlikely(err == -EWOULDBLOCK)) { |
31974 | + pr_warn("cannot retry for NFSv4 delegation" | |
31975 | + " for an internal rename\n"); | |
31976 | + iput(delegated); | |
31977 | + } | |
1facf9fc | 31978 | + dput(h_path.dentry); |
31979 | + | |
4f0767ce | 31980 | +out: |
4a4d8108 | 31981 | + AuTraceErr(err); |
1facf9fc | 31982 | + return err; |
31983 | +} | |
31984 | + | |
31985 | +/* ---------------------------------------------------------------------- */ | |
31986 | +/* | |
31987 | + * functions for removing a whiteout | |
31988 | + */ | |
31989 | + | |
31990 | +static int do_unlink_wh(struct inode *h_dir, struct path *h_path) | |
31991 | +{ | |
523b37e3 AM |
31992 | + int err, force; |
31993 | + struct inode *delegated; | |
1facf9fc | 31994 | + |
31995 | + /* | |
31996 | + * forces superio when the dir has a sticky bit. | |
31997 | + * this may be a violation of unix fs semantics. | |
31998 | + */ | |
31999 | + force = (h_dir->i_mode & S_ISVTX) | |
5527c038 | 32000 | + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid); |
523b37e3 AM |
32001 | + delegated = NULL; |
32002 | + err = vfsub_unlink(h_dir, h_path, &delegated, force); | |
32003 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32004 | + pr_warn("cannot retry for NFSv4 delegation" | |
32005 | + " for an internal unlink\n"); | |
32006 | + iput(delegated); | |
32007 | + } | |
32008 | + return err; | |
1facf9fc | 32009 | +} |
32010 | + | |
32011 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
32012 | + struct dentry *dentry) | |
32013 | +{ | |
32014 | + int err; | |
32015 | + | |
32016 | + err = do_unlink_wh(h_dir, h_path); | |
32017 | + if (!err && dentry) | |
32018 | + au_set_dbwh(dentry, -1); | |
32019 | + | |
32020 | + return err; | |
32021 | +} | |
32022 | + | |
32023 | +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh, | |
32024 | + struct au_branch *br) | |
32025 | +{ | |
32026 | + int err; | |
32027 | + struct path h_path = { | |
86dc4139 | 32028 | + .mnt = au_br_mnt(br) |
1facf9fc | 32029 | + }; |
32030 | + | |
32031 | + err = 0; | |
b4510431 | 32032 | + h_path.dentry = vfsub_lkup_one(wh, h_parent); |
1facf9fc | 32033 | + if (IS_ERR(h_path.dentry)) |
32034 | + err = PTR_ERR(h_path.dentry); | |
32035 | + else { | |
5527c038 JR |
32036 | + if (d_is_reg(h_path.dentry)) |
32037 | + err = do_unlink_wh(d_inode(h_parent), &h_path); | |
1facf9fc | 32038 | + dput(h_path.dentry); |
32039 | + } | |
32040 | + | |
32041 | + return err; | |
32042 | +} | |
32043 | + | |
32044 | +/* ---------------------------------------------------------------------- */ | |
32045 | +/* | |
32046 | + * initialize/clean whiteout for a branch | |
32047 | + */ | |
32048 | + | |
32049 | +static void au_wh_clean(struct inode *h_dir, struct path *whpath, | |
32050 | + const int isdir) | |
32051 | +{ | |
32052 | + int err; | |
523b37e3 | 32053 | + struct inode *delegated; |
1facf9fc | 32054 | + |
5527c038 | 32055 | + if (d_is_negative(whpath->dentry)) |
1facf9fc | 32056 | + return; |
32057 | + | |
86dc4139 AM |
32058 | + if (isdir) |
32059 | + err = vfsub_rmdir(h_dir, whpath); | |
523b37e3 AM |
32060 | + else { |
32061 | + delegated = NULL; | |
32062 | + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0); | |
32063 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32064 | + pr_warn("cannot retry for NFSv4 delegation" | |
32065 | + " for an internal unlink\n"); | |
32066 | + iput(delegated); | |
32067 | + } | |
32068 | + } | |
1facf9fc | 32069 | + if (unlikely(err)) |
523b37e3 AM |
32070 | + pr_warn("failed removing %pd (%d), ignored.\n", |
32071 | + whpath->dentry, err); | |
1facf9fc | 32072 | +} |
32073 | + | |
32074 | +static int test_linkable(struct dentry *h_root) | |
32075 | +{ | |
5527c038 | 32076 | + struct inode *h_dir = d_inode(h_root); |
1facf9fc | 32077 | + |
32078 | + if (h_dir->i_op->link) | |
32079 | + return 0; | |
32080 | + | |
523b37e3 AM |
32081 | + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n", |
32082 | + h_root, au_sbtype(h_root->d_sb)); | |
1facf9fc | 32083 | + return -ENOSYS; |
32084 | +} | |
32085 | + | |
32086 | +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */ | |
32087 | +static int au_whdir(struct inode *h_dir, struct path *path) | |
32088 | +{ | |
32089 | + int err; | |
32090 | + | |
32091 | + err = -EEXIST; | |
5527c038 | 32092 | + if (d_is_negative(path->dentry)) { |
1facf9fc | 32093 | + int mode = S_IRWXU; |
32094 | + | |
32095 | + if (au_test_nfs(path->dentry->d_sb)) | |
32096 | + mode |= S_IXUGO; | |
86dc4139 | 32097 | + err = vfsub_mkdir(h_dir, path, mode); |
2000de60 | 32098 | + } else if (d_is_dir(path->dentry)) |
1facf9fc | 32099 | + err = 0; |
32100 | + else | |
523b37e3 | 32101 | + pr_err("unknown %pd exists\n", path->dentry); |
1facf9fc | 32102 | + |
32103 | + return err; | |
32104 | +} | |
32105 | + | |
32106 | +struct au_wh_base { | |
32107 | + const struct qstr *name; | |
32108 | + struct dentry *dentry; | |
32109 | +}; | |
32110 | + | |
32111 | +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[], | |
32112 | + struct path *h_path) | |
32113 | +{ | |
32114 | + h_path->dentry = base[AuBrWh_BASE].dentry; | |
32115 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
32116 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
32117 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32118 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
32119 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32120 | +} | |
32121 | + | |
32122 | +/* | |
32123 | + * returns tri-state, | |
c1595e42 | 32124 | + * minus: error, caller should print the message |
1facf9fc | 32125 | + * zero: succuess |
c1595e42 | 32126 | + * plus: error, caller should NOT print the message |
1facf9fc | 32127 | + */ |
32128 | +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr, | |
32129 | + int do_plink, struct au_wh_base base[], | |
32130 | + struct path *h_path) | |
32131 | +{ | |
32132 | + int err; | |
32133 | + struct inode *h_dir; | |
32134 | + | |
5527c038 | 32135 | + h_dir = d_inode(h_root); |
1facf9fc | 32136 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
32137 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
32138 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
32139 | + if (do_plink) { | |
32140 | + err = test_linkable(h_root); | |
32141 | + if (unlikely(err)) { | |
32142 | + err = 1; | |
32143 | + goto out; | |
32144 | + } | |
32145 | + | |
32146 | + err = au_whdir(h_dir, h_path); | |
32147 | + if (unlikely(err)) | |
32148 | + goto out; | |
32149 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
32150 | + } else | |
32151 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32152 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
32153 | + err = au_whdir(h_dir, h_path); | |
32154 | + if (unlikely(err)) | |
32155 | + goto out; | |
32156 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
32157 | + | |
4f0767ce | 32158 | +out: |
1facf9fc | 32159 | + return err; |
32160 | +} | |
32161 | + | |
32162 | +/* | |
32163 | + * for the moment, aufs supports the branch filesystem which does not support | |
32164 | + * link(2). testing on FAT which does not support i_op->setattr() fully either, | |
32165 | + * copyup failed. finally, such filesystem will not be used as the writable | |
32166 | + * branch. | |
32167 | + * | |
32168 | + * returns tri-state, see above. | |
32169 | + */ | |
32170 | +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr, | |
32171 | + int do_plink, struct au_wh_base base[], | |
32172 | + struct path *h_path) | |
32173 | +{ | |
32174 | + int err; | |
32175 | + struct inode *h_dir; | |
32176 | + | |
1308ab2a | 32177 | + WbrWhMustWriteLock(wbr); |
32178 | + | |
1facf9fc | 32179 | + err = test_linkable(h_root); |
32180 | + if (unlikely(err)) { | |
32181 | + err = 1; | |
32182 | + goto out; | |
32183 | + } | |
32184 | + | |
32185 | + /* | |
32186 | + * todo: should this create be done in /sbin/mount.aufs helper? | |
32187 | + */ | |
32188 | + err = -EEXIST; | |
5527c038 JR |
32189 | + h_dir = d_inode(h_root); |
32190 | + if (d_is_negative(base[AuBrWh_BASE].dentry)) { | |
86dc4139 AM |
32191 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
32192 | + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true); | |
7e9cd9fe | 32193 | + } else if (d_is_reg(base[AuBrWh_BASE].dentry)) |
1facf9fc | 32194 | + err = 0; |
32195 | + else | |
523b37e3 | 32196 | + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry); |
1facf9fc | 32197 | + if (unlikely(err)) |
32198 | + goto out; | |
32199 | + | |
32200 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
32201 | + if (do_plink) { | |
32202 | + err = au_whdir(h_dir, h_path); | |
32203 | + if (unlikely(err)) | |
32204 | + goto out; | |
32205 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
32206 | + } else | |
32207 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32208 | + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry); | |
32209 | + | |
32210 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
32211 | + err = au_whdir(h_dir, h_path); | |
32212 | + if (unlikely(err)) | |
32213 | + goto out; | |
32214 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
32215 | + | |
4f0767ce | 32216 | +out: |
1facf9fc | 32217 | + return err; |
32218 | +} | |
32219 | + | |
32220 | +/* | |
32221 | + * initialize the whiteout base file/dir for @br. | |
32222 | + */ | |
86dc4139 | 32223 | +int au_wh_init(struct au_branch *br, struct super_block *sb) |
1facf9fc | 32224 | +{ |
32225 | + int err, i; | |
32226 | + const unsigned char do_plink | |
32227 | + = !!au_opt_test(au_mntflags(sb), PLINK); | |
1facf9fc | 32228 | + struct inode *h_dir; |
86dc4139 AM |
32229 | + struct path path = br->br_path; |
32230 | + struct dentry *h_root = path.dentry; | |
1facf9fc | 32231 | + struct au_wbr *wbr = br->br_wbr; |
32232 | + static const struct qstr base_name[] = { | |
0c3ec466 AM |
32233 | + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME, |
32234 | + sizeof(AUFS_BASE_NAME) - 1), | |
32235 | + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME, | |
32236 | + sizeof(AUFS_PLINKDIR_NAME) - 1), | |
32237 | + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME, | |
32238 | + sizeof(AUFS_ORPHDIR_NAME) - 1) | |
1facf9fc | 32239 | + }; |
32240 | + struct au_wh_base base[] = { | |
32241 | + [AuBrWh_BASE] = { | |
32242 | + .name = base_name + AuBrWh_BASE, | |
32243 | + .dentry = NULL | |
32244 | + }, | |
32245 | + [AuBrWh_PLINK] = { | |
32246 | + .name = base_name + AuBrWh_PLINK, | |
32247 | + .dentry = NULL | |
32248 | + }, | |
32249 | + [AuBrWh_ORPH] = { | |
32250 | + .name = base_name + AuBrWh_ORPH, | |
32251 | + .dentry = NULL | |
32252 | + } | |
32253 | + }; | |
32254 | + | |
1308ab2a | 32255 | + if (wbr) |
32256 | + WbrWhMustWriteLock(wbr); | |
1facf9fc | 32257 | + |
1facf9fc | 32258 | + for (i = 0; i < AuBrWh_Last; i++) { |
32259 | + /* doubly whiteouted */ | |
32260 | + struct dentry *d; | |
32261 | + | |
32262 | + d = au_wh_lkup(h_root, (void *)base[i].name, br); | |
32263 | + err = PTR_ERR(d); | |
32264 | + if (IS_ERR(d)) | |
32265 | + goto out; | |
32266 | + | |
32267 | + base[i].dentry = d; | |
32268 | + AuDebugOn(wbr | |
32269 | + && wbr->wbr_wh[i] | |
32270 | + && wbr->wbr_wh[i] != base[i].dentry); | |
32271 | + } | |
32272 | + | |
32273 | + if (wbr) | |
32274 | + for (i = 0; i < AuBrWh_Last; i++) { | |
32275 | + dput(wbr->wbr_wh[i]); | |
32276 | + wbr->wbr_wh[i] = NULL; | |
32277 | + } | |
32278 | + | |
32279 | + err = 0; | |
1e00d052 | 32280 | + if (!au_br_writable(br->br_perm)) { |
5527c038 | 32281 | + h_dir = d_inode(h_root); |
1facf9fc | 32282 | + au_wh_init_ro(h_dir, base, &path); |
1e00d052 | 32283 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 32284 | + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path); |
32285 | + if (err > 0) | |
32286 | + goto out; | |
32287 | + else if (err) | |
32288 | + goto out_err; | |
1e00d052 | 32289 | + } else { |
1facf9fc | 32290 | + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path); |
32291 | + if (err > 0) | |
32292 | + goto out; | |
32293 | + else if (err) | |
32294 | + goto out_err; | |
1facf9fc | 32295 | + } |
32296 | + goto out; /* success */ | |
32297 | + | |
4f0767ce | 32298 | +out_err: |
523b37e3 AM |
32299 | + pr_err("an error(%d) on the writable branch %pd(%s)\n", |
32300 | + err, h_root, au_sbtype(h_root->d_sb)); | |
4f0767ce | 32301 | +out: |
1facf9fc | 32302 | + for (i = 0; i < AuBrWh_Last; i++) |
32303 | + dput(base[i].dentry); | |
32304 | + return err; | |
32305 | +} | |
32306 | + | |
32307 | +/* ---------------------------------------------------------------------- */ | |
32308 | +/* | |
32309 | + * whiteouts are all hard-linked usually. | |
32310 | + * when its link count reaches a ceiling, we create a new whiteout base | |
32311 | + * asynchronously. | |
32312 | + */ | |
32313 | + | |
32314 | +struct reinit_br_wh { | |
32315 | + struct super_block *sb; | |
32316 | + struct au_branch *br; | |
32317 | +}; | |
32318 | + | |
32319 | +static void reinit_br_wh(void *arg) | |
32320 | +{ | |
32321 | + int err; | |
32322 | + aufs_bindex_t bindex; | |
32323 | + struct path h_path; | |
32324 | + struct reinit_br_wh *a = arg; | |
32325 | + struct au_wbr *wbr; | |
523b37e3 | 32326 | + struct inode *dir, *delegated; |
1facf9fc | 32327 | + struct dentry *h_root; |
32328 | + struct au_hinode *hdir; | |
32329 | + | |
32330 | + err = 0; | |
32331 | + wbr = a->br->br_wbr; | |
32332 | + /* big aufs lock */ | |
32333 | + si_noflush_write_lock(a->sb); | |
32334 | + if (!au_br_writable(a->br->br_perm)) | |
32335 | + goto out; | |
32336 | + bindex = au_br_index(a->sb, a->br->br_id); | |
32337 | + if (unlikely(bindex < 0)) | |
32338 | + goto out; | |
32339 | + | |
1308ab2a | 32340 | + di_read_lock_parent(a->sb->s_root, AuLock_IR); |
5527c038 | 32341 | + dir = d_inode(a->sb->s_root); |
1facf9fc | 32342 | + hdir = au_hi(dir, bindex); |
32343 | + h_root = au_h_dptr(a->sb->s_root, bindex); | |
86dc4139 | 32344 | + AuDebugOn(h_root != au_br_dentry(a->br)); |
1facf9fc | 32345 | + |
4a4d8108 | 32346 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 32347 | + wbr_wh_write_lock(wbr); |
32348 | + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode, | |
32349 | + h_root, a->br); | |
32350 | + if (!err) { | |
86dc4139 AM |
32351 | + h_path.dentry = wbr->wbr_whbase; |
32352 | + h_path.mnt = au_br_mnt(a->br); | |
523b37e3 AM |
32353 | + delegated = NULL; |
32354 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, | |
32355 | + /*force*/0); | |
32356 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32357 | + pr_warn("cannot retry for NFSv4 delegation" | |
32358 | + " for an internal unlink\n"); | |
32359 | + iput(delegated); | |
32360 | + } | |
1facf9fc | 32361 | + } else { |
523b37e3 | 32362 | + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase); |
1facf9fc | 32363 | + err = 0; |
32364 | + } | |
32365 | + dput(wbr->wbr_whbase); | |
32366 | + wbr->wbr_whbase = NULL; | |
32367 | + if (!err) | |
86dc4139 | 32368 | + err = au_wh_init(a->br, a->sb); |
1facf9fc | 32369 | + wbr_wh_write_unlock(wbr); |
4a4d8108 | 32370 | + au_hn_imtx_unlock(hdir); |
1308ab2a | 32371 | + di_read_unlock(a->sb->s_root, AuLock_IR); |
076b876e AM |
32372 | + if (!err) |
32373 | + au_fhsm_wrote(a->sb, bindex, /*force*/0); | |
1facf9fc | 32374 | + |
4f0767ce | 32375 | +out: |
1facf9fc | 32376 | + if (wbr) |
32377 | + atomic_dec(&wbr->wbr_wh_running); | |
32378 | + atomic_dec(&a->br->br_count); | |
1facf9fc | 32379 | + si_write_unlock(a->sb); |
027c5e7a | 32380 | + au_nwt_done(&au_sbi(a->sb)->si_nowait); |
1facf9fc | 32381 | + kfree(arg); |
32382 | + if (unlikely(err)) | |
32383 | + AuIOErr("err %d\n", err); | |
32384 | +} | |
32385 | + | |
32386 | +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br) | |
32387 | +{ | |
32388 | + int do_dec, wkq_err; | |
32389 | + struct reinit_br_wh *arg; | |
32390 | + | |
32391 | + do_dec = 1; | |
32392 | + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1) | |
32393 | + goto out; | |
32394 | + | |
32395 | + /* ignore ENOMEM */ | |
32396 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
32397 | + if (arg) { | |
32398 | + /* | |
32399 | + * dec(wh_running), kfree(arg) and dec(br_count) | |
32400 | + * in reinit function | |
32401 | + */ | |
32402 | + arg->sb = sb; | |
32403 | + arg->br = br; | |
32404 | + atomic_inc(&br->br_count); | |
53392da6 | 32405 | + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0); |
1facf9fc | 32406 | + if (unlikely(wkq_err)) { |
32407 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
32408 | + atomic_dec(&br->br_count); | |
32409 | + kfree(arg); | |
32410 | + } | |
32411 | + do_dec = 0; | |
32412 | + } | |
32413 | + | |
4f0767ce | 32414 | +out: |
1facf9fc | 32415 | + if (do_dec) |
32416 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
32417 | +} | |
32418 | + | |
32419 | +/* ---------------------------------------------------------------------- */ | |
32420 | + | |
32421 | +/* | |
32422 | + * create the whiteout @wh. | |
32423 | + */ | |
32424 | +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex, | |
32425 | + struct dentry *wh) | |
32426 | +{ | |
32427 | + int err; | |
32428 | + struct path h_path = { | |
32429 | + .dentry = wh | |
32430 | + }; | |
32431 | + struct au_branch *br; | |
32432 | + struct au_wbr *wbr; | |
32433 | + struct dentry *h_parent; | |
523b37e3 | 32434 | + struct inode *h_dir, *delegated; |
1facf9fc | 32435 | + |
32436 | + h_parent = wh->d_parent; /* dir inode is locked */ | |
5527c038 | 32437 | + h_dir = d_inode(h_parent); |
1facf9fc | 32438 | + IMustLock(h_dir); |
32439 | + | |
32440 | + br = au_sbr(sb, bindex); | |
86dc4139 | 32441 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 32442 | + wbr = br->br_wbr; |
32443 | + wbr_wh_read_lock(wbr); | |
32444 | + if (wbr->wbr_whbase) { | |
523b37e3 AM |
32445 | + delegated = NULL; |
32446 | + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated); | |
32447 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32448 | + pr_warn("cannot retry for NFSv4 delegation" | |
32449 | + " for an internal link\n"); | |
32450 | + iput(delegated); | |
32451 | + } | |
1facf9fc | 32452 | + if (!err || err != -EMLINK) |
32453 | + goto out; | |
32454 | + | |
32455 | + /* link count full. re-initialize br_whbase. */ | |
32456 | + kick_reinit_br_wh(sb, br); | |
32457 | + } | |
32458 | + | |
32459 | + /* return this error in this context */ | |
b4510431 | 32460 | + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true); |
076b876e AM |
32461 | + if (!err) |
32462 | + au_fhsm_wrote(sb, bindex, /*force*/0); | |
1facf9fc | 32463 | + |
4f0767ce | 32464 | +out: |
1facf9fc | 32465 | + wbr_wh_read_unlock(wbr); |
32466 | + return err; | |
32467 | +} | |
32468 | + | |
32469 | +/* ---------------------------------------------------------------------- */ | |
32470 | + | |
32471 | +/* | |
32472 | + * create or remove the diropq. | |
32473 | + */ | |
32474 | +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex, | |
32475 | + unsigned int flags) | |
32476 | +{ | |
32477 | + struct dentry *opq_dentry, *h_dentry; | |
32478 | + struct super_block *sb; | |
32479 | + struct au_branch *br; | |
32480 | + int err; | |
32481 | + | |
32482 | + sb = dentry->d_sb; | |
32483 | + br = au_sbr(sb, bindex); | |
32484 | + h_dentry = au_h_dptr(dentry, bindex); | |
b4510431 | 32485 | + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry); |
1facf9fc | 32486 | + if (IS_ERR(opq_dentry)) |
32487 | + goto out; | |
32488 | + | |
32489 | + if (au_ftest_diropq(flags, CREATE)) { | |
32490 | + err = link_or_create_wh(sb, bindex, opq_dentry); | |
32491 | + if (!err) { | |
32492 | + au_set_dbdiropq(dentry, bindex); | |
32493 | + goto out; /* success */ | |
32494 | + } | |
32495 | + } else { | |
32496 | + struct path tmp = { | |
32497 | + .dentry = opq_dentry, | |
86dc4139 | 32498 | + .mnt = au_br_mnt(br) |
1facf9fc | 32499 | + }; |
5527c038 | 32500 | + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp); |
1facf9fc | 32501 | + if (!err) |
32502 | + au_set_dbdiropq(dentry, -1); | |
32503 | + } | |
32504 | + dput(opq_dentry); | |
32505 | + opq_dentry = ERR_PTR(err); | |
32506 | + | |
4f0767ce | 32507 | +out: |
1facf9fc | 32508 | + return opq_dentry; |
32509 | +} | |
32510 | + | |
32511 | +struct do_diropq_args { | |
32512 | + struct dentry **errp; | |
32513 | + struct dentry *dentry; | |
32514 | + aufs_bindex_t bindex; | |
32515 | + unsigned int flags; | |
32516 | +}; | |
32517 | + | |
32518 | +static void call_do_diropq(void *args) | |
32519 | +{ | |
32520 | + struct do_diropq_args *a = args; | |
32521 | + *a->errp = do_diropq(a->dentry, a->bindex, a->flags); | |
32522 | +} | |
32523 | + | |
32524 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
32525 | + unsigned int flags) | |
32526 | +{ | |
32527 | + struct dentry *diropq, *h_dentry; | |
32528 | + | |
32529 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 32530 | + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE)) |
1facf9fc | 32531 | + diropq = do_diropq(dentry, bindex, flags); |
32532 | + else { | |
32533 | + int wkq_err; | |
32534 | + struct do_diropq_args args = { | |
32535 | + .errp = &diropq, | |
32536 | + .dentry = dentry, | |
32537 | + .bindex = bindex, | |
32538 | + .flags = flags | |
32539 | + }; | |
32540 | + | |
32541 | + wkq_err = au_wkq_wait(call_do_diropq, &args); | |
32542 | + if (unlikely(wkq_err)) | |
32543 | + diropq = ERR_PTR(wkq_err); | |
32544 | + } | |
32545 | + | |
32546 | + return diropq; | |
32547 | +} | |
32548 | + | |
32549 | +/* ---------------------------------------------------------------------- */ | |
32550 | + | |
32551 | +/* | |
32552 | + * lookup whiteout dentry. | |
32553 | + * @h_parent: lower parent dentry which must exist and be locked | |
32554 | + * @base_name: name of dentry which will be whiteouted | |
32555 | + * returns dentry for whiteout. | |
32556 | + */ | |
32557 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
32558 | + struct au_branch *br) | |
32559 | +{ | |
32560 | + int err; | |
32561 | + struct qstr wh_name; | |
32562 | + struct dentry *wh_dentry; | |
32563 | + | |
32564 | + err = au_wh_name_alloc(&wh_name, base_name); | |
32565 | + wh_dentry = ERR_PTR(err); | |
32566 | + if (!err) { | |
b4510431 | 32567 | + wh_dentry = vfsub_lkup_one(&wh_name, h_parent); |
1facf9fc | 32568 | + kfree(wh_name.name); |
32569 | + } | |
32570 | + return wh_dentry; | |
32571 | +} | |
32572 | + | |
32573 | +/* | |
32574 | + * link/create a whiteout for @dentry on @bindex. | |
32575 | + */ | |
32576 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
32577 | + struct dentry *h_parent) | |
32578 | +{ | |
32579 | + struct dentry *wh_dentry; | |
32580 | + struct super_block *sb; | |
32581 | + int err; | |
32582 | + | |
32583 | + sb = dentry->d_sb; | |
32584 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex)); | |
5527c038 | 32585 | + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) { |
1facf9fc | 32586 | + err = link_or_create_wh(sb, bindex, wh_dentry); |
076b876e | 32587 | + if (!err) { |
1facf9fc | 32588 | + au_set_dbwh(dentry, bindex); |
076b876e AM |
32589 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
32590 | + } else { | |
1facf9fc | 32591 | + dput(wh_dentry); |
32592 | + wh_dentry = ERR_PTR(err); | |
32593 | + } | |
32594 | + } | |
32595 | + | |
32596 | + return wh_dentry; | |
32597 | +} | |
32598 | + | |
32599 | +/* ---------------------------------------------------------------------- */ | |
32600 | + | |
32601 | +/* Delete all whiteouts in this directory on branch bindex. */ | |
32602 | +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist, | |
32603 | + aufs_bindex_t bindex, struct au_branch *br) | |
32604 | +{ | |
32605 | + int err; | |
32606 | + unsigned long ul, n; | |
32607 | + struct qstr wh_name; | |
32608 | + char *p; | |
32609 | + struct hlist_head *head; | |
c06a8ce3 | 32610 | + struct au_vdir_wh *pos; |
1facf9fc | 32611 | + struct au_vdir_destr *str; |
32612 | + | |
32613 | + err = -ENOMEM; | |
537831f9 | 32614 | + p = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 32615 | + wh_name.name = p; |
32616 | + if (unlikely(!wh_name.name)) | |
32617 | + goto out; | |
32618 | + | |
32619 | + err = 0; | |
32620 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
32621 | + p += AUFS_WH_PFX_LEN; | |
32622 | + n = whlist->nh_num; | |
32623 | + head = whlist->nh_head; | |
32624 | + for (ul = 0; !err && ul < n; ul++, head++) { | |
c06a8ce3 AM |
32625 | + hlist_for_each_entry(pos, head, wh_hash) { |
32626 | + if (pos->wh_bindex != bindex) | |
1facf9fc | 32627 | + continue; |
32628 | + | |
c06a8ce3 | 32629 | + str = &pos->wh_str; |
1facf9fc | 32630 | + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) { |
32631 | + memcpy(p, str->name, str->len); | |
32632 | + wh_name.len = AUFS_WH_PFX_LEN + str->len; | |
32633 | + err = unlink_wh_name(h_dentry, &wh_name, br); | |
32634 | + if (!err) | |
32635 | + continue; | |
32636 | + break; | |
32637 | + } | |
32638 | + AuIOErr("whiteout name too long %.*s\n", | |
32639 | + str->len, str->name); | |
32640 | + err = -EIO; | |
32641 | + break; | |
32642 | + } | |
32643 | + } | |
537831f9 | 32644 | + free_page((unsigned long)wh_name.name); |
1facf9fc | 32645 | + |
4f0767ce | 32646 | +out: |
1facf9fc | 32647 | + return err; |
32648 | +} | |
32649 | + | |
32650 | +struct del_wh_children_args { | |
32651 | + int *errp; | |
32652 | + struct dentry *h_dentry; | |
1308ab2a | 32653 | + struct au_nhash *whlist; |
1facf9fc | 32654 | + aufs_bindex_t bindex; |
32655 | + struct au_branch *br; | |
32656 | +}; | |
32657 | + | |
32658 | +static void call_del_wh_children(void *args) | |
32659 | +{ | |
32660 | + struct del_wh_children_args *a = args; | |
1308ab2a | 32661 | + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br); |
1facf9fc | 32662 | +} |
32663 | + | |
32664 | +/* ---------------------------------------------------------------------- */ | |
32665 | + | |
32666 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp) | |
32667 | +{ | |
32668 | + struct au_whtmp_rmdir *whtmp; | |
dece6358 | 32669 | + int err; |
1308ab2a | 32670 | + unsigned int rdhash; |
dece6358 AM |
32671 | + |
32672 | + SiMustAnyLock(sb); | |
1facf9fc | 32673 | + |
32674 | + whtmp = kmalloc(sizeof(*whtmp), gfp); | |
dece6358 AM |
32675 | + if (unlikely(!whtmp)) { |
32676 | + whtmp = ERR_PTR(-ENOMEM); | |
1facf9fc | 32677 | + goto out; |
dece6358 | 32678 | + } |
1facf9fc | 32679 | + |
32680 | + whtmp->dir = NULL; | |
027c5e7a | 32681 | + whtmp->br = NULL; |
1facf9fc | 32682 | + whtmp->wh_dentry = NULL; |
1308ab2a | 32683 | + /* no estimation for dir size */ |
32684 | + rdhash = au_sbi(sb)->si_rdhash; | |
32685 | + if (!rdhash) | |
32686 | + rdhash = AUFS_RDHASH_DEF; | |
32687 | + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp); | |
32688 | + if (unlikely(err)) { | |
32689 | + kfree(whtmp); | |
32690 | + whtmp = ERR_PTR(err); | |
32691 | + } | |
dece6358 | 32692 | + |
4f0767ce | 32693 | +out: |
dece6358 | 32694 | + return whtmp; |
1facf9fc | 32695 | +} |
32696 | + | |
32697 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp) | |
32698 | +{ | |
027c5e7a AM |
32699 | + if (whtmp->br) |
32700 | + atomic_dec(&whtmp->br->br_count); | |
1facf9fc | 32701 | + dput(whtmp->wh_dentry); |
32702 | + iput(whtmp->dir); | |
dece6358 | 32703 | + au_nhash_wh_free(&whtmp->whlist); |
1facf9fc | 32704 | + kfree(whtmp); |
32705 | +} | |
32706 | + | |
32707 | +/* | |
32708 | + * rmdir the whiteouted temporary named dir @h_dentry. | |
32709 | + * @whlist: whiteouted children. | |
32710 | + */ | |
32711 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32712 | + struct dentry *wh_dentry, struct au_nhash *whlist) | |
32713 | +{ | |
32714 | + int err; | |
2000de60 | 32715 | + unsigned int h_nlink; |
1facf9fc | 32716 | + struct path h_tmp; |
32717 | + struct inode *wh_inode, *h_dir; | |
32718 | + struct au_branch *br; | |
32719 | + | |
5527c038 | 32720 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
1facf9fc | 32721 | + IMustLock(h_dir); |
32722 | + | |
32723 | + br = au_sbr(dir->i_sb, bindex); | |
5527c038 | 32724 | + wh_inode = d_inode(wh_dentry); |
1facf9fc | 32725 | + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD); |
32726 | + | |
32727 | + /* | |
32728 | + * someone else might change some whiteouts while we were sleeping. | |
32729 | + * it means this whlist may have an obsoleted entry. | |
32730 | + */ | |
32731 | + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE)) | |
32732 | + err = del_wh_children(wh_dentry, whlist, bindex, br); | |
32733 | + else { | |
32734 | + int wkq_err; | |
32735 | + struct del_wh_children_args args = { | |
32736 | + .errp = &err, | |
32737 | + .h_dentry = wh_dentry, | |
1308ab2a | 32738 | + .whlist = whlist, |
1facf9fc | 32739 | + .bindex = bindex, |
32740 | + .br = br | |
32741 | + }; | |
32742 | + | |
32743 | + wkq_err = au_wkq_wait(call_del_wh_children, &args); | |
32744 | + if (unlikely(wkq_err)) | |
32745 | + err = wkq_err; | |
32746 | + } | |
32747 | + mutex_unlock(&wh_inode->i_mutex); | |
32748 | + | |
32749 | + if (!err) { | |
32750 | + h_tmp.dentry = wh_dentry; | |
86dc4139 | 32751 | + h_tmp.mnt = au_br_mnt(br); |
2000de60 | 32752 | + h_nlink = h_dir->i_nlink; |
1facf9fc | 32753 | + err = vfsub_rmdir(h_dir, &h_tmp); |
2000de60 JR |
32754 | + /* some fs doesn't change the parent nlink in some cases */ |
32755 | + h_nlink -= h_dir->i_nlink; | |
1facf9fc | 32756 | + } |
32757 | + | |
32758 | + if (!err) { | |
32759 | + if (au_ibstart(dir) == bindex) { | |
7f207e10 | 32760 | + /* todo: dir->i_mutex is necessary */ |
1facf9fc | 32761 | + au_cpup_attr_timesizes(dir); |
2000de60 JR |
32762 | + if (h_nlink) |
32763 | + vfsub_drop_nlink(dir); | |
1facf9fc | 32764 | + } |
32765 | + return 0; /* success */ | |
32766 | + } | |
32767 | + | |
523b37e3 | 32768 | + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err); |
1facf9fc | 32769 | + return err; |
32770 | +} | |
32771 | + | |
32772 | +static void call_rmdir_whtmp(void *args) | |
32773 | +{ | |
32774 | + int err; | |
e49829fe | 32775 | + aufs_bindex_t bindex; |
1facf9fc | 32776 | + struct au_whtmp_rmdir *a = args; |
32777 | + struct super_block *sb; | |
32778 | + struct dentry *h_parent; | |
32779 | + struct inode *h_dir; | |
1facf9fc | 32780 | + struct au_hinode *hdir; |
32781 | + | |
32782 | + /* rmdir by nfsd may cause deadlock with this i_mutex */ | |
32783 | + /* mutex_lock(&a->dir->i_mutex); */ | |
e49829fe | 32784 | + err = -EROFS; |
1facf9fc | 32785 | + sb = a->dir->i_sb; |
e49829fe JR |
32786 | + si_read_lock(sb, !AuLock_FLUSH); |
32787 | + if (!au_br_writable(a->br->br_perm)) | |
32788 | + goto out; | |
32789 | + bindex = au_br_index(sb, a->br->br_id); | |
32790 | + if (unlikely(bindex < 0)) | |
1facf9fc | 32791 | + goto out; |
32792 | + | |
32793 | + err = -EIO; | |
1facf9fc | 32794 | + ii_write_lock_parent(a->dir); |
32795 | + h_parent = dget_parent(a->wh_dentry); | |
5527c038 | 32796 | + h_dir = d_inode(h_parent); |
e49829fe | 32797 | + hdir = au_hi(a->dir, bindex); |
86dc4139 AM |
32798 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); |
32799 | + if (unlikely(err)) | |
32800 | + goto out_mnt; | |
4a4d8108 | 32801 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
e49829fe JR |
32802 | + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent, |
32803 | + a->br); | |
86dc4139 AM |
32804 | + if (!err) |
32805 | + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist); | |
4a4d8108 | 32806 | + au_hn_imtx_unlock(hdir); |
86dc4139 AM |
32807 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
32808 | + | |
32809 | +out_mnt: | |
1facf9fc | 32810 | + dput(h_parent); |
32811 | + ii_write_unlock(a->dir); | |
4f0767ce | 32812 | +out: |
1facf9fc | 32813 | + /* mutex_unlock(&a->dir->i_mutex); */ |
1facf9fc | 32814 | + au_whtmp_rmdir_free(a); |
027c5e7a AM |
32815 | + si_read_unlock(sb); |
32816 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
1facf9fc | 32817 | + if (unlikely(err)) |
32818 | + AuIOErr("err %d\n", err); | |
32819 | +} | |
32820 | + | |
32821 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32822 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args) | |
32823 | +{ | |
32824 | + int wkq_err; | |
e49829fe | 32825 | + struct super_block *sb; |
1facf9fc | 32826 | + |
32827 | + IMustLock(dir); | |
32828 | + | |
32829 | + /* all post-process will be done in do_rmdir_whtmp(). */ | |
e49829fe | 32830 | + sb = dir->i_sb; |
1facf9fc | 32831 | + args->dir = au_igrab(dir); |
e49829fe JR |
32832 | + args->br = au_sbr(sb, bindex); |
32833 | + atomic_inc(&args->br->br_count); | |
1facf9fc | 32834 | + args->wh_dentry = dget(wh_dentry); |
53392da6 | 32835 | + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0); |
1facf9fc | 32836 | + if (unlikely(wkq_err)) { |
523b37e3 | 32837 | + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err); |
1facf9fc | 32838 | + au_whtmp_rmdir_free(args); |
32839 | + } | |
32840 | +} | |
7f207e10 AM |
32841 | diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h |
32842 | --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 32843 | +++ linux/fs/aufs/whout.h 2015-06-28 17:35:44.351383872 +0200 |
076b876e | 32844 | @@ -0,0 +1,85 @@ |
1facf9fc | 32845 | +/* |
2000de60 | 32846 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 32847 | + * |
32848 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32849 | + * it under the terms of the GNU General Public License as published by | |
32850 | + * the Free Software Foundation; either version 2 of the License, or | |
32851 | + * (at your option) any later version. | |
dece6358 AM |
32852 | + * |
32853 | + * This program is distributed in the hope that it will be useful, | |
32854 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32855 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32856 | + * GNU General Public License for more details. | |
32857 | + * | |
32858 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32859 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32860 | + */ |
32861 | + | |
32862 | +/* | |
32863 | + * whiteout for logical deletion and opaque directory | |
32864 | + */ | |
32865 | + | |
32866 | +#ifndef __AUFS_WHOUT_H__ | |
32867 | +#define __AUFS_WHOUT_H__ | |
32868 | + | |
32869 | +#ifdef __KERNEL__ | |
32870 | + | |
1facf9fc | 32871 | +#include "dir.h" |
32872 | + | |
32873 | +/* whout.c */ | |
32874 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name); | |
076b876e AM |
32875 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio); |
32876 | +int au_diropq_test(struct dentry *h_dentry); | |
7e9cd9fe | 32877 | +struct au_branch; |
1facf9fc | 32878 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, |
32879 | + struct qstr *prefix); | |
32880 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br); | |
32881 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
32882 | + struct dentry *dentry); | |
86dc4139 | 32883 | +int au_wh_init(struct au_branch *br, struct super_block *sb); |
1facf9fc | 32884 | + |
32885 | +/* diropq flags */ | |
32886 | +#define AuDiropq_CREATE 1 | |
32887 | +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name) | |
7f207e10 AM |
32888 | +#define au_fset_diropq(flags, name) \ |
32889 | + do { (flags) |= AuDiropq_##name; } while (0) | |
32890 | +#define au_fclr_diropq(flags, name) \ | |
32891 | + do { (flags) &= ~AuDiropq_##name; } while (0) | |
1facf9fc | 32892 | + |
32893 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
32894 | + unsigned int flags); | |
32895 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
32896 | + struct au_branch *br); | |
32897 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
32898 | + struct dentry *h_parent); | |
32899 | + | |
32900 | +/* real rmdir for the whiteout-ed dir */ | |
32901 | +struct au_whtmp_rmdir { | |
32902 | + struct inode *dir; | |
e49829fe | 32903 | + struct au_branch *br; |
1facf9fc | 32904 | + struct dentry *wh_dentry; |
dece6358 | 32905 | + struct au_nhash whlist; |
1facf9fc | 32906 | +}; |
32907 | + | |
32908 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp); | |
32909 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp); | |
32910 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32911 | + struct dentry *wh_dentry, struct au_nhash *whlist); | |
32912 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32913 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args); | |
32914 | + | |
32915 | +/* ---------------------------------------------------------------------- */ | |
32916 | + | |
32917 | +static inline struct dentry *au_diropq_create(struct dentry *dentry, | |
32918 | + aufs_bindex_t bindex) | |
32919 | +{ | |
32920 | + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE); | |
32921 | +} | |
32922 | + | |
32923 | +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex) | |
32924 | +{ | |
32925 | + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE)); | |
32926 | +} | |
32927 | + | |
32928 | +#endif /* __KERNEL__ */ | |
32929 | +#endif /* __AUFS_WHOUT_H__ */ | |
7f207e10 AM |
32930 | diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c |
32931 | --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 32932 | +++ linux/fs/aufs/wkq.c 2015-06-28 17:35:44.351383872 +0200 |
38d290e6 | 32933 | @@ -0,0 +1,213 @@ |
1facf9fc | 32934 | +/* |
2000de60 | 32935 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 32936 | + * |
32937 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32938 | + * it under the terms of the GNU General Public License as published by | |
32939 | + * the Free Software Foundation; either version 2 of the License, or | |
32940 | + * (at your option) any later version. | |
dece6358 AM |
32941 | + * |
32942 | + * This program is distributed in the hope that it will be useful, | |
32943 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32944 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32945 | + * GNU General Public License for more details. | |
32946 | + * | |
32947 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32948 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32949 | + */ |
32950 | + | |
32951 | +/* | |
32952 | + * workqueue for asynchronous/super-io operations | |
32953 | + * todo: try new dredential scheme | |
32954 | + */ | |
32955 | + | |
dece6358 | 32956 | +#include <linux/module.h> |
1facf9fc | 32957 | +#include "aufs.h" |
32958 | + | |
9dbd164d | 32959 | +/* internal workqueue named AUFS_WKQ_NAME */ |
b752ccd1 | 32960 | + |
9dbd164d | 32961 | +static struct workqueue_struct *au_wkq; |
1facf9fc | 32962 | + |
32963 | +struct au_wkinfo { | |
32964 | + struct work_struct wk; | |
7f207e10 | 32965 | + struct kobject *kobj; |
1facf9fc | 32966 | + |
32967 | + unsigned int flags; /* see wkq.h */ | |
32968 | + | |
32969 | + au_wkq_func_t func; | |
32970 | + void *args; | |
32971 | + | |
1facf9fc | 32972 | + struct completion *comp; |
32973 | +}; | |
32974 | + | |
32975 | +/* ---------------------------------------------------------------------- */ | |
32976 | + | |
1facf9fc | 32977 | +static void wkq_func(struct work_struct *wk) |
32978 | +{ | |
32979 | + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk); | |
32980 | + | |
2dfbb274 | 32981 | + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)); |
7f207e10 AM |
32982 | + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY); |
32983 | + | |
1facf9fc | 32984 | + wkinfo->func(wkinfo->args); |
1facf9fc | 32985 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) |
32986 | + complete(wkinfo->comp); | |
32987 | + else { | |
7f207e10 | 32988 | + kobject_put(wkinfo->kobj); |
9dbd164d | 32989 | + module_put(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 32990 | + kfree(wkinfo); |
32991 | + } | |
32992 | +} | |
32993 | + | |
32994 | +/* | |
32995 | + * Since struct completion is large, try allocating it dynamically. | |
32996 | + */ | |
c2b27bf2 | 32997 | +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */ |
1facf9fc | 32998 | +#define AuWkqCompDeclare(name) struct completion *comp = NULL |
32999 | + | |
33000 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
33001 | +{ | |
33002 | + *comp = kmalloc(sizeof(**comp), GFP_NOFS); | |
33003 | + if (*comp) { | |
33004 | + init_completion(*comp); | |
33005 | + wkinfo->comp = *comp; | |
33006 | + return 0; | |
33007 | + } | |
33008 | + return -ENOMEM; | |
33009 | +} | |
33010 | + | |
33011 | +static void au_wkq_comp_free(struct completion *comp) | |
33012 | +{ | |
33013 | + kfree(comp); | |
33014 | +} | |
33015 | + | |
33016 | +#else | |
33017 | + | |
33018 | +/* no braces */ | |
33019 | +#define AuWkqCompDeclare(name) \ | |
33020 | + DECLARE_COMPLETION_ONSTACK(_ ## name); \ | |
33021 | + struct completion *comp = &_ ## name | |
33022 | + | |
33023 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
33024 | +{ | |
33025 | + wkinfo->comp = *comp; | |
33026 | + return 0; | |
33027 | +} | |
33028 | + | |
33029 | +static void au_wkq_comp_free(struct completion *comp __maybe_unused) | |
33030 | +{ | |
33031 | + /* empty */ | |
33032 | +} | |
33033 | +#endif /* 4KSTACKS */ | |
33034 | + | |
53392da6 | 33035 | +static void au_wkq_run(struct au_wkinfo *wkinfo) |
1facf9fc | 33036 | +{ |
53392da6 AM |
33037 | + if (au_ftest_wkq(wkinfo->flags, NEST)) { |
33038 | + if (au_wkq_test()) { | |
38d290e6 JR |
33039 | + AuWarn1("wkq from wkq, unless silly-rename on NFS," |
33040 | + " due to a dead dir by UDBA?\n"); | |
53392da6 AM |
33041 | + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT)); |
33042 | + } | |
33043 | + } else | |
33044 | + au_dbg_verify_kthread(); | |
33045 | + | |
33046 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) { | |
a1f66529 | 33047 | + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func); |
9dbd164d | 33048 | + queue_work(au_wkq, &wkinfo->wk); |
4a4d8108 AM |
33049 | + } else { |
33050 | + INIT_WORK(&wkinfo->wk, wkq_func); | |
33051 | + schedule_work(&wkinfo->wk); | |
33052 | + } | |
1facf9fc | 33053 | +} |
33054 | + | |
7f207e10 AM |
33055 | +/* |
33056 | + * Be careful. It is easy to make deadlock happen. | |
33057 | + * processA: lock, wkq and wait | |
33058 | + * processB: wkq and wait, lock in wkq | |
33059 | + * --> deadlock | |
33060 | + */ | |
b752ccd1 | 33061 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args) |
1facf9fc | 33062 | +{ |
33063 | + int err; | |
33064 | + AuWkqCompDeclare(comp); | |
33065 | + struct au_wkinfo wkinfo = { | |
b752ccd1 | 33066 | + .flags = flags, |
1facf9fc | 33067 | + .func = func, |
33068 | + .args = args | |
33069 | + }; | |
33070 | + | |
33071 | + err = au_wkq_comp_alloc(&wkinfo, &comp); | |
33072 | + if (!err) { | |
53392da6 | 33073 | + au_wkq_run(&wkinfo); |
1facf9fc | 33074 | + /* no timeout, no interrupt */ |
33075 | + wait_for_completion(wkinfo.comp); | |
33076 | + au_wkq_comp_free(comp); | |
4a4d8108 | 33077 | + destroy_work_on_stack(&wkinfo.wk); |
1facf9fc | 33078 | + } |
33079 | + | |
33080 | + return err; | |
33081 | + | |
33082 | +} | |
33083 | + | |
027c5e7a AM |
33084 | +/* |
33085 | + * Note: dget/dput() in func for aufs dentries are not supported. It will be a | |
33086 | + * problem in a concurrent umounting. | |
33087 | + */ | |
53392da6 AM |
33088 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
33089 | + unsigned int flags) | |
1facf9fc | 33090 | +{ |
33091 | + int err; | |
33092 | + struct au_wkinfo *wkinfo; | |
33093 | + | |
33094 | + atomic_inc(&au_sbi(sb)->si_nowait.nw_len); | |
33095 | + | |
33096 | + /* | |
33097 | + * wkq_func() must free this wkinfo. | |
33098 | + * it highly depends upon the implementation of workqueue. | |
33099 | + */ | |
33100 | + err = 0; | |
33101 | + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS); | |
33102 | + if (wkinfo) { | |
7f207e10 | 33103 | + wkinfo->kobj = &au_sbi(sb)->si_kobj; |
53392da6 | 33104 | + wkinfo->flags = flags & ~AuWkq_WAIT; |
1facf9fc | 33105 | + wkinfo->func = func; |
33106 | + wkinfo->args = args; | |
33107 | + wkinfo->comp = NULL; | |
7f207e10 | 33108 | + kobject_get(wkinfo->kobj); |
9dbd164d | 33109 | + __module_get(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 33110 | + |
53392da6 | 33111 | + au_wkq_run(wkinfo); |
1facf9fc | 33112 | + } else { |
33113 | + err = -ENOMEM; | |
e49829fe | 33114 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 33115 | + } |
33116 | + | |
33117 | + return err; | |
33118 | +} | |
33119 | + | |
33120 | +/* ---------------------------------------------------------------------- */ | |
33121 | + | |
33122 | +void au_nwt_init(struct au_nowait_tasks *nwt) | |
33123 | +{ | |
33124 | + atomic_set(&nwt->nw_len, 0); | |
4a4d8108 | 33125 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 33126 | + init_waitqueue_head(&nwt->nw_wq); |
33127 | +} | |
33128 | + | |
33129 | +void au_wkq_fin(void) | |
33130 | +{ | |
9dbd164d | 33131 | + destroy_workqueue(au_wkq); |
1facf9fc | 33132 | +} |
33133 | + | |
33134 | +int __init au_wkq_init(void) | |
33135 | +{ | |
9dbd164d | 33136 | + int err; |
b752ccd1 AM |
33137 | + |
33138 | + err = 0; | |
86dc4139 | 33139 | + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE); |
9dbd164d AM |
33140 | + if (IS_ERR(au_wkq)) |
33141 | + err = PTR_ERR(au_wkq); | |
33142 | + else if (!au_wkq) | |
33143 | + err = -ENOMEM; | |
b752ccd1 AM |
33144 | + |
33145 | + return err; | |
1facf9fc | 33146 | +} |
7f207e10 AM |
33147 | diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h |
33148 | --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 33149 | +++ linux/fs/aufs/wkq.h 2015-06-28 17:35:44.351383872 +0200 |
523b37e3 | 33150 | @@ -0,0 +1,91 @@ |
1facf9fc | 33151 | +/* |
2000de60 | 33152 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 33153 | + * |
33154 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33155 | + * it under the terms of the GNU General Public License as published by | |
33156 | + * the Free Software Foundation; either version 2 of the License, or | |
33157 | + * (at your option) any later version. | |
dece6358 AM |
33158 | + * |
33159 | + * This program is distributed in the hope that it will be useful, | |
33160 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33161 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33162 | + * GNU General Public License for more details. | |
33163 | + * | |
33164 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33165 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33166 | + */ |
33167 | + | |
33168 | +/* | |
33169 | + * workqueue for asynchronous/super-io operations | |
33170 | + * todo: try new credentials management scheme | |
33171 | + */ | |
33172 | + | |
33173 | +#ifndef __AUFS_WKQ_H__ | |
33174 | +#define __AUFS_WKQ_H__ | |
33175 | + | |
33176 | +#ifdef __KERNEL__ | |
33177 | + | |
dece6358 AM |
33178 | +struct super_block; |
33179 | + | |
1facf9fc | 33180 | +/* ---------------------------------------------------------------------- */ |
33181 | + | |
33182 | +/* | |
33183 | + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue | |
33184 | + */ | |
33185 | +struct au_nowait_tasks { | |
33186 | + atomic_t nw_len; | |
33187 | + wait_queue_head_t nw_wq; | |
33188 | +}; | |
33189 | + | |
33190 | +/* ---------------------------------------------------------------------- */ | |
33191 | + | |
33192 | +typedef void (*au_wkq_func_t)(void *args); | |
33193 | + | |
33194 | +/* wkq flags */ | |
33195 | +#define AuWkq_WAIT 1 | |
9dbd164d | 33196 | +#define AuWkq_NEST (1 << 1) |
1facf9fc | 33197 | +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name) |
7f207e10 AM |
33198 | +#define au_fset_wkq(flags, name) \ |
33199 | + do { (flags) |= AuWkq_##name; } while (0) | |
33200 | +#define au_fclr_wkq(flags, name) \ | |
33201 | + do { (flags) &= ~AuWkq_##name; } while (0) | |
1facf9fc | 33202 | + |
9dbd164d AM |
33203 | +#ifndef CONFIG_AUFS_HNOTIFY |
33204 | +#undef AuWkq_NEST | |
33205 | +#define AuWkq_NEST 0 | |
33206 | +#endif | |
33207 | + | |
1facf9fc | 33208 | +/* wkq.c */ |
b752ccd1 | 33209 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args); |
53392da6 AM |
33210 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
33211 | + unsigned int flags); | |
1facf9fc | 33212 | +void au_nwt_init(struct au_nowait_tasks *nwt); |
33213 | +int __init au_wkq_init(void); | |
33214 | +void au_wkq_fin(void); | |
33215 | + | |
33216 | +/* ---------------------------------------------------------------------- */ | |
33217 | + | |
53392da6 AM |
33218 | +static inline int au_wkq_test(void) |
33219 | +{ | |
33220 | + return current->flags & PF_WQ_WORKER; | |
33221 | +} | |
33222 | + | |
b752ccd1 | 33223 | +static inline int au_wkq_wait(au_wkq_func_t func, void *args) |
1facf9fc | 33224 | +{ |
b752ccd1 | 33225 | + return au_wkq_do_wait(AuWkq_WAIT, func, args); |
1facf9fc | 33226 | +} |
33227 | + | |
33228 | +static inline void au_nwt_done(struct au_nowait_tasks *nwt) | |
33229 | +{ | |
e49829fe | 33230 | + if (atomic_dec_and_test(&nwt->nw_len)) |
1facf9fc | 33231 | + wake_up_all(&nwt->nw_wq); |
33232 | +} | |
33233 | + | |
33234 | +static inline int au_nwt_flush(struct au_nowait_tasks *nwt) | |
33235 | +{ | |
33236 | + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len)); | |
33237 | + return 0; | |
33238 | +} | |
33239 | + | |
33240 | +#endif /* __KERNEL__ */ | |
33241 | +#endif /* __AUFS_WKQ_H__ */ | |
c1595e42 JR |
33242 | diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c |
33243 | --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 33244 | +++ linux/fs/aufs/xattr.c 2015-06-28 17:36:09.028407078 +0200 |
b912730e | 33245 | @@ -0,0 +1,344 @@ |
c1595e42 | 33246 | +/* |
2000de60 | 33247 | + * Copyright (C) 2014-2015 Junjiro R. Okajima |
c1595e42 JR |
33248 | + * |
33249 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33250 | + * it under the terms of the GNU General Public License as published by | |
33251 | + * the Free Software Foundation; either version 2 of the License, or | |
33252 | + * (at your option) any later version. | |
33253 | + * | |
33254 | + * This program is distributed in the hope that it will be useful, | |
33255 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33256 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33257 | + * GNU General Public License for more details. | |
33258 | + * | |
33259 | + * You should have received a copy of the GNU General Public License | |
33260 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
33261 | + */ | |
33262 | + | |
33263 | +/* | |
33264 | + * handling xattr functions | |
33265 | + */ | |
33266 | + | |
33267 | +#include <linux/xattr.h> | |
33268 | +#include "aufs.h" | |
33269 | + | |
33270 | +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags) | |
33271 | +{ | |
33272 | + if (!ignore_flags) | |
33273 | + goto out; | |
33274 | + switch (err) { | |
33275 | + case -ENOMEM: | |
33276 | + case -EDQUOT: | |
33277 | + goto out; | |
33278 | + } | |
33279 | + | |
33280 | + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) { | |
33281 | + err = 0; | |
33282 | + goto out; | |
33283 | + } | |
33284 | + | |
33285 | +#define cmp(brattr, prefix) do { \ | |
33286 | + if (!strncmp(name, XATTR_##prefix##_PREFIX, \ | |
33287 | + XATTR_##prefix##_PREFIX_LEN)) { \ | |
33288 | + if (ignore_flags & AuBrAttr_ICEX_##brattr) \ | |
33289 | + err = 0; \ | |
33290 | + goto out; \ | |
33291 | + } \ | |
33292 | + } while (0) | |
33293 | + | |
33294 | + cmp(SEC, SECURITY); | |
33295 | + cmp(SYS, SYSTEM); | |
33296 | + cmp(TR, TRUSTED); | |
33297 | + cmp(USR, USER); | |
33298 | +#undef cmp | |
33299 | + | |
33300 | + if (ignore_flags & AuBrAttr_ICEX_OTH) | |
33301 | + err = 0; | |
33302 | + | |
33303 | +out: | |
33304 | + return err; | |
33305 | +} | |
33306 | + | |
33307 | +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1; | |
33308 | + | |
33309 | +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe AM |
33310 | + char *name, char **buf, unsigned int ignore_flags, |
33311 | + unsigned int verbose) | |
c1595e42 JR |
33312 | +{ |
33313 | + int err; | |
33314 | + ssize_t ssz; | |
33315 | + struct inode *h_idst; | |
33316 | + | |
33317 | + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS); | |
33318 | + err = ssz; | |
33319 | + if (unlikely(err <= 0)) { | |
c1595e42 JR |
33320 | + if (err == -ENODATA |
33321 | + || (err == -EOPNOTSUPP | |
b912730e | 33322 | + && ((ignore_flags & au_xattr_out_of_list) |
5527c038 | 33323 | + || (au_test_nfs_noacl(d_inode(h_src)) |
b912730e AM |
33324 | + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) |
33325 | + || !strcmp(name, | |
33326 | + XATTR_NAME_POSIX_ACL_DEFAULT)))) | |
33327 | + )) | |
c1595e42 | 33328 | + err = 0; |
b912730e AM |
33329 | + if (err && (verbose || au_debug_test())) |
33330 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
33331 | + goto out; |
33332 | + } | |
33333 | + | |
33334 | + /* unlock it temporary */ | |
5527c038 | 33335 | + h_idst = d_inode(h_dst); |
c1595e42 JR |
33336 | + mutex_unlock(&h_idst->i_mutex); |
33337 | + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0); | |
33338 | + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2); | |
33339 | + if (unlikely(err)) { | |
7e9cd9fe AM |
33340 | + if (verbose || au_debug_test()) |
33341 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
33342 | + err = au_xattr_ignore(err, name, ignore_flags); |
33343 | + } | |
33344 | + | |
33345 | +out: | |
33346 | + return err; | |
33347 | +} | |
33348 | + | |
7e9cd9fe AM |
33349 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
33350 | + unsigned int verbose) | |
c1595e42 JR |
33351 | +{ |
33352 | + int err, unlocked, acl_access, acl_default; | |
33353 | + ssize_t ssz; | |
33354 | + struct inode *h_isrc, *h_idst; | |
33355 | + char *value, *p, *o, *e; | |
33356 | + | |
33357 | + /* try stopping to update the source inode while we are referencing */ | |
7e9cd9fe | 33358 | + /* there should not be the parent-child relationship between them */ |
5527c038 JR |
33359 | + h_isrc = d_inode(h_src); |
33360 | + h_idst = d_inode(h_dst); | |
c1595e42 JR |
33361 | + mutex_unlock(&h_idst->i_mutex); |
33362 | + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD); | |
33363 | + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2); | |
33364 | + unlocked = 0; | |
33365 | + | |
33366 | + /* some filesystems don't list POSIX ACL, for example tmpfs */ | |
33367 | + ssz = vfs_listxattr(h_src, NULL, 0); | |
33368 | + err = ssz; | |
33369 | + if (unlikely(err < 0)) { | |
33370 | + AuTraceErr(err); | |
33371 | + if (err == -ENODATA | |
33372 | + || err == -EOPNOTSUPP) | |
33373 | + err = 0; /* ignore */ | |
33374 | + goto out; | |
33375 | + } | |
33376 | + | |
33377 | + err = 0; | |
33378 | + p = NULL; | |
33379 | + o = NULL; | |
33380 | + if (ssz) { | |
33381 | + err = -ENOMEM; | |
33382 | + p = kmalloc(ssz, GFP_NOFS); | |
33383 | + o = p; | |
33384 | + if (unlikely(!p)) | |
33385 | + goto out; | |
33386 | + err = vfs_listxattr(h_src, p, ssz); | |
33387 | + } | |
33388 | + mutex_unlock(&h_isrc->i_mutex); | |
33389 | + unlocked = 1; | |
33390 | + AuDbg("err %d, ssz %zd\n", err, ssz); | |
33391 | + if (unlikely(err < 0)) | |
33392 | + goto out_free; | |
33393 | + | |
33394 | + err = 0; | |
33395 | + e = p + ssz; | |
33396 | + value = NULL; | |
33397 | + acl_access = 0; | |
33398 | + acl_default = 0; | |
33399 | + while (!err && p < e) { | |
33400 | + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS, | |
33401 | + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1); | |
33402 | + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT, | |
33403 | + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) | |
33404 | + - 1); | |
7e9cd9fe AM |
33405 | + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags, |
33406 | + verbose); | |
c1595e42 JR |
33407 | + p += strlen(p) + 1; |
33408 | + } | |
33409 | + AuTraceErr(err); | |
33410 | + ignore_flags |= au_xattr_out_of_list; | |
33411 | + if (!err && !acl_access) { | |
33412 | + err = au_do_cpup_xattr(h_dst, h_src, | |
33413 | + XATTR_NAME_POSIX_ACL_ACCESS, &value, | |
7e9cd9fe | 33414 | + ignore_flags, verbose); |
c1595e42 JR |
33415 | + AuTraceErr(err); |
33416 | + } | |
33417 | + if (!err && !acl_default) { | |
33418 | + err = au_do_cpup_xattr(h_dst, h_src, | |
33419 | + XATTR_NAME_POSIX_ACL_DEFAULT, &value, | |
7e9cd9fe | 33420 | + ignore_flags, verbose); |
c1595e42 JR |
33421 | + AuTraceErr(err); |
33422 | + } | |
33423 | + | |
33424 | + kfree(value); | |
33425 | + | |
33426 | +out_free: | |
33427 | + kfree(o); | |
33428 | +out: | |
33429 | + if (!unlocked) | |
33430 | + mutex_unlock(&h_isrc->i_mutex); | |
33431 | + AuTraceErr(err); | |
33432 | + return err; | |
33433 | +} | |
33434 | + | |
33435 | +/* ---------------------------------------------------------------------- */ | |
33436 | + | |
33437 | +enum { | |
33438 | + AU_XATTR_LIST, | |
33439 | + AU_XATTR_GET | |
33440 | +}; | |
33441 | + | |
33442 | +struct au_lgxattr { | |
33443 | + int type; | |
33444 | + union { | |
33445 | + struct { | |
33446 | + char *list; | |
33447 | + size_t size; | |
33448 | + } list; | |
33449 | + struct { | |
33450 | + const char *name; | |
33451 | + void *value; | |
33452 | + size_t size; | |
33453 | + } get; | |
33454 | + } u; | |
33455 | +}; | |
33456 | + | |
33457 | +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg) | |
33458 | +{ | |
33459 | + ssize_t err; | |
33460 | + struct path h_path; | |
33461 | + struct super_block *sb; | |
33462 | + | |
33463 | + sb = dentry->d_sb; | |
33464 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
33465 | + if (unlikely(err)) | |
33466 | + goto out; | |
33467 | + err = au_h_path_getattr(dentry, /*force*/1, &h_path); | |
33468 | + if (unlikely(err)) | |
33469 | + goto out_si; | |
33470 | + if (unlikely(!h_path.dentry)) | |
33471 | + /* illegally overlapped or something */ | |
33472 | + goto out_di; /* pretending success */ | |
33473 | + | |
33474 | + /* always topmost entry only */ | |
33475 | + switch (arg->type) { | |
33476 | + case AU_XATTR_LIST: | |
33477 | + err = vfs_listxattr(h_path.dentry, | |
33478 | + arg->u.list.list, arg->u.list.size); | |
33479 | + break; | |
33480 | + case AU_XATTR_GET: | |
33481 | + err = vfs_getxattr(h_path.dentry, | |
33482 | + arg->u.get.name, arg->u.get.value, | |
33483 | + arg->u.get.size); | |
33484 | + break; | |
33485 | + } | |
33486 | + | |
33487 | +out_di: | |
33488 | + di_read_unlock(dentry, AuLock_IR); | |
33489 | +out_si: | |
33490 | + si_read_unlock(sb); | |
33491 | +out: | |
33492 | + AuTraceErr(err); | |
33493 | + return err; | |
33494 | +} | |
33495 | + | |
33496 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size) | |
33497 | +{ | |
33498 | + struct au_lgxattr arg = { | |
33499 | + .type = AU_XATTR_LIST, | |
33500 | + .u.list = { | |
33501 | + .list = list, | |
33502 | + .size = size | |
33503 | + }, | |
33504 | + }; | |
33505 | + | |
33506 | + return au_lgxattr(dentry, &arg); | |
33507 | +} | |
33508 | + | |
33509 | +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value, | |
33510 | + size_t size) | |
33511 | +{ | |
33512 | + struct au_lgxattr arg = { | |
33513 | + .type = AU_XATTR_GET, | |
33514 | + .u.get = { | |
33515 | + .name = name, | |
33516 | + .value = value, | |
33517 | + .size = size | |
33518 | + }, | |
33519 | + }; | |
33520 | + | |
33521 | + return au_lgxattr(dentry, &arg); | |
33522 | +} | |
33523 | + | |
33524 | +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value, | |
33525 | + size_t size, int flags) | |
33526 | +{ | |
33527 | + struct au_srxattr arg = { | |
33528 | + .type = AU_XATTR_SET, | |
33529 | + .u.set = { | |
33530 | + .name = name, | |
33531 | + .value = value, | |
33532 | + .size = size, | |
33533 | + .flags = flags | |
33534 | + }, | |
33535 | + }; | |
33536 | + | |
33537 | + return au_srxattr(dentry, &arg); | |
33538 | +} | |
33539 | + | |
33540 | +int aufs_removexattr(struct dentry *dentry, const char *name) | |
33541 | +{ | |
33542 | + struct au_srxattr arg = { | |
33543 | + .type = AU_XATTR_REMOVE, | |
33544 | + .u.remove = { | |
33545 | + .name = name | |
33546 | + }, | |
33547 | + }; | |
33548 | + | |
33549 | + return au_srxattr(dentry, &arg); | |
33550 | +} | |
33551 | + | |
33552 | +/* ---------------------------------------------------------------------- */ | |
33553 | + | |
33554 | +#if 0 | |
33555 | +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size, | |
33556 | + const char *name, size_t name_len, int type) | |
33557 | +{ | |
33558 | + return aufs_listxattr(dentry, list, list_size); | |
33559 | +} | |
33560 | + | |
33561 | +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer, | |
33562 | + size_t size, int type) | |
33563 | +{ | |
33564 | + return aufs_getxattr(dentry, name, buffer, size); | |
33565 | +} | |
33566 | + | |
33567 | +static int au_xattr_set(struct dentry *dentry, const char *name, | |
33568 | + const void *value, size_t size, int flags, int type) | |
33569 | +{ | |
33570 | + return aufs_setxattr(dentry, name, value, size, flags); | |
33571 | +} | |
33572 | + | |
33573 | +static const struct xattr_handler au_xattr_handler = { | |
33574 | + /* no prefix, no flags */ | |
33575 | + .list = au_xattr_list, | |
33576 | + .get = au_xattr_get, | |
33577 | + .set = au_xattr_set | |
33578 | + /* why no remove? */ | |
33579 | +}; | |
33580 | + | |
33581 | +static const struct xattr_handler *au_xattr_handlers[] = { | |
33582 | + &au_xattr_handler | |
33583 | +}; | |
33584 | + | |
33585 | +void au_xattr_init(struct super_block *sb) | |
33586 | +{ | |
33587 | + /* sb->s_xattr = au_xattr_handlers; */ | |
33588 | +} | |
33589 | +#endif | |
7f207e10 AM |
33590 | diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c |
33591 | --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 JR |
33592 | +++ linux/fs/aufs/xino.c 2015-06-28 17:36:09.028407078 +0200 |
33593 | @@ -0,0 +1,1297 @@ | |
1facf9fc | 33594 | +/* |
2000de60 | 33595 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 33596 | + * |
33597 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33598 | + * it under the terms of the GNU General Public License as published by | |
33599 | + * the Free Software Foundation; either version 2 of the License, or | |
33600 | + * (at your option) any later version. | |
dece6358 AM |
33601 | + * |
33602 | + * This program is distributed in the hope that it will be useful, | |
33603 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33604 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33605 | + * GNU General Public License for more details. | |
33606 | + * | |
33607 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33608 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33609 | + */ |
33610 | + | |
33611 | +/* | |
33612 | + * external inode number translation table and bitmap | |
33613 | + */ | |
33614 | + | |
33615 | +#include <linux/seq_file.h> | |
392086de | 33616 | +#include <linux/statfs.h> |
1facf9fc | 33617 | +#include "aufs.h" |
33618 | + | |
9dbd164d | 33619 | +/* todo: unnecessary to support mmap_sem since kernel-space? */ |
5527c038 | 33620 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size, |
1facf9fc | 33621 | + loff_t *pos) |
33622 | +{ | |
33623 | + ssize_t err; | |
33624 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33625 | + union { |
33626 | + void *k; | |
33627 | + char __user *u; | |
33628 | + } buf; | |
1facf9fc | 33629 | + |
b752ccd1 | 33630 | + buf.k = kbuf; |
1facf9fc | 33631 | + oldfs = get_fs(); |
33632 | + set_fs(KERNEL_DS); | |
33633 | + do { | |
33634 | + /* todo: signal_pending? */ | |
b752ccd1 | 33635 | + err = func(file, buf.u, size, pos); |
1facf9fc | 33636 | + } while (err == -EAGAIN || err == -EINTR); |
33637 | + set_fs(oldfs); | |
33638 | + | |
33639 | +#if 0 /* reserved for future use */ | |
33640 | + if (err > 0) | |
2000de60 | 33641 | + fsnotify_access(file->f_path.dentry); |
1facf9fc | 33642 | +#endif |
33643 | + | |
33644 | + return err; | |
33645 | +} | |
33646 | + | |
33647 | +/* ---------------------------------------------------------------------- */ | |
33648 | + | |
5527c038 | 33649 | +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf, |
1facf9fc | 33650 | + size_t size, loff_t *pos) |
33651 | +{ | |
33652 | + ssize_t err; | |
33653 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33654 | + union { |
33655 | + void *k; | |
33656 | + const char __user *u; | |
33657 | + } buf; | |
1facf9fc | 33658 | + |
b752ccd1 | 33659 | + buf.k = kbuf; |
1facf9fc | 33660 | + oldfs = get_fs(); |
33661 | + set_fs(KERNEL_DS); | |
1facf9fc | 33662 | + do { |
33663 | + /* todo: signal_pending? */ | |
b752ccd1 | 33664 | + err = func(file, buf.u, size, pos); |
1facf9fc | 33665 | + } while (err == -EAGAIN || err == -EINTR); |
1facf9fc | 33666 | + set_fs(oldfs); |
33667 | + | |
33668 | +#if 0 /* reserved for future use */ | |
33669 | + if (err > 0) | |
2000de60 | 33670 | + fsnotify_modify(file->f_path.dentry); |
1facf9fc | 33671 | +#endif |
33672 | + | |
33673 | + return err; | |
33674 | +} | |
33675 | + | |
33676 | +struct do_xino_fwrite_args { | |
33677 | + ssize_t *errp; | |
5527c038 | 33678 | + vfs_writef_t func; |
1facf9fc | 33679 | + struct file *file; |
33680 | + void *buf; | |
33681 | + size_t size; | |
33682 | + loff_t *pos; | |
33683 | +}; | |
33684 | + | |
33685 | +static void call_do_xino_fwrite(void *args) | |
33686 | +{ | |
33687 | + struct do_xino_fwrite_args *a = args; | |
33688 | + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos); | |
33689 | +} | |
33690 | + | |
5527c038 JR |
33691 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
33692 | + size_t size, loff_t *pos) | |
1facf9fc | 33693 | +{ |
33694 | + ssize_t err; | |
33695 | + | |
33696 | + /* todo: signal block and no wkq? */ | |
b752ccd1 AM |
33697 | + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) { |
33698 | + lockdep_off(); | |
33699 | + err = do_xino_fwrite(func, file, buf, size, pos); | |
33700 | + lockdep_on(); | |
33701 | + } else { | |
33702 | + /* | |
33703 | + * it breaks RLIMIT_FSIZE and normal user's limit, | |
33704 | + * users should care about quota and real 'filesystem full.' | |
33705 | + */ | |
1facf9fc | 33706 | + int wkq_err; |
33707 | + struct do_xino_fwrite_args args = { | |
33708 | + .errp = &err, | |
33709 | + .func = func, | |
33710 | + .file = file, | |
33711 | + .buf = buf, | |
33712 | + .size = size, | |
33713 | + .pos = pos | |
33714 | + }; | |
33715 | + | |
33716 | + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args); | |
33717 | + if (unlikely(wkq_err)) | |
33718 | + err = wkq_err; | |
b752ccd1 | 33719 | + } |
1facf9fc | 33720 | + |
33721 | + return err; | |
33722 | +} | |
33723 | + | |
33724 | +/* ---------------------------------------------------------------------- */ | |
33725 | + | |
33726 | +/* | |
33727 | + * create a new xinofile at the same place/path as @base_file. | |
33728 | + */ | |
33729 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src) | |
33730 | +{ | |
33731 | + struct file *file; | |
4a4d8108 | 33732 | + struct dentry *base, *parent; |
523b37e3 | 33733 | + struct inode *dir, *delegated; |
1facf9fc | 33734 | + struct qstr *name; |
1308ab2a | 33735 | + struct path path; |
4a4d8108 | 33736 | + int err; |
1facf9fc | 33737 | + |
2000de60 | 33738 | + base = base_file->f_path.dentry; |
1facf9fc | 33739 | + parent = base->d_parent; /* dir inode is locked */ |
5527c038 | 33740 | + dir = d_inode(parent); |
1facf9fc | 33741 | + IMustLock(dir); |
33742 | + | |
33743 | + file = ERR_PTR(-EINVAL); | |
33744 | + name = &base->d_name; | |
4a4d8108 AM |
33745 | + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len); |
33746 | + if (IS_ERR(path.dentry)) { | |
33747 | + file = (void *)path.dentry; | |
523b37e3 AM |
33748 | + pr_err("%pd lookup err %ld\n", |
33749 | + base, PTR_ERR(path.dentry)); | |
1facf9fc | 33750 | + goto out; |
33751 | + } | |
33752 | + | |
33753 | + /* no need to mnt_want_write() since we call dentry_open() later */ | |
4a4d8108 | 33754 | + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL); |
1facf9fc | 33755 | + if (unlikely(err)) { |
33756 | + file = ERR_PTR(err); | |
523b37e3 | 33757 | + pr_err("%pd create err %d\n", base, err); |
1facf9fc | 33758 | + goto out_dput; |
33759 | + } | |
33760 | + | |
c06a8ce3 | 33761 | + path.mnt = base_file->f_path.mnt; |
4a4d8108 | 33762 | + file = vfsub_dentry_open(&path, |
7f207e10 | 33763 | + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 33764 | + /* | __FMODE_NONOTIFY */); |
1facf9fc | 33765 | + if (IS_ERR(file)) { |
523b37e3 | 33766 | + pr_err("%pd open err %ld\n", base, PTR_ERR(file)); |
1facf9fc | 33767 | + goto out_dput; |
33768 | + } | |
33769 | + | |
523b37e3 AM |
33770 | + delegated = NULL; |
33771 | + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0); | |
33772 | + if (unlikely(err == -EWOULDBLOCK)) { | |
33773 | + pr_warn("cannot retry for NFSv4 delegation" | |
33774 | + " for an internal unlink\n"); | |
33775 | + iput(delegated); | |
33776 | + } | |
1facf9fc | 33777 | + if (unlikely(err)) { |
523b37e3 | 33778 | + pr_err("%pd unlink err %d\n", base, err); |
1facf9fc | 33779 | + goto out_fput; |
33780 | + } | |
33781 | + | |
33782 | + if (copy_src) { | |
33783 | + /* no one can touch copy_src xino */ | |
c06a8ce3 | 33784 | + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src)); |
1facf9fc | 33785 | + if (unlikely(err)) { |
523b37e3 | 33786 | + pr_err("%pd copy err %d\n", base, err); |
1facf9fc | 33787 | + goto out_fput; |
33788 | + } | |
33789 | + } | |
33790 | + goto out_dput; /* success */ | |
33791 | + | |
4f0767ce | 33792 | +out_fput: |
1facf9fc | 33793 | + fput(file); |
33794 | + file = ERR_PTR(err); | |
4f0767ce | 33795 | +out_dput: |
4a4d8108 | 33796 | + dput(path.dentry); |
4f0767ce | 33797 | +out: |
1facf9fc | 33798 | + return file; |
33799 | +} | |
33800 | + | |
33801 | +struct au_xino_lock_dir { | |
33802 | + struct au_hinode *hdir; | |
33803 | + struct dentry *parent; | |
33804 | + struct mutex *mtx; | |
33805 | +}; | |
33806 | + | |
33807 | +static void au_xino_lock_dir(struct super_block *sb, struct file *xino, | |
33808 | + struct au_xino_lock_dir *ldir) | |
33809 | +{ | |
33810 | + aufs_bindex_t brid, bindex; | |
33811 | + | |
33812 | + ldir->hdir = NULL; | |
33813 | + bindex = -1; | |
33814 | + brid = au_xino_brid(sb); | |
33815 | + if (brid >= 0) | |
33816 | + bindex = au_br_index(sb, brid); | |
33817 | + if (bindex >= 0) { | |
5527c038 | 33818 | + ldir->hdir = au_hi(d_inode(sb->s_root), bindex); |
4a4d8108 | 33819 | + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT); |
1facf9fc | 33820 | + } else { |
2000de60 | 33821 | + ldir->parent = dget_parent(xino->f_path.dentry); |
5527c038 | 33822 | + ldir->mtx = &d_inode(ldir->parent)->i_mutex; |
1facf9fc | 33823 | + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT); |
33824 | + } | |
33825 | +} | |
33826 | + | |
33827 | +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir) | |
33828 | +{ | |
33829 | + if (ldir->hdir) | |
4a4d8108 | 33830 | + au_hn_imtx_unlock(ldir->hdir); |
1facf9fc | 33831 | + else { |
33832 | + mutex_unlock(ldir->mtx); | |
33833 | + dput(ldir->parent); | |
33834 | + } | |
33835 | +} | |
33836 | + | |
33837 | +/* ---------------------------------------------------------------------- */ | |
33838 | + | |
33839 | +/* trucate xino files asynchronously */ | |
33840 | + | |
33841 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex) | |
33842 | +{ | |
33843 | + int err; | |
392086de AM |
33844 | + unsigned long jiffy; |
33845 | + blkcnt_t blocks; | |
1facf9fc | 33846 | + aufs_bindex_t bi, bend; |
392086de | 33847 | + struct kstatfs *st; |
1facf9fc | 33848 | + struct au_branch *br; |
33849 | + struct file *new_xino, *file; | |
33850 | + struct super_block *h_sb; | |
33851 | + struct au_xino_lock_dir ldir; | |
33852 | + | |
392086de AM |
33853 | + err = -ENOMEM; |
33854 | + st = kzalloc(sizeof(*st), GFP_NOFS); | |
33855 | + if (unlikely(!st)) | |
33856 | + goto out; | |
33857 | + | |
1facf9fc | 33858 | + err = -EINVAL; |
33859 | + bend = au_sbend(sb); | |
33860 | + if (unlikely(bindex < 0 || bend < bindex)) | |
392086de | 33861 | + goto out_st; |
1facf9fc | 33862 | + br = au_sbr(sb, bindex); |
33863 | + file = br->br_xino.xi_file; | |
33864 | + if (!file) | |
392086de AM |
33865 | + goto out_st; |
33866 | + | |
33867 | + err = vfs_statfs(&file->f_path, st); | |
33868 | + if (unlikely(err)) | |
33869 | + AuErr1("statfs err %d, ignored\n", err); | |
33870 | + jiffy = jiffies; | |
33871 | + blocks = file_inode(file)->i_blocks; | |
33872 | + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
33873 | + bindex, (u64)blocks, st->f_bfree, st->f_blocks); | |
1facf9fc | 33874 | + |
33875 | + au_xino_lock_dir(sb, file, &ldir); | |
33876 | + /* mnt_want_write() is unnecessary here */ | |
33877 | + new_xino = au_xino_create2(file, file); | |
33878 | + au_xino_unlock_dir(&ldir); | |
33879 | + err = PTR_ERR(new_xino); | |
392086de AM |
33880 | + if (IS_ERR(new_xino)) { |
33881 | + pr_err("err %d, ignored\n", err); | |
33882 | + goto out_st; | |
33883 | + } | |
1facf9fc | 33884 | + err = 0; |
33885 | + fput(file); | |
33886 | + br->br_xino.xi_file = new_xino; | |
33887 | + | |
86dc4139 | 33888 | + h_sb = au_br_sb(br); |
1facf9fc | 33889 | + for (bi = 0; bi <= bend; bi++) { |
33890 | + if (unlikely(bi == bindex)) | |
33891 | + continue; | |
33892 | + br = au_sbr(sb, bi); | |
86dc4139 | 33893 | + if (au_br_sb(br) != h_sb) |
1facf9fc | 33894 | + continue; |
33895 | + | |
33896 | + fput(br->br_xino.xi_file); | |
33897 | + br->br_xino.xi_file = new_xino; | |
33898 | + get_file(new_xino); | |
33899 | + } | |
33900 | + | |
392086de AM |
33901 | + err = vfs_statfs(&new_xino->f_path, st); |
33902 | + if (!err) { | |
33903 | + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
33904 | + bindex, (u64)file_inode(new_xino)->i_blocks, | |
33905 | + st->f_bfree, st->f_blocks); | |
33906 | + if (file_inode(new_xino)->i_blocks < blocks) | |
33907 | + au_sbi(sb)->si_xino_jiffy = jiffy; | |
33908 | + } else | |
33909 | + AuErr1("statfs err %d, ignored\n", err); | |
33910 | + | |
33911 | +out_st: | |
33912 | + kfree(st); | |
4f0767ce | 33913 | +out: |
1facf9fc | 33914 | + return err; |
33915 | +} | |
33916 | + | |
33917 | +struct xino_do_trunc_args { | |
33918 | + struct super_block *sb; | |
33919 | + struct au_branch *br; | |
33920 | +}; | |
33921 | + | |
33922 | +static void xino_do_trunc(void *_args) | |
33923 | +{ | |
33924 | + struct xino_do_trunc_args *args = _args; | |
33925 | + struct super_block *sb; | |
33926 | + struct au_branch *br; | |
33927 | + struct inode *dir; | |
33928 | + int err; | |
33929 | + aufs_bindex_t bindex; | |
33930 | + | |
33931 | + err = 0; | |
33932 | + sb = args->sb; | |
5527c038 | 33933 | + dir = d_inode(sb->s_root); |
1facf9fc | 33934 | + br = args->br; |
33935 | + | |
33936 | + si_noflush_write_lock(sb); | |
33937 | + ii_read_lock_parent(dir); | |
33938 | + bindex = au_br_index(sb, br->br_id); | |
33939 | + err = au_xino_trunc(sb, bindex); | |
1facf9fc | 33940 | + ii_read_unlock(dir); |
33941 | + if (unlikely(err)) | |
392086de | 33942 | + pr_warn("err b%d, (%d)\n", bindex, err); |
1facf9fc | 33943 | + atomic_dec(&br->br_xino_running); |
33944 | + atomic_dec(&br->br_count); | |
1facf9fc | 33945 | + si_write_unlock(sb); |
027c5e7a | 33946 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 33947 | + kfree(args); |
33948 | +} | |
33949 | + | |
392086de AM |
33950 | +static int xino_trunc_test(struct super_block *sb, struct au_branch *br) |
33951 | +{ | |
33952 | + int err; | |
33953 | + struct kstatfs st; | |
33954 | + struct au_sbinfo *sbinfo; | |
33955 | + | |
33956 | + /* todo: si_xino_expire and the ratio should be customizable */ | |
33957 | + sbinfo = au_sbi(sb); | |
33958 | + if (time_before(jiffies, | |
33959 | + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire)) | |
33960 | + return 0; | |
33961 | + | |
33962 | + /* truncation border */ | |
33963 | + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st); | |
33964 | + if (unlikely(err)) { | |
33965 | + AuErr1("statfs err %d, ignored\n", err); | |
33966 | + return 0; | |
33967 | + } | |
33968 | + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC) | |
33969 | + return 0; | |
33970 | + | |
33971 | + return 1; | |
33972 | +} | |
33973 | + | |
1facf9fc | 33974 | +static void xino_try_trunc(struct super_block *sb, struct au_branch *br) |
33975 | +{ | |
33976 | + struct xino_do_trunc_args *args; | |
33977 | + int wkq_err; | |
33978 | + | |
392086de | 33979 | + if (!xino_trunc_test(sb, br)) |
1facf9fc | 33980 | + return; |
33981 | + | |
33982 | + if (atomic_inc_return(&br->br_xino_running) > 1) | |
33983 | + goto out; | |
33984 | + | |
33985 | + /* lock and kfree() will be called in trunc_xino() */ | |
33986 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
33987 | + if (unlikely(!args)) { | |
33988 | + AuErr1("no memory\n"); | |
33989 | + goto out_args; | |
33990 | + } | |
33991 | + | |
e49829fe | 33992 | + atomic_inc(&br->br_count); |
1facf9fc | 33993 | + args->sb = sb; |
33994 | + args->br = br; | |
53392da6 | 33995 | + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0); |
1facf9fc | 33996 | + if (!wkq_err) |
33997 | + return; /* success */ | |
33998 | + | |
4a4d8108 | 33999 | + pr_err("wkq %d\n", wkq_err); |
e49829fe | 34000 | + atomic_dec(&br->br_count); |
1facf9fc | 34001 | + |
4f0767ce | 34002 | +out_args: |
1facf9fc | 34003 | + kfree(args); |
4f0767ce | 34004 | +out: |
e49829fe | 34005 | + atomic_dec(&br->br_xino_running); |
1facf9fc | 34006 | +} |
34007 | + | |
34008 | +/* ---------------------------------------------------------------------- */ | |
34009 | + | |
5527c038 | 34010 | +static int au_xino_do_write(vfs_writef_t write, struct file *file, |
1facf9fc | 34011 | + ino_t h_ino, ino_t ino) |
34012 | +{ | |
34013 | + loff_t pos; | |
34014 | + ssize_t sz; | |
34015 | + | |
34016 | + pos = h_ino; | |
34017 | + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) { | |
34018 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
34019 | + return -EFBIG; | |
34020 | + } | |
34021 | + pos *= sizeof(ino); | |
34022 | + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos); | |
34023 | + if (sz == sizeof(ino)) | |
34024 | + return 0; /* success */ | |
34025 | + | |
34026 | + AuIOErr("write failed (%zd)\n", sz); | |
34027 | + return -EIO; | |
34028 | +} | |
34029 | + | |
34030 | +/* | |
34031 | + * write @ino to the xinofile for the specified branch{@sb, @bindex} | |
34032 | + * at the position of @h_ino. | |
34033 | + * even if @ino is zero, it is written to the xinofile and means no entry. | |
34034 | + * if the size of the xino file on a specific filesystem exceeds the watermark, | |
34035 | + * try truncating it. | |
34036 | + */ | |
34037 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
34038 | + ino_t ino) | |
34039 | +{ | |
34040 | + int err; | |
34041 | + unsigned int mnt_flags; | |
34042 | + struct au_branch *br; | |
34043 | + | |
34044 | + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max) | |
34045 | + || ((loff_t)-1) > 0); | |
dece6358 | 34046 | + SiMustAnyLock(sb); |
1facf9fc | 34047 | + |
34048 | + mnt_flags = au_mntflags(sb); | |
34049 | + if (!au_opt_test(mnt_flags, XINO)) | |
34050 | + return 0; | |
34051 | + | |
34052 | + br = au_sbr(sb, bindex); | |
34053 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
34054 | + h_ino, ino); | |
34055 | + if (!err) { | |
34056 | + if (au_opt_test(mnt_flags, TRUNC_XINO) | |
86dc4139 | 34057 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
1facf9fc | 34058 | + xino_try_trunc(sb, br); |
34059 | + return 0; /* success */ | |
34060 | + } | |
34061 | + | |
34062 | + AuIOErr("write failed (%d)\n", err); | |
34063 | + return -EIO; | |
34064 | +} | |
34065 | + | |
34066 | +/* ---------------------------------------------------------------------- */ | |
34067 | + | |
34068 | +/* aufs inode number bitmap */ | |
34069 | + | |
34070 | +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE; | |
34071 | +static ino_t xib_calc_ino(unsigned long pindex, int bit) | |
34072 | +{ | |
34073 | + ino_t ino; | |
34074 | + | |
34075 | + AuDebugOn(bit < 0 || page_bits <= bit); | |
34076 | + ino = AUFS_FIRST_INO + pindex * page_bits + bit; | |
34077 | + return ino; | |
34078 | +} | |
34079 | + | |
34080 | +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit) | |
34081 | +{ | |
34082 | + AuDebugOn(ino < AUFS_FIRST_INO); | |
34083 | + ino -= AUFS_FIRST_INO; | |
34084 | + *pindex = ino / page_bits; | |
34085 | + *bit = ino % page_bits; | |
34086 | +} | |
34087 | + | |
34088 | +static int xib_pindex(struct super_block *sb, unsigned long pindex) | |
34089 | +{ | |
34090 | + int err; | |
34091 | + loff_t pos; | |
34092 | + ssize_t sz; | |
34093 | + struct au_sbinfo *sbinfo; | |
34094 | + struct file *xib; | |
34095 | + unsigned long *p; | |
34096 | + | |
34097 | + sbinfo = au_sbi(sb); | |
34098 | + MtxMustLock(&sbinfo->si_xib_mtx); | |
34099 | + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE | |
34100 | + || !au_opt_test(sbinfo->si_mntflags, XINO)); | |
34101 | + | |
34102 | + if (pindex == sbinfo->si_xib_last_pindex) | |
34103 | + return 0; | |
34104 | + | |
34105 | + xib = sbinfo->si_xib; | |
34106 | + p = sbinfo->si_xib_buf; | |
34107 | + pos = sbinfo->si_xib_last_pindex; | |
34108 | + pos *= PAGE_SIZE; | |
34109 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
34110 | + if (unlikely(sz != PAGE_SIZE)) | |
34111 | + goto out; | |
34112 | + | |
34113 | + pos = pindex; | |
34114 | + pos *= PAGE_SIZE; | |
c06a8ce3 | 34115 | + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE) |
1facf9fc | 34116 | + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos); |
34117 | + else { | |
34118 | + memset(p, 0, PAGE_SIZE); | |
34119 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
34120 | + } | |
34121 | + if (sz == PAGE_SIZE) { | |
34122 | + sbinfo->si_xib_last_pindex = pindex; | |
34123 | + return 0; /* success */ | |
34124 | + } | |
34125 | + | |
4f0767ce | 34126 | +out: |
b752ccd1 AM |
34127 | + AuIOErr1("write failed (%zd)\n", sz); |
34128 | + err = sz; | |
34129 | + if (sz >= 0) | |
34130 | + err = -EIO; | |
34131 | + return err; | |
34132 | +} | |
34133 | + | |
34134 | +/* ---------------------------------------------------------------------- */ | |
34135 | + | |
34136 | +static void au_xib_clear_bit(struct inode *inode) | |
34137 | +{ | |
34138 | + int err, bit; | |
34139 | + unsigned long pindex; | |
34140 | + struct super_block *sb; | |
34141 | + struct au_sbinfo *sbinfo; | |
34142 | + | |
34143 | + AuDebugOn(inode->i_nlink); | |
34144 | + | |
34145 | + sb = inode->i_sb; | |
34146 | + xib_calc_bit(inode->i_ino, &pindex, &bit); | |
34147 | + AuDebugOn(page_bits <= bit); | |
34148 | + sbinfo = au_sbi(sb); | |
34149 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34150 | + err = xib_pindex(sb, pindex); | |
34151 | + if (!err) { | |
34152 | + clear_bit(bit, sbinfo->si_xib_buf); | |
34153 | + sbinfo->si_xib_next_bit = bit; | |
34154 | + } | |
34155 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34156 | +} | |
34157 | + | |
34158 | +/* for s_op->delete_inode() */ | |
34159 | +void au_xino_delete_inode(struct inode *inode, const int unlinked) | |
34160 | +{ | |
34161 | + int err; | |
34162 | + unsigned int mnt_flags; | |
34163 | + aufs_bindex_t bindex, bend, bi; | |
34164 | + unsigned char try_trunc; | |
34165 | + struct au_iinfo *iinfo; | |
34166 | + struct super_block *sb; | |
34167 | + struct au_hinode *hi; | |
34168 | + struct inode *h_inode; | |
34169 | + struct au_branch *br; | |
5527c038 | 34170 | + vfs_writef_t xwrite; |
b752ccd1 AM |
34171 | + |
34172 | + sb = inode->i_sb; | |
34173 | + mnt_flags = au_mntflags(sb); | |
34174 | + if (!au_opt_test(mnt_flags, XINO) | |
34175 | + || inode->i_ino == AUFS_ROOT_INO) | |
34176 | + return; | |
34177 | + | |
34178 | + if (unlinked) { | |
34179 | + au_xigen_inc(inode); | |
34180 | + au_xib_clear_bit(inode); | |
34181 | + } | |
34182 | + | |
34183 | + iinfo = au_ii(inode); | |
34184 | + if (!iinfo) | |
34185 | + return; | |
1facf9fc | 34186 | + |
b752ccd1 AM |
34187 | + bindex = iinfo->ii_bstart; |
34188 | + if (bindex < 0) | |
34189 | + return; | |
1facf9fc | 34190 | + |
b752ccd1 AM |
34191 | + xwrite = au_sbi(sb)->si_xwrite; |
34192 | + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO); | |
34193 | + hi = iinfo->ii_hinode + bindex; | |
34194 | + bend = iinfo->ii_bend; | |
34195 | + for (; bindex <= bend; bindex++, hi++) { | |
34196 | + h_inode = hi->hi_inode; | |
34197 | + if (!h_inode | |
34198 | + || (!unlinked && h_inode->i_nlink)) | |
34199 | + continue; | |
1facf9fc | 34200 | + |
b752ccd1 AM |
34201 | + /* inode may not be revalidated */ |
34202 | + bi = au_br_index(sb, hi->hi_id); | |
34203 | + if (bi < 0) | |
34204 | + continue; | |
1facf9fc | 34205 | + |
b752ccd1 AM |
34206 | + br = au_sbr(sb, bi); |
34207 | + err = au_xino_do_write(xwrite, br->br_xino.xi_file, | |
34208 | + h_inode->i_ino, /*ino*/0); | |
34209 | + if (!err && try_trunc | |
86dc4139 | 34210 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
b752ccd1 | 34211 | + xino_try_trunc(sb, br); |
1facf9fc | 34212 | + } |
1facf9fc | 34213 | +} |
34214 | + | |
34215 | +/* get an unused inode number from bitmap */ | |
34216 | +ino_t au_xino_new_ino(struct super_block *sb) | |
34217 | +{ | |
34218 | + ino_t ino; | |
34219 | + unsigned long *p, pindex, ul, pend; | |
34220 | + struct au_sbinfo *sbinfo; | |
34221 | + struct file *file; | |
34222 | + int free_bit, err; | |
34223 | + | |
34224 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
34225 | + return iunique(sb, AUFS_FIRST_INO); | |
34226 | + | |
34227 | + sbinfo = au_sbi(sb); | |
34228 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34229 | + p = sbinfo->si_xib_buf; | |
34230 | + free_bit = sbinfo->si_xib_next_bit; | |
34231 | + if (free_bit < page_bits && !test_bit(free_bit, p)) | |
34232 | + goto out; /* success */ | |
34233 | + free_bit = find_first_zero_bit(p, page_bits); | |
34234 | + if (free_bit < page_bits) | |
34235 | + goto out; /* success */ | |
34236 | + | |
34237 | + pindex = sbinfo->si_xib_last_pindex; | |
34238 | + for (ul = pindex - 1; ul < ULONG_MAX; ul--) { | |
34239 | + err = xib_pindex(sb, ul); | |
34240 | + if (unlikely(err)) | |
34241 | + goto out_err; | |
34242 | + free_bit = find_first_zero_bit(p, page_bits); | |
34243 | + if (free_bit < page_bits) | |
34244 | + goto out; /* success */ | |
34245 | + } | |
34246 | + | |
34247 | + file = sbinfo->si_xib; | |
c06a8ce3 | 34248 | + pend = vfsub_f_size_read(file) / PAGE_SIZE; |
1facf9fc | 34249 | + for (ul = pindex + 1; ul <= pend; ul++) { |
34250 | + err = xib_pindex(sb, ul); | |
34251 | + if (unlikely(err)) | |
34252 | + goto out_err; | |
34253 | + free_bit = find_first_zero_bit(p, page_bits); | |
34254 | + if (free_bit < page_bits) | |
34255 | + goto out; /* success */ | |
34256 | + } | |
34257 | + BUG(); | |
34258 | + | |
4f0767ce | 34259 | +out: |
1facf9fc | 34260 | + set_bit(free_bit, p); |
7f207e10 | 34261 | + sbinfo->si_xib_next_bit = free_bit + 1; |
1facf9fc | 34262 | + pindex = sbinfo->si_xib_last_pindex; |
34263 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34264 | + ino = xib_calc_ino(pindex, free_bit); | |
34265 | + AuDbg("i%lu\n", (unsigned long)ino); | |
34266 | + return ino; | |
4f0767ce | 34267 | +out_err: |
1facf9fc | 34268 | + mutex_unlock(&sbinfo->si_xib_mtx); |
34269 | + AuDbg("i0\n"); | |
34270 | + return 0; | |
34271 | +} | |
34272 | + | |
34273 | +/* | |
34274 | + * read @ino from xinofile for the specified branch{@sb, @bindex} | |
34275 | + * at the position of @h_ino. | |
34276 | + * if @ino does not exist and @do_new is true, get new one. | |
34277 | + */ | |
34278 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
34279 | + ino_t *ino) | |
34280 | +{ | |
34281 | + int err; | |
34282 | + ssize_t sz; | |
34283 | + loff_t pos; | |
34284 | + struct file *file; | |
34285 | + struct au_sbinfo *sbinfo; | |
34286 | + | |
34287 | + *ino = 0; | |
34288 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
34289 | + return 0; /* no xino */ | |
34290 | + | |
34291 | + err = 0; | |
34292 | + sbinfo = au_sbi(sb); | |
34293 | + pos = h_ino; | |
34294 | + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) { | |
34295 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
34296 | + return -EFBIG; | |
34297 | + } | |
34298 | + pos *= sizeof(*ino); | |
34299 | + | |
34300 | + file = au_sbr(sb, bindex)->br_xino.xi_file; | |
c06a8ce3 | 34301 | + if (vfsub_f_size_read(file) < pos + sizeof(*ino)) |
1facf9fc | 34302 | + return 0; /* no ino */ |
34303 | + | |
34304 | + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos); | |
34305 | + if (sz == sizeof(*ino)) | |
34306 | + return 0; /* success */ | |
34307 | + | |
34308 | + err = sz; | |
34309 | + if (unlikely(sz >= 0)) { | |
34310 | + err = -EIO; | |
34311 | + AuIOErr("xino read error (%zd)\n", sz); | |
34312 | + } | |
34313 | + | |
34314 | + return err; | |
34315 | +} | |
34316 | + | |
34317 | +/* ---------------------------------------------------------------------- */ | |
34318 | + | |
34319 | +/* create and set a new xino file */ | |
34320 | + | |
34321 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent) | |
34322 | +{ | |
34323 | + struct file *file; | |
34324 | + struct dentry *h_parent, *d; | |
b912730e | 34325 | + struct inode *h_dir, *inode; |
1facf9fc | 34326 | + int err; |
34327 | + | |
34328 | + /* | |
34329 | + * at mount-time, and the xino file is the default path, | |
4a4d8108 | 34330 | + * hnotify is disabled so we have no notify events to ignore. |
1facf9fc | 34331 | + * when a user specified the xino, we cannot get au_hdir to be ignored. |
34332 | + */ | |
7f207e10 | 34333 | + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 34334 | + /* | __FMODE_NONOTIFY */, |
1facf9fc | 34335 | + S_IRUGO | S_IWUGO); |
34336 | + if (IS_ERR(file)) { | |
34337 | + if (!silent) | |
4a4d8108 | 34338 | + pr_err("open %s(%ld)\n", fname, PTR_ERR(file)); |
1facf9fc | 34339 | + return file; |
34340 | + } | |
34341 | + | |
34342 | + /* keep file count */ | |
b912730e AM |
34343 | + err = 0; |
34344 | + inode = file_inode(file); | |
2000de60 | 34345 | + h_parent = dget_parent(file->f_path.dentry); |
5527c038 | 34346 | + h_dir = d_inode(h_parent); |
1facf9fc | 34347 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); |
34348 | + /* mnt_want_write() is unnecessary here */ | |
523b37e3 | 34349 | + /* no delegation since it is just created */ |
b912730e AM |
34350 | + if (inode->i_nlink) |
34351 | + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, | |
34352 | + /*force*/0); | |
1facf9fc | 34353 | + mutex_unlock(&h_dir->i_mutex); |
34354 | + dput(h_parent); | |
34355 | + if (unlikely(err)) { | |
34356 | + if (!silent) | |
4a4d8108 | 34357 | + pr_err("unlink %s(%d)\n", fname, err); |
1facf9fc | 34358 | + goto out; |
34359 | + } | |
34360 | + | |
34361 | + err = -EINVAL; | |
2000de60 | 34362 | + d = file->f_path.dentry; |
1facf9fc | 34363 | + if (unlikely(sb == d->d_sb)) { |
34364 | + if (!silent) | |
4a4d8108 | 34365 | + pr_err("%s must be outside\n", fname); |
1facf9fc | 34366 | + goto out; |
34367 | + } | |
34368 | + if (unlikely(au_test_fs_bad_xino(d->d_sb))) { | |
34369 | + if (!silent) | |
4a4d8108 AM |
34370 | + pr_err("xino doesn't support %s(%s)\n", |
34371 | + fname, au_sbtype(d->d_sb)); | |
1facf9fc | 34372 | + goto out; |
34373 | + } | |
34374 | + return file; /* success */ | |
34375 | + | |
4f0767ce | 34376 | +out: |
1facf9fc | 34377 | + fput(file); |
34378 | + file = ERR_PTR(err); | |
34379 | + return file; | |
34380 | +} | |
34381 | + | |
34382 | +/* | |
34383 | + * find another branch who is on the same filesystem of the specified | |
34384 | + * branch{@btgt}. search until @bend. | |
34385 | + */ | |
34386 | +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt, | |
34387 | + aufs_bindex_t bend) | |
34388 | +{ | |
34389 | + aufs_bindex_t bindex; | |
34390 | + struct super_block *tgt_sb = au_sbr_sb(sb, btgt); | |
34391 | + | |
34392 | + for (bindex = 0; bindex < btgt; bindex++) | |
34393 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
34394 | + return bindex; | |
34395 | + for (bindex++; bindex <= bend; bindex++) | |
34396 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
34397 | + return bindex; | |
34398 | + return -1; | |
34399 | +} | |
34400 | + | |
34401 | +/* ---------------------------------------------------------------------- */ | |
34402 | + | |
34403 | +/* | |
34404 | + * initialize the xinofile for the specified branch @br | |
34405 | + * at the place/path where @base_file indicates. | |
34406 | + * test whether another branch is on the same filesystem or not, | |
34407 | + * if @do_test is true. | |
34408 | + */ | |
34409 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino, | |
34410 | + struct file *base_file, int do_test) | |
34411 | +{ | |
34412 | + int err; | |
34413 | + ino_t ino; | |
34414 | + aufs_bindex_t bend, bindex; | |
34415 | + struct au_branch *shared_br, *b; | |
34416 | + struct file *file; | |
34417 | + struct super_block *tgt_sb; | |
34418 | + | |
34419 | + shared_br = NULL; | |
34420 | + bend = au_sbend(sb); | |
34421 | + if (do_test) { | |
86dc4139 | 34422 | + tgt_sb = au_br_sb(br); |
1facf9fc | 34423 | + for (bindex = 0; bindex <= bend; bindex++) { |
34424 | + b = au_sbr(sb, bindex); | |
86dc4139 | 34425 | + if (tgt_sb == au_br_sb(b)) { |
1facf9fc | 34426 | + shared_br = b; |
34427 | + break; | |
34428 | + } | |
34429 | + } | |
34430 | + } | |
34431 | + | |
34432 | + if (!shared_br || !shared_br->br_xino.xi_file) { | |
34433 | + struct au_xino_lock_dir ldir; | |
34434 | + | |
34435 | + au_xino_lock_dir(sb, base_file, &ldir); | |
34436 | + /* mnt_want_write() is unnecessary here */ | |
34437 | + file = au_xino_create2(base_file, NULL); | |
34438 | + au_xino_unlock_dir(&ldir); | |
34439 | + err = PTR_ERR(file); | |
34440 | + if (IS_ERR(file)) | |
34441 | + goto out; | |
34442 | + br->br_xino.xi_file = file; | |
34443 | + } else { | |
34444 | + br->br_xino.xi_file = shared_br->br_xino.xi_file; | |
34445 | + get_file(br->br_xino.xi_file); | |
34446 | + } | |
34447 | + | |
34448 | + ino = AUFS_ROOT_INO; | |
34449 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
34450 | + h_ino, ino); | |
b752ccd1 AM |
34451 | + if (unlikely(err)) { |
34452 | + fput(br->br_xino.xi_file); | |
34453 | + br->br_xino.xi_file = NULL; | |
34454 | + } | |
1facf9fc | 34455 | + |
4f0767ce | 34456 | +out: |
1facf9fc | 34457 | + return err; |
34458 | +} | |
34459 | + | |
34460 | +/* ---------------------------------------------------------------------- */ | |
34461 | + | |
34462 | +/* trucate a xino bitmap file */ | |
34463 | + | |
34464 | +/* todo: slow */ | |
34465 | +static int do_xib_restore(struct super_block *sb, struct file *file, void *page) | |
34466 | +{ | |
34467 | + int err, bit; | |
34468 | + ssize_t sz; | |
34469 | + unsigned long pindex; | |
34470 | + loff_t pos, pend; | |
34471 | + struct au_sbinfo *sbinfo; | |
5527c038 | 34472 | + vfs_readf_t func; |
1facf9fc | 34473 | + ino_t *ino; |
34474 | + unsigned long *p; | |
34475 | + | |
34476 | + err = 0; | |
34477 | + sbinfo = au_sbi(sb); | |
dece6358 | 34478 | + MtxMustLock(&sbinfo->si_xib_mtx); |
1facf9fc | 34479 | + p = sbinfo->si_xib_buf; |
34480 | + func = sbinfo->si_xread; | |
c06a8ce3 | 34481 | + pend = vfsub_f_size_read(file); |
1facf9fc | 34482 | + pos = 0; |
34483 | + while (pos < pend) { | |
34484 | + sz = xino_fread(func, file, page, PAGE_SIZE, &pos); | |
34485 | + err = sz; | |
34486 | + if (unlikely(sz <= 0)) | |
34487 | + goto out; | |
34488 | + | |
34489 | + err = 0; | |
34490 | + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) { | |
34491 | + if (unlikely(*ino < AUFS_FIRST_INO)) | |
34492 | + continue; | |
34493 | + | |
34494 | + xib_calc_bit(*ino, &pindex, &bit); | |
34495 | + AuDebugOn(page_bits <= bit); | |
34496 | + err = xib_pindex(sb, pindex); | |
34497 | + if (!err) | |
34498 | + set_bit(bit, p); | |
34499 | + else | |
34500 | + goto out; | |
34501 | + } | |
34502 | + } | |
34503 | + | |
4f0767ce | 34504 | +out: |
1facf9fc | 34505 | + return err; |
34506 | +} | |
34507 | + | |
34508 | +static int xib_restore(struct super_block *sb) | |
34509 | +{ | |
34510 | + int err; | |
34511 | + aufs_bindex_t bindex, bend; | |
34512 | + void *page; | |
34513 | + | |
34514 | + err = -ENOMEM; | |
34515 | + page = (void *)__get_free_page(GFP_NOFS); | |
34516 | + if (unlikely(!page)) | |
34517 | + goto out; | |
34518 | + | |
34519 | + err = 0; | |
34520 | + bend = au_sbend(sb); | |
34521 | + for (bindex = 0; !err && bindex <= bend; bindex++) | |
34522 | + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) | |
34523 | + err = do_xib_restore | |
34524 | + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page); | |
34525 | + else | |
34526 | + AuDbg("b%d\n", bindex); | |
34527 | + free_page((unsigned long)page); | |
34528 | + | |
4f0767ce | 34529 | +out: |
1facf9fc | 34530 | + return err; |
34531 | +} | |
34532 | + | |
34533 | +int au_xib_trunc(struct super_block *sb) | |
34534 | +{ | |
34535 | + int err; | |
34536 | + ssize_t sz; | |
34537 | + loff_t pos; | |
34538 | + struct au_xino_lock_dir ldir; | |
34539 | + struct au_sbinfo *sbinfo; | |
34540 | + unsigned long *p; | |
34541 | + struct file *file; | |
34542 | + | |
dece6358 AM |
34543 | + SiMustWriteLock(sb); |
34544 | + | |
1facf9fc | 34545 | + err = 0; |
34546 | + sbinfo = au_sbi(sb); | |
34547 | + if (!au_opt_test(sbinfo->si_mntflags, XINO)) | |
34548 | + goto out; | |
34549 | + | |
34550 | + file = sbinfo->si_xib; | |
c06a8ce3 | 34551 | + if (vfsub_f_size_read(file) <= PAGE_SIZE) |
1facf9fc | 34552 | + goto out; |
34553 | + | |
34554 | + au_xino_lock_dir(sb, file, &ldir); | |
34555 | + /* mnt_want_write() is unnecessary here */ | |
34556 | + file = au_xino_create2(sbinfo->si_xib, NULL); | |
34557 | + au_xino_unlock_dir(&ldir); | |
34558 | + err = PTR_ERR(file); | |
34559 | + if (IS_ERR(file)) | |
34560 | + goto out; | |
34561 | + fput(sbinfo->si_xib); | |
34562 | + sbinfo->si_xib = file; | |
34563 | + | |
34564 | + p = sbinfo->si_xib_buf; | |
34565 | + memset(p, 0, PAGE_SIZE); | |
34566 | + pos = 0; | |
34567 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos); | |
34568 | + if (unlikely(sz != PAGE_SIZE)) { | |
34569 | + err = sz; | |
34570 | + AuIOErr("err %d\n", err); | |
34571 | + if (sz >= 0) | |
34572 | + err = -EIO; | |
34573 | + goto out; | |
34574 | + } | |
34575 | + | |
34576 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34577 | + /* mnt_want_write() is unnecessary here */ | |
34578 | + err = xib_restore(sb); | |
34579 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34580 | + | |
34581 | +out: | |
34582 | + return err; | |
34583 | +} | |
34584 | + | |
34585 | +/* ---------------------------------------------------------------------- */ | |
34586 | + | |
34587 | +/* | |
34588 | + * xino mount option handlers | |
34589 | + */ | |
1facf9fc | 34590 | + |
34591 | +/* xino bitmap */ | |
34592 | +static void xino_clear_xib(struct super_block *sb) | |
34593 | +{ | |
34594 | + struct au_sbinfo *sbinfo; | |
34595 | + | |
dece6358 AM |
34596 | + SiMustWriteLock(sb); |
34597 | + | |
1facf9fc | 34598 | + sbinfo = au_sbi(sb); |
34599 | + sbinfo->si_xread = NULL; | |
34600 | + sbinfo->si_xwrite = NULL; | |
34601 | + if (sbinfo->si_xib) | |
34602 | + fput(sbinfo->si_xib); | |
34603 | + sbinfo->si_xib = NULL; | |
34604 | + free_page((unsigned long)sbinfo->si_xib_buf); | |
34605 | + sbinfo->si_xib_buf = NULL; | |
34606 | +} | |
34607 | + | |
34608 | +static int au_xino_set_xib(struct super_block *sb, struct file *base) | |
34609 | +{ | |
34610 | + int err; | |
34611 | + loff_t pos; | |
34612 | + struct au_sbinfo *sbinfo; | |
34613 | + struct file *file; | |
34614 | + | |
dece6358 AM |
34615 | + SiMustWriteLock(sb); |
34616 | + | |
1facf9fc | 34617 | + sbinfo = au_sbi(sb); |
34618 | + file = au_xino_create2(base, sbinfo->si_xib); | |
34619 | + err = PTR_ERR(file); | |
34620 | + if (IS_ERR(file)) | |
34621 | + goto out; | |
34622 | + if (sbinfo->si_xib) | |
34623 | + fput(sbinfo->si_xib); | |
34624 | + sbinfo->si_xib = file; | |
5527c038 JR |
34625 | + sbinfo->si_xread = vfs_readf(file); |
34626 | + sbinfo->si_xwrite = vfs_writef(file); | |
1facf9fc | 34627 | + |
34628 | + err = -ENOMEM; | |
34629 | + if (!sbinfo->si_xib_buf) | |
34630 | + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS); | |
34631 | + if (unlikely(!sbinfo->si_xib_buf)) | |
34632 | + goto out_unset; | |
34633 | + | |
34634 | + sbinfo->si_xib_last_pindex = 0; | |
34635 | + sbinfo->si_xib_next_bit = 0; | |
c06a8ce3 | 34636 | + if (vfsub_f_size_read(file) < PAGE_SIZE) { |
1facf9fc | 34637 | + pos = 0; |
34638 | + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf, | |
34639 | + PAGE_SIZE, &pos); | |
34640 | + if (unlikely(err != PAGE_SIZE)) | |
34641 | + goto out_free; | |
34642 | + } | |
34643 | + err = 0; | |
34644 | + goto out; /* success */ | |
34645 | + | |
4f0767ce | 34646 | +out_free: |
1facf9fc | 34647 | + free_page((unsigned long)sbinfo->si_xib_buf); |
b752ccd1 AM |
34648 | + sbinfo->si_xib_buf = NULL; |
34649 | + if (err >= 0) | |
34650 | + err = -EIO; | |
4f0767ce | 34651 | +out_unset: |
b752ccd1 AM |
34652 | + fput(sbinfo->si_xib); |
34653 | + sbinfo->si_xib = NULL; | |
34654 | + sbinfo->si_xread = NULL; | |
34655 | + sbinfo->si_xwrite = NULL; | |
4f0767ce | 34656 | +out: |
b752ccd1 | 34657 | + return err; |
1facf9fc | 34658 | +} |
34659 | + | |
b752ccd1 AM |
34660 | +/* xino for each branch */ |
34661 | +static void xino_clear_br(struct super_block *sb) | |
34662 | +{ | |
34663 | + aufs_bindex_t bindex, bend; | |
34664 | + struct au_branch *br; | |
1facf9fc | 34665 | + |
b752ccd1 AM |
34666 | + bend = au_sbend(sb); |
34667 | + for (bindex = 0; bindex <= bend; bindex++) { | |
34668 | + br = au_sbr(sb, bindex); | |
34669 | + if (!br || !br->br_xino.xi_file) | |
34670 | + continue; | |
34671 | + | |
34672 | + fput(br->br_xino.xi_file); | |
34673 | + br->br_xino.xi_file = NULL; | |
34674 | + } | |
34675 | +} | |
34676 | + | |
34677 | +static int au_xino_set_br(struct super_block *sb, struct file *base) | |
1facf9fc | 34678 | +{ |
34679 | + int err; | |
b752ccd1 AM |
34680 | + ino_t ino; |
34681 | + aufs_bindex_t bindex, bend, bshared; | |
34682 | + struct { | |
34683 | + struct file *old, *new; | |
34684 | + } *fpair, *p; | |
34685 | + struct au_branch *br; | |
34686 | + struct inode *inode; | |
5527c038 | 34687 | + vfs_writef_t writef; |
1facf9fc | 34688 | + |
b752ccd1 AM |
34689 | + SiMustWriteLock(sb); |
34690 | + | |
34691 | + err = -ENOMEM; | |
34692 | + bend = au_sbend(sb); | |
34693 | + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS); | |
34694 | + if (unlikely(!fpair)) | |
1facf9fc | 34695 | + goto out; |
34696 | + | |
5527c038 | 34697 | + inode = d_inode(sb->s_root); |
b752ccd1 AM |
34698 | + ino = AUFS_ROOT_INO; |
34699 | + writef = au_sbi(sb)->si_xwrite; | |
34700 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) { | |
34701 | + br = au_sbr(sb, bindex); | |
34702 | + bshared = is_sb_shared(sb, bindex, bindex - 1); | |
34703 | + if (bshared >= 0) { | |
34704 | + /* shared xino */ | |
34705 | + *p = fpair[bshared]; | |
34706 | + get_file(p->new); | |
34707 | + } | |
34708 | + | |
34709 | + if (!p->new) { | |
34710 | + /* new xino */ | |
34711 | + p->old = br->br_xino.xi_file; | |
34712 | + p->new = au_xino_create2(base, br->br_xino.xi_file); | |
34713 | + err = PTR_ERR(p->new); | |
34714 | + if (IS_ERR(p->new)) { | |
34715 | + p->new = NULL; | |
34716 | + goto out_pair; | |
34717 | + } | |
34718 | + } | |
34719 | + | |
34720 | + err = au_xino_do_write(writef, p->new, | |
34721 | + au_h_iptr(inode, bindex)->i_ino, ino); | |
34722 | + if (unlikely(err)) | |
34723 | + goto out_pair; | |
34724 | + } | |
34725 | + | |
34726 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) { | |
34727 | + br = au_sbr(sb, bindex); | |
34728 | + if (br->br_xino.xi_file) | |
34729 | + fput(br->br_xino.xi_file); | |
34730 | + get_file(p->new); | |
34731 | + br->br_xino.xi_file = p->new; | |
34732 | + } | |
1facf9fc | 34733 | + |
4f0767ce | 34734 | +out_pair: |
b752ccd1 AM |
34735 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) |
34736 | + if (p->new) | |
34737 | + fput(p->new); | |
34738 | + else | |
34739 | + break; | |
34740 | + kfree(fpair); | |
4f0767ce | 34741 | +out: |
1facf9fc | 34742 | + return err; |
34743 | +} | |
b752ccd1 AM |
34744 | + |
34745 | +void au_xino_clr(struct super_block *sb) | |
34746 | +{ | |
34747 | + struct au_sbinfo *sbinfo; | |
34748 | + | |
34749 | + au_xigen_clr(sb); | |
34750 | + xino_clear_xib(sb); | |
34751 | + xino_clear_br(sb); | |
34752 | + sbinfo = au_sbi(sb); | |
34753 | + /* lvalue, do not call au_mntflags() */ | |
34754 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
34755 | +} | |
34756 | + | |
34757 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount) | |
34758 | +{ | |
34759 | + int err, skip; | |
34760 | + struct dentry *parent, *cur_parent; | |
34761 | + struct qstr *dname, *cur_name; | |
34762 | + struct file *cur_xino; | |
34763 | + struct inode *dir; | |
34764 | + struct au_sbinfo *sbinfo; | |
34765 | + | |
34766 | + SiMustWriteLock(sb); | |
34767 | + | |
34768 | + err = 0; | |
34769 | + sbinfo = au_sbi(sb); | |
2000de60 | 34770 | + parent = dget_parent(xino->file->f_path.dentry); |
b752ccd1 AM |
34771 | + if (remount) { |
34772 | + skip = 0; | |
2000de60 | 34773 | + dname = &xino->file->f_path.dentry->d_name; |
b752ccd1 AM |
34774 | + cur_xino = sbinfo->si_xib; |
34775 | + if (cur_xino) { | |
2000de60 JR |
34776 | + cur_parent = dget_parent(cur_xino->f_path.dentry); |
34777 | + cur_name = &cur_xino->f_path.dentry->d_name; | |
b752ccd1 | 34778 | + skip = (cur_parent == parent |
38d290e6 | 34779 | + && au_qstreq(dname, cur_name)); |
b752ccd1 AM |
34780 | + dput(cur_parent); |
34781 | + } | |
34782 | + if (skip) | |
34783 | + goto out; | |
34784 | + } | |
34785 | + | |
34786 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
5527c038 | 34787 | + dir = d_inode(parent); |
b752ccd1 AM |
34788 | + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT); |
34789 | + /* mnt_want_write() is unnecessary here */ | |
34790 | + err = au_xino_set_xib(sb, xino->file); | |
34791 | + if (!err) | |
34792 | + err = au_xigen_set(sb, xino->file); | |
34793 | + if (!err) | |
34794 | + err = au_xino_set_br(sb, xino->file); | |
34795 | + mutex_unlock(&dir->i_mutex); | |
34796 | + if (!err) | |
34797 | + goto out; /* success */ | |
34798 | + | |
34799 | + /* reset all */ | |
34800 | + AuIOErr("failed creating xino(%d).\n", err); | |
c1595e42 JR |
34801 | + au_xigen_clr(sb); |
34802 | + xino_clear_xib(sb); | |
b752ccd1 | 34803 | + |
4f0767ce | 34804 | +out: |
b752ccd1 AM |
34805 | + dput(parent); |
34806 | + return err; | |
34807 | +} | |
34808 | + | |
34809 | +/* ---------------------------------------------------------------------- */ | |
34810 | + | |
34811 | +/* | |
34812 | + * create a xinofile at the default place/path. | |
34813 | + */ | |
34814 | +struct file *au_xino_def(struct super_block *sb) | |
34815 | +{ | |
34816 | + struct file *file; | |
34817 | + char *page, *p; | |
34818 | + struct au_branch *br; | |
34819 | + struct super_block *h_sb; | |
34820 | + struct path path; | |
34821 | + aufs_bindex_t bend, bindex, bwr; | |
34822 | + | |
34823 | + br = NULL; | |
34824 | + bend = au_sbend(sb); | |
34825 | + bwr = -1; | |
34826 | + for (bindex = 0; bindex <= bend; bindex++) { | |
34827 | + br = au_sbr(sb, bindex); | |
34828 | + if (au_br_writable(br->br_perm) | |
86dc4139 | 34829 | + && !au_test_fs_bad_xino(au_br_sb(br))) { |
b752ccd1 AM |
34830 | + bwr = bindex; |
34831 | + break; | |
34832 | + } | |
34833 | + } | |
34834 | + | |
7f207e10 AM |
34835 | + if (bwr >= 0) { |
34836 | + file = ERR_PTR(-ENOMEM); | |
537831f9 | 34837 | + page = (void *)__get_free_page(GFP_NOFS); |
7f207e10 AM |
34838 | + if (unlikely(!page)) |
34839 | + goto out; | |
86dc4139 | 34840 | + path.mnt = au_br_mnt(br); |
7f207e10 AM |
34841 | + path.dentry = au_h_dptr(sb->s_root, bwr); |
34842 | + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME)); | |
34843 | + file = (void *)p; | |
34844 | + if (!IS_ERR(p)) { | |
34845 | + strcat(p, "/" AUFS_XINO_FNAME); | |
34846 | + AuDbg("%s\n", p); | |
34847 | + file = au_xino_create(sb, p, /*silent*/0); | |
34848 | + if (!IS_ERR(file)) | |
34849 | + au_xino_brid_set(sb, br->br_id); | |
34850 | + } | |
537831f9 | 34851 | + free_page((unsigned long)page); |
7f207e10 AM |
34852 | + } else { |
34853 | + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0); | |
34854 | + if (IS_ERR(file)) | |
34855 | + goto out; | |
2000de60 | 34856 | + h_sb = file->f_path.dentry->d_sb; |
7f207e10 AM |
34857 | + if (unlikely(au_test_fs_bad_xino(h_sb))) { |
34858 | + pr_err("xino doesn't support %s(%s)\n", | |
34859 | + AUFS_XINO_DEFPATH, au_sbtype(h_sb)); | |
34860 | + fput(file); | |
34861 | + file = ERR_PTR(-EINVAL); | |
34862 | + } | |
34863 | + if (!IS_ERR(file)) | |
34864 | + au_xino_brid_set(sb, -1); | |
34865 | + } | |
0c5527e5 | 34866 | + |
7f207e10 AM |
34867 | +out: |
34868 | + return file; | |
34869 | +} | |
34870 | + | |
34871 | +/* ---------------------------------------------------------------------- */ | |
34872 | + | |
34873 | +int au_xino_path(struct seq_file *seq, struct file *file) | |
34874 | +{ | |
34875 | + int err; | |
34876 | + | |
34877 | + err = au_seq_path(seq, &file->f_path); | |
34878 | + if (unlikely(err < 0)) | |
34879 | + goto out; | |
34880 | + | |
34881 | + err = 0; | |
34882 | +#define Deleted "\\040(deleted)" | |
34883 | + seq->count -= sizeof(Deleted) - 1; | |
34884 | + AuDebugOn(memcmp(seq->buf + seq->count, Deleted, | |
34885 | + sizeof(Deleted) - 1)); | |
34886 | +#undef Deleted | |
34887 | + | |
34888 | +out: | |
34889 | + return err; | |
34890 | +} | |
537831f9 AM |
34891 | diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h |
34892 | --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100 | |
5527c038 | 34893 | +++ linux/include/uapi/linux/aufs_type.h 2015-06-28 17:36:09.028407078 +0200 |
c1595e42 | 34894 | @@ -0,0 +1,419 @@ |
7f207e10 | 34895 | +/* |
2000de60 | 34896 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
7f207e10 AM |
34897 | + * |
34898 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34899 | + * it under the terms of the GNU General Public License as published by | |
34900 | + * the Free Software Foundation; either version 2 of the License, or | |
34901 | + * (at your option) any later version. | |
34902 | + * | |
34903 | + * This program is distributed in the hope that it will be useful, | |
34904 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34905 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34906 | + * GNU General Public License for more details. | |
34907 | + * | |
34908 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 34909 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
34910 | + */ |
34911 | + | |
34912 | +#ifndef __AUFS_TYPE_H__ | |
34913 | +#define __AUFS_TYPE_H__ | |
34914 | + | |
f6c5ef8b AM |
34915 | +#define AUFS_NAME "aufs" |
34916 | + | |
9dbd164d | 34917 | +#ifdef __KERNEL__ |
f6c5ef8b AM |
34918 | +/* |
34919 | + * define it before including all other headers. | |
34920 | + * sched.h may use pr_* macros before defining "current", so define the | |
34921 | + * no-current version first, and re-define later. | |
34922 | + */ | |
34923 | +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__ | |
34924 | +#include <linux/sched.h> | |
34925 | +#undef pr_fmt | |
a2a7ad62 AM |
34926 | +#define pr_fmt(fmt) \ |
34927 | + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \ | |
34928 | + (int)sizeof(current->comm), current->comm, current->pid | |
9dbd164d AM |
34929 | +#else |
34930 | +#include <stdint.h> | |
34931 | +#include <sys/types.h> | |
f6c5ef8b | 34932 | +#endif /* __KERNEL__ */ |
7f207e10 | 34933 | + |
f6c5ef8b AM |
34934 | +#include <linux/limits.h> |
34935 | + | |
5527c038 | 34936 | +#define AUFS_VERSION "4.x-rcN-20150622" |
7f207e10 AM |
34937 | + |
34938 | +/* todo? move this to linux-2.6.19/include/magic.h */ | |
34939 | +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's') | |
34940 | + | |
34941 | +/* ---------------------------------------------------------------------- */ | |
34942 | + | |
34943 | +#ifdef CONFIG_AUFS_BRANCH_MAX_127 | |
9dbd164d | 34944 | +typedef int8_t aufs_bindex_t; |
7f207e10 AM |
34945 | +#define AUFS_BRANCH_MAX 127 |
34946 | +#else | |
9dbd164d | 34947 | +typedef int16_t aufs_bindex_t; |
7f207e10 AM |
34948 | +#ifdef CONFIG_AUFS_BRANCH_MAX_511 |
34949 | +#define AUFS_BRANCH_MAX 511 | |
34950 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023) | |
34951 | +#define AUFS_BRANCH_MAX 1023 | |
34952 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767) | |
34953 | +#define AUFS_BRANCH_MAX 32767 | |
34954 | +#endif | |
34955 | +#endif | |
34956 | + | |
34957 | +#ifdef __KERNEL__ | |
34958 | +#ifndef AUFS_BRANCH_MAX | |
34959 | +#error unknown CONFIG_AUFS_BRANCH_MAX value | |
34960 | +#endif | |
34961 | +#endif /* __KERNEL__ */ | |
34962 | + | |
34963 | +/* ---------------------------------------------------------------------- */ | |
34964 | + | |
7f207e10 AM |
34965 | +#define AUFS_FSTYPE AUFS_NAME |
34966 | + | |
34967 | +#define AUFS_ROOT_INO 2 | |
34968 | +#define AUFS_FIRST_INO 11 | |
34969 | + | |
34970 | +#define AUFS_WH_PFX ".wh." | |
34971 | +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1) | |
34972 | +#define AUFS_WH_TMP_LEN 4 | |
86dc4139 | 34973 | +/* a limit for rmdir/rename a dir and copyup */ |
7f207e10 AM |
34974 | +#define AUFS_MAX_NAMELEN (NAME_MAX \ |
34975 | + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\ | |
34976 | + - 1 /* dot */\ | |
34977 | + - AUFS_WH_TMP_LEN) /* hex */ | |
34978 | +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino" | |
34979 | +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME | |
392086de AM |
34980 | +#define AUFS_XINO_DEF_SEC 30 /* seconds */ |
34981 | +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */ | |
7f207e10 AM |
34982 | +#define AUFS_DIRWH_DEF 3 |
34983 | +#define AUFS_RDCACHE_DEF 10 /* seconds */ | |
027c5e7a | 34984 | +#define AUFS_RDCACHE_MAX 3600 /* seconds */ |
7f207e10 AM |
34985 | +#define AUFS_RDBLK_DEF 512 /* bytes */ |
34986 | +#define AUFS_RDHASH_DEF 32 | |
34987 | +#define AUFS_WKQ_NAME AUFS_NAME "d" | |
027c5e7a AM |
34988 | +#define AUFS_MFS_DEF_SEC 30 /* seconds */ |
34989 | +#define AUFS_MFS_MAX_SEC 3600 /* seconds */ | |
076b876e | 34990 | +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */ |
86dc4139 | 34991 | +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */ |
7f207e10 AM |
34992 | + |
34993 | +/* pseudo-link maintenace under /proc */ | |
34994 | +#define AUFS_PLINK_MAINT_NAME "plink_maint" | |
34995 | +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME | |
34996 | +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME | |
34997 | + | |
34998 | +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */ | |
34999 | +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME | |
35000 | + | |
35001 | +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME | |
35002 | +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk" | |
35003 | +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph" | |
35004 | + | |
35005 | +/* doubly whiteouted */ | |
35006 | +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME | |
35007 | +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME | |
35008 | +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME | |
35009 | + | |
1e00d052 | 35010 | +/* branch permissions and attributes */ |
7f207e10 AM |
35011 | +#define AUFS_BRPERM_RW "rw" |
35012 | +#define AUFS_BRPERM_RO "ro" | |
35013 | +#define AUFS_BRPERM_RR "rr" | |
076b876e AM |
35014 | +#define AUFS_BRATTR_COO_REG "coo_reg" |
35015 | +#define AUFS_BRATTR_COO_ALL "coo_all" | |
35016 | +#define AUFS_BRATTR_FHSM "fhsm" | |
35017 | +#define AUFS_BRATTR_UNPIN "unpin" | |
c1595e42 JR |
35018 | +#define AUFS_BRATTR_ICEX "icex" |
35019 | +#define AUFS_BRATTR_ICEX_SEC "icexsec" | |
35020 | +#define AUFS_BRATTR_ICEX_SYS "icexsys" | |
35021 | +#define AUFS_BRATTR_ICEX_TR "icextr" | |
35022 | +#define AUFS_BRATTR_ICEX_USR "icexusr" | |
35023 | +#define AUFS_BRATTR_ICEX_OTH "icexoth" | |
1e00d052 AM |
35024 | +#define AUFS_BRRATTR_WH "wh" |
35025 | +#define AUFS_BRWATTR_NLWH "nolwh" | |
076b876e AM |
35026 | +#define AUFS_BRWATTR_MOO "moo" |
35027 | + | |
35028 | +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */ | |
35029 | +#define AuBrPerm_RO (1 << 1) /* readonly */ | |
35030 | +#define AuBrPerm_RR (1 << 2) /* natively readonly */ | |
35031 | +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR) | |
35032 | + | |
35033 | +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */ | |
35034 | +#define AuBrAttr_COO_ALL (1 << 4) | |
35035 | +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL) | |
35036 | + | |
35037 | +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */ | |
35038 | +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of | |
c1595e42 JR |
35039 | + branch. meaningless since |
35040 | + linux-3.18-rc1 */ | |
35041 | + | |
35042 | +/* ignore error in copying XATTR */ | |
35043 | +#define AuBrAttr_ICEX_SEC (1 << 7) | |
35044 | +#define AuBrAttr_ICEX_SYS (1 << 8) | |
35045 | +#define AuBrAttr_ICEX_TR (1 << 9) | |
35046 | +#define AuBrAttr_ICEX_USR (1 << 10) | |
35047 | +#define AuBrAttr_ICEX_OTH (1 << 11) | |
35048 | +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \ | |
35049 | + | AuBrAttr_ICEX_SYS \ | |
35050 | + | AuBrAttr_ICEX_TR \ | |
35051 | + | AuBrAttr_ICEX_USR \ | |
35052 | + | AuBrAttr_ICEX_OTH) | |
35053 | + | |
35054 | +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */ | |
076b876e AM |
35055 | +#define AuBrRAttr_Mask AuBrRAttr_WH |
35056 | + | |
c1595e42 JR |
35057 | +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */ |
35058 | +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */ | |
076b876e AM |
35059 | +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO) |
35060 | + | |
35061 | +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO) | |
35062 | + | |
c1595e42 | 35063 | +/* #warning test userspace */ |
076b876e AM |
35064 | +#ifdef __KERNEL__ |
35065 | +#ifndef CONFIG_AUFS_FHSM | |
35066 | +#undef AuBrAttr_FHSM | |
35067 | +#define AuBrAttr_FHSM 0 | |
35068 | +#endif | |
c1595e42 JR |
35069 | +#ifndef CONFIG_AUFS_XATTR |
35070 | +#undef AuBrAttr_ICEX | |
35071 | +#define AuBrAttr_ICEX 0 | |
35072 | +#undef AuBrAttr_ICEX_SEC | |
35073 | +#define AuBrAttr_ICEX_SEC 0 | |
35074 | +#undef AuBrAttr_ICEX_SYS | |
35075 | +#define AuBrAttr_ICEX_SYS 0 | |
35076 | +#undef AuBrAttr_ICEX_TR | |
35077 | +#define AuBrAttr_ICEX_TR 0 | |
35078 | +#undef AuBrAttr_ICEX_USR | |
35079 | +#define AuBrAttr_ICEX_USR 0 | |
35080 | +#undef AuBrAttr_ICEX_OTH | |
35081 | +#define AuBrAttr_ICEX_OTH 0 | |
35082 | +#endif | |
076b876e AM |
35083 | +#endif |
35084 | + | |
35085 | +/* the longest combination */ | |
c1595e42 JR |
35086 | +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */ |
35087 | +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \ | |
35088 | + "+" AUFS_BRATTR_COO_REG \ | |
35089 | + "+" AUFS_BRATTR_FHSM \ | |
35090 | + "+" AUFS_BRATTR_UNPIN \ | |
7e9cd9fe AM |
35091 | + "+" AUFS_BRATTR_ICEX_SEC \ |
35092 | + "+" AUFS_BRATTR_ICEX_SYS \ | |
35093 | + "+" AUFS_BRATTR_ICEX_USR \ | |
35094 | + "+" AUFS_BRATTR_ICEX_OTH \ | |
076b876e AM |
35095 | + "+" AUFS_BRWATTR_NLWH) |
35096 | + | |
35097 | +typedef struct { | |
35098 | + char a[AuBrPermStrSz]; | |
35099 | +} au_br_perm_str_t; | |
35100 | + | |
35101 | +static inline int au_br_writable(int brperm) | |
35102 | +{ | |
35103 | + return brperm & AuBrPerm_RW; | |
35104 | +} | |
35105 | + | |
35106 | +static inline int au_br_whable(int brperm) | |
35107 | +{ | |
35108 | + return brperm & (AuBrPerm_RW | AuBrRAttr_WH); | |
35109 | +} | |
35110 | + | |
35111 | +static inline int au_br_wh_linkable(int brperm) | |
35112 | +{ | |
35113 | + return !(brperm & AuBrWAttr_NoLinkWH); | |
35114 | +} | |
35115 | + | |
35116 | +static inline int au_br_cmoo(int brperm) | |
35117 | +{ | |
35118 | + return brperm & AuBrAttr_CMOO_Mask; | |
35119 | +} | |
35120 | + | |
35121 | +static inline int au_br_fhsm(int brperm) | |
35122 | +{ | |
35123 | + return brperm & AuBrAttr_FHSM; | |
35124 | +} | |
7f207e10 AM |
35125 | + |
35126 | +/* ---------------------------------------------------------------------- */ | |
35127 | + | |
35128 | +/* ioctl */ | |
35129 | +enum { | |
35130 | + /* readdir in userspace */ | |
35131 | + AuCtl_RDU, | |
35132 | + AuCtl_RDU_INO, | |
35133 | + | |
076b876e AM |
35134 | + AuCtl_WBR_FD, /* pathconf wrapper */ |
35135 | + AuCtl_IBUSY, /* busy inode */ | |
35136 | + AuCtl_MVDOWN, /* move-down */ | |
35137 | + AuCtl_BR, /* info about branches */ | |
35138 | + AuCtl_FHSM_FD /* connection for fhsm */ | |
7f207e10 AM |
35139 | +}; |
35140 | + | |
35141 | +/* borrowed from linux/include/linux/kernel.h */ | |
35142 | +#ifndef ALIGN | |
35143 | +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) | |
35144 | +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | |
35145 | +#endif | |
35146 | + | |
35147 | +/* borrowed from linux/include/linux/compiler-gcc3.h */ | |
35148 | +#ifndef __aligned | |
35149 | +#define __aligned(x) __attribute__((aligned(x))) | |
53392da6 AM |
35150 | +#endif |
35151 | + | |
35152 | +#ifdef __KERNEL__ | |
35153 | +#ifndef __packed | |
7f207e10 AM |
35154 | +#define __packed __attribute__((packed)) |
35155 | +#endif | |
53392da6 | 35156 | +#endif |
7f207e10 AM |
35157 | + |
35158 | +struct au_rdu_cookie { | |
9dbd164d AM |
35159 | + uint64_t h_pos; |
35160 | + int16_t bindex; | |
35161 | + uint8_t flags; | |
35162 | + uint8_t pad; | |
35163 | + uint32_t generation; | |
7f207e10 AM |
35164 | +} __aligned(8); |
35165 | + | |
35166 | +struct au_rdu_ent { | |
9dbd164d AM |
35167 | + uint64_t ino; |
35168 | + int16_t bindex; | |
35169 | + uint8_t type; | |
35170 | + uint8_t nlen; | |
35171 | + uint8_t wh; | |
7f207e10 AM |
35172 | + char name[0]; |
35173 | +} __aligned(8); | |
35174 | + | |
35175 | +static inline int au_rdu_len(int nlen) | |
35176 | +{ | |
35177 | + /* include the terminating NULL */ | |
35178 | + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1, | |
9dbd164d | 35179 | + sizeof(uint64_t)); |
7f207e10 AM |
35180 | +} |
35181 | + | |
35182 | +union au_rdu_ent_ul { | |
35183 | + struct au_rdu_ent __user *e; | |
9dbd164d | 35184 | + uint64_t ul; |
7f207e10 AM |
35185 | +}; |
35186 | + | |
35187 | +enum { | |
35188 | + AufsCtlRduV_SZ, | |
35189 | + AufsCtlRduV_End | |
35190 | +}; | |
35191 | + | |
35192 | +struct aufs_rdu { | |
35193 | + /* input */ | |
35194 | + union { | |
9dbd164d AM |
35195 | + uint64_t sz; /* AuCtl_RDU */ |
35196 | + uint64_t nent; /* AuCtl_RDU_INO */ | |
7f207e10 AM |
35197 | + }; |
35198 | + union au_rdu_ent_ul ent; | |
9dbd164d | 35199 | + uint16_t verify[AufsCtlRduV_End]; |
7f207e10 AM |
35200 | + |
35201 | + /* input/output */ | |
9dbd164d | 35202 | + uint32_t blk; |
7f207e10 AM |
35203 | + |
35204 | + /* output */ | |
35205 | + union au_rdu_ent_ul tail; | |
35206 | + /* number of entries which were added in a single call */ | |
9dbd164d AM |
35207 | + uint64_t rent; |
35208 | + uint8_t full; | |
35209 | + uint8_t shwh; | |
7f207e10 AM |
35210 | + |
35211 | + struct au_rdu_cookie cookie; | |
35212 | +} __aligned(8); | |
35213 | + | |
1e00d052 AM |
35214 | +/* ---------------------------------------------------------------------- */ |
35215 | + | |
35216 | +struct aufs_wbr_fd { | |
9dbd164d AM |
35217 | + uint32_t oflags; |
35218 | + int16_t brid; | |
1e00d052 AM |
35219 | +} __aligned(8); |
35220 | + | |
35221 | +/* ---------------------------------------------------------------------- */ | |
35222 | + | |
027c5e7a | 35223 | +struct aufs_ibusy { |
9dbd164d AM |
35224 | + uint64_t ino, h_ino; |
35225 | + int16_t bindex; | |
027c5e7a AM |
35226 | +} __aligned(8); |
35227 | + | |
1e00d052 AM |
35228 | +/* ---------------------------------------------------------------------- */ |
35229 | + | |
392086de AM |
35230 | +/* error code for move-down */ |
35231 | +/* the actual message strings are implemented in aufs-util.git */ | |
35232 | +enum { | |
35233 | + EAU_MVDOWN_OPAQUE = 1, | |
35234 | + EAU_MVDOWN_WHITEOUT, | |
35235 | + EAU_MVDOWN_UPPER, | |
35236 | + EAU_MVDOWN_BOTTOM, | |
35237 | + EAU_MVDOWN_NOUPPER, | |
35238 | + EAU_MVDOWN_NOLOWERBR, | |
35239 | + EAU_Last | |
35240 | +}; | |
35241 | + | |
c2b27bf2 | 35242 | +/* flags for move-down */ |
392086de AM |
35243 | +#define AUFS_MVDOWN_DMSG 1 |
35244 | +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */ | |
35245 | +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */ | |
35246 | +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */ | |
35247 | +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */ | |
35248 | +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */ | |
35249 | +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */ | |
35250 | +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */ | |
35251 | +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */ | |
076b876e AM |
35252 | +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */ |
35253 | +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */ | |
35254 | +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */ | |
35255 | +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */ | |
c2b27bf2 | 35256 | + |
076b876e | 35257 | +/* index for move-down */ |
392086de AM |
35258 | +enum { |
35259 | + AUFS_MVDOWN_UPPER, | |
35260 | + AUFS_MVDOWN_LOWER, | |
35261 | + AUFS_MVDOWN_NARRAY | |
35262 | +}; | |
35263 | + | |
076b876e AM |
35264 | +/* |
35265 | + * additional info of move-down | |
35266 | + * number of free blocks and inodes. | |
35267 | + * subset of struct kstatfs, but smaller and always 64bit. | |
35268 | + */ | |
35269 | +struct aufs_stfs { | |
35270 | + uint64_t f_blocks; | |
35271 | + uint64_t f_bavail; | |
35272 | + uint64_t f_files; | |
35273 | + uint64_t f_ffree; | |
35274 | +}; | |
35275 | + | |
35276 | +struct aufs_stbr { | |
35277 | + int16_t brid; /* optional input */ | |
35278 | + int16_t bindex; /* output */ | |
35279 | + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */ | |
35280 | +} __aligned(8); | |
35281 | + | |
c2b27bf2 | 35282 | +struct aufs_mvdown { |
076b876e AM |
35283 | + uint32_t flags; /* input/output */ |
35284 | + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */ | |
35285 | + int8_t au_errno; /* output */ | |
35286 | +} __aligned(8); | |
35287 | + | |
35288 | +/* ---------------------------------------------------------------------- */ | |
35289 | + | |
35290 | +union aufs_brinfo { | |
35291 | + /* PATH_MAX may differ between kernel-space and user-space */ | |
35292 | + char _spacer[4096]; | |
392086de | 35293 | + struct { |
076b876e AM |
35294 | + int16_t id; |
35295 | + int perm; | |
35296 | + char path[0]; | |
35297 | + }; | |
c2b27bf2 AM |
35298 | +} __aligned(8); |
35299 | + | |
35300 | +/* ---------------------------------------------------------------------- */ | |
35301 | + | |
7f207e10 AM |
35302 | +#define AuCtlType 'A' |
35303 | +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu) | |
35304 | +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu) | |
1e00d052 AM |
35305 | +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \ |
35306 | + struct aufs_wbr_fd) | |
027c5e7a | 35307 | +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy) |
392086de AM |
35308 | +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \ |
35309 | + struct aufs_mvdown) | |
076b876e AM |
35310 | +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo) |
35311 | +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int) | |
7f207e10 AM |
35312 | + |
35313 | +#endif /* __AUFS_TYPE_H__ */ | |
5527c038 JR |
35314 | aufs4.x-rcN loopback patch |
35315 | ||
35316 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c | |
35317 | index 0160952..866f8e2 100644 | |
35318 | --- a/drivers/block/loop.c | |
35319 | +++ b/drivers/block/loop.c | |
35320 | @@ -419,7 +419,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) | |
35321 | } | |
35322 | ||
35323 | struct switch_request { | |
35324 | - struct file *file; | |
35325 | + struct file *file, *virt_file; | |
35326 | struct completion wait; | |
35327 | }; | |
35328 | ||
35329 | @@ -439,6 +439,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) | |
35330 | mapping = file->f_mapping; | |
35331 | mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); | |
35332 | lo->lo_backing_file = file; | |
35333 | + lo->lo_backing_virt_file = p->virt_file; | |
35334 | lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ? | |
35335 | mapping->host->i_bdev->bd_block_size : PAGE_SIZE; | |
35336 | lo->old_gfp_mask = mapping_gfp_mask(mapping); | |
35337 | @@ -450,11 +451,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) | |
35338 | * First it needs to flush existing IO, it does this by sending a magic | |
35339 | * BIO down the pipe. The completion of this BIO does the actual switch. | |
35340 | */ | |
35341 | -static int loop_switch(struct loop_device *lo, struct file *file) | |
35342 | +static int loop_switch(struct loop_device *lo, struct file *file, | |
35343 | + struct file *virt_file) | |
35344 | { | |
35345 | struct switch_request w; | |
35346 | ||
35347 | w.file = file; | |
35348 | + w.virt_file = virt_file; | |
35349 | ||
35350 | /* freeze queue and wait for completion of scheduled requests */ | |
35351 | blk_mq_freeze_queue(lo->lo_queue); | |
35352 | @@ -473,7 +476,16 @@ static int loop_switch(struct loop_device *lo, struct file *file) | |
35353 | */ | |
35354 | static int loop_flush(struct loop_device *lo) | |
35355 | { | |
35356 | - return loop_switch(lo, NULL); | |
35357 | + return loop_switch(lo, NULL, NULL); | |
35358 | +} | |
35359 | + | |
35360 | +static struct file *loop_real_file(struct file *file) | |
35361 | +{ | |
35362 | + struct file *f = NULL; | |
35363 | + | |
35364 | + if (file->f_path.dentry->d_sb->s_op->real_loop) | |
35365 | + f = file->f_path.dentry->d_sb->s_op->real_loop(file); | |
35366 | + return f; | |
35367 | } | |
35368 | ||
35369 | /* | |
35370 | @@ -488,6 +500,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, | |
35371 | unsigned int arg) | |
35372 | { | |
35373 | struct file *file, *old_file; | |
35374 | + struct file *f, *virt_file = NULL, *old_virt_file; | |
35375 | struct inode *inode; | |
35376 | int error; | |
35377 | ||
35378 | @@ -504,9 +517,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, | |
35379 | file = fget(arg); | |
35380 | if (!file) | |
35381 | goto out; | |
35382 | + f = loop_real_file(file); | |
35383 | + if (f) { | |
35384 | + virt_file = file; | |
35385 | + file = f; | |
35386 | + get_file(file); | |
35387 | + } | |
35388 | ||
35389 | inode = file->f_mapping->host; | |
35390 | old_file = lo->lo_backing_file; | |
35391 | + old_virt_file = lo->lo_backing_virt_file; | |
35392 | ||
35393 | error = -EINVAL; | |
35394 | ||
35395 | @@ -518,17 +538,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, | |
35396 | goto out_putf; | |
35397 | ||
35398 | /* and ... switch */ | |
35399 | - error = loop_switch(lo, file); | |
35400 | + error = loop_switch(lo, file, virt_file); | |
35401 | if (error) | |
35402 | goto out_putf; | |
35403 | ||
35404 | fput(old_file); | |
35405 | + if (old_virt_file) | |
35406 | + fput(old_virt_file); | |
35407 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) | |
35408 | ioctl_by_bdev(bdev, BLKRRPART, 0); | |
35409 | return 0; | |
35410 | ||
35411 | out_putf: | |
35412 | fput(file); | |
35413 | + if (virt_file) | |
35414 | + fput(virt_file); | |
35415 | out: | |
35416 | return error; | |
35417 | } | |
35418 | @@ -689,7 +713,7 @@ static void loop_config_discard(struct loop_device *lo) | |
35419 | static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |
35420 | struct block_device *bdev, unsigned int arg) | |
35421 | { | |
35422 | - struct file *file, *f; | |
35423 | + struct file *file, *f, *virt_file = NULL; | |
35424 | struct inode *inode; | |
35425 | struct address_space *mapping; | |
35426 | unsigned lo_blocksize; | |
35427 | @@ -704,6 +728,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |
35428 | file = fget(arg); | |
35429 | if (!file) | |
35430 | goto out; | |
35431 | + f = loop_real_file(file); | |
35432 | + if (f) { | |
35433 | + virt_file = file; | |
35434 | + file = f; | |
35435 | + get_file(file); | |
35436 | + } | |
35437 | ||
35438 | error = -EBUSY; | |
35439 | if (lo->lo_state != Lo_unbound) | |
35440 | @@ -752,6 +782,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |
35441 | lo->lo_device = bdev; | |
35442 | lo->lo_flags = lo_flags; | |
35443 | lo->lo_backing_file = file; | |
35444 | + lo->lo_backing_virt_file = virt_file; | |
35445 | lo->transfer = NULL; | |
35446 | lo->ioctl = NULL; | |
35447 | lo->lo_sizelimit = 0; | |
35448 | @@ -783,6 +814,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |
35449 | ||
35450 | out_putf: | |
35451 | fput(file); | |
35452 | + if (virt_file) | |
35453 | + fput(virt_file); | |
35454 | out: | |
35455 | /* This is safe: open() is still holding a reference. */ | |
35456 | module_put(THIS_MODULE); | |
35457 | @@ -829,6 +862,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, | |
35458 | static int loop_clr_fd(struct loop_device *lo) | |
35459 | { | |
35460 | struct file *filp = lo->lo_backing_file; | |
35461 | + struct file *virt_filp = lo->lo_backing_virt_file; | |
35462 | gfp_t gfp = lo->old_gfp_mask; | |
35463 | struct block_device *bdev = lo->lo_device; | |
35464 | ||
35465 | @@ -857,6 +891,7 @@ static int loop_clr_fd(struct loop_device *lo) | |
35466 | spin_lock_irq(&lo->lo_lock); | |
35467 | lo->lo_state = Lo_rundown; | |
35468 | lo->lo_backing_file = NULL; | |
35469 | + lo->lo_backing_virt_file = NULL; | |
35470 | spin_unlock_irq(&lo->lo_lock); | |
35471 | ||
35472 | loop_release_xfer(lo); | |
35473 | @@ -898,6 +933,8 @@ static int loop_clr_fd(struct loop_device *lo) | |
35474 | * bd_mutex which is usually taken before lo_ctl_mutex. | |
35475 | */ | |
35476 | fput(filp); | |
35477 | + if (virt_filp) | |
35478 | + fput(virt_filp); | |
35479 | return 0; | |
35480 | } | |
35481 | ||
35482 | diff --git a/drivers/block/loop.h b/drivers/block/loop.h | |
35483 | index 301c27f..df84aa0 100644 | |
35484 | --- a/drivers/block/loop.h | |
35485 | +++ b/drivers/block/loop.h | |
35486 | @@ -46,7 +46,7 @@ struct loop_device { | |
35487 | int (*ioctl)(struct loop_device *, int cmd, | |
35488 | unsigned long arg); | |
35489 | ||
35490 | - struct file * lo_backing_file; | |
35491 | + struct file * lo_backing_file, *lo_backing_virt_file; | |
35492 | struct block_device *lo_device; | |
35493 | unsigned lo_blocksize; | |
35494 | void *key_data; | |
35495 | diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c | |
35496 | index 91c2ce7..d4ee5a7 100644 | |
35497 | --- a/fs/aufs/f_op.c | |
35498 | +++ b/fs/aufs/f_op.c | |
35499 | @@ -389,7 +389,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, | |
35500 | if (IS_ERR(h_file)) | |
35501 | goto out; | |
35502 | ||
35503 | - if (au_test_loopback_kthread()) { | |
35504 | + if (0 && au_test_loopback_kthread()) { | |
35505 | au_warn_loopback(h_file->f_path.dentry->d_sb); | |
35506 | if (file->f_mapping != h_file->f_mapping) { | |
35507 | file->f_mapping = h_file->f_mapping; | |
35508 | diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c | |
35509 | index 69f7e96..7941063 100644 | |
35510 | --- a/fs/aufs/loop.c | |
35511 | +++ b/fs/aufs/loop.c | |
35512 | @@ -130,3 +130,19 @@ void au_loopback_fin(void) | |
35513 | symbol_put(loop_backing_file); | |
35514 | kfree(au_warn_loopback_array); | |
35515 | } | |
35516 | + | |
35517 | +/* ---------------------------------------------------------------------- */ | |
35518 | + | |
35519 | +/* support the loopback block device insude aufs */ | |
35520 | + | |
35521 | +struct file *aufs_real_loop(struct file *file) | |
35522 | +{ | |
35523 | + struct file *f; | |
35524 | + | |
35525 | + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb)); | |
35526 | + fi_read_lock(file); | |
35527 | + f = au_hf_top(file); | |
35528 | + fi_read_unlock(file); | |
35529 | + AuDebugOn(!f); | |
35530 | + return f; | |
35531 | +} | |
35532 | diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h | |
35533 | index 6d9864d..3322557 100644 | |
35534 | --- a/fs/aufs/loop.h | |
35535 | +++ b/fs/aufs/loop.h | |
35536 | @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb); | |
35537 | ||
35538 | int au_loopback_init(void); | |
35539 | void au_loopback_fin(void); | |
35540 | + | |
35541 | +struct file *aufs_real_loop(struct file *file); | |
35542 | #else | |
35543 | +AuStub(struct file *, loop_backing_file, return NULL) | |
35544 | + | |
35545 | AuStubInt0(au_test_loopback_overlap, struct super_block *sb, | |
35546 | struct dentry *h_adding) | |
35547 | AuStubInt0(au_test_loopback_kthread, void) | |
35548 | @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb) | |
35549 | ||
35550 | AuStubInt0(au_loopback_init, void) | |
35551 | AuStubVoid(au_loopback_fin, void) | |
35552 | + | |
35553 | +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file) | |
35554 | #endif /* BLK_DEV_LOOP */ | |
35555 | ||
35556 | #endif /* __KERNEL__ */ | |
35557 | diff --git a/fs/aufs/super.c b/fs/aufs/super.c | |
35558 | index ee5780d..da35759 100644 | |
35559 | --- a/fs/aufs/super.c | |
35560 | +++ b/fs/aufs/super.c | |
35561 | @@ -807,7 +807,10 @@ static const struct super_operations aufs_sop = { | |
35562 | .statfs = aufs_statfs, | |
35563 | .put_super = aufs_put_super, | |
35564 | .sync_fs = aufs_sync_fs, | |
35565 | - .remount_fs = aufs_remount_fs | |
35566 | + .remount_fs = aufs_remount_fs, | |
35567 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
35568 | + .real_loop = aufs_real_loop | |
35569 | +#endif | |
35570 | }; | |
35571 | ||
35572 | /* ---------------------------------------------------------------------- */ | |
35573 | diff --git a/include/linux/fs.h b/include/linux/fs.h | |
35574 | index 3229f97..f63cc0d 100644 | |
35575 | --- a/include/linux/fs.h | |
35576 | +++ b/include/linux/fs.h | |
35577 | @@ -1696,6 +1696,10 @@ struct super_operations { | |
35578 | struct shrink_control *); | |
35579 | long (*free_cached_objects)(struct super_block *, | |
35580 | struct shrink_control *); | |
35581 | +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE) | |
35582 | + /* and aufs */ | |
35583 | + struct file *(*real_loop)(struct file *); | |
35584 | +#endif | |
35585 | }; | |
35586 | ||
35587 | /* |