]>
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 | |
c2c0f25c | 16 | index cb20e4b..dd81418 100644 |
7f207e10 AM |
17 | --- a/fs/Makefile |
18 | +++ b/fs/Makefile | |
c2c0f25c | 19 | @@ -126,3 +126,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 |
c2c0f25c | 25 | index 1ff9942..31efc0a 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 |
c2c0f25c | 39 | index 8133cef..04beb19 100644 |
c1595e42 JR |
40 | --- a/MAINTAINERS |
41 | +++ b/MAINTAINERS | |
c2c0f25c | 42 | @@ -1939,6 +1939,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 |
c2c0f25c | 63 | index f7a4c9d..23103ad 100644 |
392086de AM |
64 | --- a/drivers/block/loop.c |
65 | +++ b/drivers/block/loop.c | |
c2c0f25c | 66 | @@ -560,6 +560,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 |
c2c0f25c | 92 | index 7a3f3e5..0b40298 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 |
c2c0f25c | 138 | index 5fc1e50..5f8385a 100644 |
7f207e10 AM |
139 | --- a/fs/splice.c |
140 | +++ b/fs/splice.c | |
c2c0f25c | 141 | @@ -1102,8 +1102,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); | |
c2c0f25c | 152 | @@ -1119,9 +1119,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 | 177 | diff --git a/include/linux/fs.h b/include/linux/fs.h |
c2c0f25c | 178 | index a0653e5..86080ea 100644 |
5527c038 JR |
179 | --- a/include/linux/fs.h |
180 | +++ b/include/linux/fs.h | |
c2c0f25c | 181 | @@ -1661,6 +1661,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, |
5527c038 JR |
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 | |
c2c0f25c | 212 | index 1cf7a53..076aff86 100644 |
fb47a38f JR |
213 | --- a/fs/buffer.c |
214 | +++ b/fs/buffer.c | |
c2c0f25c | 215 | @@ -2473,7 +2473,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 |
c2c0f25c | 225 | index 87782e8..b287e64 100644 |
c1595e42 JR |
226 | --- a/fs/proc/base.c |
227 | +++ b/fs/proc/base.c | |
c2c0f25c | 228 | @@ -1934,7 +1934,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 |
c2c0f25c | 238 | index f8595e8..cb8eda0 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 | |
c2c0f25c | 254 | index ca1e091..8940e47 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 |
c2c0f25c | 279 | index e0d64c9..7aa92db 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 | |
c2c0f25c | 295 | index 2e872f9..2494ed2 100644 |
fb47a38f JR |
296 | --- a/include/linux/mm.h |
297 | +++ b/include/linux/mm.h | |
c2c0f25c | 298 | @@ -1173,6 +1173,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 | |
c2c0f25c | 328 | index 0038ac7..409940d 100644 |
fb47a38f JR |
329 | --- a/include/linux/mm_types.h |
330 | +++ b/include/linux/mm_types.h | |
c2c0f25c | 331 | @@ -259,6 +259,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 | |
c2c0f25c | 339 | @@ -323,6 +324,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 | |
c2c0f25c | 348 | index 1bfefc6..a86bd7f 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 |
c2c0f25c | 374 | index 1283fc8..128f18f 100644 |
fb47a38f JR |
375 | --- a/mm/filemap.c |
376 | +++ b/mm/filemap.c | |
c2c0f25c | 377 | @@ -2089,7 +2089,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/memory.c b/mm/memory.c |
c2c0f25c | 387 | index a84fbb7..13973d2 100644 |
fb47a38f JR |
388 | --- a/mm/memory.c |
389 | +++ b/mm/memory.c | |
5527c038 | 390 | @@ -2034,7 +2034,7 @@ static inline int wp_page_reuse(struct mm_struct *mm, |
fb47a38f | 391 | } |
7e9cd9fe | 392 | |
b912730e AM |
393 | if (!page_mkwrite) |
394 | - file_update_time(vma->vm_file); | |
395 | + vma_file_update_time(vma); | |
396 | } | |
397 | ||
398 | return VM_FAULT_WRITE; | |
fb47a38f | 399 | diff --git a/mm/mmap.c b/mm/mmap.c |
c2c0f25c | 400 | index aa632ad..3ff75d3 100644 |
fb47a38f JR |
401 | --- a/mm/mmap.c |
402 | +++ b/mm/mmap.c | |
7e9cd9fe | 403 | @@ -274,7 +274,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma) |
fb47a38f JR |
404 | if (vma->vm_ops && vma->vm_ops->close) |
405 | vma->vm_ops->close(vma); | |
406 | if (vma->vm_file) | |
407 | - fput(vma->vm_file); | |
408 | + vma_fput(vma); | |
409 | mpol_put(vma_policy(vma)); | |
410 | kmem_cache_free(vm_area_cachep, vma); | |
411 | return next; | |
7e9cd9fe | 412 | @@ -886,7 +886,7 @@ again: remove_next = 1 + (end > next->vm_end); |
fb47a38f JR |
413 | if (remove_next) { |
414 | if (file) { | |
415 | uprobe_munmap(next, next->vm_start, next->vm_end); | |
416 | - fput(file); | |
417 | + vma_fput(vma); | |
418 | } | |
419 | if (next->anon_vma) | |
420 | anon_vma_merge(vma, next); | |
7e9cd9fe | 421 | @@ -1671,8 +1671,8 @@ out: |
35939ee7 JR |
422 | return addr; |
423 | ||
fb47a38f | 424 | unmap_and_free_vma: |
fb47a38f JR |
425 | + vma_fput(vma); |
426 | vma->vm_file = NULL; | |
427 | - fput(file); | |
428 | ||
429 | /* Undo any partial mapping done by a device driver. */ | |
430 | unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); | |
7e9cd9fe | 431 | @@ -2473,7 +2473,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
432 | goto out_free_mpol; |
433 | ||
434 | if (new->vm_file) | |
435 | - get_file(new->vm_file); | |
436 | + vma_get_file(new); | |
437 | ||
438 | if (new->vm_ops && new->vm_ops->open) | |
439 | new->vm_ops->open(new); | |
7e9cd9fe | 440 | @@ -2492,7 +2492,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
441 | if (new->vm_ops && new->vm_ops->close) |
442 | new->vm_ops->close(new); | |
443 | if (new->vm_file) | |
444 | - fput(new->vm_file); | |
445 | + vma_fput(new); | |
446 | unlink_anon_vmas(new); | |
447 | out_free_mpol: | |
448 | mpol_put(vma_policy(new)); | |
7e9cd9fe AM |
449 | @@ -2635,7 +2635,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
450 | struct vm_area_struct *vma; | |
451 | unsigned long populate = 0; | |
452 | unsigned long ret = -EINVAL; | |
453 | - struct file *file; | |
454 | ||
455 | pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. " | |
456 | "See Documentation/vm/remap_file_pages.txt.\n", | |
457 | @@ -2679,10 +2678,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, | |
458 | munlock_vma_pages_range(vma, start, start + size); | |
459 | } | |
460 | ||
461 | - file = get_file(vma->vm_file); | |
462 | + vma_get_file(vma); | |
463 | ret = do_mmap_pgoff(vma->vm_file, start, size, | |
464 | prot, flags, pgoff, &populate); | |
465 | - fput(file); | |
466 | + vma_fput(vma); | |
467 | out: | |
468 | up_write(&mm->mmap_sem); | |
469 | if (populate) | |
5527c038 | 470 | @@ -2949,7 +2948,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, |
fb47a38f JR |
471 | if (anon_vma_clone(new_vma, vma)) |
472 | goto out_free_mempol; | |
473 | if (new_vma->vm_file) | |
474 | - get_file(new_vma->vm_file); | |
475 | + vma_get_file(new_vma); | |
476 | if (new_vma->vm_ops && new_vma->vm_ops->open) | |
477 | new_vma->vm_ops->open(new_vma); | |
478 | vma_link(mm, new_vma, prev, rb_link, rb_parent); | |
fb47a38f | 479 | diff --git a/mm/nommu.c b/mm/nommu.c |
c2c0f25c | 480 | index 58ea364..f937b7e 100644 |
fb47a38f JR |
481 | --- a/mm/nommu.c |
482 | +++ b/mm/nommu.c | |
c2c0f25c | 483 | @@ -671,7 +671,7 @@ static void __put_nommu_region(struct vm_region *region) |
fb47a38f JR |
484 | up_write(&nommu_region_sem); |
485 | ||
486 | if (region->vm_file) | |
487 | - fput(region->vm_file); | |
488 | + vmr_fput(region); | |
489 | ||
490 | /* IO memory and memory shared directly out of the pagecache | |
491 | * from ramfs/tmpfs mustn't be released here */ | |
c2c0f25c | 492 | @@ -829,7 +829,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) |
fb47a38f JR |
493 | if (vma->vm_ops && vma->vm_ops->close) |
494 | vma->vm_ops->close(vma); | |
495 | if (vma->vm_file) | |
496 | - fput(vma->vm_file); | |
497 | + vma_fput(vma); | |
498 | put_nommu_region(vma->vm_region); | |
499 | kmem_cache_free(vm_area_cachep, vma); | |
500 | } | |
c2c0f25c | 501 | @@ -1354,7 +1354,7 @@ unsigned long do_mmap_pgoff(struct file *file, |
fb47a38f JR |
502 | goto error_just_free; |
503 | } | |
504 | } | |
505 | - fput(region->vm_file); | |
506 | + vmr_fput(region); | |
507 | kmem_cache_free(vm_region_jar, region); | |
508 | region = pregion; | |
509 | result = start; | |
c2c0f25c | 510 | @@ -1429,10 +1429,10 @@ error_just_free: |
fb47a38f JR |
511 | up_write(&nommu_region_sem); |
512 | error: | |
513 | if (region->vm_file) | |
514 | - fput(region->vm_file); | |
515 | + vmr_fput(region); | |
516 | kmem_cache_free(vm_region_jar, region); | |
517 | if (vma->vm_file) | |
518 | - fput(vma->vm_file); | |
519 | + vma_fput(vma); | |
520 | kmem_cache_free(vm_area_cachep, vma); | |
fb47a38f | 521 | return ret; |
c2c0f25c | 522 | |
076b876e AM |
523 | diff --git a/mm/prfile.c b/mm/prfile.c |
524 | new file mode 100644 | |
c2c0f25c | 525 | index 0000000..b323b8a |
076b876e AM |
526 | --- /dev/null |
527 | +++ b/mm/prfile.c | |
528 | @@ -0,0 +1,86 @@ | |
529 | +/* | |
530 | + * Mainly for aufs which mmap(2) diffrent file and wants to print different path | |
531 | + * in /proc/PID/maps. | |
532 | + * Call these functions via macros defined in linux/mm.h. | |
533 | + * | |
534 | + * See Documentation/filesystems/aufs/design/06mmap.txt | |
535 | + * | |
536 | + * Copyright (c) 2014 Junjro R. Okajima | |
537 | + * Copyright (c) 2014 Ian Campbell | |
538 | + */ | |
539 | + | |
540 | +#include <linux/mm.h> | |
541 | +#include <linux/file.h> | |
542 | +#include <linux/fs.h> | |
543 | + | |
544 | +/* #define PRFILE_TRACE */ | |
545 | +static inline void prfile_trace(struct file *f, struct file *pr, | |
546 | + const char func[], int line, const char func2[]) | |
547 | +{ | |
548 | +#ifdef PRFILE_TRACE | |
549 | + if (pr) | |
c2c0f25c | 550 | + pr_info("%s:%d: %s, %s\n", func, line, func2, |
7e9cd9fe | 551 | + f ? (char *)f->f_path.dentry->d_name.name : "(null)"); |
076b876e AM |
552 | +#endif |
553 | +} | |
554 | + | |
076b876e AM |
555 | +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[], |
556 | + int line) | |
557 | +{ | |
558 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
559 | + | |
560 | + prfile_trace(f, pr, func, line, __func__); | |
561 | + file_update_time(f); | |
562 | + if (f && pr) | |
563 | + file_update_time(pr); | |
564 | +} | |
565 | + | |
566 | +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[], | |
567 | + int line) | |
568 | +{ | |
569 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
570 | + | |
571 | + prfile_trace(f, pr, func, line, __func__); | |
572 | + return (f && pr) ? pr : f; | |
573 | +} | |
574 | + | |
575 | +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line) | |
576 | +{ | |
577 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
578 | + | |
579 | + prfile_trace(f, pr, func, line, __func__); | |
580 | + get_file(f); | |
581 | + if (f && pr) | |
582 | + get_file(pr); | |
583 | +} | |
584 | + | |
585 | +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line) | |
586 | +{ | |
587 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
588 | + | |
589 | + prfile_trace(f, pr, func, line, __func__); | |
590 | + fput(f); | |
591 | + if (f && pr) | |
592 | + fput(pr); | |
593 | +} | |
b912730e AM |
594 | + |
595 | +#ifndef CONFIG_MMU | |
076b876e AM |
596 | +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[], |
597 | + int line) | |
598 | +{ | |
599 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
600 | + | |
601 | + prfile_trace(f, pr, func, line, __func__); | |
602 | + return (f && pr) ? pr : f; | |
603 | +} | |
604 | + | |
605 | +void vmr_do_fput(struct vm_region *region, const char func[], int line) | |
606 | +{ | |
607 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
608 | + | |
609 | + prfile_trace(f, pr, func, line, __func__); | |
610 | + fput(f); | |
611 | + if (f && pr) | |
612 | + fput(pr); | |
613 | +} | |
b912730e | 614 | +#endif /* !CONFIG_MMU */ |
5527c038 | 615 | aufs4.x-rcN standalone patch |
7f207e10 | 616 | |
c1595e42 | 617 | diff --git a/fs/dcache.c b/fs/dcache.c |
c2c0f25c | 618 | index 0b40298..4844e61 100644 |
c1595e42 JR |
619 | --- a/fs/dcache.c |
620 | +++ b/fs/dcache.c | |
5527c038 | 621 | @@ -1269,6 +1269,7 @@ rename_retry: |
c1595e42 JR |
622 | seq = 1; |
623 | goto again; | |
624 | } | |
625 | +EXPORT_SYMBOL(d_walk); | |
626 | ||
627 | /* | |
628 | * Search for at least 1 mount point in the dentry's subdirs. | |
b912730e | 629 | diff --git a/fs/file_table.c b/fs/file_table.c |
c2c0f25c | 630 | index 7f9d407..8c9ec1d 100644 |
b912730e AM |
631 | --- a/fs/file_table.c |
632 | +++ b/fs/file_table.c | |
c2c0f25c | 633 | @@ -146,6 +146,7 @@ over: |
b912730e AM |
634 | } |
635 | return ERR_PTR(-ENFILE); | |
636 | } | |
637 | +EXPORT_SYMBOL(get_empty_filp); | |
638 | ||
639 | /** | |
640 | * alloc_file - allocate and initialize a 'struct file' | |
c2c0f25c | 641 | @@ -307,6 +308,7 @@ void put_filp(struct file *file) |
b912730e AM |
642 | file_free(file); |
643 | } | |
644 | } | |
645 | +EXPORT_SYMBOL(put_filp); | |
646 | ||
647 | void __init files_init(unsigned long mempages) | |
648 | { | |
1e00d052 | 649 | diff --git a/fs/inode.c b/fs/inode.c |
c2c0f25c | 650 | index d30640f..1ecc715 100644 |
1e00d052 AM |
651 | --- a/fs/inode.c |
652 | +++ b/fs/inode.c | |
7e9cd9fe | 653 | @@ -58,6 +58,7 @@ static struct hlist_head *inode_hashtable __read_mostly; |
4b3da204 | 654 | static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); |
2cbb1c4b JR |
655 | |
656 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock); | |
2cbb1c4b | 657 | +EXPORT_SYMBOL(inode_sb_list_lock); |
7f207e10 AM |
658 | |
659 | /* | |
4b3da204 | 660 | * Empty aops. Can be used for the cases where the user does not |
7f207e10 | 661 | diff --git a/fs/namespace.c b/fs/namespace.c |
c2c0f25c | 662 | index c7cb8a5..08723de 100644 |
7f207e10 AM |
663 | --- a/fs/namespace.c |
664 | +++ b/fs/namespace.c | |
7e9cd9fe | 665 | @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt) |
c06a8ce3 AM |
666 | mnt_dec_writers(real_mount(mnt)); |
667 | preempt_enable(); | |
668 | } | |
669 | +EXPORT_SYMBOL_GPL(__mnt_drop_write); | |
670 | ||
671 | /** | |
672 | * mnt_drop_write - give up write access to a mount | |
c2c0f25c | 673 | @@ -1779,6 +1780,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, |
7f207e10 AM |
674 | } |
675 | return 0; | |
676 | } | |
677 | +EXPORT_SYMBOL(iterate_mounts); | |
678 | ||
7eafdf33 | 679 | static void cleanup_group_ids(struct mount *mnt, struct mount *end) |
7f207e10 AM |
680 | { |
681 | diff --git a/fs/notify/group.c b/fs/notify/group.c | |
c1595e42 | 682 | index d16b62c..06ca6bc 100644 |
7f207e10 AM |
683 | --- a/fs/notify/group.c |
684 | +++ b/fs/notify/group.c | |
685 | @@ -22,6 +22,7 @@ | |
686 | #include <linux/srcu.h> | |
687 | #include <linux/rculist.h> | |
688 | #include <linux/wait.h> | |
689 | +#include <linux/module.h> | |
690 | ||
691 | #include <linux/fsnotify_backend.h> | |
692 | #include "fsnotify.h" | |
fb47a38f | 693 | @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group) |
1716fcea AM |
694 | { |
695 | atomic_inc(&group->refcnt); | |
696 | } | |
697 | +EXPORT_SYMBOL(fsnotify_get_group); | |
698 | ||
699 | /* | |
700 | * Drop a reference to a group. Free it if it's through. | |
fb47a38f | 701 | @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group) |
7f207e10 | 702 | if (atomic_dec_and_test(&group->refcnt)) |
1716fcea | 703 | fsnotify_final_destroy_group(group); |
7f207e10 AM |
704 | } |
705 | +EXPORT_SYMBOL(fsnotify_put_group); | |
706 | ||
707 | /* | |
708 | * Create a new fsnotify_group and hold a reference for the group returned. | |
fb47a38f | 709 | @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) |
7f207e10 AM |
710 | |
711 | return group; | |
712 | } | |
713 | +EXPORT_SYMBOL(fsnotify_alloc_group); | |
1716fcea AM |
714 | |
715 | int fsnotify_fasync(int fd, struct file *file, int on) | |
716 | { | |
7f207e10 | 717 | diff --git a/fs/notify/mark.c b/fs/notify/mark.c |
2000de60 | 718 | index 92e48c7..d2c4b68 100644 |
7f207e10 AM |
719 | --- a/fs/notify/mark.c |
720 | +++ b/fs/notify/mark.c | |
392086de | 721 | @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) |
7f207e10 | 722 | mark->free_mark(mark); |
1716fcea | 723 | } |
7f207e10 AM |
724 | } |
725 | +EXPORT_SYMBOL(fsnotify_put_mark); | |
726 | ||
2000de60 JR |
727 | /* Calculate mask of events for a list of marks */ |
728 | u32 fsnotify_recalc_mask(struct hlist_head *head) | |
729 | @@ -202,6 +203,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark, | |
1716fcea AM |
730 | fsnotify_destroy_mark_locked(mark, group); |
731 | mutex_unlock(&group->mark_mutex); | |
7f207e10 AM |
732 | } |
733 | +EXPORT_SYMBOL(fsnotify_destroy_mark); | |
734 | ||
2000de60 JR |
735 | /* |
736 | * Destroy all marks in the given list. The marks must be already detached from | |
737 | @@ -376,6 +378,7 @@ err: | |
7f207e10 AM |
738 | |
739 | return ret; | |
740 | } | |
741 | +EXPORT_SYMBOL(fsnotify_add_mark); | |
742 | ||
1716fcea AM |
743 | int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group, |
744 | struct inode *inode, struct vfsmount *mnt, int allow_dups) | |
2000de60 | 745 | @@ -455,6 +458,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark, |
7f207e10 AM |
746 | atomic_set(&mark->refcnt, 1); |
747 | mark->free_mark = free_mark; | |
748 | } | |
749 | +EXPORT_SYMBOL(fsnotify_init_mark); | |
750 | ||
751 | static int fsnotify_mark_destroy(void *ignored) | |
752 | { | |
753 | diff --git a/fs/open.c b/fs/open.c | |
c2c0f25c | 754 | index e33dab2..b84b828 100644 |
7f207e10 AM |
755 | --- a/fs/open.c |
756 | +++ b/fs/open.c | |
c2c0f25c | 757 | @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, |
7f207e10 AM |
758 | mutex_unlock(&dentry->d_inode->i_mutex); |
759 | return ret; | |
760 | } | |
761 | +EXPORT_SYMBOL(do_truncate); | |
762 | ||
1716fcea | 763 | long vfs_truncate(struct path *path, loff_t length) |
7f207e10 | 764 | { |
c2c0f25c | 765 | @@ -678,6 +679,7 @@ int open_check_o_direct(struct file *f) |
b912730e AM |
766 | } |
767 | return 0; | |
768 | } | |
769 | +EXPORT_SYMBOL(open_check_o_direct); | |
770 | ||
771 | static int do_dentry_open(struct file *f, | |
c2c0f25c | 772 | struct inode *inode, |
5527c038 JR |
773 | diff --git a/fs/read_write.c b/fs/read_write.c |
774 | index fd0414e..8ace6ec 100644 | |
775 | --- a/fs/read_write.c | |
776 | +++ b/fs/read_write.c | |
777 | @@ -504,6 +504,7 @@ vfs_readf_t vfs_readf(struct file *file) | |
778 | return new_sync_read; | |
779 | return ERR_PTR(-ENOSYS); | |
780 | } | |
781 | +EXPORT_SYMBOL(vfs_readf); | |
782 | ||
783 | vfs_writef_t vfs_writef(struct file *file) | |
784 | { | |
785 | @@ -515,6 +516,7 @@ vfs_writef_t vfs_writef(struct file *file) | |
786 | return new_sync_write; | |
787 | return ERR_PTR(-ENOSYS); | |
788 | } | |
789 | +EXPORT_SYMBOL(vfs_writef); | |
790 | ||
791 | ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos) | |
792 | { | |
7f207e10 | 793 | diff --git a/fs/splice.c b/fs/splice.c |
c2c0f25c | 794 | index 5f8385a..f76067e 100644 |
7f207e10 AM |
795 | --- a/fs/splice.c |
796 | +++ b/fs/splice.c | |
c2c0f25c | 797 | @@ -1115,6 +1115,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
392086de AM |
798 | |
799 | return splice_write(pipe, out, ppos, len, flags); | |
7f207e10 AM |
800 | } |
801 | +EXPORT_SYMBOL(do_splice_from); | |
802 | ||
803 | /* | |
804 | * Attempt to initiate a splice from a file to a pipe. | |
c2c0f25c | 805 | @@ -1141,6 +1142,7 @@ long do_splice_to(struct file *in, loff_t *ppos, |
7f207e10 AM |
806 | |
807 | return splice_read(in, ppos, pipe, len, flags); | |
808 | } | |
809 | +EXPORT_SYMBOL(do_splice_to); | |
810 | ||
811 | /** | |
812 | * splice_direct_to_actor - splices data directly between two non-pipes | |
c1595e42 | 813 | diff --git a/fs/xattr.c b/fs/xattr.c |
c2c0f25c | 814 | index 072fee1..a7677af 100644 |
c1595e42 JR |
815 | --- a/fs/xattr.c |
816 | +++ b/fs/xattr.c | |
817 | @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, | |
818 | *xattr_value = value; | |
819 | return error; | |
820 | } | |
821 | +EXPORT_SYMBOL(vfs_getxattr_alloc); | |
822 | ||
823 | /* Compare an extended attribute value with the given value */ | |
824 | int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name, | |
7f207e10 | 825 | diff --git a/security/commoncap.c b/security/commoncap.c |
c2c0f25c | 826 | index d103f5a4..393654e 100644 |
7f207e10 AM |
827 | --- a/security/commoncap.c |
828 | +++ b/security/commoncap.c | |
c2c0f25c | 829 | @@ -970,12 +970,14 @@ int cap_mmap_addr(unsigned long addr) |
94337f0d | 830 | } |
7f207e10 AM |
831 | return ret; |
832 | } | |
0c3ec466 AM |
833 | +EXPORT_SYMBOL(cap_mmap_addr); |
834 | ||
835 | int cap_mmap_file(struct file *file, unsigned long reqprot, | |
836 | unsigned long prot, unsigned long flags) | |
837 | { | |
838 | return 0; | |
839 | } | |
840 | +EXPORT_SYMBOL(cap_mmap_file); | |
c2c0f25c AM |
841 | |
842 | #ifdef CONFIG_SECURITY | |
843 | ||
7f207e10 | 844 | diff --git a/security/device_cgroup.c b/security/device_cgroup.c |
c1595e42 | 845 | index 188c1d2..426d9af 100644 |
7f207e10 AM |
846 | --- a/security/device_cgroup.c |
847 | +++ b/security/device_cgroup.c | |
f6c5ef8b AM |
848 | @@ -7,6 +7,7 @@ |
849 | #include <linux/device_cgroup.h> | |
850 | #include <linux/cgroup.h> | |
851 | #include <linux/ctype.h> | |
852 | +#include <linux/export.h> | |
853 | #include <linux/list.h> | |
854 | #include <linux/uaccess.h> | |
855 | #include <linux/seq_file.h> | |
076b876e | 856 | @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask) |
537831f9 AM |
857 | return __devcgroup_check_permission(type, imajor(inode), iminor(inode), |
858 | access); | |
7f207e10 | 859 | } |
2cbb1c4b | 860 | +EXPORT_SYMBOL(__devcgroup_inode_permission); |
7f207e10 AM |
861 | |
862 | int devcgroup_inode_mknod(int mode, dev_t dev) | |
863 | { | |
864 | diff --git a/security/security.c b/security/security.c | |
c2c0f25c | 865 | index 595fffa..346bad6 100644 |
7f207e10 AM |
866 | --- a/security/security.c |
867 | +++ b/security/security.c | |
c2c0f25c | 868 | @@ -438,6 +438,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry) |
7f207e10 | 869 | return 0; |
c2c0f25c | 870 | return call_int_hook(path_rmdir, 0, dir, dentry); |
7f207e10 AM |
871 | } |
872 | +EXPORT_SYMBOL(security_path_rmdir); | |
873 | ||
874 | int security_path_unlink(struct path *dir, struct dentry *dentry) | |
875 | { | |
c2c0f25c | 876 | @@ -454,6 +455,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry, |
7f207e10 | 877 | return 0; |
c2c0f25c | 878 | return call_int_hook(path_symlink, 0, dir, dentry, old_name); |
7f207e10 AM |
879 | } |
880 | +EXPORT_SYMBOL(security_path_symlink); | |
881 | ||
882 | int security_path_link(struct dentry *old_dentry, struct path *new_dir, | |
883 | struct dentry *new_dentry) | |
c2c0f25c | 884 | @@ -462,6 +464,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir, |
7f207e10 | 885 | return 0; |
c2c0f25c | 886 | return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry); |
7f207e10 AM |
887 | } |
888 | +EXPORT_SYMBOL(security_path_link); | |
889 | ||
890 | int security_path_rename(struct path *old_dir, struct dentry *old_dentry, | |
38d290e6 | 891 | struct path *new_dir, struct dentry *new_dentry, |
c2c0f25c | 892 | @@ -489,6 +492,7 @@ int security_path_truncate(struct path *path) |
7f207e10 | 893 | return 0; |
c2c0f25c | 894 | return call_int_hook(path_truncate, 0, path); |
7f207e10 AM |
895 | } |
896 | +EXPORT_SYMBOL(security_path_truncate); | |
897 | ||
7eafdf33 AM |
898 | int security_path_chmod(struct path *path, umode_t mode) |
899 | { | |
c2c0f25c | 900 | @@ -496,6 +500,7 @@ int security_path_chmod(struct path *path, umode_t mode) |
7f207e10 | 901 | return 0; |
c2c0f25c | 902 | return call_int_hook(path_chmod, 0, path, mode); |
7f207e10 AM |
903 | } |
904 | +EXPORT_SYMBOL(security_path_chmod); | |
905 | ||
537831f9 | 906 | int security_path_chown(struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 907 | { |
c2c0f25c | 908 | @@ -503,6 +508,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 909 | return 0; |
c2c0f25c | 910 | return call_int_hook(path_chown, 0, path, uid, gid); |
7f207e10 AM |
911 | } |
912 | +EXPORT_SYMBOL(security_path_chown); | |
913 | ||
914 | int security_path_chroot(struct path *path) | |
915 | { | |
c2c0f25c | 916 | @@ -588,6 +594,7 @@ int security_inode_readlink(struct dentry *dentry) |
7f207e10 | 917 | return 0; |
c2c0f25c | 918 | return call_int_hook(inode_readlink, 0, dentry); |
7f207e10 AM |
919 | } |
920 | +EXPORT_SYMBOL(security_inode_readlink); | |
921 | ||
c2c0f25c AM |
922 | int security_inode_follow_link(struct dentry *dentry, struct inode *inode, |
923 | bool rcu) | |
924 | @@ -603,6 +610,7 @@ int security_inode_permission(struct inode *inode, int mask) | |
7f207e10 | 925 | return 0; |
c2c0f25c | 926 | return call_int_hook(inode_permission, 0, inode, mask); |
7f207e10 AM |
927 | } |
928 | +EXPORT_SYMBOL(security_inode_permission); | |
929 | ||
1e00d052 | 930 | int security_inode_setattr(struct dentry *dentry, struct iattr *attr) |
7f207e10 | 931 | { |
c2c0f25c | 932 | @@ -741,6 +749,7 @@ int security_file_permission(struct file *file, int mask) |
7f207e10 AM |
933 | |
934 | return fsnotify_perm(file, mask); | |
935 | } | |
936 | +EXPORT_SYMBOL(security_file_permission); | |
937 | ||
938 | int security_file_alloc(struct file *file) | |
939 | { | |
c2c0f25c | 940 | @@ -800,6 +809,7 @@ int security_mmap_file(struct file *file, unsigned long prot, |
7f207e10 AM |
941 | return ret; |
942 | return ima_file_mmap(file, prot); | |
943 | } | |
0c3ec466 | 944 | +EXPORT_SYMBOL(security_mmap_file); |
7f207e10 | 945 | |
0c3ec466 AM |
946 | int security_mmap_addr(unsigned long addr) |
947 | { | |
7f207e10 AM |
948 | diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs |
949 | --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 950 | +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-09-24 10:47:58.244719488 +0200 |
86dc4139 | 951 | @@ -0,0 +1,50 @@ |
7f207e10 AM |
952 | +What: /debug/aufs/si_<id>/ |
953 | +Date: March 2009 | |
f6b6e03d | 954 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
955 | +Description: |
956 | + Under /debug/aufs, a directory named si_<id> is created | |
957 | + per aufs mount, where <id> is a unique id generated | |
958 | + internally. | |
1facf9fc | 959 | + |
86dc4139 AM |
960 | +What: /debug/aufs/si_<id>/plink |
961 | +Date: Apr 2013 | |
f6b6e03d | 962 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
86dc4139 AM |
963 | +Description: |
964 | + It has three lines and shows the information about the | |
965 | + pseudo-link. The first line is a single number | |
966 | + representing a number of buckets. The second line is a | |
967 | + number of pseudo-links per buckets (separated by a | |
968 | + blank). The last line is a single number representing a | |
969 | + total number of psedo-links. | |
970 | + When the aufs mount option 'noplink' is specified, it | |
971 | + will show "1\n0\n0\n". | |
972 | + | |
7f207e10 AM |
973 | +What: /debug/aufs/si_<id>/xib |
974 | +Date: March 2009 | |
f6b6e03d | 975 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
976 | +Description: |
977 | + It shows the consumed blocks by xib (External Inode Number | |
978 | + Bitmap), its block size and file size. | |
979 | + When the aufs mount option 'noxino' is specified, it | |
980 | + will be empty. About XINO files, see the aufs manual. | |
981 | + | |
982 | +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN | |
983 | +Date: March 2009 | |
f6b6e03d | 984 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
985 | +Description: |
986 | + It shows the consumed blocks by xino (External Inode Number | |
987 | + Translation Table), its link count, block size and file | |
988 | + size. | |
989 | + When the aufs mount option 'noxino' is specified, it | |
990 | + will be empty. About XINO files, see the aufs manual. | |
991 | + | |
992 | +What: /debug/aufs/si_<id>/xigen | |
993 | +Date: March 2009 | |
f6b6e03d | 994 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
995 | +Description: |
996 | + It shows the consumed blocks by xigen (External Inode | |
997 | + Generation Table), its block size and file size. | |
998 | + If CONFIG_AUFS_EXPORT is disabled, this entry will not | |
999 | + be created. | |
1000 | + When the aufs mount option 'noxino' is specified, it | |
1001 | + will be empty. About XINO files, see the aufs manual. | |
1002 | diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs | |
1003 | --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1004 | +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-09-24 10:47:58.244719488 +0200 |
392086de | 1005 | @@ -0,0 +1,31 @@ |
7f207e10 AM |
1006 | +What: /sys/fs/aufs/si_<id>/ |
1007 | +Date: March 2009 | |
f6b6e03d | 1008 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1009 | +Description: |
1010 | + Under /sys/fs/aufs, a directory named si_<id> is created | |
1011 | + per aufs mount, where <id> is a unique id generated | |
1012 | + internally. | |
1013 | + | |
1014 | +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN | |
1015 | +Date: March 2009 | |
f6b6e03d | 1016 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1017 | +Description: |
1018 | + It shows the abolute path of a member directory (which | |
1019 | + is called branch) in aufs, and its permission. | |
1020 | + | |
392086de AM |
1021 | +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN |
1022 | +Date: July 2013 | |
f6b6e03d | 1023 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
392086de AM |
1024 | +Description: |
1025 | + It shows the id of a member directory (which is called | |
1026 | + branch) in aufs. | |
1027 | + | |
7f207e10 AM |
1028 | +What: /sys/fs/aufs/si_<id>/xi_path |
1029 | +Date: March 2009 | |
f6b6e03d | 1030 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1031 | +Description: |
1032 | + It shows the abolute path of XINO (External Inode Number | |
1033 | + Bitmap, Translation Table and Generation Table) file | |
1034 | + even if it is the default path. | |
1035 | + When the aufs mount option 'noxino' is specified, it | |
1036 | + will be empty. About XINO files, see the aufs manual. | |
53392da6 AM |
1037 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt |
1038 | --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1039 | +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-09-24 10:47:58.244719488 +0200 |
7e9cd9fe | 1040 | @@ -0,0 +1,170 @@ |
53392da6 | 1041 | + |
2000de60 | 1042 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1043 | +# |
1044 | +# This program is free software; you can redistribute it and/or modify | |
1045 | +# it under the terms of the GNU General Public License as published by | |
1046 | +# the Free Software Foundation; either version 2 of the License, or | |
1047 | +# (at your option) any later version. | |
1048 | +# | |
1049 | +# This program is distributed in the hope that it will be useful, | |
1050 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1051 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1052 | +# GNU General Public License for more details. | |
1053 | +# | |
1054 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1055 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1056 | + |
1057 | +Introduction | |
1058 | +---------------------------------------- | |
1059 | + | |
1060 | +aufs [ei ju: ef es] | [a u f s] | |
1061 | +1. abbrev. for "advanced multi-layered unification filesystem". | |
1062 | +2. abbrev. for "another unionfs". | |
1063 | +3. abbrev. for "auf das" in German which means "on the" in English. | |
1064 | + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E). | |
1065 | + But "Filesystem aufs Filesystem" is hard to understand. | |
1066 | + | |
1067 | +AUFS is a filesystem with features: | |
1068 | +- multi layered stackable unification filesystem, the member directory | |
1069 | + is called as a branch. | |
1070 | +- branch permission and attribute, 'readonly', 'real-readonly', | |
7e9cd9fe | 1071 | + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their |
53392da6 AM |
1072 | + combination. |
1073 | +- internal "file copy-on-write". | |
1074 | +- logical deletion, whiteout. | |
1075 | +- dynamic branch manipulation, adding, deleting and changing permission. | |
1076 | +- allow bypassing aufs, user's direct branch access. | |
1077 | +- external inode number translation table and bitmap which maintains the | |
1078 | + persistent aufs inode number. | |
1079 | +- seekable directory, including NFS readdir. | |
1080 | +- file mapping, mmap and sharing pages. | |
1081 | +- pseudo-link, hardlink over branches. | |
1082 | +- loopback mounted filesystem as a branch. | |
1083 | +- several policies to select one among multiple writable branches. | |
1084 | +- revert a single systemcall when an error occurs in aufs. | |
1085 | +- and more... | |
1086 | + | |
1087 | + | |
1088 | +Multi Layered Stackable Unification Filesystem | |
1089 | +---------------------------------------------------------------------- | |
1090 | +Most people already knows what it is. | |
1091 | +It is a filesystem which unifies several directories and provides a | |
1092 | +merged single directory. When users access a file, the access will be | |
1093 | +passed/re-directed/converted (sorry, I am not sure which English word is | |
1094 | +correct) to the real file on the member filesystem. The member | |
1095 | +filesystem is called 'lower filesystem' or 'branch' and has a mode | |
1096 | +'readonly' and 'readwrite.' And the deletion for a file on the lower | |
1097 | +readonly branch is handled by creating 'whiteout' on the upper writable | |
1098 | +branch. | |
1099 | + | |
1100 | +On LKML, there have been discussions about UnionMount (Jan Blunck, | |
1101 | +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took | |
1102 | +different approaches to implement the merged-view. | |
1103 | +The former tries putting it into VFS, and the latter implements as a | |
1104 | +separate filesystem. | |
1105 | +(If I misunderstand about these implementations, please let me know and | |
1106 | +I shall correct it. Because it is a long time ago when I read their | |
1107 | +source files last time). | |
1108 | + | |
1109 | +UnionMount's approach will be able to small, but may be hard to share | |
1110 | +branches between several UnionMount since the whiteout in it is | |
1111 | +implemented in the inode on branch filesystem and always | |
1112 | +shared. According to Bharata's post, readdir does not seems to be | |
1113 | +finished yet. | |
1114 | +There are several missing features known in this implementations such as | |
1115 | +- for users, the inode number may change silently. eg. copy-up. | |
1116 | +- link(2) may break by copy-up. | |
1117 | +- read(2) may get an obsoleted filedata (fstat(2) too). | |
1118 | +- fcntl(F_SETLK) may be broken by copy-up. | |
1119 | +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after | |
1120 | + open(O_RDWR). | |
1121 | + | |
7e9cd9fe AM |
1122 | +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was |
1123 | +merged into mainline. This is another implementation of UnionMount as a | |
1124 | +separated filesystem. All the limitations and known problems which | |
1125 | +UnionMount are equally inherited to "overlay" filesystem. | |
1126 | + | |
1127 | +Unionfs has a longer history. When I started implementing a stackable | |
1128 | +filesystem (Aug 2005), it already existed. It has virtual super_block, | |
1129 | +inode, dentry and file objects and they have an array pointing lower | |
1130 | +same kind objects. After contributing many patches for Unionfs, I | |
1131 | +re-started my project AUFS (Jun 2006). | |
53392da6 AM |
1132 | + |
1133 | +In AUFS, the structure of filesystem resembles to Unionfs, but I | |
1134 | +implemented my own ideas, approaches and enhancements and it became | |
1135 | +totally different one. | |
1136 | + | |
1137 | +Comparing DM snapshot and fs based implementation | |
1138 | +- the number of bytes to be copied between devices is much smaller. | |
1139 | +- the type of filesystem must be one and only. | |
1140 | +- the fs must be writable, no readonly fs, even for the lower original | |
1141 | + device. so the compression fs will not be usable. but if we use | |
1142 | + loopback mount, we may address this issue. | |
1143 | + for instance, | |
1144 | + mount /cdrom/squashfs.img /sq | |
1145 | + losetup /sq/ext2.img | |
1146 | + losetup /somewhere/cow | |
1147 | + dmsetup "snapshot /dev/loop0 /dev/loop1 ..." | |
1148 | +- it will be difficult (or needs more operations) to extract the | |
1149 | + difference between the original device and COW. | |
1150 | +- DM snapshot-merge may help a lot when users try merging. in the | |
1151 | + fs-layer union, users will use rsync(1). | |
1152 | + | |
7e9cd9fe AM |
1153 | +You may want to read my old paper "Filesystems in LiveCD" |
1154 | +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf). | |
53392da6 | 1155 | + |
7e9cd9fe AM |
1156 | + |
1157 | +Several characters/aspects/persona of aufs | |
53392da6 AM |
1158 | +---------------------------------------------------------------------- |
1159 | + | |
7e9cd9fe | 1160 | +Aufs has several characters, aspects or persona. |
53392da6 AM |
1161 | +1. a filesystem, callee of VFS helper |
1162 | +2. sub-VFS, caller of VFS helper for branches | |
1163 | +3. a virtual filesystem which maintains persistent inode number | |
1164 | +4. reader/writer of files on branches such like an application | |
1165 | + | |
1166 | +1. Callee of VFS Helper | |
1167 | +As an ordinary linux filesystem, aufs is a callee of VFS. For instance, | |
1168 | +unlink(2) from an application reaches sys_unlink() kernel function and | |
1169 | +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it | |
1170 | +calls filesystem specific unlink operation. Actually aufs implements the | |
1171 | +unlink operation but it behaves like a redirector. | |
1172 | + | |
1173 | +2. Caller of VFS Helper for Branches | |
1174 | +aufs_unlink() passes the unlink request to the branch filesystem as if | |
1175 | +it were called from VFS. So the called unlink operation of the branch | |
1176 | +filesystem acts as usual. As a caller of VFS helper, aufs should handle | |
1177 | +every necessary pre/post operation for the branch filesystem. | |
1178 | +- acquire the lock for the parent dir on a branch | |
1179 | +- lookup in a branch | |
1180 | +- revalidate dentry on a branch | |
1181 | +- mnt_want_write() for a branch | |
1182 | +- vfs_unlink() for a branch | |
1183 | +- mnt_drop_write() for a branch | |
1184 | +- release the lock on a branch | |
1185 | + | |
1186 | +3. Persistent Inode Number | |
1187 | +One of the most important issue for a filesystem is to maintain inode | |
1188 | +numbers. This is particularly important to support exporting a | |
1189 | +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a | |
1190 | +backend block device for its own. But some storage is necessary to | |
7e9cd9fe AM |
1191 | +keep and maintain the inode numbers. It may be a large space and may not |
1192 | +suit to keep in memory. Aufs rents some space from its first writable | |
1193 | +branch filesystem (by default) and creates file(s) on it. These files | |
1194 | +are created by aufs internally and removed soon (currently) keeping | |
1195 | +opened. | |
53392da6 AM |
1196 | +Note: Because these files are removed, they are totally gone after |
1197 | + unmounting aufs. It means the inode numbers are not persistent | |
1198 | + across unmount or reboot. I have a plan to make them really | |
1199 | + persistent which will be important for aufs on NFS server. | |
1200 | + | |
1201 | +4. Read/Write Files Internally (copy-on-write) | |
1202 | +Because a branch can be readonly, when you write a file on it, aufs will | |
1203 | +"copy-up" it to the upper writable branch internally. And then write the | |
1204 | +originally requested thing to the file. Generally kernel doesn't | |
1205 | +open/read/write file actively. In aufs, even a single write may cause a | |
1206 | +internal "file copy". This behaviour is very similar to cp(1) command. | |
1207 | + | |
1208 | +Some people may think it is better to pass such work to user space | |
1209 | +helper, instead of doing in kernel space. Actually I am still thinking | |
1210 | +about it. But currently I have implemented it in kernel space. | |
1211 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt | |
1212 | --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1213 | +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-09-24 10:47:58.244719488 +0200 |
7e9cd9fe | 1214 | @@ -0,0 +1,258 @@ |
53392da6 | 1215 | + |
2000de60 | 1216 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1217 | +# |
1218 | +# This program is free software; you can redistribute it and/or modify | |
1219 | +# it under the terms of the GNU General Public License as published by | |
1220 | +# the Free Software Foundation; either version 2 of the License, or | |
1221 | +# (at your option) any later version. | |
1222 | +# | |
1223 | +# This program is distributed in the hope that it will be useful, | |
1224 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1225 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1226 | +# GNU General Public License for more details. | |
1227 | +# | |
1228 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1229 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1230 | + |
1231 | +Basic Aufs Internal Structure | |
1232 | + | |
1233 | +Superblock/Inode/Dentry/File Objects | |
1234 | +---------------------------------------------------------------------- | |
1235 | +As like an ordinary filesystem, aufs has its own | |
1236 | +superblock/inode/dentry/file objects. All these objects have a | |
1237 | +dynamically allocated array and store the same kind of pointers to the | |
1238 | +lower filesystem, branch. | |
1239 | +For example, when you build a union with one readwrite branch and one | |
1240 | +readonly, mounted /au, /rw and /ro respectively. | |
1241 | +- /au = /rw + /ro | |
1242 | +- /ro/fileA exists but /rw/fileA | |
1243 | + | |
1244 | +Aufs lookup operation finds /ro/fileA and gets dentry for that. These | |
1245 | +pointers are stored in a aufs dentry. The array in aufs dentry will be, | |
7e9cd9fe | 1246 | +- [0] = NULL (because /rw/fileA doesn't exist) |
53392da6 AM |
1247 | +- [1] = /ro/fileA |
1248 | + | |
1249 | +This style of an array is essentially same to the aufs | |
1250 | +superblock/inode/dentry/file objects. | |
1251 | + | |
1252 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1253 | +branches dynamically, these objects has its own generation. When |
1254 | +branches are changed, the generation in aufs superblock is | |
1255 | +incremented. And a generation in other object are compared when it is | |
1256 | +accessed. When a generation in other objects are obsoleted, aufs | |
1257 | +refreshes the internal array. | |
53392da6 AM |
1258 | + |
1259 | + | |
1260 | +Superblock | |
1261 | +---------------------------------------------------------------------- | |
1262 | +Additionally aufs superblock has some data for policies to select one | |
1263 | +among multiple writable branches, XIB files, pseudo-links and kobject. | |
1264 | +See below in detail. | |
7e9cd9fe AM |
1265 | +About the policies which supports copy-down a directory, see |
1266 | +wbr_policy.txt too. | |
53392da6 AM |
1267 | + |
1268 | + | |
1269 | +Branch and XINO(External Inode Number Translation Table) | |
1270 | +---------------------------------------------------------------------- | |
1271 | +Every branch has its own xino (external inode number translation table) | |
1272 | +file. The xino file is created and unlinked by aufs internally. When two | |
1273 | +members of a union exist on the same filesystem, they share the single | |
1274 | +xino file. | |
1275 | +The struct of a xino file is simple, just a sequence of aufs inode | |
1276 | +numbers which is indexed by the lower inode number. | |
1277 | +In the above sample, assume the inode number of /ro/fileA is i111 and | |
1278 | +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as | |
1279 | +4(8) bytes at 111 * 4(8) bytes offset in the xino file. | |
1280 | + | |
1281 | +When the inode numbers are not contiguous, the xino file will be sparse | |
1282 | +which has a hole in it and doesn't consume as much disk space as it | |
1283 | +might appear. If your branch filesystem consumes disk space for such | |
1284 | +holes, then you should specify 'xino=' option at mounting aufs. | |
1285 | + | |
7e9cd9fe AM |
1286 | +Aufs has a mount option to free the disk blocks for such holes in XINO |
1287 | +files on tmpfs or ramdisk. But it is not so effective actually. If you | |
1288 | +meet a problem of disk shortage due to XINO files, then you should try | |
1289 | +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git. | |
1290 | +The patch localizes the assignment inumbers per tmpfs-mount and avoid | |
1291 | +the holes in XINO files. | |
1292 | + | |
53392da6 | 1293 | +Also a writable branch has three kinds of "whiteout bases". All these |
7e9cd9fe | 1294 | +are existed when the branch is joined to aufs, and their names are |
53392da6 AM |
1295 | +whiteout-ed doubly, so that users will never see their names in aufs |
1296 | +hierarchy. | |
7e9cd9fe | 1297 | +1. a regular file which will be hardlinked to all whiteouts. |
53392da6 | 1298 | +2. a directory to store a pseudo-link. |
7e9cd9fe | 1299 | +3. a directory to store an "orphan"-ed file temporary. |
53392da6 AM |
1300 | + |
1301 | +1. Whiteout Base | |
1302 | + When you remove a file on a readonly branch, aufs handles it as a | |
1303 | + logical deletion and creates a whiteout on the upper writable branch | |
1304 | + as a hardlink of this file in order not to consume inode on the | |
1305 | + writable branch. | |
1306 | +2. Pseudo-link Dir | |
1307 | + See below, Pseudo-link. | |
1308 | +3. Step-Parent Dir | |
1309 | + When "fileC" exists on the lower readonly branch only and it is | |
1310 | + opened and removed with its parent dir, and then user writes | |
1311 | + something into it, then aufs copies-up fileC to this | |
1312 | + directory. Because there is no other dir to store fileC. After | |
1313 | + creating a file under this dir, the file is unlinked. | |
1314 | + | |
1315 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1316 | +dynamically, a branch has its own id. When the branch order changes, |
1317 | +aufs finds the new index by searching the branch id. | |
53392da6 AM |
1318 | + |
1319 | + | |
1320 | +Pseudo-link | |
1321 | +---------------------------------------------------------------------- | |
1322 | +Assume "fileA" exists on the lower readonly branch only and it is | |
1323 | +hardlinked to "fileB" on the branch. When you write something to fileA, | |
1324 | +aufs copies-up it to the upper writable branch. Additionally aufs | |
1325 | +creates a hardlink under the Pseudo-link Directory of the writable | |
1326 | +branch. The inode of a pseudo-link is kept in aufs super_block as a | |
1327 | +simple list. If fileB is read after unlinking fileA, aufs returns | |
1328 | +filedata from the pseudo-link instead of the lower readonly | |
1329 | +branch. Because the pseudo-link is based upon the inode, to keep the | |
7e9cd9fe | 1330 | +inode number by xino (see above) is essentially necessary. |
53392da6 AM |
1331 | + |
1332 | +All the hardlinks under the Pseudo-link Directory of the writable branch | |
1333 | +should be restored in a proper location later. Aufs provides a utility | |
1334 | +to do this. The userspace helpers executed at remounting and unmounting | |
1335 | +aufs by default. | |
1336 | +During this utility is running, it puts aufs into the pseudo-link | |
1337 | +maintenance mode. In this mode, only the process which began the | |
1338 | +maintenance mode (and its child processes) is allowed to operate in | |
1339 | +aufs. Some other processes which are not related to the pseudo-link will | |
1340 | +be allowed to run too, but the rest have to return an error or wait | |
1341 | +until the maintenance mode ends. If a process already acquires an inode | |
1342 | +mutex (in VFS), it has to return an error. | |
1343 | + | |
1344 | + | |
1345 | +XIB(external inode number bitmap) | |
1346 | +---------------------------------------------------------------------- | |
1347 | +Addition to the xino file per a branch, aufs has an external inode number | |
7e9cd9fe AM |
1348 | +bitmap in a superblock object. It is also an internal file such like a |
1349 | +xino file. | |
53392da6 AM |
1350 | +It is a simple bitmap to mark whether the aufs inode number is in-use or |
1351 | +not. | |
1352 | +To reduce the file I/O, aufs prepares a single memory page to cache xib. | |
1353 | + | |
7e9cd9fe | 1354 | +As well as XINO files, aufs has a feature to truncate/refresh XIB to |
53392da6 AM |
1355 | +reduce the number of consumed disk blocks for these files. |
1356 | + | |
1357 | + | |
1358 | +Virtual or Vertical Dir, and Readdir in Userspace | |
1359 | +---------------------------------------------------------------------- | |
1360 | +In order to support multiple layers (branches), aufs readdir operation | |
1361 | +constructs a virtual dir block on memory. For readdir, aufs calls | |
1362 | +vfs_readdir() internally for each dir on branches, merges their entries | |
1363 | +with eliminating the whiteout-ed ones, and sets it to file (dir) | |
1364 | +object. So the file object has its entry list until it is closed. The | |
1365 | +entry list will be updated when the file position is zero and becomes | |
7e9cd9fe | 1366 | +obsoleted. This decision is made in aufs automatically. |
53392da6 AM |
1367 | + |
1368 | +The dynamically allocated memory block for the name of entries has a | |
1369 | +unit of 512 bytes (by default) and stores the names contiguously (no | |
1370 | +padding). Another block for each entry is handled by kmem_cache too. | |
1371 | +During building dir blocks, aufs creates hash list and judging whether | |
1372 | +the entry is whiteouted by its upper branch or already listed. | |
1373 | +The merged result is cached in the corresponding inode object and | |
1374 | +maintained by a customizable life-time option. | |
1375 | + | |
1376 | +Some people may call it can be a security hole or invite DoS attack | |
1377 | +since the opened and once readdir-ed dir (file object) holds its entry | |
1378 | +list and becomes a pressure for system memory. But I'd say it is similar | |
1379 | +to files under /proc or /sys. The virtual files in them also holds a | |
1380 | +memory page (generally) while they are opened. When an idea to reduce | |
1381 | +memory for them is introduced, it will be applied to aufs too. | |
1382 | +For those who really hate this situation, I've developed readdir(3) | |
1383 | +library which operates this merging in userspace. You just need to set | |
1384 | +LD_PRELOAD environment variable, and aufs will not consume no memory in | |
1385 | +kernel space for readdir(3). | |
1386 | + | |
1387 | + | |
1388 | +Workqueue | |
1389 | +---------------------------------------------------------------------- | |
1390 | +Aufs sometimes requires privilege access to a branch. For instance, | |
1391 | +in copy-up/down operation. When a user process is going to make changes | |
1392 | +to a file which exists in the lower readonly branch only, and the mode | |
1393 | +of one of ancestor directories may not be writable by a user | |
1394 | +process. Here aufs copy-up the file with its ancestors and they may | |
1395 | +require privilege to set its owner/group/mode/etc. | |
1396 | +This is a typical case of a application character of aufs (see | |
1397 | +Introduction). | |
1398 | + | |
1399 | +Aufs uses workqueue synchronously for this case. It creates its own | |
1400 | +workqueue. The workqueue is a kernel thread and has privilege. Aufs | |
1401 | +passes the request to call mkdir or write (for example), and wait for | |
1402 | +its completion. This approach solves a problem of a signal handler | |
1403 | +simply. | |
1404 | +If aufs didn't adopt the workqueue and changed the privilege of the | |
7e9cd9fe AM |
1405 | +process, then the process may receive the unexpected SIGXFSZ or other |
1406 | +signals. | |
53392da6 AM |
1407 | + |
1408 | +Also aufs uses the system global workqueue ("events" kernel thread) too | |
1409 | +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a | |
1410 | +whiteout base and etc. This is unrelated to a privilege. | |
1411 | +Most of aufs operation tries acquiring a rw_semaphore for aufs | |
1412 | +superblock at the beginning, at the same time waits for the completion | |
1413 | +of all queued asynchronous tasks. | |
1414 | + | |
1415 | + | |
1416 | +Whiteout | |
1417 | +---------------------------------------------------------------------- | |
1418 | +The whiteout in aufs is very similar to Unionfs's. That is represented | |
1419 | +by its filename. UnionMount takes an approach of a file mode, but I am | |
1420 | +afraid several utilities (find(1) or something) will have to support it. | |
1421 | + | |
1422 | +Basically the whiteout represents "logical deletion" which stops aufs to | |
1423 | +lookup further, but also it represents "dir is opaque" which also stop | |
7e9cd9fe | 1424 | +further lookup. |
53392da6 AM |
1425 | + |
1426 | +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively. | |
1427 | +In order to make several functions in a single systemcall to be | |
1428 | +revertible, aufs adopts an approach to rename a directory to a temporary | |
1429 | +unique whiteouted name. | |
1430 | +For example, in rename(2) dir where the target dir already existed, aufs | |
1431 | +renames the target dir to a temporary unique whiteouted name before the | |
7e9cd9fe | 1432 | +actual rename on a branch, and then handles other actions (make it opaque, |
53392da6 AM |
1433 | +update the attributes, etc). If an error happens in these actions, aufs |
1434 | +simply renames the whiteouted name back and returns an error. If all are | |
1435 | +succeeded, aufs registers a function to remove the whiteouted unique | |
1436 | +temporary name completely and asynchronously to the system global | |
1437 | +workqueue. | |
1438 | + | |
1439 | + | |
1440 | +Copy-up | |
1441 | +---------------------------------------------------------------------- | |
1442 | +It is a well-known feature or concept. | |
1443 | +When user modifies a file on a readonly branch, aufs operate "copy-up" | |
1444 | +internally and makes change to the new file on the upper writable branch. | |
1445 | +When the trigger systemcall does not update the timestamps of the parent | |
1446 | +dir, aufs reverts it after copy-up. | |
c2b27bf2 AM |
1447 | + |
1448 | + | |
1449 | +Move-down (aufs3.9 and later) | |
1450 | +---------------------------------------------------------------------- | |
1451 | +"Copy-up" is one of the essential feature in aufs. It copies a file from | |
1452 | +the lower readonly branch to the upper writable branch when a user | |
1453 | +changes something about the file. | |
1454 | +"Move-down" is an opposite action of copy-up. Basically this action is | |
1455 | +ran manually instead of automatically and internally. | |
076b876e AM |
1456 | +For desgin and implementation, aufs has to consider these issues. |
1457 | +- whiteout for the file may exist on the lower branch. | |
1458 | +- ancestor directories may not exist on the lower branch. | |
1459 | +- diropq for the ancestor directories may exist on the upper branch. | |
1460 | +- free space on the lower branch will reduce. | |
1461 | +- another access to the file may happen during moving-down, including | |
7e9cd9fe | 1462 | + UDBA (see "Revalidate Dentry and UDBA"). |
076b876e AM |
1463 | +- the file should not be hard-linked nor pseudo-linked. they should be |
1464 | + handled by auplink utility later. | |
c2b27bf2 AM |
1465 | + |
1466 | +Sometimes users want to move-down a file from the upper writable branch | |
1467 | +to the lower readonly or writable branch. For instance, | |
1468 | +- the free space of the upper writable branch is going to run out. | |
1469 | +- create a new intermediate branch between the upper and lower branch. | |
1470 | +- etc. | |
1471 | + | |
1472 | +For this purpose, use "aumvdown" command in aufs-util.git. | |
b912730e AM |
1473 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt |
1474 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1475 | +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2015-09-24 10:47:58.244719488 +0200 |
b912730e AM |
1476 | @@ -0,0 +1,85 @@ |
1477 | + | |
1478 | +# Copyright (C) 2015 Junjiro R. Okajima | |
1479 | +# | |
1480 | +# This program is free software; you can redistribute it and/or modify | |
1481 | +# it under the terms of the GNU General Public License as published by | |
1482 | +# the Free Software Foundation; either version 2 of the License, or | |
1483 | +# (at your option) any later version. | |
1484 | +# | |
1485 | +# This program is distributed in the hope that it will be useful, | |
1486 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1487 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1488 | +# GNU General Public License for more details. | |
1489 | +# | |
1490 | +# You should have received a copy of the GNU General Public License | |
1491 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1492 | + | |
1493 | +Support for a branch who has its ->atomic_open() | |
1494 | +---------------------------------------------------------------------- | |
1495 | +The filesystems who implement its ->atomic_open() are not majority. For | |
1496 | +example NFSv4 does, and aufs should call NFSv4 ->atomic_open, | |
1497 | +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than | |
1498 | +->atomic_open(), NFSv4 returns an error for this open(2). While I am not | |
1499 | +sure whether all filesystems who have ->atomic_open() behave like this, | |
1500 | +but NFSv4 surely returns the error. | |
1501 | + | |
1502 | +In order to support ->atomic_open() for aufs, there are a few | |
1503 | +approaches. | |
1504 | + | |
1505 | +A. Introduce aufs_atomic_open() | |
1506 | + - calls one of VFS:do_last(), lookup_open() or atomic_open() for | |
1507 | + branch fs. | |
1508 | +B. Introduce aufs_atomic_open() calling create, open and chmod. this is | |
1509 | + an aufs user Pip Cet's approach | |
1510 | + - calls aufs_create(), VFS finish_open() and notify_change(). | |
1511 | + - pass fake-mode to finish_open(), and then correct the mode by | |
1512 | + notify_change(). | |
1513 | +C. Extend aufs_open() to call branch fs's ->atomic_open() | |
1514 | + - no aufs_atomic_open(). | |
1515 | + - aufs_lookup() registers the TID to an aufs internal object. | |
1516 | + - aufs_create() does nothing when the matching TID is registered, but | |
1517 | + registers the mode. | |
1518 | + - aufs_open() calls branch fs's ->atomic_open() when the matching | |
1519 | + TID is registered. | |
1520 | +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's | |
1521 | + credential | |
1522 | + - no aufs_atomic_open(). | |
1523 | + - aufs_create() registers the TID to an internal object. this info | |
1524 | + represents "this process created this file just now." | |
1525 | + - when aufs gets EACCES from branch fs's ->open(), then confirm the | |
1526 | + registered TID and re-try open() with superuser's credential. | |
1527 | + | |
1528 | +Pros and cons for each approach. | |
1529 | + | |
1530 | +A. | |
1531 | + - straightforward but highly depends upon VFS internal. | |
1532 | + - the atomic behavaiour is kept. | |
1533 | + - some of parameters such as nameidata are hard to reproduce for | |
1534 | + branch fs. | |
1535 | + - large overhead. | |
1536 | +B. | |
1537 | + - easy to implement. | |
1538 | + - the atomic behavaiour is lost. | |
1539 | +C. | |
1540 | + - the atomic behavaiour is kept. | |
1541 | + - dirty and tricky. | |
1542 | + - VFS checks whether the file is created correctly after calling | |
1543 | + ->create(), which means this approach doesn't work. | |
1544 | +D. | |
1545 | + - easy to implement. | |
1546 | + - the atomic behavaiour is lost. | |
1547 | + - to open a file with superuser's credential and give it to a user | |
1548 | + process is a bad idea, since the file object keeps the credential | |
1549 | + in it. It may affect LSM or something. This approach doesn't work | |
1550 | + either. | |
1551 | + | |
1552 | +The approach A is ideal, but it hard to implement. So here is a | |
1553 | +variation of A, which is to be implemented. | |
1554 | + | |
1555 | +A-1. Introduce aufs_atomic_open() | |
1556 | + - calls branch fs ->atomic_open() if exists. otherwise calls | |
1557 | + vfs_create() and finish_open(). | |
1558 | + - the demerit is that the several checks after branch fs | |
1559 | + ->atomic_open() are lost. in the ordinary case, the checks are | |
1560 | + done by VFS:do_last(), lookup_open() and atomic_open(). some can | |
1561 | + be implemented in aufs, but not all I am afraid. | |
53392da6 AM |
1562 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt |
1563 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1564 | +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-09-24 10:47:58.244719488 +0200 |
7e9cd9fe | 1565 | @@ -0,0 +1,113 @@ |
53392da6 | 1566 | + |
2000de60 | 1567 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1568 | +# |
1569 | +# This program is free software; you can redistribute it and/or modify | |
1570 | +# it under the terms of the GNU General Public License as published by | |
1571 | +# the Free Software Foundation; either version 2 of the License, or | |
1572 | +# (at your option) any later version. | |
1573 | +# | |
1574 | +# This program is distributed in the hope that it will be useful, | |
1575 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1576 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1577 | +# GNU General Public License for more details. | |
1578 | +# | |
1579 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1580 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1581 | + |
1582 | +Lookup in a Branch | |
1583 | +---------------------------------------------------------------------- | |
1584 | +Since aufs has a character of sub-VFS (see Introduction), it operates | |
7e9cd9fe AM |
1585 | +lookup for branches as VFS does. It may be a heavy work. But almost all |
1586 | +lookup operation in aufs is the simplest case, ie. lookup only an entry | |
1587 | +directly connected to its parent. Digging down the directory hierarchy | |
1588 | +is unnecessary. VFS has a function lookup_one_len() for that use, and | |
1589 | +aufs calls it. | |
1590 | + | |
1591 | +When a branch is a remote filesystem, aufs basically relies upon its | |
53392da6 AM |
1592 | +->d_revalidate(), also aufs forces the hardest revalidate tests for |
1593 | +them. | |
1594 | +For d_revalidate, aufs implements three levels of revalidate tests. See | |
1595 | +"Revalidate Dentry and UDBA" in detail. | |
1596 | + | |
1597 | + | |
076b876e AM |
1598 | +Test Only the Highest One for the Directory Permission (dirperm1 option) |
1599 | +---------------------------------------------------------------------- | |
1600 | +Let's try case study. | |
1601 | +- aufs has two branches, upper readwrite and lower readonly. | |
1602 | + /au = /rw + /ro | |
1603 | +- "dirA" exists under /ro, but /rw. and its mode is 0700. | |
1604 | +- user invoked "chmod a+rx /au/dirA" | |
1605 | +- the internal copy-up is activated and "/rw/dirA" is created and its | |
7e9cd9fe | 1606 | + permission bits are set to world readable. |
076b876e AM |
1607 | +- then "/au/dirA" becomes world readable? |
1608 | + | |
1609 | +In this case, /ro/dirA is still 0700 since it exists in readonly branch, | |
1610 | +or it may be a natively readonly filesystem. If aufs respects the lower | |
1611 | +branch, it should not respond readdir request from other users. But user | |
1612 | +allowed it by chmod. Should really aufs rejects showing the entries | |
1613 | +under /ro/dirA? | |
1614 | + | |
7e9cd9fe AM |
1615 | +To be honest, I don't have a good solution for this case. So aufs |
1616 | +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to | |
1617 | +users. | |
076b876e AM |
1618 | +When dirperm1 is specified, aufs checks only the highest one for the |
1619 | +directory permission, and shows the entries. Otherwise, as usual, checks | |
1620 | +every dir existing on all branches and rejects the request. | |
1621 | + | |
1622 | +As a side effect, dirperm1 option improves the performance of aufs | |
1623 | +because the number of permission check is reduced when the number of | |
1624 | +branch is many. | |
1625 | + | |
1626 | + | |
53392da6 AM |
1627 | +Revalidate Dentry and UDBA (User's Direct Branch Access) |
1628 | +---------------------------------------------------------------------- | |
1629 | +Generally VFS helpers re-validate a dentry as a part of lookup. | |
1630 | +0. digging down the directory hierarchy. | |
1631 | +1. lock the parent dir by its i_mutex. | |
1632 | +2. lookup the final (child) entry. | |
1633 | +3. revalidate it. | |
1634 | +4. call the actual operation (create, unlink, etc.) | |
1635 | +5. unlock the parent dir | |
1636 | + | |
1637 | +If the filesystem implements its ->d_revalidate() (step 3), then it is | |
1638 | +called. Actually aufs implements it and checks the dentry on a branch is | |
1639 | +still valid. | |
1640 | +But it is not enough. Because aufs has to release the lock for the | |
1641 | +parent dir on a branch at the end of ->lookup() (step 2) and | |
1642 | +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still | |
1643 | +held by VFS. | |
1644 | +If the file on a branch is changed directly, eg. bypassing aufs, after | |
1645 | +aufs released the lock, then the subsequent operation may cause | |
1646 | +something unpleasant result. | |
1647 | + | |
1648 | +This situation is a result of VFS architecture, ->lookup() and | |
1649 | +->d_revalidate() is separated. But I never say it is wrong. It is a good | |
1650 | +design from VFS's point of view. It is just not suitable for sub-VFS | |
1651 | +character in aufs. | |
1652 | + | |
1653 | +Aufs supports such case by three level of revalidation which is | |
1654 | +selectable by user. | |
1655 | +1. Simple Revalidate | |
1656 | + Addition to the native flow in VFS's, confirm the child-parent | |
1657 | + relationship on the branch just after locking the parent dir on the | |
1658 | + branch in the "actual operation" (step 4). When this validation | |
1659 | + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still | |
1660 | + checks the validation of the dentry on branches. | |
1661 | +2. Monitor Changes Internally by Inotify/Fsnotify | |
1662 | + Addition to above, in the "actual operation" (step 4) aufs re-lookup | |
1663 | + the dentry on the branch, and returns EBUSY if it finds different | |
1664 | + dentry. | |
1665 | + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches | |
1666 | + during it is in cache. When the event is notified, aufs registers a | |
1667 | + function to kernel 'events' thread by schedule_work(). And the | |
1668 | + function sets some special status to the cached aufs dentry and inode | |
1669 | + private data. If they are not cached, then aufs has nothing to | |
1670 | + do. When the same file is accessed through aufs (step 0-3) later, | |
1671 | + aufs will detect the status and refresh all necessary data. | |
1672 | + In this mode, aufs has to ignore the event which is fired by aufs | |
1673 | + itself. | |
1674 | +3. No Extra Validation | |
1675 | + This is the simplest test and doesn't add any additional revalidation | |
7e9cd9fe | 1676 | + test, and skip the revalidation in step 4. It is useful and improves |
53392da6 AM |
1677 | + aufs performance when system surely hide the aufs branches from user, |
1678 | + by over-mounting something (or another method). | |
1679 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt | |
1680 | --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1681 | +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-09-24 10:47:58.244719488 +0200 |
7e9cd9fe | 1682 | @@ -0,0 +1,74 @@ |
53392da6 | 1683 | + |
2000de60 | 1684 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1685 | +# |
1686 | +# This program is free software; you can redistribute it and/or modify | |
1687 | +# it under the terms of the GNU General Public License as published by | |
1688 | +# the Free Software Foundation; either version 2 of the License, or | |
1689 | +# (at your option) any later version. | |
1690 | +# | |
1691 | +# This program is distributed in the hope that it will be useful, | |
1692 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1693 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1694 | +# GNU General Public License for more details. | |
1695 | +# | |
1696 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1697 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1698 | + |
1699 | +Branch Manipulation | |
1700 | + | |
1701 | +Since aufs supports dynamic branch manipulation, ie. add/remove a branch | |
1702 | +and changing its permission/attribute, there are a lot of works to do. | |
1703 | + | |
1704 | + | |
1705 | +Add a Branch | |
1706 | +---------------------------------------------------------------------- | |
1707 | +o Confirm the adding dir exists outside of aufs, including loopback | |
7e9cd9fe | 1708 | + mount, and its various attributes. |
53392da6 AM |
1709 | +o Initialize the xino file and whiteout bases if necessary. |
1710 | + See struct.txt. | |
1711 | + | |
1712 | +o Check the owner/group/mode of the directory | |
1713 | + When the owner/group/mode of the adding directory differs from the | |
1714 | + existing branch, aufs issues a warning because it may impose a | |
1715 | + security risk. | |
1716 | + For example, when a upper writable branch has a world writable empty | |
1717 | + top directory, a malicious user can create any files on the writable | |
1718 | + branch directly, like copy-up and modify manually. If something like | |
1719 | + /etc/{passwd,shadow} exists on the lower readonly branch but the upper | |
1720 | + writable branch, and the writable branch is world-writable, then a | |
1721 | + malicious guy may create /etc/passwd on the writable branch directly | |
1722 | + and the infected file will be valid in aufs. | |
7e9cd9fe | 1723 | + I am afraid it can be a security issue, but aufs can do nothing except |
53392da6 AM |
1724 | + producing a warning. |
1725 | + | |
1726 | + | |
1727 | +Delete a Branch | |
1728 | +---------------------------------------------------------------------- | |
1729 | +o Confirm the deleting branch is not busy | |
1730 | + To be general, there is one merit to adopt "remount" interface to | |
1731 | + manipulate branches. It is to discard caches. At deleting a branch, | |
1732 | + aufs checks the still cached (and connected) dentries and inodes. If | |
1733 | + there are any, then they are all in-use. An inode without its | |
1734 | + corresponding dentry can be alive alone (for example, inotify/fsnotify case). | |
1735 | + | |
1736 | + For the cached one, aufs checks whether the same named entry exists on | |
1737 | + other branches. | |
1738 | + If the cached one is a directory, because aufs provides a merged view | |
1739 | + to users, as long as one dir is left on any branch aufs can show the | |
1740 | + dir to users. In this case, the branch can be removed from aufs. | |
1741 | + Otherwise aufs rejects deleting the branch. | |
1742 | + | |
1743 | + If any file on the deleting branch is opened by aufs, then aufs | |
1744 | + rejects deleting. | |
1745 | + | |
1746 | + | |
1747 | +Modify the Permission of a Branch | |
1748 | +---------------------------------------------------------------------- | |
1749 | +o Re-initialize or remove the xino file and whiteout bases if necessary. | |
1750 | + See struct.txt. | |
1751 | + | |
1752 | +o rw --> ro: Confirm the modifying branch is not busy | |
1753 | + Aufs rejects the request if any of these conditions are true. | |
1754 | + - a file on the branch is mmap-ed. | |
1755 | + - a regular file on the branch is opened for write and there is no | |
1756 | + same named entry on the upper branch. | |
1757 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt | |
1758 | --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1759 | +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-09-24 10:47:58.244719488 +0200 |
523b37e3 | 1760 | @@ -0,0 +1,64 @@ |
53392da6 | 1761 | + |
2000de60 | 1762 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1763 | +# |
1764 | +# This program is free software; you can redistribute it and/or modify | |
1765 | +# it under the terms of the GNU General Public License as published by | |
1766 | +# the Free Software Foundation; either version 2 of the License, or | |
1767 | +# (at your option) any later version. | |
1768 | +# | |
1769 | +# This program is distributed in the hope that it will be useful, | |
1770 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1771 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1772 | +# GNU General Public License for more details. | |
1773 | +# | |
1774 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1775 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1776 | + |
1777 | +Policies to Select One among Multiple Writable Branches | |
1778 | +---------------------------------------------------------------------- | |
1779 | +When the number of writable branch is more than one, aufs has to decide | |
1780 | +the target branch for file creation or copy-up. By default, the highest | |
1781 | +writable branch which has the parent (or ancestor) dir of the target | |
1782 | +file is chosen (top-down-parent policy). | |
1783 | +By user's request, aufs implements some other policies to select the | |
7e9cd9fe AM |
1784 | +writable branch, for file creation several policies, round-robin, |
1785 | +most-free-space, and other policies. For copy-up, top-down-parent, | |
1786 | +bottom-up-parent, bottom-up and others. | |
53392da6 AM |
1787 | + |
1788 | +As expected, the round-robin policy selects the branch in circular. When | |
1789 | +you have two writable branches and creates 10 new files, 5 files will be | |
1790 | +created for each branch. mkdir(2) systemcall is an exception. When you | |
1791 | +create 10 new directories, all will be created on the same branch. | |
1792 | +And the most-free-space policy selects the one which has most free | |
1793 | +space among the writable branches. The amount of free space will be | |
1794 | +checked by aufs internally, and users can specify its time interval. | |
1795 | + | |
1796 | +The policies for copy-up is more simple, | |
1797 | +top-down-parent is equivalent to the same named on in create policy, | |
1798 | +bottom-up-parent selects the writable branch where the parent dir | |
1799 | +exists and the nearest upper one from the copyup-source, | |
1800 | +bottom-up selects the nearest upper writable branch from the | |
1801 | +copyup-source, regardless the existence of the parent dir. | |
1802 | + | |
1803 | +There are some rules or exceptions to apply these policies. | |
1804 | +- If there is a readonly branch above the policy-selected branch and | |
1805 | + the parent dir is marked as opaque (a variation of whiteout), or the | |
1806 | + target (creating) file is whiteout-ed on the upper readonly branch, | |
1807 | + then the result of the policy is ignored and the target file will be | |
1808 | + created on the nearest upper writable branch than the readonly branch. | |
1809 | +- If there is a writable branch above the policy-selected branch and | |
1810 | + the parent dir is marked as opaque or the target file is whiteouted | |
1811 | + on the branch, then the result of the policy is ignored and the target | |
1812 | + file will be created on the highest one among the upper writable | |
1813 | + branches who has diropq or whiteout. In case of whiteout, aufs removes | |
1814 | + it as usual. | |
1815 | +- link(2) and rename(2) systemcalls are exceptions in every policy. | |
1816 | + They try selecting the branch where the source exists as possible | |
1817 | + since copyup a large file will take long time. If it can't be, | |
1818 | + ie. the branch where the source exists is readonly, then they will | |
1819 | + follow the copyup policy. | |
1820 | +- There is an exception for rename(2) when the target exists. | |
1821 | + If the rename target exists, aufs compares the index of the branches | |
1822 | + where the source and the target exists and selects the higher | |
1823 | + one. If the selected branch is readonly, then aufs follows the | |
1824 | + copyup policy. | |
076b876e AM |
1825 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt |
1826 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1827 | +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-09-24 10:47:58.244719488 +0200 |
076b876e AM |
1828 | @@ -0,0 +1,120 @@ |
1829 | + | |
2000de60 | 1830 | +# Copyright (C) 2011-2015 Junjiro R. Okajima |
076b876e AM |
1831 | +# |
1832 | +# This program is free software; you can redistribute it and/or modify | |
1833 | +# it under the terms of the GNU General Public License as published by | |
1834 | +# the Free Software Foundation; either version 2 of the License, or | |
1835 | +# (at your option) any later version. | |
1836 | +# | |
1837 | +# This program is distributed in the hope that it will be useful, | |
1838 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1839 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1840 | +# GNU General Public License for more details. | |
1841 | +# | |
1842 | +# You should have received a copy of the GNU General Public License | |
1843 | +# along with this program; if not, write to the Free Software | |
1844 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1845 | + | |
1846 | + | |
1847 | +File-based Hierarchical Storage Management (FHSM) | |
1848 | +---------------------------------------------------------------------- | |
1849 | +Hierarchical Storage Management (or HSM) is a well-known feature in the | |
1850 | +storage world. Aufs provides this feature as file-based with multiple | |
7e9cd9fe | 1851 | +writable branches, based upon the principle of "Colder, the Lower". |
076b876e | 1852 | +Here the word "colder" means that the less used files, and "lower" means |
7e9cd9fe | 1853 | +that the position in the order of the stacked branches vertically. |
076b876e AM |
1854 | +These multiple writable branches are prioritized, ie. the topmost one |
1855 | +should be the fastest drive and be used heavily. | |
1856 | + | |
1857 | +o Characters in aufs FHSM story | |
1858 | +- aufs itself and a new branch attribute. | |
1859 | +- a new ioctl interface to move-down and to establish a connection with | |
1860 | + the daemon ("move-down" is a converse of "copy-up"). | |
1861 | +- userspace tool and daemon. | |
1862 | + | |
1863 | +The userspace daemon establishes a connection with aufs and waits for | |
1864 | +the notification. The notified information is very similar to struct | |
1865 | +statfs containing the number of consumed blocks and inodes. | |
1866 | +When the consumed blocks/inodes of a branch exceeds the user-specified | |
1867 | +upper watermark, the daemon activates its move-down process until the | |
1868 | +consumed blocks/inodes reaches the user-specified lower watermark. | |
1869 | + | |
1870 | +The actual move-down is done by aufs based upon the request from | |
1871 | +user-space since we need to maintain the inode number and the internal | |
1872 | +pointer arrays in aufs. | |
1873 | + | |
1874 | +Currently aufs FHSM handles the regular files only. Additionally they | |
1875 | +must not be hard-linked nor pseudo-linked. | |
1876 | + | |
1877 | + | |
1878 | +o Cowork of aufs and the user-space daemon | |
1879 | + During the userspace daemon established the connection, aufs sends a | |
1880 | + small notification to it whenever aufs writes something into the | |
1881 | + writable branch. But it may cost high since aufs issues statfs(2) | |
1882 | + internally. So user can specify a new option to cache the | |
1883 | + info. Actually the notification is controlled by these factors. | |
1884 | + + the specified cache time. | |
1885 | + + classified as "force" by aufs internally. | |
1886 | + Until the specified time expires, aufs doesn't send the info | |
1887 | + except the forced cases. When aufs decide forcing, the info is always | |
1888 | + notified to userspace. | |
1889 | + For example, the number of free inodes is generally large enough and | |
1890 | + the shortage of it happens rarely. So aufs doesn't force the | |
1891 | + notification when creating a new file, directory and others. This is | |
1892 | + the typical case which aufs doesn't force. | |
1893 | + When aufs writes the actual filedata and the files consumes any of new | |
1894 | + blocks, the aufs forces notifying. | |
1895 | + | |
1896 | + | |
1897 | +o Interfaces in aufs | |
1898 | +- New branch attribute. | |
1899 | + + fhsm | |
1900 | + Specifies that the branch is managed by FHSM feature. In other word, | |
1901 | + participant in the FHSM. | |
1902 | + When nofhsm is set to the branch, it will not be the source/target | |
1903 | + branch of the move-down operation. This attribute is set | |
1904 | + independently from coo and moo attributes, and if you want full | |
1905 | + FHSM, you should specify them as well. | |
1906 | +- New mount option. | |
1907 | + + fhsm_sec | |
1908 | + Specifies a second to suppress many less important info to be | |
1909 | + notified. | |
1910 | +- New ioctl. | |
1911 | + + AUFS_CTL_FHSM_FD | |
1912 | + create a new file descriptor which userspace can read the notification | |
1913 | + (a subset of struct statfs) from aufs. | |
1914 | +- Module parameter 'brs' | |
1915 | + It has to be set to 1. Otherwise the new mount option 'fhsm' will not | |
1916 | + be set. | |
1917 | +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs | |
1918 | + When there are two or more branches with fhsm attributes, | |
1919 | + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs | |
1920 | + terminates it. As a result of remounting and branch-manipulation, the | |
1921 | + number of branches with fhsm attribute can be one. In this case, | |
1922 | + /sbin/mount.aufs will terminate the user-space daemon. | |
1923 | + | |
1924 | + | |
1925 | +Finally the operation is done as these steps in kernel-space. | |
1926 | +- make sure that, | |
1927 | + + no one else is using the file. | |
1928 | + + the file is not hard-linked. | |
1929 | + + the file is not pseudo-linked. | |
1930 | + + the file is a regular file. | |
1931 | + + the parent dir is not opaqued. | |
1932 | +- find the target writable branch. | |
1933 | +- make sure the file is not whiteout-ed by the upper (than the target) | |
1934 | + branch. | |
1935 | +- make the parent dir on the target branch. | |
1936 | +- mutex lock the inode on the branch. | |
1937 | +- unlink the whiteout on the target branch (if exists). | |
1938 | +- lookup and create the whiteout-ed temporary name on the target branch. | |
1939 | +- copy the file as the whiteout-ed temporary name on the target branch. | |
1940 | +- rename the whiteout-ed temporary name to the original name. | |
1941 | +- unlink the file on the source branch. | |
1942 | +- maintain the internal pointer array and the external inode number | |
1943 | + table (XINO). | |
1944 | +- maintain the timestamps and other attributes of the parent dir and the | |
1945 | + file. | |
1946 | + | |
1947 | +And of course, in every step, an error may happen. So the operation | |
1948 | +should restore the original file state after an error happens. | |
53392da6 AM |
1949 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt |
1950 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 1951 | +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-09-24 10:47:58.244719488 +0200 |
b912730e | 1952 | @@ -0,0 +1,72 @@ |
53392da6 | 1953 | + |
2000de60 | 1954 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
1955 | +# |
1956 | +# This program is free software; you can redistribute it and/or modify | |
1957 | +# it under the terms of the GNU General Public License as published by | |
1958 | +# the Free Software Foundation; either version 2 of the License, or | |
1959 | +# (at your option) any later version. | |
1960 | +# | |
1961 | +# This program is distributed in the hope that it will be useful, | |
1962 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1963 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1964 | +# GNU General Public License for more details. | |
1965 | +# | |
1966 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1967 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1968 | + |
1969 | +mmap(2) -- File Memory Mapping | |
1970 | +---------------------------------------------------------------------- | |
1971 | +In aufs, the file-mapped pages are handled by a branch fs directly, no | |
1972 | +interaction with aufs. It means aufs_mmap() calls the branch fs's | |
1973 | +->mmap(). | |
1974 | +This approach is simple and good, but there is one problem. | |
7e9cd9fe | 1975 | +Under /proc, several entries show the mmapped files by its path (with |
53392da6 AM |
1976 | +device and inode number), and the printed path will be the path on the |
1977 | +branch fs's instead of virtual aufs's. | |
1978 | +This is not a problem in most cases, but some utilities lsof(1) (and its | |
1979 | +user) may expect the path on aufs. | |
1980 | + | |
1981 | +To address this issue, aufs adds a new member called vm_prfile in struct | |
1982 | +vm_area_struct (and struct vm_region). The original vm_file points to | |
1983 | +the file on the branch fs in order to handle everything correctly as | |
1984 | +usual. The new vm_prfile points to a virtual file in aufs, and the | |
1985 | +show-functions in procfs refers to vm_prfile if it is set. | |
1986 | +Also we need to maintain several other places where touching vm_file | |
1987 | +such like | |
1988 | +- fork()/clone() copies vma and the reference count of vm_file is | |
1989 | + incremented. | |
1990 | +- merging vma maintains the ref count too. | |
1991 | + | |
7e9cd9fe | 1992 | +This is not a good approach. It just fakes the printed path. But it |
53392da6 AM |
1993 | +leaves all behaviour around f_mapping unchanged. This is surely an |
1994 | +advantage. | |
1995 | +Actually aufs had adopted another complicated approach which calls | |
1996 | +generic_file_mmap() and handles struct vm_operations_struct. In this | |
1997 | +approach, aufs met a hard problem and I could not solve it without | |
1998 | +switching the approach. | |
b912730e AM |
1999 | + |
2000 | +There may be one more another approach which is | |
2001 | +- bind-mount the branch-root onto the aufs-root internally | |
2002 | +- grab the new vfsmount (ie. struct mount) | |
2003 | +- lazy-umount the branch-root internally | |
2004 | +- in open(2) the aufs-file, open the branch-file with the hidden | |
2005 | + vfsmount (instead of the original branch's vfsmount) | |
2006 | +- ideally this "bind-mount and lazy-umount" should be done atomically, | |
2007 | + but it may be possible from userspace by the mount helper. | |
2008 | + | |
2009 | +Adding the internal hidden vfsmount and using it in opening a file, the | |
2010 | +file path under /proc will be printed correctly. This approach looks | |
2011 | +smarter, but is not possible I am afraid. | |
2012 | +- aufs-root may be bind-mount later. when it happens, another hidden | |
2013 | + vfsmount will be required. | |
2014 | +- it is hard to get the chance to bind-mount and lazy-umount | |
2015 | + + in kernel-space, FS can have vfsmount in open(2) via | |
2016 | + file->f_path, and aufs can know its vfsmount. But several locks are | |
2017 | + already acquired, and if aufs tries to bind-mount and lazy-umount | |
2018 | + here, then it may cause a deadlock. | |
2019 | + + in user-space, bind-mount doesn't invoke the mount helper. | |
2020 | +- since /proc shows dev and ino, aufs has to give vma these info. it | |
2021 | + means a new member vm_prinode will be necessary. this is essentially | |
2022 | + equivalent to vm_prfile described above. | |
2023 | + | |
2024 | +I have to give up this "looks-smater" approach. | |
c1595e42 JR |
2025 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt |
2026 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 2027 | +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-09-24 10:47:58.244719488 +0200 |
c1595e42 JR |
2028 | @@ -0,0 +1,96 @@ |
2029 | + | |
2000de60 | 2030 | +# Copyright (C) 2014-2015 Junjiro R. Okajima |
c1595e42 JR |
2031 | +# |
2032 | +# This program is free software; you can redistribute it and/or modify | |
2033 | +# it under the terms of the GNU General Public License as published by | |
2034 | +# the Free Software Foundation; either version 2 of the License, or | |
2035 | +# (at your option) any later version. | |
2036 | +# | |
2037 | +# This program is distributed in the hope that it will be useful, | |
2038 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2039 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2040 | +# GNU General Public License for more details. | |
2041 | +# | |
2042 | +# You should have received a copy of the GNU General Public License | |
2043 | +# along with this program; if not, write to the Free Software | |
2044 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2045 | + | |
2046 | + | |
2047 | +Listing XATTR/EA and getting the value | |
2048 | +---------------------------------------------------------------------- | |
2049 | +For the inode standard attributes (owner, group, timestamps, etc.), aufs | |
2050 | +shows the values from the topmost existing file. This behaviour is good | |
7e9cd9fe | 2051 | +for the non-dir entries since the bahaviour exactly matches the shown |
c1595e42 JR |
2052 | +information. But for the directories, aufs considers all the same named |
2053 | +entries on the lower branches. Which means, if one of the lower entry | |
2054 | +rejects readdir call, then aufs returns an error even if the topmost | |
2055 | +entry allows it. This behaviour is necessary to respect the branch fs's | |
2056 | +security, but can make users confused since the user-visible standard | |
2057 | +attributes don't match the behaviour. | |
2058 | +To address this issue, aufs has a mount option called dirperm1 which | |
2059 | +checks the permission for the topmost entry only, and ignores the lower | |
2060 | +entry's permission. | |
2061 | + | |
2062 | +A similar issue can happen around XATTR. | |
2063 | +getxattr(2) and listxattr(2) families behave as if dirperm1 option is | |
7e9cd9fe AM |
2064 | +always set. Otherwise these very unpleasant situation would happen. |
2065 | +- listxattr(2) may return the duplicated entries. | |
c1595e42 JR |
2066 | +- users may not be able to remove or reset the XATTR forever, |
2067 | + | |
2068 | + | |
2069 | +XATTR/EA support in the internal (copy,move)-(up,down) | |
2070 | +---------------------------------------------------------------------- | |
7e9cd9fe | 2071 | +Generally the extended attributes of inode are categorized as these. |
c1595e42 JR |
2072 | +- "security" for LSM and capability. |
2073 | +- "system" for posix ACL, 'acl' mount option is required for the branch | |
2074 | + fs generally. | |
2075 | +- "trusted" for userspace, CAP_SYS_ADMIN is required. | |
2076 | +- "user" for userspace, 'user_xattr' mount option is required for the | |
2077 | + branch fs generally. | |
2078 | + | |
2079 | +Moreover there are some other categories. Aufs handles these rather | |
2080 | +unpopular categories as the ordinary ones, ie. there is no special | |
2081 | +condition nor exception. | |
2082 | + | |
2083 | +In copy-up, the support for XATTR on the dst branch may differ from the | |
2084 | +src branch. In this case, the copy-up operation will get an error and | |
7e9cd9fe AM |
2085 | +the original user operation which triggered the copy-up will fail. It |
2086 | +can happen that even all copy-up will fail. | |
c1595e42 JR |
2087 | +When both of src and dst branches support XATTR and if an error occurs |
2088 | +during copying XATTR, then the copy-up should fail obviously. That is a | |
2089 | +good reason and aufs should return an error to userspace. But when only | |
7e9cd9fe | 2090 | +the src branch support that XATTR, aufs should not return an error. |
c1595e42 JR |
2091 | +For example, the src branch supports ACL but the dst branch doesn't |
2092 | +because the dst branch may natively un-support it or temporary | |
2093 | +un-support it due to "noacl" mount option. Of course, the dst branch fs | |
2094 | +may NOT return an error even if the XATTR is not supported. It is | |
2095 | +totally up to the branch fs. | |
2096 | + | |
2097 | +Anyway when the aufs internal copy-up gets an error from the dst branch | |
2098 | +fs, then aufs tries removing the just copied entry and returns the error | |
2099 | +to the userspace. The worst case of this situation will be all copy-up | |
2100 | +will fail. | |
2101 | + | |
2102 | +For the copy-up operation, there two basic approaches. | |
2103 | +- copy the specified XATTR only (by category above), and return the | |
7e9cd9fe | 2104 | + error unconditionally if it happens. |
c1595e42 JR |
2105 | +- copy all XATTR, and ignore the error on the specified category only. |
2106 | + | |
2107 | +In order to support XATTR and to implement the correct behaviour, aufs | |
7e9cd9fe AM |
2108 | +chooses the latter approach and introduces some new branch attributes, |
2109 | +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth". | |
c1595e42 | 2110 | +They correspond to the XATTR namespaces (see above). Additionally, to be |
7e9cd9fe AM |
2111 | +convenient, "icex" is also provided which means all "icex*" attributes |
2112 | +are set (here the word "icex" stands for "ignore copy-error on XATTR"). | |
c1595e42 JR |
2113 | + |
2114 | +The meaning of these attributes is to ignore the error from setting | |
2115 | +XATTR on that branch. | |
2116 | +Note that aufs tries copying all XATTR unconditionally, and ignores the | |
2117 | +error from the dst branch according to the specified attributes. | |
2118 | + | |
2119 | +Some XATTR may have its default value. The default value may come from | |
2120 | +the parent dir or the environment. If the default value is set at the | |
2121 | +file creating-time, it will be overwritten by copy-up. | |
2122 | +Some contradiction may happen I am afraid. | |
2123 | +Do we need another attribute to stop copying XATTR? I am unsure. For | |
2124 | +now, aufs implements the branch attributes to ignore the error. | |
53392da6 AM |
2125 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt |
2126 | --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 2127 | +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-09-24 10:47:58.248052907 +0200 |
523b37e3 | 2128 | @@ -0,0 +1,58 @@ |
53392da6 | 2129 | + |
2000de60 | 2130 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
2131 | +# |
2132 | +# This program is free software; you can redistribute it and/or modify | |
2133 | +# it under the terms of the GNU General Public License as published by | |
2134 | +# the Free Software Foundation; either version 2 of the License, or | |
2135 | +# (at your option) any later version. | |
2136 | +# | |
2137 | +# This program is distributed in the hope that it will be useful, | |
2138 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2139 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2140 | +# GNU General Public License for more details. | |
2141 | +# | |
2142 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2143 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2144 | + |
2145 | +Export Aufs via NFS | |
2146 | +---------------------------------------------------------------------- | |
2147 | +Here is an approach. | |
2148 | +- like xino/xib, add a new file 'xigen' which stores aufs inode | |
2149 | + generation. | |
2150 | +- iget_locked(): initialize aufs inode generation for a new inode, and | |
2151 | + store it in xigen file. | |
2152 | +- destroy_inode(): increment aufs inode generation and store it in xigen | |
2153 | + file. it is necessary even if it is not unlinked, because any data of | |
2154 | + inode may be changed by UDBA. | |
2155 | +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise | |
2156 | + build file handle by | |
2157 | + + branch id (4 bytes) | |
2158 | + + superblock generation (4 bytes) | |
2159 | + + inode number (4 or 8 bytes) | |
2160 | + + parent dir inode number (4 or 8 bytes) | |
2161 | + + inode generation (4 bytes)) | |
2162 | + + return value of exportfs_encode_fh() for the parent on a branch (4 | |
2163 | + bytes) | |
2164 | + + file handle for a branch (by exportfs_encode_fh()) | |
2165 | +- fh_to_dentry(): | |
2166 | + + find the index of a branch from its id in handle, and check it is | |
2167 | + still exist in aufs. | |
2168 | + + 1st level: get the inode number from handle and search it in cache. | |
7e9cd9fe AM |
2169 | + + 2nd level: if not found in cache, get the parent inode number from |
2170 | + the handle and search it in cache. and then open the found parent | |
2171 | + dir, find the matching inode number by vfs_readdir() and get its | |
2172 | + name, and call lookup_one_len() for the target dentry. | |
53392da6 AM |
2173 | + + 3rd level: if the parent dir is not cached, call |
2174 | + exportfs_decode_fh() for a branch and get the parent on a branch, | |
2175 | + build a pathname of it, convert it a pathname in aufs, call | |
2176 | + path_lookup(). now aufs gets a parent dir dentry, then handle it as | |
2177 | + the 2nd level. | |
2178 | + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount | |
2179 | + for every branch, but not itself. to get this, (currently) aufs | |
2180 | + searches in current->nsproxy->mnt_ns list. it may not be a good | |
2181 | + idea, but I didn't get other approach. | |
2182 | + + test the generation of the gotten inode. | |
2183 | +- every inode operation: they may get EBUSY due to UDBA. in this case, | |
2184 | + convert it into ESTALE for NFSD. | |
2185 | +- readdir(): call lockdep_on/off() because filldir in NFSD calls | |
2186 | + lookup_one_len(), vfs_getattr(), encode_fh() and others. | |
2187 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt | |
2188 | --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 2189 | +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-09-24 10:47:58.248052907 +0200 |
523b37e3 | 2190 | @@ -0,0 +1,52 @@ |
53392da6 | 2191 | + |
2000de60 | 2192 | +# Copyright (C) 2005-2015 Junjiro R. Okajima |
53392da6 AM |
2193 | +# |
2194 | +# This program is free software; you can redistribute it and/or modify | |
2195 | +# it under the terms of the GNU General Public License as published by | |
2196 | +# the Free Software Foundation; either version 2 of the License, or | |
2197 | +# (at your option) any later version. | |
2198 | +# | |
2199 | +# This program is distributed in the hope that it will be useful, | |
2200 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2201 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2202 | +# GNU General Public License for more details. | |
2203 | +# | |
2204 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2205 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2206 | + |
2207 | +Show Whiteout Mode (shwh) | |
2208 | +---------------------------------------------------------------------- | |
2209 | +Generally aufs hides the name of whiteouts. But in some cases, to show | |
2210 | +them is very useful for users. For instance, creating a new middle layer | |
2211 | +(branch) by merging existing layers. | |
2212 | + | |
2213 | +(borrowing aufs1 HOW-TO from a user, Michael Towers) | |
2214 | +When you have three branches, | |
2215 | +- Bottom: 'system', squashfs (underlying base system), read-only | |
2216 | +- Middle: 'mods', squashfs, read-only | |
2217 | +- Top: 'overlay', ram (tmpfs), read-write | |
2218 | + | |
2219 | +The top layer is loaded at boot time and saved at shutdown, to preserve | |
2220 | +the changes made to the system during the session. | |
2221 | +When larger changes have been made, or smaller changes have accumulated, | |
2222 | +the size of the saved top layer data grows. At this point, it would be | |
2223 | +nice to be able to merge the two overlay branches ('mods' and 'overlay') | |
2224 | +and rewrite the 'mods' squashfs, clearing the top layer and thus | |
2225 | +restoring save and load speed. | |
2226 | + | |
2227 | +This merging is simplified by the use of another aufs mount, of just the | |
2228 | +two overlay branches using the 'shwh' option. | |
2229 | +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \ | |
2230 | + aufs /livesys/merge_union | |
2231 | + | |
2232 | +A merged view of these two branches is then available at | |
2233 | +/livesys/merge_union, and the new feature is that the whiteouts are | |
2234 | +visible! | |
2235 | +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable | |
2236 | +writing to all branches. Also the default mode for all branches is 'ro'. | |
2237 | +It is now possible to save the combined contents of the two overlay | |
2238 | +branches to a new squashfs, e.g.: | |
2239 | +# mksquashfs /livesys/merge_union /path/to/newmods.squash | |
2240 | + | |
2241 | +This new squashfs archive can be stored on the boot device and the | |
2242 | +initramfs will use it to replace the old one at the next boot. | |
2243 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt | |
2244 | --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 2245 | +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-09-24 10:47:58.248052907 +0200 |
7e9cd9fe | 2246 | @@ -0,0 +1,47 @@ |
53392da6 | 2247 | + |
2000de60 | 2248 | +# Copyright (C) 2010-2015 Junjiro R. Okajima |
53392da6 AM |
2249 | +# |
2250 | +# This program is free software; you can redistribute it and/or modify | |
2251 | +# it under the terms of the GNU General Public License as published by | |
2252 | +# the Free Software Foundation; either version 2 of the License, or | |
2253 | +# (at your option) any later version. | |
2254 | +# | |
2255 | +# This program is distributed in the hope that it will be useful, | |
2256 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2257 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2258 | +# GNU General Public License for more details. | |
2259 | +# | |
2260 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2261 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2262 | + |
2263 | +Dynamically customizable FS operations | |
2264 | +---------------------------------------------------------------------- | |
2265 | +Generally FS operations (struct inode_operations, struct | |
2266 | +address_space_operations, struct file_operations, etc.) are defined as | |
2267 | +"static const", but it never means that FS have only one set of | |
2268 | +operation. Some FS have multiple sets of them. For instance, ext2 has | |
2269 | +three sets, one for XIP, for NOBH, and for normal. | |
2270 | +Since aufs overrides and redirects these operations, sometimes aufs has | |
7e9cd9fe | 2271 | +to change its behaviour according to the branch FS type. More importantly |
53392da6 AM |
2272 | +VFS acts differently if a function (member in the struct) is set or |
2273 | +not. It means aufs should have several sets of operations and select one | |
2274 | +among them according to the branch FS definition. | |
2275 | + | |
7e9cd9fe | 2276 | +In order to solve this problem and not to affect the behaviour of VFS, |
53392da6 | 2277 | +aufs defines these operations dynamically. For instance, aufs defines |
7e9cd9fe AM |
2278 | +dummy direct_IO function for struct address_space_operations, but it may |
2279 | +not be set to the address_space_operations actually. When the branch FS | |
2280 | +doesn't have it, aufs doesn't set it to its address_space_operations | |
2281 | +while the function definition itself is still alive. So the behaviour | |
2282 | +itself will not change, and it will return an error when direct_IO is | |
2283 | +not set. | |
53392da6 AM |
2284 | + |
2285 | +The lifetime of these dynamically generated operation object is | |
2286 | +maintained by aufs branch object. When the branch is removed from aufs, | |
2287 | +the reference counter of the object is decremented. When it reaches | |
2288 | +zero, the dynamically generated operation object will be freed. | |
2289 | + | |
7e9cd9fe AM |
2290 | +This approach is designed to support AIO (io_submit), Direct I/O and |
2291 | +XIP (DAX) mainly. | |
2292 | +Currently this approach is applied to address_space_operations for | |
2293 | +regular files only. | |
53392da6 AM |
2294 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README |
2295 | --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 2296 | +++ linux/Documentation/filesystems/aufs/README 2015-09-24 10:47:58.244719488 +0200 |
5527c038 | 2297 | @@ -0,0 +1,383 @@ |
53392da6 | 2298 | + |
5527c038 | 2299 | +Aufs4 -- advanced multi layered unification filesystem version 4.x |
53392da6 AM |
2300 | +http://aufs.sf.net |
2301 | +Junjiro R. Okajima | |
2302 | + | |
2303 | + | |
2304 | +0. Introduction | |
2305 | +---------------------------------------- | |
2306 | +In the early days, aufs was entirely re-designed and re-implemented | |
7e9cd9fe | 2307 | +Unionfs Version 1.x series. Adding many original ideas, approaches, |
53392da6 AM |
2308 | +improvements and implementations, it becomes totally different from |
2309 | +Unionfs while keeping the basic features. | |
2310 | +Recently, Unionfs Version 2.x series begin taking some of the same | |
2311 | +approaches to aufs1's. | |
2312 | +Unionfs is being developed by Professor Erez Zadok at Stony Brook | |
2313 | +University and his team. | |
2314 | + | |
5527c038 | 2315 | +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3. |
53392da6 AM |
2316 | +If you want older kernel version support, try aufs2-2.6.git or |
2317 | +aufs2-standalone.git repository, aufs1 from CVS on SourceForge. | |
2318 | + | |
2319 | +Note: it becomes clear that "Aufs was rejected. Let's give it up." | |
38d290e6 JR |
2320 | + According to Christoph Hellwig, linux rejects all union-type |
2321 | + filesystems but UnionMount. | |
53392da6 AM |
2322 | +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2> |
2323 | + | |
38d290e6 JR |
2324 | +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and |
2325 | + UnionMount, and he pointed out an issue around a directory mutex | |
2326 | + lock and aufs addressed it. But it is still unsure whether aufs will | |
2327 | + be merged (or any other union solution). | |
076b876e | 2328 | +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1> |
38d290e6 | 2329 | + |
53392da6 AM |
2330 | + |
2331 | +1. Features | |
2332 | +---------------------------------------- | |
2333 | +- unite several directories into a single virtual filesystem. The member | |
2334 | + directory is called as a branch. | |
2335 | +- you can specify the permission flags to the branch, which are 'readonly', | |
2336 | + 'readwrite' and 'whiteout-able.' | |
2337 | +- by upper writable branch, internal copyup and whiteout, files/dirs on | |
2338 | + readonly branch are modifiable logically. | |
2339 | +- dynamic branch manipulation, add, del. | |
2340 | +- etc... | |
2341 | + | |
7e9cd9fe AM |
2342 | +Also there are many enhancements in aufs, such as: |
2343 | +- test only the highest one for the directory permission (dirperm1) | |
2344 | +- copyup on open (coo=) | |
2345 | +- 'move' policy for copy-up between two writable branches, after | |
2346 | + checking free space. | |
2347 | +- xattr, acl | |
53392da6 AM |
2348 | +- readdir(3) in userspace. |
2349 | +- keep inode number by external inode number table | |
2350 | +- keep the timestamps of file/dir in internal copyup operation | |
2351 | +- seekable directory, supporting NFS readdir. | |
2352 | +- whiteout is hardlinked in order to reduce the consumption of inodes | |
2353 | + on branch | |
2354 | +- do not copyup, nor create a whiteout when it is unnecessary | |
2355 | +- revert a single systemcall when an error occurs in aufs | |
2356 | +- remount interface instead of ioctl | |
2357 | +- maintain /etc/mtab by an external command, /sbin/mount.aufs. | |
2358 | +- loopback mounted filesystem as a branch | |
2359 | +- kernel thread for removing the dir who has a plenty of whiteouts | |
2360 | +- support copyup sparse file (a file which has a 'hole' in it) | |
2361 | +- default permission flags for branches | |
2362 | +- selectable permission flags for ro branch, whether whiteout can | |
2363 | + exist or not | |
2364 | +- export via NFS. | |
2365 | +- support <sysfs>/fs/aufs and <debugfs>/aufs. | |
2366 | +- support multiple writable branches, some policies to select one | |
2367 | + among multiple writable branches. | |
2368 | +- a new semantics for link(2) and rename(2) to support multiple | |
2369 | + writable branches. | |
2370 | +- no glibc changes are required. | |
2371 | +- pseudo hardlink (hardlink over branches) | |
2372 | +- allow a direct access manually to a file on branch, e.g. bypassing aufs. | |
2373 | + including NFS or remote filesystem branch. | |
2374 | +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX. | |
2375 | +- and more... | |
2376 | + | |
5527c038 | 2377 | +Currently these features are dropped temporary from aufs4. |
53392da6 | 2378 | +See design/08plan.txt in detail. |
53392da6 AM |
2379 | +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs |
2380 | + (robr) | |
2381 | +- statistics of aufs thread (/sys/fs/aufs/stat) | |
53392da6 AM |
2382 | + |
2383 | +Features or just an idea in the future (see also design/*.txt), | |
2384 | +- reorder the branch index without del/re-add. | |
2385 | +- permanent xino files for NFSD | |
2386 | +- an option for refreshing the opened files after add/del branches | |
53392da6 AM |
2387 | +- light version, without branch manipulation. (unnecessary?) |
2388 | +- copyup in userspace | |
2389 | +- inotify in userspace | |
2390 | +- readv/writev | |
53392da6 AM |
2391 | + |
2392 | + | |
2393 | +2. Download | |
2394 | +---------------------------------------- | |
5527c038 JR |
2395 | +There are three GIT trees for aufs4, aufs4-linux.git, |
2396 | +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in | |
1e00d052 | 2397 | +"aufs-util.git." |
5527c038 JR |
2398 | +While the aufs-util is always necessary, you need either of aufs4-linux |
2399 | +or aufs4-standalone. | |
1e00d052 | 2400 | + |
5527c038 | 2401 | +The aufs4-linux tree includes the whole linux mainline GIT tree, |
1e00d052 AM |
2402 | +git://git.kernel.org/.../torvalds/linux.git. |
2403 | +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot | |
5527c038 | 2404 | +build aufs4 as an external kernel module. |
2000de60 | 2405 | +Several extra patches are not included in this tree. Only |
5527c038 | 2406 | +aufs4-standalone tree contains them. They are describe in the later |
2000de60 | 2407 | +section "Configuration and Compilation." |
1e00d052 | 2408 | + |
5527c038 | 2409 | +On the other hand, the aufs4-standalone tree has only aufs source files |
53392da6 | 2410 | +and necessary patches, and you can select CONFIG_AUFS_FS=m. |
2000de60 | 2411 | +But you need to apply all aufs patches manually. |
53392da6 | 2412 | + |
5527c038 JR |
2413 | +You will find GIT branches whose name is in form of "aufs4.x" where "x" |
2414 | +represents the linux kernel version, "linux-4.x". For instance, | |
2415 | +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use | |
2416 | +"aufs4.x-rcN" branch. | |
1e00d052 | 2417 | + |
5527c038 | 2418 | +o aufs4-linux tree |
1e00d052 | 2419 | +$ git clone --reference /your/linux/git/tree \ |
5527c038 | 2420 | + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git |
1e00d052 | 2421 | +- if you don't have linux GIT tree, then remove "--reference ..." |
5527c038 JR |
2422 | +$ cd aufs4-linux.git |
2423 | +$ git checkout origin/aufs4.0 | |
53392da6 | 2424 | + |
2000de60 JR |
2425 | +Or You may want to directly git-pull aufs into your linux GIT tree, and |
2426 | +leave the patch-work to GIT. | |
2427 | +$ cd /your/linux/git/tree | |
5527c038 JR |
2428 | +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git |
2429 | +$ git fetch aufs4 | |
2430 | +$ git checkout -b my4.0 v4.0 | |
2431 | +$ (add your local change...) | |
2432 | +$ git pull aufs4 aufs4.0 | |
2433 | +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch. | |
2000de60 | 2434 | +- you may need to solve some conflicts between your_changes and |
5527c038 JR |
2435 | + aufs4.0. in this case, git-rerere is recommended so that you can |
2436 | + solve the similar conflicts automatically when you upgrade to 4.1 or | |
2000de60 JR |
2437 | + later in the future. |
2438 | + | |
5527c038 JR |
2439 | +o aufs4-standalone tree |
2440 | +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git | |
2441 | +$ cd aufs4-standalone.git | |
2442 | +$ git checkout origin/aufs4.0 | |
53392da6 AM |
2443 | + |
2444 | +o aufs-util tree | |
5527c038 JR |
2445 | +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git |
2446 | +- note that the public aufs-util.git is on SourceForge instead of | |
2447 | + GitHUB. | |
53392da6 | 2448 | +$ cd aufs-util.git |
5527c038 | 2449 | +$ git checkout origin/aufs4.0 |
53392da6 | 2450 | + |
5527c038 JR |
2451 | +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY. |
2452 | +The minor version number, 'x' in '4.x', of aufs may not always | |
9dbd164d AM |
2453 | +follow the minor version number of the kernel. |
2454 | +Because changes in the kernel that cause the use of a new | |
2455 | +minor version number do not always require changes to aufs-util. | |
2456 | + | |
2457 | +Since aufs-util has its own minor version number, you may not be | |
2458 | +able to find a GIT branch in aufs-util for your kernel's | |
2459 | +exact minor version number. | |
2460 | +In this case, you should git-checkout the branch for the | |
53392da6 | 2461 | +nearest lower number. |
9dbd164d AM |
2462 | + |
2463 | +For (an unreleased) example: | |
5527c038 JR |
2464 | +If you are using "linux-4.10" and the "aufs4.10" branch |
2465 | +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8" | |
9dbd164d AM |
2466 | +or something numerically smaller is the branch for your kernel. |
2467 | + | |
53392da6 AM |
2468 | +Also you can view all branches by |
2469 | + $ git branch -a | |
2470 | + | |
2471 | + | |
2472 | +3. Configuration and Compilation | |
2473 | +---------------------------------------- | |
2474 | +Make sure you have git-checkout'ed the correct branch. | |
2475 | + | |
5527c038 | 2476 | +For aufs4-linux tree, |
c06a8ce3 | 2477 | +- enable CONFIG_AUFS_FS. |
1e00d052 AM |
2478 | +- set other aufs configurations if necessary. |
2479 | + | |
5527c038 | 2480 | +For aufs4-standalone tree, |
53392da6 AM |
2481 | +There are several ways to build. |
2482 | + | |
2483 | +1. | |
5527c038 JR |
2484 | +- apply ./aufs4-kbuild.patch to your kernel source files. |
2485 | +- apply ./aufs4-base.patch too. | |
2486 | +- apply ./aufs4-mmap.patch too. | |
2487 | +- apply ./aufs4-standalone.patch too, if you have a plan to set | |
2488 | + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch. | |
537831f9 AM |
2489 | +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your |
2490 | + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild. | |
c06a8ce3 | 2491 | +- enable CONFIG_AUFS_FS, you can select either |
53392da6 AM |
2492 | + =m or =y. |
2493 | +- and build your kernel as usual. | |
2494 | +- install the built kernel. | |
c06a8ce3 AM |
2495 | + Note: Since linux-3.9, every filesystem module requires an alias |
2496 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2497 | + modules.aliases file if you set CONFIG_AUFS_FS=m. | |
7eafdf33 AM |
2498 | +- install the header files too by "make headers_install" to the |
2499 | + directory where you specify. By default, it is $PWD/usr. | |
b4510431 | 2500 | + "make help" shows a brief note for headers_install. |
53392da6 AM |
2501 | +- and reboot your system. |
2502 | + | |
2503 | +2. | |
2504 | +- module only (CONFIG_AUFS_FS=m). | |
5527c038 JR |
2505 | +- apply ./aufs4-base.patch to your kernel source files. |
2506 | +- apply ./aufs4-mmap.patch too. | |
2507 | +- apply ./aufs4-standalone.patch too. | |
53392da6 AM |
2508 | +- build your kernel, don't forget "make headers_install", and reboot. |
2509 | +- edit ./config.mk and set other aufs configurations if necessary. | |
b4510431 | 2510 | + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes |
53392da6 AM |
2511 | + every aufs configurations. |
2512 | +- build the module by simple "make". | |
c06a8ce3 AM |
2513 | + Note: Since linux-3.9, every filesystem module requires an alias |
2514 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2515 | + modules.aliases file. | |
53392da6 AM |
2516 | +- you can specify ${KDIR} make variable which points to your kernel |
2517 | + source tree. | |
2518 | +- install the files | |
2519 | + + run "make install" to install the aufs module, or copy the built | |
b4510431 AM |
2520 | + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply). |
2521 | + + run "make install_headers" (instead of headers_install) to install | |
2522 | + the modified aufs header file (you can specify DESTDIR which is | |
2523 | + available in aufs standalone version's Makefile only), or copy | |
2524 | + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever | |
2525 | + you like manually. By default, the target directory is $PWD/usr. | |
5527c038 | 2526 | +- no need to apply aufs4-kbuild.patch, nor copying source files to your |
53392da6 AM |
2527 | + kernel source tree. |
2528 | + | |
b4510431 | 2529 | +Note: The header file aufs_type.h is necessary to build aufs-util |
53392da6 AM |
2530 | + as well as "make headers_install" in the kernel source tree. |
2531 | + headers_install is subject to be forgotten, but it is essentially | |
2532 | + necessary, not only for building aufs-util. | |
2533 | + You may not meet problems without headers_install in some older | |
2534 | + version though. | |
2535 | + | |
2536 | +And then, | |
2537 | +- read README in aufs-util, build and install it | |
9dbd164d AM |
2538 | +- note that your distribution may contain an obsoleted version of |
2539 | + aufs_type.h in /usr/include/linux or something. When you build aufs | |
2540 | + utilities, make sure that your compiler refers the correct aufs header | |
2541 | + file which is built by "make headers_install." | |
53392da6 AM |
2542 | +- if you want to use readdir(3) in userspace or pathconf(3) wrapper, |
2543 | + then run "make install_ulib" too. And refer to the aufs manual in | |
2544 | + detail. | |
2545 | + | |
5527c038 | 2546 | +There several other patches in aufs4-standalone.git. They are all |
38d290e6 | 2547 | +optional. When you meet some problems, they will help you. |
5527c038 | 2548 | +- aufs4-loopback.patch |
38d290e6 JR |
2549 | + Supports a nested loopback mount in a branch-fs. This patch is |
2550 | + unnecessary until aufs produces a message like "you may want to try | |
2551 | + another patch for loopback file". | |
2552 | +- vfs-ino.patch | |
2553 | + Modifies a system global kernel internal function get_next_ino() in | |
2554 | + order to stop assigning 0 for an inode-number. Not directly related to | |
2555 | + aufs, but recommended generally. | |
2556 | +- tmpfs-idr.patch | |
2557 | + Keeps the tmpfs inode number as the lowest value. Effective to reduce | |
2558 | + the size of aufs XINO files for tmpfs branch. Also it prevents the | |
2559 | + duplication of inode number, which is important for backup tools and | |
2560 | + other utilities. When you find aufs XINO files for tmpfs branch | |
2561 | + growing too much, try this patch. | |
2562 | + | |
53392da6 AM |
2563 | + |
2564 | +4. Usage | |
2565 | +---------------------------------------- | |
2566 | +At first, make sure aufs-util are installed, and please read the aufs | |
2567 | +manual, aufs.5 in aufs-util.git tree. | |
2568 | +$ man -l aufs.5 | |
2569 | + | |
2570 | +And then, | |
2571 | +$ mkdir /tmp/rw /tmp/aufs | |
2572 | +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs | |
2573 | + | |
2574 | +Here is another example. The result is equivalent. | |
2575 | +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs | |
2576 | + Or | |
2577 | +# mount -t aufs -o br:/tmp/rw none /tmp/aufs | |
2578 | +# mount -o remount,append:${HOME} /tmp/aufs | |
2579 | + | |
2580 | +Then, you can see whole tree of your home dir through /tmp/aufs. If | |
2581 | +you modify a file under /tmp/aufs, the one on your home directory is | |
2582 | +not affected, instead the same named file will be newly created under | |
2583 | +/tmp/rw. And all of your modification to a file will be applied to | |
2584 | +the one under /tmp/rw. This is called the file based Copy on Write | |
2585 | +(COW) method. | |
2586 | +Aufs mount options are described in aufs.5. | |
2587 | +If you run chroot or something and make your aufs as a root directory, | |
2588 | +then you need to customize the shutdown script. See the aufs manual in | |
2589 | +detail. | |
2590 | + | |
2591 | +Additionally, there are some sample usages of aufs which are a | |
2592 | +diskless system with network booting, and LiveCD over NFS. | |
2593 | +See sample dir in CVS tree on SourceForge. | |
2594 | + | |
2595 | + | |
2596 | +5. Contact | |
2597 | +---------------------------------------- | |
2598 | +When you have any problems or strange behaviour in aufs, please let me | |
2599 | +know with: | |
2600 | +- /proc/mounts (instead of the output of mount(8)) | |
2601 | +- /sys/module/aufs/* | |
2602 | +- /sys/fs/aufs/* (if you have them) | |
2603 | +- /debug/aufs/* (if you have them) | |
2604 | +- linux kernel version | |
2605 | + if your kernel is not plain, for example modified by distributor, | |
2606 | + the url where i can download its source is necessary too. | |
2607 | +- aufs version which was printed at loading the module or booting the | |
2608 | + system, instead of the date you downloaded. | |
2609 | +- configuration (define/undefine CONFIG_AUFS_xxx) | |
2610 | +- kernel configuration or /proc/config.gz (if you have it) | |
2611 | +- behaviour which you think to be incorrect | |
2612 | +- actual operation, reproducible one is better | |
2613 | +- mailto: aufs-users at lists.sourceforge.net | |
2614 | + | |
2615 | +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches, | |
2616 | +and Feature Requests) on SourceForge. Please join and write to | |
2617 | +aufs-users ML. | |
2618 | + | |
2619 | + | |
2620 | +6. Acknowledgements | |
2621 | +---------------------------------------- | |
2622 | +Thanks to everyone who have tried and are using aufs, whoever | |
2623 | +have reported a bug or any feedback. | |
2624 | + | |
2625 | +Especially donators: | |
2626 | +Tomas Matejicek(slax.org) made a donation (much more than once). | |
2627 | + Since Apr 2010, Tomas M (the author of Slax and Linux Live | |
2628 | + scripts) is making "doubling" donations. | |
2629 | + Unfortunately I cannot list all of the donators, but I really | |
b4510431 | 2630 | + appreciate. |
53392da6 AM |
2631 | + It ends Aug 2010, but the ordinary donation URL is still available. |
2632 | + <http://sourceforge.net/donate/index.php?group_id=167503> | |
2633 | +Dai Itasaka made a donation (2007/8). | |
2634 | +Chuck Smith made a donation (2008/4, 10 and 12). | |
2635 | +Henk Schoneveld made a donation (2008/9). | |
2636 | +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10). | |
2637 | +Francois Dupoux made a donation (2008/11). | |
2638 | +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public | |
2639 | + aufs2 GIT tree (2009/2). | |
2640 | +William Grant made a donation (2009/3). | |
2641 | +Patrick Lane made a donation (2009/4). | |
2642 | +The Mail Archive (mail-archive.com) made donations (2009/5). | |
2643 | +Nippy Networks (Ed Wildgoose) made a donation (2009/7). | |
2644 | +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11). | |
2645 | +Pavel Pronskiy made a donation (2011/2). | |
2646 | +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy | |
2647 | + Networks (Ed Wildgoose) made a donation for hardware (2011/3). | |
537831f9 AM |
2648 | +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and |
2649 | +11). | |
1e00d052 | 2650 | +Sam Liddicott made a donation (2011/9). |
86dc4139 AM |
2651 | +Era Scarecrow made a donation (2013/4). |
2652 | +Bor Ratajc made a donation (2013/4). | |
2653 | +Alessandro Gorreta made a donation (2013/4). | |
2654 | +POIRETTE Marc made a donation (2013/4). | |
2655 | +Alessandro Gorreta made a donation (2013/4). | |
2656 | +lauri kasvandik made a donation (2013/5). | |
392086de | 2657 | +"pemasu from Finland" made a donation (2013/7). |
523b37e3 AM |
2658 | +The Parted Magic Project made a donation (2013/9 and 11). |
2659 | +Pavel Barta made a donation (2013/10). | |
38d290e6 | 2660 | +Nikolay Pertsev made a donation (2014/5). |
c2c0f25c | 2661 | +James B made a donation (2014/7 and 2015/7). |
076b876e | 2662 | +Stefano Di Biase made a donation (2014/8). |
2000de60 | 2663 | +Daniel Epellei made a donation (2015/1). |
53392da6 AM |
2664 | + |
2665 | +Thank you very much. | |
2666 | +Donations are always, including future donations, very important and | |
2667 | +helpful for me to keep on developing aufs. | |
2668 | + | |
2669 | + | |
2670 | +7. | |
2671 | +---------------------------------------- | |
2672 | +If you are an experienced user, no explanation is needed. Aufs is | |
2673 | +just a linux filesystem. | |
2674 | + | |
2675 | + | |
2676 | +Enjoy! | |
2677 | + | |
2678 | +# Local variables: ; | |
2679 | +# mode: text; | |
2680 | +# End: ; | |
7f207e10 AM |
2681 | diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h |
2682 | --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 2683 | +++ linux/fs/aufs/aufs.h 2015-09-24 10:47:58.248052907 +0200 |
523b37e3 | 2684 | @@ -0,0 +1,59 @@ |
7f207e10 | 2685 | +/* |
2000de60 | 2686 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
7f207e10 AM |
2687 | + * |
2688 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2689 | + * it under the terms of the GNU General Public License as published by | |
2690 | + * the Free Software Foundation; either version 2 of the License, or | |
2691 | + * (at your option) any later version. | |
2692 | + * | |
2693 | + * This program is distributed in the hope that it will be useful, | |
2694 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2695 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2696 | + * GNU General Public License for more details. | |
2697 | + * | |
2698 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2699 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2700 | + */ |
2701 | + | |
2702 | +/* | |
2703 | + * all header files | |
2704 | + */ | |
2705 | + | |
2706 | +#ifndef __AUFS_H__ | |
2707 | +#define __AUFS_H__ | |
2708 | + | |
2709 | +#ifdef __KERNEL__ | |
2710 | + | |
2711 | +#define AuStub(type, name, body, ...) \ | |
2712 | + static inline type name(__VA_ARGS__) { body; } | |
2713 | + | |
2714 | +#define AuStubVoid(name, ...) \ | |
2715 | + AuStub(void, name, , __VA_ARGS__) | |
2716 | +#define AuStubInt0(name, ...) \ | |
2717 | + AuStub(int, name, return 0, __VA_ARGS__) | |
2718 | + | |
2719 | +#include "debug.h" | |
2720 | + | |
2721 | +#include "branch.h" | |
2722 | +#include "cpup.h" | |
2723 | +#include "dcsub.h" | |
2724 | +#include "dbgaufs.h" | |
2725 | +#include "dentry.h" | |
2726 | +#include "dir.h" | |
2727 | +#include "dynop.h" | |
2728 | +#include "file.h" | |
2729 | +#include "fstype.h" | |
2730 | +#include "inode.h" | |
2731 | +#include "loop.h" | |
2732 | +#include "module.h" | |
7f207e10 AM |
2733 | +#include "opts.h" |
2734 | +#include "rwsem.h" | |
2735 | +#include "spl.h" | |
2736 | +#include "super.h" | |
2737 | +#include "sysaufs.h" | |
2738 | +#include "vfsub.h" | |
2739 | +#include "whout.h" | |
2740 | +#include "wkq.h" | |
2741 | + | |
2742 | +#endif /* __KERNEL__ */ | |
2743 | +#endif /* __AUFS_H__ */ | |
2744 | diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c | |
2745 | --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 2746 | +++ linux/fs/aufs/branch.c 2015-09-24 10:47:58.248052907 +0200 |
5527c038 | 2747 | @@ -0,0 +1,1414 @@ |
7f207e10 | 2748 | +/* |
2000de60 | 2749 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
7f207e10 AM |
2750 | + * |
2751 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2752 | + * it under the terms of the GNU General Public License as published by | |
2753 | + * the Free Software Foundation; either version 2 of the License, or | |
2754 | + * (at your option) any later version. | |
2755 | + * | |
2756 | + * This program is distributed in the hope that it will be useful, | |
2757 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2758 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2759 | + * GNU General Public License for more details. | |
2760 | + * | |
2761 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2762 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2763 | + */ |
2764 | + | |
2765 | +/* | |
2766 | + * branch management | |
2767 | + */ | |
2768 | + | |
027c5e7a | 2769 | +#include <linux/compat.h> |
7f207e10 AM |
2770 | +#include <linux/statfs.h> |
2771 | +#include "aufs.h" | |
2772 | + | |
2773 | +/* | |
2774 | + * free a single branch | |
1facf9fc | 2775 | + */ |
2776 | +static void au_br_do_free(struct au_branch *br) | |
2777 | +{ | |
2778 | + int i; | |
2779 | + struct au_wbr *wbr; | |
4a4d8108 | 2780 | + struct au_dykey **key; |
1facf9fc | 2781 | + |
027c5e7a AM |
2782 | + au_hnotify_fin_br(br); |
2783 | + | |
1facf9fc | 2784 | + if (br->br_xino.xi_file) |
2785 | + fput(br->br_xino.xi_file); | |
2786 | + mutex_destroy(&br->br_xino.xi_nondir_mtx); | |
2787 | + | |
2788 | + AuDebugOn(atomic_read(&br->br_count)); | |
2789 | + | |
2790 | + wbr = br->br_wbr; | |
2791 | + if (wbr) { | |
2792 | + for (i = 0; i < AuBrWh_Last; i++) | |
2793 | + dput(wbr->wbr_wh[i]); | |
2794 | + AuDebugOn(atomic_read(&wbr->wbr_wh_running)); | |
dece6358 | 2795 | + AuRwDestroy(&wbr->wbr_wh_rwsem); |
1facf9fc | 2796 | + } |
2797 | + | |
076b876e AM |
2798 | + if (br->br_fhsm) { |
2799 | + au_br_fhsm_fin(br->br_fhsm); | |
2800 | + kfree(br->br_fhsm); | |
2801 | + } | |
2802 | + | |
4a4d8108 AM |
2803 | + key = br->br_dykey; |
2804 | + for (i = 0; i < AuBrDynOp; i++, key++) | |
2805 | + if (*key) | |
2806 | + au_dy_put(*key); | |
2807 | + else | |
2808 | + break; | |
2809 | + | |
537831f9 AM |
2810 | + /* recursive lock, s_umount of branch's */ |
2811 | + lockdep_off(); | |
86dc4139 | 2812 | + path_put(&br->br_path); |
537831f9 | 2813 | + lockdep_on(); |
1facf9fc | 2814 | + kfree(wbr); |
2815 | + kfree(br); | |
2816 | +} | |
2817 | + | |
2818 | +/* | |
2819 | + * frees all branches | |
2820 | + */ | |
2821 | +void au_br_free(struct au_sbinfo *sbinfo) | |
2822 | +{ | |
2823 | + aufs_bindex_t bmax; | |
2824 | + struct au_branch **br; | |
2825 | + | |
dece6358 AM |
2826 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
2827 | + | |
1facf9fc | 2828 | + bmax = sbinfo->si_bend + 1; |
2829 | + br = sbinfo->si_branch; | |
2830 | + while (bmax--) | |
2831 | + au_br_do_free(*br++); | |
2832 | +} | |
2833 | + | |
2834 | +/* | |
2835 | + * find the index of a branch which is specified by @br_id. | |
2836 | + */ | |
2837 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id) | |
2838 | +{ | |
2839 | + aufs_bindex_t bindex, bend; | |
2840 | + | |
2841 | + bend = au_sbend(sb); | |
2842 | + for (bindex = 0; bindex <= bend; bindex++) | |
2843 | + if (au_sbr_id(sb, bindex) == br_id) | |
2844 | + return bindex; | |
2845 | + return -1; | |
2846 | +} | |
2847 | + | |
2848 | +/* ---------------------------------------------------------------------- */ | |
2849 | + | |
2850 | +/* | |
2851 | + * add a branch | |
2852 | + */ | |
2853 | + | |
b752ccd1 AM |
2854 | +static int test_overlap(struct super_block *sb, struct dentry *h_adding, |
2855 | + struct dentry *h_root) | |
1facf9fc | 2856 | +{ |
b752ccd1 AM |
2857 | + if (unlikely(h_adding == h_root |
2858 | + || au_test_loopback_overlap(sb, h_adding))) | |
1facf9fc | 2859 | + return 1; |
b752ccd1 AM |
2860 | + if (h_adding->d_sb != h_root->d_sb) |
2861 | + return 0; | |
2862 | + return au_test_subdir(h_adding, h_root) | |
2863 | + || au_test_subdir(h_root, h_adding); | |
1facf9fc | 2864 | +} |
2865 | + | |
2866 | +/* | |
2867 | + * returns a newly allocated branch. @new_nbranch is a number of branches | |
2868 | + * after adding a branch. | |
2869 | + */ | |
2870 | +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch, | |
2871 | + int perm) | |
2872 | +{ | |
2873 | + struct au_branch *add_branch; | |
2874 | + struct dentry *root; | |
5527c038 | 2875 | + struct inode *inode; |
4a4d8108 | 2876 | + int err; |
1facf9fc | 2877 | + |
4a4d8108 | 2878 | + err = -ENOMEM; |
1facf9fc | 2879 | + root = sb->s_root; |
2880 | + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS); | |
2881 | + if (unlikely(!add_branch)) | |
2882 | + goto out; | |
2883 | + | |
027c5e7a AM |
2884 | + err = au_hnotify_init_br(add_branch, perm); |
2885 | + if (unlikely(err)) | |
2886 | + goto out_br; | |
2887 | + | |
1facf9fc | 2888 | + add_branch->br_wbr = NULL; |
2889 | + if (au_br_writable(perm)) { | |
2890 | + /* may be freed separately at changing the branch permission */ | |
2891 | + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr), | |
2892 | + GFP_NOFS); | |
2893 | + if (unlikely(!add_branch->br_wbr)) | |
027c5e7a | 2894 | + goto out_hnotify; |
1facf9fc | 2895 | + } |
2896 | + | |
076b876e AM |
2897 | + add_branch->br_fhsm = NULL; |
2898 | + if (au_br_fhsm(perm)) { | |
2899 | + err = au_fhsm_br_alloc(add_branch); | |
2900 | + if (unlikely(err)) | |
2901 | + goto out_wbr; | |
2902 | + } | |
2903 | + | |
4a4d8108 AM |
2904 | + err = au_sbr_realloc(au_sbi(sb), new_nbranch); |
2905 | + if (!err) | |
2906 | + err = au_di_realloc(au_di(root), new_nbranch); | |
5527c038 JR |
2907 | + if (!err) { |
2908 | + inode = d_inode(root); | |
2909 | + err = au_ii_realloc(au_ii(inode), new_nbranch); | |
2910 | + } | |
4a4d8108 AM |
2911 | + if (!err) |
2912 | + return add_branch; /* success */ | |
1facf9fc | 2913 | + |
076b876e | 2914 | +out_wbr: |
1facf9fc | 2915 | + kfree(add_branch->br_wbr); |
027c5e7a AM |
2916 | +out_hnotify: |
2917 | + au_hnotify_fin_br(add_branch); | |
4f0767ce | 2918 | +out_br: |
1facf9fc | 2919 | + kfree(add_branch); |
4f0767ce | 2920 | +out: |
4a4d8108 | 2921 | + return ERR_PTR(err); |
1facf9fc | 2922 | +} |
2923 | + | |
2924 | +/* | |
2925 | + * test if the branch permission is legal or not. | |
2926 | + */ | |
2927 | +static int test_br(struct inode *inode, int brperm, char *path) | |
2928 | +{ | |
2929 | + int err; | |
2930 | + | |
4a4d8108 AM |
2931 | + err = (au_br_writable(brperm) && IS_RDONLY(inode)); |
2932 | + if (!err) | |
2933 | + goto out; | |
1facf9fc | 2934 | + |
4a4d8108 AM |
2935 | + err = -EINVAL; |
2936 | + pr_err("write permission for readonly mount or inode, %s\n", path); | |
2937 | + | |
4f0767ce | 2938 | +out: |
1facf9fc | 2939 | + return err; |
2940 | +} | |
2941 | + | |
2942 | +/* | |
2943 | + * returns: | |
2944 | + * 0: success, the caller will add it | |
2945 | + * plus: success, it is already unified, the caller should ignore it | |
2946 | + * minus: error | |
2947 | + */ | |
2948 | +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
2949 | +{ | |
2950 | + int err; | |
2951 | + aufs_bindex_t bend, bindex; | |
5527c038 | 2952 | + struct dentry *root, *h_dentry; |
1facf9fc | 2953 | + struct inode *inode, *h_inode; |
2954 | + | |
2955 | + root = sb->s_root; | |
2956 | + bend = au_sbend(sb); | |
2957 | + if (unlikely(bend >= 0 | |
2958 | + && au_find_dbindex(root, add->path.dentry) >= 0)) { | |
2959 | + err = 1; | |
2960 | + if (!remount) { | |
2961 | + err = -EINVAL; | |
4a4d8108 | 2962 | + pr_err("%s duplicated\n", add->pathname); |
1facf9fc | 2963 | + } |
2964 | + goto out; | |
2965 | + } | |
2966 | + | |
2967 | + err = -ENOSPC; /* -E2BIG; */ | |
2968 | + if (unlikely(AUFS_BRANCH_MAX <= add->bindex | |
2969 | + || AUFS_BRANCH_MAX - 1 <= bend)) { | |
4a4d8108 | 2970 | + pr_err("number of branches exceeded %s\n", add->pathname); |
1facf9fc | 2971 | + goto out; |
2972 | + } | |
2973 | + | |
2974 | + err = -EDOM; | |
2975 | + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) { | |
4a4d8108 | 2976 | + pr_err("bad index %d\n", add->bindex); |
1facf9fc | 2977 | + goto out; |
2978 | + } | |
2979 | + | |
5527c038 | 2980 | + inode = d_inode(add->path.dentry); |
1facf9fc | 2981 | + err = -ENOENT; |
2982 | + if (unlikely(!inode->i_nlink)) { | |
4a4d8108 | 2983 | + pr_err("no existence %s\n", add->pathname); |
1facf9fc | 2984 | + goto out; |
2985 | + } | |
2986 | + | |
2987 | + err = -EINVAL; | |
2988 | + if (unlikely(inode->i_sb == sb)) { | |
4a4d8108 | 2989 | + pr_err("%s must be outside\n", add->pathname); |
1facf9fc | 2990 | + goto out; |
2991 | + } | |
2992 | + | |
2993 | + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) { | |
4a4d8108 AM |
2994 | + pr_err("unsupported filesystem, %s (%s)\n", |
2995 | + add->pathname, au_sbtype(inode->i_sb)); | |
1facf9fc | 2996 | + goto out; |
2997 | + } | |
2998 | + | |
c1595e42 JR |
2999 | + if (unlikely(inode->i_sb->s_stack_depth)) { |
3000 | + pr_err("already stacked, %s (%s)\n", | |
3001 | + add->pathname, au_sbtype(inode->i_sb)); | |
3002 | + goto out; | |
3003 | + } | |
3004 | + | |
5527c038 | 3005 | + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname); |
1facf9fc | 3006 | + if (unlikely(err)) |
3007 | + goto out; | |
3008 | + | |
3009 | + if (bend < 0) | |
3010 | + return 0; /* success */ | |
3011 | + | |
3012 | + err = -EINVAL; | |
3013 | + for (bindex = 0; bindex <= bend; bindex++) | |
3014 | + if (unlikely(test_overlap(sb, add->path.dentry, | |
3015 | + au_h_dptr(root, bindex)))) { | |
4a4d8108 | 3016 | + pr_err("%s is overlapped\n", add->pathname); |
1facf9fc | 3017 | + goto out; |
3018 | + } | |
3019 | + | |
3020 | + err = 0; | |
3021 | + if (au_opt_test(au_mntflags(sb), WARN_PERM)) { | |
5527c038 JR |
3022 | + h_dentry = au_h_dptr(root, 0); |
3023 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 3024 | + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO) |
0c3ec466 AM |
3025 | + || !uid_eq(h_inode->i_uid, inode->i_uid) |
3026 | + || !gid_eq(h_inode->i_gid, inode->i_gid)) | |
3027 | + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n", | |
3028 | + add->pathname, | |
3029 | + i_uid_read(inode), i_gid_read(inode), | |
3030 | + (inode->i_mode & S_IALLUGO), | |
3031 | + i_uid_read(h_inode), i_gid_read(h_inode), | |
3032 | + (h_inode->i_mode & S_IALLUGO)); | |
1facf9fc | 3033 | + } |
3034 | + | |
4f0767ce | 3035 | +out: |
1facf9fc | 3036 | + return err; |
3037 | +} | |
3038 | + | |
3039 | +/* | |
3040 | + * initialize or clean the whiteouts for an adding branch | |
3041 | + */ | |
3042 | +static int au_br_init_wh(struct super_block *sb, struct au_branch *br, | |
86dc4139 | 3043 | + int new_perm) |
1facf9fc | 3044 | +{ |
3045 | + int err, old_perm; | |
3046 | + aufs_bindex_t bindex; | |
3047 | + struct mutex *h_mtx; | |
3048 | + struct au_wbr *wbr; | |
3049 | + struct au_hinode *hdir; | |
5527c038 | 3050 | + struct dentry *h_dentry; |
1facf9fc | 3051 | + |
86dc4139 AM |
3052 | + err = vfsub_mnt_want_write(au_br_mnt(br)); |
3053 | + if (unlikely(err)) | |
3054 | + goto out; | |
3055 | + | |
1facf9fc | 3056 | + wbr = br->br_wbr; |
3057 | + old_perm = br->br_perm; | |
3058 | + br->br_perm = new_perm; | |
3059 | + hdir = NULL; | |
3060 | + h_mtx = NULL; | |
3061 | + bindex = au_br_index(sb, br->br_id); | |
3062 | + if (0 <= bindex) { | |
5527c038 | 3063 | + hdir = au_hi(d_inode(sb->s_root), bindex); |
4a4d8108 | 3064 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 3065 | + } else { |
5527c038 JR |
3066 | + h_dentry = au_br_dentry(br); |
3067 | + h_mtx = &d_inode(h_dentry)->i_mutex; | |
1facf9fc | 3068 | + mutex_lock_nested(h_mtx, AuLsc_I_PARENT); |
3069 | + } | |
3070 | + if (!wbr) | |
86dc4139 | 3071 | + err = au_wh_init(br, sb); |
1facf9fc | 3072 | + else { |
3073 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 3074 | + err = au_wh_init(br, sb); |
1facf9fc | 3075 | + wbr_wh_write_unlock(wbr); |
3076 | + } | |
3077 | + if (hdir) | |
4a4d8108 | 3078 | + au_hn_imtx_unlock(hdir); |
1facf9fc | 3079 | + else |
3080 | + mutex_unlock(h_mtx); | |
86dc4139 | 3081 | + vfsub_mnt_drop_write(au_br_mnt(br)); |
1facf9fc | 3082 | + br->br_perm = old_perm; |
3083 | + | |
3084 | + if (!err && wbr && !au_br_writable(new_perm)) { | |
3085 | + kfree(wbr); | |
3086 | + br->br_wbr = NULL; | |
3087 | + } | |
3088 | + | |
86dc4139 | 3089 | +out: |
1facf9fc | 3090 | + return err; |
3091 | +} | |
3092 | + | |
3093 | +static int au_wbr_init(struct au_branch *br, struct super_block *sb, | |
86dc4139 | 3094 | + int perm) |
1facf9fc | 3095 | +{ |
3096 | + int err; | |
4a4d8108 | 3097 | + struct kstatfs kst; |
1facf9fc | 3098 | + struct au_wbr *wbr; |
3099 | + | |
3100 | + wbr = br->br_wbr; | |
dece6358 | 3101 | + au_rw_init(&wbr->wbr_wh_rwsem); |
1facf9fc | 3102 | + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh)); |
3103 | + atomic_set(&wbr->wbr_wh_running, 0); | |
3104 | + wbr->wbr_bytes = 0; | |
3105 | + | |
4a4d8108 AM |
3106 | + /* |
3107 | + * a limit for rmdir/rename a dir | |
523b37e3 | 3108 | + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h |
4a4d8108 | 3109 | + */ |
86dc4139 | 3110 | + err = vfs_statfs(&br->br_path, &kst); |
4a4d8108 AM |
3111 | + if (unlikely(err)) |
3112 | + goto out; | |
3113 | + err = -EINVAL; | |
3114 | + if (kst.f_namelen >= NAME_MAX) | |
86dc4139 | 3115 | + err = au_br_init_wh(sb, br, perm); |
4a4d8108 | 3116 | + else |
523b37e3 AM |
3117 | + pr_err("%pd(%s), unsupported namelen %ld\n", |
3118 | + au_br_dentry(br), | |
86dc4139 | 3119 | + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen); |
1facf9fc | 3120 | + |
4f0767ce | 3121 | +out: |
1facf9fc | 3122 | + return err; |
3123 | +} | |
3124 | + | |
c1595e42 | 3125 | +/* initialize a new branch */ |
1facf9fc | 3126 | +static int au_br_init(struct au_branch *br, struct super_block *sb, |
3127 | + struct au_opt_add *add) | |
3128 | +{ | |
3129 | + int err; | |
5527c038 | 3130 | + struct inode *h_inode; |
1facf9fc | 3131 | + |
3132 | + err = 0; | |
3133 | + memset(&br->br_xino, 0, sizeof(br->br_xino)); | |
3134 | + mutex_init(&br->br_xino.xi_nondir_mtx); | |
3135 | + br->br_perm = add->perm; | |
86dc4139 | 3136 | + br->br_path = add->path; /* set first, path_get() later */ |
4a4d8108 AM |
3137 | + spin_lock_init(&br->br_dykey_lock); |
3138 | + memset(br->br_dykey, 0, sizeof(br->br_dykey)); | |
1facf9fc | 3139 | + atomic_set(&br->br_count, 0); |
1facf9fc | 3140 | + atomic_set(&br->br_xino_running, 0); |
3141 | + br->br_id = au_new_br_id(sb); | |
7f207e10 | 3142 | + AuDebugOn(br->br_id < 0); |
1facf9fc | 3143 | + |
3144 | + if (au_br_writable(add->perm)) { | |
86dc4139 | 3145 | + err = au_wbr_init(br, sb, add->perm); |
1facf9fc | 3146 | + if (unlikely(err)) |
b752ccd1 | 3147 | + goto out_err; |
1facf9fc | 3148 | + } |
3149 | + | |
3150 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
5527c038 JR |
3151 | + h_inode = d_inode(add->path.dentry); |
3152 | + err = au_xino_br(sb, br, h_inode->i_ino, | |
1facf9fc | 3153 | + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1); |
3154 | + if (unlikely(err)) { | |
3155 | + AuDebugOn(br->br_xino.xi_file); | |
b752ccd1 | 3156 | + goto out_err; |
1facf9fc | 3157 | + } |
3158 | + } | |
3159 | + | |
3160 | + sysaufs_br_init(br); | |
86dc4139 | 3161 | + path_get(&br->br_path); |
b752ccd1 | 3162 | + goto out; /* success */ |
1facf9fc | 3163 | + |
4f0767ce | 3164 | +out_err: |
86dc4139 | 3165 | + memset(&br->br_path, 0, sizeof(br->br_path)); |
4f0767ce | 3166 | +out: |
1facf9fc | 3167 | + return err; |
3168 | +} | |
3169 | + | |
3170 | +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex, | |
3171 | + struct au_branch *br, aufs_bindex_t bend, | |
3172 | + aufs_bindex_t amount) | |
3173 | +{ | |
3174 | + struct au_branch **brp; | |
3175 | + | |
dece6358 AM |
3176 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3177 | + | |
1facf9fc | 3178 | + brp = sbinfo->si_branch + bindex; |
3179 | + memmove(brp + 1, brp, sizeof(*brp) * amount); | |
3180 | + *brp = br; | |
3181 | + sbinfo->si_bend++; | |
3182 | + if (unlikely(bend < 0)) | |
3183 | + sbinfo->si_bend = 0; | |
3184 | +} | |
3185 | + | |
3186 | +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex, | |
3187 | + aufs_bindex_t bend, aufs_bindex_t amount) | |
3188 | +{ | |
3189 | + struct au_hdentry *hdp; | |
3190 | + | |
1308ab2a | 3191 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3192 | + | |
1facf9fc | 3193 | + hdp = dinfo->di_hdentry + bindex; |
3194 | + memmove(hdp + 1, hdp, sizeof(*hdp) * amount); | |
3195 | + au_h_dentry_init(hdp); | |
3196 | + dinfo->di_bend++; | |
3197 | + if (unlikely(bend < 0)) | |
3198 | + dinfo->di_bstart = 0; | |
3199 | +} | |
3200 | + | |
3201 | +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex, | |
3202 | + aufs_bindex_t bend, aufs_bindex_t amount) | |
3203 | +{ | |
3204 | + struct au_hinode *hip; | |
3205 | + | |
1308ab2a | 3206 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3207 | + | |
1facf9fc | 3208 | + hip = iinfo->ii_hinode + bindex; |
3209 | + memmove(hip + 1, hip, sizeof(*hip) * amount); | |
3210 | + hip->hi_inode = NULL; | |
4a4d8108 | 3211 | + au_hn_init(hip); |
1facf9fc | 3212 | + iinfo->ii_bend++; |
3213 | + if (unlikely(bend < 0)) | |
3214 | + iinfo->ii_bstart = 0; | |
3215 | +} | |
3216 | + | |
86dc4139 AM |
3217 | +static void au_br_do_add(struct super_block *sb, struct au_branch *br, |
3218 | + aufs_bindex_t bindex) | |
1facf9fc | 3219 | +{ |
86dc4139 | 3220 | + struct dentry *root, *h_dentry; |
5527c038 | 3221 | + struct inode *root_inode, *h_inode; |
1facf9fc | 3222 | + aufs_bindex_t bend, amount; |
3223 | + | |
3224 | + root = sb->s_root; | |
5527c038 | 3225 | + root_inode = d_inode(root); |
1facf9fc | 3226 | + bend = au_sbend(sb); |
3227 | + amount = bend + 1 - bindex; | |
86dc4139 | 3228 | + h_dentry = au_br_dentry(br); |
53392da6 | 3229 | + au_sbilist_lock(); |
1facf9fc | 3230 | + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount); |
3231 | + au_br_do_add_hdp(au_di(root), bindex, bend, amount); | |
3232 | + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount); | |
3233 | + au_set_h_dptr(root, bindex, dget(h_dentry)); | |
5527c038 JR |
3234 | + h_inode = d_inode(h_dentry); |
3235 | + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0); | |
53392da6 | 3236 | + au_sbilist_unlock(); |
1facf9fc | 3237 | +} |
3238 | + | |
3239 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3240 | +{ | |
3241 | + int err; | |
1facf9fc | 3242 | + aufs_bindex_t bend, add_bindex; |
3243 | + struct dentry *root, *h_dentry; | |
3244 | + struct inode *root_inode; | |
3245 | + struct au_branch *add_branch; | |
3246 | + | |
3247 | + root = sb->s_root; | |
5527c038 | 3248 | + root_inode = d_inode(root); |
1facf9fc | 3249 | + IMustLock(root_inode); |
3250 | + err = test_add(sb, add, remount); | |
3251 | + if (unlikely(err < 0)) | |
3252 | + goto out; | |
3253 | + if (err) { | |
3254 | + err = 0; | |
3255 | + goto out; /* success */ | |
3256 | + } | |
3257 | + | |
3258 | + bend = au_sbend(sb); | |
3259 | + add_branch = au_br_alloc(sb, bend + 2, add->perm); | |
3260 | + err = PTR_ERR(add_branch); | |
3261 | + if (IS_ERR(add_branch)) | |
3262 | + goto out; | |
3263 | + | |
3264 | + err = au_br_init(add_branch, sb, add); | |
3265 | + if (unlikely(err)) { | |
3266 | + au_br_do_free(add_branch); | |
3267 | + goto out; | |
3268 | + } | |
3269 | + | |
3270 | + add_bindex = add->bindex; | |
1facf9fc | 3271 | + if (!remount) |
86dc4139 | 3272 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3273 | + else { |
3274 | + sysaufs_brs_del(sb, add_bindex); | |
86dc4139 | 3275 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3276 | + sysaufs_brs_add(sb, add_bindex); |
3277 | + } | |
3278 | + | |
86dc4139 | 3279 | + h_dentry = add->path.dentry; |
1308ab2a | 3280 | + if (!add_bindex) { |
1facf9fc | 3281 | + au_cpup_attr_all(root_inode, /*force*/1); |
1308ab2a | 3282 | + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes; |
3283 | + } else | |
5527c038 | 3284 | + au_add_nlink(root_inode, d_inode(h_dentry)); |
1facf9fc | 3285 | + |
3286 | + /* | |
4a4d8108 | 3287 | + * this test/set prevents aufs from handling unnecesary notify events |
027c5e7a | 3288 | + * of xino files, in case of re-adding a writable branch which was |
1facf9fc | 3289 | + * once detached from aufs. |
3290 | + */ | |
3291 | + if (au_xino_brid(sb) < 0 | |
3292 | + && au_br_writable(add_branch->br_perm) | |
3293 | + && !au_test_fs_bad_xino(h_dentry->d_sb) | |
3294 | + && add_branch->br_xino.xi_file | |
2000de60 | 3295 | + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry) |
1facf9fc | 3296 | + au_xino_brid_set(sb, add_branch->br_id); |
3297 | + | |
4f0767ce | 3298 | +out: |
1facf9fc | 3299 | + return err; |
3300 | +} | |
3301 | + | |
3302 | +/* ---------------------------------------------------------------------- */ | |
3303 | + | |
076b876e AM |
3304 | +static unsigned long long au_farray_cb(void *a, |
3305 | + unsigned long long max __maybe_unused, | |
3306 | + void *arg) | |
3307 | +{ | |
3308 | + unsigned long long n; | |
3309 | + struct file **p, *f; | |
3310 | + struct au_sphlhead *files; | |
3311 | + struct au_finfo *finfo; | |
3312 | + struct super_block *sb = arg; | |
3313 | + | |
3314 | + n = 0; | |
3315 | + p = a; | |
3316 | + files = &au_sbi(sb)->si_files; | |
3317 | + spin_lock(&files->spin); | |
3318 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
3319 | + f = finfo->fi_file; | |
3320 | + if (file_count(f) | |
3321 | + && !special_file(file_inode(f)->i_mode)) { | |
3322 | + get_file(f); | |
3323 | + *p++ = f; | |
3324 | + n++; | |
3325 | + AuDebugOn(n > max); | |
3326 | + } | |
3327 | + } | |
3328 | + spin_unlock(&files->spin); | |
3329 | + | |
3330 | + return n; | |
3331 | +} | |
3332 | + | |
3333 | +static struct file **au_farray_alloc(struct super_block *sb, | |
3334 | + unsigned long long *max) | |
3335 | +{ | |
3336 | + *max = atomic_long_read(&au_sbi(sb)->si_nfiles); | |
3337 | + return au_array_alloc(max, au_farray_cb, sb); | |
3338 | +} | |
3339 | + | |
3340 | +static void au_farray_free(struct file **a, unsigned long long max) | |
3341 | +{ | |
3342 | + unsigned long long ull; | |
3343 | + | |
3344 | + for (ull = 0; ull < max; ull++) | |
3345 | + if (a[ull]) | |
3346 | + fput(a[ull]); | |
3347 | + au_array_free(a); | |
3348 | +} | |
3349 | + | |
3350 | +/* ---------------------------------------------------------------------- */ | |
3351 | + | |
1facf9fc | 3352 | +/* |
3353 | + * delete a branch | |
3354 | + */ | |
3355 | + | |
3356 | +/* to show the line number, do not make it inlined function */ | |
4a4d8108 | 3357 | +#define AuVerbose(do_info, fmt, ...) do { \ |
1facf9fc | 3358 | + if (do_info) \ |
4a4d8108 | 3359 | + pr_info(fmt, ##__VA_ARGS__); \ |
1facf9fc | 3360 | +} while (0) |
3361 | + | |
027c5e7a AM |
3362 | +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart, |
3363 | + aufs_bindex_t bend) | |
3364 | +{ | |
3365 | + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend; | |
3366 | +} | |
3367 | + | |
3368 | +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart, | |
3369 | + aufs_bindex_t bend) | |
3370 | +{ | |
5527c038 | 3371 | + return au_test_ibusy(d_inode(dentry), bstart, bend); |
027c5e7a AM |
3372 | +} |
3373 | + | |
1facf9fc | 3374 | +/* |
3375 | + * test if the branch is deletable or not. | |
3376 | + */ | |
3377 | +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex, | |
b752ccd1 | 3378 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3379 | +{ |
3380 | + int err, i, j, ndentry; | |
3381 | + aufs_bindex_t bstart, bend; | |
1facf9fc | 3382 | + struct au_dcsub_pages dpages; |
3383 | + struct au_dpage *dpage; | |
3384 | + struct dentry *d; | |
1facf9fc | 3385 | + |
3386 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
3387 | + if (unlikely(err)) | |
3388 | + goto out; | |
3389 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); | |
3390 | + if (unlikely(err)) | |
3391 | + goto out_dpages; | |
3392 | + | |
1facf9fc | 3393 | + for (i = 0; !err && i < dpages.ndpage; i++) { |
3394 | + dpage = dpages.dpages + i; | |
3395 | + ndentry = dpage->ndentry; | |
3396 | + for (j = 0; !err && j < ndentry; j++) { | |
3397 | + d = dpage->dentries[j]; | |
c1595e42 | 3398 | + AuDebugOn(au_dcount(d) <= 0); |
027c5e7a | 3399 | + if (!au_digen_test(d, sigen)) { |
1facf9fc | 3400 | + di_read_lock_child(d, AuLock_IR); |
027c5e7a AM |
3401 | + if (unlikely(au_dbrange_test(d))) { |
3402 | + di_read_unlock(d, AuLock_IR); | |
3403 | + continue; | |
3404 | + } | |
3405 | + } else { | |
1facf9fc | 3406 | + di_write_lock_child(d); |
027c5e7a AM |
3407 | + if (unlikely(au_dbrange_test(d))) { |
3408 | + di_write_unlock(d); | |
3409 | + continue; | |
3410 | + } | |
1facf9fc | 3411 | + err = au_reval_dpath(d, sigen); |
3412 | + if (!err) | |
3413 | + di_downgrade_lock(d, AuLock_IR); | |
3414 | + else { | |
3415 | + di_write_unlock(d); | |
3416 | + break; | |
3417 | + } | |
3418 | + } | |
3419 | + | |
027c5e7a | 3420 | + /* AuDbgDentry(d); */ |
1facf9fc | 3421 | + bstart = au_dbstart(d); |
3422 | + bend = au_dbend(d); | |
3423 | + if (bstart <= bindex | |
3424 | + && bindex <= bend | |
3425 | + && au_h_dptr(d, bindex) | |
027c5e7a | 3426 | + && au_test_dbusy(d, bstart, bend)) { |
1facf9fc | 3427 | + err = -EBUSY; |
523b37e3 | 3428 | + AuVerbose(verbose, "busy %pd\n", d); |
027c5e7a | 3429 | + AuDbgDentry(d); |
1facf9fc | 3430 | + } |
3431 | + di_read_unlock(d, AuLock_IR); | |
3432 | + } | |
3433 | + } | |
3434 | + | |
4f0767ce | 3435 | +out_dpages: |
1facf9fc | 3436 | + au_dpages_free(&dpages); |
4f0767ce | 3437 | +out: |
1facf9fc | 3438 | + return err; |
3439 | +} | |
3440 | + | |
3441 | +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex, | |
b752ccd1 | 3442 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3443 | +{ |
3444 | + int err; | |
7f207e10 AM |
3445 | + unsigned long long max, ull; |
3446 | + struct inode *i, **array; | |
1facf9fc | 3447 | + aufs_bindex_t bstart, bend; |
1facf9fc | 3448 | + |
7f207e10 AM |
3449 | + array = au_iarray_alloc(sb, &max); |
3450 | + err = PTR_ERR(array); | |
3451 | + if (IS_ERR(array)) | |
3452 | + goto out; | |
3453 | + | |
1facf9fc | 3454 | + err = 0; |
7f207e10 AM |
3455 | + AuDbg("b%d\n", bindex); |
3456 | + for (ull = 0; !err && ull < max; ull++) { | |
3457 | + i = array[ull]; | |
076b876e AM |
3458 | + if (unlikely(!i)) |
3459 | + break; | |
7f207e10 | 3460 | + if (i->i_ino == AUFS_ROOT_INO) |
1facf9fc | 3461 | + continue; |
3462 | + | |
7f207e10 | 3463 | + /* AuDbgInode(i); */ |
537831f9 | 3464 | + if (au_iigen(i, NULL) == sigen) |
1facf9fc | 3465 | + ii_read_lock_child(i); |
3466 | + else { | |
3467 | + ii_write_lock_child(i); | |
027c5e7a AM |
3468 | + err = au_refresh_hinode_self(i); |
3469 | + au_iigen_dec(i); | |
1facf9fc | 3470 | + if (!err) |
3471 | + ii_downgrade_lock(i); | |
3472 | + else { | |
3473 | + ii_write_unlock(i); | |
3474 | + break; | |
3475 | + } | |
3476 | + } | |
3477 | + | |
3478 | + bstart = au_ibstart(i); | |
3479 | + bend = au_ibend(i); | |
3480 | + if (bstart <= bindex | |
3481 | + && bindex <= bend | |
3482 | + && au_h_iptr(i, bindex) | |
027c5e7a | 3483 | + && au_test_ibusy(i, bstart, bend)) { |
1facf9fc | 3484 | + err = -EBUSY; |
3485 | + AuVerbose(verbose, "busy i%lu\n", i->i_ino); | |
7f207e10 | 3486 | + AuDbgInode(i); |
1facf9fc | 3487 | + } |
3488 | + ii_read_unlock(i); | |
3489 | + } | |
7f207e10 | 3490 | + au_iarray_free(array, max); |
1facf9fc | 3491 | + |
7f207e10 | 3492 | +out: |
1facf9fc | 3493 | + return err; |
3494 | +} | |
3495 | + | |
b752ccd1 AM |
3496 | +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex, |
3497 | + const unsigned int verbose) | |
1facf9fc | 3498 | +{ |
3499 | + int err; | |
3500 | + unsigned int sigen; | |
3501 | + | |
3502 | + sigen = au_sigen(root->d_sb); | |
3503 | + DiMustNoWaiters(root); | |
5527c038 | 3504 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 3505 | + di_write_unlock(root); |
b752ccd1 | 3506 | + err = test_dentry_busy(root, bindex, sigen, verbose); |
1facf9fc | 3507 | + if (!err) |
b752ccd1 | 3508 | + err = test_inode_busy(root->d_sb, bindex, sigen, verbose); |
1facf9fc | 3509 | + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */ |
3510 | + | |
3511 | + return err; | |
3512 | +} | |
3513 | + | |
076b876e AM |
3514 | +static int test_dir_busy(struct file *file, aufs_bindex_t br_id, |
3515 | + struct file **to_free, int *idx) | |
3516 | +{ | |
3517 | + int err; | |
c1595e42 | 3518 | + unsigned char matched, root; |
076b876e AM |
3519 | + aufs_bindex_t bindex, bend; |
3520 | + struct au_fidir *fidir; | |
3521 | + struct au_hfile *hfile; | |
3522 | + | |
3523 | + err = 0; | |
2000de60 | 3524 | + root = IS_ROOT(file->f_path.dentry); |
c1595e42 JR |
3525 | + if (root) { |
3526 | + get_file(file); | |
3527 | + to_free[*idx] = file; | |
3528 | + (*idx)++; | |
3529 | + goto out; | |
3530 | + } | |
3531 | + | |
076b876e | 3532 | + matched = 0; |
076b876e AM |
3533 | + fidir = au_fi(file)->fi_hdir; |
3534 | + AuDebugOn(!fidir); | |
3535 | + bend = au_fbend_dir(file); | |
3536 | + for (bindex = au_fbstart(file); bindex <= bend; bindex++) { | |
3537 | + hfile = fidir->fd_hfile + bindex; | |
3538 | + if (!hfile->hf_file) | |
3539 | + continue; | |
3540 | + | |
c1595e42 | 3541 | + if (hfile->hf_br->br_id == br_id) { |
076b876e | 3542 | + matched = 1; |
076b876e | 3543 | + break; |
c1595e42 | 3544 | + } |
076b876e | 3545 | + } |
c1595e42 | 3546 | + if (matched) |
076b876e AM |
3547 | + err = -EBUSY; |
3548 | + | |
3549 | +out: | |
3550 | + return err; | |
3551 | +} | |
3552 | + | |
3553 | +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id, | |
3554 | + struct file **to_free, int opened) | |
3555 | +{ | |
3556 | + int err, idx; | |
3557 | + unsigned long long ull, max; | |
3558 | + aufs_bindex_t bstart; | |
3559 | + struct file *file, **array; | |
076b876e AM |
3560 | + struct dentry *root; |
3561 | + struct au_hfile *hfile; | |
3562 | + | |
3563 | + array = au_farray_alloc(sb, &max); | |
3564 | + err = PTR_ERR(array); | |
3565 | + if (IS_ERR(array)) | |
3566 | + goto out; | |
3567 | + | |
3568 | + err = 0; | |
3569 | + idx = 0; | |
3570 | + root = sb->s_root; | |
3571 | + di_write_unlock(root); | |
3572 | + for (ull = 0; ull < max; ull++) { | |
3573 | + file = array[ull]; | |
3574 | + if (unlikely(!file)) | |
3575 | + break; | |
3576 | + | |
3577 | + /* AuDbg("%pD\n", file); */ | |
3578 | + fi_read_lock(file); | |
3579 | + bstart = au_fbstart(file); | |
2000de60 | 3580 | + if (!d_is_dir(file->f_path.dentry)) { |
076b876e AM |
3581 | + hfile = &au_fi(file)->fi_htop; |
3582 | + if (hfile->hf_br->br_id == br_id) | |
3583 | + err = -EBUSY; | |
3584 | + } else | |
3585 | + err = test_dir_busy(file, br_id, to_free, &idx); | |
3586 | + fi_read_unlock(file); | |
3587 | + if (unlikely(err)) | |
3588 | + break; | |
3589 | + } | |
3590 | + di_write_lock_child(root); | |
3591 | + au_farray_free(array, max); | |
3592 | + AuDebugOn(idx > opened); | |
3593 | + | |
3594 | +out: | |
3595 | + return err; | |
3596 | +} | |
3597 | + | |
3598 | +static void br_del_file(struct file **to_free, unsigned long long opened, | |
3599 | + aufs_bindex_t br_id) | |
3600 | +{ | |
3601 | + unsigned long long ull; | |
3602 | + aufs_bindex_t bindex, bstart, bend, bfound; | |
3603 | + struct file *file; | |
3604 | + struct au_fidir *fidir; | |
3605 | + struct au_hfile *hfile; | |
3606 | + | |
3607 | + for (ull = 0; ull < opened; ull++) { | |
3608 | + file = to_free[ull]; | |
3609 | + if (unlikely(!file)) | |
3610 | + break; | |
3611 | + | |
3612 | + /* AuDbg("%pD\n", file); */ | |
2000de60 | 3613 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
076b876e AM |
3614 | + bfound = -1; |
3615 | + fidir = au_fi(file)->fi_hdir; | |
3616 | + AuDebugOn(!fidir); | |
3617 | + fi_write_lock(file); | |
3618 | + bstart = au_fbstart(file); | |
3619 | + bend = au_fbend_dir(file); | |
3620 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
3621 | + hfile = fidir->fd_hfile + bindex; | |
3622 | + if (!hfile->hf_file) | |
3623 | + continue; | |
3624 | + | |
3625 | + if (hfile->hf_br->br_id == br_id) { | |
3626 | + bfound = bindex; | |
3627 | + break; | |
3628 | + } | |
3629 | + } | |
3630 | + AuDebugOn(bfound < 0); | |
3631 | + au_set_h_fptr(file, bfound, NULL); | |
3632 | + if (bfound == bstart) { | |
3633 | + for (bstart++; bstart <= bend; bstart++) | |
3634 | + if (au_hf_dir(file, bstart)) { | |
3635 | + au_set_fbstart(file, bstart); | |
3636 | + break; | |
3637 | + } | |
3638 | + } | |
3639 | + fi_write_unlock(file); | |
3640 | + } | |
3641 | +} | |
3642 | + | |
1facf9fc | 3643 | +static void au_br_do_del_brp(struct au_sbinfo *sbinfo, |
3644 | + const aufs_bindex_t bindex, | |
3645 | + const aufs_bindex_t bend) | |
3646 | +{ | |
3647 | + struct au_branch **brp, **p; | |
3648 | + | |
dece6358 AM |
3649 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3650 | + | |
1facf9fc | 3651 | + brp = sbinfo->si_branch + bindex; |
3652 | + if (bindex < bend) | |
3653 | + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex)); | |
3654 | + sbinfo->si_branch[0 + bend] = NULL; | |
3655 | + sbinfo->si_bend--; | |
3656 | + | |
53392da6 | 3657 | + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3658 | + if (p) |
3659 | + sbinfo->si_branch = p; | |
4a4d8108 | 3660 | + /* harmless error */ |
1facf9fc | 3661 | +} |
3662 | + | |
3663 | +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex, | |
3664 | + const aufs_bindex_t bend) | |
3665 | +{ | |
3666 | + struct au_hdentry *hdp, *p; | |
3667 | + | |
1308ab2a | 3668 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3669 | + | |
4a4d8108 | 3670 | + hdp = dinfo->di_hdentry; |
1facf9fc | 3671 | + if (bindex < bend) |
4a4d8108 AM |
3672 | + memmove(hdp + bindex, hdp + bindex + 1, |
3673 | + sizeof(*hdp) * (bend - bindex)); | |
3674 | + hdp[0 + bend].hd_dentry = NULL; | |
1facf9fc | 3675 | + dinfo->di_bend--; |
3676 | + | |
53392da6 | 3677 | + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3678 | + if (p) |
3679 | + dinfo->di_hdentry = p; | |
4a4d8108 | 3680 | + /* harmless error */ |
1facf9fc | 3681 | +} |
3682 | + | |
3683 | +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex, | |
3684 | + const aufs_bindex_t bend) | |
3685 | +{ | |
3686 | + struct au_hinode *hip, *p; | |
3687 | + | |
1308ab2a | 3688 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3689 | + | |
1facf9fc | 3690 | + hip = iinfo->ii_hinode + bindex; |
3691 | + if (bindex < bend) | |
3692 | + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex)); | |
3693 | + iinfo->ii_hinode[0 + bend].hi_inode = NULL; | |
4a4d8108 | 3694 | + au_hn_init(iinfo->ii_hinode + bend); |
1facf9fc | 3695 | + iinfo->ii_bend--; |
3696 | + | |
53392da6 | 3697 | + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3698 | + if (p) |
3699 | + iinfo->ii_hinode = p; | |
4a4d8108 | 3700 | + /* harmless error */ |
1facf9fc | 3701 | +} |
3702 | + | |
3703 | +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex, | |
3704 | + struct au_branch *br) | |
3705 | +{ | |
3706 | + aufs_bindex_t bend; | |
3707 | + struct au_sbinfo *sbinfo; | |
53392da6 AM |
3708 | + struct dentry *root, *h_root; |
3709 | + struct inode *inode, *h_inode; | |
3710 | + struct au_hinode *hinode; | |
1facf9fc | 3711 | + |
dece6358 AM |
3712 | + SiMustWriteLock(sb); |
3713 | + | |
1facf9fc | 3714 | + root = sb->s_root; |
5527c038 | 3715 | + inode = d_inode(root); |
1facf9fc | 3716 | + sbinfo = au_sbi(sb); |
3717 | + bend = sbinfo->si_bend; | |
3718 | + | |
53392da6 AM |
3719 | + h_root = au_h_dptr(root, bindex); |
3720 | + hinode = au_hi(inode, bindex); | |
3721 | + h_inode = au_igrab(hinode->hi_inode); | |
3722 | + au_hiput(hinode); | |
1facf9fc | 3723 | + |
53392da6 | 3724 | + au_sbilist_lock(); |
1facf9fc | 3725 | + au_br_do_del_brp(sbinfo, bindex, bend); |
3726 | + au_br_do_del_hdp(au_di(root), bindex, bend); | |
3727 | + au_br_do_del_hip(au_ii(inode), bindex, bend); | |
53392da6 AM |
3728 | + au_sbilist_unlock(); |
3729 | + | |
3730 | + dput(h_root); | |
3731 | + iput(h_inode); | |
3732 | + au_br_do_free(br); | |
1facf9fc | 3733 | +} |
3734 | + | |
076b876e AM |
3735 | +static unsigned long long empty_cb(void *array, unsigned long long max, |
3736 | + void *arg) | |
3737 | +{ | |
3738 | + return max; | |
3739 | +} | |
3740 | + | |
1facf9fc | 3741 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount) |
3742 | +{ | |
3743 | + int err, rerr, i; | |
076b876e | 3744 | + unsigned long long opened; |
1facf9fc | 3745 | + unsigned int mnt_flags; |
3746 | + aufs_bindex_t bindex, bend, br_id; | |
3747 | + unsigned char do_wh, verbose; | |
3748 | + struct au_branch *br; | |
3749 | + struct au_wbr *wbr; | |
076b876e AM |
3750 | + struct dentry *root; |
3751 | + struct file **to_free; | |
1facf9fc | 3752 | + |
3753 | + err = 0; | |
076b876e AM |
3754 | + opened = 0; |
3755 | + to_free = NULL; | |
3756 | + root = sb->s_root; | |
3757 | + bindex = au_find_dbindex(root, del->h_path.dentry); | |
1facf9fc | 3758 | + if (bindex < 0) { |
3759 | + if (remount) | |
3760 | + goto out; /* success */ | |
3761 | + err = -ENOENT; | |
4a4d8108 | 3762 | + pr_err("%s no such branch\n", del->pathname); |
1facf9fc | 3763 | + goto out; |
3764 | + } | |
3765 | + AuDbg("bindex b%d\n", bindex); | |
3766 | + | |
3767 | + err = -EBUSY; | |
3768 | + mnt_flags = au_mntflags(sb); | |
3769 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
3770 | + bend = au_sbend(sb); | |
3771 | + if (unlikely(!bend)) { | |
3772 | + AuVerbose(verbose, "no more branches left\n"); | |
3773 | + goto out; | |
3774 | + } | |
3775 | + br = au_sbr(sb, bindex); | |
86dc4139 | 3776 | + AuDebugOn(!path_equal(&br->br_path, &del->h_path)); |
076b876e AM |
3777 | + |
3778 | + br_id = br->br_id; | |
3779 | + opened = atomic_read(&br->br_count); | |
3780 | + if (unlikely(opened)) { | |
3781 | + to_free = au_array_alloc(&opened, empty_cb, NULL); | |
3782 | + err = PTR_ERR(to_free); | |
3783 | + if (IS_ERR(to_free)) | |
3784 | + goto out; | |
3785 | + | |
3786 | + err = test_file_busy(sb, br_id, to_free, opened); | |
3787 | + if (unlikely(err)) { | |
3788 | + AuVerbose(verbose, "%llu file(s) opened\n", opened); | |
3789 | + goto out; | |
3790 | + } | |
1facf9fc | 3791 | + } |
3792 | + | |
3793 | + wbr = br->br_wbr; | |
3794 | + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph); | |
3795 | + if (do_wh) { | |
1308ab2a | 3796 | + /* instead of WbrWhMustWriteLock(wbr) */ |
3797 | + SiMustWriteLock(sb); | |
1facf9fc | 3798 | + for (i = 0; i < AuBrWh_Last; i++) { |
3799 | + dput(wbr->wbr_wh[i]); | |
3800 | + wbr->wbr_wh[i] = NULL; | |
3801 | + } | |
3802 | + } | |
3803 | + | |
076b876e | 3804 | + err = test_children_busy(root, bindex, verbose); |
1facf9fc | 3805 | + if (unlikely(err)) { |
3806 | + if (do_wh) | |
3807 | + goto out_wh; | |
3808 | + goto out; | |
3809 | + } | |
3810 | + | |
3811 | + err = 0; | |
076b876e AM |
3812 | + if (to_free) { |
3813 | + /* | |
3814 | + * now we confirmed the branch is deletable. | |
3815 | + * let's free the remaining opened dirs on the branch. | |
3816 | + */ | |
3817 | + di_write_unlock(root); | |
3818 | + br_del_file(to_free, opened, br_id); | |
3819 | + di_write_lock_child(root); | |
3820 | + } | |
3821 | + | |
1facf9fc | 3822 | + if (!remount) |
3823 | + au_br_do_del(sb, bindex, br); | |
3824 | + else { | |
3825 | + sysaufs_brs_del(sb, bindex); | |
3826 | + au_br_do_del(sb, bindex, br); | |
3827 | + sysaufs_brs_add(sb, bindex); | |
3828 | + } | |
3829 | + | |
1308ab2a | 3830 | + if (!bindex) { |
5527c038 | 3831 | + au_cpup_attr_all(d_inode(root), /*force*/1); |
1308ab2a | 3832 | + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes; |
3833 | + } else | |
5527c038 | 3834 | + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry)); |
1facf9fc | 3835 | + if (au_opt_test(mnt_flags, PLINK)) |
3836 | + au_plink_half_refresh(sb, br_id); | |
3837 | + | |
b752ccd1 | 3838 | + if (au_xino_brid(sb) == br_id) |
1facf9fc | 3839 | + au_xino_brid_set(sb, -1); |
3840 | + goto out; /* success */ | |
3841 | + | |
4f0767ce | 3842 | +out_wh: |
1facf9fc | 3843 | + /* revert */ |
86dc4139 | 3844 | + rerr = au_br_init_wh(sb, br, br->br_perm); |
1facf9fc | 3845 | + if (rerr) |
0c3ec466 AM |
3846 | + pr_warn("failed re-creating base whiteout, %s. (%d)\n", |
3847 | + del->pathname, rerr); | |
4f0767ce | 3848 | +out: |
076b876e AM |
3849 | + if (to_free) |
3850 | + au_farray_free(to_free, opened); | |
1facf9fc | 3851 | + return err; |
3852 | +} | |
3853 | + | |
3854 | +/* ---------------------------------------------------------------------- */ | |
3855 | + | |
027c5e7a AM |
3856 | +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg) |
3857 | +{ | |
3858 | + int err; | |
3859 | + aufs_bindex_t bstart, bend; | |
3860 | + struct aufs_ibusy ibusy; | |
3861 | + struct inode *inode, *h_inode; | |
3862 | + | |
3863 | + err = -EPERM; | |
3864 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
3865 | + goto out; | |
3866 | + | |
3867 | + err = copy_from_user(&ibusy, arg, sizeof(ibusy)); | |
3868 | + if (!err) | |
3869 | + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino)); | |
3870 | + if (unlikely(err)) { | |
3871 | + err = -EFAULT; | |
3872 | + AuTraceErr(err); | |
3873 | + goto out; | |
3874 | + } | |
3875 | + | |
3876 | + err = -EINVAL; | |
3877 | + si_read_lock(sb, AuLock_FLUSH); | |
3878 | + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb))) | |
3879 | + goto out_unlock; | |
3880 | + | |
3881 | + err = 0; | |
3882 | + ibusy.h_ino = 0; /* invalid */ | |
3883 | + inode = ilookup(sb, ibusy.ino); | |
3884 | + if (!inode | |
3885 | + || inode->i_ino == AUFS_ROOT_INO | |
3886 | + || is_bad_inode(inode)) | |
3887 | + goto out_unlock; | |
3888 | + | |
3889 | + ii_read_lock_child(inode); | |
3890 | + bstart = au_ibstart(inode); | |
3891 | + bend = au_ibend(inode); | |
3892 | + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) { | |
3893 | + h_inode = au_h_iptr(inode, ibusy.bindex); | |
3894 | + if (h_inode && au_test_ibusy(inode, bstart, bend)) | |
3895 | + ibusy.h_ino = h_inode->i_ino; | |
3896 | + } | |
3897 | + ii_read_unlock(inode); | |
3898 | + iput(inode); | |
3899 | + | |
3900 | +out_unlock: | |
3901 | + si_read_unlock(sb); | |
3902 | + if (!err) { | |
3903 | + err = __put_user(ibusy.h_ino, &arg->h_ino); | |
3904 | + if (unlikely(err)) { | |
3905 | + err = -EFAULT; | |
3906 | + AuTraceErr(err); | |
3907 | + } | |
3908 | + } | |
3909 | +out: | |
3910 | + return err; | |
3911 | +} | |
3912 | + | |
3913 | +long au_ibusy_ioctl(struct file *file, unsigned long arg) | |
3914 | +{ | |
2000de60 | 3915 | + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg); |
027c5e7a AM |
3916 | +} |
3917 | + | |
3918 | +#ifdef CONFIG_COMPAT | |
3919 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg) | |
3920 | +{ | |
2000de60 | 3921 | + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg)); |
027c5e7a AM |
3922 | +} |
3923 | +#endif | |
3924 | + | |
3925 | +/* ---------------------------------------------------------------------- */ | |
3926 | + | |
1facf9fc | 3927 | +/* |
3928 | + * change a branch permission | |
3929 | + */ | |
3930 | + | |
dece6358 AM |
3931 | +static void au_warn_ima(void) |
3932 | +{ | |
3933 | +#ifdef CONFIG_IMA | |
1308ab2a | 3934 | + /* since it doesn't support mark_files_ro() */ |
027c5e7a | 3935 | + AuWarn1("RW -> RO makes IMA to produce wrong message\n"); |
dece6358 AM |
3936 | +#endif |
3937 | +} | |
3938 | + | |
1facf9fc | 3939 | +static int do_need_sigen_inc(int a, int b) |
3940 | +{ | |
3941 | + return au_br_whable(a) && !au_br_whable(b); | |
3942 | +} | |
3943 | + | |
3944 | +static int need_sigen_inc(int old, int new) | |
3945 | +{ | |
3946 | + return do_need_sigen_inc(old, new) | |
3947 | + || do_need_sigen_inc(new, old); | |
3948 | +} | |
3949 | + | |
3950 | +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex) | |
3951 | +{ | |
7f207e10 | 3952 | + int err, do_warn; |
027c5e7a | 3953 | + unsigned int mnt_flags; |
7f207e10 | 3954 | + unsigned long long ull, max; |
e49829fe | 3955 | + aufs_bindex_t br_id; |
38d290e6 | 3956 | + unsigned char verbose, writer; |
7f207e10 | 3957 | + struct file *file, *hf, **array; |
e49829fe | 3958 | + struct au_hfile *hfile; |
1facf9fc | 3959 | + |
027c5e7a AM |
3960 | + mnt_flags = au_mntflags(sb); |
3961 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
3962 | + | |
7f207e10 AM |
3963 | + array = au_farray_alloc(sb, &max); |
3964 | + err = PTR_ERR(array); | |
3965 | + if (IS_ERR(array)) | |
1facf9fc | 3966 | + goto out; |
3967 | + | |
7f207e10 | 3968 | + do_warn = 0; |
e49829fe | 3969 | + br_id = au_sbr_id(sb, bindex); |
7f207e10 AM |
3970 | + for (ull = 0; ull < max; ull++) { |
3971 | + file = array[ull]; | |
076b876e AM |
3972 | + if (unlikely(!file)) |
3973 | + break; | |
1facf9fc | 3974 | + |
523b37e3 | 3975 | + /* AuDbg("%pD\n", file); */ |
1facf9fc | 3976 | + fi_read_lock(file); |
3977 | + if (unlikely(au_test_mmapped(file))) { | |
3978 | + err = -EBUSY; | |
523b37e3 | 3979 | + AuVerbose(verbose, "mmapped %pD\n", file); |
7f207e10 | 3980 | + AuDbgFile(file); |
1facf9fc | 3981 | + FiMustNoWaiters(file); |
3982 | + fi_read_unlock(file); | |
7f207e10 | 3983 | + goto out_array; |
1facf9fc | 3984 | + } |
3985 | + | |
e49829fe JR |
3986 | + hfile = &au_fi(file)->fi_htop; |
3987 | + hf = hfile->hf_file; | |
7e9cd9fe | 3988 | + if (!d_is_reg(file->f_path.dentry) |
1facf9fc | 3989 | + || !(file->f_mode & FMODE_WRITE) |
e49829fe | 3990 | + || hfile->hf_br->br_id != br_id |
7f207e10 AM |
3991 | + || !(hf->f_mode & FMODE_WRITE)) |
3992 | + array[ull] = NULL; | |
3993 | + else { | |
3994 | + do_warn = 1; | |
3995 | + get_file(file); | |
1facf9fc | 3996 | + } |
3997 | + | |
1facf9fc | 3998 | + FiMustNoWaiters(file); |
3999 | + fi_read_unlock(file); | |
7f207e10 AM |
4000 | + fput(file); |
4001 | + } | |
1facf9fc | 4002 | + |
4003 | + err = 0; | |
7f207e10 | 4004 | + if (do_warn) |
dece6358 | 4005 | + au_warn_ima(); |
7f207e10 AM |
4006 | + |
4007 | + for (ull = 0; ull < max; ull++) { | |
4008 | + file = array[ull]; | |
4009 | + if (!file) | |
4010 | + continue; | |
4011 | + | |
1facf9fc | 4012 | + /* todo: already flushed? */ |
523b37e3 AM |
4013 | + /* |
4014 | + * fs/super.c:mark_files_ro() is gone, but aufs keeps its | |
4015 | + * approach which resets f_mode and calls mnt_drop_write() and | |
4016 | + * file_release_write() for each file, because the branch | |
4017 | + * attribute in aufs world is totally different from the native | |
4018 | + * fs rw/ro mode. | |
4019 | + */ | |
7f207e10 AM |
4020 | + /* fi_read_lock(file); */ |
4021 | + hfile = &au_fi(file)->fi_htop; | |
4022 | + hf = hfile->hf_file; | |
4023 | + /* fi_read_unlock(file); */ | |
027c5e7a | 4024 | + spin_lock(&hf->f_lock); |
38d290e6 JR |
4025 | + writer = !!(hf->f_mode & FMODE_WRITER); |
4026 | + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER); | |
027c5e7a | 4027 | + spin_unlock(&hf->f_lock); |
38d290e6 JR |
4028 | + if (writer) { |
4029 | + put_write_access(file_inode(hf)); | |
c06a8ce3 | 4030 | + __mnt_drop_write(hf->f_path.mnt); |
1facf9fc | 4031 | + } |
4032 | + } | |
4033 | + | |
7f207e10 AM |
4034 | +out_array: |
4035 | + au_farray_free(array, max); | |
4f0767ce | 4036 | +out: |
7f207e10 | 4037 | + AuTraceErr(err); |
1facf9fc | 4038 | + return err; |
4039 | +} | |
4040 | + | |
4041 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4042 | + int *do_refresh) |
1facf9fc | 4043 | +{ |
4044 | + int err, rerr; | |
4045 | + aufs_bindex_t bindex; | |
4046 | + struct dentry *root; | |
4047 | + struct au_branch *br; | |
076b876e | 4048 | + struct au_br_fhsm *bf; |
1facf9fc | 4049 | + |
4050 | + root = sb->s_root; | |
1facf9fc | 4051 | + bindex = au_find_dbindex(root, mod->h_root); |
4052 | + if (bindex < 0) { | |
4053 | + if (remount) | |
4054 | + return 0; /* success */ | |
4055 | + err = -ENOENT; | |
4a4d8108 | 4056 | + pr_err("%s no such branch\n", mod->path); |
1facf9fc | 4057 | + goto out; |
4058 | + } | |
4059 | + AuDbg("bindex b%d\n", bindex); | |
4060 | + | |
5527c038 | 4061 | + err = test_br(d_inode(mod->h_root), mod->perm, mod->path); |
1facf9fc | 4062 | + if (unlikely(err)) |
4063 | + goto out; | |
4064 | + | |
4065 | + br = au_sbr(sb, bindex); | |
86dc4139 | 4066 | + AuDebugOn(mod->h_root != au_br_dentry(br)); |
1facf9fc | 4067 | + if (br->br_perm == mod->perm) |
4068 | + return 0; /* success */ | |
4069 | + | |
076b876e AM |
4070 | + /* pre-allocate for non-fhsm --> fhsm */ |
4071 | + bf = NULL; | |
4072 | + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) { | |
4073 | + err = au_fhsm_br_alloc(br); | |
4074 | + if (unlikely(err)) | |
4075 | + goto out; | |
4076 | + bf = br->br_fhsm; | |
4077 | + br->br_fhsm = NULL; | |
4078 | + } | |
4079 | + | |
1facf9fc | 4080 | + if (au_br_writable(br->br_perm)) { |
4081 | + /* remove whiteout base */ | |
86dc4139 | 4082 | + err = au_br_init_wh(sb, br, mod->perm); |
1facf9fc | 4083 | + if (unlikely(err)) |
076b876e | 4084 | + goto out_bf; |
1facf9fc | 4085 | + |
4086 | + if (!au_br_writable(mod->perm)) { | |
4087 | + /* rw --> ro, file might be mmapped */ | |
4088 | + DiMustNoWaiters(root); | |
5527c038 | 4089 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 4090 | + di_write_unlock(root); |
4091 | + err = au_br_mod_files_ro(sb, bindex); | |
4092 | + /* aufs_write_lock() calls ..._child() */ | |
4093 | + di_write_lock_child(root); | |
4094 | + | |
4095 | + if (unlikely(err)) { | |
4096 | + rerr = -ENOMEM; | |
4097 | + br->br_wbr = kmalloc(sizeof(*br->br_wbr), | |
4098 | + GFP_NOFS); | |
86dc4139 AM |
4099 | + if (br->br_wbr) |
4100 | + rerr = au_wbr_init(br, sb, br->br_perm); | |
1facf9fc | 4101 | + if (unlikely(rerr)) { |
4102 | + AuIOErr("nested error %d (%d)\n", | |
4103 | + rerr, err); | |
4104 | + br->br_perm = mod->perm; | |
4105 | + } | |
4106 | + } | |
4107 | + } | |
4108 | + } else if (au_br_writable(mod->perm)) { | |
4109 | + /* ro --> rw */ | |
4110 | + err = -ENOMEM; | |
4111 | + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS); | |
4112 | + if (br->br_wbr) { | |
86dc4139 | 4113 | + err = au_wbr_init(br, sb, mod->perm); |
1facf9fc | 4114 | + if (unlikely(err)) { |
4115 | + kfree(br->br_wbr); | |
4116 | + br->br_wbr = NULL; | |
4117 | + } | |
4118 | + } | |
4119 | + } | |
076b876e AM |
4120 | + if (unlikely(err)) |
4121 | + goto out_bf; | |
4122 | + | |
4123 | + if (au_br_fhsm(br->br_perm)) { | |
4124 | + if (!au_br_fhsm(mod->perm)) { | |
4125 | + /* fhsm --> non-fhsm */ | |
4126 | + au_br_fhsm_fin(br->br_fhsm); | |
4127 | + kfree(br->br_fhsm); | |
4128 | + br->br_fhsm = NULL; | |
4129 | + } | |
4130 | + } else if (au_br_fhsm(mod->perm)) | |
4131 | + /* non-fhsm --> fhsm */ | |
4132 | + br->br_fhsm = bf; | |
4133 | + | |
076b876e AM |
4134 | + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm); |
4135 | + br->br_perm = mod->perm; | |
4136 | + goto out; /* success */ | |
1facf9fc | 4137 | + |
076b876e AM |
4138 | +out_bf: |
4139 | + kfree(bf); | |
4140 | +out: | |
4141 | + AuTraceErr(err); | |
4142 | + return err; | |
4143 | +} | |
4144 | + | |
4145 | +/* ---------------------------------------------------------------------- */ | |
4146 | + | |
4147 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs) | |
4148 | +{ | |
4149 | + int err; | |
4150 | + struct kstatfs kstfs; | |
4151 | + | |
4152 | + err = vfs_statfs(&br->br_path, &kstfs); | |
1facf9fc | 4153 | + if (!err) { |
076b876e AM |
4154 | + stfs->f_blocks = kstfs.f_blocks; |
4155 | + stfs->f_bavail = kstfs.f_bavail; | |
4156 | + stfs->f_files = kstfs.f_files; | |
4157 | + stfs->f_ffree = kstfs.f_ffree; | |
1facf9fc | 4158 | + } |
4159 | + | |
1facf9fc | 4160 | + return err; |
4161 | +} | |
7f207e10 AM |
4162 | diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h |
4163 | --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 4164 | +++ linux/fs/aufs/branch.h 2015-09-24 10:47:58.248052907 +0200 |
b912730e | 4165 | @@ -0,0 +1,279 @@ |
1facf9fc | 4166 | +/* |
2000de60 | 4167 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 4168 | + * |
4169 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4170 | + * it under the terms of the GNU General Public License as published by | |
4171 | + * the Free Software Foundation; either version 2 of the License, or | |
4172 | + * (at your option) any later version. | |
dece6358 AM |
4173 | + * |
4174 | + * This program is distributed in the hope that it will be useful, | |
4175 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4176 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4177 | + * GNU General Public License for more details. | |
4178 | + * | |
4179 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4180 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4181 | + */ |
4182 | + | |
4183 | +/* | |
4184 | + * branch filesystems and xino for them | |
4185 | + */ | |
4186 | + | |
4187 | +#ifndef __AUFS_BRANCH_H__ | |
4188 | +#define __AUFS_BRANCH_H__ | |
4189 | + | |
4190 | +#ifdef __KERNEL__ | |
4191 | + | |
1facf9fc | 4192 | +#include <linux/mount.h> |
4a4d8108 | 4193 | +#include "dynop.h" |
1facf9fc | 4194 | +#include "rwsem.h" |
4195 | +#include "super.h" | |
4196 | + | |
4197 | +/* ---------------------------------------------------------------------- */ | |
4198 | + | |
4199 | +/* a xino file */ | |
4200 | +struct au_xino_file { | |
4201 | + struct file *xi_file; | |
4202 | + struct mutex xi_nondir_mtx; | |
4203 | + | |
4204 | + /* todo: make xino files an array to support huge inode number */ | |
4205 | + | |
4206 | +#ifdef CONFIG_DEBUG_FS | |
4207 | + struct dentry *xi_dbgaufs; | |
4208 | +#endif | |
4209 | +}; | |
4210 | + | |
076b876e AM |
4211 | +/* File-based Hierarchical Storage Management */ |
4212 | +struct au_br_fhsm { | |
4213 | +#ifdef CONFIG_AUFS_FHSM | |
4214 | + struct mutex bf_lock; | |
4215 | + unsigned long bf_jiffy; | |
4216 | + struct aufs_stfs bf_stfs; | |
4217 | + int bf_readable; | |
4218 | +#endif | |
4219 | +}; | |
4220 | + | |
1facf9fc | 4221 | +/* members for writable branch only */ |
4222 | +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last}; | |
4223 | +struct au_wbr { | |
dece6358 | 4224 | + struct au_rwsem wbr_wh_rwsem; |
1facf9fc | 4225 | + struct dentry *wbr_wh[AuBrWh_Last]; |
4a4d8108 | 4226 | + atomic_t wbr_wh_running; |
1facf9fc | 4227 | +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */ |
4228 | +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */ | |
4229 | +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */ | |
4230 | + | |
4231 | + /* mfs mode */ | |
4232 | + unsigned long long wbr_bytes; | |
4233 | +}; | |
4234 | + | |
4a4d8108 AM |
4235 | +/* ext2 has 3 types of operations at least, ext3 has 4 */ |
4236 | +#define AuBrDynOp (AuDyLast * 4) | |
4237 | + | |
1716fcea AM |
4238 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
4239 | +/* support for asynchronous destruction */ | |
4240 | +struct au_br_hfsnotify { | |
4241 | + struct fsnotify_group *hfsn_group; | |
4242 | +}; | |
4243 | +#endif | |
4244 | + | |
392086de AM |
4245 | +/* sysfs entries */ |
4246 | +struct au_brsysfs { | |
4247 | + char name[16]; | |
4248 | + struct attribute attr; | |
4249 | +}; | |
4250 | + | |
4251 | +enum { | |
4252 | + AuBrSysfs_BR, | |
4253 | + AuBrSysfs_BRID, | |
4254 | + AuBrSysfs_Last | |
4255 | +}; | |
4256 | + | |
1facf9fc | 4257 | +/* protected by superblock rwsem */ |
4258 | +struct au_branch { | |
4259 | + struct au_xino_file br_xino; | |
4260 | + | |
4261 | + aufs_bindex_t br_id; | |
4262 | + | |
4263 | + int br_perm; | |
86dc4139 | 4264 | + struct path br_path; |
4a4d8108 AM |
4265 | + spinlock_t br_dykey_lock; |
4266 | + struct au_dykey *br_dykey[AuBrDynOp]; | |
1facf9fc | 4267 | + atomic_t br_count; |
4268 | + | |
4269 | + struct au_wbr *br_wbr; | |
076b876e | 4270 | + struct au_br_fhsm *br_fhsm; |
1facf9fc | 4271 | + |
4272 | + /* xino truncation */ | |
1facf9fc | 4273 | + atomic_t br_xino_running; |
4274 | + | |
027c5e7a | 4275 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
1716fcea | 4276 | + struct au_br_hfsnotify *br_hfsn; |
027c5e7a AM |
4277 | +#endif |
4278 | + | |
1facf9fc | 4279 | +#ifdef CONFIG_SYSFS |
392086de AM |
4280 | + /* entries under sysfs per mount-point */ |
4281 | + struct au_brsysfs br_sysfs[AuBrSysfs_Last]; | |
1facf9fc | 4282 | +#endif |
4283 | +}; | |
4284 | + | |
4285 | +/* ---------------------------------------------------------------------- */ | |
4286 | + | |
86dc4139 AM |
4287 | +static inline struct vfsmount *au_br_mnt(struct au_branch *br) |
4288 | +{ | |
4289 | + return br->br_path.mnt; | |
4290 | +} | |
4291 | + | |
4292 | +static inline struct dentry *au_br_dentry(struct au_branch *br) | |
4293 | +{ | |
4294 | + return br->br_path.dentry; | |
4295 | +} | |
4296 | + | |
4297 | +static inline struct super_block *au_br_sb(struct au_branch *br) | |
4298 | +{ | |
4299 | + return au_br_mnt(br)->mnt_sb; | |
4300 | +} | |
4301 | + | |
1facf9fc | 4302 | +static inline int au_br_rdonly(struct au_branch *br) |
4303 | +{ | |
86dc4139 | 4304 | + return ((au_br_sb(br)->s_flags & MS_RDONLY) |
1facf9fc | 4305 | + || !au_br_writable(br->br_perm)) |
4306 | + ? -EROFS : 0; | |
4307 | +} | |
4308 | + | |
4a4d8108 | 4309 | +static inline int au_br_hnotifyable(int brperm __maybe_unused) |
1facf9fc | 4310 | +{ |
4a4d8108 | 4311 | +#ifdef CONFIG_AUFS_HNOTIFY |
1e00d052 | 4312 | + return !(brperm & AuBrPerm_RR); |
1facf9fc | 4313 | +#else |
4314 | + return 0; | |
4315 | +#endif | |
4316 | +} | |
4317 | + | |
b912730e AM |
4318 | +static inline int au_br_test_oflag(int oflag, struct au_branch *br) |
4319 | +{ | |
4320 | + int err, exec_flag; | |
4321 | + | |
4322 | + err = 0; | |
4323 | + exec_flag = oflag & __FMODE_EXEC; | |
4324 | + if (unlikely(exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))) | |
4325 | + err = -EACCES; | |
4326 | + | |
4327 | + return err; | |
4328 | +} | |
4329 | + | |
1facf9fc | 4330 | +/* ---------------------------------------------------------------------- */ |
4331 | + | |
4332 | +/* branch.c */ | |
4333 | +struct au_sbinfo; | |
4334 | +void au_br_free(struct au_sbinfo *sinfo); | |
4335 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id); | |
4336 | +struct au_opt_add; | |
4337 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount); | |
4338 | +struct au_opt_del; | |
4339 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount); | |
027c5e7a AM |
4340 | +long au_ibusy_ioctl(struct file *file, unsigned long arg); |
4341 | +#ifdef CONFIG_COMPAT | |
4342 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg); | |
4343 | +#endif | |
1facf9fc | 4344 | +struct au_opt_mod; |
4345 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4346 | + int *do_refresh); |
076b876e AM |
4347 | +struct aufs_stfs; |
4348 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs); | |
1facf9fc | 4349 | + |
4350 | +/* xino.c */ | |
4351 | +static const loff_t au_loff_max = LLONG_MAX; | |
4352 | + | |
4353 | +int au_xib_trunc(struct super_block *sb); | |
5527c038 | 4354 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size, |
1facf9fc | 4355 | + loff_t *pos); |
5527c038 JR |
4356 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
4357 | + size_t size, loff_t *pos); | |
1facf9fc | 4358 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src); |
4359 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent); | |
4360 | +ino_t au_xino_new_ino(struct super_block *sb); | |
b752ccd1 | 4361 | +void au_xino_delete_inode(struct inode *inode, const int unlinked); |
1facf9fc | 4362 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
4363 | + ino_t ino); | |
4364 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4365 | + ino_t *ino); | |
4366 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino, | |
4367 | + struct file *base_file, int do_test); | |
4368 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex); | |
4369 | + | |
4370 | +struct au_opt_xino; | |
4371 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount); | |
4372 | +void au_xino_clr(struct super_block *sb); | |
4373 | +struct file *au_xino_def(struct super_block *sb); | |
4374 | +int au_xino_path(struct seq_file *seq, struct file *file); | |
4375 | + | |
4376 | +/* ---------------------------------------------------------------------- */ | |
4377 | + | |
4378 | +/* Superblock to branch */ | |
4379 | +static inline | |
4380 | +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex) | |
4381 | +{ | |
4382 | + return au_sbr(sb, bindex)->br_id; | |
4383 | +} | |
4384 | + | |
4385 | +static inline | |
4386 | +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex) | |
4387 | +{ | |
86dc4139 | 4388 | + return au_br_mnt(au_sbr(sb, bindex)); |
1facf9fc | 4389 | +} |
4390 | + | |
4391 | +static inline | |
4392 | +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex) | |
4393 | +{ | |
86dc4139 | 4394 | + return au_br_sb(au_sbr(sb, bindex)); |
1facf9fc | 4395 | +} |
4396 | + | |
4397 | +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex) | |
4398 | +{ | |
e49829fe | 4399 | + atomic_dec(&au_sbr(sb, bindex)->br_count); |
1facf9fc | 4400 | +} |
4401 | + | |
4402 | +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex) | |
4403 | +{ | |
4404 | + return au_sbr(sb, bindex)->br_perm; | |
4405 | +} | |
4406 | + | |
4407 | +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex) | |
4408 | +{ | |
4409 | + return au_br_whable(au_sbr_perm(sb, bindex)); | |
4410 | +} | |
4411 | + | |
4412 | +/* ---------------------------------------------------------------------- */ | |
4413 | + | |
4414 | +/* | |
4415 | + * wbr_wh_read_lock, wbr_wh_write_lock | |
4416 | + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock | |
4417 | + */ | |
4418 | +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem); | |
4419 | + | |
dece6358 AM |
4420 | +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem) |
4421 | +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem) | |
4422 | +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem) | |
4423 | + | |
076b876e AM |
4424 | +/* ---------------------------------------------------------------------- */ |
4425 | + | |
4426 | +#ifdef CONFIG_AUFS_FHSM | |
4427 | +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm) | |
4428 | +{ | |
4429 | + mutex_init(&brfhsm->bf_lock); | |
4430 | + brfhsm->bf_jiffy = 0; | |
4431 | + brfhsm->bf_readable = 0; | |
4432 | +} | |
4433 | + | |
4434 | +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm) | |
4435 | +{ | |
4436 | + mutex_destroy(&brfhsm->bf_lock); | |
4437 | +} | |
4438 | +#else | |
4439 | +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm) | |
4440 | +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm) | |
4441 | +#endif | |
4442 | + | |
1facf9fc | 4443 | +#endif /* __KERNEL__ */ |
4444 | +#endif /* __AUFS_BRANCH_H__ */ | |
7f207e10 AM |
4445 | diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk |
4446 | --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 4447 | +++ linux/fs/aufs/conf.mk 2015-09-24 10:47:58.248052907 +0200 |
c1595e42 | 4448 | @@ -0,0 +1,38 @@ |
4a4d8108 AM |
4449 | + |
4450 | +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS} | |
4451 | + | |
4452 | +define AuConf | |
4453 | +ifdef ${1} | |
4454 | +AuConfStr += ${1}=${${1}} | |
4455 | +endif | |
4456 | +endef | |
4457 | + | |
b752ccd1 | 4458 | +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \ |
e49829fe | 4459 | + SBILIST \ |
7f207e10 | 4460 | + HNOTIFY HFSNOTIFY \ |
4a4d8108 | 4461 | + EXPORT INO_T_64 \ |
c1595e42 | 4462 | + XATTR \ |
076b876e | 4463 | + FHSM \ |
4a4d8108 | 4464 | + RDU \ |
4a4d8108 AM |
4465 | + SHWH \ |
4466 | + BR_RAMFS \ | |
4467 | + BR_FUSE POLL \ | |
4468 | + BR_HFSPLUS \ | |
4469 | + BDEV_LOOP \ | |
b752ccd1 AM |
4470 | + DEBUG MAGIC_SYSRQ |
4471 | +$(foreach i, ${AuConfAll}, \ | |
4a4d8108 AM |
4472 | + $(eval $(call AuConf,CONFIG_AUFS_${i}))) |
4473 | + | |
4474 | +AuConfName = ${obj}/conf.str | |
4475 | +${AuConfName}.tmp: FORCE | |
4476 | + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@ | |
4477 | +${AuConfName}: ${AuConfName}.tmp | |
4478 | + @diff -q $< $@ > /dev/null 2>&1 || { \ | |
4479 | + echo ' GEN ' $@; \ | |
4480 | + cp -p $< $@; \ | |
4481 | + } | |
4482 | +FORCE: | |
4483 | +clean-files += ${AuConfName} ${AuConfName}.tmp | |
4484 | +${obj}/sysfs.o: ${AuConfName} | |
b752ccd1 AM |
4485 | + |
4486 | +-include ${srctree}/${src}/conf_priv.mk | |
7f207e10 AM |
4487 | diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c |
4488 | --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 4489 | +++ linux/fs/aufs/cpup.c 2015-09-24 10:47:58.248052907 +0200 |
5527c038 | 4490 | @@ -0,0 +1,1319 @@ |
1facf9fc | 4491 | +/* |
2000de60 | 4492 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 4493 | + * |
4494 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4495 | + * it under the terms of the GNU General Public License as published by | |
4496 | + * the Free Software Foundation; either version 2 of the License, or | |
4497 | + * (at your option) any later version. | |
dece6358 AM |
4498 | + * |
4499 | + * This program is distributed in the hope that it will be useful, | |
4500 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4501 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4502 | + * GNU General Public License for more details. | |
4503 | + * | |
4504 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4505 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4506 | + */ |
4507 | + | |
4508 | +/* | |
4509 | + * copy-up functions, see wbr_policy.c for copy-down | |
4510 | + */ | |
4511 | + | |
4512 | +#include <linux/fs_stack.h> | |
dece6358 | 4513 | +#include <linux/mm.h> |
1facf9fc | 4514 | +#include "aufs.h" |
4515 | + | |
86dc4139 | 4516 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags) |
1facf9fc | 4517 | +{ |
4518 | + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE | |
367653fa | 4519 | + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT; |
1facf9fc | 4520 | + |
86dc4139 AM |
4521 | + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags)); |
4522 | + | |
4523 | + dst->i_flags |= iflags & ~mask; | |
1facf9fc | 4524 | + if (au_test_fs_notime(dst->i_sb)) |
4525 | + dst->i_flags |= S_NOATIME | S_NOCMTIME; | |
4526 | +} | |
4527 | + | |
4528 | +void au_cpup_attr_timesizes(struct inode *inode) | |
4529 | +{ | |
4530 | + struct inode *h_inode; | |
4531 | + | |
4532 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4533 | + fsstack_copy_attr_times(inode, h_inode); | |
4a4d8108 | 4534 | + fsstack_copy_inode_size(inode, h_inode); |
1facf9fc | 4535 | +} |
4536 | + | |
4537 | +void au_cpup_attr_nlink(struct inode *inode, int force) | |
4538 | +{ | |
4539 | + struct inode *h_inode; | |
4540 | + struct super_block *sb; | |
4541 | + aufs_bindex_t bindex, bend; | |
4542 | + | |
4543 | + sb = inode->i_sb; | |
4544 | + bindex = au_ibstart(inode); | |
4545 | + h_inode = au_h_iptr(inode, bindex); | |
4546 | + if (!force | |
4547 | + && !S_ISDIR(h_inode->i_mode) | |
4548 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4549 | + && au_plink_test(inode)) | |
4550 | + return; | |
4551 | + | |
7eafdf33 AM |
4552 | + /* |
4553 | + * 0 can happen in revalidating. | |
38d290e6 JR |
4554 | + * h_inode->i_mutex may not be held here, but it is harmless since once |
4555 | + * i_nlink reaches 0, it will never become positive except O_TMPFILE | |
4556 | + * case. | |
4557 | + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause | |
4558 | + * the incorrect link count. | |
7eafdf33 | 4559 | + */ |
92d182d2 | 4560 | + set_nlink(inode, h_inode->i_nlink); |
1facf9fc | 4561 | + |
4562 | + /* | |
4563 | + * fewer nlink makes find(1) noisy, but larger nlink doesn't. | |
4564 | + * it may includes whplink directory. | |
4565 | + */ | |
4566 | + if (S_ISDIR(h_inode->i_mode)) { | |
4567 | + bend = au_ibend(inode); | |
4568 | + for (bindex++; bindex <= bend; bindex++) { | |
4569 | + h_inode = au_h_iptr(inode, bindex); | |
4570 | + if (h_inode) | |
4571 | + au_add_nlink(inode, h_inode); | |
4572 | + } | |
4573 | + } | |
4574 | +} | |
4575 | + | |
4576 | +void au_cpup_attr_changeable(struct inode *inode) | |
4577 | +{ | |
4578 | + struct inode *h_inode; | |
4579 | + | |
4580 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4581 | + inode->i_mode = h_inode->i_mode; | |
4582 | + inode->i_uid = h_inode->i_uid; | |
4583 | + inode->i_gid = h_inode->i_gid; | |
4584 | + au_cpup_attr_timesizes(inode); | |
86dc4139 | 4585 | + au_cpup_attr_flags(inode, h_inode->i_flags); |
1facf9fc | 4586 | +} |
4587 | + | |
4588 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode) | |
4589 | +{ | |
4590 | + struct au_iinfo *iinfo = au_ii(inode); | |
4591 | + | |
1308ab2a | 4592 | + IiMustWriteLock(inode); |
4593 | + | |
1facf9fc | 4594 | + iinfo->ii_higen = h_inode->i_generation; |
4595 | + iinfo->ii_hsb1 = h_inode->i_sb; | |
4596 | +} | |
4597 | + | |
4598 | +void au_cpup_attr_all(struct inode *inode, int force) | |
4599 | +{ | |
4600 | + struct inode *h_inode; | |
4601 | + | |
4602 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4603 | + au_cpup_attr_changeable(inode); | |
4604 | + if (inode->i_nlink > 0) | |
4605 | + au_cpup_attr_nlink(inode, force); | |
4606 | + inode->i_rdev = h_inode->i_rdev; | |
4607 | + inode->i_blkbits = h_inode->i_blkbits; | |
4608 | + au_cpup_igen(inode, h_inode); | |
4609 | +} | |
4610 | + | |
4611 | +/* ---------------------------------------------------------------------- */ | |
4612 | + | |
4613 | +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */ | |
4614 | + | |
4615 | +/* keep the timestamps of the parent dir when cpup */ | |
4616 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
4617 | + struct path *h_path) | |
4618 | +{ | |
4619 | + struct inode *h_inode; | |
4620 | + | |
4621 | + dt->dt_dentry = dentry; | |
4622 | + dt->dt_h_path = *h_path; | |
5527c038 | 4623 | + h_inode = d_inode(h_path->dentry); |
1facf9fc | 4624 | + dt->dt_atime = h_inode->i_atime; |
4625 | + dt->dt_mtime = h_inode->i_mtime; | |
4626 | + /* smp_mb(); */ | |
4627 | +} | |
4628 | + | |
4629 | +void au_dtime_revert(struct au_dtime *dt) | |
4630 | +{ | |
4631 | + struct iattr attr; | |
4632 | + int err; | |
4633 | + | |
4634 | + attr.ia_atime = dt->dt_atime; | |
4635 | + attr.ia_mtime = dt->dt_mtime; | |
4636 | + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET | |
4637 | + | ATTR_ATIME | ATTR_ATIME_SET; | |
4638 | + | |
523b37e3 AM |
4639 | + /* no delegation since this is a directory */ |
4640 | + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL); | |
1facf9fc | 4641 | + if (unlikely(err)) |
0c3ec466 | 4642 | + pr_warn("restoring timestamps failed(%d). ignored\n", err); |
1facf9fc | 4643 | +} |
4644 | + | |
4645 | +/* ---------------------------------------------------------------------- */ | |
4646 | + | |
86dc4139 AM |
4647 | +/* internal use only */ |
4648 | +struct au_cpup_reg_attr { | |
4649 | + int valid; | |
4650 | + struct kstat st; | |
4651 | + unsigned int iflags; /* inode->i_flags */ | |
4652 | +}; | |
4653 | + | |
1facf9fc | 4654 | +static noinline_for_stack |
86dc4139 AM |
4655 | +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src, |
4656 | + struct au_cpup_reg_attr *h_src_attr) | |
1facf9fc | 4657 | +{ |
c1595e42 | 4658 | + int err, sbits, icex; |
7e9cd9fe AM |
4659 | + unsigned int mnt_flags; |
4660 | + unsigned char verbose; | |
1facf9fc | 4661 | + struct iattr ia; |
4662 | + struct path h_path; | |
1308ab2a | 4663 | + struct inode *h_isrc, *h_idst; |
86dc4139 | 4664 | + struct kstat *h_st; |
c1595e42 | 4665 | + struct au_branch *br; |
1facf9fc | 4666 | + |
4667 | + h_path.dentry = au_h_dptr(dst, bindex); | |
5527c038 | 4668 | + h_idst = d_inode(h_path.dentry); |
c1595e42 JR |
4669 | + br = au_sbr(dst->d_sb, bindex); |
4670 | + h_path.mnt = au_br_mnt(br); | |
5527c038 | 4671 | + h_isrc = d_inode(h_src); |
1308ab2a | 4672 | + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID |
1facf9fc | 4673 | + | ATTR_ATIME | ATTR_MTIME |
4674 | + | ATTR_ATIME_SET | ATTR_MTIME_SET; | |
86dc4139 AM |
4675 | + if (h_src_attr && h_src_attr->valid) { |
4676 | + h_st = &h_src_attr->st; | |
4677 | + ia.ia_uid = h_st->uid; | |
4678 | + ia.ia_gid = h_st->gid; | |
4679 | + ia.ia_atime = h_st->atime; | |
4680 | + ia.ia_mtime = h_st->mtime; | |
4681 | + if (h_idst->i_mode != h_st->mode | |
4682 | + && !S_ISLNK(h_idst->i_mode)) { | |
4683 | + ia.ia_valid |= ATTR_MODE; | |
4684 | + ia.ia_mode = h_st->mode; | |
4685 | + } | |
4686 | + sbits = !!(h_st->mode & (S_ISUID | S_ISGID)); | |
4687 | + au_cpup_attr_flags(h_idst, h_src_attr->iflags); | |
4688 | + } else { | |
4689 | + ia.ia_uid = h_isrc->i_uid; | |
4690 | + ia.ia_gid = h_isrc->i_gid; | |
4691 | + ia.ia_atime = h_isrc->i_atime; | |
4692 | + ia.ia_mtime = h_isrc->i_mtime; | |
4693 | + if (h_idst->i_mode != h_isrc->i_mode | |
4694 | + && !S_ISLNK(h_idst->i_mode)) { | |
4695 | + ia.ia_valid |= ATTR_MODE; | |
4696 | + ia.ia_mode = h_isrc->i_mode; | |
4697 | + } | |
4698 | + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID)); | |
4699 | + au_cpup_attr_flags(h_idst, h_isrc->i_flags); | |
1308ab2a | 4700 | + } |
523b37e3 AM |
4701 | + /* no delegation since it is just created */ |
4702 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 4703 | + |
4704 | + /* is this nfs only? */ | |
4705 | + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) { | |
4706 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
4707 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 4708 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); |
1facf9fc | 4709 | + } |
4710 | + | |
c1595e42 | 4711 | + icex = br->br_perm & AuBrAttr_ICEX; |
7e9cd9fe AM |
4712 | + if (!err) { |
4713 | + mnt_flags = au_mntflags(dst->d_sb); | |
4714 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
4715 | + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose); | |
4716 | + } | |
c1595e42 | 4717 | + |
1facf9fc | 4718 | + return err; |
4719 | +} | |
4720 | + | |
4721 | +/* ---------------------------------------------------------------------- */ | |
4722 | + | |
4723 | +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len, | |
4724 | + char *buf, unsigned long blksize) | |
4725 | +{ | |
4726 | + int err; | |
4727 | + size_t sz, rbytes, wbytes; | |
4728 | + unsigned char all_zero; | |
4729 | + char *p, *zp; | |
4730 | + struct mutex *h_mtx; | |
4731 | + /* reduce stack usage */ | |
4732 | + struct iattr *ia; | |
4733 | + | |
4734 | + zp = page_address(ZERO_PAGE(0)); | |
4735 | + if (unlikely(!zp)) | |
4736 | + return -ENOMEM; /* possible? */ | |
4737 | + | |
4738 | + err = 0; | |
4739 | + all_zero = 0; | |
4740 | + while (len) { | |
4741 | + AuDbg("len %lld\n", len); | |
4742 | + sz = blksize; | |
4743 | + if (len < blksize) | |
4744 | + sz = len; | |
4745 | + | |
4746 | + rbytes = 0; | |
4747 | + /* todo: signal_pending? */ | |
4748 | + while (!rbytes || err == -EAGAIN || err == -EINTR) { | |
4749 | + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos); | |
4750 | + err = rbytes; | |
4751 | + } | |
4752 | + if (unlikely(err < 0)) | |
4753 | + break; | |
4754 | + | |
4755 | + all_zero = 0; | |
4756 | + if (len >= rbytes && rbytes == blksize) | |
4757 | + all_zero = !memcmp(buf, zp, rbytes); | |
4758 | + if (!all_zero) { | |
4759 | + wbytes = rbytes; | |
4760 | + p = buf; | |
4761 | + while (wbytes) { | |
4762 | + size_t b; | |
4763 | + | |
4764 | + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos); | |
4765 | + err = b; | |
4766 | + /* todo: signal_pending? */ | |
4767 | + if (unlikely(err == -EAGAIN || err == -EINTR)) | |
4768 | + continue; | |
4769 | + if (unlikely(err < 0)) | |
4770 | + break; | |
4771 | + wbytes -= b; | |
4772 | + p += b; | |
4773 | + } | |
392086de AM |
4774 | + if (unlikely(err < 0)) |
4775 | + break; | |
1facf9fc | 4776 | + } else { |
4777 | + loff_t res; | |
4778 | + | |
4779 | + AuLabel(hole); | |
4780 | + res = vfsub_llseek(dst, rbytes, SEEK_CUR); | |
4781 | + err = res; | |
4782 | + if (unlikely(res < 0)) | |
4783 | + break; | |
4784 | + } | |
4785 | + len -= rbytes; | |
4786 | + err = 0; | |
4787 | + } | |
4788 | + | |
4789 | + /* the last block may be a hole */ | |
4790 | + if (!err && all_zero) { | |
4791 | + AuLabel(last hole); | |
4792 | + | |
4793 | + err = 1; | |
2000de60 | 4794 | + if (au_test_nfs(dst->f_path.dentry->d_sb)) { |
1facf9fc | 4795 | + /* nfs requires this step to make last hole */ |
4796 | + /* is this only nfs? */ | |
4797 | + do { | |
4798 | + /* todo: signal_pending? */ | |
4799 | + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos); | |
4800 | + } while (err == -EAGAIN || err == -EINTR); | |
4801 | + if (err == 1) | |
4802 | + dst->f_pos--; | |
4803 | + } | |
4804 | + | |
4805 | + if (err == 1) { | |
4806 | + ia = (void *)buf; | |
4807 | + ia->ia_size = dst->f_pos; | |
4808 | + ia->ia_valid = ATTR_SIZE | ATTR_FILE; | |
4809 | + ia->ia_file = dst; | |
c06a8ce3 | 4810 | + h_mtx = &file_inode(dst)->i_mutex; |
1facf9fc | 4811 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2); |
523b37e3 AM |
4812 | + /* no delegation since it is just created */ |
4813 | + err = vfsub_notify_change(&dst->f_path, ia, | |
4814 | + /*delegated*/NULL); | |
1facf9fc | 4815 | + mutex_unlock(h_mtx); |
4816 | + } | |
4817 | + } | |
4818 | + | |
4819 | + return err; | |
4820 | +} | |
4821 | + | |
4822 | +int au_copy_file(struct file *dst, struct file *src, loff_t len) | |
4823 | +{ | |
4824 | + int err; | |
4825 | + unsigned long blksize; | |
4826 | + unsigned char do_kfree; | |
4827 | + char *buf; | |
4828 | + | |
4829 | + err = -ENOMEM; | |
2000de60 | 4830 | + blksize = dst->f_path.dentry->d_sb->s_blocksize; |
1facf9fc | 4831 | + if (!blksize || PAGE_SIZE < blksize) |
4832 | + blksize = PAGE_SIZE; | |
4833 | + AuDbg("blksize %lu\n", blksize); | |
4834 | + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *)); | |
4835 | + if (do_kfree) | |
4836 | + buf = kmalloc(blksize, GFP_NOFS); | |
4837 | + else | |
4838 | + buf = (void *)__get_free_page(GFP_NOFS); | |
4839 | + if (unlikely(!buf)) | |
4840 | + goto out; | |
4841 | + | |
4842 | + if (len > (1 << 22)) | |
4843 | + AuDbg("copying a large file %lld\n", (long long)len); | |
4844 | + | |
4845 | + src->f_pos = 0; | |
4846 | + dst->f_pos = 0; | |
4847 | + err = au_do_copy_file(dst, src, len, buf, blksize); | |
4848 | + if (do_kfree) | |
4849 | + kfree(buf); | |
4850 | + else | |
4851 | + free_page((unsigned long)buf); | |
4852 | + | |
4f0767ce | 4853 | +out: |
1facf9fc | 4854 | + return err; |
4855 | +} | |
4856 | + | |
4857 | +/* | |
4858 | + * to support a sparse file which is opened with O_APPEND, | |
4859 | + * we need to close the file. | |
4860 | + */ | |
c2b27bf2 | 4861 | +static int au_cp_regular(struct au_cp_generic *cpg) |
1facf9fc | 4862 | +{ |
4863 | + int err, i; | |
4864 | + enum { SRC, DST }; | |
4865 | + struct { | |
4866 | + aufs_bindex_t bindex; | |
4867 | + unsigned int flags; | |
4868 | + struct dentry *dentry; | |
392086de | 4869 | + int force_wr; |
1facf9fc | 4870 | + struct file *file; |
523b37e3 | 4871 | + void *label; |
1facf9fc | 4872 | + } *f, file[] = { |
4873 | + { | |
c2b27bf2 | 4874 | + .bindex = cpg->bsrc, |
1facf9fc | 4875 | + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE, |
523b37e3 | 4876 | + .label = &&out |
1facf9fc | 4877 | + }, |
4878 | + { | |
c2b27bf2 | 4879 | + .bindex = cpg->bdst, |
1facf9fc | 4880 | + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE, |
392086de | 4881 | + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST), |
523b37e3 | 4882 | + .label = &&out_src |
1facf9fc | 4883 | + } |
4884 | + }; | |
4885 | + struct super_block *sb; | |
4886 | + | |
4887 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 4888 | + sb = cpg->dentry->d_sb; |
1facf9fc | 4889 | + f = file; |
4890 | + for (i = 0; i < 2; i++, f++) { | |
c2b27bf2 AM |
4891 | + f->dentry = au_h_dptr(cpg->dentry, f->bindex); |
4892 | + f->file = au_h_open(cpg->dentry, f->bindex, f->flags, | |
392086de | 4893 | + /*file*/NULL, f->force_wr); |
1facf9fc | 4894 | + err = PTR_ERR(f->file); |
4895 | + if (IS_ERR(f->file)) | |
4896 | + goto *f->label; | |
1facf9fc | 4897 | + } |
4898 | + | |
4899 | + /* try stopping to update while we copyup */ | |
5527c038 | 4900 | + IMustLock(d_inode(file[SRC].dentry)); |
c2b27bf2 | 4901 | + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len); |
1facf9fc | 4902 | + |
1facf9fc | 4903 | + fput(file[DST].file); |
4904 | + au_sbr_put(sb, file[DST].bindex); | |
523b37e3 | 4905 | + |
4f0767ce | 4906 | +out_src: |
1facf9fc | 4907 | + fput(file[SRC].file); |
4908 | + au_sbr_put(sb, file[SRC].bindex); | |
4f0767ce | 4909 | +out: |
1facf9fc | 4910 | + return err; |
4911 | +} | |
4912 | + | |
c2b27bf2 | 4913 | +static int au_do_cpup_regular(struct au_cp_generic *cpg, |
86dc4139 | 4914 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 4915 | +{ |
4916 | + int err, rerr; | |
4917 | + loff_t l; | |
86dc4139 | 4918 | + struct path h_path; |
38d290e6 | 4919 | + struct inode *h_src_inode, *h_dst_inode; |
1facf9fc | 4920 | + |
4921 | + err = 0; | |
5527c038 | 4922 | + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc); |
86dc4139 | 4923 | + l = i_size_read(h_src_inode); |
c2b27bf2 AM |
4924 | + if (cpg->len == -1 || l < cpg->len) |
4925 | + cpg->len = l; | |
4926 | + if (cpg->len) { | |
86dc4139 AM |
4927 | + /* try stopping to update while we are referencing */ |
4928 | + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD); | |
c2b27bf2 | 4929 | + au_pin_hdir_unlock(cpg->pin); |
1facf9fc | 4930 | + |
c2b27bf2 AM |
4931 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
4932 | + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc); | |
86dc4139 | 4933 | + h_src_attr->iflags = h_src_inode->i_flags; |
5527c038 JR |
4934 | + if (!au_test_nfs(h_src_inode->i_sb)) |
4935 | + err = vfs_getattr(&h_path, &h_src_attr->st); | |
4936 | + else { | |
4937 | + mutex_unlock(&h_src_inode->i_mutex); | |
4938 | + err = vfs_getattr(&h_path, &h_src_attr->st); | |
4939 | + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD); | |
4940 | + } | |
86dc4139 AM |
4941 | + if (unlikely(err)) { |
4942 | + mutex_unlock(&h_src_inode->i_mutex); | |
4943 | + goto out; | |
4944 | + } | |
4945 | + h_src_attr->valid = 1; | |
c2b27bf2 | 4946 | + err = au_cp_regular(cpg); |
86dc4139 | 4947 | + mutex_unlock(&h_src_inode->i_mutex); |
c2b27bf2 | 4948 | + rerr = au_pin_hdir_relock(cpg->pin); |
86dc4139 AM |
4949 | + if (!err && rerr) |
4950 | + err = rerr; | |
1facf9fc | 4951 | + } |
38d290e6 JR |
4952 | + if (!err && (h_src_inode->i_state & I_LINKABLE)) { |
4953 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst); | |
5527c038 | 4954 | + h_dst_inode = d_inode(h_path.dentry); |
38d290e6 JR |
4955 | + spin_lock(&h_dst_inode->i_lock); |
4956 | + h_dst_inode->i_state |= I_LINKABLE; | |
4957 | + spin_unlock(&h_dst_inode->i_lock); | |
4958 | + } | |
1facf9fc | 4959 | + |
4f0767ce | 4960 | +out: |
1facf9fc | 4961 | + return err; |
4962 | +} | |
4963 | + | |
4964 | +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src, | |
4965 | + struct inode *h_dir) | |
4966 | +{ | |
4967 | + int err, symlen; | |
4968 | + mm_segment_t old_fs; | |
b752ccd1 AM |
4969 | + union { |
4970 | + char *k; | |
4971 | + char __user *u; | |
4972 | + } sym; | |
5527c038 JR |
4973 | + struct inode *h_inode = d_inode(h_src); |
4974 | + const struct inode_operations *h_iop = h_inode->i_op; | |
1facf9fc | 4975 | + |
4976 | + err = -ENOSYS; | |
5527c038 | 4977 | + if (unlikely(!h_iop->readlink)) |
1facf9fc | 4978 | + goto out; |
4979 | + | |
4980 | + err = -ENOMEM; | |
537831f9 | 4981 | + sym.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 4982 | + if (unlikely(!sym.k)) |
1facf9fc | 4983 | + goto out; |
4984 | + | |
9dbd164d | 4985 | + /* unnecessary to support mmap_sem since symlink is not mmap-able */ |
1facf9fc | 4986 | + old_fs = get_fs(); |
4987 | + set_fs(KERNEL_DS); | |
5527c038 | 4988 | + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX); |
1facf9fc | 4989 | + err = symlen; |
4990 | + set_fs(old_fs); | |
4991 | + | |
4992 | + if (symlen > 0) { | |
b752ccd1 AM |
4993 | + sym.k[symlen] = 0; |
4994 | + err = vfsub_symlink(h_dir, h_path, sym.k); | |
1facf9fc | 4995 | + } |
537831f9 | 4996 | + free_page((unsigned long)sym.k); |
1facf9fc | 4997 | + |
4f0767ce | 4998 | +out: |
1facf9fc | 4999 | + return err; |
5000 | +} | |
5001 | + | |
1facf9fc | 5002 | +static noinline_for_stack |
c2b27bf2 | 5003 | +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent, |
86dc4139 | 5004 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5005 | +{ |
5006 | + int err; | |
5007 | + umode_t mode; | |
5008 | + unsigned int mnt_flags; | |
076b876e | 5009 | + unsigned char isdir, isreg, force; |
c2b27bf2 | 5010 | + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5011 | + struct au_dtime dt; |
5012 | + struct path h_path; | |
5013 | + struct dentry *h_src, *h_dst, *h_parent; | |
5527c038 | 5014 | + struct inode *h_inode, *h_dir, *dir, *inode; |
1facf9fc | 5015 | + struct super_block *sb; |
5016 | + | |
5017 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5018 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 JR |
5019 | + h_inode = d_inode(h_src); |
5020 | + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc)); | |
1facf9fc | 5021 | + |
5022 | + /* try stopping to be referenced while we are creating */ | |
c2b27bf2 AM |
5023 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); |
5024 | + if (au_ftest_cpup(cpg->flags, RENAME)) | |
86dc4139 AM |
5025 | + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX, |
5026 | + AUFS_WH_PFX_LEN)); | |
1facf9fc | 5027 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5028 | + h_dir = d_inode(h_parent); |
1facf9fc | 5029 | + IMustLock(h_dir); |
5030 | + AuDebugOn(h_parent != h_dst->d_parent); | |
5031 | + | |
c2b27bf2 AM |
5032 | + sb = cpg->dentry->d_sb; |
5033 | + h_path.mnt = au_sbr_mnt(sb, cpg->bdst); | |
1facf9fc | 5034 | + if (do_dt) { |
5035 | + h_path.dentry = h_parent; | |
5036 | + au_dtime_store(&dt, dst_parent, &h_path); | |
5037 | + } | |
5038 | + h_path.dentry = h_dst; | |
5039 | + | |
076b876e | 5040 | + isreg = 0; |
1facf9fc | 5041 | + isdir = 0; |
5042 | + mode = h_inode->i_mode; | |
5043 | + switch (mode & S_IFMT) { | |
5044 | + case S_IFREG: | |
076b876e | 5045 | + isreg = 1; |
b4510431 AM |
5046 | + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR, |
5047 | + /*want_excl*/true); | |
1facf9fc | 5048 | + if (!err) |
c2b27bf2 | 5049 | + err = au_do_cpup_regular(cpg, h_src_attr); |
1facf9fc | 5050 | + break; |
5051 | + case S_IFDIR: | |
5052 | + isdir = 1; | |
5053 | + err = vfsub_mkdir(h_dir, &h_path, mode); | |
5054 | + if (!err) { | |
5055 | + /* | |
5056 | + * strange behaviour from the users view, | |
5057 | + * particularry setattr case | |
5058 | + */ | |
5527c038 JR |
5059 | + dir = d_inode(dst_parent); |
5060 | + if (au_ibstart(dir) == cpg->bdst) | |
5061 | + au_cpup_attr_nlink(dir, /*force*/1); | |
5062 | + inode = d_inode(cpg->dentry); | |
5063 | + au_cpup_attr_nlink(inode, /*force*/1); | |
1facf9fc | 5064 | + } |
5065 | + break; | |
5066 | + case S_IFLNK: | |
5067 | + err = au_do_cpup_symlink(&h_path, h_src, h_dir); | |
5068 | + break; | |
5069 | + case S_IFCHR: | |
5070 | + case S_IFBLK: | |
5071 | + AuDebugOn(!capable(CAP_MKNOD)); | |
5072 | + /*FALLTHROUGH*/ | |
5073 | + case S_IFIFO: | |
5074 | + case S_IFSOCK: | |
5075 | + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev); | |
5076 | + break; | |
5077 | + default: | |
5078 | + AuIOErr("Unknown inode type 0%o\n", mode); | |
5079 | + err = -EIO; | |
5080 | + } | |
5081 | + | |
5082 | + mnt_flags = au_mntflags(sb); | |
5083 | + if (!au_opt_test(mnt_flags, UDBA_NONE) | |
5084 | + && !isdir | |
5085 | + && au_opt_test(mnt_flags, XINO) | |
38d290e6 JR |
5086 | + && (h_inode->i_nlink == 1 |
5087 | + || (h_inode->i_state & I_LINKABLE)) | |
1facf9fc | 5088 | + /* todo: unnecessary? */ |
5527c038 | 5089 | + /* && d_inode(cpg->dentry)->i_nlink == 1 */ |
c2b27bf2 AM |
5090 | + && cpg->bdst < cpg->bsrc |
5091 | + && !au_ftest_cpup(cpg->flags, KEEPLINO)) | |
5092 | + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0); | |
1facf9fc | 5093 | + /* ignore this error */ |
5094 | + | |
076b876e AM |
5095 | + if (!err) { |
5096 | + force = 0; | |
5097 | + if (isreg) { | |
5098 | + force = !!cpg->len; | |
5099 | + if (cpg->len == -1) | |
5100 | + force = !!i_size_read(h_inode); | |
5101 | + } | |
5102 | + au_fhsm_wrote(sb, cpg->bdst, force); | |
5103 | + } | |
5104 | + | |
1facf9fc | 5105 | + if (do_dt) |
5106 | + au_dtime_revert(&dt); | |
5107 | + return err; | |
5108 | +} | |
5109 | + | |
392086de | 5110 | +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path) |
86dc4139 AM |
5111 | +{ |
5112 | + int err; | |
392086de | 5113 | + struct dentry *dentry, *h_dentry, *h_parent, *parent; |
86dc4139 | 5114 | + struct inode *h_dir; |
392086de | 5115 | + aufs_bindex_t bdst; |
86dc4139 | 5116 | + |
392086de AM |
5117 | + dentry = cpg->dentry; |
5118 | + bdst = cpg->bdst; | |
5119 | + h_dentry = au_h_dptr(dentry, bdst); | |
5120 | + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) { | |
5121 | + dget(h_dentry); | |
5122 | + au_set_h_dptr(dentry, bdst, NULL); | |
5123 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); | |
5124 | + if (!err) | |
5125 | + h_path->dentry = dget(au_h_dptr(dentry, bdst)); | |
86dc4139 | 5126 | + au_set_h_dptr(dentry, bdst, h_dentry); |
392086de AM |
5127 | + } else { |
5128 | + err = 0; | |
5129 | + parent = dget_parent(dentry); | |
5130 | + h_parent = au_h_dptr(parent, bdst); | |
5131 | + dput(parent); | |
5132 | + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
5133 | + if (IS_ERR(h_path->dentry)) | |
5134 | + err = PTR_ERR(h_path->dentry); | |
86dc4139 | 5135 | + } |
392086de AM |
5136 | + if (unlikely(err)) |
5137 | + goto out; | |
86dc4139 | 5138 | + |
86dc4139 | 5139 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ |
5527c038 | 5140 | + h_dir = d_inode(h_parent); |
86dc4139 | 5141 | + IMustLock(h_dir); |
523b37e3 AM |
5142 | + AuDbg("%pd %pd\n", h_dentry, h_path->dentry); |
5143 | + /* no delegation since it is just created */ | |
5144 | + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL); | |
86dc4139 AM |
5145 | + dput(h_path->dentry); |
5146 | + | |
5147 | +out: | |
5148 | + return err; | |
5149 | +} | |
5150 | + | |
1facf9fc | 5151 | +/* |
5152 | + * copyup the @dentry from @bsrc to @bdst. | |
5153 | + * the caller must set the both of lower dentries. | |
5154 | + * @len is for truncating when it is -1 copyup the entire file. | |
5155 | + * in link/rename cases, @dst_parent may be different from the real one. | |
c2b27bf2 | 5156 | + * basic->bsrc can be larger than basic->bdst. |
1facf9fc | 5157 | + */ |
c2b27bf2 | 5158 | +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5159 | +{ |
5160 | + int err, rerr; | |
5161 | + aufs_bindex_t old_ibstart; | |
5162 | + unsigned char isdir, plink; | |
1facf9fc | 5163 | + struct dentry *h_src, *h_dst, *h_parent; |
5527c038 | 5164 | + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode; |
1facf9fc | 5165 | + struct super_block *sb; |
86dc4139 | 5166 | + struct au_branch *br; |
c2b27bf2 AM |
5167 | + /* to reuduce stack size */ |
5168 | + struct { | |
5169 | + struct au_dtime dt; | |
5170 | + struct path h_path; | |
5171 | + struct au_cpup_reg_attr h_src_attr; | |
5172 | + } *a; | |
1facf9fc | 5173 | + |
c2b27bf2 AM |
5174 | + err = -ENOMEM; |
5175 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
5176 | + if (unlikely(!a)) | |
5177 | + goto out; | |
5178 | + a->h_src_attr.valid = 0; | |
1facf9fc | 5179 | + |
c2b27bf2 AM |
5180 | + sb = cpg->dentry->d_sb; |
5181 | + br = au_sbr(sb, cpg->bdst); | |
5182 | + a->h_path.mnt = au_br_mnt(br); | |
5183 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); | |
1facf9fc | 5184 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5185 | + h_dir = d_inode(h_parent); |
1facf9fc | 5186 | + IMustLock(h_dir); |
5187 | + | |
c2b27bf2 | 5188 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5189 | + inode = d_inode(cpg->dentry); |
1facf9fc | 5190 | + |
5191 | + if (!dst_parent) | |
c2b27bf2 | 5192 | + dst_parent = dget_parent(cpg->dentry); |
1facf9fc | 5193 | + else |
5194 | + dget(dst_parent); | |
5195 | + | |
5196 | + plink = !!au_opt_test(au_mntflags(sb), PLINK); | |
c2b27bf2 | 5197 | + dst_inode = au_h_iptr(inode, cpg->bdst); |
1facf9fc | 5198 | + if (dst_inode) { |
5199 | + if (unlikely(!plink)) { | |
5200 | + err = -EIO; | |
027c5e7a AM |
5201 | + AuIOErr("hi%lu(i%lu) exists on b%d " |
5202 | + "but plink is disabled\n", | |
c2b27bf2 AM |
5203 | + dst_inode->i_ino, inode->i_ino, cpg->bdst); |
5204 | + goto out_parent; | |
1facf9fc | 5205 | + } |
5206 | + | |
5207 | + if (dst_inode->i_nlink) { | |
c2b27bf2 | 5208 | + const int do_dt = au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5209 | + |
c2b27bf2 | 5210 | + h_src = au_plink_lkup(inode, cpg->bdst); |
1facf9fc | 5211 | + err = PTR_ERR(h_src); |
5212 | + if (IS_ERR(h_src)) | |
c2b27bf2 | 5213 | + goto out_parent; |
5527c038 | 5214 | + if (unlikely(d_is_negative(h_src))) { |
1facf9fc | 5215 | + err = -EIO; |
5216 | + AuIOErr("i%lu exists on a upper branch " | |
027c5e7a AM |
5217 | + "but not pseudo-linked\n", |
5218 | + inode->i_ino); | |
1facf9fc | 5219 | + dput(h_src); |
c2b27bf2 | 5220 | + goto out_parent; |
1facf9fc | 5221 | + } |
5222 | + | |
5223 | + if (do_dt) { | |
c2b27bf2 AM |
5224 | + a->h_path.dentry = h_parent; |
5225 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
1facf9fc | 5226 | + } |
86dc4139 | 5227 | + |
c2b27bf2 | 5228 | + a->h_path.dentry = h_dst; |
523b37e3 AM |
5229 | + delegated = NULL; |
5230 | + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated); | |
c2b27bf2 | 5231 | + if (!err && au_ftest_cpup(cpg->flags, RENAME)) |
392086de | 5232 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
1facf9fc | 5233 | + if (do_dt) |
c2b27bf2 | 5234 | + au_dtime_revert(&a->dt); |
523b37e3 AM |
5235 | + if (unlikely(err == -EWOULDBLOCK)) { |
5236 | + pr_warn("cannot retry for NFSv4 delegation" | |
5237 | + " for an internal link\n"); | |
5238 | + iput(delegated); | |
5239 | + } | |
1facf9fc | 5240 | + dput(h_src); |
c2b27bf2 | 5241 | + goto out_parent; |
1facf9fc | 5242 | + } else |
5243 | + /* todo: cpup_wh_file? */ | |
5244 | + /* udba work */ | |
4a4d8108 | 5245 | + au_update_ibrange(inode, /*do_put_zero*/1); |
1facf9fc | 5246 | + } |
5247 | + | |
86dc4139 | 5248 | + isdir = S_ISDIR(inode->i_mode); |
1facf9fc | 5249 | + old_ibstart = au_ibstart(inode); |
c2b27bf2 | 5250 | + err = cpup_entry(cpg, dst_parent, &a->h_src_attr); |
1facf9fc | 5251 | + if (unlikely(err)) |
86dc4139 | 5252 | + goto out_rev; |
5527c038 | 5253 | + dst_inode = d_inode(h_dst); |
1facf9fc | 5254 | + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2); |
86dc4139 | 5255 | + /* todo: necessary? */ |
c2b27bf2 | 5256 | + /* au_pin_hdir_unlock(cpg->pin); */ |
1facf9fc | 5257 | + |
c2b27bf2 | 5258 | + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr); |
86dc4139 AM |
5259 | + if (unlikely(err)) { |
5260 | + /* todo: necessary? */ | |
c2b27bf2 | 5261 | + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */ |
86dc4139 AM |
5262 | + mutex_unlock(&dst_inode->i_mutex); |
5263 | + goto out_rev; | |
5264 | + } | |
5265 | + | |
c2b27bf2 | 5266 | + if (cpg->bdst < old_ibstart) { |
86dc4139 | 5267 | + if (S_ISREG(inode->i_mode)) { |
c2b27bf2 | 5268 | + err = au_dy_iaop(inode, cpg->bdst, dst_inode); |
86dc4139 | 5269 | + if (unlikely(err)) { |
c2b27bf2 AM |
5270 | + /* ignore an error */ |
5271 | + /* au_pin_hdir_relock(cpg->pin); */ | |
86dc4139 AM |
5272 | + mutex_unlock(&dst_inode->i_mutex); |
5273 | + goto out_rev; | |
4a4d8108 | 5274 | + } |
4a4d8108 | 5275 | + } |
c2b27bf2 AM |
5276 | + au_set_ibstart(inode, cpg->bdst); |
5277 | + } else | |
5278 | + au_set_ibend(inode, cpg->bdst); | |
5279 | + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode), | |
86dc4139 AM |
5280 | + au_hi_flags(inode, isdir)); |
5281 | + | |
5282 | + /* todo: necessary? */ | |
c2b27bf2 | 5283 | + /* err = au_pin_hdir_relock(cpg->pin); */ |
86dc4139 AM |
5284 | + mutex_unlock(&dst_inode->i_mutex); |
5285 | + if (unlikely(err)) | |
5286 | + goto out_rev; | |
5287 | + | |
5527c038 | 5288 | + src_inode = d_inode(h_src); |
86dc4139 | 5289 | + if (!isdir |
5527c038 JR |
5290 | + && (src_inode->i_nlink > 1 |
5291 | + || src_inode->i_state & I_LINKABLE) | |
86dc4139 | 5292 | + && plink) |
c2b27bf2 | 5293 | + au_plink_append(inode, cpg->bdst, h_dst); |
86dc4139 | 5294 | + |
c2b27bf2 AM |
5295 | + if (au_ftest_cpup(cpg->flags, RENAME)) { |
5296 | + a->h_path.dentry = h_dst; | |
392086de | 5297 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
86dc4139 AM |
5298 | + } |
5299 | + if (!err) | |
c2b27bf2 | 5300 | + goto out_parent; /* success */ |
1facf9fc | 5301 | + |
5302 | + /* revert */ | |
4a4d8108 | 5303 | +out_rev: |
c2b27bf2 AM |
5304 | + a->h_path.dentry = h_parent; |
5305 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
5306 | + a->h_path.dentry = h_dst; | |
86dc4139 | 5307 | + rerr = 0; |
5527c038 | 5308 | + if (d_is_positive(h_dst)) { |
523b37e3 AM |
5309 | + if (!isdir) { |
5310 | + /* no delegation since it is just created */ | |
5311 | + rerr = vfsub_unlink(h_dir, &a->h_path, | |
5312 | + /*delegated*/NULL, /*force*/0); | |
5313 | + } else | |
c2b27bf2 | 5314 | + rerr = vfsub_rmdir(h_dir, &a->h_path); |
86dc4139 | 5315 | + } |
c2b27bf2 | 5316 | + au_dtime_revert(&a->dt); |
1facf9fc | 5317 | + if (rerr) { |
5318 | + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr); | |
5319 | + err = -EIO; | |
5320 | + } | |
c2b27bf2 | 5321 | +out_parent: |
1facf9fc | 5322 | + dput(dst_parent); |
c2b27bf2 AM |
5323 | + kfree(a); |
5324 | +out: | |
1facf9fc | 5325 | + return err; |
5326 | +} | |
5327 | + | |
7e9cd9fe | 5328 | +#if 0 /* reserved */ |
1facf9fc | 5329 | +struct au_cpup_single_args { |
5330 | + int *errp; | |
c2b27bf2 | 5331 | + struct au_cp_generic *cpg; |
1facf9fc | 5332 | + struct dentry *dst_parent; |
5333 | +}; | |
5334 | + | |
5335 | +static void au_call_cpup_single(void *args) | |
5336 | +{ | |
5337 | + struct au_cpup_single_args *a = args; | |
86dc4139 | 5338 | + |
c2b27bf2 AM |
5339 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5340 | + *a->errp = au_cpup_single(a->cpg, a->dst_parent); | |
5341 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5342 | +} |
c2b27bf2 | 5343 | +#endif |
1facf9fc | 5344 | + |
53392da6 AM |
5345 | +/* |
5346 | + * prevent SIGXFSZ in copy-up. | |
5347 | + * testing CAP_MKNOD is for generic fs, | |
5348 | + * but CAP_FSETID is for xfs only, currently. | |
5349 | + */ | |
86dc4139 | 5350 | +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode) |
53392da6 AM |
5351 | +{ |
5352 | + int do_sio; | |
86dc4139 AM |
5353 | + struct super_block *sb; |
5354 | + struct inode *h_dir; | |
53392da6 AM |
5355 | + |
5356 | + do_sio = 0; | |
86dc4139 | 5357 | + sb = au_pinned_parent(pin)->d_sb; |
53392da6 AM |
5358 | + if (!au_wkq_test() |
5359 | + && (!au_sbi(sb)->si_plink_maint_pid | |
5360 | + || au_plink_maint(sb, AuLock_NOPLM))) { | |
5361 | + switch (mode & S_IFMT) { | |
5362 | + case S_IFREG: | |
5363 | + /* no condition about RLIMIT_FSIZE and the file size */ | |
5364 | + do_sio = 1; | |
5365 | + break; | |
5366 | + case S_IFCHR: | |
5367 | + case S_IFBLK: | |
5368 | + do_sio = !capable(CAP_MKNOD); | |
5369 | + break; | |
5370 | + } | |
5371 | + if (!do_sio) | |
5372 | + do_sio = ((mode & (S_ISUID | S_ISGID)) | |
5373 | + && !capable(CAP_FSETID)); | |
86dc4139 AM |
5374 | + /* this workaround may be removed in the future */ |
5375 | + if (!do_sio) { | |
5376 | + h_dir = au_pinned_h_dir(pin); | |
5377 | + do_sio = h_dir->i_mode & S_ISVTX; | |
5378 | + } | |
53392da6 AM |
5379 | + } |
5380 | + | |
5381 | + return do_sio; | |
5382 | +} | |
5383 | + | |
7e9cd9fe | 5384 | +#if 0 /* reserved */ |
c2b27bf2 | 5385 | +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5386 | +{ |
5387 | + int err, wkq_err; | |
1facf9fc | 5388 | + struct dentry *h_dentry; |
5389 | + | |
c2b27bf2 | 5390 | + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5391 | + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode)) |
c2b27bf2 | 5392 | + err = au_cpup_single(cpg, dst_parent); |
1facf9fc | 5393 | + else { |
5394 | + struct au_cpup_single_args args = { | |
5395 | + .errp = &err, | |
c2b27bf2 AM |
5396 | + .cpg = cpg, |
5397 | + .dst_parent = dst_parent | |
1facf9fc | 5398 | + }; |
5399 | + wkq_err = au_wkq_wait(au_call_cpup_single, &args); | |
5400 | + if (unlikely(wkq_err)) | |
5401 | + err = wkq_err; | |
5402 | + } | |
5403 | + | |
5404 | + return err; | |
5405 | +} | |
c2b27bf2 | 5406 | +#endif |
1facf9fc | 5407 | + |
5408 | +/* | |
5409 | + * copyup the @dentry from the first active lower branch to @bdst, | |
5410 | + * using au_cpup_single(). | |
5411 | + */ | |
c2b27bf2 | 5412 | +static int au_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5413 | +{ |
5414 | + int err; | |
c2b27bf2 AM |
5415 | + unsigned int flags_orig; |
5416 | + struct dentry *dentry; | |
5417 | + | |
5418 | + AuDebugOn(cpg->bsrc < 0); | |
1facf9fc | 5419 | + |
c2b27bf2 | 5420 | + dentry = cpg->dentry; |
86dc4139 | 5421 | + DiMustWriteLock(dentry); |
1facf9fc | 5422 | + |
c2b27bf2 | 5423 | + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1); |
1facf9fc | 5424 | + if (!err) { |
c2b27bf2 AM |
5425 | + flags_orig = cpg->flags; |
5426 | + au_fset_cpup(cpg->flags, RENAME); | |
5427 | + err = au_cpup_single(cpg, NULL); | |
5428 | + cpg->flags = flags_orig; | |
1facf9fc | 5429 | + if (!err) |
5430 | + return 0; /* success */ | |
5431 | + | |
5432 | + /* revert */ | |
c2b27bf2 AM |
5433 | + au_set_h_dptr(dentry, cpg->bdst, NULL); |
5434 | + au_set_dbstart(dentry, cpg->bsrc); | |
1facf9fc | 5435 | + } |
5436 | + | |
5437 | + return err; | |
5438 | +} | |
5439 | + | |
5440 | +struct au_cpup_simple_args { | |
5441 | + int *errp; | |
c2b27bf2 | 5442 | + struct au_cp_generic *cpg; |
1facf9fc | 5443 | +}; |
5444 | + | |
5445 | +static void au_call_cpup_simple(void *args) | |
5446 | +{ | |
5447 | + struct au_cpup_simple_args *a = args; | |
86dc4139 | 5448 | + |
c2b27bf2 AM |
5449 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5450 | + *a->errp = au_cpup_simple(a->cpg); | |
5451 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5452 | +} |
5453 | + | |
c2b27bf2 | 5454 | +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5455 | +{ |
5456 | + int err, wkq_err; | |
c2b27bf2 AM |
5457 | + struct dentry *dentry, *parent; |
5458 | + struct file *h_file; | |
1facf9fc | 5459 | + struct inode *h_dir; |
5460 | + | |
c2b27bf2 AM |
5461 | + dentry = cpg->dentry; |
5462 | + h_file = NULL; | |
5463 | + if (au_ftest_cpup(cpg->flags, HOPEN)) { | |
5464 | + AuDebugOn(cpg->bsrc < 0); | |
392086de | 5465 | + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0); |
c2b27bf2 AM |
5466 | + err = PTR_ERR(h_file); |
5467 | + if (IS_ERR(h_file)) | |
5468 | + goto out; | |
5469 | + } | |
5470 | + | |
1facf9fc | 5471 | + parent = dget_parent(dentry); |
5527c038 | 5472 | + h_dir = au_h_iptr(d_inode(parent), cpg->bdst); |
53392da6 | 5473 | + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE) |
5527c038 | 5474 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 5475 | + err = au_cpup_simple(cpg); |
1facf9fc | 5476 | + else { |
5477 | + struct au_cpup_simple_args args = { | |
5478 | + .errp = &err, | |
c2b27bf2 | 5479 | + .cpg = cpg |
1facf9fc | 5480 | + }; |
5481 | + wkq_err = au_wkq_wait(au_call_cpup_simple, &args); | |
5482 | + if (unlikely(wkq_err)) | |
5483 | + err = wkq_err; | |
5484 | + } | |
5485 | + | |
5486 | + dput(parent); | |
c2b27bf2 AM |
5487 | + if (h_file) |
5488 | + au_h_open_post(dentry, cpg->bsrc, h_file); | |
5489 | + | |
5490 | +out: | |
1facf9fc | 5491 | + return err; |
5492 | +} | |
5493 | + | |
c2b27bf2 | 5494 | +int au_sio_cpup_simple(struct au_cp_generic *cpg) |
367653fa | 5495 | +{ |
c2b27bf2 AM |
5496 | + aufs_bindex_t bsrc, bend; |
5497 | + struct dentry *dentry, *h_dentry; | |
367653fa | 5498 | + |
c2b27bf2 AM |
5499 | + if (cpg->bsrc < 0) { |
5500 | + dentry = cpg->dentry; | |
5501 | + bend = au_dbend(dentry); | |
5502 | + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) { | |
5503 | + h_dentry = au_h_dptr(dentry, bsrc); | |
5504 | + if (h_dentry) { | |
5527c038 | 5505 | + AuDebugOn(d_is_negative(h_dentry)); |
c2b27bf2 AM |
5506 | + break; |
5507 | + } | |
5508 | + } | |
5509 | + AuDebugOn(bsrc > bend); | |
5510 | + cpg->bsrc = bsrc; | |
367653fa | 5511 | + } |
c2b27bf2 AM |
5512 | + AuDebugOn(cpg->bsrc <= cpg->bdst); |
5513 | + return au_do_sio_cpup_simple(cpg); | |
5514 | +} | |
367653fa | 5515 | + |
c2b27bf2 AM |
5516 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg) |
5517 | +{ | |
5518 | + AuDebugOn(cpg->bdst <= cpg->bsrc); | |
5519 | + return au_do_sio_cpup_simple(cpg); | |
367653fa AM |
5520 | +} |
5521 | + | |
1facf9fc | 5522 | +/* ---------------------------------------------------------------------- */ |
5523 | + | |
5524 | +/* | |
5525 | + * copyup the deleted file for writing. | |
5526 | + */ | |
c2b27bf2 AM |
5527 | +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry, |
5528 | + struct file *file) | |
1facf9fc | 5529 | +{ |
5530 | + int err; | |
c2b27bf2 AM |
5531 | + unsigned int flags_orig; |
5532 | + aufs_bindex_t bsrc_orig; | |
1facf9fc | 5533 | + struct dentry *h_d_dst, *h_d_start; |
c2b27bf2 | 5534 | + struct au_dinfo *dinfo; |
4a4d8108 | 5535 | + struct au_hdentry *hdp; |
1facf9fc | 5536 | + |
c2b27bf2 | 5537 | + dinfo = au_di(cpg->dentry); |
1308ab2a | 5538 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
5539 | + | |
c2b27bf2 AM |
5540 | + bsrc_orig = cpg->bsrc; |
5541 | + cpg->bsrc = dinfo->di_bstart; | |
4a4d8108 | 5542 | + hdp = dinfo->di_hdentry; |
c2b27bf2 AM |
5543 | + h_d_dst = hdp[0 + cpg->bdst].hd_dentry; |
5544 | + dinfo->di_bstart = cpg->bdst; | |
5545 | + hdp[0 + cpg->bdst].hd_dentry = wh_dentry; | |
86dc4139 | 5546 | + h_d_start = NULL; |
027c5e7a | 5547 | + if (file) { |
c2b27bf2 | 5548 | + h_d_start = hdp[0 + cpg->bsrc].hd_dentry; |
2000de60 | 5549 | + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry; |
027c5e7a | 5550 | + } |
c2b27bf2 AM |
5551 | + flags_orig = cpg->flags; |
5552 | + cpg->flags = !AuCpup_DTIME; | |
5553 | + err = au_cpup_single(cpg, /*h_parent*/NULL); | |
5554 | + cpg->flags = flags_orig; | |
027c5e7a AM |
5555 | + if (file) { |
5556 | + if (!err) | |
5557 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 5558 | + hdp[0 + cpg->bsrc].hd_dentry = h_d_start; |
1facf9fc | 5559 | + } |
c2b27bf2 AM |
5560 | + hdp[0 + cpg->bdst].hd_dentry = h_d_dst; |
5561 | + dinfo->di_bstart = cpg->bsrc; | |
5562 | + cpg->bsrc = bsrc_orig; | |
1facf9fc | 5563 | + |
5564 | + return err; | |
5565 | +} | |
5566 | + | |
c2b27bf2 | 5567 | +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5568 | +{ |
5569 | + int err; | |
c2b27bf2 | 5570 | + aufs_bindex_t bdst; |
1facf9fc | 5571 | + struct au_dtime dt; |
c2b27bf2 | 5572 | + struct dentry *dentry, *parent, *h_parent, *wh_dentry; |
1facf9fc | 5573 | + struct au_branch *br; |
5574 | + struct path h_path; | |
5575 | + | |
c2b27bf2 AM |
5576 | + dentry = cpg->dentry; |
5577 | + bdst = cpg->bdst; | |
1facf9fc | 5578 | + br = au_sbr(dentry->d_sb, bdst); |
5579 | + parent = dget_parent(dentry); | |
5580 | + h_parent = au_h_dptr(parent, bdst); | |
5581 | + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
5582 | + err = PTR_ERR(wh_dentry); | |
5583 | + if (IS_ERR(wh_dentry)) | |
5584 | + goto out; | |
5585 | + | |
5586 | + h_path.dentry = h_parent; | |
86dc4139 | 5587 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 5588 | + au_dtime_store(&dt, parent, &h_path); |
c2b27bf2 | 5589 | + err = au_do_cpup_wh(cpg, wh_dentry, file); |
1facf9fc | 5590 | + if (unlikely(err)) |
5591 | + goto out_wh; | |
5592 | + | |
5593 | + dget(wh_dentry); | |
5594 | + h_path.dentry = wh_dentry; | |
2000de60 | 5595 | + if (!d_is_dir(wh_dentry)) { |
523b37e3 | 5596 | + /* no delegation since it is just created */ |
5527c038 | 5597 | + err = vfsub_unlink(d_inode(h_parent), &h_path, |
523b37e3 AM |
5598 | + /*delegated*/NULL, /*force*/0); |
5599 | + } else | |
5527c038 | 5600 | + err = vfsub_rmdir(d_inode(h_parent), &h_path); |
1facf9fc | 5601 | + if (unlikely(err)) { |
523b37e3 AM |
5602 | + AuIOErr("failed remove copied-up tmp file %pd(%d)\n", |
5603 | + wh_dentry, err); | |
1facf9fc | 5604 | + err = -EIO; |
5605 | + } | |
5606 | + au_dtime_revert(&dt); | |
5527c038 | 5607 | + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry); |
1facf9fc | 5608 | + |
4f0767ce | 5609 | +out_wh: |
1facf9fc | 5610 | + dput(wh_dentry); |
4f0767ce | 5611 | +out: |
1facf9fc | 5612 | + dput(parent); |
5613 | + return err; | |
5614 | +} | |
5615 | + | |
5616 | +struct au_cpup_wh_args { | |
5617 | + int *errp; | |
c2b27bf2 | 5618 | + struct au_cp_generic *cpg; |
1facf9fc | 5619 | + struct file *file; |
5620 | +}; | |
5621 | + | |
5622 | +static void au_call_cpup_wh(void *args) | |
5623 | +{ | |
5624 | + struct au_cpup_wh_args *a = args; | |
86dc4139 | 5625 | + |
c2b27bf2 AM |
5626 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5627 | + *a->errp = au_cpup_wh(a->cpg, a->file); | |
5628 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5629 | +} |
5630 | + | |
c2b27bf2 | 5631 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5632 | +{ |
5633 | + int err, wkq_err; | |
c2b27bf2 | 5634 | + aufs_bindex_t bdst; |
c1595e42 | 5635 | + struct dentry *dentry, *parent, *h_orph, *h_parent; |
86dc4139 | 5636 | + struct inode *dir, *h_dir, *h_tmpdir; |
1facf9fc | 5637 | + struct au_wbr *wbr; |
c2b27bf2 | 5638 | + struct au_pin wh_pin, *pin_orig; |
1facf9fc | 5639 | + |
c2b27bf2 AM |
5640 | + dentry = cpg->dentry; |
5641 | + bdst = cpg->bdst; | |
1facf9fc | 5642 | + parent = dget_parent(dentry); |
5527c038 | 5643 | + dir = d_inode(parent); |
1facf9fc | 5644 | + h_orph = NULL; |
5645 | + h_parent = NULL; | |
5646 | + h_dir = au_igrab(au_h_iptr(dir, bdst)); | |
5647 | + h_tmpdir = h_dir; | |
c2b27bf2 | 5648 | + pin_orig = NULL; |
1facf9fc | 5649 | + if (!h_dir->i_nlink) { |
5650 | + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr; | |
5651 | + h_orph = wbr->wbr_orph; | |
5652 | + | |
5653 | + h_parent = dget(au_h_dptr(parent, bdst)); | |
1facf9fc | 5654 | + au_set_h_dptr(parent, bdst, dget(h_orph)); |
5527c038 | 5655 | + h_tmpdir = d_inode(h_orph); |
1facf9fc | 5656 | + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0); |
5657 | + | |
dece6358 | 5658 | + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3); |
4a4d8108 | 5659 | + /* todo: au_h_open_pre()? */ |
86dc4139 | 5660 | + |
c2b27bf2 | 5661 | + pin_orig = cpg->pin; |
86dc4139 | 5662 | + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT, |
c2b27bf2 AM |
5663 | + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED); |
5664 | + cpg->pin = &wh_pin; | |
1facf9fc | 5665 | + } |
5666 | + | |
53392da6 | 5667 | + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE) |
5527c038 | 5668 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 5669 | + err = au_cpup_wh(cpg, file); |
1facf9fc | 5670 | + else { |
5671 | + struct au_cpup_wh_args args = { | |
5672 | + .errp = &err, | |
c2b27bf2 AM |
5673 | + .cpg = cpg, |
5674 | + .file = file | |
1facf9fc | 5675 | + }; |
5676 | + wkq_err = au_wkq_wait(au_call_cpup_wh, &args); | |
5677 | + if (unlikely(wkq_err)) | |
5678 | + err = wkq_err; | |
5679 | + } | |
5680 | + | |
5681 | + if (h_orph) { | |
5682 | + mutex_unlock(&h_tmpdir->i_mutex); | |
4a4d8108 | 5683 | + /* todo: au_h_open_post()? */ |
1facf9fc | 5684 | + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0); |
1facf9fc | 5685 | + au_set_h_dptr(parent, bdst, h_parent); |
c2b27bf2 AM |
5686 | + AuDebugOn(!pin_orig); |
5687 | + cpg->pin = pin_orig; | |
1facf9fc | 5688 | + } |
5689 | + iput(h_dir); | |
5690 | + dput(parent); | |
5691 | + | |
5692 | + return err; | |
5693 | +} | |
5694 | + | |
5695 | +/* ---------------------------------------------------------------------- */ | |
5696 | + | |
5697 | +/* | |
5698 | + * generic routine for both of copy-up and copy-down. | |
5699 | + */ | |
5700 | +/* cf. revalidate function in file.c */ | |
5701 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
5702 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5703 | + struct au_pin *pin, |
1facf9fc | 5704 | + struct dentry *h_parent, void *arg), |
5705 | + void *arg) | |
5706 | +{ | |
5707 | + int err; | |
5708 | + struct au_pin pin; | |
5527c038 | 5709 | + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry; |
1facf9fc | 5710 | + |
5711 | + err = 0; | |
5712 | + parent = dget_parent(dentry); | |
5713 | + if (IS_ROOT(parent)) | |
5714 | + goto out; | |
5715 | + | |
5716 | + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2, | |
5717 | + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE); | |
5718 | + | |
5719 | + /* do not use au_dpage */ | |
5720 | + real_parent = parent; | |
5721 | + while (1) { | |
5722 | + dput(parent); | |
5723 | + parent = dget_parent(dentry); | |
5724 | + h_parent = au_h_dptr(parent, bdst); | |
5725 | + if (h_parent) | |
5726 | + goto out; /* success */ | |
5727 | + | |
5728 | + /* find top dir which is necessary to cpup */ | |
5729 | + do { | |
5730 | + d = parent; | |
5731 | + dput(parent); | |
5732 | + parent = dget_parent(d); | |
5733 | + di_read_lock_parent3(parent, !AuLock_IR); | |
5734 | + h_parent = au_h_dptr(parent, bdst); | |
5735 | + di_read_unlock(parent, !AuLock_IR); | |
5736 | + } while (!h_parent); | |
5737 | + | |
5738 | + if (d != real_parent) | |
5739 | + di_write_lock_child3(d); | |
5740 | + | |
5741 | + /* somebody else might create while we were sleeping */ | |
5527c038 JR |
5742 | + h_dentry = au_h_dptr(d, bdst); |
5743 | + if (!h_dentry || d_is_negative(h_dentry)) { | |
5744 | + if (h_dentry) | |
1facf9fc | 5745 | + au_update_dbstart(d); |
5746 | + | |
5747 | + au_pin_set_dentry(&pin, d); | |
5748 | + err = au_do_pin(&pin); | |
5749 | + if (!err) { | |
86dc4139 | 5750 | + err = cp(d, bdst, &pin, h_parent, arg); |
1facf9fc | 5751 | + au_unpin(&pin); |
5752 | + } | |
5753 | + } | |
5754 | + | |
5755 | + if (d != real_parent) | |
5756 | + di_write_unlock(d); | |
5757 | + if (unlikely(err)) | |
5758 | + break; | |
5759 | + } | |
5760 | + | |
4f0767ce | 5761 | +out: |
1facf9fc | 5762 | + dput(parent); |
5763 | + return err; | |
5764 | +} | |
5765 | + | |
5766 | +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5767 | + struct au_pin *pin, |
2000de60 | 5768 | + struct dentry *h_parent __maybe_unused, |
1facf9fc | 5769 | + void *arg __maybe_unused) |
5770 | +{ | |
c2b27bf2 AM |
5771 | + struct au_cp_generic cpg = { |
5772 | + .dentry = dentry, | |
5773 | + .bdst = bdst, | |
5774 | + .bsrc = -1, | |
5775 | + .len = 0, | |
5776 | + .pin = pin, | |
5777 | + .flags = AuCpup_DTIME | |
5778 | + }; | |
5779 | + return au_sio_cpup_simple(&cpg); | |
1facf9fc | 5780 | +} |
5781 | + | |
5782 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
5783 | +{ | |
5784 | + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL); | |
5785 | +} | |
5786 | + | |
5787 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
5788 | +{ | |
5789 | + int err; | |
5790 | + struct dentry *parent; | |
5791 | + struct inode *dir; | |
5792 | + | |
5793 | + parent = dget_parent(dentry); | |
5527c038 | 5794 | + dir = d_inode(parent); |
1facf9fc | 5795 | + err = 0; |
5796 | + if (au_h_iptr(dir, bdst)) | |
5797 | + goto out; | |
5798 | + | |
5799 | + di_read_unlock(parent, AuLock_IR); | |
5800 | + di_write_lock_parent(parent); | |
5801 | + /* someone else might change our inode while we were sleeping */ | |
5802 | + if (!au_h_iptr(dir, bdst)) | |
5803 | + err = au_cpup_dirs(dentry, bdst); | |
5804 | + di_downgrade_lock(parent, AuLock_IR); | |
5805 | + | |
4f0767ce | 5806 | +out: |
1facf9fc | 5807 | + dput(parent); |
5808 | + return err; | |
5809 | +} | |
7f207e10 AM |
5810 | diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h |
5811 | --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 5812 | +++ linux/fs/aufs/cpup.h 2015-09-24 10:47:58.248052907 +0200 |
523b37e3 | 5813 | @@ -0,0 +1,94 @@ |
1facf9fc | 5814 | +/* |
2000de60 | 5815 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 5816 | + * |
5817 | + * This program, aufs is free software; you can redistribute it and/or modify | |
5818 | + * it under the terms of the GNU General Public License as published by | |
5819 | + * the Free Software Foundation; either version 2 of the License, or | |
5820 | + * (at your option) any later version. | |
dece6358 AM |
5821 | + * |
5822 | + * This program is distributed in the hope that it will be useful, | |
5823 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5824 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
5825 | + * GNU General Public License for more details. | |
5826 | + * | |
5827 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 5828 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 5829 | + */ |
5830 | + | |
5831 | +/* | |
5832 | + * copy-up/down functions | |
5833 | + */ | |
5834 | + | |
5835 | +#ifndef __AUFS_CPUP_H__ | |
5836 | +#define __AUFS_CPUP_H__ | |
5837 | + | |
5838 | +#ifdef __KERNEL__ | |
5839 | + | |
dece6358 | 5840 | +#include <linux/path.h> |
1facf9fc | 5841 | + |
dece6358 AM |
5842 | +struct inode; |
5843 | +struct file; | |
86dc4139 | 5844 | +struct au_pin; |
dece6358 | 5845 | + |
86dc4139 | 5846 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags); |
1facf9fc | 5847 | +void au_cpup_attr_timesizes(struct inode *inode); |
5848 | +void au_cpup_attr_nlink(struct inode *inode, int force); | |
5849 | +void au_cpup_attr_changeable(struct inode *inode); | |
5850 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode); | |
5851 | +void au_cpup_attr_all(struct inode *inode, int force); | |
5852 | + | |
5853 | +/* ---------------------------------------------------------------------- */ | |
5854 | + | |
c2b27bf2 AM |
5855 | +struct au_cp_generic { |
5856 | + struct dentry *dentry; | |
5857 | + aufs_bindex_t bdst, bsrc; | |
5858 | + loff_t len; | |
5859 | + struct au_pin *pin; | |
5860 | + unsigned int flags; | |
5861 | +}; | |
5862 | + | |
1facf9fc | 5863 | +/* cpup flags */ |
392086de AM |
5864 | +#define AuCpup_DTIME 1 /* do dtime_store/revert */ |
5865 | +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino, | |
5866 | + for link(2) */ | |
5867 | +#define AuCpup_RENAME (1 << 2) /* rename after cpup */ | |
5868 | +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in | |
5869 | + cpup */ | |
5870 | +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the | |
5871 | + existing entry */ | |
5872 | +#define AuCpup_RWDST (1 << 5) /* force write target even if | |
5873 | + the branch is marked as RO */ | |
c2b27bf2 | 5874 | + |
1facf9fc | 5875 | +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name) |
7f207e10 AM |
5876 | +#define au_fset_cpup(flags, name) \ |
5877 | + do { (flags) |= AuCpup_##name; } while (0) | |
5878 | +#define au_fclr_cpup(flags, name) \ | |
5879 | + do { (flags) &= ~AuCpup_##name; } while (0) | |
1facf9fc | 5880 | + |
5881 | +int au_copy_file(struct file *dst, struct file *src, loff_t len); | |
c2b27bf2 AM |
5882 | +int au_sio_cpup_simple(struct au_cp_generic *cpg); |
5883 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg); | |
5884 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file); | |
1facf9fc | 5885 | + |
5886 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
5887 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5888 | + struct au_pin *pin, |
1facf9fc | 5889 | + struct dentry *h_parent, void *arg), |
5890 | + void *arg); | |
5891 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
5892 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
5893 | + | |
5894 | +/* ---------------------------------------------------------------------- */ | |
5895 | + | |
5896 | +/* keep timestamps when copyup */ | |
5897 | +struct au_dtime { | |
5898 | + struct dentry *dt_dentry; | |
5899 | + struct path dt_h_path; | |
5900 | + struct timespec dt_atime, dt_mtime; | |
5901 | +}; | |
5902 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
5903 | + struct path *h_path); | |
5904 | +void au_dtime_revert(struct au_dtime *dt); | |
5905 | + | |
5906 | +#endif /* __KERNEL__ */ | |
5907 | +#endif /* __AUFS_CPUP_H__ */ | |
7f207e10 AM |
5908 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c |
5909 | --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 5910 | +++ linux/fs/aufs/dbgaufs.c 2015-09-24 10:47:58.248052907 +0200 |
523b37e3 | 5911 | @@ -0,0 +1,432 @@ |
1facf9fc | 5912 | +/* |
2000de60 | 5913 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 5914 | + * |
5915 | + * This program, aufs is free software; you can redistribute it and/or modify | |
5916 | + * it under the terms of the GNU General Public License as published by | |
5917 | + * the Free Software Foundation; either version 2 of the License, or | |
5918 | + * (at your option) any later version. | |
dece6358 AM |
5919 | + * |
5920 | + * This program is distributed in the hope that it will be useful, | |
5921 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5922 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
5923 | + * GNU General Public License for more details. | |
5924 | + * | |
5925 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 5926 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 5927 | + */ |
5928 | + | |
5929 | +/* | |
5930 | + * debugfs interface | |
5931 | + */ | |
5932 | + | |
5933 | +#include <linux/debugfs.h> | |
5934 | +#include "aufs.h" | |
5935 | + | |
5936 | +#ifndef CONFIG_SYSFS | |
5937 | +#error DEBUG_FS depends upon SYSFS | |
5938 | +#endif | |
5939 | + | |
5940 | +static struct dentry *dbgaufs; | |
5941 | +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH; | |
5942 | + | |
5943 | +/* 20 is max digits length of ulong 64 */ | |
5944 | +struct dbgaufs_arg { | |
5945 | + int n; | |
5946 | + char a[20 * 4]; | |
5947 | +}; | |
5948 | + | |
5949 | +/* | |
5950 | + * common function for all XINO files | |
5951 | + */ | |
5952 | +static int dbgaufs_xi_release(struct inode *inode __maybe_unused, | |
5953 | + struct file *file) | |
5954 | +{ | |
5955 | + kfree(file->private_data); | |
5956 | + return 0; | |
5957 | +} | |
5958 | + | |
5959 | +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt) | |
5960 | +{ | |
5961 | + int err; | |
5962 | + struct kstat st; | |
5963 | + struct dbgaufs_arg *p; | |
5964 | + | |
5965 | + err = -ENOMEM; | |
5966 | + p = kmalloc(sizeof(*p), GFP_NOFS); | |
5967 | + if (unlikely(!p)) | |
5968 | + goto out; | |
5969 | + | |
5970 | + err = 0; | |
5971 | + p->n = 0; | |
5972 | + file->private_data = p; | |
5973 | + if (!xf) | |
5974 | + goto out; | |
5975 | + | |
c06a8ce3 | 5976 | + err = vfs_getattr(&xf->f_path, &st); |
1facf9fc | 5977 | + if (!err) { |
5978 | + if (do_fcnt) | |
5979 | + p->n = snprintf | |
5980 | + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n", | |
5981 | + (long)file_count(xf), st.blocks, st.blksize, | |
5982 | + (long long)st.size); | |
5983 | + else | |
5984 | + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n", | |
5985 | + st.blocks, st.blksize, | |
5986 | + (long long)st.size); | |
5987 | + AuDebugOn(p->n >= sizeof(p->a)); | |
5988 | + } else { | |
5989 | + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err); | |
5990 | + err = 0; | |
5991 | + } | |
5992 | + | |
4f0767ce | 5993 | +out: |
1facf9fc | 5994 | + return err; |
5995 | + | |
5996 | +} | |
5997 | + | |
5998 | +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf, | |
5999 | + size_t count, loff_t *ppos) | |
6000 | +{ | |
6001 | + struct dbgaufs_arg *p; | |
6002 | + | |
6003 | + p = file->private_data; | |
6004 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6005 | +} | |
6006 | + | |
6007 | +/* ---------------------------------------------------------------------- */ | |
6008 | + | |
86dc4139 AM |
6009 | +struct dbgaufs_plink_arg { |
6010 | + int n; | |
6011 | + char a[]; | |
6012 | +}; | |
6013 | + | |
6014 | +static int dbgaufs_plink_release(struct inode *inode __maybe_unused, | |
6015 | + struct file *file) | |
6016 | +{ | |
6017 | + free_page((unsigned long)file->private_data); | |
6018 | + return 0; | |
6019 | +} | |
6020 | + | |
6021 | +static int dbgaufs_plink_open(struct inode *inode, struct file *file) | |
6022 | +{ | |
6023 | + int err, i, limit; | |
6024 | + unsigned long n, sum; | |
6025 | + struct dbgaufs_plink_arg *p; | |
6026 | + struct au_sbinfo *sbinfo; | |
6027 | + struct super_block *sb; | |
6028 | + struct au_sphlhead *sphl; | |
6029 | + | |
6030 | + err = -ENOMEM; | |
6031 | + p = (void *)get_zeroed_page(GFP_NOFS); | |
6032 | + if (unlikely(!p)) | |
6033 | + goto out; | |
6034 | + | |
6035 | + err = -EFBIG; | |
6036 | + sbinfo = inode->i_private; | |
6037 | + sb = sbinfo->si_sb; | |
6038 | + si_noflush_read_lock(sb); | |
6039 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
6040 | + limit = PAGE_SIZE - sizeof(p->n); | |
6041 | + | |
6042 | + /* the number of buckets */ | |
6043 | + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH); | |
6044 | + p->n += n; | |
6045 | + limit -= n; | |
6046 | + | |
6047 | + sum = 0; | |
6048 | + for (i = 0, sphl = sbinfo->si_plink; | |
6049 | + i < AuPlink_NHASH; | |
6050 | + i++, sphl++) { | |
6051 | + n = au_sphl_count(sphl); | |
6052 | + sum += n; | |
6053 | + | |
6054 | + n = snprintf(p->a + p->n, limit, "%lu ", n); | |
6055 | + p->n += n; | |
6056 | + limit -= n; | |
6057 | + if (unlikely(limit <= 0)) | |
6058 | + goto out_free; | |
6059 | + } | |
6060 | + p->a[p->n - 1] = '\n'; | |
6061 | + | |
6062 | + /* the sum of plinks */ | |
6063 | + n = snprintf(p->a + p->n, limit, "%lu\n", sum); | |
6064 | + p->n += n; | |
6065 | + limit -= n; | |
6066 | + if (unlikely(limit <= 0)) | |
6067 | + goto out_free; | |
6068 | + } else { | |
6069 | +#define str "1\n0\n0\n" | |
6070 | + p->n = sizeof(str) - 1; | |
6071 | + strcpy(p->a, str); | |
6072 | +#undef str | |
6073 | + } | |
6074 | + si_read_unlock(sb); | |
6075 | + | |
6076 | + err = 0; | |
6077 | + file->private_data = p; | |
6078 | + goto out; /* success */ | |
6079 | + | |
6080 | +out_free: | |
6081 | + free_page((unsigned long)p); | |
6082 | +out: | |
6083 | + return err; | |
6084 | +} | |
6085 | + | |
6086 | +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf, | |
6087 | + size_t count, loff_t *ppos) | |
6088 | +{ | |
6089 | + struct dbgaufs_plink_arg *p; | |
6090 | + | |
6091 | + p = file->private_data; | |
6092 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6093 | +} | |
6094 | + | |
6095 | +static const struct file_operations dbgaufs_plink_fop = { | |
6096 | + .owner = THIS_MODULE, | |
6097 | + .open = dbgaufs_plink_open, | |
6098 | + .release = dbgaufs_plink_release, | |
6099 | + .read = dbgaufs_plink_read | |
6100 | +}; | |
6101 | + | |
6102 | +/* ---------------------------------------------------------------------- */ | |
6103 | + | |
1facf9fc | 6104 | +static int dbgaufs_xib_open(struct inode *inode, struct file *file) |
6105 | +{ | |
6106 | + int err; | |
6107 | + struct au_sbinfo *sbinfo; | |
6108 | + struct super_block *sb; | |
6109 | + | |
6110 | + sbinfo = inode->i_private; | |
6111 | + sb = sbinfo->si_sb; | |
6112 | + si_noflush_read_lock(sb); | |
6113 | + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0); | |
6114 | + si_read_unlock(sb); | |
6115 | + return err; | |
6116 | +} | |
6117 | + | |
6118 | +static const struct file_operations dbgaufs_xib_fop = { | |
4a4d8108 | 6119 | + .owner = THIS_MODULE, |
1facf9fc | 6120 | + .open = dbgaufs_xib_open, |
6121 | + .release = dbgaufs_xi_release, | |
6122 | + .read = dbgaufs_xi_read | |
6123 | +}; | |
6124 | + | |
6125 | +/* ---------------------------------------------------------------------- */ | |
6126 | + | |
6127 | +#define DbgaufsXi_PREFIX "xi" | |
6128 | + | |
6129 | +static int dbgaufs_xino_open(struct inode *inode, struct file *file) | |
6130 | +{ | |
6131 | + int err; | |
6132 | + long l; | |
6133 | + struct au_sbinfo *sbinfo; | |
6134 | + struct super_block *sb; | |
6135 | + struct file *xf; | |
6136 | + struct qstr *name; | |
6137 | + | |
6138 | + err = -ENOENT; | |
6139 | + xf = NULL; | |
2000de60 | 6140 | + name = &file->f_path.dentry->d_name; |
1facf9fc | 6141 | + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX) |
6142 | + || memcmp(name->name, DbgaufsXi_PREFIX, | |
6143 | + sizeof(DbgaufsXi_PREFIX) - 1))) | |
6144 | + goto out; | |
9dbd164d | 6145 | + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l); |
1facf9fc | 6146 | + if (unlikely(err)) |
6147 | + goto out; | |
6148 | + | |
6149 | + sbinfo = inode->i_private; | |
6150 | + sb = sbinfo->si_sb; | |
6151 | + si_noflush_read_lock(sb); | |
6152 | + if (l <= au_sbend(sb)) { | |
6153 | + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file; | |
6154 | + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1); | |
6155 | + } else | |
6156 | + err = -ENOENT; | |
6157 | + si_read_unlock(sb); | |
6158 | + | |
4f0767ce | 6159 | +out: |
1facf9fc | 6160 | + return err; |
6161 | +} | |
6162 | + | |
6163 | +static const struct file_operations dbgaufs_xino_fop = { | |
4a4d8108 | 6164 | + .owner = THIS_MODULE, |
1facf9fc | 6165 | + .open = dbgaufs_xino_open, |
6166 | + .release = dbgaufs_xi_release, | |
6167 | + .read = dbgaufs_xi_read | |
6168 | +}; | |
6169 | + | |
6170 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
6171 | +{ | |
6172 | + aufs_bindex_t bend; | |
6173 | + struct au_branch *br; | |
6174 | + struct au_xino_file *xi; | |
6175 | + | |
6176 | + if (!au_sbi(sb)->si_dbgaufs) | |
6177 | + return; | |
6178 | + | |
6179 | + bend = au_sbend(sb); | |
6180 | + for (; bindex <= bend; bindex++) { | |
6181 | + br = au_sbr(sb, bindex); | |
6182 | + xi = &br->br_xino; | |
c06a8ce3 AM |
6183 | + debugfs_remove(xi->xi_dbgaufs); |
6184 | + xi->xi_dbgaufs = NULL; | |
1facf9fc | 6185 | + } |
6186 | +} | |
6187 | + | |
6188 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
6189 | +{ | |
6190 | + struct au_sbinfo *sbinfo; | |
6191 | + struct dentry *parent; | |
6192 | + struct au_branch *br; | |
6193 | + struct au_xino_file *xi; | |
6194 | + aufs_bindex_t bend; | |
6195 | + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */ | |
6196 | + | |
6197 | + sbinfo = au_sbi(sb); | |
6198 | + parent = sbinfo->si_dbgaufs; | |
6199 | + if (!parent) | |
6200 | + return; | |
6201 | + | |
6202 | + bend = au_sbend(sb); | |
6203 | + for (; bindex <= bend; bindex++) { | |
6204 | + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex); | |
6205 | + br = au_sbr(sb, bindex); | |
6206 | + xi = &br->br_xino; | |
6207 | + AuDebugOn(xi->xi_dbgaufs); | |
6208 | + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent, | |
6209 | + sbinfo, &dbgaufs_xino_fop); | |
6210 | + /* ignore an error */ | |
6211 | + if (unlikely(!xi->xi_dbgaufs)) | |
6212 | + AuWarn1("failed %s under debugfs\n", name); | |
6213 | + } | |
6214 | +} | |
6215 | + | |
6216 | +/* ---------------------------------------------------------------------- */ | |
6217 | + | |
6218 | +#ifdef CONFIG_AUFS_EXPORT | |
6219 | +static int dbgaufs_xigen_open(struct inode *inode, struct file *file) | |
6220 | +{ | |
6221 | + int err; | |
6222 | + struct au_sbinfo *sbinfo; | |
6223 | + struct super_block *sb; | |
6224 | + | |
6225 | + sbinfo = inode->i_private; | |
6226 | + sb = sbinfo->si_sb; | |
6227 | + si_noflush_read_lock(sb); | |
6228 | + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0); | |
6229 | + si_read_unlock(sb); | |
6230 | + return err; | |
6231 | +} | |
6232 | + | |
6233 | +static const struct file_operations dbgaufs_xigen_fop = { | |
4a4d8108 | 6234 | + .owner = THIS_MODULE, |
1facf9fc | 6235 | + .open = dbgaufs_xigen_open, |
6236 | + .release = dbgaufs_xi_release, | |
6237 | + .read = dbgaufs_xi_read | |
6238 | +}; | |
6239 | + | |
6240 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6241 | +{ | |
6242 | + int err; | |
6243 | + | |
dece6358 | 6244 | + /* |
c1595e42 | 6245 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6246 | + * so the tiny check for si_rwsem is unnecessary. |
6247 | + */ | |
6248 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6249 | + | |
1facf9fc | 6250 | + err = -EIO; |
6251 | + sbinfo->si_dbgaufs_xigen = debugfs_create_file | |
6252 | + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6253 | + &dbgaufs_xigen_fop); | |
6254 | + if (sbinfo->si_dbgaufs_xigen) | |
6255 | + err = 0; | |
6256 | + | |
6257 | + return err; | |
6258 | +} | |
6259 | +#else | |
6260 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6261 | +{ | |
6262 | + return 0; | |
6263 | +} | |
6264 | +#endif /* CONFIG_AUFS_EXPORT */ | |
6265 | + | |
6266 | +/* ---------------------------------------------------------------------- */ | |
6267 | + | |
6268 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo) | |
6269 | +{ | |
dece6358 | 6270 | + /* |
7e9cd9fe | 6271 | + * This function is a dynamic '__fin' function actually, |
dece6358 AM |
6272 | + * so the tiny check for si_rwsem is unnecessary. |
6273 | + */ | |
6274 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6275 | + | |
1facf9fc | 6276 | + debugfs_remove_recursive(sbinfo->si_dbgaufs); |
6277 | + sbinfo->si_dbgaufs = NULL; | |
6278 | + kobject_put(&sbinfo->si_kobj); | |
6279 | +} | |
6280 | + | |
6281 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo) | |
6282 | +{ | |
6283 | + int err; | |
6284 | + char name[SysaufsSiNameLen]; | |
6285 | + | |
dece6358 | 6286 | + /* |
c1595e42 | 6287 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6288 | + * so the tiny check for si_rwsem is unnecessary. |
6289 | + */ | |
6290 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6291 | + | |
1facf9fc | 6292 | + err = -ENOENT; |
6293 | + if (!dbgaufs) { | |
6294 | + AuErr1("/debug/aufs is uninitialized\n"); | |
6295 | + goto out; | |
6296 | + } | |
6297 | + | |
6298 | + err = -EIO; | |
6299 | + sysaufs_name(sbinfo, name); | |
6300 | + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs); | |
6301 | + if (unlikely(!sbinfo->si_dbgaufs)) | |
6302 | + goto out; | |
6303 | + kobject_get(&sbinfo->si_kobj); | |
6304 | + | |
6305 | + sbinfo->si_dbgaufs_xib = debugfs_create_file | |
6306 | + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6307 | + &dbgaufs_xib_fop); | |
6308 | + if (unlikely(!sbinfo->si_dbgaufs_xib)) | |
6309 | + goto out_dir; | |
6310 | + | |
86dc4139 AM |
6311 | + sbinfo->si_dbgaufs_plink = debugfs_create_file |
6312 | + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6313 | + &dbgaufs_plink_fop); | |
6314 | + if (unlikely(!sbinfo->si_dbgaufs_plink)) | |
6315 | + goto out_dir; | |
6316 | + | |
1facf9fc | 6317 | + err = dbgaufs_xigen_init(sbinfo); |
6318 | + if (!err) | |
6319 | + goto out; /* success */ | |
6320 | + | |
4f0767ce | 6321 | +out_dir: |
1facf9fc | 6322 | + dbgaufs_si_fin(sbinfo); |
4f0767ce | 6323 | +out: |
1facf9fc | 6324 | + return err; |
6325 | +} | |
6326 | + | |
6327 | +/* ---------------------------------------------------------------------- */ | |
6328 | + | |
6329 | +void dbgaufs_fin(void) | |
6330 | +{ | |
6331 | + debugfs_remove(dbgaufs); | |
6332 | +} | |
6333 | + | |
6334 | +int __init dbgaufs_init(void) | |
6335 | +{ | |
6336 | + int err; | |
6337 | + | |
6338 | + err = -EIO; | |
6339 | + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL); | |
6340 | + if (dbgaufs) | |
6341 | + err = 0; | |
6342 | + return err; | |
6343 | +} | |
7f207e10 AM |
6344 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h |
6345 | --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 6346 | +++ linux/fs/aufs/dbgaufs.h 2015-09-24 10:47:58.248052907 +0200 |
523b37e3 | 6347 | @@ -0,0 +1,48 @@ |
1facf9fc | 6348 | +/* |
2000de60 | 6349 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6350 | + * |
6351 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6352 | + * it under the terms of the GNU General Public License as published by | |
6353 | + * the Free Software Foundation; either version 2 of the License, or | |
6354 | + * (at your option) any later version. | |
dece6358 AM |
6355 | + * |
6356 | + * This program is distributed in the hope that it will be useful, | |
6357 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6358 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6359 | + * GNU General Public License for more details. | |
6360 | + * | |
6361 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6362 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6363 | + */ |
6364 | + | |
6365 | +/* | |
6366 | + * debugfs interface | |
6367 | + */ | |
6368 | + | |
6369 | +#ifndef __DBGAUFS_H__ | |
6370 | +#define __DBGAUFS_H__ | |
6371 | + | |
6372 | +#ifdef __KERNEL__ | |
6373 | + | |
dece6358 | 6374 | +struct super_block; |
1facf9fc | 6375 | +struct au_sbinfo; |
dece6358 | 6376 | + |
1facf9fc | 6377 | +#ifdef CONFIG_DEBUG_FS |
6378 | +/* dbgaufs.c */ | |
6379 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
6380 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
6381 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo); | |
6382 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo); | |
6383 | +void dbgaufs_fin(void); | |
6384 | +int __init dbgaufs_init(void); | |
1facf9fc | 6385 | +#else |
4a4d8108 AM |
6386 | +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) |
6387 | +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
6388 | +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo) | |
6389 | +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo) | |
6390 | +AuStubVoid(dbgaufs_fin, void) | |
6391 | +AuStubInt0(__init dbgaufs_init, void) | |
1facf9fc | 6392 | +#endif /* CONFIG_DEBUG_FS */ |
6393 | + | |
6394 | +#endif /* __KERNEL__ */ | |
6395 | +#endif /* __DBGAUFS_H__ */ | |
7f207e10 AM |
6396 | diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c |
6397 | --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 6398 | +++ linux/fs/aufs/dcsub.c 2015-09-24 10:47:58.248052907 +0200 |
c1595e42 | 6399 | @@ -0,0 +1,224 @@ |
1facf9fc | 6400 | +/* |
2000de60 | 6401 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6402 | + * |
6403 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6404 | + * it under the terms of the GNU General Public License as published by | |
6405 | + * the Free Software Foundation; either version 2 of the License, or | |
6406 | + * (at your option) any later version. | |
dece6358 AM |
6407 | + * |
6408 | + * This program is distributed in the hope that it will be useful, | |
6409 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6410 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6411 | + * GNU General Public License for more details. | |
6412 | + * | |
6413 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6414 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6415 | + */ |
6416 | + | |
6417 | +/* | |
6418 | + * sub-routines for dentry cache | |
6419 | + */ | |
6420 | + | |
6421 | +#include "aufs.h" | |
6422 | + | |
6423 | +static void au_dpage_free(struct au_dpage *dpage) | |
6424 | +{ | |
6425 | + int i; | |
6426 | + struct dentry **p; | |
6427 | + | |
6428 | + p = dpage->dentries; | |
6429 | + for (i = 0; i < dpage->ndentry; i++) | |
6430 | + dput(*p++); | |
6431 | + free_page((unsigned long)dpage->dentries); | |
6432 | +} | |
6433 | + | |
6434 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp) | |
6435 | +{ | |
6436 | + int err; | |
6437 | + void *p; | |
6438 | + | |
6439 | + err = -ENOMEM; | |
6440 | + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp); | |
6441 | + if (unlikely(!dpages->dpages)) | |
6442 | + goto out; | |
6443 | + | |
6444 | + p = (void *)__get_free_page(gfp); | |
6445 | + if (unlikely(!p)) | |
6446 | + goto out_dpages; | |
6447 | + | |
6448 | + dpages->dpages[0].ndentry = 0; | |
6449 | + dpages->dpages[0].dentries = p; | |
6450 | + dpages->ndpage = 1; | |
6451 | + return 0; /* success */ | |
6452 | + | |
4f0767ce | 6453 | +out_dpages: |
1facf9fc | 6454 | + kfree(dpages->dpages); |
4f0767ce | 6455 | +out: |
1facf9fc | 6456 | + return err; |
6457 | +} | |
6458 | + | |
6459 | +void au_dpages_free(struct au_dcsub_pages *dpages) | |
6460 | +{ | |
6461 | + int i; | |
6462 | + struct au_dpage *p; | |
6463 | + | |
6464 | + p = dpages->dpages; | |
6465 | + for (i = 0; i < dpages->ndpage; i++) | |
6466 | + au_dpage_free(p++); | |
6467 | + kfree(dpages->dpages); | |
6468 | +} | |
6469 | + | |
6470 | +static int au_dpages_append(struct au_dcsub_pages *dpages, | |
6471 | + struct dentry *dentry, gfp_t gfp) | |
6472 | +{ | |
6473 | + int err, sz; | |
6474 | + struct au_dpage *dpage; | |
6475 | + void *p; | |
6476 | + | |
6477 | + dpage = dpages->dpages + dpages->ndpage - 1; | |
6478 | + sz = PAGE_SIZE / sizeof(dentry); | |
6479 | + if (unlikely(dpage->ndentry >= sz)) { | |
6480 | + AuLabel(new dpage); | |
6481 | + err = -ENOMEM; | |
6482 | + sz = dpages->ndpage * sizeof(*dpages->dpages); | |
6483 | + p = au_kzrealloc(dpages->dpages, sz, | |
6484 | + sz + sizeof(*dpages->dpages), gfp); | |
6485 | + if (unlikely(!p)) | |
6486 | + goto out; | |
6487 | + | |
6488 | + dpages->dpages = p; | |
6489 | + dpage = dpages->dpages + dpages->ndpage; | |
6490 | + p = (void *)__get_free_page(gfp); | |
6491 | + if (unlikely(!p)) | |
6492 | + goto out; | |
6493 | + | |
6494 | + dpage->ndentry = 0; | |
6495 | + dpage->dentries = p; | |
6496 | + dpages->ndpage++; | |
6497 | + } | |
6498 | + | |
c1595e42 | 6499 | + AuDebugOn(au_dcount(dentry) <= 0); |
027c5e7a | 6500 | + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry); |
1facf9fc | 6501 | + return 0; /* success */ |
6502 | + | |
4f0767ce | 6503 | +out: |
1facf9fc | 6504 | + return err; |
6505 | +} | |
6506 | + | |
c1595e42 JR |
6507 | +/* todo: BAD approach */ |
6508 | +/* copied from linux/fs/dcache.c */ | |
6509 | +enum d_walk_ret { | |
6510 | + D_WALK_CONTINUE, | |
6511 | + D_WALK_QUIT, | |
6512 | + D_WALK_NORETRY, | |
6513 | + D_WALK_SKIP, | |
6514 | +}; | |
6515 | + | |
6516 | +extern void d_walk(struct dentry *parent, void *data, | |
6517 | + enum d_walk_ret (*enter)(void *, struct dentry *), | |
6518 | + void (*finish)(void *)); | |
6519 | + | |
6520 | +struct ac_dpages_arg { | |
1facf9fc | 6521 | + int err; |
c1595e42 JR |
6522 | + struct au_dcsub_pages *dpages; |
6523 | + struct super_block *sb; | |
6524 | + au_dpages_test test; | |
6525 | + void *arg; | |
6526 | +}; | |
1facf9fc | 6527 | + |
c1595e42 JR |
6528 | +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry) |
6529 | +{ | |
6530 | + enum d_walk_ret ret; | |
6531 | + struct ac_dpages_arg *arg = _arg; | |
1facf9fc | 6532 | + |
c1595e42 JR |
6533 | + ret = D_WALK_CONTINUE; |
6534 | + if (dentry->d_sb == arg->sb | |
6535 | + && !IS_ROOT(dentry) | |
6536 | + && au_dcount(dentry) > 0 | |
6537 | + && au_di(dentry) | |
6538 | + && (!arg->test || arg->test(dentry, arg->arg))) { | |
6539 | + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC); | |
6540 | + if (unlikely(arg->err)) | |
6541 | + ret = D_WALK_QUIT; | |
1facf9fc | 6542 | + } |
6543 | + | |
c1595e42 JR |
6544 | + return ret; |
6545 | +} | |
027c5e7a | 6546 | + |
c1595e42 JR |
6547 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, |
6548 | + au_dpages_test test, void *arg) | |
6549 | +{ | |
6550 | + struct ac_dpages_arg args = { | |
6551 | + .err = 0, | |
6552 | + .dpages = dpages, | |
6553 | + .sb = root->d_sb, | |
6554 | + .test = test, | |
6555 | + .arg = arg | |
6556 | + }; | |
027c5e7a | 6557 | + |
c1595e42 JR |
6558 | + d_walk(root, &args, au_call_dpages_append, NULL); |
6559 | + | |
6560 | + return args.err; | |
1facf9fc | 6561 | +} |
6562 | + | |
6563 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6564 | + int do_include, au_dpages_test test, void *arg) | |
6565 | +{ | |
6566 | + int err; | |
6567 | + | |
6568 | + err = 0; | |
027c5e7a AM |
6569 | + write_seqlock(&rename_lock); |
6570 | + spin_lock(&dentry->d_lock); | |
6571 | + if (do_include | |
c1595e42 | 6572 | + && au_dcount(dentry) > 0 |
027c5e7a | 6573 | + && (!test || test(dentry, arg))) |
1facf9fc | 6574 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6575 | + spin_unlock(&dentry->d_lock); |
6576 | + if (unlikely(err)) | |
6577 | + goto out; | |
6578 | + | |
6579 | + /* | |
523b37e3 | 6580 | + * RCU for vfsmount is unnecessary since this is a traverse in a single |
027c5e7a AM |
6581 | + * mount |
6582 | + */ | |
1facf9fc | 6583 | + while (!IS_ROOT(dentry)) { |
027c5e7a AM |
6584 | + dentry = dentry->d_parent; /* rename_lock is locked */ |
6585 | + spin_lock(&dentry->d_lock); | |
c1595e42 | 6586 | + if (au_dcount(dentry) > 0 |
027c5e7a | 6587 | + && (!test || test(dentry, arg))) |
1facf9fc | 6588 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6589 | + spin_unlock(&dentry->d_lock); |
6590 | + if (unlikely(err)) | |
6591 | + break; | |
1facf9fc | 6592 | + } |
6593 | + | |
4f0767ce | 6594 | +out: |
027c5e7a | 6595 | + write_sequnlock(&rename_lock); |
1facf9fc | 6596 | + return err; |
6597 | +} | |
6598 | + | |
027c5e7a AM |
6599 | +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg) |
6600 | +{ | |
6601 | + return au_di(dentry) && dentry->d_sb == arg; | |
6602 | +} | |
6603 | + | |
6604 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, | |
6605 | + struct dentry *dentry, int do_include) | |
6606 | +{ | |
6607 | + return au_dcsub_pages_rev(dpages, dentry, do_include, | |
6608 | + au_dcsub_dpages_aufs, dentry->d_sb); | |
6609 | +} | |
6610 | + | |
4a4d8108 | 6611 | +int au_test_subdir(struct dentry *d1, struct dentry *d2) |
1facf9fc | 6612 | +{ |
4a4d8108 AM |
6613 | + struct path path[2] = { |
6614 | + { | |
6615 | + .dentry = d1 | |
6616 | + }, | |
6617 | + { | |
6618 | + .dentry = d2 | |
6619 | + } | |
6620 | + }; | |
1facf9fc | 6621 | + |
4a4d8108 | 6622 | + return path_is_under(path + 0, path + 1); |
1facf9fc | 6623 | +} |
7f207e10 AM |
6624 | diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h |
6625 | --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 6626 | +++ linux/fs/aufs/dcsub.h 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 6627 | @@ -0,0 +1,136 @@ |
1facf9fc | 6628 | +/* |
2000de60 | 6629 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6630 | + * |
6631 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6632 | + * it under the terms of the GNU General Public License as published by | |
6633 | + * the Free Software Foundation; either version 2 of the License, or | |
6634 | + * (at your option) any later version. | |
dece6358 AM |
6635 | + * |
6636 | + * This program is distributed in the hope that it will be useful, | |
6637 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6638 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6639 | + * GNU General Public License for more details. | |
6640 | + * | |
6641 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6642 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6643 | + */ |
6644 | + | |
6645 | +/* | |
6646 | + * sub-routines for dentry cache | |
6647 | + */ | |
6648 | + | |
6649 | +#ifndef __AUFS_DCSUB_H__ | |
6650 | +#define __AUFS_DCSUB_H__ | |
6651 | + | |
6652 | +#ifdef __KERNEL__ | |
6653 | + | |
7f207e10 | 6654 | +#include <linux/dcache.h> |
027c5e7a | 6655 | +#include <linux/fs.h> |
dece6358 | 6656 | + |
1facf9fc | 6657 | +struct au_dpage { |
6658 | + int ndentry; | |
6659 | + struct dentry **dentries; | |
6660 | +}; | |
6661 | + | |
6662 | +struct au_dcsub_pages { | |
6663 | + int ndpage; | |
6664 | + struct au_dpage *dpages; | |
6665 | +}; | |
6666 | + | |
6667 | +/* ---------------------------------------------------------------------- */ | |
6668 | + | |
7f207e10 | 6669 | +/* dcsub.c */ |
1facf9fc | 6670 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp); |
6671 | +void au_dpages_free(struct au_dcsub_pages *dpages); | |
6672 | +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg); | |
6673 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, | |
6674 | + au_dpages_test test, void *arg); | |
6675 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6676 | + int do_include, au_dpages_test test, void *arg); | |
027c5e7a AM |
6677 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, |
6678 | + struct dentry *dentry, int do_include); | |
4a4d8108 | 6679 | +int au_test_subdir(struct dentry *d1, struct dentry *d2); |
1facf9fc | 6680 | + |
7f207e10 AM |
6681 | +/* ---------------------------------------------------------------------- */ |
6682 | + | |
523b37e3 AM |
6683 | +/* |
6684 | + * todo: in linux-3.13, several similar (but faster) helpers are added to | |
6685 | + * include/linux/dcache.h. Try them (in the future). | |
6686 | + */ | |
6687 | + | |
027c5e7a AM |
6688 | +static inline int au_d_hashed_positive(struct dentry *d) |
6689 | +{ | |
6690 | + int err; | |
5527c038 | 6691 | + struct inode *inode = d_inode(d); |
076b876e | 6692 | + |
027c5e7a | 6693 | + err = 0; |
5527c038 JR |
6694 | + if (unlikely(d_unhashed(d) |
6695 | + || d_is_negative(d) | |
6696 | + || !inode->i_nlink)) | |
027c5e7a AM |
6697 | + err = -ENOENT; |
6698 | + return err; | |
6699 | +} | |
6700 | + | |
38d290e6 JR |
6701 | +static inline int au_d_linkable(struct dentry *d) |
6702 | +{ | |
6703 | + int err; | |
5527c038 | 6704 | + struct inode *inode = d_inode(d); |
076b876e | 6705 | + |
38d290e6 JR |
6706 | + err = au_d_hashed_positive(d); |
6707 | + if (err | |
5527c038 | 6708 | + && d_is_positive(d) |
38d290e6 JR |
6709 | + && (inode->i_state & I_LINKABLE)) |
6710 | + err = 0; | |
6711 | + return err; | |
6712 | +} | |
6713 | + | |
027c5e7a AM |
6714 | +static inline int au_d_alive(struct dentry *d) |
6715 | +{ | |
6716 | + int err; | |
6717 | + struct inode *inode; | |
076b876e | 6718 | + |
027c5e7a AM |
6719 | + err = 0; |
6720 | + if (!IS_ROOT(d)) | |
6721 | + err = au_d_hashed_positive(d); | |
6722 | + else { | |
5527c038 JR |
6723 | + inode = d_inode(d); |
6724 | + if (unlikely(d_unlinked(d) | |
6725 | + || d_is_negative(d) | |
6726 | + || !inode->i_nlink)) | |
027c5e7a AM |
6727 | + err = -ENOENT; |
6728 | + } | |
6729 | + return err; | |
6730 | +} | |
6731 | + | |
6732 | +static inline int au_alive_dir(struct dentry *d) | |
7f207e10 | 6733 | +{ |
027c5e7a | 6734 | + int err; |
076b876e | 6735 | + |
027c5e7a | 6736 | + err = au_d_alive(d); |
5527c038 | 6737 | + if (unlikely(err || IS_DEADDIR(d_inode(d)))) |
027c5e7a AM |
6738 | + err = -ENOENT; |
6739 | + return err; | |
7f207e10 AM |
6740 | +} |
6741 | + | |
38d290e6 JR |
6742 | +static inline int au_qstreq(struct qstr *a, struct qstr *b) |
6743 | +{ | |
6744 | + return a->len == b->len | |
6745 | + && !memcmp(a->name, b->name, a->len); | |
6746 | +} | |
6747 | + | |
7e9cd9fe AM |
6748 | +/* |
6749 | + * by the commit | |
6750 | + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without | |
6751 | + * taking d_lock | |
6752 | + * the type of d_lockref.count became int, but the inlined function d_count() | |
6753 | + * still returns unsigned int. | |
6754 | + * I don't know why. Maybe it is for every d_count() users? | |
6755 | + * Anyway au_dcount() lives on. | |
6756 | + */ | |
c1595e42 JR |
6757 | +static inline int au_dcount(struct dentry *d) |
6758 | +{ | |
6759 | + return (int)d_count(d); | |
6760 | +} | |
6761 | + | |
1facf9fc | 6762 | +#endif /* __KERNEL__ */ |
6763 | +#endif /* __AUFS_DCSUB_H__ */ | |
7f207e10 AM |
6764 | diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c |
6765 | --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 6766 | +++ linux/fs/aufs/debug.c 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 6767 | @@ -0,0 +1,440 @@ |
1facf9fc | 6768 | +/* |
2000de60 | 6769 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 6770 | + * |
6771 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6772 | + * it under the terms of the GNU General Public License as published by | |
6773 | + * the Free Software Foundation; either version 2 of the License, or | |
6774 | + * (at your option) any later version. | |
dece6358 AM |
6775 | + * |
6776 | + * This program is distributed in the hope that it will be useful, | |
6777 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6778 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6779 | + * GNU General Public License for more details. | |
6780 | + * | |
6781 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6782 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6783 | + */ |
6784 | + | |
6785 | +/* | |
6786 | + * debug print functions | |
6787 | + */ | |
6788 | + | |
6789 | +#include "aufs.h" | |
6790 | + | |
392086de AM |
6791 | +/* Returns 0, or -errno. arg is in kp->arg. */ |
6792 | +static int param_atomic_t_set(const char *val, const struct kernel_param *kp) | |
6793 | +{ | |
6794 | + int err, n; | |
6795 | + | |
6796 | + err = kstrtoint(val, 0, &n); | |
6797 | + if (!err) { | |
6798 | + if (n > 0) | |
6799 | + au_debug_on(); | |
6800 | + else | |
6801 | + au_debug_off(); | |
6802 | + } | |
6803 | + return err; | |
6804 | +} | |
6805 | + | |
6806 | +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
6807 | +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp) | |
6808 | +{ | |
6809 | + atomic_t *a; | |
6810 | + | |
6811 | + a = kp->arg; | |
6812 | + return sprintf(buffer, "%d", atomic_read(a)); | |
6813 | +} | |
6814 | + | |
6815 | +static struct kernel_param_ops param_ops_atomic_t = { | |
6816 | + .set = param_atomic_t_set, | |
6817 | + .get = param_atomic_t_get | |
6818 | + /* void (*free)(void *arg) */ | |
6819 | +}; | |
6820 | + | |
6821 | +atomic_t aufs_debug = ATOMIC_INIT(0); | |
1facf9fc | 6822 | +MODULE_PARM_DESC(debug, "debug print"); |
392086de | 6823 | +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP); |
1facf9fc | 6824 | + |
c1595e42 | 6825 | +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */ |
1facf9fc | 6826 | +char *au_plevel = KERN_DEBUG; |
e49829fe JR |
6827 | +#define dpri(fmt, ...) do { \ |
6828 | + if ((au_plevel \ | |
6829 | + && strcmp(au_plevel, KERN_DEBUG)) \ | |
6830 | + || au_debug_test()) \ | |
6831 | + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \ | |
1facf9fc | 6832 | +} while (0) |
6833 | + | |
6834 | +/* ---------------------------------------------------------------------- */ | |
6835 | + | |
6836 | +void au_dpri_whlist(struct au_nhash *whlist) | |
6837 | +{ | |
6838 | + unsigned long ul, n; | |
6839 | + struct hlist_head *head; | |
c06a8ce3 | 6840 | + struct au_vdir_wh *pos; |
1facf9fc | 6841 | + |
6842 | + n = whlist->nh_num; | |
6843 | + head = whlist->nh_head; | |
6844 | + for (ul = 0; ul < n; ul++) { | |
c06a8ce3 | 6845 | + hlist_for_each_entry(pos, head, wh_hash) |
1facf9fc | 6846 | + dpri("b%d, %.*s, %d\n", |
c06a8ce3 AM |
6847 | + pos->wh_bindex, |
6848 | + pos->wh_str.len, pos->wh_str.name, | |
6849 | + pos->wh_str.len); | |
1facf9fc | 6850 | + head++; |
6851 | + } | |
6852 | +} | |
6853 | + | |
6854 | +void au_dpri_vdir(struct au_vdir *vdir) | |
6855 | +{ | |
6856 | + unsigned long ul; | |
6857 | + union au_vdir_deblk_p p; | |
6858 | + unsigned char *o; | |
6859 | + | |
6860 | + if (!vdir || IS_ERR(vdir)) { | |
6861 | + dpri("err %ld\n", PTR_ERR(vdir)); | |
6862 | + return; | |
6863 | + } | |
6864 | + | |
6865 | + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n", | |
6866 | + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk, | |
6867 | + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version); | |
6868 | + for (ul = 0; ul < vdir->vd_nblk; ul++) { | |
6869 | + p.deblk = vdir->vd_deblk[ul]; | |
6870 | + o = p.deblk; | |
6871 | + dpri("[%lu]: %p\n", ul, o); | |
6872 | + } | |
6873 | +} | |
6874 | + | |
53392da6 | 6875 | +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn, |
1facf9fc | 6876 | + struct dentry *wh) |
6877 | +{ | |
6878 | + char *n = NULL; | |
6879 | + int l = 0; | |
6880 | + | |
6881 | + if (!inode || IS_ERR(inode)) { | |
6882 | + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode)); | |
6883 | + return -1; | |
6884 | + } | |
6885 | + | |
c2b27bf2 | 6886 | + /* the type of i_blocks depends upon CONFIG_LBDAF */ |
1facf9fc | 6887 | + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long) |
6888 | + && sizeof(inode->i_blocks) != sizeof(u64)); | |
6889 | + if (wh) { | |
6890 | + n = (void *)wh->d_name.name; | |
6891 | + l = wh->d_name.len; | |
6892 | + } | |
6893 | + | |
53392da6 AM |
6894 | + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu," |
6895 | + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n", | |
6896 | + bindex, inode, | |
1facf9fc | 6897 | + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??", |
6898 | + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode, | |
6899 | + i_size_read(inode), (unsigned long long)inode->i_blocks, | |
53392da6 | 6900 | + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff, |
1facf9fc | 6901 | + inode->i_mapping ? inode->i_mapping->nrpages : 0, |
b752ccd1 AM |
6902 | + inode->i_state, inode->i_flags, inode->i_version, |
6903 | + inode->i_generation, | |
1facf9fc | 6904 | + l ? ", wh " : "", l, n); |
6905 | + return 0; | |
6906 | +} | |
6907 | + | |
6908 | +void au_dpri_inode(struct inode *inode) | |
6909 | +{ | |
6910 | + struct au_iinfo *iinfo; | |
6911 | + aufs_bindex_t bindex; | |
53392da6 | 6912 | + int err, hn; |
1facf9fc | 6913 | + |
53392da6 | 6914 | + err = do_pri_inode(-1, inode, -1, NULL); |
1facf9fc | 6915 | + if (err || !au_test_aufs(inode->i_sb)) |
6916 | + return; | |
6917 | + | |
6918 | + iinfo = au_ii(inode); | |
6919 | + if (!iinfo) | |
6920 | + return; | |
6921 | + dpri("i-1: bstart %d, bend %d, gen %d\n", | |
537831f9 | 6922 | + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL)); |
1facf9fc | 6923 | + if (iinfo->ii_bstart < 0) |
6924 | + return; | |
53392da6 AM |
6925 | + hn = 0; |
6926 | + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) { | |
6927 | + hn = !!au_hn(iinfo->ii_hinode + bindex); | |
6928 | + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn, | |
1facf9fc | 6929 | + iinfo->ii_hinode[0 + bindex].hi_whdentry); |
53392da6 | 6930 | + } |
1facf9fc | 6931 | +} |
6932 | + | |
2cbb1c4b JR |
6933 | +void au_dpri_dalias(struct inode *inode) |
6934 | +{ | |
6935 | + struct dentry *d; | |
6936 | + | |
6937 | + spin_lock(&inode->i_lock); | |
c1595e42 | 6938 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) |
2cbb1c4b JR |
6939 | + au_dpri_dentry(d); |
6940 | + spin_unlock(&inode->i_lock); | |
6941 | +} | |
6942 | + | |
1facf9fc | 6943 | +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry) |
6944 | +{ | |
6945 | + struct dentry *wh = NULL; | |
53392da6 | 6946 | + int hn; |
076b876e | 6947 | + struct au_iinfo *iinfo; |
1facf9fc | 6948 | + |
6949 | + if (!dentry || IS_ERR(dentry)) { | |
6950 | + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry)); | |
6951 | + return -1; | |
6952 | + } | |
6953 | + /* do not call dget_parent() here */ | |
027c5e7a | 6954 | + /* note: access d_xxx without d_lock */ |
523b37e3 AM |
6955 | + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n", |
6956 | + bindex, dentry, dentry, | |
1facf9fc | 6957 | + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??", |
c1595e42 | 6958 | + au_dcount(dentry), dentry->d_flags, |
523b37e3 | 6959 | + d_unhashed(dentry) ? "un" : ""); |
53392da6 | 6960 | + hn = -1; |
5527c038 JR |
6961 | + if (bindex >= 0 |
6962 | + && d_is_positive(dentry) | |
6963 | + && au_test_aufs(dentry->d_sb)) { | |
6964 | + iinfo = au_ii(d_inode(dentry)); | |
53392da6 AM |
6965 | + if (iinfo) { |
6966 | + hn = !!au_hn(iinfo->ii_hinode + bindex); | |
1facf9fc | 6967 | + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry; |
53392da6 | 6968 | + } |
1facf9fc | 6969 | + } |
5527c038 | 6970 | + do_pri_inode(bindex, d_inode(dentry), hn, wh); |
1facf9fc | 6971 | + return 0; |
6972 | +} | |
6973 | + | |
6974 | +void au_dpri_dentry(struct dentry *dentry) | |
6975 | +{ | |
6976 | + struct au_dinfo *dinfo; | |
6977 | + aufs_bindex_t bindex; | |
6978 | + int err; | |
4a4d8108 | 6979 | + struct au_hdentry *hdp; |
1facf9fc | 6980 | + |
6981 | + err = do_pri_dentry(-1, dentry); | |
6982 | + if (err || !au_test_aufs(dentry->d_sb)) | |
6983 | + return; | |
6984 | + | |
6985 | + dinfo = au_di(dentry); | |
6986 | + if (!dinfo) | |
6987 | + return; | |
38d290e6 | 6988 | + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n", |
1facf9fc | 6989 | + dinfo->di_bstart, dinfo->di_bend, |
38d290e6 JR |
6990 | + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry), |
6991 | + dinfo->di_tmpfile); | |
1facf9fc | 6992 | + if (dinfo->di_bstart < 0) |
6993 | + return; | |
4a4d8108 | 6994 | + hdp = dinfo->di_hdentry; |
1facf9fc | 6995 | + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++) |
4a4d8108 | 6996 | + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry); |
1facf9fc | 6997 | +} |
6998 | + | |
6999 | +static int do_pri_file(aufs_bindex_t bindex, struct file *file) | |
7000 | +{ | |
7001 | + char a[32]; | |
7002 | + | |
7003 | + if (!file || IS_ERR(file)) { | |
7004 | + dpri("f%d: err %ld\n", bindex, PTR_ERR(file)); | |
7005 | + return -1; | |
7006 | + } | |
7007 | + a[0] = 0; | |
7008 | + if (bindex < 0 | |
b912730e | 7009 | + && !IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7010 | + && au_test_aufs(file->f_path.dentry->d_sb) |
1facf9fc | 7011 | + && au_fi(file)) |
e49829fe | 7012 | + snprintf(a, sizeof(a), ", gen %d, mmapped %d", |
2cbb1c4b | 7013 | + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped)); |
b752ccd1 | 7014 | + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n", |
1facf9fc | 7015 | + bindex, file->f_mode, file->f_flags, (long)file_count(file), |
b752ccd1 | 7016 | + file->f_version, file->f_pos, a); |
b912730e | 7017 | + if (!IS_ERR_OR_NULL(file->f_path.dentry)) |
2000de60 | 7018 | + do_pri_dentry(bindex, file->f_path.dentry); |
1facf9fc | 7019 | + return 0; |
7020 | +} | |
7021 | + | |
7022 | +void au_dpri_file(struct file *file) | |
7023 | +{ | |
7024 | + struct au_finfo *finfo; | |
4a4d8108 AM |
7025 | + struct au_fidir *fidir; |
7026 | + struct au_hfile *hfile; | |
1facf9fc | 7027 | + aufs_bindex_t bindex; |
7028 | + int err; | |
7029 | + | |
7030 | + err = do_pri_file(-1, file); | |
2000de60 | 7031 | + if (err |
b912730e | 7032 | + || IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7033 | + || !au_test_aufs(file->f_path.dentry->d_sb)) |
1facf9fc | 7034 | + return; |
7035 | + | |
7036 | + finfo = au_fi(file); | |
7037 | + if (!finfo) | |
7038 | + return; | |
4a4d8108 | 7039 | + if (finfo->fi_btop < 0) |
1facf9fc | 7040 | + return; |
4a4d8108 AM |
7041 | + fidir = finfo->fi_hdir; |
7042 | + if (!fidir) | |
7043 | + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file); | |
7044 | + else | |
e49829fe JR |
7045 | + for (bindex = finfo->fi_btop; |
7046 | + bindex >= 0 && bindex <= fidir->fd_bbot; | |
4a4d8108 AM |
7047 | + bindex++) { |
7048 | + hfile = fidir->fd_hfile + bindex; | |
7049 | + do_pri_file(bindex, hfile ? hfile->hf_file : NULL); | |
7050 | + } | |
1facf9fc | 7051 | +} |
7052 | + | |
7053 | +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br) | |
7054 | +{ | |
7055 | + struct vfsmount *mnt; | |
7056 | + struct super_block *sb; | |
7057 | + | |
7058 | + if (!br || IS_ERR(br)) | |
7059 | + goto out; | |
86dc4139 | 7060 | + mnt = au_br_mnt(br); |
1facf9fc | 7061 | + if (!mnt || IS_ERR(mnt)) |
7062 | + goto out; | |
7063 | + sb = mnt->mnt_sb; | |
7064 | + if (!sb || IS_ERR(sb)) | |
7065 | + goto out; | |
7066 | + | |
1e00d052 | 7067 | + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, " |
b752ccd1 | 7068 | + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, " |
1facf9fc | 7069 | + "xino %d\n", |
1e00d052 AM |
7070 | + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count), |
7071 | + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev), | |
b752ccd1 | 7072 | + sb->s_flags, sb->s_count, |
1facf9fc | 7073 | + atomic_read(&sb->s_active), !!br->br_xino.xi_file); |
7074 | + return 0; | |
7075 | + | |
4f0767ce | 7076 | +out: |
1facf9fc | 7077 | + dpri("s%d: err %ld\n", bindex, PTR_ERR(br)); |
7078 | + return -1; | |
7079 | +} | |
7080 | + | |
7081 | +void au_dpri_sb(struct super_block *sb) | |
7082 | +{ | |
7083 | + struct au_sbinfo *sbinfo; | |
7084 | + aufs_bindex_t bindex; | |
7085 | + int err; | |
7086 | + /* to reuduce stack size */ | |
7087 | + struct { | |
7088 | + struct vfsmount mnt; | |
7089 | + struct au_branch fake; | |
7090 | + } *a; | |
7091 | + | |
7092 | + /* this function can be called from magic sysrq */ | |
7093 | + a = kzalloc(sizeof(*a), GFP_ATOMIC); | |
7094 | + if (unlikely(!a)) { | |
7095 | + dpri("no memory\n"); | |
7096 | + return; | |
7097 | + } | |
7098 | + | |
7099 | + a->mnt.mnt_sb = sb; | |
7100 | + a->fake.br_perm = 0; | |
86dc4139 | 7101 | + a->fake.br_path.mnt = &a->mnt; |
1facf9fc | 7102 | + a->fake.br_xino.xi_file = NULL; |
7103 | + atomic_set(&a->fake.br_count, 0); | |
7104 | + smp_mb(); /* atomic_set */ | |
7105 | + err = do_pri_br(-1, &a->fake); | |
7106 | + kfree(a); | |
7107 | + dpri("dev 0x%x\n", sb->s_dev); | |
7108 | + if (err || !au_test_aufs(sb)) | |
7109 | + return; | |
7110 | + | |
7111 | + sbinfo = au_sbi(sb); | |
7112 | + if (!sbinfo) | |
7113 | + return; | |
7114 | + dpri("nw %d, gen %u, kobj %d\n", | |
7115 | + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation, | |
7116 | + atomic_read(&sbinfo->si_kobj.kref.refcount)); | |
7117 | + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++) | |
7118 | + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]); | |
7119 | +} | |
7120 | + | |
7121 | +/* ---------------------------------------------------------------------- */ | |
7122 | + | |
027c5e7a AM |
7123 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line) |
7124 | +{ | |
5527c038 | 7125 | + struct inode *h_inode, *inode = d_inode(dentry); |
027c5e7a AM |
7126 | + struct dentry *h_dentry; |
7127 | + aufs_bindex_t bindex, bend, bi; | |
7128 | + | |
7129 | + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */) | |
7130 | + return; | |
7131 | + | |
7132 | + bend = au_dbend(dentry); | |
7133 | + bi = au_ibend(inode); | |
7134 | + if (bi < bend) | |
7135 | + bend = bi; | |
7136 | + bindex = au_dbstart(dentry); | |
7137 | + bi = au_ibstart(inode); | |
7138 | + if (bi > bindex) | |
7139 | + bindex = bi; | |
7140 | + | |
7141 | + for (; bindex <= bend; bindex++) { | |
7142 | + h_dentry = au_h_dptr(dentry, bindex); | |
7143 | + if (!h_dentry) | |
7144 | + continue; | |
7145 | + h_inode = au_h_iptr(inode, bindex); | |
5527c038 | 7146 | + if (unlikely(h_inode != d_inode(h_dentry))) { |
392086de | 7147 | + au_debug_on(); |
027c5e7a AM |
7148 | + AuDbg("b%d, %s:%d\n", bindex, func, line); |
7149 | + AuDbgDentry(dentry); | |
7150 | + AuDbgInode(inode); | |
392086de | 7151 | + au_debug_off(); |
027c5e7a AM |
7152 | + BUG(); |
7153 | + } | |
7154 | + } | |
7155 | +} | |
7156 | + | |
1facf9fc | 7157 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen) |
7158 | +{ | |
7159 | + int err, i, j; | |
7160 | + struct au_dcsub_pages dpages; | |
7161 | + struct au_dpage *dpage; | |
7162 | + struct dentry **dentries; | |
7163 | + | |
7164 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
7165 | + AuDebugOn(err); | |
027c5e7a | 7166 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1); |
1facf9fc | 7167 | + AuDebugOn(err); |
7168 | + for (i = dpages.ndpage - 1; !err && i >= 0; i--) { | |
7169 | + dpage = dpages.dpages + i; | |
7170 | + dentries = dpage->dentries; | |
7171 | + for (j = dpage->ndentry - 1; !err && j >= 0; j--) | |
027c5e7a | 7172 | + AuDebugOn(au_digen_test(dentries[j], sigen)); |
1facf9fc | 7173 | + } |
7174 | + au_dpages_free(&dpages); | |
7175 | +} | |
7176 | + | |
1facf9fc | 7177 | +void au_dbg_verify_kthread(void) |
7178 | +{ | |
53392da6 | 7179 | + if (au_wkq_test()) { |
1facf9fc | 7180 | + au_dbg_blocked(); |
1e00d052 AM |
7181 | + /* |
7182 | + * It may be recursive, but udba=notify between two aufs mounts, | |
7183 | + * where a single ro branch is shared, is not a problem. | |
7184 | + */ | |
7185 | + /* WARN_ON(1); */ | |
1facf9fc | 7186 | + } |
7187 | +} | |
7188 | + | |
7189 | +/* ---------------------------------------------------------------------- */ | |
7190 | + | |
1facf9fc | 7191 | +int __init au_debug_init(void) |
7192 | +{ | |
7193 | + aufs_bindex_t bindex; | |
7194 | + struct au_vdir_destr destr; | |
7195 | + | |
7196 | + bindex = -1; | |
7197 | + AuDebugOn(bindex >= 0); | |
7198 | + | |
7199 | + destr.len = -1; | |
7200 | + AuDebugOn(destr.len < NAME_MAX); | |
7201 | + | |
7202 | +#ifdef CONFIG_4KSTACKS | |
0c3ec466 | 7203 | + pr_warn("CONFIG_4KSTACKS is defined.\n"); |
1facf9fc | 7204 | +#endif |
7205 | + | |
1facf9fc | 7206 | + return 0; |
7207 | +} | |
7f207e10 AM |
7208 | diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h |
7209 | --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 7210 | +++ linux/fs/aufs/debug.h 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 7211 | @@ -0,0 +1,225 @@ |
1facf9fc | 7212 | +/* |
2000de60 | 7213 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 7214 | + * |
7215 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7216 | + * it under the terms of the GNU General Public License as published by | |
7217 | + * the Free Software Foundation; either version 2 of the License, or | |
7218 | + * (at your option) any later version. | |
dece6358 AM |
7219 | + * |
7220 | + * This program is distributed in the hope that it will be useful, | |
7221 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7222 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7223 | + * GNU General Public License for more details. | |
7224 | + * | |
7225 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7226 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7227 | + */ |
7228 | + | |
7229 | +/* | |
7230 | + * debug print functions | |
7231 | + */ | |
7232 | + | |
7233 | +#ifndef __AUFS_DEBUG_H__ | |
7234 | +#define __AUFS_DEBUG_H__ | |
7235 | + | |
7236 | +#ifdef __KERNEL__ | |
7237 | + | |
392086de | 7238 | +#include <linux/atomic.h> |
4a4d8108 AM |
7239 | +#include <linux/module.h> |
7240 | +#include <linux/kallsyms.h> | |
1facf9fc | 7241 | +#include <linux/sysrq.h> |
4a4d8108 | 7242 | + |
1facf9fc | 7243 | +#ifdef CONFIG_AUFS_DEBUG |
7244 | +#define AuDebugOn(a) BUG_ON(a) | |
7245 | + | |
7246 | +/* module parameter */ | |
392086de AM |
7247 | +extern atomic_t aufs_debug; |
7248 | +static inline void au_debug_on(void) | |
1facf9fc | 7249 | +{ |
392086de AM |
7250 | + atomic_inc(&aufs_debug); |
7251 | +} | |
7252 | +static inline void au_debug_off(void) | |
7253 | +{ | |
7254 | + atomic_dec_if_positive(&aufs_debug); | |
1facf9fc | 7255 | +} |
7256 | + | |
7257 | +static inline int au_debug_test(void) | |
7258 | +{ | |
392086de | 7259 | + return atomic_read(&aufs_debug) > 0; |
1facf9fc | 7260 | +} |
7261 | +#else | |
7262 | +#define AuDebugOn(a) do {} while (0) | |
392086de AM |
7263 | +AuStubVoid(au_debug_on, void) |
7264 | +AuStubVoid(au_debug_off, void) | |
4a4d8108 | 7265 | +AuStubInt0(au_debug_test, void) |
1facf9fc | 7266 | +#endif /* CONFIG_AUFS_DEBUG */ |
7267 | + | |
392086de AM |
7268 | +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t) |
7269 | + | |
1facf9fc | 7270 | +/* ---------------------------------------------------------------------- */ |
7271 | + | |
7272 | +/* debug print */ | |
7273 | + | |
4a4d8108 | 7274 | +#define AuDbg(fmt, ...) do { \ |
1facf9fc | 7275 | + if (au_debug_test()) \ |
4a4d8108 | 7276 | + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \ |
1facf9fc | 7277 | +} while (0) |
4a4d8108 AM |
7278 | +#define AuLabel(l) AuDbg(#l "\n") |
7279 | +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__) | |
7280 | +#define AuWarn1(fmt, ...) do { \ | |
1facf9fc | 7281 | + static unsigned char _c; \ |
7282 | + if (!_c++) \ | |
0c3ec466 | 7283 | + pr_warn(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7284 | +} while (0) |
7285 | + | |
4a4d8108 | 7286 | +#define AuErr1(fmt, ...) do { \ |
1facf9fc | 7287 | + static unsigned char _c; \ |
7288 | + if (!_c++) \ | |
4a4d8108 | 7289 | + pr_err(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7290 | +} while (0) |
7291 | + | |
4a4d8108 | 7292 | +#define AuIOErr1(fmt, ...) do { \ |
1facf9fc | 7293 | + static unsigned char _c; \ |
7294 | + if (!_c++) \ | |
4a4d8108 | 7295 | + AuIOErr(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7296 | +} while (0) |
7297 | + | |
7298 | +#define AuUnsupportMsg "This operation is not supported." \ | |
7299 | + " Please report this application to aufs-users ML." | |
4a4d8108 AM |
7300 | +#define AuUnsupport(fmt, ...) do { \ |
7301 | + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \ | |
1facf9fc | 7302 | + dump_stack(); \ |
7303 | +} while (0) | |
7304 | + | |
7305 | +#define AuTraceErr(e) do { \ | |
7306 | + if (unlikely((e) < 0)) \ | |
7307 | + AuDbg("err %d\n", (int)(e)); \ | |
7308 | +} while (0) | |
7309 | + | |
7310 | +#define AuTraceErrPtr(p) do { \ | |
7311 | + if (IS_ERR(p)) \ | |
7312 | + AuDbg("err %ld\n", PTR_ERR(p)); \ | |
7313 | +} while (0) | |
7314 | + | |
7315 | +/* dirty macros for debug print, use with "%.*s" and caution */ | |
7316 | +#define AuLNPair(qstr) (qstr)->len, (qstr)->name | |
1facf9fc | 7317 | + |
7318 | +/* ---------------------------------------------------------------------- */ | |
7319 | + | |
dece6358 | 7320 | +struct dentry; |
1facf9fc | 7321 | +#ifdef CONFIG_AUFS_DEBUG |
c1595e42 | 7322 | +extern struct mutex au_dbg_mtx; |
1facf9fc | 7323 | +extern char *au_plevel; |
7324 | +struct au_nhash; | |
7325 | +void au_dpri_whlist(struct au_nhash *whlist); | |
7326 | +struct au_vdir; | |
7327 | +void au_dpri_vdir(struct au_vdir *vdir); | |
dece6358 | 7328 | +struct inode; |
1facf9fc | 7329 | +void au_dpri_inode(struct inode *inode); |
2cbb1c4b | 7330 | +void au_dpri_dalias(struct inode *inode); |
1facf9fc | 7331 | +void au_dpri_dentry(struct dentry *dentry); |
dece6358 | 7332 | +struct file; |
1facf9fc | 7333 | +void au_dpri_file(struct file *filp); |
dece6358 | 7334 | +struct super_block; |
1facf9fc | 7335 | +void au_dpri_sb(struct super_block *sb); |
7336 | + | |
027c5e7a AM |
7337 | +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__) |
7338 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line); | |
1facf9fc | 7339 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen); |
1facf9fc | 7340 | +void au_dbg_verify_kthread(void); |
7341 | + | |
7342 | +int __init au_debug_init(void); | |
7e9cd9fe | 7343 | + |
1facf9fc | 7344 | +#define AuDbgWhlist(w) do { \ |
c1595e42 | 7345 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7346 | + AuDbg(#w "\n"); \ |
7347 | + au_dpri_whlist(w); \ | |
c1595e42 | 7348 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7349 | +} while (0) |
7350 | + | |
7351 | +#define AuDbgVdir(v) do { \ | |
c1595e42 | 7352 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7353 | + AuDbg(#v "\n"); \ |
7354 | + au_dpri_vdir(v); \ | |
c1595e42 | 7355 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7356 | +} while (0) |
7357 | + | |
7358 | +#define AuDbgInode(i) do { \ | |
c1595e42 | 7359 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7360 | + AuDbg(#i "\n"); \ |
7361 | + au_dpri_inode(i); \ | |
c1595e42 | 7362 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7363 | +} while (0) |
7364 | + | |
2cbb1c4b | 7365 | +#define AuDbgDAlias(i) do { \ |
c1595e42 | 7366 | + mutex_lock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7367 | + AuDbg(#i "\n"); \ |
7368 | + au_dpri_dalias(i); \ | |
c1595e42 | 7369 | + mutex_unlock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7370 | +} while (0) |
7371 | + | |
1facf9fc | 7372 | +#define AuDbgDentry(d) do { \ |
c1595e42 | 7373 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7374 | + AuDbg(#d "\n"); \ |
7375 | + au_dpri_dentry(d); \ | |
c1595e42 | 7376 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7377 | +} while (0) |
7378 | + | |
7379 | +#define AuDbgFile(f) do { \ | |
c1595e42 | 7380 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7381 | + AuDbg(#f "\n"); \ |
7382 | + au_dpri_file(f); \ | |
c1595e42 | 7383 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7384 | +} while (0) |
7385 | + | |
7386 | +#define AuDbgSb(sb) do { \ | |
c1595e42 | 7387 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7388 | + AuDbg(#sb "\n"); \ |
7389 | + au_dpri_sb(sb); \ | |
c1595e42 | 7390 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7391 | +} while (0) |
7392 | + | |
4a4d8108 AM |
7393 | +#define AuDbgSym(addr) do { \ |
7394 | + char sym[KSYM_SYMBOL_LEN]; \ | |
7395 | + sprint_symbol(sym, (unsigned long)addr); \ | |
7396 | + AuDbg("%s\n", sym); \ | |
7397 | +} while (0) | |
1facf9fc | 7398 | +#else |
027c5e7a | 7399 | +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry) |
4a4d8108 AM |
7400 | +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen) |
7401 | +AuStubVoid(au_dbg_verify_kthread, void) | |
7402 | +AuStubInt0(__init au_debug_init, void) | |
1facf9fc | 7403 | + |
1facf9fc | 7404 | +#define AuDbgWhlist(w) do {} while (0) |
7405 | +#define AuDbgVdir(v) do {} while (0) | |
7406 | +#define AuDbgInode(i) do {} while (0) | |
2cbb1c4b | 7407 | +#define AuDbgDAlias(i) do {} while (0) |
1facf9fc | 7408 | +#define AuDbgDentry(d) do {} while (0) |
7409 | +#define AuDbgFile(f) do {} while (0) | |
7410 | +#define AuDbgSb(sb) do {} while (0) | |
4a4d8108 | 7411 | +#define AuDbgSym(addr) do {} while (0) |
1facf9fc | 7412 | +#endif /* CONFIG_AUFS_DEBUG */ |
7413 | + | |
7414 | +/* ---------------------------------------------------------------------- */ | |
7415 | + | |
7416 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
7417 | +int __init au_sysrq_init(void); | |
7418 | +void au_sysrq_fin(void); | |
7419 | + | |
7420 | +#ifdef CONFIG_HW_CONSOLE | |
7421 | +#define au_dbg_blocked() do { \ | |
7422 | + WARN_ON(1); \ | |
0c5527e5 | 7423 | + handle_sysrq('w'); \ |
1facf9fc | 7424 | +} while (0) |
7425 | +#else | |
4a4d8108 | 7426 | +AuStubVoid(au_dbg_blocked, void) |
1facf9fc | 7427 | +#endif |
7428 | + | |
7429 | +#else | |
4a4d8108 AM |
7430 | +AuStubInt0(__init au_sysrq_init, void) |
7431 | +AuStubVoid(au_sysrq_fin, void) | |
7432 | +AuStubVoid(au_dbg_blocked, void) | |
1facf9fc | 7433 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ |
7434 | + | |
7435 | +#endif /* __KERNEL__ */ | |
7436 | +#endif /* __AUFS_DEBUG_H__ */ | |
7f207e10 AM |
7437 | diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c |
7438 | --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 7439 | +++ linux/fs/aufs/dentry.c 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 7440 | @@ -0,0 +1,1105 @@ |
1facf9fc | 7441 | +/* |
2000de60 | 7442 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 7443 | + * |
7444 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7445 | + * it under the terms of the GNU General Public License as published by | |
7446 | + * the Free Software Foundation; either version 2 of the License, or | |
7447 | + * (at your option) any later version. | |
dece6358 AM |
7448 | + * |
7449 | + * This program is distributed in the hope that it will be useful, | |
7450 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7451 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7452 | + * GNU General Public License for more details. | |
7453 | + * | |
7454 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7455 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7456 | + */ |
7457 | + | |
7458 | +/* | |
7459 | + * lookup and dentry operations | |
7460 | + */ | |
7461 | + | |
dece6358 | 7462 | +#include <linux/namei.h> |
1facf9fc | 7463 | +#include "aufs.h" |
7464 | + | |
1facf9fc | 7465 | +#define AuLkup_ALLOW_NEG 1 |
076b876e | 7466 | +#define AuLkup_IGNORE_PERM (1 << 1) |
1facf9fc | 7467 | +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name) |
7f207e10 AM |
7468 | +#define au_fset_lkup(flags, name) \ |
7469 | + do { (flags) |= AuLkup_##name; } while (0) | |
7470 | +#define au_fclr_lkup(flags, name) \ | |
7471 | + do { (flags) &= ~AuLkup_##name; } while (0) | |
1facf9fc | 7472 | + |
7473 | +struct au_do_lookup_args { | |
7474 | + unsigned int flags; | |
7475 | + mode_t type; | |
1facf9fc | 7476 | +}; |
7477 | + | |
7478 | +/* | |
7479 | + * returns positive/negative dentry, NULL or an error. | |
7480 | + * NULL means whiteout-ed or not-found. | |
7481 | + */ | |
7482 | +static struct dentry* | |
7483 | +au_do_lookup(struct dentry *h_parent, struct dentry *dentry, | |
7484 | + aufs_bindex_t bindex, struct qstr *wh_name, | |
7485 | + struct au_do_lookup_args *args) | |
7486 | +{ | |
7487 | + struct dentry *h_dentry; | |
2000de60 | 7488 | + struct inode *h_inode; |
1facf9fc | 7489 | + struct au_branch *br; |
7490 | + int wh_found, opq; | |
7491 | + unsigned char wh_able; | |
7492 | + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG); | |
076b876e AM |
7493 | + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags, |
7494 | + IGNORE_PERM); | |
1facf9fc | 7495 | + |
1facf9fc | 7496 | + wh_found = 0; |
7497 | + br = au_sbr(dentry->d_sb, bindex); | |
7498 | + wh_able = !!au_br_whable(br->br_perm); | |
7499 | + if (wh_able) | |
076b876e | 7500 | + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0); |
1facf9fc | 7501 | + h_dentry = ERR_PTR(wh_found); |
7502 | + if (!wh_found) | |
7503 | + goto real_lookup; | |
7504 | + if (unlikely(wh_found < 0)) | |
7505 | + goto out; | |
7506 | + | |
7507 | + /* We found a whiteout */ | |
7508 | + /* au_set_dbend(dentry, bindex); */ | |
7509 | + au_set_dbwh(dentry, bindex); | |
7510 | + if (!allow_neg) | |
7511 | + return NULL; /* success */ | |
7512 | + | |
4f0767ce | 7513 | +real_lookup: |
076b876e AM |
7514 | + if (!ignore_perm) |
7515 | + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
7516 | + else | |
7517 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); | |
2000de60 JR |
7518 | + if (IS_ERR(h_dentry)) { |
7519 | + if (PTR_ERR(h_dentry) == -ENAMETOOLONG | |
7520 | + && !allow_neg) | |
7521 | + h_dentry = NULL; | |
1facf9fc | 7522 | + goto out; |
2000de60 | 7523 | + } |
1facf9fc | 7524 | + |
5527c038 JR |
7525 | + h_inode = d_inode(h_dentry); |
7526 | + if (d_is_negative(h_dentry)) { | |
1facf9fc | 7527 | + if (!allow_neg) |
7528 | + goto out_neg; | |
7529 | + } else if (wh_found | |
7530 | + || (args->type && args->type != (h_inode->i_mode & S_IFMT))) | |
7531 | + goto out_neg; | |
7532 | + | |
7533 | + if (au_dbend(dentry) <= bindex) | |
7534 | + au_set_dbend(dentry, bindex); | |
7535 | + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry)) | |
7536 | + au_set_dbstart(dentry, bindex); | |
7537 | + au_set_h_dptr(dentry, bindex, h_dentry); | |
7538 | + | |
2000de60 JR |
7539 | + if (!d_is_dir(h_dentry) |
7540 | + || !wh_able | |
5527c038 | 7541 | + || (d_really_is_positive(dentry) && !d_is_dir(dentry))) |
1facf9fc | 7542 | + goto out; /* success */ |
7543 | + | |
7544 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); | |
076b876e | 7545 | + opq = au_diropq_test(h_dentry); |
1facf9fc | 7546 | + mutex_unlock(&h_inode->i_mutex); |
7547 | + if (opq > 0) | |
7548 | + au_set_dbdiropq(dentry, bindex); | |
7549 | + else if (unlikely(opq < 0)) { | |
7550 | + au_set_h_dptr(dentry, bindex, NULL); | |
7551 | + h_dentry = ERR_PTR(opq); | |
7552 | + } | |
7553 | + goto out; | |
7554 | + | |
4f0767ce | 7555 | +out_neg: |
1facf9fc | 7556 | + dput(h_dentry); |
7557 | + h_dentry = NULL; | |
4f0767ce | 7558 | +out: |
1facf9fc | 7559 | + return h_dentry; |
7560 | +} | |
7561 | + | |
dece6358 AM |
7562 | +static int au_test_shwh(struct super_block *sb, const struct qstr *name) |
7563 | +{ | |
7564 | + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH) | |
7565 | + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))) | |
7566 | + return -EPERM; | |
7567 | + return 0; | |
7568 | +} | |
7569 | + | |
1facf9fc | 7570 | +/* |
7571 | + * returns the number of lower positive dentries, | |
7572 | + * otherwise an error. | |
7573 | + * can be called at unlinking with @type is zero. | |
7574 | + */ | |
537831f9 | 7575 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type) |
1facf9fc | 7576 | +{ |
7577 | + int npositive, err; | |
7578 | + aufs_bindex_t bindex, btail, bdiropq; | |
076b876e | 7579 | + unsigned char isdir, dirperm1; |
1facf9fc | 7580 | + struct qstr whname; |
7581 | + struct au_do_lookup_args args = { | |
b4510431 | 7582 | + .flags = 0, |
537831f9 | 7583 | + .type = type |
1facf9fc | 7584 | + }; |
7585 | + const struct qstr *name = &dentry->d_name; | |
7586 | + struct dentry *parent; | |
076b876e | 7587 | + struct super_block *sb; |
1facf9fc | 7588 | + |
076b876e AM |
7589 | + sb = dentry->d_sb; |
7590 | + err = au_test_shwh(sb, name); | |
dece6358 | 7591 | + if (unlikely(err)) |
1facf9fc | 7592 | + goto out; |
7593 | + | |
7594 | + err = au_wh_name_alloc(&whname, name); | |
7595 | + if (unlikely(err)) | |
7596 | + goto out; | |
7597 | + | |
2000de60 | 7598 | + isdir = !!d_is_dir(dentry); |
1facf9fc | 7599 | + if (!type) |
7600 | + au_fset_lkup(args.flags, ALLOW_NEG); | |
076b876e | 7601 | + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1); |
1facf9fc | 7602 | + |
7603 | + npositive = 0; | |
4a4d8108 | 7604 | + parent = dget_parent(dentry); |
1facf9fc | 7605 | + btail = au_dbtaildir(parent); |
7606 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
7607 | + struct dentry *h_parent, *h_dentry; | |
7608 | + struct inode *h_inode, *h_dir; | |
7609 | + | |
7610 | + h_dentry = au_h_dptr(dentry, bindex); | |
7611 | + if (h_dentry) { | |
5527c038 | 7612 | + if (d_is_positive(h_dentry)) |
1facf9fc | 7613 | + npositive++; |
7614 | + if (type != S_IFDIR) | |
7615 | + break; | |
7616 | + continue; | |
7617 | + } | |
7618 | + h_parent = au_h_dptr(parent, bindex); | |
2000de60 | 7619 | + if (!h_parent || !d_is_dir(h_parent)) |
1facf9fc | 7620 | + continue; |
7621 | + | |
5527c038 | 7622 | + h_dir = d_inode(h_parent); |
1facf9fc | 7623 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); |
7624 | + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname, | |
7625 | + &args); | |
7626 | + mutex_unlock(&h_dir->i_mutex); | |
7627 | + err = PTR_ERR(h_dentry); | |
7628 | + if (IS_ERR(h_dentry)) | |
4a4d8108 | 7629 | + goto out_parent; |
2000de60 JR |
7630 | + if (h_dentry) |
7631 | + au_fclr_lkup(args.flags, ALLOW_NEG); | |
076b876e AM |
7632 | + if (dirperm1) |
7633 | + au_fset_lkup(args.flags, IGNORE_PERM); | |
1facf9fc | 7634 | + |
7635 | + if (au_dbwh(dentry) >= 0) | |
7636 | + break; | |
7637 | + if (!h_dentry) | |
7638 | + continue; | |
5527c038 | 7639 | + if (d_is_negative(h_dentry)) |
1facf9fc | 7640 | + continue; |
5527c038 | 7641 | + h_inode = d_inode(h_dentry); |
1facf9fc | 7642 | + npositive++; |
7643 | + if (!args.type) | |
7644 | + args.type = h_inode->i_mode & S_IFMT; | |
7645 | + if (args.type != S_IFDIR) | |
7646 | + break; | |
7647 | + else if (isdir) { | |
7648 | + /* the type of lower may be different */ | |
7649 | + bdiropq = au_dbdiropq(dentry); | |
7650 | + if (bdiropq >= 0 && bdiropq <= bindex) | |
7651 | + break; | |
7652 | + } | |
7653 | + } | |
7654 | + | |
7655 | + if (npositive) { | |
7656 | + AuLabel(positive); | |
7657 | + au_update_dbstart(dentry); | |
7658 | + } | |
7659 | + err = npositive; | |
076b876e | 7660 | + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE) |
027c5e7a | 7661 | + && au_dbstart(dentry) < 0)) { |
1facf9fc | 7662 | + err = -EIO; |
523b37e3 AM |
7663 | + AuIOErr("both of real entry and whiteout found, %pd, err %d\n", |
7664 | + dentry, err); | |
027c5e7a | 7665 | + } |
1facf9fc | 7666 | + |
4f0767ce | 7667 | +out_parent: |
4a4d8108 | 7668 | + dput(parent); |
1facf9fc | 7669 | + kfree(whname.name); |
4f0767ce | 7670 | +out: |
1facf9fc | 7671 | + return err; |
7672 | +} | |
7673 | + | |
076b876e | 7674 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent) |
1facf9fc | 7675 | +{ |
7676 | + struct dentry *dentry; | |
7677 | + int wkq_err; | |
7678 | + | |
5527c038 | 7679 | + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC)) |
b4510431 | 7680 | + dentry = vfsub_lkup_one(name, parent); |
1facf9fc | 7681 | + else { |
b4510431 AM |
7682 | + struct vfsub_lkup_one_args args = { |
7683 | + .errp = &dentry, | |
7684 | + .name = name, | |
7685 | + .parent = parent | |
1facf9fc | 7686 | + }; |
7687 | + | |
b4510431 | 7688 | + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args); |
1facf9fc | 7689 | + if (unlikely(wkq_err)) |
7690 | + dentry = ERR_PTR(wkq_err); | |
7691 | + } | |
7692 | + | |
7693 | + return dentry; | |
7694 | +} | |
7695 | + | |
7696 | +/* | |
7697 | + * lookup @dentry on @bindex which should be negative. | |
7698 | + */ | |
86dc4139 | 7699 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh) |
1facf9fc | 7700 | +{ |
7701 | + int err; | |
7702 | + struct dentry *parent, *h_parent, *h_dentry; | |
86dc4139 | 7703 | + struct au_branch *br; |
1facf9fc | 7704 | + |
1facf9fc | 7705 | + parent = dget_parent(dentry); |
7706 | + h_parent = au_h_dptr(parent, bindex); | |
86dc4139 AM |
7707 | + br = au_sbr(dentry->d_sb, bindex); |
7708 | + if (wh) | |
7709 | + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
7710 | + else | |
076b876e | 7711 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); |
1facf9fc | 7712 | + err = PTR_ERR(h_dentry); |
7713 | + if (IS_ERR(h_dentry)) | |
7714 | + goto out; | |
5527c038 | 7715 | + if (unlikely(d_is_positive(h_dentry))) { |
1facf9fc | 7716 | + err = -EIO; |
523b37e3 | 7717 | + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex); |
1facf9fc | 7718 | + dput(h_dentry); |
7719 | + goto out; | |
7720 | + } | |
7721 | + | |
4a4d8108 | 7722 | + err = 0; |
1facf9fc | 7723 | + if (bindex < au_dbstart(dentry)) |
7724 | + au_set_dbstart(dentry, bindex); | |
7725 | + if (au_dbend(dentry) < bindex) | |
7726 | + au_set_dbend(dentry, bindex); | |
7727 | + au_set_h_dptr(dentry, bindex, h_dentry); | |
1facf9fc | 7728 | + |
4f0767ce | 7729 | +out: |
1facf9fc | 7730 | + dput(parent); |
7731 | + return err; | |
7732 | +} | |
7733 | + | |
7734 | +/* ---------------------------------------------------------------------- */ | |
7735 | + | |
7736 | +/* subset of struct inode */ | |
7737 | +struct au_iattr { | |
7738 | + unsigned long i_ino; | |
7739 | + /* unsigned int i_nlink; */ | |
0c3ec466 AM |
7740 | + kuid_t i_uid; |
7741 | + kgid_t i_gid; | |
1facf9fc | 7742 | + u64 i_version; |
7743 | +/* | |
7744 | + loff_t i_size; | |
7745 | + blkcnt_t i_blocks; | |
7746 | +*/ | |
7747 | + umode_t i_mode; | |
7748 | +}; | |
7749 | + | |
7750 | +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode) | |
7751 | +{ | |
7752 | + ia->i_ino = h_inode->i_ino; | |
7753 | + /* ia->i_nlink = h_inode->i_nlink; */ | |
7754 | + ia->i_uid = h_inode->i_uid; | |
7755 | + ia->i_gid = h_inode->i_gid; | |
7756 | + ia->i_version = h_inode->i_version; | |
7757 | +/* | |
7758 | + ia->i_size = h_inode->i_size; | |
7759 | + ia->i_blocks = h_inode->i_blocks; | |
7760 | +*/ | |
7761 | + ia->i_mode = (h_inode->i_mode & S_IFMT); | |
7762 | +} | |
7763 | + | |
7764 | +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode) | |
7765 | +{ | |
7766 | + return ia->i_ino != h_inode->i_ino | |
7767 | + /* || ia->i_nlink != h_inode->i_nlink */ | |
0c3ec466 | 7768 | + || !uid_eq(ia->i_uid, h_inode->i_uid) |
2dfbb274 | 7769 | + || !gid_eq(ia->i_gid, h_inode->i_gid) |
1facf9fc | 7770 | + || ia->i_version != h_inode->i_version |
7771 | +/* | |
7772 | + || ia->i_size != h_inode->i_size | |
7773 | + || ia->i_blocks != h_inode->i_blocks | |
7774 | +*/ | |
7775 | + || ia->i_mode != (h_inode->i_mode & S_IFMT); | |
7776 | +} | |
7777 | + | |
7778 | +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent, | |
7779 | + struct au_branch *br) | |
7780 | +{ | |
7781 | + int err; | |
7782 | + struct au_iattr ia; | |
7783 | + struct inode *h_inode; | |
7784 | + struct dentry *h_d; | |
7785 | + struct super_block *h_sb; | |
7786 | + | |
7787 | + err = 0; | |
7788 | + memset(&ia, -1, sizeof(ia)); | |
7789 | + h_sb = h_dentry->d_sb; | |
5527c038 JR |
7790 | + h_inode = NULL; |
7791 | + if (d_is_positive(h_dentry)) { | |
7792 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 7793 | + au_iattr_save(&ia, h_inode); |
5527c038 | 7794 | + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb)) |
1facf9fc | 7795 | + /* nfs d_revalidate may return 0 for negative dentry */ |
7796 | + /* fuse d_revalidate always return 0 for negative dentry */ | |
7797 | + goto out; | |
7798 | + | |
7799 | + /* main purpose is namei.c:cached_lookup() and d_revalidate */ | |
b4510431 | 7800 | + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent); |
1facf9fc | 7801 | + err = PTR_ERR(h_d); |
7802 | + if (IS_ERR(h_d)) | |
7803 | + goto out; | |
7804 | + | |
7805 | + err = 0; | |
7806 | + if (unlikely(h_d != h_dentry | |
5527c038 | 7807 | + || d_inode(h_d) != h_inode |
1facf9fc | 7808 | + || (h_inode && au_iattr_test(&ia, h_inode)))) |
7809 | + err = au_busy_or_stale(); | |
7810 | + dput(h_d); | |
7811 | + | |
4f0767ce | 7812 | +out: |
1facf9fc | 7813 | + AuTraceErr(err); |
7814 | + return err; | |
7815 | +} | |
7816 | + | |
7817 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, | |
7818 | + struct dentry *h_parent, struct au_branch *br) | |
7819 | +{ | |
7820 | + int err; | |
7821 | + | |
7822 | + err = 0; | |
027c5e7a AM |
7823 | + if (udba == AuOpt_UDBA_REVAL |
7824 | + && !au_test_fs_remote(h_dentry->d_sb)) { | |
1facf9fc | 7825 | + IMustLock(h_dir); |
5527c038 | 7826 | + err = (d_inode(h_dentry->d_parent) != h_dir); |
027c5e7a | 7827 | + } else if (udba != AuOpt_UDBA_NONE) |
1facf9fc | 7828 | + err = au_h_verify_dentry(h_dentry, h_parent, br); |
7829 | + | |
7830 | + return err; | |
7831 | +} | |
7832 | + | |
7833 | +/* ---------------------------------------------------------------------- */ | |
7834 | + | |
027c5e7a | 7835 | +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 7836 | +{ |
027c5e7a | 7837 | + int err; |
1facf9fc | 7838 | + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq; |
027c5e7a AM |
7839 | + struct au_hdentry tmp, *p, *q; |
7840 | + struct au_dinfo *dinfo; | |
7841 | + struct super_block *sb; | |
1facf9fc | 7842 | + |
027c5e7a | 7843 | + DiMustWriteLock(dentry); |
1308ab2a | 7844 | + |
027c5e7a AM |
7845 | + sb = dentry->d_sb; |
7846 | + dinfo = au_di(dentry); | |
1facf9fc | 7847 | + bend = dinfo->di_bend; |
7848 | + bwh = dinfo->di_bwh; | |
7849 | + bdiropq = dinfo->di_bdiropq; | |
027c5e7a | 7850 | + p = dinfo->di_hdentry + dinfo->di_bstart; |
1facf9fc | 7851 | + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) { |
027c5e7a | 7852 | + if (!p->hd_dentry) |
1facf9fc | 7853 | + continue; |
7854 | + | |
027c5e7a AM |
7855 | + new_bindex = au_br_index(sb, p->hd_id); |
7856 | + if (new_bindex == bindex) | |
1facf9fc | 7857 | + continue; |
1facf9fc | 7858 | + |
1facf9fc | 7859 | + if (dinfo->di_bwh == bindex) |
7860 | + bwh = new_bindex; | |
7861 | + if (dinfo->di_bdiropq == bindex) | |
7862 | + bdiropq = new_bindex; | |
7863 | + if (new_bindex < 0) { | |
7864 | + au_hdput(p); | |
7865 | + p->hd_dentry = NULL; | |
7866 | + continue; | |
7867 | + } | |
7868 | + | |
7869 | + /* swap two lower dentries, and loop again */ | |
7870 | + q = dinfo->di_hdentry + new_bindex; | |
7871 | + tmp = *q; | |
7872 | + *q = *p; | |
7873 | + *p = tmp; | |
7874 | + if (tmp.hd_dentry) { | |
7875 | + bindex--; | |
7876 | + p--; | |
7877 | + } | |
7878 | + } | |
7879 | + | |
1facf9fc | 7880 | + dinfo->di_bwh = -1; |
7881 | + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh)) | |
7882 | + dinfo->di_bwh = bwh; | |
7883 | + | |
7884 | + dinfo->di_bdiropq = -1; | |
7885 | + if (bdiropq >= 0 | |
7886 | + && bdiropq <= au_sbend(sb) | |
7887 | + && au_sbr_whable(sb, bdiropq)) | |
7888 | + dinfo->di_bdiropq = bdiropq; | |
7889 | + | |
027c5e7a AM |
7890 | + err = -EIO; |
7891 | + dinfo->di_bstart = -1; | |
7892 | + dinfo->di_bend = -1; | |
1facf9fc | 7893 | + bend = au_dbend(parent); |
7894 | + p = dinfo->di_hdentry; | |
7895 | + for (bindex = 0; bindex <= bend; bindex++, p++) | |
7896 | + if (p->hd_dentry) { | |
7897 | + dinfo->di_bstart = bindex; | |
7898 | + break; | |
7899 | + } | |
7900 | + | |
027c5e7a AM |
7901 | + if (dinfo->di_bstart >= 0) { |
7902 | + p = dinfo->di_hdentry + bend; | |
7903 | + for (bindex = bend; bindex >= 0; bindex--, p--) | |
7904 | + if (p->hd_dentry) { | |
7905 | + dinfo->di_bend = bindex; | |
7906 | + err = 0; | |
7907 | + break; | |
7908 | + } | |
7909 | + } | |
7910 | + | |
7911 | + return err; | |
1facf9fc | 7912 | +} |
7913 | + | |
027c5e7a | 7914 | +static void au_do_hide(struct dentry *dentry) |
1facf9fc | 7915 | +{ |
027c5e7a | 7916 | + struct inode *inode; |
1facf9fc | 7917 | + |
5527c038 JR |
7918 | + if (d_really_is_positive(dentry)) { |
7919 | + inode = d_inode(dentry); | |
7920 | + if (!d_is_dir(dentry)) { | |
027c5e7a AM |
7921 | + if (inode->i_nlink && !d_unhashed(dentry)) |
7922 | + drop_nlink(inode); | |
7923 | + } else { | |
7924 | + clear_nlink(inode); | |
7925 | + /* stop next lookup */ | |
7926 | + inode->i_flags |= S_DEAD; | |
7927 | + } | |
7928 | + smp_mb(); /* necessary? */ | |
7929 | + } | |
7930 | + d_drop(dentry); | |
7931 | +} | |
1308ab2a | 7932 | + |
027c5e7a AM |
7933 | +static int au_hide_children(struct dentry *parent) |
7934 | +{ | |
7935 | + int err, i, j, ndentry; | |
7936 | + struct au_dcsub_pages dpages; | |
7937 | + struct au_dpage *dpage; | |
7938 | + struct dentry *dentry; | |
1facf9fc | 7939 | + |
027c5e7a | 7940 | + err = au_dpages_init(&dpages, GFP_NOFS); |
1facf9fc | 7941 | + if (unlikely(err)) |
7942 | + goto out; | |
027c5e7a AM |
7943 | + err = au_dcsub_pages(&dpages, parent, NULL, NULL); |
7944 | + if (unlikely(err)) | |
7945 | + goto out_dpages; | |
1facf9fc | 7946 | + |
027c5e7a AM |
7947 | + /* in reverse order */ |
7948 | + for (i = dpages.ndpage - 1; i >= 0; i--) { | |
7949 | + dpage = dpages.dpages + i; | |
7950 | + ndentry = dpage->ndentry; | |
7951 | + for (j = ndentry - 1; j >= 0; j--) { | |
7952 | + dentry = dpage->dentries[j]; | |
7953 | + if (dentry != parent) | |
7954 | + au_do_hide(dentry); | |
7955 | + } | |
7956 | + } | |
1facf9fc | 7957 | + |
027c5e7a AM |
7958 | +out_dpages: |
7959 | + au_dpages_free(&dpages); | |
4f0767ce | 7960 | +out: |
027c5e7a | 7961 | + return err; |
1facf9fc | 7962 | +} |
7963 | + | |
027c5e7a | 7964 | +static void au_hide(struct dentry *dentry) |
1facf9fc | 7965 | +{ |
027c5e7a | 7966 | + int err; |
1facf9fc | 7967 | + |
027c5e7a | 7968 | + AuDbgDentry(dentry); |
2000de60 | 7969 | + if (d_is_dir(dentry)) { |
027c5e7a AM |
7970 | + /* shrink_dcache_parent(dentry); */ |
7971 | + err = au_hide_children(dentry); | |
7972 | + if (unlikely(err)) | |
523b37e3 AM |
7973 | + AuIOErr("%pd, failed hiding children, ignored %d\n", |
7974 | + dentry, err); | |
027c5e7a AM |
7975 | + } |
7976 | + au_do_hide(dentry); | |
7977 | +} | |
1facf9fc | 7978 | + |
027c5e7a AM |
7979 | +/* |
7980 | + * By adding a dirty branch, a cached dentry may be affected in various ways. | |
7981 | + * | |
7982 | + * a dirty branch is added | |
7983 | + * - on the top of layers | |
7984 | + * - in the middle of layers | |
7985 | + * - to the bottom of layers | |
7986 | + * | |
7987 | + * on the added branch there exists | |
7988 | + * - a whiteout | |
7989 | + * - a diropq | |
7990 | + * - a same named entry | |
7991 | + * + exist | |
7992 | + * * negative --> positive | |
7993 | + * * positive --> positive | |
7994 | + * - type is unchanged | |
7995 | + * - type is changed | |
7996 | + * + doesn't exist | |
7997 | + * * negative --> negative | |
7998 | + * * positive --> negative (rejected by au_br_del() for non-dir case) | |
7999 | + * - none | |
8000 | + */ | |
8001 | +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo, | |
8002 | + struct au_dinfo *tmp) | |
8003 | +{ | |
8004 | + int err; | |
8005 | + aufs_bindex_t bindex, bend; | |
8006 | + struct { | |
8007 | + struct dentry *dentry; | |
8008 | + struct inode *inode; | |
8009 | + mode_t mode; | |
8010 | + } orig_h, tmp_h; | |
8011 | + struct au_hdentry *hd; | |
8012 | + struct inode *inode, *h_inode; | |
8013 | + struct dentry *h_dentry; | |
8014 | + | |
8015 | + err = 0; | |
8016 | + AuDebugOn(dinfo->di_bstart < 0); | |
027c5e7a | 8017 | + orig_h.mode = 0; |
5527c038 JR |
8018 | + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry; |
8019 | + orig_h.inode = NULL; | |
8020 | + if (d_is_positive(orig_h.dentry)) { | |
8021 | + orig_h.inode = d_inode(orig_h.dentry); | |
027c5e7a | 8022 | + orig_h.mode = orig_h.inode->i_mode & S_IFMT; |
5527c038 | 8023 | + } |
027c5e7a AM |
8024 | + memset(&tmp_h, 0, sizeof(tmp_h)); |
8025 | + if (tmp->di_bstart >= 0) { | |
8026 | + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry; | |
5527c038 JR |
8027 | + tmp_h.inode = NULL; |
8028 | + if (d_is_positive(tmp_h.dentry)) { | |
8029 | + tmp_h.inode = d_inode(tmp_h.dentry); | |
027c5e7a | 8030 | + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT; |
5527c038 | 8031 | + } |
027c5e7a AM |
8032 | + } |
8033 | + | |
5527c038 JR |
8034 | + inode = NULL; |
8035 | + if (d_really_is_positive(dentry)) | |
8036 | + inode = d_inode(dentry); | |
027c5e7a AM |
8037 | + if (!orig_h.inode) { |
8038 | + AuDbg("nagative originally\n"); | |
8039 | + if (inode) { | |
8040 | + au_hide(dentry); | |
8041 | + goto out; | |
8042 | + } | |
8043 | + AuDebugOn(inode); | |
8044 | + AuDebugOn(dinfo->di_bstart != dinfo->di_bend); | |
8045 | + AuDebugOn(dinfo->di_bdiropq != -1); | |
8046 | + | |
8047 | + if (!tmp_h.inode) { | |
8048 | + AuDbg("negative --> negative\n"); | |
8049 | + /* should have only one negative lower */ | |
8050 | + if (tmp->di_bstart >= 0 | |
8051 | + && tmp->di_bstart < dinfo->di_bstart) { | |
8052 | + AuDebugOn(tmp->di_bstart != tmp->di_bend); | |
8053 | + AuDebugOn(dinfo->di_bstart != dinfo->di_bend); | |
8054 | + au_set_h_dptr(dentry, dinfo->di_bstart, NULL); | |
8055 | + au_di_cp(dinfo, tmp); | |
8056 | + hd = tmp->di_hdentry + tmp->di_bstart; | |
8057 | + au_set_h_dptr(dentry, tmp->di_bstart, | |
8058 | + dget(hd->hd_dentry)); | |
8059 | + } | |
8060 | + au_dbg_verify_dinode(dentry); | |
8061 | + } else { | |
8062 | + AuDbg("negative --> positive\n"); | |
8063 | + /* | |
8064 | + * similar to the behaviour of creating with bypassing | |
8065 | + * aufs. | |
8066 | + * unhash it in order to force an error in the | |
8067 | + * succeeding create operation. | |
8068 | + * we should not set S_DEAD here. | |
8069 | + */ | |
8070 | + d_drop(dentry); | |
8071 | + /* au_di_swap(tmp, dinfo); */ | |
8072 | + au_dbg_verify_dinode(dentry); | |
8073 | + } | |
8074 | + } else { | |
8075 | + AuDbg("positive originally\n"); | |
8076 | + /* inode may be NULL */ | |
8077 | + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode); | |
8078 | + if (!tmp_h.inode) { | |
8079 | + AuDbg("positive --> negative\n"); | |
8080 | + /* or bypassing aufs */ | |
8081 | + au_hide(dentry); | |
8082 | + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart) | |
8083 | + dinfo->di_bwh = tmp->di_bwh; | |
8084 | + if (inode) | |
8085 | + err = au_refresh_hinode_self(inode); | |
8086 | + au_dbg_verify_dinode(dentry); | |
8087 | + } else if (orig_h.mode == tmp_h.mode) { | |
8088 | + AuDbg("positive --> positive, same type\n"); | |
8089 | + if (!S_ISDIR(orig_h.mode) | |
8090 | + && dinfo->di_bstart > tmp->di_bstart) { | |
8091 | + /* | |
8092 | + * similar to the behaviour of removing and | |
8093 | + * creating. | |
8094 | + */ | |
8095 | + au_hide(dentry); | |
8096 | + if (inode) | |
8097 | + err = au_refresh_hinode_self(inode); | |
8098 | + au_dbg_verify_dinode(dentry); | |
8099 | + } else { | |
8100 | + /* fill empty slots */ | |
8101 | + if (dinfo->di_bstart > tmp->di_bstart) | |
8102 | + dinfo->di_bstart = tmp->di_bstart; | |
8103 | + if (dinfo->di_bend < tmp->di_bend) | |
8104 | + dinfo->di_bend = tmp->di_bend; | |
8105 | + dinfo->di_bwh = tmp->di_bwh; | |
8106 | + dinfo->di_bdiropq = tmp->di_bdiropq; | |
8107 | + hd = tmp->di_hdentry; | |
8108 | + bend = dinfo->di_bend; | |
8109 | + for (bindex = tmp->di_bstart; bindex <= bend; | |
8110 | + bindex++) { | |
8111 | + if (au_h_dptr(dentry, bindex)) | |
8112 | + continue; | |
8113 | + h_dentry = hd[bindex].hd_dentry; | |
8114 | + if (!h_dentry) | |
8115 | + continue; | |
5527c038 JR |
8116 | + AuDebugOn(d_is_negative(h_dentry)); |
8117 | + h_inode = d_inode(h_dentry); | |
027c5e7a AM |
8118 | + AuDebugOn(orig_h.mode |
8119 | + != (h_inode->i_mode | |
8120 | + & S_IFMT)); | |
8121 | + au_set_h_dptr(dentry, bindex, | |
8122 | + dget(h_dentry)); | |
8123 | + } | |
8124 | + err = au_refresh_hinode(inode, dentry); | |
8125 | + au_dbg_verify_dinode(dentry); | |
8126 | + } | |
8127 | + } else { | |
8128 | + AuDbg("positive --> positive, different type\n"); | |
8129 | + /* similar to the behaviour of removing and creating */ | |
8130 | + au_hide(dentry); | |
8131 | + if (inode) | |
8132 | + err = au_refresh_hinode_self(inode); | |
8133 | + au_dbg_verify_dinode(dentry); | |
8134 | + } | |
8135 | + } | |
8136 | + | |
8137 | +out: | |
8138 | + return err; | |
8139 | +} | |
8140 | + | |
8141 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent) | |
8142 | +{ | |
8143 | + int err, ebrange; | |
8144 | + unsigned int sigen; | |
8145 | + struct au_dinfo *dinfo, *tmp; | |
8146 | + struct super_block *sb; | |
8147 | + struct inode *inode; | |
8148 | + | |
8149 | + DiMustWriteLock(dentry); | |
8150 | + AuDebugOn(IS_ROOT(dentry)); | |
5527c038 | 8151 | + AuDebugOn(d_really_is_negative(parent)); |
027c5e7a AM |
8152 | + |
8153 | + sb = dentry->d_sb; | |
027c5e7a AM |
8154 | + sigen = au_sigen(sb); |
8155 | + err = au_digen_test(parent, sigen); | |
8156 | + if (unlikely(err)) | |
8157 | + goto out; | |
8158 | + | |
8159 | + dinfo = au_di(dentry); | |
8160 | + err = au_di_realloc(dinfo, au_sbend(sb) + 1); | |
8161 | + if (unlikely(err)) | |
8162 | + goto out; | |
8163 | + ebrange = au_dbrange_test(dentry); | |
8164 | + if (!ebrange) | |
8165 | + ebrange = au_do_refresh_hdentry(dentry, parent); | |
8166 | + | |
38d290e6 | 8167 | + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) { |
027c5e7a | 8168 | + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0); |
5527c038 JR |
8169 | + if (d_really_is_positive(dentry)) { |
8170 | + inode = d_inode(dentry); | |
027c5e7a | 8171 | + err = au_refresh_hinode_self(inode); |
5527c038 | 8172 | + } |
027c5e7a AM |
8173 | + au_dbg_verify_dinode(dentry); |
8174 | + if (!err) | |
8175 | + goto out_dgen; /* success */ | |
8176 | + goto out; | |
8177 | + } | |
8178 | + | |
8179 | + /* temporary dinfo */ | |
8180 | + AuDbgDentry(dentry); | |
8181 | + err = -ENOMEM; | |
8182 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
8183 | + if (unlikely(!tmp)) | |
8184 | + goto out; | |
8185 | + au_di_swap(tmp, dinfo); | |
8186 | + /* returns the number of positive dentries */ | |
8187 | + /* | |
8188 | + * if current working dir is removed, it returns an error. | |
8189 | + * but the dentry is legal. | |
8190 | + */ | |
537831f9 | 8191 | + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0); |
027c5e7a AM |
8192 | + AuDbgDentry(dentry); |
8193 | + au_di_swap(tmp, dinfo); | |
8194 | + if (err == -ENOENT) | |
8195 | + err = 0; | |
8196 | + if (err >= 0) { | |
8197 | + /* compare/refresh by dinfo */ | |
8198 | + AuDbgDentry(dentry); | |
8199 | + err = au_refresh_by_dinfo(dentry, dinfo, tmp); | |
8200 | + au_dbg_verify_dinode(dentry); | |
8201 | + AuTraceErr(err); | |
8202 | + } | |
8203 | + au_rw_write_unlock(&tmp->di_rwsem); | |
8204 | + au_di_free(tmp); | |
8205 | + if (unlikely(err)) | |
8206 | + goto out; | |
8207 | + | |
8208 | +out_dgen: | |
8209 | + au_update_digen(dentry); | |
8210 | +out: | |
8211 | + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) { | |
523b37e3 | 8212 | + AuIOErr("failed refreshing %pd, %d\n", dentry, err); |
027c5e7a AM |
8213 | + AuDbgDentry(dentry); |
8214 | + } | |
8215 | + AuTraceErr(err); | |
8216 | + return err; | |
8217 | +} | |
8218 | + | |
b4510431 AM |
8219 | +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags, |
8220 | + struct dentry *dentry, aufs_bindex_t bindex) | |
027c5e7a AM |
8221 | +{ |
8222 | + int err, valid; | |
027c5e7a AM |
8223 | + |
8224 | + err = 0; | |
8225 | + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE)) | |
8226 | + goto out; | |
027c5e7a AM |
8227 | + |
8228 | + AuDbg("b%d\n", bindex); | |
b4510431 AM |
8229 | + /* |
8230 | + * gave up supporting LOOKUP_CREATE/OPEN for lower fs, | |
8231 | + * due to whiteout and branch permission. | |
8232 | + */ | |
8233 | + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE | |
8234 | + | LOOKUP_FOLLOW | LOOKUP_EXCL); | |
8235 | + /* it may return tri-state */ | |
8236 | + valid = h_dentry->d_op->d_revalidate(h_dentry, flags); | |
1facf9fc | 8237 | + |
8238 | + if (unlikely(valid < 0)) | |
8239 | + err = valid; | |
8240 | + else if (!valid) | |
8241 | + err = -EINVAL; | |
8242 | + | |
4f0767ce | 8243 | +out: |
1facf9fc | 8244 | + AuTraceErr(err); |
8245 | + return err; | |
8246 | +} | |
8247 | + | |
8248 | +/* todo: remove this */ | |
8249 | +static int h_d_revalidate(struct dentry *dentry, struct inode *inode, | |
b4510431 | 8250 | + unsigned int flags, int do_udba) |
1facf9fc | 8251 | +{ |
8252 | + int err; | |
8253 | + umode_t mode, h_mode; | |
8254 | + aufs_bindex_t bindex, btail, bstart, ibs, ibe; | |
38d290e6 | 8255 | + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile; |
4a4d8108 | 8256 | + struct inode *h_inode, *h_cached_inode; |
1facf9fc | 8257 | + struct dentry *h_dentry; |
8258 | + struct qstr *name, *h_name; | |
8259 | + | |
8260 | + err = 0; | |
8261 | + plus = 0; | |
8262 | + mode = 0; | |
1facf9fc | 8263 | + ibs = -1; |
8264 | + ibe = -1; | |
8265 | + unhashed = !!d_unhashed(dentry); | |
8266 | + is_root = !!IS_ROOT(dentry); | |
8267 | + name = &dentry->d_name; | |
38d290e6 | 8268 | + tmpfile = au_di(dentry)->di_tmpfile; |
1facf9fc | 8269 | + |
8270 | + /* | |
7f207e10 AM |
8271 | + * Theoretically, REVAL test should be unnecessary in case of |
8272 | + * {FS,I}NOTIFY. | |
8273 | + * But {fs,i}notify doesn't fire some necessary events, | |
1facf9fc | 8274 | + * IN_ATTRIB for atime/nlink/pageio |
1facf9fc | 8275 | + * Let's do REVAL test too. |
8276 | + */ | |
8277 | + if (do_udba && inode) { | |
8278 | + mode = (inode->i_mode & S_IFMT); | |
8279 | + plus = (inode->i_nlink > 0); | |
1facf9fc | 8280 | + ibs = au_ibstart(inode); |
8281 | + ibe = au_ibend(inode); | |
8282 | + } | |
8283 | + | |
8284 | + bstart = au_dbstart(dentry); | |
8285 | + btail = bstart; | |
8286 | + if (inode && S_ISDIR(inode->i_mode)) | |
8287 | + btail = au_dbtaildir(dentry); | |
8288 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
8289 | + h_dentry = au_h_dptr(dentry, bindex); | |
8290 | + if (!h_dentry) | |
8291 | + continue; | |
8292 | + | |
523b37e3 AM |
8293 | + AuDbg("b%d, %pd\n", bindex, h_dentry); |
8294 | + h_nfs = !!au_test_nfs(h_dentry->d_sb); | |
027c5e7a | 8295 | + spin_lock(&h_dentry->d_lock); |
1facf9fc | 8296 | + h_name = &h_dentry->d_name; |
8297 | + if (unlikely(do_udba | |
8298 | + && !is_root | |
523b37e3 AM |
8299 | + && ((!h_nfs |
8300 | + && (unhashed != !!d_unhashed(h_dentry) | |
38d290e6 JR |
8301 | + || (!tmpfile |
8302 | + && !au_qstreq(name, h_name)) | |
8303 | + )) | |
523b37e3 AM |
8304 | + || (h_nfs |
8305 | + && !(flags & LOOKUP_OPEN) | |
8306 | + && (h_dentry->d_flags | |
8307 | + & DCACHE_NFSFS_RENAMED))) | |
1facf9fc | 8308 | + )) { |
38d290e6 JR |
8309 | + int h_unhashed; |
8310 | + | |
8311 | + h_unhashed = d_unhashed(h_dentry); | |
027c5e7a | 8312 | + spin_unlock(&h_dentry->d_lock); |
38d290e6 JR |
8313 | + AuDbg("unhash 0x%x 0x%x, %pd %pd\n", |
8314 | + unhashed, h_unhashed, dentry, h_dentry); | |
1facf9fc | 8315 | + goto err; |
8316 | + } | |
027c5e7a | 8317 | + spin_unlock(&h_dentry->d_lock); |
1facf9fc | 8318 | + |
b4510431 | 8319 | + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex); |
1facf9fc | 8320 | + if (unlikely(err)) |
8321 | + /* do not goto err, to keep the errno */ | |
8322 | + break; | |
8323 | + | |
8324 | + /* todo: plink too? */ | |
8325 | + if (!do_udba) | |
8326 | + continue; | |
8327 | + | |
8328 | + /* UDBA tests */ | |
5527c038 | 8329 | + if (unlikely(!!inode != d_is_positive(h_dentry))) |
1facf9fc | 8330 | + goto err; |
8331 | + | |
5527c038 JR |
8332 | + h_inode = NULL; |
8333 | + if (d_is_positive(h_dentry)) | |
8334 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8335 | + h_plus = plus; |
8336 | + h_mode = mode; | |
8337 | + h_cached_inode = h_inode; | |
8338 | + if (h_inode) { | |
8339 | + h_mode = (h_inode->i_mode & S_IFMT); | |
8340 | + h_plus = (h_inode->i_nlink > 0); | |
8341 | + } | |
8342 | + if (inode && ibs <= bindex && bindex <= ibe) | |
8343 | + h_cached_inode = au_h_iptr(inode, bindex); | |
8344 | + | |
523b37e3 | 8345 | + if (!h_nfs) { |
38d290e6 | 8346 | + if (unlikely(plus != h_plus && !tmpfile)) |
523b37e3 AM |
8347 | + goto err; |
8348 | + } else { | |
8349 | + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED) | |
8350 | + && !is_root | |
8351 | + && !IS_ROOT(h_dentry) | |
8352 | + && unhashed != d_unhashed(h_dentry))) | |
8353 | + goto err; | |
8354 | + } | |
8355 | + if (unlikely(mode != h_mode | |
1facf9fc | 8356 | + || h_cached_inode != h_inode)) |
8357 | + goto err; | |
8358 | + continue; | |
8359 | + | |
f6b6e03d | 8360 | +err: |
1facf9fc | 8361 | + err = -EINVAL; |
8362 | + break; | |
8363 | + } | |
8364 | + | |
523b37e3 | 8365 | + AuTraceErr(err); |
1facf9fc | 8366 | + return err; |
8367 | +} | |
8368 | + | |
027c5e7a | 8369 | +/* todo: consolidate with do_refresh() and au_reval_for_attr() */ |
1facf9fc | 8370 | +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen) |
8371 | +{ | |
8372 | + int err; | |
8373 | + struct dentry *parent; | |
1facf9fc | 8374 | + |
027c5e7a | 8375 | + if (!au_digen_test(dentry, sigen)) |
1facf9fc | 8376 | + return 0; |
8377 | + | |
8378 | + parent = dget_parent(dentry); | |
8379 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 8380 | + AuDebugOn(au_digen_test(parent, sigen)); |
1facf9fc | 8381 | + au_dbg_verify_gen(parent, sigen); |
027c5e7a | 8382 | + err = au_refresh_dentry(dentry, parent); |
1facf9fc | 8383 | + di_read_unlock(parent, AuLock_IR); |
8384 | + dput(parent); | |
027c5e7a | 8385 | + AuTraceErr(err); |
1facf9fc | 8386 | + return err; |
8387 | +} | |
8388 | + | |
8389 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen) | |
8390 | +{ | |
8391 | + int err; | |
8392 | + struct dentry *d, *parent; | |
1facf9fc | 8393 | + |
027c5e7a | 8394 | + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR)) |
1facf9fc | 8395 | + return simple_reval_dpath(dentry, sigen); |
8396 | + | |
8397 | + /* slow loop, keep it simple and stupid */ | |
8398 | + /* cf: au_cpup_dirs() */ | |
8399 | + err = 0; | |
8400 | + parent = NULL; | |
027c5e7a | 8401 | + while (au_digen_test(dentry, sigen)) { |
1facf9fc | 8402 | + d = dentry; |
8403 | + while (1) { | |
8404 | + dput(parent); | |
8405 | + parent = dget_parent(d); | |
027c5e7a | 8406 | + if (!au_digen_test(parent, sigen)) |
1facf9fc | 8407 | + break; |
8408 | + d = parent; | |
8409 | + } | |
8410 | + | |
1facf9fc | 8411 | + if (d != dentry) |
027c5e7a | 8412 | + di_write_lock_child2(d); |
1facf9fc | 8413 | + |
8414 | + /* someone might update our dentry while we were sleeping */ | |
027c5e7a AM |
8415 | + if (au_digen_test(d, sigen)) { |
8416 | + /* | |
8417 | + * todo: consolidate with simple_reval_dpath(), | |
8418 | + * do_refresh() and au_reval_for_attr(). | |
8419 | + */ | |
1facf9fc | 8420 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a | 8421 | + err = au_refresh_dentry(d, parent); |
1facf9fc | 8422 | + di_read_unlock(parent, AuLock_IR); |
8423 | + } | |
8424 | + | |
8425 | + if (d != dentry) | |
8426 | + di_write_unlock(d); | |
8427 | + dput(parent); | |
8428 | + if (unlikely(err)) | |
8429 | + break; | |
8430 | + } | |
8431 | + | |
8432 | + return err; | |
8433 | +} | |
8434 | + | |
8435 | +/* | |
8436 | + * if valid returns 1, otherwise 0. | |
8437 | + */ | |
b4510431 | 8438 | +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags) |
1facf9fc | 8439 | +{ |
8440 | + int valid, err; | |
8441 | + unsigned int sigen; | |
8442 | + unsigned char do_udba; | |
8443 | + struct super_block *sb; | |
8444 | + struct inode *inode; | |
8445 | + | |
027c5e7a | 8446 | + /* todo: support rcu-walk? */ |
b4510431 | 8447 | + if (flags & LOOKUP_RCU) |
027c5e7a AM |
8448 | + return -ECHILD; |
8449 | + | |
8450 | + valid = 0; | |
8451 | + if (unlikely(!au_di(dentry))) | |
8452 | + goto out; | |
8453 | + | |
e49829fe | 8454 | + valid = 1; |
1facf9fc | 8455 | + sb = dentry->d_sb; |
e49829fe JR |
8456 | + /* |
8457 | + * todo: very ugly | |
8458 | + * i_mutex of parent dir may be held, | |
8459 | + * but we should not return 'invalid' due to busy. | |
8460 | + */ | |
8461 | + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM); | |
8462 | + if (unlikely(err)) { | |
8463 | + valid = err; | |
027c5e7a | 8464 | + AuTraceErr(err); |
e49829fe JR |
8465 | + goto out; |
8466 | + } | |
5527c038 JR |
8467 | + inode = NULL; |
8468 | + if (d_really_is_positive(dentry)) | |
8469 | + inode = d_inode(dentry); | |
c1595e42 JR |
8470 | + if (unlikely(inode && is_bad_inode(inode))) { |
8471 | + err = -EINVAL; | |
8472 | + AuTraceErr(err); | |
8473 | + goto out_dgrade; | |
8474 | + } | |
027c5e7a AM |
8475 | + if (unlikely(au_dbrange_test(dentry))) { |
8476 | + err = -EINVAL; | |
8477 | + AuTraceErr(err); | |
8478 | + goto out_dgrade; | |
1facf9fc | 8479 | + } |
027c5e7a AM |
8480 | + |
8481 | + sigen = au_sigen(sb); | |
8482 | + if (au_digen_test(dentry, sigen)) { | |
1facf9fc | 8483 | + AuDebugOn(IS_ROOT(dentry)); |
027c5e7a AM |
8484 | + err = au_reval_dpath(dentry, sigen); |
8485 | + if (unlikely(err)) { | |
8486 | + AuTraceErr(err); | |
1facf9fc | 8487 | + goto out_dgrade; |
027c5e7a | 8488 | + } |
1facf9fc | 8489 | + } |
8490 | + di_downgrade_lock(dentry, AuLock_IR); | |
8491 | + | |
1facf9fc | 8492 | + err = -EINVAL; |
c1595e42 | 8493 | + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY)) |
523b37e3 | 8494 | + && inode |
38d290e6 | 8495 | + && !(inode->i_state && I_LINKABLE) |
523b37e3 | 8496 | + && (IS_DEADDIR(inode) || !inode->i_nlink)) |
027c5e7a AM |
8497 | + goto out_inval; |
8498 | + | |
1facf9fc | 8499 | + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE); |
8500 | + if (do_udba && inode) { | |
8501 | + aufs_bindex_t bstart = au_ibstart(inode); | |
027c5e7a | 8502 | + struct inode *h_inode; |
1facf9fc | 8503 | + |
027c5e7a AM |
8504 | + if (bstart >= 0) { |
8505 | + h_inode = au_h_iptr(inode, bstart); | |
8506 | + if (h_inode && au_test_higen(inode, h_inode)) | |
8507 | + goto out_inval; | |
8508 | + } | |
1facf9fc | 8509 | + } |
8510 | + | |
b4510431 | 8511 | + err = h_d_revalidate(dentry, inode, flags, do_udba); |
027c5e7a | 8512 | + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) { |
1facf9fc | 8513 | + err = -EIO; |
523b37e3 AM |
8514 | + AuDbg("both of real entry and whiteout found, %p, err %d\n", |
8515 | + dentry, err); | |
027c5e7a | 8516 | + } |
e49829fe | 8517 | + goto out_inval; |
1facf9fc | 8518 | + |
4f0767ce | 8519 | +out_dgrade: |
1facf9fc | 8520 | + di_downgrade_lock(dentry, AuLock_IR); |
e49829fe | 8521 | +out_inval: |
1facf9fc | 8522 | + aufs_read_unlock(dentry, AuLock_IR); |
8523 | + AuTraceErr(err); | |
8524 | + valid = !err; | |
e49829fe | 8525 | +out: |
027c5e7a | 8526 | + if (!valid) { |
523b37e3 | 8527 | + AuDbg("%pd invalid, %d\n", dentry, valid); |
027c5e7a AM |
8528 | + d_drop(dentry); |
8529 | + } | |
1facf9fc | 8530 | + return valid; |
8531 | +} | |
8532 | + | |
8533 | +static void aufs_d_release(struct dentry *dentry) | |
8534 | +{ | |
027c5e7a | 8535 | + if (au_di(dentry)) { |
4a4d8108 AM |
8536 | + au_di_fin(dentry); |
8537 | + au_hn_di_reinit(dentry); | |
1facf9fc | 8538 | + } |
1facf9fc | 8539 | +} |
8540 | + | |
4a4d8108 | 8541 | +const struct dentry_operations aufs_dop = { |
c06a8ce3 AM |
8542 | + .d_revalidate = aufs_d_revalidate, |
8543 | + .d_weak_revalidate = aufs_d_revalidate, | |
8544 | + .d_release = aufs_d_release | |
1facf9fc | 8545 | +}; |
7f207e10 AM |
8546 | diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h |
8547 | --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 8548 | +++ linux/fs/aufs/dentry.h 2015-09-24 10:47:58.251386326 +0200 |
076b876e | 8549 | @@ -0,0 +1,233 @@ |
1facf9fc | 8550 | +/* |
2000de60 | 8551 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 8552 | + * |
8553 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8554 | + * it under the terms of the GNU General Public License as published by | |
8555 | + * the Free Software Foundation; either version 2 of the License, or | |
8556 | + * (at your option) any later version. | |
dece6358 AM |
8557 | + * |
8558 | + * This program is distributed in the hope that it will be useful, | |
8559 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8560 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8561 | + * GNU General Public License for more details. | |
8562 | + * | |
8563 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8564 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8565 | + */ |
8566 | + | |
8567 | +/* | |
8568 | + * lookup and dentry operations | |
8569 | + */ | |
8570 | + | |
8571 | +#ifndef __AUFS_DENTRY_H__ | |
8572 | +#define __AUFS_DENTRY_H__ | |
8573 | + | |
8574 | +#ifdef __KERNEL__ | |
8575 | + | |
dece6358 | 8576 | +#include <linux/dcache.h> |
1facf9fc | 8577 | +#include "rwsem.h" |
8578 | + | |
1facf9fc | 8579 | +struct au_hdentry { |
8580 | + struct dentry *hd_dentry; | |
027c5e7a | 8581 | + aufs_bindex_t hd_id; |
1facf9fc | 8582 | +}; |
8583 | + | |
8584 | +struct au_dinfo { | |
8585 | + atomic_t di_generation; | |
8586 | + | |
dece6358 | 8587 | + struct au_rwsem di_rwsem; |
1facf9fc | 8588 | + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq; |
38d290e6 | 8589 | + unsigned char di_tmpfile; /* to allow the different name */ |
1facf9fc | 8590 | + struct au_hdentry *di_hdentry; |
4a4d8108 | 8591 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 8592 | + |
8593 | +/* ---------------------------------------------------------------------- */ | |
8594 | + | |
8595 | +/* dentry.c */ | |
4a4d8108 | 8596 | +extern const struct dentry_operations aufs_dop; |
1facf9fc | 8597 | +struct au_branch; |
076b876e | 8598 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent); |
1facf9fc | 8599 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, |
8600 | + struct dentry *h_parent, struct au_branch *br); | |
8601 | + | |
537831f9 | 8602 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type); |
86dc4139 | 8603 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh); |
027c5e7a | 8604 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent); |
1facf9fc | 8605 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen); |
8606 | + | |
8607 | +/* dinfo.c */ | |
4a4d8108 | 8608 | +void au_di_init_once(void *_di); |
027c5e7a AM |
8609 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc); |
8610 | +void au_di_free(struct au_dinfo *dinfo); | |
8611 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b); | |
8612 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src); | |
4a4d8108 AM |
8613 | +int au_di_init(struct dentry *dentry); |
8614 | +void au_di_fin(struct dentry *dentry); | |
1facf9fc | 8615 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr); |
8616 | + | |
8617 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc); | |
8618 | +void di_read_unlock(struct dentry *d, int flags); | |
8619 | +void di_downgrade_lock(struct dentry *d, int flags); | |
8620 | +void di_write_lock(struct dentry *d, unsigned int lsc); | |
8621 | +void di_write_unlock(struct dentry *d); | |
8622 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir); | |
8623 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir); | |
8624 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2); | |
8625 | + | |
8626 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex); | |
2cbb1c4b | 8627 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex); |
1facf9fc | 8628 | +aufs_bindex_t au_dbtail(struct dentry *dentry); |
8629 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry); | |
8630 | + | |
8631 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
8632 | + struct dentry *h_dentry); | |
027c5e7a AM |
8633 | +int au_digen_test(struct dentry *dentry, unsigned int sigen); |
8634 | +int au_dbrange_test(struct dentry *dentry); | |
1facf9fc | 8635 | +void au_update_digen(struct dentry *dentry); |
8636 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero); | |
8637 | +void au_update_dbstart(struct dentry *dentry); | |
8638 | +void au_update_dbend(struct dentry *dentry); | |
8639 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry); | |
8640 | + | |
8641 | +/* ---------------------------------------------------------------------- */ | |
8642 | + | |
8643 | +static inline struct au_dinfo *au_di(struct dentry *dentry) | |
8644 | +{ | |
8645 | + return dentry->d_fsdata; | |
8646 | +} | |
8647 | + | |
8648 | +/* ---------------------------------------------------------------------- */ | |
8649 | + | |
8650 | +/* lock subclass for dinfo */ | |
8651 | +enum { | |
8652 | + AuLsc_DI_CHILD, /* child first */ | |
4a4d8108 | 8653 | + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */ |
1facf9fc | 8654 | + AuLsc_DI_CHILD3, /* copyup dirs */ |
8655 | + AuLsc_DI_PARENT, | |
8656 | + AuLsc_DI_PARENT2, | |
027c5e7a AM |
8657 | + AuLsc_DI_PARENT3, |
8658 | + AuLsc_DI_TMP /* temp for replacing dinfo */ | |
1facf9fc | 8659 | +}; |
8660 | + | |
8661 | +/* | |
8662 | + * di_read_lock_child, di_write_lock_child, | |
8663 | + * di_read_lock_child2, di_write_lock_child2, | |
8664 | + * di_read_lock_child3, di_write_lock_child3, | |
8665 | + * di_read_lock_parent, di_write_lock_parent, | |
8666 | + * di_read_lock_parent2, di_write_lock_parent2, | |
8667 | + * di_read_lock_parent3, di_write_lock_parent3, | |
8668 | + */ | |
8669 | +#define AuReadLockFunc(name, lsc) \ | |
8670 | +static inline void di_read_lock_##name(struct dentry *d, int flags) \ | |
8671 | +{ di_read_lock(d, flags, AuLsc_DI_##lsc); } | |
8672 | + | |
8673 | +#define AuWriteLockFunc(name, lsc) \ | |
8674 | +static inline void di_write_lock_##name(struct dentry *d) \ | |
8675 | +{ di_write_lock(d, AuLsc_DI_##lsc); } | |
8676 | + | |
8677 | +#define AuRWLockFuncs(name, lsc) \ | |
8678 | + AuReadLockFunc(name, lsc) \ | |
8679 | + AuWriteLockFunc(name, lsc) | |
8680 | + | |
8681 | +AuRWLockFuncs(child, CHILD); | |
8682 | +AuRWLockFuncs(child2, CHILD2); | |
8683 | +AuRWLockFuncs(child3, CHILD3); | |
8684 | +AuRWLockFuncs(parent, PARENT); | |
8685 | +AuRWLockFuncs(parent2, PARENT2); | |
8686 | +AuRWLockFuncs(parent3, PARENT3); | |
8687 | + | |
8688 | +#undef AuReadLockFunc | |
8689 | +#undef AuWriteLockFunc | |
8690 | +#undef AuRWLockFuncs | |
8691 | + | |
8692 | +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem) | |
dece6358 AM |
8693 | +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem) |
8694 | +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem) | |
1facf9fc | 8695 | + |
8696 | +/* ---------------------------------------------------------------------- */ | |
8697 | + | |
8698 | +/* todo: memory barrier? */ | |
8699 | +static inline unsigned int au_digen(struct dentry *d) | |
8700 | +{ | |
8701 | + return atomic_read(&au_di(d)->di_generation); | |
8702 | +} | |
8703 | + | |
8704 | +static inline void au_h_dentry_init(struct au_hdentry *hdentry) | |
8705 | +{ | |
8706 | + hdentry->hd_dentry = NULL; | |
8707 | +} | |
8708 | + | |
8709 | +static inline void au_hdput(struct au_hdentry *hd) | |
8710 | +{ | |
4a4d8108 AM |
8711 | + if (hd) |
8712 | + dput(hd->hd_dentry); | |
1facf9fc | 8713 | +} |
8714 | + | |
8715 | +static inline aufs_bindex_t au_dbstart(struct dentry *dentry) | |
8716 | +{ | |
1308ab2a | 8717 | + DiMustAnyLock(dentry); |
1facf9fc | 8718 | + return au_di(dentry)->di_bstart; |
8719 | +} | |
8720 | + | |
8721 | +static inline aufs_bindex_t au_dbend(struct dentry *dentry) | |
8722 | +{ | |
1308ab2a | 8723 | + DiMustAnyLock(dentry); |
1facf9fc | 8724 | + return au_di(dentry)->di_bend; |
8725 | +} | |
8726 | + | |
8727 | +static inline aufs_bindex_t au_dbwh(struct dentry *dentry) | |
8728 | +{ | |
1308ab2a | 8729 | + DiMustAnyLock(dentry); |
1facf9fc | 8730 | + return au_di(dentry)->di_bwh; |
8731 | +} | |
8732 | + | |
8733 | +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry) | |
8734 | +{ | |
1308ab2a | 8735 | + DiMustAnyLock(dentry); |
1facf9fc | 8736 | + return au_di(dentry)->di_bdiropq; |
8737 | +} | |
8738 | + | |
8739 | +/* todo: hard/soft set? */ | |
8740 | +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex) | |
8741 | +{ | |
1308ab2a | 8742 | + DiMustWriteLock(dentry); |
1facf9fc | 8743 | + au_di(dentry)->di_bstart = bindex; |
8744 | +} | |
8745 | + | |
8746 | +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex) | |
8747 | +{ | |
1308ab2a | 8748 | + DiMustWriteLock(dentry); |
1facf9fc | 8749 | + au_di(dentry)->di_bend = bindex; |
8750 | +} | |
8751 | + | |
8752 | +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex) | |
8753 | +{ | |
1308ab2a | 8754 | + DiMustWriteLock(dentry); |
1facf9fc | 8755 | + /* dbwh can be outside of bstart - bend range */ |
8756 | + au_di(dentry)->di_bwh = bindex; | |
8757 | +} | |
8758 | + | |
8759 | +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex) | |
8760 | +{ | |
1308ab2a | 8761 | + DiMustWriteLock(dentry); |
1facf9fc | 8762 | + au_di(dentry)->di_bdiropq = bindex; |
8763 | +} | |
8764 | + | |
8765 | +/* ---------------------------------------------------------------------- */ | |
8766 | + | |
4a4d8108 | 8767 | +#ifdef CONFIG_AUFS_HNOTIFY |
1facf9fc | 8768 | +static inline void au_digen_dec(struct dentry *d) |
8769 | +{ | |
e49829fe | 8770 | + atomic_dec(&au_di(d)->di_generation); |
1facf9fc | 8771 | +} |
8772 | + | |
4a4d8108 | 8773 | +static inline void au_hn_di_reinit(struct dentry *dentry) |
1facf9fc | 8774 | +{ |
8775 | + dentry->d_fsdata = NULL; | |
8776 | +} | |
8777 | +#else | |
4a4d8108 AM |
8778 | +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused) |
8779 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
1facf9fc | 8780 | + |
8781 | +#endif /* __KERNEL__ */ | |
8782 | +#endif /* __AUFS_DENTRY_H__ */ | |
7f207e10 AM |
8783 | diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c |
8784 | --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 8785 | +++ linux/fs/aufs/dinfo.c 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 8786 | @@ -0,0 +1,550 @@ |
1facf9fc | 8787 | +/* |
2000de60 | 8788 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 8789 | + * |
8790 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8791 | + * it under the terms of the GNU General Public License as published by | |
8792 | + * the Free Software Foundation; either version 2 of the License, or | |
8793 | + * (at your option) any later version. | |
dece6358 AM |
8794 | + * |
8795 | + * This program is distributed in the hope that it will be useful, | |
8796 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8797 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8798 | + * GNU General Public License for more details. | |
8799 | + * | |
8800 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8801 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8802 | + */ |
8803 | + | |
8804 | +/* | |
8805 | + * dentry private data | |
8806 | + */ | |
8807 | + | |
8808 | +#include "aufs.h" | |
8809 | + | |
e49829fe | 8810 | +void au_di_init_once(void *_dinfo) |
4a4d8108 | 8811 | +{ |
e49829fe JR |
8812 | + struct au_dinfo *dinfo = _dinfo; |
8813 | + static struct lock_class_key aufs_di; | |
4a4d8108 | 8814 | + |
e49829fe JR |
8815 | + au_rw_init(&dinfo->di_rwsem); |
8816 | + au_rw_class(&dinfo->di_rwsem, &aufs_di); | |
4a4d8108 AM |
8817 | +} |
8818 | + | |
027c5e7a | 8819 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc) |
1facf9fc | 8820 | +{ |
8821 | + struct au_dinfo *dinfo; | |
027c5e7a | 8822 | + int nbr, i; |
1facf9fc | 8823 | + |
8824 | + dinfo = au_cache_alloc_dinfo(); | |
8825 | + if (unlikely(!dinfo)) | |
8826 | + goto out; | |
8827 | + | |
1facf9fc | 8828 | + nbr = au_sbend(sb) + 1; |
8829 | + if (nbr <= 0) | |
8830 | + nbr = 1; | |
8831 | + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS); | |
027c5e7a AM |
8832 | + if (dinfo->di_hdentry) { |
8833 | + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc); | |
8834 | + dinfo->di_bstart = -1; | |
8835 | + dinfo->di_bend = -1; | |
8836 | + dinfo->di_bwh = -1; | |
8837 | + dinfo->di_bdiropq = -1; | |
38d290e6 | 8838 | + dinfo->di_tmpfile = 0; |
027c5e7a AM |
8839 | + for (i = 0; i < nbr; i++) |
8840 | + dinfo->di_hdentry[i].hd_id = -1; | |
8841 | + goto out; | |
8842 | + } | |
1facf9fc | 8843 | + |
1facf9fc | 8844 | + au_cache_free_dinfo(dinfo); |
027c5e7a AM |
8845 | + dinfo = NULL; |
8846 | + | |
4f0767ce | 8847 | +out: |
027c5e7a | 8848 | + return dinfo; |
1facf9fc | 8849 | +} |
8850 | + | |
027c5e7a | 8851 | +void au_di_free(struct au_dinfo *dinfo) |
4a4d8108 | 8852 | +{ |
4a4d8108 AM |
8853 | + struct au_hdentry *p; |
8854 | + aufs_bindex_t bend, bindex; | |
8855 | + | |
8856 | + /* dentry may not be revalidated */ | |
027c5e7a | 8857 | + bindex = dinfo->di_bstart; |
4a4d8108 | 8858 | + if (bindex >= 0) { |
027c5e7a AM |
8859 | + bend = dinfo->di_bend; |
8860 | + p = dinfo->di_hdentry + bindex; | |
4a4d8108 AM |
8861 | + while (bindex++ <= bend) |
8862 | + au_hdput(p++); | |
8863 | + } | |
027c5e7a AM |
8864 | + kfree(dinfo->di_hdentry); |
8865 | + au_cache_free_dinfo(dinfo); | |
8866 | +} | |
8867 | + | |
8868 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b) | |
8869 | +{ | |
8870 | + struct au_hdentry *p; | |
8871 | + aufs_bindex_t bi; | |
8872 | + | |
8873 | + AuRwMustWriteLock(&a->di_rwsem); | |
8874 | + AuRwMustWriteLock(&b->di_rwsem); | |
8875 | + | |
8876 | +#define DiSwap(v, name) \ | |
8877 | + do { \ | |
8878 | + v = a->di_##name; \ | |
8879 | + a->di_##name = b->di_##name; \ | |
8880 | + b->di_##name = v; \ | |
8881 | + } while (0) | |
8882 | + | |
8883 | + DiSwap(p, hdentry); | |
8884 | + DiSwap(bi, bstart); | |
8885 | + DiSwap(bi, bend); | |
8886 | + DiSwap(bi, bwh); | |
8887 | + DiSwap(bi, bdiropq); | |
8888 | + /* smp_mb(); */ | |
8889 | + | |
8890 | +#undef DiSwap | |
8891 | +} | |
8892 | + | |
8893 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src) | |
8894 | +{ | |
8895 | + AuRwMustWriteLock(&dst->di_rwsem); | |
8896 | + AuRwMustWriteLock(&src->di_rwsem); | |
8897 | + | |
8898 | + dst->di_bstart = src->di_bstart; | |
8899 | + dst->di_bend = src->di_bend; | |
8900 | + dst->di_bwh = src->di_bwh; | |
8901 | + dst->di_bdiropq = src->di_bdiropq; | |
8902 | + /* smp_mb(); */ | |
8903 | +} | |
8904 | + | |
8905 | +int au_di_init(struct dentry *dentry) | |
8906 | +{ | |
8907 | + int err; | |
8908 | + struct super_block *sb; | |
8909 | + struct au_dinfo *dinfo; | |
8910 | + | |
8911 | + err = 0; | |
8912 | + sb = dentry->d_sb; | |
8913 | + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD); | |
8914 | + if (dinfo) { | |
8915 | + atomic_set(&dinfo->di_generation, au_sigen(sb)); | |
8916 | + /* smp_mb(); */ /* atomic_set */ | |
8917 | + dentry->d_fsdata = dinfo; | |
8918 | + } else | |
8919 | + err = -ENOMEM; | |
8920 | + | |
8921 | + return err; | |
8922 | +} | |
8923 | + | |
8924 | +void au_di_fin(struct dentry *dentry) | |
8925 | +{ | |
8926 | + struct au_dinfo *dinfo; | |
8927 | + | |
8928 | + dinfo = au_di(dentry); | |
8929 | + AuRwDestroy(&dinfo->di_rwsem); | |
8930 | + au_di_free(dinfo); | |
4a4d8108 AM |
8931 | +} |
8932 | + | |
1facf9fc | 8933 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr) |
8934 | +{ | |
8935 | + int err, sz; | |
8936 | + struct au_hdentry *hdp; | |
8937 | + | |
1308ab2a | 8938 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
8939 | + | |
1facf9fc | 8940 | + err = -ENOMEM; |
8941 | + sz = sizeof(*hdp) * (dinfo->di_bend + 1); | |
8942 | + if (!sz) | |
8943 | + sz = sizeof(*hdp); | |
8944 | + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS); | |
8945 | + if (hdp) { | |
8946 | + dinfo->di_hdentry = hdp; | |
8947 | + err = 0; | |
8948 | + } | |
8949 | + | |
8950 | + return err; | |
8951 | +} | |
8952 | + | |
8953 | +/* ---------------------------------------------------------------------- */ | |
8954 | + | |
8955 | +static void do_ii_write_lock(struct inode *inode, unsigned int lsc) | |
8956 | +{ | |
8957 | + switch (lsc) { | |
8958 | + case AuLsc_DI_CHILD: | |
8959 | + ii_write_lock_child(inode); | |
8960 | + break; | |
8961 | + case AuLsc_DI_CHILD2: | |
8962 | + ii_write_lock_child2(inode); | |
8963 | + break; | |
8964 | + case AuLsc_DI_CHILD3: | |
8965 | + ii_write_lock_child3(inode); | |
8966 | + break; | |
8967 | + case AuLsc_DI_PARENT: | |
8968 | + ii_write_lock_parent(inode); | |
8969 | + break; | |
8970 | + case AuLsc_DI_PARENT2: | |
8971 | + ii_write_lock_parent2(inode); | |
8972 | + break; | |
8973 | + case AuLsc_DI_PARENT3: | |
8974 | + ii_write_lock_parent3(inode); | |
8975 | + break; | |
8976 | + default: | |
8977 | + BUG(); | |
8978 | + } | |
8979 | +} | |
8980 | + | |
8981 | +static void do_ii_read_lock(struct inode *inode, unsigned int lsc) | |
8982 | +{ | |
8983 | + switch (lsc) { | |
8984 | + case AuLsc_DI_CHILD: | |
8985 | + ii_read_lock_child(inode); | |
8986 | + break; | |
8987 | + case AuLsc_DI_CHILD2: | |
8988 | + ii_read_lock_child2(inode); | |
8989 | + break; | |
8990 | + case AuLsc_DI_CHILD3: | |
8991 | + ii_read_lock_child3(inode); | |
8992 | + break; | |
8993 | + case AuLsc_DI_PARENT: | |
8994 | + ii_read_lock_parent(inode); | |
8995 | + break; | |
8996 | + case AuLsc_DI_PARENT2: | |
8997 | + ii_read_lock_parent2(inode); | |
8998 | + break; | |
8999 | + case AuLsc_DI_PARENT3: | |
9000 | + ii_read_lock_parent3(inode); | |
9001 | + break; | |
9002 | + default: | |
9003 | + BUG(); | |
9004 | + } | |
9005 | +} | |
9006 | + | |
9007 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc) | |
9008 | +{ | |
5527c038 JR |
9009 | + struct inode *inode; |
9010 | + | |
dece6358 | 9011 | + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9012 | + if (d_really_is_positive(d)) { |
9013 | + inode = d_inode(d); | |
1facf9fc | 9014 | + if (au_ftest_lock(flags, IW)) |
5527c038 | 9015 | + do_ii_write_lock(inode, lsc); |
1facf9fc | 9016 | + else if (au_ftest_lock(flags, IR)) |
5527c038 | 9017 | + do_ii_read_lock(inode, lsc); |
1facf9fc | 9018 | + } |
9019 | +} | |
9020 | + | |
9021 | +void di_read_unlock(struct dentry *d, int flags) | |
9022 | +{ | |
5527c038 JR |
9023 | + struct inode *inode; |
9024 | + | |
9025 | + if (d_really_is_positive(d)) { | |
9026 | + inode = d_inode(d); | |
027c5e7a AM |
9027 | + if (au_ftest_lock(flags, IW)) { |
9028 | + au_dbg_verify_dinode(d); | |
5527c038 | 9029 | + ii_write_unlock(inode); |
027c5e7a AM |
9030 | + } else if (au_ftest_lock(flags, IR)) { |
9031 | + au_dbg_verify_dinode(d); | |
5527c038 | 9032 | + ii_read_unlock(inode); |
027c5e7a | 9033 | + } |
1facf9fc | 9034 | + } |
dece6358 | 9035 | + au_rw_read_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9036 | +} |
9037 | + | |
9038 | +void di_downgrade_lock(struct dentry *d, int flags) | |
9039 | +{ | |
5527c038 JR |
9040 | + if (d_really_is_positive(d) && au_ftest_lock(flags, IR)) |
9041 | + ii_downgrade_lock(d_inode(d)); | |
dece6358 | 9042 | + au_rw_dgrade_lock(&au_di(d)->di_rwsem); |
1facf9fc | 9043 | +} |
9044 | + | |
9045 | +void di_write_lock(struct dentry *d, unsigned int lsc) | |
9046 | +{ | |
dece6358 | 9047 | + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9048 | + if (d_really_is_positive(d)) |
9049 | + do_ii_write_lock(d_inode(d), lsc); | |
1facf9fc | 9050 | +} |
9051 | + | |
9052 | +void di_write_unlock(struct dentry *d) | |
9053 | +{ | |
027c5e7a | 9054 | + au_dbg_verify_dinode(d); |
5527c038 JR |
9055 | + if (d_really_is_positive(d)) |
9056 | + ii_write_unlock(d_inode(d)); | |
dece6358 | 9057 | + au_rw_write_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9058 | +} |
9059 | + | |
9060 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir) | |
9061 | +{ | |
9062 | + AuDebugOn(d1 == d2 | |
5527c038 | 9063 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9064 | + || d1->d_sb != d2->d_sb); |
9065 | + | |
9066 | + if (isdir && au_test_subdir(d1, d2)) { | |
9067 | + di_write_lock_child(d1); | |
9068 | + di_write_lock_child2(d2); | |
9069 | + } else { | |
9070 | + /* there should be no races */ | |
9071 | + di_write_lock_child(d2); | |
9072 | + di_write_lock_child2(d1); | |
9073 | + } | |
9074 | +} | |
9075 | + | |
9076 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir) | |
9077 | +{ | |
9078 | + AuDebugOn(d1 == d2 | |
5527c038 | 9079 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9080 | + || d1->d_sb != d2->d_sb); |
9081 | + | |
9082 | + if (isdir && au_test_subdir(d1, d2)) { | |
9083 | + di_write_lock_parent(d1); | |
9084 | + di_write_lock_parent2(d2); | |
9085 | + } else { | |
9086 | + /* there should be no races */ | |
9087 | + di_write_lock_parent(d2); | |
9088 | + di_write_lock_parent2(d1); | |
9089 | + } | |
9090 | +} | |
9091 | + | |
9092 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2) | |
9093 | +{ | |
9094 | + di_write_unlock(d1); | |
5527c038 | 9095 | + if (d_inode(d1) == d_inode(d2)) |
dece6358 | 9096 | + au_rw_write_unlock(&au_di(d2)->di_rwsem); |
1facf9fc | 9097 | + else |
9098 | + di_write_unlock(d2); | |
9099 | +} | |
9100 | + | |
9101 | +/* ---------------------------------------------------------------------- */ | |
9102 | + | |
9103 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex) | |
9104 | +{ | |
9105 | + struct dentry *d; | |
9106 | + | |
1308ab2a | 9107 | + DiMustAnyLock(dentry); |
9108 | + | |
1facf9fc | 9109 | + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry)) |
9110 | + return NULL; | |
9111 | + AuDebugOn(bindex < 0); | |
9112 | + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry; | |
c1595e42 | 9113 | + AuDebugOn(d && au_dcount(d) <= 0); |
1facf9fc | 9114 | + return d; |
9115 | +} | |
9116 | + | |
2cbb1c4b JR |
9117 | +/* |
9118 | + * extended version of au_h_dptr(). | |
38d290e6 JR |
9119 | + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or |
9120 | + * error. | |
2cbb1c4b JR |
9121 | + */ |
9122 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex) | |
9123 | +{ | |
9124 | + struct dentry *h_dentry; | |
9125 | + struct inode *inode, *h_inode; | |
9126 | + | |
5527c038 | 9127 | + AuDebugOn(d_really_is_negative(dentry)); |
2cbb1c4b JR |
9128 | + |
9129 | + h_dentry = NULL; | |
9130 | + if (au_dbstart(dentry) <= bindex | |
9131 | + && bindex <= au_dbend(dentry)) | |
9132 | + h_dentry = au_h_dptr(dentry, bindex); | |
38d290e6 | 9133 | + if (h_dentry && !au_d_linkable(h_dentry)) { |
2cbb1c4b JR |
9134 | + dget(h_dentry); |
9135 | + goto out; /* success */ | |
9136 | + } | |
9137 | + | |
5527c038 | 9138 | + inode = d_inode(dentry); |
2cbb1c4b JR |
9139 | + AuDebugOn(bindex < au_ibstart(inode)); |
9140 | + AuDebugOn(au_ibend(inode) < bindex); | |
9141 | + h_inode = au_h_iptr(inode, bindex); | |
9142 | + h_dentry = d_find_alias(h_inode); | |
9143 | + if (h_dentry) { | |
9144 | + if (!IS_ERR(h_dentry)) { | |
38d290e6 | 9145 | + if (!au_d_linkable(h_dentry)) |
2cbb1c4b JR |
9146 | + goto out; /* success */ |
9147 | + dput(h_dentry); | |
9148 | + } else | |
9149 | + goto out; | |
9150 | + } | |
9151 | + | |
9152 | + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) { | |
9153 | + h_dentry = au_plink_lkup(inode, bindex); | |
9154 | + AuDebugOn(!h_dentry); | |
9155 | + if (!IS_ERR(h_dentry)) { | |
9156 | + if (!au_d_hashed_positive(h_dentry)) | |
9157 | + goto out; /* success */ | |
9158 | + dput(h_dentry); | |
9159 | + h_dentry = NULL; | |
9160 | + } | |
9161 | + } | |
9162 | + | |
9163 | +out: | |
9164 | + AuDbgDentry(h_dentry); | |
9165 | + return h_dentry; | |
9166 | +} | |
9167 | + | |
1facf9fc | 9168 | +aufs_bindex_t au_dbtail(struct dentry *dentry) |
9169 | +{ | |
9170 | + aufs_bindex_t bend, bwh; | |
9171 | + | |
9172 | + bend = au_dbend(dentry); | |
9173 | + if (0 <= bend) { | |
9174 | + bwh = au_dbwh(dentry); | |
9175 | + if (!bwh) | |
9176 | + return bwh; | |
9177 | + if (0 < bwh && bwh < bend) | |
9178 | + return bwh - 1; | |
9179 | + } | |
9180 | + return bend; | |
9181 | +} | |
9182 | + | |
9183 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry) | |
9184 | +{ | |
9185 | + aufs_bindex_t bend, bopq; | |
9186 | + | |
9187 | + bend = au_dbtail(dentry); | |
9188 | + if (0 <= bend) { | |
9189 | + bopq = au_dbdiropq(dentry); | |
9190 | + if (0 <= bopq && bopq < bend) | |
9191 | + bend = bopq; | |
9192 | + } | |
9193 | + return bend; | |
9194 | +} | |
9195 | + | |
9196 | +/* ---------------------------------------------------------------------- */ | |
9197 | + | |
9198 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9199 | + struct dentry *h_dentry) | |
9200 | +{ | |
9201 | + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex; | |
027c5e7a | 9202 | + struct au_branch *br; |
1facf9fc | 9203 | + |
1308ab2a | 9204 | + DiMustWriteLock(dentry); |
9205 | + | |
4a4d8108 | 9206 | + au_hdput(hd); |
1facf9fc | 9207 | + hd->hd_dentry = h_dentry; |
027c5e7a AM |
9208 | + if (h_dentry) { |
9209 | + br = au_sbr(dentry->d_sb, bindex); | |
9210 | + hd->hd_id = br->br_id; | |
9211 | + } | |
9212 | +} | |
9213 | + | |
9214 | +int au_dbrange_test(struct dentry *dentry) | |
9215 | +{ | |
9216 | + int err; | |
9217 | + aufs_bindex_t bstart, bend; | |
9218 | + | |
9219 | + err = 0; | |
9220 | + bstart = au_dbstart(dentry); | |
9221 | + bend = au_dbend(dentry); | |
9222 | + if (bstart >= 0) | |
9223 | + AuDebugOn(bend < 0 && bstart > bend); | |
9224 | + else { | |
9225 | + err = -EIO; | |
9226 | + AuDebugOn(bend >= 0); | |
9227 | + } | |
9228 | + | |
9229 | + return err; | |
9230 | +} | |
9231 | + | |
9232 | +int au_digen_test(struct dentry *dentry, unsigned int sigen) | |
9233 | +{ | |
9234 | + int err; | |
9235 | + | |
9236 | + err = 0; | |
9237 | + if (unlikely(au_digen(dentry) != sigen | |
5527c038 | 9238 | + || au_iigen_test(d_inode(dentry), sigen))) |
027c5e7a AM |
9239 | + err = -EIO; |
9240 | + | |
9241 | + return err; | |
1facf9fc | 9242 | +} |
9243 | + | |
9244 | +void au_update_digen(struct dentry *dentry) | |
9245 | +{ | |
9246 | + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb)); | |
9247 | + /* smp_mb(); */ /* atomic_set */ | |
9248 | +} | |
9249 | + | |
9250 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero) | |
9251 | +{ | |
9252 | + struct au_dinfo *dinfo; | |
9253 | + struct dentry *h_d; | |
4a4d8108 | 9254 | + struct au_hdentry *hdp; |
1facf9fc | 9255 | + |
1308ab2a | 9256 | + DiMustWriteLock(dentry); |
9257 | + | |
1facf9fc | 9258 | + dinfo = au_di(dentry); |
9259 | + if (!dinfo || dinfo->di_bstart < 0) | |
9260 | + return; | |
9261 | + | |
4a4d8108 | 9262 | + hdp = dinfo->di_hdentry; |
1facf9fc | 9263 | + if (do_put_zero) { |
9264 | + aufs_bindex_t bindex, bend; | |
9265 | + | |
9266 | + bend = dinfo->di_bend; | |
9267 | + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) { | |
4a4d8108 | 9268 | + h_d = hdp[0 + bindex].hd_dentry; |
5527c038 | 9269 | + if (h_d && d_is_negative(h_d)) |
1facf9fc | 9270 | + au_set_h_dptr(dentry, bindex, NULL); |
9271 | + } | |
9272 | + } | |
9273 | + | |
9274 | + dinfo->di_bstart = -1; | |
9275 | + while (++dinfo->di_bstart <= dinfo->di_bend) | |
4a4d8108 | 9276 | + if (hdp[0 + dinfo->di_bstart].hd_dentry) |
1facf9fc | 9277 | + break; |
9278 | + if (dinfo->di_bstart > dinfo->di_bend) { | |
9279 | + dinfo->di_bstart = -1; | |
9280 | + dinfo->di_bend = -1; | |
9281 | + return; | |
9282 | + } | |
9283 | + | |
9284 | + dinfo->di_bend++; | |
9285 | + while (0 <= --dinfo->di_bend) | |
4a4d8108 | 9286 | + if (hdp[0 + dinfo->di_bend].hd_dentry) |
1facf9fc | 9287 | + break; |
9288 | + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0); | |
9289 | +} | |
9290 | + | |
9291 | +void au_update_dbstart(struct dentry *dentry) | |
9292 | +{ | |
9293 | + aufs_bindex_t bindex, bend; | |
9294 | + struct dentry *h_dentry; | |
9295 | + | |
9296 | + bend = au_dbend(dentry); | |
9297 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) { | |
9298 | + h_dentry = au_h_dptr(dentry, bindex); | |
9299 | + if (!h_dentry) | |
9300 | + continue; | |
5527c038 | 9301 | + if (d_is_positive(h_dentry)) { |
1facf9fc | 9302 | + au_set_dbstart(dentry, bindex); |
9303 | + return; | |
9304 | + } | |
9305 | + au_set_h_dptr(dentry, bindex, NULL); | |
9306 | + } | |
9307 | +} | |
9308 | + | |
9309 | +void au_update_dbend(struct dentry *dentry) | |
9310 | +{ | |
9311 | + aufs_bindex_t bindex, bstart; | |
9312 | + struct dentry *h_dentry; | |
9313 | + | |
9314 | + bstart = au_dbstart(dentry); | |
7f207e10 | 9315 | + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) { |
1facf9fc | 9316 | + h_dentry = au_h_dptr(dentry, bindex); |
9317 | + if (!h_dentry) | |
9318 | + continue; | |
5527c038 | 9319 | + if (d_is_positive(h_dentry)) { |
1facf9fc | 9320 | + au_set_dbend(dentry, bindex); |
9321 | + return; | |
9322 | + } | |
9323 | + au_set_h_dptr(dentry, bindex, NULL); | |
9324 | + } | |
9325 | +} | |
9326 | + | |
9327 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry) | |
9328 | +{ | |
9329 | + aufs_bindex_t bindex, bend; | |
9330 | + | |
9331 | + bend = au_dbend(dentry); | |
9332 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) | |
9333 | + if (au_h_dptr(dentry, bindex) == h_dentry) | |
9334 | + return bindex; | |
9335 | + return -1; | |
9336 | +} | |
7f207e10 AM |
9337 | diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c |
9338 | --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 9339 | +++ linux/fs/aufs/dir.c 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 9340 | @@ -0,0 +1,753 @@ |
1facf9fc | 9341 | +/* |
2000de60 | 9342 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 9343 | + * |
9344 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9345 | + * it under the terms of the GNU General Public License as published by | |
9346 | + * the Free Software Foundation; either version 2 of the License, or | |
9347 | + * (at your option) any later version. | |
dece6358 AM |
9348 | + * |
9349 | + * This program is distributed in the hope that it will be useful, | |
9350 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9351 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9352 | + * GNU General Public License for more details. | |
9353 | + * | |
9354 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9355 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9356 | + */ |
9357 | + | |
9358 | +/* | |
9359 | + * directory operations | |
9360 | + */ | |
9361 | + | |
9362 | +#include <linux/fs_stack.h> | |
9363 | +#include "aufs.h" | |
9364 | + | |
9365 | +void au_add_nlink(struct inode *dir, struct inode *h_dir) | |
9366 | +{ | |
9dbd164d AM |
9367 | + unsigned int nlink; |
9368 | + | |
1facf9fc | 9369 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9370 | + | |
9dbd164d AM |
9371 | + nlink = dir->i_nlink; |
9372 | + nlink += h_dir->i_nlink - 2; | |
1facf9fc | 9373 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9374 | + nlink += 2; |
f6b6e03d | 9375 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 9376 | + /* 0 can happen in revaliding */ |
92d182d2 | 9377 | + set_nlink(dir, nlink); |
1facf9fc | 9378 | +} |
9379 | + | |
9380 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir) | |
9381 | +{ | |
9dbd164d AM |
9382 | + unsigned int nlink; |
9383 | + | |
1facf9fc | 9384 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9385 | + | |
9dbd164d AM |
9386 | + nlink = dir->i_nlink; |
9387 | + nlink -= h_dir->i_nlink - 2; | |
1facf9fc | 9388 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9389 | + nlink -= 2; |
f6b6e03d | 9390 | + smp_mb(); /* for i_nlink */ |
92d182d2 | 9391 | + /* nlink == 0 means the branch-fs is broken */ |
9dbd164d | 9392 | + set_nlink(dir, nlink); |
1facf9fc | 9393 | +} |
9394 | + | |
1308ab2a | 9395 | +loff_t au_dir_size(struct file *file, struct dentry *dentry) |
9396 | +{ | |
9397 | + loff_t sz; | |
9398 | + aufs_bindex_t bindex, bend; | |
9399 | + struct file *h_file; | |
9400 | + struct dentry *h_dentry; | |
9401 | + | |
9402 | + sz = 0; | |
9403 | + if (file) { | |
2000de60 | 9404 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
1308ab2a | 9405 | + |
4a4d8108 | 9406 | + bend = au_fbend_dir(file); |
1308ab2a | 9407 | + for (bindex = au_fbstart(file); |
9408 | + bindex <= bend && sz < KMALLOC_MAX_SIZE; | |
9409 | + bindex++) { | |
4a4d8108 | 9410 | + h_file = au_hf_dir(file, bindex); |
c06a8ce3 AM |
9411 | + if (h_file && file_inode(h_file)) |
9412 | + sz += vfsub_f_size_read(h_file); | |
1308ab2a | 9413 | + } |
9414 | + } else { | |
9415 | + AuDebugOn(!dentry); | |
2000de60 | 9416 | + AuDebugOn(!d_is_dir(dentry)); |
1308ab2a | 9417 | + |
9418 | + bend = au_dbtaildir(dentry); | |
9419 | + for (bindex = au_dbstart(dentry); | |
9420 | + bindex <= bend && sz < KMALLOC_MAX_SIZE; | |
9421 | + bindex++) { | |
9422 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 JR |
9423 | + if (h_dentry && d_is_positive(h_dentry)) |
9424 | + sz += i_size_read(d_inode(h_dentry)); | |
1308ab2a | 9425 | + } |
9426 | + } | |
9427 | + if (sz < KMALLOC_MAX_SIZE) | |
9428 | + sz = roundup_pow_of_two(sz); | |
9429 | + if (sz > KMALLOC_MAX_SIZE) | |
9430 | + sz = KMALLOC_MAX_SIZE; | |
9431 | + else if (sz < NAME_MAX) { | |
9432 | + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX); | |
9433 | + sz = AUFS_RDBLK_DEF; | |
9434 | + } | |
9435 | + return sz; | |
9436 | +} | |
9437 | + | |
b912730e AM |
9438 | +struct au_dir_ts_arg { |
9439 | + struct dentry *dentry; | |
9440 | + aufs_bindex_t brid; | |
9441 | +}; | |
9442 | + | |
9443 | +static void au_do_dir_ts(void *arg) | |
9444 | +{ | |
9445 | + struct au_dir_ts_arg *a = arg; | |
9446 | + struct au_dtime dt; | |
9447 | + struct path h_path; | |
9448 | + struct inode *dir, *h_dir; | |
9449 | + struct super_block *sb; | |
9450 | + struct au_branch *br; | |
9451 | + struct au_hinode *hdir; | |
9452 | + int err; | |
9453 | + aufs_bindex_t bstart, bindex; | |
9454 | + | |
9455 | + sb = a->dentry->d_sb; | |
5527c038 | 9456 | + if (d_really_is_negative(a->dentry)) |
b912730e | 9457 | + goto out; |
b912730e AM |
9458 | + aufs_read_lock(a->dentry, AuLock_DW | AuLock_DIR); /* noflush */ |
9459 | + | |
5527c038 JR |
9460 | + /* no dir->i_mutex lock */ |
9461 | + dir = d_inode(a->dentry); | |
b912730e AM |
9462 | + bstart = au_ibstart(dir); |
9463 | + bindex = au_br_index(sb, a->brid); | |
9464 | + if (bindex < bstart) | |
9465 | + goto out_unlock; | |
9466 | + | |
9467 | + br = au_sbr(sb, bindex); | |
9468 | + h_path.dentry = au_h_dptr(a->dentry, bindex); | |
9469 | + if (!h_path.dentry) | |
9470 | + goto out_unlock; | |
9471 | + h_path.mnt = au_br_mnt(br); | |
9472 | + au_dtime_store(&dt, a->dentry, &h_path); | |
9473 | + | |
9474 | + br = au_sbr(sb, bstart); | |
9475 | + if (!au_br_writable(br->br_perm)) | |
9476 | + goto out_unlock; | |
9477 | + h_path.dentry = au_h_dptr(a->dentry, bstart); | |
9478 | + h_path.mnt = au_br_mnt(br); | |
9479 | + err = vfsub_mnt_want_write(h_path.mnt); | |
9480 | + if (err) | |
9481 | + goto out_unlock; | |
9482 | + hdir = au_hi(dir, bstart); | |
9483 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); | |
9484 | + h_dir = au_h_iptr(dir, bstart); | |
9485 | + if (h_dir->i_nlink | |
9486 | + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) { | |
9487 | + dt.dt_h_path = h_path; | |
9488 | + au_dtime_revert(&dt); | |
9489 | + } | |
9490 | + au_hn_imtx_unlock(hdir); | |
9491 | + vfsub_mnt_drop_write(h_path.mnt); | |
9492 | + au_cpup_attr_timesizes(dir); | |
9493 | + | |
9494 | +out_unlock: | |
9495 | + aufs_read_unlock(a->dentry, AuLock_DW); | |
9496 | +out: | |
9497 | + dput(a->dentry); | |
9498 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
9499 | + kfree(arg); | |
9500 | +} | |
9501 | + | |
9502 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex) | |
9503 | +{ | |
9504 | + int perm, wkq_err; | |
9505 | + aufs_bindex_t bstart; | |
9506 | + struct au_dir_ts_arg *arg; | |
9507 | + struct dentry *dentry; | |
9508 | + struct super_block *sb; | |
9509 | + | |
9510 | + IMustLock(dir); | |
9511 | + | |
9512 | + dentry = d_find_any_alias(dir); | |
9513 | + AuDebugOn(!dentry); | |
9514 | + sb = dentry->d_sb; | |
9515 | + bstart = au_ibstart(dir); | |
9516 | + if (bstart == bindex) { | |
9517 | + au_cpup_attr_timesizes(dir); | |
9518 | + goto out; | |
9519 | + } | |
9520 | + | |
9521 | + perm = au_sbr_perm(sb, bstart); | |
9522 | + if (!au_br_writable(perm)) | |
9523 | + goto out; | |
9524 | + | |
9525 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
9526 | + if (!arg) | |
9527 | + goto out; | |
9528 | + | |
9529 | + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */ | |
9530 | + arg->brid = au_sbr_id(sb, bindex); | |
9531 | + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0); | |
9532 | + if (unlikely(wkq_err)) { | |
9533 | + pr_err("wkq %d\n", wkq_err); | |
9534 | + dput(dentry); | |
9535 | + kfree(arg); | |
9536 | + } | |
9537 | + | |
9538 | +out: | |
9539 | + dput(dentry); | |
9540 | +} | |
9541 | + | |
1facf9fc | 9542 | +/* ---------------------------------------------------------------------- */ |
9543 | + | |
9544 | +static int reopen_dir(struct file *file) | |
9545 | +{ | |
9546 | + int err; | |
9547 | + unsigned int flags; | |
9548 | + aufs_bindex_t bindex, btail, bstart; | |
9549 | + struct dentry *dentry, *h_dentry; | |
9550 | + struct file *h_file; | |
9551 | + | |
9552 | + /* open all lower dirs */ | |
2000de60 | 9553 | + dentry = file->f_path.dentry; |
1facf9fc | 9554 | + bstart = au_dbstart(dentry); |
9555 | + for (bindex = au_fbstart(file); bindex < bstart; bindex++) | |
9556 | + au_set_h_fptr(file, bindex, NULL); | |
9557 | + au_set_fbstart(file, bstart); | |
9558 | + | |
9559 | + btail = au_dbtaildir(dentry); | |
4a4d8108 | 9560 | + for (bindex = au_fbend_dir(file); btail < bindex; bindex--) |
1facf9fc | 9561 | + au_set_h_fptr(file, bindex, NULL); |
4a4d8108 | 9562 | + au_set_fbend_dir(file, btail); |
1facf9fc | 9563 | + |
4a4d8108 | 9564 | + flags = vfsub_file_flags(file); |
1facf9fc | 9565 | + for (bindex = bstart; bindex <= btail; bindex++) { |
9566 | + h_dentry = au_h_dptr(dentry, bindex); | |
9567 | + if (!h_dentry) | |
9568 | + continue; | |
4a4d8108 | 9569 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 9570 | + if (h_file) |
9571 | + continue; | |
9572 | + | |
392086de | 9573 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9574 | + err = PTR_ERR(h_file); |
9575 | + if (IS_ERR(h_file)) | |
9576 | + goto out; /* close all? */ | |
9577 | + au_set_h_fptr(file, bindex, h_file); | |
9578 | + } | |
9579 | + au_update_figen(file); | |
9580 | + /* todo: necessary? */ | |
9581 | + /* file->f_ra = h_file->f_ra; */ | |
9582 | + err = 0; | |
9583 | + | |
4f0767ce | 9584 | +out: |
1facf9fc | 9585 | + return err; |
9586 | +} | |
9587 | + | |
b912730e | 9588 | +static int do_open_dir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 9589 | +{ |
9590 | + int err; | |
9591 | + aufs_bindex_t bindex, btail; | |
9592 | + struct dentry *dentry, *h_dentry; | |
1facf9fc | 9593 | + |
1308ab2a | 9594 | + FiMustWriteLock(file); |
b912730e | 9595 | + AuDebugOn(h_file); |
1308ab2a | 9596 | + |
523b37e3 | 9597 | + err = 0; |
2000de60 | 9598 | + dentry = file->f_path.dentry; |
5527c038 | 9599 | + file->f_version = d_inode(dentry)->i_version; |
1facf9fc | 9600 | + bindex = au_dbstart(dentry); |
9601 | + au_set_fbstart(file, bindex); | |
9602 | + btail = au_dbtaildir(dentry); | |
4a4d8108 | 9603 | + au_set_fbend_dir(file, btail); |
1facf9fc | 9604 | + for (; !err && bindex <= btail; bindex++) { |
9605 | + h_dentry = au_h_dptr(dentry, bindex); | |
9606 | + if (!h_dentry) | |
9607 | + continue; | |
9608 | + | |
392086de | 9609 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9610 | + if (IS_ERR(h_file)) { |
9611 | + err = PTR_ERR(h_file); | |
9612 | + break; | |
9613 | + } | |
9614 | + au_set_h_fptr(file, bindex, h_file); | |
9615 | + } | |
9616 | + au_update_figen(file); | |
9617 | + /* todo: necessary? */ | |
9618 | + /* file->f_ra = h_file->f_ra; */ | |
9619 | + if (!err) | |
9620 | + return 0; /* success */ | |
9621 | + | |
9622 | + /* close all */ | |
9623 | + for (bindex = au_fbstart(file); bindex <= btail; bindex++) | |
9624 | + au_set_h_fptr(file, bindex, NULL); | |
9625 | + au_set_fbstart(file, -1); | |
4a4d8108 AM |
9626 | + au_set_fbend_dir(file, -1); |
9627 | + | |
1facf9fc | 9628 | + return err; |
9629 | +} | |
9630 | + | |
9631 | +static int aufs_open_dir(struct inode *inode __maybe_unused, | |
9632 | + struct file *file) | |
9633 | +{ | |
4a4d8108 AM |
9634 | + int err; |
9635 | + struct super_block *sb; | |
9636 | + struct au_fidir *fidir; | |
9637 | + | |
9638 | + err = -ENOMEM; | |
2000de60 | 9639 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 9640 | + si_read_lock(sb, AuLock_FLUSH); |
e49829fe | 9641 | + fidir = au_fidir_alloc(sb); |
4a4d8108 | 9642 | + if (fidir) { |
b912730e AM |
9643 | + struct au_do_open_args args = { |
9644 | + .open = do_open_dir, | |
9645 | + .fidir = fidir | |
9646 | + }; | |
9647 | + err = au_do_open(file, &args); | |
4a4d8108 AM |
9648 | + if (unlikely(err)) |
9649 | + kfree(fidir); | |
9650 | + } | |
9651 | + si_read_unlock(sb); | |
9652 | + return err; | |
1facf9fc | 9653 | +} |
9654 | + | |
9655 | +static int aufs_release_dir(struct inode *inode __maybe_unused, | |
9656 | + struct file *file) | |
9657 | +{ | |
9658 | + struct au_vdir *vdir_cache; | |
4a4d8108 AM |
9659 | + struct au_finfo *finfo; |
9660 | + struct au_fidir *fidir; | |
9661 | + aufs_bindex_t bindex, bend; | |
1facf9fc | 9662 | + |
4a4d8108 AM |
9663 | + finfo = au_fi(file); |
9664 | + fidir = finfo->fi_hdir; | |
9665 | + if (fidir) { | |
076b876e | 9666 | + au_sphl_del(&finfo->fi_hlist, |
2000de60 | 9667 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); |
4a4d8108 AM |
9668 | + vdir_cache = fidir->fd_vdir_cache; /* lock-free */ |
9669 | + if (vdir_cache) | |
9670 | + au_vdir_free(vdir_cache); | |
9671 | + | |
9672 | + bindex = finfo->fi_btop; | |
9673 | + if (bindex >= 0) { | |
9674 | + /* | |
9675 | + * calls fput() instead of filp_close(), | |
9676 | + * since no dnotify or lock for the lower file. | |
9677 | + */ | |
9678 | + bend = fidir->fd_bbot; | |
9679 | + for (; bindex <= bend; bindex++) | |
9680 | + au_set_h_fptr(file, bindex, NULL); | |
9681 | + } | |
9682 | + kfree(fidir); | |
9683 | + finfo->fi_hdir = NULL; | |
1facf9fc | 9684 | + } |
1facf9fc | 9685 | + au_finfo_fin(file); |
1facf9fc | 9686 | + return 0; |
9687 | +} | |
9688 | + | |
9689 | +/* ---------------------------------------------------------------------- */ | |
9690 | + | |
4a4d8108 AM |
9691 | +static int au_do_flush_dir(struct file *file, fl_owner_t id) |
9692 | +{ | |
9693 | + int err; | |
9694 | + aufs_bindex_t bindex, bend; | |
9695 | + struct file *h_file; | |
9696 | + | |
9697 | + err = 0; | |
9698 | + bend = au_fbend_dir(file); | |
9699 | + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) { | |
9700 | + h_file = au_hf_dir(file, bindex); | |
9701 | + if (h_file) | |
9702 | + err = vfsub_flush(h_file, id); | |
9703 | + } | |
9704 | + return err; | |
9705 | +} | |
9706 | + | |
9707 | +static int aufs_flush_dir(struct file *file, fl_owner_t id) | |
9708 | +{ | |
9709 | + return au_do_flush(file, id, au_do_flush_dir); | |
9710 | +} | |
9711 | + | |
9712 | +/* ---------------------------------------------------------------------- */ | |
9713 | + | |
1facf9fc | 9714 | +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync) |
9715 | +{ | |
9716 | + int err; | |
9717 | + aufs_bindex_t bend, bindex; | |
9718 | + struct inode *inode; | |
9719 | + struct super_block *sb; | |
9720 | + | |
9721 | + err = 0; | |
9722 | + sb = dentry->d_sb; | |
5527c038 | 9723 | + inode = d_inode(dentry); |
1facf9fc | 9724 | + IMustLock(inode); |
9725 | + bend = au_dbend(dentry); | |
9726 | + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) { | |
9727 | + struct path h_path; | |
1facf9fc | 9728 | + |
9729 | + if (au_test_ro(sb, bindex, inode)) | |
9730 | + continue; | |
9731 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
9732 | + if (!h_path.dentry) | |
9733 | + continue; | |
1facf9fc | 9734 | + |
1facf9fc | 9735 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
53392da6 | 9736 | + err = vfsub_fsync(NULL, &h_path, datasync); |
1facf9fc | 9737 | + } |
9738 | + | |
9739 | + return err; | |
9740 | +} | |
9741 | + | |
9742 | +static int au_do_fsync_dir(struct file *file, int datasync) | |
9743 | +{ | |
9744 | + int err; | |
9745 | + aufs_bindex_t bend, bindex; | |
9746 | + struct file *h_file; | |
9747 | + struct super_block *sb; | |
9748 | + struct inode *inode; | |
1facf9fc | 9749 | + |
9750 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1); | |
9751 | + if (unlikely(err)) | |
9752 | + goto out; | |
9753 | + | |
c06a8ce3 | 9754 | + inode = file_inode(file); |
b912730e | 9755 | + sb = inode->i_sb; |
4a4d8108 | 9756 | + bend = au_fbend_dir(file); |
1facf9fc | 9757 | + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) { |
4a4d8108 | 9758 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 9759 | + if (!h_file || au_test_ro(sb, bindex, inode)) |
9760 | + continue; | |
9761 | + | |
53392da6 | 9762 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
1facf9fc | 9763 | + } |
9764 | + | |
4f0767ce | 9765 | +out: |
1facf9fc | 9766 | + return err; |
9767 | +} | |
9768 | + | |
9769 | +/* | |
9770 | + * @file may be NULL | |
9771 | + */ | |
1e00d052 AM |
9772 | +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end, |
9773 | + int datasync) | |
1facf9fc | 9774 | +{ |
9775 | + int err; | |
b752ccd1 | 9776 | + struct dentry *dentry; |
5527c038 | 9777 | + struct inode *inode; |
1facf9fc | 9778 | + struct super_block *sb; |
1e00d052 | 9779 | + struct mutex *mtx; |
1facf9fc | 9780 | + |
9781 | + err = 0; | |
2000de60 | 9782 | + dentry = file->f_path.dentry; |
5527c038 JR |
9783 | + inode = d_inode(dentry); |
9784 | + mtx = &inode->i_mutex; | |
1e00d052 | 9785 | + mutex_lock(mtx); |
1facf9fc | 9786 | + sb = dentry->d_sb; |
9787 | + si_noflush_read_lock(sb); | |
9788 | + if (file) | |
9789 | + err = au_do_fsync_dir(file, datasync); | |
9790 | + else { | |
9791 | + di_write_lock_child(dentry); | |
9792 | + err = au_do_fsync_dir_no_file(dentry, datasync); | |
9793 | + } | |
5527c038 | 9794 | + au_cpup_attr_timesizes(inode); |
1facf9fc | 9795 | + di_write_unlock(dentry); |
9796 | + if (file) | |
9797 | + fi_write_unlock(file); | |
9798 | + | |
9799 | + si_read_unlock(sb); | |
1e00d052 | 9800 | + mutex_unlock(mtx); |
1facf9fc | 9801 | + return err; |
9802 | +} | |
9803 | + | |
9804 | +/* ---------------------------------------------------------------------- */ | |
9805 | + | |
392086de | 9806 | +static int aufs_iterate(struct file *file, struct dir_context *ctx) |
1facf9fc | 9807 | +{ |
9808 | + int err; | |
9809 | + struct dentry *dentry; | |
9dbd164d | 9810 | + struct inode *inode, *h_inode; |
1facf9fc | 9811 | + struct super_block *sb; |
9812 | + | |
523b37e3 | 9813 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 9814 | + |
2000de60 | 9815 | + dentry = file->f_path.dentry; |
5527c038 | 9816 | + inode = d_inode(dentry); |
1facf9fc | 9817 | + IMustLock(inode); |
9818 | + | |
9819 | + sb = dentry->d_sb; | |
9820 | + si_read_lock(sb, AuLock_FLUSH); | |
9821 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1); | |
9822 | + if (unlikely(err)) | |
9823 | + goto out; | |
027c5e7a AM |
9824 | + err = au_alive_dir(dentry); |
9825 | + if (!err) | |
9826 | + err = au_vdir_init(file); | |
1facf9fc | 9827 | + di_downgrade_lock(dentry, AuLock_IR); |
9828 | + if (unlikely(err)) | |
9829 | + goto out_unlock; | |
9830 | + | |
9dbd164d | 9831 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); |
b752ccd1 | 9832 | + if (!au_test_nfsd()) { |
392086de | 9833 | + err = au_vdir_fill_de(file, ctx); |
9dbd164d | 9834 | + fsstack_copy_attr_atime(inode, h_inode); |
1facf9fc | 9835 | + } else { |
9836 | + /* | |
9837 | + * nfsd filldir may call lookup_one_len(), vfs_getattr(), | |
9838 | + * encode_fh() and others. | |
9839 | + */ | |
9dbd164d | 9840 | + atomic_inc(&h_inode->i_count); |
1facf9fc | 9841 | + di_read_unlock(dentry, AuLock_IR); |
9842 | + si_read_unlock(sb); | |
392086de | 9843 | + err = au_vdir_fill_de(file, ctx); |
1facf9fc | 9844 | + fsstack_copy_attr_atime(inode, h_inode); |
9845 | + fi_write_unlock(file); | |
9dbd164d | 9846 | + iput(h_inode); |
1facf9fc | 9847 | + |
9848 | + AuTraceErr(err); | |
9849 | + return err; | |
9850 | + } | |
9851 | + | |
4f0767ce | 9852 | +out_unlock: |
1facf9fc | 9853 | + di_read_unlock(dentry, AuLock_IR); |
9854 | + fi_write_unlock(file); | |
4f0767ce | 9855 | +out: |
1facf9fc | 9856 | + si_read_unlock(sb); |
9857 | + return err; | |
9858 | +} | |
9859 | + | |
9860 | +/* ---------------------------------------------------------------------- */ | |
9861 | + | |
9862 | +#define AuTestEmpty_WHONLY 1 | |
dece6358 AM |
9863 | +#define AuTestEmpty_CALLED (1 << 1) |
9864 | +#define AuTestEmpty_SHWH (1 << 2) | |
1facf9fc | 9865 | +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name) |
7f207e10 AM |
9866 | +#define au_fset_testempty(flags, name) \ |
9867 | + do { (flags) |= AuTestEmpty_##name; } while (0) | |
9868 | +#define au_fclr_testempty(flags, name) \ | |
9869 | + do { (flags) &= ~AuTestEmpty_##name; } while (0) | |
1facf9fc | 9870 | + |
dece6358 AM |
9871 | +#ifndef CONFIG_AUFS_SHWH |
9872 | +#undef AuTestEmpty_SHWH | |
9873 | +#define AuTestEmpty_SHWH 0 | |
9874 | +#endif | |
9875 | + | |
1facf9fc | 9876 | +struct test_empty_arg { |
392086de | 9877 | + struct dir_context ctx; |
1308ab2a | 9878 | + struct au_nhash *whlist; |
1facf9fc | 9879 | + unsigned int flags; |
9880 | + int err; | |
9881 | + aufs_bindex_t bindex; | |
9882 | +}; | |
9883 | + | |
392086de AM |
9884 | +static int test_empty_cb(struct dir_context *ctx, const char *__name, |
9885 | + int namelen, loff_t offset __maybe_unused, u64 ino, | |
dece6358 | 9886 | + unsigned int d_type) |
1facf9fc | 9887 | +{ |
392086de AM |
9888 | + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg, |
9889 | + ctx); | |
1facf9fc | 9890 | + char *name = (void *)__name; |
9891 | + | |
9892 | + arg->err = 0; | |
9893 | + au_fset_testempty(arg->flags, CALLED); | |
9894 | + /* smp_mb(); */ | |
9895 | + if (name[0] == '.' | |
9896 | + && (namelen == 1 || (name[1] == '.' && namelen == 2))) | |
9897 | + goto out; /* success */ | |
9898 | + | |
9899 | + if (namelen <= AUFS_WH_PFX_LEN | |
9900 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
9901 | + if (au_ftest_testempty(arg->flags, WHONLY) | |
1308ab2a | 9902 | + && !au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 9903 | + arg->err = -ENOTEMPTY; |
9904 | + goto out; | |
9905 | + } | |
9906 | + | |
9907 | + name += AUFS_WH_PFX_LEN; | |
9908 | + namelen -= AUFS_WH_PFX_LEN; | |
1308ab2a | 9909 | + if (!au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 9910 | + arg->err = au_nhash_append_wh |
1308ab2a | 9911 | + (arg->whlist, name, namelen, ino, d_type, arg->bindex, |
dece6358 | 9912 | + au_ftest_testempty(arg->flags, SHWH)); |
1facf9fc | 9913 | + |
4f0767ce | 9914 | +out: |
1facf9fc | 9915 | + /* smp_mb(); */ |
9916 | + AuTraceErr(arg->err); | |
9917 | + return arg->err; | |
9918 | +} | |
9919 | + | |
9920 | +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
9921 | +{ | |
9922 | + int err; | |
9923 | + struct file *h_file; | |
9924 | + | |
9925 | + h_file = au_h_open(dentry, arg->bindex, | |
9926 | + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE, | |
392086de | 9927 | + /*file*/NULL, /*force_wr*/0); |
1facf9fc | 9928 | + err = PTR_ERR(h_file); |
9929 | + if (IS_ERR(h_file)) | |
9930 | + goto out; | |
9931 | + | |
9932 | + err = 0; | |
9933 | + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE) | |
c06a8ce3 | 9934 | + && !file_inode(h_file)->i_nlink) |
1facf9fc | 9935 | + goto out_put; |
9936 | + | |
9937 | + do { | |
9938 | + arg->err = 0; | |
9939 | + au_fclr_testempty(arg->flags, CALLED); | |
9940 | + /* smp_mb(); */ | |
392086de | 9941 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1facf9fc | 9942 | + if (err >= 0) |
9943 | + err = arg->err; | |
9944 | + } while (!err && au_ftest_testempty(arg->flags, CALLED)); | |
9945 | + | |
4f0767ce | 9946 | +out_put: |
1facf9fc | 9947 | + fput(h_file); |
9948 | + au_sbr_put(dentry->d_sb, arg->bindex); | |
4f0767ce | 9949 | +out: |
1facf9fc | 9950 | + return err; |
9951 | +} | |
9952 | + | |
9953 | +struct do_test_empty_args { | |
9954 | + int *errp; | |
9955 | + struct dentry *dentry; | |
9956 | + struct test_empty_arg *arg; | |
9957 | +}; | |
9958 | + | |
9959 | +static void call_do_test_empty(void *args) | |
9960 | +{ | |
9961 | + struct do_test_empty_args *a = args; | |
9962 | + *a->errp = do_test_empty(a->dentry, a->arg); | |
9963 | +} | |
9964 | + | |
9965 | +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
9966 | +{ | |
9967 | + int err, wkq_err; | |
9968 | + struct dentry *h_dentry; | |
9969 | + struct inode *h_inode; | |
9970 | + | |
9971 | + h_dentry = au_h_dptr(dentry, arg->bindex); | |
5527c038 | 9972 | + h_inode = d_inode(h_dentry); |
53392da6 | 9973 | + /* todo: i_mode changes anytime? */ |
1facf9fc | 9974 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
9975 | + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ); | |
9976 | + mutex_unlock(&h_inode->i_mutex); | |
9977 | + if (!err) | |
9978 | + err = do_test_empty(dentry, arg); | |
9979 | + else { | |
9980 | + struct do_test_empty_args args = { | |
9981 | + .errp = &err, | |
9982 | + .dentry = dentry, | |
9983 | + .arg = arg | |
9984 | + }; | |
9985 | + unsigned int flags = arg->flags; | |
9986 | + | |
9987 | + wkq_err = au_wkq_wait(call_do_test_empty, &args); | |
9988 | + if (unlikely(wkq_err)) | |
9989 | + err = wkq_err; | |
9990 | + arg->flags = flags; | |
9991 | + } | |
9992 | + | |
9993 | + return err; | |
9994 | +} | |
9995 | + | |
9996 | +int au_test_empty_lower(struct dentry *dentry) | |
9997 | +{ | |
9998 | + int err; | |
1308ab2a | 9999 | + unsigned int rdhash; |
1facf9fc | 10000 | + aufs_bindex_t bindex, bstart, btail; |
1308ab2a | 10001 | + struct au_nhash whlist; |
392086de AM |
10002 | + struct test_empty_arg arg = { |
10003 | + .ctx = { | |
2000de60 | 10004 | + .actor = test_empty_cb |
392086de AM |
10005 | + } |
10006 | + }; | |
076b876e | 10007 | + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg); |
1facf9fc | 10008 | + |
dece6358 AM |
10009 | + SiMustAnyLock(dentry->d_sb); |
10010 | + | |
1308ab2a | 10011 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; |
10012 | + if (!rdhash) | |
10013 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry)); | |
10014 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
dece6358 | 10015 | + if (unlikely(err)) |
1facf9fc | 10016 | + goto out; |
10017 | + | |
1facf9fc | 10018 | + arg.flags = 0; |
1308ab2a | 10019 | + arg.whlist = &whlist; |
10020 | + bstart = au_dbstart(dentry); | |
dece6358 AM |
10021 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10022 | + au_fset_testempty(arg.flags, SHWH); | |
076b876e AM |
10023 | + test_empty = do_test_empty; |
10024 | + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)) | |
10025 | + test_empty = sio_test_empty; | |
1facf9fc | 10026 | + arg.bindex = bstart; |
076b876e | 10027 | + err = test_empty(dentry, &arg); |
1facf9fc | 10028 | + if (unlikely(err)) |
10029 | + goto out_whlist; | |
10030 | + | |
10031 | + au_fset_testempty(arg.flags, WHONLY); | |
10032 | + btail = au_dbtaildir(dentry); | |
10033 | + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) { | |
10034 | + struct dentry *h_dentry; | |
10035 | + | |
10036 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10037 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10038 | + arg.bindex = bindex; |
076b876e | 10039 | + err = test_empty(dentry, &arg); |
1facf9fc | 10040 | + } |
10041 | + } | |
10042 | + | |
4f0767ce | 10043 | +out_whlist: |
1308ab2a | 10044 | + au_nhash_wh_free(&whlist); |
4f0767ce | 10045 | +out: |
1facf9fc | 10046 | + return err; |
10047 | +} | |
10048 | + | |
10049 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist) | |
10050 | +{ | |
10051 | + int err; | |
392086de AM |
10052 | + struct test_empty_arg arg = { |
10053 | + .ctx = { | |
2000de60 | 10054 | + .actor = test_empty_cb |
392086de AM |
10055 | + } |
10056 | + }; | |
1facf9fc | 10057 | + aufs_bindex_t bindex, btail; |
10058 | + | |
10059 | + err = 0; | |
1308ab2a | 10060 | + arg.whlist = whlist; |
1facf9fc | 10061 | + arg.flags = AuTestEmpty_WHONLY; |
dece6358 AM |
10062 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10063 | + au_fset_testempty(arg.flags, SHWH); | |
1facf9fc | 10064 | + btail = au_dbtaildir(dentry); |
10065 | + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) { | |
10066 | + struct dentry *h_dentry; | |
10067 | + | |
10068 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10069 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10070 | + arg.bindex = bindex; |
10071 | + err = sio_test_empty(dentry, &arg); | |
10072 | + } | |
10073 | + } | |
10074 | + | |
10075 | + return err; | |
10076 | +} | |
10077 | + | |
10078 | +/* ---------------------------------------------------------------------- */ | |
10079 | + | |
10080 | +const struct file_operations aufs_dir_fop = { | |
4a4d8108 | 10081 | + .owner = THIS_MODULE, |
027c5e7a | 10082 | + .llseek = default_llseek, |
1facf9fc | 10083 | + .read = generic_read_dir, |
392086de | 10084 | + .iterate = aufs_iterate, |
1facf9fc | 10085 | + .unlocked_ioctl = aufs_ioctl_dir, |
b752ccd1 AM |
10086 | +#ifdef CONFIG_COMPAT |
10087 | + .compat_ioctl = aufs_compat_ioctl_dir, | |
10088 | +#endif | |
1facf9fc | 10089 | + .open = aufs_open_dir, |
10090 | + .release = aufs_release_dir, | |
4a4d8108 | 10091 | + .flush = aufs_flush_dir, |
1facf9fc | 10092 | + .fsync = aufs_fsync_dir |
10093 | +}; | |
7f207e10 AM |
10094 | diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h |
10095 | --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 10096 | +++ linux/fs/aufs/dir.h 2015-09-24 10:47:58.251386326 +0200 |
b912730e | 10097 | @@ -0,0 +1,131 @@ |
1facf9fc | 10098 | +/* |
2000de60 | 10099 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 10100 | + * |
10101 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10102 | + * it under the terms of the GNU General Public License as published by | |
10103 | + * the Free Software Foundation; either version 2 of the License, or | |
10104 | + * (at your option) any later version. | |
dece6358 AM |
10105 | + * |
10106 | + * This program is distributed in the hope that it will be useful, | |
10107 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10108 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10109 | + * GNU General Public License for more details. | |
10110 | + * | |
10111 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10112 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10113 | + */ |
10114 | + | |
10115 | +/* | |
10116 | + * directory operations | |
10117 | + */ | |
10118 | + | |
10119 | +#ifndef __AUFS_DIR_H__ | |
10120 | +#define __AUFS_DIR_H__ | |
10121 | + | |
10122 | +#ifdef __KERNEL__ | |
10123 | + | |
10124 | +#include <linux/fs.h> | |
1facf9fc | 10125 | + |
10126 | +/* ---------------------------------------------------------------------- */ | |
10127 | + | |
10128 | +/* need to be faster and smaller */ | |
10129 | + | |
10130 | +struct au_nhash { | |
dece6358 AM |
10131 | + unsigned int nh_num; |
10132 | + struct hlist_head *nh_head; | |
1facf9fc | 10133 | +}; |
10134 | + | |
10135 | +struct au_vdir_destr { | |
10136 | + unsigned char len; | |
10137 | + unsigned char name[0]; | |
10138 | +} __packed; | |
10139 | + | |
10140 | +struct au_vdir_dehstr { | |
10141 | + struct hlist_node hash; | |
10142 | + struct au_vdir_destr *str; | |
4a4d8108 | 10143 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10144 | + |
10145 | +struct au_vdir_de { | |
10146 | + ino_t de_ino; | |
10147 | + unsigned char de_type; | |
10148 | + /* caution: packed */ | |
10149 | + struct au_vdir_destr de_str; | |
10150 | +} __packed; | |
10151 | + | |
10152 | +struct au_vdir_wh { | |
10153 | + struct hlist_node wh_hash; | |
dece6358 AM |
10154 | +#ifdef CONFIG_AUFS_SHWH |
10155 | + ino_t wh_ino; | |
1facf9fc | 10156 | + aufs_bindex_t wh_bindex; |
dece6358 AM |
10157 | + unsigned char wh_type; |
10158 | +#else | |
10159 | + aufs_bindex_t wh_bindex; | |
10160 | +#endif | |
10161 | + /* caution: packed */ | |
1facf9fc | 10162 | + struct au_vdir_destr wh_str; |
10163 | +} __packed; | |
10164 | + | |
10165 | +union au_vdir_deblk_p { | |
10166 | + unsigned char *deblk; | |
10167 | + struct au_vdir_de *de; | |
10168 | +}; | |
10169 | + | |
10170 | +struct au_vdir { | |
10171 | + unsigned char **vd_deblk; | |
10172 | + unsigned long vd_nblk; | |
1facf9fc | 10173 | + struct { |
10174 | + unsigned long ul; | |
10175 | + union au_vdir_deblk_p p; | |
10176 | + } vd_last; | |
10177 | + | |
10178 | + unsigned long vd_version; | |
dece6358 | 10179 | + unsigned int vd_deblk_sz; |
1facf9fc | 10180 | + unsigned long vd_jiffy; |
4a4d8108 | 10181 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10182 | + |
10183 | +/* ---------------------------------------------------------------------- */ | |
10184 | + | |
10185 | +/* dir.c */ | |
10186 | +extern const struct file_operations aufs_dir_fop; | |
10187 | +void au_add_nlink(struct inode *dir, struct inode *h_dir); | |
10188 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir); | |
1308ab2a | 10189 | +loff_t au_dir_size(struct file *file, struct dentry *dentry); |
b912730e | 10190 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc); |
1facf9fc | 10191 | +int au_test_empty_lower(struct dentry *dentry); |
10192 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist); | |
10193 | + | |
10194 | +/* vdir.c */ | |
1308ab2a | 10195 | +unsigned int au_rdhash_est(loff_t sz); |
dece6358 AM |
10196 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp); |
10197 | +void au_nhash_wh_free(struct au_nhash *whlist); | |
1facf9fc | 10198 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, |
10199 | + int limit); | |
dece6358 AM |
10200 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen); |
10201 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
10202 | + unsigned int d_type, aufs_bindex_t bindex, | |
10203 | + unsigned char shwh); | |
1facf9fc | 10204 | +void au_vdir_free(struct au_vdir *vdir); |
10205 | +int au_vdir_init(struct file *file); | |
392086de | 10206 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx); |
1facf9fc | 10207 | + |
10208 | +/* ioctl.c */ | |
10209 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg); | |
10210 | + | |
1308ab2a | 10211 | +#ifdef CONFIG_AUFS_RDU |
10212 | +/* rdu.c */ | |
10213 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
10214 | +#ifdef CONFIG_COMPAT |
10215 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, | |
10216 | + unsigned long arg); | |
10217 | +#endif | |
1308ab2a | 10218 | +#else |
c1595e42 JR |
10219 | +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file, |
10220 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10221 | +#ifdef CONFIG_COMPAT |
c1595e42 JR |
10222 | +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file, |
10223 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10224 | +#endif |
1308ab2a | 10225 | +#endif |
10226 | + | |
1facf9fc | 10227 | +#endif /* __KERNEL__ */ |
10228 | +#endif /* __AUFS_DIR_H__ */ | |
7f207e10 AM |
10229 | diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c |
10230 | --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 10231 | +++ linux/fs/aufs/dynop.c 2015-09-24 10:47:58.251386326 +0200 |
7e9cd9fe | 10232 | @@ -0,0 +1,369 @@ |
1facf9fc | 10233 | +/* |
2000de60 | 10234 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
1facf9fc | 10235 | + * |
10236 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10237 | + * it under the terms of the GNU General Public License as published by | |
10238 | + * the Free Software Foundation; either version 2 of the License, or | |
10239 | + * (at your option) any later version. | |
dece6358 AM |
10240 | + * |
10241 | + * This program is distributed in the hope that it will be useful, | |
10242 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10243 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10244 | + * GNU General Public License for more details. | |
10245 | + * | |
10246 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10247 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10248 | + */ |
10249 | + | |
10250 | +/* | |
4a4d8108 | 10251 | + * dynamically customizable operations for regular files |
1facf9fc | 10252 | + */ |
10253 | + | |
1facf9fc | 10254 | +#include "aufs.h" |
10255 | + | |
4a4d8108 | 10256 | +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop) |
1facf9fc | 10257 | + |
4a4d8108 AM |
10258 | +/* |
10259 | + * How large will these lists be? | |
10260 | + * Usually just a few elements, 20-30 at most for each, I guess. | |
10261 | + */ | |
10262 | +static struct au_splhead dynop[AuDyLast]; | |
10263 | + | |
10264 | +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op) | |
1facf9fc | 10265 | +{ |
4a4d8108 AM |
10266 | + struct au_dykey *key, *tmp; |
10267 | + struct list_head *head; | |
1facf9fc | 10268 | + |
4a4d8108 AM |
10269 | + key = NULL; |
10270 | + head = &spl->head; | |
10271 | + rcu_read_lock(); | |
10272 | + list_for_each_entry_rcu(tmp, head, dk_list) | |
10273 | + if (tmp->dk_op.dy_hop == h_op) { | |
10274 | + key = tmp; | |
10275 | + kref_get(&key->dk_kref); | |
10276 | + break; | |
10277 | + } | |
10278 | + rcu_read_unlock(); | |
10279 | + | |
10280 | + return key; | |
1facf9fc | 10281 | +} |
10282 | + | |
4a4d8108 | 10283 | +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key) |
1facf9fc | 10284 | +{ |
4a4d8108 AM |
10285 | + struct au_dykey **k, *found; |
10286 | + const void *h_op = key->dk_op.dy_hop; | |
10287 | + int i; | |
1facf9fc | 10288 | + |
4a4d8108 AM |
10289 | + found = NULL; |
10290 | + k = br->br_dykey; | |
10291 | + for (i = 0; i < AuBrDynOp; i++) | |
10292 | + if (k[i]) { | |
10293 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10294 | + found = k[i]; | |
10295 | + break; | |
10296 | + } | |
10297 | + } else | |
10298 | + break; | |
10299 | + if (!found) { | |
10300 | + spin_lock(&br->br_dykey_lock); | |
10301 | + for (; i < AuBrDynOp; i++) | |
10302 | + if (k[i]) { | |
10303 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10304 | + found = k[i]; | |
10305 | + break; | |
10306 | + } | |
10307 | + } else { | |
10308 | + k[i] = key; | |
10309 | + break; | |
10310 | + } | |
10311 | + spin_unlock(&br->br_dykey_lock); | |
10312 | + BUG_ON(i == AuBrDynOp); /* expand the array */ | |
10313 | + } | |
10314 | + | |
10315 | + return found; | |
1facf9fc | 10316 | +} |
10317 | + | |
4a4d8108 AM |
10318 | +/* kref_get() if @key is already added */ |
10319 | +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key) | |
10320 | +{ | |
10321 | + struct au_dykey *tmp, *found; | |
10322 | + struct list_head *head; | |
10323 | + const void *h_op = key->dk_op.dy_hop; | |
1facf9fc | 10324 | + |
4a4d8108 AM |
10325 | + found = NULL; |
10326 | + head = &spl->head; | |
10327 | + spin_lock(&spl->spin); | |
10328 | + list_for_each_entry(tmp, head, dk_list) | |
10329 | + if (tmp->dk_op.dy_hop == h_op) { | |
10330 | + kref_get(&tmp->dk_kref); | |
10331 | + found = tmp; | |
10332 | + break; | |
10333 | + } | |
10334 | + if (!found) | |
10335 | + list_add_rcu(&key->dk_list, head); | |
10336 | + spin_unlock(&spl->spin); | |
1facf9fc | 10337 | + |
4a4d8108 AM |
10338 | + if (!found) |
10339 | + DyPrSym(key); | |
10340 | + return found; | |
10341 | +} | |
10342 | + | |
10343 | +static void dy_free_rcu(struct rcu_head *rcu) | |
1facf9fc | 10344 | +{ |
4a4d8108 AM |
10345 | + struct au_dykey *key; |
10346 | + | |
10347 | + key = container_of(rcu, struct au_dykey, dk_rcu); | |
10348 | + DyPrSym(key); | |
10349 | + kfree(key); | |
1facf9fc | 10350 | +} |
10351 | + | |
4a4d8108 AM |
10352 | +static void dy_free(struct kref *kref) |
10353 | +{ | |
10354 | + struct au_dykey *key; | |
10355 | + struct au_splhead *spl; | |
1facf9fc | 10356 | + |
4a4d8108 AM |
10357 | + key = container_of(kref, struct au_dykey, dk_kref); |
10358 | + spl = dynop + key->dk_op.dy_type; | |
10359 | + au_spl_del_rcu(&key->dk_list, spl); | |
10360 | + call_rcu(&key->dk_rcu, dy_free_rcu); | |
10361 | +} | |
10362 | + | |
10363 | +void au_dy_put(struct au_dykey *key) | |
1facf9fc | 10364 | +{ |
4a4d8108 AM |
10365 | + kref_put(&key->dk_kref, dy_free); |
10366 | +} | |
1facf9fc | 10367 | + |
4a4d8108 AM |
10368 | +/* ---------------------------------------------------------------------- */ |
10369 | + | |
10370 | +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *)) | |
10371 | + | |
10372 | +#ifdef CONFIG_AUFS_DEBUG | |
10373 | +#define DyDbgDeclare(cnt) unsigned int cnt = 0 | |
4f0767ce | 10374 | +#define DyDbgInc(cnt) do { cnt++; } while (0) |
4a4d8108 AM |
10375 | +#else |
10376 | +#define DyDbgDeclare(cnt) do {} while (0) | |
10377 | +#define DyDbgInc(cnt) do {} while (0) | |
10378 | +#endif | |
10379 | + | |
10380 | +#define DySet(func, dst, src, h_op, h_sb) do { \ | |
10381 | + DyDbgInc(cnt); \ | |
10382 | + if (h_op->func) { \ | |
10383 | + if (src.func) \ | |
10384 | + dst.func = src.func; \ | |
10385 | + else \ | |
10386 | + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \ | |
10387 | + } \ | |
10388 | +} while (0) | |
10389 | + | |
10390 | +#define DySetForce(func, dst, src) do { \ | |
10391 | + AuDebugOn(!src.func); \ | |
10392 | + DyDbgInc(cnt); \ | |
10393 | + dst.func = src.func; \ | |
10394 | +} while (0) | |
10395 | + | |
10396 | +#define DySetAop(func) \ | |
10397 | + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb) | |
10398 | +#define DySetAopForce(func) \ | |
10399 | + DySetForce(func, dyaop->da_op, aufs_aop) | |
10400 | + | |
10401 | +static void dy_aop(struct au_dykey *key, const void *h_op, | |
10402 | + struct super_block *h_sb __maybe_unused) | |
10403 | +{ | |
10404 | + struct au_dyaop *dyaop = (void *)key; | |
10405 | + const struct address_space_operations *h_aop = h_op; | |
10406 | + DyDbgDeclare(cnt); | |
10407 | + | |
10408 | + AuDbg("%s\n", au_sbtype(h_sb)); | |
10409 | + | |
10410 | + DySetAop(writepage); | |
10411 | + DySetAopForce(readpage); /* force */ | |
4a4d8108 AM |
10412 | + DySetAop(writepages); |
10413 | + DySetAop(set_page_dirty); | |
10414 | + DySetAop(readpages); | |
10415 | + DySetAop(write_begin); | |
10416 | + DySetAop(write_end); | |
10417 | + DySetAop(bmap); | |
10418 | + DySetAop(invalidatepage); | |
10419 | + DySetAop(releasepage); | |
027c5e7a | 10420 | + DySetAop(freepage); |
7e9cd9fe | 10421 | + /* this one will be changed according to an aufs mount option */ |
4a4d8108 | 10422 | + DySetAop(direct_IO); |
4a4d8108 AM |
10423 | + DySetAop(migratepage); |
10424 | + DySetAop(launder_page); | |
10425 | + DySetAop(is_partially_uptodate); | |
392086de | 10426 | + DySetAop(is_dirty_writeback); |
4a4d8108 | 10427 | + DySetAop(error_remove_page); |
b4510431 AM |
10428 | + DySetAop(swap_activate); |
10429 | + DySetAop(swap_deactivate); | |
4a4d8108 AM |
10430 | + |
10431 | + DyDbgSize(cnt, *h_aop); | |
4a4d8108 AM |
10432 | +} |
10433 | + | |
4a4d8108 AM |
10434 | +/* ---------------------------------------------------------------------- */ |
10435 | + | |
10436 | +static void dy_bug(struct kref *kref) | |
10437 | +{ | |
10438 | + BUG(); | |
10439 | +} | |
10440 | + | |
10441 | +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br) | |
10442 | +{ | |
10443 | + struct au_dykey *key, *old; | |
10444 | + struct au_splhead *spl; | |
b752ccd1 | 10445 | + struct op { |
4a4d8108 | 10446 | + unsigned int sz; |
b752ccd1 AM |
10447 | + void (*set)(struct au_dykey *key, const void *h_op, |
10448 | + struct super_block *h_sb __maybe_unused); | |
10449 | + }; | |
10450 | + static const struct op a[] = { | |
4a4d8108 AM |
10451 | + [AuDy_AOP] = { |
10452 | + .sz = sizeof(struct au_dyaop), | |
b752ccd1 | 10453 | + .set = dy_aop |
4a4d8108 | 10454 | + } |
b752ccd1 AM |
10455 | + }; |
10456 | + const struct op *p; | |
4a4d8108 AM |
10457 | + |
10458 | + spl = dynop + op->dy_type; | |
10459 | + key = dy_gfind_get(spl, op->dy_hop); | |
10460 | + if (key) | |
10461 | + goto out_add; /* success */ | |
10462 | + | |
10463 | + p = a + op->dy_type; | |
10464 | + key = kzalloc(p->sz, GFP_NOFS); | |
10465 | + if (unlikely(!key)) { | |
10466 | + key = ERR_PTR(-ENOMEM); | |
10467 | + goto out; | |
10468 | + } | |
10469 | + | |
10470 | + key->dk_op.dy_hop = op->dy_hop; | |
10471 | + kref_init(&key->dk_kref); | |
86dc4139 | 10472 | + p->set(key, op->dy_hop, au_br_sb(br)); |
4a4d8108 AM |
10473 | + old = dy_gadd(spl, key); |
10474 | + if (old) { | |
10475 | + kfree(key); | |
10476 | + key = old; | |
10477 | + } | |
10478 | + | |
10479 | +out_add: | |
10480 | + old = dy_bradd(br, key); | |
10481 | + if (old) | |
10482 | + /* its ref-count should never be zero here */ | |
10483 | + kref_put(&key->dk_kref, dy_bug); | |
10484 | +out: | |
10485 | + return key; | |
10486 | +} | |
10487 | + | |
10488 | +/* ---------------------------------------------------------------------- */ | |
10489 | +/* | |
10490 | + * Aufs prohibits O_DIRECT by defaut even if the branch supports it. | |
c1595e42 | 10491 | + * This behaviour is necessary to return an error from open(O_DIRECT) instead |
4a4d8108 AM |
10492 | + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes |
10493 | + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error. | |
10494 | + * See the aufs manual in detail. | |
4a4d8108 AM |
10495 | + */ |
10496 | +static void dy_adx(struct au_dyaop *dyaop, int do_dx) | |
10497 | +{ | |
7e9cd9fe | 10498 | + if (!do_dx) |
4a4d8108 | 10499 | + dyaop->da_op.direct_IO = NULL; |
7e9cd9fe | 10500 | + else |
4a4d8108 | 10501 | + dyaop->da_op.direct_IO = aufs_aop.direct_IO; |
4a4d8108 AM |
10502 | +} |
10503 | + | |
10504 | +static struct au_dyaop *dy_aget(struct au_branch *br, | |
10505 | + const struct address_space_operations *h_aop, | |
10506 | + int do_dx) | |
10507 | +{ | |
10508 | + struct au_dyaop *dyaop; | |
10509 | + struct au_dynop op; | |
10510 | + | |
10511 | + op.dy_type = AuDy_AOP; | |
10512 | + op.dy_haop = h_aop; | |
10513 | + dyaop = (void *)dy_get(&op, br); | |
10514 | + if (IS_ERR(dyaop)) | |
10515 | + goto out; | |
10516 | + dy_adx(dyaop, do_dx); | |
10517 | + | |
10518 | +out: | |
10519 | + return dyaop; | |
10520 | +} | |
10521 | + | |
10522 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
10523 | + struct inode *h_inode) | |
10524 | +{ | |
10525 | + int err, do_dx; | |
10526 | + struct super_block *sb; | |
10527 | + struct au_branch *br; | |
10528 | + struct au_dyaop *dyaop; | |
10529 | + | |
10530 | + AuDebugOn(!S_ISREG(h_inode->i_mode)); | |
10531 | + IiMustWriteLock(inode); | |
10532 | + | |
10533 | + sb = inode->i_sb; | |
10534 | + br = au_sbr(sb, bindex); | |
10535 | + do_dx = !!au_opt_test(au_mntflags(sb), DIO); | |
10536 | + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx); | |
10537 | + err = PTR_ERR(dyaop); | |
10538 | + if (IS_ERR(dyaop)) | |
10539 | + /* unnecessary to call dy_fput() */ | |
10540 | + goto out; | |
10541 | + | |
10542 | + err = 0; | |
10543 | + inode->i_mapping->a_ops = &dyaop->da_op; | |
10544 | + | |
10545 | +out: | |
10546 | + return err; | |
10547 | +} | |
10548 | + | |
b752ccd1 AM |
10549 | +/* |
10550 | + * Is it safe to replace a_ops during the inode/file is in operation? | |
10551 | + * Yes, I hope so. | |
10552 | + */ | |
10553 | +int au_dy_irefresh(struct inode *inode) | |
10554 | +{ | |
10555 | + int err; | |
10556 | + aufs_bindex_t bstart; | |
10557 | + struct inode *h_inode; | |
10558 | + | |
10559 | + err = 0; | |
10560 | + if (S_ISREG(inode->i_mode)) { | |
10561 | + bstart = au_ibstart(inode); | |
10562 | + h_inode = au_h_iptr(inode, bstart); | |
10563 | + err = au_dy_iaop(inode, bstart, h_inode); | |
10564 | + } | |
10565 | + return err; | |
10566 | +} | |
10567 | + | |
4a4d8108 AM |
10568 | +void au_dy_arefresh(int do_dx) |
10569 | +{ | |
10570 | + struct au_splhead *spl; | |
10571 | + struct list_head *head; | |
10572 | + struct au_dykey *key; | |
10573 | + | |
10574 | + spl = dynop + AuDy_AOP; | |
10575 | + head = &spl->head; | |
10576 | + spin_lock(&spl->spin); | |
10577 | + list_for_each_entry(key, head, dk_list) | |
10578 | + dy_adx((void *)key, do_dx); | |
10579 | + spin_unlock(&spl->spin); | |
10580 | +} | |
10581 | + | |
4a4d8108 AM |
10582 | +/* ---------------------------------------------------------------------- */ |
10583 | + | |
10584 | +void __init au_dy_init(void) | |
10585 | +{ | |
10586 | + int i; | |
10587 | + | |
10588 | + /* make sure that 'struct au_dykey *' can be any type */ | |
10589 | + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key)); | |
4a4d8108 AM |
10590 | + |
10591 | + for (i = 0; i < AuDyLast; i++) | |
10592 | + au_spl_init(dynop + i); | |
10593 | +} | |
10594 | + | |
10595 | +void au_dy_fin(void) | |
10596 | +{ | |
10597 | + int i; | |
10598 | + | |
10599 | + for (i = 0; i < AuDyLast; i++) | |
10600 | + WARN_ON(!list_empty(&dynop[i].head)); | |
10601 | +} | |
7f207e10 AM |
10602 | diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h |
10603 | --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 10604 | +++ linux/fs/aufs/dynop.h 2015-09-24 10:47:58.251386326 +0200 |
7e9cd9fe | 10605 | @@ -0,0 +1,74 @@ |
4a4d8108 | 10606 | +/* |
2000de60 | 10607 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
4a4d8108 AM |
10608 | + * |
10609 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10610 | + * it under the terms of the GNU General Public License as published by | |
10611 | + * the Free Software Foundation; either version 2 of the License, or | |
10612 | + * (at your option) any later version. | |
10613 | + * | |
10614 | + * This program is distributed in the hope that it will be useful, | |
10615 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10616 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10617 | + * GNU General Public License for more details. | |
10618 | + * | |
10619 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10620 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
10621 | + */ |
10622 | + | |
10623 | +/* | |
10624 | + * dynamically customizable operations (for regular files only) | |
10625 | + */ | |
10626 | + | |
10627 | +#ifndef __AUFS_DYNOP_H__ | |
10628 | +#define __AUFS_DYNOP_H__ | |
10629 | + | |
10630 | +#ifdef __KERNEL__ | |
10631 | + | |
7e9cd9fe AM |
10632 | +#include <linux/fs.h> |
10633 | +#include <linux/kref.h> | |
4a4d8108 | 10634 | + |
2cbb1c4b | 10635 | +enum {AuDy_AOP, AuDyLast}; |
4a4d8108 AM |
10636 | + |
10637 | +struct au_dynop { | |
10638 | + int dy_type; | |
10639 | + union { | |
10640 | + const void *dy_hop; | |
10641 | + const struct address_space_operations *dy_haop; | |
4a4d8108 AM |
10642 | + }; |
10643 | +}; | |
10644 | + | |
10645 | +struct au_dykey { | |
10646 | + union { | |
10647 | + struct list_head dk_list; | |
10648 | + struct rcu_head dk_rcu; | |
10649 | + }; | |
10650 | + struct au_dynop dk_op; | |
10651 | + | |
10652 | + /* | |
10653 | + * during I am in the branch local array, kref is gotten. when the | |
10654 | + * branch is removed, kref is put. | |
10655 | + */ | |
10656 | + struct kref dk_kref; | |
10657 | +}; | |
10658 | + | |
10659 | +/* stop unioning since their sizes are very different from each other */ | |
10660 | +struct au_dyaop { | |
10661 | + struct au_dykey da_key; | |
10662 | + struct address_space_operations da_op; /* not const */ | |
4a4d8108 AM |
10663 | +}; |
10664 | + | |
4a4d8108 AM |
10665 | +/* ---------------------------------------------------------------------- */ |
10666 | + | |
10667 | +/* dynop.c */ | |
10668 | +struct au_branch; | |
10669 | +void au_dy_put(struct au_dykey *key); | |
10670 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
10671 | + struct inode *h_inode); | |
b752ccd1 | 10672 | +int au_dy_irefresh(struct inode *inode); |
4a4d8108 | 10673 | +void au_dy_arefresh(int do_dio); |
4a4d8108 AM |
10674 | + |
10675 | +void __init au_dy_init(void); | |
10676 | +void au_dy_fin(void); | |
10677 | + | |
4a4d8108 AM |
10678 | +#endif /* __KERNEL__ */ |
10679 | +#endif /* __AUFS_DYNOP_H__ */ | |
7f207e10 AM |
10680 | diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c |
10681 | --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 10682 | +++ linux/fs/aufs/export.c 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 10683 | @@ -0,0 +1,832 @@ |
4a4d8108 | 10684 | +/* |
2000de60 | 10685 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
10686 | + * |
10687 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10688 | + * it under the terms of the GNU General Public License as published by | |
10689 | + * the Free Software Foundation; either version 2 of the License, or | |
10690 | + * (at your option) any later version. | |
10691 | + * | |
10692 | + * This program is distributed in the hope that it will be useful, | |
10693 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10694 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10695 | + * GNU General Public License for more details. | |
10696 | + * | |
10697 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10698 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
10699 | + */ |
10700 | + | |
10701 | +/* | |
10702 | + * export via nfs | |
10703 | + */ | |
10704 | + | |
10705 | +#include <linux/exportfs.h> | |
7eafdf33 | 10706 | +#include <linux/fs_struct.h> |
4a4d8108 AM |
10707 | +#include <linux/namei.h> |
10708 | +#include <linux/nsproxy.h> | |
10709 | +#include <linux/random.h> | |
10710 | +#include <linux/writeback.h> | |
7eafdf33 | 10711 | +#include "../fs/mount.h" |
4a4d8108 AM |
10712 | +#include "aufs.h" |
10713 | + | |
10714 | +union conv { | |
10715 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10716 | + __u32 a[2]; | |
10717 | +#else | |
10718 | + __u32 a[1]; | |
10719 | +#endif | |
10720 | + ino_t ino; | |
10721 | +}; | |
10722 | + | |
10723 | +static ino_t decode_ino(__u32 *a) | |
10724 | +{ | |
10725 | + union conv u; | |
10726 | + | |
10727 | + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a)); | |
10728 | + u.a[0] = a[0]; | |
10729 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10730 | + u.a[1] = a[1]; | |
10731 | +#endif | |
10732 | + return u.ino; | |
10733 | +} | |
10734 | + | |
10735 | +static void encode_ino(__u32 *a, ino_t ino) | |
10736 | +{ | |
10737 | + union conv u; | |
10738 | + | |
10739 | + u.ino = ino; | |
10740 | + a[0] = u.a[0]; | |
10741 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10742 | + a[1] = u.a[1]; | |
10743 | +#endif | |
10744 | +} | |
10745 | + | |
10746 | +/* NFS file handle */ | |
10747 | +enum { | |
10748 | + Fh_br_id, | |
10749 | + Fh_sigen, | |
10750 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10751 | + /* support 64bit inode number */ | |
10752 | + Fh_ino1, | |
10753 | + Fh_ino2, | |
10754 | + Fh_dir_ino1, | |
10755 | + Fh_dir_ino2, | |
10756 | +#else | |
10757 | + Fh_ino1, | |
10758 | + Fh_dir_ino1, | |
10759 | +#endif | |
10760 | + Fh_igen, | |
10761 | + Fh_h_type, | |
10762 | + Fh_tail, | |
10763 | + | |
10764 | + Fh_ino = Fh_ino1, | |
10765 | + Fh_dir_ino = Fh_dir_ino1 | |
10766 | +}; | |
10767 | + | |
10768 | +static int au_test_anon(struct dentry *dentry) | |
10769 | +{ | |
027c5e7a | 10770 | + /* note: read d_flags without d_lock */ |
4a4d8108 AM |
10771 | + return !!(dentry->d_flags & DCACHE_DISCONNECTED); |
10772 | +} | |
10773 | + | |
a2a7ad62 AM |
10774 | +int au_test_nfsd(void) |
10775 | +{ | |
10776 | + int ret; | |
10777 | + struct task_struct *tsk = current; | |
10778 | + char comm[sizeof(tsk->comm)]; | |
10779 | + | |
10780 | + ret = 0; | |
10781 | + if (tsk->flags & PF_KTHREAD) { | |
10782 | + get_task_comm(comm, tsk); | |
10783 | + ret = !strcmp(comm, "nfsd"); | |
10784 | + } | |
10785 | + | |
10786 | + return ret; | |
10787 | +} | |
10788 | + | |
4a4d8108 AM |
10789 | +/* ---------------------------------------------------------------------- */ |
10790 | +/* inode generation external table */ | |
10791 | + | |
b752ccd1 | 10792 | +void au_xigen_inc(struct inode *inode) |
4a4d8108 | 10793 | +{ |
4a4d8108 AM |
10794 | + loff_t pos; |
10795 | + ssize_t sz; | |
10796 | + __u32 igen; | |
10797 | + struct super_block *sb; | |
10798 | + struct au_sbinfo *sbinfo; | |
10799 | + | |
4a4d8108 | 10800 | + sb = inode->i_sb; |
b752ccd1 | 10801 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); |
1facf9fc | 10802 | + |
b752ccd1 | 10803 | + sbinfo = au_sbi(sb); |
1facf9fc | 10804 | + pos = inode->i_ino; |
10805 | + pos *= sizeof(igen); | |
10806 | + igen = inode->i_generation + 1; | |
1facf9fc | 10807 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen, |
10808 | + sizeof(igen), &pos); | |
10809 | + if (sz == sizeof(igen)) | |
b752ccd1 | 10810 | + return; /* success */ |
1facf9fc | 10811 | + |
b752ccd1 | 10812 | + if (unlikely(sz >= 0)) |
1facf9fc | 10813 | + AuIOErr("xigen error (%zd)\n", sz); |
1facf9fc | 10814 | +} |
10815 | + | |
10816 | +int au_xigen_new(struct inode *inode) | |
10817 | +{ | |
10818 | + int err; | |
10819 | + loff_t pos; | |
10820 | + ssize_t sz; | |
10821 | + struct super_block *sb; | |
10822 | + struct au_sbinfo *sbinfo; | |
10823 | + struct file *file; | |
10824 | + | |
10825 | + err = 0; | |
10826 | + /* todo: dirty, at mount time */ | |
10827 | + if (inode->i_ino == AUFS_ROOT_INO) | |
10828 | + goto out; | |
10829 | + sb = inode->i_sb; | |
dece6358 | 10830 | + SiMustAnyLock(sb); |
1facf9fc | 10831 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) |
10832 | + goto out; | |
10833 | + | |
10834 | + err = -EFBIG; | |
10835 | + pos = inode->i_ino; | |
10836 | + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) { | |
10837 | + AuIOErr1("too large i%lld\n", pos); | |
10838 | + goto out; | |
10839 | + } | |
10840 | + pos *= sizeof(inode->i_generation); | |
10841 | + | |
10842 | + err = 0; | |
10843 | + sbinfo = au_sbi(sb); | |
10844 | + file = sbinfo->si_xigen; | |
10845 | + BUG_ON(!file); | |
10846 | + | |
c06a8ce3 | 10847 | + if (vfsub_f_size_read(file) |
1facf9fc | 10848 | + < pos + sizeof(inode->i_generation)) { |
10849 | + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next); | |
10850 | + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation, | |
10851 | + sizeof(inode->i_generation), &pos); | |
10852 | + } else | |
10853 | + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation, | |
10854 | + sizeof(inode->i_generation), &pos); | |
10855 | + if (sz == sizeof(inode->i_generation)) | |
10856 | + goto out; /* success */ | |
10857 | + | |
10858 | + err = sz; | |
10859 | + if (unlikely(sz >= 0)) { | |
10860 | + err = -EIO; | |
10861 | + AuIOErr("xigen error (%zd)\n", sz); | |
10862 | + } | |
10863 | + | |
4f0767ce | 10864 | +out: |
1facf9fc | 10865 | + return err; |
10866 | +} | |
10867 | + | |
10868 | +int au_xigen_set(struct super_block *sb, struct file *base) | |
10869 | +{ | |
10870 | + int err; | |
10871 | + struct au_sbinfo *sbinfo; | |
10872 | + struct file *file; | |
10873 | + | |
dece6358 AM |
10874 | + SiMustWriteLock(sb); |
10875 | + | |
1facf9fc | 10876 | + sbinfo = au_sbi(sb); |
10877 | + file = au_xino_create2(base, sbinfo->si_xigen); | |
10878 | + err = PTR_ERR(file); | |
10879 | + if (IS_ERR(file)) | |
10880 | + goto out; | |
10881 | + err = 0; | |
10882 | + if (sbinfo->si_xigen) | |
10883 | + fput(sbinfo->si_xigen); | |
10884 | + sbinfo->si_xigen = file; | |
10885 | + | |
4f0767ce | 10886 | +out: |
1facf9fc | 10887 | + return err; |
10888 | +} | |
10889 | + | |
10890 | +void au_xigen_clr(struct super_block *sb) | |
10891 | +{ | |
10892 | + struct au_sbinfo *sbinfo; | |
10893 | + | |
dece6358 AM |
10894 | + SiMustWriteLock(sb); |
10895 | + | |
1facf9fc | 10896 | + sbinfo = au_sbi(sb); |
10897 | + if (sbinfo->si_xigen) { | |
10898 | + fput(sbinfo->si_xigen); | |
10899 | + sbinfo->si_xigen = NULL; | |
10900 | + } | |
10901 | +} | |
10902 | + | |
10903 | +/* ---------------------------------------------------------------------- */ | |
10904 | + | |
10905 | +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino, | |
10906 | + ino_t dir_ino) | |
10907 | +{ | |
10908 | + struct dentry *dentry, *d; | |
10909 | + struct inode *inode; | |
10910 | + unsigned int sigen; | |
10911 | + | |
10912 | + dentry = NULL; | |
10913 | + inode = ilookup(sb, ino); | |
10914 | + if (!inode) | |
10915 | + goto out; | |
10916 | + | |
10917 | + dentry = ERR_PTR(-ESTALE); | |
10918 | + sigen = au_sigen(sb); | |
10919 | + if (unlikely(is_bad_inode(inode) | |
10920 | + || IS_DEADDIR(inode) | |
537831f9 | 10921 | + || sigen != au_iigen(inode, NULL))) |
1facf9fc | 10922 | + goto out_iput; |
10923 | + | |
10924 | + dentry = NULL; | |
10925 | + if (!dir_ino || S_ISDIR(inode->i_mode)) | |
10926 | + dentry = d_find_alias(inode); | |
10927 | + else { | |
027c5e7a | 10928 | + spin_lock(&inode->i_lock); |
c1595e42 | 10929 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 10930 | + spin_lock(&d->d_lock); |
1facf9fc | 10931 | + if (!au_test_anon(d) |
5527c038 | 10932 | + && d_inode(d->d_parent)->i_ino == dir_ino) { |
027c5e7a AM |
10933 | + dentry = dget_dlock(d); |
10934 | + spin_unlock(&d->d_lock); | |
1facf9fc | 10935 | + break; |
10936 | + } | |
027c5e7a AM |
10937 | + spin_unlock(&d->d_lock); |
10938 | + } | |
10939 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 10940 | + } |
027c5e7a | 10941 | + if (unlikely(dentry && au_digen_test(dentry, sigen))) { |
2cbb1c4b | 10942 | + /* need to refresh */ |
1facf9fc | 10943 | + dput(dentry); |
2cbb1c4b | 10944 | + dentry = NULL; |
1facf9fc | 10945 | + } |
10946 | + | |
4f0767ce | 10947 | +out_iput: |
1facf9fc | 10948 | + iput(inode); |
4f0767ce | 10949 | +out: |
2cbb1c4b | 10950 | + AuTraceErrPtr(dentry); |
1facf9fc | 10951 | + return dentry; |
10952 | +} | |
10953 | + | |
10954 | +/* ---------------------------------------------------------------------- */ | |
10955 | + | |
10956 | +/* todo: dirty? */ | |
10957 | +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */ | |
4a4d8108 AM |
10958 | + |
10959 | +struct au_compare_mnt_args { | |
10960 | + /* input */ | |
10961 | + struct super_block *sb; | |
10962 | + | |
10963 | + /* output */ | |
10964 | + struct vfsmount *mnt; | |
10965 | +}; | |
10966 | + | |
10967 | +static int au_compare_mnt(struct vfsmount *mnt, void *arg) | |
10968 | +{ | |
10969 | + struct au_compare_mnt_args *a = arg; | |
10970 | + | |
10971 | + if (mnt->mnt_sb != a->sb) | |
10972 | + return 0; | |
10973 | + a->mnt = mntget(mnt); | |
10974 | + return 1; | |
10975 | +} | |
10976 | + | |
1facf9fc | 10977 | +static struct vfsmount *au_mnt_get(struct super_block *sb) |
10978 | +{ | |
4a4d8108 | 10979 | + int err; |
7eafdf33 | 10980 | + struct path root; |
4a4d8108 AM |
10981 | + struct au_compare_mnt_args args = { |
10982 | + .sb = sb | |
10983 | + }; | |
1facf9fc | 10984 | + |
7eafdf33 | 10985 | + get_fs_root(current->fs, &root); |
523b37e3 | 10986 | + rcu_read_lock(); |
7eafdf33 | 10987 | + err = iterate_mounts(au_compare_mnt, &args, root.mnt); |
523b37e3 | 10988 | + rcu_read_unlock(); |
7eafdf33 | 10989 | + path_put(&root); |
4a4d8108 AM |
10990 | + AuDebugOn(!err); |
10991 | + AuDebugOn(!args.mnt); | |
10992 | + return args.mnt; | |
1facf9fc | 10993 | +} |
10994 | + | |
10995 | +struct au_nfsd_si_lock { | |
4a4d8108 | 10996 | + unsigned int sigen; |
027c5e7a | 10997 | + aufs_bindex_t bindex, br_id; |
1facf9fc | 10998 | + unsigned char force_lock; |
10999 | +}; | |
11000 | + | |
027c5e7a AM |
11001 | +static int si_nfsd_read_lock(struct super_block *sb, |
11002 | + struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 11003 | +{ |
027c5e7a | 11004 | + int err; |
1facf9fc | 11005 | + aufs_bindex_t bindex; |
11006 | + | |
11007 | + si_read_lock(sb, AuLock_FLUSH); | |
11008 | + | |
11009 | + /* branch id may be wrapped around */ | |
027c5e7a | 11010 | + err = 0; |
1facf9fc | 11011 | + bindex = au_br_index(sb, nsi_lock->br_id); |
11012 | + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb)) | |
11013 | + goto out; /* success */ | |
11014 | + | |
027c5e7a AM |
11015 | + err = -ESTALE; |
11016 | + bindex = -1; | |
1facf9fc | 11017 | + if (!nsi_lock->force_lock) |
11018 | + si_read_unlock(sb); | |
1facf9fc | 11019 | + |
4f0767ce | 11020 | +out: |
027c5e7a AM |
11021 | + nsi_lock->bindex = bindex; |
11022 | + return err; | |
1facf9fc | 11023 | +} |
11024 | + | |
11025 | +struct find_name_by_ino { | |
392086de | 11026 | + struct dir_context ctx; |
1facf9fc | 11027 | + int called, found; |
11028 | + ino_t ino; | |
11029 | + char *name; | |
11030 | + int namelen; | |
11031 | +}; | |
11032 | + | |
11033 | +static int | |
392086de AM |
11034 | +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen, |
11035 | + loff_t offset, u64 ino, unsigned int d_type) | |
1facf9fc | 11036 | +{ |
392086de AM |
11037 | + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino, |
11038 | + ctx); | |
1facf9fc | 11039 | + |
11040 | + a->called++; | |
11041 | + if (a->ino != ino) | |
11042 | + return 0; | |
11043 | + | |
11044 | + memcpy(a->name, name, namelen); | |
11045 | + a->namelen = namelen; | |
11046 | + a->found = 1; | |
11047 | + return 1; | |
11048 | +} | |
11049 | + | |
11050 | +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino, | |
11051 | + struct au_nfsd_si_lock *nsi_lock) | |
11052 | +{ | |
11053 | + struct dentry *dentry, *parent; | |
11054 | + struct file *file; | |
11055 | + struct inode *dir; | |
392086de AM |
11056 | + struct find_name_by_ino arg = { |
11057 | + .ctx = { | |
2000de60 | 11058 | + .actor = find_name_by_ino |
392086de AM |
11059 | + } |
11060 | + }; | |
1facf9fc | 11061 | + int err; |
11062 | + | |
11063 | + parent = path->dentry; | |
11064 | + if (nsi_lock) | |
11065 | + si_read_unlock(parent->d_sb); | |
4a4d8108 | 11066 | + file = vfsub_dentry_open(path, au_dir_roflags); |
1facf9fc | 11067 | + dentry = (void *)file; |
11068 | + if (IS_ERR(file)) | |
11069 | + goto out; | |
11070 | + | |
11071 | + dentry = ERR_PTR(-ENOMEM); | |
537831f9 | 11072 | + arg.name = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 11073 | + if (unlikely(!arg.name)) |
11074 | + goto out_file; | |
11075 | + arg.ino = ino; | |
11076 | + arg.found = 0; | |
11077 | + do { | |
11078 | + arg.called = 0; | |
11079 | + /* smp_mb(); */ | |
392086de | 11080 | + err = vfsub_iterate_dir(file, &arg.ctx); |
1facf9fc | 11081 | + } while (!err && !arg.found && arg.called); |
11082 | + dentry = ERR_PTR(err); | |
11083 | + if (unlikely(err)) | |
11084 | + goto out_name; | |
1716fcea AM |
11085 | + /* instead of ENOENT */ |
11086 | + dentry = ERR_PTR(-ESTALE); | |
1facf9fc | 11087 | + if (!arg.found) |
11088 | + goto out_name; | |
11089 | + | |
b4510431 | 11090 | + /* do not call vfsub_lkup_one() */ |
5527c038 | 11091 | + dir = d_inode(parent); |
1facf9fc | 11092 | + mutex_lock(&dir->i_mutex); |
11093 | + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen); | |
11094 | + mutex_unlock(&dir->i_mutex); | |
11095 | + AuTraceErrPtr(dentry); | |
11096 | + if (IS_ERR(dentry)) | |
11097 | + goto out_name; | |
11098 | + AuDebugOn(au_test_anon(dentry)); | |
5527c038 | 11099 | + if (unlikely(d_really_is_negative(dentry))) { |
1facf9fc | 11100 | + dput(dentry); |
11101 | + dentry = ERR_PTR(-ENOENT); | |
11102 | + } | |
11103 | + | |
4f0767ce | 11104 | +out_name: |
537831f9 | 11105 | + free_page((unsigned long)arg.name); |
4f0767ce | 11106 | +out_file: |
1facf9fc | 11107 | + fput(file); |
4f0767ce | 11108 | +out: |
1facf9fc | 11109 | + if (unlikely(nsi_lock |
11110 | + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0)) | |
11111 | + if (!IS_ERR(dentry)) { | |
11112 | + dput(dentry); | |
11113 | + dentry = ERR_PTR(-ESTALE); | |
11114 | + } | |
11115 | + AuTraceErrPtr(dentry); | |
11116 | + return dentry; | |
11117 | +} | |
11118 | + | |
11119 | +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino, | |
11120 | + ino_t dir_ino, | |
11121 | + struct au_nfsd_si_lock *nsi_lock) | |
11122 | +{ | |
11123 | + struct dentry *dentry; | |
11124 | + struct path path; | |
11125 | + | |
11126 | + if (dir_ino != AUFS_ROOT_INO) { | |
11127 | + path.dentry = decode_by_ino(sb, dir_ino, 0); | |
11128 | + dentry = path.dentry; | |
11129 | + if (!path.dentry || IS_ERR(path.dentry)) | |
11130 | + goto out; | |
11131 | + AuDebugOn(au_test_anon(path.dentry)); | |
11132 | + } else | |
11133 | + path.dentry = dget(sb->s_root); | |
11134 | + | |
11135 | + path.mnt = au_mnt_get(sb); | |
11136 | + dentry = au_lkup_by_ino(&path, ino, nsi_lock); | |
11137 | + path_put(&path); | |
11138 | + | |
4f0767ce | 11139 | +out: |
1facf9fc | 11140 | + AuTraceErrPtr(dentry); |
11141 | + return dentry; | |
11142 | +} | |
11143 | + | |
11144 | +/* ---------------------------------------------------------------------- */ | |
11145 | + | |
11146 | +static int h_acceptable(void *expv, struct dentry *dentry) | |
11147 | +{ | |
11148 | + return 1; | |
11149 | +} | |
11150 | + | |
11151 | +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath, | |
11152 | + char *buf, int len, struct super_block *sb) | |
11153 | +{ | |
11154 | + char *p; | |
11155 | + int n; | |
11156 | + struct path path; | |
11157 | + | |
11158 | + p = d_path(h_rootpath, buf, len); | |
11159 | + if (IS_ERR(p)) | |
11160 | + goto out; | |
11161 | + n = strlen(p); | |
11162 | + | |
11163 | + path.mnt = h_rootpath->mnt; | |
11164 | + path.dentry = h_parent; | |
11165 | + p = d_path(&path, buf, len); | |
11166 | + if (IS_ERR(p)) | |
11167 | + goto out; | |
11168 | + if (n != 1) | |
11169 | + p += n; | |
11170 | + | |
11171 | + path.mnt = au_mnt_get(sb); | |
11172 | + path.dentry = sb->s_root; | |
11173 | + p = d_path(&path, buf, len - strlen(p)); | |
11174 | + mntput(path.mnt); | |
11175 | + if (IS_ERR(p)) | |
11176 | + goto out; | |
11177 | + if (n != 1) | |
11178 | + p[strlen(p)] = '/'; | |
11179 | + | |
4f0767ce | 11180 | +out: |
1facf9fc | 11181 | + AuTraceErrPtr(p); |
11182 | + return p; | |
11183 | +} | |
11184 | + | |
11185 | +static | |
027c5e7a AM |
11186 | +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh, |
11187 | + int fh_len, struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 11188 | +{ |
11189 | + struct dentry *dentry, *h_parent, *root; | |
11190 | + struct super_block *h_sb; | |
11191 | + char *pathname, *p; | |
11192 | + struct vfsmount *h_mnt; | |
11193 | + struct au_branch *br; | |
11194 | + int err; | |
11195 | + struct path path; | |
11196 | + | |
027c5e7a | 11197 | + br = au_sbr(sb, nsi_lock->bindex); |
86dc4139 | 11198 | + h_mnt = au_br_mnt(br); |
1facf9fc | 11199 | + h_sb = h_mnt->mnt_sb; |
11200 | + /* todo: call lower fh_to_dentry()? fh_to_parent()? */ | |
11201 | + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail), | |
11202 | + fh_len - Fh_tail, fh[Fh_h_type], | |
11203 | + h_acceptable, /*context*/NULL); | |
11204 | + dentry = h_parent; | |
11205 | + if (unlikely(!h_parent || IS_ERR(h_parent))) { | |
11206 | + AuWarn1("%s decode_fh failed, %ld\n", | |
11207 | + au_sbtype(h_sb), PTR_ERR(h_parent)); | |
11208 | + goto out; | |
11209 | + } | |
11210 | + dentry = NULL; | |
11211 | + if (unlikely(au_test_anon(h_parent))) { | |
11212 | + AuWarn1("%s decode_fh returned a disconnected dentry\n", | |
11213 | + au_sbtype(h_sb)); | |
11214 | + goto out_h_parent; | |
11215 | + } | |
11216 | + | |
11217 | + dentry = ERR_PTR(-ENOMEM); | |
11218 | + pathname = (void *)__get_free_page(GFP_NOFS); | |
11219 | + if (unlikely(!pathname)) | |
11220 | + goto out_h_parent; | |
11221 | + | |
11222 | + root = sb->s_root; | |
11223 | + path.mnt = h_mnt; | |
11224 | + di_read_lock_parent(root, !AuLock_IR); | |
027c5e7a | 11225 | + path.dentry = au_h_dptr(root, nsi_lock->bindex); |
1facf9fc | 11226 | + di_read_unlock(root, !AuLock_IR); |
11227 | + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb); | |
11228 | + dentry = (void *)p; | |
11229 | + if (IS_ERR(p)) | |
11230 | + goto out_pathname; | |
11231 | + | |
11232 | + si_read_unlock(sb); | |
11233 | + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | |
11234 | + dentry = ERR_PTR(err); | |
11235 | + if (unlikely(err)) | |
11236 | + goto out_relock; | |
11237 | + | |
11238 | + dentry = ERR_PTR(-ENOENT); | |
11239 | + AuDebugOn(au_test_anon(path.dentry)); | |
5527c038 | 11240 | + if (unlikely(d_really_is_negative(path.dentry))) |
1facf9fc | 11241 | + goto out_path; |
11242 | + | |
5527c038 | 11243 | + if (ino != d_inode(path.dentry)->i_ino) |
1facf9fc | 11244 | + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL); |
11245 | + else | |
11246 | + dentry = dget(path.dentry); | |
11247 | + | |
4f0767ce | 11248 | +out_path: |
1facf9fc | 11249 | + path_put(&path); |
4f0767ce | 11250 | +out_relock: |
1facf9fc | 11251 | + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0)) |
11252 | + if (!IS_ERR(dentry)) { | |
11253 | + dput(dentry); | |
11254 | + dentry = ERR_PTR(-ESTALE); | |
11255 | + } | |
4f0767ce | 11256 | +out_pathname: |
1facf9fc | 11257 | + free_page((unsigned long)pathname); |
4f0767ce | 11258 | +out_h_parent: |
1facf9fc | 11259 | + dput(h_parent); |
4f0767ce | 11260 | +out: |
1facf9fc | 11261 | + AuTraceErrPtr(dentry); |
11262 | + return dentry; | |
11263 | +} | |
11264 | + | |
11265 | +/* ---------------------------------------------------------------------- */ | |
11266 | + | |
11267 | +static struct dentry * | |
11268 | +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, | |
11269 | + int fh_type) | |
11270 | +{ | |
11271 | + struct dentry *dentry; | |
11272 | + __u32 *fh = fid->raw; | |
027c5e7a | 11273 | + struct au_branch *br; |
1facf9fc | 11274 | + ino_t ino, dir_ino; |
1facf9fc | 11275 | + struct au_nfsd_si_lock nsi_lock = { |
1facf9fc | 11276 | + .force_lock = 0 |
11277 | + }; | |
11278 | + | |
1facf9fc | 11279 | + dentry = ERR_PTR(-ESTALE); |
4a4d8108 AM |
11280 | + /* it should never happen, but the file handle is unreliable */ |
11281 | + if (unlikely(fh_len < Fh_tail)) | |
11282 | + goto out; | |
11283 | + nsi_lock.sigen = fh[Fh_sigen]; | |
11284 | + nsi_lock.br_id = fh[Fh_br_id]; | |
11285 | + | |
1facf9fc | 11286 | + /* branch id may be wrapped around */ |
027c5e7a AM |
11287 | + br = NULL; |
11288 | + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock))) | |
1facf9fc | 11289 | + goto out; |
11290 | + nsi_lock.force_lock = 1; | |
11291 | + | |
11292 | + /* is this inode still cached? */ | |
11293 | + ino = decode_ino(fh + Fh_ino); | |
4a4d8108 AM |
11294 | + /* it should never happen */ |
11295 | + if (unlikely(ino == AUFS_ROOT_INO)) | |
11296 | + goto out; | |
11297 | + | |
1facf9fc | 11298 | + dir_ino = decode_ino(fh + Fh_dir_ino); |
11299 | + dentry = decode_by_ino(sb, ino, dir_ino); | |
11300 | + if (IS_ERR(dentry)) | |
11301 | + goto out_unlock; | |
11302 | + if (dentry) | |
11303 | + goto accept; | |
11304 | + | |
11305 | + /* is the parent dir cached? */ | |
027c5e7a AM |
11306 | + br = au_sbr(sb, nsi_lock.bindex); |
11307 | + atomic_inc(&br->br_count); | |
1facf9fc | 11308 | + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock); |
11309 | + if (IS_ERR(dentry)) | |
11310 | + goto out_unlock; | |
11311 | + if (dentry) | |
11312 | + goto accept; | |
11313 | + | |
11314 | + /* lookup path */ | |
027c5e7a | 11315 | + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock); |
1facf9fc | 11316 | + if (IS_ERR(dentry)) |
11317 | + goto out_unlock; | |
11318 | + if (unlikely(!dentry)) | |
11319 | + /* todo?: make it ESTALE */ | |
11320 | + goto out_unlock; | |
11321 | + | |
4f0767ce | 11322 | +accept: |
027c5e7a | 11323 | + if (!au_digen_test(dentry, au_sigen(sb)) |
5527c038 | 11324 | + && d_inode(dentry)->i_generation == fh[Fh_igen]) |
1facf9fc | 11325 | + goto out_unlock; /* success */ |
11326 | + | |
11327 | + dput(dentry); | |
11328 | + dentry = ERR_PTR(-ESTALE); | |
4f0767ce | 11329 | +out_unlock: |
027c5e7a AM |
11330 | + if (br) |
11331 | + atomic_dec(&br->br_count); | |
1facf9fc | 11332 | + si_read_unlock(sb); |
4f0767ce | 11333 | +out: |
1facf9fc | 11334 | + AuTraceErrPtr(dentry); |
11335 | + return dentry; | |
11336 | +} | |
11337 | + | |
11338 | +#if 0 /* reserved for future use */ | |
11339 | +/* support subtreecheck option */ | |
11340 | +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid, | |
11341 | + int fh_len, int fh_type) | |
11342 | +{ | |
11343 | + struct dentry *parent; | |
11344 | + __u32 *fh = fid->raw; | |
11345 | + ino_t dir_ino; | |
11346 | + | |
11347 | + dir_ino = decode_ino(fh + Fh_dir_ino); | |
11348 | + parent = decode_by_ino(sb, dir_ino, 0); | |
11349 | + if (IS_ERR(parent)) | |
11350 | + goto out; | |
11351 | + if (!parent) | |
11352 | + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]), | |
11353 | + dir_ino, fh, fh_len); | |
11354 | + | |
4f0767ce | 11355 | +out: |
1facf9fc | 11356 | + AuTraceErrPtr(parent); |
11357 | + return parent; | |
11358 | +} | |
11359 | +#endif | |
11360 | + | |
11361 | +/* ---------------------------------------------------------------------- */ | |
11362 | + | |
0c3ec466 AM |
11363 | +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, |
11364 | + struct inode *dir) | |
1facf9fc | 11365 | +{ |
11366 | + int err; | |
0c3ec466 | 11367 | + aufs_bindex_t bindex; |
1facf9fc | 11368 | + struct super_block *sb, *h_sb; |
0c3ec466 AM |
11369 | + struct dentry *dentry, *parent, *h_parent; |
11370 | + struct inode *h_dir; | |
1facf9fc | 11371 | + struct au_branch *br; |
11372 | + | |
1facf9fc | 11373 | + err = -ENOSPC; |
11374 | + if (unlikely(*max_len <= Fh_tail)) { | |
11375 | + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len); | |
11376 | + goto out; | |
11377 | + } | |
11378 | + | |
11379 | + err = FILEID_ROOT; | |
0c3ec466 AM |
11380 | + if (inode->i_ino == AUFS_ROOT_INO) { |
11381 | + AuDebugOn(inode->i_ino != AUFS_ROOT_INO); | |
1facf9fc | 11382 | + goto out; |
11383 | + } | |
11384 | + | |
1facf9fc | 11385 | + h_parent = NULL; |
0c3ec466 AM |
11386 | + sb = inode->i_sb; |
11387 | + err = si_read_lock(sb, AuLock_FLUSH); | |
027c5e7a AM |
11388 | + if (unlikely(err)) |
11389 | + goto out; | |
11390 | + | |
1facf9fc | 11391 | +#ifdef CONFIG_AUFS_DEBUG |
11392 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) | |
11393 | + AuWarn1("NFS-exporting requires xino\n"); | |
11394 | +#endif | |
027c5e7a | 11395 | + err = -EIO; |
0c3ec466 AM |
11396 | + parent = NULL; |
11397 | + ii_read_lock_child(inode); | |
11398 | + bindex = au_ibstart(inode); | |
11399 | + if (!dir) { | |
c1595e42 | 11400 | + dentry = d_find_any_alias(inode); |
0c3ec466 AM |
11401 | + if (unlikely(!dentry)) |
11402 | + goto out_unlock; | |
11403 | + AuDebugOn(au_test_anon(dentry)); | |
11404 | + parent = dget_parent(dentry); | |
11405 | + dput(dentry); | |
11406 | + if (unlikely(!parent)) | |
11407 | + goto out_unlock; | |
5527c038 JR |
11408 | + if (d_really_is_positive(parent)) |
11409 | + dir = d_inode(parent); | |
1facf9fc | 11410 | + } |
0c3ec466 AM |
11411 | + |
11412 | + ii_read_lock_parent(dir); | |
11413 | + h_dir = au_h_iptr(dir, bindex); | |
11414 | + ii_read_unlock(dir); | |
11415 | + if (unlikely(!h_dir)) | |
11416 | + goto out_parent; | |
c1595e42 | 11417 | + h_parent = d_find_any_alias(h_dir); |
1facf9fc | 11418 | + if (unlikely(!h_parent)) |
0c3ec466 | 11419 | + goto out_hparent; |
1facf9fc | 11420 | + |
11421 | + err = -EPERM; | |
11422 | + br = au_sbr(sb, bindex); | |
86dc4139 | 11423 | + h_sb = au_br_sb(br); |
1facf9fc | 11424 | + if (unlikely(!h_sb->s_export_op)) { |
11425 | + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb)); | |
0c3ec466 | 11426 | + goto out_hparent; |
1facf9fc | 11427 | + } |
11428 | + | |
11429 | + fh[Fh_br_id] = br->br_id; | |
11430 | + fh[Fh_sigen] = au_sigen(sb); | |
11431 | + encode_ino(fh + Fh_ino, inode->i_ino); | |
0c3ec466 | 11432 | + encode_ino(fh + Fh_dir_ino, dir->i_ino); |
1facf9fc | 11433 | + fh[Fh_igen] = inode->i_generation; |
11434 | + | |
11435 | + *max_len -= Fh_tail; | |
11436 | + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail), | |
11437 | + max_len, | |
11438 | + /*connectable or subtreecheck*/0); | |
11439 | + err = fh[Fh_h_type]; | |
11440 | + *max_len += Fh_tail; | |
11441 | + /* todo: macros? */ | |
1716fcea | 11442 | + if (err != FILEID_INVALID) |
1facf9fc | 11443 | + err = 99; |
11444 | + else | |
11445 | + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb)); | |
11446 | + | |
0c3ec466 | 11447 | +out_hparent: |
1facf9fc | 11448 | + dput(h_parent); |
0c3ec466 | 11449 | +out_parent: |
1facf9fc | 11450 | + dput(parent); |
0c3ec466 AM |
11451 | +out_unlock: |
11452 | + ii_read_unlock(inode); | |
11453 | + si_read_unlock(sb); | |
4f0767ce | 11454 | +out: |
1facf9fc | 11455 | + if (unlikely(err < 0)) |
1716fcea | 11456 | + err = FILEID_INVALID; |
1facf9fc | 11457 | + return err; |
11458 | +} | |
11459 | + | |
11460 | +/* ---------------------------------------------------------------------- */ | |
11461 | + | |
4a4d8108 AM |
11462 | +static int aufs_commit_metadata(struct inode *inode) |
11463 | +{ | |
11464 | + int err; | |
11465 | + aufs_bindex_t bindex; | |
11466 | + struct super_block *sb; | |
11467 | + struct inode *h_inode; | |
11468 | + int (*f)(struct inode *inode); | |
11469 | + | |
11470 | + sb = inode->i_sb; | |
e49829fe | 11471 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 AM |
11472 | + ii_write_lock_child(inode); |
11473 | + bindex = au_ibstart(inode); | |
11474 | + AuDebugOn(bindex < 0); | |
11475 | + h_inode = au_h_iptr(inode, bindex); | |
11476 | + | |
11477 | + f = h_inode->i_sb->s_export_op->commit_metadata; | |
11478 | + if (f) | |
11479 | + err = f(h_inode); | |
11480 | + else { | |
11481 | + struct writeback_control wbc = { | |
11482 | + .sync_mode = WB_SYNC_ALL, | |
11483 | + .nr_to_write = 0 /* metadata only */ | |
11484 | + }; | |
11485 | + | |
11486 | + err = sync_inode(h_inode, &wbc); | |
11487 | + } | |
11488 | + | |
11489 | + au_cpup_attr_timesizes(inode); | |
11490 | + ii_write_unlock(inode); | |
11491 | + si_read_unlock(sb); | |
11492 | + return err; | |
11493 | +} | |
11494 | + | |
11495 | +/* ---------------------------------------------------------------------- */ | |
11496 | + | |
1facf9fc | 11497 | +static struct export_operations aufs_export_op = { |
4a4d8108 | 11498 | + .fh_to_dentry = aufs_fh_to_dentry, |
1facf9fc | 11499 | + /* .fh_to_parent = aufs_fh_to_parent, */ |
4a4d8108 AM |
11500 | + .encode_fh = aufs_encode_fh, |
11501 | + .commit_metadata = aufs_commit_metadata | |
1facf9fc | 11502 | +}; |
11503 | + | |
11504 | +void au_export_init(struct super_block *sb) | |
11505 | +{ | |
11506 | + struct au_sbinfo *sbinfo; | |
11507 | + __u32 u; | |
11508 | + | |
11509 | + sb->s_export_op = &aufs_export_op; | |
11510 | + sbinfo = au_sbi(sb); | |
11511 | + sbinfo->si_xigen = NULL; | |
11512 | + get_random_bytes(&u, sizeof(u)); | |
11513 | + BUILD_BUG_ON(sizeof(u) != sizeof(int)); | |
11514 | + atomic_set(&sbinfo->si_xigen_next, u); | |
11515 | +} | |
076b876e AM |
11516 | diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c |
11517 | --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 11518 | +++ linux/fs/aufs/fhsm.c 2015-09-24 10:47:58.251386326 +0200 |
c1595e42 | 11519 | @@ -0,0 +1,426 @@ |
076b876e | 11520 | +/* |
2000de60 | 11521 | + * Copyright (C) 2011-2015 Junjiro R. Okajima |
076b876e AM |
11522 | + * |
11523 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11524 | + * it under the terms of the GNU General Public License as published by | |
11525 | + * the Free Software Foundation; either version 2 of the License, or | |
11526 | + * (at your option) any later version. | |
11527 | + * | |
11528 | + * This program is distributed in the hope that it will be useful, | |
11529 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11530 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11531 | + * GNU General Public License for more details. | |
11532 | + * | |
11533 | + * You should have received a copy of the GNU General Public License | |
11534 | + * along with this program; if not, write to the Free Software | |
11535 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
11536 | + */ | |
11537 | + | |
11538 | +/* | |
11539 | + * File-based Hierarchy Storage Management | |
11540 | + */ | |
11541 | + | |
11542 | +#include <linux/anon_inodes.h> | |
11543 | +#include <linux/poll.h> | |
11544 | +#include <linux/seq_file.h> | |
11545 | +#include <linux/statfs.h> | |
11546 | +#include "aufs.h" | |
11547 | + | |
c1595e42 JR |
11548 | +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb) |
11549 | +{ | |
11550 | + struct au_sbinfo *sbinfo; | |
11551 | + struct au_fhsm *fhsm; | |
11552 | + | |
11553 | + SiMustAnyLock(sb); | |
11554 | + | |
11555 | + sbinfo = au_sbi(sb); | |
11556 | + fhsm = &sbinfo->si_fhsm; | |
11557 | + AuDebugOn(!fhsm); | |
11558 | + return fhsm->fhsm_bottom; | |
11559 | +} | |
11560 | + | |
11561 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex) | |
11562 | +{ | |
11563 | + struct au_sbinfo *sbinfo; | |
11564 | + struct au_fhsm *fhsm; | |
11565 | + | |
11566 | + SiMustWriteLock(sb); | |
11567 | + | |
11568 | + sbinfo = au_sbi(sb); | |
11569 | + fhsm = &sbinfo->si_fhsm; | |
11570 | + AuDebugOn(!fhsm); | |
11571 | + fhsm->fhsm_bottom = bindex; | |
11572 | +} | |
11573 | + | |
11574 | +/* ---------------------------------------------------------------------- */ | |
11575 | + | |
076b876e AM |
11576 | +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br) |
11577 | +{ | |
11578 | + struct au_br_fhsm *bf; | |
11579 | + | |
11580 | + bf = br->br_fhsm; | |
11581 | + MtxMustLock(&bf->bf_lock); | |
11582 | + | |
11583 | + return !bf->bf_readable | |
11584 | + || time_after(jiffies, | |
11585 | + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire); | |
11586 | +} | |
11587 | + | |
11588 | +/* ---------------------------------------------------------------------- */ | |
11589 | + | |
11590 | +static void au_fhsm_notify(struct super_block *sb, int val) | |
11591 | +{ | |
11592 | + struct au_sbinfo *sbinfo; | |
11593 | + struct au_fhsm *fhsm; | |
11594 | + | |
11595 | + SiMustAnyLock(sb); | |
11596 | + | |
11597 | + sbinfo = au_sbi(sb); | |
11598 | + fhsm = &sbinfo->si_fhsm; | |
11599 | + if (au_fhsm_pid(fhsm) | |
11600 | + && atomic_read(&fhsm->fhsm_readable) != -1) { | |
11601 | + atomic_set(&fhsm->fhsm_readable, val); | |
11602 | + if (val) | |
11603 | + wake_up(&fhsm->fhsm_wqh); | |
11604 | + } | |
11605 | +} | |
11606 | + | |
11607 | +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex, | |
11608 | + struct aufs_stfs *rstfs, int do_lock, int do_notify) | |
11609 | +{ | |
11610 | + int err; | |
11611 | + struct au_branch *br; | |
11612 | + struct au_br_fhsm *bf; | |
11613 | + | |
11614 | + br = au_sbr(sb, bindex); | |
11615 | + AuDebugOn(au_br_rdonly(br)); | |
11616 | + bf = br->br_fhsm; | |
11617 | + AuDebugOn(!bf); | |
11618 | + | |
11619 | + if (do_lock) | |
11620 | + mutex_lock(&bf->bf_lock); | |
11621 | + else | |
11622 | + MtxMustLock(&bf->bf_lock); | |
11623 | + | |
11624 | + /* sb->s_root for NFS is unreliable */ | |
11625 | + err = au_br_stfs(br, &bf->bf_stfs); | |
11626 | + if (unlikely(err)) { | |
11627 | + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err); | |
11628 | + goto out; | |
11629 | + } | |
11630 | + | |
11631 | + bf->bf_jiffy = jiffies; | |
11632 | + bf->bf_readable = 1; | |
11633 | + if (do_notify) | |
11634 | + au_fhsm_notify(sb, /*val*/1); | |
11635 | + if (rstfs) | |
11636 | + *rstfs = bf->bf_stfs; | |
11637 | + | |
11638 | +out: | |
11639 | + if (do_lock) | |
11640 | + mutex_unlock(&bf->bf_lock); | |
11641 | + au_fhsm_notify(sb, /*val*/1); | |
11642 | + | |
11643 | + return err; | |
11644 | +} | |
11645 | + | |
11646 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force) | |
11647 | +{ | |
11648 | + int err; | |
076b876e AM |
11649 | + struct au_sbinfo *sbinfo; |
11650 | + struct au_fhsm *fhsm; | |
11651 | + struct au_branch *br; | |
11652 | + struct au_br_fhsm *bf; | |
11653 | + | |
11654 | + AuDbg("b%d, force %d\n", bindex, force); | |
11655 | + SiMustAnyLock(sb); | |
11656 | + | |
11657 | + sbinfo = au_sbi(sb); | |
11658 | + fhsm = &sbinfo->si_fhsm; | |
c1595e42 JR |
11659 | + if (!au_ftest_si(sbinfo, FHSM) |
11660 | + || fhsm->fhsm_bottom == bindex) | |
076b876e AM |
11661 | + return; |
11662 | + | |
11663 | + br = au_sbr(sb, bindex); | |
11664 | + bf = br->br_fhsm; | |
11665 | + AuDebugOn(!bf); | |
11666 | + mutex_lock(&bf->bf_lock); | |
11667 | + if (force | |
11668 | + || au_fhsm_pid(fhsm) | |
11669 | + || au_fhsm_test_jiffy(sbinfo, br)) | |
11670 | + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0, | |
11671 | + /*do_notify*/1); | |
11672 | + mutex_unlock(&bf->bf_lock); | |
11673 | +} | |
11674 | + | |
11675 | +void au_fhsm_wrote_all(struct super_block *sb, int force) | |
11676 | +{ | |
11677 | + aufs_bindex_t bindex, bend; | |
11678 | + struct au_branch *br; | |
11679 | + | |
11680 | + /* exclude the bottom */ | |
c1595e42 | 11681 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11682 | + for (bindex = 0; bindex < bend; bindex++) { |
11683 | + br = au_sbr(sb, bindex); | |
11684 | + if (au_br_fhsm(br->br_perm)) | |
11685 | + au_fhsm_wrote(sb, bindex, force); | |
11686 | + } | |
11687 | +} | |
11688 | + | |
11689 | +/* ---------------------------------------------------------------------- */ | |
11690 | + | |
11691 | +static unsigned int au_fhsm_poll(struct file *file, | |
11692 | + struct poll_table_struct *wait) | |
11693 | +{ | |
11694 | + unsigned int mask; | |
11695 | + struct au_sbinfo *sbinfo; | |
11696 | + struct au_fhsm *fhsm; | |
11697 | + | |
11698 | + mask = 0; | |
11699 | + sbinfo = file->private_data; | |
11700 | + fhsm = &sbinfo->si_fhsm; | |
11701 | + poll_wait(file, &fhsm->fhsm_wqh, wait); | |
11702 | + if (atomic_read(&fhsm->fhsm_readable)) | |
11703 | + mask = POLLIN /* | POLLRDNORM */; | |
11704 | + | |
11705 | + AuTraceErr((int)mask); | |
11706 | + return mask; | |
11707 | +} | |
11708 | + | |
11709 | +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr, | |
11710 | + struct aufs_stfs *stfs, __s16 brid) | |
11711 | +{ | |
11712 | + int err; | |
11713 | + | |
11714 | + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs)); | |
11715 | + if (!err) | |
11716 | + err = __put_user(brid, &stbr->brid); | |
11717 | + if (unlikely(err)) | |
11718 | + err = -EFAULT; | |
11719 | + | |
11720 | + return err; | |
11721 | +} | |
11722 | + | |
11723 | +static ssize_t au_fhsm_do_read(struct super_block *sb, | |
11724 | + struct aufs_stbr __user *stbr, size_t count) | |
11725 | +{ | |
11726 | + ssize_t err; | |
11727 | + int nstbr; | |
11728 | + aufs_bindex_t bindex, bend; | |
11729 | + struct au_branch *br; | |
11730 | + struct au_br_fhsm *bf; | |
11731 | + | |
11732 | + /* except the bottom branch */ | |
11733 | + err = 0; | |
11734 | + nstbr = 0; | |
c1595e42 | 11735 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11736 | + for (bindex = 0; !err && bindex < bend; bindex++) { |
11737 | + br = au_sbr(sb, bindex); | |
11738 | + if (!au_br_fhsm(br->br_perm)) | |
11739 | + continue; | |
11740 | + | |
11741 | + bf = br->br_fhsm; | |
11742 | + mutex_lock(&bf->bf_lock); | |
11743 | + if (bf->bf_readable) { | |
11744 | + err = -EFAULT; | |
11745 | + if (count >= sizeof(*stbr)) | |
11746 | + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs, | |
11747 | + br->br_id); | |
11748 | + if (!err) { | |
11749 | + bf->bf_readable = 0; | |
11750 | + count -= sizeof(*stbr); | |
11751 | + nstbr++; | |
11752 | + } | |
11753 | + } | |
11754 | + mutex_unlock(&bf->bf_lock); | |
11755 | + } | |
11756 | + if (!err) | |
11757 | + err = sizeof(*stbr) * nstbr; | |
11758 | + | |
11759 | + return err; | |
11760 | +} | |
11761 | + | |
11762 | +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count, | |
11763 | + loff_t *pos) | |
11764 | +{ | |
11765 | + ssize_t err; | |
11766 | + int readable; | |
11767 | + aufs_bindex_t nfhsm, bindex, bend; | |
11768 | + struct au_sbinfo *sbinfo; | |
11769 | + struct au_fhsm *fhsm; | |
11770 | + struct au_branch *br; | |
11771 | + struct super_block *sb; | |
11772 | + | |
11773 | + err = 0; | |
11774 | + sbinfo = file->private_data; | |
11775 | + fhsm = &sbinfo->si_fhsm; | |
11776 | +need_data: | |
11777 | + spin_lock_irq(&fhsm->fhsm_wqh.lock); | |
11778 | + if (!atomic_read(&fhsm->fhsm_readable)) { | |
11779 | + if (vfsub_file_flags(file) & O_NONBLOCK) | |
11780 | + err = -EAGAIN; | |
11781 | + else | |
11782 | + err = wait_event_interruptible_locked_irq | |
11783 | + (fhsm->fhsm_wqh, | |
11784 | + atomic_read(&fhsm->fhsm_readable)); | |
11785 | + } | |
11786 | + spin_unlock_irq(&fhsm->fhsm_wqh.lock); | |
11787 | + if (unlikely(err)) | |
11788 | + goto out; | |
11789 | + | |
11790 | + /* sb may already be dead */ | |
11791 | + au_rw_read_lock(&sbinfo->si_rwsem); | |
11792 | + readable = atomic_read(&fhsm->fhsm_readable); | |
11793 | + if (readable > 0) { | |
11794 | + sb = sbinfo->si_sb; | |
11795 | + AuDebugOn(!sb); | |
11796 | + /* exclude the bottom branch */ | |
11797 | + nfhsm = 0; | |
c1595e42 | 11798 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11799 | + for (bindex = 0; bindex < bend; bindex++) { |
11800 | + br = au_sbr(sb, bindex); | |
11801 | + if (au_br_fhsm(br->br_perm)) | |
11802 | + nfhsm++; | |
11803 | + } | |
11804 | + err = -EMSGSIZE; | |
11805 | + if (nfhsm * sizeof(struct aufs_stbr) <= count) { | |
11806 | + atomic_set(&fhsm->fhsm_readable, 0); | |
11807 | + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf, | |
11808 | + count); | |
11809 | + } | |
11810 | + } | |
11811 | + au_rw_read_unlock(&sbinfo->si_rwsem); | |
11812 | + if (!readable) | |
11813 | + goto need_data; | |
11814 | + | |
11815 | +out: | |
11816 | + return err; | |
11817 | +} | |
11818 | + | |
11819 | +static int au_fhsm_release(struct inode *inode, struct file *file) | |
11820 | +{ | |
11821 | + struct au_sbinfo *sbinfo; | |
11822 | + struct au_fhsm *fhsm; | |
11823 | + | |
11824 | + /* sb may already be dead */ | |
11825 | + sbinfo = file->private_data; | |
11826 | + fhsm = &sbinfo->si_fhsm; | |
11827 | + spin_lock(&fhsm->fhsm_spin); | |
11828 | + fhsm->fhsm_pid = 0; | |
11829 | + spin_unlock(&fhsm->fhsm_spin); | |
11830 | + kobject_put(&sbinfo->si_kobj); | |
11831 | + | |
11832 | + return 0; | |
11833 | +} | |
11834 | + | |
11835 | +static const struct file_operations au_fhsm_fops = { | |
11836 | + .owner = THIS_MODULE, | |
11837 | + .llseek = noop_llseek, | |
11838 | + .read = au_fhsm_read, | |
11839 | + .poll = au_fhsm_poll, | |
11840 | + .release = au_fhsm_release | |
11841 | +}; | |
11842 | + | |
11843 | +int au_fhsm_fd(struct super_block *sb, int oflags) | |
11844 | +{ | |
11845 | + int err, fd; | |
11846 | + struct au_sbinfo *sbinfo; | |
11847 | + struct au_fhsm *fhsm; | |
11848 | + | |
11849 | + err = -EPERM; | |
11850 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
11851 | + goto out; | |
11852 | + | |
11853 | + err = -EINVAL; | |
11854 | + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK))) | |
11855 | + goto out; | |
11856 | + | |
11857 | + err = 0; | |
11858 | + sbinfo = au_sbi(sb); | |
11859 | + fhsm = &sbinfo->si_fhsm; | |
11860 | + spin_lock(&fhsm->fhsm_spin); | |
11861 | + if (!fhsm->fhsm_pid) | |
11862 | + fhsm->fhsm_pid = current->pid; | |
11863 | + else | |
11864 | + err = -EBUSY; | |
11865 | + spin_unlock(&fhsm->fhsm_spin); | |
11866 | + if (unlikely(err)) | |
11867 | + goto out; | |
11868 | + | |
11869 | + oflags |= O_RDONLY; | |
11870 | + /* oflags |= FMODE_NONOTIFY; */ | |
11871 | + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags); | |
11872 | + err = fd; | |
11873 | + if (unlikely(fd < 0)) | |
11874 | + goto out_pid; | |
11875 | + | |
11876 | + /* succeed reglardless 'fhsm' status */ | |
11877 | + kobject_get(&sbinfo->si_kobj); | |
11878 | + si_noflush_read_lock(sb); | |
11879 | + if (au_ftest_si(sbinfo, FHSM)) | |
11880 | + au_fhsm_wrote_all(sb, /*force*/0); | |
11881 | + si_read_unlock(sb); | |
11882 | + goto out; /* success */ | |
11883 | + | |
11884 | +out_pid: | |
11885 | + spin_lock(&fhsm->fhsm_spin); | |
11886 | + fhsm->fhsm_pid = 0; | |
11887 | + spin_unlock(&fhsm->fhsm_spin); | |
11888 | +out: | |
11889 | + AuTraceErr(err); | |
11890 | + return err; | |
11891 | +} | |
11892 | + | |
11893 | +/* ---------------------------------------------------------------------- */ | |
11894 | + | |
11895 | +int au_fhsm_br_alloc(struct au_branch *br) | |
11896 | +{ | |
11897 | + int err; | |
11898 | + | |
11899 | + err = 0; | |
11900 | + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS); | |
11901 | + if (br->br_fhsm) | |
11902 | + au_br_fhsm_init(br->br_fhsm); | |
11903 | + else | |
11904 | + err = -ENOMEM; | |
11905 | + | |
11906 | + return err; | |
11907 | +} | |
11908 | + | |
11909 | +/* ---------------------------------------------------------------------- */ | |
11910 | + | |
11911 | +void au_fhsm_fin(struct super_block *sb) | |
11912 | +{ | |
11913 | + au_fhsm_notify(sb, /*val*/-1); | |
11914 | +} | |
11915 | + | |
11916 | +void au_fhsm_init(struct au_sbinfo *sbinfo) | |
11917 | +{ | |
11918 | + struct au_fhsm *fhsm; | |
11919 | + | |
11920 | + fhsm = &sbinfo->si_fhsm; | |
11921 | + spin_lock_init(&fhsm->fhsm_spin); | |
11922 | + init_waitqueue_head(&fhsm->fhsm_wqh); | |
11923 | + atomic_set(&fhsm->fhsm_readable, 0); | |
11924 | + fhsm->fhsm_expire | |
11925 | + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC); | |
c1595e42 | 11926 | + fhsm->fhsm_bottom = -1; |
076b876e AM |
11927 | +} |
11928 | + | |
11929 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec) | |
11930 | +{ | |
11931 | + sbinfo->si_fhsm.fhsm_expire | |
11932 | + = msecs_to_jiffies(sec * MSEC_PER_SEC); | |
11933 | +} | |
11934 | + | |
11935 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo) | |
11936 | +{ | |
11937 | + unsigned int u; | |
11938 | + | |
11939 | + if (!au_ftest_si(sbinfo, FHSM)) | |
11940 | + return; | |
11941 | + | |
11942 | + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC; | |
11943 | + if (u != AUFS_FHSM_CACHE_DEF_SEC) | |
11944 | + seq_printf(seq, ",fhsm_sec=%u", u); | |
11945 | +} | |
7f207e10 AM |
11946 | diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c |
11947 | --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 11948 | +++ linux/fs/aufs/file.c 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 11949 | @@ -0,0 +1,841 @@ |
1facf9fc | 11950 | +/* |
2000de60 | 11951 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 11952 | + * |
11953 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11954 | + * it under the terms of the GNU General Public License as published by | |
11955 | + * the Free Software Foundation; either version 2 of the License, or | |
11956 | + * (at your option) any later version. | |
dece6358 AM |
11957 | + * |
11958 | + * This program is distributed in the hope that it will be useful, | |
11959 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11960 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11961 | + * GNU General Public License for more details. | |
11962 | + * | |
11963 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 11964 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 11965 | + */ |
11966 | + | |
11967 | +/* | |
4a4d8108 | 11968 | + * handling file/dir, and address_space operation |
1facf9fc | 11969 | + */ |
11970 | + | |
7eafdf33 AM |
11971 | +#ifdef CONFIG_AUFS_DEBUG |
11972 | +#include <linux/migrate.h> | |
11973 | +#endif | |
4a4d8108 | 11974 | +#include <linux/pagemap.h> |
1facf9fc | 11975 | +#include "aufs.h" |
11976 | + | |
4a4d8108 AM |
11977 | +/* drop flags for writing */ |
11978 | +unsigned int au_file_roflags(unsigned int flags) | |
11979 | +{ | |
11980 | + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC); | |
11981 | + flags |= O_RDONLY | O_NOATIME; | |
11982 | + return flags; | |
11983 | +} | |
11984 | + | |
11985 | +/* common functions to regular file and dir */ | |
11986 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 11987 | + struct file *file, int force_wr) |
1facf9fc | 11988 | +{ |
1308ab2a | 11989 | + struct file *h_file; |
4a4d8108 AM |
11990 | + struct dentry *h_dentry; |
11991 | + struct inode *h_inode; | |
11992 | + struct super_block *sb; | |
11993 | + struct au_branch *br; | |
11994 | + struct path h_path; | |
b912730e | 11995 | + int err; |
1facf9fc | 11996 | + |
4a4d8108 AM |
11997 | + /* a race condition can happen between open and unlink/rmdir */ |
11998 | + h_file = ERR_PTR(-ENOENT); | |
11999 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 12000 | + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry))) |
4a4d8108 | 12001 | + goto out; |
5527c038 | 12002 | + h_inode = d_inode(h_dentry); |
027c5e7a AM |
12003 | + spin_lock(&h_dentry->d_lock); |
12004 | + err = (!d_unhashed(dentry) && d_unlinked(h_dentry)) | |
5527c038 | 12005 | + /* || !d_inode(dentry)->i_nlink */ |
027c5e7a AM |
12006 | + ; |
12007 | + spin_unlock(&h_dentry->d_lock); | |
12008 | + if (unlikely(err)) | |
4a4d8108 | 12009 | + goto out; |
1facf9fc | 12010 | + |
4a4d8108 AM |
12011 | + sb = dentry->d_sb; |
12012 | + br = au_sbr(sb, bindex); | |
b912730e AM |
12013 | + err = au_br_test_oflag(flags, br); |
12014 | + h_file = ERR_PTR(err); | |
12015 | + if (unlikely(err)) | |
027c5e7a | 12016 | + goto out; |
1facf9fc | 12017 | + |
4a4d8108 | 12018 | + /* drop flags for writing */ |
5527c038 | 12019 | + if (au_test_ro(sb, bindex, d_inode(dentry))) { |
392086de AM |
12020 | + if (force_wr && !(flags & O_WRONLY)) |
12021 | + force_wr = 0; | |
4a4d8108 | 12022 | + flags = au_file_roflags(flags); |
392086de AM |
12023 | + if (force_wr) { |
12024 | + h_file = ERR_PTR(-EROFS); | |
12025 | + flags = au_file_roflags(flags); | |
12026 | + if (unlikely(vfsub_native_ro(h_inode) | |
12027 | + || IS_APPEND(h_inode))) | |
12028 | + goto out; | |
12029 | + flags &= ~O_ACCMODE; | |
12030 | + flags |= O_WRONLY; | |
12031 | + } | |
12032 | + } | |
4a4d8108 AM |
12033 | + flags &= ~O_CREAT; |
12034 | + atomic_inc(&br->br_count); | |
12035 | + h_path.dentry = h_dentry; | |
86dc4139 | 12036 | + h_path.mnt = au_br_mnt(br); |
38d290e6 | 12037 | + h_file = vfsub_dentry_open(&h_path, flags); |
4a4d8108 AM |
12038 | + if (IS_ERR(h_file)) |
12039 | + goto out_br; | |
dece6358 | 12040 | + |
b912730e | 12041 | + if (flags & __FMODE_EXEC) { |
4a4d8108 AM |
12042 | + err = deny_write_access(h_file); |
12043 | + if (unlikely(err)) { | |
12044 | + fput(h_file); | |
12045 | + h_file = ERR_PTR(err); | |
12046 | + goto out_br; | |
12047 | + } | |
12048 | + } | |
953406b4 | 12049 | + fsnotify_open(h_file); |
4a4d8108 | 12050 | + goto out; /* success */ |
1facf9fc | 12051 | + |
4f0767ce | 12052 | +out_br: |
4a4d8108 | 12053 | + atomic_dec(&br->br_count); |
4f0767ce | 12054 | +out: |
4a4d8108 AM |
12055 | + return h_file; |
12056 | +} | |
1308ab2a | 12057 | + |
076b876e AM |
12058 | +static int au_cmoo(struct dentry *dentry) |
12059 | +{ | |
12060 | + int err, cmoo; | |
12061 | + unsigned int udba; | |
12062 | + struct path h_path; | |
12063 | + struct au_pin pin; | |
12064 | + struct au_cp_generic cpg = { | |
12065 | + .dentry = dentry, | |
12066 | + .bdst = -1, | |
12067 | + .bsrc = -1, | |
12068 | + .len = -1, | |
12069 | + .pin = &pin, | |
12070 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
12071 | + }; | |
7e9cd9fe | 12072 | + struct inode *delegated; |
076b876e AM |
12073 | + struct super_block *sb; |
12074 | + struct au_sbinfo *sbinfo; | |
12075 | + struct au_fhsm *fhsm; | |
12076 | + pid_t pid; | |
12077 | + struct au_branch *br; | |
12078 | + struct dentry *parent; | |
12079 | + struct au_hinode *hdir; | |
12080 | + | |
12081 | + DiMustWriteLock(dentry); | |
5527c038 | 12082 | + IiMustWriteLock(d_inode(dentry)); |
076b876e AM |
12083 | + |
12084 | + err = 0; | |
12085 | + if (IS_ROOT(dentry)) | |
12086 | + goto out; | |
12087 | + cpg.bsrc = au_dbstart(dentry); | |
12088 | + if (!cpg.bsrc) | |
12089 | + goto out; | |
12090 | + | |
12091 | + sb = dentry->d_sb; | |
12092 | + sbinfo = au_sbi(sb); | |
12093 | + fhsm = &sbinfo->si_fhsm; | |
12094 | + pid = au_fhsm_pid(fhsm); | |
12095 | + if (pid | |
12096 | + && (current->pid == pid | |
12097 | + || current->real_parent->pid == pid)) | |
12098 | + goto out; | |
12099 | + | |
12100 | + br = au_sbr(sb, cpg.bsrc); | |
12101 | + cmoo = au_br_cmoo(br->br_perm); | |
12102 | + if (!cmoo) | |
12103 | + goto out; | |
7e9cd9fe | 12104 | + if (!d_is_reg(dentry)) |
076b876e AM |
12105 | + cmoo &= AuBrAttr_COO_ALL; |
12106 | + if (!cmoo) | |
12107 | + goto out; | |
12108 | + | |
12109 | + parent = dget_parent(dentry); | |
12110 | + di_write_lock_parent(parent); | |
12111 | + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1); | |
12112 | + cpg.bdst = err; | |
12113 | + if (unlikely(err < 0)) { | |
12114 | + err = 0; /* there is no upper writable branch */ | |
12115 | + goto out_dgrade; | |
12116 | + } | |
12117 | + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst); | |
12118 | + | |
12119 | + /* do not respect the coo attrib for the target branch */ | |
12120 | + err = au_cpup_dirs(dentry, cpg.bdst); | |
12121 | + if (unlikely(err)) | |
12122 | + goto out_dgrade; | |
12123 | + | |
12124 | + di_downgrade_lock(parent, AuLock_IR); | |
12125 | + udba = au_opt_udba(sb); | |
12126 | + err = au_pin(&pin, dentry, cpg.bdst, udba, | |
12127 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12128 | + if (unlikely(err)) | |
12129 | + goto out_parent; | |
12130 | + | |
12131 | + err = au_sio_cpup_simple(&cpg); | |
12132 | + au_unpin(&pin); | |
12133 | + if (unlikely(err)) | |
12134 | + goto out_parent; | |
12135 | + if (!(cmoo & AuBrWAttr_MOO)) | |
12136 | + goto out_parent; /* success */ | |
12137 | + | |
12138 | + err = au_pin(&pin, dentry, cpg.bsrc, udba, | |
12139 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12140 | + if (unlikely(err)) | |
12141 | + goto out_parent; | |
12142 | + | |
12143 | + h_path.mnt = au_br_mnt(br); | |
12144 | + h_path.dentry = au_h_dptr(dentry, cpg.bsrc); | |
5527c038 | 12145 | + hdir = au_hi(d_inode(parent), cpg.bsrc); |
076b876e AM |
12146 | + delegated = NULL; |
12147 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1); | |
12148 | + au_unpin(&pin); | |
12149 | + /* todo: keep h_dentry or not? */ | |
12150 | + if (unlikely(err == -EWOULDBLOCK)) { | |
12151 | + pr_warn("cannot retry for NFSv4 delegation" | |
12152 | + " for an internal unlink\n"); | |
12153 | + iput(delegated); | |
12154 | + } | |
12155 | + if (unlikely(err)) { | |
12156 | + pr_err("unlink %pd after coo failed (%d), ignored\n", | |
12157 | + dentry, err); | |
12158 | + err = 0; | |
12159 | + } | |
12160 | + goto out_parent; /* success */ | |
12161 | + | |
12162 | +out_dgrade: | |
12163 | + di_downgrade_lock(parent, AuLock_IR); | |
12164 | +out_parent: | |
12165 | + di_read_unlock(parent, AuLock_IR); | |
12166 | + dput(parent); | |
12167 | +out: | |
12168 | + AuTraceErr(err); | |
12169 | + return err; | |
12170 | +} | |
12171 | + | |
b912730e | 12172 | +int au_do_open(struct file *file, struct au_do_open_args *args) |
1facf9fc | 12173 | +{ |
b912730e | 12174 | + int err, no_lock = args->no_lock; |
1facf9fc | 12175 | + struct dentry *dentry; |
076b876e | 12176 | + struct au_finfo *finfo; |
1308ab2a | 12177 | + |
b912730e AM |
12178 | + if (!no_lock) |
12179 | + err = au_finfo_init(file, args->fidir); | |
12180 | + else { | |
12181 | + lockdep_off(); | |
12182 | + err = au_finfo_init(file, args->fidir); | |
12183 | + lockdep_on(); | |
12184 | + } | |
4a4d8108 AM |
12185 | + if (unlikely(err)) |
12186 | + goto out; | |
1facf9fc | 12187 | + |
2000de60 | 12188 | + dentry = file->f_path.dentry; |
b912730e AM |
12189 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
12190 | + if (!no_lock) { | |
12191 | + di_write_lock_child(dentry); | |
12192 | + err = au_cmoo(dentry); | |
12193 | + di_downgrade_lock(dentry, AuLock_IR); | |
12194 | + if (!err) | |
12195 | + err = args->open(file, vfsub_file_flags(file), NULL); | |
12196 | + di_read_unlock(dentry, AuLock_IR); | |
12197 | + } else { | |
12198 | + err = au_cmoo(dentry); | |
12199 | + if (!err) | |
12200 | + err = args->open(file, vfsub_file_flags(file), | |
12201 | + args->h_file); | |
12202 | + if (!err && au_fbstart(file) != au_dbstart(dentry)) | |
12203 | + /* | |
12204 | + * cmoo happens after h_file was opened. | |
12205 | + * need to refresh file later. | |
12206 | + */ | |
12207 | + atomic_dec(&au_fi(file)->fi_generation); | |
12208 | + } | |
1facf9fc | 12209 | + |
076b876e AM |
12210 | + finfo = au_fi(file); |
12211 | + if (!err) { | |
12212 | + finfo->fi_file = file; | |
12213 | + au_sphl_add(&finfo->fi_hlist, | |
2000de60 | 12214 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); |
076b876e | 12215 | + } |
b912730e AM |
12216 | + if (!no_lock) |
12217 | + fi_write_unlock(file); | |
12218 | + else { | |
12219 | + lockdep_off(); | |
12220 | + fi_write_unlock(file); | |
12221 | + lockdep_on(); | |
12222 | + } | |
4a4d8108 | 12223 | + if (unlikely(err)) { |
076b876e | 12224 | + finfo->fi_hdir = NULL; |
4a4d8108 | 12225 | + au_finfo_fin(file); |
1308ab2a | 12226 | + } |
4a4d8108 | 12227 | + |
4f0767ce | 12228 | +out: |
1308ab2a | 12229 | + return err; |
12230 | +} | |
dece6358 | 12231 | + |
4a4d8108 | 12232 | +int au_reopen_nondir(struct file *file) |
1308ab2a | 12233 | +{ |
4a4d8108 AM |
12234 | + int err; |
12235 | + aufs_bindex_t bstart; | |
12236 | + struct dentry *dentry; | |
12237 | + struct file *h_file, *h_file_tmp; | |
1308ab2a | 12238 | + |
2000de60 | 12239 | + dentry = file->f_path.dentry; |
4a4d8108 AM |
12240 | + bstart = au_dbstart(dentry); |
12241 | + h_file_tmp = NULL; | |
12242 | + if (au_fbstart(file) == bstart) { | |
12243 | + h_file = au_hf_top(file); | |
12244 | + if (file->f_mode == h_file->f_mode) | |
12245 | + return 0; /* success */ | |
12246 | + h_file_tmp = h_file; | |
12247 | + get_file(h_file_tmp); | |
12248 | + au_set_h_fptr(file, bstart, NULL); | |
12249 | + } | |
12250 | + AuDebugOn(au_fi(file)->fi_hdir); | |
86dc4139 AM |
12251 | + /* |
12252 | + * it can happen | |
12253 | + * file exists on both of rw and ro | |
12254 | + * open --> dbstart and fbstart are both 0 | |
12255 | + * prepend a branch as rw, "rw" become ro | |
12256 | + * remove rw/file | |
12257 | + * delete the top branch, "rw" becomes rw again | |
12258 | + * --> dbstart is 1, fbstart is still 0 | |
12259 | + * write --> fbstart is 0 but dbstart is 1 | |
12260 | + */ | |
12261 | + /* AuDebugOn(au_fbstart(file) < bstart); */ | |
1308ab2a | 12262 | + |
4a4d8108 | 12263 | + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC, |
392086de | 12264 | + file, /*force_wr*/0); |
4a4d8108 | 12265 | + err = PTR_ERR(h_file); |
86dc4139 AM |
12266 | + if (IS_ERR(h_file)) { |
12267 | + if (h_file_tmp) { | |
12268 | + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count); | |
12269 | + au_set_h_fptr(file, bstart, h_file_tmp); | |
12270 | + h_file_tmp = NULL; | |
12271 | + } | |
4a4d8108 | 12272 | + goto out; /* todo: close all? */ |
86dc4139 | 12273 | + } |
4a4d8108 AM |
12274 | + |
12275 | + err = 0; | |
12276 | + au_set_fbstart(file, bstart); | |
12277 | + au_set_h_fptr(file, bstart, h_file); | |
12278 | + au_update_figen(file); | |
12279 | + /* todo: necessary? */ | |
12280 | + /* file->f_ra = h_file->f_ra; */ | |
12281 | + | |
4f0767ce | 12282 | +out: |
4a4d8108 AM |
12283 | + if (h_file_tmp) |
12284 | + fput(h_file_tmp); | |
12285 | + return err; | |
1facf9fc | 12286 | +} |
12287 | + | |
1308ab2a | 12288 | +/* ---------------------------------------------------------------------- */ |
12289 | + | |
4a4d8108 AM |
12290 | +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt, |
12291 | + struct dentry *hi_wh) | |
1facf9fc | 12292 | +{ |
4a4d8108 AM |
12293 | + int err; |
12294 | + aufs_bindex_t bstart; | |
12295 | + struct au_dinfo *dinfo; | |
12296 | + struct dentry *h_dentry; | |
12297 | + struct au_hdentry *hdp; | |
1facf9fc | 12298 | + |
2000de60 | 12299 | + dinfo = au_di(file->f_path.dentry); |
4a4d8108 | 12300 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
dece6358 | 12301 | + |
4a4d8108 AM |
12302 | + bstart = dinfo->di_bstart; |
12303 | + dinfo->di_bstart = btgt; | |
12304 | + hdp = dinfo->di_hdentry; | |
12305 | + h_dentry = hdp[0 + btgt].hd_dentry; | |
12306 | + hdp[0 + btgt].hd_dentry = hi_wh; | |
12307 | + err = au_reopen_nondir(file); | |
12308 | + hdp[0 + btgt].hd_dentry = h_dentry; | |
12309 | + dinfo->di_bstart = bstart; | |
1facf9fc | 12310 | + |
1facf9fc | 12311 | + return err; |
12312 | +} | |
12313 | + | |
4a4d8108 | 12314 | +static int au_ready_to_write_wh(struct file *file, loff_t len, |
86dc4139 | 12315 | + aufs_bindex_t bcpup, struct au_pin *pin) |
1facf9fc | 12316 | +{ |
4a4d8108 | 12317 | + int err; |
027c5e7a | 12318 | + struct inode *inode, *h_inode; |
c2b27bf2 AM |
12319 | + struct dentry *h_dentry, *hi_wh; |
12320 | + struct au_cp_generic cpg = { | |
2000de60 | 12321 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12322 | + .bdst = bcpup, |
12323 | + .bsrc = -1, | |
12324 | + .len = len, | |
12325 | + .pin = pin | |
12326 | + }; | |
1facf9fc | 12327 | + |
c2b27bf2 | 12328 | + au_update_dbstart(cpg.dentry); |
5527c038 | 12329 | + inode = d_inode(cpg.dentry); |
027c5e7a | 12330 | + h_inode = NULL; |
c2b27bf2 AM |
12331 | + if (au_dbstart(cpg.dentry) <= bcpup |
12332 | + && au_dbend(cpg.dentry) >= bcpup) { | |
12333 | + h_dentry = au_h_dptr(cpg.dentry, bcpup); | |
5527c038 JR |
12334 | + if (h_dentry && d_is_positive(h_dentry)) |
12335 | + h_inode = d_inode(h_dentry); | |
027c5e7a | 12336 | + } |
4a4d8108 | 12337 | + hi_wh = au_hi_wh(inode, bcpup); |
027c5e7a | 12338 | + if (!hi_wh && !h_inode) |
c2b27bf2 | 12339 | + err = au_sio_cpup_wh(&cpg, file); |
4a4d8108 AM |
12340 | + else |
12341 | + /* already copied-up after unlink */ | |
12342 | + err = au_reopen_wh(file, bcpup, hi_wh); | |
1facf9fc | 12343 | + |
4a4d8108 | 12344 | + if (!err |
38d290e6 JR |
12345 | + && (inode->i_nlink > 1 |
12346 | + || (inode->i_state & I_LINKABLE)) | |
c2b27bf2 AM |
12347 | + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK)) |
12348 | + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup)); | |
1308ab2a | 12349 | + |
dece6358 | 12350 | + return err; |
1facf9fc | 12351 | +} |
12352 | + | |
4a4d8108 AM |
12353 | +/* |
12354 | + * prepare the @file for writing. | |
12355 | + */ | |
12356 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin) | |
1facf9fc | 12357 | +{ |
4a4d8108 | 12358 | + int err; |
c2b27bf2 | 12359 | + aufs_bindex_t dbstart; |
c1595e42 | 12360 | + struct dentry *parent; |
86dc4139 | 12361 | + struct inode *inode; |
1facf9fc | 12362 | + struct super_block *sb; |
4a4d8108 | 12363 | + struct file *h_file; |
c2b27bf2 | 12364 | + struct au_cp_generic cpg = { |
2000de60 | 12365 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12366 | + .bdst = -1, |
12367 | + .bsrc = -1, | |
12368 | + .len = len, | |
12369 | + .pin = pin, | |
12370 | + .flags = AuCpup_DTIME | |
12371 | + }; | |
1facf9fc | 12372 | + |
c2b27bf2 | 12373 | + sb = cpg.dentry->d_sb; |
5527c038 | 12374 | + inode = d_inode(cpg.dentry); |
c2b27bf2 AM |
12375 | + cpg.bsrc = au_fbstart(file); |
12376 | + err = au_test_ro(sb, cpg.bsrc, inode); | |
4a4d8108 | 12377 | + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) { |
c2b27bf2 AM |
12378 | + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE, |
12379 | + /*flags*/0); | |
1facf9fc | 12380 | + goto out; |
4a4d8108 | 12381 | + } |
1facf9fc | 12382 | + |
027c5e7a | 12383 | + /* need to cpup or reopen */ |
c2b27bf2 | 12384 | + parent = dget_parent(cpg.dentry); |
4a4d8108 | 12385 | + di_write_lock_parent(parent); |
c2b27bf2 AM |
12386 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12387 | + cpg.bdst = err; | |
4a4d8108 AM |
12388 | + if (unlikely(err < 0)) |
12389 | + goto out_dgrade; | |
12390 | + err = 0; | |
12391 | + | |
c2b27bf2 AM |
12392 | + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) { |
12393 | + err = au_cpup_dirs(cpg.dentry, cpg.bdst); | |
1facf9fc | 12394 | + if (unlikely(err)) |
4a4d8108 AM |
12395 | + goto out_dgrade; |
12396 | + } | |
12397 | + | |
c2b27bf2 | 12398 | + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 AM |
12399 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
12400 | + if (unlikely(err)) | |
12401 | + goto out_dgrade; | |
12402 | + | |
c2b27bf2 | 12403 | + dbstart = au_dbstart(cpg.dentry); |
c1595e42 | 12404 | + if (dbstart <= cpg.bdst) |
c2b27bf2 | 12405 | + cpg.bsrc = cpg.bdst; |
027c5e7a | 12406 | + |
c2b27bf2 AM |
12407 | + if (dbstart <= cpg.bdst /* just reopen */ |
12408 | + || !d_unhashed(cpg.dentry) /* copyup and reopen */ | |
027c5e7a | 12409 | + ) { |
392086de | 12410 | + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0); |
86dc4139 | 12411 | + if (IS_ERR(h_file)) |
027c5e7a | 12412 | + err = PTR_ERR(h_file); |
86dc4139 | 12413 | + else { |
027c5e7a | 12414 | + di_downgrade_lock(parent, AuLock_IR); |
c2b27bf2 AM |
12415 | + if (dbstart > cpg.bdst) |
12416 | + err = au_sio_cpup_simple(&cpg); | |
027c5e7a AM |
12417 | + if (!err) |
12418 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 12419 | + au_h_open_post(cpg.dentry, cpg.bsrc, h_file); |
027c5e7a | 12420 | + } |
027c5e7a AM |
12421 | + } else { /* copyup as wh and reopen */ |
12422 | + /* | |
12423 | + * since writable hfsplus branch is not supported, | |
12424 | + * h_open_pre/post() are unnecessary. | |
12425 | + */ | |
c2b27bf2 | 12426 | + err = au_ready_to_write_wh(file, len, cpg.bdst, pin); |
4a4d8108 | 12427 | + di_downgrade_lock(parent, AuLock_IR); |
4a4d8108 | 12428 | + } |
4a4d8108 AM |
12429 | + |
12430 | + if (!err) { | |
12431 | + au_pin_set_parent_lflag(pin, /*lflag*/0); | |
12432 | + goto out_dput; /* success */ | |
12433 | + } | |
12434 | + au_unpin(pin); | |
12435 | + goto out_unlock; | |
1facf9fc | 12436 | + |
4f0767ce | 12437 | +out_dgrade: |
4a4d8108 | 12438 | + di_downgrade_lock(parent, AuLock_IR); |
4f0767ce | 12439 | +out_unlock: |
4a4d8108 | 12440 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12441 | +out_dput: |
4a4d8108 | 12442 | + dput(parent); |
4f0767ce | 12443 | +out: |
1facf9fc | 12444 | + return err; |
12445 | +} | |
12446 | + | |
4a4d8108 AM |
12447 | +/* ---------------------------------------------------------------------- */ |
12448 | + | |
12449 | +int au_do_flush(struct file *file, fl_owner_t id, | |
12450 | + int (*flush)(struct file *file, fl_owner_t id)) | |
1facf9fc | 12451 | +{ |
4a4d8108 | 12452 | + int err; |
1facf9fc | 12453 | + struct super_block *sb; |
4a4d8108 | 12454 | + struct inode *inode; |
1facf9fc | 12455 | + |
c06a8ce3 AM |
12456 | + inode = file_inode(file); |
12457 | + sb = inode->i_sb; | |
4a4d8108 AM |
12458 | + si_noflush_read_lock(sb); |
12459 | + fi_read_lock(file); | |
b752ccd1 | 12460 | + ii_read_lock_child(inode); |
1facf9fc | 12461 | + |
4a4d8108 AM |
12462 | + err = flush(file, id); |
12463 | + au_cpup_attr_timesizes(inode); | |
1facf9fc | 12464 | + |
b752ccd1 | 12465 | + ii_read_unlock(inode); |
4a4d8108 | 12466 | + fi_read_unlock(file); |
1308ab2a | 12467 | + si_read_unlock(sb); |
dece6358 | 12468 | + return err; |
1facf9fc | 12469 | +} |
12470 | + | |
4a4d8108 AM |
12471 | +/* ---------------------------------------------------------------------- */ |
12472 | + | |
12473 | +static int au_file_refresh_by_inode(struct file *file, int *need_reopen) | |
1facf9fc | 12474 | +{ |
4a4d8108 | 12475 | + int err; |
4a4d8108 AM |
12476 | + struct au_pin pin; |
12477 | + struct au_finfo *finfo; | |
c2b27bf2 | 12478 | + struct dentry *parent, *hi_wh; |
4a4d8108 | 12479 | + struct inode *inode; |
1facf9fc | 12480 | + struct super_block *sb; |
c2b27bf2 | 12481 | + struct au_cp_generic cpg = { |
2000de60 | 12482 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
12483 | + .bdst = -1, |
12484 | + .bsrc = -1, | |
12485 | + .len = -1, | |
12486 | + .pin = &pin, | |
12487 | + .flags = AuCpup_DTIME | |
12488 | + }; | |
1facf9fc | 12489 | + |
4a4d8108 AM |
12490 | + FiMustWriteLock(file); |
12491 | + | |
12492 | + err = 0; | |
12493 | + finfo = au_fi(file); | |
c2b27bf2 | 12494 | + sb = cpg.dentry->d_sb; |
5527c038 | 12495 | + inode = d_inode(cpg.dentry); |
c2b27bf2 AM |
12496 | + cpg.bdst = au_ibstart(inode); |
12497 | + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry)) | |
1308ab2a | 12498 | + goto out; |
dece6358 | 12499 | + |
c2b27bf2 AM |
12500 | + parent = dget_parent(cpg.dentry); |
12501 | + if (au_test_ro(sb, cpg.bdst, inode)) { | |
4a4d8108 | 12502 | + di_read_lock_parent(parent, !AuLock_IR); |
c2b27bf2 AM |
12503 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12504 | + cpg.bdst = err; | |
4a4d8108 AM |
12505 | + di_read_unlock(parent, !AuLock_IR); |
12506 | + if (unlikely(err < 0)) | |
12507 | + goto out_parent; | |
12508 | + err = 0; | |
1facf9fc | 12509 | + } |
1facf9fc | 12510 | + |
4a4d8108 | 12511 | + di_read_lock_parent(parent, AuLock_IR); |
c2b27bf2 | 12512 | + hi_wh = au_hi_wh(inode, cpg.bdst); |
7f207e10 AM |
12513 | + if (!S_ISDIR(inode->i_mode) |
12514 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4a4d8108 | 12515 | + && au_plink_test(inode) |
c2b27bf2 AM |
12516 | + && !d_unhashed(cpg.dentry) |
12517 | + && cpg.bdst < au_dbstart(cpg.dentry)) { | |
12518 | + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst); | |
4a4d8108 AM |
12519 | + if (unlikely(err)) |
12520 | + goto out_unlock; | |
12521 | + | |
12522 | + /* always superio. */ | |
c2b27bf2 | 12523 | + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 | 12524 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
367653fa | 12525 | + if (!err) { |
c2b27bf2 | 12526 | + err = au_sio_cpup_simple(&cpg); |
367653fa AM |
12527 | + au_unpin(&pin); |
12528 | + } | |
4a4d8108 AM |
12529 | + } else if (hi_wh) { |
12530 | + /* already copied-up after unlink */ | |
c2b27bf2 | 12531 | + err = au_reopen_wh(file, cpg.bdst, hi_wh); |
4a4d8108 AM |
12532 | + *need_reopen = 0; |
12533 | + } | |
1facf9fc | 12534 | + |
4f0767ce | 12535 | +out_unlock: |
4a4d8108 | 12536 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12537 | +out_parent: |
4a4d8108 | 12538 | + dput(parent); |
4f0767ce | 12539 | +out: |
1308ab2a | 12540 | + return err; |
dece6358 | 12541 | +} |
1facf9fc | 12542 | + |
4a4d8108 | 12543 | +static void au_do_refresh_dir(struct file *file) |
dece6358 | 12544 | +{ |
4a4d8108 AM |
12545 | + aufs_bindex_t bindex, bend, new_bindex, brid; |
12546 | + struct au_hfile *p, tmp, *q; | |
12547 | + struct au_finfo *finfo; | |
1308ab2a | 12548 | + struct super_block *sb; |
4a4d8108 | 12549 | + struct au_fidir *fidir; |
1facf9fc | 12550 | + |
4a4d8108 | 12551 | + FiMustWriteLock(file); |
1facf9fc | 12552 | + |
2000de60 | 12553 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 AM |
12554 | + finfo = au_fi(file); |
12555 | + fidir = finfo->fi_hdir; | |
12556 | + AuDebugOn(!fidir); | |
12557 | + p = fidir->fd_hfile + finfo->fi_btop; | |
12558 | + brid = p->hf_br->br_id; | |
12559 | + bend = fidir->fd_bbot; | |
12560 | + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) { | |
12561 | + if (!p->hf_file) | |
12562 | + continue; | |
1308ab2a | 12563 | + |
4a4d8108 AM |
12564 | + new_bindex = au_br_index(sb, p->hf_br->br_id); |
12565 | + if (new_bindex == bindex) | |
12566 | + continue; | |
12567 | + if (new_bindex < 0) { | |
12568 | + au_set_h_fptr(file, bindex, NULL); | |
12569 | + continue; | |
12570 | + } | |
1308ab2a | 12571 | + |
4a4d8108 AM |
12572 | + /* swap two lower inode, and loop again */ |
12573 | + q = fidir->fd_hfile + new_bindex; | |
12574 | + tmp = *q; | |
12575 | + *q = *p; | |
12576 | + *p = tmp; | |
12577 | + if (tmp.hf_file) { | |
12578 | + bindex--; | |
12579 | + p--; | |
12580 | + } | |
12581 | + } | |
1308ab2a | 12582 | + |
4a4d8108 | 12583 | + p = fidir->fd_hfile; |
2000de60 | 12584 | + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) { |
4a4d8108 AM |
12585 | + bend = au_sbend(sb); |
12586 | + for (finfo->fi_btop = 0; finfo->fi_btop <= bend; | |
12587 | + finfo->fi_btop++, p++) | |
12588 | + if (p->hf_file) { | |
c06a8ce3 | 12589 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12590 | + break; |
c1595e42 | 12591 | + au_hfput(p, file); |
4a4d8108 AM |
12592 | + } |
12593 | + } else { | |
12594 | + bend = au_br_index(sb, brid); | |
12595 | + for (finfo->fi_btop = 0; finfo->fi_btop < bend; | |
12596 | + finfo->fi_btop++, p++) | |
12597 | + if (p->hf_file) | |
12598 | + au_hfput(p, file); | |
12599 | + bend = au_sbend(sb); | |
12600 | + } | |
1308ab2a | 12601 | + |
4a4d8108 AM |
12602 | + p = fidir->fd_hfile + bend; |
12603 | + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop; | |
12604 | + fidir->fd_bbot--, p--) | |
12605 | + if (p->hf_file) { | |
c06a8ce3 | 12606 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12607 | + break; |
c1595e42 | 12608 | + au_hfput(p, file); |
4a4d8108 AM |
12609 | + } |
12610 | + AuDebugOn(fidir->fd_bbot < finfo->fi_btop); | |
1308ab2a | 12611 | +} |
12612 | + | |
4a4d8108 AM |
12613 | +/* |
12614 | + * after branch manipulating, refresh the file. | |
12615 | + */ | |
12616 | +static int refresh_file(struct file *file, int (*reopen)(struct file *file)) | |
1facf9fc | 12617 | +{ |
4a4d8108 AM |
12618 | + int err, need_reopen; |
12619 | + aufs_bindex_t bend, bindex; | |
12620 | + struct dentry *dentry; | |
1308ab2a | 12621 | + struct au_finfo *finfo; |
4a4d8108 | 12622 | + struct au_hfile *hfile; |
1facf9fc | 12623 | + |
2000de60 | 12624 | + dentry = file->f_path.dentry; |
1308ab2a | 12625 | + finfo = au_fi(file); |
4a4d8108 AM |
12626 | + if (!finfo->fi_hdir) { |
12627 | + hfile = &finfo->fi_htop; | |
12628 | + AuDebugOn(!hfile->hf_file); | |
12629 | + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id); | |
12630 | + AuDebugOn(bindex < 0); | |
12631 | + if (bindex != finfo->fi_btop) | |
12632 | + au_set_fbstart(file, bindex); | |
12633 | + } else { | |
12634 | + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1); | |
12635 | + if (unlikely(err)) | |
12636 | + goto out; | |
12637 | + au_do_refresh_dir(file); | |
12638 | + } | |
1facf9fc | 12639 | + |
4a4d8108 AM |
12640 | + err = 0; |
12641 | + need_reopen = 1; | |
12642 | + if (!au_test_mmapped(file)) | |
12643 | + err = au_file_refresh_by_inode(file, &need_reopen); | |
027c5e7a | 12644 | + if (!err && need_reopen && !d_unlinked(dentry)) |
4a4d8108 AM |
12645 | + err = reopen(file); |
12646 | + if (!err) { | |
12647 | + au_update_figen(file); | |
12648 | + goto out; /* success */ | |
12649 | + } | |
12650 | + | |
12651 | + /* error, close all lower files */ | |
12652 | + if (finfo->fi_hdir) { | |
12653 | + bend = au_fbend_dir(file); | |
12654 | + for (bindex = au_fbstart(file); bindex <= bend; bindex++) | |
12655 | + au_set_h_fptr(file, bindex, NULL); | |
12656 | + } | |
1facf9fc | 12657 | + |
4f0767ce | 12658 | +out: |
1facf9fc | 12659 | + return err; |
12660 | +} | |
12661 | + | |
4a4d8108 AM |
12662 | +/* common function to regular file and dir */ |
12663 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
12664 | + int wlock) | |
dece6358 | 12665 | +{ |
1308ab2a | 12666 | + int err; |
4a4d8108 AM |
12667 | + unsigned int sigen, figen; |
12668 | + aufs_bindex_t bstart; | |
12669 | + unsigned char pseudo_link; | |
12670 | + struct dentry *dentry; | |
12671 | + struct inode *inode; | |
1facf9fc | 12672 | + |
4a4d8108 | 12673 | + err = 0; |
2000de60 | 12674 | + dentry = file->f_path.dentry; |
5527c038 | 12675 | + inode = d_inode(dentry); |
4a4d8108 AM |
12676 | + sigen = au_sigen(dentry->d_sb); |
12677 | + fi_write_lock(file); | |
12678 | + figen = au_figen(file); | |
12679 | + di_write_lock_child(dentry); | |
12680 | + bstart = au_dbstart(dentry); | |
12681 | + pseudo_link = (bstart != au_ibstart(inode)); | |
12682 | + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) { | |
12683 | + if (!wlock) { | |
12684 | + di_downgrade_lock(dentry, AuLock_IR); | |
12685 | + fi_downgrade_lock(file); | |
12686 | + } | |
12687 | + goto out; /* success */ | |
12688 | + } | |
dece6358 | 12689 | + |
4a4d8108 | 12690 | + AuDbg("sigen %d, figen %d\n", sigen, figen); |
027c5e7a | 12691 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 | 12692 | + err = au_reval_dpath(dentry, sigen); |
027c5e7a | 12693 | + AuDebugOn(!err && au_digen_test(dentry, sigen)); |
4a4d8108 | 12694 | + } |
dece6358 | 12695 | + |
027c5e7a AM |
12696 | + if (!err) |
12697 | + err = refresh_file(file, reopen); | |
4a4d8108 AM |
12698 | + if (!err) { |
12699 | + if (!wlock) { | |
12700 | + di_downgrade_lock(dentry, AuLock_IR); | |
12701 | + fi_downgrade_lock(file); | |
12702 | + } | |
12703 | + } else { | |
12704 | + di_write_unlock(dentry); | |
12705 | + fi_write_unlock(file); | |
12706 | + } | |
1facf9fc | 12707 | + |
4f0767ce | 12708 | +out: |
1308ab2a | 12709 | + return err; |
12710 | +} | |
1facf9fc | 12711 | + |
4a4d8108 AM |
12712 | +/* ---------------------------------------------------------------------- */ |
12713 | + | |
12714 | +/* cf. aufs_nopage() */ | |
12715 | +/* for madvise(2) */ | |
12716 | +static int aufs_readpage(struct file *file __maybe_unused, struct page *page) | |
1308ab2a | 12717 | +{ |
4a4d8108 AM |
12718 | + unlock_page(page); |
12719 | + return 0; | |
12720 | +} | |
1facf9fc | 12721 | + |
4a4d8108 | 12722 | +/* it will never be called, but necessary to support O_DIRECT */ |
5527c038 JR |
12723 | +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, |
12724 | + loff_t offset) | |
4a4d8108 | 12725 | +{ BUG(); return 0; } |
1facf9fc | 12726 | + |
4a4d8108 AM |
12727 | +/* they will never be called. */ |
12728 | +#ifdef CONFIG_AUFS_DEBUG | |
12729 | +static int aufs_write_begin(struct file *file, struct address_space *mapping, | |
12730 | + loff_t pos, unsigned len, unsigned flags, | |
12731 | + struct page **pagep, void **fsdata) | |
12732 | +{ AuUnsupport(); return 0; } | |
12733 | +static int aufs_write_end(struct file *file, struct address_space *mapping, | |
12734 | + loff_t pos, unsigned len, unsigned copied, | |
12735 | + struct page *page, void *fsdata) | |
12736 | +{ AuUnsupport(); return 0; } | |
12737 | +static int aufs_writepage(struct page *page, struct writeback_control *wbc) | |
12738 | +{ AuUnsupport(); return 0; } | |
1308ab2a | 12739 | + |
4a4d8108 AM |
12740 | +static int aufs_set_page_dirty(struct page *page) |
12741 | +{ AuUnsupport(); return 0; } | |
392086de AM |
12742 | +static void aufs_invalidatepage(struct page *page, unsigned int offset, |
12743 | + unsigned int length) | |
4a4d8108 AM |
12744 | +{ AuUnsupport(); } |
12745 | +static int aufs_releasepage(struct page *page, gfp_t gfp) | |
12746 | +{ AuUnsupport(); return 0; } | |
12747 | +static int aufs_migratepage(struct address_space *mapping, struct page *newpage, | |
7eafdf33 | 12748 | + struct page *page, enum migrate_mode mode) |
4a4d8108 AM |
12749 | +{ AuUnsupport(); return 0; } |
12750 | +static int aufs_launder_page(struct page *page) | |
12751 | +{ AuUnsupport(); return 0; } | |
12752 | +static int aufs_is_partially_uptodate(struct page *page, | |
38d290e6 JR |
12753 | + unsigned long from, |
12754 | + unsigned long count) | |
4a4d8108 | 12755 | +{ AuUnsupport(); return 0; } |
392086de AM |
12756 | +static void aufs_is_dirty_writeback(struct page *page, bool *dirty, |
12757 | + bool *writeback) | |
12758 | +{ AuUnsupport(); } | |
4a4d8108 AM |
12759 | +static int aufs_error_remove_page(struct address_space *mapping, |
12760 | + struct page *page) | |
12761 | +{ AuUnsupport(); return 0; } | |
b4510431 AM |
12762 | +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file, |
12763 | + sector_t *span) | |
12764 | +{ AuUnsupport(); return 0; } | |
12765 | +static void aufs_swap_deactivate(struct file *file) | |
12766 | +{ AuUnsupport(); } | |
4a4d8108 AM |
12767 | +#endif /* CONFIG_AUFS_DEBUG */ |
12768 | + | |
12769 | +const struct address_space_operations aufs_aop = { | |
12770 | + .readpage = aufs_readpage, | |
12771 | + .direct_IO = aufs_direct_IO, | |
4a4d8108 AM |
12772 | +#ifdef CONFIG_AUFS_DEBUG |
12773 | + .writepage = aufs_writepage, | |
4a4d8108 AM |
12774 | + /* no writepages, because of writepage */ |
12775 | + .set_page_dirty = aufs_set_page_dirty, | |
12776 | + /* no readpages, because of readpage */ | |
12777 | + .write_begin = aufs_write_begin, | |
12778 | + .write_end = aufs_write_end, | |
12779 | + /* no bmap, no block device */ | |
12780 | + .invalidatepage = aufs_invalidatepage, | |
12781 | + .releasepage = aufs_releasepage, | |
12782 | + .migratepage = aufs_migratepage, | |
12783 | + .launder_page = aufs_launder_page, | |
12784 | + .is_partially_uptodate = aufs_is_partially_uptodate, | |
392086de | 12785 | + .is_dirty_writeback = aufs_is_dirty_writeback, |
b4510431 AM |
12786 | + .error_remove_page = aufs_error_remove_page, |
12787 | + .swap_activate = aufs_swap_activate, | |
12788 | + .swap_deactivate = aufs_swap_deactivate | |
4a4d8108 | 12789 | +#endif /* CONFIG_AUFS_DEBUG */ |
dece6358 | 12790 | +}; |
7f207e10 AM |
12791 | diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h |
12792 | --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 12793 | +++ linux/fs/aufs/file.h 2015-09-24 10:47:58.251386326 +0200 |
b912730e | 12794 | @@ -0,0 +1,291 @@ |
4a4d8108 | 12795 | +/* |
2000de60 | 12796 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
12797 | + * |
12798 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12799 | + * it under the terms of the GNU General Public License as published by | |
12800 | + * the Free Software Foundation; either version 2 of the License, or | |
12801 | + * (at your option) any later version. | |
12802 | + * | |
12803 | + * This program is distributed in the hope that it will be useful, | |
12804 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12805 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12806 | + * GNU General Public License for more details. | |
12807 | + * | |
12808 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12809 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 12810 | + */ |
1facf9fc | 12811 | + |
4a4d8108 AM |
12812 | +/* |
12813 | + * file operations | |
12814 | + */ | |
1facf9fc | 12815 | + |
4a4d8108 AM |
12816 | +#ifndef __AUFS_FILE_H__ |
12817 | +#define __AUFS_FILE_H__ | |
1facf9fc | 12818 | + |
4a4d8108 | 12819 | +#ifdef __KERNEL__ |
1facf9fc | 12820 | + |
2cbb1c4b | 12821 | +#include <linux/file.h> |
4a4d8108 AM |
12822 | +#include <linux/fs.h> |
12823 | +#include <linux/poll.h> | |
4a4d8108 | 12824 | +#include "rwsem.h" |
1facf9fc | 12825 | + |
4a4d8108 AM |
12826 | +struct au_branch; |
12827 | +struct au_hfile { | |
12828 | + struct file *hf_file; | |
12829 | + struct au_branch *hf_br; | |
12830 | +}; | |
1facf9fc | 12831 | + |
4a4d8108 AM |
12832 | +struct au_vdir; |
12833 | +struct au_fidir { | |
12834 | + aufs_bindex_t fd_bbot; | |
12835 | + aufs_bindex_t fd_nent; | |
12836 | + struct au_vdir *fd_vdir_cache; | |
12837 | + struct au_hfile fd_hfile[]; | |
12838 | +}; | |
1facf9fc | 12839 | + |
4a4d8108 | 12840 | +static inline int au_fidir_sz(int nent) |
dece6358 | 12841 | +{ |
4f0767ce JR |
12842 | + AuDebugOn(nent < 0); |
12843 | + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent; | |
4a4d8108 | 12844 | +} |
1facf9fc | 12845 | + |
4a4d8108 AM |
12846 | +struct au_finfo { |
12847 | + atomic_t fi_generation; | |
dece6358 | 12848 | + |
4a4d8108 AM |
12849 | + struct au_rwsem fi_rwsem; |
12850 | + aufs_bindex_t fi_btop; | |
12851 | + | |
12852 | + /* do not union them */ | |
12853 | + struct { /* for non-dir */ | |
12854 | + struct au_hfile fi_htop; | |
2cbb1c4b | 12855 | + atomic_t fi_mmapped; |
4a4d8108 AM |
12856 | + }; |
12857 | + struct au_fidir *fi_hdir; /* for dir only */ | |
523b37e3 AM |
12858 | + |
12859 | + struct hlist_node fi_hlist; | |
12860 | + struct file *fi_file; /* very ugly */ | |
4a4d8108 | 12861 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 12862 | + |
4a4d8108 | 12863 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12864 | + |
4a4d8108 AM |
12865 | +/* file.c */ |
12866 | +extern const struct address_space_operations aufs_aop; | |
12867 | +unsigned int au_file_roflags(unsigned int flags); | |
12868 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 12869 | + struct file *file, int force_wr); |
b912730e AM |
12870 | +struct au_do_open_args { |
12871 | + int no_lock; | |
12872 | + int (*open)(struct file *file, int flags, | |
12873 | + struct file *h_file); | |
12874 | + struct au_fidir *fidir; | |
12875 | + struct file *h_file; | |
12876 | +}; | |
12877 | +int au_do_open(struct file *file, struct au_do_open_args *args); | |
4a4d8108 AM |
12878 | +int au_reopen_nondir(struct file *file); |
12879 | +struct au_pin; | |
12880 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin); | |
12881 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
12882 | + int wlock); | |
12883 | +int au_do_flush(struct file *file, fl_owner_t id, | |
12884 | + int (*flush)(struct file *file, fl_owner_t id)); | |
1facf9fc | 12885 | + |
4a4d8108 AM |
12886 | +/* poll.c */ |
12887 | +#ifdef CONFIG_AUFS_POLL | |
12888 | +unsigned int aufs_poll(struct file *file, poll_table *wait); | |
12889 | +#endif | |
1facf9fc | 12890 | + |
4a4d8108 AM |
12891 | +#ifdef CONFIG_AUFS_BR_HFSPLUS |
12892 | +/* hfsplus.c */ | |
392086de AM |
12893 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
12894 | + int force_wr); | |
4a4d8108 AM |
12895 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
12896 | + struct file *h_file); | |
12897 | +#else | |
c1595e42 JR |
12898 | +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry, |
12899 | + aufs_bindex_t bindex, int force_wr) | |
4a4d8108 AM |
12900 | +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex, |
12901 | + struct file *h_file); | |
12902 | +#endif | |
1facf9fc | 12903 | + |
4a4d8108 AM |
12904 | +/* f_op.c */ |
12905 | +extern const struct file_operations aufs_file_fop; | |
b912730e | 12906 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file); |
4a4d8108 | 12907 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file); |
b912730e | 12908 | +struct file *au_read_pre(struct file *file, int keep_fi); |
4a4d8108 | 12909 | + |
4a4d8108 AM |
12910 | +/* finfo.c */ |
12911 | +void au_hfput(struct au_hfile *hf, struct file *file); | |
12912 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, | |
12913 | + struct file *h_file); | |
1facf9fc | 12914 | + |
4a4d8108 | 12915 | +void au_update_figen(struct file *file); |
4a4d8108 AM |
12916 | +struct au_fidir *au_fidir_alloc(struct super_block *sb); |
12917 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr); | |
1facf9fc | 12918 | + |
4a4d8108 AM |
12919 | +void au_fi_init_once(void *_fi); |
12920 | +void au_finfo_fin(struct file *file); | |
12921 | +int au_finfo_init(struct file *file, struct au_fidir *fidir); | |
1facf9fc | 12922 | + |
4a4d8108 AM |
12923 | +/* ioctl.c */ |
12924 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
12925 | +#ifdef CONFIG_COMPAT |
12926 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
12927 | + unsigned long arg); | |
c2b27bf2 AM |
12928 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
12929 | + unsigned long arg); | |
b752ccd1 | 12930 | +#endif |
1facf9fc | 12931 | + |
4a4d8108 | 12932 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12933 | + |
4a4d8108 AM |
12934 | +static inline struct au_finfo *au_fi(struct file *file) |
12935 | +{ | |
38d290e6 | 12936 | + return file->private_data; |
4a4d8108 | 12937 | +} |
1facf9fc | 12938 | + |
4a4d8108 | 12939 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12940 | + |
4a4d8108 AM |
12941 | +/* |
12942 | + * fi_read_lock, fi_write_lock, | |
12943 | + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock | |
12944 | + */ | |
12945 | +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem); | |
1308ab2a | 12946 | + |
4a4d8108 AM |
12947 | +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem) |
12948 | +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem) | |
12949 | +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem) | |
1facf9fc | 12950 | + |
1308ab2a | 12951 | +/* ---------------------------------------------------------------------- */ |
12952 | + | |
4a4d8108 AM |
12953 | +/* todo: hard/soft set? */ |
12954 | +static inline aufs_bindex_t au_fbstart(struct file *file) | |
dece6358 | 12955 | +{ |
4a4d8108 AM |
12956 | + FiMustAnyLock(file); |
12957 | + return au_fi(file)->fi_btop; | |
12958 | +} | |
dece6358 | 12959 | + |
4a4d8108 AM |
12960 | +static inline aufs_bindex_t au_fbend_dir(struct file *file) |
12961 | +{ | |
12962 | + FiMustAnyLock(file); | |
12963 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12964 | + return au_fi(file)->fi_hdir->fd_bbot; | |
12965 | +} | |
1facf9fc | 12966 | + |
4a4d8108 AM |
12967 | +static inline struct au_vdir *au_fvdir_cache(struct file *file) |
12968 | +{ | |
12969 | + FiMustAnyLock(file); | |
12970 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12971 | + return au_fi(file)->fi_hdir->fd_vdir_cache; | |
12972 | +} | |
1facf9fc | 12973 | + |
4a4d8108 AM |
12974 | +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex) |
12975 | +{ | |
12976 | + FiMustWriteLock(file); | |
12977 | + au_fi(file)->fi_btop = bindex; | |
12978 | +} | |
1facf9fc | 12979 | + |
4a4d8108 AM |
12980 | +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex) |
12981 | +{ | |
12982 | + FiMustWriteLock(file); | |
12983 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12984 | + au_fi(file)->fi_hdir->fd_bbot = bindex; | |
12985 | +} | |
1308ab2a | 12986 | + |
4a4d8108 AM |
12987 | +static inline void au_set_fvdir_cache(struct file *file, |
12988 | + struct au_vdir *vdir_cache) | |
12989 | +{ | |
12990 | + FiMustWriteLock(file); | |
12991 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12992 | + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache; | |
12993 | +} | |
dece6358 | 12994 | + |
4a4d8108 AM |
12995 | +static inline struct file *au_hf_top(struct file *file) |
12996 | +{ | |
12997 | + FiMustAnyLock(file); | |
12998 | + AuDebugOn(au_fi(file)->fi_hdir); | |
12999 | + return au_fi(file)->fi_htop.hf_file; | |
13000 | +} | |
1facf9fc | 13001 | + |
4a4d8108 AM |
13002 | +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex) |
13003 | +{ | |
13004 | + FiMustAnyLock(file); | |
13005 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
13006 | + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file; | |
dece6358 AM |
13007 | +} |
13008 | + | |
4a4d8108 AM |
13009 | +/* todo: memory barrier? */ |
13010 | +static inline unsigned int au_figen(struct file *f) | |
dece6358 | 13011 | +{ |
4a4d8108 AM |
13012 | + return atomic_read(&au_fi(f)->fi_generation); |
13013 | +} | |
dece6358 | 13014 | + |
2cbb1c4b JR |
13015 | +static inline void au_set_mmapped(struct file *f) |
13016 | +{ | |
13017 | + if (atomic_inc_return(&au_fi(f)->fi_mmapped)) | |
13018 | + return; | |
0c3ec466 | 13019 | + pr_warn("fi_mmapped wrapped around\n"); |
2cbb1c4b JR |
13020 | + while (!atomic_inc_return(&au_fi(f)->fi_mmapped)) |
13021 | + ; | |
13022 | +} | |
13023 | + | |
13024 | +static inline void au_unset_mmapped(struct file *f) | |
13025 | +{ | |
13026 | + atomic_dec(&au_fi(f)->fi_mmapped); | |
13027 | +} | |
13028 | + | |
4a4d8108 AM |
13029 | +static inline int au_test_mmapped(struct file *f) |
13030 | +{ | |
2cbb1c4b JR |
13031 | + return atomic_read(&au_fi(f)->fi_mmapped); |
13032 | +} | |
13033 | + | |
13034 | +/* customize vma->vm_file */ | |
13035 | + | |
13036 | +static inline void au_do_vm_file_reset(struct vm_area_struct *vma, | |
13037 | + struct file *file) | |
13038 | +{ | |
53392da6 AM |
13039 | + struct file *f; |
13040 | + | |
13041 | + f = vma->vm_file; | |
2cbb1c4b JR |
13042 | + get_file(file); |
13043 | + vma->vm_file = file; | |
53392da6 | 13044 | + fput(f); |
2cbb1c4b JR |
13045 | +} |
13046 | + | |
13047 | +#ifdef CONFIG_MMU | |
13048 | +#define AuDbgVmRegion(file, vma) do {} while (0) | |
13049 | + | |
13050 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
13051 | + struct file *file) | |
13052 | +{ | |
13053 | + au_do_vm_file_reset(vma, file); | |
13054 | +} | |
13055 | +#else | |
13056 | +#define AuDbgVmRegion(file, vma) \ | |
13057 | + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file)) | |
13058 | + | |
13059 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
13060 | + struct file *file) | |
13061 | +{ | |
53392da6 AM |
13062 | + struct file *f; |
13063 | + | |
2cbb1c4b | 13064 | + au_do_vm_file_reset(vma, file); |
53392da6 | 13065 | + f = vma->vm_region->vm_file; |
2cbb1c4b JR |
13066 | + get_file(file); |
13067 | + vma->vm_region->vm_file = file; | |
53392da6 | 13068 | + fput(f); |
2cbb1c4b JR |
13069 | +} |
13070 | +#endif /* CONFIG_MMU */ | |
13071 | + | |
13072 | +/* handle vma->vm_prfile */ | |
fb47a38f | 13073 | +static inline void au_vm_prfile_set(struct vm_area_struct *vma, |
2cbb1c4b JR |
13074 | + struct file *file) |
13075 | +{ | |
2cbb1c4b JR |
13076 | + get_file(file); |
13077 | + vma->vm_prfile = file; | |
13078 | +#ifndef CONFIG_MMU | |
13079 | + get_file(file); | |
13080 | + vma->vm_region->vm_prfile = file; | |
13081 | +#endif | |
fb47a38f | 13082 | +} |
1308ab2a | 13083 | + |
4a4d8108 AM |
13084 | +#endif /* __KERNEL__ */ |
13085 | +#endif /* __AUFS_FILE_H__ */ | |
7f207e10 AM |
13086 | diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c |
13087 | --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 13088 | +++ linux/fs/aufs/finfo.c 2015-09-24 10:47:58.251386326 +0200 |
b912730e | 13089 | @@ -0,0 +1,157 @@ |
4a4d8108 | 13090 | +/* |
2000de60 | 13091 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
13092 | + * |
13093 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13094 | + * it under the terms of the GNU General Public License as published by | |
13095 | + * the Free Software Foundation; either version 2 of the License, or | |
13096 | + * (at your option) any later version. | |
13097 | + * | |
13098 | + * This program is distributed in the hope that it will be useful, | |
13099 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13100 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13101 | + * GNU General Public License for more details. | |
13102 | + * | |
13103 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13104 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 13105 | + */ |
1308ab2a | 13106 | + |
4a4d8108 AM |
13107 | +/* |
13108 | + * file private data | |
13109 | + */ | |
1facf9fc | 13110 | + |
4a4d8108 | 13111 | +#include "aufs.h" |
1facf9fc | 13112 | + |
4a4d8108 AM |
13113 | +void au_hfput(struct au_hfile *hf, struct file *file) |
13114 | +{ | |
13115 | + /* todo: direct access f_flags */ | |
2cbb1c4b | 13116 | + if (vfsub_file_flags(file) & __FMODE_EXEC) |
4a4d8108 AM |
13117 | + allow_write_access(hf->hf_file); |
13118 | + fput(hf->hf_file); | |
13119 | + hf->hf_file = NULL; | |
e49829fe | 13120 | + atomic_dec(&hf->hf_br->br_count); |
4a4d8108 AM |
13121 | + hf->hf_br = NULL; |
13122 | +} | |
1facf9fc | 13123 | + |
4a4d8108 AM |
13124 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val) |
13125 | +{ | |
13126 | + struct au_finfo *finfo = au_fi(file); | |
13127 | + struct au_hfile *hf; | |
13128 | + struct au_fidir *fidir; | |
13129 | + | |
13130 | + fidir = finfo->fi_hdir; | |
13131 | + if (!fidir) { | |
13132 | + AuDebugOn(finfo->fi_btop != bindex); | |
13133 | + hf = &finfo->fi_htop; | |
13134 | + } else | |
13135 | + hf = fidir->fd_hfile + bindex; | |
13136 | + | |
13137 | + if (hf && hf->hf_file) | |
13138 | + au_hfput(hf, file); | |
13139 | + if (val) { | |
13140 | + FiMustWriteLock(file); | |
b912730e | 13141 | + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry)); |
4a4d8108 | 13142 | + hf->hf_file = val; |
2000de60 | 13143 | + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex); |
1308ab2a | 13144 | + } |
4a4d8108 | 13145 | +} |
1facf9fc | 13146 | + |
4a4d8108 AM |
13147 | +void au_update_figen(struct file *file) |
13148 | +{ | |
2000de60 | 13149 | + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry)); |
4a4d8108 | 13150 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 13151 | +} |
13152 | + | |
4a4d8108 AM |
13153 | +/* ---------------------------------------------------------------------- */ |
13154 | + | |
4a4d8108 AM |
13155 | +struct au_fidir *au_fidir_alloc(struct super_block *sb) |
13156 | +{ | |
13157 | + struct au_fidir *fidir; | |
13158 | + int nbr; | |
13159 | + | |
13160 | + nbr = au_sbend(sb) + 1; | |
13161 | + if (nbr < 2) | |
13162 | + nbr = 2; /* initial allocate for 2 branches */ | |
13163 | + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS); | |
13164 | + if (fidir) { | |
13165 | + fidir->fd_bbot = -1; | |
13166 | + fidir->fd_nent = nbr; | |
13167 | + fidir->fd_vdir_cache = NULL; | |
13168 | + } | |
13169 | + | |
13170 | + return fidir; | |
13171 | +} | |
13172 | + | |
13173 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr) | |
13174 | +{ | |
13175 | + int err; | |
13176 | + struct au_fidir *fidir, *p; | |
13177 | + | |
13178 | + AuRwMustWriteLock(&finfo->fi_rwsem); | |
13179 | + fidir = finfo->fi_hdir; | |
13180 | + AuDebugOn(!fidir); | |
13181 | + | |
13182 | + err = -ENOMEM; | |
13183 | + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr), | |
13184 | + GFP_NOFS); | |
13185 | + if (p) { | |
13186 | + p->fd_nent = nbr; | |
13187 | + finfo->fi_hdir = p; | |
13188 | + err = 0; | |
13189 | + } | |
1facf9fc | 13190 | + |
dece6358 | 13191 | + return err; |
1facf9fc | 13192 | +} |
1308ab2a | 13193 | + |
13194 | +/* ---------------------------------------------------------------------- */ | |
13195 | + | |
4a4d8108 | 13196 | +void au_finfo_fin(struct file *file) |
1308ab2a | 13197 | +{ |
4a4d8108 AM |
13198 | + struct au_finfo *finfo; |
13199 | + | |
2000de60 | 13200 | + au_nfiles_dec(file->f_path.dentry->d_sb); |
7f207e10 | 13201 | + |
4a4d8108 AM |
13202 | + finfo = au_fi(file); |
13203 | + AuDebugOn(finfo->fi_hdir); | |
13204 | + AuRwDestroy(&finfo->fi_rwsem); | |
13205 | + au_cache_free_finfo(finfo); | |
1308ab2a | 13206 | +} |
1308ab2a | 13207 | + |
e49829fe | 13208 | +void au_fi_init_once(void *_finfo) |
4a4d8108 | 13209 | +{ |
e49829fe | 13210 | + struct au_finfo *finfo = _finfo; |
2cbb1c4b | 13211 | + static struct lock_class_key aufs_fi; |
1308ab2a | 13212 | + |
e49829fe JR |
13213 | + au_rw_init(&finfo->fi_rwsem); |
13214 | + au_rw_class(&finfo->fi_rwsem, &aufs_fi); | |
4a4d8108 | 13215 | +} |
1308ab2a | 13216 | + |
4a4d8108 AM |
13217 | +int au_finfo_init(struct file *file, struct au_fidir *fidir) |
13218 | +{ | |
1716fcea | 13219 | + int err; |
4a4d8108 AM |
13220 | + struct au_finfo *finfo; |
13221 | + struct dentry *dentry; | |
13222 | + | |
13223 | + err = -ENOMEM; | |
2000de60 | 13224 | + dentry = file->f_path.dentry; |
4a4d8108 AM |
13225 | + finfo = au_cache_alloc_finfo(); |
13226 | + if (unlikely(!finfo)) | |
13227 | + goto out; | |
13228 | + | |
13229 | + err = 0; | |
7f207e10 | 13230 | + au_nfiles_inc(dentry->d_sb); |
1716fcea AM |
13231 | + /* verbose coding for lock class name */ |
13232 | + if (!fidir) | |
13233 | + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO); | |
13234 | + else | |
13235 | + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO); | |
4a4d8108 AM |
13236 | + au_rw_write_lock(&finfo->fi_rwsem); |
13237 | + finfo->fi_btop = -1; | |
13238 | + finfo->fi_hdir = fidir; | |
13239 | + atomic_set(&finfo->fi_generation, au_digen(dentry)); | |
13240 | + /* smp_mb(); */ /* atomic_set */ | |
13241 | + | |
13242 | + file->private_data = finfo; | |
13243 | + | |
13244 | +out: | |
13245 | + return err; | |
13246 | +} | |
7f207e10 AM |
13247 | diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c |
13248 | --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 13249 | +++ linux/fs/aufs/f_op.c 2015-09-24 10:47:58.251386326 +0200 |
5527c038 | 13250 | @@ -0,0 +1,738 @@ |
dece6358 | 13251 | +/* |
2000de60 | 13252 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
dece6358 AM |
13253 | + * |
13254 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13255 | + * it under the terms of the GNU General Public License as published by | |
13256 | + * the Free Software Foundation; either version 2 of the License, or | |
13257 | + * (at your option) any later version. | |
13258 | + * | |
13259 | + * This program is distributed in the hope that it will be useful, | |
13260 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13261 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13262 | + * GNU General Public License for more details. | |
13263 | + * | |
13264 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13265 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 13266 | + */ |
1facf9fc | 13267 | + |
13268 | +/* | |
4a4d8108 | 13269 | + * file and vm operations |
1facf9fc | 13270 | + */ |
dece6358 | 13271 | + |
86dc4139 | 13272 | +#include <linux/aio.h> |
4a4d8108 AM |
13273 | +#include <linux/fs_stack.h> |
13274 | +#include <linux/mman.h> | |
4a4d8108 | 13275 | +#include <linux/security.h> |
dece6358 AM |
13276 | +#include "aufs.h" |
13277 | + | |
b912730e | 13278 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 13279 | +{ |
4a4d8108 AM |
13280 | + int err; |
13281 | + aufs_bindex_t bindex; | |
4a4d8108 AM |
13282 | + struct dentry *dentry; |
13283 | + struct au_finfo *finfo; | |
38d290e6 | 13284 | + struct inode *h_inode; |
4a4d8108 AM |
13285 | + |
13286 | + FiMustWriteLock(file); | |
13287 | + | |
523b37e3 | 13288 | + err = 0; |
2000de60 | 13289 | + dentry = file->f_path.dentry; |
b912730e | 13290 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
4a4d8108 AM |
13291 | + finfo = au_fi(file); |
13292 | + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop)); | |
2cbb1c4b | 13293 | + atomic_set(&finfo->fi_mmapped, 0); |
4a4d8108 | 13294 | + bindex = au_dbstart(dentry); |
b912730e AM |
13295 | + if (!h_file) |
13296 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); | |
13297 | + else | |
13298 | + get_file(h_file); | |
4a4d8108 AM |
13299 | + if (IS_ERR(h_file)) |
13300 | + err = PTR_ERR(h_file); | |
13301 | + else { | |
38d290e6 JR |
13302 | + if ((flags & __O_TMPFILE) |
13303 | + && !(flags & O_EXCL)) { | |
13304 | + h_inode = file_inode(h_file); | |
13305 | + spin_lock(&h_inode->i_lock); | |
13306 | + h_inode->i_state |= I_LINKABLE; | |
13307 | + spin_unlock(&h_inode->i_lock); | |
13308 | + } | |
4a4d8108 AM |
13309 | + au_set_fbstart(file, bindex); |
13310 | + au_set_h_fptr(file, bindex, h_file); | |
13311 | + au_update_figen(file); | |
13312 | + /* todo: necessary? */ | |
13313 | + /* file->f_ra = h_file->f_ra; */ | |
13314 | + } | |
027c5e7a | 13315 | + |
4a4d8108 | 13316 | + return err; |
1facf9fc | 13317 | +} |
13318 | + | |
4a4d8108 AM |
13319 | +static int aufs_open_nondir(struct inode *inode __maybe_unused, |
13320 | + struct file *file) | |
1facf9fc | 13321 | +{ |
4a4d8108 | 13322 | + int err; |
1308ab2a | 13323 | + struct super_block *sb; |
b912730e AM |
13324 | + struct au_do_open_args args = { |
13325 | + .open = au_do_open_nondir | |
13326 | + }; | |
1facf9fc | 13327 | + |
523b37e3 AM |
13328 | + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n", |
13329 | + file, vfsub_file_flags(file), file->f_mode); | |
1facf9fc | 13330 | + |
2000de60 | 13331 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 13332 | + si_read_lock(sb, AuLock_FLUSH); |
b912730e | 13333 | + err = au_do_open(file, &args); |
4a4d8108 AM |
13334 | + si_read_unlock(sb); |
13335 | + return err; | |
13336 | +} | |
1facf9fc | 13337 | + |
4a4d8108 AM |
13338 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file) |
13339 | +{ | |
13340 | + struct au_finfo *finfo; | |
13341 | + aufs_bindex_t bindex; | |
1facf9fc | 13342 | + |
4a4d8108 | 13343 | + finfo = au_fi(file); |
2000de60 JR |
13344 | + au_sphl_del(&finfo->fi_hlist, |
13345 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
4a4d8108 | 13346 | + bindex = finfo->fi_btop; |
b4510431 | 13347 | + if (bindex >= 0) |
4a4d8108 | 13348 | + au_set_h_fptr(file, bindex, NULL); |
7f207e10 | 13349 | + |
4a4d8108 AM |
13350 | + au_finfo_fin(file); |
13351 | + return 0; | |
1facf9fc | 13352 | +} |
13353 | + | |
4a4d8108 AM |
13354 | +/* ---------------------------------------------------------------------- */ |
13355 | + | |
13356 | +static int au_do_flush_nondir(struct file *file, fl_owner_t id) | |
dece6358 | 13357 | +{ |
1308ab2a | 13358 | + int err; |
4a4d8108 AM |
13359 | + struct file *h_file; |
13360 | + | |
13361 | + err = 0; | |
13362 | + h_file = au_hf_top(file); | |
13363 | + if (h_file) | |
13364 | + err = vfsub_flush(h_file, id); | |
13365 | + return err; | |
13366 | +} | |
13367 | + | |
13368 | +static int aufs_flush_nondir(struct file *file, fl_owner_t id) | |
13369 | +{ | |
13370 | + return au_do_flush(file, id, au_do_flush_nondir); | |
13371 | +} | |
13372 | + | |
13373 | +/* ---------------------------------------------------------------------- */ | |
9dbd164d AM |
13374 | +/* |
13375 | + * read and write functions acquire [fdi]_rwsem once, but release before | |
13376 | + * mmap_sem. This is because to stop a race condition between mmap(2). | |
13377 | + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping | |
13378 | + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in | |
13379 | + * read functions after [fdi]_rwsem are released, but it should be harmless. | |
13380 | + */ | |
4a4d8108 | 13381 | + |
b912730e AM |
13382 | +/* Callers should call au_read_post() or fput() in the end */ |
13383 | +struct file *au_read_pre(struct file *file, int keep_fi) | |
4a4d8108 | 13384 | +{ |
4a4d8108 | 13385 | + struct file *h_file; |
b912730e | 13386 | + int err; |
1facf9fc | 13387 | + |
4a4d8108 | 13388 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0); |
b912730e AM |
13389 | + if (!err) { |
13390 | + di_read_unlock(file->f_path.dentry, AuLock_IR); | |
13391 | + h_file = au_hf_top(file); | |
13392 | + get_file(h_file); | |
13393 | + if (!keep_fi) | |
13394 | + fi_read_unlock(file); | |
13395 | + } else | |
13396 | + h_file = ERR_PTR(err); | |
13397 | + | |
13398 | + return h_file; | |
13399 | +} | |
13400 | + | |
13401 | +static void au_read_post(struct inode *inode, struct file *h_file) | |
13402 | +{ | |
13403 | + /* update without lock, I don't think it a problem */ | |
13404 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
13405 | + fput(h_file); | |
13406 | +} | |
13407 | + | |
13408 | +struct au_write_pre { | |
13409 | + blkcnt_t blks; | |
13410 | + aufs_bindex_t bstart; | |
13411 | +}; | |
13412 | + | |
13413 | +/* | |
13414 | + * return with iinfo is write-locked | |
13415 | + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the | |
13416 | + * end | |
13417 | + */ | |
13418 | +static struct file *au_write_pre(struct file *file, int do_ready, | |
13419 | + struct au_write_pre *wpre) | |
13420 | +{ | |
13421 | + struct file *h_file; | |
13422 | + struct dentry *dentry; | |
13423 | + int err; | |
13424 | + struct au_pin pin; | |
13425 | + | |
13426 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); | |
13427 | + h_file = ERR_PTR(err); | |
dece6358 AM |
13428 | + if (unlikely(err)) |
13429 | + goto out; | |
1facf9fc | 13430 | + |
b912730e AM |
13431 | + dentry = file->f_path.dentry; |
13432 | + if (do_ready) { | |
13433 | + err = au_ready_to_write(file, -1, &pin); | |
13434 | + if (unlikely(err)) { | |
13435 | + h_file = ERR_PTR(err); | |
13436 | + di_write_unlock(dentry); | |
13437 | + goto out_fi; | |
13438 | + } | |
13439 | + } | |
13440 | + | |
13441 | + di_downgrade_lock(dentry, /*flags*/0); | |
13442 | + if (wpre) | |
13443 | + wpre->bstart = au_fbstart(file); | |
4a4d8108 | 13444 | + h_file = au_hf_top(file); |
9dbd164d | 13445 | + get_file(h_file); |
b912730e AM |
13446 | + if (wpre) |
13447 | + wpre->blks = file_inode(h_file)->i_blocks; | |
13448 | + if (do_ready) | |
13449 | + au_unpin(&pin); | |
13450 | + di_read_unlock(dentry, /*flags*/0); | |
13451 | + | |
13452 | +out_fi: | |
13453 | + fi_write_unlock(file); | |
13454 | +out: | |
13455 | + return h_file; | |
13456 | +} | |
13457 | + | |
13458 | +static void au_write_post(struct inode *inode, struct file *h_file, | |
13459 | + struct au_write_pre *wpre, ssize_t written) | |
13460 | +{ | |
13461 | + struct inode *h_inode; | |
13462 | + | |
13463 | + au_cpup_attr_timesizes(inode); | |
13464 | + AuDebugOn(au_ibstart(inode) != wpre->bstart); | |
13465 | + h_inode = file_inode(h_file); | |
13466 | + inode->i_mode = h_inode->i_mode; | |
13467 | + ii_write_unlock(inode); | |
13468 | + fput(h_file); | |
13469 | + | |
13470 | + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */ | |
13471 | + if (written > 0) | |
13472 | + au_fhsm_wrote(inode->i_sb, wpre->bstart, | |
13473 | + /*force*/h_inode->i_blocks > wpre->blks); | |
13474 | +} | |
13475 | + | |
13476 | +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count, | |
13477 | + loff_t *ppos) | |
13478 | +{ | |
13479 | + ssize_t err; | |
13480 | + struct inode *inode; | |
13481 | + struct file *h_file; | |
13482 | + struct super_block *sb; | |
13483 | + | |
13484 | + inode = file_inode(file); | |
13485 | + sb = inode->i_sb; | |
13486 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
13487 | + | |
13488 | + h_file = au_read_pre(file, /*keep_fi*/0); | |
13489 | + err = PTR_ERR(h_file); | |
13490 | + if (IS_ERR(h_file)) | |
13491 | + goto out; | |
9dbd164d AM |
13492 | + |
13493 | + /* filedata may be obsoleted by concurrent copyup, but no problem */ | |
4a4d8108 AM |
13494 | + err = vfsub_read_u(h_file, buf, count, ppos); |
13495 | + /* todo: necessary? */ | |
13496 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 13497 | + au_read_post(inode, h_file); |
1308ab2a | 13498 | + |
4f0767ce | 13499 | +out: |
dece6358 AM |
13500 | + si_read_unlock(sb); |
13501 | + return err; | |
13502 | +} | |
1facf9fc | 13503 | + |
e49829fe JR |
13504 | +/* |
13505 | + * todo: very ugly | |
13506 | + * it locks both of i_mutex and si_rwsem for read in safe. | |
13507 | + * if the plink maintenance mode continues forever (that is the problem), | |
13508 | + * may loop forever. | |
13509 | + */ | |
13510 | +static void au_mtx_and_read_lock(struct inode *inode) | |
13511 | +{ | |
13512 | + int err; | |
13513 | + struct super_block *sb = inode->i_sb; | |
13514 | + | |
13515 | + while (1) { | |
13516 | + mutex_lock(&inode->i_mutex); | |
13517 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
13518 | + if (!err) | |
13519 | + break; | |
13520 | + mutex_unlock(&inode->i_mutex); | |
13521 | + si_read_lock(sb, AuLock_NOPLMW); | |
13522 | + si_read_unlock(sb); | |
13523 | + } | |
13524 | +} | |
13525 | + | |
4a4d8108 AM |
13526 | +static ssize_t aufs_write(struct file *file, const char __user *ubuf, |
13527 | + size_t count, loff_t *ppos) | |
dece6358 | 13528 | +{ |
4a4d8108 | 13529 | + ssize_t err; |
b912730e AM |
13530 | + struct au_write_pre wpre; |
13531 | + struct inode *inode; | |
4a4d8108 AM |
13532 | + struct file *h_file; |
13533 | + char __user *buf = (char __user *)ubuf; | |
1facf9fc | 13534 | + |
b912730e | 13535 | + inode = file_inode(file); |
e49829fe | 13536 | + au_mtx_and_read_lock(inode); |
1facf9fc | 13537 | + |
b912730e AM |
13538 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13539 | + err = PTR_ERR(h_file); | |
13540 | + if (IS_ERR(h_file)) | |
9dbd164d | 13541 | + goto out; |
9dbd164d | 13542 | + |
4a4d8108 | 13543 | + err = vfsub_write_u(h_file, buf, count, ppos); |
b912730e | 13544 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 13545 | + |
4f0767ce | 13546 | +out: |
b912730e | 13547 | + si_read_unlock(inode->i_sb); |
4a4d8108 | 13548 | + mutex_unlock(&inode->i_mutex); |
dece6358 AM |
13549 | + return err; |
13550 | +} | |
1facf9fc | 13551 | + |
076b876e AM |
13552 | +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio, |
13553 | + struct iov_iter *iov_iter) | |
dece6358 | 13554 | +{ |
4a4d8108 AM |
13555 | + ssize_t err; |
13556 | + struct file *file; | |
076b876e | 13557 | + ssize_t (*iter)(struct kiocb *, struct iov_iter *); |
1facf9fc | 13558 | + |
4a4d8108 AM |
13559 | + err = security_file_permission(h_file, rw); |
13560 | + if (unlikely(err)) | |
13561 | + goto out; | |
1facf9fc | 13562 | + |
4a4d8108 | 13563 | + err = -ENOSYS; |
076b876e | 13564 | + iter = NULL; |
5527c038 | 13565 | + if (rw == MAY_READ) |
076b876e | 13566 | + iter = h_file->f_op->read_iter; |
5527c038 | 13567 | + else if (rw == MAY_WRITE) |
076b876e | 13568 | + iter = h_file->f_op->write_iter; |
076b876e AM |
13569 | + |
13570 | + file = kio->ki_filp; | |
13571 | + kio->ki_filp = h_file; | |
13572 | + if (iter) { | |
2cbb1c4b | 13573 | + lockdep_off(); |
076b876e AM |
13574 | + err = iter(kio, iov_iter); |
13575 | + lockdep_on(); | |
4a4d8108 AM |
13576 | + } else |
13577 | + /* currently there is no such fs */ | |
13578 | + WARN_ON_ONCE(1); | |
076b876e | 13579 | + kio->ki_filp = file; |
1facf9fc | 13580 | + |
4f0767ce | 13581 | +out: |
dece6358 AM |
13582 | + return err; |
13583 | +} | |
1facf9fc | 13584 | + |
076b876e | 13585 | +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1facf9fc | 13586 | +{ |
4a4d8108 AM |
13587 | + ssize_t err; |
13588 | + struct file *file, *h_file; | |
b912730e | 13589 | + struct inode *inode; |
dece6358 | 13590 | + struct super_block *sb; |
1facf9fc | 13591 | + |
4a4d8108 | 13592 | + file = kio->ki_filp; |
b912730e AM |
13593 | + inode = file_inode(file); |
13594 | + sb = inode->i_sb; | |
e49829fe | 13595 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 13596 | + |
b912730e AM |
13597 | + h_file = au_read_pre(file, /*keep_fi*/0); |
13598 | + err = PTR_ERR(h_file); | |
13599 | + if (IS_ERR(h_file)) | |
13600 | + goto out; | |
9dbd164d | 13601 | + |
076b876e | 13602 | + err = au_do_iter(h_file, MAY_READ, kio, iov_iter); |
4a4d8108 AM |
13603 | + /* todo: necessary? */ |
13604 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 13605 | + au_read_post(inode, h_file); |
1facf9fc | 13606 | + |
4f0767ce | 13607 | +out: |
4a4d8108 | 13608 | + si_read_unlock(sb); |
1308ab2a | 13609 | + return err; |
13610 | +} | |
1facf9fc | 13611 | + |
076b876e | 13612 | +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1308ab2a | 13613 | +{ |
4a4d8108 | 13614 | + ssize_t err; |
b912730e AM |
13615 | + struct au_write_pre wpre; |
13616 | + struct inode *inode; | |
4a4d8108 | 13617 | + struct file *file, *h_file; |
1308ab2a | 13618 | + |
4a4d8108 | 13619 | + file = kio->ki_filp; |
b912730e | 13620 | + inode = file_inode(file); |
e49829fe JR |
13621 | + au_mtx_and_read_lock(inode); |
13622 | + | |
b912730e AM |
13623 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13624 | + err = PTR_ERR(h_file); | |
13625 | + if (IS_ERR(h_file)) | |
9dbd164d | 13626 | + goto out; |
9dbd164d | 13627 | + |
076b876e | 13628 | + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter); |
b912730e | 13629 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 13630 | + |
4f0767ce | 13631 | +out: |
b912730e | 13632 | + si_read_unlock(inode->i_sb); |
4a4d8108 | 13633 | + mutex_unlock(&inode->i_mutex); |
dece6358 | 13634 | + return err; |
1facf9fc | 13635 | +} |
13636 | + | |
4a4d8108 AM |
13637 | +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, |
13638 | + struct pipe_inode_info *pipe, size_t len, | |
13639 | + unsigned int flags) | |
1facf9fc | 13640 | +{ |
4a4d8108 AM |
13641 | + ssize_t err; |
13642 | + struct file *h_file; | |
b912730e | 13643 | + struct inode *inode; |
dece6358 | 13644 | + struct super_block *sb; |
1facf9fc | 13645 | + |
b912730e AM |
13646 | + inode = file_inode(file); |
13647 | + sb = inode->i_sb; | |
e49829fe | 13648 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e AM |
13649 | + |
13650 | + h_file = au_read_pre(file, /*keep_fi*/1); | |
13651 | + err = PTR_ERR(h_file); | |
13652 | + if (IS_ERR(h_file)) | |
dece6358 | 13653 | + goto out; |
1facf9fc | 13654 | + |
4a4d8108 | 13655 | + if (au_test_loopback_kthread()) { |
2000de60 | 13656 | + au_warn_loopback(h_file->f_path.dentry->d_sb); |
87a755f4 AM |
13657 | + if (file->f_mapping != h_file->f_mapping) { |
13658 | + file->f_mapping = h_file->f_mapping; | |
13659 | + smp_mb(); /* unnecessary? */ | |
13660 | + } | |
1308ab2a | 13661 | + } |
9dbd164d AM |
13662 | + fi_read_unlock(file); |
13663 | + | |
4a4d8108 AM |
13664 | + err = vfsub_splice_to(h_file, ppos, pipe, len, flags); |
13665 | + /* todo: necessasry? */ | |
13666 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 13667 | + au_read_post(inode, h_file); |
1facf9fc | 13668 | + |
4f0767ce | 13669 | +out: |
4a4d8108 | 13670 | + si_read_unlock(sb); |
dece6358 | 13671 | + return err; |
1facf9fc | 13672 | +} |
13673 | + | |
4a4d8108 AM |
13674 | +static ssize_t |
13675 | +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos, | |
13676 | + size_t len, unsigned int flags) | |
1facf9fc | 13677 | +{ |
4a4d8108 | 13678 | + ssize_t err; |
b912730e AM |
13679 | + struct au_write_pre wpre; |
13680 | + struct inode *inode; | |
076b876e | 13681 | + struct file *h_file; |
1facf9fc | 13682 | + |
b912730e | 13683 | + inode = file_inode(file); |
e49829fe | 13684 | + au_mtx_and_read_lock(inode); |
9dbd164d | 13685 | + |
b912730e AM |
13686 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13687 | + err = PTR_ERR(h_file); | |
13688 | + if (IS_ERR(h_file)) | |
9dbd164d | 13689 | + goto out; |
9dbd164d | 13690 | + |
4a4d8108 | 13691 | + err = vfsub_splice_from(pipe, h_file, ppos, len, flags); |
b912730e | 13692 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 13693 | + |
4f0767ce | 13694 | +out: |
b912730e | 13695 | + si_read_unlock(inode->i_sb); |
4a4d8108 AM |
13696 | + mutex_unlock(&inode->i_mutex); |
13697 | + return err; | |
13698 | +} | |
1facf9fc | 13699 | + |
38d290e6 JR |
13700 | +static long aufs_fallocate(struct file *file, int mode, loff_t offset, |
13701 | + loff_t len) | |
13702 | +{ | |
13703 | + long err; | |
b912730e | 13704 | + struct au_write_pre wpre; |
38d290e6 JR |
13705 | + struct inode *inode; |
13706 | + struct file *h_file; | |
13707 | + | |
b912730e | 13708 | + inode = file_inode(file); |
38d290e6 JR |
13709 | + au_mtx_and_read_lock(inode); |
13710 | + | |
b912730e AM |
13711 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
13712 | + err = PTR_ERR(h_file); | |
13713 | + if (IS_ERR(h_file)) | |
38d290e6 | 13714 | + goto out; |
38d290e6 JR |
13715 | + |
13716 | + lockdep_off(); | |
03673fb0 | 13717 | + err = vfs_fallocate(h_file, mode, offset, len); |
38d290e6 | 13718 | + lockdep_on(); |
b912730e | 13719 | + au_write_post(inode, h_file, &wpre, /*written*/1); |
38d290e6 JR |
13720 | + |
13721 | +out: | |
b912730e | 13722 | + si_read_unlock(inode->i_sb); |
38d290e6 JR |
13723 | + mutex_unlock(&inode->i_mutex); |
13724 | + return err; | |
13725 | +} | |
13726 | + | |
4a4d8108 AM |
13727 | +/* ---------------------------------------------------------------------- */ |
13728 | + | |
9dbd164d AM |
13729 | +/* |
13730 | + * The locking order around current->mmap_sem. | |
13731 | + * - in most and regular cases | |
13732 | + * file I/O syscall -- aufs_read() or something | |
13733 | + * -- si_rwsem for read -- mmap_sem | |
13734 | + * (Note that [fdi]i_rwsem are released before mmap_sem). | |
13735 | + * - in mmap case | |
13736 | + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem | |
13737 | + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for | |
13738 | + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in | |
13739 | + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though. | |
13740 | + * It means that when aufs acquires si_rwsem for write, the process should never | |
13741 | + * acquire mmap_sem. | |
13742 | + * | |
392086de | 13743 | + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a |
9dbd164d AM |
13744 | + * problem either since any directory is not able to be mmap-ed. |
13745 | + * The similar scenario is applied to aufs_readlink() too. | |
13746 | + */ | |
13747 | + | |
38d290e6 | 13748 | +#if 0 /* stop calling security_file_mmap() */ |
2dfbb274 AM |
13749 | +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */ |
13750 | +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b) | |
13751 | + | |
13752 | +static unsigned long au_arch_prot_conv(unsigned long flags) | |
13753 | +{ | |
13754 | + /* currently ppc64 only */ | |
13755 | +#ifdef CONFIG_PPC64 | |
13756 | + /* cf. linux/arch/powerpc/include/asm/mman.h */ | |
13757 | + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO); | |
13758 | + return AuConv_VM_PROT(flags, SAO); | |
13759 | +#else | |
13760 | + AuDebugOn(arch_calc_vm_prot_bits(-1)); | |
13761 | + return 0; | |
13762 | +#endif | |
13763 | +} | |
13764 | + | |
13765 | +static unsigned long au_prot_conv(unsigned long flags) | |
13766 | +{ | |
13767 | + return AuConv_VM_PROT(flags, READ) | |
13768 | + | AuConv_VM_PROT(flags, WRITE) | |
13769 | + | AuConv_VM_PROT(flags, EXEC) | |
13770 | + | au_arch_prot_conv(flags); | |
13771 | +} | |
13772 | + | |
13773 | +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */ | |
13774 | +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b) | |
13775 | + | |
13776 | +static unsigned long au_flag_conv(unsigned long flags) | |
13777 | +{ | |
13778 | + return AuConv_VM_MAP(flags, GROWSDOWN) | |
13779 | + | AuConv_VM_MAP(flags, DENYWRITE) | |
2dfbb274 AM |
13780 | + | AuConv_VM_MAP(flags, LOCKED); |
13781 | +} | |
38d290e6 | 13782 | +#endif |
2dfbb274 | 13783 | + |
9dbd164d | 13784 | +static int aufs_mmap(struct file *file, struct vm_area_struct *vma) |
dece6358 | 13785 | +{ |
4a4d8108 | 13786 | + int err; |
4a4d8108 | 13787 | + const unsigned char wlock |
9dbd164d | 13788 | + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED); |
4a4d8108 | 13789 | + struct super_block *sb; |
9dbd164d | 13790 | + struct file *h_file; |
b912730e | 13791 | + struct inode *inode; |
9dbd164d AM |
13792 | + |
13793 | + AuDbgVmRegion(file, vma); | |
1308ab2a | 13794 | + |
b912730e AM |
13795 | + inode = file_inode(file); |
13796 | + sb = inode->i_sb; | |
9dbd164d | 13797 | + lockdep_off(); |
e49829fe | 13798 | + si_read_lock(sb, AuLock_NOPLMW); |
4a4d8108 | 13799 | + |
b912730e | 13800 | + h_file = au_write_pre(file, wlock, /*wpre*/NULL); |
9dbd164d | 13801 | + lockdep_on(); |
b912730e AM |
13802 | + err = PTR_ERR(h_file); |
13803 | + if (IS_ERR(h_file)) | |
13804 | + goto out; | |
1308ab2a | 13805 | + |
b912730e AM |
13806 | + err = 0; |
13807 | + au_set_mmapped(file); | |
9dbd164d | 13808 | + au_vm_file_reset(vma, h_file); |
38d290e6 JR |
13809 | + /* |
13810 | + * we cannot call security_mmap_file() here since it may acquire | |
13811 | + * mmap_sem or i_mutex. | |
13812 | + * | |
13813 | + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags), | |
13814 | + * au_flag_conv(vma->vm_flags)); | |
13815 | + */ | |
9dbd164d AM |
13816 | + if (!err) |
13817 | + err = h_file->f_op->mmap(h_file, vma); | |
b912730e AM |
13818 | + if (!err) { |
13819 | + au_vm_prfile_set(vma, file); | |
13820 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
13821 | + goto out_fput; /* success */ | |
13822 | + } | |
2cbb1c4b JR |
13823 | + au_unset_mmapped(file); |
13824 | + au_vm_file_reset(vma, file); | |
b912730e | 13825 | + |
2cbb1c4b | 13826 | +out_fput: |
9dbd164d | 13827 | + lockdep_off(); |
b912730e AM |
13828 | + ii_write_unlock(inode); |
13829 | + lockdep_on(); | |
13830 | + fput(h_file); | |
4f0767ce | 13831 | +out: |
b912730e | 13832 | + lockdep_off(); |
9dbd164d AM |
13833 | + si_read_unlock(sb); |
13834 | + lockdep_on(); | |
13835 | + AuTraceErr(err); | |
4a4d8108 AM |
13836 | + return err; |
13837 | +} | |
13838 | + | |
13839 | +/* ---------------------------------------------------------------------- */ | |
13840 | + | |
1e00d052 AM |
13841 | +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end, |
13842 | + int datasync) | |
4a4d8108 AM |
13843 | +{ |
13844 | + int err; | |
b912730e | 13845 | + struct au_write_pre wpre; |
4a4d8108 AM |
13846 | + struct inode *inode; |
13847 | + struct file *h_file; | |
4a4d8108 AM |
13848 | + |
13849 | + err = 0; /* -EBADF; */ /* posix? */ | |
13850 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
b912730e | 13851 | + goto out; |
4a4d8108 | 13852 | + |
b912730e AM |
13853 | + inode = file_inode(file); |
13854 | + au_mtx_and_read_lock(inode); | |
13855 | + | |
13856 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); | |
13857 | + err = PTR_ERR(h_file); | |
13858 | + if (IS_ERR(h_file)) | |
4a4d8108 | 13859 | + goto out_unlock; |
4a4d8108 | 13860 | + |
53392da6 | 13861 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
b912730e | 13862 | + au_write_post(inode, h_file, &wpre, /*written*/0); |
4a4d8108 | 13863 | + |
4f0767ce | 13864 | +out_unlock: |
b912730e | 13865 | + si_read_unlock(inode->i_sb); |
1e00d052 | 13866 | + mutex_unlock(&inode->i_mutex); |
b912730e | 13867 | +out: |
4a4d8108 | 13868 | + return err; |
dece6358 AM |
13869 | +} |
13870 | + | |
4a4d8108 AM |
13871 | +/* no one supports this operation, currently */ |
13872 | +#if 0 | |
13873 | +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync) | |
dece6358 | 13874 | +{ |
4a4d8108 | 13875 | + int err; |
b912730e | 13876 | + struct au_write_pre wpre; |
4a4d8108 AM |
13877 | + struct inode *inode; |
13878 | + struct file *file, *h_file; | |
1308ab2a | 13879 | + |
4a4d8108 AM |
13880 | + err = 0; /* -EBADF; */ /* posix? */ |
13881 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
13882 | + goto out; | |
1308ab2a | 13883 | + |
b912730e AM |
13884 | + file = kio->ki_filp; |
13885 | + inode = file_inode(file); | |
13886 | + au_mtx_and_read_lock(inode); | |
13887 | + | |
13888 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); | |
13889 | + err = PTR_ERR(h_file); | |
13890 | + if (IS_ERR(h_file)) | |
4a4d8108 | 13891 | + goto out_unlock; |
1308ab2a | 13892 | + |
4a4d8108 AM |
13893 | + err = -ENOSYS; |
13894 | + h_file = au_hf_top(file); | |
523b37e3 | 13895 | + if (h_file->f_op->aio_fsync) { |
4a4d8108 | 13896 | + struct mutex *h_mtx; |
1308ab2a | 13897 | + |
c06a8ce3 | 13898 | + h_mtx = &file_inode(h_file)->i_mutex; |
4a4d8108 AM |
13899 | + if (!is_sync_kiocb(kio)) { |
13900 | + get_file(h_file); | |
13901 | + fput(file); | |
13902 | + } | |
13903 | + kio->ki_filp = h_file; | |
13904 | + err = h_file->f_op->aio_fsync(kio, datasync); | |
13905 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
13906 | + if (!err) | |
13907 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); | |
13908 | + /*ignore*/ | |
4a4d8108 AM |
13909 | + mutex_unlock(h_mtx); |
13910 | + } | |
b912730e | 13911 | + au_write_post(inode, h_file, &wpre, /*written*/0); |
1308ab2a | 13912 | + |
4f0767ce | 13913 | +out_unlock: |
e49829fe | 13914 | + si_read_unlock(inode->sb); |
4a4d8108 | 13915 | + mutex_unlock(&inode->i_mutex); |
b912730e | 13916 | +out: |
4a4d8108 | 13917 | + return err; |
dece6358 | 13918 | +} |
4a4d8108 | 13919 | +#endif |
dece6358 | 13920 | + |
4a4d8108 | 13921 | +static int aufs_fasync(int fd, struct file *file, int flag) |
dece6358 | 13922 | +{ |
4a4d8108 AM |
13923 | + int err; |
13924 | + struct file *h_file; | |
4a4d8108 | 13925 | + struct super_block *sb; |
1308ab2a | 13926 | + |
b912730e | 13927 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 13928 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e AM |
13929 | + |
13930 | + h_file = au_read_pre(file, /*keep_fi*/0); | |
13931 | + err = PTR_ERR(h_file); | |
13932 | + if (IS_ERR(h_file)) | |
4a4d8108 AM |
13933 | + goto out; |
13934 | + | |
523b37e3 | 13935 | + if (h_file->f_op->fasync) |
4a4d8108 | 13936 | + err = h_file->f_op->fasync(fd, h_file, flag); |
b912730e | 13937 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 13938 | + |
4f0767ce | 13939 | +out: |
4a4d8108 | 13940 | + si_read_unlock(sb); |
1308ab2a | 13941 | + return err; |
dece6358 | 13942 | +} |
4a4d8108 AM |
13943 | + |
13944 | +/* ---------------------------------------------------------------------- */ | |
13945 | + | |
13946 | +/* no one supports this operation, currently */ | |
13947 | +#if 0 | |
13948 | +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset, | |
2000de60 | 13949 | + size_t len, loff_t *pos, int more) |
4a4d8108 AM |
13950 | +{ |
13951 | +} | |
13952 | +#endif | |
13953 | + | |
13954 | +/* ---------------------------------------------------------------------- */ | |
13955 | + | |
13956 | +const struct file_operations aufs_file_fop = { | |
13957 | + .owner = THIS_MODULE, | |
2cbb1c4b | 13958 | + |
027c5e7a | 13959 | + .llseek = default_llseek, |
4a4d8108 AM |
13960 | + |
13961 | + .read = aufs_read, | |
13962 | + .write = aufs_write, | |
076b876e AM |
13963 | + .read_iter = aufs_read_iter, |
13964 | + .write_iter = aufs_write_iter, | |
13965 | + | |
4a4d8108 AM |
13966 | +#ifdef CONFIG_AUFS_POLL |
13967 | + .poll = aufs_poll, | |
13968 | +#endif | |
13969 | + .unlocked_ioctl = aufs_ioctl_nondir, | |
b752ccd1 | 13970 | +#ifdef CONFIG_COMPAT |
c2b27bf2 | 13971 | + .compat_ioctl = aufs_compat_ioctl_nondir, |
b752ccd1 | 13972 | +#endif |
4a4d8108 AM |
13973 | + .mmap = aufs_mmap, |
13974 | + .open = aufs_open_nondir, | |
13975 | + .flush = aufs_flush_nondir, | |
13976 | + .release = aufs_release_nondir, | |
13977 | + .fsync = aufs_fsync_nondir, | |
13978 | + /* .aio_fsync = aufs_aio_fsync_nondir, */ | |
13979 | + .fasync = aufs_fasync, | |
13980 | + /* .sendpage = aufs_sendpage, */ | |
13981 | + .splice_write = aufs_splice_write, | |
13982 | + .splice_read = aufs_splice_read, | |
13983 | +#if 0 | |
13984 | + .aio_splice_write = aufs_aio_splice_write, | |
38d290e6 | 13985 | + .aio_splice_read = aufs_aio_splice_read, |
4a4d8108 | 13986 | +#endif |
38d290e6 | 13987 | + .fallocate = aufs_fallocate |
4a4d8108 | 13988 | +}; |
7f207e10 AM |
13989 | diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h |
13990 | --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 13991 | +++ linux/fs/aufs/fstype.h 2015-09-24 10:47:58.254719746 +0200 |
b912730e | 13992 | @@ -0,0 +1,400 @@ |
4a4d8108 | 13993 | +/* |
2000de60 | 13994 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
13995 | + * |
13996 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13997 | + * it under the terms of the GNU General Public License as published by | |
13998 | + * the Free Software Foundation; either version 2 of the License, or | |
13999 | + * (at your option) any later version. | |
14000 | + * | |
14001 | + * This program is distributed in the hope that it will be useful, | |
14002 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14003 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14004 | + * GNU General Public License for more details. | |
14005 | + * | |
14006 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14007 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
14008 | + */ |
14009 | + | |
14010 | +/* | |
14011 | + * judging filesystem type | |
14012 | + */ | |
14013 | + | |
14014 | +#ifndef __AUFS_FSTYPE_H__ | |
14015 | +#define __AUFS_FSTYPE_H__ | |
14016 | + | |
14017 | +#ifdef __KERNEL__ | |
14018 | + | |
14019 | +#include <linux/fs.h> | |
14020 | +#include <linux/magic.h> | |
14021 | +#include <linux/romfs_fs.h> | |
b912730e | 14022 | +#include <linux/nfs_fs.h> |
4a4d8108 AM |
14023 | + |
14024 | +static inline int au_test_aufs(struct super_block *sb) | |
14025 | +{ | |
14026 | + return sb->s_magic == AUFS_SUPER_MAGIC; | |
14027 | +} | |
14028 | + | |
14029 | +static inline const char *au_sbtype(struct super_block *sb) | |
14030 | +{ | |
14031 | + return sb->s_type->name; | |
14032 | +} | |
1308ab2a | 14033 | + |
14034 | +static inline int au_test_iso9660(struct super_block *sb __maybe_unused) | |
14035 | +{ | |
2000de60 JR |
14036 | +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE) |
14037 | + return sb->s_magic == ISOFS_SUPER_MAGIC; | |
dece6358 AM |
14038 | +#else |
14039 | + return 0; | |
14040 | +#endif | |
14041 | +} | |
14042 | + | |
1308ab2a | 14043 | +static inline int au_test_romfs(struct super_block *sb __maybe_unused) |
dece6358 | 14044 | +{ |
2000de60 JR |
14045 | +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE) |
14046 | + return sb->s_magic == ROMFS_MAGIC; | |
dece6358 AM |
14047 | +#else |
14048 | + return 0; | |
14049 | +#endif | |
14050 | +} | |
14051 | + | |
1308ab2a | 14052 | +static inline int au_test_cramfs(struct super_block *sb __maybe_unused) |
dece6358 | 14053 | +{ |
1308ab2a | 14054 | +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE) |
14055 | + return sb->s_magic == CRAMFS_MAGIC; | |
14056 | +#endif | |
14057 | + return 0; | |
14058 | +} | |
14059 | + | |
14060 | +static inline int au_test_nfs(struct super_block *sb __maybe_unused) | |
14061 | +{ | |
14062 | +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE) | |
14063 | + return sb->s_magic == NFS_SUPER_MAGIC; | |
dece6358 AM |
14064 | +#else |
14065 | + return 0; | |
14066 | +#endif | |
14067 | +} | |
14068 | + | |
1308ab2a | 14069 | +static inline int au_test_fuse(struct super_block *sb __maybe_unused) |
dece6358 | 14070 | +{ |
1308ab2a | 14071 | +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE) |
14072 | + return sb->s_magic == FUSE_SUPER_MAGIC; | |
dece6358 AM |
14073 | +#else |
14074 | + return 0; | |
14075 | +#endif | |
14076 | +} | |
14077 | + | |
1308ab2a | 14078 | +static inline int au_test_xfs(struct super_block *sb __maybe_unused) |
dece6358 | 14079 | +{ |
1308ab2a | 14080 | +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE) |
14081 | + return sb->s_magic == XFS_SB_MAGIC; | |
dece6358 AM |
14082 | +#else |
14083 | + return 0; | |
14084 | +#endif | |
14085 | +} | |
14086 | + | |
1308ab2a | 14087 | +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused) |
dece6358 | 14088 | +{ |
1308ab2a | 14089 | +#ifdef CONFIG_TMPFS |
14090 | + return sb->s_magic == TMPFS_MAGIC; | |
14091 | +#else | |
14092 | + return 0; | |
dece6358 | 14093 | +#endif |
dece6358 AM |
14094 | +} |
14095 | + | |
1308ab2a | 14096 | +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused) |
1facf9fc | 14097 | +{ |
1308ab2a | 14098 | +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE) |
14099 | + return !strcmp(au_sbtype(sb), "ecryptfs"); | |
14100 | +#else | |
14101 | + return 0; | |
14102 | +#endif | |
1facf9fc | 14103 | +} |
14104 | + | |
1308ab2a | 14105 | +static inline int au_test_ramfs(struct super_block *sb) |
14106 | +{ | |
14107 | + return sb->s_magic == RAMFS_MAGIC; | |
14108 | +} | |
14109 | + | |
14110 | +static inline int au_test_ubifs(struct super_block *sb __maybe_unused) | |
14111 | +{ | |
14112 | +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE) | |
14113 | + return sb->s_magic == UBIFS_SUPER_MAGIC; | |
14114 | +#else | |
14115 | + return 0; | |
14116 | +#endif | |
14117 | +} | |
14118 | + | |
14119 | +static inline int au_test_procfs(struct super_block *sb __maybe_unused) | |
14120 | +{ | |
14121 | +#ifdef CONFIG_PROC_FS | |
14122 | + return sb->s_magic == PROC_SUPER_MAGIC; | |
14123 | +#else | |
14124 | + return 0; | |
14125 | +#endif | |
14126 | +} | |
14127 | + | |
14128 | +static inline int au_test_sysfs(struct super_block *sb __maybe_unused) | |
14129 | +{ | |
14130 | +#ifdef CONFIG_SYSFS | |
14131 | + return sb->s_magic == SYSFS_MAGIC; | |
14132 | +#else | |
14133 | + return 0; | |
14134 | +#endif | |
14135 | +} | |
14136 | + | |
14137 | +static inline int au_test_configfs(struct super_block *sb __maybe_unused) | |
14138 | +{ | |
14139 | +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE) | |
14140 | + return sb->s_magic == CONFIGFS_MAGIC; | |
14141 | +#else | |
14142 | + return 0; | |
14143 | +#endif | |
14144 | +} | |
14145 | + | |
14146 | +static inline int au_test_minix(struct super_block *sb __maybe_unused) | |
14147 | +{ | |
14148 | +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE) | |
14149 | + return sb->s_magic == MINIX3_SUPER_MAGIC | |
14150 | + || sb->s_magic == MINIX2_SUPER_MAGIC | |
14151 | + || sb->s_magic == MINIX2_SUPER_MAGIC2 | |
14152 | + || sb->s_magic == MINIX_SUPER_MAGIC | |
14153 | + || sb->s_magic == MINIX_SUPER_MAGIC2; | |
14154 | +#else | |
14155 | + return 0; | |
14156 | +#endif | |
14157 | +} | |
14158 | + | |
1308ab2a | 14159 | +static inline int au_test_fat(struct super_block *sb __maybe_unused) |
14160 | +{ | |
14161 | +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE) | |
14162 | + return sb->s_magic == MSDOS_SUPER_MAGIC; | |
14163 | +#else | |
14164 | + return 0; | |
14165 | +#endif | |
14166 | +} | |
14167 | + | |
14168 | +static inline int au_test_msdos(struct super_block *sb) | |
14169 | +{ | |
14170 | + return au_test_fat(sb); | |
14171 | +} | |
14172 | + | |
14173 | +static inline int au_test_vfat(struct super_block *sb) | |
14174 | +{ | |
14175 | + return au_test_fat(sb); | |
14176 | +} | |
14177 | + | |
14178 | +static inline int au_test_securityfs(struct super_block *sb __maybe_unused) | |
14179 | +{ | |
14180 | +#ifdef CONFIG_SECURITYFS | |
14181 | + return sb->s_magic == SECURITYFS_MAGIC; | |
14182 | +#else | |
14183 | + return 0; | |
14184 | +#endif | |
14185 | +} | |
14186 | + | |
14187 | +static inline int au_test_squashfs(struct super_block *sb __maybe_unused) | |
14188 | +{ | |
14189 | +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE) | |
14190 | + return sb->s_magic == SQUASHFS_MAGIC; | |
14191 | +#else | |
14192 | + return 0; | |
14193 | +#endif | |
14194 | +} | |
14195 | + | |
14196 | +static inline int au_test_btrfs(struct super_block *sb __maybe_unused) | |
14197 | +{ | |
14198 | +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE) | |
14199 | + return sb->s_magic == BTRFS_SUPER_MAGIC; | |
14200 | +#else | |
14201 | + return 0; | |
14202 | +#endif | |
14203 | +} | |
14204 | + | |
14205 | +static inline int au_test_xenfs(struct super_block *sb __maybe_unused) | |
14206 | +{ | |
14207 | +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE) | |
14208 | + return sb->s_magic == XENFS_SUPER_MAGIC; | |
14209 | +#else | |
14210 | + return 0; | |
14211 | +#endif | |
14212 | +} | |
14213 | + | |
14214 | +static inline int au_test_debugfs(struct super_block *sb __maybe_unused) | |
14215 | +{ | |
14216 | +#ifdef CONFIG_DEBUG_FS | |
14217 | + return sb->s_magic == DEBUGFS_MAGIC; | |
14218 | +#else | |
14219 | + return 0; | |
14220 | +#endif | |
14221 | +} | |
14222 | + | |
14223 | +static inline int au_test_nilfs(struct super_block *sb __maybe_unused) | |
14224 | +{ | |
14225 | +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE) | |
14226 | + return sb->s_magic == NILFS_SUPER_MAGIC; | |
14227 | +#else | |
14228 | + return 0; | |
14229 | +#endif | |
14230 | +} | |
14231 | + | |
4a4d8108 AM |
14232 | +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused) |
14233 | +{ | |
14234 | +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE) | |
14235 | + return sb->s_magic == HFSPLUS_SUPER_MAGIC; | |
14236 | +#else | |
14237 | + return 0; | |
14238 | +#endif | |
14239 | +} | |
14240 | + | |
1308ab2a | 14241 | +/* ---------------------------------------------------------------------- */ |
14242 | +/* | |
14243 | + * they can't be an aufs branch. | |
14244 | + */ | |
14245 | +static inline int au_test_fs_unsuppoted(struct super_block *sb) | |
14246 | +{ | |
14247 | + return | |
14248 | +#ifndef CONFIG_AUFS_BR_RAMFS | |
14249 | + au_test_ramfs(sb) || | |
14250 | +#endif | |
14251 | + au_test_procfs(sb) | |
14252 | + || au_test_sysfs(sb) | |
14253 | + || au_test_configfs(sb) | |
14254 | + || au_test_debugfs(sb) | |
14255 | + || au_test_securityfs(sb) | |
14256 | + || au_test_xenfs(sb) | |
14257 | + || au_test_ecryptfs(sb) | |
14258 | + /* || !strcmp(au_sbtype(sb), "unionfs") */ | |
14259 | + || au_test_aufs(sb); /* will be supported in next version */ | |
14260 | +} | |
14261 | + | |
1308ab2a | 14262 | +static inline int au_test_fs_remote(struct super_block *sb) |
14263 | +{ | |
14264 | + return !au_test_tmpfs(sb) | |
14265 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14266 | + && !au_test_ramfs(sb) | |
14267 | +#endif | |
14268 | + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV); | |
14269 | +} | |
14270 | + | |
14271 | +/* ---------------------------------------------------------------------- */ | |
14272 | + | |
14273 | +/* | |
14274 | + * Note: these functions (below) are created after reading ->getattr() in all | |
14275 | + * filesystems under linux/fs. it means we have to do so in every update... | |
14276 | + */ | |
14277 | + | |
14278 | +/* | |
14279 | + * some filesystems require getattr to refresh the inode attributes before | |
14280 | + * referencing. | |
14281 | + * in most cases, we can rely on the inode attribute in NFS (or every remote fs) | |
14282 | + * and leave the work for d_revalidate() | |
14283 | + */ | |
14284 | +static inline int au_test_fs_refresh_iattr(struct super_block *sb) | |
14285 | +{ | |
14286 | + return au_test_nfs(sb) | |
14287 | + || au_test_fuse(sb) | |
1308ab2a | 14288 | + /* || au_test_btrfs(sb) */ /* untested */ |
1308ab2a | 14289 | + ; |
14290 | +} | |
14291 | + | |
14292 | +/* | |
14293 | + * filesystems which don't maintain i_size or i_blocks. | |
14294 | + */ | |
14295 | +static inline int au_test_fs_bad_iattr_size(struct super_block *sb) | |
14296 | +{ | |
14297 | + return au_test_xfs(sb) | |
4a4d8108 AM |
14298 | + || au_test_btrfs(sb) |
14299 | + || au_test_ubifs(sb) | |
14300 | + || au_test_hfsplus(sb) /* maintained, but incorrect */ | |
1308ab2a | 14301 | + /* || au_test_minix(sb) */ /* untested */ |
14302 | + ; | |
14303 | +} | |
14304 | + | |
14305 | +/* | |
14306 | + * filesystems which don't store the correct value in some of their inode | |
14307 | + * attributes. | |
14308 | + */ | |
14309 | +static inline int au_test_fs_bad_iattr(struct super_block *sb) | |
14310 | +{ | |
14311 | + return au_test_fs_bad_iattr_size(sb) | |
1308ab2a | 14312 | + || au_test_fat(sb) |
14313 | + || au_test_msdos(sb) | |
14314 | + || au_test_vfat(sb); | |
1facf9fc | 14315 | +} |
14316 | + | |
14317 | +/* they don't check i_nlink in link(2) */ | |
14318 | +static inline int au_test_fs_no_limit_nlink(struct super_block *sb) | |
14319 | +{ | |
14320 | + return au_test_tmpfs(sb) | |
14321 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14322 | + || au_test_ramfs(sb) | |
14323 | +#endif | |
4a4d8108 | 14324 | + || au_test_ubifs(sb) |
4a4d8108 | 14325 | + || au_test_hfsplus(sb); |
1facf9fc | 14326 | +} |
14327 | + | |
14328 | +/* | |
14329 | + * filesystems which sets S_NOATIME and S_NOCMTIME. | |
14330 | + */ | |
14331 | +static inline int au_test_fs_notime(struct super_block *sb) | |
14332 | +{ | |
14333 | + return au_test_nfs(sb) | |
14334 | + || au_test_fuse(sb) | |
dece6358 | 14335 | + || au_test_ubifs(sb) |
1facf9fc | 14336 | + ; |
14337 | +} | |
14338 | + | |
1facf9fc | 14339 | +/* temporary support for i#1 in cramfs */ |
14340 | +static inline int au_test_fs_unique_ino(struct inode *inode) | |
14341 | +{ | |
14342 | + if (au_test_cramfs(inode->i_sb)) | |
14343 | + return inode->i_ino != 1; | |
14344 | + return 1; | |
14345 | +} | |
14346 | + | |
14347 | +/* ---------------------------------------------------------------------- */ | |
14348 | + | |
14349 | +/* | |
14350 | + * the filesystem where the xino files placed must support i/o after unlink and | |
14351 | + * maintain i_size and i_blocks. | |
14352 | + */ | |
14353 | +static inline int au_test_fs_bad_xino(struct super_block *sb) | |
14354 | +{ | |
14355 | + return au_test_fs_remote(sb) | |
14356 | + || au_test_fs_bad_iattr_size(sb) | |
1facf9fc | 14357 | + /* don't want unnecessary work for xino */ |
14358 | + || au_test_aufs(sb) | |
1308ab2a | 14359 | + || au_test_ecryptfs(sb) |
14360 | + || au_test_nilfs(sb); | |
1facf9fc | 14361 | +} |
14362 | + | |
14363 | +static inline int au_test_fs_trunc_xino(struct super_block *sb) | |
14364 | +{ | |
14365 | + return au_test_tmpfs(sb) | |
14366 | + || au_test_ramfs(sb); | |
14367 | +} | |
14368 | + | |
14369 | +/* | |
14370 | + * test if the @sb is real-readonly. | |
14371 | + */ | |
14372 | +static inline int au_test_fs_rr(struct super_block *sb) | |
14373 | +{ | |
14374 | + return au_test_squashfs(sb) | |
14375 | + || au_test_iso9660(sb) | |
14376 | + || au_test_cramfs(sb) | |
14377 | + || au_test_romfs(sb); | |
14378 | +} | |
14379 | + | |
b912730e AM |
14380 | +/* |
14381 | + * test if the @inode is nfs with 'noacl' option | |
14382 | + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.' | |
14383 | + */ | |
14384 | +static inline int au_test_nfs_noacl(struct inode *inode) | |
14385 | +{ | |
14386 | + return au_test_nfs(inode->i_sb) | |
14387 | + /* && IS_POSIXACL(inode) */ | |
14388 | + && !nfs_server_capable(inode, NFS_CAP_ACLS); | |
14389 | +} | |
14390 | + | |
1facf9fc | 14391 | +#endif /* __KERNEL__ */ |
14392 | +#endif /* __AUFS_FSTYPE_H__ */ | |
7f207e10 AM |
14393 | diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c |
14394 | --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 14395 | +++ linux/fs/aufs/hfsnotify.c 2015-09-24 10:47:58.254719746 +0200 |
c1595e42 | 14396 | @@ -0,0 +1,288 @@ |
1facf9fc | 14397 | +/* |
2000de60 | 14398 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 14399 | + * |
14400 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14401 | + * it under the terms of the GNU General Public License as published by | |
14402 | + * the Free Software Foundation; either version 2 of the License, or | |
14403 | + * (at your option) any later version. | |
dece6358 AM |
14404 | + * |
14405 | + * This program is distributed in the hope that it will be useful, | |
14406 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14407 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14408 | + * GNU General Public License for more details. | |
14409 | + * | |
14410 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14411 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 14412 | + */ |
14413 | + | |
14414 | +/* | |
4a4d8108 | 14415 | + * fsnotify for the lower directories |
1facf9fc | 14416 | + */ |
14417 | + | |
14418 | +#include "aufs.h" | |
14419 | + | |
4a4d8108 AM |
14420 | +/* FS_IN_IGNORED is unnecessary */ |
14421 | +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE | |
14422 | + | FS_CREATE | FS_EVENT_ON_CHILD); | |
7f207e10 | 14423 | +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq); |
7eafdf33 | 14424 | +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0); |
1facf9fc | 14425 | + |
0c5527e5 | 14426 | +static void au_hfsn_free_mark(struct fsnotify_mark *mark) |
1facf9fc | 14427 | +{ |
0c5527e5 AM |
14428 | + struct au_hnotify *hn = container_of(mark, struct au_hnotify, |
14429 | + hn_mark); | |
4a4d8108 | 14430 | + AuDbg("here\n"); |
7eafdf33 | 14431 | + au_cache_free_hnotify(hn); |
076b876e | 14432 | + smp_mb__before_atomic(); |
1716fcea AM |
14433 | + if (atomic64_dec_and_test(&au_hfsn_ifree)) |
14434 | + wake_up(&au_hfsn_wq); | |
4a4d8108 | 14435 | +} |
1facf9fc | 14436 | + |
027c5e7a | 14437 | +static int au_hfsn_alloc(struct au_hinode *hinode) |
4a4d8108 | 14438 | +{ |
1716fcea | 14439 | + int err; |
027c5e7a AM |
14440 | + struct au_hnotify *hn; |
14441 | + struct super_block *sb; | |
14442 | + struct au_branch *br; | |
0c5527e5 | 14443 | + struct fsnotify_mark *mark; |
027c5e7a | 14444 | + aufs_bindex_t bindex; |
1facf9fc | 14445 | + |
027c5e7a AM |
14446 | + hn = hinode->hi_notify; |
14447 | + sb = hn->hn_aufs_inode->i_sb; | |
14448 | + bindex = au_br_index(sb, hinode->hi_id); | |
14449 | + br = au_sbr(sb, bindex); | |
1716fcea AM |
14450 | + AuDebugOn(!br->br_hfsn); |
14451 | + | |
0c5527e5 AM |
14452 | + mark = &hn->hn_mark; |
14453 | + fsnotify_init_mark(mark, au_hfsn_free_mark); | |
14454 | + mark->mask = AuHfsnMask; | |
7f207e10 AM |
14455 | + /* |
14456 | + * by udba rename or rmdir, aufs assign a new inode to the known | |
14457 | + * h_inode, so specify 1 to allow dups. | |
14458 | + */ | |
c1595e42 | 14459 | + lockdep_off(); |
1716fcea | 14460 | + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode, |
027c5e7a | 14461 | + /*mnt*/NULL, /*allow_dups*/1); |
1716fcea AM |
14462 | + /* even if err */ |
14463 | + fsnotify_put_mark(mark); | |
c1595e42 | 14464 | + lockdep_on(); |
1716fcea AM |
14465 | + |
14466 | + return err; | |
1facf9fc | 14467 | +} |
14468 | + | |
7eafdf33 | 14469 | +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn) |
1facf9fc | 14470 | +{ |
0c5527e5 | 14471 | + struct fsnotify_mark *mark; |
7eafdf33 | 14472 | + unsigned long long ull; |
1716fcea | 14473 | + struct fsnotify_group *group; |
7eafdf33 AM |
14474 | + |
14475 | + ull = atomic64_inc_return(&au_hfsn_ifree); | |
14476 | + BUG_ON(!ull); | |
953406b4 | 14477 | + |
0c5527e5 | 14478 | + mark = &hn->hn_mark; |
1716fcea AM |
14479 | + spin_lock(&mark->lock); |
14480 | + group = mark->group; | |
14481 | + fsnotify_get_group(group); | |
14482 | + spin_unlock(&mark->lock); | |
c1595e42 | 14483 | + lockdep_off(); |
1716fcea AM |
14484 | + fsnotify_destroy_mark(mark, group); |
14485 | + fsnotify_put_group(group); | |
c1595e42 | 14486 | + lockdep_on(); |
7f207e10 | 14487 | + |
7eafdf33 AM |
14488 | + /* free hn by myself */ |
14489 | + return 0; | |
1facf9fc | 14490 | +} |
14491 | + | |
14492 | +/* ---------------------------------------------------------------------- */ | |
14493 | + | |
4a4d8108 | 14494 | +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set) |
1facf9fc | 14495 | +{ |
0c5527e5 | 14496 | + struct fsnotify_mark *mark; |
1facf9fc | 14497 | + |
0c5527e5 AM |
14498 | + mark = &hinode->hi_notify->hn_mark; |
14499 | + spin_lock(&mark->lock); | |
1facf9fc | 14500 | + if (do_set) { |
0c5527e5 AM |
14501 | + AuDebugOn(mark->mask & AuHfsnMask); |
14502 | + mark->mask |= AuHfsnMask; | |
1facf9fc | 14503 | + } else { |
0c5527e5 AM |
14504 | + AuDebugOn(!(mark->mask & AuHfsnMask)); |
14505 | + mark->mask &= ~AuHfsnMask; | |
1facf9fc | 14506 | + } |
0c5527e5 | 14507 | + spin_unlock(&mark->lock); |
4a4d8108 | 14508 | + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */ |
1facf9fc | 14509 | +} |
14510 | + | |
4a4d8108 | 14511 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 14512 | + |
4a4d8108 AM |
14513 | +/* #define AuDbgHnotify */ |
14514 | +#ifdef AuDbgHnotify | |
14515 | +static char *au_hfsn_name(u32 mask) | |
14516 | +{ | |
14517 | +#ifdef CONFIG_AUFS_DEBUG | |
c06a8ce3 AM |
14518 | +#define test_ret(flag) \ |
14519 | + do { \ | |
14520 | + if (mask & flag) \ | |
14521 | + return #flag; \ | |
14522 | + } while (0) | |
4a4d8108 AM |
14523 | + test_ret(FS_ACCESS); |
14524 | + test_ret(FS_MODIFY); | |
14525 | + test_ret(FS_ATTRIB); | |
14526 | + test_ret(FS_CLOSE_WRITE); | |
14527 | + test_ret(FS_CLOSE_NOWRITE); | |
14528 | + test_ret(FS_OPEN); | |
14529 | + test_ret(FS_MOVED_FROM); | |
14530 | + test_ret(FS_MOVED_TO); | |
14531 | + test_ret(FS_CREATE); | |
14532 | + test_ret(FS_DELETE); | |
14533 | + test_ret(FS_DELETE_SELF); | |
14534 | + test_ret(FS_MOVE_SELF); | |
14535 | + test_ret(FS_UNMOUNT); | |
14536 | + test_ret(FS_Q_OVERFLOW); | |
14537 | + test_ret(FS_IN_IGNORED); | |
b912730e | 14538 | + test_ret(FS_ISDIR); |
4a4d8108 AM |
14539 | + test_ret(FS_IN_ONESHOT); |
14540 | + test_ret(FS_EVENT_ON_CHILD); | |
14541 | + return ""; | |
14542 | +#undef test_ret | |
14543 | +#else | |
14544 | + return "??"; | |
14545 | +#endif | |
1facf9fc | 14546 | +} |
4a4d8108 | 14547 | +#endif |
1facf9fc | 14548 | + |
14549 | +/* ---------------------------------------------------------------------- */ | |
14550 | + | |
1716fcea AM |
14551 | +static void au_hfsn_free_group(struct fsnotify_group *group) |
14552 | +{ | |
14553 | + struct au_br_hfsnotify *hfsn = group->private; | |
14554 | + | |
14555 | + AuDbg("here\n"); | |
14556 | + kfree(hfsn); | |
14557 | +} | |
14558 | + | |
4a4d8108 | 14559 | +static int au_hfsn_handle_event(struct fsnotify_group *group, |
fb47a38f | 14560 | + struct inode *inode, |
0c5527e5 AM |
14561 | + struct fsnotify_mark *inode_mark, |
14562 | + struct fsnotify_mark *vfsmount_mark, | |
fb47a38f JR |
14563 | + u32 mask, void *data, int data_type, |
14564 | + const unsigned char *file_name, u32 cookie) | |
1facf9fc | 14565 | +{ |
14566 | + int err; | |
4a4d8108 AM |
14567 | + struct au_hnotify *hnotify; |
14568 | + struct inode *h_dir, *h_inode; | |
fb47a38f | 14569 | + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name)); |
4a4d8108 | 14570 | + |
fb47a38f | 14571 | + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE); |
1facf9fc | 14572 | + |
14573 | + err = 0; | |
0c5527e5 | 14574 | + /* if FS_UNMOUNT happens, there must be another bug */ |
4a4d8108 | 14575 | + AuDebugOn(mask & FS_UNMOUNT); |
0c5527e5 | 14576 | + if (mask & (FS_IN_IGNORED | FS_UNMOUNT)) |
1facf9fc | 14577 | + goto out; |
1facf9fc | 14578 | + |
fb47a38f JR |
14579 | + h_dir = inode; |
14580 | + h_inode = NULL; | |
4a4d8108 | 14581 | +#ifdef AuDbgHnotify |
392086de | 14582 | + au_debug_on(); |
4a4d8108 AM |
14583 | + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1 |
14584 | + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) { | |
14585 | + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n", | |
14586 | + h_dir->i_ino, mask, au_hfsn_name(mask), | |
14587 | + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0); | |
14588 | + /* WARN_ON(1); */ | |
1facf9fc | 14589 | + } |
392086de | 14590 | + au_debug_off(); |
1facf9fc | 14591 | +#endif |
4a4d8108 | 14592 | + |
0c5527e5 AM |
14593 | + AuDebugOn(!inode_mark); |
14594 | + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark); | |
14595 | + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode); | |
1facf9fc | 14596 | + |
4a4d8108 AM |
14597 | +out: |
14598 | + return err; | |
14599 | +} | |
1facf9fc | 14600 | + |
4a4d8108 | 14601 | +static struct fsnotify_ops au_hfsn_ops = { |
1716fcea AM |
14602 | + .handle_event = au_hfsn_handle_event, |
14603 | + .free_group_priv = au_hfsn_free_group | |
4a4d8108 AM |
14604 | +}; |
14605 | + | |
14606 | +/* ---------------------------------------------------------------------- */ | |
14607 | + | |
027c5e7a AM |
14608 | +static void au_hfsn_fin_br(struct au_branch *br) |
14609 | +{ | |
1716fcea | 14610 | + struct au_br_hfsnotify *hfsn; |
027c5e7a | 14611 | + |
1716fcea | 14612 | + hfsn = br->br_hfsn; |
c1595e42 JR |
14613 | + if (hfsn) { |
14614 | + lockdep_off(); | |
1716fcea | 14615 | + fsnotify_put_group(hfsn->hfsn_group); |
c1595e42 JR |
14616 | + lockdep_on(); |
14617 | + } | |
027c5e7a AM |
14618 | +} |
14619 | + | |
1716fcea | 14620 | +static int au_hfsn_init_br(struct au_branch *br, int perm) |
4a4d8108 AM |
14621 | +{ |
14622 | + int err; | |
1716fcea AM |
14623 | + struct fsnotify_group *group; |
14624 | + struct au_br_hfsnotify *hfsn; | |
1facf9fc | 14625 | + |
4a4d8108 | 14626 | + err = 0; |
1716fcea AM |
14627 | + br->br_hfsn = NULL; |
14628 | + if (!au_br_hnotifyable(perm)) | |
027c5e7a | 14629 | + goto out; |
027c5e7a | 14630 | + |
1716fcea AM |
14631 | + err = -ENOMEM; |
14632 | + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS); | |
14633 | + if (unlikely(!hfsn)) | |
027c5e7a AM |
14634 | + goto out; |
14635 | + | |
1716fcea AM |
14636 | + err = 0; |
14637 | + group = fsnotify_alloc_group(&au_hfsn_ops); | |
14638 | + if (IS_ERR(group)) { | |
14639 | + err = PTR_ERR(group); | |
0c5527e5 | 14640 | + pr_err("fsnotify_alloc_group() failed, %d\n", err); |
1716fcea | 14641 | + goto out_hfsn; |
4a4d8108 | 14642 | + } |
1facf9fc | 14643 | + |
1716fcea AM |
14644 | + group->private = hfsn; |
14645 | + hfsn->hfsn_group = group; | |
14646 | + br->br_hfsn = hfsn; | |
14647 | + goto out; /* success */ | |
14648 | + | |
14649 | +out_hfsn: | |
14650 | + kfree(hfsn); | |
027c5e7a | 14651 | +out: |
1716fcea AM |
14652 | + return err; |
14653 | +} | |
14654 | + | |
14655 | +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
14656 | +{ | |
14657 | + int err; | |
14658 | + | |
14659 | + err = 0; | |
14660 | + if (!br->br_hfsn) | |
14661 | + err = au_hfsn_init_br(br, perm); | |
14662 | + | |
1facf9fc | 14663 | + return err; |
14664 | +} | |
14665 | + | |
7eafdf33 AM |
14666 | +/* ---------------------------------------------------------------------- */ |
14667 | + | |
14668 | +static void au_hfsn_fin(void) | |
14669 | +{ | |
14670 | + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree)); | |
14671 | + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree)); | |
14672 | +} | |
14673 | + | |
4a4d8108 AM |
14674 | +const struct au_hnotify_op au_hnotify_op = { |
14675 | + .ctl = au_hfsn_ctl, | |
14676 | + .alloc = au_hfsn_alloc, | |
14677 | + .free = au_hfsn_free, | |
1facf9fc | 14678 | + |
7eafdf33 AM |
14679 | + .fin = au_hfsn_fin, |
14680 | + | |
027c5e7a AM |
14681 | + .reset_br = au_hfsn_reset_br, |
14682 | + .fin_br = au_hfsn_fin_br, | |
14683 | + .init_br = au_hfsn_init_br | |
4a4d8108 | 14684 | +}; |
7f207e10 AM |
14685 | diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c |
14686 | --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 14687 | +++ linux/fs/aufs/hfsplus.c 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 14688 | @@ -0,0 +1,56 @@ |
4a4d8108 | 14689 | +/* |
2000de60 | 14690 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
4a4d8108 AM |
14691 | + * |
14692 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14693 | + * it under the terms of the GNU General Public License as published by | |
14694 | + * the Free Software Foundation; either version 2 of the License, or | |
14695 | + * (at your option) any later version. | |
14696 | + * | |
14697 | + * This program is distributed in the hope that it will be useful, | |
14698 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14699 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14700 | + * GNU General Public License for more details. | |
14701 | + * | |
14702 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14703 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 14704 | + */ |
1facf9fc | 14705 | + |
4a4d8108 AM |
14706 | +/* |
14707 | + * special support for filesystems which aqucires an inode mutex | |
14708 | + * at final closing a file, eg, hfsplus. | |
14709 | + * | |
14710 | + * This trick is very simple and stupid, just to open the file before really | |
14711 | + * neceeary open to tell hfsplus that this is not the final closing. | |
14712 | + * The caller should call au_h_open_pre() after acquiring the inode mutex, | |
14713 | + * and au_h_open_post() after releasing it. | |
14714 | + */ | |
1facf9fc | 14715 | + |
4a4d8108 | 14716 | +#include "aufs.h" |
1facf9fc | 14717 | + |
392086de AM |
14718 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
14719 | + int force_wr) | |
4a4d8108 AM |
14720 | +{ |
14721 | + struct file *h_file; | |
14722 | + struct dentry *h_dentry; | |
1facf9fc | 14723 | + |
4a4d8108 AM |
14724 | + h_dentry = au_h_dptr(dentry, bindex); |
14725 | + AuDebugOn(!h_dentry); | |
5527c038 | 14726 | + AuDebugOn(d_is_negative(h_dentry)); |
4a4d8108 AM |
14727 | + |
14728 | + h_file = NULL; | |
14729 | + if (au_test_hfsplus(h_dentry->d_sb) | |
7e9cd9fe | 14730 | + && d_is_reg(h_dentry)) |
4a4d8108 AM |
14731 | + h_file = au_h_open(dentry, bindex, |
14732 | + O_RDONLY | O_NOATIME | O_LARGEFILE, | |
392086de | 14733 | + /*file*/NULL, force_wr); |
4a4d8108 | 14734 | + return h_file; |
1facf9fc | 14735 | +} |
14736 | + | |
4a4d8108 AM |
14737 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
14738 | + struct file *h_file) | |
14739 | +{ | |
14740 | + if (h_file) { | |
14741 | + fput(h_file); | |
14742 | + au_sbr_put(dentry->d_sb, bindex); | |
14743 | + } | |
14744 | +} | |
7f207e10 AM |
14745 | diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c |
14746 | --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 14747 | +++ linux/fs/aufs/hnotify.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 14748 | @@ -0,0 +1,710 @@ |
e49829fe | 14749 | +/* |
2000de60 | 14750 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
e49829fe JR |
14751 | + * |
14752 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14753 | + * it under the terms of the GNU General Public License as published by | |
14754 | + * the Free Software Foundation; either version 2 of the License, or | |
14755 | + * (at your option) any later version. | |
14756 | + * | |
14757 | + * This program is distributed in the hope that it will be useful, | |
14758 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14759 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14760 | + * GNU General Public License for more details. | |
14761 | + * | |
14762 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14763 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
14764 | + */ |
14765 | + | |
14766 | +/* | |
7f207e10 | 14767 | + * abstraction to notify the direct changes on lower directories |
e49829fe JR |
14768 | + */ |
14769 | + | |
14770 | +#include "aufs.h" | |
14771 | + | |
027c5e7a | 14772 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode) |
e49829fe JR |
14773 | +{ |
14774 | + int err; | |
7f207e10 | 14775 | + struct au_hnotify *hn; |
1facf9fc | 14776 | + |
4a4d8108 AM |
14777 | + err = -ENOMEM; |
14778 | + hn = au_cache_alloc_hnotify(); | |
14779 | + if (hn) { | |
14780 | + hn->hn_aufs_inode = inode; | |
027c5e7a AM |
14781 | + hinode->hi_notify = hn; |
14782 | + err = au_hnotify_op.alloc(hinode); | |
14783 | + AuTraceErr(err); | |
14784 | + if (unlikely(err)) { | |
14785 | + hinode->hi_notify = NULL; | |
4a4d8108 AM |
14786 | + au_cache_free_hnotify(hn); |
14787 | + /* | |
14788 | + * The upper dir was removed by udba, but the same named | |
14789 | + * dir left. In this case, aufs assignes a new inode | |
14790 | + * number and set the monitor again. | |
14791 | + * For the lower dir, the old monitnor is still left. | |
14792 | + */ | |
14793 | + if (err == -EEXIST) | |
14794 | + err = 0; | |
14795 | + } | |
1308ab2a | 14796 | + } |
1308ab2a | 14797 | + |
027c5e7a | 14798 | + AuTraceErr(err); |
1308ab2a | 14799 | + return err; |
dece6358 | 14800 | +} |
1facf9fc | 14801 | + |
4a4d8108 | 14802 | +void au_hn_free(struct au_hinode *hinode) |
dece6358 | 14803 | +{ |
4a4d8108 | 14804 | + struct au_hnotify *hn; |
1facf9fc | 14805 | + |
4a4d8108 AM |
14806 | + hn = hinode->hi_notify; |
14807 | + if (hn) { | |
4a4d8108 | 14808 | + hinode->hi_notify = NULL; |
7eafdf33 AM |
14809 | + if (au_hnotify_op.free(hinode, hn)) |
14810 | + au_cache_free_hnotify(hn); | |
4a4d8108 AM |
14811 | + } |
14812 | +} | |
dece6358 | 14813 | + |
4a4d8108 | 14814 | +/* ---------------------------------------------------------------------- */ |
dece6358 | 14815 | + |
4a4d8108 AM |
14816 | +void au_hn_ctl(struct au_hinode *hinode, int do_set) |
14817 | +{ | |
14818 | + if (hinode->hi_notify) | |
14819 | + au_hnotify_op.ctl(hinode, do_set); | |
14820 | +} | |
14821 | + | |
14822 | +void au_hn_reset(struct inode *inode, unsigned int flags) | |
14823 | +{ | |
14824 | + aufs_bindex_t bindex, bend; | |
14825 | + struct inode *hi; | |
14826 | + struct dentry *iwhdentry; | |
1facf9fc | 14827 | + |
1308ab2a | 14828 | + bend = au_ibend(inode); |
4a4d8108 AM |
14829 | + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) { |
14830 | + hi = au_h_iptr(inode, bindex); | |
14831 | + if (!hi) | |
14832 | + continue; | |
1308ab2a | 14833 | + |
4a4d8108 AM |
14834 | + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */ |
14835 | + iwhdentry = au_hi_wh(inode, bindex); | |
14836 | + if (iwhdentry) | |
14837 | + dget(iwhdentry); | |
14838 | + au_igrab(hi); | |
14839 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
14840 | + au_set_h_iptr(inode, bindex, au_igrab(hi), | |
14841 | + flags & ~AuHi_XINO); | |
14842 | + iput(hi); | |
14843 | + dput(iwhdentry); | |
14844 | + /* mutex_unlock(&hi->i_mutex); */ | |
1facf9fc | 14845 | + } |
1facf9fc | 14846 | +} |
14847 | + | |
1308ab2a | 14848 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 14849 | + |
4a4d8108 | 14850 | +static int hn_xino(struct inode *inode, struct inode *h_inode) |
1facf9fc | 14851 | +{ |
4a4d8108 AM |
14852 | + int err; |
14853 | + aufs_bindex_t bindex, bend, bfound, bstart; | |
14854 | + struct inode *h_i; | |
1facf9fc | 14855 | + |
4a4d8108 AM |
14856 | + err = 0; |
14857 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 14858 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
14859 | + goto out; |
14860 | + } | |
1facf9fc | 14861 | + |
4a4d8108 AM |
14862 | + bfound = -1; |
14863 | + bend = au_ibend(inode); | |
14864 | + bstart = au_ibstart(inode); | |
14865 | +#if 0 /* reserved for future use */ | |
14866 | + if (bindex == bend) { | |
14867 | + /* keep this ino in rename case */ | |
14868 | + goto out; | |
14869 | + } | |
14870 | +#endif | |
14871 | + for (bindex = bstart; bindex <= bend; bindex++) | |
14872 | + if (au_h_iptr(inode, bindex) == h_inode) { | |
14873 | + bfound = bindex; | |
14874 | + break; | |
14875 | + } | |
14876 | + if (bfound < 0) | |
1308ab2a | 14877 | + goto out; |
1facf9fc | 14878 | + |
4a4d8108 AM |
14879 | + for (bindex = bstart; bindex <= bend; bindex++) { |
14880 | + h_i = au_h_iptr(inode, bindex); | |
14881 | + if (!h_i) | |
14882 | + continue; | |
1facf9fc | 14883 | + |
4a4d8108 AM |
14884 | + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0); |
14885 | + /* ignore this error */ | |
14886 | + /* bad action? */ | |
1facf9fc | 14887 | + } |
1facf9fc | 14888 | + |
4a4d8108 | 14889 | + /* children inode number will be broken */ |
1facf9fc | 14890 | + |
4f0767ce | 14891 | +out: |
4a4d8108 AM |
14892 | + AuTraceErr(err); |
14893 | + return err; | |
1facf9fc | 14894 | +} |
14895 | + | |
4a4d8108 | 14896 | +static int hn_gen_tree(struct dentry *dentry) |
1facf9fc | 14897 | +{ |
4a4d8108 AM |
14898 | + int err, i, j, ndentry; |
14899 | + struct au_dcsub_pages dpages; | |
14900 | + struct au_dpage *dpage; | |
14901 | + struct dentry **dentries; | |
1facf9fc | 14902 | + |
4a4d8108 AM |
14903 | + err = au_dpages_init(&dpages, GFP_NOFS); |
14904 | + if (unlikely(err)) | |
14905 | + goto out; | |
14906 | + err = au_dcsub_pages(&dpages, dentry, NULL, NULL); | |
14907 | + if (unlikely(err)) | |
14908 | + goto out_dpages; | |
1facf9fc | 14909 | + |
4a4d8108 AM |
14910 | + for (i = 0; i < dpages.ndpage; i++) { |
14911 | + dpage = dpages.dpages + i; | |
14912 | + dentries = dpage->dentries; | |
14913 | + ndentry = dpage->ndentry; | |
14914 | + for (j = 0; j < ndentry; j++) { | |
14915 | + struct dentry *d; | |
14916 | + | |
14917 | + d = dentries[j]; | |
14918 | + if (IS_ROOT(d)) | |
14919 | + continue; | |
14920 | + | |
4a4d8108 | 14921 | + au_digen_dec(d); |
5527c038 | 14922 | + if (d_really_is_positive(d)) |
4a4d8108 AM |
14923 | + /* todo: reset children xino? |
14924 | + cached children only? */ | |
5527c038 | 14925 | + au_iigen_dec(d_inode(d)); |
1308ab2a | 14926 | + } |
dece6358 | 14927 | + } |
1facf9fc | 14928 | + |
4f0767ce | 14929 | +out_dpages: |
4a4d8108 | 14930 | + au_dpages_free(&dpages); |
dece6358 | 14931 | + |
027c5e7a | 14932 | +#if 0 |
4a4d8108 AM |
14933 | + /* discard children */ |
14934 | + dentry_unhash(dentry); | |
14935 | + dput(dentry); | |
027c5e7a | 14936 | +#endif |
4f0767ce | 14937 | +out: |
dece6358 AM |
14938 | + return err; |
14939 | +} | |
14940 | + | |
1308ab2a | 14941 | +/* |
4a4d8108 | 14942 | + * return 0 if processed. |
1308ab2a | 14943 | + */ |
4a4d8108 AM |
14944 | +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode, |
14945 | + const unsigned int isdir) | |
dece6358 | 14946 | +{ |
1308ab2a | 14947 | + int err; |
4a4d8108 AM |
14948 | + struct dentry *d; |
14949 | + struct qstr *dname; | |
1facf9fc | 14950 | + |
4a4d8108 AM |
14951 | + err = 1; |
14952 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 14953 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
14954 | + err = 0; |
14955 | + goto out; | |
14956 | + } | |
dece6358 | 14957 | + |
4a4d8108 AM |
14958 | + if (!isdir) { |
14959 | + AuDebugOn(!name); | |
14960 | + au_iigen_dec(inode); | |
027c5e7a | 14961 | + spin_lock(&inode->i_lock); |
c1595e42 | 14962 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 14963 | + spin_lock(&d->d_lock); |
4a4d8108 AM |
14964 | + dname = &d->d_name; |
14965 | + if (dname->len != nlen | |
027c5e7a AM |
14966 | + && memcmp(dname->name, name, nlen)) { |
14967 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 14968 | + continue; |
027c5e7a | 14969 | + } |
4a4d8108 | 14970 | + err = 0; |
4a4d8108 AM |
14971 | + au_digen_dec(d); |
14972 | + spin_unlock(&d->d_lock); | |
14973 | + break; | |
1facf9fc | 14974 | + } |
027c5e7a | 14975 | + spin_unlock(&inode->i_lock); |
1308ab2a | 14976 | + } else { |
027c5e7a | 14977 | + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR); |
c1595e42 | 14978 | + d = d_find_any_alias(inode); |
4a4d8108 AM |
14979 | + if (!d) { |
14980 | + au_iigen_dec(inode); | |
14981 | + goto out; | |
14982 | + } | |
1facf9fc | 14983 | + |
027c5e7a | 14984 | + spin_lock(&d->d_lock); |
4a4d8108 | 14985 | + dname = &d->d_name; |
027c5e7a AM |
14986 | + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) { |
14987 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 14988 | + err = hn_gen_tree(d); |
027c5e7a AM |
14989 | + spin_lock(&d->d_lock); |
14990 | + } | |
14991 | + spin_unlock(&d->d_lock); | |
4a4d8108 AM |
14992 | + dput(d); |
14993 | + } | |
1facf9fc | 14994 | + |
4f0767ce | 14995 | +out: |
4a4d8108 | 14996 | + AuTraceErr(err); |
1308ab2a | 14997 | + return err; |
14998 | +} | |
dece6358 | 14999 | + |
4a4d8108 | 15000 | +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir) |
1facf9fc | 15001 | +{ |
4a4d8108 | 15002 | + int err; |
1facf9fc | 15003 | + |
5527c038 | 15004 | + if (IS_ROOT(dentry)) { |
0c3ec466 | 15005 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
15006 | + return 0; |
15007 | + } | |
1308ab2a | 15008 | + |
4a4d8108 AM |
15009 | + err = 0; |
15010 | + if (!isdir) { | |
4a4d8108 | 15011 | + au_digen_dec(dentry); |
5527c038 JR |
15012 | + if (d_really_is_positive(dentry)) |
15013 | + au_iigen_dec(d_inode(dentry)); | |
4a4d8108 | 15014 | + } else { |
027c5e7a | 15015 | + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR); |
5527c038 | 15016 | + if (d_really_is_positive(dentry)) |
4a4d8108 AM |
15017 | + err = hn_gen_tree(dentry); |
15018 | + } | |
15019 | + | |
15020 | + AuTraceErr(err); | |
15021 | + return err; | |
1facf9fc | 15022 | +} |
15023 | + | |
4a4d8108 | 15024 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15025 | + |
4a4d8108 AM |
15026 | +/* hnotify job flags */ |
15027 | +#define AuHnJob_XINO0 1 | |
15028 | +#define AuHnJob_GEN (1 << 1) | |
15029 | +#define AuHnJob_DIRENT (1 << 2) | |
15030 | +#define AuHnJob_ISDIR (1 << 3) | |
15031 | +#define AuHnJob_TRYXINO0 (1 << 4) | |
15032 | +#define AuHnJob_MNTPNT (1 << 5) | |
15033 | +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name) | |
7f207e10 AM |
15034 | +#define au_fset_hnjob(flags, name) \ |
15035 | + do { (flags) |= AuHnJob_##name; } while (0) | |
15036 | +#define au_fclr_hnjob(flags, name) \ | |
15037 | + do { (flags) &= ~AuHnJob_##name; } while (0) | |
1facf9fc | 15038 | + |
4a4d8108 AM |
15039 | +enum { |
15040 | + AuHn_CHILD, | |
15041 | + AuHn_PARENT, | |
15042 | + AuHnLast | |
15043 | +}; | |
1facf9fc | 15044 | + |
4a4d8108 AM |
15045 | +struct au_hnotify_args { |
15046 | + struct inode *h_dir, *dir, *h_child_inode; | |
15047 | + u32 mask; | |
15048 | + unsigned int flags[AuHnLast]; | |
15049 | + unsigned int h_child_nlen; | |
15050 | + char h_child_name[]; | |
15051 | +}; | |
1facf9fc | 15052 | + |
4a4d8108 AM |
15053 | +struct hn_job_args { |
15054 | + unsigned int flags; | |
15055 | + struct inode *inode, *h_inode, *dir, *h_dir; | |
15056 | + struct dentry *dentry; | |
15057 | + char *h_name; | |
15058 | + int h_nlen; | |
15059 | +}; | |
1308ab2a | 15060 | + |
4a4d8108 AM |
15061 | +static int hn_job(struct hn_job_args *a) |
15062 | +{ | |
15063 | + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR); | |
076b876e | 15064 | + int e; |
1308ab2a | 15065 | + |
4a4d8108 AM |
15066 | + /* reset xino */ |
15067 | + if (au_ftest_hnjob(a->flags, XINO0) && a->inode) | |
15068 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ | |
1308ab2a | 15069 | + |
4a4d8108 AM |
15070 | + if (au_ftest_hnjob(a->flags, TRYXINO0) |
15071 | + && a->inode | |
15072 | + && a->h_inode) { | |
15073 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
38d290e6 JR |
15074 | + if (!a->h_inode->i_nlink |
15075 | + && !(a->h_inode->i_state & I_LINKABLE)) | |
4a4d8108 AM |
15076 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ |
15077 | + mutex_unlock(&a->h_inode->i_mutex); | |
1308ab2a | 15078 | + } |
1facf9fc | 15079 | + |
4a4d8108 AM |
15080 | + /* make the generation obsolete */ |
15081 | + if (au_ftest_hnjob(a->flags, GEN)) { | |
076b876e | 15082 | + e = -1; |
4a4d8108 | 15083 | + if (a->inode) |
076b876e | 15084 | + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode, |
4a4d8108 | 15085 | + isdir); |
076b876e | 15086 | + if (e && a->dentry) |
4a4d8108 AM |
15087 | + hn_gen_by_name(a->dentry, isdir); |
15088 | + /* ignore this error */ | |
1facf9fc | 15089 | + } |
1facf9fc | 15090 | + |
4a4d8108 AM |
15091 | + /* make dir entries obsolete */ |
15092 | + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) { | |
15093 | + struct au_vdir *vdir; | |
1facf9fc | 15094 | + |
4a4d8108 AM |
15095 | + vdir = au_ivdir(a->inode); |
15096 | + if (vdir) | |
15097 | + vdir->vd_jiffy = 0; | |
15098 | + /* IMustLock(a->inode); */ | |
15099 | + /* a->inode->i_version++; */ | |
15100 | + } | |
1facf9fc | 15101 | + |
4a4d8108 AM |
15102 | + /* can do nothing but warn */ |
15103 | + if (au_ftest_hnjob(a->flags, MNTPNT) | |
15104 | + && a->dentry | |
15105 | + && d_mountpoint(a->dentry)) | |
523b37e3 | 15106 | + pr_warn("mount-point %pd is removed or renamed\n", a->dentry); |
1facf9fc | 15107 | + |
4a4d8108 | 15108 | + return 0; |
1308ab2a | 15109 | +} |
1facf9fc | 15110 | + |
1308ab2a | 15111 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15112 | + |
4a4d8108 AM |
15113 | +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen, |
15114 | + struct inode *dir) | |
1308ab2a | 15115 | +{ |
4a4d8108 AM |
15116 | + struct dentry *dentry, *d, *parent; |
15117 | + struct qstr *dname; | |
1308ab2a | 15118 | + |
c1595e42 | 15119 | + parent = d_find_any_alias(dir); |
4a4d8108 AM |
15120 | + if (!parent) |
15121 | + return NULL; | |
1308ab2a | 15122 | + |
4a4d8108 | 15123 | + dentry = NULL; |
027c5e7a | 15124 | + spin_lock(&parent->d_lock); |
c1595e42 | 15125 | + list_for_each_entry(d, &parent->d_subdirs, d_child) { |
523b37e3 | 15126 | + /* AuDbg("%pd\n", d); */ |
027c5e7a | 15127 | + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED); |
4a4d8108 AM |
15128 | + dname = &d->d_name; |
15129 | + if (dname->len != nlen || memcmp(dname->name, name, nlen)) | |
027c5e7a AM |
15130 | + goto cont_unlock; |
15131 | + if (au_di(d)) | |
15132 | + au_digen_dec(d); | |
15133 | + else | |
15134 | + goto cont_unlock; | |
c1595e42 | 15135 | + if (au_dcount(d) > 0) { |
027c5e7a | 15136 | + dentry = dget_dlock(d); |
4a4d8108 | 15137 | + spin_unlock(&d->d_lock); |
027c5e7a | 15138 | + break; |
dece6358 | 15139 | + } |
1facf9fc | 15140 | + |
f6b6e03d | 15141 | +cont_unlock: |
027c5e7a | 15142 | + spin_unlock(&d->d_lock); |
1308ab2a | 15143 | + } |
027c5e7a | 15144 | + spin_unlock(&parent->d_lock); |
4a4d8108 | 15145 | + dput(parent); |
1facf9fc | 15146 | + |
4a4d8108 AM |
15147 | + if (dentry) |
15148 | + di_write_lock_child(dentry); | |
1308ab2a | 15149 | + |
4a4d8108 AM |
15150 | + return dentry; |
15151 | +} | |
dece6358 | 15152 | + |
4a4d8108 AM |
15153 | +static struct inode *lookup_wlock_by_ino(struct super_block *sb, |
15154 | + aufs_bindex_t bindex, ino_t h_ino) | |
15155 | +{ | |
15156 | + struct inode *inode; | |
15157 | + ino_t ino; | |
15158 | + int err; | |
15159 | + | |
15160 | + inode = NULL; | |
15161 | + err = au_xino_read(sb, bindex, h_ino, &ino); | |
15162 | + if (!err && ino) | |
15163 | + inode = ilookup(sb, ino); | |
15164 | + if (!inode) | |
15165 | + goto out; | |
15166 | + | |
15167 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 15168 | + pr_warn("wrong root branch\n"); |
4a4d8108 AM |
15169 | + iput(inode); |
15170 | + inode = NULL; | |
15171 | + goto out; | |
1308ab2a | 15172 | + } |
15173 | + | |
4a4d8108 | 15174 | + ii_write_lock_child(inode); |
1308ab2a | 15175 | + |
4f0767ce | 15176 | +out: |
4a4d8108 | 15177 | + return inode; |
dece6358 AM |
15178 | +} |
15179 | + | |
4a4d8108 | 15180 | +static void au_hn_bh(void *_args) |
1facf9fc | 15181 | +{ |
4a4d8108 AM |
15182 | + struct au_hnotify_args *a = _args; |
15183 | + struct super_block *sb; | |
15184 | + aufs_bindex_t bindex, bend, bfound; | |
15185 | + unsigned char xino, try_iput; | |
1facf9fc | 15186 | + int err; |
1308ab2a | 15187 | + struct inode *inode; |
4a4d8108 AM |
15188 | + ino_t h_ino; |
15189 | + struct hn_job_args args; | |
15190 | + struct dentry *dentry; | |
15191 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 15192 | + |
4a4d8108 AM |
15193 | + AuDebugOn(!_args); |
15194 | + AuDebugOn(!a->h_dir); | |
15195 | + AuDebugOn(!a->dir); | |
15196 | + AuDebugOn(!a->mask); | |
15197 | + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n", | |
15198 | + a->mask, a->dir->i_ino, a->h_dir->i_ino, | |
15199 | + a->h_child_inode ? a->h_child_inode->i_ino : 0); | |
1facf9fc | 15200 | + |
4a4d8108 AM |
15201 | + inode = NULL; |
15202 | + dentry = NULL; | |
15203 | + /* | |
15204 | + * do not lock a->dir->i_mutex here | |
15205 | + * because of d_revalidate() may cause a deadlock. | |
15206 | + */ | |
15207 | + sb = a->dir->i_sb; | |
15208 | + AuDebugOn(!sb); | |
15209 | + sbinfo = au_sbi(sb); | |
15210 | + AuDebugOn(!sbinfo); | |
7f207e10 | 15211 | + si_write_lock(sb, AuLock_NOPLMW); |
1facf9fc | 15212 | + |
4a4d8108 AM |
15213 | + ii_read_lock_parent(a->dir); |
15214 | + bfound = -1; | |
15215 | + bend = au_ibend(a->dir); | |
15216 | + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++) | |
15217 | + if (au_h_iptr(a->dir, bindex) == a->h_dir) { | |
15218 | + bfound = bindex; | |
15219 | + break; | |
15220 | + } | |
15221 | + ii_read_unlock(a->dir); | |
15222 | + if (unlikely(bfound < 0)) | |
15223 | + goto out; | |
1facf9fc | 15224 | + |
4a4d8108 AM |
15225 | + xino = !!au_opt_test(au_mntflags(sb), XINO); |
15226 | + h_ino = 0; | |
15227 | + if (a->h_child_inode) | |
15228 | + h_ino = a->h_child_inode->i_ino; | |
1facf9fc | 15229 | + |
4a4d8108 AM |
15230 | + if (a->h_child_nlen |
15231 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN) | |
15232 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT))) | |
15233 | + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen, | |
15234 | + a->dir); | |
15235 | + try_iput = 0; | |
5527c038 JR |
15236 | + if (dentry && d_really_is_positive(dentry)) |
15237 | + inode = d_inode(dentry); | |
4a4d8108 AM |
15238 | + if (xino && !inode && h_ino |
15239 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0) | |
15240 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0) | |
15241 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) { | |
15242 | + inode = lookup_wlock_by_ino(sb, bfound, h_ino); | |
15243 | + try_iput = 1; | |
15244 | + } | |
1facf9fc | 15245 | + |
4a4d8108 AM |
15246 | + args.flags = a->flags[AuHn_CHILD]; |
15247 | + args.dentry = dentry; | |
15248 | + args.inode = inode; | |
15249 | + args.h_inode = a->h_child_inode; | |
15250 | + args.dir = a->dir; | |
15251 | + args.h_dir = a->h_dir; | |
15252 | + args.h_name = a->h_child_name; | |
15253 | + args.h_nlen = a->h_child_nlen; | |
15254 | + err = hn_job(&args); | |
15255 | + if (dentry) { | |
027c5e7a | 15256 | + if (au_di(dentry)) |
4a4d8108 AM |
15257 | + di_write_unlock(dentry); |
15258 | + dput(dentry); | |
15259 | + } | |
15260 | + if (inode && try_iput) { | |
15261 | + ii_write_unlock(inode); | |
15262 | + iput(inode); | |
15263 | + } | |
1facf9fc | 15264 | + |
4a4d8108 AM |
15265 | + ii_write_lock_parent(a->dir); |
15266 | + args.flags = a->flags[AuHn_PARENT]; | |
15267 | + args.dentry = NULL; | |
15268 | + args.inode = a->dir; | |
15269 | + args.h_inode = a->h_dir; | |
15270 | + args.dir = NULL; | |
15271 | + args.h_dir = NULL; | |
15272 | + args.h_name = NULL; | |
15273 | + args.h_nlen = 0; | |
15274 | + err = hn_job(&args); | |
15275 | + ii_write_unlock(a->dir); | |
1facf9fc | 15276 | + |
4f0767ce | 15277 | +out: |
4a4d8108 AM |
15278 | + iput(a->h_child_inode); |
15279 | + iput(a->h_dir); | |
15280 | + iput(a->dir); | |
027c5e7a AM |
15281 | + si_write_unlock(sb); |
15282 | + au_nwt_done(&sbinfo->si_nowait); | |
1308ab2a | 15283 | + kfree(a); |
dece6358 | 15284 | +} |
1facf9fc | 15285 | + |
4a4d8108 AM |
15286 | +/* ---------------------------------------------------------------------- */ |
15287 | + | |
15288 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
15289 | + struct qstr *h_child_qstr, struct inode *h_child_inode) | |
dece6358 | 15290 | +{ |
4a4d8108 | 15291 | + int err, len; |
53392da6 | 15292 | + unsigned int flags[AuHnLast], f; |
4a4d8108 AM |
15293 | + unsigned char isdir, isroot, wh; |
15294 | + struct inode *dir; | |
15295 | + struct au_hnotify_args *args; | |
15296 | + char *p, *h_child_name; | |
dece6358 | 15297 | + |
1308ab2a | 15298 | + err = 0; |
4a4d8108 AM |
15299 | + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode); |
15300 | + dir = igrab(hnotify->hn_aufs_inode); | |
15301 | + if (!dir) | |
15302 | + goto out; | |
1facf9fc | 15303 | + |
4a4d8108 AM |
15304 | + isroot = (dir->i_ino == AUFS_ROOT_INO); |
15305 | + wh = 0; | |
15306 | + h_child_name = (void *)h_child_qstr->name; | |
15307 | + len = h_child_qstr->len; | |
15308 | + if (h_child_name) { | |
15309 | + if (len > AUFS_WH_PFX_LEN | |
15310 | + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
15311 | + h_child_name += AUFS_WH_PFX_LEN; | |
15312 | + len -= AUFS_WH_PFX_LEN; | |
15313 | + wh = 1; | |
15314 | + } | |
1facf9fc | 15315 | + } |
dece6358 | 15316 | + |
4a4d8108 AM |
15317 | + isdir = 0; |
15318 | + if (h_child_inode) | |
15319 | + isdir = !!S_ISDIR(h_child_inode->i_mode); | |
15320 | + flags[AuHn_PARENT] = AuHnJob_ISDIR; | |
15321 | + flags[AuHn_CHILD] = 0; | |
15322 | + if (isdir) | |
15323 | + flags[AuHn_CHILD] = AuHnJob_ISDIR; | |
15324 | + au_fset_hnjob(flags[AuHn_PARENT], DIRENT); | |
15325 | + au_fset_hnjob(flags[AuHn_CHILD], GEN); | |
15326 | + switch (mask & FS_EVENTS_POSS_ON_CHILD) { | |
15327 | + case FS_MOVED_FROM: | |
15328 | + case FS_MOVED_TO: | |
15329 | + au_fset_hnjob(flags[AuHn_CHILD], XINO0); | |
15330 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
15331 | + /*FALLTHROUGH*/ | |
15332 | + case FS_CREATE: | |
fb47a38f | 15333 | + AuDebugOn(!h_child_name); |
4a4d8108 | 15334 | + break; |
1facf9fc | 15335 | + |
4a4d8108 AM |
15336 | + case FS_DELETE: |
15337 | + /* | |
15338 | + * aufs never be able to get this child inode. | |
15339 | + * revalidation should be in d_revalidate() | |
15340 | + * by checking i_nlink, i_generation or d_unhashed(). | |
15341 | + */ | |
15342 | + AuDebugOn(!h_child_name); | |
15343 | + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0); | |
15344 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
15345 | + break; | |
dece6358 | 15346 | + |
4a4d8108 AM |
15347 | + default: |
15348 | + AuDebugOn(1); | |
15349 | + } | |
1308ab2a | 15350 | + |
4a4d8108 AM |
15351 | + if (wh) |
15352 | + h_child_inode = NULL; | |
1308ab2a | 15353 | + |
4a4d8108 AM |
15354 | + err = -ENOMEM; |
15355 | + /* iput() and kfree() will be called in au_hnotify() */ | |
4a4d8108 | 15356 | + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS); |
4a4d8108 AM |
15357 | + if (unlikely(!args)) { |
15358 | + AuErr1("no memory\n"); | |
15359 | + iput(dir); | |
15360 | + goto out; | |
15361 | + } | |
15362 | + args->flags[AuHn_PARENT] = flags[AuHn_PARENT]; | |
15363 | + args->flags[AuHn_CHILD] = flags[AuHn_CHILD]; | |
15364 | + args->mask = mask; | |
15365 | + args->dir = dir; | |
15366 | + args->h_dir = igrab(h_dir); | |
15367 | + if (h_child_inode) | |
15368 | + h_child_inode = igrab(h_child_inode); /* can be NULL */ | |
15369 | + args->h_child_inode = h_child_inode; | |
15370 | + args->h_child_nlen = len; | |
15371 | + if (len) { | |
15372 | + p = (void *)args; | |
15373 | + p += sizeof(*args); | |
15374 | + memcpy(p, h_child_name, len); | |
15375 | + p[len] = 0; | |
1308ab2a | 15376 | + } |
1308ab2a | 15377 | + |
38d290e6 | 15378 | + /* NFS fires the event for silly-renamed one from kworker */ |
53392da6 | 15379 | + f = 0; |
38d290e6 JR |
15380 | + if (!dir->i_nlink |
15381 | + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE))) | |
53392da6 AM |
15382 | + f = AuWkq_NEST; |
15383 | + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f); | |
4a4d8108 AM |
15384 | + if (unlikely(err)) { |
15385 | + pr_err("wkq %d\n", err); | |
15386 | + iput(args->h_child_inode); | |
15387 | + iput(args->h_dir); | |
15388 | + iput(args->dir); | |
15389 | + kfree(args); | |
1facf9fc | 15390 | + } |
1facf9fc | 15391 | + |
4a4d8108 | 15392 | +out: |
1facf9fc | 15393 | + return err; |
15394 | +} | |
15395 | + | |
027c5e7a AM |
15396 | +/* ---------------------------------------------------------------------- */ |
15397 | + | |
15398 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
15399 | +{ | |
15400 | + int err; | |
15401 | + | |
15402 | + AuDebugOn(!(udba & AuOptMask_UDBA)); | |
15403 | + | |
15404 | + err = 0; | |
15405 | + if (au_hnotify_op.reset_br) | |
15406 | + err = au_hnotify_op.reset_br(udba, br, perm); | |
15407 | + | |
15408 | + return err; | |
15409 | +} | |
15410 | + | |
15411 | +int au_hnotify_init_br(struct au_branch *br, int perm) | |
15412 | +{ | |
15413 | + int err; | |
15414 | + | |
15415 | + err = 0; | |
15416 | + if (au_hnotify_op.init_br) | |
15417 | + err = au_hnotify_op.init_br(br, perm); | |
15418 | + | |
15419 | + return err; | |
15420 | +} | |
15421 | + | |
15422 | +void au_hnotify_fin_br(struct au_branch *br) | |
15423 | +{ | |
15424 | + if (au_hnotify_op.fin_br) | |
15425 | + au_hnotify_op.fin_br(br); | |
15426 | +} | |
15427 | + | |
4a4d8108 AM |
15428 | +static void au_hn_destroy_cache(void) |
15429 | +{ | |
15430 | + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]); | |
15431 | + au_cachep[AuCache_HNOTIFY] = NULL; | |
15432 | +} | |
1308ab2a | 15433 | + |
4a4d8108 | 15434 | +int __init au_hnotify_init(void) |
1facf9fc | 15435 | +{ |
1308ab2a | 15436 | + int err; |
1308ab2a | 15437 | + |
4a4d8108 AM |
15438 | + err = -ENOMEM; |
15439 | + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify); | |
15440 | + if (au_cachep[AuCache_HNOTIFY]) { | |
027c5e7a AM |
15441 | + err = 0; |
15442 | + if (au_hnotify_op.init) | |
15443 | + err = au_hnotify_op.init(); | |
4a4d8108 AM |
15444 | + if (unlikely(err)) |
15445 | + au_hn_destroy_cache(); | |
1308ab2a | 15446 | + } |
1308ab2a | 15447 | + AuTraceErr(err); |
4a4d8108 | 15448 | + return err; |
1308ab2a | 15449 | +} |
15450 | + | |
4a4d8108 | 15451 | +void au_hnotify_fin(void) |
1308ab2a | 15452 | +{ |
027c5e7a AM |
15453 | + if (au_hnotify_op.fin) |
15454 | + au_hnotify_op.fin(); | |
4a4d8108 AM |
15455 | + /* cf. au_cache_fin() */ |
15456 | + if (au_cachep[AuCache_HNOTIFY]) | |
15457 | + au_hn_destroy_cache(); | |
dece6358 | 15458 | +} |
7f207e10 AM |
15459 | diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c |
15460 | --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 15461 | +++ linux/fs/aufs/iinfo.c 2015-09-24 10:47:58.254719746 +0200 |
38d290e6 | 15462 | @@ -0,0 +1,277 @@ |
dece6358 | 15463 | +/* |
2000de60 | 15464 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
dece6358 AM |
15465 | + * |
15466 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15467 | + * it under the terms of the GNU General Public License as published by | |
15468 | + * the Free Software Foundation; either version 2 of the License, or | |
15469 | + * (at your option) any later version. | |
15470 | + * | |
15471 | + * This program is distributed in the hope that it will be useful, | |
15472 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15473 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15474 | + * GNU General Public License for more details. | |
15475 | + * | |
15476 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15477 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 15478 | + */ |
1facf9fc | 15479 | + |
dece6358 | 15480 | +/* |
4a4d8108 | 15481 | + * inode private data |
dece6358 | 15482 | + */ |
1facf9fc | 15483 | + |
1308ab2a | 15484 | +#include "aufs.h" |
1facf9fc | 15485 | + |
4a4d8108 | 15486 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 15487 | +{ |
4a4d8108 | 15488 | + struct inode *h_inode; |
1facf9fc | 15489 | + |
4a4d8108 | 15490 | + IiMustAnyLock(inode); |
1facf9fc | 15491 | + |
4a4d8108 AM |
15492 | + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode; |
15493 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); | |
15494 | + return h_inode; | |
15495 | +} | |
1facf9fc | 15496 | + |
4a4d8108 AM |
15497 | +/* todo: hard/soft set? */ |
15498 | +void au_hiput(struct au_hinode *hinode) | |
15499 | +{ | |
15500 | + au_hn_free(hinode); | |
15501 | + dput(hinode->hi_whdentry); | |
15502 | + iput(hinode->hi_inode); | |
15503 | +} | |
1facf9fc | 15504 | + |
4a4d8108 AM |
15505 | +unsigned int au_hi_flags(struct inode *inode, int isdir) |
15506 | +{ | |
15507 | + unsigned int flags; | |
15508 | + const unsigned int mnt_flags = au_mntflags(inode->i_sb); | |
1facf9fc | 15509 | + |
4a4d8108 AM |
15510 | + flags = 0; |
15511 | + if (au_opt_test(mnt_flags, XINO)) | |
15512 | + au_fset_hi(flags, XINO); | |
15513 | + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY)) | |
15514 | + au_fset_hi(flags, HNOTIFY); | |
15515 | + return flags; | |
1facf9fc | 15516 | +} |
15517 | + | |
4a4d8108 AM |
15518 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
15519 | + struct inode *h_inode, unsigned int flags) | |
1308ab2a | 15520 | +{ |
4a4d8108 AM |
15521 | + struct au_hinode *hinode; |
15522 | + struct inode *hi; | |
15523 | + struct au_iinfo *iinfo = au_ii(inode); | |
1facf9fc | 15524 | + |
4a4d8108 | 15525 | + IiMustWriteLock(inode); |
dece6358 | 15526 | + |
4a4d8108 AM |
15527 | + hinode = iinfo->ii_hinode + bindex; |
15528 | + hi = hinode->hi_inode; | |
15529 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); | |
15530 | + | |
15531 | + if (hi) | |
15532 | + au_hiput(hinode); | |
15533 | + hinode->hi_inode = h_inode; | |
15534 | + if (h_inode) { | |
15535 | + int err; | |
15536 | + struct super_block *sb = inode->i_sb; | |
15537 | + struct au_branch *br; | |
15538 | + | |
027c5e7a AM |
15539 | + AuDebugOn(inode->i_mode |
15540 | + && (h_inode->i_mode & S_IFMT) | |
15541 | + != (inode->i_mode & S_IFMT)); | |
4a4d8108 AM |
15542 | + if (bindex == iinfo->ii_bstart) |
15543 | + au_cpup_igen(inode, h_inode); | |
15544 | + br = au_sbr(sb, bindex); | |
15545 | + hinode->hi_id = br->br_id; | |
15546 | + if (au_ftest_hi(flags, XINO)) { | |
15547 | + err = au_xino_write(sb, bindex, h_inode->i_ino, | |
15548 | + inode->i_ino); | |
15549 | + if (unlikely(err)) | |
15550 | + AuIOErr1("failed au_xino_write() %d\n", err); | |
15551 | + } | |
15552 | + | |
15553 | + if (au_ftest_hi(flags, HNOTIFY) | |
15554 | + && au_br_hnotifyable(br->br_perm)) { | |
027c5e7a | 15555 | + err = au_hn_alloc(hinode, inode); |
4a4d8108 AM |
15556 | + if (unlikely(err)) |
15557 | + AuIOErr1("au_hn_alloc() %d\n", err); | |
1308ab2a | 15558 | + } |
15559 | + } | |
4a4d8108 | 15560 | +} |
dece6358 | 15561 | + |
4a4d8108 AM |
15562 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, |
15563 | + struct dentry *h_wh) | |
15564 | +{ | |
15565 | + struct au_hinode *hinode; | |
dece6358 | 15566 | + |
4a4d8108 AM |
15567 | + IiMustWriteLock(inode); |
15568 | + | |
15569 | + hinode = au_ii(inode)->ii_hinode + bindex; | |
15570 | + AuDebugOn(hinode->hi_whdentry); | |
15571 | + hinode->hi_whdentry = h_wh; | |
1facf9fc | 15572 | +} |
15573 | + | |
537831f9 | 15574 | +void au_update_iigen(struct inode *inode, int half) |
1308ab2a | 15575 | +{ |
537831f9 AM |
15576 | + struct au_iinfo *iinfo; |
15577 | + struct au_iigen *iigen; | |
15578 | + unsigned int sigen; | |
15579 | + | |
15580 | + sigen = au_sigen(inode->i_sb); | |
15581 | + iinfo = au_ii(inode); | |
15582 | + iigen = &iinfo->ii_generation; | |
15583 | + spin_lock(&iinfo->ii_genspin); | |
15584 | + iigen->ig_generation = sigen; | |
15585 | + if (half) | |
15586 | + au_ig_fset(iigen->ig_flags, HALF_REFRESHED); | |
15587 | + else | |
15588 | + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED); | |
15589 | + spin_unlock(&iinfo->ii_genspin); | |
4a4d8108 | 15590 | +} |
1facf9fc | 15591 | + |
4a4d8108 AM |
15592 | +/* it may be called at remount time, too */ |
15593 | +void au_update_ibrange(struct inode *inode, int do_put_zero) | |
15594 | +{ | |
15595 | + struct au_iinfo *iinfo; | |
027c5e7a | 15596 | + aufs_bindex_t bindex, bend; |
1facf9fc | 15597 | + |
4a4d8108 | 15598 | + iinfo = au_ii(inode); |
027c5e7a | 15599 | + if (!iinfo) |
4a4d8108 | 15600 | + return; |
1facf9fc | 15601 | + |
4a4d8108 | 15602 | + IiMustWriteLock(inode); |
1facf9fc | 15603 | + |
027c5e7a | 15604 | + if (do_put_zero && iinfo->ii_bstart >= 0) { |
4a4d8108 AM |
15605 | + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; |
15606 | + bindex++) { | |
15607 | + struct inode *h_i; | |
1facf9fc | 15608 | + |
4a4d8108 | 15609 | + h_i = iinfo->ii_hinode[0 + bindex].hi_inode; |
38d290e6 JR |
15610 | + if (h_i |
15611 | + && !h_i->i_nlink | |
15612 | + && !(h_i->i_state & I_LINKABLE)) | |
027c5e7a AM |
15613 | + au_set_h_iptr(inode, bindex, NULL, 0); |
15614 | + } | |
4a4d8108 AM |
15615 | + } |
15616 | + | |
027c5e7a AM |
15617 | + iinfo->ii_bstart = -1; |
15618 | + iinfo->ii_bend = -1; | |
15619 | + bend = au_sbend(inode->i_sb); | |
15620 | + for (bindex = 0; bindex <= bend; bindex++) | |
15621 | + if (iinfo->ii_hinode[0 + bindex].hi_inode) { | |
15622 | + iinfo->ii_bstart = bindex; | |
4a4d8108 | 15623 | + break; |
027c5e7a AM |
15624 | + } |
15625 | + if (iinfo->ii_bstart >= 0) | |
15626 | + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--) | |
15627 | + if (iinfo->ii_hinode[0 + bindex].hi_inode) { | |
15628 | + iinfo->ii_bend = bindex; | |
15629 | + break; | |
15630 | + } | |
15631 | + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend); | |
1308ab2a | 15632 | +} |
1facf9fc | 15633 | + |
dece6358 | 15634 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15635 | + |
4a4d8108 | 15636 | +void au_icntnr_init_once(void *_c) |
dece6358 | 15637 | +{ |
4a4d8108 AM |
15638 | + struct au_icntnr *c = _c; |
15639 | + struct au_iinfo *iinfo = &c->iinfo; | |
e49829fe | 15640 | + static struct lock_class_key aufs_ii; |
1facf9fc | 15641 | + |
537831f9 | 15642 | + spin_lock_init(&iinfo->ii_genspin); |
4a4d8108 | 15643 | + au_rw_init(&iinfo->ii_rwsem); |
e49829fe | 15644 | + au_rw_class(&iinfo->ii_rwsem, &aufs_ii); |
4a4d8108 AM |
15645 | + inode_init_once(&c->vfs_inode); |
15646 | +} | |
1facf9fc | 15647 | + |
4a4d8108 AM |
15648 | +int au_iinfo_init(struct inode *inode) |
15649 | +{ | |
15650 | + struct au_iinfo *iinfo; | |
15651 | + struct super_block *sb; | |
15652 | + int nbr, i; | |
1facf9fc | 15653 | + |
4a4d8108 AM |
15654 | + sb = inode->i_sb; |
15655 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
15656 | + nbr = au_sbend(sb) + 1; | |
15657 | + if (unlikely(nbr <= 0)) | |
15658 | + nbr = 1; | |
15659 | + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS); | |
15660 | + if (iinfo->ii_hinode) { | |
7f207e10 | 15661 | + au_ninodes_inc(sb); |
4a4d8108 AM |
15662 | + for (i = 0; i < nbr; i++) |
15663 | + iinfo->ii_hinode[i].hi_id = -1; | |
1facf9fc | 15664 | + |
537831f9 | 15665 | + iinfo->ii_generation.ig_generation = au_sigen(sb); |
4a4d8108 AM |
15666 | + iinfo->ii_bstart = -1; |
15667 | + iinfo->ii_bend = -1; | |
15668 | + iinfo->ii_vdir = NULL; | |
15669 | + return 0; | |
1308ab2a | 15670 | + } |
4a4d8108 AM |
15671 | + return -ENOMEM; |
15672 | +} | |
1facf9fc | 15673 | + |
4a4d8108 AM |
15674 | +int au_ii_realloc(struct au_iinfo *iinfo, int nbr) |
15675 | +{ | |
15676 | + int err, sz; | |
15677 | + struct au_hinode *hip; | |
1facf9fc | 15678 | + |
4a4d8108 AM |
15679 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
15680 | + | |
15681 | + err = -ENOMEM; | |
15682 | + sz = sizeof(*hip) * (iinfo->ii_bend + 1); | |
15683 | + if (!sz) | |
15684 | + sz = sizeof(*hip); | |
15685 | + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS); | |
15686 | + if (hip) { | |
15687 | + iinfo->ii_hinode = hip; | |
15688 | + err = 0; | |
1308ab2a | 15689 | + } |
4a4d8108 | 15690 | + |
1308ab2a | 15691 | + return err; |
1facf9fc | 15692 | +} |
15693 | + | |
4a4d8108 | 15694 | +void au_iinfo_fin(struct inode *inode) |
1facf9fc | 15695 | +{ |
4a4d8108 AM |
15696 | + struct au_iinfo *iinfo; |
15697 | + struct au_hinode *hi; | |
15698 | + struct super_block *sb; | |
b752ccd1 AM |
15699 | + aufs_bindex_t bindex, bend; |
15700 | + const unsigned char unlinked = !inode->i_nlink; | |
1308ab2a | 15701 | + |
4a4d8108 AM |
15702 | + iinfo = au_ii(inode); |
15703 | + /* bad_inode case */ | |
15704 | + if (!iinfo) | |
15705 | + return; | |
1308ab2a | 15706 | + |
b752ccd1 | 15707 | + sb = inode->i_sb; |
7f207e10 | 15708 | + au_ninodes_dec(sb); |
b752ccd1 AM |
15709 | + if (si_pid_test(sb)) |
15710 | + au_xino_delete_inode(inode, unlinked); | |
15711 | + else { | |
15712 | + /* | |
15713 | + * it is safe to hide the dependency between sbinfo and | |
15714 | + * sb->s_umount. | |
15715 | + */ | |
15716 | + lockdep_off(); | |
15717 | + si_noflush_read_lock(sb); | |
15718 | + au_xino_delete_inode(inode, unlinked); | |
15719 | + si_read_unlock(sb); | |
15720 | + lockdep_on(); | |
15721 | + } | |
15722 | + | |
4a4d8108 AM |
15723 | + if (iinfo->ii_vdir) |
15724 | + au_vdir_free(iinfo->ii_vdir); | |
1308ab2a | 15725 | + |
b752ccd1 AM |
15726 | + bindex = iinfo->ii_bstart; |
15727 | + if (bindex >= 0) { | |
15728 | + hi = iinfo->ii_hinode + bindex; | |
4a4d8108 | 15729 | + bend = iinfo->ii_bend; |
b752ccd1 AM |
15730 | + while (bindex++ <= bend) { |
15731 | + if (hi->hi_inode) | |
4a4d8108 | 15732 | + au_hiput(hi); |
4a4d8108 AM |
15733 | + hi++; |
15734 | + } | |
15735 | + } | |
4a4d8108 | 15736 | + kfree(iinfo->ii_hinode); |
027c5e7a | 15737 | + iinfo->ii_hinode = NULL; |
4a4d8108 | 15738 | + AuRwDestroy(&iinfo->ii_rwsem); |
dece6358 | 15739 | +} |
7f207e10 AM |
15740 | diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c |
15741 | --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 15742 | +++ linux/fs/aufs/inode.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 15743 | @@ -0,0 +1,500 @@ |
4a4d8108 | 15744 | +/* |
2000de60 | 15745 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
15746 | + * |
15747 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15748 | + * it under the terms of the GNU General Public License as published by | |
15749 | + * the Free Software Foundation; either version 2 of the License, or | |
15750 | + * (at your option) any later version. | |
15751 | + * | |
15752 | + * This program is distributed in the hope that it will be useful, | |
15753 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15754 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15755 | + * GNU General Public License for more details. | |
15756 | + * | |
15757 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15758 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 15759 | + */ |
1facf9fc | 15760 | + |
4a4d8108 AM |
15761 | +/* |
15762 | + * inode functions | |
15763 | + */ | |
1facf9fc | 15764 | + |
4a4d8108 | 15765 | +#include "aufs.h" |
1308ab2a | 15766 | + |
4a4d8108 AM |
15767 | +struct inode *au_igrab(struct inode *inode) |
15768 | +{ | |
15769 | + if (inode) { | |
15770 | + AuDebugOn(!atomic_read(&inode->i_count)); | |
027c5e7a | 15771 | + ihold(inode); |
1facf9fc | 15772 | + } |
4a4d8108 AM |
15773 | + return inode; |
15774 | +} | |
1facf9fc | 15775 | + |
4a4d8108 AM |
15776 | +static void au_refresh_hinode_attr(struct inode *inode, int do_version) |
15777 | +{ | |
15778 | + au_cpup_attr_all(inode, /*force*/0); | |
537831f9 | 15779 | + au_update_iigen(inode, /*half*/1); |
4a4d8108 AM |
15780 | + if (do_version) |
15781 | + inode->i_version++; | |
dece6358 | 15782 | +} |
1facf9fc | 15783 | + |
027c5e7a | 15784 | +static int au_ii_refresh(struct inode *inode, int *update) |
dece6358 | 15785 | +{ |
4a4d8108 | 15786 | + int err, e; |
027c5e7a | 15787 | + umode_t type; |
4a4d8108 | 15788 | + aufs_bindex_t bindex, new_bindex; |
1308ab2a | 15789 | + struct super_block *sb; |
4a4d8108 | 15790 | + struct au_iinfo *iinfo; |
027c5e7a | 15791 | + struct au_hinode *p, *q, tmp; |
1facf9fc | 15792 | + |
4a4d8108 | 15793 | + IiMustWriteLock(inode); |
1facf9fc | 15794 | + |
027c5e7a | 15795 | + *update = 0; |
4a4d8108 | 15796 | + sb = inode->i_sb; |
027c5e7a | 15797 | + type = inode->i_mode & S_IFMT; |
4a4d8108 AM |
15798 | + iinfo = au_ii(inode); |
15799 | + err = au_ii_realloc(iinfo, au_sbend(sb) + 1); | |
15800 | + if (unlikely(err)) | |
1308ab2a | 15801 | + goto out; |
1facf9fc | 15802 | + |
027c5e7a | 15803 | + AuDebugOn(iinfo->ii_bstart < 0); |
4a4d8108 | 15804 | + p = iinfo->ii_hinode + iinfo->ii_bstart; |
4a4d8108 AM |
15805 | + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; |
15806 | + bindex++, p++) { | |
15807 | + if (!p->hi_inode) | |
15808 | + continue; | |
1facf9fc | 15809 | + |
027c5e7a | 15810 | + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT)); |
4a4d8108 AM |
15811 | + new_bindex = au_br_index(sb, p->hi_id); |
15812 | + if (new_bindex == bindex) | |
15813 | + continue; | |
1facf9fc | 15814 | + |
4a4d8108 | 15815 | + if (new_bindex < 0) { |
027c5e7a | 15816 | + *update = 1; |
4a4d8108 AM |
15817 | + au_hiput(p); |
15818 | + p->hi_inode = NULL; | |
15819 | + continue; | |
1308ab2a | 15820 | + } |
4a4d8108 AM |
15821 | + |
15822 | + if (new_bindex < iinfo->ii_bstart) | |
15823 | + iinfo->ii_bstart = new_bindex; | |
15824 | + if (iinfo->ii_bend < new_bindex) | |
15825 | + iinfo->ii_bend = new_bindex; | |
15826 | + /* swap two lower inode, and loop again */ | |
15827 | + q = iinfo->ii_hinode + new_bindex; | |
15828 | + tmp = *q; | |
15829 | + *q = *p; | |
15830 | + *p = tmp; | |
15831 | + if (tmp.hi_inode) { | |
15832 | + bindex--; | |
15833 | + p--; | |
1308ab2a | 15834 | + } |
15835 | + } | |
4a4d8108 AM |
15836 | + au_update_ibrange(inode, /*do_put_zero*/0); |
15837 | + e = au_dy_irefresh(inode); | |
15838 | + if (unlikely(e && !err)) | |
15839 | + err = e; | |
1facf9fc | 15840 | + |
4f0767ce | 15841 | +out: |
027c5e7a AM |
15842 | + AuTraceErr(err); |
15843 | + return err; | |
15844 | +} | |
15845 | + | |
15846 | +int au_refresh_hinode_self(struct inode *inode) | |
15847 | +{ | |
15848 | + int err, update; | |
15849 | + | |
15850 | + err = au_ii_refresh(inode, &update); | |
15851 | + if (!err) | |
15852 | + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode)); | |
15853 | + | |
15854 | + AuTraceErr(err); | |
4a4d8108 AM |
15855 | + return err; |
15856 | +} | |
1facf9fc | 15857 | + |
4a4d8108 AM |
15858 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry) |
15859 | +{ | |
027c5e7a | 15860 | + int err, e, update; |
4a4d8108 | 15861 | + unsigned int flags; |
027c5e7a | 15862 | + umode_t mode; |
4a4d8108 | 15863 | + aufs_bindex_t bindex, bend; |
027c5e7a | 15864 | + unsigned char isdir; |
4a4d8108 AM |
15865 | + struct au_hinode *p; |
15866 | + struct au_iinfo *iinfo; | |
1facf9fc | 15867 | + |
027c5e7a | 15868 | + err = au_ii_refresh(inode, &update); |
4a4d8108 AM |
15869 | + if (unlikely(err)) |
15870 | + goto out; | |
15871 | + | |
15872 | + update = 0; | |
15873 | + iinfo = au_ii(inode); | |
15874 | + p = iinfo->ii_hinode + iinfo->ii_bstart; | |
027c5e7a AM |
15875 | + mode = (inode->i_mode & S_IFMT); |
15876 | + isdir = S_ISDIR(mode); | |
4a4d8108 AM |
15877 | + flags = au_hi_flags(inode, isdir); |
15878 | + bend = au_dbend(dentry); | |
15879 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) { | |
5527c038 | 15880 | + struct inode *h_i, *h_inode; |
4a4d8108 AM |
15881 | + struct dentry *h_d; |
15882 | + | |
15883 | + h_d = au_h_dptr(dentry, bindex); | |
5527c038 | 15884 | + if (!h_d || d_is_negative(h_d)) |
4a4d8108 AM |
15885 | + continue; |
15886 | + | |
5527c038 JR |
15887 | + h_inode = d_inode(h_d); |
15888 | + AuDebugOn(mode != (h_inode->i_mode & S_IFMT)); | |
4a4d8108 AM |
15889 | + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) { |
15890 | + h_i = au_h_iptr(inode, bindex); | |
15891 | + if (h_i) { | |
5527c038 | 15892 | + if (h_i == h_inode) |
4a4d8108 AM |
15893 | + continue; |
15894 | + err = -EIO; | |
15895 | + break; | |
15896 | + } | |
15897 | + } | |
15898 | + if (bindex < iinfo->ii_bstart) | |
15899 | + iinfo->ii_bstart = bindex; | |
15900 | + if (iinfo->ii_bend < bindex) | |
15901 | + iinfo->ii_bend = bindex; | |
5527c038 | 15902 | + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags); |
4a4d8108 | 15903 | + update = 1; |
1308ab2a | 15904 | + } |
4a4d8108 AM |
15905 | + au_update_ibrange(inode, /*do_put_zero*/0); |
15906 | + e = au_dy_irefresh(inode); | |
15907 | + if (unlikely(e && !err)) | |
15908 | + err = e; | |
027c5e7a AM |
15909 | + if (!err) |
15910 | + au_refresh_hinode_attr(inode, update && isdir); | |
4a4d8108 | 15911 | + |
4f0767ce | 15912 | +out: |
4a4d8108 | 15913 | + AuTraceErr(err); |
1308ab2a | 15914 | + return err; |
dece6358 AM |
15915 | +} |
15916 | + | |
4a4d8108 | 15917 | +static int set_inode(struct inode *inode, struct dentry *dentry) |
dece6358 | 15918 | +{ |
4a4d8108 AM |
15919 | + int err; |
15920 | + unsigned int flags; | |
15921 | + umode_t mode; | |
15922 | + aufs_bindex_t bindex, bstart, btail; | |
15923 | + unsigned char isdir; | |
15924 | + struct dentry *h_dentry; | |
15925 | + struct inode *h_inode; | |
15926 | + struct au_iinfo *iinfo; | |
dece6358 | 15927 | + |
4a4d8108 | 15928 | + IiMustWriteLock(inode); |
dece6358 | 15929 | + |
4a4d8108 AM |
15930 | + err = 0; |
15931 | + isdir = 0; | |
15932 | + bstart = au_dbstart(dentry); | |
5527c038 JR |
15933 | + h_dentry = au_h_dptr(dentry, bstart); |
15934 | + h_inode = d_inode(h_dentry); | |
4a4d8108 AM |
15935 | + mode = h_inode->i_mode; |
15936 | + switch (mode & S_IFMT) { | |
15937 | + case S_IFREG: | |
15938 | + btail = au_dbtail(dentry); | |
15939 | + inode->i_op = &aufs_iop; | |
15940 | + inode->i_fop = &aufs_file_fop; | |
15941 | + err = au_dy_iaop(inode, bstart, h_inode); | |
15942 | + if (unlikely(err)) | |
15943 | + goto out; | |
15944 | + break; | |
15945 | + case S_IFDIR: | |
15946 | + isdir = 1; | |
15947 | + btail = au_dbtaildir(dentry); | |
15948 | + inode->i_op = &aufs_dir_iop; | |
15949 | + inode->i_fop = &aufs_dir_fop; | |
15950 | + break; | |
15951 | + case S_IFLNK: | |
15952 | + btail = au_dbtail(dentry); | |
15953 | + inode->i_op = &aufs_symlink_iop; | |
15954 | + break; | |
15955 | + case S_IFBLK: | |
15956 | + case S_IFCHR: | |
15957 | + case S_IFIFO: | |
15958 | + case S_IFSOCK: | |
15959 | + btail = au_dbtail(dentry); | |
15960 | + inode->i_op = &aufs_iop; | |
38d290e6 | 15961 | + init_special_inode(inode, mode, h_inode->i_rdev); |
4a4d8108 AM |
15962 | + break; |
15963 | + default: | |
15964 | + AuIOErr("Unknown file type 0%o\n", mode); | |
15965 | + err = -EIO; | |
1308ab2a | 15966 | + goto out; |
4a4d8108 | 15967 | + } |
dece6358 | 15968 | + |
4a4d8108 AM |
15969 | + /* do not set hnotify for whiteouted dirs (SHWH mode) */ |
15970 | + flags = au_hi_flags(inode, isdir); | |
15971 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH) | |
15972 | + && au_ftest_hi(flags, HNOTIFY) | |
15973 | + && dentry->d_name.len > AUFS_WH_PFX_LEN | |
15974 | + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) | |
15975 | + au_fclr_hi(flags, HNOTIFY); | |
15976 | + iinfo = au_ii(inode); | |
15977 | + iinfo->ii_bstart = bstart; | |
15978 | + iinfo->ii_bend = btail; | |
15979 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
15980 | + h_dentry = au_h_dptr(dentry, bindex); | |
15981 | + if (h_dentry) | |
15982 | + au_set_h_iptr(inode, bindex, | |
5527c038 | 15983 | + au_igrab(d_inode(h_dentry)), flags); |
4a4d8108 AM |
15984 | + } |
15985 | + au_cpup_attr_all(inode, /*force*/1); | |
c1595e42 JR |
15986 | + /* |
15987 | + * to force calling aufs_get_acl() every time, | |
15988 | + * do not call cache_no_acl() for aufs inode. | |
15989 | + */ | |
dece6358 | 15990 | + |
4f0767ce | 15991 | +out: |
4a4d8108 AM |
15992 | + return err; |
15993 | +} | |
dece6358 | 15994 | + |
027c5e7a AM |
15995 | +/* |
15996 | + * successful returns with iinfo write_locked | |
15997 | + * minus: errno | |
15998 | + * zero: success, matched | |
15999 | + * plus: no error, but unmatched | |
16000 | + */ | |
16001 | +static int reval_inode(struct inode *inode, struct dentry *dentry) | |
4a4d8108 AM |
16002 | +{ |
16003 | + int err; | |
537831f9 AM |
16004 | + unsigned int gen; |
16005 | + struct au_iigen iigen; | |
4a4d8108 AM |
16006 | + aufs_bindex_t bindex, bend; |
16007 | + struct inode *h_inode, *h_dinode; | |
5527c038 | 16008 | + struct dentry *h_dentry; |
dece6358 | 16009 | + |
4a4d8108 AM |
16010 | + /* |
16011 | + * before this function, if aufs got any iinfo lock, it must be only | |
16012 | + * one, the parent dir. | |
16013 | + * it can happen by UDBA and the obsoleted inode number. | |
16014 | + */ | |
16015 | + err = -EIO; | |
16016 | + if (unlikely(inode->i_ino == parent_ino(dentry))) | |
16017 | + goto out; | |
16018 | + | |
027c5e7a | 16019 | + err = 1; |
4a4d8108 | 16020 | + ii_write_lock_new_child(inode); |
5527c038 JR |
16021 | + h_dentry = au_h_dptr(dentry, au_dbstart(dentry)); |
16022 | + h_dinode = d_inode(h_dentry); | |
4a4d8108 AM |
16023 | + bend = au_ibend(inode); |
16024 | + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) { | |
16025 | + h_inode = au_h_iptr(inode, bindex); | |
537831f9 AM |
16026 | + if (!h_inode || h_inode != h_dinode) |
16027 | + continue; | |
16028 | + | |
16029 | + err = 0; | |
16030 | + gen = au_iigen(inode, &iigen); | |
16031 | + if (gen == au_digen(dentry) | |
16032 | + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED)) | |
4a4d8108 | 16033 | + break; |
537831f9 AM |
16034 | + |
16035 | + /* fully refresh inode using dentry */ | |
16036 | + err = au_refresh_hinode(inode, dentry); | |
16037 | + if (!err) | |
16038 | + au_update_iigen(inode, /*half*/0); | |
16039 | + break; | |
1facf9fc | 16040 | + } |
dece6358 | 16041 | + |
4a4d8108 AM |
16042 | + if (unlikely(err)) |
16043 | + ii_write_unlock(inode); | |
4f0767ce | 16044 | +out: |
1facf9fc | 16045 | + return err; |
16046 | +} | |
1facf9fc | 16047 | + |
4a4d8108 AM |
16048 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
16049 | + unsigned int d_type, ino_t *ino) | |
1facf9fc | 16050 | +{ |
4a4d8108 AM |
16051 | + int err; |
16052 | + struct mutex *mtx; | |
1facf9fc | 16053 | + |
b752ccd1 | 16054 | + /* prevent hardlinked inode number from race condition */ |
4a4d8108 | 16055 | + mtx = NULL; |
b752ccd1 | 16056 | + if (d_type != DT_DIR) { |
4a4d8108 AM |
16057 | + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx; |
16058 | + mutex_lock(mtx); | |
16059 | + } | |
16060 | + err = au_xino_read(sb, bindex, h_ino, ino); | |
16061 | + if (unlikely(err)) | |
16062 | + goto out; | |
1308ab2a | 16063 | + |
4a4d8108 AM |
16064 | + if (!*ino) { |
16065 | + err = -EIO; | |
16066 | + *ino = au_xino_new_ino(sb); | |
16067 | + if (unlikely(!*ino)) | |
1facf9fc | 16068 | + goto out; |
4a4d8108 AM |
16069 | + err = au_xino_write(sb, bindex, h_ino, *ino); |
16070 | + if (unlikely(err)) | |
1308ab2a | 16071 | + goto out; |
1308ab2a | 16072 | + } |
1facf9fc | 16073 | + |
4f0767ce | 16074 | +out: |
b752ccd1 | 16075 | + if (mtx) |
4a4d8108 | 16076 | + mutex_unlock(mtx); |
1facf9fc | 16077 | + return err; |
16078 | +} | |
16079 | + | |
4a4d8108 AM |
16080 | +/* successful returns with iinfo write_locked */ |
16081 | +/* todo: return with unlocked? */ | |
16082 | +struct inode *au_new_inode(struct dentry *dentry, int must_new) | |
1facf9fc | 16083 | +{ |
5527c038 | 16084 | + struct inode *inode, *h_inode; |
4a4d8108 AM |
16085 | + struct dentry *h_dentry; |
16086 | + struct super_block *sb; | |
b752ccd1 | 16087 | + struct mutex *mtx; |
4a4d8108 | 16088 | + ino_t h_ino, ino; |
1716fcea | 16089 | + int err; |
4a4d8108 | 16090 | + aufs_bindex_t bstart; |
1facf9fc | 16091 | + |
4a4d8108 AM |
16092 | + sb = dentry->d_sb; |
16093 | + bstart = au_dbstart(dentry); | |
16094 | + h_dentry = au_h_dptr(dentry, bstart); | |
5527c038 JR |
16095 | + h_inode = d_inode(h_dentry); |
16096 | + h_ino = h_inode->i_ino; | |
b752ccd1 AM |
16097 | + |
16098 | + /* | |
16099 | + * stop 'race'-ing between hardlinks under different | |
16100 | + * parents. | |
16101 | + */ | |
16102 | + mtx = NULL; | |
2000de60 | 16103 | + if (!d_is_dir(h_dentry)) |
b752ccd1 AM |
16104 | + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx; |
16105 | + | |
4f0767ce | 16106 | +new_ino: |
b752ccd1 AM |
16107 | + if (mtx) |
16108 | + mutex_lock(mtx); | |
4a4d8108 AM |
16109 | + err = au_xino_read(sb, bstart, h_ino, &ino); |
16110 | + inode = ERR_PTR(err); | |
16111 | + if (unlikely(err)) | |
16112 | + goto out; | |
b752ccd1 | 16113 | + |
4a4d8108 AM |
16114 | + if (!ino) { |
16115 | + ino = au_xino_new_ino(sb); | |
16116 | + if (unlikely(!ino)) { | |
16117 | + inode = ERR_PTR(-EIO); | |
dece6358 AM |
16118 | + goto out; |
16119 | + } | |
16120 | + } | |
1facf9fc | 16121 | + |
4a4d8108 AM |
16122 | + AuDbg("i%lu\n", (unsigned long)ino); |
16123 | + inode = au_iget_locked(sb, ino); | |
16124 | + err = PTR_ERR(inode); | |
16125 | + if (IS_ERR(inode)) | |
1facf9fc | 16126 | + goto out; |
1facf9fc | 16127 | + |
4a4d8108 AM |
16128 | + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW)); |
16129 | + if (inode->i_state & I_NEW) { | |
1716fcea | 16130 | + /* verbose coding for lock class name */ |
2000de60 | 16131 | + if (unlikely(d_is_symlink(h_dentry))) |
1716fcea AM |
16132 | + au_rw_class(&au_ii(inode)->ii_rwsem, |
16133 | + au_lc_key + AuLcSymlink_IIINFO); | |
2000de60 | 16134 | + else if (unlikely(d_is_dir(h_dentry))) |
1716fcea AM |
16135 | + au_rw_class(&au_ii(inode)->ii_rwsem, |
16136 | + au_lc_key + AuLcDir_IIINFO); | |
16137 | + else /* likely */ | |
16138 | + au_rw_class(&au_ii(inode)->ii_rwsem, | |
16139 | + au_lc_key + AuLcNonDir_IIINFO); | |
2dfbb274 | 16140 | + |
4a4d8108 AM |
16141 | + ii_write_lock_new_child(inode); |
16142 | + err = set_inode(inode, dentry); | |
16143 | + if (!err) { | |
16144 | + unlock_new_inode(inode); | |
16145 | + goto out; /* success */ | |
16146 | + } | |
1308ab2a | 16147 | + |
027c5e7a AM |
16148 | + /* |
16149 | + * iget_failed() calls iput(), but we need to call | |
16150 | + * ii_write_unlock() after iget_failed(). so dirty hack for | |
16151 | + * i_count. | |
16152 | + */ | |
16153 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 16154 | + iget_failed(inode); |
027c5e7a AM |
16155 | + ii_write_unlock(inode); |
16156 | + au_xino_write(sb, bstart, h_ino, /*ino*/0); | |
16157 | + /* ignore this error */ | |
16158 | + goto out_iput; | |
16159 | + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) { | |
b752ccd1 AM |
16160 | + /* |
16161 | + * horrible race condition between lookup, readdir and copyup | |
16162 | + * (or something). | |
16163 | + */ | |
16164 | + if (mtx) | |
16165 | + mutex_unlock(mtx); | |
027c5e7a AM |
16166 | + err = reval_inode(inode, dentry); |
16167 | + if (unlikely(err < 0)) { | |
16168 | + mtx = NULL; | |
16169 | + goto out_iput; | |
16170 | + } | |
16171 | + | |
b752ccd1 AM |
16172 | + if (!err) { |
16173 | + mtx = NULL; | |
4a4d8108 | 16174 | + goto out; /* success */ |
b752ccd1 AM |
16175 | + } else if (mtx) |
16176 | + mutex_lock(mtx); | |
4a4d8108 AM |
16177 | + } |
16178 | + | |
5527c038 | 16179 | + if (unlikely(au_test_fs_unique_ino(h_inode))) |
4a4d8108 | 16180 | + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir," |
523b37e3 AM |
16181 | + " b%d, %s, %pd, hi%lu, i%lu.\n", |
16182 | + bstart, au_sbtype(h_dentry->d_sb), dentry, | |
4a4d8108 AM |
16183 | + (unsigned long)h_ino, (unsigned long)ino); |
16184 | + ino = 0; | |
16185 | + err = au_xino_write(sb, bstart, h_ino, /*ino*/0); | |
16186 | + if (!err) { | |
16187 | + iput(inode); | |
b752ccd1 AM |
16188 | + if (mtx) |
16189 | + mutex_unlock(mtx); | |
4a4d8108 AM |
16190 | + goto new_ino; |
16191 | + } | |
1308ab2a | 16192 | + |
4f0767ce | 16193 | +out_iput: |
4a4d8108 | 16194 | + iput(inode); |
4a4d8108 | 16195 | + inode = ERR_PTR(err); |
4f0767ce | 16196 | +out: |
b752ccd1 AM |
16197 | + if (mtx) |
16198 | + mutex_unlock(mtx); | |
4a4d8108 | 16199 | + return inode; |
1facf9fc | 16200 | +} |
16201 | + | |
4a4d8108 | 16202 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16203 | + |
4a4d8108 AM |
16204 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, |
16205 | + struct inode *inode) | |
16206 | +{ | |
16207 | + int err; | |
076b876e | 16208 | + struct inode *hi; |
1facf9fc | 16209 | + |
4a4d8108 | 16210 | + err = au_br_rdonly(au_sbr(sb, bindex)); |
1facf9fc | 16211 | + |
4a4d8108 AM |
16212 | + /* pseudo-link after flushed may happen out of bounds */ |
16213 | + if (!err | |
16214 | + && inode | |
16215 | + && au_ibstart(inode) <= bindex | |
16216 | + && bindex <= au_ibend(inode)) { | |
16217 | + /* | |
16218 | + * permission check is unnecessary since vfsub routine | |
16219 | + * will be called later | |
16220 | + */ | |
076b876e | 16221 | + hi = au_h_iptr(inode, bindex); |
4a4d8108 AM |
16222 | + if (hi) |
16223 | + err = IS_IMMUTABLE(hi) ? -EROFS : 0; | |
1facf9fc | 16224 | + } |
16225 | + | |
4a4d8108 AM |
16226 | + return err; |
16227 | +} | |
dece6358 | 16228 | + |
4a4d8108 AM |
16229 | +int au_test_h_perm(struct inode *h_inode, int mask) |
16230 | +{ | |
2dfbb274 | 16231 | + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) |
4a4d8108 AM |
16232 | + return 0; |
16233 | + return inode_permission(h_inode, mask); | |
16234 | +} | |
1facf9fc | 16235 | + |
4a4d8108 AM |
16236 | +int au_test_h_perm_sio(struct inode *h_inode, int mask) |
16237 | +{ | |
16238 | + if (au_test_nfs(h_inode->i_sb) | |
16239 | + && (mask & MAY_WRITE) | |
16240 | + && S_ISDIR(h_inode->i_mode)) | |
16241 | + mask |= MAY_READ; /* force permission check */ | |
16242 | + return au_test_h_perm(h_inode, mask); | |
1facf9fc | 16243 | +} |
7f207e10 AM |
16244 | diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h |
16245 | --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 16246 | +++ linux/fs/aufs/inode.h 2015-09-24 10:47:58.254719746 +0200 |
b912730e | 16247 | @@ -0,0 +1,673 @@ |
4a4d8108 | 16248 | +/* |
2000de60 | 16249 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
16250 | + * |
16251 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16252 | + * it under the terms of the GNU General Public License as published by | |
16253 | + * the Free Software Foundation; either version 2 of the License, or | |
16254 | + * (at your option) any later version. | |
16255 | + * | |
16256 | + * This program is distributed in the hope that it will be useful, | |
16257 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16258 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16259 | + * GNU General Public License for more details. | |
16260 | + * | |
16261 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16262 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 16263 | + */ |
1facf9fc | 16264 | + |
1308ab2a | 16265 | +/* |
4a4d8108 | 16266 | + * inode operations |
1308ab2a | 16267 | + */ |
dece6358 | 16268 | + |
4a4d8108 AM |
16269 | +#ifndef __AUFS_INODE_H__ |
16270 | +#define __AUFS_INODE_H__ | |
dece6358 | 16271 | + |
4a4d8108 | 16272 | +#ifdef __KERNEL__ |
1308ab2a | 16273 | + |
4a4d8108 | 16274 | +#include <linux/fsnotify.h> |
4a4d8108 | 16275 | +#include "rwsem.h" |
1308ab2a | 16276 | + |
4a4d8108 | 16277 | +struct vfsmount; |
1facf9fc | 16278 | + |
4a4d8108 AM |
16279 | +struct au_hnotify { |
16280 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16281 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
7f207e10 | 16282 | + /* never use fsnotify_add_vfsmount_mark() */ |
0c5527e5 | 16283 | + struct fsnotify_mark hn_mark; |
4a4d8108 | 16284 | +#endif |
7f207e10 | 16285 | + struct inode *hn_aufs_inode; /* no get/put */ |
4a4d8108 AM |
16286 | +#endif |
16287 | +} ____cacheline_aligned_in_smp; | |
1facf9fc | 16288 | + |
4a4d8108 AM |
16289 | +struct au_hinode { |
16290 | + struct inode *hi_inode; | |
16291 | + aufs_bindex_t hi_id; | |
16292 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16293 | + struct au_hnotify *hi_notify; | |
16294 | +#endif | |
dece6358 | 16295 | + |
4a4d8108 AM |
16296 | + /* reference to the copied-up whiteout with get/put */ |
16297 | + struct dentry *hi_whdentry; | |
16298 | +}; | |
dece6358 | 16299 | + |
537831f9 AM |
16300 | +/* ig_flags */ |
16301 | +#define AuIG_HALF_REFRESHED 1 | |
16302 | +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name) | |
16303 | +#define au_ig_fset(flags, name) \ | |
16304 | + do { (flags) |= AuIG_##name; } while (0) | |
16305 | +#define au_ig_fclr(flags, name) \ | |
16306 | + do { (flags) &= ~AuIG_##name; } while (0) | |
16307 | + | |
16308 | +struct au_iigen { | |
16309 | + __u32 ig_generation, ig_flags; | |
16310 | +}; | |
16311 | + | |
4a4d8108 AM |
16312 | +struct au_vdir; |
16313 | +struct au_iinfo { | |
537831f9 | 16314 | + spinlock_t ii_genspin; |
7a9e40b8 | 16315 | + struct au_iigen ii_generation; |
4a4d8108 | 16316 | + struct super_block *ii_hsb1; /* no get/put */ |
1facf9fc | 16317 | + |
4a4d8108 AM |
16318 | + struct au_rwsem ii_rwsem; |
16319 | + aufs_bindex_t ii_bstart, ii_bend; | |
16320 | + __u32 ii_higen; | |
16321 | + struct au_hinode *ii_hinode; | |
16322 | + struct au_vdir *ii_vdir; | |
16323 | +}; | |
1facf9fc | 16324 | + |
4a4d8108 AM |
16325 | +struct au_icntnr { |
16326 | + struct au_iinfo iinfo; | |
16327 | + struct inode vfs_inode; | |
16328 | +} ____cacheline_aligned_in_smp; | |
1308ab2a | 16329 | + |
4a4d8108 AM |
16330 | +/* au_pin flags */ |
16331 | +#define AuPin_DI_LOCKED 1 | |
16332 | +#define AuPin_MNT_WRITE (1 << 1) | |
16333 | +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name) | |
7f207e10 AM |
16334 | +#define au_fset_pin(flags, name) \ |
16335 | + do { (flags) |= AuPin_##name; } while (0) | |
16336 | +#define au_fclr_pin(flags, name) \ | |
16337 | + do { (flags) &= ~AuPin_##name; } while (0) | |
4a4d8108 AM |
16338 | + |
16339 | +struct au_pin { | |
16340 | + /* input */ | |
16341 | + struct dentry *dentry; | |
16342 | + unsigned int udba; | |
16343 | + unsigned char lsc_di, lsc_hi, flags; | |
16344 | + aufs_bindex_t bindex; | |
16345 | + | |
16346 | + /* output */ | |
16347 | + struct dentry *parent; | |
16348 | + struct au_hinode *hdir; | |
16349 | + struct vfsmount *h_mnt; | |
86dc4139 AM |
16350 | + |
16351 | + /* temporary unlock/relock for copyup */ | |
16352 | + struct dentry *h_dentry, *h_parent; | |
16353 | + struct au_branch *br; | |
16354 | + struct task_struct *task; | |
4a4d8108 | 16355 | +}; |
1facf9fc | 16356 | + |
86dc4139 | 16357 | +void au_pin_hdir_unlock(struct au_pin *p); |
c1595e42 | 16358 | +int au_pin_hdir_lock(struct au_pin *p); |
86dc4139 AM |
16359 | +int au_pin_hdir_relock(struct au_pin *p); |
16360 | +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task); | |
16361 | +void au_pin_hdir_acquire_nest(struct au_pin *p); | |
16362 | +void au_pin_hdir_release(struct au_pin *p); | |
16363 | + | |
1308ab2a | 16364 | +/* ---------------------------------------------------------------------- */ |
16365 | + | |
4a4d8108 | 16366 | +static inline struct au_iinfo *au_ii(struct inode *inode) |
1facf9fc | 16367 | +{ |
4a4d8108 | 16368 | + struct au_iinfo *iinfo; |
1facf9fc | 16369 | + |
4a4d8108 AM |
16370 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); |
16371 | + if (iinfo->ii_hinode) | |
16372 | + return iinfo; | |
16373 | + return NULL; /* debugging bad_inode case */ | |
16374 | +} | |
1facf9fc | 16375 | + |
4a4d8108 | 16376 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16377 | + |
4a4d8108 AM |
16378 | +/* inode.c */ |
16379 | +struct inode *au_igrab(struct inode *inode); | |
027c5e7a | 16380 | +int au_refresh_hinode_self(struct inode *inode); |
4a4d8108 AM |
16381 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry); |
16382 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
16383 | + unsigned int d_type, ino_t *ino); | |
16384 | +struct inode *au_new_inode(struct dentry *dentry, int must_new); | |
16385 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, | |
16386 | + struct inode *inode); | |
16387 | +int au_test_h_perm(struct inode *h_inode, int mask); | |
16388 | +int au_test_h_perm_sio(struct inode *h_inode, int mask); | |
1facf9fc | 16389 | + |
4a4d8108 AM |
16390 | +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, |
16391 | + ino_t h_ino, unsigned int d_type, ino_t *ino) | |
16392 | +{ | |
16393 | +#ifdef CONFIG_AUFS_SHWH | |
16394 | + return au_ino(sb, bindex, h_ino, d_type, ino); | |
16395 | +#else | |
16396 | + return 0; | |
16397 | +#endif | |
16398 | +} | |
1facf9fc | 16399 | + |
4a4d8108 AM |
16400 | +/* i_op.c */ |
16401 | +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop; | |
1308ab2a | 16402 | + |
4a4d8108 AM |
16403 | +/* au_wr_dir flags */ |
16404 | +#define AuWrDir_ADD_ENTRY 1 | |
7e9cd9fe AM |
16405 | +#define AuWrDir_ISDIR (1 << 1) |
16406 | +#define AuWrDir_TMPFILE (1 << 2) | |
4a4d8108 | 16407 | +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name) |
7f207e10 AM |
16408 | +#define au_fset_wrdir(flags, name) \ |
16409 | + do { (flags) |= AuWrDir_##name; } while (0) | |
16410 | +#define au_fclr_wrdir(flags, name) \ | |
16411 | + do { (flags) &= ~AuWrDir_##name; } while (0) | |
1facf9fc | 16412 | + |
4a4d8108 AM |
16413 | +struct au_wr_dir_args { |
16414 | + aufs_bindex_t force_btgt; | |
16415 | + unsigned char flags; | |
16416 | +}; | |
16417 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
16418 | + struct au_wr_dir_args *args); | |
dece6358 | 16419 | + |
4a4d8108 AM |
16420 | +struct dentry *au_pinned_h_parent(struct au_pin *pin); |
16421 | +void au_pin_init(struct au_pin *pin, struct dentry *dentry, | |
16422 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
16423 | + unsigned int udba, unsigned char flags); | |
16424 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
16425 | + unsigned int udba, unsigned char flags) __must_check; | |
16426 | +int au_do_pin(struct au_pin *pin) __must_check; | |
16427 | +void au_unpin(struct au_pin *pin); | |
c1595e42 JR |
16428 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen); |
16429 | + | |
16430 | +#define AuIcpup_DID_CPUP 1 | |
16431 | +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name) | |
16432 | +#define au_fset_icpup(flags, name) \ | |
16433 | + do { (flags) |= AuIcpup_##name; } while (0) | |
16434 | +#define au_fclr_icpup(flags, name) \ | |
16435 | + do { (flags) &= ~AuIcpup_##name; } while (0) | |
16436 | + | |
16437 | +struct au_icpup_args { | |
16438 | + unsigned char flags; | |
16439 | + unsigned char pin_flags; | |
16440 | + aufs_bindex_t btgt; | |
16441 | + unsigned int udba; | |
16442 | + struct au_pin pin; | |
16443 | + struct path h_path; | |
16444 | + struct inode *h_inode; | |
16445 | +}; | |
16446 | + | |
16447 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, | |
16448 | + struct au_icpup_args *a); | |
16449 | + | |
16450 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path); | |
1facf9fc | 16451 | + |
4a4d8108 AM |
16452 | +/* i_op_add.c */ |
16453 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
16454 | + struct dentry *h_parent, int isdir); | |
7eafdf33 AM |
16455 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
16456 | + dev_t dev); | |
4a4d8108 | 16457 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname); |
7eafdf33 | 16458 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 16459 | + bool want_excl); |
b912730e AM |
16460 | +struct vfsub_aopen_args; |
16461 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, | |
16462 | + struct vfsub_aopen_args *args); | |
38d290e6 | 16463 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode); |
4a4d8108 AM |
16464 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, |
16465 | + struct dentry *dentry); | |
7eafdf33 | 16466 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
1facf9fc | 16467 | + |
4a4d8108 AM |
16468 | +/* i_op_del.c */ |
16469 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup); | |
16470 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
16471 | + struct dentry *h_parent, int isdir); | |
16472 | +int aufs_unlink(struct inode *dir, struct dentry *dentry); | |
16473 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry); | |
1308ab2a | 16474 | + |
4a4d8108 AM |
16475 | +/* i_op_ren.c */ |
16476 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt); | |
16477 | +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry, | |
16478 | + struct inode *dir, struct dentry *dentry); | |
1facf9fc | 16479 | + |
4a4d8108 AM |
16480 | +/* iinfo.c */ |
16481 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex); | |
16482 | +void au_hiput(struct au_hinode *hinode); | |
16483 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, | |
16484 | + struct dentry *h_wh); | |
16485 | +unsigned int au_hi_flags(struct inode *inode, int isdir); | |
1308ab2a | 16486 | + |
4a4d8108 AM |
16487 | +/* hinode flags */ |
16488 | +#define AuHi_XINO 1 | |
16489 | +#define AuHi_HNOTIFY (1 << 1) | |
16490 | +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name) | |
7f207e10 AM |
16491 | +#define au_fset_hi(flags, name) \ |
16492 | + do { (flags) |= AuHi_##name; } while (0) | |
16493 | +#define au_fclr_hi(flags, name) \ | |
16494 | + do { (flags) &= ~AuHi_##name; } while (0) | |
1facf9fc | 16495 | + |
4a4d8108 AM |
16496 | +#ifndef CONFIG_AUFS_HNOTIFY |
16497 | +#undef AuHi_HNOTIFY | |
16498 | +#define AuHi_HNOTIFY 0 | |
16499 | +#endif | |
1facf9fc | 16500 | + |
4a4d8108 AM |
16501 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
16502 | + struct inode *h_inode, unsigned int flags); | |
1facf9fc | 16503 | + |
537831f9 | 16504 | +void au_update_iigen(struct inode *inode, int half); |
4a4d8108 | 16505 | +void au_update_ibrange(struct inode *inode, int do_put_zero); |
1facf9fc | 16506 | + |
4a4d8108 AM |
16507 | +void au_icntnr_init_once(void *_c); |
16508 | +int au_iinfo_init(struct inode *inode); | |
16509 | +void au_iinfo_fin(struct inode *inode); | |
16510 | +int au_ii_realloc(struct au_iinfo *iinfo, int nbr); | |
1308ab2a | 16511 | + |
e49829fe | 16512 | +#ifdef CONFIG_PROC_FS |
4a4d8108 | 16513 | +/* plink.c */ |
e49829fe | 16514 | +int au_plink_maint(struct super_block *sb, int flags); |
7e9cd9fe | 16515 | +struct au_sbinfo; |
e49829fe JR |
16516 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo); |
16517 | +int au_plink_maint_enter(struct super_block *sb); | |
4a4d8108 AM |
16518 | +#ifdef CONFIG_AUFS_DEBUG |
16519 | +void au_plink_list(struct super_block *sb); | |
16520 | +#else | |
16521 | +AuStubVoid(au_plink_list, struct super_block *sb) | |
16522 | +#endif | |
16523 | +int au_plink_test(struct inode *inode); | |
16524 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex); | |
16525 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
16526 | + struct dentry *h_dentry); | |
e49829fe JR |
16527 | +void au_plink_put(struct super_block *sb, int verbose); |
16528 | +void au_plink_clean(struct super_block *sb, int verbose); | |
4a4d8108 | 16529 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id); |
e49829fe JR |
16530 | +#else |
16531 | +AuStubInt0(au_plink_maint, struct super_block *sb, int flags); | |
16532 | +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo); | |
16533 | +AuStubInt0(au_plink_maint_enter, struct super_block *sb); | |
16534 | +AuStubVoid(au_plink_list, struct super_block *sb); | |
16535 | +AuStubInt0(au_plink_test, struct inode *inode); | |
16536 | +AuStub(struct dentry *, au_plink_lkup, return NULL, | |
16537 | + struct inode *inode, aufs_bindex_t bindex); | |
16538 | +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex, | |
16539 | + struct dentry *h_dentry); | |
16540 | +AuStubVoid(au_plink_put, struct super_block *sb, int verbose); | |
16541 | +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose); | |
16542 | +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id); | |
16543 | +#endif /* CONFIG_PROC_FS */ | |
1facf9fc | 16544 | + |
c1595e42 JR |
16545 | +#ifdef CONFIG_AUFS_XATTR |
16546 | +/* xattr.c */ | |
7e9cd9fe AM |
16547 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
16548 | + unsigned int verbose); | |
c1595e42 JR |
16549 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size); |
16550 | +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value, | |
16551 | + size_t size); | |
16552 | +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value, | |
16553 | + size_t size, int flags); | |
16554 | +int aufs_removexattr(struct dentry *dentry, const char *name); | |
16555 | + | |
16556 | +/* void au_xattr_init(struct super_block *sb); */ | |
16557 | +#else | |
16558 | +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe | 16559 | + int ignore_flags, unsigned int verbose); |
c1595e42 JR |
16560 | +/* AuStubVoid(au_xattr_init, struct super_block *sb); */ |
16561 | +#endif | |
16562 | + | |
16563 | +#ifdef CONFIG_FS_POSIX_ACL | |
16564 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type); | |
16565 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
16566 | +#endif | |
16567 | + | |
16568 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) | |
16569 | +enum { | |
16570 | + AU_XATTR_SET, | |
16571 | + AU_XATTR_REMOVE, | |
16572 | + AU_ACL_SET | |
16573 | +}; | |
16574 | + | |
16575 | +struct au_srxattr { | |
16576 | + int type; | |
16577 | + union { | |
16578 | + struct { | |
16579 | + const char *name; | |
16580 | + const void *value; | |
16581 | + size_t size; | |
16582 | + int flags; | |
16583 | + } set; | |
16584 | + struct { | |
16585 | + const char *name; | |
16586 | + } remove; | |
16587 | + struct { | |
16588 | + struct posix_acl *acl; | |
16589 | + int type; | |
16590 | + } acl_set; | |
16591 | + } u; | |
16592 | +}; | |
16593 | +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg); | |
16594 | +#endif | |
16595 | + | |
4a4d8108 | 16596 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16597 | + |
4a4d8108 AM |
16598 | +/* lock subclass for iinfo */ |
16599 | +enum { | |
16600 | + AuLsc_II_CHILD, /* child first */ | |
16601 | + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */ | |
16602 | + AuLsc_II_CHILD3, /* copyup dirs */ | |
16603 | + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */ | |
16604 | + AuLsc_II_PARENT2, | |
16605 | + AuLsc_II_PARENT3, /* copyup dirs */ | |
16606 | + AuLsc_II_NEW_CHILD | |
16607 | +}; | |
1308ab2a | 16608 | + |
1facf9fc | 16609 | +/* |
4a4d8108 AM |
16610 | + * ii_read_lock_child, ii_write_lock_child, |
16611 | + * ii_read_lock_child2, ii_write_lock_child2, | |
16612 | + * ii_read_lock_child3, ii_write_lock_child3, | |
16613 | + * ii_read_lock_parent, ii_write_lock_parent, | |
16614 | + * ii_read_lock_parent2, ii_write_lock_parent2, | |
16615 | + * ii_read_lock_parent3, ii_write_lock_parent3, | |
16616 | + * ii_read_lock_new_child, ii_write_lock_new_child, | |
1facf9fc | 16617 | + */ |
4a4d8108 AM |
16618 | +#define AuReadLockFunc(name, lsc) \ |
16619 | +static inline void ii_read_lock_##name(struct inode *i) \ | |
16620 | +{ \ | |
16621 | + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
16622 | +} | |
16623 | + | |
16624 | +#define AuWriteLockFunc(name, lsc) \ | |
16625 | +static inline void ii_write_lock_##name(struct inode *i) \ | |
16626 | +{ \ | |
16627 | + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
16628 | +} | |
16629 | + | |
16630 | +#define AuRWLockFuncs(name, lsc) \ | |
16631 | + AuReadLockFunc(name, lsc) \ | |
16632 | + AuWriteLockFunc(name, lsc) | |
16633 | + | |
16634 | +AuRWLockFuncs(child, CHILD); | |
16635 | +AuRWLockFuncs(child2, CHILD2); | |
16636 | +AuRWLockFuncs(child3, CHILD3); | |
16637 | +AuRWLockFuncs(parent, PARENT); | |
16638 | +AuRWLockFuncs(parent2, PARENT2); | |
16639 | +AuRWLockFuncs(parent3, PARENT3); | |
16640 | +AuRWLockFuncs(new_child, NEW_CHILD); | |
16641 | + | |
16642 | +#undef AuReadLockFunc | |
16643 | +#undef AuWriteLockFunc | |
16644 | +#undef AuRWLockFuncs | |
1facf9fc | 16645 | + |
16646 | +/* | |
4a4d8108 | 16647 | + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock |
1facf9fc | 16648 | + */ |
4a4d8108 | 16649 | +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem); |
1facf9fc | 16650 | + |
4a4d8108 AM |
16651 | +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem) |
16652 | +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem) | |
16653 | +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 16654 | + |
4a4d8108 | 16655 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16656 | + |
027c5e7a AM |
16657 | +static inline void au_icntnr_init(struct au_icntnr *c) |
16658 | +{ | |
16659 | +#ifdef CONFIG_AUFS_DEBUG | |
16660 | + c->vfs_inode.i_mode = 0; | |
16661 | +#endif | |
16662 | +} | |
16663 | + | |
537831f9 | 16664 | +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen) |
4a4d8108 | 16665 | +{ |
537831f9 AM |
16666 | + unsigned int gen; |
16667 | + struct au_iinfo *iinfo; | |
16668 | + | |
16669 | + iinfo = au_ii(inode); | |
16670 | + spin_lock(&iinfo->ii_genspin); | |
16671 | + if (iigen) | |
16672 | + *iigen = iinfo->ii_generation; | |
16673 | + gen = iinfo->ii_generation.ig_generation; | |
16674 | + spin_unlock(&iinfo->ii_genspin); | |
16675 | + | |
16676 | + return gen; | |
4a4d8108 | 16677 | +} |
1308ab2a | 16678 | + |
4a4d8108 AM |
16679 | +/* tiny test for inode number */ |
16680 | +/* tmpfs generation is too rough */ | |
16681 | +static inline int au_test_higen(struct inode *inode, struct inode *h_inode) | |
16682 | +{ | |
16683 | + struct au_iinfo *iinfo; | |
1308ab2a | 16684 | + |
4a4d8108 AM |
16685 | + iinfo = au_ii(inode); |
16686 | + AuRwMustAnyLock(&iinfo->ii_rwsem); | |
16687 | + return !(iinfo->ii_hsb1 == h_inode->i_sb | |
16688 | + && iinfo->ii_higen == h_inode->i_generation); | |
16689 | +} | |
1308ab2a | 16690 | + |
4a4d8108 AM |
16691 | +static inline void au_iigen_dec(struct inode *inode) |
16692 | +{ | |
537831f9 AM |
16693 | + struct au_iinfo *iinfo; |
16694 | + | |
16695 | + iinfo = au_ii(inode); | |
16696 | + spin_lock(&iinfo->ii_genspin); | |
16697 | + iinfo->ii_generation.ig_generation--; | |
16698 | + spin_unlock(&iinfo->ii_genspin); | |
027c5e7a AM |
16699 | +} |
16700 | + | |
16701 | +static inline int au_iigen_test(struct inode *inode, unsigned int sigen) | |
16702 | +{ | |
16703 | + int err; | |
16704 | + | |
16705 | + err = 0; | |
537831f9 | 16706 | + if (unlikely(inode && au_iigen(inode, NULL) != sigen)) |
027c5e7a AM |
16707 | + err = -EIO; |
16708 | + | |
16709 | + return err; | |
4a4d8108 | 16710 | +} |
1308ab2a | 16711 | + |
4a4d8108 | 16712 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16713 | + |
4a4d8108 AM |
16714 | +static inline aufs_bindex_t au_ii_br_id(struct inode *inode, |
16715 | + aufs_bindex_t bindex) | |
16716 | +{ | |
16717 | + IiMustAnyLock(inode); | |
16718 | + return au_ii(inode)->ii_hinode[0 + bindex].hi_id; | |
16719 | +} | |
1308ab2a | 16720 | + |
4a4d8108 AM |
16721 | +static inline aufs_bindex_t au_ibstart(struct inode *inode) |
16722 | +{ | |
16723 | + IiMustAnyLock(inode); | |
16724 | + return au_ii(inode)->ii_bstart; | |
16725 | +} | |
1308ab2a | 16726 | + |
4a4d8108 AM |
16727 | +static inline aufs_bindex_t au_ibend(struct inode *inode) |
16728 | +{ | |
16729 | + IiMustAnyLock(inode); | |
16730 | + return au_ii(inode)->ii_bend; | |
16731 | +} | |
1308ab2a | 16732 | + |
4a4d8108 AM |
16733 | +static inline struct au_vdir *au_ivdir(struct inode *inode) |
16734 | +{ | |
16735 | + IiMustAnyLock(inode); | |
16736 | + return au_ii(inode)->ii_vdir; | |
16737 | +} | |
1308ab2a | 16738 | + |
4a4d8108 AM |
16739 | +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex) |
16740 | +{ | |
16741 | + IiMustAnyLock(inode); | |
16742 | + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry; | |
16743 | +} | |
1308ab2a | 16744 | + |
4a4d8108 | 16745 | +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 16746 | +{ |
4a4d8108 AM |
16747 | + IiMustWriteLock(inode); |
16748 | + au_ii(inode)->ii_bstart = bindex; | |
16749 | +} | |
1308ab2a | 16750 | + |
4a4d8108 AM |
16751 | +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex) |
16752 | +{ | |
16753 | + IiMustWriteLock(inode); | |
16754 | + au_ii(inode)->ii_bend = bindex; | |
1308ab2a | 16755 | +} |
16756 | + | |
4a4d8108 AM |
16757 | +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir) |
16758 | +{ | |
16759 | + IiMustWriteLock(inode); | |
16760 | + au_ii(inode)->ii_vdir = vdir; | |
16761 | +} | |
1facf9fc | 16762 | + |
4a4d8108 | 16763 | +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 16764 | +{ |
4a4d8108 AM |
16765 | + IiMustAnyLock(inode); |
16766 | + return au_ii(inode)->ii_hinode + bindex; | |
16767 | +} | |
dece6358 | 16768 | + |
4a4d8108 | 16769 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16770 | + |
4a4d8108 AM |
16771 | +static inline struct dentry *au_pinned_parent(struct au_pin *pin) |
16772 | +{ | |
16773 | + if (pin) | |
16774 | + return pin->parent; | |
16775 | + return NULL; | |
1facf9fc | 16776 | +} |
16777 | + | |
4a4d8108 | 16778 | +static inline struct inode *au_pinned_h_dir(struct au_pin *pin) |
1facf9fc | 16779 | +{ |
4a4d8108 AM |
16780 | + if (pin && pin->hdir) |
16781 | + return pin->hdir->hi_inode; | |
16782 | + return NULL; | |
1308ab2a | 16783 | +} |
1facf9fc | 16784 | + |
4a4d8108 AM |
16785 | +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin) |
16786 | +{ | |
16787 | + if (pin) | |
16788 | + return pin->hdir; | |
16789 | + return NULL; | |
16790 | +} | |
1facf9fc | 16791 | + |
4a4d8108 | 16792 | +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry) |
1308ab2a | 16793 | +{ |
4a4d8108 AM |
16794 | + if (pin) |
16795 | + pin->dentry = dentry; | |
16796 | +} | |
1308ab2a | 16797 | + |
4a4d8108 AM |
16798 | +static inline void au_pin_set_parent_lflag(struct au_pin *pin, |
16799 | + unsigned char lflag) | |
16800 | +{ | |
16801 | + if (pin) { | |
7f207e10 | 16802 | + if (lflag) |
4a4d8108 | 16803 | + au_fset_pin(pin->flags, DI_LOCKED); |
7f207e10 | 16804 | + else |
4a4d8108 | 16805 | + au_fclr_pin(pin->flags, DI_LOCKED); |
1308ab2a | 16806 | + } |
4a4d8108 AM |
16807 | +} |
16808 | + | |
7e9cd9fe | 16809 | +#if 0 /* reserved */ |
4a4d8108 AM |
16810 | +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent) |
16811 | +{ | |
16812 | + if (pin) { | |
16813 | + dput(pin->parent); | |
16814 | + pin->parent = dget(parent); | |
1facf9fc | 16815 | + } |
4a4d8108 | 16816 | +} |
7e9cd9fe | 16817 | +#endif |
1facf9fc | 16818 | + |
4a4d8108 AM |
16819 | +/* ---------------------------------------------------------------------- */ |
16820 | + | |
027c5e7a | 16821 | +struct au_branch; |
4a4d8108 AM |
16822 | +#ifdef CONFIG_AUFS_HNOTIFY |
16823 | +struct au_hnotify_op { | |
16824 | + void (*ctl)(struct au_hinode *hinode, int do_set); | |
027c5e7a | 16825 | + int (*alloc)(struct au_hinode *hinode); |
7eafdf33 AM |
16826 | + |
16827 | + /* | |
16828 | + * if it returns true, the the caller should free hinode->hi_notify, | |
16829 | + * otherwise ->free() frees it. | |
16830 | + */ | |
16831 | + int (*free)(struct au_hinode *hinode, | |
16832 | + struct au_hnotify *hn) __must_check; | |
4a4d8108 AM |
16833 | + |
16834 | + void (*fin)(void); | |
16835 | + int (*init)(void); | |
027c5e7a AM |
16836 | + |
16837 | + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm); | |
16838 | + void (*fin_br)(struct au_branch *br); | |
16839 | + int (*init_br)(struct au_branch *br, int perm); | |
4a4d8108 AM |
16840 | +}; |
16841 | + | |
16842 | +/* hnotify.c */ | |
027c5e7a | 16843 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode); |
4a4d8108 AM |
16844 | +void au_hn_free(struct au_hinode *hinode); |
16845 | +void au_hn_ctl(struct au_hinode *hinode, int do_set); | |
16846 | +void au_hn_reset(struct inode *inode, unsigned int flags); | |
16847 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
16848 | + struct qstr *h_child_qstr, struct inode *h_child_inode); | |
027c5e7a AM |
16849 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm); |
16850 | +int au_hnotify_init_br(struct au_branch *br, int perm); | |
16851 | +void au_hnotify_fin_br(struct au_branch *br); | |
4a4d8108 AM |
16852 | +int __init au_hnotify_init(void); |
16853 | +void au_hnotify_fin(void); | |
16854 | + | |
7f207e10 | 16855 | +/* hfsnotify.c */ |
4a4d8108 AM |
16856 | +extern const struct au_hnotify_op au_hnotify_op; |
16857 | + | |
16858 | +static inline | |
16859 | +void au_hn_init(struct au_hinode *hinode) | |
16860 | +{ | |
16861 | + hinode->hi_notify = NULL; | |
1308ab2a | 16862 | +} |
16863 | + | |
53392da6 AM |
16864 | +static inline struct au_hnotify *au_hn(struct au_hinode *hinode) |
16865 | +{ | |
16866 | + return hinode->hi_notify; | |
16867 | +} | |
16868 | + | |
4a4d8108 | 16869 | +#else |
c1595e42 JR |
16870 | +AuStub(int, au_hn_alloc, return -EOPNOTSUPP, |
16871 | + struct au_hinode *hinode __maybe_unused, | |
16872 | + struct inode *inode __maybe_unused) | |
16873 | +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode) | |
4a4d8108 AM |
16874 | +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused) |
16875 | +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused, | |
16876 | + int do_set __maybe_unused) | |
16877 | +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused, | |
16878 | + unsigned int flags __maybe_unused) | |
027c5e7a AM |
16879 | +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused, |
16880 | + struct au_branch *br __maybe_unused, | |
16881 | + int perm __maybe_unused) | |
16882 | +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused, | |
16883 | + int perm __maybe_unused) | |
16884 | +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused) | |
4a4d8108 AM |
16885 | +AuStubInt0(__init au_hnotify_init, void) |
16886 | +AuStubVoid(au_hnotify_fin, void) | |
16887 | +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused) | |
16888 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
16889 | + | |
16890 | +static inline void au_hn_suspend(struct au_hinode *hdir) | |
16891 | +{ | |
16892 | + au_hn_ctl(hdir, /*do_set*/0); | |
1308ab2a | 16893 | +} |
16894 | + | |
4a4d8108 | 16895 | +static inline void au_hn_resume(struct au_hinode *hdir) |
1308ab2a | 16896 | +{ |
4a4d8108 AM |
16897 | + au_hn_ctl(hdir, /*do_set*/1); |
16898 | +} | |
1308ab2a | 16899 | + |
4a4d8108 AM |
16900 | +static inline void au_hn_imtx_lock(struct au_hinode *hdir) |
16901 | +{ | |
16902 | + mutex_lock(&hdir->hi_inode->i_mutex); | |
16903 | + au_hn_suspend(hdir); | |
16904 | +} | |
dece6358 | 16905 | + |
4a4d8108 AM |
16906 | +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir, |
16907 | + unsigned int sc __maybe_unused) | |
16908 | +{ | |
16909 | + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc); | |
16910 | + au_hn_suspend(hdir); | |
1facf9fc | 16911 | +} |
1facf9fc | 16912 | + |
4a4d8108 AM |
16913 | +static inline void au_hn_imtx_unlock(struct au_hinode *hdir) |
16914 | +{ | |
16915 | + au_hn_resume(hdir); | |
16916 | + mutex_unlock(&hdir->hi_inode->i_mutex); | |
16917 | +} | |
16918 | + | |
16919 | +#endif /* __KERNEL__ */ | |
16920 | +#endif /* __AUFS_INODE_H__ */ | |
7f207e10 AM |
16921 | diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c |
16922 | --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 16923 | +++ linux/fs/aufs/ioctl.c 2015-09-24 10:47:58.254719746 +0200 |
c1595e42 | 16924 | @@ -0,0 +1,219 @@ |
4a4d8108 | 16925 | +/* |
2000de60 | 16926 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
16927 | + * |
16928 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16929 | + * it under the terms of the GNU General Public License as published by | |
16930 | + * the Free Software Foundation; either version 2 of the License, or | |
16931 | + * (at your option) any later version. | |
16932 | + * | |
16933 | + * This program is distributed in the hope that it will be useful, | |
16934 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16935 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16936 | + * GNU General Public License for more details. | |
16937 | + * | |
16938 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16939 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
16940 | + */ |
16941 | + | |
16942 | +/* | |
16943 | + * ioctl | |
16944 | + * plink-management and readdir in userspace. | |
16945 | + * assist the pathconf(3) wrapper library. | |
c2b27bf2 | 16946 | + * move-down |
076b876e | 16947 | + * File-based Hierarchical Storage Management. |
4a4d8108 AM |
16948 | + */ |
16949 | + | |
c2b27bf2 AM |
16950 | +#include <linux/compat.h> |
16951 | +#include <linux/file.h> | |
4a4d8108 AM |
16952 | +#include "aufs.h" |
16953 | + | |
1e00d052 | 16954 | +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg) |
4a4d8108 AM |
16955 | +{ |
16956 | + int err, fd; | |
16957 | + aufs_bindex_t wbi, bindex, bend; | |
16958 | + struct file *h_file; | |
16959 | + struct super_block *sb; | |
16960 | + struct dentry *root; | |
1e00d052 AM |
16961 | + struct au_branch *br; |
16962 | + struct aufs_wbr_fd wbrfd = { | |
16963 | + .oflags = au_dir_roflags, | |
16964 | + .brid = -1 | |
16965 | + }; | |
16966 | + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY | |
16967 | + | O_NOATIME | O_CLOEXEC; | |
4a4d8108 | 16968 | + |
1e00d052 AM |
16969 | + AuDebugOn(wbrfd.oflags & ~valid); |
16970 | + | |
16971 | + if (arg) { | |
16972 | + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd)); | |
16973 | + if (unlikely(err)) { | |
16974 | + err = -EFAULT; | |
16975 | + goto out; | |
16976 | + } | |
16977 | + | |
16978 | + err = -EINVAL; | |
16979 | + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid); | |
16980 | + wbrfd.oflags |= au_dir_roflags; | |
16981 | + AuDbg("0%o\n", wbrfd.oflags); | |
16982 | + if (unlikely(wbrfd.oflags & ~valid)) | |
16983 | + goto out; | |
16984 | + } | |
16985 | + | |
2000de60 | 16986 | + fd = get_unused_fd_flags(0); |
1e00d052 AM |
16987 | + err = fd; |
16988 | + if (unlikely(fd < 0)) | |
4a4d8108 | 16989 | + goto out; |
4a4d8108 | 16990 | + |
1e00d052 | 16991 | + h_file = ERR_PTR(-EINVAL); |
4a4d8108 | 16992 | + wbi = 0; |
1e00d052 | 16993 | + br = NULL; |
4a4d8108 AM |
16994 | + sb = path->dentry->d_sb; |
16995 | + root = sb->s_root; | |
16996 | + aufs_read_lock(root, AuLock_IR); | |
1e00d052 AM |
16997 | + bend = au_sbend(sb); |
16998 | + if (wbrfd.brid >= 0) { | |
16999 | + wbi = au_br_index(sb, wbrfd.brid); | |
17000 | + if (unlikely(wbi < 0 || wbi > bend)) | |
17001 | + goto out_unlock; | |
17002 | + } | |
17003 | + | |
17004 | + h_file = ERR_PTR(-ENOENT); | |
17005 | + br = au_sbr(sb, wbi); | |
17006 | + if (!au_br_writable(br->br_perm)) { | |
17007 | + if (arg) | |
17008 | + goto out_unlock; | |
17009 | + | |
17010 | + bindex = wbi + 1; | |
17011 | + wbi = -1; | |
17012 | + for (; bindex <= bend; bindex++) { | |
17013 | + br = au_sbr(sb, bindex); | |
17014 | + if (au_br_writable(br->br_perm)) { | |
4a4d8108 | 17015 | + wbi = bindex; |
1e00d052 | 17016 | + br = au_sbr(sb, wbi); |
4a4d8108 AM |
17017 | + break; |
17018 | + } | |
17019 | + } | |
4a4d8108 AM |
17020 | + } |
17021 | + AuDbg("wbi %d\n", wbi); | |
1e00d052 | 17022 | + if (wbi >= 0) |
392086de AM |
17023 | + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL, |
17024 | + /*force_wr*/0); | |
1e00d052 AM |
17025 | + |
17026 | +out_unlock: | |
4a4d8108 AM |
17027 | + aufs_read_unlock(root, AuLock_IR); |
17028 | + err = PTR_ERR(h_file); | |
17029 | + if (IS_ERR(h_file)) | |
17030 | + goto out_fd; | |
17031 | + | |
1e00d052 | 17032 | + atomic_dec(&br->br_count); /* cf. au_h_open() */ |
4a4d8108 AM |
17033 | + fd_install(fd, h_file); |
17034 | + err = fd; | |
17035 | + goto out; /* success */ | |
17036 | + | |
4f0767ce | 17037 | +out_fd: |
4a4d8108 | 17038 | + put_unused_fd(fd); |
4f0767ce | 17039 | +out: |
1e00d052 | 17040 | + AuTraceErr(err); |
4a4d8108 AM |
17041 | + return err; |
17042 | +} | |
17043 | + | |
17044 | +/* ---------------------------------------------------------------------- */ | |
17045 | + | |
17046 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg) | |
17047 | +{ | |
17048 | + long err; | |
c1595e42 | 17049 | + struct dentry *dentry; |
4a4d8108 AM |
17050 | + |
17051 | + switch (cmd) { | |
4a4d8108 AM |
17052 | + case AUFS_CTL_RDU: |
17053 | + case AUFS_CTL_RDU_INO: | |
17054 | + err = au_rdu_ioctl(file, cmd, arg); | |
17055 | + break; | |
17056 | + | |
17057 | + case AUFS_CTL_WBR_FD: | |
1e00d052 | 17058 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17059 | + break; |
17060 | + | |
027c5e7a AM |
17061 | + case AUFS_CTL_IBUSY: |
17062 | + err = au_ibusy_ioctl(file, arg); | |
17063 | + break; | |
17064 | + | |
076b876e AM |
17065 | + case AUFS_CTL_BRINFO: |
17066 | + err = au_brinfo_ioctl(file, arg); | |
17067 | + break; | |
17068 | + | |
17069 | + case AUFS_CTL_FHSM_FD: | |
2000de60 | 17070 | + dentry = file->f_path.dentry; |
c1595e42 JR |
17071 | + if (IS_ROOT(dentry)) |
17072 | + err = au_fhsm_fd(dentry->d_sb, arg); | |
17073 | + else | |
17074 | + err = -ENOTTY; | |
076b876e AM |
17075 | + break; |
17076 | + | |
4a4d8108 AM |
17077 | + default: |
17078 | + /* do not call the lower */ | |
17079 | + AuDbg("0x%x\n", cmd); | |
17080 | + err = -ENOTTY; | |
17081 | + } | |
17082 | + | |
17083 | + AuTraceErr(err); | |
17084 | + return err; | |
17085 | +} | |
17086 | + | |
17087 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg) | |
17088 | +{ | |
17089 | + long err; | |
17090 | + | |
17091 | + switch (cmd) { | |
c2b27bf2 | 17092 | + case AUFS_CTL_MVDOWN: |
2000de60 | 17093 | + err = au_mvdown(file->f_path.dentry, (void __user *)arg); |
c2b27bf2 AM |
17094 | + break; |
17095 | + | |
4a4d8108 | 17096 | + case AUFS_CTL_WBR_FD: |
1e00d052 | 17097 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17098 | + break; |
17099 | + | |
17100 | + default: | |
17101 | + /* do not call the lower */ | |
17102 | + AuDbg("0x%x\n", cmd); | |
17103 | + err = -ENOTTY; | |
17104 | + } | |
17105 | + | |
17106 | + AuTraceErr(err); | |
17107 | + return err; | |
17108 | +} | |
b752ccd1 AM |
17109 | + |
17110 | +#ifdef CONFIG_COMPAT | |
17111 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
17112 | + unsigned long arg) | |
17113 | +{ | |
17114 | + long err; | |
17115 | + | |
17116 | + switch (cmd) { | |
17117 | + case AUFS_CTL_RDU: | |
17118 | + case AUFS_CTL_RDU_INO: | |
17119 | + err = au_rdu_compat_ioctl(file, cmd, arg); | |
17120 | + break; | |
17121 | + | |
027c5e7a AM |
17122 | + case AUFS_CTL_IBUSY: |
17123 | + err = au_ibusy_compat_ioctl(file, arg); | |
17124 | + break; | |
17125 | + | |
076b876e AM |
17126 | + case AUFS_CTL_BRINFO: |
17127 | + err = au_brinfo_compat_ioctl(file, arg); | |
17128 | + break; | |
17129 | + | |
b752ccd1 AM |
17130 | + default: |
17131 | + err = aufs_ioctl_dir(file, cmd, arg); | |
17132 | + } | |
17133 | + | |
17134 | + AuTraceErr(err); | |
17135 | + return err; | |
17136 | +} | |
17137 | + | |
b752ccd1 AM |
17138 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
17139 | + unsigned long arg) | |
17140 | +{ | |
17141 | + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg)); | |
17142 | +} | |
17143 | +#endif | |
7f207e10 AM |
17144 | diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c |
17145 | --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 17146 | +++ linux/fs/aufs/i_op_add.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 17147 | @@ -0,0 +1,932 @@ |
4a4d8108 | 17148 | +/* |
2000de60 | 17149 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
17150 | + * |
17151 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17152 | + * it under the terms of the GNU General Public License as published by | |
17153 | + * the Free Software Foundation; either version 2 of the License, or | |
17154 | + * (at your option) any later version. | |
17155 | + * | |
17156 | + * This program is distributed in the hope that it will be useful, | |
17157 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17158 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17159 | + * GNU General Public License for more details. | |
17160 | + * | |
17161 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17162 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
17163 | + */ |
17164 | + | |
17165 | +/* | |
17166 | + * inode operations (add entry) | |
17167 | + */ | |
17168 | + | |
17169 | +#include "aufs.h" | |
17170 | + | |
17171 | +/* | |
17172 | + * final procedure of adding a new entry, except link(2). | |
17173 | + * remove whiteout, instantiate, copyup the parent dir's times and size | |
17174 | + * and update version. | |
17175 | + * if it failed, re-create the removed whiteout. | |
17176 | + */ | |
17177 | +static int epilog(struct inode *dir, aufs_bindex_t bindex, | |
17178 | + struct dentry *wh_dentry, struct dentry *dentry) | |
17179 | +{ | |
17180 | + int err, rerr; | |
17181 | + aufs_bindex_t bwh; | |
17182 | + struct path h_path; | |
076b876e | 17183 | + struct super_block *sb; |
4a4d8108 AM |
17184 | + struct inode *inode, *h_dir; |
17185 | + struct dentry *wh; | |
17186 | + | |
17187 | + bwh = -1; | |
076b876e | 17188 | + sb = dir->i_sb; |
4a4d8108 | 17189 | + if (wh_dentry) { |
5527c038 | 17190 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
4a4d8108 AM |
17191 | + IMustLock(h_dir); |
17192 | + AuDebugOn(au_h_iptr(dir, bindex) != h_dir); | |
17193 | + bwh = au_dbwh(dentry); | |
17194 | + h_path.dentry = wh_dentry; | |
076b876e | 17195 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
4a4d8108 AM |
17196 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, |
17197 | + dentry); | |
17198 | + if (unlikely(err)) | |
17199 | + goto out; | |
17200 | + } | |
17201 | + | |
17202 | + inode = au_new_inode(dentry, /*must_new*/1); | |
17203 | + if (!IS_ERR(inode)) { | |
17204 | + d_instantiate(dentry, inode); | |
5527c038 | 17205 | + dir = d_inode(dentry->d_parent); /* dir inode is locked */ |
4a4d8108 | 17206 | + IMustLock(dir); |
b912730e | 17207 | + au_dir_ts(dir, bindex); |
4a4d8108 | 17208 | + dir->i_version++; |
076b876e | 17209 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
4a4d8108 AM |
17210 | + return 0; /* success */ |
17211 | + } | |
17212 | + | |
17213 | + err = PTR_ERR(inode); | |
17214 | + if (!wh_dentry) | |
17215 | + goto out; | |
17216 | + | |
17217 | + /* revert */ | |
17218 | + /* dir inode is locked */ | |
17219 | + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent); | |
17220 | + rerr = PTR_ERR(wh); | |
17221 | + if (IS_ERR(wh)) { | |
523b37e3 AM |
17222 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", |
17223 | + dentry, err, rerr); | |
4a4d8108 AM |
17224 | + err = -EIO; |
17225 | + } else | |
17226 | + dput(wh); | |
17227 | + | |
4f0767ce | 17228 | +out: |
4a4d8108 AM |
17229 | + return err; |
17230 | +} | |
17231 | + | |
027c5e7a AM |
17232 | +static int au_d_may_add(struct dentry *dentry) |
17233 | +{ | |
17234 | + int err; | |
17235 | + | |
17236 | + err = 0; | |
17237 | + if (unlikely(d_unhashed(dentry))) | |
17238 | + err = -ENOENT; | |
5527c038 | 17239 | + if (unlikely(d_really_is_positive(dentry))) |
027c5e7a AM |
17240 | + err = -EEXIST; |
17241 | + return err; | |
17242 | +} | |
17243 | + | |
4a4d8108 AM |
17244 | +/* |
17245 | + * simple tests for the adding inode operations. | |
17246 | + * following the checks in vfs, plus the parent-child relationship. | |
17247 | + */ | |
17248 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
17249 | + struct dentry *h_parent, int isdir) | |
17250 | +{ | |
17251 | + int err; | |
17252 | + umode_t h_mode; | |
17253 | + struct dentry *h_dentry; | |
17254 | + struct inode *h_inode; | |
17255 | + | |
17256 | + err = -ENAMETOOLONG; | |
17257 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17258 | + goto out; | |
17259 | + | |
17260 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 17261 | + if (d_really_is_negative(dentry)) { |
4a4d8108 | 17262 | + err = -EEXIST; |
5527c038 | 17263 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
17264 | + goto out; |
17265 | + } else { | |
17266 | + /* rename(2) case */ | |
17267 | + err = -EIO; | |
5527c038 JR |
17268 | + if (unlikely(d_is_negative(h_dentry))) |
17269 | + goto out; | |
17270 | + h_inode = d_inode(h_dentry); | |
17271 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 AM |
17272 | + goto out; |
17273 | + | |
17274 | + h_mode = h_inode->i_mode; | |
17275 | + if (!isdir) { | |
17276 | + err = -EISDIR; | |
17277 | + if (unlikely(S_ISDIR(h_mode))) | |
17278 | + goto out; | |
17279 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
17280 | + err = -ENOTDIR; | |
17281 | + goto out; | |
17282 | + } | |
17283 | + } | |
17284 | + | |
17285 | + err = 0; | |
17286 | + /* expected parent dir is locked */ | |
17287 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
17288 | + err = -EIO; | |
17289 | + | |
4f0767ce | 17290 | +out: |
4a4d8108 AM |
17291 | + AuTraceErr(err); |
17292 | + return err; | |
17293 | +} | |
17294 | + | |
17295 | +/* | |
17296 | + * initial procedure of adding a new entry. | |
17297 | + * prepare writable branch and the parent dir, lock it, | |
17298 | + * and lookup whiteout for the new entry. | |
17299 | + */ | |
17300 | +static struct dentry* | |
17301 | +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt, | |
17302 | + struct dentry *src_dentry, struct au_pin *pin, | |
17303 | + struct au_wr_dir_args *wr_dir_args) | |
17304 | +{ | |
17305 | + struct dentry *wh_dentry, *h_parent; | |
17306 | + struct super_block *sb; | |
17307 | + struct au_branch *br; | |
17308 | + int err; | |
17309 | + unsigned int udba; | |
17310 | + aufs_bindex_t bcpup; | |
17311 | + | |
523b37e3 | 17312 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17313 | + |
17314 | + err = au_wr_dir(dentry, src_dentry, wr_dir_args); | |
17315 | + bcpup = err; | |
17316 | + wh_dentry = ERR_PTR(err); | |
17317 | + if (unlikely(err < 0)) | |
17318 | + goto out; | |
17319 | + | |
17320 | + sb = dentry->d_sb; | |
17321 | + udba = au_opt_udba(sb); | |
17322 | + err = au_pin(pin, dentry, bcpup, udba, | |
17323 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17324 | + wh_dentry = ERR_PTR(err); | |
17325 | + if (unlikely(err)) | |
17326 | + goto out; | |
17327 | + | |
17328 | + h_parent = au_pinned_h_parent(pin); | |
17329 | + if (udba != AuOpt_UDBA_NONE | |
17330 | + && au_dbstart(dentry) == bcpup) | |
17331 | + err = au_may_add(dentry, bcpup, h_parent, | |
17332 | + au_ftest_wrdir(wr_dir_args->flags, ISDIR)); | |
17333 | + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17334 | + err = -ENAMETOOLONG; | |
17335 | + wh_dentry = ERR_PTR(err); | |
17336 | + if (unlikely(err)) | |
17337 | + goto out_unpin; | |
17338 | + | |
17339 | + br = au_sbr(sb, bcpup); | |
17340 | + if (dt) { | |
17341 | + struct path tmp = { | |
17342 | + .dentry = h_parent, | |
86dc4139 | 17343 | + .mnt = au_br_mnt(br) |
4a4d8108 AM |
17344 | + }; |
17345 | + au_dtime_store(dt, au_pinned_parent(pin), &tmp); | |
17346 | + } | |
17347 | + | |
17348 | + wh_dentry = NULL; | |
17349 | + if (bcpup != au_dbwh(dentry)) | |
17350 | + goto out; /* success */ | |
17351 | + | |
2000de60 JR |
17352 | + /* |
17353 | + * ENAMETOOLONG here means that if we allowed create such name, then it | |
17354 | + * would not be able to removed in the future. So we don't allow such | |
17355 | + * name here and we don't handle ENAMETOOLONG differently here. | |
17356 | + */ | |
4a4d8108 AM |
17357 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br); |
17358 | + | |
4f0767ce | 17359 | +out_unpin: |
4a4d8108 AM |
17360 | + if (IS_ERR(wh_dentry)) |
17361 | + au_unpin(pin); | |
4f0767ce | 17362 | +out: |
4a4d8108 AM |
17363 | + return wh_dentry; |
17364 | +} | |
17365 | + | |
17366 | +/* ---------------------------------------------------------------------- */ | |
17367 | + | |
17368 | +enum { Mknod, Symlink, Creat }; | |
17369 | +struct simple_arg { | |
17370 | + int type; | |
17371 | + union { | |
17372 | + struct { | |
b912730e AM |
17373 | + umode_t mode; |
17374 | + bool want_excl; | |
17375 | + bool try_aopen; | |
17376 | + struct vfsub_aopen_args *aopen; | |
4a4d8108 AM |
17377 | + } c; |
17378 | + struct { | |
17379 | + const char *symname; | |
17380 | + } s; | |
17381 | + struct { | |
7eafdf33 | 17382 | + umode_t mode; |
4a4d8108 AM |
17383 | + dev_t dev; |
17384 | + } m; | |
17385 | + } u; | |
17386 | +}; | |
17387 | + | |
17388 | +static int add_simple(struct inode *dir, struct dentry *dentry, | |
17389 | + struct simple_arg *arg) | |
17390 | +{ | |
076b876e | 17391 | + int err, rerr; |
4a4d8108 AM |
17392 | + aufs_bindex_t bstart; |
17393 | + unsigned char created; | |
b912730e AM |
17394 | + const unsigned char try_aopen |
17395 | + = (arg->type == Creat && arg->u.c.try_aopen); | |
4a4d8108 AM |
17396 | + struct dentry *wh_dentry, *parent; |
17397 | + struct inode *h_dir; | |
b912730e AM |
17398 | + struct super_block *sb; |
17399 | + struct au_branch *br; | |
c2b27bf2 AM |
17400 | + /* to reuduce stack size */ |
17401 | + struct { | |
17402 | + struct au_dtime dt; | |
17403 | + struct au_pin pin; | |
17404 | + struct path h_path; | |
17405 | + struct au_wr_dir_args wr_dir_args; | |
17406 | + } *a; | |
4a4d8108 | 17407 | + |
523b37e3 | 17408 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17409 | + IMustLock(dir); |
17410 | + | |
c2b27bf2 AM |
17411 | + err = -ENOMEM; |
17412 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
17413 | + if (unlikely(!a)) | |
17414 | + goto out; | |
17415 | + a->wr_dir_args.force_btgt = -1; | |
17416 | + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY; | |
17417 | + | |
4a4d8108 | 17418 | + parent = dentry->d_parent; /* dir inode is locked */ |
b912730e AM |
17419 | + if (!try_aopen) { |
17420 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); | |
17421 | + if (unlikely(err)) | |
17422 | + goto out_free; | |
17423 | + } | |
027c5e7a AM |
17424 | + err = au_d_may_add(dentry); |
17425 | + if (unlikely(err)) | |
17426 | + goto out_unlock; | |
b912730e AM |
17427 | + if (!try_aopen) |
17428 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
17429 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, |
17430 | + &a->pin, &a->wr_dir_args); | |
4a4d8108 AM |
17431 | + err = PTR_ERR(wh_dentry); |
17432 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 17433 | + goto out_parent; |
4a4d8108 AM |
17434 | + |
17435 | + bstart = au_dbstart(dentry); | |
b912730e AM |
17436 | + sb = dentry->d_sb; |
17437 | + br = au_sbr(sb, bstart); | |
c2b27bf2 | 17438 | + a->h_path.dentry = au_h_dptr(dentry, bstart); |
b912730e | 17439 | + a->h_path.mnt = au_br_mnt(br); |
c2b27bf2 | 17440 | + h_dir = au_pinned_h_dir(&a->pin); |
4a4d8108 AM |
17441 | + switch (arg->type) { |
17442 | + case Creat: | |
b912730e AM |
17443 | + err = 0; |
17444 | + if (!try_aopen || !h_dir->i_op->atomic_open) | |
17445 | + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode, | |
17446 | + arg->u.c.want_excl); | |
17447 | + else | |
17448 | + err = vfsub_atomic_open(h_dir, a->h_path.dentry, | |
17449 | + arg->u.c.aopen, br); | |
4a4d8108 AM |
17450 | + break; |
17451 | + case Symlink: | |
c2b27bf2 | 17452 | + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname); |
4a4d8108 AM |
17453 | + break; |
17454 | + case Mknod: | |
c2b27bf2 AM |
17455 | + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode, |
17456 | + arg->u.m.dev); | |
4a4d8108 AM |
17457 | + break; |
17458 | + default: | |
17459 | + BUG(); | |
17460 | + } | |
17461 | + created = !err; | |
17462 | + if (!err) | |
17463 | + err = epilog(dir, bstart, wh_dentry, dentry); | |
17464 | + | |
17465 | + /* revert */ | |
5527c038 | 17466 | + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) { |
523b37e3 AM |
17467 | + /* no delegation since it is just created */ |
17468 | + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL, | |
17469 | + /*force*/0); | |
4a4d8108 | 17470 | + if (rerr) { |
523b37e3 AM |
17471 | + AuIOErr("%pd revert failure(%d, %d)\n", |
17472 | + dentry, err, rerr); | |
4a4d8108 AM |
17473 | + err = -EIO; |
17474 | + } | |
c2b27bf2 | 17475 | + au_dtime_revert(&a->dt); |
4a4d8108 AM |
17476 | + } |
17477 | + | |
b912730e AM |
17478 | + if (!err && try_aopen && !h_dir->i_op->atomic_open) |
17479 | + *arg->u.c.aopen->opened |= FILE_CREATED; | |
17480 | + | |
c2b27bf2 | 17481 | + au_unpin(&a->pin); |
4a4d8108 AM |
17482 | + dput(wh_dentry); |
17483 | + | |
027c5e7a | 17484 | +out_parent: |
b912730e AM |
17485 | + if (!try_aopen) |
17486 | + di_write_unlock(parent); | |
027c5e7a | 17487 | +out_unlock: |
4a4d8108 AM |
17488 | + if (unlikely(err)) { |
17489 | + au_update_dbstart(dentry); | |
17490 | + d_drop(dentry); | |
17491 | + } | |
b912730e AM |
17492 | + if (!try_aopen) |
17493 | + aufs_read_unlock(dentry, AuLock_DW); | |
c2b27bf2 AM |
17494 | +out_free: |
17495 | + kfree(a); | |
027c5e7a | 17496 | +out: |
4a4d8108 AM |
17497 | + return err; |
17498 | +} | |
17499 | + | |
7eafdf33 AM |
17500 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
17501 | + dev_t dev) | |
4a4d8108 AM |
17502 | +{ |
17503 | + struct simple_arg arg = { | |
17504 | + .type = Mknod, | |
17505 | + .u.m = { | |
17506 | + .mode = mode, | |
17507 | + .dev = dev | |
17508 | + } | |
17509 | + }; | |
17510 | + return add_simple(dir, dentry, &arg); | |
17511 | +} | |
17512 | + | |
17513 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |
17514 | +{ | |
17515 | + struct simple_arg arg = { | |
17516 | + .type = Symlink, | |
17517 | + .u.s.symname = symname | |
17518 | + }; | |
17519 | + return add_simple(dir, dentry, &arg); | |
17520 | +} | |
17521 | + | |
7eafdf33 | 17522 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 17523 | + bool want_excl) |
4a4d8108 AM |
17524 | +{ |
17525 | + struct simple_arg arg = { | |
17526 | + .type = Creat, | |
17527 | + .u.c = { | |
b4510431 AM |
17528 | + .mode = mode, |
17529 | + .want_excl = want_excl | |
4a4d8108 AM |
17530 | + } |
17531 | + }; | |
17532 | + return add_simple(dir, dentry, &arg); | |
17533 | +} | |
17534 | + | |
b912730e AM |
17535 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, |
17536 | + struct vfsub_aopen_args *aopen_args) | |
17537 | +{ | |
17538 | + struct simple_arg arg = { | |
17539 | + .type = Creat, | |
17540 | + .u.c = { | |
17541 | + .mode = aopen_args->create_mode, | |
17542 | + .want_excl = aopen_args->open_flag & O_EXCL, | |
17543 | + .try_aopen = true, | |
17544 | + .aopen = aopen_args | |
17545 | + } | |
17546 | + }; | |
17547 | + return add_simple(dir, dentry, &arg); | |
17548 | +} | |
17549 | + | |
38d290e6 JR |
17550 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
17551 | +{ | |
17552 | + int err; | |
17553 | + aufs_bindex_t bindex; | |
17554 | + struct super_block *sb; | |
17555 | + struct dentry *parent, *h_parent, *h_dentry; | |
17556 | + struct inode *h_dir, *inode; | |
17557 | + struct vfsmount *h_mnt; | |
17558 | + struct au_wr_dir_args wr_dir_args = { | |
17559 | + .force_btgt = -1, | |
17560 | + .flags = AuWrDir_TMPFILE | |
17561 | + }; | |
17562 | + | |
17563 | + /* copy-up may happen */ | |
17564 | + mutex_lock(&dir->i_mutex); | |
17565 | + | |
17566 | + sb = dir->i_sb; | |
17567 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
17568 | + if (unlikely(err)) | |
17569 | + goto out; | |
17570 | + | |
17571 | + err = au_di_init(dentry); | |
17572 | + if (unlikely(err)) | |
17573 | + goto out_si; | |
17574 | + | |
17575 | + err = -EBUSY; | |
17576 | + parent = d_find_any_alias(dir); | |
17577 | + AuDebugOn(!parent); | |
17578 | + di_write_lock_parent(parent); | |
5527c038 | 17579 | + if (unlikely(d_inode(parent) != dir)) |
38d290e6 JR |
17580 | + goto out_parent; |
17581 | + | |
17582 | + err = au_digen_test(parent, au_sigen(sb)); | |
17583 | + if (unlikely(err)) | |
17584 | + goto out_parent; | |
17585 | + | |
17586 | + bindex = au_dbstart(parent); | |
17587 | + au_set_dbstart(dentry, bindex); | |
17588 | + au_set_dbend(dentry, bindex); | |
17589 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); | |
17590 | + bindex = err; | |
17591 | + if (unlikely(err < 0)) | |
17592 | + goto out_parent; | |
17593 | + | |
17594 | + err = -EOPNOTSUPP; | |
17595 | + h_dir = au_h_iptr(dir, bindex); | |
17596 | + if (unlikely(!h_dir->i_op->tmpfile)) | |
17597 | + goto out_parent; | |
17598 | + | |
17599 | + h_mnt = au_sbr_mnt(sb, bindex); | |
17600 | + err = vfsub_mnt_want_write(h_mnt); | |
17601 | + if (unlikely(err)) | |
17602 | + goto out_parent; | |
17603 | + | |
17604 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 17605 | + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC); |
38d290e6 JR |
17606 | + if (unlikely(err)) |
17607 | + goto out_mnt; | |
17608 | + | |
17609 | + err = -ENOMEM; | |
17610 | + h_dentry = d_alloc(h_parent, &dentry->d_name); | |
17611 | + if (unlikely(!h_dentry)) | |
17612 | + goto out_mnt; | |
17613 | + | |
17614 | + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode); | |
17615 | + if (unlikely(err)) | |
17616 | + goto out_dentry; | |
17617 | + | |
17618 | + au_set_dbstart(dentry, bindex); | |
17619 | + au_set_dbend(dentry, bindex); | |
17620 | + au_set_h_dptr(dentry, bindex, dget(h_dentry)); | |
17621 | + inode = au_new_inode(dentry, /*must_new*/1); | |
17622 | + if (IS_ERR(inode)) { | |
17623 | + err = PTR_ERR(inode); | |
17624 | + au_set_h_dptr(dentry, bindex, NULL); | |
17625 | + au_set_dbstart(dentry, -1); | |
17626 | + au_set_dbend(dentry, -1); | |
17627 | + } else { | |
17628 | + if (!inode->i_nlink) | |
17629 | + set_nlink(inode, 1); | |
17630 | + d_tmpfile(dentry, inode); | |
17631 | + au_di(dentry)->di_tmpfile = 1; | |
17632 | + | |
17633 | + /* update without i_mutex */ | |
17634 | + if (au_ibstart(dir) == au_dbstart(dentry)) | |
17635 | + au_cpup_attr_timesizes(dir); | |
17636 | + } | |
17637 | + | |
17638 | +out_dentry: | |
17639 | + dput(h_dentry); | |
17640 | +out_mnt: | |
17641 | + vfsub_mnt_drop_write(h_mnt); | |
17642 | +out_parent: | |
17643 | + di_write_unlock(parent); | |
17644 | + dput(parent); | |
17645 | + di_write_unlock(dentry); | |
17646 | + if (!err) | |
17647 | +#if 0 | |
17648 | + /* verbose coding for lock class name */ | |
17649 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
17650 | + au_lc_key + AuLcNonDir_DIINFO); | |
17651 | +#else | |
17652 | + ; | |
17653 | +#endif | |
17654 | + else { | |
17655 | + au_di_fin(dentry); | |
17656 | + dentry->d_fsdata = NULL; | |
17657 | + } | |
17658 | +out_si: | |
17659 | + si_read_unlock(sb); | |
17660 | +out: | |
17661 | + mutex_unlock(&dir->i_mutex); | |
17662 | + return err; | |
17663 | +} | |
17664 | + | |
4a4d8108 AM |
17665 | +/* ---------------------------------------------------------------------- */ |
17666 | + | |
17667 | +struct au_link_args { | |
17668 | + aufs_bindex_t bdst, bsrc; | |
17669 | + struct au_pin pin; | |
17670 | + struct path h_path; | |
17671 | + struct dentry *src_parent, *parent; | |
17672 | +}; | |
17673 | + | |
17674 | +static int au_cpup_before_link(struct dentry *src_dentry, | |
17675 | + struct au_link_args *a) | |
17676 | +{ | |
17677 | + int err; | |
17678 | + struct dentry *h_src_dentry; | |
c2b27bf2 AM |
17679 | + struct au_cp_generic cpg = { |
17680 | + .dentry = src_dentry, | |
17681 | + .bdst = a->bdst, | |
17682 | + .bsrc = a->bsrc, | |
17683 | + .len = -1, | |
17684 | + .pin = &a->pin, | |
17685 | + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */ | |
17686 | + }; | |
4a4d8108 AM |
17687 | + |
17688 | + di_read_lock_parent(a->src_parent, AuLock_IR); | |
17689 | + err = au_test_and_cpup_dirs(src_dentry, a->bdst); | |
17690 | + if (unlikely(err)) | |
17691 | + goto out; | |
17692 | + | |
17693 | + h_src_dentry = au_h_dptr(src_dentry, a->bsrc); | |
4a4d8108 AM |
17694 | + err = au_pin(&a->pin, src_dentry, a->bdst, |
17695 | + au_opt_udba(src_dentry->d_sb), | |
17696 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17697 | + if (unlikely(err)) | |
17698 | + goto out; | |
367653fa | 17699 | + |
c2b27bf2 | 17700 | + err = au_sio_cpup_simple(&cpg); |
4a4d8108 AM |
17701 | + au_unpin(&a->pin); |
17702 | + | |
4f0767ce | 17703 | +out: |
4a4d8108 AM |
17704 | + di_read_unlock(a->src_parent, AuLock_IR); |
17705 | + return err; | |
17706 | +} | |
17707 | + | |
86dc4139 AM |
17708 | +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry, |
17709 | + struct au_link_args *a) | |
4a4d8108 AM |
17710 | +{ |
17711 | + int err; | |
17712 | + unsigned char plink; | |
86dc4139 | 17713 | + aufs_bindex_t bend; |
4a4d8108 | 17714 | + struct dentry *h_src_dentry; |
523b37e3 | 17715 | + struct inode *h_inode, *inode, *delegated; |
4a4d8108 AM |
17716 | + struct super_block *sb; |
17717 | + struct file *h_file; | |
17718 | + | |
17719 | + plink = 0; | |
17720 | + h_inode = NULL; | |
17721 | + sb = src_dentry->d_sb; | |
5527c038 | 17722 | + inode = d_inode(src_dentry); |
4a4d8108 AM |
17723 | + if (au_ibstart(inode) <= a->bdst) |
17724 | + h_inode = au_h_iptr(inode, a->bdst); | |
17725 | + if (!h_inode || !h_inode->i_nlink) { | |
17726 | + /* copyup src_dentry as the name of dentry. */ | |
86dc4139 AM |
17727 | + bend = au_dbend(dentry); |
17728 | + if (bend < a->bsrc) | |
17729 | + au_set_dbend(dentry, a->bsrc); | |
17730 | + au_set_h_dptr(dentry, a->bsrc, | |
17731 | + dget(au_h_dptr(src_dentry, a->bsrc))); | |
17732 | + dget(a->h_path.dentry); | |
17733 | + au_set_h_dptr(dentry, a->bdst, NULL); | |
c1595e42 JR |
17734 | + AuDbg("temporary d_inode...\n"); |
17735 | + spin_lock(&dentry->d_lock); | |
5527c038 | 17736 | + dentry->d_inode = d_inode(src_dentry); /* tmp */ |
c1595e42 | 17737 | + spin_unlock(&dentry->d_lock); |
392086de | 17738 | + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0); |
86dc4139 | 17739 | + if (IS_ERR(h_file)) |
4a4d8108 | 17740 | + err = PTR_ERR(h_file); |
86dc4139 | 17741 | + else { |
c2b27bf2 AM |
17742 | + struct au_cp_generic cpg = { |
17743 | + .dentry = dentry, | |
17744 | + .bdst = a->bdst, | |
17745 | + .bsrc = -1, | |
17746 | + .len = -1, | |
17747 | + .pin = &a->pin, | |
17748 | + .flags = AuCpup_KEEPLINO | |
17749 | + }; | |
17750 | + err = au_sio_cpup_simple(&cpg); | |
86dc4139 AM |
17751 | + au_h_open_post(dentry, a->bsrc, h_file); |
17752 | + if (!err) { | |
17753 | + dput(a->h_path.dentry); | |
17754 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
17755 | + } else | |
17756 | + au_set_h_dptr(dentry, a->bdst, | |
17757 | + a->h_path.dentry); | |
17758 | + } | |
c1595e42 | 17759 | + spin_lock(&dentry->d_lock); |
86dc4139 | 17760 | + dentry->d_inode = NULL; /* restore */ |
c1595e42 JR |
17761 | + spin_unlock(&dentry->d_lock); |
17762 | + AuDbg("temporary d_inode...done\n"); | |
86dc4139 AM |
17763 | + au_set_h_dptr(dentry, a->bsrc, NULL); |
17764 | + au_set_dbend(dentry, bend); | |
4a4d8108 AM |
17765 | + } else { |
17766 | + /* the inode of src_dentry already exists on a.bdst branch */ | |
17767 | + h_src_dentry = d_find_alias(h_inode); | |
17768 | + if (!h_src_dentry && au_plink_test(inode)) { | |
17769 | + plink = 1; | |
17770 | + h_src_dentry = au_plink_lkup(inode, a->bdst); | |
17771 | + err = PTR_ERR(h_src_dentry); | |
17772 | + if (IS_ERR(h_src_dentry)) | |
17773 | + goto out; | |
17774 | + | |
5527c038 | 17775 | + if (unlikely(d_is_negative(h_src_dentry))) { |
4a4d8108 AM |
17776 | + dput(h_src_dentry); |
17777 | + h_src_dentry = NULL; | |
17778 | + } | |
17779 | + | |
17780 | + } | |
17781 | + if (h_src_dentry) { | |
523b37e3 | 17782 | + delegated = NULL; |
4a4d8108 | 17783 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
17784 | + &a->h_path, &delegated); |
17785 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17786 | + pr_warn("cannot retry for NFSv4 delegation" | |
17787 | + " for an internal link\n"); | |
17788 | + iput(delegated); | |
17789 | + } | |
4a4d8108 AM |
17790 | + dput(h_src_dentry); |
17791 | + } else { | |
17792 | + AuIOErr("no dentry found for hi%lu on b%d\n", | |
17793 | + h_inode->i_ino, a->bdst); | |
17794 | + err = -EIO; | |
17795 | + } | |
17796 | + } | |
17797 | + | |
17798 | + if (!err && !plink) | |
17799 | + au_plink_append(inode, a->bdst, a->h_path.dentry); | |
17800 | + | |
17801 | +out: | |
2cbb1c4b | 17802 | + AuTraceErr(err); |
4a4d8108 AM |
17803 | + return err; |
17804 | +} | |
17805 | + | |
17806 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, | |
17807 | + struct dentry *dentry) | |
17808 | +{ | |
17809 | + int err, rerr; | |
17810 | + struct au_dtime dt; | |
17811 | + struct au_link_args *a; | |
17812 | + struct dentry *wh_dentry, *h_src_dentry; | |
523b37e3 | 17813 | + struct inode *inode, *delegated; |
4a4d8108 AM |
17814 | + struct super_block *sb; |
17815 | + struct au_wr_dir_args wr_dir_args = { | |
17816 | + /* .force_btgt = -1, */ | |
17817 | + .flags = AuWrDir_ADD_ENTRY | |
17818 | + }; | |
17819 | + | |
17820 | + IMustLock(dir); | |
5527c038 | 17821 | + inode = d_inode(src_dentry); |
4a4d8108 AM |
17822 | + IMustLock(inode); |
17823 | + | |
4a4d8108 AM |
17824 | + err = -ENOMEM; |
17825 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
17826 | + if (unlikely(!a)) | |
17827 | + goto out; | |
17828 | + | |
17829 | + a->parent = dentry->d_parent; /* dir inode is locked */ | |
027c5e7a AM |
17830 | + err = aufs_read_and_write_lock2(dentry, src_dentry, |
17831 | + AuLock_NOPLM | AuLock_GEN); | |
e49829fe JR |
17832 | + if (unlikely(err)) |
17833 | + goto out_kfree; | |
38d290e6 | 17834 | + err = au_d_linkable(src_dentry); |
027c5e7a AM |
17835 | + if (unlikely(err)) |
17836 | + goto out_unlock; | |
17837 | + err = au_d_may_add(dentry); | |
17838 | + if (unlikely(err)) | |
17839 | + goto out_unlock; | |
e49829fe | 17840 | + |
4a4d8108 | 17841 | + a->src_parent = dget_parent(src_dentry); |
2cbb1c4b | 17842 | + wr_dir_args.force_btgt = au_ibstart(inode); |
4a4d8108 AM |
17843 | + |
17844 | + di_write_lock_parent(a->parent); | |
17845 | + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt); | |
17846 | + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin, | |
17847 | + &wr_dir_args); | |
17848 | + err = PTR_ERR(wh_dentry); | |
17849 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 17850 | + goto out_parent; |
4a4d8108 AM |
17851 | + |
17852 | + err = 0; | |
17853 | + sb = dentry->d_sb; | |
17854 | + a->bdst = au_dbstart(dentry); | |
17855 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
17856 | + a->h_path.mnt = au_sbr_mnt(sb, a->bdst); | |
2cbb1c4b JR |
17857 | + a->bsrc = au_ibstart(inode); |
17858 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); | |
38d290e6 JR |
17859 | + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile) |
17860 | + h_src_dentry = dget(au_hi_wh(inode, a->bsrc)); | |
2cbb1c4b JR |
17861 | + if (!h_src_dentry) { |
17862 | + a->bsrc = au_dbstart(src_dentry); | |
17863 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); | |
17864 | + AuDebugOn(!h_src_dentry); | |
38d290e6 JR |
17865 | + } else if (IS_ERR(h_src_dentry)) { |
17866 | + err = PTR_ERR(h_src_dentry); | |
2cbb1c4b | 17867 | + goto out_parent; |
38d290e6 | 17868 | + } |
2cbb1c4b | 17869 | + |
4a4d8108 AM |
17870 | + if (au_opt_test(au_mntflags(sb), PLINK)) { |
17871 | + if (a->bdst < a->bsrc | |
17872 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) | |
86dc4139 | 17873 | + err = au_cpup_or_link(src_dentry, dentry, a); |
523b37e3 AM |
17874 | + else { |
17875 | + delegated = NULL; | |
4a4d8108 | 17876 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
17877 | + &a->h_path, &delegated); |
17878 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17879 | + pr_warn("cannot retry for NFSv4 delegation" | |
17880 | + " for an internal link\n"); | |
17881 | + iput(delegated); | |
17882 | + } | |
17883 | + } | |
2cbb1c4b | 17884 | + dput(h_src_dentry); |
4a4d8108 AM |
17885 | + } else { |
17886 | + /* | |
17887 | + * copyup src_dentry to the branch we process, | |
17888 | + * and then link(2) to it. | |
17889 | + */ | |
2cbb1c4b | 17890 | + dput(h_src_dentry); |
4a4d8108 AM |
17891 | + if (a->bdst < a->bsrc |
17892 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) { | |
17893 | + au_unpin(&a->pin); | |
17894 | + di_write_unlock(a->parent); | |
17895 | + err = au_cpup_before_link(src_dentry, a); | |
17896 | + di_write_lock_parent(a->parent); | |
17897 | + if (!err) | |
17898 | + err = au_pin(&a->pin, dentry, a->bdst, | |
17899 | + au_opt_udba(sb), | |
17900 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17901 | + if (unlikely(err)) | |
17902 | + goto out_wh; | |
17903 | + } | |
17904 | + if (!err) { | |
17905 | + h_src_dentry = au_h_dptr(src_dentry, a->bdst); | |
17906 | + err = -ENOENT; | |
5527c038 | 17907 | + if (h_src_dentry && d_is_positive(h_src_dentry)) { |
523b37e3 | 17908 | + delegated = NULL; |
4a4d8108 AM |
17909 | + err = vfsub_link(h_src_dentry, |
17910 | + au_pinned_h_dir(&a->pin), | |
523b37e3 AM |
17911 | + &a->h_path, &delegated); |
17912 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17913 | + pr_warn("cannot retry" | |
17914 | + " for NFSv4 delegation" | |
17915 | + " for an internal link\n"); | |
17916 | + iput(delegated); | |
17917 | + } | |
17918 | + } | |
4a4d8108 AM |
17919 | + } |
17920 | + } | |
17921 | + if (unlikely(err)) | |
17922 | + goto out_unpin; | |
17923 | + | |
17924 | + if (wh_dentry) { | |
17925 | + a->h_path.dentry = wh_dentry; | |
17926 | + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path, | |
17927 | + dentry); | |
17928 | + if (unlikely(err)) | |
17929 | + goto out_revert; | |
17930 | + } | |
17931 | + | |
b912730e | 17932 | + au_dir_ts(dir, a->bdst); |
4a4d8108 | 17933 | + dir->i_version++; |
4a4d8108 AM |
17934 | + inc_nlink(inode); |
17935 | + inode->i_ctime = dir->i_ctime; | |
027c5e7a AM |
17936 | + d_instantiate(dentry, au_igrab(inode)); |
17937 | + if (d_unhashed(a->h_path.dentry)) | |
4a4d8108 AM |
17938 | + /* some filesystem calls d_drop() */ |
17939 | + d_drop(dentry); | |
076b876e AM |
17940 | + /* some filesystems consume an inode even hardlink */ |
17941 | + au_fhsm_wrote(sb, a->bdst, /*force*/0); | |
4a4d8108 AM |
17942 | + goto out_unpin; /* success */ |
17943 | + | |
4f0767ce | 17944 | +out_revert: |
523b37e3 AM |
17945 | + /* no delegation since it is just created */ |
17946 | + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, | |
17947 | + /*delegated*/NULL, /*force*/0); | |
027c5e7a | 17948 | + if (unlikely(rerr)) { |
523b37e3 | 17949 | + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr); |
027c5e7a AM |
17950 | + err = -EIO; |
17951 | + } | |
4a4d8108 | 17952 | + au_dtime_revert(&dt); |
4f0767ce | 17953 | +out_unpin: |
4a4d8108 | 17954 | + au_unpin(&a->pin); |
4f0767ce | 17955 | +out_wh: |
4a4d8108 | 17956 | + dput(wh_dentry); |
027c5e7a AM |
17957 | +out_parent: |
17958 | + di_write_unlock(a->parent); | |
17959 | + dput(a->src_parent); | |
4f0767ce | 17960 | +out_unlock: |
4a4d8108 AM |
17961 | + if (unlikely(err)) { |
17962 | + au_update_dbstart(dentry); | |
17963 | + d_drop(dentry); | |
17964 | + } | |
4a4d8108 | 17965 | + aufs_read_and_write_unlock2(dentry, src_dentry); |
e49829fe | 17966 | +out_kfree: |
4a4d8108 | 17967 | + kfree(a); |
4f0767ce | 17968 | +out: |
86dc4139 | 17969 | + AuTraceErr(err); |
4a4d8108 AM |
17970 | + return err; |
17971 | +} | |
17972 | + | |
7eafdf33 | 17973 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
4a4d8108 AM |
17974 | +{ |
17975 | + int err, rerr; | |
17976 | + aufs_bindex_t bindex; | |
17977 | + unsigned char diropq; | |
17978 | + struct path h_path; | |
17979 | + struct dentry *wh_dentry, *parent, *opq_dentry; | |
17980 | + struct mutex *h_mtx; | |
17981 | + struct super_block *sb; | |
17982 | + struct { | |
17983 | + struct au_pin pin; | |
17984 | + struct au_dtime dt; | |
17985 | + } *a; /* reduce the stack usage */ | |
17986 | + struct au_wr_dir_args wr_dir_args = { | |
17987 | + .force_btgt = -1, | |
17988 | + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR | |
17989 | + }; | |
17990 | + | |
17991 | + IMustLock(dir); | |
17992 | + | |
17993 | + err = -ENOMEM; | |
17994 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
17995 | + if (unlikely(!a)) | |
17996 | + goto out; | |
17997 | + | |
027c5e7a AM |
17998 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
17999 | + if (unlikely(err)) | |
18000 | + goto out_free; | |
18001 | + err = au_d_may_add(dentry); | |
18002 | + if (unlikely(err)) | |
18003 | + goto out_unlock; | |
18004 | + | |
4a4d8108 AM |
18005 | + parent = dentry->d_parent; /* dir inode is locked */ |
18006 | + di_write_lock_parent(parent); | |
18007 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, | |
18008 | + &a->pin, &wr_dir_args); | |
18009 | + err = PTR_ERR(wh_dentry); | |
18010 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 18011 | + goto out_parent; |
4a4d8108 AM |
18012 | + |
18013 | + sb = dentry->d_sb; | |
18014 | + bindex = au_dbstart(dentry); | |
18015 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
18016 | + h_path.mnt = au_sbr_mnt(sb, bindex); | |
18017 | + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode); | |
18018 | + if (unlikely(err)) | |
027c5e7a | 18019 | + goto out_unpin; |
4a4d8108 AM |
18020 | + |
18021 | + /* make the dir opaque */ | |
18022 | + diropq = 0; | |
5527c038 | 18023 | + h_mtx = &d_inode(h_path.dentry)->i_mutex; |
4a4d8108 AM |
18024 | + if (wh_dentry |
18025 | + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) { | |
18026 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
18027 | + opq_dentry = au_diropq_create(dentry, bindex); | |
18028 | + mutex_unlock(h_mtx); | |
18029 | + err = PTR_ERR(opq_dentry); | |
18030 | + if (IS_ERR(opq_dentry)) | |
18031 | + goto out_dir; | |
18032 | + dput(opq_dentry); | |
18033 | + diropq = 1; | |
18034 | + } | |
18035 | + | |
18036 | + err = epilog(dir, bindex, wh_dentry, dentry); | |
18037 | + if (!err) { | |
18038 | + inc_nlink(dir); | |
027c5e7a | 18039 | + goto out_unpin; /* success */ |
4a4d8108 AM |
18040 | + } |
18041 | + | |
18042 | + /* revert */ | |
18043 | + if (diropq) { | |
18044 | + AuLabel(revert opq); | |
18045 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
18046 | + rerr = au_diropq_remove(dentry, bindex); | |
18047 | + mutex_unlock(h_mtx); | |
18048 | + if (rerr) { | |
523b37e3 AM |
18049 | + AuIOErr("%pd reverting diropq failed(%d, %d)\n", |
18050 | + dentry, err, rerr); | |
4a4d8108 AM |
18051 | + err = -EIO; |
18052 | + } | |
18053 | + } | |
18054 | + | |
4f0767ce | 18055 | +out_dir: |
4a4d8108 AM |
18056 | + AuLabel(revert dir); |
18057 | + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path); | |
18058 | + if (rerr) { | |
523b37e3 AM |
18059 | + AuIOErr("%pd reverting dir failed(%d, %d)\n", |
18060 | + dentry, err, rerr); | |
4a4d8108 AM |
18061 | + err = -EIO; |
18062 | + } | |
4a4d8108 | 18063 | + au_dtime_revert(&a->dt); |
027c5e7a | 18064 | +out_unpin: |
4a4d8108 AM |
18065 | + au_unpin(&a->pin); |
18066 | + dput(wh_dentry); | |
027c5e7a AM |
18067 | +out_parent: |
18068 | + di_write_unlock(parent); | |
18069 | +out_unlock: | |
4a4d8108 AM |
18070 | + if (unlikely(err)) { |
18071 | + au_update_dbstart(dentry); | |
18072 | + d_drop(dentry); | |
18073 | + } | |
4a4d8108 | 18074 | + aufs_read_unlock(dentry, AuLock_DW); |
027c5e7a | 18075 | +out_free: |
4a4d8108 | 18076 | + kfree(a); |
4f0767ce | 18077 | +out: |
4a4d8108 AM |
18078 | + return err; |
18079 | +} | |
7f207e10 AM |
18080 | diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c |
18081 | --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c AM |
18082 | +++ linux/fs/aufs/i_op.c 2015-09-24 10:47:58.254719746 +0200 |
18083 | @@ -0,0 +1,1483 @@ | |
4a4d8108 | 18084 | +/* |
2000de60 | 18085 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
4a4d8108 AM |
18086 | + * |
18087 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18088 | + * it under the terms of the GNU General Public License as published by | |
18089 | + * the Free Software Foundation; either version 2 of the License, or | |
18090 | + * (at your option) any later version. | |
18091 | + * | |
18092 | + * This program is distributed in the hope that it will be useful, | |
18093 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18094 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18095 | + * GNU General Public License for more details. | |
18096 | + * | |
18097 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18098 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18099 | + */ |
1facf9fc | 18100 | + |
1308ab2a | 18101 | +/* |
4a4d8108 | 18102 | + * inode operations (except add/del/rename) |
1308ab2a | 18103 | + */ |
4a4d8108 AM |
18104 | + |
18105 | +#include <linux/device_cgroup.h> | |
18106 | +#include <linux/fs_stack.h> | |
92d182d2 | 18107 | +#include <linux/mm.h> |
4a4d8108 AM |
18108 | +#include <linux/namei.h> |
18109 | +#include <linux/security.h> | |
4a4d8108 AM |
18110 | +#include "aufs.h" |
18111 | + | |
1e00d052 | 18112 | +static int h_permission(struct inode *h_inode, int mask, |
4a4d8108 | 18113 | + struct vfsmount *h_mnt, int brperm) |
1facf9fc | 18114 | +{ |
1308ab2a | 18115 | + int err; |
4a4d8108 | 18116 | + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); |
1facf9fc | 18117 | + |
4a4d8108 AM |
18118 | + err = -EACCES; |
18119 | + if ((write_mask && IS_IMMUTABLE(h_inode)) | |
18120 | + || ((mask & MAY_EXEC) | |
18121 | + && S_ISREG(h_inode->i_mode) | |
18122 | + && ((h_mnt->mnt_flags & MNT_NOEXEC) | |
18123 | + || !(h_inode->i_mode & S_IXUGO)))) | |
18124 | + goto out; | |
18125 | + | |
18126 | + /* | |
18127 | + * - skip the lower fs test in the case of write to ro branch. | |
18128 | + * - nfs dir permission write check is optimized, but a policy for | |
18129 | + * link/rename requires a real check. | |
b912730e AM |
18130 | + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.' |
18131 | + * in this case, generic_permission() returns -EOPNOTSUPP. | |
4a4d8108 AM |
18132 | + */ |
18133 | + if ((write_mask && !au_br_writable(brperm)) | |
18134 | + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode) | |
18135 | + && write_mask && !(mask & MAY_READ)) | |
18136 | + || !h_inode->i_op->permission) { | |
18137 | + /* AuLabel(generic_permission); */ | |
b912730e | 18138 | + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */ |
1e00d052 | 18139 | + err = generic_permission(h_inode, mask); |
b912730e AM |
18140 | + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode)) |
18141 | + err = h_inode->i_op->permission(h_inode, mask); | |
18142 | + AuTraceErr(err); | |
1308ab2a | 18143 | + } else { |
4a4d8108 | 18144 | + /* AuLabel(h_inode->permission); */ |
1e00d052 | 18145 | + err = h_inode->i_op->permission(h_inode, mask); |
4a4d8108 AM |
18146 | + AuTraceErr(err); |
18147 | + } | |
1facf9fc | 18148 | + |
4a4d8108 AM |
18149 | + if (!err) |
18150 | + err = devcgroup_inode_permission(h_inode, mask); | |
7f207e10 | 18151 | + if (!err) |
4a4d8108 | 18152 | + err = security_inode_permission(h_inode, mask); |
4a4d8108 AM |
18153 | + |
18154 | +#if 0 | |
18155 | + if (!err) { | |
18156 | + /* todo: do we need to call ima_path_check()? */ | |
18157 | + struct path h_path = { | |
18158 | + .dentry = | |
18159 | + .mnt = h_mnt | |
18160 | + }; | |
18161 | + err = ima_path_check(&h_path, | |
18162 | + mask & (MAY_READ | MAY_WRITE | MAY_EXEC), | |
18163 | + IMA_COUNT_LEAVE); | |
1308ab2a | 18164 | + } |
4a4d8108 | 18165 | +#endif |
dece6358 | 18166 | + |
4f0767ce | 18167 | +out: |
1308ab2a | 18168 | + return err; |
18169 | +} | |
dece6358 | 18170 | + |
1e00d052 | 18171 | +static int aufs_permission(struct inode *inode, int mask) |
1308ab2a | 18172 | +{ |
18173 | + int err; | |
4a4d8108 AM |
18174 | + aufs_bindex_t bindex, bend; |
18175 | + const unsigned char isdir = !!S_ISDIR(inode->i_mode), | |
18176 | + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); | |
18177 | + struct inode *h_inode; | |
18178 | + struct super_block *sb; | |
18179 | + struct au_branch *br; | |
1facf9fc | 18180 | + |
027c5e7a | 18181 | + /* todo: support rcu-walk? */ |
1e00d052 | 18182 | + if (mask & MAY_NOT_BLOCK) |
027c5e7a AM |
18183 | + return -ECHILD; |
18184 | + | |
4a4d8108 AM |
18185 | + sb = inode->i_sb; |
18186 | + si_read_lock(sb, AuLock_FLUSH); | |
18187 | + ii_read_lock_child(inode); | |
027c5e7a AM |
18188 | +#if 0 |
18189 | + err = au_iigen_test(inode, au_sigen(sb)); | |
18190 | + if (unlikely(err)) | |
18191 | + goto out; | |
18192 | +#endif | |
dece6358 | 18193 | + |
076b876e AM |
18194 | + if (!isdir |
18195 | + || write_mask | |
18196 | + || au_opt_test(au_mntflags(sb), DIRPERM1)) { | |
4a4d8108 AM |
18197 | + err = au_busy_or_stale(); |
18198 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
18199 | + if (unlikely(!h_inode | |
18200 | + || (h_inode->i_mode & S_IFMT) | |
18201 | + != (inode->i_mode & S_IFMT))) | |
18202 | + goto out; | |
1facf9fc | 18203 | + |
4a4d8108 AM |
18204 | + err = 0; |
18205 | + bindex = au_ibstart(inode); | |
18206 | + br = au_sbr(sb, bindex); | |
86dc4139 | 18207 | + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm); |
4a4d8108 AM |
18208 | + if (write_mask |
18209 | + && !err | |
18210 | + && !special_file(h_inode->i_mode)) { | |
18211 | + /* test whether the upper writable branch exists */ | |
18212 | + err = -EROFS; | |
18213 | + for (; bindex >= 0; bindex--) | |
18214 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
18215 | + err = 0; | |
18216 | + break; | |
18217 | + } | |
18218 | + } | |
18219 | + goto out; | |
18220 | + } | |
dece6358 | 18221 | + |
4a4d8108 | 18222 | + /* non-write to dir */ |
1308ab2a | 18223 | + err = 0; |
4a4d8108 AM |
18224 | + bend = au_ibend(inode); |
18225 | + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) { | |
18226 | + h_inode = au_h_iptr(inode, bindex); | |
18227 | + if (h_inode) { | |
18228 | + err = au_busy_or_stale(); | |
18229 | + if (unlikely(!S_ISDIR(h_inode->i_mode))) | |
18230 | + break; | |
18231 | + | |
18232 | + br = au_sbr(sb, bindex); | |
86dc4139 | 18233 | + err = h_permission(h_inode, mask, au_br_mnt(br), |
4a4d8108 AM |
18234 | + br->br_perm); |
18235 | + } | |
18236 | + } | |
1308ab2a | 18237 | + |
4f0767ce | 18238 | +out: |
4a4d8108 AM |
18239 | + ii_read_unlock(inode); |
18240 | + si_read_unlock(sb); | |
1308ab2a | 18241 | + return err; |
18242 | +} | |
18243 | + | |
4a4d8108 | 18244 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18245 | + |
4a4d8108 | 18246 | +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry, |
b4510431 | 18247 | + unsigned int flags) |
4a4d8108 AM |
18248 | +{ |
18249 | + struct dentry *ret, *parent; | |
b752ccd1 | 18250 | + struct inode *inode; |
4a4d8108 | 18251 | + struct super_block *sb; |
1716fcea | 18252 | + int err, npositive; |
dece6358 | 18253 | + |
4a4d8108 | 18254 | + IMustLock(dir); |
1308ab2a | 18255 | + |
537831f9 AM |
18256 | + /* todo: support rcu-walk? */ |
18257 | + ret = ERR_PTR(-ECHILD); | |
18258 | + if (flags & LOOKUP_RCU) | |
18259 | + goto out; | |
18260 | + | |
18261 | + ret = ERR_PTR(-ENAMETOOLONG); | |
18262 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
18263 | + goto out; | |
18264 | + | |
4a4d8108 | 18265 | + sb = dir->i_sb; |
7f207e10 AM |
18266 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
18267 | + ret = ERR_PTR(err); | |
18268 | + if (unlikely(err)) | |
18269 | + goto out; | |
18270 | + | |
4a4d8108 AM |
18271 | + err = au_di_init(dentry); |
18272 | + ret = ERR_PTR(err); | |
18273 | + if (unlikely(err)) | |
7f207e10 | 18274 | + goto out_si; |
1308ab2a | 18275 | + |
9dbd164d | 18276 | + inode = NULL; |
027c5e7a | 18277 | + npositive = 0; /* suppress a warning */ |
4a4d8108 AM |
18278 | + parent = dentry->d_parent; /* dir inode is locked */ |
18279 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a AM |
18280 | + err = au_alive_dir(parent); |
18281 | + if (!err) | |
18282 | + err = au_digen_test(parent, au_sigen(sb)); | |
18283 | + if (!err) { | |
18284 | + npositive = au_lkup_dentry(dentry, au_dbstart(parent), | |
537831f9 | 18285 | + /*type*/0); |
027c5e7a AM |
18286 | + err = npositive; |
18287 | + } | |
4a4d8108 | 18288 | + di_read_unlock(parent, AuLock_IR); |
4a4d8108 AM |
18289 | + ret = ERR_PTR(err); |
18290 | + if (unlikely(err < 0)) | |
18291 | + goto out_unlock; | |
1308ab2a | 18292 | + |
4a4d8108 | 18293 | + if (npositive) { |
b752ccd1 | 18294 | + inode = au_new_inode(dentry, /*must_new*/0); |
c1595e42 JR |
18295 | + if (IS_ERR(inode)) { |
18296 | + ret = (void *)inode; | |
18297 | + inode = NULL; | |
18298 | + goto out_unlock; | |
18299 | + } | |
9dbd164d | 18300 | + } |
4a4d8108 | 18301 | + |
c1595e42 JR |
18302 | + if (inode) |
18303 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 18304 | + ret = d_splice_alias(inode, dentry); |
537831f9 AM |
18305 | +#if 0 |
18306 | + if (unlikely(d_need_lookup(dentry))) { | |
18307 | + spin_lock(&dentry->d_lock); | |
18308 | + dentry->d_flags &= ~DCACHE_NEED_LOOKUP; | |
18309 | + spin_unlock(&dentry->d_lock); | |
18310 | + } else | |
18311 | +#endif | |
c1595e42 | 18312 | + if (inode) { |
2000de60 | 18313 | + if (!IS_ERR(ret)) { |
c1595e42 | 18314 | + iput(inode); |
2000de60 JR |
18315 | + if (ret && ret != dentry) |
18316 | + ii_write_unlock(inode); | |
18317 | + } else { | |
c1595e42 JR |
18318 | + ii_write_unlock(inode); |
18319 | + iput(inode); | |
18320 | + inode = NULL; | |
18321 | + } | |
7f207e10 | 18322 | + } |
1facf9fc | 18323 | + |
4f0767ce | 18324 | +out_unlock: |
4a4d8108 | 18325 | + di_write_unlock(dentry); |
2dfbb274 | 18326 | + if (inode) { |
1716fcea AM |
18327 | + /* verbose coding for lock class name */ |
18328 | + if (unlikely(S_ISLNK(inode->i_mode))) | |
18329 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18330 | + au_lc_key + AuLcSymlink_DIINFO); | |
18331 | + else if (unlikely(S_ISDIR(inode->i_mode))) | |
18332 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18333 | + au_lc_key + AuLcDir_DIINFO); | |
18334 | + else /* likely */ | |
18335 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18336 | + au_lc_key + AuLcNonDir_DIINFO); | |
9dbd164d | 18337 | + } |
7f207e10 | 18338 | +out_si: |
4a4d8108 | 18339 | + si_read_unlock(sb); |
7f207e10 | 18340 | +out: |
4a4d8108 AM |
18341 | + return ret; |
18342 | +} | |
1facf9fc | 18343 | + |
4a4d8108 | 18344 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18345 | + |
b912730e AM |
18346 | +struct aopen_node { |
18347 | + struct hlist_node hlist; | |
18348 | + struct file *file, *h_file; | |
18349 | +}; | |
18350 | + | |
18351 | +static int au_do_aopen(struct inode *inode, struct file *file) | |
18352 | +{ | |
18353 | + struct au_sphlhead *aopen; | |
18354 | + struct aopen_node *node; | |
18355 | + struct au_do_open_args args = { | |
18356 | + .no_lock = 1, | |
18357 | + .open = au_do_open_nondir | |
18358 | + }; | |
18359 | + | |
18360 | + aopen = &au_sbi(inode->i_sb)->si_aopen; | |
18361 | + spin_lock(&aopen->spin); | |
18362 | + hlist_for_each_entry(node, &aopen->head, hlist) | |
18363 | + if (node->file == file) { | |
18364 | + args.h_file = node->h_file; | |
18365 | + break; | |
18366 | + } | |
18367 | + spin_unlock(&aopen->spin); | |
18368 | + /* AuDebugOn(!args.h_file); */ | |
18369 | + | |
18370 | + return au_do_open(file, &args); | |
18371 | +} | |
18372 | + | |
18373 | +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry, | |
18374 | + struct file *file, unsigned int open_flag, | |
18375 | + umode_t create_mode, int *opened) | |
18376 | +{ | |
18377 | + int err, h_opened = *opened; | |
18378 | + struct dentry *parent; | |
18379 | + struct dentry *d; | |
18380 | + struct au_sphlhead *aopen; | |
18381 | + struct vfsub_aopen_args args = { | |
18382 | + .open_flag = open_flag, | |
18383 | + .create_mode = create_mode, | |
18384 | + .opened = &h_opened | |
18385 | + }; | |
18386 | + struct aopen_node aopen_node = { | |
18387 | + .file = file | |
18388 | + }; | |
18389 | + | |
18390 | + IMustLock(dir); | |
18391 | + AuDbg("open_flag 0x%x\n", open_flag); | |
18392 | + AuDbgDentry(dentry); | |
18393 | + | |
18394 | + err = 0; | |
18395 | + if (!au_di(dentry)) { | |
18396 | + d = aufs_lookup(dir, dentry, /*flags*/0); | |
18397 | + if (IS_ERR(d)) { | |
18398 | + err = PTR_ERR(d); | |
18399 | + goto out; | |
18400 | + } else if (d) { | |
18401 | + /* | |
18402 | + * obsoleted dentry found. | |
18403 | + * another error will be returned later. | |
18404 | + */ | |
18405 | + d_drop(d); | |
18406 | + dput(d); | |
18407 | + AuDbgDentry(d); | |
18408 | + } | |
18409 | + AuDbgDentry(dentry); | |
18410 | + } | |
18411 | + | |
18412 | + if (d_is_positive(dentry) | |
18413 | + || d_unhashed(dentry) | |
18414 | + || d_unlinked(dentry) | |
18415 | + || !(open_flag & O_CREAT)) | |
18416 | + goto out_no_open; | |
18417 | + | |
18418 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); | |
18419 | + if (unlikely(err)) | |
18420 | + goto out; | |
18421 | + | |
18422 | + parent = dentry->d_parent; /* dir is locked */ | |
18423 | + di_write_lock_parent(parent); | |
18424 | + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0); | |
18425 | + if (unlikely(err)) | |
18426 | + goto out_unlock; | |
18427 | + | |
18428 | + AuDbgDentry(dentry); | |
18429 | + if (d_is_positive(dentry)) | |
18430 | + goto out_unlock; | |
18431 | + | |
18432 | + args.file = get_empty_filp(); | |
18433 | + err = PTR_ERR(args.file); | |
18434 | + if (IS_ERR(args.file)) | |
18435 | + goto out_unlock; | |
18436 | + | |
18437 | + args.file->f_flags = file->f_flags; | |
18438 | + err = au_aopen_or_create(dir, dentry, &args); | |
18439 | + AuTraceErr(err); | |
18440 | + AuDbgFile(args.file); | |
18441 | + if (unlikely(err < 0)) { | |
18442 | + if (h_opened & FILE_OPENED) | |
18443 | + fput(args.file); | |
18444 | + else | |
18445 | + put_filp(args.file); | |
18446 | + goto out_unlock; | |
18447 | + } | |
18448 | + | |
18449 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
18450 | + *opened |= FILE_CREATED; | |
18451 | + if (h_opened & FILE_OPENED) | |
18452 | + aopen_node.h_file = args.file; | |
18453 | + else { | |
18454 | + put_filp(args.file); | |
18455 | + args.file = NULL; | |
18456 | + } | |
18457 | + aopen = &au_sbi(dir->i_sb)->si_aopen; | |
18458 | + au_sphl_add(&aopen_node.hlist, aopen); | |
18459 | + err = finish_open(file, dentry, au_do_aopen, opened); | |
18460 | + au_sphl_del(&aopen_node.hlist, aopen); | |
18461 | + AuTraceErr(err); | |
18462 | + AuDbgFile(file); | |
18463 | + if (aopen_node.h_file) | |
18464 | + fput(aopen_node.h_file); | |
18465 | + | |
18466 | +out_unlock: | |
18467 | + di_write_unlock(parent); | |
18468 | + aufs_read_unlock(dentry, AuLock_DW); | |
18469 | + AuDbgDentry(dentry); | |
18470 | + if (unlikely(err)) | |
18471 | + goto out; | |
18472 | +out_no_open: | |
18473 | + if (!err && !(*opened & FILE_CREATED)) { | |
18474 | + AuLabel(out_no_open); | |
18475 | + dget(dentry); | |
18476 | + err = finish_no_open(file, dentry); | |
18477 | + } | |
18478 | +out: | |
18479 | + AuDbg("%pd%s%s\n", dentry, | |
18480 | + (*opened & FILE_CREATED) ? " created" : "", | |
18481 | + (*opened & FILE_OPENED) ? " opened" : ""); | |
18482 | + AuTraceErr(err); | |
18483 | + return err; | |
18484 | +} | |
18485 | + | |
18486 | + | |
18487 | +/* ---------------------------------------------------------------------- */ | |
18488 | + | |
4a4d8108 AM |
18489 | +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent, |
18490 | + const unsigned char add_entry, aufs_bindex_t bcpup, | |
18491 | + aufs_bindex_t bstart) | |
18492 | +{ | |
18493 | + int err; | |
18494 | + struct dentry *h_parent; | |
18495 | + struct inode *h_dir; | |
1facf9fc | 18496 | + |
027c5e7a | 18497 | + if (add_entry) |
5527c038 | 18498 | + IMustLock(d_inode(parent)); |
027c5e7a | 18499 | + else |
4a4d8108 AM |
18500 | + di_write_lock_parent(parent); |
18501 | + | |
18502 | + err = 0; | |
18503 | + if (!au_h_dptr(parent, bcpup)) { | |
c2b27bf2 AM |
18504 | + if (bstart > bcpup) |
18505 | + err = au_cpup_dirs(dentry, bcpup); | |
18506 | + else if (bstart < bcpup) | |
4a4d8108 AM |
18507 | + err = au_cpdown_dirs(dentry, bcpup); |
18508 | + else | |
c2b27bf2 | 18509 | + BUG(); |
4a4d8108 | 18510 | + } |
38d290e6 | 18511 | + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) { |
4a4d8108 | 18512 | + h_parent = au_h_dptr(parent, bcpup); |
5527c038 | 18513 | + h_dir = d_inode(h_parent); |
4a4d8108 | 18514 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); |
7e9cd9fe | 18515 | + err = au_lkup_neg(dentry, bcpup, /*wh*/0); |
4a4d8108 AM |
18516 | + /* todo: no unlock here */ |
18517 | + mutex_unlock(&h_dir->i_mutex); | |
027c5e7a AM |
18518 | + |
18519 | + AuDbg("bcpup %d\n", bcpup); | |
18520 | + if (!err) { | |
5527c038 | 18521 | + if (d_really_is_negative(dentry)) |
027c5e7a | 18522 | + au_set_h_dptr(dentry, bstart, NULL); |
4a4d8108 AM |
18523 | + au_update_dbrange(dentry, /*do_put_zero*/0); |
18524 | + } | |
1308ab2a | 18525 | + } |
1facf9fc | 18526 | + |
4a4d8108 AM |
18527 | + if (!add_entry) |
18528 | + di_write_unlock(parent); | |
18529 | + if (!err) | |
18530 | + err = bcpup; /* success */ | |
1308ab2a | 18531 | + |
027c5e7a | 18532 | + AuTraceErr(err); |
4a4d8108 AM |
18533 | + return err; |
18534 | +} | |
1facf9fc | 18535 | + |
4a4d8108 AM |
18536 | +/* |
18537 | + * decide the branch and the parent dir where we will create a new entry. | |
18538 | + * returns new bindex or an error. | |
18539 | + * copyup the parent dir if needed. | |
18540 | + */ | |
18541 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
18542 | + struct au_wr_dir_args *args) | |
18543 | +{ | |
18544 | + int err; | |
392086de | 18545 | + unsigned int flags; |
4a4d8108 | 18546 | + aufs_bindex_t bcpup, bstart, src_bstart; |
86dc4139 AM |
18547 | + const unsigned char add_entry |
18548 | + = au_ftest_wrdir(args->flags, ADD_ENTRY) | |
38d290e6 | 18549 | + | au_ftest_wrdir(args->flags, TMPFILE); |
4a4d8108 AM |
18550 | + struct super_block *sb; |
18551 | + struct dentry *parent; | |
18552 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 18553 | + |
4a4d8108 AM |
18554 | + sb = dentry->d_sb; |
18555 | + sbinfo = au_sbi(sb); | |
18556 | + parent = dget_parent(dentry); | |
18557 | + bstart = au_dbstart(dentry); | |
18558 | + bcpup = bstart; | |
18559 | + if (args->force_btgt < 0) { | |
18560 | + if (src_dentry) { | |
18561 | + src_bstart = au_dbstart(src_dentry); | |
18562 | + if (src_bstart < bstart) | |
18563 | + bcpup = src_bstart; | |
18564 | + } else if (add_entry) { | |
392086de AM |
18565 | + flags = 0; |
18566 | + if (au_ftest_wrdir(args->flags, ISDIR)) | |
18567 | + au_fset_wbr(flags, DIR); | |
18568 | + err = AuWbrCreate(sbinfo, dentry, flags); | |
4a4d8108 AM |
18569 | + bcpup = err; |
18570 | + } | |
1facf9fc | 18571 | + |
5527c038 | 18572 | + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) { |
4a4d8108 AM |
18573 | + if (add_entry) |
18574 | + err = AuWbrCopyup(sbinfo, dentry); | |
18575 | + else { | |
18576 | + if (!IS_ROOT(dentry)) { | |
18577 | + di_read_lock_parent(parent, !AuLock_IR); | |
18578 | + err = AuWbrCopyup(sbinfo, dentry); | |
18579 | + di_read_unlock(parent, !AuLock_IR); | |
18580 | + } else | |
18581 | + err = AuWbrCopyup(sbinfo, dentry); | |
18582 | + } | |
18583 | + bcpup = err; | |
18584 | + if (unlikely(err < 0)) | |
18585 | + goto out; | |
18586 | + } | |
18587 | + } else { | |
18588 | + bcpup = args->force_btgt; | |
5527c038 | 18589 | + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry))); |
1308ab2a | 18590 | + } |
027c5e7a | 18591 | + |
4a4d8108 AM |
18592 | + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup); |
18593 | + err = bcpup; | |
18594 | + if (bcpup == bstart) | |
18595 | + goto out; /* success */ | |
4a4d8108 AM |
18596 | + |
18597 | + /* copyup the new parent into the branch we process */ | |
18598 | + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart); | |
027c5e7a | 18599 | + if (err >= 0) { |
5527c038 | 18600 | + if (d_really_is_negative(dentry)) { |
027c5e7a AM |
18601 | + au_set_h_dptr(dentry, bstart, NULL); |
18602 | + au_set_dbstart(dentry, bcpup); | |
18603 | + au_set_dbend(dentry, bcpup); | |
18604 | + } | |
38d290e6 JR |
18605 | + AuDebugOn(add_entry |
18606 | + && !au_ftest_wrdir(args->flags, TMPFILE) | |
18607 | + && !au_h_dptr(dentry, bcpup)); | |
027c5e7a | 18608 | + } |
86dc4139 AM |
18609 | + |
18610 | +out: | |
18611 | + dput(parent); | |
18612 | + return err; | |
18613 | +} | |
18614 | + | |
18615 | +/* ---------------------------------------------------------------------- */ | |
18616 | + | |
18617 | +void au_pin_hdir_unlock(struct au_pin *p) | |
18618 | +{ | |
18619 | + if (p->hdir) | |
18620 | + au_hn_imtx_unlock(p->hdir); | |
18621 | +} | |
18622 | + | |
c1595e42 | 18623 | +int au_pin_hdir_lock(struct au_pin *p) |
86dc4139 AM |
18624 | +{ |
18625 | + int err; | |
18626 | + | |
18627 | + err = 0; | |
18628 | + if (!p->hdir) | |
18629 | + goto out; | |
18630 | + | |
18631 | + /* even if an error happens later, keep this lock */ | |
18632 | + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi); | |
18633 | + | |
18634 | + err = -EBUSY; | |
5527c038 | 18635 | + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent))) |
86dc4139 AM |
18636 | + goto out; |
18637 | + | |
18638 | + err = 0; | |
18639 | + if (p->h_dentry) | |
18640 | + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode, | |
18641 | + p->h_parent, p->br); | |
18642 | + | |
18643 | +out: | |
18644 | + return err; | |
18645 | +} | |
18646 | + | |
18647 | +int au_pin_hdir_relock(struct au_pin *p) | |
18648 | +{ | |
18649 | + int err, i; | |
18650 | + struct inode *h_i; | |
18651 | + struct dentry *h_d[] = { | |
18652 | + p->h_dentry, | |
18653 | + p->h_parent | |
18654 | + }; | |
18655 | + | |
18656 | + err = au_pin_hdir_lock(p); | |
18657 | + if (unlikely(err)) | |
18658 | + goto out; | |
18659 | + | |
18660 | + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) { | |
18661 | + if (!h_d[i]) | |
18662 | + continue; | |
5527c038 JR |
18663 | + if (d_is_positive(h_d[i])) { |
18664 | + h_i = d_inode(h_d[i]); | |
86dc4139 | 18665 | + err = !h_i->i_nlink; |
5527c038 | 18666 | + } |
86dc4139 AM |
18667 | + } |
18668 | + | |
18669 | +out: | |
18670 | + return err; | |
18671 | +} | |
18672 | + | |
18673 | +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task) | |
18674 | +{ | |
18675 | +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP) | |
18676 | + p->hdir->hi_inode->i_mutex.owner = task; | |
18677 | +#endif | |
18678 | +} | |
18679 | + | |
18680 | +void au_pin_hdir_acquire_nest(struct au_pin *p) | |
18681 | +{ | |
18682 | + if (p->hdir) { | |
18683 | + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map, | |
18684 | + p->lsc_hi, 0, NULL, _RET_IP_); | |
18685 | + au_pin_hdir_set_owner(p, current); | |
18686 | + } | |
dece6358 | 18687 | +} |
1facf9fc | 18688 | + |
86dc4139 AM |
18689 | +void au_pin_hdir_release(struct au_pin *p) |
18690 | +{ | |
18691 | + if (p->hdir) { | |
18692 | + au_pin_hdir_set_owner(p, p->task); | |
18693 | + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_); | |
18694 | + } | |
18695 | +} | |
1308ab2a | 18696 | + |
4a4d8108 | 18697 | +struct dentry *au_pinned_h_parent(struct au_pin *pin) |
1308ab2a | 18698 | +{ |
4a4d8108 AM |
18699 | + if (pin && pin->parent) |
18700 | + return au_h_dptr(pin->parent, pin->bindex); | |
18701 | + return NULL; | |
dece6358 | 18702 | +} |
1facf9fc | 18703 | + |
4a4d8108 | 18704 | +void au_unpin(struct au_pin *p) |
dece6358 | 18705 | +{ |
86dc4139 AM |
18706 | + if (p->hdir) |
18707 | + au_pin_hdir_unlock(p); | |
e49829fe | 18708 | + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE)) |
b4510431 | 18709 | + vfsub_mnt_drop_write(p->h_mnt); |
4a4d8108 AM |
18710 | + if (!p->hdir) |
18711 | + return; | |
1facf9fc | 18712 | + |
4a4d8108 AM |
18713 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18714 | + di_read_unlock(p->parent, AuLock_IR); | |
18715 | + iput(p->hdir->hi_inode); | |
18716 | + dput(p->parent); | |
18717 | + p->parent = NULL; | |
18718 | + p->hdir = NULL; | |
18719 | + p->h_mnt = NULL; | |
86dc4139 | 18720 | + /* do not clear p->task */ |
4a4d8108 | 18721 | +} |
1308ab2a | 18722 | + |
4a4d8108 AM |
18723 | +int au_do_pin(struct au_pin *p) |
18724 | +{ | |
18725 | + int err; | |
18726 | + struct super_block *sb; | |
4a4d8108 AM |
18727 | + struct inode *h_dir; |
18728 | + | |
18729 | + err = 0; | |
18730 | + sb = p->dentry->d_sb; | |
86dc4139 | 18731 | + p->br = au_sbr(sb, p->bindex); |
4a4d8108 AM |
18732 | + if (IS_ROOT(p->dentry)) { |
18733 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { | |
86dc4139 | 18734 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 18735 | + err = vfsub_mnt_want_write(p->h_mnt); |
4a4d8108 AM |
18736 | + if (unlikely(err)) { |
18737 | + au_fclr_pin(p->flags, MNT_WRITE); | |
18738 | + goto out_err; | |
18739 | + } | |
18740 | + } | |
dece6358 | 18741 | + goto out; |
1facf9fc | 18742 | + } |
18743 | + | |
86dc4139 | 18744 | + p->h_dentry = NULL; |
4a4d8108 | 18745 | + if (p->bindex <= au_dbend(p->dentry)) |
86dc4139 | 18746 | + p->h_dentry = au_h_dptr(p->dentry, p->bindex); |
dece6358 | 18747 | + |
4a4d8108 AM |
18748 | + p->parent = dget_parent(p->dentry); |
18749 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) | |
18750 | + di_read_lock(p->parent, AuLock_IR, p->lsc_di); | |
dece6358 | 18751 | + |
4a4d8108 | 18752 | + h_dir = NULL; |
86dc4139 | 18753 | + p->h_parent = au_h_dptr(p->parent, p->bindex); |
5527c038 | 18754 | + p->hdir = au_hi(d_inode(p->parent), p->bindex); |
4a4d8108 AM |
18755 | + if (p->hdir) |
18756 | + h_dir = p->hdir->hi_inode; | |
dece6358 | 18757 | + |
b752ccd1 AM |
18758 | + /* |
18759 | + * udba case, or | |
18760 | + * if DI_LOCKED is not set, then p->parent may be different | |
18761 | + * and h_parent can be NULL. | |
18762 | + */ | |
86dc4139 | 18763 | + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) { |
e49829fe | 18764 | + err = -EBUSY; |
4a4d8108 AM |
18765 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18766 | + di_read_unlock(p->parent, AuLock_IR); | |
18767 | + dput(p->parent); | |
18768 | + p->parent = NULL; | |
18769 | + goto out_err; | |
18770 | + } | |
1308ab2a | 18771 | + |
4a4d8108 | 18772 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { |
86dc4139 | 18773 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 18774 | + err = vfsub_mnt_want_write(p->h_mnt); |
dece6358 | 18775 | + if (unlikely(err)) { |
4a4d8108 | 18776 | + au_fclr_pin(p->flags, MNT_WRITE); |
86dc4139 AM |
18777 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18778 | + di_read_unlock(p->parent, AuLock_IR); | |
18779 | + dput(p->parent); | |
18780 | + p->parent = NULL; | |
18781 | + goto out_err; | |
dece6358 AM |
18782 | + } |
18783 | + } | |
4a4d8108 | 18784 | + |
86dc4139 AM |
18785 | + au_igrab(h_dir); |
18786 | + err = au_pin_hdir_lock(p); | |
18787 | + if (!err) | |
18788 | + goto out; /* success */ | |
18789 | + | |
076b876e AM |
18790 | + au_unpin(p); |
18791 | + | |
4f0767ce | 18792 | +out_err: |
4a4d8108 AM |
18793 | + pr_err("err %d\n", err); |
18794 | + err = au_busy_or_stale(); | |
4f0767ce | 18795 | +out: |
1facf9fc | 18796 | + return err; |
18797 | +} | |
18798 | + | |
4a4d8108 AM |
18799 | +void au_pin_init(struct au_pin *p, struct dentry *dentry, |
18800 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
18801 | + unsigned int udba, unsigned char flags) | |
18802 | +{ | |
18803 | + p->dentry = dentry; | |
18804 | + p->udba = udba; | |
18805 | + p->lsc_di = lsc_di; | |
18806 | + p->lsc_hi = lsc_hi; | |
18807 | + p->flags = flags; | |
18808 | + p->bindex = bindex; | |
18809 | + | |
18810 | + p->parent = NULL; | |
18811 | + p->hdir = NULL; | |
18812 | + p->h_mnt = NULL; | |
86dc4139 AM |
18813 | + |
18814 | + p->h_dentry = NULL; | |
18815 | + p->h_parent = NULL; | |
18816 | + p->br = NULL; | |
18817 | + p->task = current; | |
4a4d8108 AM |
18818 | +} |
18819 | + | |
18820 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
18821 | + unsigned int udba, unsigned char flags) | |
18822 | +{ | |
18823 | + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2, | |
18824 | + udba, flags); | |
18825 | + return au_do_pin(pin); | |
18826 | +} | |
18827 | + | |
dece6358 AM |
18828 | +/* ---------------------------------------------------------------------- */ |
18829 | + | |
1308ab2a | 18830 | +/* |
4a4d8108 AM |
18831 | + * ->setattr() and ->getattr() are called in various cases. |
18832 | + * chmod, stat: dentry is revalidated. | |
18833 | + * fchmod, fstat: file and dentry are not revalidated, additionally they may be | |
18834 | + * unhashed. | |
18835 | + * for ->setattr(), ia->ia_file is passed from ftruncate only. | |
1308ab2a | 18836 | + */ |
027c5e7a | 18837 | +/* todo: consolidate with do_refresh() and simple_reval_dpath() */ |
c1595e42 | 18838 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen) |
1facf9fc | 18839 | +{ |
4a4d8108 | 18840 | + int err; |
4a4d8108 | 18841 | + struct dentry *parent; |
1facf9fc | 18842 | + |
1308ab2a | 18843 | + err = 0; |
027c5e7a | 18844 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 AM |
18845 | + parent = dget_parent(dentry); |
18846 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 18847 | + err = au_refresh_dentry(dentry, parent); |
4a4d8108 AM |
18848 | + di_read_unlock(parent, AuLock_IR); |
18849 | + dput(parent); | |
dece6358 | 18850 | + } |
1facf9fc | 18851 | + |
4a4d8108 | 18852 | + AuTraceErr(err); |
1308ab2a | 18853 | + return err; |
18854 | +} | |
dece6358 | 18855 | + |
c1595e42 JR |
18856 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, |
18857 | + struct au_icpup_args *a) | |
1308ab2a | 18858 | +{ |
18859 | + int err; | |
4a4d8108 | 18860 | + loff_t sz; |
e49829fe | 18861 | + aufs_bindex_t bstart, ibstart; |
4a4d8108 AM |
18862 | + struct dentry *hi_wh, *parent; |
18863 | + struct inode *inode; | |
4a4d8108 AM |
18864 | + struct au_wr_dir_args wr_dir_args = { |
18865 | + .force_btgt = -1, | |
18866 | + .flags = 0 | |
18867 | + }; | |
18868 | + | |
2000de60 | 18869 | + if (d_is_dir(dentry)) |
4a4d8108 AM |
18870 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
18871 | + /* plink or hi_wh() case */ | |
2000de60 | 18872 | + bstart = au_dbstart(dentry); |
5527c038 | 18873 | + inode = d_inode(dentry); |
e49829fe | 18874 | + ibstart = au_ibstart(inode); |
027c5e7a | 18875 | + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode)) |
e49829fe | 18876 | + wr_dir_args.force_btgt = ibstart; |
4a4d8108 AM |
18877 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
18878 | + if (unlikely(err < 0)) | |
18879 | + goto out; | |
18880 | + a->btgt = err; | |
18881 | + if (err != bstart) | |
18882 | + au_fset_icpup(a->flags, DID_CPUP); | |
18883 | + | |
18884 | + err = 0; | |
18885 | + a->pin_flags = AuPin_MNT_WRITE; | |
18886 | + parent = NULL; | |
18887 | + if (!IS_ROOT(dentry)) { | |
18888 | + au_fset_pin(a->pin_flags, DI_LOCKED); | |
18889 | + parent = dget_parent(dentry); | |
18890 | + di_write_lock_parent(parent); | |
18891 | + } | |
18892 | + | |
18893 | + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags); | |
18894 | + if (unlikely(err)) | |
18895 | + goto out_parent; | |
18896 | + | |
18897 | + a->h_path.dentry = au_h_dptr(dentry, bstart); | |
4a4d8108 | 18898 | + sz = -1; |
5527c038 | 18899 | + a->h_inode = d_inode(a->h_path.dentry); |
c1595e42 JR |
18900 | + if (ia && (ia->ia_valid & ATTR_SIZE)) { |
18901 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
18902 | + if (ia->ia_size < i_size_read(a->h_inode)) | |
18903 | + sz = ia->ia_size; | |
18904 | + mutex_unlock(&a->h_inode->i_mutex); | |
18905 | + } | |
4a4d8108 | 18906 | + |
4a4d8108 | 18907 | + hi_wh = NULL; |
027c5e7a | 18908 | + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) { |
4a4d8108 AM |
18909 | + hi_wh = au_hi_wh(inode, a->btgt); |
18910 | + if (!hi_wh) { | |
c2b27bf2 AM |
18911 | + struct au_cp_generic cpg = { |
18912 | + .dentry = dentry, | |
18913 | + .bdst = a->btgt, | |
18914 | + .bsrc = -1, | |
18915 | + .len = sz, | |
18916 | + .pin = &a->pin | |
18917 | + }; | |
18918 | + err = au_sio_cpup_wh(&cpg, /*file*/NULL); | |
4a4d8108 AM |
18919 | + if (unlikely(err)) |
18920 | + goto out_unlock; | |
18921 | + hi_wh = au_hi_wh(inode, a->btgt); | |
18922 | + /* todo: revalidate hi_wh? */ | |
18923 | + } | |
18924 | + } | |
18925 | + | |
18926 | + if (parent) { | |
18927 | + au_pin_set_parent_lflag(&a->pin, /*lflag*/0); | |
18928 | + di_downgrade_lock(parent, AuLock_IR); | |
18929 | + dput(parent); | |
18930 | + parent = NULL; | |
18931 | + } | |
18932 | + if (!au_ftest_icpup(a->flags, DID_CPUP)) | |
18933 | + goto out; /* success */ | |
18934 | + | |
18935 | + if (!d_unhashed(dentry)) { | |
c2b27bf2 AM |
18936 | + struct au_cp_generic cpg = { |
18937 | + .dentry = dentry, | |
18938 | + .bdst = a->btgt, | |
18939 | + .bsrc = bstart, | |
18940 | + .len = sz, | |
18941 | + .pin = &a->pin, | |
18942 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
18943 | + }; | |
18944 | + err = au_sio_cpup_simple(&cpg); | |
4a4d8108 AM |
18945 | + if (!err) |
18946 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
18947 | + } else if (!hi_wh) | |
18948 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
18949 | + else | |
18950 | + a->h_path.dentry = hi_wh; /* do not dget here */ | |
1308ab2a | 18951 | + |
4f0767ce | 18952 | +out_unlock: |
5527c038 | 18953 | + a->h_inode = d_inode(a->h_path.dentry); |
86dc4139 | 18954 | + if (!err) |
dece6358 | 18955 | + goto out; /* success */ |
4a4d8108 | 18956 | + au_unpin(&a->pin); |
4f0767ce | 18957 | +out_parent: |
4a4d8108 AM |
18958 | + if (parent) { |
18959 | + di_write_unlock(parent); | |
18960 | + dput(parent); | |
18961 | + } | |
4f0767ce | 18962 | +out: |
86dc4139 AM |
18963 | + if (!err) |
18964 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
1facf9fc | 18965 | + return err; |
18966 | +} | |
18967 | + | |
4a4d8108 | 18968 | +static int aufs_setattr(struct dentry *dentry, struct iattr *ia) |
1facf9fc | 18969 | +{ |
4a4d8108 | 18970 | + int err; |
523b37e3 | 18971 | + struct inode *inode, *delegated; |
4a4d8108 AM |
18972 | + struct super_block *sb; |
18973 | + struct file *file; | |
18974 | + struct au_icpup_args *a; | |
1facf9fc | 18975 | + |
5527c038 | 18976 | + inode = d_inode(dentry); |
4a4d8108 | 18977 | + IMustLock(inode); |
dece6358 | 18978 | + |
4a4d8108 AM |
18979 | + err = -ENOMEM; |
18980 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
18981 | + if (unlikely(!a)) | |
18982 | + goto out; | |
1facf9fc | 18983 | + |
4a4d8108 AM |
18984 | + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
18985 | + ia->ia_valid &= ~ATTR_MODE; | |
dece6358 | 18986 | + |
4a4d8108 AM |
18987 | + file = NULL; |
18988 | + sb = dentry->d_sb; | |
e49829fe JR |
18989 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
18990 | + if (unlikely(err)) | |
18991 | + goto out_kfree; | |
18992 | + | |
4a4d8108 AM |
18993 | + if (ia->ia_valid & ATTR_FILE) { |
18994 | + /* currently ftruncate(2) only */ | |
7e9cd9fe | 18995 | + AuDebugOn(!d_is_reg(dentry)); |
4a4d8108 AM |
18996 | + file = ia->ia_file; |
18997 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); | |
18998 | + if (unlikely(err)) | |
18999 | + goto out_si; | |
19000 | + ia->ia_file = au_hf_top(file); | |
19001 | + a->udba = AuOpt_UDBA_NONE; | |
19002 | + } else { | |
19003 | + /* fchmod() doesn't pass ia_file */ | |
19004 | + a->udba = au_opt_udba(sb); | |
027c5e7a AM |
19005 | + di_write_lock_child(dentry); |
19006 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
4a4d8108 AM |
19007 | + if (d_unhashed(dentry)) |
19008 | + a->udba = AuOpt_UDBA_NONE; | |
4a4d8108 AM |
19009 | + if (a->udba != AuOpt_UDBA_NONE) { |
19010 | + AuDebugOn(IS_ROOT(dentry)); | |
19011 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
19012 | + if (unlikely(err)) | |
19013 | + goto out_dentry; | |
19014 | + } | |
dece6358 | 19015 | + } |
dece6358 | 19016 | + |
4a4d8108 AM |
19017 | + err = au_pin_and_icpup(dentry, ia, a); |
19018 | + if (unlikely(err < 0)) | |
19019 | + goto out_dentry; | |
19020 | + if (au_ftest_icpup(a->flags, DID_CPUP)) { | |
19021 | + ia->ia_file = NULL; | |
19022 | + ia->ia_valid &= ~ATTR_FILE; | |
1308ab2a | 19023 | + } |
dece6358 | 19024 | + |
4a4d8108 AM |
19025 | + a->h_path.mnt = au_sbr_mnt(sb, a->btgt); |
19026 | + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME)) | |
19027 | + == (ATTR_MODE | ATTR_CTIME)) { | |
7eafdf33 | 19028 | + err = security_path_chmod(&a->h_path, ia->ia_mode); |
4a4d8108 AM |
19029 | + if (unlikely(err)) |
19030 | + goto out_unlock; | |
19031 | + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID)) | |
19032 | + && (ia->ia_valid & ATTR_CTIME)) { | |
86dc4139 | 19033 | + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid); |
4a4d8108 AM |
19034 | + if (unlikely(err)) |
19035 | + goto out_unlock; | |
19036 | + } | |
dece6358 | 19037 | + |
4a4d8108 AM |
19038 | + if (ia->ia_valid & ATTR_SIZE) { |
19039 | + struct file *f; | |
1308ab2a | 19040 | + |
953406b4 | 19041 | + if (ia->ia_size < i_size_read(inode)) |
4a4d8108 | 19042 | + /* unmap only */ |
953406b4 | 19043 | + truncate_setsize(inode, ia->ia_size); |
1308ab2a | 19044 | + |
4a4d8108 AM |
19045 | + f = NULL; |
19046 | + if (ia->ia_valid & ATTR_FILE) | |
19047 | + f = ia->ia_file; | |
19048 | + mutex_unlock(&a->h_inode->i_mutex); | |
19049 | + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f); | |
19050 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
523b37e3 AM |
19051 | + } else { |
19052 | + delegated = NULL; | |
19053 | + while (1) { | |
19054 | + err = vfsub_notify_change(&a->h_path, ia, &delegated); | |
19055 | + if (delegated) { | |
19056 | + err = break_deleg_wait(&delegated); | |
19057 | + if (!err) | |
19058 | + continue; | |
19059 | + } | |
19060 | + break; | |
19061 | + } | |
19062 | + } | |
4a4d8108 AM |
19063 | + if (!err) |
19064 | + au_cpup_attr_changeable(inode); | |
1308ab2a | 19065 | + |
4f0767ce | 19066 | +out_unlock: |
4a4d8108 AM |
19067 | + mutex_unlock(&a->h_inode->i_mutex); |
19068 | + au_unpin(&a->pin); | |
027c5e7a AM |
19069 | + if (unlikely(err)) |
19070 | + au_update_dbstart(dentry); | |
4f0767ce | 19071 | +out_dentry: |
4a4d8108 AM |
19072 | + di_write_unlock(dentry); |
19073 | + if (file) { | |
19074 | + fi_write_unlock(file); | |
19075 | + ia->ia_file = file; | |
19076 | + ia->ia_valid |= ATTR_FILE; | |
19077 | + } | |
4f0767ce | 19078 | +out_si: |
4a4d8108 | 19079 | + si_read_unlock(sb); |
e49829fe | 19080 | +out_kfree: |
4a4d8108 | 19081 | + kfree(a); |
4f0767ce | 19082 | +out: |
4a4d8108 AM |
19083 | + AuTraceErr(err); |
19084 | + return err; | |
1facf9fc | 19085 | +} |
19086 | + | |
c1595e42 JR |
19087 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) |
19088 | +static int au_h_path_to_set_attr(struct dentry *dentry, | |
19089 | + struct au_icpup_args *a, struct path *h_path) | |
19090 | +{ | |
19091 | + int err; | |
19092 | + struct super_block *sb; | |
19093 | + | |
19094 | + sb = dentry->d_sb; | |
19095 | + a->udba = au_opt_udba(sb); | |
19096 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
19097 | + if (d_unhashed(dentry)) | |
19098 | + a->udba = AuOpt_UDBA_NONE; | |
19099 | + if (a->udba != AuOpt_UDBA_NONE) { | |
19100 | + AuDebugOn(IS_ROOT(dentry)); | |
19101 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
19102 | + if (unlikely(err)) | |
19103 | + goto out; | |
19104 | + } | |
19105 | + err = au_pin_and_icpup(dentry, /*ia*/NULL, a); | |
19106 | + if (unlikely(err < 0)) | |
19107 | + goto out; | |
19108 | + | |
19109 | + h_path->dentry = a->h_path.dentry; | |
19110 | + h_path->mnt = au_sbr_mnt(sb, a->btgt); | |
19111 | + | |
19112 | +out: | |
19113 | + return err; | |
19114 | +} | |
19115 | + | |
19116 | +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg) | |
19117 | +{ | |
19118 | + int err; | |
19119 | + struct path h_path; | |
19120 | + struct super_block *sb; | |
19121 | + struct au_icpup_args *a; | |
19122 | + struct inode *inode, *h_inode; | |
19123 | + | |
5527c038 | 19124 | + inode = d_inode(dentry); |
c1595e42 JR |
19125 | + IMustLock(inode); |
19126 | + | |
19127 | + err = -ENOMEM; | |
19128 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
19129 | + if (unlikely(!a)) | |
19130 | + goto out; | |
19131 | + | |
19132 | + sb = dentry->d_sb; | |
19133 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19134 | + if (unlikely(err)) | |
19135 | + goto out_kfree; | |
19136 | + | |
19137 | + h_path.dentry = NULL; /* silence gcc */ | |
19138 | + di_write_lock_child(dentry); | |
19139 | + err = au_h_path_to_set_attr(dentry, a, &h_path); | |
19140 | + if (unlikely(err)) | |
19141 | + goto out_di; | |
19142 | + | |
19143 | + mutex_unlock(&a->h_inode->i_mutex); | |
19144 | + switch (arg->type) { | |
19145 | + case AU_XATTR_SET: | |
19146 | + err = vfsub_setxattr(h_path.dentry, | |
19147 | + arg->u.set.name, arg->u.set.value, | |
19148 | + arg->u.set.size, arg->u.set.flags); | |
19149 | + break; | |
19150 | + case AU_XATTR_REMOVE: | |
19151 | + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name); | |
19152 | + break; | |
19153 | + case AU_ACL_SET: | |
19154 | + err = -EOPNOTSUPP; | |
5527c038 | 19155 | + h_inode = d_inode(h_path.dentry); |
c1595e42 JR |
19156 | + if (h_inode->i_op->set_acl) |
19157 | + err = h_inode->i_op->set_acl(h_inode, | |
19158 | + arg->u.acl_set.acl, | |
19159 | + arg->u.acl_set.type); | |
19160 | + break; | |
19161 | + } | |
19162 | + if (!err) | |
19163 | + au_cpup_attr_timesizes(inode); | |
19164 | + | |
19165 | + au_unpin(&a->pin); | |
19166 | + if (unlikely(err)) | |
19167 | + au_update_dbstart(dentry); | |
19168 | + | |
19169 | +out_di: | |
19170 | + di_write_unlock(dentry); | |
19171 | + si_read_unlock(sb); | |
19172 | +out_kfree: | |
19173 | + kfree(a); | |
19174 | +out: | |
19175 | + AuTraceErr(err); | |
19176 | + return err; | |
19177 | +} | |
19178 | +#endif | |
19179 | + | |
4a4d8108 AM |
19180 | +static void au_refresh_iattr(struct inode *inode, struct kstat *st, |
19181 | + unsigned int nlink) | |
1facf9fc | 19182 | +{ |
9dbd164d AM |
19183 | + unsigned int n; |
19184 | + | |
4a4d8108 | 19185 | + inode->i_mode = st->mode; |
86dc4139 AM |
19186 | + /* don't i_[ug]id_write() here */ |
19187 | + inode->i_uid = st->uid; | |
19188 | + inode->i_gid = st->gid; | |
4a4d8108 AM |
19189 | + inode->i_atime = st->atime; |
19190 | + inode->i_mtime = st->mtime; | |
19191 | + inode->i_ctime = st->ctime; | |
1facf9fc | 19192 | + |
4a4d8108 AM |
19193 | + au_cpup_attr_nlink(inode, /*force*/0); |
19194 | + if (S_ISDIR(inode->i_mode)) { | |
9dbd164d AM |
19195 | + n = inode->i_nlink; |
19196 | + n -= nlink; | |
19197 | + n += st->nlink; | |
f6b6e03d | 19198 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 19199 | + /* 0 can happen */ |
92d182d2 | 19200 | + set_nlink(inode, n); |
4a4d8108 | 19201 | + } |
1facf9fc | 19202 | + |
4a4d8108 AM |
19203 | + spin_lock(&inode->i_lock); |
19204 | + inode->i_blocks = st->blocks; | |
19205 | + i_size_write(inode, st->size); | |
19206 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 19207 | +} |
19208 | + | |
c1595e42 JR |
19209 | +/* |
19210 | + * common routine for aufs_getattr() and aufs_getxattr(). | |
19211 | + * returns zero or negative (an error). | |
19212 | + * @dentry will be read-locked in success. | |
19213 | + */ | |
19214 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path) | |
1facf9fc | 19215 | +{ |
4a4d8108 | 19216 | + int err; |
076b876e | 19217 | + unsigned int mnt_flags, sigen; |
c1595e42 | 19218 | + unsigned char udba_none; |
4a4d8108 | 19219 | + aufs_bindex_t bindex; |
4a4d8108 AM |
19220 | + struct super_block *sb, *h_sb; |
19221 | + struct inode *inode; | |
1facf9fc | 19222 | + |
c1595e42 JR |
19223 | + h_path->mnt = NULL; |
19224 | + h_path->dentry = NULL; | |
19225 | + | |
19226 | + err = 0; | |
4a4d8108 | 19227 | + sb = dentry->d_sb; |
4a4d8108 AM |
19228 | + mnt_flags = au_mntflags(sb); |
19229 | + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE); | |
1facf9fc | 19230 | + |
4a4d8108 | 19231 | + /* support fstat(2) */ |
027c5e7a | 19232 | + if (!d_unlinked(dentry) && !udba_none) { |
076b876e | 19233 | + sigen = au_sigen(sb); |
027c5e7a AM |
19234 | + err = au_digen_test(dentry, sigen); |
19235 | + if (!err) { | |
4a4d8108 | 19236 | + di_read_lock_child(dentry, AuLock_IR); |
027c5e7a | 19237 | + err = au_dbrange_test(dentry); |
c1595e42 JR |
19238 | + if (unlikely(err)) { |
19239 | + di_read_unlock(dentry, AuLock_IR); | |
19240 | + goto out; | |
19241 | + } | |
027c5e7a | 19242 | + } else { |
4a4d8108 AM |
19243 | + AuDebugOn(IS_ROOT(dentry)); |
19244 | + di_write_lock_child(dentry); | |
027c5e7a AM |
19245 | + err = au_dbrange_test(dentry); |
19246 | + if (!err) | |
19247 | + err = au_reval_for_attr(dentry, sigen); | |
c1595e42 JR |
19248 | + if (!err) |
19249 | + di_downgrade_lock(dentry, AuLock_IR); | |
19250 | + else { | |
19251 | + di_write_unlock(dentry); | |
19252 | + goto out; | |
19253 | + } | |
4a4d8108 AM |
19254 | + } |
19255 | + } else | |
19256 | + di_read_lock_child(dentry, AuLock_IR); | |
1facf9fc | 19257 | + |
5527c038 | 19258 | + inode = d_inode(dentry); |
4a4d8108 | 19259 | + bindex = au_ibstart(inode); |
c1595e42 JR |
19260 | + h_path->mnt = au_sbr_mnt(sb, bindex); |
19261 | + h_sb = h_path->mnt->mnt_sb; | |
19262 | + if (!force | |
19263 | + && !au_test_fs_bad_iattr(h_sb) | |
19264 | + && udba_none) | |
19265 | + goto out; /* success */ | |
1facf9fc | 19266 | + |
4a4d8108 | 19267 | + if (au_dbstart(dentry) == bindex) |
c1595e42 | 19268 | + h_path->dentry = au_h_dptr(dentry, bindex); |
4a4d8108 | 19269 | + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) { |
c1595e42 JR |
19270 | + h_path->dentry = au_plink_lkup(inode, bindex); |
19271 | + if (IS_ERR(h_path->dentry)) | |
19272 | + /* pretending success */ | |
19273 | + h_path->dentry = NULL; | |
19274 | + else | |
19275 | + dput(h_path->dentry); | |
4a4d8108 | 19276 | + } |
c1595e42 JR |
19277 | + |
19278 | +out: | |
19279 | + return err; | |
19280 | +} | |
19281 | + | |
19282 | +static int aufs_getattr(struct vfsmount *mnt __maybe_unused, | |
19283 | + struct dentry *dentry, struct kstat *st) | |
19284 | +{ | |
19285 | + int err; | |
19286 | + unsigned char positive; | |
19287 | + struct path h_path; | |
19288 | + struct inode *inode; | |
19289 | + struct super_block *sb; | |
19290 | + | |
5527c038 | 19291 | + inode = d_inode(dentry); |
c1595e42 JR |
19292 | + sb = dentry->d_sb; |
19293 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19294 | + if (unlikely(err)) | |
19295 | + goto out; | |
19296 | + err = au_h_path_getattr(dentry, /*force*/0, &h_path); | |
19297 | + if (unlikely(err)) | |
19298 | + goto out_si; | |
c06a8ce3 | 19299 | + if (unlikely(!h_path.dentry)) |
c1595e42 | 19300 | + /* illegally overlapped or something */ |
4a4d8108 AM |
19301 | + goto out_fill; /* pretending success */ |
19302 | + | |
5527c038 | 19303 | + positive = d_is_positive(h_path.dentry); |
4a4d8108 | 19304 | + if (positive) |
c06a8ce3 | 19305 | + err = vfs_getattr(&h_path, st); |
4a4d8108 AM |
19306 | + if (!err) { |
19307 | + if (positive) | |
c06a8ce3 | 19308 | + au_refresh_iattr(inode, st, |
5527c038 | 19309 | + d_inode(h_path.dentry)->i_nlink); |
4a4d8108 | 19310 | + goto out_fill; /* success */ |
1facf9fc | 19311 | + } |
7f207e10 | 19312 | + AuTraceErr(err); |
c1595e42 | 19313 | + goto out_di; |
4a4d8108 | 19314 | + |
4f0767ce | 19315 | +out_fill: |
4a4d8108 | 19316 | + generic_fillattr(inode, st); |
c1595e42 | 19317 | +out_di: |
4a4d8108 | 19318 | + di_read_unlock(dentry, AuLock_IR); |
c1595e42 | 19319 | +out_si: |
4a4d8108 | 19320 | + si_read_unlock(sb); |
7f207e10 AM |
19321 | +out: |
19322 | + AuTraceErr(err); | |
4a4d8108 | 19323 | + return err; |
1facf9fc | 19324 | +} |
19325 | + | |
19326 | +/* ---------------------------------------------------------------------- */ | |
19327 | + | |
c2c0f25c AM |
19328 | +/* |
19329 | + * Assumption: | |
19330 | + * - the number of symlinks is not so many. | |
19331 | + * | |
19332 | + * Structure: | |
19333 | + * - sbinfo (instead of iinfo) contains an hlist of struct au_symlink. | |
19334 | + * If iinfo contained the hlist, then it would be rather large waste of memory | |
19335 | + * I am afraid. | |
19336 | + * - struct au_symlink contains the necessary info for h_inode follow_link() and | |
19337 | + * put_link(). | |
19338 | + */ | |
1facf9fc | 19339 | + |
c2c0f25c AM |
19340 | +struct au_symlink { |
19341 | + union { | |
19342 | + struct hlist_node hlist; | |
19343 | + struct rcu_head rcu; | |
19344 | + }; | |
1facf9fc | 19345 | + |
c2c0f25c AM |
19346 | + struct inode *h_inode; |
19347 | + void *h_cookie; | |
19348 | +}; | |
1facf9fc | 19349 | + |
c2c0f25c AM |
19350 | +static void au_symlink_add(struct super_block *sb, struct au_symlink *slink, |
19351 | + struct inode *h_inode, void *cookie) | |
19352 | +{ | |
19353 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 19354 | + |
c2c0f25c AM |
19355 | + ihold(h_inode); |
19356 | + slink->h_inode = h_inode; | |
19357 | + slink->h_cookie = cookie; | |
19358 | + sbinfo = au_sbi(sb); | |
19359 | + au_sphl_add(&slink->hlist, &sbinfo->si_symlink); | |
4a4d8108 | 19360 | +} |
1facf9fc | 19361 | + |
c2c0f25c | 19362 | +static void au_symlink_del(struct super_block *sb, struct au_symlink *slink) |
4a4d8108 | 19363 | +{ |
c2c0f25c | 19364 | + struct au_sbinfo *sbinfo; |
1facf9fc | 19365 | + |
c2c0f25c AM |
19366 | + /* do not iput() within rcu */ |
19367 | + iput(slink->h_inode); | |
19368 | + slink->h_inode = NULL; | |
19369 | + sbinfo = au_sbi(sb); | |
19370 | + au_sphl_del_rcu(&slink->hlist, &sbinfo->si_symlink); | |
19371 | + kfree_rcu(slink, rcu); | |
4a4d8108 | 19372 | +} |
1facf9fc | 19373 | + |
c2c0f25c | 19374 | +static const char *aufs_follow_link(struct dentry *dentry, void **cookie) |
4a4d8108 | 19375 | +{ |
c2c0f25c AM |
19376 | + const char *ret; |
19377 | + struct inode *inode, *h_inode; | |
19378 | + struct dentry *h_dentry; | |
19379 | + struct au_symlink *slink; | |
4a4d8108 | 19380 | + int err; |
c2c0f25c | 19381 | + aufs_bindex_t bindex; |
1facf9fc | 19382 | + |
c2c0f25c | 19383 | + ret = NULL; /* supress a warning */ |
027c5e7a AM |
19384 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
19385 | + if (unlikely(err)) | |
c2c0f25c | 19386 | + goto out; |
027c5e7a AM |
19387 | + |
19388 | + err = au_d_hashed_positive(dentry); | |
c2c0f25c AM |
19389 | + if (unlikely(err)) |
19390 | + goto out_unlock; | |
19391 | + | |
19392 | + err = -EINVAL; | |
19393 | + inode = d_inode(dentry); | |
19394 | + bindex = au_ibstart(inode); | |
19395 | + h_inode = au_h_iptr(inode, bindex); | |
19396 | + if (unlikely(!h_inode->i_op->follow_link)) | |
19397 | + goto out_unlock; | |
19398 | + | |
19399 | + err = -ENOMEM; | |
19400 | + slink = kmalloc(sizeof(*slink), GFP_NOFS); | |
19401 | + if (unlikely(!slink)) | |
19402 | + goto out_unlock; | |
19403 | + | |
19404 | + err = -EBUSY; | |
19405 | + h_dentry = NULL; | |
19406 | + if (au_dbstart(dentry) <= bindex) { | |
19407 | + h_dentry = au_h_dptr(dentry, bindex); | |
19408 | + if (h_dentry) | |
19409 | + dget(h_dentry); | |
027c5e7a | 19410 | + } |
c2c0f25c AM |
19411 | + if (!h_dentry) { |
19412 | + h_dentry = d_find_any_alias(h_inode); | |
19413 | + if (IS_ERR(h_dentry)) { | |
19414 | + err = PTR_ERR(h_dentry); | |
19415 | + goto out_free; | |
19416 | + } | |
19417 | + } | |
19418 | + if (unlikely(!h_dentry)) | |
19419 | + goto out_free; | |
1facf9fc | 19420 | + |
c2c0f25c AM |
19421 | + err = 0; |
19422 | + AuDbg("%pf\n", h_inode->i_op->follow_link); | |
19423 | + AuDbgDentry(h_dentry); | |
19424 | + ret = h_inode->i_op->follow_link(h_dentry, cookie); | |
19425 | + dput(h_dentry); | |
19426 | + | |
19427 | + if (!IS_ERR_OR_NULL(ret)) { | |
19428 | + au_symlink_add(inode->i_sb, slink, h_inode, *cookie); | |
19429 | + *cookie = slink; | |
19430 | + AuDbg("slink %p\n", slink); | |
19431 | + goto out_unlock; /* success */ | |
1308ab2a | 19432 | + } |
1facf9fc | 19433 | + |
c2c0f25c AM |
19434 | +out_free: |
19435 | + slink->h_inode = NULL; | |
19436 | + kfree_rcu(slink, rcu); | |
19437 | +out_unlock: | |
19438 | + aufs_read_unlock(dentry, AuLock_IR); | |
4f0767ce | 19439 | +out: |
c2c0f25c AM |
19440 | + if (unlikely(err)) |
19441 | + ret = ERR_PTR(err); | |
19442 | + AuTraceErrPtr(ret); | |
19443 | + return ret; | |
4a4d8108 | 19444 | +} |
1facf9fc | 19445 | + |
c2c0f25c | 19446 | +static void aufs_put_link(struct inode *inode, void *cookie) |
4a4d8108 | 19447 | +{ |
c2c0f25c AM |
19448 | + struct au_symlink *slink; |
19449 | + struct inode *h_inode; | |
537831f9 | 19450 | + |
c2c0f25c AM |
19451 | + slink = cookie; |
19452 | + AuDbg("slink %p\n", slink); | |
19453 | + h_inode = slink->h_inode; | |
19454 | + AuDbg("%pf\n", h_inode->i_op->put_link); | |
19455 | + AuDbgInode(h_inode); | |
19456 | + if (h_inode->i_op->put_link) | |
19457 | + h_inode->i_op->put_link(h_inode, slink->h_cookie); | |
19458 | + au_symlink_del(inode->i_sb, slink); | |
4a4d8108 | 19459 | +} |
1facf9fc | 19460 | + |
4a4d8108 | 19461 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19462 | + |
0c3ec466 | 19463 | +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags) |
4a4d8108 | 19464 | +{ |
0c3ec466 AM |
19465 | + int err; |
19466 | + struct super_block *sb; | |
19467 | + struct inode *h_inode; | |
19468 | + | |
19469 | + sb = inode->i_sb; | |
19470 | + /* mmap_sem might be acquired already, cf. aufs_mmap() */ | |
19471 | + lockdep_off(); | |
19472 | + si_read_lock(sb, AuLock_FLUSH); | |
19473 | + ii_write_lock_child(inode); | |
19474 | + lockdep_on(); | |
19475 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
19476 | + err = vfsub_update_time(h_inode, ts, flags); | |
19477 | + lockdep_off(); | |
38d290e6 JR |
19478 | + if (!err) |
19479 | + au_cpup_attr_timesizes(inode); | |
0c3ec466 AM |
19480 | + ii_write_unlock(inode); |
19481 | + si_read_unlock(sb); | |
19482 | + lockdep_on(); | |
38d290e6 JR |
19483 | + |
19484 | + if (!err && (flags & S_VERSION)) | |
19485 | + inode_inc_iversion(inode); | |
19486 | + | |
0c3ec466 | 19487 | + return err; |
4a4d8108 | 19488 | +} |
1facf9fc | 19489 | + |
4a4d8108 | 19490 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19491 | + |
4a4d8108 AM |
19492 | +struct inode_operations aufs_symlink_iop = { |
19493 | + .permission = aufs_permission, | |
c1595e42 JR |
19494 | +#ifdef CONFIG_FS_POSIX_ACL |
19495 | + .get_acl = aufs_get_acl, | |
19496 | + .set_acl = aufs_set_acl, /* unsupport for symlink? */ | |
19497 | +#endif | |
19498 | + | |
4a4d8108 AM |
19499 | + .setattr = aufs_setattr, |
19500 | + .getattr = aufs_getattr, | |
0c3ec466 | 19501 | + |
c1595e42 JR |
19502 | +#ifdef CONFIG_AUFS_XATTR |
19503 | + .setxattr = aufs_setxattr, | |
19504 | + .getxattr = aufs_getxattr, | |
19505 | + .listxattr = aufs_listxattr, | |
19506 | + .removexattr = aufs_removexattr, | |
19507 | +#endif | |
19508 | + | |
c2c0f25c | 19509 | + .readlink = generic_readlink, |
4a4d8108 | 19510 | + .follow_link = aufs_follow_link, |
0c3ec466 AM |
19511 | + .put_link = aufs_put_link, |
19512 | + | |
19513 | + /* .update_time = aufs_update_time */ | |
4a4d8108 AM |
19514 | +}; |
19515 | + | |
19516 | +struct inode_operations aufs_dir_iop = { | |
19517 | + .create = aufs_create, | |
19518 | + .lookup = aufs_lookup, | |
19519 | + .link = aufs_link, | |
19520 | + .unlink = aufs_unlink, | |
19521 | + .symlink = aufs_symlink, | |
19522 | + .mkdir = aufs_mkdir, | |
19523 | + .rmdir = aufs_rmdir, | |
19524 | + .mknod = aufs_mknod, | |
19525 | + .rename = aufs_rename, | |
19526 | + | |
19527 | + .permission = aufs_permission, | |
c1595e42 JR |
19528 | +#ifdef CONFIG_FS_POSIX_ACL |
19529 | + .get_acl = aufs_get_acl, | |
19530 | + .set_acl = aufs_set_acl, | |
19531 | +#endif | |
19532 | + | |
4a4d8108 | 19533 | + .setattr = aufs_setattr, |
0c3ec466 AM |
19534 | + .getattr = aufs_getattr, |
19535 | + | |
c1595e42 JR |
19536 | +#ifdef CONFIG_AUFS_XATTR |
19537 | + .setxattr = aufs_setxattr, | |
19538 | + .getxattr = aufs_getxattr, | |
19539 | + .listxattr = aufs_listxattr, | |
19540 | + .removexattr = aufs_removexattr, | |
19541 | +#endif | |
19542 | + | |
38d290e6 | 19543 | + .update_time = aufs_update_time, |
b912730e | 19544 | + .atomic_open = aufs_atomic_open, |
38d290e6 | 19545 | + .tmpfile = aufs_tmpfile |
4a4d8108 AM |
19546 | +}; |
19547 | + | |
19548 | +struct inode_operations aufs_iop = { | |
19549 | + .permission = aufs_permission, | |
c1595e42 JR |
19550 | +#ifdef CONFIG_FS_POSIX_ACL |
19551 | + .get_acl = aufs_get_acl, | |
19552 | + .set_acl = aufs_set_acl, | |
19553 | +#endif | |
19554 | + | |
4a4d8108 AM |
19555 | + .setattr = aufs_setattr, |
19556 | + .getattr = aufs_getattr, | |
0c3ec466 | 19557 | + |
c1595e42 JR |
19558 | +#ifdef CONFIG_AUFS_XATTR |
19559 | + .setxattr = aufs_setxattr, | |
19560 | + .getxattr = aufs_getxattr, | |
19561 | + .listxattr = aufs_listxattr, | |
19562 | + .removexattr = aufs_removexattr, | |
19563 | +#endif | |
19564 | + | |
0c3ec466 | 19565 | + .update_time = aufs_update_time |
4a4d8108 | 19566 | +}; |
7f207e10 AM |
19567 | diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c |
19568 | --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 19569 | +++ linux/fs/aufs/i_op_del.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 19570 | @@ -0,0 +1,510 @@ |
1facf9fc | 19571 | +/* |
2000de60 | 19572 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 19573 | + * |
19574 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19575 | + * it under the terms of the GNU General Public License as published by | |
19576 | + * the Free Software Foundation; either version 2 of the License, or | |
19577 | + * (at your option) any later version. | |
dece6358 AM |
19578 | + * |
19579 | + * This program is distributed in the hope that it will be useful, | |
19580 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19581 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19582 | + * GNU General Public License for more details. | |
19583 | + * | |
19584 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19585 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 19586 | + */ |
19587 | + | |
19588 | +/* | |
4a4d8108 | 19589 | + * inode operations (del entry) |
1308ab2a | 19590 | + */ |
dece6358 | 19591 | + |
1308ab2a | 19592 | +#include "aufs.h" |
dece6358 | 19593 | + |
4a4d8108 AM |
19594 | +/* |
19595 | + * decide if a new whiteout for @dentry is necessary or not. | |
19596 | + * when it is necessary, prepare the parent dir for the upper branch whose | |
19597 | + * branch index is @bcpup for creation. the actual creation of the whiteout will | |
19598 | + * be done by caller. | |
19599 | + * return value: | |
19600 | + * 0: wh is unnecessary | |
19601 | + * plus: wh is necessary | |
19602 | + * minus: error | |
19603 | + */ | |
19604 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup) | |
1308ab2a | 19605 | +{ |
4a4d8108 AM |
19606 | + int need_wh, err; |
19607 | + aufs_bindex_t bstart; | |
19608 | + struct super_block *sb; | |
dece6358 | 19609 | + |
4a4d8108 AM |
19610 | + sb = dentry->d_sb; |
19611 | + bstart = au_dbstart(dentry); | |
19612 | + if (*bcpup < 0) { | |
19613 | + *bcpup = bstart; | |
5527c038 | 19614 | + if (au_test_ro(sb, bstart, d_inode(dentry))) { |
4a4d8108 AM |
19615 | + err = AuWbrCopyup(au_sbi(sb), dentry); |
19616 | + *bcpup = err; | |
19617 | + if (unlikely(err < 0)) | |
19618 | + goto out; | |
19619 | + } | |
19620 | + } else | |
19621 | + AuDebugOn(bstart < *bcpup | |
5527c038 | 19622 | + || au_test_ro(sb, *bcpup, d_inode(dentry))); |
4a4d8108 | 19623 | + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart); |
1308ab2a | 19624 | + |
4a4d8108 AM |
19625 | + if (*bcpup != bstart) { |
19626 | + err = au_cpup_dirs(dentry, *bcpup); | |
19627 | + if (unlikely(err)) | |
19628 | + goto out; | |
19629 | + need_wh = 1; | |
19630 | + } else { | |
027c5e7a | 19631 | + struct au_dinfo *dinfo, *tmp; |
4a4d8108 | 19632 | + |
027c5e7a AM |
19633 | + need_wh = -ENOMEM; |
19634 | + dinfo = au_di(dentry); | |
19635 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
19636 | + if (tmp) { | |
19637 | + au_di_cp(tmp, dinfo); | |
19638 | + au_di_swap(tmp, dinfo); | |
19639 | + /* returns the number of positive dentries */ | |
537831f9 | 19640 | + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0); |
027c5e7a AM |
19641 | + au_di_swap(tmp, dinfo); |
19642 | + au_rw_write_unlock(&tmp->di_rwsem); | |
19643 | + au_di_free(tmp); | |
4a4d8108 AM |
19644 | + } |
19645 | + } | |
19646 | + AuDbg("need_wh %d\n", need_wh); | |
19647 | + err = need_wh; | |
19648 | + | |
4f0767ce | 19649 | +out: |
4a4d8108 | 19650 | + return err; |
1facf9fc | 19651 | +} |
19652 | + | |
4a4d8108 AM |
19653 | +/* |
19654 | + * simple tests for the del-entry operations. | |
19655 | + * following the checks in vfs, plus the parent-child relationship. | |
19656 | + */ | |
19657 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
19658 | + struct dentry *h_parent, int isdir) | |
1facf9fc | 19659 | +{ |
4a4d8108 AM |
19660 | + int err; |
19661 | + umode_t h_mode; | |
19662 | + struct dentry *h_dentry, *h_latest; | |
1308ab2a | 19663 | + struct inode *h_inode; |
1facf9fc | 19664 | + |
4a4d8108 | 19665 | + h_dentry = au_h_dptr(dentry, bindex); |
5527c038 | 19666 | + if (d_really_is_positive(dentry)) { |
4a4d8108 | 19667 | + err = -ENOENT; |
5527c038 JR |
19668 | + if (unlikely(d_is_negative(h_dentry))) |
19669 | + goto out; | |
19670 | + h_inode = d_inode(h_dentry); | |
19671 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 | 19672 | + goto out; |
1facf9fc | 19673 | + |
4a4d8108 AM |
19674 | + h_mode = h_inode->i_mode; |
19675 | + if (!isdir) { | |
19676 | + err = -EISDIR; | |
19677 | + if (unlikely(S_ISDIR(h_mode))) | |
19678 | + goto out; | |
19679 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
19680 | + err = -ENOTDIR; | |
19681 | + goto out; | |
19682 | + } | |
19683 | + } else { | |
19684 | + /* rename(2) case */ | |
19685 | + err = -EIO; | |
5527c038 | 19686 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
19687 | + goto out; |
19688 | + } | |
1facf9fc | 19689 | + |
4a4d8108 AM |
19690 | + err = -ENOENT; |
19691 | + /* expected parent dir is locked */ | |
19692 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
19693 | + goto out; | |
19694 | + err = 0; | |
19695 | + | |
19696 | + /* | |
19697 | + * rmdir a dir may break the consistency on some filesystem. | |
19698 | + * let's try heavy test. | |
19699 | + */ | |
19700 | + err = -EACCES; | |
076b876e | 19701 | + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1) |
5527c038 | 19702 | + && au_test_h_perm(d_inode(h_parent), |
076b876e | 19703 | + MAY_EXEC | MAY_WRITE))) |
4a4d8108 AM |
19704 | + goto out; |
19705 | + | |
076b876e | 19706 | + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent); |
4a4d8108 AM |
19707 | + err = -EIO; |
19708 | + if (IS_ERR(h_latest)) | |
19709 | + goto out; | |
19710 | + if (h_latest == h_dentry) | |
19711 | + err = 0; | |
19712 | + dput(h_latest); | |
19713 | + | |
4f0767ce | 19714 | +out: |
4a4d8108 | 19715 | + return err; |
1308ab2a | 19716 | +} |
1facf9fc | 19717 | + |
4a4d8108 AM |
19718 | +/* |
19719 | + * decide the branch where we operate for @dentry. the branch index will be set | |
19720 | + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent | |
19721 | + * dir for reverting. | |
19722 | + * when a new whiteout is necessary, create it. | |
19723 | + */ | |
19724 | +static struct dentry* | |
19725 | +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup, | |
19726 | + struct au_dtime *dt, struct au_pin *pin) | |
1308ab2a | 19727 | +{ |
4a4d8108 AM |
19728 | + struct dentry *wh_dentry; |
19729 | + struct super_block *sb; | |
19730 | + struct path h_path; | |
19731 | + int err, need_wh; | |
19732 | + unsigned int udba; | |
19733 | + aufs_bindex_t bcpup; | |
dece6358 | 19734 | + |
4a4d8108 AM |
19735 | + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup); |
19736 | + wh_dentry = ERR_PTR(need_wh); | |
19737 | + if (unlikely(need_wh < 0)) | |
19738 | + goto out; | |
19739 | + | |
19740 | + sb = dentry->d_sb; | |
19741 | + udba = au_opt_udba(sb); | |
19742 | + bcpup = *rbcpup; | |
19743 | + err = au_pin(pin, dentry, bcpup, udba, | |
19744 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
19745 | + wh_dentry = ERR_PTR(err); | |
19746 | + if (unlikely(err)) | |
19747 | + goto out; | |
19748 | + | |
19749 | + h_path.dentry = au_pinned_h_parent(pin); | |
19750 | + if (udba != AuOpt_UDBA_NONE | |
19751 | + && au_dbstart(dentry) == bcpup) { | |
19752 | + err = au_may_del(dentry, bcpup, h_path.dentry, isdir); | |
19753 | + wh_dentry = ERR_PTR(err); | |
19754 | + if (unlikely(err)) | |
19755 | + goto out_unpin; | |
19756 | + } | |
19757 | + | |
19758 | + h_path.mnt = au_sbr_mnt(sb, bcpup); | |
19759 | + au_dtime_store(dt, au_pinned_parent(pin), &h_path); | |
19760 | + wh_dentry = NULL; | |
19761 | + if (!need_wh) | |
19762 | + goto out; /* success, no need to create whiteout */ | |
19763 | + | |
19764 | + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry); | |
19765 | + if (IS_ERR(wh_dentry)) | |
19766 | + goto out_unpin; | |
19767 | + | |
19768 | + /* returns with the parent is locked and wh_dentry is dget-ed */ | |
19769 | + goto out; /* success */ | |
19770 | + | |
4f0767ce | 19771 | +out_unpin: |
4a4d8108 | 19772 | + au_unpin(pin); |
4f0767ce | 19773 | +out: |
4a4d8108 | 19774 | + return wh_dentry; |
1facf9fc | 19775 | +} |
19776 | + | |
4a4d8108 AM |
19777 | +/* |
19778 | + * when removing a dir, rename it to a unique temporary whiteout-ed name first | |
19779 | + * in order to be revertible and save time for removing many child whiteouts | |
19780 | + * under the dir. | |
19781 | + * returns 1 when there are too many child whiteout and caller should remove | |
19782 | + * them asynchronously. returns 0 when the number of children is enough small to | |
19783 | + * remove now or the branch fs is a remote fs. | |
19784 | + * otherwise return an error. | |
19785 | + */ | |
19786 | +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex, | |
19787 | + struct au_nhash *whlist, struct inode *dir) | |
1facf9fc | 19788 | +{ |
4a4d8108 AM |
19789 | + int rmdir_later, err, dirwh; |
19790 | + struct dentry *h_dentry; | |
19791 | + struct super_block *sb; | |
5527c038 | 19792 | + struct inode *inode; |
4a4d8108 AM |
19793 | + |
19794 | + sb = dentry->d_sb; | |
19795 | + SiMustAnyLock(sb); | |
19796 | + h_dentry = au_h_dptr(dentry, bindex); | |
19797 | + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex)); | |
19798 | + if (unlikely(err)) | |
19799 | + goto out; | |
19800 | + | |
19801 | + /* stop monitoring */ | |
5527c038 JR |
19802 | + inode = d_inode(dentry); |
19803 | + au_hn_free(au_hi(inode, bindex)); | |
4a4d8108 AM |
19804 | + |
19805 | + if (!au_test_fs_remote(h_dentry->d_sb)) { | |
19806 | + dirwh = au_sbi(sb)->si_dirwh; | |
19807 | + rmdir_later = (dirwh <= 1); | |
19808 | + if (!rmdir_later) | |
19809 | + rmdir_later = au_nhash_test_longer_wh(whlist, bindex, | |
19810 | + dirwh); | |
19811 | + if (rmdir_later) | |
19812 | + return rmdir_later; | |
19813 | + } | |
1facf9fc | 19814 | + |
4a4d8108 AM |
19815 | + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist); |
19816 | + if (unlikely(err)) { | |
523b37e3 AM |
19817 | + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n", |
19818 | + h_dentry, bindex, err); | |
4a4d8108 AM |
19819 | + err = 0; |
19820 | + } | |
dece6358 | 19821 | + |
4f0767ce | 19822 | +out: |
4a4d8108 AM |
19823 | + AuTraceErr(err); |
19824 | + return err; | |
19825 | +} | |
1308ab2a | 19826 | + |
4a4d8108 AM |
19827 | +/* |
19828 | + * final procedure for deleting a entry. | |
19829 | + * maintain dentry and iattr. | |
19830 | + */ | |
19831 | +static void epilog(struct inode *dir, struct dentry *dentry, | |
19832 | + aufs_bindex_t bindex) | |
19833 | +{ | |
19834 | + struct inode *inode; | |
1308ab2a | 19835 | + |
5527c038 | 19836 | + inode = d_inode(dentry); |
4a4d8108 AM |
19837 | + d_drop(dentry); |
19838 | + inode->i_ctime = dir->i_ctime; | |
1308ab2a | 19839 | + |
b912730e | 19840 | + au_dir_ts(dir, bindex); |
4a4d8108 | 19841 | + dir->i_version++; |
1facf9fc | 19842 | +} |
19843 | + | |
4a4d8108 AM |
19844 | +/* |
19845 | + * when an error happened, remove the created whiteout and revert everything. | |
19846 | + */ | |
7f207e10 AM |
19847 | +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex, |
19848 | + aufs_bindex_t bwh, struct dentry *wh_dentry, | |
19849 | + struct dentry *dentry, struct au_dtime *dt) | |
1facf9fc | 19850 | +{ |
4a4d8108 AM |
19851 | + int rerr; |
19852 | + struct path h_path = { | |
19853 | + .dentry = wh_dentry, | |
7f207e10 | 19854 | + .mnt = au_sbr_mnt(dir->i_sb, bindex) |
4a4d8108 | 19855 | + }; |
dece6358 | 19856 | + |
7f207e10 | 19857 | + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry); |
4a4d8108 AM |
19858 | + if (!rerr) { |
19859 | + au_set_dbwh(dentry, bwh); | |
19860 | + au_dtime_revert(dt); | |
19861 | + return 0; | |
19862 | + } | |
dece6358 | 19863 | + |
523b37e3 | 19864 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr); |
4a4d8108 | 19865 | + return -EIO; |
1facf9fc | 19866 | +} |
19867 | + | |
4a4d8108 | 19868 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19869 | + |
4a4d8108 | 19870 | +int aufs_unlink(struct inode *dir, struct dentry *dentry) |
1308ab2a | 19871 | +{ |
4a4d8108 AM |
19872 | + int err; |
19873 | + aufs_bindex_t bwh, bindex, bstart; | |
523b37e3 | 19874 | + struct inode *inode, *h_dir, *delegated; |
4a4d8108 | 19875 | + struct dentry *parent, *wh_dentry; |
c2b27bf2 AM |
19876 | + /* to reuduce stack size */ |
19877 | + struct { | |
19878 | + struct au_dtime dt; | |
19879 | + struct au_pin pin; | |
19880 | + struct path h_path; | |
19881 | + } *a; | |
1facf9fc | 19882 | + |
4a4d8108 | 19883 | + IMustLock(dir); |
027c5e7a | 19884 | + |
c2b27bf2 AM |
19885 | + err = -ENOMEM; |
19886 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19887 | + if (unlikely(!a)) | |
19888 | + goto out; | |
19889 | + | |
027c5e7a AM |
19890 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
19891 | + if (unlikely(err)) | |
c2b27bf2 | 19892 | + goto out_free; |
027c5e7a AM |
19893 | + err = au_d_hashed_positive(dentry); |
19894 | + if (unlikely(err)) | |
19895 | + goto out_unlock; | |
5527c038 | 19896 | + inode = d_inode(dentry); |
4a4d8108 | 19897 | + IMustLock(inode); |
027c5e7a | 19898 | + err = -EISDIR; |
2000de60 | 19899 | + if (unlikely(d_is_dir(dentry))) |
027c5e7a | 19900 | + goto out_unlock; /* possible? */ |
1facf9fc | 19901 | + |
4a4d8108 AM |
19902 | + bstart = au_dbstart(dentry); |
19903 | + bwh = au_dbwh(dentry); | |
19904 | + bindex = -1; | |
027c5e7a AM |
19905 | + parent = dentry->d_parent; /* dir inode is locked */ |
19906 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
19907 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt, |
19908 | + &a->pin); | |
4a4d8108 AM |
19909 | + err = PTR_ERR(wh_dentry); |
19910 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 19911 | + goto out_parent; |
1facf9fc | 19912 | + |
c2b27bf2 AM |
19913 | + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart); |
19914 | + a->h_path.dentry = au_h_dptr(dentry, bstart); | |
19915 | + dget(a->h_path.dentry); | |
4a4d8108 | 19916 | + if (bindex == bstart) { |
c2b27bf2 | 19917 | + h_dir = au_pinned_h_dir(&a->pin); |
523b37e3 AM |
19918 | + delegated = NULL; |
19919 | + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0); | |
19920 | + if (unlikely(err == -EWOULDBLOCK)) { | |
19921 | + pr_warn("cannot retry for NFSv4 delegation" | |
19922 | + " for an internal unlink\n"); | |
19923 | + iput(delegated); | |
19924 | + } | |
4a4d8108 AM |
19925 | + } else { |
19926 | + /* dir inode is locked */ | |
5527c038 | 19927 | + h_dir = d_inode(wh_dentry->d_parent); |
4a4d8108 AM |
19928 | + IMustLock(h_dir); |
19929 | + err = 0; | |
19930 | + } | |
dece6358 | 19931 | + |
4a4d8108 | 19932 | + if (!err) { |
7f207e10 | 19933 | + vfsub_drop_nlink(inode); |
4a4d8108 AM |
19934 | + epilog(dir, dentry, bindex); |
19935 | + | |
19936 | + /* update target timestamps */ | |
19937 | + if (bindex == bstart) { | |
c2b27bf2 AM |
19938 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); |
19939 | + /*ignore*/ | |
5527c038 | 19940 | + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
4a4d8108 AM |
19941 | + } else |
19942 | + /* todo: this timestamp may be reverted later */ | |
19943 | + inode->i_ctime = h_dir->i_ctime; | |
027c5e7a | 19944 | + goto out_unpin; /* success */ |
1facf9fc | 19945 | + } |
19946 | + | |
4a4d8108 AM |
19947 | + /* revert */ |
19948 | + if (wh_dentry) { | |
19949 | + int rerr; | |
19950 | + | |
c2b27bf2 AM |
19951 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
19952 | + &a->dt); | |
4a4d8108 AM |
19953 | + if (rerr) |
19954 | + err = rerr; | |
dece6358 | 19955 | + } |
1facf9fc | 19956 | + |
027c5e7a | 19957 | +out_unpin: |
c2b27bf2 | 19958 | + au_unpin(&a->pin); |
4a4d8108 | 19959 | + dput(wh_dentry); |
c2b27bf2 | 19960 | + dput(a->h_path.dentry); |
027c5e7a | 19961 | +out_parent: |
4a4d8108 | 19962 | + di_write_unlock(parent); |
027c5e7a | 19963 | +out_unlock: |
4a4d8108 | 19964 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 AM |
19965 | +out_free: |
19966 | + kfree(a); | |
027c5e7a | 19967 | +out: |
4a4d8108 | 19968 | + return err; |
dece6358 AM |
19969 | +} |
19970 | + | |
4a4d8108 | 19971 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry) |
1308ab2a | 19972 | +{ |
4a4d8108 AM |
19973 | + int err, rmdir_later; |
19974 | + aufs_bindex_t bwh, bindex, bstart; | |
4a4d8108 AM |
19975 | + struct inode *inode; |
19976 | + struct dentry *parent, *wh_dentry, *h_dentry; | |
19977 | + struct au_whtmp_rmdir *args; | |
c2b27bf2 AM |
19978 | + /* to reuduce stack size */ |
19979 | + struct { | |
19980 | + struct au_dtime dt; | |
19981 | + struct au_pin pin; | |
19982 | + } *a; | |
1facf9fc | 19983 | + |
4a4d8108 | 19984 | + IMustLock(dir); |
027c5e7a | 19985 | + |
c2b27bf2 AM |
19986 | + err = -ENOMEM; |
19987 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19988 | + if (unlikely(!a)) | |
19989 | + goto out; | |
19990 | + | |
027c5e7a AM |
19991 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); |
19992 | + if (unlikely(err)) | |
c2b27bf2 | 19993 | + goto out_free; |
53392da6 AM |
19994 | + err = au_alive_dir(dentry); |
19995 | + if (unlikely(err)) | |
027c5e7a | 19996 | + goto out_unlock; |
5527c038 | 19997 | + inode = d_inode(dentry); |
4a4d8108 | 19998 | + IMustLock(inode); |
027c5e7a | 19999 | + err = -ENOTDIR; |
2000de60 | 20000 | + if (unlikely(!d_is_dir(dentry))) |
027c5e7a | 20001 | + goto out_unlock; /* possible? */ |
dece6358 | 20002 | + |
4a4d8108 AM |
20003 | + err = -ENOMEM; |
20004 | + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS); | |
20005 | + if (unlikely(!args)) | |
20006 | + goto out_unlock; | |
dece6358 | 20007 | + |
4a4d8108 AM |
20008 | + parent = dentry->d_parent; /* dir inode is locked */ |
20009 | + di_write_lock_parent(parent); | |
20010 | + err = au_test_empty(dentry, &args->whlist); | |
20011 | + if (unlikely(err)) | |
027c5e7a | 20012 | + goto out_parent; |
1facf9fc | 20013 | + |
4a4d8108 AM |
20014 | + bstart = au_dbstart(dentry); |
20015 | + bwh = au_dbwh(dentry); | |
20016 | + bindex = -1; | |
c2b27bf2 AM |
20017 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt, |
20018 | + &a->pin); | |
4a4d8108 AM |
20019 | + err = PTR_ERR(wh_dentry); |
20020 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20021 | + goto out_parent; |
1facf9fc | 20022 | + |
4a4d8108 AM |
20023 | + h_dentry = au_h_dptr(dentry, bstart); |
20024 | + dget(h_dentry); | |
20025 | + rmdir_later = 0; | |
20026 | + if (bindex == bstart) { | |
20027 | + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir); | |
20028 | + if (err > 0) { | |
20029 | + rmdir_later = err; | |
20030 | + err = 0; | |
20031 | + } | |
20032 | + } else { | |
20033 | + /* stop monitoring */ | |
20034 | + au_hn_free(au_hi(inode, bstart)); | |
20035 | + | |
20036 | + /* dir inode is locked */ | |
5527c038 | 20037 | + IMustLock(d_inode(wh_dentry->d_parent)); |
1facf9fc | 20038 | + err = 0; |
20039 | + } | |
20040 | + | |
4a4d8108 | 20041 | + if (!err) { |
027c5e7a | 20042 | + vfsub_dead_dir(inode); |
4a4d8108 AM |
20043 | + au_set_dbdiropq(dentry, -1); |
20044 | + epilog(dir, dentry, bindex); | |
1308ab2a | 20045 | + |
4a4d8108 AM |
20046 | + if (rmdir_later) { |
20047 | + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args); | |
20048 | + args = NULL; | |
20049 | + } | |
1308ab2a | 20050 | + |
4a4d8108 | 20051 | + goto out_unpin; /* success */ |
1facf9fc | 20052 | + } |
20053 | + | |
4a4d8108 AM |
20054 | + /* revert */ |
20055 | + AuLabel(revert); | |
20056 | + if (wh_dentry) { | |
20057 | + int rerr; | |
1308ab2a | 20058 | + |
c2b27bf2 AM |
20059 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
20060 | + &a->dt); | |
4a4d8108 AM |
20061 | + if (rerr) |
20062 | + err = rerr; | |
1facf9fc | 20063 | + } |
20064 | + | |
4f0767ce | 20065 | +out_unpin: |
c2b27bf2 | 20066 | + au_unpin(&a->pin); |
4a4d8108 AM |
20067 | + dput(wh_dentry); |
20068 | + dput(h_dentry); | |
027c5e7a | 20069 | +out_parent: |
4a4d8108 AM |
20070 | + di_write_unlock(parent); |
20071 | + if (args) | |
20072 | + au_whtmp_rmdir_free(args); | |
4f0767ce | 20073 | +out_unlock: |
4a4d8108 | 20074 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 AM |
20075 | +out_free: |
20076 | + kfree(a); | |
4f0767ce | 20077 | +out: |
4a4d8108 AM |
20078 | + AuTraceErr(err); |
20079 | + return err; | |
dece6358 | 20080 | +} |
7f207e10 AM |
20081 | diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c |
20082 | --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 20083 | +++ linux/fs/aufs/i_op_ren.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 20084 | @@ -0,0 +1,1017 @@ |
1facf9fc | 20085 | +/* |
2000de60 | 20086 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 20087 | + * |
20088 | + * This program, aufs is free software; you can redistribute it and/or modify | |
20089 | + * it under the terms of the GNU General Public License as published by | |
20090 | + * the Free Software Foundation; either version 2 of the License, or | |
20091 | + * (at your option) any later version. | |
dece6358 AM |
20092 | + * |
20093 | + * This program is distributed in the hope that it will be useful, | |
20094 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20095 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20096 | + * GNU General Public License for more details. | |
20097 | + * | |
20098 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 20099 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 20100 | + */ |
20101 | + | |
20102 | +/* | |
4a4d8108 AM |
20103 | + * inode operation (rename entry) |
20104 | + * todo: this is crazy monster | |
1facf9fc | 20105 | + */ |
20106 | + | |
20107 | +#include "aufs.h" | |
20108 | + | |
4a4d8108 AM |
20109 | +enum { AuSRC, AuDST, AuSrcDst }; |
20110 | +enum { AuPARENT, AuCHILD, AuParentChild }; | |
1facf9fc | 20111 | + |
4a4d8108 AM |
20112 | +#define AuRen_ISDIR 1 |
20113 | +#define AuRen_ISSAMEDIR (1 << 1) | |
20114 | +#define AuRen_WHSRC (1 << 2) | |
20115 | +#define AuRen_WHDST (1 << 3) | |
20116 | +#define AuRen_MNT_WRITE (1 << 4) | |
20117 | +#define AuRen_DT_DSTDIR (1 << 5) | |
20118 | +#define AuRen_DIROPQ (1 << 6) | |
4a4d8108 | 20119 | +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name) |
7f207e10 AM |
20120 | +#define au_fset_ren(flags, name) \ |
20121 | + do { (flags) |= AuRen_##name; } while (0) | |
20122 | +#define au_fclr_ren(flags, name) \ | |
20123 | + do { (flags) &= ~AuRen_##name; } while (0) | |
1facf9fc | 20124 | + |
4a4d8108 AM |
20125 | +struct au_ren_args { |
20126 | + struct { | |
20127 | + struct dentry *dentry, *h_dentry, *parent, *h_parent, | |
20128 | + *wh_dentry; | |
20129 | + struct inode *dir, *inode; | |
20130 | + struct au_hinode *hdir; | |
20131 | + struct au_dtime dt[AuParentChild]; | |
20132 | + aufs_bindex_t bstart; | |
20133 | + } sd[AuSrcDst]; | |
1facf9fc | 20134 | + |
4a4d8108 AM |
20135 | +#define src_dentry sd[AuSRC].dentry |
20136 | +#define src_dir sd[AuSRC].dir | |
20137 | +#define src_inode sd[AuSRC].inode | |
20138 | +#define src_h_dentry sd[AuSRC].h_dentry | |
20139 | +#define src_parent sd[AuSRC].parent | |
20140 | +#define src_h_parent sd[AuSRC].h_parent | |
20141 | +#define src_wh_dentry sd[AuSRC].wh_dentry | |
20142 | +#define src_hdir sd[AuSRC].hdir | |
20143 | +#define src_h_dir sd[AuSRC].hdir->hi_inode | |
20144 | +#define src_dt sd[AuSRC].dt | |
20145 | +#define src_bstart sd[AuSRC].bstart | |
1facf9fc | 20146 | + |
4a4d8108 AM |
20147 | +#define dst_dentry sd[AuDST].dentry |
20148 | +#define dst_dir sd[AuDST].dir | |
20149 | +#define dst_inode sd[AuDST].inode | |
20150 | +#define dst_h_dentry sd[AuDST].h_dentry | |
20151 | +#define dst_parent sd[AuDST].parent | |
20152 | +#define dst_h_parent sd[AuDST].h_parent | |
20153 | +#define dst_wh_dentry sd[AuDST].wh_dentry | |
20154 | +#define dst_hdir sd[AuDST].hdir | |
20155 | +#define dst_h_dir sd[AuDST].hdir->hi_inode | |
20156 | +#define dst_dt sd[AuDST].dt | |
20157 | +#define dst_bstart sd[AuDST].bstart | |
20158 | + | |
20159 | + struct dentry *h_trap; | |
20160 | + struct au_branch *br; | |
20161 | + struct au_hinode *src_hinode; | |
20162 | + struct path h_path; | |
20163 | + struct au_nhash whlist; | |
027c5e7a | 20164 | + aufs_bindex_t btgt, src_bwh, src_bdiropq; |
1facf9fc | 20165 | + |
1308ab2a | 20166 | + unsigned int flags; |
1facf9fc | 20167 | + |
4a4d8108 AM |
20168 | + struct au_whtmp_rmdir *thargs; |
20169 | + struct dentry *h_dst; | |
20170 | +}; | |
1308ab2a | 20171 | + |
4a4d8108 | 20172 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 20173 | + |
4a4d8108 AM |
20174 | +/* |
20175 | + * functions for reverting. | |
20176 | + * when an error happened in a single rename systemcall, we should revert | |
20177 | + * everything as if nothing happend. | |
20178 | + * we don't need to revert the copied-up/down the parent dir since they are | |
20179 | + * harmless. | |
20180 | + */ | |
1facf9fc | 20181 | + |
4a4d8108 AM |
20182 | +#define RevertFailure(fmt, ...) do { \ |
20183 | + AuIOErr("revert failure: " fmt " (%d, %d)\n", \ | |
20184 | + ##__VA_ARGS__, err, rerr); \ | |
20185 | + err = -EIO; \ | |
20186 | +} while (0) | |
1facf9fc | 20187 | + |
4a4d8108 | 20188 | +static void au_ren_rev_diropq(int err, struct au_ren_args *a) |
1facf9fc | 20189 | +{ |
4a4d8108 | 20190 | + int rerr; |
1facf9fc | 20191 | + |
4a4d8108 AM |
20192 | + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD); |
20193 | + rerr = au_diropq_remove(a->src_dentry, a->btgt); | |
20194 | + au_hn_imtx_unlock(a->src_hinode); | |
027c5e7a | 20195 | + au_set_dbdiropq(a->src_dentry, a->src_bdiropq); |
4a4d8108 | 20196 | + if (rerr) |
523b37e3 | 20197 | + RevertFailure("remove diropq %pd", a->src_dentry); |
4a4d8108 | 20198 | +} |
1facf9fc | 20199 | + |
4a4d8108 AM |
20200 | +static void au_ren_rev_rename(int err, struct au_ren_args *a) |
20201 | +{ | |
20202 | + int rerr; | |
523b37e3 | 20203 | + struct inode *delegated; |
1facf9fc | 20204 | + |
b4510431 AM |
20205 | + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, |
20206 | + a->src_h_parent); | |
4a4d8108 AM |
20207 | + rerr = PTR_ERR(a->h_path.dentry); |
20208 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 20209 | + RevertFailure("lkup one %pd", a->src_dentry); |
4a4d8108 | 20210 | + return; |
1facf9fc | 20211 | + } |
20212 | + | |
523b37e3 | 20213 | + delegated = NULL; |
4a4d8108 AM |
20214 | + rerr = vfsub_rename(a->dst_h_dir, |
20215 | + au_h_dptr(a->src_dentry, a->btgt), | |
523b37e3 AM |
20216 | + a->src_h_dir, &a->h_path, &delegated); |
20217 | + if (unlikely(rerr == -EWOULDBLOCK)) { | |
20218 | + pr_warn("cannot retry for NFSv4 delegation" | |
20219 | + " for an internal rename\n"); | |
20220 | + iput(delegated); | |
20221 | + } | |
4a4d8108 AM |
20222 | + d_drop(a->h_path.dentry); |
20223 | + dput(a->h_path.dentry); | |
20224 | + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */ | |
20225 | + if (rerr) | |
523b37e3 | 20226 | + RevertFailure("rename %pd", a->src_dentry); |
1facf9fc | 20227 | +} |
20228 | + | |
4a4d8108 | 20229 | +static void au_ren_rev_whtmp(int err, struct au_ren_args *a) |
1facf9fc | 20230 | +{ |
4a4d8108 | 20231 | + int rerr; |
523b37e3 | 20232 | + struct inode *delegated; |
dece6358 | 20233 | + |
b4510431 AM |
20234 | + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, |
20235 | + a->dst_h_parent); | |
4a4d8108 AM |
20236 | + rerr = PTR_ERR(a->h_path.dentry); |
20237 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 20238 | + RevertFailure("lkup one %pd", a->dst_dentry); |
4a4d8108 AM |
20239 | + return; |
20240 | + } | |
5527c038 | 20241 | + if (d_is_positive(a->h_path.dentry)) { |
4a4d8108 AM |
20242 | + d_drop(a->h_path.dentry); |
20243 | + dput(a->h_path.dentry); | |
20244 | + return; | |
dece6358 AM |
20245 | + } |
20246 | + | |
523b37e3 AM |
20247 | + delegated = NULL; |
20248 | + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path, | |
20249 | + &delegated); | |
20250 | + if (unlikely(rerr == -EWOULDBLOCK)) { | |
20251 | + pr_warn("cannot retry for NFSv4 delegation" | |
20252 | + " for an internal rename\n"); | |
20253 | + iput(delegated); | |
20254 | + } | |
4a4d8108 AM |
20255 | + d_drop(a->h_path.dentry); |
20256 | + dput(a->h_path.dentry); | |
20257 | + if (!rerr) | |
20258 | + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst)); | |
20259 | + else | |
523b37e3 | 20260 | + RevertFailure("rename %pd", a->h_dst); |
4a4d8108 | 20261 | +} |
1308ab2a | 20262 | + |
4a4d8108 AM |
20263 | +static void au_ren_rev_whsrc(int err, struct au_ren_args *a) |
20264 | +{ | |
20265 | + int rerr; | |
1308ab2a | 20266 | + |
4a4d8108 AM |
20267 | + a->h_path.dentry = a->src_wh_dentry; |
20268 | + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry); | |
027c5e7a | 20269 | + au_set_dbwh(a->src_dentry, a->src_bwh); |
4a4d8108 | 20270 | + if (rerr) |
523b37e3 | 20271 | + RevertFailure("unlink %pd", a->src_wh_dentry); |
4a4d8108 | 20272 | +} |
4a4d8108 | 20273 | +#undef RevertFailure |
1facf9fc | 20274 | + |
1308ab2a | 20275 | +/* ---------------------------------------------------------------------- */ |
20276 | + | |
4a4d8108 AM |
20277 | +/* |
20278 | + * when we have to copyup the renaming entry, do it with the rename-target name | |
20279 | + * in order to minimize the cost (the later actual rename is unnecessary). | |
20280 | + * otherwise rename it on the target branch. | |
20281 | + */ | |
20282 | +static int au_ren_or_cpup(struct au_ren_args *a) | |
1facf9fc | 20283 | +{ |
dece6358 | 20284 | + int err; |
4a4d8108 | 20285 | + struct dentry *d; |
523b37e3 | 20286 | + struct inode *delegated; |
1facf9fc | 20287 | + |
4a4d8108 AM |
20288 | + d = a->src_dentry; |
20289 | + if (au_dbstart(d) == a->btgt) { | |
20290 | + a->h_path.dentry = a->dst_h_dentry; | |
20291 | + if (au_ftest_ren(a->flags, DIROPQ) | |
20292 | + && au_dbdiropq(d) == a->btgt) | |
20293 | + au_fclr_ren(a->flags, DIROPQ); | |
20294 | + AuDebugOn(au_dbstart(d) != a->btgt); | |
523b37e3 | 20295 | + delegated = NULL; |
4a4d8108 | 20296 | + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt), |
523b37e3 AM |
20297 | + a->dst_h_dir, &a->h_path, &delegated); |
20298 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20299 | + pr_warn("cannot retry for NFSv4 delegation" | |
20300 | + " for an internal rename\n"); | |
20301 | + iput(delegated); | |
20302 | + } | |
c2b27bf2 | 20303 | + } else |
86dc4139 | 20304 | + BUG(); |
1308ab2a | 20305 | + |
027c5e7a AM |
20306 | + if (!err && a->h_dst) |
20307 | + /* it will be set to dinfo later */ | |
20308 | + dget(a->h_dst); | |
1facf9fc | 20309 | + |
dece6358 AM |
20310 | + return err; |
20311 | +} | |
1facf9fc | 20312 | + |
4a4d8108 AM |
20313 | +/* cf. aufs_rmdir() */ |
20314 | +static int au_ren_del_whtmp(struct au_ren_args *a) | |
dece6358 | 20315 | +{ |
4a4d8108 AM |
20316 | + int err; |
20317 | + struct inode *dir; | |
1facf9fc | 20318 | + |
4a4d8108 AM |
20319 | + dir = a->dst_dir; |
20320 | + SiMustAnyLock(dir->i_sb); | |
20321 | + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt, | |
20322 | + au_sbi(dir->i_sb)->si_dirwh) | |
20323 | + || au_test_fs_remote(a->h_dst->d_sb)) { | |
20324 | + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist); | |
20325 | + if (unlikely(err)) | |
523b37e3 AM |
20326 | + pr_warn("failed removing whtmp dir %pd (%d), " |
20327 | + "ignored.\n", a->h_dst, err); | |
4a4d8108 AM |
20328 | + } else { |
20329 | + au_nhash_wh_free(&a->thargs->whlist); | |
20330 | + a->thargs->whlist = a->whlist; | |
20331 | + a->whlist.nh_num = 0; | |
20332 | + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs); | |
20333 | + dput(a->h_dst); | |
20334 | + a->thargs = NULL; | |
20335 | + } | |
20336 | + | |
20337 | + return 0; | |
1308ab2a | 20338 | +} |
1facf9fc | 20339 | + |
4a4d8108 AM |
20340 | +/* make it 'opaque' dir. */ |
20341 | +static int au_ren_diropq(struct au_ren_args *a) | |
20342 | +{ | |
20343 | + int err; | |
20344 | + struct dentry *diropq; | |
1facf9fc | 20345 | + |
4a4d8108 | 20346 | + err = 0; |
027c5e7a | 20347 | + a->src_bdiropq = au_dbdiropq(a->src_dentry); |
4a4d8108 AM |
20348 | + a->src_hinode = au_hi(a->src_inode, a->btgt); |
20349 | + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD); | |
20350 | + diropq = au_diropq_create(a->src_dentry, a->btgt); | |
20351 | + au_hn_imtx_unlock(a->src_hinode); | |
20352 | + if (IS_ERR(diropq)) | |
20353 | + err = PTR_ERR(diropq); | |
076b876e AM |
20354 | + else |
20355 | + dput(diropq); | |
1facf9fc | 20356 | + |
4a4d8108 AM |
20357 | + return err; |
20358 | +} | |
1facf9fc | 20359 | + |
4a4d8108 AM |
20360 | +static int do_rename(struct au_ren_args *a) |
20361 | +{ | |
20362 | + int err; | |
20363 | + struct dentry *d, *h_d; | |
1facf9fc | 20364 | + |
4a4d8108 AM |
20365 | + /* prepare workqueue args for asynchronous rmdir */ |
20366 | + h_d = a->dst_h_dentry; | |
5527c038 | 20367 | + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) { |
4a4d8108 AM |
20368 | + err = -ENOMEM; |
20369 | + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS); | |
20370 | + if (unlikely(!a->thargs)) | |
20371 | + goto out; | |
20372 | + a->h_dst = dget(h_d); | |
20373 | + } | |
1facf9fc | 20374 | + |
4a4d8108 AM |
20375 | + /* create whiteout for src_dentry */ |
20376 | + if (au_ftest_ren(a->flags, WHSRC)) { | |
027c5e7a AM |
20377 | + a->src_bwh = au_dbwh(a->src_dentry); |
20378 | + AuDebugOn(a->src_bwh >= 0); | |
4a4d8108 AM |
20379 | + a->src_wh_dentry |
20380 | + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent); | |
20381 | + err = PTR_ERR(a->src_wh_dentry); | |
20382 | + if (IS_ERR(a->src_wh_dentry)) | |
20383 | + goto out_thargs; | |
20384 | + } | |
1facf9fc | 20385 | + |
4a4d8108 AM |
20386 | + /* lookup whiteout for dentry */ |
20387 | + if (au_ftest_ren(a->flags, WHDST)) { | |
20388 | + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name, | |
20389 | + a->br); | |
20390 | + err = PTR_ERR(h_d); | |
20391 | + if (IS_ERR(h_d)) | |
20392 | + goto out_whsrc; | |
5527c038 | 20393 | + if (d_is_negative(h_d)) |
4a4d8108 AM |
20394 | + dput(h_d); |
20395 | + else | |
20396 | + a->dst_wh_dentry = h_d; | |
20397 | + } | |
1facf9fc | 20398 | + |
4a4d8108 AM |
20399 | + /* rename dentry to tmpwh */ |
20400 | + if (a->thargs) { | |
20401 | + err = au_whtmp_ren(a->dst_h_dentry, a->br); | |
20402 | + if (unlikely(err)) | |
20403 | + goto out_whdst; | |
dece6358 | 20404 | + |
4a4d8108 AM |
20405 | + d = a->dst_dentry; |
20406 | + au_set_h_dptr(d, a->btgt, NULL); | |
86dc4139 | 20407 | + err = au_lkup_neg(d, a->btgt, /*wh*/0); |
4a4d8108 AM |
20408 | + if (unlikely(err)) |
20409 | + goto out_whtmp; | |
20410 | + a->dst_h_dentry = au_h_dptr(d, a->btgt); | |
20411 | + } | |
1facf9fc | 20412 | + |
5527c038 | 20413 | + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_bstart != a->btgt); |
1facf9fc | 20414 | + |
4a4d8108 AM |
20415 | + /* rename by vfs_rename or cpup */ |
20416 | + d = a->dst_dentry; | |
20417 | + if (au_ftest_ren(a->flags, ISDIR) | |
20418 | + && (a->dst_wh_dentry | |
20419 | + || au_dbdiropq(d) == a->btgt | |
20420 | + /* hide the lower to keep xino */ | |
20421 | + || a->btgt < au_dbend(d) | |
20422 | + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ))) | |
20423 | + au_fset_ren(a->flags, DIROPQ); | |
20424 | + err = au_ren_or_cpup(a); | |
20425 | + if (unlikely(err)) | |
20426 | + /* leave the copied-up one */ | |
20427 | + goto out_whtmp; | |
1308ab2a | 20428 | + |
4a4d8108 AM |
20429 | + /* make dir opaque */ |
20430 | + if (au_ftest_ren(a->flags, DIROPQ)) { | |
20431 | + err = au_ren_diropq(a); | |
20432 | + if (unlikely(err)) | |
20433 | + goto out_rename; | |
20434 | + } | |
1308ab2a | 20435 | + |
4a4d8108 AM |
20436 | + /* update target timestamps */ |
20437 | + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt); | |
20438 | + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt); | |
20439 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
5527c038 | 20440 | + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
1facf9fc | 20441 | + |
4a4d8108 AM |
20442 | + /* remove whiteout for dentry */ |
20443 | + if (a->dst_wh_dentry) { | |
20444 | + a->h_path.dentry = a->dst_wh_dentry; | |
20445 | + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path, | |
20446 | + a->dst_dentry); | |
20447 | + if (unlikely(err)) | |
20448 | + goto out_diropq; | |
20449 | + } | |
1facf9fc | 20450 | + |
4a4d8108 AM |
20451 | + /* remove whtmp */ |
20452 | + if (a->thargs) | |
20453 | + au_ren_del_whtmp(a); /* ignore this error */ | |
1308ab2a | 20454 | + |
076b876e | 20455 | + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0); |
4a4d8108 AM |
20456 | + err = 0; |
20457 | + goto out_success; | |
20458 | + | |
4f0767ce | 20459 | +out_diropq: |
4a4d8108 AM |
20460 | + if (au_ftest_ren(a->flags, DIROPQ)) |
20461 | + au_ren_rev_diropq(err, a); | |
4f0767ce | 20462 | +out_rename: |
7e9cd9fe | 20463 | + au_ren_rev_rename(err, a); |
027c5e7a | 20464 | + dput(a->h_dst); |
4f0767ce | 20465 | +out_whtmp: |
4a4d8108 AM |
20466 | + if (a->thargs) |
20467 | + au_ren_rev_whtmp(err, a); | |
4f0767ce | 20468 | +out_whdst: |
4a4d8108 AM |
20469 | + dput(a->dst_wh_dentry); |
20470 | + a->dst_wh_dentry = NULL; | |
4f0767ce | 20471 | +out_whsrc: |
4a4d8108 AM |
20472 | + if (a->src_wh_dentry) |
20473 | + au_ren_rev_whsrc(err, a); | |
4f0767ce | 20474 | +out_success: |
4a4d8108 AM |
20475 | + dput(a->src_wh_dentry); |
20476 | + dput(a->dst_wh_dentry); | |
4f0767ce | 20477 | +out_thargs: |
4a4d8108 AM |
20478 | + if (a->thargs) { |
20479 | + dput(a->h_dst); | |
20480 | + au_whtmp_rmdir_free(a->thargs); | |
20481 | + a->thargs = NULL; | |
20482 | + } | |
4f0767ce | 20483 | +out: |
4a4d8108 | 20484 | + return err; |
dece6358 | 20485 | +} |
1facf9fc | 20486 | + |
1308ab2a | 20487 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20488 | + |
4a4d8108 AM |
20489 | +/* |
20490 | + * test if @dentry dir can be rename destination or not. | |
20491 | + * success means, it is a logically empty dir. | |
20492 | + */ | |
20493 | +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist) | |
1308ab2a | 20494 | +{ |
4a4d8108 | 20495 | + return au_test_empty(dentry, whlist); |
1308ab2a | 20496 | +} |
1facf9fc | 20497 | + |
4a4d8108 AM |
20498 | +/* |
20499 | + * test if @dentry dir can be rename source or not. | |
20500 | + * if it can, return 0 and @children is filled. | |
20501 | + * success means, | |
20502 | + * - it is a logically empty dir. | |
20503 | + * - or, it exists on writable branch and has no children including whiteouts | |
20504 | + * on the lower branch. | |
20505 | + */ | |
20506 | +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt) | |
20507 | +{ | |
20508 | + int err; | |
20509 | + unsigned int rdhash; | |
20510 | + aufs_bindex_t bstart; | |
1facf9fc | 20511 | + |
4a4d8108 AM |
20512 | + bstart = au_dbstart(dentry); |
20513 | + if (bstart != btgt) { | |
20514 | + struct au_nhash whlist; | |
dece6358 | 20515 | + |
4a4d8108 AM |
20516 | + SiMustAnyLock(dentry->d_sb); |
20517 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; | |
20518 | + if (!rdhash) | |
20519 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, | |
20520 | + dentry)); | |
20521 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
20522 | + if (unlikely(err)) | |
20523 | + goto out; | |
20524 | + err = au_test_empty(dentry, &whlist); | |
20525 | + au_nhash_wh_free(&whlist); | |
20526 | + goto out; | |
20527 | + } | |
dece6358 | 20528 | + |
4a4d8108 AM |
20529 | + if (bstart == au_dbtaildir(dentry)) |
20530 | + return 0; /* success */ | |
dece6358 | 20531 | + |
4a4d8108 | 20532 | + err = au_test_empty_lower(dentry); |
1facf9fc | 20533 | + |
4f0767ce | 20534 | +out: |
4a4d8108 AM |
20535 | + if (err == -ENOTEMPTY) { |
20536 | + AuWarn1("renaming dir who has child(ren) on multiple branches," | |
20537 | + " is not supported\n"); | |
20538 | + err = -EXDEV; | |
20539 | + } | |
20540 | + return err; | |
20541 | +} | |
1308ab2a | 20542 | + |
4a4d8108 AM |
20543 | +/* side effect: sets whlist and h_dentry */ |
20544 | +static int au_ren_may_dir(struct au_ren_args *a) | |
1308ab2a | 20545 | +{ |
4a4d8108 AM |
20546 | + int err; |
20547 | + unsigned int rdhash; | |
20548 | + struct dentry *d; | |
1facf9fc | 20549 | + |
4a4d8108 AM |
20550 | + d = a->dst_dentry; |
20551 | + SiMustAnyLock(d->d_sb); | |
1facf9fc | 20552 | + |
4a4d8108 AM |
20553 | + err = 0; |
20554 | + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) { | |
20555 | + rdhash = au_sbi(d->d_sb)->si_rdhash; | |
20556 | + if (!rdhash) | |
20557 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d)); | |
20558 | + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS); | |
20559 | + if (unlikely(err)) | |
20560 | + goto out; | |
1308ab2a | 20561 | + |
4a4d8108 AM |
20562 | + au_set_dbstart(d, a->dst_bstart); |
20563 | + err = may_rename_dstdir(d, &a->whlist); | |
20564 | + au_set_dbstart(d, a->btgt); | |
20565 | + } | |
20566 | + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d)); | |
20567 | + if (unlikely(err)) | |
20568 | + goto out; | |
20569 | + | |
20570 | + d = a->src_dentry; | |
20571 | + a->src_h_dentry = au_h_dptr(d, au_dbstart(d)); | |
20572 | + if (au_ftest_ren(a->flags, ISDIR)) { | |
20573 | + err = may_rename_srcdir(d, a->btgt); | |
20574 | + if (unlikely(err)) { | |
20575 | + au_nhash_wh_free(&a->whlist); | |
20576 | + a->whlist.nh_num = 0; | |
20577 | + } | |
20578 | + } | |
4f0767ce | 20579 | +out: |
4a4d8108 | 20580 | + return err; |
1facf9fc | 20581 | +} |
20582 | + | |
4a4d8108 | 20583 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20584 | + |
4a4d8108 AM |
20585 | +/* |
20586 | + * simple tests for rename. | |
20587 | + * following the checks in vfs, plus the parent-child relationship. | |
20588 | + */ | |
20589 | +static int au_may_ren(struct au_ren_args *a) | |
20590 | +{ | |
20591 | + int err, isdir; | |
20592 | + struct inode *h_inode; | |
1facf9fc | 20593 | + |
4a4d8108 AM |
20594 | + if (a->src_bstart == a->btgt) { |
20595 | + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent, | |
20596 | + au_ftest_ren(a->flags, ISDIR)); | |
20597 | + if (unlikely(err)) | |
20598 | + goto out; | |
20599 | + err = -EINVAL; | |
20600 | + if (unlikely(a->src_h_dentry == a->h_trap)) | |
20601 | + goto out; | |
20602 | + } | |
1facf9fc | 20603 | + |
4a4d8108 AM |
20604 | + err = 0; |
20605 | + if (a->dst_bstart != a->btgt) | |
20606 | + goto out; | |
1facf9fc | 20607 | + |
027c5e7a AM |
20608 | + err = -ENOTEMPTY; |
20609 | + if (unlikely(a->dst_h_dentry == a->h_trap)) | |
20610 | + goto out; | |
20611 | + | |
4a4d8108 | 20612 | + err = -EIO; |
4a4d8108 | 20613 | + isdir = !!au_ftest_ren(a->flags, ISDIR); |
5527c038 JR |
20614 | + if (d_really_is_negative(a->dst_dentry)) { |
20615 | + if (d_is_negative(a->dst_h_dentry)) | |
20616 | + err = au_may_add(a->dst_dentry, a->btgt, | |
20617 | + a->dst_h_parent, isdir); | |
4a4d8108 | 20618 | + } else { |
5527c038 | 20619 | + if (unlikely(d_is_negative(a->dst_h_dentry))) |
4a4d8108 | 20620 | + goto out; |
5527c038 JR |
20621 | + h_inode = d_inode(a->dst_h_dentry); |
20622 | + if (h_inode->i_nlink) | |
20623 | + err = au_may_del(a->dst_dentry, a->btgt, | |
20624 | + a->dst_h_parent, isdir); | |
4a4d8108 | 20625 | + } |
1facf9fc | 20626 | + |
4f0767ce | 20627 | +out: |
4a4d8108 AM |
20628 | + if (unlikely(err == -ENOENT || err == -EEXIST)) |
20629 | + err = -EIO; | |
20630 | + AuTraceErr(err); | |
20631 | + return err; | |
20632 | +} | |
1facf9fc | 20633 | + |
1308ab2a | 20634 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20635 | + |
4a4d8108 AM |
20636 | +/* |
20637 | + * locking order | |
20638 | + * (VFS) | |
20639 | + * - src_dir and dir by lock_rename() | |
20640 | + * - inode if exitsts | |
20641 | + * (aufs) | |
20642 | + * - lock all | |
20643 | + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls, | |
20644 | + * + si_read_lock | |
20645 | + * + di_write_lock2_child() | |
20646 | + * + di_write_lock_child() | |
20647 | + * + ii_write_lock_child() | |
20648 | + * + di_write_lock_child2() | |
20649 | + * + ii_write_lock_child2() | |
20650 | + * + src_parent and parent | |
20651 | + * + di_write_lock_parent() | |
20652 | + * + ii_write_lock_parent() | |
20653 | + * + di_write_lock_parent2() | |
20654 | + * + ii_write_lock_parent2() | |
20655 | + * + lower src_dir and dir by vfsub_lock_rename() | |
20656 | + * + verify the every relationships between child and parent. if any | |
20657 | + * of them failed, unlock all and return -EBUSY. | |
20658 | + */ | |
20659 | +static void au_ren_unlock(struct au_ren_args *a) | |
1308ab2a | 20660 | +{ |
4a4d8108 AM |
20661 | + vfsub_unlock_rename(a->src_h_parent, a->src_hdir, |
20662 | + a->dst_h_parent, a->dst_hdir); | |
86dc4139 AM |
20663 | + if (au_ftest_ren(a->flags, MNT_WRITE)) |
20664 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); | |
1308ab2a | 20665 | +} |
20666 | + | |
4a4d8108 | 20667 | +static int au_ren_lock(struct au_ren_args *a) |
1308ab2a | 20668 | +{ |
4a4d8108 AM |
20669 | + int err; |
20670 | + unsigned int udba; | |
1308ab2a | 20671 | + |
4a4d8108 AM |
20672 | + err = 0; |
20673 | + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt); | |
20674 | + a->src_hdir = au_hi(a->src_dir, a->btgt); | |
20675 | + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt); | |
20676 | + a->dst_hdir = au_hi(a->dst_dir, a->btgt); | |
86dc4139 AM |
20677 | + |
20678 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); | |
20679 | + if (unlikely(err)) | |
20680 | + goto out; | |
20681 | + au_fset_ren(a->flags, MNT_WRITE); | |
4a4d8108 AM |
20682 | + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir, |
20683 | + a->dst_h_parent, a->dst_hdir); | |
20684 | + udba = au_opt_udba(a->src_dentry->d_sb); | |
5527c038 JR |
20685 | + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent) |
20686 | + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent))) | |
4a4d8108 AM |
20687 | + err = au_busy_or_stale(); |
20688 | + if (!err && au_dbstart(a->src_dentry) == a->btgt) | |
20689 | + err = au_h_verify(a->src_h_dentry, udba, | |
5527c038 | 20690 | + d_inode(a->src_h_parent), a->src_h_parent, |
4a4d8108 AM |
20691 | + a->br); |
20692 | + if (!err && au_dbstart(a->dst_dentry) == a->btgt) | |
20693 | + err = au_h_verify(a->dst_h_dentry, udba, | |
5527c038 | 20694 | + d_inode(a->dst_h_parent), a->dst_h_parent, |
4a4d8108 | 20695 | + a->br); |
86dc4139 | 20696 | + if (!err) |
4a4d8108 | 20697 | + goto out; /* success */ |
4a4d8108 AM |
20698 | + |
20699 | + err = au_busy_or_stale(); | |
4a4d8108 | 20700 | + au_ren_unlock(a); |
86dc4139 | 20701 | + |
4f0767ce | 20702 | +out: |
4a4d8108 | 20703 | + return err; |
1facf9fc | 20704 | +} |
20705 | + | |
20706 | +/* ---------------------------------------------------------------------- */ | |
20707 | + | |
4a4d8108 | 20708 | +static void au_ren_refresh_dir(struct au_ren_args *a) |
1facf9fc | 20709 | +{ |
4a4d8108 | 20710 | + struct inode *dir; |
dece6358 | 20711 | + |
4a4d8108 AM |
20712 | + dir = a->dst_dir; |
20713 | + dir->i_version++; | |
20714 | + if (au_ftest_ren(a->flags, ISDIR)) { | |
20715 | + /* is this updating defined in POSIX? */ | |
20716 | + au_cpup_attr_timesizes(a->src_inode); | |
20717 | + au_cpup_attr_nlink(dir, /*force*/1); | |
4a4d8108 | 20718 | + } |
027c5e7a | 20719 | + |
b912730e | 20720 | + au_dir_ts(dir, a->btgt); |
dece6358 | 20721 | + |
4a4d8108 AM |
20722 | + if (au_ftest_ren(a->flags, ISSAMEDIR)) |
20723 | + return; | |
dece6358 | 20724 | + |
4a4d8108 AM |
20725 | + dir = a->src_dir; |
20726 | + dir->i_version++; | |
20727 | + if (au_ftest_ren(a->flags, ISDIR)) | |
20728 | + au_cpup_attr_nlink(dir, /*force*/1); | |
b912730e | 20729 | + au_dir_ts(dir, a->btgt); |
1facf9fc | 20730 | +} |
20731 | + | |
4a4d8108 | 20732 | +static void au_ren_refresh(struct au_ren_args *a) |
1facf9fc | 20733 | +{ |
4a4d8108 AM |
20734 | + aufs_bindex_t bend, bindex; |
20735 | + struct dentry *d, *h_d; | |
20736 | + struct inode *i, *h_i; | |
20737 | + struct super_block *sb; | |
dece6358 | 20738 | + |
027c5e7a AM |
20739 | + d = a->dst_dentry; |
20740 | + d_drop(d); | |
20741 | + if (a->h_dst) | |
20742 | + /* already dget-ed by au_ren_or_cpup() */ | |
20743 | + au_set_h_dptr(d, a->btgt, a->h_dst); | |
20744 | + | |
20745 | + i = a->dst_inode; | |
20746 | + if (i) { | |
20747 | + if (!au_ftest_ren(a->flags, ISDIR)) | |
20748 | + vfsub_drop_nlink(i); | |
20749 | + else { | |
20750 | + vfsub_dead_dir(i); | |
20751 | + au_cpup_attr_timesizes(i); | |
20752 | + } | |
20753 | + au_update_dbrange(d, /*do_put_zero*/1); | |
20754 | + } else { | |
20755 | + bend = a->btgt; | |
20756 | + for (bindex = au_dbstart(d); bindex < bend; bindex++) | |
20757 | + au_set_h_dptr(d, bindex, NULL); | |
20758 | + bend = au_dbend(d); | |
20759 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) | |
20760 | + au_set_h_dptr(d, bindex, NULL); | |
20761 | + au_update_dbrange(d, /*do_put_zero*/0); | |
20762 | + } | |
20763 | + | |
4a4d8108 AM |
20764 | + d = a->src_dentry; |
20765 | + au_set_dbwh(d, -1); | |
20766 | + bend = au_dbend(d); | |
20767 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) { | |
20768 | + h_d = au_h_dptr(d, bindex); | |
20769 | + if (h_d) | |
20770 | + au_set_h_dptr(d, bindex, NULL); | |
20771 | + } | |
20772 | + au_set_dbend(d, a->btgt); | |
20773 | + | |
20774 | + sb = d->d_sb; | |
20775 | + i = a->src_inode; | |
20776 | + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i)) | |
20777 | + return; /* success */ | |
20778 | + | |
20779 | + bend = au_ibend(i); | |
20780 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) { | |
20781 | + h_i = au_h_iptr(i, bindex); | |
20782 | + if (h_i) { | |
20783 | + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0); | |
20784 | + /* ignore this error */ | |
20785 | + au_set_h_iptr(i, bindex, NULL, 0); | |
20786 | + } | |
20787 | + } | |
20788 | + au_set_ibend(i, a->btgt); | |
1308ab2a | 20789 | +} |
dece6358 | 20790 | + |
4a4d8108 AM |
20791 | +/* ---------------------------------------------------------------------- */ |
20792 | + | |
20793 | +/* mainly for link(2) and rename(2) */ | |
20794 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt) | |
1308ab2a | 20795 | +{ |
4a4d8108 AM |
20796 | + aufs_bindex_t bdiropq, bwh; |
20797 | + struct dentry *parent; | |
20798 | + struct au_branch *br; | |
20799 | + | |
20800 | + parent = dentry->d_parent; | |
5527c038 | 20801 | + IMustLock(d_inode(parent)); /* dir is locked */ |
4a4d8108 AM |
20802 | + |
20803 | + bdiropq = au_dbdiropq(parent); | |
20804 | + bwh = au_dbwh(dentry); | |
20805 | + br = au_sbr(dentry->d_sb, btgt); | |
20806 | + if (au_br_rdonly(br) | |
20807 | + || (0 <= bdiropq && bdiropq < btgt) | |
20808 | + || (0 <= bwh && bwh < btgt)) | |
20809 | + btgt = -1; | |
20810 | + | |
20811 | + AuDbg("btgt %d\n", btgt); | |
20812 | + return btgt; | |
1facf9fc | 20813 | +} |
20814 | + | |
4a4d8108 AM |
20815 | +/* sets src_bstart, dst_bstart and btgt */ |
20816 | +static int au_ren_wbr(struct au_ren_args *a) | |
1facf9fc | 20817 | +{ |
4a4d8108 AM |
20818 | + int err; |
20819 | + struct au_wr_dir_args wr_dir_args = { | |
20820 | + /* .force_btgt = -1, */ | |
20821 | + .flags = AuWrDir_ADD_ENTRY | |
20822 | + }; | |
dece6358 | 20823 | + |
4a4d8108 AM |
20824 | + a->src_bstart = au_dbstart(a->src_dentry); |
20825 | + a->dst_bstart = au_dbstart(a->dst_dentry); | |
20826 | + if (au_ftest_ren(a->flags, ISDIR)) | |
20827 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); | |
20828 | + wr_dir_args.force_btgt = a->src_bstart; | |
20829 | + if (a->dst_inode && a->dst_bstart < a->src_bstart) | |
20830 | + wr_dir_args.force_btgt = a->dst_bstart; | |
20831 | + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt); | |
20832 | + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args); | |
20833 | + a->btgt = err; | |
dece6358 | 20834 | + |
4a4d8108 | 20835 | + return err; |
1facf9fc | 20836 | +} |
20837 | + | |
4a4d8108 | 20838 | +static void au_ren_dt(struct au_ren_args *a) |
1facf9fc | 20839 | +{ |
4a4d8108 AM |
20840 | + a->h_path.dentry = a->src_h_parent; |
20841 | + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path); | |
20842 | + if (!au_ftest_ren(a->flags, ISSAMEDIR)) { | |
20843 | + a->h_path.dentry = a->dst_h_parent; | |
20844 | + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path); | |
20845 | + } | |
1facf9fc | 20846 | + |
4a4d8108 AM |
20847 | + au_fclr_ren(a->flags, DT_DSTDIR); |
20848 | + if (!au_ftest_ren(a->flags, ISDIR)) | |
20849 | + return; | |
dece6358 | 20850 | + |
4a4d8108 AM |
20851 | + a->h_path.dentry = a->src_h_dentry; |
20852 | + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path); | |
5527c038 | 20853 | + if (d_is_positive(a->dst_h_dentry)) { |
4a4d8108 AM |
20854 | + au_fset_ren(a->flags, DT_DSTDIR); |
20855 | + a->h_path.dentry = a->dst_h_dentry; | |
20856 | + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path); | |
20857 | + } | |
1308ab2a | 20858 | +} |
dece6358 | 20859 | + |
4a4d8108 | 20860 | +static void au_ren_rev_dt(int err, struct au_ren_args *a) |
1308ab2a | 20861 | +{ |
4a4d8108 AM |
20862 | + struct dentry *h_d; |
20863 | + struct mutex *h_mtx; | |
20864 | + | |
20865 | + au_dtime_revert(a->src_dt + AuPARENT); | |
20866 | + if (!au_ftest_ren(a->flags, ISSAMEDIR)) | |
20867 | + au_dtime_revert(a->dst_dt + AuPARENT); | |
20868 | + | |
20869 | + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) { | |
20870 | + h_d = a->src_dt[AuCHILD].dt_h_path.dentry; | |
5527c038 | 20871 | + h_mtx = &d_inode(h_d)->i_mutex; |
4a4d8108 AM |
20872 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); |
20873 | + au_dtime_revert(a->src_dt + AuCHILD); | |
20874 | + mutex_unlock(h_mtx); | |
20875 | + | |
20876 | + if (au_ftest_ren(a->flags, DT_DSTDIR)) { | |
20877 | + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry; | |
5527c038 | 20878 | + h_mtx = &d_inode(h_d)->i_mutex; |
4a4d8108 AM |
20879 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); |
20880 | + au_dtime_revert(a->dst_dt + AuCHILD); | |
20881 | + mutex_unlock(h_mtx); | |
1facf9fc | 20882 | + } |
20883 | + } | |
20884 | +} | |
20885 | + | |
4a4d8108 AM |
20886 | +/* ---------------------------------------------------------------------- */ |
20887 | + | |
20888 | +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, | |
20889 | + struct inode *_dst_dir, struct dentry *_dst_dentry) | |
1facf9fc | 20890 | +{ |
e49829fe | 20891 | + int err, flags; |
4a4d8108 AM |
20892 | + /* reduce stack space */ |
20893 | + struct au_ren_args *a; | |
20894 | + | |
523b37e3 | 20895 | + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry); |
4a4d8108 AM |
20896 | + IMustLock(_src_dir); |
20897 | + IMustLock(_dst_dir); | |
20898 | + | |
20899 | + err = -ENOMEM; | |
20900 | + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE); | |
20901 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
20902 | + if (unlikely(!a)) | |
20903 | + goto out; | |
20904 | + | |
20905 | + a->src_dir = _src_dir; | |
20906 | + a->src_dentry = _src_dentry; | |
5527c038 JR |
20907 | + a->src_inode = NULL; |
20908 | + if (d_really_is_positive(a->src_dentry)) | |
20909 | + a->src_inode = d_inode(a->src_dentry); | |
4a4d8108 AM |
20910 | + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */ |
20911 | + a->dst_dir = _dst_dir; | |
20912 | + a->dst_dentry = _dst_dentry; | |
5527c038 JR |
20913 | + a->dst_inode = NULL; |
20914 | + if (d_really_is_positive(a->dst_dentry)) | |
20915 | + a->dst_inode = d_inode(a->dst_dentry); | |
4a4d8108 AM |
20916 | + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */ |
20917 | + if (a->dst_inode) { | |
20918 | + IMustLock(a->dst_inode); | |
20919 | + au_igrab(a->dst_inode); | |
1facf9fc | 20920 | + } |
1facf9fc | 20921 | + |
4a4d8108 | 20922 | + err = -ENOTDIR; |
027c5e7a | 20923 | + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN; |
2000de60 | 20924 | + if (d_is_dir(a->src_dentry)) { |
4a4d8108 | 20925 | + au_fset_ren(a->flags, ISDIR); |
5527c038 | 20926 | + if (unlikely(d_really_is_positive(a->dst_dentry) |
2000de60 | 20927 | + && !d_is_dir(a->dst_dentry))) |
4a4d8108 | 20928 | + goto out_free; |
e49829fe JR |
20929 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
20930 | + AuLock_DIR | flags); | |
4a4d8108 | 20931 | + } else |
e49829fe JR |
20932 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
20933 | + flags); | |
20934 | + if (unlikely(err)) | |
20935 | + goto out_free; | |
1facf9fc | 20936 | + |
027c5e7a AM |
20937 | + err = au_d_hashed_positive(a->src_dentry); |
20938 | + if (unlikely(err)) | |
20939 | + goto out_unlock; | |
20940 | + err = -ENOENT; | |
20941 | + if (a->dst_inode) { | |
20942 | + /* | |
20943 | + * If it is a dir, VFS unhash dst_dentry before this | |
20944 | + * function. It means we cannot rely upon d_unhashed(). | |
20945 | + */ | |
20946 | + if (unlikely(!a->dst_inode->i_nlink)) | |
20947 | + goto out_unlock; | |
20948 | + if (!S_ISDIR(a->dst_inode->i_mode)) { | |
20949 | + err = au_d_hashed_positive(a->dst_dentry); | |
20950 | + if (unlikely(err)) | |
20951 | + goto out_unlock; | |
20952 | + } else if (unlikely(IS_DEADDIR(a->dst_inode))) | |
20953 | + goto out_unlock; | |
20954 | + } else if (unlikely(d_unhashed(a->dst_dentry))) | |
20955 | + goto out_unlock; | |
20956 | + | |
7eafdf33 AM |
20957 | + /* |
20958 | + * is it possible? | |
20959 | + * yes, it happend (in linux-3.3-rcN) but I don't know why. | |
20960 | + * there may exist a problem somewhere else. | |
20961 | + */ | |
20962 | + err = -EINVAL; | |
5527c038 | 20963 | + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry))) |
7eafdf33 AM |
20964 | + goto out_unlock; |
20965 | + | |
4a4d8108 AM |
20966 | + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */ |
20967 | + di_write_lock_parent(a->dst_parent); | |
1facf9fc | 20968 | + |
4a4d8108 AM |
20969 | + /* which branch we process */ |
20970 | + err = au_ren_wbr(a); | |
20971 | + if (unlikely(err < 0)) | |
027c5e7a | 20972 | + goto out_parent; |
4a4d8108 | 20973 | + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt); |
86dc4139 | 20974 | + a->h_path.mnt = au_br_mnt(a->br); |
1facf9fc | 20975 | + |
4a4d8108 AM |
20976 | + /* are they available to be renamed */ |
20977 | + err = au_ren_may_dir(a); | |
20978 | + if (unlikely(err)) | |
20979 | + goto out_children; | |
1facf9fc | 20980 | + |
4a4d8108 AM |
20981 | + /* prepare the writable parent dir on the same branch */ |
20982 | + if (a->dst_bstart == a->btgt) { | |
20983 | + au_fset_ren(a->flags, WHDST); | |
20984 | + } else { | |
20985 | + err = au_cpup_dirs(a->dst_dentry, a->btgt); | |
20986 | + if (unlikely(err)) | |
20987 | + goto out_children; | |
20988 | + } | |
1facf9fc | 20989 | + |
4a4d8108 AM |
20990 | + if (a->src_dir != a->dst_dir) { |
20991 | + /* | |
20992 | + * this temporary unlock is safe, | |
20993 | + * because both dir->i_mutex are locked. | |
20994 | + */ | |
20995 | + di_write_unlock(a->dst_parent); | |
20996 | + di_write_lock_parent(a->src_parent); | |
20997 | + err = au_wr_dir_need_wh(a->src_dentry, | |
20998 | + au_ftest_ren(a->flags, ISDIR), | |
20999 | + &a->btgt); | |
21000 | + di_write_unlock(a->src_parent); | |
21001 | + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1); | |
21002 | + au_fclr_ren(a->flags, ISSAMEDIR); | |
21003 | + } else | |
21004 | + err = au_wr_dir_need_wh(a->src_dentry, | |
21005 | + au_ftest_ren(a->flags, ISDIR), | |
21006 | + &a->btgt); | |
21007 | + if (unlikely(err < 0)) | |
21008 | + goto out_children; | |
21009 | + if (err) | |
21010 | + au_fset_ren(a->flags, WHSRC); | |
1facf9fc | 21011 | + |
86dc4139 AM |
21012 | + /* cpup src */ |
21013 | + if (a->src_bstart != a->btgt) { | |
86dc4139 AM |
21014 | + struct au_pin pin; |
21015 | + | |
21016 | + err = au_pin(&pin, a->src_dentry, a->btgt, | |
21017 | + au_opt_udba(a->src_dentry->d_sb), | |
21018 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
367653fa | 21019 | + if (!err) { |
c2b27bf2 AM |
21020 | + struct au_cp_generic cpg = { |
21021 | + .dentry = a->src_dentry, | |
21022 | + .bdst = a->btgt, | |
21023 | + .bsrc = a->src_bstart, | |
21024 | + .len = -1, | |
21025 | + .pin = &pin, | |
21026 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
21027 | + }; | |
367653fa | 21028 | + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart); |
c2b27bf2 | 21029 | + err = au_sio_cpup_simple(&cpg); |
367653fa | 21030 | + au_unpin(&pin); |
86dc4139 | 21031 | + } |
86dc4139 AM |
21032 | + if (unlikely(err)) |
21033 | + goto out_children; | |
21034 | + a->src_bstart = a->btgt; | |
21035 | + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt); | |
21036 | + au_fset_ren(a->flags, WHSRC); | |
21037 | + } | |
21038 | + | |
4a4d8108 AM |
21039 | + /* lock them all */ |
21040 | + err = au_ren_lock(a); | |
21041 | + if (unlikely(err)) | |
86dc4139 | 21042 | + /* leave the copied-up one */ |
4a4d8108 | 21043 | + goto out_children; |
1facf9fc | 21044 | + |
4a4d8108 AM |
21045 | + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE)) |
21046 | + err = au_may_ren(a); | |
21047 | + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
21048 | + err = -ENAMETOOLONG; | |
21049 | + if (unlikely(err)) | |
21050 | + goto out_hdir; | |
1facf9fc | 21051 | + |
4a4d8108 AM |
21052 | + /* store timestamps to be revertible */ |
21053 | + au_ren_dt(a); | |
1facf9fc | 21054 | + |
4a4d8108 AM |
21055 | + /* here we go */ |
21056 | + err = do_rename(a); | |
21057 | + if (unlikely(err)) | |
21058 | + goto out_dt; | |
21059 | + | |
21060 | + /* update dir attributes */ | |
21061 | + au_ren_refresh_dir(a); | |
21062 | + | |
21063 | + /* dput/iput all lower dentries */ | |
21064 | + au_ren_refresh(a); | |
21065 | + | |
21066 | + goto out_hdir; /* success */ | |
21067 | + | |
4f0767ce | 21068 | +out_dt: |
4a4d8108 | 21069 | + au_ren_rev_dt(err, a); |
4f0767ce | 21070 | +out_hdir: |
4a4d8108 | 21071 | + au_ren_unlock(a); |
4f0767ce | 21072 | +out_children: |
4a4d8108 | 21073 | + au_nhash_wh_free(&a->whlist); |
027c5e7a AM |
21074 | + if (err && a->dst_inode && a->dst_bstart != a->btgt) { |
21075 | + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt); | |
21076 | + au_set_h_dptr(a->dst_dentry, a->btgt, NULL); | |
21077 | + au_set_dbstart(a->dst_dentry, a->dst_bstart); | |
4a4d8108 | 21078 | + } |
027c5e7a | 21079 | +out_parent: |
4a4d8108 AM |
21080 | + if (!err) |
21081 | + d_move(a->src_dentry, a->dst_dentry); | |
027c5e7a AM |
21082 | + else { |
21083 | + au_update_dbstart(a->dst_dentry); | |
21084 | + if (!a->dst_inode) | |
21085 | + d_drop(a->dst_dentry); | |
21086 | + } | |
4a4d8108 AM |
21087 | + if (au_ftest_ren(a->flags, ISSAMEDIR)) |
21088 | + di_write_unlock(a->dst_parent); | |
21089 | + else | |
21090 | + di_write_unlock2(a->src_parent, a->dst_parent); | |
027c5e7a | 21091 | +out_unlock: |
4a4d8108 | 21092 | + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry); |
4f0767ce | 21093 | +out_free: |
4a4d8108 AM |
21094 | + iput(a->dst_inode); |
21095 | + if (a->thargs) | |
21096 | + au_whtmp_rmdir_free(a->thargs); | |
21097 | + kfree(a); | |
4f0767ce | 21098 | +out: |
4a4d8108 AM |
21099 | + AuTraceErr(err); |
21100 | + return err; | |
1308ab2a | 21101 | +} |
7f207e10 AM |
21102 | diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig |
21103 | --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21104 | +++ linux/fs/aufs/Kconfig 2015-09-24 10:47:58.248052907 +0200 |
c1595e42 | 21105 | @@ -0,0 +1,185 @@ |
4a4d8108 AM |
21106 | +config AUFS_FS |
21107 | + tristate "Aufs (Advanced multi layered unification filesystem) support" | |
4a4d8108 AM |
21108 | + help |
21109 | + Aufs is a stackable unification filesystem such as Unionfs, | |
21110 | + which unifies several directories and provides a merged single | |
21111 | + directory. | |
21112 | + In the early days, aufs was entirely re-designed and | |
21113 | + re-implemented Unionfs Version 1.x series. Introducing many | |
21114 | + original ideas, approaches and improvements, it becomes totally | |
21115 | + different from Unionfs while keeping the basic features. | |
1facf9fc | 21116 | + |
4a4d8108 AM |
21117 | +if AUFS_FS |
21118 | +choice | |
21119 | + prompt "Maximum number of branches" | |
21120 | + default AUFS_BRANCH_MAX_127 | |
21121 | + help | |
21122 | + Specifies the maximum number of branches (or member directories) | |
21123 | + in a single aufs. The larger value consumes more system | |
21124 | + resources and has a minor impact to performance. | |
21125 | +config AUFS_BRANCH_MAX_127 | |
21126 | + bool "127" | |
21127 | + help | |
21128 | + Specifies the maximum number of branches (or member directories) | |
21129 | + in a single aufs. The larger value consumes more system | |
21130 | + resources and has a minor impact to performance. | |
21131 | +config AUFS_BRANCH_MAX_511 | |
21132 | + bool "511" | |
21133 | + help | |
21134 | + Specifies the maximum number of branches (or member directories) | |
21135 | + in a single aufs. The larger value consumes more system | |
21136 | + resources and has a minor impact to performance. | |
21137 | +config AUFS_BRANCH_MAX_1023 | |
21138 | + bool "1023" | |
21139 | + help | |
21140 | + Specifies the maximum number of branches (or member directories) | |
21141 | + in a single aufs. The larger value consumes more system | |
21142 | + resources and has a minor impact to performance. | |
21143 | +config AUFS_BRANCH_MAX_32767 | |
21144 | + bool "32767" | |
21145 | + help | |
21146 | + Specifies the maximum number of branches (or member directories) | |
21147 | + in a single aufs. The larger value consumes more system | |
21148 | + resources and has a minor impact to performance. | |
21149 | +endchoice | |
1facf9fc | 21150 | + |
e49829fe JR |
21151 | +config AUFS_SBILIST |
21152 | + bool | |
21153 | + depends on AUFS_MAGIC_SYSRQ || PROC_FS | |
21154 | + default y | |
21155 | + help | |
21156 | + Automatic configuration for internal use. | |
21157 | + When aufs supports Magic SysRq or /proc, enabled automatically. | |
21158 | + | |
4a4d8108 AM |
21159 | +config AUFS_HNOTIFY |
21160 | + bool "Detect direct branch access (bypassing aufs)" | |
21161 | + help | |
21162 | + If you want to modify files on branches directly, eg. bypassing aufs, | |
21163 | + and want aufs to detect the changes of them fully, then enable this | |
21164 | + option and use 'udba=notify' mount option. | |
7f207e10 | 21165 | + Currently there is only one available configuration, "fsnotify". |
4a4d8108 AM |
21166 | + It will have a negative impact to the performance. |
21167 | + See detail in aufs.5. | |
dece6358 | 21168 | + |
4a4d8108 AM |
21169 | +choice |
21170 | + prompt "method" if AUFS_HNOTIFY | |
21171 | + default AUFS_HFSNOTIFY | |
21172 | +config AUFS_HFSNOTIFY | |
21173 | + bool "fsnotify" | |
21174 | + select FSNOTIFY | |
4a4d8108 | 21175 | +endchoice |
1facf9fc | 21176 | + |
4a4d8108 AM |
21177 | +config AUFS_EXPORT |
21178 | + bool "NFS-exportable aufs" | |
2cbb1c4b | 21179 | + depends on EXPORTFS |
4a4d8108 AM |
21180 | + help |
21181 | + If you want to export your mounted aufs via NFS, then enable this | |
21182 | + option. There are several requirements for this configuration. | |
21183 | + See detail in aufs.5. | |
1facf9fc | 21184 | + |
4a4d8108 AM |
21185 | +config AUFS_INO_T_64 |
21186 | + bool | |
21187 | + depends on AUFS_EXPORT | |
21188 | + depends on 64BIT && !(ALPHA || S390) | |
21189 | + default y | |
21190 | + help | |
21191 | + Automatic configuration for internal use. | |
21192 | + /* typedef unsigned long/int __kernel_ino_t */ | |
21193 | + /* alpha and s390x are int */ | |
1facf9fc | 21194 | + |
c1595e42 JR |
21195 | +config AUFS_XATTR |
21196 | + bool "support for XATTR/EA (including Security Labels)" | |
21197 | + help | |
21198 | + If your branch fs supports XATTR/EA and you want to make them | |
21199 | + available in aufs too, then enable this opsion and specify the | |
21200 | + branch attributes for EA. | |
21201 | + See detail in aufs.5. | |
21202 | + | |
076b876e AM |
21203 | +config AUFS_FHSM |
21204 | + bool "File-based Hierarchical Storage Management" | |
21205 | + help | |
21206 | + Hierarchical Storage Management (or HSM) is a well-known feature | |
21207 | + in the storage world. Aufs provides this feature as file-based. | |
21208 | + with multiple branches. | |
21209 | + These multiple branches are prioritized, ie. the topmost one | |
21210 | + should be the fastest drive and be used heavily. | |
21211 | + | |
4a4d8108 AM |
21212 | +config AUFS_RDU |
21213 | + bool "Readdir in userspace" | |
21214 | + help | |
21215 | + Aufs has two methods to provide a merged view for a directory, | |
21216 | + by a user-space library and by kernel-space natively. The latter | |
21217 | + is always enabled but sometimes large and slow. | |
21218 | + If you enable this option, install the library in aufs2-util | |
21219 | + package, and set some environment variables for your readdir(3), | |
21220 | + then the work will be handled in user-space which generally | |
21221 | + shows better performance in most cases. | |
21222 | + See detail in aufs.5. | |
1facf9fc | 21223 | + |
4a4d8108 AM |
21224 | +config AUFS_SHWH |
21225 | + bool "Show whiteouts" | |
21226 | + help | |
21227 | + If you want to make the whiteouts in aufs visible, then enable | |
21228 | + this option and specify 'shwh' mount option. Although it may | |
21229 | + sounds like philosophy or something, but in technically it | |
21230 | + simply shows the name of whiteout with keeping its behaviour. | |
1facf9fc | 21231 | + |
4a4d8108 AM |
21232 | +config AUFS_BR_RAMFS |
21233 | + bool "Ramfs (initramfs/rootfs) as an aufs branch" | |
21234 | + help | |
21235 | + If you want to use ramfs as an aufs branch fs, then enable this | |
21236 | + option. Generally tmpfs is recommended. | |
21237 | + Aufs prohibited them to be a branch fs by default, because | |
21238 | + initramfs becomes unusable after switch_root or something | |
21239 | + generally. If you sets initramfs as an aufs branch and boot your | |
21240 | + system by switch_root, you will meet a problem easily since the | |
21241 | + files in initramfs may be inaccessible. | |
21242 | + Unless you are going to use ramfs as an aufs branch fs without | |
21243 | + switch_root or something, leave it N. | |
1facf9fc | 21244 | + |
4a4d8108 AM |
21245 | +config AUFS_BR_FUSE |
21246 | + bool "Fuse fs as an aufs branch" | |
21247 | + depends on FUSE_FS | |
21248 | + select AUFS_POLL | |
21249 | + help | |
21250 | + If you want to use fuse-based userspace filesystem as an aufs | |
21251 | + branch fs, then enable this option. | |
21252 | + It implements the internal poll(2) operation which is | |
21253 | + implemented by fuse only (curretnly). | |
1facf9fc | 21254 | + |
4a4d8108 AM |
21255 | +config AUFS_POLL |
21256 | + bool | |
21257 | + help | |
21258 | + Automatic configuration for internal use. | |
1facf9fc | 21259 | + |
4a4d8108 AM |
21260 | +config AUFS_BR_HFSPLUS |
21261 | + bool "Hfsplus as an aufs branch" | |
21262 | + depends on HFSPLUS_FS | |
21263 | + default y | |
21264 | + help | |
21265 | + If you want to use hfsplus fs as an aufs branch fs, then enable | |
21266 | + this option. This option introduces a small overhead at | |
21267 | + copying-up a file on hfsplus. | |
1facf9fc | 21268 | + |
4a4d8108 AM |
21269 | +config AUFS_BDEV_LOOP |
21270 | + bool | |
21271 | + depends on BLK_DEV_LOOP | |
21272 | + default y | |
21273 | + help | |
21274 | + Automatic configuration for internal use. | |
21275 | + Convert =[ym] into =y. | |
1308ab2a | 21276 | + |
4a4d8108 AM |
21277 | +config AUFS_DEBUG |
21278 | + bool "Debug aufs" | |
21279 | + help | |
21280 | + Enable this to compile aufs internal debug code. | |
21281 | + It will have a negative impact to the performance. | |
21282 | + | |
21283 | +config AUFS_MAGIC_SYSRQ | |
21284 | + bool | |
21285 | + depends on AUFS_DEBUG && MAGIC_SYSRQ | |
21286 | + default y | |
21287 | + help | |
21288 | + Automatic configuration for internal use. | |
21289 | + When aufs supports Magic SysRq, enabled automatically. | |
21290 | +endif | |
7f207e10 AM |
21291 | diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c |
21292 | --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21293 | +++ linux/fs/aufs/loop.c 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 21294 | @@ -0,0 +1,145 @@ |
1facf9fc | 21295 | +/* |
2000de60 | 21296 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21297 | + * |
21298 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21299 | + * it under the terms of the GNU General Public License as published by | |
21300 | + * the Free Software Foundation; either version 2 of the License, or | |
21301 | + * (at your option) any later version. | |
dece6358 AM |
21302 | + * |
21303 | + * This program is distributed in the hope that it will be useful, | |
21304 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21305 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21306 | + * GNU General Public License for more details. | |
21307 | + * | |
21308 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21309 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21310 | + */ |
21311 | + | |
21312 | +/* | |
21313 | + * support for loopback block device as a branch | |
21314 | + */ | |
21315 | + | |
1facf9fc | 21316 | +#include "aufs.h" |
21317 | + | |
392086de AM |
21318 | +/* added into drivers/block/loop.c */ |
21319 | +static struct file *(*backing_file_func)(struct super_block *sb); | |
21320 | + | |
1facf9fc | 21321 | +/* |
21322 | + * test if two lower dentries have overlapping branches. | |
21323 | + */ | |
b752ccd1 | 21324 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding) |
1facf9fc | 21325 | +{ |
b752ccd1 | 21326 | + struct super_block *h_sb; |
392086de AM |
21327 | + struct file *backing_file; |
21328 | + | |
21329 | + if (unlikely(!backing_file_func)) { | |
21330 | + /* don't load "loop" module here */ | |
21331 | + backing_file_func = symbol_get(loop_backing_file); | |
21332 | + if (unlikely(!backing_file_func)) | |
21333 | + /* "loop" module is not loaded */ | |
21334 | + return 0; | |
21335 | + } | |
1facf9fc | 21336 | + |
b752ccd1 | 21337 | + h_sb = h_adding->d_sb; |
392086de AM |
21338 | + backing_file = backing_file_func(h_sb); |
21339 | + if (!backing_file) | |
1facf9fc | 21340 | + return 0; |
21341 | + | |
2000de60 | 21342 | + h_adding = backing_file->f_path.dentry; |
b752ccd1 AM |
21343 | + /* |
21344 | + * h_adding can be local NFS. | |
21345 | + * in this case aufs cannot detect the loop. | |
21346 | + */ | |
21347 | + if (unlikely(h_adding->d_sb == sb)) | |
1facf9fc | 21348 | + return 1; |
b752ccd1 | 21349 | + return !!au_test_subdir(h_adding, sb->s_root); |
1facf9fc | 21350 | +} |
21351 | + | |
21352 | +/* true if a kernel thread named 'loop[0-9].*' accesses a file */ | |
21353 | +int au_test_loopback_kthread(void) | |
21354 | +{ | |
b752ccd1 AM |
21355 | + int ret; |
21356 | + struct task_struct *tsk = current; | |
a2a7ad62 | 21357 | + char c, comm[sizeof(tsk->comm)]; |
b752ccd1 AM |
21358 | + |
21359 | + ret = 0; | |
21360 | + if (tsk->flags & PF_KTHREAD) { | |
a2a7ad62 AM |
21361 | + get_task_comm(comm, tsk); |
21362 | + c = comm[4]; | |
b752ccd1 | 21363 | + ret = ('0' <= c && c <= '9' |
a2a7ad62 | 21364 | + && !strncmp(comm, "loop", 4)); |
b752ccd1 | 21365 | + } |
1facf9fc | 21366 | + |
b752ccd1 | 21367 | + return ret; |
1facf9fc | 21368 | +} |
87a755f4 AM |
21369 | + |
21370 | +/* ---------------------------------------------------------------------- */ | |
21371 | + | |
21372 | +#define au_warn_loopback_step 16 | |
21373 | +static int au_warn_loopback_nelem = au_warn_loopback_step; | |
21374 | +static unsigned long *au_warn_loopback_array; | |
21375 | + | |
21376 | +void au_warn_loopback(struct super_block *h_sb) | |
21377 | +{ | |
21378 | + int i, new_nelem; | |
21379 | + unsigned long *a, magic; | |
21380 | + static DEFINE_SPINLOCK(spin); | |
21381 | + | |
21382 | + magic = h_sb->s_magic; | |
21383 | + spin_lock(&spin); | |
21384 | + a = au_warn_loopback_array; | |
21385 | + for (i = 0; i < au_warn_loopback_nelem && *a; i++) | |
21386 | + if (a[i] == magic) { | |
21387 | + spin_unlock(&spin); | |
21388 | + return; | |
21389 | + } | |
21390 | + | |
21391 | + /* h_sb is new to us, print it */ | |
21392 | + if (i < au_warn_loopback_nelem) { | |
21393 | + a[i] = magic; | |
21394 | + goto pr; | |
21395 | + } | |
21396 | + | |
21397 | + /* expand the array */ | |
21398 | + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step; | |
21399 | + a = au_kzrealloc(au_warn_loopback_array, | |
21400 | + au_warn_loopback_nelem * sizeof(unsigned long), | |
21401 | + new_nelem * sizeof(unsigned long), GFP_ATOMIC); | |
21402 | + if (a) { | |
21403 | + au_warn_loopback_nelem = new_nelem; | |
21404 | + au_warn_loopback_array = a; | |
21405 | + a[i] = magic; | |
21406 | + goto pr; | |
21407 | + } | |
21408 | + | |
21409 | + spin_unlock(&spin); | |
21410 | + AuWarn1("realloc failed, ignored\n"); | |
21411 | + return; | |
21412 | + | |
21413 | +pr: | |
21414 | + spin_unlock(&spin); | |
0c3ec466 AM |
21415 | + pr_warn("you may want to try another patch for loopback file " |
21416 | + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic); | |
87a755f4 AM |
21417 | +} |
21418 | + | |
21419 | +int au_loopback_init(void) | |
21420 | +{ | |
21421 | + int err; | |
21422 | + struct super_block *sb __maybe_unused; | |
21423 | + | |
21424 | + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long)); | |
21425 | + | |
21426 | + err = 0; | |
21427 | + au_warn_loopback_array = kcalloc(au_warn_loopback_step, | |
21428 | + sizeof(unsigned long), GFP_NOFS); | |
21429 | + if (unlikely(!au_warn_loopback_array)) | |
21430 | + err = -ENOMEM; | |
21431 | + | |
21432 | + return err; | |
21433 | +} | |
21434 | + | |
21435 | +void au_loopback_fin(void) | |
21436 | +{ | |
392086de | 21437 | + symbol_put(loop_backing_file); |
87a755f4 AM |
21438 | + kfree(au_warn_loopback_array); |
21439 | +} | |
7f207e10 AM |
21440 | diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h |
21441 | --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21442 | +++ linux/fs/aufs/loop.h 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 21443 | @@ -0,0 +1,52 @@ |
1facf9fc | 21444 | +/* |
2000de60 | 21445 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21446 | + * |
21447 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21448 | + * it under the terms of the GNU General Public License as published by | |
21449 | + * the Free Software Foundation; either version 2 of the License, or | |
21450 | + * (at your option) any later version. | |
dece6358 AM |
21451 | + * |
21452 | + * This program is distributed in the hope that it will be useful, | |
21453 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21454 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21455 | + * GNU General Public License for more details. | |
21456 | + * | |
21457 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21458 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21459 | + */ |
21460 | + | |
21461 | +/* | |
21462 | + * support for loopback mount as a branch | |
21463 | + */ | |
21464 | + | |
21465 | +#ifndef __AUFS_LOOP_H__ | |
21466 | +#define __AUFS_LOOP_H__ | |
21467 | + | |
21468 | +#ifdef __KERNEL__ | |
21469 | + | |
dece6358 AM |
21470 | +struct dentry; |
21471 | +struct super_block; | |
1facf9fc | 21472 | + |
21473 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
392086de AM |
21474 | +/* drivers/block/loop.c */ |
21475 | +struct file *loop_backing_file(struct super_block *sb); | |
21476 | + | |
1facf9fc | 21477 | +/* loop.c */ |
b752ccd1 | 21478 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding); |
1facf9fc | 21479 | +int au_test_loopback_kthread(void); |
87a755f4 AM |
21480 | +void au_warn_loopback(struct super_block *h_sb); |
21481 | + | |
21482 | +int au_loopback_init(void); | |
21483 | +void au_loopback_fin(void); | |
1facf9fc | 21484 | +#else |
4a4d8108 | 21485 | +AuStubInt0(au_test_loopback_overlap, struct super_block *sb, |
b752ccd1 | 21486 | + struct dentry *h_adding) |
4a4d8108 | 21487 | +AuStubInt0(au_test_loopback_kthread, void) |
87a755f4 AM |
21488 | +AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
21489 | + | |
21490 | +AuStubInt0(au_loopback_init, void) | |
21491 | +AuStubVoid(au_loopback_fin, void) | |
1facf9fc | 21492 | +#endif /* BLK_DEV_LOOP */ |
21493 | + | |
21494 | +#endif /* __KERNEL__ */ | |
21495 | +#endif /* __AUFS_LOOP_H__ */ | |
7f207e10 AM |
21496 | diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk |
21497 | --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21498 | +++ linux/fs/aufs/magic.mk 2015-09-24 10:47:58.254719746 +0200 |
7e9cd9fe | 21499 | @@ -0,0 +1,30 @@ |
1facf9fc | 21500 | + |
21501 | +# defined in ${srctree}/fs/fuse/inode.c | |
21502 | +# tristate | |
21503 | +ifdef CONFIG_FUSE_FS | |
21504 | +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546 | |
21505 | +endif | |
21506 | + | |
1facf9fc | 21507 | +# defined in ${srctree}/fs/xfs/xfs_sb.h |
21508 | +# tristate | |
21509 | +ifdef CONFIG_XFS_FS | |
21510 | +ccflags-y += -DXFS_SB_MAGIC=0x58465342 | |
21511 | +endif | |
21512 | + | |
21513 | +# defined in ${srctree}/fs/configfs/mount.c | |
21514 | +# tristate | |
21515 | +ifdef CONFIG_CONFIGFS_FS | |
21516 | +ccflags-y += -DCONFIGFS_MAGIC=0x62656570 | |
21517 | +endif | |
21518 | + | |
1facf9fc | 21519 | +# defined in ${srctree}/fs/ubifs/ubifs.h |
21520 | +# tristate | |
21521 | +ifdef CONFIG_UBIFS_FS | |
21522 | +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905 | |
21523 | +endif | |
4a4d8108 AM |
21524 | + |
21525 | +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h | |
21526 | +# tristate | |
21527 | +ifdef CONFIG_HFSPLUS_FS | |
21528 | +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b | |
21529 | +endif | |
7f207e10 AM |
21530 | diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile |
21531 | --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21532 | +++ linux/fs/aufs/Makefile 2015-09-24 10:47:58.248052907 +0200 |
c1595e42 | 21533 | @@ -0,0 +1,44 @@ |
4a4d8108 AM |
21534 | + |
21535 | +include ${src}/magic.mk | |
21536 | +ifeq (${CONFIG_AUFS_FS},m) | |
21537 | +include ${src}/conf.mk | |
21538 | +endif | |
21539 | +-include ${src}/priv_def.mk | |
21540 | + | |
21541 | +# cf. include/linux/kernel.h | |
21542 | +# enable pr_debug | |
21543 | +ccflags-y += -DDEBUG | |
f6c5ef8b AM |
21544 | +# sparse requires the full pathname |
21545 | +ifdef M | |
523b37e3 | 21546 | +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h |
f6c5ef8b | 21547 | +else |
523b37e3 | 21548 | +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h |
f6c5ef8b | 21549 | +endif |
4a4d8108 AM |
21550 | + |
21551 | +obj-$(CONFIG_AUFS_FS) += aufs.o | |
21552 | +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \ | |
21553 | + wkq.o vfsub.o dcsub.o \ | |
e49829fe | 21554 | + cpup.o whout.o wbr_policy.o \ |
4a4d8108 AM |
21555 | + dinfo.o dentry.o \ |
21556 | + dynop.o \ | |
21557 | + finfo.o file.o f_op.o \ | |
21558 | + dir.o vdir.o \ | |
21559 | + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \ | |
c2b27bf2 | 21560 | + mvdown.o ioctl.o |
4a4d8108 AM |
21561 | + |
21562 | +# all are boolean | |
e49829fe | 21563 | +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o |
4a4d8108 AM |
21564 | +aufs-$(CONFIG_SYSFS) += sysfs.o |
21565 | +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o | |
21566 | +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o | |
21567 | +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o | |
21568 | +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o | |
4a4d8108 | 21569 | +aufs-$(CONFIG_AUFS_EXPORT) += export.o |
c1595e42 JR |
21570 | +aufs-$(CONFIG_AUFS_XATTR) += xattr.o |
21571 | +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o | |
076b876e | 21572 | +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o |
4a4d8108 AM |
21573 | +aufs-$(CONFIG_AUFS_POLL) += poll.o |
21574 | +aufs-$(CONFIG_AUFS_RDU) += rdu.o | |
4a4d8108 AM |
21575 | +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o |
21576 | +aufs-$(CONFIG_AUFS_DEBUG) += debug.o | |
21577 | +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o | |
7f207e10 AM |
21578 | diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c |
21579 | --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21580 | +++ linux/fs/aufs/module.c 2015-09-24 10:47:58.254719746 +0200 |
076b876e | 21581 | @@ -0,0 +1,210 @@ |
1facf9fc | 21582 | +/* |
2000de60 | 21583 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21584 | + * |
21585 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21586 | + * it under the terms of the GNU General Public License as published by | |
21587 | + * the Free Software Foundation; either version 2 of the License, or | |
21588 | + * (at your option) any later version. | |
dece6358 AM |
21589 | + * |
21590 | + * This program is distributed in the hope that it will be useful, | |
21591 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21592 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21593 | + * GNU General Public License for more details. | |
21594 | + * | |
21595 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21596 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21597 | + */ |
21598 | + | |
21599 | +/* | |
21600 | + * module global variables and operations | |
21601 | + */ | |
21602 | + | |
21603 | +#include <linux/module.h> | |
21604 | +#include <linux/seq_file.h> | |
21605 | +#include "aufs.h" | |
21606 | + | |
21607 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp) | |
21608 | +{ | |
21609 | + if (new_sz <= nused) | |
21610 | + return p; | |
21611 | + | |
21612 | + p = krealloc(p, new_sz, gfp); | |
21613 | + if (p) | |
21614 | + memset(p + nused, 0, new_sz - nused); | |
21615 | + return p; | |
21616 | +} | |
21617 | + | |
21618 | +/* ---------------------------------------------------------------------- */ | |
21619 | + | |
21620 | +/* | |
21621 | + * aufs caches | |
21622 | + */ | |
21623 | +struct kmem_cache *au_cachep[AuCache_Last]; | |
21624 | +static int __init au_cache_init(void) | |
21625 | +{ | |
4a4d8108 | 21626 | + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once); |
1facf9fc | 21627 | + if (au_cachep[AuCache_DINFO]) |
027c5e7a | 21628 | + /* SLAB_DESTROY_BY_RCU */ |
4a4d8108 AM |
21629 | + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr, |
21630 | + au_icntnr_init_once); | |
1facf9fc | 21631 | + if (au_cachep[AuCache_ICNTNR]) |
4a4d8108 AM |
21632 | + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo, |
21633 | + au_fi_init_once); | |
1facf9fc | 21634 | + if (au_cachep[AuCache_FINFO]) |
21635 | + au_cachep[AuCache_VDIR] = AuCache(au_vdir); | |
21636 | + if (au_cachep[AuCache_VDIR]) | |
21637 | + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr); | |
21638 | + if (au_cachep[AuCache_DEHSTR]) | |
21639 | + return 0; | |
21640 | + | |
21641 | + return -ENOMEM; | |
21642 | +} | |
21643 | + | |
21644 | +static void au_cache_fin(void) | |
21645 | +{ | |
21646 | + int i; | |
4a4d8108 | 21647 | + |
537831f9 AM |
21648 | + /* |
21649 | + * Make sure all delayed rcu free inodes are flushed before we | |
21650 | + * destroy cache. | |
21651 | + */ | |
21652 | + rcu_barrier(); | |
21653 | + | |
7eafdf33 AM |
21654 | + /* excluding AuCache_HNOTIFY */ |
21655 | + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last); | |
21656 | + for (i = 0; i < AuCache_HNOTIFY; i++) | |
1facf9fc | 21657 | + if (au_cachep[i]) { |
21658 | + kmem_cache_destroy(au_cachep[i]); | |
21659 | + au_cachep[i] = NULL; | |
21660 | + } | |
21661 | +} | |
21662 | + | |
21663 | +/* ---------------------------------------------------------------------- */ | |
21664 | + | |
21665 | +int au_dir_roflags; | |
21666 | + | |
e49829fe | 21667 | +#ifdef CONFIG_AUFS_SBILIST |
1e00d052 AM |
21668 | +/* |
21669 | + * iterate_supers_type() doesn't protect us from | |
21670 | + * remounting (branch management) | |
21671 | + */ | |
e49829fe JR |
21672 | +struct au_splhead au_sbilist; |
21673 | +#endif | |
21674 | + | |
9dbd164d AM |
21675 | +struct lock_class_key au_lc_key[AuLcKey_Last]; |
21676 | + | |
1facf9fc | 21677 | +/* |
21678 | + * functions for module interface. | |
21679 | + */ | |
21680 | +MODULE_LICENSE("GPL"); | |
21681 | +/* MODULE_LICENSE("GPL v2"); */ | |
dece6358 | 21682 | +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>"); |
1facf9fc | 21683 | +MODULE_DESCRIPTION(AUFS_NAME |
21684 | + " -- Advanced multi layered unification filesystem"); | |
21685 | +MODULE_VERSION(AUFS_VERSION); | |
c06a8ce3 | 21686 | +MODULE_ALIAS_FS(AUFS_NAME); |
1facf9fc | 21687 | + |
1facf9fc | 21688 | +/* this module parameter has no meaning when SYSFS is disabled */ |
21689 | +int sysaufs_brs = 1; | |
21690 | +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN"); | |
21691 | +module_param_named(brs, sysaufs_brs, int, S_IRUGO); | |
21692 | + | |
076b876e AM |
21693 | +/* this module parameter has no meaning when USER_NS is disabled */ |
21694 | +static bool au_userns; | |
21695 | +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns"); | |
21696 | +module_param_named(allow_userns, au_userns, bool, S_IRUGO); | |
21697 | + | |
1facf9fc | 21698 | +/* ---------------------------------------------------------------------- */ |
21699 | + | |
21700 | +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */ | |
21701 | + | |
21702 | +int au_seq_path(struct seq_file *seq, struct path *path) | |
21703 | +{ | |
21704 | + return seq_path(seq, path, au_esc_chars); | |
21705 | +} | |
21706 | + | |
21707 | +/* ---------------------------------------------------------------------- */ | |
21708 | + | |
21709 | +static int __init aufs_init(void) | |
21710 | +{ | |
21711 | + int err, i; | |
21712 | + char *p; | |
21713 | + | |
21714 | + p = au_esc_chars; | |
21715 | + for (i = 1; i <= ' '; i++) | |
21716 | + *p++ = i; | |
21717 | + *p++ = '\\'; | |
21718 | + *p++ = '\x7f'; | |
21719 | + *p = 0; | |
21720 | + | |
21721 | + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE); | |
21722 | + | |
e49829fe | 21723 | + au_sbilist_init(); |
1facf9fc | 21724 | + sysaufs_brs_init(); |
21725 | + au_debug_init(); | |
4a4d8108 | 21726 | + au_dy_init(); |
1facf9fc | 21727 | + err = sysaufs_init(); |
21728 | + if (unlikely(err)) | |
21729 | + goto out; | |
e49829fe | 21730 | + err = au_procfs_init(); |
4f0767ce | 21731 | + if (unlikely(err)) |
953406b4 | 21732 | + goto out_sysaufs; |
e49829fe JR |
21733 | + err = au_wkq_init(); |
21734 | + if (unlikely(err)) | |
21735 | + goto out_procfs; | |
87a755f4 | 21736 | + err = au_loopback_init(); |
1facf9fc | 21737 | + if (unlikely(err)) |
21738 | + goto out_wkq; | |
87a755f4 AM |
21739 | + err = au_hnotify_init(); |
21740 | + if (unlikely(err)) | |
21741 | + goto out_loopback; | |
1facf9fc | 21742 | + err = au_sysrq_init(); |
21743 | + if (unlikely(err)) | |
21744 | + goto out_hin; | |
21745 | + err = au_cache_init(); | |
21746 | + if (unlikely(err)) | |
21747 | + goto out_sysrq; | |
076b876e AM |
21748 | + |
21749 | + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0; | |
1facf9fc | 21750 | + err = register_filesystem(&aufs_fs_type); |
21751 | + if (unlikely(err)) | |
21752 | + goto out_cache; | |
076b876e | 21753 | + |
4a4d8108 AM |
21754 | + /* since we define pr_fmt, call printk directly */ |
21755 | + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n"); | |
1facf9fc | 21756 | + goto out; /* success */ |
21757 | + | |
4f0767ce | 21758 | +out_cache: |
1facf9fc | 21759 | + au_cache_fin(); |
4f0767ce | 21760 | +out_sysrq: |
1facf9fc | 21761 | + au_sysrq_fin(); |
4f0767ce | 21762 | +out_hin: |
4a4d8108 | 21763 | + au_hnotify_fin(); |
87a755f4 AM |
21764 | +out_loopback: |
21765 | + au_loopback_fin(); | |
4f0767ce | 21766 | +out_wkq: |
1facf9fc | 21767 | + au_wkq_fin(); |
e49829fe JR |
21768 | +out_procfs: |
21769 | + au_procfs_fin(); | |
4f0767ce | 21770 | +out_sysaufs: |
1facf9fc | 21771 | + sysaufs_fin(); |
4a4d8108 | 21772 | + au_dy_fin(); |
4f0767ce | 21773 | +out: |
1facf9fc | 21774 | + return err; |
21775 | +} | |
21776 | + | |
21777 | +static void __exit aufs_exit(void) | |
21778 | +{ | |
21779 | + unregister_filesystem(&aufs_fs_type); | |
21780 | + au_cache_fin(); | |
21781 | + au_sysrq_fin(); | |
4a4d8108 | 21782 | + au_hnotify_fin(); |
87a755f4 | 21783 | + au_loopback_fin(); |
1facf9fc | 21784 | + au_wkq_fin(); |
e49829fe | 21785 | + au_procfs_fin(); |
1facf9fc | 21786 | + sysaufs_fin(); |
4a4d8108 | 21787 | + au_dy_fin(); |
1facf9fc | 21788 | +} |
21789 | + | |
21790 | +module_init(aufs_init); | |
21791 | +module_exit(aufs_exit); | |
7f207e10 AM |
21792 | diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h |
21793 | --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21794 | +++ linux/fs/aufs/module.h 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 21795 | @@ -0,0 +1,104 @@ |
1facf9fc | 21796 | +/* |
2000de60 | 21797 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 21798 | + * |
21799 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21800 | + * it under the terms of the GNU General Public License as published by | |
21801 | + * the Free Software Foundation; either version 2 of the License, or | |
21802 | + * (at your option) any later version. | |
dece6358 AM |
21803 | + * |
21804 | + * This program is distributed in the hope that it will be useful, | |
21805 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21806 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21807 | + * GNU General Public License for more details. | |
21808 | + * | |
21809 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21810 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21811 | + */ |
21812 | + | |
21813 | +/* | |
21814 | + * module initialization and module-global | |
21815 | + */ | |
21816 | + | |
21817 | +#ifndef __AUFS_MODULE_H__ | |
21818 | +#define __AUFS_MODULE_H__ | |
21819 | + | |
21820 | +#ifdef __KERNEL__ | |
21821 | + | |
21822 | +#include <linux/slab.h> | |
21823 | + | |
dece6358 AM |
21824 | +struct path; |
21825 | +struct seq_file; | |
21826 | + | |
1facf9fc | 21827 | +/* module parameters */ |
1facf9fc | 21828 | +extern int sysaufs_brs; |
21829 | + | |
21830 | +/* ---------------------------------------------------------------------- */ | |
21831 | + | |
21832 | +extern int au_dir_roflags; | |
21833 | + | |
9dbd164d AM |
21834 | +enum { |
21835 | + AuLcNonDir_FIINFO, | |
21836 | + AuLcNonDir_DIINFO, | |
21837 | + AuLcNonDir_IIINFO, | |
21838 | + | |
21839 | + AuLcDir_FIINFO, | |
21840 | + AuLcDir_DIINFO, | |
21841 | + AuLcDir_IIINFO, | |
21842 | + | |
21843 | + AuLcSymlink_DIINFO, | |
21844 | + AuLcSymlink_IIINFO, | |
21845 | + | |
21846 | + AuLcKey_Last | |
21847 | +}; | |
21848 | +extern struct lock_class_key au_lc_key[AuLcKey_Last]; | |
21849 | + | |
1facf9fc | 21850 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp); |
21851 | +int au_seq_path(struct seq_file *seq, struct path *path); | |
21852 | + | |
e49829fe JR |
21853 | +#ifdef CONFIG_PROC_FS |
21854 | +/* procfs.c */ | |
21855 | +int __init au_procfs_init(void); | |
21856 | +void au_procfs_fin(void); | |
21857 | +#else | |
21858 | +AuStubInt0(au_procfs_init, void); | |
21859 | +AuStubVoid(au_procfs_fin, void); | |
21860 | +#endif | |
21861 | + | |
4f0767ce JR |
21862 | +/* ---------------------------------------------------------------------- */ |
21863 | + | |
21864 | +/* kmem cache */ | |
1facf9fc | 21865 | +enum { |
21866 | + AuCache_DINFO, | |
21867 | + AuCache_ICNTNR, | |
21868 | + AuCache_FINFO, | |
21869 | + AuCache_VDIR, | |
21870 | + AuCache_DEHSTR, | |
7eafdf33 | 21871 | + AuCache_HNOTIFY, /* must be last */ |
1facf9fc | 21872 | + AuCache_Last |
21873 | +}; | |
21874 | + | |
4a4d8108 AM |
21875 | +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD) |
21876 | +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags) | |
21877 | +#define AuCacheCtor(type, ctor) \ | |
21878 | + kmem_cache_create(#type, sizeof(struct type), \ | |
21879 | + __alignof__(struct type), AuCacheFlags, ctor) | |
1facf9fc | 21880 | + |
21881 | +extern struct kmem_cache *au_cachep[]; | |
21882 | + | |
21883 | +#define AuCacheFuncs(name, index) \ | |
4a4d8108 | 21884 | +static inline struct au_##name *au_cache_alloc_##name(void) \ |
1facf9fc | 21885 | +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \ |
4a4d8108 | 21886 | +static inline void au_cache_free_##name(struct au_##name *p) \ |
1facf9fc | 21887 | +{ kmem_cache_free(au_cachep[AuCache_##index], p); } |
21888 | + | |
21889 | +AuCacheFuncs(dinfo, DINFO); | |
21890 | +AuCacheFuncs(icntnr, ICNTNR); | |
21891 | +AuCacheFuncs(finfo, FINFO); | |
21892 | +AuCacheFuncs(vdir, VDIR); | |
4a4d8108 AM |
21893 | +AuCacheFuncs(vdir_dehstr, DEHSTR); |
21894 | +#ifdef CONFIG_AUFS_HNOTIFY | |
21895 | +AuCacheFuncs(hnotify, HNOTIFY); | |
21896 | +#endif | |
1facf9fc | 21897 | + |
4a4d8108 AM |
21898 | +#endif /* __KERNEL__ */ |
21899 | +#endif /* __AUFS_MODULE_H__ */ | |
c2b27bf2 AM |
21900 | diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c |
21901 | --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 21902 | +++ linux/fs/aufs/mvdown.c 2015-09-24 10:47:58.254719746 +0200 |
c1595e42 | 21903 | @@ -0,0 +1,694 @@ |
c2b27bf2 | 21904 | +/* |
2000de60 | 21905 | + * Copyright (C) 2011-2015 Junjiro R. Okajima |
c2b27bf2 AM |
21906 | + * |
21907 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21908 | + * it under the terms of the GNU General Public License as published by | |
21909 | + * the Free Software Foundation; either version 2 of the License, or | |
21910 | + * (at your option) any later version. | |
21911 | + * | |
21912 | + * This program is distributed in the hope that it will be useful, | |
21913 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21914 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21915 | + * GNU General Public License for more details. | |
21916 | + * | |
21917 | + * You should have received a copy of the GNU General Public License | |
523b37e3 AM |
21918 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21919 | + */ | |
21920 | + | |
21921 | +/* | |
21922 | + * move-down, opposite of copy-up | |
c2b27bf2 AM |
21923 | + */ |
21924 | + | |
21925 | +#include "aufs.h" | |
21926 | + | |
c2b27bf2 AM |
21927 | +struct au_mvd_args { |
21928 | + struct { | |
c2b27bf2 AM |
21929 | + struct super_block *h_sb; |
21930 | + struct dentry *h_parent; | |
21931 | + struct au_hinode *hdir; | |
392086de | 21932 | + struct inode *h_dir, *h_inode; |
c1595e42 | 21933 | + struct au_pin pin; |
c2b27bf2 AM |
21934 | + } info[AUFS_MVDOWN_NARRAY]; |
21935 | + | |
21936 | + struct aufs_mvdown mvdown; | |
21937 | + struct dentry *dentry, *parent; | |
21938 | + struct inode *inode, *dir; | |
21939 | + struct super_block *sb; | |
21940 | + aufs_bindex_t bopq, bwh, bfound; | |
21941 | + unsigned char rename_lock; | |
c2b27bf2 AM |
21942 | +}; |
21943 | + | |
392086de | 21944 | +#define mvd_errno mvdown.au_errno |
076b876e AM |
21945 | +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex |
21946 | +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid | |
21947 | +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex | |
21948 | +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid | |
c2b27bf2 | 21949 | + |
392086de AM |
21950 | +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb |
21951 | +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent | |
21952 | +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir | |
21953 | +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir | |
21954 | +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode | |
c1595e42 | 21955 | +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin |
392086de AM |
21956 | + |
21957 | +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb | |
21958 | +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent | |
21959 | +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir | |
21960 | +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir | |
21961 | +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode | |
c1595e42 | 21962 | +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin |
c2b27bf2 AM |
21963 | + |
21964 | +#define AU_MVD_PR(flag, ...) do { \ | |
21965 | + if (flag) \ | |
21966 | + pr_err(__VA_ARGS__); \ | |
21967 | + } while (0) | |
21968 | + | |
076b876e AM |
21969 | +static int find_lower_writable(struct au_mvd_args *a) |
21970 | +{ | |
21971 | + struct super_block *sb; | |
21972 | + aufs_bindex_t bindex, bend; | |
21973 | + struct au_branch *br; | |
21974 | + | |
21975 | + sb = a->sb; | |
21976 | + bindex = a->mvd_bsrc; | |
21977 | + bend = au_sbend(sb); | |
21978 | + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER) | |
21979 | + for (bindex++; bindex <= bend; bindex++) { | |
21980 | + br = au_sbr(sb, bindex); | |
21981 | + if (au_br_fhsm(br->br_perm) | |
21982 | + && (!(au_br_sb(br)->s_flags & MS_RDONLY))) | |
21983 | + return bindex; | |
21984 | + } | |
21985 | + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) | |
21986 | + for (bindex++; bindex <= bend; bindex++) { | |
21987 | + br = au_sbr(sb, bindex); | |
21988 | + if (!au_br_rdonly(br)) | |
21989 | + return bindex; | |
21990 | + } | |
21991 | + else | |
21992 | + for (bindex++; bindex <= bend; bindex++) { | |
21993 | + br = au_sbr(sb, bindex); | |
21994 | + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) { | |
21995 | + if (au_br_rdonly(br)) | |
21996 | + a->mvdown.flags | |
21997 | + |= AUFS_MVDOWN_ROLOWER_R; | |
21998 | + return bindex; | |
21999 | + } | |
22000 | + } | |
22001 | + | |
22002 | + return -1; | |
22003 | +} | |
22004 | + | |
c2b27bf2 | 22005 | +/* make the parent dir on bdst */ |
392086de | 22006 | +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22007 | +{ |
22008 | + int err; | |
22009 | + | |
22010 | + err = 0; | |
22011 | + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc); | |
22012 | + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst); | |
22013 | + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc); | |
22014 | + a->mvd_h_dst_parent = NULL; | |
22015 | + if (au_dbend(a->parent) >= a->mvd_bdst) | |
22016 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
22017 | + if (!a->mvd_h_dst_parent) { | |
22018 | + err = au_cpdown_dirs(a->dentry, a->mvd_bdst); | |
22019 | + if (unlikely(err)) { | |
392086de | 22020 | + AU_MVD_PR(dmsg, "cpdown_dirs failed\n"); |
c2b27bf2 AM |
22021 | + goto out; |
22022 | + } | |
22023 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
22024 | + } | |
22025 | + | |
22026 | +out: | |
22027 | + AuTraceErr(err); | |
22028 | + return err; | |
22029 | +} | |
22030 | + | |
22031 | +/* lock them all */ | |
392086de | 22032 | +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22033 | +{ |
22034 | + int err; | |
22035 | + struct dentry *h_trap; | |
22036 | + | |
22037 | + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc); | |
22038 | + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst); | |
c1595e42 JR |
22039 | + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst, |
22040 | + au_opt_udba(a->sb), | |
22041 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22042 | + AuTraceErr(err); | |
22043 | + if (unlikely(err)) { | |
22044 | + AU_MVD_PR(dmsg, "pin_dst failed\n"); | |
22045 | + goto out; | |
22046 | + } | |
22047 | + | |
c2b27bf2 AM |
22048 | + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) { |
22049 | + a->rename_lock = 0; | |
c1595e42 JR |
22050 | + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, |
22051 | + AuLsc_DI_PARENT, AuLsc_I_PARENT3, | |
22052 | + au_opt_udba(a->sb), | |
22053 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22054 | + err = au_do_pin(&a->mvd_pin_src); | |
22055 | + AuTraceErr(err); | |
5527c038 | 22056 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
22057 | + if (unlikely(err)) { |
22058 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
22059 | + goto out_dst; | |
22060 | + } | |
22061 | + goto out; /* success */ | |
c2b27bf2 AM |
22062 | + } |
22063 | + | |
c2b27bf2 | 22064 | + a->rename_lock = 1; |
c1595e42 JR |
22065 | + au_pin_hdir_unlock(&a->mvd_pin_dst); |
22066 | + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, | |
22067 | + au_opt_udba(a->sb), | |
22068 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
22069 | + AuTraceErr(err); | |
5527c038 | 22070 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
22071 | + if (unlikely(err)) { |
22072 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
22073 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22074 | + goto out_dst; | |
22075 | + } | |
22076 | + au_pin_hdir_unlock(&a->mvd_pin_src); | |
c2b27bf2 AM |
22077 | + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
22078 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
22079 | + if (h_trap) { | |
22080 | + err = (h_trap != a->mvd_h_src_parent); | |
22081 | + if (err) | |
22082 | + err = (h_trap != a->mvd_h_dst_parent); | |
22083 | + } | |
22084 | + BUG_ON(err); /* it should never happen */ | |
c1595e42 JR |
22085 | + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) { |
22086 | + err = -EBUSY; | |
22087 | + AuTraceErr(err); | |
22088 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, | |
22089 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
22090 | + au_pin_hdir_lock(&a->mvd_pin_src); | |
22091 | + au_unpin(&a->mvd_pin_src); | |
22092 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22093 | + goto out_dst; | |
22094 | + } | |
22095 | + goto out; /* success */ | |
c2b27bf2 | 22096 | + |
c1595e42 JR |
22097 | +out_dst: |
22098 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
22099 | +out: |
22100 | + AuTraceErr(err); | |
22101 | + return err; | |
22102 | +} | |
22103 | + | |
392086de | 22104 | +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 | 22105 | +{ |
c1595e42 JR |
22106 | + if (!a->rename_lock) |
22107 | + au_unpin(&a->mvd_pin_src); | |
22108 | + else { | |
c2b27bf2 AM |
22109 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
22110 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
c1595e42 JR |
22111 | + au_pin_hdir_lock(&a->mvd_pin_src); |
22112 | + au_unpin(&a->mvd_pin_src); | |
22113 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
22114 | + } | |
22115 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
22116 | +} |
22117 | + | |
22118 | +/* copy-down the file */ | |
392086de | 22119 | +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22120 | +{ |
22121 | + int err; | |
22122 | + struct au_cp_generic cpg = { | |
22123 | + .dentry = a->dentry, | |
22124 | + .bdst = a->mvd_bdst, | |
22125 | + .bsrc = a->mvd_bsrc, | |
22126 | + .len = -1, | |
c1595e42 | 22127 | + .pin = &a->mvd_pin_dst, |
c2b27bf2 AM |
22128 | + .flags = AuCpup_DTIME | AuCpup_HOPEN |
22129 | + }; | |
22130 | + | |
22131 | + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst); | |
392086de AM |
22132 | + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER) |
22133 | + au_fset_cpup(cpg.flags, OVERWRITE); | |
22134 | + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER) | |
22135 | + au_fset_cpup(cpg.flags, RWDST); | |
c2b27bf2 AM |
22136 | + err = au_sio_cpdown_simple(&cpg); |
22137 | + if (unlikely(err)) | |
392086de | 22138 | + AU_MVD_PR(dmsg, "cpdown failed\n"); |
c2b27bf2 AM |
22139 | + |
22140 | + AuTraceErr(err); | |
22141 | + return err; | |
22142 | +} | |
22143 | + | |
22144 | +/* | |
22145 | + * unlink the whiteout on bdst if exist which may be created by UDBA while we | |
22146 | + * were sleeping | |
22147 | + */ | |
392086de | 22148 | +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22149 | +{ |
22150 | + int err; | |
22151 | + struct path h_path; | |
22152 | + struct au_branch *br; | |
523b37e3 | 22153 | + struct inode *delegated; |
c2b27bf2 AM |
22154 | + |
22155 | + br = au_sbr(a->sb, a->mvd_bdst); | |
22156 | + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br); | |
22157 | + err = PTR_ERR(h_path.dentry); | |
22158 | + if (IS_ERR(h_path.dentry)) { | |
392086de | 22159 | + AU_MVD_PR(dmsg, "wh_lkup failed\n"); |
c2b27bf2 AM |
22160 | + goto out; |
22161 | + } | |
22162 | + | |
22163 | + err = 0; | |
5527c038 | 22164 | + if (d_is_positive(h_path.dentry)) { |
c2b27bf2 | 22165 | + h_path.mnt = au_br_mnt(br); |
523b37e3 | 22166 | + delegated = NULL; |
5527c038 | 22167 | + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path, |
523b37e3 AM |
22168 | + &delegated, /*force*/0); |
22169 | + if (unlikely(err == -EWOULDBLOCK)) { | |
22170 | + pr_warn("cannot retry for NFSv4 delegation" | |
22171 | + " for an internal unlink\n"); | |
22172 | + iput(delegated); | |
22173 | + } | |
c2b27bf2 | 22174 | + if (unlikely(err)) |
392086de | 22175 | + AU_MVD_PR(dmsg, "wh_unlink failed\n"); |
c2b27bf2 AM |
22176 | + } |
22177 | + dput(h_path.dentry); | |
22178 | + | |
22179 | +out: | |
22180 | + AuTraceErr(err); | |
22181 | + return err; | |
22182 | +} | |
22183 | + | |
22184 | +/* | |
22185 | + * unlink the topmost h_dentry | |
c2b27bf2 | 22186 | + */ |
392086de | 22187 | +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22188 | +{ |
22189 | + int err; | |
22190 | + struct path h_path; | |
523b37e3 | 22191 | + struct inode *delegated; |
c2b27bf2 AM |
22192 | + |
22193 | + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc); | |
22194 | + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc); | |
523b37e3 AM |
22195 | + delegated = NULL; |
22196 | + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0); | |
22197 | + if (unlikely(err == -EWOULDBLOCK)) { | |
22198 | + pr_warn("cannot retry for NFSv4 delegation" | |
22199 | + " for an internal unlink\n"); | |
22200 | + iput(delegated); | |
22201 | + } | |
c2b27bf2 | 22202 | + if (unlikely(err)) |
392086de | 22203 | + AU_MVD_PR(dmsg, "unlink failed\n"); |
c2b27bf2 AM |
22204 | + |
22205 | + AuTraceErr(err); | |
22206 | + return err; | |
22207 | +} | |
22208 | + | |
076b876e AM |
22209 | +/* Since mvdown succeeded, we ignore an error of this function */ |
22210 | +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a) | |
22211 | +{ | |
22212 | + int err; | |
22213 | + struct au_branch *br; | |
22214 | + | |
22215 | + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED; | |
22216 | + br = au_sbr(a->sb, a->mvd_bsrc); | |
22217 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs); | |
22218 | + if (!err) { | |
22219 | + br = au_sbr(a->sb, a->mvd_bdst); | |
22220 | + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id; | |
22221 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs); | |
22222 | + } | |
22223 | + if (!err) | |
22224 | + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED; | |
22225 | + else | |
22226 | + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err); | |
22227 | +} | |
22228 | + | |
c2b27bf2 AM |
22229 | +/* |
22230 | + * copy-down the file and unlink the bsrc file. | |
22231 | + * - unlink the bdst whout if exist | |
22232 | + * - copy-down the file (with whtmp name and rename) | |
22233 | + * - unlink the bsrc file | |
22234 | + */ | |
392086de | 22235 | +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22236 | +{ |
22237 | + int err; | |
22238 | + | |
392086de | 22239 | + err = au_do_mkdir(dmsg, a); |
c2b27bf2 | 22240 | + if (!err) |
392086de | 22241 | + err = au_do_lock(dmsg, a); |
c2b27bf2 AM |
22242 | + if (unlikely(err)) |
22243 | + goto out; | |
22244 | + | |
22245 | + /* | |
22246 | + * do not revert the activities we made on bdst since they should be | |
22247 | + * harmless in aufs. | |
22248 | + */ | |
22249 | + | |
392086de | 22250 | + err = au_do_cpdown(dmsg, a); |
c2b27bf2 | 22251 | + if (!err) |
392086de AM |
22252 | + err = au_do_unlink_wh(dmsg, a); |
22253 | + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
22254 | + err = au_do_unlink(dmsg, a); | |
c2b27bf2 AM |
22255 | + if (unlikely(err)) |
22256 | + goto out_unlock; | |
22257 | + | |
c1595e42 JR |
22258 | + AuDbg("%pd2, 0x%x, %d --> %d\n", |
22259 | + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst); | |
076b876e AM |
22260 | + if (find_lower_writable(a) < 0) |
22261 | + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM; | |
22262 | + | |
22263 | + if (a->mvdown.flags & AUFS_MVDOWN_STFS) | |
22264 | + au_do_stfs(dmsg, a); | |
22265 | + | |
c2b27bf2 | 22266 | + /* maintain internal array */ |
392086de AM |
22267 | + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) { |
22268 | + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL); | |
22269 | + au_set_dbstart(a->dentry, a->mvd_bdst); | |
22270 | + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0); | |
22271 | + au_set_ibstart(a->inode, a->mvd_bdst); | |
22272 | + } | |
c2b27bf2 AM |
22273 | + if (au_dbend(a->dentry) < a->mvd_bdst) |
22274 | + au_set_dbend(a->dentry, a->mvd_bdst); | |
c2b27bf2 AM |
22275 | + if (au_ibend(a->inode) < a->mvd_bdst) |
22276 | + au_set_ibend(a->inode, a->mvd_bdst); | |
22277 | + | |
22278 | +out_unlock: | |
392086de | 22279 | + au_do_unlock(dmsg, a); |
c2b27bf2 AM |
22280 | +out: |
22281 | + AuTraceErr(err); | |
22282 | + return err; | |
22283 | +} | |
22284 | + | |
22285 | +/* ---------------------------------------------------------------------- */ | |
22286 | + | |
c2b27bf2 | 22287 | +/* make sure the file is idle */ |
392086de | 22288 | +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22289 | +{ |
22290 | + int err, plinked; | |
c2b27bf2 AM |
22291 | + |
22292 | + err = 0; | |
c2b27bf2 AM |
22293 | + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK); |
22294 | + if (au_dbstart(a->dentry) == a->mvd_bsrc | |
c1595e42 | 22295 | + && au_dcount(a->dentry) == 1 |
c2b27bf2 | 22296 | + && atomic_read(&a->inode->i_count) == 1 |
392086de | 22297 | + /* && a->mvd_h_src_inode->i_nlink == 1 */ |
c2b27bf2 AM |
22298 | + && (!plinked || !au_plink_test(a->inode)) |
22299 | + && a->inode->i_nlink == 1) | |
22300 | + goto out; | |
22301 | + | |
22302 | + err = -EBUSY; | |
392086de | 22303 | + AU_MVD_PR(dmsg, |
c1595e42 JR |
22304 | + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n", |
22305 | + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry), | |
c2b27bf2 | 22306 | + atomic_read(&a->inode->i_count), a->inode->i_nlink, |
392086de | 22307 | + a->mvd_h_src_inode->i_nlink, |
c2b27bf2 AM |
22308 | + plinked, plinked ? au_plink_test(a->inode) : 0); |
22309 | + | |
22310 | +out: | |
22311 | + AuTraceErr(err); | |
22312 | + return err; | |
22313 | +} | |
22314 | + | |
22315 | +/* make sure the parent dir is fine */ | |
392086de | 22316 | +static int au_mvd_args_parent(const unsigned char dmsg, |
c2b27bf2 AM |
22317 | + struct au_mvd_args *a) |
22318 | +{ | |
22319 | + int err; | |
22320 | + aufs_bindex_t bindex; | |
22321 | + | |
22322 | + err = 0; | |
22323 | + if (unlikely(au_alive_dir(a->parent))) { | |
22324 | + err = -ENOENT; | |
392086de | 22325 | + AU_MVD_PR(dmsg, "parent dir is dead\n"); |
c2b27bf2 AM |
22326 | + goto out; |
22327 | + } | |
22328 | + | |
22329 | + a->bopq = au_dbdiropq(a->parent); | |
22330 | + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst); | |
22331 | + AuDbg("b%d\n", bindex); | |
22332 | + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst) | |
22333 | + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) { | |
22334 | + err = -EINVAL; | |
392086de AM |
22335 | + a->mvd_errno = EAU_MVDOWN_OPAQUE; |
22336 | + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n", | |
c2b27bf2 AM |
22337 | + a->bopq, a->mvd_bdst); |
22338 | + } | |
22339 | + | |
22340 | +out: | |
22341 | + AuTraceErr(err); | |
22342 | + return err; | |
22343 | +} | |
22344 | + | |
392086de | 22345 | +static int au_mvd_args_intermediate(const unsigned char dmsg, |
c2b27bf2 AM |
22346 | + struct au_mvd_args *a) |
22347 | +{ | |
22348 | + int err; | |
22349 | + struct au_dinfo *dinfo, *tmp; | |
22350 | + | |
22351 | + /* lookup the next lower positive entry */ | |
22352 | + err = -ENOMEM; | |
22353 | + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP); | |
22354 | + if (unlikely(!tmp)) | |
22355 | + goto out; | |
22356 | + | |
22357 | + a->bfound = -1; | |
22358 | + a->bwh = -1; | |
22359 | + dinfo = au_di(a->dentry); | |
22360 | + au_di_cp(tmp, dinfo); | |
22361 | + au_di_swap(tmp, dinfo); | |
22362 | + | |
22363 | + /* returns the number of positive dentries */ | |
22364 | + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0); | |
22365 | + if (!err) | |
22366 | + a->bwh = au_dbwh(a->dentry); | |
22367 | + else if (err > 0) | |
22368 | + a->bfound = au_dbstart(a->dentry); | |
22369 | + | |
22370 | + au_di_swap(tmp, dinfo); | |
22371 | + au_rw_write_unlock(&tmp->di_rwsem); | |
22372 | + au_di_free(tmp); | |
22373 | + if (unlikely(err < 0)) | |
392086de | 22374 | + AU_MVD_PR(dmsg, "failed look-up lower\n"); |
c2b27bf2 AM |
22375 | + |
22376 | + /* | |
22377 | + * here, we have these cases. | |
22378 | + * bfound == -1 | |
22379 | + * no positive dentry under bsrc. there are more sub-cases. | |
22380 | + * bwh < 0 | |
22381 | + * there no whiteout, we can safely move-down. | |
22382 | + * bwh <= bsrc | |
22383 | + * impossible | |
22384 | + * bsrc < bwh && bwh < bdst | |
22385 | + * there is a whiteout on RO branch. cannot proceed. | |
22386 | + * bwh == bdst | |
22387 | + * there is a whiteout on the RW target branch. it should | |
22388 | + * be removed. | |
22389 | + * bdst < bwh | |
22390 | + * there is a whiteout somewhere unrelated branch. | |
22391 | + * -1 < bfound && bfound <= bsrc | |
22392 | + * impossible. | |
22393 | + * bfound < bdst | |
22394 | + * found, but it is on RO branch between bsrc and bdst. cannot | |
22395 | + * proceed. | |
22396 | + * bfound == bdst | |
22397 | + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return | |
22398 | + * error. | |
22399 | + * bdst < bfound | |
22400 | + * found, after we create the file on bdst, it will be hidden. | |
22401 | + */ | |
22402 | + | |
22403 | + AuDebugOn(a->bfound == -1 | |
22404 | + && a->bwh != -1 | |
22405 | + && a->bwh <= a->mvd_bsrc); | |
22406 | + AuDebugOn(-1 < a->bfound | |
22407 | + && a->bfound <= a->mvd_bsrc); | |
22408 | + | |
22409 | + err = -EINVAL; | |
22410 | + if (a->bfound == -1 | |
22411 | + && a->mvd_bsrc < a->bwh | |
22412 | + && a->bwh != -1 | |
22413 | + && a->bwh < a->mvd_bdst) { | |
392086de AM |
22414 | + a->mvd_errno = EAU_MVDOWN_WHITEOUT; |
22415 | + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n", | |
c2b27bf2 AM |
22416 | + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh); |
22417 | + goto out; | |
22418 | + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) { | |
392086de AM |
22419 | + a->mvd_errno = EAU_MVDOWN_UPPER; |
22420 | + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n", | |
c2b27bf2 AM |
22421 | + a->mvd_bdst, a->bfound); |
22422 | + goto out; | |
22423 | + } | |
22424 | + | |
22425 | + err = 0; /* success */ | |
22426 | + | |
22427 | +out: | |
22428 | + AuTraceErr(err); | |
22429 | + return err; | |
22430 | +} | |
22431 | + | |
392086de | 22432 | +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22433 | +{ |
22434 | + int err; | |
22435 | + | |
392086de AM |
22436 | + err = 0; |
22437 | + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER) | |
22438 | + && a->bfound == a->mvd_bdst) | |
22439 | + err = -EEXIST; | |
c2b27bf2 AM |
22440 | + AuTraceErr(err); |
22441 | + return err; | |
22442 | +} | |
22443 | + | |
392086de | 22444 | +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22445 | +{ |
22446 | + int err; | |
22447 | + struct au_branch *br; | |
22448 | + | |
22449 | + err = -EISDIR; | |
22450 | + if (unlikely(S_ISDIR(a->inode->i_mode))) | |
22451 | + goto out; | |
22452 | + | |
22453 | + err = -EINVAL; | |
392086de AM |
22454 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER)) |
22455 | + a->mvd_bsrc = au_ibstart(a->inode); | |
22456 | + else { | |
22457 | + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid); | |
22458 | + if (unlikely(a->mvd_bsrc < 0 | |
22459 | + || (a->mvd_bsrc < au_dbstart(a->dentry) | |
22460 | + || au_dbend(a->dentry) < a->mvd_bsrc | |
22461 | + || !au_h_dptr(a->dentry, a->mvd_bsrc)) | |
22462 | + || (a->mvd_bsrc < au_ibstart(a->inode) | |
22463 | + || au_ibend(a->inode) < a->mvd_bsrc | |
22464 | + || !au_h_iptr(a->inode, a->mvd_bsrc)))) { | |
22465 | + a->mvd_errno = EAU_MVDOWN_NOUPPER; | |
22466 | + AU_MVD_PR(dmsg, "no upper\n"); | |
22467 | + goto out; | |
22468 | + } | |
22469 | + } | |
c2b27bf2 | 22470 | + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) { |
392086de AM |
22471 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; |
22472 | + AU_MVD_PR(dmsg, "on the bottom\n"); | |
c2b27bf2 AM |
22473 | + goto out; |
22474 | + } | |
392086de | 22475 | + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc); |
c2b27bf2 AM |
22476 | + br = au_sbr(a->sb, a->mvd_bsrc); |
22477 | + err = au_br_rdonly(br); | |
392086de AM |
22478 | + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) { |
22479 | + if (unlikely(err)) | |
22480 | + goto out; | |
22481 | + } else if (!(vfsub_native_ro(a->mvd_h_src_inode) | |
22482 | + || IS_APPEND(a->mvd_h_src_inode))) { | |
22483 | + if (err) | |
22484 | + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R; | |
22485 | + /* go on */ | |
22486 | + } else | |
c2b27bf2 AM |
22487 | + goto out; |
22488 | + | |
22489 | + err = -EINVAL; | |
392086de AM |
22490 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) { |
22491 | + a->mvd_bdst = find_lower_writable(a); | |
22492 | + if (unlikely(a->mvd_bdst < 0)) { | |
22493 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; | |
22494 | + AU_MVD_PR(dmsg, "no writable lower branch\n"); | |
22495 | + goto out; | |
22496 | + } | |
22497 | + } else { | |
22498 | + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid); | |
22499 | + if (unlikely(a->mvd_bdst < 0 | |
22500 | + || au_sbend(a->sb) < a->mvd_bdst)) { | |
22501 | + a->mvd_errno = EAU_MVDOWN_NOLOWERBR; | |
22502 | + AU_MVD_PR(dmsg, "no lower brid\n"); | |
22503 | + goto out; | |
22504 | + } | |
c2b27bf2 AM |
22505 | + } |
22506 | + | |
392086de | 22507 | + err = au_mvd_args_busy(dmsg, a); |
c2b27bf2 | 22508 | + if (!err) |
392086de | 22509 | + err = au_mvd_args_parent(dmsg, a); |
c2b27bf2 | 22510 | + if (!err) |
392086de | 22511 | + err = au_mvd_args_intermediate(dmsg, a); |
c2b27bf2 | 22512 | + if (!err) |
392086de | 22513 | + err = au_mvd_args_exist(dmsg, a); |
c2b27bf2 AM |
22514 | + if (!err) |
22515 | + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst); | |
22516 | + | |
22517 | +out: | |
22518 | + AuTraceErr(err); | |
22519 | + return err; | |
22520 | +} | |
22521 | + | |
22522 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg) | |
22523 | +{ | |
392086de AM |
22524 | + int err, e; |
22525 | + unsigned char dmsg; | |
22526 | + struct au_mvd_args *args; | |
c2b27bf2 AM |
22527 | + |
22528 | + err = -EPERM; | |
22529 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
22530 | + goto out; | |
22531 | + | |
392086de AM |
22532 | + err = -ENOMEM; |
22533 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
22534 | + if (unlikely(!args)) | |
22535 | + goto out; | |
22536 | + | |
22537 | + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown)); | |
22538 | + if (!err) | |
22539 | + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg)); | |
c2b27bf2 AM |
22540 | + if (unlikely(err)) { |
22541 | + err = -EFAULT; | |
392086de AM |
22542 | + AuTraceErr(err); |
22543 | + goto out_free; | |
c2b27bf2 | 22544 | + } |
392086de AM |
22545 | + AuDbg("flags 0x%x\n", args->mvdown.flags); |
22546 | + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R); | |
22547 | + args->mvdown.au_errno = 0; | |
22548 | + args->dentry = dentry; | |
5527c038 | 22549 | + args->inode = d_inode(dentry); |
392086de | 22550 | + args->sb = dentry->d_sb; |
c2b27bf2 | 22551 | + |
392086de AM |
22552 | + err = -ENOENT; |
22553 | + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG); | |
22554 | + args->parent = dget_parent(dentry); | |
5527c038 | 22555 | + args->dir = d_inode(args->parent); |
392086de AM |
22556 | + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT); |
22557 | + dput(args->parent); | |
22558 | + if (unlikely(args->parent != dentry->d_parent)) { | |
22559 | + AU_MVD_PR(dmsg, "parent dir is moved\n"); | |
c2b27bf2 AM |
22560 | + goto out_dir; |
22561 | + } | |
22562 | + | |
392086de | 22563 | + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD); |
c2b27bf2 AM |
22564 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH); |
22565 | + if (unlikely(err)) | |
22566 | + goto out_inode; | |
22567 | + | |
392086de AM |
22568 | + di_write_lock_parent(args->parent); |
22569 | + err = au_mvd_args(dmsg, args); | |
c2b27bf2 AM |
22570 | + if (unlikely(err)) |
22571 | + goto out_parent; | |
22572 | + | |
392086de | 22573 | + err = au_do_mvdown(dmsg, args); |
c2b27bf2 AM |
22574 | + if (unlikely(err)) |
22575 | + goto out_parent; | |
c2b27bf2 | 22576 | + |
392086de AM |
22577 | + au_cpup_attr_timesizes(args->dir); |
22578 | + au_cpup_attr_timesizes(args->inode); | |
22579 | + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst)); | |
c2b27bf2 AM |
22580 | + /* au_digen_dec(dentry); */ |
22581 | + | |
22582 | +out_parent: | |
392086de | 22583 | + di_write_unlock(args->parent); |
c2b27bf2 AM |
22584 | + aufs_read_unlock(dentry, AuLock_DW); |
22585 | +out_inode: | |
392086de | 22586 | + mutex_unlock(&args->inode->i_mutex); |
c2b27bf2 | 22587 | +out_dir: |
392086de AM |
22588 | + mutex_unlock(&args->dir->i_mutex); |
22589 | +out_free: | |
22590 | + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown)); | |
22591 | + if (unlikely(e)) | |
22592 | + err = -EFAULT; | |
22593 | + kfree(args); | |
c2b27bf2 AM |
22594 | +out: |
22595 | + AuTraceErr(err); | |
22596 | + return err; | |
22597 | +} | |
22598 | diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c | |
22599 | --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 22600 | +++ linux/fs/aufs/opts.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 22601 | @@ -0,0 +1,1835 @@ |
1facf9fc | 22602 | +/* |
2000de60 | 22603 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 22604 | + * |
22605 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22606 | + * it under the terms of the GNU General Public License as published by | |
22607 | + * the Free Software Foundation; either version 2 of the License, or | |
22608 | + * (at your option) any later version. | |
dece6358 AM |
22609 | + * |
22610 | + * This program is distributed in the hope that it will be useful, | |
22611 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22612 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22613 | + * GNU General Public License for more details. | |
22614 | + * | |
22615 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22616 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22617 | + */ |
22618 | + | |
22619 | +/* | |
22620 | + * mount options/flags | |
22621 | + */ | |
22622 | + | |
dece6358 | 22623 | +#include <linux/namei.h> |
1facf9fc | 22624 | +#include <linux/types.h> /* a distribution requires */ |
22625 | +#include <linux/parser.h> | |
22626 | +#include "aufs.h" | |
22627 | + | |
22628 | +/* ---------------------------------------------------------------------- */ | |
22629 | + | |
22630 | +enum { | |
22631 | + Opt_br, | |
7e9cd9fe AM |
22632 | + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend, |
22633 | + Opt_idel, Opt_imod, | |
22634 | + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, | |
dece6358 | 22635 | + Opt_rdblk_def, Opt_rdhash_def, |
7e9cd9fe | 22636 | + Opt_xino, Opt_noxino, |
1facf9fc | 22637 | + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino, |
22638 | + Opt_trunc_xino_path, Opt_itrunc_xino, | |
22639 | + Opt_trunc_xib, Opt_notrunc_xib, | |
dece6358 | 22640 | + Opt_shwh, Opt_noshwh, |
1facf9fc | 22641 | + Opt_plink, Opt_noplink, Opt_list_plink, |
22642 | + Opt_udba, | |
4a4d8108 | 22643 | + Opt_dio, Opt_nodio, |
1facf9fc | 22644 | + Opt_diropq_a, Opt_diropq_w, |
22645 | + Opt_warn_perm, Opt_nowarn_perm, | |
22646 | + Opt_wbr_copyup, Opt_wbr_create, | |
076b876e | 22647 | + Opt_fhsm_sec, |
1facf9fc | 22648 | + Opt_verbose, Opt_noverbose, |
22649 | + Opt_sum, Opt_nosum, Opt_wsum, | |
076b876e | 22650 | + Opt_dirperm1, Opt_nodirperm1, |
c1595e42 | 22651 | + Opt_acl, Opt_noacl, |
1facf9fc | 22652 | + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err |
22653 | +}; | |
22654 | + | |
22655 | +static match_table_t options = { | |
22656 | + {Opt_br, "br=%s"}, | |
22657 | + {Opt_br, "br:%s"}, | |
22658 | + | |
22659 | + {Opt_add, "add=%d:%s"}, | |
22660 | + {Opt_add, "add:%d:%s"}, | |
22661 | + {Opt_add, "ins=%d:%s"}, | |
22662 | + {Opt_add, "ins:%d:%s"}, | |
22663 | + {Opt_append, "append=%s"}, | |
22664 | + {Opt_append, "append:%s"}, | |
22665 | + {Opt_prepend, "prepend=%s"}, | |
22666 | + {Opt_prepend, "prepend:%s"}, | |
22667 | + | |
22668 | + {Opt_del, "del=%s"}, | |
22669 | + {Opt_del, "del:%s"}, | |
22670 | + /* {Opt_idel, "idel:%d"}, */ | |
22671 | + {Opt_mod, "mod=%s"}, | |
22672 | + {Opt_mod, "mod:%s"}, | |
22673 | + /* {Opt_imod, "imod:%d:%s"}, */ | |
22674 | + | |
22675 | + {Opt_dirwh, "dirwh=%d"}, | |
22676 | + | |
22677 | + {Opt_xino, "xino=%s"}, | |
22678 | + {Opt_noxino, "noxino"}, | |
22679 | + {Opt_trunc_xino, "trunc_xino"}, | |
22680 | + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"}, | |
22681 | + {Opt_notrunc_xino, "notrunc_xino"}, | |
22682 | + {Opt_trunc_xino_path, "trunc_xino=%s"}, | |
22683 | + {Opt_itrunc_xino, "itrunc_xino=%d"}, | |
22684 | + /* {Opt_zxino, "zxino=%s"}, */ | |
22685 | + {Opt_trunc_xib, "trunc_xib"}, | |
22686 | + {Opt_notrunc_xib, "notrunc_xib"}, | |
22687 | + | |
e49829fe | 22688 | +#ifdef CONFIG_PROC_FS |
1facf9fc | 22689 | + {Opt_plink, "plink"}, |
e49829fe JR |
22690 | +#else |
22691 | + {Opt_ignore_silent, "plink"}, | |
22692 | +#endif | |
22693 | + | |
1facf9fc | 22694 | + {Opt_noplink, "noplink"}, |
e49829fe | 22695 | + |
1facf9fc | 22696 | +#ifdef CONFIG_AUFS_DEBUG |
22697 | + {Opt_list_plink, "list_plink"}, | |
22698 | +#endif | |
22699 | + | |
22700 | + {Opt_udba, "udba=%s"}, | |
22701 | + | |
4a4d8108 AM |
22702 | + {Opt_dio, "dio"}, |
22703 | + {Opt_nodio, "nodio"}, | |
22704 | + | |
076b876e AM |
22705 | +#ifdef CONFIG_AUFS_FHSM |
22706 | + {Opt_fhsm_sec, "fhsm_sec=%d"}, | |
22707 | +#else | |
22708 | + {Opt_ignore_silent, "fhsm_sec=%d"}, | |
22709 | +#endif | |
22710 | + | |
1facf9fc | 22711 | + {Opt_diropq_a, "diropq=always"}, |
22712 | + {Opt_diropq_a, "diropq=a"}, | |
22713 | + {Opt_diropq_w, "diropq=whiteouted"}, | |
22714 | + {Opt_diropq_w, "diropq=w"}, | |
22715 | + | |
22716 | + {Opt_warn_perm, "warn_perm"}, | |
22717 | + {Opt_nowarn_perm, "nowarn_perm"}, | |
22718 | + | |
22719 | + /* keep them temporary */ | |
1facf9fc | 22720 | + {Opt_ignore_silent, "nodlgt"}, |
1facf9fc | 22721 | + {Opt_ignore_silent, "clean_plink"}, |
22722 | + | |
dece6358 AM |
22723 | +#ifdef CONFIG_AUFS_SHWH |
22724 | + {Opt_shwh, "shwh"}, | |
22725 | +#endif | |
22726 | + {Opt_noshwh, "noshwh"}, | |
22727 | + | |
076b876e AM |
22728 | + {Opt_dirperm1, "dirperm1"}, |
22729 | + {Opt_nodirperm1, "nodirperm1"}, | |
22730 | + | |
1facf9fc | 22731 | + {Opt_verbose, "verbose"}, |
22732 | + {Opt_verbose, "v"}, | |
22733 | + {Opt_noverbose, "noverbose"}, | |
22734 | + {Opt_noverbose, "quiet"}, | |
22735 | + {Opt_noverbose, "q"}, | |
22736 | + {Opt_noverbose, "silent"}, | |
22737 | + | |
22738 | + {Opt_sum, "sum"}, | |
22739 | + {Opt_nosum, "nosum"}, | |
22740 | + {Opt_wsum, "wsum"}, | |
22741 | + | |
22742 | + {Opt_rdcache, "rdcache=%d"}, | |
22743 | + {Opt_rdblk, "rdblk=%d"}, | |
dece6358 | 22744 | + {Opt_rdblk_def, "rdblk=def"}, |
1facf9fc | 22745 | + {Opt_rdhash, "rdhash=%d"}, |
dece6358 | 22746 | + {Opt_rdhash_def, "rdhash=def"}, |
1facf9fc | 22747 | + |
22748 | + {Opt_wbr_create, "create=%s"}, | |
22749 | + {Opt_wbr_create, "create_policy=%s"}, | |
22750 | + {Opt_wbr_copyup, "cpup=%s"}, | |
22751 | + {Opt_wbr_copyup, "copyup=%s"}, | |
22752 | + {Opt_wbr_copyup, "copyup_policy=%s"}, | |
22753 | + | |
c1595e42 JR |
22754 | + /* generic VFS flag */ |
22755 | +#ifdef CONFIG_FS_POSIX_ACL | |
22756 | + {Opt_acl, "acl"}, | |
22757 | + {Opt_noacl, "noacl"}, | |
22758 | +#else | |
22759 | + {Opt_ignore_silent, "acl"}, | |
22760 | + {Opt_ignore_silent, "noacl"}, | |
22761 | +#endif | |
22762 | + | |
1facf9fc | 22763 | + /* internal use for the scripts */ |
22764 | + {Opt_ignore_silent, "si=%s"}, | |
22765 | + | |
22766 | + {Opt_br, "dirs=%s"}, | |
22767 | + {Opt_ignore, "debug=%d"}, | |
22768 | + {Opt_ignore, "delete=whiteout"}, | |
22769 | + {Opt_ignore, "delete=all"}, | |
22770 | + {Opt_ignore, "imap=%s"}, | |
22771 | + | |
1308ab2a | 22772 | + /* temporary workaround, due to old mount(8)? */ |
22773 | + {Opt_ignore_silent, "relatime"}, | |
22774 | + | |
1facf9fc | 22775 | + {Opt_err, NULL} |
22776 | +}; | |
22777 | + | |
22778 | +/* ---------------------------------------------------------------------- */ | |
22779 | + | |
076b876e | 22780 | +static const char *au_parser_pattern(int val, match_table_t tbl) |
1facf9fc | 22781 | +{ |
076b876e AM |
22782 | + struct match_token *p; |
22783 | + | |
22784 | + p = tbl; | |
22785 | + while (p->pattern) { | |
22786 | + if (p->token == val) | |
22787 | + return p->pattern; | |
22788 | + p++; | |
1facf9fc | 22789 | + } |
22790 | + BUG(); | |
22791 | + return "??"; | |
22792 | +} | |
22793 | + | |
076b876e AM |
22794 | +static const char *au_optstr(int *val, match_table_t tbl) |
22795 | +{ | |
22796 | + struct match_token *p; | |
22797 | + int v; | |
22798 | + | |
22799 | + v = *val; | |
2000de60 JR |
22800 | + if (!v) |
22801 | + goto out; | |
076b876e | 22802 | + p = tbl; |
2000de60 JR |
22803 | + while (p->pattern) { |
22804 | + if (p->token | |
22805 | + && (v & p->token) == p->token) { | |
076b876e AM |
22806 | + *val &= ~p->token; |
22807 | + return p->pattern; | |
22808 | + } | |
22809 | + p++; | |
22810 | + } | |
2000de60 JR |
22811 | + |
22812 | +out: | |
076b876e AM |
22813 | + return NULL; |
22814 | +} | |
22815 | + | |
1facf9fc | 22816 | +/* ---------------------------------------------------------------------- */ |
22817 | + | |
1e00d052 | 22818 | +static match_table_t brperm = { |
1facf9fc | 22819 | + {AuBrPerm_RO, AUFS_BRPERM_RO}, |
22820 | + {AuBrPerm_RR, AUFS_BRPERM_RR}, | |
22821 | + {AuBrPerm_RW, AUFS_BRPERM_RW}, | |
1e00d052 AM |
22822 | + {0, NULL} |
22823 | +}; | |
1facf9fc | 22824 | + |
86dc4139 | 22825 | +static match_table_t brattr = { |
076b876e AM |
22826 | + /* general */ |
22827 | + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG}, | |
22828 | + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL}, | |
c1595e42 | 22829 | + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */ |
86dc4139 | 22830 | + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN}, |
2000de60 | 22831 | +#ifdef CONFIG_AUFS_FHSM |
076b876e | 22832 | + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM}, |
2000de60 JR |
22833 | +#endif |
22834 | +#ifdef CONFIG_AUFS_XATTR | |
c1595e42 JR |
22835 | + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX}, |
22836 | + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC}, | |
22837 | + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS}, | |
22838 | + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR}, | |
22839 | + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR}, | |
22840 | + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH}, | |
2000de60 | 22841 | +#endif |
076b876e AM |
22842 | + |
22843 | + /* ro/rr branch */ | |
1e00d052 | 22844 | + {AuBrRAttr_WH, AUFS_BRRATTR_WH}, |
076b876e AM |
22845 | + |
22846 | + /* rw branch */ | |
22847 | + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO}, | |
1e00d052 | 22848 | + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH}, |
076b876e | 22849 | + |
1e00d052 | 22850 | + {0, NULL} |
1facf9fc | 22851 | +}; |
22852 | + | |
1e00d052 AM |
22853 | +static int br_attr_val(char *str, match_table_t table, substring_t args[]) |
22854 | +{ | |
22855 | + int attr, v; | |
22856 | + char *p; | |
22857 | + | |
22858 | + attr = 0; | |
22859 | + do { | |
22860 | + p = strchr(str, '+'); | |
22861 | + if (p) | |
22862 | + *p = 0; | |
22863 | + v = match_token(str, table, args); | |
076b876e AM |
22864 | + if (v) { |
22865 | + if (v & AuBrAttr_CMOO_Mask) | |
22866 | + attr &= ~AuBrAttr_CMOO_Mask; | |
1e00d052 | 22867 | + attr |= v; |
076b876e | 22868 | + } else { |
1e00d052 AM |
22869 | + if (p) |
22870 | + *p = '+'; | |
0c3ec466 | 22871 | + pr_warn("ignored branch attribute %s\n", str); |
1e00d052 AM |
22872 | + break; |
22873 | + } | |
22874 | + if (p) | |
22875 | + str = p + 1; | |
22876 | + } while (p); | |
22877 | + | |
22878 | + return attr; | |
22879 | +} | |
22880 | + | |
076b876e AM |
22881 | +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm) |
22882 | +{ | |
22883 | + int sz; | |
22884 | + const char *p; | |
22885 | + char *q; | |
22886 | + | |
076b876e AM |
22887 | + q = str->a; |
22888 | + *q = 0; | |
22889 | + p = au_optstr(&perm, brattr); | |
22890 | + if (p) { | |
22891 | + sz = strlen(p); | |
22892 | + memcpy(q, p, sz + 1); | |
22893 | + q += sz; | |
22894 | + } else | |
22895 | + goto out; | |
22896 | + | |
22897 | + do { | |
22898 | + p = au_optstr(&perm, brattr); | |
22899 | + if (p) { | |
22900 | + *q++ = '+'; | |
22901 | + sz = strlen(p); | |
22902 | + memcpy(q, p, sz + 1); | |
22903 | + q += sz; | |
22904 | + } | |
22905 | + } while (p); | |
22906 | + | |
22907 | +out: | |
c1595e42 | 22908 | + return q - str->a; |
076b876e AM |
22909 | +} |
22910 | + | |
4a4d8108 | 22911 | +static int noinline_for_stack br_perm_val(char *perm) |
1facf9fc | 22912 | +{ |
076b876e AM |
22913 | + int val, bad, sz; |
22914 | + char *p; | |
1facf9fc | 22915 | + substring_t args[MAX_OPT_ARGS]; |
076b876e | 22916 | + au_br_perm_str_t attr; |
1facf9fc | 22917 | + |
1e00d052 AM |
22918 | + p = strchr(perm, '+'); |
22919 | + if (p) | |
22920 | + *p = 0; | |
22921 | + val = match_token(perm, brperm, args); | |
22922 | + if (!val) { | |
22923 | + if (p) | |
22924 | + *p = '+'; | |
0c3ec466 | 22925 | + pr_warn("ignored branch permission %s\n", perm); |
1e00d052 AM |
22926 | + val = AuBrPerm_RO; |
22927 | + goto out; | |
22928 | + } | |
22929 | + if (!p) | |
22930 | + goto out; | |
22931 | + | |
076b876e AM |
22932 | + val |= br_attr_val(p + 1, brattr, args); |
22933 | + | |
22934 | + bad = 0; | |
86dc4139 | 22935 | + switch (val & AuBrPerm_Mask) { |
1e00d052 AM |
22936 | + case AuBrPerm_RO: |
22937 | + case AuBrPerm_RR: | |
076b876e AM |
22938 | + bad = val & AuBrWAttr_Mask; |
22939 | + val &= ~AuBrWAttr_Mask; | |
1e00d052 AM |
22940 | + break; |
22941 | + case AuBrPerm_RW: | |
076b876e AM |
22942 | + bad = val & AuBrRAttr_Mask; |
22943 | + val &= ~AuBrRAttr_Mask; | |
1e00d052 AM |
22944 | + break; |
22945 | + } | |
c1595e42 JR |
22946 | + |
22947 | + /* | |
22948 | + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs | |
22949 | + * does not treat it as an error, just warning. | |
22950 | + * this is a tiny guard for the user operation. | |
22951 | + */ | |
22952 | + if (val & AuBrAttr_UNPIN) { | |
22953 | + bad |= AuBrAttr_UNPIN; | |
22954 | + val &= ~AuBrAttr_UNPIN; | |
22955 | + } | |
22956 | + | |
076b876e AM |
22957 | + if (unlikely(bad)) { |
22958 | + sz = au_do_optstr_br_attr(&attr, bad); | |
22959 | + AuDebugOn(!sz); | |
22960 | + pr_warn("ignored branch attribute %s\n", attr.a); | |
22961 | + } | |
1e00d052 AM |
22962 | + |
22963 | +out: | |
1facf9fc | 22964 | + return val; |
22965 | +} | |
22966 | + | |
076b876e | 22967 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm) |
1facf9fc | 22968 | +{ |
076b876e AM |
22969 | + au_br_perm_str_t attr; |
22970 | + const char *p; | |
22971 | + char *q; | |
1e00d052 AM |
22972 | + int sz; |
22973 | + | |
076b876e AM |
22974 | + q = str->a; |
22975 | + p = au_optstr(&perm, brperm); | |
22976 | + AuDebugOn(!p || !*p); | |
22977 | + sz = strlen(p); | |
22978 | + memcpy(q, p, sz + 1); | |
22979 | + q += sz; | |
1e00d052 | 22980 | + |
076b876e AM |
22981 | + sz = au_do_optstr_br_attr(&attr, perm); |
22982 | + if (sz) { | |
22983 | + *q++ = '+'; | |
22984 | + memcpy(q, attr.a, sz + 1); | |
1e00d052 AM |
22985 | + } |
22986 | + | |
076b876e | 22987 | + AuDebugOn(strlen(str->a) >= sizeof(str->a)); |
1facf9fc | 22988 | +} |
22989 | + | |
22990 | +/* ---------------------------------------------------------------------- */ | |
22991 | + | |
22992 | +static match_table_t udbalevel = { | |
22993 | + {AuOpt_UDBA_REVAL, "reval"}, | |
22994 | + {AuOpt_UDBA_NONE, "none"}, | |
4a4d8108 AM |
22995 | +#ifdef CONFIG_AUFS_HNOTIFY |
22996 | + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */ | |
22997 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
22998 | + {AuOpt_UDBA_HNOTIFY, "fsnotify"}, | |
4a4d8108 | 22999 | +#endif |
1facf9fc | 23000 | +#endif |
23001 | + {-1, NULL} | |
23002 | +}; | |
23003 | + | |
4a4d8108 | 23004 | +static int noinline_for_stack udba_val(char *str) |
1facf9fc | 23005 | +{ |
23006 | + substring_t args[MAX_OPT_ARGS]; | |
23007 | + | |
7f207e10 | 23008 | + return match_token(str, udbalevel, args); |
1facf9fc | 23009 | +} |
23010 | + | |
23011 | +const char *au_optstr_udba(int udba) | |
23012 | +{ | |
076b876e | 23013 | + return au_parser_pattern(udba, udbalevel); |
1facf9fc | 23014 | +} |
23015 | + | |
23016 | +/* ---------------------------------------------------------------------- */ | |
23017 | + | |
23018 | +static match_table_t au_wbr_create_policy = { | |
23019 | + {AuWbrCreate_TDP, "tdp"}, | |
23020 | + {AuWbrCreate_TDP, "top-down-parent"}, | |
23021 | + {AuWbrCreate_RR, "rr"}, | |
23022 | + {AuWbrCreate_RR, "round-robin"}, | |
23023 | + {AuWbrCreate_MFS, "mfs"}, | |
23024 | + {AuWbrCreate_MFS, "most-free-space"}, | |
23025 | + {AuWbrCreate_MFSV, "mfs:%d"}, | |
23026 | + {AuWbrCreate_MFSV, "most-free-space:%d"}, | |
23027 | + | |
23028 | + {AuWbrCreate_MFSRR, "mfsrr:%d"}, | |
23029 | + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"}, | |
23030 | + {AuWbrCreate_PMFS, "pmfs"}, | |
23031 | + {AuWbrCreate_PMFSV, "pmfs:%d"}, | |
392086de AM |
23032 | + {AuWbrCreate_PMFSRR, "pmfsrr:%d"}, |
23033 | + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"}, | |
1facf9fc | 23034 | + |
23035 | + {-1, NULL} | |
23036 | +}; | |
23037 | + | |
dece6358 AM |
23038 | +/* |
23039 | + * cf. linux/lib/parser.c and cmdline.c | |
23040 | + * gave up calling memparse() since it uses simple_strtoull() instead of | |
9dbd164d | 23041 | + * kstrto...(). |
dece6358 | 23042 | + */ |
4a4d8108 AM |
23043 | +static int noinline_for_stack |
23044 | +au_match_ull(substring_t *s, unsigned long long *result) | |
1facf9fc | 23045 | +{ |
23046 | + int err; | |
23047 | + unsigned int len; | |
23048 | + char a[32]; | |
23049 | + | |
23050 | + err = -ERANGE; | |
23051 | + len = s->to - s->from; | |
23052 | + if (len + 1 <= sizeof(a)) { | |
23053 | + memcpy(a, s->from, len); | |
23054 | + a[len] = '\0'; | |
9dbd164d | 23055 | + err = kstrtoull(a, 0, result); |
1facf9fc | 23056 | + } |
23057 | + return err; | |
23058 | +} | |
23059 | + | |
23060 | +static int au_wbr_mfs_wmark(substring_t *arg, char *str, | |
23061 | + struct au_opt_wbr_create *create) | |
23062 | +{ | |
23063 | + int err; | |
23064 | + unsigned long long ull; | |
23065 | + | |
23066 | + err = 0; | |
23067 | + if (!au_match_ull(arg, &ull)) | |
23068 | + create->mfsrr_watermark = ull; | |
23069 | + else { | |
4a4d8108 | 23070 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 23071 | + err = -EINVAL; |
23072 | + } | |
23073 | + | |
23074 | + return err; | |
23075 | +} | |
23076 | + | |
23077 | +static int au_wbr_mfs_sec(substring_t *arg, char *str, | |
23078 | + struct au_opt_wbr_create *create) | |
23079 | +{ | |
23080 | + int n, err; | |
23081 | + | |
23082 | + err = 0; | |
027c5e7a | 23083 | + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC) |
1facf9fc | 23084 | + create->mfs_second = n; |
23085 | + else { | |
4a4d8108 | 23086 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 23087 | + err = -EINVAL; |
23088 | + } | |
23089 | + | |
23090 | + return err; | |
23091 | +} | |
23092 | + | |
4a4d8108 AM |
23093 | +static int noinline_for_stack |
23094 | +au_wbr_create_val(char *str, struct au_opt_wbr_create *create) | |
1facf9fc | 23095 | +{ |
23096 | + int err, e; | |
23097 | + substring_t args[MAX_OPT_ARGS]; | |
23098 | + | |
23099 | + err = match_token(str, au_wbr_create_policy, args); | |
23100 | + create->wbr_create = err; | |
23101 | + switch (err) { | |
23102 | + case AuWbrCreate_MFSRRV: | |
392086de | 23103 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 23104 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
23105 | + if (!e) | |
23106 | + e = au_wbr_mfs_sec(&args[1], str, create); | |
23107 | + if (unlikely(e)) | |
23108 | + err = e; | |
23109 | + break; | |
23110 | + case AuWbrCreate_MFSRR: | |
392086de | 23111 | + case AuWbrCreate_PMFSRR: |
1facf9fc | 23112 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
23113 | + if (unlikely(e)) { | |
23114 | + err = e; | |
23115 | + break; | |
23116 | + } | |
23117 | + /*FALLTHROUGH*/ | |
23118 | + case AuWbrCreate_MFS: | |
23119 | + case AuWbrCreate_PMFS: | |
027c5e7a | 23120 | + create->mfs_second = AUFS_MFS_DEF_SEC; |
1facf9fc | 23121 | + break; |
23122 | + case AuWbrCreate_MFSV: | |
23123 | + case AuWbrCreate_PMFSV: | |
23124 | + e = au_wbr_mfs_sec(&args[0], str, create); | |
23125 | + if (unlikely(e)) | |
23126 | + err = e; | |
23127 | + break; | |
23128 | + } | |
23129 | + | |
23130 | + return err; | |
23131 | +} | |
23132 | + | |
23133 | +const char *au_optstr_wbr_create(int wbr_create) | |
23134 | +{ | |
076b876e | 23135 | + return au_parser_pattern(wbr_create, au_wbr_create_policy); |
1facf9fc | 23136 | +} |
23137 | + | |
23138 | +static match_table_t au_wbr_copyup_policy = { | |
23139 | + {AuWbrCopyup_TDP, "tdp"}, | |
23140 | + {AuWbrCopyup_TDP, "top-down-parent"}, | |
23141 | + {AuWbrCopyup_BUP, "bup"}, | |
23142 | + {AuWbrCopyup_BUP, "bottom-up-parent"}, | |
23143 | + {AuWbrCopyup_BU, "bu"}, | |
23144 | + {AuWbrCopyup_BU, "bottom-up"}, | |
23145 | + {-1, NULL} | |
23146 | +}; | |
23147 | + | |
4a4d8108 | 23148 | +static int noinline_for_stack au_wbr_copyup_val(char *str) |
1facf9fc | 23149 | +{ |
23150 | + substring_t args[MAX_OPT_ARGS]; | |
23151 | + | |
23152 | + return match_token(str, au_wbr_copyup_policy, args); | |
23153 | +} | |
23154 | + | |
23155 | +const char *au_optstr_wbr_copyup(int wbr_copyup) | |
23156 | +{ | |
076b876e | 23157 | + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy); |
1facf9fc | 23158 | +} |
23159 | + | |
23160 | +/* ---------------------------------------------------------------------- */ | |
23161 | + | |
23162 | +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY; | |
23163 | + | |
23164 | +static void dump_opts(struct au_opts *opts) | |
23165 | +{ | |
23166 | +#ifdef CONFIG_AUFS_DEBUG | |
23167 | + /* reduce stack space */ | |
23168 | + union { | |
23169 | + struct au_opt_add *add; | |
23170 | + struct au_opt_del *del; | |
23171 | + struct au_opt_mod *mod; | |
23172 | + struct au_opt_xino *xino; | |
23173 | + struct au_opt_xino_itrunc *xino_itrunc; | |
23174 | + struct au_opt_wbr_create *create; | |
23175 | + } u; | |
23176 | + struct au_opt *opt; | |
23177 | + | |
23178 | + opt = opts->opt; | |
23179 | + while (opt->type != Opt_tail) { | |
23180 | + switch (opt->type) { | |
23181 | + case Opt_add: | |
23182 | + u.add = &opt->add; | |
23183 | + AuDbg("add {b%d, %s, 0x%x, %p}\n", | |
23184 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23185 | + u.add->path.dentry); | |
23186 | + break; | |
23187 | + case Opt_del: | |
23188 | + case Opt_idel: | |
23189 | + u.del = &opt->del; | |
23190 | + AuDbg("del {%s, %p}\n", | |
23191 | + u.del->pathname, u.del->h_path.dentry); | |
23192 | + break; | |
23193 | + case Opt_mod: | |
23194 | + case Opt_imod: | |
23195 | + u.mod = &opt->mod; | |
23196 | + AuDbg("mod {%s, 0x%x, %p}\n", | |
23197 | + u.mod->path, u.mod->perm, u.mod->h_root); | |
23198 | + break; | |
23199 | + case Opt_append: | |
23200 | + u.add = &opt->add; | |
23201 | + AuDbg("append {b%d, %s, 0x%x, %p}\n", | |
23202 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23203 | + u.add->path.dentry); | |
23204 | + break; | |
23205 | + case Opt_prepend: | |
23206 | + u.add = &opt->add; | |
23207 | + AuDbg("prepend {b%d, %s, 0x%x, %p}\n", | |
23208 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23209 | + u.add->path.dentry); | |
23210 | + break; | |
23211 | + case Opt_dirwh: | |
23212 | + AuDbg("dirwh %d\n", opt->dirwh); | |
23213 | + break; | |
23214 | + case Opt_rdcache: | |
23215 | + AuDbg("rdcache %d\n", opt->rdcache); | |
23216 | + break; | |
23217 | + case Opt_rdblk: | |
23218 | + AuDbg("rdblk %u\n", opt->rdblk); | |
23219 | + break; | |
dece6358 AM |
23220 | + case Opt_rdblk_def: |
23221 | + AuDbg("rdblk_def\n"); | |
23222 | + break; | |
1facf9fc | 23223 | + case Opt_rdhash: |
23224 | + AuDbg("rdhash %u\n", opt->rdhash); | |
23225 | + break; | |
dece6358 AM |
23226 | + case Opt_rdhash_def: |
23227 | + AuDbg("rdhash_def\n"); | |
23228 | + break; | |
1facf9fc | 23229 | + case Opt_xino: |
23230 | + u.xino = &opt->xino; | |
523b37e3 | 23231 | + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file); |
1facf9fc | 23232 | + break; |
23233 | + case Opt_trunc_xino: | |
23234 | + AuLabel(trunc_xino); | |
23235 | + break; | |
23236 | + case Opt_notrunc_xino: | |
23237 | + AuLabel(notrunc_xino); | |
23238 | + break; | |
23239 | + case Opt_trunc_xino_path: | |
23240 | + case Opt_itrunc_xino: | |
23241 | + u.xino_itrunc = &opt->xino_itrunc; | |
23242 | + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex); | |
23243 | + break; | |
1facf9fc | 23244 | + case Opt_noxino: |
23245 | + AuLabel(noxino); | |
23246 | + break; | |
23247 | + case Opt_trunc_xib: | |
23248 | + AuLabel(trunc_xib); | |
23249 | + break; | |
23250 | + case Opt_notrunc_xib: | |
23251 | + AuLabel(notrunc_xib); | |
23252 | + break; | |
dece6358 AM |
23253 | + case Opt_shwh: |
23254 | + AuLabel(shwh); | |
23255 | + break; | |
23256 | + case Opt_noshwh: | |
23257 | + AuLabel(noshwh); | |
23258 | + break; | |
076b876e AM |
23259 | + case Opt_dirperm1: |
23260 | + AuLabel(dirperm1); | |
23261 | + break; | |
23262 | + case Opt_nodirperm1: | |
23263 | + AuLabel(nodirperm1); | |
23264 | + break; | |
1facf9fc | 23265 | + case Opt_plink: |
23266 | + AuLabel(plink); | |
23267 | + break; | |
23268 | + case Opt_noplink: | |
23269 | + AuLabel(noplink); | |
23270 | + break; | |
23271 | + case Opt_list_plink: | |
23272 | + AuLabel(list_plink); | |
23273 | + break; | |
23274 | + case Opt_udba: | |
23275 | + AuDbg("udba %d, %s\n", | |
23276 | + opt->udba, au_optstr_udba(opt->udba)); | |
23277 | + break; | |
4a4d8108 AM |
23278 | + case Opt_dio: |
23279 | + AuLabel(dio); | |
23280 | + break; | |
23281 | + case Opt_nodio: | |
23282 | + AuLabel(nodio); | |
23283 | + break; | |
1facf9fc | 23284 | + case Opt_diropq_a: |
23285 | + AuLabel(diropq_a); | |
23286 | + break; | |
23287 | + case Opt_diropq_w: | |
23288 | + AuLabel(diropq_w); | |
23289 | + break; | |
23290 | + case Opt_warn_perm: | |
23291 | + AuLabel(warn_perm); | |
23292 | + break; | |
23293 | + case Opt_nowarn_perm: | |
23294 | + AuLabel(nowarn_perm); | |
23295 | + break; | |
1facf9fc | 23296 | + case Opt_verbose: |
23297 | + AuLabel(verbose); | |
23298 | + break; | |
23299 | + case Opt_noverbose: | |
23300 | + AuLabel(noverbose); | |
23301 | + break; | |
23302 | + case Opt_sum: | |
23303 | + AuLabel(sum); | |
23304 | + break; | |
23305 | + case Opt_nosum: | |
23306 | + AuLabel(nosum); | |
23307 | + break; | |
23308 | + case Opt_wsum: | |
23309 | + AuLabel(wsum); | |
23310 | + break; | |
23311 | + case Opt_wbr_create: | |
23312 | + u.create = &opt->wbr_create; | |
23313 | + AuDbg("create %d, %s\n", u.create->wbr_create, | |
23314 | + au_optstr_wbr_create(u.create->wbr_create)); | |
23315 | + switch (u.create->wbr_create) { | |
23316 | + case AuWbrCreate_MFSV: | |
23317 | + case AuWbrCreate_PMFSV: | |
23318 | + AuDbg("%d sec\n", u.create->mfs_second); | |
23319 | + break; | |
23320 | + case AuWbrCreate_MFSRR: | |
23321 | + AuDbg("%llu watermark\n", | |
23322 | + u.create->mfsrr_watermark); | |
23323 | + break; | |
23324 | + case AuWbrCreate_MFSRRV: | |
392086de | 23325 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 23326 | + AuDbg("%llu watermark, %d sec\n", |
23327 | + u.create->mfsrr_watermark, | |
23328 | + u.create->mfs_second); | |
23329 | + break; | |
23330 | + } | |
23331 | + break; | |
23332 | + case Opt_wbr_copyup: | |
23333 | + AuDbg("copyup %d, %s\n", opt->wbr_copyup, | |
23334 | + au_optstr_wbr_copyup(opt->wbr_copyup)); | |
23335 | + break; | |
076b876e AM |
23336 | + case Opt_fhsm_sec: |
23337 | + AuDbg("fhsm_sec %u\n", opt->fhsm_second); | |
23338 | + break; | |
c1595e42 JR |
23339 | + case Opt_acl: |
23340 | + AuLabel(acl); | |
23341 | + break; | |
23342 | + case Opt_noacl: | |
23343 | + AuLabel(noacl); | |
23344 | + break; | |
1facf9fc | 23345 | + default: |
23346 | + BUG(); | |
23347 | + } | |
23348 | + opt++; | |
23349 | + } | |
23350 | +#endif | |
23351 | +} | |
23352 | + | |
23353 | +void au_opts_free(struct au_opts *opts) | |
23354 | +{ | |
23355 | + struct au_opt *opt; | |
23356 | + | |
23357 | + opt = opts->opt; | |
23358 | + while (opt->type != Opt_tail) { | |
23359 | + switch (opt->type) { | |
23360 | + case Opt_add: | |
23361 | + case Opt_append: | |
23362 | + case Opt_prepend: | |
23363 | + path_put(&opt->add.path); | |
23364 | + break; | |
23365 | + case Opt_del: | |
23366 | + case Opt_idel: | |
23367 | + path_put(&opt->del.h_path); | |
23368 | + break; | |
23369 | + case Opt_mod: | |
23370 | + case Opt_imod: | |
23371 | + dput(opt->mod.h_root); | |
23372 | + break; | |
23373 | + case Opt_xino: | |
23374 | + fput(opt->xino.file); | |
23375 | + break; | |
23376 | + } | |
23377 | + opt++; | |
23378 | + } | |
23379 | +} | |
23380 | + | |
23381 | +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags, | |
23382 | + aufs_bindex_t bindex) | |
23383 | +{ | |
23384 | + int err; | |
23385 | + struct au_opt_add *add = &opt->add; | |
23386 | + char *p; | |
23387 | + | |
23388 | + add->bindex = bindex; | |
1e00d052 | 23389 | + add->perm = AuBrPerm_RO; |
1facf9fc | 23390 | + add->pathname = opt_str; |
23391 | + p = strchr(opt_str, '='); | |
23392 | + if (p) { | |
23393 | + *p++ = 0; | |
23394 | + if (*p) | |
23395 | + add->perm = br_perm_val(p); | |
23396 | + } | |
23397 | + | |
23398 | + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path); | |
23399 | + if (!err) { | |
23400 | + if (!p) { | |
23401 | + add->perm = AuBrPerm_RO; | |
23402 | + if (au_test_fs_rr(add->path.dentry->d_sb)) | |
23403 | + add->perm = AuBrPerm_RR; | |
23404 | + else if (!bindex && !(sb_flags & MS_RDONLY)) | |
23405 | + add->perm = AuBrPerm_RW; | |
23406 | + } | |
23407 | + opt->type = Opt_add; | |
23408 | + goto out; | |
23409 | + } | |
4a4d8108 | 23410 | + pr_err("lookup failed %s (%d)\n", add->pathname, err); |
1facf9fc | 23411 | + err = -EINVAL; |
23412 | + | |
4f0767ce | 23413 | +out: |
1facf9fc | 23414 | + return err; |
23415 | +} | |
23416 | + | |
23417 | +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[]) | |
23418 | +{ | |
23419 | + int err; | |
23420 | + | |
23421 | + del->pathname = args[0].from; | |
23422 | + AuDbg("del path %s\n", del->pathname); | |
23423 | + | |
23424 | + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path); | |
23425 | + if (unlikely(err)) | |
4a4d8108 | 23426 | + pr_err("lookup failed %s (%d)\n", del->pathname, err); |
1facf9fc | 23427 | + |
23428 | + return err; | |
23429 | +} | |
23430 | + | |
23431 | +#if 0 /* reserved for future use */ | |
23432 | +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex, | |
23433 | + struct au_opt_del *del, substring_t args[]) | |
23434 | +{ | |
23435 | + int err; | |
23436 | + struct dentry *root; | |
23437 | + | |
23438 | + err = -EINVAL; | |
23439 | + root = sb->s_root; | |
23440 | + aufs_read_lock(root, AuLock_FLUSH); | |
23441 | + if (bindex < 0 || au_sbend(sb) < bindex) { | |
4a4d8108 | 23442 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 23443 | + goto out; |
23444 | + } | |
23445 | + | |
23446 | + err = 0; | |
23447 | + del->h_path.dentry = dget(au_h_dptr(root, bindex)); | |
23448 | + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex)); | |
23449 | + | |
4f0767ce | 23450 | +out: |
1facf9fc | 23451 | + aufs_read_unlock(root, !AuLock_IR); |
23452 | + return err; | |
23453 | +} | |
23454 | +#endif | |
23455 | + | |
4a4d8108 AM |
23456 | +static int noinline_for_stack |
23457 | +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[]) | |
1facf9fc | 23458 | +{ |
23459 | + int err; | |
23460 | + struct path path; | |
23461 | + char *p; | |
23462 | + | |
23463 | + err = -EINVAL; | |
23464 | + mod->path = args[0].from; | |
23465 | + p = strchr(mod->path, '='); | |
23466 | + if (unlikely(!p)) { | |
4a4d8108 | 23467 | + pr_err("no permssion %s\n", args[0].from); |
1facf9fc | 23468 | + goto out; |
23469 | + } | |
23470 | + | |
23471 | + *p++ = 0; | |
23472 | + err = vfsub_kern_path(mod->path, lkup_dirflags, &path); | |
23473 | + if (unlikely(err)) { | |
4a4d8108 | 23474 | + pr_err("lookup failed %s (%d)\n", mod->path, err); |
1facf9fc | 23475 | + goto out; |
23476 | + } | |
23477 | + | |
23478 | + mod->perm = br_perm_val(p); | |
23479 | + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p); | |
23480 | + mod->h_root = dget(path.dentry); | |
23481 | + path_put(&path); | |
23482 | + | |
4f0767ce | 23483 | +out: |
1facf9fc | 23484 | + return err; |
23485 | +} | |
23486 | + | |
23487 | +#if 0 /* reserved for future use */ | |
23488 | +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex, | |
23489 | + struct au_opt_mod *mod, substring_t args[]) | |
23490 | +{ | |
23491 | + int err; | |
23492 | + struct dentry *root; | |
23493 | + | |
23494 | + err = -EINVAL; | |
23495 | + root = sb->s_root; | |
23496 | + aufs_read_lock(root, AuLock_FLUSH); | |
23497 | + if (bindex < 0 || au_sbend(sb) < bindex) { | |
4a4d8108 | 23498 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 23499 | + goto out; |
23500 | + } | |
23501 | + | |
23502 | + err = 0; | |
23503 | + mod->perm = br_perm_val(args[1].from); | |
23504 | + AuDbg("mod path %s, perm 0x%x, %s\n", | |
23505 | + mod->path, mod->perm, args[1].from); | |
23506 | + mod->h_root = dget(au_h_dptr(root, bindex)); | |
23507 | + | |
4f0767ce | 23508 | +out: |
1facf9fc | 23509 | + aufs_read_unlock(root, !AuLock_IR); |
23510 | + return err; | |
23511 | +} | |
23512 | +#endif | |
23513 | + | |
23514 | +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino, | |
23515 | + substring_t args[]) | |
23516 | +{ | |
23517 | + int err; | |
23518 | + struct file *file; | |
23519 | + | |
23520 | + file = au_xino_create(sb, args[0].from, /*silent*/0); | |
23521 | + err = PTR_ERR(file); | |
23522 | + if (IS_ERR(file)) | |
23523 | + goto out; | |
23524 | + | |
23525 | + err = -EINVAL; | |
2000de60 | 23526 | + if (unlikely(file->f_path.dentry->d_sb == sb)) { |
1facf9fc | 23527 | + fput(file); |
4a4d8108 | 23528 | + pr_err("%s must be outside\n", args[0].from); |
1facf9fc | 23529 | + goto out; |
23530 | + } | |
23531 | + | |
23532 | + err = 0; | |
23533 | + xino->file = file; | |
23534 | + xino->path = args[0].from; | |
23535 | + | |
4f0767ce | 23536 | +out: |
1facf9fc | 23537 | + return err; |
23538 | +} | |
23539 | + | |
4a4d8108 AM |
23540 | +static int noinline_for_stack |
23541 | +au_opts_parse_xino_itrunc_path(struct super_block *sb, | |
23542 | + struct au_opt_xino_itrunc *xino_itrunc, | |
23543 | + substring_t args[]) | |
1facf9fc | 23544 | +{ |
23545 | + int err; | |
23546 | + aufs_bindex_t bend, bindex; | |
23547 | + struct path path; | |
23548 | + struct dentry *root; | |
23549 | + | |
23550 | + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path); | |
23551 | + if (unlikely(err)) { | |
4a4d8108 | 23552 | + pr_err("lookup failed %s (%d)\n", args[0].from, err); |
1facf9fc | 23553 | + goto out; |
23554 | + } | |
23555 | + | |
23556 | + xino_itrunc->bindex = -1; | |
23557 | + root = sb->s_root; | |
23558 | + aufs_read_lock(root, AuLock_FLUSH); | |
23559 | + bend = au_sbend(sb); | |
23560 | + for (bindex = 0; bindex <= bend; bindex++) { | |
23561 | + if (au_h_dptr(root, bindex) == path.dentry) { | |
23562 | + xino_itrunc->bindex = bindex; | |
23563 | + break; | |
23564 | + } | |
23565 | + } | |
23566 | + aufs_read_unlock(root, !AuLock_IR); | |
23567 | + path_put(&path); | |
23568 | + | |
23569 | + if (unlikely(xino_itrunc->bindex < 0)) { | |
4a4d8108 | 23570 | + pr_err("no such branch %s\n", args[0].from); |
1facf9fc | 23571 | + err = -EINVAL; |
23572 | + } | |
23573 | + | |
4f0767ce | 23574 | +out: |
1facf9fc | 23575 | + return err; |
23576 | +} | |
23577 | + | |
23578 | +/* called without aufs lock */ | |
23579 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts) | |
23580 | +{ | |
23581 | + int err, n, token; | |
23582 | + aufs_bindex_t bindex; | |
23583 | + unsigned char skipped; | |
23584 | + struct dentry *root; | |
23585 | + struct au_opt *opt, *opt_tail; | |
23586 | + char *opt_str; | |
23587 | + /* reduce the stack space */ | |
23588 | + union { | |
23589 | + struct au_opt_xino_itrunc *xino_itrunc; | |
23590 | + struct au_opt_wbr_create *create; | |
23591 | + } u; | |
23592 | + struct { | |
23593 | + substring_t args[MAX_OPT_ARGS]; | |
23594 | + } *a; | |
23595 | + | |
23596 | + err = -ENOMEM; | |
23597 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
23598 | + if (unlikely(!a)) | |
23599 | + goto out; | |
23600 | + | |
23601 | + root = sb->s_root; | |
23602 | + err = 0; | |
23603 | + bindex = 0; | |
23604 | + opt = opts->opt; | |
23605 | + opt_tail = opt + opts->max_opt - 1; | |
23606 | + opt->type = Opt_tail; | |
23607 | + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) { | |
23608 | + err = -EINVAL; | |
23609 | + skipped = 0; | |
23610 | + token = match_token(opt_str, options, a->args); | |
23611 | + switch (token) { | |
23612 | + case Opt_br: | |
23613 | + err = 0; | |
23614 | + while (!err && (opt_str = strsep(&a->args[0].from, ":")) | |
23615 | + && *opt_str) { | |
23616 | + err = opt_add(opt, opt_str, opts->sb_flags, | |
23617 | + bindex++); | |
23618 | + if (unlikely(!err && ++opt > opt_tail)) { | |
23619 | + err = -E2BIG; | |
23620 | + break; | |
23621 | + } | |
23622 | + opt->type = Opt_tail; | |
23623 | + skipped = 1; | |
23624 | + } | |
23625 | + break; | |
23626 | + case Opt_add: | |
23627 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23628 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23629 | + break; |
23630 | + } | |
23631 | + bindex = n; | |
23632 | + err = opt_add(opt, a->args[1].from, opts->sb_flags, | |
23633 | + bindex); | |
23634 | + if (!err) | |
23635 | + opt->type = token; | |
23636 | + break; | |
23637 | + case Opt_append: | |
23638 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
23639 | + /*dummy bindex*/1); | |
23640 | + if (!err) | |
23641 | + opt->type = token; | |
23642 | + break; | |
23643 | + case Opt_prepend: | |
23644 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
23645 | + /*bindex*/0); | |
23646 | + if (!err) | |
23647 | + opt->type = token; | |
23648 | + break; | |
23649 | + case Opt_del: | |
23650 | + err = au_opts_parse_del(&opt->del, a->args); | |
23651 | + if (!err) | |
23652 | + opt->type = token; | |
23653 | + break; | |
23654 | +#if 0 /* reserved for future use */ | |
23655 | + case Opt_idel: | |
23656 | + del->pathname = "(indexed)"; | |
23657 | + if (unlikely(match_int(&args[0], &n))) { | |
4a4d8108 | 23658 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23659 | + break; |
23660 | + } | |
23661 | + err = au_opts_parse_idel(sb, n, &opt->del, a->args); | |
23662 | + if (!err) | |
23663 | + opt->type = token; | |
23664 | + break; | |
23665 | +#endif | |
23666 | + case Opt_mod: | |
23667 | + err = au_opts_parse_mod(&opt->mod, a->args); | |
23668 | + if (!err) | |
23669 | + opt->type = token; | |
23670 | + break; | |
23671 | +#ifdef IMOD /* reserved for future use */ | |
23672 | + case Opt_imod: | |
23673 | + u.mod->path = "(indexed)"; | |
23674 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23675 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23676 | + break; |
23677 | + } | |
23678 | + err = au_opts_parse_imod(sb, n, &opt->mod, a->args); | |
23679 | + if (!err) | |
23680 | + opt->type = token; | |
23681 | + break; | |
23682 | +#endif | |
23683 | + case Opt_xino: | |
23684 | + err = au_opts_parse_xino(sb, &opt->xino, a->args); | |
23685 | + if (!err) | |
23686 | + opt->type = token; | |
23687 | + break; | |
23688 | + | |
23689 | + case Opt_trunc_xino_path: | |
23690 | + err = au_opts_parse_xino_itrunc_path | |
23691 | + (sb, &opt->xino_itrunc, a->args); | |
23692 | + if (!err) | |
23693 | + opt->type = token; | |
23694 | + break; | |
23695 | + | |
23696 | + case Opt_itrunc_xino: | |
23697 | + u.xino_itrunc = &opt->xino_itrunc; | |
23698 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23699 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23700 | + break; |
23701 | + } | |
23702 | + u.xino_itrunc->bindex = n; | |
23703 | + aufs_read_lock(root, AuLock_FLUSH); | |
23704 | + if (n < 0 || au_sbend(sb) < n) { | |
4a4d8108 | 23705 | + pr_err("out of bounds, %d\n", n); |
1facf9fc | 23706 | + aufs_read_unlock(root, !AuLock_IR); |
23707 | + break; | |
23708 | + } | |
23709 | + aufs_read_unlock(root, !AuLock_IR); | |
23710 | + err = 0; | |
23711 | + opt->type = token; | |
23712 | + break; | |
23713 | + | |
23714 | + case Opt_dirwh: | |
23715 | + if (unlikely(match_int(&a->args[0], &opt->dirwh))) | |
23716 | + break; | |
23717 | + err = 0; | |
23718 | + opt->type = token; | |
23719 | + break; | |
23720 | + | |
23721 | + case Opt_rdcache: | |
027c5e7a AM |
23722 | + if (unlikely(match_int(&a->args[0], &n))) { |
23723 | + pr_err("bad integer in %s\n", opt_str); | |
1facf9fc | 23724 | + break; |
027c5e7a AM |
23725 | + } |
23726 | + if (unlikely(n > AUFS_RDCACHE_MAX)) { | |
23727 | + pr_err("rdcache must be smaller than %d\n", | |
23728 | + AUFS_RDCACHE_MAX); | |
23729 | + break; | |
23730 | + } | |
23731 | + opt->rdcache = n; | |
1facf9fc | 23732 | + err = 0; |
23733 | + opt->type = token; | |
23734 | + break; | |
23735 | + case Opt_rdblk: | |
23736 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 23737 | + || n < 0 |
1facf9fc | 23738 | + || n > KMALLOC_MAX_SIZE)) { |
4a4d8108 | 23739 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23740 | + break; |
23741 | + } | |
1308ab2a | 23742 | + if (unlikely(n && n < NAME_MAX)) { |
4a4d8108 AM |
23743 | + pr_err("rdblk must be larger than %d\n", |
23744 | + NAME_MAX); | |
1facf9fc | 23745 | + break; |
23746 | + } | |
23747 | + opt->rdblk = n; | |
23748 | + err = 0; | |
23749 | + opt->type = token; | |
23750 | + break; | |
23751 | + case Opt_rdhash: | |
23752 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 23753 | + || n < 0 |
1facf9fc | 23754 | + || n * sizeof(struct hlist_head) |
23755 | + > KMALLOC_MAX_SIZE)) { | |
4a4d8108 | 23756 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23757 | + break; |
23758 | + } | |
23759 | + opt->rdhash = n; | |
23760 | + err = 0; | |
23761 | + opt->type = token; | |
23762 | + break; | |
23763 | + | |
23764 | + case Opt_trunc_xino: | |
23765 | + case Opt_notrunc_xino: | |
23766 | + case Opt_noxino: | |
23767 | + case Opt_trunc_xib: | |
23768 | + case Opt_notrunc_xib: | |
dece6358 AM |
23769 | + case Opt_shwh: |
23770 | + case Opt_noshwh: | |
076b876e AM |
23771 | + case Opt_dirperm1: |
23772 | + case Opt_nodirperm1: | |
1facf9fc | 23773 | + case Opt_plink: |
23774 | + case Opt_noplink: | |
23775 | + case Opt_list_plink: | |
4a4d8108 AM |
23776 | + case Opt_dio: |
23777 | + case Opt_nodio: | |
1facf9fc | 23778 | + case Opt_diropq_a: |
23779 | + case Opt_diropq_w: | |
23780 | + case Opt_warn_perm: | |
23781 | + case Opt_nowarn_perm: | |
1facf9fc | 23782 | + case Opt_verbose: |
23783 | + case Opt_noverbose: | |
23784 | + case Opt_sum: | |
23785 | + case Opt_nosum: | |
23786 | + case Opt_wsum: | |
dece6358 AM |
23787 | + case Opt_rdblk_def: |
23788 | + case Opt_rdhash_def: | |
c1595e42 JR |
23789 | + case Opt_acl: |
23790 | + case Opt_noacl: | |
1facf9fc | 23791 | + err = 0; |
23792 | + opt->type = token; | |
23793 | + break; | |
23794 | + | |
23795 | + case Opt_udba: | |
23796 | + opt->udba = udba_val(a->args[0].from); | |
23797 | + if (opt->udba >= 0) { | |
23798 | + err = 0; | |
23799 | + opt->type = token; | |
23800 | + } else | |
4a4d8108 | 23801 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23802 | + break; |
23803 | + | |
23804 | + case Opt_wbr_create: | |
23805 | + u.create = &opt->wbr_create; | |
23806 | + u.create->wbr_create | |
23807 | + = au_wbr_create_val(a->args[0].from, u.create); | |
23808 | + if (u.create->wbr_create >= 0) { | |
23809 | + err = 0; | |
23810 | + opt->type = token; | |
23811 | + } else | |
4a4d8108 | 23812 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23813 | + break; |
23814 | + case Opt_wbr_copyup: | |
23815 | + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from); | |
23816 | + if (opt->wbr_copyup >= 0) { | |
23817 | + err = 0; | |
23818 | + opt->type = token; | |
23819 | + } else | |
4a4d8108 | 23820 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23821 | + break; |
23822 | + | |
076b876e AM |
23823 | + case Opt_fhsm_sec: |
23824 | + if (unlikely(match_int(&a->args[0], &n) | |
23825 | + || n < 0)) { | |
23826 | + pr_err("bad integer in %s\n", opt_str); | |
23827 | + break; | |
23828 | + } | |
23829 | + if (sysaufs_brs) { | |
23830 | + opt->fhsm_second = n; | |
23831 | + opt->type = token; | |
23832 | + } else | |
23833 | + pr_warn("ignored %s\n", opt_str); | |
23834 | + err = 0; | |
23835 | + break; | |
23836 | + | |
1facf9fc | 23837 | + case Opt_ignore: |
0c3ec466 | 23838 | + pr_warn("ignored %s\n", opt_str); |
1facf9fc | 23839 | + /*FALLTHROUGH*/ |
23840 | + case Opt_ignore_silent: | |
23841 | + skipped = 1; | |
23842 | + err = 0; | |
23843 | + break; | |
23844 | + case Opt_err: | |
4a4d8108 | 23845 | + pr_err("unknown option %s\n", opt_str); |
1facf9fc | 23846 | + break; |
23847 | + } | |
23848 | + | |
23849 | + if (!err && !skipped) { | |
23850 | + if (unlikely(++opt > opt_tail)) { | |
23851 | + err = -E2BIG; | |
23852 | + opt--; | |
23853 | + opt->type = Opt_tail; | |
23854 | + break; | |
23855 | + } | |
23856 | + opt->type = Opt_tail; | |
23857 | + } | |
23858 | + } | |
23859 | + | |
23860 | + kfree(a); | |
23861 | + dump_opts(opts); | |
23862 | + if (unlikely(err)) | |
23863 | + au_opts_free(opts); | |
23864 | + | |
4f0767ce | 23865 | +out: |
1facf9fc | 23866 | + return err; |
23867 | +} | |
23868 | + | |
23869 | +static int au_opt_wbr_create(struct super_block *sb, | |
23870 | + struct au_opt_wbr_create *create) | |
23871 | +{ | |
23872 | + int err; | |
23873 | + struct au_sbinfo *sbinfo; | |
23874 | + | |
dece6358 AM |
23875 | + SiMustWriteLock(sb); |
23876 | + | |
1facf9fc | 23877 | + err = 1; /* handled */ |
23878 | + sbinfo = au_sbi(sb); | |
23879 | + if (sbinfo->si_wbr_create_ops->fin) { | |
23880 | + err = sbinfo->si_wbr_create_ops->fin(sb); | |
23881 | + if (!err) | |
23882 | + err = 1; | |
23883 | + } | |
23884 | + | |
23885 | + sbinfo->si_wbr_create = create->wbr_create; | |
23886 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create; | |
23887 | + switch (create->wbr_create) { | |
23888 | + case AuWbrCreate_MFSRRV: | |
23889 | + case AuWbrCreate_MFSRR: | |
392086de AM |
23890 | + case AuWbrCreate_PMFSRR: |
23891 | + case AuWbrCreate_PMFSRRV: | |
1facf9fc | 23892 | + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark; |
23893 | + /*FALLTHROUGH*/ | |
23894 | + case AuWbrCreate_MFS: | |
23895 | + case AuWbrCreate_MFSV: | |
23896 | + case AuWbrCreate_PMFS: | |
23897 | + case AuWbrCreate_PMFSV: | |
e49829fe JR |
23898 | + sbinfo->si_wbr_mfs.mfs_expire |
23899 | + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC); | |
1facf9fc | 23900 | + break; |
23901 | + } | |
23902 | + | |
23903 | + if (sbinfo->si_wbr_create_ops->init) | |
23904 | + sbinfo->si_wbr_create_ops->init(sb); /* ignore */ | |
23905 | + | |
23906 | + return err; | |
23907 | +} | |
23908 | + | |
23909 | +/* | |
23910 | + * returns, | |
23911 | + * plus: processed without an error | |
23912 | + * zero: unprocessed | |
23913 | + */ | |
23914 | +static int au_opt_simple(struct super_block *sb, struct au_opt *opt, | |
23915 | + struct au_opts *opts) | |
23916 | +{ | |
23917 | + int err; | |
23918 | + struct au_sbinfo *sbinfo; | |
23919 | + | |
dece6358 AM |
23920 | + SiMustWriteLock(sb); |
23921 | + | |
1facf9fc | 23922 | + err = 1; /* handled */ |
23923 | + sbinfo = au_sbi(sb); | |
23924 | + switch (opt->type) { | |
23925 | + case Opt_udba: | |
23926 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; | |
23927 | + sbinfo->si_mntflags |= opt->udba; | |
23928 | + opts->given_udba |= opt->udba; | |
23929 | + break; | |
23930 | + | |
23931 | + case Opt_plink: | |
23932 | + au_opt_set(sbinfo->si_mntflags, PLINK); | |
23933 | + break; | |
23934 | + case Opt_noplink: | |
23935 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
e49829fe | 23936 | + au_plink_put(sb, /*verbose*/1); |
1facf9fc | 23937 | + au_opt_clr(sbinfo->si_mntflags, PLINK); |
23938 | + break; | |
23939 | + case Opt_list_plink: | |
23940 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
23941 | + au_plink_list(sb); | |
23942 | + break; | |
23943 | + | |
4a4d8108 AM |
23944 | + case Opt_dio: |
23945 | + au_opt_set(sbinfo->si_mntflags, DIO); | |
23946 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
23947 | + break; | |
23948 | + case Opt_nodio: | |
23949 | + au_opt_clr(sbinfo->si_mntflags, DIO); | |
23950 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
23951 | + break; | |
23952 | + | |
076b876e AM |
23953 | + case Opt_fhsm_sec: |
23954 | + au_fhsm_set(sbinfo, opt->fhsm_second); | |
23955 | + break; | |
23956 | + | |
1facf9fc | 23957 | + case Opt_diropq_a: |
23958 | + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
23959 | + break; | |
23960 | + case Opt_diropq_w: | |
23961 | + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
23962 | + break; | |
23963 | + | |
23964 | + case Opt_warn_perm: | |
23965 | + au_opt_set(sbinfo->si_mntflags, WARN_PERM); | |
23966 | + break; | |
23967 | + case Opt_nowarn_perm: | |
23968 | + au_opt_clr(sbinfo->si_mntflags, WARN_PERM); | |
23969 | + break; | |
23970 | + | |
1facf9fc | 23971 | + case Opt_verbose: |
23972 | + au_opt_set(sbinfo->si_mntflags, VERBOSE); | |
23973 | + break; | |
23974 | + case Opt_noverbose: | |
23975 | + au_opt_clr(sbinfo->si_mntflags, VERBOSE); | |
23976 | + break; | |
23977 | + | |
23978 | + case Opt_sum: | |
23979 | + au_opt_set(sbinfo->si_mntflags, SUM); | |
23980 | + break; | |
23981 | + case Opt_wsum: | |
23982 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
23983 | + au_opt_set(sbinfo->si_mntflags, SUM_W); | |
23984 | + case Opt_nosum: | |
23985 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
23986 | + au_opt_clr(sbinfo->si_mntflags, SUM_W); | |
23987 | + break; | |
23988 | + | |
23989 | + case Opt_wbr_create: | |
23990 | + err = au_opt_wbr_create(sb, &opt->wbr_create); | |
23991 | + break; | |
23992 | + case Opt_wbr_copyup: | |
23993 | + sbinfo->si_wbr_copyup = opt->wbr_copyup; | |
23994 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup; | |
23995 | + break; | |
23996 | + | |
23997 | + case Opt_dirwh: | |
23998 | + sbinfo->si_dirwh = opt->dirwh; | |
23999 | + break; | |
24000 | + | |
24001 | + case Opt_rdcache: | |
e49829fe JR |
24002 | + sbinfo->si_rdcache |
24003 | + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC); | |
1facf9fc | 24004 | + break; |
24005 | + case Opt_rdblk: | |
24006 | + sbinfo->si_rdblk = opt->rdblk; | |
24007 | + break; | |
dece6358 AM |
24008 | + case Opt_rdblk_def: |
24009 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; | |
24010 | + break; | |
1facf9fc | 24011 | + case Opt_rdhash: |
24012 | + sbinfo->si_rdhash = opt->rdhash; | |
24013 | + break; | |
dece6358 AM |
24014 | + case Opt_rdhash_def: |
24015 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
24016 | + break; | |
24017 | + | |
24018 | + case Opt_shwh: | |
24019 | + au_opt_set(sbinfo->si_mntflags, SHWH); | |
24020 | + break; | |
24021 | + case Opt_noshwh: | |
24022 | + au_opt_clr(sbinfo->si_mntflags, SHWH); | |
24023 | + break; | |
1facf9fc | 24024 | + |
076b876e AM |
24025 | + case Opt_dirperm1: |
24026 | + au_opt_set(sbinfo->si_mntflags, DIRPERM1); | |
24027 | + break; | |
24028 | + case Opt_nodirperm1: | |
24029 | + au_opt_clr(sbinfo->si_mntflags, DIRPERM1); | |
24030 | + break; | |
24031 | + | |
1facf9fc | 24032 | + case Opt_trunc_xino: |
24033 | + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO); | |
24034 | + break; | |
24035 | + case Opt_notrunc_xino: | |
24036 | + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO); | |
24037 | + break; | |
24038 | + | |
24039 | + case Opt_trunc_xino_path: | |
24040 | + case Opt_itrunc_xino: | |
24041 | + err = au_xino_trunc(sb, opt->xino_itrunc.bindex); | |
24042 | + if (!err) | |
24043 | + err = 1; | |
24044 | + break; | |
24045 | + | |
24046 | + case Opt_trunc_xib: | |
24047 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
24048 | + break; | |
24049 | + case Opt_notrunc_xib: | |
24050 | + au_fclr_opts(opts->flags, TRUNC_XIB); | |
24051 | + break; | |
24052 | + | |
c1595e42 JR |
24053 | + case Opt_acl: |
24054 | + sb->s_flags |= MS_POSIXACL; | |
24055 | + break; | |
24056 | + case Opt_noacl: | |
24057 | + sb->s_flags &= ~MS_POSIXACL; | |
24058 | + break; | |
24059 | + | |
1facf9fc | 24060 | + default: |
24061 | + err = 0; | |
24062 | + break; | |
24063 | + } | |
24064 | + | |
24065 | + return err; | |
24066 | +} | |
24067 | + | |
24068 | +/* | |
24069 | + * returns tri-state. | |
24070 | + * plus: processed without an error | |
24071 | + * zero: unprocessed | |
24072 | + * minus: error | |
24073 | + */ | |
24074 | +static int au_opt_br(struct super_block *sb, struct au_opt *opt, | |
24075 | + struct au_opts *opts) | |
24076 | +{ | |
24077 | + int err, do_refresh; | |
24078 | + | |
24079 | + err = 0; | |
24080 | + switch (opt->type) { | |
24081 | + case Opt_append: | |
24082 | + opt->add.bindex = au_sbend(sb) + 1; | |
24083 | + if (opt->add.bindex < 0) | |
24084 | + opt->add.bindex = 0; | |
24085 | + goto add; | |
24086 | + case Opt_prepend: | |
24087 | + opt->add.bindex = 0; | |
f6b6e03d | 24088 | + add: /* indented label */ |
1facf9fc | 24089 | + case Opt_add: |
24090 | + err = au_br_add(sb, &opt->add, | |
24091 | + au_ftest_opts(opts->flags, REMOUNT)); | |
24092 | + if (!err) { | |
24093 | + err = 1; | |
027c5e7a | 24094 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24095 | + } |
24096 | + break; | |
24097 | + | |
24098 | + case Opt_del: | |
24099 | + case Opt_idel: | |
24100 | + err = au_br_del(sb, &opt->del, | |
24101 | + au_ftest_opts(opts->flags, REMOUNT)); | |
24102 | + if (!err) { | |
24103 | + err = 1; | |
24104 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
027c5e7a | 24105 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24106 | + } |
24107 | + break; | |
24108 | + | |
24109 | + case Opt_mod: | |
24110 | + case Opt_imod: | |
24111 | + err = au_br_mod(sb, &opt->mod, | |
24112 | + au_ftest_opts(opts->flags, REMOUNT), | |
24113 | + &do_refresh); | |
24114 | + if (!err) { | |
24115 | + err = 1; | |
027c5e7a AM |
24116 | + if (do_refresh) |
24117 | + au_fset_opts(opts->flags, REFRESH); | |
1facf9fc | 24118 | + } |
24119 | + break; | |
24120 | + } | |
24121 | + | |
24122 | + return err; | |
24123 | +} | |
24124 | + | |
24125 | +static int au_opt_xino(struct super_block *sb, struct au_opt *opt, | |
24126 | + struct au_opt_xino **opt_xino, | |
24127 | + struct au_opts *opts) | |
24128 | +{ | |
24129 | + int err; | |
24130 | + aufs_bindex_t bend, bindex; | |
24131 | + struct dentry *root, *parent, *h_root; | |
24132 | + | |
24133 | + err = 0; | |
24134 | + switch (opt->type) { | |
24135 | + case Opt_xino: | |
24136 | + err = au_xino_set(sb, &opt->xino, | |
24137 | + !!au_ftest_opts(opts->flags, REMOUNT)); | |
24138 | + if (unlikely(err)) | |
24139 | + break; | |
24140 | + | |
24141 | + *opt_xino = &opt->xino; | |
24142 | + au_xino_brid_set(sb, -1); | |
24143 | + | |
24144 | + /* safe d_parent access */ | |
2000de60 | 24145 | + parent = opt->xino.file->f_path.dentry->d_parent; |
1facf9fc | 24146 | + root = sb->s_root; |
24147 | + bend = au_sbend(sb); | |
24148 | + for (bindex = 0; bindex <= bend; bindex++) { | |
24149 | + h_root = au_h_dptr(root, bindex); | |
24150 | + if (h_root == parent) { | |
24151 | + au_xino_brid_set(sb, au_sbr_id(sb, bindex)); | |
24152 | + break; | |
24153 | + } | |
24154 | + } | |
24155 | + break; | |
24156 | + | |
24157 | + case Opt_noxino: | |
24158 | + au_xino_clr(sb); | |
24159 | + au_xino_brid_set(sb, -1); | |
24160 | + *opt_xino = (void *)-1; | |
24161 | + break; | |
24162 | + } | |
24163 | + | |
24164 | + return err; | |
24165 | +} | |
24166 | + | |
24167 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
24168 | + unsigned int pending) | |
24169 | +{ | |
076b876e | 24170 | + int err, fhsm; |
1facf9fc | 24171 | + aufs_bindex_t bindex, bend; |
24172 | + unsigned char do_plink, skip, do_free; | |
24173 | + struct au_branch *br; | |
24174 | + struct au_wbr *wbr; | |
24175 | + struct dentry *root; | |
24176 | + struct inode *dir, *h_dir; | |
24177 | + struct au_sbinfo *sbinfo; | |
24178 | + struct au_hinode *hdir; | |
24179 | + | |
dece6358 AM |
24180 | + SiMustAnyLock(sb); |
24181 | + | |
1facf9fc | 24182 | + sbinfo = au_sbi(sb); |
24183 | + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA)); | |
24184 | + | |
dece6358 AM |
24185 | + if (!(sb_flags & MS_RDONLY)) { |
24186 | + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0)))) | |
0c3ec466 | 24187 | + pr_warn("first branch should be rw\n"); |
dece6358 | 24188 | + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH))) |
0c3ec466 | 24189 | + pr_warn("shwh should be used with ro\n"); |
dece6358 | 24190 | + } |
1facf9fc | 24191 | + |
4a4d8108 | 24192 | + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY) |
1facf9fc | 24193 | + && !au_opt_test(sbinfo->si_mntflags, XINO)) |
0c3ec466 | 24194 | + pr_warn("udba=*notify requires xino\n"); |
1facf9fc | 24195 | + |
076b876e AM |
24196 | + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1)) |
24197 | + pr_warn("dirperm1 breaks the protection" | |
24198 | + " by the permission bits on the lower branch\n"); | |
24199 | + | |
1facf9fc | 24200 | + err = 0; |
076b876e | 24201 | + fhsm = 0; |
1facf9fc | 24202 | + root = sb->s_root; |
5527c038 | 24203 | + dir = d_inode(root); |
1facf9fc | 24204 | + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK); |
24205 | + bend = au_sbend(sb); | |
24206 | + for (bindex = 0; !err && bindex <= bend; bindex++) { | |
24207 | + skip = 0; | |
24208 | + h_dir = au_h_iptr(dir, bindex); | |
24209 | + br = au_sbr(sb, bindex); | |
1facf9fc | 24210 | + |
c1595e42 JR |
24211 | + if ((br->br_perm & AuBrAttr_ICEX) |
24212 | + && !h_dir->i_op->listxattr) | |
24213 | + br->br_perm &= ~AuBrAttr_ICEX; | |
24214 | +#if 0 | |
24215 | + if ((br->br_perm & AuBrAttr_ICEX_SEC) | |
24216 | + && (au_br_sb(br)->s_flags & MS_NOSEC)) | |
24217 | + br->br_perm &= ~AuBrAttr_ICEX_SEC; | |
24218 | +#endif | |
24219 | + | |
24220 | + do_free = 0; | |
1facf9fc | 24221 | + wbr = br->br_wbr; |
24222 | + if (wbr) | |
24223 | + wbr_wh_read_lock(wbr); | |
24224 | + | |
1e00d052 | 24225 | + if (!au_br_writable(br->br_perm)) { |
1facf9fc | 24226 | + do_free = !!wbr; |
24227 | + skip = (!wbr | |
24228 | + || (!wbr->wbr_whbase | |
24229 | + && !wbr->wbr_plink | |
24230 | + && !wbr->wbr_orph)); | |
1e00d052 | 24231 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 24232 | + /* skip = (!br->br_whbase && !br->br_orph); */ |
24233 | + skip = (!wbr || !wbr->wbr_whbase); | |
24234 | + if (skip && wbr) { | |
24235 | + if (do_plink) | |
24236 | + skip = !!wbr->wbr_plink; | |
24237 | + else | |
24238 | + skip = !wbr->wbr_plink; | |
24239 | + } | |
1e00d052 | 24240 | + } else { |
1facf9fc | 24241 | + /* skip = (br->br_whbase && br->br_ohph); */ |
24242 | + skip = (wbr && wbr->wbr_whbase); | |
24243 | + if (skip) { | |
24244 | + if (do_plink) | |
24245 | + skip = !!wbr->wbr_plink; | |
24246 | + else | |
24247 | + skip = !wbr->wbr_plink; | |
24248 | + } | |
1facf9fc | 24249 | + } |
24250 | + if (wbr) | |
24251 | + wbr_wh_read_unlock(wbr); | |
24252 | + | |
076b876e AM |
24253 | + if (au_br_fhsm(br->br_perm)) { |
24254 | + fhsm++; | |
24255 | + AuDebugOn(!br->br_fhsm); | |
24256 | + } | |
24257 | + | |
1facf9fc | 24258 | + if (skip) |
24259 | + continue; | |
24260 | + | |
24261 | + hdir = au_hi(dir, bindex); | |
4a4d8108 | 24262 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 24263 | + if (wbr) |
24264 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 24265 | + err = au_wh_init(br, sb); |
1facf9fc | 24266 | + if (wbr) |
24267 | + wbr_wh_write_unlock(wbr); | |
4a4d8108 | 24268 | + au_hn_imtx_unlock(hdir); |
1facf9fc | 24269 | + |
24270 | + if (!err && do_free) { | |
24271 | + kfree(wbr); | |
24272 | + br->br_wbr = NULL; | |
24273 | + } | |
24274 | + } | |
24275 | + | |
c1595e42 | 24276 | + if (fhsm >= 2) { |
076b876e | 24277 | + au_fset_si(sbinfo, FHSM); |
c1595e42 JR |
24278 | + for (bindex = bend; bindex >= 0; bindex--) { |
24279 | + br = au_sbr(sb, bindex); | |
24280 | + if (au_br_fhsm(br->br_perm)) { | |
24281 | + au_fhsm_set_bottom(sb, bindex); | |
24282 | + break; | |
24283 | + } | |
24284 | + } | |
24285 | + } else { | |
076b876e | 24286 | + au_fclr_si(sbinfo, FHSM); |
c1595e42 JR |
24287 | + au_fhsm_set_bottom(sb, -1); |
24288 | + } | |
076b876e | 24289 | + |
1facf9fc | 24290 | + return err; |
24291 | +} | |
24292 | + | |
24293 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts) | |
24294 | +{ | |
24295 | + int err; | |
24296 | + unsigned int tmp; | |
027c5e7a | 24297 | + aufs_bindex_t bindex, bend; |
1facf9fc | 24298 | + struct au_opt *opt; |
24299 | + struct au_opt_xino *opt_xino, xino; | |
24300 | + struct au_sbinfo *sbinfo; | |
027c5e7a | 24301 | + struct au_branch *br; |
076b876e | 24302 | + struct inode *dir; |
1facf9fc | 24303 | + |
dece6358 AM |
24304 | + SiMustWriteLock(sb); |
24305 | + | |
1facf9fc | 24306 | + err = 0; |
24307 | + opt_xino = NULL; | |
24308 | + opt = opts->opt; | |
24309 | + while (err >= 0 && opt->type != Opt_tail) | |
24310 | + err = au_opt_simple(sb, opt++, opts); | |
24311 | + if (err > 0) | |
24312 | + err = 0; | |
24313 | + else if (unlikely(err < 0)) | |
24314 | + goto out; | |
24315 | + | |
24316 | + /* disable xino and udba temporary */ | |
24317 | + sbinfo = au_sbi(sb); | |
24318 | + tmp = sbinfo->si_mntflags; | |
24319 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
24320 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL); | |
24321 | + | |
24322 | + opt = opts->opt; | |
24323 | + while (err >= 0 && opt->type != Opt_tail) | |
24324 | + err = au_opt_br(sb, opt++, opts); | |
24325 | + if (err > 0) | |
24326 | + err = 0; | |
24327 | + else if (unlikely(err < 0)) | |
24328 | + goto out; | |
24329 | + | |
24330 | + bend = au_sbend(sb); | |
24331 | + if (unlikely(bend < 0)) { | |
24332 | + err = -EINVAL; | |
4a4d8108 | 24333 | + pr_err("no branches\n"); |
1facf9fc | 24334 | + goto out; |
24335 | + } | |
24336 | + | |
24337 | + if (au_opt_test(tmp, XINO)) | |
24338 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
24339 | + opt = opts->opt; | |
24340 | + while (!err && opt->type != Opt_tail) | |
24341 | + err = au_opt_xino(sb, opt++, &opt_xino, opts); | |
24342 | + if (unlikely(err)) | |
24343 | + goto out; | |
24344 | + | |
24345 | + err = au_opts_verify(sb, sb->s_flags, tmp); | |
24346 | + if (unlikely(err)) | |
24347 | + goto out; | |
24348 | + | |
24349 | + /* restore xino */ | |
24350 | + if (au_opt_test(tmp, XINO) && !opt_xino) { | |
24351 | + xino.file = au_xino_def(sb); | |
24352 | + err = PTR_ERR(xino.file); | |
24353 | + if (IS_ERR(xino.file)) | |
24354 | + goto out; | |
24355 | + | |
24356 | + err = au_xino_set(sb, &xino, /*remount*/0); | |
24357 | + fput(xino.file); | |
24358 | + if (unlikely(err)) | |
24359 | + goto out; | |
24360 | + } | |
24361 | + | |
24362 | + /* restore udba */ | |
027c5e7a | 24363 | + tmp &= AuOptMask_UDBA; |
1facf9fc | 24364 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; |
027c5e7a AM |
24365 | + sbinfo->si_mntflags |= tmp; |
24366 | + bend = au_sbend(sb); | |
24367 | + for (bindex = 0; bindex <= bend; bindex++) { | |
24368 | + br = au_sbr(sb, bindex); | |
24369 | + err = au_hnotify_reset_br(tmp, br, br->br_perm); | |
24370 | + if (unlikely(err)) | |
24371 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", | |
24372 | + bindex, err); | |
24373 | + /* go on even if err */ | |
24374 | + } | |
4a4d8108 | 24375 | + if (au_opt_test(tmp, UDBA_HNOTIFY)) { |
5527c038 | 24376 | + dir = d_inode(sb->s_root); |
4a4d8108 | 24377 | + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO); |
1facf9fc | 24378 | + } |
24379 | + | |
4f0767ce | 24380 | +out: |
1facf9fc | 24381 | + return err; |
24382 | +} | |
24383 | + | |
24384 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts) | |
24385 | +{ | |
24386 | + int err, rerr; | |
24387 | + struct inode *dir; | |
24388 | + struct au_opt_xino *opt_xino; | |
24389 | + struct au_opt *opt; | |
24390 | + struct au_sbinfo *sbinfo; | |
24391 | + | |
dece6358 AM |
24392 | + SiMustWriteLock(sb); |
24393 | + | |
5527c038 | 24394 | + dir = d_inode(sb->s_root); |
1facf9fc | 24395 | + sbinfo = au_sbi(sb); |
24396 | + err = 0; | |
24397 | + opt_xino = NULL; | |
24398 | + opt = opts->opt; | |
24399 | + while (err >= 0 && opt->type != Opt_tail) { | |
24400 | + err = au_opt_simple(sb, opt, opts); | |
24401 | + if (!err) | |
24402 | + err = au_opt_br(sb, opt, opts); | |
24403 | + if (!err) | |
24404 | + err = au_opt_xino(sb, opt, &opt_xino, opts); | |
24405 | + opt++; | |
24406 | + } | |
24407 | + if (err > 0) | |
24408 | + err = 0; | |
24409 | + AuTraceErr(err); | |
24410 | + /* go on even err */ | |
24411 | + | |
24412 | + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0); | |
24413 | + if (unlikely(rerr && !err)) | |
24414 | + err = rerr; | |
24415 | + | |
24416 | + if (au_ftest_opts(opts->flags, TRUNC_XIB)) { | |
24417 | + rerr = au_xib_trunc(sb); | |
24418 | + if (unlikely(rerr && !err)) | |
24419 | + err = rerr; | |
24420 | + } | |
24421 | + | |
24422 | + /* will be handled by the caller */ | |
027c5e7a | 24423 | + if (!au_ftest_opts(opts->flags, REFRESH) |
1facf9fc | 24424 | + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO))) |
027c5e7a | 24425 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24426 | + |
24427 | + AuDbg("status 0x%x\n", opts->flags); | |
24428 | + return err; | |
24429 | +} | |
24430 | + | |
24431 | +/* ---------------------------------------------------------------------- */ | |
24432 | + | |
24433 | +unsigned int au_opt_udba(struct super_block *sb) | |
24434 | +{ | |
24435 | + return au_mntflags(sb) & AuOptMask_UDBA; | |
24436 | +} | |
7f207e10 AM |
24437 | diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h |
24438 | --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 24439 | +++ linux/fs/aufs/opts.h 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 24440 | @@ -0,0 +1,210 @@ |
1facf9fc | 24441 | +/* |
2000de60 | 24442 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 24443 | + * |
24444 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24445 | + * it under the terms of the GNU General Public License as published by | |
24446 | + * the Free Software Foundation; either version 2 of the License, or | |
24447 | + * (at your option) any later version. | |
dece6358 AM |
24448 | + * |
24449 | + * This program is distributed in the hope that it will be useful, | |
24450 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24451 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24452 | + * GNU General Public License for more details. | |
24453 | + * | |
24454 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24455 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24456 | + */ |
24457 | + | |
24458 | +/* | |
24459 | + * mount options/flags | |
24460 | + */ | |
24461 | + | |
24462 | +#ifndef __AUFS_OPTS_H__ | |
24463 | +#define __AUFS_OPTS_H__ | |
24464 | + | |
24465 | +#ifdef __KERNEL__ | |
24466 | + | |
dece6358 | 24467 | +#include <linux/path.h> |
1facf9fc | 24468 | + |
dece6358 AM |
24469 | +struct file; |
24470 | +struct super_block; | |
24471 | + | |
1facf9fc | 24472 | +/* ---------------------------------------------------------------------- */ |
24473 | + | |
24474 | +/* mount flags */ | |
24475 | +#define AuOpt_XINO 1 /* external inode number bitmap | |
24476 | + and translation table */ | |
24477 | +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */ | |
24478 | +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */ | |
24479 | +#define AuOpt_UDBA_REVAL (1 << 3) | |
4a4d8108 | 24480 | +#define AuOpt_UDBA_HNOTIFY (1 << 4) |
dece6358 AM |
24481 | +#define AuOpt_SHWH (1 << 5) /* show whiteout */ |
24482 | +#define AuOpt_PLINK (1 << 6) /* pseudo-link */ | |
076b876e AM |
24483 | +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm |
24484 | + bits */ | |
dece6358 AM |
24485 | +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */ |
24486 | +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */ | |
24487 | +#define AuOpt_SUM_W (1 << 11) /* unimplemented */ | |
24488 | +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */ | |
24489 | +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */ | |
4a4d8108 | 24490 | +#define AuOpt_DIO (1 << 14) /* direct io */ |
1facf9fc | 24491 | + |
4a4d8108 AM |
24492 | +#ifndef CONFIG_AUFS_HNOTIFY |
24493 | +#undef AuOpt_UDBA_HNOTIFY | |
24494 | +#define AuOpt_UDBA_HNOTIFY 0 | |
1facf9fc | 24495 | +#endif |
dece6358 AM |
24496 | +#ifndef CONFIG_AUFS_SHWH |
24497 | +#undef AuOpt_SHWH | |
24498 | +#define AuOpt_SHWH 0 | |
24499 | +#endif | |
1facf9fc | 24500 | + |
24501 | +#define AuOpt_Def (AuOpt_XINO \ | |
24502 | + | AuOpt_UDBA_REVAL \ | |
24503 | + | AuOpt_PLINK \ | |
24504 | + /* | AuOpt_DIRPERM1 */ \ | |
24505 | + | AuOpt_WARN_PERM) | |
24506 | +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \ | |
24507 | + | AuOpt_UDBA_REVAL \ | |
4a4d8108 | 24508 | + | AuOpt_UDBA_HNOTIFY) |
1facf9fc | 24509 | + |
24510 | +#define au_opt_test(flags, name) (flags & AuOpt_##name) | |
24511 | +#define au_opt_set(flags, name) do { \ | |
24512 | + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \ | |
24513 | + ((flags) |= AuOpt_##name); \ | |
24514 | +} while (0) | |
24515 | +#define au_opt_set_udba(flags, name) do { \ | |
24516 | + (flags) &= ~AuOptMask_UDBA; \ | |
24517 | + ((flags) |= AuOpt_##name); \ | |
24518 | +} while (0) | |
7f207e10 AM |
24519 | +#define au_opt_clr(flags, name) do { \ |
24520 | + ((flags) &= ~AuOpt_##name); \ | |
24521 | +} while (0) | |
1facf9fc | 24522 | + |
e49829fe JR |
24523 | +static inline unsigned int au_opts_plink(unsigned int mntflags) |
24524 | +{ | |
24525 | +#ifdef CONFIG_PROC_FS | |
24526 | + return mntflags; | |
24527 | +#else | |
24528 | + return mntflags & ~AuOpt_PLINK; | |
24529 | +#endif | |
24530 | +} | |
24531 | + | |
1facf9fc | 24532 | +/* ---------------------------------------------------------------------- */ |
24533 | + | |
24534 | +/* policies to select one among multiple writable branches */ | |
24535 | +enum { | |
24536 | + AuWbrCreate_TDP, /* top down parent */ | |
24537 | + AuWbrCreate_RR, /* round robin */ | |
24538 | + AuWbrCreate_MFS, /* most free space */ | |
24539 | + AuWbrCreate_MFSV, /* mfs with seconds */ | |
24540 | + AuWbrCreate_MFSRR, /* mfs then rr */ | |
24541 | + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */ | |
24542 | + AuWbrCreate_PMFS, /* parent and mfs */ | |
24543 | + AuWbrCreate_PMFSV, /* parent and mfs with seconds */ | |
392086de AM |
24544 | + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */ |
24545 | + AuWbrCreate_PMFSRRV, /* plus seconds */ | |
1facf9fc | 24546 | + |
24547 | + AuWbrCreate_Def = AuWbrCreate_TDP | |
24548 | +}; | |
24549 | + | |
24550 | +enum { | |
24551 | + AuWbrCopyup_TDP, /* top down parent */ | |
24552 | + AuWbrCopyup_BUP, /* bottom up parent */ | |
24553 | + AuWbrCopyup_BU, /* bottom up */ | |
24554 | + | |
24555 | + AuWbrCopyup_Def = AuWbrCopyup_TDP | |
24556 | +}; | |
24557 | + | |
24558 | +/* ---------------------------------------------------------------------- */ | |
24559 | + | |
24560 | +struct au_opt_add { | |
24561 | + aufs_bindex_t bindex; | |
24562 | + char *pathname; | |
24563 | + int perm; | |
24564 | + struct path path; | |
24565 | +}; | |
24566 | + | |
24567 | +struct au_opt_del { | |
24568 | + char *pathname; | |
24569 | + struct path h_path; | |
24570 | +}; | |
24571 | + | |
24572 | +struct au_opt_mod { | |
24573 | + char *path; | |
24574 | + int perm; | |
24575 | + struct dentry *h_root; | |
24576 | +}; | |
24577 | + | |
24578 | +struct au_opt_xino { | |
24579 | + char *path; | |
24580 | + struct file *file; | |
24581 | +}; | |
24582 | + | |
24583 | +struct au_opt_xino_itrunc { | |
24584 | + aufs_bindex_t bindex; | |
24585 | +}; | |
24586 | + | |
24587 | +struct au_opt_wbr_create { | |
24588 | + int wbr_create; | |
24589 | + int mfs_second; | |
24590 | + unsigned long long mfsrr_watermark; | |
24591 | +}; | |
24592 | + | |
24593 | +struct au_opt { | |
24594 | + int type; | |
24595 | + union { | |
24596 | + struct au_opt_xino xino; | |
24597 | + struct au_opt_xino_itrunc xino_itrunc; | |
24598 | + struct au_opt_add add; | |
24599 | + struct au_opt_del del; | |
24600 | + struct au_opt_mod mod; | |
24601 | + int dirwh; | |
24602 | + int rdcache; | |
24603 | + unsigned int rdblk; | |
24604 | + unsigned int rdhash; | |
24605 | + int udba; | |
24606 | + struct au_opt_wbr_create wbr_create; | |
24607 | + int wbr_copyup; | |
076b876e | 24608 | + unsigned int fhsm_second; |
1facf9fc | 24609 | + }; |
24610 | +}; | |
24611 | + | |
24612 | +/* opts flags */ | |
24613 | +#define AuOpts_REMOUNT 1 | |
027c5e7a AM |
24614 | +#define AuOpts_REFRESH (1 << 1) |
24615 | +#define AuOpts_TRUNC_XIB (1 << 2) | |
24616 | +#define AuOpts_REFRESH_DYAOP (1 << 3) | |
1facf9fc | 24617 | +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name) |
7f207e10 AM |
24618 | +#define au_fset_opts(flags, name) \ |
24619 | + do { (flags) |= AuOpts_##name; } while (0) | |
24620 | +#define au_fclr_opts(flags, name) \ | |
24621 | + do { (flags) &= ~AuOpts_##name; } while (0) | |
1facf9fc | 24622 | + |
24623 | +struct au_opts { | |
24624 | + struct au_opt *opt; | |
24625 | + int max_opt; | |
24626 | + | |
24627 | + unsigned int given_udba; | |
24628 | + unsigned int flags; | |
24629 | + unsigned long sb_flags; | |
24630 | +}; | |
24631 | + | |
24632 | +/* ---------------------------------------------------------------------- */ | |
24633 | + | |
7e9cd9fe | 24634 | +/* opts.c */ |
076b876e | 24635 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm); |
1facf9fc | 24636 | +const char *au_optstr_udba(int udba); |
24637 | +const char *au_optstr_wbr_copyup(int wbr_copyup); | |
24638 | +const char *au_optstr_wbr_create(int wbr_create); | |
24639 | + | |
24640 | +void au_opts_free(struct au_opts *opts); | |
24641 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts); | |
24642 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
24643 | + unsigned int pending); | |
24644 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts); | |
24645 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts); | |
24646 | + | |
24647 | +unsigned int au_opt_udba(struct super_block *sb); | |
24648 | + | |
1facf9fc | 24649 | +#endif /* __KERNEL__ */ |
24650 | +#endif /* __AUFS_OPTS_H__ */ | |
7f207e10 AM |
24651 | diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c |
24652 | --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 24653 | +++ linux/fs/aufs/plink.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 24654 | @@ -0,0 +1,528 @@ |
1facf9fc | 24655 | +/* |
2000de60 | 24656 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 24657 | + * |
24658 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24659 | + * it under the terms of the GNU General Public License as published by | |
24660 | + * the Free Software Foundation; either version 2 of the License, or | |
24661 | + * (at your option) any later version. | |
dece6358 AM |
24662 | + * |
24663 | + * This program is distributed in the hope that it will be useful, | |
24664 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24665 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24666 | + * GNU General Public License for more details. | |
24667 | + * | |
24668 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24669 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24670 | + */ |
24671 | + | |
24672 | +/* | |
24673 | + * pseudo-link | |
24674 | + */ | |
24675 | + | |
24676 | +#include "aufs.h" | |
24677 | + | |
24678 | +/* | |
e49829fe | 24679 | + * the pseudo-link maintenance mode. |
1facf9fc | 24680 | + * during a user process maintains the pseudo-links, |
24681 | + * prohibit adding a new plink and branch manipulation. | |
e49829fe JR |
24682 | + * |
24683 | + * Flags | |
24684 | + * NOPLM: | |
24685 | + * For entry functions which will handle plink, and i_mutex is already held | |
24686 | + * in VFS. | |
24687 | + * They cannot wait and should return an error at once. | |
24688 | + * Callers has to check the error. | |
24689 | + * NOPLMW: | |
24690 | + * For entry functions which will handle plink, but i_mutex is not held | |
24691 | + * in VFS. | |
24692 | + * They can wait the plink maintenance mode to finish. | |
24693 | + * | |
24694 | + * They behave like F_SETLK and F_SETLKW. | |
24695 | + * If the caller never handle plink, then both flags are unnecessary. | |
1facf9fc | 24696 | + */ |
e49829fe JR |
24697 | + |
24698 | +int au_plink_maint(struct super_block *sb, int flags) | |
1facf9fc | 24699 | +{ |
e49829fe JR |
24700 | + int err; |
24701 | + pid_t pid, ppid; | |
24702 | + struct au_sbinfo *sbi; | |
dece6358 AM |
24703 | + |
24704 | + SiMustAnyLock(sb); | |
24705 | + | |
e49829fe JR |
24706 | + err = 0; |
24707 | + if (!au_opt_test(au_mntflags(sb), PLINK)) | |
24708 | + goto out; | |
24709 | + | |
24710 | + sbi = au_sbi(sb); | |
24711 | + pid = sbi->si_plink_maint_pid; | |
24712 | + if (!pid || pid == current->pid) | |
24713 | + goto out; | |
24714 | + | |
24715 | + /* todo: it highly depends upon /sbin/mount.aufs */ | |
24716 | + rcu_read_lock(); | |
24717 | + ppid = task_pid_vnr(rcu_dereference(current->real_parent)); | |
24718 | + rcu_read_unlock(); | |
24719 | + if (pid == ppid) | |
24720 | + goto out; | |
24721 | + | |
24722 | + if (au_ftest_lock(flags, NOPLMW)) { | |
027c5e7a AM |
24723 | + /* if there is no i_mutex lock in VFS, we don't need to wait */ |
24724 | + /* AuDebugOn(!lockdep_depth(current)); */ | |
e49829fe JR |
24725 | + while (sbi->si_plink_maint_pid) { |
24726 | + si_read_unlock(sb); | |
24727 | + /* gave up wake_up_bit() */ | |
24728 | + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid); | |
24729 | + | |
24730 | + if (au_ftest_lock(flags, FLUSH)) | |
24731 | + au_nwt_flush(&sbi->si_nowait); | |
24732 | + si_noflush_read_lock(sb); | |
24733 | + } | |
24734 | + } else if (au_ftest_lock(flags, NOPLM)) { | |
24735 | + AuDbg("ppid %d, pid %d\n", ppid, pid); | |
24736 | + err = -EAGAIN; | |
24737 | + } | |
24738 | + | |
24739 | +out: | |
24740 | + return err; | |
4a4d8108 AM |
24741 | +} |
24742 | + | |
e49829fe | 24743 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo) |
4a4d8108 | 24744 | +{ |
4a4d8108 | 24745 | + spin_lock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 24746 | + sbinfo->si_plink_maint_pid = 0; |
4a4d8108 | 24747 | + spin_unlock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 24748 | + wake_up_all(&sbinfo->si_plink_wq); |
4a4d8108 AM |
24749 | +} |
24750 | + | |
e49829fe | 24751 | +int au_plink_maint_enter(struct super_block *sb) |
4a4d8108 AM |
24752 | +{ |
24753 | + int err; | |
4a4d8108 AM |
24754 | + struct au_sbinfo *sbinfo; |
24755 | + | |
24756 | + err = 0; | |
4a4d8108 AM |
24757 | + sbinfo = au_sbi(sb); |
24758 | + /* make sure i am the only one in this fs */ | |
e49829fe JR |
24759 | + si_write_lock(sb, AuLock_FLUSH); |
24760 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
24761 | + spin_lock(&sbinfo->si_plink_maint_lock); | |
24762 | + if (!sbinfo->si_plink_maint_pid) | |
24763 | + sbinfo->si_plink_maint_pid = current->pid; | |
24764 | + else | |
24765 | + err = -EBUSY; | |
24766 | + spin_unlock(&sbinfo->si_plink_maint_lock); | |
24767 | + } | |
4a4d8108 AM |
24768 | + si_write_unlock(sb); |
24769 | + | |
24770 | + return err; | |
1facf9fc | 24771 | +} |
24772 | + | |
24773 | +/* ---------------------------------------------------------------------- */ | |
24774 | + | |
1facf9fc | 24775 | +#ifdef CONFIG_AUFS_DEBUG |
24776 | +void au_plink_list(struct super_block *sb) | |
24777 | +{ | |
86dc4139 | 24778 | + int i; |
1facf9fc | 24779 | + struct au_sbinfo *sbinfo; |
86dc4139 | 24780 | + struct hlist_head *plink_hlist; |
1facf9fc | 24781 | + struct pseudo_link *plink; |
24782 | + | |
dece6358 AM |
24783 | + SiMustAnyLock(sb); |
24784 | + | |
1facf9fc | 24785 | + sbinfo = au_sbi(sb); |
24786 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 24787 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 24788 | + |
86dc4139 AM |
24789 | + for (i = 0; i < AuPlink_NHASH; i++) { |
24790 | + plink_hlist = &sbinfo->si_plink[i].head; | |
24791 | + rcu_read_lock(); | |
24792 | + hlist_for_each_entry_rcu(plink, plink_hlist, hlist) | |
24793 | + AuDbg("%lu\n", plink->inode->i_ino); | |
24794 | + rcu_read_unlock(); | |
24795 | + } | |
1facf9fc | 24796 | +} |
24797 | +#endif | |
24798 | + | |
24799 | +/* is the inode pseudo-linked? */ | |
24800 | +int au_plink_test(struct inode *inode) | |
24801 | +{ | |
86dc4139 | 24802 | + int found, i; |
1facf9fc | 24803 | + struct au_sbinfo *sbinfo; |
86dc4139 | 24804 | + struct hlist_head *plink_hlist; |
1facf9fc | 24805 | + struct pseudo_link *plink; |
24806 | + | |
24807 | + sbinfo = au_sbi(inode->i_sb); | |
dece6358 | 24808 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
1facf9fc | 24809 | + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK)); |
e49829fe | 24810 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
1facf9fc | 24811 | + |
24812 | + found = 0; | |
86dc4139 AM |
24813 | + i = au_plink_hash(inode->i_ino); |
24814 | + plink_hlist = &sbinfo->si_plink[i].head; | |
4a4d8108 | 24815 | + rcu_read_lock(); |
86dc4139 | 24816 | + hlist_for_each_entry_rcu(plink, plink_hlist, hlist) |
1facf9fc | 24817 | + if (plink->inode == inode) { |
24818 | + found = 1; | |
24819 | + break; | |
24820 | + } | |
4a4d8108 | 24821 | + rcu_read_unlock(); |
1facf9fc | 24822 | + return found; |
24823 | +} | |
24824 | + | |
24825 | +/* ---------------------------------------------------------------------- */ | |
24826 | + | |
24827 | +/* | |
24828 | + * generate a name for plink. | |
24829 | + * the file will be stored under AUFS_WH_PLINKDIR. | |
24830 | + */ | |
24831 | +/* 20 is max digits length of ulong 64 */ | |
24832 | +#define PLINK_NAME_LEN ((20 + 1) * 2) | |
24833 | + | |
24834 | +static int plink_name(char *name, int len, struct inode *inode, | |
24835 | + aufs_bindex_t bindex) | |
24836 | +{ | |
24837 | + int rlen; | |
24838 | + struct inode *h_inode; | |
24839 | + | |
24840 | + h_inode = au_h_iptr(inode, bindex); | |
24841 | + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino); | |
24842 | + return rlen; | |
24843 | +} | |
24844 | + | |
7f207e10 AM |
24845 | +struct au_do_plink_lkup_args { |
24846 | + struct dentry **errp; | |
24847 | + struct qstr *tgtname; | |
24848 | + struct dentry *h_parent; | |
24849 | + struct au_branch *br; | |
24850 | +}; | |
24851 | + | |
24852 | +static struct dentry *au_do_plink_lkup(struct qstr *tgtname, | |
24853 | + struct dentry *h_parent, | |
24854 | + struct au_branch *br) | |
24855 | +{ | |
24856 | + struct dentry *h_dentry; | |
24857 | + struct mutex *h_mtx; | |
24858 | + | |
5527c038 | 24859 | + h_mtx = &d_inode(h_parent)->i_mutex; |
7f207e10 | 24860 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2); |
b4510431 | 24861 | + h_dentry = vfsub_lkup_one(tgtname, h_parent); |
7f207e10 AM |
24862 | + mutex_unlock(h_mtx); |
24863 | + return h_dentry; | |
24864 | +} | |
24865 | + | |
24866 | +static void au_call_do_plink_lkup(void *args) | |
24867 | +{ | |
24868 | + struct au_do_plink_lkup_args *a = args; | |
24869 | + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br); | |
24870 | +} | |
24871 | + | |
1facf9fc | 24872 | +/* lookup the plink-ed @inode under the branch at @bindex */ |
24873 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex) | |
24874 | +{ | |
24875 | + struct dentry *h_dentry, *h_parent; | |
24876 | + struct au_branch *br; | |
7f207e10 | 24877 | + int wkq_err; |
1facf9fc | 24878 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 24879 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 24880 | + |
e49829fe JR |
24881 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
24882 | + | |
1facf9fc | 24883 | + br = au_sbr(inode->i_sb, bindex); |
24884 | + h_parent = br->br_wbr->wbr_plink; | |
1facf9fc | 24885 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
24886 | + | |
2dfbb274 | 24887 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
7f207e10 AM |
24888 | + struct au_do_plink_lkup_args args = { |
24889 | + .errp = &h_dentry, | |
24890 | + .tgtname = &tgtname, | |
24891 | + .h_parent = h_parent, | |
24892 | + .br = br | |
24893 | + }; | |
24894 | + | |
24895 | + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args); | |
24896 | + if (unlikely(wkq_err)) | |
24897 | + h_dentry = ERR_PTR(wkq_err); | |
24898 | + } else | |
24899 | + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br); | |
24900 | + | |
1facf9fc | 24901 | + return h_dentry; |
24902 | +} | |
24903 | + | |
24904 | +/* create a pseudo-link */ | |
24905 | +static int do_whplink(struct qstr *tgt, struct dentry *h_parent, | |
24906 | + struct dentry *h_dentry, struct au_branch *br) | |
24907 | +{ | |
24908 | + int err; | |
24909 | + struct path h_path = { | |
86dc4139 | 24910 | + .mnt = au_br_mnt(br) |
1facf9fc | 24911 | + }; |
523b37e3 | 24912 | + struct inode *h_dir, *delegated; |
1facf9fc | 24913 | + |
5527c038 | 24914 | + h_dir = d_inode(h_parent); |
7f207e10 | 24915 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2); |
4f0767ce | 24916 | +again: |
b4510431 | 24917 | + h_path.dentry = vfsub_lkup_one(tgt, h_parent); |
1facf9fc | 24918 | + err = PTR_ERR(h_path.dentry); |
24919 | + if (IS_ERR(h_path.dentry)) | |
24920 | + goto out; | |
24921 | + | |
24922 | + err = 0; | |
24923 | + /* wh.plink dir is not monitored */ | |
7f207e10 | 24924 | + /* todo: is it really safe? */ |
5527c038 JR |
24925 | + if (d_is_positive(h_path.dentry) |
24926 | + && d_inode(h_path.dentry) != d_inode(h_dentry)) { | |
523b37e3 AM |
24927 | + delegated = NULL; |
24928 | + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0); | |
24929 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24930 | + pr_warn("cannot retry for NFSv4 delegation" | |
24931 | + " for an internal unlink\n"); | |
24932 | + iput(delegated); | |
24933 | + } | |
1facf9fc | 24934 | + dput(h_path.dentry); |
24935 | + h_path.dentry = NULL; | |
24936 | + if (!err) | |
24937 | + goto again; | |
24938 | + } | |
5527c038 | 24939 | + if (!err && d_is_negative(h_path.dentry)) { |
523b37e3 AM |
24940 | + delegated = NULL; |
24941 | + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated); | |
24942 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24943 | + pr_warn("cannot retry for NFSv4 delegation" | |
24944 | + " for an internal link\n"); | |
24945 | + iput(delegated); | |
24946 | + } | |
24947 | + } | |
1facf9fc | 24948 | + dput(h_path.dentry); |
24949 | + | |
4f0767ce | 24950 | +out: |
7f207e10 | 24951 | + mutex_unlock(&h_dir->i_mutex); |
1facf9fc | 24952 | + return err; |
24953 | +} | |
24954 | + | |
24955 | +struct do_whplink_args { | |
24956 | + int *errp; | |
24957 | + struct qstr *tgt; | |
24958 | + struct dentry *h_parent; | |
24959 | + struct dentry *h_dentry; | |
24960 | + struct au_branch *br; | |
24961 | +}; | |
24962 | + | |
24963 | +static void call_do_whplink(void *args) | |
24964 | +{ | |
24965 | + struct do_whplink_args *a = args; | |
24966 | + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br); | |
24967 | +} | |
24968 | + | |
24969 | +static int whplink(struct dentry *h_dentry, struct inode *inode, | |
24970 | + aufs_bindex_t bindex, struct au_branch *br) | |
24971 | +{ | |
24972 | + int err, wkq_err; | |
24973 | + struct au_wbr *wbr; | |
24974 | + struct dentry *h_parent; | |
1facf9fc | 24975 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 24976 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 24977 | + |
24978 | + wbr = au_sbr(inode->i_sb, bindex)->br_wbr; | |
24979 | + h_parent = wbr->wbr_plink; | |
1facf9fc | 24980 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
24981 | + | |
24982 | + /* always superio. */ | |
2dfbb274 | 24983 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
1facf9fc | 24984 | + struct do_whplink_args args = { |
24985 | + .errp = &err, | |
24986 | + .tgt = &tgtname, | |
24987 | + .h_parent = h_parent, | |
24988 | + .h_dentry = h_dentry, | |
24989 | + .br = br | |
24990 | + }; | |
24991 | + wkq_err = au_wkq_wait(call_do_whplink, &args); | |
24992 | + if (unlikely(wkq_err)) | |
24993 | + err = wkq_err; | |
24994 | + } else | |
24995 | + err = do_whplink(&tgtname, h_parent, h_dentry, br); | |
1facf9fc | 24996 | + |
24997 | + return err; | |
24998 | +} | |
24999 | + | |
25000 | +/* free a single plink */ | |
25001 | +static void do_put_plink(struct pseudo_link *plink, int do_del) | |
25002 | +{ | |
1facf9fc | 25003 | + if (do_del) |
86dc4139 | 25004 | + hlist_del(&plink->hlist); |
4a4d8108 AM |
25005 | + iput(plink->inode); |
25006 | + kfree(plink); | |
25007 | +} | |
25008 | + | |
25009 | +static void do_put_plink_rcu(struct rcu_head *rcu) | |
25010 | +{ | |
25011 | + struct pseudo_link *plink; | |
25012 | + | |
25013 | + plink = container_of(rcu, struct pseudo_link, rcu); | |
25014 | + iput(plink->inode); | |
1facf9fc | 25015 | + kfree(plink); |
25016 | +} | |
25017 | + | |
25018 | +/* | |
25019 | + * create a new pseudo-link for @h_dentry on @bindex. | |
25020 | + * the linked inode is held in aufs @inode. | |
25021 | + */ | |
25022 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
25023 | + struct dentry *h_dentry) | |
25024 | +{ | |
25025 | + struct super_block *sb; | |
25026 | + struct au_sbinfo *sbinfo; | |
86dc4139 | 25027 | + struct hlist_head *plink_hlist; |
4a4d8108 | 25028 | + struct pseudo_link *plink, *tmp; |
86dc4139 AM |
25029 | + struct au_sphlhead *sphl; |
25030 | + int found, err, cnt, i; | |
1facf9fc | 25031 | + |
25032 | + sb = inode->i_sb; | |
25033 | + sbinfo = au_sbi(sb); | |
25034 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25035 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25036 | + |
86dc4139 | 25037 | + found = au_plink_test(inode); |
4a4d8108 | 25038 | + if (found) |
1facf9fc | 25039 | + return; |
4a4d8108 | 25040 | + |
86dc4139 AM |
25041 | + i = au_plink_hash(inode->i_ino); |
25042 | + sphl = sbinfo->si_plink + i; | |
25043 | + plink_hlist = &sphl->head; | |
4a4d8108 AM |
25044 | + tmp = kmalloc(sizeof(*plink), GFP_NOFS); |
25045 | + if (tmp) | |
25046 | + tmp->inode = au_igrab(inode); | |
25047 | + else { | |
25048 | + err = -ENOMEM; | |
25049 | + goto out; | |
1facf9fc | 25050 | + } |
25051 | + | |
86dc4139 AM |
25052 | + spin_lock(&sphl->spin); |
25053 | + hlist_for_each_entry(plink, plink_hlist, hlist) { | |
4a4d8108 AM |
25054 | + if (plink->inode == inode) { |
25055 | + found = 1; | |
25056 | + break; | |
25057 | + } | |
1facf9fc | 25058 | + } |
4a4d8108 | 25059 | + if (!found) |
86dc4139 AM |
25060 | + hlist_add_head_rcu(&tmp->hlist, plink_hlist); |
25061 | + spin_unlock(&sphl->spin); | |
4a4d8108 | 25062 | + if (!found) { |
86dc4139 AM |
25063 | + cnt = au_sphl_count(sphl); |
25064 | +#define msg "unexpectedly unblanced or too many pseudo-links" | |
25065 | + if (cnt > AUFS_PLINK_WARN) | |
25066 | + AuWarn1(msg ", %d\n", cnt); | |
25067 | +#undef msg | |
1facf9fc | 25068 | + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex)); |
4a4d8108 AM |
25069 | + } else { |
25070 | + do_put_plink(tmp, 0); | |
25071 | + return; | |
1facf9fc | 25072 | + } |
25073 | + | |
4a4d8108 | 25074 | +out: |
1facf9fc | 25075 | + if (unlikely(err)) { |
0c3ec466 | 25076 | + pr_warn("err %d, damaged pseudo link.\n", err); |
4a4d8108 | 25077 | + if (tmp) { |
86dc4139 | 25078 | + au_sphl_del_rcu(&tmp->hlist, sphl); |
4a4d8108 AM |
25079 | + call_rcu(&tmp->rcu, do_put_plink_rcu); |
25080 | + } | |
1facf9fc | 25081 | + } |
25082 | +} | |
25083 | + | |
25084 | +/* free all plinks */ | |
e49829fe | 25085 | +void au_plink_put(struct super_block *sb, int verbose) |
1facf9fc | 25086 | +{ |
86dc4139 | 25087 | + int i, warned; |
1facf9fc | 25088 | + struct au_sbinfo *sbinfo; |
86dc4139 AM |
25089 | + struct hlist_head *plink_hlist; |
25090 | + struct hlist_node *tmp; | |
25091 | + struct pseudo_link *plink; | |
1facf9fc | 25092 | + |
dece6358 AM |
25093 | + SiMustWriteLock(sb); |
25094 | + | |
1facf9fc | 25095 | + sbinfo = au_sbi(sb); |
25096 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25097 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25098 | + |
1facf9fc | 25099 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
25100 | + warned = 0; |
25101 | + for (i = 0; i < AuPlink_NHASH; i++) { | |
25102 | + plink_hlist = &sbinfo->si_plink[i].head; | |
25103 | + if (!warned && verbose && !hlist_empty(plink_hlist)) { | |
25104 | + pr_warn("pseudo-link is not flushed"); | |
25105 | + warned = 1; | |
25106 | + } | |
25107 | + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) | |
25108 | + do_put_plink(plink, 0); | |
25109 | + INIT_HLIST_HEAD(plink_hlist); | |
25110 | + } | |
1facf9fc | 25111 | +} |
25112 | + | |
e49829fe JR |
25113 | +void au_plink_clean(struct super_block *sb, int verbose) |
25114 | +{ | |
25115 | + struct dentry *root; | |
25116 | + | |
25117 | + root = sb->s_root; | |
25118 | + aufs_write_lock(root); | |
25119 | + if (au_opt_test(au_mntflags(sb), PLINK)) | |
25120 | + au_plink_put(sb, verbose); | |
25121 | + aufs_write_unlock(root); | |
25122 | +} | |
25123 | + | |
86dc4139 AM |
25124 | +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id) |
25125 | +{ | |
25126 | + int do_put; | |
25127 | + aufs_bindex_t bstart, bend, bindex; | |
25128 | + | |
25129 | + do_put = 0; | |
25130 | + bstart = au_ibstart(inode); | |
25131 | + bend = au_ibend(inode); | |
25132 | + if (bstart >= 0) { | |
25133 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
25134 | + if (!au_h_iptr(inode, bindex) | |
25135 | + || au_ii_br_id(inode, bindex) != br_id) | |
25136 | + continue; | |
25137 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
25138 | + do_put = 1; | |
25139 | + break; | |
25140 | + } | |
25141 | + if (do_put) | |
25142 | + for (bindex = bstart; bindex <= bend; bindex++) | |
25143 | + if (au_h_iptr(inode, bindex)) { | |
25144 | + do_put = 0; | |
25145 | + break; | |
25146 | + } | |
25147 | + } else | |
25148 | + do_put = 1; | |
25149 | + | |
25150 | + return do_put; | |
25151 | +} | |
25152 | + | |
1facf9fc | 25153 | +/* free the plinks on a branch specified by @br_id */ |
25154 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id) | |
25155 | +{ | |
25156 | + struct au_sbinfo *sbinfo; | |
86dc4139 AM |
25157 | + struct hlist_head *plink_hlist; |
25158 | + struct hlist_node *tmp; | |
25159 | + struct pseudo_link *plink; | |
1facf9fc | 25160 | + struct inode *inode; |
86dc4139 | 25161 | + int i, do_put; |
1facf9fc | 25162 | + |
dece6358 AM |
25163 | + SiMustWriteLock(sb); |
25164 | + | |
1facf9fc | 25165 | + sbinfo = au_sbi(sb); |
25166 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 25167 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25168 | + |
1facf9fc | 25169 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
25170 | + for (i = 0; i < AuPlink_NHASH; i++) { |
25171 | + plink_hlist = &sbinfo->si_plink[i].head; | |
25172 | + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) { | |
25173 | + inode = au_igrab(plink->inode); | |
25174 | + ii_write_lock_child(inode); | |
25175 | + do_put = au_plink_do_half_refresh(inode, br_id); | |
dece6358 AM |
25176 | + if (do_put) |
25177 | + do_put_plink(plink, 1); | |
86dc4139 AM |
25178 | + ii_write_unlock(inode); |
25179 | + iput(inode); | |
dece6358 | 25180 | + } |
dece6358 AM |
25181 | + } |
25182 | +} | |
7f207e10 AM |
25183 | diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c |
25184 | --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 25185 | +++ linux/fs/aufs/poll.c 2015-09-24 10:47:58.254719746 +0200 |
b912730e | 25186 | @@ -0,0 +1,52 @@ |
dece6358 | 25187 | +/* |
2000de60 | 25188 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
dece6358 AM |
25189 | + * |
25190 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25191 | + * it under the terms of the GNU General Public License as published by | |
25192 | + * the Free Software Foundation; either version 2 of the License, or | |
25193 | + * (at your option) any later version. | |
25194 | + * | |
25195 | + * This program is distributed in the hope that it will be useful, | |
25196 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25197 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25198 | + * GNU General Public License for more details. | |
25199 | + * | |
25200 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25201 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 AM |
25202 | + */ |
25203 | + | |
1308ab2a | 25204 | +/* |
25205 | + * poll operation | |
25206 | + * There is only one filesystem which implements ->poll operation, currently. | |
25207 | + */ | |
25208 | + | |
25209 | +#include "aufs.h" | |
25210 | + | |
25211 | +unsigned int aufs_poll(struct file *file, poll_table *wait) | |
25212 | +{ | |
25213 | + unsigned int mask; | |
25214 | + int err; | |
25215 | + struct file *h_file; | |
1308ab2a | 25216 | + struct super_block *sb; |
25217 | + | |
25218 | + /* We should pretend an error happened. */ | |
25219 | + mask = POLLERR /* | POLLIN | POLLOUT */; | |
b912730e | 25220 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 25221 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e AM |
25222 | + |
25223 | + h_file = au_read_pre(file, /*keep_fi*/0); | |
25224 | + err = PTR_ERR(h_file); | |
25225 | + if (IS_ERR(h_file)) | |
1308ab2a | 25226 | + goto out; |
25227 | + | |
25228 | + /* it is not an error if h_file has no operation */ | |
25229 | + mask = DEFAULT_POLLMASK; | |
523b37e3 | 25230 | + if (h_file->f_op->poll) |
1308ab2a | 25231 | + mask = h_file->f_op->poll(h_file, wait); |
b912730e | 25232 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 25233 | + |
4f0767ce | 25234 | +out: |
1308ab2a | 25235 | + si_read_unlock(sb); |
25236 | + AuTraceErr((int)mask); | |
25237 | + return mask; | |
25238 | +} | |
c1595e42 JR |
25239 | diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c |
25240 | --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 25241 | +++ linux/fs/aufs/posix_acl.c 2015-09-24 10:47:58.254719746 +0200 |
c1595e42 JR |
25242 | @@ -0,0 +1,99 @@ |
25243 | +/* | |
2000de60 | 25244 | + * Copyright (C) 2014-2015 Junjiro R. Okajima |
c1595e42 JR |
25245 | + * |
25246 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25247 | + * it under the terms of the GNU General Public License as published by | |
25248 | + * the Free Software Foundation; either version 2 of the License, or | |
25249 | + * (at your option) any later version. | |
25250 | + * | |
25251 | + * This program is distributed in the hope that it will be useful, | |
25252 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25253 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25254 | + * GNU General Public License for more details. | |
25255 | + * | |
25256 | + * You should have received a copy of the GNU General Public License | |
25257 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25258 | + */ | |
25259 | + | |
25260 | +/* | |
25261 | + * posix acl operations | |
25262 | + */ | |
25263 | + | |
25264 | +#include <linux/fs.h> | |
25265 | +#include <linux/posix_acl.h> | |
25266 | +#include "aufs.h" | |
25267 | + | |
25268 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type) | |
25269 | +{ | |
25270 | + struct posix_acl *acl; | |
25271 | + int err; | |
25272 | + aufs_bindex_t bindex; | |
25273 | + struct inode *h_inode; | |
25274 | + struct super_block *sb; | |
25275 | + | |
25276 | + acl = NULL; | |
25277 | + sb = inode->i_sb; | |
25278 | + si_read_lock(sb, AuLock_FLUSH); | |
25279 | + ii_read_lock_child(inode); | |
25280 | + if (!(sb->s_flags & MS_POSIXACL)) | |
25281 | + goto out; | |
25282 | + | |
25283 | + bindex = au_ibstart(inode); | |
25284 | + h_inode = au_h_iptr(inode, bindex); | |
25285 | + if (unlikely(!h_inode | |
25286 | + || ((h_inode->i_mode & S_IFMT) | |
25287 | + != (inode->i_mode & S_IFMT)))) { | |
25288 | + err = au_busy_or_stale(); | |
25289 | + acl = ERR_PTR(err); | |
25290 | + goto out; | |
25291 | + } | |
25292 | + | |
25293 | + /* always topmost only */ | |
25294 | + acl = get_acl(h_inode, type); | |
25295 | + | |
25296 | +out: | |
25297 | + ii_read_unlock(inode); | |
25298 | + si_read_unlock(sb); | |
25299 | + | |
25300 | + AuTraceErrPtr(acl); | |
25301 | + return acl; | |
25302 | +} | |
25303 | + | |
25304 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |
25305 | +{ | |
25306 | + int err; | |
25307 | + ssize_t ssz; | |
25308 | + struct dentry *dentry; | |
25309 | + struct au_srxattr arg = { | |
25310 | + .type = AU_ACL_SET, | |
25311 | + .u.acl_set = { | |
25312 | + .acl = acl, | |
25313 | + .type = type | |
25314 | + }, | |
25315 | + }; | |
25316 | + | |
25317 | + mutex_lock(&inode->i_mutex); | |
25318 | + if (inode->i_ino == AUFS_ROOT_INO) | |
25319 | + dentry = dget(inode->i_sb->s_root); | |
25320 | + else { | |
25321 | + dentry = d_find_alias(inode); | |
25322 | + if (!dentry) | |
25323 | + dentry = d_find_any_alias(inode); | |
25324 | + if (!dentry) { | |
25325 | + pr_warn("cannot handle this inode, " | |
25326 | + "please report to aufs-users ML\n"); | |
25327 | + err = -ENOENT; | |
25328 | + goto out; | |
25329 | + } | |
25330 | + } | |
25331 | + | |
25332 | + ssz = au_srxattr(dentry, &arg); | |
25333 | + dput(dentry); | |
25334 | + err = ssz; | |
25335 | + if (ssz >= 0) | |
25336 | + err = 0; | |
25337 | + | |
25338 | +out: | |
25339 | + mutex_unlock(&inode->i_mutex); | |
25340 | + return err; | |
25341 | +} | |
7f207e10 AM |
25342 | diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c |
25343 | --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 25344 | +++ linux/fs/aufs/procfs.c 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 25345 | @@ -0,0 +1,169 @@ |
e49829fe | 25346 | +/* |
2000de60 | 25347 | + * Copyright (C) 2010-2015 Junjiro R. Okajima |
e49829fe JR |
25348 | + * |
25349 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25350 | + * it under the terms of the GNU General Public License as published by | |
25351 | + * the Free Software Foundation; either version 2 of the License, or | |
25352 | + * (at your option) any later version. | |
25353 | + * | |
25354 | + * This program is distributed in the hope that it will be useful, | |
25355 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25356 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25357 | + * GNU General Public License for more details. | |
25358 | + * | |
25359 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25360 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
25361 | + */ |
25362 | + | |
25363 | +/* | |
25364 | + * procfs interfaces | |
25365 | + */ | |
25366 | + | |
25367 | +#include <linux/proc_fs.h> | |
25368 | +#include "aufs.h" | |
25369 | + | |
25370 | +static int au_procfs_plm_release(struct inode *inode, struct file *file) | |
25371 | +{ | |
25372 | + struct au_sbinfo *sbinfo; | |
25373 | + | |
25374 | + sbinfo = file->private_data; | |
25375 | + if (sbinfo) { | |
25376 | + au_plink_maint_leave(sbinfo); | |
25377 | + kobject_put(&sbinfo->si_kobj); | |
25378 | + } | |
25379 | + | |
25380 | + return 0; | |
25381 | +} | |
25382 | + | |
25383 | +static void au_procfs_plm_write_clean(struct file *file) | |
25384 | +{ | |
25385 | + struct au_sbinfo *sbinfo; | |
25386 | + | |
25387 | + sbinfo = file->private_data; | |
25388 | + if (sbinfo) | |
25389 | + au_plink_clean(sbinfo->si_sb, /*verbose*/0); | |
25390 | +} | |
25391 | + | |
25392 | +static int au_procfs_plm_write_si(struct file *file, unsigned long id) | |
25393 | +{ | |
25394 | + int err; | |
25395 | + struct super_block *sb; | |
25396 | + struct au_sbinfo *sbinfo; | |
25397 | + | |
25398 | + err = -EBUSY; | |
25399 | + if (unlikely(file->private_data)) | |
25400 | + goto out; | |
25401 | + | |
25402 | + sb = NULL; | |
53392da6 | 25403 | + /* don't use au_sbilist_lock() here */ |
e49829fe JR |
25404 | + spin_lock(&au_sbilist.spin); |
25405 | + list_for_each_entry(sbinfo, &au_sbilist.head, si_list) | |
25406 | + if (id == sysaufs_si_id(sbinfo)) { | |
25407 | + kobject_get(&sbinfo->si_kobj); | |
25408 | + sb = sbinfo->si_sb; | |
25409 | + break; | |
25410 | + } | |
25411 | + spin_unlock(&au_sbilist.spin); | |
25412 | + | |
25413 | + err = -EINVAL; | |
25414 | + if (unlikely(!sb)) | |
25415 | + goto out; | |
25416 | + | |
25417 | + err = au_plink_maint_enter(sb); | |
25418 | + if (!err) | |
25419 | + /* keep kobject_get() */ | |
25420 | + file->private_data = sbinfo; | |
25421 | + else | |
25422 | + kobject_put(&sbinfo->si_kobj); | |
25423 | +out: | |
25424 | + return err; | |
25425 | +} | |
25426 | + | |
25427 | +/* | |
25428 | + * Accept a valid "si=xxxx" only. | |
25429 | + * Once it is accepted successfully, accept "clean" too. | |
25430 | + */ | |
25431 | +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf, | |
25432 | + size_t count, loff_t *ppos) | |
25433 | +{ | |
25434 | + ssize_t err; | |
25435 | + unsigned long id; | |
25436 | + /* last newline is allowed */ | |
25437 | + char buf[3 + sizeof(unsigned long) * 2 + 1]; | |
25438 | + | |
25439 | + err = -EACCES; | |
25440 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
25441 | + goto out; | |
25442 | + | |
25443 | + err = -EINVAL; | |
25444 | + if (unlikely(count > sizeof(buf))) | |
25445 | + goto out; | |
25446 | + | |
25447 | + err = copy_from_user(buf, ubuf, count); | |
25448 | + if (unlikely(err)) { | |
25449 | + err = -EFAULT; | |
25450 | + goto out; | |
25451 | + } | |
25452 | + buf[count] = 0; | |
25453 | + | |
25454 | + err = -EINVAL; | |
25455 | + if (!strcmp("clean", buf)) { | |
25456 | + au_procfs_plm_write_clean(file); | |
25457 | + goto out_success; | |
25458 | + } else if (unlikely(strncmp("si=", buf, 3))) | |
25459 | + goto out; | |
25460 | + | |
9dbd164d | 25461 | + err = kstrtoul(buf + 3, 16, &id); |
e49829fe JR |
25462 | + if (unlikely(err)) |
25463 | + goto out; | |
25464 | + | |
25465 | + err = au_procfs_plm_write_si(file, id); | |
25466 | + if (unlikely(err)) | |
25467 | + goto out; | |
25468 | + | |
25469 | +out_success: | |
25470 | + err = count; /* success */ | |
25471 | +out: | |
25472 | + return err; | |
25473 | +} | |
25474 | + | |
25475 | +static const struct file_operations au_procfs_plm_fop = { | |
25476 | + .write = au_procfs_plm_write, | |
25477 | + .release = au_procfs_plm_release, | |
25478 | + .owner = THIS_MODULE | |
25479 | +}; | |
25480 | + | |
25481 | +/* ---------------------------------------------------------------------- */ | |
25482 | + | |
25483 | +static struct proc_dir_entry *au_procfs_dir; | |
25484 | + | |
25485 | +void au_procfs_fin(void) | |
25486 | +{ | |
25487 | + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir); | |
25488 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
25489 | +} | |
25490 | + | |
25491 | +int __init au_procfs_init(void) | |
25492 | +{ | |
25493 | + int err; | |
25494 | + struct proc_dir_entry *entry; | |
25495 | + | |
25496 | + err = -ENOMEM; | |
25497 | + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL); | |
25498 | + if (unlikely(!au_procfs_dir)) | |
25499 | + goto out; | |
25500 | + | |
25501 | + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR, | |
25502 | + au_procfs_dir, &au_procfs_plm_fop); | |
25503 | + if (unlikely(!entry)) | |
25504 | + goto out_dir; | |
25505 | + | |
25506 | + err = 0; | |
25507 | + goto out; /* success */ | |
25508 | + | |
25509 | + | |
25510 | +out_dir: | |
25511 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
25512 | +out: | |
25513 | + return err; | |
25514 | +} | |
7f207e10 AM |
25515 | diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c |
25516 | --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 25517 | +++ linux/fs/aufs/rdu.c 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 25518 | @@ -0,0 +1,388 @@ |
1308ab2a | 25519 | +/* |
2000de60 | 25520 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1308ab2a | 25521 | + * |
25522 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25523 | + * it under the terms of the GNU General Public License as published by | |
25524 | + * the Free Software Foundation; either version 2 of the License, or | |
25525 | + * (at your option) any later version. | |
25526 | + * | |
25527 | + * This program is distributed in the hope that it will be useful, | |
25528 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25529 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25530 | + * GNU General Public License for more details. | |
25531 | + * | |
25532 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25533 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1308ab2a | 25534 | + */ |
25535 | + | |
25536 | +/* | |
25537 | + * readdir in userspace. | |
25538 | + */ | |
25539 | + | |
b752ccd1 | 25540 | +#include <linux/compat.h> |
4a4d8108 | 25541 | +#include <linux/fs_stack.h> |
1308ab2a | 25542 | +#include <linux/security.h> |
1308ab2a | 25543 | +#include "aufs.h" |
25544 | + | |
25545 | +/* bits for struct aufs_rdu.flags */ | |
25546 | +#define AuRdu_CALLED 1 | |
25547 | +#define AuRdu_CONT (1 << 1) | |
25548 | +#define AuRdu_FULL (1 << 2) | |
25549 | +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name) | |
7f207e10 AM |
25550 | +#define au_fset_rdu(flags, name) \ |
25551 | + do { (flags) |= AuRdu_##name; } while (0) | |
25552 | +#define au_fclr_rdu(flags, name) \ | |
25553 | + do { (flags) &= ~AuRdu_##name; } while (0) | |
1308ab2a | 25554 | + |
25555 | +struct au_rdu_arg { | |
392086de | 25556 | + struct dir_context ctx; |
1308ab2a | 25557 | + struct aufs_rdu *rdu; |
25558 | + union au_rdu_ent_ul ent; | |
25559 | + unsigned long end; | |
25560 | + | |
25561 | + struct super_block *sb; | |
25562 | + int err; | |
25563 | +}; | |
25564 | + | |
392086de | 25565 | +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen, |
1308ab2a | 25566 | + loff_t offset, u64 h_ino, unsigned int d_type) |
25567 | +{ | |
25568 | + int err, len; | |
392086de | 25569 | + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx); |
1308ab2a | 25570 | + struct aufs_rdu *rdu = arg->rdu; |
25571 | + struct au_rdu_ent ent; | |
25572 | + | |
25573 | + err = 0; | |
25574 | + arg->err = 0; | |
25575 | + au_fset_rdu(rdu->cookie.flags, CALLED); | |
25576 | + len = au_rdu_len(nlen); | |
25577 | + if (arg->ent.ul + len < arg->end) { | |
25578 | + ent.ino = h_ino; | |
25579 | + ent.bindex = rdu->cookie.bindex; | |
25580 | + ent.type = d_type; | |
25581 | + ent.nlen = nlen; | |
4a4d8108 AM |
25582 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) |
25583 | + ent.type = DT_UNKNOWN; | |
1308ab2a | 25584 | + |
9dbd164d | 25585 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 25586 | + err = -EFAULT; |
25587 | + if (copy_to_user(arg->ent.e, &ent, sizeof(ent))) | |
25588 | + goto out; | |
25589 | + if (copy_to_user(arg->ent.e->name, name, nlen)) | |
25590 | + goto out; | |
25591 | + /* the terminating NULL */ | |
25592 | + if (__put_user(0, arg->ent.e->name + nlen)) | |
25593 | + goto out; | |
25594 | + err = 0; | |
25595 | + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */ | |
25596 | + arg->ent.ul += len; | |
25597 | + rdu->rent++; | |
25598 | + } else { | |
25599 | + err = -EFAULT; | |
25600 | + au_fset_rdu(rdu->cookie.flags, FULL); | |
25601 | + rdu->full = 1; | |
25602 | + rdu->tail = arg->ent; | |
25603 | + } | |
25604 | + | |
4f0767ce | 25605 | +out: |
1308ab2a | 25606 | + /* AuTraceErr(err); */ |
25607 | + return err; | |
25608 | +} | |
25609 | + | |
25610 | +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg) | |
25611 | +{ | |
25612 | + int err; | |
25613 | + loff_t offset; | |
25614 | + struct au_rdu_cookie *cookie = &arg->rdu->cookie; | |
25615 | + | |
92d182d2 | 25616 | + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */ |
1308ab2a | 25617 | + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET); |
25618 | + err = offset; | |
25619 | + if (unlikely(offset != cookie->h_pos)) | |
25620 | + goto out; | |
25621 | + | |
25622 | + err = 0; | |
25623 | + do { | |
25624 | + arg->err = 0; | |
25625 | + au_fclr_rdu(cookie->flags, CALLED); | |
25626 | + /* smp_mb(); */ | |
392086de | 25627 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1308ab2a | 25628 | + if (err >= 0) |
25629 | + err = arg->err; | |
25630 | + } while (!err | |
25631 | + && au_ftest_rdu(cookie->flags, CALLED) | |
25632 | + && !au_ftest_rdu(cookie->flags, FULL)); | |
25633 | + cookie->h_pos = h_file->f_pos; | |
25634 | + | |
4f0767ce | 25635 | +out: |
1308ab2a | 25636 | + AuTraceErr(err); |
25637 | + return err; | |
25638 | +} | |
25639 | + | |
25640 | +static int au_rdu(struct file *file, struct aufs_rdu *rdu) | |
25641 | +{ | |
25642 | + int err; | |
25643 | + aufs_bindex_t bend; | |
392086de AM |
25644 | + struct au_rdu_arg arg = { |
25645 | + .ctx = { | |
2000de60 | 25646 | + .actor = au_rdu_fill |
392086de AM |
25647 | + } |
25648 | + }; | |
1308ab2a | 25649 | + struct dentry *dentry; |
25650 | + struct inode *inode; | |
25651 | + struct file *h_file; | |
25652 | + struct au_rdu_cookie *cookie = &rdu->cookie; | |
25653 | + | |
25654 | + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz); | |
25655 | + if (unlikely(err)) { | |
25656 | + err = -EFAULT; | |
25657 | + AuTraceErr(err); | |
25658 | + goto out; | |
25659 | + } | |
25660 | + rdu->rent = 0; | |
25661 | + rdu->tail = rdu->ent; | |
25662 | + rdu->full = 0; | |
25663 | + arg.rdu = rdu; | |
25664 | + arg.ent = rdu->ent; | |
25665 | + arg.end = arg.ent.ul; | |
25666 | + arg.end += rdu->sz; | |
25667 | + | |
25668 | + err = -ENOTDIR; | |
523b37e3 | 25669 | + if (unlikely(!file->f_op->iterate)) |
1308ab2a | 25670 | + goto out; |
25671 | + | |
25672 | + err = security_file_permission(file, MAY_READ); | |
25673 | + AuTraceErr(err); | |
25674 | + if (unlikely(err)) | |
25675 | + goto out; | |
25676 | + | |
2000de60 | 25677 | + dentry = file->f_path.dentry; |
5527c038 | 25678 | + inode = d_inode(dentry); |
1308ab2a | 25679 | +#if 1 |
25680 | + mutex_lock(&inode->i_mutex); | |
25681 | +#else | |
25682 | + err = mutex_lock_killable(&inode->i_mutex); | |
25683 | + AuTraceErr(err); | |
25684 | + if (unlikely(err)) | |
25685 | + goto out; | |
25686 | +#endif | |
1308ab2a | 25687 | + |
25688 | + arg.sb = inode->i_sb; | |
e49829fe JR |
25689 | + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM); |
25690 | + if (unlikely(err)) | |
25691 | + goto out_mtx; | |
027c5e7a AM |
25692 | + err = au_alive_dir(dentry); |
25693 | + if (unlikely(err)) | |
25694 | + goto out_si; | |
e49829fe | 25695 | + /* todo: reval? */ |
1308ab2a | 25696 | + fi_read_lock(file); |
25697 | + | |
25698 | + err = -EAGAIN; | |
25699 | + if (unlikely(au_ftest_rdu(cookie->flags, CONT) | |
25700 | + && cookie->generation != au_figen(file))) | |
25701 | + goto out_unlock; | |
25702 | + | |
25703 | + err = 0; | |
25704 | + if (!rdu->blk) { | |
25705 | + rdu->blk = au_sbi(arg.sb)->si_rdblk; | |
25706 | + if (!rdu->blk) | |
25707 | + rdu->blk = au_dir_size(file, /*dentry*/NULL); | |
25708 | + } | |
25709 | + bend = au_fbstart(file); | |
25710 | + if (cookie->bindex < bend) | |
25711 | + cookie->bindex = bend; | |
4a4d8108 | 25712 | + bend = au_fbend_dir(file); |
1308ab2a | 25713 | + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */ |
25714 | + for (; !err && cookie->bindex <= bend; | |
25715 | + cookie->bindex++, cookie->h_pos = 0) { | |
4a4d8108 | 25716 | + h_file = au_hf_dir(file, cookie->bindex); |
1308ab2a | 25717 | + if (!h_file) |
25718 | + continue; | |
25719 | + | |
25720 | + au_fclr_rdu(cookie->flags, FULL); | |
25721 | + err = au_rdu_do(h_file, &arg); | |
25722 | + AuTraceErr(err); | |
25723 | + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err)) | |
25724 | + break; | |
25725 | + } | |
25726 | + AuDbg("rent %llu\n", rdu->rent); | |
25727 | + | |
25728 | + if (!err && !au_ftest_rdu(cookie->flags, CONT)) { | |
25729 | + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH); | |
25730 | + au_fset_rdu(cookie->flags, CONT); | |
25731 | + cookie->generation = au_figen(file); | |
25732 | + } | |
25733 | + | |
25734 | + ii_read_lock_child(inode); | |
25735 | + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode))); | |
25736 | + ii_read_unlock(inode); | |
25737 | + | |
4f0767ce | 25738 | +out_unlock: |
1308ab2a | 25739 | + fi_read_unlock(file); |
027c5e7a | 25740 | +out_si: |
1308ab2a | 25741 | + si_read_unlock(arg.sb); |
4f0767ce | 25742 | +out_mtx: |
1308ab2a | 25743 | + mutex_unlock(&inode->i_mutex); |
4f0767ce | 25744 | +out: |
1308ab2a | 25745 | + AuTraceErr(err); |
25746 | + return err; | |
25747 | +} | |
25748 | + | |
25749 | +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu) | |
25750 | +{ | |
25751 | + int err; | |
25752 | + ino_t ino; | |
25753 | + unsigned long long nent; | |
25754 | + union au_rdu_ent_ul *u; | |
25755 | + struct au_rdu_ent ent; | |
25756 | + struct super_block *sb; | |
25757 | + | |
25758 | + err = 0; | |
25759 | + nent = rdu->nent; | |
25760 | + u = &rdu->ent; | |
2000de60 | 25761 | + sb = file->f_path.dentry->d_sb; |
1308ab2a | 25762 | + si_read_lock(sb, AuLock_FLUSH); |
25763 | + while (nent-- > 0) { | |
9dbd164d | 25764 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 25765 | + err = copy_from_user(&ent, u->e, sizeof(ent)); |
4a4d8108 AM |
25766 | + if (!err) |
25767 | + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino)); | |
1308ab2a | 25768 | + if (unlikely(err)) { |
25769 | + err = -EFAULT; | |
25770 | + AuTraceErr(err); | |
25771 | + break; | |
25772 | + } | |
25773 | + | |
25774 | + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */ | |
25775 | + if (!ent.wh) | |
25776 | + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino); | |
25777 | + else | |
25778 | + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type, | |
25779 | + &ino); | |
25780 | + if (unlikely(err)) { | |
25781 | + AuTraceErr(err); | |
25782 | + break; | |
25783 | + } | |
25784 | + | |
25785 | + err = __put_user(ino, &u->e->ino); | |
25786 | + if (unlikely(err)) { | |
25787 | + err = -EFAULT; | |
25788 | + AuTraceErr(err); | |
25789 | + break; | |
25790 | + } | |
25791 | + u->ul += au_rdu_len(ent.nlen); | |
25792 | + } | |
25793 | + si_read_unlock(sb); | |
25794 | + | |
25795 | + return err; | |
25796 | +} | |
25797 | + | |
25798 | +/* ---------------------------------------------------------------------- */ | |
25799 | + | |
25800 | +static int au_rdu_verify(struct aufs_rdu *rdu) | |
25801 | +{ | |
b752ccd1 | 25802 | + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | " |
1308ab2a | 25803 | + "%llu, b%d, 0x%x, g%u}\n", |
b752ccd1 | 25804 | + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ], |
1308ab2a | 25805 | + rdu->blk, |
25806 | + rdu->rent, rdu->shwh, rdu->full, | |
25807 | + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags, | |
25808 | + rdu->cookie.generation); | |
dece6358 | 25809 | + |
b752ccd1 | 25810 | + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu)) |
1308ab2a | 25811 | + return 0; |
dece6358 | 25812 | + |
b752ccd1 AM |
25813 | + AuDbg("%u:%u\n", |
25814 | + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu)); | |
1308ab2a | 25815 | + return -EINVAL; |
25816 | +} | |
25817 | + | |
25818 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
dece6358 | 25819 | +{ |
1308ab2a | 25820 | + long err, e; |
25821 | + struct aufs_rdu rdu; | |
25822 | + void __user *p = (void __user *)arg; | |
dece6358 | 25823 | + |
1308ab2a | 25824 | + err = copy_from_user(&rdu, p, sizeof(rdu)); |
25825 | + if (unlikely(err)) { | |
25826 | + err = -EFAULT; | |
25827 | + AuTraceErr(err); | |
25828 | + goto out; | |
25829 | + } | |
25830 | + err = au_rdu_verify(&rdu); | |
dece6358 AM |
25831 | + if (unlikely(err)) |
25832 | + goto out; | |
25833 | + | |
1308ab2a | 25834 | + switch (cmd) { |
25835 | + case AUFS_CTL_RDU: | |
25836 | + err = au_rdu(file, &rdu); | |
25837 | + if (unlikely(err)) | |
25838 | + break; | |
dece6358 | 25839 | + |
1308ab2a | 25840 | + e = copy_to_user(p, &rdu, sizeof(rdu)); |
25841 | + if (unlikely(e)) { | |
25842 | + err = -EFAULT; | |
25843 | + AuTraceErr(err); | |
25844 | + } | |
25845 | + break; | |
25846 | + case AUFS_CTL_RDU_INO: | |
25847 | + err = au_rdu_ino(file, &rdu); | |
25848 | + break; | |
25849 | + | |
25850 | + default: | |
4a4d8108 | 25851 | + /* err = -ENOTTY; */ |
1308ab2a | 25852 | + err = -EINVAL; |
25853 | + } | |
dece6358 | 25854 | + |
4f0767ce | 25855 | +out: |
1308ab2a | 25856 | + AuTraceErr(err); |
25857 | + return err; | |
1facf9fc | 25858 | +} |
b752ccd1 AM |
25859 | + |
25860 | +#ifdef CONFIG_COMPAT | |
25861 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
25862 | +{ | |
25863 | + long err, e; | |
25864 | + struct aufs_rdu rdu; | |
25865 | + void __user *p = compat_ptr(arg); | |
25866 | + | |
25867 | + /* todo: get_user()? */ | |
25868 | + err = copy_from_user(&rdu, p, sizeof(rdu)); | |
25869 | + if (unlikely(err)) { | |
25870 | + err = -EFAULT; | |
25871 | + AuTraceErr(err); | |
25872 | + goto out; | |
25873 | + } | |
25874 | + rdu.ent.e = compat_ptr(rdu.ent.ul); | |
25875 | + err = au_rdu_verify(&rdu); | |
25876 | + if (unlikely(err)) | |
25877 | + goto out; | |
25878 | + | |
25879 | + switch (cmd) { | |
25880 | + case AUFS_CTL_RDU: | |
25881 | + err = au_rdu(file, &rdu); | |
25882 | + if (unlikely(err)) | |
25883 | + break; | |
25884 | + | |
25885 | + rdu.ent.ul = ptr_to_compat(rdu.ent.e); | |
25886 | + rdu.tail.ul = ptr_to_compat(rdu.tail.e); | |
25887 | + e = copy_to_user(p, &rdu, sizeof(rdu)); | |
25888 | + if (unlikely(e)) { | |
25889 | + err = -EFAULT; | |
25890 | + AuTraceErr(err); | |
25891 | + } | |
25892 | + break; | |
25893 | + case AUFS_CTL_RDU_INO: | |
25894 | + err = au_rdu_ino(file, &rdu); | |
25895 | + break; | |
25896 | + | |
25897 | + default: | |
25898 | + /* err = -ENOTTY; */ | |
25899 | + err = -EINVAL; | |
25900 | + } | |
25901 | + | |
4f0767ce | 25902 | +out: |
b752ccd1 AM |
25903 | + AuTraceErr(err); |
25904 | + return err; | |
25905 | +} | |
25906 | +#endif | |
7f207e10 AM |
25907 | diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h |
25908 | --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 25909 | +++ linux/fs/aufs/rwsem.h 2015-09-24 10:47:58.254719746 +0200 |
076b876e | 25910 | @@ -0,0 +1,191 @@ |
1facf9fc | 25911 | +/* |
2000de60 | 25912 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 25913 | + * |
25914 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25915 | + * it under the terms of the GNU General Public License as published by | |
25916 | + * the Free Software Foundation; either version 2 of the License, or | |
25917 | + * (at your option) any later version. | |
dece6358 AM |
25918 | + * |
25919 | + * This program is distributed in the hope that it will be useful, | |
25920 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25921 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25922 | + * GNU General Public License for more details. | |
25923 | + * | |
25924 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25925 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25926 | + */ |
25927 | + | |
25928 | +/* | |
25929 | + * simple read-write semaphore wrappers | |
25930 | + */ | |
25931 | + | |
25932 | +#ifndef __AUFS_RWSEM_H__ | |
25933 | +#define __AUFS_RWSEM_H__ | |
25934 | + | |
25935 | +#ifdef __KERNEL__ | |
25936 | + | |
4a4d8108 | 25937 | +#include "debug.h" |
dece6358 AM |
25938 | + |
25939 | +struct au_rwsem { | |
25940 | + struct rw_semaphore rwsem; | |
25941 | +#ifdef CONFIG_AUFS_DEBUG | |
25942 | + /* just for debugging, not almighty counter */ | |
25943 | + atomic_t rcnt, wcnt; | |
25944 | +#endif | |
25945 | +}; | |
25946 | + | |
25947 | +#ifdef CONFIG_AUFS_DEBUG | |
25948 | +#define AuDbgCntInit(rw) do { \ | |
25949 | + atomic_set(&(rw)->rcnt, 0); \ | |
25950 | + atomic_set(&(rw)->wcnt, 0); \ | |
25951 | + smp_mb(); /* atomic set */ \ | |
25952 | +} while (0) | |
25953 | + | |
e49829fe | 25954 | +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt) |
dece6358 | 25955 | +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0) |
e49829fe | 25956 | +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt) |
dece6358 AM |
25957 | +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0) |
25958 | +#else | |
25959 | +#define AuDbgCntInit(rw) do {} while (0) | |
25960 | +#define AuDbgRcntInc(rw) do {} while (0) | |
25961 | +#define AuDbgRcntDec(rw) do {} while (0) | |
25962 | +#define AuDbgWcntInc(rw) do {} while (0) | |
25963 | +#define AuDbgWcntDec(rw) do {} while (0) | |
25964 | +#endif /* CONFIG_AUFS_DEBUG */ | |
25965 | + | |
25966 | +/* to debug easier, do not make them inlined functions */ | |
25967 | +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list)) | |
25968 | +/* rwsem_is_locked() is unusable */ | |
25969 | +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0) | |
25970 | +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0) | |
25971 | +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \ | |
25972 | + && atomic_read(&(rw)->wcnt) <= 0) | |
25973 | +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \ | |
25974 | + || atomic_read(&(rw)->wcnt)) | |
25975 | + | |
e49829fe JR |
25976 | +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key) |
25977 | + | |
dece6358 AM |
25978 | +static inline void au_rw_init(struct au_rwsem *rw) |
25979 | +{ | |
25980 | + AuDbgCntInit(rw); | |
25981 | + init_rwsem(&rw->rwsem); | |
25982 | +} | |
25983 | + | |
25984 | +static inline void au_rw_init_wlock(struct au_rwsem *rw) | |
25985 | +{ | |
25986 | + au_rw_init(rw); | |
25987 | + down_write(&rw->rwsem); | |
25988 | + AuDbgWcntInc(rw); | |
25989 | +} | |
25990 | + | |
25991 | +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw, | |
25992 | + unsigned int lsc) | |
25993 | +{ | |
25994 | + au_rw_init(rw); | |
25995 | + down_write_nested(&rw->rwsem, lsc); | |
25996 | + AuDbgWcntInc(rw); | |
25997 | +} | |
25998 | + | |
25999 | +static inline void au_rw_read_lock(struct au_rwsem *rw) | |
26000 | +{ | |
26001 | + down_read(&rw->rwsem); | |
26002 | + AuDbgRcntInc(rw); | |
26003 | +} | |
26004 | + | |
26005 | +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc) | |
26006 | +{ | |
26007 | + down_read_nested(&rw->rwsem, lsc); | |
26008 | + AuDbgRcntInc(rw); | |
26009 | +} | |
26010 | + | |
26011 | +static inline void au_rw_read_unlock(struct au_rwsem *rw) | |
26012 | +{ | |
26013 | + AuRwMustReadLock(rw); | |
26014 | + AuDbgRcntDec(rw); | |
26015 | + up_read(&rw->rwsem); | |
26016 | +} | |
26017 | + | |
26018 | +static inline void au_rw_dgrade_lock(struct au_rwsem *rw) | |
26019 | +{ | |
26020 | + AuRwMustWriteLock(rw); | |
26021 | + AuDbgRcntInc(rw); | |
26022 | + AuDbgWcntDec(rw); | |
26023 | + downgrade_write(&rw->rwsem); | |
26024 | +} | |
26025 | + | |
26026 | +static inline void au_rw_write_lock(struct au_rwsem *rw) | |
26027 | +{ | |
26028 | + down_write(&rw->rwsem); | |
26029 | + AuDbgWcntInc(rw); | |
26030 | +} | |
26031 | + | |
26032 | +static inline void au_rw_write_lock_nested(struct au_rwsem *rw, | |
26033 | + unsigned int lsc) | |
26034 | +{ | |
26035 | + down_write_nested(&rw->rwsem, lsc); | |
26036 | + AuDbgWcntInc(rw); | |
26037 | +} | |
1facf9fc | 26038 | + |
dece6358 AM |
26039 | +static inline void au_rw_write_unlock(struct au_rwsem *rw) |
26040 | +{ | |
26041 | + AuRwMustWriteLock(rw); | |
26042 | + AuDbgWcntDec(rw); | |
26043 | + up_write(&rw->rwsem); | |
26044 | +} | |
26045 | + | |
26046 | +/* why is not _nested version defined */ | |
26047 | +static inline int au_rw_read_trylock(struct au_rwsem *rw) | |
26048 | +{ | |
076b876e AM |
26049 | + int ret; |
26050 | + | |
26051 | + ret = down_read_trylock(&rw->rwsem); | |
dece6358 AM |
26052 | + if (ret) |
26053 | + AuDbgRcntInc(rw); | |
26054 | + return ret; | |
26055 | +} | |
26056 | + | |
26057 | +static inline int au_rw_write_trylock(struct au_rwsem *rw) | |
26058 | +{ | |
076b876e AM |
26059 | + int ret; |
26060 | + | |
26061 | + ret = down_write_trylock(&rw->rwsem); | |
dece6358 AM |
26062 | + if (ret) |
26063 | + AuDbgWcntInc(rw); | |
26064 | + return ret; | |
26065 | +} | |
26066 | + | |
26067 | +#undef AuDbgCntInit | |
26068 | +#undef AuDbgRcntInc | |
26069 | +#undef AuDbgRcntDec | |
26070 | +#undef AuDbgWcntInc | |
26071 | +#undef AuDbgWcntDec | |
1facf9fc | 26072 | + |
26073 | +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
26074 | +static inline void prefix##_read_lock(param) \ | |
dece6358 | 26075 | +{ au_rw_read_lock(rwsem); } \ |
1facf9fc | 26076 | +static inline void prefix##_write_lock(param) \ |
dece6358 | 26077 | +{ au_rw_write_lock(rwsem); } \ |
1facf9fc | 26078 | +static inline int prefix##_read_trylock(param) \ |
dece6358 | 26079 | +{ return au_rw_read_trylock(rwsem); } \ |
1facf9fc | 26080 | +static inline int prefix##_write_trylock(param) \ |
dece6358 | 26081 | +{ return au_rw_write_trylock(rwsem); } |
1facf9fc | 26082 | +/* why is not _nested version defined */ |
26083 | +/* static inline void prefix##_read_trylock_nested(param, lsc) | |
dece6358 | 26084 | +{ au_rw_read_trylock_nested(rwsem, lsc)); } |
1facf9fc | 26085 | +static inline void prefix##_write_trylock_nestd(param, lsc) |
dece6358 | 26086 | +{ au_rw_write_trylock_nested(rwsem, lsc); } */ |
1facf9fc | 26087 | + |
26088 | +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \ | |
26089 | +static inline void prefix##_read_unlock(param) \ | |
dece6358 | 26090 | +{ au_rw_read_unlock(rwsem); } \ |
1facf9fc | 26091 | +static inline void prefix##_write_unlock(param) \ |
dece6358 | 26092 | +{ au_rw_write_unlock(rwsem); } \ |
1facf9fc | 26093 | +static inline void prefix##_downgrade_lock(param) \ |
dece6358 | 26094 | +{ au_rw_dgrade_lock(rwsem); } |
1facf9fc | 26095 | + |
26096 | +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \ | |
26097 | + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
26098 | + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) | |
26099 | + | |
26100 | +#endif /* __KERNEL__ */ | |
26101 | +#endif /* __AUFS_RWSEM_H__ */ | |
7f207e10 AM |
26102 | diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c |
26103 | --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c AM |
26104 | +++ linux/fs/aufs/sbinfo.c 2015-09-24 10:47:58.254719746 +0200 |
26105 | @@ -0,0 +1,360 @@ | |
1facf9fc | 26106 | +/* |
2000de60 | 26107 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 26108 | + * |
26109 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26110 | + * it under the terms of the GNU General Public License as published by | |
26111 | + * the Free Software Foundation; either version 2 of the License, or | |
26112 | + * (at your option) any later version. | |
dece6358 AM |
26113 | + * |
26114 | + * This program is distributed in the hope that it will be useful, | |
26115 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26116 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26117 | + * GNU General Public License for more details. | |
26118 | + * | |
26119 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26120 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26121 | + */ |
26122 | + | |
26123 | +/* | |
26124 | + * superblock private data | |
26125 | + */ | |
26126 | + | |
26127 | +#include "aufs.h" | |
26128 | + | |
26129 | +/* | |
26130 | + * they are necessary regardless sysfs is disabled. | |
26131 | + */ | |
26132 | +void au_si_free(struct kobject *kobj) | |
26133 | +{ | |
86dc4139 | 26134 | + int i; |
1facf9fc | 26135 | + struct au_sbinfo *sbinfo; |
b752ccd1 | 26136 | + char *locked __maybe_unused; /* debug only */ |
1facf9fc | 26137 | + |
26138 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
86dc4139 AM |
26139 | + for (i = 0; i < AuPlink_NHASH; i++) |
26140 | + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head)); | |
e49829fe | 26141 | + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len)); |
1facf9fc | 26142 | + |
c2c0f25c AM |
26143 | + AuDebugOn(!hlist_empty(&sbinfo->si_symlink.head)); |
26144 | + | |
e49829fe | 26145 | + au_rw_write_lock(&sbinfo->si_rwsem); |
1facf9fc | 26146 | + au_br_free(sbinfo); |
e49829fe | 26147 | + au_rw_write_unlock(&sbinfo->si_rwsem); |
b752ccd1 AM |
26148 | + |
26149 | + AuDebugOn(radix_tree_gang_lookup | |
26150 | + (&sbinfo->au_si_pid.tree, (void **)&locked, | |
26151 | + /*first_index*/PID_MAX_DEFAULT - 1, | |
26152 | + /*max_items*/sizeof(locked)/sizeof(*locked))); | |
26153 | + | |
1facf9fc | 26154 | + kfree(sbinfo->si_branch); |
b752ccd1 | 26155 | + kfree(sbinfo->au_si_pid.bitmap); |
1facf9fc | 26156 | + mutex_destroy(&sbinfo->si_xib_mtx); |
dece6358 | 26157 | + AuRwDestroy(&sbinfo->si_rwsem); |
1facf9fc | 26158 | + |
26159 | + kfree(sbinfo); | |
26160 | +} | |
26161 | + | |
26162 | +int au_si_alloc(struct super_block *sb) | |
26163 | +{ | |
86dc4139 | 26164 | + int err, i; |
1facf9fc | 26165 | + struct au_sbinfo *sbinfo; |
e49829fe | 26166 | + static struct lock_class_key aufs_si; |
1facf9fc | 26167 | + |
26168 | + err = -ENOMEM; | |
4a4d8108 | 26169 | + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS); |
1facf9fc | 26170 | + if (unlikely(!sbinfo)) |
26171 | + goto out; | |
26172 | + | |
b752ccd1 AM |
26173 | + BUILD_BUG_ON(sizeof(unsigned long) != |
26174 | + sizeof(*sbinfo->au_si_pid.bitmap)); | |
26175 | + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT), | |
26176 | + sizeof(*sbinfo->au_si_pid.bitmap), | |
26177 | + GFP_NOFS); | |
26178 | + if (unlikely(!sbinfo->au_si_pid.bitmap)) | |
26179 | + goto out_sbinfo; | |
26180 | + | |
1facf9fc | 26181 | + /* will be reallocated separately */ |
26182 | + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS); | |
26183 | + if (unlikely(!sbinfo->si_branch)) | |
b752ccd1 | 26184 | + goto out_pidmap; |
1facf9fc | 26185 | + |
1facf9fc | 26186 | + err = sysaufs_si_init(sbinfo); |
26187 | + if (unlikely(err)) | |
26188 | + goto out_br; | |
26189 | + | |
26190 | + au_nwt_init(&sbinfo->si_nowait); | |
dece6358 | 26191 | + au_rw_init_wlock(&sbinfo->si_rwsem); |
e49829fe | 26192 | + au_rw_class(&sbinfo->si_rwsem, &aufs_si); |
b752ccd1 AM |
26193 | + spin_lock_init(&sbinfo->au_si_pid.tree_lock); |
26194 | + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL); | |
26195 | + | |
7f207e10 | 26196 | + atomic_long_set(&sbinfo->si_ninodes, 0); |
7f207e10 AM |
26197 | + atomic_long_set(&sbinfo->si_nfiles, 0); |
26198 | + | |
1facf9fc | 26199 | + sbinfo->si_bend = -1; |
392086de | 26200 | + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2; |
1facf9fc | 26201 | + |
26202 | + sbinfo->si_wbr_copyup = AuWbrCopyup_Def; | |
26203 | + sbinfo->si_wbr_create = AuWbrCreate_Def; | |
4a4d8108 AM |
26204 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup; |
26205 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create; | |
1facf9fc | 26206 | + |
076b876e AM |
26207 | + au_fhsm_init(sbinfo); |
26208 | + | |
e49829fe | 26209 | + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def); |
1facf9fc | 26210 | + |
c2c0f25c AM |
26211 | + au_sphl_init(&sbinfo->si_symlink); |
26212 | + | |
392086de AM |
26213 | + sbinfo->si_xino_jiffy = jiffies; |
26214 | + sbinfo->si_xino_expire | |
26215 | + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC); | |
1facf9fc | 26216 | + mutex_init(&sbinfo->si_xib_mtx); |
1facf9fc | 26217 | + sbinfo->si_xino_brid = -1; |
26218 | + /* leave si_xib_last_pindex and si_xib_next_bit */ | |
26219 | + | |
b912730e AM |
26220 | + au_sphl_init(&sbinfo->si_aopen); |
26221 | + | |
e49829fe | 26222 | + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC); |
1facf9fc | 26223 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; |
26224 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
26225 | + sbinfo->si_dirwh = AUFS_DIRWH_DEF; | |
26226 | + | |
86dc4139 AM |
26227 | + for (i = 0; i < AuPlink_NHASH; i++) |
26228 | + au_sphl_init(sbinfo->si_plink + i); | |
1facf9fc | 26229 | + init_waitqueue_head(&sbinfo->si_plink_wq); |
4a4d8108 | 26230 | + spin_lock_init(&sbinfo->si_plink_maint_lock); |
1facf9fc | 26231 | + |
523b37e3 AM |
26232 | + au_sphl_init(&sbinfo->si_files); |
26233 | + | |
1facf9fc | 26234 | + /* leave other members for sysaufs and si_mnt. */ |
26235 | + sbinfo->si_sb = sb; | |
26236 | + sb->s_fs_info = sbinfo; | |
b752ccd1 | 26237 | + si_pid_set(sb); |
1facf9fc | 26238 | + return 0; /* success */ |
26239 | + | |
4f0767ce | 26240 | +out_br: |
1facf9fc | 26241 | + kfree(sbinfo->si_branch); |
4f0767ce | 26242 | +out_pidmap: |
b752ccd1 | 26243 | + kfree(sbinfo->au_si_pid.bitmap); |
4f0767ce | 26244 | +out_sbinfo: |
1facf9fc | 26245 | + kfree(sbinfo); |
4f0767ce | 26246 | +out: |
1facf9fc | 26247 | + return err; |
26248 | +} | |
26249 | + | |
26250 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr) | |
26251 | +{ | |
26252 | + int err, sz; | |
26253 | + struct au_branch **brp; | |
26254 | + | |
dece6358 AM |
26255 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
26256 | + | |
1facf9fc | 26257 | + err = -ENOMEM; |
26258 | + sz = sizeof(*brp) * (sbinfo->si_bend + 1); | |
26259 | + if (unlikely(!sz)) | |
26260 | + sz = sizeof(*brp); | |
26261 | + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS); | |
26262 | + if (brp) { | |
26263 | + sbinfo->si_branch = brp; | |
26264 | + err = 0; | |
26265 | + } | |
26266 | + | |
26267 | + return err; | |
26268 | +} | |
26269 | + | |
26270 | +/* ---------------------------------------------------------------------- */ | |
26271 | + | |
26272 | +unsigned int au_sigen_inc(struct super_block *sb) | |
26273 | +{ | |
26274 | + unsigned int gen; | |
5527c038 | 26275 | + struct inode *inode; |
1facf9fc | 26276 | + |
dece6358 AM |
26277 | + SiMustWriteLock(sb); |
26278 | + | |
1facf9fc | 26279 | + gen = ++au_sbi(sb)->si_generation; |
26280 | + au_update_digen(sb->s_root); | |
5527c038 JR |
26281 | + inode = d_inode(sb->s_root); |
26282 | + au_update_iigen(inode, /*half*/0); | |
26283 | + inode->i_version++; | |
1facf9fc | 26284 | + return gen; |
26285 | +} | |
26286 | + | |
26287 | +aufs_bindex_t au_new_br_id(struct super_block *sb) | |
26288 | +{ | |
26289 | + aufs_bindex_t br_id; | |
26290 | + int i; | |
26291 | + struct au_sbinfo *sbinfo; | |
26292 | + | |
dece6358 AM |
26293 | + SiMustWriteLock(sb); |
26294 | + | |
1facf9fc | 26295 | + sbinfo = au_sbi(sb); |
26296 | + for (i = 0; i <= AUFS_BRANCH_MAX; i++) { | |
26297 | + br_id = ++sbinfo->si_last_br_id; | |
7f207e10 | 26298 | + AuDebugOn(br_id < 0); |
1facf9fc | 26299 | + if (br_id && au_br_index(sb, br_id) < 0) |
26300 | + return br_id; | |
26301 | + } | |
26302 | + | |
26303 | + return -1; | |
26304 | +} | |
26305 | + | |
26306 | +/* ---------------------------------------------------------------------- */ | |
26307 | + | |
e49829fe JR |
26308 | +/* it is ok that new 'nwt' tasks are appended while we are sleeping */ |
26309 | +int si_read_lock(struct super_block *sb, int flags) | |
26310 | +{ | |
26311 | + int err; | |
26312 | + | |
26313 | + err = 0; | |
26314 | + if (au_ftest_lock(flags, FLUSH)) | |
26315 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
26316 | + | |
26317 | + si_noflush_read_lock(sb); | |
26318 | + err = au_plink_maint(sb, flags); | |
26319 | + if (unlikely(err)) | |
26320 | + si_read_unlock(sb); | |
26321 | + | |
26322 | + return err; | |
26323 | +} | |
26324 | + | |
26325 | +int si_write_lock(struct super_block *sb, int flags) | |
26326 | +{ | |
26327 | + int err; | |
26328 | + | |
26329 | + if (au_ftest_lock(flags, FLUSH)) | |
26330 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
26331 | + | |
26332 | + si_noflush_write_lock(sb); | |
26333 | + err = au_plink_maint(sb, flags); | |
26334 | + if (unlikely(err)) | |
26335 | + si_write_unlock(sb); | |
26336 | + | |
26337 | + return err; | |
26338 | +} | |
26339 | + | |
1facf9fc | 26340 | +/* dentry and super_block lock. call at entry point */ |
e49829fe | 26341 | +int aufs_read_lock(struct dentry *dentry, int flags) |
1facf9fc | 26342 | +{ |
e49829fe | 26343 | + int err; |
027c5e7a | 26344 | + struct super_block *sb; |
e49829fe | 26345 | + |
027c5e7a AM |
26346 | + sb = dentry->d_sb; |
26347 | + err = si_read_lock(sb, flags); | |
26348 | + if (unlikely(err)) | |
26349 | + goto out; | |
26350 | + | |
26351 | + if (au_ftest_lock(flags, DW)) | |
26352 | + di_write_lock_child(dentry); | |
26353 | + else | |
26354 | + di_read_lock_child(dentry, flags); | |
26355 | + | |
26356 | + if (au_ftest_lock(flags, GEN)) { | |
26357 | + err = au_digen_test(dentry, au_sigen(sb)); | |
26358 | + AuDebugOn(!err && au_dbrange_test(dentry)); | |
26359 | + if (unlikely(err)) | |
26360 | + aufs_read_unlock(dentry, flags); | |
e49829fe JR |
26361 | + } |
26362 | + | |
027c5e7a | 26363 | +out: |
e49829fe | 26364 | + return err; |
1facf9fc | 26365 | +} |
26366 | + | |
26367 | +void aufs_read_unlock(struct dentry *dentry, int flags) | |
26368 | +{ | |
26369 | + if (au_ftest_lock(flags, DW)) | |
26370 | + di_write_unlock(dentry); | |
26371 | + else | |
26372 | + di_read_unlock(dentry, flags); | |
26373 | + si_read_unlock(dentry->d_sb); | |
26374 | +} | |
26375 | + | |
26376 | +void aufs_write_lock(struct dentry *dentry) | |
26377 | +{ | |
e49829fe | 26378 | + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW); |
1facf9fc | 26379 | + di_write_lock_child(dentry); |
26380 | +} | |
26381 | + | |
26382 | +void aufs_write_unlock(struct dentry *dentry) | |
26383 | +{ | |
26384 | + di_write_unlock(dentry); | |
26385 | + si_write_unlock(dentry->d_sb); | |
26386 | +} | |
26387 | + | |
e49829fe | 26388 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags) |
1facf9fc | 26389 | +{ |
e49829fe | 26390 | + int err; |
027c5e7a AM |
26391 | + unsigned int sigen; |
26392 | + struct super_block *sb; | |
e49829fe | 26393 | + |
027c5e7a AM |
26394 | + sb = d1->d_sb; |
26395 | + err = si_read_lock(sb, flags); | |
26396 | + if (unlikely(err)) | |
26397 | + goto out; | |
26398 | + | |
26399 | + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR)); | |
26400 | + | |
26401 | + if (au_ftest_lock(flags, GEN)) { | |
26402 | + sigen = au_sigen(sb); | |
26403 | + err = au_digen_test(d1, sigen); | |
26404 | + AuDebugOn(!err && au_dbrange_test(d1)); | |
26405 | + if (!err) { | |
26406 | + err = au_digen_test(d2, sigen); | |
26407 | + AuDebugOn(!err && au_dbrange_test(d2)); | |
26408 | + } | |
26409 | + if (unlikely(err)) | |
26410 | + aufs_read_and_write_unlock2(d1, d2); | |
26411 | + } | |
26412 | + | |
26413 | +out: | |
e49829fe | 26414 | + return err; |
1facf9fc | 26415 | +} |
26416 | + | |
26417 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2) | |
26418 | +{ | |
26419 | + di_write_unlock2(d1, d2); | |
26420 | + si_read_unlock(d1->d_sb); | |
26421 | +} | |
b752ccd1 AM |
26422 | + |
26423 | +/* ---------------------------------------------------------------------- */ | |
26424 | + | |
26425 | +int si_pid_test_slow(struct super_block *sb) | |
26426 | +{ | |
26427 | + void *p; | |
26428 | + | |
26429 | + rcu_read_lock(); | |
26430 | + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid); | |
26431 | + rcu_read_unlock(); | |
26432 | + | |
027c5e7a | 26433 | + return (long)!!p; |
b752ccd1 AM |
26434 | +} |
26435 | + | |
26436 | +void si_pid_set_slow(struct super_block *sb) | |
26437 | +{ | |
26438 | + int err; | |
26439 | + struct au_sbinfo *sbinfo; | |
26440 | + | |
26441 | + AuDebugOn(si_pid_test_slow(sb)); | |
26442 | + | |
26443 | + sbinfo = au_sbi(sb); | |
26444 | + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL); | |
26445 | + AuDebugOn(err); | |
26446 | + spin_lock(&sbinfo->au_si_pid.tree_lock); | |
26447 | + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid, | |
027c5e7a | 26448 | + /*any valid ptr*/sb); |
b752ccd1 AM |
26449 | + spin_unlock(&sbinfo->au_si_pid.tree_lock); |
26450 | + AuDebugOn(err); | |
26451 | + radix_tree_preload_end(); | |
26452 | +} | |
26453 | + | |
26454 | +void si_pid_clr_slow(struct super_block *sb) | |
26455 | +{ | |
26456 | + void *p; | |
26457 | + struct au_sbinfo *sbinfo; | |
26458 | + | |
26459 | + AuDebugOn(!si_pid_test_slow(sb)); | |
26460 | + | |
26461 | + sbinfo = au_sbi(sb); | |
26462 | + spin_lock(&sbinfo->au_si_pid.tree_lock); | |
26463 | + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid); | |
26464 | + spin_unlock(&sbinfo->au_si_pid.tree_lock); | |
b752ccd1 | 26465 | +} |
7f207e10 AM |
26466 | diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h |
26467 | --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 26468 | +++ linux/fs/aufs/spl.h 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 26469 | @@ -0,0 +1,111 @@ |
1facf9fc | 26470 | +/* |
2000de60 | 26471 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 26472 | + * |
26473 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26474 | + * it under the terms of the GNU General Public License as published by | |
26475 | + * the Free Software Foundation; either version 2 of the License, or | |
26476 | + * (at your option) any later version. | |
dece6358 AM |
26477 | + * |
26478 | + * This program is distributed in the hope that it will be useful, | |
26479 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26480 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26481 | + * GNU General Public License for more details. | |
26482 | + * | |
26483 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26484 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26485 | + */ |
26486 | + | |
26487 | +/* | |
26488 | + * simple list protected by a spinlock | |
26489 | + */ | |
26490 | + | |
26491 | +#ifndef __AUFS_SPL_H__ | |
26492 | +#define __AUFS_SPL_H__ | |
26493 | + | |
26494 | +#ifdef __KERNEL__ | |
26495 | + | |
1facf9fc | 26496 | +struct au_splhead { |
26497 | + spinlock_t spin; | |
26498 | + struct list_head head; | |
26499 | +}; | |
26500 | + | |
26501 | +static inline void au_spl_init(struct au_splhead *spl) | |
26502 | +{ | |
26503 | + spin_lock_init(&spl->spin); | |
26504 | + INIT_LIST_HEAD(&spl->head); | |
26505 | +} | |
26506 | + | |
26507 | +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl) | |
26508 | +{ | |
26509 | + spin_lock(&spl->spin); | |
26510 | + list_add(list, &spl->head); | |
26511 | + spin_unlock(&spl->spin); | |
26512 | +} | |
26513 | + | |
26514 | +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl) | |
26515 | +{ | |
26516 | + spin_lock(&spl->spin); | |
26517 | + list_del(list); | |
26518 | + spin_unlock(&spl->spin); | |
26519 | +} | |
26520 | + | |
4a4d8108 AM |
26521 | +static inline void au_spl_del_rcu(struct list_head *list, |
26522 | + struct au_splhead *spl) | |
26523 | +{ | |
26524 | + spin_lock(&spl->spin); | |
26525 | + list_del_rcu(list); | |
26526 | + spin_unlock(&spl->spin); | |
26527 | +} | |
26528 | + | |
86dc4139 AM |
26529 | +/* ---------------------------------------------------------------------- */ |
26530 | + | |
26531 | +struct au_sphlhead { | |
26532 | + spinlock_t spin; | |
26533 | + struct hlist_head head; | |
26534 | +}; | |
26535 | + | |
26536 | +static inline void au_sphl_init(struct au_sphlhead *sphl) | |
26537 | +{ | |
26538 | + spin_lock_init(&sphl->spin); | |
26539 | + INIT_HLIST_HEAD(&sphl->head); | |
26540 | +} | |
26541 | + | |
26542 | +static inline void au_sphl_add(struct hlist_node *hlist, | |
26543 | + struct au_sphlhead *sphl) | |
26544 | +{ | |
26545 | + spin_lock(&sphl->spin); | |
26546 | + hlist_add_head(hlist, &sphl->head); | |
26547 | + spin_unlock(&sphl->spin); | |
26548 | +} | |
26549 | + | |
26550 | +static inline void au_sphl_del(struct hlist_node *hlist, | |
26551 | + struct au_sphlhead *sphl) | |
26552 | +{ | |
26553 | + spin_lock(&sphl->spin); | |
26554 | + hlist_del(hlist); | |
26555 | + spin_unlock(&sphl->spin); | |
26556 | +} | |
26557 | + | |
26558 | +static inline void au_sphl_del_rcu(struct hlist_node *hlist, | |
26559 | + struct au_sphlhead *sphl) | |
26560 | +{ | |
26561 | + spin_lock(&sphl->spin); | |
26562 | + hlist_del_rcu(hlist); | |
26563 | + spin_unlock(&sphl->spin); | |
26564 | +} | |
26565 | + | |
26566 | +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl) | |
26567 | +{ | |
26568 | + unsigned long cnt; | |
26569 | + struct hlist_node *pos; | |
26570 | + | |
26571 | + cnt = 0; | |
26572 | + spin_lock(&sphl->spin); | |
26573 | + hlist_for_each(pos, &sphl->head) | |
26574 | + cnt++; | |
26575 | + spin_unlock(&sphl->spin); | |
26576 | + return cnt; | |
26577 | +} | |
26578 | + | |
1facf9fc | 26579 | +#endif /* __KERNEL__ */ |
26580 | +#endif /* __AUFS_SPL_H__ */ | |
7f207e10 AM |
26581 | diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c |
26582 | --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 26583 | +++ linux/fs/aufs/super.c 2015-09-24 10:47:58.254719746 +0200 |
5527c038 | 26584 | @@ -0,0 +1,1004 @@ |
1facf9fc | 26585 | +/* |
2000de60 | 26586 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 26587 | + * |
26588 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26589 | + * it under the terms of the GNU General Public License as published by | |
26590 | + * the Free Software Foundation; either version 2 of the License, or | |
26591 | + * (at your option) any later version. | |
dece6358 AM |
26592 | + * |
26593 | + * This program is distributed in the hope that it will be useful, | |
26594 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26595 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26596 | + * GNU General Public License for more details. | |
26597 | + * | |
26598 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26599 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26600 | + */ |
26601 | + | |
26602 | +/* | |
26603 | + * mount and super_block operations | |
26604 | + */ | |
26605 | + | |
f6c5ef8b | 26606 | +#include <linux/mm.h> |
1facf9fc | 26607 | +#include <linux/seq_file.h> |
26608 | +#include <linux/statfs.h> | |
7f207e10 | 26609 | +#include <linux/vmalloc.h> |
1facf9fc | 26610 | +#include "aufs.h" |
26611 | + | |
26612 | +/* | |
26613 | + * super_operations | |
26614 | + */ | |
26615 | +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused) | |
26616 | +{ | |
26617 | + struct au_icntnr *c; | |
26618 | + | |
26619 | + c = au_cache_alloc_icntnr(); | |
26620 | + if (c) { | |
027c5e7a | 26621 | + au_icntnr_init(c); |
1facf9fc | 26622 | + c->vfs_inode.i_version = 1; /* sigen(sb); */ |
26623 | + c->iinfo.ii_hinode = NULL; | |
26624 | + return &c->vfs_inode; | |
26625 | + } | |
26626 | + return NULL; | |
26627 | +} | |
26628 | + | |
027c5e7a AM |
26629 | +static void aufs_destroy_inode_cb(struct rcu_head *head) |
26630 | +{ | |
26631 | + struct inode *inode = container_of(head, struct inode, i_rcu); | |
26632 | + | |
b4510431 | 26633 | + INIT_HLIST_HEAD(&inode->i_dentry); |
027c5e7a AM |
26634 | + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode)); |
26635 | +} | |
26636 | + | |
1facf9fc | 26637 | +static void aufs_destroy_inode(struct inode *inode) |
26638 | +{ | |
26639 | + au_iinfo_fin(inode); | |
027c5e7a | 26640 | + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb); |
1facf9fc | 26641 | +} |
26642 | + | |
26643 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino) | |
26644 | +{ | |
26645 | + struct inode *inode; | |
26646 | + int err; | |
26647 | + | |
26648 | + inode = iget_locked(sb, ino); | |
26649 | + if (unlikely(!inode)) { | |
26650 | + inode = ERR_PTR(-ENOMEM); | |
26651 | + goto out; | |
26652 | + } | |
26653 | + if (!(inode->i_state & I_NEW)) | |
26654 | + goto out; | |
26655 | + | |
26656 | + err = au_xigen_new(inode); | |
26657 | + if (!err) | |
26658 | + err = au_iinfo_init(inode); | |
26659 | + if (!err) | |
26660 | + inode->i_version++; | |
26661 | + else { | |
26662 | + iget_failed(inode); | |
26663 | + inode = ERR_PTR(err); | |
26664 | + } | |
26665 | + | |
4f0767ce | 26666 | +out: |
1facf9fc | 26667 | + /* never return NULL */ |
26668 | + AuDebugOn(!inode); | |
26669 | + AuTraceErrPtr(inode); | |
26670 | + return inode; | |
26671 | +} | |
26672 | + | |
26673 | +/* lock free root dinfo */ | |
26674 | +static int au_show_brs(struct seq_file *seq, struct super_block *sb) | |
26675 | +{ | |
26676 | + int err; | |
26677 | + aufs_bindex_t bindex, bend; | |
26678 | + struct path path; | |
4a4d8108 | 26679 | + struct au_hdentry *hdp; |
1facf9fc | 26680 | + struct au_branch *br; |
076b876e | 26681 | + au_br_perm_str_t perm; |
1facf9fc | 26682 | + |
26683 | + err = 0; | |
26684 | + bend = au_sbend(sb); | |
4a4d8108 | 26685 | + hdp = au_di(sb->s_root)->di_hdentry; |
1facf9fc | 26686 | + for (bindex = 0; !err && bindex <= bend; bindex++) { |
26687 | + br = au_sbr(sb, bindex); | |
86dc4139 | 26688 | + path.mnt = au_br_mnt(br); |
4a4d8108 | 26689 | + path.dentry = hdp[bindex].hd_dentry; |
1facf9fc | 26690 | + err = au_seq_path(seq, &path); |
1e00d052 | 26691 | + if (err > 0) { |
076b876e AM |
26692 | + au_optstr_br_perm(&perm, br->br_perm); |
26693 | + err = seq_printf(seq, "=%s", perm.a); | |
26694 | + if (err == -1) | |
26695 | + err = -E2BIG; | |
1e00d052 | 26696 | + } |
1facf9fc | 26697 | + if (!err && bindex != bend) |
26698 | + err = seq_putc(seq, ':'); | |
26699 | + } | |
26700 | + | |
26701 | + return err; | |
26702 | +} | |
26703 | + | |
26704 | +static void au_show_wbr_create(struct seq_file *m, int v, | |
26705 | + struct au_sbinfo *sbinfo) | |
26706 | +{ | |
26707 | + const char *pat; | |
26708 | + | |
dece6358 AM |
26709 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
26710 | + | |
c2b27bf2 | 26711 | + seq_puts(m, ",create="); |
1facf9fc | 26712 | + pat = au_optstr_wbr_create(v); |
26713 | + switch (v) { | |
26714 | + case AuWbrCreate_TDP: | |
26715 | + case AuWbrCreate_RR: | |
26716 | + case AuWbrCreate_MFS: | |
26717 | + case AuWbrCreate_PMFS: | |
c2b27bf2 | 26718 | + seq_puts(m, pat); |
1facf9fc | 26719 | + break; |
26720 | + case AuWbrCreate_MFSV: | |
26721 | + seq_printf(m, /*pat*/"mfs:%lu", | |
e49829fe JR |
26722 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26723 | + / MSEC_PER_SEC); | |
1facf9fc | 26724 | + break; |
26725 | + case AuWbrCreate_PMFSV: | |
26726 | + seq_printf(m, /*pat*/"pmfs:%lu", | |
e49829fe JR |
26727 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26728 | + / MSEC_PER_SEC); | |
1facf9fc | 26729 | + break; |
26730 | + case AuWbrCreate_MFSRR: | |
26731 | + seq_printf(m, /*pat*/"mfsrr:%llu", | |
26732 | + sbinfo->si_wbr_mfs.mfsrr_watermark); | |
26733 | + break; | |
26734 | + case AuWbrCreate_MFSRRV: | |
26735 | + seq_printf(m, /*pat*/"mfsrr:%llu:%lu", | |
26736 | + sbinfo->si_wbr_mfs.mfsrr_watermark, | |
e49829fe JR |
26737 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26738 | + / MSEC_PER_SEC); | |
1facf9fc | 26739 | + break; |
392086de AM |
26740 | + case AuWbrCreate_PMFSRR: |
26741 | + seq_printf(m, /*pat*/"pmfsrr:%llu", | |
26742 | + sbinfo->si_wbr_mfs.mfsrr_watermark); | |
26743 | + break; | |
26744 | + case AuWbrCreate_PMFSRRV: | |
26745 | + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu", | |
26746 | + sbinfo->si_wbr_mfs.mfsrr_watermark, | |
26747 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) | |
26748 | + / MSEC_PER_SEC); | |
26749 | + break; | |
1facf9fc | 26750 | + } |
26751 | +} | |
26752 | + | |
7eafdf33 | 26753 | +static int au_show_xino(struct seq_file *seq, struct super_block *sb) |
1facf9fc | 26754 | +{ |
26755 | +#ifdef CONFIG_SYSFS | |
26756 | + return 0; | |
26757 | +#else | |
26758 | + int err; | |
26759 | + const int len = sizeof(AUFS_XINO_FNAME) - 1; | |
26760 | + aufs_bindex_t bindex, brid; | |
1facf9fc | 26761 | + struct qstr *name; |
26762 | + struct file *f; | |
26763 | + struct dentry *d, *h_root; | |
4a4d8108 | 26764 | + struct au_hdentry *hdp; |
1facf9fc | 26765 | + |
dece6358 AM |
26766 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
26767 | + | |
1facf9fc | 26768 | + err = 0; |
1facf9fc | 26769 | + f = au_sbi(sb)->si_xib; |
26770 | + if (!f) | |
26771 | + goto out; | |
26772 | + | |
26773 | + /* stop printing the default xino path on the first writable branch */ | |
26774 | + h_root = NULL; | |
26775 | + brid = au_xino_brid(sb); | |
26776 | + if (brid >= 0) { | |
26777 | + bindex = au_br_index(sb, brid); | |
4a4d8108 AM |
26778 | + hdp = au_di(sb->s_root)->di_hdentry; |
26779 | + h_root = hdp[0 + bindex].hd_dentry; | |
1facf9fc | 26780 | + } |
2000de60 | 26781 | + d = f->f_path.dentry; |
1facf9fc | 26782 | + name = &d->d_name; |
26783 | + /* safe ->d_parent because the file is unlinked */ | |
26784 | + if (d->d_parent == h_root | |
26785 | + && name->len == len | |
26786 | + && !memcmp(name->name, AUFS_XINO_FNAME, len)) | |
26787 | + goto out; | |
26788 | + | |
26789 | + seq_puts(seq, ",xino="); | |
26790 | + err = au_xino_path(seq, f); | |
26791 | + | |
4f0767ce | 26792 | +out: |
1facf9fc | 26793 | + return err; |
26794 | +#endif | |
26795 | +} | |
26796 | + | |
26797 | +/* seq_file will re-call me in case of too long string */ | |
7eafdf33 | 26798 | +static int aufs_show_options(struct seq_file *m, struct dentry *dentry) |
1facf9fc | 26799 | +{ |
027c5e7a | 26800 | + int err; |
1facf9fc | 26801 | + unsigned int mnt_flags, v; |
26802 | + struct super_block *sb; | |
26803 | + struct au_sbinfo *sbinfo; | |
26804 | + | |
26805 | +#define AuBool(name, str) do { \ | |
26806 | + v = au_opt_test(mnt_flags, name); \ | |
26807 | + if (v != au_opt_test(AuOpt_Def, name)) \ | |
26808 | + seq_printf(m, ",%s" #str, v ? "" : "no"); \ | |
26809 | +} while (0) | |
26810 | + | |
26811 | +#define AuStr(name, str) do { \ | |
26812 | + v = mnt_flags & AuOptMask_##name; \ | |
26813 | + if (v != (AuOpt_Def & AuOptMask_##name)) \ | |
26814 | + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \ | |
26815 | +} while (0) | |
26816 | + | |
26817 | +#define AuUInt(name, str, val) do { \ | |
26818 | + if (val != AUFS_##name##_DEF) \ | |
26819 | + seq_printf(m, "," #str "=%u", val); \ | |
26820 | +} while (0) | |
26821 | + | |
7eafdf33 | 26822 | + sb = dentry->d_sb; |
c1595e42 JR |
26823 | + if (sb->s_flags & MS_POSIXACL) |
26824 | + seq_puts(m, ",acl"); | |
26825 | + | |
26826 | + /* lock free root dinfo */ | |
1facf9fc | 26827 | + si_noflush_read_lock(sb); |
26828 | + sbinfo = au_sbi(sb); | |
26829 | + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo)); | |
26830 | + | |
26831 | + mnt_flags = au_mntflags(sb); | |
26832 | + if (au_opt_test(mnt_flags, XINO)) { | |
7eafdf33 | 26833 | + err = au_show_xino(m, sb); |
1facf9fc | 26834 | + if (unlikely(err)) |
26835 | + goto out; | |
26836 | + } else | |
26837 | + seq_puts(m, ",noxino"); | |
26838 | + | |
26839 | + AuBool(TRUNC_XINO, trunc_xino); | |
26840 | + AuStr(UDBA, udba); | |
dece6358 | 26841 | + AuBool(SHWH, shwh); |
1facf9fc | 26842 | + AuBool(PLINK, plink); |
4a4d8108 | 26843 | + AuBool(DIO, dio); |
076b876e | 26844 | + AuBool(DIRPERM1, dirperm1); |
1facf9fc | 26845 | + |
26846 | + v = sbinfo->si_wbr_create; | |
26847 | + if (v != AuWbrCreate_Def) | |
26848 | + au_show_wbr_create(m, v, sbinfo); | |
26849 | + | |
26850 | + v = sbinfo->si_wbr_copyup; | |
26851 | + if (v != AuWbrCopyup_Def) | |
26852 | + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v)); | |
26853 | + | |
26854 | + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ); | |
26855 | + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ)) | |
26856 | + seq_printf(m, ",diropq=%c", v ? 'a' : 'w'); | |
26857 | + | |
26858 | + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh); | |
26859 | + | |
027c5e7a AM |
26860 | + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC; |
26861 | + AuUInt(RDCACHE, rdcache, v); | |
1facf9fc | 26862 | + |
26863 | + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk); | |
26864 | + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash); | |
26865 | + | |
076b876e AM |
26866 | + au_fhsm_show(m, sbinfo); |
26867 | + | |
1facf9fc | 26868 | + AuBool(SUM, sum); |
26869 | + /* AuBool(SUM_W, wsum); */ | |
26870 | + AuBool(WARN_PERM, warn_perm); | |
26871 | + AuBool(VERBOSE, verbose); | |
26872 | + | |
4f0767ce | 26873 | +out: |
1facf9fc | 26874 | + /* be sure to print "br:" last */ |
26875 | + if (!sysaufs_brs) { | |
26876 | + seq_puts(m, ",br:"); | |
26877 | + au_show_brs(m, sb); | |
26878 | + } | |
26879 | + si_read_unlock(sb); | |
26880 | + return 0; | |
26881 | + | |
1facf9fc | 26882 | +#undef AuBool |
26883 | +#undef AuStr | |
4a4d8108 | 26884 | +#undef AuUInt |
1facf9fc | 26885 | +} |
26886 | + | |
26887 | +/* ---------------------------------------------------------------------- */ | |
26888 | + | |
26889 | +/* sum mode which returns the summation for statfs(2) */ | |
26890 | + | |
26891 | +static u64 au_add_till_max(u64 a, u64 b) | |
26892 | +{ | |
26893 | + u64 old; | |
26894 | + | |
26895 | + old = a; | |
26896 | + a += b; | |
92d182d2 AM |
26897 | + if (old <= a) |
26898 | + return a; | |
26899 | + return ULLONG_MAX; | |
26900 | +} | |
26901 | + | |
26902 | +static u64 au_mul_till_max(u64 a, long mul) | |
26903 | +{ | |
26904 | + u64 old; | |
26905 | + | |
26906 | + old = a; | |
26907 | + a *= mul; | |
26908 | + if (old <= a) | |
1facf9fc | 26909 | + return a; |
26910 | + return ULLONG_MAX; | |
26911 | +} | |
26912 | + | |
26913 | +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf) | |
26914 | +{ | |
26915 | + int err; | |
92d182d2 | 26916 | + long bsize, factor; |
1facf9fc | 26917 | + u64 blocks, bfree, bavail, files, ffree; |
26918 | + aufs_bindex_t bend, bindex, i; | |
26919 | + unsigned char shared; | |
7f207e10 | 26920 | + struct path h_path; |
1facf9fc | 26921 | + struct super_block *h_sb; |
26922 | + | |
92d182d2 AM |
26923 | + err = 0; |
26924 | + bsize = LONG_MAX; | |
26925 | + files = 0; | |
26926 | + ffree = 0; | |
1facf9fc | 26927 | + blocks = 0; |
26928 | + bfree = 0; | |
26929 | + bavail = 0; | |
1facf9fc | 26930 | + bend = au_sbend(sb); |
92d182d2 | 26931 | + for (bindex = 0; bindex <= bend; bindex++) { |
7f207e10 AM |
26932 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
26933 | + h_sb = h_path.mnt->mnt_sb; | |
1facf9fc | 26934 | + shared = 0; |
92d182d2 | 26935 | + for (i = 0; !shared && i < bindex; i++) |
1facf9fc | 26936 | + shared = (au_sbr_sb(sb, i) == h_sb); |
26937 | + if (shared) | |
26938 | + continue; | |
26939 | + | |
26940 | + /* sb->s_root for NFS is unreliable */ | |
7f207e10 AM |
26941 | + h_path.dentry = h_path.mnt->mnt_root; |
26942 | + err = vfs_statfs(&h_path, buf); | |
1facf9fc | 26943 | + if (unlikely(err)) |
26944 | + goto out; | |
26945 | + | |
92d182d2 AM |
26946 | + if (bsize > buf->f_bsize) { |
26947 | + /* | |
26948 | + * we will reduce bsize, so we have to expand blocks | |
26949 | + * etc. to match them again | |
26950 | + */ | |
26951 | + factor = (bsize / buf->f_bsize); | |
26952 | + blocks = au_mul_till_max(blocks, factor); | |
26953 | + bfree = au_mul_till_max(bfree, factor); | |
26954 | + bavail = au_mul_till_max(bavail, factor); | |
26955 | + bsize = buf->f_bsize; | |
26956 | + } | |
26957 | + | |
26958 | + factor = (buf->f_bsize / bsize); | |
26959 | + blocks = au_add_till_max(blocks, | |
26960 | + au_mul_till_max(buf->f_blocks, factor)); | |
26961 | + bfree = au_add_till_max(bfree, | |
26962 | + au_mul_till_max(buf->f_bfree, factor)); | |
26963 | + bavail = au_add_till_max(bavail, | |
26964 | + au_mul_till_max(buf->f_bavail, factor)); | |
1facf9fc | 26965 | + files = au_add_till_max(files, buf->f_files); |
26966 | + ffree = au_add_till_max(ffree, buf->f_ffree); | |
26967 | + } | |
26968 | + | |
92d182d2 | 26969 | + buf->f_bsize = bsize; |
1facf9fc | 26970 | + buf->f_blocks = blocks; |
26971 | + buf->f_bfree = bfree; | |
26972 | + buf->f_bavail = bavail; | |
26973 | + buf->f_files = files; | |
26974 | + buf->f_ffree = ffree; | |
92d182d2 | 26975 | + buf->f_frsize = 0; |
1facf9fc | 26976 | + |
4f0767ce | 26977 | +out: |
1facf9fc | 26978 | + return err; |
26979 | +} | |
26980 | + | |
26981 | +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf) | |
26982 | +{ | |
26983 | + int err; | |
7f207e10 | 26984 | + struct path h_path; |
1facf9fc | 26985 | + struct super_block *sb; |
26986 | + | |
26987 | + /* lock free root dinfo */ | |
26988 | + sb = dentry->d_sb; | |
26989 | + si_noflush_read_lock(sb); | |
7f207e10 | 26990 | + if (!au_opt_test(au_mntflags(sb), SUM)) { |
1facf9fc | 26991 | + /* sb->s_root for NFS is unreliable */ |
7f207e10 AM |
26992 | + h_path.mnt = au_sbr_mnt(sb, 0); |
26993 | + h_path.dentry = h_path.mnt->mnt_root; | |
26994 | + err = vfs_statfs(&h_path, buf); | |
26995 | + } else | |
1facf9fc | 26996 | + err = au_statfs_sum(sb, buf); |
26997 | + si_read_unlock(sb); | |
26998 | + | |
26999 | + if (!err) { | |
27000 | + buf->f_type = AUFS_SUPER_MAGIC; | |
4a4d8108 | 27001 | + buf->f_namelen = AUFS_MAX_NAMELEN; |
1facf9fc | 27002 | + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid)); |
27003 | + } | |
27004 | + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */ | |
27005 | + | |
27006 | + return err; | |
27007 | +} | |
27008 | + | |
27009 | +/* ---------------------------------------------------------------------- */ | |
27010 | + | |
537831f9 AM |
27011 | +static int aufs_sync_fs(struct super_block *sb, int wait) |
27012 | +{ | |
27013 | + int err, e; | |
27014 | + aufs_bindex_t bend, bindex; | |
27015 | + struct au_branch *br; | |
27016 | + struct super_block *h_sb; | |
27017 | + | |
27018 | + err = 0; | |
27019 | + si_noflush_read_lock(sb); | |
27020 | + bend = au_sbend(sb); | |
27021 | + for (bindex = 0; bindex <= bend; bindex++) { | |
27022 | + br = au_sbr(sb, bindex); | |
27023 | + if (!au_br_writable(br->br_perm)) | |
27024 | + continue; | |
27025 | + | |
27026 | + h_sb = au_sbr_sb(sb, bindex); | |
27027 | + if (h_sb->s_op->sync_fs) { | |
27028 | + e = h_sb->s_op->sync_fs(h_sb, wait); | |
27029 | + if (unlikely(e && !err)) | |
27030 | + err = e; | |
27031 | + /* go on even if an error happens */ | |
27032 | + } | |
27033 | + } | |
27034 | + si_read_unlock(sb); | |
27035 | + | |
27036 | + return err; | |
27037 | +} | |
27038 | + | |
27039 | +/* ---------------------------------------------------------------------- */ | |
27040 | + | |
1facf9fc | 27041 | +/* final actions when unmounting a file system */ |
27042 | +static void aufs_put_super(struct super_block *sb) | |
27043 | +{ | |
27044 | + struct au_sbinfo *sbinfo; | |
27045 | + | |
27046 | + sbinfo = au_sbi(sb); | |
27047 | + if (!sbinfo) | |
27048 | + return; | |
27049 | + | |
1facf9fc | 27050 | + dbgaufs_si_fin(sbinfo); |
27051 | + kobject_put(&sbinfo->si_kobj); | |
27052 | +} | |
27053 | + | |
27054 | +/* ---------------------------------------------------------------------- */ | |
27055 | + | |
7f207e10 AM |
27056 | +void au_array_free(void *array) |
27057 | +{ | |
27058 | + if (array) { | |
27059 | + if (!is_vmalloc_addr(array)) | |
27060 | + kfree(array); | |
27061 | + else | |
27062 | + vfree(array); | |
27063 | + } | |
27064 | +} | |
27065 | + | |
27066 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg) | |
27067 | +{ | |
27068 | + void *array; | |
076b876e | 27069 | + unsigned long long n, sz; |
7f207e10 AM |
27070 | + |
27071 | + array = NULL; | |
27072 | + n = 0; | |
27073 | + if (!*hint) | |
27074 | + goto out; | |
27075 | + | |
27076 | + if (*hint > ULLONG_MAX / sizeof(array)) { | |
27077 | + array = ERR_PTR(-EMFILE); | |
27078 | + pr_err("hint %llu\n", *hint); | |
27079 | + goto out; | |
27080 | + } | |
27081 | + | |
076b876e AM |
27082 | + sz = sizeof(array) * *hint; |
27083 | + array = kzalloc(sz, GFP_NOFS); | |
7f207e10 | 27084 | + if (unlikely(!array)) |
076b876e | 27085 | + array = vzalloc(sz); |
7f207e10 AM |
27086 | + if (unlikely(!array)) { |
27087 | + array = ERR_PTR(-ENOMEM); | |
27088 | + goto out; | |
27089 | + } | |
27090 | + | |
27091 | + n = cb(array, *hint, arg); | |
27092 | + AuDebugOn(n > *hint); | |
27093 | + | |
27094 | +out: | |
27095 | + *hint = n; | |
27096 | + return array; | |
27097 | +} | |
27098 | + | |
27099 | +static unsigned long long au_iarray_cb(void *a, | |
27100 | + unsigned long long max __maybe_unused, | |
27101 | + void *arg) | |
27102 | +{ | |
27103 | + unsigned long long n; | |
27104 | + struct inode **p, *inode; | |
27105 | + struct list_head *head; | |
27106 | + | |
27107 | + n = 0; | |
27108 | + p = a; | |
27109 | + head = arg; | |
2cbb1c4b | 27110 | + spin_lock(&inode_sb_list_lock); |
7f207e10 AM |
27111 | + list_for_each_entry(inode, head, i_sb_list) { |
27112 | + if (!is_bad_inode(inode) | |
27113 | + && au_ii(inode)->ii_bstart >= 0) { | |
2cbb1c4b JR |
27114 | + spin_lock(&inode->i_lock); |
27115 | + if (atomic_read(&inode->i_count)) { | |
27116 | + au_igrab(inode); | |
27117 | + *p++ = inode; | |
27118 | + n++; | |
27119 | + AuDebugOn(n > max); | |
27120 | + } | |
27121 | + spin_unlock(&inode->i_lock); | |
7f207e10 AM |
27122 | + } |
27123 | + } | |
2cbb1c4b | 27124 | + spin_unlock(&inode_sb_list_lock); |
7f207e10 AM |
27125 | + |
27126 | + return n; | |
27127 | +} | |
27128 | + | |
27129 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max) | |
27130 | +{ | |
27131 | + *max = atomic_long_read(&au_sbi(sb)->si_ninodes); | |
27132 | + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes); | |
27133 | +} | |
27134 | + | |
27135 | +void au_iarray_free(struct inode **a, unsigned long long max) | |
27136 | +{ | |
27137 | + unsigned long long ull; | |
27138 | + | |
27139 | + for (ull = 0; ull < max; ull++) | |
27140 | + iput(a[ull]); | |
27141 | + au_array_free(a); | |
27142 | +} | |
27143 | + | |
27144 | +/* ---------------------------------------------------------------------- */ | |
27145 | + | |
1facf9fc | 27146 | +/* |
27147 | + * refresh dentry and inode at remount time. | |
27148 | + */ | |
027c5e7a AM |
27149 | +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */ |
27150 | +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags, | |
27151 | + struct dentry *parent) | |
1facf9fc | 27152 | +{ |
27153 | + int err; | |
1facf9fc | 27154 | + |
27155 | + di_write_lock_child(dentry); | |
1facf9fc | 27156 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a AM |
27157 | + err = au_refresh_dentry(dentry, parent); |
27158 | + if (!err && dir_flags) | |
5527c038 | 27159 | + au_hn_reset(d_inode(dentry), dir_flags); |
1facf9fc | 27160 | + di_read_unlock(parent, AuLock_IR); |
1facf9fc | 27161 | + di_write_unlock(dentry); |
27162 | + | |
27163 | + return err; | |
27164 | +} | |
27165 | + | |
027c5e7a AM |
27166 | +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen, |
27167 | + struct au_sbinfo *sbinfo, | |
27168 | + const unsigned int dir_flags) | |
1facf9fc | 27169 | +{ |
027c5e7a AM |
27170 | + int err; |
27171 | + struct dentry *parent; | |
027c5e7a AM |
27172 | + |
27173 | + err = 0; | |
27174 | + parent = dget_parent(dentry); | |
27175 | + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) { | |
5527c038 JR |
27176 | + if (d_really_is_positive(dentry)) { |
27177 | + if (!d_is_dir(dentry)) | |
027c5e7a AM |
27178 | + err = au_do_refresh(dentry, /*dir_flags*/0, |
27179 | + parent); | |
27180 | + else { | |
27181 | + err = au_do_refresh(dentry, dir_flags, parent); | |
27182 | + if (unlikely(err)) | |
27183 | + au_fset_si(sbinfo, FAILED_REFRESH_DIR); | |
27184 | + } | |
27185 | + } else | |
27186 | + err = au_do_refresh(dentry, /*dir_flags*/0, parent); | |
27187 | + AuDbgDentry(dentry); | |
27188 | + } | |
27189 | + dput(parent); | |
27190 | + | |
27191 | + AuTraceErr(err); | |
27192 | + return err; | |
1facf9fc | 27193 | +} |
27194 | + | |
027c5e7a | 27195 | +static int au_refresh_d(struct super_block *sb) |
1facf9fc | 27196 | +{ |
27197 | + int err, i, j, ndentry, e; | |
027c5e7a | 27198 | + unsigned int sigen; |
1facf9fc | 27199 | + struct au_dcsub_pages dpages; |
27200 | + struct au_dpage *dpage; | |
027c5e7a AM |
27201 | + struct dentry **dentries, *d; |
27202 | + struct au_sbinfo *sbinfo; | |
27203 | + struct dentry *root = sb->s_root; | |
5527c038 | 27204 | + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1); |
1facf9fc | 27205 | + |
027c5e7a AM |
27206 | + err = au_dpages_init(&dpages, GFP_NOFS); |
27207 | + if (unlikely(err)) | |
1facf9fc | 27208 | + goto out; |
027c5e7a AM |
27209 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); |
27210 | + if (unlikely(err)) | |
1facf9fc | 27211 | + goto out_dpages; |
1facf9fc | 27212 | + |
027c5e7a AM |
27213 | + sigen = au_sigen(sb); |
27214 | + sbinfo = au_sbi(sb); | |
27215 | + for (i = 0; i < dpages.ndpage; i++) { | |
1facf9fc | 27216 | + dpage = dpages.dpages + i; |
27217 | + dentries = dpage->dentries; | |
27218 | + ndentry = dpage->ndentry; | |
027c5e7a | 27219 | + for (j = 0; j < ndentry; j++) { |
1facf9fc | 27220 | + d = dentries[j]; |
027c5e7a AM |
27221 | + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags); |
27222 | + if (unlikely(e && !err)) | |
27223 | + err = e; | |
27224 | + /* go on even err */ | |
1facf9fc | 27225 | + } |
27226 | + } | |
27227 | + | |
4f0767ce | 27228 | +out_dpages: |
1facf9fc | 27229 | + au_dpages_free(&dpages); |
4f0767ce | 27230 | +out: |
1facf9fc | 27231 | + return err; |
27232 | +} | |
27233 | + | |
027c5e7a | 27234 | +static int au_refresh_i(struct super_block *sb) |
1facf9fc | 27235 | +{ |
027c5e7a AM |
27236 | + int err, e; |
27237 | + unsigned int sigen; | |
27238 | + unsigned long long max, ull; | |
27239 | + struct inode *inode, **array; | |
1facf9fc | 27240 | + |
027c5e7a AM |
27241 | + array = au_iarray_alloc(sb, &max); |
27242 | + err = PTR_ERR(array); | |
27243 | + if (IS_ERR(array)) | |
27244 | + goto out; | |
1facf9fc | 27245 | + |
27246 | + err = 0; | |
027c5e7a AM |
27247 | + sigen = au_sigen(sb); |
27248 | + for (ull = 0; ull < max; ull++) { | |
27249 | + inode = array[ull]; | |
076b876e AM |
27250 | + if (unlikely(!inode)) |
27251 | + break; | |
537831f9 | 27252 | + if (au_iigen(inode, NULL) != sigen) { |
1facf9fc | 27253 | + ii_write_lock_child(inode); |
027c5e7a | 27254 | + e = au_refresh_hinode_self(inode); |
1facf9fc | 27255 | + ii_write_unlock(inode); |
27256 | + if (unlikely(e)) { | |
027c5e7a | 27257 | + pr_err("error %d, i%lu\n", e, inode->i_ino); |
1facf9fc | 27258 | + if (!err) |
27259 | + err = e; | |
27260 | + /* go on even if err */ | |
27261 | + } | |
27262 | + } | |
1facf9fc | 27263 | + } |
27264 | + | |
027c5e7a | 27265 | + au_iarray_free(array, max); |
1facf9fc | 27266 | + |
4f0767ce | 27267 | +out: |
1facf9fc | 27268 | + return err; |
27269 | +} | |
27270 | + | |
027c5e7a | 27271 | +static void au_remount_refresh(struct super_block *sb) |
1facf9fc | 27272 | +{ |
027c5e7a AM |
27273 | + int err, e; |
27274 | + unsigned int udba; | |
27275 | + aufs_bindex_t bindex, bend; | |
1facf9fc | 27276 | + struct dentry *root; |
27277 | + struct inode *inode; | |
027c5e7a | 27278 | + struct au_branch *br; |
1facf9fc | 27279 | + |
27280 | + au_sigen_inc(sb); | |
027c5e7a | 27281 | + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR); |
1facf9fc | 27282 | + |
27283 | + root = sb->s_root; | |
27284 | + DiMustNoWaiters(root); | |
5527c038 | 27285 | + inode = d_inode(root); |
1facf9fc | 27286 | + IiMustNoWaiters(inode); |
1facf9fc | 27287 | + |
027c5e7a AM |
27288 | + udba = au_opt_udba(sb); |
27289 | + bend = au_sbend(sb); | |
27290 | + for (bindex = 0; bindex <= bend; bindex++) { | |
27291 | + br = au_sbr(sb, bindex); | |
27292 | + err = au_hnotify_reset_br(udba, br, br->br_perm); | |
1facf9fc | 27293 | + if (unlikely(err)) |
027c5e7a AM |
27294 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", |
27295 | + bindex, err); | |
27296 | + /* go on even if err */ | |
1facf9fc | 27297 | + } |
027c5e7a | 27298 | + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1)); |
1facf9fc | 27299 | + |
027c5e7a AM |
27300 | + di_write_unlock(root); |
27301 | + err = au_refresh_d(sb); | |
27302 | + e = au_refresh_i(sb); | |
27303 | + if (unlikely(e && !err)) | |
27304 | + err = e; | |
1facf9fc | 27305 | + /* aufs_write_lock() calls ..._child() */ |
27306 | + di_write_lock_child(root); | |
027c5e7a AM |
27307 | + |
27308 | + au_cpup_attr_all(inode, /*force*/1); | |
27309 | + | |
27310 | + if (unlikely(err)) | |
27311 | + AuIOErr("refresh failed, ignored, %d\n", err); | |
1facf9fc | 27312 | +} |
27313 | + | |
27314 | +/* stop extra interpretation of errno in mount(8), and strange error messages */ | |
27315 | +static int cvt_err(int err) | |
27316 | +{ | |
27317 | + AuTraceErr(err); | |
27318 | + | |
27319 | + switch (err) { | |
27320 | + case -ENOENT: | |
27321 | + case -ENOTDIR: | |
27322 | + case -EEXIST: | |
27323 | + case -EIO: | |
27324 | + err = -EINVAL; | |
27325 | + } | |
27326 | + return err; | |
27327 | +} | |
27328 | + | |
27329 | +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data) | |
27330 | +{ | |
4a4d8108 AM |
27331 | + int err, do_dx; |
27332 | + unsigned int mntflags; | |
1facf9fc | 27333 | + struct au_opts opts; |
27334 | + struct dentry *root; | |
27335 | + struct inode *inode; | |
27336 | + struct au_sbinfo *sbinfo; | |
27337 | + | |
27338 | + err = 0; | |
27339 | + root = sb->s_root; | |
27340 | + if (!data || !*data) { | |
e49829fe JR |
27341 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
27342 | + if (!err) { | |
27343 | + di_write_lock_child(root); | |
27344 | + err = au_opts_verify(sb, *flags, /*pending*/0); | |
27345 | + aufs_write_unlock(root); | |
27346 | + } | |
1facf9fc | 27347 | + goto out; |
27348 | + } | |
27349 | + | |
27350 | + err = -ENOMEM; | |
27351 | + memset(&opts, 0, sizeof(opts)); | |
27352 | + opts.opt = (void *)__get_free_page(GFP_NOFS); | |
27353 | + if (unlikely(!opts.opt)) | |
27354 | + goto out; | |
27355 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
27356 | + opts.flags = AuOpts_REMOUNT; | |
27357 | + opts.sb_flags = *flags; | |
27358 | + | |
27359 | + /* parse it before aufs lock */ | |
27360 | + err = au_opts_parse(sb, data, &opts); | |
27361 | + if (unlikely(err)) | |
27362 | + goto out_opts; | |
27363 | + | |
27364 | + sbinfo = au_sbi(sb); | |
5527c038 | 27365 | + inode = d_inode(root); |
1facf9fc | 27366 | + mutex_lock(&inode->i_mutex); |
e49829fe JR |
27367 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
27368 | + if (unlikely(err)) | |
27369 | + goto out_mtx; | |
27370 | + di_write_lock_child(root); | |
1facf9fc | 27371 | + |
27372 | + /* au_opts_remount() may return an error */ | |
27373 | + err = au_opts_remount(sb, &opts); | |
27374 | + au_opts_free(&opts); | |
27375 | + | |
027c5e7a AM |
27376 | + if (au_ftest_opts(opts.flags, REFRESH)) |
27377 | + au_remount_refresh(sb); | |
1facf9fc | 27378 | + |
4a4d8108 AM |
27379 | + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) { |
27380 | + mntflags = au_mntflags(sb); | |
27381 | + do_dx = !!au_opt_test(mntflags, DIO); | |
27382 | + au_dy_arefresh(do_dx); | |
27383 | + } | |
27384 | + | |
076b876e | 27385 | + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */ |
1facf9fc | 27386 | + aufs_write_unlock(root); |
953406b4 | 27387 | + |
e49829fe JR |
27388 | +out_mtx: |
27389 | + mutex_unlock(&inode->i_mutex); | |
4f0767ce | 27390 | +out_opts: |
1facf9fc | 27391 | + free_page((unsigned long)opts.opt); |
4f0767ce | 27392 | +out: |
1facf9fc | 27393 | + err = cvt_err(err); |
27394 | + AuTraceErr(err); | |
27395 | + return err; | |
27396 | +} | |
27397 | + | |
4a4d8108 | 27398 | +static const struct super_operations aufs_sop = { |
1facf9fc | 27399 | + .alloc_inode = aufs_alloc_inode, |
27400 | + .destroy_inode = aufs_destroy_inode, | |
b752ccd1 | 27401 | + /* always deleting, no clearing */ |
1facf9fc | 27402 | + .drop_inode = generic_delete_inode, |
27403 | + .show_options = aufs_show_options, | |
27404 | + .statfs = aufs_statfs, | |
27405 | + .put_super = aufs_put_super, | |
537831f9 | 27406 | + .sync_fs = aufs_sync_fs, |
1facf9fc | 27407 | + .remount_fs = aufs_remount_fs |
27408 | +}; | |
27409 | + | |
27410 | +/* ---------------------------------------------------------------------- */ | |
27411 | + | |
27412 | +static int alloc_root(struct super_block *sb) | |
27413 | +{ | |
27414 | + int err; | |
27415 | + struct inode *inode; | |
27416 | + struct dentry *root; | |
27417 | + | |
27418 | + err = -ENOMEM; | |
27419 | + inode = au_iget_locked(sb, AUFS_ROOT_INO); | |
27420 | + err = PTR_ERR(inode); | |
27421 | + if (IS_ERR(inode)) | |
27422 | + goto out; | |
27423 | + | |
27424 | + inode->i_op = &aufs_dir_iop; | |
27425 | + inode->i_fop = &aufs_dir_fop; | |
27426 | + inode->i_mode = S_IFDIR; | |
9dbd164d | 27427 | + set_nlink(inode, 2); |
1facf9fc | 27428 | + unlock_new_inode(inode); |
27429 | + | |
92d182d2 | 27430 | + root = d_make_root(inode); |
1facf9fc | 27431 | + if (unlikely(!root)) |
92d182d2 | 27432 | + goto out; |
1facf9fc | 27433 | + err = PTR_ERR(root); |
27434 | + if (IS_ERR(root)) | |
92d182d2 | 27435 | + goto out; |
1facf9fc | 27436 | + |
4a4d8108 | 27437 | + err = au_di_init(root); |
1facf9fc | 27438 | + if (!err) { |
27439 | + sb->s_root = root; | |
27440 | + return 0; /* success */ | |
27441 | + } | |
27442 | + dput(root); | |
1facf9fc | 27443 | + |
4f0767ce | 27444 | +out: |
1facf9fc | 27445 | + return err; |
1facf9fc | 27446 | +} |
27447 | + | |
27448 | +static int aufs_fill_super(struct super_block *sb, void *raw_data, | |
27449 | + int silent __maybe_unused) | |
27450 | +{ | |
27451 | + int err; | |
27452 | + struct au_opts opts; | |
27453 | + struct dentry *root; | |
27454 | + struct inode *inode; | |
27455 | + char *arg = raw_data; | |
27456 | + | |
27457 | + if (unlikely(!arg || !*arg)) { | |
27458 | + err = -EINVAL; | |
4a4d8108 | 27459 | + pr_err("no arg\n"); |
1facf9fc | 27460 | + goto out; |
27461 | + } | |
27462 | + | |
27463 | + err = -ENOMEM; | |
27464 | + memset(&opts, 0, sizeof(opts)); | |
27465 | + opts.opt = (void *)__get_free_page(GFP_NOFS); | |
27466 | + if (unlikely(!opts.opt)) | |
27467 | + goto out; | |
27468 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
27469 | + opts.sb_flags = sb->s_flags; | |
27470 | + | |
27471 | + err = au_si_alloc(sb); | |
27472 | + if (unlikely(err)) | |
27473 | + goto out_opts; | |
27474 | + | |
27475 | + /* all timestamps always follow the ones on the branch */ | |
27476 | + sb->s_flags |= MS_NOATIME | MS_NODIRATIME; | |
27477 | + sb->s_op = &aufs_sop; | |
027c5e7a | 27478 | + sb->s_d_op = &aufs_dop; |
1facf9fc | 27479 | + sb->s_magic = AUFS_SUPER_MAGIC; |
27480 | + sb->s_maxbytes = 0; | |
c1595e42 | 27481 | + sb->s_stack_depth = 1; |
1facf9fc | 27482 | + au_export_init(sb); |
c1595e42 | 27483 | + /* au_xattr_init(sb); */ |
1facf9fc | 27484 | + |
27485 | + err = alloc_root(sb); | |
27486 | + if (unlikely(err)) { | |
27487 | + si_write_unlock(sb); | |
27488 | + goto out_info; | |
27489 | + } | |
27490 | + root = sb->s_root; | |
5527c038 | 27491 | + inode = d_inode(root); |
1facf9fc | 27492 | + |
27493 | + /* | |
27494 | + * actually we can parse options regardless aufs lock here. | |
27495 | + * but at remount time, parsing must be done before aufs lock. | |
27496 | + * so we follow the same rule. | |
27497 | + */ | |
27498 | + ii_write_lock_parent(inode); | |
27499 | + aufs_write_unlock(root); | |
27500 | + err = au_opts_parse(sb, arg, &opts); | |
27501 | + if (unlikely(err)) | |
27502 | + goto out_root; | |
27503 | + | |
27504 | + /* lock vfs_inode first, then aufs. */ | |
27505 | + mutex_lock(&inode->i_mutex); | |
1facf9fc | 27506 | + aufs_write_lock(root); |
27507 | + err = au_opts_mount(sb, &opts); | |
27508 | + au_opts_free(&opts); | |
1facf9fc | 27509 | + aufs_write_unlock(root); |
27510 | + mutex_unlock(&inode->i_mutex); | |
4a4d8108 AM |
27511 | + if (!err) |
27512 | + goto out_opts; /* success */ | |
1facf9fc | 27513 | + |
4f0767ce | 27514 | +out_root: |
1facf9fc | 27515 | + dput(root); |
27516 | + sb->s_root = NULL; | |
4f0767ce | 27517 | +out_info: |
2cbb1c4b | 27518 | + dbgaufs_si_fin(au_sbi(sb)); |
1facf9fc | 27519 | + kobject_put(&au_sbi(sb)->si_kobj); |
27520 | + sb->s_fs_info = NULL; | |
4f0767ce | 27521 | +out_opts: |
1facf9fc | 27522 | + free_page((unsigned long)opts.opt); |
4f0767ce | 27523 | +out: |
1facf9fc | 27524 | + AuTraceErr(err); |
27525 | + err = cvt_err(err); | |
27526 | + AuTraceErr(err); | |
27527 | + return err; | |
27528 | +} | |
27529 | + | |
27530 | +/* ---------------------------------------------------------------------- */ | |
27531 | + | |
027c5e7a AM |
27532 | +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags, |
27533 | + const char *dev_name __maybe_unused, | |
27534 | + void *raw_data) | |
1facf9fc | 27535 | +{ |
027c5e7a | 27536 | + struct dentry *root; |
1facf9fc | 27537 | + struct super_block *sb; |
27538 | + | |
27539 | + /* all timestamps always follow the ones on the branch */ | |
27540 | + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */ | |
027c5e7a AM |
27541 | + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super); |
27542 | + if (IS_ERR(root)) | |
27543 | + goto out; | |
27544 | + | |
27545 | + sb = root->d_sb; | |
27546 | + si_write_lock(sb, !AuLock_FLUSH); | |
27547 | + sysaufs_brs_add(sb, 0); | |
27548 | + si_write_unlock(sb); | |
27549 | + au_sbilist_add(sb); | |
27550 | + | |
27551 | +out: | |
27552 | + return root; | |
1facf9fc | 27553 | +} |
27554 | + | |
e49829fe JR |
27555 | +static void aufs_kill_sb(struct super_block *sb) |
27556 | +{ | |
27557 | + struct au_sbinfo *sbinfo; | |
27558 | + | |
27559 | + sbinfo = au_sbi(sb); | |
27560 | + if (sbinfo) { | |
27561 | + au_sbilist_del(sb); | |
27562 | + aufs_write_lock(sb->s_root); | |
076b876e | 27563 | + au_fhsm_fin(sb); |
e49829fe JR |
27564 | + if (sbinfo->si_wbr_create_ops->fin) |
27565 | + sbinfo->si_wbr_create_ops->fin(sb); | |
27566 | + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) { | |
27567 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE); | |
027c5e7a | 27568 | + au_remount_refresh(sb); |
e49829fe JR |
27569 | + } |
27570 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
27571 | + au_plink_put(sb, /*verbose*/1); | |
27572 | + au_xino_clr(sb); | |
1e00d052 | 27573 | + sbinfo->si_sb = NULL; |
e49829fe | 27574 | + aufs_write_unlock(sb->s_root); |
e49829fe JR |
27575 | + au_nwt_flush(&sbinfo->si_nowait); |
27576 | + } | |
98d9a5b1 | 27577 | + kill_anon_super(sb); |
e49829fe JR |
27578 | +} |
27579 | + | |
1facf9fc | 27580 | +struct file_system_type aufs_fs_type = { |
27581 | + .name = AUFS_FSTYPE, | |
c06a8ce3 AM |
27582 | + /* a race between rename and others */ |
27583 | + .fs_flags = FS_RENAME_DOES_D_MOVE, | |
027c5e7a | 27584 | + .mount = aufs_mount, |
e49829fe | 27585 | + .kill_sb = aufs_kill_sb, |
1facf9fc | 27586 | + /* no need to __module_get() and module_put(). */ |
27587 | + .owner = THIS_MODULE, | |
27588 | +}; | |
7f207e10 AM |
27589 | diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h |
27590 | --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c AM |
27591 | +++ linux/fs/aufs/super.h 2015-09-24 10:47:58.254719746 +0200 |
27592 | @@ -0,0 +1,638 @@ | |
1facf9fc | 27593 | +/* |
2000de60 | 27594 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 27595 | + * |
27596 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27597 | + * it under the terms of the GNU General Public License as published by | |
27598 | + * the Free Software Foundation; either version 2 of the License, or | |
27599 | + * (at your option) any later version. | |
dece6358 AM |
27600 | + * |
27601 | + * This program is distributed in the hope that it will be useful, | |
27602 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27603 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27604 | + * GNU General Public License for more details. | |
27605 | + * | |
27606 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27607 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27608 | + */ |
27609 | + | |
27610 | +/* | |
27611 | + * super_block operations | |
27612 | + */ | |
27613 | + | |
27614 | +#ifndef __AUFS_SUPER_H__ | |
27615 | +#define __AUFS_SUPER_H__ | |
27616 | + | |
27617 | +#ifdef __KERNEL__ | |
27618 | + | |
27619 | +#include <linux/fs.h> | |
5527c038 | 27620 | +#include <linux/kobject.h> |
1facf9fc | 27621 | +#include "rwsem.h" |
27622 | +#include "spl.h" | |
27623 | +#include "wkq.h" | |
27624 | + | |
1facf9fc | 27625 | +/* policies to select one among multiple writable branches */ |
27626 | +struct au_wbr_copyup_operations { | |
27627 | + int (*copyup)(struct dentry *dentry); | |
27628 | +}; | |
27629 | + | |
392086de AM |
27630 | +#define AuWbr_DIR 1 /* target is a dir */ |
27631 | +#define AuWbr_PARENT (1 << 1) /* always require a parent */ | |
27632 | + | |
27633 | +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name) | |
27634 | +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; } | |
27635 | +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; } | |
27636 | + | |
1facf9fc | 27637 | +struct au_wbr_create_operations { |
392086de | 27638 | + int (*create)(struct dentry *dentry, unsigned int flags); |
1facf9fc | 27639 | + int (*init)(struct super_block *sb); |
27640 | + int (*fin)(struct super_block *sb); | |
27641 | +}; | |
27642 | + | |
27643 | +struct au_wbr_mfs { | |
27644 | + struct mutex mfs_lock; /* protect this structure */ | |
27645 | + unsigned long mfs_jiffy; | |
27646 | + unsigned long mfs_expire; | |
27647 | + aufs_bindex_t mfs_bindex; | |
27648 | + | |
27649 | + unsigned long long mfsrr_bytes; | |
27650 | + unsigned long long mfsrr_watermark; | |
27651 | +}; | |
27652 | + | |
86dc4139 AM |
27653 | +struct pseudo_link { |
27654 | + union { | |
27655 | + struct hlist_node hlist; | |
27656 | + struct rcu_head rcu; | |
27657 | + }; | |
27658 | + struct inode *inode; | |
27659 | +}; | |
27660 | + | |
27661 | +#define AuPlink_NHASH 100 | |
27662 | +static inline int au_plink_hash(ino_t ino) | |
27663 | +{ | |
27664 | + return ino % AuPlink_NHASH; | |
27665 | +} | |
27666 | + | |
076b876e AM |
27667 | +/* File-based Hierarchical Storage Management */ |
27668 | +struct au_fhsm { | |
27669 | +#ifdef CONFIG_AUFS_FHSM | |
27670 | + /* allow only one process who can receive the notification */ | |
27671 | + spinlock_t fhsm_spin; | |
27672 | + pid_t fhsm_pid; | |
27673 | + wait_queue_head_t fhsm_wqh; | |
27674 | + atomic_t fhsm_readable; | |
27675 | + | |
c1595e42 | 27676 | + /* these are protected by si_rwsem */ |
076b876e | 27677 | + unsigned long fhsm_expire; |
c1595e42 | 27678 | + aufs_bindex_t fhsm_bottom; |
076b876e AM |
27679 | +#endif |
27680 | +}; | |
27681 | + | |
1facf9fc | 27682 | +struct au_branch; |
27683 | +struct au_sbinfo { | |
27684 | + /* nowait tasks in the system-wide workqueue */ | |
27685 | + struct au_nowait_tasks si_nowait; | |
27686 | + | |
b752ccd1 AM |
27687 | + /* |
27688 | + * tried sb->s_umount, but failed due to the dependecy between i_mutex. | |
27689 | + * rwsem for au_sbinfo is necessary. | |
27690 | + */ | |
dece6358 | 27691 | + struct au_rwsem si_rwsem; |
1facf9fc | 27692 | + |
b752ccd1 AM |
27693 | + /* prevent recursive locking in deleting inode */ |
27694 | + struct { | |
27695 | + unsigned long *bitmap; | |
27696 | + spinlock_t tree_lock; | |
27697 | + struct radix_tree_root tree; | |
27698 | + } au_si_pid; | |
27699 | + | |
7f207e10 | 27700 | + /* |
523b37e3 AM |
27701 | + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from |
27702 | + * remount. | |
7f207e10 AM |
27703 | + */ |
27704 | + atomic_long_t si_ninodes, si_nfiles; | |
27705 | + | |
1facf9fc | 27706 | + /* branch management */ |
27707 | + unsigned int si_generation; | |
27708 | + | |
2000de60 | 27709 | + /* see AuSi_ flags */ |
1facf9fc | 27710 | + unsigned char au_si_status; |
27711 | + | |
27712 | + aufs_bindex_t si_bend; | |
7f207e10 AM |
27713 | + |
27714 | + /* dirty trick to keep br_id plus */ | |
27715 | + unsigned int si_last_br_id : | |
27716 | + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1; | |
1facf9fc | 27717 | + struct au_branch **si_branch; |
27718 | + | |
27719 | + /* policy to select a writable branch */ | |
27720 | + unsigned char si_wbr_copyup; | |
27721 | + unsigned char si_wbr_create; | |
27722 | + struct au_wbr_copyup_operations *si_wbr_copyup_ops; | |
27723 | + struct au_wbr_create_operations *si_wbr_create_ops; | |
27724 | + | |
27725 | + /* round robin */ | |
27726 | + atomic_t si_wbr_rr_next; | |
27727 | + | |
27728 | + /* most free space */ | |
27729 | + struct au_wbr_mfs si_wbr_mfs; | |
27730 | + | |
076b876e AM |
27731 | + /* File-based Hierarchical Storage Management */ |
27732 | + struct au_fhsm si_fhsm; | |
27733 | + | |
1facf9fc | 27734 | + /* mount flags */ |
27735 | + /* include/asm-ia64/siginfo.h defines a macro named si_flags */ | |
27736 | + unsigned int si_mntflags; | |
27737 | + | |
c2c0f25c AM |
27738 | + /* symlink to follow_link() and put_link() */ |
27739 | + struct au_sphlhead si_symlink; | |
27740 | + | |
1facf9fc | 27741 | + /* external inode number (bitmap and translation table) */ |
5527c038 JR |
27742 | + vfs_readf_t si_xread; |
27743 | + vfs_writef_t si_xwrite; | |
1facf9fc | 27744 | + struct file *si_xib; |
27745 | + struct mutex si_xib_mtx; /* protect xib members */ | |
27746 | + unsigned long *si_xib_buf; | |
27747 | + unsigned long si_xib_last_pindex; | |
27748 | + int si_xib_next_bit; | |
27749 | + aufs_bindex_t si_xino_brid; | |
392086de AM |
27750 | + unsigned long si_xino_jiffy; |
27751 | + unsigned long si_xino_expire; | |
1facf9fc | 27752 | + /* reserved for future use */ |
27753 | + /* unsigned long long si_xib_limit; */ /* Max xib file size */ | |
27754 | + | |
27755 | +#ifdef CONFIG_AUFS_EXPORT | |
27756 | + /* i_generation */ | |
27757 | + struct file *si_xigen; | |
27758 | + atomic_t si_xigen_next; | |
27759 | +#endif | |
27760 | + | |
b912730e AM |
27761 | + /* dirty trick to suppoer atomic_open */ |
27762 | + struct au_sphlhead si_aopen; | |
27763 | + | |
1facf9fc | 27764 | + /* vdir parameters */ |
e49829fe | 27765 | + unsigned long si_rdcache; /* max cache time in jiffies */ |
1facf9fc | 27766 | + unsigned int si_rdblk; /* deblk size */ |
27767 | + unsigned int si_rdhash; /* hash size */ | |
27768 | + | |
27769 | + /* | |
27770 | + * If the number of whiteouts are larger than si_dirwh, leave all of | |
27771 | + * them after au_whtmp_ren to reduce the cost of rmdir(2). | |
27772 | + * future fsck.aufs or kernel thread will remove them later. | |
27773 | + * Otherwise, remove all whiteouts and the dir in rmdir(2). | |
27774 | + */ | |
27775 | + unsigned int si_dirwh; | |
27776 | + | |
1facf9fc | 27777 | + /* pseudo_link list */ |
86dc4139 | 27778 | + struct au_sphlhead si_plink[AuPlink_NHASH]; |
1facf9fc | 27779 | + wait_queue_head_t si_plink_wq; |
4a4d8108 | 27780 | + spinlock_t si_plink_maint_lock; |
e49829fe | 27781 | + pid_t si_plink_maint_pid; |
1facf9fc | 27782 | + |
523b37e3 AM |
27783 | + /* file list */ |
27784 | + struct au_sphlhead si_files; | |
27785 | + | |
1facf9fc | 27786 | + /* |
27787 | + * sysfs and lifetime management. | |
27788 | + * this is not a small structure and it may be a waste of memory in case | |
27789 | + * of sysfs is disabled, particulary when many aufs-es are mounted. | |
27790 | + * but using sysfs is majority. | |
27791 | + */ | |
27792 | + struct kobject si_kobj; | |
27793 | +#ifdef CONFIG_DEBUG_FS | |
86dc4139 AM |
27794 | + struct dentry *si_dbgaufs; |
27795 | + struct dentry *si_dbgaufs_plink; | |
27796 | + struct dentry *si_dbgaufs_xib; | |
1facf9fc | 27797 | +#ifdef CONFIG_AUFS_EXPORT |
27798 | + struct dentry *si_dbgaufs_xigen; | |
27799 | +#endif | |
27800 | +#endif | |
27801 | + | |
e49829fe JR |
27802 | +#ifdef CONFIG_AUFS_SBILIST |
27803 | + struct list_head si_list; | |
27804 | +#endif | |
27805 | + | |
1facf9fc | 27806 | + /* dirty, necessary for unmounting, sysfs and sysrq */ |
27807 | + struct super_block *si_sb; | |
27808 | +}; | |
27809 | + | |
dece6358 AM |
27810 | +/* sbinfo status flags */ |
27811 | +/* | |
27812 | + * set true when refresh_dirs() failed at remount time. | |
27813 | + * then try refreshing dirs at access time again. | |
27814 | + * if it is false, refreshing dirs at access time is unnecesary | |
27815 | + */ | |
027c5e7a | 27816 | +#define AuSi_FAILED_REFRESH_DIR 1 |
076b876e AM |
27817 | + |
27818 | +#define AuSi_FHSM (1 << 1) /* fhsm is active now */ | |
27819 | + | |
27820 | +#ifndef CONFIG_AUFS_FHSM | |
27821 | +#undef AuSi_FHSM | |
27822 | +#define AuSi_FHSM 0 | |
27823 | +#endif | |
27824 | + | |
dece6358 AM |
27825 | +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi, |
27826 | + unsigned int flag) | |
27827 | +{ | |
27828 | + AuRwMustAnyLock(&sbi->si_rwsem); | |
27829 | + return sbi->au_si_status & flag; | |
27830 | +} | |
27831 | +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name) | |
27832 | +#define au_fset_si(sbinfo, name) do { \ | |
27833 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
27834 | + (sbinfo)->au_si_status |= AuSi_##name; \ | |
27835 | +} while (0) | |
27836 | +#define au_fclr_si(sbinfo, name) do { \ | |
27837 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
27838 | + (sbinfo)->au_si_status &= ~AuSi_##name; \ | |
27839 | +} while (0) | |
27840 | + | |
1facf9fc | 27841 | +/* ---------------------------------------------------------------------- */ |
27842 | + | |
27843 | +/* policy to select one among writable branches */ | |
4a4d8108 AM |
27844 | +#define AuWbrCopyup(sbinfo, ...) \ |
27845 | + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__)) | |
27846 | +#define AuWbrCreate(sbinfo, ...) \ | |
27847 | + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__)) | |
1facf9fc | 27848 | + |
27849 | +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */ | |
27850 | +#define AuLock_DW 1 /* write-lock dentry */ | |
27851 | +#define AuLock_IR (1 << 1) /* read-lock inode */ | |
27852 | +#define AuLock_IW (1 << 2) /* write-lock inode */ | |
27853 | +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */ | |
27854 | +#define AuLock_DIR (1 << 4) /* target is a dir */ | |
e49829fe JR |
27855 | +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */ |
27856 | +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */ | |
027c5e7a | 27857 | +#define AuLock_GEN (1 << 7) /* test digen/iigen */ |
1facf9fc | 27858 | +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name) |
7f207e10 AM |
27859 | +#define au_fset_lock(flags, name) \ |
27860 | + do { (flags) |= AuLock_##name; } while (0) | |
27861 | +#define au_fclr_lock(flags, name) \ | |
27862 | + do { (flags) &= ~AuLock_##name; } while (0) | |
1facf9fc | 27863 | + |
27864 | +/* ---------------------------------------------------------------------- */ | |
27865 | + | |
27866 | +/* super.c */ | |
27867 | +extern struct file_system_type aufs_fs_type; | |
27868 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino); | |
7f207e10 AM |
27869 | +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max, |
27870 | + void *arg); | |
27871 | +void au_array_free(void *array); | |
27872 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg); | |
27873 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max); | |
27874 | +void au_iarray_free(struct inode **a, unsigned long long max); | |
1facf9fc | 27875 | + |
27876 | +/* sbinfo.c */ | |
27877 | +void au_si_free(struct kobject *kobj); | |
27878 | +int au_si_alloc(struct super_block *sb); | |
27879 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr); | |
27880 | + | |
27881 | +unsigned int au_sigen_inc(struct super_block *sb); | |
27882 | +aufs_bindex_t au_new_br_id(struct super_block *sb); | |
27883 | + | |
e49829fe JR |
27884 | +int si_read_lock(struct super_block *sb, int flags); |
27885 | +int si_write_lock(struct super_block *sb, int flags); | |
27886 | +int aufs_read_lock(struct dentry *dentry, int flags); | |
1facf9fc | 27887 | +void aufs_read_unlock(struct dentry *dentry, int flags); |
27888 | +void aufs_write_lock(struct dentry *dentry); | |
27889 | +void aufs_write_unlock(struct dentry *dentry); | |
e49829fe | 27890 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags); |
1facf9fc | 27891 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2); |
27892 | + | |
b752ccd1 AM |
27893 | +int si_pid_test_slow(struct super_block *sb); |
27894 | +void si_pid_set_slow(struct super_block *sb); | |
27895 | +void si_pid_clr_slow(struct super_block *sb); | |
27896 | + | |
1facf9fc | 27897 | +/* wbr_policy.c */ |
27898 | +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[]; | |
27899 | +extern struct au_wbr_create_operations au_wbr_create_ops[]; | |
27900 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
c2b27bf2 | 27901 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex); |
076b876e | 27902 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart); |
c2b27bf2 AM |
27903 | + |
27904 | +/* mvdown.c */ | |
27905 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg); | |
1facf9fc | 27906 | + |
076b876e AM |
27907 | +#ifdef CONFIG_AUFS_FHSM |
27908 | +/* fhsm.c */ | |
27909 | + | |
27910 | +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm) | |
27911 | +{ | |
27912 | + pid_t pid; | |
27913 | + | |
27914 | + spin_lock(&fhsm->fhsm_spin); | |
27915 | + pid = fhsm->fhsm_pid; | |
27916 | + spin_unlock(&fhsm->fhsm_spin); | |
27917 | + | |
27918 | + return pid; | |
27919 | +} | |
27920 | + | |
27921 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force); | |
27922 | +void au_fhsm_wrote_all(struct super_block *sb, int force); | |
27923 | +int au_fhsm_fd(struct super_block *sb, int oflags); | |
27924 | +int au_fhsm_br_alloc(struct au_branch *br); | |
c1595e42 | 27925 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex); |
076b876e AM |
27926 | +void au_fhsm_fin(struct super_block *sb); |
27927 | +void au_fhsm_init(struct au_sbinfo *sbinfo); | |
27928 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec); | |
27929 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo); | |
27930 | +#else | |
27931 | +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex, | |
27932 | + int force) | |
27933 | +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force) | |
27934 | +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags) | |
c1595e42 JR |
27935 | +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm) |
27936 | +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br) | |
27937 | +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex) | |
076b876e AM |
27938 | +AuStubVoid(au_fhsm_fin, struct super_block *sb) |
27939 | +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo) | |
27940 | +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec) | |
27941 | +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo) | |
27942 | +#endif | |
27943 | + | |
1facf9fc | 27944 | +/* ---------------------------------------------------------------------- */ |
27945 | + | |
27946 | +static inline struct au_sbinfo *au_sbi(struct super_block *sb) | |
27947 | +{ | |
27948 | + return sb->s_fs_info; | |
27949 | +} | |
27950 | + | |
27951 | +/* ---------------------------------------------------------------------- */ | |
27952 | + | |
27953 | +#ifdef CONFIG_AUFS_EXPORT | |
a2a7ad62 | 27954 | +int au_test_nfsd(void); |
1facf9fc | 27955 | +void au_export_init(struct super_block *sb); |
b752ccd1 | 27956 | +void au_xigen_inc(struct inode *inode); |
1facf9fc | 27957 | +int au_xigen_new(struct inode *inode); |
27958 | +int au_xigen_set(struct super_block *sb, struct file *base); | |
27959 | +void au_xigen_clr(struct super_block *sb); | |
27960 | + | |
27961 | +static inline int au_busy_or_stale(void) | |
27962 | +{ | |
b752ccd1 | 27963 | + if (!au_test_nfsd()) |
1facf9fc | 27964 | + return -EBUSY; |
27965 | + return -ESTALE; | |
27966 | +} | |
27967 | +#else | |
b752ccd1 | 27968 | +AuStubInt0(au_test_nfsd, void) |
a2a7ad62 | 27969 | +AuStubVoid(au_export_init, struct super_block *sb) |
b752ccd1 | 27970 | +AuStubVoid(au_xigen_inc, struct inode *inode) |
4a4d8108 AM |
27971 | +AuStubInt0(au_xigen_new, struct inode *inode) |
27972 | +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base) | |
27973 | +AuStubVoid(au_xigen_clr, struct super_block *sb) | |
c1595e42 | 27974 | +AuStub(int, au_busy_or_stale, return -EBUSY, void) |
1facf9fc | 27975 | +#endif /* CONFIG_AUFS_EXPORT */ |
27976 | + | |
27977 | +/* ---------------------------------------------------------------------- */ | |
27978 | + | |
e49829fe JR |
27979 | +#ifdef CONFIG_AUFS_SBILIST |
27980 | +/* module.c */ | |
27981 | +extern struct au_splhead au_sbilist; | |
27982 | + | |
27983 | +static inline void au_sbilist_init(void) | |
27984 | +{ | |
27985 | + au_spl_init(&au_sbilist); | |
27986 | +} | |
27987 | + | |
27988 | +static inline void au_sbilist_add(struct super_block *sb) | |
27989 | +{ | |
27990 | + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist); | |
27991 | +} | |
27992 | + | |
27993 | +static inline void au_sbilist_del(struct super_block *sb) | |
27994 | +{ | |
27995 | + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist); | |
27996 | +} | |
53392da6 AM |
27997 | + |
27998 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
27999 | +static inline void au_sbilist_lock(void) | |
28000 | +{ | |
28001 | + spin_lock(&au_sbilist.spin); | |
28002 | +} | |
28003 | + | |
28004 | +static inline void au_sbilist_unlock(void) | |
28005 | +{ | |
28006 | + spin_unlock(&au_sbilist.spin); | |
28007 | +} | |
28008 | +#define AuGFP_SBILIST GFP_ATOMIC | |
28009 | +#else | |
28010 | +AuStubVoid(au_sbilist_lock, void) | |
28011 | +AuStubVoid(au_sbilist_unlock, void) | |
28012 | +#define AuGFP_SBILIST GFP_NOFS | |
28013 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ | |
e49829fe JR |
28014 | +#else |
28015 | +AuStubVoid(au_sbilist_init, void) | |
c1595e42 JR |
28016 | +AuStubVoid(au_sbilist_add, struct super_block *sb) |
28017 | +AuStubVoid(au_sbilist_del, struct super_block *sb) | |
53392da6 AM |
28018 | +AuStubVoid(au_sbilist_lock, void) |
28019 | +AuStubVoid(au_sbilist_unlock, void) | |
28020 | +#define AuGFP_SBILIST GFP_NOFS | |
e49829fe JR |
28021 | +#endif |
28022 | + | |
28023 | +/* ---------------------------------------------------------------------- */ | |
28024 | + | |
1facf9fc | 28025 | +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo) |
28026 | +{ | |
dece6358 | 28027 | + /* |
c1595e42 | 28028 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
28029 | + * so the tiny check for si_rwsem is unnecessary. |
28030 | + */ | |
28031 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
1facf9fc | 28032 | +#ifdef CONFIG_DEBUG_FS |
28033 | + sbinfo->si_dbgaufs = NULL; | |
86dc4139 | 28034 | + sbinfo->si_dbgaufs_plink = NULL; |
1facf9fc | 28035 | + sbinfo->si_dbgaufs_xib = NULL; |
28036 | +#ifdef CONFIG_AUFS_EXPORT | |
28037 | + sbinfo->si_dbgaufs_xigen = NULL; | |
28038 | +#endif | |
28039 | +#endif | |
28040 | +} | |
28041 | + | |
28042 | +/* ---------------------------------------------------------------------- */ | |
28043 | + | |
b752ccd1 AM |
28044 | +static inline pid_t si_pid_bit(void) |
28045 | +{ | |
28046 | + /* the origin of pid is 1, but the bitmap's is 0 */ | |
28047 | + return current->pid - 1; | |
28048 | +} | |
28049 | + | |
28050 | +static inline int si_pid_test(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 | + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
c1595e42 | 28057 | + return si_pid_test_slow(sb); |
b752ccd1 AM |
28058 | +} |
28059 | + | |
28060 | +static inline void si_pid_set(struct super_block *sb) | |
28061 | +{ | |
076b876e AM |
28062 | + pid_t bit; |
28063 | + | |
28064 | + bit = si_pid_bit(); | |
b752ccd1 AM |
28065 | + if (bit < PID_MAX_DEFAULT) { |
28066 | + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap)); | |
28067 | + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
28068 | + /* smp_mb(); */ | |
28069 | + } else | |
28070 | + si_pid_set_slow(sb); | |
28071 | +} | |
28072 | + | |
28073 | +static inline void si_pid_clr(struct super_block *sb) | |
28074 | +{ | |
076b876e AM |
28075 | + pid_t bit; |
28076 | + | |
28077 | + bit = si_pid_bit(); | |
b752ccd1 AM |
28078 | + if (bit < PID_MAX_DEFAULT) { |
28079 | + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap)); | |
28080 | + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
28081 | + /* smp_mb(); */ | |
28082 | + } else | |
28083 | + si_pid_clr_slow(sb); | |
28084 | +} | |
28085 | + | |
28086 | +/* ---------------------------------------------------------------------- */ | |
28087 | + | |
1facf9fc | 28088 | +/* lock superblock. mainly for entry point functions */ |
28089 | +/* | |
b752ccd1 AM |
28090 | + * __si_read_lock, __si_write_lock, |
28091 | + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock | |
1facf9fc | 28092 | + */ |
b752ccd1 | 28093 | +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem); |
1facf9fc | 28094 | + |
dece6358 AM |
28095 | +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem) |
28096 | +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem) | |
28097 | +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem) | |
28098 | + | |
b752ccd1 AM |
28099 | +static inline void si_noflush_read_lock(struct super_block *sb) |
28100 | +{ | |
28101 | + __si_read_lock(sb); | |
28102 | + si_pid_set(sb); | |
28103 | +} | |
28104 | + | |
28105 | +static inline int si_noflush_read_trylock(struct super_block *sb) | |
28106 | +{ | |
076b876e AM |
28107 | + int locked; |
28108 | + | |
28109 | + locked = __si_read_trylock(sb); | |
b752ccd1 AM |
28110 | + if (locked) |
28111 | + si_pid_set(sb); | |
28112 | + return locked; | |
28113 | +} | |
28114 | + | |
28115 | +static inline void si_noflush_write_lock(struct super_block *sb) | |
28116 | +{ | |
28117 | + __si_write_lock(sb); | |
28118 | + si_pid_set(sb); | |
28119 | +} | |
28120 | + | |
28121 | +static inline int si_noflush_write_trylock(struct super_block *sb) | |
28122 | +{ | |
076b876e AM |
28123 | + int locked; |
28124 | + | |
28125 | + locked = __si_write_trylock(sb); | |
b752ccd1 AM |
28126 | + if (locked) |
28127 | + si_pid_set(sb); | |
28128 | + return locked; | |
28129 | +} | |
28130 | + | |
7e9cd9fe | 28131 | +#if 0 /* reserved */ |
1facf9fc | 28132 | +static inline int si_read_trylock(struct super_block *sb, int flags) |
28133 | +{ | |
28134 | + if (au_ftest_lock(flags, FLUSH)) | |
28135 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28136 | + return si_noflush_read_trylock(sb); | |
28137 | +} | |
e49829fe | 28138 | +#endif |
1facf9fc | 28139 | + |
b752ccd1 AM |
28140 | +static inline void si_read_unlock(struct super_block *sb) |
28141 | +{ | |
28142 | + si_pid_clr(sb); | |
28143 | + __si_read_unlock(sb); | |
28144 | +} | |
28145 | + | |
7e9cd9fe | 28146 | +#if 0 /* reserved */ |
1facf9fc | 28147 | +static inline int si_write_trylock(struct super_block *sb, int flags) |
28148 | +{ | |
28149 | + if (au_ftest_lock(flags, FLUSH)) | |
28150 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28151 | + return si_noflush_write_trylock(sb); | |
28152 | +} | |
b752ccd1 AM |
28153 | +#endif |
28154 | + | |
28155 | +static inline void si_write_unlock(struct super_block *sb) | |
28156 | +{ | |
28157 | + si_pid_clr(sb); | |
28158 | + __si_write_unlock(sb); | |
28159 | +} | |
28160 | + | |
7e9cd9fe | 28161 | +#if 0 /* reserved */ |
b752ccd1 AM |
28162 | +static inline void si_downgrade_lock(struct super_block *sb) |
28163 | +{ | |
28164 | + __si_downgrade_lock(sb); | |
28165 | +} | |
28166 | +#endif | |
1facf9fc | 28167 | + |
28168 | +/* ---------------------------------------------------------------------- */ | |
28169 | + | |
28170 | +static inline aufs_bindex_t au_sbend(struct super_block *sb) | |
28171 | +{ | |
dece6358 | 28172 | + SiMustAnyLock(sb); |
1facf9fc | 28173 | + return au_sbi(sb)->si_bend; |
28174 | +} | |
28175 | + | |
28176 | +static inline unsigned int au_mntflags(struct super_block *sb) | |
28177 | +{ | |
dece6358 | 28178 | + SiMustAnyLock(sb); |
1facf9fc | 28179 | + return au_sbi(sb)->si_mntflags; |
28180 | +} | |
28181 | + | |
28182 | +static inline unsigned int au_sigen(struct super_block *sb) | |
28183 | +{ | |
dece6358 | 28184 | + SiMustAnyLock(sb); |
1facf9fc | 28185 | + return au_sbi(sb)->si_generation; |
28186 | +} | |
28187 | + | |
7f207e10 AM |
28188 | +static inline void au_ninodes_inc(struct super_block *sb) |
28189 | +{ | |
28190 | + atomic_long_inc(&au_sbi(sb)->si_ninodes); | |
28191 | +} | |
28192 | + | |
28193 | +static inline void au_ninodes_dec(struct super_block *sb) | |
28194 | +{ | |
28195 | + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes)); | |
28196 | + atomic_long_dec(&au_sbi(sb)->si_ninodes); | |
28197 | +} | |
28198 | + | |
28199 | +static inline void au_nfiles_inc(struct super_block *sb) | |
28200 | +{ | |
28201 | + atomic_long_inc(&au_sbi(sb)->si_nfiles); | |
28202 | +} | |
28203 | + | |
28204 | +static inline void au_nfiles_dec(struct super_block *sb) | |
28205 | +{ | |
28206 | + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles)); | |
28207 | + atomic_long_dec(&au_sbi(sb)->si_nfiles); | |
28208 | +} | |
28209 | + | |
1facf9fc | 28210 | +static inline struct au_branch *au_sbr(struct super_block *sb, |
28211 | + aufs_bindex_t bindex) | |
28212 | +{ | |
dece6358 | 28213 | + SiMustAnyLock(sb); |
1facf9fc | 28214 | + return au_sbi(sb)->si_branch[0 + bindex]; |
28215 | +} | |
28216 | + | |
28217 | +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid) | |
28218 | +{ | |
dece6358 | 28219 | + SiMustWriteLock(sb); |
1facf9fc | 28220 | + au_sbi(sb)->si_xino_brid = brid; |
28221 | +} | |
28222 | + | |
28223 | +static inline aufs_bindex_t au_xino_brid(struct super_block *sb) | |
28224 | +{ | |
dece6358 | 28225 | + SiMustAnyLock(sb); |
1facf9fc | 28226 | + return au_sbi(sb)->si_xino_brid; |
28227 | +} | |
28228 | + | |
28229 | +#endif /* __KERNEL__ */ | |
28230 | +#endif /* __AUFS_SUPER_H__ */ | |
7f207e10 AM |
28231 | diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c |
28232 | --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 28233 | +++ linux/fs/aufs/sysaufs.c 2015-09-24 10:47:58.254719746 +0200 |
523b37e3 | 28234 | @@ -0,0 +1,104 @@ |
1facf9fc | 28235 | +/* |
2000de60 | 28236 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28237 | + * |
28238 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28239 | + * it under the terms of the GNU General Public License as published by | |
28240 | + * the Free Software Foundation; either version 2 of the License, or | |
28241 | + * (at your option) any later version. | |
dece6358 AM |
28242 | + * |
28243 | + * This program is distributed in the hope that it will be useful, | |
28244 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28245 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28246 | + * GNU General Public License for more details. | |
28247 | + * | |
28248 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28249 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28250 | + */ |
28251 | + | |
28252 | +/* | |
28253 | + * sysfs interface and lifetime management | |
28254 | + * they are necessary regardless sysfs is disabled. | |
28255 | + */ | |
28256 | + | |
1facf9fc | 28257 | +#include <linux/random.h> |
1facf9fc | 28258 | +#include "aufs.h" |
28259 | + | |
28260 | +unsigned long sysaufs_si_mask; | |
e49829fe | 28261 | +struct kset *sysaufs_kset; |
1facf9fc | 28262 | + |
28263 | +#define AuSiAttr(_name) { \ | |
28264 | + .attr = { .name = __stringify(_name), .mode = 0444 }, \ | |
28265 | + .show = sysaufs_si_##_name, \ | |
28266 | +} | |
28267 | + | |
28268 | +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path); | |
28269 | +struct attribute *sysaufs_si_attrs[] = { | |
28270 | + &sysaufs_si_attr_xi_path.attr, | |
28271 | + NULL, | |
28272 | +}; | |
28273 | + | |
4a4d8108 | 28274 | +static const struct sysfs_ops au_sbi_ops = { |
1facf9fc | 28275 | + .show = sysaufs_si_show |
28276 | +}; | |
28277 | + | |
28278 | +static struct kobj_type au_sbi_ktype = { | |
28279 | + .release = au_si_free, | |
28280 | + .sysfs_ops = &au_sbi_ops, | |
28281 | + .default_attrs = sysaufs_si_attrs | |
28282 | +}; | |
28283 | + | |
28284 | +/* ---------------------------------------------------------------------- */ | |
28285 | + | |
28286 | +int sysaufs_si_init(struct au_sbinfo *sbinfo) | |
28287 | +{ | |
28288 | + int err; | |
28289 | + | |
e49829fe | 28290 | + sbinfo->si_kobj.kset = sysaufs_kset; |
1facf9fc | 28291 | + /* cf. sysaufs_name() */ |
28292 | + err = kobject_init_and_add | |
e49829fe | 28293 | + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL, |
1facf9fc | 28294 | + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo)); |
28295 | + | |
28296 | + dbgaufs_si_null(sbinfo); | |
28297 | + if (!err) { | |
28298 | + err = dbgaufs_si_init(sbinfo); | |
28299 | + if (unlikely(err)) | |
28300 | + kobject_put(&sbinfo->si_kobj); | |
28301 | + } | |
28302 | + return err; | |
28303 | +} | |
28304 | + | |
28305 | +void sysaufs_fin(void) | |
28306 | +{ | |
28307 | + dbgaufs_fin(); | |
e49829fe JR |
28308 | + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
28309 | + kset_unregister(sysaufs_kset); | |
1facf9fc | 28310 | +} |
28311 | + | |
28312 | +int __init sysaufs_init(void) | |
28313 | +{ | |
28314 | + int err; | |
28315 | + | |
28316 | + do { | |
28317 | + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask)); | |
28318 | + } while (!sysaufs_si_mask); | |
28319 | + | |
4a4d8108 | 28320 | + err = -EINVAL; |
e49829fe JR |
28321 | + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj); |
28322 | + if (unlikely(!sysaufs_kset)) | |
4a4d8108 | 28323 | + goto out; |
e49829fe JR |
28324 | + err = PTR_ERR(sysaufs_kset); |
28325 | + if (IS_ERR(sysaufs_kset)) | |
1facf9fc | 28326 | + goto out; |
e49829fe | 28327 | + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
1facf9fc | 28328 | + if (unlikely(err)) { |
e49829fe | 28329 | + kset_unregister(sysaufs_kset); |
1facf9fc | 28330 | + goto out; |
28331 | + } | |
28332 | + | |
28333 | + err = dbgaufs_init(); | |
28334 | + if (unlikely(err)) | |
28335 | + sysaufs_fin(); | |
4f0767ce | 28336 | +out: |
1facf9fc | 28337 | + return err; |
28338 | +} | |
7f207e10 AM |
28339 | diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h |
28340 | --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 28341 | +++ linux/fs/aufs/sysaufs.h 2015-09-24 10:47:58.254719746 +0200 |
c1595e42 | 28342 | @@ -0,0 +1,101 @@ |
1facf9fc | 28343 | +/* |
2000de60 | 28344 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28345 | + * |
28346 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28347 | + * it under the terms of the GNU General Public License as published by | |
28348 | + * the Free Software Foundation; either version 2 of the License, or | |
28349 | + * (at your option) any later version. | |
dece6358 AM |
28350 | + * |
28351 | + * This program is distributed in the hope that it will be useful, | |
28352 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28353 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28354 | + * GNU General Public License for more details. | |
28355 | + * | |
28356 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28357 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28358 | + */ |
28359 | + | |
28360 | +/* | |
28361 | + * sysfs interface and mount lifetime management | |
28362 | + */ | |
28363 | + | |
28364 | +#ifndef __SYSAUFS_H__ | |
28365 | +#define __SYSAUFS_H__ | |
28366 | + | |
28367 | +#ifdef __KERNEL__ | |
28368 | + | |
1facf9fc | 28369 | +#include <linux/sysfs.h> |
1facf9fc | 28370 | +#include "module.h" |
28371 | + | |
dece6358 AM |
28372 | +struct super_block; |
28373 | +struct au_sbinfo; | |
28374 | + | |
1facf9fc | 28375 | +struct sysaufs_si_attr { |
28376 | + struct attribute attr; | |
28377 | + int (*show)(struct seq_file *seq, struct super_block *sb); | |
28378 | +}; | |
28379 | + | |
28380 | +/* ---------------------------------------------------------------------- */ | |
28381 | + | |
28382 | +/* sysaufs.c */ | |
28383 | +extern unsigned long sysaufs_si_mask; | |
e49829fe | 28384 | +extern struct kset *sysaufs_kset; |
1facf9fc | 28385 | +extern struct attribute *sysaufs_si_attrs[]; |
28386 | +int sysaufs_si_init(struct au_sbinfo *sbinfo); | |
28387 | +int __init sysaufs_init(void); | |
28388 | +void sysaufs_fin(void); | |
28389 | + | |
28390 | +/* ---------------------------------------------------------------------- */ | |
28391 | + | |
28392 | +/* some people doesn't like to show a pointer in kernel */ | |
28393 | +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo) | |
28394 | +{ | |
28395 | + return sysaufs_si_mask ^ (unsigned long)sbinfo; | |
28396 | +} | |
28397 | + | |
28398 | +#define SysaufsSiNamePrefix "si_" | |
28399 | +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16) | |
28400 | +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name) | |
28401 | +{ | |
28402 | + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx", | |
28403 | + sysaufs_si_id(sbinfo)); | |
28404 | +} | |
28405 | + | |
28406 | +struct au_branch; | |
28407 | +#ifdef CONFIG_SYSFS | |
28408 | +/* sysfs.c */ | |
28409 | +extern struct attribute_group *sysaufs_attr_group; | |
28410 | + | |
28411 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb); | |
28412 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
28413 | + char *buf); | |
076b876e AM |
28414 | +long au_brinfo_ioctl(struct file *file, unsigned long arg); |
28415 | +#ifdef CONFIG_COMPAT | |
28416 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg); | |
28417 | +#endif | |
1facf9fc | 28418 | + |
28419 | +void sysaufs_br_init(struct au_branch *br); | |
28420 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
28421 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
28422 | + | |
28423 | +#define sysaufs_brs_init() do {} while (0) | |
28424 | + | |
28425 | +#else | |
28426 | +#define sysaufs_attr_group NULL | |
28427 | + | |
4a4d8108 | 28428 | +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb) |
c1595e42 JR |
28429 | +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj, |
28430 | + struct attribute *attr, char *buf) | |
4a4d8108 AM |
28431 | +AuStubVoid(sysaufs_br_init, struct au_branch *br) |
28432 | +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
28433 | +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) | |
1facf9fc | 28434 | + |
28435 | +static inline void sysaufs_brs_init(void) | |
28436 | +{ | |
28437 | + sysaufs_brs = 0; | |
28438 | +} | |
28439 | + | |
28440 | +#endif /* CONFIG_SYSFS */ | |
28441 | + | |
28442 | +#endif /* __KERNEL__ */ | |
28443 | +#endif /* __SYSAUFS_H__ */ | |
7f207e10 AM |
28444 | diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c |
28445 | --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 28446 | +++ linux/fs/aufs/sysfs.c 2015-09-24 10:47:58.254719746 +0200 |
076b876e | 28447 | @@ -0,0 +1,372 @@ |
1facf9fc | 28448 | +/* |
2000de60 | 28449 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28450 | + * |
28451 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28452 | + * it under the terms of the GNU General Public License as published by | |
28453 | + * the Free Software Foundation; either version 2 of the License, or | |
28454 | + * (at your option) any later version. | |
dece6358 AM |
28455 | + * |
28456 | + * This program is distributed in the hope that it will be useful, | |
28457 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28458 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28459 | + * GNU General Public License for more details. | |
28460 | + * | |
28461 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28462 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28463 | + */ |
28464 | + | |
28465 | +/* | |
28466 | + * sysfs interface | |
28467 | + */ | |
28468 | + | |
076b876e | 28469 | +#include <linux/compat.h> |
1facf9fc | 28470 | +#include <linux/seq_file.h> |
1facf9fc | 28471 | +#include "aufs.h" |
28472 | + | |
4a4d8108 AM |
28473 | +#ifdef CONFIG_AUFS_FS_MODULE |
28474 | +/* this entry violates the "one line per file" policy of sysfs */ | |
28475 | +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr, | |
28476 | + char *buf) | |
28477 | +{ | |
28478 | + ssize_t err; | |
28479 | + static char *conf = | |
28480 | +/* this file is generated at compiling */ | |
28481 | +#include "conf.str" | |
28482 | + ; | |
28483 | + | |
28484 | + err = snprintf(buf, PAGE_SIZE, conf); | |
28485 | + if (unlikely(err >= PAGE_SIZE)) | |
28486 | + err = -EFBIG; | |
28487 | + return err; | |
28488 | +} | |
28489 | + | |
28490 | +static struct kobj_attribute au_config_attr = __ATTR_RO(config); | |
28491 | +#endif | |
28492 | + | |
1facf9fc | 28493 | +static struct attribute *au_attr[] = { |
4a4d8108 AM |
28494 | +#ifdef CONFIG_AUFS_FS_MODULE |
28495 | + &au_config_attr.attr, | |
28496 | +#endif | |
1facf9fc | 28497 | + NULL, /* need to NULL terminate the list of attributes */ |
28498 | +}; | |
28499 | + | |
28500 | +static struct attribute_group sysaufs_attr_group_body = { | |
28501 | + .attrs = au_attr | |
28502 | +}; | |
28503 | + | |
28504 | +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body; | |
28505 | + | |
28506 | +/* ---------------------------------------------------------------------- */ | |
28507 | + | |
28508 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb) | |
28509 | +{ | |
28510 | + int err; | |
28511 | + | |
dece6358 AM |
28512 | + SiMustAnyLock(sb); |
28513 | + | |
1facf9fc | 28514 | + err = 0; |
28515 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
28516 | + err = au_xino_path(seq, au_sbi(sb)->si_xib); | |
28517 | + seq_putc(seq, '\n'); | |
28518 | + } | |
28519 | + return err; | |
28520 | +} | |
28521 | + | |
28522 | +/* | |
28523 | + * the lifetime of branch is independent from the entry under sysfs. | |
28524 | + * sysfs handles the lifetime of the entry, and never call ->show() after it is | |
28525 | + * unlinked. | |
28526 | + */ | |
28527 | +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb, | |
392086de | 28528 | + aufs_bindex_t bindex, int idx) |
1facf9fc | 28529 | +{ |
1e00d052 | 28530 | + int err; |
1facf9fc | 28531 | + struct path path; |
28532 | + struct dentry *root; | |
28533 | + struct au_branch *br; | |
076b876e | 28534 | + au_br_perm_str_t perm; |
1facf9fc | 28535 | + |
28536 | + AuDbg("b%d\n", bindex); | |
28537 | + | |
1e00d052 | 28538 | + err = 0; |
1facf9fc | 28539 | + root = sb->s_root; |
28540 | + di_read_lock_parent(root, !AuLock_IR); | |
28541 | + br = au_sbr(sb, bindex); | |
392086de AM |
28542 | + |
28543 | + switch (idx) { | |
28544 | + case AuBrSysfs_BR: | |
28545 | + path.mnt = au_br_mnt(br); | |
28546 | + path.dentry = au_h_dptr(root, bindex); | |
28547 | + au_seq_path(seq, &path); | |
076b876e AM |
28548 | + au_optstr_br_perm(&perm, br->br_perm); |
28549 | + err = seq_printf(seq, "=%s\n", perm.a); | |
392086de AM |
28550 | + break; |
28551 | + case AuBrSysfs_BRID: | |
28552 | + err = seq_printf(seq, "%d\n", br->br_id); | |
392086de AM |
28553 | + break; |
28554 | + } | |
076b876e AM |
28555 | + di_read_unlock(root, !AuLock_IR); |
28556 | + if (err == -1) | |
28557 | + err = -E2BIG; | |
392086de | 28558 | + |
1e00d052 | 28559 | + return err; |
1facf9fc | 28560 | +} |
28561 | + | |
28562 | +/* ---------------------------------------------------------------------- */ | |
28563 | + | |
28564 | +static struct seq_file *au_seq(char *p, ssize_t len) | |
28565 | +{ | |
28566 | + struct seq_file *seq; | |
28567 | + | |
28568 | + seq = kzalloc(sizeof(*seq), GFP_NOFS); | |
28569 | + if (seq) { | |
28570 | + /* mutex_init(&seq.lock); */ | |
28571 | + seq->buf = p; | |
28572 | + seq->size = len; | |
28573 | + return seq; /* success */ | |
28574 | + } | |
28575 | + | |
28576 | + seq = ERR_PTR(-ENOMEM); | |
28577 | + return seq; | |
28578 | +} | |
28579 | + | |
392086de AM |
28580 | +#define SysaufsBr_PREFIX "br" |
28581 | +#define SysaufsBrid_PREFIX "brid" | |
1facf9fc | 28582 | + |
28583 | +/* todo: file size may exceed PAGE_SIZE */ | |
28584 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
1308ab2a | 28585 | + char *buf) |
1facf9fc | 28586 | +{ |
28587 | + ssize_t err; | |
392086de | 28588 | + int idx; |
1facf9fc | 28589 | + long l; |
28590 | + aufs_bindex_t bend; | |
28591 | + struct au_sbinfo *sbinfo; | |
28592 | + struct super_block *sb; | |
28593 | + struct seq_file *seq; | |
28594 | + char *name; | |
28595 | + struct attribute **cattr; | |
28596 | + | |
28597 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
28598 | + sb = sbinfo->si_sb; | |
1308ab2a | 28599 | + |
28600 | + /* | |
28601 | + * prevent a race condition between sysfs and aufs. | |
28602 | + * for instance, sysfs_file_read() calls sysfs_get_active_two() which | |
28603 | + * prohibits maintaining the sysfs entries. | |
28604 | + * hew we acquire read lock after sysfs_get_active_two(). | |
28605 | + * on the other hand, the remount process may maintain the sysfs/aufs | |
28606 | + * entries after acquiring write lock. | |
28607 | + * it can cause a deadlock. | |
28608 | + * simply we gave up processing read here. | |
28609 | + */ | |
28610 | + err = -EBUSY; | |
28611 | + if (unlikely(!si_noflush_read_trylock(sb))) | |
28612 | + goto out; | |
1facf9fc | 28613 | + |
28614 | + seq = au_seq(buf, PAGE_SIZE); | |
28615 | + err = PTR_ERR(seq); | |
28616 | + if (IS_ERR(seq)) | |
1308ab2a | 28617 | + goto out_unlock; |
1facf9fc | 28618 | + |
28619 | + name = (void *)attr->name; | |
28620 | + cattr = sysaufs_si_attrs; | |
28621 | + while (*cattr) { | |
28622 | + if (!strcmp(name, (*cattr)->name)) { | |
28623 | + err = container_of(*cattr, struct sysaufs_si_attr, attr) | |
28624 | + ->show(seq, sb); | |
28625 | + goto out_seq; | |
28626 | + } | |
28627 | + cattr++; | |
28628 | + } | |
28629 | + | |
392086de AM |
28630 | + if (!strncmp(name, SysaufsBrid_PREFIX, |
28631 | + sizeof(SysaufsBrid_PREFIX) - 1)) { | |
28632 | + idx = AuBrSysfs_BRID; | |
28633 | + name += sizeof(SysaufsBrid_PREFIX) - 1; | |
28634 | + } else if (!strncmp(name, SysaufsBr_PREFIX, | |
28635 | + sizeof(SysaufsBr_PREFIX) - 1)) { | |
28636 | + idx = AuBrSysfs_BR; | |
1facf9fc | 28637 | + name += sizeof(SysaufsBr_PREFIX) - 1; |
392086de AM |
28638 | + } else |
28639 | + BUG(); | |
28640 | + | |
28641 | + err = kstrtol(name, 10, &l); | |
28642 | + if (!err) { | |
28643 | + bend = au_sbend(sb); | |
28644 | + if (l <= bend) | |
28645 | + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx); | |
28646 | + else | |
28647 | + err = -ENOENT; | |
1facf9fc | 28648 | + } |
1facf9fc | 28649 | + |
4f0767ce | 28650 | +out_seq: |
1facf9fc | 28651 | + if (!err) { |
28652 | + err = seq->count; | |
28653 | + /* sysfs limit */ | |
28654 | + if (unlikely(err == PAGE_SIZE)) | |
28655 | + err = -EFBIG; | |
28656 | + } | |
28657 | + kfree(seq); | |
4f0767ce | 28658 | +out_unlock: |
1facf9fc | 28659 | + si_read_unlock(sb); |
4f0767ce | 28660 | +out: |
1facf9fc | 28661 | + return err; |
28662 | +} | |
28663 | + | |
28664 | +/* ---------------------------------------------------------------------- */ | |
28665 | + | |
076b876e AM |
28666 | +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg) |
28667 | +{ | |
28668 | + int err; | |
28669 | + int16_t brid; | |
28670 | + aufs_bindex_t bindex, bend; | |
28671 | + size_t sz; | |
28672 | + char *buf; | |
28673 | + struct seq_file *seq; | |
28674 | + struct au_branch *br; | |
28675 | + | |
28676 | + si_read_lock(sb, AuLock_FLUSH); | |
28677 | + bend = au_sbend(sb); | |
28678 | + err = bend + 1; | |
28679 | + if (!arg) | |
28680 | + goto out; | |
28681 | + | |
28682 | + err = -ENOMEM; | |
28683 | + buf = (void *)__get_free_page(GFP_NOFS); | |
28684 | + if (unlikely(!buf)) | |
28685 | + goto out; | |
28686 | + | |
28687 | + seq = au_seq(buf, PAGE_SIZE); | |
28688 | + err = PTR_ERR(seq); | |
28689 | + if (IS_ERR(seq)) | |
28690 | + goto out_buf; | |
28691 | + | |
28692 | + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path); | |
28693 | + for (bindex = 0; bindex <= bend; bindex++, arg++) { | |
28694 | + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg)); | |
28695 | + if (unlikely(err)) | |
28696 | + break; | |
28697 | + | |
28698 | + br = au_sbr(sb, bindex); | |
28699 | + brid = br->br_id; | |
28700 | + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id)); | |
28701 | + err = __put_user(brid, &arg->id); | |
28702 | + if (unlikely(err)) | |
28703 | + break; | |
28704 | + | |
28705 | + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm)); | |
28706 | + err = __put_user(br->br_perm, &arg->perm); | |
28707 | + if (unlikely(err)) | |
28708 | + break; | |
28709 | + | |
28710 | + au_seq_path(seq, &br->br_path); | |
28711 | + err = seq_putc(seq, '\0'); | |
28712 | + if (!err && seq->count <= sz) { | |
28713 | + err = copy_to_user(arg->path, seq->buf, seq->count); | |
28714 | + seq->count = 0; | |
28715 | + if (unlikely(err)) | |
28716 | + break; | |
28717 | + } else { | |
28718 | + err = -E2BIG; | |
28719 | + goto out_seq; | |
28720 | + } | |
28721 | + } | |
28722 | + if (unlikely(err)) | |
28723 | + err = -EFAULT; | |
28724 | + | |
28725 | +out_seq: | |
28726 | + kfree(seq); | |
28727 | +out_buf: | |
28728 | + free_page((unsigned long)buf); | |
28729 | +out: | |
28730 | + si_read_unlock(sb); | |
28731 | + return err; | |
28732 | +} | |
28733 | + | |
28734 | +long au_brinfo_ioctl(struct file *file, unsigned long arg) | |
28735 | +{ | |
2000de60 | 28736 | + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg); |
076b876e AM |
28737 | +} |
28738 | + | |
28739 | +#ifdef CONFIG_COMPAT | |
28740 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg) | |
28741 | +{ | |
2000de60 | 28742 | + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg)); |
076b876e AM |
28743 | +} |
28744 | +#endif | |
28745 | + | |
28746 | +/* ---------------------------------------------------------------------- */ | |
28747 | + | |
1facf9fc | 28748 | +void sysaufs_br_init(struct au_branch *br) |
28749 | +{ | |
392086de AM |
28750 | + int i; |
28751 | + struct au_brsysfs *br_sysfs; | |
28752 | + struct attribute *attr; | |
4a4d8108 | 28753 | + |
392086de AM |
28754 | + br_sysfs = br->br_sysfs; |
28755 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28756 | + attr = &br_sysfs->attr; | |
28757 | + sysfs_attr_init(attr); | |
28758 | + attr->name = br_sysfs->name; | |
28759 | + attr->mode = S_IRUGO; | |
28760 | + br_sysfs++; | |
28761 | + } | |
1facf9fc | 28762 | +} |
28763 | + | |
28764 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
28765 | +{ | |
28766 | + struct au_branch *br; | |
28767 | + struct kobject *kobj; | |
392086de AM |
28768 | + struct au_brsysfs *br_sysfs; |
28769 | + int i; | |
1facf9fc | 28770 | + aufs_bindex_t bend; |
28771 | + | |
28772 | + dbgaufs_brs_del(sb, bindex); | |
28773 | + | |
28774 | + if (!sysaufs_brs) | |
28775 | + return; | |
28776 | + | |
28777 | + kobj = &au_sbi(sb)->si_kobj; | |
28778 | + bend = au_sbend(sb); | |
28779 | + for (; bindex <= bend; bindex++) { | |
28780 | + br = au_sbr(sb, bindex); | |
392086de AM |
28781 | + br_sysfs = br->br_sysfs; |
28782 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28783 | + sysfs_remove_file(kobj, &br_sysfs->attr); | |
28784 | + br_sysfs++; | |
28785 | + } | |
1facf9fc | 28786 | + } |
28787 | +} | |
28788 | + | |
28789 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
28790 | +{ | |
392086de | 28791 | + int err, i; |
1facf9fc | 28792 | + aufs_bindex_t bend; |
28793 | + struct kobject *kobj; | |
28794 | + struct au_branch *br; | |
392086de | 28795 | + struct au_brsysfs *br_sysfs; |
1facf9fc | 28796 | + |
28797 | + dbgaufs_brs_add(sb, bindex); | |
28798 | + | |
28799 | + if (!sysaufs_brs) | |
28800 | + return; | |
28801 | + | |
28802 | + kobj = &au_sbi(sb)->si_kobj; | |
28803 | + bend = au_sbend(sb); | |
28804 | + for (; bindex <= bend; bindex++) { | |
28805 | + br = au_sbr(sb, bindex); | |
392086de AM |
28806 | + br_sysfs = br->br_sysfs; |
28807 | + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name), | |
28808 | + SysaufsBr_PREFIX "%d", bindex); | |
28809 | + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name), | |
28810 | + SysaufsBrid_PREFIX "%d", bindex); | |
28811 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28812 | + err = sysfs_create_file(kobj, &br_sysfs->attr); | |
28813 | + if (unlikely(err)) | |
28814 | + pr_warn("failed %s under sysfs(%d)\n", | |
28815 | + br_sysfs->name, err); | |
28816 | + br_sysfs++; | |
28817 | + } | |
1facf9fc | 28818 | + } |
28819 | +} | |
7f207e10 AM |
28820 | diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c |
28821 | --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 28822 | +++ linux/fs/aufs/sysrq.c 2015-09-24 10:47:58.254719746 +0200 |
076b876e | 28823 | @@ -0,0 +1,157 @@ |
1facf9fc | 28824 | +/* |
2000de60 | 28825 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28826 | + * |
28827 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28828 | + * it under the terms of the GNU General Public License as published by | |
28829 | + * the Free Software Foundation; either version 2 of the License, or | |
28830 | + * (at your option) any later version. | |
dece6358 AM |
28831 | + * |
28832 | + * This program is distributed in the hope that it will be useful, | |
28833 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28834 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28835 | + * GNU General Public License for more details. | |
28836 | + * | |
28837 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28838 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28839 | + */ |
28840 | + | |
28841 | +/* | |
28842 | + * magic sysrq hanlder | |
28843 | + */ | |
28844 | + | |
1facf9fc | 28845 | +/* #include <linux/sysrq.h> */ |
027c5e7a | 28846 | +#include <linux/writeback.h> |
1facf9fc | 28847 | +#include "aufs.h" |
28848 | + | |
28849 | +/* ---------------------------------------------------------------------- */ | |
28850 | + | |
28851 | +static void sysrq_sb(struct super_block *sb) | |
28852 | +{ | |
28853 | + char *plevel; | |
28854 | + struct au_sbinfo *sbinfo; | |
28855 | + struct file *file; | |
523b37e3 AM |
28856 | + struct au_sphlhead *files; |
28857 | + struct au_finfo *finfo; | |
1facf9fc | 28858 | + |
28859 | + plevel = au_plevel; | |
28860 | + au_plevel = KERN_WARNING; | |
1facf9fc | 28861 | + |
4a4d8108 | 28862 | + /* since we define pr_fmt, call printk directly */ |
c06a8ce3 AM |
28863 | +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str) |
28864 | + | |
28865 | + sbinfo = au_sbi(sb); | |
4a4d8108 | 28866 | + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo)); |
c06a8ce3 | 28867 | + pr("superblock\n"); |
1facf9fc | 28868 | + au_dpri_sb(sb); |
027c5e7a AM |
28869 | + |
28870 | +#if 0 | |
c06a8ce3 | 28871 | + pr("root dentry\n"); |
1facf9fc | 28872 | + au_dpri_dentry(sb->s_root); |
c06a8ce3 | 28873 | + pr("root inode\n"); |
5527c038 | 28874 | + au_dpri_inode(d_inode(sb->s_root)); |
027c5e7a AM |
28875 | +#endif |
28876 | + | |
1facf9fc | 28877 | +#if 0 |
027c5e7a AM |
28878 | + do { |
28879 | + int err, i, j, ndentry; | |
28880 | + struct au_dcsub_pages dpages; | |
28881 | + struct au_dpage *dpage; | |
28882 | + | |
28883 | + err = au_dpages_init(&dpages, GFP_ATOMIC); | |
28884 | + if (unlikely(err)) | |
28885 | + break; | |
28886 | + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL); | |
28887 | + if (!err) | |
28888 | + for (i = 0; i < dpages.ndpage; i++) { | |
28889 | + dpage = dpages.dpages + i; | |
28890 | + ndentry = dpage->ndentry; | |
28891 | + for (j = 0; j < ndentry; j++) | |
28892 | + au_dpri_dentry(dpage->dentries[j]); | |
28893 | + } | |
28894 | + au_dpages_free(&dpages); | |
28895 | + } while (0); | |
28896 | +#endif | |
28897 | + | |
28898 | +#if 1 | |
28899 | + { | |
28900 | + struct inode *i; | |
076b876e | 28901 | + |
c06a8ce3 | 28902 | + pr("isolated inode\n"); |
2cbb1c4b JR |
28903 | + spin_lock(&inode_sb_list_lock); |
28904 | + list_for_each_entry(i, &sb->s_inodes, i_sb_list) { | |
28905 | + spin_lock(&i->i_lock); | |
b4510431 | 28906 | + if (1 || hlist_empty(&i->i_dentry)) |
027c5e7a | 28907 | + au_dpri_inode(i); |
2cbb1c4b JR |
28908 | + spin_unlock(&i->i_lock); |
28909 | + } | |
28910 | + spin_unlock(&inode_sb_list_lock); | |
027c5e7a | 28911 | + } |
1facf9fc | 28912 | +#endif |
c06a8ce3 | 28913 | + pr("files\n"); |
523b37e3 AM |
28914 | + files = &au_sbi(sb)->si_files; |
28915 | + spin_lock(&files->spin); | |
28916 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
4a4d8108 | 28917 | + umode_t mode; |
076b876e | 28918 | + |
523b37e3 | 28919 | + file = finfo->fi_file; |
c06a8ce3 | 28920 | + mode = file_inode(file)->i_mode; |
38d290e6 | 28921 | + if (!special_file(mode)) |
1facf9fc | 28922 | + au_dpri_file(file); |
523b37e3 AM |
28923 | + } |
28924 | + spin_unlock(&files->spin); | |
c06a8ce3 | 28925 | + pr("done\n"); |
1facf9fc | 28926 | + |
c06a8ce3 | 28927 | +#undef pr |
1facf9fc | 28928 | + au_plevel = plevel; |
1facf9fc | 28929 | +} |
28930 | + | |
28931 | +/* ---------------------------------------------------------------------- */ | |
28932 | + | |
28933 | +/* module parameter */ | |
28934 | +static char *aufs_sysrq_key = "a"; | |
28935 | +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO); | |
28936 | +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME); | |
28937 | + | |
0c5527e5 | 28938 | +static void au_sysrq(int key __maybe_unused) |
1facf9fc | 28939 | +{ |
1facf9fc | 28940 | + struct au_sbinfo *sbinfo; |
28941 | + | |
027c5e7a | 28942 | + lockdep_off(); |
53392da6 | 28943 | + au_sbilist_lock(); |
e49829fe | 28944 | + list_for_each_entry(sbinfo, &au_sbilist.head, si_list) |
1facf9fc | 28945 | + sysrq_sb(sbinfo->si_sb); |
53392da6 | 28946 | + au_sbilist_unlock(); |
027c5e7a | 28947 | + lockdep_on(); |
1facf9fc | 28948 | +} |
28949 | + | |
28950 | +static struct sysrq_key_op au_sysrq_op = { | |
28951 | + .handler = au_sysrq, | |
28952 | + .help_msg = "Aufs", | |
28953 | + .action_msg = "Aufs", | |
28954 | + .enable_mask = SYSRQ_ENABLE_DUMP | |
28955 | +}; | |
28956 | + | |
28957 | +/* ---------------------------------------------------------------------- */ | |
28958 | + | |
28959 | +int __init au_sysrq_init(void) | |
28960 | +{ | |
28961 | + int err; | |
28962 | + char key; | |
28963 | + | |
28964 | + err = -1; | |
28965 | + key = *aufs_sysrq_key; | |
28966 | + if ('a' <= key && key <= 'z') | |
28967 | + err = register_sysrq_key(key, &au_sysrq_op); | |
28968 | + if (unlikely(err)) | |
4a4d8108 | 28969 | + pr_err("err %d, sysrq=%c\n", err, key); |
1facf9fc | 28970 | + return err; |
28971 | +} | |
28972 | + | |
28973 | +void au_sysrq_fin(void) | |
28974 | +{ | |
28975 | + int err; | |
076b876e | 28976 | + |
1facf9fc | 28977 | + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op); |
28978 | + if (unlikely(err)) | |
4a4d8108 | 28979 | + pr_err("err %d (ignored)\n", err); |
1facf9fc | 28980 | +} |
7f207e10 AM |
28981 | diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c |
28982 | --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 28983 | +++ linux/fs/aufs/vdir.c 2015-09-24 10:47:58.258053165 +0200 |
b912730e | 28984 | @@ -0,0 +1,888 @@ |
1facf9fc | 28985 | +/* |
2000de60 | 28986 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 28987 | + * |
28988 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28989 | + * it under the terms of the GNU General Public License as published by | |
28990 | + * the Free Software Foundation; either version 2 of the License, or | |
28991 | + * (at your option) any later version. | |
dece6358 AM |
28992 | + * |
28993 | + * This program is distributed in the hope that it will be useful, | |
28994 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28995 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28996 | + * GNU General Public License for more details. | |
28997 | + * | |
28998 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28999 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29000 | + */ |
29001 | + | |
29002 | +/* | |
29003 | + * virtual or vertical directory | |
29004 | + */ | |
29005 | + | |
29006 | +#include "aufs.h" | |
29007 | + | |
dece6358 | 29008 | +static unsigned int calc_size(int nlen) |
1facf9fc | 29009 | +{ |
dece6358 | 29010 | + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t)); |
1facf9fc | 29011 | +} |
29012 | + | |
29013 | +static int set_deblk_end(union au_vdir_deblk_p *p, | |
29014 | + union au_vdir_deblk_p *deblk_end) | |
29015 | +{ | |
29016 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) { | |
29017 | + p->de->de_str.len = 0; | |
29018 | + /* smp_mb(); */ | |
29019 | + return 0; | |
29020 | + } | |
29021 | + return -1; /* error */ | |
29022 | +} | |
29023 | + | |
29024 | +/* returns true or false */ | |
29025 | +static int is_deblk_end(union au_vdir_deblk_p *p, | |
29026 | + union au_vdir_deblk_p *deblk_end) | |
29027 | +{ | |
29028 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) | |
29029 | + return !p->de->de_str.len; | |
29030 | + return 1; | |
29031 | +} | |
29032 | + | |
29033 | +static unsigned char *last_deblk(struct au_vdir *vdir) | |
29034 | +{ | |
29035 | + return vdir->vd_deblk[vdir->vd_nblk - 1]; | |
29036 | +} | |
29037 | + | |
29038 | +/* ---------------------------------------------------------------------- */ | |
29039 | + | |
1308ab2a | 29040 | +/* estimate the apropriate size for name hash table */ |
29041 | +unsigned int au_rdhash_est(loff_t sz) | |
29042 | +{ | |
29043 | + unsigned int n; | |
29044 | + | |
29045 | + n = UINT_MAX; | |
29046 | + sz >>= 10; | |
29047 | + if (sz < n) | |
29048 | + n = sz; | |
29049 | + if (sz < AUFS_RDHASH_DEF) | |
29050 | + n = AUFS_RDHASH_DEF; | |
4a4d8108 | 29051 | + /* pr_info("n %u\n", n); */ |
1308ab2a | 29052 | + return n; |
29053 | +} | |
29054 | + | |
1facf9fc | 29055 | +/* |
29056 | + * the allocated memory has to be freed by | |
dece6358 | 29057 | + * au_nhash_wh_free() or au_nhash_de_free(). |
1facf9fc | 29058 | + */ |
dece6358 | 29059 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp) |
1facf9fc | 29060 | +{ |
1facf9fc | 29061 | + struct hlist_head *head; |
dece6358 | 29062 | + unsigned int u; |
076b876e | 29063 | + size_t sz; |
1facf9fc | 29064 | + |
076b876e AM |
29065 | + sz = sizeof(*nhash->nh_head) * num_hash; |
29066 | + head = kmalloc(sz, gfp); | |
dece6358 AM |
29067 | + if (head) { |
29068 | + nhash->nh_num = num_hash; | |
29069 | + nhash->nh_head = head; | |
29070 | + for (u = 0; u < num_hash; u++) | |
1facf9fc | 29071 | + INIT_HLIST_HEAD(head++); |
dece6358 | 29072 | + return 0; /* success */ |
1facf9fc | 29073 | + } |
1facf9fc | 29074 | + |
dece6358 | 29075 | + return -ENOMEM; |
1facf9fc | 29076 | +} |
29077 | + | |
dece6358 AM |
29078 | +static void nhash_count(struct hlist_head *head) |
29079 | +{ | |
29080 | +#if 0 | |
29081 | + unsigned long n; | |
29082 | + struct hlist_node *pos; | |
29083 | + | |
29084 | + n = 0; | |
29085 | + hlist_for_each(pos, head) | |
29086 | + n++; | |
4a4d8108 | 29087 | + pr_info("%lu\n", n); |
dece6358 AM |
29088 | +#endif |
29089 | +} | |
29090 | + | |
29091 | +static void au_nhash_wh_do_free(struct hlist_head *head) | |
1facf9fc | 29092 | +{ |
c06a8ce3 AM |
29093 | + struct au_vdir_wh *pos; |
29094 | + struct hlist_node *node; | |
1facf9fc | 29095 | + |
c06a8ce3 AM |
29096 | + hlist_for_each_entry_safe(pos, node, head, wh_hash) |
29097 | + kfree(pos); | |
1facf9fc | 29098 | +} |
29099 | + | |
dece6358 | 29100 | +static void au_nhash_de_do_free(struct hlist_head *head) |
1facf9fc | 29101 | +{ |
c06a8ce3 AM |
29102 | + struct au_vdir_dehstr *pos; |
29103 | + struct hlist_node *node; | |
1facf9fc | 29104 | + |
c06a8ce3 AM |
29105 | + hlist_for_each_entry_safe(pos, node, head, hash) |
29106 | + au_cache_free_vdir_dehstr(pos); | |
1facf9fc | 29107 | +} |
29108 | + | |
dece6358 AM |
29109 | +static void au_nhash_do_free(struct au_nhash *nhash, |
29110 | + void (*free)(struct hlist_head *head)) | |
1facf9fc | 29111 | +{ |
1308ab2a | 29112 | + unsigned int n; |
1facf9fc | 29113 | + struct hlist_head *head; |
1facf9fc | 29114 | + |
dece6358 | 29115 | + n = nhash->nh_num; |
1308ab2a | 29116 | + if (!n) |
29117 | + return; | |
29118 | + | |
dece6358 | 29119 | + head = nhash->nh_head; |
1308ab2a | 29120 | + while (n-- > 0) { |
dece6358 AM |
29121 | + nhash_count(head); |
29122 | + free(head++); | |
1facf9fc | 29123 | + } |
dece6358 | 29124 | + kfree(nhash->nh_head); |
1facf9fc | 29125 | +} |
29126 | + | |
dece6358 | 29127 | +void au_nhash_wh_free(struct au_nhash *whlist) |
1facf9fc | 29128 | +{ |
dece6358 AM |
29129 | + au_nhash_do_free(whlist, au_nhash_wh_do_free); |
29130 | +} | |
1facf9fc | 29131 | + |
dece6358 AM |
29132 | +static void au_nhash_de_free(struct au_nhash *delist) |
29133 | +{ | |
29134 | + au_nhash_do_free(delist, au_nhash_de_do_free); | |
1facf9fc | 29135 | +} |
29136 | + | |
29137 | +/* ---------------------------------------------------------------------- */ | |
29138 | + | |
29139 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, | |
29140 | + int limit) | |
29141 | +{ | |
29142 | + int num; | |
29143 | + unsigned int u, n; | |
29144 | + struct hlist_head *head; | |
c06a8ce3 | 29145 | + struct au_vdir_wh *pos; |
1facf9fc | 29146 | + |
29147 | + num = 0; | |
29148 | + n = whlist->nh_num; | |
29149 | + head = whlist->nh_head; | |
1308ab2a | 29150 | + for (u = 0; u < n; u++, head++) |
c06a8ce3 AM |
29151 | + hlist_for_each_entry(pos, head, wh_hash) |
29152 | + if (pos->wh_bindex == btgt && ++num > limit) | |
1facf9fc | 29153 | + return 1; |
1facf9fc | 29154 | + return 0; |
29155 | +} | |
29156 | + | |
29157 | +static struct hlist_head *au_name_hash(struct au_nhash *nhash, | |
dece6358 | 29158 | + unsigned char *name, |
1facf9fc | 29159 | + unsigned int len) |
29160 | +{ | |
dece6358 AM |
29161 | + unsigned int v; |
29162 | + /* const unsigned int magic_bit = 12; */ | |
29163 | + | |
1308ab2a | 29164 | + AuDebugOn(!nhash->nh_num || !nhash->nh_head); |
29165 | + | |
dece6358 AM |
29166 | + v = 0; |
29167 | + while (len--) | |
29168 | + v += *name++; | |
29169 | + /* v = hash_long(v, magic_bit); */ | |
29170 | + v %= nhash->nh_num; | |
29171 | + return nhash->nh_head + v; | |
29172 | +} | |
29173 | + | |
29174 | +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name, | |
29175 | + int nlen) | |
29176 | +{ | |
29177 | + return str->len == nlen && !memcmp(str->name, name, nlen); | |
1facf9fc | 29178 | +} |
29179 | + | |
29180 | +/* returns found or not */ | |
dece6358 | 29181 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen) |
1facf9fc | 29182 | +{ |
29183 | + struct hlist_head *head; | |
c06a8ce3 | 29184 | + struct au_vdir_wh *pos; |
1facf9fc | 29185 | + struct au_vdir_destr *str; |
29186 | + | |
dece6358 | 29187 | + head = au_name_hash(whlist, name, nlen); |
c06a8ce3 AM |
29188 | + hlist_for_each_entry(pos, head, wh_hash) { |
29189 | + str = &pos->wh_str; | |
1facf9fc | 29190 | + AuDbg("%.*s\n", str->len, str->name); |
dece6358 AM |
29191 | + if (au_nhash_test_name(str, name, nlen)) |
29192 | + return 1; | |
29193 | + } | |
29194 | + return 0; | |
29195 | +} | |
29196 | + | |
29197 | +/* returns found(true) or not */ | |
29198 | +static int test_known(struct au_nhash *delist, char *name, int nlen) | |
29199 | +{ | |
29200 | + struct hlist_head *head; | |
c06a8ce3 | 29201 | + struct au_vdir_dehstr *pos; |
dece6358 AM |
29202 | + struct au_vdir_destr *str; |
29203 | + | |
29204 | + head = au_name_hash(delist, name, nlen); | |
c06a8ce3 AM |
29205 | + hlist_for_each_entry(pos, head, hash) { |
29206 | + str = pos->str; | |
dece6358 AM |
29207 | + AuDbg("%.*s\n", str->len, str->name); |
29208 | + if (au_nhash_test_name(str, name, nlen)) | |
1facf9fc | 29209 | + return 1; |
29210 | + } | |
29211 | + return 0; | |
29212 | +} | |
29213 | + | |
dece6358 AM |
29214 | +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino, |
29215 | + unsigned char d_type) | |
29216 | +{ | |
29217 | +#ifdef CONFIG_AUFS_SHWH | |
29218 | + wh->wh_ino = ino; | |
29219 | + wh->wh_type = d_type; | |
29220 | +#endif | |
29221 | +} | |
29222 | + | |
29223 | +/* ---------------------------------------------------------------------- */ | |
29224 | + | |
29225 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
29226 | + unsigned int d_type, aufs_bindex_t bindex, | |
29227 | + unsigned char shwh) | |
1facf9fc | 29228 | +{ |
29229 | + int err; | |
29230 | + struct au_vdir_destr *str; | |
29231 | + struct au_vdir_wh *wh; | |
29232 | + | |
dece6358 | 29233 | + AuDbg("%.*s\n", nlen, name); |
1308ab2a | 29234 | + AuDebugOn(!whlist->nh_num || !whlist->nh_head); |
29235 | + | |
1facf9fc | 29236 | + err = -ENOMEM; |
dece6358 | 29237 | + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS); |
1facf9fc | 29238 | + if (unlikely(!wh)) |
29239 | + goto out; | |
29240 | + | |
29241 | + err = 0; | |
29242 | + wh->wh_bindex = bindex; | |
dece6358 AM |
29243 | + if (shwh) |
29244 | + au_shwh_init_wh(wh, ino, d_type); | |
1facf9fc | 29245 | + str = &wh->wh_str; |
dece6358 AM |
29246 | + str->len = nlen; |
29247 | + memcpy(str->name, name, nlen); | |
29248 | + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen)); | |
1facf9fc | 29249 | + /* smp_mb(); */ |
29250 | + | |
4f0767ce | 29251 | +out: |
1facf9fc | 29252 | + return err; |
29253 | +} | |
29254 | + | |
1facf9fc | 29255 | +static int append_deblk(struct au_vdir *vdir) |
29256 | +{ | |
29257 | + int err; | |
dece6358 | 29258 | + unsigned long ul; |
1facf9fc | 29259 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; |
29260 | + union au_vdir_deblk_p p, deblk_end; | |
29261 | + unsigned char **o; | |
29262 | + | |
29263 | + err = -ENOMEM; | |
dece6358 AM |
29264 | + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1), |
29265 | + GFP_NOFS); | |
1facf9fc | 29266 | + if (unlikely(!o)) |
29267 | + goto out; | |
29268 | + | |
29269 | + vdir->vd_deblk = o; | |
29270 | + p.deblk = kmalloc(deblk_sz, GFP_NOFS); | |
29271 | + if (p.deblk) { | |
29272 | + ul = vdir->vd_nblk++; | |
29273 | + vdir->vd_deblk[ul] = p.deblk; | |
29274 | + vdir->vd_last.ul = ul; | |
29275 | + vdir->vd_last.p.deblk = p.deblk; | |
29276 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29277 | + err = set_deblk_end(&p, &deblk_end); | |
29278 | + } | |
29279 | + | |
4f0767ce | 29280 | +out: |
1facf9fc | 29281 | + return err; |
29282 | +} | |
29283 | + | |
dece6358 AM |
29284 | +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino, |
29285 | + unsigned int d_type, struct au_nhash *delist) | |
29286 | +{ | |
29287 | + int err; | |
29288 | + unsigned int sz; | |
29289 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; | |
29290 | + union au_vdir_deblk_p p, *room, deblk_end; | |
29291 | + struct au_vdir_dehstr *dehstr; | |
29292 | + | |
29293 | + p.deblk = last_deblk(vdir); | |
29294 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29295 | + room = &vdir->vd_last.p; | |
29296 | + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk | |
29297 | + || !is_deblk_end(room, &deblk_end)); | |
29298 | + | |
29299 | + sz = calc_size(nlen); | |
29300 | + if (unlikely(sz > deblk_end.deblk - room->deblk)) { | |
29301 | + err = append_deblk(vdir); | |
29302 | + if (unlikely(err)) | |
29303 | + goto out; | |
29304 | + | |
29305 | + p.deblk = last_deblk(vdir); | |
29306 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29307 | + /* smp_mb(); */ | |
29308 | + AuDebugOn(room->deblk != p.deblk); | |
29309 | + } | |
29310 | + | |
29311 | + err = -ENOMEM; | |
4a4d8108 | 29312 | + dehstr = au_cache_alloc_vdir_dehstr(); |
dece6358 AM |
29313 | + if (unlikely(!dehstr)) |
29314 | + goto out; | |
29315 | + | |
29316 | + dehstr->str = &room->de->de_str; | |
29317 | + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen)); | |
29318 | + room->de->de_ino = ino; | |
29319 | + room->de->de_type = d_type; | |
29320 | + room->de->de_str.len = nlen; | |
29321 | + memcpy(room->de->de_str.name, name, nlen); | |
29322 | + | |
29323 | + err = 0; | |
29324 | + room->deblk += sz; | |
29325 | + if (unlikely(set_deblk_end(room, &deblk_end))) | |
29326 | + err = append_deblk(vdir); | |
29327 | + /* smp_mb(); */ | |
29328 | + | |
4f0767ce | 29329 | +out: |
dece6358 AM |
29330 | + return err; |
29331 | +} | |
29332 | + | |
29333 | +/* ---------------------------------------------------------------------- */ | |
29334 | + | |
29335 | +void au_vdir_free(struct au_vdir *vdir) | |
29336 | +{ | |
29337 | + unsigned char **deblk; | |
29338 | + | |
29339 | + deblk = vdir->vd_deblk; | |
29340 | + while (vdir->vd_nblk--) | |
29341 | + kfree(*deblk++); | |
29342 | + kfree(vdir->vd_deblk); | |
29343 | + au_cache_free_vdir(vdir); | |
29344 | +} | |
29345 | + | |
1308ab2a | 29346 | +static struct au_vdir *alloc_vdir(struct file *file) |
1facf9fc | 29347 | +{ |
29348 | + struct au_vdir *vdir; | |
1308ab2a | 29349 | + struct super_block *sb; |
1facf9fc | 29350 | + int err; |
29351 | + | |
2000de60 | 29352 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
29353 | + SiMustAnyLock(sb); |
29354 | + | |
1facf9fc | 29355 | + err = -ENOMEM; |
29356 | + vdir = au_cache_alloc_vdir(); | |
29357 | + if (unlikely(!vdir)) | |
29358 | + goto out; | |
29359 | + | |
29360 | + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS); | |
29361 | + if (unlikely(!vdir->vd_deblk)) | |
29362 | + goto out_free; | |
29363 | + | |
29364 | + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk; | |
1308ab2a | 29365 | + if (!vdir->vd_deblk_sz) { |
29366 | + /* estimate the apropriate size for deblk */ | |
29367 | + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL); | |
4a4d8108 | 29368 | + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */ |
1308ab2a | 29369 | + } |
1facf9fc | 29370 | + vdir->vd_nblk = 0; |
29371 | + vdir->vd_version = 0; | |
29372 | + vdir->vd_jiffy = 0; | |
29373 | + err = append_deblk(vdir); | |
29374 | + if (!err) | |
29375 | + return vdir; /* success */ | |
29376 | + | |
29377 | + kfree(vdir->vd_deblk); | |
29378 | + | |
4f0767ce | 29379 | +out_free: |
1facf9fc | 29380 | + au_cache_free_vdir(vdir); |
4f0767ce | 29381 | +out: |
1facf9fc | 29382 | + vdir = ERR_PTR(err); |
29383 | + return vdir; | |
29384 | +} | |
29385 | + | |
29386 | +static int reinit_vdir(struct au_vdir *vdir) | |
29387 | +{ | |
29388 | + int err; | |
29389 | + union au_vdir_deblk_p p, deblk_end; | |
29390 | + | |
29391 | + while (vdir->vd_nblk > 1) { | |
29392 | + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]); | |
29393 | + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */ | |
29394 | + vdir->vd_nblk--; | |
29395 | + } | |
29396 | + p.deblk = vdir->vd_deblk[0]; | |
29397 | + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz; | |
29398 | + err = set_deblk_end(&p, &deblk_end); | |
29399 | + /* keep vd_dblk_sz */ | |
29400 | + vdir->vd_last.ul = 0; | |
29401 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
29402 | + vdir->vd_version = 0; | |
29403 | + vdir->vd_jiffy = 0; | |
29404 | + /* smp_mb(); */ | |
29405 | + return err; | |
29406 | +} | |
29407 | + | |
29408 | +/* ---------------------------------------------------------------------- */ | |
29409 | + | |
1facf9fc | 29410 | +#define AuFillVdir_CALLED 1 |
29411 | +#define AuFillVdir_WHABLE (1 << 1) | |
dece6358 | 29412 | +#define AuFillVdir_SHWH (1 << 2) |
1facf9fc | 29413 | +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name) |
7f207e10 AM |
29414 | +#define au_fset_fillvdir(flags, name) \ |
29415 | + do { (flags) |= AuFillVdir_##name; } while (0) | |
29416 | +#define au_fclr_fillvdir(flags, name) \ | |
29417 | + do { (flags) &= ~AuFillVdir_##name; } while (0) | |
1facf9fc | 29418 | + |
dece6358 AM |
29419 | +#ifndef CONFIG_AUFS_SHWH |
29420 | +#undef AuFillVdir_SHWH | |
29421 | +#define AuFillVdir_SHWH 0 | |
29422 | +#endif | |
29423 | + | |
1facf9fc | 29424 | +struct fillvdir_arg { |
392086de | 29425 | + struct dir_context ctx; |
1facf9fc | 29426 | + struct file *file; |
29427 | + struct au_vdir *vdir; | |
dece6358 AM |
29428 | + struct au_nhash delist; |
29429 | + struct au_nhash whlist; | |
1facf9fc | 29430 | + aufs_bindex_t bindex; |
29431 | + unsigned int flags; | |
29432 | + int err; | |
29433 | +}; | |
29434 | + | |
392086de | 29435 | +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen, |
1facf9fc | 29436 | + loff_t offset __maybe_unused, u64 h_ino, |
29437 | + unsigned int d_type) | |
29438 | +{ | |
392086de | 29439 | + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx); |
1facf9fc | 29440 | + char *name = (void *)__name; |
29441 | + struct super_block *sb; | |
1facf9fc | 29442 | + ino_t ino; |
dece6358 | 29443 | + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH); |
1facf9fc | 29444 | + |
1facf9fc | 29445 | + arg->err = 0; |
2000de60 | 29446 | + sb = arg->file->f_path.dentry->d_sb; |
1facf9fc | 29447 | + au_fset_fillvdir(arg->flags, CALLED); |
29448 | + /* smp_mb(); */ | |
dece6358 | 29449 | + if (nlen <= AUFS_WH_PFX_LEN |
1facf9fc | 29450 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { |
dece6358 AM |
29451 | + if (test_known(&arg->delist, name, nlen) |
29452 | + || au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
29453 | + goto out; /* already exists or whiteouted */ | |
1facf9fc | 29454 | + |
dece6358 | 29455 | + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino); |
4a4d8108 AM |
29456 | + if (!arg->err) { |
29457 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) | |
29458 | + d_type = DT_UNKNOWN; | |
dece6358 AM |
29459 | + arg->err = append_de(arg->vdir, name, nlen, ino, |
29460 | + d_type, &arg->delist); | |
4a4d8108 | 29461 | + } |
1facf9fc | 29462 | + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) { |
29463 | + name += AUFS_WH_PFX_LEN; | |
dece6358 AM |
29464 | + nlen -= AUFS_WH_PFX_LEN; |
29465 | + if (au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
29466 | + goto out; /* already whiteouted */ | |
1facf9fc | 29467 | + |
dece6358 AM |
29468 | + if (shwh) |
29469 | + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type, | |
29470 | + &ino); | |
4a4d8108 AM |
29471 | + if (!arg->err) { |
29472 | + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN) | |
29473 | + d_type = DT_UNKNOWN; | |
1facf9fc | 29474 | + arg->err = au_nhash_append_wh |
dece6358 AM |
29475 | + (&arg->whlist, name, nlen, ino, d_type, |
29476 | + arg->bindex, shwh); | |
4a4d8108 | 29477 | + } |
1facf9fc | 29478 | + } |
29479 | + | |
4f0767ce | 29480 | +out: |
1facf9fc | 29481 | + if (!arg->err) |
29482 | + arg->vdir->vd_jiffy = jiffies; | |
29483 | + /* smp_mb(); */ | |
29484 | + AuTraceErr(arg->err); | |
29485 | + return arg->err; | |
29486 | +} | |
29487 | + | |
dece6358 AM |
29488 | +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir, |
29489 | + struct au_nhash *whlist, struct au_nhash *delist) | |
29490 | +{ | |
29491 | +#ifdef CONFIG_AUFS_SHWH | |
29492 | + int err; | |
29493 | + unsigned int nh, u; | |
29494 | + struct hlist_head *head; | |
c06a8ce3 AM |
29495 | + struct au_vdir_wh *pos; |
29496 | + struct hlist_node *n; | |
dece6358 AM |
29497 | + char *p, *o; |
29498 | + struct au_vdir_destr *destr; | |
29499 | + | |
29500 | + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH)); | |
29501 | + | |
29502 | + err = -ENOMEM; | |
537831f9 | 29503 | + o = p = (void *)__get_free_page(GFP_NOFS); |
dece6358 AM |
29504 | + if (unlikely(!p)) |
29505 | + goto out; | |
29506 | + | |
29507 | + err = 0; | |
29508 | + nh = whlist->nh_num; | |
29509 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
29510 | + p += AUFS_WH_PFX_LEN; | |
29511 | + for (u = 0; u < nh; u++) { | |
29512 | + head = whlist->nh_head + u; | |
c06a8ce3 AM |
29513 | + hlist_for_each_entry_safe(pos, n, head, wh_hash) { |
29514 | + destr = &pos->wh_str; | |
dece6358 AM |
29515 | + memcpy(p, destr->name, destr->len); |
29516 | + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN, | |
c06a8ce3 | 29517 | + pos->wh_ino, pos->wh_type, delist); |
dece6358 AM |
29518 | + if (unlikely(err)) |
29519 | + break; | |
29520 | + } | |
29521 | + } | |
29522 | + | |
537831f9 | 29523 | + free_page((unsigned long)o); |
dece6358 | 29524 | + |
4f0767ce | 29525 | +out: |
dece6358 AM |
29526 | + AuTraceErr(err); |
29527 | + return err; | |
29528 | +#else | |
29529 | + return 0; | |
29530 | +#endif | |
29531 | +} | |
29532 | + | |
1facf9fc | 29533 | +static int au_do_read_vdir(struct fillvdir_arg *arg) |
29534 | +{ | |
29535 | + int err; | |
dece6358 | 29536 | + unsigned int rdhash; |
1facf9fc | 29537 | + loff_t offset; |
dece6358 AM |
29538 | + aufs_bindex_t bend, bindex, bstart; |
29539 | + unsigned char shwh; | |
1facf9fc | 29540 | + struct file *hf, *file; |
29541 | + struct super_block *sb; | |
29542 | + | |
1facf9fc | 29543 | + file = arg->file; |
2000de60 | 29544 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
29545 | + SiMustAnyLock(sb); |
29546 | + | |
29547 | + rdhash = au_sbi(sb)->si_rdhash; | |
1308ab2a | 29548 | + if (!rdhash) |
29549 | + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL)); | |
dece6358 AM |
29550 | + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS); |
29551 | + if (unlikely(err)) | |
1facf9fc | 29552 | + goto out; |
dece6358 AM |
29553 | + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS); |
29554 | + if (unlikely(err)) | |
1facf9fc | 29555 | + goto out_delist; |
29556 | + | |
29557 | + err = 0; | |
29558 | + arg->flags = 0; | |
dece6358 AM |
29559 | + shwh = 0; |
29560 | + if (au_opt_test(au_mntflags(sb), SHWH)) { | |
29561 | + shwh = 1; | |
29562 | + au_fset_fillvdir(arg->flags, SHWH); | |
29563 | + } | |
29564 | + bstart = au_fbstart(file); | |
4a4d8108 | 29565 | + bend = au_fbend_dir(file); |
dece6358 | 29566 | + for (bindex = bstart; !err && bindex <= bend; bindex++) { |
4a4d8108 | 29567 | + hf = au_hf_dir(file, bindex); |
1facf9fc | 29568 | + if (!hf) |
29569 | + continue; | |
29570 | + | |
29571 | + offset = vfsub_llseek(hf, 0, SEEK_SET); | |
29572 | + err = offset; | |
29573 | + if (unlikely(offset)) | |
29574 | + break; | |
29575 | + | |
29576 | + arg->bindex = bindex; | |
29577 | + au_fclr_fillvdir(arg->flags, WHABLE); | |
dece6358 AM |
29578 | + if (shwh |
29579 | + || (bindex != bend | |
29580 | + && au_br_whable(au_sbr_perm(sb, bindex)))) | |
1facf9fc | 29581 | + au_fset_fillvdir(arg->flags, WHABLE); |
29582 | + do { | |
29583 | + arg->err = 0; | |
29584 | + au_fclr_fillvdir(arg->flags, CALLED); | |
29585 | + /* smp_mb(); */ | |
392086de | 29586 | + err = vfsub_iterate_dir(hf, &arg->ctx); |
1facf9fc | 29587 | + if (err >= 0) |
29588 | + err = arg->err; | |
29589 | + } while (!err && au_ftest_fillvdir(arg->flags, CALLED)); | |
392086de AM |
29590 | + |
29591 | + /* | |
29592 | + * dir_relax() may be good for concurrency, but aufs should not | |
29593 | + * use it since it will cause a lockdep problem. | |
29594 | + */ | |
1facf9fc | 29595 | + } |
dece6358 AM |
29596 | + |
29597 | + if (!err && shwh) | |
29598 | + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist); | |
29599 | + | |
29600 | + au_nhash_wh_free(&arg->whlist); | |
1facf9fc | 29601 | + |
4f0767ce | 29602 | +out_delist: |
dece6358 | 29603 | + au_nhash_de_free(&arg->delist); |
4f0767ce | 29604 | +out: |
1facf9fc | 29605 | + return err; |
29606 | +} | |
29607 | + | |
29608 | +static int read_vdir(struct file *file, int may_read) | |
29609 | +{ | |
29610 | + int err; | |
29611 | + unsigned long expire; | |
29612 | + unsigned char do_read; | |
392086de AM |
29613 | + struct fillvdir_arg arg = { |
29614 | + .ctx = { | |
2000de60 | 29615 | + .actor = fillvdir |
392086de AM |
29616 | + } |
29617 | + }; | |
1facf9fc | 29618 | + struct inode *inode; |
29619 | + struct au_vdir *vdir, *allocated; | |
29620 | + | |
29621 | + err = 0; | |
c06a8ce3 | 29622 | + inode = file_inode(file); |
1facf9fc | 29623 | + IMustLock(inode); |
dece6358 AM |
29624 | + SiMustAnyLock(inode->i_sb); |
29625 | + | |
1facf9fc | 29626 | + allocated = NULL; |
29627 | + do_read = 0; | |
29628 | + expire = au_sbi(inode->i_sb)->si_rdcache; | |
29629 | + vdir = au_ivdir(inode); | |
29630 | + if (!vdir) { | |
29631 | + do_read = 1; | |
1308ab2a | 29632 | + vdir = alloc_vdir(file); |
1facf9fc | 29633 | + err = PTR_ERR(vdir); |
29634 | + if (IS_ERR(vdir)) | |
29635 | + goto out; | |
29636 | + err = 0; | |
29637 | + allocated = vdir; | |
29638 | + } else if (may_read | |
29639 | + && (inode->i_version != vdir->vd_version | |
29640 | + || time_after(jiffies, vdir->vd_jiffy + expire))) { | |
29641 | + do_read = 1; | |
29642 | + err = reinit_vdir(vdir); | |
29643 | + if (unlikely(err)) | |
29644 | + goto out; | |
29645 | + } | |
29646 | + | |
29647 | + if (!do_read) | |
29648 | + return 0; /* success */ | |
29649 | + | |
29650 | + arg.file = file; | |
29651 | + arg.vdir = vdir; | |
29652 | + err = au_do_read_vdir(&arg); | |
29653 | + if (!err) { | |
392086de | 29654 | + /* file->f_pos = 0; */ /* todo: ctx->pos? */ |
1facf9fc | 29655 | + vdir->vd_version = inode->i_version; |
29656 | + vdir->vd_last.ul = 0; | |
29657 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
29658 | + if (allocated) | |
29659 | + au_set_ivdir(inode, allocated); | |
29660 | + } else if (allocated) | |
29661 | + au_vdir_free(allocated); | |
29662 | + | |
4f0767ce | 29663 | +out: |
1facf9fc | 29664 | + return err; |
29665 | +} | |
29666 | + | |
29667 | +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src) | |
29668 | +{ | |
29669 | + int err, rerr; | |
29670 | + unsigned long ul, n; | |
29671 | + const unsigned int deblk_sz = src->vd_deblk_sz; | |
29672 | + | |
29673 | + AuDebugOn(tgt->vd_nblk != 1); | |
29674 | + | |
29675 | + err = -ENOMEM; | |
29676 | + if (tgt->vd_nblk < src->vd_nblk) { | |
29677 | + unsigned char **p; | |
29678 | + | |
dece6358 AM |
29679 | + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk, |
29680 | + GFP_NOFS); | |
1facf9fc | 29681 | + if (unlikely(!p)) |
29682 | + goto out; | |
29683 | + tgt->vd_deblk = p; | |
29684 | + } | |
29685 | + | |
1308ab2a | 29686 | + if (tgt->vd_deblk_sz != deblk_sz) { |
29687 | + unsigned char *p; | |
29688 | + | |
29689 | + tgt->vd_deblk_sz = deblk_sz; | |
29690 | + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS); | |
29691 | + if (unlikely(!p)) | |
29692 | + goto out; | |
29693 | + tgt->vd_deblk[0] = p; | |
29694 | + } | |
1facf9fc | 29695 | + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz); |
1facf9fc | 29696 | + tgt->vd_version = src->vd_version; |
29697 | + tgt->vd_jiffy = src->vd_jiffy; | |
29698 | + | |
29699 | + n = src->vd_nblk; | |
29700 | + for (ul = 1; ul < n; ul++) { | |
dece6358 AM |
29701 | + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz, |
29702 | + GFP_NOFS); | |
29703 | + if (unlikely(!tgt->vd_deblk[ul])) | |
1facf9fc | 29704 | + goto out; |
1308ab2a | 29705 | + tgt->vd_nblk++; |
1facf9fc | 29706 | + } |
1308ab2a | 29707 | + tgt->vd_nblk = n; |
29708 | + tgt->vd_last.ul = tgt->vd_last.ul; | |
29709 | + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul]; | |
29710 | + tgt->vd_last.p.deblk += src->vd_last.p.deblk | |
29711 | + - src->vd_deblk[src->vd_last.ul]; | |
1facf9fc | 29712 | + /* smp_mb(); */ |
29713 | + return 0; /* success */ | |
29714 | + | |
4f0767ce | 29715 | +out: |
1facf9fc | 29716 | + rerr = reinit_vdir(tgt); |
29717 | + BUG_ON(rerr); | |
29718 | + return err; | |
29719 | +} | |
29720 | + | |
29721 | +int au_vdir_init(struct file *file) | |
29722 | +{ | |
29723 | + int err; | |
29724 | + struct inode *inode; | |
29725 | + struct au_vdir *vdir_cache, *allocated; | |
29726 | + | |
392086de | 29727 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 29728 | + err = read_vdir(file, !file->f_pos); |
29729 | + if (unlikely(err)) | |
29730 | + goto out; | |
29731 | + | |
29732 | + allocated = NULL; | |
29733 | + vdir_cache = au_fvdir_cache(file); | |
29734 | + if (!vdir_cache) { | |
1308ab2a | 29735 | + vdir_cache = alloc_vdir(file); |
1facf9fc | 29736 | + err = PTR_ERR(vdir_cache); |
29737 | + if (IS_ERR(vdir_cache)) | |
29738 | + goto out; | |
29739 | + allocated = vdir_cache; | |
29740 | + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) { | |
392086de | 29741 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 29742 | + err = reinit_vdir(vdir_cache); |
29743 | + if (unlikely(err)) | |
29744 | + goto out; | |
29745 | + } else | |
29746 | + return 0; /* success */ | |
29747 | + | |
c06a8ce3 | 29748 | + inode = file_inode(file); |
1facf9fc | 29749 | + err = copy_vdir(vdir_cache, au_ivdir(inode)); |
29750 | + if (!err) { | |
29751 | + file->f_version = inode->i_version; | |
29752 | + if (allocated) | |
29753 | + au_set_fvdir_cache(file, allocated); | |
29754 | + } else if (allocated) | |
29755 | + au_vdir_free(allocated); | |
29756 | + | |
4f0767ce | 29757 | +out: |
1facf9fc | 29758 | + return err; |
29759 | +} | |
29760 | + | |
29761 | +static loff_t calc_offset(struct au_vdir *vdir) | |
29762 | +{ | |
29763 | + loff_t offset; | |
29764 | + union au_vdir_deblk_p p; | |
29765 | + | |
29766 | + p.deblk = vdir->vd_deblk[vdir->vd_last.ul]; | |
29767 | + offset = vdir->vd_last.p.deblk - p.deblk; | |
29768 | + offset += vdir->vd_deblk_sz * vdir->vd_last.ul; | |
29769 | + return offset; | |
29770 | +} | |
29771 | + | |
29772 | +/* returns true or false */ | |
392086de | 29773 | +static int seek_vdir(struct file *file, struct dir_context *ctx) |
1facf9fc | 29774 | +{ |
29775 | + int valid; | |
29776 | + unsigned int deblk_sz; | |
29777 | + unsigned long ul, n; | |
29778 | + loff_t offset; | |
29779 | + union au_vdir_deblk_p p, deblk_end; | |
29780 | + struct au_vdir *vdir_cache; | |
29781 | + | |
29782 | + valid = 1; | |
29783 | + vdir_cache = au_fvdir_cache(file); | |
29784 | + offset = calc_offset(vdir_cache); | |
29785 | + AuDbg("offset %lld\n", offset); | |
392086de | 29786 | + if (ctx->pos == offset) |
1facf9fc | 29787 | + goto out; |
29788 | + | |
29789 | + vdir_cache->vd_last.ul = 0; | |
29790 | + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0]; | |
392086de | 29791 | + if (!ctx->pos) |
1facf9fc | 29792 | + goto out; |
29793 | + | |
29794 | + valid = 0; | |
29795 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
392086de | 29796 | + ul = div64_u64(ctx->pos, deblk_sz); |
1facf9fc | 29797 | + AuDbg("ul %lu\n", ul); |
29798 | + if (ul >= vdir_cache->vd_nblk) | |
29799 | + goto out; | |
29800 | + | |
29801 | + n = vdir_cache->vd_nblk; | |
29802 | + for (; ul < n; ul++) { | |
29803 | + p.deblk = vdir_cache->vd_deblk[ul]; | |
29804 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29805 | + offset = ul; | |
29806 | + offset *= deblk_sz; | |
392086de | 29807 | + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) { |
1facf9fc | 29808 | + unsigned int l; |
29809 | + | |
29810 | + l = calc_size(p.de->de_str.len); | |
29811 | + offset += l; | |
29812 | + p.deblk += l; | |
29813 | + } | |
29814 | + if (!is_deblk_end(&p, &deblk_end)) { | |
29815 | + valid = 1; | |
29816 | + vdir_cache->vd_last.ul = ul; | |
29817 | + vdir_cache->vd_last.p = p; | |
29818 | + break; | |
29819 | + } | |
29820 | + } | |
29821 | + | |
4f0767ce | 29822 | +out: |
1facf9fc | 29823 | + /* smp_mb(); */ |
29824 | + AuTraceErr(!valid); | |
29825 | + return valid; | |
29826 | +} | |
29827 | + | |
392086de | 29828 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx) |
1facf9fc | 29829 | +{ |
1facf9fc | 29830 | + unsigned int l, deblk_sz; |
29831 | + union au_vdir_deblk_p deblk_end; | |
29832 | + struct au_vdir *vdir_cache; | |
29833 | + struct au_vdir_de *de; | |
29834 | + | |
29835 | + vdir_cache = au_fvdir_cache(file); | |
392086de | 29836 | + if (!seek_vdir(file, ctx)) |
1facf9fc | 29837 | + return 0; |
29838 | + | |
29839 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
29840 | + while (1) { | |
29841 | + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
29842 | + deblk_end.deblk += deblk_sz; | |
29843 | + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) { | |
29844 | + de = vdir_cache->vd_last.p.de; | |
29845 | + AuDbg("%.*s, off%lld, i%lu, dt%d\n", | |
392086de | 29846 | + de->de_str.len, de->de_str.name, ctx->pos, |
1facf9fc | 29847 | + (unsigned long)de->de_ino, de->de_type); |
392086de AM |
29848 | + if (unlikely(!dir_emit(ctx, de->de_str.name, |
29849 | + de->de_str.len, de->de_ino, | |
29850 | + de->de_type))) { | |
1facf9fc | 29851 | + /* todo: ignore the error caused by udba? */ |
29852 | + /* return err; */ | |
29853 | + return 0; | |
29854 | + } | |
29855 | + | |
29856 | + l = calc_size(de->de_str.len); | |
29857 | + vdir_cache->vd_last.p.deblk += l; | |
392086de | 29858 | + ctx->pos += l; |
1facf9fc | 29859 | + } |
29860 | + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) { | |
29861 | + vdir_cache->vd_last.ul++; | |
29862 | + vdir_cache->vd_last.p.deblk | |
29863 | + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
392086de | 29864 | + ctx->pos = deblk_sz * vdir_cache->vd_last.ul; |
1facf9fc | 29865 | + continue; |
29866 | + } | |
29867 | + break; | |
29868 | + } | |
29869 | + | |
29870 | + /* smp_mb(); */ | |
29871 | + return 0; | |
29872 | +} | |
7f207e10 AM |
29873 | diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c |
29874 | --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 29875 | +++ linux/fs/aufs/vfsub.c 2015-09-24 10:47:58.258053165 +0200 |
5527c038 | 29876 | @@ -0,0 +1,848 @@ |
1facf9fc | 29877 | +/* |
2000de60 | 29878 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 29879 | + * |
29880 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29881 | + * it under the terms of the GNU General Public License as published by | |
29882 | + * the Free Software Foundation; either version 2 of the License, or | |
29883 | + * (at your option) any later version. | |
dece6358 AM |
29884 | + * |
29885 | + * This program is distributed in the hope that it will be useful, | |
29886 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29887 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29888 | + * GNU General Public License for more details. | |
29889 | + * | |
29890 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29891 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29892 | + */ |
29893 | + | |
29894 | +/* | |
29895 | + * sub-routines for VFS | |
29896 | + */ | |
29897 | + | |
dece6358 AM |
29898 | +#include <linux/namei.h> |
29899 | +#include <linux/security.h> | |
29900 | +#include <linux/splice.h> | |
1facf9fc | 29901 | +#include "aufs.h" |
29902 | + | |
29903 | +int vfsub_update_h_iattr(struct path *h_path, int *did) | |
29904 | +{ | |
29905 | + int err; | |
29906 | + struct kstat st; | |
29907 | + struct super_block *h_sb; | |
29908 | + | |
29909 | + /* for remote fs, leave work for its getattr or d_revalidate */ | |
29910 | + /* for bad i_attr fs, handle them in aufs_getattr() */ | |
29911 | + /* still some fs may acquire i_mutex. we need to skip them */ | |
29912 | + err = 0; | |
29913 | + if (!did) | |
29914 | + did = &err; | |
29915 | + h_sb = h_path->dentry->d_sb; | |
29916 | + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb)); | |
29917 | + if (*did) | |
c06a8ce3 | 29918 | + err = vfs_getattr(h_path, &st); |
1facf9fc | 29919 | + |
29920 | + return err; | |
29921 | +} | |
29922 | + | |
29923 | +/* ---------------------------------------------------------------------- */ | |
29924 | + | |
4a4d8108 | 29925 | +struct file *vfsub_dentry_open(struct path *path, int flags) |
1308ab2a | 29926 | +{ |
29927 | + struct file *file; | |
29928 | + | |
b4510431 | 29929 | + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */, |
7f207e10 | 29930 | + current_cred()); |
2cbb1c4b JR |
29931 | + if (!IS_ERR_OR_NULL(file) |
29932 | + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | |
5527c038 | 29933 | + i_readcount_inc(d_inode(path->dentry)); |
4a4d8108 | 29934 | + |
1308ab2a | 29935 | + return file; |
29936 | +} | |
29937 | + | |
1facf9fc | 29938 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode) |
29939 | +{ | |
29940 | + struct file *file; | |
29941 | + | |
2cbb1c4b | 29942 | + lockdep_off(); |
7f207e10 | 29943 | + file = filp_open(path, |
2cbb1c4b | 29944 | + oflags /* | __FMODE_NONOTIFY */, |
7f207e10 | 29945 | + mode); |
2cbb1c4b | 29946 | + lockdep_on(); |
1facf9fc | 29947 | + if (IS_ERR(file)) |
29948 | + goto out; | |
29949 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
29950 | + | |
4f0767ce | 29951 | +out: |
1facf9fc | 29952 | + return file; |
29953 | +} | |
29954 | + | |
b912730e AM |
29955 | +/* |
29956 | + * Ideally this function should call VFS:do_last() in order to keep all its | |
29957 | + * checkings. But it is very hard for aufs to regenerate several VFS internal | |
29958 | + * structure such as nameidata. This is a second (or third) best approach. | |
29959 | + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open(). | |
29960 | + */ | |
29961 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
29962 | + struct vfsub_aopen_args *args, struct au_branch *br) | |
29963 | +{ | |
29964 | + int err; | |
29965 | + struct file *file = args->file; | |
29966 | + /* copied from linux/fs/namei.c:atomic_open() */ | |
29967 | + struct dentry *const DENTRY_NOT_SET = (void *)-1UL; | |
29968 | + | |
29969 | + IMustLock(dir); | |
29970 | + AuDebugOn(!dir->i_op->atomic_open); | |
29971 | + | |
29972 | + err = au_br_test_oflag(args->open_flag, br); | |
29973 | + if (unlikely(err)) | |
29974 | + goto out; | |
29975 | + | |
29976 | + args->file->f_path.dentry = DENTRY_NOT_SET; | |
29977 | + args->file->f_path.mnt = au_br_mnt(br); | |
29978 | + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag, | |
29979 | + args->create_mode, args->opened); | |
29980 | + if (err >= 0) { | |
29981 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
29982 | + if (*args->opened & FILE_CREATED) | |
29983 | + fsnotify_create(dir, dentry); | |
29984 | + } else | |
29985 | + goto out; | |
29986 | + | |
29987 | + | |
29988 | + if (!err) { | |
29989 | + /* todo: call VFS:may_open() here */ | |
29990 | + err = open_check_o_direct(file); | |
29991 | + /* todo: ima_file_check() too? */ | |
29992 | + if (!err && (args->open_flag & __FMODE_EXEC)) | |
29993 | + err = deny_write_access(file); | |
29994 | + if (unlikely(err)) | |
29995 | + /* note that the file is created and still opened */ | |
29996 | + goto out; | |
29997 | + } | |
29998 | + | |
29999 | + atomic_inc(&br->br_count); | |
30000 | + fsnotify_open(file); | |
30001 | + | |
30002 | +out: | |
30003 | + return err; | |
30004 | +} | |
30005 | + | |
1facf9fc | 30006 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path) |
30007 | +{ | |
30008 | + int err; | |
30009 | + | |
1facf9fc | 30010 | + err = kern_path(name, flags, path); |
5527c038 | 30011 | + if (!err && d_is_positive(path->dentry)) |
1facf9fc | 30012 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ |
30013 | + return err; | |
30014 | +} | |
30015 | + | |
30016 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, | |
30017 | + int len) | |
30018 | +{ | |
30019 | + struct path path = { | |
30020 | + .mnt = NULL | |
30021 | + }; | |
30022 | + | |
1308ab2a | 30023 | + /* VFS checks it too, but by WARN_ON_ONCE() */ |
5527c038 | 30024 | + IMustLock(d_inode(parent)); |
1facf9fc | 30025 | + |
30026 | + path.dentry = lookup_one_len(name, parent, len); | |
30027 | + if (IS_ERR(path.dentry)) | |
30028 | + goto out; | |
5527c038 | 30029 | + if (d_is_positive(path.dentry)) |
1facf9fc | 30030 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ |
30031 | + | |
4f0767ce | 30032 | +out: |
4a4d8108 | 30033 | + AuTraceErrPtr(path.dentry); |
1facf9fc | 30034 | + return path.dentry; |
30035 | +} | |
30036 | + | |
b4510431 | 30037 | +void vfsub_call_lkup_one(void *args) |
2cbb1c4b | 30038 | +{ |
b4510431 AM |
30039 | + struct vfsub_lkup_one_args *a = args; |
30040 | + *a->errp = vfsub_lkup_one(a->name, a->parent); | |
2cbb1c4b JR |
30041 | +} |
30042 | + | |
1facf9fc | 30043 | +/* ---------------------------------------------------------------------- */ |
30044 | + | |
30045 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30046 | + struct dentry *d2, struct au_hinode *hdir2) | |
30047 | +{ | |
30048 | + struct dentry *d; | |
30049 | + | |
2cbb1c4b | 30050 | + lockdep_off(); |
1facf9fc | 30051 | + d = lock_rename(d1, d2); |
2cbb1c4b | 30052 | + lockdep_on(); |
4a4d8108 | 30053 | + au_hn_suspend(hdir1); |
1facf9fc | 30054 | + if (hdir1 != hdir2) |
4a4d8108 | 30055 | + au_hn_suspend(hdir2); |
1facf9fc | 30056 | + |
30057 | + return d; | |
30058 | +} | |
30059 | + | |
30060 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30061 | + struct dentry *d2, struct au_hinode *hdir2) | |
30062 | +{ | |
4a4d8108 | 30063 | + au_hn_resume(hdir1); |
1facf9fc | 30064 | + if (hdir1 != hdir2) |
4a4d8108 | 30065 | + au_hn_resume(hdir2); |
2cbb1c4b | 30066 | + lockdep_off(); |
1facf9fc | 30067 | + unlock_rename(d1, d2); |
2cbb1c4b | 30068 | + lockdep_on(); |
1facf9fc | 30069 | +} |
30070 | + | |
30071 | +/* ---------------------------------------------------------------------- */ | |
30072 | + | |
b4510431 | 30073 | +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl) |
1facf9fc | 30074 | +{ |
30075 | + int err; | |
30076 | + struct dentry *d; | |
30077 | + | |
30078 | + IMustLock(dir); | |
30079 | + | |
30080 | + d = path->dentry; | |
30081 | + path->dentry = d->d_parent; | |
b752ccd1 | 30082 | + err = security_path_mknod(path, d, mode, 0); |
1facf9fc | 30083 | + path->dentry = d; |
30084 | + if (unlikely(err)) | |
30085 | + goto out; | |
30086 | + | |
c1595e42 | 30087 | + lockdep_off(); |
b4510431 | 30088 | + err = vfs_create(dir, path->dentry, mode, want_excl); |
c1595e42 | 30089 | + lockdep_on(); |
1facf9fc | 30090 | + if (!err) { |
30091 | + struct path tmp = *path; | |
30092 | + int did; | |
30093 | + | |
30094 | + vfsub_update_h_iattr(&tmp, &did); | |
30095 | + if (did) { | |
30096 | + tmp.dentry = path->dentry->d_parent; | |
30097 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30098 | + } | |
30099 | + /*ignore*/ | |
30100 | + } | |
30101 | + | |
4f0767ce | 30102 | +out: |
1facf9fc | 30103 | + return err; |
30104 | +} | |
30105 | + | |
30106 | +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname) | |
30107 | +{ | |
30108 | + int err; | |
30109 | + struct dentry *d; | |
30110 | + | |
30111 | + IMustLock(dir); | |
30112 | + | |
30113 | + d = path->dentry; | |
30114 | + path->dentry = d->d_parent; | |
b752ccd1 | 30115 | + err = security_path_symlink(path, d, symname); |
1facf9fc | 30116 | + path->dentry = d; |
30117 | + if (unlikely(err)) | |
30118 | + goto out; | |
30119 | + | |
c1595e42 | 30120 | + lockdep_off(); |
1facf9fc | 30121 | + err = vfs_symlink(dir, path->dentry, symname); |
c1595e42 | 30122 | + lockdep_on(); |
1facf9fc | 30123 | + if (!err) { |
30124 | + struct path tmp = *path; | |
30125 | + int did; | |
30126 | + | |
30127 | + vfsub_update_h_iattr(&tmp, &did); | |
30128 | + if (did) { | |
30129 | + tmp.dentry = path->dentry->d_parent; | |
30130 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30131 | + } | |
30132 | + /*ignore*/ | |
30133 | + } | |
30134 | + | |
4f0767ce | 30135 | +out: |
1facf9fc | 30136 | + return err; |
30137 | +} | |
30138 | + | |
30139 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev) | |
30140 | +{ | |
30141 | + int err; | |
30142 | + struct dentry *d; | |
30143 | + | |
30144 | + IMustLock(dir); | |
30145 | + | |
30146 | + d = path->dentry; | |
30147 | + path->dentry = d->d_parent; | |
027c5e7a | 30148 | + err = security_path_mknod(path, d, mode, new_encode_dev(dev)); |
1facf9fc | 30149 | + path->dentry = d; |
30150 | + if (unlikely(err)) | |
30151 | + goto out; | |
30152 | + | |
c1595e42 | 30153 | + lockdep_off(); |
1facf9fc | 30154 | + err = vfs_mknod(dir, path->dentry, mode, dev); |
c1595e42 | 30155 | + lockdep_on(); |
1facf9fc | 30156 | + if (!err) { |
30157 | + struct path tmp = *path; | |
30158 | + int did; | |
30159 | + | |
30160 | + vfsub_update_h_iattr(&tmp, &did); | |
30161 | + if (did) { | |
30162 | + tmp.dentry = path->dentry->d_parent; | |
30163 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30164 | + } | |
30165 | + /*ignore*/ | |
30166 | + } | |
30167 | + | |
4f0767ce | 30168 | +out: |
1facf9fc | 30169 | + return err; |
30170 | +} | |
30171 | + | |
30172 | +static int au_test_nlink(struct inode *inode) | |
30173 | +{ | |
30174 | + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */ | |
30175 | + | |
30176 | + if (!au_test_fs_no_limit_nlink(inode->i_sb) | |
30177 | + || inode->i_nlink < link_max) | |
30178 | + return 0; | |
30179 | + return -EMLINK; | |
30180 | +} | |
30181 | + | |
523b37e3 AM |
30182 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path, |
30183 | + struct inode **delegated_inode) | |
1facf9fc | 30184 | +{ |
30185 | + int err; | |
30186 | + struct dentry *d; | |
30187 | + | |
30188 | + IMustLock(dir); | |
30189 | + | |
5527c038 | 30190 | + err = au_test_nlink(d_inode(src_dentry)); |
1facf9fc | 30191 | + if (unlikely(err)) |
30192 | + return err; | |
30193 | + | |
b4510431 | 30194 | + /* we don't call may_linkat() */ |
1facf9fc | 30195 | + d = path->dentry; |
30196 | + path->dentry = d->d_parent; | |
b752ccd1 | 30197 | + err = security_path_link(src_dentry, path, d); |
1facf9fc | 30198 | + path->dentry = d; |
30199 | + if (unlikely(err)) | |
30200 | + goto out; | |
30201 | + | |
2cbb1c4b | 30202 | + lockdep_off(); |
523b37e3 | 30203 | + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode); |
2cbb1c4b | 30204 | + lockdep_on(); |
1facf9fc | 30205 | + if (!err) { |
30206 | + struct path tmp = *path; | |
30207 | + int did; | |
30208 | + | |
30209 | + /* fuse has different memory inode for the same inumber */ | |
30210 | + vfsub_update_h_iattr(&tmp, &did); | |
30211 | + if (did) { | |
30212 | + tmp.dentry = path->dentry->d_parent; | |
30213 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30214 | + tmp.dentry = src_dentry; | |
30215 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30216 | + } | |
30217 | + /*ignore*/ | |
30218 | + } | |
30219 | + | |
4f0767ce | 30220 | +out: |
1facf9fc | 30221 | + return err; |
30222 | +} | |
30223 | + | |
30224 | +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry, | |
523b37e3 AM |
30225 | + struct inode *dir, struct path *path, |
30226 | + struct inode **delegated_inode) | |
1facf9fc | 30227 | +{ |
30228 | + int err; | |
30229 | + struct path tmp = { | |
30230 | + .mnt = path->mnt | |
30231 | + }; | |
30232 | + struct dentry *d; | |
30233 | + | |
30234 | + IMustLock(dir); | |
30235 | + IMustLock(src_dir); | |
30236 | + | |
30237 | + d = path->dentry; | |
30238 | + path->dentry = d->d_parent; | |
30239 | + tmp.dentry = src_dentry->d_parent; | |
38d290e6 | 30240 | + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0); |
1facf9fc | 30241 | + path->dentry = d; |
30242 | + if (unlikely(err)) | |
30243 | + goto out; | |
30244 | + | |
2cbb1c4b | 30245 | + lockdep_off(); |
523b37e3 | 30246 | + err = vfs_rename(src_dir, src_dentry, dir, path->dentry, |
38d290e6 | 30247 | + delegated_inode, /*flags*/0); |
2cbb1c4b | 30248 | + lockdep_on(); |
1facf9fc | 30249 | + if (!err) { |
30250 | + int did; | |
30251 | + | |
30252 | + tmp.dentry = d->d_parent; | |
30253 | + vfsub_update_h_iattr(&tmp, &did); | |
30254 | + if (did) { | |
30255 | + tmp.dentry = src_dentry; | |
30256 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30257 | + tmp.dentry = src_dentry->d_parent; | |
30258 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30259 | + } | |
30260 | + /*ignore*/ | |
30261 | + } | |
30262 | + | |
4f0767ce | 30263 | +out: |
1facf9fc | 30264 | + return err; |
30265 | +} | |
30266 | + | |
30267 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode) | |
30268 | +{ | |
30269 | + int err; | |
30270 | + struct dentry *d; | |
30271 | + | |
30272 | + IMustLock(dir); | |
30273 | + | |
30274 | + d = path->dentry; | |
30275 | + path->dentry = d->d_parent; | |
b752ccd1 | 30276 | + err = security_path_mkdir(path, d, mode); |
1facf9fc | 30277 | + path->dentry = d; |
30278 | + if (unlikely(err)) | |
30279 | + goto out; | |
30280 | + | |
c1595e42 | 30281 | + lockdep_off(); |
1facf9fc | 30282 | + err = vfs_mkdir(dir, path->dentry, mode); |
c1595e42 | 30283 | + lockdep_on(); |
1facf9fc | 30284 | + if (!err) { |
30285 | + struct path tmp = *path; | |
30286 | + int did; | |
30287 | + | |
30288 | + vfsub_update_h_iattr(&tmp, &did); | |
30289 | + if (did) { | |
30290 | + tmp.dentry = path->dentry->d_parent; | |
30291 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30292 | + } | |
30293 | + /*ignore*/ | |
30294 | + } | |
30295 | + | |
4f0767ce | 30296 | +out: |
1facf9fc | 30297 | + return err; |
30298 | +} | |
30299 | + | |
30300 | +int vfsub_rmdir(struct inode *dir, struct path *path) | |
30301 | +{ | |
30302 | + int err; | |
30303 | + struct dentry *d; | |
30304 | + | |
30305 | + IMustLock(dir); | |
30306 | + | |
30307 | + d = path->dentry; | |
30308 | + path->dentry = d->d_parent; | |
b752ccd1 | 30309 | + err = security_path_rmdir(path, d); |
1facf9fc | 30310 | + path->dentry = d; |
30311 | + if (unlikely(err)) | |
30312 | + goto out; | |
30313 | + | |
2cbb1c4b | 30314 | + lockdep_off(); |
1facf9fc | 30315 | + err = vfs_rmdir(dir, path->dentry); |
2cbb1c4b | 30316 | + lockdep_on(); |
1facf9fc | 30317 | + if (!err) { |
30318 | + struct path tmp = { | |
30319 | + .dentry = path->dentry->d_parent, | |
30320 | + .mnt = path->mnt | |
30321 | + }; | |
30322 | + | |
30323 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
30324 | + } | |
30325 | + | |
4f0767ce | 30326 | +out: |
1facf9fc | 30327 | + return err; |
30328 | +} | |
30329 | + | |
30330 | +/* ---------------------------------------------------------------------- */ | |
30331 | + | |
9dbd164d | 30332 | +/* todo: support mmap_sem? */ |
1facf9fc | 30333 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, |
30334 | + loff_t *ppos) | |
30335 | +{ | |
30336 | + ssize_t err; | |
30337 | + | |
2cbb1c4b | 30338 | + lockdep_off(); |
1facf9fc | 30339 | + err = vfs_read(file, ubuf, count, ppos); |
2cbb1c4b | 30340 | + lockdep_on(); |
1facf9fc | 30341 | + if (err >= 0) |
30342 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30343 | + return err; | |
30344 | +} | |
30345 | + | |
30346 | +/* todo: kernel_read()? */ | |
30347 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
30348 | + loff_t *ppos) | |
30349 | +{ | |
30350 | + ssize_t err; | |
30351 | + mm_segment_t oldfs; | |
b752ccd1 AM |
30352 | + union { |
30353 | + void *k; | |
30354 | + char __user *u; | |
30355 | + } buf; | |
1facf9fc | 30356 | + |
b752ccd1 | 30357 | + buf.k = kbuf; |
1facf9fc | 30358 | + oldfs = get_fs(); |
30359 | + set_fs(KERNEL_DS); | |
b752ccd1 | 30360 | + err = vfsub_read_u(file, buf.u, count, ppos); |
1facf9fc | 30361 | + set_fs(oldfs); |
30362 | + return err; | |
30363 | +} | |
30364 | + | |
30365 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
30366 | + loff_t *ppos) | |
30367 | +{ | |
30368 | + ssize_t err; | |
30369 | + | |
2cbb1c4b | 30370 | + lockdep_off(); |
1facf9fc | 30371 | + err = vfs_write(file, ubuf, count, ppos); |
2cbb1c4b | 30372 | + lockdep_on(); |
1facf9fc | 30373 | + if (err >= 0) |
30374 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30375 | + return err; | |
30376 | +} | |
30377 | + | |
30378 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos) | |
30379 | +{ | |
30380 | + ssize_t err; | |
30381 | + mm_segment_t oldfs; | |
b752ccd1 AM |
30382 | + union { |
30383 | + void *k; | |
30384 | + const char __user *u; | |
30385 | + } buf; | |
1facf9fc | 30386 | + |
b752ccd1 | 30387 | + buf.k = kbuf; |
1facf9fc | 30388 | + oldfs = get_fs(); |
30389 | + set_fs(KERNEL_DS); | |
b752ccd1 | 30390 | + err = vfsub_write_u(file, buf.u, count, ppos); |
1facf9fc | 30391 | + set_fs(oldfs); |
30392 | + return err; | |
30393 | +} | |
30394 | + | |
4a4d8108 AM |
30395 | +int vfsub_flush(struct file *file, fl_owner_t id) |
30396 | +{ | |
30397 | + int err; | |
30398 | + | |
30399 | + err = 0; | |
523b37e3 | 30400 | + if (file->f_op->flush) { |
2000de60 | 30401 | + if (!au_test_nfs(file->f_path.dentry->d_sb)) |
2cbb1c4b JR |
30402 | + err = file->f_op->flush(file, id); |
30403 | + else { | |
30404 | + lockdep_off(); | |
30405 | + err = file->f_op->flush(file, id); | |
30406 | + lockdep_on(); | |
30407 | + } | |
4a4d8108 AM |
30408 | + if (!err) |
30409 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); | |
30410 | + /*ignore*/ | |
30411 | + } | |
30412 | + return err; | |
30413 | +} | |
30414 | + | |
392086de | 30415 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx) |
1facf9fc | 30416 | +{ |
30417 | + int err; | |
30418 | + | |
523b37e3 | 30419 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 30420 | + |
2cbb1c4b | 30421 | + lockdep_off(); |
392086de | 30422 | + err = iterate_dir(file, ctx); |
2cbb1c4b | 30423 | + lockdep_on(); |
1facf9fc | 30424 | + if (err >= 0) |
30425 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30426 | + return err; | |
30427 | +} | |
30428 | + | |
30429 | +long vfsub_splice_to(struct file *in, loff_t *ppos, | |
30430 | + struct pipe_inode_info *pipe, size_t len, | |
30431 | + unsigned int flags) | |
30432 | +{ | |
30433 | + long err; | |
30434 | + | |
2cbb1c4b | 30435 | + lockdep_off(); |
0fc653ad | 30436 | + err = do_splice_to(in, ppos, pipe, len, flags); |
2cbb1c4b | 30437 | + lockdep_on(); |
4a4d8108 | 30438 | + file_accessed(in); |
1facf9fc | 30439 | + if (err >= 0) |
30440 | + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/ | |
30441 | + return err; | |
30442 | +} | |
30443 | + | |
30444 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
30445 | + loff_t *ppos, size_t len, unsigned int flags) | |
30446 | +{ | |
30447 | + long err; | |
30448 | + | |
2cbb1c4b | 30449 | + lockdep_off(); |
0fc653ad | 30450 | + err = do_splice_from(pipe, out, ppos, len, flags); |
2cbb1c4b | 30451 | + lockdep_on(); |
1facf9fc | 30452 | + if (err >= 0) |
30453 | + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/ | |
30454 | + return err; | |
30455 | +} | |
30456 | + | |
53392da6 AM |
30457 | +int vfsub_fsync(struct file *file, struct path *path, int datasync) |
30458 | +{ | |
30459 | + int err; | |
30460 | + | |
30461 | + /* file can be NULL */ | |
30462 | + lockdep_off(); | |
30463 | + err = vfs_fsync(file, datasync); | |
30464 | + lockdep_on(); | |
30465 | + if (!err) { | |
30466 | + if (!path) { | |
30467 | + AuDebugOn(!file); | |
30468 | + path = &file->f_path; | |
30469 | + } | |
30470 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ | |
30471 | + } | |
30472 | + return err; | |
30473 | +} | |
30474 | + | |
1facf9fc | 30475 | +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */ |
30476 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, | |
30477 | + struct file *h_file) | |
30478 | +{ | |
30479 | + int err; | |
30480 | + struct inode *h_inode; | |
c06a8ce3 | 30481 | + struct super_block *h_sb; |
1facf9fc | 30482 | + |
1facf9fc | 30483 | + if (!h_file) { |
c06a8ce3 AM |
30484 | + err = vfsub_truncate(h_path, length); |
30485 | + goto out; | |
1facf9fc | 30486 | + } |
30487 | + | |
5527c038 | 30488 | + h_inode = d_inode(h_path->dentry); |
c06a8ce3 AM |
30489 | + h_sb = h_inode->i_sb; |
30490 | + lockdep_off(); | |
30491 | + sb_start_write(h_sb); | |
30492 | + lockdep_on(); | |
1facf9fc | 30493 | + err = locks_verify_truncate(h_inode, h_file, length); |
30494 | + if (!err) | |
953406b4 | 30495 | + err = security_path_truncate(h_path); |
2cbb1c4b JR |
30496 | + if (!err) { |
30497 | + lockdep_off(); | |
1facf9fc | 30498 | + err = do_truncate(h_path->dentry, length, attr, h_file); |
2cbb1c4b JR |
30499 | + lockdep_on(); |
30500 | + } | |
c06a8ce3 AM |
30501 | + lockdep_off(); |
30502 | + sb_end_write(h_sb); | |
30503 | + lockdep_on(); | |
1facf9fc | 30504 | + |
4f0767ce | 30505 | +out: |
1facf9fc | 30506 | + return err; |
30507 | +} | |
30508 | + | |
30509 | +/* ---------------------------------------------------------------------- */ | |
30510 | + | |
30511 | +struct au_vfsub_mkdir_args { | |
30512 | + int *errp; | |
30513 | + struct inode *dir; | |
30514 | + struct path *path; | |
30515 | + int mode; | |
30516 | +}; | |
30517 | + | |
30518 | +static void au_call_vfsub_mkdir(void *args) | |
30519 | +{ | |
30520 | + struct au_vfsub_mkdir_args *a = args; | |
30521 | + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode); | |
30522 | +} | |
30523 | + | |
30524 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode) | |
30525 | +{ | |
30526 | + int err, do_sio, wkq_err; | |
30527 | + | |
30528 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
30529 | + if (!do_sio) { |
30530 | + lockdep_off(); | |
1facf9fc | 30531 | + err = vfsub_mkdir(dir, path, mode); |
c1595e42 JR |
30532 | + lockdep_on(); |
30533 | + } else { | |
1facf9fc | 30534 | + struct au_vfsub_mkdir_args args = { |
30535 | + .errp = &err, | |
30536 | + .dir = dir, | |
30537 | + .path = path, | |
30538 | + .mode = mode | |
30539 | + }; | |
30540 | + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args); | |
30541 | + if (unlikely(wkq_err)) | |
30542 | + err = wkq_err; | |
30543 | + } | |
30544 | + | |
30545 | + return err; | |
30546 | +} | |
30547 | + | |
30548 | +struct au_vfsub_rmdir_args { | |
30549 | + int *errp; | |
30550 | + struct inode *dir; | |
30551 | + struct path *path; | |
30552 | +}; | |
30553 | + | |
30554 | +static void au_call_vfsub_rmdir(void *args) | |
30555 | +{ | |
30556 | + struct au_vfsub_rmdir_args *a = args; | |
30557 | + *a->errp = vfsub_rmdir(a->dir, a->path); | |
30558 | +} | |
30559 | + | |
30560 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path) | |
30561 | +{ | |
30562 | + int err, do_sio, wkq_err; | |
30563 | + | |
30564 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
30565 | + if (!do_sio) { |
30566 | + lockdep_off(); | |
1facf9fc | 30567 | + err = vfsub_rmdir(dir, path); |
c1595e42 JR |
30568 | + lockdep_on(); |
30569 | + } else { | |
1facf9fc | 30570 | + struct au_vfsub_rmdir_args args = { |
30571 | + .errp = &err, | |
30572 | + .dir = dir, | |
30573 | + .path = path | |
30574 | + }; | |
30575 | + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args); | |
30576 | + if (unlikely(wkq_err)) | |
30577 | + err = wkq_err; | |
30578 | + } | |
30579 | + | |
30580 | + return err; | |
30581 | +} | |
30582 | + | |
30583 | +/* ---------------------------------------------------------------------- */ | |
30584 | + | |
30585 | +struct notify_change_args { | |
30586 | + int *errp; | |
30587 | + struct path *path; | |
30588 | + struct iattr *ia; | |
523b37e3 | 30589 | + struct inode **delegated_inode; |
1facf9fc | 30590 | +}; |
30591 | + | |
30592 | +static void call_notify_change(void *args) | |
30593 | +{ | |
30594 | + struct notify_change_args *a = args; | |
30595 | + struct inode *h_inode; | |
30596 | + | |
5527c038 | 30597 | + h_inode = d_inode(a->path->dentry); |
1facf9fc | 30598 | + IMustLock(h_inode); |
30599 | + | |
30600 | + *a->errp = -EPERM; | |
30601 | + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) { | |
c1595e42 | 30602 | + lockdep_off(); |
523b37e3 AM |
30603 | + *a->errp = notify_change(a->path->dentry, a->ia, |
30604 | + a->delegated_inode); | |
c1595e42 | 30605 | + lockdep_on(); |
1facf9fc | 30606 | + if (!*a->errp) |
30607 | + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/ | |
30608 | + } | |
30609 | + AuTraceErr(*a->errp); | |
30610 | +} | |
30611 | + | |
523b37e3 AM |
30612 | +int vfsub_notify_change(struct path *path, struct iattr *ia, |
30613 | + struct inode **delegated_inode) | |
1facf9fc | 30614 | +{ |
30615 | + int err; | |
30616 | + struct notify_change_args args = { | |
523b37e3 AM |
30617 | + .errp = &err, |
30618 | + .path = path, | |
30619 | + .ia = ia, | |
30620 | + .delegated_inode = delegated_inode | |
1facf9fc | 30621 | + }; |
30622 | + | |
30623 | + call_notify_change(&args); | |
30624 | + | |
30625 | + return err; | |
30626 | +} | |
30627 | + | |
523b37e3 AM |
30628 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
30629 | + struct inode **delegated_inode) | |
1facf9fc | 30630 | +{ |
30631 | + int err, wkq_err; | |
30632 | + struct notify_change_args args = { | |
523b37e3 AM |
30633 | + .errp = &err, |
30634 | + .path = path, | |
30635 | + .ia = ia, | |
30636 | + .delegated_inode = delegated_inode | |
1facf9fc | 30637 | + }; |
30638 | + | |
30639 | + wkq_err = au_wkq_wait(call_notify_change, &args); | |
30640 | + if (unlikely(wkq_err)) | |
30641 | + err = wkq_err; | |
30642 | + | |
30643 | + return err; | |
30644 | +} | |
30645 | + | |
30646 | +/* ---------------------------------------------------------------------- */ | |
30647 | + | |
30648 | +struct unlink_args { | |
30649 | + int *errp; | |
30650 | + struct inode *dir; | |
30651 | + struct path *path; | |
523b37e3 | 30652 | + struct inode **delegated_inode; |
1facf9fc | 30653 | +}; |
30654 | + | |
30655 | +static void call_unlink(void *args) | |
30656 | +{ | |
30657 | + struct unlink_args *a = args; | |
30658 | + struct dentry *d = a->path->dentry; | |
30659 | + struct inode *h_inode; | |
30660 | + const int stop_sillyrename = (au_test_nfs(d->d_sb) | |
c1595e42 | 30661 | + && au_dcount(d) == 1); |
1facf9fc | 30662 | + |
30663 | + IMustLock(a->dir); | |
30664 | + | |
30665 | + a->path->dentry = d->d_parent; | |
30666 | + *a->errp = security_path_unlink(a->path, d); | |
30667 | + a->path->dentry = d; | |
30668 | + if (unlikely(*a->errp)) | |
30669 | + return; | |
30670 | + | |
30671 | + if (!stop_sillyrename) | |
30672 | + dget(d); | |
5527c038 JR |
30673 | + h_inode = NULL; |
30674 | + if (d_is_positive(d)) { | |
30675 | + h_inode = d_inode(d); | |
027c5e7a | 30676 | + ihold(h_inode); |
5527c038 | 30677 | + } |
1facf9fc | 30678 | + |
2cbb1c4b | 30679 | + lockdep_off(); |
523b37e3 | 30680 | + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode); |
2cbb1c4b | 30681 | + lockdep_on(); |
1facf9fc | 30682 | + if (!*a->errp) { |
30683 | + struct path tmp = { | |
30684 | + .dentry = d->d_parent, | |
30685 | + .mnt = a->path->mnt | |
30686 | + }; | |
30687 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
30688 | + } | |
30689 | + | |
30690 | + if (!stop_sillyrename) | |
30691 | + dput(d); | |
30692 | + if (h_inode) | |
30693 | + iput(h_inode); | |
30694 | + | |
30695 | + AuTraceErr(*a->errp); | |
30696 | +} | |
30697 | + | |
30698 | +/* | |
30699 | + * @dir: must be locked. | |
30700 | + * @dentry: target dentry. | |
30701 | + */ | |
523b37e3 AM |
30702 | +int vfsub_unlink(struct inode *dir, struct path *path, |
30703 | + struct inode **delegated_inode, int force) | |
1facf9fc | 30704 | +{ |
30705 | + int err; | |
30706 | + struct unlink_args args = { | |
523b37e3 AM |
30707 | + .errp = &err, |
30708 | + .dir = dir, | |
30709 | + .path = path, | |
30710 | + .delegated_inode = delegated_inode | |
1facf9fc | 30711 | + }; |
30712 | + | |
30713 | + if (!force) | |
30714 | + call_unlink(&args); | |
30715 | + else { | |
30716 | + int wkq_err; | |
30717 | + | |
30718 | + wkq_err = au_wkq_wait(call_unlink, &args); | |
30719 | + if (unlikely(wkq_err)) | |
30720 | + err = wkq_err; | |
30721 | + } | |
30722 | + | |
30723 | + return err; | |
30724 | +} | |
7f207e10 AM |
30725 | diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h |
30726 | --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 30727 | +++ linux/fs/aufs/vfsub.h 2015-09-24 10:47:58.258053165 +0200 |
b912730e | 30728 | @@ -0,0 +1,286 @@ |
1facf9fc | 30729 | +/* |
2000de60 | 30730 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 30731 | + * |
30732 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30733 | + * it under the terms of the GNU General Public License as published by | |
30734 | + * the Free Software Foundation; either version 2 of the License, or | |
30735 | + * (at your option) any later version. | |
dece6358 AM |
30736 | + * |
30737 | + * This program is distributed in the hope that it will be useful, | |
30738 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30739 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30740 | + * GNU General Public License for more details. | |
30741 | + * | |
30742 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30743 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30744 | + */ |
30745 | + | |
30746 | +/* | |
30747 | + * sub-routines for VFS | |
30748 | + */ | |
30749 | + | |
30750 | +#ifndef __AUFS_VFSUB_H__ | |
30751 | +#define __AUFS_VFSUB_H__ | |
30752 | + | |
30753 | +#ifdef __KERNEL__ | |
30754 | + | |
30755 | +#include <linux/fs.h> | |
b4510431 | 30756 | +#include <linux/mount.h> |
c1595e42 | 30757 | +#include <linux/xattr.h> |
7f207e10 | 30758 | +#include "debug.h" |
1facf9fc | 30759 | + |
7f207e10 | 30760 | +/* copied from linux/fs/internal.h */ |
2cbb1c4b | 30761 | +/* todo: BAD approach!! */ |
c06a8ce3 | 30762 | +extern void __mnt_drop_write(struct vfsmount *); |
2cbb1c4b | 30763 | +extern spinlock_t inode_sb_list_lock; |
b912730e | 30764 | +extern int open_check_o_direct(struct file *f); |
7f207e10 AM |
30765 | + |
30766 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 30767 | + |
30768 | +/* lock subclass for lower inode */ | |
30769 | +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */ | |
30770 | +/* reduce? gave up. */ | |
30771 | +enum { | |
c1595e42 | 30772 | + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */ |
1facf9fc | 30773 | + AuLsc_I_PARENT, /* lower inode, parent first */ |
30774 | + AuLsc_I_PARENT2, /* copyup dirs */ | |
dece6358 | 30775 | + AuLsc_I_PARENT3, /* copyup wh */ |
1facf9fc | 30776 | + AuLsc_I_CHILD, |
30777 | + AuLsc_I_CHILD2, | |
30778 | + AuLsc_I_End | |
30779 | +}; | |
30780 | + | |
30781 | +/* to debug easier, do not make them inlined functions */ | |
30782 | +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx)) | |
30783 | +#define IMustLock(i) MtxMustLock(&(i)->i_mutex) | |
30784 | + | |
30785 | +/* ---------------------------------------------------------------------- */ | |
30786 | + | |
7f207e10 AM |
30787 | +static inline void vfsub_drop_nlink(struct inode *inode) |
30788 | +{ | |
30789 | + AuDebugOn(!inode->i_nlink); | |
30790 | + drop_nlink(inode); | |
30791 | +} | |
30792 | + | |
027c5e7a AM |
30793 | +static inline void vfsub_dead_dir(struct inode *inode) |
30794 | +{ | |
30795 | + AuDebugOn(!S_ISDIR(inode->i_mode)); | |
30796 | + inode->i_flags |= S_DEAD; | |
30797 | + clear_nlink(inode); | |
30798 | +} | |
30799 | + | |
392086de AM |
30800 | +static inline int vfsub_native_ro(struct inode *inode) |
30801 | +{ | |
30802 | + return (inode->i_sb->s_flags & MS_RDONLY) | |
30803 | + || IS_RDONLY(inode) | |
30804 | + /* || IS_APPEND(inode) */ | |
30805 | + || IS_IMMUTABLE(inode); | |
30806 | +} | |
30807 | + | |
7f207e10 AM |
30808 | +/* ---------------------------------------------------------------------- */ |
30809 | + | |
30810 | +int vfsub_update_h_iattr(struct path *h_path, int *did); | |
30811 | +struct file *vfsub_dentry_open(struct path *path, int flags); | |
30812 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode); | |
b912730e AM |
30813 | +struct vfsub_aopen_args { |
30814 | + struct file *file; | |
30815 | + unsigned int open_flag; | |
30816 | + umode_t create_mode; | |
30817 | + int *opened; | |
30818 | +}; | |
30819 | +struct au_branch; | |
30820 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
30821 | + struct vfsub_aopen_args *args, struct au_branch *br); | |
1facf9fc | 30822 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path); |
b4510431 | 30823 | + |
1facf9fc | 30824 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
30825 | + int len); | |
b4510431 AM |
30826 | + |
30827 | +struct vfsub_lkup_one_args { | |
30828 | + struct dentry **errp; | |
30829 | + struct qstr *name; | |
30830 | + struct dentry *parent; | |
30831 | +}; | |
30832 | + | |
30833 | +static inline struct dentry *vfsub_lkup_one(struct qstr *name, | |
30834 | + struct dentry *parent) | |
30835 | +{ | |
30836 | + return vfsub_lookup_one_len(name->name, parent, name->len); | |
30837 | +} | |
30838 | + | |
30839 | +void vfsub_call_lkup_one(void *args); | |
30840 | + | |
30841 | +/* ---------------------------------------------------------------------- */ | |
30842 | + | |
30843 | +static inline int vfsub_mnt_want_write(struct vfsmount *mnt) | |
30844 | +{ | |
30845 | + int err; | |
076b876e | 30846 | + |
b4510431 AM |
30847 | + lockdep_off(); |
30848 | + err = mnt_want_write(mnt); | |
30849 | + lockdep_on(); | |
30850 | + return err; | |
30851 | +} | |
30852 | + | |
30853 | +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt) | |
30854 | +{ | |
30855 | + lockdep_off(); | |
30856 | + mnt_drop_write(mnt); | |
30857 | + lockdep_on(); | |
30858 | +} | |
1facf9fc | 30859 | + |
7e9cd9fe | 30860 | +#if 0 /* reserved */ |
c06a8ce3 AM |
30861 | +static inline void vfsub_mnt_drop_write_file(struct file *file) |
30862 | +{ | |
30863 | + lockdep_off(); | |
30864 | + mnt_drop_write_file(file); | |
30865 | + lockdep_on(); | |
30866 | +} | |
7e9cd9fe | 30867 | +#endif |
c06a8ce3 | 30868 | + |
1facf9fc | 30869 | +/* ---------------------------------------------------------------------- */ |
30870 | + | |
30871 | +struct au_hinode; | |
30872 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30873 | + struct dentry *d2, struct au_hinode *hdir2); | |
30874 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30875 | + struct dentry *d2, struct au_hinode *hdir2); | |
30876 | + | |
537831f9 AM |
30877 | +int vfsub_create(struct inode *dir, struct path *path, int mode, |
30878 | + bool want_excl); | |
1facf9fc | 30879 | +int vfsub_symlink(struct inode *dir, struct path *path, |
30880 | + const char *symname); | |
30881 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev); | |
30882 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, | |
523b37e3 | 30883 | + struct path *path, struct inode **delegated_inode); |
1facf9fc | 30884 | +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry, |
523b37e3 AM |
30885 | + struct inode *hdir, struct path *path, |
30886 | + struct inode **delegated_inode); | |
1facf9fc | 30887 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode); |
30888 | +int vfsub_rmdir(struct inode *dir, struct path *path); | |
30889 | + | |
30890 | +/* ---------------------------------------------------------------------- */ | |
30891 | + | |
30892 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, | |
30893 | + loff_t *ppos); | |
30894 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
30895 | + loff_t *ppos); | |
30896 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
30897 | + loff_t *ppos); | |
30898 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, | |
30899 | + loff_t *ppos); | |
4a4d8108 | 30900 | +int vfsub_flush(struct file *file, fl_owner_t id); |
392086de AM |
30901 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx); |
30902 | + | |
c06a8ce3 AM |
30903 | +static inline loff_t vfsub_f_size_read(struct file *file) |
30904 | +{ | |
30905 | + return i_size_read(file_inode(file)); | |
30906 | +} | |
30907 | + | |
4a4d8108 AM |
30908 | +static inline unsigned int vfsub_file_flags(struct file *file) |
30909 | +{ | |
30910 | + unsigned int flags; | |
30911 | + | |
30912 | + spin_lock(&file->f_lock); | |
30913 | + flags = file->f_flags; | |
30914 | + spin_unlock(&file->f_lock); | |
30915 | + | |
30916 | + return flags; | |
30917 | +} | |
1308ab2a | 30918 | + |
7e9cd9fe | 30919 | +#if 0 /* reserved */ |
1facf9fc | 30920 | +static inline void vfsub_file_accessed(struct file *h_file) |
30921 | +{ | |
30922 | + file_accessed(h_file); | |
30923 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/ | |
30924 | +} | |
7e9cd9fe | 30925 | +#endif |
1facf9fc | 30926 | + |
30927 | +static inline void vfsub_touch_atime(struct vfsmount *h_mnt, | |
30928 | + struct dentry *h_dentry) | |
30929 | +{ | |
30930 | + struct path h_path = { | |
30931 | + .dentry = h_dentry, | |
30932 | + .mnt = h_mnt | |
30933 | + }; | |
92d182d2 | 30934 | + touch_atime(&h_path); |
1facf9fc | 30935 | + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/ |
30936 | +} | |
30937 | + | |
0c3ec466 AM |
30938 | +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts, |
30939 | + int flags) | |
30940 | +{ | |
7e9cd9fe | 30941 | + return generic_update_time(h_inode, ts, flags); |
0c3ec466 AM |
30942 | + /* no vfsub_update_h_iattr() since we don't have struct path */ |
30943 | +} | |
30944 | + | |
4a4d8108 AM |
30945 | +long vfsub_splice_to(struct file *in, loff_t *ppos, |
30946 | + struct pipe_inode_info *pipe, size_t len, | |
30947 | + unsigned int flags); | |
30948 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
30949 | + loff_t *ppos, size_t len, unsigned int flags); | |
c06a8ce3 AM |
30950 | + |
30951 | +static inline long vfsub_truncate(struct path *path, loff_t length) | |
30952 | +{ | |
30953 | + long err; | |
076b876e | 30954 | + |
c06a8ce3 AM |
30955 | + lockdep_off(); |
30956 | + err = vfs_truncate(path, length); | |
30957 | + lockdep_on(); | |
30958 | + return err; | |
30959 | +} | |
30960 | + | |
4a4d8108 AM |
30961 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, |
30962 | + struct file *h_file); | |
53392da6 | 30963 | +int vfsub_fsync(struct file *file, struct path *path, int datasync); |
4a4d8108 | 30964 | + |
1facf9fc | 30965 | +/* ---------------------------------------------------------------------- */ |
30966 | + | |
30967 | +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin) | |
30968 | +{ | |
30969 | + loff_t err; | |
30970 | + | |
2cbb1c4b | 30971 | + lockdep_off(); |
1facf9fc | 30972 | + err = vfs_llseek(file, offset, origin); |
2cbb1c4b | 30973 | + lockdep_on(); |
1facf9fc | 30974 | + return err; |
30975 | +} | |
30976 | + | |
30977 | +/* ---------------------------------------------------------------------- */ | |
30978 | + | |
4a4d8108 AM |
30979 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode); |
30980 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path); | |
523b37e3 AM |
30981 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
30982 | + struct inode **delegated_inode); | |
30983 | +int vfsub_notify_change(struct path *path, struct iattr *ia, | |
30984 | + struct inode **delegated_inode); | |
30985 | +int vfsub_unlink(struct inode *dir, struct path *path, | |
30986 | + struct inode **delegated_inode, int force); | |
4a4d8108 | 30987 | + |
c1595e42 JR |
30988 | +/* ---------------------------------------------------------------------- */ |
30989 | + | |
30990 | +static inline int vfsub_setxattr(struct dentry *dentry, const char *name, | |
30991 | + const void *value, size_t size, int flags) | |
30992 | +{ | |
30993 | + int err; | |
30994 | + | |
30995 | + lockdep_off(); | |
30996 | + err = vfs_setxattr(dentry, name, value, size, flags); | |
30997 | + lockdep_on(); | |
30998 | + | |
30999 | + return err; | |
31000 | +} | |
31001 | + | |
31002 | +static inline int vfsub_removexattr(struct dentry *dentry, const char *name) | |
31003 | +{ | |
31004 | + int err; | |
31005 | + | |
31006 | + lockdep_off(); | |
31007 | + err = vfs_removexattr(dentry, name); | |
31008 | + lockdep_on(); | |
31009 | + | |
31010 | + return err; | |
31011 | +} | |
31012 | + | |
1facf9fc | 31013 | +#endif /* __KERNEL__ */ |
31014 | +#endif /* __AUFS_VFSUB_H__ */ | |
7f207e10 AM |
31015 | diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c |
31016 | --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 31017 | +++ linux/fs/aufs/wbr_policy.c 2015-09-24 10:47:58.258053165 +0200 |
076b876e | 31018 | @@ -0,0 +1,765 @@ |
1facf9fc | 31019 | +/* |
2000de60 | 31020 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 31021 | + * |
31022 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31023 | + * it under the terms of the GNU General Public License as published by | |
31024 | + * the Free Software Foundation; either version 2 of the License, or | |
31025 | + * (at your option) any later version. | |
dece6358 AM |
31026 | + * |
31027 | + * This program is distributed in the hope that it will be useful, | |
31028 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31029 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31030 | + * GNU General Public License for more details. | |
31031 | + * | |
31032 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31033 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31034 | + */ |
31035 | + | |
31036 | +/* | |
31037 | + * policies for selecting one among multiple writable branches | |
31038 | + */ | |
31039 | + | |
31040 | +#include <linux/statfs.h> | |
31041 | +#include "aufs.h" | |
31042 | + | |
31043 | +/* subset of cpup_attr() */ | |
31044 | +static noinline_for_stack | |
31045 | +int au_cpdown_attr(struct path *h_path, struct dentry *h_src) | |
31046 | +{ | |
31047 | + int err, sbits; | |
31048 | + struct iattr ia; | |
31049 | + struct inode *h_isrc; | |
31050 | + | |
5527c038 | 31051 | + h_isrc = d_inode(h_src); |
1facf9fc | 31052 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID; |
31053 | + ia.ia_mode = h_isrc->i_mode; | |
31054 | + ia.ia_uid = h_isrc->i_uid; | |
31055 | + ia.ia_gid = h_isrc->i_gid; | |
31056 | + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID)); | |
5527c038 | 31057 | + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags); |
523b37e3 AM |
31058 | + /* no delegation since it is just created */ |
31059 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 31060 | + |
31061 | + /* is this nfs only? */ | |
31062 | + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) { | |
31063 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
31064 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 31065 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); |
1facf9fc | 31066 | + } |
31067 | + | |
31068 | + return err; | |
31069 | +} | |
31070 | + | |
31071 | +#define AuCpdown_PARENT_OPQ 1 | |
31072 | +#define AuCpdown_WHED (1 << 1) | |
31073 | +#define AuCpdown_MADE_DIR (1 << 2) | |
31074 | +#define AuCpdown_DIROPQ (1 << 3) | |
31075 | +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name) | |
7f207e10 AM |
31076 | +#define au_fset_cpdown(flags, name) \ |
31077 | + do { (flags) |= AuCpdown_##name; } while (0) | |
31078 | +#define au_fclr_cpdown(flags, name) \ | |
31079 | + do { (flags) &= ~AuCpdown_##name; } while (0) | |
1facf9fc | 31080 | + |
1facf9fc | 31081 | +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst, |
c2b27bf2 | 31082 | + unsigned int *flags) |
1facf9fc | 31083 | +{ |
31084 | + int err; | |
31085 | + struct dentry *opq_dentry; | |
31086 | + | |
31087 | + opq_dentry = au_diropq_create(dentry, bdst); | |
31088 | + err = PTR_ERR(opq_dentry); | |
31089 | + if (IS_ERR(opq_dentry)) | |
31090 | + goto out; | |
31091 | + dput(opq_dentry); | |
c2b27bf2 | 31092 | + au_fset_cpdown(*flags, DIROPQ); |
1facf9fc | 31093 | + |
4f0767ce | 31094 | +out: |
1facf9fc | 31095 | + return err; |
31096 | +} | |
31097 | + | |
31098 | +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent, | |
31099 | + struct inode *dir, aufs_bindex_t bdst) | |
31100 | +{ | |
31101 | + int err; | |
31102 | + struct path h_path; | |
31103 | + struct au_branch *br; | |
31104 | + | |
31105 | + br = au_sbr(dentry->d_sb, bdst); | |
31106 | + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br); | |
31107 | + err = PTR_ERR(h_path.dentry); | |
31108 | + if (IS_ERR(h_path.dentry)) | |
31109 | + goto out; | |
31110 | + | |
31111 | + err = 0; | |
5527c038 | 31112 | + if (d_is_positive(h_path.dentry)) { |
86dc4139 | 31113 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 31114 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path, |
31115 | + dentry); | |
31116 | + } | |
31117 | + dput(h_path.dentry); | |
31118 | + | |
4f0767ce | 31119 | +out: |
1facf9fc | 31120 | + return err; |
31121 | +} | |
31122 | + | |
31123 | +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 31124 | + struct au_pin *pin, |
1facf9fc | 31125 | + struct dentry *h_parent, void *arg) |
31126 | +{ | |
31127 | + int err, rerr; | |
4a4d8108 | 31128 | + aufs_bindex_t bopq, bstart; |
1facf9fc | 31129 | + struct path h_path; |
31130 | + struct dentry *parent; | |
31131 | + struct inode *h_dir, *h_inode, *inode, *dir; | |
c2b27bf2 | 31132 | + unsigned int *flags = arg; |
1facf9fc | 31133 | + |
31134 | + bstart = au_dbstart(dentry); | |
31135 | + /* dentry is di-locked */ | |
31136 | + parent = dget_parent(dentry); | |
5527c038 JR |
31137 | + dir = d_inode(parent); |
31138 | + h_dir = d_inode(h_parent); | |
1facf9fc | 31139 | + AuDebugOn(h_dir != au_h_iptr(dir, bdst)); |
31140 | + IMustLock(h_dir); | |
31141 | + | |
86dc4139 | 31142 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); |
1facf9fc | 31143 | + if (unlikely(err < 0)) |
31144 | + goto out; | |
31145 | + h_path.dentry = au_h_dptr(dentry, bdst); | |
31146 | + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst); | |
31147 | + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, | |
31148 | + S_IRWXU | S_IRUGO | S_IXUGO); | |
31149 | + if (unlikely(err)) | |
31150 | + goto out_put; | |
c2b27bf2 | 31151 | + au_fset_cpdown(*flags, MADE_DIR); |
1facf9fc | 31152 | + |
1facf9fc | 31153 | + bopq = au_dbdiropq(dentry); |
c2b27bf2 AM |
31154 | + au_fclr_cpdown(*flags, WHED); |
31155 | + au_fclr_cpdown(*flags, DIROPQ); | |
1facf9fc | 31156 | + if (au_dbwh(dentry) == bdst) |
c2b27bf2 AM |
31157 | + au_fset_cpdown(*flags, WHED); |
31158 | + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst) | |
31159 | + au_fset_cpdown(*flags, PARENT_OPQ); | |
5527c038 | 31160 | + h_inode = d_inode(h_path.dentry); |
1facf9fc | 31161 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
c2b27bf2 AM |
31162 | + if (au_ftest_cpdown(*flags, WHED)) { |
31163 | + err = au_cpdown_dir_opq(dentry, bdst, flags); | |
1facf9fc | 31164 | + if (unlikely(err)) { |
31165 | + mutex_unlock(&h_inode->i_mutex); | |
31166 | + goto out_dir; | |
31167 | + } | |
31168 | + } | |
31169 | + | |
31170 | + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart)); | |
31171 | + mutex_unlock(&h_inode->i_mutex); | |
31172 | + if (unlikely(err)) | |
31173 | + goto out_opq; | |
31174 | + | |
c2b27bf2 | 31175 | + if (au_ftest_cpdown(*flags, WHED)) { |
1facf9fc | 31176 | + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst); |
31177 | + if (unlikely(err)) | |
31178 | + goto out_opq; | |
31179 | + } | |
31180 | + | |
5527c038 | 31181 | + inode = d_inode(dentry); |
1facf9fc | 31182 | + if (au_ibend(inode) < bdst) |
31183 | + au_set_ibend(inode, bdst); | |
31184 | + au_set_h_iptr(inode, bdst, au_igrab(h_inode), | |
31185 | + au_hi_flags(inode, /*isdir*/1)); | |
076b876e | 31186 | + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0); |
1facf9fc | 31187 | + goto out; /* success */ |
31188 | + | |
31189 | + /* revert */ | |
4f0767ce | 31190 | +out_opq: |
c2b27bf2 | 31191 | + if (au_ftest_cpdown(*flags, DIROPQ)) { |
1facf9fc | 31192 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
31193 | + rerr = au_diropq_remove(dentry, bdst); | |
31194 | + mutex_unlock(&h_inode->i_mutex); | |
31195 | + if (unlikely(rerr)) { | |
523b37e3 AM |
31196 | + AuIOErr("failed removing diropq for %pd b%d (%d)\n", |
31197 | + dentry, bdst, rerr); | |
1facf9fc | 31198 | + err = -EIO; |
31199 | + goto out; | |
31200 | + } | |
31201 | + } | |
4f0767ce | 31202 | +out_dir: |
c2b27bf2 | 31203 | + if (au_ftest_cpdown(*flags, MADE_DIR)) { |
1facf9fc | 31204 | + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path); |
31205 | + if (unlikely(rerr)) { | |
523b37e3 AM |
31206 | + AuIOErr("failed removing %pd b%d (%d)\n", |
31207 | + dentry, bdst, rerr); | |
1facf9fc | 31208 | + err = -EIO; |
31209 | + } | |
31210 | + } | |
4f0767ce | 31211 | +out_put: |
1facf9fc | 31212 | + au_set_h_dptr(dentry, bdst, NULL); |
31213 | + if (au_dbend(dentry) == bdst) | |
31214 | + au_update_dbend(dentry); | |
4f0767ce | 31215 | +out: |
1facf9fc | 31216 | + dput(parent); |
31217 | + return err; | |
31218 | +} | |
31219 | + | |
31220 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
31221 | +{ | |
31222 | + int err; | |
c2b27bf2 | 31223 | + unsigned int flags; |
1facf9fc | 31224 | + |
c2b27bf2 AM |
31225 | + flags = 0; |
31226 | + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags); | |
1facf9fc | 31227 | + |
31228 | + return err; | |
31229 | +} | |
31230 | + | |
31231 | +/* ---------------------------------------------------------------------- */ | |
31232 | + | |
31233 | +/* policies for create */ | |
31234 | + | |
c2b27bf2 | 31235 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex) |
4a4d8108 AM |
31236 | +{ |
31237 | + int err, i, j, ndentry; | |
31238 | + aufs_bindex_t bopq; | |
31239 | + struct au_dcsub_pages dpages; | |
31240 | + struct au_dpage *dpage; | |
31241 | + struct dentry **dentries, *parent, *d; | |
31242 | + | |
31243 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
31244 | + if (unlikely(err)) | |
31245 | + goto out; | |
31246 | + parent = dget_parent(dentry); | |
027c5e7a | 31247 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0); |
4a4d8108 AM |
31248 | + if (unlikely(err)) |
31249 | + goto out_free; | |
31250 | + | |
31251 | + err = bindex; | |
31252 | + for (i = 0; i < dpages.ndpage; i++) { | |
31253 | + dpage = dpages.dpages + i; | |
31254 | + dentries = dpage->dentries; | |
31255 | + ndentry = dpage->ndentry; | |
31256 | + for (j = 0; j < ndentry; j++) { | |
31257 | + d = dentries[j]; | |
31258 | + di_read_lock_parent2(d, !AuLock_IR); | |
31259 | + bopq = au_dbdiropq(d); | |
31260 | + di_read_unlock(d, !AuLock_IR); | |
31261 | + if (bopq >= 0 && bopq < err) | |
31262 | + err = bopq; | |
31263 | + } | |
31264 | + } | |
31265 | + | |
31266 | +out_free: | |
31267 | + dput(parent); | |
31268 | + au_dpages_free(&dpages); | |
31269 | +out: | |
31270 | + return err; | |
31271 | +} | |
31272 | + | |
1facf9fc | 31273 | +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex) |
31274 | +{ | |
31275 | + for (; bindex >= 0; bindex--) | |
31276 | + if (!au_br_rdonly(au_sbr(sb, bindex))) | |
31277 | + return bindex; | |
31278 | + return -EROFS; | |
31279 | +} | |
31280 | + | |
31281 | +/* top down parent */ | |
392086de AM |
31282 | +static int au_wbr_create_tdp(struct dentry *dentry, |
31283 | + unsigned int flags __maybe_unused) | |
1facf9fc | 31284 | +{ |
31285 | + int err; | |
31286 | + aufs_bindex_t bstart, bindex; | |
31287 | + struct super_block *sb; | |
31288 | + struct dentry *parent, *h_parent; | |
31289 | + | |
31290 | + sb = dentry->d_sb; | |
31291 | + bstart = au_dbstart(dentry); | |
31292 | + err = bstart; | |
31293 | + if (!au_br_rdonly(au_sbr(sb, bstart))) | |
31294 | + goto out; | |
31295 | + | |
31296 | + err = -EROFS; | |
31297 | + parent = dget_parent(dentry); | |
31298 | + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) { | |
31299 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31300 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 31301 | + continue; |
31302 | + | |
31303 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
31304 | + err = bindex; | |
31305 | + break; | |
31306 | + } | |
31307 | + } | |
31308 | + dput(parent); | |
31309 | + | |
31310 | + /* bottom up here */ | |
4a4d8108 | 31311 | + if (unlikely(err < 0)) { |
1facf9fc | 31312 | + err = au_wbr_bu(sb, bstart - 1); |
4a4d8108 AM |
31313 | + if (err >= 0) |
31314 | + err = au_wbr_nonopq(dentry, err); | |
31315 | + } | |
1facf9fc | 31316 | + |
4f0767ce | 31317 | +out: |
1facf9fc | 31318 | + AuDbg("b%d\n", err); |
31319 | + return err; | |
31320 | +} | |
31321 | + | |
31322 | +/* ---------------------------------------------------------------------- */ | |
31323 | + | |
31324 | +/* an exception for the policy other than tdp */ | |
31325 | +static int au_wbr_create_exp(struct dentry *dentry) | |
31326 | +{ | |
31327 | + int err; | |
31328 | + aufs_bindex_t bwh, bdiropq; | |
31329 | + struct dentry *parent; | |
31330 | + | |
31331 | + err = -1; | |
31332 | + bwh = au_dbwh(dentry); | |
31333 | + parent = dget_parent(dentry); | |
31334 | + bdiropq = au_dbdiropq(parent); | |
31335 | + if (bwh >= 0) { | |
31336 | + if (bdiropq >= 0) | |
31337 | + err = min(bdiropq, bwh); | |
31338 | + else | |
31339 | + err = bwh; | |
31340 | + AuDbg("%d\n", err); | |
31341 | + } else if (bdiropq >= 0) { | |
31342 | + err = bdiropq; | |
31343 | + AuDbg("%d\n", err); | |
31344 | + } | |
31345 | + dput(parent); | |
31346 | + | |
4a4d8108 AM |
31347 | + if (err >= 0) |
31348 | + err = au_wbr_nonopq(dentry, err); | |
31349 | + | |
1facf9fc | 31350 | + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err))) |
31351 | + err = -1; | |
31352 | + | |
31353 | + AuDbg("%d\n", err); | |
31354 | + return err; | |
31355 | +} | |
31356 | + | |
31357 | +/* ---------------------------------------------------------------------- */ | |
31358 | + | |
31359 | +/* round robin */ | |
31360 | +static int au_wbr_create_init_rr(struct super_block *sb) | |
31361 | +{ | |
31362 | + int err; | |
31363 | + | |
31364 | + err = au_wbr_bu(sb, au_sbend(sb)); | |
31365 | + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */ | |
dece6358 | 31366 | + /* smp_mb(); */ |
1facf9fc | 31367 | + |
31368 | + AuDbg("b%d\n", err); | |
31369 | + return err; | |
31370 | +} | |
31371 | + | |
392086de | 31372 | +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31373 | +{ |
31374 | + int err, nbr; | |
31375 | + unsigned int u; | |
31376 | + aufs_bindex_t bindex, bend; | |
31377 | + struct super_block *sb; | |
31378 | + atomic_t *next; | |
31379 | + | |
31380 | + err = au_wbr_create_exp(dentry); | |
31381 | + if (err >= 0) | |
31382 | + goto out; | |
31383 | + | |
31384 | + sb = dentry->d_sb; | |
31385 | + next = &au_sbi(sb)->si_wbr_rr_next; | |
31386 | + bend = au_sbend(sb); | |
31387 | + nbr = bend + 1; | |
31388 | + for (bindex = 0; bindex <= bend; bindex++) { | |
392086de | 31389 | + if (!au_ftest_wbr(flags, DIR)) { |
1facf9fc | 31390 | + err = atomic_dec_return(next) + 1; |
31391 | + /* modulo for 0 is meaningless */ | |
31392 | + if (unlikely(!err)) | |
31393 | + err = atomic_dec_return(next) + 1; | |
31394 | + } else | |
31395 | + err = atomic_read(next); | |
31396 | + AuDbg("%d\n", err); | |
31397 | + u = err; | |
31398 | + err = u % nbr; | |
31399 | + AuDbg("%d\n", err); | |
31400 | + if (!au_br_rdonly(au_sbr(sb, err))) | |
31401 | + break; | |
31402 | + err = -EROFS; | |
31403 | + } | |
31404 | + | |
4a4d8108 AM |
31405 | + if (err >= 0) |
31406 | + err = au_wbr_nonopq(dentry, err); | |
31407 | + | |
4f0767ce | 31408 | +out: |
1facf9fc | 31409 | + AuDbg("%d\n", err); |
31410 | + return err; | |
31411 | +} | |
31412 | + | |
31413 | +/* ---------------------------------------------------------------------- */ | |
31414 | + | |
31415 | +/* most free space */ | |
392086de | 31416 | +static void au_mfs(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 31417 | +{ |
31418 | + struct super_block *sb; | |
31419 | + struct au_branch *br; | |
31420 | + struct au_wbr_mfs *mfs; | |
392086de | 31421 | + struct dentry *h_parent; |
1facf9fc | 31422 | + aufs_bindex_t bindex, bend; |
31423 | + int err; | |
31424 | + unsigned long long b, bavail; | |
7f207e10 | 31425 | + struct path h_path; |
1facf9fc | 31426 | + /* reduce the stack usage */ |
31427 | + struct kstatfs *st; | |
31428 | + | |
31429 | + st = kmalloc(sizeof(*st), GFP_NOFS); | |
31430 | + if (unlikely(!st)) { | |
31431 | + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM); | |
31432 | + return; | |
31433 | + } | |
31434 | + | |
31435 | + bavail = 0; | |
31436 | + sb = dentry->d_sb; | |
31437 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
dece6358 | 31438 | + MtxMustLock(&mfs->mfs_lock); |
1facf9fc | 31439 | + mfs->mfs_bindex = -EROFS; |
31440 | + mfs->mfsrr_bytes = 0; | |
392086de AM |
31441 | + if (!parent) { |
31442 | + bindex = 0; | |
31443 | + bend = au_sbend(sb); | |
31444 | + } else { | |
31445 | + bindex = au_dbstart(parent); | |
31446 | + bend = au_dbtaildir(parent); | |
31447 | + } | |
31448 | + | |
31449 | + for (; bindex <= bend; bindex++) { | |
31450 | + if (parent) { | |
31451 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31452 | + if (!h_parent || d_is_negative(h_parent)) |
392086de AM |
31453 | + continue; |
31454 | + } | |
1facf9fc | 31455 | + br = au_sbr(sb, bindex); |
31456 | + if (au_br_rdonly(br)) | |
31457 | + continue; | |
31458 | + | |
31459 | + /* sb->s_root for NFS is unreliable */ | |
86dc4139 | 31460 | + h_path.mnt = au_br_mnt(br); |
7f207e10 AM |
31461 | + h_path.dentry = h_path.mnt->mnt_root; |
31462 | + err = vfs_statfs(&h_path, st); | |
1facf9fc | 31463 | + if (unlikely(err)) { |
31464 | + AuWarn1("failed statfs, b%d, %d\n", bindex, err); | |
31465 | + continue; | |
31466 | + } | |
31467 | + | |
31468 | + /* when the available size is equal, select the lower one */ | |
31469 | + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail) | |
31470 | + || sizeof(b) < sizeof(st->f_bsize)); | |
31471 | + b = st->f_bavail * st->f_bsize; | |
31472 | + br->br_wbr->wbr_bytes = b; | |
31473 | + if (b >= bavail) { | |
31474 | + bavail = b; | |
31475 | + mfs->mfs_bindex = bindex; | |
31476 | + mfs->mfs_jiffy = jiffies; | |
31477 | + } | |
31478 | + } | |
31479 | + | |
31480 | + mfs->mfsrr_bytes = bavail; | |
31481 | + AuDbg("b%d\n", mfs->mfs_bindex); | |
31482 | + kfree(st); | |
31483 | +} | |
31484 | + | |
392086de | 31485 | +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31486 | +{ |
31487 | + int err; | |
392086de | 31488 | + struct dentry *parent; |
1facf9fc | 31489 | + struct super_block *sb; |
31490 | + struct au_wbr_mfs *mfs; | |
31491 | + | |
31492 | + err = au_wbr_create_exp(dentry); | |
31493 | + if (err >= 0) | |
31494 | + goto out; | |
31495 | + | |
31496 | + sb = dentry->d_sb; | |
392086de AM |
31497 | + parent = NULL; |
31498 | + if (au_ftest_wbr(flags, PARENT)) | |
31499 | + parent = dget_parent(dentry); | |
1facf9fc | 31500 | + mfs = &au_sbi(sb)->si_wbr_mfs; |
31501 | + mutex_lock(&mfs->mfs_lock); | |
31502 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
31503 | + || mfs->mfs_bindex < 0 | |
31504 | + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex))) | |
392086de | 31505 | + au_mfs(dentry, parent); |
1facf9fc | 31506 | + mutex_unlock(&mfs->mfs_lock); |
31507 | + err = mfs->mfs_bindex; | |
392086de | 31508 | + dput(parent); |
1facf9fc | 31509 | + |
4a4d8108 AM |
31510 | + if (err >= 0) |
31511 | + err = au_wbr_nonopq(dentry, err); | |
31512 | + | |
4f0767ce | 31513 | +out: |
1facf9fc | 31514 | + AuDbg("b%d\n", err); |
31515 | + return err; | |
31516 | +} | |
31517 | + | |
31518 | +static int au_wbr_create_init_mfs(struct super_block *sb) | |
31519 | +{ | |
31520 | + struct au_wbr_mfs *mfs; | |
31521 | + | |
31522 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
31523 | + mutex_init(&mfs->mfs_lock); | |
31524 | + mfs->mfs_jiffy = 0; | |
31525 | + mfs->mfs_bindex = -EROFS; | |
31526 | + | |
31527 | + return 0; | |
31528 | +} | |
31529 | + | |
31530 | +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused) | |
31531 | +{ | |
31532 | + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock); | |
31533 | + return 0; | |
31534 | +} | |
31535 | + | |
31536 | +/* ---------------------------------------------------------------------- */ | |
31537 | + | |
31538 | +/* most free space and then round robin */ | |
392086de | 31539 | +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31540 | +{ |
31541 | + int err; | |
31542 | + struct au_wbr_mfs *mfs; | |
31543 | + | |
392086de | 31544 | + err = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 31545 | + if (err >= 0) { |
31546 | + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs; | |
dece6358 | 31547 | + mutex_lock(&mfs->mfs_lock); |
1facf9fc | 31548 | + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark) |
392086de | 31549 | + err = au_wbr_create_rr(dentry, flags); |
dece6358 | 31550 | + mutex_unlock(&mfs->mfs_lock); |
1facf9fc | 31551 | + } |
31552 | + | |
31553 | + AuDbg("b%d\n", err); | |
31554 | + return err; | |
31555 | +} | |
31556 | + | |
31557 | +static int au_wbr_create_init_mfsrr(struct super_block *sb) | |
31558 | +{ | |
31559 | + int err; | |
31560 | + | |
31561 | + au_wbr_create_init_mfs(sb); /* ignore */ | |
31562 | + err = au_wbr_create_init_rr(sb); | |
31563 | + | |
31564 | + return err; | |
31565 | +} | |
31566 | + | |
31567 | +/* ---------------------------------------------------------------------- */ | |
31568 | + | |
31569 | +/* top down parent and most free space */ | |
392086de | 31570 | +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31571 | +{ |
31572 | + int err, e2; | |
31573 | + unsigned long long b; | |
31574 | + aufs_bindex_t bindex, bstart, bend; | |
31575 | + struct super_block *sb; | |
31576 | + struct dentry *parent, *h_parent; | |
31577 | + struct au_branch *br; | |
31578 | + | |
392086de | 31579 | + err = au_wbr_create_tdp(dentry, flags); |
1facf9fc | 31580 | + if (unlikely(err < 0)) |
31581 | + goto out; | |
31582 | + parent = dget_parent(dentry); | |
31583 | + bstart = au_dbstart(parent); | |
31584 | + bend = au_dbtaildir(parent); | |
31585 | + if (bstart == bend) | |
31586 | + goto out_parent; /* success */ | |
31587 | + | |
392086de | 31588 | + e2 = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 31589 | + if (e2 < 0) |
31590 | + goto out_parent; /* success */ | |
31591 | + | |
31592 | + /* when the available size is equal, select upper one */ | |
31593 | + sb = dentry->d_sb; | |
31594 | + br = au_sbr(sb, err); | |
31595 | + b = br->br_wbr->wbr_bytes; | |
31596 | + AuDbg("b%d, %llu\n", err, b); | |
31597 | + | |
31598 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
31599 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31600 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 31601 | + continue; |
31602 | + | |
31603 | + br = au_sbr(sb, bindex); | |
31604 | + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) { | |
31605 | + b = br->br_wbr->wbr_bytes; | |
31606 | + err = bindex; | |
31607 | + AuDbg("b%d, %llu\n", err, b); | |
31608 | + } | |
31609 | + } | |
31610 | + | |
4a4d8108 AM |
31611 | + if (err >= 0) |
31612 | + err = au_wbr_nonopq(dentry, err); | |
31613 | + | |
4f0767ce | 31614 | +out_parent: |
1facf9fc | 31615 | + dput(parent); |
4f0767ce | 31616 | +out: |
1facf9fc | 31617 | + AuDbg("b%d\n", err); |
31618 | + return err; | |
31619 | +} | |
31620 | + | |
31621 | +/* ---------------------------------------------------------------------- */ | |
31622 | + | |
392086de AM |
31623 | +/* |
31624 | + * - top down parent | |
31625 | + * - most free space with parent | |
31626 | + * - most free space round-robin regardless parent | |
31627 | + */ | |
31628 | +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags) | |
31629 | +{ | |
31630 | + int err; | |
31631 | + unsigned long long watermark; | |
31632 | + struct super_block *sb; | |
31633 | + struct au_branch *br; | |
31634 | + struct au_wbr_mfs *mfs; | |
31635 | + | |
31636 | + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT); | |
31637 | + if (unlikely(err < 0)) | |
31638 | + goto out; | |
31639 | + | |
31640 | + sb = dentry->d_sb; | |
31641 | + br = au_sbr(sb, err); | |
31642 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
31643 | + mutex_lock(&mfs->mfs_lock); | |
31644 | + watermark = mfs->mfsrr_watermark; | |
31645 | + mutex_unlock(&mfs->mfs_lock); | |
31646 | + if (br->br_wbr->wbr_bytes < watermark) | |
31647 | + /* regardless the parent dir */ | |
31648 | + err = au_wbr_create_mfsrr(dentry, flags); | |
31649 | + | |
31650 | +out: | |
31651 | + AuDbg("b%d\n", err); | |
31652 | + return err; | |
31653 | +} | |
31654 | + | |
31655 | +/* ---------------------------------------------------------------------- */ | |
31656 | + | |
1facf9fc | 31657 | +/* policies for copyup */ |
31658 | + | |
31659 | +/* top down parent */ | |
31660 | +static int au_wbr_copyup_tdp(struct dentry *dentry) | |
31661 | +{ | |
392086de | 31662 | + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0); |
1facf9fc | 31663 | +} |
31664 | + | |
31665 | +/* bottom up parent */ | |
31666 | +static int au_wbr_copyup_bup(struct dentry *dentry) | |
31667 | +{ | |
31668 | + int err; | |
31669 | + aufs_bindex_t bindex, bstart; | |
31670 | + struct dentry *parent, *h_parent; | |
31671 | + struct super_block *sb; | |
31672 | + | |
31673 | + err = -EROFS; | |
31674 | + sb = dentry->d_sb; | |
31675 | + parent = dget_parent(dentry); | |
31676 | + bstart = au_dbstart(parent); | |
31677 | + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) { | |
31678 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 31679 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 31680 | + continue; |
31681 | + | |
31682 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
31683 | + err = bindex; | |
31684 | + break; | |
31685 | + } | |
31686 | + } | |
31687 | + dput(parent); | |
31688 | + | |
31689 | + /* bottom up here */ | |
31690 | + if (unlikely(err < 0)) | |
31691 | + err = au_wbr_bu(sb, bstart - 1); | |
31692 | + | |
31693 | + AuDbg("b%d\n", err); | |
31694 | + return err; | |
31695 | +} | |
31696 | + | |
31697 | +/* bottom up */ | |
076b876e | 31698 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart) |
1facf9fc | 31699 | +{ |
31700 | + int err; | |
31701 | + | |
4a4d8108 AM |
31702 | + err = au_wbr_bu(dentry->d_sb, bstart); |
31703 | + AuDbg("b%d\n", err); | |
31704 | + if (err > bstart) | |
31705 | + err = au_wbr_nonopq(dentry, err); | |
1facf9fc | 31706 | + |
31707 | + AuDbg("b%d\n", err); | |
31708 | + return err; | |
31709 | +} | |
31710 | + | |
076b876e AM |
31711 | +static int au_wbr_copyup_bu(struct dentry *dentry) |
31712 | +{ | |
31713 | + int err; | |
31714 | + aufs_bindex_t bstart; | |
31715 | + | |
31716 | + bstart = au_dbstart(dentry); | |
31717 | + err = au_wbr_do_copyup_bu(dentry, bstart); | |
31718 | + return err; | |
31719 | +} | |
31720 | + | |
1facf9fc | 31721 | +/* ---------------------------------------------------------------------- */ |
31722 | + | |
31723 | +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = { | |
31724 | + [AuWbrCopyup_TDP] = { | |
31725 | + .copyup = au_wbr_copyup_tdp | |
31726 | + }, | |
31727 | + [AuWbrCopyup_BUP] = { | |
31728 | + .copyup = au_wbr_copyup_bup | |
31729 | + }, | |
31730 | + [AuWbrCopyup_BU] = { | |
31731 | + .copyup = au_wbr_copyup_bu | |
31732 | + } | |
31733 | +}; | |
31734 | + | |
31735 | +struct au_wbr_create_operations au_wbr_create_ops[] = { | |
31736 | + [AuWbrCreate_TDP] = { | |
31737 | + .create = au_wbr_create_tdp | |
31738 | + }, | |
31739 | + [AuWbrCreate_RR] = { | |
31740 | + .create = au_wbr_create_rr, | |
31741 | + .init = au_wbr_create_init_rr | |
31742 | + }, | |
31743 | + [AuWbrCreate_MFS] = { | |
31744 | + .create = au_wbr_create_mfs, | |
31745 | + .init = au_wbr_create_init_mfs, | |
31746 | + .fin = au_wbr_create_fin_mfs | |
31747 | + }, | |
31748 | + [AuWbrCreate_MFSV] = { | |
31749 | + .create = au_wbr_create_mfs, | |
31750 | + .init = au_wbr_create_init_mfs, | |
31751 | + .fin = au_wbr_create_fin_mfs | |
31752 | + }, | |
31753 | + [AuWbrCreate_MFSRR] = { | |
31754 | + .create = au_wbr_create_mfsrr, | |
31755 | + .init = au_wbr_create_init_mfsrr, | |
31756 | + .fin = au_wbr_create_fin_mfs | |
31757 | + }, | |
31758 | + [AuWbrCreate_MFSRRV] = { | |
31759 | + .create = au_wbr_create_mfsrr, | |
31760 | + .init = au_wbr_create_init_mfsrr, | |
31761 | + .fin = au_wbr_create_fin_mfs | |
31762 | + }, | |
31763 | + [AuWbrCreate_PMFS] = { | |
31764 | + .create = au_wbr_create_pmfs, | |
31765 | + .init = au_wbr_create_init_mfs, | |
31766 | + .fin = au_wbr_create_fin_mfs | |
31767 | + }, | |
31768 | + [AuWbrCreate_PMFSV] = { | |
31769 | + .create = au_wbr_create_pmfs, | |
31770 | + .init = au_wbr_create_init_mfs, | |
31771 | + .fin = au_wbr_create_fin_mfs | |
392086de AM |
31772 | + }, |
31773 | + [AuWbrCreate_PMFSRR] = { | |
31774 | + .create = au_wbr_create_pmfsrr, | |
31775 | + .init = au_wbr_create_init_mfsrr, | |
31776 | + .fin = au_wbr_create_fin_mfs | |
31777 | + }, | |
31778 | + [AuWbrCreate_PMFSRRV] = { | |
31779 | + .create = au_wbr_create_pmfsrr, | |
31780 | + .init = au_wbr_create_init_mfsrr, | |
31781 | + .fin = au_wbr_create_fin_mfs | |
1facf9fc | 31782 | + } |
31783 | +}; | |
7f207e10 AM |
31784 | diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c |
31785 | --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 31786 | +++ linux/fs/aufs/whout.c 2015-09-24 10:47:58.258053165 +0200 |
5527c038 | 31787 | @@ -0,0 +1,1063 @@ |
1facf9fc | 31788 | +/* |
2000de60 | 31789 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 31790 | + * |
31791 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31792 | + * it under the terms of the GNU General Public License as published by | |
31793 | + * the Free Software Foundation; either version 2 of the License, or | |
31794 | + * (at your option) any later version. | |
dece6358 AM |
31795 | + * |
31796 | + * This program is distributed in the hope that it will be useful, | |
31797 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31798 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31799 | + * GNU General Public License for more details. | |
31800 | + * | |
31801 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31802 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31803 | + */ |
31804 | + | |
31805 | +/* | |
31806 | + * whiteout for logical deletion and opaque directory | |
31807 | + */ | |
31808 | + | |
1facf9fc | 31809 | +#include "aufs.h" |
31810 | + | |
31811 | +#define WH_MASK S_IRUGO | |
31812 | + | |
31813 | +/* | |
31814 | + * If a directory contains this file, then it is opaque. We start with the | |
31815 | + * .wh. flag so that it is blocked by lookup. | |
31816 | + */ | |
0c3ec466 AM |
31817 | +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ, |
31818 | + sizeof(AUFS_WH_DIROPQ) - 1); | |
1facf9fc | 31819 | + |
31820 | +/* | |
31821 | + * generate whiteout name, which is NOT terminated by NULL. | |
31822 | + * @name: original d_name.name | |
31823 | + * @len: original d_name.len | |
31824 | + * @wh: whiteout qstr | |
31825 | + * returns zero when succeeds, otherwise error. | |
31826 | + * succeeded value as wh->name should be freed by kfree(). | |
31827 | + */ | |
31828 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name) | |
31829 | +{ | |
31830 | + char *p; | |
31831 | + | |
31832 | + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN)) | |
31833 | + return -ENAMETOOLONG; | |
31834 | + | |
31835 | + wh->len = name->len + AUFS_WH_PFX_LEN; | |
31836 | + p = kmalloc(wh->len, GFP_NOFS); | |
31837 | + wh->name = p; | |
31838 | + if (p) { | |
31839 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
31840 | + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len); | |
31841 | + /* smp_mb(); */ | |
31842 | + return 0; | |
31843 | + } | |
31844 | + return -ENOMEM; | |
31845 | +} | |
31846 | + | |
31847 | +/* ---------------------------------------------------------------------- */ | |
31848 | + | |
31849 | +/* | |
31850 | + * test if the @wh_name exists under @h_parent. | |
31851 | + * @try_sio specifies the necessary of super-io. | |
31852 | + */ | |
076b876e | 31853 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio) |
1facf9fc | 31854 | +{ |
31855 | + int err; | |
31856 | + struct dentry *wh_dentry; | |
1facf9fc | 31857 | + |
1facf9fc | 31858 | + if (!try_sio) |
b4510431 | 31859 | + wh_dentry = vfsub_lkup_one(wh_name, h_parent); |
1facf9fc | 31860 | + else |
076b876e | 31861 | + wh_dentry = au_sio_lkup_one(wh_name, h_parent); |
1facf9fc | 31862 | + err = PTR_ERR(wh_dentry); |
2000de60 JR |
31863 | + if (IS_ERR(wh_dentry)) { |
31864 | + if (err == -ENAMETOOLONG) | |
31865 | + err = 0; | |
1facf9fc | 31866 | + goto out; |
2000de60 | 31867 | + } |
1facf9fc | 31868 | + |
31869 | + err = 0; | |
5527c038 | 31870 | + if (d_is_negative(wh_dentry)) |
1facf9fc | 31871 | + goto out_wh; /* success */ |
31872 | + | |
31873 | + err = 1; | |
7e9cd9fe | 31874 | + if (d_is_reg(wh_dentry)) |
1facf9fc | 31875 | + goto out_wh; /* success */ |
31876 | + | |
31877 | + err = -EIO; | |
523b37e3 | 31878 | + AuIOErr("%pd Invalid whiteout entry type 0%o.\n", |
5527c038 | 31879 | + wh_dentry, d_inode(wh_dentry)->i_mode); |
1facf9fc | 31880 | + |
4f0767ce | 31881 | +out_wh: |
1facf9fc | 31882 | + dput(wh_dentry); |
4f0767ce | 31883 | +out: |
1facf9fc | 31884 | + return err; |
31885 | +} | |
31886 | + | |
31887 | +/* | |
31888 | + * test if the @h_dentry sets opaque or not. | |
31889 | + */ | |
076b876e | 31890 | +int au_diropq_test(struct dentry *h_dentry) |
1facf9fc | 31891 | +{ |
31892 | + int err; | |
31893 | + struct inode *h_dir; | |
31894 | + | |
5527c038 | 31895 | + h_dir = d_inode(h_dentry); |
076b876e | 31896 | + err = au_wh_test(h_dentry, &diropq_name, |
1facf9fc | 31897 | + au_test_h_perm_sio(h_dir, MAY_EXEC)); |
31898 | + return err; | |
31899 | +} | |
31900 | + | |
31901 | +/* | |
31902 | + * returns a negative dentry whose name is unique and temporary. | |
31903 | + */ | |
31904 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, | |
31905 | + struct qstr *prefix) | |
31906 | +{ | |
1facf9fc | 31907 | + struct dentry *dentry; |
31908 | + int i; | |
027c5e7a | 31909 | + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1], |
4a4d8108 | 31910 | + *name, *p; |
027c5e7a | 31911 | + /* strict atomic_t is unnecessary here */ |
1facf9fc | 31912 | + static unsigned short cnt; |
31913 | + struct qstr qs; | |
31914 | + | |
4a4d8108 AM |
31915 | + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN); |
31916 | + | |
1facf9fc | 31917 | + name = defname; |
027c5e7a AM |
31918 | + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1; |
31919 | + if (unlikely(prefix->len > DNAME_INLINE_LEN)) { | |
1facf9fc | 31920 | + dentry = ERR_PTR(-ENAMETOOLONG); |
4a4d8108 | 31921 | + if (unlikely(qs.len > NAME_MAX)) |
1facf9fc | 31922 | + goto out; |
31923 | + dentry = ERR_PTR(-ENOMEM); | |
31924 | + name = kmalloc(qs.len + 1, GFP_NOFS); | |
31925 | + if (unlikely(!name)) | |
31926 | + goto out; | |
31927 | + } | |
31928 | + | |
31929 | + /* doubly whiteout-ed */ | |
31930 | + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2); | |
31931 | + p = name + AUFS_WH_PFX_LEN * 2; | |
31932 | + memcpy(p, prefix->name, prefix->len); | |
31933 | + p += prefix->len; | |
31934 | + *p++ = '.'; | |
4a4d8108 | 31935 | + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN); |
1facf9fc | 31936 | + |
31937 | + qs.name = name; | |
31938 | + for (i = 0; i < 3; i++) { | |
b752ccd1 | 31939 | + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++); |
076b876e | 31940 | + dentry = au_sio_lkup_one(&qs, h_parent); |
5527c038 | 31941 | + if (IS_ERR(dentry) || d_is_negative(dentry)) |
1facf9fc | 31942 | + goto out_name; |
31943 | + dput(dentry); | |
31944 | + } | |
0c3ec466 | 31945 | + /* pr_warn("could not get random name\n"); */ |
1facf9fc | 31946 | + dentry = ERR_PTR(-EEXIST); |
31947 | + AuDbg("%.*s\n", AuLNPair(&qs)); | |
31948 | + BUG(); | |
31949 | + | |
4f0767ce | 31950 | +out_name: |
1facf9fc | 31951 | + if (name != defname) |
31952 | + kfree(name); | |
4f0767ce | 31953 | +out: |
4a4d8108 | 31954 | + AuTraceErrPtr(dentry); |
1facf9fc | 31955 | + return dentry; |
1facf9fc | 31956 | +} |
31957 | + | |
31958 | +/* | |
31959 | + * rename the @h_dentry on @br to the whiteouted temporary name. | |
31960 | + */ | |
31961 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br) | |
31962 | +{ | |
31963 | + int err; | |
31964 | + struct path h_path = { | |
86dc4139 | 31965 | + .mnt = au_br_mnt(br) |
1facf9fc | 31966 | + }; |
523b37e3 | 31967 | + struct inode *h_dir, *delegated; |
1facf9fc | 31968 | + struct dentry *h_parent; |
31969 | + | |
31970 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ | |
5527c038 | 31971 | + h_dir = d_inode(h_parent); |
1facf9fc | 31972 | + IMustLock(h_dir); |
31973 | + | |
31974 | + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name); | |
31975 | + err = PTR_ERR(h_path.dentry); | |
31976 | + if (IS_ERR(h_path.dentry)) | |
31977 | + goto out; | |
31978 | + | |
31979 | + /* under the same dir, no need to lock_rename() */ | |
523b37e3 AM |
31980 | + delegated = NULL; |
31981 | + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated); | |
1facf9fc | 31982 | + AuTraceErr(err); |
523b37e3 AM |
31983 | + if (unlikely(err == -EWOULDBLOCK)) { |
31984 | + pr_warn("cannot retry for NFSv4 delegation" | |
31985 | + " for an internal rename\n"); | |
31986 | + iput(delegated); | |
31987 | + } | |
1facf9fc | 31988 | + dput(h_path.dentry); |
31989 | + | |
4f0767ce | 31990 | +out: |
4a4d8108 | 31991 | + AuTraceErr(err); |
1facf9fc | 31992 | + return err; |
31993 | +} | |
31994 | + | |
31995 | +/* ---------------------------------------------------------------------- */ | |
31996 | +/* | |
31997 | + * functions for removing a whiteout | |
31998 | + */ | |
31999 | + | |
32000 | +static int do_unlink_wh(struct inode *h_dir, struct path *h_path) | |
32001 | +{ | |
523b37e3 AM |
32002 | + int err, force; |
32003 | + struct inode *delegated; | |
1facf9fc | 32004 | + |
32005 | + /* | |
32006 | + * forces superio when the dir has a sticky bit. | |
32007 | + * this may be a violation of unix fs semantics. | |
32008 | + */ | |
32009 | + force = (h_dir->i_mode & S_ISVTX) | |
5527c038 | 32010 | + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid); |
523b37e3 AM |
32011 | + delegated = NULL; |
32012 | + err = vfsub_unlink(h_dir, h_path, &delegated, force); | |
32013 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32014 | + pr_warn("cannot retry for NFSv4 delegation" | |
32015 | + " for an internal unlink\n"); | |
32016 | + iput(delegated); | |
32017 | + } | |
32018 | + return err; | |
1facf9fc | 32019 | +} |
32020 | + | |
32021 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
32022 | + struct dentry *dentry) | |
32023 | +{ | |
32024 | + int err; | |
32025 | + | |
32026 | + err = do_unlink_wh(h_dir, h_path); | |
32027 | + if (!err && dentry) | |
32028 | + au_set_dbwh(dentry, -1); | |
32029 | + | |
32030 | + return err; | |
32031 | +} | |
32032 | + | |
32033 | +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh, | |
32034 | + struct au_branch *br) | |
32035 | +{ | |
32036 | + int err; | |
32037 | + struct path h_path = { | |
86dc4139 | 32038 | + .mnt = au_br_mnt(br) |
1facf9fc | 32039 | + }; |
32040 | + | |
32041 | + err = 0; | |
b4510431 | 32042 | + h_path.dentry = vfsub_lkup_one(wh, h_parent); |
1facf9fc | 32043 | + if (IS_ERR(h_path.dentry)) |
32044 | + err = PTR_ERR(h_path.dentry); | |
32045 | + else { | |
5527c038 JR |
32046 | + if (d_is_reg(h_path.dentry)) |
32047 | + err = do_unlink_wh(d_inode(h_parent), &h_path); | |
1facf9fc | 32048 | + dput(h_path.dentry); |
32049 | + } | |
32050 | + | |
32051 | + return err; | |
32052 | +} | |
32053 | + | |
32054 | +/* ---------------------------------------------------------------------- */ | |
32055 | +/* | |
32056 | + * initialize/clean whiteout for a branch | |
32057 | + */ | |
32058 | + | |
32059 | +static void au_wh_clean(struct inode *h_dir, struct path *whpath, | |
32060 | + const int isdir) | |
32061 | +{ | |
32062 | + int err; | |
523b37e3 | 32063 | + struct inode *delegated; |
1facf9fc | 32064 | + |
5527c038 | 32065 | + if (d_is_negative(whpath->dentry)) |
1facf9fc | 32066 | + return; |
32067 | + | |
86dc4139 AM |
32068 | + if (isdir) |
32069 | + err = vfsub_rmdir(h_dir, whpath); | |
523b37e3 AM |
32070 | + else { |
32071 | + delegated = NULL; | |
32072 | + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0); | |
32073 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32074 | + pr_warn("cannot retry for NFSv4 delegation" | |
32075 | + " for an internal unlink\n"); | |
32076 | + iput(delegated); | |
32077 | + } | |
32078 | + } | |
1facf9fc | 32079 | + if (unlikely(err)) |
523b37e3 AM |
32080 | + pr_warn("failed removing %pd (%d), ignored.\n", |
32081 | + whpath->dentry, err); | |
1facf9fc | 32082 | +} |
32083 | + | |
32084 | +static int test_linkable(struct dentry *h_root) | |
32085 | +{ | |
5527c038 | 32086 | + struct inode *h_dir = d_inode(h_root); |
1facf9fc | 32087 | + |
32088 | + if (h_dir->i_op->link) | |
32089 | + return 0; | |
32090 | + | |
523b37e3 AM |
32091 | + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n", |
32092 | + h_root, au_sbtype(h_root->d_sb)); | |
1facf9fc | 32093 | + return -ENOSYS; |
32094 | +} | |
32095 | + | |
32096 | +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */ | |
32097 | +static int au_whdir(struct inode *h_dir, struct path *path) | |
32098 | +{ | |
32099 | + int err; | |
32100 | + | |
32101 | + err = -EEXIST; | |
5527c038 | 32102 | + if (d_is_negative(path->dentry)) { |
1facf9fc | 32103 | + int mode = S_IRWXU; |
32104 | + | |
32105 | + if (au_test_nfs(path->dentry->d_sb)) | |
32106 | + mode |= S_IXUGO; | |
86dc4139 | 32107 | + err = vfsub_mkdir(h_dir, path, mode); |
2000de60 | 32108 | + } else if (d_is_dir(path->dentry)) |
1facf9fc | 32109 | + err = 0; |
32110 | + else | |
523b37e3 | 32111 | + pr_err("unknown %pd exists\n", path->dentry); |
1facf9fc | 32112 | + |
32113 | + return err; | |
32114 | +} | |
32115 | + | |
32116 | +struct au_wh_base { | |
32117 | + const struct qstr *name; | |
32118 | + struct dentry *dentry; | |
32119 | +}; | |
32120 | + | |
32121 | +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[], | |
32122 | + struct path *h_path) | |
32123 | +{ | |
32124 | + h_path->dentry = base[AuBrWh_BASE].dentry; | |
32125 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
32126 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
32127 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32128 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
32129 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32130 | +} | |
32131 | + | |
32132 | +/* | |
32133 | + * returns tri-state, | |
c1595e42 | 32134 | + * minus: error, caller should print the message |
1facf9fc | 32135 | + * zero: succuess |
c1595e42 | 32136 | + * plus: error, caller should NOT print the message |
1facf9fc | 32137 | + */ |
32138 | +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr, | |
32139 | + int do_plink, struct au_wh_base base[], | |
32140 | + struct path *h_path) | |
32141 | +{ | |
32142 | + int err; | |
32143 | + struct inode *h_dir; | |
32144 | + | |
5527c038 | 32145 | + h_dir = d_inode(h_root); |
1facf9fc | 32146 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
32147 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
32148 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
32149 | + if (do_plink) { | |
32150 | + err = test_linkable(h_root); | |
32151 | + if (unlikely(err)) { | |
32152 | + err = 1; | |
32153 | + goto out; | |
32154 | + } | |
32155 | + | |
32156 | + err = au_whdir(h_dir, h_path); | |
32157 | + if (unlikely(err)) | |
32158 | + goto out; | |
32159 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
32160 | + } else | |
32161 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32162 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
32163 | + err = au_whdir(h_dir, h_path); | |
32164 | + if (unlikely(err)) | |
32165 | + goto out; | |
32166 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
32167 | + | |
4f0767ce | 32168 | +out: |
1facf9fc | 32169 | + return err; |
32170 | +} | |
32171 | + | |
32172 | +/* | |
32173 | + * for the moment, aufs supports the branch filesystem which does not support | |
32174 | + * link(2). testing on FAT which does not support i_op->setattr() fully either, | |
32175 | + * copyup failed. finally, such filesystem will not be used as the writable | |
32176 | + * branch. | |
32177 | + * | |
32178 | + * returns tri-state, see above. | |
32179 | + */ | |
32180 | +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr, | |
32181 | + int do_plink, struct au_wh_base base[], | |
32182 | + struct path *h_path) | |
32183 | +{ | |
32184 | + int err; | |
32185 | + struct inode *h_dir; | |
32186 | + | |
1308ab2a | 32187 | + WbrWhMustWriteLock(wbr); |
32188 | + | |
1facf9fc | 32189 | + err = test_linkable(h_root); |
32190 | + if (unlikely(err)) { | |
32191 | + err = 1; | |
32192 | + goto out; | |
32193 | + } | |
32194 | + | |
32195 | + /* | |
32196 | + * todo: should this create be done in /sbin/mount.aufs helper? | |
32197 | + */ | |
32198 | + err = -EEXIST; | |
5527c038 JR |
32199 | + h_dir = d_inode(h_root); |
32200 | + if (d_is_negative(base[AuBrWh_BASE].dentry)) { | |
86dc4139 AM |
32201 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
32202 | + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true); | |
7e9cd9fe | 32203 | + } else if (d_is_reg(base[AuBrWh_BASE].dentry)) |
1facf9fc | 32204 | + err = 0; |
32205 | + else | |
523b37e3 | 32206 | + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry); |
1facf9fc | 32207 | + if (unlikely(err)) |
32208 | + goto out; | |
32209 | + | |
32210 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
32211 | + if (do_plink) { | |
32212 | + err = au_whdir(h_dir, h_path); | |
32213 | + if (unlikely(err)) | |
32214 | + goto out; | |
32215 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
32216 | + } else | |
32217 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32218 | + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry); | |
32219 | + | |
32220 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
32221 | + err = au_whdir(h_dir, h_path); | |
32222 | + if (unlikely(err)) | |
32223 | + goto out; | |
32224 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
32225 | + | |
4f0767ce | 32226 | +out: |
1facf9fc | 32227 | + return err; |
32228 | +} | |
32229 | + | |
32230 | +/* | |
32231 | + * initialize the whiteout base file/dir for @br. | |
32232 | + */ | |
86dc4139 | 32233 | +int au_wh_init(struct au_branch *br, struct super_block *sb) |
1facf9fc | 32234 | +{ |
32235 | + int err, i; | |
32236 | + const unsigned char do_plink | |
32237 | + = !!au_opt_test(au_mntflags(sb), PLINK); | |
1facf9fc | 32238 | + struct inode *h_dir; |
86dc4139 AM |
32239 | + struct path path = br->br_path; |
32240 | + struct dentry *h_root = path.dentry; | |
1facf9fc | 32241 | + struct au_wbr *wbr = br->br_wbr; |
32242 | + static const struct qstr base_name[] = { | |
0c3ec466 AM |
32243 | + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME, |
32244 | + sizeof(AUFS_BASE_NAME) - 1), | |
32245 | + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME, | |
32246 | + sizeof(AUFS_PLINKDIR_NAME) - 1), | |
32247 | + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME, | |
32248 | + sizeof(AUFS_ORPHDIR_NAME) - 1) | |
1facf9fc | 32249 | + }; |
32250 | + struct au_wh_base base[] = { | |
32251 | + [AuBrWh_BASE] = { | |
32252 | + .name = base_name + AuBrWh_BASE, | |
32253 | + .dentry = NULL | |
32254 | + }, | |
32255 | + [AuBrWh_PLINK] = { | |
32256 | + .name = base_name + AuBrWh_PLINK, | |
32257 | + .dentry = NULL | |
32258 | + }, | |
32259 | + [AuBrWh_ORPH] = { | |
32260 | + .name = base_name + AuBrWh_ORPH, | |
32261 | + .dentry = NULL | |
32262 | + } | |
32263 | + }; | |
32264 | + | |
1308ab2a | 32265 | + if (wbr) |
32266 | + WbrWhMustWriteLock(wbr); | |
1facf9fc | 32267 | + |
1facf9fc | 32268 | + for (i = 0; i < AuBrWh_Last; i++) { |
32269 | + /* doubly whiteouted */ | |
32270 | + struct dentry *d; | |
32271 | + | |
32272 | + d = au_wh_lkup(h_root, (void *)base[i].name, br); | |
32273 | + err = PTR_ERR(d); | |
32274 | + if (IS_ERR(d)) | |
32275 | + goto out; | |
32276 | + | |
32277 | + base[i].dentry = d; | |
32278 | + AuDebugOn(wbr | |
32279 | + && wbr->wbr_wh[i] | |
32280 | + && wbr->wbr_wh[i] != base[i].dentry); | |
32281 | + } | |
32282 | + | |
32283 | + if (wbr) | |
32284 | + for (i = 0; i < AuBrWh_Last; i++) { | |
32285 | + dput(wbr->wbr_wh[i]); | |
32286 | + wbr->wbr_wh[i] = NULL; | |
32287 | + } | |
32288 | + | |
32289 | + err = 0; | |
1e00d052 | 32290 | + if (!au_br_writable(br->br_perm)) { |
5527c038 | 32291 | + h_dir = d_inode(h_root); |
1facf9fc | 32292 | + au_wh_init_ro(h_dir, base, &path); |
1e00d052 | 32293 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 32294 | + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path); |
32295 | + if (err > 0) | |
32296 | + goto out; | |
32297 | + else if (err) | |
32298 | + goto out_err; | |
1e00d052 | 32299 | + } else { |
1facf9fc | 32300 | + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path); |
32301 | + if (err > 0) | |
32302 | + goto out; | |
32303 | + else if (err) | |
32304 | + goto out_err; | |
1facf9fc | 32305 | + } |
32306 | + goto out; /* success */ | |
32307 | + | |
4f0767ce | 32308 | +out_err: |
523b37e3 AM |
32309 | + pr_err("an error(%d) on the writable branch %pd(%s)\n", |
32310 | + err, h_root, au_sbtype(h_root->d_sb)); | |
4f0767ce | 32311 | +out: |
1facf9fc | 32312 | + for (i = 0; i < AuBrWh_Last; i++) |
32313 | + dput(base[i].dentry); | |
32314 | + return err; | |
32315 | +} | |
32316 | + | |
32317 | +/* ---------------------------------------------------------------------- */ | |
32318 | +/* | |
32319 | + * whiteouts are all hard-linked usually. | |
32320 | + * when its link count reaches a ceiling, we create a new whiteout base | |
32321 | + * asynchronously. | |
32322 | + */ | |
32323 | + | |
32324 | +struct reinit_br_wh { | |
32325 | + struct super_block *sb; | |
32326 | + struct au_branch *br; | |
32327 | +}; | |
32328 | + | |
32329 | +static void reinit_br_wh(void *arg) | |
32330 | +{ | |
32331 | + int err; | |
32332 | + aufs_bindex_t bindex; | |
32333 | + struct path h_path; | |
32334 | + struct reinit_br_wh *a = arg; | |
32335 | + struct au_wbr *wbr; | |
523b37e3 | 32336 | + struct inode *dir, *delegated; |
1facf9fc | 32337 | + struct dentry *h_root; |
32338 | + struct au_hinode *hdir; | |
32339 | + | |
32340 | + err = 0; | |
32341 | + wbr = a->br->br_wbr; | |
32342 | + /* big aufs lock */ | |
32343 | + si_noflush_write_lock(a->sb); | |
32344 | + if (!au_br_writable(a->br->br_perm)) | |
32345 | + goto out; | |
32346 | + bindex = au_br_index(a->sb, a->br->br_id); | |
32347 | + if (unlikely(bindex < 0)) | |
32348 | + goto out; | |
32349 | + | |
1308ab2a | 32350 | + di_read_lock_parent(a->sb->s_root, AuLock_IR); |
5527c038 | 32351 | + dir = d_inode(a->sb->s_root); |
1facf9fc | 32352 | + hdir = au_hi(dir, bindex); |
32353 | + h_root = au_h_dptr(a->sb->s_root, bindex); | |
86dc4139 | 32354 | + AuDebugOn(h_root != au_br_dentry(a->br)); |
1facf9fc | 32355 | + |
4a4d8108 | 32356 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 32357 | + wbr_wh_write_lock(wbr); |
32358 | + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode, | |
32359 | + h_root, a->br); | |
32360 | + if (!err) { | |
86dc4139 AM |
32361 | + h_path.dentry = wbr->wbr_whbase; |
32362 | + h_path.mnt = au_br_mnt(a->br); | |
523b37e3 AM |
32363 | + delegated = NULL; |
32364 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, | |
32365 | + /*force*/0); | |
32366 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32367 | + pr_warn("cannot retry for NFSv4 delegation" | |
32368 | + " for an internal unlink\n"); | |
32369 | + iput(delegated); | |
32370 | + } | |
1facf9fc | 32371 | + } else { |
523b37e3 | 32372 | + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase); |
1facf9fc | 32373 | + err = 0; |
32374 | + } | |
32375 | + dput(wbr->wbr_whbase); | |
32376 | + wbr->wbr_whbase = NULL; | |
32377 | + if (!err) | |
86dc4139 | 32378 | + err = au_wh_init(a->br, a->sb); |
1facf9fc | 32379 | + wbr_wh_write_unlock(wbr); |
4a4d8108 | 32380 | + au_hn_imtx_unlock(hdir); |
1308ab2a | 32381 | + di_read_unlock(a->sb->s_root, AuLock_IR); |
076b876e AM |
32382 | + if (!err) |
32383 | + au_fhsm_wrote(a->sb, bindex, /*force*/0); | |
1facf9fc | 32384 | + |
4f0767ce | 32385 | +out: |
1facf9fc | 32386 | + if (wbr) |
32387 | + atomic_dec(&wbr->wbr_wh_running); | |
32388 | + atomic_dec(&a->br->br_count); | |
1facf9fc | 32389 | + si_write_unlock(a->sb); |
027c5e7a | 32390 | + au_nwt_done(&au_sbi(a->sb)->si_nowait); |
1facf9fc | 32391 | + kfree(arg); |
32392 | + if (unlikely(err)) | |
32393 | + AuIOErr("err %d\n", err); | |
32394 | +} | |
32395 | + | |
32396 | +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br) | |
32397 | +{ | |
32398 | + int do_dec, wkq_err; | |
32399 | + struct reinit_br_wh *arg; | |
32400 | + | |
32401 | + do_dec = 1; | |
32402 | + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1) | |
32403 | + goto out; | |
32404 | + | |
32405 | + /* ignore ENOMEM */ | |
32406 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
32407 | + if (arg) { | |
32408 | + /* | |
32409 | + * dec(wh_running), kfree(arg) and dec(br_count) | |
32410 | + * in reinit function | |
32411 | + */ | |
32412 | + arg->sb = sb; | |
32413 | + arg->br = br; | |
32414 | + atomic_inc(&br->br_count); | |
53392da6 | 32415 | + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0); |
1facf9fc | 32416 | + if (unlikely(wkq_err)) { |
32417 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
32418 | + atomic_dec(&br->br_count); | |
32419 | + kfree(arg); | |
32420 | + } | |
32421 | + do_dec = 0; | |
32422 | + } | |
32423 | + | |
4f0767ce | 32424 | +out: |
1facf9fc | 32425 | + if (do_dec) |
32426 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
32427 | +} | |
32428 | + | |
32429 | +/* ---------------------------------------------------------------------- */ | |
32430 | + | |
32431 | +/* | |
32432 | + * create the whiteout @wh. | |
32433 | + */ | |
32434 | +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex, | |
32435 | + struct dentry *wh) | |
32436 | +{ | |
32437 | + int err; | |
32438 | + struct path h_path = { | |
32439 | + .dentry = wh | |
32440 | + }; | |
32441 | + struct au_branch *br; | |
32442 | + struct au_wbr *wbr; | |
32443 | + struct dentry *h_parent; | |
523b37e3 | 32444 | + struct inode *h_dir, *delegated; |
1facf9fc | 32445 | + |
32446 | + h_parent = wh->d_parent; /* dir inode is locked */ | |
5527c038 | 32447 | + h_dir = d_inode(h_parent); |
1facf9fc | 32448 | + IMustLock(h_dir); |
32449 | + | |
32450 | + br = au_sbr(sb, bindex); | |
86dc4139 | 32451 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 32452 | + wbr = br->br_wbr; |
32453 | + wbr_wh_read_lock(wbr); | |
32454 | + if (wbr->wbr_whbase) { | |
523b37e3 AM |
32455 | + delegated = NULL; |
32456 | + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated); | |
32457 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32458 | + pr_warn("cannot retry for NFSv4 delegation" | |
32459 | + " for an internal link\n"); | |
32460 | + iput(delegated); | |
32461 | + } | |
1facf9fc | 32462 | + if (!err || err != -EMLINK) |
32463 | + goto out; | |
32464 | + | |
32465 | + /* link count full. re-initialize br_whbase. */ | |
32466 | + kick_reinit_br_wh(sb, br); | |
32467 | + } | |
32468 | + | |
32469 | + /* return this error in this context */ | |
b4510431 | 32470 | + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true); |
076b876e AM |
32471 | + if (!err) |
32472 | + au_fhsm_wrote(sb, bindex, /*force*/0); | |
1facf9fc | 32473 | + |
4f0767ce | 32474 | +out: |
1facf9fc | 32475 | + wbr_wh_read_unlock(wbr); |
32476 | + return err; | |
32477 | +} | |
32478 | + | |
32479 | +/* ---------------------------------------------------------------------- */ | |
32480 | + | |
32481 | +/* | |
32482 | + * create or remove the diropq. | |
32483 | + */ | |
32484 | +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex, | |
32485 | + unsigned int flags) | |
32486 | +{ | |
32487 | + struct dentry *opq_dentry, *h_dentry; | |
32488 | + struct super_block *sb; | |
32489 | + struct au_branch *br; | |
32490 | + int err; | |
32491 | + | |
32492 | + sb = dentry->d_sb; | |
32493 | + br = au_sbr(sb, bindex); | |
32494 | + h_dentry = au_h_dptr(dentry, bindex); | |
b4510431 | 32495 | + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry); |
1facf9fc | 32496 | + if (IS_ERR(opq_dentry)) |
32497 | + goto out; | |
32498 | + | |
32499 | + if (au_ftest_diropq(flags, CREATE)) { | |
32500 | + err = link_or_create_wh(sb, bindex, opq_dentry); | |
32501 | + if (!err) { | |
32502 | + au_set_dbdiropq(dentry, bindex); | |
32503 | + goto out; /* success */ | |
32504 | + } | |
32505 | + } else { | |
32506 | + struct path tmp = { | |
32507 | + .dentry = opq_dentry, | |
86dc4139 | 32508 | + .mnt = au_br_mnt(br) |
1facf9fc | 32509 | + }; |
5527c038 | 32510 | + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp); |
1facf9fc | 32511 | + if (!err) |
32512 | + au_set_dbdiropq(dentry, -1); | |
32513 | + } | |
32514 | + dput(opq_dentry); | |
32515 | + opq_dentry = ERR_PTR(err); | |
32516 | + | |
4f0767ce | 32517 | +out: |
1facf9fc | 32518 | + return opq_dentry; |
32519 | +} | |
32520 | + | |
32521 | +struct do_diropq_args { | |
32522 | + struct dentry **errp; | |
32523 | + struct dentry *dentry; | |
32524 | + aufs_bindex_t bindex; | |
32525 | + unsigned int flags; | |
32526 | +}; | |
32527 | + | |
32528 | +static void call_do_diropq(void *args) | |
32529 | +{ | |
32530 | + struct do_diropq_args *a = args; | |
32531 | + *a->errp = do_diropq(a->dentry, a->bindex, a->flags); | |
32532 | +} | |
32533 | + | |
32534 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
32535 | + unsigned int flags) | |
32536 | +{ | |
32537 | + struct dentry *diropq, *h_dentry; | |
32538 | + | |
32539 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 32540 | + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE)) |
1facf9fc | 32541 | + diropq = do_diropq(dentry, bindex, flags); |
32542 | + else { | |
32543 | + int wkq_err; | |
32544 | + struct do_diropq_args args = { | |
32545 | + .errp = &diropq, | |
32546 | + .dentry = dentry, | |
32547 | + .bindex = bindex, | |
32548 | + .flags = flags | |
32549 | + }; | |
32550 | + | |
32551 | + wkq_err = au_wkq_wait(call_do_diropq, &args); | |
32552 | + if (unlikely(wkq_err)) | |
32553 | + diropq = ERR_PTR(wkq_err); | |
32554 | + } | |
32555 | + | |
32556 | + return diropq; | |
32557 | +} | |
32558 | + | |
32559 | +/* ---------------------------------------------------------------------- */ | |
32560 | + | |
32561 | +/* | |
32562 | + * lookup whiteout dentry. | |
32563 | + * @h_parent: lower parent dentry which must exist and be locked | |
32564 | + * @base_name: name of dentry which will be whiteouted | |
32565 | + * returns dentry for whiteout. | |
32566 | + */ | |
32567 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
32568 | + struct au_branch *br) | |
32569 | +{ | |
32570 | + int err; | |
32571 | + struct qstr wh_name; | |
32572 | + struct dentry *wh_dentry; | |
32573 | + | |
32574 | + err = au_wh_name_alloc(&wh_name, base_name); | |
32575 | + wh_dentry = ERR_PTR(err); | |
32576 | + if (!err) { | |
b4510431 | 32577 | + wh_dentry = vfsub_lkup_one(&wh_name, h_parent); |
1facf9fc | 32578 | + kfree(wh_name.name); |
32579 | + } | |
32580 | + return wh_dentry; | |
32581 | +} | |
32582 | + | |
32583 | +/* | |
32584 | + * link/create a whiteout for @dentry on @bindex. | |
32585 | + */ | |
32586 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
32587 | + struct dentry *h_parent) | |
32588 | +{ | |
32589 | + struct dentry *wh_dentry; | |
32590 | + struct super_block *sb; | |
32591 | + int err; | |
32592 | + | |
32593 | + sb = dentry->d_sb; | |
32594 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex)); | |
5527c038 | 32595 | + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) { |
1facf9fc | 32596 | + err = link_or_create_wh(sb, bindex, wh_dentry); |
076b876e | 32597 | + if (!err) { |
1facf9fc | 32598 | + au_set_dbwh(dentry, bindex); |
076b876e AM |
32599 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
32600 | + } else { | |
1facf9fc | 32601 | + dput(wh_dentry); |
32602 | + wh_dentry = ERR_PTR(err); | |
32603 | + } | |
32604 | + } | |
32605 | + | |
32606 | + return wh_dentry; | |
32607 | +} | |
32608 | + | |
32609 | +/* ---------------------------------------------------------------------- */ | |
32610 | + | |
32611 | +/* Delete all whiteouts in this directory on branch bindex. */ | |
32612 | +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist, | |
32613 | + aufs_bindex_t bindex, struct au_branch *br) | |
32614 | +{ | |
32615 | + int err; | |
32616 | + unsigned long ul, n; | |
32617 | + struct qstr wh_name; | |
32618 | + char *p; | |
32619 | + struct hlist_head *head; | |
c06a8ce3 | 32620 | + struct au_vdir_wh *pos; |
1facf9fc | 32621 | + struct au_vdir_destr *str; |
32622 | + | |
32623 | + err = -ENOMEM; | |
537831f9 | 32624 | + p = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 32625 | + wh_name.name = p; |
32626 | + if (unlikely(!wh_name.name)) | |
32627 | + goto out; | |
32628 | + | |
32629 | + err = 0; | |
32630 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
32631 | + p += AUFS_WH_PFX_LEN; | |
32632 | + n = whlist->nh_num; | |
32633 | + head = whlist->nh_head; | |
32634 | + for (ul = 0; !err && ul < n; ul++, head++) { | |
c06a8ce3 AM |
32635 | + hlist_for_each_entry(pos, head, wh_hash) { |
32636 | + if (pos->wh_bindex != bindex) | |
1facf9fc | 32637 | + continue; |
32638 | + | |
c06a8ce3 | 32639 | + str = &pos->wh_str; |
1facf9fc | 32640 | + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) { |
32641 | + memcpy(p, str->name, str->len); | |
32642 | + wh_name.len = AUFS_WH_PFX_LEN + str->len; | |
32643 | + err = unlink_wh_name(h_dentry, &wh_name, br); | |
32644 | + if (!err) | |
32645 | + continue; | |
32646 | + break; | |
32647 | + } | |
32648 | + AuIOErr("whiteout name too long %.*s\n", | |
32649 | + str->len, str->name); | |
32650 | + err = -EIO; | |
32651 | + break; | |
32652 | + } | |
32653 | + } | |
537831f9 | 32654 | + free_page((unsigned long)wh_name.name); |
1facf9fc | 32655 | + |
4f0767ce | 32656 | +out: |
1facf9fc | 32657 | + return err; |
32658 | +} | |
32659 | + | |
32660 | +struct del_wh_children_args { | |
32661 | + int *errp; | |
32662 | + struct dentry *h_dentry; | |
1308ab2a | 32663 | + struct au_nhash *whlist; |
1facf9fc | 32664 | + aufs_bindex_t bindex; |
32665 | + struct au_branch *br; | |
32666 | +}; | |
32667 | + | |
32668 | +static void call_del_wh_children(void *args) | |
32669 | +{ | |
32670 | + struct del_wh_children_args *a = args; | |
1308ab2a | 32671 | + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br); |
1facf9fc | 32672 | +} |
32673 | + | |
32674 | +/* ---------------------------------------------------------------------- */ | |
32675 | + | |
32676 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp) | |
32677 | +{ | |
32678 | + struct au_whtmp_rmdir *whtmp; | |
dece6358 | 32679 | + int err; |
1308ab2a | 32680 | + unsigned int rdhash; |
dece6358 AM |
32681 | + |
32682 | + SiMustAnyLock(sb); | |
1facf9fc | 32683 | + |
32684 | + whtmp = kmalloc(sizeof(*whtmp), gfp); | |
dece6358 AM |
32685 | + if (unlikely(!whtmp)) { |
32686 | + whtmp = ERR_PTR(-ENOMEM); | |
1facf9fc | 32687 | + goto out; |
dece6358 | 32688 | + } |
1facf9fc | 32689 | + |
32690 | + whtmp->dir = NULL; | |
027c5e7a | 32691 | + whtmp->br = NULL; |
1facf9fc | 32692 | + whtmp->wh_dentry = NULL; |
1308ab2a | 32693 | + /* no estimation for dir size */ |
32694 | + rdhash = au_sbi(sb)->si_rdhash; | |
32695 | + if (!rdhash) | |
32696 | + rdhash = AUFS_RDHASH_DEF; | |
32697 | + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp); | |
32698 | + if (unlikely(err)) { | |
32699 | + kfree(whtmp); | |
32700 | + whtmp = ERR_PTR(err); | |
32701 | + } | |
dece6358 | 32702 | + |
4f0767ce | 32703 | +out: |
dece6358 | 32704 | + return whtmp; |
1facf9fc | 32705 | +} |
32706 | + | |
32707 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp) | |
32708 | +{ | |
027c5e7a AM |
32709 | + if (whtmp->br) |
32710 | + atomic_dec(&whtmp->br->br_count); | |
1facf9fc | 32711 | + dput(whtmp->wh_dentry); |
32712 | + iput(whtmp->dir); | |
dece6358 | 32713 | + au_nhash_wh_free(&whtmp->whlist); |
1facf9fc | 32714 | + kfree(whtmp); |
32715 | +} | |
32716 | + | |
32717 | +/* | |
32718 | + * rmdir the whiteouted temporary named dir @h_dentry. | |
32719 | + * @whlist: whiteouted children. | |
32720 | + */ | |
32721 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32722 | + struct dentry *wh_dentry, struct au_nhash *whlist) | |
32723 | +{ | |
32724 | + int err; | |
2000de60 | 32725 | + unsigned int h_nlink; |
1facf9fc | 32726 | + struct path h_tmp; |
32727 | + struct inode *wh_inode, *h_dir; | |
32728 | + struct au_branch *br; | |
32729 | + | |
5527c038 | 32730 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
1facf9fc | 32731 | + IMustLock(h_dir); |
32732 | + | |
32733 | + br = au_sbr(dir->i_sb, bindex); | |
5527c038 | 32734 | + wh_inode = d_inode(wh_dentry); |
1facf9fc | 32735 | + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD); |
32736 | + | |
32737 | + /* | |
32738 | + * someone else might change some whiteouts while we were sleeping. | |
32739 | + * it means this whlist may have an obsoleted entry. | |
32740 | + */ | |
32741 | + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE)) | |
32742 | + err = del_wh_children(wh_dentry, whlist, bindex, br); | |
32743 | + else { | |
32744 | + int wkq_err; | |
32745 | + struct del_wh_children_args args = { | |
32746 | + .errp = &err, | |
32747 | + .h_dentry = wh_dentry, | |
1308ab2a | 32748 | + .whlist = whlist, |
1facf9fc | 32749 | + .bindex = bindex, |
32750 | + .br = br | |
32751 | + }; | |
32752 | + | |
32753 | + wkq_err = au_wkq_wait(call_del_wh_children, &args); | |
32754 | + if (unlikely(wkq_err)) | |
32755 | + err = wkq_err; | |
32756 | + } | |
32757 | + mutex_unlock(&wh_inode->i_mutex); | |
32758 | + | |
32759 | + if (!err) { | |
32760 | + h_tmp.dentry = wh_dentry; | |
86dc4139 | 32761 | + h_tmp.mnt = au_br_mnt(br); |
2000de60 | 32762 | + h_nlink = h_dir->i_nlink; |
1facf9fc | 32763 | + err = vfsub_rmdir(h_dir, &h_tmp); |
2000de60 JR |
32764 | + /* some fs doesn't change the parent nlink in some cases */ |
32765 | + h_nlink -= h_dir->i_nlink; | |
1facf9fc | 32766 | + } |
32767 | + | |
32768 | + if (!err) { | |
32769 | + if (au_ibstart(dir) == bindex) { | |
7f207e10 | 32770 | + /* todo: dir->i_mutex is necessary */ |
1facf9fc | 32771 | + au_cpup_attr_timesizes(dir); |
2000de60 JR |
32772 | + if (h_nlink) |
32773 | + vfsub_drop_nlink(dir); | |
1facf9fc | 32774 | + } |
32775 | + return 0; /* success */ | |
32776 | + } | |
32777 | + | |
523b37e3 | 32778 | + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err); |
1facf9fc | 32779 | + return err; |
32780 | +} | |
32781 | + | |
32782 | +static void call_rmdir_whtmp(void *args) | |
32783 | +{ | |
32784 | + int err; | |
e49829fe | 32785 | + aufs_bindex_t bindex; |
1facf9fc | 32786 | + struct au_whtmp_rmdir *a = args; |
32787 | + struct super_block *sb; | |
32788 | + struct dentry *h_parent; | |
32789 | + struct inode *h_dir; | |
1facf9fc | 32790 | + struct au_hinode *hdir; |
32791 | + | |
32792 | + /* rmdir by nfsd may cause deadlock with this i_mutex */ | |
32793 | + /* mutex_lock(&a->dir->i_mutex); */ | |
e49829fe | 32794 | + err = -EROFS; |
1facf9fc | 32795 | + sb = a->dir->i_sb; |
e49829fe JR |
32796 | + si_read_lock(sb, !AuLock_FLUSH); |
32797 | + if (!au_br_writable(a->br->br_perm)) | |
32798 | + goto out; | |
32799 | + bindex = au_br_index(sb, a->br->br_id); | |
32800 | + if (unlikely(bindex < 0)) | |
1facf9fc | 32801 | + goto out; |
32802 | + | |
32803 | + err = -EIO; | |
1facf9fc | 32804 | + ii_write_lock_parent(a->dir); |
32805 | + h_parent = dget_parent(a->wh_dentry); | |
5527c038 | 32806 | + h_dir = d_inode(h_parent); |
e49829fe | 32807 | + hdir = au_hi(a->dir, bindex); |
86dc4139 AM |
32808 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); |
32809 | + if (unlikely(err)) | |
32810 | + goto out_mnt; | |
4a4d8108 | 32811 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
e49829fe JR |
32812 | + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent, |
32813 | + a->br); | |
86dc4139 AM |
32814 | + if (!err) |
32815 | + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist); | |
4a4d8108 | 32816 | + au_hn_imtx_unlock(hdir); |
86dc4139 AM |
32817 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
32818 | + | |
32819 | +out_mnt: | |
1facf9fc | 32820 | + dput(h_parent); |
32821 | + ii_write_unlock(a->dir); | |
4f0767ce | 32822 | +out: |
1facf9fc | 32823 | + /* mutex_unlock(&a->dir->i_mutex); */ |
1facf9fc | 32824 | + au_whtmp_rmdir_free(a); |
027c5e7a AM |
32825 | + si_read_unlock(sb); |
32826 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
1facf9fc | 32827 | + if (unlikely(err)) |
32828 | + AuIOErr("err %d\n", err); | |
32829 | +} | |
32830 | + | |
32831 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32832 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args) | |
32833 | +{ | |
32834 | + int wkq_err; | |
e49829fe | 32835 | + struct super_block *sb; |
1facf9fc | 32836 | + |
32837 | + IMustLock(dir); | |
32838 | + | |
32839 | + /* all post-process will be done in do_rmdir_whtmp(). */ | |
e49829fe | 32840 | + sb = dir->i_sb; |
1facf9fc | 32841 | + args->dir = au_igrab(dir); |
e49829fe JR |
32842 | + args->br = au_sbr(sb, bindex); |
32843 | + atomic_inc(&args->br->br_count); | |
1facf9fc | 32844 | + args->wh_dentry = dget(wh_dentry); |
53392da6 | 32845 | + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0); |
1facf9fc | 32846 | + if (unlikely(wkq_err)) { |
523b37e3 | 32847 | + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err); |
1facf9fc | 32848 | + au_whtmp_rmdir_free(args); |
32849 | + } | |
32850 | +} | |
7f207e10 AM |
32851 | diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h |
32852 | --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 32853 | +++ linux/fs/aufs/whout.h 2015-09-24 10:47:58.258053165 +0200 |
076b876e | 32854 | @@ -0,0 +1,85 @@ |
1facf9fc | 32855 | +/* |
2000de60 | 32856 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 32857 | + * |
32858 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32859 | + * it under the terms of the GNU General Public License as published by | |
32860 | + * the Free Software Foundation; either version 2 of the License, or | |
32861 | + * (at your option) any later version. | |
dece6358 AM |
32862 | + * |
32863 | + * This program is distributed in the hope that it will be useful, | |
32864 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32865 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32866 | + * GNU General Public License for more details. | |
32867 | + * | |
32868 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32869 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32870 | + */ |
32871 | + | |
32872 | +/* | |
32873 | + * whiteout for logical deletion and opaque directory | |
32874 | + */ | |
32875 | + | |
32876 | +#ifndef __AUFS_WHOUT_H__ | |
32877 | +#define __AUFS_WHOUT_H__ | |
32878 | + | |
32879 | +#ifdef __KERNEL__ | |
32880 | + | |
1facf9fc | 32881 | +#include "dir.h" |
32882 | + | |
32883 | +/* whout.c */ | |
32884 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name); | |
076b876e AM |
32885 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio); |
32886 | +int au_diropq_test(struct dentry *h_dentry); | |
7e9cd9fe | 32887 | +struct au_branch; |
1facf9fc | 32888 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, |
32889 | + struct qstr *prefix); | |
32890 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br); | |
32891 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
32892 | + struct dentry *dentry); | |
86dc4139 | 32893 | +int au_wh_init(struct au_branch *br, struct super_block *sb); |
1facf9fc | 32894 | + |
32895 | +/* diropq flags */ | |
32896 | +#define AuDiropq_CREATE 1 | |
32897 | +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name) | |
7f207e10 AM |
32898 | +#define au_fset_diropq(flags, name) \ |
32899 | + do { (flags) |= AuDiropq_##name; } while (0) | |
32900 | +#define au_fclr_diropq(flags, name) \ | |
32901 | + do { (flags) &= ~AuDiropq_##name; } while (0) | |
1facf9fc | 32902 | + |
32903 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
32904 | + unsigned int flags); | |
32905 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
32906 | + struct au_branch *br); | |
32907 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
32908 | + struct dentry *h_parent); | |
32909 | + | |
32910 | +/* real rmdir for the whiteout-ed dir */ | |
32911 | +struct au_whtmp_rmdir { | |
32912 | + struct inode *dir; | |
e49829fe | 32913 | + struct au_branch *br; |
1facf9fc | 32914 | + struct dentry *wh_dentry; |
dece6358 | 32915 | + struct au_nhash whlist; |
1facf9fc | 32916 | +}; |
32917 | + | |
32918 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp); | |
32919 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp); | |
32920 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32921 | + struct dentry *wh_dentry, struct au_nhash *whlist); | |
32922 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32923 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args); | |
32924 | + | |
32925 | +/* ---------------------------------------------------------------------- */ | |
32926 | + | |
32927 | +static inline struct dentry *au_diropq_create(struct dentry *dentry, | |
32928 | + aufs_bindex_t bindex) | |
32929 | +{ | |
32930 | + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE); | |
32931 | +} | |
32932 | + | |
32933 | +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex) | |
32934 | +{ | |
32935 | + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE)); | |
32936 | +} | |
32937 | + | |
32938 | +#endif /* __KERNEL__ */ | |
32939 | +#endif /* __AUFS_WHOUT_H__ */ | |
7f207e10 AM |
32940 | diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c |
32941 | --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 32942 | +++ linux/fs/aufs/wkq.c 2015-09-24 10:47:58.258053165 +0200 |
38d290e6 | 32943 | @@ -0,0 +1,213 @@ |
1facf9fc | 32944 | +/* |
2000de60 | 32945 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 32946 | + * |
32947 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32948 | + * it under the terms of the GNU General Public License as published by | |
32949 | + * the Free Software Foundation; either version 2 of the License, or | |
32950 | + * (at your option) any later version. | |
dece6358 AM |
32951 | + * |
32952 | + * This program is distributed in the hope that it will be useful, | |
32953 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32954 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32955 | + * GNU General Public License for more details. | |
32956 | + * | |
32957 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32958 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32959 | + */ |
32960 | + | |
32961 | +/* | |
32962 | + * workqueue for asynchronous/super-io operations | |
32963 | + * todo: try new dredential scheme | |
32964 | + */ | |
32965 | + | |
dece6358 | 32966 | +#include <linux/module.h> |
1facf9fc | 32967 | +#include "aufs.h" |
32968 | + | |
9dbd164d | 32969 | +/* internal workqueue named AUFS_WKQ_NAME */ |
b752ccd1 | 32970 | + |
9dbd164d | 32971 | +static struct workqueue_struct *au_wkq; |
1facf9fc | 32972 | + |
32973 | +struct au_wkinfo { | |
32974 | + struct work_struct wk; | |
7f207e10 | 32975 | + struct kobject *kobj; |
1facf9fc | 32976 | + |
32977 | + unsigned int flags; /* see wkq.h */ | |
32978 | + | |
32979 | + au_wkq_func_t func; | |
32980 | + void *args; | |
32981 | + | |
1facf9fc | 32982 | + struct completion *comp; |
32983 | +}; | |
32984 | + | |
32985 | +/* ---------------------------------------------------------------------- */ | |
32986 | + | |
1facf9fc | 32987 | +static void wkq_func(struct work_struct *wk) |
32988 | +{ | |
32989 | + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk); | |
32990 | + | |
2dfbb274 | 32991 | + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)); |
7f207e10 AM |
32992 | + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY); |
32993 | + | |
1facf9fc | 32994 | + wkinfo->func(wkinfo->args); |
1facf9fc | 32995 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) |
32996 | + complete(wkinfo->comp); | |
32997 | + else { | |
7f207e10 | 32998 | + kobject_put(wkinfo->kobj); |
9dbd164d | 32999 | + module_put(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 33000 | + kfree(wkinfo); |
33001 | + } | |
33002 | +} | |
33003 | + | |
33004 | +/* | |
33005 | + * Since struct completion is large, try allocating it dynamically. | |
33006 | + */ | |
c2b27bf2 | 33007 | +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */ |
1facf9fc | 33008 | +#define AuWkqCompDeclare(name) struct completion *comp = NULL |
33009 | + | |
33010 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
33011 | +{ | |
33012 | + *comp = kmalloc(sizeof(**comp), GFP_NOFS); | |
33013 | + if (*comp) { | |
33014 | + init_completion(*comp); | |
33015 | + wkinfo->comp = *comp; | |
33016 | + return 0; | |
33017 | + } | |
33018 | + return -ENOMEM; | |
33019 | +} | |
33020 | + | |
33021 | +static void au_wkq_comp_free(struct completion *comp) | |
33022 | +{ | |
33023 | + kfree(comp); | |
33024 | +} | |
33025 | + | |
33026 | +#else | |
33027 | + | |
33028 | +/* no braces */ | |
33029 | +#define AuWkqCompDeclare(name) \ | |
33030 | + DECLARE_COMPLETION_ONSTACK(_ ## name); \ | |
33031 | + struct completion *comp = &_ ## name | |
33032 | + | |
33033 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
33034 | +{ | |
33035 | + wkinfo->comp = *comp; | |
33036 | + return 0; | |
33037 | +} | |
33038 | + | |
33039 | +static void au_wkq_comp_free(struct completion *comp __maybe_unused) | |
33040 | +{ | |
33041 | + /* empty */ | |
33042 | +} | |
33043 | +#endif /* 4KSTACKS */ | |
33044 | + | |
53392da6 | 33045 | +static void au_wkq_run(struct au_wkinfo *wkinfo) |
1facf9fc | 33046 | +{ |
53392da6 AM |
33047 | + if (au_ftest_wkq(wkinfo->flags, NEST)) { |
33048 | + if (au_wkq_test()) { | |
38d290e6 JR |
33049 | + AuWarn1("wkq from wkq, unless silly-rename on NFS," |
33050 | + " due to a dead dir by UDBA?\n"); | |
53392da6 AM |
33051 | + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT)); |
33052 | + } | |
33053 | + } else | |
33054 | + au_dbg_verify_kthread(); | |
33055 | + | |
33056 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) { | |
a1f66529 | 33057 | + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func); |
9dbd164d | 33058 | + queue_work(au_wkq, &wkinfo->wk); |
4a4d8108 AM |
33059 | + } else { |
33060 | + INIT_WORK(&wkinfo->wk, wkq_func); | |
33061 | + schedule_work(&wkinfo->wk); | |
33062 | + } | |
1facf9fc | 33063 | +} |
33064 | + | |
7f207e10 AM |
33065 | +/* |
33066 | + * Be careful. It is easy to make deadlock happen. | |
33067 | + * processA: lock, wkq and wait | |
33068 | + * processB: wkq and wait, lock in wkq | |
33069 | + * --> deadlock | |
33070 | + */ | |
b752ccd1 | 33071 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args) |
1facf9fc | 33072 | +{ |
33073 | + int err; | |
33074 | + AuWkqCompDeclare(comp); | |
33075 | + struct au_wkinfo wkinfo = { | |
b752ccd1 | 33076 | + .flags = flags, |
1facf9fc | 33077 | + .func = func, |
33078 | + .args = args | |
33079 | + }; | |
33080 | + | |
33081 | + err = au_wkq_comp_alloc(&wkinfo, &comp); | |
33082 | + if (!err) { | |
53392da6 | 33083 | + au_wkq_run(&wkinfo); |
1facf9fc | 33084 | + /* no timeout, no interrupt */ |
33085 | + wait_for_completion(wkinfo.comp); | |
33086 | + au_wkq_comp_free(comp); | |
4a4d8108 | 33087 | + destroy_work_on_stack(&wkinfo.wk); |
1facf9fc | 33088 | + } |
33089 | + | |
33090 | + return err; | |
33091 | + | |
33092 | +} | |
33093 | + | |
027c5e7a AM |
33094 | +/* |
33095 | + * Note: dget/dput() in func for aufs dentries are not supported. It will be a | |
33096 | + * problem in a concurrent umounting. | |
33097 | + */ | |
53392da6 AM |
33098 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
33099 | + unsigned int flags) | |
1facf9fc | 33100 | +{ |
33101 | + int err; | |
33102 | + struct au_wkinfo *wkinfo; | |
33103 | + | |
33104 | + atomic_inc(&au_sbi(sb)->si_nowait.nw_len); | |
33105 | + | |
33106 | + /* | |
33107 | + * wkq_func() must free this wkinfo. | |
33108 | + * it highly depends upon the implementation of workqueue. | |
33109 | + */ | |
33110 | + err = 0; | |
33111 | + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS); | |
33112 | + if (wkinfo) { | |
7f207e10 | 33113 | + wkinfo->kobj = &au_sbi(sb)->si_kobj; |
53392da6 | 33114 | + wkinfo->flags = flags & ~AuWkq_WAIT; |
1facf9fc | 33115 | + wkinfo->func = func; |
33116 | + wkinfo->args = args; | |
33117 | + wkinfo->comp = NULL; | |
7f207e10 | 33118 | + kobject_get(wkinfo->kobj); |
9dbd164d | 33119 | + __module_get(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 33120 | + |
53392da6 | 33121 | + au_wkq_run(wkinfo); |
1facf9fc | 33122 | + } else { |
33123 | + err = -ENOMEM; | |
e49829fe | 33124 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 33125 | + } |
33126 | + | |
33127 | + return err; | |
33128 | +} | |
33129 | + | |
33130 | +/* ---------------------------------------------------------------------- */ | |
33131 | + | |
33132 | +void au_nwt_init(struct au_nowait_tasks *nwt) | |
33133 | +{ | |
33134 | + atomic_set(&nwt->nw_len, 0); | |
4a4d8108 | 33135 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 33136 | + init_waitqueue_head(&nwt->nw_wq); |
33137 | +} | |
33138 | + | |
33139 | +void au_wkq_fin(void) | |
33140 | +{ | |
9dbd164d | 33141 | + destroy_workqueue(au_wkq); |
1facf9fc | 33142 | +} |
33143 | + | |
33144 | +int __init au_wkq_init(void) | |
33145 | +{ | |
9dbd164d | 33146 | + int err; |
b752ccd1 AM |
33147 | + |
33148 | + err = 0; | |
86dc4139 | 33149 | + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE); |
9dbd164d AM |
33150 | + if (IS_ERR(au_wkq)) |
33151 | + err = PTR_ERR(au_wkq); | |
33152 | + else if (!au_wkq) | |
33153 | + err = -ENOMEM; | |
b752ccd1 AM |
33154 | + |
33155 | + return err; | |
1facf9fc | 33156 | +} |
7f207e10 AM |
33157 | diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h |
33158 | --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 33159 | +++ linux/fs/aufs/wkq.h 2015-09-24 10:47:58.258053165 +0200 |
523b37e3 | 33160 | @@ -0,0 +1,91 @@ |
1facf9fc | 33161 | +/* |
2000de60 | 33162 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 33163 | + * |
33164 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33165 | + * it under the terms of the GNU General Public License as published by | |
33166 | + * the Free Software Foundation; either version 2 of the License, or | |
33167 | + * (at your option) any later version. | |
dece6358 AM |
33168 | + * |
33169 | + * This program is distributed in the hope that it will be useful, | |
33170 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33171 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33172 | + * GNU General Public License for more details. | |
33173 | + * | |
33174 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33175 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33176 | + */ |
33177 | + | |
33178 | +/* | |
33179 | + * workqueue for asynchronous/super-io operations | |
33180 | + * todo: try new credentials management scheme | |
33181 | + */ | |
33182 | + | |
33183 | +#ifndef __AUFS_WKQ_H__ | |
33184 | +#define __AUFS_WKQ_H__ | |
33185 | + | |
33186 | +#ifdef __KERNEL__ | |
33187 | + | |
dece6358 AM |
33188 | +struct super_block; |
33189 | + | |
1facf9fc | 33190 | +/* ---------------------------------------------------------------------- */ |
33191 | + | |
33192 | +/* | |
33193 | + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue | |
33194 | + */ | |
33195 | +struct au_nowait_tasks { | |
33196 | + atomic_t nw_len; | |
33197 | + wait_queue_head_t nw_wq; | |
33198 | +}; | |
33199 | + | |
33200 | +/* ---------------------------------------------------------------------- */ | |
33201 | + | |
33202 | +typedef void (*au_wkq_func_t)(void *args); | |
33203 | + | |
33204 | +/* wkq flags */ | |
33205 | +#define AuWkq_WAIT 1 | |
9dbd164d | 33206 | +#define AuWkq_NEST (1 << 1) |
1facf9fc | 33207 | +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name) |
7f207e10 AM |
33208 | +#define au_fset_wkq(flags, name) \ |
33209 | + do { (flags) |= AuWkq_##name; } while (0) | |
33210 | +#define au_fclr_wkq(flags, name) \ | |
33211 | + do { (flags) &= ~AuWkq_##name; } while (0) | |
1facf9fc | 33212 | + |
9dbd164d AM |
33213 | +#ifndef CONFIG_AUFS_HNOTIFY |
33214 | +#undef AuWkq_NEST | |
33215 | +#define AuWkq_NEST 0 | |
33216 | +#endif | |
33217 | + | |
1facf9fc | 33218 | +/* wkq.c */ |
b752ccd1 | 33219 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args); |
53392da6 AM |
33220 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
33221 | + unsigned int flags); | |
1facf9fc | 33222 | +void au_nwt_init(struct au_nowait_tasks *nwt); |
33223 | +int __init au_wkq_init(void); | |
33224 | +void au_wkq_fin(void); | |
33225 | + | |
33226 | +/* ---------------------------------------------------------------------- */ | |
33227 | + | |
53392da6 AM |
33228 | +static inline int au_wkq_test(void) |
33229 | +{ | |
33230 | + return current->flags & PF_WQ_WORKER; | |
33231 | +} | |
33232 | + | |
b752ccd1 | 33233 | +static inline int au_wkq_wait(au_wkq_func_t func, void *args) |
1facf9fc | 33234 | +{ |
b752ccd1 | 33235 | + return au_wkq_do_wait(AuWkq_WAIT, func, args); |
1facf9fc | 33236 | +} |
33237 | + | |
33238 | +static inline void au_nwt_done(struct au_nowait_tasks *nwt) | |
33239 | +{ | |
e49829fe | 33240 | + if (atomic_dec_and_test(&nwt->nw_len)) |
1facf9fc | 33241 | + wake_up_all(&nwt->nw_wq); |
33242 | +} | |
33243 | + | |
33244 | +static inline int au_nwt_flush(struct au_nowait_tasks *nwt) | |
33245 | +{ | |
33246 | + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len)); | |
33247 | + return 0; | |
33248 | +} | |
33249 | + | |
33250 | +#endif /* __KERNEL__ */ | |
33251 | +#endif /* __AUFS_WKQ_H__ */ | |
c1595e42 JR |
33252 | diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c |
33253 | --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 33254 | +++ linux/fs/aufs/xattr.c 2015-09-24 10:47:58.258053165 +0200 |
b912730e | 33255 | @@ -0,0 +1,344 @@ |
c1595e42 | 33256 | +/* |
2000de60 | 33257 | + * Copyright (C) 2014-2015 Junjiro R. Okajima |
c1595e42 JR |
33258 | + * |
33259 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33260 | + * it under the terms of the GNU General Public License as published by | |
33261 | + * the Free Software Foundation; either version 2 of the License, or | |
33262 | + * (at your option) any later version. | |
33263 | + * | |
33264 | + * This program is distributed in the hope that it will be useful, | |
33265 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33266 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33267 | + * GNU General Public License for more details. | |
33268 | + * | |
33269 | + * You should have received a copy of the GNU General Public License | |
33270 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
33271 | + */ | |
33272 | + | |
33273 | +/* | |
33274 | + * handling xattr functions | |
33275 | + */ | |
33276 | + | |
33277 | +#include <linux/xattr.h> | |
33278 | +#include "aufs.h" | |
33279 | + | |
33280 | +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags) | |
33281 | +{ | |
33282 | + if (!ignore_flags) | |
33283 | + goto out; | |
33284 | + switch (err) { | |
33285 | + case -ENOMEM: | |
33286 | + case -EDQUOT: | |
33287 | + goto out; | |
33288 | + } | |
33289 | + | |
33290 | + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) { | |
33291 | + err = 0; | |
33292 | + goto out; | |
33293 | + } | |
33294 | + | |
33295 | +#define cmp(brattr, prefix) do { \ | |
33296 | + if (!strncmp(name, XATTR_##prefix##_PREFIX, \ | |
33297 | + XATTR_##prefix##_PREFIX_LEN)) { \ | |
33298 | + if (ignore_flags & AuBrAttr_ICEX_##brattr) \ | |
33299 | + err = 0; \ | |
33300 | + goto out; \ | |
33301 | + } \ | |
33302 | + } while (0) | |
33303 | + | |
33304 | + cmp(SEC, SECURITY); | |
33305 | + cmp(SYS, SYSTEM); | |
33306 | + cmp(TR, TRUSTED); | |
33307 | + cmp(USR, USER); | |
33308 | +#undef cmp | |
33309 | + | |
33310 | + if (ignore_flags & AuBrAttr_ICEX_OTH) | |
33311 | + err = 0; | |
33312 | + | |
33313 | +out: | |
33314 | + return err; | |
33315 | +} | |
33316 | + | |
33317 | +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1; | |
33318 | + | |
33319 | +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe AM |
33320 | + char *name, char **buf, unsigned int ignore_flags, |
33321 | + unsigned int verbose) | |
c1595e42 JR |
33322 | +{ |
33323 | + int err; | |
33324 | + ssize_t ssz; | |
33325 | + struct inode *h_idst; | |
33326 | + | |
33327 | + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS); | |
33328 | + err = ssz; | |
33329 | + if (unlikely(err <= 0)) { | |
c1595e42 JR |
33330 | + if (err == -ENODATA |
33331 | + || (err == -EOPNOTSUPP | |
b912730e | 33332 | + && ((ignore_flags & au_xattr_out_of_list) |
5527c038 | 33333 | + || (au_test_nfs_noacl(d_inode(h_src)) |
b912730e AM |
33334 | + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) |
33335 | + || !strcmp(name, | |
33336 | + XATTR_NAME_POSIX_ACL_DEFAULT)))) | |
33337 | + )) | |
c1595e42 | 33338 | + err = 0; |
b912730e AM |
33339 | + if (err && (verbose || au_debug_test())) |
33340 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
33341 | + goto out; |
33342 | + } | |
33343 | + | |
33344 | + /* unlock it temporary */ | |
5527c038 | 33345 | + h_idst = d_inode(h_dst); |
c1595e42 JR |
33346 | + mutex_unlock(&h_idst->i_mutex); |
33347 | + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0); | |
33348 | + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2); | |
33349 | + if (unlikely(err)) { | |
7e9cd9fe AM |
33350 | + if (verbose || au_debug_test()) |
33351 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
33352 | + err = au_xattr_ignore(err, name, ignore_flags); |
33353 | + } | |
33354 | + | |
33355 | +out: | |
33356 | + return err; | |
33357 | +} | |
33358 | + | |
7e9cd9fe AM |
33359 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
33360 | + unsigned int verbose) | |
c1595e42 JR |
33361 | +{ |
33362 | + int err, unlocked, acl_access, acl_default; | |
33363 | + ssize_t ssz; | |
33364 | + struct inode *h_isrc, *h_idst; | |
33365 | + char *value, *p, *o, *e; | |
33366 | + | |
33367 | + /* try stopping to update the source inode while we are referencing */ | |
7e9cd9fe | 33368 | + /* there should not be the parent-child relationship between them */ |
5527c038 JR |
33369 | + h_isrc = d_inode(h_src); |
33370 | + h_idst = d_inode(h_dst); | |
c1595e42 JR |
33371 | + mutex_unlock(&h_idst->i_mutex); |
33372 | + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD); | |
33373 | + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2); | |
33374 | + unlocked = 0; | |
33375 | + | |
33376 | + /* some filesystems don't list POSIX ACL, for example tmpfs */ | |
33377 | + ssz = vfs_listxattr(h_src, NULL, 0); | |
33378 | + err = ssz; | |
33379 | + if (unlikely(err < 0)) { | |
33380 | + AuTraceErr(err); | |
33381 | + if (err == -ENODATA | |
33382 | + || err == -EOPNOTSUPP) | |
33383 | + err = 0; /* ignore */ | |
33384 | + goto out; | |
33385 | + } | |
33386 | + | |
33387 | + err = 0; | |
33388 | + p = NULL; | |
33389 | + o = NULL; | |
33390 | + if (ssz) { | |
33391 | + err = -ENOMEM; | |
33392 | + p = kmalloc(ssz, GFP_NOFS); | |
33393 | + o = p; | |
33394 | + if (unlikely(!p)) | |
33395 | + goto out; | |
33396 | + err = vfs_listxattr(h_src, p, ssz); | |
33397 | + } | |
33398 | + mutex_unlock(&h_isrc->i_mutex); | |
33399 | + unlocked = 1; | |
33400 | + AuDbg("err %d, ssz %zd\n", err, ssz); | |
33401 | + if (unlikely(err < 0)) | |
33402 | + goto out_free; | |
33403 | + | |
33404 | + err = 0; | |
33405 | + e = p + ssz; | |
33406 | + value = NULL; | |
33407 | + acl_access = 0; | |
33408 | + acl_default = 0; | |
33409 | + while (!err && p < e) { | |
33410 | + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS, | |
33411 | + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1); | |
33412 | + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT, | |
33413 | + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) | |
33414 | + - 1); | |
7e9cd9fe AM |
33415 | + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags, |
33416 | + verbose); | |
c1595e42 JR |
33417 | + p += strlen(p) + 1; |
33418 | + } | |
33419 | + AuTraceErr(err); | |
33420 | + ignore_flags |= au_xattr_out_of_list; | |
33421 | + if (!err && !acl_access) { | |
33422 | + err = au_do_cpup_xattr(h_dst, h_src, | |
33423 | + XATTR_NAME_POSIX_ACL_ACCESS, &value, | |
7e9cd9fe | 33424 | + ignore_flags, verbose); |
c1595e42 JR |
33425 | + AuTraceErr(err); |
33426 | + } | |
33427 | + if (!err && !acl_default) { | |
33428 | + err = au_do_cpup_xattr(h_dst, h_src, | |
33429 | + XATTR_NAME_POSIX_ACL_DEFAULT, &value, | |
7e9cd9fe | 33430 | + ignore_flags, verbose); |
c1595e42 JR |
33431 | + AuTraceErr(err); |
33432 | + } | |
33433 | + | |
33434 | + kfree(value); | |
33435 | + | |
33436 | +out_free: | |
33437 | + kfree(o); | |
33438 | +out: | |
33439 | + if (!unlocked) | |
33440 | + mutex_unlock(&h_isrc->i_mutex); | |
33441 | + AuTraceErr(err); | |
33442 | + return err; | |
33443 | +} | |
33444 | + | |
33445 | +/* ---------------------------------------------------------------------- */ | |
33446 | + | |
33447 | +enum { | |
33448 | + AU_XATTR_LIST, | |
33449 | + AU_XATTR_GET | |
33450 | +}; | |
33451 | + | |
33452 | +struct au_lgxattr { | |
33453 | + int type; | |
33454 | + union { | |
33455 | + struct { | |
33456 | + char *list; | |
33457 | + size_t size; | |
33458 | + } list; | |
33459 | + struct { | |
33460 | + const char *name; | |
33461 | + void *value; | |
33462 | + size_t size; | |
33463 | + } get; | |
33464 | + } u; | |
33465 | +}; | |
33466 | + | |
33467 | +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg) | |
33468 | +{ | |
33469 | + ssize_t err; | |
33470 | + struct path h_path; | |
33471 | + struct super_block *sb; | |
33472 | + | |
33473 | + sb = dentry->d_sb; | |
33474 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
33475 | + if (unlikely(err)) | |
33476 | + goto out; | |
33477 | + err = au_h_path_getattr(dentry, /*force*/1, &h_path); | |
33478 | + if (unlikely(err)) | |
33479 | + goto out_si; | |
33480 | + if (unlikely(!h_path.dentry)) | |
33481 | + /* illegally overlapped or something */ | |
33482 | + goto out_di; /* pretending success */ | |
33483 | + | |
33484 | + /* always topmost entry only */ | |
33485 | + switch (arg->type) { | |
33486 | + case AU_XATTR_LIST: | |
33487 | + err = vfs_listxattr(h_path.dentry, | |
33488 | + arg->u.list.list, arg->u.list.size); | |
33489 | + break; | |
33490 | + case AU_XATTR_GET: | |
33491 | + err = vfs_getxattr(h_path.dentry, | |
33492 | + arg->u.get.name, arg->u.get.value, | |
33493 | + arg->u.get.size); | |
33494 | + break; | |
33495 | + } | |
33496 | + | |
33497 | +out_di: | |
33498 | + di_read_unlock(dentry, AuLock_IR); | |
33499 | +out_si: | |
33500 | + si_read_unlock(sb); | |
33501 | +out: | |
33502 | + AuTraceErr(err); | |
33503 | + return err; | |
33504 | +} | |
33505 | + | |
33506 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size) | |
33507 | +{ | |
33508 | + struct au_lgxattr arg = { | |
33509 | + .type = AU_XATTR_LIST, | |
33510 | + .u.list = { | |
33511 | + .list = list, | |
33512 | + .size = size | |
33513 | + }, | |
33514 | + }; | |
33515 | + | |
33516 | + return au_lgxattr(dentry, &arg); | |
33517 | +} | |
33518 | + | |
33519 | +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value, | |
33520 | + size_t size) | |
33521 | +{ | |
33522 | + struct au_lgxattr arg = { | |
33523 | + .type = AU_XATTR_GET, | |
33524 | + .u.get = { | |
33525 | + .name = name, | |
33526 | + .value = value, | |
33527 | + .size = size | |
33528 | + }, | |
33529 | + }; | |
33530 | + | |
33531 | + return au_lgxattr(dentry, &arg); | |
33532 | +} | |
33533 | + | |
33534 | +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value, | |
33535 | + size_t size, int flags) | |
33536 | +{ | |
33537 | + struct au_srxattr arg = { | |
33538 | + .type = AU_XATTR_SET, | |
33539 | + .u.set = { | |
33540 | + .name = name, | |
33541 | + .value = value, | |
33542 | + .size = size, | |
33543 | + .flags = flags | |
33544 | + }, | |
33545 | + }; | |
33546 | + | |
33547 | + return au_srxattr(dentry, &arg); | |
33548 | +} | |
33549 | + | |
33550 | +int aufs_removexattr(struct dentry *dentry, const char *name) | |
33551 | +{ | |
33552 | + struct au_srxattr arg = { | |
33553 | + .type = AU_XATTR_REMOVE, | |
33554 | + .u.remove = { | |
33555 | + .name = name | |
33556 | + }, | |
33557 | + }; | |
33558 | + | |
33559 | + return au_srxattr(dentry, &arg); | |
33560 | +} | |
33561 | + | |
33562 | +/* ---------------------------------------------------------------------- */ | |
33563 | + | |
33564 | +#if 0 | |
33565 | +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size, | |
33566 | + const char *name, size_t name_len, int type) | |
33567 | +{ | |
33568 | + return aufs_listxattr(dentry, list, list_size); | |
33569 | +} | |
33570 | + | |
33571 | +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer, | |
33572 | + size_t size, int type) | |
33573 | +{ | |
33574 | + return aufs_getxattr(dentry, name, buffer, size); | |
33575 | +} | |
33576 | + | |
33577 | +static int au_xattr_set(struct dentry *dentry, const char *name, | |
33578 | + const void *value, size_t size, int flags, int type) | |
33579 | +{ | |
33580 | + return aufs_setxattr(dentry, name, value, size, flags); | |
33581 | +} | |
33582 | + | |
33583 | +static const struct xattr_handler au_xattr_handler = { | |
33584 | + /* no prefix, no flags */ | |
33585 | + .list = au_xattr_list, | |
33586 | + .get = au_xattr_get, | |
33587 | + .set = au_xattr_set | |
33588 | + /* why no remove? */ | |
33589 | +}; | |
33590 | + | |
33591 | +static const struct xattr_handler *au_xattr_handlers[] = { | |
33592 | + &au_xattr_handler | |
33593 | +}; | |
33594 | + | |
33595 | +void au_xattr_init(struct super_block *sb) | |
33596 | +{ | |
33597 | + /* sb->s_xattr = au_xattr_handlers; */ | |
33598 | +} | |
33599 | +#endif | |
7f207e10 AM |
33600 | diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c |
33601 | --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 33602 | +++ linux/fs/aufs/xino.c 2015-09-24 10:47:58.258053165 +0200 |
5527c038 | 33603 | @@ -0,0 +1,1297 @@ |
1facf9fc | 33604 | +/* |
2000de60 | 33605 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
1facf9fc | 33606 | + * |
33607 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33608 | + * it under the terms of the GNU General Public License as published by | |
33609 | + * the Free Software Foundation; either version 2 of the License, or | |
33610 | + * (at your option) any later version. | |
dece6358 AM |
33611 | + * |
33612 | + * This program is distributed in the hope that it will be useful, | |
33613 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33614 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33615 | + * GNU General Public License for more details. | |
33616 | + * | |
33617 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33618 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33619 | + */ |
33620 | + | |
33621 | +/* | |
33622 | + * external inode number translation table and bitmap | |
33623 | + */ | |
33624 | + | |
33625 | +#include <linux/seq_file.h> | |
392086de | 33626 | +#include <linux/statfs.h> |
1facf9fc | 33627 | +#include "aufs.h" |
33628 | + | |
9dbd164d | 33629 | +/* todo: unnecessary to support mmap_sem since kernel-space? */ |
5527c038 | 33630 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size, |
1facf9fc | 33631 | + loff_t *pos) |
33632 | +{ | |
33633 | + ssize_t err; | |
33634 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33635 | + union { |
33636 | + void *k; | |
33637 | + char __user *u; | |
33638 | + } buf; | |
1facf9fc | 33639 | + |
b752ccd1 | 33640 | + buf.k = kbuf; |
1facf9fc | 33641 | + oldfs = get_fs(); |
33642 | + set_fs(KERNEL_DS); | |
33643 | + do { | |
33644 | + /* todo: signal_pending? */ | |
b752ccd1 | 33645 | + err = func(file, buf.u, size, pos); |
1facf9fc | 33646 | + } while (err == -EAGAIN || err == -EINTR); |
33647 | + set_fs(oldfs); | |
33648 | + | |
33649 | +#if 0 /* reserved for future use */ | |
33650 | + if (err > 0) | |
2000de60 | 33651 | + fsnotify_access(file->f_path.dentry); |
1facf9fc | 33652 | +#endif |
33653 | + | |
33654 | + return err; | |
33655 | +} | |
33656 | + | |
33657 | +/* ---------------------------------------------------------------------- */ | |
33658 | + | |
5527c038 | 33659 | +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf, |
1facf9fc | 33660 | + size_t size, loff_t *pos) |
33661 | +{ | |
33662 | + ssize_t err; | |
33663 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33664 | + union { |
33665 | + void *k; | |
33666 | + const char __user *u; | |
33667 | + } buf; | |
1facf9fc | 33668 | + |
b752ccd1 | 33669 | + buf.k = kbuf; |
1facf9fc | 33670 | + oldfs = get_fs(); |
33671 | + set_fs(KERNEL_DS); | |
1facf9fc | 33672 | + do { |
33673 | + /* todo: signal_pending? */ | |
b752ccd1 | 33674 | + err = func(file, buf.u, size, pos); |
1facf9fc | 33675 | + } while (err == -EAGAIN || err == -EINTR); |
1facf9fc | 33676 | + set_fs(oldfs); |
33677 | + | |
33678 | +#if 0 /* reserved for future use */ | |
33679 | + if (err > 0) | |
2000de60 | 33680 | + fsnotify_modify(file->f_path.dentry); |
1facf9fc | 33681 | +#endif |
33682 | + | |
33683 | + return err; | |
33684 | +} | |
33685 | + | |
33686 | +struct do_xino_fwrite_args { | |
33687 | + ssize_t *errp; | |
5527c038 | 33688 | + vfs_writef_t func; |
1facf9fc | 33689 | + struct file *file; |
33690 | + void *buf; | |
33691 | + size_t size; | |
33692 | + loff_t *pos; | |
33693 | +}; | |
33694 | + | |
33695 | +static void call_do_xino_fwrite(void *args) | |
33696 | +{ | |
33697 | + struct do_xino_fwrite_args *a = args; | |
33698 | + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos); | |
33699 | +} | |
33700 | + | |
5527c038 JR |
33701 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
33702 | + size_t size, loff_t *pos) | |
1facf9fc | 33703 | +{ |
33704 | + ssize_t err; | |
33705 | + | |
33706 | + /* todo: signal block and no wkq? */ | |
b752ccd1 AM |
33707 | + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) { |
33708 | + lockdep_off(); | |
33709 | + err = do_xino_fwrite(func, file, buf, size, pos); | |
33710 | + lockdep_on(); | |
33711 | + } else { | |
33712 | + /* | |
33713 | + * it breaks RLIMIT_FSIZE and normal user's limit, | |
33714 | + * users should care about quota and real 'filesystem full.' | |
33715 | + */ | |
1facf9fc | 33716 | + int wkq_err; |
33717 | + struct do_xino_fwrite_args args = { | |
33718 | + .errp = &err, | |
33719 | + .func = func, | |
33720 | + .file = file, | |
33721 | + .buf = buf, | |
33722 | + .size = size, | |
33723 | + .pos = pos | |
33724 | + }; | |
33725 | + | |
33726 | + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args); | |
33727 | + if (unlikely(wkq_err)) | |
33728 | + err = wkq_err; | |
b752ccd1 | 33729 | + } |
1facf9fc | 33730 | + |
33731 | + return err; | |
33732 | +} | |
33733 | + | |
33734 | +/* ---------------------------------------------------------------------- */ | |
33735 | + | |
33736 | +/* | |
33737 | + * create a new xinofile at the same place/path as @base_file. | |
33738 | + */ | |
33739 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src) | |
33740 | +{ | |
33741 | + struct file *file; | |
4a4d8108 | 33742 | + struct dentry *base, *parent; |
523b37e3 | 33743 | + struct inode *dir, *delegated; |
1facf9fc | 33744 | + struct qstr *name; |
1308ab2a | 33745 | + struct path path; |
4a4d8108 | 33746 | + int err; |
1facf9fc | 33747 | + |
2000de60 | 33748 | + base = base_file->f_path.dentry; |
1facf9fc | 33749 | + parent = base->d_parent; /* dir inode is locked */ |
5527c038 | 33750 | + dir = d_inode(parent); |
1facf9fc | 33751 | + IMustLock(dir); |
33752 | + | |
33753 | + file = ERR_PTR(-EINVAL); | |
33754 | + name = &base->d_name; | |
4a4d8108 AM |
33755 | + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len); |
33756 | + if (IS_ERR(path.dentry)) { | |
33757 | + file = (void *)path.dentry; | |
523b37e3 AM |
33758 | + pr_err("%pd lookup err %ld\n", |
33759 | + base, PTR_ERR(path.dentry)); | |
1facf9fc | 33760 | + goto out; |
33761 | + } | |
33762 | + | |
33763 | + /* no need to mnt_want_write() since we call dentry_open() later */ | |
4a4d8108 | 33764 | + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL); |
1facf9fc | 33765 | + if (unlikely(err)) { |
33766 | + file = ERR_PTR(err); | |
523b37e3 | 33767 | + pr_err("%pd create err %d\n", base, err); |
1facf9fc | 33768 | + goto out_dput; |
33769 | + } | |
33770 | + | |
c06a8ce3 | 33771 | + path.mnt = base_file->f_path.mnt; |
4a4d8108 | 33772 | + file = vfsub_dentry_open(&path, |
7f207e10 | 33773 | + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 33774 | + /* | __FMODE_NONOTIFY */); |
1facf9fc | 33775 | + if (IS_ERR(file)) { |
523b37e3 | 33776 | + pr_err("%pd open err %ld\n", base, PTR_ERR(file)); |
1facf9fc | 33777 | + goto out_dput; |
33778 | + } | |
33779 | + | |
523b37e3 AM |
33780 | + delegated = NULL; |
33781 | + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0); | |
33782 | + if (unlikely(err == -EWOULDBLOCK)) { | |
33783 | + pr_warn("cannot retry for NFSv4 delegation" | |
33784 | + " for an internal unlink\n"); | |
33785 | + iput(delegated); | |
33786 | + } | |
1facf9fc | 33787 | + if (unlikely(err)) { |
523b37e3 | 33788 | + pr_err("%pd unlink err %d\n", base, err); |
1facf9fc | 33789 | + goto out_fput; |
33790 | + } | |
33791 | + | |
33792 | + if (copy_src) { | |
33793 | + /* no one can touch copy_src xino */ | |
c06a8ce3 | 33794 | + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src)); |
1facf9fc | 33795 | + if (unlikely(err)) { |
523b37e3 | 33796 | + pr_err("%pd copy err %d\n", base, err); |
1facf9fc | 33797 | + goto out_fput; |
33798 | + } | |
33799 | + } | |
33800 | + goto out_dput; /* success */ | |
33801 | + | |
4f0767ce | 33802 | +out_fput: |
1facf9fc | 33803 | + fput(file); |
33804 | + file = ERR_PTR(err); | |
4f0767ce | 33805 | +out_dput: |
4a4d8108 | 33806 | + dput(path.dentry); |
4f0767ce | 33807 | +out: |
1facf9fc | 33808 | + return file; |
33809 | +} | |
33810 | + | |
33811 | +struct au_xino_lock_dir { | |
33812 | + struct au_hinode *hdir; | |
33813 | + struct dentry *parent; | |
33814 | + struct mutex *mtx; | |
33815 | +}; | |
33816 | + | |
33817 | +static void au_xino_lock_dir(struct super_block *sb, struct file *xino, | |
33818 | + struct au_xino_lock_dir *ldir) | |
33819 | +{ | |
33820 | + aufs_bindex_t brid, bindex; | |
33821 | + | |
33822 | + ldir->hdir = NULL; | |
33823 | + bindex = -1; | |
33824 | + brid = au_xino_brid(sb); | |
33825 | + if (brid >= 0) | |
33826 | + bindex = au_br_index(sb, brid); | |
33827 | + if (bindex >= 0) { | |
5527c038 | 33828 | + ldir->hdir = au_hi(d_inode(sb->s_root), bindex); |
4a4d8108 | 33829 | + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT); |
1facf9fc | 33830 | + } else { |
2000de60 | 33831 | + ldir->parent = dget_parent(xino->f_path.dentry); |
5527c038 | 33832 | + ldir->mtx = &d_inode(ldir->parent)->i_mutex; |
1facf9fc | 33833 | + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT); |
33834 | + } | |
33835 | +} | |
33836 | + | |
33837 | +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir) | |
33838 | +{ | |
33839 | + if (ldir->hdir) | |
4a4d8108 | 33840 | + au_hn_imtx_unlock(ldir->hdir); |
1facf9fc | 33841 | + else { |
33842 | + mutex_unlock(ldir->mtx); | |
33843 | + dput(ldir->parent); | |
33844 | + } | |
33845 | +} | |
33846 | + | |
33847 | +/* ---------------------------------------------------------------------- */ | |
33848 | + | |
33849 | +/* trucate xino files asynchronously */ | |
33850 | + | |
33851 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex) | |
33852 | +{ | |
33853 | + int err; | |
392086de AM |
33854 | + unsigned long jiffy; |
33855 | + blkcnt_t blocks; | |
1facf9fc | 33856 | + aufs_bindex_t bi, bend; |
392086de | 33857 | + struct kstatfs *st; |
1facf9fc | 33858 | + struct au_branch *br; |
33859 | + struct file *new_xino, *file; | |
33860 | + struct super_block *h_sb; | |
33861 | + struct au_xino_lock_dir ldir; | |
33862 | + | |
392086de AM |
33863 | + err = -ENOMEM; |
33864 | + st = kzalloc(sizeof(*st), GFP_NOFS); | |
33865 | + if (unlikely(!st)) | |
33866 | + goto out; | |
33867 | + | |
1facf9fc | 33868 | + err = -EINVAL; |
33869 | + bend = au_sbend(sb); | |
33870 | + if (unlikely(bindex < 0 || bend < bindex)) | |
392086de | 33871 | + goto out_st; |
1facf9fc | 33872 | + br = au_sbr(sb, bindex); |
33873 | + file = br->br_xino.xi_file; | |
33874 | + if (!file) | |
392086de AM |
33875 | + goto out_st; |
33876 | + | |
33877 | + err = vfs_statfs(&file->f_path, st); | |
33878 | + if (unlikely(err)) | |
33879 | + AuErr1("statfs err %d, ignored\n", err); | |
33880 | + jiffy = jiffies; | |
33881 | + blocks = file_inode(file)->i_blocks; | |
33882 | + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
33883 | + bindex, (u64)blocks, st->f_bfree, st->f_blocks); | |
1facf9fc | 33884 | + |
33885 | + au_xino_lock_dir(sb, file, &ldir); | |
33886 | + /* mnt_want_write() is unnecessary here */ | |
33887 | + new_xino = au_xino_create2(file, file); | |
33888 | + au_xino_unlock_dir(&ldir); | |
33889 | + err = PTR_ERR(new_xino); | |
392086de AM |
33890 | + if (IS_ERR(new_xino)) { |
33891 | + pr_err("err %d, ignored\n", err); | |
33892 | + goto out_st; | |
33893 | + } | |
1facf9fc | 33894 | + err = 0; |
33895 | + fput(file); | |
33896 | + br->br_xino.xi_file = new_xino; | |
33897 | + | |
86dc4139 | 33898 | + h_sb = au_br_sb(br); |
1facf9fc | 33899 | + for (bi = 0; bi <= bend; bi++) { |
33900 | + if (unlikely(bi == bindex)) | |
33901 | + continue; | |
33902 | + br = au_sbr(sb, bi); | |
86dc4139 | 33903 | + if (au_br_sb(br) != h_sb) |
1facf9fc | 33904 | + continue; |
33905 | + | |
33906 | + fput(br->br_xino.xi_file); | |
33907 | + br->br_xino.xi_file = new_xino; | |
33908 | + get_file(new_xino); | |
33909 | + } | |
33910 | + | |
392086de AM |
33911 | + err = vfs_statfs(&new_xino->f_path, st); |
33912 | + if (!err) { | |
33913 | + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
33914 | + bindex, (u64)file_inode(new_xino)->i_blocks, | |
33915 | + st->f_bfree, st->f_blocks); | |
33916 | + if (file_inode(new_xino)->i_blocks < blocks) | |
33917 | + au_sbi(sb)->si_xino_jiffy = jiffy; | |
33918 | + } else | |
33919 | + AuErr1("statfs err %d, ignored\n", err); | |
33920 | + | |
33921 | +out_st: | |
33922 | + kfree(st); | |
4f0767ce | 33923 | +out: |
1facf9fc | 33924 | + return err; |
33925 | +} | |
33926 | + | |
33927 | +struct xino_do_trunc_args { | |
33928 | + struct super_block *sb; | |
33929 | + struct au_branch *br; | |
33930 | +}; | |
33931 | + | |
33932 | +static void xino_do_trunc(void *_args) | |
33933 | +{ | |
33934 | + struct xino_do_trunc_args *args = _args; | |
33935 | + struct super_block *sb; | |
33936 | + struct au_branch *br; | |
33937 | + struct inode *dir; | |
33938 | + int err; | |
33939 | + aufs_bindex_t bindex; | |
33940 | + | |
33941 | + err = 0; | |
33942 | + sb = args->sb; | |
5527c038 | 33943 | + dir = d_inode(sb->s_root); |
1facf9fc | 33944 | + br = args->br; |
33945 | + | |
33946 | + si_noflush_write_lock(sb); | |
33947 | + ii_read_lock_parent(dir); | |
33948 | + bindex = au_br_index(sb, br->br_id); | |
33949 | + err = au_xino_trunc(sb, bindex); | |
1facf9fc | 33950 | + ii_read_unlock(dir); |
33951 | + if (unlikely(err)) | |
392086de | 33952 | + pr_warn("err b%d, (%d)\n", bindex, err); |
1facf9fc | 33953 | + atomic_dec(&br->br_xino_running); |
33954 | + atomic_dec(&br->br_count); | |
1facf9fc | 33955 | + si_write_unlock(sb); |
027c5e7a | 33956 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 33957 | + kfree(args); |
33958 | +} | |
33959 | + | |
392086de AM |
33960 | +static int xino_trunc_test(struct super_block *sb, struct au_branch *br) |
33961 | +{ | |
33962 | + int err; | |
33963 | + struct kstatfs st; | |
33964 | + struct au_sbinfo *sbinfo; | |
33965 | + | |
33966 | + /* todo: si_xino_expire and the ratio should be customizable */ | |
33967 | + sbinfo = au_sbi(sb); | |
33968 | + if (time_before(jiffies, | |
33969 | + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire)) | |
33970 | + return 0; | |
33971 | + | |
33972 | + /* truncation border */ | |
33973 | + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st); | |
33974 | + if (unlikely(err)) { | |
33975 | + AuErr1("statfs err %d, ignored\n", err); | |
33976 | + return 0; | |
33977 | + } | |
33978 | + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC) | |
33979 | + return 0; | |
33980 | + | |
33981 | + return 1; | |
33982 | +} | |
33983 | + | |
1facf9fc | 33984 | +static void xino_try_trunc(struct super_block *sb, struct au_branch *br) |
33985 | +{ | |
33986 | + struct xino_do_trunc_args *args; | |
33987 | + int wkq_err; | |
33988 | + | |
392086de | 33989 | + if (!xino_trunc_test(sb, br)) |
1facf9fc | 33990 | + return; |
33991 | + | |
33992 | + if (atomic_inc_return(&br->br_xino_running) > 1) | |
33993 | + goto out; | |
33994 | + | |
33995 | + /* lock and kfree() will be called in trunc_xino() */ | |
33996 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
33997 | + if (unlikely(!args)) { | |
33998 | + AuErr1("no memory\n"); | |
33999 | + goto out_args; | |
34000 | + } | |
34001 | + | |
e49829fe | 34002 | + atomic_inc(&br->br_count); |
1facf9fc | 34003 | + args->sb = sb; |
34004 | + args->br = br; | |
53392da6 | 34005 | + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0); |
1facf9fc | 34006 | + if (!wkq_err) |
34007 | + return; /* success */ | |
34008 | + | |
4a4d8108 | 34009 | + pr_err("wkq %d\n", wkq_err); |
e49829fe | 34010 | + atomic_dec(&br->br_count); |
1facf9fc | 34011 | + |
4f0767ce | 34012 | +out_args: |
1facf9fc | 34013 | + kfree(args); |
4f0767ce | 34014 | +out: |
e49829fe | 34015 | + atomic_dec(&br->br_xino_running); |
1facf9fc | 34016 | +} |
34017 | + | |
34018 | +/* ---------------------------------------------------------------------- */ | |
34019 | + | |
5527c038 | 34020 | +static int au_xino_do_write(vfs_writef_t write, struct file *file, |
1facf9fc | 34021 | + ino_t h_ino, ino_t ino) |
34022 | +{ | |
34023 | + loff_t pos; | |
34024 | + ssize_t sz; | |
34025 | + | |
34026 | + pos = h_ino; | |
34027 | + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) { | |
34028 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
34029 | + return -EFBIG; | |
34030 | + } | |
34031 | + pos *= sizeof(ino); | |
34032 | + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos); | |
34033 | + if (sz == sizeof(ino)) | |
34034 | + return 0; /* success */ | |
34035 | + | |
34036 | + AuIOErr("write failed (%zd)\n", sz); | |
34037 | + return -EIO; | |
34038 | +} | |
34039 | + | |
34040 | +/* | |
34041 | + * write @ino to the xinofile for the specified branch{@sb, @bindex} | |
34042 | + * at the position of @h_ino. | |
34043 | + * even if @ino is zero, it is written to the xinofile and means no entry. | |
34044 | + * if the size of the xino file on a specific filesystem exceeds the watermark, | |
34045 | + * try truncating it. | |
34046 | + */ | |
34047 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
34048 | + ino_t ino) | |
34049 | +{ | |
34050 | + int err; | |
34051 | + unsigned int mnt_flags; | |
34052 | + struct au_branch *br; | |
34053 | + | |
34054 | + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max) | |
34055 | + || ((loff_t)-1) > 0); | |
dece6358 | 34056 | + SiMustAnyLock(sb); |
1facf9fc | 34057 | + |
34058 | + mnt_flags = au_mntflags(sb); | |
34059 | + if (!au_opt_test(mnt_flags, XINO)) | |
34060 | + return 0; | |
34061 | + | |
34062 | + br = au_sbr(sb, bindex); | |
34063 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
34064 | + h_ino, ino); | |
34065 | + if (!err) { | |
34066 | + if (au_opt_test(mnt_flags, TRUNC_XINO) | |
86dc4139 | 34067 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
1facf9fc | 34068 | + xino_try_trunc(sb, br); |
34069 | + return 0; /* success */ | |
34070 | + } | |
34071 | + | |
34072 | + AuIOErr("write failed (%d)\n", err); | |
34073 | + return -EIO; | |
34074 | +} | |
34075 | + | |
34076 | +/* ---------------------------------------------------------------------- */ | |
34077 | + | |
34078 | +/* aufs inode number bitmap */ | |
34079 | + | |
34080 | +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE; | |
34081 | +static ino_t xib_calc_ino(unsigned long pindex, int bit) | |
34082 | +{ | |
34083 | + ino_t ino; | |
34084 | + | |
34085 | + AuDebugOn(bit < 0 || page_bits <= bit); | |
34086 | + ino = AUFS_FIRST_INO + pindex * page_bits + bit; | |
34087 | + return ino; | |
34088 | +} | |
34089 | + | |
34090 | +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit) | |
34091 | +{ | |
34092 | + AuDebugOn(ino < AUFS_FIRST_INO); | |
34093 | + ino -= AUFS_FIRST_INO; | |
34094 | + *pindex = ino / page_bits; | |
34095 | + *bit = ino % page_bits; | |
34096 | +} | |
34097 | + | |
34098 | +static int xib_pindex(struct super_block *sb, unsigned long pindex) | |
34099 | +{ | |
34100 | + int err; | |
34101 | + loff_t pos; | |
34102 | + ssize_t sz; | |
34103 | + struct au_sbinfo *sbinfo; | |
34104 | + struct file *xib; | |
34105 | + unsigned long *p; | |
34106 | + | |
34107 | + sbinfo = au_sbi(sb); | |
34108 | + MtxMustLock(&sbinfo->si_xib_mtx); | |
34109 | + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE | |
34110 | + || !au_opt_test(sbinfo->si_mntflags, XINO)); | |
34111 | + | |
34112 | + if (pindex == sbinfo->si_xib_last_pindex) | |
34113 | + return 0; | |
34114 | + | |
34115 | + xib = sbinfo->si_xib; | |
34116 | + p = sbinfo->si_xib_buf; | |
34117 | + pos = sbinfo->si_xib_last_pindex; | |
34118 | + pos *= PAGE_SIZE; | |
34119 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
34120 | + if (unlikely(sz != PAGE_SIZE)) | |
34121 | + goto out; | |
34122 | + | |
34123 | + pos = pindex; | |
34124 | + pos *= PAGE_SIZE; | |
c06a8ce3 | 34125 | + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE) |
1facf9fc | 34126 | + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos); |
34127 | + else { | |
34128 | + memset(p, 0, PAGE_SIZE); | |
34129 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
34130 | + } | |
34131 | + if (sz == PAGE_SIZE) { | |
34132 | + sbinfo->si_xib_last_pindex = pindex; | |
34133 | + return 0; /* success */ | |
34134 | + } | |
34135 | + | |
4f0767ce | 34136 | +out: |
b752ccd1 AM |
34137 | + AuIOErr1("write failed (%zd)\n", sz); |
34138 | + err = sz; | |
34139 | + if (sz >= 0) | |
34140 | + err = -EIO; | |
34141 | + return err; | |
34142 | +} | |
34143 | + | |
34144 | +/* ---------------------------------------------------------------------- */ | |
34145 | + | |
34146 | +static void au_xib_clear_bit(struct inode *inode) | |
34147 | +{ | |
34148 | + int err, bit; | |
34149 | + unsigned long pindex; | |
34150 | + struct super_block *sb; | |
34151 | + struct au_sbinfo *sbinfo; | |
34152 | + | |
34153 | + AuDebugOn(inode->i_nlink); | |
34154 | + | |
34155 | + sb = inode->i_sb; | |
34156 | + xib_calc_bit(inode->i_ino, &pindex, &bit); | |
34157 | + AuDebugOn(page_bits <= bit); | |
34158 | + sbinfo = au_sbi(sb); | |
34159 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34160 | + err = xib_pindex(sb, pindex); | |
34161 | + if (!err) { | |
34162 | + clear_bit(bit, sbinfo->si_xib_buf); | |
34163 | + sbinfo->si_xib_next_bit = bit; | |
34164 | + } | |
34165 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34166 | +} | |
34167 | + | |
34168 | +/* for s_op->delete_inode() */ | |
34169 | +void au_xino_delete_inode(struct inode *inode, const int unlinked) | |
34170 | +{ | |
34171 | + int err; | |
34172 | + unsigned int mnt_flags; | |
34173 | + aufs_bindex_t bindex, bend, bi; | |
34174 | + unsigned char try_trunc; | |
34175 | + struct au_iinfo *iinfo; | |
34176 | + struct super_block *sb; | |
34177 | + struct au_hinode *hi; | |
34178 | + struct inode *h_inode; | |
34179 | + struct au_branch *br; | |
5527c038 | 34180 | + vfs_writef_t xwrite; |
b752ccd1 AM |
34181 | + |
34182 | + sb = inode->i_sb; | |
34183 | + mnt_flags = au_mntflags(sb); | |
34184 | + if (!au_opt_test(mnt_flags, XINO) | |
34185 | + || inode->i_ino == AUFS_ROOT_INO) | |
34186 | + return; | |
34187 | + | |
34188 | + if (unlinked) { | |
34189 | + au_xigen_inc(inode); | |
34190 | + au_xib_clear_bit(inode); | |
34191 | + } | |
34192 | + | |
34193 | + iinfo = au_ii(inode); | |
34194 | + if (!iinfo) | |
34195 | + return; | |
1facf9fc | 34196 | + |
b752ccd1 AM |
34197 | + bindex = iinfo->ii_bstart; |
34198 | + if (bindex < 0) | |
34199 | + return; | |
1facf9fc | 34200 | + |
b752ccd1 AM |
34201 | + xwrite = au_sbi(sb)->si_xwrite; |
34202 | + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO); | |
34203 | + hi = iinfo->ii_hinode + bindex; | |
34204 | + bend = iinfo->ii_bend; | |
34205 | + for (; bindex <= bend; bindex++, hi++) { | |
34206 | + h_inode = hi->hi_inode; | |
34207 | + if (!h_inode | |
34208 | + || (!unlinked && h_inode->i_nlink)) | |
34209 | + continue; | |
1facf9fc | 34210 | + |
b752ccd1 AM |
34211 | + /* inode may not be revalidated */ |
34212 | + bi = au_br_index(sb, hi->hi_id); | |
34213 | + if (bi < 0) | |
34214 | + continue; | |
1facf9fc | 34215 | + |
b752ccd1 AM |
34216 | + br = au_sbr(sb, bi); |
34217 | + err = au_xino_do_write(xwrite, br->br_xino.xi_file, | |
34218 | + h_inode->i_ino, /*ino*/0); | |
34219 | + if (!err && try_trunc | |
86dc4139 | 34220 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
b752ccd1 | 34221 | + xino_try_trunc(sb, br); |
1facf9fc | 34222 | + } |
1facf9fc | 34223 | +} |
34224 | + | |
34225 | +/* get an unused inode number from bitmap */ | |
34226 | +ino_t au_xino_new_ino(struct super_block *sb) | |
34227 | +{ | |
34228 | + ino_t ino; | |
34229 | + unsigned long *p, pindex, ul, pend; | |
34230 | + struct au_sbinfo *sbinfo; | |
34231 | + struct file *file; | |
34232 | + int free_bit, err; | |
34233 | + | |
34234 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
34235 | + return iunique(sb, AUFS_FIRST_INO); | |
34236 | + | |
34237 | + sbinfo = au_sbi(sb); | |
34238 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34239 | + p = sbinfo->si_xib_buf; | |
34240 | + free_bit = sbinfo->si_xib_next_bit; | |
34241 | + if (free_bit < page_bits && !test_bit(free_bit, p)) | |
34242 | + goto out; /* success */ | |
34243 | + free_bit = find_first_zero_bit(p, page_bits); | |
34244 | + if (free_bit < page_bits) | |
34245 | + goto out; /* success */ | |
34246 | + | |
34247 | + pindex = sbinfo->si_xib_last_pindex; | |
34248 | + for (ul = pindex - 1; ul < ULONG_MAX; ul--) { | |
34249 | + err = xib_pindex(sb, ul); | |
34250 | + if (unlikely(err)) | |
34251 | + goto out_err; | |
34252 | + free_bit = find_first_zero_bit(p, page_bits); | |
34253 | + if (free_bit < page_bits) | |
34254 | + goto out; /* success */ | |
34255 | + } | |
34256 | + | |
34257 | + file = sbinfo->si_xib; | |
c06a8ce3 | 34258 | + pend = vfsub_f_size_read(file) / PAGE_SIZE; |
1facf9fc | 34259 | + for (ul = pindex + 1; ul <= pend; ul++) { |
34260 | + err = xib_pindex(sb, ul); | |
34261 | + if (unlikely(err)) | |
34262 | + goto out_err; | |
34263 | + free_bit = find_first_zero_bit(p, page_bits); | |
34264 | + if (free_bit < page_bits) | |
34265 | + goto out; /* success */ | |
34266 | + } | |
34267 | + BUG(); | |
34268 | + | |
4f0767ce | 34269 | +out: |
1facf9fc | 34270 | + set_bit(free_bit, p); |
7f207e10 | 34271 | + sbinfo->si_xib_next_bit = free_bit + 1; |
1facf9fc | 34272 | + pindex = sbinfo->si_xib_last_pindex; |
34273 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34274 | + ino = xib_calc_ino(pindex, free_bit); | |
34275 | + AuDbg("i%lu\n", (unsigned long)ino); | |
34276 | + return ino; | |
4f0767ce | 34277 | +out_err: |
1facf9fc | 34278 | + mutex_unlock(&sbinfo->si_xib_mtx); |
34279 | + AuDbg("i0\n"); | |
34280 | + return 0; | |
34281 | +} | |
34282 | + | |
34283 | +/* | |
34284 | + * read @ino from xinofile for the specified branch{@sb, @bindex} | |
34285 | + * at the position of @h_ino. | |
34286 | + * if @ino does not exist and @do_new is true, get new one. | |
34287 | + */ | |
34288 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
34289 | + ino_t *ino) | |
34290 | +{ | |
34291 | + int err; | |
34292 | + ssize_t sz; | |
34293 | + loff_t pos; | |
34294 | + struct file *file; | |
34295 | + struct au_sbinfo *sbinfo; | |
34296 | + | |
34297 | + *ino = 0; | |
34298 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
34299 | + return 0; /* no xino */ | |
34300 | + | |
34301 | + err = 0; | |
34302 | + sbinfo = au_sbi(sb); | |
34303 | + pos = h_ino; | |
34304 | + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) { | |
34305 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
34306 | + return -EFBIG; | |
34307 | + } | |
34308 | + pos *= sizeof(*ino); | |
34309 | + | |
34310 | + file = au_sbr(sb, bindex)->br_xino.xi_file; | |
c06a8ce3 | 34311 | + if (vfsub_f_size_read(file) < pos + sizeof(*ino)) |
1facf9fc | 34312 | + return 0; /* no ino */ |
34313 | + | |
34314 | + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos); | |
34315 | + if (sz == sizeof(*ino)) | |
34316 | + return 0; /* success */ | |
34317 | + | |
34318 | + err = sz; | |
34319 | + if (unlikely(sz >= 0)) { | |
34320 | + err = -EIO; | |
34321 | + AuIOErr("xino read error (%zd)\n", sz); | |
34322 | + } | |
34323 | + | |
34324 | + return err; | |
34325 | +} | |
34326 | + | |
34327 | +/* ---------------------------------------------------------------------- */ | |
34328 | + | |
34329 | +/* create and set a new xino file */ | |
34330 | + | |
34331 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent) | |
34332 | +{ | |
34333 | + struct file *file; | |
34334 | + struct dentry *h_parent, *d; | |
b912730e | 34335 | + struct inode *h_dir, *inode; |
1facf9fc | 34336 | + int err; |
34337 | + | |
34338 | + /* | |
34339 | + * at mount-time, and the xino file is the default path, | |
4a4d8108 | 34340 | + * hnotify is disabled so we have no notify events to ignore. |
1facf9fc | 34341 | + * when a user specified the xino, we cannot get au_hdir to be ignored. |
34342 | + */ | |
7f207e10 | 34343 | + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 34344 | + /* | __FMODE_NONOTIFY */, |
1facf9fc | 34345 | + S_IRUGO | S_IWUGO); |
34346 | + if (IS_ERR(file)) { | |
34347 | + if (!silent) | |
4a4d8108 | 34348 | + pr_err("open %s(%ld)\n", fname, PTR_ERR(file)); |
1facf9fc | 34349 | + return file; |
34350 | + } | |
34351 | + | |
34352 | + /* keep file count */ | |
b912730e AM |
34353 | + err = 0; |
34354 | + inode = file_inode(file); | |
2000de60 | 34355 | + h_parent = dget_parent(file->f_path.dentry); |
5527c038 | 34356 | + h_dir = d_inode(h_parent); |
1facf9fc | 34357 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); |
34358 | + /* mnt_want_write() is unnecessary here */ | |
523b37e3 | 34359 | + /* no delegation since it is just created */ |
b912730e AM |
34360 | + if (inode->i_nlink) |
34361 | + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, | |
34362 | + /*force*/0); | |
1facf9fc | 34363 | + mutex_unlock(&h_dir->i_mutex); |
34364 | + dput(h_parent); | |
34365 | + if (unlikely(err)) { | |
34366 | + if (!silent) | |
4a4d8108 | 34367 | + pr_err("unlink %s(%d)\n", fname, err); |
1facf9fc | 34368 | + goto out; |
34369 | + } | |
34370 | + | |
34371 | + err = -EINVAL; | |
2000de60 | 34372 | + d = file->f_path.dentry; |
1facf9fc | 34373 | + if (unlikely(sb == d->d_sb)) { |
34374 | + if (!silent) | |
4a4d8108 | 34375 | + pr_err("%s must be outside\n", fname); |
1facf9fc | 34376 | + goto out; |
34377 | + } | |
34378 | + if (unlikely(au_test_fs_bad_xino(d->d_sb))) { | |
34379 | + if (!silent) | |
4a4d8108 AM |
34380 | + pr_err("xino doesn't support %s(%s)\n", |
34381 | + fname, au_sbtype(d->d_sb)); | |
1facf9fc | 34382 | + goto out; |
34383 | + } | |
34384 | + return file; /* success */ | |
34385 | + | |
4f0767ce | 34386 | +out: |
1facf9fc | 34387 | + fput(file); |
34388 | + file = ERR_PTR(err); | |
34389 | + return file; | |
34390 | +} | |
34391 | + | |
34392 | +/* | |
34393 | + * find another branch who is on the same filesystem of the specified | |
34394 | + * branch{@btgt}. search until @bend. | |
34395 | + */ | |
34396 | +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt, | |
34397 | + aufs_bindex_t bend) | |
34398 | +{ | |
34399 | + aufs_bindex_t bindex; | |
34400 | + struct super_block *tgt_sb = au_sbr_sb(sb, btgt); | |
34401 | + | |
34402 | + for (bindex = 0; bindex < btgt; bindex++) | |
34403 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
34404 | + return bindex; | |
34405 | + for (bindex++; bindex <= bend; bindex++) | |
34406 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
34407 | + return bindex; | |
34408 | + return -1; | |
34409 | +} | |
34410 | + | |
34411 | +/* ---------------------------------------------------------------------- */ | |
34412 | + | |
34413 | +/* | |
34414 | + * initialize the xinofile for the specified branch @br | |
34415 | + * at the place/path where @base_file indicates. | |
34416 | + * test whether another branch is on the same filesystem or not, | |
34417 | + * if @do_test is true. | |
34418 | + */ | |
34419 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino, | |
34420 | + struct file *base_file, int do_test) | |
34421 | +{ | |
34422 | + int err; | |
34423 | + ino_t ino; | |
34424 | + aufs_bindex_t bend, bindex; | |
34425 | + struct au_branch *shared_br, *b; | |
34426 | + struct file *file; | |
34427 | + struct super_block *tgt_sb; | |
34428 | + | |
34429 | + shared_br = NULL; | |
34430 | + bend = au_sbend(sb); | |
34431 | + if (do_test) { | |
86dc4139 | 34432 | + tgt_sb = au_br_sb(br); |
1facf9fc | 34433 | + for (bindex = 0; bindex <= bend; bindex++) { |
34434 | + b = au_sbr(sb, bindex); | |
86dc4139 | 34435 | + if (tgt_sb == au_br_sb(b)) { |
1facf9fc | 34436 | + shared_br = b; |
34437 | + break; | |
34438 | + } | |
34439 | + } | |
34440 | + } | |
34441 | + | |
34442 | + if (!shared_br || !shared_br->br_xino.xi_file) { | |
34443 | + struct au_xino_lock_dir ldir; | |
34444 | + | |
34445 | + au_xino_lock_dir(sb, base_file, &ldir); | |
34446 | + /* mnt_want_write() is unnecessary here */ | |
34447 | + file = au_xino_create2(base_file, NULL); | |
34448 | + au_xino_unlock_dir(&ldir); | |
34449 | + err = PTR_ERR(file); | |
34450 | + if (IS_ERR(file)) | |
34451 | + goto out; | |
34452 | + br->br_xino.xi_file = file; | |
34453 | + } else { | |
34454 | + br->br_xino.xi_file = shared_br->br_xino.xi_file; | |
34455 | + get_file(br->br_xino.xi_file); | |
34456 | + } | |
34457 | + | |
34458 | + ino = AUFS_ROOT_INO; | |
34459 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
34460 | + h_ino, ino); | |
b752ccd1 AM |
34461 | + if (unlikely(err)) { |
34462 | + fput(br->br_xino.xi_file); | |
34463 | + br->br_xino.xi_file = NULL; | |
34464 | + } | |
1facf9fc | 34465 | + |
4f0767ce | 34466 | +out: |
1facf9fc | 34467 | + return err; |
34468 | +} | |
34469 | + | |
34470 | +/* ---------------------------------------------------------------------- */ | |
34471 | + | |
34472 | +/* trucate a xino bitmap file */ | |
34473 | + | |
34474 | +/* todo: slow */ | |
34475 | +static int do_xib_restore(struct super_block *sb, struct file *file, void *page) | |
34476 | +{ | |
34477 | + int err, bit; | |
34478 | + ssize_t sz; | |
34479 | + unsigned long pindex; | |
34480 | + loff_t pos, pend; | |
34481 | + struct au_sbinfo *sbinfo; | |
5527c038 | 34482 | + vfs_readf_t func; |
1facf9fc | 34483 | + ino_t *ino; |
34484 | + unsigned long *p; | |
34485 | + | |
34486 | + err = 0; | |
34487 | + sbinfo = au_sbi(sb); | |
dece6358 | 34488 | + MtxMustLock(&sbinfo->si_xib_mtx); |
1facf9fc | 34489 | + p = sbinfo->si_xib_buf; |
34490 | + func = sbinfo->si_xread; | |
c06a8ce3 | 34491 | + pend = vfsub_f_size_read(file); |
1facf9fc | 34492 | + pos = 0; |
34493 | + while (pos < pend) { | |
34494 | + sz = xino_fread(func, file, page, PAGE_SIZE, &pos); | |
34495 | + err = sz; | |
34496 | + if (unlikely(sz <= 0)) | |
34497 | + goto out; | |
34498 | + | |
34499 | + err = 0; | |
34500 | + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) { | |
34501 | + if (unlikely(*ino < AUFS_FIRST_INO)) | |
34502 | + continue; | |
34503 | + | |
34504 | + xib_calc_bit(*ino, &pindex, &bit); | |
34505 | + AuDebugOn(page_bits <= bit); | |
34506 | + err = xib_pindex(sb, pindex); | |
34507 | + if (!err) | |
34508 | + set_bit(bit, p); | |
34509 | + else | |
34510 | + goto out; | |
34511 | + } | |
34512 | + } | |
34513 | + | |
4f0767ce | 34514 | +out: |
1facf9fc | 34515 | + return err; |
34516 | +} | |
34517 | + | |
34518 | +static int xib_restore(struct super_block *sb) | |
34519 | +{ | |
34520 | + int err; | |
34521 | + aufs_bindex_t bindex, bend; | |
34522 | + void *page; | |
34523 | + | |
34524 | + err = -ENOMEM; | |
34525 | + page = (void *)__get_free_page(GFP_NOFS); | |
34526 | + if (unlikely(!page)) | |
34527 | + goto out; | |
34528 | + | |
34529 | + err = 0; | |
34530 | + bend = au_sbend(sb); | |
34531 | + for (bindex = 0; !err && bindex <= bend; bindex++) | |
34532 | + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) | |
34533 | + err = do_xib_restore | |
34534 | + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page); | |
34535 | + else | |
34536 | + AuDbg("b%d\n", bindex); | |
34537 | + free_page((unsigned long)page); | |
34538 | + | |
4f0767ce | 34539 | +out: |
1facf9fc | 34540 | + return err; |
34541 | +} | |
34542 | + | |
34543 | +int au_xib_trunc(struct super_block *sb) | |
34544 | +{ | |
34545 | + int err; | |
34546 | + ssize_t sz; | |
34547 | + loff_t pos; | |
34548 | + struct au_xino_lock_dir ldir; | |
34549 | + struct au_sbinfo *sbinfo; | |
34550 | + unsigned long *p; | |
34551 | + struct file *file; | |
34552 | + | |
dece6358 AM |
34553 | + SiMustWriteLock(sb); |
34554 | + | |
1facf9fc | 34555 | + err = 0; |
34556 | + sbinfo = au_sbi(sb); | |
34557 | + if (!au_opt_test(sbinfo->si_mntflags, XINO)) | |
34558 | + goto out; | |
34559 | + | |
34560 | + file = sbinfo->si_xib; | |
c06a8ce3 | 34561 | + if (vfsub_f_size_read(file) <= PAGE_SIZE) |
1facf9fc | 34562 | + goto out; |
34563 | + | |
34564 | + au_xino_lock_dir(sb, file, &ldir); | |
34565 | + /* mnt_want_write() is unnecessary here */ | |
34566 | + file = au_xino_create2(sbinfo->si_xib, NULL); | |
34567 | + au_xino_unlock_dir(&ldir); | |
34568 | + err = PTR_ERR(file); | |
34569 | + if (IS_ERR(file)) | |
34570 | + goto out; | |
34571 | + fput(sbinfo->si_xib); | |
34572 | + sbinfo->si_xib = file; | |
34573 | + | |
34574 | + p = sbinfo->si_xib_buf; | |
34575 | + memset(p, 0, PAGE_SIZE); | |
34576 | + pos = 0; | |
34577 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos); | |
34578 | + if (unlikely(sz != PAGE_SIZE)) { | |
34579 | + err = sz; | |
34580 | + AuIOErr("err %d\n", err); | |
34581 | + if (sz >= 0) | |
34582 | + err = -EIO; | |
34583 | + goto out; | |
34584 | + } | |
34585 | + | |
34586 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34587 | + /* mnt_want_write() is unnecessary here */ | |
34588 | + err = xib_restore(sb); | |
34589 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34590 | + | |
34591 | +out: | |
34592 | + return err; | |
34593 | +} | |
34594 | + | |
34595 | +/* ---------------------------------------------------------------------- */ | |
34596 | + | |
34597 | +/* | |
34598 | + * xino mount option handlers | |
34599 | + */ | |
1facf9fc | 34600 | + |
34601 | +/* xino bitmap */ | |
34602 | +static void xino_clear_xib(struct super_block *sb) | |
34603 | +{ | |
34604 | + struct au_sbinfo *sbinfo; | |
34605 | + | |
dece6358 AM |
34606 | + SiMustWriteLock(sb); |
34607 | + | |
1facf9fc | 34608 | + sbinfo = au_sbi(sb); |
34609 | + sbinfo->si_xread = NULL; | |
34610 | + sbinfo->si_xwrite = NULL; | |
34611 | + if (sbinfo->si_xib) | |
34612 | + fput(sbinfo->si_xib); | |
34613 | + sbinfo->si_xib = NULL; | |
34614 | + free_page((unsigned long)sbinfo->si_xib_buf); | |
34615 | + sbinfo->si_xib_buf = NULL; | |
34616 | +} | |
34617 | + | |
34618 | +static int au_xino_set_xib(struct super_block *sb, struct file *base) | |
34619 | +{ | |
34620 | + int err; | |
34621 | + loff_t pos; | |
34622 | + struct au_sbinfo *sbinfo; | |
34623 | + struct file *file; | |
34624 | + | |
dece6358 AM |
34625 | + SiMustWriteLock(sb); |
34626 | + | |
1facf9fc | 34627 | + sbinfo = au_sbi(sb); |
34628 | + file = au_xino_create2(base, sbinfo->si_xib); | |
34629 | + err = PTR_ERR(file); | |
34630 | + if (IS_ERR(file)) | |
34631 | + goto out; | |
34632 | + if (sbinfo->si_xib) | |
34633 | + fput(sbinfo->si_xib); | |
34634 | + sbinfo->si_xib = file; | |
5527c038 JR |
34635 | + sbinfo->si_xread = vfs_readf(file); |
34636 | + sbinfo->si_xwrite = vfs_writef(file); | |
1facf9fc | 34637 | + |
34638 | + err = -ENOMEM; | |
34639 | + if (!sbinfo->si_xib_buf) | |
34640 | + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS); | |
34641 | + if (unlikely(!sbinfo->si_xib_buf)) | |
34642 | + goto out_unset; | |
34643 | + | |
34644 | + sbinfo->si_xib_last_pindex = 0; | |
34645 | + sbinfo->si_xib_next_bit = 0; | |
c06a8ce3 | 34646 | + if (vfsub_f_size_read(file) < PAGE_SIZE) { |
1facf9fc | 34647 | + pos = 0; |
34648 | + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf, | |
34649 | + PAGE_SIZE, &pos); | |
34650 | + if (unlikely(err != PAGE_SIZE)) | |
34651 | + goto out_free; | |
34652 | + } | |
34653 | + err = 0; | |
34654 | + goto out; /* success */ | |
34655 | + | |
4f0767ce | 34656 | +out_free: |
1facf9fc | 34657 | + free_page((unsigned long)sbinfo->si_xib_buf); |
b752ccd1 AM |
34658 | + sbinfo->si_xib_buf = NULL; |
34659 | + if (err >= 0) | |
34660 | + err = -EIO; | |
4f0767ce | 34661 | +out_unset: |
b752ccd1 AM |
34662 | + fput(sbinfo->si_xib); |
34663 | + sbinfo->si_xib = NULL; | |
34664 | + sbinfo->si_xread = NULL; | |
34665 | + sbinfo->si_xwrite = NULL; | |
4f0767ce | 34666 | +out: |
b752ccd1 | 34667 | + return err; |
1facf9fc | 34668 | +} |
34669 | + | |
b752ccd1 AM |
34670 | +/* xino for each branch */ |
34671 | +static void xino_clear_br(struct super_block *sb) | |
34672 | +{ | |
34673 | + aufs_bindex_t bindex, bend; | |
34674 | + struct au_branch *br; | |
1facf9fc | 34675 | + |
b752ccd1 AM |
34676 | + bend = au_sbend(sb); |
34677 | + for (bindex = 0; bindex <= bend; bindex++) { | |
34678 | + br = au_sbr(sb, bindex); | |
34679 | + if (!br || !br->br_xino.xi_file) | |
34680 | + continue; | |
34681 | + | |
34682 | + fput(br->br_xino.xi_file); | |
34683 | + br->br_xino.xi_file = NULL; | |
34684 | + } | |
34685 | +} | |
34686 | + | |
34687 | +static int au_xino_set_br(struct super_block *sb, struct file *base) | |
1facf9fc | 34688 | +{ |
34689 | + int err; | |
b752ccd1 AM |
34690 | + ino_t ino; |
34691 | + aufs_bindex_t bindex, bend, bshared; | |
34692 | + struct { | |
34693 | + struct file *old, *new; | |
34694 | + } *fpair, *p; | |
34695 | + struct au_branch *br; | |
34696 | + struct inode *inode; | |
5527c038 | 34697 | + vfs_writef_t writef; |
1facf9fc | 34698 | + |
b752ccd1 AM |
34699 | + SiMustWriteLock(sb); |
34700 | + | |
34701 | + err = -ENOMEM; | |
34702 | + bend = au_sbend(sb); | |
34703 | + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS); | |
34704 | + if (unlikely(!fpair)) | |
1facf9fc | 34705 | + goto out; |
34706 | + | |
5527c038 | 34707 | + inode = d_inode(sb->s_root); |
b752ccd1 AM |
34708 | + ino = AUFS_ROOT_INO; |
34709 | + writef = au_sbi(sb)->si_xwrite; | |
34710 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) { | |
34711 | + br = au_sbr(sb, bindex); | |
34712 | + bshared = is_sb_shared(sb, bindex, bindex - 1); | |
34713 | + if (bshared >= 0) { | |
34714 | + /* shared xino */ | |
34715 | + *p = fpair[bshared]; | |
34716 | + get_file(p->new); | |
34717 | + } | |
34718 | + | |
34719 | + if (!p->new) { | |
34720 | + /* new xino */ | |
34721 | + p->old = br->br_xino.xi_file; | |
34722 | + p->new = au_xino_create2(base, br->br_xino.xi_file); | |
34723 | + err = PTR_ERR(p->new); | |
34724 | + if (IS_ERR(p->new)) { | |
34725 | + p->new = NULL; | |
34726 | + goto out_pair; | |
34727 | + } | |
34728 | + } | |
34729 | + | |
34730 | + err = au_xino_do_write(writef, p->new, | |
34731 | + au_h_iptr(inode, bindex)->i_ino, ino); | |
34732 | + if (unlikely(err)) | |
34733 | + goto out_pair; | |
34734 | + } | |
34735 | + | |
34736 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) { | |
34737 | + br = au_sbr(sb, bindex); | |
34738 | + if (br->br_xino.xi_file) | |
34739 | + fput(br->br_xino.xi_file); | |
34740 | + get_file(p->new); | |
34741 | + br->br_xino.xi_file = p->new; | |
34742 | + } | |
1facf9fc | 34743 | + |
4f0767ce | 34744 | +out_pair: |
b752ccd1 AM |
34745 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) |
34746 | + if (p->new) | |
34747 | + fput(p->new); | |
34748 | + else | |
34749 | + break; | |
34750 | + kfree(fpair); | |
4f0767ce | 34751 | +out: |
1facf9fc | 34752 | + return err; |
34753 | +} | |
b752ccd1 AM |
34754 | + |
34755 | +void au_xino_clr(struct super_block *sb) | |
34756 | +{ | |
34757 | + struct au_sbinfo *sbinfo; | |
34758 | + | |
34759 | + au_xigen_clr(sb); | |
34760 | + xino_clear_xib(sb); | |
34761 | + xino_clear_br(sb); | |
34762 | + sbinfo = au_sbi(sb); | |
34763 | + /* lvalue, do not call au_mntflags() */ | |
34764 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
34765 | +} | |
34766 | + | |
34767 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount) | |
34768 | +{ | |
34769 | + int err, skip; | |
34770 | + struct dentry *parent, *cur_parent; | |
34771 | + struct qstr *dname, *cur_name; | |
34772 | + struct file *cur_xino; | |
34773 | + struct inode *dir; | |
34774 | + struct au_sbinfo *sbinfo; | |
34775 | + | |
34776 | + SiMustWriteLock(sb); | |
34777 | + | |
34778 | + err = 0; | |
34779 | + sbinfo = au_sbi(sb); | |
2000de60 | 34780 | + parent = dget_parent(xino->file->f_path.dentry); |
b752ccd1 AM |
34781 | + if (remount) { |
34782 | + skip = 0; | |
2000de60 | 34783 | + dname = &xino->file->f_path.dentry->d_name; |
b752ccd1 AM |
34784 | + cur_xino = sbinfo->si_xib; |
34785 | + if (cur_xino) { | |
2000de60 JR |
34786 | + cur_parent = dget_parent(cur_xino->f_path.dentry); |
34787 | + cur_name = &cur_xino->f_path.dentry->d_name; | |
b752ccd1 | 34788 | + skip = (cur_parent == parent |
38d290e6 | 34789 | + && au_qstreq(dname, cur_name)); |
b752ccd1 AM |
34790 | + dput(cur_parent); |
34791 | + } | |
34792 | + if (skip) | |
34793 | + goto out; | |
34794 | + } | |
34795 | + | |
34796 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
5527c038 | 34797 | + dir = d_inode(parent); |
b752ccd1 AM |
34798 | + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT); |
34799 | + /* mnt_want_write() is unnecessary here */ | |
34800 | + err = au_xino_set_xib(sb, xino->file); | |
34801 | + if (!err) | |
34802 | + err = au_xigen_set(sb, xino->file); | |
34803 | + if (!err) | |
34804 | + err = au_xino_set_br(sb, xino->file); | |
34805 | + mutex_unlock(&dir->i_mutex); | |
34806 | + if (!err) | |
34807 | + goto out; /* success */ | |
34808 | + | |
34809 | + /* reset all */ | |
34810 | + AuIOErr("failed creating xino(%d).\n", err); | |
c1595e42 JR |
34811 | + au_xigen_clr(sb); |
34812 | + xino_clear_xib(sb); | |
b752ccd1 | 34813 | + |
4f0767ce | 34814 | +out: |
b752ccd1 AM |
34815 | + dput(parent); |
34816 | + return err; | |
34817 | +} | |
34818 | + | |
34819 | +/* ---------------------------------------------------------------------- */ | |
34820 | + | |
34821 | +/* | |
34822 | + * create a xinofile at the default place/path. | |
34823 | + */ | |
34824 | +struct file *au_xino_def(struct super_block *sb) | |
34825 | +{ | |
34826 | + struct file *file; | |
34827 | + char *page, *p; | |
34828 | + struct au_branch *br; | |
34829 | + struct super_block *h_sb; | |
34830 | + struct path path; | |
34831 | + aufs_bindex_t bend, bindex, bwr; | |
34832 | + | |
34833 | + br = NULL; | |
34834 | + bend = au_sbend(sb); | |
34835 | + bwr = -1; | |
34836 | + for (bindex = 0; bindex <= bend; bindex++) { | |
34837 | + br = au_sbr(sb, bindex); | |
34838 | + if (au_br_writable(br->br_perm) | |
86dc4139 | 34839 | + && !au_test_fs_bad_xino(au_br_sb(br))) { |
b752ccd1 AM |
34840 | + bwr = bindex; |
34841 | + break; | |
34842 | + } | |
34843 | + } | |
34844 | + | |
7f207e10 AM |
34845 | + if (bwr >= 0) { |
34846 | + file = ERR_PTR(-ENOMEM); | |
537831f9 | 34847 | + page = (void *)__get_free_page(GFP_NOFS); |
7f207e10 AM |
34848 | + if (unlikely(!page)) |
34849 | + goto out; | |
86dc4139 | 34850 | + path.mnt = au_br_mnt(br); |
7f207e10 AM |
34851 | + path.dentry = au_h_dptr(sb->s_root, bwr); |
34852 | + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME)); | |
34853 | + file = (void *)p; | |
34854 | + if (!IS_ERR(p)) { | |
34855 | + strcat(p, "/" AUFS_XINO_FNAME); | |
34856 | + AuDbg("%s\n", p); | |
34857 | + file = au_xino_create(sb, p, /*silent*/0); | |
34858 | + if (!IS_ERR(file)) | |
34859 | + au_xino_brid_set(sb, br->br_id); | |
34860 | + } | |
537831f9 | 34861 | + free_page((unsigned long)page); |
7f207e10 AM |
34862 | + } else { |
34863 | + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0); | |
34864 | + if (IS_ERR(file)) | |
34865 | + goto out; | |
2000de60 | 34866 | + h_sb = file->f_path.dentry->d_sb; |
7f207e10 AM |
34867 | + if (unlikely(au_test_fs_bad_xino(h_sb))) { |
34868 | + pr_err("xino doesn't support %s(%s)\n", | |
34869 | + AUFS_XINO_DEFPATH, au_sbtype(h_sb)); | |
34870 | + fput(file); | |
34871 | + file = ERR_PTR(-EINVAL); | |
34872 | + } | |
34873 | + if (!IS_ERR(file)) | |
34874 | + au_xino_brid_set(sb, -1); | |
34875 | + } | |
0c5527e5 | 34876 | + |
7f207e10 AM |
34877 | +out: |
34878 | + return file; | |
34879 | +} | |
34880 | + | |
34881 | +/* ---------------------------------------------------------------------- */ | |
34882 | + | |
34883 | +int au_xino_path(struct seq_file *seq, struct file *file) | |
34884 | +{ | |
34885 | + int err; | |
34886 | + | |
34887 | + err = au_seq_path(seq, &file->f_path); | |
34888 | + if (unlikely(err < 0)) | |
34889 | + goto out; | |
34890 | + | |
34891 | + err = 0; | |
34892 | +#define Deleted "\\040(deleted)" | |
34893 | + seq->count -= sizeof(Deleted) - 1; | |
34894 | + AuDebugOn(memcmp(seq->buf + seq->count, Deleted, | |
34895 | + sizeof(Deleted) - 1)); | |
34896 | +#undef Deleted | |
34897 | + | |
34898 | +out: | |
34899 | + return err; | |
34900 | +} | |
537831f9 AM |
34901 | diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h |
34902 | --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100 | |
c2c0f25c | 34903 | +++ linux/include/uapi/linux/aufs_type.h 2015-09-24 10:47:58.258053165 +0200 |
c1595e42 | 34904 | @@ -0,0 +1,419 @@ |
7f207e10 | 34905 | +/* |
2000de60 | 34906 | + * Copyright (C) 2005-2015 Junjiro R. Okajima |
7f207e10 AM |
34907 | + * |
34908 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34909 | + * it under the terms of the GNU General Public License as published by | |
34910 | + * the Free Software Foundation; either version 2 of the License, or | |
34911 | + * (at your option) any later version. | |
34912 | + * | |
34913 | + * This program is distributed in the hope that it will be useful, | |
34914 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34915 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34916 | + * GNU General Public License for more details. | |
34917 | + * | |
34918 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 34919 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
34920 | + */ |
34921 | + | |
34922 | +#ifndef __AUFS_TYPE_H__ | |
34923 | +#define __AUFS_TYPE_H__ | |
34924 | + | |
f6c5ef8b AM |
34925 | +#define AUFS_NAME "aufs" |
34926 | + | |
9dbd164d | 34927 | +#ifdef __KERNEL__ |
f6c5ef8b AM |
34928 | +/* |
34929 | + * define it before including all other headers. | |
34930 | + * sched.h may use pr_* macros before defining "current", so define the | |
34931 | + * no-current version first, and re-define later. | |
34932 | + */ | |
34933 | +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__ | |
34934 | +#include <linux/sched.h> | |
34935 | +#undef pr_fmt | |
a2a7ad62 AM |
34936 | +#define pr_fmt(fmt) \ |
34937 | + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \ | |
34938 | + (int)sizeof(current->comm), current->comm, current->pid | |
9dbd164d AM |
34939 | +#else |
34940 | +#include <stdint.h> | |
34941 | +#include <sys/types.h> | |
f6c5ef8b | 34942 | +#endif /* __KERNEL__ */ |
7f207e10 | 34943 | + |
f6c5ef8b AM |
34944 | +#include <linux/limits.h> |
34945 | + | |
c2c0f25c | 34946 | +#define AUFS_VERSION "4.x-rcN-20150921" |
7f207e10 AM |
34947 | + |
34948 | +/* todo? move this to linux-2.6.19/include/magic.h */ | |
34949 | +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's') | |
34950 | + | |
34951 | +/* ---------------------------------------------------------------------- */ | |
34952 | + | |
34953 | +#ifdef CONFIG_AUFS_BRANCH_MAX_127 | |
9dbd164d | 34954 | +typedef int8_t aufs_bindex_t; |
7f207e10 AM |
34955 | +#define AUFS_BRANCH_MAX 127 |
34956 | +#else | |
9dbd164d | 34957 | +typedef int16_t aufs_bindex_t; |
7f207e10 AM |
34958 | +#ifdef CONFIG_AUFS_BRANCH_MAX_511 |
34959 | +#define AUFS_BRANCH_MAX 511 | |
34960 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023) | |
34961 | +#define AUFS_BRANCH_MAX 1023 | |
34962 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767) | |
34963 | +#define AUFS_BRANCH_MAX 32767 | |
34964 | +#endif | |
34965 | +#endif | |
34966 | + | |
34967 | +#ifdef __KERNEL__ | |
34968 | +#ifndef AUFS_BRANCH_MAX | |
34969 | +#error unknown CONFIG_AUFS_BRANCH_MAX value | |
34970 | +#endif | |
34971 | +#endif /* __KERNEL__ */ | |
34972 | + | |
34973 | +/* ---------------------------------------------------------------------- */ | |
34974 | + | |
7f207e10 AM |
34975 | +#define AUFS_FSTYPE AUFS_NAME |
34976 | + | |
34977 | +#define AUFS_ROOT_INO 2 | |
34978 | +#define AUFS_FIRST_INO 11 | |
34979 | + | |
34980 | +#define AUFS_WH_PFX ".wh." | |
34981 | +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1) | |
34982 | +#define AUFS_WH_TMP_LEN 4 | |
86dc4139 | 34983 | +/* a limit for rmdir/rename a dir and copyup */ |
7f207e10 AM |
34984 | +#define AUFS_MAX_NAMELEN (NAME_MAX \ |
34985 | + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\ | |
34986 | + - 1 /* dot */\ | |
34987 | + - AUFS_WH_TMP_LEN) /* hex */ | |
34988 | +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino" | |
34989 | +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME | |
392086de AM |
34990 | +#define AUFS_XINO_DEF_SEC 30 /* seconds */ |
34991 | +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */ | |
7f207e10 AM |
34992 | +#define AUFS_DIRWH_DEF 3 |
34993 | +#define AUFS_RDCACHE_DEF 10 /* seconds */ | |
027c5e7a | 34994 | +#define AUFS_RDCACHE_MAX 3600 /* seconds */ |
7f207e10 AM |
34995 | +#define AUFS_RDBLK_DEF 512 /* bytes */ |
34996 | +#define AUFS_RDHASH_DEF 32 | |
34997 | +#define AUFS_WKQ_NAME AUFS_NAME "d" | |
027c5e7a AM |
34998 | +#define AUFS_MFS_DEF_SEC 30 /* seconds */ |
34999 | +#define AUFS_MFS_MAX_SEC 3600 /* seconds */ | |
076b876e | 35000 | +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */ |
86dc4139 | 35001 | +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */ |
7f207e10 AM |
35002 | + |
35003 | +/* pseudo-link maintenace under /proc */ | |
35004 | +#define AUFS_PLINK_MAINT_NAME "plink_maint" | |
35005 | +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME | |
35006 | +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME | |
35007 | + | |
35008 | +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */ | |
35009 | +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME | |
35010 | + | |
35011 | +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME | |
35012 | +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk" | |
35013 | +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph" | |
35014 | + | |
35015 | +/* doubly whiteouted */ | |
35016 | +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME | |
35017 | +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME | |
35018 | +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME | |
35019 | + | |
1e00d052 | 35020 | +/* branch permissions and attributes */ |
7f207e10 AM |
35021 | +#define AUFS_BRPERM_RW "rw" |
35022 | +#define AUFS_BRPERM_RO "ro" | |
35023 | +#define AUFS_BRPERM_RR "rr" | |
076b876e AM |
35024 | +#define AUFS_BRATTR_COO_REG "coo_reg" |
35025 | +#define AUFS_BRATTR_COO_ALL "coo_all" | |
35026 | +#define AUFS_BRATTR_FHSM "fhsm" | |
35027 | +#define AUFS_BRATTR_UNPIN "unpin" | |
c1595e42 JR |
35028 | +#define AUFS_BRATTR_ICEX "icex" |
35029 | +#define AUFS_BRATTR_ICEX_SEC "icexsec" | |
35030 | +#define AUFS_BRATTR_ICEX_SYS "icexsys" | |
35031 | +#define AUFS_BRATTR_ICEX_TR "icextr" | |
35032 | +#define AUFS_BRATTR_ICEX_USR "icexusr" | |
35033 | +#define AUFS_BRATTR_ICEX_OTH "icexoth" | |
1e00d052 AM |
35034 | +#define AUFS_BRRATTR_WH "wh" |
35035 | +#define AUFS_BRWATTR_NLWH "nolwh" | |
076b876e AM |
35036 | +#define AUFS_BRWATTR_MOO "moo" |
35037 | + | |
35038 | +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */ | |
35039 | +#define AuBrPerm_RO (1 << 1) /* readonly */ | |
35040 | +#define AuBrPerm_RR (1 << 2) /* natively readonly */ | |
35041 | +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR) | |
35042 | + | |
35043 | +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */ | |
35044 | +#define AuBrAttr_COO_ALL (1 << 4) | |
35045 | +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL) | |
35046 | + | |
35047 | +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */ | |
35048 | +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of | |
c1595e42 JR |
35049 | + branch. meaningless since |
35050 | + linux-3.18-rc1 */ | |
35051 | + | |
35052 | +/* ignore error in copying XATTR */ | |
35053 | +#define AuBrAttr_ICEX_SEC (1 << 7) | |
35054 | +#define AuBrAttr_ICEX_SYS (1 << 8) | |
35055 | +#define AuBrAttr_ICEX_TR (1 << 9) | |
35056 | +#define AuBrAttr_ICEX_USR (1 << 10) | |
35057 | +#define AuBrAttr_ICEX_OTH (1 << 11) | |
35058 | +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \ | |
35059 | + | AuBrAttr_ICEX_SYS \ | |
35060 | + | AuBrAttr_ICEX_TR \ | |
35061 | + | AuBrAttr_ICEX_USR \ | |
35062 | + | AuBrAttr_ICEX_OTH) | |
35063 | + | |
35064 | +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */ | |
076b876e AM |
35065 | +#define AuBrRAttr_Mask AuBrRAttr_WH |
35066 | + | |
c1595e42 JR |
35067 | +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */ |
35068 | +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */ | |
076b876e AM |
35069 | +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO) |
35070 | + | |
35071 | +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO) | |
35072 | + | |
c1595e42 | 35073 | +/* #warning test userspace */ |
076b876e AM |
35074 | +#ifdef __KERNEL__ |
35075 | +#ifndef CONFIG_AUFS_FHSM | |
35076 | +#undef AuBrAttr_FHSM | |
35077 | +#define AuBrAttr_FHSM 0 | |
35078 | +#endif | |
c1595e42 JR |
35079 | +#ifndef CONFIG_AUFS_XATTR |
35080 | +#undef AuBrAttr_ICEX | |
35081 | +#define AuBrAttr_ICEX 0 | |
35082 | +#undef AuBrAttr_ICEX_SEC | |
35083 | +#define AuBrAttr_ICEX_SEC 0 | |
35084 | +#undef AuBrAttr_ICEX_SYS | |
35085 | +#define AuBrAttr_ICEX_SYS 0 | |
35086 | +#undef AuBrAttr_ICEX_TR | |
35087 | +#define AuBrAttr_ICEX_TR 0 | |
35088 | +#undef AuBrAttr_ICEX_USR | |
35089 | +#define AuBrAttr_ICEX_USR 0 | |
35090 | +#undef AuBrAttr_ICEX_OTH | |
35091 | +#define AuBrAttr_ICEX_OTH 0 | |
35092 | +#endif | |
076b876e AM |
35093 | +#endif |
35094 | + | |
35095 | +/* the longest combination */ | |
c1595e42 JR |
35096 | +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */ |
35097 | +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \ | |
35098 | + "+" AUFS_BRATTR_COO_REG \ | |
35099 | + "+" AUFS_BRATTR_FHSM \ | |
35100 | + "+" AUFS_BRATTR_UNPIN \ | |
7e9cd9fe AM |
35101 | + "+" AUFS_BRATTR_ICEX_SEC \ |
35102 | + "+" AUFS_BRATTR_ICEX_SYS \ | |
35103 | + "+" AUFS_BRATTR_ICEX_USR \ | |
35104 | + "+" AUFS_BRATTR_ICEX_OTH \ | |
076b876e AM |
35105 | + "+" AUFS_BRWATTR_NLWH) |
35106 | + | |
35107 | +typedef struct { | |
35108 | + char a[AuBrPermStrSz]; | |
35109 | +} au_br_perm_str_t; | |
35110 | + | |
35111 | +static inline int au_br_writable(int brperm) | |
35112 | +{ | |
35113 | + return brperm & AuBrPerm_RW; | |
35114 | +} | |
35115 | + | |
35116 | +static inline int au_br_whable(int brperm) | |
35117 | +{ | |
35118 | + return brperm & (AuBrPerm_RW | AuBrRAttr_WH); | |
35119 | +} | |
35120 | + | |
35121 | +static inline int au_br_wh_linkable(int brperm) | |
35122 | +{ | |
35123 | + return !(brperm & AuBrWAttr_NoLinkWH); | |
35124 | +} | |
35125 | + | |
35126 | +static inline int au_br_cmoo(int brperm) | |
35127 | +{ | |
35128 | + return brperm & AuBrAttr_CMOO_Mask; | |
35129 | +} | |
35130 | + | |
35131 | +static inline int au_br_fhsm(int brperm) | |
35132 | +{ | |
35133 | + return brperm & AuBrAttr_FHSM; | |
35134 | +} | |
7f207e10 AM |
35135 | + |
35136 | +/* ---------------------------------------------------------------------- */ | |
35137 | + | |
35138 | +/* ioctl */ | |
35139 | +enum { | |
35140 | + /* readdir in userspace */ | |
35141 | + AuCtl_RDU, | |
35142 | + AuCtl_RDU_INO, | |
35143 | + | |
076b876e AM |
35144 | + AuCtl_WBR_FD, /* pathconf wrapper */ |
35145 | + AuCtl_IBUSY, /* busy inode */ | |
35146 | + AuCtl_MVDOWN, /* move-down */ | |
35147 | + AuCtl_BR, /* info about branches */ | |
35148 | + AuCtl_FHSM_FD /* connection for fhsm */ | |
7f207e10 AM |
35149 | +}; |
35150 | + | |
35151 | +/* borrowed from linux/include/linux/kernel.h */ | |
35152 | +#ifndef ALIGN | |
35153 | +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) | |
35154 | +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | |
35155 | +#endif | |
35156 | + | |
35157 | +/* borrowed from linux/include/linux/compiler-gcc3.h */ | |
35158 | +#ifndef __aligned | |
35159 | +#define __aligned(x) __attribute__((aligned(x))) | |
53392da6 AM |
35160 | +#endif |
35161 | + | |
35162 | +#ifdef __KERNEL__ | |
35163 | +#ifndef __packed | |
7f207e10 AM |
35164 | +#define __packed __attribute__((packed)) |
35165 | +#endif | |
53392da6 | 35166 | +#endif |
7f207e10 AM |
35167 | + |
35168 | +struct au_rdu_cookie { | |
9dbd164d AM |
35169 | + uint64_t h_pos; |
35170 | + int16_t bindex; | |
35171 | + uint8_t flags; | |
35172 | + uint8_t pad; | |
35173 | + uint32_t generation; | |
7f207e10 AM |
35174 | +} __aligned(8); |
35175 | + | |
35176 | +struct au_rdu_ent { | |
9dbd164d AM |
35177 | + uint64_t ino; |
35178 | + int16_t bindex; | |
35179 | + uint8_t type; | |
35180 | + uint8_t nlen; | |
35181 | + uint8_t wh; | |
7f207e10 AM |
35182 | + char name[0]; |
35183 | +} __aligned(8); | |
35184 | + | |
35185 | +static inline int au_rdu_len(int nlen) | |
35186 | +{ | |
35187 | + /* include the terminating NULL */ | |
35188 | + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1, | |
9dbd164d | 35189 | + sizeof(uint64_t)); |
7f207e10 AM |
35190 | +} |
35191 | + | |
35192 | +union au_rdu_ent_ul { | |
35193 | + struct au_rdu_ent __user *e; | |
9dbd164d | 35194 | + uint64_t ul; |
7f207e10 AM |
35195 | +}; |
35196 | + | |
35197 | +enum { | |
35198 | + AufsCtlRduV_SZ, | |
35199 | + AufsCtlRduV_End | |
35200 | +}; | |
35201 | + | |
35202 | +struct aufs_rdu { | |
35203 | + /* input */ | |
35204 | + union { | |
9dbd164d AM |
35205 | + uint64_t sz; /* AuCtl_RDU */ |
35206 | + uint64_t nent; /* AuCtl_RDU_INO */ | |
7f207e10 AM |
35207 | + }; |
35208 | + union au_rdu_ent_ul ent; | |
9dbd164d | 35209 | + uint16_t verify[AufsCtlRduV_End]; |
7f207e10 AM |
35210 | + |
35211 | + /* input/output */ | |
9dbd164d | 35212 | + uint32_t blk; |
7f207e10 AM |
35213 | + |
35214 | + /* output */ | |
35215 | + union au_rdu_ent_ul tail; | |
35216 | + /* number of entries which were added in a single call */ | |
9dbd164d AM |
35217 | + uint64_t rent; |
35218 | + uint8_t full; | |
35219 | + uint8_t shwh; | |
7f207e10 AM |
35220 | + |
35221 | + struct au_rdu_cookie cookie; | |
35222 | +} __aligned(8); | |
35223 | + | |
1e00d052 AM |
35224 | +/* ---------------------------------------------------------------------- */ |
35225 | + | |
35226 | +struct aufs_wbr_fd { | |
9dbd164d AM |
35227 | + uint32_t oflags; |
35228 | + int16_t brid; | |
1e00d052 AM |
35229 | +} __aligned(8); |
35230 | + | |
35231 | +/* ---------------------------------------------------------------------- */ | |
35232 | + | |
027c5e7a | 35233 | +struct aufs_ibusy { |
9dbd164d AM |
35234 | + uint64_t ino, h_ino; |
35235 | + int16_t bindex; | |
027c5e7a AM |
35236 | +} __aligned(8); |
35237 | + | |
1e00d052 AM |
35238 | +/* ---------------------------------------------------------------------- */ |
35239 | + | |
392086de AM |
35240 | +/* error code for move-down */ |
35241 | +/* the actual message strings are implemented in aufs-util.git */ | |
35242 | +enum { | |
35243 | + EAU_MVDOWN_OPAQUE = 1, | |
35244 | + EAU_MVDOWN_WHITEOUT, | |
35245 | + EAU_MVDOWN_UPPER, | |
35246 | + EAU_MVDOWN_BOTTOM, | |
35247 | + EAU_MVDOWN_NOUPPER, | |
35248 | + EAU_MVDOWN_NOLOWERBR, | |
35249 | + EAU_Last | |
35250 | +}; | |
35251 | + | |
c2b27bf2 | 35252 | +/* flags for move-down */ |
392086de AM |
35253 | +#define AUFS_MVDOWN_DMSG 1 |
35254 | +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */ | |
35255 | +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */ | |
35256 | +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */ | |
35257 | +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */ | |
35258 | +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */ | |
35259 | +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */ | |
35260 | +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */ | |
35261 | +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */ | |
076b876e AM |
35262 | +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */ |
35263 | +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */ | |
35264 | +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */ | |
35265 | +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */ | |
c2b27bf2 | 35266 | + |
076b876e | 35267 | +/* index for move-down */ |
392086de AM |
35268 | +enum { |
35269 | + AUFS_MVDOWN_UPPER, | |
35270 | + AUFS_MVDOWN_LOWER, | |
35271 | + AUFS_MVDOWN_NARRAY | |
35272 | +}; | |
35273 | + | |
076b876e AM |
35274 | +/* |
35275 | + * additional info of move-down | |
35276 | + * number of free blocks and inodes. | |
35277 | + * subset of struct kstatfs, but smaller and always 64bit. | |
35278 | + */ | |
35279 | +struct aufs_stfs { | |
35280 | + uint64_t f_blocks; | |
35281 | + uint64_t f_bavail; | |
35282 | + uint64_t f_files; | |
35283 | + uint64_t f_ffree; | |
35284 | +}; | |
35285 | + | |
35286 | +struct aufs_stbr { | |
35287 | + int16_t brid; /* optional input */ | |
35288 | + int16_t bindex; /* output */ | |
35289 | + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */ | |
35290 | +} __aligned(8); | |
35291 | + | |
c2b27bf2 | 35292 | +struct aufs_mvdown { |
076b876e AM |
35293 | + uint32_t flags; /* input/output */ |
35294 | + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */ | |
35295 | + int8_t au_errno; /* output */ | |
35296 | +} __aligned(8); | |
35297 | + | |
35298 | +/* ---------------------------------------------------------------------- */ | |
35299 | + | |
35300 | +union aufs_brinfo { | |
35301 | + /* PATH_MAX may differ between kernel-space and user-space */ | |
35302 | + char _spacer[4096]; | |
392086de | 35303 | + struct { |
076b876e AM |
35304 | + int16_t id; |
35305 | + int perm; | |
35306 | + char path[0]; | |
35307 | + }; | |
c2b27bf2 AM |
35308 | +} __aligned(8); |
35309 | + | |
35310 | +/* ---------------------------------------------------------------------- */ | |
35311 | + | |
7f207e10 AM |
35312 | +#define AuCtlType 'A' |
35313 | +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu) | |
35314 | +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu) | |
1e00d052 AM |
35315 | +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \ |
35316 | + struct aufs_wbr_fd) | |
027c5e7a | 35317 | +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy) |
392086de AM |
35318 | +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \ |
35319 | + struct aufs_mvdown) | |
076b876e AM |
35320 | +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo) |
35321 | +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int) | |
7f207e10 AM |
35322 | + |
35323 | +#endif /* __AUFS_TYPE_H__ */ | |
5527c038 JR |
35324 | aufs4.x-rcN loopback patch |
35325 | ||
35326 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c | |
c2c0f25c | 35327 | index 23103ad..5c3263f 100644 |
5527c038 JR |
35328 | --- a/drivers/block/loop.c |
35329 | +++ b/drivers/block/loop.c | |
c2c0f25c | 35330 | @@ -417,7 +417,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) |
5527c038 JR |
35331 | } |
35332 | ||
35333 | struct switch_request { | |
35334 | - struct file *file; | |
35335 | + struct file *file, *virt_file; | |
35336 | struct completion wait; | |
35337 | }; | |
35338 | ||
c2c0f25c | 35339 | @@ -437,6 +437,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) |
5527c038 JR |
35340 | mapping = file->f_mapping; |
35341 | mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); | |
35342 | lo->lo_backing_file = file; | |
35343 | + lo->lo_backing_virt_file = p->virt_file; | |
35344 | lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ? | |
35345 | mapping->host->i_bdev->bd_block_size : PAGE_SIZE; | |
35346 | lo->old_gfp_mask = mapping_gfp_mask(mapping); | |
c2c0f25c | 35347 | @@ -448,11 +449,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) |
5527c038 JR |
35348 | * First it needs to flush existing IO, it does this by sending a magic |
35349 | * BIO down the pipe. The completion of this BIO does the actual switch. | |
35350 | */ | |
35351 | -static int loop_switch(struct loop_device *lo, struct file *file) | |
35352 | +static int loop_switch(struct loop_device *lo, struct file *file, | |
35353 | + struct file *virt_file) | |
35354 | { | |
35355 | struct switch_request w; | |
35356 | ||
35357 | w.file = file; | |
35358 | + w.virt_file = virt_file; | |
35359 | ||
35360 | /* freeze queue and wait for completion of scheduled requests */ | |
35361 | blk_mq_freeze_queue(lo->lo_queue); | |
c2c0f25c | 35362 | @@ -471,7 +474,16 @@ static int loop_switch(struct loop_device *lo, struct file *file) |
5527c038 JR |
35363 | */ |
35364 | static int loop_flush(struct loop_device *lo) | |
35365 | { | |
35366 | - return loop_switch(lo, NULL); | |
35367 | + return loop_switch(lo, NULL, NULL); | |
35368 | +} | |
35369 | + | |
35370 | +static struct file *loop_real_file(struct file *file) | |
35371 | +{ | |
35372 | + struct file *f = NULL; | |
35373 | + | |
35374 | + if (file->f_path.dentry->d_sb->s_op->real_loop) | |
35375 | + f = file->f_path.dentry->d_sb->s_op->real_loop(file); | |
35376 | + return f; | |
35377 | } | |
35378 | ||
c2c0f25c AM |
35379 | static void loop_reread_partitions(struct loop_device *lo, |
35380 | @@ -508,6 +520,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, | |
5527c038 JR |
35381 | unsigned int arg) |
35382 | { | |
35383 | struct file *file, *old_file; | |
35384 | + struct file *f, *virt_file = NULL, *old_virt_file; | |
35385 | struct inode *inode; | |
35386 | int error; | |
35387 | ||
c2c0f25c | 35388 | @@ -524,9 +537,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
35389 | file = fget(arg); |
35390 | if (!file) | |
35391 | goto out; | |
35392 | + f = loop_real_file(file); | |
35393 | + if (f) { | |
35394 | + virt_file = file; | |
35395 | + file = f; | |
35396 | + get_file(file); | |
35397 | + } | |
35398 | ||
35399 | inode = file->f_mapping->host; | |
35400 | old_file = lo->lo_backing_file; | |
35401 | + old_virt_file = lo->lo_backing_virt_file; | |
35402 | ||
35403 | error = -EINVAL; | |
35404 | ||
c2c0f25c | 35405 | @@ -538,17 +558,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
35406 | goto out_putf; |
35407 | ||
35408 | /* and ... switch */ | |
35409 | - error = loop_switch(lo, file); | |
35410 | + error = loop_switch(lo, file, virt_file); | |
35411 | if (error) | |
35412 | goto out_putf; | |
35413 | ||
35414 | fput(old_file); | |
35415 | + if (old_virt_file) | |
35416 | + fput(old_virt_file); | |
35417 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) | |
c2c0f25c | 35418 | loop_reread_partitions(lo, bdev); |
5527c038 JR |
35419 | return 0; |
35420 | ||
35421 | out_putf: | |
35422 | fput(file); | |
35423 | + if (virt_file) | |
35424 | + fput(virt_file); | |
35425 | out: | |
35426 | return error; | |
35427 | } | |
c2c0f25c | 35428 | @@ -709,7 +733,7 @@ static void loop_config_discard(struct loop_device *lo) |
5527c038 JR |
35429 | static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
35430 | struct block_device *bdev, unsigned int arg) | |
35431 | { | |
35432 | - struct file *file, *f; | |
35433 | + struct file *file, *f, *virt_file = NULL; | |
35434 | struct inode *inode; | |
35435 | struct address_space *mapping; | |
35436 | unsigned lo_blocksize; | |
c2c0f25c | 35437 | @@ -724,6 +748,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
35438 | file = fget(arg); |
35439 | if (!file) | |
35440 | goto out; | |
35441 | + f = loop_real_file(file); | |
35442 | + if (f) { | |
35443 | + virt_file = file; | |
35444 | + file = f; | |
35445 | + get_file(file); | |
35446 | + } | |
35447 | ||
35448 | error = -EBUSY; | |
35449 | if (lo->lo_state != Lo_unbound) | |
c2c0f25c | 35450 | @@ -778,6 +808,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
35451 | lo->lo_device = bdev; |
35452 | lo->lo_flags = lo_flags; | |
35453 | lo->lo_backing_file = file; | |
35454 | + lo->lo_backing_virt_file = virt_file; | |
35455 | lo->transfer = NULL; | |
35456 | lo->ioctl = NULL; | |
35457 | lo->lo_sizelimit = 0; | |
c2c0f25c | 35458 | @@ -809,6 +840,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
35459 | |
35460 | out_putf: | |
35461 | fput(file); | |
35462 | + if (virt_file) | |
35463 | + fput(virt_file); | |
35464 | out: | |
35465 | /* This is safe: open() is still holding a reference. */ | |
35466 | module_put(THIS_MODULE); | |
c2c0f25c | 35467 | @@ -855,6 +888,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, |
5527c038 JR |
35468 | static int loop_clr_fd(struct loop_device *lo) |
35469 | { | |
35470 | struct file *filp = lo->lo_backing_file; | |
35471 | + struct file *virt_filp = lo->lo_backing_virt_file; | |
35472 | gfp_t gfp = lo->old_gfp_mask; | |
35473 | struct block_device *bdev = lo->lo_device; | |
35474 | ||
c2c0f25c | 35475 | @@ -886,6 +920,7 @@ static int loop_clr_fd(struct loop_device *lo) |
5527c038 JR |
35476 | spin_lock_irq(&lo->lo_lock); |
35477 | lo->lo_state = Lo_rundown; | |
35478 | lo->lo_backing_file = NULL; | |
35479 | + lo->lo_backing_virt_file = NULL; | |
35480 | spin_unlock_irq(&lo->lo_lock); | |
35481 | ||
35482 | loop_release_xfer(lo); | |
c2c0f25c | 35483 | @@ -931,6 +966,8 @@ static int loop_clr_fd(struct loop_device *lo) |
5527c038 JR |
35484 | * bd_mutex which is usually taken before lo_ctl_mutex. |
35485 | */ | |
35486 | fput(filp); | |
35487 | + if (virt_filp) | |
35488 | + fput(virt_filp); | |
35489 | return 0; | |
35490 | } | |
35491 | ||
35492 | diff --git a/drivers/block/loop.h b/drivers/block/loop.h | |
c2c0f25c | 35493 | index 25e8997..93b6fce 100644 |
5527c038 JR |
35494 | --- a/drivers/block/loop.h |
35495 | +++ b/drivers/block/loop.h | |
35496 | @@ -46,7 +46,7 @@ struct loop_device { | |
35497 | int (*ioctl)(struct loop_device *, int cmd, | |
35498 | unsigned long arg); | |
35499 | ||
35500 | - struct file * lo_backing_file; | |
35501 | + struct file * lo_backing_file, *lo_backing_virt_file; | |
35502 | struct block_device *lo_device; | |
35503 | unsigned lo_blocksize; | |
35504 | void *key_data; | |
35505 | diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c | |
35506 | index 91c2ce7..d4ee5a7 100644 | |
35507 | --- a/fs/aufs/f_op.c | |
35508 | +++ b/fs/aufs/f_op.c | |
35509 | @@ -389,7 +389,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, | |
35510 | if (IS_ERR(h_file)) | |
35511 | goto out; | |
35512 | ||
35513 | - if (au_test_loopback_kthread()) { | |
35514 | + if (0 && au_test_loopback_kthread()) { | |
35515 | au_warn_loopback(h_file->f_path.dentry->d_sb); | |
35516 | if (file->f_mapping != h_file->f_mapping) { | |
35517 | file->f_mapping = h_file->f_mapping; | |
35518 | diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c | |
35519 | index 69f7e96..7941063 100644 | |
35520 | --- a/fs/aufs/loop.c | |
35521 | +++ b/fs/aufs/loop.c | |
35522 | @@ -130,3 +130,19 @@ void au_loopback_fin(void) | |
35523 | symbol_put(loop_backing_file); | |
35524 | kfree(au_warn_loopback_array); | |
35525 | } | |
35526 | + | |
35527 | +/* ---------------------------------------------------------------------- */ | |
35528 | + | |
35529 | +/* support the loopback block device insude aufs */ | |
35530 | + | |
35531 | +struct file *aufs_real_loop(struct file *file) | |
35532 | +{ | |
35533 | + struct file *f; | |
35534 | + | |
35535 | + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb)); | |
35536 | + fi_read_lock(file); | |
35537 | + f = au_hf_top(file); | |
35538 | + fi_read_unlock(file); | |
35539 | + AuDebugOn(!f); | |
35540 | + return f; | |
35541 | +} | |
35542 | diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h | |
35543 | index 6d9864d..3322557 100644 | |
35544 | --- a/fs/aufs/loop.h | |
35545 | +++ b/fs/aufs/loop.h | |
35546 | @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb); | |
35547 | ||
35548 | int au_loopback_init(void); | |
35549 | void au_loopback_fin(void); | |
35550 | + | |
35551 | +struct file *aufs_real_loop(struct file *file); | |
35552 | #else | |
35553 | +AuStub(struct file *, loop_backing_file, return NULL) | |
35554 | + | |
35555 | AuStubInt0(au_test_loopback_overlap, struct super_block *sb, | |
35556 | struct dentry *h_adding) | |
35557 | AuStubInt0(au_test_loopback_kthread, void) | |
35558 | @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb) | |
35559 | ||
35560 | AuStubInt0(au_loopback_init, void) | |
35561 | AuStubVoid(au_loopback_fin, void) | |
35562 | + | |
35563 | +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file) | |
35564 | #endif /* BLK_DEV_LOOP */ | |
35565 | ||
35566 | #endif /* __KERNEL__ */ | |
35567 | diff --git a/fs/aufs/super.c b/fs/aufs/super.c | |
35568 | index ee5780d..da35759 100644 | |
35569 | --- a/fs/aufs/super.c | |
35570 | +++ b/fs/aufs/super.c | |
35571 | @@ -807,7 +807,10 @@ static const struct super_operations aufs_sop = { | |
35572 | .statfs = aufs_statfs, | |
35573 | .put_super = aufs_put_super, | |
35574 | .sync_fs = aufs_sync_fs, | |
35575 | - .remount_fs = aufs_remount_fs | |
35576 | + .remount_fs = aufs_remount_fs, | |
35577 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
35578 | + .real_loop = aufs_real_loop | |
35579 | +#endif | |
35580 | }; | |
35581 | ||
35582 | /* ---------------------------------------------------------------------- */ | |
35583 | diff --git a/include/linux/fs.h b/include/linux/fs.h | |
c2c0f25c | 35584 | index 86080ea..5f8e0f2 100644 |
5527c038 JR |
35585 | --- a/include/linux/fs.h |
35586 | +++ b/include/linux/fs.h | |
c2c0f25c | 35587 | @@ -1708,6 +1708,10 @@ struct super_operations { |
5527c038 JR |
35588 | struct shrink_control *); |
35589 | long (*free_cached_objects)(struct super_block *, | |
35590 | struct shrink_control *); | |
35591 | +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE) | |
35592 | + /* and aufs */ | |
35593 | + struct file *(*real_loop)(struct file *); | |
35594 | +#endif | |
35595 | }; | |
35596 | ||
35597 | /* |