]>
Commit | Line | Data |
---|---|---|
c1595e42 | 1 | aufs3.18.1+ kbuild patch |
7f207e10 AM |
2 | |
3 | diff --git a/fs/Kconfig b/fs/Kconfig | |
c1595e42 | 4 | index 664991a..1481093 100644 |
7f207e10 AM |
5 | --- a/fs/Kconfig |
6 | +++ b/fs/Kconfig | |
c1595e42 | 7 | @@ -210,6 +210,7 @@ source "fs/ufs/Kconfig" |
7f207e10 | 8 | source "fs/exofs/Kconfig" |
1716fcea | 9 | source "fs/f2fs/Kconfig" |
c06a8ce3 | 10 | source "fs/efivarfs/Kconfig" |
7f207e10 AM |
11 | +source "fs/aufs/Kconfig" |
12 | ||
13 | endif # MISC_FILESYSTEMS | |
14 | ||
15 | diff --git a/fs/Makefile b/fs/Makefile | |
c1595e42 | 16 | index da0bbb4..c8bc724 100644 |
7f207e10 AM |
17 | --- a/fs/Makefile |
18 | +++ b/fs/Makefile | |
c1595e42 | 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 |
c1595e42 | 25 | index 8523f9b..11f8f74 100644 |
c06a8ce3 AM |
26 | --- a/include/uapi/linux/Kbuild |
27 | +++ b/include/uapi/linux/Kbuild | |
28 | @@ -56,6 +56,7 @@ header-y += atmppp.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 |
c1595e42 | 36 | aufs3.18.1+ base patch |
7f207e10 | 37 | |
c1595e42 JR |
38 | diff --git a/MAINTAINERS b/MAINTAINERS |
39 | index c721042..83801d0 100644 | |
40 | --- a/MAINTAINERS | |
41 | +++ b/MAINTAINERS | |
42 | @@ -1795,6 +1795,20 @@ F: include/linux/audit.h | |
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 | |
51 | +T: git://git.code.sf.net/p/aufs/aufs3-linux | |
52 | +T: git://github.com/sfjro/aufs3-linux.git | |
53 | +S: Supported | |
54 | +F: Documentation/filesystems/aufs/ | |
55 | +F: Documentation/ABI/testing/debugfs-aufs | |
56 | +F: Documentation/ABI/testing/sysfs-aufs | |
57 | +F: fs/aufs/ | |
58 | +F: include/uapi/linux/aufs_type.h | |
59 | + | |
60 | AUXILIARY DISPLAY DRIVERS | |
61 | M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> | |
62 | W: http://miguelojeda.es/auxdisplay.htm | |
392086de | 63 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c |
076b876e | 64 | index 6cb1beb..30efd68 100644 |
392086de AM |
65 | --- a/drivers/block/loop.c |
66 | +++ b/drivers/block/loop.c | |
fb47a38f | 67 | @@ -692,6 +692,24 @@ static inline int is_loop_device(struct file *file) |
392086de AM |
68 | return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR; |
69 | } | |
70 | ||
71 | +/* | |
72 | + * for AUFS | |
73 | + * no get/put for file. | |
74 | + */ | |
75 | +struct file *loop_backing_file(struct super_block *sb) | |
76 | +{ | |
77 | + struct file *ret; | |
78 | + struct loop_device *l; | |
79 | + | |
80 | + ret = NULL; | |
81 | + if (MAJOR(sb->s_dev) == LOOP_MAJOR) { | |
82 | + l = sb->s_bdev->bd_disk->private_data; | |
83 | + ret = l->lo_backing_file; | |
84 | + } | |
85 | + return ret; | |
86 | +} | |
87 | +EXPORT_SYMBOL(loop_backing_file); | |
88 | + | |
89 | /* loop sysfs attributes */ | |
90 | ||
91 | static ssize_t loop_attr_show(struct device *dev, char *page, | |
c1595e42 JR |
92 | diff --git a/fs/dcache.c b/fs/dcache.c |
93 | index 71acf8d..da7342e 100644 | |
94 | --- a/fs/dcache.c | |
95 | +++ b/fs/dcache.c | |
96 | @@ -1019,7 +1019,7 @@ enum d_walk_ret { | |
97 | * | |
98 | * The @enter() and @finish() callbacks are called with d_lock held. | |
99 | */ | |
100 | -static void d_walk(struct dentry *parent, void *data, | |
101 | +void d_walk(struct dentry *parent, void *data, | |
102 | enum d_walk_ret (*enter)(void *, struct dentry *), | |
103 | void (*finish)(void *)) | |
104 | { | |
0c3ec466 | 105 | diff --git a/fs/inode.c b/fs/inode.c |
c1595e42 | 106 | index 26753ba..df21e66 100644 |
0c3ec466 AM |
107 | --- a/fs/inode.c |
108 | +++ b/fs/inode.c | |
c1595e42 | 109 | @@ -1497,7 +1497,7 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode, |
0c3ec466 AM |
110 | * This does the actual work of updating an inodes time or version. Must have |
111 | * had called mnt_want_write() before calling this. | |
112 | */ | |
113 | -static int update_time(struct inode *inode, struct timespec *time, int flags) | |
114 | +int update_time(struct inode *inode, struct timespec *time, int flags) | |
115 | { | |
116 | if (inode->i_op->update_time) | |
117 | return inode->i_op->update_time(inode, time, flags); | |
7f207e10 | 118 | diff --git a/fs/splice.c b/fs/splice.c |
c1595e42 | 119 | index 75c6058..619359a 100644 |
7f207e10 AM |
120 | --- a/fs/splice.c |
121 | +++ b/fs/splice.c | |
076b876e | 122 | @@ -1114,8 +1114,8 @@ EXPORT_SYMBOL(generic_splice_sendpage); |
7f207e10 AM |
123 | /* |
124 | * Attempt to initiate a splice from pipe to file. | |
125 | */ | |
126 | -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
127 | - loff_t *ppos, size_t len, unsigned int flags) | |
128 | +long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
129 | + loff_t *ppos, size_t len, unsigned int flags) | |
130 | { | |
131 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, | |
132 | loff_t *, size_t, unsigned int); | |
076b876e | 133 | @@ -1131,9 +1131,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
7f207e10 AM |
134 | /* |
135 | * Attempt to initiate a splice from a file to a pipe. | |
136 | */ | |
137 | -static long do_splice_to(struct file *in, loff_t *ppos, | |
138 | - struct pipe_inode_info *pipe, size_t len, | |
139 | - unsigned int flags) | |
140 | +long do_splice_to(struct file *in, loff_t *ppos, | |
141 | + struct pipe_inode_info *pipe, size_t len, | |
142 | + unsigned int flags) | |
143 | { | |
144 | ssize_t (*splice_read)(struct file *, loff_t *, | |
145 | struct pipe_inode_info *, size_t, unsigned int); | |
0c3ec466 | 146 | diff --git a/include/linux/fs.h b/include/linux/fs.h |
c1595e42 | 147 | index 9ab779e..aabcbba 100644 |
0c3ec466 AM |
148 | --- a/include/linux/fs.h |
149 | +++ b/include/linux/fs.h | |
c1595e42 | 150 | @@ -2664,6 +2664,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *); |
0c3ec466 AM |
151 | extern int inode_newsize_ok(const struct inode *, loff_t offset); |
152 | extern void setattr_copy(struct inode *inode, const struct iattr *attr); | |
153 | ||
154 | +extern int update_time(struct inode *, struct timespec *, int); | |
155 | extern int file_update_time(struct file *file); | |
156 | ||
157 | extern int generic_show_options(struct seq_file *m, struct dentry *root); | |
1e00d052 | 158 | diff --git a/include/linux/splice.h b/include/linux/splice.h |
076b876e | 159 | index da2751d..2e0fca6 100644 |
1e00d052 AM |
160 | --- a/include/linux/splice.h |
161 | +++ b/include/linux/splice.h | |
076b876e | 162 | @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *); |
4b3da204 AM |
163 | extern void spd_release_page(struct splice_pipe_desc *, unsigned int); |
164 | ||
165 | extern const struct pipe_buf_operations page_cache_pipe_buf_ops; | |
1e00d052 AM |
166 | + |
167 | +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
168 | + loff_t *ppos, size_t len, unsigned int flags); | |
169 | +extern long do_splice_to(struct file *in, loff_t *ppos, | |
170 | + struct pipe_inode_info *pipe, size_t len, | |
171 | + unsigned int flags); | |
172 | #endif | |
c1595e42 | 173 | aufs3.18.1+ mmap patch |
fb47a38f JR |
174 | |
175 | diff --git a/fs/buffer.c b/fs/buffer.c | |
c1595e42 | 176 | index 20805db..363569f 100644 |
fb47a38f JR |
177 | --- a/fs/buffer.c |
178 | +++ b/fs/buffer.c | |
c1595e42 | 179 | @@ -2450,7 +2450,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, |
fb47a38f JR |
180 | * Update file times before taking page lock. We may end up failing the |
181 | * fault so this update may be superfluous but who really cares... | |
182 | */ | |
183 | - file_update_time(vma->vm_file); | |
184 | + vma_file_update_time(vma); | |
185 | ||
186 | ret = __block_page_mkwrite(vma, vmf, get_block); | |
187 | sb_end_pagefault(sb); | |
c1595e42 JR |
188 | diff --git a/fs/proc/base.c b/fs/proc/base.c |
189 | index 772efa4..2c944de 100644 | |
190 | --- a/fs/proc/base.c | |
191 | +++ b/fs/proc/base.c | |
192 | @@ -1735,7 +1735,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path) | |
193 | down_read(&mm->mmap_sem); | |
194 | vma = find_exact_vma(mm, vm_start, vm_end); | |
195 | if (vma && vma->vm_file) { | |
196 | - *path = vma->vm_file->f_path; | |
197 | + *path = vma_pr_or_file(vma)->f_path; | |
198 | path_get(path); | |
199 | rc = 0; | |
200 | } | |
fb47a38f | 201 | diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c |
076b876e | 202 | index d4a3574..1397181 100644 |
fb47a38f JR |
203 | --- a/fs/proc/nommu.c |
204 | +++ b/fs/proc/nommu.c | |
076b876e | 205 | @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region) |
fb47a38f JR |
206 | file = region->vm_file; |
207 | ||
208 | if (file) { | |
209 | - struct inode *inode = file_inode(region->vm_file); | |
210 | + struct inode *inode; | |
076b876e | 211 | + |
fb47a38f JR |
212 | + file = vmr_pr_or_file(region); |
213 | + inode = file_inode(file); | |
214 | dev = inode->i_sb->s_dev; | |
215 | ino = inode->i_ino; | |
216 | } | |
217 | diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c | |
c1595e42 | 218 | index 4e0388c..fc429e7 100644 |
fb47a38f JR |
219 | --- a/fs/proc/task_mmu.c |
220 | +++ b/fs/proc/task_mmu.c | |
c1595e42 | 221 | @@ -276,7 +276,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) |
fb47a38f JR |
222 | const char *name = NULL; |
223 | ||
224 | if (file) { | |
225 | - struct inode *inode = file_inode(vma->vm_file); | |
226 | + struct inode *inode; | |
076b876e | 227 | + |
fb47a38f JR |
228 | + file = vma_pr_or_file(vma); |
229 | + inode = file_inode(file); | |
230 | dev = inode->i_sb->s_dev; | |
231 | ino = inode->i_ino; | |
232 | pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; | |
c1595e42 | 233 | @@ -1440,7 +1443,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid) |
076b876e AM |
234 | struct proc_maps_private *proc_priv = &numa_priv->proc_maps; |
235 | struct vm_area_struct *vma = v; | |
236 | struct numa_maps *md = &numa_priv->md; | |
237 | - struct file *file = vma->vm_file; | |
238 | + struct file *file = vma_pr_or_file(vma); | |
076b876e AM |
239 | struct mm_struct *mm = vma->vm_mm; |
240 | struct mm_walk walk = {}; | |
e26ee53e | 241 | struct mempolicy *pol; |
fb47a38f | 242 | diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c |
c1595e42 | 243 | index 599ec2e..de6cd6e 100644 |
fb47a38f JR |
244 | --- a/fs/proc/task_nommu.c |
245 | +++ b/fs/proc/task_nommu.c | |
c1595e42 | 246 | @@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma, |
fb47a38f JR |
247 | file = vma->vm_file; |
248 | ||
249 | if (file) { | |
250 | - struct inode *inode = file_inode(vma->vm_file); | |
251 | + struct inode *inode; | |
076b876e | 252 | + |
fb47a38f JR |
253 | + file = vma_pr_or_file(file); |
254 | + inode = file_inode(file); | |
255 | dev = inode->i_sb->s_dev; | |
256 | ino = inode->i_ino; | |
257 | pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT; | |
258 | diff --git a/include/linux/mm.h b/include/linux/mm.h | |
c1595e42 | 259 | index b464611..8027d51 100644 |
fb47a38f JR |
260 | --- a/include/linux/mm.h |
261 | +++ b/include/linux/mm.h | |
c1595e42 | 262 | @@ -1206,6 +1206,28 @@ static inline int fixup_user_fault(struct task_struct *tsk, |
fb47a38f JR |
263 | } |
264 | #endif | |
265 | ||
076b876e AM |
266 | +#ifdef CONFIG_MMU |
267 | +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int); | |
268 | +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[], | |
269 | + int); | |
270 | +extern void vma_do_get_file(struct vm_area_struct *, const char[], int); | |
271 | +extern void vma_do_fput(struct vm_area_struct *, const char[], int); | |
fb47a38f | 272 | + |
fb47a38f JR |
273 | +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \ |
274 | + __LINE__) | |
275 | +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \ | |
276 | + __LINE__) | |
277 | +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__) | |
278 | +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__) | |
076b876e AM |
279 | +#else |
280 | +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int); | |
281 | +extern void vmr_do_fput(struct vm_region *, const char[], int); | |
282 | + | |
283 | +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \ | |
284 | + __LINE__) | |
285 | +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__) | |
286 | +#endif /* CONFIG_MMU */ | |
fb47a38f JR |
287 | + |
288 | extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write); | |
289 | extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, | |
290 | void *buf, int len, int write); | |
291 | diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h | |
c1595e42 | 292 | index 6e0b286..8f374ed 100644 |
fb47a38f JR |
293 | --- a/include/linux/mm_types.h |
294 | +++ b/include/linux/mm_types.h | |
38d290e6 | 295 | @@ -232,6 +232,7 @@ struct vm_region { |
fb47a38f JR |
296 | unsigned long vm_top; /* region allocated to here */ |
297 | unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */ | |
298 | struct file *vm_file; /* the backing file or NULL */ | |
299 | + struct file *vm_prfile; /* the virtual backing file or NULL */ | |
300 | ||
301 | int vm_usage; /* region usage count (access under nommu_region_sem) */ | |
302 | bool vm_icache_flushed : 1; /* true if the icache has been flushed for | |
38d290e6 | 303 | @@ -300,6 +301,7 @@ struct vm_area_struct { |
fb47a38f JR |
304 | unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE |
305 | units, *not* PAGE_CACHE_SIZE */ | |
306 | struct file * vm_file; /* File we map to (can be NULL). */ | |
307 | + struct file *vm_prfile; /* shadow of vm_file */ | |
308 | void * vm_private_data; /* was vm_pte (shared mem) */ | |
309 | ||
310 | #ifndef CONFIG_MMU | |
311 | diff --git a/kernel/fork.c b/kernel/fork.c | |
c1595e42 | 312 | index 9b7d746..9a3b8fe 100644 |
fb47a38f JR |
313 | --- a/kernel/fork.c |
314 | +++ b/kernel/fork.c | |
c1595e42 | 315 | @@ -430,7 +430,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) |
fb47a38f JR |
316 | struct inode *inode = file_inode(file); |
317 | struct address_space *mapping = file->f_mapping; | |
318 | ||
319 | - get_file(file); | |
320 | + vma_get_file(tmp); | |
321 | if (tmp->vm_flags & VM_DENYWRITE) | |
322 | atomic_dec(&inode->i_writecount); | |
323 | mutex_lock(&mapping->i_mmap_mutex); | |
076b876e | 324 | diff --git a/mm/Makefile b/mm/Makefile |
c1595e42 | 325 | index 8405eb0..e0bda2d 100644 |
076b876e AM |
326 | --- a/mm/Makefile |
327 | +++ b/mm/Makefile | |
c1595e42 | 328 | @@ -18,7 +18,7 @@ obj-y := filemap.o mempool.o oom_kill.o \ |
076b876e | 329 | mm_init.o mmu_context.o percpu.o slab_common.o \ |
c1595e42 | 330 | compaction.o vmacache.o \ |
076b876e | 331 | interval_tree.o list_lru.o workingset.o \ |
e26ee53e | 332 | - iov_iter.o debug.o $(mmu-y) |
c1595e42 | 333 | + iov_iter.o prfile.o debug.o $(mmu-y) |
076b876e AM |
334 | |
335 | obj-y += init-mm.o | |
336 | ||
fb47a38f | 337 | diff --git a/mm/filemap.c b/mm/filemap.c |
c1595e42 | 338 | index 14b4642..99bc835 100644 |
fb47a38f JR |
339 | --- a/mm/filemap.c |
340 | +++ b/mm/filemap.c | |
c1595e42 | 341 | @@ -2067,7 +2067,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) |
fb47a38f JR |
342 | int ret = VM_FAULT_LOCKED; |
343 | ||
344 | sb_start_pagefault(inode->i_sb); | |
345 | - file_update_time(vma->vm_file); | |
346 | + vma_file_update_time(vma); | |
347 | lock_page(page); | |
348 | if (page->mapping != inode->i_mapping) { | |
349 | unlock_page(page); | |
350 | diff --git a/mm/fremap.c b/mm/fremap.c | |
076b876e | 351 | index 72b8fa3..a00bbf0 100644 |
fb47a38f JR |
352 | --- a/mm/fremap.c |
353 | +++ b/mm/fremap.c | |
076b876e | 354 | @@ -224,16 +224,28 @@ get_write_lock: |
38d290e6 JR |
355 | */ |
356 | if (mapping_cap_account_dirty(mapping)) { | |
357 | unsigned long addr; | |
358 | - struct file *file = get_file(vma->vm_file); | |
359 | + struct file *file = vma->vm_file, | |
360 | + *prfile = vma->vm_prfile; | |
361 | + | |
fb47a38f JR |
362 | /* mmap_region may free vma; grab the info now */ |
363 | vm_flags = vma->vm_flags; | |
364 | ||
365 | + vma_get_file(vma); | |
366 | addr = mmap_region(file, start, size, vm_flags, pgoff); | |
38d290e6 | 367 | - fput(file); |
fb47a38f | 368 | + vma_fput(vma); |
fb47a38f JR |
369 | if (IS_ERR_VALUE(addr)) { |
370 | err = addr; | |
38d290e6 JR |
371 | } else { |
372 | BUG_ON(addr != start); | |
373 | + if (prfile) { | |
374 | + struct vm_area_struct *new_vma; | |
076b876e | 375 | + |
38d290e6 JR |
376 | + new_vma = find_vma(mm, addr); |
377 | + if (!new_vma->vm_prfile) | |
378 | + new_vma->vm_prfile = prfile; | |
379 | + if (new_vma != vma) | |
380 | + get_file(prfile); | |
381 | + } | |
382 | err = 0; | |
383 | } | |
384 | goto out_freed; | |
fb47a38f | 385 | diff --git a/mm/madvise.c b/mm/madvise.c |
c1595e42 | 386 | index 0938b30..0b66856 100644 |
fb47a38f JR |
387 | --- a/mm/madvise.c |
388 | +++ b/mm/madvise.c | |
c1595e42 | 389 | @@ -324,12 +324,12 @@ static long madvise_remove(struct vm_area_struct *vma, |
fb47a38f JR |
390 | * vma's reference to the file) can go away as soon as we drop |
391 | * mmap_sem. | |
392 | */ | |
393 | - get_file(f); | |
394 | + vma_get_file(vma); | |
395 | up_read(¤t->mm->mmap_sem); | |
03673fb0 | 396 | error = vfs_fallocate(f, |
fb47a38f JR |
397 | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, |
398 | offset, end - start); | |
399 | - fput(f); | |
400 | + vma_fput(vma); | |
401 | down_read(¤t->mm->mmap_sem); | |
402 | return error; | |
403 | } | |
404 | diff --git a/mm/memory.c b/mm/memory.c | |
c1595e42 | 405 | index d5f2ae9..0830a96 100644 |
fb47a38f JR |
406 | --- a/mm/memory.c |
407 | +++ b/mm/memory.c | |
c1595e42 | 408 | @@ -2163,7 +2163,7 @@ reuse: |
38d290e6 | 409 | set_page_dirty_balance(dirty_page); |
fb47a38f JR |
410 | /* file_update_time outside page_lock */ |
411 | if (vma->vm_file) | |
412 | - file_update_time(vma->vm_file); | |
413 | + vma_file_update_time(vma); | |
414 | } | |
415 | put_page(dirty_page); | |
416 | if (page_mkwrite) { | |
fb47a38f | 417 | diff --git a/mm/mmap.c b/mm/mmap.c |
c1595e42 | 418 | index ae91989..e3bee5c 100644 |
fb47a38f JR |
419 | --- a/mm/mmap.c |
420 | +++ b/mm/mmap.c | |
c1595e42 | 421 | @@ -277,7 +277,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma) |
fb47a38f JR |
422 | if (vma->vm_ops && vma->vm_ops->close) |
423 | vma->vm_ops->close(vma); | |
424 | if (vma->vm_file) | |
425 | - fput(vma->vm_file); | |
426 | + vma_fput(vma); | |
427 | mpol_put(vma_policy(vma)); | |
428 | kmem_cache_free(vm_area_cachep, vma); | |
429 | return next; | |
c1595e42 | 430 | @@ -895,7 +895,7 @@ again: remove_next = 1 + (end > next->vm_end); |
fb47a38f JR |
431 | if (remove_next) { |
432 | if (file) { | |
433 | uprobe_munmap(next, next->vm_start, next->vm_end); | |
434 | - fput(file); | |
435 | + vma_fput(vma); | |
436 | } | |
437 | if (next->anon_vma) | |
438 | anon_vma_merge(vma, next); | |
c1595e42 | 439 | @@ -1680,8 +1680,8 @@ out: |
35939ee7 JR |
440 | return addr; |
441 | ||
fb47a38f | 442 | unmap_and_free_vma: |
fb47a38f JR |
443 | + vma_fput(vma); |
444 | vma->vm_file = NULL; | |
445 | - fput(file); | |
446 | ||
447 | /* Undo any partial mapping done by a device driver. */ | |
448 | unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); | |
c1595e42 | 449 | @@ -2477,7 +2477,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
450 | goto out_free_mpol; |
451 | ||
452 | if (new->vm_file) | |
453 | - get_file(new->vm_file); | |
454 | + vma_get_file(new); | |
455 | ||
456 | if (new->vm_ops && new->vm_ops->open) | |
457 | new->vm_ops->open(new); | |
c1595e42 | 458 | @@ -2496,7 +2496,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
459 | if (new->vm_ops && new->vm_ops->close) |
460 | new->vm_ops->close(new); | |
461 | if (new->vm_file) | |
462 | - fput(new->vm_file); | |
463 | + vma_fput(new); | |
464 | unlink_anon_vmas(new); | |
465 | out_free_mpol: | |
466 | mpol_put(vma_policy(new)); | |
c1595e42 | 467 | @@ -2886,7 +2886,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, |
fb47a38f JR |
468 | if (anon_vma_clone(new_vma, vma)) |
469 | goto out_free_mempol; | |
470 | if (new_vma->vm_file) | |
471 | - get_file(new_vma->vm_file); | |
472 | + vma_get_file(new_vma); | |
473 | if (new_vma->vm_ops && new_vma->vm_ops->open) | |
474 | new_vma->vm_ops->open(new_vma); | |
475 | vma_link(mm, new_vma, prev, rb_link, rb_parent); | |
476 | diff --git a/mm/msync.c b/mm/msync.c | |
076b876e | 477 | index 992a167..ce1915b 100644 |
fb47a38f JR |
478 | --- a/mm/msync.c |
479 | +++ b/mm/msync.c | |
076b876e | 480 | @@ -84,13 +84,13 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) |
fb47a38f JR |
481 | start = vma->vm_end; |
482 | if ((flags & MS_SYNC) && file && | |
483 | (vma->vm_flags & VM_SHARED)) { | |
484 | - get_file(file); | |
485 | + vma_get_file(vma); | |
486 | up_read(&mm->mmap_sem); | |
076b876e AM |
487 | if (vma->vm_flags & VM_NONLINEAR) |
488 | error = vfs_fsync(file, 1); | |
489 | else | |
490 | error = vfs_fsync_range(file, fstart, fend, 1); | |
fb47a38f JR |
491 | - fput(file); |
492 | + vma_fput(vma); | |
493 | if (error || start >= end) | |
494 | goto out; | |
495 | down_read(&mm->mmap_sem); | |
496 | diff --git a/mm/nommu.c b/mm/nommu.c | |
c1595e42 | 497 | index bd1808e..c9ea035 100644 |
fb47a38f JR |
498 | --- a/mm/nommu.c |
499 | +++ b/mm/nommu.c | |
076b876e | 500 | @@ -658,7 +658,7 @@ static void __put_nommu_region(struct vm_region *region) |
fb47a38f JR |
501 | up_write(&nommu_region_sem); |
502 | ||
503 | if (region->vm_file) | |
504 | - fput(region->vm_file); | |
505 | + vmr_fput(region); | |
506 | ||
507 | /* IO memory and memory shared directly out of the pagecache | |
508 | * from ramfs/tmpfs mustn't be released here */ | |
076b876e | 509 | @@ -823,7 +823,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) |
fb47a38f JR |
510 | if (vma->vm_ops && vma->vm_ops->close) |
511 | vma->vm_ops->close(vma); | |
512 | if (vma->vm_file) | |
513 | - fput(vma->vm_file); | |
514 | + vma_fput(vma); | |
515 | put_nommu_region(vma->vm_region); | |
516 | kmem_cache_free(vm_area_cachep, vma); | |
517 | } | |
076b876e | 518 | @@ -1385,7 +1385,7 @@ unsigned long do_mmap_pgoff(struct file *file, |
fb47a38f JR |
519 | goto error_just_free; |
520 | } | |
521 | } | |
522 | - fput(region->vm_file); | |
523 | + vmr_fput(region); | |
524 | kmem_cache_free(vm_region_jar, region); | |
525 | region = pregion; | |
526 | result = start; | |
076b876e | 527 | @@ -1461,10 +1461,10 @@ error_just_free: |
fb47a38f JR |
528 | up_write(&nommu_region_sem); |
529 | error: | |
530 | if (region->vm_file) | |
531 | - fput(region->vm_file); | |
532 | + vmr_fput(region); | |
533 | kmem_cache_free(vm_region_jar, region); | |
534 | if (vma->vm_file) | |
535 | - fput(vma->vm_file); | |
536 | + vma_fput(vma); | |
537 | kmem_cache_free(vm_area_cachep, vma); | |
538 | kleave(" = %d", ret); | |
539 | return ret; | |
076b876e AM |
540 | diff --git a/mm/prfile.c b/mm/prfile.c |
541 | new file mode 100644 | |
542 | index 0000000..fc708d2 | |
543 | --- /dev/null | |
544 | +++ b/mm/prfile.c | |
545 | @@ -0,0 +1,86 @@ | |
546 | +/* | |
547 | + * Mainly for aufs which mmap(2) diffrent file and wants to print different path | |
548 | + * in /proc/PID/maps. | |
549 | + * Call these functions via macros defined in linux/mm.h. | |
550 | + * | |
551 | + * See Documentation/filesystems/aufs/design/06mmap.txt | |
552 | + * | |
553 | + * Copyright (c) 2014 Junjro R. Okajima | |
554 | + * Copyright (c) 2014 Ian Campbell | |
555 | + */ | |
556 | + | |
557 | +#include <linux/mm.h> | |
558 | +#include <linux/file.h> | |
559 | +#include <linux/fs.h> | |
560 | + | |
561 | +/* #define PRFILE_TRACE */ | |
562 | +static inline void prfile_trace(struct file *f, struct file *pr, | |
563 | + const char func[], int line, const char func2[]) | |
564 | +{ | |
565 | +#ifdef PRFILE_TRACE | |
566 | + if (pr) | |
567 | + pr_info("%s:%d: %s, %p\n", func, line, func2, | |
568 | + f ? (char *)f->f_dentry->d_name.name : "(null)"); | |
569 | +#endif | |
570 | +} | |
571 | + | |
572 | +#ifdef CONFIG_MMU | |
573 | +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[], | |
574 | + int line) | |
575 | +{ | |
576 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
577 | + | |
578 | + prfile_trace(f, pr, func, line, __func__); | |
579 | + file_update_time(f); | |
580 | + if (f && pr) | |
581 | + file_update_time(pr); | |
582 | +} | |
583 | + | |
584 | +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[], | |
585 | + int line) | |
586 | +{ | |
587 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
588 | + | |
589 | + prfile_trace(f, pr, func, line, __func__); | |
590 | + return (f && pr) ? pr : f; | |
591 | +} | |
592 | + | |
593 | +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line) | |
594 | +{ | |
595 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
596 | + | |
597 | + prfile_trace(f, pr, func, line, __func__); | |
598 | + get_file(f); | |
599 | + if (f && pr) | |
600 | + get_file(pr); | |
601 | +} | |
602 | + | |
603 | +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line) | |
604 | +{ | |
605 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
606 | + | |
607 | + prfile_trace(f, pr, func, line, __func__); | |
608 | + fput(f); | |
609 | + if (f && pr) | |
610 | + fput(pr); | |
611 | +} | |
612 | +#else | |
613 | +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[], | |
614 | + int line) | |
615 | +{ | |
616 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
617 | + | |
618 | + prfile_trace(f, pr, func, line, __func__); | |
619 | + return (f && pr) ? pr : f; | |
620 | +} | |
621 | + | |
622 | +void vmr_do_fput(struct vm_region *region, const char func[], int line) | |
623 | +{ | |
624 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
625 | + | |
626 | + prfile_trace(f, pr, func, line, __func__); | |
627 | + fput(f); | |
628 | + if (f && pr) | |
629 | + fput(pr); | |
630 | +} | |
631 | +#endif /* CONFIG_MMU */ | |
c1595e42 | 632 | aufs3.18.1+ standalone patch |
7f207e10 | 633 | |
c1595e42 JR |
634 | diff --git a/fs/dcache.c b/fs/dcache.c |
635 | index da7342e..b147b6c 100644 | |
636 | --- a/fs/dcache.c | |
637 | +++ b/fs/dcache.c | |
638 | @@ -1124,6 +1124,7 @@ rename_retry: | |
639 | seq = 1; | |
640 | goto again; | |
641 | } | |
642 | +EXPORT_SYMBOL(d_walk); | |
643 | ||
644 | /* | |
645 | * Search for at least 1 mount point in the dentry's subdirs. | |
1e00d052 | 646 | diff --git a/fs/inode.c b/fs/inode.c |
c1595e42 | 647 | index df21e66..c8df03d 100644 |
1e00d052 AM |
648 | --- a/fs/inode.c |
649 | +++ b/fs/inode.c | |
392086de | 650 | @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly; |
4b3da204 | 651 | static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); |
2cbb1c4b JR |
652 | |
653 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock); | |
2cbb1c4b | 654 | +EXPORT_SYMBOL(inode_sb_list_lock); |
7f207e10 AM |
655 | |
656 | /* | |
4b3da204 | 657 | * Empty aops. Can be used for the cases where the user does not |
c1595e42 | 658 | @@ -1513,6 +1514,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags) |
0c3ec466 AM |
659 | mark_inode_dirty_sync(inode); |
660 | return 0; | |
661 | } | |
662 | +EXPORT_SYMBOL(update_time); | |
663 | ||
664 | /** | |
665 | * touch_atime - update the access time | |
7f207e10 | 666 | diff --git a/fs/namespace.c b/fs/namespace.c |
c1595e42 | 667 | index 5b66b2b..68ff4e4 100644 |
7f207e10 AM |
668 | --- a/fs/namespace.c |
669 | +++ b/fs/namespace.c | |
c1595e42 | 670 | @@ -454,6 +454,7 @@ void __mnt_drop_write(struct vfsmount *mnt) |
c06a8ce3 AM |
671 | mnt_dec_writers(real_mount(mnt)); |
672 | preempt_enable(); | |
673 | } | |
674 | +EXPORT_SYMBOL_GPL(__mnt_drop_write); | |
675 | ||
676 | /** | |
677 | * mnt_drop_write - give up write access to a mount | |
c1595e42 | 678 | @@ -1727,6 +1728,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, |
7f207e10 AM |
679 | } |
680 | return 0; | |
681 | } | |
682 | +EXPORT_SYMBOL(iterate_mounts); | |
683 | ||
7eafdf33 | 684 | static void cleanup_group_ids(struct mount *mnt, struct mount *end) |
7f207e10 AM |
685 | { |
686 | diff --git a/fs/notify/group.c b/fs/notify/group.c | |
c1595e42 | 687 | index d16b62c..06ca6bc 100644 |
7f207e10 AM |
688 | --- a/fs/notify/group.c |
689 | +++ b/fs/notify/group.c | |
690 | @@ -22,6 +22,7 @@ | |
691 | #include <linux/srcu.h> | |
692 | #include <linux/rculist.h> | |
693 | #include <linux/wait.h> | |
694 | +#include <linux/module.h> | |
695 | ||
696 | #include <linux/fsnotify_backend.h> | |
697 | #include "fsnotify.h" | |
fb47a38f | 698 | @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group) |
1716fcea AM |
699 | { |
700 | atomic_inc(&group->refcnt); | |
701 | } | |
702 | +EXPORT_SYMBOL(fsnotify_get_group); | |
703 | ||
704 | /* | |
705 | * Drop a reference to a group. Free it if it's through. | |
fb47a38f | 706 | @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group) |
7f207e10 | 707 | if (atomic_dec_and_test(&group->refcnt)) |
1716fcea | 708 | fsnotify_final_destroy_group(group); |
7f207e10 AM |
709 | } |
710 | +EXPORT_SYMBOL(fsnotify_put_group); | |
711 | ||
712 | /* | |
713 | * Create a new fsnotify_group and hold a reference for the group returned. | |
fb47a38f | 714 | @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) |
7f207e10 AM |
715 | |
716 | return group; | |
717 | } | |
718 | +EXPORT_SYMBOL(fsnotify_alloc_group); | |
1716fcea AM |
719 | |
720 | int fsnotify_fasync(int fd, struct file *file, int on) | |
721 | { | |
7f207e10 | 722 | diff --git a/fs/notify/mark.c b/fs/notify/mark.c |
c1595e42 | 723 | index 34c38fa..d40cf58 100644 |
7f207e10 AM |
724 | --- a/fs/notify/mark.c |
725 | +++ b/fs/notify/mark.c | |
392086de | 726 | @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) |
7f207e10 | 727 | mark->free_mark(mark); |
1716fcea | 728 | } |
7f207e10 AM |
729 | } |
730 | +EXPORT_SYMBOL(fsnotify_put_mark); | |
731 | ||
732 | /* | |
733 | * Any time a mark is getting freed we end up here. | |
392086de | 734 | @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark, |
1716fcea AM |
735 | fsnotify_destroy_mark_locked(mark, group); |
736 | mutex_unlock(&group->mark_mutex); | |
7f207e10 AM |
737 | } |
738 | +EXPORT_SYMBOL(fsnotify_destroy_mark); | |
739 | ||
740 | void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask) | |
741 | { | |
c1595e42 | 742 | @@ -311,6 +313,7 @@ err: |
7f207e10 AM |
743 | |
744 | return ret; | |
745 | } | |
746 | +EXPORT_SYMBOL(fsnotify_add_mark); | |
747 | ||
1716fcea AM |
748 | int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group, |
749 | struct inode *inode, struct vfsmount *mnt, int allow_dups) | |
c1595e42 | 750 | @@ -372,6 +375,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark, |
7f207e10 AM |
751 | atomic_set(&mark->refcnt, 1); |
752 | mark->free_mark = free_mark; | |
753 | } | |
754 | +EXPORT_SYMBOL(fsnotify_init_mark); | |
755 | ||
756 | static int fsnotify_mark_destroy(void *ignored) | |
757 | { | |
758 | diff --git a/fs/open.c b/fs/open.c | |
c1595e42 | 759 | index de92c13..65d8ab0 100644 |
7f207e10 AM |
760 | --- a/fs/open.c |
761 | +++ b/fs/open.c | |
523b37e3 | 762 | @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, |
7f207e10 AM |
763 | mutex_unlock(&dentry->d_inode->i_mutex); |
764 | return ret; | |
765 | } | |
766 | +EXPORT_SYMBOL(do_truncate); | |
767 | ||
1716fcea | 768 | long vfs_truncate(struct path *path, loff_t length) |
7f207e10 AM |
769 | { |
770 | diff --git a/fs/splice.c b/fs/splice.c | |
c1595e42 | 771 | index 619359a..c14f60e 100644 |
7f207e10 AM |
772 | --- a/fs/splice.c |
773 | +++ b/fs/splice.c | |
076b876e | 774 | @@ -1127,6 +1127,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
392086de AM |
775 | |
776 | return splice_write(pipe, out, ppos, len, flags); | |
7f207e10 AM |
777 | } |
778 | +EXPORT_SYMBOL(do_splice_from); | |
779 | ||
780 | /* | |
781 | * Attempt to initiate a splice from a file to a pipe. | |
076b876e | 782 | @@ -1153,6 +1154,7 @@ long do_splice_to(struct file *in, loff_t *ppos, |
7f207e10 AM |
783 | |
784 | return splice_read(in, ppos, pipe, len, flags); | |
785 | } | |
786 | +EXPORT_SYMBOL(do_splice_to); | |
787 | ||
788 | /** | |
789 | * splice_direct_to_actor - splices data directly between two non-pipes | |
c1595e42 JR |
790 | diff --git a/fs/xattr.c b/fs/xattr.c |
791 | index 64e83ef..bd71e53 100644 | |
792 | --- a/fs/xattr.c | |
793 | +++ b/fs/xattr.c | |
794 | @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, | |
795 | *xattr_value = value; | |
796 | return error; | |
797 | } | |
798 | +EXPORT_SYMBOL(vfs_getxattr_alloc); | |
799 | ||
800 | /* Compare an extended attribute value with the given value */ | |
801 | int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name, | |
7f207e10 | 802 | diff --git a/security/commoncap.c b/security/commoncap.c |
c1595e42 | 803 | index bab0611..3fa2f82 100644 |
7f207e10 AM |
804 | --- a/security/commoncap.c |
805 | +++ b/security/commoncap.c | |
c1595e42 | 806 | @@ -979,9 +979,11 @@ int cap_mmap_addr(unsigned long addr) |
94337f0d | 807 | } |
7f207e10 AM |
808 | return ret; |
809 | } | |
0c3ec466 AM |
810 | +EXPORT_SYMBOL(cap_mmap_addr); |
811 | ||
812 | int cap_mmap_file(struct file *file, unsigned long reqprot, | |
813 | unsigned long prot, unsigned long flags) | |
814 | { | |
815 | return 0; | |
816 | } | |
817 | +EXPORT_SYMBOL(cap_mmap_file); | |
7f207e10 | 818 | diff --git a/security/device_cgroup.c b/security/device_cgroup.c |
c1595e42 | 819 | index 188c1d2..426d9af 100644 |
7f207e10 AM |
820 | --- a/security/device_cgroup.c |
821 | +++ b/security/device_cgroup.c | |
f6c5ef8b AM |
822 | @@ -7,6 +7,7 @@ |
823 | #include <linux/device_cgroup.h> | |
824 | #include <linux/cgroup.h> | |
825 | #include <linux/ctype.h> | |
826 | +#include <linux/export.h> | |
827 | #include <linux/list.h> | |
828 | #include <linux/uaccess.h> | |
829 | #include <linux/seq_file.h> | |
076b876e | 830 | @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask) |
537831f9 AM |
831 | return __devcgroup_check_permission(type, imajor(inode), iminor(inode), |
832 | access); | |
7f207e10 | 833 | } |
2cbb1c4b | 834 | +EXPORT_SYMBOL(__devcgroup_inode_permission); |
7f207e10 AM |
835 | |
836 | int devcgroup_inode_mknod(int mode, dev_t dev) | |
837 | { | |
838 | diff --git a/security/security.c b/security/security.c | |
c1595e42 | 839 | index 18b35c6..12c67af 100644 |
7f207e10 AM |
840 | --- a/security/security.c |
841 | +++ b/security/security.c | |
392086de | 842 | @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry) |
7f207e10 AM |
843 | return 0; |
844 | return security_ops->path_rmdir(dir, dentry); | |
845 | } | |
846 | +EXPORT_SYMBOL(security_path_rmdir); | |
847 | ||
848 | int security_path_unlink(struct path *dir, struct dentry *dentry) | |
849 | { | |
392086de | 850 | @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry, |
7f207e10 AM |
851 | return 0; |
852 | return security_ops->path_symlink(dir, dentry, old_name); | |
853 | } | |
854 | +EXPORT_SYMBOL(security_path_symlink); | |
855 | ||
856 | int security_path_link(struct dentry *old_dentry, struct path *new_dir, | |
857 | struct dentry *new_dentry) | |
392086de | 858 | @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir, |
7f207e10 AM |
859 | return 0; |
860 | return security_ops->path_link(old_dentry, new_dir, new_dentry); | |
861 | } | |
862 | +EXPORT_SYMBOL(security_path_link); | |
863 | ||
864 | int security_path_rename(struct path *old_dir, struct dentry *old_dentry, | |
38d290e6 JR |
865 | struct path *new_dir, struct dentry *new_dentry, |
866 | @@ -458,6 +461,7 @@ int security_path_truncate(struct path *path) | |
7f207e10 AM |
867 | return 0; |
868 | return security_ops->path_truncate(path); | |
869 | } | |
870 | +EXPORT_SYMBOL(security_path_truncate); | |
871 | ||
7eafdf33 AM |
872 | int security_path_chmod(struct path *path, umode_t mode) |
873 | { | |
38d290e6 | 874 | @@ -465,6 +469,7 @@ int security_path_chmod(struct path *path, umode_t mode) |
7f207e10 | 875 | return 0; |
7eafdf33 | 876 | return security_ops->path_chmod(path, mode); |
7f207e10 AM |
877 | } |
878 | +EXPORT_SYMBOL(security_path_chmod); | |
879 | ||
537831f9 | 880 | int security_path_chown(struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 881 | { |
38d290e6 | 882 | @@ -472,6 +477,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 AM |
883 | return 0; |
884 | return security_ops->path_chown(path, uid, gid); | |
885 | } | |
886 | +EXPORT_SYMBOL(security_path_chown); | |
887 | ||
888 | int security_path_chroot(struct path *path) | |
889 | { | |
38d290e6 | 890 | @@ -557,6 +563,7 @@ int security_inode_readlink(struct dentry *dentry) |
7f207e10 AM |
891 | return 0; |
892 | return security_ops->inode_readlink(dentry); | |
893 | } | |
894 | +EXPORT_SYMBOL(security_inode_readlink); | |
895 | ||
896 | int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd) | |
897 | { | |
38d290e6 | 898 | @@ -571,6 +578,7 @@ int security_inode_permission(struct inode *inode, int mask) |
7f207e10 | 899 | return 0; |
1e00d052 | 900 | return security_ops->inode_permission(inode, mask); |
7f207e10 AM |
901 | } |
902 | +EXPORT_SYMBOL(security_inode_permission); | |
903 | ||
1e00d052 | 904 | int security_inode_setattr(struct dentry *dentry, struct iattr *attr) |
7f207e10 | 905 | { |
38d290e6 | 906 | @@ -693,6 +701,7 @@ int security_file_permission(struct file *file, int mask) |
7f207e10 AM |
907 | |
908 | return fsnotify_perm(file, mask); | |
909 | } | |
910 | +EXPORT_SYMBOL(security_file_permission); | |
911 | ||
912 | int security_file_alloc(struct file *file) | |
913 | { | |
38d290e6 | 914 | @@ -753,6 +762,7 @@ int security_mmap_file(struct file *file, unsigned long prot, |
7f207e10 AM |
915 | return ret; |
916 | return ima_file_mmap(file, prot); | |
917 | } | |
0c3ec466 | 918 | +EXPORT_SYMBOL(security_mmap_file); |
7f207e10 | 919 | |
0c3ec466 AM |
920 | int security_mmap_addr(unsigned long addr) |
921 | { | |
7f207e10 AM |
922 | diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs |
923 | --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 924 | +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-01-25 13:00:38.627713742 +0100 |
86dc4139 | 925 | @@ -0,0 +1,50 @@ |
7f207e10 AM |
926 | +What: /debug/aufs/si_<id>/ |
927 | +Date: March 2009 | |
f6b6e03d | 928 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
929 | +Description: |
930 | + Under /debug/aufs, a directory named si_<id> is created | |
931 | + per aufs mount, where <id> is a unique id generated | |
932 | + internally. | |
1facf9fc | 933 | + |
86dc4139 AM |
934 | +What: /debug/aufs/si_<id>/plink |
935 | +Date: Apr 2013 | |
f6b6e03d | 936 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
86dc4139 AM |
937 | +Description: |
938 | + It has three lines and shows the information about the | |
939 | + pseudo-link. The first line is a single number | |
940 | + representing a number of buckets. The second line is a | |
941 | + number of pseudo-links per buckets (separated by a | |
942 | + blank). The last line is a single number representing a | |
943 | + total number of psedo-links. | |
944 | + When the aufs mount option 'noplink' is specified, it | |
945 | + will show "1\n0\n0\n". | |
946 | + | |
7f207e10 AM |
947 | +What: /debug/aufs/si_<id>/xib |
948 | +Date: March 2009 | |
f6b6e03d | 949 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
950 | +Description: |
951 | + It shows the consumed blocks by xib (External Inode Number | |
952 | + Bitmap), its block size and file size. | |
953 | + When the aufs mount option 'noxino' is specified, it | |
954 | + will be empty. About XINO files, see the aufs manual. | |
955 | + | |
956 | +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN | |
957 | +Date: March 2009 | |
f6b6e03d | 958 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
959 | +Description: |
960 | + It shows the consumed blocks by xino (External Inode Number | |
961 | + Translation Table), its link count, block size and file | |
962 | + size. | |
963 | + When the aufs mount option 'noxino' is specified, it | |
964 | + will be empty. About XINO files, see the aufs manual. | |
965 | + | |
966 | +What: /debug/aufs/si_<id>/xigen | |
967 | +Date: March 2009 | |
f6b6e03d | 968 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
969 | +Description: |
970 | + It shows the consumed blocks by xigen (External Inode | |
971 | + Generation Table), its block size and file size. | |
972 | + If CONFIG_AUFS_EXPORT is disabled, this entry will not | |
973 | + be created. | |
974 | + When the aufs mount option 'noxino' is specified, it | |
975 | + will be empty. About XINO files, see the aufs manual. | |
976 | diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs | |
977 | --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 978 | +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-01-25 13:00:38.627713742 +0100 |
392086de | 979 | @@ -0,0 +1,31 @@ |
7f207e10 AM |
980 | +What: /sys/fs/aufs/si_<id>/ |
981 | +Date: March 2009 | |
f6b6e03d | 982 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
983 | +Description: |
984 | + Under /sys/fs/aufs, a directory named si_<id> is created | |
985 | + per aufs mount, where <id> is a unique id generated | |
986 | + internally. | |
987 | + | |
988 | +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN | |
989 | +Date: March 2009 | |
f6b6e03d | 990 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
991 | +Description: |
992 | + It shows the abolute path of a member directory (which | |
993 | + is called branch) in aufs, and its permission. | |
994 | + | |
392086de AM |
995 | +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN |
996 | +Date: July 2013 | |
f6b6e03d | 997 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
392086de AM |
998 | +Description: |
999 | + It shows the id of a member directory (which is called | |
1000 | + branch) in aufs. | |
1001 | + | |
7f207e10 AM |
1002 | +What: /sys/fs/aufs/si_<id>/xi_path |
1003 | +Date: March 2009 | |
f6b6e03d | 1004 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1005 | +Description: |
1006 | + It shows the abolute path of XINO (External Inode Number | |
1007 | + Bitmap, Translation Table and Generation Table) file | |
1008 | + even if it is the default path. | |
1009 | + When the aufs mount option 'noxino' is specified, it | |
1010 | + will be empty. About XINO files, see the aufs manual. | |
53392da6 AM |
1011 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt |
1012 | --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1013 | +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 1014 | @@ -0,0 +1,161 @@ |
53392da6 | 1015 | + |
523b37e3 | 1016 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
1017 | +# |
1018 | +# This program is free software; you can redistribute it and/or modify | |
1019 | +# it under the terms of the GNU General Public License as published by | |
1020 | +# the Free Software Foundation; either version 2 of the License, or | |
1021 | +# (at your option) any later version. | |
1022 | +# | |
1023 | +# This program is distributed in the hope that it will be useful, | |
1024 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1025 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1026 | +# GNU General Public License for more details. | |
1027 | +# | |
1028 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1029 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1030 | + |
1031 | +Introduction | |
1032 | +---------------------------------------- | |
1033 | + | |
1034 | +aufs [ei ju: ef es] | [a u f s] | |
1035 | +1. abbrev. for "advanced multi-layered unification filesystem". | |
1036 | +2. abbrev. for "another unionfs". | |
1037 | +3. abbrev. for "auf das" in German which means "on the" in English. | |
1038 | + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E). | |
1039 | + But "Filesystem aufs Filesystem" is hard to understand. | |
1040 | + | |
1041 | +AUFS is a filesystem with features: | |
1042 | +- multi layered stackable unification filesystem, the member directory | |
1043 | + is called as a branch. | |
1044 | +- branch permission and attribute, 'readonly', 'real-readonly', | |
1045 | + 'readwrite', 'whiteout-able', 'link-able whiteout' and their | |
1046 | + combination. | |
1047 | +- internal "file copy-on-write". | |
1048 | +- logical deletion, whiteout. | |
1049 | +- dynamic branch manipulation, adding, deleting and changing permission. | |
1050 | +- allow bypassing aufs, user's direct branch access. | |
1051 | +- external inode number translation table and bitmap which maintains the | |
1052 | + persistent aufs inode number. | |
1053 | +- seekable directory, including NFS readdir. | |
1054 | +- file mapping, mmap and sharing pages. | |
1055 | +- pseudo-link, hardlink over branches. | |
1056 | +- loopback mounted filesystem as a branch. | |
1057 | +- several policies to select one among multiple writable branches. | |
1058 | +- revert a single systemcall when an error occurs in aufs. | |
1059 | +- and more... | |
1060 | + | |
1061 | + | |
1062 | +Multi Layered Stackable Unification Filesystem | |
1063 | +---------------------------------------------------------------------- | |
1064 | +Most people already knows what it is. | |
1065 | +It is a filesystem which unifies several directories and provides a | |
1066 | +merged single directory. When users access a file, the access will be | |
1067 | +passed/re-directed/converted (sorry, I am not sure which English word is | |
1068 | +correct) to the real file on the member filesystem. The member | |
1069 | +filesystem is called 'lower filesystem' or 'branch' and has a mode | |
1070 | +'readonly' and 'readwrite.' And the deletion for a file on the lower | |
1071 | +readonly branch is handled by creating 'whiteout' on the upper writable | |
1072 | +branch. | |
1073 | + | |
1074 | +On LKML, there have been discussions about UnionMount (Jan Blunck, | |
1075 | +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took | |
1076 | +different approaches to implement the merged-view. | |
1077 | +The former tries putting it into VFS, and the latter implements as a | |
1078 | +separate filesystem. | |
1079 | +(If I misunderstand about these implementations, please let me know and | |
1080 | +I shall correct it. Because it is a long time ago when I read their | |
1081 | +source files last time). | |
1082 | + | |
1083 | +UnionMount's approach will be able to small, but may be hard to share | |
1084 | +branches between several UnionMount since the whiteout in it is | |
1085 | +implemented in the inode on branch filesystem and always | |
1086 | +shared. According to Bharata's post, readdir does not seems to be | |
1087 | +finished yet. | |
1088 | +There are several missing features known in this implementations such as | |
1089 | +- for users, the inode number may change silently. eg. copy-up. | |
1090 | +- link(2) may break by copy-up. | |
1091 | +- read(2) may get an obsoleted filedata (fstat(2) too). | |
1092 | +- fcntl(F_SETLK) may be broken by copy-up. | |
1093 | +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after | |
1094 | + open(O_RDWR). | |
1095 | + | |
1096 | +Unionfs has a longer history. When I started implementing a stacking filesystem | |
1097 | +(Aug 2005), it already existed. It has virtual super_block, inode, | |
1098 | +dentry and file objects and they have an array pointing lower same kind | |
1099 | +objects. After contributing many patches for Unionfs, I re-started my | |
1100 | +project AUFS (Jun 2006). | |
1101 | + | |
1102 | +In AUFS, the structure of filesystem resembles to Unionfs, but I | |
1103 | +implemented my own ideas, approaches and enhancements and it became | |
1104 | +totally different one. | |
1105 | + | |
1106 | +Comparing DM snapshot and fs based implementation | |
1107 | +- the number of bytes to be copied between devices is much smaller. | |
1108 | +- the type of filesystem must be one and only. | |
1109 | +- the fs must be writable, no readonly fs, even for the lower original | |
1110 | + device. so the compression fs will not be usable. but if we use | |
1111 | + loopback mount, we may address this issue. | |
1112 | + for instance, | |
1113 | + mount /cdrom/squashfs.img /sq | |
1114 | + losetup /sq/ext2.img | |
1115 | + losetup /somewhere/cow | |
1116 | + dmsetup "snapshot /dev/loop0 /dev/loop1 ..." | |
1117 | +- it will be difficult (or needs more operations) to extract the | |
1118 | + difference between the original device and COW. | |
1119 | +- DM snapshot-merge may help a lot when users try merging. in the | |
1120 | + fs-layer union, users will use rsync(1). | |
1121 | + | |
1122 | + | |
1123 | +Several characters/aspects of aufs | |
1124 | +---------------------------------------------------------------------- | |
1125 | + | |
1126 | +Aufs has several characters or aspects. | |
1127 | +1. a filesystem, callee of VFS helper | |
1128 | +2. sub-VFS, caller of VFS helper for branches | |
1129 | +3. a virtual filesystem which maintains persistent inode number | |
1130 | +4. reader/writer of files on branches such like an application | |
1131 | + | |
1132 | +1. Callee of VFS Helper | |
1133 | +As an ordinary linux filesystem, aufs is a callee of VFS. For instance, | |
1134 | +unlink(2) from an application reaches sys_unlink() kernel function and | |
1135 | +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it | |
1136 | +calls filesystem specific unlink operation. Actually aufs implements the | |
1137 | +unlink operation but it behaves like a redirector. | |
1138 | + | |
1139 | +2. Caller of VFS Helper for Branches | |
1140 | +aufs_unlink() passes the unlink request to the branch filesystem as if | |
1141 | +it were called from VFS. So the called unlink operation of the branch | |
1142 | +filesystem acts as usual. As a caller of VFS helper, aufs should handle | |
1143 | +every necessary pre/post operation for the branch filesystem. | |
1144 | +- acquire the lock for the parent dir on a branch | |
1145 | +- lookup in a branch | |
1146 | +- revalidate dentry on a branch | |
1147 | +- mnt_want_write() for a branch | |
1148 | +- vfs_unlink() for a branch | |
1149 | +- mnt_drop_write() for a branch | |
1150 | +- release the lock on a branch | |
1151 | + | |
1152 | +3. Persistent Inode Number | |
1153 | +One of the most important issue for a filesystem is to maintain inode | |
1154 | +numbers. This is particularly important to support exporting a | |
1155 | +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a | |
1156 | +backend block device for its own. But some storage is necessary to | |
1157 | +maintain inode number. It may be a large space and may not suit to keep | |
1158 | +in memory. Aufs rents some space from its first writable branch | |
1159 | +filesystem (by default) and creates file(s) on it. These files are | |
1160 | +created by aufs internally and removed soon (currently) keeping opened. | |
1161 | +Note: Because these files are removed, they are totally gone after | |
1162 | + unmounting aufs. It means the inode numbers are not persistent | |
1163 | + across unmount or reboot. I have a plan to make them really | |
1164 | + persistent which will be important for aufs on NFS server. | |
1165 | + | |
1166 | +4. Read/Write Files Internally (copy-on-write) | |
1167 | +Because a branch can be readonly, when you write a file on it, aufs will | |
1168 | +"copy-up" it to the upper writable branch internally. And then write the | |
1169 | +originally requested thing to the file. Generally kernel doesn't | |
1170 | +open/read/write file actively. In aufs, even a single write may cause a | |
1171 | +internal "file copy". This behaviour is very similar to cp(1) command. | |
1172 | + | |
1173 | +Some people may think it is better to pass such work to user space | |
1174 | +helper, instead of doing in kernel space. Actually I am still thinking | |
1175 | +about it. But currently I have implemented it in kernel space. | |
1176 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt | |
1177 | --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1178 | +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-01-25 13:00:38.627713742 +0100 |
076b876e | 1179 | @@ -0,0 +1,251 @@ |
53392da6 | 1180 | + |
523b37e3 | 1181 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
1182 | +# |
1183 | +# This program is free software; you can redistribute it and/or modify | |
1184 | +# it under the terms of the GNU General Public License as published by | |
1185 | +# the Free Software Foundation; either version 2 of the License, or | |
1186 | +# (at your option) any later version. | |
1187 | +# | |
1188 | +# This program is distributed in the hope that it will be useful, | |
1189 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1190 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1191 | +# GNU General Public License for more details. | |
1192 | +# | |
1193 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1194 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1195 | + |
1196 | +Basic Aufs Internal Structure | |
1197 | + | |
1198 | +Superblock/Inode/Dentry/File Objects | |
1199 | +---------------------------------------------------------------------- | |
1200 | +As like an ordinary filesystem, aufs has its own | |
1201 | +superblock/inode/dentry/file objects. All these objects have a | |
1202 | +dynamically allocated array and store the same kind of pointers to the | |
1203 | +lower filesystem, branch. | |
1204 | +For example, when you build a union with one readwrite branch and one | |
1205 | +readonly, mounted /au, /rw and /ro respectively. | |
1206 | +- /au = /rw + /ro | |
1207 | +- /ro/fileA exists but /rw/fileA | |
1208 | + | |
1209 | +Aufs lookup operation finds /ro/fileA and gets dentry for that. These | |
1210 | +pointers are stored in a aufs dentry. The array in aufs dentry will be, | |
1211 | +- [0] = NULL | |
1212 | +- [1] = /ro/fileA | |
1213 | + | |
1214 | +This style of an array is essentially same to the aufs | |
1215 | +superblock/inode/dentry/file objects. | |
1216 | + | |
1217 | +Because aufs supports manipulating branches, ie. add/delete/change | |
1218 | +dynamically, these objects has its own generation. When branches are | |
1219 | +changed, the generation in aufs superblock is incremented. And a | |
1220 | +generation in other object are compared when it is accessed. | |
1221 | +When a generation in other objects are obsoleted, aufs refreshes the | |
1222 | +internal array. | |
1223 | + | |
1224 | + | |
1225 | +Superblock | |
1226 | +---------------------------------------------------------------------- | |
1227 | +Additionally aufs superblock has some data for policies to select one | |
1228 | +among multiple writable branches, XIB files, pseudo-links and kobject. | |
1229 | +See below in detail. | |
1230 | +About the policies which supports copy-down a directory, see policy.txt | |
1231 | +too. | |
1232 | + | |
1233 | + | |
1234 | +Branch and XINO(External Inode Number Translation Table) | |
1235 | +---------------------------------------------------------------------- | |
1236 | +Every branch has its own xino (external inode number translation table) | |
1237 | +file. The xino file is created and unlinked by aufs internally. When two | |
1238 | +members of a union exist on the same filesystem, they share the single | |
1239 | +xino file. | |
1240 | +The struct of a xino file is simple, just a sequence of aufs inode | |
1241 | +numbers which is indexed by the lower inode number. | |
1242 | +In the above sample, assume the inode number of /ro/fileA is i111 and | |
1243 | +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as | |
1244 | +4(8) bytes at 111 * 4(8) bytes offset in the xino file. | |
1245 | + | |
1246 | +When the inode numbers are not contiguous, the xino file will be sparse | |
1247 | +which has a hole in it and doesn't consume as much disk space as it | |
1248 | +might appear. If your branch filesystem consumes disk space for such | |
1249 | +holes, then you should specify 'xino=' option at mounting aufs. | |
1250 | + | |
1251 | +Also a writable branch has three kinds of "whiteout bases". All these | |
1252 | +are existed when the branch is joined to aufs and the names are | |
1253 | +whiteout-ed doubly, so that users will never see their names in aufs | |
1254 | +hierarchy. | |
1255 | +1. a regular file which will be linked to all whiteouts. | |
1256 | +2. a directory to store a pseudo-link. | |
1257 | +3. a directory to store an "orphan-ed" file temporary. | |
1258 | + | |
1259 | +1. Whiteout Base | |
1260 | + When you remove a file on a readonly branch, aufs handles it as a | |
1261 | + logical deletion and creates a whiteout on the upper writable branch | |
1262 | + as a hardlink of this file in order not to consume inode on the | |
1263 | + writable branch. | |
1264 | +2. Pseudo-link Dir | |
1265 | + See below, Pseudo-link. | |
1266 | +3. Step-Parent Dir | |
1267 | + When "fileC" exists on the lower readonly branch only and it is | |
1268 | + opened and removed with its parent dir, and then user writes | |
1269 | + something into it, then aufs copies-up fileC to this | |
1270 | + directory. Because there is no other dir to store fileC. After | |
1271 | + creating a file under this dir, the file is unlinked. | |
1272 | + | |
1273 | +Because aufs supports manipulating branches, ie. add/delete/change | |
1274 | +dynamically, a branch has its own id. When the branch order changes, aufs | |
1275 | +finds the new index by searching the branch id. | |
1276 | + | |
1277 | + | |
1278 | +Pseudo-link | |
1279 | +---------------------------------------------------------------------- | |
1280 | +Assume "fileA" exists on the lower readonly branch only and it is | |
1281 | +hardlinked to "fileB" on the branch. When you write something to fileA, | |
1282 | +aufs copies-up it to the upper writable branch. Additionally aufs | |
1283 | +creates a hardlink under the Pseudo-link Directory of the writable | |
1284 | +branch. The inode of a pseudo-link is kept in aufs super_block as a | |
1285 | +simple list. If fileB is read after unlinking fileA, aufs returns | |
1286 | +filedata from the pseudo-link instead of the lower readonly | |
1287 | +branch. Because the pseudo-link is based upon the inode, to keep the | |
1288 | +inode number by xino (see above) is important. | |
1289 | + | |
1290 | +All the hardlinks under the Pseudo-link Directory of the writable branch | |
1291 | +should be restored in a proper location later. Aufs provides a utility | |
1292 | +to do this. The userspace helpers executed at remounting and unmounting | |
1293 | +aufs by default. | |
1294 | +During this utility is running, it puts aufs into the pseudo-link | |
1295 | +maintenance mode. In this mode, only the process which began the | |
1296 | +maintenance mode (and its child processes) is allowed to operate in | |
1297 | +aufs. Some other processes which are not related to the pseudo-link will | |
1298 | +be allowed to run too, but the rest have to return an error or wait | |
1299 | +until the maintenance mode ends. If a process already acquires an inode | |
1300 | +mutex (in VFS), it has to return an error. | |
1301 | + | |
1302 | + | |
1303 | +XIB(external inode number bitmap) | |
1304 | +---------------------------------------------------------------------- | |
1305 | +Addition to the xino file per a branch, aufs has an external inode number | |
1306 | +bitmap in a superblock object. It is also a file such like a xino file. | |
1307 | +It is a simple bitmap to mark whether the aufs inode number is in-use or | |
1308 | +not. | |
1309 | +To reduce the file I/O, aufs prepares a single memory page to cache xib. | |
1310 | + | |
1311 | +Aufs implements a feature to truncate/refresh both of xino and xib to | |
1312 | +reduce the number of consumed disk blocks for these files. | |
1313 | + | |
1314 | + | |
1315 | +Virtual or Vertical Dir, and Readdir in Userspace | |
1316 | +---------------------------------------------------------------------- | |
1317 | +In order to support multiple layers (branches), aufs readdir operation | |
1318 | +constructs a virtual dir block on memory. For readdir, aufs calls | |
1319 | +vfs_readdir() internally for each dir on branches, merges their entries | |
1320 | +with eliminating the whiteout-ed ones, and sets it to file (dir) | |
1321 | +object. So the file object has its entry list until it is closed. The | |
1322 | +entry list will be updated when the file position is zero and becomes | |
1323 | +old. This decision is made in aufs automatically. | |
1324 | + | |
1325 | +The dynamically allocated memory block for the name of entries has a | |
1326 | +unit of 512 bytes (by default) and stores the names contiguously (no | |
1327 | +padding). Another block for each entry is handled by kmem_cache too. | |
1328 | +During building dir blocks, aufs creates hash list and judging whether | |
1329 | +the entry is whiteouted by its upper branch or already listed. | |
1330 | +The merged result is cached in the corresponding inode object and | |
1331 | +maintained by a customizable life-time option. | |
1332 | + | |
1333 | +Some people may call it can be a security hole or invite DoS attack | |
1334 | +since the opened and once readdir-ed dir (file object) holds its entry | |
1335 | +list and becomes a pressure for system memory. But I'd say it is similar | |
1336 | +to files under /proc or /sys. The virtual files in them also holds a | |
1337 | +memory page (generally) while they are opened. When an idea to reduce | |
1338 | +memory for them is introduced, it will be applied to aufs too. | |
1339 | +For those who really hate this situation, I've developed readdir(3) | |
1340 | +library which operates this merging in userspace. You just need to set | |
1341 | +LD_PRELOAD environment variable, and aufs will not consume no memory in | |
1342 | +kernel space for readdir(3). | |
1343 | + | |
1344 | + | |
1345 | +Workqueue | |
1346 | +---------------------------------------------------------------------- | |
1347 | +Aufs sometimes requires privilege access to a branch. For instance, | |
1348 | +in copy-up/down operation. When a user process is going to make changes | |
1349 | +to a file which exists in the lower readonly branch only, and the mode | |
1350 | +of one of ancestor directories may not be writable by a user | |
1351 | +process. Here aufs copy-up the file with its ancestors and they may | |
1352 | +require privilege to set its owner/group/mode/etc. | |
1353 | +This is a typical case of a application character of aufs (see | |
1354 | +Introduction). | |
1355 | + | |
1356 | +Aufs uses workqueue synchronously for this case. It creates its own | |
1357 | +workqueue. The workqueue is a kernel thread and has privilege. Aufs | |
1358 | +passes the request to call mkdir or write (for example), and wait for | |
1359 | +its completion. This approach solves a problem of a signal handler | |
1360 | +simply. | |
1361 | +If aufs didn't adopt the workqueue and changed the privilege of the | |
1362 | +process, and if the mkdir/write call arises SIGXFSZ or other signal, | |
1363 | +then the user process might gain a privilege or the generated core file | |
1364 | +was owned by a superuser. | |
1365 | + | |
1366 | +Also aufs uses the system global workqueue ("events" kernel thread) too | |
1367 | +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a | |
1368 | +whiteout base and etc. This is unrelated to a privilege. | |
1369 | +Most of aufs operation tries acquiring a rw_semaphore for aufs | |
1370 | +superblock at the beginning, at the same time waits for the completion | |
1371 | +of all queued asynchronous tasks. | |
1372 | + | |
1373 | + | |
1374 | +Whiteout | |
1375 | +---------------------------------------------------------------------- | |
1376 | +The whiteout in aufs is very similar to Unionfs's. That is represented | |
1377 | +by its filename. UnionMount takes an approach of a file mode, but I am | |
1378 | +afraid several utilities (find(1) or something) will have to support it. | |
1379 | + | |
1380 | +Basically the whiteout represents "logical deletion" which stops aufs to | |
1381 | +lookup further, but also it represents "dir is opaque" which also stop | |
1382 | +lookup. | |
1383 | + | |
1384 | +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively. | |
1385 | +In order to make several functions in a single systemcall to be | |
1386 | +revertible, aufs adopts an approach to rename a directory to a temporary | |
1387 | +unique whiteouted name. | |
1388 | +For example, in rename(2) dir where the target dir already existed, aufs | |
1389 | +renames the target dir to a temporary unique whiteouted name before the | |
1390 | +actual rename on a branch and then handles other actions (make it opaque, | |
1391 | +update the attributes, etc). If an error happens in these actions, aufs | |
1392 | +simply renames the whiteouted name back and returns an error. If all are | |
1393 | +succeeded, aufs registers a function to remove the whiteouted unique | |
1394 | +temporary name completely and asynchronously to the system global | |
1395 | +workqueue. | |
1396 | + | |
1397 | + | |
1398 | +Copy-up | |
1399 | +---------------------------------------------------------------------- | |
1400 | +It is a well-known feature or concept. | |
1401 | +When user modifies a file on a readonly branch, aufs operate "copy-up" | |
1402 | +internally and makes change to the new file on the upper writable branch. | |
1403 | +When the trigger systemcall does not update the timestamps of the parent | |
1404 | +dir, aufs reverts it after copy-up. | |
c2b27bf2 AM |
1405 | + |
1406 | + | |
1407 | +Move-down (aufs3.9 and later) | |
1408 | +---------------------------------------------------------------------- | |
1409 | +"Copy-up" is one of the essential feature in aufs. It copies a file from | |
1410 | +the lower readonly branch to the upper writable branch when a user | |
1411 | +changes something about the file. | |
1412 | +"Move-down" is an opposite action of copy-up. Basically this action is | |
1413 | +ran manually instead of automatically and internally. | |
076b876e AM |
1414 | +For desgin and implementation, aufs has to consider these issues. |
1415 | +- whiteout for the file may exist on the lower branch. | |
1416 | +- ancestor directories may not exist on the lower branch. | |
1417 | +- diropq for the ancestor directories may exist on the upper branch. | |
1418 | +- free space on the lower branch will reduce. | |
1419 | +- another access to the file may happen during moving-down, including | |
1420 | + UDBA. | |
1421 | +- the file should not be hard-linked nor pseudo-linked. they should be | |
1422 | + handled by auplink utility later. | |
c2b27bf2 AM |
1423 | + |
1424 | +Sometimes users want to move-down a file from the upper writable branch | |
1425 | +to the lower readonly or writable branch. For instance, | |
1426 | +- the free space of the upper writable branch is going to run out. | |
1427 | +- create a new intermediate branch between the upper and lower branch. | |
1428 | +- etc. | |
1429 | + | |
1430 | +For this purpose, use "aumvdown" command in aufs-util.git. | |
53392da6 AM |
1431 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt |
1432 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1433 | +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-01-25 13:00:38.627713742 +0100 |
076b876e | 1434 | @@ -0,0 +1,133 @@ |
53392da6 | 1435 | + |
523b37e3 | 1436 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
1437 | +# |
1438 | +# This program is free software; you can redistribute it and/or modify | |
1439 | +# it under the terms of the GNU General Public License as published by | |
1440 | +# the Free Software Foundation; either version 2 of the License, or | |
1441 | +# (at your option) any later version. | |
1442 | +# | |
1443 | +# This program is distributed in the hope that it will be useful, | |
1444 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1445 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1446 | +# GNU General Public License for more details. | |
1447 | +# | |
1448 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1449 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1450 | + |
1451 | +Lookup in a Branch | |
1452 | +---------------------------------------------------------------------- | |
1453 | +Since aufs has a character of sub-VFS (see Introduction), it operates | |
1454 | +lookup for branches as VFS does. It may be a heavy work. Generally | |
1455 | +speaking struct nameidata is a bigger structure and includes many | |
1456 | +information. But almost all lookup operation in aufs is the simplest | |
1457 | +case, ie. lookup only an entry directly connected to its parent. Digging | |
1458 | +down the directory hierarchy is unnecessary. | |
1459 | + | |
1460 | +VFS has a function lookup_one_len() for that use, but it is not usable | |
1461 | +for a branch filesystem which requires struct nameidata. So aufs | |
1462 | +implements a simple lookup wrapper function. When a branch filesystem | |
1463 | +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds | |
1464 | +a simplest nameidata and calls lookup_hash(). | |
1465 | +Here aufs applies "a principle in NFSD", ie. if the filesystem supports | |
1466 | +NFS-export, then it has to support NULL as a nameidata parameter for | |
1467 | +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in | |
1468 | +aufs tests if ->s_export_op in the branch is NULL or not. | |
1469 | + | |
1470 | +When a branch is a remote filesystem, aufs basically trusts its | |
1471 | +->d_revalidate(), also aufs forces the hardest revalidate tests for | |
1472 | +them. | |
1473 | +For d_revalidate, aufs implements three levels of revalidate tests. See | |
1474 | +"Revalidate Dentry and UDBA" in detail. | |
1475 | + | |
1476 | + | |
076b876e AM |
1477 | +Test Only the Highest One for the Directory Permission (dirperm1 option) |
1478 | +---------------------------------------------------------------------- | |
1479 | +Let's try case study. | |
1480 | +- aufs has two branches, upper readwrite and lower readonly. | |
1481 | + /au = /rw + /ro | |
1482 | +- "dirA" exists under /ro, but /rw. and its mode is 0700. | |
1483 | +- user invoked "chmod a+rx /au/dirA" | |
1484 | +- the internal copy-up is activated and "/rw/dirA" is created and its | |
1485 | + permission bits are set to world readble. | |
1486 | +- then "/au/dirA" becomes world readable? | |
1487 | + | |
1488 | +In this case, /ro/dirA is still 0700 since it exists in readonly branch, | |
1489 | +or it may be a natively readonly filesystem. If aufs respects the lower | |
1490 | +branch, it should not respond readdir request from other users. But user | |
1491 | +allowed it by chmod. Should really aufs rejects showing the entries | |
1492 | +under /ro/dirA? | |
1493 | + | |
1494 | +To be honest, I don't have a best solution for this case. So aufs | |
1495 | +implements 'dirperm1' and 'nodirperm1' and leave it to users. | |
1496 | +When dirperm1 is specified, aufs checks only the highest one for the | |
1497 | +directory permission, and shows the entries. Otherwise, as usual, checks | |
1498 | +every dir existing on all branches and rejects the request. | |
1499 | + | |
1500 | +As a side effect, dirperm1 option improves the performance of aufs | |
1501 | +because the number of permission check is reduced when the number of | |
1502 | +branch is many. | |
1503 | + | |
1504 | + | |
53392da6 AM |
1505 | +Loopback Mount |
1506 | +---------------------------------------------------------------------- | |
1507 | +Basically aufs supports any type of filesystem and block device for a | |
1508 | +branch (actually there are some exceptions). But it is prohibited to add | |
1509 | +a loopback mounted one whose backend file exists in a filesystem which is | |
1510 | +already added to aufs. The reason is to protect aufs from a recursive | |
1511 | +lookup. If it was allowed, the aufs lookup operation might re-enter a | |
1512 | +lookup for the loopback mounted branch in the same context, and will | |
1513 | +cause a deadlock. | |
1514 | + | |
1515 | + | |
1516 | +Revalidate Dentry and UDBA (User's Direct Branch Access) | |
1517 | +---------------------------------------------------------------------- | |
1518 | +Generally VFS helpers re-validate a dentry as a part of lookup. | |
1519 | +0. digging down the directory hierarchy. | |
1520 | +1. lock the parent dir by its i_mutex. | |
1521 | +2. lookup the final (child) entry. | |
1522 | +3. revalidate it. | |
1523 | +4. call the actual operation (create, unlink, etc.) | |
1524 | +5. unlock the parent dir | |
1525 | + | |
1526 | +If the filesystem implements its ->d_revalidate() (step 3), then it is | |
1527 | +called. Actually aufs implements it and checks the dentry on a branch is | |
1528 | +still valid. | |
1529 | +But it is not enough. Because aufs has to release the lock for the | |
1530 | +parent dir on a branch at the end of ->lookup() (step 2) and | |
1531 | +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still | |
1532 | +held by VFS. | |
1533 | +If the file on a branch is changed directly, eg. bypassing aufs, after | |
1534 | +aufs released the lock, then the subsequent operation may cause | |
1535 | +something unpleasant result. | |
1536 | + | |
1537 | +This situation is a result of VFS architecture, ->lookup() and | |
1538 | +->d_revalidate() is separated. But I never say it is wrong. It is a good | |
1539 | +design from VFS's point of view. It is just not suitable for sub-VFS | |
1540 | +character in aufs. | |
1541 | + | |
1542 | +Aufs supports such case by three level of revalidation which is | |
1543 | +selectable by user. | |
1544 | +1. Simple Revalidate | |
1545 | + Addition to the native flow in VFS's, confirm the child-parent | |
1546 | + relationship on the branch just after locking the parent dir on the | |
1547 | + branch in the "actual operation" (step 4). When this validation | |
1548 | + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still | |
1549 | + checks the validation of the dentry on branches. | |
1550 | +2. Monitor Changes Internally by Inotify/Fsnotify | |
1551 | + Addition to above, in the "actual operation" (step 4) aufs re-lookup | |
1552 | + the dentry on the branch, and returns EBUSY if it finds different | |
1553 | + dentry. | |
1554 | + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches | |
1555 | + during it is in cache. When the event is notified, aufs registers a | |
1556 | + function to kernel 'events' thread by schedule_work(). And the | |
1557 | + function sets some special status to the cached aufs dentry and inode | |
1558 | + private data. If they are not cached, then aufs has nothing to | |
1559 | + do. When the same file is accessed through aufs (step 0-3) later, | |
1560 | + aufs will detect the status and refresh all necessary data. | |
1561 | + In this mode, aufs has to ignore the event which is fired by aufs | |
1562 | + itself. | |
1563 | +3. No Extra Validation | |
1564 | + This is the simplest test and doesn't add any additional revalidation | |
1565 | + test, and skip therevalidatin in step 4. It is useful and improves | |
1566 | + aufs performance when system surely hide the aufs branches from user, | |
1567 | + by over-mounting something (or another method). | |
1568 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt | |
1569 | --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1570 | +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 1571 | @@ -0,0 +1,75 @@ |
53392da6 | 1572 | + |
523b37e3 | 1573 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
1574 | +# |
1575 | +# This program is free software; you can redistribute it and/or modify | |
1576 | +# it under the terms of the GNU General Public License as published by | |
1577 | +# the Free Software Foundation; either version 2 of the License, or | |
1578 | +# (at your option) any later version. | |
1579 | +# | |
1580 | +# This program is distributed in the hope that it will be useful, | |
1581 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1582 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1583 | +# GNU General Public License for more details. | |
1584 | +# | |
1585 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1586 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1587 | + |
1588 | +Branch Manipulation | |
1589 | + | |
1590 | +Since aufs supports dynamic branch manipulation, ie. add/remove a branch | |
1591 | +and changing its permission/attribute, there are a lot of works to do. | |
1592 | + | |
1593 | + | |
1594 | +Add a Branch | |
1595 | +---------------------------------------------------------------------- | |
1596 | +o Confirm the adding dir exists outside of aufs, including loopback | |
1597 | + mount. | |
1598 | +- and other various attributes... | |
1599 | +o Initialize the xino file and whiteout bases if necessary. | |
1600 | + See struct.txt. | |
1601 | + | |
1602 | +o Check the owner/group/mode of the directory | |
1603 | + When the owner/group/mode of the adding directory differs from the | |
1604 | + existing branch, aufs issues a warning because it may impose a | |
1605 | + security risk. | |
1606 | + For example, when a upper writable branch has a world writable empty | |
1607 | + top directory, a malicious user can create any files on the writable | |
1608 | + branch directly, like copy-up and modify manually. If something like | |
1609 | + /etc/{passwd,shadow} exists on the lower readonly branch but the upper | |
1610 | + writable branch, and the writable branch is world-writable, then a | |
1611 | + malicious guy may create /etc/passwd on the writable branch directly | |
1612 | + and the infected file will be valid in aufs. | |
1613 | + I am afraid it can be a security issue, but nothing to do except | |
1614 | + producing a warning. | |
1615 | + | |
1616 | + | |
1617 | +Delete a Branch | |
1618 | +---------------------------------------------------------------------- | |
1619 | +o Confirm the deleting branch is not busy | |
1620 | + To be general, there is one merit to adopt "remount" interface to | |
1621 | + manipulate branches. It is to discard caches. At deleting a branch, | |
1622 | + aufs checks the still cached (and connected) dentries and inodes. If | |
1623 | + there are any, then they are all in-use. An inode without its | |
1624 | + corresponding dentry can be alive alone (for example, inotify/fsnotify case). | |
1625 | + | |
1626 | + For the cached one, aufs checks whether the same named entry exists on | |
1627 | + other branches. | |
1628 | + If the cached one is a directory, because aufs provides a merged view | |
1629 | + to users, as long as one dir is left on any branch aufs can show the | |
1630 | + dir to users. In this case, the branch can be removed from aufs. | |
1631 | + Otherwise aufs rejects deleting the branch. | |
1632 | + | |
1633 | + If any file on the deleting branch is opened by aufs, then aufs | |
1634 | + rejects deleting. | |
1635 | + | |
1636 | + | |
1637 | +Modify the Permission of a Branch | |
1638 | +---------------------------------------------------------------------- | |
1639 | +o Re-initialize or remove the xino file and whiteout bases if necessary. | |
1640 | + See struct.txt. | |
1641 | + | |
1642 | +o rw --> ro: Confirm the modifying branch is not busy | |
1643 | + Aufs rejects the request if any of these conditions are true. | |
1644 | + - a file on the branch is mmap-ed. | |
1645 | + - a regular file on the branch is opened for write and there is no | |
1646 | + same named entry on the upper branch. | |
1647 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt | |
1648 | --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1649 | +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 1650 | @@ -0,0 +1,64 @@ |
53392da6 | 1651 | + |
523b37e3 | 1652 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
1653 | +# |
1654 | +# This program is free software; you can redistribute it and/or modify | |
1655 | +# it under the terms of the GNU General Public License as published by | |
1656 | +# the Free Software Foundation; either version 2 of the License, or | |
1657 | +# (at your option) any later version. | |
1658 | +# | |
1659 | +# This program is distributed in the hope that it will be useful, | |
1660 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1661 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1662 | +# GNU General Public License for more details. | |
1663 | +# | |
1664 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1665 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1666 | + |
1667 | +Policies to Select One among Multiple Writable Branches | |
1668 | +---------------------------------------------------------------------- | |
1669 | +When the number of writable branch is more than one, aufs has to decide | |
1670 | +the target branch for file creation or copy-up. By default, the highest | |
1671 | +writable branch which has the parent (or ancestor) dir of the target | |
1672 | +file is chosen (top-down-parent policy). | |
1673 | +By user's request, aufs implements some other policies to select the | |
1674 | +writable branch, for file creation two policies, round-robin and | |
1675 | +most-free-space policies. For copy-up three policies, top-down-parent, | |
1676 | +bottom-up-parent and bottom-up policies. | |
1677 | + | |
1678 | +As expected, the round-robin policy selects the branch in circular. When | |
1679 | +you have two writable branches and creates 10 new files, 5 files will be | |
1680 | +created for each branch. mkdir(2) systemcall is an exception. When you | |
1681 | +create 10 new directories, all will be created on the same branch. | |
1682 | +And the most-free-space policy selects the one which has most free | |
1683 | +space among the writable branches. The amount of free space will be | |
1684 | +checked by aufs internally, and users can specify its time interval. | |
1685 | + | |
1686 | +The policies for copy-up is more simple, | |
1687 | +top-down-parent is equivalent to the same named on in create policy, | |
1688 | +bottom-up-parent selects the writable branch where the parent dir | |
1689 | +exists and the nearest upper one from the copyup-source, | |
1690 | +bottom-up selects the nearest upper writable branch from the | |
1691 | +copyup-source, regardless the existence of the parent dir. | |
1692 | + | |
1693 | +There are some rules or exceptions to apply these policies. | |
1694 | +- If there is a readonly branch above the policy-selected branch and | |
1695 | + the parent dir is marked as opaque (a variation of whiteout), or the | |
1696 | + target (creating) file is whiteout-ed on the upper readonly branch, | |
1697 | + then the result of the policy is ignored and the target file will be | |
1698 | + created on the nearest upper writable branch than the readonly branch. | |
1699 | +- If there is a writable branch above the policy-selected branch and | |
1700 | + the parent dir is marked as opaque or the target file is whiteouted | |
1701 | + on the branch, then the result of the policy is ignored and the target | |
1702 | + file will be created on the highest one among the upper writable | |
1703 | + branches who has diropq or whiteout. In case of whiteout, aufs removes | |
1704 | + it as usual. | |
1705 | +- link(2) and rename(2) systemcalls are exceptions in every policy. | |
1706 | + They try selecting the branch where the source exists as possible | |
1707 | + since copyup a large file will take long time. If it can't be, | |
1708 | + ie. the branch where the source exists is readonly, then they will | |
1709 | + follow the copyup policy. | |
1710 | +- There is an exception for rename(2) when the target exists. | |
1711 | + If the rename target exists, aufs compares the index of the branches | |
1712 | + where the source and the target exists and selects the higher | |
1713 | + one. If the selected branch is readonly, then aufs follows the | |
1714 | + copyup policy. | |
076b876e AM |
1715 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt |
1716 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1717 | +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-01-25 13:00:38.627713742 +0100 |
076b876e AM |
1718 | @@ -0,0 +1,120 @@ |
1719 | + | |
1720 | +# Copyright (C) 2011-2014 Junjiro R. Okajima | |
1721 | +# | |
1722 | +# This program is free software; you can redistribute it and/or modify | |
1723 | +# it under the terms of the GNU General Public License as published by | |
1724 | +# the Free Software Foundation; either version 2 of the License, or | |
1725 | +# (at your option) any later version. | |
1726 | +# | |
1727 | +# This program is distributed in the hope that it will be useful, | |
1728 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1729 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1730 | +# GNU General Public License for more details. | |
1731 | +# | |
1732 | +# You should have received a copy of the GNU General Public License | |
1733 | +# along with this program; if not, write to the Free Software | |
1734 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1735 | + | |
1736 | + | |
1737 | +File-based Hierarchical Storage Management (FHSM) | |
1738 | +---------------------------------------------------------------------- | |
1739 | +Hierarchical Storage Management (or HSM) is a well-known feature in the | |
1740 | +storage world. Aufs provides this feature as file-based with multiple | |
1741 | +writable branches, based upon the principle of "Colder-Lower". | |
1742 | +Here the word "colder" means that the less used files, and "lower" means | |
1743 | +that the position in the order of the stacked branches. | |
1744 | +These multiple writable branches are prioritized, ie. the topmost one | |
1745 | +should be the fastest drive and be used heavily. | |
1746 | + | |
1747 | +o Characters in aufs FHSM story | |
1748 | +- aufs itself and a new branch attribute. | |
1749 | +- a new ioctl interface to move-down and to establish a connection with | |
1750 | + the daemon ("move-down" is a converse of "copy-up"). | |
1751 | +- userspace tool and daemon. | |
1752 | + | |
1753 | +The userspace daemon establishes a connection with aufs and waits for | |
1754 | +the notification. The notified information is very similar to struct | |
1755 | +statfs containing the number of consumed blocks and inodes. | |
1756 | +When the consumed blocks/inodes of a branch exceeds the user-specified | |
1757 | +upper watermark, the daemon activates its move-down process until the | |
1758 | +consumed blocks/inodes reaches the user-specified lower watermark. | |
1759 | + | |
1760 | +The actual move-down is done by aufs based upon the request from | |
1761 | +user-space since we need to maintain the inode number and the internal | |
1762 | +pointer arrays in aufs. | |
1763 | + | |
1764 | +Currently aufs FHSM handles the regular files only. Additionally they | |
1765 | +must not be hard-linked nor pseudo-linked. | |
1766 | + | |
1767 | + | |
1768 | +o Cowork of aufs and the user-space daemon | |
1769 | + During the userspace daemon established the connection, aufs sends a | |
1770 | + small notification to it whenever aufs writes something into the | |
1771 | + writable branch. But it may cost high since aufs issues statfs(2) | |
1772 | + internally. So user can specify a new option to cache the | |
1773 | + info. Actually the notification is controlled by these factors. | |
1774 | + + the specified cache time. | |
1775 | + + classified as "force" by aufs internally. | |
1776 | + Until the specified time expires, aufs doesn't send the info | |
1777 | + except the forced cases. When aufs decide forcing, the info is always | |
1778 | + notified to userspace. | |
1779 | + For example, the number of free inodes is generally large enough and | |
1780 | + the shortage of it happens rarely. So aufs doesn't force the | |
1781 | + notification when creating a new file, directory and others. This is | |
1782 | + the typical case which aufs doesn't force. | |
1783 | + When aufs writes the actual filedata and the files consumes any of new | |
1784 | + blocks, the aufs forces notifying. | |
1785 | + | |
1786 | + | |
1787 | +o Interfaces in aufs | |
1788 | +- New branch attribute. | |
1789 | + + fhsm | |
1790 | + Specifies that the branch is managed by FHSM feature. In other word, | |
1791 | + participant in the FHSM. | |
1792 | + When nofhsm is set to the branch, it will not be the source/target | |
1793 | + branch of the move-down operation. This attribute is set | |
1794 | + independently from coo and moo attributes, and if you want full | |
1795 | + FHSM, you should specify them as well. | |
1796 | +- New mount option. | |
1797 | + + fhsm_sec | |
1798 | + Specifies a second to suppress many less important info to be | |
1799 | + notified. | |
1800 | +- New ioctl. | |
1801 | + + AUFS_CTL_FHSM_FD | |
1802 | + create a new file descriptor which userspace can read the notification | |
1803 | + (a subset of struct statfs) from aufs. | |
1804 | +- Module parameter 'brs' | |
1805 | + It has to be set to 1. Otherwise the new mount option 'fhsm' will not | |
1806 | + be set. | |
1807 | +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs | |
1808 | + When there are two or more branches with fhsm attributes, | |
1809 | + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs | |
1810 | + terminates it. As a result of remounting and branch-manipulation, the | |
1811 | + number of branches with fhsm attribute can be one. In this case, | |
1812 | + /sbin/mount.aufs will terminate the user-space daemon. | |
1813 | + | |
1814 | + | |
1815 | +Finally the operation is done as these steps in kernel-space. | |
1816 | +- make sure that, | |
1817 | + + no one else is using the file. | |
1818 | + + the file is not hard-linked. | |
1819 | + + the file is not pseudo-linked. | |
1820 | + + the file is a regular file. | |
1821 | + + the parent dir is not opaqued. | |
1822 | +- find the target writable branch. | |
1823 | +- make sure the file is not whiteout-ed by the upper (than the target) | |
1824 | + branch. | |
1825 | +- make the parent dir on the target branch. | |
1826 | +- mutex lock the inode on the branch. | |
1827 | +- unlink the whiteout on the target branch (if exists). | |
1828 | +- lookup and create the whiteout-ed temporary name on the target branch. | |
1829 | +- copy the file as the whiteout-ed temporary name on the target branch. | |
1830 | +- rename the whiteout-ed temporary name to the original name. | |
1831 | +- unlink the file on the source branch. | |
1832 | +- maintain the internal pointer array and the external inode number | |
1833 | + table (XINO). | |
1834 | +- maintain the timestamps and other attributes of the parent dir and the | |
1835 | + file. | |
1836 | + | |
1837 | +And of course, in every step, an error may happen. So the operation | |
1838 | +should restore the original file state after an error happens. | |
53392da6 AM |
1839 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt |
1840 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1841 | +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 1842 | @@ -0,0 +1,46 @@ |
53392da6 | 1843 | + |
523b37e3 | 1844 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
1845 | +# |
1846 | +# This program is free software; you can redistribute it and/or modify | |
1847 | +# it under the terms of the GNU General Public License as published by | |
1848 | +# the Free Software Foundation; either version 2 of the License, or | |
1849 | +# (at your option) any later version. | |
1850 | +# | |
1851 | +# This program is distributed in the hope that it will be useful, | |
1852 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1853 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1854 | +# GNU General Public License for more details. | |
1855 | +# | |
1856 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1857 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1858 | + |
1859 | +mmap(2) -- File Memory Mapping | |
1860 | +---------------------------------------------------------------------- | |
1861 | +In aufs, the file-mapped pages are handled by a branch fs directly, no | |
1862 | +interaction with aufs. It means aufs_mmap() calls the branch fs's | |
1863 | +->mmap(). | |
1864 | +This approach is simple and good, but there is one problem. | |
1865 | +Under /proc, several entries show the mmap-ped files by its path (with | |
1866 | +device and inode number), and the printed path will be the path on the | |
1867 | +branch fs's instead of virtual aufs's. | |
1868 | +This is not a problem in most cases, but some utilities lsof(1) (and its | |
1869 | +user) may expect the path on aufs. | |
1870 | + | |
1871 | +To address this issue, aufs adds a new member called vm_prfile in struct | |
1872 | +vm_area_struct (and struct vm_region). The original vm_file points to | |
1873 | +the file on the branch fs in order to handle everything correctly as | |
1874 | +usual. The new vm_prfile points to a virtual file in aufs, and the | |
1875 | +show-functions in procfs refers to vm_prfile if it is set. | |
1876 | +Also we need to maintain several other places where touching vm_file | |
1877 | +such like | |
1878 | +- fork()/clone() copies vma and the reference count of vm_file is | |
1879 | + incremented. | |
1880 | +- merging vma maintains the ref count too. | |
1881 | + | |
1882 | +This is not a good approach. It just faking the printed path. But it | |
1883 | +leaves all behaviour around f_mapping unchanged. This is surely an | |
1884 | +advantage. | |
1885 | +Actually aufs had adopted another complicated approach which calls | |
1886 | +generic_file_mmap() and handles struct vm_operations_struct. In this | |
1887 | +approach, aufs met a hard problem and I could not solve it without | |
1888 | +switching the approach. | |
c1595e42 JR |
1889 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt |
1890 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100 | |
1891 | +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-01-25 13:00:38.627713742 +0100 | |
1892 | @@ -0,0 +1,96 @@ | |
1893 | + | |
1894 | +# Copyright (C) 2014 Junjiro R. Okajima | |
1895 | +# | |
1896 | +# This program is free software; you can redistribute it and/or modify | |
1897 | +# it under the terms of the GNU General Public License as published by | |
1898 | +# the Free Software Foundation; either version 2 of the License, or | |
1899 | +# (at your option) any later version. | |
1900 | +# | |
1901 | +# This program is distributed in the hope that it will be useful, | |
1902 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1903 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1904 | +# GNU General Public License for more details. | |
1905 | +# | |
1906 | +# You should have received a copy of the GNU General Public License | |
1907 | +# along with this program; if not, write to the Free Software | |
1908 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1909 | + | |
1910 | + | |
1911 | +Listing XATTR/EA and getting the value | |
1912 | +---------------------------------------------------------------------- | |
1913 | +For the inode standard attributes (owner, group, timestamps, etc.), aufs | |
1914 | +shows the values from the topmost existing file. This behaviour is good | |
1915 | +for the non-dir entreis since the bahaviour exactly matches the shown | |
1916 | +information. But for the directories, aufs considers all the same named | |
1917 | +entries on the lower branches. Which means, if one of the lower entry | |
1918 | +rejects readdir call, then aufs returns an error even if the topmost | |
1919 | +entry allows it. This behaviour is necessary to respect the branch fs's | |
1920 | +security, but can make users confused since the user-visible standard | |
1921 | +attributes don't match the behaviour. | |
1922 | +To address this issue, aufs has a mount option called dirperm1 which | |
1923 | +checks the permission for the topmost entry only, and ignores the lower | |
1924 | +entry's permission. | |
1925 | + | |
1926 | +A similar issue can happen around XATTR. | |
1927 | +getxattr(2) and listxattr(2) families behave as if dirperm1 option is | |
1928 | +always set. Otherwise these very unpleasant situation can happen. | |
1929 | +- listxattr(2) may return the duplicated entires. | |
1930 | +- users may not be able to remove or reset the XATTR forever, | |
1931 | + | |
1932 | + | |
1933 | +XATTR/EA support in the internal (copy,move)-(up,down) | |
1934 | +---------------------------------------------------------------------- | |
1935 | +Generally the extended attributes of inode are categorazied as these. | |
1936 | +- "security" for LSM and capability. | |
1937 | +- "system" for posix ACL, 'acl' mount option is required for the branch | |
1938 | + fs generally. | |
1939 | +- "trusted" for userspace, CAP_SYS_ADMIN is required. | |
1940 | +- "user" for userspace, 'user_xattr' mount option is required for the | |
1941 | + branch fs generally. | |
1942 | + | |
1943 | +Moreover there are some other categories. Aufs handles these rather | |
1944 | +unpopular categories as the ordinary ones, ie. there is no special | |
1945 | +condition nor exception. | |
1946 | + | |
1947 | +In copy-up, the support for XATTR on the dst branch may differ from the | |
1948 | +src branch. In this case, the copy-up operation will get an error and | |
1949 | +the original user operation which triggered the copy-up fails. It can | |
1950 | +happen that even all copy-up will fail. | |
1951 | +When both of src and dst branches support XATTR and if an error occurs | |
1952 | +during copying XATTR, then the copy-up should fail obviously. That is a | |
1953 | +good reason and aufs should return an error to userspace. But when only | |
1954 | +the src branch support XATTR, aufs should not return an error. | |
1955 | +For example, the src branch supports ACL but the dst branch doesn't | |
1956 | +because the dst branch may natively un-support it or temporary | |
1957 | +un-support it due to "noacl" mount option. Of course, the dst branch fs | |
1958 | +may NOT return an error even if the XATTR is not supported. It is | |
1959 | +totally up to the branch fs. | |
1960 | + | |
1961 | +Anyway when the aufs internal copy-up gets an error from the dst branch | |
1962 | +fs, then aufs tries removing the just copied entry and returns the error | |
1963 | +to the userspace. The worst case of this situation will be all copy-up | |
1964 | +will fail. | |
1965 | + | |
1966 | +For the copy-up operation, there two basic approaches. | |
1967 | +- copy the specified XATTR only (by category above), and return the | |
1968 | + error if it happens inconditionally. | |
1969 | +- copy all XATTR, and ignore the error on the specified category only. | |
1970 | + | |
1971 | +In order to support XATTR and to implement the correct behaviour, aufs | |
1972 | +chooses the latter approach and introduces some attributes for its | |
1973 | +branch, "icexsec", "icexsys", "icextr", "icexusr", and "icexoth". | |
1974 | +They correspond to the XATTR namespaces (see above). Additionally, to be | |
1975 | +convenient, "icex" is also provided which means all "ix*" attributes are | |
1976 | +set. | |
1977 | + | |
1978 | +The meaning of these attributes is to ignore the error from setting | |
1979 | +XATTR on that branch. | |
1980 | +Note that aufs tries copying all XATTR unconditionally, and ignores the | |
1981 | +error from the dst branch according to the specified attributes. | |
1982 | + | |
1983 | +Some XATTR may have its default value. The default value may come from | |
1984 | +the parent dir or the environment. If the default value is set at the | |
1985 | +file creating-time, it will be overwritten by copy-up. | |
1986 | +Some contradiction may happen I am afraid. | |
1987 | +Do we need another attribute to stop copying XATTR? I am unsure. For | |
1988 | +now, aufs implements the branch attributes to ignore the error. | |
53392da6 AM |
1989 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt |
1990 | --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 1991 | +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 1992 | @@ -0,0 +1,58 @@ |
53392da6 | 1993 | + |
523b37e3 | 1994 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
1995 | +# |
1996 | +# This program is free software; you can redistribute it and/or modify | |
1997 | +# it under the terms of the GNU General Public License as published by | |
1998 | +# the Free Software Foundation; either version 2 of the License, or | |
1999 | +# (at your option) any later version. | |
2000 | +# | |
2001 | +# This program is distributed in the hope that it will be useful, | |
2002 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2003 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2004 | +# GNU General Public License for more details. | |
2005 | +# | |
2006 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2007 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2008 | + |
2009 | +Export Aufs via NFS | |
2010 | +---------------------------------------------------------------------- | |
2011 | +Here is an approach. | |
2012 | +- like xino/xib, add a new file 'xigen' which stores aufs inode | |
2013 | + generation. | |
2014 | +- iget_locked(): initialize aufs inode generation for a new inode, and | |
2015 | + store it in xigen file. | |
2016 | +- destroy_inode(): increment aufs inode generation and store it in xigen | |
2017 | + file. it is necessary even if it is not unlinked, because any data of | |
2018 | + inode may be changed by UDBA. | |
2019 | +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise | |
2020 | + build file handle by | |
2021 | + + branch id (4 bytes) | |
2022 | + + superblock generation (4 bytes) | |
2023 | + + inode number (4 or 8 bytes) | |
2024 | + + parent dir inode number (4 or 8 bytes) | |
2025 | + + inode generation (4 bytes)) | |
2026 | + + return value of exportfs_encode_fh() for the parent on a branch (4 | |
2027 | + bytes) | |
2028 | + + file handle for a branch (by exportfs_encode_fh()) | |
2029 | +- fh_to_dentry(): | |
2030 | + + find the index of a branch from its id in handle, and check it is | |
2031 | + still exist in aufs. | |
2032 | + + 1st level: get the inode number from handle and search it in cache. | |
2033 | + + 2nd level: if not found, get the parent inode number from handle and | |
2034 | + search it in cache. and then open the parent dir, find the matching | |
2035 | + inode number by vfs_readdir() and get its name, and call | |
2036 | + lookup_one_len() for the target dentry. | |
2037 | + + 3rd level: if the parent dir is not cached, call | |
2038 | + exportfs_decode_fh() for a branch and get the parent on a branch, | |
2039 | + build a pathname of it, convert it a pathname in aufs, call | |
2040 | + path_lookup(). now aufs gets a parent dir dentry, then handle it as | |
2041 | + the 2nd level. | |
2042 | + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount | |
2043 | + for every branch, but not itself. to get this, (currently) aufs | |
2044 | + searches in current->nsproxy->mnt_ns list. it may not be a good | |
2045 | + idea, but I didn't get other approach. | |
2046 | + + test the generation of the gotten inode. | |
2047 | +- every inode operation: they may get EBUSY due to UDBA. in this case, | |
2048 | + convert it into ESTALE for NFSD. | |
2049 | +- readdir(): call lockdep_on/off() because filldir in NFSD calls | |
2050 | + lookup_one_len(), vfs_getattr(), encode_fh() and others. | |
2051 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt | |
2052 | --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 2053 | +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 2054 | @@ -0,0 +1,52 @@ |
53392da6 | 2055 | + |
523b37e3 | 2056 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
2057 | +# |
2058 | +# This program is free software; you can redistribute it and/or modify | |
2059 | +# it under the terms of the GNU General Public License as published by | |
2060 | +# the Free Software Foundation; either version 2 of the License, or | |
2061 | +# (at your option) any later version. | |
2062 | +# | |
2063 | +# This program is distributed in the hope that it will be useful, | |
2064 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2065 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2066 | +# GNU General Public License for more details. | |
2067 | +# | |
2068 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2069 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2070 | + |
2071 | +Show Whiteout Mode (shwh) | |
2072 | +---------------------------------------------------------------------- | |
2073 | +Generally aufs hides the name of whiteouts. But in some cases, to show | |
2074 | +them is very useful for users. For instance, creating a new middle layer | |
2075 | +(branch) by merging existing layers. | |
2076 | + | |
2077 | +(borrowing aufs1 HOW-TO from a user, Michael Towers) | |
2078 | +When you have three branches, | |
2079 | +- Bottom: 'system', squashfs (underlying base system), read-only | |
2080 | +- Middle: 'mods', squashfs, read-only | |
2081 | +- Top: 'overlay', ram (tmpfs), read-write | |
2082 | + | |
2083 | +The top layer is loaded at boot time and saved at shutdown, to preserve | |
2084 | +the changes made to the system during the session. | |
2085 | +When larger changes have been made, or smaller changes have accumulated, | |
2086 | +the size of the saved top layer data grows. At this point, it would be | |
2087 | +nice to be able to merge the two overlay branches ('mods' and 'overlay') | |
2088 | +and rewrite the 'mods' squashfs, clearing the top layer and thus | |
2089 | +restoring save and load speed. | |
2090 | + | |
2091 | +This merging is simplified by the use of another aufs mount, of just the | |
2092 | +two overlay branches using the 'shwh' option. | |
2093 | +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \ | |
2094 | + aufs /livesys/merge_union | |
2095 | + | |
2096 | +A merged view of these two branches is then available at | |
2097 | +/livesys/merge_union, and the new feature is that the whiteouts are | |
2098 | +visible! | |
2099 | +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable | |
2100 | +writing to all branches. Also the default mode for all branches is 'ro'. | |
2101 | +It is now possible to save the combined contents of the two overlay | |
2102 | +branches to a new squashfs, e.g.: | |
2103 | +# mksquashfs /livesys/merge_union /path/to/newmods.squash | |
2104 | + | |
2105 | +This new squashfs archive can be stored on the boot device and the | |
2106 | +initramfs will use it to replace the old one at the next boot. | |
2107 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt | |
2108 | --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 2109 | +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 2110 | @@ -0,0 +1,46 @@ |
53392da6 | 2111 | + |
523b37e3 | 2112 | +# Copyright (C) 2010-2014 Junjiro R. Okajima |
53392da6 AM |
2113 | +# |
2114 | +# This program is free software; you can redistribute it and/or modify | |
2115 | +# it under the terms of the GNU General Public License as published by | |
2116 | +# the Free Software Foundation; either version 2 of the License, or | |
2117 | +# (at your option) any later version. | |
2118 | +# | |
2119 | +# This program is distributed in the hope that it will be useful, | |
2120 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2121 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2122 | +# GNU General Public License for more details. | |
2123 | +# | |
2124 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2125 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2126 | + |
2127 | +Dynamically customizable FS operations | |
2128 | +---------------------------------------------------------------------- | |
2129 | +Generally FS operations (struct inode_operations, struct | |
2130 | +address_space_operations, struct file_operations, etc.) are defined as | |
2131 | +"static const", but it never means that FS have only one set of | |
2132 | +operation. Some FS have multiple sets of them. For instance, ext2 has | |
2133 | +three sets, one for XIP, for NOBH, and for normal. | |
2134 | +Since aufs overrides and redirects these operations, sometimes aufs has | |
2135 | +to change its behaviour according to the branch FS type. More imporantly | |
2136 | +VFS acts differently if a function (member in the struct) is set or | |
2137 | +not. It means aufs should have several sets of operations and select one | |
2138 | +among them according to the branch FS definition. | |
2139 | + | |
2140 | +In order to solve this problem and not to affect the behavour of VFS, | |
2141 | +aufs defines these operations dynamically. For instance, aufs defines | |
2142 | +aio_read function for struct file_operations, but it may not be set to | |
2143 | +the file_operations. When the branch FS doesn't have it, aufs doesn't | |
2144 | +set it to its file_operations while the function definition itself is | |
2145 | +still alive. So the behaviour of io_submit(2) will not change, and it | |
2146 | +will return an error when aio_read is not defined. | |
2147 | + | |
2148 | +The lifetime of these dynamically generated operation object is | |
2149 | +maintained by aufs branch object. When the branch is removed from aufs, | |
2150 | +the reference counter of the object is decremented. When it reaches | |
2151 | +zero, the dynamically generated operation object will be freed. | |
2152 | + | |
2153 | +This approach is designed to support AIO (io_submit), Direcit I/O and | |
2154 | +XIP mainly. | |
2155 | +Currently this approach is applied to file_operations and | |
2156 | +vm_operations_struct for regular files only. | |
2157 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt | |
2158 | --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 2159 | +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2015-01-25 13:00:38.627713742 +0100 |
076b876e | 2160 | @@ -0,0 +1,58 @@ |
53392da6 | 2161 | + |
523b37e3 | 2162 | +# Copyright (C) 2005-2014 Junjiro R. Okajima |
53392da6 AM |
2163 | +# |
2164 | +# This program is free software; you can redistribute it and/or modify | |
2165 | +# it under the terms of the GNU General Public License as published by | |
2166 | +# the Free Software Foundation; either version 2 of the License, or | |
2167 | +# (at your option) any later version. | |
2168 | +# | |
2169 | +# This program is distributed in the hope that it will be useful, | |
2170 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2171 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2172 | +# GNU General Public License for more details. | |
2173 | +# | |
2174 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2175 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2176 | + |
2177 | +Plan | |
2178 | + | |
2179 | +Restoring some features which was implemented in aufs1. | |
2180 | +They were dropped in aufs2 in order to make source files simpler and | |
2181 | +easier to be reviewed. | |
2182 | + | |
2183 | + | |
53392da6 AM |
2184 | +Being Another Aufs's Readonly Branch (robr) |
2185 | +---------------------------------------------------------------------- | |
2186 | +Aufs1 allows aufs to be another aufs's readonly branch. | |
2187 | +This feature was developed by a user's request. But it may not be used | |
2188 | +currecnly. | |
2189 | + | |
2190 | + | |
53392da6 AM |
2191 | +Refresh the Opened File (refrof) |
2192 | +---------------------------------------------------------------------- | |
2193 | +This option is implemented in aufs1 but incomplete. | |
2194 | + | |
2195 | +When user reads from a file, he expects to get its latest filedata | |
2196 | +generally. If the file is removed and a new same named file is created, | |
2197 | +the content he gets is unchanged, ie. the unlinked filedata. | |
2198 | + | |
2199 | +Let's try case study again. | |
2200 | +- aufs has two branches. | |
2201 | + /au = /rw + /ro | |
2202 | +- "fileA" exists under /ro, but /rw. | |
2203 | +- user opened "/au/fileA". | |
2204 | +- he or someone else inserts a branch (/new) between /rw and /ro. | |
2205 | + /au = /rw + /new + /ro | |
2206 | +- the new branch has "fileA". | |
2207 | +- user reads from the opened "fileA" | |
2208 | +- which filedata should aufs return, from /ro or /new? | |
2209 | + | |
2210 | +Some people says it has to be "from /ro" and it is a semantics of Unix. | |
2211 | +The others say it should be "from /new" because the file is not removed | |
2212 | +and it is equivalent to the case of someone else modifies the file. | |
2213 | + | |
2214 | +Here again I don't have a best and final answer. I got an idea to | |
2215 | +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the | |
2216 | +Opened File) is specified (by default), aufs returns the filedata from | |
2217 | +/new. | |
2218 | +Otherwise from /new. | |
2219 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README | |
2220 | --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 2221 | +++ linux/Documentation/filesystems/aufs/README 2015-01-25 13:00:38.627713742 +0100 |
076b876e | 2222 | @@ -0,0 +1,370 @@ |
53392da6 AM |
2223 | + |
2224 | +Aufs3 -- advanced multi layered unification filesystem version 3.x | |
2225 | +http://aufs.sf.net | |
2226 | +Junjiro R. Okajima | |
2227 | + | |
2228 | + | |
2229 | +0. Introduction | |
2230 | +---------------------------------------- | |
2231 | +In the early days, aufs was entirely re-designed and re-implemented | |
2232 | +Unionfs Version 1.x series. After many original ideas, approaches, | |
2233 | +improvements and implementations, it becomes totally different from | |
2234 | +Unionfs while keeping the basic features. | |
2235 | +Recently, Unionfs Version 2.x series begin taking some of the same | |
2236 | +approaches to aufs1's. | |
2237 | +Unionfs is being developed by Professor Erez Zadok at Stony Brook | |
2238 | +University and his team. | |
2239 | + | |
2240 | +Aufs3 supports linux-3.0 and later. | |
2241 | +If you want older kernel version support, try aufs2-2.6.git or | |
2242 | +aufs2-standalone.git repository, aufs1 from CVS on SourceForge. | |
2243 | + | |
2244 | +Note: it becomes clear that "Aufs was rejected. Let's give it up." | |
38d290e6 JR |
2245 | + According to Christoph Hellwig, linux rejects all union-type |
2246 | + filesystems but UnionMount. | |
53392da6 AM |
2247 | +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2> |
2248 | + | |
38d290e6 JR |
2249 | +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and |
2250 | + UnionMount, and he pointed out an issue around a directory mutex | |
2251 | + lock and aufs addressed it. But it is still unsure whether aufs will | |
2252 | + be merged (or any other union solution). | |
076b876e | 2253 | +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1> |
38d290e6 | 2254 | + |
53392da6 AM |
2255 | + |
2256 | +1. Features | |
2257 | +---------------------------------------- | |
2258 | +- unite several directories into a single virtual filesystem. The member | |
2259 | + directory is called as a branch. | |
2260 | +- you can specify the permission flags to the branch, which are 'readonly', | |
2261 | + 'readwrite' and 'whiteout-able.' | |
2262 | +- by upper writable branch, internal copyup and whiteout, files/dirs on | |
2263 | + readonly branch are modifiable logically. | |
2264 | +- dynamic branch manipulation, add, del. | |
2265 | +- etc... | |
2266 | + | |
2267 | +Also there are many enhancements in aufs1, such as: | |
2268 | +- readdir(3) in userspace. | |
2269 | +- keep inode number by external inode number table | |
2270 | +- keep the timestamps of file/dir in internal copyup operation | |
2271 | +- seekable directory, supporting NFS readdir. | |
2272 | +- whiteout is hardlinked in order to reduce the consumption of inodes | |
2273 | + on branch | |
2274 | +- do not copyup, nor create a whiteout when it is unnecessary | |
2275 | +- revert a single systemcall when an error occurs in aufs | |
2276 | +- remount interface instead of ioctl | |
2277 | +- maintain /etc/mtab by an external command, /sbin/mount.aufs. | |
2278 | +- loopback mounted filesystem as a branch | |
2279 | +- kernel thread for removing the dir who has a plenty of whiteouts | |
2280 | +- support copyup sparse file (a file which has a 'hole' in it) | |
2281 | +- default permission flags for branches | |
2282 | +- selectable permission flags for ro branch, whether whiteout can | |
2283 | + exist or not | |
2284 | +- export via NFS. | |
2285 | +- support <sysfs>/fs/aufs and <debugfs>/aufs. | |
2286 | +- support multiple writable branches, some policies to select one | |
2287 | + among multiple writable branches. | |
2288 | +- a new semantics for link(2) and rename(2) to support multiple | |
2289 | + writable branches. | |
2290 | +- no glibc changes are required. | |
2291 | +- pseudo hardlink (hardlink over branches) | |
2292 | +- allow a direct access manually to a file on branch, e.g. bypassing aufs. | |
2293 | + including NFS or remote filesystem branch. | |
2294 | +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX. | |
2295 | +- and more... | |
2296 | + | |
2297 | +Currently these features are dropped temporary from aufs3. | |
2298 | +See design/08plan.txt in detail. | |
2299 | +- test only the highest one for the directory permission (dirperm1) | |
2300 | +- copyup on open (coo=) | |
2301 | +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs | |
2302 | + (robr) | |
2303 | +- statistics of aufs thread (/sys/fs/aufs/stat) | |
2304 | +- delegation mode (dlgt) | |
2305 | + a delegation of the internal branch access to support task I/O | |
2306 | + accounting, which also supports Linux Security Modules (LSM) mainly | |
2307 | + for Suse AppArmor. | |
2308 | +- intent.open/create (file open in a single lookup) | |
2309 | + | |
2310 | +Features or just an idea in the future (see also design/*.txt), | |
2311 | +- reorder the branch index without del/re-add. | |
2312 | +- permanent xino files for NFSD | |
2313 | +- an option for refreshing the opened files after add/del branches | |
2314 | +- 'move' policy for copy-up between two writable branches, after | |
2315 | + checking free space. | |
2316 | +- light version, without branch manipulation. (unnecessary?) | |
2317 | +- copyup in userspace | |
2318 | +- inotify in userspace | |
2319 | +- readv/writev | |
2320 | +- xattr, acl | |
2321 | + | |
2322 | + | |
2323 | +2. Download | |
2324 | +---------------------------------------- | |
1e00d052 AM |
2325 | +There were three GIT trees for aufs3, aufs3-linux.git, |
2326 | +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in | |
2327 | +"aufs-util.git." | |
2328 | +While the aufs-util is always necessary, you need either of aufs3-linux | |
2329 | +or aufs3-standalone. | |
2330 | + | |
2331 | +The aufs3-linux tree includes the whole linux mainline GIT tree, | |
2332 | +git://git.kernel.org/.../torvalds/linux.git. | |
2333 | +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot | |
b4510431 | 2334 | +build aufs3 as an external kernel module. |
1e00d052 AM |
2335 | + |
2336 | +On the other hand, the aufs3-standalone tree has only aufs source files | |
53392da6 AM |
2337 | +and necessary patches, and you can select CONFIG_AUFS_FS=m. |
2338 | + | |
2339 | +You will find GIT branches whose name is in form of "aufs3.x" where "x" | |
2340 | +represents the linux kernel version, "linux-3.x". For instance, | |
1e00d052 AM |
2341 | +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use |
2342 | +"aufs3.x-rcN" branch. | |
2343 | + | |
2344 | +o aufs3-linux tree | |
2345 | +$ git clone --reference /your/linux/git/tree \ | |
86dc4139 | 2346 | + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \ |
1e00d052 AM |
2347 | + aufs3-linux.git |
2348 | +- if you don't have linux GIT tree, then remove "--reference ..." | |
2349 | +$ cd aufs3-linux.git | |
2350 | +$ git checkout origin/aufs3.0 | |
53392da6 AM |
2351 | + |
2352 | +o aufs3-standalone tree | |
86dc4139 | 2353 | +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \ |
53392da6 AM |
2354 | + aufs3-standalone.git |
2355 | +$ cd aufs3-standalone.git | |
2356 | +$ git checkout origin/aufs3.0 | |
2357 | + | |
2358 | +o aufs-util tree | |
86dc4139 | 2359 | +$ git clone git://git.code.sf.net/p/aufs/aufs-util \ |
53392da6 AM |
2360 | + aufs-util.git |
2361 | +$ cd aufs-util.git | |
2362 | +$ git checkout origin/aufs3.0 | |
2363 | + | |
9dbd164d AM |
2364 | +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY. |
2365 | +The minor version number, 'x' in '3.x', of aufs may not always | |
2366 | +follow the minor version number of the kernel. | |
2367 | +Because changes in the kernel that cause the use of a new | |
2368 | +minor version number do not always require changes to aufs-util. | |
2369 | + | |
2370 | +Since aufs-util has its own minor version number, you may not be | |
2371 | +able to find a GIT branch in aufs-util for your kernel's | |
2372 | +exact minor version number. | |
2373 | +In this case, you should git-checkout the branch for the | |
53392da6 | 2374 | +nearest lower number. |
9dbd164d AM |
2375 | + |
2376 | +For (an unreleased) example: | |
2377 | +If you are using "linux-3.10" and the "aufs3.10" branch | |
7eafdf33 | 2378 | +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8" |
9dbd164d AM |
2379 | +or something numerically smaller is the branch for your kernel. |
2380 | + | |
53392da6 AM |
2381 | +Also you can view all branches by |
2382 | + $ git branch -a | |
2383 | + | |
2384 | + | |
2385 | +3. Configuration and Compilation | |
2386 | +---------------------------------------- | |
2387 | +Make sure you have git-checkout'ed the correct branch. | |
2388 | + | |
1e00d052 | 2389 | +For aufs3-linux tree, |
c06a8ce3 | 2390 | +- enable CONFIG_AUFS_FS. |
1e00d052 AM |
2391 | +- set other aufs configurations if necessary. |
2392 | + | |
53392da6 AM |
2393 | +For aufs3-standalone tree, |
2394 | +There are several ways to build. | |
2395 | + | |
2396 | +1. | |
2397 | +- apply ./aufs3-kbuild.patch to your kernel source files. | |
2398 | +- apply ./aufs3-base.patch too. | |
523b37e3 | 2399 | +- apply ./aufs3-mmap.patch too. |
53392da6 AM |
2400 | +- apply ./aufs3-standalone.patch too, if you have a plan to set |
2401 | + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch. | |
537831f9 AM |
2402 | +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your |
2403 | + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild. | |
c06a8ce3 | 2404 | +- enable CONFIG_AUFS_FS, you can select either |
53392da6 AM |
2405 | + =m or =y. |
2406 | +- and build your kernel as usual. | |
2407 | +- install the built kernel. | |
c06a8ce3 AM |
2408 | + Note: Since linux-3.9, every filesystem module requires an alias |
2409 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2410 | + modules.aliases file if you set CONFIG_AUFS_FS=m. | |
7eafdf33 AM |
2411 | +- install the header files too by "make headers_install" to the |
2412 | + directory where you specify. By default, it is $PWD/usr. | |
b4510431 | 2413 | + "make help" shows a brief note for headers_install. |
53392da6 AM |
2414 | +- and reboot your system. |
2415 | + | |
2416 | +2. | |
2417 | +- module only (CONFIG_AUFS_FS=m). | |
2418 | +- apply ./aufs3-base.patch to your kernel source files. | |
523b37e3 | 2419 | +- apply ./aufs3-mmap.patch too. |
53392da6 AM |
2420 | +- apply ./aufs3-standalone.patch too. |
2421 | +- build your kernel, don't forget "make headers_install", and reboot. | |
2422 | +- edit ./config.mk and set other aufs configurations if necessary. | |
b4510431 | 2423 | + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes |
53392da6 AM |
2424 | + every aufs configurations. |
2425 | +- build the module by simple "make". | |
c06a8ce3 AM |
2426 | + Note: Since linux-3.9, every filesystem module requires an alias |
2427 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2428 | + modules.aliases file. | |
53392da6 AM |
2429 | +- you can specify ${KDIR} make variable which points to your kernel |
2430 | + source tree. | |
2431 | +- install the files | |
2432 | + + run "make install" to install the aufs module, or copy the built | |
b4510431 AM |
2433 | + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply). |
2434 | + + run "make install_headers" (instead of headers_install) to install | |
2435 | + the modified aufs header file (you can specify DESTDIR which is | |
2436 | + available in aufs standalone version's Makefile only), or copy | |
2437 | + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever | |
2438 | + you like manually. By default, the target directory is $PWD/usr. | |
53392da6 AM |
2439 | +- no need to apply aufs3-kbuild.patch, nor copying source files to your |
2440 | + kernel source tree. | |
2441 | + | |
b4510431 | 2442 | +Note: The header file aufs_type.h is necessary to build aufs-util |
53392da6 AM |
2443 | + as well as "make headers_install" in the kernel source tree. |
2444 | + headers_install is subject to be forgotten, but it is essentially | |
2445 | + necessary, not only for building aufs-util. | |
2446 | + You may not meet problems without headers_install in some older | |
2447 | + version though. | |
2448 | + | |
2449 | +And then, | |
2450 | +- read README in aufs-util, build and install it | |
9dbd164d AM |
2451 | +- note that your distribution may contain an obsoleted version of |
2452 | + aufs_type.h in /usr/include/linux or something. When you build aufs | |
2453 | + utilities, make sure that your compiler refers the correct aufs header | |
2454 | + file which is built by "make headers_install." | |
53392da6 AM |
2455 | +- if you want to use readdir(3) in userspace or pathconf(3) wrapper, |
2456 | + then run "make install_ulib" too. And refer to the aufs manual in | |
2457 | + detail. | |
2458 | + | |
38d290e6 JR |
2459 | +There several other patches in aufs3-standalone.git. They are all |
2460 | +optional. When you meet some problems, they will help you. | |
2461 | +- aufs3-loopback.patch | |
2462 | + Supports a nested loopback mount in a branch-fs. This patch is | |
2463 | + unnecessary until aufs produces a message like "you may want to try | |
2464 | + another patch for loopback file". | |
2465 | +- vfs-ino.patch | |
2466 | + Modifies a system global kernel internal function get_next_ino() in | |
2467 | + order to stop assigning 0 for an inode-number. Not directly related to | |
2468 | + aufs, but recommended generally. | |
2469 | +- tmpfs-idr.patch | |
2470 | + Keeps the tmpfs inode number as the lowest value. Effective to reduce | |
2471 | + the size of aufs XINO files for tmpfs branch. Also it prevents the | |
2472 | + duplication of inode number, which is important for backup tools and | |
2473 | + other utilities. When you find aufs XINO files for tmpfs branch | |
2474 | + growing too much, try this patch. | |
2475 | + | |
53392da6 AM |
2476 | + |
2477 | +4. Usage | |
2478 | +---------------------------------------- | |
2479 | +At first, make sure aufs-util are installed, and please read the aufs | |
2480 | +manual, aufs.5 in aufs-util.git tree. | |
2481 | +$ man -l aufs.5 | |
2482 | + | |
2483 | +And then, | |
2484 | +$ mkdir /tmp/rw /tmp/aufs | |
2485 | +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs | |
2486 | + | |
2487 | +Here is another example. The result is equivalent. | |
2488 | +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs | |
2489 | + Or | |
2490 | +# mount -t aufs -o br:/tmp/rw none /tmp/aufs | |
2491 | +# mount -o remount,append:${HOME} /tmp/aufs | |
2492 | + | |
2493 | +Then, you can see whole tree of your home dir through /tmp/aufs. If | |
2494 | +you modify a file under /tmp/aufs, the one on your home directory is | |
2495 | +not affected, instead the same named file will be newly created under | |
2496 | +/tmp/rw. And all of your modification to a file will be applied to | |
2497 | +the one under /tmp/rw. This is called the file based Copy on Write | |
2498 | +(COW) method. | |
2499 | +Aufs mount options are described in aufs.5. | |
2500 | +If you run chroot or something and make your aufs as a root directory, | |
2501 | +then you need to customize the shutdown script. See the aufs manual in | |
2502 | +detail. | |
2503 | + | |
2504 | +Additionally, there are some sample usages of aufs which are a | |
2505 | +diskless system with network booting, and LiveCD over NFS. | |
2506 | +See sample dir in CVS tree on SourceForge. | |
2507 | + | |
2508 | + | |
2509 | +5. Contact | |
2510 | +---------------------------------------- | |
2511 | +When you have any problems or strange behaviour in aufs, please let me | |
2512 | +know with: | |
2513 | +- /proc/mounts (instead of the output of mount(8)) | |
2514 | +- /sys/module/aufs/* | |
2515 | +- /sys/fs/aufs/* (if you have them) | |
2516 | +- /debug/aufs/* (if you have them) | |
2517 | +- linux kernel version | |
2518 | + if your kernel is not plain, for example modified by distributor, | |
2519 | + the url where i can download its source is necessary too. | |
2520 | +- aufs version which was printed at loading the module or booting the | |
2521 | + system, instead of the date you downloaded. | |
2522 | +- configuration (define/undefine CONFIG_AUFS_xxx) | |
2523 | +- kernel configuration or /proc/config.gz (if you have it) | |
2524 | +- behaviour which you think to be incorrect | |
2525 | +- actual operation, reproducible one is better | |
2526 | +- mailto: aufs-users at lists.sourceforge.net | |
2527 | + | |
2528 | +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches, | |
2529 | +and Feature Requests) on SourceForge. Please join and write to | |
2530 | +aufs-users ML. | |
2531 | + | |
2532 | + | |
2533 | +6. Acknowledgements | |
2534 | +---------------------------------------- | |
2535 | +Thanks to everyone who have tried and are using aufs, whoever | |
2536 | +have reported a bug or any feedback. | |
2537 | + | |
2538 | +Especially donators: | |
2539 | +Tomas Matejicek(slax.org) made a donation (much more than once). | |
2540 | + Since Apr 2010, Tomas M (the author of Slax and Linux Live | |
2541 | + scripts) is making "doubling" donations. | |
2542 | + Unfortunately I cannot list all of the donators, but I really | |
b4510431 | 2543 | + appreciate. |
53392da6 AM |
2544 | + It ends Aug 2010, but the ordinary donation URL is still available. |
2545 | + <http://sourceforge.net/donate/index.php?group_id=167503> | |
2546 | +Dai Itasaka made a donation (2007/8). | |
2547 | +Chuck Smith made a donation (2008/4, 10 and 12). | |
2548 | +Henk Schoneveld made a donation (2008/9). | |
2549 | +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10). | |
2550 | +Francois Dupoux made a donation (2008/11). | |
2551 | +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public | |
2552 | + aufs2 GIT tree (2009/2). | |
2553 | +William Grant made a donation (2009/3). | |
2554 | +Patrick Lane made a donation (2009/4). | |
2555 | +The Mail Archive (mail-archive.com) made donations (2009/5). | |
2556 | +Nippy Networks (Ed Wildgoose) made a donation (2009/7). | |
2557 | +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11). | |
2558 | +Pavel Pronskiy made a donation (2011/2). | |
2559 | +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy | |
2560 | + Networks (Ed Wildgoose) made a donation for hardware (2011/3). | |
537831f9 AM |
2561 | +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and |
2562 | +11). | |
1e00d052 | 2563 | +Sam Liddicott made a donation (2011/9). |
86dc4139 AM |
2564 | +Era Scarecrow made a donation (2013/4). |
2565 | +Bor Ratajc made a donation (2013/4). | |
2566 | +Alessandro Gorreta made a donation (2013/4). | |
2567 | +POIRETTE Marc made a donation (2013/4). | |
2568 | +Alessandro Gorreta made a donation (2013/4). | |
2569 | +lauri kasvandik made a donation (2013/5). | |
392086de | 2570 | +"pemasu from Finland" made a donation (2013/7). |
523b37e3 AM |
2571 | +The Parted Magic Project made a donation (2013/9 and 11). |
2572 | +Pavel Barta made a donation (2013/10). | |
38d290e6 | 2573 | +Nikolay Pertsev made a donation (2014/5). |
076b876e AM |
2574 | +James B made a donation (2014/7). |
2575 | +Stefano Di Biase made a donation (2014/8). | |
53392da6 AM |
2576 | + |
2577 | +Thank you very much. | |
2578 | +Donations are always, including future donations, very important and | |
2579 | +helpful for me to keep on developing aufs. | |
2580 | + | |
2581 | + | |
2582 | +7. | |
2583 | +---------------------------------------- | |
2584 | +If you are an experienced user, no explanation is needed. Aufs is | |
2585 | +just a linux filesystem. | |
2586 | + | |
2587 | + | |
2588 | +Enjoy! | |
2589 | + | |
2590 | +# Local variables: ; | |
2591 | +# mode: text; | |
2592 | +# End: ; | |
7f207e10 AM |
2593 | diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h |
2594 | --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 2595 | +++ linux/fs/aufs/aufs.h 2015-01-25 13:00:38.627713742 +0100 |
523b37e3 | 2596 | @@ -0,0 +1,59 @@ |
7f207e10 | 2597 | +/* |
523b37e3 | 2598 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
7f207e10 AM |
2599 | + * |
2600 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2601 | + * it under the terms of the GNU General Public License as published by | |
2602 | + * the Free Software Foundation; either version 2 of the License, or | |
2603 | + * (at your option) any later version. | |
2604 | + * | |
2605 | + * This program is distributed in the hope that it will be useful, | |
2606 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2607 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2608 | + * GNU General Public License for more details. | |
2609 | + * | |
2610 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2611 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2612 | + */ |
2613 | + | |
2614 | +/* | |
2615 | + * all header files | |
2616 | + */ | |
2617 | + | |
2618 | +#ifndef __AUFS_H__ | |
2619 | +#define __AUFS_H__ | |
2620 | + | |
2621 | +#ifdef __KERNEL__ | |
2622 | + | |
2623 | +#define AuStub(type, name, body, ...) \ | |
2624 | + static inline type name(__VA_ARGS__) { body; } | |
2625 | + | |
2626 | +#define AuStubVoid(name, ...) \ | |
2627 | + AuStub(void, name, , __VA_ARGS__) | |
2628 | +#define AuStubInt0(name, ...) \ | |
2629 | + AuStub(int, name, return 0, __VA_ARGS__) | |
2630 | + | |
2631 | +#include "debug.h" | |
2632 | + | |
2633 | +#include "branch.h" | |
2634 | +#include "cpup.h" | |
2635 | +#include "dcsub.h" | |
2636 | +#include "dbgaufs.h" | |
2637 | +#include "dentry.h" | |
2638 | +#include "dir.h" | |
2639 | +#include "dynop.h" | |
2640 | +#include "file.h" | |
2641 | +#include "fstype.h" | |
2642 | +#include "inode.h" | |
2643 | +#include "loop.h" | |
2644 | +#include "module.h" | |
7f207e10 AM |
2645 | +#include "opts.h" |
2646 | +#include "rwsem.h" | |
2647 | +#include "spl.h" | |
2648 | +#include "super.h" | |
2649 | +#include "sysaufs.h" | |
2650 | +#include "vfsub.h" | |
2651 | +#include "whout.h" | |
2652 | +#include "wkq.h" | |
2653 | + | |
2654 | +#endif /* __KERNEL__ */ | |
2655 | +#endif /* __AUFS_H__ */ | |
2656 | diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c | |
2657 | --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
2658 | +++ linux/fs/aufs/branch.c 2015-01-25 13:00:38.627713742 +0100 |
2659 | @@ -0,0 +1,1410 @@ | |
7f207e10 | 2660 | +/* |
523b37e3 | 2661 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
7f207e10 AM |
2662 | + * |
2663 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2664 | + * it under the terms of the GNU General Public License as published by | |
2665 | + * the Free Software Foundation; either version 2 of the License, or | |
2666 | + * (at your option) any later version. | |
2667 | + * | |
2668 | + * This program is distributed in the hope that it will be useful, | |
2669 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2670 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2671 | + * GNU General Public License for more details. | |
2672 | + * | |
2673 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2674 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2675 | + */ |
2676 | + | |
2677 | +/* | |
2678 | + * branch management | |
2679 | + */ | |
2680 | + | |
027c5e7a | 2681 | +#include <linux/compat.h> |
7f207e10 AM |
2682 | +#include <linux/statfs.h> |
2683 | +#include "aufs.h" | |
2684 | + | |
2685 | +/* | |
2686 | + * free a single branch | |
1facf9fc | 2687 | + */ |
2688 | +static void au_br_do_free(struct au_branch *br) | |
2689 | +{ | |
2690 | + int i; | |
2691 | + struct au_wbr *wbr; | |
4a4d8108 | 2692 | + struct au_dykey **key; |
1facf9fc | 2693 | + |
027c5e7a AM |
2694 | + au_hnotify_fin_br(br); |
2695 | + | |
1facf9fc | 2696 | + if (br->br_xino.xi_file) |
2697 | + fput(br->br_xino.xi_file); | |
2698 | + mutex_destroy(&br->br_xino.xi_nondir_mtx); | |
2699 | + | |
2700 | + AuDebugOn(atomic_read(&br->br_count)); | |
2701 | + | |
2702 | + wbr = br->br_wbr; | |
2703 | + if (wbr) { | |
2704 | + for (i = 0; i < AuBrWh_Last; i++) | |
2705 | + dput(wbr->wbr_wh[i]); | |
2706 | + AuDebugOn(atomic_read(&wbr->wbr_wh_running)); | |
dece6358 | 2707 | + AuRwDestroy(&wbr->wbr_wh_rwsem); |
1facf9fc | 2708 | + } |
2709 | + | |
076b876e AM |
2710 | + if (br->br_fhsm) { |
2711 | + au_br_fhsm_fin(br->br_fhsm); | |
2712 | + kfree(br->br_fhsm); | |
2713 | + } | |
2714 | + | |
4a4d8108 AM |
2715 | + key = br->br_dykey; |
2716 | + for (i = 0; i < AuBrDynOp; i++, key++) | |
2717 | + if (*key) | |
2718 | + au_dy_put(*key); | |
2719 | + else | |
2720 | + break; | |
2721 | + | |
537831f9 AM |
2722 | + /* recursive lock, s_umount of branch's */ |
2723 | + lockdep_off(); | |
86dc4139 | 2724 | + path_put(&br->br_path); |
537831f9 | 2725 | + lockdep_on(); |
1facf9fc | 2726 | + kfree(wbr); |
2727 | + kfree(br); | |
2728 | +} | |
2729 | + | |
2730 | +/* | |
2731 | + * frees all branches | |
2732 | + */ | |
2733 | +void au_br_free(struct au_sbinfo *sbinfo) | |
2734 | +{ | |
2735 | + aufs_bindex_t bmax; | |
2736 | + struct au_branch **br; | |
2737 | + | |
dece6358 AM |
2738 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
2739 | + | |
1facf9fc | 2740 | + bmax = sbinfo->si_bend + 1; |
2741 | + br = sbinfo->si_branch; | |
2742 | + while (bmax--) | |
2743 | + au_br_do_free(*br++); | |
2744 | +} | |
2745 | + | |
2746 | +/* | |
2747 | + * find the index of a branch which is specified by @br_id. | |
2748 | + */ | |
2749 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id) | |
2750 | +{ | |
2751 | + aufs_bindex_t bindex, bend; | |
2752 | + | |
2753 | + bend = au_sbend(sb); | |
2754 | + for (bindex = 0; bindex <= bend; bindex++) | |
2755 | + if (au_sbr_id(sb, bindex) == br_id) | |
2756 | + return bindex; | |
2757 | + return -1; | |
2758 | +} | |
2759 | + | |
2760 | +/* ---------------------------------------------------------------------- */ | |
2761 | + | |
2762 | +/* | |
2763 | + * add a branch | |
2764 | + */ | |
2765 | + | |
b752ccd1 AM |
2766 | +static int test_overlap(struct super_block *sb, struct dentry *h_adding, |
2767 | + struct dentry *h_root) | |
1facf9fc | 2768 | +{ |
b752ccd1 AM |
2769 | + if (unlikely(h_adding == h_root |
2770 | + || au_test_loopback_overlap(sb, h_adding))) | |
1facf9fc | 2771 | + return 1; |
b752ccd1 AM |
2772 | + if (h_adding->d_sb != h_root->d_sb) |
2773 | + return 0; | |
2774 | + return au_test_subdir(h_adding, h_root) | |
2775 | + || au_test_subdir(h_root, h_adding); | |
1facf9fc | 2776 | +} |
2777 | + | |
2778 | +/* | |
2779 | + * returns a newly allocated branch. @new_nbranch is a number of branches | |
2780 | + * after adding a branch. | |
2781 | + */ | |
2782 | +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch, | |
2783 | + int perm) | |
2784 | +{ | |
2785 | + struct au_branch *add_branch; | |
2786 | + struct dentry *root; | |
4a4d8108 | 2787 | + int err; |
1facf9fc | 2788 | + |
4a4d8108 | 2789 | + err = -ENOMEM; |
1facf9fc | 2790 | + root = sb->s_root; |
2791 | + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS); | |
2792 | + if (unlikely(!add_branch)) | |
2793 | + goto out; | |
2794 | + | |
027c5e7a AM |
2795 | + err = au_hnotify_init_br(add_branch, perm); |
2796 | + if (unlikely(err)) | |
2797 | + goto out_br; | |
2798 | + | |
1facf9fc | 2799 | + add_branch->br_wbr = NULL; |
2800 | + if (au_br_writable(perm)) { | |
2801 | + /* may be freed separately at changing the branch permission */ | |
2802 | + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr), | |
2803 | + GFP_NOFS); | |
2804 | + if (unlikely(!add_branch->br_wbr)) | |
027c5e7a | 2805 | + goto out_hnotify; |
1facf9fc | 2806 | + } |
2807 | + | |
076b876e AM |
2808 | + add_branch->br_fhsm = NULL; |
2809 | + if (au_br_fhsm(perm)) { | |
2810 | + err = au_fhsm_br_alloc(add_branch); | |
2811 | + if (unlikely(err)) | |
2812 | + goto out_wbr; | |
2813 | + } | |
2814 | + | |
4a4d8108 AM |
2815 | + err = au_sbr_realloc(au_sbi(sb), new_nbranch); |
2816 | + if (!err) | |
2817 | + err = au_di_realloc(au_di(root), new_nbranch); | |
2818 | + if (!err) | |
2819 | + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch); | |
2820 | + if (!err) | |
2821 | + return add_branch; /* success */ | |
1facf9fc | 2822 | + |
076b876e | 2823 | +out_wbr: |
1facf9fc | 2824 | + kfree(add_branch->br_wbr); |
027c5e7a AM |
2825 | +out_hnotify: |
2826 | + au_hnotify_fin_br(add_branch); | |
4f0767ce | 2827 | +out_br: |
1facf9fc | 2828 | + kfree(add_branch); |
4f0767ce | 2829 | +out: |
4a4d8108 | 2830 | + return ERR_PTR(err); |
1facf9fc | 2831 | +} |
2832 | + | |
2833 | +/* | |
2834 | + * test if the branch permission is legal or not. | |
2835 | + */ | |
2836 | +static int test_br(struct inode *inode, int brperm, char *path) | |
2837 | +{ | |
2838 | + int err; | |
2839 | + | |
4a4d8108 AM |
2840 | + err = (au_br_writable(brperm) && IS_RDONLY(inode)); |
2841 | + if (!err) | |
2842 | + goto out; | |
1facf9fc | 2843 | + |
4a4d8108 AM |
2844 | + err = -EINVAL; |
2845 | + pr_err("write permission for readonly mount or inode, %s\n", path); | |
2846 | + | |
4f0767ce | 2847 | +out: |
1facf9fc | 2848 | + return err; |
2849 | +} | |
2850 | + | |
2851 | +/* | |
2852 | + * returns: | |
2853 | + * 0: success, the caller will add it | |
2854 | + * plus: success, it is already unified, the caller should ignore it | |
2855 | + * minus: error | |
2856 | + */ | |
2857 | +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
2858 | +{ | |
2859 | + int err; | |
2860 | + aufs_bindex_t bend, bindex; | |
2861 | + struct dentry *root; | |
2862 | + struct inode *inode, *h_inode; | |
2863 | + | |
2864 | + root = sb->s_root; | |
2865 | + bend = au_sbend(sb); | |
2866 | + if (unlikely(bend >= 0 | |
2867 | + && au_find_dbindex(root, add->path.dentry) >= 0)) { | |
2868 | + err = 1; | |
2869 | + if (!remount) { | |
2870 | + err = -EINVAL; | |
4a4d8108 | 2871 | + pr_err("%s duplicated\n", add->pathname); |
1facf9fc | 2872 | + } |
2873 | + goto out; | |
2874 | + } | |
2875 | + | |
2876 | + err = -ENOSPC; /* -E2BIG; */ | |
2877 | + if (unlikely(AUFS_BRANCH_MAX <= add->bindex | |
2878 | + || AUFS_BRANCH_MAX - 1 <= bend)) { | |
4a4d8108 | 2879 | + pr_err("number of branches exceeded %s\n", add->pathname); |
1facf9fc | 2880 | + goto out; |
2881 | + } | |
2882 | + | |
2883 | + err = -EDOM; | |
2884 | + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) { | |
4a4d8108 | 2885 | + pr_err("bad index %d\n", add->bindex); |
1facf9fc | 2886 | + goto out; |
2887 | + } | |
2888 | + | |
2889 | + inode = add->path.dentry->d_inode; | |
2890 | + err = -ENOENT; | |
2891 | + if (unlikely(!inode->i_nlink)) { | |
4a4d8108 | 2892 | + pr_err("no existence %s\n", add->pathname); |
1facf9fc | 2893 | + goto out; |
2894 | + } | |
2895 | + | |
2896 | + err = -EINVAL; | |
2897 | + if (unlikely(inode->i_sb == sb)) { | |
4a4d8108 | 2898 | + pr_err("%s must be outside\n", add->pathname); |
1facf9fc | 2899 | + goto out; |
2900 | + } | |
2901 | + | |
2902 | + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) { | |
4a4d8108 AM |
2903 | + pr_err("unsupported filesystem, %s (%s)\n", |
2904 | + add->pathname, au_sbtype(inode->i_sb)); | |
1facf9fc | 2905 | + goto out; |
2906 | + } | |
2907 | + | |
c1595e42 JR |
2908 | + if (unlikely(inode->i_sb->s_stack_depth)) { |
2909 | + pr_err("already stacked, %s (%s)\n", | |
2910 | + add->pathname, au_sbtype(inode->i_sb)); | |
2911 | + goto out; | |
2912 | + } | |
2913 | + | |
1facf9fc | 2914 | + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname); |
2915 | + if (unlikely(err)) | |
2916 | + goto out; | |
2917 | + | |
2918 | + if (bend < 0) | |
2919 | + return 0; /* success */ | |
2920 | + | |
2921 | + err = -EINVAL; | |
2922 | + for (bindex = 0; bindex <= bend; bindex++) | |
2923 | + if (unlikely(test_overlap(sb, add->path.dentry, | |
2924 | + au_h_dptr(root, bindex)))) { | |
4a4d8108 | 2925 | + pr_err("%s is overlapped\n", add->pathname); |
1facf9fc | 2926 | + goto out; |
2927 | + } | |
2928 | + | |
2929 | + err = 0; | |
2930 | + if (au_opt_test(au_mntflags(sb), WARN_PERM)) { | |
2931 | + h_inode = au_h_dptr(root, 0)->d_inode; | |
2932 | + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO) | |
0c3ec466 AM |
2933 | + || !uid_eq(h_inode->i_uid, inode->i_uid) |
2934 | + || !gid_eq(h_inode->i_gid, inode->i_gid)) | |
2935 | + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n", | |
2936 | + add->pathname, | |
2937 | + i_uid_read(inode), i_gid_read(inode), | |
2938 | + (inode->i_mode & S_IALLUGO), | |
2939 | + i_uid_read(h_inode), i_gid_read(h_inode), | |
2940 | + (h_inode->i_mode & S_IALLUGO)); | |
1facf9fc | 2941 | + } |
2942 | + | |
4f0767ce | 2943 | +out: |
1facf9fc | 2944 | + return err; |
2945 | +} | |
2946 | + | |
2947 | +/* | |
2948 | + * initialize or clean the whiteouts for an adding branch | |
2949 | + */ | |
2950 | +static int au_br_init_wh(struct super_block *sb, struct au_branch *br, | |
86dc4139 | 2951 | + int new_perm) |
1facf9fc | 2952 | +{ |
2953 | + int err, old_perm; | |
2954 | + aufs_bindex_t bindex; | |
2955 | + struct mutex *h_mtx; | |
2956 | + struct au_wbr *wbr; | |
2957 | + struct au_hinode *hdir; | |
2958 | + | |
86dc4139 AM |
2959 | + err = vfsub_mnt_want_write(au_br_mnt(br)); |
2960 | + if (unlikely(err)) | |
2961 | + goto out; | |
2962 | + | |
1facf9fc | 2963 | + wbr = br->br_wbr; |
2964 | + old_perm = br->br_perm; | |
2965 | + br->br_perm = new_perm; | |
2966 | + hdir = NULL; | |
2967 | + h_mtx = NULL; | |
2968 | + bindex = au_br_index(sb, br->br_id); | |
2969 | + if (0 <= bindex) { | |
2970 | + hdir = au_hi(sb->s_root->d_inode, bindex); | |
4a4d8108 | 2971 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 2972 | + } else { |
86dc4139 | 2973 | + h_mtx = &au_br_dentry(br)->d_inode->i_mutex; |
1facf9fc | 2974 | + mutex_lock_nested(h_mtx, AuLsc_I_PARENT); |
2975 | + } | |
2976 | + if (!wbr) | |
86dc4139 | 2977 | + err = au_wh_init(br, sb); |
1facf9fc | 2978 | + else { |
2979 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 2980 | + err = au_wh_init(br, sb); |
1facf9fc | 2981 | + wbr_wh_write_unlock(wbr); |
2982 | + } | |
2983 | + if (hdir) | |
4a4d8108 | 2984 | + au_hn_imtx_unlock(hdir); |
1facf9fc | 2985 | + else |
2986 | + mutex_unlock(h_mtx); | |
86dc4139 | 2987 | + vfsub_mnt_drop_write(au_br_mnt(br)); |
1facf9fc | 2988 | + br->br_perm = old_perm; |
2989 | + | |
2990 | + if (!err && wbr && !au_br_writable(new_perm)) { | |
2991 | + kfree(wbr); | |
2992 | + br->br_wbr = NULL; | |
2993 | + } | |
2994 | + | |
86dc4139 | 2995 | +out: |
1facf9fc | 2996 | + return err; |
2997 | +} | |
2998 | + | |
2999 | +static int au_wbr_init(struct au_branch *br, struct super_block *sb, | |
86dc4139 | 3000 | + int perm) |
1facf9fc | 3001 | +{ |
3002 | + int err; | |
4a4d8108 | 3003 | + struct kstatfs kst; |
1facf9fc | 3004 | + struct au_wbr *wbr; |
3005 | + | |
3006 | + wbr = br->br_wbr; | |
dece6358 | 3007 | + au_rw_init(&wbr->wbr_wh_rwsem); |
1facf9fc | 3008 | + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh)); |
3009 | + atomic_set(&wbr->wbr_wh_running, 0); | |
3010 | + wbr->wbr_bytes = 0; | |
3011 | + | |
4a4d8108 AM |
3012 | + /* |
3013 | + * a limit for rmdir/rename a dir | |
523b37e3 | 3014 | + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h |
4a4d8108 | 3015 | + */ |
86dc4139 | 3016 | + err = vfs_statfs(&br->br_path, &kst); |
4a4d8108 AM |
3017 | + if (unlikely(err)) |
3018 | + goto out; | |
3019 | + err = -EINVAL; | |
3020 | + if (kst.f_namelen >= NAME_MAX) | |
86dc4139 | 3021 | + err = au_br_init_wh(sb, br, perm); |
4a4d8108 | 3022 | + else |
523b37e3 AM |
3023 | + pr_err("%pd(%s), unsupported namelen %ld\n", |
3024 | + au_br_dentry(br), | |
86dc4139 | 3025 | + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen); |
1facf9fc | 3026 | + |
4f0767ce | 3027 | +out: |
1facf9fc | 3028 | + return err; |
3029 | +} | |
3030 | + | |
c1595e42 | 3031 | +/* initialize a new branch */ |
1facf9fc | 3032 | +static int au_br_init(struct au_branch *br, struct super_block *sb, |
3033 | + struct au_opt_add *add) | |
3034 | +{ | |
3035 | + int err; | |
3036 | + | |
3037 | + err = 0; | |
3038 | + memset(&br->br_xino, 0, sizeof(br->br_xino)); | |
3039 | + mutex_init(&br->br_xino.xi_nondir_mtx); | |
3040 | + br->br_perm = add->perm; | |
86dc4139 | 3041 | + br->br_path = add->path; /* set first, path_get() later */ |
4a4d8108 AM |
3042 | + spin_lock_init(&br->br_dykey_lock); |
3043 | + memset(br->br_dykey, 0, sizeof(br->br_dykey)); | |
1facf9fc | 3044 | + atomic_set(&br->br_count, 0); |
1facf9fc | 3045 | + atomic_set(&br->br_xino_running, 0); |
3046 | + br->br_id = au_new_br_id(sb); | |
7f207e10 | 3047 | + AuDebugOn(br->br_id < 0); |
1facf9fc | 3048 | + |
3049 | + if (au_br_writable(add->perm)) { | |
86dc4139 | 3050 | + err = au_wbr_init(br, sb, add->perm); |
1facf9fc | 3051 | + if (unlikely(err)) |
b752ccd1 | 3052 | + goto out_err; |
1facf9fc | 3053 | + } |
3054 | + | |
3055 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
3056 | + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino, | |
3057 | + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1); | |
3058 | + if (unlikely(err)) { | |
3059 | + AuDebugOn(br->br_xino.xi_file); | |
b752ccd1 | 3060 | + goto out_err; |
1facf9fc | 3061 | + } |
3062 | + } | |
3063 | + | |
3064 | + sysaufs_br_init(br); | |
86dc4139 | 3065 | + path_get(&br->br_path); |
b752ccd1 | 3066 | + goto out; /* success */ |
1facf9fc | 3067 | + |
4f0767ce | 3068 | +out_err: |
86dc4139 | 3069 | + memset(&br->br_path, 0, sizeof(br->br_path)); |
4f0767ce | 3070 | +out: |
1facf9fc | 3071 | + return err; |
3072 | +} | |
3073 | + | |
3074 | +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex, | |
3075 | + struct au_branch *br, aufs_bindex_t bend, | |
3076 | + aufs_bindex_t amount) | |
3077 | +{ | |
3078 | + struct au_branch **brp; | |
3079 | + | |
dece6358 AM |
3080 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3081 | + | |
1facf9fc | 3082 | + brp = sbinfo->si_branch + bindex; |
3083 | + memmove(brp + 1, brp, sizeof(*brp) * amount); | |
3084 | + *brp = br; | |
3085 | + sbinfo->si_bend++; | |
3086 | + if (unlikely(bend < 0)) | |
3087 | + sbinfo->si_bend = 0; | |
3088 | +} | |
3089 | + | |
3090 | +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex, | |
3091 | + aufs_bindex_t bend, aufs_bindex_t amount) | |
3092 | +{ | |
3093 | + struct au_hdentry *hdp; | |
3094 | + | |
1308ab2a | 3095 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3096 | + | |
1facf9fc | 3097 | + hdp = dinfo->di_hdentry + bindex; |
3098 | + memmove(hdp + 1, hdp, sizeof(*hdp) * amount); | |
3099 | + au_h_dentry_init(hdp); | |
3100 | + dinfo->di_bend++; | |
3101 | + if (unlikely(bend < 0)) | |
3102 | + dinfo->di_bstart = 0; | |
3103 | +} | |
3104 | + | |
3105 | +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex, | |
3106 | + aufs_bindex_t bend, aufs_bindex_t amount) | |
3107 | +{ | |
3108 | + struct au_hinode *hip; | |
3109 | + | |
1308ab2a | 3110 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3111 | + | |
1facf9fc | 3112 | + hip = iinfo->ii_hinode + bindex; |
3113 | + memmove(hip + 1, hip, sizeof(*hip) * amount); | |
3114 | + hip->hi_inode = NULL; | |
4a4d8108 | 3115 | + au_hn_init(hip); |
1facf9fc | 3116 | + iinfo->ii_bend++; |
3117 | + if (unlikely(bend < 0)) | |
3118 | + iinfo->ii_bstart = 0; | |
3119 | +} | |
3120 | + | |
86dc4139 AM |
3121 | +static void au_br_do_add(struct super_block *sb, struct au_branch *br, |
3122 | + aufs_bindex_t bindex) | |
1facf9fc | 3123 | +{ |
86dc4139 | 3124 | + struct dentry *root, *h_dentry; |
1facf9fc | 3125 | + struct inode *root_inode; |
3126 | + aufs_bindex_t bend, amount; | |
3127 | + | |
3128 | + root = sb->s_root; | |
3129 | + root_inode = root->d_inode; | |
1facf9fc | 3130 | + bend = au_sbend(sb); |
3131 | + amount = bend + 1 - bindex; | |
86dc4139 | 3132 | + h_dentry = au_br_dentry(br); |
53392da6 | 3133 | + au_sbilist_lock(); |
1facf9fc | 3134 | + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount); |
3135 | + au_br_do_add_hdp(au_di(root), bindex, bend, amount); | |
3136 | + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount); | |
3137 | + au_set_h_dptr(root, bindex, dget(h_dentry)); | |
3138 | + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode), | |
3139 | + /*flags*/0); | |
53392da6 | 3140 | + au_sbilist_unlock(); |
1facf9fc | 3141 | +} |
3142 | + | |
3143 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3144 | +{ | |
3145 | + int err; | |
1facf9fc | 3146 | + aufs_bindex_t bend, add_bindex; |
3147 | + struct dentry *root, *h_dentry; | |
3148 | + struct inode *root_inode; | |
3149 | + struct au_branch *add_branch; | |
3150 | + | |
3151 | + root = sb->s_root; | |
3152 | + root_inode = root->d_inode; | |
3153 | + IMustLock(root_inode); | |
3154 | + err = test_add(sb, add, remount); | |
3155 | + if (unlikely(err < 0)) | |
3156 | + goto out; | |
3157 | + if (err) { | |
3158 | + err = 0; | |
3159 | + goto out; /* success */ | |
3160 | + } | |
3161 | + | |
3162 | + bend = au_sbend(sb); | |
3163 | + add_branch = au_br_alloc(sb, bend + 2, add->perm); | |
3164 | + err = PTR_ERR(add_branch); | |
3165 | + if (IS_ERR(add_branch)) | |
3166 | + goto out; | |
3167 | + | |
3168 | + err = au_br_init(add_branch, sb, add); | |
3169 | + if (unlikely(err)) { | |
3170 | + au_br_do_free(add_branch); | |
3171 | + goto out; | |
3172 | + } | |
3173 | + | |
3174 | + add_bindex = add->bindex; | |
1facf9fc | 3175 | + if (!remount) |
86dc4139 | 3176 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3177 | + else { |
3178 | + sysaufs_brs_del(sb, add_bindex); | |
86dc4139 | 3179 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3180 | + sysaufs_brs_add(sb, add_bindex); |
3181 | + } | |
3182 | + | |
86dc4139 | 3183 | + h_dentry = add->path.dentry; |
1308ab2a | 3184 | + if (!add_bindex) { |
1facf9fc | 3185 | + au_cpup_attr_all(root_inode, /*force*/1); |
1308ab2a | 3186 | + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes; |
3187 | + } else | |
1facf9fc | 3188 | + au_add_nlink(root_inode, h_dentry->d_inode); |
1facf9fc | 3189 | + |
3190 | + /* | |
4a4d8108 | 3191 | + * this test/set prevents aufs from handling unnecesary notify events |
027c5e7a | 3192 | + * of xino files, in case of re-adding a writable branch which was |
1facf9fc | 3193 | + * once detached from aufs. |
3194 | + */ | |
3195 | + if (au_xino_brid(sb) < 0 | |
3196 | + && au_br_writable(add_branch->br_perm) | |
3197 | + && !au_test_fs_bad_xino(h_dentry->d_sb) | |
3198 | + && add_branch->br_xino.xi_file | |
3199 | + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry) | |
3200 | + au_xino_brid_set(sb, add_branch->br_id); | |
3201 | + | |
4f0767ce | 3202 | +out: |
1facf9fc | 3203 | + return err; |
3204 | +} | |
3205 | + | |
3206 | +/* ---------------------------------------------------------------------- */ | |
3207 | + | |
076b876e AM |
3208 | +static unsigned long long au_farray_cb(void *a, |
3209 | + unsigned long long max __maybe_unused, | |
3210 | + void *arg) | |
3211 | +{ | |
3212 | + unsigned long long n; | |
3213 | + struct file **p, *f; | |
3214 | + struct au_sphlhead *files; | |
3215 | + struct au_finfo *finfo; | |
3216 | + struct super_block *sb = arg; | |
3217 | + | |
3218 | + n = 0; | |
3219 | + p = a; | |
3220 | + files = &au_sbi(sb)->si_files; | |
3221 | + spin_lock(&files->spin); | |
3222 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
3223 | + f = finfo->fi_file; | |
3224 | + if (file_count(f) | |
3225 | + && !special_file(file_inode(f)->i_mode)) { | |
3226 | + get_file(f); | |
3227 | + *p++ = f; | |
3228 | + n++; | |
3229 | + AuDebugOn(n > max); | |
3230 | + } | |
3231 | + } | |
3232 | + spin_unlock(&files->spin); | |
3233 | + | |
3234 | + return n; | |
3235 | +} | |
3236 | + | |
3237 | +static struct file **au_farray_alloc(struct super_block *sb, | |
3238 | + unsigned long long *max) | |
3239 | +{ | |
3240 | + *max = atomic_long_read(&au_sbi(sb)->si_nfiles); | |
3241 | + return au_array_alloc(max, au_farray_cb, sb); | |
3242 | +} | |
3243 | + | |
3244 | +static void au_farray_free(struct file **a, unsigned long long max) | |
3245 | +{ | |
3246 | + unsigned long long ull; | |
3247 | + | |
3248 | + for (ull = 0; ull < max; ull++) | |
3249 | + if (a[ull]) | |
3250 | + fput(a[ull]); | |
3251 | + au_array_free(a); | |
3252 | +} | |
3253 | + | |
3254 | +/* ---------------------------------------------------------------------- */ | |
3255 | + | |
1facf9fc | 3256 | +/* |
3257 | + * delete a branch | |
3258 | + */ | |
3259 | + | |
3260 | +/* to show the line number, do not make it inlined function */ | |
4a4d8108 | 3261 | +#define AuVerbose(do_info, fmt, ...) do { \ |
1facf9fc | 3262 | + if (do_info) \ |
4a4d8108 | 3263 | + pr_info(fmt, ##__VA_ARGS__); \ |
1facf9fc | 3264 | +} while (0) |
3265 | + | |
027c5e7a AM |
3266 | +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart, |
3267 | + aufs_bindex_t bend) | |
3268 | +{ | |
3269 | + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend; | |
3270 | +} | |
3271 | + | |
3272 | +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart, | |
3273 | + aufs_bindex_t bend) | |
3274 | +{ | |
3275 | + return au_test_ibusy(dentry->d_inode, bstart, bend); | |
3276 | +} | |
3277 | + | |
1facf9fc | 3278 | +/* |
3279 | + * test if the branch is deletable or not. | |
3280 | + */ | |
3281 | +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex, | |
b752ccd1 | 3282 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3283 | +{ |
3284 | + int err, i, j, ndentry; | |
3285 | + aufs_bindex_t bstart, bend; | |
1facf9fc | 3286 | + struct au_dcsub_pages dpages; |
3287 | + struct au_dpage *dpage; | |
3288 | + struct dentry *d; | |
1facf9fc | 3289 | + |
3290 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
3291 | + if (unlikely(err)) | |
3292 | + goto out; | |
3293 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); | |
3294 | + if (unlikely(err)) | |
3295 | + goto out_dpages; | |
3296 | + | |
1facf9fc | 3297 | + for (i = 0; !err && i < dpages.ndpage; i++) { |
3298 | + dpage = dpages.dpages + i; | |
3299 | + ndentry = dpage->ndentry; | |
3300 | + for (j = 0; !err && j < ndentry; j++) { | |
3301 | + d = dpage->dentries[j]; | |
c1595e42 | 3302 | + AuDebugOn(au_dcount(d) <= 0); |
027c5e7a | 3303 | + if (!au_digen_test(d, sigen)) { |
1facf9fc | 3304 | + di_read_lock_child(d, AuLock_IR); |
027c5e7a AM |
3305 | + if (unlikely(au_dbrange_test(d))) { |
3306 | + di_read_unlock(d, AuLock_IR); | |
3307 | + continue; | |
3308 | + } | |
3309 | + } else { | |
1facf9fc | 3310 | + di_write_lock_child(d); |
027c5e7a AM |
3311 | + if (unlikely(au_dbrange_test(d))) { |
3312 | + di_write_unlock(d); | |
3313 | + continue; | |
3314 | + } | |
1facf9fc | 3315 | + err = au_reval_dpath(d, sigen); |
3316 | + if (!err) | |
3317 | + di_downgrade_lock(d, AuLock_IR); | |
3318 | + else { | |
3319 | + di_write_unlock(d); | |
3320 | + break; | |
3321 | + } | |
3322 | + } | |
3323 | + | |
027c5e7a | 3324 | + /* AuDbgDentry(d); */ |
1facf9fc | 3325 | + bstart = au_dbstart(d); |
3326 | + bend = au_dbend(d); | |
3327 | + if (bstart <= bindex | |
3328 | + && bindex <= bend | |
3329 | + && au_h_dptr(d, bindex) | |
027c5e7a | 3330 | + && au_test_dbusy(d, bstart, bend)) { |
1facf9fc | 3331 | + err = -EBUSY; |
523b37e3 | 3332 | + AuVerbose(verbose, "busy %pd\n", d); |
027c5e7a | 3333 | + AuDbgDentry(d); |
1facf9fc | 3334 | + } |
3335 | + di_read_unlock(d, AuLock_IR); | |
3336 | + } | |
3337 | + } | |
3338 | + | |
4f0767ce | 3339 | +out_dpages: |
1facf9fc | 3340 | + au_dpages_free(&dpages); |
4f0767ce | 3341 | +out: |
1facf9fc | 3342 | + return err; |
3343 | +} | |
3344 | + | |
3345 | +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex, | |
b752ccd1 | 3346 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3347 | +{ |
3348 | + int err; | |
7f207e10 AM |
3349 | + unsigned long long max, ull; |
3350 | + struct inode *i, **array; | |
1facf9fc | 3351 | + aufs_bindex_t bstart, bend; |
1facf9fc | 3352 | + |
7f207e10 AM |
3353 | + array = au_iarray_alloc(sb, &max); |
3354 | + err = PTR_ERR(array); | |
3355 | + if (IS_ERR(array)) | |
3356 | + goto out; | |
3357 | + | |
1facf9fc | 3358 | + err = 0; |
7f207e10 AM |
3359 | + AuDbg("b%d\n", bindex); |
3360 | + for (ull = 0; !err && ull < max; ull++) { | |
3361 | + i = array[ull]; | |
076b876e AM |
3362 | + if (unlikely(!i)) |
3363 | + break; | |
7f207e10 | 3364 | + if (i->i_ino == AUFS_ROOT_INO) |
1facf9fc | 3365 | + continue; |
3366 | + | |
7f207e10 | 3367 | + /* AuDbgInode(i); */ |
537831f9 | 3368 | + if (au_iigen(i, NULL) == sigen) |
1facf9fc | 3369 | + ii_read_lock_child(i); |
3370 | + else { | |
3371 | + ii_write_lock_child(i); | |
027c5e7a AM |
3372 | + err = au_refresh_hinode_self(i); |
3373 | + au_iigen_dec(i); | |
1facf9fc | 3374 | + if (!err) |
3375 | + ii_downgrade_lock(i); | |
3376 | + else { | |
3377 | + ii_write_unlock(i); | |
3378 | + break; | |
3379 | + } | |
3380 | + } | |
3381 | + | |
3382 | + bstart = au_ibstart(i); | |
3383 | + bend = au_ibend(i); | |
3384 | + if (bstart <= bindex | |
3385 | + && bindex <= bend | |
3386 | + && au_h_iptr(i, bindex) | |
027c5e7a | 3387 | + && au_test_ibusy(i, bstart, bend)) { |
1facf9fc | 3388 | + err = -EBUSY; |
3389 | + AuVerbose(verbose, "busy i%lu\n", i->i_ino); | |
7f207e10 | 3390 | + AuDbgInode(i); |
1facf9fc | 3391 | + } |
3392 | + ii_read_unlock(i); | |
3393 | + } | |
7f207e10 | 3394 | + au_iarray_free(array, max); |
1facf9fc | 3395 | + |
7f207e10 | 3396 | +out: |
1facf9fc | 3397 | + return err; |
3398 | +} | |
3399 | + | |
b752ccd1 AM |
3400 | +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex, |
3401 | + const unsigned int verbose) | |
1facf9fc | 3402 | +{ |
3403 | + int err; | |
3404 | + unsigned int sigen; | |
3405 | + | |
3406 | + sigen = au_sigen(root->d_sb); | |
3407 | + DiMustNoWaiters(root); | |
3408 | + IiMustNoWaiters(root->d_inode); | |
3409 | + di_write_unlock(root); | |
b752ccd1 | 3410 | + err = test_dentry_busy(root, bindex, sigen, verbose); |
1facf9fc | 3411 | + if (!err) |
b752ccd1 | 3412 | + err = test_inode_busy(root->d_sb, bindex, sigen, verbose); |
1facf9fc | 3413 | + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */ |
3414 | + | |
3415 | + return err; | |
3416 | +} | |
3417 | + | |
076b876e AM |
3418 | +static int test_dir_busy(struct file *file, aufs_bindex_t br_id, |
3419 | + struct file **to_free, int *idx) | |
3420 | +{ | |
3421 | + int err; | |
c1595e42 | 3422 | + unsigned char matched, root; |
076b876e AM |
3423 | + aufs_bindex_t bindex, bend; |
3424 | + struct au_fidir *fidir; | |
3425 | + struct au_hfile *hfile; | |
3426 | + | |
3427 | + err = 0; | |
c1595e42 JR |
3428 | + root = IS_ROOT(file->f_dentry); |
3429 | + if (root) { | |
3430 | + get_file(file); | |
3431 | + to_free[*idx] = file; | |
3432 | + (*idx)++; | |
3433 | + goto out; | |
3434 | + } | |
3435 | + | |
076b876e | 3436 | + matched = 0; |
076b876e AM |
3437 | + fidir = au_fi(file)->fi_hdir; |
3438 | + AuDebugOn(!fidir); | |
3439 | + bend = au_fbend_dir(file); | |
3440 | + for (bindex = au_fbstart(file); bindex <= bend; bindex++) { | |
3441 | + hfile = fidir->fd_hfile + bindex; | |
3442 | + if (!hfile->hf_file) | |
3443 | + continue; | |
3444 | + | |
c1595e42 | 3445 | + if (hfile->hf_br->br_id == br_id) { |
076b876e | 3446 | + matched = 1; |
076b876e | 3447 | + break; |
c1595e42 | 3448 | + } |
076b876e | 3449 | + } |
c1595e42 | 3450 | + if (matched) |
076b876e AM |
3451 | + err = -EBUSY; |
3452 | + | |
3453 | +out: | |
3454 | + return err; | |
3455 | +} | |
3456 | + | |
3457 | +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id, | |
3458 | + struct file **to_free, int opened) | |
3459 | +{ | |
3460 | + int err, idx; | |
3461 | + unsigned long long ull, max; | |
3462 | + aufs_bindex_t bstart; | |
3463 | + struct file *file, **array; | |
3464 | + struct inode *inode; | |
3465 | + struct dentry *root; | |
3466 | + struct au_hfile *hfile; | |
3467 | + | |
3468 | + array = au_farray_alloc(sb, &max); | |
3469 | + err = PTR_ERR(array); | |
3470 | + if (IS_ERR(array)) | |
3471 | + goto out; | |
3472 | + | |
3473 | + err = 0; | |
3474 | + idx = 0; | |
3475 | + root = sb->s_root; | |
3476 | + di_write_unlock(root); | |
3477 | + for (ull = 0; ull < max; ull++) { | |
3478 | + file = array[ull]; | |
3479 | + if (unlikely(!file)) | |
3480 | + break; | |
3481 | + | |
3482 | + /* AuDbg("%pD\n", file); */ | |
3483 | + fi_read_lock(file); | |
3484 | + bstart = au_fbstart(file); | |
3485 | + inode = file_inode(file); | |
3486 | + if (!S_ISDIR(inode->i_mode)) { | |
3487 | + hfile = &au_fi(file)->fi_htop; | |
3488 | + if (hfile->hf_br->br_id == br_id) | |
3489 | + err = -EBUSY; | |
3490 | + } else | |
3491 | + err = test_dir_busy(file, br_id, to_free, &idx); | |
3492 | + fi_read_unlock(file); | |
3493 | + if (unlikely(err)) | |
3494 | + break; | |
3495 | + } | |
3496 | + di_write_lock_child(root); | |
3497 | + au_farray_free(array, max); | |
3498 | + AuDebugOn(idx > opened); | |
3499 | + | |
3500 | +out: | |
3501 | + return err; | |
3502 | +} | |
3503 | + | |
3504 | +static void br_del_file(struct file **to_free, unsigned long long opened, | |
3505 | + aufs_bindex_t br_id) | |
3506 | +{ | |
3507 | + unsigned long long ull; | |
3508 | + aufs_bindex_t bindex, bstart, bend, bfound; | |
3509 | + struct file *file; | |
3510 | + struct au_fidir *fidir; | |
3511 | + struct au_hfile *hfile; | |
3512 | + | |
3513 | + for (ull = 0; ull < opened; ull++) { | |
3514 | + file = to_free[ull]; | |
3515 | + if (unlikely(!file)) | |
3516 | + break; | |
3517 | + | |
3518 | + /* AuDbg("%pD\n", file); */ | |
3519 | + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode)); | |
3520 | + bfound = -1; | |
3521 | + fidir = au_fi(file)->fi_hdir; | |
3522 | + AuDebugOn(!fidir); | |
3523 | + fi_write_lock(file); | |
3524 | + bstart = au_fbstart(file); | |
3525 | + bend = au_fbend_dir(file); | |
3526 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
3527 | + hfile = fidir->fd_hfile + bindex; | |
3528 | + if (!hfile->hf_file) | |
3529 | + continue; | |
3530 | + | |
3531 | + if (hfile->hf_br->br_id == br_id) { | |
3532 | + bfound = bindex; | |
3533 | + break; | |
3534 | + } | |
3535 | + } | |
3536 | + AuDebugOn(bfound < 0); | |
3537 | + au_set_h_fptr(file, bfound, NULL); | |
3538 | + if (bfound == bstart) { | |
3539 | + for (bstart++; bstart <= bend; bstart++) | |
3540 | + if (au_hf_dir(file, bstart)) { | |
3541 | + au_set_fbstart(file, bstart); | |
3542 | + break; | |
3543 | + } | |
3544 | + } | |
3545 | + fi_write_unlock(file); | |
3546 | + } | |
3547 | +} | |
3548 | + | |
1facf9fc | 3549 | +static void au_br_do_del_brp(struct au_sbinfo *sbinfo, |
3550 | + const aufs_bindex_t bindex, | |
3551 | + const aufs_bindex_t bend) | |
3552 | +{ | |
3553 | + struct au_branch **brp, **p; | |
3554 | + | |
dece6358 AM |
3555 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3556 | + | |
1facf9fc | 3557 | + brp = sbinfo->si_branch + bindex; |
3558 | + if (bindex < bend) | |
3559 | + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex)); | |
3560 | + sbinfo->si_branch[0 + bend] = NULL; | |
3561 | + sbinfo->si_bend--; | |
3562 | + | |
53392da6 | 3563 | + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3564 | + if (p) |
3565 | + sbinfo->si_branch = p; | |
4a4d8108 | 3566 | + /* harmless error */ |
1facf9fc | 3567 | +} |
3568 | + | |
3569 | +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex, | |
3570 | + const aufs_bindex_t bend) | |
3571 | +{ | |
3572 | + struct au_hdentry *hdp, *p; | |
3573 | + | |
1308ab2a | 3574 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3575 | + | |
4a4d8108 | 3576 | + hdp = dinfo->di_hdentry; |
1facf9fc | 3577 | + if (bindex < bend) |
4a4d8108 AM |
3578 | + memmove(hdp + bindex, hdp + bindex + 1, |
3579 | + sizeof(*hdp) * (bend - bindex)); | |
3580 | + hdp[0 + bend].hd_dentry = NULL; | |
1facf9fc | 3581 | + dinfo->di_bend--; |
3582 | + | |
53392da6 | 3583 | + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3584 | + if (p) |
3585 | + dinfo->di_hdentry = p; | |
4a4d8108 | 3586 | + /* harmless error */ |
1facf9fc | 3587 | +} |
3588 | + | |
3589 | +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex, | |
3590 | + const aufs_bindex_t bend) | |
3591 | +{ | |
3592 | + struct au_hinode *hip, *p; | |
3593 | + | |
1308ab2a | 3594 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3595 | + | |
1facf9fc | 3596 | + hip = iinfo->ii_hinode + bindex; |
3597 | + if (bindex < bend) | |
3598 | + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex)); | |
3599 | + iinfo->ii_hinode[0 + bend].hi_inode = NULL; | |
4a4d8108 | 3600 | + au_hn_init(iinfo->ii_hinode + bend); |
1facf9fc | 3601 | + iinfo->ii_bend--; |
3602 | + | |
53392da6 | 3603 | + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST); |
1facf9fc | 3604 | + if (p) |
3605 | + iinfo->ii_hinode = p; | |
4a4d8108 | 3606 | + /* harmless error */ |
1facf9fc | 3607 | +} |
3608 | + | |
3609 | +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex, | |
3610 | + struct au_branch *br) | |
3611 | +{ | |
3612 | + aufs_bindex_t bend; | |
3613 | + struct au_sbinfo *sbinfo; | |
53392da6 AM |
3614 | + struct dentry *root, *h_root; |
3615 | + struct inode *inode, *h_inode; | |
3616 | + struct au_hinode *hinode; | |
1facf9fc | 3617 | + |
dece6358 AM |
3618 | + SiMustWriteLock(sb); |
3619 | + | |
1facf9fc | 3620 | + root = sb->s_root; |
3621 | + inode = root->d_inode; | |
1facf9fc | 3622 | + sbinfo = au_sbi(sb); |
3623 | + bend = sbinfo->si_bend; | |
3624 | + | |
53392da6 AM |
3625 | + h_root = au_h_dptr(root, bindex); |
3626 | + hinode = au_hi(inode, bindex); | |
3627 | + h_inode = au_igrab(hinode->hi_inode); | |
3628 | + au_hiput(hinode); | |
1facf9fc | 3629 | + |
53392da6 | 3630 | + au_sbilist_lock(); |
1facf9fc | 3631 | + au_br_do_del_brp(sbinfo, bindex, bend); |
3632 | + au_br_do_del_hdp(au_di(root), bindex, bend); | |
3633 | + au_br_do_del_hip(au_ii(inode), bindex, bend); | |
53392da6 AM |
3634 | + au_sbilist_unlock(); |
3635 | + | |
3636 | + dput(h_root); | |
3637 | + iput(h_inode); | |
3638 | + au_br_do_free(br); | |
1facf9fc | 3639 | +} |
3640 | + | |
076b876e AM |
3641 | +static unsigned long long empty_cb(void *array, unsigned long long max, |
3642 | + void *arg) | |
3643 | +{ | |
3644 | + return max; | |
3645 | +} | |
3646 | + | |
1facf9fc | 3647 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount) |
3648 | +{ | |
3649 | + int err, rerr, i; | |
076b876e | 3650 | + unsigned long long opened; |
1facf9fc | 3651 | + unsigned int mnt_flags; |
3652 | + aufs_bindex_t bindex, bend, br_id; | |
3653 | + unsigned char do_wh, verbose; | |
3654 | + struct au_branch *br; | |
3655 | + struct au_wbr *wbr; | |
076b876e AM |
3656 | + struct dentry *root; |
3657 | + struct file **to_free; | |
1facf9fc | 3658 | + |
3659 | + err = 0; | |
076b876e AM |
3660 | + opened = 0; |
3661 | + to_free = NULL; | |
3662 | + root = sb->s_root; | |
3663 | + bindex = au_find_dbindex(root, del->h_path.dentry); | |
1facf9fc | 3664 | + if (bindex < 0) { |
3665 | + if (remount) | |
3666 | + goto out; /* success */ | |
3667 | + err = -ENOENT; | |
4a4d8108 | 3668 | + pr_err("%s no such branch\n", del->pathname); |
1facf9fc | 3669 | + goto out; |
3670 | + } | |
3671 | + AuDbg("bindex b%d\n", bindex); | |
3672 | + | |
3673 | + err = -EBUSY; | |
3674 | + mnt_flags = au_mntflags(sb); | |
3675 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
3676 | + bend = au_sbend(sb); | |
3677 | + if (unlikely(!bend)) { | |
3678 | + AuVerbose(verbose, "no more branches left\n"); | |
3679 | + goto out; | |
3680 | + } | |
3681 | + br = au_sbr(sb, bindex); | |
86dc4139 | 3682 | + AuDebugOn(!path_equal(&br->br_path, &del->h_path)); |
076b876e AM |
3683 | + |
3684 | + br_id = br->br_id; | |
3685 | + opened = atomic_read(&br->br_count); | |
3686 | + if (unlikely(opened)) { | |
3687 | + to_free = au_array_alloc(&opened, empty_cb, NULL); | |
3688 | + err = PTR_ERR(to_free); | |
3689 | + if (IS_ERR(to_free)) | |
3690 | + goto out; | |
3691 | + | |
3692 | + err = test_file_busy(sb, br_id, to_free, opened); | |
3693 | + if (unlikely(err)) { | |
3694 | + AuVerbose(verbose, "%llu file(s) opened\n", opened); | |
3695 | + goto out; | |
3696 | + } | |
1facf9fc | 3697 | + } |
3698 | + | |
3699 | + wbr = br->br_wbr; | |
3700 | + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph); | |
3701 | + if (do_wh) { | |
1308ab2a | 3702 | + /* instead of WbrWhMustWriteLock(wbr) */ |
3703 | + SiMustWriteLock(sb); | |
1facf9fc | 3704 | + for (i = 0; i < AuBrWh_Last; i++) { |
3705 | + dput(wbr->wbr_wh[i]); | |
3706 | + wbr->wbr_wh[i] = NULL; | |
3707 | + } | |
3708 | + } | |
3709 | + | |
076b876e | 3710 | + err = test_children_busy(root, bindex, verbose); |
1facf9fc | 3711 | + if (unlikely(err)) { |
3712 | + if (do_wh) | |
3713 | + goto out_wh; | |
3714 | + goto out; | |
3715 | + } | |
3716 | + | |
3717 | + err = 0; | |
076b876e AM |
3718 | + if (to_free) { |
3719 | + /* | |
3720 | + * now we confirmed the branch is deletable. | |
3721 | + * let's free the remaining opened dirs on the branch. | |
3722 | + */ | |
3723 | + di_write_unlock(root); | |
3724 | + br_del_file(to_free, opened, br_id); | |
3725 | + di_write_lock_child(root); | |
3726 | + } | |
3727 | + | |
1facf9fc | 3728 | + if (!remount) |
3729 | + au_br_do_del(sb, bindex, br); | |
3730 | + else { | |
3731 | + sysaufs_brs_del(sb, bindex); | |
3732 | + au_br_do_del(sb, bindex, br); | |
3733 | + sysaufs_brs_add(sb, bindex); | |
3734 | + } | |
3735 | + | |
1308ab2a | 3736 | + if (!bindex) { |
076b876e | 3737 | + au_cpup_attr_all(root->d_inode, /*force*/1); |
1308ab2a | 3738 | + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes; |
3739 | + } else | |
076b876e | 3740 | + au_sub_nlink(root->d_inode, del->h_path.dentry->d_inode); |
1facf9fc | 3741 | + if (au_opt_test(mnt_flags, PLINK)) |
3742 | + au_plink_half_refresh(sb, br_id); | |
3743 | + | |
b752ccd1 | 3744 | + if (au_xino_brid(sb) == br_id) |
1facf9fc | 3745 | + au_xino_brid_set(sb, -1); |
3746 | + goto out; /* success */ | |
3747 | + | |
4f0767ce | 3748 | +out_wh: |
1facf9fc | 3749 | + /* revert */ |
86dc4139 | 3750 | + rerr = au_br_init_wh(sb, br, br->br_perm); |
1facf9fc | 3751 | + if (rerr) |
0c3ec466 AM |
3752 | + pr_warn("failed re-creating base whiteout, %s. (%d)\n", |
3753 | + del->pathname, rerr); | |
4f0767ce | 3754 | +out: |
076b876e AM |
3755 | + if (to_free) |
3756 | + au_farray_free(to_free, opened); | |
1facf9fc | 3757 | + return err; |
3758 | +} | |
3759 | + | |
3760 | +/* ---------------------------------------------------------------------- */ | |
3761 | + | |
027c5e7a AM |
3762 | +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg) |
3763 | +{ | |
3764 | + int err; | |
3765 | + aufs_bindex_t bstart, bend; | |
3766 | + struct aufs_ibusy ibusy; | |
3767 | + struct inode *inode, *h_inode; | |
3768 | + | |
3769 | + err = -EPERM; | |
3770 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
3771 | + goto out; | |
3772 | + | |
3773 | + err = copy_from_user(&ibusy, arg, sizeof(ibusy)); | |
3774 | + if (!err) | |
3775 | + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino)); | |
3776 | + if (unlikely(err)) { | |
3777 | + err = -EFAULT; | |
3778 | + AuTraceErr(err); | |
3779 | + goto out; | |
3780 | + } | |
3781 | + | |
3782 | + err = -EINVAL; | |
3783 | + si_read_lock(sb, AuLock_FLUSH); | |
3784 | + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb))) | |
3785 | + goto out_unlock; | |
3786 | + | |
3787 | + err = 0; | |
3788 | + ibusy.h_ino = 0; /* invalid */ | |
3789 | + inode = ilookup(sb, ibusy.ino); | |
3790 | + if (!inode | |
3791 | + || inode->i_ino == AUFS_ROOT_INO | |
3792 | + || is_bad_inode(inode)) | |
3793 | + goto out_unlock; | |
3794 | + | |
3795 | + ii_read_lock_child(inode); | |
3796 | + bstart = au_ibstart(inode); | |
3797 | + bend = au_ibend(inode); | |
3798 | + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) { | |
3799 | + h_inode = au_h_iptr(inode, ibusy.bindex); | |
3800 | + if (h_inode && au_test_ibusy(inode, bstart, bend)) | |
3801 | + ibusy.h_ino = h_inode->i_ino; | |
3802 | + } | |
3803 | + ii_read_unlock(inode); | |
3804 | + iput(inode); | |
3805 | + | |
3806 | +out_unlock: | |
3807 | + si_read_unlock(sb); | |
3808 | + if (!err) { | |
3809 | + err = __put_user(ibusy.h_ino, &arg->h_ino); | |
3810 | + if (unlikely(err)) { | |
3811 | + err = -EFAULT; | |
3812 | + AuTraceErr(err); | |
3813 | + } | |
3814 | + } | |
3815 | +out: | |
3816 | + return err; | |
3817 | +} | |
3818 | + | |
3819 | +long au_ibusy_ioctl(struct file *file, unsigned long arg) | |
3820 | +{ | |
3821 | + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg); | |
3822 | +} | |
3823 | + | |
3824 | +#ifdef CONFIG_COMPAT | |
3825 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg) | |
3826 | +{ | |
3827 | + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg)); | |
3828 | +} | |
3829 | +#endif | |
3830 | + | |
3831 | +/* ---------------------------------------------------------------------- */ | |
3832 | + | |
1facf9fc | 3833 | +/* |
3834 | + * change a branch permission | |
3835 | + */ | |
3836 | + | |
dece6358 AM |
3837 | +static void au_warn_ima(void) |
3838 | +{ | |
3839 | +#ifdef CONFIG_IMA | |
1308ab2a | 3840 | + /* since it doesn't support mark_files_ro() */ |
027c5e7a | 3841 | + AuWarn1("RW -> RO makes IMA to produce wrong message\n"); |
dece6358 AM |
3842 | +#endif |
3843 | +} | |
3844 | + | |
1facf9fc | 3845 | +static int do_need_sigen_inc(int a, int b) |
3846 | +{ | |
3847 | + return au_br_whable(a) && !au_br_whable(b); | |
3848 | +} | |
3849 | + | |
3850 | +static int need_sigen_inc(int old, int new) | |
3851 | +{ | |
3852 | + return do_need_sigen_inc(old, new) | |
3853 | + || do_need_sigen_inc(new, old); | |
3854 | +} | |
3855 | + | |
3856 | +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex) | |
3857 | +{ | |
7f207e10 | 3858 | + int err, do_warn; |
027c5e7a | 3859 | + unsigned int mnt_flags; |
7f207e10 | 3860 | + unsigned long long ull, max; |
e49829fe | 3861 | + aufs_bindex_t br_id; |
38d290e6 | 3862 | + unsigned char verbose, writer; |
7f207e10 | 3863 | + struct file *file, *hf, **array; |
e49829fe JR |
3864 | + struct inode *inode; |
3865 | + struct au_hfile *hfile; | |
1facf9fc | 3866 | + |
027c5e7a AM |
3867 | + mnt_flags = au_mntflags(sb); |
3868 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
3869 | + | |
7f207e10 AM |
3870 | + array = au_farray_alloc(sb, &max); |
3871 | + err = PTR_ERR(array); | |
3872 | + if (IS_ERR(array)) | |
1facf9fc | 3873 | + goto out; |
3874 | + | |
7f207e10 | 3875 | + do_warn = 0; |
e49829fe | 3876 | + br_id = au_sbr_id(sb, bindex); |
7f207e10 AM |
3877 | + for (ull = 0; ull < max; ull++) { |
3878 | + file = array[ull]; | |
076b876e AM |
3879 | + if (unlikely(!file)) |
3880 | + break; | |
1facf9fc | 3881 | + |
523b37e3 | 3882 | + /* AuDbg("%pD\n", file); */ |
1facf9fc | 3883 | + fi_read_lock(file); |
3884 | + if (unlikely(au_test_mmapped(file))) { | |
3885 | + err = -EBUSY; | |
523b37e3 | 3886 | + AuVerbose(verbose, "mmapped %pD\n", file); |
7f207e10 | 3887 | + AuDbgFile(file); |
1facf9fc | 3888 | + FiMustNoWaiters(file); |
3889 | + fi_read_unlock(file); | |
7f207e10 | 3890 | + goto out_array; |
1facf9fc | 3891 | + } |
3892 | + | |
c06a8ce3 | 3893 | + inode = file_inode(file); |
e49829fe JR |
3894 | + hfile = &au_fi(file)->fi_htop; |
3895 | + hf = hfile->hf_file; | |
3896 | + if (!S_ISREG(inode->i_mode) | |
1facf9fc | 3897 | + || !(file->f_mode & FMODE_WRITE) |
e49829fe | 3898 | + || hfile->hf_br->br_id != br_id |
7f207e10 AM |
3899 | + || !(hf->f_mode & FMODE_WRITE)) |
3900 | + array[ull] = NULL; | |
3901 | + else { | |
3902 | + do_warn = 1; | |
3903 | + get_file(file); | |
1facf9fc | 3904 | + } |
3905 | + | |
1facf9fc | 3906 | + FiMustNoWaiters(file); |
3907 | + fi_read_unlock(file); | |
7f207e10 AM |
3908 | + fput(file); |
3909 | + } | |
1facf9fc | 3910 | + |
3911 | + err = 0; | |
7f207e10 | 3912 | + if (do_warn) |
dece6358 | 3913 | + au_warn_ima(); |
7f207e10 AM |
3914 | + |
3915 | + for (ull = 0; ull < max; ull++) { | |
3916 | + file = array[ull]; | |
3917 | + if (!file) | |
3918 | + continue; | |
3919 | + | |
1facf9fc | 3920 | + /* todo: already flushed? */ |
523b37e3 AM |
3921 | + /* |
3922 | + * fs/super.c:mark_files_ro() is gone, but aufs keeps its | |
3923 | + * approach which resets f_mode and calls mnt_drop_write() and | |
3924 | + * file_release_write() for each file, because the branch | |
3925 | + * attribute in aufs world is totally different from the native | |
3926 | + * fs rw/ro mode. | |
3927 | + */ | |
7f207e10 AM |
3928 | + /* fi_read_lock(file); */ |
3929 | + hfile = &au_fi(file)->fi_htop; | |
3930 | + hf = hfile->hf_file; | |
3931 | + /* fi_read_unlock(file); */ | |
027c5e7a | 3932 | + spin_lock(&hf->f_lock); |
38d290e6 JR |
3933 | + writer = !!(hf->f_mode & FMODE_WRITER); |
3934 | + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER); | |
027c5e7a | 3935 | + spin_unlock(&hf->f_lock); |
38d290e6 JR |
3936 | + if (writer) { |
3937 | + put_write_access(file_inode(hf)); | |
c06a8ce3 | 3938 | + __mnt_drop_write(hf->f_path.mnt); |
1facf9fc | 3939 | + } |
3940 | + } | |
3941 | + | |
7f207e10 AM |
3942 | +out_array: |
3943 | + au_farray_free(array, max); | |
4f0767ce | 3944 | +out: |
7f207e10 | 3945 | + AuTraceErr(err); |
1facf9fc | 3946 | + return err; |
3947 | +} | |
3948 | + | |
3949 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 3950 | + int *do_refresh) |
1facf9fc | 3951 | +{ |
3952 | + int err, rerr; | |
3953 | + aufs_bindex_t bindex; | |
3954 | + struct dentry *root; | |
3955 | + struct au_branch *br; | |
076b876e | 3956 | + struct au_br_fhsm *bf; |
1facf9fc | 3957 | + |
3958 | + root = sb->s_root; | |
1facf9fc | 3959 | + bindex = au_find_dbindex(root, mod->h_root); |
3960 | + if (bindex < 0) { | |
3961 | + if (remount) | |
3962 | + return 0; /* success */ | |
3963 | + err = -ENOENT; | |
4a4d8108 | 3964 | + pr_err("%s no such branch\n", mod->path); |
1facf9fc | 3965 | + goto out; |
3966 | + } | |
3967 | + AuDbg("bindex b%d\n", bindex); | |
3968 | + | |
3969 | + err = test_br(mod->h_root->d_inode, mod->perm, mod->path); | |
3970 | + if (unlikely(err)) | |
3971 | + goto out; | |
3972 | + | |
3973 | + br = au_sbr(sb, bindex); | |
86dc4139 | 3974 | + AuDebugOn(mod->h_root != au_br_dentry(br)); |
1facf9fc | 3975 | + if (br->br_perm == mod->perm) |
3976 | + return 0; /* success */ | |
3977 | + | |
076b876e AM |
3978 | + /* pre-allocate for non-fhsm --> fhsm */ |
3979 | + bf = NULL; | |
3980 | + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) { | |
3981 | + err = au_fhsm_br_alloc(br); | |
3982 | + if (unlikely(err)) | |
3983 | + goto out; | |
3984 | + bf = br->br_fhsm; | |
3985 | + br->br_fhsm = NULL; | |
3986 | + } | |
3987 | + | |
1facf9fc | 3988 | + if (au_br_writable(br->br_perm)) { |
3989 | + /* remove whiteout base */ | |
86dc4139 | 3990 | + err = au_br_init_wh(sb, br, mod->perm); |
1facf9fc | 3991 | + if (unlikely(err)) |
076b876e | 3992 | + goto out_bf; |
1facf9fc | 3993 | + |
3994 | + if (!au_br_writable(mod->perm)) { | |
3995 | + /* rw --> ro, file might be mmapped */ | |
3996 | + DiMustNoWaiters(root); | |
3997 | + IiMustNoWaiters(root->d_inode); | |
3998 | + di_write_unlock(root); | |
3999 | + err = au_br_mod_files_ro(sb, bindex); | |
4000 | + /* aufs_write_lock() calls ..._child() */ | |
4001 | + di_write_lock_child(root); | |
4002 | + | |
4003 | + if (unlikely(err)) { | |
4004 | + rerr = -ENOMEM; | |
4005 | + br->br_wbr = kmalloc(sizeof(*br->br_wbr), | |
4006 | + GFP_NOFS); | |
86dc4139 AM |
4007 | + if (br->br_wbr) |
4008 | + rerr = au_wbr_init(br, sb, br->br_perm); | |
1facf9fc | 4009 | + if (unlikely(rerr)) { |
4010 | + AuIOErr("nested error %d (%d)\n", | |
4011 | + rerr, err); | |
4012 | + br->br_perm = mod->perm; | |
4013 | + } | |
4014 | + } | |
4015 | + } | |
4016 | + } else if (au_br_writable(mod->perm)) { | |
4017 | + /* ro --> rw */ | |
4018 | + err = -ENOMEM; | |
4019 | + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS); | |
4020 | + if (br->br_wbr) { | |
86dc4139 | 4021 | + err = au_wbr_init(br, sb, mod->perm); |
1facf9fc | 4022 | + if (unlikely(err)) { |
4023 | + kfree(br->br_wbr); | |
4024 | + br->br_wbr = NULL; | |
4025 | + } | |
4026 | + } | |
4027 | + } | |
076b876e AM |
4028 | + if (unlikely(err)) |
4029 | + goto out_bf; | |
4030 | + | |
4031 | + if (au_br_fhsm(br->br_perm)) { | |
4032 | + if (!au_br_fhsm(mod->perm)) { | |
4033 | + /* fhsm --> non-fhsm */ | |
4034 | + au_br_fhsm_fin(br->br_fhsm); | |
4035 | + kfree(br->br_fhsm); | |
4036 | + br->br_fhsm = NULL; | |
4037 | + } | |
4038 | + } else if (au_br_fhsm(mod->perm)) | |
4039 | + /* non-fhsm --> fhsm */ | |
4040 | + br->br_fhsm = bf; | |
4041 | + | |
076b876e AM |
4042 | + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm); |
4043 | + br->br_perm = mod->perm; | |
4044 | + goto out; /* success */ | |
1facf9fc | 4045 | + |
076b876e AM |
4046 | +out_bf: |
4047 | + kfree(bf); | |
4048 | +out: | |
4049 | + AuTraceErr(err); | |
4050 | + return err; | |
4051 | +} | |
4052 | + | |
4053 | +/* ---------------------------------------------------------------------- */ | |
4054 | + | |
4055 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs) | |
4056 | +{ | |
4057 | + int err; | |
4058 | + struct kstatfs kstfs; | |
4059 | + | |
4060 | + err = vfs_statfs(&br->br_path, &kstfs); | |
1facf9fc | 4061 | + if (!err) { |
076b876e AM |
4062 | + stfs->f_blocks = kstfs.f_blocks; |
4063 | + stfs->f_bavail = kstfs.f_bavail; | |
4064 | + stfs->f_files = kstfs.f_files; | |
4065 | + stfs->f_ffree = kstfs.f_ffree; | |
1facf9fc | 4066 | + } |
4067 | + | |
1facf9fc | 4068 | + return err; |
4069 | +} | |
7f207e10 AM |
4070 | diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h |
4071 | --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
4072 | +++ linux/fs/aufs/branch.h 2015-01-25 13:00:38.627713742 +0100 |
4073 | @@ -0,0 +1,267 @@ | |
1facf9fc | 4074 | +/* |
523b37e3 | 4075 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 4076 | + * |
4077 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4078 | + * it under the terms of the GNU General Public License as published by | |
4079 | + * the Free Software Foundation; either version 2 of the License, or | |
4080 | + * (at your option) any later version. | |
dece6358 AM |
4081 | + * |
4082 | + * This program is distributed in the hope that it will be useful, | |
4083 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4084 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4085 | + * GNU General Public License for more details. | |
4086 | + * | |
4087 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4088 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4089 | + */ |
4090 | + | |
4091 | +/* | |
4092 | + * branch filesystems and xino for them | |
4093 | + */ | |
4094 | + | |
4095 | +#ifndef __AUFS_BRANCH_H__ | |
4096 | +#define __AUFS_BRANCH_H__ | |
4097 | + | |
4098 | +#ifdef __KERNEL__ | |
4099 | + | |
1facf9fc | 4100 | +#include <linux/mount.h> |
4a4d8108 | 4101 | +#include "dynop.h" |
1facf9fc | 4102 | +#include "rwsem.h" |
4103 | +#include "super.h" | |
4104 | + | |
4105 | +/* ---------------------------------------------------------------------- */ | |
4106 | + | |
4107 | +/* a xino file */ | |
4108 | +struct au_xino_file { | |
4109 | + struct file *xi_file; | |
4110 | + struct mutex xi_nondir_mtx; | |
4111 | + | |
4112 | + /* todo: make xino files an array to support huge inode number */ | |
4113 | + | |
4114 | +#ifdef CONFIG_DEBUG_FS | |
4115 | + struct dentry *xi_dbgaufs; | |
4116 | +#endif | |
4117 | +}; | |
4118 | + | |
076b876e AM |
4119 | +/* File-based Hierarchical Storage Management */ |
4120 | +struct au_br_fhsm { | |
4121 | +#ifdef CONFIG_AUFS_FHSM | |
4122 | + struct mutex bf_lock; | |
4123 | + unsigned long bf_jiffy; | |
4124 | + struct aufs_stfs bf_stfs; | |
4125 | + int bf_readable; | |
4126 | +#endif | |
4127 | +}; | |
4128 | + | |
1facf9fc | 4129 | +/* members for writable branch only */ |
4130 | +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last}; | |
4131 | +struct au_wbr { | |
dece6358 | 4132 | + struct au_rwsem wbr_wh_rwsem; |
1facf9fc | 4133 | + struct dentry *wbr_wh[AuBrWh_Last]; |
4a4d8108 | 4134 | + atomic_t wbr_wh_running; |
1facf9fc | 4135 | +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */ |
4136 | +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */ | |
4137 | +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */ | |
4138 | + | |
4139 | + /* mfs mode */ | |
4140 | + unsigned long long wbr_bytes; | |
4141 | +}; | |
4142 | + | |
4a4d8108 AM |
4143 | +/* ext2 has 3 types of operations at least, ext3 has 4 */ |
4144 | +#define AuBrDynOp (AuDyLast * 4) | |
4145 | + | |
1716fcea AM |
4146 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
4147 | +/* support for asynchronous destruction */ | |
4148 | +struct au_br_hfsnotify { | |
4149 | + struct fsnotify_group *hfsn_group; | |
4150 | +}; | |
4151 | +#endif | |
4152 | + | |
392086de AM |
4153 | +/* sysfs entries */ |
4154 | +struct au_brsysfs { | |
4155 | + char name[16]; | |
4156 | + struct attribute attr; | |
4157 | +}; | |
4158 | + | |
4159 | +enum { | |
4160 | + AuBrSysfs_BR, | |
4161 | + AuBrSysfs_BRID, | |
4162 | + AuBrSysfs_Last | |
4163 | +}; | |
4164 | + | |
1facf9fc | 4165 | +/* protected by superblock rwsem */ |
4166 | +struct au_branch { | |
4167 | + struct au_xino_file br_xino; | |
4168 | + | |
4169 | + aufs_bindex_t br_id; | |
4170 | + | |
4171 | + int br_perm; | |
86dc4139 | 4172 | + struct path br_path; |
4a4d8108 AM |
4173 | + spinlock_t br_dykey_lock; |
4174 | + struct au_dykey *br_dykey[AuBrDynOp]; | |
1facf9fc | 4175 | + atomic_t br_count; |
4176 | + | |
4177 | + struct au_wbr *br_wbr; | |
076b876e | 4178 | + struct au_br_fhsm *br_fhsm; |
1facf9fc | 4179 | + |
4180 | + /* xino truncation */ | |
1facf9fc | 4181 | + atomic_t br_xino_running; |
4182 | + | |
027c5e7a | 4183 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
1716fcea | 4184 | + struct au_br_hfsnotify *br_hfsn; |
027c5e7a AM |
4185 | +#endif |
4186 | + | |
1facf9fc | 4187 | +#ifdef CONFIG_SYSFS |
392086de AM |
4188 | + /* entries under sysfs per mount-point */ |
4189 | + struct au_brsysfs br_sysfs[AuBrSysfs_Last]; | |
1facf9fc | 4190 | +#endif |
4191 | +}; | |
4192 | + | |
4193 | +/* ---------------------------------------------------------------------- */ | |
4194 | + | |
86dc4139 AM |
4195 | +static inline struct vfsmount *au_br_mnt(struct au_branch *br) |
4196 | +{ | |
4197 | + return br->br_path.mnt; | |
4198 | +} | |
4199 | + | |
4200 | +static inline struct dentry *au_br_dentry(struct au_branch *br) | |
4201 | +{ | |
4202 | + return br->br_path.dentry; | |
4203 | +} | |
4204 | + | |
4205 | +static inline struct super_block *au_br_sb(struct au_branch *br) | |
4206 | +{ | |
4207 | + return au_br_mnt(br)->mnt_sb; | |
4208 | +} | |
4209 | + | |
1facf9fc | 4210 | +static inline int au_br_rdonly(struct au_branch *br) |
4211 | +{ | |
86dc4139 | 4212 | + return ((au_br_sb(br)->s_flags & MS_RDONLY) |
1facf9fc | 4213 | + || !au_br_writable(br->br_perm)) |
4214 | + ? -EROFS : 0; | |
4215 | +} | |
4216 | + | |
4a4d8108 | 4217 | +static inline int au_br_hnotifyable(int brperm __maybe_unused) |
1facf9fc | 4218 | +{ |
4a4d8108 | 4219 | +#ifdef CONFIG_AUFS_HNOTIFY |
1e00d052 | 4220 | + return !(brperm & AuBrPerm_RR); |
1facf9fc | 4221 | +#else |
4222 | + return 0; | |
4223 | +#endif | |
4224 | +} | |
4225 | + | |
4226 | +/* ---------------------------------------------------------------------- */ | |
4227 | + | |
4228 | +/* branch.c */ | |
4229 | +struct au_sbinfo; | |
4230 | +void au_br_free(struct au_sbinfo *sinfo); | |
4231 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id); | |
4232 | +struct au_opt_add; | |
4233 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount); | |
4234 | +struct au_opt_del; | |
4235 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount); | |
027c5e7a AM |
4236 | +long au_ibusy_ioctl(struct file *file, unsigned long arg); |
4237 | +#ifdef CONFIG_COMPAT | |
4238 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg); | |
4239 | +#endif | |
1facf9fc | 4240 | +struct au_opt_mod; |
4241 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4242 | + int *do_refresh); |
076b876e AM |
4243 | +struct aufs_stfs; |
4244 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs); | |
1facf9fc | 4245 | + |
4246 | +/* xino.c */ | |
4247 | +static const loff_t au_loff_max = LLONG_MAX; | |
4248 | + | |
4249 | +int au_xib_trunc(struct super_block *sb); | |
4250 | +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size, | |
4251 | + loff_t *pos); | |
4252 | +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size, | |
4253 | + loff_t *pos); | |
4254 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src); | |
4255 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent); | |
4256 | +ino_t au_xino_new_ino(struct super_block *sb); | |
b752ccd1 | 4257 | +void au_xino_delete_inode(struct inode *inode, const int unlinked); |
1facf9fc | 4258 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
4259 | + ino_t ino); | |
4260 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4261 | + ino_t *ino); | |
4262 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino, | |
4263 | + struct file *base_file, int do_test); | |
4264 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex); | |
4265 | + | |
4266 | +struct au_opt_xino; | |
4267 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount); | |
4268 | +void au_xino_clr(struct super_block *sb); | |
4269 | +struct file *au_xino_def(struct super_block *sb); | |
4270 | +int au_xino_path(struct seq_file *seq, struct file *file); | |
4271 | + | |
4272 | +/* ---------------------------------------------------------------------- */ | |
4273 | + | |
4274 | +/* Superblock to branch */ | |
4275 | +static inline | |
4276 | +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex) | |
4277 | +{ | |
4278 | + return au_sbr(sb, bindex)->br_id; | |
4279 | +} | |
4280 | + | |
4281 | +static inline | |
4282 | +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex) | |
4283 | +{ | |
86dc4139 | 4284 | + return au_br_mnt(au_sbr(sb, bindex)); |
1facf9fc | 4285 | +} |
4286 | + | |
4287 | +static inline | |
4288 | +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex) | |
4289 | +{ | |
86dc4139 | 4290 | + return au_br_sb(au_sbr(sb, bindex)); |
1facf9fc | 4291 | +} |
4292 | + | |
4293 | +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex) | |
4294 | +{ | |
e49829fe | 4295 | + atomic_dec(&au_sbr(sb, bindex)->br_count); |
1facf9fc | 4296 | +} |
4297 | + | |
4298 | +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex) | |
4299 | +{ | |
4300 | + return au_sbr(sb, bindex)->br_perm; | |
4301 | +} | |
4302 | + | |
4303 | +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex) | |
4304 | +{ | |
4305 | + return au_br_whable(au_sbr_perm(sb, bindex)); | |
4306 | +} | |
4307 | + | |
4308 | +/* ---------------------------------------------------------------------- */ | |
4309 | + | |
4310 | +/* | |
4311 | + * wbr_wh_read_lock, wbr_wh_write_lock | |
4312 | + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock | |
4313 | + */ | |
4314 | +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem); | |
4315 | + | |
dece6358 AM |
4316 | +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem) |
4317 | +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem) | |
4318 | +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem) | |
4319 | + | |
076b876e AM |
4320 | +/* ---------------------------------------------------------------------- */ |
4321 | + | |
4322 | +#ifdef CONFIG_AUFS_FHSM | |
4323 | +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm) | |
4324 | +{ | |
4325 | + mutex_init(&brfhsm->bf_lock); | |
4326 | + brfhsm->bf_jiffy = 0; | |
4327 | + brfhsm->bf_readable = 0; | |
4328 | +} | |
4329 | + | |
4330 | +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm) | |
4331 | +{ | |
4332 | + mutex_destroy(&brfhsm->bf_lock); | |
4333 | +} | |
4334 | +#else | |
4335 | +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm) | |
4336 | +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm) | |
4337 | +#endif | |
4338 | + | |
1facf9fc | 4339 | +#endif /* __KERNEL__ */ |
4340 | +#endif /* __AUFS_BRANCH_H__ */ | |
7f207e10 AM |
4341 | diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk |
4342 | --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
4343 | +++ linux/fs/aufs/conf.mk 2015-01-25 13:00:38.631047076 +0100 |
4344 | @@ -0,0 +1,38 @@ | |
4a4d8108 AM |
4345 | + |
4346 | +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS} | |
4347 | + | |
4348 | +define AuConf | |
4349 | +ifdef ${1} | |
4350 | +AuConfStr += ${1}=${${1}} | |
4351 | +endif | |
4352 | +endef | |
4353 | + | |
b752ccd1 | 4354 | +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \ |
e49829fe | 4355 | + SBILIST \ |
7f207e10 | 4356 | + HNOTIFY HFSNOTIFY \ |
4a4d8108 | 4357 | + EXPORT INO_T_64 \ |
c1595e42 | 4358 | + XATTR \ |
076b876e | 4359 | + FHSM \ |
4a4d8108 | 4360 | + RDU \ |
4a4d8108 AM |
4361 | + SHWH \ |
4362 | + BR_RAMFS \ | |
4363 | + BR_FUSE POLL \ | |
4364 | + BR_HFSPLUS \ | |
4365 | + BDEV_LOOP \ | |
b752ccd1 AM |
4366 | + DEBUG MAGIC_SYSRQ |
4367 | +$(foreach i, ${AuConfAll}, \ | |
4a4d8108 AM |
4368 | + $(eval $(call AuConf,CONFIG_AUFS_${i}))) |
4369 | + | |
4370 | +AuConfName = ${obj}/conf.str | |
4371 | +${AuConfName}.tmp: FORCE | |
4372 | + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@ | |
4373 | +${AuConfName}: ${AuConfName}.tmp | |
4374 | + @diff -q $< $@ > /dev/null 2>&1 || { \ | |
4375 | + echo ' GEN ' $@; \ | |
4376 | + cp -p $< $@; \ | |
4377 | + } | |
4378 | +FORCE: | |
4379 | +clean-files += ${AuConfName} ${AuConfName}.tmp | |
4380 | +${obj}/sysfs.o: ${AuConfName} | |
b752ccd1 AM |
4381 | + |
4382 | +-include ${srctree}/${src}/conf_priv.mk | |
7f207e10 AM |
4383 | diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c |
4384 | --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
4385 | +++ linux/fs/aufs/cpup.c 2015-01-25 13:00:38.631047076 +0100 |
4386 | @@ -0,0 +1,1303 @@ | |
1facf9fc | 4387 | +/* |
523b37e3 | 4388 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 4389 | + * |
4390 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4391 | + * it under the terms of the GNU General Public License as published by | |
4392 | + * the Free Software Foundation; either version 2 of the License, or | |
4393 | + * (at your option) any later version. | |
dece6358 AM |
4394 | + * |
4395 | + * This program is distributed in the hope that it will be useful, | |
4396 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4397 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4398 | + * GNU General Public License for more details. | |
4399 | + * | |
4400 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4401 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4402 | + */ |
4403 | + | |
4404 | +/* | |
4405 | + * copy-up functions, see wbr_policy.c for copy-down | |
4406 | + */ | |
4407 | + | |
4408 | +#include <linux/fs_stack.h> | |
dece6358 | 4409 | +#include <linux/mm.h> |
1facf9fc | 4410 | +#include "aufs.h" |
4411 | + | |
86dc4139 | 4412 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags) |
1facf9fc | 4413 | +{ |
4414 | + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE | |
367653fa | 4415 | + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT; |
1facf9fc | 4416 | + |
86dc4139 AM |
4417 | + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags)); |
4418 | + | |
4419 | + dst->i_flags |= iflags & ~mask; | |
1facf9fc | 4420 | + if (au_test_fs_notime(dst->i_sb)) |
4421 | + dst->i_flags |= S_NOATIME | S_NOCMTIME; | |
4422 | +} | |
4423 | + | |
4424 | +void au_cpup_attr_timesizes(struct inode *inode) | |
4425 | +{ | |
4426 | + struct inode *h_inode; | |
4427 | + | |
4428 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4429 | + fsstack_copy_attr_times(inode, h_inode); | |
4a4d8108 | 4430 | + fsstack_copy_inode_size(inode, h_inode); |
1facf9fc | 4431 | +} |
4432 | + | |
4433 | +void au_cpup_attr_nlink(struct inode *inode, int force) | |
4434 | +{ | |
4435 | + struct inode *h_inode; | |
4436 | + struct super_block *sb; | |
4437 | + aufs_bindex_t bindex, bend; | |
4438 | + | |
4439 | + sb = inode->i_sb; | |
4440 | + bindex = au_ibstart(inode); | |
4441 | + h_inode = au_h_iptr(inode, bindex); | |
4442 | + if (!force | |
4443 | + && !S_ISDIR(h_inode->i_mode) | |
4444 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4445 | + && au_plink_test(inode)) | |
4446 | + return; | |
4447 | + | |
7eafdf33 AM |
4448 | + /* |
4449 | + * 0 can happen in revalidating. | |
38d290e6 JR |
4450 | + * h_inode->i_mutex may not be held here, but it is harmless since once |
4451 | + * i_nlink reaches 0, it will never become positive except O_TMPFILE | |
4452 | + * case. | |
4453 | + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause | |
4454 | + * the incorrect link count. | |
7eafdf33 | 4455 | + */ |
92d182d2 | 4456 | + set_nlink(inode, h_inode->i_nlink); |
1facf9fc | 4457 | + |
4458 | + /* | |
4459 | + * fewer nlink makes find(1) noisy, but larger nlink doesn't. | |
4460 | + * it may includes whplink directory. | |
4461 | + */ | |
4462 | + if (S_ISDIR(h_inode->i_mode)) { | |
4463 | + bend = au_ibend(inode); | |
4464 | + for (bindex++; bindex <= bend; bindex++) { | |
4465 | + h_inode = au_h_iptr(inode, bindex); | |
4466 | + if (h_inode) | |
4467 | + au_add_nlink(inode, h_inode); | |
4468 | + } | |
4469 | + } | |
4470 | +} | |
4471 | + | |
4472 | +void au_cpup_attr_changeable(struct inode *inode) | |
4473 | +{ | |
4474 | + struct inode *h_inode; | |
4475 | + | |
4476 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4477 | + inode->i_mode = h_inode->i_mode; | |
4478 | + inode->i_uid = h_inode->i_uid; | |
4479 | + inode->i_gid = h_inode->i_gid; | |
4480 | + au_cpup_attr_timesizes(inode); | |
86dc4139 | 4481 | + au_cpup_attr_flags(inode, h_inode->i_flags); |
1facf9fc | 4482 | +} |
4483 | + | |
4484 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode) | |
4485 | +{ | |
4486 | + struct au_iinfo *iinfo = au_ii(inode); | |
4487 | + | |
1308ab2a | 4488 | + IiMustWriteLock(inode); |
4489 | + | |
1facf9fc | 4490 | + iinfo->ii_higen = h_inode->i_generation; |
4491 | + iinfo->ii_hsb1 = h_inode->i_sb; | |
4492 | +} | |
4493 | + | |
4494 | +void au_cpup_attr_all(struct inode *inode, int force) | |
4495 | +{ | |
4496 | + struct inode *h_inode; | |
4497 | + | |
4498 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
4499 | + au_cpup_attr_changeable(inode); | |
4500 | + if (inode->i_nlink > 0) | |
4501 | + au_cpup_attr_nlink(inode, force); | |
4502 | + inode->i_rdev = h_inode->i_rdev; | |
4503 | + inode->i_blkbits = h_inode->i_blkbits; | |
4504 | + au_cpup_igen(inode, h_inode); | |
4505 | +} | |
4506 | + | |
4507 | +/* ---------------------------------------------------------------------- */ | |
4508 | + | |
4509 | +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */ | |
4510 | + | |
4511 | +/* keep the timestamps of the parent dir when cpup */ | |
4512 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
4513 | + struct path *h_path) | |
4514 | +{ | |
4515 | + struct inode *h_inode; | |
4516 | + | |
4517 | + dt->dt_dentry = dentry; | |
4518 | + dt->dt_h_path = *h_path; | |
4519 | + h_inode = h_path->dentry->d_inode; | |
4520 | + dt->dt_atime = h_inode->i_atime; | |
4521 | + dt->dt_mtime = h_inode->i_mtime; | |
4522 | + /* smp_mb(); */ | |
4523 | +} | |
4524 | + | |
4525 | +void au_dtime_revert(struct au_dtime *dt) | |
4526 | +{ | |
4527 | + struct iattr attr; | |
4528 | + int err; | |
4529 | + | |
4530 | + attr.ia_atime = dt->dt_atime; | |
4531 | + attr.ia_mtime = dt->dt_mtime; | |
4532 | + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET | |
4533 | + | ATTR_ATIME | ATTR_ATIME_SET; | |
4534 | + | |
523b37e3 AM |
4535 | + /* no delegation since this is a directory */ |
4536 | + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL); | |
1facf9fc | 4537 | + if (unlikely(err)) |
0c3ec466 | 4538 | + pr_warn("restoring timestamps failed(%d). ignored\n", err); |
1facf9fc | 4539 | +} |
4540 | + | |
4541 | +/* ---------------------------------------------------------------------- */ | |
4542 | + | |
86dc4139 AM |
4543 | +/* internal use only */ |
4544 | +struct au_cpup_reg_attr { | |
4545 | + int valid; | |
4546 | + struct kstat st; | |
4547 | + unsigned int iflags; /* inode->i_flags */ | |
4548 | +}; | |
4549 | + | |
1facf9fc | 4550 | +static noinline_for_stack |
86dc4139 AM |
4551 | +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src, |
4552 | + struct au_cpup_reg_attr *h_src_attr) | |
1facf9fc | 4553 | +{ |
c1595e42 | 4554 | + int err, sbits, icex; |
1facf9fc | 4555 | + struct iattr ia; |
4556 | + struct path h_path; | |
1308ab2a | 4557 | + struct inode *h_isrc, *h_idst; |
86dc4139 | 4558 | + struct kstat *h_st; |
c1595e42 | 4559 | + struct au_branch *br; |
1facf9fc | 4560 | + |
4561 | + h_path.dentry = au_h_dptr(dst, bindex); | |
1308ab2a | 4562 | + h_idst = h_path.dentry->d_inode; |
c1595e42 JR |
4563 | + br = au_sbr(dst->d_sb, bindex); |
4564 | + h_path.mnt = au_br_mnt(br); | |
1facf9fc | 4565 | + h_isrc = h_src->d_inode; |
1308ab2a | 4566 | + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID |
1facf9fc | 4567 | + | ATTR_ATIME | ATTR_MTIME |
4568 | + | ATTR_ATIME_SET | ATTR_MTIME_SET; | |
86dc4139 AM |
4569 | + if (h_src_attr && h_src_attr->valid) { |
4570 | + h_st = &h_src_attr->st; | |
4571 | + ia.ia_uid = h_st->uid; | |
4572 | + ia.ia_gid = h_st->gid; | |
4573 | + ia.ia_atime = h_st->atime; | |
4574 | + ia.ia_mtime = h_st->mtime; | |
4575 | + if (h_idst->i_mode != h_st->mode | |
4576 | + && !S_ISLNK(h_idst->i_mode)) { | |
4577 | + ia.ia_valid |= ATTR_MODE; | |
4578 | + ia.ia_mode = h_st->mode; | |
4579 | + } | |
4580 | + sbits = !!(h_st->mode & (S_ISUID | S_ISGID)); | |
4581 | + au_cpup_attr_flags(h_idst, h_src_attr->iflags); | |
4582 | + } else { | |
4583 | + ia.ia_uid = h_isrc->i_uid; | |
4584 | + ia.ia_gid = h_isrc->i_gid; | |
4585 | + ia.ia_atime = h_isrc->i_atime; | |
4586 | + ia.ia_mtime = h_isrc->i_mtime; | |
4587 | + if (h_idst->i_mode != h_isrc->i_mode | |
4588 | + && !S_ISLNK(h_idst->i_mode)) { | |
4589 | + ia.ia_valid |= ATTR_MODE; | |
4590 | + ia.ia_mode = h_isrc->i_mode; | |
4591 | + } | |
4592 | + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID)); | |
4593 | + au_cpup_attr_flags(h_idst, h_isrc->i_flags); | |
1308ab2a | 4594 | + } |
523b37e3 AM |
4595 | + /* no delegation since it is just created */ |
4596 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 4597 | + |
4598 | + /* is this nfs only? */ | |
4599 | + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) { | |
4600 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
4601 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 4602 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); |
1facf9fc | 4603 | + } |
4604 | + | |
c1595e42 JR |
4605 | + icex = br->br_perm & AuBrAttr_ICEX; |
4606 | + if (!err) | |
4607 | + err = au_cpup_xattr(h_path.dentry, h_src, icex); | |
4608 | + | |
1facf9fc | 4609 | + return err; |
4610 | +} | |
4611 | + | |
4612 | +/* ---------------------------------------------------------------------- */ | |
4613 | + | |
4614 | +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len, | |
4615 | + char *buf, unsigned long blksize) | |
4616 | +{ | |
4617 | + int err; | |
4618 | + size_t sz, rbytes, wbytes; | |
4619 | + unsigned char all_zero; | |
4620 | + char *p, *zp; | |
4621 | + struct mutex *h_mtx; | |
4622 | + /* reduce stack usage */ | |
4623 | + struct iattr *ia; | |
4624 | + | |
4625 | + zp = page_address(ZERO_PAGE(0)); | |
4626 | + if (unlikely(!zp)) | |
4627 | + return -ENOMEM; /* possible? */ | |
4628 | + | |
4629 | + err = 0; | |
4630 | + all_zero = 0; | |
4631 | + while (len) { | |
4632 | + AuDbg("len %lld\n", len); | |
4633 | + sz = blksize; | |
4634 | + if (len < blksize) | |
4635 | + sz = len; | |
4636 | + | |
4637 | + rbytes = 0; | |
4638 | + /* todo: signal_pending? */ | |
4639 | + while (!rbytes || err == -EAGAIN || err == -EINTR) { | |
4640 | + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos); | |
4641 | + err = rbytes; | |
4642 | + } | |
4643 | + if (unlikely(err < 0)) | |
4644 | + break; | |
4645 | + | |
4646 | + all_zero = 0; | |
4647 | + if (len >= rbytes && rbytes == blksize) | |
4648 | + all_zero = !memcmp(buf, zp, rbytes); | |
4649 | + if (!all_zero) { | |
4650 | + wbytes = rbytes; | |
4651 | + p = buf; | |
4652 | + while (wbytes) { | |
4653 | + size_t b; | |
4654 | + | |
4655 | + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos); | |
4656 | + err = b; | |
4657 | + /* todo: signal_pending? */ | |
4658 | + if (unlikely(err == -EAGAIN || err == -EINTR)) | |
4659 | + continue; | |
4660 | + if (unlikely(err < 0)) | |
4661 | + break; | |
4662 | + wbytes -= b; | |
4663 | + p += b; | |
4664 | + } | |
392086de AM |
4665 | + if (unlikely(err < 0)) |
4666 | + break; | |
1facf9fc | 4667 | + } else { |
4668 | + loff_t res; | |
4669 | + | |
4670 | + AuLabel(hole); | |
4671 | + res = vfsub_llseek(dst, rbytes, SEEK_CUR); | |
4672 | + err = res; | |
4673 | + if (unlikely(res < 0)) | |
4674 | + break; | |
4675 | + } | |
4676 | + len -= rbytes; | |
4677 | + err = 0; | |
4678 | + } | |
4679 | + | |
4680 | + /* the last block may be a hole */ | |
4681 | + if (!err && all_zero) { | |
4682 | + AuLabel(last hole); | |
4683 | + | |
4684 | + err = 1; | |
4685 | + if (au_test_nfs(dst->f_dentry->d_sb)) { | |
4686 | + /* nfs requires this step to make last hole */ | |
4687 | + /* is this only nfs? */ | |
4688 | + do { | |
4689 | + /* todo: signal_pending? */ | |
4690 | + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos); | |
4691 | + } while (err == -EAGAIN || err == -EINTR); | |
4692 | + if (err == 1) | |
4693 | + dst->f_pos--; | |
4694 | + } | |
4695 | + | |
4696 | + if (err == 1) { | |
4697 | + ia = (void *)buf; | |
4698 | + ia->ia_size = dst->f_pos; | |
4699 | + ia->ia_valid = ATTR_SIZE | ATTR_FILE; | |
4700 | + ia->ia_file = dst; | |
c06a8ce3 | 4701 | + h_mtx = &file_inode(dst)->i_mutex; |
1facf9fc | 4702 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2); |
523b37e3 AM |
4703 | + /* no delegation since it is just created */ |
4704 | + err = vfsub_notify_change(&dst->f_path, ia, | |
4705 | + /*delegated*/NULL); | |
1facf9fc | 4706 | + mutex_unlock(h_mtx); |
4707 | + } | |
4708 | + } | |
4709 | + | |
4710 | + return err; | |
4711 | +} | |
4712 | + | |
4713 | +int au_copy_file(struct file *dst, struct file *src, loff_t len) | |
4714 | +{ | |
4715 | + int err; | |
4716 | + unsigned long blksize; | |
4717 | + unsigned char do_kfree; | |
4718 | + char *buf; | |
4719 | + | |
4720 | + err = -ENOMEM; | |
4721 | + blksize = dst->f_dentry->d_sb->s_blocksize; | |
4722 | + if (!blksize || PAGE_SIZE < blksize) | |
4723 | + blksize = PAGE_SIZE; | |
4724 | + AuDbg("blksize %lu\n", blksize); | |
4725 | + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *)); | |
4726 | + if (do_kfree) | |
4727 | + buf = kmalloc(blksize, GFP_NOFS); | |
4728 | + else | |
4729 | + buf = (void *)__get_free_page(GFP_NOFS); | |
4730 | + if (unlikely(!buf)) | |
4731 | + goto out; | |
4732 | + | |
4733 | + if (len > (1 << 22)) | |
4734 | + AuDbg("copying a large file %lld\n", (long long)len); | |
4735 | + | |
4736 | + src->f_pos = 0; | |
4737 | + dst->f_pos = 0; | |
4738 | + err = au_do_copy_file(dst, src, len, buf, blksize); | |
4739 | + if (do_kfree) | |
4740 | + kfree(buf); | |
4741 | + else | |
4742 | + free_page((unsigned long)buf); | |
4743 | + | |
4f0767ce | 4744 | +out: |
1facf9fc | 4745 | + return err; |
4746 | +} | |
4747 | + | |
4748 | +/* | |
4749 | + * to support a sparse file which is opened with O_APPEND, | |
4750 | + * we need to close the file. | |
4751 | + */ | |
c2b27bf2 | 4752 | +static int au_cp_regular(struct au_cp_generic *cpg) |
1facf9fc | 4753 | +{ |
4754 | + int err, i; | |
4755 | + enum { SRC, DST }; | |
4756 | + struct { | |
4757 | + aufs_bindex_t bindex; | |
4758 | + unsigned int flags; | |
4759 | + struct dentry *dentry; | |
392086de | 4760 | + int force_wr; |
1facf9fc | 4761 | + struct file *file; |
523b37e3 | 4762 | + void *label; |
1facf9fc | 4763 | + } *f, file[] = { |
4764 | + { | |
c2b27bf2 | 4765 | + .bindex = cpg->bsrc, |
1facf9fc | 4766 | + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE, |
523b37e3 | 4767 | + .label = &&out |
1facf9fc | 4768 | + }, |
4769 | + { | |
c2b27bf2 | 4770 | + .bindex = cpg->bdst, |
1facf9fc | 4771 | + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE, |
392086de | 4772 | + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST), |
523b37e3 | 4773 | + .label = &&out_src |
1facf9fc | 4774 | + } |
4775 | + }; | |
4776 | + struct super_block *sb; | |
4777 | + | |
4778 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 4779 | + sb = cpg->dentry->d_sb; |
1facf9fc | 4780 | + f = file; |
4781 | + for (i = 0; i < 2; i++, f++) { | |
c2b27bf2 AM |
4782 | + f->dentry = au_h_dptr(cpg->dentry, f->bindex); |
4783 | + f->file = au_h_open(cpg->dentry, f->bindex, f->flags, | |
392086de | 4784 | + /*file*/NULL, f->force_wr); |
1facf9fc | 4785 | + err = PTR_ERR(f->file); |
4786 | + if (IS_ERR(f->file)) | |
4787 | + goto *f->label; | |
1facf9fc | 4788 | + } |
4789 | + | |
4790 | + /* try stopping to update while we copyup */ | |
4791 | + IMustLock(file[SRC].dentry->d_inode); | |
c2b27bf2 | 4792 | + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len); |
1facf9fc | 4793 | + |
1facf9fc | 4794 | + fput(file[DST].file); |
4795 | + au_sbr_put(sb, file[DST].bindex); | |
523b37e3 | 4796 | + |
4f0767ce | 4797 | +out_src: |
1facf9fc | 4798 | + fput(file[SRC].file); |
4799 | + au_sbr_put(sb, file[SRC].bindex); | |
4f0767ce | 4800 | +out: |
1facf9fc | 4801 | + return err; |
4802 | +} | |
4803 | + | |
c2b27bf2 | 4804 | +static int au_do_cpup_regular(struct au_cp_generic *cpg, |
86dc4139 | 4805 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 4806 | +{ |
4807 | + int err, rerr; | |
4808 | + loff_t l; | |
86dc4139 | 4809 | + struct path h_path; |
38d290e6 | 4810 | + struct inode *h_src_inode, *h_dst_inode; |
1facf9fc | 4811 | + |
4812 | + err = 0; | |
c2b27bf2 | 4813 | + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc); |
86dc4139 | 4814 | + l = i_size_read(h_src_inode); |
c2b27bf2 AM |
4815 | + if (cpg->len == -1 || l < cpg->len) |
4816 | + cpg->len = l; | |
4817 | + if (cpg->len) { | |
86dc4139 AM |
4818 | + /* try stopping to update while we are referencing */ |
4819 | + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD); | |
c2b27bf2 | 4820 | + au_pin_hdir_unlock(cpg->pin); |
1facf9fc | 4821 | + |
c2b27bf2 AM |
4822 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
4823 | + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc); | |
86dc4139 AM |
4824 | + h_src_attr->iflags = h_src_inode->i_flags; |
4825 | + err = vfs_getattr(&h_path, &h_src_attr->st); | |
4826 | + if (unlikely(err)) { | |
4827 | + mutex_unlock(&h_src_inode->i_mutex); | |
4828 | + goto out; | |
4829 | + } | |
4830 | + h_src_attr->valid = 1; | |
c2b27bf2 | 4831 | + err = au_cp_regular(cpg); |
86dc4139 | 4832 | + mutex_unlock(&h_src_inode->i_mutex); |
c2b27bf2 | 4833 | + rerr = au_pin_hdir_relock(cpg->pin); |
86dc4139 AM |
4834 | + if (!err && rerr) |
4835 | + err = rerr; | |
1facf9fc | 4836 | + } |
38d290e6 JR |
4837 | + if (!err && (h_src_inode->i_state & I_LINKABLE)) { |
4838 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst); | |
4839 | + h_dst_inode = h_path.dentry->d_inode; | |
4840 | + spin_lock(&h_dst_inode->i_lock); | |
4841 | + h_dst_inode->i_state |= I_LINKABLE; | |
4842 | + spin_unlock(&h_dst_inode->i_lock); | |
4843 | + } | |
1facf9fc | 4844 | + |
4f0767ce | 4845 | +out: |
1facf9fc | 4846 | + return err; |
4847 | +} | |
4848 | + | |
4849 | +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src, | |
4850 | + struct inode *h_dir) | |
4851 | +{ | |
4852 | + int err, symlen; | |
4853 | + mm_segment_t old_fs; | |
b752ccd1 AM |
4854 | + union { |
4855 | + char *k; | |
4856 | + char __user *u; | |
4857 | + } sym; | |
1facf9fc | 4858 | + |
4859 | + err = -ENOSYS; | |
4860 | + if (unlikely(!h_src->d_inode->i_op->readlink)) | |
4861 | + goto out; | |
4862 | + | |
4863 | + err = -ENOMEM; | |
537831f9 | 4864 | + sym.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 4865 | + if (unlikely(!sym.k)) |
1facf9fc | 4866 | + goto out; |
4867 | + | |
9dbd164d | 4868 | + /* unnecessary to support mmap_sem since symlink is not mmap-able */ |
1facf9fc | 4869 | + old_fs = get_fs(); |
4870 | + set_fs(KERNEL_DS); | |
b752ccd1 | 4871 | + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX); |
1facf9fc | 4872 | + err = symlen; |
4873 | + set_fs(old_fs); | |
4874 | + | |
4875 | + if (symlen > 0) { | |
b752ccd1 AM |
4876 | + sym.k[symlen] = 0; |
4877 | + err = vfsub_symlink(h_dir, h_path, sym.k); | |
1facf9fc | 4878 | + } |
537831f9 | 4879 | + free_page((unsigned long)sym.k); |
1facf9fc | 4880 | + |
4f0767ce | 4881 | +out: |
1facf9fc | 4882 | + return err; |
4883 | +} | |
4884 | + | |
1facf9fc | 4885 | +static noinline_for_stack |
c2b27bf2 | 4886 | +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent, |
86dc4139 | 4887 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 4888 | +{ |
4889 | + int err; | |
4890 | + umode_t mode; | |
4891 | + unsigned int mnt_flags; | |
076b876e | 4892 | + unsigned char isdir, isreg, force; |
c2b27bf2 | 4893 | + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 4894 | + struct au_dtime dt; |
4895 | + struct path h_path; | |
4896 | + struct dentry *h_src, *h_dst, *h_parent; | |
4897 | + struct inode *h_inode, *h_dir; | |
4898 | + struct super_block *sb; | |
4899 | + | |
4900 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 4901 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
1facf9fc | 4902 | + h_inode = h_src->d_inode; |
c2b27bf2 | 4903 | + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc)); |
1facf9fc | 4904 | + |
4905 | + /* try stopping to be referenced while we are creating */ | |
c2b27bf2 AM |
4906 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); |
4907 | + if (au_ftest_cpup(cpg->flags, RENAME)) | |
86dc4139 AM |
4908 | + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX, |
4909 | + AUFS_WH_PFX_LEN)); | |
1facf9fc | 4910 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
4911 | + h_dir = h_parent->d_inode; | |
4912 | + IMustLock(h_dir); | |
4913 | + AuDebugOn(h_parent != h_dst->d_parent); | |
4914 | + | |
c2b27bf2 AM |
4915 | + sb = cpg->dentry->d_sb; |
4916 | + h_path.mnt = au_sbr_mnt(sb, cpg->bdst); | |
1facf9fc | 4917 | + if (do_dt) { |
4918 | + h_path.dentry = h_parent; | |
4919 | + au_dtime_store(&dt, dst_parent, &h_path); | |
4920 | + } | |
4921 | + h_path.dentry = h_dst; | |
4922 | + | |
076b876e | 4923 | + isreg = 0; |
1facf9fc | 4924 | + isdir = 0; |
4925 | + mode = h_inode->i_mode; | |
4926 | + switch (mode & S_IFMT) { | |
4927 | + case S_IFREG: | |
076b876e | 4928 | + isreg = 1; |
b4510431 AM |
4929 | + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR, |
4930 | + /*want_excl*/true); | |
1facf9fc | 4931 | + if (!err) |
c2b27bf2 | 4932 | + err = au_do_cpup_regular(cpg, h_src_attr); |
1facf9fc | 4933 | + break; |
4934 | + case S_IFDIR: | |
4935 | + isdir = 1; | |
4936 | + err = vfsub_mkdir(h_dir, &h_path, mode); | |
4937 | + if (!err) { | |
4938 | + /* | |
4939 | + * strange behaviour from the users view, | |
4940 | + * particularry setattr case | |
4941 | + */ | |
c2b27bf2 | 4942 | + if (au_ibstart(dst_parent->d_inode) == cpg->bdst) |
1facf9fc | 4943 | + au_cpup_attr_nlink(dst_parent->d_inode, |
4944 | + /*force*/1); | |
c2b27bf2 | 4945 | + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1); |
1facf9fc | 4946 | + } |
4947 | + break; | |
4948 | + case S_IFLNK: | |
4949 | + err = au_do_cpup_symlink(&h_path, h_src, h_dir); | |
4950 | + break; | |
4951 | + case S_IFCHR: | |
4952 | + case S_IFBLK: | |
4953 | + AuDebugOn(!capable(CAP_MKNOD)); | |
4954 | + /*FALLTHROUGH*/ | |
4955 | + case S_IFIFO: | |
4956 | + case S_IFSOCK: | |
4957 | + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev); | |
4958 | + break; | |
4959 | + default: | |
4960 | + AuIOErr("Unknown inode type 0%o\n", mode); | |
4961 | + err = -EIO; | |
4962 | + } | |
4963 | + | |
4964 | + mnt_flags = au_mntflags(sb); | |
4965 | + if (!au_opt_test(mnt_flags, UDBA_NONE) | |
4966 | + && !isdir | |
4967 | + && au_opt_test(mnt_flags, XINO) | |
38d290e6 JR |
4968 | + && (h_inode->i_nlink == 1 |
4969 | + || (h_inode->i_state & I_LINKABLE)) | |
1facf9fc | 4970 | + /* todo: unnecessary? */ |
c2b27bf2 AM |
4971 | + /* && cpg->dentry->d_inode->i_nlink == 1 */ |
4972 | + && cpg->bdst < cpg->bsrc | |
4973 | + && !au_ftest_cpup(cpg->flags, KEEPLINO)) | |
4974 | + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0); | |
1facf9fc | 4975 | + /* ignore this error */ |
4976 | + | |
076b876e AM |
4977 | + if (!err) { |
4978 | + force = 0; | |
4979 | + if (isreg) { | |
4980 | + force = !!cpg->len; | |
4981 | + if (cpg->len == -1) | |
4982 | + force = !!i_size_read(h_inode); | |
4983 | + } | |
4984 | + au_fhsm_wrote(sb, cpg->bdst, force); | |
4985 | + } | |
4986 | + | |
1facf9fc | 4987 | + if (do_dt) |
4988 | + au_dtime_revert(&dt); | |
4989 | + return err; | |
4990 | +} | |
4991 | + | |
392086de | 4992 | +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path) |
86dc4139 AM |
4993 | +{ |
4994 | + int err; | |
392086de | 4995 | + struct dentry *dentry, *h_dentry, *h_parent, *parent; |
86dc4139 | 4996 | + struct inode *h_dir; |
392086de | 4997 | + aufs_bindex_t bdst; |
86dc4139 | 4998 | + |
392086de AM |
4999 | + dentry = cpg->dentry; |
5000 | + bdst = cpg->bdst; | |
5001 | + h_dentry = au_h_dptr(dentry, bdst); | |
5002 | + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) { | |
5003 | + dget(h_dentry); | |
5004 | + au_set_h_dptr(dentry, bdst, NULL); | |
5005 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); | |
5006 | + if (!err) | |
5007 | + h_path->dentry = dget(au_h_dptr(dentry, bdst)); | |
86dc4139 | 5008 | + au_set_h_dptr(dentry, bdst, h_dentry); |
392086de AM |
5009 | + } else { |
5010 | + err = 0; | |
5011 | + parent = dget_parent(dentry); | |
5012 | + h_parent = au_h_dptr(parent, bdst); | |
5013 | + dput(parent); | |
5014 | + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
5015 | + if (IS_ERR(h_path->dentry)) | |
5016 | + err = PTR_ERR(h_path->dentry); | |
86dc4139 | 5017 | + } |
392086de AM |
5018 | + if (unlikely(err)) |
5019 | + goto out; | |
86dc4139 | 5020 | + |
86dc4139 AM |
5021 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ |
5022 | + h_dir = h_parent->d_inode; | |
5023 | + IMustLock(h_dir); | |
523b37e3 AM |
5024 | + AuDbg("%pd %pd\n", h_dentry, h_path->dentry); |
5025 | + /* no delegation since it is just created */ | |
5026 | + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL); | |
86dc4139 AM |
5027 | + dput(h_path->dentry); |
5028 | + | |
5029 | +out: | |
5030 | + return err; | |
5031 | +} | |
5032 | + | |
1facf9fc | 5033 | +/* |
5034 | + * copyup the @dentry from @bsrc to @bdst. | |
5035 | + * the caller must set the both of lower dentries. | |
5036 | + * @len is for truncating when it is -1 copyup the entire file. | |
5037 | + * in link/rename cases, @dst_parent may be different from the real one. | |
c2b27bf2 | 5038 | + * basic->bsrc can be larger than basic->bdst. |
1facf9fc | 5039 | + */ |
c2b27bf2 | 5040 | +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5041 | +{ |
5042 | + int err, rerr; | |
5043 | + aufs_bindex_t old_ibstart; | |
5044 | + unsigned char isdir, plink; | |
1facf9fc | 5045 | + struct dentry *h_src, *h_dst, *h_parent; |
523b37e3 | 5046 | + struct inode *dst_inode, *h_dir, *inode, *delegated; |
1facf9fc | 5047 | + struct super_block *sb; |
86dc4139 | 5048 | + struct au_branch *br; |
c2b27bf2 AM |
5049 | + /* to reuduce stack size */ |
5050 | + struct { | |
5051 | + struct au_dtime dt; | |
5052 | + struct path h_path; | |
5053 | + struct au_cpup_reg_attr h_src_attr; | |
5054 | + } *a; | |
1facf9fc | 5055 | + |
c2b27bf2 AM |
5056 | + err = -ENOMEM; |
5057 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
5058 | + if (unlikely(!a)) | |
5059 | + goto out; | |
5060 | + a->h_src_attr.valid = 0; | |
1facf9fc | 5061 | + |
c2b27bf2 AM |
5062 | + sb = cpg->dentry->d_sb; |
5063 | + br = au_sbr(sb, cpg->bdst); | |
5064 | + a->h_path.mnt = au_br_mnt(br); | |
5065 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); | |
1facf9fc | 5066 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5067 | + h_dir = h_parent->d_inode; | |
5068 | + IMustLock(h_dir); | |
5069 | + | |
c2b27bf2 AM |
5070 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5071 | + inode = cpg->dentry->d_inode; | |
1facf9fc | 5072 | + |
5073 | + if (!dst_parent) | |
c2b27bf2 | 5074 | + dst_parent = dget_parent(cpg->dentry); |
1facf9fc | 5075 | + else |
5076 | + dget(dst_parent); | |
5077 | + | |
5078 | + plink = !!au_opt_test(au_mntflags(sb), PLINK); | |
c2b27bf2 | 5079 | + dst_inode = au_h_iptr(inode, cpg->bdst); |
1facf9fc | 5080 | + if (dst_inode) { |
5081 | + if (unlikely(!plink)) { | |
5082 | + err = -EIO; | |
027c5e7a AM |
5083 | + AuIOErr("hi%lu(i%lu) exists on b%d " |
5084 | + "but plink is disabled\n", | |
c2b27bf2 AM |
5085 | + dst_inode->i_ino, inode->i_ino, cpg->bdst); |
5086 | + goto out_parent; | |
1facf9fc | 5087 | + } |
5088 | + | |
5089 | + if (dst_inode->i_nlink) { | |
c2b27bf2 | 5090 | + const int do_dt = au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5091 | + |
c2b27bf2 | 5092 | + h_src = au_plink_lkup(inode, cpg->bdst); |
1facf9fc | 5093 | + err = PTR_ERR(h_src); |
5094 | + if (IS_ERR(h_src)) | |
c2b27bf2 | 5095 | + goto out_parent; |
1facf9fc | 5096 | + if (unlikely(!h_src->d_inode)) { |
5097 | + err = -EIO; | |
5098 | + AuIOErr("i%lu exists on a upper branch " | |
027c5e7a AM |
5099 | + "but not pseudo-linked\n", |
5100 | + inode->i_ino); | |
1facf9fc | 5101 | + dput(h_src); |
c2b27bf2 | 5102 | + goto out_parent; |
1facf9fc | 5103 | + } |
5104 | + | |
5105 | + if (do_dt) { | |
c2b27bf2 AM |
5106 | + a->h_path.dentry = h_parent; |
5107 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
1facf9fc | 5108 | + } |
86dc4139 | 5109 | + |
c2b27bf2 | 5110 | + a->h_path.dentry = h_dst; |
523b37e3 AM |
5111 | + delegated = NULL; |
5112 | + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated); | |
c2b27bf2 | 5113 | + if (!err && au_ftest_cpup(cpg->flags, RENAME)) |
392086de | 5114 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
1facf9fc | 5115 | + if (do_dt) |
c2b27bf2 | 5116 | + au_dtime_revert(&a->dt); |
523b37e3 AM |
5117 | + if (unlikely(err == -EWOULDBLOCK)) { |
5118 | + pr_warn("cannot retry for NFSv4 delegation" | |
5119 | + " for an internal link\n"); | |
5120 | + iput(delegated); | |
5121 | + } | |
1facf9fc | 5122 | + dput(h_src); |
c2b27bf2 | 5123 | + goto out_parent; |
1facf9fc | 5124 | + } else |
5125 | + /* todo: cpup_wh_file? */ | |
5126 | + /* udba work */ | |
4a4d8108 | 5127 | + au_update_ibrange(inode, /*do_put_zero*/1); |
1facf9fc | 5128 | + } |
5129 | + | |
86dc4139 | 5130 | + isdir = S_ISDIR(inode->i_mode); |
1facf9fc | 5131 | + old_ibstart = au_ibstart(inode); |
c2b27bf2 | 5132 | + err = cpup_entry(cpg, dst_parent, &a->h_src_attr); |
1facf9fc | 5133 | + if (unlikely(err)) |
86dc4139 | 5134 | + goto out_rev; |
1facf9fc | 5135 | + dst_inode = h_dst->d_inode; |
5136 | + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2); | |
86dc4139 | 5137 | + /* todo: necessary? */ |
c2b27bf2 | 5138 | + /* au_pin_hdir_unlock(cpg->pin); */ |
1facf9fc | 5139 | + |
c2b27bf2 | 5140 | + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr); |
86dc4139 AM |
5141 | + if (unlikely(err)) { |
5142 | + /* todo: necessary? */ | |
c2b27bf2 | 5143 | + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */ |
86dc4139 AM |
5144 | + mutex_unlock(&dst_inode->i_mutex); |
5145 | + goto out_rev; | |
5146 | + } | |
5147 | + | |
c2b27bf2 | 5148 | + if (cpg->bdst < old_ibstart) { |
86dc4139 | 5149 | + if (S_ISREG(inode->i_mode)) { |
c2b27bf2 | 5150 | + err = au_dy_iaop(inode, cpg->bdst, dst_inode); |
86dc4139 | 5151 | + if (unlikely(err)) { |
c2b27bf2 AM |
5152 | + /* ignore an error */ |
5153 | + /* au_pin_hdir_relock(cpg->pin); */ | |
86dc4139 AM |
5154 | + mutex_unlock(&dst_inode->i_mutex); |
5155 | + goto out_rev; | |
4a4d8108 | 5156 | + } |
4a4d8108 | 5157 | + } |
c2b27bf2 AM |
5158 | + au_set_ibstart(inode, cpg->bdst); |
5159 | + } else | |
5160 | + au_set_ibend(inode, cpg->bdst); | |
5161 | + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode), | |
86dc4139 AM |
5162 | + au_hi_flags(inode, isdir)); |
5163 | + | |
5164 | + /* todo: necessary? */ | |
c2b27bf2 | 5165 | + /* err = au_pin_hdir_relock(cpg->pin); */ |
86dc4139 AM |
5166 | + mutex_unlock(&dst_inode->i_mutex); |
5167 | + if (unlikely(err)) | |
5168 | + goto out_rev; | |
5169 | + | |
5170 | + if (!isdir | |
38d290e6 JR |
5171 | + && (h_src->d_inode->i_nlink > 1 |
5172 | + || h_src->d_inode->i_state & I_LINKABLE) | |
86dc4139 | 5173 | + && plink) |
c2b27bf2 | 5174 | + au_plink_append(inode, cpg->bdst, h_dst); |
86dc4139 | 5175 | + |
c2b27bf2 AM |
5176 | + if (au_ftest_cpup(cpg->flags, RENAME)) { |
5177 | + a->h_path.dentry = h_dst; | |
392086de | 5178 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
86dc4139 AM |
5179 | + } |
5180 | + if (!err) | |
c2b27bf2 | 5181 | + goto out_parent; /* success */ |
1facf9fc | 5182 | + |
5183 | + /* revert */ | |
4a4d8108 | 5184 | +out_rev: |
c2b27bf2 AM |
5185 | + a->h_path.dentry = h_parent; |
5186 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
5187 | + a->h_path.dentry = h_dst; | |
86dc4139 AM |
5188 | + rerr = 0; |
5189 | + if (h_dst->d_inode) { | |
523b37e3 AM |
5190 | + if (!isdir) { |
5191 | + /* no delegation since it is just created */ | |
5192 | + rerr = vfsub_unlink(h_dir, &a->h_path, | |
5193 | + /*delegated*/NULL, /*force*/0); | |
5194 | + } else | |
c2b27bf2 | 5195 | + rerr = vfsub_rmdir(h_dir, &a->h_path); |
86dc4139 | 5196 | + } |
c2b27bf2 | 5197 | + au_dtime_revert(&a->dt); |
1facf9fc | 5198 | + if (rerr) { |
5199 | + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr); | |
5200 | + err = -EIO; | |
5201 | + } | |
c2b27bf2 | 5202 | +out_parent: |
1facf9fc | 5203 | + dput(dst_parent); |
c2b27bf2 AM |
5204 | + kfree(a); |
5205 | +out: | |
1facf9fc | 5206 | + return err; |
5207 | +} | |
5208 | + | |
c2b27bf2 | 5209 | +#if 0 /* unused */ |
1facf9fc | 5210 | +struct au_cpup_single_args { |
5211 | + int *errp; | |
c2b27bf2 | 5212 | + struct au_cp_generic *cpg; |
1facf9fc | 5213 | + struct dentry *dst_parent; |
5214 | +}; | |
5215 | + | |
5216 | +static void au_call_cpup_single(void *args) | |
5217 | +{ | |
5218 | + struct au_cpup_single_args *a = args; | |
86dc4139 | 5219 | + |
c2b27bf2 AM |
5220 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5221 | + *a->errp = au_cpup_single(a->cpg, a->dst_parent); | |
5222 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5223 | +} |
c2b27bf2 | 5224 | +#endif |
1facf9fc | 5225 | + |
53392da6 AM |
5226 | +/* |
5227 | + * prevent SIGXFSZ in copy-up. | |
5228 | + * testing CAP_MKNOD is for generic fs, | |
5229 | + * but CAP_FSETID is for xfs only, currently. | |
5230 | + */ | |
86dc4139 | 5231 | +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode) |
53392da6 AM |
5232 | +{ |
5233 | + int do_sio; | |
86dc4139 AM |
5234 | + struct super_block *sb; |
5235 | + struct inode *h_dir; | |
53392da6 AM |
5236 | + |
5237 | + do_sio = 0; | |
86dc4139 | 5238 | + sb = au_pinned_parent(pin)->d_sb; |
53392da6 AM |
5239 | + if (!au_wkq_test() |
5240 | + && (!au_sbi(sb)->si_plink_maint_pid | |
5241 | + || au_plink_maint(sb, AuLock_NOPLM))) { | |
5242 | + switch (mode & S_IFMT) { | |
5243 | + case S_IFREG: | |
5244 | + /* no condition about RLIMIT_FSIZE and the file size */ | |
5245 | + do_sio = 1; | |
5246 | + break; | |
5247 | + case S_IFCHR: | |
5248 | + case S_IFBLK: | |
5249 | + do_sio = !capable(CAP_MKNOD); | |
5250 | + break; | |
5251 | + } | |
5252 | + if (!do_sio) | |
5253 | + do_sio = ((mode & (S_ISUID | S_ISGID)) | |
5254 | + && !capable(CAP_FSETID)); | |
86dc4139 AM |
5255 | + /* this workaround may be removed in the future */ |
5256 | + if (!do_sio) { | |
5257 | + h_dir = au_pinned_h_dir(pin); | |
5258 | + do_sio = h_dir->i_mode & S_ISVTX; | |
5259 | + } | |
53392da6 AM |
5260 | + } |
5261 | + | |
5262 | + return do_sio; | |
5263 | +} | |
5264 | + | |
c2b27bf2 AM |
5265 | +#if 0 /* unused */ |
5266 | +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) | |
1facf9fc | 5267 | +{ |
5268 | + int err, wkq_err; | |
1facf9fc | 5269 | + struct dentry *h_dentry; |
5270 | + | |
c2b27bf2 | 5271 | + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
86dc4139 | 5272 | + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode)) |
c2b27bf2 | 5273 | + err = au_cpup_single(cpg, dst_parent); |
1facf9fc | 5274 | + else { |
5275 | + struct au_cpup_single_args args = { | |
5276 | + .errp = &err, | |
c2b27bf2 AM |
5277 | + .cpg = cpg, |
5278 | + .dst_parent = dst_parent | |
1facf9fc | 5279 | + }; |
5280 | + wkq_err = au_wkq_wait(au_call_cpup_single, &args); | |
5281 | + if (unlikely(wkq_err)) | |
5282 | + err = wkq_err; | |
5283 | + } | |
5284 | + | |
5285 | + return err; | |
5286 | +} | |
c2b27bf2 | 5287 | +#endif |
1facf9fc | 5288 | + |
5289 | +/* | |
5290 | + * copyup the @dentry from the first active lower branch to @bdst, | |
5291 | + * using au_cpup_single(). | |
5292 | + */ | |
c2b27bf2 | 5293 | +static int au_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5294 | +{ |
5295 | + int err; | |
c2b27bf2 AM |
5296 | + unsigned int flags_orig; |
5297 | + struct dentry *dentry; | |
5298 | + | |
5299 | + AuDebugOn(cpg->bsrc < 0); | |
1facf9fc | 5300 | + |
c2b27bf2 | 5301 | + dentry = cpg->dentry; |
86dc4139 | 5302 | + DiMustWriteLock(dentry); |
1facf9fc | 5303 | + |
c2b27bf2 | 5304 | + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1); |
1facf9fc | 5305 | + if (!err) { |
c2b27bf2 AM |
5306 | + flags_orig = cpg->flags; |
5307 | + au_fset_cpup(cpg->flags, RENAME); | |
5308 | + err = au_cpup_single(cpg, NULL); | |
5309 | + cpg->flags = flags_orig; | |
1facf9fc | 5310 | + if (!err) |
5311 | + return 0; /* success */ | |
5312 | + | |
5313 | + /* revert */ | |
c2b27bf2 AM |
5314 | + au_set_h_dptr(dentry, cpg->bdst, NULL); |
5315 | + au_set_dbstart(dentry, cpg->bsrc); | |
1facf9fc | 5316 | + } |
5317 | + | |
5318 | + return err; | |
5319 | +} | |
5320 | + | |
5321 | +struct au_cpup_simple_args { | |
5322 | + int *errp; | |
c2b27bf2 | 5323 | + struct au_cp_generic *cpg; |
1facf9fc | 5324 | +}; |
5325 | + | |
5326 | +static void au_call_cpup_simple(void *args) | |
5327 | +{ | |
5328 | + struct au_cpup_simple_args *a = args; | |
86dc4139 | 5329 | + |
c2b27bf2 AM |
5330 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5331 | + *a->errp = au_cpup_simple(a->cpg); | |
5332 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5333 | +} |
5334 | + | |
c2b27bf2 | 5335 | +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5336 | +{ |
5337 | + int err, wkq_err; | |
c2b27bf2 AM |
5338 | + struct dentry *dentry, *parent; |
5339 | + struct file *h_file; | |
1facf9fc | 5340 | + struct inode *h_dir; |
5341 | + | |
c2b27bf2 AM |
5342 | + dentry = cpg->dentry; |
5343 | + h_file = NULL; | |
5344 | + if (au_ftest_cpup(cpg->flags, HOPEN)) { | |
5345 | + AuDebugOn(cpg->bsrc < 0); | |
392086de | 5346 | + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0); |
c2b27bf2 AM |
5347 | + err = PTR_ERR(h_file); |
5348 | + if (IS_ERR(h_file)) | |
5349 | + goto out; | |
5350 | + } | |
5351 | + | |
1facf9fc | 5352 | + parent = dget_parent(dentry); |
c2b27bf2 | 5353 | + h_dir = au_h_iptr(parent->d_inode, cpg->bdst); |
53392da6 | 5354 | + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE) |
c2b27bf2 AM |
5355 | + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode)) |
5356 | + err = au_cpup_simple(cpg); | |
1facf9fc | 5357 | + else { |
5358 | + struct au_cpup_simple_args args = { | |
5359 | + .errp = &err, | |
c2b27bf2 | 5360 | + .cpg = cpg |
1facf9fc | 5361 | + }; |
5362 | + wkq_err = au_wkq_wait(au_call_cpup_simple, &args); | |
5363 | + if (unlikely(wkq_err)) | |
5364 | + err = wkq_err; | |
5365 | + } | |
5366 | + | |
5367 | + dput(parent); | |
c2b27bf2 AM |
5368 | + if (h_file) |
5369 | + au_h_open_post(dentry, cpg->bsrc, h_file); | |
5370 | + | |
5371 | +out: | |
1facf9fc | 5372 | + return err; |
5373 | +} | |
5374 | + | |
c2b27bf2 | 5375 | +int au_sio_cpup_simple(struct au_cp_generic *cpg) |
367653fa | 5376 | +{ |
c2b27bf2 AM |
5377 | + aufs_bindex_t bsrc, bend; |
5378 | + struct dentry *dentry, *h_dentry; | |
367653fa | 5379 | + |
c2b27bf2 AM |
5380 | + if (cpg->bsrc < 0) { |
5381 | + dentry = cpg->dentry; | |
5382 | + bend = au_dbend(dentry); | |
5383 | + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) { | |
5384 | + h_dentry = au_h_dptr(dentry, bsrc); | |
5385 | + if (h_dentry) { | |
5386 | + AuDebugOn(!h_dentry->d_inode); | |
5387 | + break; | |
5388 | + } | |
5389 | + } | |
5390 | + AuDebugOn(bsrc > bend); | |
5391 | + cpg->bsrc = bsrc; | |
367653fa | 5392 | + } |
c2b27bf2 AM |
5393 | + AuDebugOn(cpg->bsrc <= cpg->bdst); |
5394 | + return au_do_sio_cpup_simple(cpg); | |
5395 | +} | |
367653fa | 5396 | + |
c2b27bf2 AM |
5397 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg) |
5398 | +{ | |
5399 | + AuDebugOn(cpg->bdst <= cpg->bsrc); | |
5400 | + return au_do_sio_cpup_simple(cpg); | |
367653fa AM |
5401 | +} |
5402 | + | |
1facf9fc | 5403 | +/* ---------------------------------------------------------------------- */ |
5404 | + | |
5405 | +/* | |
5406 | + * copyup the deleted file for writing. | |
5407 | + */ | |
c2b27bf2 AM |
5408 | +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry, |
5409 | + struct file *file) | |
1facf9fc | 5410 | +{ |
5411 | + int err; | |
c2b27bf2 AM |
5412 | + unsigned int flags_orig; |
5413 | + aufs_bindex_t bsrc_orig; | |
1facf9fc | 5414 | + struct dentry *h_d_dst, *h_d_start; |
c2b27bf2 | 5415 | + struct au_dinfo *dinfo; |
4a4d8108 | 5416 | + struct au_hdentry *hdp; |
1facf9fc | 5417 | + |
c2b27bf2 | 5418 | + dinfo = au_di(cpg->dentry); |
1308ab2a | 5419 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
5420 | + | |
c2b27bf2 AM |
5421 | + bsrc_orig = cpg->bsrc; |
5422 | + cpg->bsrc = dinfo->di_bstart; | |
4a4d8108 | 5423 | + hdp = dinfo->di_hdentry; |
c2b27bf2 AM |
5424 | + h_d_dst = hdp[0 + cpg->bdst].hd_dentry; |
5425 | + dinfo->di_bstart = cpg->bdst; | |
5426 | + hdp[0 + cpg->bdst].hd_dentry = wh_dentry; | |
86dc4139 | 5427 | + h_d_start = NULL; |
027c5e7a | 5428 | + if (file) { |
c2b27bf2 AM |
5429 | + h_d_start = hdp[0 + cpg->bsrc].hd_dentry; |
5430 | + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry; | |
027c5e7a | 5431 | + } |
c2b27bf2 AM |
5432 | + flags_orig = cpg->flags; |
5433 | + cpg->flags = !AuCpup_DTIME; | |
5434 | + err = au_cpup_single(cpg, /*h_parent*/NULL); | |
5435 | + cpg->flags = flags_orig; | |
027c5e7a AM |
5436 | + if (file) { |
5437 | + if (!err) | |
5438 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 5439 | + hdp[0 + cpg->bsrc].hd_dentry = h_d_start; |
1facf9fc | 5440 | + } |
c2b27bf2 AM |
5441 | + hdp[0 + cpg->bdst].hd_dentry = h_d_dst; |
5442 | + dinfo->di_bstart = cpg->bsrc; | |
5443 | + cpg->bsrc = bsrc_orig; | |
1facf9fc | 5444 | + |
5445 | + return err; | |
5446 | +} | |
5447 | + | |
c2b27bf2 | 5448 | +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5449 | +{ |
5450 | + int err; | |
c2b27bf2 | 5451 | + aufs_bindex_t bdst; |
1facf9fc | 5452 | + struct au_dtime dt; |
c2b27bf2 | 5453 | + struct dentry *dentry, *parent, *h_parent, *wh_dentry; |
1facf9fc | 5454 | + struct au_branch *br; |
5455 | + struct path h_path; | |
5456 | + | |
c2b27bf2 AM |
5457 | + dentry = cpg->dentry; |
5458 | + bdst = cpg->bdst; | |
1facf9fc | 5459 | + br = au_sbr(dentry->d_sb, bdst); |
5460 | + parent = dget_parent(dentry); | |
5461 | + h_parent = au_h_dptr(parent, bdst); | |
5462 | + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
5463 | + err = PTR_ERR(wh_dentry); | |
5464 | + if (IS_ERR(wh_dentry)) | |
5465 | + goto out; | |
5466 | + | |
5467 | + h_path.dentry = h_parent; | |
86dc4139 | 5468 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 5469 | + au_dtime_store(&dt, parent, &h_path); |
c2b27bf2 | 5470 | + err = au_do_cpup_wh(cpg, wh_dentry, file); |
1facf9fc | 5471 | + if (unlikely(err)) |
5472 | + goto out_wh; | |
5473 | + | |
5474 | + dget(wh_dentry); | |
5475 | + h_path.dentry = wh_dentry; | |
523b37e3 AM |
5476 | + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) { |
5477 | + /* no delegation since it is just created */ | |
5478 | + err = vfsub_unlink(h_parent->d_inode, &h_path, | |
5479 | + /*delegated*/NULL, /*force*/0); | |
5480 | + } else | |
4a4d8108 | 5481 | + err = vfsub_rmdir(h_parent->d_inode, &h_path); |
1facf9fc | 5482 | + if (unlikely(err)) { |
523b37e3 AM |
5483 | + AuIOErr("failed remove copied-up tmp file %pd(%d)\n", |
5484 | + wh_dentry, err); | |
1facf9fc | 5485 | + err = -EIO; |
5486 | + } | |
5487 | + au_dtime_revert(&dt); | |
5488 | + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry); | |
5489 | + | |
4f0767ce | 5490 | +out_wh: |
1facf9fc | 5491 | + dput(wh_dentry); |
4f0767ce | 5492 | +out: |
1facf9fc | 5493 | + dput(parent); |
5494 | + return err; | |
5495 | +} | |
5496 | + | |
5497 | +struct au_cpup_wh_args { | |
5498 | + int *errp; | |
c2b27bf2 | 5499 | + struct au_cp_generic *cpg; |
1facf9fc | 5500 | + struct file *file; |
5501 | +}; | |
5502 | + | |
5503 | +static void au_call_cpup_wh(void *args) | |
5504 | +{ | |
5505 | + struct au_cpup_wh_args *a = args; | |
86dc4139 | 5506 | + |
c2b27bf2 AM |
5507 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5508 | + *a->errp = au_cpup_wh(a->cpg, a->file); | |
5509 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5510 | +} |
5511 | + | |
c2b27bf2 | 5512 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 5513 | +{ |
5514 | + int err, wkq_err; | |
c2b27bf2 | 5515 | + aufs_bindex_t bdst; |
c1595e42 | 5516 | + struct dentry *dentry, *parent, *h_orph, *h_parent; |
86dc4139 | 5517 | + struct inode *dir, *h_dir, *h_tmpdir; |
1facf9fc | 5518 | + struct au_wbr *wbr; |
c2b27bf2 | 5519 | + struct au_pin wh_pin, *pin_orig; |
1facf9fc | 5520 | + |
c2b27bf2 AM |
5521 | + dentry = cpg->dentry; |
5522 | + bdst = cpg->bdst; | |
1facf9fc | 5523 | + parent = dget_parent(dentry); |
5524 | + dir = parent->d_inode; | |
5525 | + h_orph = NULL; | |
5526 | + h_parent = NULL; | |
5527 | + h_dir = au_igrab(au_h_iptr(dir, bdst)); | |
5528 | + h_tmpdir = h_dir; | |
c2b27bf2 | 5529 | + pin_orig = NULL; |
1facf9fc | 5530 | + if (!h_dir->i_nlink) { |
5531 | + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr; | |
5532 | + h_orph = wbr->wbr_orph; | |
5533 | + | |
5534 | + h_parent = dget(au_h_dptr(parent, bdst)); | |
1facf9fc | 5535 | + au_set_h_dptr(parent, bdst, dget(h_orph)); |
5536 | + h_tmpdir = h_orph->d_inode; | |
1facf9fc | 5537 | + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0); |
5538 | + | |
dece6358 | 5539 | + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3); |
4a4d8108 | 5540 | + /* todo: au_h_open_pre()? */ |
86dc4139 | 5541 | + |
c2b27bf2 | 5542 | + pin_orig = cpg->pin; |
86dc4139 | 5543 | + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT, |
c2b27bf2 AM |
5544 | + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED); |
5545 | + cpg->pin = &wh_pin; | |
1facf9fc | 5546 | + } |
5547 | + | |
53392da6 | 5548 | + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE) |
c2b27bf2 AM |
5549 | + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode)) |
5550 | + err = au_cpup_wh(cpg, file); | |
1facf9fc | 5551 | + else { |
5552 | + struct au_cpup_wh_args args = { | |
5553 | + .errp = &err, | |
c2b27bf2 AM |
5554 | + .cpg = cpg, |
5555 | + .file = file | |
1facf9fc | 5556 | + }; |
5557 | + wkq_err = au_wkq_wait(au_call_cpup_wh, &args); | |
5558 | + if (unlikely(wkq_err)) | |
5559 | + err = wkq_err; | |
5560 | + } | |
5561 | + | |
5562 | + if (h_orph) { | |
5563 | + mutex_unlock(&h_tmpdir->i_mutex); | |
4a4d8108 | 5564 | + /* todo: au_h_open_post()? */ |
1facf9fc | 5565 | + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0); |
1facf9fc | 5566 | + au_set_h_dptr(parent, bdst, h_parent); |
c2b27bf2 AM |
5567 | + AuDebugOn(!pin_orig); |
5568 | + cpg->pin = pin_orig; | |
1facf9fc | 5569 | + } |
5570 | + iput(h_dir); | |
5571 | + dput(parent); | |
5572 | + | |
5573 | + return err; | |
5574 | +} | |
5575 | + | |
5576 | +/* ---------------------------------------------------------------------- */ | |
5577 | + | |
5578 | +/* | |
5579 | + * generic routine for both of copy-up and copy-down. | |
5580 | + */ | |
5581 | +/* cf. revalidate function in file.c */ | |
5582 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
5583 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5584 | + struct au_pin *pin, |
1facf9fc | 5585 | + struct dentry *h_parent, void *arg), |
5586 | + void *arg) | |
5587 | +{ | |
5588 | + int err; | |
5589 | + struct au_pin pin; | |
5590 | + struct dentry *d, *parent, *h_parent, *real_parent; | |
5591 | + | |
5592 | + err = 0; | |
5593 | + parent = dget_parent(dentry); | |
5594 | + if (IS_ROOT(parent)) | |
5595 | + goto out; | |
5596 | + | |
5597 | + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2, | |
5598 | + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE); | |
5599 | + | |
5600 | + /* do not use au_dpage */ | |
5601 | + real_parent = parent; | |
5602 | + while (1) { | |
5603 | + dput(parent); | |
5604 | + parent = dget_parent(dentry); | |
5605 | + h_parent = au_h_dptr(parent, bdst); | |
5606 | + if (h_parent) | |
5607 | + goto out; /* success */ | |
5608 | + | |
5609 | + /* find top dir which is necessary to cpup */ | |
5610 | + do { | |
5611 | + d = parent; | |
5612 | + dput(parent); | |
5613 | + parent = dget_parent(d); | |
5614 | + di_read_lock_parent3(parent, !AuLock_IR); | |
5615 | + h_parent = au_h_dptr(parent, bdst); | |
5616 | + di_read_unlock(parent, !AuLock_IR); | |
5617 | + } while (!h_parent); | |
5618 | + | |
5619 | + if (d != real_parent) | |
5620 | + di_write_lock_child3(d); | |
5621 | + | |
5622 | + /* somebody else might create while we were sleeping */ | |
5623 | + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) { | |
5624 | + if (au_h_dptr(d, bdst)) | |
5625 | + au_update_dbstart(d); | |
5626 | + | |
5627 | + au_pin_set_dentry(&pin, d); | |
5628 | + err = au_do_pin(&pin); | |
5629 | + if (!err) { | |
86dc4139 | 5630 | + err = cp(d, bdst, &pin, h_parent, arg); |
1facf9fc | 5631 | + au_unpin(&pin); |
5632 | + } | |
5633 | + } | |
5634 | + | |
5635 | + if (d != real_parent) | |
5636 | + di_write_unlock(d); | |
5637 | + if (unlikely(err)) | |
5638 | + break; | |
5639 | + } | |
5640 | + | |
4f0767ce | 5641 | +out: |
1facf9fc | 5642 | + dput(parent); |
5643 | + return err; | |
5644 | +} | |
5645 | + | |
5646 | +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5647 | + struct au_pin *pin, |
1facf9fc | 5648 | + struct dentry *h_parent __maybe_unused , |
5649 | + void *arg __maybe_unused) | |
5650 | +{ | |
c2b27bf2 AM |
5651 | + struct au_cp_generic cpg = { |
5652 | + .dentry = dentry, | |
5653 | + .bdst = bdst, | |
5654 | + .bsrc = -1, | |
5655 | + .len = 0, | |
5656 | + .pin = pin, | |
5657 | + .flags = AuCpup_DTIME | |
5658 | + }; | |
5659 | + return au_sio_cpup_simple(&cpg); | |
1facf9fc | 5660 | +} |
5661 | + | |
5662 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
5663 | +{ | |
5664 | + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL); | |
5665 | +} | |
5666 | + | |
5667 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
5668 | +{ | |
5669 | + int err; | |
5670 | + struct dentry *parent; | |
5671 | + struct inode *dir; | |
5672 | + | |
5673 | + parent = dget_parent(dentry); | |
5674 | + dir = parent->d_inode; | |
5675 | + err = 0; | |
5676 | + if (au_h_iptr(dir, bdst)) | |
5677 | + goto out; | |
5678 | + | |
5679 | + di_read_unlock(parent, AuLock_IR); | |
5680 | + di_write_lock_parent(parent); | |
5681 | + /* someone else might change our inode while we were sleeping */ | |
5682 | + if (!au_h_iptr(dir, bdst)) | |
5683 | + err = au_cpup_dirs(dentry, bdst); | |
5684 | + di_downgrade_lock(parent, AuLock_IR); | |
5685 | + | |
4f0767ce | 5686 | +out: |
1facf9fc | 5687 | + dput(parent); |
5688 | + return err; | |
5689 | +} | |
7f207e10 AM |
5690 | diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h |
5691 | --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 5692 | +++ linux/fs/aufs/cpup.h 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 5693 | @@ -0,0 +1,94 @@ |
1facf9fc | 5694 | +/* |
523b37e3 | 5695 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 5696 | + * |
5697 | + * This program, aufs is free software; you can redistribute it and/or modify | |
5698 | + * it under the terms of the GNU General Public License as published by | |
5699 | + * the Free Software Foundation; either version 2 of the License, or | |
5700 | + * (at your option) any later version. | |
dece6358 AM |
5701 | + * |
5702 | + * This program is distributed in the hope that it will be useful, | |
5703 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5704 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
5705 | + * GNU General Public License for more details. | |
5706 | + * | |
5707 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 5708 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 5709 | + */ |
5710 | + | |
5711 | +/* | |
5712 | + * copy-up/down functions | |
5713 | + */ | |
5714 | + | |
5715 | +#ifndef __AUFS_CPUP_H__ | |
5716 | +#define __AUFS_CPUP_H__ | |
5717 | + | |
5718 | +#ifdef __KERNEL__ | |
5719 | + | |
dece6358 | 5720 | +#include <linux/path.h> |
1facf9fc | 5721 | + |
dece6358 AM |
5722 | +struct inode; |
5723 | +struct file; | |
86dc4139 | 5724 | +struct au_pin; |
dece6358 | 5725 | + |
86dc4139 | 5726 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags); |
1facf9fc | 5727 | +void au_cpup_attr_timesizes(struct inode *inode); |
5728 | +void au_cpup_attr_nlink(struct inode *inode, int force); | |
5729 | +void au_cpup_attr_changeable(struct inode *inode); | |
5730 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode); | |
5731 | +void au_cpup_attr_all(struct inode *inode, int force); | |
5732 | + | |
5733 | +/* ---------------------------------------------------------------------- */ | |
5734 | + | |
c2b27bf2 AM |
5735 | +struct au_cp_generic { |
5736 | + struct dentry *dentry; | |
5737 | + aufs_bindex_t bdst, bsrc; | |
5738 | + loff_t len; | |
5739 | + struct au_pin *pin; | |
5740 | + unsigned int flags; | |
5741 | +}; | |
5742 | + | |
1facf9fc | 5743 | +/* cpup flags */ |
392086de AM |
5744 | +#define AuCpup_DTIME 1 /* do dtime_store/revert */ |
5745 | +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino, | |
5746 | + for link(2) */ | |
5747 | +#define AuCpup_RENAME (1 << 2) /* rename after cpup */ | |
5748 | +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in | |
5749 | + cpup */ | |
5750 | +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the | |
5751 | + existing entry */ | |
5752 | +#define AuCpup_RWDST (1 << 5) /* force write target even if | |
5753 | + the branch is marked as RO */ | |
c2b27bf2 | 5754 | + |
1facf9fc | 5755 | +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name) |
7f207e10 AM |
5756 | +#define au_fset_cpup(flags, name) \ |
5757 | + do { (flags) |= AuCpup_##name; } while (0) | |
5758 | +#define au_fclr_cpup(flags, name) \ | |
5759 | + do { (flags) &= ~AuCpup_##name; } while (0) | |
1facf9fc | 5760 | + |
5761 | +int au_copy_file(struct file *dst, struct file *src, loff_t len); | |
c2b27bf2 AM |
5762 | +int au_sio_cpup_simple(struct au_cp_generic *cpg); |
5763 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg); | |
5764 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file); | |
1facf9fc | 5765 | + |
5766 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
5767 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 5768 | + struct au_pin *pin, |
1facf9fc | 5769 | + struct dentry *h_parent, void *arg), |
5770 | + void *arg); | |
5771 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
5772 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
5773 | + | |
5774 | +/* ---------------------------------------------------------------------- */ | |
5775 | + | |
5776 | +/* keep timestamps when copyup */ | |
5777 | +struct au_dtime { | |
5778 | + struct dentry *dt_dentry; | |
5779 | + struct path dt_h_path; | |
5780 | + struct timespec dt_atime, dt_mtime; | |
5781 | +}; | |
5782 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
5783 | + struct path *h_path); | |
5784 | +void au_dtime_revert(struct au_dtime *dt); | |
5785 | + | |
5786 | +#endif /* __KERNEL__ */ | |
5787 | +#endif /* __AUFS_CPUP_H__ */ | |
7f207e10 AM |
5788 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c |
5789 | --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 5790 | +++ linux/fs/aufs/dbgaufs.c 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 5791 | @@ -0,0 +1,432 @@ |
1facf9fc | 5792 | +/* |
523b37e3 | 5793 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 5794 | + * |
5795 | + * This program, aufs is free software; you can redistribute it and/or modify | |
5796 | + * it under the terms of the GNU General Public License as published by | |
5797 | + * the Free Software Foundation; either version 2 of the License, or | |
5798 | + * (at your option) any later version. | |
dece6358 AM |
5799 | + * |
5800 | + * This program is distributed in the hope that it will be useful, | |
5801 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5802 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
5803 | + * GNU General Public License for more details. | |
5804 | + * | |
5805 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 5806 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 5807 | + */ |
5808 | + | |
5809 | +/* | |
5810 | + * debugfs interface | |
5811 | + */ | |
5812 | + | |
5813 | +#include <linux/debugfs.h> | |
5814 | +#include "aufs.h" | |
5815 | + | |
5816 | +#ifndef CONFIG_SYSFS | |
5817 | +#error DEBUG_FS depends upon SYSFS | |
5818 | +#endif | |
5819 | + | |
5820 | +static struct dentry *dbgaufs; | |
5821 | +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH; | |
5822 | + | |
5823 | +/* 20 is max digits length of ulong 64 */ | |
5824 | +struct dbgaufs_arg { | |
5825 | + int n; | |
5826 | + char a[20 * 4]; | |
5827 | +}; | |
5828 | + | |
5829 | +/* | |
5830 | + * common function for all XINO files | |
5831 | + */ | |
5832 | +static int dbgaufs_xi_release(struct inode *inode __maybe_unused, | |
5833 | + struct file *file) | |
5834 | +{ | |
5835 | + kfree(file->private_data); | |
5836 | + return 0; | |
5837 | +} | |
5838 | + | |
5839 | +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt) | |
5840 | +{ | |
5841 | + int err; | |
5842 | + struct kstat st; | |
5843 | + struct dbgaufs_arg *p; | |
5844 | + | |
5845 | + err = -ENOMEM; | |
5846 | + p = kmalloc(sizeof(*p), GFP_NOFS); | |
5847 | + if (unlikely(!p)) | |
5848 | + goto out; | |
5849 | + | |
5850 | + err = 0; | |
5851 | + p->n = 0; | |
5852 | + file->private_data = p; | |
5853 | + if (!xf) | |
5854 | + goto out; | |
5855 | + | |
c06a8ce3 | 5856 | + err = vfs_getattr(&xf->f_path, &st); |
1facf9fc | 5857 | + if (!err) { |
5858 | + if (do_fcnt) | |
5859 | + p->n = snprintf | |
5860 | + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n", | |
5861 | + (long)file_count(xf), st.blocks, st.blksize, | |
5862 | + (long long)st.size); | |
5863 | + else | |
5864 | + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n", | |
5865 | + st.blocks, st.blksize, | |
5866 | + (long long)st.size); | |
5867 | + AuDebugOn(p->n >= sizeof(p->a)); | |
5868 | + } else { | |
5869 | + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err); | |
5870 | + err = 0; | |
5871 | + } | |
5872 | + | |
4f0767ce | 5873 | +out: |
1facf9fc | 5874 | + return err; |
5875 | + | |
5876 | +} | |
5877 | + | |
5878 | +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf, | |
5879 | + size_t count, loff_t *ppos) | |
5880 | +{ | |
5881 | + struct dbgaufs_arg *p; | |
5882 | + | |
5883 | + p = file->private_data; | |
5884 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
5885 | +} | |
5886 | + | |
5887 | +/* ---------------------------------------------------------------------- */ | |
5888 | + | |
86dc4139 AM |
5889 | +struct dbgaufs_plink_arg { |
5890 | + int n; | |
5891 | + char a[]; | |
5892 | +}; | |
5893 | + | |
5894 | +static int dbgaufs_plink_release(struct inode *inode __maybe_unused, | |
5895 | + struct file *file) | |
5896 | +{ | |
5897 | + free_page((unsigned long)file->private_data); | |
5898 | + return 0; | |
5899 | +} | |
5900 | + | |
5901 | +static int dbgaufs_plink_open(struct inode *inode, struct file *file) | |
5902 | +{ | |
5903 | + int err, i, limit; | |
5904 | + unsigned long n, sum; | |
5905 | + struct dbgaufs_plink_arg *p; | |
5906 | + struct au_sbinfo *sbinfo; | |
5907 | + struct super_block *sb; | |
5908 | + struct au_sphlhead *sphl; | |
5909 | + | |
5910 | + err = -ENOMEM; | |
5911 | + p = (void *)get_zeroed_page(GFP_NOFS); | |
5912 | + if (unlikely(!p)) | |
5913 | + goto out; | |
5914 | + | |
5915 | + err = -EFBIG; | |
5916 | + sbinfo = inode->i_private; | |
5917 | + sb = sbinfo->si_sb; | |
5918 | + si_noflush_read_lock(sb); | |
5919 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
5920 | + limit = PAGE_SIZE - sizeof(p->n); | |
5921 | + | |
5922 | + /* the number of buckets */ | |
5923 | + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH); | |
5924 | + p->n += n; | |
5925 | + limit -= n; | |
5926 | + | |
5927 | + sum = 0; | |
5928 | + for (i = 0, sphl = sbinfo->si_plink; | |
5929 | + i < AuPlink_NHASH; | |
5930 | + i++, sphl++) { | |
5931 | + n = au_sphl_count(sphl); | |
5932 | + sum += n; | |
5933 | + | |
5934 | + n = snprintf(p->a + p->n, limit, "%lu ", n); | |
5935 | + p->n += n; | |
5936 | + limit -= n; | |
5937 | + if (unlikely(limit <= 0)) | |
5938 | + goto out_free; | |
5939 | + } | |
5940 | + p->a[p->n - 1] = '\n'; | |
5941 | + | |
5942 | + /* the sum of plinks */ | |
5943 | + n = snprintf(p->a + p->n, limit, "%lu\n", sum); | |
5944 | + p->n += n; | |
5945 | + limit -= n; | |
5946 | + if (unlikely(limit <= 0)) | |
5947 | + goto out_free; | |
5948 | + } else { | |
5949 | +#define str "1\n0\n0\n" | |
5950 | + p->n = sizeof(str) - 1; | |
5951 | + strcpy(p->a, str); | |
5952 | +#undef str | |
5953 | + } | |
5954 | + si_read_unlock(sb); | |
5955 | + | |
5956 | + err = 0; | |
5957 | + file->private_data = p; | |
5958 | + goto out; /* success */ | |
5959 | + | |
5960 | +out_free: | |
5961 | + free_page((unsigned long)p); | |
5962 | +out: | |
5963 | + return err; | |
5964 | +} | |
5965 | + | |
5966 | +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf, | |
5967 | + size_t count, loff_t *ppos) | |
5968 | +{ | |
5969 | + struct dbgaufs_plink_arg *p; | |
5970 | + | |
5971 | + p = file->private_data; | |
5972 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
5973 | +} | |
5974 | + | |
5975 | +static const struct file_operations dbgaufs_plink_fop = { | |
5976 | + .owner = THIS_MODULE, | |
5977 | + .open = dbgaufs_plink_open, | |
5978 | + .release = dbgaufs_plink_release, | |
5979 | + .read = dbgaufs_plink_read | |
5980 | +}; | |
5981 | + | |
5982 | +/* ---------------------------------------------------------------------- */ | |
5983 | + | |
1facf9fc | 5984 | +static int dbgaufs_xib_open(struct inode *inode, struct file *file) |
5985 | +{ | |
5986 | + int err; | |
5987 | + struct au_sbinfo *sbinfo; | |
5988 | + struct super_block *sb; | |
5989 | + | |
5990 | + sbinfo = inode->i_private; | |
5991 | + sb = sbinfo->si_sb; | |
5992 | + si_noflush_read_lock(sb); | |
5993 | + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0); | |
5994 | + si_read_unlock(sb); | |
5995 | + return err; | |
5996 | +} | |
5997 | + | |
5998 | +static const struct file_operations dbgaufs_xib_fop = { | |
4a4d8108 | 5999 | + .owner = THIS_MODULE, |
1facf9fc | 6000 | + .open = dbgaufs_xib_open, |
6001 | + .release = dbgaufs_xi_release, | |
6002 | + .read = dbgaufs_xi_read | |
6003 | +}; | |
6004 | + | |
6005 | +/* ---------------------------------------------------------------------- */ | |
6006 | + | |
6007 | +#define DbgaufsXi_PREFIX "xi" | |
6008 | + | |
6009 | +static int dbgaufs_xino_open(struct inode *inode, struct file *file) | |
6010 | +{ | |
6011 | + int err; | |
6012 | + long l; | |
6013 | + struct au_sbinfo *sbinfo; | |
6014 | + struct super_block *sb; | |
6015 | + struct file *xf; | |
6016 | + struct qstr *name; | |
6017 | + | |
6018 | + err = -ENOENT; | |
6019 | + xf = NULL; | |
6020 | + name = &file->f_dentry->d_name; | |
6021 | + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX) | |
6022 | + || memcmp(name->name, DbgaufsXi_PREFIX, | |
6023 | + sizeof(DbgaufsXi_PREFIX) - 1))) | |
6024 | + goto out; | |
9dbd164d | 6025 | + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l); |
1facf9fc | 6026 | + if (unlikely(err)) |
6027 | + goto out; | |
6028 | + | |
6029 | + sbinfo = inode->i_private; | |
6030 | + sb = sbinfo->si_sb; | |
6031 | + si_noflush_read_lock(sb); | |
6032 | + if (l <= au_sbend(sb)) { | |
6033 | + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file; | |
6034 | + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1); | |
6035 | + } else | |
6036 | + err = -ENOENT; | |
6037 | + si_read_unlock(sb); | |
6038 | + | |
4f0767ce | 6039 | +out: |
1facf9fc | 6040 | + return err; |
6041 | +} | |
6042 | + | |
6043 | +static const struct file_operations dbgaufs_xino_fop = { | |
4a4d8108 | 6044 | + .owner = THIS_MODULE, |
1facf9fc | 6045 | + .open = dbgaufs_xino_open, |
6046 | + .release = dbgaufs_xi_release, | |
6047 | + .read = dbgaufs_xi_read | |
6048 | +}; | |
6049 | + | |
6050 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
6051 | +{ | |
6052 | + aufs_bindex_t bend; | |
6053 | + struct au_branch *br; | |
6054 | + struct au_xino_file *xi; | |
6055 | + | |
6056 | + if (!au_sbi(sb)->si_dbgaufs) | |
6057 | + return; | |
6058 | + | |
6059 | + bend = au_sbend(sb); | |
6060 | + for (; bindex <= bend; bindex++) { | |
6061 | + br = au_sbr(sb, bindex); | |
6062 | + xi = &br->br_xino; | |
c06a8ce3 AM |
6063 | + debugfs_remove(xi->xi_dbgaufs); |
6064 | + xi->xi_dbgaufs = NULL; | |
1facf9fc | 6065 | + } |
6066 | +} | |
6067 | + | |
6068 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
6069 | +{ | |
6070 | + struct au_sbinfo *sbinfo; | |
6071 | + struct dentry *parent; | |
6072 | + struct au_branch *br; | |
6073 | + struct au_xino_file *xi; | |
6074 | + aufs_bindex_t bend; | |
6075 | + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */ | |
6076 | + | |
6077 | + sbinfo = au_sbi(sb); | |
6078 | + parent = sbinfo->si_dbgaufs; | |
6079 | + if (!parent) | |
6080 | + return; | |
6081 | + | |
6082 | + bend = au_sbend(sb); | |
6083 | + for (; bindex <= bend; bindex++) { | |
6084 | + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex); | |
6085 | + br = au_sbr(sb, bindex); | |
6086 | + xi = &br->br_xino; | |
6087 | + AuDebugOn(xi->xi_dbgaufs); | |
6088 | + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent, | |
6089 | + sbinfo, &dbgaufs_xino_fop); | |
6090 | + /* ignore an error */ | |
6091 | + if (unlikely(!xi->xi_dbgaufs)) | |
6092 | + AuWarn1("failed %s under debugfs\n", name); | |
6093 | + } | |
6094 | +} | |
6095 | + | |
6096 | +/* ---------------------------------------------------------------------- */ | |
6097 | + | |
6098 | +#ifdef CONFIG_AUFS_EXPORT | |
6099 | +static int dbgaufs_xigen_open(struct inode *inode, struct file *file) | |
6100 | +{ | |
6101 | + int err; | |
6102 | + struct au_sbinfo *sbinfo; | |
6103 | + struct super_block *sb; | |
6104 | + | |
6105 | + sbinfo = inode->i_private; | |
6106 | + sb = sbinfo->si_sb; | |
6107 | + si_noflush_read_lock(sb); | |
6108 | + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0); | |
6109 | + si_read_unlock(sb); | |
6110 | + return err; | |
6111 | +} | |
6112 | + | |
6113 | +static const struct file_operations dbgaufs_xigen_fop = { | |
4a4d8108 | 6114 | + .owner = THIS_MODULE, |
1facf9fc | 6115 | + .open = dbgaufs_xigen_open, |
6116 | + .release = dbgaufs_xi_release, | |
6117 | + .read = dbgaufs_xi_read | |
6118 | +}; | |
6119 | + | |
6120 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6121 | +{ | |
6122 | + int err; | |
6123 | + | |
dece6358 | 6124 | + /* |
c1595e42 | 6125 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6126 | + * so the tiny check for si_rwsem is unnecessary. |
6127 | + */ | |
6128 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6129 | + | |
1facf9fc | 6130 | + err = -EIO; |
6131 | + sbinfo->si_dbgaufs_xigen = debugfs_create_file | |
6132 | + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6133 | + &dbgaufs_xigen_fop); | |
6134 | + if (sbinfo->si_dbgaufs_xigen) | |
6135 | + err = 0; | |
6136 | + | |
6137 | + return err; | |
6138 | +} | |
6139 | +#else | |
6140 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6141 | +{ | |
6142 | + return 0; | |
6143 | +} | |
6144 | +#endif /* CONFIG_AUFS_EXPORT */ | |
6145 | + | |
6146 | +/* ---------------------------------------------------------------------- */ | |
6147 | + | |
6148 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo) | |
6149 | +{ | |
dece6358 | 6150 | + /* |
c1595e42 | 6151 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6152 | + * so the tiny check for si_rwsem is unnecessary. |
6153 | + */ | |
6154 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6155 | + | |
1facf9fc | 6156 | + debugfs_remove_recursive(sbinfo->si_dbgaufs); |
6157 | + sbinfo->si_dbgaufs = NULL; | |
6158 | + kobject_put(&sbinfo->si_kobj); | |
6159 | +} | |
6160 | + | |
6161 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo) | |
6162 | +{ | |
6163 | + int err; | |
6164 | + char name[SysaufsSiNameLen]; | |
6165 | + | |
dece6358 | 6166 | + /* |
c1595e42 | 6167 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6168 | + * so the tiny check for si_rwsem is unnecessary. |
6169 | + */ | |
6170 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6171 | + | |
1facf9fc | 6172 | + err = -ENOENT; |
6173 | + if (!dbgaufs) { | |
6174 | + AuErr1("/debug/aufs is uninitialized\n"); | |
6175 | + goto out; | |
6176 | + } | |
6177 | + | |
6178 | + err = -EIO; | |
6179 | + sysaufs_name(sbinfo, name); | |
6180 | + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs); | |
6181 | + if (unlikely(!sbinfo->si_dbgaufs)) | |
6182 | + goto out; | |
6183 | + kobject_get(&sbinfo->si_kobj); | |
6184 | + | |
6185 | + sbinfo->si_dbgaufs_xib = debugfs_create_file | |
6186 | + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6187 | + &dbgaufs_xib_fop); | |
6188 | + if (unlikely(!sbinfo->si_dbgaufs_xib)) | |
6189 | + goto out_dir; | |
6190 | + | |
86dc4139 AM |
6191 | + sbinfo->si_dbgaufs_plink = debugfs_create_file |
6192 | + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6193 | + &dbgaufs_plink_fop); | |
6194 | + if (unlikely(!sbinfo->si_dbgaufs_plink)) | |
6195 | + goto out_dir; | |
6196 | + | |
1facf9fc | 6197 | + err = dbgaufs_xigen_init(sbinfo); |
6198 | + if (!err) | |
6199 | + goto out; /* success */ | |
6200 | + | |
4f0767ce | 6201 | +out_dir: |
1facf9fc | 6202 | + dbgaufs_si_fin(sbinfo); |
4f0767ce | 6203 | +out: |
1facf9fc | 6204 | + return err; |
6205 | +} | |
6206 | + | |
6207 | +/* ---------------------------------------------------------------------- */ | |
6208 | + | |
6209 | +void dbgaufs_fin(void) | |
6210 | +{ | |
6211 | + debugfs_remove(dbgaufs); | |
6212 | +} | |
6213 | + | |
6214 | +int __init dbgaufs_init(void) | |
6215 | +{ | |
6216 | + int err; | |
6217 | + | |
6218 | + err = -EIO; | |
6219 | + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL); | |
6220 | + if (dbgaufs) | |
6221 | + err = 0; | |
6222 | + return err; | |
6223 | +} | |
7f207e10 AM |
6224 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h |
6225 | --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 6226 | +++ linux/fs/aufs/dbgaufs.h 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 6227 | @@ -0,0 +1,48 @@ |
1facf9fc | 6228 | +/* |
523b37e3 | 6229 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 6230 | + * |
6231 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6232 | + * it under the terms of the GNU General Public License as published by | |
6233 | + * the Free Software Foundation; either version 2 of the License, or | |
6234 | + * (at your option) any later version. | |
dece6358 AM |
6235 | + * |
6236 | + * This program is distributed in the hope that it will be useful, | |
6237 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6238 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6239 | + * GNU General Public License for more details. | |
6240 | + * | |
6241 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6242 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6243 | + */ |
6244 | + | |
6245 | +/* | |
6246 | + * debugfs interface | |
6247 | + */ | |
6248 | + | |
6249 | +#ifndef __DBGAUFS_H__ | |
6250 | +#define __DBGAUFS_H__ | |
6251 | + | |
6252 | +#ifdef __KERNEL__ | |
6253 | + | |
dece6358 | 6254 | +struct super_block; |
1facf9fc | 6255 | +struct au_sbinfo; |
dece6358 | 6256 | + |
1facf9fc | 6257 | +#ifdef CONFIG_DEBUG_FS |
6258 | +/* dbgaufs.c */ | |
6259 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
6260 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
6261 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo); | |
6262 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo); | |
6263 | +void dbgaufs_fin(void); | |
6264 | +int __init dbgaufs_init(void); | |
1facf9fc | 6265 | +#else |
4a4d8108 AM |
6266 | +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) |
6267 | +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
6268 | +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo) | |
6269 | +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo) | |
6270 | +AuStubVoid(dbgaufs_fin, void) | |
6271 | +AuStubInt0(__init dbgaufs_init, void) | |
1facf9fc | 6272 | +#endif /* CONFIG_DEBUG_FS */ |
6273 | + | |
6274 | +#endif /* __KERNEL__ */ | |
6275 | +#endif /* __DBGAUFS_H__ */ | |
7f207e10 AM |
6276 | diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c |
6277 | --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
6278 | +++ linux/fs/aufs/dcsub.c 2015-01-25 13:00:38.631047076 +0100 |
6279 | @@ -0,0 +1,224 @@ | |
1facf9fc | 6280 | +/* |
523b37e3 | 6281 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 6282 | + * |
6283 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6284 | + * it under the terms of the GNU General Public License as published by | |
6285 | + * the Free Software Foundation; either version 2 of the License, or | |
6286 | + * (at your option) any later version. | |
dece6358 AM |
6287 | + * |
6288 | + * This program is distributed in the hope that it will be useful, | |
6289 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6290 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6291 | + * GNU General Public License for more details. | |
6292 | + * | |
6293 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6294 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6295 | + */ |
6296 | + | |
6297 | +/* | |
6298 | + * sub-routines for dentry cache | |
6299 | + */ | |
6300 | + | |
6301 | +#include "aufs.h" | |
6302 | + | |
6303 | +static void au_dpage_free(struct au_dpage *dpage) | |
6304 | +{ | |
6305 | + int i; | |
6306 | + struct dentry **p; | |
6307 | + | |
6308 | + p = dpage->dentries; | |
6309 | + for (i = 0; i < dpage->ndentry; i++) | |
6310 | + dput(*p++); | |
6311 | + free_page((unsigned long)dpage->dentries); | |
6312 | +} | |
6313 | + | |
6314 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp) | |
6315 | +{ | |
6316 | + int err; | |
6317 | + void *p; | |
6318 | + | |
6319 | + err = -ENOMEM; | |
6320 | + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp); | |
6321 | + if (unlikely(!dpages->dpages)) | |
6322 | + goto out; | |
6323 | + | |
6324 | + p = (void *)__get_free_page(gfp); | |
6325 | + if (unlikely(!p)) | |
6326 | + goto out_dpages; | |
6327 | + | |
6328 | + dpages->dpages[0].ndentry = 0; | |
6329 | + dpages->dpages[0].dentries = p; | |
6330 | + dpages->ndpage = 1; | |
6331 | + return 0; /* success */ | |
6332 | + | |
4f0767ce | 6333 | +out_dpages: |
1facf9fc | 6334 | + kfree(dpages->dpages); |
4f0767ce | 6335 | +out: |
1facf9fc | 6336 | + return err; |
6337 | +} | |
6338 | + | |
6339 | +void au_dpages_free(struct au_dcsub_pages *dpages) | |
6340 | +{ | |
6341 | + int i; | |
6342 | + struct au_dpage *p; | |
6343 | + | |
6344 | + p = dpages->dpages; | |
6345 | + for (i = 0; i < dpages->ndpage; i++) | |
6346 | + au_dpage_free(p++); | |
6347 | + kfree(dpages->dpages); | |
6348 | +} | |
6349 | + | |
6350 | +static int au_dpages_append(struct au_dcsub_pages *dpages, | |
6351 | + struct dentry *dentry, gfp_t gfp) | |
6352 | +{ | |
6353 | + int err, sz; | |
6354 | + struct au_dpage *dpage; | |
6355 | + void *p; | |
6356 | + | |
6357 | + dpage = dpages->dpages + dpages->ndpage - 1; | |
6358 | + sz = PAGE_SIZE / sizeof(dentry); | |
6359 | + if (unlikely(dpage->ndentry >= sz)) { | |
6360 | + AuLabel(new dpage); | |
6361 | + err = -ENOMEM; | |
6362 | + sz = dpages->ndpage * sizeof(*dpages->dpages); | |
6363 | + p = au_kzrealloc(dpages->dpages, sz, | |
6364 | + sz + sizeof(*dpages->dpages), gfp); | |
6365 | + if (unlikely(!p)) | |
6366 | + goto out; | |
6367 | + | |
6368 | + dpages->dpages = p; | |
6369 | + dpage = dpages->dpages + dpages->ndpage; | |
6370 | + p = (void *)__get_free_page(gfp); | |
6371 | + if (unlikely(!p)) | |
6372 | + goto out; | |
6373 | + | |
6374 | + dpage->ndentry = 0; | |
6375 | + dpage->dentries = p; | |
6376 | + dpages->ndpage++; | |
6377 | + } | |
6378 | + | |
c1595e42 | 6379 | + AuDebugOn(au_dcount(dentry) <= 0); |
027c5e7a | 6380 | + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry); |
1facf9fc | 6381 | + return 0; /* success */ |
6382 | + | |
4f0767ce | 6383 | +out: |
1facf9fc | 6384 | + return err; |
6385 | +} | |
6386 | + | |
c1595e42 JR |
6387 | +/* todo: BAD approach */ |
6388 | +/* copied from linux/fs/dcache.c */ | |
6389 | +enum d_walk_ret { | |
6390 | + D_WALK_CONTINUE, | |
6391 | + D_WALK_QUIT, | |
6392 | + D_WALK_NORETRY, | |
6393 | + D_WALK_SKIP, | |
6394 | +}; | |
6395 | + | |
6396 | +extern void d_walk(struct dentry *parent, void *data, | |
6397 | + enum d_walk_ret (*enter)(void *, struct dentry *), | |
6398 | + void (*finish)(void *)); | |
6399 | + | |
6400 | +struct ac_dpages_arg { | |
1facf9fc | 6401 | + int err; |
c1595e42 JR |
6402 | + struct au_dcsub_pages *dpages; |
6403 | + struct super_block *sb; | |
6404 | + au_dpages_test test; | |
6405 | + void *arg; | |
6406 | +}; | |
1facf9fc | 6407 | + |
c1595e42 JR |
6408 | +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry) |
6409 | +{ | |
6410 | + enum d_walk_ret ret; | |
6411 | + struct ac_dpages_arg *arg = _arg; | |
1facf9fc | 6412 | + |
c1595e42 JR |
6413 | + ret = D_WALK_CONTINUE; |
6414 | + if (dentry->d_sb == arg->sb | |
6415 | + && !IS_ROOT(dentry) | |
6416 | + && au_dcount(dentry) > 0 | |
6417 | + && au_di(dentry) | |
6418 | + && (!arg->test || arg->test(dentry, arg->arg))) { | |
6419 | + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC); | |
6420 | + if (unlikely(arg->err)) | |
6421 | + ret = D_WALK_QUIT; | |
1facf9fc | 6422 | + } |
6423 | + | |
c1595e42 JR |
6424 | + return ret; |
6425 | +} | |
027c5e7a | 6426 | + |
c1595e42 JR |
6427 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, |
6428 | + au_dpages_test test, void *arg) | |
6429 | +{ | |
6430 | + struct ac_dpages_arg args = { | |
6431 | + .err = 0, | |
6432 | + .dpages = dpages, | |
6433 | + .sb = root->d_sb, | |
6434 | + .test = test, | |
6435 | + .arg = arg | |
6436 | + }; | |
027c5e7a | 6437 | + |
c1595e42 JR |
6438 | + d_walk(root, &args, au_call_dpages_append, NULL); |
6439 | + | |
6440 | + return args.err; | |
1facf9fc | 6441 | +} |
6442 | + | |
6443 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6444 | + int do_include, au_dpages_test test, void *arg) | |
6445 | +{ | |
6446 | + int err; | |
6447 | + | |
6448 | + err = 0; | |
027c5e7a AM |
6449 | + write_seqlock(&rename_lock); |
6450 | + spin_lock(&dentry->d_lock); | |
6451 | + if (do_include | |
c1595e42 | 6452 | + && au_dcount(dentry) > 0 |
027c5e7a | 6453 | + && (!test || test(dentry, arg))) |
1facf9fc | 6454 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6455 | + spin_unlock(&dentry->d_lock); |
6456 | + if (unlikely(err)) | |
6457 | + goto out; | |
6458 | + | |
6459 | + /* | |
523b37e3 | 6460 | + * RCU for vfsmount is unnecessary since this is a traverse in a single |
027c5e7a AM |
6461 | + * mount |
6462 | + */ | |
1facf9fc | 6463 | + while (!IS_ROOT(dentry)) { |
027c5e7a AM |
6464 | + dentry = dentry->d_parent; /* rename_lock is locked */ |
6465 | + spin_lock(&dentry->d_lock); | |
c1595e42 | 6466 | + if (au_dcount(dentry) > 0 |
027c5e7a | 6467 | + && (!test || test(dentry, arg))) |
1facf9fc | 6468 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
6469 | + spin_unlock(&dentry->d_lock); |
6470 | + if (unlikely(err)) | |
6471 | + break; | |
1facf9fc | 6472 | + } |
6473 | + | |
4f0767ce | 6474 | +out: |
027c5e7a | 6475 | + write_sequnlock(&rename_lock); |
1facf9fc | 6476 | + return err; |
6477 | +} | |
6478 | + | |
027c5e7a AM |
6479 | +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg) |
6480 | +{ | |
6481 | + return au_di(dentry) && dentry->d_sb == arg; | |
6482 | +} | |
6483 | + | |
6484 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, | |
6485 | + struct dentry *dentry, int do_include) | |
6486 | +{ | |
6487 | + return au_dcsub_pages_rev(dpages, dentry, do_include, | |
6488 | + au_dcsub_dpages_aufs, dentry->d_sb); | |
6489 | +} | |
6490 | + | |
4a4d8108 | 6491 | +int au_test_subdir(struct dentry *d1, struct dentry *d2) |
1facf9fc | 6492 | +{ |
4a4d8108 AM |
6493 | + struct path path[2] = { |
6494 | + { | |
6495 | + .dentry = d1 | |
6496 | + }, | |
6497 | + { | |
6498 | + .dentry = d2 | |
6499 | + } | |
6500 | + }; | |
1facf9fc | 6501 | + |
4a4d8108 | 6502 | + return path_is_under(path + 0, path + 1); |
1facf9fc | 6503 | +} |
7f207e10 AM |
6504 | diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h |
6505 | --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
6506 | +++ linux/fs/aufs/dcsub.h 2015-01-25 13:00:38.631047076 +0100 |
6507 | @@ -0,0 +1,125 @@ | |
1facf9fc | 6508 | +/* |
523b37e3 | 6509 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 6510 | + * |
6511 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6512 | + * it under the terms of the GNU General Public License as published by | |
6513 | + * the Free Software Foundation; either version 2 of the License, or | |
6514 | + * (at your option) any later version. | |
dece6358 AM |
6515 | + * |
6516 | + * This program is distributed in the hope that it will be useful, | |
6517 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6518 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6519 | + * GNU General Public License for more details. | |
6520 | + * | |
6521 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6522 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6523 | + */ |
6524 | + | |
6525 | +/* | |
6526 | + * sub-routines for dentry cache | |
6527 | + */ | |
6528 | + | |
6529 | +#ifndef __AUFS_DCSUB_H__ | |
6530 | +#define __AUFS_DCSUB_H__ | |
6531 | + | |
6532 | +#ifdef __KERNEL__ | |
6533 | + | |
7f207e10 | 6534 | +#include <linux/dcache.h> |
027c5e7a | 6535 | +#include <linux/fs.h> |
dece6358 AM |
6536 | + |
6537 | +struct dentry; | |
1facf9fc | 6538 | + |
6539 | +struct au_dpage { | |
6540 | + int ndentry; | |
6541 | + struct dentry **dentries; | |
6542 | +}; | |
6543 | + | |
6544 | +struct au_dcsub_pages { | |
6545 | + int ndpage; | |
6546 | + struct au_dpage *dpages; | |
6547 | +}; | |
6548 | + | |
6549 | +/* ---------------------------------------------------------------------- */ | |
6550 | + | |
7f207e10 | 6551 | +/* dcsub.c */ |
1facf9fc | 6552 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp); |
6553 | +void au_dpages_free(struct au_dcsub_pages *dpages); | |
6554 | +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg); | |
6555 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, | |
6556 | + au_dpages_test test, void *arg); | |
6557 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
6558 | + int do_include, au_dpages_test test, void *arg); | |
027c5e7a AM |
6559 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, |
6560 | + struct dentry *dentry, int do_include); | |
4a4d8108 | 6561 | +int au_test_subdir(struct dentry *d1, struct dentry *d2); |
1facf9fc | 6562 | + |
7f207e10 AM |
6563 | +/* ---------------------------------------------------------------------- */ |
6564 | + | |
523b37e3 AM |
6565 | +/* |
6566 | + * todo: in linux-3.13, several similar (but faster) helpers are added to | |
6567 | + * include/linux/dcache.h. Try them (in the future). | |
6568 | + */ | |
6569 | + | |
027c5e7a AM |
6570 | +static inline int au_d_hashed_positive(struct dentry *d) |
6571 | +{ | |
6572 | + int err; | |
6573 | + struct inode *inode = d->d_inode; | |
076b876e | 6574 | + |
027c5e7a AM |
6575 | + err = 0; |
6576 | + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink)) | |
6577 | + err = -ENOENT; | |
6578 | + return err; | |
6579 | +} | |
6580 | + | |
38d290e6 JR |
6581 | +static inline int au_d_linkable(struct dentry *d) |
6582 | +{ | |
6583 | + int err; | |
6584 | + struct inode *inode = d->d_inode; | |
076b876e | 6585 | + |
38d290e6 JR |
6586 | + err = au_d_hashed_positive(d); |
6587 | + if (err | |
6588 | + && inode | |
6589 | + && (inode->i_state & I_LINKABLE)) | |
6590 | + err = 0; | |
6591 | + return err; | |
6592 | +} | |
6593 | + | |
027c5e7a AM |
6594 | +static inline int au_d_alive(struct dentry *d) |
6595 | +{ | |
6596 | + int err; | |
6597 | + struct inode *inode; | |
076b876e | 6598 | + |
027c5e7a AM |
6599 | + err = 0; |
6600 | + if (!IS_ROOT(d)) | |
6601 | + err = au_d_hashed_positive(d); | |
6602 | + else { | |
6603 | + inode = d->d_inode; | |
6604 | + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink)) | |
6605 | + err = -ENOENT; | |
6606 | + } | |
6607 | + return err; | |
6608 | +} | |
6609 | + | |
6610 | +static inline int au_alive_dir(struct dentry *d) | |
7f207e10 | 6611 | +{ |
027c5e7a | 6612 | + int err; |
076b876e | 6613 | + |
027c5e7a AM |
6614 | + err = au_d_alive(d); |
6615 | + if (unlikely(err || IS_DEADDIR(d->d_inode))) | |
6616 | + err = -ENOENT; | |
6617 | + return err; | |
7f207e10 AM |
6618 | +} |
6619 | + | |
38d290e6 JR |
6620 | +static inline int au_qstreq(struct qstr *a, struct qstr *b) |
6621 | +{ | |
6622 | + return a->len == b->len | |
6623 | + && !memcmp(a->name, b->name, a->len); | |
6624 | +} | |
6625 | + | |
c1595e42 JR |
6626 | +static inline int au_dcount(struct dentry *d) |
6627 | +{ | |
6628 | + return (int)d_count(d); | |
6629 | +} | |
6630 | + | |
1facf9fc | 6631 | +#endif /* __KERNEL__ */ |
6632 | +#endif /* __AUFS_DCSUB_H__ */ | |
7f207e10 AM |
6633 | diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c |
6634 | --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
6635 | +++ linux/fs/aufs/debug.c 2015-01-25 13:00:38.631047076 +0100 |
6636 | @@ -0,0 +1,520 @@ | |
1facf9fc | 6637 | +/* |
523b37e3 | 6638 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 6639 | + * |
6640 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6641 | + * it under the terms of the GNU General Public License as published by | |
6642 | + * the Free Software Foundation; either version 2 of the License, or | |
6643 | + * (at your option) any later version. | |
dece6358 AM |
6644 | + * |
6645 | + * This program is distributed in the hope that it will be useful, | |
6646 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6647 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6648 | + * GNU General Public License for more details. | |
6649 | + * | |
6650 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6651 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6652 | + */ |
6653 | + | |
6654 | +/* | |
6655 | + * debug print functions | |
6656 | + */ | |
6657 | + | |
7f207e10 | 6658 | +#include <linux/vt_kern.h> |
1facf9fc | 6659 | +#include "aufs.h" |
6660 | + | |
392086de AM |
6661 | +/* Returns 0, or -errno. arg is in kp->arg. */ |
6662 | +static int param_atomic_t_set(const char *val, const struct kernel_param *kp) | |
6663 | +{ | |
6664 | + int err, n; | |
6665 | + | |
6666 | + err = kstrtoint(val, 0, &n); | |
6667 | + if (!err) { | |
6668 | + if (n > 0) | |
6669 | + au_debug_on(); | |
6670 | + else | |
6671 | + au_debug_off(); | |
6672 | + } | |
6673 | + return err; | |
6674 | +} | |
6675 | + | |
6676 | +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
6677 | +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp) | |
6678 | +{ | |
6679 | + atomic_t *a; | |
6680 | + | |
6681 | + a = kp->arg; | |
6682 | + return sprintf(buffer, "%d", atomic_read(a)); | |
6683 | +} | |
6684 | + | |
6685 | +static struct kernel_param_ops param_ops_atomic_t = { | |
6686 | + .set = param_atomic_t_set, | |
6687 | + .get = param_atomic_t_get | |
6688 | + /* void (*free)(void *arg) */ | |
6689 | +}; | |
6690 | + | |
6691 | +atomic_t aufs_debug = ATOMIC_INIT(0); | |
1facf9fc | 6692 | +MODULE_PARM_DESC(debug, "debug print"); |
392086de | 6693 | +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP); |
1facf9fc | 6694 | + |
c1595e42 | 6695 | +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */ |
1facf9fc | 6696 | +char *au_plevel = KERN_DEBUG; |
e49829fe JR |
6697 | +#define dpri(fmt, ...) do { \ |
6698 | + if ((au_plevel \ | |
6699 | + && strcmp(au_plevel, KERN_DEBUG)) \ | |
6700 | + || au_debug_test()) \ | |
6701 | + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \ | |
1facf9fc | 6702 | +} while (0) |
6703 | + | |
6704 | +/* ---------------------------------------------------------------------- */ | |
6705 | + | |
6706 | +void au_dpri_whlist(struct au_nhash *whlist) | |
6707 | +{ | |
6708 | + unsigned long ul, n; | |
6709 | + struct hlist_head *head; | |
c06a8ce3 | 6710 | + struct au_vdir_wh *pos; |
1facf9fc | 6711 | + |
6712 | + n = whlist->nh_num; | |
6713 | + head = whlist->nh_head; | |
6714 | + for (ul = 0; ul < n; ul++) { | |
c06a8ce3 | 6715 | + hlist_for_each_entry(pos, head, wh_hash) |
1facf9fc | 6716 | + dpri("b%d, %.*s, %d\n", |
c06a8ce3 AM |
6717 | + pos->wh_bindex, |
6718 | + pos->wh_str.len, pos->wh_str.name, | |
6719 | + pos->wh_str.len); | |
1facf9fc | 6720 | + head++; |
6721 | + } | |
6722 | +} | |
6723 | + | |
6724 | +void au_dpri_vdir(struct au_vdir *vdir) | |
6725 | +{ | |
6726 | + unsigned long ul; | |
6727 | + union au_vdir_deblk_p p; | |
6728 | + unsigned char *o; | |
6729 | + | |
6730 | + if (!vdir || IS_ERR(vdir)) { | |
6731 | + dpri("err %ld\n", PTR_ERR(vdir)); | |
6732 | + return; | |
6733 | + } | |
6734 | + | |
6735 | + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n", | |
6736 | + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk, | |
6737 | + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version); | |
6738 | + for (ul = 0; ul < vdir->vd_nblk; ul++) { | |
6739 | + p.deblk = vdir->vd_deblk[ul]; | |
6740 | + o = p.deblk; | |
6741 | + dpri("[%lu]: %p\n", ul, o); | |
6742 | + } | |
6743 | +} | |
6744 | + | |
53392da6 | 6745 | +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn, |
1facf9fc | 6746 | + struct dentry *wh) |
6747 | +{ | |
6748 | + char *n = NULL; | |
6749 | + int l = 0; | |
6750 | + | |
6751 | + if (!inode || IS_ERR(inode)) { | |
6752 | + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode)); | |
6753 | + return -1; | |
6754 | + } | |
6755 | + | |
c2b27bf2 | 6756 | + /* the type of i_blocks depends upon CONFIG_LBDAF */ |
1facf9fc | 6757 | + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long) |
6758 | + && sizeof(inode->i_blocks) != sizeof(u64)); | |
6759 | + if (wh) { | |
6760 | + n = (void *)wh->d_name.name; | |
6761 | + l = wh->d_name.len; | |
6762 | + } | |
6763 | + | |
53392da6 AM |
6764 | + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu," |
6765 | + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n", | |
6766 | + bindex, inode, | |
1facf9fc | 6767 | + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??", |
6768 | + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode, | |
6769 | + i_size_read(inode), (unsigned long long)inode->i_blocks, | |
53392da6 | 6770 | + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff, |
1facf9fc | 6771 | + inode->i_mapping ? inode->i_mapping->nrpages : 0, |
b752ccd1 AM |
6772 | + inode->i_state, inode->i_flags, inode->i_version, |
6773 | + inode->i_generation, | |
1facf9fc | 6774 | + l ? ", wh " : "", l, n); |
6775 | + return 0; | |
6776 | +} | |
6777 | + | |
6778 | +void au_dpri_inode(struct inode *inode) | |
6779 | +{ | |
6780 | + struct au_iinfo *iinfo; | |
6781 | + aufs_bindex_t bindex; | |
53392da6 | 6782 | + int err, hn; |
1facf9fc | 6783 | + |
53392da6 | 6784 | + err = do_pri_inode(-1, inode, -1, NULL); |
1facf9fc | 6785 | + if (err || !au_test_aufs(inode->i_sb)) |
6786 | + return; | |
6787 | + | |
6788 | + iinfo = au_ii(inode); | |
6789 | + if (!iinfo) | |
6790 | + return; | |
6791 | + dpri("i-1: bstart %d, bend %d, gen %d\n", | |
537831f9 | 6792 | + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL)); |
1facf9fc | 6793 | + if (iinfo->ii_bstart < 0) |
6794 | + return; | |
53392da6 AM |
6795 | + hn = 0; |
6796 | + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) { | |
6797 | + hn = !!au_hn(iinfo->ii_hinode + bindex); | |
6798 | + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn, | |
1facf9fc | 6799 | + iinfo->ii_hinode[0 + bindex].hi_whdentry); |
53392da6 | 6800 | + } |
1facf9fc | 6801 | +} |
6802 | + | |
2cbb1c4b JR |
6803 | +void au_dpri_dalias(struct inode *inode) |
6804 | +{ | |
6805 | + struct dentry *d; | |
6806 | + | |
6807 | + spin_lock(&inode->i_lock); | |
c1595e42 | 6808 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) |
2cbb1c4b JR |
6809 | + au_dpri_dentry(d); |
6810 | + spin_unlock(&inode->i_lock); | |
6811 | +} | |
6812 | + | |
1facf9fc | 6813 | +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry) |
6814 | +{ | |
6815 | + struct dentry *wh = NULL; | |
53392da6 | 6816 | + int hn; |
076b876e | 6817 | + struct au_iinfo *iinfo; |
1facf9fc | 6818 | + |
6819 | + if (!dentry || IS_ERR(dentry)) { | |
6820 | + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry)); | |
6821 | + return -1; | |
6822 | + } | |
6823 | + /* do not call dget_parent() here */ | |
027c5e7a | 6824 | + /* note: access d_xxx without d_lock */ |
523b37e3 AM |
6825 | + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n", |
6826 | + bindex, dentry, dentry, | |
1facf9fc | 6827 | + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??", |
c1595e42 | 6828 | + au_dcount(dentry), dentry->d_flags, |
523b37e3 | 6829 | + d_unhashed(dentry) ? "un" : ""); |
53392da6 | 6830 | + hn = -1; |
1facf9fc | 6831 | + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) { |
076b876e | 6832 | + iinfo = au_ii(dentry->d_inode); |
53392da6 AM |
6833 | + if (iinfo) { |
6834 | + hn = !!au_hn(iinfo->ii_hinode + bindex); | |
1facf9fc | 6835 | + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry; |
53392da6 | 6836 | + } |
1facf9fc | 6837 | + } |
53392da6 | 6838 | + do_pri_inode(bindex, dentry->d_inode, hn, wh); |
1facf9fc | 6839 | + return 0; |
6840 | +} | |
6841 | + | |
6842 | +void au_dpri_dentry(struct dentry *dentry) | |
6843 | +{ | |
6844 | + struct au_dinfo *dinfo; | |
6845 | + aufs_bindex_t bindex; | |
6846 | + int err; | |
4a4d8108 | 6847 | + struct au_hdentry *hdp; |
1facf9fc | 6848 | + |
6849 | + err = do_pri_dentry(-1, dentry); | |
6850 | + if (err || !au_test_aufs(dentry->d_sb)) | |
6851 | + return; | |
6852 | + | |
6853 | + dinfo = au_di(dentry); | |
6854 | + if (!dinfo) | |
6855 | + return; | |
38d290e6 | 6856 | + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n", |
1facf9fc | 6857 | + dinfo->di_bstart, dinfo->di_bend, |
38d290e6 JR |
6858 | + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry), |
6859 | + dinfo->di_tmpfile); | |
1facf9fc | 6860 | + if (dinfo->di_bstart < 0) |
6861 | + return; | |
4a4d8108 | 6862 | + hdp = dinfo->di_hdentry; |
1facf9fc | 6863 | + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++) |
4a4d8108 | 6864 | + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry); |
1facf9fc | 6865 | +} |
6866 | + | |
6867 | +static int do_pri_file(aufs_bindex_t bindex, struct file *file) | |
6868 | +{ | |
6869 | + char a[32]; | |
6870 | + | |
6871 | + if (!file || IS_ERR(file)) { | |
6872 | + dpri("f%d: err %ld\n", bindex, PTR_ERR(file)); | |
6873 | + return -1; | |
6874 | + } | |
6875 | + a[0] = 0; | |
6876 | + if (bindex < 0 | |
6877 | + && file->f_dentry | |
6878 | + && au_test_aufs(file->f_dentry->d_sb) | |
6879 | + && au_fi(file)) | |
e49829fe | 6880 | + snprintf(a, sizeof(a), ", gen %d, mmapped %d", |
2cbb1c4b | 6881 | + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped)); |
b752ccd1 | 6882 | + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n", |
1facf9fc | 6883 | + bindex, file->f_mode, file->f_flags, (long)file_count(file), |
b752ccd1 | 6884 | + file->f_version, file->f_pos, a); |
1facf9fc | 6885 | + if (file->f_dentry) |
6886 | + do_pri_dentry(bindex, file->f_dentry); | |
6887 | + return 0; | |
6888 | +} | |
6889 | + | |
6890 | +void au_dpri_file(struct file *file) | |
6891 | +{ | |
6892 | + struct au_finfo *finfo; | |
4a4d8108 AM |
6893 | + struct au_fidir *fidir; |
6894 | + struct au_hfile *hfile; | |
1facf9fc | 6895 | + aufs_bindex_t bindex; |
6896 | + int err; | |
6897 | + | |
6898 | + err = do_pri_file(-1, file); | |
6899 | + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb)) | |
6900 | + return; | |
6901 | + | |
6902 | + finfo = au_fi(file); | |
6903 | + if (!finfo) | |
6904 | + return; | |
4a4d8108 | 6905 | + if (finfo->fi_btop < 0) |
1facf9fc | 6906 | + return; |
4a4d8108 AM |
6907 | + fidir = finfo->fi_hdir; |
6908 | + if (!fidir) | |
6909 | + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file); | |
6910 | + else | |
e49829fe JR |
6911 | + for (bindex = finfo->fi_btop; |
6912 | + bindex >= 0 && bindex <= fidir->fd_bbot; | |
4a4d8108 AM |
6913 | + bindex++) { |
6914 | + hfile = fidir->fd_hfile + bindex; | |
6915 | + do_pri_file(bindex, hfile ? hfile->hf_file : NULL); | |
6916 | + } | |
1facf9fc | 6917 | +} |
6918 | + | |
6919 | +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br) | |
6920 | +{ | |
6921 | + struct vfsmount *mnt; | |
6922 | + struct super_block *sb; | |
6923 | + | |
6924 | + if (!br || IS_ERR(br)) | |
6925 | + goto out; | |
86dc4139 | 6926 | + mnt = au_br_mnt(br); |
1facf9fc | 6927 | + if (!mnt || IS_ERR(mnt)) |
6928 | + goto out; | |
6929 | + sb = mnt->mnt_sb; | |
6930 | + if (!sb || IS_ERR(sb)) | |
6931 | + goto out; | |
6932 | + | |
1e00d052 | 6933 | + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, " |
b752ccd1 | 6934 | + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, " |
1facf9fc | 6935 | + "xino %d\n", |
1e00d052 AM |
6936 | + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count), |
6937 | + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev), | |
b752ccd1 | 6938 | + sb->s_flags, sb->s_count, |
1facf9fc | 6939 | + atomic_read(&sb->s_active), !!br->br_xino.xi_file); |
6940 | + return 0; | |
6941 | + | |
4f0767ce | 6942 | +out: |
1facf9fc | 6943 | + dpri("s%d: err %ld\n", bindex, PTR_ERR(br)); |
6944 | + return -1; | |
6945 | +} | |
6946 | + | |
6947 | +void au_dpri_sb(struct super_block *sb) | |
6948 | +{ | |
6949 | + struct au_sbinfo *sbinfo; | |
6950 | + aufs_bindex_t bindex; | |
6951 | + int err; | |
6952 | + /* to reuduce stack size */ | |
6953 | + struct { | |
6954 | + struct vfsmount mnt; | |
6955 | + struct au_branch fake; | |
6956 | + } *a; | |
6957 | + | |
6958 | + /* this function can be called from magic sysrq */ | |
6959 | + a = kzalloc(sizeof(*a), GFP_ATOMIC); | |
6960 | + if (unlikely(!a)) { | |
6961 | + dpri("no memory\n"); | |
6962 | + return; | |
6963 | + } | |
6964 | + | |
6965 | + a->mnt.mnt_sb = sb; | |
6966 | + a->fake.br_perm = 0; | |
86dc4139 | 6967 | + a->fake.br_path.mnt = &a->mnt; |
1facf9fc | 6968 | + a->fake.br_xino.xi_file = NULL; |
6969 | + atomic_set(&a->fake.br_count, 0); | |
6970 | + smp_mb(); /* atomic_set */ | |
6971 | + err = do_pri_br(-1, &a->fake); | |
6972 | + kfree(a); | |
6973 | + dpri("dev 0x%x\n", sb->s_dev); | |
6974 | + if (err || !au_test_aufs(sb)) | |
6975 | + return; | |
6976 | + | |
6977 | + sbinfo = au_sbi(sb); | |
6978 | + if (!sbinfo) | |
6979 | + return; | |
6980 | + dpri("nw %d, gen %u, kobj %d\n", | |
6981 | + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation, | |
6982 | + atomic_read(&sbinfo->si_kobj.kref.refcount)); | |
6983 | + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++) | |
6984 | + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]); | |
6985 | +} | |
6986 | + | |
6987 | +/* ---------------------------------------------------------------------- */ | |
6988 | + | |
6989 | +void au_dbg_sleep_jiffy(int jiffy) | |
6990 | +{ | |
6991 | + while (jiffy) | |
6992 | + jiffy = schedule_timeout_uninterruptible(jiffy); | |
6993 | +} | |
6994 | + | |
6995 | +void au_dbg_iattr(struct iattr *ia) | |
6996 | +{ | |
c06a8ce3 AM |
6997 | +#define AuBit(name) \ |
6998 | + do { \ | |
6999 | + if (ia->ia_valid & ATTR_ ## name) \ | |
7000 | + dpri(#name "\n"); \ | |
7001 | + } while (0) | |
1facf9fc | 7002 | + AuBit(MODE); |
7003 | + AuBit(UID); | |
7004 | + AuBit(GID); | |
7005 | + AuBit(SIZE); | |
7006 | + AuBit(ATIME); | |
7007 | + AuBit(MTIME); | |
7008 | + AuBit(CTIME); | |
7009 | + AuBit(ATIME_SET); | |
7010 | + AuBit(MTIME_SET); | |
7011 | + AuBit(FORCE); | |
7012 | + AuBit(ATTR_FLAG); | |
7013 | + AuBit(KILL_SUID); | |
7014 | + AuBit(KILL_SGID); | |
7015 | + AuBit(FILE); | |
7016 | + AuBit(KILL_PRIV); | |
7017 | + AuBit(OPEN); | |
7018 | + AuBit(TIMES_SET); | |
7019 | +#undef AuBit | |
7020 | + dpri("ia_file %p\n", ia->ia_file); | |
7021 | +} | |
7022 | + | |
7023 | +/* ---------------------------------------------------------------------- */ | |
7024 | + | |
027c5e7a AM |
7025 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line) |
7026 | +{ | |
7027 | + struct inode *h_inode, *inode = dentry->d_inode; | |
7028 | + struct dentry *h_dentry; | |
7029 | + aufs_bindex_t bindex, bend, bi; | |
7030 | + | |
7031 | + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */) | |
7032 | + return; | |
7033 | + | |
7034 | + bend = au_dbend(dentry); | |
7035 | + bi = au_ibend(inode); | |
7036 | + if (bi < bend) | |
7037 | + bend = bi; | |
7038 | + bindex = au_dbstart(dentry); | |
7039 | + bi = au_ibstart(inode); | |
7040 | + if (bi > bindex) | |
7041 | + bindex = bi; | |
7042 | + | |
7043 | + for (; bindex <= bend; bindex++) { | |
7044 | + h_dentry = au_h_dptr(dentry, bindex); | |
7045 | + if (!h_dentry) | |
7046 | + continue; | |
7047 | + h_inode = au_h_iptr(inode, bindex); | |
7048 | + if (unlikely(h_inode != h_dentry->d_inode)) { | |
392086de | 7049 | + au_debug_on(); |
027c5e7a AM |
7050 | + AuDbg("b%d, %s:%d\n", bindex, func, line); |
7051 | + AuDbgDentry(dentry); | |
7052 | + AuDbgInode(inode); | |
392086de | 7053 | + au_debug_off(); |
027c5e7a AM |
7054 | + BUG(); |
7055 | + } | |
7056 | + } | |
7057 | +} | |
7058 | + | |
1facf9fc | 7059 | +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen) |
7060 | +{ | |
7061 | + struct dentry *parent; | |
7062 | + | |
7063 | + parent = dget_parent(dentry); | |
027c5e7a AM |
7064 | + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode)); |
7065 | + AuDebugOn(IS_ROOT(dentry)); | |
7066 | + AuDebugOn(au_digen_test(parent, sigen)); | |
1facf9fc | 7067 | + dput(parent); |
7068 | +} | |
7069 | + | |
7070 | +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen) | |
7071 | +{ | |
7072 | + struct dentry *parent; | |
027c5e7a | 7073 | + struct inode *inode; |
1facf9fc | 7074 | + |
7075 | + parent = dget_parent(dentry); | |
027c5e7a AM |
7076 | + inode = dentry->d_inode; |
7077 | + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode)); | |
7078 | + AuDebugOn(au_digen_test(parent, sigen)); | |
1facf9fc | 7079 | + dput(parent); |
7080 | +} | |
7081 | + | |
7082 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen) | |
7083 | +{ | |
7084 | + int err, i, j; | |
7085 | + struct au_dcsub_pages dpages; | |
7086 | + struct au_dpage *dpage; | |
7087 | + struct dentry **dentries; | |
7088 | + | |
7089 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
7090 | + AuDebugOn(err); | |
027c5e7a | 7091 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1); |
1facf9fc | 7092 | + AuDebugOn(err); |
7093 | + for (i = dpages.ndpage - 1; !err && i >= 0; i--) { | |
7094 | + dpage = dpages.dpages + i; | |
7095 | + dentries = dpage->dentries; | |
7096 | + for (j = dpage->ndentry - 1; !err && j >= 0; j--) | |
027c5e7a | 7097 | + AuDebugOn(au_digen_test(dentries[j], sigen)); |
1facf9fc | 7098 | + } |
7099 | + au_dpages_free(&dpages); | |
7100 | +} | |
7101 | + | |
1facf9fc | 7102 | +void au_dbg_verify_kthread(void) |
7103 | +{ | |
53392da6 | 7104 | + if (au_wkq_test()) { |
1facf9fc | 7105 | + au_dbg_blocked(); |
1e00d052 AM |
7106 | + /* |
7107 | + * It may be recursive, but udba=notify between two aufs mounts, | |
7108 | + * where a single ro branch is shared, is not a problem. | |
7109 | + */ | |
7110 | + /* WARN_ON(1); */ | |
1facf9fc | 7111 | + } |
7112 | +} | |
7113 | + | |
7114 | +/* ---------------------------------------------------------------------- */ | |
7115 | + | |
7116 | +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused) | |
7117 | +{ | |
7118 | +#ifdef AuForceNoPlink | |
7119 | + au_opt_clr(sbinfo->si_mntflags, PLINK); | |
7120 | +#endif | |
7121 | +#ifdef AuForceNoXino | |
7122 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
7123 | +#endif | |
7124 | +#ifdef AuForceNoRefrof | |
7125 | + au_opt_clr(sbinfo->si_mntflags, REFROF); | |
7126 | +#endif | |
4a4d8108 AM |
7127 | +#ifdef AuForceHnotify |
7128 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY); | |
1facf9fc | 7129 | +#endif |
1308ab2a | 7130 | +#ifdef AuForceRd0 |
7131 | + sbinfo->si_rdblk = 0; | |
7132 | + sbinfo->si_rdhash = 0; | |
7133 | +#endif | |
1facf9fc | 7134 | +} |
7135 | + | |
7136 | +int __init au_debug_init(void) | |
7137 | +{ | |
7138 | + aufs_bindex_t bindex; | |
7139 | + struct au_vdir_destr destr; | |
7140 | + | |
7141 | + bindex = -1; | |
7142 | + AuDebugOn(bindex >= 0); | |
7143 | + | |
7144 | + destr.len = -1; | |
7145 | + AuDebugOn(destr.len < NAME_MAX); | |
7146 | + | |
7147 | +#ifdef CONFIG_4KSTACKS | |
0c3ec466 | 7148 | + pr_warn("CONFIG_4KSTACKS is defined.\n"); |
1facf9fc | 7149 | +#endif |
7150 | + | |
7151 | +#ifdef AuForceNoBrs | |
7152 | + sysaufs_brs = 0; | |
7153 | +#endif | |
7154 | + | |
7155 | + return 0; | |
7156 | +} | |
7f207e10 AM |
7157 | diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h |
7158 | --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
7159 | +++ linux/fs/aufs/debug.h 2015-01-25 13:00:38.631047076 +0100 |
7160 | @@ -0,0 +1,262 @@ | |
1facf9fc | 7161 | +/* |
523b37e3 | 7162 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 7163 | + * |
7164 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7165 | + * it under the terms of the GNU General Public License as published by | |
7166 | + * the Free Software Foundation; either version 2 of the License, or | |
7167 | + * (at your option) any later version. | |
dece6358 AM |
7168 | + * |
7169 | + * This program is distributed in the hope that it will be useful, | |
7170 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7171 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7172 | + * GNU General Public License for more details. | |
7173 | + * | |
7174 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7175 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7176 | + */ |
7177 | + | |
7178 | +/* | |
7179 | + * debug print functions | |
7180 | + */ | |
7181 | + | |
7182 | +#ifndef __AUFS_DEBUG_H__ | |
7183 | +#define __AUFS_DEBUG_H__ | |
7184 | + | |
7185 | +#ifdef __KERNEL__ | |
7186 | + | |
392086de | 7187 | +#include <linux/atomic.h> |
4a4d8108 AM |
7188 | +#include <linux/module.h> |
7189 | +#include <linux/kallsyms.h> | |
1facf9fc | 7190 | +#include <linux/sysrq.h> |
4a4d8108 | 7191 | + |
1facf9fc | 7192 | +#ifdef CONFIG_AUFS_DEBUG |
7193 | +#define AuDebugOn(a) BUG_ON(a) | |
7194 | + | |
7195 | +/* module parameter */ | |
392086de AM |
7196 | +extern atomic_t aufs_debug; |
7197 | +static inline void au_debug_on(void) | |
1facf9fc | 7198 | +{ |
392086de AM |
7199 | + atomic_inc(&aufs_debug); |
7200 | +} | |
7201 | +static inline void au_debug_off(void) | |
7202 | +{ | |
7203 | + atomic_dec_if_positive(&aufs_debug); | |
1facf9fc | 7204 | +} |
7205 | + | |
7206 | +static inline int au_debug_test(void) | |
7207 | +{ | |
392086de | 7208 | + return atomic_read(&aufs_debug) > 0; |
1facf9fc | 7209 | +} |
7210 | +#else | |
7211 | +#define AuDebugOn(a) do {} while (0) | |
392086de AM |
7212 | +AuStubVoid(au_debug_on, void) |
7213 | +AuStubVoid(au_debug_off, void) | |
4a4d8108 | 7214 | +AuStubInt0(au_debug_test, void) |
1facf9fc | 7215 | +#endif /* CONFIG_AUFS_DEBUG */ |
7216 | + | |
392086de AM |
7217 | +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t) |
7218 | + | |
1facf9fc | 7219 | +/* ---------------------------------------------------------------------- */ |
7220 | + | |
7221 | +/* debug print */ | |
7222 | + | |
4a4d8108 | 7223 | +#define AuDbg(fmt, ...) do { \ |
1facf9fc | 7224 | + if (au_debug_test()) \ |
4a4d8108 | 7225 | + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \ |
1facf9fc | 7226 | +} while (0) |
4a4d8108 AM |
7227 | +#define AuLabel(l) AuDbg(#l "\n") |
7228 | +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__) | |
7229 | +#define AuWarn1(fmt, ...) do { \ | |
1facf9fc | 7230 | + static unsigned char _c; \ |
7231 | + if (!_c++) \ | |
0c3ec466 | 7232 | + pr_warn(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7233 | +} while (0) |
7234 | + | |
4a4d8108 | 7235 | +#define AuErr1(fmt, ...) do { \ |
1facf9fc | 7236 | + static unsigned char _c; \ |
7237 | + if (!_c++) \ | |
4a4d8108 | 7238 | + pr_err(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7239 | +} while (0) |
7240 | + | |
4a4d8108 | 7241 | +#define AuIOErr1(fmt, ...) do { \ |
1facf9fc | 7242 | + static unsigned char _c; \ |
7243 | + if (!_c++) \ | |
4a4d8108 | 7244 | + AuIOErr(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7245 | +} while (0) |
7246 | + | |
7247 | +#define AuUnsupportMsg "This operation is not supported." \ | |
7248 | + " Please report this application to aufs-users ML." | |
4a4d8108 AM |
7249 | +#define AuUnsupport(fmt, ...) do { \ |
7250 | + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \ | |
1facf9fc | 7251 | + dump_stack(); \ |
7252 | +} while (0) | |
7253 | + | |
7254 | +#define AuTraceErr(e) do { \ | |
7255 | + if (unlikely((e) < 0)) \ | |
7256 | + AuDbg("err %d\n", (int)(e)); \ | |
7257 | +} while (0) | |
7258 | + | |
7259 | +#define AuTraceErrPtr(p) do { \ | |
7260 | + if (IS_ERR(p)) \ | |
7261 | + AuDbg("err %ld\n", PTR_ERR(p)); \ | |
7262 | +} while (0) | |
7263 | + | |
7264 | +/* dirty macros for debug print, use with "%.*s" and caution */ | |
7265 | +#define AuLNPair(qstr) (qstr)->len, (qstr)->name | |
1facf9fc | 7266 | + |
7267 | +/* ---------------------------------------------------------------------- */ | |
7268 | + | |
7269 | +struct au_sbinfo; | |
7270 | +struct au_finfo; | |
dece6358 | 7271 | +struct dentry; |
1facf9fc | 7272 | +#ifdef CONFIG_AUFS_DEBUG |
c1595e42 | 7273 | +extern struct mutex au_dbg_mtx; |
1facf9fc | 7274 | +extern char *au_plevel; |
7275 | +struct au_nhash; | |
7276 | +void au_dpri_whlist(struct au_nhash *whlist); | |
7277 | +struct au_vdir; | |
7278 | +void au_dpri_vdir(struct au_vdir *vdir); | |
dece6358 | 7279 | +struct inode; |
1facf9fc | 7280 | +void au_dpri_inode(struct inode *inode); |
2cbb1c4b | 7281 | +void au_dpri_dalias(struct inode *inode); |
1facf9fc | 7282 | +void au_dpri_dentry(struct dentry *dentry); |
dece6358 | 7283 | +struct file; |
1facf9fc | 7284 | +void au_dpri_file(struct file *filp); |
dece6358 | 7285 | +struct super_block; |
1facf9fc | 7286 | +void au_dpri_sb(struct super_block *sb); |
7287 | + | |
7288 | +void au_dbg_sleep_jiffy(int jiffy); | |
dece6358 | 7289 | +struct iattr; |
1facf9fc | 7290 | +void au_dbg_iattr(struct iattr *ia); |
7291 | + | |
027c5e7a AM |
7292 | +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__) |
7293 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line); | |
1facf9fc | 7294 | +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen); |
7295 | +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen); | |
7296 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen); | |
1facf9fc | 7297 | +void au_dbg_verify_kthread(void); |
7298 | + | |
7299 | +int __init au_debug_init(void); | |
7300 | +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo); | |
7301 | +#define AuDbgWhlist(w) do { \ | |
c1595e42 | 7302 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7303 | + AuDbg(#w "\n"); \ |
7304 | + au_dpri_whlist(w); \ | |
c1595e42 | 7305 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7306 | +} while (0) |
7307 | + | |
7308 | +#define AuDbgVdir(v) do { \ | |
c1595e42 | 7309 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7310 | + AuDbg(#v "\n"); \ |
7311 | + au_dpri_vdir(v); \ | |
c1595e42 | 7312 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7313 | +} while (0) |
7314 | + | |
7315 | +#define AuDbgInode(i) do { \ | |
c1595e42 | 7316 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7317 | + AuDbg(#i "\n"); \ |
7318 | + au_dpri_inode(i); \ | |
c1595e42 | 7319 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7320 | +} while (0) |
7321 | + | |
2cbb1c4b | 7322 | +#define AuDbgDAlias(i) do { \ |
c1595e42 | 7323 | + mutex_lock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7324 | + AuDbg(#i "\n"); \ |
7325 | + au_dpri_dalias(i); \ | |
c1595e42 | 7326 | + mutex_unlock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7327 | +} while (0) |
7328 | + | |
1facf9fc | 7329 | +#define AuDbgDentry(d) do { \ |
c1595e42 | 7330 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7331 | + AuDbg(#d "\n"); \ |
7332 | + au_dpri_dentry(d); \ | |
c1595e42 | 7333 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7334 | +} while (0) |
7335 | + | |
7336 | +#define AuDbgFile(f) do { \ | |
c1595e42 | 7337 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7338 | + AuDbg(#f "\n"); \ |
7339 | + au_dpri_file(f); \ | |
c1595e42 | 7340 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7341 | +} while (0) |
7342 | + | |
7343 | +#define AuDbgSb(sb) do { \ | |
c1595e42 | 7344 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7345 | + AuDbg(#sb "\n"); \ |
7346 | + au_dpri_sb(sb); \ | |
c1595e42 | 7347 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7348 | +} while (0) |
7349 | + | |
7350 | +#define AuDbgSleep(sec) do { \ | |
7351 | + AuDbg("sleep %d sec\n", sec); \ | |
7352 | + ssleep(sec); \ | |
7353 | +} while (0) | |
7354 | + | |
7355 | +#define AuDbgSleepJiffy(jiffy) do { \ | |
7356 | + AuDbg("sleep %d jiffies\n", jiffy); \ | |
7357 | + au_dbg_sleep_jiffy(jiffy); \ | |
7358 | +} while (0) | |
7359 | + | |
7360 | +#define AuDbgIAttr(ia) do { \ | |
7361 | + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \ | |
7362 | + au_dbg_iattr(ia); \ | |
7363 | +} while (0) | |
4a4d8108 AM |
7364 | + |
7365 | +#define AuDbgSym(addr) do { \ | |
7366 | + char sym[KSYM_SYMBOL_LEN]; \ | |
7367 | + sprint_symbol(sym, (unsigned long)addr); \ | |
7368 | + AuDbg("%s\n", sym); \ | |
7369 | +} while (0) | |
7370 | + | |
7371 | +#define AuInfoSym(addr) do { \ | |
7372 | + char sym[KSYM_SYMBOL_LEN]; \ | |
7373 | + sprint_symbol(sym, (unsigned long)addr); \ | |
7374 | + AuInfo("%s\n", sym); \ | |
7375 | +} while (0) | |
1facf9fc | 7376 | +#else |
027c5e7a | 7377 | +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry) |
4a4d8108 AM |
7378 | +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen) |
7379 | +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry, | |
7380 | + unsigned int sigen) | |
7381 | +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen) | |
7382 | +AuStubVoid(au_dbg_verify_kthread, void) | |
7383 | +AuStubInt0(__init au_debug_init, void) | |
7384 | +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo) | |
1facf9fc | 7385 | + |
1facf9fc | 7386 | +#define AuDbgWhlist(w) do {} while (0) |
7387 | +#define AuDbgVdir(v) do {} while (0) | |
7388 | +#define AuDbgInode(i) do {} while (0) | |
2cbb1c4b | 7389 | +#define AuDbgDAlias(i) do {} while (0) |
1facf9fc | 7390 | +#define AuDbgDentry(d) do {} while (0) |
7391 | +#define AuDbgFile(f) do {} while (0) | |
7392 | +#define AuDbgSb(sb) do {} while (0) | |
7393 | +#define AuDbgSleep(sec) do {} while (0) | |
7394 | +#define AuDbgSleepJiffy(jiffy) do {} while (0) | |
7395 | +#define AuDbgIAttr(ia) do {} while (0) | |
4a4d8108 AM |
7396 | +#define AuDbgSym(addr) do {} while (0) |
7397 | +#define AuInfoSym(addr) do {} while (0) | |
1facf9fc | 7398 | +#endif /* CONFIG_AUFS_DEBUG */ |
7399 | + | |
7400 | +/* ---------------------------------------------------------------------- */ | |
7401 | + | |
7402 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
7403 | +int __init au_sysrq_init(void); | |
7404 | +void au_sysrq_fin(void); | |
7405 | + | |
7406 | +#ifdef CONFIG_HW_CONSOLE | |
7407 | +#define au_dbg_blocked() do { \ | |
7408 | + WARN_ON(1); \ | |
0c5527e5 | 7409 | + handle_sysrq('w'); \ |
1facf9fc | 7410 | +} while (0) |
7411 | +#else | |
4a4d8108 | 7412 | +AuStubVoid(au_dbg_blocked, void) |
1facf9fc | 7413 | +#endif |
7414 | + | |
7415 | +#else | |
4a4d8108 AM |
7416 | +AuStubInt0(__init au_sysrq_init, void) |
7417 | +AuStubVoid(au_sysrq_fin, void) | |
7418 | +AuStubVoid(au_dbg_blocked, void) | |
1facf9fc | 7419 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ |
7420 | + | |
7421 | +#endif /* __KERNEL__ */ | |
7422 | +#endif /* __AUFS_DEBUG_H__ */ | |
7f207e10 AM |
7423 | diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c |
7424 | --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
7425 | +++ linux/fs/aufs/dentry.c 2015-01-25 13:00:38.631047076 +0100 |
7426 | @@ -0,0 +1,1096 @@ | |
1facf9fc | 7427 | +/* |
523b37e3 | 7428 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 7429 | + * |
7430 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7431 | + * it under the terms of the GNU General Public License as published by | |
7432 | + * the Free Software Foundation; either version 2 of the License, or | |
7433 | + * (at your option) any later version. | |
dece6358 AM |
7434 | + * |
7435 | + * This program is distributed in the hope that it will be useful, | |
7436 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7437 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7438 | + * GNU General Public License for more details. | |
7439 | + * | |
7440 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7441 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7442 | + */ |
7443 | + | |
7444 | +/* | |
7445 | + * lookup and dentry operations | |
7446 | + */ | |
7447 | + | |
dece6358 | 7448 | +#include <linux/namei.h> |
1facf9fc | 7449 | +#include "aufs.h" |
7450 | + | |
1facf9fc | 7451 | +#define AuLkup_ALLOW_NEG 1 |
076b876e | 7452 | +#define AuLkup_IGNORE_PERM (1 << 1) |
1facf9fc | 7453 | +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name) |
7f207e10 AM |
7454 | +#define au_fset_lkup(flags, name) \ |
7455 | + do { (flags) |= AuLkup_##name; } while (0) | |
7456 | +#define au_fclr_lkup(flags, name) \ | |
7457 | + do { (flags) &= ~AuLkup_##name; } while (0) | |
1facf9fc | 7458 | + |
7459 | +struct au_do_lookup_args { | |
7460 | + unsigned int flags; | |
7461 | + mode_t type; | |
1facf9fc | 7462 | +}; |
7463 | + | |
7464 | +/* | |
7465 | + * returns positive/negative dentry, NULL or an error. | |
7466 | + * NULL means whiteout-ed or not-found. | |
7467 | + */ | |
7468 | +static struct dentry* | |
7469 | +au_do_lookup(struct dentry *h_parent, struct dentry *dentry, | |
7470 | + aufs_bindex_t bindex, struct qstr *wh_name, | |
7471 | + struct au_do_lookup_args *args) | |
7472 | +{ | |
7473 | + struct dentry *h_dentry; | |
7474 | + struct inode *h_inode, *inode; | |
1facf9fc | 7475 | + struct au_branch *br; |
7476 | + int wh_found, opq; | |
7477 | + unsigned char wh_able; | |
7478 | + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG); | |
076b876e AM |
7479 | + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags, |
7480 | + IGNORE_PERM); | |
1facf9fc | 7481 | + |
1facf9fc | 7482 | + wh_found = 0; |
7483 | + br = au_sbr(dentry->d_sb, bindex); | |
7484 | + wh_able = !!au_br_whable(br->br_perm); | |
7485 | + if (wh_able) | |
076b876e | 7486 | + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0); |
1facf9fc | 7487 | + h_dentry = ERR_PTR(wh_found); |
7488 | + if (!wh_found) | |
7489 | + goto real_lookup; | |
7490 | + if (unlikely(wh_found < 0)) | |
7491 | + goto out; | |
7492 | + | |
7493 | + /* We found a whiteout */ | |
7494 | + /* au_set_dbend(dentry, bindex); */ | |
7495 | + au_set_dbwh(dentry, bindex); | |
7496 | + if (!allow_neg) | |
7497 | + return NULL; /* success */ | |
7498 | + | |
4f0767ce | 7499 | +real_lookup: |
076b876e AM |
7500 | + if (!ignore_perm) |
7501 | + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
7502 | + else | |
7503 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); | |
1facf9fc | 7504 | + if (IS_ERR(h_dentry)) |
7505 | + goto out; | |
7506 | + | |
7507 | + h_inode = h_dentry->d_inode; | |
7508 | + if (!h_inode) { | |
7509 | + if (!allow_neg) | |
7510 | + goto out_neg; | |
7511 | + } else if (wh_found | |
7512 | + || (args->type && args->type != (h_inode->i_mode & S_IFMT))) | |
7513 | + goto out_neg; | |
7514 | + | |
7515 | + if (au_dbend(dentry) <= bindex) | |
7516 | + au_set_dbend(dentry, bindex); | |
7517 | + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry)) | |
7518 | + au_set_dbstart(dentry, bindex); | |
7519 | + au_set_h_dptr(dentry, bindex, h_dentry); | |
7520 | + | |
7521 | + inode = dentry->d_inode; | |
7522 | + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able | |
7523 | + || (inode && !S_ISDIR(inode->i_mode))) | |
7524 | + goto out; /* success */ | |
7525 | + | |
7526 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); | |
076b876e | 7527 | + opq = au_diropq_test(h_dentry); |
1facf9fc | 7528 | + mutex_unlock(&h_inode->i_mutex); |
7529 | + if (opq > 0) | |
7530 | + au_set_dbdiropq(dentry, bindex); | |
7531 | + else if (unlikely(opq < 0)) { | |
7532 | + au_set_h_dptr(dentry, bindex, NULL); | |
7533 | + h_dentry = ERR_PTR(opq); | |
7534 | + } | |
7535 | + goto out; | |
7536 | + | |
4f0767ce | 7537 | +out_neg: |
1facf9fc | 7538 | + dput(h_dentry); |
7539 | + h_dentry = NULL; | |
4f0767ce | 7540 | +out: |
1facf9fc | 7541 | + return h_dentry; |
7542 | +} | |
7543 | + | |
dece6358 AM |
7544 | +static int au_test_shwh(struct super_block *sb, const struct qstr *name) |
7545 | +{ | |
7546 | + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH) | |
7547 | + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))) | |
7548 | + return -EPERM; | |
7549 | + return 0; | |
7550 | +} | |
7551 | + | |
1facf9fc | 7552 | +/* |
7553 | + * returns the number of lower positive dentries, | |
7554 | + * otherwise an error. | |
7555 | + * can be called at unlinking with @type is zero. | |
7556 | + */ | |
537831f9 | 7557 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type) |
1facf9fc | 7558 | +{ |
7559 | + int npositive, err; | |
7560 | + aufs_bindex_t bindex, btail, bdiropq; | |
076b876e | 7561 | + unsigned char isdir, dirperm1; |
1facf9fc | 7562 | + struct qstr whname; |
7563 | + struct au_do_lookup_args args = { | |
b4510431 | 7564 | + .flags = 0, |
537831f9 | 7565 | + .type = type |
1facf9fc | 7566 | + }; |
7567 | + const struct qstr *name = &dentry->d_name; | |
7568 | + struct dentry *parent; | |
7569 | + struct inode *inode; | |
076b876e | 7570 | + struct super_block *sb; |
1facf9fc | 7571 | + |
076b876e AM |
7572 | + sb = dentry->d_sb; |
7573 | + err = au_test_shwh(sb, name); | |
dece6358 | 7574 | + if (unlikely(err)) |
1facf9fc | 7575 | + goto out; |
7576 | + | |
7577 | + err = au_wh_name_alloc(&whname, name); | |
7578 | + if (unlikely(err)) | |
7579 | + goto out; | |
7580 | + | |
7581 | + inode = dentry->d_inode; | |
7582 | + isdir = !!(inode && S_ISDIR(inode->i_mode)); | |
7583 | + if (!type) | |
7584 | + au_fset_lkup(args.flags, ALLOW_NEG); | |
076b876e | 7585 | + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1); |
1facf9fc | 7586 | + |
7587 | + npositive = 0; | |
4a4d8108 | 7588 | + parent = dget_parent(dentry); |
1facf9fc | 7589 | + btail = au_dbtaildir(parent); |
7590 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
7591 | + struct dentry *h_parent, *h_dentry; | |
7592 | + struct inode *h_inode, *h_dir; | |
7593 | + | |
7594 | + h_dentry = au_h_dptr(dentry, bindex); | |
7595 | + if (h_dentry) { | |
7596 | + if (h_dentry->d_inode) | |
7597 | + npositive++; | |
7598 | + if (type != S_IFDIR) | |
7599 | + break; | |
7600 | + continue; | |
7601 | + } | |
7602 | + h_parent = au_h_dptr(parent, bindex); | |
7603 | + if (!h_parent) | |
7604 | + continue; | |
7605 | + h_dir = h_parent->d_inode; | |
7606 | + if (!h_dir || !S_ISDIR(h_dir->i_mode)) | |
7607 | + continue; | |
7608 | + | |
7609 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); | |
7610 | + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname, | |
7611 | + &args); | |
7612 | + mutex_unlock(&h_dir->i_mutex); | |
7613 | + err = PTR_ERR(h_dentry); | |
7614 | + if (IS_ERR(h_dentry)) | |
4a4d8108 | 7615 | + goto out_parent; |
1facf9fc | 7616 | + au_fclr_lkup(args.flags, ALLOW_NEG); |
076b876e AM |
7617 | + if (dirperm1) |
7618 | + au_fset_lkup(args.flags, IGNORE_PERM); | |
1facf9fc | 7619 | + |
7620 | + if (au_dbwh(dentry) >= 0) | |
7621 | + break; | |
7622 | + if (!h_dentry) | |
7623 | + continue; | |
7624 | + h_inode = h_dentry->d_inode; | |
7625 | + if (!h_inode) | |
7626 | + continue; | |
7627 | + npositive++; | |
7628 | + if (!args.type) | |
7629 | + args.type = h_inode->i_mode & S_IFMT; | |
7630 | + if (args.type != S_IFDIR) | |
7631 | + break; | |
7632 | + else if (isdir) { | |
7633 | + /* the type of lower may be different */ | |
7634 | + bdiropq = au_dbdiropq(dentry); | |
7635 | + if (bdiropq >= 0 && bdiropq <= bindex) | |
7636 | + break; | |
7637 | + } | |
7638 | + } | |
7639 | + | |
7640 | + if (npositive) { | |
7641 | + AuLabel(positive); | |
7642 | + au_update_dbstart(dentry); | |
7643 | + } | |
7644 | + err = npositive; | |
076b876e | 7645 | + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE) |
027c5e7a | 7646 | + && au_dbstart(dentry) < 0)) { |
1facf9fc | 7647 | + err = -EIO; |
523b37e3 AM |
7648 | + AuIOErr("both of real entry and whiteout found, %pd, err %d\n", |
7649 | + dentry, err); | |
027c5e7a | 7650 | + } |
1facf9fc | 7651 | + |
4f0767ce | 7652 | +out_parent: |
4a4d8108 | 7653 | + dput(parent); |
1facf9fc | 7654 | + kfree(whname.name); |
4f0767ce | 7655 | +out: |
1facf9fc | 7656 | + return err; |
7657 | +} | |
7658 | + | |
076b876e | 7659 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent) |
1facf9fc | 7660 | +{ |
7661 | + struct dentry *dentry; | |
7662 | + int wkq_err; | |
7663 | + | |
7664 | + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC)) | |
b4510431 | 7665 | + dentry = vfsub_lkup_one(name, parent); |
1facf9fc | 7666 | + else { |
b4510431 AM |
7667 | + struct vfsub_lkup_one_args args = { |
7668 | + .errp = &dentry, | |
7669 | + .name = name, | |
7670 | + .parent = parent | |
1facf9fc | 7671 | + }; |
7672 | + | |
b4510431 | 7673 | + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args); |
1facf9fc | 7674 | + if (unlikely(wkq_err)) |
7675 | + dentry = ERR_PTR(wkq_err); | |
7676 | + } | |
7677 | + | |
7678 | + return dentry; | |
7679 | +} | |
7680 | + | |
7681 | +/* | |
7682 | + * lookup @dentry on @bindex which should be negative. | |
7683 | + */ | |
86dc4139 | 7684 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh) |
1facf9fc | 7685 | +{ |
7686 | + int err; | |
7687 | + struct dentry *parent, *h_parent, *h_dentry; | |
86dc4139 | 7688 | + struct au_branch *br; |
1facf9fc | 7689 | + |
1facf9fc | 7690 | + parent = dget_parent(dentry); |
7691 | + h_parent = au_h_dptr(parent, bindex); | |
86dc4139 AM |
7692 | + br = au_sbr(dentry->d_sb, bindex); |
7693 | + if (wh) | |
7694 | + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
7695 | + else | |
076b876e | 7696 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); |
1facf9fc | 7697 | + err = PTR_ERR(h_dentry); |
7698 | + if (IS_ERR(h_dentry)) | |
7699 | + goto out; | |
7700 | + if (unlikely(h_dentry->d_inode)) { | |
7701 | + err = -EIO; | |
523b37e3 | 7702 | + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex); |
1facf9fc | 7703 | + dput(h_dentry); |
7704 | + goto out; | |
7705 | + } | |
7706 | + | |
4a4d8108 | 7707 | + err = 0; |
1facf9fc | 7708 | + if (bindex < au_dbstart(dentry)) |
7709 | + au_set_dbstart(dentry, bindex); | |
7710 | + if (au_dbend(dentry) < bindex) | |
7711 | + au_set_dbend(dentry, bindex); | |
7712 | + au_set_h_dptr(dentry, bindex, h_dentry); | |
1facf9fc | 7713 | + |
4f0767ce | 7714 | +out: |
1facf9fc | 7715 | + dput(parent); |
7716 | + return err; | |
7717 | +} | |
7718 | + | |
7719 | +/* ---------------------------------------------------------------------- */ | |
7720 | + | |
7721 | +/* subset of struct inode */ | |
7722 | +struct au_iattr { | |
7723 | + unsigned long i_ino; | |
7724 | + /* unsigned int i_nlink; */ | |
0c3ec466 AM |
7725 | + kuid_t i_uid; |
7726 | + kgid_t i_gid; | |
1facf9fc | 7727 | + u64 i_version; |
7728 | +/* | |
7729 | + loff_t i_size; | |
7730 | + blkcnt_t i_blocks; | |
7731 | +*/ | |
7732 | + umode_t i_mode; | |
7733 | +}; | |
7734 | + | |
7735 | +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode) | |
7736 | +{ | |
7737 | + ia->i_ino = h_inode->i_ino; | |
7738 | + /* ia->i_nlink = h_inode->i_nlink; */ | |
7739 | + ia->i_uid = h_inode->i_uid; | |
7740 | + ia->i_gid = h_inode->i_gid; | |
7741 | + ia->i_version = h_inode->i_version; | |
7742 | +/* | |
7743 | + ia->i_size = h_inode->i_size; | |
7744 | + ia->i_blocks = h_inode->i_blocks; | |
7745 | +*/ | |
7746 | + ia->i_mode = (h_inode->i_mode & S_IFMT); | |
7747 | +} | |
7748 | + | |
7749 | +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode) | |
7750 | +{ | |
7751 | + return ia->i_ino != h_inode->i_ino | |
7752 | + /* || ia->i_nlink != h_inode->i_nlink */ | |
0c3ec466 | 7753 | + || !uid_eq(ia->i_uid, h_inode->i_uid) |
2dfbb274 | 7754 | + || !gid_eq(ia->i_gid, h_inode->i_gid) |
1facf9fc | 7755 | + || ia->i_version != h_inode->i_version |
7756 | +/* | |
7757 | + || ia->i_size != h_inode->i_size | |
7758 | + || ia->i_blocks != h_inode->i_blocks | |
7759 | +*/ | |
7760 | + || ia->i_mode != (h_inode->i_mode & S_IFMT); | |
7761 | +} | |
7762 | + | |
7763 | +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent, | |
7764 | + struct au_branch *br) | |
7765 | +{ | |
7766 | + int err; | |
7767 | + struct au_iattr ia; | |
7768 | + struct inode *h_inode; | |
7769 | + struct dentry *h_d; | |
7770 | + struct super_block *h_sb; | |
7771 | + | |
7772 | + err = 0; | |
7773 | + memset(&ia, -1, sizeof(ia)); | |
7774 | + h_sb = h_dentry->d_sb; | |
7775 | + h_inode = h_dentry->d_inode; | |
7776 | + if (h_inode) | |
7777 | + au_iattr_save(&ia, h_inode); | |
7778 | + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb)) | |
7779 | + /* nfs d_revalidate may return 0 for negative dentry */ | |
7780 | + /* fuse d_revalidate always return 0 for negative dentry */ | |
7781 | + goto out; | |
7782 | + | |
7783 | + /* main purpose is namei.c:cached_lookup() and d_revalidate */ | |
b4510431 | 7784 | + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent); |
1facf9fc | 7785 | + err = PTR_ERR(h_d); |
7786 | + if (IS_ERR(h_d)) | |
7787 | + goto out; | |
7788 | + | |
7789 | + err = 0; | |
7790 | + if (unlikely(h_d != h_dentry | |
7791 | + || h_d->d_inode != h_inode | |
7792 | + || (h_inode && au_iattr_test(&ia, h_inode)))) | |
7793 | + err = au_busy_or_stale(); | |
7794 | + dput(h_d); | |
7795 | + | |
4f0767ce | 7796 | +out: |
1facf9fc | 7797 | + AuTraceErr(err); |
7798 | + return err; | |
7799 | +} | |
7800 | + | |
7801 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, | |
7802 | + struct dentry *h_parent, struct au_branch *br) | |
7803 | +{ | |
7804 | + int err; | |
7805 | + | |
7806 | + err = 0; | |
027c5e7a AM |
7807 | + if (udba == AuOpt_UDBA_REVAL |
7808 | + && !au_test_fs_remote(h_dentry->d_sb)) { | |
1facf9fc | 7809 | + IMustLock(h_dir); |
7810 | + err = (h_dentry->d_parent->d_inode != h_dir); | |
027c5e7a | 7811 | + } else if (udba != AuOpt_UDBA_NONE) |
1facf9fc | 7812 | + err = au_h_verify_dentry(h_dentry, h_parent, br); |
7813 | + | |
7814 | + return err; | |
7815 | +} | |
7816 | + | |
7817 | +/* ---------------------------------------------------------------------- */ | |
7818 | + | |
027c5e7a | 7819 | +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 7820 | +{ |
027c5e7a | 7821 | + int err; |
1facf9fc | 7822 | + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq; |
027c5e7a AM |
7823 | + struct au_hdentry tmp, *p, *q; |
7824 | + struct au_dinfo *dinfo; | |
7825 | + struct super_block *sb; | |
1facf9fc | 7826 | + |
027c5e7a | 7827 | + DiMustWriteLock(dentry); |
1308ab2a | 7828 | + |
027c5e7a AM |
7829 | + sb = dentry->d_sb; |
7830 | + dinfo = au_di(dentry); | |
1facf9fc | 7831 | + bend = dinfo->di_bend; |
7832 | + bwh = dinfo->di_bwh; | |
7833 | + bdiropq = dinfo->di_bdiropq; | |
027c5e7a | 7834 | + p = dinfo->di_hdentry + dinfo->di_bstart; |
1facf9fc | 7835 | + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) { |
027c5e7a | 7836 | + if (!p->hd_dentry) |
1facf9fc | 7837 | + continue; |
7838 | + | |
027c5e7a AM |
7839 | + new_bindex = au_br_index(sb, p->hd_id); |
7840 | + if (new_bindex == bindex) | |
1facf9fc | 7841 | + continue; |
1facf9fc | 7842 | + |
1facf9fc | 7843 | + if (dinfo->di_bwh == bindex) |
7844 | + bwh = new_bindex; | |
7845 | + if (dinfo->di_bdiropq == bindex) | |
7846 | + bdiropq = new_bindex; | |
7847 | + if (new_bindex < 0) { | |
7848 | + au_hdput(p); | |
7849 | + p->hd_dentry = NULL; | |
7850 | + continue; | |
7851 | + } | |
7852 | + | |
7853 | + /* swap two lower dentries, and loop again */ | |
7854 | + q = dinfo->di_hdentry + new_bindex; | |
7855 | + tmp = *q; | |
7856 | + *q = *p; | |
7857 | + *p = tmp; | |
7858 | + if (tmp.hd_dentry) { | |
7859 | + bindex--; | |
7860 | + p--; | |
7861 | + } | |
7862 | + } | |
7863 | + | |
1facf9fc | 7864 | + dinfo->di_bwh = -1; |
7865 | + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh)) | |
7866 | + dinfo->di_bwh = bwh; | |
7867 | + | |
7868 | + dinfo->di_bdiropq = -1; | |
7869 | + if (bdiropq >= 0 | |
7870 | + && bdiropq <= au_sbend(sb) | |
7871 | + && au_sbr_whable(sb, bdiropq)) | |
7872 | + dinfo->di_bdiropq = bdiropq; | |
7873 | + | |
027c5e7a AM |
7874 | + err = -EIO; |
7875 | + dinfo->di_bstart = -1; | |
7876 | + dinfo->di_bend = -1; | |
1facf9fc | 7877 | + bend = au_dbend(parent); |
7878 | + p = dinfo->di_hdentry; | |
7879 | + for (bindex = 0; bindex <= bend; bindex++, p++) | |
7880 | + if (p->hd_dentry) { | |
7881 | + dinfo->di_bstart = bindex; | |
7882 | + break; | |
7883 | + } | |
7884 | + | |
027c5e7a AM |
7885 | + if (dinfo->di_bstart >= 0) { |
7886 | + p = dinfo->di_hdentry + bend; | |
7887 | + for (bindex = bend; bindex >= 0; bindex--, p--) | |
7888 | + if (p->hd_dentry) { | |
7889 | + dinfo->di_bend = bindex; | |
7890 | + err = 0; | |
7891 | + break; | |
7892 | + } | |
7893 | + } | |
7894 | + | |
7895 | + return err; | |
1facf9fc | 7896 | +} |
7897 | + | |
027c5e7a | 7898 | +static void au_do_hide(struct dentry *dentry) |
1facf9fc | 7899 | +{ |
027c5e7a | 7900 | + struct inode *inode; |
1facf9fc | 7901 | + |
027c5e7a AM |
7902 | + inode = dentry->d_inode; |
7903 | + if (inode) { | |
7904 | + if (!S_ISDIR(inode->i_mode)) { | |
7905 | + if (inode->i_nlink && !d_unhashed(dentry)) | |
7906 | + drop_nlink(inode); | |
7907 | + } else { | |
7908 | + clear_nlink(inode); | |
7909 | + /* stop next lookup */ | |
7910 | + inode->i_flags |= S_DEAD; | |
7911 | + } | |
7912 | + smp_mb(); /* necessary? */ | |
7913 | + } | |
7914 | + d_drop(dentry); | |
7915 | +} | |
1308ab2a | 7916 | + |
027c5e7a AM |
7917 | +static int au_hide_children(struct dentry *parent) |
7918 | +{ | |
7919 | + int err, i, j, ndentry; | |
7920 | + struct au_dcsub_pages dpages; | |
7921 | + struct au_dpage *dpage; | |
7922 | + struct dentry *dentry; | |
1facf9fc | 7923 | + |
027c5e7a | 7924 | + err = au_dpages_init(&dpages, GFP_NOFS); |
1facf9fc | 7925 | + if (unlikely(err)) |
7926 | + goto out; | |
027c5e7a AM |
7927 | + err = au_dcsub_pages(&dpages, parent, NULL, NULL); |
7928 | + if (unlikely(err)) | |
7929 | + goto out_dpages; | |
1facf9fc | 7930 | + |
027c5e7a AM |
7931 | + /* in reverse order */ |
7932 | + for (i = dpages.ndpage - 1; i >= 0; i--) { | |
7933 | + dpage = dpages.dpages + i; | |
7934 | + ndentry = dpage->ndentry; | |
7935 | + for (j = ndentry - 1; j >= 0; j--) { | |
7936 | + dentry = dpage->dentries[j]; | |
7937 | + if (dentry != parent) | |
7938 | + au_do_hide(dentry); | |
7939 | + } | |
7940 | + } | |
1facf9fc | 7941 | + |
027c5e7a AM |
7942 | +out_dpages: |
7943 | + au_dpages_free(&dpages); | |
4f0767ce | 7944 | +out: |
027c5e7a | 7945 | + return err; |
1facf9fc | 7946 | +} |
7947 | + | |
027c5e7a | 7948 | +static void au_hide(struct dentry *dentry) |
1facf9fc | 7949 | +{ |
027c5e7a AM |
7950 | + int err; |
7951 | + struct inode *inode; | |
1facf9fc | 7952 | + |
027c5e7a AM |
7953 | + AuDbgDentry(dentry); |
7954 | + inode = dentry->d_inode; | |
7955 | + if (inode && S_ISDIR(inode->i_mode)) { | |
7956 | + /* shrink_dcache_parent(dentry); */ | |
7957 | + err = au_hide_children(dentry); | |
7958 | + if (unlikely(err)) | |
523b37e3 AM |
7959 | + AuIOErr("%pd, failed hiding children, ignored %d\n", |
7960 | + dentry, err); | |
027c5e7a AM |
7961 | + } |
7962 | + au_do_hide(dentry); | |
7963 | +} | |
1facf9fc | 7964 | + |
027c5e7a AM |
7965 | +/* |
7966 | + * By adding a dirty branch, a cached dentry may be affected in various ways. | |
7967 | + * | |
7968 | + * a dirty branch is added | |
7969 | + * - on the top of layers | |
7970 | + * - in the middle of layers | |
7971 | + * - to the bottom of layers | |
7972 | + * | |
7973 | + * on the added branch there exists | |
7974 | + * - a whiteout | |
7975 | + * - a diropq | |
7976 | + * - a same named entry | |
7977 | + * + exist | |
7978 | + * * negative --> positive | |
7979 | + * * positive --> positive | |
7980 | + * - type is unchanged | |
7981 | + * - type is changed | |
7982 | + * + doesn't exist | |
7983 | + * * negative --> negative | |
7984 | + * * positive --> negative (rejected by au_br_del() for non-dir case) | |
7985 | + * - none | |
7986 | + */ | |
7987 | +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo, | |
7988 | + struct au_dinfo *tmp) | |
7989 | +{ | |
7990 | + int err; | |
7991 | + aufs_bindex_t bindex, bend; | |
7992 | + struct { | |
7993 | + struct dentry *dentry; | |
7994 | + struct inode *inode; | |
7995 | + mode_t mode; | |
7996 | + } orig_h, tmp_h; | |
7997 | + struct au_hdentry *hd; | |
7998 | + struct inode *inode, *h_inode; | |
7999 | + struct dentry *h_dentry; | |
8000 | + | |
8001 | + err = 0; | |
8002 | + AuDebugOn(dinfo->di_bstart < 0); | |
8003 | + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry; | |
8004 | + orig_h.inode = orig_h.dentry->d_inode; | |
8005 | + orig_h.mode = 0; | |
8006 | + if (orig_h.inode) | |
8007 | + orig_h.mode = orig_h.inode->i_mode & S_IFMT; | |
8008 | + memset(&tmp_h, 0, sizeof(tmp_h)); | |
8009 | + if (tmp->di_bstart >= 0) { | |
8010 | + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry; | |
8011 | + tmp_h.inode = tmp_h.dentry->d_inode; | |
8012 | + if (tmp_h.inode) | |
8013 | + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT; | |
8014 | + } | |
8015 | + | |
8016 | + inode = dentry->d_inode; | |
8017 | + if (!orig_h.inode) { | |
8018 | + AuDbg("nagative originally\n"); | |
8019 | + if (inode) { | |
8020 | + au_hide(dentry); | |
8021 | + goto out; | |
8022 | + } | |
8023 | + AuDebugOn(inode); | |
8024 | + AuDebugOn(dinfo->di_bstart != dinfo->di_bend); | |
8025 | + AuDebugOn(dinfo->di_bdiropq != -1); | |
8026 | + | |
8027 | + if (!tmp_h.inode) { | |
8028 | + AuDbg("negative --> negative\n"); | |
8029 | + /* should have only one negative lower */ | |
8030 | + if (tmp->di_bstart >= 0 | |
8031 | + && tmp->di_bstart < dinfo->di_bstart) { | |
8032 | + AuDebugOn(tmp->di_bstart != tmp->di_bend); | |
8033 | + AuDebugOn(dinfo->di_bstart != dinfo->di_bend); | |
8034 | + au_set_h_dptr(dentry, dinfo->di_bstart, NULL); | |
8035 | + au_di_cp(dinfo, tmp); | |
8036 | + hd = tmp->di_hdentry + tmp->di_bstart; | |
8037 | + au_set_h_dptr(dentry, tmp->di_bstart, | |
8038 | + dget(hd->hd_dentry)); | |
8039 | + } | |
8040 | + au_dbg_verify_dinode(dentry); | |
8041 | + } else { | |
8042 | + AuDbg("negative --> positive\n"); | |
8043 | + /* | |
8044 | + * similar to the behaviour of creating with bypassing | |
8045 | + * aufs. | |
8046 | + * unhash it in order to force an error in the | |
8047 | + * succeeding create operation. | |
8048 | + * we should not set S_DEAD here. | |
8049 | + */ | |
8050 | + d_drop(dentry); | |
8051 | + /* au_di_swap(tmp, dinfo); */ | |
8052 | + au_dbg_verify_dinode(dentry); | |
8053 | + } | |
8054 | + } else { | |
8055 | + AuDbg("positive originally\n"); | |
8056 | + /* inode may be NULL */ | |
8057 | + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode); | |
8058 | + if (!tmp_h.inode) { | |
8059 | + AuDbg("positive --> negative\n"); | |
8060 | + /* or bypassing aufs */ | |
8061 | + au_hide(dentry); | |
8062 | + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart) | |
8063 | + dinfo->di_bwh = tmp->di_bwh; | |
8064 | + if (inode) | |
8065 | + err = au_refresh_hinode_self(inode); | |
8066 | + au_dbg_verify_dinode(dentry); | |
8067 | + } else if (orig_h.mode == tmp_h.mode) { | |
8068 | + AuDbg("positive --> positive, same type\n"); | |
8069 | + if (!S_ISDIR(orig_h.mode) | |
8070 | + && dinfo->di_bstart > tmp->di_bstart) { | |
8071 | + /* | |
8072 | + * similar to the behaviour of removing and | |
8073 | + * creating. | |
8074 | + */ | |
8075 | + au_hide(dentry); | |
8076 | + if (inode) | |
8077 | + err = au_refresh_hinode_self(inode); | |
8078 | + au_dbg_verify_dinode(dentry); | |
8079 | + } else { | |
8080 | + /* fill empty slots */ | |
8081 | + if (dinfo->di_bstart > tmp->di_bstart) | |
8082 | + dinfo->di_bstart = tmp->di_bstart; | |
8083 | + if (dinfo->di_bend < tmp->di_bend) | |
8084 | + dinfo->di_bend = tmp->di_bend; | |
8085 | + dinfo->di_bwh = tmp->di_bwh; | |
8086 | + dinfo->di_bdiropq = tmp->di_bdiropq; | |
8087 | + hd = tmp->di_hdentry; | |
8088 | + bend = dinfo->di_bend; | |
8089 | + for (bindex = tmp->di_bstart; bindex <= bend; | |
8090 | + bindex++) { | |
8091 | + if (au_h_dptr(dentry, bindex)) | |
8092 | + continue; | |
8093 | + h_dentry = hd[bindex].hd_dentry; | |
8094 | + if (!h_dentry) | |
8095 | + continue; | |
8096 | + h_inode = h_dentry->d_inode; | |
8097 | + AuDebugOn(!h_inode); | |
8098 | + AuDebugOn(orig_h.mode | |
8099 | + != (h_inode->i_mode | |
8100 | + & S_IFMT)); | |
8101 | + au_set_h_dptr(dentry, bindex, | |
8102 | + dget(h_dentry)); | |
8103 | + } | |
8104 | + err = au_refresh_hinode(inode, dentry); | |
8105 | + au_dbg_verify_dinode(dentry); | |
8106 | + } | |
8107 | + } else { | |
8108 | + AuDbg("positive --> positive, different type\n"); | |
8109 | + /* similar to the behaviour of removing and creating */ | |
8110 | + au_hide(dentry); | |
8111 | + if (inode) | |
8112 | + err = au_refresh_hinode_self(inode); | |
8113 | + au_dbg_verify_dinode(dentry); | |
8114 | + } | |
8115 | + } | |
8116 | + | |
8117 | +out: | |
8118 | + return err; | |
8119 | +} | |
8120 | + | |
8121 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent) | |
8122 | +{ | |
8123 | + int err, ebrange; | |
8124 | + unsigned int sigen; | |
8125 | + struct au_dinfo *dinfo, *tmp; | |
8126 | + struct super_block *sb; | |
8127 | + struct inode *inode; | |
8128 | + | |
8129 | + DiMustWriteLock(dentry); | |
8130 | + AuDebugOn(IS_ROOT(dentry)); | |
8131 | + AuDebugOn(!parent->d_inode); | |
8132 | + | |
8133 | + sb = dentry->d_sb; | |
8134 | + inode = dentry->d_inode; | |
8135 | + sigen = au_sigen(sb); | |
8136 | + err = au_digen_test(parent, sigen); | |
8137 | + if (unlikely(err)) | |
8138 | + goto out; | |
8139 | + | |
8140 | + dinfo = au_di(dentry); | |
8141 | + err = au_di_realloc(dinfo, au_sbend(sb) + 1); | |
8142 | + if (unlikely(err)) | |
8143 | + goto out; | |
8144 | + ebrange = au_dbrange_test(dentry); | |
8145 | + if (!ebrange) | |
8146 | + ebrange = au_do_refresh_hdentry(dentry, parent); | |
8147 | + | |
38d290e6 | 8148 | + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) { |
027c5e7a AM |
8149 | + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0); |
8150 | + if (inode) | |
8151 | + err = au_refresh_hinode_self(inode); | |
8152 | + au_dbg_verify_dinode(dentry); | |
8153 | + if (!err) | |
8154 | + goto out_dgen; /* success */ | |
8155 | + goto out; | |
8156 | + } | |
8157 | + | |
8158 | + /* temporary dinfo */ | |
8159 | + AuDbgDentry(dentry); | |
8160 | + err = -ENOMEM; | |
8161 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
8162 | + if (unlikely(!tmp)) | |
8163 | + goto out; | |
8164 | + au_di_swap(tmp, dinfo); | |
8165 | + /* returns the number of positive dentries */ | |
8166 | + /* | |
8167 | + * if current working dir is removed, it returns an error. | |
8168 | + * but the dentry is legal. | |
8169 | + */ | |
537831f9 | 8170 | + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0); |
027c5e7a AM |
8171 | + AuDbgDentry(dentry); |
8172 | + au_di_swap(tmp, dinfo); | |
8173 | + if (err == -ENOENT) | |
8174 | + err = 0; | |
8175 | + if (err >= 0) { | |
8176 | + /* compare/refresh by dinfo */ | |
8177 | + AuDbgDentry(dentry); | |
8178 | + err = au_refresh_by_dinfo(dentry, dinfo, tmp); | |
8179 | + au_dbg_verify_dinode(dentry); | |
8180 | + AuTraceErr(err); | |
8181 | + } | |
8182 | + au_rw_write_unlock(&tmp->di_rwsem); | |
8183 | + au_di_free(tmp); | |
8184 | + if (unlikely(err)) | |
8185 | + goto out; | |
8186 | + | |
8187 | +out_dgen: | |
8188 | + au_update_digen(dentry); | |
8189 | +out: | |
8190 | + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) { | |
523b37e3 | 8191 | + AuIOErr("failed refreshing %pd, %d\n", dentry, err); |
027c5e7a AM |
8192 | + AuDbgDentry(dentry); |
8193 | + } | |
8194 | + AuTraceErr(err); | |
8195 | + return err; | |
8196 | +} | |
8197 | + | |
b4510431 AM |
8198 | +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags, |
8199 | + struct dentry *dentry, aufs_bindex_t bindex) | |
027c5e7a AM |
8200 | +{ |
8201 | + int err, valid; | |
027c5e7a AM |
8202 | + |
8203 | + err = 0; | |
8204 | + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE)) | |
8205 | + goto out; | |
027c5e7a AM |
8206 | + |
8207 | + AuDbg("b%d\n", bindex); | |
b4510431 AM |
8208 | + /* |
8209 | + * gave up supporting LOOKUP_CREATE/OPEN for lower fs, | |
8210 | + * due to whiteout and branch permission. | |
8211 | + */ | |
8212 | + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE | |
8213 | + | LOOKUP_FOLLOW | LOOKUP_EXCL); | |
8214 | + /* it may return tri-state */ | |
8215 | + valid = h_dentry->d_op->d_revalidate(h_dentry, flags); | |
1facf9fc | 8216 | + |
8217 | + if (unlikely(valid < 0)) | |
8218 | + err = valid; | |
8219 | + else if (!valid) | |
8220 | + err = -EINVAL; | |
8221 | + | |
4f0767ce | 8222 | +out: |
1facf9fc | 8223 | + AuTraceErr(err); |
8224 | + return err; | |
8225 | +} | |
8226 | + | |
8227 | +/* todo: remove this */ | |
8228 | +static int h_d_revalidate(struct dentry *dentry, struct inode *inode, | |
b4510431 | 8229 | + unsigned int flags, int do_udba) |
1facf9fc | 8230 | +{ |
8231 | + int err; | |
8232 | + umode_t mode, h_mode; | |
8233 | + aufs_bindex_t bindex, btail, bstart, ibs, ibe; | |
38d290e6 | 8234 | + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile; |
4a4d8108 | 8235 | + struct inode *h_inode, *h_cached_inode; |
1facf9fc | 8236 | + struct dentry *h_dentry; |
8237 | + struct qstr *name, *h_name; | |
8238 | + | |
8239 | + err = 0; | |
8240 | + plus = 0; | |
8241 | + mode = 0; | |
1facf9fc | 8242 | + ibs = -1; |
8243 | + ibe = -1; | |
8244 | + unhashed = !!d_unhashed(dentry); | |
8245 | + is_root = !!IS_ROOT(dentry); | |
8246 | + name = &dentry->d_name; | |
38d290e6 | 8247 | + tmpfile = au_di(dentry)->di_tmpfile; |
1facf9fc | 8248 | + |
8249 | + /* | |
7f207e10 AM |
8250 | + * Theoretically, REVAL test should be unnecessary in case of |
8251 | + * {FS,I}NOTIFY. | |
8252 | + * But {fs,i}notify doesn't fire some necessary events, | |
1facf9fc | 8253 | + * IN_ATTRIB for atime/nlink/pageio |
1facf9fc | 8254 | + * Let's do REVAL test too. |
8255 | + */ | |
8256 | + if (do_udba && inode) { | |
8257 | + mode = (inode->i_mode & S_IFMT); | |
8258 | + plus = (inode->i_nlink > 0); | |
1facf9fc | 8259 | + ibs = au_ibstart(inode); |
8260 | + ibe = au_ibend(inode); | |
8261 | + } | |
8262 | + | |
8263 | + bstart = au_dbstart(dentry); | |
8264 | + btail = bstart; | |
8265 | + if (inode && S_ISDIR(inode->i_mode)) | |
8266 | + btail = au_dbtaildir(dentry); | |
8267 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
8268 | + h_dentry = au_h_dptr(dentry, bindex); | |
8269 | + if (!h_dentry) | |
8270 | + continue; | |
8271 | + | |
523b37e3 AM |
8272 | + AuDbg("b%d, %pd\n", bindex, h_dentry); |
8273 | + h_nfs = !!au_test_nfs(h_dentry->d_sb); | |
027c5e7a | 8274 | + spin_lock(&h_dentry->d_lock); |
1facf9fc | 8275 | + h_name = &h_dentry->d_name; |
8276 | + if (unlikely(do_udba | |
8277 | + && !is_root | |
523b37e3 AM |
8278 | + && ((!h_nfs |
8279 | + && (unhashed != !!d_unhashed(h_dentry) | |
38d290e6 JR |
8280 | + || (!tmpfile |
8281 | + && !au_qstreq(name, h_name)) | |
8282 | + )) | |
523b37e3 AM |
8283 | + || (h_nfs |
8284 | + && !(flags & LOOKUP_OPEN) | |
8285 | + && (h_dentry->d_flags | |
8286 | + & DCACHE_NFSFS_RENAMED))) | |
1facf9fc | 8287 | + )) { |
38d290e6 JR |
8288 | + int h_unhashed; |
8289 | + | |
8290 | + h_unhashed = d_unhashed(h_dentry); | |
027c5e7a | 8291 | + spin_unlock(&h_dentry->d_lock); |
38d290e6 JR |
8292 | + AuDbg("unhash 0x%x 0x%x, %pd %pd\n", |
8293 | + unhashed, h_unhashed, dentry, h_dentry); | |
1facf9fc | 8294 | + goto err; |
8295 | + } | |
027c5e7a | 8296 | + spin_unlock(&h_dentry->d_lock); |
1facf9fc | 8297 | + |
b4510431 | 8298 | + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex); |
1facf9fc | 8299 | + if (unlikely(err)) |
8300 | + /* do not goto err, to keep the errno */ | |
8301 | + break; | |
8302 | + | |
8303 | + /* todo: plink too? */ | |
8304 | + if (!do_udba) | |
8305 | + continue; | |
8306 | + | |
8307 | + /* UDBA tests */ | |
8308 | + h_inode = h_dentry->d_inode; | |
8309 | + if (unlikely(!!inode != !!h_inode)) | |
8310 | + goto err; | |
8311 | + | |
8312 | + h_plus = plus; | |
8313 | + h_mode = mode; | |
8314 | + h_cached_inode = h_inode; | |
8315 | + if (h_inode) { | |
8316 | + h_mode = (h_inode->i_mode & S_IFMT); | |
8317 | + h_plus = (h_inode->i_nlink > 0); | |
8318 | + } | |
8319 | + if (inode && ibs <= bindex && bindex <= ibe) | |
8320 | + h_cached_inode = au_h_iptr(inode, bindex); | |
8321 | + | |
523b37e3 | 8322 | + if (!h_nfs) { |
38d290e6 | 8323 | + if (unlikely(plus != h_plus && !tmpfile)) |
523b37e3 AM |
8324 | + goto err; |
8325 | + } else { | |
8326 | + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED) | |
8327 | + && !is_root | |
8328 | + && !IS_ROOT(h_dentry) | |
8329 | + && unhashed != d_unhashed(h_dentry))) | |
8330 | + goto err; | |
8331 | + } | |
8332 | + if (unlikely(mode != h_mode | |
1facf9fc | 8333 | + || h_cached_inode != h_inode)) |
8334 | + goto err; | |
8335 | + continue; | |
8336 | + | |
f6b6e03d | 8337 | +err: |
1facf9fc | 8338 | + err = -EINVAL; |
8339 | + break; | |
8340 | + } | |
8341 | + | |
523b37e3 | 8342 | + AuTraceErr(err); |
1facf9fc | 8343 | + return err; |
8344 | +} | |
8345 | + | |
027c5e7a | 8346 | +/* todo: consolidate with do_refresh() and au_reval_for_attr() */ |
1facf9fc | 8347 | +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen) |
8348 | +{ | |
8349 | + int err; | |
8350 | + struct dentry *parent; | |
1facf9fc | 8351 | + |
027c5e7a | 8352 | + if (!au_digen_test(dentry, sigen)) |
1facf9fc | 8353 | + return 0; |
8354 | + | |
8355 | + parent = dget_parent(dentry); | |
8356 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 8357 | + AuDebugOn(au_digen_test(parent, sigen)); |
1facf9fc | 8358 | + au_dbg_verify_gen(parent, sigen); |
027c5e7a | 8359 | + err = au_refresh_dentry(dentry, parent); |
1facf9fc | 8360 | + di_read_unlock(parent, AuLock_IR); |
8361 | + dput(parent); | |
027c5e7a | 8362 | + AuTraceErr(err); |
1facf9fc | 8363 | + return err; |
8364 | +} | |
8365 | + | |
8366 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen) | |
8367 | +{ | |
8368 | + int err; | |
8369 | + struct dentry *d, *parent; | |
8370 | + struct inode *inode; | |
8371 | + | |
027c5e7a | 8372 | + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR)) |
1facf9fc | 8373 | + return simple_reval_dpath(dentry, sigen); |
8374 | + | |
8375 | + /* slow loop, keep it simple and stupid */ | |
8376 | + /* cf: au_cpup_dirs() */ | |
8377 | + err = 0; | |
8378 | + parent = NULL; | |
027c5e7a | 8379 | + while (au_digen_test(dentry, sigen)) { |
1facf9fc | 8380 | + d = dentry; |
8381 | + while (1) { | |
8382 | + dput(parent); | |
8383 | + parent = dget_parent(d); | |
027c5e7a | 8384 | + if (!au_digen_test(parent, sigen)) |
1facf9fc | 8385 | + break; |
8386 | + d = parent; | |
8387 | + } | |
8388 | + | |
8389 | + inode = d->d_inode; | |
8390 | + if (d != dentry) | |
027c5e7a | 8391 | + di_write_lock_child2(d); |
1facf9fc | 8392 | + |
8393 | + /* someone might update our dentry while we were sleeping */ | |
027c5e7a AM |
8394 | + if (au_digen_test(d, sigen)) { |
8395 | + /* | |
8396 | + * todo: consolidate with simple_reval_dpath(), | |
8397 | + * do_refresh() and au_reval_for_attr(). | |
8398 | + */ | |
1facf9fc | 8399 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a | 8400 | + err = au_refresh_dentry(d, parent); |
1facf9fc | 8401 | + di_read_unlock(parent, AuLock_IR); |
8402 | + } | |
8403 | + | |
8404 | + if (d != dentry) | |
8405 | + di_write_unlock(d); | |
8406 | + dput(parent); | |
8407 | + if (unlikely(err)) | |
8408 | + break; | |
8409 | + } | |
8410 | + | |
8411 | + return err; | |
8412 | +} | |
8413 | + | |
8414 | +/* | |
8415 | + * if valid returns 1, otherwise 0. | |
8416 | + */ | |
b4510431 | 8417 | +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags) |
1facf9fc | 8418 | +{ |
8419 | + int valid, err; | |
8420 | + unsigned int sigen; | |
8421 | + unsigned char do_udba; | |
8422 | + struct super_block *sb; | |
8423 | + struct inode *inode; | |
8424 | + | |
027c5e7a | 8425 | + /* todo: support rcu-walk? */ |
b4510431 | 8426 | + if (flags & LOOKUP_RCU) |
027c5e7a AM |
8427 | + return -ECHILD; |
8428 | + | |
8429 | + valid = 0; | |
8430 | + if (unlikely(!au_di(dentry))) | |
8431 | + goto out; | |
8432 | + | |
e49829fe | 8433 | + valid = 1; |
1facf9fc | 8434 | + sb = dentry->d_sb; |
e49829fe JR |
8435 | + /* |
8436 | + * todo: very ugly | |
8437 | + * i_mutex of parent dir may be held, | |
8438 | + * but we should not return 'invalid' due to busy. | |
8439 | + */ | |
8440 | + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM); | |
8441 | + if (unlikely(err)) { | |
8442 | + valid = err; | |
027c5e7a | 8443 | + AuTraceErr(err); |
e49829fe JR |
8444 | + goto out; |
8445 | + } | |
c1595e42 JR |
8446 | + inode = dentry->d_inode; |
8447 | + if (unlikely(inode && is_bad_inode(inode))) { | |
8448 | + err = -EINVAL; | |
8449 | + AuTraceErr(err); | |
8450 | + goto out_dgrade; | |
8451 | + } | |
027c5e7a AM |
8452 | + if (unlikely(au_dbrange_test(dentry))) { |
8453 | + err = -EINVAL; | |
8454 | + AuTraceErr(err); | |
8455 | + goto out_dgrade; | |
1facf9fc | 8456 | + } |
027c5e7a AM |
8457 | + |
8458 | + sigen = au_sigen(sb); | |
8459 | + if (au_digen_test(dentry, sigen)) { | |
1facf9fc | 8460 | + AuDebugOn(IS_ROOT(dentry)); |
027c5e7a AM |
8461 | + err = au_reval_dpath(dentry, sigen); |
8462 | + if (unlikely(err)) { | |
8463 | + AuTraceErr(err); | |
1facf9fc | 8464 | + goto out_dgrade; |
027c5e7a | 8465 | + } |
1facf9fc | 8466 | + } |
8467 | + di_downgrade_lock(dentry, AuLock_IR); | |
8468 | + | |
1facf9fc | 8469 | + err = -EINVAL; |
c1595e42 | 8470 | + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY)) |
523b37e3 | 8471 | + && inode |
38d290e6 | 8472 | + && !(inode->i_state && I_LINKABLE) |
523b37e3 | 8473 | + && (IS_DEADDIR(inode) || !inode->i_nlink)) |
027c5e7a AM |
8474 | + goto out_inval; |
8475 | + | |
1facf9fc | 8476 | + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE); |
8477 | + if (do_udba && inode) { | |
8478 | + aufs_bindex_t bstart = au_ibstart(inode); | |
027c5e7a | 8479 | + struct inode *h_inode; |
1facf9fc | 8480 | + |
027c5e7a AM |
8481 | + if (bstart >= 0) { |
8482 | + h_inode = au_h_iptr(inode, bstart); | |
8483 | + if (h_inode && au_test_higen(inode, h_inode)) | |
8484 | + goto out_inval; | |
8485 | + } | |
1facf9fc | 8486 | + } |
8487 | + | |
b4510431 | 8488 | + err = h_d_revalidate(dentry, inode, flags, do_udba); |
027c5e7a | 8489 | + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) { |
1facf9fc | 8490 | + err = -EIO; |
523b37e3 AM |
8491 | + AuDbg("both of real entry and whiteout found, %p, err %d\n", |
8492 | + dentry, err); | |
027c5e7a | 8493 | + } |
e49829fe | 8494 | + goto out_inval; |
1facf9fc | 8495 | + |
4f0767ce | 8496 | +out_dgrade: |
1facf9fc | 8497 | + di_downgrade_lock(dentry, AuLock_IR); |
e49829fe | 8498 | +out_inval: |
1facf9fc | 8499 | + aufs_read_unlock(dentry, AuLock_IR); |
8500 | + AuTraceErr(err); | |
8501 | + valid = !err; | |
e49829fe | 8502 | +out: |
027c5e7a | 8503 | + if (!valid) { |
523b37e3 | 8504 | + AuDbg("%pd invalid, %d\n", dentry, valid); |
027c5e7a AM |
8505 | + d_drop(dentry); |
8506 | + } | |
1facf9fc | 8507 | + return valid; |
8508 | +} | |
8509 | + | |
8510 | +static void aufs_d_release(struct dentry *dentry) | |
8511 | +{ | |
027c5e7a | 8512 | + if (au_di(dentry)) { |
4a4d8108 AM |
8513 | + au_di_fin(dentry); |
8514 | + au_hn_di_reinit(dentry); | |
1facf9fc | 8515 | + } |
1facf9fc | 8516 | +} |
8517 | + | |
4a4d8108 | 8518 | +const struct dentry_operations aufs_dop = { |
c06a8ce3 AM |
8519 | + .d_revalidate = aufs_d_revalidate, |
8520 | + .d_weak_revalidate = aufs_d_revalidate, | |
8521 | + .d_release = aufs_d_release | |
1facf9fc | 8522 | +}; |
7f207e10 AM |
8523 | diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h |
8524 | --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 8525 | +++ linux/fs/aufs/dentry.h 2015-01-25 13:00:38.631047076 +0100 |
076b876e | 8526 | @@ -0,0 +1,233 @@ |
1facf9fc | 8527 | +/* |
523b37e3 | 8528 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 8529 | + * |
8530 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8531 | + * it under the terms of the GNU General Public License as published by | |
8532 | + * the Free Software Foundation; either version 2 of the License, or | |
8533 | + * (at your option) any later version. | |
dece6358 AM |
8534 | + * |
8535 | + * This program is distributed in the hope that it will be useful, | |
8536 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8537 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8538 | + * GNU General Public License for more details. | |
8539 | + * | |
8540 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8541 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8542 | + */ |
8543 | + | |
8544 | +/* | |
8545 | + * lookup and dentry operations | |
8546 | + */ | |
8547 | + | |
8548 | +#ifndef __AUFS_DENTRY_H__ | |
8549 | +#define __AUFS_DENTRY_H__ | |
8550 | + | |
8551 | +#ifdef __KERNEL__ | |
8552 | + | |
dece6358 | 8553 | +#include <linux/dcache.h> |
1facf9fc | 8554 | +#include "rwsem.h" |
8555 | + | |
1facf9fc | 8556 | +struct au_hdentry { |
8557 | + struct dentry *hd_dentry; | |
027c5e7a | 8558 | + aufs_bindex_t hd_id; |
1facf9fc | 8559 | +}; |
8560 | + | |
8561 | +struct au_dinfo { | |
8562 | + atomic_t di_generation; | |
8563 | + | |
dece6358 | 8564 | + struct au_rwsem di_rwsem; |
1facf9fc | 8565 | + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq; |
38d290e6 | 8566 | + unsigned char di_tmpfile; /* to allow the different name */ |
1facf9fc | 8567 | + struct au_hdentry *di_hdentry; |
4a4d8108 | 8568 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 8569 | + |
8570 | +/* ---------------------------------------------------------------------- */ | |
8571 | + | |
8572 | +/* dentry.c */ | |
4a4d8108 | 8573 | +extern const struct dentry_operations aufs_dop; |
1facf9fc | 8574 | +struct au_branch; |
076b876e | 8575 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent); |
1facf9fc | 8576 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, |
8577 | + struct dentry *h_parent, struct au_branch *br); | |
8578 | + | |
537831f9 | 8579 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type); |
86dc4139 | 8580 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh); |
027c5e7a | 8581 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent); |
1facf9fc | 8582 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen); |
8583 | + | |
8584 | +/* dinfo.c */ | |
4a4d8108 | 8585 | +void au_di_init_once(void *_di); |
027c5e7a AM |
8586 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc); |
8587 | +void au_di_free(struct au_dinfo *dinfo); | |
8588 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b); | |
8589 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src); | |
4a4d8108 AM |
8590 | +int au_di_init(struct dentry *dentry); |
8591 | +void au_di_fin(struct dentry *dentry); | |
1facf9fc | 8592 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr); |
8593 | + | |
8594 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc); | |
8595 | +void di_read_unlock(struct dentry *d, int flags); | |
8596 | +void di_downgrade_lock(struct dentry *d, int flags); | |
8597 | +void di_write_lock(struct dentry *d, unsigned int lsc); | |
8598 | +void di_write_unlock(struct dentry *d); | |
8599 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir); | |
8600 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir); | |
8601 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2); | |
8602 | + | |
8603 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex); | |
2cbb1c4b | 8604 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex); |
1facf9fc | 8605 | +aufs_bindex_t au_dbtail(struct dentry *dentry); |
8606 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry); | |
8607 | + | |
8608 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
8609 | + struct dentry *h_dentry); | |
027c5e7a AM |
8610 | +int au_digen_test(struct dentry *dentry, unsigned int sigen); |
8611 | +int au_dbrange_test(struct dentry *dentry); | |
1facf9fc | 8612 | +void au_update_digen(struct dentry *dentry); |
8613 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero); | |
8614 | +void au_update_dbstart(struct dentry *dentry); | |
8615 | +void au_update_dbend(struct dentry *dentry); | |
8616 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry); | |
8617 | + | |
8618 | +/* ---------------------------------------------------------------------- */ | |
8619 | + | |
8620 | +static inline struct au_dinfo *au_di(struct dentry *dentry) | |
8621 | +{ | |
8622 | + return dentry->d_fsdata; | |
8623 | +} | |
8624 | + | |
8625 | +/* ---------------------------------------------------------------------- */ | |
8626 | + | |
8627 | +/* lock subclass for dinfo */ | |
8628 | +enum { | |
8629 | + AuLsc_DI_CHILD, /* child first */ | |
4a4d8108 | 8630 | + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */ |
1facf9fc | 8631 | + AuLsc_DI_CHILD3, /* copyup dirs */ |
8632 | + AuLsc_DI_PARENT, | |
8633 | + AuLsc_DI_PARENT2, | |
027c5e7a AM |
8634 | + AuLsc_DI_PARENT3, |
8635 | + AuLsc_DI_TMP /* temp for replacing dinfo */ | |
1facf9fc | 8636 | +}; |
8637 | + | |
8638 | +/* | |
8639 | + * di_read_lock_child, di_write_lock_child, | |
8640 | + * di_read_lock_child2, di_write_lock_child2, | |
8641 | + * di_read_lock_child3, di_write_lock_child3, | |
8642 | + * di_read_lock_parent, di_write_lock_parent, | |
8643 | + * di_read_lock_parent2, di_write_lock_parent2, | |
8644 | + * di_read_lock_parent3, di_write_lock_parent3, | |
8645 | + */ | |
8646 | +#define AuReadLockFunc(name, lsc) \ | |
8647 | +static inline void di_read_lock_##name(struct dentry *d, int flags) \ | |
8648 | +{ di_read_lock(d, flags, AuLsc_DI_##lsc); } | |
8649 | + | |
8650 | +#define AuWriteLockFunc(name, lsc) \ | |
8651 | +static inline void di_write_lock_##name(struct dentry *d) \ | |
8652 | +{ di_write_lock(d, AuLsc_DI_##lsc); } | |
8653 | + | |
8654 | +#define AuRWLockFuncs(name, lsc) \ | |
8655 | + AuReadLockFunc(name, lsc) \ | |
8656 | + AuWriteLockFunc(name, lsc) | |
8657 | + | |
8658 | +AuRWLockFuncs(child, CHILD); | |
8659 | +AuRWLockFuncs(child2, CHILD2); | |
8660 | +AuRWLockFuncs(child3, CHILD3); | |
8661 | +AuRWLockFuncs(parent, PARENT); | |
8662 | +AuRWLockFuncs(parent2, PARENT2); | |
8663 | +AuRWLockFuncs(parent3, PARENT3); | |
8664 | + | |
8665 | +#undef AuReadLockFunc | |
8666 | +#undef AuWriteLockFunc | |
8667 | +#undef AuRWLockFuncs | |
8668 | + | |
8669 | +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem) | |
dece6358 AM |
8670 | +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem) |
8671 | +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem) | |
1facf9fc | 8672 | + |
8673 | +/* ---------------------------------------------------------------------- */ | |
8674 | + | |
8675 | +/* todo: memory barrier? */ | |
8676 | +static inline unsigned int au_digen(struct dentry *d) | |
8677 | +{ | |
8678 | + return atomic_read(&au_di(d)->di_generation); | |
8679 | +} | |
8680 | + | |
8681 | +static inline void au_h_dentry_init(struct au_hdentry *hdentry) | |
8682 | +{ | |
8683 | + hdentry->hd_dentry = NULL; | |
8684 | +} | |
8685 | + | |
8686 | +static inline void au_hdput(struct au_hdentry *hd) | |
8687 | +{ | |
4a4d8108 AM |
8688 | + if (hd) |
8689 | + dput(hd->hd_dentry); | |
1facf9fc | 8690 | +} |
8691 | + | |
8692 | +static inline aufs_bindex_t au_dbstart(struct dentry *dentry) | |
8693 | +{ | |
1308ab2a | 8694 | + DiMustAnyLock(dentry); |
1facf9fc | 8695 | + return au_di(dentry)->di_bstart; |
8696 | +} | |
8697 | + | |
8698 | +static inline aufs_bindex_t au_dbend(struct dentry *dentry) | |
8699 | +{ | |
1308ab2a | 8700 | + DiMustAnyLock(dentry); |
1facf9fc | 8701 | + return au_di(dentry)->di_bend; |
8702 | +} | |
8703 | + | |
8704 | +static inline aufs_bindex_t au_dbwh(struct dentry *dentry) | |
8705 | +{ | |
1308ab2a | 8706 | + DiMustAnyLock(dentry); |
1facf9fc | 8707 | + return au_di(dentry)->di_bwh; |
8708 | +} | |
8709 | + | |
8710 | +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry) | |
8711 | +{ | |
1308ab2a | 8712 | + DiMustAnyLock(dentry); |
1facf9fc | 8713 | + return au_di(dentry)->di_bdiropq; |
8714 | +} | |
8715 | + | |
8716 | +/* todo: hard/soft set? */ | |
8717 | +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex) | |
8718 | +{ | |
1308ab2a | 8719 | + DiMustWriteLock(dentry); |
1facf9fc | 8720 | + au_di(dentry)->di_bstart = bindex; |
8721 | +} | |
8722 | + | |
8723 | +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex) | |
8724 | +{ | |
1308ab2a | 8725 | + DiMustWriteLock(dentry); |
1facf9fc | 8726 | + au_di(dentry)->di_bend = bindex; |
8727 | +} | |
8728 | + | |
8729 | +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex) | |
8730 | +{ | |
1308ab2a | 8731 | + DiMustWriteLock(dentry); |
1facf9fc | 8732 | + /* dbwh can be outside of bstart - bend range */ |
8733 | + au_di(dentry)->di_bwh = bindex; | |
8734 | +} | |
8735 | + | |
8736 | +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex) | |
8737 | +{ | |
1308ab2a | 8738 | + DiMustWriteLock(dentry); |
1facf9fc | 8739 | + au_di(dentry)->di_bdiropq = bindex; |
8740 | +} | |
8741 | + | |
8742 | +/* ---------------------------------------------------------------------- */ | |
8743 | + | |
4a4d8108 | 8744 | +#ifdef CONFIG_AUFS_HNOTIFY |
1facf9fc | 8745 | +static inline void au_digen_dec(struct dentry *d) |
8746 | +{ | |
e49829fe | 8747 | + atomic_dec(&au_di(d)->di_generation); |
1facf9fc | 8748 | +} |
8749 | + | |
4a4d8108 | 8750 | +static inline void au_hn_di_reinit(struct dentry *dentry) |
1facf9fc | 8751 | +{ |
8752 | + dentry->d_fsdata = NULL; | |
8753 | +} | |
8754 | +#else | |
4a4d8108 AM |
8755 | +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused) |
8756 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
1facf9fc | 8757 | + |
8758 | +#endif /* __KERNEL__ */ | |
8759 | +#endif /* __AUFS_DENTRY_H__ */ | |
7f207e10 AM |
8760 | diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c |
8761 | --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 8762 | +++ linux/fs/aufs/dinfo.c 2015-01-25 13:00:38.631047076 +0100 |
38d290e6 | 8763 | @@ -0,0 +1,544 @@ |
1facf9fc | 8764 | +/* |
523b37e3 | 8765 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 8766 | + * |
8767 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8768 | + * it under the terms of the GNU General Public License as published by | |
8769 | + * the Free Software Foundation; either version 2 of the License, or | |
8770 | + * (at your option) any later version. | |
dece6358 AM |
8771 | + * |
8772 | + * This program is distributed in the hope that it will be useful, | |
8773 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8774 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8775 | + * GNU General Public License for more details. | |
8776 | + * | |
8777 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8778 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8779 | + */ |
8780 | + | |
8781 | +/* | |
8782 | + * dentry private data | |
8783 | + */ | |
8784 | + | |
8785 | +#include "aufs.h" | |
8786 | + | |
e49829fe | 8787 | +void au_di_init_once(void *_dinfo) |
4a4d8108 | 8788 | +{ |
e49829fe JR |
8789 | + struct au_dinfo *dinfo = _dinfo; |
8790 | + static struct lock_class_key aufs_di; | |
4a4d8108 | 8791 | + |
e49829fe JR |
8792 | + au_rw_init(&dinfo->di_rwsem); |
8793 | + au_rw_class(&dinfo->di_rwsem, &aufs_di); | |
4a4d8108 AM |
8794 | +} |
8795 | + | |
027c5e7a | 8796 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc) |
1facf9fc | 8797 | +{ |
8798 | + struct au_dinfo *dinfo; | |
027c5e7a | 8799 | + int nbr, i; |
1facf9fc | 8800 | + |
8801 | + dinfo = au_cache_alloc_dinfo(); | |
8802 | + if (unlikely(!dinfo)) | |
8803 | + goto out; | |
8804 | + | |
1facf9fc | 8805 | + nbr = au_sbend(sb) + 1; |
8806 | + if (nbr <= 0) | |
8807 | + nbr = 1; | |
8808 | + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS); | |
027c5e7a AM |
8809 | + if (dinfo->di_hdentry) { |
8810 | + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc); | |
8811 | + dinfo->di_bstart = -1; | |
8812 | + dinfo->di_bend = -1; | |
8813 | + dinfo->di_bwh = -1; | |
8814 | + dinfo->di_bdiropq = -1; | |
38d290e6 | 8815 | + dinfo->di_tmpfile = 0; |
027c5e7a AM |
8816 | + for (i = 0; i < nbr; i++) |
8817 | + dinfo->di_hdentry[i].hd_id = -1; | |
8818 | + goto out; | |
8819 | + } | |
1facf9fc | 8820 | + |
1facf9fc | 8821 | + au_cache_free_dinfo(dinfo); |
027c5e7a AM |
8822 | + dinfo = NULL; |
8823 | + | |
4f0767ce | 8824 | +out: |
027c5e7a | 8825 | + return dinfo; |
1facf9fc | 8826 | +} |
8827 | + | |
027c5e7a | 8828 | +void au_di_free(struct au_dinfo *dinfo) |
4a4d8108 | 8829 | +{ |
4a4d8108 AM |
8830 | + struct au_hdentry *p; |
8831 | + aufs_bindex_t bend, bindex; | |
8832 | + | |
8833 | + /* dentry may not be revalidated */ | |
027c5e7a | 8834 | + bindex = dinfo->di_bstart; |
4a4d8108 | 8835 | + if (bindex >= 0) { |
027c5e7a AM |
8836 | + bend = dinfo->di_bend; |
8837 | + p = dinfo->di_hdentry + bindex; | |
4a4d8108 AM |
8838 | + while (bindex++ <= bend) |
8839 | + au_hdput(p++); | |
8840 | + } | |
027c5e7a AM |
8841 | + kfree(dinfo->di_hdentry); |
8842 | + au_cache_free_dinfo(dinfo); | |
8843 | +} | |
8844 | + | |
8845 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b) | |
8846 | +{ | |
8847 | + struct au_hdentry *p; | |
8848 | + aufs_bindex_t bi; | |
8849 | + | |
8850 | + AuRwMustWriteLock(&a->di_rwsem); | |
8851 | + AuRwMustWriteLock(&b->di_rwsem); | |
8852 | + | |
8853 | +#define DiSwap(v, name) \ | |
8854 | + do { \ | |
8855 | + v = a->di_##name; \ | |
8856 | + a->di_##name = b->di_##name; \ | |
8857 | + b->di_##name = v; \ | |
8858 | + } while (0) | |
8859 | + | |
8860 | + DiSwap(p, hdentry); | |
8861 | + DiSwap(bi, bstart); | |
8862 | + DiSwap(bi, bend); | |
8863 | + DiSwap(bi, bwh); | |
8864 | + DiSwap(bi, bdiropq); | |
8865 | + /* smp_mb(); */ | |
8866 | + | |
8867 | +#undef DiSwap | |
8868 | +} | |
8869 | + | |
8870 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src) | |
8871 | +{ | |
8872 | + AuRwMustWriteLock(&dst->di_rwsem); | |
8873 | + AuRwMustWriteLock(&src->di_rwsem); | |
8874 | + | |
8875 | + dst->di_bstart = src->di_bstart; | |
8876 | + dst->di_bend = src->di_bend; | |
8877 | + dst->di_bwh = src->di_bwh; | |
8878 | + dst->di_bdiropq = src->di_bdiropq; | |
8879 | + /* smp_mb(); */ | |
8880 | +} | |
8881 | + | |
8882 | +int au_di_init(struct dentry *dentry) | |
8883 | +{ | |
8884 | + int err; | |
8885 | + struct super_block *sb; | |
8886 | + struct au_dinfo *dinfo; | |
8887 | + | |
8888 | + err = 0; | |
8889 | + sb = dentry->d_sb; | |
8890 | + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD); | |
8891 | + if (dinfo) { | |
8892 | + atomic_set(&dinfo->di_generation, au_sigen(sb)); | |
8893 | + /* smp_mb(); */ /* atomic_set */ | |
8894 | + dentry->d_fsdata = dinfo; | |
8895 | + } else | |
8896 | + err = -ENOMEM; | |
8897 | + | |
8898 | + return err; | |
8899 | +} | |
8900 | + | |
8901 | +void au_di_fin(struct dentry *dentry) | |
8902 | +{ | |
8903 | + struct au_dinfo *dinfo; | |
8904 | + | |
8905 | + dinfo = au_di(dentry); | |
8906 | + AuRwDestroy(&dinfo->di_rwsem); | |
8907 | + au_di_free(dinfo); | |
4a4d8108 AM |
8908 | +} |
8909 | + | |
1facf9fc | 8910 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr) |
8911 | +{ | |
8912 | + int err, sz; | |
8913 | + struct au_hdentry *hdp; | |
8914 | + | |
1308ab2a | 8915 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
8916 | + | |
1facf9fc | 8917 | + err = -ENOMEM; |
8918 | + sz = sizeof(*hdp) * (dinfo->di_bend + 1); | |
8919 | + if (!sz) | |
8920 | + sz = sizeof(*hdp); | |
8921 | + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS); | |
8922 | + if (hdp) { | |
8923 | + dinfo->di_hdentry = hdp; | |
8924 | + err = 0; | |
8925 | + } | |
8926 | + | |
8927 | + return err; | |
8928 | +} | |
8929 | + | |
8930 | +/* ---------------------------------------------------------------------- */ | |
8931 | + | |
8932 | +static void do_ii_write_lock(struct inode *inode, unsigned int lsc) | |
8933 | +{ | |
8934 | + switch (lsc) { | |
8935 | + case AuLsc_DI_CHILD: | |
8936 | + ii_write_lock_child(inode); | |
8937 | + break; | |
8938 | + case AuLsc_DI_CHILD2: | |
8939 | + ii_write_lock_child2(inode); | |
8940 | + break; | |
8941 | + case AuLsc_DI_CHILD3: | |
8942 | + ii_write_lock_child3(inode); | |
8943 | + break; | |
8944 | + case AuLsc_DI_PARENT: | |
8945 | + ii_write_lock_parent(inode); | |
8946 | + break; | |
8947 | + case AuLsc_DI_PARENT2: | |
8948 | + ii_write_lock_parent2(inode); | |
8949 | + break; | |
8950 | + case AuLsc_DI_PARENT3: | |
8951 | + ii_write_lock_parent3(inode); | |
8952 | + break; | |
8953 | + default: | |
8954 | + BUG(); | |
8955 | + } | |
8956 | +} | |
8957 | + | |
8958 | +static void do_ii_read_lock(struct inode *inode, unsigned int lsc) | |
8959 | +{ | |
8960 | + switch (lsc) { | |
8961 | + case AuLsc_DI_CHILD: | |
8962 | + ii_read_lock_child(inode); | |
8963 | + break; | |
8964 | + case AuLsc_DI_CHILD2: | |
8965 | + ii_read_lock_child2(inode); | |
8966 | + break; | |
8967 | + case AuLsc_DI_CHILD3: | |
8968 | + ii_read_lock_child3(inode); | |
8969 | + break; | |
8970 | + case AuLsc_DI_PARENT: | |
8971 | + ii_read_lock_parent(inode); | |
8972 | + break; | |
8973 | + case AuLsc_DI_PARENT2: | |
8974 | + ii_read_lock_parent2(inode); | |
8975 | + break; | |
8976 | + case AuLsc_DI_PARENT3: | |
8977 | + ii_read_lock_parent3(inode); | |
8978 | + break; | |
8979 | + default: | |
8980 | + BUG(); | |
8981 | + } | |
8982 | +} | |
8983 | + | |
8984 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc) | |
8985 | +{ | |
dece6358 | 8986 | + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc); |
1facf9fc | 8987 | + if (d->d_inode) { |
8988 | + if (au_ftest_lock(flags, IW)) | |
8989 | + do_ii_write_lock(d->d_inode, lsc); | |
8990 | + else if (au_ftest_lock(flags, IR)) | |
8991 | + do_ii_read_lock(d->d_inode, lsc); | |
8992 | + } | |
8993 | +} | |
8994 | + | |
8995 | +void di_read_unlock(struct dentry *d, int flags) | |
8996 | +{ | |
8997 | + if (d->d_inode) { | |
027c5e7a AM |
8998 | + if (au_ftest_lock(flags, IW)) { |
8999 | + au_dbg_verify_dinode(d); | |
1facf9fc | 9000 | + ii_write_unlock(d->d_inode); |
027c5e7a AM |
9001 | + } else if (au_ftest_lock(flags, IR)) { |
9002 | + au_dbg_verify_dinode(d); | |
1facf9fc | 9003 | + ii_read_unlock(d->d_inode); |
027c5e7a | 9004 | + } |
1facf9fc | 9005 | + } |
dece6358 | 9006 | + au_rw_read_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9007 | +} |
9008 | + | |
9009 | +void di_downgrade_lock(struct dentry *d, int flags) | |
9010 | +{ | |
1facf9fc | 9011 | + if (d->d_inode && au_ftest_lock(flags, IR)) |
9012 | + ii_downgrade_lock(d->d_inode); | |
dece6358 | 9013 | + au_rw_dgrade_lock(&au_di(d)->di_rwsem); |
1facf9fc | 9014 | +} |
9015 | + | |
9016 | +void di_write_lock(struct dentry *d, unsigned int lsc) | |
9017 | +{ | |
dece6358 | 9018 | + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc); |
1facf9fc | 9019 | + if (d->d_inode) |
9020 | + do_ii_write_lock(d->d_inode, lsc); | |
9021 | +} | |
9022 | + | |
9023 | +void di_write_unlock(struct dentry *d) | |
9024 | +{ | |
027c5e7a | 9025 | + au_dbg_verify_dinode(d); |
1facf9fc | 9026 | + if (d->d_inode) |
9027 | + ii_write_unlock(d->d_inode); | |
dece6358 | 9028 | + au_rw_write_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9029 | +} |
9030 | + | |
9031 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir) | |
9032 | +{ | |
9033 | + AuDebugOn(d1 == d2 | |
9034 | + || d1->d_inode == d2->d_inode | |
9035 | + || d1->d_sb != d2->d_sb); | |
9036 | + | |
9037 | + if (isdir && au_test_subdir(d1, d2)) { | |
9038 | + di_write_lock_child(d1); | |
9039 | + di_write_lock_child2(d2); | |
9040 | + } else { | |
9041 | + /* there should be no races */ | |
9042 | + di_write_lock_child(d2); | |
9043 | + di_write_lock_child2(d1); | |
9044 | + } | |
9045 | +} | |
9046 | + | |
9047 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir) | |
9048 | +{ | |
9049 | + AuDebugOn(d1 == d2 | |
9050 | + || d1->d_inode == d2->d_inode | |
9051 | + || d1->d_sb != d2->d_sb); | |
9052 | + | |
9053 | + if (isdir && au_test_subdir(d1, d2)) { | |
9054 | + di_write_lock_parent(d1); | |
9055 | + di_write_lock_parent2(d2); | |
9056 | + } else { | |
9057 | + /* there should be no races */ | |
9058 | + di_write_lock_parent(d2); | |
9059 | + di_write_lock_parent2(d1); | |
9060 | + } | |
9061 | +} | |
9062 | + | |
9063 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2) | |
9064 | +{ | |
9065 | + di_write_unlock(d1); | |
9066 | + if (d1->d_inode == d2->d_inode) | |
dece6358 | 9067 | + au_rw_write_unlock(&au_di(d2)->di_rwsem); |
1facf9fc | 9068 | + else |
9069 | + di_write_unlock(d2); | |
9070 | +} | |
9071 | + | |
9072 | +/* ---------------------------------------------------------------------- */ | |
9073 | + | |
9074 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex) | |
9075 | +{ | |
9076 | + struct dentry *d; | |
9077 | + | |
1308ab2a | 9078 | + DiMustAnyLock(dentry); |
9079 | + | |
1facf9fc | 9080 | + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry)) |
9081 | + return NULL; | |
9082 | + AuDebugOn(bindex < 0); | |
9083 | + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry; | |
c1595e42 | 9084 | + AuDebugOn(d && au_dcount(d) <= 0); |
1facf9fc | 9085 | + return d; |
9086 | +} | |
9087 | + | |
2cbb1c4b JR |
9088 | +/* |
9089 | + * extended version of au_h_dptr(). | |
38d290e6 JR |
9090 | + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or |
9091 | + * error. | |
2cbb1c4b JR |
9092 | + */ |
9093 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex) | |
9094 | +{ | |
9095 | + struct dentry *h_dentry; | |
9096 | + struct inode *inode, *h_inode; | |
9097 | + | |
9098 | + inode = dentry->d_inode; | |
9099 | + AuDebugOn(!inode); | |
9100 | + | |
9101 | + h_dentry = NULL; | |
9102 | + if (au_dbstart(dentry) <= bindex | |
9103 | + && bindex <= au_dbend(dentry)) | |
9104 | + h_dentry = au_h_dptr(dentry, bindex); | |
38d290e6 | 9105 | + if (h_dentry && !au_d_linkable(h_dentry)) { |
2cbb1c4b JR |
9106 | + dget(h_dentry); |
9107 | + goto out; /* success */ | |
9108 | + } | |
9109 | + | |
9110 | + AuDebugOn(bindex < au_ibstart(inode)); | |
9111 | + AuDebugOn(au_ibend(inode) < bindex); | |
9112 | + h_inode = au_h_iptr(inode, bindex); | |
9113 | + h_dentry = d_find_alias(h_inode); | |
9114 | + if (h_dentry) { | |
9115 | + if (!IS_ERR(h_dentry)) { | |
38d290e6 | 9116 | + if (!au_d_linkable(h_dentry)) |
2cbb1c4b JR |
9117 | + goto out; /* success */ |
9118 | + dput(h_dentry); | |
9119 | + } else | |
9120 | + goto out; | |
9121 | + } | |
9122 | + | |
9123 | + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) { | |
9124 | + h_dentry = au_plink_lkup(inode, bindex); | |
9125 | + AuDebugOn(!h_dentry); | |
9126 | + if (!IS_ERR(h_dentry)) { | |
9127 | + if (!au_d_hashed_positive(h_dentry)) | |
9128 | + goto out; /* success */ | |
9129 | + dput(h_dentry); | |
9130 | + h_dentry = NULL; | |
9131 | + } | |
9132 | + } | |
9133 | + | |
9134 | +out: | |
9135 | + AuDbgDentry(h_dentry); | |
9136 | + return h_dentry; | |
9137 | +} | |
9138 | + | |
1facf9fc | 9139 | +aufs_bindex_t au_dbtail(struct dentry *dentry) |
9140 | +{ | |
9141 | + aufs_bindex_t bend, bwh; | |
9142 | + | |
9143 | + bend = au_dbend(dentry); | |
9144 | + if (0 <= bend) { | |
9145 | + bwh = au_dbwh(dentry); | |
9146 | + if (!bwh) | |
9147 | + return bwh; | |
9148 | + if (0 < bwh && bwh < bend) | |
9149 | + return bwh - 1; | |
9150 | + } | |
9151 | + return bend; | |
9152 | +} | |
9153 | + | |
9154 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry) | |
9155 | +{ | |
9156 | + aufs_bindex_t bend, bopq; | |
9157 | + | |
9158 | + bend = au_dbtail(dentry); | |
9159 | + if (0 <= bend) { | |
9160 | + bopq = au_dbdiropq(dentry); | |
9161 | + if (0 <= bopq && bopq < bend) | |
9162 | + bend = bopq; | |
9163 | + } | |
9164 | + return bend; | |
9165 | +} | |
9166 | + | |
9167 | +/* ---------------------------------------------------------------------- */ | |
9168 | + | |
9169 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9170 | + struct dentry *h_dentry) | |
9171 | +{ | |
9172 | + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex; | |
027c5e7a | 9173 | + struct au_branch *br; |
1facf9fc | 9174 | + |
1308ab2a | 9175 | + DiMustWriteLock(dentry); |
9176 | + | |
4a4d8108 | 9177 | + au_hdput(hd); |
1facf9fc | 9178 | + hd->hd_dentry = h_dentry; |
027c5e7a AM |
9179 | + if (h_dentry) { |
9180 | + br = au_sbr(dentry->d_sb, bindex); | |
9181 | + hd->hd_id = br->br_id; | |
9182 | + } | |
9183 | +} | |
9184 | + | |
9185 | +int au_dbrange_test(struct dentry *dentry) | |
9186 | +{ | |
9187 | + int err; | |
9188 | + aufs_bindex_t bstart, bend; | |
9189 | + | |
9190 | + err = 0; | |
9191 | + bstart = au_dbstart(dentry); | |
9192 | + bend = au_dbend(dentry); | |
9193 | + if (bstart >= 0) | |
9194 | + AuDebugOn(bend < 0 && bstart > bend); | |
9195 | + else { | |
9196 | + err = -EIO; | |
9197 | + AuDebugOn(bend >= 0); | |
9198 | + } | |
9199 | + | |
9200 | + return err; | |
9201 | +} | |
9202 | + | |
9203 | +int au_digen_test(struct dentry *dentry, unsigned int sigen) | |
9204 | +{ | |
9205 | + int err; | |
9206 | + | |
9207 | + err = 0; | |
9208 | + if (unlikely(au_digen(dentry) != sigen | |
9209 | + || au_iigen_test(dentry->d_inode, sigen))) | |
9210 | + err = -EIO; | |
9211 | + | |
9212 | + return err; | |
1facf9fc | 9213 | +} |
9214 | + | |
9215 | +void au_update_digen(struct dentry *dentry) | |
9216 | +{ | |
9217 | + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb)); | |
9218 | + /* smp_mb(); */ /* atomic_set */ | |
9219 | +} | |
9220 | + | |
9221 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero) | |
9222 | +{ | |
9223 | + struct au_dinfo *dinfo; | |
9224 | + struct dentry *h_d; | |
4a4d8108 | 9225 | + struct au_hdentry *hdp; |
1facf9fc | 9226 | + |
1308ab2a | 9227 | + DiMustWriteLock(dentry); |
9228 | + | |
1facf9fc | 9229 | + dinfo = au_di(dentry); |
9230 | + if (!dinfo || dinfo->di_bstart < 0) | |
9231 | + return; | |
9232 | + | |
4a4d8108 | 9233 | + hdp = dinfo->di_hdentry; |
1facf9fc | 9234 | + if (do_put_zero) { |
9235 | + aufs_bindex_t bindex, bend; | |
9236 | + | |
9237 | + bend = dinfo->di_bend; | |
9238 | + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) { | |
4a4d8108 | 9239 | + h_d = hdp[0 + bindex].hd_dentry; |
1facf9fc | 9240 | + if (h_d && !h_d->d_inode) |
9241 | + au_set_h_dptr(dentry, bindex, NULL); | |
9242 | + } | |
9243 | + } | |
9244 | + | |
9245 | + dinfo->di_bstart = -1; | |
9246 | + while (++dinfo->di_bstart <= dinfo->di_bend) | |
4a4d8108 | 9247 | + if (hdp[0 + dinfo->di_bstart].hd_dentry) |
1facf9fc | 9248 | + break; |
9249 | + if (dinfo->di_bstart > dinfo->di_bend) { | |
9250 | + dinfo->di_bstart = -1; | |
9251 | + dinfo->di_bend = -1; | |
9252 | + return; | |
9253 | + } | |
9254 | + | |
9255 | + dinfo->di_bend++; | |
9256 | + while (0 <= --dinfo->di_bend) | |
4a4d8108 | 9257 | + if (hdp[0 + dinfo->di_bend].hd_dentry) |
1facf9fc | 9258 | + break; |
9259 | + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0); | |
9260 | +} | |
9261 | + | |
9262 | +void au_update_dbstart(struct dentry *dentry) | |
9263 | +{ | |
9264 | + aufs_bindex_t bindex, bend; | |
9265 | + struct dentry *h_dentry; | |
9266 | + | |
9267 | + bend = au_dbend(dentry); | |
9268 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) { | |
9269 | + h_dentry = au_h_dptr(dentry, bindex); | |
9270 | + if (!h_dentry) | |
9271 | + continue; | |
9272 | + if (h_dentry->d_inode) { | |
9273 | + au_set_dbstart(dentry, bindex); | |
9274 | + return; | |
9275 | + } | |
9276 | + au_set_h_dptr(dentry, bindex, NULL); | |
9277 | + } | |
9278 | +} | |
9279 | + | |
9280 | +void au_update_dbend(struct dentry *dentry) | |
9281 | +{ | |
9282 | + aufs_bindex_t bindex, bstart; | |
9283 | + struct dentry *h_dentry; | |
9284 | + | |
9285 | + bstart = au_dbstart(dentry); | |
7f207e10 | 9286 | + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) { |
1facf9fc | 9287 | + h_dentry = au_h_dptr(dentry, bindex); |
9288 | + if (!h_dentry) | |
9289 | + continue; | |
9290 | + if (h_dentry->d_inode) { | |
9291 | + au_set_dbend(dentry, bindex); | |
9292 | + return; | |
9293 | + } | |
9294 | + au_set_h_dptr(dentry, bindex, NULL); | |
9295 | + } | |
9296 | +} | |
9297 | + | |
9298 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry) | |
9299 | +{ | |
9300 | + aufs_bindex_t bindex, bend; | |
9301 | + | |
9302 | + bend = au_dbend(dentry); | |
9303 | + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) | |
9304 | + if (au_h_dptr(dentry, bindex) == h_dentry) | |
9305 | + return bindex; | |
9306 | + return -1; | |
9307 | +} | |
7f207e10 AM |
9308 | diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c |
9309 | --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 9310 | +++ linux/fs/aufs/dir.c 2015-01-25 13:00:38.631047076 +0100 |
076b876e | 9311 | @@ -0,0 +1,645 @@ |
1facf9fc | 9312 | +/* |
523b37e3 | 9313 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 9314 | + * |
9315 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9316 | + * it under the terms of the GNU General Public License as published by | |
9317 | + * the Free Software Foundation; either version 2 of the License, or | |
9318 | + * (at your option) any later version. | |
dece6358 AM |
9319 | + * |
9320 | + * This program is distributed in the hope that it will be useful, | |
9321 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9322 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9323 | + * GNU General Public License for more details. | |
9324 | + * | |
9325 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9326 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9327 | + */ |
9328 | + | |
9329 | +/* | |
9330 | + * directory operations | |
9331 | + */ | |
9332 | + | |
9333 | +#include <linux/fs_stack.h> | |
9334 | +#include "aufs.h" | |
9335 | + | |
9336 | +void au_add_nlink(struct inode *dir, struct inode *h_dir) | |
9337 | +{ | |
9dbd164d AM |
9338 | + unsigned int nlink; |
9339 | + | |
1facf9fc | 9340 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9341 | + | |
9dbd164d AM |
9342 | + nlink = dir->i_nlink; |
9343 | + nlink += h_dir->i_nlink - 2; | |
1facf9fc | 9344 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9345 | + nlink += 2; |
f6b6e03d | 9346 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 9347 | + /* 0 can happen in revaliding */ |
92d182d2 | 9348 | + set_nlink(dir, nlink); |
1facf9fc | 9349 | +} |
9350 | + | |
9351 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir) | |
9352 | +{ | |
9dbd164d AM |
9353 | + unsigned int nlink; |
9354 | + | |
1facf9fc | 9355 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
9356 | + | |
9dbd164d AM |
9357 | + nlink = dir->i_nlink; |
9358 | + nlink -= h_dir->i_nlink - 2; | |
1facf9fc | 9359 | + if (h_dir->i_nlink < 2) |
9dbd164d | 9360 | + nlink -= 2; |
f6b6e03d | 9361 | + smp_mb(); /* for i_nlink */ |
92d182d2 | 9362 | + /* nlink == 0 means the branch-fs is broken */ |
9dbd164d | 9363 | + set_nlink(dir, nlink); |
1facf9fc | 9364 | +} |
9365 | + | |
1308ab2a | 9366 | +loff_t au_dir_size(struct file *file, struct dentry *dentry) |
9367 | +{ | |
9368 | + loff_t sz; | |
9369 | + aufs_bindex_t bindex, bend; | |
9370 | + struct file *h_file; | |
9371 | + struct dentry *h_dentry; | |
9372 | + | |
9373 | + sz = 0; | |
9374 | + if (file) { | |
c06a8ce3 AM |
9375 | + AuDebugOn(!file_inode(file)); |
9376 | + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode)); | |
1308ab2a | 9377 | + |
4a4d8108 | 9378 | + bend = au_fbend_dir(file); |
1308ab2a | 9379 | + for (bindex = au_fbstart(file); |
9380 | + bindex <= bend && sz < KMALLOC_MAX_SIZE; | |
9381 | + bindex++) { | |
4a4d8108 | 9382 | + h_file = au_hf_dir(file, bindex); |
c06a8ce3 AM |
9383 | + if (h_file && file_inode(h_file)) |
9384 | + sz += vfsub_f_size_read(h_file); | |
1308ab2a | 9385 | + } |
9386 | + } else { | |
9387 | + AuDebugOn(!dentry); | |
9388 | + AuDebugOn(!dentry->d_inode); | |
9389 | + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode)); | |
9390 | + | |
9391 | + bend = au_dbtaildir(dentry); | |
9392 | + for (bindex = au_dbstart(dentry); | |
9393 | + bindex <= bend && sz < KMALLOC_MAX_SIZE; | |
9394 | + bindex++) { | |
9395 | + h_dentry = au_h_dptr(dentry, bindex); | |
9396 | + if (h_dentry && h_dentry->d_inode) | |
9397 | + sz += i_size_read(h_dentry->d_inode); | |
9398 | + } | |
9399 | + } | |
9400 | + if (sz < KMALLOC_MAX_SIZE) | |
9401 | + sz = roundup_pow_of_two(sz); | |
9402 | + if (sz > KMALLOC_MAX_SIZE) | |
9403 | + sz = KMALLOC_MAX_SIZE; | |
9404 | + else if (sz < NAME_MAX) { | |
9405 | + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX); | |
9406 | + sz = AUFS_RDBLK_DEF; | |
9407 | + } | |
9408 | + return sz; | |
9409 | +} | |
9410 | + | |
1facf9fc | 9411 | +/* ---------------------------------------------------------------------- */ |
9412 | + | |
9413 | +static int reopen_dir(struct file *file) | |
9414 | +{ | |
9415 | + int err; | |
9416 | + unsigned int flags; | |
9417 | + aufs_bindex_t bindex, btail, bstart; | |
9418 | + struct dentry *dentry, *h_dentry; | |
9419 | + struct file *h_file; | |
9420 | + | |
9421 | + /* open all lower dirs */ | |
9422 | + dentry = file->f_dentry; | |
9423 | + bstart = au_dbstart(dentry); | |
9424 | + for (bindex = au_fbstart(file); bindex < bstart; bindex++) | |
9425 | + au_set_h_fptr(file, bindex, NULL); | |
9426 | + au_set_fbstart(file, bstart); | |
9427 | + | |
9428 | + btail = au_dbtaildir(dentry); | |
4a4d8108 | 9429 | + for (bindex = au_fbend_dir(file); btail < bindex; bindex--) |
1facf9fc | 9430 | + au_set_h_fptr(file, bindex, NULL); |
4a4d8108 | 9431 | + au_set_fbend_dir(file, btail); |
1facf9fc | 9432 | + |
4a4d8108 | 9433 | + flags = vfsub_file_flags(file); |
1facf9fc | 9434 | + for (bindex = bstart; bindex <= btail; bindex++) { |
9435 | + h_dentry = au_h_dptr(dentry, bindex); | |
9436 | + if (!h_dentry) | |
9437 | + continue; | |
4a4d8108 | 9438 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 9439 | + if (h_file) |
9440 | + continue; | |
9441 | + | |
392086de | 9442 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9443 | + err = PTR_ERR(h_file); |
9444 | + if (IS_ERR(h_file)) | |
9445 | + goto out; /* close all? */ | |
9446 | + au_set_h_fptr(file, bindex, h_file); | |
9447 | + } | |
9448 | + au_update_figen(file); | |
9449 | + /* todo: necessary? */ | |
9450 | + /* file->f_ra = h_file->f_ra; */ | |
9451 | + err = 0; | |
9452 | + | |
4f0767ce | 9453 | +out: |
1facf9fc | 9454 | + return err; |
9455 | +} | |
9456 | + | |
9457 | +static int do_open_dir(struct file *file, int flags) | |
9458 | +{ | |
9459 | + int err; | |
9460 | + aufs_bindex_t bindex, btail; | |
9461 | + struct dentry *dentry, *h_dentry; | |
9462 | + struct file *h_file; | |
9463 | + | |
1308ab2a | 9464 | + FiMustWriteLock(file); |
9465 | + | |
523b37e3 | 9466 | + err = 0; |
1facf9fc | 9467 | + dentry = file->f_dentry; |
1facf9fc | 9468 | + file->f_version = dentry->d_inode->i_version; |
9469 | + bindex = au_dbstart(dentry); | |
9470 | + au_set_fbstart(file, bindex); | |
9471 | + btail = au_dbtaildir(dentry); | |
4a4d8108 | 9472 | + au_set_fbend_dir(file, btail); |
1facf9fc | 9473 | + for (; !err && bindex <= btail; bindex++) { |
9474 | + h_dentry = au_h_dptr(dentry, bindex); | |
9475 | + if (!h_dentry) | |
9476 | + continue; | |
9477 | + | |
392086de | 9478 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 9479 | + if (IS_ERR(h_file)) { |
9480 | + err = PTR_ERR(h_file); | |
9481 | + break; | |
9482 | + } | |
9483 | + au_set_h_fptr(file, bindex, h_file); | |
9484 | + } | |
9485 | + au_update_figen(file); | |
9486 | + /* todo: necessary? */ | |
9487 | + /* file->f_ra = h_file->f_ra; */ | |
9488 | + if (!err) | |
9489 | + return 0; /* success */ | |
9490 | + | |
9491 | + /* close all */ | |
9492 | + for (bindex = au_fbstart(file); bindex <= btail; bindex++) | |
9493 | + au_set_h_fptr(file, bindex, NULL); | |
9494 | + au_set_fbstart(file, -1); | |
4a4d8108 AM |
9495 | + au_set_fbend_dir(file, -1); |
9496 | + | |
1facf9fc | 9497 | + return err; |
9498 | +} | |
9499 | + | |
9500 | +static int aufs_open_dir(struct inode *inode __maybe_unused, | |
9501 | + struct file *file) | |
9502 | +{ | |
4a4d8108 AM |
9503 | + int err; |
9504 | + struct super_block *sb; | |
9505 | + struct au_fidir *fidir; | |
9506 | + | |
9507 | + err = -ENOMEM; | |
9508 | + sb = file->f_dentry->d_sb; | |
9509 | + si_read_lock(sb, AuLock_FLUSH); | |
e49829fe | 9510 | + fidir = au_fidir_alloc(sb); |
4a4d8108 AM |
9511 | + if (fidir) { |
9512 | + err = au_do_open(file, do_open_dir, fidir); | |
9513 | + if (unlikely(err)) | |
9514 | + kfree(fidir); | |
9515 | + } | |
9516 | + si_read_unlock(sb); | |
9517 | + return err; | |
1facf9fc | 9518 | +} |
9519 | + | |
9520 | +static int aufs_release_dir(struct inode *inode __maybe_unused, | |
9521 | + struct file *file) | |
9522 | +{ | |
9523 | + struct au_vdir *vdir_cache; | |
4a4d8108 AM |
9524 | + struct au_finfo *finfo; |
9525 | + struct au_fidir *fidir; | |
9526 | + aufs_bindex_t bindex, bend; | |
1facf9fc | 9527 | + |
4a4d8108 AM |
9528 | + finfo = au_fi(file); |
9529 | + fidir = finfo->fi_hdir; | |
9530 | + if (fidir) { | |
076b876e AM |
9531 | + au_sphl_del(&finfo->fi_hlist, |
9532 | + &au_sbi(file->f_dentry->d_sb)->si_files); | |
4a4d8108 AM |
9533 | + vdir_cache = fidir->fd_vdir_cache; /* lock-free */ |
9534 | + if (vdir_cache) | |
9535 | + au_vdir_free(vdir_cache); | |
9536 | + | |
9537 | + bindex = finfo->fi_btop; | |
9538 | + if (bindex >= 0) { | |
9539 | + /* | |
9540 | + * calls fput() instead of filp_close(), | |
9541 | + * since no dnotify or lock for the lower file. | |
9542 | + */ | |
9543 | + bend = fidir->fd_bbot; | |
9544 | + for (; bindex <= bend; bindex++) | |
9545 | + au_set_h_fptr(file, bindex, NULL); | |
9546 | + } | |
9547 | + kfree(fidir); | |
9548 | + finfo->fi_hdir = NULL; | |
1facf9fc | 9549 | + } |
1facf9fc | 9550 | + au_finfo_fin(file); |
1facf9fc | 9551 | + return 0; |
9552 | +} | |
9553 | + | |
9554 | +/* ---------------------------------------------------------------------- */ | |
9555 | + | |
4a4d8108 AM |
9556 | +static int au_do_flush_dir(struct file *file, fl_owner_t id) |
9557 | +{ | |
9558 | + int err; | |
9559 | + aufs_bindex_t bindex, bend; | |
9560 | + struct file *h_file; | |
9561 | + | |
9562 | + err = 0; | |
9563 | + bend = au_fbend_dir(file); | |
9564 | + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) { | |
9565 | + h_file = au_hf_dir(file, bindex); | |
9566 | + if (h_file) | |
9567 | + err = vfsub_flush(h_file, id); | |
9568 | + } | |
9569 | + return err; | |
9570 | +} | |
9571 | + | |
9572 | +static int aufs_flush_dir(struct file *file, fl_owner_t id) | |
9573 | +{ | |
9574 | + return au_do_flush(file, id, au_do_flush_dir); | |
9575 | +} | |
9576 | + | |
9577 | +/* ---------------------------------------------------------------------- */ | |
9578 | + | |
1facf9fc | 9579 | +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync) |
9580 | +{ | |
9581 | + int err; | |
9582 | + aufs_bindex_t bend, bindex; | |
9583 | + struct inode *inode; | |
9584 | + struct super_block *sb; | |
9585 | + | |
9586 | + err = 0; | |
9587 | + sb = dentry->d_sb; | |
9588 | + inode = dentry->d_inode; | |
9589 | + IMustLock(inode); | |
9590 | + bend = au_dbend(dentry); | |
9591 | + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) { | |
9592 | + struct path h_path; | |
1facf9fc | 9593 | + |
9594 | + if (au_test_ro(sb, bindex, inode)) | |
9595 | + continue; | |
9596 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
9597 | + if (!h_path.dentry) | |
9598 | + continue; | |
1facf9fc | 9599 | + |
1facf9fc | 9600 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
53392da6 | 9601 | + err = vfsub_fsync(NULL, &h_path, datasync); |
1facf9fc | 9602 | + } |
9603 | + | |
9604 | + return err; | |
9605 | +} | |
9606 | + | |
9607 | +static int au_do_fsync_dir(struct file *file, int datasync) | |
9608 | +{ | |
9609 | + int err; | |
9610 | + aufs_bindex_t bend, bindex; | |
9611 | + struct file *h_file; | |
9612 | + struct super_block *sb; | |
9613 | + struct inode *inode; | |
1facf9fc | 9614 | + |
9615 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1); | |
9616 | + if (unlikely(err)) | |
9617 | + goto out; | |
9618 | + | |
9619 | + sb = file->f_dentry->d_sb; | |
c06a8ce3 | 9620 | + inode = file_inode(file); |
4a4d8108 | 9621 | + bend = au_fbend_dir(file); |
1facf9fc | 9622 | + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) { |
4a4d8108 | 9623 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 9624 | + if (!h_file || au_test_ro(sb, bindex, inode)) |
9625 | + continue; | |
9626 | + | |
53392da6 | 9627 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
1facf9fc | 9628 | + } |
9629 | + | |
4f0767ce | 9630 | +out: |
1facf9fc | 9631 | + return err; |
9632 | +} | |
9633 | + | |
9634 | +/* | |
9635 | + * @file may be NULL | |
9636 | + */ | |
1e00d052 AM |
9637 | +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end, |
9638 | + int datasync) | |
1facf9fc | 9639 | +{ |
9640 | + int err; | |
b752ccd1 | 9641 | + struct dentry *dentry; |
1facf9fc | 9642 | + struct super_block *sb; |
1e00d052 | 9643 | + struct mutex *mtx; |
1facf9fc | 9644 | + |
9645 | + err = 0; | |
1e00d052 AM |
9646 | + dentry = file->f_dentry; |
9647 | + mtx = &dentry->d_inode->i_mutex; | |
9648 | + mutex_lock(mtx); | |
1facf9fc | 9649 | + sb = dentry->d_sb; |
9650 | + si_noflush_read_lock(sb); | |
9651 | + if (file) | |
9652 | + err = au_do_fsync_dir(file, datasync); | |
9653 | + else { | |
9654 | + di_write_lock_child(dentry); | |
9655 | + err = au_do_fsync_dir_no_file(dentry, datasync); | |
9656 | + } | |
9657 | + au_cpup_attr_timesizes(dentry->d_inode); | |
9658 | + di_write_unlock(dentry); | |
9659 | + if (file) | |
9660 | + fi_write_unlock(file); | |
9661 | + | |
9662 | + si_read_unlock(sb); | |
1e00d052 | 9663 | + mutex_unlock(mtx); |
1facf9fc | 9664 | + return err; |
9665 | +} | |
9666 | + | |
9667 | +/* ---------------------------------------------------------------------- */ | |
9668 | + | |
392086de | 9669 | +static int aufs_iterate(struct file *file, struct dir_context *ctx) |
1facf9fc | 9670 | +{ |
9671 | + int err; | |
9672 | + struct dentry *dentry; | |
9dbd164d | 9673 | + struct inode *inode, *h_inode; |
1facf9fc | 9674 | + struct super_block *sb; |
9675 | + | |
523b37e3 | 9676 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 9677 | + |
1facf9fc | 9678 | + dentry = file->f_dentry; |
9679 | + inode = dentry->d_inode; | |
9680 | + IMustLock(inode); | |
9681 | + | |
9682 | + sb = dentry->d_sb; | |
9683 | + si_read_lock(sb, AuLock_FLUSH); | |
9684 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1); | |
9685 | + if (unlikely(err)) | |
9686 | + goto out; | |
027c5e7a AM |
9687 | + err = au_alive_dir(dentry); |
9688 | + if (!err) | |
9689 | + err = au_vdir_init(file); | |
1facf9fc | 9690 | + di_downgrade_lock(dentry, AuLock_IR); |
9691 | + if (unlikely(err)) | |
9692 | + goto out_unlock; | |
9693 | + | |
9dbd164d | 9694 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); |
b752ccd1 | 9695 | + if (!au_test_nfsd()) { |
392086de | 9696 | + err = au_vdir_fill_de(file, ctx); |
9dbd164d | 9697 | + fsstack_copy_attr_atime(inode, h_inode); |
1facf9fc | 9698 | + } else { |
9699 | + /* | |
9700 | + * nfsd filldir may call lookup_one_len(), vfs_getattr(), | |
9701 | + * encode_fh() and others. | |
9702 | + */ | |
9dbd164d | 9703 | + atomic_inc(&h_inode->i_count); |
1facf9fc | 9704 | + di_read_unlock(dentry, AuLock_IR); |
9705 | + si_read_unlock(sb); | |
392086de | 9706 | + err = au_vdir_fill_de(file, ctx); |
1facf9fc | 9707 | + fsstack_copy_attr_atime(inode, h_inode); |
9708 | + fi_write_unlock(file); | |
9dbd164d | 9709 | + iput(h_inode); |
1facf9fc | 9710 | + |
9711 | + AuTraceErr(err); | |
9712 | + return err; | |
9713 | + } | |
9714 | + | |
4f0767ce | 9715 | +out_unlock: |
1facf9fc | 9716 | + di_read_unlock(dentry, AuLock_IR); |
9717 | + fi_write_unlock(file); | |
4f0767ce | 9718 | +out: |
1facf9fc | 9719 | + si_read_unlock(sb); |
9720 | + return err; | |
9721 | +} | |
9722 | + | |
9723 | +/* ---------------------------------------------------------------------- */ | |
9724 | + | |
9725 | +#define AuTestEmpty_WHONLY 1 | |
dece6358 AM |
9726 | +#define AuTestEmpty_CALLED (1 << 1) |
9727 | +#define AuTestEmpty_SHWH (1 << 2) | |
1facf9fc | 9728 | +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name) |
7f207e10 AM |
9729 | +#define au_fset_testempty(flags, name) \ |
9730 | + do { (flags) |= AuTestEmpty_##name; } while (0) | |
9731 | +#define au_fclr_testempty(flags, name) \ | |
9732 | + do { (flags) &= ~AuTestEmpty_##name; } while (0) | |
1facf9fc | 9733 | + |
dece6358 AM |
9734 | +#ifndef CONFIG_AUFS_SHWH |
9735 | +#undef AuTestEmpty_SHWH | |
9736 | +#define AuTestEmpty_SHWH 0 | |
9737 | +#endif | |
9738 | + | |
1facf9fc | 9739 | +struct test_empty_arg { |
392086de | 9740 | + struct dir_context ctx; |
1308ab2a | 9741 | + struct au_nhash *whlist; |
1facf9fc | 9742 | + unsigned int flags; |
9743 | + int err; | |
9744 | + aufs_bindex_t bindex; | |
9745 | +}; | |
9746 | + | |
392086de AM |
9747 | +static int test_empty_cb(struct dir_context *ctx, const char *__name, |
9748 | + int namelen, loff_t offset __maybe_unused, u64 ino, | |
dece6358 | 9749 | + unsigned int d_type) |
1facf9fc | 9750 | +{ |
392086de AM |
9751 | + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg, |
9752 | + ctx); | |
1facf9fc | 9753 | + char *name = (void *)__name; |
9754 | + | |
9755 | + arg->err = 0; | |
9756 | + au_fset_testempty(arg->flags, CALLED); | |
9757 | + /* smp_mb(); */ | |
9758 | + if (name[0] == '.' | |
9759 | + && (namelen == 1 || (name[1] == '.' && namelen == 2))) | |
9760 | + goto out; /* success */ | |
9761 | + | |
9762 | + if (namelen <= AUFS_WH_PFX_LEN | |
9763 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
9764 | + if (au_ftest_testempty(arg->flags, WHONLY) | |
1308ab2a | 9765 | + && !au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 9766 | + arg->err = -ENOTEMPTY; |
9767 | + goto out; | |
9768 | + } | |
9769 | + | |
9770 | + name += AUFS_WH_PFX_LEN; | |
9771 | + namelen -= AUFS_WH_PFX_LEN; | |
1308ab2a | 9772 | + if (!au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 9773 | + arg->err = au_nhash_append_wh |
1308ab2a | 9774 | + (arg->whlist, name, namelen, ino, d_type, arg->bindex, |
dece6358 | 9775 | + au_ftest_testempty(arg->flags, SHWH)); |
1facf9fc | 9776 | + |
4f0767ce | 9777 | +out: |
1facf9fc | 9778 | + /* smp_mb(); */ |
9779 | + AuTraceErr(arg->err); | |
9780 | + return arg->err; | |
9781 | +} | |
9782 | + | |
9783 | +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
9784 | +{ | |
9785 | + int err; | |
9786 | + struct file *h_file; | |
9787 | + | |
9788 | + h_file = au_h_open(dentry, arg->bindex, | |
9789 | + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE, | |
392086de | 9790 | + /*file*/NULL, /*force_wr*/0); |
1facf9fc | 9791 | + err = PTR_ERR(h_file); |
9792 | + if (IS_ERR(h_file)) | |
9793 | + goto out; | |
9794 | + | |
9795 | + err = 0; | |
9796 | + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE) | |
c06a8ce3 | 9797 | + && !file_inode(h_file)->i_nlink) |
1facf9fc | 9798 | + goto out_put; |
9799 | + | |
9800 | + do { | |
9801 | + arg->err = 0; | |
9802 | + au_fclr_testempty(arg->flags, CALLED); | |
9803 | + /* smp_mb(); */ | |
392086de | 9804 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1facf9fc | 9805 | + if (err >= 0) |
9806 | + err = arg->err; | |
9807 | + } while (!err && au_ftest_testempty(arg->flags, CALLED)); | |
9808 | + | |
4f0767ce | 9809 | +out_put: |
1facf9fc | 9810 | + fput(h_file); |
9811 | + au_sbr_put(dentry->d_sb, arg->bindex); | |
4f0767ce | 9812 | +out: |
1facf9fc | 9813 | + return err; |
9814 | +} | |
9815 | + | |
9816 | +struct do_test_empty_args { | |
9817 | + int *errp; | |
9818 | + struct dentry *dentry; | |
9819 | + struct test_empty_arg *arg; | |
9820 | +}; | |
9821 | + | |
9822 | +static void call_do_test_empty(void *args) | |
9823 | +{ | |
9824 | + struct do_test_empty_args *a = args; | |
9825 | + *a->errp = do_test_empty(a->dentry, a->arg); | |
9826 | +} | |
9827 | + | |
9828 | +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
9829 | +{ | |
9830 | + int err, wkq_err; | |
9831 | + struct dentry *h_dentry; | |
9832 | + struct inode *h_inode; | |
9833 | + | |
9834 | + h_dentry = au_h_dptr(dentry, arg->bindex); | |
9835 | + h_inode = h_dentry->d_inode; | |
53392da6 | 9836 | + /* todo: i_mode changes anytime? */ |
1facf9fc | 9837 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
9838 | + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ); | |
9839 | + mutex_unlock(&h_inode->i_mutex); | |
9840 | + if (!err) | |
9841 | + err = do_test_empty(dentry, arg); | |
9842 | + else { | |
9843 | + struct do_test_empty_args args = { | |
9844 | + .errp = &err, | |
9845 | + .dentry = dentry, | |
9846 | + .arg = arg | |
9847 | + }; | |
9848 | + unsigned int flags = arg->flags; | |
9849 | + | |
9850 | + wkq_err = au_wkq_wait(call_do_test_empty, &args); | |
9851 | + if (unlikely(wkq_err)) | |
9852 | + err = wkq_err; | |
9853 | + arg->flags = flags; | |
9854 | + } | |
9855 | + | |
9856 | + return err; | |
9857 | +} | |
9858 | + | |
9859 | +int au_test_empty_lower(struct dentry *dentry) | |
9860 | +{ | |
9861 | + int err; | |
1308ab2a | 9862 | + unsigned int rdhash; |
1facf9fc | 9863 | + aufs_bindex_t bindex, bstart, btail; |
1308ab2a | 9864 | + struct au_nhash whlist; |
392086de AM |
9865 | + struct test_empty_arg arg = { |
9866 | + .ctx = { | |
9867 | + .actor = au_diractor(test_empty_cb) | |
9868 | + } | |
9869 | + }; | |
076b876e | 9870 | + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg); |
1facf9fc | 9871 | + |
dece6358 AM |
9872 | + SiMustAnyLock(dentry->d_sb); |
9873 | + | |
1308ab2a | 9874 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; |
9875 | + if (!rdhash) | |
9876 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry)); | |
9877 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
dece6358 | 9878 | + if (unlikely(err)) |
1facf9fc | 9879 | + goto out; |
9880 | + | |
1facf9fc | 9881 | + arg.flags = 0; |
1308ab2a | 9882 | + arg.whlist = &whlist; |
9883 | + bstart = au_dbstart(dentry); | |
dece6358 AM |
9884 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
9885 | + au_fset_testempty(arg.flags, SHWH); | |
076b876e AM |
9886 | + test_empty = do_test_empty; |
9887 | + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)) | |
9888 | + test_empty = sio_test_empty; | |
1facf9fc | 9889 | + arg.bindex = bstart; |
076b876e | 9890 | + err = test_empty(dentry, &arg); |
1facf9fc | 9891 | + if (unlikely(err)) |
9892 | + goto out_whlist; | |
9893 | + | |
9894 | + au_fset_testempty(arg.flags, WHONLY); | |
9895 | + btail = au_dbtaildir(dentry); | |
9896 | + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) { | |
9897 | + struct dentry *h_dentry; | |
9898 | + | |
9899 | + h_dentry = au_h_dptr(dentry, bindex); | |
9900 | + if (h_dentry && h_dentry->d_inode) { | |
9901 | + arg.bindex = bindex; | |
076b876e | 9902 | + err = test_empty(dentry, &arg); |
1facf9fc | 9903 | + } |
9904 | + } | |
9905 | + | |
4f0767ce | 9906 | +out_whlist: |
1308ab2a | 9907 | + au_nhash_wh_free(&whlist); |
4f0767ce | 9908 | +out: |
1facf9fc | 9909 | + return err; |
9910 | +} | |
9911 | + | |
9912 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist) | |
9913 | +{ | |
9914 | + int err; | |
392086de AM |
9915 | + struct test_empty_arg arg = { |
9916 | + .ctx = { | |
9917 | + .actor = au_diractor(test_empty_cb) | |
9918 | + } | |
9919 | + }; | |
1facf9fc | 9920 | + aufs_bindex_t bindex, btail; |
9921 | + | |
9922 | + err = 0; | |
1308ab2a | 9923 | + arg.whlist = whlist; |
1facf9fc | 9924 | + arg.flags = AuTestEmpty_WHONLY; |
dece6358 AM |
9925 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
9926 | + au_fset_testempty(arg.flags, SHWH); | |
1facf9fc | 9927 | + btail = au_dbtaildir(dentry); |
9928 | + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) { | |
9929 | + struct dentry *h_dentry; | |
9930 | + | |
9931 | + h_dentry = au_h_dptr(dentry, bindex); | |
9932 | + if (h_dentry && h_dentry->d_inode) { | |
9933 | + arg.bindex = bindex; | |
9934 | + err = sio_test_empty(dentry, &arg); | |
9935 | + } | |
9936 | + } | |
9937 | + | |
9938 | + return err; | |
9939 | +} | |
9940 | + | |
9941 | +/* ---------------------------------------------------------------------- */ | |
9942 | + | |
9943 | +const struct file_operations aufs_dir_fop = { | |
4a4d8108 | 9944 | + .owner = THIS_MODULE, |
027c5e7a | 9945 | + .llseek = default_llseek, |
1facf9fc | 9946 | + .read = generic_read_dir, |
392086de | 9947 | + .iterate = aufs_iterate, |
1facf9fc | 9948 | + .unlocked_ioctl = aufs_ioctl_dir, |
b752ccd1 AM |
9949 | +#ifdef CONFIG_COMPAT |
9950 | + .compat_ioctl = aufs_compat_ioctl_dir, | |
9951 | +#endif | |
1facf9fc | 9952 | + .open = aufs_open_dir, |
9953 | + .release = aufs_release_dir, | |
4a4d8108 | 9954 | + .flush = aufs_flush_dir, |
1facf9fc | 9955 | + .fsync = aufs_fsync_dir |
9956 | +}; | |
7f207e10 AM |
9957 | diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h |
9958 | --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
9959 | +++ linux/fs/aufs/dir.h 2015-01-25 13:00:38.631047076 +0100 |
9960 | @@ -0,0 +1,130 @@ | |
1facf9fc | 9961 | +/* |
523b37e3 | 9962 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 9963 | + * |
9964 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9965 | + * it under the terms of the GNU General Public License as published by | |
9966 | + * the Free Software Foundation; either version 2 of the License, or | |
9967 | + * (at your option) any later version. | |
dece6358 AM |
9968 | + * |
9969 | + * This program is distributed in the hope that it will be useful, | |
9970 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9971 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9972 | + * GNU General Public License for more details. | |
9973 | + * | |
9974 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9975 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9976 | + */ |
9977 | + | |
9978 | +/* | |
9979 | + * directory operations | |
9980 | + */ | |
9981 | + | |
9982 | +#ifndef __AUFS_DIR_H__ | |
9983 | +#define __AUFS_DIR_H__ | |
9984 | + | |
9985 | +#ifdef __KERNEL__ | |
9986 | + | |
9987 | +#include <linux/fs.h> | |
1facf9fc | 9988 | + |
9989 | +/* ---------------------------------------------------------------------- */ | |
9990 | + | |
9991 | +/* need to be faster and smaller */ | |
9992 | + | |
9993 | +struct au_nhash { | |
dece6358 AM |
9994 | + unsigned int nh_num; |
9995 | + struct hlist_head *nh_head; | |
1facf9fc | 9996 | +}; |
9997 | + | |
9998 | +struct au_vdir_destr { | |
9999 | + unsigned char len; | |
10000 | + unsigned char name[0]; | |
10001 | +} __packed; | |
10002 | + | |
10003 | +struct au_vdir_dehstr { | |
10004 | + struct hlist_node hash; | |
10005 | + struct au_vdir_destr *str; | |
4a4d8108 | 10006 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10007 | + |
10008 | +struct au_vdir_de { | |
10009 | + ino_t de_ino; | |
10010 | + unsigned char de_type; | |
10011 | + /* caution: packed */ | |
10012 | + struct au_vdir_destr de_str; | |
10013 | +} __packed; | |
10014 | + | |
10015 | +struct au_vdir_wh { | |
10016 | + struct hlist_node wh_hash; | |
dece6358 AM |
10017 | +#ifdef CONFIG_AUFS_SHWH |
10018 | + ino_t wh_ino; | |
1facf9fc | 10019 | + aufs_bindex_t wh_bindex; |
dece6358 AM |
10020 | + unsigned char wh_type; |
10021 | +#else | |
10022 | + aufs_bindex_t wh_bindex; | |
10023 | +#endif | |
10024 | + /* caution: packed */ | |
1facf9fc | 10025 | + struct au_vdir_destr wh_str; |
10026 | +} __packed; | |
10027 | + | |
10028 | +union au_vdir_deblk_p { | |
10029 | + unsigned char *deblk; | |
10030 | + struct au_vdir_de *de; | |
10031 | +}; | |
10032 | + | |
10033 | +struct au_vdir { | |
10034 | + unsigned char **vd_deblk; | |
10035 | + unsigned long vd_nblk; | |
1facf9fc | 10036 | + struct { |
10037 | + unsigned long ul; | |
10038 | + union au_vdir_deblk_p p; | |
10039 | + } vd_last; | |
10040 | + | |
10041 | + unsigned long vd_version; | |
dece6358 | 10042 | + unsigned int vd_deblk_sz; |
1facf9fc | 10043 | + unsigned long vd_jiffy; |
4a4d8108 | 10044 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10045 | + |
10046 | +/* ---------------------------------------------------------------------- */ | |
10047 | + | |
10048 | +/* dir.c */ | |
10049 | +extern const struct file_operations aufs_dir_fop; | |
10050 | +void au_add_nlink(struct inode *dir, struct inode *h_dir); | |
10051 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir); | |
1308ab2a | 10052 | +loff_t au_dir_size(struct file *file, struct dentry *dentry); |
1facf9fc | 10053 | +int au_test_empty_lower(struct dentry *dentry); |
10054 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist); | |
10055 | + | |
10056 | +/* vdir.c */ | |
1308ab2a | 10057 | +unsigned int au_rdhash_est(loff_t sz); |
dece6358 AM |
10058 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp); |
10059 | +void au_nhash_wh_free(struct au_nhash *whlist); | |
1facf9fc | 10060 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, |
10061 | + int limit); | |
dece6358 AM |
10062 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen); |
10063 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
10064 | + unsigned int d_type, aufs_bindex_t bindex, | |
10065 | + unsigned char shwh); | |
1facf9fc | 10066 | +void au_vdir_free(struct au_vdir *vdir); |
10067 | +int au_vdir_init(struct file *file); | |
392086de | 10068 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx); |
1facf9fc | 10069 | + |
10070 | +/* ioctl.c */ | |
10071 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg); | |
10072 | + | |
1308ab2a | 10073 | +#ifdef CONFIG_AUFS_RDU |
10074 | +/* rdu.c */ | |
10075 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
10076 | +#ifdef CONFIG_COMPAT |
10077 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, | |
10078 | + unsigned long arg); | |
10079 | +#endif | |
1308ab2a | 10080 | +#else |
c1595e42 JR |
10081 | +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file, |
10082 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10083 | +#ifdef CONFIG_COMPAT |
c1595e42 JR |
10084 | +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file, |
10085 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10086 | +#endif |
1308ab2a | 10087 | +#endif |
10088 | + | |
1facf9fc | 10089 | +#endif /* __KERNEL__ */ |
10090 | +#endif /* __AUFS_DIR_H__ */ | |
7f207e10 AM |
10091 | diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c |
10092 | --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 10093 | +++ linux/fs/aufs/dynop.c 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 10094 | @@ -0,0 +1,379 @@ |
1facf9fc | 10095 | +/* |
523b37e3 | 10096 | + * Copyright (C) 2010-2014 Junjiro R. Okajima |
1facf9fc | 10097 | + * |
10098 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10099 | + * it under the terms of the GNU General Public License as published by | |
10100 | + * the Free Software Foundation; either version 2 of the License, or | |
10101 | + * (at your option) any later version. | |
dece6358 AM |
10102 | + * |
10103 | + * This program is distributed in the hope that it will be useful, | |
10104 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10105 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10106 | + * GNU General Public License for more details. | |
10107 | + * | |
10108 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10109 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10110 | + */ |
10111 | + | |
10112 | +/* | |
4a4d8108 | 10113 | + * dynamically customizable operations for regular files |
1facf9fc | 10114 | + */ |
10115 | + | |
1facf9fc | 10116 | +#include "aufs.h" |
10117 | + | |
4a4d8108 | 10118 | +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop) |
1facf9fc | 10119 | + |
4a4d8108 AM |
10120 | +/* |
10121 | + * How large will these lists be? | |
10122 | + * Usually just a few elements, 20-30 at most for each, I guess. | |
10123 | + */ | |
10124 | +static struct au_splhead dynop[AuDyLast]; | |
10125 | + | |
10126 | +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op) | |
1facf9fc | 10127 | +{ |
4a4d8108 AM |
10128 | + struct au_dykey *key, *tmp; |
10129 | + struct list_head *head; | |
1facf9fc | 10130 | + |
4a4d8108 AM |
10131 | + key = NULL; |
10132 | + head = &spl->head; | |
10133 | + rcu_read_lock(); | |
10134 | + list_for_each_entry_rcu(tmp, head, dk_list) | |
10135 | + if (tmp->dk_op.dy_hop == h_op) { | |
10136 | + key = tmp; | |
10137 | + kref_get(&key->dk_kref); | |
10138 | + break; | |
10139 | + } | |
10140 | + rcu_read_unlock(); | |
10141 | + | |
10142 | + return key; | |
1facf9fc | 10143 | +} |
10144 | + | |
4a4d8108 | 10145 | +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key) |
1facf9fc | 10146 | +{ |
4a4d8108 AM |
10147 | + struct au_dykey **k, *found; |
10148 | + const void *h_op = key->dk_op.dy_hop; | |
10149 | + int i; | |
1facf9fc | 10150 | + |
4a4d8108 AM |
10151 | + found = NULL; |
10152 | + k = br->br_dykey; | |
10153 | + for (i = 0; i < AuBrDynOp; i++) | |
10154 | + if (k[i]) { | |
10155 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10156 | + found = k[i]; | |
10157 | + break; | |
10158 | + } | |
10159 | + } else | |
10160 | + break; | |
10161 | + if (!found) { | |
10162 | + spin_lock(&br->br_dykey_lock); | |
10163 | + for (; i < AuBrDynOp; i++) | |
10164 | + if (k[i]) { | |
10165 | + if (k[i]->dk_op.dy_hop == h_op) { | |
10166 | + found = k[i]; | |
10167 | + break; | |
10168 | + } | |
10169 | + } else { | |
10170 | + k[i] = key; | |
10171 | + break; | |
10172 | + } | |
10173 | + spin_unlock(&br->br_dykey_lock); | |
10174 | + BUG_ON(i == AuBrDynOp); /* expand the array */ | |
10175 | + } | |
10176 | + | |
10177 | + return found; | |
1facf9fc | 10178 | +} |
10179 | + | |
4a4d8108 AM |
10180 | +/* kref_get() if @key is already added */ |
10181 | +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key) | |
10182 | +{ | |
10183 | + struct au_dykey *tmp, *found; | |
10184 | + struct list_head *head; | |
10185 | + const void *h_op = key->dk_op.dy_hop; | |
1facf9fc | 10186 | + |
4a4d8108 AM |
10187 | + found = NULL; |
10188 | + head = &spl->head; | |
10189 | + spin_lock(&spl->spin); | |
10190 | + list_for_each_entry(tmp, head, dk_list) | |
10191 | + if (tmp->dk_op.dy_hop == h_op) { | |
10192 | + kref_get(&tmp->dk_kref); | |
10193 | + found = tmp; | |
10194 | + break; | |
10195 | + } | |
10196 | + if (!found) | |
10197 | + list_add_rcu(&key->dk_list, head); | |
10198 | + spin_unlock(&spl->spin); | |
1facf9fc | 10199 | + |
4a4d8108 AM |
10200 | + if (!found) |
10201 | + DyPrSym(key); | |
10202 | + return found; | |
10203 | +} | |
10204 | + | |
10205 | +static void dy_free_rcu(struct rcu_head *rcu) | |
1facf9fc | 10206 | +{ |
4a4d8108 AM |
10207 | + struct au_dykey *key; |
10208 | + | |
10209 | + key = container_of(rcu, struct au_dykey, dk_rcu); | |
10210 | + DyPrSym(key); | |
10211 | + kfree(key); | |
1facf9fc | 10212 | +} |
10213 | + | |
4a4d8108 AM |
10214 | +static void dy_free(struct kref *kref) |
10215 | +{ | |
10216 | + struct au_dykey *key; | |
10217 | + struct au_splhead *spl; | |
1facf9fc | 10218 | + |
4a4d8108 AM |
10219 | + key = container_of(kref, struct au_dykey, dk_kref); |
10220 | + spl = dynop + key->dk_op.dy_type; | |
10221 | + au_spl_del_rcu(&key->dk_list, spl); | |
10222 | + call_rcu(&key->dk_rcu, dy_free_rcu); | |
10223 | +} | |
10224 | + | |
10225 | +void au_dy_put(struct au_dykey *key) | |
1facf9fc | 10226 | +{ |
4a4d8108 AM |
10227 | + kref_put(&key->dk_kref, dy_free); |
10228 | +} | |
1facf9fc | 10229 | + |
4a4d8108 AM |
10230 | +/* ---------------------------------------------------------------------- */ |
10231 | + | |
10232 | +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *)) | |
10233 | + | |
10234 | +#ifdef CONFIG_AUFS_DEBUG | |
10235 | +#define DyDbgDeclare(cnt) unsigned int cnt = 0 | |
4f0767ce | 10236 | +#define DyDbgInc(cnt) do { cnt++; } while (0) |
4a4d8108 AM |
10237 | +#else |
10238 | +#define DyDbgDeclare(cnt) do {} while (0) | |
10239 | +#define DyDbgInc(cnt) do {} while (0) | |
10240 | +#endif | |
10241 | + | |
10242 | +#define DySet(func, dst, src, h_op, h_sb) do { \ | |
10243 | + DyDbgInc(cnt); \ | |
10244 | + if (h_op->func) { \ | |
10245 | + if (src.func) \ | |
10246 | + dst.func = src.func; \ | |
10247 | + else \ | |
10248 | + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \ | |
10249 | + } \ | |
10250 | +} while (0) | |
10251 | + | |
10252 | +#define DySetForce(func, dst, src) do { \ | |
10253 | + AuDebugOn(!src.func); \ | |
10254 | + DyDbgInc(cnt); \ | |
10255 | + dst.func = src.func; \ | |
10256 | +} while (0) | |
10257 | + | |
10258 | +#define DySetAop(func) \ | |
10259 | + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb) | |
10260 | +#define DySetAopForce(func) \ | |
10261 | + DySetForce(func, dyaop->da_op, aufs_aop) | |
10262 | + | |
10263 | +static void dy_aop(struct au_dykey *key, const void *h_op, | |
10264 | + struct super_block *h_sb __maybe_unused) | |
10265 | +{ | |
10266 | + struct au_dyaop *dyaop = (void *)key; | |
10267 | + const struct address_space_operations *h_aop = h_op; | |
10268 | + DyDbgDeclare(cnt); | |
10269 | + | |
10270 | + AuDbg("%s\n", au_sbtype(h_sb)); | |
10271 | + | |
10272 | + DySetAop(writepage); | |
10273 | + DySetAopForce(readpage); /* force */ | |
4a4d8108 AM |
10274 | + DySetAop(writepages); |
10275 | + DySetAop(set_page_dirty); | |
10276 | + DySetAop(readpages); | |
10277 | + DySetAop(write_begin); | |
10278 | + DySetAop(write_end); | |
10279 | + DySetAop(bmap); | |
10280 | + DySetAop(invalidatepage); | |
10281 | + DySetAop(releasepage); | |
027c5e7a | 10282 | + DySetAop(freepage); |
4a4d8108 AM |
10283 | + /* these two will be changed according to an aufs mount option */ |
10284 | + DySetAop(direct_IO); | |
10285 | + DySetAop(get_xip_mem); | |
10286 | + DySetAop(migratepage); | |
10287 | + DySetAop(launder_page); | |
10288 | + DySetAop(is_partially_uptodate); | |
392086de | 10289 | + DySetAop(is_dirty_writeback); |
4a4d8108 | 10290 | + DySetAop(error_remove_page); |
b4510431 AM |
10291 | + DySetAop(swap_activate); |
10292 | + DySetAop(swap_deactivate); | |
4a4d8108 AM |
10293 | + |
10294 | + DyDbgSize(cnt, *h_aop); | |
10295 | + dyaop->da_get_xip_mem = h_aop->get_xip_mem; | |
10296 | +} | |
10297 | + | |
4a4d8108 AM |
10298 | +/* ---------------------------------------------------------------------- */ |
10299 | + | |
10300 | +static void dy_bug(struct kref *kref) | |
10301 | +{ | |
10302 | + BUG(); | |
10303 | +} | |
10304 | + | |
10305 | +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br) | |
10306 | +{ | |
10307 | + struct au_dykey *key, *old; | |
10308 | + struct au_splhead *spl; | |
b752ccd1 | 10309 | + struct op { |
4a4d8108 | 10310 | + unsigned int sz; |
b752ccd1 AM |
10311 | + void (*set)(struct au_dykey *key, const void *h_op, |
10312 | + struct super_block *h_sb __maybe_unused); | |
10313 | + }; | |
10314 | + static const struct op a[] = { | |
4a4d8108 AM |
10315 | + [AuDy_AOP] = { |
10316 | + .sz = sizeof(struct au_dyaop), | |
b752ccd1 | 10317 | + .set = dy_aop |
4a4d8108 | 10318 | + } |
b752ccd1 AM |
10319 | + }; |
10320 | + const struct op *p; | |
4a4d8108 AM |
10321 | + |
10322 | + spl = dynop + op->dy_type; | |
10323 | + key = dy_gfind_get(spl, op->dy_hop); | |
10324 | + if (key) | |
10325 | + goto out_add; /* success */ | |
10326 | + | |
10327 | + p = a + op->dy_type; | |
10328 | + key = kzalloc(p->sz, GFP_NOFS); | |
10329 | + if (unlikely(!key)) { | |
10330 | + key = ERR_PTR(-ENOMEM); | |
10331 | + goto out; | |
10332 | + } | |
10333 | + | |
10334 | + key->dk_op.dy_hop = op->dy_hop; | |
10335 | + kref_init(&key->dk_kref); | |
86dc4139 | 10336 | + p->set(key, op->dy_hop, au_br_sb(br)); |
4a4d8108 AM |
10337 | + old = dy_gadd(spl, key); |
10338 | + if (old) { | |
10339 | + kfree(key); | |
10340 | + key = old; | |
10341 | + } | |
10342 | + | |
10343 | +out_add: | |
10344 | + old = dy_bradd(br, key); | |
10345 | + if (old) | |
10346 | + /* its ref-count should never be zero here */ | |
10347 | + kref_put(&key->dk_kref, dy_bug); | |
10348 | +out: | |
10349 | + return key; | |
10350 | +} | |
10351 | + | |
10352 | +/* ---------------------------------------------------------------------- */ | |
10353 | +/* | |
10354 | + * Aufs prohibits O_DIRECT by defaut even if the branch supports it. | |
c1595e42 | 10355 | + * This behaviour is necessary to return an error from open(O_DIRECT) instead |
4a4d8108 AM |
10356 | + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes |
10357 | + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error. | |
10358 | + * See the aufs manual in detail. | |
10359 | + * | |
10360 | + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the | |
10361 | + * performance of fadvise() and madvise() may be affected. | |
10362 | + */ | |
10363 | +static void dy_adx(struct au_dyaop *dyaop, int do_dx) | |
10364 | +{ | |
10365 | + if (!do_dx) { | |
10366 | + dyaop->da_op.direct_IO = NULL; | |
10367 | + dyaop->da_op.get_xip_mem = NULL; | |
10368 | + } else { | |
10369 | + dyaop->da_op.direct_IO = aufs_aop.direct_IO; | |
10370 | + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem; | |
10371 | + if (!dyaop->da_get_xip_mem) | |
10372 | + dyaop->da_op.get_xip_mem = NULL; | |
10373 | + } | |
10374 | +} | |
10375 | + | |
10376 | +static struct au_dyaop *dy_aget(struct au_branch *br, | |
10377 | + const struct address_space_operations *h_aop, | |
10378 | + int do_dx) | |
10379 | +{ | |
10380 | + struct au_dyaop *dyaop; | |
10381 | + struct au_dynop op; | |
10382 | + | |
10383 | + op.dy_type = AuDy_AOP; | |
10384 | + op.dy_haop = h_aop; | |
10385 | + dyaop = (void *)dy_get(&op, br); | |
10386 | + if (IS_ERR(dyaop)) | |
10387 | + goto out; | |
10388 | + dy_adx(dyaop, do_dx); | |
10389 | + | |
10390 | +out: | |
10391 | + return dyaop; | |
10392 | +} | |
10393 | + | |
10394 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
10395 | + struct inode *h_inode) | |
10396 | +{ | |
10397 | + int err, do_dx; | |
10398 | + struct super_block *sb; | |
10399 | + struct au_branch *br; | |
10400 | + struct au_dyaop *dyaop; | |
10401 | + | |
10402 | + AuDebugOn(!S_ISREG(h_inode->i_mode)); | |
10403 | + IiMustWriteLock(inode); | |
10404 | + | |
10405 | + sb = inode->i_sb; | |
10406 | + br = au_sbr(sb, bindex); | |
10407 | + do_dx = !!au_opt_test(au_mntflags(sb), DIO); | |
10408 | + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx); | |
10409 | + err = PTR_ERR(dyaop); | |
10410 | + if (IS_ERR(dyaop)) | |
10411 | + /* unnecessary to call dy_fput() */ | |
10412 | + goto out; | |
10413 | + | |
10414 | + err = 0; | |
10415 | + inode->i_mapping->a_ops = &dyaop->da_op; | |
10416 | + | |
10417 | +out: | |
10418 | + return err; | |
10419 | +} | |
10420 | + | |
b752ccd1 AM |
10421 | +/* |
10422 | + * Is it safe to replace a_ops during the inode/file is in operation? | |
10423 | + * Yes, I hope so. | |
10424 | + */ | |
10425 | +int au_dy_irefresh(struct inode *inode) | |
10426 | +{ | |
10427 | + int err; | |
10428 | + aufs_bindex_t bstart; | |
10429 | + struct inode *h_inode; | |
10430 | + | |
10431 | + err = 0; | |
10432 | + if (S_ISREG(inode->i_mode)) { | |
10433 | + bstart = au_ibstart(inode); | |
10434 | + h_inode = au_h_iptr(inode, bstart); | |
10435 | + err = au_dy_iaop(inode, bstart, h_inode); | |
10436 | + } | |
10437 | + return err; | |
10438 | +} | |
10439 | + | |
4a4d8108 AM |
10440 | +void au_dy_arefresh(int do_dx) |
10441 | +{ | |
10442 | + struct au_splhead *spl; | |
10443 | + struct list_head *head; | |
10444 | + struct au_dykey *key; | |
10445 | + | |
10446 | + spl = dynop + AuDy_AOP; | |
10447 | + head = &spl->head; | |
10448 | + spin_lock(&spl->spin); | |
10449 | + list_for_each_entry(key, head, dk_list) | |
10450 | + dy_adx((void *)key, do_dx); | |
10451 | + spin_unlock(&spl->spin); | |
10452 | +} | |
10453 | + | |
4a4d8108 AM |
10454 | +/* ---------------------------------------------------------------------- */ |
10455 | + | |
10456 | +void __init au_dy_init(void) | |
10457 | +{ | |
10458 | + int i; | |
10459 | + | |
10460 | + /* make sure that 'struct au_dykey *' can be any type */ | |
10461 | + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key)); | |
4a4d8108 AM |
10462 | + |
10463 | + for (i = 0; i < AuDyLast; i++) | |
10464 | + au_spl_init(dynop + i); | |
10465 | +} | |
10466 | + | |
10467 | +void au_dy_fin(void) | |
10468 | +{ | |
10469 | + int i; | |
10470 | + | |
10471 | + for (i = 0; i < AuDyLast; i++) | |
10472 | + WARN_ON(!list_empty(&dynop[i].head)); | |
10473 | +} | |
7f207e10 AM |
10474 | diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h |
10475 | --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 10476 | +++ linux/fs/aufs/dynop.h 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 10477 | @@ -0,0 +1,75 @@ |
4a4d8108 | 10478 | +/* |
523b37e3 | 10479 | + * Copyright (C) 2010-2014 Junjiro R. Okajima |
4a4d8108 AM |
10480 | + * |
10481 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10482 | + * it under the terms of the GNU General Public License as published by | |
10483 | + * the Free Software Foundation; either version 2 of the License, or | |
10484 | + * (at your option) any later version. | |
10485 | + * | |
10486 | + * This program is distributed in the hope that it will be useful, | |
10487 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10488 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10489 | + * GNU General Public License for more details. | |
10490 | + * | |
10491 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10492 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
10493 | + */ |
10494 | + | |
10495 | +/* | |
10496 | + * dynamically customizable operations (for regular files only) | |
10497 | + */ | |
10498 | + | |
10499 | +#ifndef __AUFS_DYNOP_H__ | |
10500 | +#define __AUFS_DYNOP_H__ | |
10501 | + | |
10502 | +#ifdef __KERNEL__ | |
10503 | + | |
4a4d8108 AM |
10504 | +#include "inode.h" |
10505 | + | |
2cbb1c4b | 10506 | +enum {AuDy_AOP, AuDyLast}; |
4a4d8108 AM |
10507 | + |
10508 | +struct au_dynop { | |
10509 | + int dy_type; | |
10510 | + union { | |
10511 | + const void *dy_hop; | |
10512 | + const struct address_space_operations *dy_haop; | |
4a4d8108 AM |
10513 | + }; |
10514 | +}; | |
10515 | + | |
10516 | +struct au_dykey { | |
10517 | + union { | |
10518 | + struct list_head dk_list; | |
10519 | + struct rcu_head dk_rcu; | |
10520 | + }; | |
10521 | + struct au_dynop dk_op; | |
10522 | + | |
10523 | + /* | |
10524 | + * during I am in the branch local array, kref is gotten. when the | |
10525 | + * branch is removed, kref is put. | |
10526 | + */ | |
10527 | + struct kref dk_kref; | |
10528 | +}; | |
10529 | + | |
10530 | +/* stop unioning since their sizes are very different from each other */ | |
10531 | +struct au_dyaop { | |
10532 | + struct au_dykey da_key; | |
10533 | + struct address_space_operations da_op; /* not const */ | |
10534 | + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int, | |
10535 | + void **, unsigned long *); | |
10536 | +}; | |
10537 | + | |
4a4d8108 AM |
10538 | +/* ---------------------------------------------------------------------- */ |
10539 | + | |
10540 | +/* dynop.c */ | |
10541 | +struct au_branch; | |
10542 | +void au_dy_put(struct au_dykey *key); | |
10543 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
10544 | + struct inode *h_inode); | |
b752ccd1 | 10545 | +int au_dy_irefresh(struct inode *inode); |
4a4d8108 | 10546 | +void au_dy_arefresh(int do_dio); |
4a4d8108 AM |
10547 | + |
10548 | +void __init au_dy_init(void); | |
10549 | +void au_dy_fin(void); | |
10550 | + | |
4a4d8108 AM |
10551 | +#endif /* __KERNEL__ */ |
10552 | +#endif /* __AUFS_DYNOP_H__ */ | |
7f207e10 AM |
10553 | diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c |
10554 | --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 10555 | +++ linux/fs/aufs/export.c 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 10556 | @@ -0,0 +1,831 @@ |
4a4d8108 | 10557 | +/* |
523b37e3 | 10558 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
10559 | + * |
10560 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10561 | + * it under the terms of the GNU General Public License as published by | |
10562 | + * the Free Software Foundation; either version 2 of the License, or | |
10563 | + * (at your option) any later version. | |
10564 | + * | |
10565 | + * This program is distributed in the hope that it will be useful, | |
10566 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10567 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10568 | + * GNU General Public License for more details. | |
10569 | + * | |
10570 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10571 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
10572 | + */ |
10573 | + | |
10574 | +/* | |
10575 | + * export via nfs | |
10576 | + */ | |
10577 | + | |
10578 | +#include <linux/exportfs.h> | |
7eafdf33 | 10579 | +#include <linux/fs_struct.h> |
4a4d8108 AM |
10580 | +#include <linux/namei.h> |
10581 | +#include <linux/nsproxy.h> | |
10582 | +#include <linux/random.h> | |
10583 | +#include <linux/writeback.h> | |
7eafdf33 | 10584 | +#include "../fs/mount.h" |
4a4d8108 AM |
10585 | +#include "aufs.h" |
10586 | + | |
10587 | +union conv { | |
10588 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10589 | + __u32 a[2]; | |
10590 | +#else | |
10591 | + __u32 a[1]; | |
10592 | +#endif | |
10593 | + ino_t ino; | |
10594 | +}; | |
10595 | + | |
10596 | +static ino_t decode_ino(__u32 *a) | |
10597 | +{ | |
10598 | + union conv u; | |
10599 | + | |
10600 | + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a)); | |
10601 | + u.a[0] = a[0]; | |
10602 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10603 | + u.a[1] = a[1]; | |
10604 | +#endif | |
10605 | + return u.ino; | |
10606 | +} | |
10607 | + | |
10608 | +static void encode_ino(__u32 *a, ino_t ino) | |
10609 | +{ | |
10610 | + union conv u; | |
10611 | + | |
10612 | + u.ino = ino; | |
10613 | + a[0] = u.a[0]; | |
10614 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10615 | + a[1] = u.a[1]; | |
10616 | +#endif | |
10617 | +} | |
10618 | + | |
10619 | +/* NFS file handle */ | |
10620 | +enum { | |
10621 | + Fh_br_id, | |
10622 | + Fh_sigen, | |
10623 | +#ifdef CONFIG_AUFS_INO_T_64 | |
10624 | + /* support 64bit inode number */ | |
10625 | + Fh_ino1, | |
10626 | + Fh_ino2, | |
10627 | + Fh_dir_ino1, | |
10628 | + Fh_dir_ino2, | |
10629 | +#else | |
10630 | + Fh_ino1, | |
10631 | + Fh_dir_ino1, | |
10632 | +#endif | |
10633 | + Fh_igen, | |
10634 | + Fh_h_type, | |
10635 | + Fh_tail, | |
10636 | + | |
10637 | + Fh_ino = Fh_ino1, | |
10638 | + Fh_dir_ino = Fh_dir_ino1 | |
10639 | +}; | |
10640 | + | |
10641 | +static int au_test_anon(struct dentry *dentry) | |
10642 | +{ | |
027c5e7a | 10643 | + /* note: read d_flags without d_lock */ |
4a4d8108 AM |
10644 | + return !!(dentry->d_flags & DCACHE_DISCONNECTED); |
10645 | +} | |
10646 | + | |
a2a7ad62 AM |
10647 | +int au_test_nfsd(void) |
10648 | +{ | |
10649 | + int ret; | |
10650 | + struct task_struct *tsk = current; | |
10651 | + char comm[sizeof(tsk->comm)]; | |
10652 | + | |
10653 | + ret = 0; | |
10654 | + if (tsk->flags & PF_KTHREAD) { | |
10655 | + get_task_comm(comm, tsk); | |
10656 | + ret = !strcmp(comm, "nfsd"); | |
10657 | + } | |
10658 | + | |
10659 | + return ret; | |
10660 | +} | |
10661 | + | |
4a4d8108 AM |
10662 | +/* ---------------------------------------------------------------------- */ |
10663 | +/* inode generation external table */ | |
10664 | + | |
b752ccd1 | 10665 | +void au_xigen_inc(struct inode *inode) |
4a4d8108 | 10666 | +{ |
4a4d8108 AM |
10667 | + loff_t pos; |
10668 | + ssize_t sz; | |
10669 | + __u32 igen; | |
10670 | + struct super_block *sb; | |
10671 | + struct au_sbinfo *sbinfo; | |
10672 | + | |
4a4d8108 | 10673 | + sb = inode->i_sb; |
b752ccd1 | 10674 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); |
1facf9fc | 10675 | + |
b752ccd1 | 10676 | + sbinfo = au_sbi(sb); |
1facf9fc | 10677 | + pos = inode->i_ino; |
10678 | + pos *= sizeof(igen); | |
10679 | + igen = inode->i_generation + 1; | |
1facf9fc | 10680 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen, |
10681 | + sizeof(igen), &pos); | |
10682 | + if (sz == sizeof(igen)) | |
b752ccd1 | 10683 | + return; /* success */ |
1facf9fc | 10684 | + |
b752ccd1 | 10685 | + if (unlikely(sz >= 0)) |
1facf9fc | 10686 | + AuIOErr("xigen error (%zd)\n", sz); |
1facf9fc | 10687 | +} |
10688 | + | |
10689 | +int au_xigen_new(struct inode *inode) | |
10690 | +{ | |
10691 | + int err; | |
10692 | + loff_t pos; | |
10693 | + ssize_t sz; | |
10694 | + struct super_block *sb; | |
10695 | + struct au_sbinfo *sbinfo; | |
10696 | + struct file *file; | |
10697 | + | |
10698 | + err = 0; | |
10699 | + /* todo: dirty, at mount time */ | |
10700 | + if (inode->i_ino == AUFS_ROOT_INO) | |
10701 | + goto out; | |
10702 | + sb = inode->i_sb; | |
dece6358 | 10703 | + SiMustAnyLock(sb); |
1facf9fc | 10704 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) |
10705 | + goto out; | |
10706 | + | |
10707 | + err = -EFBIG; | |
10708 | + pos = inode->i_ino; | |
10709 | + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) { | |
10710 | + AuIOErr1("too large i%lld\n", pos); | |
10711 | + goto out; | |
10712 | + } | |
10713 | + pos *= sizeof(inode->i_generation); | |
10714 | + | |
10715 | + err = 0; | |
10716 | + sbinfo = au_sbi(sb); | |
10717 | + file = sbinfo->si_xigen; | |
10718 | + BUG_ON(!file); | |
10719 | + | |
c06a8ce3 | 10720 | + if (vfsub_f_size_read(file) |
1facf9fc | 10721 | + < pos + sizeof(inode->i_generation)) { |
10722 | + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next); | |
10723 | + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation, | |
10724 | + sizeof(inode->i_generation), &pos); | |
10725 | + } else | |
10726 | + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation, | |
10727 | + sizeof(inode->i_generation), &pos); | |
10728 | + if (sz == sizeof(inode->i_generation)) | |
10729 | + goto out; /* success */ | |
10730 | + | |
10731 | + err = sz; | |
10732 | + if (unlikely(sz >= 0)) { | |
10733 | + err = -EIO; | |
10734 | + AuIOErr("xigen error (%zd)\n", sz); | |
10735 | + } | |
10736 | + | |
4f0767ce | 10737 | +out: |
1facf9fc | 10738 | + return err; |
10739 | +} | |
10740 | + | |
10741 | +int au_xigen_set(struct super_block *sb, struct file *base) | |
10742 | +{ | |
10743 | + int err; | |
10744 | + struct au_sbinfo *sbinfo; | |
10745 | + struct file *file; | |
10746 | + | |
dece6358 AM |
10747 | + SiMustWriteLock(sb); |
10748 | + | |
1facf9fc | 10749 | + sbinfo = au_sbi(sb); |
10750 | + file = au_xino_create2(base, sbinfo->si_xigen); | |
10751 | + err = PTR_ERR(file); | |
10752 | + if (IS_ERR(file)) | |
10753 | + goto out; | |
10754 | + err = 0; | |
10755 | + if (sbinfo->si_xigen) | |
10756 | + fput(sbinfo->si_xigen); | |
10757 | + sbinfo->si_xigen = file; | |
10758 | + | |
4f0767ce | 10759 | +out: |
1facf9fc | 10760 | + return err; |
10761 | +} | |
10762 | + | |
10763 | +void au_xigen_clr(struct super_block *sb) | |
10764 | +{ | |
10765 | + struct au_sbinfo *sbinfo; | |
10766 | + | |
dece6358 AM |
10767 | + SiMustWriteLock(sb); |
10768 | + | |
1facf9fc | 10769 | + sbinfo = au_sbi(sb); |
10770 | + if (sbinfo->si_xigen) { | |
10771 | + fput(sbinfo->si_xigen); | |
10772 | + sbinfo->si_xigen = NULL; | |
10773 | + } | |
10774 | +} | |
10775 | + | |
10776 | +/* ---------------------------------------------------------------------- */ | |
10777 | + | |
10778 | +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino, | |
10779 | + ino_t dir_ino) | |
10780 | +{ | |
10781 | + struct dentry *dentry, *d; | |
10782 | + struct inode *inode; | |
10783 | + unsigned int sigen; | |
10784 | + | |
10785 | + dentry = NULL; | |
10786 | + inode = ilookup(sb, ino); | |
10787 | + if (!inode) | |
10788 | + goto out; | |
10789 | + | |
10790 | + dentry = ERR_PTR(-ESTALE); | |
10791 | + sigen = au_sigen(sb); | |
10792 | + if (unlikely(is_bad_inode(inode) | |
10793 | + || IS_DEADDIR(inode) | |
537831f9 | 10794 | + || sigen != au_iigen(inode, NULL))) |
1facf9fc | 10795 | + goto out_iput; |
10796 | + | |
10797 | + dentry = NULL; | |
10798 | + if (!dir_ino || S_ISDIR(inode->i_mode)) | |
10799 | + dentry = d_find_alias(inode); | |
10800 | + else { | |
027c5e7a | 10801 | + spin_lock(&inode->i_lock); |
c1595e42 | 10802 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 10803 | + spin_lock(&d->d_lock); |
1facf9fc | 10804 | + if (!au_test_anon(d) |
10805 | + && d->d_parent->d_inode->i_ino == dir_ino) { | |
027c5e7a AM |
10806 | + dentry = dget_dlock(d); |
10807 | + spin_unlock(&d->d_lock); | |
1facf9fc | 10808 | + break; |
10809 | + } | |
027c5e7a AM |
10810 | + spin_unlock(&d->d_lock); |
10811 | + } | |
10812 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 10813 | + } |
027c5e7a | 10814 | + if (unlikely(dentry && au_digen_test(dentry, sigen))) { |
2cbb1c4b | 10815 | + /* need to refresh */ |
1facf9fc | 10816 | + dput(dentry); |
2cbb1c4b | 10817 | + dentry = NULL; |
1facf9fc | 10818 | + } |
10819 | + | |
4f0767ce | 10820 | +out_iput: |
1facf9fc | 10821 | + iput(inode); |
4f0767ce | 10822 | +out: |
2cbb1c4b | 10823 | + AuTraceErrPtr(dentry); |
1facf9fc | 10824 | + return dentry; |
10825 | +} | |
10826 | + | |
10827 | +/* ---------------------------------------------------------------------- */ | |
10828 | + | |
10829 | +/* todo: dirty? */ | |
10830 | +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */ | |
4a4d8108 AM |
10831 | + |
10832 | +struct au_compare_mnt_args { | |
10833 | + /* input */ | |
10834 | + struct super_block *sb; | |
10835 | + | |
10836 | + /* output */ | |
10837 | + struct vfsmount *mnt; | |
10838 | +}; | |
10839 | + | |
10840 | +static int au_compare_mnt(struct vfsmount *mnt, void *arg) | |
10841 | +{ | |
10842 | + struct au_compare_mnt_args *a = arg; | |
10843 | + | |
10844 | + if (mnt->mnt_sb != a->sb) | |
10845 | + return 0; | |
10846 | + a->mnt = mntget(mnt); | |
10847 | + return 1; | |
10848 | +} | |
10849 | + | |
1facf9fc | 10850 | +static struct vfsmount *au_mnt_get(struct super_block *sb) |
10851 | +{ | |
4a4d8108 | 10852 | + int err; |
7eafdf33 | 10853 | + struct path root; |
4a4d8108 AM |
10854 | + struct au_compare_mnt_args args = { |
10855 | + .sb = sb | |
10856 | + }; | |
1facf9fc | 10857 | + |
7eafdf33 | 10858 | + get_fs_root(current->fs, &root); |
523b37e3 | 10859 | + rcu_read_lock(); |
7eafdf33 | 10860 | + err = iterate_mounts(au_compare_mnt, &args, root.mnt); |
523b37e3 | 10861 | + rcu_read_unlock(); |
7eafdf33 | 10862 | + path_put(&root); |
4a4d8108 AM |
10863 | + AuDebugOn(!err); |
10864 | + AuDebugOn(!args.mnt); | |
10865 | + return args.mnt; | |
1facf9fc | 10866 | +} |
10867 | + | |
10868 | +struct au_nfsd_si_lock { | |
4a4d8108 | 10869 | + unsigned int sigen; |
027c5e7a | 10870 | + aufs_bindex_t bindex, br_id; |
1facf9fc | 10871 | + unsigned char force_lock; |
10872 | +}; | |
10873 | + | |
027c5e7a AM |
10874 | +static int si_nfsd_read_lock(struct super_block *sb, |
10875 | + struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 10876 | +{ |
027c5e7a | 10877 | + int err; |
1facf9fc | 10878 | + aufs_bindex_t bindex; |
10879 | + | |
10880 | + si_read_lock(sb, AuLock_FLUSH); | |
10881 | + | |
10882 | + /* branch id may be wrapped around */ | |
027c5e7a | 10883 | + err = 0; |
1facf9fc | 10884 | + bindex = au_br_index(sb, nsi_lock->br_id); |
10885 | + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb)) | |
10886 | + goto out; /* success */ | |
10887 | + | |
027c5e7a AM |
10888 | + err = -ESTALE; |
10889 | + bindex = -1; | |
1facf9fc | 10890 | + if (!nsi_lock->force_lock) |
10891 | + si_read_unlock(sb); | |
1facf9fc | 10892 | + |
4f0767ce | 10893 | +out: |
027c5e7a AM |
10894 | + nsi_lock->bindex = bindex; |
10895 | + return err; | |
1facf9fc | 10896 | +} |
10897 | + | |
10898 | +struct find_name_by_ino { | |
392086de | 10899 | + struct dir_context ctx; |
1facf9fc | 10900 | + int called, found; |
10901 | + ino_t ino; | |
10902 | + char *name; | |
10903 | + int namelen; | |
10904 | +}; | |
10905 | + | |
10906 | +static int | |
392086de AM |
10907 | +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen, |
10908 | + loff_t offset, u64 ino, unsigned int d_type) | |
1facf9fc | 10909 | +{ |
392086de AM |
10910 | + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino, |
10911 | + ctx); | |
1facf9fc | 10912 | + |
10913 | + a->called++; | |
10914 | + if (a->ino != ino) | |
10915 | + return 0; | |
10916 | + | |
10917 | + memcpy(a->name, name, namelen); | |
10918 | + a->namelen = namelen; | |
10919 | + a->found = 1; | |
10920 | + return 1; | |
10921 | +} | |
10922 | + | |
10923 | +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino, | |
10924 | + struct au_nfsd_si_lock *nsi_lock) | |
10925 | +{ | |
10926 | + struct dentry *dentry, *parent; | |
10927 | + struct file *file; | |
10928 | + struct inode *dir; | |
392086de AM |
10929 | + struct find_name_by_ino arg = { |
10930 | + .ctx = { | |
10931 | + .actor = au_diractor(find_name_by_ino) | |
10932 | + } | |
10933 | + }; | |
1facf9fc | 10934 | + int err; |
10935 | + | |
10936 | + parent = path->dentry; | |
10937 | + if (nsi_lock) | |
10938 | + si_read_unlock(parent->d_sb); | |
4a4d8108 | 10939 | + file = vfsub_dentry_open(path, au_dir_roflags); |
1facf9fc | 10940 | + dentry = (void *)file; |
10941 | + if (IS_ERR(file)) | |
10942 | + goto out; | |
10943 | + | |
10944 | + dentry = ERR_PTR(-ENOMEM); | |
537831f9 | 10945 | + arg.name = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 10946 | + if (unlikely(!arg.name)) |
10947 | + goto out_file; | |
10948 | + arg.ino = ino; | |
10949 | + arg.found = 0; | |
10950 | + do { | |
10951 | + arg.called = 0; | |
10952 | + /* smp_mb(); */ | |
392086de | 10953 | + err = vfsub_iterate_dir(file, &arg.ctx); |
1facf9fc | 10954 | + } while (!err && !arg.found && arg.called); |
10955 | + dentry = ERR_PTR(err); | |
10956 | + if (unlikely(err)) | |
10957 | + goto out_name; | |
1716fcea AM |
10958 | + /* instead of ENOENT */ |
10959 | + dentry = ERR_PTR(-ESTALE); | |
1facf9fc | 10960 | + if (!arg.found) |
10961 | + goto out_name; | |
10962 | + | |
b4510431 | 10963 | + /* do not call vfsub_lkup_one() */ |
1facf9fc | 10964 | + dir = parent->d_inode; |
10965 | + mutex_lock(&dir->i_mutex); | |
10966 | + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen); | |
10967 | + mutex_unlock(&dir->i_mutex); | |
10968 | + AuTraceErrPtr(dentry); | |
10969 | + if (IS_ERR(dentry)) | |
10970 | + goto out_name; | |
10971 | + AuDebugOn(au_test_anon(dentry)); | |
10972 | + if (unlikely(!dentry->d_inode)) { | |
10973 | + dput(dentry); | |
10974 | + dentry = ERR_PTR(-ENOENT); | |
10975 | + } | |
10976 | + | |
4f0767ce | 10977 | +out_name: |
537831f9 | 10978 | + free_page((unsigned long)arg.name); |
4f0767ce | 10979 | +out_file: |
1facf9fc | 10980 | + fput(file); |
4f0767ce | 10981 | +out: |
1facf9fc | 10982 | + if (unlikely(nsi_lock |
10983 | + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0)) | |
10984 | + if (!IS_ERR(dentry)) { | |
10985 | + dput(dentry); | |
10986 | + dentry = ERR_PTR(-ESTALE); | |
10987 | + } | |
10988 | + AuTraceErrPtr(dentry); | |
10989 | + return dentry; | |
10990 | +} | |
10991 | + | |
10992 | +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino, | |
10993 | + ino_t dir_ino, | |
10994 | + struct au_nfsd_si_lock *nsi_lock) | |
10995 | +{ | |
10996 | + struct dentry *dentry; | |
10997 | + struct path path; | |
10998 | + | |
10999 | + if (dir_ino != AUFS_ROOT_INO) { | |
11000 | + path.dentry = decode_by_ino(sb, dir_ino, 0); | |
11001 | + dentry = path.dentry; | |
11002 | + if (!path.dentry || IS_ERR(path.dentry)) | |
11003 | + goto out; | |
11004 | + AuDebugOn(au_test_anon(path.dentry)); | |
11005 | + } else | |
11006 | + path.dentry = dget(sb->s_root); | |
11007 | + | |
11008 | + path.mnt = au_mnt_get(sb); | |
11009 | + dentry = au_lkup_by_ino(&path, ino, nsi_lock); | |
11010 | + path_put(&path); | |
11011 | + | |
4f0767ce | 11012 | +out: |
1facf9fc | 11013 | + AuTraceErrPtr(dentry); |
11014 | + return dentry; | |
11015 | +} | |
11016 | + | |
11017 | +/* ---------------------------------------------------------------------- */ | |
11018 | + | |
11019 | +static int h_acceptable(void *expv, struct dentry *dentry) | |
11020 | +{ | |
11021 | + return 1; | |
11022 | +} | |
11023 | + | |
11024 | +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath, | |
11025 | + char *buf, int len, struct super_block *sb) | |
11026 | +{ | |
11027 | + char *p; | |
11028 | + int n; | |
11029 | + struct path path; | |
11030 | + | |
11031 | + p = d_path(h_rootpath, buf, len); | |
11032 | + if (IS_ERR(p)) | |
11033 | + goto out; | |
11034 | + n = strlen(p); | |
11035 | + | |
11036 | + path.mnt = h_rootpath->mnt; | |
11037 | + path.dentry = h_parent; | |
11038 | + p = d_path(&path, buf, len); | |
11039 | + if (IS_ERR(p)) | |
11040 | + goto out; | |
11041 | + if (n != 1) | |
11042 | + p += n; | |
11043 | + | |
11044 | + path.mnt = au_mnt_get(sb); | |
11045 | + path.dentry = sb->s_root; | |
11046 | + p = d_path(&path, buf, len - strlen(p)); | |
11047 | + mntput(path.mnt); | |
11048 | + if (IS_ERR(p)) | |
11049 | + goto out; | |
11050 | + if (n != 1) | |
11051 | + p[strlen(p)] = '/'; | |
11052 | + | |
4f0767ce | 11053 | +out: |
1facf9fc | 11054 | + AuTraceErrPtr(p); |
11055 | + return p; | |
11056 | +} | |
11057 | + | |
11058 | +static | |
027c5e7a AM |
11059 | +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh, |
11060 | + int fh_len, struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 11061 | +{ |
11062 | + struct dentry *dentry, *h_parent, *root; | |
11063 | + struct super_block *h_sb; | |
11064 | + char *pathname, *p; | |
11065 | + struct vfsmount *h_mnt; | |
11066 | + struct au_branch *br; | |
11067 | + int err; | |
11068 | + struct path path; | |
11069 | + | |
027c5e7a | 11070 | + br = au_sbr(sb, nsi_lock->bindex); |
86dc4139 | 11071 | + h_mnt = au_br_mnt(br); |
1facf9fc | 11072 | + h_sb = h_mnt->mnt_sb; |
11073 | + /* todo: call lower fh_to_dentry()? fh_to_parent()? */ | |
11074 | + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail), | |
11075 | + fh_len - Fh_tail, fh[Fh_h_type], | |
11076 | + h_acceptable, /*context*/NULL); | |
11077 | + dentry = h_parent; | |
11078 | + if (unlikely(!h_parent || IS_ERR(h_parent))) { | |
11079 | + AuWarn1("%s decode_fh failed, %ld\n", | |
11080 | + au_sbtype(h_sb), PTR_ERR(h_parent)); | |
11081 | + goto out; | |
11082 | + } | |
11083 | + dentry = NULL; | |
11084 | + if (unlikely(au_test_anon(h_parent))) { | |
11085 | + AuWarn1("%s decode_fh returned a disconnected dentry\n", | |
11086 | + au_sbtype(h_sb)); | |
11087 | + goto out_h_parent; | |
11088 | + } | |
11089 | + | |
11090 | + dentry = ERR_PTR(-ENOMEM); | |
11091 | + pathname = (void *)__get_free_page(GFP_NOFS); | |
11092 | + if (unlikely(!pathname)) | |
11093 | + goto out_h_parent; | |
11094 | + | |
11095 | + root = sb->s_root; | |
11096 | + path.mnt = h_mnt; | |
11097 | + di_read_lock_parent(root, !AuLock_IR); | |
027c5e7a | 11098 | + path.dentry = au_h_dptr(root, nsi_lock->bindex); |
1facf9fc | 11099 | + di_read_unlock(root, !AuLock_IR); |
11100 | + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb); | |
11101 | + dentry = (void *)p; | |
11102 | + if (IS_ERR(p)) | |
11103 | + goto out_pathname; | |
11104 | + | |
11105 | + si_read_unlock(sb); | |
11106 | + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | |
11107 | + dentry = ERR_PTR(err); | |
11108 | + if (unlikely(err)) | |
11109 | + goto out_relock; | |
11110 | + | |
11111 | + dentry = ERR_PTR(-ENOENT); | |
11112 | + AuDebugOn(au_test_anon(path.dentry)); | |
11113 | + if (unlikely(!path.dentry->d_inode)) | |
11114 | + goto out_path; | |
11115 | + | |
11116 | + if (ino != path.dentry->d_inode->i_ino) | |
11117 | + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL); | |
11118 | + else | |
11119 | + dentry = dget(path.dentry); | |
11120 | + | |
4f0767ce | 11121 | +out_path: |
1facf9fc | 11122 | + path_put(&path); |
4f0767ce | 11123 | +out_relock: |
1facf9fc | 11124 | + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0)) |
11125 | + if (!IS_ERR(dentry)) { | |
11126 | + dput(dentry); | |
11127 | + dentry = ERR_PTR(-ESTALE); | |
11128 | + } | |
4f0767ce | 11129 | +out_pathname: |
1facf9fc | 11130 | + free_page((unsigned long)pathname); |
4f0767ce | 11131 | +out_h_parent: |
1facf9fc | 11132 | + dput(h_parent); |
4f0767ce | 11133 | +out: |
1facf9fc | 11134 | + AuTraceErrPtr(dentry); |
11135 | + return dentry; | |
11136 | +} | |
11137 | + | |
11138 | +/* ---------------------------------------------------------------------- */ | |
11139 | + | |
11140 | +static struct dentry * | |
11141 | +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, | |
11142 | + int fh_type) | |
11143 | +{ | |
11144 | + struct dentry *dentry; | |
11145 | + __u32 *fh = fid->raw; | |
027c5e7a | 11146 | + struct au_branch *br; |
1facf9fc | 11147 | + ino_t ino, dir_ino; |
1facf9fc | 11148 | + struct au_nfsd_si_lock nsi_lock = { |
1facf9fc | 11149 | + .force_lock = 0 |
11150 | + }; | |
11151 | + | |
1facf9fc | 11152 | + dentry = ERR_PTR(-ESTALE); |
4a4d8108 AM |
11153 | + /* it should never happen, but the file handle is unreliable */ |
11154 | + if (unlikely(fh_len < Fh_tail)) | |
11155 | + goto out; | |
11156 | + nsi_lock.sigen = fh[Fh_sigen]; | |
11157 | + nsi_lock.br_id = fh[Fh_br_id]; | |
11158 | + | |
1facf9fc | 11159 | + /* branch id may be wrapped around */ |
027c5e7a AM |
11160 | + br = NULL; |
11161 | + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock))) | |
1facf9fc | 11162 | + goto out; |
11163 | + nsi_lock.force_lock = 1; | |
11164 | + | |
11165 | + /* is this inode still cached? */ | |
11166 | + ino = decode_ino(fh + Fh_ino); | |
4a4d8108 AM |
11167 | + /* it should never happen */ |
11168 | + if (unlikely(ino == AUFS_ROOT_INO)) | |
11169 | + goto out; | |
11170 | + | |
1facf9fc | 11171 | + dir_ino = decode_ino(fh + Fh_dir_ino); |
11172 | + dentry = decode_by_ino(sb, ino, dir_ino); | |
11173 | + if (IS_ERR(dentry)) | |
11174 | + goto out_unlock; | |
11175 | + if (dentry) | |
11176 | + goto accept; | |
11177 | + | |
11178 | + /* is the parent dir cached? */ | |
027c5e7a AM |
11179 | + br = au_sbr(sb, nsi_lock.bindex); |
11180 | + atomic_inc(&br->br_count); | |
1facf9fc | 11181 | + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock); |
11182 | + if (IS_ERR(dentry)) | |
11183 | + goto out_unlock; | |
11184 | + if (dentry) | |
11185 | + goto accept; | |
11186 | + | |
11187 | + /* lookup path */ | |
027c5e7a | 11188 | + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock); |
1facf9fc | 11189 | + if (IS_ERR(dentry)) |
11190 | + goto out_unlock; | |
11191 | + if (unlikely(!dentry)) | |
11192 | + /* todo?: make it ESTALE */ | |
11193 | + goto out_unlock; | |
11194 | + | |
4f0767ce | 11195 | +accept: |
027c5e7a AM |
11196 | + if (!au_digen_test(dentry, au_sigen(sb)) |
11197 | + && dentry->d_inode->i_generation == fh[Fh_igen]) | |
1facf9fc | 11198 | + goto out_unlock; /* success */ |
11199 | + | |
11200 | + dput(dentry); | |
11201 | + dentry = ERR_PTR(-ESTALE); | |
4f0767ce | 11202 | +out_unlock: |
027c5e7a AM |
11203 | + if (br) |
11204 | + atomic_dec(&br->br_count); | |
1facf9fc | 11205 | + si_read_unlock(sb); |
4f0767ce | 11206 | +out: |
1facf9fc | 11207 | + AuTraceErrPtr(dentry); |
11208 | + return dentry; | |
11209 | +} | |
11210 | + | |
11211 | +#if 0 /* reserved for future use */ | |
11212 | +/* support subtreecheck option */ | |
11213 | +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid, | |
11214 | + int fh_len, int fh_type) | |
11215 | +{ | |
11216 | + struct dentry *parent; | |
11217 | + __u32 *fh = fid->raw; | |
11218 | + ino_t dir_ino; | |
11219 | + | |
11220 | + dir_ino = decode_ino(fh + Fh_dir_ino); | |
11221 | + parent = decode_by_ino(sb, dir_ino, 0); | |
11222 | + if (IS_ERR(parent)) | |
11223 | + goto out; | |
11224 | + if (!parent) | |
11225 | + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]), | |
11226 | + dir_ino, fh, fh_len); | |
11227 | + | |
4f0767ce | 11228 | +out: |
1facf9fc | 11229 | + AuTraceErrPtr(parent); |
11230 | + return parent; | |
11231 | +} | |
11232 | +#endif | |
11233 | + | |
11234 | +/* ---------------------------------------------------------------------- */ | |
11235 | + | |
0c3ec466 AM |
11236 | +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, |
11237 | + struct inode *dir) | |
1facf9fc | 11238 | +{ |
11239 | + int err; | |
0c3ec466 | 11240 | + aufs_bindex_t bindex; |
1facf9fc | 11241 | + struct super_block *sb, *h_sb; |
0c3ec466 AM |
11242 | + struct dentry *dentry, *parent, *h_parent; |
11243 | + struct inode *h_dir; | |
1facf9fc | 11244 | + struct au_branch *br; |
11245 | + | |
1facf9fc | 11246 | + err = -ENOSPC; |
11247 | + if (unlikely(*max_len <= Fh_tail)) { | |
11248 | + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len); | |
11249 | + goto out; | |
11250 | + } | |
11251 | + | |
11252 | + err = FILEID_ROOT; | |
0c3ec466 AM |
11253 | + if (inode->i_ino == AUFS_ROOT_INO) { |
11254 | + AuDebugOn(inode->i_ino != AUFS_ROOT_INO); | |
1facf9fc | 11255 | + goto out; |
11256 | + } | |
11257 | + | |
1facf9fc | 11258 | + h_parent = NULL; |
0c3ec466 AM |
11259 | + sb = inode->i_sb; |
11260 | + err = si_read_lock(sb, AuLock_FLUSH); | |
027c5e7a AM |
11261 | + if (unlikely(err)) |
11262 | + goto out; | |
11263 | + | |
1facf9fc | 11264 | +#ifdef CONFIG_AUFS_DEBUG |
11265 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) | |
11266 | + AuWarn1("NFS-exporting requires xino\n"); | |
11267 | +#endif | |
027c5e7a | 11268 | + err = -EIO; |
0c3ec466 AM |
11269 | + parent = NULL; |
11270 | + ii_read_lock_child(inode); | |
11271 | + bindex = au_ibstart(inode); | |
11272 | + if (!dir) { | |
c1595e42 | 11273 | + dentry = d_find_any_alias(inode); |
0c3ec466 AM |
11274 | + if (unlikely(!dentry)) |
11275 | + goto out_unlock; | |
11276 | + AuDebugOn(au_test_anon(dentry)); | |
11277 | + parent = dget_parent(dentry); | |
11278 | + dput(dentry); | |
11279 | + if (unlikely(!parent)) | |
11280 | + goto out_unlock; | |
11281 | + dir = parent->d_inode; | |
1facf9fc | 11282 | + } |
0c3ec466 AM |
11283 | + |
11284 | + ii_read_lock_parent(dir); | |
11285 | + h_dir = au_h_iptr(dir, bindex); | |
11286 | + ii_read_unlock(dir); | |
11287 | + if (unlikely(!h_dir)) | |
11288 | + goto out_parent; | |
c1595e42 | 11289 | + h_parent = d_find_any_alias(h_dir); |
1facf9fc | 11290 | + if (unlikely(!h_parent)) |
0c3ec466 | 11291 | + goto out_hparent; |
1facf9fc | 11292 | + |
11293 | + err = -EPERM; | |
11294 | + br = au_sbr(sb, bindex); | |
86dc4139 | 11295 | + h_sb = au_br_sb(br); |
1facf9fc | 11296 | + if (unlikely(!h_sb->s_export_op)) { |
11297 | + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb)); | |
0c3ec466 | 11298 | + goto out_hparent; |
1facf9fc | 11299 | + } |
11300 | + | |
11301 | + fh[Fh_br_id] = br->br_id; | |
11302 | + fh[Fh_sigen] = au_sigen(sb); | |
11303 | + encode_ino(fh + Fh_ino, inode->i_ino); | |
0c3ec466 | 11304 | + encode_ino(fh + Fh_dir_ino, dir->i_ino); |
1facf9fc | 11305 | + fh[Fh_igen] = inode->i_generation; |
11306 | + | |
11307 | + *max_len -= Fh_tail; | |
11308 | + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail), | |
11309 | + max_len, | |
11310 | + /*connectable or subtreecheck*/0); | |
11311 | + err = fh[Fh_h_type]; | |
11312 | + *max_len += Fh_tail; | |
11313 | + /* todo: macros? */ | |
1716fcea | 11314 | + if (err != FILEID_INVALID) |
1facf9fc | 11315 | + err = 99; |
11316 | + else | |
11317 | + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb)); | |
11318 | + | |
0c3ec466 | 11319 | +out_hparent: |
1facf9fc | 11320 | + dput(h_parent); |
0c3ec466 | 11321 | +out_parent: |
1facf9fc | 11322 | + dput(parent); |
0c3ec466 AM |
11323 | +out_unlock: |
11324 | + ii_read_unlock(inode); | |
11325 | + si_read_unlock(sb); | |
4f0767ce | 11326 | +out: |
1facf9fc | 11327 | + if (unlikely(err < 0)) |
1716fcea | 11328 | + err = FILEID_INVALID; |
1facf9fc | 11329 | + return err; |
11330 | +} | |
11331 | + | |
11332 | +/* ---------------------------------------------------------------------- */ | |
11333 | + | |
4a4d8108 AM |
11334 | +static int aufs_commit_metadata(struct inode *inode) |
11335 | +{ | |
11336 | + int err; | |
11337 | + aufs_bindex_t bindex; | |
11338 | + struct super_block *sb; | |
11339 | + struct inode *h_inode; | |
11340 | + int (*f)(struct inode *inode); | |
11341 | + | |
11342 | + sb = inode->i_sb; | |
e49829fe | 11343 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 AM |
11344 | + ii_write_lock_child(inode); |
11345 | + bindex = au_ibstart(inode); | |
11346 | + AuDebugOn(bindex < 0); | |
11347 | + h_inode = au_h_iptr(inode, bindex); | |
11348 | + | |
11349 | + f = h_inode->i_sb->s_export_op->commit_metadata; | |
11350 | + if (f) | |
11351 | + err = f(h_inode); | |
11352 | + else { | |
11353 | + struct writeback_control wbc = { | |
11354 | + .sync_mode = WB_SYNC_ALL, | |
11355 | + .nr_to_write = 0 /* metadata only */ | |
11356 | + }; | |
11357 | + | |
11358 | + err = sync_inode(h_inode, &wbc); | |
11359 | + } | |
11360 | + | |
11361 | + au_cpup_attr_timesizes(inode); | |
11362 | + ii_write_unlock(inode); | |
11363 | + si_read_unlock(sb); | |
11364 | + return err; | |
11365 | +} | |
11366 | + | |
11367 | +/* ---------------------------------------------------------------------- */ | |
11368 | + | |
1facf9fc | 11369 | +static struct export_operations aufs_export_op = { |
4a4d8108 | 11370 | + .fh_to_dentry = aufs_fh_to_dentry, |
1facf9fc | 11371 | + /* .fh_to_parent = aufs_fh_to_parent, */ |
4a4d8108 AM |
11372 | + .encode_fh = aufs_encode_fh, |
11373 | + .commit_metadata = aufs_commit_metadata | |
1facf9fc | 11374 | +}; |
11375 | + | |
11376 | +void au_export_init(struct super_block *sb) | |
11377 | +{ | |
11378 | + struct au_sbinfo *sbinfo; | |
11379 | + __u32 u; | |
11380 | + | |
11381 | + sb->s_export_op = &aufs_export_op; | |
11382 | + sbinfo = au_sbi(sb); | |
11383 | + sbinfo->si_xigen = NULL; | |
11384 | + get_random_bytes(&u, sizeof(u)); | |
11385 | + BUILD_BUG_ON(sizeof(u) != sizeof(int)); | |
11386 | + atomic_set(&sbinfo->si_xigen_next, u); | |
11387 | +} | |
076b876e AM |
11388 | diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c |
11389 | --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
11390 | +++ linux/fs/aufs/fhsm.c 2015-01-25 13:00:38.631047076 +0100 |
11391 | @@ -0,0 +1,426 @@ | |
076b876e AM |
11392 | +/* |
11393 | + * Copyright (C) 2011-2014 Junjiro R. Okajima | |
11394 | + * | |
11395 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11396 | + * it under the terms of the GNU General Public License as published by | |
11397 | + * the Free Software Foundation; either version 2 of the License, or | |
11398 | + * (at your option) any later version. | |
11399 | + * | |
11400 | + * This program is distributed in the hope that it will be useful, | |
11401 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11402 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11403 | + * GNU General Public License for more details. | |
11404 | + * | |
11405 | + * You should have received a copy of the GNU General Public License | |
11406 | + * along with this program; if not, write to the Free Software | |
11407 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
11408 | + */ | |
11409 | + | |
11410 | +/* | |
11411 | + * File-based Hierarchy Storage Management | |
11412 | + */ | |
11413 | + | |
11414 | +#include <linux/anon_inodes.h> | |
11415 | +#include <linux/poll.h> | |
11416 | +#include <linux/seq_file.h> | |
11417 | +#include <linux/statfs.h> | |
11418 | +#include "aufs.h" | |
11419 | + | |
c1595e42 JR |
11420 | +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb) |
11421 | +{ | |
11422 | + struct au_sbinfo *sbinfo; | |
11423 | + struct au_fhsm *fhsm; | |
11424 | + | |
11425 | + SiMustAnyLock(sb); | |
11426 | + | |
11427 | + sbinfo = au_sbi(sb); | |
11428 | + fhsm = &sbinfo->si_fhsm; | |
11429 | + AuDebugOn(!fhsm); | |
11430 | + return fhsm->fhsm_bottom; | |
11431 | +} | |
11432 | + | |
11433 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex) | |
11434 | +{ | |
11435 | + struct au_sbinfo *sbinfo; | |
11436 | + struct au_fhsm *fhsm; | |
11437 | + | |
11438 | + SiMustWriteLock(sb); | |
11439 | + | |
11440 | + sbinfo = au_sbi(sb); | |
11441 | + fhsm = &sbinfo->si_fhsm; | |
11442 | + AuDebugOn(!fhsm); | |
11443 | + fhsm->fhsm_bottom = bindex; | |
11444 | +} | |
11445 | + | |
11446 | +/* ---------------------------------------------------------------------- */ | |
11447 | + | |
076b876e AM |
11448 | +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br) |
11449 | +{ | |
11450 | + struct au_br_fhsm *bf; | |
11451 | + | |
11452 | + bf = br->br_fhsm; | |
11453 | + MtxMustLock(&bf->bf_lock); | |
11454 | + | |
11455 | + return !bf->bf_readable | |
11456 | + || time_after(jiffies, | |
11457 | + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire); | |
11458 | +} | |
11459 | + | |
11460 | +/* ---------------------------------------------------------------------- */ | |
11461 | + | |
11462 | +static void au_fhsm_notify(struct super_block *sb, int val) | |
11463 | +{ | |
11464 | + struct au_sbinfo *sbinfo; | |
11465 | + struct au_fhsm *fhsm; | |
11466 | + | |
11467 | + SiMustAnyLock(sb); | |
11468 | + | |
11469 | + sbinfo = au_sbi(sb); | |
11470 | + fhsm = &sbinfo->si_fhsm; | |
11471 | + if (au_fhsm_pid(fhsm) | |
11472 | + && atomic_read(&fhsm->fhsm_readable) != -1) { | |
11473 | + atomic_set(&fhsm->fhsm_readable, val); | |
11474 | + if (val) | |
11475 | + wake_up(&fhsm->fhsm_wqh); | |
11476 | + } | |
11477 | +} | |
11478 | + | |
11479 | +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex, | |
11480 | + struct aufs_stfs *rstfs, int do_lock, int do_notify) | |
11481 | +{ | |
11482 | + int err; | |
11483 | + struct au_branch *br; | |
11484 | + struct au_br_fhsm *bf; | |
11485 | + | |
11486 | + br = au_sbr(sb, bindex); | |
11487 | + AuDebugOn(au_br_rdonly(br)); | |
11488 | + bf = br->br_fhsm; | |
11489 | + AuDebugOn(!bf); | |
11490 | + | |
11491 | + if (do_lock) | |
11492 | + mutex_lock(&bf->bf_lock); | |
11493 | + else | |
11494 | + MtxMustLock(&bf->bf_lock); | |
11495 | + | |
11496 | + /* sb->s_root for NFS is unreliable */ | |
11497 | + err = au_br_stfs(br, &bf->bf_stfs); | |
11498 | + if (unlikely(err)) { | |
11499 | + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err); | |
11500 | + goto out; | |
11501 | + } | |
11502 | + | |
11503 | + bf->bf_jiffy = jiffies; | |
11504 | + bf->bf_readable = 1; | |
11505 | + if (do_notify) | |
11506 | + au_fhsm_notify(sb, /*val*/1); | |
11507 | + if (rstfs) | |
11508 | + *rstfs = bf->bf_stfs; | |
11509 | + | |
11510 | +out: | |
11511 | + if (do_lock) | |
11512 | + mutex_unlock(&bf->bf_lock); | |
11513 | + au_fhsm_notify(sb, /*val*/1); | |
11514 | + | |
11515 | + return err; | |
11516 | +} | |
11517 | + | |
11518 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force) | |
11519 | +{ | |
11520 | + int err; | |
076b876e AM |
11521 | + struct au_sbinfo *sbinfo; |
11522 | + struct au_fhsm *fhsm; | |
11523 | + struct au_branch *br; | |
11524 | + struct au_br_fhsm *bf; | |
11525 | + | |
11526 | + AuDbg("b%d, force %d\n", bindex, force); | |
11527 | + SiMustAnyLock(sb); | |
11528 | + | |
11529 | + sbinfo = au_sbi(sb); | |
11530 | + fhsm = &sbinfo->si_fhsm; | |
c1595e42 JR |
11531 | + if (!au_ftest_si(sbinfo, FHSM) |
11532 | + || fhsm->fhsm_bottom == bindex) | |
076b876e AM |
11533 | + return; |
11534 | + | |
11535 | + br = au_sbr(sb, bindex); | |
11536 | + bf = br->br_fhsm; | |
11537 | + AuDebugOn(!bf); | |
11538 | + mutex_lock(&bf->bf_lock); | |
11539 | + if (force | |
11540 | + || au_fhsm_pid(fhsm) | |
11541 | + || au_fhsm_test_jiffy(sbinfo, br)) | |
11542 | + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0, | |
11543 | + /*do_notify*/1); | |
11544 | + mutex_unlock(&bf->bf_lock); | |
11545 | +} | |
11546 | + | |
11547 | +void au_fhsm_wrote_all(struct super_block *sb, int force) | |
11548 | +{ | |
11549 | + aufs_bindex_t bindex, bend; | |
11550 | + struct au_branch *br; | |
11551 | + | |
11552 | + /* exclude the bottom */ | |
c1595e42 | 11553 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11554 | + for (bindex = 0; bindex < bend; bindex++) { |
11555 | + br = au_sbr(sb, bindex); | |
11556 | + if (au_br_fhsm(br->br_perm)) | |
11557 | + au_fhsm_wrote(sb, bindex, force); | |
11558 | + } | |
11559 | +} | |
11560 | + | |
11561 | +/* ---------------------------------------------------------------------- */ | |
11562 | + | |
11563 | +static unsigned int au_fhsm_poll(struct file *file, | |
11564 | + struct poll_table_struct *wait) | |
11565 | +{ | |
11566 | + unsigned int mask; | |
11567 | + struct au_sbinfo *sbinfo; | |
11568 | + struct au_fhsm *fhsm; | |
11569 | + | |
11570 | + mask = 0; | |
11571 | + sbinfo = file->private_data; | |
11572 | + fhsm = &sbinfo->si_fhsm; | |
11573 | + poll_wait(file, &fhsm->fhsm_wqh, wait); | |
11574 | + if (atomic_read(&fhsm->fhsm_readable)) | |
11575 | + mask = POLLIN /* | POLLRDNORM */; | |
11576 | + | |
11577 | + AuTraceErr((int)mask); | |
11578 | + return mask; | |
11579 | +} | |
11580 | + | |
11581 | +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr, | |
11582 | + struct aufs_stfs *stfs, __s16 brid) | |
11583 | +{ | |
11584 | + int err; | |
11585 | + | |
11586 | + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs)); | |
11587 | + if (!err) | |
11588 | + err = __put_user(brid, &stbr->brid); | |
11589 | + if (unlikely(err)) | |
11590 | + err = -EFAULT; | |
11591 | + | |
11592 | + return err; | |
11593 | +} | |
11594 | + | |
11595 | +static ssize_t au_fhsm_do_read(struct super_block *sb, | |
11596 | + struct aufs_stbr __user *stbr, size_t count) | |
11597 | +{ | |
11598 | + ssize_t err; | |
11599 | + int nstbr; | |
11600 | + aufs_bindex_t bindex, bend; | |
11601 | + struct au_branch *br; | |
11602 | + struct au_br_fhsm *bf; | |
11603 | + | |
11604 | + /* except the bottom branch */ | |
11605 | + err = 0; | |
11606 | + nstbr = 0; | |
c1595e42 | 11607 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11608 | + for (bindex = 0; !err && bindex < bend; bindex++) { |
11609 | + br = au_sbr(sb, bindex); | |
11610 | + if (!au_br_fhsm(br->br_perm)) | |
11611 | + continue; | |
11612 | + | |
11613 | + bf = br->br_fhsm; | |
11614 | + mutex_lock(&bf->bf_lock); | |
11615 | + if (bf->bf_readable) { | |
11616 | + err = -EFAULT; | |
11617 | + if (count >= sizeof(*stbr)) | |
11618 | + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs, | |
11619 | + br->br_id); | |
11620 | + if (!err) { | |
11621 | + bf->bf_readable = 0; | |
11622 | + count -= sizeof(*stbr); | |
11623 | + nstbr++; | |
11624 | + } | |
11625 | + } | |
11626 | + mutex_unlock(&bf->bf_lock); | |
11627 | + } | |
11628 | + if (!err) | |
11629 | + err = sizeof(*stbr) * nstbr; | |
11630 | + | |
11631 | + return err; | |
11632 | +} | |
11633 | + | |
11634 | +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count, | |
11635 | + loff_t *pos) | |
11636 | +{ | |
11637 | + ssize_t err; | |
11638 | + int readable; | |
11639 | + aufs_bindex_t nfhsm, bindex, bend; | |
11640 | + struct au_sbinfo *sbinfo; | |
11641 | + struct au_fhsm *fhsm; | |
11642 | + struct au_branch *br; | |
11643 | + struct super_block *sb; | |
11644 | + | |
11645 | + err = 0; | |
11646 | + sbinfo = file->private_data; | |
11647 | + fhsm = &sbinfo->si_fhsm; | |
11648 | +need_data: | |
11649 | + spin_lock_irq(&fhsm->fhsm_wqh.lock); | |
11650 | + if (!atomic_read(&fhsm->fhsm_readable)) { | |
11651 | + if (vfsub_file_flags(file) & O_NONBLOCK) | |
11652 | + err = -EAGAIN; | |
11653 | + else | |
11654 | + err = wait_event_interruptible_locked_irq | |
11655 | + (fhsm->fhsm_wqh, | |
11656 | + atomic_read(&fhsm->fhsm_readable)); | |
11657 | + } | |
11658 | + spin_unlock_irq(&fhsm->fhsm_wqh.lock); | |
11659 | + if (unlikely(err)) | |
11660 | + goto out; | |
11661 | + | |
11662 | + /* sb may already be dead */ | |
11663 | + au_rw_read_lock(&sbinfo->si_rwsem); | |
11664 | + readable = atomic_read(&fhsm->fhsm_readable); | |
11665 | + if (readable > 0) { | |
11666 | + sb = sbinfo->si_sb; | |
11667 | + AuDebugOn(!sb); | |
11668 | + /* exclude the bottom branch */ | |
11669 | + nfhsm = 0; | |
c1595e42 | 11670 | + bend = au_fhsm_bottom(sb); |
076b876e AM |
11671 | + for (bindex = 0; bindex < bend; bindex++) { |
11672 | + br = au_sbr(sb, bindex); | |
11673 | + if (au_br_fhsm(br->br_perm)) | |
11674 | + nfhsm++; | |
11675 | + } | |
11676 | + err = -EMSGSIZE; | |
11677 | + if (nfhsm * sizeof(struct aufs_stbr) <= count) { | |
11678 | + atomic_set(&fhsm->fhsm_readable, 0); | |
11679 | + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf, | |
11680 | + count); | |
11681 | + } | |
11682 | + } | |
11683 | + au_rw_read_unlock(&sbinfo->si_rwsem); | |
11684 | + if (!readable) | |
11685 | + goto need_data; | |
11686 | + | |
11687 | +out: | |
11688 | + return err; | |
11689 | +} | |
11690 | + | |
11691 | +static int au_fhsm_release(struct inode *inode, struct file *file) | |
11692 | +{ | |
11693 | + struct au_sbinfo *sbinfo; | |
11694 | + struct au_fhsm *fhsm; | |
11695 | + | |
11696 | + /* sb may already be dead */ | |
11697 | + sbinfo = file->private_data; | |
11698 | + fhsm = &sbinfo->si_fhsm; | |
11699 | + spin_lock(&fhsm->fhsm_spin); | |
11700 | + fhsm->fhsm_pid = 0; | |
11701 | + spin_unlock(&fhsm->fhsm_spin); | |
11702 | + kobject_put(&sbinfo->si_kobj); | |
11703 | + | |
11704 | + return 0; | |
11705 | +} | |
11706 | + | |
11707 | +static const struct file_operations au_fhsm_fops = { | |
11708 | + .owner = THIS_MODULE, | |
11709 | + .llseek = noop_llseek, | |
11710 | + .read = au_fhsm_read, | |
11711 | + .poll = au_fhsm_poll, | |
11712 | + .release = au_fhsm_release | |
11713 | +}; | |
11714 | + | |
11715 | +int au_fhsm_fd(struct super_block *sb, int oflags) | |
11716 | +{ | |
11717 | + int err, fd; | |
11718 | + struct au_sbinfo *sbinfo; | |
11719 | + struct au_fhsm *fhsm; | |
11720 | + | |
11721 | + err = -EPERM; | |
11722 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
11723 | + goto out; | |
11724 | + | |
11725 | + err = -EINVAL; | |
11726 | + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK))) | |
11727 | + goto out; | |
11728 | + | |
11729 | + err = 0; | |
11730 | + sbinfo = au_sbi(sb); | |
11731 | + fhsm = &sbinfo->si_fhsm; | |
11732 | + spin_lock(&fhsm->fhsm_spin); | |
11733 | + if (!fhsm->fhsm_pid) | |
11734 | + fhsm->fhsm_pid = current->pid; | |
11735 | + else | |
11736 | + err = -EBUSY; | |
11737 | + spin_unlock(&fhsm->fhsm_spin); | |
11738 | + if (unlikely(err)) | |
11739 | + goto out; | |
11740 | + | |
11741 | + oflags |= O_RDONLY; | |
11742 | + /* oflags |= FMODE_NONOTIFY; */ | |
11743 | + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags); | |
11744 | + err = fd; | |
11745 | + if (unlikely(fd < 0)) | |
11746 | + goto out_pid; | |
11747 | + | |
11748 | + /* succeed reglardless 'fhsm' status */ | |
11749 | + kobject_get(&sbinfo->si_kobj); | |
11750 | + si_noflush_read_lock(sb); | |
11751 | + if (au_ftest_si(sbinfo, FHSM)) | |
11752 | + au_fhsm_wrote_all(sb, /*force*/0); | |
11753 | + si_read_unlock(sb); | |
11754 | + goto out; /* success */ | |
11755 | + | |
11756 | +out_pid: | |
11757 | + spin_lock(&fhsm->fhsm_spin); | |
11758 | + fhsm->fhsm_pid = 0; | |
11759 | + spin_unlock(&fhsm->fhsm_spin); | |
11760 | +out: | |
11761 | + AuTraceErr(err); | |
11762 | + return err; | |
11763 | +} | |
11764 | + | |
11765 | +/* ---------------------------------------------------------------------- */ | |
11766 | + | |
11767 | +int au_fhsm_br_alloc(struct au_branch *br) | |
11768 | +{ | |
11769 | + int err; | |
11770 | + | |
11771 | + err = 0; | |
11772 | + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS); | |
11773 | + if (br->br_fhsm) | |
11774 | + au_br_fhsm_init(br->br_fhsm); | |
11775 | + else | |
11776 | + err = -ENOMEM; | |
11777 | + | |
11778 | + return err; | |
11779 | +} | |
11780 | + | |
11781 | +/* ---------------------------------------------------------------------- */ | |
11782 | + | |
11783 | +void au_fhsm_fin(struct super_block *sb) | |
11784 | +{ | |
11785 | + au_fhsm_notify(sb, /*val*/-1); | |
11786 | +} | |
11787 | + | |
11788 | +void au_fhsm_init(struct au_sbinfo *sbinfo) | |
11789 | +{ | |
11790 | + struct au_fhsm *fhsm; | |
11791 | + | |
11792 | + fhsm = &sbinfo->si_fhsm; | |
11793 | + spin_lock_init(&fhsm->fhsm_spin); | |
11794 | + init_waitqueue_head(&fhsm->fhsm_wqh); | |
11795 | + atomic_set(&fhsm->fhsm_readable, 0); | |
11796 | + fhsm->fhsm_expire | |
11797 | + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC); | |
c1595e42 | 11798 | + fhsm->fhsm_bottom = -1; |
076b876e AM |
11799 | +} |
11800 | + | |
11801 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec) | |
11802 | +{ | |
11803 | + sbinfo->si_fhsm.fhsm_expire | |
11804 | + = msecs_to_jiffies(sec * MSEC_PER_SEC); | |
11805 | +} | |
11806 | + | |
11807 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo) | |
11808 | +{ | |
11809 | + unsigned int u; | |
11810 | + | |
11811 | + if (!au_ftest_si(sbinfo, FHSM)) | |
11812 | + return; | |
11813 | + | |
11814 | + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC; | |
11815 | + if (u != AUFS_FHSM_CACHE_DEF_SEC) | |
11816 | + seq_printf(seq, ",fhsm_sec=%u", u); | |
11817 | +} | |
7f207e10 AM |
11818 | diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c |
11819 | --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
11820 | +++ linux/fs/aufs/file.c 2015-01-25 13:00:38.631047076 +0100 |
11821 | @@ -0,0 +1,829 @@ | |
1facf9fc | 11822 | +/* |
523b37e3 | 11823 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 11824 | + * |
11825 | + * This program, aufs is free software; you can redistribute it and/or modify | |
11826 | + * it under the terms of the GNU General Public License as published by | |
11827 | + * the Free Software Foundation; either version 2 of the License, or | |
11828 | + * (at your option) any later version. | |
dece6358 AM |
11829 | + * |
11830 | + * This program is distributed in the hope that it will be useful, | |
11831 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11832 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11833 | + * GNU General Public License for more details. | |
11834 | + * | |
11835 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 11836 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 11837 | + */ |
11838 | + | |
11839 | +/* | |
4a4d8108 | 11840 | + * handling file/dir, and address_space operation |
1facf9fc | 11841 | + */ |
11842 | + | |
7eafdf33 AM |
11843 | +#ifdef CONFIG_AUFS_DEBUG |
11844 | +#include <linux/migrate.h> | |
11845 | +#endif | |
4a4d8108 | 11846 | +#include <linux/pagemap.h> |
1facf9fc | 11847 | +#include "aufs.h" |
11848 | + | |
4a4d8108 AM |
11849 | +/* drop flags for writing */ |
11850 | +unsigned int au_file_roflags(unsigned int flags) | |
11851 | +{ | |
11852 | + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC); | |
11853 | + flags |= O_RDONLY | O_NOATIME; | |
11854 | + return flags; | |
11855 | +} | |
11856 | + | |
11857 | +/* common functions to regular file and dir */ | |
11858 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 11859 | + struct file *file, int force_wr) |
1facf9fc | 11860 | +{ |
1308ab2a | 11861 | + struct file *h_file; |
4a4d8108 AM |
11862 | + struct dentry *h_dentry; |
11863 | + struct inode *h_inode; | |
11864 | + struct super_block *sb; | |
11865 | + struct au_branch *br; | |
11866 | + struct path h_path; | |
11867 | + int err, exec_flag; | |
1facf9fc | 11868 | + |
4a4d8108 AM |
11869 | + /* a race condition can happen between open and unlink/rmdir */ |
11870 | + h_file = ERR_PTR(-ENOENT); | |
11871 | + h_dentry = au_h_dptr(dentry, bindex); | |
b752ccd1 | 11872 | + if (au_test_nfsd() && !h_dentry) |
4a4d8108 AM |
11873 | + goto out; |
11874 | + h_inode = h_dentry->d_inode; | |
b752ccd1 | 11875 | + if (au_test_nfsd() && !h_inode) |
4a4d8108 | 11876 | + goto out; |
027c5e7a AM |
11877 | + spin_lock(&h_dentry->d_lock); |
11878 | + err = (!d_unhashed(dentry) && d_unlinked(h_dentry)) | |
11879 | + || !h_inode | |
11880 | + /* || !dentry->d_inode->i_nlink */ | |
11881 | + ; | |
11882 | + spin_unlock(&h_dentry->d_lock); | |
11883 | + if (unlikely(err)) | |
4a4d8108 | 11884 | + goto out; |
1facf9fc | 11885 | + |
4a4d8108 AM |
11886 | + sb = dentry->d_sb; |
11887 | + br = au_sbr(sb, bindex); | |
11888 | + h_file = ERR_PTR(-EACCES); | |
2cbb1c4b | 11889 | + exec_flag = flags & __FMODE_EXEC; |
86dc4139 | 11890 | + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC)) |
027c5e7a | 11891 | + goto out; |
1facf9fc | 11892 | + |
4a4d8108 | 11893 | + /* drop flags for writing */ |
392086de AM |
11894 | + if (au_test_ro(sb, bindex, dentry->d_inode)) { |
11895 | + if (force_wr && !(flags & O_WRONLY)) | |
11896 | + force_wr = 0; | |
4a4d8108 | 11897 | + flags = au_file_roflags(flags); |
392086de AM |
11898 | + if (force_wr) { |
11899 | + h_file = ERR_PTR(-EROFS); | |
11900 | + flags = au_file_roflags(flags); | |
11901 | + if (unlikely(vfsub_native_ro(h_inode) | |
11902 | + || IS_APPEND(h_inode))) | |
11903 | + goto out; | |
11904 | + flags &= ~O_ACCMODE; | |
11905 | + flags |= O_WRONLY; | |
11906 | + } | |
11907 | + } | |
4a4d8108 AM |
11908 | + flags &= ~O_CREAT; |
11909 | + atomic_inc(&br->br_count); | |
11910 | + h_path.dentry = h_dentry; | |
86dc4139 | 11911 | + h_path.mnt = au_br_mnt(br); |
38d290e6 | 11912 | + h_file = vfsub_dentry_open(&h_path, flags); |
4a4d8108 AM |
11913 | + if (IS_ERR(h_file)) |
11914 | + goto out_br; | |
dece6358 | 11915 | + |
4a4d8108 AM |
11916 | + if (exec_flag) { |
11917 | + err = deny_write_access(h_file); | |
11918 | + if (unlikely(err)) { | |
11919 | + fput(h_file); | |
11920 | + h_file = ERR_PTR(err); | |
11921 | + goto out_br; | |
11922 | + } | |
11923 | + } | |
953406b4 | 11924 | + fsnotify_open(h_file); |
4a4d8108 | 11925 | + goto out; /* success */ |
1facf9fc | 11926 | + |
4f0767ce | 11927 | +out_br: |
4a4d8108 | 11928 | + atomic_dec(&br->br_count); |
4f0767ce | 11929 | +out: |
4a4d8108 AM |
11930 | + return h_file; |
11931 | +} | |
1308ab2a | 11932 | + |
076b876e AM |
11933 | +static int au_cmoo(struct dentry *dentry) |
11934 | +{ | |
11935 | + int err, cmoo; | |
11936 | + unsigned int udba; | |
11937 | + struct path h_path; | |
11938 | + struct au_pin pin; | |
11939 | + struct au_cp_generic cpg = { | |
11940 | + .dentry = dentry, | |
11941 | + .bdst = -1, | |
11942 | + .bsrc = -1, | |
11943 | + .len = -1, | |
11944 | + .pin = &pin, | |
11945 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
11946 | + }; | |
11947 | + struct inode *inode, *delegated; | |
11948 | + struct super_block *sb; | |
11949 | + struct au_sbinfo *sbinfo; | |
11950 | + struct au_fhsm *fhsm; | |
11951 | + pid_t pid; | |
11952 | + struct au_branch *br; | |
11953 | + struct dentry *parent; | |
11954 | + struct au_hinode *hdir; | |
11955 | + | |
11956 | + DiMustWriteLock(dentry); | |
11957 | + inode = dentry->d_inode; | |
11958 | + IiMustWriteLock(inode); | |
11959 | + | |
11960 | + err = 0; | |
11961 | + if (IS_ROOT(dentry)) | |
11962 | + goto out; | |
11963 | + cpg.bsrc = au_dbstart(dentry); | |
11964 | + if (!cpg.bsrc) | |
11965 | + goto out; | |
11966 | + | |
11967 | + sb = dentry->d_sb; | |
11968 | + sbinfo = au_sbi(sb); | |
11969 | + fhsm = &sbinfo->si_fhsm; | |
11970 | + pid = au_fhsm_pid(fhsm); | |
11971 | + if (pid | |
11972 | + && (current->pid == pid | |
11973 | + || current->real_parent->pid == pid)) | |
11974 | + goto out; | |
11975 | + | |
11976 | + br = au_sbr(sb, cpg.bsrc); | |
11977 | + cmoo = au_br_cmoo(br->br_perm); | |
11978 | + if (!cmoo) | |
11979 | + goto out; | |
11980 | + if (!S_ISREG(inode->i_mode)) | |
11981 | + cmoo &= AuBrAttr_COO_ALL; | |
11982 | + if (!cmoo) | |
11983 | + goto out; | |
11984 | + | |
11985 | + parent = dget_parent(dentry); | |
11986 | + di_write_lock_parent(parent); | |
11987 | + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1); | |
11988 | + cpg.bdst = err; | |
11989 | + if (unlikely(err < 0)) { | |
11990 | + err = 0; /* there is no upper writable branch */ | |
11991 | + goto out_dgrade; | |
11992 | + } | |
11993 | + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst); | |
11994 | + | |
11995 | + /* do not respect the coo attrib for the target branch */ | |
11996 | + err = au_cpup_dirs(dentry, cpg.bdst); | |
11997 | + if (unlikely(err)) | |
11998 | + goto out_dgrade; | |
11999 | + | |
12000 | + di_downgrade_lock(parent, AuLock_IR); | |
12001 | + udba = au_opt_udba(sb); | |
12002 | + err = au_pin(&pin, dentry, cpg.bdst, udba, | |
12003 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12004 | + if (unlikely(err)) | |
12005 | + goto out_parent; | |
12006 | + | |
12007 | + err = au_sio_cpup_simple(&cpg); | |
12008 | + au_unpin(&pin); | |
12009 | + if (unlikely(err)) | |
12010 | + goto out_parent; | |
12011 | + if (!(cmoo & AuBrWAttr_MOO)) | |
12012 | + goto out_parent; /* success */ | |
12013 | + | |
12014 | + err = au_pin(&pin, dentry, cpg.bsrc, udba, | |
12015 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
12016 | + if (unlikely(err)) | |
12017 | + goto out_parent; | |
12018 | + | |
12019 | + h_path.mnt = au_br_mnt(br); | |
12020 | + h_path.dentry = au_h_dptr(dentry, cpg.bsrc); | |
12021 | + hdir = au_hi(parent->d_inode, cpg.bsrc); | |
12022 | + delegated = NULL; | |
12023 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1); | |
12024 | + au_unpin(&pin); | |
12025 | + /* todo: keep h_dentry or not? */ | |
12026 | + if (unlikely(err == -EWOULDBLOCK)) { | |
12027 | + pr_warn("cannot retry for NFSv4 delegation" | |
12028 | + " for an internal unlink\n"); | |
12029 | + iput(delegated); | |
12030 | + } | |
12031 | + if (unlikely(err)) { | |
12032 | + pr_err("unlink %pd after coo failed (%d), ignored\n", | |
12033 | + dentry, err); | |
12034 | + err = 0; | |
12035 | + } | |
12036 | + goto out_parent; /* success */ | |
12037 | + | |
12038 | +out_dgrade: | |
12039 | + di_downgrade_lock(parent, AuLock_IR); | |
12040 | +out_parent: | |
12041 | + di_read_unlock(parent, AuLock_IR); | |
12042 | + dput(parent); | |
12043 | +out: | |
12044 | + AuTraceErr(err); | |
12045 | + return err; | |
12046 | +} | |
12047 | + | |
4a4d8108 AM |
12048 | +int au_do_open(struct file *file, int (*open)(struct file *file, int flags), |
12049 | + struct au_fidir *fidir) | |
1facf9fc | 12050 | +{ |
dece6358 | 12051 | + int err; |
1facf9fc | 12052 | + struct dentry *dentry; |
076b876e | 12053 | + struct au_finfo *finfo; |
1308ab2a | 12054 | + |
4a4d8108 AM |
12055 | + err = au_finfo_init(file, fidir); |
12056 | + if (unlikely(err)) | |
12057 | + goto out; | |
1facf9fc | 12058 | + |
12059 | + dentry = file->f_dentry; | |
076b876e AM |
12060 | + di_write_lock_child(dentry); |
12061 | + err = au_cmoo(dentry); | |
12062 | + di_downgrade_lock(dentry, AuLock_IR); | |
12063 | + if (!err) | |
12064 | + err = open(file, vfsub_file_flags(file)); | |
4a4d8108 | 12065 | + di_read_unlock(dentry, AuLock_IR); |
1facf9fc | 12066 | + |
076b876e AM |
12067 | + finfo = au_fi(file); |
12068 | + if (!err) { | |
12069 | + finfo->fi_file = file; | |
12070 | + au_sphl_add(&finfo->fi_hlist, | |
12071 | + &au_sbi(file->f_dentry->d_sb)->si_files); | |
12072 | + } | |
4a4d8108 AM |
12073 | + fi_write_unlock(file); |
12074 | + if (unlikely(err)) { | |
076b876e | 12075 | + finfo->fi_hdir = NULL; |
4a4d8108 | 12076 | + au_finfo_fin(file); |
1308ab2a | 12077 | + } |
4a4d8108 | 12078 | + |
4f0767ce | 12079 | +out: |
1308ab2a | 12080 | + return err; |
12081 | +} | |
dece6358 | 12082 | + |
4a4d8108 | 12083 | +int au_reopen_nondir(struct file *file) |
1308ab2a | 12084 | +{ |
4a4d8108 AM |
12085 | + int err; |
12086 | + aufs_bindex_t bstart; | |
12087 | + struct dentry *dentry; | |
12088 | + struct file *h_file, *h_file_tmp; | |
1308ab2a | 12089 | + |
4a4d8108 | 12090 | + dentry = file->f_dentry; |
4a4d8108 AM |
12091 | + bstart = au_dbstart(dentry); |
12092 | + h_file_tmp = NULL; | |
12093 | + if (au_fbstart(file) == bstart) { | |
12094 | + h_file = au_hf_top(file); | |
12095 | + if (file->f_mode == h_file->f_mode) | |
12096 | + return 0; /* success */ | |
12097 | + h_file_tmp = h_file; | |
12098 | + get_file(h_file_tmp); | |
12099 | + au_set_h_fptr(file, bstart, NULL); | |
12100 | + } | |
12101 | + AuDebugOn(au_fi(file)->fi_hdir); | |
86dc4139 AM |
12102 | + /* |
12103 | + * it can happen | |
12104 | + * file exists on both of rw and ro | |
12105 | + * open --> dbstart and fbstart are both 0 | |
12106 | + * prepend a branch as rw, "rw" become ro | |
12107 | + * remove rw/file | |
12108 | + * delete the top branch, "rw" becomes rw again | |
12109 | + * --> dbstart is 1, fbstart is still 0 | |
12110 | + * write --> fbstart is 0 but dbstart is 1 | |
12111 | + */ | |
12112 | + /* AuDebugOn(au_fbstart(file) < bstart); */ | |
1308ab2a | 12113 | + |
4a4d8108 | 12114 | + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC, |
392086de | 12115 | + file, /*force_wr*/0); |
4a4d8108 | 12116 | + err = PTR_ERR(h_file); |
86dc4139 AM |
12117 | + if (IS_ERR(h_file)) { |
12118 | + if (h_file_tmp) { | |
12119 | + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count); | |
12120 | + au_set_h_fptr(file, bstart, h_file_tmp); | |
12121 | + h_file_tmp = NULL; | |
12122 | + } | |
4a4d8108 | 12123 | + goto out; /* todo: close all? */ |
86dc4139 | 12124 | + } |
4a4d8108 AM |
12125 | + |
12126 | + err = 0; | |
12127 | + au_set_fbstart(file, bstart); | |
12128 | + au_set_h_fptr(file, bstart, h_file); | |
12129 | + au_update_figen(file); | |
12130 | + /* todo: necessary? */ | |
12131 | + /* file->f_ra = h_file->f_ra; */ | |
12132 | + | |
4f0767ce | 12133 | +out: |
4a4d8108 AM |
12134 | + if (h_file_tmp) |
12135 | + fput(h_file_tmp); | |
12136 | + return err; | |
1facf9fc | 12137 | +} |
12138 | + | |
1308ab2a | 12139 | +/* ---------------------------------------------------------------------- */ |
12140 | + | |
4a4d8108 AM |
12141 | +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt, |
12142 | + struct dentry *hi_wh) | |
1facf9fc | 12143 | +{ |
4a4d8108 AM |
12144 | + int err; |
12145 | + aufs_bindex_t bstart; | |
12146 | + struct au_dinfo *dinfo; | |
12147 | + struct dentry *h_dentry; | |
12148 | + struct au_hdentry *hdp; | |
1facf9fc | 12149 | + |
4a4d8108 AM |
12150 | + dinfo = au_di(file->f_dentry); |
12151 | + AuRwMustWriteLock(&dinfo->di_rwsem); | |
dece6358 | 12152 | + |
4a4d8108 AM |
12153 | + bstart = dinfo->di_bstart; |
12154 | + dinfo->di_bstart = btgt; | |
12155 | + hdp = dinfo->di_hdentry; | |
12156 | + h_dentry = hdp[0 + btgt].hd_dentry; | |
12157 | + hdp[0 + btgt].hd_dentry = hi_wh; | |
12158 | + err = au_reopen_nondir(file); | |
12159 | + hdp[0 + btgt].hd_dentry = h_dentry; | |
12160 | + dinfo->di_bstart = bstart; | |
1facf9fc | 12161 | + |
1facf9fc | 12162 | + return err; |
12163 | +} | |
12164 | + | |
4a4d8108 | 12165 | +static int au_ready_to_write_wh(struct file *file, loff_t len, |
86dc4139 | 12166 | + aufs_bindex_t bcpup, struct au_pin *pin) |
1facf9fc | 12167 | +{ |
4a4d8108 | 12168 | + int err; |
027c5e7a | 12169 | + struct inode *inode, *h_inode; |
c2b27bf2 AM |
12170 | + struct dentry *h_dentry, *hi_wh; |
12171 | + struct au_cp_generic cpg = { | |
12172 | + .dentry = file->f_dentry, | |
12173 | + .bdst = bcpup, | |
12174 | + .bsrc = -1, | |
12175 | + .len = len, | |
12176 | + .pin = pin | |
12177 | + }; | |
1facf9fc | 12178 | + |
c2b27bf2 AM |
12179 | + au_update_dbstart(cpg.dentry); |
12180 | + inode = cpg.dentry->d_inode; | |
027c5e7a | 12181 | + h_inode = NULL; |
c2b27bf2 AM |
12182 | + if (au_dbstart(cpg.dentry) <= bcpup |
12183 | + && au_dbend(cpg.dentry) >= bcpup) { | |
12184 | + h_dentry = au_h_dptr(cpg.dentry, bcpup); | |
027c5e7a AM |
12185 | + if (h_dentry) |
12186 | + h_inode = h_dentry->d_inode; | |
12187 | + } | |
4a4d8108 | 12188 | + hi_wh = au_hi_wh(inode, bcpup); |
027c5e7a | 12189 | + if (!hi_wh && !h_inode) |
c2b27bf2 | 12190 | + err = au_sio_cpup_wh(&cpg, file); |
4a4d8108 AM |
12191 | + else |
12192 | + /* already copied-up after unlink */ | |
12193 | + err = au_reopen_wh(file, bcpup, hi_wh); | |
1facf9fc | 12194 | + |
4a4d8108 | 12195 | + if (!err |
38d290e6 JR |
12196 | + && (inode->i_nlink > 1 |
12197 | + || (inode->i_state & I_LINKABLE)) | |
c2b27bf2 AM |
12198 | + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK)) |
12199 | + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup)); | |
1308ab2a | 12200 | + |
dece6358 | 12201 | + return err; |
1facf9fc | 12202 | +} |
12203 | + | |
4a4d8108 AM |
12204 | +/* |
12205 | + * prepare the @file for writing. | |
12206 | + */ | |
12207 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin) | |
1facf9fc | 12208 | +{ |
4a4d8108 | 12209 | + int err; |
c2b27bf2 | 12210 | + aufs_bindex_t dbstart; |
c1595e42 | 12211 | + struct dentry *parent; |
86dc4139 | 12212 | + struct inode *inode; |
1facf9fc | 12213 | + struct super_block *sb; |
4a4d8108 | 12214 | + struct file *h_file; |
c2b27bf2 AM |
12215 | + struct au_cp_generic cpg = { |
12216 | + .dentry = file->f_dentry, | |
12217 | + .bdst = -1, | |
12218 | + .bsrc = -1, | |
12219 | + .len = len, | |
12220 | + .pin = pin, | |
12221 | + .flags = AuCpup_DTIME | |
12222 | + }; | |
1facf9fc | 12223 | + |
c2b27bf2 AM |
12224 | + sb = cpg.dentry->d_sb; |
12225 | + inode = cpg.dentry->d_inode; | |
c2b27bf2 AM |
12226 | + cpg.bsrc = au_fbstart(file); |
12227 | + err = au_test_ro(sb, cpg.bsrc, inode); | |
4a4d8108 | 12228 | + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) { |
c2b27bf2 AM |
12229 | + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE, |
12230 | + /*flags*/0); | |
1facf9fc | 12231 | + goto out; |
4a4d8108 | 12232 | + } |
1facf9fc | 12233 | + |
027c5e7a | 12234 | + /* need to cpup or reopen */ |
c2b27bf2 | 12235 | + parent = dget_parent(cpg.dentry); |
4a4d8108 | 12236 | + di_write_lock_parent(parent); |
c2b27bf2 AM |
12237 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12238 | + cpg.bdst = err; | |
4a4d8108 AM |
12239 | + if (unlikely(err < 0)) |
12240 | + goto out_dgrade; | |
12241 | + err = 0; | |
12242 | + | |
c2b27bf2 AM |
12243 | + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) { |
12244 | + err = au_cpup_dirs(cpg.dentry, cpg.bdst); | |
1facf9fc | 12245 | + if (unlikely(err)) |
4a4d8108 AM |
12246 | + goto out_dgrade; |
12247 | + } | |
12248 | + | |
c2b27bf2 | 12249 | + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 AM |
12250 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
12251 | + if (unlikely(err)) | |
12252 | + goto out_dgrade; | |
12253 | + | |
c2b27bf2 | 12254 | + dbstart = au_dbstart(cpg.dentry); |
c1595e42 | 12255 | + if (dbstart <= cpg.bdst) |
c2b27bf2 | 12256 | + cpg.bsrc = cpg.bdst; |
027c5e7a | 12257 | + |
c2b27bf2 AM |
12258 | + if (dbstart <= cpg.bdst /* just reopen */ |
12259 | + || !d_unhashed(cpg.dentry) /* copyup and reopen */ | |
027c5e7a | 12260 | + ) { |
392086de | 12261 | + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0); |
86dc4139 | 12262 | + if (IS_ERR(h_file)) |
027c5e7a | 12263 | + err = PTR_ERR(h_file); |
86dc4139 | 12264 | + else { |
027c5e7a | 12265 | + di_downgrade_lock(parent, AuLock_IR); |
c2b27bf2 AM |
12266 | + if (dbstart > cpg.bdst) |
12267 | + err = au_sio_cpup_simple(&cpg); | |
027c5e7a AM |
12268 | + if (!err) |
12269 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 12270 | + au_h_open_post(cpg.dentry, cpg.bsrc, h_file); |
027c5e7a | 12271 | + } |
027c5e7a AM |
12272 | + } else { /* copyup as wh and reopen */ |
12273 | + /* | |
12274 | + * since writable hfsplus branch is not supported, | |
12275 | + * h_open_pre/post() are unnecessary. | |
12276 | + */ | |
c2b27bf2 | 12277 | + err = au_ready_to_write_wh(file, len, cpg.bdst, pin); |
4a4d8108 | 12278 | + di_downgrade_lock(parent, AuLock_IR); |
4a4d8108 | 12279 | + } |
4a4d8108 AM |
12280 | + |
12281 | + if (!err) { | |
12282 | + au_pin_set_parent_lflag(pin, /*lflag*/0); | |
12283 | + goto out_dput; /* success */ | |
12284 | + } | |
12285 | + au_unpin(pin); | |
12286 | + goto out_unlock; | |
1facf9fc | 12287 | + |
4f0767ce | 12288 | +out_dgrade: |
4a4d8108 | 12289 | + di_downgrade_lock(parent, AuLock_IR); |
4f0767ce | 12290 | +out_unlock: |
4a4d8108 | 12291 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12292 | +out_dput: |
4a4d8108 | 12293 | + dput(parent); |
4f0767ce | 12294 | +out: |
1facf9fc | 12295 | + return err; |
12296 | +} | |
12297 | + | |
4a4d8108 AM |
12298 | +/* ---------------------------------------------------------------------- */ |
12299 | + | |
12300 | +int au_do_flush(struct file *file, fl_owner_t id, | |
12301 | + int (*flush)(struct file *file, fl_owner_t id)) | |
1facf9fc | 12302 | +{ |
4a4d8108 | 12303 | + int err; |
1facf9fc | 12304 | + struct super_block *sb; |
4a4d8108 | 12305 | + struct inode *inode; |
1facf9fc | 12306 | + |
c06a8ce3 AM |
12307 | + inode = file_inode(file); |
12308 | + sb = inode->i_sb; | |
4a4d8108 AM |
12309 | + si_noflush_read_lock(sb); |
12310 | + fi_read_lock(file); | |
b752ccd1 | 12311 | + ii_read_lock_child(inode); |
1facf9fc | 12312 | + |
4a4d8108 AM |
12313 | + err = flush(file, id); |
12314 | + au_cpup_attr_timesizes(inode); | |
1facf9fc | 12315 | + |
b752ccd1 | 12316 | + ii_read_unlock(inode); |
4a4d8108 | 12317 | + fi_read_unlock(file); |
1308ab2a | 12318 | + si_read_unlock(sb); |
dece6358 | 12319 | + return err; |
1facf9fc | 12320 | +} |
12321 | + | |
4a4d8108 AM |
12322 | +/* ---------------------------------------------------------------------- */ |
12323 | + | |
12324 | +static int au_file_refresh_by_inode(struct file *file, int *need_reopen) | |
1facf9fc | 12325 | +{ |
4a4d8108 | 12326 | + int err; |
4a4d8108 AM |
12327 | + struct au_pin pin; |
12328 | + struct au_finfo *finfo; | |
c2b27bf2 | 12329 | + struct dentry *parent, *hi_wh; |
4a4d8108 | 12330 | + struct inode *inode; |
1facf9fc | 12331 | + struct super_block *sb; |
c2b27bf2 AM |
12332 | + struct au_cp_generic cpg = { |
12333 | + .dentry = file->f_dentry, | |
12334 | + .bdst = -1, | |
12335 | + .bsrc = -1, | |
12336 | + .len = -1, | |
12337 | + .pin = &pin, | |
12338 | + .flags = AuCpup_DTIME | |
12339 | + }; | |
1facf9fc | 12340 | + |
4a4d8108 AM |
12341 | + FiMustWriteLock(file); |
12342 | + | |
12343 | + err = 0; | |
12344 | + finfo = au_fi(file); | |
c2b27bf2 AM |
12345 | + sb = cpg.dentry->d_sb; |
12346 | + inode = cpg.dentry->d_inode; | |
12347 | + cpg.bdst = au_ibstart(inode); | |
12348 | + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry)) | |
1308ab2a | 12349 | + goto out; |
dece6358 | 12350 | + |
c2b27bf2 AM |
12351 | + parent = dget_parent(cpg.dentry); |
12352 | + if (au_test_ro(sb, cpg.bdst, inode)) { | |
4a4d8108 | 12353 | + di_read_lock_parent(parent, !AuLock_IR); |
c2b27bf2 AM |
12354 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
12355 | + cpg.bdst = err; | |
4a4d8108 AM |
12356 | + di_read_unlock(parent, !AuLock_IR); |
12357 | + if (unlikely(err < 0)) | |
12358 | + goto out_parent; | |
12359 | + err = 0; | |
1facf9fc | 12360 | + } |
1facf9fc | 12361 | + |
4a4d8108 | 12362 | + di_read_lock_parent(parent, AuLock_IR); |
c2b27bf2 | 12363 | + hi_wh = au_hi_wh(inode, cpg.bdst); |
7f207e10 AM |
12364 | + if (!S_ISDIR(inode->i_mode) |
12365 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4a4d8108 | 12366 | + && au_plink_test(inode) |
c2b27bf2 AM |
12367 | + && !d_unhashed(cpg.dentry) |
12368 | + && cpg.bdst < au_dbstart(cpg.dentry)) { | |
12369 | + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst); | |
4a4d8108 AM |
12370 | + if (unlikely(err)) |
12371 | + goto out_unlock; | |
12372 | + | |
12373 | + /* always superio. */ | |
c2b27bf2 | 12374 | + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 | 12375 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
367653fa | 12376 | + if (!err) { |
c2b27bf2 | 12377 | + err = au_sio_cpup_simple(&cpg); |
367653fa AM |
12378 | + au_unpin(&pin); |
12379 | + } | |
4a4d8108 AM |
12380 | + } else if (hi_wh) { |
12381 | + /* already copied-up after unlink */ | |
c2b27bf2 | 12382 | + err = au_reopen_wh(file, cpg.bdst, hi_wh); |
4a4d8108 AM |
12383 | + *need_reopen = 0; |
12384 | + } | |
1facf9fc | 12385 | + |
4f0767ce | 12386 | +out_unlock: |
4a4d8108 | 12387 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 12388 | +out_parent: |
4a4d8108 | 12389 | + dput(parent); |
4f0767ce | 12390 | +out: |
1308ab2a | 12391 | + return err; |
dece6358 | 12392 | +} |
1facf9fc | 12393 | + |
4a4d8108 | 12394 | +static void au_do_refresh_dir(struct file *file) |
dece6358 | 12395 | +{ |
4a4d8108 AM |
12396 | + aufs_bindex_t bindex, bend, new_bindex, brid; |
12397 | + struct au_hfile *p, tmp, *q; | |
12398 | + struct au_finfo *finfo; | |
1308ab2a | 12399 | + struct super_block *sb; |
4a4d8108 | 12400 | + struct au_fidir *fidir; |
1facf9fc | 12401 | + |
4a4d8108 | 12402 | + FiMustWriteLock(file); |
1facf9fc | 12403 | + |
4a4d8108 AM |
12404 | + sb = file->f_dentry->d_sb; |
12405 | + finfo = au_fi(file); | |
12406 | + fidir = finfo->fi_hdir; | |
12407 | + AuDebugOn(!fidir); | |
12408 | + p = fidir->fd_hfile + finfo->fi_btop; | |
12409 | + brid = p->hf_br->br_id; | |
12410 | + bend = fidir->fd_bbot; | |
12411 | + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) { | |
12412 | + if (!p->hf_file) | |
12413 | + continue; | |
1308ab2a | 12414 | + |
4a4d8108 AM |
12415 | + new_bindex = au_br_index(sb, p->hf_br->br_id); |
12416 | + if (new_bindex == bindex) | |
12417 | + continue; | |
12418 | + if (new_bindex < 0) { | |
12419 | + au_set_h_fptr(file, bindex, NULL); | |
12420 | + continue; | |
12421 | + } | |
1308ab2a | 12422 | + |
4a4d8108 AM |
12423 | + /* swap two lower inode, and loop again */ |
12424 | + q = fidir->fd_hfile + new_bindex; | |
12425 | + tmp = *q; | |
12426 | + *q = *p; | |
12427 | + *p = tmp; | |
12428 | + if (tmp.hf_file) { | |
12429 | + bindex--; | |
12430 | + p--; | |
12431 | + } | |
12432 | + } | |
1308ab2a | 12433 | + |
4a4d8108 | 12434 | + p = fidir->fd_hfile; |
027c5e7a | 12435 | + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) { |
4a4d8108 AM |
12436 | + bend = au_sbend(sb); |
12437 | + for (finfo->fi_btop = 0; finfo->fi_btop <= bend; | |
12438 | + finfo->fi_btop++, p++) | |
12439 | + if (p->hf_file) { | |
c06a8ce3 | 12440 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12441 | + break; |
c1595e42 | 12442 | + au_hfput(p, file); |
4a4d8108 AM |
12443 | + } |
12444 | + } else { | |
12445 | + bend = au_br_index(sb, brid); | |
12446 | + for (finfo->fi_btop = 0; finfo->fi_btop < bend; | |
12447 | + finfo->fi_btop++, p++) | |
12448 | + if (p->hf_file) | |
12449 | + au_hfput(p, file); | |
12450 | + bend = au_sbend(sb); | |
12451 | + } | |
1308ab2a | 12452 | + |
4a4d8108 AM |
12453 | + p = fidir->fd_hfile + bend; |
12454 | + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop; | |
12455 | + fidir->fd_bbot--, p--) | |
12456 | + if (p->hf_file) { | |
c06a8ce3 | 12457 | + if (file_inode(p->hf_file)) |
4a4d8108 | 12458 | + break; |
c1595e42 | 12459 | + au_hfput(p, file); |
4a4d8108 AM |
12460 | + } |
12461 | + AuDebugOn(fidir->fd_bbot < finfo->fi_btop); | |
1308ab2a | 12462 | +} |
12463 | + | |
4a4d8108 AM |
12464 | +/* |
12465 | + * after branch manipulating, refresh the file. | |
12466 | + */ | |
12467 | +static int refresh_file(struct file *file, int (*reopen)(struct file *file)) | |
1facf9fc | 12468 | +{ |
4a4d8108 AM |
12469 | + int err, need_reopen; |
12470 | + aufs_bindex_t bend, bindex; | |
12471 | + struct dentry *dentry; | |
1308ab2a | 12472 | + struct au_finfo *finfo; |
4a4d8108 | 12473 | + struct au_hfile *hfile; |
1facf9fc | 12474 | + |
4a4d8108 | 12475 | + dentry = file->f_dentry; |
1308ab2a | 12476 | + finfo = au_fi(file); |
4a4d8108 AM |
12477 | + if (!finfo->fi_hdir) { |
12478 | + hfile = &finfo->fi_htop; | |
12479 | + AuDebugOn(!hfile->hf_file); | |
12480 | + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id); | |
12481 | + AuDebugOn(bindex < 0); | |
12482 | + if (bindex != finfo->fi_btop) | |
12483 | + au_set_fbstart(file, bindex); | |
12484 | + } else { | |
12485 | + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1); | |
12486 | + if (unlikely(err)) | |
12487 | + goto out; | |
12488 | + au_do_refresh_dir(file); | |
12489 | + } | |
1facf9fc | 12490 | + |
4a4d8108 AM |
12491 | + err = 0; |
12492 | + need_reopen = 1; | |
12493 | + if (!au_test_mmapped(file)) | |
12494 | + err = au_file_refresh_by_inode(file, &need_reopen); | |
027c5e7a | 12495 | + if (!err && need_reopen && !d_unlinked(dentry)) |
4a4d8108 AM |
12496 | + err = reopen(file); |
12497 | + if (!err) { | |
12498 | + au_update_figen(file); | |
12499 | + goto out; /* success */ | |
12500 | + } | |
12501 | + | |
12502 | + /* error, close all lower files */ | |
12503 | + if (finfo->fi_hdir) { | |
12504 | + bend = au_fbend_dir(file); | |
12505 | + for (bindex = au_fbstart(file); bindex <= bend; bindex++) | |
12506 | + au_set_h_fptr(file, bindex, NULL); | |
12507 | + } | |
1facf9fc | 12508 | + |
4f0767ce | 12509 | +out: |
1facf9fc | 12510 | + return err; |
12511 | +} | |
12512 | + | |
4a4d8108 AM |
12513 | +/* common function to regular file and dir */ |
12514 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
12515 | + int wlock) | |
dece6358 | 12516 | +{ |
1308ab2a | 12517 | + int err; |
4a4d8108 AM |
12518 | + unsigned int sigen, figen; |
12519 | + aufs_bindex_t bstart; | |
12520 | + unsigned char pseudo_link; | |
12521 | + struct dentry *dentry; | |
12522 | + struct inode *inode; | |
1facf9fc | 12523 | + |
4a4d8108 AM |
12524 | + err = 0; |
12525 | + dentry = file->f_dentry; | |
12526 | + inode = dentry->d_inode; | |
4a4d8108 AM |
12527 | + sigen = au_sigen(dentry->d_sb); |
12528 | + fi_write_lock(file); | |
12529 | + figen = au_figen(file); | |
12530 | + di_write_lock_child(dentry); | |
12531 | + bstart = au_dbstart(dentry); | |
12532 | + pseudo_link = (bstart != au_ibstart(inode)); | |
12533 | + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) { | |
12534 | + if (!wlock) { | |
12535 | + di_downgrade_lock(dentry, AuLock_IR); | |
12536 | + fi_downgrade_lock(file); | |
12537 | + } | |
12538 | + goto out; /* success */ | |
12539 | + } | |
dece6358 | 12540 | + |
4a4d8108 | 12541 | + AuDbg("sigen %d, figen %d\n", sigen, figen); |
027c5e7a | 12542 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 | 12543 | + err = au_reval_dpath(dentry, sigen); |
027c5e7a | 12544 | + AuDebugOn(!err && au_digen_test(dentry, sigen)); |
4a4d8108 | 12545 | + } |
dece6358 | 12546 | + |
027c5e7a AM |
12547 | + if (!err) |
12548 | + err = refresh_file(file, reopen); | |
4a4d8108 AM |
12549 | + if (!err) { |
12550 | + if (!wlock) { | |
12551 | + di_downgrade_lock(dentry, AuLock_IR); | |
12552 | + fi_downgrade_lock(file); | |
12553 | + } | |
12554 | + } else { | |
12555 | + di_write_unlock(dentry); | |
12556 | + fi_write_unlock(file); | |
12557 | + } | |
1facf9fc | 12558 | + |
4f0767ce | 12559 | +out: |
1308ab2a | 12560 | + return err; |
12561 | +} | |
1facf9fc | 12562 | + |
4a4d8108 AM |
12563 | +/* ---------------------------------------------------------------------- */ |
12564 | + | |
12565 | +/* cf. aufs_nopage() */ | |
12566 | +/* for madvise(2) */ | |
12567 | +static int aufs_readpage(struct file *file __maybe_unused, struct page *page) | |
1308ab2a | 12568 | +{ |
4a4d8108 AM |
12569 | + unlock_page(page); |
12570 | + return 0; | |
12571 | +} | |
1facf9fc | 12572 | + |
4a4d8108 AM |
12573 | +/* it will never be called, but necessary to support O_DIRECT */ |
12574 | +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb, | |
076b876e | 12575 | + struct iov_iter *iter, loff_t offset) |
4a4d8108 | 12576 | +{ BUG(); return 0; } |
1facf9fc | 12577 | + |
4a4d8108 AM |
12578 | +/* |
12579 | + * it will never be called, but madvise and fadvise behaves differently | |
12580 | + * when get_xip_mem is defined | |
12581 | + */ | |
12582 | +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff, | |
12583 | + int create, void **kmem, unsigned long *pfn) | |
12584 | +{ BUG(); return 0; } | |
1facf9fc | 12585 | + |
4a4d8108 AM |
12586 | +/* they will never be called. */ |
12587 | +#ifdef CONFIG_AUFS_DEBUG | |
12588 | +static int aufs_write_begin(struct file *file, struct address_space *mapping, | |
12589 | + loff_t pos, unsigned len, unsigned flags, | |
12590 | + struct page **pagep, void **fsdata) | |
12591 | +{ AuUnsupport(); return 0; } | |
12592 | +static int aufs_write_end(struct file *file, struct address_space *mapping, | |
12593 | + loff_t pos, unsigned len, unsigned copied, | |
12594 | + struct page *page, void *fsdata) | |
12595 | +{ AuUnsupport(); return 0; } | |
12596 | +static int aufs_writepage(struct page *page, struct writeback_control *wbc) | |
12597 | +{ AuUnsupport(); return 0; } | |
1308ab2a | 12598 | + |
4a4d8108 AM |
12599 | +static int aufs_set_page_dirty(struct page *page) |
12600 | +{ AuUnsupport(); return 0; } | |
392086de AM |
12601 | +static void aufs_invalidatepage(struct page *page, unsigned int offset, |
12602 | + unsigned int length) | |
4a4d8108 AM |
12603 | +{ AuUnsupport(); } |
12604 | +static int aufs_releasepage(struct page *page, gfp_t gfp) | |
12605 | +{ AuUnsupport(); return 0; } | |
12606 | +static int aufs_migratepage(struct address_space *mapping, struct page *newpage, | |
7eafdf33 | 12607 | + struct page *page, enum migrate_mode mode) |
4a4d8108 AM |
12608 | +{ AuUnsupport(); return 0; } |
12609 | +static int aufs_launder_page(struct page *page) | |
12610 | +{ AuUnsupport(); return 0; } | |
12611 | +static int aufs_is_partially_uptodate(struct page *page, | |
38d290e6 JR |
12612 | + unsigned long from, |
12613 | + unsigned long count) | |
4a4d8108 | 12614 | +{ AuUnsupport(); return 0; } |
392086de AM |
12615 | +static void aufs_is_dirty_writeback(struct page *page, bool *dirty, |
12616 | + bool *writeback) | |
12617 | +{ AuUnsupport(); } | |
4a4d8108 AM |
12618 | +static int aufs_error_remove_page(struct address_space *mapping, |
12619 | + struct page *page) | |
12620 | +{ AuUnsupport(); return 0; } | |
b4510431 AM |
12621 | +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file, |
12622 | + sector_t *span) | |
12623 | +{ AuUnsupport(); return 0; } | |
12624 | +static void aufs_swap_deactivate(struct file *file) | |
12625 | +{ AuUnsupport(); } | |
4a4d8108 AM |
12626 | +#endif /* CONFIG_AUFS_DEBUG */ |
12627 | + | |
12628 | +const struct address_space_operations aufs_aop = { | |
12629 | + .readpage = aufs_readpage, | |
12630 | + .direct_IO = aufs_direct_IO, | |
12631 | + .get_xip_mem = aufs_get_xip_mem, | |
12632 | +#ifdef CONFIG_AUFS_DEBUG | |
12633 | + .writepage = aufs_writepage, | |
4a4d8108 AM |
12634 | + /* no writepages, because of writepage */ |
12635 | + .set_page_dirty = aufs_set_page_dirty, | |
12636 | + /* no readpages, because of readpage */ | |
12637 | + .write_begin = aufs_write_begin, | |
12638 | + .write_end = aufs_write_end, | |
12639 | + /* no bmap, no block device */ | |
12640 | + .invalidatepage = aufs_invalidatepage, | |
12641 | + .releasepage = aufs_releasepage, | |
12642 | + .migratepage = aufs_migratepage, | |
12643 | + .launder_page = aufs_launder_page, | |
12644 | + .is_partially_uptodate = aufs_is_partially_uptodate, | |
392086de | 12645 | + .is_dirty_writeback = aufs_is_dirty_writeback, |
b4510431 AM |
12646 | + .error_remove_page = aufs_error_remove_page, |
12647 | + .swap_activate = aufs_swap_activate, | |
12648 | + .swap_deactivate = aufs_swap_deactivate | |
4a4d8108 | 12649 | +#endif /* CONFIG_AUFS_DEBUG */ |
dece6358 | 12650 | +}; |
7f207e10 AM |
12651 | diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h |
12652 | --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
12653 | +++ linux/fs/aufs/file.h 2015-01-25 13:00:38.631047076 +0100 |
12654 | @@ -0,0 +1,284 @@ | |
4a4d8108 | 12655 | +/* |
523b37e3 | 12656 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
12657 | + * |
12658 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12659 | + * it under the terms of the GNU General Public License as published by | |
12660 | + * the Free Software Foundation; either version 2 of the License, or | |
12661 | + * (at your option) any later version. | |
12662 | + * | |
12663 | + * This program is distributed in the hope that it will be useful, | |
12664 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12665 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12666 | + * GNU General Public License for more details. | |
12667 | + * | |
12668 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12669 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 12670 | + */ |
1facf9fc | 12671 | + |
4a4d8108 AM |
12672 | +/* |
12673 | + * file operations | |
12674 | + */ | |
1facf9fc | 12675 | + |
4a4d8108 AM |
12676 | +#ifndef __AUFS_FILE_H__ |
12677 | +#define __AUFS_FILE_H__ | |
1facf9fc | 12678 | + |
4a4d8108 | 12679 | +#ifdef __KERNEL__ |
1facf9fc | 12680 | + |
2cbb1c4b | 12681 | +#include <linux/file.h> |
4a4d8108 AM |
12682 | +#include <linux/fs.h> |
12683 | +#include <linux/poll.h> | |
4a4d8108 | 12684 | +#include "rwsem.h" |
1facf9fc | 12685 | + |
4a4d8108 AM |
12686 | +struct au_branch; |
12687 | +struct au_hfile { | |
12688 | + struct file *hf_file; | |
12689 | + struct au_branch *hf_br; | |
12690 | +}; | |
1facf9fc | 12691 | + |
4a4d8108 AM |
12692 | +struct au_vdir; |
12693 | +struct au_fidir { | |
12694 | + aufs_bindex_t fd_bbot; | |
12695 | + aufs_bindex_t fd_nent; | |
12696 | + struct au_vdir *fd_vdir_cache; | |
12697 | + struct au_hfile fd_hfile[]; | |
12698 | +}; | |
1facf9fc | 12699 | + |
4a4d8108 | 12700 | +static inline int au_fidir_sz(int nent) |
dece6358 | 12701 | +{ |
4f0767ce JR |
12702 | + AuDebugOn(nent < 0); |
12703 | + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent; | |
4a4d8108 | 12704 | +} |
1facf9fc | 12705 | + |
4a4d8108 AM |
12706 | +struct au_finfo { |
12707 | + atomic_t fi_generation; | |
dece6358 | 12708 | + |
4a4d8108 AM |
12709 | + struct au_rwsem fi_rwsem; |
12710 | + aufs_bindex_t fi_btop; | |
12711 | + | |
12712 | + /* do not union them */ | |
12713 | + struct { /* for non-dir */ | |
12714 | + struct au_hfile fi_htop; | |
2cbb1c4b | 12715 | + atomic_t fi_mmapped; |
4a4d8108 AM |
12716 | + }; |
12717 | + struct au_fidir *fi_hdir; /* for dir only */ | |
523b37e3 AM |
12718 | + |
12719 | + struct hlist_node fi_hlist; | |
12720 | + struct file *fi_file; /* very ugly */ | |
4a4d8108 | 12721 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 12722 | + |
4a4d8108 | 12723 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12724 | + |
4a4d8108 AM |
12725 | +/* file.c */ |
12726 | +extern const struct address_space_operations aufs_aop; | |
12727 | +unsigned int au_file_roflags(unsigned int flags); | |
12728 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 12729 | + struct file *file, int force_wr); |
4a4d8108 AM |
12730 | +int au_do_open(struct file *file, int (*open)(struct file *file, int flags), |
12731 | + struct au_fidir *fidir); | |
12732 | +int au_reopen_nondir(struct file *file); | |
12733 | +struct au_pin; | |
12734 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin); | |
12735 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
12736 | + int wlock); | |
12737 | +int au_do_flush(struct file *file, fl_owner_t id, | |
12738 | + int (*flush)(struct file *file, fl_owner_t id)); | |
1facf9fc | 12739 | + |
4a4d8108 AM |
12740 | +/* poll.c */ |
12741 | +#ifdef CONFIG_AUFS_POLL | |
12742 | +unsigned int aufs_poll(struct file *file, poll_table *wait); | |
12743 | +#endif | |
1facf9fc | 12744 | + |
4a4d8108 AM |
12745 | +#ifdef CONFIG_AUFS_BR_HFSPLUS |
12746 | +/* hfsplus.c */ | |
392086de AM |
12747 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
12748 | + int force_wr); | |
4a4d8108 AM |
12749 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
12750 | + struct file *h_file); | |
12751 | +#else | |
c1595e42 JR |
12752 | +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry, |
12753 | + aufs_bindex_t bindex, int force_wr) | |
4a4d8108 AM |
12754 | +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex, |
12755 | + struct file *h_file); | |
12756 | +#endif | |
1facf9fc | 12757 | + |
4a4d8108 AM |
12758 | +/* f_op.c */ |
12759 | +extern const struct file_operations aufs_file_fop; | |
4a4d8108 AM |
12760 | +int au_do_open_nondir(struct file *file, int flags); |
12761 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file); | |
12762 | + | |
4a4d8108 AM |
12763 | +/* finfo.c */ |
12764 | +void au_hfput(struct au_hfile *hf, struct file *file); | |
12765 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, | |
12766 | + struct file *h_file); | |
1facf9fc | 12767 | + |
4a4d8108 | 12768 | +void au_update_figen(struct file *file); |
4a4d8108 AM |
12769 | +struct au_fidir *au_fidir_alloc(struct super_block *sb); |
12770 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr); | |
1facf9fc | 12771 | + |
4a4d8108 AM |
12772 | +void au_fi_init_once(void *_fi); |
12773 | +void au_finfo_fin(struct file *file); | |
12774 | +int au_finfo_init(struct file *file, struct au_fidir *fidir); | |
1facf9fc | 12775 | + |
4a4d8108 AM |
12776 | +/* ioctl.c */ |
12777 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
12778 | +#ifdef CONFIG_COMPAT |
12779 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
12780 | + unsigned long arg); | |
c2b27bf2 AM |
12781 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
12782 | + unsigned long arg); | |
b752ccd1 | 12783 | +#endif |
1facf9fc | 12784 | + |
4a4d8108 | 12785 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12786 | + |
4a4d8108 AM |
12787 | +static inline struct au_finfo *au_fi(struct file *file) |
12788 | +{ | |
38d290e6 | 12789 | + return file->private_data; |
4a4d8108 | 12790 | +} |
1facf9fc | 12791 | + |
4a4d8108 | 12792 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 12793 | + |
4a4d8108 AM |
12794 | +/* |
12795 | + * fi_read_lock, fi_write_lock, | |
12796 | + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock | |
12797 | + */ | |
12798 | +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem); | |
1308ab2a | 12799 | + |
4a4d8108 AM |
12800 | +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem) |
12801 | +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem) | |
12802 | +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem) | |
1facf9fc | 12803 | + |
1308ab2a | 12804 | +/* ---------------------------------------------------------------------- */ |
12805 | + | |
4a4d8108 AM |
12806 | +/* todo: hard/soft set? */ |
12807 | +static inline aufs_bindex_t au_fbstart(struct file *file) | |
dece6358 | 12808 | +{ |
4a4d8108 AM |
12809 | + FiMustAnyLock(file); |
12810 | + return au_fi(file)->fi_btop; | |
12811 | +} | |
dece6358 | 12812 | + |
4a4d8108 AM |
12813 | +static inline aufs_bindex_t au_fbend_dir(struct file *file) |
12814 | +{ | |
12815 | + FiMustAnyLock(file); | |
12816 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12817 | + return au_fi(file)->fi_hdir->fd_bbot; | |
12818 | +} | |
1facf9fc | 12819 | + |
4a4d8108 AM |
12820 | +static inline struct au_vdir *au_fvdir_cache(struct file *file) |
12821 | +{ | |
12822 | + FiMustAnyLock(file); | |
12823 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12824 | + return au_fi(file)->fi_hdir->fd_vdir_cache; | |
12825 | +} | |
1facf9fc | 12826 | + |
4a4d8108 AM |
12827 | +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex) |
12828 | +{ | |
12829 | + FiMustWriteLock(file); | |
12830 | + au_fi(file)->fi_btop = bindex; | |
12831 | +} | |
1facf9fc | 12832 | + |
4a4d8108 AM |
12833 | +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex) |
12834 | +{ | |
12835 | + FiMustWriteLock(file); | |
12836 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12837 | + au_fi(file)->fi_hdir->fd_bbot = bindex; | |
12838 | +} | |
1308ab2a | 12839 | + |
4a4d8108 AM |
12840 | +static inline void au_set_fvdir_cache(struct file *file, |
12841 | + struct au_vdir *vdir_cache) | |
12842 | +{ | |
12843 | + FiMustWriteLock(file); | |
12844 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12845 | + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache; | |
12846 | +} | |
dece6358 | 12847 | + |
4a4d8108 AM |
12848 | +static inline struct file *au_hf_top(struct file *file) |
12849 | +{ | |
12850 | + FiMustAnyLock(file); | |
12851 | + AuDebugOn(au_fi(file)->fi_hdir); | |
12852 | + return au_fi(file)->fi_htop.hf_file; | |
12853 | +} | |
1facf9fc | 12854 | + |
4a4d8108 AM |
12855 | +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex) |
12856 | +{ | |
12857 | + FiMustAnyLock(file); | |
12858 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
12859 | + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file; | |
dece6358 AM |
12860 | +} |
12861 | + | |
4a4d8108 AM |
12862 | +/* todo: memory barrier? */ |
12863 | +static inline unsigned int au_figen(struct file *f) | |
dece6358 | 12864 | +{ |
4a4d8108 AM |
12865 | + return atomic_read(&au_fi(f)->fi_generation); |
12866 | +} | |
dece6358 | 12867 | + |
2cbb1c4b JR |
12868 | +static inline void au_set_mmapped(struct file *f) |
12869 | +{ | |
12870 | + if (atomic_inc_return(&au_fi(f)->fi_mmapped)) | |
12871 | + return; | |
0c3ec466 | 12872 | + pr_warn("fi_mmapped wrapped around\n"); |
2cbb1c4b JR |
12873 | + while (!atomic_inc_return(&au_fi(f)->fi_mmapped)) |
12874 | + ; | |
12875 | +} | |
12876 | + | |
12877 | +static inline void au_unset_mmapped(struct file *f) | |
12878 | +{ | |
12879 | + atomic_dec(&au_fi(f)->fi_mmapped); | |
12880 | +} | |
12881 | + | |
4a4d8108 AM |
12882 | +static inline int au_test_mmapped(struct file *f) |
12883 | +{ | |
2cbb1c4b JR |
12884 | + return atomic_read(&au_fi(f)->fi_mmapped); |
12885 | +} | |
12886 | + | |
12887 | +/* customize vma->vm_file */ | |
12888 | + | |
12889 | +static inline void au_do_vm_file_reset(struct vm_area_struct *vma, | |
12890 | + struct file *file) | |
12891 | +{ | |
53392da6 AM |
12892 | + struct file *f; |
12893 | + | |
12894 | + f = vma->vm_file; | |
2cbb1c4b JR |
12895 | + get_file(file); |
12896 | + vma->vm_file = file; | |
53392da6 | 12897 | + fput(f); |
2cbb1c4b JR |
12898 | +} |
12899 | + | |
12900 | +#ifdef CONFIG_MMU | |
12901 | +#define AuDbgVmRegion(file, vma) do {} while (0) | |
12902 | + | |
12903 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
12904 | + struct file *file) | |
12905 | +{ | |
12906 | + au_do_vm_file_reset(vma, file); | |
12907 | +} | |
12908 | +#else | |
12909 | +#define AuDbgVmRegion(file, vma) \ | |
12910 | + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file)) | |
12911 | + | |
12912 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
12913 | + struct file *file) | |
12914 | +{ | |
53392da6 AM |
12915 | + struct file *f; |
12916 | + | |
2cbb1c4b | 12917 | + au_do_vm_file_reset(vma, file); |
53392da6 | 12918 | + f = vma->vm_region->vm_file; |
2cbb1c4b JR |
12919 | + get_file(file); |
12920 | + vma->vm_region->vm_file = file; | |
53392da6 | 12921 | + fput(f); |
2cbb1c4b JR |
12922 | +} |
12923 | +#endif /* CONFIG_MMU */ | |
12924 | + | |
12925 | +/* handle vma->vm_prfile */ | |
fb47a38f | 12926 | +static inline void au_vm_prfile_set(struct vm_area_struct *vma, |
2cbb1c4b JR |
12927 | + struct file *file) |
12928 | +{ | |
2cbb1c4b JR |
12929 | + get_file(file); |
12930 | + vma->vm_prfile = file; | |
12931 | +#ifndef CONFIG_MMU | |
12932 | + get_file(file); | |
12933 | + vma->vm_region->vm_prfile = file; | |
12934 | +#endif | |
fb47a38f | 12935 | +} |
1308ab2a | 12936 | + |
4a4d8108 AM |
12937 | +#endif /* __KERNEL__ */ |
12938 | +#endif /* __AUFS_FILE_H__ */ | |
7f207e10 AM |
12939 | diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c |
12940 | --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 12941 | +++ linux/fs/aufs/finfo.c 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 12942 | @@ -0,0 +1,156 @@ |
4a4d8108 | 12943 | +/* |
523b37e3 | 12944 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
12945 | + * |
12946 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12947 | + * it under the terms of the GNU General Public License as published by | |
12948 | + * the Free Software Foundation; either version 2 of the License, or | |
12949 | + * (at your option) any later version. | |
12950 | + * | |
12951 | + * This program is distributed in the hope that it will be useful, | |
12952 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12953 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12954 | + * GNU General Public License for more details. | |
12955 | + * | |
12956 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12957 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 12958 | + */ |
1308ab2a | 12959 | + |
4a4d8108 AM |
12960 | +/* |
12961 | + * file private data | |
12962 | + */ | |
1facf9fc | 12963 | + |
4a4d8108 | 12964 | +#include "aufs.h" |
1facf9fc | 12965 | + |
4a4d8108 AM |
12966 | +void au_hfput(struct au_hfile *hf, struct file *file) |
12967 | +{ | |
12968 | + /* todo: direct access f_flags */ | |
2cbb1c4b | 12969 | + if (vfsub_file_flags(file) & __FMODE_EXEC) |
4a4d8108 AM |
12970 | + allow_write_access(hf->hf_file); |
12971 | + fput(hf->hf_file); | |
12972 | + hf->hf_file = NULL; | |
e49829fe | 12973 | + atomic_dec(&hf->hf_br->br_count); |
4a4d8108 AM |
12974 | + hf->hf_br = NULL; |
12975 | +} | |
1facf9fc | 12976 | + |
4a4d8108 AM |
12977 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val) |
12978 | +{ | |
12979 | + struct au_finfo *finfo = au_fi(file); | |
12980 | + struct au_hfile *hf; | |
12981 | + struct au_fidir *fidir; | |
12982 | + | |
12983 | + fidir = finfo->fi_hdir; | |
12984 | + if (!fidir) { | |
12985 | + AuDebugOn(finfo->fi_btop != bindex); | |
12986 | + hf = &finfo->fi_htop; | |
12987 | + } else | |
12988 | + hf = fidir->fd_hfile + bindex; | |
12989 | + | |
12990 | + if (hf && hf->hf_file) | |
12991 | + au_hfput(hf, file); | |
12992 | + if (val) { | |
12993 | + FiMustWriteLock(file); | |
12994 | + hf->hf_file = val; | |
12995 | + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex); | |
1308ab2a | 12996 | + } |
4a4d8108 | 12997 | +} |
1facf9fc | 12998 | + |
4a4d8108 AM |
12999 | +void au_update_figen(struct file *file) |
13000 | +{ | |
13001 | + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry)); | |
13002 | + /* smp_mb(); */ /* atomic_set */ | |
1facf9fc | 13003 | +} |
13004 | + | |
4a4d8108 AM |
13005 | +/* ---------------------------------------------------------------------- */ |
13006 | + | |
4a4d8108 AM |
13007 | +struct au_fidir *au_fidir_alloc(struct super_block *sb) |
13008 | +{ | |
13009 | + struct au_fidir *fidir; | |
13010 | + int nbr; | |
13011 | + | |
13012 | + nbr = au_sbend(sb) + 1; | |
13013 | + if (nbr < 2) | |
13014 | + nbr = 2; /* initial allocate for 2 branches */ | |
13015 | + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS); | |
13016 | + if (fidir) { | |
13017 | + fidir->fd_bbot = -1; | |
13018 | + fidir->fd_nent = nbr; | |
13019 | + fidir->fd_vdir_cache = NULL; | |
13020 | + } | |
13021 | + | |
13022 | + return fidir; | |
13023 | +} | |
13024 | + | |
13025 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr) | |
13026 | +{ | |
13027 | + int err; | |
13028 | + struct au_fidir *fidir, *p; | |
13029 | + | |
13030 | + AuRwMustWriteLock(&finfo->fi_rwsem); | |
13031 | + fidir = finfo->fi_hdir; | |
13032 | + AuDebugOn(!fidir); | |
13033 | + | |
13034 | + err = -ENOMEM; | |
13035 | + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr), | |
13036 | + GFP_NOFS); | |
13037 | + if (p) { | |
13038 | + p->fd_nent = nbr; | |
13039 | + finfo->fi_hdir = p; | |
13040 | + err = 0; | |
13041 | + } | |
1facf9fc | 13042 | + |
dece6358 | 13043 | + return err; |
1facf9fc | 13044 | +} |
1308ab2a | 13045 | + |
13046 | +/* ---------------------------------------------------------------------- */ | |
13047 | + | |
4a4d8108 | 13048 | +void au_finfo_fin(struct file *file) |
1308ab2a | 13049 | +{ |
4a4d8108 AM |
13050 | + struct au_finfo *finfo; |
13051 | + | |
7f207e10 AM |
13052 | + au_nfiles_dec(file->f_dentry->d_sb); |
13053 | + | |
4a4d8108 AM |
13054 | + finfo = au_fi(file); |
13055 | + AuDebugOn(finfo->fi_hdir); | |
13056 | + AuRwDestroy(&finfo->fi_rwsem); | |
13057 | + au_cache_free_finfo(finfo); | |
1308ab2a | 13058 | +} |
1308ab2a | 13059 | + |
e49829fe | 13060 | +void au_fi_init_once(void *_finfo) |
4a4d8108 | 13061 | +{ |
e49829fe | 13062 | + struct au_finfo *finfo = _finfo; |
2cbb1c4b | 13063 | + static struct lock_class_key aufs_fi; |
1308ab2a | 13064 | + |
e49829fe JR |
13065 | + au_rw_init(&finfo->fi_rwsem); |
13066 | + au_rw_class(&finfo->fi_rwsem, &aufs_fi); | |
4a4d8108 | 13067 | +} |
1308ab2a | 13068 | + |
4a4d8108 AM |
13069 | +int au_finfo_init(struct file *file, struct au_fidir *fidir) |
13070 | +{ | |
1716fcea | 13071 | + int err; |
4a4d8108 AM |
13072 | + struct au_finfo *finfo; |
13073 | + struct dentry *dentry; | |
13074 | + | |
13075 | + err = -ENOMEM; | |
13076 | + dentry = file->f_dentry; | |
13077 | + finfo = au_cache_alloc_finfo(); | |
13078 | + if (unlikely(!finfo)) | |
13079 | + goto out; | |
13080 | + | |
13081 | + err = 0; | |
7f207e10 | 13082 | + au_nfiles_inc(dentry->d_sb); |
1716fcea AM |
13083 | + /* verbose coding for lock class name */ |
13084 | + if (!fidir) | |
13085 | + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO); | |
13086 | + else | |
13087 | + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO); | |
4a4d8108 AM |
13088 | + au_rw_write_lock(&finfo->fi_rwsem); |
13089 | + finfo->fi_btop = -1; | |
13090 | + finfo->fi_hdir = fidir; | |
13091 | + atomic_set(&finfo->fi_generation, au_digen(dentry)); | |
13092 | + /* smp_mb(); */ /* atomic_set */ | |
13093 | + | |
13094 | + file->private_data = finfo; | |
13095 | + | |
13096 | +out: | |
13097 | + return err; | |
13098 | +} | |
7f207e10 AM |
13099 | diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c |
13100 | --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 13101 | +++ linux/fs/aufs/f_op.c 2015-01-25 13:00:38.631047076 +0100 |
076b876e | 13102 | @@ -0,0 +1,813 @@ |
dece6358 | 13103 | +/* |
523b37e3 | 13104 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
dece6358 AM |
13105 | + * |
13106 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13107 | + * it under the terms of the GNU General Public License as published by | |
13108 | + * the Free Software Foundation; either version 2 of the License, or | |
13109 | + * (at your option) any later version. | |
13110 | + * | |
13111 | + * This program is distributed in the hope that it will be useful, | |
13112 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13113 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13114 | + * GNU General Public License for more details. | |
13115 | + * | |
13116 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13117 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 13118 | + */ |
1facf9fc | 13119 | + |
13120 | +/* | |
4a4d8108 | 13121 | + * file and vm operations |
1facf9fc | 13122 | + */ |
dece6358 | 13123 | + |
86dc4139 | 13124 | +#include <linux/aio.h> |
4a4d8108 AM |
13125 | +#include <linux/fs_stack.h> |
13126 | +#include <linux/mman.h> | |
4a4d8108 | 13127 | +#include <linux/security.h> |
dece6358 AM |
13128 | +#include "aufs.h" |
13129 | + | |
4a4d8108 | 13130 | +int au_do_open_nondir(struct file *file, int flags) |
1facf9fc | 13131 | +{ |
4a4d8108 AM |
13132 | + int err; |
13133 | + aufs_bindex_t bindex; | |
13134 | + struct file *h_file; | |
13135 | + struct dentry *dentry; | |
13136 | + struct au_finfo *finfo; | |
38d290e6 | 13137 | + struct inode *h_inode; |
4a4d8108 AM |
13138 | + |
13139 | + FiMustWriteLock(file); | |
13140 | + | |
523b37e3 | 13141 | + err = 0; |
4a4d8108 AM |
13142 | + dentry = file->f_dentry; |
13143 | + finfo = au_fi(file); | |
13144 | + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop)); | |
2cbb1c4b | 13145 | + atomic_set(&finfo->fi_mmapped, 0); |
4a4d8108 | 13146 | + bindex = au_dbstart(dentry); |
392086de | 13147 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
4a4d8108 AM |
13148 | + if (IS_ERR(h_file)) |
13149 | + err = PTR_ERR(h_file); | |
13150 | + else { | |
38d290e6 JR |
13151 | + if ((flags & __O_TMPFILE) |
13152 | + && !(flags & O_EXCL)) { | |
13153 | + h_inode = file_inode(h_file); | |
13154 | + spin_lock(&h_inode->i_lock); | |
13155 | + h_inode->i_state |= I_LINKABLE; | |
13156 | + spin_unlock(&h_inode->i_lock); | |
13157 | + } | |
4a4d8108 AM |
13158 | + au_set_fbstart(file, bindex); |
13159 | + au_set_h_fptr(file, bindex, h_file); | |
13160 | + au_update_figen(file); | |
13161 | + /* todo: necessary? */ | |
13162 | + /* file->f_ra = h_file->f_ra; */ | |
13163 | + } | |
027c5e7a | 13164 | + |
4a4d8108 | 13165 | + return err; |
1facf9fc | 13166 | +} |
13167 | + | |
4a4d8108 AM |
13168 | +static int aufs_open_nondir(struct inode *inode __maybe_unused, |
13169 | + struct file *file) | |
1facf9fc | 13170 | +{ |
4a4d8108 | 13171 | + int err; |
1308ab2a | 13172 | + struct super_block *sb; |
1facf9fc | 13173 | + |
523b37e3 AM |
13174 | + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n", |
13175 | + file, vfsub_file_flags(file), file->f_mode); | |
1facf9fc | 13176 | + |
4a4d8108 AM |
13177 | + sb = file->f_dentry->d_sb; |
13178 | + si_read_lock(sb, AuLock_FLUSH); | |
13179 | + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL); | |
13180 | + si_read_unlock(sb); | |
13181 | + return err; | |
13182 | +} | |
1facf9fc | 13183 | + |
4a4d8108 AM |
13184 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file) |
13185 | +{ | |
13186 | + struct au_finfo *finfo; | |
13187 | + aufs_bindex_t bindex; | |
1facf9fc | 13188 | + |
4a4d8108 | 13189 | + finfo = au_fi(file); |
523b37e3 | 13190 | + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files); |
4a4d8108 | 13191 | + bindex = finfo->fi_btop; |
b4510431 | 13192 | + if (bindex >= 0) |
4a4d8108 | 13193 | + au_set_h_fptr(file, bindex, NULL); |
7f207e10 | 13194 | + |
4a4d8108 AM |
13195 | + au_finfo_fin(file); |
13196 | + return 0; | |
1facf9fc | 13197 | +} |
13198 | + | |
4a4d8108 AM |
13199 | +/* ---------------------------------------------------------------------- */ |
13200 | + | |
13201 | +static int au_do_flush_nondir(struct file *file, fl_owner_t id) | |
dece6358 | 13202 | +{ |
1308ab2a | 13203 | + int err; |
4a4d8108 AM |
13204 | + struct file *h_file; |
13205 | + | |
13206 | + err = 0; | |
13207 | + h_file = au_hf_top(file); | |
13208 | + if (h_file) | |
13209 | + err = vfsub_flush(h_file, id); | |
13210 | + return err; | |
13211 | +} | |
13212 | + | |
13213 | +static int aufs_flush_nondir(struct file *file, fl_owner_t id) | |
13214 | +{ | |
13215 | + return au_do_flush(file, id, au_do_flush_nondir); | |
13216 | +} | |
13217 | + | |
13218 | +/* ---------------------------------------------------------------------- */ | |
9dbd164d AM |
13219 | +/* |
13220 | + * read and write functions acquire [fdi]_rwsem once, but release before | |
13221 | + * mmap_sem. This is because to stop a race condition between mmap(2). | |
13222 | + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping | |
13223 | + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in | |
13224 | + * read functions after [fdi]_rwsem are released, but it should be harmless. | |
13225 | + */ | |
4a4d8108 AM |
13226 | + |
13227 | +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count, | |
13228 | + loff_t *ppos) | |
13229 | +{ | |
13230 | + ssize_t err; | |
dece6358 | 13231 | + struct dentry *dentry; |
4a4d8108 | 13232 | + struct file *h_file; |
dece6358 | 13233 | + struct super_block *sb; |
1facf9fc | 13234 | + |
dece6358 AM |
13235 | + dentry = file->f_dentry; |
13236 | + sb = dentry->d_sb; | |
e49829fe | 13237 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 13238 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0); |
dece6358 AM |
13239 | + if (unlikely(err)) |
13240 | + goto out; | |
1facf9fc | 13241 | + |
4a4d8108 | 13242 | + h_file = au_hf_top(file); |
9dbd164d AM |
13243 | + get_file(h_file); |
13244 | + di_read_unlock(dentry, AuLock_IR); | |
13245 | + fi_read_unlock(file); | |
13246 | + | |
13247 | + /* filedata may be obsoleted by concurrent copyup, but no problem */ | |
4a4d8108 AM |
13248 | + err = vfsub_read_u(h_file, buf, count, ppos); |
13249 | + /* todo: necessary? */ | |
13250 | + /* file->f_ra = h_file->f_ra; */ | |
9dbd164d | 13251 | + /* update without lock, I don't think it a problem */ |
c06a8ce3 | 13252 | + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file)); |
9dbd164d | 13253 | + fput(h_file); |
1308ab2a | 13254 | + |
4f0767ce | 13255 | +out: |
dece6358 AM |
13256 | + si_read_unlock(sb); |
13257 | + return err; | |
13258 | +} | |
1facf9fc | 13259 | + |
e49829fe JR |
13260 | +/* |
13261 | + * todo: very ugly | |
13262 | + * it locks both of i_mutex and si_rwsem for read in safe. | |
13263 | + * if the plink maintenance mode continues forever (that is the problem), | |
13264 | + * may loop forever. | |
13265 | + */ | |
13266 | +static void au_mtx_and_read_lock(struct inode *inode) | |
13267 | +{ | |
13268 | + int err; | |
13269 | + struct super_block *sb = inode->i_sb; | |
13270 | + | |
13271 | + while (1) { | |
13272 | + mutex_lock(&inode->i_mutex); | |
13273 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
13274 | + if (!err) | |
13275 | + break; | |
13276 | + mutex_unlock(&inode->i_mutex); | |
13277 | + si_read_lock(sb, AuLock_NOPLMW); | |
13278 | + si_read_unlock(sb); | |
13279 | + } | |
13280 | +} | |
13281 | + | |
4a4d8108 AM |
13282 | +static ssize_t aufs_write(struct file *file, const char __user *ubuf, |
13283 | + size_t count, loff_t *ppos) | |
dece6358 | 13284 | +{ |
4a4d8108 | 13285 | + ssize_t err; |
076b876e AM |
13286 | + blkcnt_t blks; |
13287 | + aufs_bindex_t bstart; | |
4a4d8108 | 13288 | + struct au_pin pin; |
dece6358 | 13289 | + struct dentry *dentry; |
076b876e | 13290 | + struct inode *inode, *h_inode; |
9dbd164d | 13291 | + struct super_block *sb; |
4a4d8108 AM |
13292 | + struct file *h_file; |
13293 | + char __user *buf = (char __user *)ubuf; | |
1facf9fc | 13294 | + |
dece6358 | 13295 | + dentry = file->f_dentry; |
9dbd164d | 13296 | + sb = dentry->d_sb; |
4a4d8108 | 13297 | + inode = dentry->d_inode; |
e49829fe | 13298 | + au_mtx_and_read_lock(inode); |
1facf9fc | 13299 | + |
4a4d8108 AM |
13300 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); |
13301 | + if (unlikely(err)) | |
13302 | + goto out; | |
1facf9fc | 13303 | + |
4a4d8108 AM |
13304 | + err = au_ready_to_write(file, -1, &pin); |
13305 | + di_downgrade_lock(dentry, AuLock_IR); | |
9dbd164d AM |
13306 | + if (unlikely(err)) { |
13307 | + di_read_unlock(dentry, AuLock_IR); | |
13308 | + fi_write_unlock(file); | |
13309 | + goto out; | |
13310 | + } | |
1facf9fc | 13311 | + |
076b876e | 13312 | + bstart = au_fbstart(file); |
4a4d8108 | 13313 | + h_file = au_hf_top(file); |
9dbd164d | 13314 | + get_file(h_file); |
c1595e42 | 13315 | + h_inode = file_inode(h_file); |
076b876e | 13316 | + blks = h_inode->i_blocks; |
4a4d8108 | 13317 | + au_unpin(&pin); |
9dbd164d AM |
13318 | + di_read_unlock(dentry, AuLock_IR); |
13319 | + fi_write_unlock(file); | |
13320 | + | |
4a4d8108 | 13321 | + err = vfsub_write_u(h_file, buf, count, ppos); |
9dbd164d | 13322 | + ii_write_lock_child(inode); |
4a4d8108 | 13323 | + au_cpup_attr_timesizes(inode); |
c06a8ce3 | 13324 | + inode->i_mode = file_inode(h_file)->i_mode; |
076b876e AM |
13325 | + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); |
13326 | + if (err > 0) | |
13327 | + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks); | |
9dbd164d AM |
13328 | + ii_write_unlock(inode); |
13329 | + fput(h_file); | |
1facf9fc | 13330 | + |
4f0767ce | 13331 | +out: |
9dbd164d | 13332 | + si_read_unlock(sb); |
4a4d8108 | 13333 | + mutex_unlock(&inode->i_mutex); |
dece6358 AM |
13334 | + return err; |
13335 | +} | |
1facf9fc | 13336 | + |
076b876e AM |
13337 | +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio, |
13338 | + struct iov_iter *iov_iter) | |
dece6358 | 13339 | +{ |
4a4d8108 AM |
13340 | + ssize_t err; |
13341 | + struct file *file; | |
076b876e AM |
13342 | + ssize_t (*iter)(struct kiocb *, struct iov_iter *); |
13343 | + ssize_t (*aio)(struct kiocb *, const struct iovec *, unsigned long, | |
13344 | + loff_t); | |
1facf9fc | 13345 | + |
4a4d8108 AM |
13346 | + err = security_file_permission(h_file, rw); |
13347 | + if (unlikely(err)) | |
13348 | + goto out; | |
1facf9fc | 13349 | + |
4a4d8108 | 13350 | + err = -ENOSYS; |
076b876e AM |
13351 | + iter = NULL; |
13352 | + aio = NULL; | |
13353 | + if (rw == MAY_READ) { | |
13354 | + iter = h_file->f_op->read_iter; | |
13355 | + aio = h_file->f_op->aio_read; | |
13356 | + } else if (rw == MAY_WRITE) { | |
13357 | + iter = h_file->f_op->write_iter; | |
13358 | + aio = h_file->f_op->aio_write; | |
13359 | + } | |
13360 | + | |
13361 | + file = kio->ki_filp; | |
13362 | + kio->ki_filp = h_file; | |
13363 | + if (iter) { | |
2cbb1c4b | 13364 | + lockdep_off(); |
076b876e AM |
13365 | + err = iter(kio, iov_iter); |
13366 | + lockdep_on(); | |
13367 | + } else if (aio) { | |
13368 | + lockdep_off(); | |
13369 | + err = aio(kio, iov_iter->iov, iov_iter->nr_segs, kio->ki_pos); | |
2cbb1c4b | 13370 | + lockdep_on(); |
4a4d8108 AM |
13371 | + } else |
13372 | + /* currently there is no such fs */ | |
13373 | + WARN_ON_ONCE(1); | |
076b876e | 13374 | + kio->ki_filp = file; |
1facf9fc | 13375 | + |
4f0767ce | 13376 | +out: |
dece6358 AM |
13377 | + return err; |
13378 | +} | |
1facf9fc | 13379 | + |
076b876e | 13380 | +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1facf9fc | 13381 | +{ |
4a4d8108 AM |
13382 | + ssize_t err; |
13383 | + struct file *file, *h_file; | |
13384 | + struct dentry *dentry; | |
dece6358 | 13385 | + struct super_block *sb; |
1facf9fc | 13386 | + |
4a4d8108 | 13387 | + file = kio->ki_filp; |
dece6358 | 13388 | + dentry = file->f_dentry; |
1308ab2a | 13389 | + sb = dentry->d_sb; |
e49829fe | 13390 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 AM |
13391 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0); |
13392 | + if (unlikely(err)) | |
13393 | + goto out; | |
13394 | + | |
13395 | + h_file = au_hf_top(file); | |
9dbd164d AM |
13396 | + get_file(h_file); |
13397 | + di_read_unlock(dentry, AuLock_IR); | |
13398 | + fi_read_unlock(file); | |
13399 | + | |
076b876e | 13400 | + err = au_do_iter(h_file, MAY_READ, kio, iov_iter); |
4a4d8108 AM |
13401 | + /* todo: necessary? */ |
13402 | + /* file->f_ra = h_file->f_ra; */ | |
9dbd164d | 13403 | + /* update without lock, I don't think it a problem */ |
c06a8ce3 | 13404 | + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file)); |
9dbd164d | 13405 | + fput(h_file); |
1facf9fc | 13406 | + |
4f0767ce | 13407 | +out: |
4a4d8108 | 13408 | + si_read_unlock(sb); |
1308ab2a | 13409 | + return err; |
13410 | +} | |
1facf9fc | 13411 | + |
076b876e | 13412 | +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1308ab2a | 13413 | +{ |
4a4d8108 | 13414 | + ssize_t err; |
076b876e AM |
13415 | + blkcnt_t blks; |
13416 | + aufs_bindex_t bstart; | |
4a4d8108 AM |
13417 | + struct au_pin pin; |
13418 | + struct dentry *dentry; | |
076b876e | 13419 | + struct inode *inode, *h_inode; |
4a4d8108 | 13420 | + struct file *file, *h_file; |
9dbd164d | 13421 | + struct super_block *sb; |
1308ab2a | 13422 | + |
4a4d8108 | 13423 | + file = kio->ki_filp; |
1308ab2a | 13424 | + dentry = file->f_dentry; |
9dbd164d | 13425 | + sb = dentry->d_sb; |
1308ab2a | 13426 | + inode = dentry->d_inode; |
e49829fe JR |
13427 | + au_mtx_and_read_lock(inode); |
13428 | + | |
4a4d8108 AM |
13429 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); |
13430 | + if (unlikely(err)) | |
1308ab2a | 13431 | + goto out; |
1facf9fc | 13432 | + |
4a4d8108 AM |
13433 | + err = au_ready_to_write(file, -1, &pin); |
13434 | + di_downgrade_lock(dentry, AuLock_IR); | |
9dbd164d AM |
13435 | + if (unlikely(err)) { |
13436 | + di_read_unlock(dentry, AuLock_IR); | |
13437 | + fi_write_unlock(file); | |
13438 | + goto out; | |
13439 | + } | |
1facf9fc | 13440 | + |
076b876e | 13441 | + bstart = au_fbstart(file); |
4a4d8108 | 13442 | + h_file = au_hf_top(file); |
9dbd164d | 13443 | + get_file(h_file); |
c1595e42 | 13444 | + h_inode = file_inode(h_file); |
076b876e | 13445 | + blks = h_inode->i_blocks; |
9dbd164d AM |
13446 | + au_unpin(&pin); |
13447 | + di_read_unlock(dentry, AuLock_IR); | |
13448 | + fi_write_unlock(file); | |
13449 | + | |
076b876e | 13450 | + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter); |
9dbd164d | 13451 | + ii_write_lock_child(inode); |
4a4d8108 | 13452 | + au_cpup_attr_timesizes(inode); |
c06a8ce3 | 13453 | + inode->i_mode = file_inode(h_file)->i_mode; |
076b876e AM |
13454 | + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); |
13455 | + if (err > 0) | |
13456 | + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks); | |
9dbd164d AM |
13457 | + ii_write_unlock(inode); |
13458 | + fput(h_file); | |
1facf9fc | 13459 | + |
4f0767ce | 13460 | +out: |
9dbd164d | 13461 | + si_read_unlock(sb); |
4a4d8108 | 13462 | + mutex_unlock(&inode->i_mutex); |
dece6358 | 13463 | + return err; |
1facf9fc | 13464 | +} |
13465 | + | |
4a4d8108 AM |
13466 | +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, |
13467 | + struct pipe_inode_info *pipe, size_t len, | |
13468 | + unsigned int flags) | |
1facf9fc | 13469 | +{ |
4a4d8108 AM |
13470 | + ssize_t err; |
13471 | + struct file *h_file; | |
13472 | + struct dentry *dentry; | |
dece6358 | 13473 | + struct super_block *sb; |
1facf9fc | 13474 | + |
dece6358 | 13475 | + dentry = file->f_dentry; |
dece6358 | 13476 | + sb = dentry->d_sb; |
e49829fe | 13477 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 AM |
13478 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0); |
13479 | + if (unlikely(err)) | |
dece6358 | 13480 | + goto out; |
1facf9fc | 13481 | + |
4a4d8108 AM |
13482 | + err = -EINVAL; |
13483 | + h_file = au_hf_top(file); | |
9dbd164d | 13484 | + get_file(h_file); |
4a4d8108 | 13485 | + if (au_test_loopback_kthread()) { |
87a755f4 AM |
13486 | + au_warn_loopback(h_file->f_dentry->d_sb); |
13487 | + if (file->f_mapping != h_file->f_mapping) { | |
13488 | + file->f_mapping = h_file->f_mapping; | |
13489 | + smp_mb(); /* unnecessary? */ | |
13490 | + } | |
1308ab2a | 13491 | + } |
9dbd164d AM |
13492 | + di_read_unlock(dentry, AuLock_IR); |
13493 | + fi_read_unlock(file); | |
13494 | + | |
4a4d8108 AM |
13495 | + err = vfsub_splice_to(h_file, ppos, pipe, len, flags); |
13496 | + /* todo: necessasry? */ | |
13497 | + /* file->f_ra = h_file->f_ra; */ | |
9dbd164d | 13498 | + /* update without lock, I don't think it a problem */ |
c06a8ce3 | 13499 | + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file)); |
9dbd164d | 13500 | + fput(h_file); |
1facf9fc | 13501 | + |
4f0767ce | 13502 | +out: |
4a4d8108 | 13503 | + si_read_unlock(sb); |
dece6358 | 13504 | + return err; |
1facf9fc | 13505 | +} |
13506 | + | |
4a4d8108 AM |
13507 | +static ssize_t |
13508 | +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos, | |
13509 | + size_t len, unsigned int flags) | |
1facf9fc | 13510 | +{ |
4a4d8108 | 13511 | + ssize_t err; |
076b876e AM |
13512 | + blkcnt_t blks; |
13513 | + aufs_bindex_t bstart; | |
4a4d8108 AM |
13514 | + struct au_pin pin; |
13515 | + struct dentry *dentry; | |
076b876e | 13516 | + struct inode *inode, *h_inode; |
9dbd164d | 13517 | + struct super_block *sb; |
076b876e | 13518 | + struct file *h_file; |
1facf9fc | 13519 | + |
4a4d8108 | 13520 | + dentry = file->f_dentry; |
9dbd164d | 13521 | + sb = dentry->d_sb; |
4a4d8108 | 13522 | + inode = dentry->d_inode; |
e49829fe | 13523 | + au_mtx_and_read_lock(inode); |
9dbd164d | 13524 | + |
4a4d8108 AM |
13525 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); |
13526 | + if (unlikely(err)) | |
13527 | + goto out; | |
1facf9fc | 13528 | + |
4a4d8108 AM |
13529 | + err = au_ready_to_write(file, -1, &pin); |
13530 | + di_downgrade_lock(dentry, AuLock_IR); | |
9dbd164d AM |
13531 | + if (unlikely(err)) { |
13532 | + di_read_unlock(dentry, AuLock_IR); | |
13533 | + fi_write_unlock(file); | |
13534 | + goto out; | |
13535 | + } | |
1facf9fc | 13536 | + |
076b876e | 13537 | + bstart = au_fbstart(file); |
4a4d8108 | 13538 | + h_file = au_hf_top(file); |
9dbd164d | 13539 | + get_file(h_file); |
c1595e42 | 13540 | + h_inode = file_inode(h_file); |
076b876e | 13541 | + blks = h_inode->i_blocks; |
4a4d8108 | 13542 | + au_unpin(&pin); |
9dbd164d AM |
13543 | + di_read_unlock(dentry, AuLock_IR); |
13544 | + fi_write_unlock(file); | |
13545 | + | |
4a4d8108 | 13546 | + err = vfsub_splice_from(pipe, h_file, ppos, len, flags); |
9dbd164d | 13547 | + ii_write_lock_child(inode); |
4a4d8108 | 13548 | + au_cpup_attr_timesizes(inode); |
c06a8ce3 | 13549 | + inode->i_mode = file_inode(h_file)->i_mode; |
076b876e AM |
13550 | + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); |
13551 | + if (err > 0) | |
13552 | + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks); | |
9dbd164d AM |
13553 | + ii_write_unlock(inode); |
13554 | + fput(h_file); | |
1facf9fc | 13555 | + |
4f0767ce | 13556 | +out: |
9dbd164d | 13557 | + si_read_unlock(sb); |
4a4d8108 AM |
13558 | + mutex_unlock(&inode->i_mutex); |
13559 | + return err; | |
13560 | +} | |
1facf9fc | 13561 | + |
38d290e6 JR |
13562 | +static long aufs_fallocate(struct file *file, int mode, loff_t offset, |
13563 | + loff_t len) | |
13564 | +{ | |
13565 | + long err; | |
13566 | + struct au_pin pin; | |
13567 | + struct dentry *dentry; | |
13568 | + struct super_block *sb; | |
13569 | + struct inode *inode; | |
13570 | + struct file *h_file; | |
13571 | + | |
13572 | + dentry = file->f_dentry; | |
13573 | + sb = dentry->d_sb; | |
13574 | + inode = dentry->d_inode; | |
13575 | + au_mtx_and_read_lock(inode); | |
13576 | + | |
13577 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); | |
13578 | + if (unlikely(err)) | |
13579 | + goto out; | |
13580 | + | |
13581 | + err = au_ready_to_write(file, -1, &pin); | |
13582 | + di_downgrade_lock(dentry, AuLock_IR); | |
13583 | + if (unlikely(err)) { | |
13584 | + di_read_unlock(dentry, AuLock_IR); | |
13585 | + fi_write_unlock(file); | |
13586 | + goto out; | |
13587 | + } | |
13588 | + | |
13589 | + h_file = au_hf_top(file); | |
13590 | + get_file(h_file); | |
13591 | + au_unpin(&pin); | |
13592 | + di_read_unlock(dentry, AuLock_IR); | |
13593 | + fi_write_unlock(file); | |
13594 | + | |
13595 | + lockdep_off(); | |
03673fb0 | 13596 | + err = vfs_fallocate(h_file, mode, offset, len); |
38d290e6 JR |
13597 | + lockdep_on(); |
13598 | + ii_write_lock_child(inode); | |
13599 | + au_cpup_attr_timesizes(inode); | |
13600 | + inode->i_mode = file_inode(h_file)->i_mode; | |
13601 | + ii_write_unlock(inode); | |
13602 | + fput(h_file); | |
13603 | + | |
13604 | +out: | |
13605 | + si_read_unlock(sb); | |
13606 | + mutex_unlock(&inode->i_mutex); | |
13607 | + return err; | |
13608 | +} | |
13609 | + | |
4a4d8108 AM |
13610 | +/* ---------------------------------------------------------------------- */ |
13611 | + | |
9dbd164d AM |
13612 | +/* |
13613 | + * The locking order around current->mmap_sem. | |
13614 | + * - in most and regular cases | |
13615 | + * file I/O syscall -- aufs_read() or something | |
13616 | + * -- si_rwsem for read -- mmap_sem | |
13617 | + * (Note that [fdi]i_rwsem are released before mmap_sem). | |
13618 | + * - in mmap case | |
13619 | + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem | |
13620 | + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for | |
13621 | + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in | |
13622 | + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though. | |
13623 | + * It means that when aufs acquires si_rwsem for write, the process should never | |
13624 | + * acquire mmap_sem. | |
13625 | + * | |
392086de | 13626 | + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a |
9dbd164d AM |
13627 | + * problem either since any directory is not able to be mmap-ed. |
13628 | + * The similar scenario is applied to aufs_readlink() too. | |
13629 | + */ | |
13630 | + | |
38d290e6 | 13631 | +#if 0 /* stop calling security_file_mmap() */ |
2dfbb274 AM |
13632 | +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */ |
13633 | +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b) | |
13634 | + | |
13635 | +static unsigned long au_arch_prot_conv(unsigned long flags) | |
13636 | +{ | |
13637 | + /* currently ppc64 only */ | |
13638 | +#ifdef CONFIG_PPC64 | |
13639 | + /* cf. linux/arch/powerpc/include/asm/mman.h */ | |
13640 | + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO); | |
13641 | + return AuConv_VM_PROT(flags, SAO); | |
13642 | +#else | |
13643 | + AuDebugOn(arch_calc_vm_prot_bits(-1)); | |
13644 | + return 0; | |
13645 | +#endif | |
13646 | +} | |
13647 | + | |
13648 | +static unsigned long au_prot_conv(unsigned long flags) | |
13649 | +{ | |
13650 | + return AuConv_VM_PROT(flags, READ) | |
13651 | + | AuConv_VM_PROT(flags, WRITE) | |
13652 | + | AuConv_VM_PROT(flags, EXEC) | |
13653 | + | au_arch_prot_conv(flags); | |
13654 | +} | |
13655 | + | |
13656 | +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */ | |
13657 | +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b) | |
13658 | + | |
13659 | +static unsigned long au_flag_conv(unsigned long flags) | |
13660 | +{ | |
13661 | + return AuConv_VM_MAP(flags, GROWSDOWN) | |
13662 | + | AuConv_VM_MAP(flags, DENYWRITE) | |
2dfbb274 AM |
13663 | + | AuConv_VM_MAP(flags, LOCKED); |
13664 | +} | |
38d290e6 | 13665 | +#endif |
2dfbb274 | 13666 | + |
9dbd164d | 13667 | +static int aufs_mmap(struct file *file, struct vm_area_struct *vma) |
dece6358 | 13668 | +{ |
4a4d8108 AM |
13669 | + int err; |
13670 | + aufs_bindex_t bstart; | |
13671 | + const unsigned char wlock | |
9dbd164d | 13672 | + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED); |
4a4d8108 AM |
13673 | + struct dentry *dentry; |
13674 | + struct super_block *sb; | |
9dbd164d AM |
13675 | + struct file *h_file; |
13676 | + struct au_branch *br; | |
13677 | + struct au_pin pin; | |
13678 | + | |
13679 | + AuDbgVmRegion(file, vma); | |
1308ab2a | 13680 | + |
4a4d8108 AM |
13681 | + dentry = file->f_dentry; |
13682 | + sb = dentry->d_sb; | |
9dbd164d | 13683 | + lockdep_off(); |
e49829fe | 13684 | + si_read_lock(sb, AuLock_NOPLMW); |
4a4d8108 AM |
13685 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); |
13686 | + if (unlikely(err)) | |
13687 | + goto out; | |
13688 | + | |
4a4d8108 | 13689 | + if (wlock) { |
4a4d8108 AM |
13690 | + err = au_ready_to_write(file, -1, &pin); |
13691 | + di_write_unlock(dentry); | |
9dbd164d AM |
13692 | + if (unlikely(err)) { |
13693 | + fi_write_unlock(file); | |
13694 | + goto out; | |
13695 | + } | |
4a4d8108 AM |
13696 | + au_unpin(&pin); |
13697 | + } else | |
13698 | + di_write_unlock(dentry); | |
9dbd164d | 13699 | + |
4a4d8108 | 13700 | + bstart = au_fbstart(file); |
9dbd164d AM |
13701 | + br = au_sbr(sb, bstart); |
13702 | + h_file = au_hf_top(file); | |
13703 | + get_file(h_file); | |
2cbb1c4b | 13704 | + au_set_mmapped(file); |
4a4d8108 | 13705 | + fi_write_unlock(file); |
9dbd164d | 13706 | + lockdep_on(); |
1308ab2a | 13707 | + |
9dbd164d | 13708 | + au_vm_file_reset(vma, h_file); |
38d290e6 JR |
13709 | + /* |
13710 | + * we cannot call security_mmap_file() here since it may acquire | |
13711 | + * mmap_sem or i_mutex. | |
13712 | + * | |
13713 | + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags), | |
13714 | + * au_flag_conv(vma->vm_flags)); | |
13715 | + */ | |
9dbd164d AM |
13716 | + if (!err) |
13717 | + err = h_file->f_op->mmap(h_file, vma); | |
2cbb1c4b JR |
13718 | + if (unlikely(err)) |
13719 | + goto out_reset; | |
4a4d8108 | 13720 | + |
fb47a38f | 13721 | + au_vm_prfile_set(vma, file); |
4a4d8108 | 13722 | + /* update without lock, I don't think it a problem */ |
c06a8ce3 | 13723 | + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file)); |
2cbb1c4b | 13724 | + goto out_fput; /* success */ |
4a4d8108 | 13725 | + |
2cbb1c4b JR |
13726 | +out_reset: |
13727 | + au_unset_mmapped(file); | |
13728 | + au_vm_file_reset(vma, file); | |
13729 | +out_fput: | |
9dbd164d AM |
13730 | + fput(h_file); |
13731 | + lockdep_off(); | |
4f0767ce | 13732 | +out: |
9dbd164d AM |
13733 | + si_read_unlock(sb); |
13734 | + lockdep_on(); | |
13735 | + AuTraceErr(err); | |
4a4d8108 AM |
13736 | + return err; |
13737 | +} | |
13738 | + | |
13739 | +/* ---------------------------------------------------------------------- */ | |
13740 | + | |
1e00d052 AM |
13741 | +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end, |
13742 | + int datasync) | |
4a4d8108 AM |
13743 | +{ |
13744 | + int err; | |
13745 | + struct au_pin pin; | |
b752ccd1 | 13746 | + struct dentry *dentry; |
4a4d8108 AM |
13747 | + struct inode *inode; |
13748 | + struct file *h_file; | |
13749 | + struct super_block *sb; | |
13750 | + | |
b752ccd1 | 13751 | + dentry = file->f_dentry; |
4a4d8108 | 13752 | + inode = dentry->d_inode; |
4a4d8108 | 13753 | + sb = dentry->d_sb; |
1e00d052 | 13754 | + mutex_lock(&inode->i_mutex); |
e49829fe JR |
13755 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
13756 | + if (unlikely(err)) | |
13757 | + goto out; | |
4a4d8108 AM |
13758 | + |
13759 | + err = 0; /* -EBADF; */ /* posix? */ | |
13760 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
e49829fe | 13761 | + goto out_si; |
4a4d8108 AM |
13762 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); |
13763 | + if (unlikely(err)) | |
e49829fe | 13764 | + goto out_si; |
4a4d8108 AM |
13765 | + |
13766 | + err = au_ready_to_write(file, -1, &pin); | |
13767 | + di_downgrade_lock(dentry, AuLock_IR); | |
13768 | + if (unlikely(err)) | |
13769 | + goto out_unlock; | |
13770 | + au_unpin(&pin); | |
13771 | + | |
13772 | + err = -EINVAL; | |
13773 | + h_file = au_hf_top(file); | |
53392da6 AM |
13774 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
13775 | + au_cpup_attr_timesizes(inode); | |
4a4d8108 | 13776 | + |
4f0767ce | 13777 | +out_unlock: |
4a4d8108 | 13778 | + di_read_unlock(dentry, AuLock_IR); |
1308ab2a | 13779 | + fi_write_unlock(file); |
e49829fe | 13780 | +out_si: |
953406b4 | 13781 | + si_read_unlock(sb); |
e49829fe | 13782 | +out: |
1e00d052 | 13783 | + mutex_unlock(&inode->i_mutex); |
4a4d8108 | 13784 | + return err; |
dece6358 AM |
13785 | +} |
13786 | + | |
4a4d8108 AM |
13787 | +/* no one supports this operation, currently */ |
13788 | +#if 0 | |
13789 | +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync) | |
dece6358 | 13790 | +{ |
4a4d8108 AM |
13791 | + int err; |
13792 | + struct au_pin pin; | |
1308ab2a | 13793 | + struct dentry *dentry; |
4a4d8108 AM |
13794 | + struct inode *inode; |
13795 | + struct file *file, *h_file; | |
1308ab2a | 13796 | + |
4a4d8108 | 13797 | + file = kio->ki_filp; |
1308ab2a | 13798 | + dentry = file->f_dentry; |
4a4d8108 | 13799 | + inode = dentry->d_inode; |
e49829fe | 13800 | + au_mtx_and_read_lock(inode); |
4a4d8108 AM |
13801 | + |
13802 | + err = 0; /* -EBADF; */ /* posix? */ | |
13803 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
13804 | + goto out; | |
13805 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); | |
13806 | + if (unlikely(err)) | |
1308ab2a | 13807 | + goto out; |
13808 | + | |
4a4d8108 AM |
13809 | + err = au_ready_to_write(file, -1, &pin); |
13810 | + di_downgrade_lock(dentry, AuLock_IR); | |
13811 | + if (unlikely(err)) | |
13812 | + goto out_unlock; | |
13813 | + au_unpin(&pin); | |
1308ab2a | 13814 | + |
4a4d8108 AM |
13815 | + err = -ENOSYS; |
13816 | + h_file = au_hf_top(file); | |
523b37e3 | 13817 | + if (h_file->f_op->aio_fsync) { |
4a4d8108 | 13818 | + struct mutex *h_mtx; |
1308ab2a | 13819 | + |
c06a8ce3 | 13820 | + h_mtx = &file_inode(h_file)->i_mutex; |
4a4d8108 AM |
13821 | + if (!is_sync_kiocb(kio)) { |
13822 | + get_file(h_file); | |
13823 | + fput(file); | |
13824 | + } | |
13825 | + kio->ki_filp = h_file; | |
13826 | + err = h_file->f_op->aio_fsync(kio, datasync); | |
13827 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
13828 | + if (!err) | |
13829 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); | |
13830 | + /*ignore*/ | |
13831 | + au_cpup_attr_timesizes(inode); | |
13832 | + mutex_unlock(h_mtx); | |
13833 | + } | |
1308ab2a | 13834 | + |
4f0767ce | 13835 | +out_unlock: |
4a4d8108 AM |
13836 | + di_read_unlock(dentry, AuLock_IR); |
13837 | + fi_write_unlock(file); | |
4f0767ce | 13838 | +out: |
e49829fe | 13839 | + si_read_unlock(inode->sb); |
4a4d8108 AM |
13840 | + mutex_unlock(&inode->i_mutex); |
13841 | + return err; | |
dece6358 | 13842 | +} |
4a4d8108 | 13843 | +#endif |
dece6358 | 13844 | + |
4a4d8108 | 13845 | +static int aufs_fasync(int fd, struct file *file, int flag) |
dece6358 | 13846 | +{ |
4a4d8108 AM |
13847 | + int err; |
13848 | + struct file *h_file; | |
13849 | + struct dentry *dentry; | |
13850 | + struct super_block *sb; | |
1308ab2a | 13851 | + |
4a4d8108 AM |
13852 | + dentry = file->f_dentry; |
13853 | + sb = dentry->d_sb; | |
e49829fe | 13854 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 AM |
13855 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0); |
13856 | + if (unlikely(err)) | |
13857 | + goto out; | |
13858 | + | |
13859 | + h_file = au_hf_top(file); | |
523b37e3 | 13860 | + if (h_file->f_op->fasync) |
4a4d8108 AM |
13861 | + err = h_file->f_op->fasync(fd, h_file, flag); |
13862 | + | |
13863 | + di_read_unlock(dentry, AuLock_IR); | |
13864 | + fi_read_unlock(file); | |
1308ab2a | 13865 | + |
4f0767ce | 13866 | +out: |
4a4d8108 | 13867 | + si_read_unlock(sb); |
1308ab2a | 13868 | + return err; |
dece6358 | 13869 | +} |
4a4d8108 AM |
13870 | + |
13871 | +/* ---------------------------------------------------------------------- */ | |
13872 | + | |
13873 | +/* no one supports this operation, currently */ | |
13874 | +#if 0 | |
13875 | +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset, | |
13876 | + size_t len, loff_t *pos , int more) | |
13877 | +{ | |
13878 | +} | |
13879 | +#endif | |
13880 | + | |
13881 | +/* ---------------------------------------------------------------------- */ | |
13882 | + | |
13883 | +const struct file_operations aufs_file_fop = { | |
13884 | + .owner = THIS_MODULE, | |
2cbb1c4b | 13885 | + |
027c5e7a | 13886 | + .llseek = default_llseek, |
4a4d8108 AM |
13887 | + |
13888 | + .read = aufs_read, | |
13889 | + .write = aufs_write, | |
076b876e AM |
13890 | + .read_iter = aufs_read_iter, |
13891 | + .write_iter = aufs_write_iter, | |
13892 | + | |
4a4d8108 AM |
13893 | +#ifdef CONFIG_AUFS_POLL |
13894 | + .poll = aufs_poll, | |
13895 | +#endif | |
13896 | + .unlocked_ioctl = aufs_ioctl_nondir, | |
b752ccd1 | 13897 | +#ifdef CONFIG_COMPAT |
c2b27bf2 | 13898 | + .compat_ioctl = aufs_compat_ioctl_nondir, |
b752ccd1 | 13899 | +#endif |
4a4d8108 AM |
13900 | + .mmap = aufs_mmap, |
13901 | + .open = aufs_open_nondir, | |
13902 | + .flush = aufs_flush_nondir, | |
13903 | + .release = aufs_release_nondir, | |
13904 | + .fsync = aufs_fsync_nondir, | |
13905 | + /* .aio_fsync = aufs_aio_fsync_nondir, */ | |
13906 | + .fasync = aufs_fasync, | |
13907 | + /* .sendpage = aufs_sendpage, */ | |
13908 | + .splice_write = aufs_splice_write, | |
13909 | + .splice_read = aufs_splice_read, | |
13910 | +#if 0 | |
13911 | + .aio_splice_write = aufs_aio_splice_write, | |
38d290e6 | 13912 | + .aio_splice_read = aufs_aio_splice_read, |
4a4d8108 | 13913 | +#endif |
38d290e6 | 13914 | + .fallocate = aufs_fallocate |
4a4d8108 | 13915 | +}; |
7f207e10 AM |
13916 | diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h |
13917 | --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 13918 | +++ linux/fs/aufs/fstype.h 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 13919 | @@ -0,0 +1,469 @@ |
4a4d8108 | 13920 | +/* |
523b37e3 | 13921 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
13922 | + * |
13923 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13924 | + * it under the terms of the GNU General Public License as published by | |
13925 | + * the Free Software Foundation; either version 2 of the License, or | |
13926 | + * (at your option) any later version. | |
13927 | + * | |
13928 | + * This program is distributed in the hope that it will be useful, | |
13929 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13930 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13931 | + * GNU General Public License for more details. | |
13932 | + * | |
13933 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 13934 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
13935 | + */ |
13936 | + | |
13937 | +/* | |
13938 | + * judging filesystem type | |
13939 | + */ | |
13940 | + | |
13941 | +#ifndef __AUFS_FSTYPE_H__ | |
13942 | +#define __AUFS_FSTYPE_H__ | |
13943 | + | |
13944 | +#ifdef __KERNEL__ | |
13945 | + | |
13946 | +#include <linux/fs.h> | |
13947 | +#include <linux/magic.h> | |
13948 | +#include <linux/romfs_fs.h> | |
4a4d8108 AM |
13949 | + |
13950 | +static inline int au_test_aufs(struct super_block *sb) | |
13951 | +{ | |
13952 | + return sb->s_magic == AUFS_SUPER_MAGIC; | |
13953 | +} | |
13954 | + | |
13955 | +static inline const char *au_sbtype(struct super_block *sb) | |
13956 | +{ | |
13957 | + return sb->s_type->name; | |
13958 | +} | |
1308ab2a | 13959 | + |
13960 | +static inline int au_test_iso9660(struct super_block *sb __maybe_unused) | |
13961 | +{ | |
13962 | +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE) | |
13963 | + return sb->s_magic == ROMFS_MAGIC; | |
dece6358 AM |
13964 | +#else |
13965 | + return 0; | |
13966 | +#endif | |
13967 | +} | |
13968 | + | |
1308ab2a | 13969 | +static inline int au_test_romfs(struct super_block *sb __maybe_unused) |
dece6358 | 13970 | +{ |
1308ab2a | 13971 | +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE) |
13972 | + return sb->s_magic == ISOFS_SUPER_MAGIC; | |
dece6358 AM |
13973 | +#else |
13974 | + return 0; | |
13975 | +#endif | |
13976 | +} | |
13977 | + | |
1308ab2a | 13978 | +static inline int au_test_cramfs(struct super_block *sb __maybe_unused) |
dece6358 | 13979 | +{ |
1308ab2a | 13980 | +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE) |
13981 | + return sb->s_magic == CRAMFS_MAGIC; | |
13982 | +#endif | |
13983 | + return 0; | |
13984 | +} | |
13985 | + | |
13986 | +static inline int au_test_nfs(struct super_block *sb __maybe_unused) | |
13987 | +{ | |
13988 | +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE) | |
13989 | + return sb->s_magic == NFS_SUPER_MAGIC; | |
dece6358 AM |
13990 | +#else |
13991 | + return 0; | |
13992 | +#endif | |
13993 | +} | |
13994 | + | |
1308ab2a | 13995 | +static inline int au_test_fuse(struct super_block *sb __maybe_unused) |
dece6358 | 13996 | +{ |
1308ab2a | 13997 | +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE) |
13998 | + return sb->s_magic == FUSE_SUPER_MAGIC; | |
dece6358 AM |
13999 | +#else |
14000 | + return 0; | |
14001 | +#endif | |
14002 | +} | |
14003 | + | |
1308ab2a | 14004 | +static inline int au_test_xfs(struct super_block *sb __maybe_unused) |
dece6358 | 14005 | +{ |
1308ab2a | 14006 | +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE) |
14007 | + return sb->s_magic == XFS_SB_MAGIC; | |
dece6358 AM |
14008 | +#else |
14009 | + return 0; | |
14010 | +#endif | |
14011 | +} | |
14012 | + | |
1308ab2a | 14013 | +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused) |
dece6358 | 14014 | +{ |
1308ab2a | 14015 | +#ifdef CONFIG_TMPFS |
14016 | + return sb->s_magic == TMPFS_MAGIC; | |
14017 | +#else | |
14018 | + return 0; | |
dece6358 | 14019 | +#endif |
dece6358 AM |
14020 | +} |
14021 | + | |
1308ab2a | 14022 | +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused) |
1facf9fc | 14023 | +{ |
1308ab2a | 14024 | +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE) |
14025 | + return !strcmp(au_sbtype(sb), "ecryptfs"); | |
14026 | +#else | |
14027 | + return 0; | |
14028 | +#endif | |
1facf9fc | 14029 | +} |
14030 | + | |
1308ab2a | 14031 | +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused) |
1facf9fc | 14032 | +{ |
1308ab2a | 14033 | +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE) |
14034 | + return sb->s_magic == OCFS2_SUPER_MAGIC; | |
14035 | +#else | |
14036 | + return 0; | |
14037 | +#endif | |
1facf9fc | 14038 | +} |
14039 | + | |
1308ab2a | 14040 | +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused) |
1facf9fc | 14041 | +{ |
1308ab2a | 14042 | +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE) |
14043 | + return sb->s_magic == DLMFS_MAGIC; | |
14044 | +#else | |
14045 | + return 0; | |
14046 | +#endif | |
1facf9fc | 14047 | +} |
14048 | + | |
1308ab2a | 14049 | +static inline int au_test_coda(struct super_block *sb __maybe_unused) |
1facf9fc | 14050 | +{ |
1308ab2a | 14051 | +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE) |
14052 | + return sb->s_magic == CODA_SUPER_MAGIC; | |
14053 | +#else | |
14054 | + return 0; | |
14055 | +#endif | |
14056 | +} | |
14057 | + | |
14058 | +static inline int au_test_v9fs(struct super_block *sb __maybe_unused) | |
14059 | +{ | |
14060 | +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE) | |
14061 | + return sb->s_magic == V9FS_MAGIC; | |
14062 | +#else | |
14063 | + return 0; | |
14064 | +#endif | |
14065 | +} | |
14066 | + | |
14067 | +static inline int au_test_ext4(struct super_block *sb __maybe_unused) | |
14068 | +{ | |
c2b27bf2 | 14069 | +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE) |
1308ab2a | 14070 | + return sb->s_magic == EXT4_SUPER_MAGIC; |
14071 | +#else | |
14072 | + return 0; | |
14073 | +#endif | |
14074 | +} | |
14075 | + | |
14076 | +static inline int au_test_sysv(struct super_block *sb __maybe_unused) | |
14077 | +{ | |
14078 | +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE) | |
14079 | + return !strcmp(au_sbtype(sb), "sysv"); | |
14080 | +#else | |
14081 | + return 0; | |
14082 | +#endif | |
14083 | +} | |
14084 | + | |
14085 | +static inline int au_test_ramfs(struct super_block *sb) | |
14086 | +{ | |
14087 | + return sb->s_magic == RAMFS_MAGIC; | |
14088 | +} | |
14089 | + | |
14090 | +static inline int au_test_ubifs(struct super_block *sb __maybe_unused) | |
14091 | +{ | |
14092 | +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE) | |
14093 | + return sb->s_magic == UBIFS_SUPER_MAGIC; | |
14094 | +#else | |
14095 | + return 0; | |
14096 | +#endif | |
14097 | +} | |
14098 | + | |
14099 | +static inline int au_test_procfs(struct super_block *sb __maybe_unused) | |
14100 | +{ | |
14101 | +#ifdef CONFIG_PROC_FS | |
14102 | + return sb->s_magic == PROC_SUPER_MAGIC; | |
14103 | +#else | |
14104 | + return 0; | |
14105 | +#endif | |
14106 | +} | |
14107 | + | |
14108 | +static inline int au_test_sysfs(struct super_block *sb __maybe_unused) | |
14109 | +{ | |
14110 | +#ifdef CONFIG_SYSFS | |
14111 | + return sb->s_magic == SYSFS_MAGIC; | |
14112 | +#else | |
14113 | + return 0; | |
14114 | +#endif | |
14115 | +} | |
14116 | + | |
14117 | +static inline int au_test_configfs(struct super_block *sb __maybe_unused) | |
14118 | +{ | |
14119 | +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE) | |
14120 | + return sb->s_magic == CONFIGFS_MAGIC; | |
14121 | +#else | |
14122 | + return 0; | |
14123 | +#endif | |
14124 | +} | |
14125 | + | |
14126 | +static inline int au_test_minix(struct super_block *sb __maybe_unused) | |
14127 | +{ | |
14128 | +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE) | |
14129 | + return sb->s_magic == MINIX3_SUPER_MAGIC | |
14130 | + || sb->s_magic == MINIX2_SUPER_MAGIC | |
14131 | + || sb->s_magic == MINIX2_SUPER_MAGIC2 | |
14132 | + || sb->s_magic == MINIX_SUPER_MAGIC | |
14133 | + || sb->s_magic == MINIX_SUPER_MAGIC2; | |
14134 | +#else | |
14135 | + return 0; | |
14136 | +#endif | |
14137 | +} | |
14138 | + | |
14139 | +static inline int au_test_cifs(struct super_block *sb __maybe_unused) | |
14140 | +{ | |
14141 | +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE) | |
14142 | + return sb->s_magic == CIFS_MAGIC_NUMBER; | |
14143 | +#else | |
14144 | + return 0; | |
14145 | +#endif | |
14146 | +} | |
14147 | + | |
14148 | +static inline int au_test_fat(struct super_block *sb __maybe_unused) | |
14149 | +{ | |
14150 | +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE) | |
14151 | + return sb->s_magic == MSDOS_SUPER_MAGIC; | |
14152 | +#else | |
14153 | + return 0; | |
14154 | +#endif | |
14155 | +} | |
14156 | + | |
14157 | +static inline int au_test_msdos(struct super_block *sb) | |
14158 | +{ | |
14159 | + return au_test_fat(sb); | |
14160 | +} | |
14161 | + | |
14162 | +static inline int au_test_vfat(struct super_block *sb) | |
14163 | +{ | |
14164 | + return au_test_fat(sb); | |
14165 | +} | |
14166 | + | |
14167 | +static inline int au_test_securityfs(struct super_block *sb __maybe_unused) | |
14168 | +{ | |
14169 | +#ifdef CONFIG_SECURITYFS | |
14170 | + return sb->s_magic == SECURITYFS_MAGIC; | |
14171 | +#else | |
14172 | + return 0; | |
14173 | +#endif | |
14174 | +} | |
14175 | + | |
14176 | +static inline int au_test_squashfs(struct super_block *sb __maybe_unused) | |
14177 | +{ | |
14178 | +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE) | |
14179 | + return sb->s_magic == SQUASHFS_MAGIC; | |
14180 | +#else | |
14181 | + return 0; | |
14182 | +#endif | |
14183 | +} | |
14184 | + | |
14185 | +static inline int au_test_btrfs(struct super_block *sb __maybe_unused) | |
14186 | +{ | |
14187 | +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE) | |
14188 | + return sb->s_magic == BTRFS_SUPER_MAGIC; | |
14189 | +#else | |
14190 | + return 0; | |
14191 | +#endif | |
14192 | +} | |
14193 | + | |
14194 | +static inline int au_test_xenfs(struct super_block *sb __maybe_unused) | |
14195 | +{ | |
14196 | +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE) | |
14197 | + return sb->s_magic == XENFS_SUPER_MAGIC; | |
14198 | +#else | |
14199 | + return 0; | |
14200 | +#endif | |
14201 | +} | |
14202 | + | |
14203 | +static inline int au_test_debugfs(struct super_block *sb __maybe_unused) | |
14204 | +{ | |
14205 | +#ifdef CONFIG_DEBUG_FS | |
14206 | + return sb->s_magic == DEBUGFS_MAGIC; | |
14207 | +#else | |
14208 | + return 0; | |
14209 | +#endif | |
14210 | +} | |
14211 | + | |
14212 | +static inline int au_test_nilfs(struct super_block *sb __maybe_unused) | |
14213 | +{ | |
14214 | +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE) | |
14215 | + return sb->s_magic == NILFS_SUPER_MAGIC; | |
14216 | +#else | |
14217 | + return 0; | |
14218 | +#endif | |
14219 | +} | |
14220 | + | |
4a4d8108 AM |
14221 | +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused) |
14222 | +{ | |
14223 | +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE) | |
14224 | + return sb->s_magic == HFSPLUS_SUPER_MAGIC; | |
14225 | +#else | |
14226 | + return 0; | |
14227 | +#endif | |
14228 | +} | |
14229 | + | |
1308ab2a | 14230 | +/* ---------------------------------------------------------------------- */ |
14231 | +/* | |
14232 | + * they can't be an aufs branch. | |
14233 | + */ | |
14234 | +static inline int au_test_fs_unsuppoted(struct super_block *sb) | |
14235 | +{ | |
14236 | + return | |
14237 | +#ifndef CONFIG_AUFS_BR_RAMFS | |
14238 | + au_test_ramfs(sb) || | |
14239 | +#endif | |
14240 | + au_test_procfs(sb) | |
14241 | + || au_test_sysfs(sb) | |
14242 | + || au_test_configfs(sb) | |
14243 | + || au_test_debugfs(sb) | |
14244 | + || au_test_securityfs(sb) | |
14245 | + || au_test_xenfs(sb) | |
14246 | + || au_test_ecryptfs(sb) | |
14247 | + /* || !strcmp(au_sbtype(sb), "unionfs") */ | |
14248 | + || au_test_aufs(sb); /* will be supported in next version */ | |
14249 | +} | |
14250 | + | |
1308ab2a | 14251 | +static inline int au_test_fs_remote(struct super_block *sb) |
14252 | +{ | |
14253 | + return !au_test_tmpfs(sb) | |
14254 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14255 | + && !au_test_ramfs(sb) | |
14256 | +#endif | |
14257 | + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV); | |
14258 | +} | |
14259 | + | |
14260 | +/* ---------------------------------------------------------------------- */ | |
14261 | + | |
14262 | +/* | |
14263 | + * Note: these functions (below) are created after reading ->getattr() in all | |
14264 | + * filesystems under linux/fs. it means we have to do so in every update... | |
14265 | + */ | |
14266 | + | |
14267 | +/* | |
14268 | + * some filesystems require getattr to refresh the inode attributes before | |
14269 | + * referencing. | |
14270 | + * in most cases, we can rely on the inode attribute in NFS (or every remote fs) | |
14271 | + * and leave the work for d_revalidate() | |
14272 | + */ | |
14273 | +static inline int au_test_fs_refresh_iattr(struct super_block *sb) | |
14274 | +{ | |
14275 | + return au_test_nfs(sb) | |
14276 | + || au_test_fuse(sb) | |
1308ab2a | 14277 | + /* || au_test_ocfs2(sb) */ /* untested */ |
14278 | + /* || au_test_btrfs(sb) */ /* untested */ | |
14279 | + /* || au_test_coda(sb) */ /* untested */ | |
14280 | + /* || au_test_v9fs(sb) */ /* untested */ | |
14281 | + ; | |
14282 | +} | |
14283 | + | |
14284 | +/* | |
14285 | + * filesystems which don't maintain i_size or i_blocks. | |
14286 | + */ | |
14287 | +static inline int au_test_fs_bad_iattr_size(struct super_block *sb) | |
14288 | +{ | |
14289 | + return au_test_xfs(sb) | |
4a4d8108 AM |
14290 | + || au_test_btrfs(sb) |
14291 | + || au_test_ubifs(sb) | |
14292 | + || au_test_hfsplus(sb) /* maintained, but incorrect */ | |
1308ab2a | 14293 | + /* || au_test_ext4(sb) */ /* untested */ |
14294 | + /* || au_test_ocfs2(sb) */ /* untested */ | |
14295 | + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */ | |
14296 | + /* || au_test_sysv(sb) */ /* untested */ | |
1308ab2a | 14297 | + /* || au_test_minix(sb) */ /* untested */ |
14298 | + ; | |
14299 | +} | |
14300 | + | |
14301 | +/* | |
14302 | + * filesystems which don't store the correct value in some of their inode | |
14303 | + * attributes. | |
14304 | + */ | |
14305 | +static inline int au_test_fs_bad_iattr(struct super_block *sb) | |
14306 | +{ | |
14307 | + return au_test_fs_bad_iattr_size(sb) | |
14308 | + /* || au_test_cifs(sb) */ /* untested */ | |
14309 | + || au_test_fat(sb) | |
14310 | + || au_test_msdos(sb) | |
14311 | + || au_test_vfat(sb); | |
1facf9fc | 14312 | +} |
14313 | + | |
14314 | +/* they don't check i_nlink in link(2) */ | |
14315 | +static inline int au_test_fs_no_limit_nlink(struct super_block *sb) | |
14316 | +{ | |
14317 | + return au_test_tmpfs(sb) | |
14318 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
14319 | + || au_test_ramfs(sb) | |
14320 | +#endif | |
4a4d8108 | 14321 | + || au_test_ubifs(sb) |
4a4d8108 | 14322 | + || au_test_hfsplus(sb); |
1facf9fc | 14323 | +} |
14324 | + | |
14325 | +/* | |
14326 | + * filesystems which sets S_NOATIME and S_NOCMTIME. | |
14327 | + */ | |
14328 | +static inline int au_test_fs_notime(struct super_block *sb) | |
14329 | +{ | |
14330 | + return au_test_nfs(sb) | |
14331 | + || au_test_fuse(sb) | |
dece6358 | 14332 | + || au_test_ubifs(sb) |
1facf9fc | 14333 | + /* || au_test_cifs(sb) */ /* untested */ |
1facf9fc | 14334 | + ; |
14335 | +} | |
14336 | + | |
14337 | +/* | |
14338 | + * filesystems which requires replacing i_mapping. | |
14339 | + */ | |
14340 | +static inline int au_test_fs_bad_mapping(struct super_block *sb) | |
14341 | +{ | |
dece6358 AM |
14342 | + return au_test_fuse(sb) |
14343 | + || au_test_ubifs(sb); | |
1facf9fc | 14344 | +} |
14345 | + | |
14346 | +/* temporary support for i#1 in cramfs */ | |
14347 | +static inline int au_test_fs_unique_ino(struct inode *inode) | |
14348 | +{ | |
14349 | + if (au_test_cramfs(inode->i_sb)) | |
14350 | + return inode->i_ino != 1; | |
14351 | + return 1; | |
14352 | +} | |
14353 | + | |
14354 | +/* ---------------------------------------------------------------------- */ | |
14355 | + | |
14356 | +/* | |
14357 | + * the filesystem where the xino files placed must support i/o after unlink and | |
14358 | + * maintain i_size and i_blocks. | |
14359 | + */ | |
14360 | +static inline int au_test_fs_bad_xino(struct super_block *sb) | |
14361 | +{ | |
14362 | + return au_test_fs_remote(sb) | |
14363 | + || au_test_fs_bad_iattr_size(sb) | |
1facf9fc | 14364 | + /* don't want unnecessary work for xino */ |
14365 | + || au_test_aufs(sb) | |
1308ab2a | 14366 | + || au_test_ecryptfs(sb) |
14367 | + || au_test_nilfs(sb); | |
1facf9fc | 14368 | +} |
14369 | + | |
14370 | +static inline int au_test_fs_trunc_xino(struct super_block *sb) | |
14371 | +{ | |
14372 | + return au_test_tmpfs(sb) | |
14373 | + || au_test_ramfs(sb); | |
14374 | +} | |
14375 | + | |
14376 | +/* | |
14377 | + * test if the @sb is real-readonly. | |
14378 | + */ | |
14379 | +static inline int au_test_fs_rr(struct super_block *sb) | |
14380 | +{ | |
14381 | + return au_test_squashfs(sb) | |
14382 | + || au_test_iso9660(sb) | |
14383 | + || au_test_cramfs(sb) | |
14384 | + || au_test_romfs(sb); | |
14385 | +} | |
14386 | + | |
14387 | +#endif /* __KERNEL__ */ | |
14388 | +#endif /* __AUFS_FSTYPE_H__ */ | |
7f207e10 AM |
14389 | diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c |
14390 | --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
14391 | +++ linux/fs/aufs/hfsnotify.c 2015-01-25 13:00:38.631047076 +0100 |
14392 | @@ -0,0 +1,288 @@ | |
1facf9fc | 14393 | +/* |
523b37e3 | 14394 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 14395 | + * |
14396 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14397 | + * it under the terms of the GNU General Public License as published by | |
14398 | + * the Free Software Foundation; either version 2 of the License, or | |
14399 | + * (at your option) any later version. | |
dece6358 AM |
14400 | + * |
14401 | + * This program is distributed in the hope that it will be useful, | |
14402 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14403 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14404 | + * GNU General Public License for more details. | |
14405 | + * | |
14406 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14407 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 14408 | + */ |
14409 | + | |
14410 | +/* | |
4a4d8108 | 14411 | + * fsnotify for the lower directories |
1facf9fc | 14412 | + */ |
14413 | + | |
14414 | +#include "aufs.h" | |
14415 | + | |
4a4d8108 AM |
14416 | +/* FS_IN_IGNORED is unnecessary */ |
14417 | +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE | |
14418 | + | FS_CREATE | FS_EVENT_ON_CHILD); | |
7f207e10 | 14419 | +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq); |
7eafdf33 | 14420 | +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0); |
1facf9fc | 14421 | + |
0c5527e5 | 14422 | +static void au_hfsn_free_mark(struct fsnotify_mark *mark) |
1facf9fc | 14423 | +{ |
0c5527e5 AM |
14424 | + struct au_hnotify *hn = container_of(mark, struct au_hnotify, |
14425 | + hn_mark); | |
4a4d8108 | 14426 | + AuDbg("here\n"); |
7eafdf33 | 14427 | + au_cache_free_hnotify(hn); |
076b876e | 14428 | + smp_mb__before_atomic(); |
1716fcea AM |
14429 | + if (atomic64_dec_and_test(&au_hfsn_ifree)) |
14430 | + wake_up(&au_hfsn_wq); | |
4a4d8108 | 14431 | +} |
1facf9fc | 14432 | + |
027c5e7a | 14433 | +static int au_hfsn_alloc(struct au_hinode *hinode) |
4a4d8108 | 14434 | +{ |
1716fcea | 14435 | + int err; |
027c5e7a AM |
14436 | + struct au_hnotify *hn; |
14437 | + struct super_block *sb; | |
14438 | + struct au_branch *br; | |
0c5527e5 | 14439 | + struct fsnotify_mark *mark; |
027c5e7a | 14440 | + aufs_bindex_t bindex; |
1facf9fc | 14441 | + |
027c5e7a AM |
14442 | + hn = hinode->hi_notify; |
14443 | + sb = hn->hn_aufs_inode->i_sb; | |
14444 | + bindex = au_br_index(sb, hinode->hi_id); | |
14445 | + br = au_sbr(sb, bindex); | |
1716fcea AM |
14446 | + AuDebugOn(!br->br_hfsn); |
14447 | + | |
0c5527e5 AM |
14448 | + mark = &hn->hn_mark; |
14449 | + fsnotify_init_mark(mark, au_hfsn_free_mark); | |
14450 | + mark->mask = AuHfsnMask; | |
7f207e10 AM |
14451 | + /* |
14452 | + * by udba rename or rmdir, aufs assign a new inode to the known | |
14453 | + * h_inode, so specify 1 to allow dups. | |
14454 | + */ | |
c1595e42 | 14455 | + lockdep_off(); |
1716fcea | 14456 | + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode, |
027c5e7a | 14457 | + /*mnt*/NULL, /*allow_dups*/1); |
1716fcea AM |
14458 | + /* even if err */ |
14459 | + fsnotify_put_mark(mark); | |
c1595e42 | 14460 | + lockdep_on(); |
1716fcea AM |
14461 | + |
14462 | + return err; | |
1facf9fc | 14463 | +} |
14464 | + | |
7eafdf33 | 14465 | +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn) |
1facf9fc | 14466 | +{ |
0c5527e5 | 14467 | + struct fsnotify_mark *mark; |
7eafdf33 | 14468 | + unsigned long long ull; |
1716fcea | 14469 | + struct fsnotify_group *group; |
7eafdf33 AM |
14470 | + |
14471 | + ull = atomic64_inc_return(&au_hfsn_ifree); | |
14472 | + BUG_ON(!ull); | |
953406b4 | 14473 | + |
0c5527e5 | 14474 | + mark = &hn->hn_mark; |
1716fcea AM |
14475 | + spin_lock(&mark->lock); |
14476 | + group = mark->group; | |
14477 | + fsnotify_get_group(group); | |
14478 | + spin_unlock(&mark->lock); | |
c1595e42 | 14479 | + lockdep_off(); |
1716fcea AM |
14480 | + fsnotify_destroy_mark(mark, group); |
14481 | + fsnotify_put_group(group); | |
c1595e42 | 14482 | + lockdep_on(); |
7f207e10 | 14483 | + |
7eafdf33 AM |
14484 | + /* free hn by myself */ |
14485 | + return 0; | |
1facf9fc | 14486 | +} |
14487 | + | |
14488 | +/* ---------------------------------------------------------------------- */ | |
14489 | + | |
4a4d8108 | 14490 | +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set) |
1facf9fc | 14491 | +{ |
0c5527e5 | 14492 | + struct fsnotify_mark *mark; |
1facf9fc | 14493 | + |
0c5527e5 AM |
14494 | + mark = &hinode->hi_notify->hn_mark; |
14495 | + spin_lock(&mark->lock); | |
1facf9fc | 14496 | + if (do_set) { |
0c5527e5 AM |
14497 | + AuDebugOn(mark->mask & AuHfsnMask); |
14498 | + mark->mask |= AuHfsnMask; | |
1facf9fc | 14499 | + } else { |
0c5527e5 AM |
14500 | + AuDebugOn(!(mark->mask & AuHfsnMask)); |
14501 | + mark->mask &= ~AuHfsnMask; | |
1facf9fc | 14502 | + } |
0c5527e5 | 14503 | + spin_unlock(&mark->lock); |
4a4d8108 | 14504 | + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */ |
1facf9fc | 14505 | +} |
14506 | + | |
4a4d8108 | 14507 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 14508 | + |
4a4d8108 AM |
14509 | +/* #define AuDbgHnotify */ |
14510 | +#ifdef AuDbgHnotify | |
14511 | +static char *au_hfsn_name(u32 mask) | |
14512 | +{ | |
14513 | +#ifdef CONFIG_AUFS_DEBUG | |
c06a8ce3 AM |
14514 | +#define test_ret(flag) \ |
14515 | + do { \ | |
14516 | + if (mask & flag) \ | |
14517 | + return #flag; \ | |
14518 | + } while (0) | |
4a4d8108 AM |
14519 | + test_ret(FS_ACCESS); |
14520 | + test_ret(FS_MODIFY); | |
14521 | + test_ret(FS_ATTRIB); | |
14522 | + test_ret(FS_CLOSE_WRITE); | |
14523 | + test_ret(FS_CLOSE_NOWRITE); | |
14524 | + test_ret(FS_OPEN); | |
14525 | + test_ret(FS_MOVED_FROM); | |
14526 | + test_ret(FS_MOVED_TO); | |
14527 | + test_ret(FS_CREATE); | |
14528 | + test_ret(FS_DELETE); | |
14529 | + test_ret(FS_DELETE_SELF); | |
14530 | + test_ret(FS_MOVE_SELF); | |
14531 | + test_ret(FS_UNMOUNT); | |
14532 | + test_ret(FS_Q_OVERFLOW); | |
14533 | + test_ret(FS_IN_IGNORED); | |
14534 | + test_ret(FS_IN_ISDIR); | |
14535 | + test_ret(FS_IN_ONESHOT); | |
14536 | + test_ret(FS_EVENT_ON_CHILD); | |
14537 | + return ""; | |
14538 | +#undef test_ret | |
14539 | +#else | |
14540 | + return "??"; | |
14541 | +#endif | |
1facf9fc | 14542 | +} |
4a4d8108 | 14543 | +#endif |
1facf9fc | 14544 | + |
14545 | +/* ---------------------------------------------------------------------- */ | |
14546 | + | |
1716fcea AM |
14547 | +static void au_hfsn_free_group(struct fsnotify_group *group) |
14548 | +{ | |
14549 | + struct au_br_hfsnotify *hfsn = group->private; | |
14550 | + | |
14551 | + AuDbg("here\n"); | |
14552 | + kfree(hfsn); | |
14553 | +} | |
14554 | + | |
4a4d8108 | 14555 | +static int au_hfsn_handle_event(struct fsnotify_group *group, |
fb47a38f | 14556 | + struct inode *inode, |
0c5527e5 AM |
14557 | + struct fsnotify_mark *inode_mark, |
14558 | + struct fsnotify_mark *vfsmount_mark, | |
fb47a38f JR |
14559 | + u32 mask, void *data, int data_type, |
14560 | + const unsigned char *file_name, u32 cookie) | |
1facf9fc | 14561 | +{ |
14562 | + int err; | |
4a4d8108 AM |
14563 | + struct au_hnotify *hnotify; |
14564 | + struct inode *h_dir, *h_inode; | |
fb47a38f | 14565 | + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name)); |
4a4d8108 | 14566 | + |
fb47a38f | 14567 | + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE); |
1facf9fc | 14568 | + |
14569 | + err = 0; | |
0c5527e5 | 14570 | + /* if FS_UNMOUNT happens, there must be another bug */ |
4a4d8108 | 14571 | + AuDebugOn(mask & FS_UNMOUNT); |
0c5527e5 | 14572 | + if (mask & (FS_IN_IGNORED | FS_UNMOUNT)) |
1facf9fc | 14573 | + goto out; |
1facf9fc | 14574 | + |
fb47a38f JR |
14575 | + h_dir = inode; |
14576 | + h_inode = NULL; | |
4a4d8108 | 14577 | +#ifdef AuDbgHnotify |
392086de | 14578 | + au_debug_on(); |
4a4d8108 AM |
14579 | + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1 |
14580 | + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) { | |
14581 | + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n", | |
14582 | + h_dir->i_ino, mask, au_hfsn_name(mask), | |
14583 | + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0); | |
14584 | + /* WARN_ON(1); */ | |
1facf9fc | 14585 | + } |
392086de | 14586 | + au_debug_off(); |
1facf9fc | 14587 | +#endif |
4a4d8108 | 14588 | + |
0c5527e5 AM |
14589 | + AuDebugOn(!inode_mark); |
14590 | + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark); | |
14591 | + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode); | |
1facf9fc | 14592 | + |
4a4d8108 AM |
14593 | +out: |
14594 | + return err; | |
14595 | +} | |
1facf9fc | 14596 | + |
4a4d8108 | 14597 | +static struct fsnotify_ops au_hfsn_ops = { |
1716fcea AM |
14598 | + .handle_event = au_hfsn_handle_event, |
14599 | + .free_group_priv = au_hfsn_free_group | |
4a4d8108 AM |
14600 | +}; |
14601 | + | |
14602 | +/* ---------------------------------------------------------------------- */ | |
14603 | + | |
027c5e7a AM |
14604 | +static void au_hfsn_fin_br(struct au_branch *br) |
14605 | +{ | |
1716fcea | 14606 | + struct au_br_hfsnotify *hfsn; |
027c5e7a | 14607 | + |
1716fcea | 14608 | + hfsn = br->br_hfsn; |
c1595e42 JR |
14609 | + if (hfsn) { |
14610 | + lockdep_off(); | |
1716fcea | 14611 | + fsnotify_put_group(hfsn->hfsn_group); |
c1595e42 JR |
14612 | + lockdep_on(); |
14613 | + } | |
027c5e7a AM |
14614 | +} |
14615 | + | |
1716fcea | 14616 | +static int au_hfsn_init_br(struct au_branch *br, int perm) |
4a4d8108 AM |
14617 | +{ |
14618 | + int err; | |
1716fcea AM |
14619 | + struct fsnotify_group *group; |
14620 | + struct au_br_hfsnotify *hfsn; | |
1facf9fc | 14621 | + |
4a4d8108 | 14622 | + err = 0; |
1716fcea AM |
14623 | + br->br_hfsn = NULL; |
14624 | + if (!au_br_hnotifyable(perm)) | |
027c5e7a | 14625 | + goto out; |
027c5e7a | 14626 | + |
1716fcea AM |
14627 | + err = -ENOMEM; |
14628 | + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS); | |
14629 | + if (unlikely(!hfsn)) | |
027c5e7a AM |
14630 | + goto out; |
14631 | + | |
1716fcea AM |
14632 | + err = 0; |
14633 | + group = fsnotify_alloc_group(&au_hfsn_ops); | |
14634 | + if (IS_ERR(group)) { | |
14635 | + err = PTR_ERR(group); | |
0c5527e5 | 14636 | + pr_err("fsnotify_alloc_group() failed, %d\n", err); |
1716fcea | 14637 | + goto out_hfsn; |
4a4d8108 | 14638 | + } |
1facf9fc | 14639 | + |
1716fcea AM |
14640 | + group->private = hfsn; |
14641 | + hfsn->hfsn_group = group; | |
14642 | + br->br_hfsn = hfsn; | |
14643 | + goto out; /* success */ | |
14644 | + | |
14645 | +out_hfsn: | |
14646 | + kfree(hfsn); | |
027c5e7a | 14647 | +out: |
1716fcea AM |
14648 | + return err; |
14649 | +} | |
14650 | + | |
14651 | +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
14652 | +{ | |
14653 | + int err; | |
14654 | + | |
14655 | + err = 0; | |
14656 | + if (!br->br_hfsn) | |
14657 | + err = au_hfsn_init_br(br, perm); | |
14658 | + | |
1facf9fc | 14659 | + return err; |
14660 | +} | |
14661 | + | |
7eafdf33 AM |
14662 | +/* ---------------------------------------------------------------------- */ |
14663 | + | |
14664 | +static void au_hfsn_fin(void) | |
14665 | +{ | |
14666 | + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree)); | |
14667 | + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree)); | |
14668 | +} | |
14669 | + | |
4a4d8108 AM |
14670 | +const struct au_hnotify_op au_hnotify_op = { |
14671 | + .ctl = au_hfsn_ctl, | |
14672 | + .alloc = au_hfsn_alloc, | |
14673 | + .free = au_hfsn_free, | |
1facf9fc | 14674 | + |
7eafdf33 AM |
14675 | + .fin = au_hfsn_fin, |
14676 | + | |
027c5e7a AM |
14677 | + .reset_br = au_hfsn_reset_br, |
14678 | + .fin_br = au_hfsn_fin_br, | |
14679 | + .init_br = au_hfsn_init_br | |
4a4d8108 | 14680 | +}; |
7f207e10 AM |
14681 | diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c |
14682 | --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 14683 | +++ linux/fs/aufs/hfsplus.c 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 14684 | @@ -0,0 +1,56 @@ |
4a4d8108 | 14685 | +/* |
523b37e3 | 14686 | + * Copyright (C) 2010-2014 Junjiro R. Okajima |
4a4d8108 AM |
14687 | + * |
14688 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14689 | + * it under the terms of the GNU General Public License as published by | |
14690 | + * the Free Software Foundation; either version 2 of the License, or | |
14691 | + * (at your option) any later version. | |
14692 | + * | |
14693 | + * This program is distributed in the hope that it will be useful, | |
14694 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14695 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14696 | + * GNU General Public License for more details. | |
14697 | + * | |
14698 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14699 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 14700 | + */ |
1facf9fc | 14701 | + |
4a4d8108 AM |
14702 | +/* |
14703 | + * special support for filesystems which aqucires an inode mutex | |
14704 | + * at final closing a file, eg, hfsplus. | |
14705 | + * | |
14706 | + * This trick is very simple and stupid, just to open the file before really | |
14707 | + * neceeary open to tell hfsplus that this is not the final closing. | |
14708 | + * The caller should call au_h_open_pre() after acquiring the inode mutex, | |
14709 | + * and au_h_open_post() after releasing it. | |
14710 | + */ | |
1facf9fc | 14711 | + |
4a4d8108 | 14712 | +#include "aufs.h" |
1facf9fc | 14713 | + |
392086de AM |
14714 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
14715 | + int force_wr) | |
4a4d8108 AM |
14716 | +{ |
14717 | + struct file *h_file; | |
14718 | + struct dentry *h_dentry; | |
1facf9fc | 14719 | + |
4a4d8108 AM |
14720 | + h_dentry = au_h_dptr(dentry, bindex); |
14721 | + AuDebugOn(!h_dentry); | |
14722 | + AuDebugOn(!h_dentry->d_inode); | |
4a4d8108 AM |
14723 | + |
14724 | + h_file = NULL; | |
14725 | + if (au_test_hfsplus(h_dentry->d_sb) | |
14726 | + && S_ISREG(h_dentry->d_inode->i_mode)) | |
14727 | + h_file = au_h_open(dentry, bindex, | |
14728 | + O_RDONLY | O_NOATIME | O_LARGEFILE, | |
392086de | 14729 | + /*file*/NULL, force_wr); |
4a4d8108 | 14730 | + return h_file; |
1facf9fc | 14731 | +} |
14732 | + | |
4a4d8108 AM |
14733 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
14734 | + struct file *h_file) | |
14735 | +{ | |
14736 | + if (h_file) { | |
14737 | + fput(h_file); | |
14738 | + au_sbr_put(dentry->d_sb, bindex); | |
14739 | + } | |
14740 | +} | |
7f207e10 AM |
14741 | diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c |
14742 | --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 14743 | +++ linux/fs/aufs/hnotify.c 2015-01-25 13:00:38.631047076 +0100 |
076b876e | 14744 | @@ -0,0 +1,714 @@ |
e49829fe | 14745 | +/* |
523b37e3 | 14746 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
e49829fe JR |
14747 | + * |
14748 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14749 | + * it under the terms of the GNU General Public License as published by | |
14750 | + * the Free Software Foundation; either version 2 of the License, or | |
14751 | + * (at your option) any later version. | |
14752 | + * | |
14753 | + * This program is distributed in the hope that it will be useful, | |
14754 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14755 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14756 | + * GNU General Public License for more details. | |
14757 | + * | |
14758 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14759 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
14760 | + */ |
14761 | + | |
14762 | +/* | |
7f207e10 | 14763 | + * abstraction to notify the direct changes on lower directories |
e49829fe JR |
14764 | + */ |
14765 | + | |
14766 | +#include "aufs.h" | |
14767 | + | |
027c5e7a | 14768 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode) |
e49829fe JR |
14769 | +{ |
14770 | + int err; | |
7f207e10 | 14771 | + struct au_hnotify *hn; |
1facf9fc | 14772 | + |
4a4d8108 AM |
14773 | + err = -ENOMEM; |
14774 | + hn = au_cache_alloc_hnotify(); | |
14775 | + if (hn) { | |
14776 | + hn->hn_aufs_inode = inode; | |
027c5e7a AM |
14777 | + hinode->hi_notify = hn; |
14778 | + err = au_hnotify_op.alloc(hinode); | |
14779 | + AuTraceErr(err); | |
14780 | + if (unlikely(err)) { | |
14781 | + hinode->hi_notify = NULL; | |
4a4d8108 AM |
14782 | + au_cache_free_hnotify(hn); |
14783 | + /* | |
14784 | + * The upper dir was removed by udba, but the same named | |
14785 | + * dir left. In this case, aufs assignes a new inode | |
14786 | + * number and set the monitor again. | |
14787 | + * For the lower dir, the old monitnor is still left. | |
14788 | + */ | |
14789 | + if (err == -EEXIST) | |
14790 | + err = 0; | |
14791 | + } | |
1308ab2a | 14792 | + } |
1308ab2a | 14793 | + |
027c5e7a | 14794 | + AuTraceErr(err); |
1308ab2a | 14795 | + return err; |
dece6358 | 14796 | +} |
1facf9fc | 14797 | + |
4a4d8108 | 14798 | +void au_hn_free(struct au_hinode *hinode) |
dece6358 | 14799 | +{ |
4a4d8108 | 14800 | + struct au_hnotify *hn; |
1facf9fc | 14801 | + |
4a4d8108 AM |
14802 | + hn = hinode->hi_notify; |
14803 | + if (hn) { | |
4a4d8108 | 14804 | + hinode->hi_notify = NULL; |
7eafdf33 AM |
14805 | + if (au_hnotify_op.free(hinode, hn)) |
14806 | + au_cache_free_hnotify(hn); | |
4a4d8108 AM |
14807 | + } |
14808 | +} | |
dece6358 | 14809 | + |
4a4d8108 | 14810 | +/* ---------------------------------------------------------------------- */ |
dece6358 | 14811 | + |
4a4d8108 AM |
14812 | +void au_hn_ctl(struct au_hinode *hinode, int do_set) |
14813 | +{ | |
14814 | + if (hinode->hi_notify) | |
14815 | + au_hnotify_op.ctl(hinode, do_set); | |
14816 | +} | |
14817 | + | |
14818 | +void au_hn_reset(struct inode *inode, unsigned int flags) | |
14819 | +{ | |
14820 | + aufs_bindex_t bindex, bend; | |
14821 | + struct inode *hi; | |
14822 | + struct dentry *iwhdentry; | |
1facf9fc | 14823 | + |
1308ab2a | 14824 | + bend = au_ibend(inode); |
4a4d8108 AM |
14825 | + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) { |
14826 | + hi = au_h_iptr(inode, bindex); | |
14827 | + if (!hi) | |
14828 | + continue; | |
1308ab2a | 14829 | + |
4a4d8108 AM |
14830 | + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */ |
14831 | + iwhdentry = au_hi_wh(inode, bindex); | |
14832 | + if (iwhdentry) | |
14833 | + dget(iwhdentry); | |
14834 | + au_igrab(hi); | |
14835 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
14836 | + au_set_h_iptr(inode, bindex, au_igrab(hi), | |
14837 | + flags & ~AuHi_XINO); | |
14838 | + iput(hi); | |
14839 | + dput(iwhdentry); | |
14840 | + /* mutex_unlock(&hi->i_mutex); */ | |
1facf9fc | 14841 | + } |
1facf9fc | 14842 | +} |
14843 | + | |
1308ab2a | 14844 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 14845 | + |
4a4d8108 | 14846 | +static int hn_xino(struct inode *inode, struct inode *h_inode) |
1facf9fc | 14847 | +{ |
4a4d8108 AM |
14848 | + int err; |
14849 | + aufs_bindex_t bindex, bend, bfound, bstart; | |
14850 | + struct inode *h_i; | |
1facf9fc | 14851 | + |
4a4d8108 AM |
14852 | + err = 0; |
14853 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 14854 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
14855 | + goto out; |
14856 | + } | |
1facf9fc | 14857 | + |
4a4d8108 AM |
14858 | + bfound = -1; |
14859 | + bend = au_ibend(inode); | |
14860 | + bstart = au_ibstart(inode); | |
14861 | +#if 0 /* reserved for future use */ | |
14862 | + if (bindex == bend) { | |
14863 | + /* keep this ino in rename case */ | |
14864 | + goto out; | |
14865 | + } | |
14866 | +#endif | |
14867 | + for (bindex = bstart; bindex <= bend; bindex++) | |
14868 | + if (au_h_iptr(inode, bindex) == h_inode) { | |
14869 | + bfound = bindex; | |
14870 | + break; | |
14871 | + } | |
14872 | + if (bfound < 0) | |
1308ab2a | 14873 | + goto out; |
1facf9fc | 14874 | + |
4a4d8108 AM |
14875 | + for (bindex = bstart; bindex <= bend; bindex++) { |
14876 | + h_i = au_h_iptr(inode, bindex); | |
14877 | + if (!h_i) | |
14878 | + continue; | |
1facf9fc | 14879 | + |
4a4d8108 AM |
14880 | + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0); |
14881 | + /* ignore this error */ | |
14882 | + /* bad action? */ | |
1facf9fc | 14883 | + } |
1facf9fc | 14884 | + |
4a4d8108 | 14885 | + /* children inode number will be broken */ |
1facf9fc | 14886 | + |
4f0767ce | 14887 | +out: |
4a4d8108 AM |
14888 | + AuTraceErr(err); |
14889 | + return err; | |
1facf9fc | 14890 | +} |
14891 | + | |
4a4d8108 | 14892 | +static int hn_gen_tree(struct dentry *dentry) |
1facf9fc | 14893 | +{ |
4a4d8108 AM |
14894 | + int err, i, j, ndentry; |
14895 | + struct au_dcsub_pages dpages; | |
14896 | + struct au_dpage *dpage; | |
14897 | + struct dentry **dentries; | |
1facf9fc | 14898 | + |
4a4d8108 AM |
14899 | + err = au_dpages_init(&dpages, GFP_NOFS); |
14900 | + if (unlikely(err)) | |
14901 | + goto out; | |
14902 | + err = au_dcsub_pages(&dpages, dentry, NULL, NULL); | |
14903 | + if (unlikely(err)) | |
14904 | + goto out_dpages; | |
1facf9fc | 14905 | + |
4a4d8108 AM |
14906 | + for (i = 0; i < dpages.ndpage; i++) { |
14907 | + dpage = dpages.dpages + i; | |
14908 | + dentries = dpage->dentries; | |
14909 | + ndentry = dpage->ndentry; | |
14910 | + for (j = 0; j < ndentry; j++) { | |
14911 | + struct dentry *d; | |
14912 | + | |
14913 | + d = dentries[j]; | |
14914 | + if (IS_ROOT(d)) | |
14915 | + continue; | |
14916 | + | |
4a4d8108 AM |
14917 | + au_digen_dec(d); |
14918 | + if (d->d_inode) | |
14919 | + /* todo: reset children xino? | |
14920 | + cached children only? */ | |
14921 | + au_iigen_dec(d->d_inode); | |
1308ab2a | 14922 | + } |
dece6358 | 14923 | + } |
1facf9fc | 14924 | + |
4f0767ce | 14925 | +out_dpages: |
4a4d8108 | 14926 | + au_dpages_free(&dpages); |
dece6358 | 14927 | + |
027c5e7a | 14928 | +#if 0 |
4a4d8108 AM |
14929 | + /* discard children */ |
14930 | + dentry_unhash(dentry); | |
14931 | + dput(dentry); | |
027c5e7a | 14932 | +#endif |
4f0767ce | 14933 | +out: |
dece6358 AM |
14934 | + return err; |
14935 | +} | |
14936 | + | |
1308ab2a | 14937 | +/* |
4a4d8108 | 14938 | + * return 0 if processed. |
1308ab2a | 14939 | + */ |
4a4d8108 AM |
14940 | +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode, |
14941 | + const unsigned int isdir) | |
dece6358 | 14942 | +{ |
1308ab2a | 14943 | + int err; |
4a4d8108 AM |
14944 | + struct dentry *d; |
14945 | + struct qstr *dname; | |
1facf9fc | 14946 | + |
4a4d8108 AM |
14947 | + err = 1; |
14948 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 14949 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
14950 | + err = 0; |
14951 | + goto out; | |
14952 | + } | |
dece6358 | 14953 | + |
4a4d8108 AM |
14954 | + if (!isdir) { |
14955 | + AuDebugOn(!name); | |
14956 | + au_iigen_dec(inode); | |
027c5e7a | 14957 | + spin_lock(&inode->i_lock); |
c1595e42 | 14958 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 14959 | + spin_lock(&d->d_lock); |
4a4d8108 AM |
14960 | + dname = &d->d_name; |
14961 | + if (dname->len != nlen | |
027c5e7a AM |
14962 | + && memcmp(dname->name, name, nlen)) { |
14963 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 14964 | + continue; |
027c5e7a | 14965 | + } |
4a4d8108 | 14966 | + err = 0; |
4a4d8108 AM |
14967 | + au_digen_dec(d); |
14968 | + spin_unlock(&d->d_lock); | |
14969 | + break; | |
1facf9fc | 14970 | + } |
027c5e7a | 14971 | + spin_unlock(&inode->i_lock); |
1308ab2a | 14972 | + } else { |
027c5e7a | 14973 | + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR); |
c1595e42 | 14974 | + d = d_find_any_alias(inode); |
4a4d8108 AM |
14975 | + if (!d) { |
14976 | + au_iigen_dec(inode); | |
14977 | + goto out; | |
14978 | + } | |
1facf9fc | 14979 | + |
027c5e7a | 14980 | + spin_lock(&d->d_lock); |
4a4d8108 | 14981 | + dname = &d->d_name; |
027c5e7a AM |
14982 | + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) { |
14983 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 14984 | + err = hn_gen_tree(d); |
027c5e7a AM |
14985 | + spin_lock(&d->d_lock); |
14986 | + } | |
14987 | + spin_unlock(&d->d_lock); | |
4a4d8108 AM |
14988 | + dput(d); |
14989 | + } | |
1facf9fc | 14990 | + |
4f0767ce | 14991 | +out: |
4a4d8108 | 14992 | + AuTraceErr(err); |
1308ab2a | 14993 | + return err; |
14994 | +} | |
dece6358 | 14995 | + |
4a4d8108 | 14996 | +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir) |
1facf9fc | 14997 | +{ |
4a4d8108 AM |
14998 | + int err; |
14999 | + struct inode *inode; | |
1facf9fc | 15000 | + |
4a4d8108 AM |
15001 | + inode = dentry->d_inode; |
15002 | + if (IS_ROOT(dentry) | |
15003 | + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */ | |
15004 | + ) { | |
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 AM |
15011 | + au_digen_dec(dentry); |
15012 | + if (inode) | |
15013 | + au_iigen_dec(inode); | |
15014 | + } else { | |
027c5e7a | 15015 | + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR); |
4a4d8108 AM |
15016 | + if (inode) |
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; | |
15236 | + if (dentry) | |
15237 | + inode = dentry->d_inode; | |
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 | |
c1595e42 | 15461 | +++ linux/fs/aufs/iinfo.c 2015-01-25 13:00:38.631047076 +0100 |
38d290e6 | 15462 | @@ -0,0 +1,277 @@ |
dece6358 | 15463 | +/* |
523b37e3 | 15464 | + * Copyright (C) 2005-2014 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 | |
c1595e42 JR |
15742 | +++ linux/fs/aufs/inode.c 2015-01-25 13:00:38.631047076 +0100 |
15743 | @@ -0,0 +1,496 @@ | |
4a4d8108 | 15744 | +/* |
523b37e3 | 15745 | + * Copyright (C) 2005-2014 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++) { | |
15880 | + struct inode *h_i; | |
15881 | + struct dentry *h_d; | |
15882 | + | |
15883 | + h_d = au_h_dptr(dentry, bindex); | |
15884 | + if (!h_d || !h_d->d_inode) | |
15885 | + continue; | |
15886 | + | |
027c5e7a | 15887 | + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT)); |
4a4d8108 AM |
15888 | + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) { |
15889 | + h_i = au_h_iptr(inode, bindex); | |
15890 | + if (h_i) { | |
15891 | + if (h_i == h_d->d_inode) | |
15892 | + continue; | |
15893 | + err = -EIO; | |
15894 | + break; | |
15895 | + } | |
15896 | + } | |
15897 | + if (bindex < iinfo->ii_bstart) | |
15898 | + iinfo->ii_bstart = bindex; | |
15899 | + if (iinfo->ii_bend < bindex) | |
15900 | + iinfo->ii_bend = bindex; | |
15901 | + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags); | |
15902 | + update = 1; | |
1308ab2a | 15903 | + } |
4a4d8108 AM |
15904 | + au_update_ibrange(inode, /*do_put_zero*/0); |
15905 | + e = au_dy_irefresh(inode); | |
15906 | + if (unlikely(e && !err)) | |
15907 | + err = e; | |
027c5e7a AM |
15908 | + if (!err) |
15909 | + au_refresh_hinode_attr(inode, update && isdir); | |
4a4d8108 | 15910 | + |
4f0767ce | 15911 | +out: |
4a4d8108 | 15912 | + AuTraceErr(err); |
1308ab2a | 15913 | + return err; |
dece6358 AM |
15914 | +} |
15915 | + | |
4a4d8108 | 15916 | +static int set_inode(struct inode *inode, struct dentry *dentry) |
dece6358 | 15917 | +{ |
4a4d8108 AM |
15918 | + int err; |
15919 | + unsigned int flags; | |
15920 | + umode_t mode; | |
15921 | + aufs_bindex_t bindex, bstart, btail; | |
15922 | + unsigned char isdir; | |
15923 | + struct dentry *h_dentry; | |
15924 | + struct inode *h_inode; | |
15925 | + struct au_iinfo *iinfo; | |
dece6358 | 15926 | + |
4a4d8108 | 15927 | + IiMustWriteLock(inode); |
dece6358 | 15928 | + |
4a4d8108 AM |
15929 | + err = 0; |
15930 | + isdir = 0; | |
15931 | + bstart = au_dbstart(dentry); | |
15932 | + h_inode = au_h_dptr(dentry, bstart)->d_inode; | |
15933 | + mode = h_inode->i_mode; | |
15934 | + switch (mode & S_IFMT) { | |
15935 | + case S_IFREG: | |
15936 | + btail = au_dbtail(dentry); | |
15937 | + inode->i_op = &aufs_iop; | |
15938 | + inode->i_fop = &aufs_file_fop; | |
15939 | + err = au_dy_iaop(inode, bstart, h_inode); | |
15940 | + if (unlikely(err)) | |
15941 | + goto out; | |
15942 | + break; | |
15943 | + case S_IFDIR: | |
15944 | + isdir = 1; | |
15945 | + btail = au_dbtaildir(dentry); | |
15946 | + inode->i_op = &aufs_dir_iop; | |
15947 | + inode->i_fop = &aufs_dir_fop; | |
15948 | + break; | |
15949 | + case S_IFLNK: | |
15950 | + btail = au_dbtail(dentry); | |
15951 | + inode->i_op = &aufs_symlink_iop; | |
15952 | + break; | |
15953 | + case S_IFBLK: | |
15954 | + case S_IFCHR: | |
15955 | + case S_IFIFO: | |
15956 | + case S_IFSOCK: | |
15957 | + btail = au_dbtail(dentry); | |
15958 | + inode->i_op = &aufs_iop; | |
38d290e6 | 15959 | + init_special_inode(inode, mode, h_inode->i_rdev); |
4a4d8108 AM |
15960 | + break; |
15961 | + default: | |
15962 | + AuIOErr("Unknown file type 0%o\n", mode); | |
15963 | + err = -EIO; | |
1308ab2a | 15964 | + goto out; |
4a4d8108 | 15965 | + } |
dece6358 | 15966 | + |
4a4d8108 AM |
15967 | + /* do not set hnotify for whiteouted dirs (SHWH mode) */ |
15968 | + flags = au_hi_flags(inode, isdir); | |
15969 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH) | |
15970 | + && au_ftest_hi(flags, HNOTIFY) | |
15971 | + && dentry->d_name.len > AUFS_WH_PFX_LEN | |
15972 | + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) | |
15973 | + au_fclr_hi(flags, HNOTIFY); | |
15974 | + iinfo = au_ii(inode); | |
15975 | + iinfo->ii_bstart = bstart; | |
15976 | + iinfo->ii_bend = btail; | |
15977 | + for (bindex = bstart; bindex <= btail; bindex++) { | |
15978 | + h_dentry = au_h_dptr(dentry, bindex); | |
15979 | + if (h_dentry) | |
15980 | + au_set_h_iptr(inode, bindex, | |
15981 | + au_igrab(h_dentry->d_inode), flags); | |
15982 | + } | |
15983 | + au_cpup_attr_all(inode, /*force*/1); | |
c1595e42 JR |
15984 | + /* |
15985 | + * to force calling aufs_get_acl() every time, | |
15986 | + * do not call cache_no_acl() for aufs inode. | |
15987 | + */ | |
dece6358 | 15988 | + |
4f0767ce | 15989 | +out: |
4a4d8108 AM |
15990 | + return err; |
15991 | +} | |
dece6358 | 15992 | + |
027c5e7a AM |
15993 | +/* |
15994 | + * successful returns with iinfo write_locked | |
15995 | + * minus: errno | |
15996 | + * zero: success, matched | |
15997 | + * plus: no error, but unmatched | |
15998 | + */ | |
15999 | +static int reval_inode(struct inode *inode, struct dentry *dentry) | |
4a4d8108 AM |
16000 | +{ |
16001 | + int err; | |
537831f9 AM |
16002 | + unsigned int gen; |
16003 | + struct au_iigen iigen; | |
4a4d8108 AM |
16004 | + aufs_bindex_t bindex, bend; |
16005 | + struct inode *h_inode, *h_dinode; | |
dece6358 | 16006 | + |
4a4d8108 AM |
16007 | + /* |
16008 | + * before this function, if aufs got any iinfo lock, it must be only | |
16009 | + * one, the parent dir. | |
16010 | + * it can happen by UDBA and the obsoleted inode number. | |
16011 | + */ | |
16012 | + err = -EIO; | |
16013 | + if (unlikely(inode->i_ino == parent_ino(dentry))) | |
16014 | + goto out; | |
16015 | + | |
027c5e7a | 16016 | + err = 1; |
4a4d8108 AM |
16017 | + ii_write_lock_new_child(inode); |
16018 | + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode; | |
16019 | + bend = au_ibend(inode); | |
16020 | + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) { | |
16021 | + h_inode = au_h_iptr(inode, bindex); | |
537831f9 AM |
16022 | + if (!h_inode || h_inode != h_dinode) |
16023 | + continue; | |
16024 | + | |
16025 | + err = 0; | |
16026 | + gen = au_iigen(inode, &iigen); | |
16027 | + if (gen == au_digen(dentry) | |
16028 | + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED)) | |
4a4d8108 | 16029 | + break; |
537831f9 AM |
16030 | + |
16031 | + /* fully refresh inode using dentry */ | |
16032 | + err = au_refresh_hinode(inode, dentry); | |
16033 | + if (!err) | |
16034 | + au_update_iigen(inode, /*half*/0); | |
16035 | + break; | |
1facf9fc | 16036 | + } |
dece6358 | 16037 | + |
4a4d8108 AM |
16038 | + if (unlikely(err)) |
16039 | + ii_write_unlock(inode); | |
4f0767ce | 16040 | +out: |
1facf9fc | 16041 | + return err; |
16042 | +} | |
1facf9fc | 16043 | + |
4a4d8108 AM |
16044 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
16045 | + unsigned int d_type, ino_t *ino) | |
1facf9fc | 16046 | +{ |
4a4d8108 AM |
16047 | + int err; |
16048 | + struct mutex *mtx; | |
1facf9fc | 16049 | + |
b752ccd1 | 16050 | + /* prevent hardlinked inode number from race condition */ |
4a4d8108 | 16051 | + mtx = NULL; |
b752ccd1 | 16052 | + if (d_type != DT_DIR) { |
4a4d8108 AM |
16053 | + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx; |
16054 | + mutex_lock(mtx); | |
16055 | + } | |
16056 | + err = au_xino_read(sb, bindex, h_ino, ino); | |
16057 | + if (unlikely(err)) | |
16058 | + goto out; | |
1308ab2a | 16059 | + |
4a4d8108 AM |
16060 | + if (!*ino) { |
16061 | + err = -EIO; | |
16062 | + *ino = au_xino_new_ino(sb); | |
16063 | + if (unlikely(!*ino)) | |
1facf9fc | 16064 | + goto out; |
4a4d8108 AM |
16065 | + err = au_xino_write(sb, bindex, h_ino, *ino); |
16066 | + if (unlikely(err)) | |
1308ab2a | 16067 | + goto out; |
1308ab2a | 16068 | + } |
1facf9fc | 16069 | + |
4f0767ce | 16070 | +out: |
b752ccd1 | 16071 | + if (mtx) |
4a4d8108 | 16072 | + mutex_unlock(mtx); |
1facf9fc | 16073 | + return err; |
16074 | +} | |
16075 | + | |
4a4d8108 AM |
16076 | +/* successful returns with iinfo write_locked */ |
16077 | +/* todo: return with unlocked? */ | |
16078 | +struct inode *au_new_inode(struct dentry *dentry, int must_new) | |
1facf9fc | 16079 | +{ |
b752ccd1 | 16080 | + struct inode *inode, *h_inode; |
4a4d8108 AM |
16081 | + struct dentry *h_dentry; |
16082 | + struct super_block *sb; | |
b752ccd1 | 16083 | + struct mutex *mtx; |
4a4d8108 | 16084 | + ino_t h_ino, ino; |
1716fcea | 16085 | + int err; |
4a4d8108 | 16086 | + aufs_bindex_t bstart; |
1facf9fc | 16087 | + |
4a4d8108 AM |
16088 | + sb = dentry->d_sb; |
16089 | + bstart = au_dbstart(dentry); | |
16090 | + h_dentry = au_h_dptr(dentry, bstart); | |
b752ccd1 AM |
16091 | + h_inode = h_dentry->d_inode; |
16092 | + h_ino = h_inode->i_ino; | |
16093 | + | |
16094 | + /* | |
16095 | + * stop 'race'-ing between hardlinks under different | |
16096 | + * parents. | |
16097 | + */ | |
16098 | + mtx = NULL; | |
16099 | + if (!S_ISDIR(h_inode->i_mode)) | |
16100 | + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx; | |
16101 | + | |
4f0767ce | 16102 | +new_ino: |
b752ccd1 AM |
16103 | + if (mtx) |
16104 | + mutex_lock(mtx); | |
4a4d8108 AM |
16105 | + err = au_xino_read(sb, bstart, h_ino, &ino); |
16106 | + inode = ERR_PTR(err); | |
16107 | + if (unlikely(err)) | |
16108 | + goto out; | |
b752ccd1 | 16109 | + |
4a4d8108 AM |
16110 | + if (!ino) { |
16111 | + ino = au_xino_new_ino(sb); | |
16112 | + if (unlikely(!ino)) { | |
16113 | + inode = ERR_PTR(-EIO); | |
dece6358 AM |
16114 | + goto out; |
16115 | + } | |
16116 | + } | |
1facf9fc | 16117 | + |
4a4d8108 AM |
16118 | + AuDbg("i%lu\n", (unsigned long)ino); |
16119 | + inode = au_iget_locked(sb, ino); | |
16120 | + err = PTR_ERR(inode); | |
16121 | + if (IS_ERR(inode)) | |
1facf9fc | 16122 | + goto out; |
1facf9fc | 16123 | + |
4a4d8108 AM |
16124 | + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW)); |
16125 | + if (inode->i_state & I_NEW) { | |
1716fcea AM |
16126 | + /* verbose coding for lock class name */ |
16127 | + if (unlikely(S_ISLNK(h_inode->i_mode))) | |
16128 | + au_rw_class(&au_ii(inode)->ii_rwsem, | |
16129 | + au_lc_key + AuLcSymlink_IIINFO); | |
16130 | + else if (unlikely(S_ISDIR(h_inode->i_mode))) | |
16131 | + au_rw_class(&au_ii(inode)->ii_rwsem, | |
16132 | + au_lc_key + AuLcDir_IIINFO); | |
16133 | + else /* likely */ | |
16134 | + au_rw_class(&au_ii(inode)->ii_rwsem, | |
16135 | + au_lc_key + AuLcNonDir_IIINFO); | |
2dfbb274 | 16136 | + |
4a4d8108 AM |
16137 | + ii_write_lock_new_child(inode); |
16138 | + err = set_inode(inode, dentry); | |
16139 | + if (!err) { | |
16140 | + unlock_new_inode(inode); | |
16141 | + goto out; /* success */ | |
16142 | + } | |
1308ab2a | 16143 | + |
027c5e7a AM |
16144 | + /* |
16145 | + * iget_failed() calls iput(), but we need to call | |
16146 | + * ii_write_unlock() after iget_failed(). so dirty hack for | |
16147 | + * i_count. | |
16148 | + */ | |
16149 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 16150 | + iget_failed(inode); |
027c5e7a AM |
16151 | + ii_write_unlock(inode); |
16152 | + au_xino_write(sb, bstart, h_ino, /*ino*/0); | |
16153 | + /* ignore this error */ | |
16154 | + goto out_iput; | |
16155 | + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) { | |
b752ccd1 AM |
16156 | + /* |
16157 | + * horrible race condition between lookup, readdir and copyup | |
16158 | + * (or something). | |
16159 | + */ | |
16160 | + if (mtx) | |
16161 | + mutex_unlock(mtx); | |
027c5e7a AM |
16162 | + err = reval_inode(inode, dentry); |
16163 | + if (unlikely(err < 0)) { | |
16164 | + mtx = NULL; | |
16165 | + goto out_iput; | |
16166 | + } | |
16167 | + | |
b752ccd1 AM |
16168 | + if (!err) { |
16169 | + mtx = NULL; | |
4a4d8108 | 16170 | + goto out; /* success */ |
b752ccd1 AM |
16171 | + } else if (mtx) |
16172 | + mutex_lock(mtx); | |
4a4d8108 AM |
16173 | + } |
16174 | + | |
16175 | + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode))) | |
16176 | + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir," | |
523b37e3 AM |
16177 | + " b%d, %s, %pd, hi%lu, i%lu.\n", |
16178 | + bstart, au_sbtype(h_dentry->d_sb), dentry, | |
4a4d8108 AM |
16179 | + (unsigned long)h_ino, (unsigned long)ino); |
16180 | + ino = 0; | |
16181 | + err = au_xino_write(sb, bstart, h_ino, /*ino*/0); | |
16182 | + if (!err) { | |
16183 | + iput(inode); | |
b752ccd1 AM |
16184 | + if (mtx) |
16185 | + mutex_unlock(mtx); | |
4a4d8108 AM |
16186 | + goto new_ino; |
16187 | + } | |
1308ab2a | 16188 | + |
4f0767ce | 16189 | +out_iput: |
4a4d8108 | 16190 | + iput(inode); |
4a4d8108 | 16191 | + inode = ERR_PTR(err); |
4f0767ce | 16192 | +out: |
b752ccd1 AM |
16193 | + if (mtx) |
16194 | + mutex_unlock(mtx); | |
4a4d8108 | 16195 | + return inode; |
1facf9fc | 16196 | +} |
16197 | + | |
4a4d8108 | 16198 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16199 | + |
4a4d8108 AM |
16200 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, |
16201 | + struct inode *inode) | |
16202 | +{ | |
16203 | + int err; | |
076b876e | 16204 | + struct inode *hi; |
1facf9fc | 16205 | + |
4a4d8108 | 16206 | + err = au_br_rdonly(au_sbr(sb, bindex)); |
1facf9fc | 16207 | + |
4a4d8108 AM |
16208 | + /* pseudo-link after flushed may happen out of bounds */ |
16209 | + if (!err | |
16210 | + && inode | |
16211 | + && au_ibstart(inode) <= bindex | |
16212 | + && bindex <= au_ibend(inode)) { | |
16213 | + /* | |
16214 | + * permission check is unnecessary since vfsub routine | |
16215 | + * will be called later | |
16216 | + */ | |
076b876e | 16217 | + hi = au_h_iptr(inode, bindex); |
4a4d8108 AM |
16218 | + if (hi) |
16219 | + err = IS_IMMUTABLE(hi) ? -EROFS : 0; | |
1facf9fc | 16220 | + } |
16221 | + | |
4a4d8108 AM |
16222 | + return err; |
16223 | +} | |
dece6358 | 16224 | + |
4a4d8108 AM |
16225 | +int au_test_h_perm(struct inode *h_inode, int mask) |
16226 | +{ | |
2dfbb274 | 16227 | + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) |
4a4d8108 AM |
16228 | + return 0; |
16229 | + return inode_permission(h_inode, mask); | |
16230 | +} | |
1facf9fc | 16231 | + |
4a4d8108 AM |
16232 | +int au_test_h_perm_sio(struct inode *h_inode, int mask) |
16233 | +{ | |
16234 | + if (au_test_nfs(h_inode->i_sb) | |
16235 | + && (mask & MAY_WRITE) | |
16236 | + && S_ISDIR(h_inode->i_mode)) | |
16237 | + mask |= MAY_READ; /* force permission check */ | |
16238 | + return au_test_h_perm(h_inode, mask); | |
1facf9fc | 16239 | +} |
7f207e10 AM |
16240 | diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h |
16241 | --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
16242 | +++ linux/fs/aufs/inode.h 2015-01-25 13:00:38.631047076 +0100 |
16243 | @@ -0,0 +1,667 @@ | |
4a4d8108 | 16244 | +/* |
523b37e3 | 16245 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
16246 | + * |
16247 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16248 | + * it under the terms of the GNU General Public License as published by | |
16249 | + * the Free Software Foundation; either version 2 of the License, or | |
16250 | + * (at your option) any later version. | |
16251 | + * | |
16252 | + * This program is distributed in the hope that it will be useful, | |
16253 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16254 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16255 | + * GNU General Public License for more details. | |
16256 | + * | |
16257 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16258 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 16259 | + */ |
1facf9fc | 16260 | + |
1308ab2a | 16261 | +/* |
4a4d8108 | 16262 | + * inode operations |
1308ab2a | 16263 | + */ |
dece6358 | 16264 | + |
4a4d8108 AM |
16265 | +#ifndef __AUFS_INODE_H__ |
16266 | +#define __AUFS_INODE_H__ | |
dece6358 | 16267 | + |
4a4d8108 | 16268 | +#ifdef __KERNEL__ |
1308ab2a | 16269 | + |
4a4d8108 | 16270 | +#include <linux/fsnotify.h> |
4a4d8108 | 16271 | +#include "rwsem.h" |
1308ab2a | 16272 | + |
4a4d8108 | 16273 | +struct vfsmount; |
1facf9fc | 16274 | + |
4a4d8108 AM |
16275 | +struct au_hnotify { |
16276 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16277 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
7f207e10 | 16278 | + /* never use fsnotify_add_vfsmount_mark() */ |
0c5527e5 | 16279 | + struct fsnotify_mark hn_mark; |
4a4d8108 | 16280 | +#endif |
7f207e10 | 16281 | + struct inode *hn_aufs_inode; /* no get/put */ |
4a4d8108 AM |
16282 | +#endif |
16283 | +} ____cacheline_aligned_in_smp; | |
1facf9fc | 16284 | + |
4a4d8108 AM |
16285 | +struct au_hinode { |
16286 | + struct inode *hi_inode; | |
16287 | + aufs_bindex_t hi_id; | |
16288 | +#ifdef CONFIG_AUFS_HNOTIFY | |
16289 | + struct au_hnotify *hi_notify; | |
16290 | +#endif | |
dece6358 | 16291 | + |
4a4d8108 AM |
16292 | + /* reference to the copied-up whiteout with get/put */ |
16293 | + struct dentry *hi_whdentry; | |
16294 | +}; | |
dece6358 | 16295 | + |
537831f9 AM |
16296 | +/* ig_flags */ |
16297 | +#define AuIG_HALF_REFRESHED 1 | |
16298 | +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name) | |
16299 | +#define au_ig_fset(flags, name) \ | |
16300 | + do { (flags) |= AuIG_##name; } while (0) | |
16301 | +#define au_ig_fclr(flags, name) \ | |
16302 | + do { (flags) &= ~AuIG_##name; } while (0) | |
16303 | + | |
16304 | +struct au_iigen { | |
16305 | + __u32 ig_generation, ig_flags; | |
16306 | +}; | |
16307 | + | |
4a4d8108 AM |
16308 | +struct au_vdir; |
16309 | +struct au_iinfo { | |
537831f9 | 16310 | + spinlock_t ii_genspin; |
7a9e40b8 | 16311 | + struct au_iigen ii_generation; |
4a4d8108 | 16312 | + struct super_block *ii_hsb1; /* no get/put */ |
1facf9fc | 16313 | + |
4a4d8108 AM |
16314 | + struct au_rwsem ii_rwsem; |
16315 | + aufs_bindex_t ii_bstart, ii_bend; | |
16316 | + __u32 ii_higen; | |
16317 | + struct au_hinode *ii_hinode; | |
16318 | + struct au_vdir *ii_vdir; | |
16319 | +}; | |
1facf9fc | 16320 | + |
4a4d8108 AM |
16321 | +struct au_icntnr { |
16322 | + struct au_iinfo iinfo; | |
16323 | + struct inode vfs_inode; | |
16324 | +} ____cacheline_aligned_in_smp; | |
1308ab2a | 16325 | + |
4a4d8108 AM |
16326 | +/* au_pin flags */ |
16327 | +#define AuPin_DI_LOCKED 1 | |
16328 | +#define AuPin_MNT_WRITE (1 << 1) | |
16329 | +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name) | |
7f207e10 AM |
16330 | +#define au_fset_pin(flags, name) \ |
16331 | + do { (flags) |= AuPin_##name; } while (0) | |
16332 | +#define au_fclr_pin(flags, name) \ | |
16333 | + do { (flags) &= ~AuPin_##name; } while (0) | |
4a4d8108 AM |
16334 | + |
16335 | +struct au_pin { | |
16336 | + /* input */ | |
16337 | + struct dentry *dentry; | |
16338 | + unsigned int udba; | |
16339 | + unsigned char lsc_di, lsc_hi, flags; | |
16340 | + aufs_bindex_t bindex; | |
16341 | + | |
16342 | + /* output */ | |
16343 | + struct dentry *parent; | |
16344 | + struct au_hinode *hdir; | |
16345 | + struct vfsmount *h_mnt; | |
86dc4139 AM |
16346 | + |
16347 | + /* temporary unlock/relock for copyup */ | |
16348 | + struct dentry *h_dentry, *h_parent; | |
16349 | + struct au_branch *br; | |
16350 | + struct task_struct *task; | |
4a4d8108 | 16351 | +}; |
1facf9fc | 16352 | + |
86dc4139 | 16353 | +void au_pin_hdir_unlock(struct au_pin *p); |
c1595e42 | 16354 | +int au_pin_hdir_lock(struct au_pin *p); |
86dc4139 AM |
16355 | +int au_pin_hdir_relock(struct au_pin *p); |
16356 | +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task); | |
16357 | +void au_pin_hdir_acquire_nest(struct au_pin *p); | |
16358 | +void au_pin_hdir_release(struct au_pin *p); | |
16359 | + | |
1308ab2a | 16360 | +/* ---------------------------------------------------------------------- */ |
16361 | + | |
4a4d8108 | 16362 | +static inline struct au_iinfo *au_ii(struct inode *inode) |
1facf9fc | 16363 | +{ |
4a4d8108 | 16364 | + struct au_iinfo *iinfo; |
1facf9fc | 16365 | + |
4a4d8108 AM |
16366 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); |
16367 | + if (iinfo->ii_hinode) | |
16368 | + return iinfo; | |
16369 | + return NULL; /* debugging bad_inode case */ | |
16370 | +} | |
1facf9fc | 16371 | + |
4a4d8108 | 16372 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16373 | + |
4a4d8108 AM |
16374 | +/* inode.c */ |
16375 | +struct inode *au_igrab(struct inode *inode); | |
027c5e7a | 16376 | +int au_refresh_hinode_self(struct inode *inode); |
4a4d8108 AM |
16377 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry); |
16378 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
16379 | + unsigned int d_type, ino_t *ino); | |
16380 | +struct inode *au_new_inode(struct dentry *dentry, int must_new); | |
16381 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, | |
16382 | + struct inode *inode); | |
16383 | +int au_test_h_perm(struct inode *h_inode, int mask); | |
16384 | +int au_test_h_perm_sio(struct inode *h_inode, int mask); | |
1facf9fc | 16385 | + |
4a4d8108 AM |
16386 | +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, |
16387 | + ino_t h_ino, unsigned int d_type, ino_t *ino) | |
16388 | +{ | |
16389 | +#ifdef CONFIG_AUFS_SHWH | |
16390 | + return au_ino(sb, bindex, h_ino, d_type, ino); | |
16391 | +#else | |
16392 | + return 0; | |
16393 | +#endif | |
16394 | +} | |
1facf9fc | 16395 | + |
4a4d8108 AM |
16396 | +/* i_op.c */ |
16397 | +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop; | |
1308ab2a | 16398 | + |
4a4d8108 AM |
16399 | +/* au_wr_dir flags */ |
16400 | +#define AuWrDir_ADD_ENTRY 1 | |
86dc4139 AM |
16401 | +#define AuWrDir_TMP_WHENTRY (1 << 1) |
16402 | +#define AuWrDir_ISDIR (1 << 2) | |
38d290e6 | 16403 | +#define AuWrDir_TMPFILE (1 << 3) |
4a4d8108 | 16404 | +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name) |
7f207e10 AM |
16405 | +#define au_fset_wrdir(flags, name) \ |
16406 | + do { (flags) |= AuWrDir_##name; } while (0) | |
16407 | +#define au_fclr_wrdir(flags, name) \ | |
16408 | + do { (flags) &= ~AuWrDir_##name; } while (0) | |
1facf9fc | 16409 | + |
4a4d8108 AM |
16410 | +struct au_wr_dir_args { |
16411 | + aufs_bindex_t force_btgt; | |
16412 | + unsigned char flags; | |
16413 | +}; | |
16414 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
16415 | + struct au_wr_dir_args *args); | |
dece6358 | 16416 | + |
4a4d8108 AM |
16417 | +struct dentry *au_pinned_h_parent(struct au_pin *pin); |
16418 | +void au_pin_init(struct au_pin *pin, struct dentry *dentry, | |
16419 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
16420 | + unsigned int udba, unsigned char flags); | |
16421 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
16422 | + unsigned int udba, unsigned char flags) __must_check; | |
16423 | +int au_do_pin(struct au_pin *pin) __must_check; | |
16424 | +void au_unpin(struct au_pin *pin); | |
c1595e42 JR |
16425 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen); |
16426 | + | |
16427 | +#define AuIcpup_DID_CPUP 1 | |
16428 | +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name) | |
16429 | +#define au_fset_icpup(flags, name) \ | |
16430 | + do { (flags) |= AuIcpup_##name; } while (0) | |
16431 | +#define au_fclr_icpup(flags, name) \ | |
16432 | + do { (flags) &= ~AuIcpup_##name; } while (0) | |
16433 | + | |
16434 | +struct au_icpup_args { | |
16435 | + unsigned char flags; | |
16436 | + unsigned char pin_flags; | |
16437 | + aufs_bindex_t btgt; | |
16438 | + unsigned int udba; | |
16439 | + struct au_pin pin; | |
16440 | + struct path h_path; | |
16441 | + struct inode *h_inode; | |
16442 | +}; | |
16443 | + | |
16444 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, | |
16445 | + struct au_icpup_args *a); | |
16446 | + | |
16447 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path); | |
1facf9fc | 16448 | + |
4a4d8108 AM |
16449 | +/* i_op_add.c */ |
16450 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
16451 | + struct dentry *h_parent, int isdir); | |
7eafdf33 AM |
16452 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
16453 | + dev_t dev); | |
4a4d8108 | 16454 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname); |
7eafdf33 | 16455 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 16456 | + bool want_excl); |
38d290e6 | 16457 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode); |
4a4d8108 AM |
16458 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, |
16459 | + struct dentry *dentry); | |
7eafdf33 | 16460 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
1facf9fc | 16461 | + |
4a4d8108 AM |
16462 | +/* i_op_del.c */ |
16463 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup); | |
16464 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
16465 | + struct dentry *h_parent, int isdir); | |
16466 | +int aufs_unlink(struct inode *dir, struct dentry *dentry); | |
16467 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry); | |
1308ab2a | 16468 | + |
4a4d8108 AM |
16469 | +/* i_op_ren.c */ |
16470 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt); | |
16471 | +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry, | |
16472 | + struct inode *dir, struct dentry *dentry); | |
1facf9fc | 16473 | + |
4a4d8108 AM |
16474 | +/* iinfo.c */ |
16475 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex); | |
16476 | +void au_hiput(struct au_hinode *hinode); | |
16477 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, | |
16478 | + struct dentry *h_wh); | |
16479 | +unsigned int au_hi_flags(struct inode *inode, int isdir); | |
1308ab2a | 16480 | + |
4a4d8108 AM |
16481 | +/* hinode flags */ |
16482 | +#define AuHi_XINO 1 | |
16483 | +#define AuHi_HNOTIFY (1 << 1) | |
16484 | +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name) | |
7f207e10 AM |
16485 | +#define au_fset_hi(flags, name) \ |
16486 | + do { (flags) |= AuHi_##name; } while (0) | |
16487 | +#define au_fclr_hi(flags, name) \ | |
16488 | + do { (flags) &= ~AuHi_##name; } while (0) | |
1facf9fc | 16489 | + |
4a4d8108 AM |
16490 | +#ifndef CONFIG_AUFS_HNOTIFY |
16491 | +#undef AuHi_HNOTIFY | |
16492 | +#define AuHi_HNOTIFY 0 | |
16493 | +#endif | |
1facf9fc | 16494 | + |
4a4d8108 AM |
16495 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
16496 | + struct inode *h_inode, unsigned int flags); | |
1facf9fc | 16497 | + |
537831f9 | 16498 | +void au_update_iigen(struct inode *inode, int half); |
4a4d8108 | 16499 | +void au_update_ibrange(struct inode *inode, int do_put_zero); |
1facf9fc | 16500 | + |
4a4d8108 AM |
16501 | +void au_icntnr_init_once(void *_c); |
16502 | +int au_iinfo_init(struct inode *inode); | |
16503 | +void au_iinfo_fin(struct inode *inode); | |
16504 | +int au_ii_realloc(struct au_iinfo *iinfo, int nbr); | |
1308ab2a | 16505 | + |
e49829fe | 16506 | +#ifdef CONFIG_PROC_FS |
4a4d8108 | 16507 | +/* plink.c */ |
e49829fe JR |
16508 | +int au_plink_maint(struct super_block *sb, int flags); |
16509 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo); | |
16510 | +int au_plink_maint_enter(struct super_block *sb); | |
4a4d8108 AM |
16511 | +#ifdef CONFIG_AUFS_DEBUG |
16512 | +void au_plink_list(struct super_block *sb); | |
16513 | +#else | |
16514 | +AuStubVoid(au_plink_list, struct super_block *sb) | |
16515 | +#endif | |
16516 | +int au_plink_test(struct inode *inode); | |
16517 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex); | |
16518 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
16519 | + struct dentry *h_dentry); | |
e49829fe JR |
16520 | +void au_plink_put(struct super_block *sb, int verbose); |
16521 | +void au_plink_clean(struct super_block *sb, int verbose); | |
4a4d8108 | 16522 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id); |
e49829fe JR |
16523 | +#else |
16524 | +AuStubInt0(au_plink_maint, struct super_block *sb, int flags); | |
16525 | +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo); | |
16526 | +AuStubInt0(au_plink_maint_enter, struct super_block *sb); | |
16527 | +AuStubVoid(au_plink_list, struct super_block *sb); | |
16528 | +AuStubInt0(au_plink_test, struct inode *inode); | |
16529 | +AuStub(struct dentry *, au_plink_lkup, return NULL, | |
16530 | + struct inode *inode, aufs_bindex_t bindex); | |
16531 | +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex, | |
16532 | + struct dentry *h_dentry); | |
16533 | +AuStubVoid(au_plink_put, struct super_block *sb, int verbose); | |
16534 | +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose); | |
16535 | +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id); | |
16536 | +#endif /* CONFIG_PROC_FS */ | |
1facf9fc | 16537 | + |
c1595e42 JR |
16538 | +#ifdef CONFIG_AUFS_XATTR |
16539 | +/* xattr.c */ | |
16540 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags); | |
16541 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size); | |
16542 | +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value, | |
16543 | + size_t size); | |
16544 | +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value, | |
16545 | + size_t size, int flags); | |
16546 | +int aufs_removexattr(struct dentry *dentry, const char *name); | |
16547 | + | |
16548 | +/* void au_xattr_init(struct super_block *sb); */ | |
16549 | +#else | |
16550 | +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src, | |
16551 | + int ignore_flags); | |
16552 | +/* AuStubVoid(au_xattr_init, struct super_block *sb); */ | |
16553 | +#endif | |
16554 | + | |
16555 | +#ifdef CONFIG_FS_POSIX_ACL | |
16556 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type); | |
16557 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
16558 | +#endif | |
16559 | + | |
16560 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) | |
16561 | +enum { | |
16562 | + AU_XATTR_SET, | |
16563 | + AU_XATTR_REMOVE, | |
16564 | + AU_ACL_SET | |
16565 | +}; | |
16566 | + | |
16567 | +struct au_srxattr { | |
16568 | + int type; | |
16569 | + union { | |
16570 | + struct { | |
16571 | + const char *name; | |
16572 | + const void *value; | |
16573 | + size_t size; | |
16574 | + int flags; | |
16575 | + } set; | |
16576 | + struct { | |
16577 | + const char *name; | |
16578 | + } remove; | |
16579 | + struct { | |
16580 | + struct posix_acl *acl; | |
16581 | + int type; | |
16582 | + } acl_set; | |
16583 | + } u; | |
16584 | +}; | |
16585 | +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg); | |
16586 | +#endif | |
16587 | + | |
4a4d8108 | 16588 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16589 | + |
4a4d8108 AM |
16590 | +/* lock subclass for iinfo */ |
16591 | +enum { | |
16592 | + AuLsc_II_CHILD, /* child first */ | |
16593 | + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */ | |
16594 | + AuLsc_II_CHILD3, /* copyup dirs */ | |
16595 | + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */ | |
16596 | + AuLsc_II_PARENT2, | |
16597 | + AuLsc_II_PARENT3, /* copyup dirs */ | |
16598 | + AuLsc_II_NEW_CHILD | |
16599 | +}; | |
1308ab2a | 16600 | + |
1facf9fc | 16601 | +/* |
4a4d8108 AM |
16602 | + * ii_read_lock_child, ii_write_lock_child, |
16603 | + * ii_read_lock_child2, ii_write_lock_child2, | |
16604 | + * ii_read_lock_child3, ii_write_lock_child3, | |
16605 | + * ii_read_lock_parent, ii_write_lock_parent, | |
16606 | + * ii_read_lock_parent2, ii_write_lock_parent2, | |
16607 | + * ii_read_lock_parent3, ii_write_lock_parent3, | |
16608 | + * ii_read_lock_new_child, ii_write_lock_new_child, | |
1facf9fc | 16609 | + */ |
4a4d8108 AM |
16610 | +#define AuReadLockFunc(name, lsc) \ |
16611 | +static inline void ii_read_lock_##name(struct inode *i) \ | |
16612 | +{ \ | |
16613 | + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
16614 | +} | |
16615 | + | |
16616 | +#define AuWriteLockFunc(name, lsc) \ | |
16617 | +static inline void ii_write_lock_##name(struct inode *i) \ | |
16618 | +{ \ | |
16619 | + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
16620 | +} | |
16621 | + | |
16622 | +#define AuRWLockFuncs(name, lsc) \ | |
16623 | + AuReadLockFunc(name, lsc) \ | |
16624 | + AuWriteLockFunc(name, lsc) | |
16625 | + | |
16626 | +AuRWLockFuncs(child, CHILD); | |
16627 | +AuRWLockFuncs(child2, CHILD2); | |
16628 | +AuRWLockFuncs(child3, CHILD3); | |
16629 | +AuRWLockFuncs(parent, PARENT); | |
16630 | +AuRWLockFuncs(parent2, PARENT2); | |
16631 | +AuRWLockFuncs(parent3, PARENT3); | |
16632 | +AuRWLockFuncs(new_child, NEW_CHILD); | |
16633 | + | |
16634 | +#undef AuReadLockFunc | |
16635 | +#undef AuWriteLockFunc | |
16636 | +#undef AuRWLockFuncs | |
1facf9fc | 16637 | + |
16638 | +/* | |
4a4d8108 | 16639 | + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock |
1facf9fc | 16640 | + */ |
4a4d8108 | 16641 | +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem); |
1facf9fc | 16642 | + |
4a4d8108 AM |
16643 | +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem) |
16644 | +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem) | |
16645 | +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 16646 | + |
4a4d8108 | 16647 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16648 | + |
027c5e7a AM |
16649 | +static inline void au_icntnr_init(struct au_icntnr *c) |
16650 | +{ | |
16651 | +#ifdef CONFIG_AUFS_DEBUG | |
16652 | + c->vfs_inode.i_mode = 0; | |
16653 | +#endif | |
16654 | +} | |
16655 | + | |
537831f9 | 16656 | +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen) |
4a4d8108 | 16657 | +{ |
537831f9 AM |
16658 | + unsigned int gen; |
16659 | + struct au_iinfo *iinfo; | |
16660 | + | |
16661 | + iinfo = au_ii(inode); | |
16662 | + spin_lock(&iinfo->ii_genspin); | |
16663 | + if (iigen) | |
16664 | + *iigen = iinfo->ii_generation; | |
16665 | + gen = iinfo->ii_generation.ig_generation; | |
16666 | + spin_unlock(&iinfo->ii_genspin); | |
16667 | + | |
16668 | + return gen; | |
4a4d8108 | 16669 | +} |
1308ab2a | 16670 | + |
4a4d8108 AM |
16671 | +/* tiny test for inode number */ |
16672 | +/* tmpfs generation is too rough */ | |
16673 | +static inline int au_test_higen(struct inode *inode, struct inode *h_inode) | |
16674 | +{ | |
16675 | + struct au_iinfo *iinfo; | |
1308ab2a | 16676 | + |
4a4d8108 AM |
16677 | + iinfo = au_ii(inode); |
16678 | + AuRwMustAnyLock(&iinfo->ii_rwsem); | |
16679 | + return !(iinfo->ii_hsb1 == h_inode->i_sb | |
16680 | + && iinfo->ii_higen == h_inode->i_generation); | |
16681 | +} | |
1308ab2a | 16682 | + |
4a4d8108 AM |
16683 | +static inline void au_iigen_dec(struct inode *inode) |
16684 | +{ | |
537831f9 AM |
16685 | + struct au_iinfo *iinfo; |
16686 | + | |
16687 | + iinfo = au_ii(inode); | |
16688 | + spin_lock(&iinfo->ii_genspin); | |
16689 | + iinfo->ii_generation.ig_generation--; | |
16690 | + spin_unlock(&iinfo->ii_genspin); | |
027c5e7a AM |
16691 | +} |
16692 | + | |
16693 | +static inline int au_iigen_test(struct inode *inode, unsigned int sigen) | |
16694 | +{ | |
16695 | + int err; | |
16696 | + | |
16697 | + err = 0; | |
537831f9 | 16698 | + if (unlikely(inode && au_iigen(inode, NULL) != sigen)) |
027c5e7a AM |
16699 | + err = -EIO; |
16700 | + | |
16701 | + return err; | |
4a4d8108 | 16702 | +} |
1308ab2a | 16703 | + |
4a4d8108 | 16704 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 16705 | + |
4a4d8108 AM |
16706 | +static inline aufs_bindex_t au_ii_br_id(struct inode *inode, |
16707 | + aufs_bindex_t bindex) | |
16708 | +{ | |
16709 | + IiMustAnyLock(inode); | |
16710 | + return au_ii(inode)->ii_hinode[0 + bindex].hi_id; | |
16711 | +} | |
1308ab2a | 16712 | + |
4a4d8108 AM |
16713 | +static inline aufs_bindex_t au_ibstart(struct inode *inode) |
16714 | +{ | |
16715 | + IiMustAnyLock(inode); | |
16716 | + return au_ii(inode)->ii_bstart; | |
16717 | +} | |
1308ab2a | 16718 | + |
4a4d8108 AM |
16719 | +static inline aufs_bindex_t au_ibend(struct inode *inode) |
16720 | +{ | |
16721 | + IiMustAnyLock(inode); | |
16722 | + return au_ii(inode)->ii_bend; | |
16723 | +} | |
1308ab2a | 16724 | + |
4a4d8108 AM |
16725 | +static inline struct au_vdir *au_ivdir(struct inode *inode) |
16726 | +{ | |
16727 | + IiMustAnyLock(inode); | |
16728 | + return au_ii(inode)->ii_vdir; | |
16729 | +} | |
1308ab2a | 16730 | + |
4a4d8108 AM |
16731 | +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex) |
16732 | +{ | |
16733 | + IiMustAnyLock(inode); | |
16734 | + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry; | |
16735 | +} | |
1308ab2a | 16736 | + |
4a4d8108 | 16737 | +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 16738 | +{ |
4a4d8108 AM |
16739 | + IiMustWriteLock(inode); |
16740 | + au_ii(inode)->ii_bstart = bindex; | |
16741 | +} | |
1308ab2a | 16742 | + |
4a4d8108 AM |
16743 | +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex) |
16744 | +{ | |
16745 | + IiMustWriteLock(inode); | |
16746 | + au_ii(inode)->ii_bend = bindex; | |
1308ab2a | 16747 | +} |
16748 | + | |
4a4d8108 AM |
16749 | +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir) |
16750 | +{ | |
16751 | + IiMustWriteLock(inode); | |
16752 | + au_ii(inode)->ii_vdir = vdir; | |
16753 | +} | |
1facf9fc | 16754 | + |
4a4d8108 | 16755 | +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 16756 | +{ |
4a4d8108 AM |
16757 | + IiMustAnyLock(inode); |
16758 | + return au_ii(inode)->ii_hinode + bindex; | |
16759 | +} | |
dece6358 | 16760 | + |
4a4d8108 | 16761 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16762 | + |
4a4d8108 AM |
16763 | +static inline struct dentry *au_pinned_parent(struct au_pin *pin) |
16764 | +{ | |
16765 | + if (pin) | |
16766 | + return pin->parent; | |
16767 | + return NULL; | |
1facf9fc | 16768 | +} |
16769 | + | |
4a4d8108 | 16770 | +static inline struct inode *au_pinned_h_dir(struct au_pin *pin) |
1facf9fc | 16771 | +{ |
4a4d8108 AM |
16772 | + if (pin && pin->hdir) |
16773 | + return pin->hdir->hi_inode; | |
16774 | + return NULL; | |
1308ab2a | 16775 | +} |
1facf9fc | 16776 | + |
4a4d8108 AM |
16777 | +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin) |
16778 | +{ | |
16779 | + if (pin) | |
16780 | + return pin->hdir; | |
16781 | + return NULL; | |
16782 | +} | |
1facf9fc | 16783 | + |
4a4d8108 | 16784 | +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry) |
1308ab2a | 16785 | +{ |
4a4d8108 AM |
16786 | + if (pin) |
16787 | + pin->dentry = dentry; | |
16788 | +} | |
1308ab2a | 16789 | + |
4a4d8108 AM |
16790 | +static inline void au_pin_set_parent_lflag(struct au_pin *pin, |
16791 | + unsigned char lflag) | |
16792 | +{ | |
16793 | + if (pin) { | |
7f207e10 | 16794 | + if (lflag) |
4a4d8108 | 16795 | + au_fset_pin(pin->flags, DI_LOCKED); |
7f207e10 | 16796 | + else |
4a4d8108 | 16797 | + au_fclr_pin(pin->flags, DI_LOCKED); |
1308ab2a | 16798 | + } |
4a4d8108 AM |
16799 | +} |
16800 | + | |
16801 | +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent) | |
16802 | +{ | |
16803 | + if (pin) { | |
16804 | + dput(pin->parent); | |
16805 | + pin->parent = dget(parent); | |
1facf9fc | 16806 | + } |
4a4d8108 | 16807 | +} |
1facf9fc | 16808 | + |
4a4d8108 AM |
16809 | +/* ---------------------------------------------------------------------- */ |
16810 | + | |
027c5e7a | 16811 | +struct au_branch; |
4a4d8108 AM |
16812 | +#ifdef CONFIG_AUFS_HNOTIFY |
16813 | +struct au_hnotify_op { | |
16814 | + void (*ctl)(struct au_hinode *hinode, int do_set); | |
027c5e7a | 16815 | + int (*alloc)(struct au_hinode *hinode); |
7eafdf33 AM |
16816 | + |
16817 | + /* | |
16818 | + * if it returns true, the the caller should free hinode->hi_notify, | |
16819 | + * otherwise ->free() frees it. | |
16820 | + */ | |
16821 | + int (*free)(struct au_hinode *hinode, | |
16822 | + struct au_hnotify *hn) __must_check; | |
4a4d8108 AM |
16823 | + |
16824 | + void (*fin)(void); | |
16825 | + int (*init)(void); | |
027c5e7a AM |
16826 | + |
16827 | + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm); | |
16828 | + void (*fin_br)(struct au_branch *br); | |
16829 | + int (*init_br)(struct au_branch *br, int perm); | |
4a4d8108 AM |
16830 | +}; |
16831 | + | |
16832 | +/* hnotify.c */ | |
027c5e7a | 16833 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode); |
4a4d8108 AM |
16834 | +void au_hn_free(struct au_hinode *hinode); |
16835 | +void au_hn_ctl(struct au_hinode *hinode, int do_set); | |
16836 | +void au_hn_reset(struct inode *inode, unsigned int flags); | |
16837 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
16838 | + struct qstr *h_child_qstr, struct inode *h_child_inode); | |
027c5e7a AM |
16839 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm); |
16840 | +int au_hnotify_init_br(struct au_branch *br, int perm); | |
16841 | +void au_hnotify_fin_br(struct au_branch *br); | |
4a4d8108 AM |
16842 | +int __init au_hnotify_init(void); |
16843 | +void au_hnotify_fin(void); | |
16844 | + | |
7f207e10 | 16845 | +/* hfsnotify.c */ |
4a4d8108 AM |
16846 | +extern const struct au_hnotify_op au_hnotify_op; |
16847 | + | |
16848 | +static inline | |
16849 | +void au_hn_init(struct au_hinode *hinode) | |
16850 | +{ | |
16851 | + hinode->hi_notify = NULL; | |
1308ab2a | 16852 | +} |
16853 | + | |
53392da6 AM |
16854 | +static inline struct au_hnotify *au_hn(struct au_hinode *hinode) |
16855 | +{ | |
16856 | + return hinode->hi_notify; | |
16857 | +} | |
16858 | + | |
4a4d8108 | 16859 | +#else |
c1595e42 JR |
16860 | +AuStub(int, au_hn_alloc, return -EOPNOTSUPP, |
16861 | + struct au_hinode *hinode __maybe_unused, | |
16862 | + struct inode *inode __maybe_unused) | |
16863 | +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode) | |
4a4d8108 AM |
16864 | +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused) |
16865 | +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused, | |
16866 | + int do_set __maybe_unused) | |
16867 | +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused, | |
16868 | + unsigned int flags __maybe_unused) | |
027c5e7a AM |
16869 | +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused, |
16870 | + struct au_branch *br __maybe_unused, | |
16871 | + int perm __maybe_unused) | |
16872 | +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused, | |
16873 | + int perm __maybe_unused) | |
16874 | +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused) | |
4a4d8108 AM |
16875 | +AuStubInt0(__init au_hnotify_init, void) |
16876 | +AuStubVoid(au_hnotify_fin, void) | |
16877 | +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused) | |
16878 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
16879 | + | |
16880 | +static inline void au_hn_suspend(struct au_hinode *hdir) | |
16881 | +{ | |
16882 | + au_hn_ctl(hdir, /*do_set*/0); | |
1308ab2a | 16883 | +} |
16884 | + | |
4a4d8108 | 16885 | +static inline void au_hn_resume(struct au_hinode *hdir) |
1308ab2a | 16886 | +{ |
4a4d8108 AM |
16887 | + au_hn_ctl(hdir, /*do_set*/1); |
16888 | +} | |
1308ab2a | 16889 | + |
4a4d8108 AM |
16890 | +static inline void au_hn_imtx_lock(struct au_hinode *hdir) |
16891 | +{ | |
16892 | + mutex_lock(&hdir->hi_inode->i_mutex); | |
16893 | + au_hn_suspend(hdir); | |
16894 | +} | |
dece6358 | 16895 | + |
4a4d8108 AM |
16896 | +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir, |
16897 | + unsigned int sc __maybe_unused) | |
16898 | +{ | |
16899 | + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc); | |
16900 | + au_hn_suspend(hdir); | |
1facf9fc | 16901 | +} |
1facf9fc | 16902 | + |
4a4d8108 AM |
16903 | +static inline void au_hn_imtx_unlock(struct au_hinode *hdir) |
16904 | +{ | |
16905 | + au_hn_resume(hdir); | |
16906 | + mutex_unlock(&hdir->hi_inode->i_mutex); | |
16907 | +} | |
16908 | + | |
16909 | +#endif /* __KERNEL__ */ | |
16910 | +#endif /* __AUFS_INODE_H__ */ | |
7f207e10 AM |
16911 | diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c |
16912 | --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
16913 | +++ linux/fs/aufs/ioctl.c 2015-01-25 13:00:38.631047076 +0100 |
16914 | @@ -0,0 +1,219 @@ | |
4a4d8108 | 16915 | +/* |
523b37e3 | 16916 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
16917 | + * |
16918 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16919 | + * it under the terms of the GNU General Public License as published by | |
16920 | + * the Free Software Foundation; either version 2 of the License, or | |
16921 | + * (at your option) any later version. | |
16922 | + * | |
16923 | + * This program is distributed in the hope that it will be useful, | |
16924 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16925 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16926 | + * GNU General Public License for more details. | |
16927 | + * | |
16928 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16929 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
16930 | + */ |
16931 | + | |
16932 | +/* | |
16933 | + * ioctl | |
16934 | + * plink-management and readdir in userspace. | |
16935 | + * assist the pathconf(3) wrapper library. | |
c2b27bf2 | 16936 | + * move-down |
076b876e | 16937 | + * File-based Hierarchical Storage Management. |
4a4d8108 AM |
16938 | + */ |
16939 | + | |
c2b27bf2 AM |
16940 | +#include <linux/compat.h> |
16941 | +#include <linux/file.h> | |
4a4d8108 AM |
16942 | +#include "aufs.h" |
16943 | + | |
1e00d052 | 16944 | +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg) |
4a4d8108 AM |
16945 | +{ |
16946 | + int err, fd; | |
16947 | + aufs_bindex_t wbi, bindex, bend; | |
16948 | + struct file *h_file; | |
16949 | + struct super_block *sb; | |
16950 | + struct dentry *root; | |
1e00d052 AM |
16951 | + struct au_branch *br; |
16952 | + struct aufs_wbr_fd wbrfd = { | |
16953 | + .oflags = au_dir_roflags, | |
16954 | + .brid = -1 | |
16955 | + }; | |
16956 | + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY | |
16957 | + | O_NOATIME | O_CLOEXEC; | |
4a4d8108 | 16958 | + |
1e00d052 AM |
16959 | + AuDebugOn(wbrfd.oflags & ~valid); |
16960 | + | |
16961 | + if (arg) { | |
16962 | + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd)); | |
16963 | + if (unlikely(err)) { | |
16964 | + err = -EFAULT; | |
16965 | + goto out; | |
16966 | + } | |
16967 | + | |
16968 | + err = -EINVAL; | |
16969 | + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid); | |
16970 | + wbrfd.oflags |= au_dir_roflags; | |
16971 | + AuDbg("0%o\n", wbrfd.oflags); | |
16972 | + if (unlikely(wbrfd.oflags & ~valid)) | |
16973 | + goto out; | |
16974 | + } | |
16975 | + | |
16976 | + fd = get_unused_fd(); | |
16977 | + err = fd; | |
16978 | + if (unlikely(fd < 0)) | |
4a4d8108 | 16979 | + goto out; |
4a4d8108 | 16980 | + |
1e00d052 | 16981 | + h_file = ERR_PTR(-EINVAL); |
4a4d8108 | 16982 | + wbi = 0; |
1e00d052 | 16983 | + br = NULL; |
4a4d8108 AM |
16984 | + sb = path->dentry->d_sb; |
16985 | + root = sb->s_root; | |
16986 | + aufs_read_lock(root, AuLock_IR); | |
1e00d052 AM |
16987 | + bend = au_sbend(sb); |
16988 | + if (wbrfd.brid >= 0) { | |
16989 | + wbi = au_br_index(sb, wbrfd.brid); | |
16990 | + if (unlikely(wbi < 0 || wbi > bend)) | |
16991 | + goto out_unlock; | |
16992 | + } | |
16993 | + | |
16994 | + h_file = ERR_PTR(-ENOENT); | |
16995 | + br = au_sbr(sb, wbi); | |
16996 | + if (!au_br_writable(br->br_perm)) { | |
16997 | + if (arg) | |
16998 | + goto out_unlock; | |
16999 | + | |
17000 | + bindex = wbi + 1; | |
17001 | + wbi = -1; | |
17002 | + for (; bindex <= bend; bindex++) { | |
17003 | + br = au_sbr(sb, bindex); | |
17004 | + if (au_br_writable(br->br_perm)) { | |
4a4d8108 | 17005 | + wbi = bindex; |
1e00d052 | 17006 | + br = au_sbr(sb, wbi); |
4a4d8108 AM |
17007 | + break; |
17008 | + } | |
17009 | + } | |
4a4d8108 AM |
17010 | + } |
17011 | + AuDbg("wbi %d\n", wbi); | |
1e00d052 | 17012 | + if (wbi >= 0) |
392086de AM |
17013 | + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL, |
17014 | + /*force_wr*/0); | |
1e00d052 AM |
17015 | + |
17016 | +out_unlock: | |
4a4d8108 AM |
17017 | + aufs_read_unlock(root, AuLock_IR); |
17018 | + err = PTR_ERR(h_file); | |
17019 | + if (IS_ERR(h_file)) | |
17020 | + goto out_fd; | |
17021 | + | |
1e00d052 | 17022 | + atomic_dec(&br->br_count); /* cf. au_h_open() */ |
4a4d8108 AM |
17023 | + fd_install(fd, h_file); |
17024 | + err = fd; | |
17025 | + goto out; /* success */ | |
17026 | + | |
4f0767ce | 17027 | +out_fd: |
4a4d8108 | 17028 | + put_unused_fd(fd); |
4f0767ce | 17029 | +out: |
1e00d052 | 17030 | + AuTraceErr(err); |
4a4d8108 AM |
17031 | + return err; |
17032 | +} | |
17033 | + | |
17034 | +/* ---------------------------------------------------------------------- */ | |
17035 | + | |
17036 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg) | |
17037 | +{ | |
17038 | + long err; | |
c1595e42 | 17039 | + struct dentry *dentry; |
4a4d8108 AM |
17040 | + |
17041 | + switch (cmd) { | |
4a4d8108 AM |
17042 | + case AUFS_CTL_RDU: |
17043 | + case AUFS_CTL_RDU_INO: | |
17044 | + err = au_rdu_ioctl(file, cmd, arg); | |
17045 | + break; | |
17046 | + | |
17047 | + case AUFS_CTL_WBR_FD: | |
1e00d052 | 17048 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17049 | + break; |
17050 | + | |
027c5e7a AM |
17051 | + case AUFS_CTL_IBUSY: |
17052 | + err = au_ibusy_ioctl(file, arg); | |
17053 | + break; | |
17054 | + | |
076b876e AM |
17055 | + case AUFS_CTL_BRINFO: |
17056 | + err = au_brinfo_ioctl(file, arg); | |
17057 | + break; | |
17058 | + | |
17059 | + case AUFS_CTL_FHSM_FD: | |
c1595e42 JR |
17060 | + dentry = file->f_dentry; |
17061 | + if (IS_ROOT(dentry)) | |
17062 | + err = au_fhsm_fd(dentry->d_sb, arg); | |
17063 | + else | |
17064 | + err = -ENOTTY; | |
076b876e AM |
17065 | + break; |
17066 | + | |
4a4d8108 AM |
17067 | + default: |
17068 | + /* do not call the lower */ | |
17069 | + AuDbg("0x%x\n", cmd); | |
17070 | + err = -ENOTTY; | |
17071 | + } | |
17072 | + | |
17073 | + AuTraceErr(err); | |
17074 | + return err; | |
17075 | +} | |
17076 | + | |
17077 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg) | |
17078 | +{ | |
17079 | + long err; | |
17080 | + | |
17081 | + switch (cmd) { | |
c2b27bf2 | 17082 | + case AUFS_CTL_MVDOWN: |
c2b27bf2 AM |
17083 | + err = au_mvdown(file->f_dentry, (void __user *)arg); |
17084 | + break; | |
17085 | + | |
4a4d8108 | 17086 | + case AUFS_CTL_WBR_FD: |
1e00d052 | 17087 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
17088 | + break; |
17089 | + | |
17090 | + default: | |
17091 | + /* do not call the lower */ | |
17092 | + AuDbg("0x%x\n", cmd); | |
17093 | + err = -ENOTTY; | |
17094 | + } | |
17095 | + | |
17096 | + AuTraceErr(err); | |
17097 | + return err; | |
17098 | +} | |
b752ccd1 AM |
17099 | + |
17100 | +#ifdef CONFIG_COMPAT | |
17101 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
17102 | + unsigned long arg) | |
17103 | +{ | |
17104 | + long err; | |
17105 | + | |
17106 | + switch (cmd) { | |
17107 | + case AUFS_CTL_RDU: | |
17108 | + case AUFS_CTL_RDU_INO: | |
17109 | + err = au_rdu_compat_ioctl(file, cmd, arg); | |
17110 | + break; | |
17111 | + | |
027c5e7a AM |
17112 | + case AUFS_CTL_IBUSY: |
17113 | + err = au_ibusy_compat_ioctl(file, arg); | |
17114 | + break; | |
17115 | + | |
076b876e AM |
17116 | + case AUFS_CTL_BRINFO: |
17117 | + err = au_brinfo_compat_ioctl(file, arg); | |
17118 | + break; | |
17119 | + | |
b752ccd1 AM |
17120 | + default: |
17121 | + err = aufs_ioctl_dir(file, cmd, arg); | |
17122 | + } | |
17123 | + | |
17124 | + AuTraceErr(err); | |
17125 | + return err; | |
17126 | +} | |
17127 | + | |
b752ccd1 AM |
17128 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
17129 | + unsigned long arg) | |
17130 | +{ | |
17131 | + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg)); | |
17132 | +} | |
17133 | +#endif | |
7f207e10 AM |
17134 | diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c |
17135 | --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
17136 | +++ linux/fs/aufs/i_op_add.c 2015-01-25 13:00:38.631047076 +0100 |
17137 | @@ -0,0 +1,891 @@ | |
4a4d8108 | 17138 | +/* |
523b37e3 | 17139 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
17140 | + * |
17141 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17142 | + * it under the terms of the GNU General Public License as published by | |
17143 | + * the Free Software Foundation; either version 2 of the License, or | |
17144 | + * (at your option) any later version. | |
17145 | + * | |
17146 | + * This program is distributed in the hope that it will be useful, | |
17147 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17148 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17149 | + * GNU General Public License for more details. | |
17150 | + * | |
17151 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17152 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
17153 | + */ |
17154 | + | |
17155 | +/* | |
17156 | + * inode operations (add entry) | |
17157 | + */ | |
17158 | + | |
17159 | +#include "aufs.h" | |
17160 | + | |
17161 | +/* | |
17162 | + * final procedure of adding a new entry, except link(2). | |
17163 | + * remove whiteout, instantiate, copyup the parent dir's times and size | |
17164 | + * and update version. | |
17165 | + * if it failed, re-create the removed whiteout. | |
17166 | + */ | |
17167 | +static int epilog(struct inode *dir, aufs_bindex_t bindex, | |
17168 | + struct dentry *wh_dentry, struct dentry *dentry) | |
17169 | +{ | |
17170 | + int err, rerr; | |
17171 | + aufs_bindex_t bwh; | |
17172 | + struct path h_path; | |
076b876e | 17173 | + struct super_block *sb; |
4a4d8108 AM |
17174 | + struct inode *inode, *h_dir; |
17175 | + struct dentry *wh; | |
17176 | + | |
17177 | + bwh = -1; | |
076b876e | 17178 | + sb = dir->i_sb; |
4a4d8108 AM |
17179 | + if (wh_dentry) { |
17180 | + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */ | |
17181 | + IMustLock(h_dir); | |
17182 | + AuDebugOn(au_h_iptr(dir, bindex) != h_dir); | |
17183 | + bwh = au_dbwh(dentry); | |
17184 | + h_path.dentry = wh_dentry; | |
076b876e | 17185 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
4a4d8108 AM |
17186 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, |
17187 | + dentry); | |
17188 | + if (unlikely(err)) | |
17189 | + goto out; | |
17190 | + } | |
17191 | + | |
17192 | + inode = au_new_inode(dentry, /*must_new*/1); | |
17193 | + if (!IS_ERR(inode)) { | |
17194 | + d_instantiate(dentry, inode); | |
17195 | + dir = dentry->d_parent->d_inode; /* dir inode is locked */ | |
17196 | + IMustLock(dir); | |
17197 | + if (au_ibstart(dir) == au_dbstart(dentry)) | |
17198 | + au_cpup_attr_timesizes(dir); | |
17199 | + dir->i_version++; | |
076b876e | 17200 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
4a4d8108 AM |
17201 | + return 0; /* success */ |
17202 | + } | |
17203 | + | |
17204 | + err = PTR_ERR(inode); | |
17205 | + if (!wh_dentry) | |
17206 | + goto out; | |
17207 | + | |
17208 | + /* revert */ | |
17209 | + /* dir inode is locked */ | |
17210 | + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent); | |
17211 | + rerr = PTR_ERR(wh); | |
17212 | + if (IS_ERR(wh)) { | |
523b37e3 AM |
17213 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", |
17214 | + dentry, err, rerr); | |
4a4d8108 AM |
17215 | + err = -EIO; |
17216 | + } else | |
17217 | + dput(wh); | |
17218 | + | |
4f0767ce | 17219 | +out: |
4a4d8108 AM |
17220 | + return err; |
17221 | +} | |
17222 | + | |
027c5e7a AM |
17223 | +static int au_d_may_add(struct dentry *dentry) |
17224 | +{ | |
17225 | + int err; | |
17226 | + | |
17227 | + err = 0; | |
17228 | + if (unlikely(d_unhashed(dentry))) | |
17229 | + err = -ENOENT; | |
17230 | + if (unlikely(dentry->d_inode)) | |
17231 | + err = -EEXIST; | |
17232 | + return err; | |
17233 | +} | |
17234 | + | |
4a4d8108 AM |
17235 | +/* |
17236 | + * simple tests for the adding inode operations. | |
17237 | + * following the checks in vfs, plus the parent-child relationship. | |
17238 | + */ | |
17239 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
17240 | + struct dentry *h_parent, int isdir) | |
17241 | +{ | |
17242 | + int err; | |
17243 | + umode_t h_mode; | |
17244 | + struct dentry *h_dentry; | |
17245 | + struct inode *h_inode; | |
17246 | + | |
17247 | + err = -ENAMETOOLONG; | |
17248 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17249 | + goto out; | |
17250 | + | |
17251 | + h_dentry = au_h_dptr(dentry, bindex); | |
17252 | + h_inode = h_dentry->d_inode; | |
17253 | + if (!dentry->d_inode) { | |
17254 | + err = -EEXIST; | |
17255 | + if (unlikely(h_inode)) | |
17256 | + goto out; | |
17257 | + } else { | |
17258 | + /* rename(2) case */ | |
17259 | + err = -EIO; | |
17260 | + if (unlikely(!h_inode || !h_inode->i_nlink)) | |
17261 | + goto out; | |
17262 | + | |
17263 | + h_mode = h_inode->i_mode; | |
17264 | + if (!isdir) { | |
17265 | + err = -EISDIR; | |
17266 | + if (unlikely(S_ISDIR(h_mode))) | |
17267 | + goto out; | |
17268 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
17269 | + err = -ENOTDIR; | |
17270 | + goto out; | |
17271 | + } | |
17272 | + } | |
17273 | + | |
17274 | + err = 0; | |
17275 | + /* expected parent dir is locked */ | |
17276 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
17277 | + err = -EIO; | |
17278 | + | |
4f0767ce | 17279 | +out: |
4a4d8108 AM |
17280 | + AuTraceErr(err); |
17281 | + return err; | |
17282 | +} | |
17283 | + | |
17284 | +/* | |
17285 | + * initial procedure of adding a new entry. | |
17286 | + * prepare writable branch and the parent dir, lock it, | |
17287 | + * and lookup whiteout for the new entry. | |
17288 | + */ | |
17289 | +static struct dentry* | |
17290 | +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt, | |
17291 | + struct dentry *src_dentry, struct au_pin *pin, | |
17292 | + struct au_wr_dir_args *wr_dir_args) | |
17293 | +{ | |
17294 | + struct dentry *wh_dentry, *h_parent; | |
17295 | + struct super_block *sb; | |
17296 | + struct au_branch *br; | |
17297 | + int err; | |
17298 | + unsigned int udba; | |
17299 | + aufs_bindex_t bcpup; | |
17300 | + | |
523b37e3 | 17301 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17302 | + |
17303 | + err = au_wr_dir(dentry, src_dentry, wr_dir_args); | |
17304 | + bcpup = err; | |
17305 | + wh_dentry = ERR_PTR(err); | |
17306 | + if (unlikely(err < 0)) | |
17307 | + goto out; | |
17308 | + | |
17309 | + sb = dentry->d_sb; | |
17310 | + udba = au_opt_udba(sb); | |
17311 | + err = au_pin(pin, dentry, bcpup, udba, | |
17312 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17313 | + wh_dentry = ERR_PTR(err); | |
17314 | + if (unlikely(err)) | |
17315 | + goto out; | |
17316 | + | |
17317 | + h_parent = au_pinned_h_parent(pin); | |
17318 | + if (udba != AuOpt_UDBA_NONE | |
17319 | + && au_dbstart(dentry) == bcpup) | |
17320 | + err = au_may_add(dentry, bcpup, h_parent, | |
17321 | + au_ftest_wrdir(wr_dir_args->flags, ISDIR)); | |
17322 | + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
17323 | + err = -ENAMETOOLONG; | |
17324 | + wh_dentry = ERR_PTR(err); | |
17325 | + if (unlikely(err)) | |
17326 | + goto out_unpin; | |
17327 | + | |
17328 | + br = au_sbr(sb, bcpup); | |
17329 | + if (dt) { | |
17330 | + struct path tmp = { | |
17331 | + .dentry = h_parent, | |
86dc4139 | 17332 | + .mnt = au_br_mnt(br) |
4a4d8108 AM |
17333 | + }; |
17334 | + au_dtime_store(dt, au_pinned_parent(pin), &tmp); | |
17335 | + } | |
17336 | + | |
17337 | + wh_dentry = NULL; | |
17338 | + if (bcpup != au_dbwh(dentry)) | |
17339 | + goto out; /* success */ | |
17340 | + | |
17341 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br); | |
17342 | + | |
4f0767ce | 17343 | +out_unpin: |
4a4d8108 AM |
17344 | + if (IS_ERR(wh_dentry)) |
17345 | + au_unpin(pin); | |
4f0767ce | 17346 | +out: |
4a4d8108 AM |
17347 | + return wh_dentry; |
17348 | +} | |
17349 | + | |
17350 | +/* ---------------------------------------------------------------------- */ | |
17351 | + | |
17352 | +enum { Mknod, Symlink, Creat }; | |
17353 | +struct simple_arg { | |
17354 | + int type; | |
17355 | + union { | |
17356 | + struct { | |
7eafdf33 | 17357 | + umode_t mode; |
b4510431 | 17358 | + bool want_excl; |
4a4d8108 AM |
17359 | + } c; |
17360 | + struct { | |
17361 | + const char *symname; | |
17362 | + } s; | |
17363 | + struct { | |
7eafdf33 | 17364 | + umode_t mode; |
4a4d8108 AM |
17365 | + dev_t dev; |
17366 | + } m; | |
17367 | + } u; | |
17368 | +}; | |
17369 | + | |
17370 | +static int add_simple(struct inode *dir, struct dentry *dentry, | |
17371 | + struct simple_arg *arg) | |
17372 | +{ | |
076b876e | 17373 | + int err, rerr; |
4a4d8108 AM |
17374 | + aufs_bindex_t bstart; |
17375 | + unsigned char created; | |
4a4d8108 AM |
17376 | + struct dentry *wh_dentry, *parent; |
17377 | + struct inode *h_dir; | |
c2b27bf2 AM |
17378 | + /* to reuduce stack size */ |
17379 | + struct { | |
17380 | + struct au_dtime dt; | |
17381 | + struct au_pin pin; | |
17382 | + struct path h_path; | |
17383 | + struct au_wr_dir_args wr_dir_args; | |
17384 | + } *a; | |
4a4d8108 | 17385 | + |
523b37e3 | 17386 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
17387 | + IMustLock(dir); |
17388 | + | |
c2b27bf2 AM |
17389 | + err = -ENOMEM; |
17390 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
17391 | + if (unlikely(!a)) | |
17392 | + goto out; | |
17393 | + a->wr_dir_args.force_btgt = -1; | |
17394 | + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY; | |
17395 | + | |
4a4d8108 | 17396 | + parent = dentry->d_parent; /* dir inode is locked */ |
027c5e7a AM |
17397 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
17398 | + if (unlikely(err)) | |
c2b27bf2 | 17399 | + goto out_free; |
027c5e7a AM |
17400 | + err = au_d_may_add(dentry); |
17401 | + if (unlikely(err)) | |
17402 | + goto out_unlock; | |
4a4d8108 | 17403 | + di_write_lock_parent(parent); |
c2b27bf2 AM |
17404 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, |
17405 | + &a->pin, &a->wr_dir_args); | |
4a4d8108 AM |
17406 | + err = PTR_ERR(wh_dentry); |
17407 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 17408 | + goto out_parent; |
4a4d8108 AM |
17409 | + |
17410 | + bstart = au_dbstart(dentry); | |
c2b27bf2 AM |
17411 | + a->h_path.dentry = au_h_dptr(dentry, bstart); |
17412 | + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart); | |
17413 | + h_dir = au_pinned_h_dir(&a->pin); | |
4a4d8108 AM |
17414 | + switch (arg->type) { |
17415 | + case Creat: | |
c2b27bf2 | 17416 | + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode, |
537831f9 | 17417 | + arg->u.c.want_excl); |
4a4d8108 AM |
17418 | + break; |
17419 | + case Symlink: | |
c2b27bf2 | 17420 | + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname); |
4a4d8108 AM |
17421 | + break; |
17422 | + case Mknod: | |
c2b27bf2 AM |
17423 | + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode, |
17424 | + arg->u.m.dev); | |
4a4d8108 AM |
17425 | + break; |
17426 | + default: | |
17427 | + BUG(); | |
17428 | + } | |
17429 | + created = !err; | |
17430 | + if (!err) | |
17431 | + err = epilog(dir, bstart, wh_dentry, dentry); | |
17432 | + | |
17433 | + /* revert */ | |
c2b27bf2 | 17434 | + if (unlikely(created && err && a->h_path.dentry->d_inode)) { |
523b37e3 AM |
17435 | + /* no delegation since it is just created */ |
17436 | + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL, | |
17437 | + /*force*/0); | |
4a4d8108 | 17438 | + if (rerr) { |
523b37e3 AM |
17439 | + AuIOErr("%pd revert failure(%d, %d)\n", |
17440 | + dentry, err, rerr); | |
4a4d8108 AM |
17441 | + err = -EIO; |
17442 | + } | |
c2b27bf2 | 17443 | + au_dtime_revert(&a->dt); |
4a4d8108 AM |
17444 | + } |
17445 | + | |
c2b27bf2 | 17446 | + au_unpin(&a->pin); |
4a4d8108 AM |
17447 | + dput(wh_dentry); |
17448 | + | |
027c5e7a AM |
17449 | +out_parent: |
17450 | + di_write_unlock(parent); | |
17451 | +out_unlock: | |
4a4d8108 AM |
17452 | + if (unlikely(err)) { |
17453 | + au_update_dbstart(dentry); | |
17454 | + d_drop(dentry); | |
17455 | + } | |
4a4d8108 | 17456 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 AM |
17457 | +out_free: |
17458 | + kfree(a); | |
027c5e7a | 17459 | +out: |
4a4d8108 AM |
17460 | + return err; |
17461 | +} | |
17462 | + | |
7eafdf33 AM |
17463 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
17464 | + dev_t dev) | |
4a4d8108 AM |
17465 | +{ |
17466 | + struct simple_arg arg = { | |
17467 | + .type = Mknod, | |
17468 | + .u.m = { | |
17469 | + .mode = mode, | |
17470 | + .dev = dev | |
17471 | + } | |
17472 | + }; | |
17473 | + return add_simple(dir, dentry, &arg); | |
17474 | +} | |
17475 | + | |
17476 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |
17477 | +{ | |
17478 | + struct simple_arg arg = { | |
17479 | + .type = Symlink, | |
17480 | + .u.s.symname = symname | |
17481 | + }; | |
17482 | + return add_simple(dir, dentry, &arg); | |
17483 | +} | |
17484 | + | |
7eafdf33 | 17485 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 17486 | + bool want_excl) |
4a4d8108 AM |
17487 | +{ |
17488 | + struct simple_arg arg = { | |
17489 | + .type = Creat, | |
17490 | + .u.c = { | |
b4510431 AM |
17491 | + .mode = mode, |
17492 | + .want_excl = want_excl | |
4a4d8108 AM |
17493 | + } |
17494 | + }; | |
17495 | + return add_simple(dir, dentry, &arg); | |
17496 | +} | |
17497 | + | |
38d290e6 JR |
17498 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
17499 | +{ | |
17500 | + int err; | |
17501 | + aufs_bindex_t bindex; | |
17502 | + struct super_block *sb; | |
17503 | + struct dentry *parent, *h_parent, *h_dentry; | |
17504 | + struct inode *h_dir, *inode; | |
17505 | + struct vfsmount *h_mnt; | |
17506 | + struct au_wr_dir_args wr_dir_args = { | |
17507 | + .force_btgt = -1, | |
17508 | + .flags = AuWrDir_TMPFILE | |
17509 | + }; | |
17510 | + | |
17511 | + /* copy-up may happen */ | |
17512 | + mutex_lock(&dir->i_mutex); | |
17513 | + | |
17514 | + sb = dir->i_sb; | |
17515 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
17516 | + if (unlikely(err)) | |
17517 | + goto out; | |
17518 | + | |
17519 | + err = au_di_init(dentry); | |
17520 | + if (unlikely(err)) | |
17521 | + goto out_si; | |
17522 | + | |
17523 | + err = -EBUSY; | |
17524 | + parent = d_find_any_alias(dir); | |
17525 | + AuDebugOn(!parent); | |
17526 | + di_write_lock_parent(parent); | |
17527 | + if (unlikely(parent->d_inode != dir)) | |
17528 | + goto out_parent; | |
17529 | + | |
17530 | + err = au_digen_test(parent, au_sigen(sb)); | |
17531 | + if (unlikely(err)) | |
17532 | + goto out_parent; | |
17533 | + | |
17534 | + bindex = au_dbstart(parent); | |
17535 | + au_set_dbstart(dentry, bindex); | |
17536 | + au_set_dbend(dentry, bindex); | |
17537 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); | |
17538 | + bindex = err; | |
17539 | + if (unlikely(err < 0)) | |
17540 | + goto out_parent; | |
17541 | + | |
17542 | + err = -EOPNOTSUPP; | |
17543 | + h_dir = au_h_iptr(dir, bindex); | |
17544 | + if (unlikely(!h_dir->i_op->tmpfile)) | |
17545 | + goto out_parent; | |
17546 | + | |
17547 | + h_mnt = au_sbr_mnt(sb, bindex); | |
17548 | + err = vfsub_mnt_want_write(h_mnt); | |
17549 | + if (unlikely(err)) | |
17550 | + goto out_parent; | |
17551 | + | |
17552 | + h_parent = au_h_dptr(parent, bindex); | |
17553 | + err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC); | |
17554 | + if (unlikely(err)) | |
17555 | + goto out_mnt; | |
17556 | + | |
17557 | + err = -ENOMEM; | |
17558 | + h_dentry = d_alloc(h_parent, &dentry->d_name); | |
17559 | + if (unlikely(!h_dentry)) | |
17560 | + goto out_mnt; | |
17561 | + | |
17562 | + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode); | |
17563 | + if (unlikely(err)) | |
17564 | + goto out_dentry; | |
17565 | + | |
17566 | + au_set_dbstart(dentry, bindex); | |
17567 | + au_set_dbend(dentry, bindex); | |
17568 | + au_set_h_dptr(dentry, bindex, dget(h_dentry)); | |
17569 | + inode = au_new_inode(dentry, /*must_new*/1); | |
17570 | + if (IS_ERR(inode)) { | |
17571 | + err = PTR_ERR(inode); | |
17572 | + au_set_h_dptr(dentry, bindex, NULL); | |
17573 | + au_set_dbstart(dentry, -1); | |
17574 | + au_set_dbend(dentry, -1); | |
17575 | + } else { | |
17576 | + if (!inode->i_nlink) | |
17577 | + set_nlink(inode, 1); | |
17578 | + d_tmpfile(dentry, inode); | |
17579 | + au_di(dentry)->di_tmpfile = 1; | |
17580 | + | |
17581 | + /* update without i_mutex */ | |
17582 | + if (au_ibstart(dir) == au_dbstart(dentry)) | |
17583 | + au_cpup_attr_timesizes(dir); | |
17584 | + } | |
17585 | + | |
17586 | +out_dentry: | |
17587 | + dput(h_dentry); | |
17588 | +out_mnt: | |
17589 | + vfsub_mnt_drop_write(h_mnt); | |
17590 | +out_parent: | |
17591 | + di_write_unlock(parent); | |
17592 | + dput(parent); | |
17593 | + di_write_unlock(dentry); | |
17594 | + if (!err) | |
17595 | +#if 0 | |
17596 | + /* verbose coding for lock class name */ | |
17597 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
17598 | + au_lc_key + AuLcNonDir_DIINFO); | |
17599 | +#else | |
17600 | + ; | |
17601 | +#endif | |
17602 | + else { | |
17603 | + au_di_fin(dentry); | |
17604 | + dentry->d_fsdata = NULL; | |
17605 | + } | |
17606 | +out_si: | |
17607 | + si_read_unlock(sb); | |
17608 | +out: | |
17609 | + mutex_unlock(&dir->i_mutex); | |
17610 | + return err; | |
17611 | +} | |
17612 | + | |
4a4d8108 AM |
17613 | +/* ---------------------------------------------------------------------- */ |
17614 | + | |
17615 | +struct au_link_args { | |
17616 | + aufs_bindex_t bdst, bsrc; | |
17617 | + struct au_pin pin; | |
17618 | + struct path h_path; | |
17619 | + struct dentry *src_parent, *parent; | |
17620 | +}; | |
17621 | + | |
17622 | +static int au_cpup_before_link(struct dentry *src_dentry, | |
17623 | + struct au_link_args *a) | |
17624 | +{ | |
17625 | + int err; | |
17626 | + struct dentry *h_src_dentry; | |
c2b27bf2 AM |
17627 | + struct au_cp_generic cpg = { |
17628 | + .dentry = src_dentry, | |
17629 | + .bdst = a->bdst, | |
17630 | + .bsrc = a->bsrc, | |
17631 | + .len = -1, | |
17632 | + .pin = &a->pin, | |
17633 | + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */ | |
17634 | + }; | |
4a4d8108 AM |
17635 | + |
17636 | + di_read_lock_parent(a->src_parent, AuLock_IR); | |
17637 | + err = au_test_and_cpup_dirs(src_dentry, a->bdst); | |
17638 | + if (unlikely(err)) | |
17639 | + goto out; | |
17640 | + | |
17641 | + h_src_dentry = au_h_dptr(src_dentry, a->bsrc); | |
4a4d8108 AM |
17642 | + err = au_pin(&a->pin, src_dentry, a->bdst, |
17643 | + au_opt_udba(src_dentry->d_sb), | |
17644 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17645 | + if (unlikely(err)) | |
17646 | + goto out; | |
367653fa | 17647 | + |
c2b27bf2 | 17648 | + err = au_sio_cpup_simple(&cpg); |
4a4d8108 AM |
17649 | + au_unpin(&a->pin); |
17650 | + | |
4f0767ce | 17651 | +out: |
4a4d8108 AM |
17652 | + di_read_unlock(a->src_parent, AuLock_IR); |
17653 | + return err; | |
17654 | +} | |
17655 | + | |
86dc4139 AM |
17656 | +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry, |
17657 | + struct au_link_args *a) | |
4a4d8108 AM |
17658 | +{ |
17659 | + int err; | |
17660 | + unsigned char plink; | |
86dc4139 | 17661 | + aufs_bindex_t bend; |
4a4d8108 | 17662 | + struct dentry *h_src_dentry; |
523b37e3 | 17663 | + struct inode *h_inode, *inode, *delegated; |
4a4d8108 AM |
17664 | + struct super_block *sb; |
17665 | + struct file *h_file; | |
17666 | + | |
17667 | + plink = 0; | |
17668 | + h_inode = NULL; | |
17669 | + sb = src_dentry->d_sb; | |
17670 | + inode = src_dentry->d_inode; | |
17671 | + if (au_ibstart(inode) <= a->bdst) | |
17672 | + h_inode = au_h_iptr(inode, a->bdst); | |
17673 | + if (!h_inode || !h_inode->i_nlink) { | |
17674 | + /* copyup src_dentry as the name of dentry. */ | |
86dc4139 AM |
17675 | + bend = au_dbend(dentry); |
17676 | + if (bend < a->bsrc) | |
17677 | + au_set_dbend(dentry, a->bsrc); | |
17678 | + au_set_h_dptr(dentry, a->bsrc, | |
17679 | + dget(au_h_dptr(src_dentry, a->bsrc))); | |
17680 | + dget(a->h_path.dentry); | |
17681 | + au_set_h_dptr(dentry, a->bdst, NULL); | |
c1595e42 JR |
17682 | + AuDbg("temporary d_inode...\n"); |
17683 | + spin_lock(&dentry->d_lock); | |
86dc4139 | 17684 | + dentry->d_inode = src_dentry->d_inode; /* tmp */ |
c1595e42 | 17685 | + spin_unlock(&dentry->d_lock); |
392086de | 17686 | + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0); |
86dc4139 | 17687 | + if (IS_ERR(h_file)) |
4a4d8108 | 17688 | + err = PTR_ERR(h_file); |
86dc4139 | 17689 | + else { |
c2b27bf2 AM |
17690 | + struct au_cp_generic cpg = { |
17691 | + .dentry = dentry, | |
17692 | + .bdst = a->bdst, | |
17693 | + .bsrc = -1, | |
17694 | + .len = -1, | |
17695 | + .pin = &a->pin, | |
17696 | + .flags = AuCpup_KEEPLINO | |
17697 | + }; | |
17698 | + err = au_sio_cpup_simple(&cpg); | |
86dc4139 AM |
17699 | + au_h_open_post(dentry, a->bsrc, h_file); |
17700 | + if (!err) { | |
17701 | + dput(a->h_path.dentry); | |
17702 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
17703 | + } else | |
17704 | + au_set_h_dptr(dentry, a->bdst, | |
17705 | + a->h_path.dentry); | |
17706 | + } | |
c1595e42 | 17707 | + spin_lock(&dentry->d_lock); |
86dc4139 | 17708 | + dentry->d_inode = NULL; /* restore */ |
c1595e42 JR |
17709 | + spin_unlock(&dentry->d_lock); |
17710 | + AuDbg("temporary d_inode...done\n"); | |
86dc4139 AM |
17711 | + au_set_h_dptr(dentry, a->bsrc, NULL); |
17712 | + au_set_dbend(dentry, bend); | |
4a4d8108 AM |
17713 | + } else { |
17714 | + /* the inode of src_dentry already exists on a.bdst branch */ | |
17715 | + h_src_dentry = d_find_alias(h_inode); | |
17716 | + if (!h_src_dentry && au_plink_test(inode)) { | |
17717 | + plink = 1; | |
17718 | + h_src_dentry = au_plink_lkup(inode, a->bdst); | |
17719 | + err = PTR_ERR(h_src_dentry); | |
17720 | + if (IS_ERR(h_src_dentry)) | |
17721 | + goto out; | |
17722 | + | |
17723 | + if (unlikely(!h_src_dentry->d_inode)) { | |
17724 | + dput(h_src_dentry); | |
17725 | + h_src_dentry = NULL; | |
17726 | + } | |
17727 | + | |
17728 | + } | |
17729 | + if (h_src_dentry) { | |
523b37e3 | 17730 | + delegated = NULL; |
4a4d8108 | 17731 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
17732 | + &a->h_path, &delegated); |
17733 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17734 | + pr_warn("cannot retry for NFSv4 delegation" | |
17735 | + " for an internal link\n"); | |
17736 | + iput(delegated); | |
17737 | + } | |
4a4d8108 AM |
17738 | + dput(h_src_dentry); |
17739 | + } else { | |
17740 | + AuIOErr("no dentry found for hi%lu on b%d\n", | |
17741 | + h_inode->i_ino, a->bdst); | |
17742 | + err = -EIO; | |
17743 | + } | |
17744 | + } | |
17745 | + | |
17746 | + if (!err && !plink) | |
17747 | + au_plink_append(inode, a->bdst, a->h_path.dentry); | |
17748 | + | |
17749 | +out: | |
2cbb1c4b | 17750 | + AuTraceErr(err); |
4a4d8108 AM |
17751 | + return err; |
17752 | +} | |
17753 | + | |
17754 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, | |
17755 | + struct dentry *dentry) | |
17756 | +{ | |
17757 | + int err, rerr; | |
17758 | + struct au_dtime dt; | |
17759 | + struct au_link_args *a; | |
17760 | + struct dentry *wh_dentry, *h_src_dentry; | |
523b37e3 | 17761 | + struct inode *inode, *delegated; |
4a4d8108 AM |
17762 | + struct super_block *sb; |
17763 | + struct au_wr_dir_args wr_dir_args = { | |
17764 | + /* .force_btgt = -1, */ | |
17765 | + .flags = AuWrDir_ADD_ENTRY | |
17766 | + }; | |
17767 | + | |
17768 | + IMustLock(dir); | |
17769 | + inode = src_dentry->d_inode; | |
17770 | + IMustLock(inode); | |
17771 | + | |
4a4d8108 AM |
17772 | + err = -ENOMEM; |
17773 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
17774 | + if (unlikely(!a)) | |
17775 | + goto out; | |
17776 | + | |
17777 | + a->parent = dentry->d_parent; /* dir inode is locked */ | |
027c5e7a AM |
17778 | + err = aufs_read_and_write_lock2(dentry, src_dentry, |
17779 | + AuLock_NOPLM | AuLock_GEN); | |
e49829fe JR |
17780 | + if (unlikely(err)) |
17781 | + goto out_kfree; | |
38d290e6 | 17782 | + err = au_d_linkable(src_dentry); |
027c5e7a AM |
17783 | + if (unlikely(err)) |
17784 | + goto out_unlock; | |
17785 | + err = au_d_may_add(dentry); | |
17786 | + if (unlikely(err)) | |
17787 | + goto out_unlock; | |
e49829fe | 17788 | + |
4a4d8108 | 17789 | + a->src_parent = dget_parent(src_dentry); |
2cbb1c4b | 17790 | + wr_dir_args.force_btgt = au_ibstart(inode); |
4a4d8108 AM |
17791 | + |
17792 | + di_write_lock_parent(a->parent); | |
17793 | + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt); | |
17794 | + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin, | |
17795 | + &wr_dir_args); | |
17796 | + err = PTR_ERR(wh_dentry); | |
17797 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 17798 | + goto out_parent; |
4a4d8108 AM |
17799 | + |
17800 | + err = 0; | |
17801 | + sb = dentry->d_sb; | |
17802 | + a->bdst = au_dbstart(dentry); | |
17803 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
17804 | + a->h_path.mnt = au_sbr_mnt(sb, a->bdst); | |
2cbb1c4b JR |
17805 | + a->bsrc = au_ibstart(inode); |
17806 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); | |
38d290e6 JR |
17807 | + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile) |
17808 | + h_src_dentry = dget(au_hi_wh(inode, a->bsrc)); | |
2cbb1c4b JR |
17809 | + if (!h_src_dentry) { |
17810 | + a->bsrc = au_dbstart(src_dentry); | |
17811 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); | |
17812 | + AuDebugOn(!h_src_dentry); | |
38d290e6 JR |
17813 | + } else if (IS_ERR(h_src_dentry)) { |
17814 | + err = PTR_ERR(h_src_dentry); | |
2cbb1c4b | 17815 | + goto out_parent; |
38d290e6 | 17816 | + } |
2cbb1c4b | 17817 | + |
4a4d8108 AM |
17818 | + if (au_opt_test(au_mntflags(sb), PLINK)) { |
17819 | + if (a->bdst < a->bsrc | |
17820 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) | |
86dc4139 | 17821 | + err = au_cpup_or_link(src_dentry, dentry, a); |
523b37e3 AM |
17822 | + else { |
17823 | + delegated = NULL; | |
4a4d8108 | 17824 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
17825 | + &a->h_path, &delegated); |
17826 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17827 | + pr_warn("cannot retry for NFSv4 delegation" | |
17828 | + " for an internal link\n"); | |
17829 | + iput(delegated); | |
17830 | + } | |
17831 | + } | |
2cbb1c4b | 17832 | + dput(h_src_dentry); |
4a4d8108 AM |
17833 | + } else { |
17834 | + /* | |
17835 | + * copyup src_dentry to the branch we process, | |
17836 | + * and then link(2) to it. | |
17837 | + */ | |
2cbb1c4b | 17838 | + dput(h_src_dentry); |
4a4d8108 AM |
17839 | + if (a->bdst < a->bsrc |
17840 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) { | |
17841 | + au_unpin(&a->pin); | |
17842 | + di_write_unlock(a->parent); | |
17843 | + err = au_cpup_before_link(src_dentry, a); | |
17844 | + di_write_lock_parent(a->parent); | |
17845 | + if (!err) | |
17846 | + err = au_pin(&a->pin, dentry, a->bdst, | |
17847 | + au_opt_udba(sb), | |
17848 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
17849 | + if (unlikely(err)) | |
17850 | + goto out_wh; | |
17851 | + } | |
17852 | + if (!err) { | |
17853 | + h_src_dentry = au_h_dptr(src_dentry, a->bdst); | |
17854 | + err = -ENOENT; | |
523b37e3 AM |
17855 | + if (h_src_dentry && h_src_dentry->d_inode) { |
17856 | + delegated = NULL; | |
4a4d8108 AM |
17857 | + err = vfsub_link(h_src_dentry, |
17858 | + au_pinned_h_dir(&a->pin), | |
523b37e3 AM |
17859 | + &a->h_path, &delegated); |
17860 | + if (unlikely(err == -EWOULDBLOCK)) { | |
17861 | + pr_warn("cannot retry" | |
17862 | + " for NFSv4 delegation" | |
17863 | + " for an internal link\n"); | |
17864 | + iput(delegated); | |
17865 | + } | |
17866 | + } | |
4a4d8108 AM |
17867 | + } |
17868 | + } | |
17869 | + if (unlikely(err)) | |
17870 | + goto out_unpin; | |
17871 | + | |
17872 | + if (wh_dentry) { | |
17873 | + a->h_path.dentry = wh_dentry; | |
17874 | + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path, | |
17875 | + dentry); | |
17876 | + if (unlikely(err)) | |
17877 | + goto out_revert; | |
17878 | + } | |
17879 | + | |
17880 | + dir->i_version++; | |
17881 | + if (au_ibstart(dir) == au_dbstart(dentry)) | |
17882 | + au_cpup_attr_timesizes(dir); | |
17883 | + inc_nlink(inode); | |
17884 | + inode->i_ctime = dir->i_ctime; | |
027c5e7a AM |
17885 | + d_instantiate(dentry, au_igrab(inode)); |
17886 | + if (d_unhashed(a->h_path.dentry)) | |
4a4d8108 AM |
17887 | + /* some filesystem calls d_drop() */ |
17888 | + d_drop(dentry); | |
076b876e AM |
17889 | + /* some filesystems consume an inode even hardlink */ |
17890 | + au_fhsm_wrote(sb, a->bdst, /*force*/0); | |
4a4d8108 AM |
17891 | + goto out_unpin; /* success */ |
17892 | + | |
4f0767ce | 17893 | +out_revert: |
523b37e3 AM |
17894 | + /* no delegation since it is just created */ |
17895 | + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, | |
17896 | + /*delegated*/NULL, /*force*/0); | |
027c5e7a | 17897 | + if (unlikely(rerr)) { |
523b37e3 | 17898 | + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr); |
027c5e7a AM |
17899 | + err = -EIO; |
17900 | + } | |
4a4d8108 | 17901 | + au_dtime_revert(&dt); |
4f0767ce | 17902 | +out_unpin: |
4a4d8108 | 17903 | + au_unpin(&a->pin); |
4f0767ce | 17904 | +out_wh: |
4a4d8108 | 17905 | + dput(wh_dentry); |
027c5e7a AM |
17906 | +out_parent: |
17907 | + di_write_unlock(a->parent); | |
17908 | + dput(a->src_parent); | |
4f0767ce | 17909 | +out_unlock: |
4a4d8108 AM |
17910 | + if (unlikely(err)) { |
17911 | + au_update_dbstart(dentry); | |
17912 | + d_drop(dentry); | |
17913 | + } | |
4a4d8108 | 17914 | + aufs_read_and_write_unlock2(dentry, src_dentry); |
e49829fe | 17915 | +out_kfree: |
4a4d8108 | 17916 | + kfree(a); |
4f0767ce | 17917 | +out: |
86dc4139 | 17918 | + AuTraceErr(err); |
4a4d8108 AM |
17919 | + return err; |
17920 | +} | |
17921 | + | |
7eafdf33 | 17922 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
4a4d8108 AM |
17923 | +{ |
17924 | + int err, rerr; | |
17925 | + aufs_bindex_t bindex; | |
17926 | + unsigned char diropq; | |
17927 | + struct path h_path; | |
17928 | + struct dentry *wh_dentry, *parent, *opq_dentry; | |
17929 | + struct mutex *h_mtx; | |
17930 | + struct super_block *sb; | |
17931 | + struct { | |
17932 | + struct au_pin pin; | |
17933 | + struct au_dtime dt; | |
17934 | + } *a; /* reduce the stack usage */ | |
17935 | + struct au_wr_dir_args wr_dir_args = { | |
17936 | + .force_btgt = -1, | |
17937 | + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR | |
17938 | + }; | |
17939 | + | |
17940 | + IMustLock(dir); | |
17941 | + | |
17942 | + err = -ENOMEM; | |
17943 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
17944 | + if (unlikely(!a)) | |
17945 | + goto out; | |
17946 | + | |
027c5e7a AM |
17947 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
17948 | + if (unlikely(err)) | |
17949 | + goto out_free; | |
17950 | + err = au_d_may_add(dentry); | |
17951 | + if (unlikely(err)) | |
17952 | + goto out_unlock; | |
17953 | + | |
4a4d8108 AM |
17954 | + parent = dentry->d_parent; /* dir inode is locked */ |
17955 | + di_write_lock_parent(parent); | |
17956 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, | |
17957 | + &a->pin, &wr_dir_args); | |
17958 | + err = PTR_ERR(wh_dentry); | |
17959 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 17960 | + goto out_parent; |
4a4d8108 AM |
17961 | + |
17962 | + sb = dentry->d_sb; | |
17963 | + bindex = au_dbstart(dentry); | |
17964 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
17965 | + h_path.mnt = au_sbr_mnt(sb, bindex); | |
17966 | + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode); | |
17967 | + if (unlikely(err)) | |
027c5e7a | 17968 | + goto out_unpin; |
4a4d8108 AM |
17969 | + |
17970 | + /* make the dir opaque */ | |
17971 | + diropq = 0; | |
17972 | + h_mtx = &h_path.dentry->d_inode->i_mutex; | |
17973 | + if (wh_dentry | |
17974 | + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) { | |
17975 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
17976 | + opq_dentry = au_diropq_create(dentry, bindex); | |
17977 | + mutex_unlock(h_mtx); | |
17978 | + err = PTR_ERR(opq_dentry); | |
17979 | + if (IS_ERR(opq_dentry)) | |
17980 | + goto out_dir; | |
17981 | + dput(opq_dentry); | |
17982 | + diropq = 1; | |
17983 | + } | |
17984 | + | |
17985 | + err = epilog(dir, bindex, wh_dentry, dentry); | |
17986 | + if (!err) { | |
17987 | + inc_nlink(dir); | |
027c5e7a | 17988 | + goto out_unpin; /* success */ |
4a4d8108 AM |
17989 | + } |
17990 | + | |
17991 | + /* revert */ | |
17992 | + if (diropq) { | |
17993 | + AuLabel(revert opq); | |
17994 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
17995 | + rerr = au_diropq_remove(dentry, bindex); | |
17996 | + mutex_unlock(h_mtx); | |
17997 | + if (rerr) { | |
523b37e3 AM |
17998 | + AuIOErr("%pd reverting diropq failed(%d, %d)\n", |
17999 | + dentry, err, rerr); | |
4a4d8108 AM |
18000 | + err = -EIO; |
18001 | + } | |
18002 | + } | |
18003 | + | |
4f0767ce | 18004 | +out_dir: |
4a4d8108 AM |
18005 | + AuLabel(revert dir); |
18006 | + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path); | |
18007 | + if (rerr) { | |
523b37e3 AM |
18008 | + AuIOErr("%pd reverting dir failed(%d, %d)\n", |
18009 | + dentry, err, rerr); | |
4a4d8108 AM |
18010 | + err = -EIO; |
18011 | + } | |
4a4d8108 | 18012 | + au_dtime_revert(&a->dt); |
027c5e7a | 18013 | +out_unpin: |
4a4d8108 AM |
18014 | + au_unpin(&a->pin); |
18015 | + dput(wh_dentry); | |
027c5e7a AM |
18016 | +out_parent: |
18017 | + di_write_unlock(parent); | |
18018 | +out_unlock: | |
4a4d8108 AM |
18019 | + if (unlikely(err)) { |
18020 | + au_update_dbstart(dentry); | |
18021 | + d_drop(dentry); | |
18022 | + } | |
4a4d8108 | 18023 | + aufs_read_unlock(dentry, AuLock_DW); |
027c5e7a | 18024 | +out_free: |
4a4d8108 | 18025 | + kfree(a); |
4f0767ce | 18026 | +out: |
4a4d8108 AM |
18027 | + return err; |
18028 | +} | |
7f207e10 AM |
18029 | diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c |
18030 | --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
18031 | +++ linux/fs/aufs/i_op.c 2015-01-25 13:00:38.631047076 +0100 |
18032 | @@ -0,0 +1,1306 @@ | |
4a4d8108 | 18033 | +/* |
523b37e3 | 18034 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
4a4d8108 AM |
18035 | + * |
18036 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18037 | + * it under the terms of the GNU General Public License as published by | |
18038 | + * the Free Software Foundation; either version 2 of the License, or | |
18039 | + * (at your option) any later version. | |
18040 | + * | |
18041 | + * This program is distributed in the hope that it will be useful, | |
18042 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18043 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18044 | + * GNU General Public License for more details. | |
18045 | + * | |
18046 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18047 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18048 | + */ |
1facf9fc | 18049 | + |
1308ab2a | 18050 | +/* |
4a4d8108 | 18051 | + * inode operations (except add/del/rename) |
1308ab2a | 18052 | + */ |
4a4d8108 AM |
18053 | + |
18054 | +#include <linux/device_cgroup.h> | |
18055 | +#include <linux/fs_stack.h> | |
92d182d2 | 18056 | +#include <linux/mm.h> |
4a4d8108 AM |
18057 | +#include <linux/namei.h> |
18058 | +#include <linux/security.h> | |
4a4d8108 AM |
18059 | +#include "aufs.h" |
18060 | + | |
1e00d052 | 18061 | +static int h_permission(struct inode *h_inode, int mask, |
4a4d8108 | 18062 | + struct vfsmount *h_mnt, int brperm) |
1facf9fc | 18063 | +{ |
1308ab2a | 18064 | + int err; |
4a4d8108 | 18065 | + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); |
1facf9fc | 18066 | + |
4a4d8108 AM |
18067 | + err = -EACCES; |
18068 | + if ((write_mask && IS_IMMUTABLE(h_inode)) | |
18069 | + || ((mask & MAY_EXEC) | |
18070 | + && S_ISREG(h_inode->i_mode) | |
18071 | + && ((h_mnt->mnt_flags & MNT_NOEXEC) | |
18072 | + || !(h_inode->i_mode & S_IXUGO)))) | |
18073 | + goto out; | |
18074 | + | |
18075 | + /* | |
18076 | + * - skip the lower fs test in the case of write to ro branch. | |
18077 | + * - nfs dir permission write check is optimized, but a policy for | |
18078 | + * link/rename requires a real check. | |
18079 | + */ | |
18080 | + if ((write_mask && !au_br_writable(brperm)) | |
18081 | + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode) | |
18082 | + && write_mask && !(mask & MAY_READ)) | |
18083 | + || !h_inode->i_op->permission) { | |
18084 | + /* AuLabel(generic_permission); */ | |
1e00d052 | 18085 | + err = generic_permission(h_inode, mask); |
1308ab2a | 18086 | + } else { |
4a4d8108 | 18087 | + /* AuLabel(h_inode->permission); */ |
1e00d052 | 18088 | + err = h_inode->i_op->permission(h_inode, mask); |
4a4d8108 AM |
18089 | + AuTraceErr(err); |
18090 | + } | |
1facf9fc | 18091 | + |
4a4d8108 AM |
18092 | + if (!err) |
18093 | + err = devcgroup_inode_permission(h_inode, mask); | |
7f207e10 | 18094 | + if (!err) |
4a4d8108 | 18095 | + err = security_inode_permission(h_inode, mask); |
4a4d8108 AM |
18096 | + |
18097 | +#if 0 | |
18098 | + if (!err) { | |
18099 | + /* todo: do we need to call ima_path_check()? */ | |
18100 | + struct path h_path = { | |
18101 | + .dentry = | |
18102 | + .mnt = h_mnt | |
18103 | + }; | |
18104 | + err = ima_path_check(&h_path, | |
18105 | + mask & (MAY_READ | MAY_WRITE | MAY_EXEC), | |
18106 | + IMA_COUNT_LEAVE); | |
1308ab2a | 18107 | + } |
4a4d8108 | 18108 | +#endif |
dece6358 | 18109 | + |
4f0767ce | 18110 | +out: |
1308ab2a | 18111 | + return err; |
18112 | +} | |
dece6358 | 18113 | + |
1e00d052 | 18114 | +static int aufs_permission(struct inode *inode, int mask) |
1308ab2a | 18115 | +{ |
18116 | + int err; | |
4a4d8108 AM |
18117 | + aufs_bindex_t bindex, bend; |
18118 | + const unsigned char isdir = !!S_ISDIR(inode->i_mode), | |
18119 | + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); | |
18120 | + struct inode *h_inode; | |
18121 | + struct super_block *sb; | |
18122 | + struct au_branch *br; | |
1facf9fc | 18123 | + |
027c5e7a | 18124 | + /* todo: support rcu-walk? */ |
1e00d052 | 18125 | + if (mask & MAY_NOT_BLOCK) |
027c5e7a AM |
18126 | + return -ECHILD; |
18127 | + | |
4a4d8108 AM |
18128 | + sb = inode->i_sb; |
18129 | + si_read_lock(sb, AuLock_FLUSH); | |
18130 | + ii_read_lock_child(inode); | |
027c5e7a AM |
18131 | +#if 0 |
18132 | + err = au_iigen_test(inode, au_sigen(sb)); | |
18133 | + if (unlikely(err)) | |
18134 | + goto out; | |
18135 | +#endif | |
dece6358 | 18136 | + |
076b876e AM |
18137 | + if (!isdir |
18138 | + || write_mask | |
18139 | + || au_opt_test(au_mntflags(sb), DIRPERM1)) { | |
4a4d8108 AM |
18140 | + err = au_busy_or_stale(); |
18141 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
18142 | + if (unlikely(!h_inode | |
18143 | + || (h_inode->i_mode & S_IFMT) | |
18144 | + != (inode->i_mode & S_IFMT))) | |
18145 | + goto out; | |
1facf9fc | 18146 | + |
4a4d8108 AM |
18147 | + err = 0; |
18148 | + bindex = au_ibstart(inode); | |
18149 | + br = au_sbr(sb, bindex); | |
86dc4139 | 18150 | + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm); |
4a4d8108 AM |
18151 | + if (write_mask |
18152 | + && !err | |
18153 | + && !special_file(h_inode->i_mode)) { | |
18154 | + /* test whether the upper writable branch exists */ | |
18155 | + err = -EROFS; | |
18156 | + for (; bindex >= 0; bindex--) | |
18157 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
18158 | + err = 0; | |
18159 | + break; | |
18160 | + } | |
18161 | + } | |
18162 | + goto out; | |
18163 | + } | |
dece6358 | 18164 | + |
4a4d8108 | 18165 | + /* non-write to dir */ |
1308ab2a | 18166 | + err = 0; |
4a4d8108 AM |
18167 | + bend = au_ibend(inode); |
18168 | + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) { | |
18169 | + h_inode = au_h_iptr(inode, bindex); | |
18170 | + if (h_inode) { | |
18171 | + err = au_busy_or_stale(); | |
18172 | + if (unlikely(!S_ISDIR(h_inode->i_mode))) | |
18173 | + break; | |
18174 | + | |
18175 | + br = au_sbr(sb, bindex); | |
86dc4139 | 18176 | + err = h_permission(h_inode, mask, au_br_mnt(br), |
4a4d8108 AM |
18177 | + br->br_perm); |
18178 | + } | |
18179 | + } | |
1308ab2a | 18180 | + |
4f0767ce | 18181 | +out: |
4a4d8108 AM |
18182 | + ii_read_unlock(inode); |
18183 | + si_read_unlock(sb); | |
1308ab2a | 18184 | + return err; |
18185 | +} | |
18186 | + | |
4a4d8108 | 18187 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18188 | + |
4a4d8108 | 18189 | +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry, |
b4510431 | 18190 | + unsigned int flags) |
4a4d8108 AM |
18191 | +{ |
18192 | + struct dentry *ret, *parent; | |
b752ccd1 | 18193 | + struct inode *inode; |
4a4d8108 | 18194 | + struct super_block *sb; |
1716fcea | 18195 | + int err, npositive; |
dece6358 | 18196 | + |
4a4d8108 | 18197 | + IMustLock(dir); |
1308ab2a | 18198 | + |
537831f9 AM |
18199 | + /* todo: support rcu-walk? */ |
18200 | + ret = ERR_PTR(-ECHILD); | |
18201 | + if (flags & LOOKUP_RCU) | |
18202 | + goto out; | |
18203 | + | |
18204 | + ret = ERR_PTR(-ENAMETOOLONG); | |
18205 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
18206 | + goto out; | |
18207 | + | |
4a4d8108 | 18208 | + sb = dir->i_sb; |
7f207e10 AM |
18209 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
18210 | + ret = ERR_PTR(err); | |
18211 | + if (unlikely(err)) | |
18212 | + goto out; | |
18213 | + | |
4a4d8108 AM |
18214 | + err = au_di_init(dentry); |
18215 | + ret = ERR_PTR(err); | |
18216 | + if (unlikely(err)) | |
7f207e10 | 18217 | + goto out_si; |
1308ab2a | 18218 | + |
9dbd164d | 18219 | + inode = NULL; |
027c5e7a | 18220 | + npositive = 0; /* suppress a warning */ |
4a4d8108 AM |
18221 | + parent = dentry->d_parent; /* dir inode is locked */ |
18222 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a AM |
18223 | + err = au_alive_dir(parent); |
18224 | + if (!err) | |
18225 | + err = au_digen_test(parent, au_sigen(sb)); | |
18226 | + if (!err) { | |
18227 | + npositive = au_lkup_dentry(dentry, au_dbstart(parent), | |
537831f9 | 18228 | + /*type*/0); |
027c5e7a AM |
18229 | + err = npositive; |
18230 | + } | |
4a4d8108 | 18231 | + di_read_unlock(parent, AuLock_IR); |
4a4d8108 AM |
18232 | + ret = ERR_PTR(err); |
18233 | + if (unlikely(err < 0)) | |
18234 | + goto out_unlock; | |
1308ab2a | 18235 | + |
4a4d8108 | 18236 | + if (npositive) { |
b752ccd1 | 18237 | + inode = au_new_inode(dentry, /*must_new*/0); |
c1595e42 JR |
18238 | + if (IS_ERR(inode)) { |
18239 | + ret = (void *)inode; | |
18240 | + inode = NULL; | |
18241 | + goto out_unlock; | |
18242 | + } | |
9dbd164d | 18243 | + } |
4a4d8108 | 18244 | + |
c1595e42 JR |
18245 | + if (inode) |
18246 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 18247 | + ret = d_splice_alias(inode, dentry); |
c1595e42 JR |
18248 | + if (IS_ERR(ret) |
18249 | + && PTR_ERR(ret) == -EIO | |
18250 | + && inode | |
18251 | + && S_ISDIR(inode->i_mode)) { | |
18252 | + atomic_inc(&inode->i_count); | |
18253 | + ret = d_materialise_unique(dentry, inode); | |
18254 | + if (!IS_ERR(ret)) | |
18255 | + ii_write_unlock(inode); | |
18256 | + } | |
537831f9 AM |
18257 | +#if 0 |
18258 | + if (unlikely(d_need_lookup(dentry))) { | |
18259 | + spin_lock(&dentry->d_lock); | |
18260 | + dentry->d_flags &= ~DCACHE_NEED_LOOKUP; | |
18261 | + spin_unlock(&dentry->d_lock); | |
18262 | + } else | |
18263 | +#endif | |
c1595e42 JR |
18264 | + if (inode) { |
18265 | + if (!IS_ERR(ret)) | |
18266 | + iput(inode); | |
18267 | + else { | |
18268 | + ii_write_unlock(inode); | |
18269 | + iput(inode); | |
18270 | + inode = NULL; | |
18271 | + } | |
7f207e10 | 18272 | + } |
1facf9fc | 18273 | + |
4f0767ce | 18274 | +out_unlock: |
4a4d8108 | 18275 | + di_write_unlock(dentry); |
2dfbb274 | 18276 | + if (inode) { |
1716fcea AM |
18277 | + /* verbose coding for lock class name */ |
18278 | + if (unlikely(S_ISLNK(inode->i_mode))) | |
18279 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18280 | + au_lc_key + AuLcSymlink_DIINFO); | |
18281 | + else if (unlikely(S_ISDIR(inode->i_mode))) | |
18282 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18283 | + au_lc_key + AuLcDir_DIINFO); | |
18284 | + else /* likely */ | |
18285 | + au_rw_class(&au_di(dentry)->di_rwsem, | |
18286 | + au_lc_key + AuLcNonDir_DIINFO); | |
9dbd164d | 18287 | + } |
7f207e10 | 18288 | +out_si: |
4a4d8108 | 18289 | + si_read_unlock(sb); |
7f207e10 | 18290 | +out: |
4a4d8108 AM |
18291 | + return ret; |
18292 | +} | |
1facf9fc | 18293 | + |
4a4d8108 | 18294 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18295 | + |
4a4d8108 AM |
18296 | +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent, |
18297 | + const unsigned char add_entry, aufs_bindex_t bcpup, | |
18298 | + aufs_bindex_t bstart) | |
18299 | +{ | |
18300 | + int err; | |
18301 | + struct dentry *h_parent; | |
18302 | + struct inode *h_dir; | |
1facf9fc | 18303 | + |
027c5e7a | 18304 | + if (add_entry) |
4a4d8108 | 18305 | + IMustLock(parent->d_inode); |
027c5e7a | 18306 | + else |
4a4d8108 AM |
18307 | + di_write_lock_parent(parent); |
18308 | + | |
18309 | + err = 0; | |
18310 | + if (!au_h_dptr(parent, bcpup)) { | |
c2b27bf2 AM |
18311 | + if (bstart > bcpup) |
18312 | + err = au_cpup_dirs(dentry, bcpup); | |
18313 | + else if (bstart < bcpup) | |
4a4d8108 AM |
18314 | + err = au_cpdown_dirs(dentry, bcpup); |
18315 | + else | |
c2b27bf2 | 18316 | + BUG(); |
4a4d8108 | 18317 | + } |
38d290e6 | 18318 | + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) { |
4a4d8108 AM |
18319 | + h_parent = au_h_dptr(parent, bcpup); |
18320 | + h_dir = h_parent->d_inode; | |
18321 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); | |
86dc4139 AM |
18322 | + err = au_lkup_neg(dentry, bcpup, |
18323 | + au_ftest_wrdir(add_entry, TMP_WHENTRY)); | |
4a4d8108 AM |
18324 | + /* todo: no unlock here */ |
18325 | + mutex_unlock(&h_dir->i_mutex); | |
027c5e7a AM |
18326 | + |
18327 | + AuDbg("bcpup %d\n", bcpup); | |
18328 | + if (!err) { | |
18329 | + if (!dentry->d_inode) | |
18330 | + au_set_h_dptr(dentry, bstart, NULL); | |
4a4d8108 AM |
18331 | + au_update_dbrange(dentry, /*do_put_zero*/0); |
18332 | + } | |
1308ab2a | 18333 | + } |
1facf9fc | 18334 | + |
4a4d8108 AM |
18335 | + if (!add_entry) |
18336 | + di_write_unlock(parent); | |
18337 | + if (!err) | |
18338 | + err = bcpup; /* success */ | |
1308ab2a | 18339 | + |
027c5e7a | 18340 | + AuTraceErr(err); |
4a4d8108 AM |
18341 | + return err; |
18342 | +} | |
1facf9fc | 18343 | + |
4a4d8108 AM |
18344 | +/* |
18345 | + * decide the branch and the parent dir where we will create a new entry. | |
18346 | + * returns new bindex or an error. | |
18347 | + * copyup the parent dir if needed. | |
18348 | + */ | |
18349 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
18350 | + struct au_wr_dir_args *args) | |
18351 | +{ | |
18352 | + int err; | |
392086de | 18353 | + unsigned int flags; |
4a4d8108 | 18354 | + aufs_bindex_t bcpup, bstart, src_bstart; |
86dc4139 AM |
18355 | + const unsigned char add_entry |
18356 | + = au_ftest_wrdir(args->flags, ADD_ENTRY) | |
38d290e6 JR |
18357 | + | au_ftest_wrdir(args->flags, TMP_WHENTRY) |
18358 | + | au_ftest_wrdir(args->flags, TMPFILE); | |
4a4d8108 AM |
18359 | + struct super_block *sb; |
18360 | + struct dentry *parent; | |
18361 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 18362 | + |
4a4d8108 AM |
18363 | + sb = dentry->d_sb; |
18364 | + sbinfo = au_sbi(sb); | |
18365 | + parent = dget_parent(dentry); | |
18366 | + bstart = au_dbstart(dentry); | |
18367 | + bcpup = bstart; | |
18368 | + if (args->force_btgt < 0) { | |
18369 | + if (src_dentry) { | |
18370 | + src_bstart = au_dbstart(src_dentry); | |
18371 | + if (src_bstart < bstart) | |
18372 | + bcpup = src_bstart; | |
18373 | + } else if (add_entry) { | |
392086de AM |
18374 | + flags = 0; |
18375 | + if (au_ftest_wrdir(args->flags, ISDIR)) | |
18376 | + au_fset_wbr(flags, DIR); | |
18377 | + err = AuWbrCreate(sbinfo, dentry, flags); | |
4a4d8108 AM |
18378 | + bcpup = err; |
18379 | + } | |
1facf9fc | 18380 | + |
4a4d8108 AM |
18381 | + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) { |
18382 | + if (add_entry) | |
18383 | + err = AuWbrCopyup(sbinfo, dentry); | |
18384 | + else { | |
18385 | + if (!IS_ROOT(dentry)) { | |
18386 | + di_read_lock_parent(parent, !AuLock_IR); | |
18387 | + err = AuWbrCopyup(sbinfo, dentry); | |
18388 | + di_read_unlock(parent, !AuLock_IR); | |
18389 | + } else | |
18390 | + err = AuWbrCopyup(sbinfo, dentry); | |
18391 | + } | |
18392 | + bcpup = err; | |
18393 | + if (unlikely(err < 0)) | |
18394 | + goto out; | |
18395 | + } | |
18396 | + } else { | |
18397 | + bcpup = args->force_btgt; | |
18398 | + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode)); | |
1308ab2a | 18399 | + } |
027c5e7a | 18400 | + |
4a4d8108 AM |
18401 | + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup); |
18402 | + err = bcpup; | |
18403 | + if (bcpup == bstart) | |
18404 | + goto out; /* success */ | |
4a4d8108 AM |
18405 | + |
18406 | + /* copyup the new parent into the branch we process */ | |
18407 | + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart); | |
027c5e7a AM |
18408 | + if (err >= 0) { |
18409 | + if (!dentry->d_inode) { | |
18410 | + au_set_h_dptr(dentry, bstart, NULL); | |
18411 | + au_set_dbstart(dentry, bcpup); | |
18412 | + au_set_dbend(dentry, bcpup); | |
18413 | + } | |
38d290e6 JR |
18414 | + AuDebugOn(add_entry |
18415 | + && !au_ftest_wrdir(args->flags, TMPFILE) | |
18416 | + && !au_h_dptr(dentry, bcpup)); | |
027c5e7a | 18417 | + } |
86dc4139 AM |
18418 | + |
18419 | +out: | |
18420 | + dput(parent); | |
18421 | + return err; | |
18422 | +} | |
18423 | + | |
18424 | +/* ---------------------------------------------------------------------- */ | |
18425 | + | |
18426 | +void au_pin_hdir_unlock(struct au_pin *p) | |
18427 | +{ | |
18428 | + if (p->hdir) | |
18429 | + au_hn_imtx_unlock(p->hdir); | |
18430 | +} | |
18431 | + | |
c1595e42 | 18432 | +int au_pin_hdir_lock(struct au_pin *p) |
86dc4139 AM |
18433 | +{ |
18434 | + int err; | |
18435 | + | |
18436 | + err = 0; | |
18437 | + if (!p->hdir) | |
18438 | + goto out; | |
18439 | + | |
18440 | + /* even if an error happens later, keep this lock */ | |
18441 | + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi); | |
18442 | + | |
18443 | + err = -EBUSY; | |
18444 | + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode)) | |
18445 | + goto out; | |
18446 | + | |
18447 | + err = 0; | |
18448 | + if (p->h_dentry) | |
18449 | + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode, | |
18450 | + p->h_parent, p->br); | |
18451 | + | |
18452 | +out: | |
18453 | + return err; | |
18454 | +} | |
18455 | + | |
18456 | +int au_pin_hdir_relock(struct au_pin *p) | |
18457 | +{ | |
18458 | + int err, i; | |
18459 | + struct inode *h_i; | |
18460 | + struct dentry *h_d[] = { | |
18461 | + p->h_dentry, | |
18462 | + p->h_parent | |
18463 | + }; | |
18464 | + | |
18465 | + err = au_pin_hdir_lock(p); | |
18466 | + if (unlikely(err)) | |
18467 | + goto out; | |
18468 | + | |
18469 | + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) { | |
18470 | + if (!h_d[i]) | |
18471 | + continue; | |
18472 | + h_i = h_d[i]->d_inode; | |
18473 | + if (h_i) | |
18474 | + err = !h_i->i_nlink; | |
18475 | + } | |
18476 | + | |
18477 | +out: | |
18478 | + return err; | |
18479 | +} | |
18480 | + | |
18481 | +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task) | |
18482 | +{ | |
18483 | +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP) | |
18484 | + p->hdir->hi_inode->i_mutex.owner = task; | |
18485 | +#endif | |
18486 | +} | |
18487 | + | |
18488 | +void au_pin_hdir_acquire_nest(struct au_pin *p) | |
18489 | +{ | |
18490 | + if (p->hdir) { | |
18491 | + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map, | |
18492 | + p->lsc_hi, 0, NULL, _RET_IP_); | |
18493 | + au_pin_hdir_set_owner(p, current); | |
18494 | + } | |
dece6358 | 18495 | +} |
1facf9fc | 18496 | + |
86dc4139 AM |
18497 | +void au_pin_hdir_release(struct au_pin *p) |
18498 | +{ | |
18499 | + if (p->hdir) { | |
18500 | + au_pin_hdir_set_owner(p, p->task); | |
18501 | + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_); | |
18502 | + } | |
18503 | +} | |
1308ab2a | 18504 | + |
4a4d8108 | 18505 | +struct dentry *au_pinned_h_parent(struct au_pin *pin) |
1308ab2a | 18506 | +{ |
4a4d8108 AM |
18507 | + if (pin && pin->parent) |
18508 | + return au_h_dptr(pin->parent, pin->bindex); | |
18509 | + return NULL; | |
dece6358 | 18510 | +} |
1facf9fc | 18511 | + |
4a4d8108 | 18512 | +void au_unpin(struct au_pin *p) |
dece6358 | 18513 | +{ |
86dc4139 AM |
18514 | + if (p->hdir) |
18515 | + au_pin_hdir_unlock(p); | |
e49829fe | 18516 | + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE)) |
b4510431 | 18517 | + vfsub_mnt_drop_write(p->h_mnt); |
4a4d8108 AM |
18518 | + if (!p->hdir) |
18519 | + return; | |
1facf9fc | 18520 | + |
4a4d8108 AM |
18521 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18522 | + di_read_unlock(p->parent, AuLock_IR); | |
18523 | + iput(p->hdir->hi_inode); | |
18524 | + dput(p->parent); | |
18525 | + p->parent = NULL; | |
18526 | + p->hdir = NULL; | |
18527 | + p->h_mnt = NULL; | |
86dc4139 | 18528 | + /* do not clear p->task */ |
4a4d8108 | 18529 | +} |
1308ab2a | 18530 | + |
4a4d8108 AM |
18531 | +int au_do_pin(struct au_pin *p) |
18532 | +{ | |
18533 | + int err; | |
18534 | + struct super_block *sb; | |
4a4d8108 AM |
18535 | + struct inode *h_dir; |
18536 | + | |
18537 | + err = 0; | |
18538 | + sb = p->dentry->d_sb; | |
86dc4139 | 18539 | + p->br = au_sbr(sb, p->bindex); |
4a4d8108 AM |
18540 | + if (IS_ROOT(p->dentry)) { |
18541 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { | |
86dc4139 | 18542 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 18543 | + err = vfsub_mnt_want_write(p->h_mnt); |
4a4d8108 AM |
18544 | + if (unlikely(err)) { |
18545 | + au_fclr_pin(p->flags, MNT_WRITE); | |
18546 | + goto out_err; | |
18547 | + } | |
18548 | + } | |
dece6358 | 18549 | + goto out; |
1facf9fc | 18550 | + } |
18551 | + | |
86dc4139 | 18552 | + p->h_dentry = NULL; |
4a4d8108 | 18553 | + if (p->bindex <= au_dbend(p->dentry)) |
86dc4139 | 18554 | + p->h_dentry = au_h_dptr(p->dentry, p->bindex); |
dece6358 | 18555 | + |
4a4d8108 AM |
18556 | + p->parent = dget_parent(p->dentry); |
18557 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) | |
18558 | + di_read_lock(p->parent, AuLock_IR, p->lsc_di); | |
dece6358 | 18559 | + |
4a4d8108 | 18560 | + h_dir = NULL; |
86dc4139 | 18561 | + p->h_parent = au_h_dptr(p->parent, p->bindex); |
4a4d8108 AM |
18562 | + p->hdir = au_hi(p->parent->d_inode, p->bindex); |
18563 | + if (p->hdir) | |
18564 | + h_dir = p->hdir->hi_inode; | |
dece6358 | 18565 | + |
b752ccd1 AM |
18566 | + /* |
18567 | + * udba case, or | |
18568 | + * if DI_LOCKED is not set, then p->parent may be different | |
18569 | + * and h_parent can be NULL. | |
18570 | + */ | |
86dc4139 | 18571 | + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) { |
e49829fe | 18572 | + err = -EBUSY; |
4a4d8108 AM |
18573 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18574 | + di_read_unlock(p->parent, AuLock_IR); | |
18575 | + dput(p->parent); | |
18576 | + p->parent = NULL; | |
18577 | + goto out_err; | |
18578 | + } | |
1308ab2a | 18579 | + |
4a4d8108 | 18580 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { |
86dc4139 | 18581 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 18582 | + err = vfsub_mnt_want_write(p->h_mnt); |
dece6358 | 18583 | + if (unlikely(err)) { |
4a4d8108 | 18584 | + au_fclr_pin(p->flags, MNT_WRITE); |
86dc4139 AM |
18585 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
18586 | + di_read_unlock(p->parent, AuLock_IR); | |
18587 | + dput(p->parent); | |
18588 | + p->parent = NULL; | |
18589 | + goto out_err; | |
dece6358 AM |
18590 | + } |
18591 | + } | |
4a4d8108 | 18592 | + |
86dc4139 AM |
18593 | + au_igrab(h_dir); |
18594 | + err = au_pin_hdir_lock(p); | |
18595 | + if (!err) | |
18596 | + goto out; /* success */ | |
18597 | + | |
076b876e AM |
18598 | + au_unpin(p); |
18599 | + | |
4f0767ce | 18600 | +out_err: |
4a4d8108 AM |
18601 | + pr_err("err %d\n", err); |
18602 | + err = au_busy_or_stale(); | |
4f0767ce | 18603 | +out: |
1facf9fc | 18604 | + return err; |
18605 | +} | |
18606 | + | |
4a4d8108 AM |
18607 | +void au_pin_init(struct au_pin *p, struct dentry *dentry, |
18608 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
18609 | + unsigned int udba, unsigned char flags) | |
18610 | +{ | |
18611 | + p->dentry = dentry; | |
18612 | + p->udba = udba; | |
18613 | + p->lsc_di = lsc_di; | |
18614 | + p->lsc_hi = lsc_hi; | |
18615 | + p->flags = flags; | |
18616 | + p->bindex = bindex; | |
18617 | + | |
18618 | + p->parent = NULL; | |
18619 | + p->hdir = NULL; | |
18620 | + p->h_mnt = NULL; | |
86dc4139 AM |
18621 | + |
18622 | + p->h_dentry = NULL; | |
18623 | + p->h_parent = NULL; | |
18624 | + p->br = NULL; | |
18625 | + p->task = current; | |
4a4d8108 AM |
18626 | +} |
18627 | + | |
18628 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
18629 | + unsigned int udba, unsigned char flags) | |
18630 | +{ | |
18631 | + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2, | |
18632 | + udba, flags); | |
18633 | + return au_do_pin(pin); | |
18634 | +} | |
18635 | + | |
dece6358 AM |
18636 | +/* ---------------------------------------------------------------------- */ |
18637 | + | |
1308ab2a | 18638 | +/* |
4a4d8108 AM |
18639 | + * ->setattr() and ->getattr() are called in various cases. |
18640 | + * chmod, stat: dentry is revalidated. | |
18641 | + * fchmod, fstat: file and dentry are not revalidated, additionally they may be | |
18642 | + * unhashed. | |
18643 | + * for ->setattr(), ia->ia_file is passed from ftruncate only. | |
1308ab2a | 18644 | + */ |
027c5e7a | 18645 | +/* todo: consolidate with do_refresh() and simple_reval_dpath() */ |
c1595e42 | 18646 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen) |
1facf9fc | 18647 | +{ |
4a4d8108 AM |
18648 | + int err; |
18649 | + struct inode *inode; | |
18650 | + struct dentry *parent; | |
1facf9fc | 18651 | + |
1308ab2a | 18652 | + err = 0; |
4a4d8108 | 18653 | + inode = dentry->d_inode; |
027c5e7a | 18654 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 AM |
18655 | + parent = dget_parent(dentry); |
18656 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 18657 | + err = au_refresh_dentry(dentry, parent); |
4a4d8108 AM |
18658 | + di_read_unlock(parent, AuLock_IR); |
18659 | + dput(parent); | |
dece6358 | 18660 | + } |
1facf9fc | 18661 | + |
4a4d8108 | 18662 | + AuTraceErr(err); |
1308ab2a | 18663 | + return err; |
18664 | +} | |
dece6358 | 18665 | + |
c1595e42 JR |
18666 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, |
18667 | + struct au_icpup_args *a) | |
1308ab2a | 18668 | +{ |
18669 | + int err; | |
4a4d8108 | 18670 | + loff_t sz; |
e49829fe | 18671 | + aufs_bindex_t bstart, ibstart; |
4a4d8108 AM |
18672 | + struct dentry *hi_wh, *parent; |
18673 | + struct inode *inode; | |
4a4d8108 AM |
18674 | + struct au_wr_dir_args wr_dir_args = { |
18675 | + .force_btgt = -1, | |
18676 | + .flags = 0 | |
18677 | + }; | |
18678 | + | |
18679 | + bstart = au_dbstart(dentry); | |
18680 | + inode = dentry->d_inode; | |
18681 | + if (S_ISDIR(inode->i_mode)) | |
18682 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); | |
18683 | + /* plink or hi_wh() case */ | |
e49829fe | 18684 | + ibstart = au_ibstart(inode); |
027c5e7a | 18685 | + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode)) |
e49829fe | 18686 | + wr_dir_args.force_btgt = ibstart; |
4a4d8108 AM |
18687 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
18688 | + if (unlikely(err < 0)) | |
18689 | + goto out; | |
18690 | + a->btgt = err; | |
18691 | + if (err != bstart) | |
18692 | + au_fset_icpup(a->flags, DID_CPUP); | |
18693 | + | |
18694 | + err = 0; | |
18695 | + a->pin_flags = AuPin_MNT_WRITE; | |
18696 | + parent = NULL; | |
18697 | + if (!IS_ROOT(dentry)) { | |
18698 | + au_fset_pin(a->pin_flags, DI_LOCKED); | |
18699 | + parent = dget_parent(dentry); | |
18700 | + di_write_lock_parent(parent); | |
18701 | + } | |
18702 | + | |
18703 | + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags); | |
18704 | + if (unlikely(err)) | |
18705 | + goto out_parent; | |
18706 | + | |
18707 | + a->h_path.dentry = au_h_dptr(dentry, bstart); | |
18708 | + a->h_inode = a->h_path.dentry->d_inode; | |
4a4d8108 | 18709 | + sz = -1; |
c1595e42 JR |
18710 | + if (ia && (ia->ia_valid & ATTR_SIZE)) { |
18711 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
18712 | + if (ia->ia_size < i_size_read(a->h_inode)) | |
18713 | + sz = ia->ia_size; | |
18714 | + mutex_unlock(&a->h_inode->i_mutex); | |
18715 | + } | |
4a4d8108 | 18716 | + |
4a4d8108 | 18717 | + hi_wh = NULL; |
027c5e7a | 18718 | + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) { |
4a4d8108 AM |
18719 | + hi_wh = au_hi_wh(inode, a->btgt); |
18720 | + if (!hi_wh) { | |
c2b27bf2 AM |
18721 | + struct au_cp_generic cpg = { |
18722 | + .dentry = dentry, | |
18723 | + .bdst = a->btgt, | |
18724 | + .bsrc = -1, | |
18725 | + .len = sz, | |
18726 | + .pin = &a->pin | |
18727 | + }; | |
18728 | + err = au_sio_cpup_wh(&cpg, /*file*/NULL); | |
4a4d8108 AM |
18729 | + if (unlikely(err)) |
18730 | + goto out_unlock; | |
18731 | + hi_wh = au_hi_wh(inode, a->btgt); | |
18732 | + /* todo: revalidate hi_wh? */ | |
18733 | + } | |
18734 | + } | |
18735 | + | |
18736 | + if (parent) { | |
18737 | + au_pin_set_parent_lflag(&a->pin, /*lflag*/0); | |
18738 | + di_downgrade_lock(parent, AuLock_IR); | |
18739 | + dput(parent); | |
18740 | + parent = NULL; | |
18741 | + } | |
18742 | + if (!au_ftest_icpup(a->flags, DID_CPUP)) | |
18743 | + goto out; /* success */ | |
18744 | + | |
18745 | + if (!d_unhashed(dentry)) { | |
c2b27bf2 AM |
18746 | + struct au_cp_generic cpg = { |
18747 | + .dentry = dentry, | |
18748 | + .bdst = a->btgt, | |
18749 | + .bsrc = bstart, | |
18750 | + .len = sz, | |
18751 | + .pin = &a->pin, | |
18752 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
18753 | + }; | |
18754 | + err = au_sio_cpup_simple(&cpg); | |
4a4d8108 AM |
18755 | + if (!err) |
18756 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
18757 | + } else if (!hi_wh) | |
18758 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
18759 | + else | |
18760 | + a->h_path.dentry = hi_wh; /* do not dget here */ | |
1308ab2a | 18761 | + |
4f0767ce | 18762 | +out_unlock: |
4a4d8108 | 18763 | + a->h_inode = a->h_path.dentry->d_inode; |
86dc4139 | 18764 | + if (!err) |
dece6358 | 18765 | + goto out; /* success */ |
4a4d8108 | 18766 | + au_unpin(&a->pin); |
4f0767ce | 18767 | +out_parent: |
4a4d8108 AM |
18768 | + if (parent) { |
18769 | + di_write_unlock(parent); | |
18770 | + dput(parent); | |
18771 | + } | |
4f0767ce | 18772 | +out: |
86dc4139 AM |
18773 | + if (!err) |
18774 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
1facf9fc | 18775 | + return err; |
18776 | +} | |
18777 | + | |
4a4d8108 | 18778 | +static int aufs_setattr(struct dentry *dentry, struct iattr *ia) |
1facf9fc | 18779 | +{ |
4a4d8108 | 18780 | + int err; |
523b37e3 | 18781 | + struct inode *inode, *delegated; |
4a4d8108 AM |
18782 | + struct super_block *sb; |
18783 | + struct file *file; | |
18784 | + struct au_icpup_args *a; | |
1facf9fc | 18785 | + |
4a4d8108 AM |
18786 | + inode = dentry->d_inode; |
18787 | + IMustLock(inode); | |
dece6358 | 18788 | + |
4a4d8108 AM |
18789 | + err = -ENOMEM; |
18790 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
18791 | + if (unlikely(!a)) | |
18792 | + goto out; | |
1facf9fc | 18793 | + |
4a4d8108 AM |
18794 | + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
18795 | + ia->ia_valid &= ~ATTR_MODE; | |
dece6358 | 18796 | + |
4a4d8108 AM |
18797 | + file = NULL; |
18798 | + sb = dentry->d_sb; | |
e49829fe JR |
18799 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
18800 | + if (unlikely(err)) | |
18801 | + goto out_kfree; | |
18802 | + | |
4a4d8108 AM |
18803 | + if (ia->ia_valid & ATTR_FILE) { |
18804 | + /* currently ftruncate(2) only */ | |
18805 | + AuDebugOn(!S_ISREG(inode->i_mode)); | |
18806 | + file = ia->ia_file; | |
18807 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1); | |
18808 | + if (unlikely(err)) | |
18809 | + goto out_si; | |
18810 | + ia->ia_file = au_hf_top(file); | |
18811 | + a->udba = AuOpt_UDBA_NONE; | |
18812 | + } else { | |
18813 | + /* fchmod() doesn't pass ia_file */ | |
18814 | + a->udba = au_opt_udba(sb); | |
027c5e7a AM |
18815 | + di_write_lock_child(dentry); |
18816 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
4a4d8108 AM |
18817 | + if (d_unhashed(dentry)) |
18818 | + a->udba = AuOpt_UDBA_NONE; | |
4a4d8108 AM |
18819 | + if (a->udba != AuOpt_UDBA_NONE) { |
18820 | + AuDebugOn(IS_ROOT(dentry)); | |
18821 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
18822 | + if (unlikely(err)) | |
18823 | + goto out_dentry; | |
18824 | + } | |
dece6358 | 18825 | + } |
dece6358 | 18826 | + |
4a4d8108 AM |
18827 | + err = au_pin_and_icpup(dentry, ia, a); |
18828 | + if (unlikely(err < 0)) | |
18829 | + goto out_dentry; | |
18830 | + if (au_ftest_icpup(a->flags, DID_CPUP)) { | |
18831 | + ia->ia_file = NULL; | |
18832 | + ia->ia_valid &= ~ATTR_FILE; | |
1308ab2a | 18833 | + } |
dece6358 | 18834 | + |
4a4d8108 AM |
18835 | + a->h_path.mnt = au_sbr_mnt(sb, a->btgt); |
18836 | + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME)) | |
18837 | + == (ATTR_MODE | ATTR_CTIME)) { | |
7eafdf33 | 18838 | + err = security_path_chmod(&a->h_path, ia->ia_mode); |
4a4d8108 AM |
18839 | + if (unlikely(err)) |
18840 | + goto out_unlock; | |
18841 | + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID)) | |
18842 | + && (ia->ia_valid & ATTR_CTIME)) { | |
86dc4139 | 18843 | + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid); |
4a4d8108 AM |
18844 | + if (unlikely(err)) |
18845 | + goto out_unlock; | |
18846 | + } | |
dece6358 | 18847 | + |
4a4d8108 AM |
18848 | + if (ia->ia_valid & ATTR_SIZE) { |
18849 | + struct file *f; | |
1308ab2a | 18850 | + |
953406b4 | 18851 | + if (ia->ia_size < i_size_read(inode)) |
4a4d8108 | 18852 | + /* unmap only */ |
953406b4 | 18853 | + truncate_setsize(inode, ia->ia_size); |
1308ab2a | 18854 | + |
4a4d8108 AM |
18855 | + f = NULL; |
18856 | + if (ia->ia_valid & ATTR_FILE) | |
18857 | + f = ia->ia_file; | |
18858 | + mutex_unlock(&a->h_inode->i_mutex); | |
18859 | + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f); | |
18860 | + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD); | |
523b37e3 AM |
18861 | + } else { |
18862 | + delegated = NULL; | |
18863 | + while (1) { | |
18864 | + err = vfsub_notify_change(&a->h_path, ia, &delegated); | |
18865 | + if (delegated) { | |
18866 | + err = break_deleg_wait(&delegated); | |
18867 | + if (!err) | |
18868 | + continue; | |
18869 | + } | |
18870 | + break; | |
18871 | + } | |
18872 | + } | |
4a4d8108 AM |
18873 | + if (!err) |
18874 | + au_cpup_attr_changeable(inode); | |
1308ab2a | 18875 | + |
4f0767ce | 18876 | +out_unlock: |
4a4d8108 AM |
18877 | + mutex_unlock(&a->h_inode->i_mutex); |
18878 | + au_unpin(&a->pin); | |
027c5e7a AM |
18879 | + if (unlikely(err)) |
18880 | + au_update_dbstart(dentry); | |
4f0767ce | 18881 | +out_dentry: |
4a4d8108 AM |
18882 | + di_write_unlock(dentry); |
18883 | + if (file) { | |
18884 | + fi_write_unlock(file); | |
18885 | + ia->ia_file = file; | |
18886 | + ia->ia_valid |= ATTR_FILE; | |
18887 | + } | |
4f0767ce | 18888 | +out_si: |
4a4d8108 | 18889 | + si_read_unlock(sb); |
e49829fe | 18890 | +out_kfree: |
4a4d8108 | 18891 | + kfree(a); |
4f0767ce | 18892 | +out: |
4a4d8108 AM |
18893 | + AuTraceErr(err); |
18894 | + return err; | |
1facf9fc | 18895 | +} |
18896 | + | |
c1595e42 JR |
18897 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) |
18898 | +static int au_h_path_to_set_attr(struct dentry *dentry, | |
18899 | + struct au_icpup_args *a, struct path *h_path) | |
18900 | +{ | |
18901 | + int err; | |
18902 | + struct super_block *sb; | |
18903 | + | |
18904 | + sb = dentry->d_sb; | |
18905 | + a->udba = au_opt_udba(sb); | |
18906 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
18907 | + if (d_unhashed(dentry)) | |
18908 | + a->udba = AuOpt_UDBA_NONE; | |
18909 | + if (a->udba != AuOpt_UDBA_NONE) { | |
18910 | + AuDebugOn(IS_ROOT(dentry)); | |
18911 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
18912 | + if (unlikely(err)) | |
18913 | + goto out; | |
18914 | + } | |
18915 | + err = au_pin_and_icpup(dentry, /*ia*/NULL, a); | |
18916 | + if (unlikely(err < 0)) | |
18917 | + goto out; | |
18918 | + | |
18919 | + h_path->dentry = a->h_path.dentry; | |
18920 | + h_path->mnt = au_sbr_mnt(sb, a->btgt); | |
18921 | + | |
18922 | +out: | |
18923 | + return err; | |
18924 | +} | |
18925 | + | |
18926 | +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg) | |
18927 | +{ | |
18928 | + int err; | |
18929 | + struct path h_path; | |
18930 | + struct super_block *sb; | |
18931 | + struct au_icpup_args *a; | |
18932 | + struct inode *inode, *h_inode; | |
18933 | + | |
18934 | + inode = dentry->d_inode; | |
18935 | + IMustLock(inode); | |
18936 | + | |
18937 | + err = -ENOMEM; | |
18938 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
18939 | + if (unlikely(!a)) | |
18940 | + goto out; | |
18941 | + | |
18942 | + sb = dentry->d_sb; | |
18943 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
18944 | + if (unlikely(err)) | |
18945 | + goto out_kfree; | |
18946 | + | |
18947 | + h_path.dentry = NULL; /* silence gcc */ | |
18948 | + di_write_lock_child(dentry); | |
18949 | + err = au_h_path_to_set_attr(dentry, a, &h_path); | |
18950 | + if (unlikely(err)) | |
18951 | + goto out_di; | |
18952 | + | |
18953 | + mutex_unlock(&a->h_inode->i_mutex); | |
18954 | + switch (arg->type) { | |
18955 | + case AU_XATTR_SET: | |
18956 | + err = vfsub_setxattr(h_path.dentry, | |
18957 | + arg->u.set.name, arg->u.set.value, | |
18958 | + arg->u.set.size, arg->u.set.flags); | |
18959 | + break; | |
18960 | + case AU_XATTR_REMOVE: | |
18961 | + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name); | |
18962 | + break; | |
18963 | + case AU_ACL_SET: | |
18964 | + err = -EOPNOTSUPP; | |
18965 | + h_inode = h_path.dentry->d_inode; | |
18966 | + if (h_inode->i_op->set_acl) | |
18967 | + err = h_inode->i_op->set_acl(h_inode, | |
18968 | + arg->u.acl_set.acl, | |
18969 | + arg->u.acl_set.type); | |
18970 | + break; | |
18971 | + } | |
18972 | + if (!err) | |
18973 | + au_cpup_attr_timesizes(inode); | |
18974 | + | |
18975 | + au_unpin(&a->pin); | |
18976 | + if (unlikely(err)) | |
18977 | + au_update_dbstart(dentry); | |
18978 | + | |
18979 | +out_di: | |
18980 | + di_write_unlock(dentry); | |
18981 | + si_read_unlock(sb); | |
18982 | +out_kfree: | |
18983 | + kfree(a); | |
18984 | +out: | |
18985 | + AuTraceErr(err); | |
18986 | + return err; | |
18987 | +} | |
18988 | +#endif | |
18989 | + | |
4a4d8108 AM |
18990 | +static void au_refresh_iattr(struct inode *inode, struct kstat *st, |
18991 | + unsigned int nlink) | |
1facf9fc | 18992 | +{ |
9dbd164d AM |
18993 | + unsigned int n; |
18994 | + | |
4a4d8108 | 18995 | + inode->i_mode = st->mode; |
86dc4139 AM |
18996 | + /* don't i_[ug]id_write() here */ |
18997 | + inode->i_uid = st->uid; | |
18998 | + inode->i_gid = st->gid; | |
4a4d8108 AM |
18999 | + inode->i_atime = st->atime; |
19000 | + inode->i_mtime = st->mtime; | |
19001 | + inode->i_ctime = st->ctime; | |
1facf9fc | 19002 | + |
4a4d8108 AM |
19003 | + au_cpup_attr_nlink(inode, /*force*/0); |
19004 | + if (S_ISDIR(inode->i_mode)) { | |
9dbd164d AM |
19005 | + n = inode->i_nlink; |
19006 | + n -= nlink; | |
19007 | + n += st->nlink; | |
f6b6e03d | 19008 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 19009 | + /* 0 can happen */ |
92d182d2 | 19010 | + set_nlink(inode, n); |
4a4d8108 | 19011 | + } |
1facf9fc | 19012 | + |
4a4d8108 AM |
19013 | + spin_lock(&inode->i_lock); |
19014 | + inode->i_blocks = st->blocks; | |
19015 | + i_size_write(inode, st->size); | |
19016 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 19017 | +} |
19018 | + | |
c1595e42 JR |
19019 | +/* |
19020 | + * common routine for aufs_getattr() and aufs_getxattr(). | |
19021 | + * returns zero or negative (an error). | |
19022 | + * @dentry will be read-locked in success. | |
19023 | + */ | |
19024 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path) | |
1facf9fc | 19025 | +{ |
4a4d8108 | 19026 | + int err; |
076b876e | 19027 | + unsigned int mnt_flags, sigen; |
c1595e42 | 19028 | + unsigned char udba_none; |
4a4d8108 | 19029 | + aufs_bindex_t bindex; |
4a4d8108 AM |
19030 | + struct super_block *sb, *h_sb; |
19031 | + struct inode *inode; | |
1facf9fc | 19032 | + |
c1595e42 JR |
19033 | + h_path->mnt = NULL; |
19034 | + h_path->dentry = NULL; | |
19035 | + | |
19036 | + err = 0; | |
4a4d8108 | 19037 | + sb = dentry->d_sb; |
4a4d8108 AM |
19038 | + mnt_flags = au_mntflags(sb); |
19039 | + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE); | |
1facf9fc | 19040 | + |
4a4d8108 | 19041 | + /* support fstat(2) */ |
027c5e7a | 19042 | + if (!d_unlinked(dentry) && !udba_none) { |
076b876e | 19043 | + sigen = au_sigen(sb); |
027c5e7a AM |
19044 | + err = au_digen_test(dentry, sigen); |
19045 | + if (!err) { | |
4a4d8108 | 19046 | + di_read_lock_child(dentry, AuLock_IR); |
027c5e7a | 19047 | + err = au_dbrange_test(dentry); |
c1595e42 JR |
19048 | + if (unlikely(err)) { |
19049 | + di_read_unlock(dentry, AuLock_IR); | |
19050 | + goto out; | |
19051 | + } | |
027c5e7a | 19052 | + } else { |
4a4d8108 AM |
19053 | + AuDebugOn(IS_ROOT(dentry)); |
19054 | + di_write_lock_child(dentry); | |
027c5e7a AM |
19055 | + err = au_dbrange_test(dentry); |
19056 | + if (!err) | |
19057 | + err = au_reval_for_attr(dentry, sigen); | |
c1595e42 JR |
19058 | + if (!err) |
19059 | + di_downgrade_lock(dentry, AuLock_IR); | |
19060 | + else { | |
19061 | + di_write_unlock(dentry); | |
19062 | + goto out; | |
19063 | + } | |
4a4d8108 AM |
19064 | + } |
19065 | + } else | |
19066 | + di_read_lock_child(dentry, AuLock_IR); | |
1facf9fc | 19067 | + |
c1595e42 | 19068 | + inode = dentry->d_inode; |
4a4d8108 | 19069 | + bindex = au_ibstart(inode); |
c1595e42 JR |
19070 | + h_path->mnt = au_sbr_mnt(sb, bindex); |
19071 | + h_sb = h_path->mnt->mnt_sb; | |
19072 | + if (!force | |
19073 | + && !au_test_fs_bad_iattr(h_sb) | |
19074 | + && udba_none) | |
19075 | + goto out; /* success */ | |
1facf9fc | 19076 | + |
4a4d8108 | 19077 | + if (au_dbstart(dentry) == bindex) |
c1595e42 | 19078 | + h_path->dentry = au_h_dptr(dentry, bindex); |
4a4d8108 | 19079 | + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) { |
c1595e42 JR |
19080 | + h_path->dentry = au_plink_lkup(inode, bindex); |
19081 | + if (IS_ERR(h_path->dentry)) | |
19082 | + /* pretending success */ | |
19083 | + h_path->dentry = NULL; | |
19084 | + else | |
19085 | + dput(h_path->dentry); | |
4a4d8108 | 19086 | + } |
c1595e42 JR |
19087 | + |
19088 | +out: | |
19089 | + return err; | |
19090 | +} | |
19091 | + | |
19092 | +static int aufs_getattr(struct vfsmount *mnt __maybe_unused, | |
19093 | + struct dentry *dentry, struct kstat *st) | |
19094 | +{ | |
19095 | + int err; | |
19096 | + unsigned char positive; | |
19097 | + struct path h_path; | |
19098 | + struct inode *inode; | |
19099 | + struct super_block *sb; | |
19100 | + | |
19101 | + inode = dentry->d_inode; | |
19102 | + sb = dentry->d_sb; | |
19103 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19104 | + if (unlikely(err)) | |
19105 | + goto out; | |
19106 | + err = au_h_path_getattr(dentry, /*force*/0, &h_path); | |
19107 | + if (unlikely(err)) | |
19108 | + goto out_si; | |
c06a8ce3 | 19109 | + if (unlikely(!h_path.dentry)) |
c1595e42 | 19110 | + /* illegally overlapped or something */ |
4a4d8108 AM |
19111 | + goto out_fill; /* pretending success */ |
19112 | + | |
c06a8ce3 | 19113 | + positive = !!h_path.dentry->d_inode; |
4a4d8108 | 19114 | + if (positive) |
c06a8ce3 | 19115 | + err = vfs_getattr(&h_path, st); |
4a4d8108 AM |
19116 | + if (!err) { |
19117 | + if (positive) | |
c06a8ce3 AM |
19118 | + au_refresh_iattr(inode, st, |
19119 | + h_path.dentry->d_inode->i_nlink); | |
4a4d8108 | 19120 | + goto out_fill; /* success */ |
1facf9fc | 19121 | + } |
7f207e10 | 19122 | + AuTraceErr(err); |
c1595e42 | 19123 | + goto out_di; |
4a4d8108 | 19124 | + |
4f0767ce | 19125 | +out_fill: |
4a4d8108 | 19126 | + generic_fillattr(inode, st); |
c1595e42 | 19127 | +out_di: |
4a4d8108 | 19128 | + di_read_unlock(dentry, AuLock_IR); |
c1595e42 | 19129 | +out_si: |
4a4d8108 | 19130 | + si_read_unlock(sb); |
7f207e10 AM |
19131 | +out: |
19132 | + AuTraceErr(err); | |
4a4d8108 | 19133 | + return err; |
1facf9fc | 19134 | +} |
19135 | + | |
19136 | +/* ---------------------------------------------------------------------- */ | |
19137 | + | |
4a4d8108 AM |
19138 | +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf, |
19139 | + int bufsiz) | |
1facf9fc | 19140 | +{ |
19141 | + int err; | |
4a4d8108 AM |
19142 | + struct super_block *sb; |
19143 | + struct dentry *h_dentry; | |
1facf9fc | 19144 | + |
4a4d8108 AM |
19145 | + err = -EINVAL; |
19146 | + h_dentry = au_h_dptr(dentry, bindex); | |
19147 | + if (unlikely(!h_dentry->d_inode->i_op->readlink)) | |
19148 | + goto out; | |
1facf9fc | 19149 | + |
4a4d8108 AM |
19150 | + err = security_inode_readlink(h_dentry); |
19151 | + if (unlikely(err)) | |
dece6358 | 19152 | + goto out; |
1facf9fc | 19153 | + |
4a4d8108 AM |
19154 | + sb = dentry->d_sb; |
19155 | + if (!au_test_ro(sb, bindex, dentry->d_inode)) { | |
19156 | + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry); | |
19157 | + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode); | |
1facf9fc | 19158 | + } |
4a4d8108 | 19159 | + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz); |
1facf9fc | 19160 | + |
4f0767ce | 19161 | +out: |
4a4d8108 AM |
19162 | + return err; |
19163 | +} | |
1facf9fc | 19164 | + |
4a4d8108 AM |
19165 | +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz) |
19166 | +{ | |
19167 | + int err; | |
1facf9fc | 19168 | + |
027c5e7a AM |
19169 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
19170 | + if (unlikely(err)) | |
19171 | + goto out; | |
19172 | + err = au_d_hashed_positive(dentry); | |
19173 | + if (!err) | |
19174 | + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz); | |
4a4d8108 | 19175 | + aufs_read_unlock(dentry, AuLock_IR); |
1facf9fc | 19176 | + |
027c5e7a | 19177 | +out: |
4a4d8108 AM |
19178 | + return err; |
19179 | +} | |
1facf9fc | 19180 | + |
4a4d8108 AM |
19181 | +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd) |
19182 | +{ | |
19183 | + int err; | |
4a4d8108 | 19184 | + mm_segment_t old_fs; |
b752ccd1 AM |
19185 | + union { |
19186 | + char *k; | |
19187 | + char __user *u; | |
19188 | + } buf; | |
1facf9fc | 19189 | + |
4a4d8108 | 19190 | + err = -ENOMEM; |
537831f9 | 19191 | + buf.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 19192 | + if (unlikely(!buf.k)) |
4a4d8108 | 19193 | + goto out; |
1facf9fc | 19194 | + |
027c5e7a AM |
19195 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
19196 | + if (unlikely(err)) | |
19197 | + goto out_name; | |
19198 | + | |
19199 | + err = au_d_hashed_positive(dentry); | |
19200 | + if (!err) { | |
19201 | + old_fs = get_fs(); | |
19202 | + set_fs(KERNEL_DS); | |
19203 | + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX); | |
19204 | + set_fs(old_fs); | |
19205 | + } | |
4a4d8108 | 19206 | + aufs_read_unlock(dentry, AuLock_IR); |
1facf9fc | 19207 | + |
4a4d8108 | 19208 | + if (err >= 0) { |
b752ccd1 | 19209 | + buf.k[err] = 0; |
4a4d8108 | 19210 | + /* will be freed by put_link */ |
b752ccd1 | 19211 | + nd_set_link(nd, buf.k); |
4a4d8108 | 19212 | + return NULL; /* success */ |
1308ab2a | 19213 | + } |
1facf9fc | 19214 | + |
027c5e7a | 19215 | +out_name: |
537831f9 | 19216 | + free_page((unsigned long)buf.k); |
4f0767ce | 19217 | +out: |
4a4d8108 AM |
19218 | + AuTraceErr(err); |
19219 | + return ERR_PTR(err); | |
19220 | +} | |
1facf9fc | 19221 | + |
4a4d8108 AM |
19222 | +static void aufs_put_link(struct dentry *dentry __maybe_unused, |
19223 | + struct nameidata *nd, void *cookie __maybe_unused) | |
19224 | +{ | |
537831f9 AM |
19225 | + char *p; |
19226 | + | |
19227 | + p = nd_get_link(nd); | |
19228 | + if (!IS_ERR_OR_NULL(p)) | |
19229 | + free_page((unsigned long)p); | |
4a4d8108 | 19230 | +} |
1facf9fc | 19231 | + |
4a4d8108 | 19232 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19233 | + |
0c3ec466 | 19234 | +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags) |
4a4d8108 | 19235 | +{ |
0c3ec466 AM |
19236 | + int err; |
19237 | + struct super_block *sb; | |
19238 | + struct inode *h_inode; | |
19239 | + | |
19240 | + sb = inode->i_sb; | |
19241 | + /* mmap_sem might be acquired already, cf. aufs_mmap() */ | |
19242 | + lockdep_off(); | |
19243 | + si_read_lock(sb, AuLock_FLUSH); | |
19244 | + ii_write_lock_child(inode); | |
19245 | + lockdep_on(); | |
19246 | + h_inode = au_h_iptr(inode, au_ibstart(inode)); | |
19247 | + err = vfsub_update_time(h_inode, ts, flags); | |
19248 | + lockdep_off(); | |
38d290e6 JR |
19249 | + if (!err) |
19250 | + au_cpup_attr_timesizes(inode); | |
0c3ec466 AM |
19251 | + ii_write_unlock(inode); |
19252 | + si_read_unlock(sb); | |
19253 | + lockdep_on(); | |
38d290e6 JR |
19254 | + |
19255 | + if (!err && (flags & S_VERSION)) | |
19256 | + inode_inc_iversion(inode); | |
19257 | + | |
0c3ec466 | 19258 | + return err; |
4a4d8108 | 19259 | +} |
1facf9fc | 19260 | + |
4a4d8108 | 19261 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19262 | + |
4a4d8108 AM |
19263 | +struct inode_operations aufs_symlink_iop = { |
19264 | + .permission = aufs_permission, | |
c1595e42 JR |
19265 | +#ifdef CONFIG_FS_POSIX_ACL |
19266 | + .get_acl = aufs_get_acl, | |
19267 | + .set_acl = aufs_set_acl, /* unsupport for symlink? */ | |
19268 | +#endif | |
19269 | + | |
4a4d8108 AM |
19270 | + .setattr = aufs_setattr, |
19271 | + .getattr = aufs_getattr, | |
0c3ec466 | 19272 | + |
c1595e42 JR |
19273 | +#ifdef CONFIG_AUFS_XATTR |
19274 | + .setxattr = aufs_setxattr, | |
19275 | + .getxattr = aufs_getxattr, | |
19276 | + .listxattr = aufs_listxattr, | |
19277 | + .removexattr = aufs_removexattr, | |
19278 | +#endif | |
19279 | + | |
4a4d8108 AM |
19280 | + .readlink = aufs_readlink, |
19281 | + .follow_link = aufs_follow_link, | |
0c3ec466 AM |
19282 | + .put_link = aufs_put_link, |
19283 | + | |
19284 | + /* .update_time = aufs_update_time */ | |
4a4d8108 AM |
19285 | +}; |
19286 | + | |
19287 | +struct inode_operations aufs_dir_iop = { | |
19288 | + .create = aufs_create, | |
19289 | + .lookup = aufs_lookup, | |
19290 | + .link = aufs_link, | |
19291 | + .unlink = aufs_unlink, | |
19292 | + .symlink = aufs_symlink, | |
19293 | + .mkdir = aufs_mkdir, | |
19294 | + .rmdir = aufs_rmdir, | |
19295 | + .mknod = aufs_mknod, | |
19296 | + .rename = aufs_rename, | |
19297 | + | |
19298 | + .permission = aufs_permission, | |
c1595e42 JR |
19299 | +#ifdef CONFIG_FS_POSIX_ACL |
19300 | + .get_acl = aufs_get_acl, | |
19301 | + .set_acl = aufs_set_acl, | |
19302 | +#endif | |
19303 | + | |
4a4d8108 | 19304 | + .setattr = aufs_setattr, |
0c3ec466 AM |
19305 | + .getattr = aufs_getattr, |
19306 | + | |
c1595e42 JR |
19307 | +#ifdef CONFIG_AUFS_XATTR |
19308 | + .setxattr = aufs_setxattr, | |
19309 | + .getxattr = aufs_getxattr, | |
19310 | + .listxattr = aufs_listxattr, | |
19311 | + .removexattr = aufs_removexattr, | |
19312 | +#endif | |
19313 | + | |
38d290e6 | 19314 | + .update_time = aufs_update_time, |
b4510431 | 19315 | + /* no support for atomic_open() */ |
38d290e6 JR |
19316 | + |
19317 | + .tmpfile = aufs_tmpfile | |
4a4d8108 AM |
19318 | +}; |
19319 | + | |
19320 | +struct inode_operations aufs_iop = { | |
19321 | + .permission = aufs_permission, | |
c1595e42 JR |
19322 | +#ifdef CONFIG_FS_POSIX_ACL |
19323 | + .get_acl = aufs_get_acl, | |
19324 | + .set_acl = aufs_set_acl, | |
19325 | +#endif | |
19326 | + | |
4a4d8108 AM |
19327 | + .setattr = aufs_setattr, |
19328 | + .getattr = aufs_getattr, | |
0c3ec466 | 19329 | + |
c1595e42 JR |
19330 | +#ifdef CONFIG_AUFS_XATTR |
19331 | + .setxattr = aufs_setxattr, | |
19332 | + .getxattr = aufs_getxattr, | |
19333 | + .listxattr = aufs_listxattr, | |
19334 | + .removexattr = aufs_removexattr, | |
19335 | +#endif | |
19336 | + | |
0c3ec466 | 19337 | + .update_time = aufs_update_time |
4a4d8108 | 19338 | +}; |
7f207e10 AM |
19339 | diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c |
19340 | --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 19341 | +++ linux/fs/aufs/i_op_del.c 2015-01-25 13:00:38.631047076 +0100 |
076b876e | 19342 | @@ -0,0 +1,507 @@ |
1facf9fc | 19343 | +/* |
523b37e3 | 19344 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 19345 | + * |
19346 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19347 | + * it under the terms of the GNU General Public License as published by | |
19348 | + * the Free Software Foundation; either version 2 of the License, or | |
19349 | + * (at your option) any later version. | |
dece6358 AM |
19350 | + * |
19351 | + * This program is distributed in the hope that it will be useful, | |
19352 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19353 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19354 | + * GNU General Public License for more details. | |
19355 | + * | |
19356 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19357 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 19358 | + */ |
19359 | + | |
19360 | +/* | |
4a4d8108 | 19361 | + * inode operations (del entry) |
1308ab2a | 19362 | + */ |
dece6358 | 19363 | + |
1308ab2a | 19364 | +#include "aufs.h" |
dece6358 | 19365 | + |
4a4d8108 AM |
19366 | +/* |
19367 | + * decide if a new whiteout for @dentry is necessary or not. | |
19368 | + * when it is necessary, prepare the parent dir for the upper branch whose | |
19369 | + * branch index is @bcpup for creation. the actual creation of the whiteout will | |
19370 | + * be done by caller. | |
19371 | + * return value: | |
19372 | + * 0: wh is unnecessary | |
19373 | + * plus: wh is necessary | |
19374 | + * minus: error | |
19375 | + */ | |
19376 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup) | |
1308ab2a | 19377 | +{ |
4a4d8108 AM |
19378 | + int need_wh, err; |
19379 | + aufs_bindex_t bstart; | |
19380 | + struct super_block *sb; | |
dece6358 | 19381 | + |
4a4d8108 AM |
19382 | + sb = dentry->d_sb; |
19383 | + bstart = au_dbstart(dentry); | |
19384 | + if (*bcpup < 0) { | |
19385 | + *bcpup = bstart; | |
19386 | + if (au_test_ro(sb, bstart, dentry->d_inode)) { | |
19387 | + err = AuWbrCopyup(au_sbi(sb), dentry); | |
19388 | + *bcpup = err; | |
19389 | + if (unlikely(err < 0)) | |
19390 | + goto out; | |
19391 | + } | |
19392 | + } else | |
19393 | + AuDebugOn(bstart < *bcpup | |
19394 | + || au_test_ro(sb, *bcpup, dentry->d_inode)); | |
19395 | + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart); | |
1308ab2a | 19396 | + |
4a4d8108 AM |
19397 | + if (*bcpup != bstart) { |
19398 | + err = au_cpup_dirs(dentry, *bcpup); | |
19399 | + if (unlikely(err)) | |
19400 | + goto out; | |
19401 | + need_wh = 1; | |
19402 | + } else { | |
027c5e7a | 19403 | + struct au_dinfo *dinfo, *tmp; |
4a4d8108 | 19404 | + |
027c5e7a AM |
19405 | + need_wh = -ENOMEM; |
19406 | + dinfo = au_di(dentry); | |
19407 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
19408 | + if (tmp) { | |
19409 | + au_di_cp(tmp, dinfo); | |
19410 | + au_di_swap(tmp, dinfo); | |
19411 | + /* returns the number of positive dentries */ | |
537831f9 | 19412 | + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0); |
027c5e7a AM |
19413 | + au_di_swap(tmp, dinfo); |
19414 | + au_rw_write_unlock(&tmp->di_rwsem); | |
19415 | + au_di_free(tmp); | |
4a4d8108 AM |
19416 | + } |
19417 | + } | |
19418 | + AuDbg("need_wh %d\n", need_wh); | |
19419 | + err = need_wh; | |
19420 | + | |
4f0767ce | 19421 | +out: |
4a4d8108 | 19422 | + return err; |
1facf9fc | 19423 | +} |
19424 | + | |
4a4d8108 AM |
19425 | +/* |
19426 | + * simple tests for the del-entry operations. | |
19427 | + * following the checks in vfs, plus the parent-child relationship. | |
19428 | + */ | |
19429 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
19430 | + struct dentry *h_parent, int isdir) | |
1facf9fc | 19431 | +{ |
4a4d8108 AM |
19432 | + int err; |
19433 | + umode_t h_mode; | |
19434 | + struct dentry *h_dentry, *h_latest; | |
1308ab2a | 19435 | + struct inode *h_inode; |
1facf9fc | 19436 | + |
4a4d8108 AM |
19437 | + h_dentry = au_h_dptr(dentry, bindex); |
19438 | + h_inode = h_dentry->d_inode; | |
19439 | + if (dentry->d_inode) { | |
19440 | + err = -ENOENT; | |
19441 | + if (unlikely(!h_inode || !h_inode->i_nlink)) | |
19442 | + goto out; | |
1facf9fc | 19443 | + |
4a4d8108 AM |
19444 | + h_mode = h_inode->i_mode; |
19445 | + if (!isdir) { | |
19446 | + err = -EISDIR; | |
19447 | + if (unlikely(S_ISDIR(h_mode))) | |
19448 | + goto out; | |
19449 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
19450 | + err = -ENOTDIR; | |
19451 | + goto out; | |
19452 | + } | |
19453 | + } else { | |
19454 | + /* rename(2) case */ | |
19455 | + err = -EIO; | |
19456 | + if (unlikely(h_inode)) | |
19457 | + goto out; | |
19458 | + } | |
1facf9fc | 19459 | + |
4a4d8108 AM |
19460 | + err = -ENOENT; |
19461 | + /* expected parent dir is locked */ | |
19462 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
19463 | + goto out; | |
19464 | + err = 0; | |
19465 | + | |
19466 | + /* | |
19467 | + * rmdir a dir may break the consistency on some filesystem. | |
19468 | + * let's try heavy test. | |
19469 | + */ | |
19470 | + err = -EACCES; | |
076b876e AM |
19471 | + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1) |
19472 | + && au_test_h_perm(h_parent->d_inode, | |
19473 | + MAY_EXEC | MAY_WRITE))) | |
4a4d8108 AM |
19474 | + goto out; |
19475 | + | |
076b876e | 19476 | + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent); |
4a4d8108 AM |
19477 | + err = -EIO; |
19478 | + if (IS_ERR(h_latest)) | |
19479 | + goto out; | |
19480 | + if (h_latest == h_dentry) | |
19481 | + err = 0; | |
19482 | + dput(h_latest); | |
19483 | + | |
4f0767ce | 19484 | +out: |
4a4d8108 | 19485 | + return err; |
1308ab2a | 19486 | +} |
1facf9fc | 19487 | + |
4a4d8108 AM |
19488 | +/* |
19489 | + * decide the branch where we operate for @dentry. the branch index will be set | |
19490 | + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent | |
19491 | + * dir for reverting. | |
19492 | + * when a new whiteout is necessary, create it. | |
19493 | + */ | |
19494 | +static struct dentry* | |
19495 | +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup, | |
19496 | + struct au_dtime *dt, struct au_pin *pin) | |
1308ab2a | 19497 | +{ |
4a4d8108 AM |
19498 | + struct dentry *wh_dentry; |
19499 | + struct super_block *sb; | |
19500 | + struct path h_path; | |
19501 | + int err, need_wh; | |
19502 | + unsigned int udba; | |
19503 | + aufs_bindex_t bcpup; | |
dece6358 | 19504 | + |
4a4d8108 AM |
19505 | + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup); |
19506 | + wh_dentry = ERR_PTR(need_wh); | |
19507 | + if (unlikely(need_wh < 0)) | |
19508 | + goto out; | |
19509 | + | |
19510 | + sb = dentry->d_sb; | |
19511 | + udba = au_opt_udba(sb); | |
19512 | + bcpup = *rbcpup; | |
19513 | + err = au_pin(pin, dentry, bcpup, udba, | |
19514 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
19515 | + wh_dentry = ERR_PTR(err); | |
19516 | + if (unlikely(err)) | |
19517 | + goto out; | |
19518 | + | |
19519 | + h_path.dentry = au_pinned_h_parent(pin); | |
19520 | + if (udba != AuOpt_UDBA_NONE | |
19521 | + && au_dbstart(dentry) == bcpup) { | |
19522 | + err = au_may_del(dentry, bcpup, h_path.dentry, isdir); | |
19523 | + wh_dentry = ERR_PTR(err); | |
19524 | + if (unlikely(err)) | |
19525 | + goto out_unpin; | |
19526 | + } | |
19527 | + | |
19528 | + h_path.mnt = au_sbr_mnt(sb, bcpup); | |
19529 | + au_dtime_store(dt, au_pinned_parent(pin), &h_path); | |
19530 | + wh_dentry = NULL; | |
19531 | + if (!need_wh) | |
19532 | + goto out; /* success, no need to create whiteout */ | |
19533 | + | |
19534 | + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry); | |
19535 | + if (IS_ERR(wh_dentry)) | |
19536 | + goto out_unpin; | |
19537 | + | |
19538 | + /* returns with the parent is locked and wh_dentry is dget-ed */ | |
19539 | + goto out; /* success */ | |
19540 | + | |
4f0767ce | 19541 | +out_unpin: |
4a4d8108 | 19542 | + au_unpin(pin); |
4f0767ce | 19543 | +out: |
4a4d8108 | 19544 | + return wh_dentry; |
1facf9fc | 19545 | +} |
19546 | + | |
4a4d8108 AM |
19547 | +/* |
19548 | + * when removing a dir, rename it to a unique temporary whiteout-ed name first | |
19549 | + * in order to be revertible and save time for removing many child whiteouts | |
19550 | + * under the dir. | |
19551 | + * returns 1 when there are too many child whiteout and caller should remove | |
19552 | + * them asynchronously. returns 0 when the number of children is enough small to | |
19553 | + * remove now or the branch fs is a remote fs. | |
19554 | + * otherwise return an error. | |
19555 | + */ | |
19556 | +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex, | |
19557 | + struct au_nhash *whlist, struct inode *dir) | |
1facf9fc | 19558 | +{ |
4a4d8108 AM |
19559 | + int rmdir_later, err, dirwh; |
19560 | + struct dentry *h_dentry; | |
19561 | + struct super_block *sb; | |
19562 | + | |
19563 | + sb = dentry->d_sb; | |
19564 | + SiMustAnyLock(sb); | |
19565 | + h_dentry = au_h_dptr(dentry, bindex); | |
19566 | + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex)); | |
19567 | + if (unlikely(err)) | |
19568 | + goto out; | |
19569 | + | |
19570 | + /* stop monitoring */ | |
19571 | + au_hn_free(au_hi(dentry->d_inode, bindex)); | |
19572 | + | |
19573 | + if (!au_test_fs_remote(h_dentry->d_sb)) { | |
19574 | + dirwh = au_sbi(sb)->si_dirwh; | |
19575 | + rmdir_later = (dirwh <= 1); | |
19576 | + if (!rmdir_later) | |
19577 | + rmdir_later = au_nhash_test_longer_wh(whlist, bindex, | |
19578 | + dirwh); | |
19579 | + if (rmdir_later) | |
19580 | + return rmdir_later; | |
19581 | + } | |
1facf9fc | 19582 | + |
4a4d8108 AM |
19583 | + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist); |
19584 | + if (unlikely(err)) { | |
523b37e3 AM |
19585 | + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n", |
19586 | + h_dentry, bindex, err); | |
4a4d8108 AM |
19587 | + err = 0; |
19588 | + } | |
dece6358 | 19589 | + |
4f0767ce | 19590 | +out: |
4a4d8108 AM |
19591 | + AuTraceErr(err); |
19592 | + return err; | |
19593 | +} | |
1308ab2a | 19594 | + |
4a4d8108 AM |
19595 | +/* |
19596 | + * final procedure for deleting a entry. | |
19597 | + * maintain dentry and iattr. | |
19598 | + */ | |
19599 | +static void epilog(struct inode *dir, struct dentry *dentry, | |
19600 | + aufs_bindex_t bindex) | |
19601 | +{ | |
19602 | + struct inode *inode; | |
1308ab2a | 19603 | + |
4a4d8108 AM |
19604 | + inode = dentry->d_inode; |
19605 | + d_drop(dentry); | |
19606 | + inode->i_ctime = dir->i_ctime; | |
1308ab2a | 19607 | + |
4a4d8108 AM |
19608 | + if (au_ibstart(dir) == bindex) |
19609 | + au_cpup_attr_timesizes(dir); | |
19610 | + dir->i_version++; | |
1facf9fc | 19611 | +} |
19612 | + | |
4a4d8108 AM |
19613 | +/* |
19614 | + * when an error happened, remove the created whiteout and revert everything. | |
19615 | + */ | |
7f207e10 AM |
19616 | +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex, |
19617 | + aufs_bindex_t bwh, struct dentry *wh_dentry, | |
19618 | + struct dentry *dentry, struct au_dtime *dt) | |
1facf9fc | 19619 | +{ |
4a4d8108 AM |
19620 | + int rerr; |
19621 | + struct path h_path = { | |
19622 | + .dentry = wh_dentry, | |
7f207e10 | 19623 | + .mnt = au_sbr_mnt(dir->i_sb, bindex) |
4a4d8108 | 19624 | + }; |
dece6358 | 19625 | + |
7f207e10 | 19626 | + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry); |
4a4d8108 AM |
19627 | + if (!rerr) { |
19628 | + au_set_dbwh(dentry, bwh); | |
19629 | + au_dtime_revert(dt); | |
19630 | + return 0; | |
19631 | + } | |
dece6358 | 19632 | + |
523b37e3 | 19633 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr); |
4a4d8108 | 19634 | + return -EIO; |
1facf9fc | 19635 | +} |
19636 | + | |
4a4d8108 | 19637 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19638 | + |
4a4d8108 | 19639 | +int aufs_unlink(struct inode *dir, struct dentry *dentry) |
1308ab2a | 19640 | +{ |
4a4d8108 AM |
19641 | + int err; |
19642 | + aufs_bindex_t bwh, bindex, bstart; | |
523b37e3 | 19643 | + struct inode *inode, *h_dir, *delegated; |
4a4d8108 | 19644 | + struct dentry *parent, *wh_dentry; |
c2b27bf2 AM |
19645 | + /* to reuduce stack size */ |
19646 | + struct { | |
19647 | + struct au_dtime dt; | |
19648 | + struct au_pin pin; | |
19649 | + struct path h_path; | |
19650 | + } *a; | |
1facf9fc | 19651 | + |
4a4d8108 | 19652 | + IMustLock(dir); |
027c5e7a | 19653 | + |
c2b27bf2 AM |
19654 | + err = -ENOMEM; |
19655 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19656 | + if (unlikely(!a)) | |
19657 | + goto out; | |
19658 | + | |
027c5e7a AM |
19659 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
19660 | + if (unlikely(err)) | |
c2b27bf2 | 19661 | + goto out_free; |
027c5e7a AM |
19662 | + err = au_d_hashed_positive(dentry); |
19663 | + if (unlikely(err)) | |
19664 | + goto out_unlock; | |
4a4d8108 | 19665 | + inode = dentry->d_inode; |
4a4d8108 | 19666 | + IMustLock(inode); |
027c5e7a AM |
19667 | + err = -EISDIR; |
19668 | + if (unlikely(S_ISDIR(inode->i_mode))) | |
19669 | + goto out_unlock; /* possible? */ | |
1facf9fc | 19670 | + |
4a4d8108 AM |
19671 | + bstart = au_dbstart(dentry); |
19672 | + bwh = au_dbwh(dentry); | |
19673 | + bindex = -1; | |
027c5e7a AM |
19674 | + parent = dentry->d_parent; /* dir inode is locked */ |
19675 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
19676 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt, |
19677 | + &a->pin); | |
4a4d8108 AM |
19678 | + err = PTR_ERR(wh_dentry); |
19679 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 19680 | + goto out_parent; |
1facf9fc | 19681 | + |
c2b27bf2 AM |
19682 | + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart); |
19683 | + a->h_path.dentry = au_h_dptr(dentry, bstart); | |
19684 | + dget(a->h_path.dentry); | |
4a4d8108 | 19685 | + if (bindex == bstart) { |
c2b27bf2 | 19686 | + h_dir = au_pinned_h_dir(&a->pin); |
523b37e3 AM |
19687 | + delegated = NULL; |
19688 | + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0); | |
19689 | + if (unlikely(err == -EWOULDBLOCK)) { | |
19690 | + pr_warn("cannot retry for NFSv4 delegation" | |
19691 | + " for an internal unlink\n"); | |
19692 | + iput(delegated); | |
19693 | + } | |
4a4d8108 AM |
19694 | + } else { |
19695 | + /* dir inode is locked */ | |
19696 | + h_dir = wh_dentry->d_parent->d_inode; | |
19697 | + IMustLock(h_dir); | |
19698 | + err = 0; | |
19699 | + } | |
dece6358 | 19700 | + |
4a4d8108 | 19701 | + if (!err) { |
7f207e10 | 19702 | + vfsub_drop_nlink(inode); |
4a4d8108 AM |
19703 | + epilog(dir, dentry, bindex); |
19704 | + | |
19705 | + /* update target timestamps */ | |
19706 | + if (bindex == bstart) { | |
c2b27bf2 AM |
19707 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); |
19708 | + /*ignore*/ | |
19709 | + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime; | |
4a4d8108 AM |
19710 | + } else |
19711 | + /* todo: this timestamp may be reverted later */ | |
19712 | + inode->i_ctime = h_dir->i_ctime; | |
027c5e7a | 19713 | + goto out_unpin; /* success */ |
1facf9fc | 19714 | + } |
19715 | + | |
4a4d8108 AM |
19716 | + /* revert */ |
19717 | + if (wh_dentry) { | |
19718 | + int rerr; | |
19719 | + | |
c2b27bf2 AM |
19720 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
19721 | + &a->dt); | |
4a4d8108 AM |
19722 | + if (rerr) |
19723 | + err = rerr; | |
dece6358 | 19724 | + } |
1facf9fc | 19725 | + |
027c5e7a | 19726 | +out_unpin: |
c2b27bf2 | 19727 | + au_unpin(&a->pin); |
4a4d8108 | 19728 | + dput(wh_dentry); |
c2b27bf2 | 19729 | + dput(a->h_path.dentry); |
027c5e7a | 19730 | +out_parent: |
4a4d8108 | 19731 | + di_write_unlock(parent); |
027c5e7a | 19732 | +out_unlock: |
4a4d8108 | 19733 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 AM |
19734 | +out_free: |
19735 | + kfree(a); | |
027c5e7a | 19736 | +out: |
4a4d8108 | 19737 | + return err; |
dece6358 AM |
19738 | +} |
19739 | + | |
4a4d8108 | 19740 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry) |
1308ab2a | 19741 | +{ |
4a4d8108 AM |
19742 | + int err, rmdir_later; |
19743 | + aufs_bindex_t bwh, bindex, bstart; | |
4a4d8108 AM |
19744 | + struct inode *inode; |
19745 | + struct dentry *parent, *wh_dentry, *h_dentry; | |
19746 | + struct au_whtmp_rmdir *args; | |
c2b27bf2 AM |
19747 | + /* to reuduce stack size */ |
19748 | + struct { | |
19749 | + struct au_dtime dt; | |
19750 | + struct au_pin pin; | |
19751 | + } *a; | |
1facf9fc | 19752 | + |
4a4d8108 | 19753 | + IMustLock(dir); |
027c5e7a | 19754 | + |
c2b27bf2 AM |
19755 | + err = -ENOMEM; |
19756 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19757 | + if (unlikely(!a)) | |
19758 | + goto out; | |
19759 | + | |
027c5e7a AM |
19760 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); |
19761 | + if (unlikely(err)) | |
c2b27bf2 | 19762 | + goto out_free; |
53392da6 AM |
19763 | + err = au_alive_dir(dentry); |
19764 | + if (unlikely(err)) | |
027c5e7a | 19765 | + goto out_unlock; |
53392da6 | 19766 | + inode = dentry->d_inode; |
4a4d8108 | 19767 | + IMustLock(inode); |
027c5e7a AM |
19768 | + err = -ENOTDIR; |
19769 | + if (unlikely(!S_ISDIR(inode->i_mode))) | |
19770 | + goto out_unlock; /* possible? */ | |
dece6358 | 19771 | + |
4a4d8108 AM |
19772 | + err = -ENOMEM; |
19773 | + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS); | |
19774 | + if (unlikely(!args)) | |
19775 | + goto out_unlock; | |
dece6358 | 19776 | + |
4a4d8108 AM |
19777 | + parent = dentry->d_parent; /* dir inode is locked */ |
19778 | + di_write_lock_parent(parent); | |
19779 | + err = au_test_empty(dentry, &args->whlist); | |
19780 | + if (unlikely(err)) | |
027c5e7a | 19781 | + goto out_parent; |
1facf9fc | 19782 | + |
4a4d8108 AM |
19783 | + bstart = au_dbstart(dentry); |
19784 | + bwh = au_dbwh(dentry); | |
19785 | + bindex = -1; | |
c2b27bf2 AM |
19786 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt, |
19787 | + &a->pin); | |
4a4d8108 AM |
19788 | + err = PTR_ERR(wh_dentry); |
19789 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 19790 | + goto out_parent; |
1facf9fc | 19791 | + |
4a4d8108 AM |
19792 | + h_dentry = au_h_dptr(dentry, bstart); |
19793 | + dget(h_dentry); | |
19794 | + rmdir_later = 0; | |
19795 | + if (bindex == bstart) { | |
19796 | + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir); | |
19797 | + if (err > 0) { | |
19798 | + rmdir_later = err; | |
19799 | + err = 0; | |
19800 | + } | |
19801 | + } else { | |
19802 | + /* stop monitoring */ | |
19803 | + au_hn_free(au_hi(inode, bstart)); | |
19804 | + | |
19805 | + /* dir inode is locked */ | |
19806 | + IMustLock(wh_dentry->d_parent->d_inode); | |
1facf9fc | 19807 | + err = 0; |
19808 | + } | |
19809 | + | |
4a4d8108 | 19810 | + if (!err) { |
027c5e7a | 19811 | + vfsub_dead_dir(inode); |
4a4d8108 AM |
19812 | + au_set_dbdiropq(dentry, -1); |
19813 | + epilog(dir, dentry, bindex); | |
1308ab2a | 19814 | + |
4a4d8108 AM |
19815 | + if (rmdir_later) { |
19816 | + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args); | |
19817 | + args = NULL; | |
19818 | + } | |
1308ab2a | 19819 | + |
4a4d8108 | 19820 | + goto out_unpin; /* success */ |
1facf9fc | 19821 | + } |
19822 | + | |
4a4d8108 AM |
19823 | + /* revert */ |
19824 | + AuLabel(revert); | |
19825 | + if (wh_dentry) { | |
19826 | + int rerr; | |
1308ab2a | 19827 | + |
c2b27bf2 AM |
19828 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
19829 | + &a->dt); | |
4a4d8108 AM |
19830 | + if (rerr) |
19831 | + err = rerr; | |
1facf9fc | 19832 | + } |
19833 | + | |
4f0767ce | 19834 | +out_unpin: |
c2b27bf2 | 19835 | + au_unpin(&a->pin); |
4a4d8108 AM |
19836 | + dput(wh_dentry); |
19837 | + dput(h_dentry); | |
027c5e7a | 19838 | +out_parent: |
4a4d8108 AM |
19839 | + di_write_unlock(parent); |
19840 | + if (args) | |
19841 | + au_whtmp_rmdir_free(args); | |
4f0767ce | 19842 | +out_unlock: |
4a4d8108 | 19843 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 AM |
19844 | +out_free: |
19845 | + kfree(a); | |
4f0767ce | 19846 | +out: |
4a4d8108 AM |
19847 | + AuTraceErr(err); |
19848 | + return err; | |
dece6358 | 19849 | +} |
7f207e10 AM |
19850 | diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c |
19851 | --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 19852 | +++ linux/fs/aufs/i_op_ren.c 2015-01-25 13:00:38.631047076 +0100 |
076b876e | 19853 | @@ -0,0 +1,1034 @@ |
1facf9fc | 19854 | +/* |
523b37e3 | 19855 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 19856 | + * |
19857 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19858 | + * it under the terms of the GNU General Public License as published by | |
19859 | + * the Free Software Foundation; either version 2 of the License, or | |
19860 | + * (at your option) any later version. | |
dece6358 AM |
19861 | + * |
19862 | + * This program is distributed in the hope that it will be useful, | |
19863 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19864 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19865 | + * GNU General Public License for more details. | |
19866 | + * | |
19867 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19868 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 19869 | + */ |
19870 | + | |
19871 | +/* | |
4a4d8108 AM |
19872 | + * inode operation (rename entry) |
19873 | + * todo: this is crazy monster | |
1facf9fc | 19874 | + */ |
19875 | + | |
19876 | +#include "aufs.h" | |
19877 | + | |
4a4d8108 AM |
19878 | +enum { AuSRC, AuDST, AuSrcDst }; |
19879 | +enum { AuPARENT, AuCHILD, AuParentChild }; | |
1facf9fc | 19880 | + |
4a4d8108 AM |
19881 | +#define AuRen_ISDIR 1 |
19882 | +#define AuRen_ISSAMEDIR (1 << 1) | |
19883 | +#define AuRen_WHSRC (1 << 2) | |
19884 | +#define AuRen_WHDST (1 << 3) | |
19885 | +#define AuRen_MNT_WRITE (1 << 4) | |
19886 | +#define AuRen_DT_DSTDIR (1 << 5) | |
19887 | +#define AuRen_DIROPQ (1 << 6) | |
19888 | +#define AuRen_CPUP (1 << 7) | |
19889 | +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name) | |
7f207e10 AM |
19890 | +#define au_fset_ren(flags, name) \ |
19891 | + do { (flags) |= AuRen_##name; } while (0) | |
19892 | +#define au_fclr_ren(flags, name) \ | |
19893 | + do { (flags) &= ~AuRen_##name; } while (0) | |
1facf9fc | 19894 | + |
4a4d8108 AM |
19895 | +struct au_ren_args { |
19896 | + struct { | |
19897 | + struct dentry *dentry, *h_dentry, *parent, *h_parent, | |
19898 | + *wh_dentry; | |
19899 | + struct inode *dir, *inode; | |
19900 | + struct au_hinode *hdir; | |
19901 | + struct au_dtime dt[AuParentChild]; | |
19902 | + aufs_bindex_t bstart; | |
19903 | + } sd[AuSrcDst]; | |
1facf9fc | 19904 | + |
4a4d8108 AM |
19905 | +#define src_dentry sd[AuSRC].dentry |
19906 | +#define src_dir sd[AuSRC].dir | |
19907 | +#define src_inode sd[AuSRC].inode | |
19908 | +#define src_h_dentry sd[AuSRC].h_dentry | |
19909 | +#define src_parent sd[AuSRC].parent | |
19910 | +#define src_h_parent sd[AuSRC].h_parent | |
19911 | +#define src_wh_dentry sd[AuSRC].wh_dentry | |
19912 | +#define src_hdir sd[AuSRC].hdir | |
19913 | +#define src_h_dir sd[AuSRC].hdir->hi_inode | |
19914 | +#define src_dt sd[AuSRC].dt | |
19915 | +#define src_bstart sd[AuSRC].bstart | |
1facf9fc | 19916 | + |
4a4d8108 AM |
19917 | +#define dst_dentry sd[AuDST].dentry |
19918 | +#define dst_dir sd[AuDST].dir | |
19919 | +#define dst_inode sd[AuDST].inode | |
19920 | +#define dst_h_dentry sd[AuDST].h_dentry | |
19921 | +#define dst_parent sd[AuDST].parent | |
19922 | +#define dst_h_parent sd[AuDST].h_parent | |
19923 | +#define dst_wh_dentry sd[AuDST].wh_dentry | |
19924 | +#define dst_hdir sd[AuDST].hdir | |
19925 | +#define dst_h_dir sd[AuDST].hdir->hi_inode | |
19926 | +#define dst_dt sd[AuDST].dt | |
19927 | +#define dst_bstart sd[AuDST].bstart | |
19928 | + | |
19929 | + struct dentry *h_trap; | |
19930 | + struct au_branch *br; | |
19931 | + struct au_hinode *src_hinode; | |
19932 | + struct path h_path; | |
19933 | + struct au_nhash whlist; | |
027c5e7a | 19934 | + aufs_bindex_t btgt, src_bwh, src_bdiropq; |
1facf9fc | 19935 | + |
1308ab2a | 19936 | + unsigned int flags; |
1facf9fc | 19937 | + |
4a4d8108 AM |
19938 | + struct au_whtmp_rmdir *thargs; |
19939 | + struct dentry *h_dst; | |
19940 | +}; | |
1308ab2a | 19941 | + |
4a4d8108 | 19942 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19943 | + |
4a4d8108 AM |
19944 | +/* |
19945 | + * functions for reverting. | |
19946 | + * when an error happened in a single rename systemcall, we should revert | |
19947 | + * everything as if nothing happend. | |
19948 | + * we don't need to revert the copied-up/down the parent dir since they are | |
19949 | + * harmless. | |
19950 | + */ | |
1facf9fc | 19951 | + |
4a4d8108 AM |
19952 | +#define RevertFailure(fmt, ...) do { \ |
19953 | + AuIOErr("revert failure: " fmt " (%d, %d)\n", \ | |
19954 | + ##__VA_ARGS__, err, rerr); \ | |
19955 | + err = -EIO; \ | |
19956 | +} while (0) | |
1facf9fc | 19957 | + |
4a4d8108 | 19958 | +static void au_ren_rev_diropq(int err, struct au_ren_args *a) |
1facf9fc | 19959 | +{ |
4a4d8108 | 19960 | + int rerr; |
1facf9fc | 19961 | + |
4a4d8108 AM |
19962 | + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD); |
19963 | + rerr = au_diropq_remove(a->src_dentry, a->btgt); | |
19964 | + au_hn_imtx_unlock(a->src_hinode); | |
027c5e7a | 19965 | + au_set_dbdiropq(a->src_dentry, a->src_bdiropq); |
4a4d8108 | 19966 | + if (rerr) |
523b37e3 | 19967 | + RevertFailure("remove diropq %pd", a->src_dentry); |
4a4d8108 | 19968 | +} |
1facf9fc | 19969 | + |
4a4d8108 AM |
19970 | +static void au_ren_rev_rename(int err, struct au_ren_args *a) |
19971 | +{ | |
19972 | + int rerr; | |
523b37e3 | 19973 | + struct inode *delegated; |
1facf9fc | 19974 | + |
b4510431 AM |
19975 | + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, |
19976 | + a->src_h_parent); | |
4a4d8108 AM |
19977 | + rerr = PTR_ERR(a->h_path.dentry); |
19978 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 19979 | + RevertFailure("lkup one %pd", a->src_dentry); |
4a4d8108 | 19980 | + return; |
1facf9fc | 19981 | + } |
19982 | + | |
523b37e3 | 19983 | + delegated = NULL; |
4a4d8108 AM |
19984 | + rerr = vfsub_rename(a->dst_h_dir, |
19985 | + au_h_dptr(a->src_dentry, a->btgt), | |
523b37e3 AM |
19986 | + a->src_h_dir, &a->h_path, &delegated); |
19987 | + if (unlikely(rerr == -EWOULDBLOCK)) { | |
19988 | + pr_warn("cannot retry for NFSv4 delegation" | |
19989 | + " for an internal rename\n"); | |
19990 | + iput(delegated); | |
19991 | + } | |
4a4d8108 AM |
19992 | + d_drop(a->h_path.dentry); |
19993 | + dput(a->h_path.dentry); | |
19994 | + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */ | |
19995 | + if (rerr) | |
523b37e3 | 19996 | + RevertFailure("rename %pd", a->src_dentry); |
1facf9fc | 19997 | +} |
19998 | + | |
4a4d8108 | 19999 | +static void au_ren_rev_cpup(int err, struct au_ren_args *a) |
1facf9fc | 20000 | +{ |
4a4d8108 | 20001 | + int rerr; |
1facf9fc | 20002 | + |
4a4d8108 | 20003 | + a->h_path.dentry = a->dst_h_dentry; |
523b37e3 AM |
20004 | + /* no delegation since it is just created */ |
20005 | + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL, | |
20006 | + /*force*/0); | |
4a4d8108 AM |
20007 | + au_set_h_dptr(a->src_dentry, a->btgt, NULL); |
20008 | + au_set_dbstart(a->src_dentry, a->src_bstart); | |
20009 | + if (rerr) | |
523b37e3 | 20010 | + RevertFailure("unlink %pd", a->dst_h_dentry); |
1facf9fc | 20011 | +} |
20012 | + | |
4a4d8108 | 20013 | +static void au_ren_rev_whtmp(int err, struct au_ren_args *a) |
1facf9fc | 20014 | +{ |
4a4d8108 | 20015 | + int rerr; |
523b37e3 | 20016 | + struct inode *delegated; |
dece6358 | 20017 | + |
b4510431 AM |
20018 | + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, |
20019 | + a->dst_h_parent); | |
4a4d8108 AM |
20020 | + rerr = PTR_ERR(a->h_path.dentry); |
20021 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 20022 | + RevertFailure("lkup one %pd", a->dst_dentry); |
4a4d8108 AM |
20023 | + return; |
20024 | + } | |
20025 | + if (a->h_path.dentry->d_inode) { | |
20026 | + d_drop(a->h_path.dentry); | |
20027 | + dput(a->h_path.dentry); | |
20028 | + return; | |
dece6358 AM |
20029 | + } |
20030 | + | |
523b37e3 AM |
20031 | + delegated = NULL; |
20032 | + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path, | |
20033 | + &delegated); | |
20034 | + if (unlikely(rerr == -EWOULDBLOCK)) { | |
20035 | + pr_warn("cannot retry for NFSv4 delegation" | |
20036 | + " for an internal rename\n"); | |
20037 | + iput(delegated); | |
20038 | + } | |
4a4d8108 AM |
20039 | + d_drop(a->h_path.dentry); |
20040 | + dput(a->h_path.dentry); | |
20041 | + if (!rerr) | |
20042 | + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst)); | |
20043 | + else | |
523b37e3 | 20044 | + RevertFailure("rename %pd", a->h_dst); |
4a4d8108 | 20045 | +} |
1308ab2a | 20046 | + |
4a4d8108 AM |
20047 | +static void au_ren_rev_whsrc(int err, struct au_ren_args *a) |
20048 | +{ | |
20049 | + int rerr; | |
1308ab2a | 20050 | + |
4a4d8108 AM |
20051 | + a->h_path.dentry = a->src_wh_dentry; |
20052 | + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry); | |
027c5e7a | 20053 | + au_set_dbwh(a->src_dentry, a->src_bwh); |
4a4d8108 | 20054 | + if (rerr) |
523b37e3 | 20055 | + RevertFailure("unlink %pd", a->src_wh_dentry); |
4a4d8108 | 20056 | +} |
4a4d8108 | 20057 | +#undef RevertFailure |
1facf9fc | 20058 | + |
1308ab2a | 20059 | +/* ---------------------------------------------------------------------- */ |
20060 | + | |
4a4d8108 AM |
20061 | +/* |
20062 | + * when we have to copyup the renaming entry, do it with the rename-target name | |
20063 | + * in order to minimize the cost (the later actual rename is unnecessary). | |
20064 | + * otherwise rename it on the target branch. | |
20065 | + */ | |
20066 | +static int au_ren_or_cpup(struct au_ren_args *a) | |
1facf9fc | 20067 | +{ |
dece6358 | 20068 | + int err; |
4a4d8108 | 20069 | + struct dentry *d; |
523b37e3 | 20070 | + struct inode *delegated; |
1facf9fc | 20071 | + |
4a4d8108 AM |
20072 | + d = a->src_dentry; |
20073 | + if (au_dbstart(d) == a->btgt) { | |
20074 | + a->h_path.dentry = a->dst_h_dentry; | |
20075 | + if (au_ftest_ren(a->flags, DIROPQ) | |
20076 | + && au_dbdiropq(d) == a->btgt) | |
20077 | + au_fclr_ren(a->flags, DIROPQ); | |
20078 | + AuDebugOn(au_dbstart(d) != a->btgt); | |
523b37e3 | 20079 | + delegated = NULL; |
4a4d8108 | 20080 | + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt), |
523b37e3 AM |
20081 | + a->dst_h_dir, &a->h_path, &delegated); |
20082 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20083 | + pr_warn("cannot retry for NFSv4 delegation" | |
20084 | + " for an internal rename\n"); | |
20085 | + iput(delegated); | |
20086 | + } | |
c2b27bf2 | 20087 | + } else |
86dc4139 | 20088 | + BUG(); |
1308ab2a | 20089 | + |
027c5e7a AM |
20090 | + if (!err && a->h_dst) |
20091 | + /* it will be set to dinfo later */ | |
20092 | + dget(a->h_dst); | |
1facf9fc | 20093 | + |
dece6358 AM |
20094 | + return err; |
20095 | +} | |
1facf9fc | 20096 | + |
4a4d8108 AM |
20097 | +/* cf. aufs_rmdir() */ |
20098 | +static int au_ren_del_whtmp(struct au_ren_args *a) | |
dece6358 | 20099 | +{ |
4a4d8108 AM |
20100 | + int err; |
20101 | + struct inode *dir; | |
1facf9fc | 20102 | + |
4a4d8108 AM |
20103 | + dir = a->dst_dir; |
20104 | + SiMustAnyLock(dir->i_sb); | |
20105 | + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt, | |
20106 | + au_sbi(dir->i_sb)->si_dirwh) | |
20107 | + || au_test_fs_remote(a->h_dst->d_sb)) { | |
20108 | + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist); | |
20109 | + if (unlikely(err)) | |
523b37e3 AM |
20110 | + pr_warn("failed removing whtmp dir %pd (%d), " |
20111 | + "ignored.\n", a->h_dst, err); | |
4a4d8108 AM |
20112 | + } else { |
20113 | + au_nhash_wh_free(&a->thargs->whlist); | |
20114 | + a->thargs->whlist = a->whlist; | |
20115 | + a->whlist.nh_num = 0; | |
20116 | + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs); | |
20117 | + dput(a->h_dst); | |
20118 | + a->thargs = NULL; | |
20119 | + } | |
20120 | + | |
20121 | + return 0; | |
1308ab2a | 20122 | +} |
1facf9fc | 20123 | + |
4a4d8108 AM |
20124 | +/* make it 'opaque' dir. */ |
20125 | +static int au_ren_diropq(struct au_ren_args *a) | |
20126 | +{ | |
20127 | + int err; | |
20128 | + struct dentry *diropq; | |
1facf9fc | 20129 | + |
4a4d8108 | 20130 | + err = 0; |
027c5e7a | 20131 | + a->src_bdiropq = au_dbdiropq(a->src_dentry); |
4a4d8108 AM |
20132 | + a->src_hinode = au_hi(a->src_inode, a->btgt); |
20133 | + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD); | |
20134 | + diropq = au_diropq_create(a->src_dentry, a->btgt); | |
20135 | + au_hn_imtx_unlock(a->src_hinode); | |
20136 | + if (IS_ERR(diropq)) | |
20137 | + err = PTR_ERR(diropq); | |
076b876e AM |
20138 | + else |
20139 | + dput(diropq); | |
1facf9fc | 20140 | + |
4a4d8108 AM |
20141 | + return err; |
20142 | +} | |
1facf9fc | 20143 | + |
4a4d8108 AM |
20144 | +static int do_rename(struct au_ren_args *a) |
20145 | +{ | |
20146 | + int err; | |
20147 | + struct dentry *d, *h_d; | |
1facf9fc | 20148 | + |
4a4d8108 AM |
20149 | + /* prepare workqueue args for asynchronous rmdir */ |
20150 | + h_d = a->dst_h_dentry; | |
20151 | + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) { | |
20152 | + err = -ENOMEM; | |
20153 | + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS); | |
20154 | + if (unlikely(!a->thargs)) | |
20155 | + goto out; | |
20156 | + a->h_dst = dget(h_d); | |
20157 | + } | |
1facf9fc | 20158 | + |
4a4d8108 AM |
20159 | + /* create whiteout for src_dentry */ |
20160 | + if (au_ftest_ren(a->flags, WHSRC)) { | |
027c5e7a AM |
20161 | + a->src_bwh = au_dbwh(a->src_dentry); |
20162 | + AuDebugOn(a->src_bwh >= 0); | |
4a4d8108 AM |
20163 | + a->src_wh_dentry |
20164 | + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent); | |
20165 | + err = PTR_ERR(a->src_wh_dentry); | |
20166 | + if (IS_ERR(a->src_wh_dentry)) | |
20167 | + goto out_thargs; | |
20168 | + } | |
1facf9fc | 20169 | + |
4a4d8108 AM |
20170 | + /* lookup whiteout for dentry */ |
20171 | + if (au_ftest_ren(a->flags, WHDST)) { | |
20172 | + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name, | |
20173 | + a->br); | |
20174 | + err = PTR_ERR(h_d); | |
20175 | + if (IS_ERR(h_d)) | |
20176 | + goto out_whsrc; | |
20177 | + if (!h_d->d_inode) | |
20178 | + dput(h_d); | |
20179 | + else | |
20180 | + a->dst_wh_dentry = h_d; | |
20181 | + } | |
1facf9fc | 20182 | + |
4a4d8108 AM |
20183 | + /* rename dentry to tmpwh */ |
20184 | + if (a->thargs) { | |
20185 | + err = au_whtmp_ren(a->dst_h_dentry, a->br); | |
20186 | + if (unlikely(err)) | |
20187 | + goto out_whdst; | |
dece6358 | 20188 | + |
4a4d8108 AM |
20189 | + d = a->dst_dentry; |
20190 | + au_set_h_dptr(d, a->btgt, NULL); | |
86dc4139 | 20191 | + err = au_lkup_neg(d, a->btgt, /*wh*/0); |
4a4d8108 AM |
20192 | + if (unlikely(err)) |
20193 | + goto out_whtmp; | |
20194 | + a->dst_h_dentry = au_h_dptr(d, a->btgt); | |
20195 | + } | |
1facf9fc | 20196 | + |
c2b27bf2 | 20197 | + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt); |
1facf9fc | 20198 | + |
4a4d8108 AM |
20199 | + /* rename by vfs_rename or cpup */ |
20200 | + d = a->dst_dentry; | |
20201 | + if (au_ftest_ren(a->flags, ISDIR) | |
20202 | + && (a->dst_wh_dentry | |
20203 | + || au_dbdiropq(d) == a->btgt | |
20204 | + /* hide the lower to keep xino */ | |
20205 | + || a->btgt < au_dbend(d) | |
20206 | + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ))) | |
20207 | + au_fset_ren(a->flags, DIROPQ); | |
20208 | + err = au_ren_or_cpup(a); | |
20209 | + if (unlikely(err)) | |
20210 | + /* leave the copied-up one */ | |
20211 | + goto out_whtmp; | |
1308ab2a | 20212 | + |
4a4d8108 AM |
20213 | + /* make dir opaque */ |
20214 | + if (au_ftest_ren(a->flags, DIROPQ)) { | |
20215 | + err = au_ren_diropq(a); | |
20216 | + if (unlikely(err)) | |
20217 | + goto out_rename; | |
20218 | + } | |
1308ab2a | 20219 | + |
4a4d8108 AM |
20220 | + /* update target timestamps */ |
20221 | + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt); | |
20222 | + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt); | |
20223 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
20224 | + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime; | |
1facf9fc | 20225 | + |
4a4d8108 AM |
20226 | + /* remove whiteout for dentry */ |
20227 | + if (a->dst_wh_dentry) { | |
20228 | + a->h_path.dentry = a->dst_wh_dentry; | |
20229 | + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path, | |
20230 | + a->dst_dentry); | |
20231 | + if (unlikely(err)) | |
20232 | + goto out_diropq; | |
20233 | + } | |
1facf9fc | 20234 | + |
4a4d8108 AM |
20235 | + /* remove whtmp */ |
20236 | + if (a->thargs) | |
20237 | + au_ren_del_whtmp(a); /* ignore this error */ | |
1308ab2a | 20238 | + |
076b876e | 20239 | + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0); |
4a4d8108 AM |
20240 | + err = 0; |
20241 | + goto out_success; | |
20242 | + | |
4f0767ce | 20243 | +out_diropq: |
4a4d8108 AM |
20244 | + if (au_ftest_ren(a->flags, DIROPQ)) |
20245 | + au_ren_rev_diropq(err, a); | |
4f0767ce | 20246 | +out_rename: |
4a4d8108 AM |
20247 | + if (!au_ftest_ren(a->flags, CPUP)) |
20248 | + au_ren_rev_rename(err, a); | |
20249 | + else | |
20250 | + au_ren_rev_cpup(err, a); | |
027c5e7a | 20251 | + dput(a->h_dst); |
4f0767ce | 20252 | +out_whtmp: |
4a4d8108 AM |
20253 | + if (a->thargs) |
20254 | + au_ren_rev_whtmp(err, a); | |
4f0767ce | 20255 | +out_whdst: |
4a4d8108 AM |
20256 | + dput(a->dst_wh_dentry); |
20257 | + a->dst_wh_dentry = NULL; | |
4f0767ce | 20258 | +out_whsrc: |
4a4d8108 AM |
20259 | + if (a->src_wh_dentry) |
20260 | + au_ren_rev_whsrc(err, a); | |
4f0767ce | 20261 | +out_success: |
4a4d8108 AM |
20262 | + dput(a->src_wh_dentry); |
20263 | + dput(a->dst_wh_dentry); | |
4f0767ce | 20264 | +out_thargs: |
4a4d8108 AM |
20265 | + if (a->thargs) { |
20266 | + dput(a->h_dst); | |
20267 | + au_whtmp_rmdir_free(a->thargs); | |
20268 | + a->thargs = NULL; | |
20269 | + } | |
4f0767ce | 20270 | +out: |
4a4d8108 | 20271 | + return err; |
dece6358 | 20272 | +} |
1facf9fc | 20273 | + |
1308ab2a | 20274 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20275 | + |
4a4d8108 AM |
20276 | +/* |
20277 | + * test if @dentry dir can be rename destination or not. | |
20278 | + * success means, it is a logically empty dir. | |
20279 | + */ | |
20280 | +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist) | |
1308ab2a | 20281 | +{ |
4a4d8108 | 20282 | + return au_test_empty(dentry, whlist); |
1308ab2a | 20283 | +} |
1facf9fc | 20284 | + |
4a4d8108 AM |
20285 | +/* |
20286 | + * test if @dentry dir can be rename source or not. | |
20287 | + * if it can, return 0 and @children is filled. | |
20288 | + * success means, | |
20289 | + * - it is a logically empty dir. | |
20290 | + * - or, it exists on writable branch and has no children including whiteouts | |
20291 | + * on the lower branch. | |
20292 | + */ | |
20293 | +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt) | |
20294 | +{ | |
20295 | + int err; | |
20296 | + unsigned int rdhash; | |
20297 | + aufs_bindex_t bstart; | |
1facf9fc | 20298 | + |
4a4d8108 AM |
20299 | + bstart = au_dbstart(dentry); |
20300 | + if (bstart != btgt) { | |
20301 | + struct au_nhash whlist; | |
dece6358 | 20302 | + |
4a4d8108 AM |
20303 | + SiMustAnyLock(dentry->d_sb); |
20304 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; | |
20305 | + if (!rdhash) | |
20306 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, | |
20307 | + dentry)); | |
20308 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
20309 | + if (unlikely(err)) | |
20310 | + goto out; | |
20311 | + err = au_test_empty(dentry, &whlist); | |
20312 | + au_nhash_wh_free(&whlist); | |
20313 | + goto out; | |
20314 | + } | |
dece6358 | 20315 | + |
4a4d8108 AM |
20316 | + if (bstart == au_dbtaildir(dentry)) |
20317 | + return 0; /* success */ | |
dece6358 | 20318 | + |
4a4d8108 | 20319 | + err = au_test_empty_lower(dentry); |
1facf9fc | 20320 | + |
4f0767ce | 20321 | +out: |
4a4d8108 AM |
20322 | + if (err == -ENOTEMPTY) { |
20323 | + AuWarn1("renaming dir who has child(ren) on multiple branches," | |
20324 | + " is not supported\n"); | |
20325 | + err = -EXDEV; | |
20326 | + } | |
20327 | + return err; | |
20328 | +} | |
1308ab2a | 20329 | + |
4a4d8108 AM |
20330 | +/* side effect: sets whlist and h_dentry */ |
20331 | +static int au_ren_may_dir(struct au_ren_args *a) | |
1308ab2a | 20332 | +{ |
4a4d8108 AM |
20333 | + int err; |
20334 | + unsigned int rdhash; | |
20335 | + struct dentry *d; | |
1facf9fc | 20336 | + |
4a4d8108 AM |
20337 | + d = a->dst_dentry; |
20338 | + SiMustAnyLock(d->d_sb); | |
1facf9fc | 20339 | + |
4a4d8108 AM |
20340 | + err = 0; |
20341 | + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) { | |
20342 | + rdhash = au_sbi(d->d_sb)->si_rdhash; | |
20343 | + if (!rdhash) | |
20344 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d)); | |
20345 | + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS); | |
20346 | + if (unlikely(err)) | |
20347 | + goto out; | |
1308ab2a | 20348 | + |
4a4d8108 AM |
20349 | + au_set_dbstart(d, a->dst_bstart); |
20350 | + err = may_rename_dstdir(d, &a->whlist); | |
20351 | + au_set_dbstart(d, a->btgt); | |
20352 | + } | |
20353 | + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d)); | |
20354 | + if (unlikely(err)) | |
20355 | + goto out; | |
20356 | + | |
20357 | + d = a->src_dentry; | |
20358 | + a->src_h_dentry = au_h_dptr(d, au_dbstart(d)); | |
20359 | + if (au_ftest_ren(a->flags, ISDIR)) { | |
20360 | + err = may_rename_srcdir(d, a->btgt); | |
20361 | + if (unlikely(err)) { | |
20362 | + au_nhash_wh_free(&a->whlist); | |
20363 | + a->whlist.nh_num = 0; | |
20364 | + } | |
20365 | + } | |
4f0767ce | 20366 | +out: |
4a4d8108 | 20367 | + return err; |
1facf9fc | 20368 | +} |
20369 | + | |
4a4d8108 | 20370 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20371 | + |
4a4d8108 AM |
20372 | +/* |
20373 | + * simple tests for rename. | |
20374 | + * following the checks in vfs, plus the parent-child relationship. | |
20375 | + */ | |
20376 | +static int au_may_ren(struct au_ren_args *a) | |
20377 | +{ | |
20378 | + int err, isdir; | |
20379 | + struct inode *h_inode; | |
1facf9fc | 20380 | + |
4a4d8108 AM |
20381 | + if (a->src_bstart == a->btgt) { |
20382 | + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent, | |
20383 | + au_ftest_ren(a->flags, ISDIR)); | |
20384 | + if (unlikely(err)) | |
20385 | + goto out; | |
20386 | + err = -EINVAL; | |
20387 | + if (unlikely(a->src_h_dentry == a->h_trap)) | |
20388 | + goto out; | |
20389 | + } | |
1facf9fc | 20390 | + |
4a4d8108 AM |
20391 | + err = 0; |
20392 | + if (a->dst_bstart != a->btgt) | |
20393 | + goto out; | |
1facf9fc | 20394 | + |
027c5e7a AM |
20395 | + err = -ENOTEMPTY; |
20396 | + if (unlikely(a->dst_h_dentry == a->h_trap)) | |
20397 | + goto out; | |
20398 | + | |
4a4d8108 AM |
20399 | + err = -EIO; |
20400 | + h_inode = a->dst_h_dentry->d_inode; | |
20401 | + isdir = !!au_ftest_ren(a->flags, ISDIR); | |
20402 | + if (!a->dst_dentry->d_inode) { | |
20403 | + if (unlikely(h_inode)) | |
20404 | + goto out; | |
20405 | + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent, | |
20406 | + isdir); | |
20407 | + } else { | |
20408 | + if (unlikely(!h_inode || !h_inode->i_nlink)) | |
20409 | + goto out; | |
20410 | + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent, | |
20411 | + isdir); | |
20412 | + if (unlikely(err)) | |
20413 | + goto out; | |
4a4d8108 | 20414 | + } |
1facf9fc | 20415 | + |
4f0767ce | 20416 | +out: |
4a4d8108 AM |
20417 | + if (unlikely(err == -ENOENT || err == -EEXIST)) |
20418 | + err = -EIO; | |
20419 | + AuTraceErr(err); | |
20420 | + return err; | |
20421 | +} | |
1facf9fc | 20422 | + |
1308ab2a | 20423 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20424 | + |
4a4d8108 AM |
20425 | +/* |
20426 | + * locking order | |
20427 | + * (VFS) | |
20428 | + * - src_dir and dir by lock_rename() | |
20429 | + * - inode if exitsts | |
20430 | + * (aufs) | |
20431 | + * - lock all | |
20432 | + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls, | |
20433 | + * + si_read_lock | |
20434 | + * + di_write_lock2_child() | |
20435 | + * + di_write_lock_child() | |
20436 | + * + ii_write_lock_child() | |
20437 | + * + di_write_lock_child2() | |
20438 | + * + ii_write_lock_child2() | |
20439 | + * + src_parent and parent | |
20440 | + * + di_write_lock_parent() | |
20441 | + * + ii_write_lock_parent() | |
20442 | + * + di_write_lock_parent2() | |
20443 | + * + ii_write_lock_parent2() | |
20444 | + * + lower src_dir and dir by vfsub_lock_rename() | |
20445 | + * + verify the every relationships between child and parent. if any | |
20446 | + * of them failed, unlock all and return -EBUSY. | |
20447 | + */ | |
20448 | +static void au_ren_unlock(struct au_ren_args *a) | |
1308ab2a | 20449 | +{ |
4a4d8108 AM |
20450 | + vfsub_unlock_rename(a->src_h_parent, a->src_hdir, |
20451 | + a->dst_h_parent, a->dst_hdir); | |
86dc4139 AM |
20452 | + if (au_ftest_ren(a->flags, MNT_WRITE)) |
20453 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); | |
1308ab2a | 20454 | +} |
20455 | + | |
4a4d8108 | 20456 | +static int au_ren_lock(struct au_ren_args *a) |
1308ab2a | 20457 | +{ |
4a4d8108 AM |
20458 | + int err; |
20459 | + unsigned int udba; | |
1308ab2a | 20460 | + |
4a4d8108 AM |
20461 | + err = 0; |
20462 | + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt); | |
20463 | + a->src_hdir = au_hi(a->src_dir, a->btgt); | |
20464 | + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt); | |
20465 | + a->dst_hdir = au_hi(a->dst_dir, a->btgt); | |
86dc4139 AM |
20466 | + |
20467 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); | |
20468 | + if (unlikely(err)) | |
20469 | + goto out; | |
20470 | + au_fset_ren(a->flags, MNT_WRITE); | |
4a4d8108 AM |
20471 | + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir, |
20472 | + a->dst_h_parent, a->dst_hdir); | |
20473 | + udba = au_opt_udba(a->src_dentry->d_sb); | |
20474 | + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode | |
20475 | + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode)) | |
20476 | + err = au_busy_or_stale(); | |
20477 | + if (!err && au_dbstart(a->src_dentry) == a->btgt) | |
20478 | + err = au_h_verify(a->src_h_dentry, udba, | |
20479 | + a->src_h_parent->d_inode, a->src_h_parent, | |
20480 | + a->br); | |
20481 | + if (!err && au_dbstart(a->dst_dentry) == a->btgt) | |
20482 | + err = au_h_verify(a->dst_h_dentry, udba, | |
20483 | + a->dst_h_parent->d_inode, a->dst_h_parent, | |
20484 | + a->br); | |
86dc4139 | 20485 | + if (!err) |
4a4d8108 | 20486 | + goto out; /* success */ |
4a4d8108 AM |
20487 | + |
20488 | + err = au_busy_or_stale(); | |
4a4d8108 | 20489 | + au_ren_unlock(a); |
86dc4139 | 20490 | + |
4f0767ce | 20491 | +out: |
4a4d8108 | 20492 | + return err; |
1facf9fc | 20493 | +} |
20494 | + | |
20495 | +/* ---------------------------------------------------------------------- */ | |
20496 | + | |
4a4d8108 | 20497 | +static void au_ren_refresh_dir(struct au_ren_args *a) |
1facf9fc | 20498 | +{ |
4a4d8108 | 20499 | + struct inode *dir; |
dece6358 | 20500 | + |
4a4d8108 AM |
20501 | + dir = a->dst_dir; |
20502 | + dir->i_version++; | |
20503 | + if (au_ftest_ren(a->flags, ISDIR)) { | |
20504 | + /* is this updating defined in POSIX? */ | |
20505 | + au_cpup_attr_timesizes(a->src_inode); | |
20506 | + au_cpup_attr_nlink(dir, /*force*/1); | |
4a4d8108 | 20507 | + } |
027c5e7a | 20508 | + |
4a4d8108 AM |
20509 | + if (au_ibstart(dir) == a->btgt) |
20510 | + au_cpup_attr_timesizes(dir); | |
dece6358 | 20511 | + |
4a4d8108 AM |
20512 | + if (au_ftest_ren(a->flags, ISSAMEDIR)) |
20513 | + return; | |
dece6358 | 20514 | + |
4a4d8108 AM |
20515 | + dir = a->src_dir; |
20516 | + dir->i_version++; | |
20517 | + if (au_ftest_ren(a->flags, ISDIR)) | |
20518 | + au_cpup_attr_nlink(dir, /*force*/1); | |
20519 | + if (au_ibstart(dir) == a->btgt) | |
20520 | + au_cpup_attr_timesizes(dir); | |
1facf9fc | 20521 | +} |
20522 | + | |
4a4d8108 | 20523 | +static void au_ren_refresh(struct au_ren_args *a) |
1facf9fc | 20524 | +{ |
4a4d8108 AM |
20525 | + aufs_bindex_t bend, bindex; |
20526 | + struct dentry *d, *h_d; | |
20527 | + struct inode *i, *h_i; | |
20528 | + struct super_block *sb; | |
dece6358 | 20529 | + |
027c5e7a AM |
20530 | + d = a->dst_dentry; |
20531 | + d_drop(d); | |
20532 | + if (a->h_dst) | |
20533 | + /* already dget-ed by au_ren_or_cpup() */ | |
20534 | + au_set_h_dptr(d, a->btgt, a->h_dst); | |
20535 | + | |
20536 | + i = a->dst_inode; | |
20537 | + if (i) { | |
20538 | + if (!au_ftest_ren(a->flags, ISDIR)) | |
20539 | + vfsub_drop_nlink(i); | |
20540 | + else { | |
20541 | + vfsub_dead_dir(i); | |
20542 | + au_cpup_attr_timesizes(i); | |
20543 | + } | |
20544 | + au_update_dbrange(d, /*do_put_zero*/1); | |
20545 | + } else { | |
20546 | + bend = a->btgt; | |
20547 | + for (bindex = au_dbstart(d); bindex < bend; bindex++) | |
20548 | + au_set_h_dptr(d, bindex, NULL); | |
20549 | + bend = au_dbend(d); | |
20550 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) | |
20551 | + au_set_h_dptr(d, bindex, NULL); | |
20552 | + au_update_dbrange(d, /*do_put_zero*/0); | |
20553 | + } | |
20554 | + | |
4a4d8108 AM |
20555 | + d = a->src_dentry; |
20556 | + au_set_dbwh(d, -1); | |
20557 | + bend = au_dbend(d); | |
20558 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) { | |
20559 | + h_d = au_h_dptr(d, bindex); | |
20560 | + if (h_d) | |
20561 | + au_set_h_dptr(d, bindex, NULL); | |
20562 | + } | |
20563 | + au_set_dbend(d, a->btgt); | |
20564 | + | |
20565 | + sb = d->d_sb; | |
20566 | + i = a->src_inode; | |
20567 | + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i)) | |
20568 | + return; /* success */ | |
20569 | + | |
20570 | + bend = au_ibend(i); | |
20571 | + for (bindex = a->btgt + 1; bindex <= bend; bindex++) { | |
20572 | + h_i = au_h_iptr(i, bindex); | |
20573 | + if (h_i) { | |
20574 | + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0); | |
20575 | + /* ignore this error */ | |
20576 | + au_set_h_iptr(i, bindex, NULL, 0); | |
20577 | + } | |
20578 | + } | |
20579 | + au_set_ibend(i, a->btgt); | |
1308ab2a | 20580 | +} |
dece6358 | 20581 | + |
4a4d8108 AM |
20582 | +/* ---------------------------------------------------------------------- */ |
20583 | + | |
20584 | +/* mainly for link(2) and rename(2) */ | |
20585 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt) | |
1308ab2a | 20586 | +{ |
4a4d8108 AM |
20587 | + aufs_bindex_t bdiropq, bwh; |
20588 | + struct dentry *parent; | |
20589 | + struct au_branch *br; | |
20590 | + | |
20591 | + parent = dentry->d_parent; | |
20592 | + IMustLock(parent->d_inode); /* dir is locked */ | |
20593 | + | |
20594 | + bdiropq = au_dbdiropq(parent); | |
20595 | + bwh = au_dbwh(dentry); | |
20596 | + br = au_sbr(dentry->d_sb, btgt); | |
20597 | + if (au_br_rdonly(br) | |
20598 | + || (0 <= bdiropq && bdiropq < btgt) | |
20599 | + || (0 <= bwh && bwh < btgt)) | |
20600 | + btgt = -1; | |
20601 | + | |
20602 | + AuDbg("btgt %d\n", btgt); | |
20603 | + return btgt; | |
1facf9fc | 20604 | +} |
20605 | + | |
4a4d8108 AM |
20606 | +/* sets src_bstart, dst_bstart and btgt */ |
20607 | +static int au_ren_wbr(struct au_ren_args *a) | |
1facf9fc | 20608 | +{ |
4a4d8108 AM |
20609 | + int err; |
20610 | + struct au_wr_dir_args wr_dir_args = { | |
20611 | + /* .force_btgt = -1, */ | |
20612 | + .flags = AuWrDir_ADD_ENTRY | |
20613 | + }; | |
dece6358 | 20614 | + |
4a4d8108 AM |
20615 | + a->src_bstart = au_dbstart(a->src_dentry); |
20616 | + a->dst_bstart = au_dbstart(a->dst_dentry); | |
20617 | + if (au_ftest_ren(a->flags, ISDIR)) | |
20618 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); | |
20619 | + wr_dir_args.force_btgt = a->src_bstart; | |
20620 | + if (a->dst_inode && a->dst_bstart < a->src_bstart) | |
20621 | + wr_dir_args.force_btgt = a->dst_bstart; | |
20622 | + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt); | |
20623 | + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args); | |
20624 | + a->btgt = err; | |
dece6358 | 20625 | + |
4a4d8108 | 20626 | + return err; |
1facf9fc | 20627 | +} |
20628 | + | |
4a4d8108 | 20629 | +static void au_ren_dt(struct au_ren_args *a) |
1facf9fc | 20630 | +{ |
4a4d8108 AM |
20631 | + a->h_path.dentry = a->src_h_parent; |
20632 | + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path); | |
20633 | + if (!au_ftest_ren(a->flags, ISSAMEDIR)) { | |
20634 | + a->h_path.dentry = a->dst_h_parent; | |
20635 | + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path); | |
20636 | + } | |
1facf9fc | 20637 | + |
4a4d8108 AM |
20638 | + au_fclr_ren(a->flags, DT_DSTDIR); |
20639 | + if (!au_ftest_ren(a->flags, ISDIR)) | |
20640 | + return; | |
dece6358 | 20641 | + |
4a4d8108 AM |
20642 | + a->h_path.dentry = a->src_h_dentry; |
20643 | + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path); | |
20644 | + if (a->dst_h_dentry->d_inode) { | |
20645 | + au_fset_ren(a->flags, DT_DSTDIR); | |
20646 | + a->h_path.dentry = a->dst_h_dentry; | |
20647 | + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path); | |
20648 | + } | |
1308ab2a | 20649 | +} |
dece6358 | 20650 | + |
4a4d8108 | 20651 | +static void au_ren_rev_dt(int err, struct au_ren_args *a) |
1308ab2a | 20652 | +{ |
4a4d8108 AM |
20653 | + struct dentry *h_d; |
20654 | + struct mutex *h_mtx; | |
20655 | + | |
20656 | + au_dtime_revert(a->src_dt + AuPARENT); | |
20657 | + if (!au_ftest_ren(a->flags, ISSAMEDIR)) | |
20658 | + au_dtime_revert(a->dst_dt + AuPARENT); | |
20659 | + | |
20660 | + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) { | |
20661 | + h_d = a->src_dt[AuCHILD].dt_h_path.dentry; | |
20662 | + h_mtx = &h_d->d_inode->i_mutex; | |
20663 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
20664 | + au_dtime_revert(a->src_dt + AuCHILD); | |
20665 | + mutex_unlock(h_mtx); | |
20666 | + | |
20667 | + if (au_ftest_ren(a->flags, DT_DSTDIR)) { | |
20668 | + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry; | |
20669 | + h_mtx = &h_d->d_inode->i_mutex; | |
20670 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD); | |
20671 | + au_dtime_revert(a->dst_dt + AuCHILD); | |
20672 | + mutex_unlock(h_mtx); | |
1facf9fc | 20673 | + } |
20674 | + } | |
20675 | +} | |
20676 | + | |
4a4d8108 AM |
20677 | +/* ---------------------------------------------------------------------- */ |
20678 | + | |
20679 | +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, | |
20680 | + struct inode *_dst_dir, struct dentry *_dst_dentry) | |
1facf9fc | 20681 | +{ |
e49829fe | 20682 | + int err, flags; |
4a4d8108 AM |
20683 | + /* reduce stack space */ |
20684 | + struct au_ren_args *a; | |
20685 | + | |
523b37e3 | 20686 | + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry); |
4a4d8108 AM |
20687 | + IMustLock(_src_dir); |
20688 | + IMustLock(_dst_dir); | |
20689 | + | |
20690 | + err = -ENOMEM; | |
20691 | + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE); | |
20692 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
20693 | + if (unlikely(!a)) | |
20694 | + goto out; | |
20695 | + | |
20696 | + a->src_dir = _src_dir; | |
20697 | + a->src_dentry = _src_dentry; | |
20698 | + a->src_inode = a->src_dentry->d_inode; | |
20699 | + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */ | |
20700 | + a->dst_dir = _dst_dir; | |
20701 | + a->dst_dentry = _dst_dentry; | |
20702 | + a->dst_inode = a->dst_dentry->d_inode; | |
20703 | + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */ | |
20704 | + if (a->dst_inode) { | |
20705 | + IMustLock(a->dst_inode); | |
20706 | + au_igrab(a->dst_inode); | |
1facf9fc | 20707 | + } |
1facf9fc | 20708 | + |
4a4d8108 | 20709 | + err = -ENOTDIR; |
027c5e7a | 20710 | + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN; |
4a4d8108 AM |
20711 | + if (S_ISDIR(a->src_inode->i_mode)) { |
20712 | + au_fset_ren(a->flags, ISDIR); | |
20713 | + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode))) | |
20714 | + goto out_free; | |
e49829fe JR |
20715 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
20716 | + AuLock_DIR | flags); | |
4a4d8108 | 20717 | + } else |
e49829fe JR |
20718 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
20719 | + flags); | |
20720 | + if (unlikely(err)) | |
20721 | + goto out_free; | |
1facf9fc | 20722 | + |
027c5e7a AM |
20723 | + err = au_d_hashed_positive(a->src_dentry); |
20724 | + if (unlikely(err)) | |
20725 | + goto out_unlock; | |
20726 | + err = -ENOENT; | |
20727 | + if (a->dst_inode) { | |
20728 | + /* | |
20729 | + * If it is a dir, VFS unhash dst_dentry before this | |
20730 | + * function. It means we cannot rely upon d_unhashed(). | |
20731 | + */ | |
20732 | + if (unlikely(!a->dst_inode->i_nlink)) | |
20733 | + goto out_unlock; | |
20734 | + if (!S_ISDIR(a->dst_inode->i_mode)) { | |
20735 | + err = au_d_hashed_positive(a->dst_dentry); | |
20736 | + if (unlikely(err)) | |
20737 | + goto out_unlock; | |
20738 | + } else if (unlikely(IS_DEADDIR(a->dst_inode))) | |
20739 | + goto out_unlock; | |
20740 | + } else if (unlikely(d_unhashed(a->dst_dentry))) | |
20741 | + goto out_unlock; | |
20742 | + | |
7eafdf33 AM |
20743 | + /* |
20744 | + * is it possible? | |
20745 | + * yes, it happend (in linux-3.3-rcN) but I don't know why. | |
20746 | + * there may exist a problem somewhere else. | |
20747 | + */ | |
20748 | + err = -EINVAL; | |
20749 | + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode)) | |
20750 | + goto out_unlock; | |
20751 | + | |
4a4d8108 AM |
20752 | + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */ |
20753 | + di_write_lock_parent(a->dst_parent); | |
1facf9fc | 20754 | + |
4a4d8108 AM |
20755 | + /* which branch we process */ |
20756 | + err = au_ren_wbr(a); | |
20757 | + if (unlikely(err < 0)) | |
027c5e7a | 20758 | + goto out_parent; |
4a4d8108 | 20759 | + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt); |
86dc4139 | 20760 | + a->h_path.mnt = au_br_mnt(a->br); |
1facf9fc | 20761 | + |
4a4d8108 AM |
20762 | + /* are they available to be renamed */ |
20763 | + err = au_ren_may_dir(a); | |
20764 | + if (unlikely(err)) | |
20765 | + goto out_children; | |
1facf9fc | 20766 | + |
4a4d8108 AM |
20767 | + /* prepare the writable parent dir on the same branch */ |
20768 | + if (a->dst_bstart == a->btgt) { | |
20769 | + au_fset_ren(a->flags, WHDST); | |
20770 | + } else { | |
20771 | + err = au_cpup_dirs(a->dst_dentry, a->btgt); | |
20772 | + if (unlikely(err)) | |
20773 | + goto out_children; | |
20774 | + } | |
1facf9fc | 20775 | + |
4a4d8108 AM |
20776 | + if (a->src_dir != a->dst_dir) { |
20777 | + /* | |
20778 | + * this temporary unlock is safe, | |
20779 | + * because both dir->i_mutex are locked. | |
20780 | + */ | |
20781 | + di_write_unlock(a->dst_parent); | |
20782 | + di_write_lock_parent(a->src_parent); | |
20783 | + err = au_wr_dir_need_wh(a->src_dentry, | |
20784 | + au_ftest_ren(a->flags, ISDIR), | |
20785 | + &a->btgt); | |
20786 | + di_write_unlock(a->src_parent); | |
20787 | + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1); | |
20788 | + au_fclr_ren(a->flags, ISSAMEDIR); | |
20789 | + } else | |
20790 | + err = au_wr_dir_need_wh(a->src_dentry, | |
20791 | + au_ftest_ren(a->flags, ISDIR), | |
20792 | + &a->btgt); | |
20793 | + if (unlikely(err < 0)) | |
20794 | + goto out_children; | |
20795 | + if (err) | |
20796 | + au_fset_ren(a->flags, WHSRC); | |
1facf9fc | 20797 | + |
86dc4139 AM |
20798 | + /* cpup src */ |
20799 | + if (a->src_bstart != a->btgt) { | |
86dc4139 AM |
20800 | + struct au_pin pin; |
20801 | + | |
20802 | + err = au_pin(&pin, a->src_dentry, a->btgt, | |
20803 | + au_opt_udba(a->src_dentry->d_sb), | |
20804 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
367653fa | 20805 | + if (!err) { |
c2b27bf2 AM |
20806 | + struct au_cp_generic cpg = { |
20807 | + .dentry = a->src_dentry, | |
20808 | + .bdst = a->btgt, | |
20809 | + .bsrc = a->src_bstart, | |
20810 | + .len = -1, | |
20811 | + .pin = &pin, | |
20812 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
20813 | + }; | |
367653fa | 20814 | + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart); |
c2b27bf2 | 20815 | + err = au_sio_cpup_simple(&cpg); |
367653fa | 20816 | + au_unpin(&pin); |
86dc4139 | 20817 | + } |
86dc4139 AM |
20818 | + if (unlikely(err)) |
20819 | + goto out_children; | |
20820 | + a->src_bstart = a->btgt; | |
20821 | + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt); | |
20822 | + au_fset_ren(a->flags, WHSRC); | |
20823 | + } | |
20824 | + | |
4a4d8108 AM |
20825 | + /* lock them all */ |
20826 | + err = au_ren_lock(a); | |
20827 | + if (unlikely(err)) | |
86dc4139 | 20828 | + /* leave the copied-up one */ |
4a4d8108 | 20829 | + goto out_children; |
1facf9fc | 20830 | + |
4a4d8108 AM |
20831 | + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE)) |
20832 | + err = au_may_ren(a); | |
20833 | + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
20834 | + err = -ENAMETOOLONG; | |
20835 | + if (unlikely(err)) | |
20836 | + goto out_hdir; | |
1facf9fc | 20837 | + |
4a4d8108 AM |
20838 | + /* store timestamps to be revertible */ |
20839 | + au_ren_dt(a); | |
1facf9fc | 20840 | + |
4a4d8108 AM |
20841 | + /* here we go */ |
20842 | + err = do_rename(a); | |
20843 | + if (unlikely(err)) | |
20844 | + goto out_dt; | |
20845 | + | |
20846 | + /* update dir attributes */ | |
20847 | + au_ren_refresh_dir(a); | |
20848 | + | |
20849 | + /* dput/iput all lower dentries */ | |
20850 | + au_ren_refresh(a); | |
20851 | + | |
20852 | + goto out_hdir; /* success */ | |
20853 | + | |
4f0767ce | 20854 | +out_dt: |
4a4d8108 | 20855 | + au_ren_rev_dt(err, a); |
4f0767ce | 20856 | +out_hdir: |
4a4d8108 | 20857 | + au_ren_unlock(a); |
4f0767ce | 20858 | +out_children: |
4a4d8108 | 20859 | + au_nhash_wh_free(&a->whlist); |
027c5e7a AM |
20860 | + if (err && a->dst_inode && a->dst_bstart != a->btgt) { |
20861 | + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt); | |
20862 | + au_set_h_dptr(a->dst_dentry, a->btgt, NULL); | |
20863 | + au_set_dbstart(a->dst_dentry, a->dst_bstart); | |
4a4d8108 | 20864 | + } |
027c5e7a | 20865 | +out_parent: |
4a4d8108 AM |
20866 | + if (!err) |
20867 | + d_move(a->src_dentry, a->dst_dentry); | |
027c5e7a AM |
20868 | + else { |
20869 | + au_update_dbstart(a->dst_dentry); | |
20870 | + if (!a->dst_inode) | |
20871 | + d_drop(a->dst_dentry); | |
20872 | + } | |
4a4d8108 AM |
20873 | + if (au_ftest_ren(a->flags, ISSAMEDIR)) |
20874 | + di_write_unlock(a->dst_parent); | |
20875 | + else | |
20876 | + di_write_unlock2(a->src_parent, a->dst_parent); | |
027c5e7a | 20877 | +out_unlock: |
4a4d8108 | 20878 | + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry); |
4f0767ce | 20879 | +out_free: |
4a4d8108 AM |
20880 | + iput(a->dst_inode); |
20881 | + if (a->thargs) | |
20882 | + au_whtmp_rmdir_free(a->thargs); | |
20883 | + kfree(a); | |
4f0767ce | 20884 | +out: |
4a4d8108 AM |
20885 | + AuTraceErr(err); |
20886 | + return err; | |
1308ab2a | 20887 | +} |
7f207e10 AM |
20888 | diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig |
20889 | --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
20890 | +++ linux/fs/aufs/Kconfig 2015-01-25 13:00:38.627713742 +0100 |
20891 | @@ -0,0 +1,185 @@ | |
4a4d8108 AM |
20892 | +config AUFS_FS |
20893 | + tristate "Aufs (Advanced multi layered unification filesystem) support" | |
4a4d8108 AM |
20894 | + help |
20895 | + Aufs is a stackable unification filesystem such as Unionfs, | |
20896 | + which unifies several directories and provides a merged single | |
20897 | + directory. | |
20898 | + In the early days, aufs was entirely re-designed and | |
20899 | + re-implemented Unionfs Version 1.x series. Introducing many | |
20900 | + original ideas, approaches and improvements, it becomes totally | |
20901 | + different from Unionfs while keeping the basic features. | |
1facf9fc | 20902 | + |
4a4d8108 AM |
20903 | +if AUFS_FS |
20904 | +choice | |
20905 | + prompt "Maximum number of branches" | |
20906 | + default AUFS_BRANCH_MAX_127 | |
20907 | + help | |
20908 | + Specifies the maximum number of branches (or member directories) | |
20909 | + in a single aufs. The larger value consumes more system | |
20910 | + resources and has a minor impact to performance. | |
20911 | +config AUFS_BRANCH_MAX_127 | |
20912 | + bool "127" | |
20913 | + help | |
20914 | + Specifies the maximum number of branches (or member directories) | |
20915 | + in a single aufs. The larger value consumes more system | |
20916 | + resources and has a minor impact to performance. | |
20917 | +config AUFS_BRANCH_MAX_511 | |
20918 | + bool "511" | |
20919 | + help | |
20920 | + Specifies the maximum number of branches (or member directories) | |
20921 | + in a single aufs. The larger value consumes more system | |
20922 | + resources and has a minor impact to performance. | |
20923 | +config AUFS_BRANCH_MAX_1023 | |
20924 | + bool "1023" | |
20925 | + help | |
20926 | + Specifies the maximum number of branches (or member directories) | |
20927 | + in a single aufs. The larger value consumes more system | |
20928 | + resources and has a minor impact to performance. | |
20929 | +config AUFS_BRANCH_MAX_32767 | |
20930 | + bool "32767" | |
20931 | + help | |
20932 | + Specifies the maximum number of branches (or member directories) | |
20933 | + in a single aufs. The larger value consumes more system | |
20934 | + resources and has a minor impact to performance. | |
20935 | +endchoice | |
1facf9fc | 20936 | + |
e49829fe JR |
20937 | +config AUFS_SBILIST |
20938 | + bool | |
20939 | + depends on AUFS_MAGIC_SYSRQ || PROC_FS | |
20940 | + default y | |
20941 | + help | |
20942 | + Automatic configuration for internal use. | |
20943 | + When aufs supports Magic SysRq or /proc, enabled automatically. | |
20944 | + | |
4a4d8108 AM |
20945 | +config AUFS_HNOTIFY |
20946 | + bool "Detect direct branch access (bypassing aufs)" | |
20947 | + help | |
20948 | + If you want to modify files on branches directly, eg. bypassing aufs, | |
20949 | + and want aufs to detect the changes of them fully, then enable this | |
20950 | + option and use 'udba=notify' mount option. | |
7f207e10 | 20951 | + Currently there is only one available configuration, "fsnotify". |
4a4d8108 AM |
20952 | + It will have a negative impact to the performance. |
20953 | + See detail in aufs.5. | |
dece6358 | 20954 | + |
4a4d8108 AM |
20955 | +choice |
20956 | + prompt "method" if AUFS_HNOTIFY | |
20957 | + default AUFS_HFSNOTIFY | |
20958 | +config AUFS_HFSNOTIFY | |
20959 | + bool "fsnotify" | |
20960 | + select FSNOTIFY | |
4a4d8108 | 20961 | +endchoice |
1facf9fc | 20962 | + |
4a4d8108 AM |
20963 | +config AUFS_EXPORT |
20964 | + bool "NFS-exportable aufs" | |
2cbb1c4b | 20965 | + depends on EXPORTFS |
4a4d8108 AM |
20966 | + help |
20967 | + If you want to export your mounted aufs via NFS, then enable this | |
20968 | + option. There are several requirements for this configuration. | |
20969 | + See detail in aufs.5. | |
1facf9fc | 20970 | + |
4a4d8108 AM |
20971 | +config AUFS_INO_T_64 |
20972 | + bool | |
20973 | + depends on AUFS_EXPORT | |
20974 | + depends on 64BIT && !(ALPHA || S390) | |
20975 | + default y | |
20976 | + help | |
20977 | + Automatic configuration for internal use. | |
20978 | + /* typedef unsigned long/int __kernel_ino_t */ | |
20979 | + /* alpha and s390x are int */ | |
1facf9fc | 20980 | + |
c1595e42 JR |
20981 | +config AUFS_XATTR |
20982 | + bool "support for XATTR/EA (including Security Labels)" | |
20983 | + help | |
20984 | + If your branch fs supports XATTR/EA and you want to make them | |
20985 | + available in aufs too, then enable this opsion and specify the | |
20986 | + branch attributes for EA. | |
20987 | + See detail in aufs.5. | |
20988 | + | |
076b876e AM |
20989 | +config AUFS_FHSM |
20990 | + bool "File-based Hierarchical Storage Management" | |
20991 | + help | |
20992 | + Hierarchical Storage Management (or HSM) is a well-known feature | |
20993 | + in the storage world. Aufs provides this feature as file-based. | |
20994 | + with multiple branches. | |
20995 | + These multiple branches are prioritized, ie. the topmost one | |
20996 | + should be the fastest drive and be used heavily. | |
20997 | + | |
4a4d8108 AM |
20998 | +config AUFS_RDU |
20999 | + bool "Readdir in userspace" | |
21000 | + help | |
21001 | + Aufs has two methods to provide a merged view for a directory, | |
21002 | + by a user-space library and by kernel-space natively. The latter | |
21003 | + is always enabled but sometimes large and slow. | |
21004 | + If you enable this option, install the library in aufs2-util | |
21005 | + package, and set some environment variables for your readdir(3), | |
21006 | + then the work will be handled in user-space which generally | |
21007 | + shows better performance in most cases. | |
21008 | + See detail in aufs.5. | |
1facf9fc | 21009 | + |
4a4d8108 AM |
21010 | +config AUFS_SHWH |
21011 | + bool "Show whiteouts" | |
21012 | + help | |
21013 | + If you want to make the whiteouts in aufs visible, then enable | |
21014 | + this option and specify 'shwh' mount option. Although it may | |
21015 | + sounds like philosophy or something, but in technically it | |
21016 | + simply shows the name of whiteout with keeping its behaviour. | |
1facf9fc | 21017 | + |
4a4d8108 AM |
21018 | +config AUFS_BR_RAMFS |
21019 | + bool "Ramfs (initramfs/rootfs) as an aufs branch" | |
21020 | + help | |
21021 | + If you want to use ramfs as an aufs branch fs, then enable this | |
21022 | + option. Generally tmpfs is recommended. | |
21023 | + Aufs prohibited them to be a branch fs by default, because | |
21024 | + initramfs becomes unusable after switch_root or something | |
21025 | + generally. If you sets initramfs as an aufs branch and boot your | |
21026 | + system by switch_root, you will meet a problem easily since the | |
21027 | + files in initramfs may be inaccessible. | |
21028 | + Unless you are going to use ramfs as an aufs branch fs without | |
21029 | + switch_root or something, leave it N. | |
1facf9fc | 21030 | + |
4a4d8108 AM |
21031 | +config AUFS_BR_FUSE |
21032 | + bool "Fuse fs as an aufs branch" | |
21033 | + depends on FUSE_FS | |
21034 | + select AUFS_POLL | |
21035 | + help | |
21036 | + If you want to use fuse-based userspace filesystem as an aufs | |
21037 | + branch fs, then enable this option. | |
21038 | + It implements the internal poll(2) operation which is | |
21039 | + implemented by fuse only (curretnly). | |
1facf9fc | 21040 | + |
4a4d8108 AM |
21041 | +config AUFS_POLL |
21042 | + bool | |
21043 | + help | |
21044 | + Automatic configuration for internal use. | |
1facf9fc | 21045 | + |
4a4d8108 AM |
21046 | +config AUFS_BR_HFSPLUS |
21047 | + bool "Hfsplus as an aufs branch" | |
21048 | + depends on HFSPLUS_FS | |
21049 | + default y | |
21050 | + help | |
21051 | + If you want to use hfsplus fs as an aufs branch fs, then enable | |
21052 | + this option. This option introduces a small overhead at | |
21053 | + copying-up a file on hfsplus. | |
1facf9fc | 21054 | + |
4a4d8108 AM |
21055 | +config AUFS_BDEV_LOOP |
21056 | + bool | |
21057 | + depends on BLK_DEV_LOOP | |
21058 | + default y | |
21059 | + help | |
21060 | + Automatic configuration for internal use. | |
21061 | + Convert =[ym] into =y. | |
1308ab2a | 21062 | + |
4a4d8108 AM |
21063 | +config AUFS_DEBUG |
21064 | + bool "Debug aufs" | |
21065 | + help | |
21066 | + Enable this to compile aufs internal debug code. | |
21067 | + It will have a negative impact to the performance. | |
21068 | + | |
21069 | +config AUFS_MAGIC_SYSRQ | |
21070 | + bool | |
21071 | + depends on AUFS_DEBUG && MAGIC_SYSRQ | |
21072 | + default y | |
21073 | + help | |
21074 | + Automatic configuration for internal use. | |
21075 | + When aufs supports Magic SysRq, enabled automatically. | |
21076 | +endif | |
7f207e10 AM |
21077 | diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c |
21078 | --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 21079 | +++ linux/fs/aufs/loop.c 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 21080 | @@ -0,0 +1,145 @@ |
1facf9fc | 21081 | +/* |
523b37e3 | 21082 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 21083 | + * |
21084 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21085 | + * it under the terms of the GNU General Public License as published by | |
21086 | + * the Free Software Foundation; either version 2 of the License, or | |
21087 | + * (at your option) any later version. | |
dece6358 AM |
21088 | + * |
21089 | + * This program is distributed in the hope that it will be useful, | |
21090 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21091 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21092 | + * GNU General Public License for more details. | |
21093 | + * | |
21094 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21095 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21096 | + */ |
21097 | + | |
21098 | +/* | |
21099 | + * support for loopback block device as a branch | |
21100 | + */ | |
21101 | + | |
1facf9fc | 21102 | +#include "aufs.h" |
21103 | + | |
392086de AM |
21104 | +/* added into drivers/block/loop.c */ |
21105 | +static struct file *(*backing_file_func)(struct super_block *sb); | |
21106 | + | |
1facf9fc | 21107 | +/* |
21108 | + * test if two lower dentries have overlapping branches. | |
21109 | + */ | |
b752ccd1 | 21110 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding) |
1facf9fc | 21111 | +{ |
b752ccd1 | 21112 | + struct super_block *h_sb; |
392086de AM |
21113 | + struct file *backing_file; |
21114 | + | |
21115 | + if (unlikely(!backing_file_func)) { | |
21116 | + /* don't load "loop" module here */ | |
21117 | + backing_file_func = symbol_get(loop_backing_file); | |
21118 | + if (unlikely(!backing_file_func)) | |
21119 | + /* "loop" module is not loaded */ | |
21120 | + return 0; | |
21121 | + } | |
1facf9fc | 21122 | + |
b752ccd1 | 21123 | + h_sb = h_adding->d_sb; |
392086de AM |
21124 | + backing_file = backing_file_func(h_sb); |
21125 | + if (!backing_file) | |
1facf9fc | 21126 | + return 0; |
21127 | + | |
392086de | 21128 | + h_adding = backing_file->f_dentry; |
b752ccd1 AM |
21129 | + /* |
21130 | + * h_adding can be local NFS. | |
21131 | + * in this case aufs cannot detect the loop. | |
21132 | + */ | |
21133 | + if (unlikely(h_adding->d_sb == sb)) | |
1facf9fc | 21134 | + return 1; |
b752ccd1 | 21135 | + return !!au_test_subdir(h_adding, sb->s_root); |
1facf9fc | 21136 | +} |
21137 | + | |
21138 | +/* true if a kernel thread named 'loop[0-9].*' accesses a file */ | |
21139 | +int au_test_loopback_kthread(void) | |
21140 | +{ | |
b752ccd1 AM |
21141 | + int ret; |
21142 | + struct task_struct *tsk = current; | |
a2a7ad62 | 21143 | + char c, comm[sizeof(tsk->comm)]; |
b752ccd1 AM |
21144 | + |
21145 | + ret = 0; | |
21146 | + if (tsk->flags & PF_KTHREAD) { | |
a2a7ad62 AM |
21147 | + get_task_comm(comm, tsk); |
21148 | + c = comm[4]; | |
b752ccd1 | 21149 | + ret = ('0' <= c && c <= '9' |
a2a7ad62 | 21150 | + && !strncmp(comm, "loop", 4)); |
b752ccd1 | 21151 | + } |
1facf9fc | 21152 | + |
b752ccd1 | 21153 | + return ret; |
1facf9fc | 21154 | +} |
87a755f4 AM |
21155 | + |
21156 | +/* ---------------------------------------------------------------------- */ | |
21157 | + | |
21158 | +#define au_warn_loopback_step 16 | |
21159 | +static int au_warn_loopback_nelem = au_warn_loopback_step; | |
21160 | +static unsigned long *au_warn_loopback_array; | |
21161 | + | |
21162 | +void au_warn_loopback(struct super_block *h_sb) | |
21163 | +{ | |
21164 | + int i, new_nelem; | |
21165 | + unsigned long *a, magic; | |
21166 | + static DEFINE_SPINLOCK(spin); | |
21167 | + | |
21168 | + magic = h_sb->s_magic; | |
21169 | + spin_lock(&spin); | |
21170 | + a = au_warn_loopback_array; | |
21171 | + for (i = 0; i < au_warn_loopback_nelem && *a; i++) | |
21172 | + if (a[i] == magic) { | |
21173 | + spin_unlock(&spin); | |
21174 | + return; | |
21175 | + } | |
21176 | + | |
21177 | + /* h_sb is new to us, print it */ | |
21178 | + if (i < au_warn_loopback_nelem) { | |
21179 | + a[i] = magic; | |
21180 | + goto pr; | |
21181 | + } | |
21182 | + | |
21183 | + /* expand the array */ | |
21184 | + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step; | |
21185 | + a = au_kzrealloc(au_warn_loopback_array, | |
21186 | + au_warn_loopback_nelem * sizeof(unsigned long), | |
21187 | + new_nelem * sizeof(unsigned long), GFP_ATOMIC); | |
21188 | + if (a) { | |
21189 | + au_warn_loopback_nelem = new_nelem; | |
21190 | + au_warn_loopback_array = a; | |
21191 | + a[i] = magic; | |
21192 | + goto pr; | |
21193 | + } | |
21194 | + | |
21195 | + spin_unlock(&spin); | |
21196 | + AuWarn1("realloc failed, ignored\n"); | |
21197 | + return; | |
21198 | + | |
21199 | +pr: | |
21200 | + spin_unlock(&spin); | |
0c3ec466 AM |
21201 | + pr_warn("you may want to try another patch for loopback file " |
21202 | + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic); | |
87a755f4 AM |
21203 | +} |
21204 | + | |
21205 | +int au_loopback_init(void) | |
21206 | +{ | |
21207 | + int err; | |
21208 | + struct super_block *sb __maybe_unused; | |
21209 | + | |
21210 | + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long)); | |
21211 | + | |
21212 | + err = 0; | |
21213 | + au_warn_loopback_array = kcalloc(au_warn_loopback_step, | |
21214 | + sizeof(unsigned long), GFP_NOFS); | |
21215 | + if (unlikely(!au_warn_loopback_array)) | |
21216 | + err = -ENOMEM; | |
21217 | + | |
21218 | + return err; | |
21219 | +} | |
21220 | + | |
21221 | +void au_loopback_fin(void) | |
21222 | +{ | |
392086de | 21223 | + symbol_put(loop_backing_file); |
87a755f4 AM |
21224 | + kfree(au_warn_loopback_array); |
21225 | +} | |
7f207e10 AM |
21226 | diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h |
21227 | --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 21228 | +++ linux/fs/aufs/loop.h 2015-01-25 13:00:38.631047076 +0100 |
523b37e3 | 21229 | @@ -0,0 +1,52 @@ |
1facf9fc | 21230 | +/* |
523b37e3 | 21231 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 21232 | + * |
21233 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21234 | + * it under the terms of the GNU General Public License as published by | |
21235 | + * the Free Software Foundation; either version 2 of the License, or | |
21236 | + * (at your option) any later version. | |
dece6358 AM |
21237 | + * |
21238 | + * This program is distributed in the hope that it will be useful, | |
21239 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21240 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21241 | + * GNU General Public License for more details. | |
21242 | + * | |
21243 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21244 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21245 | + */ |
21246 | + | |
21247 | +/* | |
21248 | + * support for loopback mount as a branch | |
21249 | + */ | |
21250 | + | |
21251 | +#ifndef __AUFS_LOOP_H__ | |
21252 | +#define __AUFS_LOOP_H__ | |
21253 | + | |
21254 | +#ifdef __KERNEL__ | |
21255 | + | |
dece6358 AM |
21256 | +struct dentry; |
21257 | +struct super_block; | |
1facf9fc | 21258 | + |
21259 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
392086de AM |
21260 | +/* drivers/block/loop.c */ |
21261 | +struct file *loop_backing_file(struct super_block *sb); | |
21262 | + | |
1facf9fc | 21263 | +/* loop.c */ |
b752ccd1 | 21264 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding); |
1facf9fc | 21265 | +int au_test_loopback_kthread(void); |
87a755f4 AM |
21266 | +void au_warn_loopback(struct super_block *h_sb); |
21267 | + | |
21268 | +int au_loopback_init(void); | |
21269 | +void au_loopback_fin(void); | |
1facf9fc | 21270 | +#else |
4a4d8108 | 21271 | +AuStubInt0(au_test_loopback_overlap, struct super_block *sb, |
b752ccd1 | 21272 | + struct dentry *h_adding) |
4a4d8108 | 21273 | +AuStubInt0(au_test_loopback_kthread, void) |
87a755f4 AM |
21274 | +AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
21275 | + | |
21276 | +AuStubInt0(au_loopback_init, void) | |
21277 | +AuStubVoid(au_loopback_fin, void) | |
1facf9fc | 21278 | +#endif /* BLK_DEV_LOOP */ |
21279 | + | |
21280 | +#endif /* __KERNEL__ */ | |
21281 | +#endif /* __AUFS_LOOP_H__ */ | |
7f207e10 AM |
21282 | diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk |
21283 | --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 21284 | +++ linux/fs/aufs/magic.mk 2015-01-25 13:00:38.631047076 +0100 |
4a4d8108 | 21285 | @@ -0,0 +1,54 @@ |
1facf9fc | 21286 | + |
21287 | +# defined in ${srctree}/fs/fuse/inode.c | |
21288 | +# tristate | |
21289 | +ifdef CONFIG_FUSE_FS | |
21290 | +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546 | |
21291 | +endif | |
21292 | + | |
21293 | +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h | |
21294 | +# tristate | |
21295 | +ifdef CONFIG_OCFS2_FS | |
21296 | +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f | |
21297 | +endif | |
21298 | + | |
21299 | +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h | |
21300 | +# tristate | |
21301 | +ifdef CONFIG_OCFS2_FS_O2CB | |
21302 | +ccflags-y += -DDLMFS_MAGIC=0x76a9f425 | |
21303 | +endif | |
21304 | + | |
1facf9fc | 21305 | +# defined in ${srctree}/fs/cifs/cifsfs.c |
21306 | +# tristate | |
21307 | +ifdef CONFIG_CIFS_FS | |
21308 | +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42 | |
21309 | +endif | |
21310 | + | |
21311 | +# defined in ${srctree}/fs/xfs/xfs_sb.h | |
21312 | +# tristate | |
21313 | +ifdef CONFIG_XFS_FS | |
21314 | +ccflags-y += -DXFS_SB_MAGIC=0x58465342 | |
21315 | +endif | |
21316 | + | |
21317 | +# defined in ${srctree}/fs/configfs/mount.c | |
21318 | +# tristate | |
21319 | +ifdef CONFIG_CONFIGFS_FS | |
21320 | +ccflags-y += -DCONFIGFS_MAGIC=0x62656570 | |
21321 | +endif | |
21322 | + | |
21323 | +# defined in ${srctree}/fs/9p/v9fs.h | |
21324 | +# tristate | |
21325 | +ifdef CONFIG_9P_FS | |
21326 | +ccflags-y += -DV9FS_MAGIC=0x01021997 | |
21327 | +endif | |
21328 | + | |
21329 | +# defined in ${srctree}/fs/ubifs/ubifs.h | |
21330 | +# tristate | |
21331 | +ifdef CONFIG_UBIFS_FS | |
21332 | +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905 | |
21333 | +endif | |
4a4d8108 AM |
21334 | + |
21335 | +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h | |
21336 | +# tristate | |
21337 | +ifdef CONFIG_HFSPLUS_FS | |
21338 | +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b | |
21339 | +endif | |
7f207e10 AM |
21340 | diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile |
21341 | --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
21342 | +++ linux/fs/aufs/Makefile 2015-01-25 13:00:38.627713742 +0100 |
21343 | @@ -0,0 +1,44 @@ | |
4a4d8108 AM |
21344 | + |
21345 | +include ${src}/magic.mk | |
21346 | +ifeq (${CONFIG_AUFS_FS},m) | |
21347 | +include ${src}/conf.mk | |
21348 | +endif | |
21349 | +-include ${src}/priv_def.mk | |
21350 | + | |
21351 | +# cf. include/linux/kernel.h | |
21352 | +# enable pr_debug | |
21353 | +ccflags-y += -DDEBUG | |
f6c5ef8b AM |
21354 | +# sparse requires the full pathname |
21355 | +ifdef M | |
523b37e3 | 21356 | +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h |
f6c5ef8b | 21357 | +else |
523b37e3 | 21358 | +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h |
f6c5ef8b | 21359 | +endif |
4a4d8108 AM |
21360 | + |
21361 | +obj-$(CONFIG_AUFS_FS) += aufs.o | |
21362 | +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \ | |
21363 | + wkq.o vfsub.o dcsub.o \ | |
e49829fe | 21364 | + cpup.o whout.o wbr_policy.o \ |
4a4d8108 AM |
21365 | + dinfo.o dentry.o \ |
21366 | + dynop.o \ | |
21367 | + finfo.o file.o f_op.o \ | |
21368 | + dir.o vdir.o \ | |
21369 | + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \ | |
c2b27bf2 | 21370 | + mvdown.o ioctl.o |
4a4d8108 AM |
21371 | + |
21372 | +# all are boolean | |
e49829fe | 21373 | +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o |
4a4d8108 AM |
21374 | +aufs-$(CONFIG_SYSFS) += sysfs.o |
21375 | +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o | |
21376 | +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o | |
21377 | +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o | |
21378 | +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o | |
4a4d8108 | 21379 | +aufs-$(CONFIG_AUFS_EXPORT) += export.o |
c1595e42 JR |
21380 | +aufs-$(CONFIG_AUFS_XATTR) += xattr.o |
21381 | +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o | |
076b876e | 21382 | +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o |
4a4d8108 AM |
21383 | +aufs-$(CONFIG_AUFS_POLL) += poll.o |
21384 | +aufs-$(CONFIG_AUFS_RDU) += rdu.o | |
4a4d8108 AM |
21385 | +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o |
21386 | +aufs-$(CONFIG_AUFS_DEBUG) += debug.o | |
21387 | +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o | |
7f207e10 AM |
21388 | diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c |
21389 | --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 21390 | +++ linux/fs/aufs/module.c 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 21391 | @@ -0,0 +1,210 @@ |
1facf9fc | 21392 | +/* |
523b37e3 | 21393 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 21394 | + * |
21395 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21396 | + * it under the terms of the GNU General Public License as published by | |
21397 | + * the Free Software Foundation; either version 2 of the License, or | |
21398 | + * (at your option) any later version. | |
dece6358 AM |
21399 | + * |
21400 | + * This program is distributed in the hope that it will be useful, | |
21401 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21402 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21403 | + * GNU General Public License for more details. | |
21404 | + * | |
21405 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21406 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21407 | + */ |
21408 | + | |
21409 | +/* | |
21410 | + * module global variables and operations | |
21411 | + */ | |
21412 | + | |
21413 | +#include <linux/module.h> | |
21414 | +#include <linux/seq_file.h> | |
21415 | +#include "aufs.h" | |
21416 | + | |
21417 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp) | |
21418 | +{ | |
21419 | + if (new_sz <= nused) | |
21420 | + return p; | |
21421 | + | |
21422 | + p = krealloc(p, new_sz, gfp); | |
21423 | + if (p) | |
21424 | + memset(p + nused, 0, new_sz - nused); | |
21425 | + return p; | |
21426 | +} | |
21427 | + | |
21428 | +/* ---------------------------------------------------------------------- */ | |
21429 | + | |
21430 | +/* | |
21431 | + * aufs caches | |
21432 | + */ | |
21433 | +struct kmem_cache *au_cachep[AuCache_Last]; | |
21434 | +static int __init au_cache_init(void) | |
21435 | +{ | |
4a4d8108 | 21436 | + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once); |
1facf9fc | 21437 | + if (au_cachep[AuCache_DINFO]) |
027c5e7a | 21438 | + /* SLAB_DESTROY_BY_RCU */ |
4a4d8108 AM |
21439 | + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr, |
21440 | + au_icntnr_init_once); | |
1facf9fc | 21441 | + if (au_cachep[AuCache_ICNTNR]) |
4a4d8108 AM |
21442 | + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo, |
21443 | + au_fi_init_once); | |
1facf9fc | 21444 | + if (au_cachep[AuCache_FINFO]) |
21445 | + au_cachep[AuCache_VDIR] = AuCache(au_vdir); | |
21446 | + if (au_cachep[AuCache_VDIR]) | |
21447 | + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr); | |
21448 | + if (au_cachep[AuCache_DEHSTR]) | |
21449 | + return 0; | |
21450 | + | |
21451 | + return -ENOMEM; | |
21452 | +} | |
21453 | + | |
21454 | +static void au_cache_fin(void) | |
21455 | +{ | |
21456 | + int i; | |
4a4d8108 | 21457 | + |
537831f9 AM |
21458 | + /* |
21459 | + * Make sure all delayed rcu free inodes are flushed before we | |
21460 | + * destroy cache. | |
21461 | + */ | |
21462 | + rcu_barrier(); | |
21463 | + | |
7eafdf33 AM |
21464 | + /* excluding AuCache_HNOTIFY */ |
21465 | + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last); | |
21466 | + for (i = 0; i < AuCache_HNOTIFY; i++) | |
1facf9fc | 21467 | + if (au_cachep[i]) { |
21468 | + kmem_cache_destroy(au_cachep[i]); | |
21469 | + au_cachep[i] = NULL; | |
21470 | + } | |
21471 | +} | |
21472 | + | |
21473 | +/* ---------------------------------------------------------------------- */ | |
21474 | + | |
21475 | +int au_dir_roflags; | |
21476 | + | |
e49829fe | 21477 | +#ifdef CONFIG_AUFS_SBILIST |
1e00d052 AM |
21478 | +/* |
21479 | + * iterate_supers_type() doesn't protect us from | |
21480 | + * remounting (branch management) | |
21481 | + */ | |
e49829fe JR |
21482 | +struct au_splhead au_sbilist; |
21483 | +#endif | |
21484 | + | |
9dbd164d AM |
21485 | +struct lock_class_key au_lc_key[AuLcKey_Last]; |
21486 | + | |
1facf9fc | 21487 | +/* |
21488 | + * functions for module interface. | |
21489 | + */ | |
21490 | +MODULE_LICENSE("GPL"); | |
21491 | +/* MODULE_LICENSE("GPL v2"); */ | |
dece6358 | 21492 | +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>"); |
1facf9fc | 21493 | +MODULE_DESCRIPTION(AUFS_NAME |
21494 | + " -- Advanced multi layered unification filesystem"); | |
21495 | +MODULE_VERSION(AUFS_VERSION); | |
c06a8ce3 | 21496 | +MODULE_ALIAS_FS(AUFS_NAME); |
1facf9fc | 21497 | + |
1facf9fc | 21498 | +/* this module parameter has no meaning when SYSFS is disabled */ |
21499 | +int sysaufs_brs = 1; | |
21500 | +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN"); | |
21501 | +module_param_named(brs, sysaufs_brs, int, S_IRUGO); | |
21502 | + | |
076b876e AM |
21503 | +/* this module parameter has no meaning when USER_NS is disabled */ |
21504 | +static bool au_userns; | |
21505 | +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns"); | |
21506 | +module_param_named(allow_userns, au_userns, bool, S_IRUGO); | |
21507 | + | |
1facf9fc | 21508 | +/* ---------------------------------------------------------------------- */ |
21509 | + | |
21510 | +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */ | |
21511 | + | |
21512 | +int au_seq_path(struct seq_file *seq, struct path *path) | |
21513 | +{ | |
21514 | + return seq_path(seq, path, au_esc_chars); | |
21515 | +} | |
21516 | + | |
21517 | +/* ---------------------------------------------------------------------- */ | |
21518 | + | |
21519 | +static int __init aufs_init(void) | |
21520 | +{ | |
21521 | + int err, i; | |
21522 | + char *p; | |
21523 | + | |
21524 | + p = au_esc_chars; | |
21525 | + for (i = 1; i <= ' '; i++) | |
21526 | + *p++ = i; | |
21527 | + *p++ = '\\'; | |
21528 | + *p++ = '\x7f'; | |
21529 | + *p = 0; | |
21530 | + | |
21531 | + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE); | |
21532 | + | |
e49829fe | 21533 | + au_sbilist_init(); |
1facf9fc | 21534 | + sysaufs_brs_init(); |
21535 | + au_debug_init(); | |
4a4d8108 | 21536 | + au_dy_init(); |
1facf9fc | 21537 | + err = sysaufs_init(); |
21538 | + if (unlikely(err)) | |
21539 | + goto out; | |
e49829fe | 21540 | + err = au_procfs_init(); |
4f0767ce | 21541 | + if (unlikely(err)) |
953406b4 | 21542 | + goto out_sysaufs; |
e49829fe JR |
21543 | + err = au_wkq_init(); |
21544 | + if (unlikely(err)) | |
21545 | + goto out_procfs; | |
87a755f4 | 21546 | + err = au_loopback_init(); |
1facf9fc | 21547 | + if (unlikely(err)) |
21548 | + goto out_wkq; | |
87a755f4 AM |
21549 | + err = au_hnotify_init(); |
21550 | + if (unlikely(err)) | |
21551 | + goto out_loopback; | |
1facf9fc | 21552 | + err = au_sysrq_init(); |
21553 | + if (unlikely(err)) | |
21554 | + goto out_hin; | |
21555 | + err = au_cache_init(); | |
21556 | + if (unlikely(err)) | |
21557 | + goto out_sysrq; | |
076b876e AM |
21558 | + |
21559 | + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0; | |
1facf9fc | 21560 | + err = register_filesystem(&aufs_fs_type); |
21561 | + if (unlikely(err)) | |
21562 | + goto out_cache; | |
076b876e | 21563 | + |
4a4d8108 AM |
21564 | + /* since we define pr_fmt, call printk directly */ |
21565 | + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n"); | |
1facf9fc | 21566 | + goto out; /* success */ |
21567 | + | |
4f0767ce | 21568 | +out_cache: |
1facf9fc | 21569 | + au_cache_fin(); |
4f0767ce | 21570 | +out_sysrq: |
1facf9fc | 21571 | + au_sysrq_fin(); |
4f0767ce | 21572 | +out_hin: |
4a4d8108 | 21573 | + au_hnotify_fin(); |
87a755f4 AM |
21574 | +out_loopback: |
21575 | + au_loopback_fin(); | |
4f0767ce | 21576 | +out_wkq: |
1facf9fc | 21577 | + au_wkq_fin(); |
e49829fe JR |
21578 | +out_procfs: |
21579 | + au_procfs_fin(); | |
4f0767ce | 21580 | +out_sysaufs: |
1facf9fc | 21581 | + sysaufs_fin(); |
4a4d8108 | 21582 | + au_dy_fin(); |
4f0767ce | 21583 | +out: |
1facf9fc | 21584 | + return err; |
21585 | +} | |
21586 | + | |
21587 | +static void __exit aufs_exit(void) | |
21588 | +{ | |
21589 | + unregister_filesystem(&aufs_fs_type); | |
21590 | + au_cache_fin(); | |
21591 | + au_sysrq_fin(); | |
4a4d8108 | 21592 | + au_hnotify_fin(); |
87a755f4 | 21593 | + au_loopback_fin(); |
1facf9fc | 21594 | + au_wkq_fin(); |
e49829fe | 21595 | + au_procfs_fin(); |
1facf9fc | 21596 | + sysaufs_fin(); |
4a4d8108 | 21597 | + au_dy_fin(); |
1facf9fc | 21598 | +} |
21599 | + | |
21600 | +module_init(aufs_init); | |
21601 | +module_exit(aufs_exit); | |
7f207e10 AM |
21602 | diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h |
21603 | --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 21604 | +++ linux/fs/aufs/module.h 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 21605 | @@ -0,0 +1,104 @@ |
1facf9fc | 21606 | +/* |
523b37e3 | 21607 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 21608 | + * |
21609 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21610 | + * it under the terms of the GNU General Public License as published by | |
21611 | + * the Free Software Foundation; either version 2 of the License, or | |
21612 | + * (at your option) any later version. | |
dece6358 AM |
21613 | + * |
21614 | + * This program is distributed in the hope that it will be useful, | |
21615 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21616 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21617 | + * GNU General Public License for more details. | |
21618 | + * | |
21619 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21620 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21621 | + */ |
21622 | + | |
21623 | +/* | |
21624 | + * module initialization and module-global | |
21625 | + */ | |
21626 | + | |
21627 | +#ifndef __AUFS_MODULE_H__ | |
21628 | +#define __AUFS_MODULE_H__ | |
21629 | + | |
21630 | +#ifdef __KERNEL__ | |
21631 | + | |
21632 | +#include <linux/slab.h> | |
21633 | + | |
dece6358 AM |
21634 | +struct path; |
21635 | +struct seq_file; | |
21636 | + | |
1facf9fc | 21637 | +/* module parameters */ |
1facf9fc | 21638 | +extern int sysaufs_brs; |
21639 | + | |
21640 | +/* ---------------------------------------------------------------------- */ | |
21641 | + | |
21642 | +extern int au_dir_roflags; | |
21643 | + | |
9dbd164d AM |
21644 | +enum { |
21645 | + AuLcNonDir_FIINFO, | |
21646 | + AuLcNonDir_DIINFO, | |
21647 | + AuLcNonDir_IIINFO, | |
21648 | + | |
21649 | + AuLcDir_FIINFO, | |
21650 | + AuLcDir_DIINFO, | |
21651 | + AuLcDir_IIINFO, | |
21652 | + | |
21653 | + AuLcSymlink_DIINFO, | |
21654 | + AuLcSymlink_IIINFO, | |
21655 | + | |
21656 | + AuLcKey_Last | |
21657 | +}; | |
21658 | +extern struct lock_class_key au_lc_key[AuLcKey_Last]; | |
21659 | + | |
1facf9fc | 21660 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp); |
21661 | +int au_seq_path(struct seq_file *seq, struct path *path); | |
21662 | + | |
e49829fe JR |
21663 | +#ifdef CONFIG_PROC_FS |
21664 | +/* procfs.c */ | |
21665 | +int __init au_procfs_init(void); | |
21666 | +void au_procfs_fin(void); | |
21667 | +#else | |
21668 | +AuStubInt0(au_procfs_init, void); | |
21669 | +AuStubVoid(au_procfs_fin, void); | |
21670 | +#endif | |
21671 | + | |
4f0767ce JR |
21672 | +/* ---------------------------------------------------------------------- */ |
21673 | + | |
21674 | +/* kmem cache */ | |
1facf9fc | 21675 | +enum { |
21676 | + AuCache_DINFO, | |
21677 | + AuCache_ICNTNR, | |
21678 | + AuCache_FINFO, | |
21679 | + AuCache_VDIR, | |
21680 | + AuCache_DEHSTR, | |
7eafdf33 | 21681 | + AuCache_HNOTIFY, /* must be last */ |
1facf9fc | 21682 | + AuCache_Last |
21683 | +}; | |
21684 | + | |
4a4d8108 AM |
21685 | +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD) |
21686 | +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags) | |
21687 | +#define AuCacheCtor(type, ctor) \ | |
21688 | + kmem_cache_create(#type, sizeof(struct type), \ | |
21689 | + __alignof__(struct type), AuCacheFlags, ctor) | |
1facf9fc | 21690 | + |
21691 | +extern struct kmem_cache *au_cachep[]; | |
21692 | + | |
21693 | +#define AuCacheFuncs(name, index) \ | |
4a4d8108 | 21694 | +static inline struct au_##name *au_cache_alloc_##name(void) \ |
1facf9fc | 21695 | +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \ |
4a4d8108 | 21696 | +static inline void au_cache_free_##name(struct au_##name *p) \ |
1facf9fc | 21697 | +{ kmem_cache_free(au_cachep[AuCache_##index], p); } |
21698 | + | |
21699 | +AuCacheFuncs(dinfo, DINFO); | |
21700 | +AuCacheFuncs(icntnr, ICNTNR); | |
21701 | +AuCacheFuncs(finfo, FINFO); | |
21702 | +AuCacheFuncs(vdir, VDIR); | |
4a4d8108 AM |
21703 | +AuCacheFuncs(vdir_dehstr, DEHSTR); |
21704 | +#ifdef CONFIG_AUFS_HNOTIFY | |
21705 | +AuCacheFuncs(hnotify, HNOTIFY); | |
21706 | +#endif | |
1facf9fc | 21707 | + |
4a4d8108 AM |
21708 | +#endif /* __KERNEL__ */ |
21709 | +#endif /* __AUFS_MODULE_H__ */ | |
c2b27bf2 AM |
21710 | diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c |
21711 | --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
21712 | +++ linux/fs/aufs/mvdown.c 2015-01-25 13:00:38.634380408 +0100 |
21713 | @@ -0,0 +1,694 @@ | |
c2b27bf2 | 21714 | +/* |
523b37e3 | 21715 | + * Copyright (C) 2011-2014 Junjiro R. Okajima |
c2b27bf2 AM |
21716 | + * |
21717 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21718 | + * it under the terms of the GNU General Public License as published by | |
21719 | + * the Free Software Foundation; either version 2 of the License, or | |
21720 | + * (at your option) any later version. | |
21721 | + * | |
21722 | + * This program is distributed in the hope that it will be useful, | |
21723 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21724 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21725 | + * GNU General Public License for more details. | |
21726 | + * | |
21727 | + * You should have received a copy of the GNU General Public License | |
523b37e3 AM |
21728 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21729 | + */ | |
21730 | + | |
21731 | +/* | |
21732 | + * move-down, opposite of copy-up | |
c2b27bf2 AM |
21733 | + */ |
21734 | + | |
21735 | +#include "aufs.h" | |
21736 | + | |
c2b27bf2 AM |
21737 | +struct au_mvd_args { |
21738 | + struct { | |
c2b27bf2 AM |
21739 | + struct super_block *h_sb; |
21740 | + struct dentry *h_parent; | |
21741 | + struct au_hinode *hdir; | |
392086de | 21742 | + struct inode *h_dir, *h_inode; |
c1595e42 | 21743 | + struct au_pin pin; |
c2b27bf2 AM |
21744 | + } info[AUFS_MVDOWN_NARRAY]; |
21745 | + | |
21746 | + struct aufs_mvdown mvdown; | |
21747 | + struct dentry *dentry, *parent; | |
21748 | + struct inode *inode, *dir; | |
21749 | + struct super_block *sb; | |
21750 | + aufs_bindex_t bopq, bwh, bfound; | |
21751 | + unsigned char rename_lock; | |
c2b27bf2 AM |
21752 | +}; |
21753 | + | |
392086de | 21754 | +#define mvd_errno mvdown.au_errno |
076b876e AM |
21755 | +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex |
21756 | +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid | |
21757 | +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex | |
21758 | +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid | |
c2b27bf2 | 21759 | + |
392086de AM |
21760 | +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb |
21761 | +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent | |
21762 | +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir | |
21763 | +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir | |
21764 | +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode | |
c1595e42 | 21765 | +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin |
392086de AM |
21766 | + |
21767 | +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb | |
21768 | +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent | |
21769 | +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir | |
21770 | +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir | |
21771 | +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode | |
c1595e42 | 21772 | +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin |
c2b27bf2 AM |
21773 | + |
21774 | +#define AU_MVD_PR(flag, ...) do { \ | |
21775 | + if (flag) \ | |
21776 | + pr_err(__VA_ARGS__); \ | |
21777 | + } while (0) | |
21778 | + | |
076b876e AM |
21779 | +static int find_lower_writable(struct au_mvd_args *a) |
21780 | +{ | |
21781 | + struct super_block *sb; | |
21782 | + aufs_bindex_t bindex, bend; | |
21783 | + struct au_branch *br; | |
21784 | + | |
21785 | + sb = a->sb; | |
21786 | + bindex = a->mvd_bsrc; | |
21787 | + bend = au_sbend(sb); | |
21788 | + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER) | |
21789 | + for (bindex++; bindex <= bend; bindex++) { | |
21790 | + br = au_sbr(sb, bindex); | |
21791 | + if (au_br_fhsm(br->br_perm) | |
21792 | + && (!(au_br_sb(br)->s_flags & MS_RDONLY))) | |
21793 | + return bindex; | |
21794 | + } | |
21795 | + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) | |
21796 | + for (bindex++; bindex <= bend; bindex++) { | |
21797 | + br = au_sbr(sb, bindex); | |
21798 | + if (!au_br_rdonly(br)) | |
21799 | + return bindex; | |
21800 | + } | |
21801 | + else | |
21802 | + for (bindex++; bindex <= bend; bindex++) { | |
21803 | + br = au_sbr(sb, bindex); | |
21804 | + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) { | |
21805 | + if (au_br_rdonly(br)) | |
21806 | + a->mvdown.flags | |
21807 | + |= AUFS_MVDOWN_ROLOWER_R; | |
21808 | + return bindex; | |
21809 | + } | |
21810 | + } | |
21811 | + | |
21812 | + return -1; | |
21813 | +} | |
21814 | + | |
c2b27bf2 | 21815 | +/* make the parent dir on bdst */ |
392086de | 21816 | +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
21817 | +{ |
21818 | + int err; | |
21819 | + | |
21820 | + err = 0; | |
21821 | + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc); | |
21822 | + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst); | |
21823 | + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc); | |
21824 | + a->mvd_h_dst_parent = NULL; | |
21825 | + if (au_dbend(a->parent) >= a->mvd_bdst) | |
21826 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
21827 | + if (!a->mvd_h_dst_parent) { | |
21828 | + err = au_cpdown_dirs(a->dentry, a->mvd_bdst); | |
21829 | + if (unlikely(err)) { | |
392086de | 21830 | + AU_MVD_PR(dmsg, "cpdown_dirs failed\n"); |
c2b27bf2 AM |
21831 | + goto out; |
21832 | + } | |
21833 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
21834 | + } | |
21835 | + | |
21836 | +out: | |
21837 | + AuTraceErr(err); | |
21838 | + return err; | |
21839 | +} | |
21840 | + | |
21841 | +/* lock them all */ | |
392086de | 21842 | +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
21843 | +{ |
21844 | + int err; | |
21845 | + struct dentry *h_trap; | |
21846 | + | |
21847 | + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc); | |
21848 | + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst); | |
c1595e42 JR |
21849 | + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst, |
21850 | + au_opt_udba(a->sb), | |
21851 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
21852 | + AuTraceErr(err); | |
21853 | + if (unlikely(err)) { | |
21854 | + AU_MVD_PR(dmsg, "pin_dst failed\n"); | |
21855 | + goto out; | |
21856 | + } | |
21857 | + | |
c2b27bf2 AM |
21858 | + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) { |
21859 | + a->rename_lock = 0; | |
c1595e42 JR |
21860 | + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, |
21861 | + AuLsc_DI_PARENT, AuLsc_I_PARENT3, | |
21862 | + au_opt_udba(a->sb), | |
21863 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
21864 | + err = au_do_pin(&a->mvd_pin_src); | |
21865 | + AuTraceErr(err); | |
21866 | + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode; | |
21867 | + if (unlikely(err)) { | |
21868 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
21869 | + goto out_dst; | |
21870 | + } | |
21871 | + goto out; /* success */ | |
c2b27bf2 AM |
21872 | + } |
21873 | + | |
c2b27bf2 | 21874 | + a->rename_lock = 1; |
c1595e42 JR |
21875 | + au_pin_hdir_unlock(&a->mvd_pin_dst); |
21876 | + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, | |
21877 | + au_opt_udba(a->sb), | |
21878 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
21879 | + AuTraceErr(err); | |
21880 | + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode; | |
21881 | + if (unlikely(err)) { | |
21882 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
21883 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
21884 | + goto out_dst; | |
21885 | + } | |
21886 | + au_pin_hdir_unlock(&a->mvd_pin_src); | |
c2b27bf2 AM |
21887 | + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
21888 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
21889 | + if (h_trap) { | |
21890 | + err = (h_trap != a->mvd_h_src_parent); | |
21891 | + if (err) | |
21892 | + err = (h_trap != a->mvd_h_dst_parent); | |
21893 | + } | |
21894 | + BUG_ON(err); /* it should never happen */ | |
c1595e42 JR |
21895 | + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) { |
21896 | + err = -EBUSY; | |
21897 | + AuTraceErr(err); | |
21898 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, | |
21899 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
21900 | + au_pin_hdir_lock(&a->mvd_pin_src); | |
21901 | + au_unpin(&a->mvd_pin_src); | |
21902 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
21903 | + goto out_dst; | |
21904 | + } | |
21905 | + goto out; /* success */ | |
c2b27bf2 | 21906 | + |
c1595e42 JR |
21907 | +out_dst: |
21908 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
21909 | +out: |
21910 | + AuTraceErr(err); | |
21911 | + return err; | |
21912 | +} | |
21913 | + | |
392086de | 21914 | +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 | 21915 | +{ |
c1595e42 JR |
21916 | + if (!a->rename_lock) |
21917 | + au_unpin(&a->mvd_pin_src); | |
21918 | + else { | |
c2b27bf2 AM |
21919 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
21920 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
c1595e42 JR |
21921 | + au_pin_hdir_lock(&a->mvd_pin_src); |
21922 | + au_unpin(&a->mvd_pin_src); | |
21923 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
21924 | + } | |
21925 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
21926 | +} |
21927 | + | |
21928 | +/* copy-down the file */ | |
392086de | 21929 | +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
21930 | +{ |
21931 | + int err; | |
21932 | + struct au_cp_generic cpg = { | |
21933 | + .dentry = a->dentry, | |
21934 | + .bdst = a->mvd_bdst, | |
21935 | + .bsrc = a->mvd_bsrc, | |
21936 | + .len = -1, | |
c1595e42 | 21937 | + .pin = &a->mvd_pin_dst, |
c2b27bf2 AM |
21938 | + .flags = AuCpup_DTIME | AuCpup_HOPEN |
21939 | + }; | |
21940 | + | |
21941 | + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst); | |
392086de AM |
21942 | + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER) |
21943 | + au_fset_cpup(cpg.flags, OVERWRITE); | |
21944 | + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER) | |
21945 | + au_fset_cpup(cpg.flags, RWDST); | |
c2b27bf2 AM |
21946 | + err = au_sio_cpdown_simple(&cpg); |
21947 | + if (unlikely(err)) | |
392086de | 21948 | + AU_MVD_PR(dmsg, "cpdown failed\n"); |
c2b27bf2 AM |
21949 | + |
21950 | + AuTraceErr(err); | |
21951 | + return err; | |
21952 | +} | |
21953 | + | |
21954 | +/* | |
21955 | + * unlink the whiteout on bdst if exist which may be created by UDBA while we | |
21956 | + * were sleeping | |
21957 | + */ | |
392086de | 21958 | +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
21959 | +{ |
21960 | + int err; | |
21961 | + struct path h_path; | |
21962 | + struct au_branch *br; | |
523b37e3 | 21963 | + struct inode *delegated; |
c2b27bf2 AM |
21964 | + |
21965 | + br = au_sbr(a->sb, a->mvd_bdst); | |
21966 | + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br); | |
21967 | + err = PTR_ERR(h_path.dentry); | |
21968 | + if (IS_ERR(h_path.dentry)) { | |
392086de | 21969 | + AU_MVD_PR(dmsg, "wh_lkup failed\n"); |
c2b27bf2 AM |
21970 | + goto out; |
21971 | + } | |
21972 | + | |
21973 | + err = 0; | |
21974 | + if (h_path.dentry->d_inode) { | |
21975 | + h_path.mnt = au_br_mnt(br); | |
523b37e3 | 21976 | + delegated = NULL; |
c2b27bf2 | 21977 | + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path, |
523b37e3 AM |
21978 | + &delegated, /*force*/0); |
21979 | + if (unlikely(err == -EWOULDBLOCK)) { | |
21980 | + pr_warn("cannot retry for NFSv4 delegation" | |
21981 | + " for an internal unlink\n"); | |
21982 | + iput(delegated); | |
21983 | + } | |
c2b27bf2 | 21984 | + if (unlikely(err)) |
392086de | 21985 | + AU_MVD_PR(dmsg, "wh_unlink failed\n"); |
c2b27bf2 AM |
21986 | + } |
21987 | + dput(h_path.dentry); | |
21988 | + | |
21989 | +out: | |
21990 | + AuTraceErr(err); | |
21991 | + return err; | |
21992 | +} | |
21993 | + | |
21994 | +/* | |
21995 | + * unlink the topmost h_dentry | |
c2b27bf2 | 21996 | + */ |
392086de | 21997 | +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
21998 | +{ |
21999 | + int err; | |
22000 | + struct path h_path; | |
523b37e3 | 22001 | + struct inode *delegated; |
c2b27bf2 AM |
22002 | + |
22003 | + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc); | |
22004 | + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc); | |
523b37e3 AM |
22005 | + delegated = NULL; |
22006 | + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0); | |
22007 | + if (unlikely(err == -EWOULDBLOCK)) { | |
22008 | + pr_warn("cannot retry for NFSv4 delegation" | |
22009 | + " for an internal unlink\n"); | |
22010 | + iput(delegated); | |
22011 | + } | |
c2b27bf2 | 22012 | + if (unlikely(err)) |
392086de | 22013 | + AU_MVD_PR(dmsg, "unlink failed\n"); |
c2b27bf2 AM |
22014 | + |
22015 | + AuTraceErr(err); | |
22016 | + return err; | |
22017 | +} | |
22018 | + | |
076b876e AM |
22019 | +/* Since mvdown succeeded, we ignore an error of this function */ |
22020 | +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a) | |
22021 | +{ | |
22022 | + int err; | |
22023 | + struct au_branch *br; | |
22024 | + | |
22025 | + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED; | |
22026 | + br = au_sbr(a->sb, a->mvd_bsrc); | |
22027 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs); | |
22028 | + if (!err) { | |
22029 | + br = au_sbr(a->sb, a->mvd_bdst); | |
22030 | + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id; | |
22031 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs); | |
22032 | + } | |
22033 | + if (!err) | |
22034 | + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED; | |
22035 | + else | |
22036 | + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err); | |
22037 | +} | |
22038 | + | |
c2b27bf2 AM |
22039 | +/* |
22040 | + * copy-down the file and unlink the bsrc file. | |
22041 | + * - unlink the bdst whout if exist | |
22042 | + * - copy-down the file (with whtmp name and rename) | |
22043 | + * - unlink the bsrc file | |
22044 | + */ | |
392086de | 22045 | +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22046 | +{ |
22047 | + int err; | |
22048 | + | |
392086de | 22049 | + err = au_do_mkdir(dmsg, a); |
c2b27bf2 | 22050 | + if (!err) |
392086de | 22051 | + err = au_do_lock(dmsg, a); |
c2b27bf2 AM |
22052 | + if (unlikely(err)) |
22053 | + goto out; | |
22054 | + | |
22055 | + /* | |
22056 | + * do not revert the activities we made on bdst since they should be | |
22057 | + * harmless in aufs. | |
22058 | + */ | |
22059 | + | |
392086de | 22060 | + err = au_do_cpdown(dmsg, a); |
c2b27bf2 | 22061 | + if (!err) |
392086de AM |
22062 | + err = au_do_unlink_wh(dmsg, a); |
22063 | + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
22064 | + err = au_do_unlink(dmsg, a); | |
c2b27bf2 AM |
22065 | + if (unlikely(err)) |
22066 | + goto out_unlock; | |
22067 | + | |
c1595e42 JR |
22068 | + AuDbg("%pd2, 0x%x, %d --> %d\n", |
22069 | + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst); | |
076b876e AM |
22070 | + if (find_lower_writable(a) < 0) |
22071 | + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM; | |
22072 | + | |
22073 | + if (a->mvdown.flags & AUFS_MVDOWN_STFS) | |
22074 | + au_do_stfs(dmsg, a); | |
22075 | + | |
c2b27bf2 | 22076 | + /* maintain internal array */ |
392086de AM |
22077 | + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) { |
22078 | + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL); | |
22079 | + au_set_dbstart(a->dentry, a->mvd_bdst); | |
22080 | + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0); | |
22081 | + au_set_ibstart(a->inode, a->mvd_bdst); | |
22082 | + } | |
c2b27bf2 AM |
22083 | + if (au_dbend(a->dentry) < a->mvd_bdst) |
22084 | + au_set_dbend(a->dentry, a->mvd_bdst); | |
c2b27bf2 AM |
22085 | + if (au_ibend(a->inode) < a->mvd_bdst) |
22086 | + au_set_ibend(a->inode, a->mvd_bdst); | |
22087 | + | |
22088 | +out_unlock: | |
392086de | 22089 | + au_do_unlock(dmsg, a); |
c2b27bf2 AM |
22090 | +out: |
22091 | + AuTraceErr(err); | |
22092 | + return err; | |
22093 | +} | |
22094 | + | |
22095 | +/* ---------------------------------------------------------------------- */ | |
22096 | + | |
c2b27bf2 | 22097 | +/* make sure the file is idle */ |
392086de | 22098 | +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22099 | +{ |
22100 | + int err, plinked; | |
c2b27bf2 AM |
22101 | + |
22102 | + err = 0; | |
c2b27bf2 AM |
22103 | + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK); |
22104 | + if (au_dbstart(a->dentry) == a->mvd_bsrc | |
c1595e42 | 22105 | + && au_dcount(a->dentry) == 1 |
c2b27bf2 | 22106 | + && atomic_read(&a->inode->i_count) == 1 |
392086de | 22107 | + /* && a->mvd_h_src_inode->i_nlink == 1 */ |
c2b27bf2 AM |
22108 | + && (!plinked || !au_plink_test(a->inode)) |
22109 | + && a->inode->i_nlink == 1) | |
22110 | + goto out; | |
22111 | + | |
22112 | + err = -EBUSY; | |
392086de | 22113 | + AU_MVD_PR(dmsg, |
c1595e42 JR |
22114 | + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n", |
22115 | + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry), | |
c2b27bf2 | 22116 | + atomic_read(&a->inode->i_count), a->inode->i_nlink, |
392086de | 22117 | + a->mvd_h_src_inode->i_nlink, |
c2b27bf2 AM |
22118 | + plinked, plinked ? au_plink_test(a->inode) : 0); |
22119 | + | |
22120 | +out: | |
22121 | + AuTraceErr(err); | |
22122 | + return err; | |
22123 | +} | |
22124 | + | |
22125 | +/* make sure the parent dir is fine */ | |
392086de | 22126 | +static int au_mvd_args_parent(const unsigned char dmsg, |
c2b27bf2 AM |
22127 | + struct au_mvd_args *a) |
22128 | +{ | |
22129 | + int err; | |
22130 | + aufs_bindex_t bindex; | |
22131 | + | |
22132 | + err = 0; | |
22133 | + if (unlikely(au_alive_dir(a->parent))) { | |
22134 | + err = -ENOENT; | |
392086de | 22135 | + AU_MVD_PR(dmsg, "parent dir is dead\n"); |
c2b27bf2 AM |
22136 | + goto out; |
22137 | + } | |
22138 | + | |
22139 | + a->bopq = au_dbdiropq(a->parent); | |
22140 | + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst); | |
22141 | + AuDbg("b%d\n", bindex); | |
22142 | + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst) | |
22143 | + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) { | |
22144 | + err = -EINVAL; | |
392086de AM |
22145 | + a->mvd_errno = EAU_MVDOWN_OPAQUE; |
22146 | + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n", | |
c2b27bf2 AM |
22147 | + a->bopq, a->mvd_bdst); |
22148 | + } | |
22149 | + | |
22150 | +out: | |
22151 | + AuTraceErr(err); | |
22152 | + return err; | |
22153 | +} | |
22154 | + | |
392086de | 22155 | +static int au_mvd_args_intermediate(const unsigned char dmsg, |
c2b27bf2 AM |
22156 | + struct au_mvd_args *a) |
22157 | +{ | |
22158 | + int err; | |
22159 | + struct au_dinfo *dinfo, *tmp; | |
22160 | + | |
22161 | + /* lookup the next lower positive entry */ | |
22162 | + err = -ENOMEM; | |
22163 | + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP); | |
22164 | + if (unlikely(!tmp)) | |
22165 | + goto out; | |
22166 | + | |
22167 | + a->bfound = -1; | |
22168 | + a->bwh = -1; | |
22169 | + dinfo = au_di(a->dentry); | |
22170 | + au_di_cp(tmp, dinfo); | |
22171 | + au_di_swap(tmp, dinfo); | |
22172 | + | |
22173 | + /* returns the number of positive dentries */ | |
22174 | + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0); | |
22175 | + if (!err) | |
22176 | + a->bwh = au_dbwh(a->dentry); | |
22177 | + else if (err > 0) | |
22178 | + a->bfound = au_dbstart(a->dentry); | |
22179 | + | |
22180 | + au_di_swap(tmp, dinfo); | |
22181 | + au_rw_write_unlock(&tmp->di_rwsem); | |
22182 | + au_di_free(tmp); | |
22183 | + if (unlikely(err < 0)) | |
392086de | 22184 | + AU_MVD_PR(dmsg, "failed look-up lower\n"); |
c2b27bf2 AM |
22185 | + |
22186 | + /* | |
22187 | + * here, we have these cases. | |
22188 | + * bfound == -1 | |
22189 | + * no positive dentry under bsrc. there are more sub-cases. | |
22190 | + * bwh < 0 | |
22191 | + * there no whiteout, we can safely move-down. | |
22192 | + * bwh <= bsrc | |
22193 | + * impossible | |
22194 | + * bsrc < bwh && bwh < bdst | |
22195 | + * there is a whiteout on RO branch. cannot proceed. | |
22196 | + * bwh == bdst | |
22197 | + * there is a whiteout on the RW target branch. it should | |
22198 | + * be removed. | |
22199 | + * bdst < bwh | |
22200 | + * there is a whiteout somewhere unrelated branch. | |
22201 | + * -1 < bfound && bfound <= bsrc | |
22202 | + * impossible. | |
22203 | + * bfound < bdst | |
22204 | + * found, but it is on RO branch between bsrc and bdst. cannot | |
22205 | + * proceed. | |
22206 | + * bfound == bdst | |
22207 | + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return | |
22208 | + * error. | |
22209 | + * bdst < bfound | |
22210 | + * found, after we create the file on bdst, it will be hidden. | |
22211 | + */ | |
22212 | + | |
22213 | + AuDebugOn(a->bfound == -1 | |
22214 | + && a->bwh != -1 | |
22215 | + && a->bwh <= a->mvd_bsrc); | |
22216 | + AuDebugOn(-1 < a->bfound | |
22217 | + && a->bfound <= a->mvd_bsrc); | |
22218 | + | |
22219 | + err = -EINVAL; | |
22220 | + if (a->bfound == -1 | |
22221 | + && a->mvd_bsrc < a->bwh | |
22222 | + && a->bwh != -1 | |
22223 | + && a->bwh < a->mvd_bdst) { | |
392086de AM |
22224 | + a->mvd_errno = EAU_MVDOWN_WHITEOUT; |
22225 | + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n", | |
c2b27bf2 AM |
22226 | + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh); |
22227 | + goto out; | |
22228 | + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) { | |
392086de AM |
22229 | + a->mvd_errno = EAU_MVDOWN_UPPER; |
22230 | + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n", | |
c2b27bf2 AM |
22231 | + a->mvd_bdst, a->bfound); |
22232 | + goto out; | |
22233 | + } | |
22234 | + | |
22235 | + err = 0; /* success */ | |
22236 | + | |
22237 | +out: | |
22238 | + AuTraceErr(err); | |
22239 | + return err; | |
22240 | +} | |
22241 | + | |
392086de | 22242 | +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22243 | +{ |
22244 | + int err; | |
22245 | + | |
392086de AM |
22246 | + err = 0; |
22247 | + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER) | |
22248 | + && a->bfound == a->mvd_bdst) | |
22249 | + err = -EEXIST; | |
c2b27bf2 AM |
22250 | + AuTraceErr(err); |
22251 | + return err; | |
22252 | +} | |
22253 | + | |
392086de | 22254 | +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
22255 | +{ |
22256 | + int err; | |
22257 | + struct au_branch *br; | |
22258 | + | |
22259 | + err = -EISDIR; | |
22260 | + if (unlikely(S_ISDIR(a->inode->i_mode))) | |
22261 | + goto out; | |
22262 | + | |
22263 | + err = -EINVAL; | |
392086de AM |
22264 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER)) |
22265 | + a->mvd_bsrc = au_ibstart(a->inode); | |
22266 | + else { | |
22267 | + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid); | |
22268 | + if (unlikely(a->mvd_bsrc < 0 | |
22269 | + || (a->mvd_bsrc < au_dbstart(a->dentry) | |
22270 | + || au_dbend(a->dentry) < a->mvd_bsrc | |
22271 | + || !au_h_dptr(a->dentry, a->mvd_bsrc)) | |
22272 | + || (a->mvd_bsrc < au_ibstart(a->inode) | |
22273 | + || au_ibend(a->inode) < a->mvd_bsrc | |
22274 | + || !au_h_iptr(a->inode, a->mvd_bsrc)))) { | |
22275 | + a->mvd_errno = EAU_MVDOWN_NOUPPER; | |
22276 | + AU_MVD_PR(dmsg, "no upper\n"); | |
22277 | + goto out; | |
22278 | + } | |
22279 | + } | |
c2b27bf2 | 22280 | + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) { |
392086de AM |
22281 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; |
22282 | + AU_MVD_PR(dmsg, "on the bottom\n"); | |
c2b27bf2 AM |
22283 | + goto out; |
22284 | + } | |
392086de | 22285 | + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc); |
c2b27bf2 AM |
22286 | + br = au_sbr(a->sb, a->mvd_bsrc); |
22287 | + err = au_br_rdonly(br); | |
392086de AM |
22288 | + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) { |
22289 | + if (unlikely(err)) | |
22290 | + goto out; | |
22291 | + } else if (!(vfsub_native_ro(a->mvd_h_src_inode) | |
22292 | + || IS_APPEND(a->mvd_h_src_inode))) { | |
22293 | + if (err) | |
22294 | + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R; | |
22295 | + /* go on */ | |
22296 | + } else | |
c2b27bf2 AM |
22297 | + goto out; |
22298 | + | |
22299 | + err = -EINVAL; | |
392086de AM |
22300 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) { |
22301 | + a->mvd_bdst = find_lower_writable(a); | |
22302 | + if (unlikely(a->mvd_bdst < 0)) { | |
22303 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; | |
22304 | + AU_MVD_PR(dmsg, "no writable lower branch\n"); | |
22305 | + goto out; | |
22306 | + } | |
22307 | + } else { | |
22308 | + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid); | |
22309 | + if (unlikely(a->mvd_bdst < 0 | |
22310 | + || au_sbend(a->sb) < a->mvd_bdst)) { | |
22311 | + a->mvd_errno = EAU_MVDOWN_NOLOWERBR; | |
22312 | + AU_MVD_PR(dmsg, "no lower brid\n"); | |
22313 | + goto out; | |
22314 | + } | |
c2b27bf2 AM |
22315 | + } |
22316 | + | |
392086de | 22317 | + err = au_mvd_args_busy(dmsg, a); |
c2b27bf2 | 22318 | + if (!err) |
392086de | 22319 | + err = au_mvd_args_parent(dmsg, a); |
c2b27bf2 | 22320 | + if (!err) |
392086de | 22321 | + err = au_mvd_args_intermediate(dmsg, a); |
c2b27bf2 | 22322 | + if (!err) |
392086de | 22323 | + err = au_mvd_args_exist(dmsg, a); |
c2b27bf2 AM |
22324 | + if (!err) |
22325 | + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst); | |
22326 | + | |
22327 | +out: | |
22328 | + AuTraceErr(err); | |
22329 | + return err; | |
22330 | +} | |
22331 | + | |
22332 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg) | |
22333 | +{ | |
392086de AM |
22334 | + int err, e; |
22335 | + unsigned char dmsg; | |
22336 | + struct au_mvd_args *args; | |
c2b27bf2 AM |
22337 | + |
22338 | + err = -EPERM; | |
22339 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
22340 | + goto out; | |
22341 | + | |
392086de AM |
22342 | + err = -ENOMEM; |
22343 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
22344 | + if (unlikely(!args)) | |
22345 | + goto out; | |
22346 | + | |
22347 | + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown)); | |
22348 | + if (!err) | |
22349 | + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg)); | |
c2b27bf2 AM |
22350 | + if (unlikely(err)) { |
22351 | + err = -EFAULT; | |
392086de AM |
22352 | + AuTraceErr(err); |
22353 | + goto out_free; | |
c2b27bf2 | 22354 | + } |
392086de AM |
22355 | + AuDbg("flags 0x%x\n", args->mvdown.flags); |
22356 | + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R); | |
22357 | + args->mvdown.au_errno = 0; | |
22358 | + args->dentry = dentry; | |
22359 | + args->inode = dentry->d_inode; | |
22360 | + args->sb = dentry->d_sb; | |
c2b27bf2 | 22361 | + |
392086de AM |
22362 | + err = -ENOENT; |
22363 | + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG); | |
22364 | + args->parent = dget_parent(dentry); | |
22365 | + args->dir = args->parent->d_inode; | |
22366 | + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT); | |
22367 | + dput(args->parent); | |
22368 | + if (unlikely(args->parent != dentry->d_parent)) { | |
22369 | + AU_MVD_PR(dmsg, "parent dir is moved\n"); | |
c2b27bf2 AM |
22370 | + goto out_dir; |
22371 | + } | |
22372 | + | |
392086de | 22373 | + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD); |
c2b27bf2 AM |
22374 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH); |
22375 | + if (unlikely(err)) | |
22376 | + goto out_inode; | |
22377 | + | |
392086de AM |
22378 | + di_write_lock_parent(args->parent); |
22379 | + err = au_mvd_args(dmsg, args); | |
c2b27bf2 AM |
22380 | + if (unlikely(err)) |
22381 | + goto out_parent; | |
22382 | + | |
392086de | 22383 | + err = au_do_mvdown(dmsg, args); |
c2b27bf2 AM |
22384 | + if (unlikely(err)) |
22385 | + goto out_parent; | |
c2b27bf2 | 22386 | + |
392086de AM |
22387 | + au_cpup_attr_timesizes(args->dir); |
22388 | + au_cpup_attr_timesizes(args->inode); | |
22389 | + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst)); | |
c2b27bf2 AM |
22390 | + /* au_digen_dec(dentry); */ |
22391 | + | |
22392 | +out_parent: | |
392086de | 22393 | + di_write_unlock(args->parent); |
c2b27bf2 AM |
22394 | + aufs_read_unlock(dentry, AuLock_DW); |
22395 | +out_inode: | |
392086de | 22396 | + mutex_unlock(&args->inode->i_mutex); |
c2b27bf2 | 22397 | +out_dir: |
392086de AM |
22398 | + mutex_unlock(&args->dir->i_mutex); |
22399 | +out_free: | |
22400 | + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown)); | |
22401 | + if (unlikely(e)) | |
22402 | + err = -EFAULT; | |
22403 | + kfree(args); | |
c2b27bf2 AM |
22404 | +out: |
22405 | + AuTraceErr(err); | |
22406 | + return err; | |
22407 | +} | |
22408 | diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c | |
22409 | --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
22410 | +++ linux/fs/aufs/opts.c 2015-01-25 13:00:38.634380408 +0100 |
22411 | @@ -0,0 +1,1850 @@ | |
1facf9fc | 22412 | +/* |
523b37e3 | 22413 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 22414 | + * |
22415 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22416 | + * it under the terms of the GNU General Public License as published by | |
22417 | + * the Free Software Foundation; either version 2 of the License, or | |
22418 | + * (at your option) any later version. | |
dece6358 AM |
22419 | + * |
22420 | + * This program is distributed in the hope that it will be useful, | |
22421 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22422 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22423 | + * GNU General Public License for more details. | |
22424 | + * | |
22425 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22426 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22427 | + */ |
22428 | + | |
22429 | +/* | |
22430 | + * mount options/flags | |
22431 | + */ | |
22432 | + | |
dece6358 | 22433 | +#include <linux/namei.h> |
1facf9fc | 22434 | +#include <linux/types.h> /* a distribution requires */ |
22435 | +#include <linux/parser.h> | |
22436 | +#include "aufs.h" | |
22437 | + | |
22438 | +/* ---------------------------------------------------------------------- */ | |
22439 | + | |
22440 | +enum { | |
22441 | + Opt_br, | |
22442 | + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend, | |
22443 | + Opt_idel, Opt_imod, Opt_ireorder, | |
22444 | + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir, | |
dece6358 | 22445 | + Opt_rdblk_def, Opt_rdhash_def, |
1facf9fc | 22446 | + Opt_xino, Opt_zxino, Opt_noxino, |
22447 | + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino, | |
22448 | + Opt_trunc_xino_path, Opt_itrunc_xino, | |
22449 | + Opt_trunc_xib, Opt_notrunc_xib, | |
dece6358 | 22450 | + Opt_shwh, Opt_noshwh, |
1facf9fc | 22451 | + Opt_plink, Opt_noplink, Opt_list_plink, |
22452 | + Opt_udba, | |
4a4d8108 | 22453 | + Opt_dio, Opt_nodio, |
1facf9fc | 22454 | + /* Opt_lock, Opt_unlock, */ |
22455 | + Opt_cmd, Opt_cmd_args, | |
22456 | + Opt_diropq_a, Opt_diropq_w, | |
22457 | + Opt_warn_perm, Opt_nowarn_perm, | |
22458 | + Opt_wbr_copyup, Opt_wbr_create, | |
076b876e | 22459 | + Opt_fhsm_sec, |
1facf9fc | 22460 | + Opt_refrof, Opt_norefrof, |
22461 | + Opt_verbose, Opt_noverbose, | |
22462 | + Opt_sum, Opt_nosum, Opt_wsum, | |
076b876e | 22463 | + Opt_dirperm1, Opt_nodirperm1, |
c1595e42 | 22464 | + Opt_acl, Opt_noacl, |
1facf9fc | 22465 | + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err |
22466 | +}; | |
22467 | + | |
22468 | +static match_table_t options = { | |
22469 | + {Opt_br, "br=%s"}, | |
22470 | + {Opt_br, "br:%s"}, | |
22471 | + | |
22472 | + {Opt_add, "add=%d:%s"}, | |
22473 | + {Opt_add, "add:%d:%s"}, | |
22474 | + {Opt_add, "ins=%d:%s"}, | |
22475 | + {Opt_add, "ins:%d:%s"}, | |
22476 | + {Opt_append, "append=%s"}, | |
22477 | + {Opt_append, "append:%s"}, | |
22478 | + {Opt_prepend, "prepend=%s"}, | |
22479 | + {Opt_prepend, "prepend:%s"}, | |
22480 | + | |
22481 | + {Opt_del, "del=%s"}, | |
22482 | + {Opt_del, "del:%s"}, | |
22483 | + /* {Opt_idel, "idel:%d"}, */ | |
22484 | + {Opt_mod, "mod=%s"}, | |
22485 | + {Opt_mod, "mod:%s"}, | |
22486 | + /* {Opt_imod, "imod:%d:%s"}, */ | |
22487 | + | |
22488 | + {Opt_dirwh, "dirwh=%d"}, | |
22489 | + | |
22490 | + {Opt_xino, "xino=%s"}, | |
22491 | + {Opt_noxino, "noxino"}, | |
22492 | + {Opt_trunc_xino, "trunc_xino"}, | |
22493 | + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"}, | |
22494 | + {Opt_notrunc_xino, "notrunc_xino"}, | |
22495 | + {Opt_trunc_xino_path, "trunc_xino=%s"}, | |
22496 | + {Opt_itrunc_xino, "itrunc_xino=%d"}, | |
22497 | + /* {Opt_zxino, "zxino=%s"}, */ | |
22498 | + {Opt_trunc_xib, "trunc_xib"}, | |
22499 | + {Opt_notrunc_xib, "notrunc_xib"}, | |
22500 | + | |
e49829fe | 22501 | +#ifdef CONFIG_PROC_FS |
1facf9fc | 22502 | + {Opt_plink, "plink"}, |
e49829fe JR |
22503 | +#else |
22504 | + {Opt_ignore_silent, "plink"}, | |
22505 | +#endif | |
22506 | + | |
1facf9fc | 22507 | + {Opt_noplink, "noplink"}, |
e49829fe | 22508 | + |
1facf9fc | 22509 | +#ifdef CONFIG_AUFS_DEBUG |
22510 | + {Opt_list_plink, "list_plink"}, | |
22511 | +#endif | |
22512 | + | |
22513 | + {Opt_udba, "udba=%s"}, | |
22514 | + | |
4a4d8108 AM |
22515 | + {Opt_dio, "dio"}, |
22516 | + {Opt_nodio, "nodio"}, | |
22517 | + | |
076b876e AM |
22518 | +#ifdef CONFIG_AUFS_FHSM |
22519 | + {Opt_fhsm_sec, "fhsm_sec=%d"}, | |
22520 | +#else | |
22521 | + {Opt_ignore_silent, "fhsm_sec=%d"}, | |
22522 | +#endif | |
22523 | + | |
1facf9fc | 22524 | + {Opt_diropq_a, "diropq=always"}, |
22525 | + {Opt_diropq_a, "diropq=a"}, | |
22526 | + {Opt_diropq_w, "diropq=whiteouted"}, | |
22527 | + {Opt_diropq_w, "diropq=w"}, | |
22528 | + | |
22529 | + {Opt_warn_perm, "warn_perm"}, | |
22530 | + {Opt_nowarn_perm, "nowarn_perm"}, | |
22531 | + | |
22532 | + /* keep them temporary */ | |
1facf9fc | 22533 | + {Opt_ignore_silent, "nodlgt"}, |
1facf9fc | 22534 | + {Opt_ignore_silent, "clean_plink"}, |
22535 | + | |
dece6358 AM |
22536 | +#ifdef CONFIG_AUFS_SHWH |
22537 | + {Opt_shwh, "shwh"}, | |
22538 | +#endif | |
22539 | + {Opt_noshwh, "noshwh"}, | |
22540 | + | |
076b876e AM |
22541 | + {Opt_dirperm1, "dirperm1"}, |
22542 | + {Opt_nodirperm1, "nodirperm1"}, | |
22543 | + | |
1facf9fc | 22544 | + {Opt_rendir, "rendir=%d"}, |
22545 | + | |
22546 | + {Opt_refrof, "refrof"}, | |
22547 | + {Opt_norefrof, "norefrof"}, | |
22548 | + | |
22549 | + {Opt_verbose, "verbose"}, | |
22550 | + {Opt_verbose, "v"}, | |
22551 | + {Opt_noverbose, "noverbose"}, | |
22552 | + {Opt_noverbose, "quiet"}, | |
22553 | + {Opt_noverbose, "q"}, | |
22554 | + {Opt_noverbose, "silent"}, | |
22555 | + | |
22556 | + {Opt_sum, "sum"}, | |
22557 | + {Opt_nosum, "nosum"}, | |
22558 | + {Opt_wsum, "wsum"}, | |
22559 | + | |
22560 | + {Opt_rdcache, "rdcache=%d"}, | |
22561 | + {Opt_rdblk, "rdblk=%d"}, | |
dece6358 | 22562 | + {Opt_rdblk_def, "rdblk=def"}, |
1facf9fc | 22563 | + {Opt_rdhash, "rdhash=%d"}, |
dece6358 | 22564 | + {Opt_rdhash_def, "rdhash=def"}, |
1facf9fc | 22565 | + |
22566 | + {Opt_wbr_create, "create=%s"}, | |
22567 | + {Opt_wbr_create, "create_policy=%s"}, | |
22568 | + {Opt_wbr_copyup, "cpup=%s"}, | |
22569 | + {Opt_wbr_copyup, "copyup=%s"}, | |
22570 | + {Opt_wbr_copyup, "copyup_policy=%s"}, | |
22571 | + | |
c1595e42 JR |
22572 | + /* generic VFS flag */ |
22573 | +#ifdef CONFIG_FS_POSIX_ACL | |
22574 | + {Opt_acl, "acl"}, | |
22575 | + {Opt_noacl, "noacl"}, | |
22576 | +#else | |
22577 | + {Opt_ignore_silent, "acl"}, | |
22578 | + {Opt_ignore_silent, "noacl"}, | |
22579 | +#endif | |
22580 | + | |
1facf9fc | 22581 | + /* internal use for the scripts */ |
22582 | + {Opt_ignore_silent, "si=%s"}, | |
22583 | + | |
22584 | + {Opt_br, "dirs=%s"}, | |
22585 | + {Opt_ignore, "debug=%d"}, | |
22586 | + {Opt_ignore, "delete=whiteout"}, | |
22587 | + {Opt_ignore, "delete=all"}, | |
22588 | + {Opt_ignore, "imap=%s"}, | |
22589 | + | |
1308ab2a | 22590 | + /* temporary workaround, due to old mount(8)? */ |
22591 | + {Opt_ignore_silent, "relatime"}, | |
22592 | + | |
1facf9fc | 22593 | + {Opt_err, NULL} |
22594 | +}; | |
22595 | + | |
22596 | +/* ---------------------------------------------------------------------- */ | |
22597 | + | |
076b876e | 22598 | +static const char *au_parser_pattern(int val, match_table_t tbl) |
1facf9fc | 22599 | +{ |
076b876e AM |
22600 | + struct match_token *p; |
22601 | + | |
22602 | + p = tbl; | |
22603 | + while (p->pattern) { | |
22604 | + if (p->token == val) | |
22605 | + return p->pattern; | |
22606 | + p++; | |
1facf9fc | 22607 | + } |
22608 | + BUG(); | |
22609 | + return "??"; | |
22610 | +} | |
22611 | + | |
076b876e AM |
22612 | +static const char *au_optstr(int *val, match_table_t tbl) |
22613 | +{ | |
22614 | + struct match_token *p; | |
22615 | + int v; | |
22616 | + | |
22617 | + v = *val; | |
22618 | + p = tbl; | |
22619 | + while (p->token) { | |
22620 | + if ((v & p->token) == p->token) { | |
22621 | + *val &= ~p->token; | |
22622 | + return p->pattern; | |
22623 | + } | |
22624 | + p++; | |
22625 | + } | |
22626 | + return NULL; | |
22627 | +} | |
22628 | + | |
1facf9fc | 22629 | +/* ---------------------------------------------------------------------- */ |
22630 | + | |
1e00d052 | 22631 | +static match_table_t brperm = { |
1facf9fc | 22632 | + {AuBrPerm_RO, AUFS_BRPERM_RO}, |
22633 | + {AuBrPerm_RR, AUFS_BRPERM_RR}, | |
22634 | + {AuBrPerm_RW, AUFS_BRPERM_RW}, | |
1e00d052 AM |
22635 | + {0, NULL} |
22636 | +}; | |
1facf9fc | 22637 | + |
86dc4139 | 22638 | +static match_table_t brattr = { |
076b876e AM |
22639 | + /* general */ |
22640 | + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG}, | |
22641 | + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL}, | |
c1595e42 | 22642 | + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */ |
86dc4139 | 22643 | + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN}, |
076b876e | 22644 | + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM}, |
c1595e42 JR |
22645 | + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX}, |
22646 | + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC}, | |
22647 | + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS}, | |
22648 | + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR}, | |
22649 | + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR}, | |
22650 | + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH}, | |
076b876e AM |
22651 | + |
22652 | + /* ro/rr branch */ | |
1e00d052 | 22653 | + {AuBrRAttr_WH, AUFS_BRRATTR_WH}, |
076b876e AM |
22654 | + |
22655 | + /* rw branch */ | |
22656 | + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO}, | |
1e00d052 | 22657 | + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH}, |
076b876e | 22658 | + |
1e00d052 | 22659 | + {0, NULL} |
1facf9fc | 22660 | +}; |
22661 | + | |
1e00d052 AM |
22662 | +static int br_attr_val(char *str, match_table_t table, substring_t args[]) |
22663 | +{ | |
22664 | + int attr, v; | |
22665 | + char *p; | |
22666 | + | |
22667 | + attr = 0; | |
22668 | + do { | |
22669 | + p = strchr(str, '+'); | |
22670 | + if (p) | |
22671 | + *p = 0; | |
22672 | + v = match_token(str, table, args); | |
076b876e AM |
22673 | + if (v) { |
22674 | + if (v & AuBrAttr_CMOO_Mask) | |
22675 | + attr &= ~AuBrAttr_CMOO_Mask; | |
1e00d052 | 22676 | + attr |= v; |
076b876e | 22677 | + } else { |
1e00d052 AM |
22678 | + if (p) |
22679 | + *p = '+'; | |
0c3ec466 | 22680 | + pr_warn("ignored branch attribute %s\n", str); |
1e00d052 AM |
22681 | + break; |
22682 | + } | |
22683 | + if (p) | |
22684 | + str = p + 1; | |
22685 | + } while (p); | |
22686 | + | |
22687 | + return attr; | |
22688 | +} | |
22689 | + | |
076b876e AM |
22690 | +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm) |
22691 | +{ | |
22692 | + int sz; | |
22693 | + const char *p; | |
22694 | + char *q; | |
22695 | + | |
076b876e AM |
22696 | + q = str->a; |
22697 | + *q = 0; | |
22698 | + p = au_optstr(&perm, brattr); | |
22699 | + if (p) { | |
22700 | + sz = strlen(p); | |
22701 | + memcpy(q, p, sz + 1); | |
22702 | + q += sz; | |
22703 | + } else | |
22704 | + goto out; | |
22705 | + | |
22706 | + do { | |
22707 | + p = au_optstr(&perm, brattr); | |
22708 | + if (p) { | |
22709 | + *q++ = '+'; | |
22710 | + sz = strlen(p); | |
22711 | + memcpy(q, p, sz + 1); | |
22712 | + q += sz; | |
22713 | + } | |
22714 | + } while (p); | |
22715 | + | |
22716 | +out: | |
c1595e42 | 22717 | + return q - str->a; |
076b876e AM |
22718 | +} |
22719 | + | |
4a4d8108 | 22720 | +static int noinline_for_stack br_perm_val(char *perm) |
1facf9fc | 22721 | +{ |
076b876e AM |
22722 | + int val, bad, sz; |
22723 | + char *p; | |
1facf9fc | 22724 | + substring_t args[MAX_OPT_ARGS]; |
076b876e | 22725 | + au_br_perm_str_t attr; |
1facf9fc | 22726 | + |
1e00d052 AM |
22727 | + p = strchr(perm, '+'); |
22728 | + if (p) | |
22729 | + *p = 0; | |
22730 | + val = match_token(perm, brperm, args); | |
22731 | + if (!val) { | |
22732 | + if (p) | |
22733 | + *p = '+'; | |
0c3ec466 | 22734 | + pr_warn("ignored branch permission %s\n", perm); |
1e00d052 AM |
22735 | + val = AuBrPerm_RO; |
22736 | + goto out; | |
22737 | + } | |
22738 | + if (!p) | |
22739 | + goto out; | |
22740 | + | |
076b876e AM |
22741 | + val |= br_attr_val(p + 1, brattr, args); |
22742 | + | |
22743 | + bad = 0; | |
86dc4139 | 22744 | + switch (val & AuBrPerm_Mask) { |
1e00d052 AM |
22745 | + case AuBrPerm_RO: |
22746 | + case AuBrPerm_RR: | |
076b876e AM |
22747 | + bad = val & AuBrWAttr_Mask; |
22748 | + val &= ~AuBrWAttr_Mask; | |
1e00d052 AM |
22749 | + break; |
22750 | + case AuBrPerm_RW: | |
076b876e AM |
22751 | + bad = val & AuBrRAttr_Mask; |
22752 | + val &= ~AuBrRAttr_Mask; | |
1e00d052 AM |
22753 | + break; |
22754 | + } | |
c1595e42 JR |
22755 | + |
22756 | + /* | |
22757 | + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs | |
22758 | + * does not treat it as an error, just warning. | |
22759 | + * this is a tiny guard for the user operation. | |
22760 | + */ | |
22761 | + if (val & AuBrAttr_UNPIN) { | |
22762 | + bad |= AuBrAttr_UNPIN; | |
22763 | + val &= ~AuBrAttr_UNPIN; | |
22764 | + } | |
22765 | + | |
076b876e AM |
22766 | + if (unlikely(bad)) { |
22767 | + sz = au_do_optstr_br_attr(&attr, bad); | |
22768 | + AuDebugOn(!sz); | |
22769 | + pr_warn("ignored branch attribute %s\n", attr.a); | |
22770 | + } | |
1e00d052 AM |
22771 | + |
22772 | +out: | |
1facf9fc | 22773 | + return val; |
22774 | +} | |
22775 | + | |
076b876e | 22776 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm) |
1facf9fc | 22777 | +{ |
076b876e AM |
22778 | + au_br_perm_str_t attr; |
22779 | + const char *p; | |
22780 | + char *q; | |
1e00d052 AM |
22781 | + int sz; |
22782 | + | |
076b876e AM |
22783 | + q = str->a; |
22784 | + p = au_optstr(&perm, brperm); | |
22785 | + AuDebugOn(!p || !*p); | |
22786 | + sz = strlen(p); | |
22787 | + memcpy(q, p, sz + 1); | |
22788 | + q += sz; | |
1e00d052 | 22789 | + |
076b876e AM |
22790 | + sz = au_do_optstr_br_attr(&attr, perm); |
22791 | + if (sz) { | |
22792 | + *q++ = '+'; | |
22793 | + memcpy(q, attr.a, sz + 1); | |
1e00d052 AM |
22794 | + } |
22795 | + | |
076b876e | 22796 | + AuDebugOn(strlen(str->a) >= sizeof(str->a)); |
1facf9fc | 22797 | +} |
22798 | + | |
22799 | +/* ---------------------------------------------------------------------- */ | |
22800 | + | |
22801 | +static match_table_t udbalevel = { | |
22802 | + {AuOpt_UDBA_REVAL, "reval"}, | |
22803 | + {AuOpt_UDBA_NONE, "none"}, | |
4a4d8108 AM |
22804 | +#ifdef CONFIG_AUFS_HNOTIFY |
22805 | + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */ | |
22806 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
22807 | + {AuOpt_UDBA_HNOTIFY, "fsnotify"}, | |
4a4d8108 | 22808 | +#endif |
1facf9fc | 22809 | +#endif |
22810 | + {-1, NULL} | |
22811 | +}; | |
22812 | + | |
4a4d8108 | 22813 | +static int noinline_for_stack udba_val(char *str) |
1facf9fc | 22814 | +{ |
22815 | + substring_t args[MAX_OPT_ARGS]; | |
22816 | + | |
7f207e10 | 22817 | + return match_token(str, udbalevel, args); |
1facf9fc | 22818 | +} |
22819 | + | |
22820 | +const char *au_optstr_udba(int udba) | |
22821 | +{ | |
076b876e | 22822 | + return au_parser_pattern(udba, udbalevel); |
1facf9fc | 22823 | +} |
22824 | + | |
22825 | +/* ---------------------------------------------------------------------- */ | |
22826 | + | |
22827 | +static match_table_t au_wbr_create_policy = { | |
22828 | + {AuWbrCreate_TDP, "tdp"}, | |
22829 | + {AuWbrCreate_TDP, "top-down-parent"}, | |
22830 | + {AuWbrCreate_RR, "rr"}, | |
22831 | + {AuWbrCreate_RR, "round-robin"}, | |
22832 | + {AuWbrCreate_MFS, "mfs"}, | |
22833 | + {AuWbrCreate_MFS, "most-free-space"}, | |
22834 | + {AuWbrCreate_MFSV, "mfs:%d"}, | |
22835 | + {AuWbrCreate_MFSV, "most-free-space:%d"}, | |
22836 | + | |
22837 | + {AuWbrCreate_MFSRR, "mfsrr:%d"}, | |
22838 | + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"}, | |
22839 | + {AuWbrCreate_PMFS, "pmfs"}, | |
22840 | + {AuWbrCreate_PMFSV, "pmfs:%d"}, | |
392086de AM |
22841 | + {AuWbrCreate_PMFSRR, "pmfsrr:%d"}, |
22842 | + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"}, | |
1facf9fc | 22843 | + |
22844 | + {-1, NULL} | |
22845 | +}; | |
22846 | + | |
dece6358 AM |
22847 | +/* |
22848 | + * cf. linux/lib/parser.c and cmdline.c | |
22849 | + * gave up calling memparse() since it uses simple_strtoull() instead of | |
9dbd164d | 22850 | + * kstrto...(). |
dece6358 | 22851 | + */ |
4a4d8108 AM |
22852 | +static int noinline_for_stack |
22853 | +au_match_ull(substring_t *s, unsigned long long *result) | |
1facf9fc | 22854 | +{ |
22855 | + int err; | |
22856 | + unsigned int len; | |
22857 | + char a[32]; | |
22858 | + | |
22859 | + err = -ERANGE; | |
22860 | + len = s->to - s->from; | |
22861 | + if (len + 1 <= sizeof(a)) { | |
22862 | + memcpy(a, s->from, len); | |
22863 | + a[len] = '\0'; | |
9dbd164d | 22864 | + err = kstrtoull(a, 0, result); |
1facf9fc | 22865 | + } |
22866 | + return err; | |
22867 | +} | |
22868 | + | |
22869 | +static int au_wbr_mfs_wmark(substring_t *arg, char *str, | |
22870 | + struct au_opt_wbr_create *create) | |
22871 | +{ | |
22872 | + int err; | |
22873 | + unsigned long long ull; | |
22874 | + | |
22875 | + err = 0; | |
22876 | + if (!au_match_ull(arg, &ull)) | |
22877 | + create->mfsrr_watermark = ull; | |
22878 | + else { | |
4a4d8108 | 22879 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 22880 | + err = -EINVAL; |
22881 | + } | |
22882 | + | |
22883 | + return err; | |
22884 | +} | |
22885 | + | |
22886 | +static int au_wbr_mfs_sec(substring_t *arg, char *str, | |
22887 | + struct au_opt_wbr_create *create) | |
22888 | +{ | |
22889 | + int n, err; | |
22890 | + | |
22891 | + err = 0; | |
027c5e7a | 22892 | + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC) |
1facf9fc | 22893 | + create->mfs_second = n; |
22894 | + else { | |
4a4d8108 | 22895 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 22896 | + err = -EINVAL; |
22897 | + } | |
22898 | + | |
22899 | + return err; | |
22900 | +} | |
22901 | + | |
4a4d8108 AM |
22902 | +static int noinline_for_stack |
22903 | +au_wbr_create_val(char *str, struct au_opt_wbr_create *create) | |
1facf9fc | 22904 | +{ |
22905 | + int err, e; | |
22906 | + substring_t args[MAX_OPT_ARGS]; | |
22907 | + | |
22908 | + err = match_token(str, au_wbr_create_policy, args); | |
22909 | + create->wbr_create = err; | |
22910 | + switch (err) { | |
22911 | + case AuWbrCreate_MFSRRV: | |
392086de | 22912 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 22913 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
22914 | + if (!e) | |
22915 | + e = au_wbr_mfs_sec(&args[1], str, create); | |
22916 | + if (unlikely(e)) | |
22917 | + err = e; | |
22918 | + break; | |
22919 | + case AuWbrCreate_MFSRR: | |
392086de | 22920 | + case AuWbrCreate_PMFSRR: |
1facf9fc | 22921 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
22922 | + if (unlikely(e)) { | |
22923 | + err = e; | |
22924 | + break; | |
22925 | + } | |
22926 | + /*FALLTHROUGH*/ | |
22927 | + case AuWbrCreate_MFS: | |
22928 | + case AuWbrCreate_PMFS: | |
027c5e7a | 22929 | + create->mfs_second = AUFS_MFS_DEF_SEC; |
1facf9fc | 22930 | + break; |
22931 | + case AuWbrCreate_MFSV: | |
22932 | + case AuWbrCreate_PMFSV: | |
22933 | + e = au_wbr_mfs_sec(&args[0], str, create); | |
22934 | + if (unlikely(e)) | |
22935 | + err = e; | |
22936 | + break; | |
22937 | + } | |
22938 | + | |
22939 | + return err; | |
22940 | +} | |
22941 | + | |
22942 | +const char *au_optstr_wbr_create(int wbr_create) | |
22943 | +{ | |
076b876e | 22944 | + return au_parser_pattern(wbr_create, au_wbr_create_policy); |
1facf9fc | 22945 | +} |
22946 | + | |
22947 | +static match_table_t au_wbr_copyup_policy = { | |
22948 | + {AuWbrCopyup_TDP, "tdp"}, | |
22949 | + {AuWbrCopyup_TDP, "top-down-parent"}, | |
22950 | + {AuWbrCopyup_BUP, "bup"}, | |
22951 | + {AuWbrCopyup_BUP, "bottom-up-parent"}, | |
22952 | + {AuWbrCopyup_BU, "bu"}, | |
22953 | + {AuWbrCopyup_BU, "bottom-up"}, | |
22954 | + {-1, NULL} | |
22955 | +}; | |
22956 | + | |
4a4d8108 | 22957 | +static int noinline_for_stack au_wbr_copyup_val(char *str) |
1facf9fc | 22958 | +{ |
22959 | + substring_t args[MAX_OPT_ARGS]; | |
22960 | + | |
22961 | + return match_token(str, au_wbr_copyup_policy, args); | |
22962 | +} | |
22963 | + | |
22964 | +const char *au_optstr_wbr_copyup(int wbr_copyup) | |
22965 | +{ | |
076b876e | 22966 | + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy); |
1facf9fc | 22967 | +} |
22968 | + | |
22969 | +/* ---------------------------------------------------------------------- */ | |
22970 | + | |
22971 | +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY; | |
22972 | + | |
22973 | +static void dump_opts(struct au_opts *opts) | |
22974 | +{ | |
22975 | +#ifdef CONFIG_AUFS_DEBUG | |
22976 | + /* reduce stack space */ | |
22977 | + union { | |
22978 | + struct au_opt_add *add; | |
22979 | + struct au_opt_del *del; | |
22980 | + struct au_opt_mod *mod; | |
22981 | + struct au_opt_xino *xino; | |
22982 | + struct au_opt_xino_itrunc *xino_itrunc; | |
22983 | + struct au_opt_wbr_create *create; | |
22984 | + } u; | |
22985 | + struct au_opt *opt; | |
22986 | + | |
22987 | + opt = opts->opt; | |
22988 | + while (opt->type != Opt_tail) { | |
22989 | + switch (opt->type) { | |
22990 | + case Opt_add: | |
22991 | + u.add = &opt->add; | |
22992 | + AuDbg("add {b%d, %s, 0x%x, %p}\n", | |
22993 | + u.add->bindex, u.add->pathname, u.add->perm, | |
22994 | + u.add->path.dentry); | |
22995 | + break; | |
22996 | + case Opt_del: | |
22997 | + case Opt_idel: | |
22998 | + u.del = &opt->del; | |
22999 | + AuDbg("del {%s, %p}\n", | |
23000 | + u.del->pathname, u.del->h_path.dentry); | |
23001 | + break; | |
23002 | + case Opt_mod: | |
23003 | + case Opt_imod: | |
23004 | + u.mod = &opt->mod; | |
23005 | + AuDbg("mod {%s, 0x%x, %p}\n", | |
23006 | + u.mod->path, u.mod->perm, u.mod->h_root); | |
23007 | + break; | |
23008 | + case Opt_append: | |
23009 | + u.add = &opt->add; | |
23010 | + AuDbg("append {b%d, %s, 0x%x, %p}\n", | |
23011 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23012 | + u.add->path.dentry); | |
23013 | + break; | |
23014 | + case Opt_prepend: | |
23015 | + u.add = &opt->add; | |
23016 | + AuDbg("prepend {b%d, %s, 0x%x, %p}\n", | |
23017 | + u.add->bindex, u.add->pathname, u.add->perm, | |
23018 | + u.add->path.dentry); | |
23019 | + break; | |
23020 | + case Opt_dirwh: | |
23021 | + AuDbg("dirwh %d\n", opt->dirwh); | |
23022 | + break; | |
23023 | + case Opt_rdcache: | |
23024 | + AuDbg("rdcache %d\n", opt->rdcache); | |
23025 | + break; | |
23026 | + case Opt_rdblk: | |
23027 | + AuDbg("rdblk %u\n", opt->rdblk); | |
23028 | + break; | |
dece6358 AM |
23029 | + case Opt_rdblk_def: |
23030 | + AuDbg("rdblk_def\n"); | |
23031 | + break; | |
1facf9fc | 23032 | + case Opt_rdhash: |
23033 | + AuDbg("rdhash %u\n", opt->rdhash); | |
23034 | + break; | |
dece6358 AM |
23035 | + case Opt_rdhash_def: |
23036 | + AuDbg("rdhash_def\n"); | |
23037 | + break; | |
1facf9fc | 23038 | + case Opt_xino: |
23039 | + u.xino = &opt->xino; | |
523b37e3 | 23040 | + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file); |
1facf9fc | 23041 | + break; |
23042 | + case Opt_trunc_xino: | |
23043 | + AuLabel(trunc_xino); | |
23044 | + break; | |
23045 | + case Opt_notrunc_xino: | |
23046 | + AuLabel(notrunc_xino); | |
23047 | + break; | |
23048 | + case Opt_trunc_xino_path: | |
23049 | + case Opt_itrunc_xino: | |
23050 | + u.xino_itrunc = &opt->xino_itrunc; | |
23051 | + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex); | |
23052 | + break; | |
23053 | + | |
23054 | + case Opt_noxino: | |
23055 | + AuLabel(noxino); | |
23056 | + break; | |
23057 | + case Opt_trunc_xib: | |
23058 | + AuLabel(trunc_xib); | |
23059 | + break; | |
23060 | + case Opt_notrunc_xib: | |
23061 | + AuLabel(notrunc_xib); | |
23062 | + break; | |
dece6358 AM |
23063 | + case Opt_shwh: |
23064 | + AuLabel(shwh); | |
23065 | + break; | |
23066 | + case Opt_noshwh: | |
23067 | + AuLabel(noshwh); | |
23068 | + break; | |
076b876e AM |
23069 | + case Opt_dirperm1: |
23070 | + AuLabel(dirperm1); | |
23071 | + break; | |
23072 | + case Opt_nodirperm1: | |
23073 | + AuLabel(nodirperm1); | |
23074 | + break; | |
1facf9fc | 23075 | + case Opt_plink: |
23076 | + AuLabel(plink); | |
23077 | + break; | |
23078 | + case Opt_noplink: | |
23079 | + AuLabel(noplink); | |
23080 | + break; | |
23081 | + case Opt_list_plink: | |
23082 | + AuLabel(list_plink); | |
23083 | + break; | |
23084 | + case Opt_udba: | |
23085 | + AuDbg("udba %d, %s\n", | |
23086 | + opt->udba, au_optstr_udba(opt->udba)); | |
23087 | + break; | |
4a4d8108 AM |
23088 | + case Opt_dio: |
23089 | + AuLabel(dio); | |
23090 | + break; | |
23091 | + case Opt_nodio: | |
23092 | + AuLabel(nodio); | |
23093 | + break; | |
1facf9fc | 23094 | + case Opt_diropq_a: |
23095 | + AuLabel(diropq_a); | |
23096 | + break; | |
23097 | + case Opt_diropq_w: | |
23098 | + AuLabel(diropq_w); | |
23099 | + break; | |
23100 | + case Opt_warn_perm: | |
23101 | + AuLabel(warn_perm); | |
23102 | + break; | |
23103 | + case Opt_nowarn_perm: | |
23104 | + AuLabel(nowarn_perm); | |
23105 | + break; | |
23106 | + case Opt_refrof: | |
23107 | + AuLabel(refrof); | |
23108 | + break; | |
23109 | + case Opt_norefrof: | |
23110 | + AuLabel(norefrof); | |
23111 | + break; | |
23112 | + case Opt_verbose: | |
23113 | + AuLabel(verbose); | |
23114 | + break; | |
23115 | + case Opt_noverbose: | |
23116 | + AuLabel(noverbose); | |
23117 | + break; | |
23118 | + case Opt_sum: | |
23119 | + AuLabel(sum); | |
23120 | + break; | |
23121 | + case Opt_nosum: | |
23122 | + AuLabel(nosum); | |
23123 | + break; | |
23124 | + case Opt_wsum: | |
23125 | + AuLabel(wsum); | |
23126 | + break; | |
23127 | + case Opt_wbr_create: | |
23128 | + u.create = &opt->wbr_create; | |
23129 | + AuDbg("create %d, %s\n", u.create->wbr_create, | |
23130 | + au_optstr_wbr_create(u.create->wbr_create)); | |
23131 | + switch (u.create->wbr_create) { | |
23132 | + case AuWbrCreate_MFSV: | |
23133 | + case AuWbrCreate_PMFSV: | |
23134 | + AuDbg("%d sec\n", u.create->mfs_second); | |
23135 | + break; | |
23136 | + case AuWbrCreate_MFSRR: | |
23137 | + AuDbg("%llu watermark\n", | |
23138 | + u.create->mfsrr_watermark); | |
23139 | + break; | |
23140 | + case AuWbrCreate_MFSRRV: | |
392086de | 23141 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 23142 | + AuDbg("%llu watermark, %d sec\n", |
23143 | + u.create->mfsrr_watermark, | |
23144 | + u.create->mfs_second); | |
23145 | + break; | |
23146 | + } | |
23147 | + break; | |
23148 | + case Opt_wbr_copyup: | |
23149 | + AuDbg("copyup %d, %s\n", opt->wbr_copyup, | |
23150 | + au_optstr_wbr_copyup(opt->wbr_copyup)); | |
23151 | + break; | |
076b876e AM |
23152 | + case Opt_fhsm_sec: |
23153 | + AuDbg("fhsm_sec %u\n", opt->fhsm_second); | |
23154 | + break; | |
c1595e42 JR |
23155 | + case Opt_acl: |
23156 | + AuLabel(acl); | |
23157 | + break; | |
23158 | + case Opt_noacl: | |
23159 | + AuLabel(noacl); | |
23160 | + break; | |
1facf9fc | 23161 | + default: |
23162 | + BUG(); | |
23163 | + } | |
23164 | + opt++; | |
23165 | + } | |
23166 | +#endif | |
23167 | +} | |
23168 | + | |
23169 | +void au_opts_free(struct au_opts *opts) | |
23170 | +{ | |
23171 | + struct au_opt *opt; | |
23172 | + | |
23173 | + opt = opts->opt; | |
23174 | + while (opt->type != Opt_tail) { | |
23175 | + switch (opt->type) { | |
23176 | + case Opt_add: | |
23177 | + case Opt_append: | |
23178 | + case Opt_prepend: | |
23179 | + path_put(&opt->add.path); | |
23180 | + break; | |
23181 | + case Opt_del: | |
23182 | + case Opt_idel: | |
23183 | + path_put(&opt->del.h_path); | |
23184 | + break; | |
23185 | + case Opt_mod: | |
23186 | + case Opt_imod: | |
23187 | + dput(opt->mod.h_root); | |
23188 | + break; | |
23189 | + case Opt_xino: | |
23190 | + fput(opt->xino.file); | |
23191 | + break; | |
23192 | + } | |
23193 | + opt++; | |
23194 | + } | |
23195 | +} | |
23196 | + | |
23197 | +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags, | |
23198 | + aufs_bindex_t bindex) | |
23199 | +{ | |
23200 | + int err; | |
23201 | + struct au_opt_add *add = &opt->add; | |
23202 | + char *p; | |
23203 | + | |
23204 | + add->bindex = bindex; | |
1e00d052 | 23205 | + add->perm = AuBrPerm_RO; |
1facf9fc | 23206 | + add->pathname = opt_str; |
23207 | + p = strchr(opt_str, '='); | |
23208 | + if (p) { | |
23209 | + *p++ = 0; | |
23210 | + if (*p) | |
23211 | + add->perm = br_perm_val(p); | |
23212 | + } | |
23213 | + | |
23214 | + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path); | |
23215 | + if (!err) { | |
23216 | + if (!p) { | |
23217 | + add->perm = AuBrPerm_RO; | |
23218 | + if (au_test_fs_rr(add->path.dentry->d_sb)) | |
23219 | + add->perm = AuBrPerm_RR; | |
23220 | + else if (!bindex && !(sb_flags & MS_RDONLY)) | |
23221 | + add->perm = AuBrPerm_RW; | |
23222 | + } | |
23223 | + opt->type = Opt_add; | |
23224 | + goto out; | |
23225 | + } | |
4a4d8108 | 23226 | + pr_err("lookup failed %s (%d)\n", add->pathname, err); |
1facf9fc | 23227 | + err = -EINVAL; |
23228 | + | |
4f0767ce | 23229 | +out: |
1facf9fc | 23230 | + return err; |
23231 | +} | |
23232 | + | |
23233 | +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[]) | |
23234 | +{ | |
23235 | + int err; | |
23236 | + | |
23237 | + del->pathname = args[0].from; | |
23238 | + AuDbg("del path %s\n", del->pathname); | |
23239 | + | |
23240 | + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path); | |
23241 | + if (unlikely(err)) | |
4a4d8108 | 23242 | + pr_err("lookup failed %s (%d)\n", del->pathname, err); |
1facf9fc | 23243 | + |
23244 | + return err; | |
23245 | +} | |
23246 | + | |
23247 | +#if 0 /* reserved for future use */ | |
23248 | +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex, | |
23249 | + struct au_opt_del *del, substring_t args[]) | |
23250 | +{ | |
23251 | + int err; | |
23252 | + struct dentry *root; | |
23253 | + | |
23254 | + err = -EINVAL; | |
23255 | + root = sb->s_root; | |
23256 | + aufs_read_lock(root, AuLock_FLUSH); | |
23257 | + if (bindex < 0 || au_sbend(sb) < bindex) { | |
4a4d8108 | 23258 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 23259 | + goto out; |
23260 | + } | |
23261 | + | |
23262 | + err = 0; | |
23263 | + del->h_path.dentry = dget(au_h_dptr(root, bindex)); | |
23264 | + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex)); | |
23265 | + | |
4f0767ce | 23266 | +out: |
1facf9fc | 23267 | + aufs_read_unlock(root, !AuLock_IR); |
23268 | + return err; | |
23269 | +} | |
23270 | +#endif | |
23271 | + | |
4a4d8108 AM |
23272 | +static int noinline_for_stack |
23273 | +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[]) | |
1facf9fc | 23274 | +{ |
23275 | + int err; | |
23276 | + struct path path; | |
23277 | + char *p; | |
23278 | + | |
23279 | + err = -EINVAL; | |
23280 | + mod->path = args[0].from; | |
23281 | + p = strchr(mod->path, '='); | |
23282 | + if (unlikely(!p)) { | |
4a4d8108 | 23283 | + pr_err("no permssion %s\n", args[0].from); |
1facf9fc | 23284 | + goto out; |
23285 | + } | |
23286 | + | |
23287 | + *p++ = 0; | |
23288 | + err = vfsub_kern_path(mod->path, lkup_dirflags, &path); | |
23289 | + if (unlikely(err)) { | |
4a4d8108 | 23290 | + pr_err("lookup failed %s (%d)\n", mod->path, err); |
1facf9fc | 23291 | + goto out; |
23292 | + } | |
23293 | + | |
23294 | + mod->perm = br_perm_val(p); | |
23295 | + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p); | |
23296 | + mod->h_root = dget(path.dentry); | |
23297 | + path_put(&path); | |
23298 | + | |
4f0767ce | 23299 | +out: |
1facf9fc | 23300 | + return err; |
23301 | +} | |
23302 | + | |
23303 | +#if 0 /* reserved for future use */ | |
23304 | +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex, | |
23305 | + struct au_opt_mod *mod, substring_t args[]) | |
23306 | +{ | |
23307 | + int err; | |
23308 | + struct dentry *root; | |
23309 | + | |
23310 | + err = -EINVAL; | |
23311 | + root = sb->s_root; | |
23312 | + aufs_read_lock(root, AuLock_FLUSH); | |
23313 | + if (bindex < 0 || au_sbend(sb) < bindex) { | |
4a4d8108 | 23314 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 23315 | + goto out; |
23316 | + } | |
23317 | + | |
23318 | + err = 0; | |
23319 | + mod->perm = br_perm_val(args[1].from); | |
23320 | + AuDbg("mod path %s, perm 0x%x, %s\n", | |
23321 | + mod->path, mod->perm, args[1].from); | |
23322 | + mod->h_root = dget(au_h_dptr(root, bindex)); | |
23323 | + | |
4f0767ce | 23324 | +out: |
1facf9fc | 23325 | + aufs_read_unlock(root, !AuLock_IR); |
23326 | + return err; | |
23327 | +} | |
23328 | +#endif | |
23329 | + | |
23330 | +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino, | |
23331 | + substring_t args[]) | |
23332 | +{ | |
23333 | + int err; | |
23334 | + struct file *file; | |
23335 | + | |
23336 | + file = au_xino_create(sb, args[0].from, /*silent*/0); | |
23337 | + err = PTR_ERR(file); | |
23338 | + if (IS_ERR(file)) | |
23339 | + goto out; | |
23340 | + | |
23341 | + err = -EINVAL; | |
23342 | + if (unlikely(file->f_dentry->d_sb == sb)) { | |
23343 | + fput(file); | |
4a4d8108 | 23344 | + pr_err("%s must be outside\n", args[0].from); |
1facf9fc | 23345 | + goto out; |
23346 | + } | |
23347 | + | |
23348 | + err = 0; | |
23349 | + xino->file = file; | |
23350 | + xino->path = args[0].from; | |
23351 | + | |
4f0767ce | 23352 | +out: |
1facf9fc | 23353 | + return err; |
23354 | +} | |
23355 | + | |
4a4d8108 AM |
23356 | +static int noinline_for_stack |
23357 | +au_opts_parse_xino_itrunc_path(struct super_block *sb, | |
23358 | + struct au_opt_xino_itrunc *xino_itrunc, | |
23359 | + substring_t args[]) | |
1facf9fc | 23360 | +{ |
23361 | + int err; | |
23362 | + aufs_bindex_t bend, bindex; | |
23363 | + struct path path; | |
23364 | + struct dentry *root; | |
23365 | + | |
23366 | + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path); | |
23367 | + if (unlikely(err)) { | |
4a4d8108 | 23368 | + pr_err("lookup failed %s (%d)\n", args[0].from, err); |
1facf9fc | 23369 | + goto out; |
23370 | + } | |
23371 | + | |
23372 | + xino_itrunc->bindex = -1; | |
23373 | + root = sb->s_root; | |
23374 | + aufs_read_lock(root, AuLock_FLUSH); | |
23375 | + bend = au_sbend(sb); | |
23376 | + for (bindex = 0; bindex <= bend; bindex++) { | |
23377 | + if (au_h_dptr(root, bindex) == path.dentry) { | |
23378 | + xino_itrunc->bindex = bindex; | |
23379 | + break; | |
23380 | + } | |
23381 | + } | |
23382 | + aufs_read_unlock(root, !AuLock_IR); | |
23383 | + path_put(&path); | |
23384 | + | |
23385 | + if (unlikely(xino_itrunc->bindex < 0)) { | |
4a4d8108 | 23386 | + pr_err("no such branch %s\n", args[0].from); |
1facf9fc | 23387 | + err = -EINVAL; |
23388 | + } | |
23389 | + | |
4f0767ce | 23390 | +out: |
1facf9fc | 23391 | + return err; |
23392 | +} | |
23393 | + | |
23394 | +/* called without aufs lock */ | |
23395 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts) | |
23396 | +{ | |
23397 | + int err, n, token; | |
23398 | + aufs_bindex_t bindex; | |
23399 | + unsigned char skipped; | |
23400 | + struct dentry *root; | |
23401 | + struct au_opt *opt, *opt_tail; | |
23402 | + char *opt_str; | |
23403 | + /* reduce the stack space */ | |
23404 | + union { | |
23405 | + struct au_opt_xino_itrunc *xino_itrunc; | |
23406 | + struct au_opt_wbr_create *create; | |
23407 | + } u; | |
23408 | + struct { | |
23409 | + substring_t args[MAX_OPT_ARGS]; | |
23410 | + } *a; | |
23411 | + | |
23412 | + err = -ENOMEM; | |
23413 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
23414 | + if (unlikely(!a)) | |
23415 | + goto out; | |
23416 | + | |
23417 | + root = sb->s_root; | |
23418 | + err = 0; | |
23419 | + bindex = 0; | |
23420 | + opt = opts->opt; | |
23421 | + opt_tail = opt + opts->max_opt - 1; | |
23422 | + opt->type = Opt_tail; | |
23423 | + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) { | |
23424 | + err = -EINVAL; | |
23425 | + skipped = 0; | |
23426 | + token = match_token(opt_str, options, a->args); | |
23427 | + switch (token) { | |
23428 | + case Opt_br: | |
23429 | + err = 0; | |
23430 | + while (!err && (opt_str = strsep(&a->args[0].from, ":")) | |
23431 | + && *opt_str) { | |
23432 | + err = opt_add(opt, opt_str, opts->sb_flags, | |
23433 | + bindex++); | |
23434 | + if (unlikely(!err && ++opt > opt_tail)) { | |
23435 | + err = -E2BIG; | |
23436 | + break; | |
23437 | + } | |
23438 | + opt->type = Opt_tail; | |
23439 | + skipped = 1; | |
23440 | + } | |
23441 | + break; | |
23442 | + case Opt_add: | |
23443 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23444 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23445 | + break; |
23446 | + } | |
23447 | + bindex = n; | |
23448 | + err = opt_add(opt, a->args[1].from, opts->sb_flags, | |
23449 | + bindex); | |
23450 | + if (!err) | |
23451 | + opt->type = token; | |
23452 | + break; | |
23453 | + case Opt_append: | |
23454 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
23455 | + /*dummy bindex*/1); | |
23456 | + if (!err) | |
23457 | + opt->type = token; | |
23458 | + break; | |
23459 | + case Opt_prepend: | |
23460 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
23461 | + /*bindex*/0); | |
23462 | + if (!err) | |
23463 | + opt->type = token; | |
23464 | + break; | |
23465 | + case Opt_del: | |
23466 | + err = au_opts_parse_del(&opt->del, a->args); | |
23467 | + if (!err) | |
23468 | + opt->type = token; | |
23469 | + break; | |
23470 | +#if 0 /* reserved for future use */ | |
23471 | + case Opt_idel: | |
23472 | + del->pathname = "(indexed)"; | |
23473 | + if (unlikely(match_int(&args[0], &n))) { | |
4a4d8108 | 23474 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23475 | + break; |
23476 | + } | |
23477 | + err = au_opts_parse_idel(sb, n, &opt->del, a->args); | |
23478 | + if (!err) | |
23479 | + opt->type = token; | |
23480 | + break; | |
23481 | +#endif | |
23482 | + case Opt_mod: | |
23483 | + err = au_opts_parse_mod(&opt->mod, a->args); | |
23484 | + if (!err) | |
23485 | + opt->type = token; | |
23486 | + break; | |
23487 | +#ifdef IMOD /* reserved for future use */ | |
23488 | + case Opt_imod: | |
23489 | + u.mod->path = "(indexed)"; | |
23490 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23491 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23492 | + break; |
23493 | + } | |
23494 | + err = au_opts_parse_imod(sb, n, &opt->mod, a->args); | |
23495 | + if (!err) | |
23496 | + opt->type = token; | |
23497 | + break; | |
23498 | +#endif | |
23499 | + case Opt_xino: | |
23500 | + err = au_opts_parse_xino(sb, &opt->xino, a->args); | |
23501 | + if (!err) | |
23502 | + opt->type = token; | |
23503 | + break; | |
23504 | + | |
23505 | + case Opt_trunc_xino_path: | |
23506 | + err = au_opts_parse_xino_itrunc_path | |
23507 | + (sb, &opt->xino_itrunc, a->args); | |
23508 | + if (!err) | |
23509 | + opt->type = token; | |
23510 | + break; | |
23511 | + | |
23512 | + case Opt_itrunc_xino: | |
23513 | + u.xino_itrunc = &opt->xino_itrunc; | |
23514 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 23515 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23516 | + break; |
23517 | + } | |
23518 | + u.xino_itrunc->bindex = n; | |
23519 | + aufs_read_lock(root, AuLock_FLUSH); | |
23520 | + if (n < 0 || au_sbend(sb) < n) { | |
4a4d8108 | 23521 | + pr_err("out of bounds, %d\n", n); |
1facf9fc | 23522 | + aufs_read_unlock(root, !AuLock_IR); |
23523 | + break; | |
23524 | + } | |
23525 | + aufs_read_unlock(root, !AuLock_IR); | |
23526 | + err = 0; | |
23527 | + opt->type = token; | |
23528 | + break; | |
23529 | + | |
23530 | + case Opt_dirwh: | |
23531 | + if (unlikely(match_int(&a->args[0], &opt->dirwh))) | |
23532 | + break; | |
23533 | + err = 0; | |
23534 | + opt->type = token; | |
23535 | + break; | |
23536 | + | |
23537 | + case Opt_rdcache: | |
027c5e7a AM |
23538 | + if (unlikely(match_int(&a->args[0], &n))) { |
23539 | + pr_err("bad integer in %s\n", opt_str); | |
1facf9fc | 23540 | + break; |
027c5e7a AM |
23541 | + } |
23542 | + if (unlikely(n > AUFS_RDCACHE_MAX)) { | |
23543 | + pr_err("rdcache must be smaller than %d\n", | |
23544 | + AUFS_RDCACHE_MAX); | |
23545 | + break; | |
23546 | + } | |
23547 | + opt->rdcache = n; | |
1facf9fc | 23548 | + err = 0; |
23549 | + opt->type = token; | |
23550 | + break; | |
23551 | + case Opt_rdblk: | |
23552 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 23553 | + || n < 0 |
1facf9fc | 23554 | + || n > KMALLOC_MAX_SIZE)) { |
4a4d8108 | 23555 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23556 | + break; |
23557 | + } | |
1308ab2a | 23558 | + if (unlikely(n && n < NAME_MAX)) { |
4a4d8108 AM |
23559 | + pr_err("rdblk must be larger than %d\n", |
23560 | + NAME_MAX); | |
1facf9fc | 23561 | + break; |
23562 | + } | |
23563 | + opt->rdblk = n; | |
23564 | + err = 0; | |
23565 | + opt->type = token; | |
23566 | + break; | |
23567 | + case Opt_rdhash: | |
23568 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 23569 | + || n < 0 |
1facf9fc | 23570 | + || n * sizeof(struct hlist_head) |
23571 | + > KMALLOC_MAX_SIZE)) { | |
4a4d8108 | 23572 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 23573 | + break; |
23574 | + } | |
23575 | + opt->rdhash = n; | |
23576 | + err = 0; | |
23577 | + opt->type = token; | |
23578 | + break; | |
23579 | + | |
23580 | + case Opt_trunc_xino: | |
23581 | + case Opt_notrunc_xino: | |
23582 | + case Opt_noxino: | |
23583 | + case Opt_trunc_xib: | |
23584 | + case Opt_notrunc_xib: | |
dece6358 AM |
23585 | + case Opt_shwh: |
23586 | + case Opt_noshwh: | |
076b876e AM |
23587 | + case Opt_dirperm1: |
23588 | + case Opt_nodirperm1: | |
1facf9fc | 23589 | + case Opt_plink: |
23590 | + case Opt_noplink: | |
23591 | + case Opt_list_plink: | |
4a4d8108 AM |
23592 | + case Opt_dio: |
23593 | + case Opt_nodio: | |
1facf9fc | 23594 | + case Opt_diropq_a: |
23595 | + case Opt_diropq_w: | |
23596 | + case Opt_warn_perm: | |
23597 | + case Opt_nowarn_perm: | |
23598 | + case Opt_refrof: | |
23599 | + case Opt_norefrof: | |
23600 | + case Opt_verbose: | |
23601 | + case Opt_noverbose: | |
23602 | + case Opt_sum: | |
23603 | + case Opt_nosum: | |
23604 | + case Opt_wsum: | |
dece6358 AM |
23605 | + case Opt_rdblk_def: |
23606 | + case Opt_rdhash_def: | |
c1595e42 JR |
23607 | + case Opt_acl: |
23608 | + case Opt_noacl: | |
1facf9fc | 23609 | + err = 0; |
23610 | + opt->type = token; | |
23611 | + break; | |
23612 | + | |
23613 | + case Opt_udba: | |
23614 | + opt->udba = udba_val(a->args[0].from); | |
23615 | + if (opt->udba >= 0) { | |
23616 | + err = 0; | |
23617 | + opt->type = token; | |
23618 | + } else | |
4a4d8108 | 23619 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23620 | + break; |
23621 | + | |
23622 | + case Opt_wbr_create: | |
23623 | + u.create = &opt->wbr_create; | |
23624 | + u.create->wbr_create | |
23625 | + = au_wbr_create_val(a->args[0].from, u.create); | |
23626 | + if (u.create->wbr_create >= 0) { | |
23627 | + err = 0; | |
23628 | + opt->type = token; | |
23629 | + } else | |
4a4d8108 | 23630 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23631 | + break; |
23632 | + case Opt_wbr_copyup: | |
23633 | + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from); | |
23634 | + if (opt->wbr_copyup >= 0) { | |
23635 | + err = 0; | |
23636 | + opt->type = token; | |
23637 | + } else | |
4a4d8108 | 23638 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 23639 | + break; |
23640 | + | |
076b876e AM |
23641 | + case Opt_fhsm_sec: |
23642 | + if (unlikely(match_int(&a->args[0], &n) | |
23643 | + || n < 0)) { | |
23644 | + pr_err("bad integer in %s\n", opt_str); | |
23645 | + break; | |
23646 | + } | |
23647 | + if (sysaufs_brs) { | |
23648 | + opt->fhsm_second = n; | |
23649 | + opt->type = token; | |
23650 | + } else | |
23651 | + pr_warn("ignored %s\n", opt_str); | |
23652 | + err = 0; | |
23653 | + break; | |
23654 | + | |
1facf9fc | 23655 | + case Opt_ignore: |
0c3ec466 | 23656 | + pr_warn("ignored %s\n", opt_str); |
1facf9fc | 23657 | + /*FALLTHROUGH*/ |
23658 | + case Opt_ignore_silent: | |
23659 | + skipped = 1; | |
23660 | + err = 0; | |
23661 | + break; | |
23662 | + case Opt_err: | |
4a4d8108 | 23663 | + pr_err("unknown option %s\n", opt_str); |
1facf9fc | 23664 | + break; |
23665 | + } | |
23666 | + | |
23667 | + if (!err && !skipped) { | |
23668 | + if (unlikely(++opt > opt_tail)) { | |
23669 | + err = -E2BIG; | |
23670 | + opt--; | |
23671 | + opt->type = Opt_tail; | |
23672 | + break; | |
23673 | + } | |
23674 | + opt->type = Opt_tail; | |
23675 | + } | |
23676 | + } | |
23677 | + | |
23678 | + kfree(a); | |
23679 | + dump_opts(opts); | |
23680 | + if (unlikely(err)) | |
23681 | + au_opts_free(opts); | |
23682 | + | |
4f0767ce | 23683 | +out: |
1facf9fc | 23684 | + return err; |
23685 | +} | |
23686 | + | |
23687 | +static int au_opt_wbr_create(struct super_block *sb, | |
23688 | + struct au_opt_wbr_create *create) | |
23689 | +{ | |
23690 | + int err; | |
23691 | + struct au_sbinfo *sbinfo; | |
23692 | + | |
dece6358 AM |
23693 | + SiMustWriteLock(sb); |
23694 | + | |
1facf9fc | 23695 | + err = 1; /* handled */ |
23696 | + sbinfo = au_sbi(sb); | |
23697 | + if (sbinfo->si_wbr_create_ops->fin) { | |
23698 | + err = sbinfo->si_wbr_create_ops->fin(sb); | |
23699 | + if (!err) | |
23700 | + err = 1; | |
23701 | + } | |
23702 | + | |
23703 | + sbinfo->si_wbr_create = create->wbr_create; | |
23704 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create; | |
23705 | + switch (create->wbr_create) { | |
23706 | + case AuWbrCreate_MFSRRV: | |
23707 | + case AuWbrCreate_MFSRR: | |
392086de AM |
23708 | + case AuWbrCreate_PMFSRR: |
23709 | + case AuWbrCreate_PMFSRRV: | |
1facf9fc | 23710 | + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark; |
23711 | + /*FALLTHROUGH*/ | |
23712 | + case AuWbrCreate_MFS: | |
23713 | + case AuWbrCreate_MFSV: | |
23714 | + case AuWbrCreate_PMFS: | |
23715 | + case AuWbrCreate_PMFSV: | |
e49829fe JR |
23716 | + sbinfo->si_wbr_mfs.mfs_expire |
23717 | + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC); | |
1facf9fc | 23718 | + break; |
23719 | + } | |
23720 | + | |
23721 | + if (sbinfo->si_wbr_create_ops->init) | |
23722 | + sbinfo->si_wbr_create_ops->init(sb); /* ignore */ | |
23723 | + | |
23724 | + return err; | |
23725 | +} | |
23726 | + | |
23727 | +/* | |
23728 | + * returns, | |
23729 | + * plus: processed without an error | |
23730 | + * zero: unprocessed | |
23731 | + */ | |
23732 | +static int au_opt_simple(struct super_block *sb, struct au_opt *opt, | |
23733 | + struct au_opts *opts) | |
23734 | +{ | |
23735 | + int err; | |
23736 | + struct au_sbinfo *sbinfo; | |
23737 | + | |
dece6358 AM |
23738 | + SiMustWriteLock(sb); |
23739 | + | |
1facf9fc | 23740 | + err = 1; /* handled */ |
23741 | + sbinfo = au_sbi(sb); | |
23742 | + switch (opt->type) { | |
23743 | + case Opt_udba: | |
23744 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; | |
23745 | + sbinfo->si_mntflags |= opt->udba; | |
23746 | + opts->given_udba |= opt->udba; | |
23747 | + break; | |
23748 | + | |
23749 | + case Opt_plink: | |
23750 | + au_opt_set(sbinfo->si_mntflags, PLINK); | |
23751 | + break; | |
23752 | + case Opt_noplink: | |
23753 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
e49829fe | 23754 | + au_plink_put(sb, /*verbose*/1); |
1facf9fc | 23755 | + au_opt_clr(sbinfo->si_mntflags, PLINK); |
23756 | + break; | |
23757 | + case Opt_list_plink: | |
23758 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
23759 | + au_plink_list(sb); | |
23760 | + break; | |
23761 | + | |
4a4d8108 AM |
23762 | + case Opt_dio: |
23763 | + au_opt_set(sbinfo->si_mntflags, DIO); | |
23764 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
23765 | + break; | |
23766 | + case Opt_nodio: | |
23767 | + au_opt_clr(sbinfo->si_mntflags, DIO); | |
23768 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
23769 | + break; | |
23770 | + | |
076b876e AM |
23771 | + case Opt_fhsm_sec: |
23772 | + au_fhsm_set(sbinfo, opt->fhsm_second); | |
23773 | + break; | |
23774 | + | |
1facf9fc | 23775 | + case Opt_diropq_a: |
23776 | + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
23777 | + break; | |
23778 | + case Opt_diropq_w: | |
23779 | + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
23780 | + break; | |
23781 | + | |
23782 | + case Opt_warn_perm: | |
23783 | + au_opt_set(sbinfo->si_mntflags, WARN_PERM); | |
23784 | + break; | |
23785 | + case Opt_nowarn_perm: | |
23786 | + au_opt_clr(sbinfo->si_mntflags, WARN_PERM); | |
23787 | + break; | |
23788 | + | |
23789 | + case Opt_refrof: | |
23790 | + au_opt_set(sbinfo->si_mntflags, REFROF); | |
23791 | + break; | |
23792 | + case Opt_norefrof: | |
23793 | + au_opt_clr(sbinfo->si_mntflags, REFROF); | |
23794 | + break; | |
23795 | + | |
23796 | + case Opt_verbose: | |
23797 | + au_opt_set(sbinfo->si_mntflags, VERBOSE); | |
23798 | + break; | |
23799 | + case Opt_noverbose: | |
23800 | + au_opt_clr(sbinfo->si_mntflags, VERBOSE); | |
23801 | + break; | |
23802 | + | |
23803 | + case Opt_sum: | |
23804 | + au_opt_set(sbinfo->si_mntflags, SUM); | |
23805 | + break; | |
23806 | + case Opt_wsum: | |
23807 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
23808 | + au_opt_set(sbinfo->si_mntflags, SUM_W); | |
23809 | + case Opt_nosum: | |
23810 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
23811 | + au_opt_clr(sbinfo->si_mntflags, SUM_W); | |
23812 | + break; | |
23813 | + | |
23814 | + case Opt_wbr_create: | |
23815 | + err = au_opt_wbr_create(sb, &opt->wbr_create); | |
23816 | + break; | |
23817 | + case Opt_wbr_copyup: | |
23818 | + sbinfo->si_wbr_copyup = opt->wbr_copyup; | |
23819 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup; | |
23820 | + break; | |
23821 | + | |
23822 | + case Opt_dirwh: | |
23823 | + sbinfo->si_dirwh = opt->dirwh; | |
23824 | + break; | |
23825 | + | |
23826 | + case Opt_rdcache: | |
e49829fe JR |
23827 | + sbinfo->si_rdcache |
23828 | + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC); | |
1facf9fc | 23829 | + break; |
23830 | + case Opt_rdblk: | |
23831 | + sbinfo->si_rdblk = opt->rdblk; | |
23832 | + break; | |
dece6358 AM |
23833 | + case Opt_rdblk_def: |
23834 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; | |
23835 | + break; | |
1facf9fc | 23836 | + case Opt_rdhash: |
23837 | + sbinfo->si_rdhash = opt->rdhash; | |
23838 | + break; | |
dece6358 AM |
23839 | + case Opt_rdhash_def: |
23840 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
23841 | + break; | |
23842 | + | |
23843 | + case Opt_shwh: | |
23844 | + au_opt_set(sbinfo->si_mntflags, SHWH); | |
23845 | + break; | |
23846 | + case Opt_noshwh: | |
23847 | + au_opt_clr(sbinfo->si_mntflags, SHWH); | |
23848 | + break; | |
1facf9fc | 23849 | + |
076b876e AM |
23850 | + case Opt_dirperm1: |
23851 | + au_opt_set(sbinfo->si_mntflags, DIRPERM1); | |
23852 | + break; | |
23853 | + case Opt_nodirperm1: | |
23854 | + au_opt_clr(sbinfo->si_mntflags, DIRPERM1); | |
23855 | + break; | |
23856 | + | |
1facf9fc | 23857 | + case Opt_trunc_xino: |
23858 | + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO); | |
23859 | + break; | |
23860 | + case Opt_notrunc_xino: | |
23861 | + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO); | |
23862 | + break; | |
23863 | + | |
23864 | + case Opt_trunc_xino_path: | |
23865 | + case Opt_itrunc_xino: | |
23866 | + err = au_xino_trunc(sb, opt->xino_itrunc.bindex); | |
23867 | + if (!err) | |
23868 | + err = 1; | |
23869 | + break; | |
23870 | + | |
23871 | + case Opt_trunc_xib: | |
23872 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
23873 | + break; | |
23874 | + case Opt_notrunc_xib: | |
23875 | + au_fclr_opts(opts->flags, TRUNC_XIB); | |
23876 | + break; | |
23877 | + | |
c1595e42 JR |
23878 | + case Opt_acl: |
23879 | + sb->s_flags |= MS_POSIXACL; | |
23880 | + break; | |
23881 | + case Opt_noacl: | |
23882 | + sb->s_flags &= ~MS_POSIXACL; | |
23883 | + break; | |
23884 | + | |
1facf9fc | 23885 | + default: |
23886 | + err = 0; | |
23887 | + break; | |
23888 | + } | |
23889 | + | |
23890 | + return err; | |
23891 | +} | |
23892 | + | |
23893 | +/* | |
23894 | + * returns tri-state. | |
23895 | + * plus: processed without an error | |
23896 | + * zero: unprocessed | |
23897 | + * minus: error | |
23898 | + */ | |
23899 | +static int au_opt_br(struct super_block *sb, struct au_opt *opt, | |
23900 | + struct au_opts *opts) | |
23901 | +{ | |
23902 | + int err, do_refresh; | |
23903 | + | |
23904 | + err = 0; | |
23905 | + switch (opt->type) { | |
23906 | + case Opt_append: | |
23907 | + opt->add.bindex = au_sbend(sb) + 1; | |
23908 | + if (opt->add.bindex < 0) | |
23909 | + opt->add.bindex = 0; | |
23910 | + goto add; | |
23911 | + case Opt_prepend: | |
23912 | + opt->add.bindex = 0; | |
f6b6e03d | 23913 | + add: /* indented label */ |
1facf9fc | 23914 | + case Opt_add: |
23915 | + err = au_br_add(sb, &opt->add, | |
23916 | + au_ftest_opts(opts->flags, REMOUNT)); | |
23917 | + if (!err) { | |
23918 | + err = 1; | |
027c5e7a | 23919 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 23920 | + } |
23921 | + break; | |
23922 | + | |
23923 | + case Opt_del: | |
23924 | + case Opt_idel: | |
23925 | + err = au_br_del(sb, &opt->del, | |
23926 | + au_ftest_opts(opts->flags, REMOUNT)); | |
23927 | + if (!err) { | |
23928 | + err = 1; | |
23929 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
027c5e7a | 23930 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 23931 | + } |
23932 | + break; | |
23933 | + | |
23934 | + case Opt_mod: | |
23935 | + case Opt_imod: | |
23936 | + err = au_br_mod(sb, &opt->mod, | |
23937 | + au_ftest_opts(opts->flags, REMOUNT), | |
23938 | + &do_refresh); | |
23939 | + if (!err) { | |
23940 | + err = 1; | |
027c5e7a AM |
23941 | + if (do_refresh) |
23942 | + au_fset_opts(opts->flags, REFRESH); | |
1facf9fc | 23943 | + } |
23944 | + break; | |
23945 | + } | |
23946 | + | |
23947 | + return err; | |
23948 | +} | |
23949 | + | |
23950 | +static int au_opt_xino(struct super_block *sb, struct au_opt *opt, | |
23951 | + struct au_opt_xino **opt_xino, | |
23952 | + struct au_opts *opts) | |
23953 | +{ | |
23954 | + int err; | |
23955 | + aufs_bindex_t bend, bindex; | |
23956 | + struct dentry *root, *parent, *h_root; | |
23957 | + | |
23958 | + err = 0; | |
23959 | + switch (opt->type) { | |
23960 | + case Opt_xino: | |
23961 | + err = au_xino_set(sb, &opt->xino, | |
23962 | + !!au_ftest_opts(opts->flags, REMOUNT)); | |
23963 | + if (unlikely(err)) | |
23964 | + break; | |
23965 | + | |
23966 | + *opt_xino = &opt->xino; | |
23967 | + au_xino_brid_set(sb, -1); | |
23968 | + | |
23969 | + /* safe d_parent access */ | |
23970 | + parent = opt->xino.file->f_dentry->d_parent; | |
23971 | + root = sb->s_root; | |
23972 | + bend = au_sbend(sb); | |
23973 | + for (bindex = 0; bindex <= bend; bindex++) { | |
23974 | + h_root = au_h_dptr(root, bindex); | |
23975 | + if (h_root == parent) { | |
23976 | + au_xino_brid_set(sb, au_sbr_id(sb, bindex)); | |
23977 | + break; | |
23978 | + } | |
23979 | + } | |
23980 | + break; | |
23981 | + | |
23982 | + case Opt_noxino: | |
23983 | + au_xino_clr(sb); | |
23984 | + au_xino_brid_set(sb, -1); | |
23985 | + *opt_xino = (void *)-1; | |
23986 | + break; | |
23987 | + } | |
23988 | + | |
23989 | + return err; | |
23990 | +} | |
23991 | + | |
23992 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
23993 | + unsigned int pending) | |
23994 | +{ | |
076b876e | 23995 | + int err, fhsm; |
1facf9fc | 23996 | + aufs_bindex_t bindex, bend; |
23997 | + unsigned char do_plink, skip, do_free; | |
23998 | + struct au_branch *br; | |
23999 | + struct au_wbr *wbr; | |
24000 | + struct dentry *root; | |
24001 | + struct inode *dir, *h_dir; | |
24002 | + struct au_sbinfo *sbinfo; | |
24003 | + struct au_hinode *hdir; | |
24004 | + | |
dece6358 AM |
24005 | + SiMustAnyLock(sb); |
24006 | + | |
1facf9fc | 24007 | + sbinfo = au_sbi(sb); |
24008 | + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA)); | |
24009 | + | |
dece6358 AM |
24010 | + if (!(sb_flags & MS_RDONLY)) { |
24011 | + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0)))) | |
0c3ec466 | 24012 | + pr_warn("first branch should be rw\n"); |
dece6358 | 24013 | + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH))) |
0c3ec466 | 24014 | + pr_warn("shwh should be used with ro\n"); |
dece6358 | 24015 | + } |
1facf9fc | 24016 | + |
4a4d8108 | 24017 | + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY) |
1facf9fc | 24018 | + && !au_opt_test(sbinfo->si_mntflags, XINO)) |
0c3ec466 | 24019 | + pr_warn("udba=*notify requires xino\n"); |
1facf9fc | 24020 | + |
076b876e AM |
24021 | + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1)) |
24022 | + pr_warn("dirperm1 breaks the protection" | |
24023 | + " by the permission bits on the lower branch\n"); | |
24024 | + | |
1facf9fc | 24025 | + err = 0; |
076b876e | 24026 | + fhsm = 0; |
1facf9fc | 24027 | + root = sb->s_root; |
4a4d8108 | 24028 | + dir = root->d_inode; |
1facf9fc | 24029 | + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK); |
24030 | + bend = au_sbend(sb); | |
24031 | + for (bindex = 0; !err && bindex <= bend; bindex++) { | |
24032 | + skip = 0; | |
24033 | + h_dir = au_h_iptr(dir, bindex); | |
24034 | + br = au_sbr(sb, bindex); | |
1facf9fc | 24035 | + |
c1595e42 JR |
24036 | + if ((br->br_perm & AuBrAttr_ICEX) |
24037 | + && !h_dir->i_op->listxattr) | |
24038 | + br->br_perm &= ~AuBrAttr_ICEX; | |
24039 | +#if 0 | |
24040 | + if ((br->br_perm & AuBrAttr_ICEX_SEC) | |
24041 | + && (au_br_sb(br)->s_flags & MS_NOSEC)) | |
24042 | + br->br_perm &= ~AuBrAttr_ICEX_SEC; | |
24043 | +#endif | |
24044 | + | |
24045 | + do_free = 0; | |
1facf9fc | 24046 | + wbr = br->br_wbr; |
24047 | + if (wbr) | |
24048 | + wbr_wh_read_lock(wbr); | |
24049 | + | |
1e00d052 | 24050 | + if (!au_br_writable(br->br_perm)) { |
1facf9fc | 24051 | + do_free = !!wbr; |
24052 | + skip = (!wbr | |
24053 | + || (!wbr->wbr_whbase | |
24054 | + && !wbr->wbr_plink | |
24055 | + && !wbr->wbr_orph)); | |
1e00d052 | 24056 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 24057 | + /* skip = (!br->br_whbase && !br->br_orph); */ |
24058 | + skip = (!wbr || !wbr->wbr_whbase); | |
24059 | + if (skip && wbr) { | |
24060 | + if (do_plink) | |
24061 | + skip = !!wbr->wbr_plink; | |
24062 | + else | |
24063 | + skip = !wbr->wbr_plink; | |
24064 | + } | |
1e00d052 | 24065 | + } else { |
1facf9fc | 24066 | + /* skip = (br->br_whbase && br->br_ohph); */ |
24067 | + skip = (wbr && wbr->wbr_whbase); | |
24068 | + if (skip) { | |
24069 | + if (do_plink) | |
24070 | + skip = !!wbr->wbr_plink; | |
24071 | + else | |
24072 | + skip = !wbr->wbr_plink; | |
24073 | + } | |
1facf9fc | 24074 | + } |
24075 | + if (wbr) | |
24076 | + wbr_wh_read_unlock(wbr); | |
24077 | + | |
076b876e AM |
24078 | + if (au_br_fhsm(br->br_perm)) { |
24079 | + fhsm++; | |
24080 | + AuDebugOn(!br->br_fhsm); | |
24081 | + } | |
24082 | + | |
1facf9fc | 24083 | + if (skip) |
24084 | + continue; | |
24085 | + | |
24086 | + hdir = au_hi(dir, bindex); | |
4a4d8108 | 24087 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 24088 | + if (wbr) |
24089 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 24090 | + err = au_wh_init(br, sb); |
1facf9fc | 24091 | + if (wbr) |
24092 | + wbr_wh_write_unlock(wbr); | |
4a4d8108 | 24093 | + au_hn_imtx_unlock(hdir); |
1facf9fc | 24094 | + |
24095 | + if (!err && do_free) { | |
24096 | + kfree(wbr); | |
24097 | + br->br_wbr = NULL; | |
24098 | + } | |
24099 | + } | |
24100 | + | |
c1595e42 | 24101 | + if (fhsm >= 2) { |
076b876e | 24102 | + au_fset_si(sbinfo, FHSM); |
c1595e42 JR |
24103 | + for (bindex = bend; bindex >= 0; bindex--) { |
24104 | + br = au_sbr(sb, bindex); | |
24105 | + if (au_br_fhsm(br->br_perm)) { | |
24106 | + au_fhsm_set_bottom(sb, bindex); | |
24107 | + break; | |
24108 | + } | |
24109 | + } | |
24110 | + } else { | |
076b876e | 24111 | + au_fclr_si(sbinfo, FHSM); |
c1595e42 JR |
24112 | + au_fhsm_set_bottom(sb, -1); |
24113 | + } | |
076b876e | 24114 | + |
1facf9fc | 24115 | + return err; |
24116 | +} | |
24117 | + | |
24118 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts) | |
24119 | +{ | |
24120 | + int err; | |
24121 | + unsigned int tmp; | |
027c5e7a | 24122 | + aufs_bindex_t bindex, bend; |
1facf9fc | 24123 | + struct au_opt *opt; |
24124 | + struct au_opt_xino *opt_xino, xino; | |
24125 | + struct au_sbinfo *sbinfo; | |
027c5e7a | 24126 | + struct au_branch *br; |
076b876e | 24127 | + struct inode *dir; |
1facf9fc | 24128 | + |
dece6358 AM |
24129 | + SiMustWriteLock(sb); |
24130 | + | |
1facf9fc | 24131 | + err = 0; |
24132 | + opt_xino = NULL; | |
24133 | + opt = opts->opt; | |
24134 | + while (err >= 0 && opt->type != Opt_tail) | |
24135 | + err = au_opt_simple(sb, opt++, opts); | |
24136 | + if (err > 0) | |
24137 | + err = 0; | |
24138 | + else if (unlikely(err < 0)) | |
24139 | + goto out; | |
24140 | + | |
24141 | + /* disable xino and udba temporary */ | |
24142 | + sbinfo = au_sbi(sb); | |
24143 | + tmp = sbinfo->si_mntflags; | |
24144 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
24145 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL); | |
24146 | + | |
24147 | + opt = opts->opt; | |
24148 | + while (err >= 0 && opt->type != Opt_tail) | |
24149 | + err = au_opt_br(sb, opt++, opts); | |
24150 | + if (err > 0) | |
24151 | + err = 0; | |
24152 | + else if (unlikely(err < 0)) | |
24153 | + goto out; | |
24154 | + | |
24155 | + bend = au_sbend(sb); | |
24156 | + if (unlikely(bend < 0)) { | |
24157 | + err = -EINVAL; | |
4a4d8108 | 24158 | + pr_err("no branches\n"); |
1facf9fc | 24159 | + goto out; |
24160 | + } | |
24161 | + | |
24162 | + if (au_opt_test(tmp, XINO)) | |
24163 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
24164 | + opt = opts->opt; | |
24165 | + while (!err && opt->type != Opt_tail) | |
24166 | + err = au_opt_xino(sb, opt++, &opt_xino, opts); | |
24167 | + if (unlikely(err)) | |
24168 | + goto out; | |
24169 | + | |
24170 | + err = au_opts_verify(sb, sb->s_flags, tmp); | |
24171 | + if (unlikely(err)) | |
24172 | + goto out; | |
24173 | + | |
24174 | + /* restore xino */ | |
24175 | + if (au_opt_test(tmp, XINO) && !opt_xino) { | |
24176 | + xino.file = au_xino_def(sb); | |
24177 | + err = PTR_ERR(xino.file); | |
24178 | + if (IS_ERR(xino.file)) | |
24179 | + goto out; | |
24180 | + | |
24181 | + err = au_xino_set(sb, &xino, /*remount*/0); | |
24182 | + fput(xino.file); | |
24183 | + if (unlikely(err)) | |
24184 | + goto out; | |
24185 | + } | |
24186 | + | |
24187 | + /* restore udba */ | |
027c5e7a | 24188 | + tmp &= AuOptMask_UDBA; |
1facf9fc | 24189 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; |
027c5e7a AM |
24190 | + sbinfo->si_mntflags |= tmp; |
24191 | + bend = au_sbend(sb); | |
24192 | + for (bindex = 0; bindex <= bend; bindex++) { | |
24193 | + br = au_sbr(sb, bindex); | |
24194 | + err = au_hnotify_reset_br(tmp, br, br->br_perm); | |
24195 | + if (unlikely(err)) | |
24196 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", | |
24197 | + bindex, err); | |
24198 | + /* go on even if err */ | |
24199 | + } | |
4a4d8108 | 24200 | + if (au_opt_test(tmp, UDBA_HNOTIFY)) { |
076b876e | 24201 | + dir = sb->s_root->d_inode; |
4a4d8108 | 24202 | + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO); |
1facf9fc | 24203 | + } |
24204 | + | |
4f0767ce | 24205 | +out: |
1facf9fc | 24206 | + return err; |
24207 | +} | |
24208 | + | |
24209 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts) | |
24210 | +{ | |
24211 | + int err, rerr; | |
24212 | + struct inode *dir; | |
24213 | + struct au_opt_xino *opt_xino; | |
24214 | + struct au_opt *opt; | |
24215 | + struct au_sbinfo *sbinfo; | |
24216 | + | |
dece6358 AM |
24217 | + SiMustWriteLock(sb); |
24218 | + | |
1facf9fc | 24219 | + dir = sb->s_root->d_inode; |
24220 | + sbinfo = au_sbi(sb); | |
24221 | + err = 0; | |
24222 | + opt_xino = NULL; | |
24223 | + opt = opts->opt; | |
24224 | + while (err >= 0 && opt->type != Opt_tail) { | |
24225 | + err = au_opt_simple(sb, opt, opts); | |
24226 | + if (!err) | |
24227 | + err = au_opt_br(sb, opt, opts); | |
24228 | + if (!err) | |
24229 | + err = au_opt_xino(sb, opt, &opt_xino, opts); | |
24230 | + opt++; | |
24231 | + } | |
24232 | + if (err > 0) | |
24233 | + err = 0; | |
24234 | + AuTraceErr(err); | |
24235 | + /* go on even err */ | |
24236 | + | |
24237 | + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0); | |
24238 | + if (unlikely(rerr && !err)) | |
24239 | + err = rerr; | |
24240 | + | |
24241 | + if (au_ftest_opts(opts->flags, TRUNC_XIB)) { | |
24242 | + rerr = au_xib_trunc(sb); | |
24243 | + if (unlikely(rerr && !err)) | |
24244 | + err = rerr; | |
24245 | + } | |
24246 | + | |
24247 | + /* will be handled by the caller */ | |
027c5e7a | 24248 | + if (!au_ftest_opts(opts->flags, REFRESH) |
1facf9fc | 24249 | + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO))) |
027c5e7a | 24250 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 24251 | + |
24252 | + AuDbg("status 0x%x\n", opts->flags); | |
24253 | + return err; | |
24254 | +} | |
24255 | + | |
24256 | +/* ---------------------------------------------------------------------- */ | |
24257 | + | |
24258 | +unsigned int au_opt_udba(struct super_block *sb) | |
24259 | +{ | |
24260 | + return au_mntflags(sb) & AuOptMask_UDBA; | |
24261 | +} | |
7f207e10 AM |
24262 | diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h |
24263 | --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 24264 | +++ linux/fs/aufs/opts.h 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 24265 | @@ -0,0 +1,213 @@ |
1facf9fc | 24266 | +/* |
523b37e3 | 24267 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 24268 | + * |
24269 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24270 | + * it under the terms of the GNU General Public License as published by | |
24271 | + * the Free Software Foundation; either version 2 of the License, or | |
24272 | + * (at your option) any later version. | |
dece6358 AM |
24273 | + * |
24274 | + * This program is distributed in the hope that it will be useful, | |
24275 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24276 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24277 | + * GNU General Public License for more details. | |
24278 | + * | |
24279 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24280 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24281 | + */ |
24282 | + | |
24283 | +/* | |
24284 | + * mount options/flags | |
24285 | + */ | |
24286 | + | |
24287 | +#ifndef __AUFS_OPTS_H__ | |
24288 | +#define __AUFS_OPTS_H__ | |
24289 | + | |
24290 | +#ifdef __KERNEL__ | |
24291 | + | |
dece6358 | 24292 | +#include <linux/path.h> |
076b876e | 24293 | +#include "branch.h" |
1facf9fc | 24294 | + |
dece6358 AM |
24295 | +struct file; |
24296 | +struct super_block; | |
24297 | + | |
1facf9fc | 24298 | +/* ---------------------------------------------------------------------- */ |
24299 | + | |
24300 | +/* mount flags */ | |
24301 | +#define AuOpt_XINO 1 /* external inode number bitmap | |
24302 | + and translation table */ | |
24303 | +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */ | |
24304 | +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */ | |
24305 | +#define AuOpt_UDBA_REVAL (1 << 3) | |
4a4d8108 | 24306 | +#define AuOpt_UDBA_HNOTIFY (1 << 4) |
dece6358 AM |
24307 | +#define AuOpt_SHWH (1 << 5) /* show whiteout */ |
24308 | +#define AuOpt_PLINK (1 << 6) /* pseudo-link */ | |
076b876e AM |
24309 | +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm |
24310 | + bits */ | |
dece6358 AM |
24311 | +#define AuOpt_REFROF (1 << 8) /* unimplemented */ |
24312 | +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */ | |
24313 | +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */ | |
24314 | +#define AuOpt_SUM_W (1 << 11) /* unimplemented */ | |
24315 | +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */ | |
24316 | +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */ | |
4a4d8108 | 24317 | +#define AuOpt_DIO (1 << 14) /* direct io */ |
1facf9fc | 24318 | + |
4a4d8108 AM |
24319 | +#ifndef CONFIG_AUFS_HNOTIFY |
24320 | +#undef AuOpt_UDBA_HNOTIFY | |
24321 | +#define AuOpt_UDBA_HNOTIFY 0 | |
1facf9fc | 24322 | +#endif |
dece6358 AM |
24323 | +#ifndef CONFIG_AUFS_SHWH |
24324 | +#undef AuOpt_SHWH | |
24325 | +#define AuOpt_SHWH 0 | |
24326 | +#endif | |
1facf9fc | 24327 | + |
24328 | +#define AuOpt_Def (AuOpt_XINO \ | |
24329 | + | AuOpt_UDBA_REVAL \ | |
24330 | + | AuOpt_PLINK \ | |
24331 | + /* | AuOpt_DIRPERM1 */ \ | |
24332 | + | AuOpt_WARN_PERM) | |
24333 | +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \ | |
24334 | + | AuOpt_UDBA_REVAL \ | |
4a4d8108 | 24335 | + | AuOpt_UDBA_HNOTIFY) |
1facf9fc | 24336 | + |
24337 | +#define au_opt_test(flags, name) (flags & AuOpt_##name) | |
24338 | +#define au_opt_set(flags, name) do { \ | |
24339 | + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \ | |
24340 | + ((flags) |= AuOpt_##name); \ | |
24341 | +} while (0) | |
24342 | +#define au_opt_set_udba(flags, name) do { \ | |
24343 | + (flags) &= ~AuOptMask_UDBA; \ | |
24344 | + ((flags) |= AuOpt_##name); \ | |
24345 | +} while (0) | |
7f207e10 AM |
24346 | +#define au_opt_clr(flags, name) do { \ |
24347 | + ((flags) &= ~AuOpt_##name); \ | |
24348 | +} while (0) | |
1facf9fc | 24349 | + |
e49829fe JR |
24350 | +static inline unsigned int au_opts_plink(unsigned int mntflags) |
24351 | +{ | |
24352 | +#ifdef CONFIG_PROC_FS | |
24353 | + return mntflags; | |
24354 | +#else | |
24355 | + return mntflags & ~AuOpt_PLINK; | |
24356 | +#endif | |
24357 | +} | |
24358 | + | |
1facf9fc | 24359 | +/* ---------------------------------------------------------------------- */ |
24360 | + | |
24361 | +/* policies to select one among multiple writable branches */ | |
24362 | +enum { | |
24363 | + AuWbrCreate_TDP, /* top down parent */ | |
24364 | + AuWbrCreate_RR, /* round robin */ | |
24365 | + AuWbrCreate_MFS, /* most free space */ | |
24366 | + AuWbrCreate_MFSV, /* mfs with seconds */ | |
24367 | + AuWbrCreate_MFSRR, /* mfs then rr */ | |
24368 | + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */ | |
24369 | + AuWbrCreate_PMFS, /* parent and mfs */ | |
24370 | + AuWbrCreate_PMFSV, /* parent and mfs with seconds */ | |
392086de AM |
24371 | + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */ |
24372 | + AuWbrCreate_PMFSRRV, /* plus seconds */ | |
1facf9fc | 24373 | + |
24374 | + AuWbrCreate_Def = AuWbrCreate_TDP | |
24375 | +}; | |
24376 | + | |
24377 | +enum { | |
24378 | + AuWbrCopyup_TDP, /* top down parent */ | |
24379 | + AuWbrCopyup_BUP, /* bottom up parent */ | |
24380 | + AuWbrCopyup_BU, /* bottom up */ | |
24381 | + | |
24382 | + AuWbrCopyup_Def = AuWbrCopyup_TDP | |
24383 | +}; | |
24384 | + | |
24385 | +/* ---------------------------------------------------------------------- */ | |
24386 | + | |
24387 | +struct au_opt_add { | |
24388 | + aufs_bindex_t bindex; | |
24389 | + char *pathname; | |
24390 | + int perm; | |
24391 | + struct path path; | |
24392 | +}; | |
24393 | + | |
24394 | +struct au_opt_del { | |
24395 | + char *pathname; | |
24396 | + struct path h_path; | |
24397 | +}; | |
24398 | + | |
24399 | +struct au_opt_mod { | |
24400 | + char *path; | |
24401 | + int perm; | |
24402 | + struct dentry *h_root; | |
24403 | +}; | |
24404 | + | |
24405 | +struct au_opt_xino { | |
24406 | + char *path; | |
24407 | + struct file *file; | |
24408 | +}; | |
24409 | + | |
24410 | +struct au_opt_xino_itrunc { | |
24411 | + aufs_bindex_t bindex; | |
24412 | +}; | |
24413 | + | |
24414 | +struct au_opt_wbr_create { | |
24415 | + int wbr_create; | |
24416 | + int mfs_second; | |
24417 | + unsigned long long mfsrr_watermark; | |
24418 | +}; | |
24419 | + | |
24420 | +struct au_opt { | |
24421 | + int type; | |
24422 | + union { | |
24423 | + struct au_opt_xino xino; | |
24424 | + struct au_opt_xino_itrunc xino_itrunc; | |
24425 | + struct au_opt_add add; | |
24426 | + struct au_opt_del del; | |
24427 | + struct au_opt_mod mod; | |
24428 | + int dirwh; | |
24429 | + int rdcache; | |
24430 | + unsigned int rdblk; | |
24431 | + unsigned int rdhash; | |
24432 | + int udba; | |
24433 | + struct au_opt_wbr_create wbr_create; | |
24434 | + int wbr_copyup; | |
076b876e | 24435 | + unsigned int fhsm_second; |
1facf9fc | 24436 | + }; |
24437 | +}; | |
24438 | + | |
24439 | +/* opts flags */ | |
24440 | +#define AuOpts_REMOUNT 1 | |
027c5e7a AM |
24441 | +#define AuOpts_REFRESH (1 << 1) |
24442 | +#define AuOpts_TRUNC_XIB (1 << 2) | |
24443 | +#define AuOpts_REFRESH_DYAOP (1 << 3) | |
1facf9fc | 24444 | +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name) |
7f207e10 AM |
24445 | +#define au_fset_opts(flags, name) \ |
24446 | + do { (flags) |= AuOpts_##name; } while (0) | |
24447 | +#define au_fclr_opts(flags, name) \ | |
24448 | + do { (flags) &= ~AuOpts_##name; } while (0) | |
1facf9fc | 24449 | + |
24450 | +struct au_opts { | |
24451 | + struct au_opt *opt; | |
24452 | + int max_opt; | |
24453 | + | |
24454 | + unsigned int given_udba; | |
24455 | + unsigned int flags; | |
24456 | + unsigned long sb_flags; | |
24457 | +}; | |
24458 | + | |
24459 | +/* ---------------------------------------------------------------------- */ | |
24460 | + | |
076b876e | 24461 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm); |
1facf9fc | 24462 | +const char *au_optstr_udba(int udba); |
24463 | +const char *au_optstr_wbr_copyup(int wbr_copyup); | |
24464 | +const char *au_optstr_wbr_create(int wbr_create); | |
24465 | + | |
24466 | +void au_opts_free(struct au_opts *opts); | |
24467 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts); | |
24468 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
24469 | + unsigned int pending); | |
24470 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts); | |
24471 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts); | |
24472 | + | |
24473 | +unsigned int au_opt_udba(struct super_block *sb); | |
24474 | + | |
24475 | +/* ---------------------------------------------------------------------- */ | |
24476 | + | |
24477 | +#endif /* __KERNEL__ */ | |
24478 | +#endif /* __AUFS_OPTS_H__ */ | |
7f207e10 AM |
24479 | diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c |
24480 | --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 24481 | +++ linux/fs/aufs/plink.c 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 24482 | @@ -0,0 +1,532 @@ |
1facf9fc | 24483 | +/* |
523b37e3 | 24484 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 24485 | + * |
24486 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24487 | + * it under the terms of the GNU General Public License as published by | |
24488 | + * the Free Software Foundation; either version 2 of the License, or | |
24489 | + * (at your option) any later version. | |
dece6358 AM |
24490 | + * |
24491 | + * This program is distributed in the hope that it will be useful, | |
24492 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24493 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24494 | + * GNU General Public License for more details. | |
24495 | + * | |
24496 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24497 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24498 | + */ |
24499 | + | |
24500 | +/* | |
24501 | + * pseudo-link | |
24502 | + */ | |
24503 | + | |
24504 | +#include "aufs.h" | |
24505 | + | |
24506 | +/* | |
e49829fe | 24507 | + * the pseudo-link maintenance mode. |
1facf9fc | 24508 | + * during a user process maintains the pseudo-links, |
24509 | + * prohibit adding a new plink and branch manipulation. | |
e49829fe JR |
24510 | + * |
24511 | + * Flags | |
24512 | + * NOPLM: | |
24513 | + * For entry functions which will handle plink, and i_mutex is already held | |
24514 | + * in VFS. | |
24515 | + * They cannot wait and should return an error at once. | |
24516 | + * Callers has to check the error. | |
24517 | + * NOPLMW: | |
24518 | + * For entry functions which will handle plink, but i_mutex is not held | |
24519 | + * in VFS. | |
24520 | + * They can wait the plink maintenance mode to finish. | |
24521 | + * | |
24522 | + * They behave like F_SETLK and F_SETLKW. | |
24523 | + * If the caller never handle plink, then both flags are unnecessary. | |
1facf9fc | 24524 | + */ |
e49829fe JR |
24525 | + |
24526 | +int au_plink_maint(struct super_block *sb, int flags) | |
1facf9fc | 24527 | +{ |
e49829fe JR |
24528 | + int err; |
24529 | + pid_t pid, ppid; | |
24530 | + struct au_sbinfo *sbi; | |
dece6358 AM |
24531 | + |
24532 | + SiMustAnyLock(sb); | |
24533 | + | |
e49829fe JR |
24534 | + err = 0; |
24535 | + if (!au_opt_test(au_mntflags(sb), PLINK)) | |
24536 | + goto out; | |
24537 | + | |
24538 | + sbi = au_sbi(sb); | |
24539 | + pid = sbi->si_plink_maint_pid; | |
24540 | + if (!pid || pid == current->pid) | |
24541 | + goto out; | |
24542 | + | |
24543 | + /* todo: it highly depends upon /sbin/mount.aufs */ | |
24544 | + rcu_read_lock(); | |
24545 | + ppid = task_pid_vnr(rcu_dereference(current->real_parent)); | |
24546 | + rcu_read_unlock(); | |
24547 | + if (pid == ppid) | |
24548 | + goto out; | |
24549 | + | |
24550 | + if (au_ftest_lock(flags, NOPLMW)) { | |
027c5e7a AM |
24551 | + /* if there is no i_mutex lock in VFS, we don't need to wait */ |
24552 | + /* AuDebugOn(!lockdep_depth(current)); */ | |
e49829fe JR |
24553 | + while (sbi->si_plink_maint_pid) { |
24554 | + si_read_unlock(sb); | |
24555 | + /* gave up wake_up_bit() */ | |
24556 | + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid); | |
24557 | + | |
24558 | + if (au_ftest_lock(flags, FLUSH)) | |
24559 | + au_nwt_flush(&sbi->si_nowait); | |
24560 | + si_noflush_read_lock(sb); | |
24561 | + } | |
24562 | + } else if (au_ftest_lock(flags, NOPLM)) { | |
24563 | + AuDbg("ppid %d, pid %d\n", ppid, pid); | |
24564 | + err = -EAGAIN; | |
24565 | + } | |
24566 | + | |
24567 | +out: | |
24568 | + return err; | |
4a4d8108 AM |
24569 | +} |
24570 | + | |
e49829fe | 24571 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo) |
4a4d8108 | 24572 | +{ |
4a4d8108 | 24573 | + spin_lock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 24574 | + sbinfo->si_plink_maint_pid = 0; |
4a4d8108 | 24575 | + spin_unlock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 24576 | + wake_up_all(&sbinfo->si_plink_wq); |
4a4d8108 AM |
24577 | +} |
24578 | + | |
e49829fe | 24579 | +int au_plink_maint_enter(struct super_block *sb) |
4a4d8108 AM |
24580 | +{ |
24581 | + int err; | |
4a4d8108 AM |
24582 | + struct au_sbinfo *sbinfo; |
24583 | + | |
24584 | + err = 0; | |
4a4d8108 AM |
24585 | + sbinfo = au_sbi(sb); |
24586 | + /* make sure i am the only one in this fs */ | |
e49829fe JR |
24587 | + si_write_lock(sb, AuLock_FLUSH); |
24588 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
24589 | + spin_lock(&sbinfo->si_plink_maint_lock); | |
24590 | + if (!sbinfo->si_plink_maint_pid) | |
24591 | + sbinfo->si_plink_maint_pid = current->pid; | |
24592 | + else | |
24593 | + err = -EBUSY; | |
24594 | + spin_unlock(&sbinfo->si_plink_maint_lock); | |
24595 | + } | |
4a4d8108 AM |
24596 | + si_write_unlock(sb); |
24597 | + | |
24598 | + return err; | |
1facf9fc | 24599 | +} |
24600 | + | |
24601 | +/* ---------------------------------------------------------------------- */ | |
24602 | + | |
1facf9fc | 24603 | +#ifdef CONFIG_AUFS_DEBUG |
24604 | +void au_plink_list(struct super_block *sb) | |
24605 | +{ | |
86dc4139 | 24606 | + int i; |
1facf9fc | 24607 | + struct au_sbinfo *sbinfo; |
86dc4139 | 24608 | + struct hlist_head *plink_hlist; |
1facf9fc | 24609 | + struct pseudo_link *plink; |
24610 | + | |
dece6358 AM |
24611 | + SiMustAnyLock(sb); |
24612 | + | |
1facf9fc | 24613 | + sbinfo = au_sbi(sb); |
24614 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 24615 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 24616 | + |
86dc4139 AM |
24617 | + for (i = 0; i < AuPlink_NHASH; i++) { |
24618 | + plink_hlist = &sbinfo->si_plink[i].head; | |
24619 | + rcu_read_lock(); | |
24620 | + hlist_for_each_entry_rcu(plink, plink_hlist, hlist) | |
24621 | + AuDbg("%lu\n", plink->inode->i_ino); | |
24622 | + rcu_read_unlock(); | |
24623 | + } | |
1facf9fc | 24624 | +} |
24625 | +#endif | |
24626 | + | |
24627 | +/* is the inode pseudo-linked? */ | |
24628 | +int au_plink_test(struct inode *inode) | |
24629 | +{ | |
86dc4139 | 24630 | + int found, i; |
1facf9fc | 24631 | + struct au_sbinfo *sbinfo; |
86dc4139 | 24632 | + struct hlist_head *plink_hlist; |
1facf9fc | 24633 | + struct pseudo_link *plink; |
24634 | + | |
24635 | + sbinfo = au_sbi(inode->i_sb); | |
dece6358 | 24636 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
1facf9fc | 24637 | + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK)); |
e49829fe | 24638 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
1facf9fc | 24639 | + |
24640 | + found = 0; | |
86dc4139 AM |
24641 | + i = au_plink_hash(inode->i_ino); |
24642 | + plink_hlist = &sbinfo->si_plink[i].head; | |
4a4d8108 | 24643 | + rcu_read_lock(); |
86dc4139 | 24644 | + hlist_for_each_entry_rcu(plink, plink_hlist, hlist) |
1facf9fc | 24645 | + if (plink->inode == inode) { |
24646 | + found = 1; | |
24647 | + break; | |
24648 | + } | |
4a4d8108 | 24649 | + rcu_read_unlock(); |
1facf9fc | 24650 | + return found; |
24651 | +} | |
24652 | + | |
24653 | +/* ---------------------------------------------------------------------- */ | |
24654 | + | |
24655 | +/* | |
24656 | + * generate a name for plink. | |
24657 | + * the file will be stored under AUFS_WH_PLINKDIR. | |
24658 | + */ | |
24659 | +/* 20 is max digits length of ulong 64 */ | |
24660 | +#define PLINK_NAME_LEN ((20 + 1) * 2) | |
24661 | + | |
24662 | +static int plink_name(char *name, int len, struct inode *inode, | |
24663 | + aufs_bindex_t bindex) | |
24664 | +{ | |
24665 | + int rlen; | |
24666 | + struct inode *h_inode; | |
24667 | + | |
24668 | + h_inode = au_h_iptr(inode, bindex); | |
24669 | + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino); | |
24670 | + return rlen; | |
24671 | +} | |
24672 | + | |
7f207e10 AM |
24673 | +struct au_do_plink_lkup_args { |
24674 | + struct dentry **errp; | |
24675 | + struct qstr *tgtname; | |
24676 | + struct dentry *h_parent; | |
24677 | + struct au_branch *br; | |
24678 | +}; | |
24679 | + | |
24680 | +static struct dentry *au_do_plink_lkup(struct qstr *tgtname, | |
24681 | + struct dentry *h_parent, | |
24682 | + struct au_branch *br) | |
24683 | +{ | |
24684 | + struct dentry *h_dentry; | |
24685 | + struct mutex *h_mtx; | |
24686 | + | |
24687 | + h_mtx = &h_parent->d_inode->i_mutex; | |
24688 | + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2); | |
b4510431 | 24689 | + h_dentry = vfsub_lkup_one(tgtname, h_parent); |
7f207e10 AM |
24690 | + mutex_unlock(h_mtx); |
24691 | + return h_dentry; | |
24692 | +} | |
24693 | + | |
24694 | +static void au_call_do_plink_lkup(void *args) | |
24695 | +{ | |
24696 | + struct au_do_plink_lkup_args *a = args; | |
24697 | + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br); | |
24698 | +} | |
24699 | + | |
1facf9fc | 24700 | +/* lookup the plink-ed @inode under the branch at @bindex */ |
24701 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex) | |
24702 | +{ | |
24703 | + struct dentry *h_dentry, *h_parent; | |
24704 | + struct au_branch *br; | |
24705 | + struct inode *h_dir; | |
7f207e10 | 24706 | + int wkq_err; |
1facf9fc | 24707 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 24708 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 24709 | + |
e49829fe JR |
24710 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
24711 | + | |
1facf9fc | 24712 | + br = au_sbr(inode->i_sb, bindex); |
24713 | + h_parent = br->br_wbr->wbr_plink; | |
24714 | + h_dir = h_parent->d_inode; | |
24715 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); | |
24716 | + | |
2dfbb274 | 24717 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
7f207e10 AM |
24718 | + struct au_do_plink_lkup_args args = { |
24719 | + .errp = &h_dentry, | |
24720 | + .tgtname = &tgtname, | |
24721 | + .h_parent = h_parent, | |
24722 | + .br = br | |
24723 | + }; | |
24724 | + | |
24725 | + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args); | |
24726 | + if (unlikely(wkq_err)) | |
24727 | + h_dentry = ERR_PTR(wkq_err); | |
24728 | + } else | |
24729 | + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br); | |
24730 | + | |
1facf9fc | 24731 | + return h_dentry; |
24732 | +} | |
24733 | + | |
24734 | +/* create a pseudo-link */ | |
24735 | +static int do_whplink(struct qstr *tgt, struct dentry *h_parent, | |
24736 | + struct dentry *h_dentry, struct au_branch *br) | |
24737 | +{ | |
24738 | + int err; | |
24739 | + struct path h_path = { | |
86dc4139 | 24740 | + .mnt = au_br_mnt(br) |
1facf9fc | 24741 | + }; |
523b37e3 | 24742 | + struct inode *h_dir, *delegated; |
1facf9fc | 24743 | + |
24744 | + h_dir = h_parent->d_inode; | |
7f207e10 | 24745 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2); |
4f0767ce | 24746 | +again: |
b4510431 | 24747 | + h_path.dentry = vfsub_lkup_one(tgt, h_parent); |
1facf9fc | 24748 | + err = PTR_ERR(h_path.dentry); |
24749 | + if (IS_ERR(h_path.dentry)) | |
24750 | + goto out; | |
24751 | + | |
24752 | + err = 0; | |
24753 | + /* wh.plink dir is not monitored */ | |
7f207e10 | 24754 | + /* todo: is it really safe? */ |
1facf9fc | 24755 | + if (h_path.dentry->d_inode |
24756 | + && h_path.dentry->d_inode != h_dentry->d_inode) { | |
523b37e3 AM |
24757 | + delegated = NULL; |
24758 | + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0); | |
24759 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24760 | + pr_warn("cannot retry for NFSv4 delegation" | |
24761 | + " for an internal unlink\n"); | |
24762 | + iput(delegated); | |
24763 | + } | |
1facf9fc | 24764 | + dput(h_path.dentry); |
24765 | + h_path.dentry = NULL; | |
24766 | + if (!err) | |
24767 | + goto again; | |
24768 | + } | |
523b37e3 AM |
24769 | + if (!err && !h_path.dentry->d_inode) { |
24770 | + delegated = NULL; | |
24771 | + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated); | |
24772 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24773 | + pr_warn("cannot retry for NFSv4 delegation" | |
24774 | + " for an internal link\n"); | |
24775 | + iput(delegated); | |
24776 | + } | |
24777 | + } | |
1facf9fc | 24778 | + dput(h_path.dentry); |
24779 | + | |
4f0767ce | 24780 | +out: |
7f207e10 | 24781 | + mutex_unlock(&h_dir->i_mutex); |
1facf9fc | 24782 | + return err; |
24783 | +} | |
24784 | + | |
24785 | +struct do_whplink_args { | |
24786 | + int *errp; | |
24787 | + struct qstr *tgt; | |
24788 | + struct dentry *h_parent; | |
24789 | + struct dentry *h_dentry; | |
24790 | + struct au_branch *br; | |
24791 | +}; | |
24792 | + | |
24793 | +static void call_do_whplink(void *args) | |
24794 | +{ | |
24795 | + struct do_whplink_args *a = args; | |
24796 | + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br); | |
24797 | +} | |
24798 | + | |
24799 | +static int whplink(struct dentry *h_dentry, struct inode *inode, | |
24800 | + aufs_bindex_t bindex, struct au_branch *br) | |
24801 | +{ | |
24802 | + int err, wkq_err; | |
24803 | + struct au_wbr *wbr; | |
24804 | + struct dentry *h_parent; | |
24805 | + struct inode *h_dir; | |
24806 | + char a[PLINK_NAME_LEN]; | |
0c3ec466 | 24807 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 24808 | + |
24809 | + wbr = au_sbr(inode->i_sb, bindex)->br_wbr; | |
24810 | + h_parent = wbr->wbr_plink; | |
24811 | + h_dir = h_parent->d_inode; | |
24812 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); | |
24813 | + | |
24814 | + /* always superio. */ | |
2dfbb274 | 24815 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
1facf9fc | 24816 | + struct do_whplink_args args = { |
24817 | + .errp = &err, | |
24818 | + .tgt = &tgtname, | |
24819 | + .h_parent = h_parent, | |
24820 | + .h_dentry = h_dentry, | |
24821 | + .br = br | |
24822 | + }; | |
24823 | + wkq_err = au_wkq_wait(call_do_whplink, &args); | |
24824 | + if (unlikely(wkq_err)) | |
24825 | + err = wkq_err; | |
24826 | + } else | |
24827 | + err = do_whplink(&tgtname, h_parent, h_dentry, br); | |
1facf9fc | 24828 | + |
24829 | + return err; | |
24830 | +} | |
24831 | + | |
24832 | +/* free a single plink */ | |
24833 | +static void do_put_plink(struct pseudo_link *plink, int do_del) | |
24834 | +{ | |
1facf9fc | 24835 | + if (do_del) |
86dc4139 | 24836 | + hlist_del(&plink->hlist); |
4a4d8108 AM |
24837 | + iput(plink->inode); |
24838 | + kfree(plink); | |
24839 | +} | |
24840 | + | |
24841 | +static void do_put_plink_rcu(struct rcu_head *rcu) | |
24842 | +{ | |
24843 | + struct pseudo_link *plink; | |
24844 | + | |
24845 | + plink = container_of(rcu, struct pseudo_link, rcu); | |
24846 | + iput(plink->inode); | |
1facf9fc | 24847 | + kfree(plink); |
24848 | +} | |
24849 | + | |
24850 | +/* | |
24851 | + * create a new pseudo-link for @h_dentry on @bindex. | |
24852 | + * the linked inode is held in aufs @inode. | |
24853 | + */ | |
24854 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
24855 | + struct dentry *h_dentry) | |
24856 | +{ | |
24857 | + struct super_block *sb; | |
24858 | + struct au_sbinfo *sbinfo; | |
86dc4139 | 24859 | + struct hlist_head *plink_hlist; |
4a4d8108 | 24860 | + struct pseudo_link *plink, *tmp; |
86dc4139 AM |
24861 | + struct au_sphlhead *sphl; |
24862 | + int found, err, cnt, i; | |
1facf9fc | 24863 | + |
24864 | + sb = inode->i_sb; | |
24865 | + sbinfo = au_sbi(sb); | |
24866 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 24867 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 24868 | + |
86dc4139 | 24869 | + found = au_plink_test(inode); |
4a4d8108 | 24870 | + if (found) |
1facf9fc | 24871 | + return; |
4a4d8108 | 24872 | + |
86dc4139 AM |
24873 | + i = au_plink_hash(inode->i_ino); |
24874 | + sphl = sbinfo->si_plink + i; | |
24875 | + plink_hlist = &sphl->head; | |
4a4d8108 AM |
24876 | + tmp = kmalloc(sizeof(*plink), GFP_NOFS); |
24877 | + if (tmp) | |
24878 | + tmp->inode = au_igrab(inode); | |
24879 | + else { | |
24880 | + err = -ENOMEM; | |
24881 | + goto out; | |
1facf9fc | 24882 | + } |
24883 | + | |
86dc4139 AM |
24884 | + spin_lock(&sphl->spin); |
24885 | + hlist_for_each_entry(plink, plink_hlist, hlist) { | |
4a4d8108 AM |
24886 | + if (plink->inode == inode) { |
24887 | + found = 1; | |
24888 | + break; | |
24889 | + } | |
1facf9fc | 24890 | + } |
4a4d8108 | 24891 | + if (!found) |
86dc4139 AM |
24892 | + hlist_add_head_rcu(&tmp->hlist, plink_hlist); |
24893 | + spin_unlock(&sphl->spin); | |
4a4d8108 | 24894 | + if (!found) { |
86dc4139 AM |
24895 | + cnt = au_sphl_count(sphl); |
24896 | +#define msg "unexpectedly unblanced or too many pseudo-links" | |
24897 | + if (cnt > AUFS_PLINK_WARN) | |
24898 | + AuWarn1(msg ", %d\n", cnt); | |
24899 | +#undef msg | |
1facf9fc | 24900 | + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex)); |
4a4d8108 AM |
24901 | + } else { |
24902 | + do_put_plink(tmp, 0); | |
24903 | + return; | |
1facf9fc | 24904 | + } |
24905 | + | |
4a4d8108 | 24906 | +out: |
1facf9fc | 24907 | + if (unlikely(err)) { |
0c3ec466 | 24908 | + pr_warn("err %d, damaged pseudo link.\n", err); |
4a4d8108 | 24909 | + if (tmp) { |
86dc4139 | 24910 | + au_sphl_del_rcu(&tmp->hlist, sphl); |
4a4d8108 AM |
24911 | + call_rcu(&tmp->rcu, do_put_plink_rcu); |
24912 | + } | |
1facf9fc | 24913 | + } |
24914 | +} | |
24915 | + | |
24916 | +/* free all plinks */ | |
e49829fe | 24917 | +void au_plink_put(struct super_block *sb, int verbose) |
1facf9fc | 24918 | +{ |
86dc4139 | 24919 | + int i, warned; |
1facf9fc | 24920 | + struct au_sbinfo *sbinfo; |
86dc4139 AM |
24921 | + struct hlist_head *plink_hlist; |
24922 | + struct hlist_node *tmp; | |
24923 | + struct pseudo_link *plink; | |
1facf9fc | 24924 | + |
dece6358 AM |
24925 | + SiMustWriteLock(sb); |
24926 | + | |
1facf9fc | 24927 | + sbinfo = au_sbi(sb); |
24928 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 24929 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 24930 | + |
1facf9fc | 24931 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
24932 | + warned = 0; |
24933 | + for (i = 0; i < AuPlink_NHASH; i++) { | |
24934 | + plink_hlist = &sbinfo->si_plink[i].head; | |
24935 | + if (!warned && verbose && !hlist_empty(plink_hlist)) { | |
24936 | + pr_warn("pseudo-link is not flushed"); | |
24937 | + warned = 1; | |
24938 | + } | |
24939 | + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) | |
24940 | + do_put_plink(plink, 0); | |
24941 | + INIT_HLIST_HEAD(plink_hlist); | |
24942 | + } | |
1facf9fc | 24943 | +} |
24944 | + | |
e49829fe JR |
24945 | +void au_plink_clean(struct super_block *sb, int verbose) |
24946 | +{ | |
24947 | + struct dentry *root; | |
24948 | + | |
24949 | + root = sb->s_root; | |
24950 | + aufs_write_lock(root); | |
24951 | + if (au_opt_test(au_mntflags(sb), PLINK)) | |
24952 | + au_plink_put(sb, verbose); | |
24953 | + aufs_write_unlock(root); | |
24954 | +} | |
24955 | + | |
86dc4139 AM |
24956 | +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id) |
24957 | +{ | |
24958 | + int do_put; | |
24959 | + aufs_bindex_t bstart, bend, bindex; | |
24960 | + | |
24961 | + do_put = 0; | |
24962 | + bstart = au_ibstart(inode); | |
24963 | + bend = au_ibend(inode); | |
24964 | + if (bstart >= 0) { | |
24965 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
24966 | + if (!au_h_iptr(inode, bindex) | |
24967 | + || au_ii_br_id(inode, bindex) != br_id) | |
24968 | + continue; | |
24969 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
24970 | + do_put = 1; | |
24971 | + break; | |
24972 | + } | |
24973 | + if (do_put) | |
24974 | + for (bindex = bstart; bindex <= bend; bindex++) | |
24975 | + if (au_h_iptr(inode, bindex)) { | |
24976 | + do_put = 0; | |
24977 | + break; | |
24978 | + } | |
24979 | + } else | |
24980 | + do_put = 1; | |
24981 | + | |
24982 | + return do_put; | |
24983 | +} | |
24984 | + | |
1facf9fc | 24985 | +/* free the plinks on a branch specified by @br_id */ |
24986 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id) | |
24987 | +{ | |
24988 | + struct au_sbinfo *sbinfo; | |
86dc4139 AM |
24989 | + struct hlist_head *plink_hlist; |
24990 | + struct hlist_node *tmp; | |
24991 | + struct pseudo_link *plink; | |
1facf9fc | 24992 | + struct inode *inode; |
86dc4139 | 24993 | + int i, do_put; |
1facf9fc | 24994 | + |
dece6358 AM |
24995 | + SiMustWriteLock(sb); |
24996 | + | |
1facf9fc | 24997 | + sbinfo = au_sbi(sb); |
24998 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 24999 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 25000 | + |
1facf9fc | 25001 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
25002 | + for (i = 0; i < AuPlink_NHASH; i++) { |
25003 | + plink_hlist = &sbinfo->si_plink[i].head; | |
25004 | + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) { | |
25005 | + inode = au_igrab(plink->inode); | |
25006 | + ii_write_lock_child(inode); | |
25007 | + do_put = au_plink_do_half_refresh(inode, br_id); | |
dece6358 AM |
25008 | + if (do_put) |
25009 | + do_put_plink(plink, 1); | |
86dc4139 AM |
25010 | + ii_write_unlock(inode); |
25011 | + iput(inode); | |
dece6358 | 25012 | + } |
dece6358 AM |
25013 | + } |
25014 | +} | |
7f207e10 AM |
25015 | diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c |
25016 | --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 25017 | +++ linux/fs/aufs/poll.c 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 25018 | @@ -0,0 +1,55 @@ |
dece6358 | 25019 | +/* |
523b37e3 | 25020 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
dece6358 AM |
25021 | + * |
25022 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25023 | + * it under the terms of the GNU General Public License as published by | |
25024 | + * the Free Software Foundation; either version 2 of the License, or | |
25025 | + * (at your option) any later version. | |
25026 | + * | |
25027 | + * This program is distributed in the hope that it will be useful, | |
25028 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25029 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25030 | + * GNU General Public License for more details. | |
25031 | + * | |
25032 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25033 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 AM |
25034 | + */ |
25035 | + | |
1308ab2a | 25036 | +/* |
25037 | + * poll operation | |
25038 | + * There is only one filesystem which implements ->poll operation, currently. | |
25039 | + */ | |
25040 | + | |
25041 | +#include "aufs.h" | |
25042 | + | |
25043 | +unsigned int aufs_poll(struct file *file, poll_table *wait) | |
25044 | +{ | |
25045 | + unsigned int mask; | |
25046 | + int err; | |
25047 | + struct file *h_file; | |
25048 | + struct dentry *dentry; | |
25049 | + struct super_block *sb; | |
25050 | + | |
25051 | + /* We should pretend an error happened. */ | |
25052 | + mask = POLLERR /* | POLLIN | POLLOUT */; | |
25053 | + dentry = file->f_dentry; | |
25054 | + sb = dentry->d_sb; | |
e49829fe | 25055 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
1308ab2a | 25056 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0); |
25057 | + if (unlikely(err)) | |
25058 | + goto out; | |
25059 | + | |
25060 | + /* it is not an error if h_file has no operation */ | |
25061 | + mask = DEFAULT_POLLMASK; | |
4a4d8108 | 25062 | + h_file = au_hf_top(file); |
523b37e3 | 25063 | + if (h_file->f_op->poll) |
1308ab2a | 25064 | + mask = h_file->f_op->poll(h_file, wait); |
25065 | + | |
25066 | + di_read_unlock(dentry, AuLock_IR); | |
25067 | + fi_read_unlock(file); | |
25068 | + | |
4f0767ce | 25069 | +out: |
1308ab2a | 25070 | + si_read_unlock(sb); |
25071 | + AuTraceErr((int)mask); | |
25072 | + return mask; | |
25073 | +} | |
c1595e42 JR |
25074 | diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c |
25075 | --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100 | |
25076 | +++ linux/fs/aufs/posix_acl.c 2015-01-25 13:00:38.634380408 +0100 | |
25077 | @@ -0,0 +1,99 @@ | |
25078 | +/* | |
25079 | + * Copyright (C) 2014 Junjiro R. Okajima | |
25080 | + * | |
25081 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25082 | + * it under the terms of the GNU General Public License as published by | |
25083 | + * the Free Software Foundation; either version 2 of the License, or | |
25084 | + * (at your option) any later version. | |
25085 | + * | |
25086 | + * This program is distributed in the hope that it will be useful, | |
25087 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25088 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25089 | + * GNU General Public License for more details. | |
25090 | + * | |
25091 | + * You should have received a copy of the GNU General Public License | |
25092 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25093 | + */ | |
25094 | + | |
25095 | +/* | |
25096 | + * posix acl operations | |
25097 | + */ | |
25098 | + | |
25099 | +#include <linux/fs.h> | |
25100 | +#include <linux/posix_acl.h> | |
25101 | +#include "aufs.h" | |
25102 | + | |
25103 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type) | |
25104 | +{ | |
25105 | + struct posix_acl *acl; | |
25106 | + int err; | |
25107 | + aufs_bindex_t bindex; | |
25108 | + struct inode *h_inode; | |
25109 | + struct super_block *sb; | |
25110 | + | |
25111 | + acl = NULL; | |
25112 | + sb = inode->i_sb; | |
25113 | + si_read_lock(sb, AuLock_FLUSH); | |
25114 | + ii_read_lock_child(inode); | |
25115 | + if (!(sb->s_flags & MS_POSIXACL)) | |
25116 | + goto out; | |
25117 | + | |
25118 | + bindex = au_ibstart(inode); | |
25119 | + h_inode = au_h_iptr(inode, bindex); | |
25120 | + if (unlikely(!h_inode | |
25121 | + || ((h_inode->i_mode & S_IFMT) | |
25122 | + != (inode->i_mode & S_IFMT)))) { | |
25123 | + err = au_busy_or_stale(); | |
25124 | + acl = ERR_PTR(err); | |
25125 | + goto out; | |
25126 | + } | |
25127 | + | |
25128 | + /* always topmost only */ | |
25129 | + acl = get_acl(h_inode, type); | |
25130 | + | |
25131 | +out: | |
25132 | + ii_read_unlock(inode); | |
25133 | + si_read_unlock(sb); | |
25134 | + | |
25135 | + AuTraceErrPtr(acl); | |
25136 | + return acl; | |
25137 | +} | |
25138 | + | |
25139 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |
25140 | +{ | |
25141 | + int err; | |
25142 | + ssize_t ssz; | |
25143 | + struct dentry *dentry; | |
25144 | + struct au_srxattr arg = { | |
25145 | + .type = AU_ACL_SET, | |
25146 | + .u.acl_set = { | |
25147 | + .acl = acl, | |
25148 | + .type = type | |
25149 | + }, | |
25150 | + }; | |
25151 | + | |
25152 | + mutex_lock(&inode->i_mutex); | |
25153 | + if (inode->i_ino == AUFS_ROOT_INO) | |
25154 | + dentry = dget(inode->i_sb->s_root); | |
25155 | + else { | |
25156 | + dentry = d_find_alias(inode); | |
25157 | + if (!dentry) | |
25158 | + dentry = d_find_any_alias(inode); | |
25159 | + if (!dentry) { | |
25160 | + pr_warn("cannot handle this inode, " | |
25161 | + "please report to aufs-users ML\n"); | |
25162 | + err = -ENOENT; | |
25163 | + goto out; | |
25164 | + } | |
25165 | + } | |
25166 | + | |
25167 | + ssz = au_srxattr(dentry, &arg); | |
25168 | + dput(dentry); | |
25169 | + err = ssz; | |
25170 | + if (ssz >= 0) | |
25171 | + err = 0; | |
25172 | + | |
25173 | +out: | |
25174 | + mutex_unlock(&inode->i_mutex); | |
25175 | + return err; | |
25176 | +} | |
7f207e10 AM |
25177 | diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c |
25178 | --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 25179 | +++ linux/fs/aufs/procfs.c 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 25180 | @@ -0,0 +1,169 @@ |
e49829fe | 25181 | +/* |
523b37e3 | 25182 | + * Copyright (C) 2010-2014 Junjiro R. Okajima |
e49829fe JR |
25183 | + * |
25184 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25185 | + * it under the terms of the GNU General Public License as published by | |
25186 | + * the Free Software Foundation; either version 2 of the License, or | |
25187 | + * (at your option) any later version. | |
25188 | + * | |
25189 | + * This program is distributed in the hope that it will be useful, | |
25190 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25191 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25192 | + * GNU General Public License for more details. | |
25193 | + * | |
25194 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25195 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
25196 | + */ |
25197 | + | |
25198 | +/* | |
25199 | + * procfs interfaces | |
25200 | + */ | |
25201 | + | |
25202 | +#include <linux/proc_fs.h> | |
25203 | +#include "aufs.h" | |
25204 | + | |
25205 | +static int au_procfs_plm_release(struct inode *inode, struct file *file) | |
25206 | +{ | |
25207 | + struct au_sbinfo *sbinfo; | |
25208 | + | |
25209 | + sbinfo = file->private_data; | |
25210 | + if (sbinfo) { | |
25211 | + au_plink_maint_leave(sbinfo); | |
25212 | + kobject_put(&sbinfo->si_kobj); | |
25213 | + } | |
25214 | + | |
25215 | + return 0; | |
25216 | +} | |
25217 | + | |
25218 | +static void au_procfs_plm_write_clean(struct file *file) | |
25219 | +{ | |
25220 | + struct au_sbinfo *sbinfo; | |
25221 | + | |
25222 | + sbinfo = file->private_data; | |
25223 | + if (sbinfo) | |
25224 | + au_plink_clean(sbinfo->si_sb, /*verbose*/0); | |
25225 | +} | |
25226 | + | |
25227 | +static int au_procfs_plm_write_si(struct file *file, unsigned long id) | |
25228 | +{ | |
25229 | + int err; | |
25230 | + struct super_block *sb; | |
25231 | + struct au_sbinfo *sbinfo; | |
25232 | + | |
25233 | + err = -EBUSY; | |
25234 | + if (unlikely(file->private_data)) | |
25235 | + goto out; | |
25236 | + | |
25237 | + sb = NULL; | |
53392da6 | 25238 | + /* don't use au_sbilist_lock() here */ |
e49829fe JR |
25239 | + spin_lock(&au_sbilist.spin); |
25240 | + list_for_each_entry(sbinfo, &au_sbilist.head, si_list) | |
25241 | + if (id == sysaufs_si_id(sbinfo)) { | |
25242 | + kobject_get(&sbinfo->si_kobj); | |
25243 | + sb = sbinfo->si_sb; | |
25244 | + break; | |
25245 | + } | |
25246 | + spin_unlock(&au_sbilist.spin); | |
25247 | + | |
25248 | + err = -EINVAL; | |
25249 | + if (unlikely(!sb)) | |
25250 | + goto out; | |
25251 | + | |
25252 | + err = au_plink_maint_enter(sb); | |
25253 | + if (!err) | |
25254 | + /* keep kobject_get() */ | |
25255 | + file->private_data = sbinfo; | |
25256 | + else | |
25257 | + kobject_put(&sbinfo->si_kobj); | |
25258 | +out: | |
25259 | + return err; | |
25260 | +} | |
25261 | + | |
25262 | +/* | |
25263 | + * Accept a valid "si=xxxx" only. | |
25264 | + * Once it is accepted successfully, accept "clean" too. | |
25265 | + */ | |
25266 | +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf, | |
25267 | + size_t count, loff_t *ppos) | |
25268 | +{ | |
25269 | + ssize_t err; | |
25270 | + unsigned long id; | |
25271 | + /* last newline is allowed */ | |
25272 | + char buf[3 + sizeof(unsigned long) * 2 + 1]; | |
25273 | + | |
25274 | + err = -EACCES; | |
25275 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
25276 | + goto out; | |
25277 | + | |
25278 | + err = -EINVAL; | |
25279 | + if (unlikely(count > sizeof(buf))) | |
25280 | + goto out; | |
25281 | + | |
25282 | + err = copy_from_user(buf, ubuf, count); | |
25283 | + if (unlikely(err)) { | |
25284 | + err = -EFAULT; | |
25285 | + goto out; | |
25286 | + } | |
25287 | + buf[count] = 0; | |
25288 | + | |
25289 | + err = -EINVAL; | |
25290 | + if (!strcmp("clean", buf)) { | |
25291 | + au_procfs_plm_write_clean(file); | |
25292 | + goto out_success; | |
25293 | + } else if (unlikely(strncmp("si=", buf, 3))) | |
25294 | + goto out; | |
25295 | + | |
9dbd164d | 25296 | + err = kstrtoul(buf + 3, 16, &id); |
e49829fe JR |
25297 | + if (unlikely(err)) |
25298 | + goto out; | |
25299 | + | |
25300 | + err = au_procfs_plm_write_si(file, id); | |
25301 | + if (unlikely(err)) | |
25302 | + goto out; | |
25303 | + | |
25304 | +out_success: | |
25305 | + err = count; /* success */ | |
25306 | +out: | |
25307 | + return err; | |
25308 | +} | |
25309 | + | |
25310 | +static const struct file_operations au_procfs_plm_fop = { | |
25311 | + .write = au_procfs_plm_write, | |
25312 | + .release = au_procfs_plm_release, | |
25313 | + .owner = THIS_MODULE | |
25314 | +}; | |
25315 | + | |
25316 | +/* ---------------------------------------------------------------------- */ | |
25317 | + | |
25318 | +static struct proc_dir_entry *au_procfs_dir; | |
25319 | + | |
25320 | +void au_procfs_fin(void) | |
25321 | +{ | |
25322 | + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir); | |
25323 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
25324 | +} | |
25325 | + | |
25326 | +int __init au_procfs_init(void) | |
25327 | +{ | |
25328 | + int err; | |
25329 | + struct proc_dir_entry *entry; | |
25330 | + | |
25331 | + err = -ENOMEM; | |
25332 | + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL); | |
25333 | + if (unlikely(!au_procfs_dir)) | |
25334 | + goto out; | |
25335 | + | |
25336 | + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR, | |
25337 | + au_procfs_dir, &au_procfs_plm_fop); | |
25338 | + if (unlikely(!entry)) | |
25339 | + goto out_dir; | |
25340 | + | |
25341 | + err = 0; | |
25342 | + goto out; /* success */ | |
25343 | + | |
25344 | + | |
25345 | +out_dir: | |
25346 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
25347 | +out: | |
25348 | + return err; | |
25349 | +} | |
7f207e10 AM |
25350 | diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c |
25351 | --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 25352 | +++ linux/fs/aufs/rdu.c 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 25353 | @@ -0,0 +1,388 @@ |
1308ab2a | 25354 | +/* |
523b37e3 | 25355 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1308ab2a | 25356 | + * |
25357 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25358 | + * it under the terms of the GNU General Public License as published by | |
25359 | + * the Free Software Foundation; either version 2 of the License, or | |
25360 | + * (at your option) any later version. | |
25361 | + * | |
25362 | + * This program is distributed in the hope that it will be useful, | |
25363 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25364 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25365 | + * GNU General Public License for more details. | |
25366 | + * | |
25367 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25368 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1308ab2a | 25369 | + */ |
25370 | + | |
25371 | +/* | |
25372 | + * readdir in userspace. | |
25373 | + */ | |
25374 | + | |
b752ccd1 | 25375 | +#include <linux/compat.h> |
4a4d8108 | 25376 | +#include <linux/fs_stack.h> |
1308ab2a | 25377 | +#include <linux/security.h> |
1308ab2a | 25378 | +#include "aufs.h" |
25379 | + | |
25380 | +/* bits for struct aufs_rdu.flags */ | |
25381 | +#define AuRdu_CALLED 1 | |
25382 | +#define AuRdu_CONT (1 << 1) | |
25383 | +#define AuRdu_FULL (1 << 2) | |
25384 | +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name) | |
7f207e10 AM |
25385 | +#define au_fset_rdu(flags, name) \ |
25386 | + do { (flags) |= AuRdu_##name; } while (0) | |
25387 | +#define au_fclr_rdu(flags, name) \ | |
25388 | + do { (flags) &= ~AuRdu_##name; } while (0) | |
1308ab2a | 25389 | + |
25390 | +struct au_rdu_arg { | |
392086de | 25391 | + struct dir_context ctx; |
1308ab2a | 25392 | + struct aufs_rdu *rdu; |
25393 | + union au_rdu_ent_ul ent; | |
25394 | + unsigned long end; | |
25395 | + | |
25396 | + struct super_block *sb; | |
25397 | + int err; | |
25398 | +}; | |
25399 | + | |
392086de | 25400 | +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen, |
1308ab2a | 25401 | + loff_t offset, u64 h_ino, unsigned int d_type) |
25402 | +{ | |
25403 | + int err, len; | |
392086de | 25404 | + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx); |
1308ab2a | 25405 | + struct aufs_rdu *rdu = arg->rdu; |
25406 | + struct au_rdu_ent ent; | |
25407 | + | |
25408 | + err = 0; | |
25409 | + arg->err = 0; | |
25410 | + au_fset_rdu(rdu->cookie.flags, CALLED); | |
25411 | + len = au_rdu_len(nlen); | |
25412 | + if (arg->ent.ul + len < arg->end) { | |
25413 | + ent.ino = h_ino; | |
25414 | + ent.bindex = rdu->cookie.bindex; | |
25415 | + ent.type = d_type; | |
25416 | + ent.nlen = nlen; | |
4a4d8108 AM |
25417 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) |
25418 | + ent.type = DT_UNKNOWN; | |
1308ab2a | 25419 | + |
9dbd164d | 25420 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 25421 | + err = -EFAULT; |
25422 | + if (copy_to_user(arg->ent.e, &ent, sizeof(ent))) | |
25423 | + goto out; | |
25424 | + if (copy_to_user(arg->ent.e->name, name, nlen)) | |
25425 | + goto out; | |
25426 | + /* the terminating NULL */ | |
25427 | + if (__put_user(0, arg->ent.e->name + nlen)) | |
25428 | + goto out; | |
25429 | + err = 0; | |
25430 | + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */ | |
25431 | + arg->ent.ul += len; | |
25432 | + rdu->rent++; | |
25433 | + } else { | |
25434 | + err = -EFAULT; | |
25435 | + au_fset_rdu(rdu->cookie.flags, FULL); | |
25436 | + rdu->full = 1; | |
25437 | + rdu->tail = arg->ent; | |
25438 | + } | |
25439 | + | |
4f0767ce | 25440 | +out: |
1308ab2a | 25441 | + /* AuTraceErr(err); */ |
25442 | + return err; | |
25443 | +} | |
25444 | + | |
25445 | +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg) | |
25446 | +{ | |
25447 | + int err; | |
25448 | + loff_t offset; | |
25449 | + struct au_rdu_cookie *cookie = &arg->rdu->cookie; | |
25450 | + | |
92d182d2 | 25451 | + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */ |
1308ab2a | 25452 | + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET); |
25453 | + err = offset; | |
25454 | + if (unlikely(offset != cookie->h_pos)) | |
25455 | + goto out; | |
25456 | + | |
25457 | + err = 0; | |
25458 | + do { | |
25459 | + arg->err = 0; | |
25460 | + au_fclr_rdu(cookie->flags, CALLED); | |
25461 | + /* smp_mb(); */ | |
392086de | 25462 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1308ab2a | 25463 | + if (err >= 0) |
25464 | + err = arg->err; | |
25465 | + } while (!err | |
25466 | + && au_ftest_rdu(cookie->flags, CALLED) | |
25467 | + && !au_ftest_rdu(cookie->flags, FULL)); | |
25468 | + cookie->h_pos = h_file->f_pos; | |
25469 | + | |
4f0767ce | 25470 | +out: |
1308ab2a | 25471 | + AuTraceErr(err); |
25472 | + return err; | |
25473 | +} | |
25474 | + | |
25475 | +static int au_rdu(struct file *file, struct aufs_rdu *rdu) | |
25476 | +{ | |
25477 | + int err; | |
25478 | + aufs_bindex_t bend; | |
392086de AM |
25479 | + struct au_rdu_arg arg = { |
25480 | + .ctx = { | |
25481 | + .actor = au_diractor(au_rdu_fill) | |
25482 | + } | |
25483 | + }; | |
1308ab2a | 25484 | + struct dentry *dentry; |
25485 | + struct inode *inode; | |
25486 | + struct file *h_file; | |
25487 | + struct au_rdu_cookie *cookie = &rdu->cookie; | |
25488 | + | |
25489 | + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz); | |
25490 | + if (unlikely(err)) { | |
25491 | + err = -EFAULT; | |
25492 | + AuTraceErr(err); | |
25493 | + goto out; | |
25494 | + } | |
25495 | + rdu->rent = 0; | |
25496 | + rdu->tail = rdu->ent; | |
25497 | + rdu->full = 0; | |
25498 | + arg.rdu = rdu; | |
25499 | + arg.ent = rdu->ent; | |
25500 | + arg.end = arg.ent.ul; | |
25501 | + arg.end += rdu->sz; | |
25502 | + | |
25503 | + err = -ENOTDIR; | |
523b37e3 | 25504 | + if (unlikely(!file->f_op->iterate)) |
1308ab2a | 25505 | + goto out; |
25506 | + | |
25507 | + err = security_file_permission(file, MAY_READ); | |
25508 | + AuTraceErr(err); | |
25509 | + if (unlikely(err)) | |
25510 | + goto out; | |
25511 | + | |
25512 | + dentry = file->f_dentry; | |
25513 | + inode = dentry->d_inode; | |
25514 | +#if 1 | |
25515 | + mutex_lock(&inode->i_mutex); | |
25516 | +#else | |
25517 | + err = mutex_lock_killable(&inode->i_mutex); | |
25518 | + AuTraceErr(err); | |
25519 | + if (unlikely(err)) | |
25520 | + goto out; | |
25521 | +#endif | |
1308ab2a | 25522 | + |
25523 | + arg.sb = inode->i_sb; | |
e49829fe JR |
25524 | + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM); |
25525 | + if (unlikely(err)) | |
25526 | + goto out_mtx; | |
027c5e7a AM |
25527 | + err = au_alive_dir(dentry); |
25528 | + if (unlikely(err)) | |
25529 | + goto out_si; | |
e49829fe | 25530 | + /* todo: reval? */ |
1308ab2a | 25531 | + fi_read_lock(file); |
25532 | + | |
25533 | + err = -EAGAIN; | |
25534 | + if (unlikely(au_ftest_rdu(cookie->flags, CONT) | |
25535 | + && cookie->generation != au_figen(file))) | |
25536 | + goto out_unlock; | |
25537 | + | |
25538 | + err = 0; | |
25539 | + if (!rdu->blk) { | |
25540 | + rdu->blk = au_sbi(arg.sb)->si_rdblk; | |
25541 | + if (!rdu->blk) | |
25542 | + rdu->blk = au_dir_size(file, /*dentry*/NULL); | |
25543 | + } | |
25544 | + bend = au_fbstart(file); | |
25545 | + if (cookie->bindex < bend) | |
25546 | + cookie->bindex = bend; | |
4a4d8108 | 25547 | + bend = au_fbend_dir(file); |
1308ab2a | 25548 | + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */ |
25549 | + for (; !err && cookie->bindex <= bend; | |
25550 | + cookie->bindex++, cookie->h_pos = 0) { | |
4a4d8108 | 25551 | + h_file = au_hf_dir(file, cookie->bindex); |
1308ab2a | 25552 | + if (!h_file) |
25553 | + continue; | |
25554 | + | |
25555 | + au_fclr_rdu(cookie->flags, FULL); | |
25556 | + err = au_rdu_do(h_file, &arg); | |
25557 | + AuTraceErr(err); | |
25558 | + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err)) | |
25559 | + break; | |
25560 | + } | |
25561 | + AuDbg("rent %llu\n", rdu->rent); | |
25562 | + | |
25563 | + if (!err && !au_ftest_rdu(cookie->flags, CONT)) { | |
25564 | + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH); | |
25565 | + au_fset_rdu(cookie->flags, CONT); | |
25566 | + cookie->generation = au_figen(file); | |
25567 | + } | |
25568 | + | |
25569 | + ii_read_lock_child(inode); | |
25570 | + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode))); | |
25571 | + ii_read_unlock(inode); | |
25572 | + | |
4f0767ce | 25573 | +out_unlock: |
1308ab2a | 25574 | + fi_read_unlock(file); |
027c5e7a | 25575 | +out_si: |
1308ab2a | 25576 | + si_read_unlock(arg.sb); |
4f0767ce | 25577 | +out_mtx: |
1308ab2a | 25578 | + mutex_unlock(&inode->i_mutex); |
4f0767ce | 25579 | +out: |
1308ab2a | 25580 | + AuTraceErr(err); |
25581 | + return err; | |
25582 | +} | |
25583 | + | |
25584 | +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu) | |
25585 | +{ | |
25586 | + int err; | |
25587 | + ino_t ino; | |
25588 | + unsigned long long nent; | |
25589 | + union au_rdu_ent_ul *u; | |
25590 | + struct au_rdu_ent ent; | |
25591 | + struct super_block *sb; | |
25592 | + | |
25593 | + err = 0; | |
25594 | + nent = rdu->nent; | |
25595 | + u = &rdu->ent; | |
25596 | + sb = file->f_dentry->d_sb; | |
25597 | + si_read_lock(sb, AuLock_FLUSH); | |
25598 | + while (nent-- > 0) { | |
9dbd164d | 25599 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 25600 | + err = copy_from_user(&ent, u->e, sizeof(ent)); |
4a4d8108 AM |
25601 | + if (!err) |
25602 | + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino)); | |
1308ab2a | 25603 | + if (unlikely(err)) { |
25604 | + err = -EFAULT; | |
25605 | + AuTraceErr(err); | |
25606 | + break; | |
25607 | + } | |
25608 | + | |
25609 | + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */ | |
25610 | + if (!ent.wh) | |
25611 | + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino); | |
25612 | + else | |
25613 | + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type, | |
25614 | + &ino); | |
25615 | + if (unlikely(err)) { | |
25616 | + AuTraceErr(err); | |
25617 | + break; | |
25618 | + } | |
25619 | + | |
25620 | + err = __put_user(ino, &u->e->ino); | |
25621 | + if (unlikely(err)) { | |
25622 | + err = -EFAULT; | |
25623 | + AuTraceErr(err); | |
25624 | + break; | |
25625 | + } | |
25626 | + u->ul += au_rdu_len(ent.nlen); | |
25627 | + } | |
25628 | + si_read_unlock(sb); | |
25629 | + | |
25630 | + return err; | |
25631 | +} | |
25632 | + | |
25633 | +/* ---------------------------------------------------------------------- */ | |
25634 | + | |
25635 | +static int au_rdu_verify(struct aufs_rdu *rdu) | |
25636 | +{ | |
b752ccd1 | 25637 | + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | " |
1308ab2a | 25638 | + "%llu, b%d, 0x%x, g%u}\n", |
b752ccd1 | 25639 | + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ], |
1308ab2a | 25640 | + rdu->blk, |
25641 | + rdu->rent, rdu->shwh, rdu->full, | |
25642 | + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags, | |
25643 | + rdu->cookie.generation); | |
dece6358 | 25644 | + |
b752ccd1 | 25645 | + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu)) |
1308ab2a | 25646 | + return 0; |
dece6358 | 25647 | + |
b752ccd1 AM |
25648 | + AuDbg("%u:%u\n", |
25649 | + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu)); | |
1308ab2a | 25650 | + return -EINVAL; |
25651 | +} | |
25652 | + | |
25653 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
dece6358 | 25654 | +{ |
1308ab2a | 25655 | + long err, e; |
25656 | + struct aufs_rdu rdu; | |
25657 | + void __user *p = (void __user *)arg; | |
dece6358 | 25658 | + |
1308ab2a | 25659 | + err = copy_from_user(&rdu, p, sizeof(rdu)); |
25660 | + if (unlikely(err)) { | |
25661 | + err = -EFAULT; | |
25662 | + AuTraceErr(err); | |
25663 | + goto out; | |
25664 | + } | |
25665 | + err = au_rdu_verify(&rdu); | |
dece6358 AM |
25666 | + if (unlikely(err)) |
25667 | + goto out; | |
25668 | + | |
1308ab2a | 25669 | + switch (cmd) { |
25670 | + case AUFS_CTL_RDU: | |
25671 | + err = au_rdu(file, &rdu); | |
25672 | + if (unlikely(err)) | |
25673 | + break; | |
dece6358 | 25674 | + |
1308ab2a | 25675 | + e = copy_to_user(p, &rdu, sizeof(rdu)); |
25676 | + if (unlikely(e)) { | |
25677 | + err = -EFAULT; | |
25678 | + AuTraceErr(err); | |
25679 | + } | |
25680 | + break; | |
25681 | + case AUFS_CTL_RDU_INO: | |
25682 | + err = au_rdu_ino(file, &rdu); | |
25683 | + break; | |
25684 | + | |
25685 | + default: | |
4a4d8108 | 25686 | + /* err = -ENOTTY; */ |
1308ab2a | 25687 | + err = -EINVAL; |
25688 | + } | |
dece6358 | 25689 | + |
4f0767ce | 25690 | +out: |
1308ab2a | 25691 | + AuTraceErr(err); |
25692 | + return err; | |
1facf9fc | 25693 | +} |
b752ccd1 AM |
25694 | + |
25695 | +#ifdef CONFIG_COMPAT | |
25696 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
25697 | +{ | |
25698 | + long err, e; | |
25699 | + struct aufs_rdu rdu; | |
25700 | + void __user *p = compat_ptr(arg); | |
25701 | + | |
25702 | + /* todo: get_user()? */ | |
25703 | + err = copy_from_user(&rdu, p, sizeof(rdu)); | |
25704 | + if (unlikely(err)) { | |
25705 | + err = -EFAULT; | |
25706 | + AuTraceErr(err); | |
25707 | + goto out; | |
25708 | + } | |
25709 | + rdu.ent.e = compat_ptr(rdu.ent.ul); | |
25710 | + err = au_rdu_verify(&rdu); | |
25711 | + if (unlikely(err)) | |
25712 | + goto out; | |
25713 | + | |
25714 | + switch (cmd) { | |
25715 | + case AUFS_CTL_RDU: | |
25716 | + err = au_rdu(file, &rdu); | |
25717 | + if (unlikely(err)) | |
25718 | + break; | |
25719 | + | |
25720 | + rdu.ent.ul = ptr_to_compat(rdu.ent.e); | |
25721 | + rdu.tail.ul = ptr_to_compat(rdu.tail.e); | |
25722 | + e = copy_to_user(p, &rdu, sizeof(rdu)); | |
25723 | + if (unlikely(e)) { | |
25724 | + err = -EFAULT; | |
25725 | + AuTraceErr(err); | |
25726 | + } | |
25727 | + break; | |
25728 | + case AUFS_CTL_RDU_INO: | |
25729 | + err = au_rdu_ino(file, &rdu); | |
25730 | + break; | |
25731 | + | |
25732 | + default: | |
25733 | + /* err = -ENOTTY; */ | |
25734 | + err = -EINVAL; | |
25735 | + } | |
25736 | + | |
4f0767ce | 25737 | +out: |
b752ccd1 AM |
25738 | + AuTraceErr(err); |
25739 | + return err; | |
25740 | +} | |
25741 | +#endif | |
7f207e10 AM |
25742 | diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h |
25743 | --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 25744 | +++ linux/fs/aufs/rwsem.h 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 25745 | @@ -0,0 +1,191 @@ |
1facf9fc | 25746 | +/* |
523b37e3 | 25747 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 25748 | + * |
25749 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25750 | + * it under the terms of the GNU General Public License as published by | |
25751 | + * the Free Software Foundation; either version 2 of the License, or | |
25752 | + * (at your option) any later version. | |
dece6358 AM |
25753 | + * |
25754 | + * This program is distributed in the hope that it will be useful, | |
25755 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25756 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25757 | + * GNU General Public License for more details. | |
25758 | + * | |
25759 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25760 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25761 | + */ |
25762 | + | |
25763 | +/* | |
25764 | + * simple read-write semaphore wrappers | |
25765 | + */ | |
25766 | + | |
25767 | +#ifndef __AUFS_RWSEM_H__ | |
25768 | +#define __AUFS_RWSEM_H__ | |
25769 | + | |
25770 | +#ifdef __KERNEL__ | |
25771 | + | |
4a4d8108 | 25772 | +#include "debug.h" |
dece6358 AM |
25773 | + |
25774 | +struct au_rwsem { | |
25775 | + struct rw_semaphore rwsem; | |
25776 | +#ifdef CONFIG_AUFS_DEBUG | |
25777 | + /* just for debugging, not almighty counter */ | |
25778 | + atomic_t rcnt, wcnt; | |
25779 | +#endif | |
25780 | +}; | |
25781 | + | |
25782 | +#ifdef CONFIG_AUFS_DEBUG | |
25783 | +#define AuDbgCntInit(rw) do { \ | |
25784 | + atomic_set(&(rw)->rcnt, 0); \ | |
25785 | + atomic_set(&(rw)->wcnt, 0); \ | |
25786 | + smp_mb(); /* atomic set */ \ | |
25787 | +} while (0) | |
25788 | + | |
e49829fe | 25789 | +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt) |
dece6358 | 25790 | +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0) |
e49829fe | 25791 | +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt) |
dece6358 AM |
25792 | +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0) |
25793 | +#else | |
25794 | +#define AuDbgCntInit(rw) do {} while (0) | |
25795 | +#define AuDbgRcntInc(rw) do {} while (0) | |
25796 | +#define AuDbgRcntDec(rw) do {} while (0) | |
25797 | +#define AuDbgWcntInc(rw) do {} while (0) | |
25798 | +#define AuDbgWcntDec(rw) do {} while (0) | |
25799 | +#endif /* CONFIG_AUFS_DEBUG */ | |
25800 | + | |
25801 | +/* to debug easier, do not make them inlined functions */ | |
25802 | +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list)) | |
25803 | +/* rwsem_is_locked() is unusable */ | |
25804 | +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0) | |
25805 | +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0) | |
25806 | +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \ | |
25807 | + && atomic_read(&(rw)->wcnt) <= 0) | |
25808 | +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \ | |
25809 | + || atomic_read(&(rw)->wcnt)) | |
25810 | + | |
e49829fe JR |
25811 | +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key) |
25812 | + | |
dece6358 AM |
25813 | +static inline void au_rw_init(struct au_rwsem *rw) |
25814 | +{ | |
25815 | + AuDbgCntInit(rw); | |
25816 | + init_rwsem(&rw->rwsem); | |
25817 | +} | |
25818 | + | |
25819 | +static inline void au_rw_init_wlock(struct au_rwsem *rw) | |
25820 | +{ | |
25821 | + au_rw_init(rw); | |
25822 | + down_write(&rw->rwsem); | |
25823 | + AuDbgWcntInc(rw); | |
25824 | +} | |
25825 | + | |
25826 | +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw, | |
25827 | + unsigned int lsc) | |
25828 | +{ | |
25829 | + au_rw_init(rw); | |
25830 | + down_write_nested(&rw->rwsem, lsc); | |
25831 | + AuDbgWcntInc(rw); | |
25832 | +} | |
25833 | + | |
25834 | +static inline void au_rw_read_lock(struct au_rwsem *rw) | |
25835 | +{ | |
25836 | + down_read(&rw->rwsem); | |
25837 | + AuDbgRcntInc(rw); | |
25838 | +} | |
25839 | + | |
25840 | +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc) | |
25841 | +{ | |
25842 | + down_read_nested(&rw->rwsem, lsc); | |
25843 | + AuDbgRcntInc(rw); | |
25844 | +} | |
25845 | + | |
25846 | +static inline void au_rw_read_unlock(struct au_rwsem *rw) | |
25847 | +{ | |
25848 | + AuRwMustReadLock(rw); | |
25849 | + AuDbgRcntDec(rw); | |
25850 | + up_read(&rw->rwsem); | |
25851 | +} | |
25852 | + | |
25853 | +static inline void au_rw_dgrade_lock(struct au_rwsem *rw) | |
25854 | +{ | |
25855 | + AuRwMustWriteLock(rw); | |
25856 | + AuDbgRcntInc(rw); | |
25857 | + AuDbgWcntDec(rw); | |
25858 | + downgrade_write(&rw->rwsem); | |
25859 | +} | |
25860 | + | |
25861 | +static inline void au_rw_write_lock(struct au_rwsem *rw) | |
25862 | +{ | |
25863 | + down_write(&rw->rwsem); | |
25864 | + AuDbgWcntInc(rw); | |
25865 | +} | |
25866 | + | |
25867 | +static inline void au_rw_write_lock_nested(struct au_rwsem *rw, | |
25868 | + unsigned int lsc) | |
25869 | +{ | |
25870 | + down_write_nested(&rw->rwsem, lsc); | |
25871 | + AuDbgWcntInc(rw); | |
25872 | +} | |
1facf9fc | 25873 | + |
dece6358 AM |
25874 | +static inline void au_rw_write_unlock(struct au_rwsem *rw) |
25875 | +{ | |
25876 | + AuRwMustWriteLock(rw); | |
25877 | + AuDbgWcntDec(rw); | |
25878 | + up_write(&rw->rwsem); | |
25879 | +} | |
25880 | + | |
25881 | +/* why is not _nested version defined */ | |
25882 | +static inline int au_rw_read_trylock(struct au_rwsem *rw) | |
25883 | +{ | |
076b876e AM |
25884 | + int ret; |
25885 | + | |
25886 | + ret = down_read_trylock(&rw->rwsem); | |
dece6358 AM |
25887 | + if (ret) |
25888 | + AuDbgRcntInc(rw); | |
25889 | + return ret; | |
25890 | +} | |
25891 | + | |
25892 | +static inline int au_rw_write_trylock(struct au_rwsem *rw) | |
25893 | +{ | |
076b876e AM |
25894 | + int ret; |
25895 | + | |
25896 | + ret = down_write_trylock(&rw->rwsem); | |
dece6358 AM |
25897 | + if (ret) |
25898 | + AuDbgWcntInc(rw); | |
25899 | + return ret; | |
25900 | +} | |
25901 | + | |
25902 | +#undef AuDbgCntInit | |
25903 | +#undef AuDbgRcntInc | |
25904 | +#undef AuDbgRcntDec | |
25905 | +#undef AuDbgWcntInc | |
25906 | +#undef AuDbgWcntDec | |
1facf9fc | 25907 | + |
25908 | +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
25909 | +static inline void prefix##_read_lock(param) \ | |
dece6358 | 25910 | +{ au_rw_read_lock(rwsem); } \ |
1facf9fc | 25911 | +static inline void prefix##_write_lock(param) \ |
dece6358 | 25912 | +{ au_rw_write_lock(rwsem); } \ |
1facf9fc | 25913 | +static inline int prefix##_read_trylock(param) \ |
dece6358 | 25914 | +{ return au_rw_read_trylock(rwsem); } \ |
1facf9fc | 25915 | +static inline int prefix##_write_trylock(param) \ |
dece6358 | 25916 | +{ return au_rw_write_trylock(rwsem); } |
1facf9fc | 25917 | +/* why is not _nested version defined */ |
25918 | +/* static inline void prefix##_read_trylock_nested(param, lsc) | |
dece6358 | 25919 | +{ au_rw_read_trylock_nested(rwsem, lsc)); } |
1facf9fc | 25920 | +static inline void prefix##_write_trylock_nestd(param, lsc) |
dece6358 | 25921 | +{ au_rw_write_trylock_nested(rwsem, lsc); } */ |
1facf9fc | 25922 | + |
25923 | +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \ | |
25924 | +static inline void prefix##_read_unlock(param) \ | |
dece6358 | 25925 | +{ au_rw_read_unlock(rwsem); } \ |
1facf9fc | 25926 | +static inline void prefix##_write_unlock(param) \ |
dece6358 | 25927 | +{ au_rw_write_unlock(rwsem); } \ |
1facf9fc | 25928 | +static inline void prefix##_downgrade_lock(param) \ |
dece6358 | 25929 | +{ au_rw_dgrade_lock(rwsem); } |
1facf9fc | 25930 | + |
25931 | +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \ | |
25932 | + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \ | |
25933 | + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) | |
25934 | + | |
25935 | +#endif /* __KERNEL__ */ | |
25936 | +#endif /* __AUFS_RWSEM_H__ */ | |
7f207e10 AM |
25937 | diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c |
25938 | --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 25939 | +++ linux/fs/aufs/sbinfo.c 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 25940 | @@ -0,0 +1,353 @@ |
1facf9fc | 25941 | +/* |
523b37e3 | 25942 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 25943 | + * |
25944 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25945 | + * it under the terms of the GNU General Public License as published by | |
25946 | + * the Free Software Foundation; either version 2 of the License, or | |
25947 | + * (at your option) any later version. | |
dece6358 AM |
25948 | + * |
25949 | + * This program is distributed in the hope that it will be useful, | |
25950 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25951 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25952 | + * GNU General Public License for more details. | |
25953 | + * | |
25954 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25955 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25956 | + */ |
25957 | + | |
25958 | +/* | |
25959 | + * superblock private data | |
25960 | + */ | |
25961 | + | |
25962 | +#include "aufs.h" | |
25963 | + | |
25964 | +/* | |
25965 | + * they are necessary regardless sysfs is disabled. | |
25966 | + */ | |
25967 | +void au_si_free(struct kobject *kobj) | |
25968 | +{ | |
86dc4139 | 25969 | + int i; |
1facf9fc | 25970 | + struct au_sbinfo *sbinfo; |
b752ccd1 | 25971 | + char *locked __maybe_unused; /* debug only */ |
1facf9fc | 25972 | + |
25973 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
86dc4139 AM |
25974 | + for (i = 0; i < AuPlink_NHASH; i++) |
25975 | + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head)); | |
e49829fe | 25976 | + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len)); |
1facf9fc | 25977 | + |
e49829fe | 25978 | + au_rw_write_lock(&sbinfo->si_rwsem); |
1facf9fc | 25979 | + au_br_free(sbinfo); |
e49829fe | 25980 | + au_rw_write_unlock(&sbinfo->si_rwsem); |
b752ccd1 AM |
25981 | + |
25982 | + AuDebugOn(radix_tree_gang_lookup | |
25983 | + (&sbinfo->au_si_pid.tree, (void **)&locked, | |
25984 | + /*first_index*/PID_MAX_DEFAULT - 1, | |
25985 | + /*max_items*/sizeof(locked)/sizeof(*locked))); | |
25986 | + | |
1facf9fc | 25987 | + kfree(sbinfo->si_branch); |
b752ccd1 | 25988 | + kfree(sbinfo->au_si_pid.bitmap); |
1facf9fc | 25989 | + mutex_destroy(&sbinfo->si_xib_mtx); |
dece6358 | 25990 | + AuRwDestroy(&sbinfo->si_rwsem); |
1facf9fc | 25991 | + |
25992 | + kfree(sbinfo); | |
25993 | +} | |
25994 | + | |
25995 | +int au_si_alloc(struct super_block *sb) | |
25996 | +{ | |
86dc4139 | 25997 | + int err, i; |
1facf9fc | 25998 | + struct au_sbinfo *sbinfo; |
e49829fe | 25999 | + static struct lock_class_key aufs_si; |
1facf9fc | 26000 | + |
26001 | + err = -ENOMEM; | |
4a4d8108 | 26002 | + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS); |
1facf9fc | 26003 | + if (unlikely(!sbinfo)) |
26004 | + goto out; | |
26005 | + | |
b752ccd1 AM |
26006 | + BUILD_BUG_ON(sizeof(unsigned long) != |
26007 | + sizeof(*sbinfo->au_si_pid.bitmap)); | |
26008 | + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT), | |
26009 | + sizeof(*sbinfo->au_si_pid.bitmap), | |
26010 | + GFP_NOFS); | |
26011 | + if (unlikely(!sbinfo->au_si_pid.bitmap)) | |
26012 | + goto out_sbinfo; | |
26013 | + | |
1facf9fc | 26014 | + /* will be reallocated separately */ |
26015 | + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS); | |
26016 | + if (unlikely(!sbinfo->si_branch)) | |
b752ccd1 | 26017 | + goto out_pidmap; |
1facf9fc | 26018 | + |
1facf9fc | 26019 | + err = sysaufs_si_init(sbinfo); |
26020 | + if (unlikely(err)) | |
26021 | + goto out_br; | |
26022 | + | |
26023 | + au_nwt_init(&sbinfo->si_nowait); | |
dece6358 | 26024 | + au_rw_init_wlock(&sbinfo->si_rwsem); |
e49829fe | 26025 | + au_rw_class(&sbinfo->si_rwsem, &aufs_si); |
b752ccd1 AM |
26026 | + spin_lock_init(&sbinfo->au_si_pid.tree_lock); |
26027 | + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL); | |
26028 | + | |
7f207e10 | 26029 | + atomic_long_set(&sbinfo->si_ninodes, 0); |
7f207e10 AM |
26030 | + atomic_long_set(&sbinfo->si_nfiles, 0); |
26031 | + | |
1facf9fc | 26032 | + sbinfo->si_bend = -1; |
392086de | 26033 | + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2; |
1facf9fc | 26034 | + |
26035 | + sbinfo->si_wbr_copyup = AuWbrCopyup_Def; | |
26036 | + sbinfo->si_wbr_create = AuWbrCreate_Def; | |
4a4d8108 AM |
26037 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup; |
26038 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create; | |
1facf9fc | 26039 | + |
076b876e AM |
26040 | + au_fhsm_init(sbinfo); |
26041 | + | |
e49829fe | 26042 | + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def); |
1facf9fc | 26043 | + |
392086de AM |
26044 | + sbinfo->si_xino_jiffy = jiffies; |
26045 | + sbinfo->si_xino_expire | |
26046 | + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC); | |
1facf9fc | 26047 | + mutex_init(&sbinfo->si_xib_mtx); |
1facf9fc | 26048 | + sbinfo->si_xino_brid = -1; |
26049 | + /* leave si_xib_last_pindex and si_xib_next_bit */ | |
26050 | + | |
e49829fe | 26051 | + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC); |
1facf9fc | 26052 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; |
26053 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
26054 | + sbinfo->si_dirwh = AUFS_DIRWH_DEF; | |
26055 | + | |
86dc4139 AM |
26056 | + for (i = 0; i < AuPlink_NHASH; i++) |
26057 | + au_sphl_init(sbinfo->si_plink + i); | |
1facf9fc | 26058 | + init_waitqueue_head(&sbinfo->si_plink_wq); |
4a4d8108 | 26059 | + spin_lock_init(&sbinfo->si_plink_maint_lock); |
1facf9fc | 26060 | + |
523b37e3 AM |
26061 | + au_sphl_init(&sbinfo->si_files); |
26062 | + | |
1facf9fc | 26063 | + /* leave other members for sysaufs and si_mnt. */ |
26064 | + sbinfo->si_sb = sb; | |
26065 | + sb->s_fs_info = sbinfo; | |
b752ccd1 | 26066 | + si_pid_set(sb); |
1facf9fc | 26067 | + au_debug_sbinfo_init(sbinfo); |
26068 | + return 0; /* success */ | |
26069 | + | |
4f0767ce | 26070 | +out_br: |
1facf9fc | 26071 | + kfree(sbinfo->si_branch); |
4f0767ce | 26072 | +out_pidmap: |
b752ccd1 | 26073 | + kfree(sbinfo->au_si_pid.bitmap); |
4f0767ce | 26074 | +out_sbinfo: |
1facf9fc | 26075 | + kfree(sbinfo); |
4f0767ce | 26076 | +out: |
1facf9fc | 26077 | + return err; |
26078 | +} | |
26079 | + | |
26080 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr) | |
26081 | +{ | |
26082 | + int err, sz; | |
26083 | + struct au_branch **brp; | |
26084 | + | |
dece6358 AM |
26085 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
26086 | + | |
1facf9fc | 26087 | + err = -ENOMEM; |
26088 | + sz = sizeof(*brp) * (sbinfo->si_bend + 1); | |
26089 | + if (unlikely(!sz)) | |
26090 | + sz = sizeof(*brp); | |
26091 | + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS); | |
26092 | + if (brp) { | |
26093 | + sbinfo->si_branch = brp; | |
26094 | + err = 0; | |
26095 | + } | |
26096 | + | |
26097 | + return err; | |
26098 | +} | |
26099 | + | |
26100 | +/* ---------------------------------------------------------------------- */ | |
26101 | + | |
26102 | +unsigned int au_sigen_inc(struct super_block *sb) | |
26103 | +{ | |
26104 | + unsigned int gen; | |
26105 | + | |
dece6358 AM |
26106 | + SiMustWriteLock(sb); |
26107 | + | |
1facf9fc | 26108 | + gen = ++au_sbi(sb)->si_generation; |
26109 | + au_update_digen(sb->s_root); | |
537831f9 | 26110 | + au_update_iigen(sb->s_root->d_inode, /*half*/0); |
1facf9fc | 26111 | + sb->s_root->d_inode->i_version++; |
26112 | + return gen; | |
26113 | +} | |
26114 | + | |
26115 | +aufs_bindex_t au_new_br_id(struct super_block *sb) | |
26116 | +{ | |
26117 | + aufs_bindex_t br_id; | |
26118 | + int i; | |
26119 | + struct au_sbinfo *sbinfo; | |
26120 | + | |
dece6358 AM |
26121 | + SiMustWriteLock(sb); |
26122 | + | |
1facf9fc | 26123 | + sbinfo = au_sbi(sb); |
26124 | + for (i = 0; i <= AUFS_BRANCH_MAX; i++) { | |
26125 | + br_id = ++sbinfo->si_last_br_id; | |
7f207e10 | 26126 | + AuDebugOn(br_id < 0); |
1facf9fc | 26127 | + if (br_id && au_br_index(sb, br_id) < 0) |
26128 | + return br_id; | |
26129 | + } | |
26130 | + | |
26131 | + return -1; | |
26132 | +} | |
26133 | + | |
26134 | +/* ---------------------------------------------------------------------- */ | |
26135 | + | |
e49829fe JR |
26136 | +/* it is ok that new 'nwt' tasks are appended while we are sleeping */ |
26137 | +int si_read_lock(struct super_block *sb, int flags) | |
26138 | +{ | |
26139 | + int err; | |
26140 | + | |
26141 | + err = 0; | |
26142 | + if (au_ftest_lock(flags, FLUSH)) | |
26143 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
26144 | + | |
26145 | + si_noflush_read_lock(sb); | |
26146 | + err = au_plink_maint(sb, flags); | |
26147 | + if (unlikely(err)) | |
26148 | + si_read_unlock(sb); | |
26149 | + | |
26150 | + return err; | |
26151 | +} | |
26152 | + | |
26153 | +int si_write_lock(struct super_block *sb, int flags) | |
26154 | +{ | |
26155 | + int err; | |
26156 | + | |
26157 | + if (au_ftest_lock(flags, FLUSH)) | |
26158 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
26159 | + | |
26160 | + si_noflush_write_lock(sb); | |
26161 | + err = au_plink_maint(sb, flags); | |
26162 | + if (unlikely(err)) | |
26163 | + si_write_unlock(sb); | |
26164 | + | |
26165 | + return err; | |
26166 | +} | |
26167 | + | |
1facf9fc | 26168 | +/* dentry and super_block lock. call at entry point */ |
e49829fe | 26169 | +int aufs_read_lock(struct dentry *dentry, int flags) |
1facf9fc | 26170 | +{ |
e49829fe | 26171 | + int err; |
027c5e7a | 26172 | + struct super_block *sb; |
e49829fe | 26173 | + |
027c5e7a AM |
26174 | + sb = dentry->d_sb; |
26175 | + err = si_read_lock(sb, flags); | |
26176 | + if (unlikely(err)) | |
26177 | + goto out; | |
26178 | + | |
26179 | + if (au_ftest_lock(flags, DW)) | |
26180 | + di_write_lock_child(dentry); | |
26181 | + else | |
26182 | + di_read_lock_child(dentry, flags); | |
26183 | + | |
26184 | + if (au_ftest_lock(flags, GEN)) { | |
26185 | + err = au_digen_test(dentry, au_sigen(sb)); | |
26186 | + AuDebugOn(!err && au_dbrange_test(dentry)); | |
26187 | + if (unlikely(err)) | |
26188 | + aufs_read_unlock(dentry, flags); | |
e49829fe JR |
26189 | + } |
26190 | + | |
027c5e7a | 26191 | +out: |
e49829fe | 26192 | + return err; |
1facf9fc | 26193 | +} |
26194 | + | |
26195 | +void aufs_read_unlock(struct dentry *dentry, int flags) | |
26196 | +{ | |
26197 | + if (au_ftest_lock(flags, DW)) | |
26198 | + di_write_unlock(dentry); | |
26199 | + else | |
26200 | + di_read_unlock(dentry, flags); | |
26201 | + si_read_unlock(dentry->d_sb); | |
26202 | +} | |
26203 | + | |
26204 | +void aufs_write_lock(struct dentry *dentry) | |
26205 | +{ | |
e49829fe | 26206 | + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW); |
1facf9fc | 26207 | + di_write_lock_child(dentry); |
26208 | +} | |
26209 | + | |
26210 | +void aufs_write_unlock(struct dentry *dentry) | |
26211 | +{ | |
26212 | + di_write_unlock(dentry); | |
26213 | + si_write_unlock(dentry->d_sb); | |
26214 | +} | |
26215 | + | |
e49829fe | 26216 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags) |
1facf9fc | 26217 | +{ |
e49829fe | 26218 | + int err; |
027c5e7a AM |
26219 | + unsigned int sigen; |
26220 | + struct super_block *sb; | |
e49829fe | 26221 | + |
027c5e7a AM |
26222 | + sb = d1->d_sb; |
26223 | + err = si_read_lock(sb, flags); | |
26224 | + if (unlikely(err)) | |
26225 | + goto out; | |
26226 | + | |
26227 | + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR)); | |
26228 | + | |
26229 | + if (au_ftest_lock(flags, GEN)) { | |
26230 | + sigen = au_sigen(sb); | |
26231 | + err = au_digen_test(d1, sigen); | |
26232 | + AuDebugOn(!err && au_dbrange_test(d1)); | |
26233 | + if (!err) { | |
26234 | + err = au_digen_test(d2, sigen); | |
26235 | + AuDebugOn(!err && au_dbrange_test(d2)); | |
26236 | + } | |
26237 | + if (unlikely(err)) | |
26238 | + aufs_read_and_write_unlock2(d1, d2); | |
26239 | + } | |
26240 | + | |
26241 | +out: | |
e49829fe | 26242 | + return err; |
1facf9fc | 26243 | +} |
26244 | + | |
26245 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2) | |
26246 | +{ | |
26247 | + di_write_unlock2(d1, d2); | |
26248 | + si_read_unlock(d1->d_sb); | |
26249 | +} | |
b752ccd1 AM |
26250 | + |
26251 | +/* ---------------------------------------------------------------------- */ | |
26252 | + | |
26253 | +int si_pid_test_slow(struct super_block *sb) | |
26254 | +{ | |
26255 | + void *p; | |
26256 | + | |
26257 | + rcu_read_lock(); | |
26258 | + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid); | |
26259 | + rcu_read_unlock(); | |
26260 | + | |
027c5e7a | 26261 | + return (long)!!p; |
b752ccd1 AM |
26262 | +} |
26263 | + | |
26264 | +void si_pid_set_slow(struct super_block *sb) | |
26265 | +{ | |
26266 | + int err; | |
26267 | + struct au_sbinfo *sbinfo; | |
26268 | + | |
26269 | + AuDebugOn(si_pid_test_slow(sb)); | |
26270 | + | |
26271 | + sbinfo = au_sbi(sb); | |
26272 | + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL); | |
26273 | + AuDebugOn(err); | |
26274 | + spin_lock(&sbinfo->au_si_pid.tree_lock); | |
26275 | + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid, | |
027c5e7a | 26276 | + /*any valid ptr*/sb); |
b752ccd1 AM |
26277 | + spin_unlock(&sbinfo->au_si_pid.tree_lock); |
26278 | + AuDebugOn(err); | |
26279 | + radix_tree_preload_end(); | |
26280 | +} | |
26281 | + | |
26282 | +void si_pid_clr_slow(struct super_block *sb) | |
26283 | +{ | |
26284 | + void *p; | |
26285 | + struct au_sbinfo *sbinfo; | |
26286 | + | |
26287 | + AuDebugOn(!si_pid_test_slow(sb)); | |
26288 | + | |
26289 | + sbinfo = au_sbi(sb); | |
26290 | + spin_lock(&sbinfo->au_si_pid.tree_lock); | |
26291 | + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid); | |
26292 | + spin_unlock(&sbinfo->au_si_pid.tree_lock); | |
b752ccd1 | 26293 | +} |
7f207e10 AM |
26294 | diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h |
26295 | --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 26296 | +++ linux/fs/aufs/spl.h 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 26297 | @@ -0,0 +1,111 @@ |
1facf9fc | 26298 | +/* |
523b37e3 | 26299 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 26300 | + * |
26301 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26302 | + * it under the terms of the GNU General Public License as published by | |
26303 | + * the Free Software Foundation; either version 2 of the License, or | |
26304 | + * (at your option) any later version. | |
dece6358 AM |
26305 | + * |
26306 | + * This program is distributed in the hope that it will be useful, | |
26307 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26308 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26309 | + * GNU General Public License for more details. | |
26310 | + * | |
26311 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26312 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26313 | + */ |
26314 | + | |
26315 | +/* | |
26316 | + * simple list protected by a spinlock | |
26317 | + */ | |
26318 | + | |
26319 | +#ifndef __AUFS_SPL_H__ | |
26320 | +#define __AUFS_SPL_H__ | |
26321 | + | |
26322 | +#ifdef __KERNEL__ | |
26323 | + | |
1facf9fc | 26324 | +struct au_splhead { |
26325 | + spinlock_t spin; | |
26326 | + struct list_head head; | |
26327 | +}; | |
26328 | + | |
26329 | +static inline void au_spl_init(struct au_splhead *spl) | |
26330 | +{ | |
26331 | + spin_lock_init(&spl->spin); | |
26332 | + INIT_LIST_HEAD(&spl->head); | |
26333 | +} | |
26334 | + | |
26335 | +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl) | |
26336 | +{ | |
26337 | + spin_lock(&spl->spin); | |
26338 | + list_add(list, &spl->head); | |
26339 | + spin_unlock(&spl->spin); | |
26340 | +} | |
26341 | + | |
26342 | +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl) | |
26343 | +{ | |
26344 | + spin_lock(&spl->spin); | |
26345 | + list_del(list); | |
26346 | + spin_unlock(&spl->spin); | |
26347 | +} | |
26348 | + | |
4a4d8108 AM |
26349 | +static inline void au_spl_del_rcu(struct list_head *list, |
26350 | + struct au_splhead *spl) | |
26351 | +{ | |
26352 | + spin_lock(&spl->spin); | |
26353 | + list_del_rcu(list); | |
26354 | + spin_unlock(&spl->spin); | |
26355 | +} | |
26356 | + | |
86dc4139 AM |
26357 | +/* ---------------------------------------------------------------------- */ |
26358 | + | |
26359 | +struct au_sphlhead { | |
26360 | + spinlock_t spin; | |
26361 | + struct hlist_head head; | |
26362 | +}; | |
26363 | + | |
26364 | +static inline void au_sphl_init(struct au_sphlhead *sphl) | |
26365 | +{ | |
26366 | + spin_lock_init(&sphl->spin); | |
26367 | + INIT_HLIST_HEAD(&sphl->head); | |
26368 | +} | |
26369 | + | |
26370 | +static inline void au_sphl_add(struct hlist_node *hlist, | |
26371 | + struct au_sphlhead *sphl) | |
26372 | +{ | |
26373 | + spin_lock(&sphl->spin); | |
26374 | + hlist_add_head(hlist, &sphl->head); | |
26375 | + spin_unlock(&sphl->spin); | |
26376 | +} | |
26377 | + | |
26378 | +static inline void au_sphl_del(struct hlist_node *hlist, | |
26379 | + struct au_sphlhead *sphl) | |
26380 | +{ | |
26381 | + spin_lock(&sphl->spin); | |
26382 | + hlist_del(hlist); | |
26383 | + spin_unlock(&sphl->spin); | |
26384 | +} | |
26385 | + | |
26386 | +static inline void au_sphl_del_rcu(struct hlist_node *hlist, | |
26387 | + struct au_sphlhead *sphl) | |
26388 | +{ | |
26389 | + spin_lock(&sphl->spin); | |
26390 | + hlist_del_rcu(hlist); | |
26391 | + spin_unlock(&sphl->spin); | |
26392 | +} | |
26393 | + | |
26394 | +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl) | |
26395 | +{ | |
26396 | + unsigned long cnt; | |
26397 | + struct hlist_node *pos; | |
26398 | + | |
26399 | + cnt = 0; | |
26400 | + spin_lock(&sphl->spin); | |
26401 | + hlist_for_each(pos, &sphl->head) | |
26402 | + cnt++; | |
26403 | + spin_unlock(&sphl->spin); | |
26404 | + return cnt; | |
26405 | +} | |
26406 | + | |
1facf9fc | 26407 | +#endif /* __KERNEL__ */ |
26408 | +#endif /* __AUFS_SPL_H__ */ | |
7f207e10 AM |
26409 | diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c |
26410 | --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
26411 | +++ linux/fs/aufs/super.c 2015-01-25 13:00:38.634380408 +0100 |
26412 | @@ -0,0 +1,1009 @@ | |
1facf9fc | 26413 | +/* |
523b37e3 | 26414 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 26415 | + * |
26416 | + * This program, aufs is free software; you can redistribute it and/or modify | |
26417 | + * it under the terms of the GNU General Public License as published by | |
26418 | + * the Free Software Foundation; either version 2 of the License, or | |
26419 | + * (at your option) any later version. | |
dece6358 AM |
26420 | + * |
26421 | + * This program is distributed in the hope that it will be useful, | |
26422 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26423 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26424 | + * GNU General Public License for more details. | |
26425 | + * | |
26426 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 26427 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 26428 | + */ |
26429 | + | |
26430 | +/* | |
26431 | + * mount and super_block operations | |
26432 | + */ | |
26433 | + | |
f6c5ef8b | 26434 | +#include <linux/mm.h> |
dece6358 | 26435 | +#include <linux/module.h> |
1facf9fc | 26436 | +#include <linux/seq_file.h> |
26437 | +#include <linux/statfs.h> | |
7f207e10 AM |
26438 | +#include <linux/vmalloc.h> |
26439 | +#include <linux/writeback.h> | |
1facf9fc | 26440 | +#include "aufs.h" |
26441 | + | |
26442 | +/* | |
26443 | + * super_operations | |
26444 | + */ | |
26445 | +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused) | |
26446 | +{ | |
26447 | + struct au_icntnr *c; | |
26448 | + | |
26449 | + c = au_cache_alloc_icntnr(); | |
26450 | + if (c) { | |
027c5e7a | 26451 | + au_icntnr_init(c); |
1facf9fc | 26452 | + c->vfs_inode.i_version = 1; /* sigen(sb); */ |
26453 | + c->iinfo.ii_hinode = NULL; | |
26454 | + return &c->vfs_inode; | |
26455 | + } | |
26456 | + return NULL; | |
26457 | +} | |
26458 | + | |
027c5e7a AM |
26459 | +static void aufs_destroy_inode_cb(struct rcu_head *head) |
26460 | +{ | |
26461 | + struct inode *inode = container_of(head, struct inode, i_rcu); | |
26462 | + | |
b4510431 | 26463 | + INIT_HLIST_HEAD(&inode->i_dentry); |
027c5e7a AM |
26464 | + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode)); |
26465 | +} | |
26466 | + | |
1facf9fc | 26467 | +static void aufs_destroy_inode(struct inode *inode) |
26468 | +{ | |
26469 | + au_iinfo_fin(inode); | |
027c5e7a | 26470 | + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb); |
1facf9fc | 26471 | +} |
26472 | + | |
26473 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino) | |
26474 | +{ | |
26475 | + struct inode *inode; | |
26476 | + int err; | |
26477 | + | |
26478 | + inode = iget_locked(sb, ino); | |
26479 | + if (unlikely(!inode)) { | |
26480 | + inode = ERR_PTR(-ENOMEM); | |
26481 | + goto out; | |
26482 | + } | |
26483 | + if (!(inode->i_state & I_NEW)) | |
26484 | + goto out; | |
26485 | + | |
26486 | + err = au_xigen_new(inode); | |
26487 | + if (!err) | |
26488 | + err = au_iinfo_init(inode); | |
26489 | + if (!err) | |
26490 | + inode->i_version++; | |
26491 | + else { | |
26492 | + iget_failed(inode); | |
26493 | + inode = ERR_PTR(err); | |
26494 | + } | |
26495 | + | |
4f0767ce | 26496 | +out: |
1facf9fc | 26497 | + /* never return NULL */ |
26498 | + AuDebugOn(!inode); | |
26499 | + AuTraceErrPtr(inode); | |
26500 | + return inode; | |
26501 | +} | |
26502 | + | |
26503 | +/* lock free root dinfo */ | |
26504 | +static int au_show_brs(struct seq_file *seq, struct super_block *sb) | |
26505 | +{ | |
26506 | + int err; | |
26507 | + aufs_bindex_t bindex, bend; | |
26508 | + struct path path; | |
4a4d8108 | 26509 | + struct au_hdentry *hdp; |
1facf9fc | 26510 | + struct au_branch *br; |
076b876e | 26511 | + au_br_perm_str_t perm; |
1facf9fc | 26512 | + |
26513 | + err = 0; | |
26514 | + bend = au_sbend(sb); | |
4a4d8108 | 26515 | + hdp = au_di(sb->s_root)->di_hdentry; |
1facf9fc | 26516 | + for (bindex = 0; !err && bindex <= bend; bindex++) { |
26517 | + br = au_sbr(sb, bindex); | |
86dc4139 | 26518 | + path.mnt = au_br_mnt(br); |
4a4d8108 | 26519 | + path.dentry = hdp[bindex].hd_dentry; |
1facf9fc | 26520 | + err = au_seq_path(seq, &path); |
1e00d052 | 26521 | + if (err > 0) { |
076b876e AM |
26522 | + au_optstr_br_perm(&perm, br->br_perm); |
26523 | + err = seq_printf(seq, "=%s", perm.a); | |
26524 | + if (err == -1) | |
26525 | + err = -E2BIG; | |
1e00d052 | 26526 | + } |
1facf9fc | 26527 | + if (!err && bindex != bend) |
26528 | + err = seq_putc(seq, ':'); | |
26529 | + } | |
26530 | + | |
26531 | + return err; | |
26532 | +} | |
26533 | + | |
26534 | +static void au_show_wbr_create(struct seq_file *m, int v, | |
26535 | + struct au_sbinfo *sbinfo) | |
26536 | +{ | |
26537 | + const char *pat; | |
26538 | + | |
dece6358 AM |
26539 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
26540 | + | |
c2b27bf2 | 26541 | + seq_puts(m, ",create="); |
1facf9fc | 26542 | + pat = au_optstr_wbr_create(v); |
26543 | + switch (v) { | |
26544 | + case AuWbrCreate_TDP: | |
26545 | + case AuWbrCreate_RR: | |
26546 | + case AuWbrCreate_MFS: | |
26547 | + case AuWbrCreate_PMFS: | |
c2b27bf2 | 26548 | + seq_puts(m, pat); |
1facf9fc | 26549 | + break; |
26550 | + case AuWbrCreate_MFSV: | |
26551 | + seq_printf(m, /*pat*/"mfs:%lu", | |
e49829fe JR |
26552 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26553 | + / MSEC_PER_SEC); | |
1facf9fc | 26554 | + break; |
26555 | + case AuWbrCreate_PMFSV: | |
26556 | + seq_printf(m, /*pat*/"pmfs:%lu", | |
e49829fe JR |
26557 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26558 | + / MSEC_PER_SEC); | |
1facf9fc | 26559 | + break; |
26560 | + case AuWbrCreate_MFSRR: | |
26561 | + seq_printf(m, /*pat*/"mfsrr:%llu", | |
26562 | + sbinfo->si_wbr_mfs.mfsrr_watermark); | |
26563 | + break; | |
26564 | + case AuWbrCreate_MFSRRV: | |
26565 | + seq_printf(m, /*pat*/"mfsrr:%llu:%lu", | |
26566 | + sbinfo->si_wbr_mfs.mfsrr_watermark, | |
e49829fe JR |
26567 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) |
26568 | + / MSEC_PER_SEC); | |
1facf9fc | 26569 | + break; |
392086de AM |
26570 | + case AuWbrCreate_PMFSRR: |
26571 | + seq_printf(m, /*pat*/"pmfsrr:%llu", | |
26572 | + sbinfo->si_wbr_mfs.mfsrr_watermark); | |
26573 | + break; | |
26574 | + case AuWbrCreate_PMFSRRV: | |
26575 | + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu", | |
26576 | + sbinfo->si_wbr_mfs.mfsrr_watermark, | |
26577 | + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire) | |
26578 | + / MSEC_PER_SEC); | |
26579 | + break; | |
1facf9fc | 26580 | + } |
26581 | +} | |
26582 | + | |
7eafdf33 | 26583 | +static int au_show_xino(struct seq_file *seq, struct super_block *sb) |
1facf9fc | 26584 | +{ |
26585 | +#ifdef CONFIG_SYSFS | |
26586 | + return 0; | |
26587 | +#else | |
26588 | + int err; | |
26589 | + const int len = sizeof(AUFS_XINO_FNAME) - 1; | |
26590 | + aufs_bindex_t bindex, brid; | |
1facf9fc | 26591 | + struct qstr *name; |
26592 | + struct file *f; | |
26593 | + struct dentry *d, *h_root; | |
4a4d8108 | 26594 | + struct au_hdentry *hdp; |
1facf9fc | 26595 | + |
dece6358 AM |
26596 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
26597 | + | |
1facf9fc | 26598 | + err = 0; |
1facf9fc | 26599 | + f = au_sbi(sb)->si_xib; |
26600 | + if (!f) | |
26601 | + goto out; | |
26602 | + | |
26603 | + /* stop printing the default xino path on the first writable branch */ | |
26604 | + h_root = NULL; | |
26605 | + brid = au_xino_brid(sb); | |
26606 | + if (brid >= 0) { | |
26607 | + bindex = au_br_index(sb, brid); | |
4a4d8108 AM |
26608 | + hdp = au_di(sb->s_root)->di_hdentry; |
26609 | + h_root = hdp[0 + bindex].hd_dentry; | |
1facf9fc | 26610 | + } |
26611 | + d = f->f_dentry; | |
26612 | + name = &d->d_name; | |
26613 | + /* safe ->d_parent because the file is unlinked */ | |
26614 | + if (d->d_parent == h_root | |
26615 | + && name->len == len | |
26616 | + && !memcmp(name->name, AUFS_XINO_FNAME, len)) | |
26617 | + goto out; | |
26618 | + | |
26619 | + seq_puts(seq, ",xino="); | |
26620 | + err = au_xino_path(seq, f); | |
26621 | + | |
4f0767ce | 26622 | +out: |
1facf9fc | 26623 | + return err; |
26624 | +#endif | |
26625 | +} | |
26626 | + | |
26627 | +/* seq_file will re-call me in case of too long string */ | |
7eafdf33 | 26628 | +static int aufs_show_options(struct seq_file *m, struct dentry *dentry) |
1facf9fc | 26629 | +{ |
027c5e7a | 26630 | + int err; |
1facf9fc | 26631 | + unsigned int mnt_flags, v; |
26632 | + struct super_block *sb; | |
26633 | + struct au_sbinfo *sbinfo; | |
26634 | + | |
26635 | +#define AuBool(name, str) do { \ | |
26636 | + v = au_opt_test(mnt_flags, name); \ | |
26637 | + if (v != au_opt_test(AuOpt_Def, name)) \ | |
26638 | + seq_printf(m, ",%s" #str, v ? "" : "no"); \ | |
26639 | +} while (0) | |
26640 | + | |
26641 | +#define AuStr(name, str) do { \ | |
26642 | + v = mnt_flags & AuOptMask_##name; \ | |
26643 | + if (v != (AuOpt_Def & AuOptMask_##name)) \ | |
26644 | + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \ | |
26645 | +} while (0) | |
26646 | + | |
26647 | +#define AuUInt(name, str, val) do { \ | |
26648 | + if (val != AUFS_##name##_DEF) \ | |
26649 | + seq_printf(m, "," #str "=%u", val); \ | |
26650 | +} while (0) | |
26651 | + | |
7eafdf33 | 26652 | + sb = dentry->d_sb; |
c1595e42 JR |
26653 | + if (sb->s_flags & MS_POSIXACL) |
26654 | + seq_puts(m, ",acl"); | |
26655 | + | |
26656 | + /* lock free root dinfo */ | |
1facf9fc | 26657 | + si_noflush_read_lock(sb); |
26658 | + sbinfo = au_sbi(sb); | |
26659 | + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo)); | |
26660 | + | |
26661 | + mnt_flags = au_mntflags(sb); | |
26662 | + if (au_opt_test(mnt_flags, XINO)) { | |
7eafdf33 | 26663 | + err = au_show_xino(m, sb); |
1facf9fc | 26664 | + if (unlikely(err)) |
26665 | + goto out; | |
26666 | + } else | |
26667 | + seq_puts(m, ",noxino"); | |
26668 | + | |
26669 | + AuBool(TRUNC_XINO, trunc_xino); | |
26670 | + AuStr(UDBA, udba); | |
dece6358 | 26671 | + AuBool(SHWH, shwh); |
1facf9fc | 26672 | + AuBool(PLINK, plink); |
4a4d8108 | 26673 | + AuBool(DIO, dio); |
076b876e | 26674 | + AuBool(DIRPERM1, dirperm1); |
1facf9fc | 26675 | + /* AuBool(REFROF, refrof); */ |
26676 | + | |
26677 | + v = sbinfo->si_wbr_create; | |
26678 | + if (v != AuWbrCreate_Def) | |
26679 | + au_show_wbr_create(m, v, sbinfo); | |
26680 | + | |
26681 | + v = sbinfo->si_wbr_copyup; | |
26682 | + if (v != AuWbrCopyup_Def) | |
26683 | + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v)); | |
26684 | + | |
26685 | + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ); | |
26686 | + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ)) | |
26687 | + seq_printf(m, ",diropq=%c", v ? 'a' : 'w'); | |
26688 | + | |
26689 | + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh); | |
26690 | + | |
027c5e7a AM |
26691 | + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC; |
26692 | + AuUInt(RDCACHE, rdcache, v); | |
1facf9fc | 26693 | + |
26694 | + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk); | |
26695 | + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash); | |
26696 | + | |
076b876e AM |
26697 | + au_fhsm_show(m, sbinfo); |
26698 | + | |
1facf9fc | 26699 | + AuBool(SUM, sum); |
26700 | + /* AuBool(SUM_W, wsum); */ | |
26701 | + AuBool(WARN_PERM, warn_perm); | |
26702 | + AuBool(VERBOSE, verbose); | |
26703 | + | |
4f0767ce | 26704 | +out: |
1facf9fc | 26705 | + /* be sure to print "br:" last */ |
26706 | + if (!sysaufs_brs) { | |
26707 | + seq_puts(m, ",br:"); | |
26708 | + au_show_brs(m, sb); | |
26709 | + } | |
26710 | + si_read_unlock(sb); | |
26711 | + return 0; | |
26712 | + | |
1facf9fc | 26713 | +#undef AuBool |
26714 | +#undef AuStr | |
4a4d8108 | 26715 | +#undef AuUInt |
1facf9fc | 26716 | +} |
26717 | + | |
26718 | +/* ---------------------------------------------------------------------- */ | |
26719 | + | |
26720 | +/* sum mode which returns the summation for statfs(2) */ | |
26721 | + | |
26722 | +static u64 au_add_till_max(u64 a, u64 b) | |
26723 | +{ | |
26724 | + u64 old; | |
26725 | + | |
26726 | + old = a; | |
26727 | + a += b; | |
92d182d2 AM |
26728 | + if (old <= a) |
26729 | + return a; | |
26730 | + return ULLONG_MAX; | |
26731 | +} | |
26732 | + | |
26733 | +static u64 au_mul_till_max(u64 a, long mul) | |
26734 | +{ | |
26735 | + u64 old; | |
26736 | + | |
26737 | + old = a; | |
26738 | + a *= mul; | |
26739 | + if (old <= a) | |
1facf9fc | 26740 | + return a; |
26741 | + return ULLONG_MAX; | |
26742 | +} | |
26743 | + | |
26744 | +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf) | |
26745 | +{ | |
26746 | + int err; | |
92d182d2 | 26747 | + long bsize, factor; |
1facf9fc | 26748 | + u64 blocks, bfree, bavail, files, ffree; |
26749 | + aufs_bindex_t bend, bindex, i; | |
26750 | + unsigned char shared; | |
7f207e10 | 26751 | + struct path h_path; |
1facf9fc | 26752 | + struct super_block *h_sb; |
26753 | + | |
92d182d2 AM |
26754 | + err = 0; |
26755 | + bsize = LONG_MAX; | |
26756 | + files = 0; | |
26757 | + ffree = 0; | |
1facf9fc | 26758 | + blocks = 0; |
26759 | + bfree = 0; | |
26760 | + bavail = 0; | |
1facf9fc | 26761 | + bend = au_sbend(sb); |
92d182d2 | 26762 | + for (bindex = 0; bindex <= bend; bindex++) { |
7f207e10 AM |
26763 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
26764 | + h_sb = h_path.mnt->mnt_sb; | |
1facf9fc | 26765 | + shared = 0; |
92d182d2 | 26766 | + for (i = 0; !shared && i < bindex; i++) |
1facf9fc | 26767 | + shared = (au_sbr_sb(sb, i) == h_sb); |
26768 | + if (shared) | |
26769 | + continue; | |
26770 | + | |
26771 | + /* sb->s_root for NFS is unreliable */ | |
7f207e10 AM |
26772 | + h_path.dentry = h_path.mnt->mnt_root; |
26773 | + err = vfs_statfs(&h_path, buf); | |
1facf9fc | 26774 | + if (unlikely(err)) |
26775 | + goto out; | |
26776 | + | |
92d182d2 AM |
26777 | + if (bsize > buf->f_bsize) { |
26778 | + /* | |
26779 | + * we will reduce bsize, so we have to expand blocks | |
26780 | + * etc. to match them again | |
26781 | + */ | |
26782 | + factor = (bsize / buf->f_bsize); | |
26783 | + blocks = au_mul_till_max(blocks, factor); | |
26784 | + bfree = au_mul_till_max(bfree, factor); | |
26785 | + bavail = au_mul_till_max(bavail, factor); | |
26786 | + bsize = buf->f_bsize; | |
26787 | + } | |
26788 | + | |
26789 | + factor = (buf->f_bsize / bsize); | |
26790 | + blocks = au_add_till_max(blocks, | |
26791 | + au_mul_till_max(buf->f_blocks, factor)); | |
26792 | + bfree = au_add_till_max(bfree, | |
26793 | + au_mul_till_max(buf->f_bfree, factor)); | |
26794 | + bavail = au_add_till_max(bavail, | |
26795 | + au_mul_till_max(buf->f_bavail, factor)); | |
1facf9fc | 26796 | + files = au_add_till_max(files, buf->f_files); |
26797 | + ffree = au_add_till_max(ffree, buf->f_ffree); | |
26798 | + } | |
26799 | + | |
92d182d2 | 26800 | + buf->f_bsize = bsize; |
1facf9fc | 26801 | + buf->f_blocks = blocks; |
26802 | + buf->f_bfree = bfree; | |
26803 | + buf->f_bavail = bavail; | |
26804 | + buf->f_files = files; | |
26805 | + buf->f_ffree = ffree; | |
92d182d2 | 26806 | + buf->f_frsize = 0; |
1facf9fc | 26807 | + |
4f0767ce | 26808 | +out: |
1facf9fc | 26809 | + return err; |
26810 | +} | |
26811 | + | |
26812 | +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf) | |
26813 | +{ | |
26814 | + int err; | |
7f207e10 | 26815 | + struct path h_path; |
1facf9fc | 26816 | + struct super_block *sb; |
26817 | + | |
26818 | + /* lock free root dinfo */ | |
26819 | + sb = dentry->d_sb; | |
26820 | + si_noflush_read_lock(sb); | |
7f207e10 | 26821 | + if (!au_opt_test(au_mntflags(sb), SUM)) { |
1facf9fc | 26822 | + /* sb->s_root for NFS is unreliable */ |
7f207e10 AM |
26823 | + h_path.mnt = au_sbr_mnt(sb, 0); |
26824 | + h_path.dentry = h_path.mnt->mnt_root; | |
26825 | + err = vfs_statfs(&h_path, buf); | |
26826 | + } else | |
1facf9fc | 26827 | + err = au_statfs_sum(sb, buf); |
26828 | + si_read_unlock(sb); | |
26829 | + | |
26830 | + if (!err) { | |
26831 | + buf->f_type = AUFS_SUPER_MAGIC; | |
4a4d8108 | 26832 | + buf->f_namelen = AUFS_MAX_NAMELEN; |
1facf9fc | 26833 | + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid)); |
26834 | + } | |
26835 | + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */ | |
26836 | + | |
26837 | + return err; | |
26838 | +} | |
26839 | + | |
26840 | +/* ---------------------------------------------------------------------- */ | |
26841 | + | |
537831f9 AM |
26842 | +static int aufs_sync_fs(struct super_block *sb, int wait) |
26843 | +{ | |
26844 | + int err, e; | |
26845 | + aufs_bindex_t bend, bindex; | |
26846 | + struct au_branch *br; | |
26847 | + struct super_block *h_sb; | |
26848 | + | |
26849 | + err = 0; | |
26850 | + si_noflush_read_lock(sb); | |
26851 | + bend = au_sbend(sb); | |
26852 | + for (bindex = 0; bindex <= bend; bindex++) { | |
26853 | + br = au_sbr(sb, bindex); | |
26854 | + if (!au_br_writable(br->br_perm)) | |
26855 | + continue; | |
26856 | + | |
26857 | + h_sb = au_sbr_sb(sb, bindex); | |
26858 | + if (h_sb->s_op->sync_fs) { | |
26859 | + e = h_sb->s_op->sync_fs(h_sb, wait); | |
26860 | + if (unlikely(e && !err)) | |
26861 | + err = e; | |
26862 | + /* go on even if an error happens */ | |
26863 | + } | |
26864 | + } | |
26865 | + si_read_unlock(sb); | |
26866 | + | |
26867 | + return err; | |
26868 | +} | |
26869 | + | |
26870 | +/* ---------------------------------------------------------------------- */ | |
26871 | + | |
1facf9fc | 26872 | +/* final actions when unmounting a file system */ |
26873 | +static void aufs_put_super(struct super_block *sb) | |
26874 | +{ | |
26875 | + struct au_sbinfo *sbinfo; | |
26876 | + | |
26877 | + sbinfo = au_sbi(sb); | |
26878 | + if (!sbinfo) | |
26879 | + return; | |
26880 | + | |
1facf9fc | 26881 | + dbgaufs_si_fin(sbinfo); |
26882 | + kobject_put(&sbinfo->si_kobj); | |
26883 | +} | |
26884 | + | |
26885 | +/* ---------------------------------------------------------------------- */ | |
26886 | + | |
7f207e10 AM |
26887 | +void au_array_free(void *array) |
26888 | +{ | |
26889 | + if (array) { | |
26890 | + if (!is_vmalloc_addr(array)) | |
26891 | + kfree(array); | |
26892 | + else | |
26893 | + vfree(array); | |
26894 | + } | |
26895 | +} | |
26896 | + | |
26897 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg) | |
26898 | +{ | |
26899 | + void *array; | |
076b876e | 26900 | + unsigned long long n, sz; |
7f207e10 AM |
26901 | + |
26902 | + array = NULL; | |
26903 | + n = 0; | |
26904 | + if (!*hint) | |
26905 | + goto out; | |
26906 | + | |
26907 | + if (*hint > ULLONG_MAX / sizeof(array)) { | |
26908 | + array = ERR_PTR(-EMFILE); | |
26909 | + pr_err("hint %llu\n", *hint); | |
26910 | + goto out; | |
26911 | + } | |
26912 | + | |
076b876e AM |
26913 | + sz = sizeof(array) * *hint; |
26914 | + array = kzalloc(sz, GFP_NOFS); | |
7f207e10 | 26915 | + if (unlikely(!array)) |
076b876e | 26916 | + array = vzalloc(sz); |
7f207e10 AM |
26917 | + if (unlikely(!array)) { |
26918 | + array = ERR_PTR(-ENOMEM); | |
26919 | + goto out; | |
26920 | + } | |
26921 | + | |
26922 | + n = cb(array, *hint, arg); | |
26923 | + AuDebugOn(n > *hint); | |
26924 | + | |
26925 | +out: | |
26926 | + *hint = n; | |
26927 | + return array; | |
26928 | +} | |
26929 | + | |
26930 | +static unsigned long long au_iarray_cb(void *a, | |
26931 | + unsigned long long max __maybe_unused, | |
26932 | + void *arg) | |
26933 | +{ | |
26934 | + unsigned long long n; | |
26935 | + struct inode **p, *inode; | |
26936 | + struct list_head *head; | |
26937 | + | |
26938 | + n = 0; | |
26939 | + p = a; | |
26940 | + head = arg; | |
2cbb1c4b | 26941 | + spin_lock(&inode_sb_list_lock); |
7f207e10 AM |
26942 | + list_for_each_entry(inode, head, i_sb_list) { |
26943 | + if (!is_bad_inode(inode) | |
26944 | + && au_ii(inode)->ii_bstart >= 0) { | |
2cbb1c4b JR |
26945 | + spin_lock(&inode->i_lock); |
26946 | + if (atomic_read(&inode->i_count)) { | |
26947 | + au_igrab(inode); | |
26948 | + *p++ = inode; | |
26949 | + n++; | |
26950 | + AuDebugOn(n > max); | |
26951 | + } | |
26952 | + spin_unlock(&inode->i_lock); | |
7f207e10 AM |
26953 | + } |
26954 | + } | |
2cbb1c4b | 26955 | + spin_unlock(&inode_sb_list_lock); |
7f207e10 AM |
26956 | + |
26957 | + return n; | |
26958 | +} | |
26959 | + | |
26960 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max) | |
26961 | +{ | |
26962 | + *max = atomic_long_read(&au_sbi(sb)->si_ninodes); | |
26963 | + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes); | |
26964 | +} | |
26965 | + | |
26966 | +void au_iarray_free(struct inode **a, unsigned long long max) | |
26967 | +{ | |
26968 | + unsigned long long ull; | |
26969 | + | |
26970 | + for (ull = 0; ull < max; ull++) | |
26971 | + iput(a[ull]); | |
26972 | + au_array_free(a); | |
26973 | +} | |
26974 | + | |
26975 | +/* ---------------------------------------------------------------------- */ | |
26976 | + | |
1facf9fc | 26977 | +/* |
26978 | + * refresh dentry and inode at remount time. | |
26979 | + */ | |
027c5e7a AM |
26980 | +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */ |
26981 | +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags, | |
26982 | + struct dentry *parent) | |
1facf9fc | 26983 | +{ |
26984 | + int err; | |
1facf9fc | 26985 | + |
26986 | + di_write_lock_child(dentry); | |
1facf9fc | 26987 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a AM |
26988 | + err = au_refresh_dentry(dentry, parent); |
26989 | + if (!err && dir_flags) | |
26990 | + au_hn_reset(dentry->d_inode, dir_flags); | |
1facf9fc | 26991 | + di_read_unlock(parent, AuLock_IR); |
1facf9fc | 26992 | + di_write_unlock(dentry); |
26993 | + | |
26994 | + return err; | |
26995 | +} | |
26996 | + | |
027c5e7a AM |
26997 | +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen, |
26998 | + struct au_sbinfo *sbinfo, | |
26999 | + const unsigned int dir_flags) | |
1facf9fc | 27000 | +{ |
027c5e7a AM |
27001 | + int err; |
27002 | + struct dentry *parent; | |
27003 | + struct inode *inode; | |
27004 | + | |
27005 | + err = 0; | |
27006 | + parent = dget_parent(dentry); | |
27007 | + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) { | |
27008 | + inode = dentry->d_inode; | |
27009 | + if (inode) { | |
27010 | + if (!S_ISDIR(inode->i_mode)) | |
27011 | + err = au_do_refresh(dentry, /*dir_flags*/0, | |
27012 | + parent); | |
27013 | + else { | |
27014 | + err = au_do_refresh(dentry, dir_flags, parent); | |
27015 | + if (unlikely(err)) | |
27016 | + au_fset_si(sbinfo, FAILED_REFRESH_DIR); | |
27017 | + } | |
27018 | + } else | |
27019 | + err = au_do_refresh(dentry, /*dir_flags*/0, parent); | |
27020 | + AuDbgDentry(dentry); | |
27021 | + } | |
27022 | + dput(parent); | |
27023 | + | |
27024 | + AuTraceErr(err); | |
27025 | + return err; | |
1facf9fc | 27026 | +} |
27027 | + | |
027c5e7a | 27028 | +static int au_refresh_d(struct super_block *sb) |
1facf9fc | 27029 | +{ |
27030 | + int err, i, j, ndentry, e; | |
027c5e7a | 27031 | + unsigned int sigen; |
1facf9fc | 27032 | + struct au_dcsub_pages dpages; |
27033 | + struct au_dpage *dpage; | |
027c5e7a AM |
27034 | + struct dentry **dentries, *d; |
27035 | + struct au_sbinfo *sbinfo; | |
27036 | + struct dentry *root = sb->s_root; | |
27037 | + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1); | |
1facf9fc | 27038 | + |
027c5e7a AM |
27039 | + err = au_dpages_init(&dpages, GFP_NOFS); |
27040 | + if (unlikely(err)) | |
1facf9fc | 27041 | + goto out; |
027c5e7a AM |
27042 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); |
27043 | + if (unlikely(err)) | |
1facf9fc | 27044 | + goto out_dpages; |
1facf9fc | 27045 | + |
027c5e7a AM |
27046 | + sigen = au_sigen(sb); |
27047 | + sbinfo = au_sbi(sb); | |
27048 | + for (i = 0; i < dpages.ndpage; i++) { | |
1facf9fc | 27049 | + dpage = dpages.dpages + i; |
27050 | + dentries = dpage->dentries; | |
27051 | + ndentry = dpage->ndentry; | |
027c5e7a | 27052 | + for (j = 0; j < ndentry; j++) { |
1facf9fc | 27053 | + d = dentries[j]; |
027c5e7a AM |
27054 | + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags); |
27055 | + if (unlikely(e && !err)) | |
27056 | + err = e; | |
27057 | + /* go on even err */ | |
1facf9fc | 27058 | + } |
27059 | + } | |
27060 | + | |
4f0767ce | 27061 | +out_dpages: |
1facf9fc | 27062 | + au_dpages_free(&dpages); |
4f0767ce | 27063 | +out: |
1facf9fc | 27064 | + return err; |
27065 | +} | |
27066 | + | |
027c5e7a | 27067 | +static int au_refresh_i(struct super_block *sb) |
1facf9fc | 27068 | +{ |
027c5e7a AM |
27069 | + int err, e; |
27070 | + unsigned int sigen; | |
27071 | + unsigned long long max, ull; | |
27072 | + struct inode *inode, **array; | |
1facf9fc | 27073 | + |
027c5e7a AM |
27074 | + array = au_iarray_alloc(sb, &max); |
27075 | + err = PTR_ERR(array); | |
27076 | + if (IS_ERR(array)) | |
27077 | + goto out; | |
1facf9fc | 27078 | + |
27079 | + err = 0; | |
027c5e7a AM |
27080 | + sigen = au_sigen(sb); |
27081 | + for (ull = 0; ull < max; ull++) { | |
27082 | + inode = array[ull]; | |
076b876e AM |
27083 | + if (unlikely(!inode)) |
27084 | + break; | |
537831f9 | 27085 | + if (au_iigen(inode, NULL) != sigen) { |
1facf9fc | 27086 | + ii_write_lock_child(inode); |
027c5e7a | 27087 | + e = au_refresh_hinode_self(inode); |
1facf9fc | 27088 | + ii_write_unlock(inode); |
27089 | + if (unlikely(e)) { | |
027c5e7a | 27090 | + pr_err("error %d, i%lu\n", e, inode->i_ino); |
1facf9fc | 27091 | + if (!err) |
27092 | + err = e; | |
27093 | + /* go on even if err */ | |
27094 | + } | |
27095 | + } | |
1facf9fc | 27096 | + } |
27097 | + | |
027c5e7a | 27098 | + au_iarray_free(array, max); |
1facf9fc | 27099 | + |
4f0767ce | 27100 | +out: |
1facf9fc | 27101 | + return err; |
27102 | +} | |
27103 | + | |
027c5e7a | 27104 | +static void au_remount_refresh(struct super_block *sb) |
1facf9fc | 27105 | +{ |
027c5e7a AM |
27106 | + int err, e; |
27107 | + unsigned int udba; | |
27108 | + aufs_bindex_t bindex, bend; | |
1facf9fc | 27109 | + struct dentry *root; |
27110 | + struct inode *inode; | |
027c5e7a | 27111 | + struct au_branch *br; |
1facf9fc | 27112 | + |
27113 | + au_sigen_inc(sb); | |
027c5e7a | 27114 | + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR); |
1facf9fc | 27115 | + |
27116 | + root = sb->s_root; | |
27117 | + DiMustNoWaiters(root); | |
27118 | + inode = root->d_inode; | |
27119 | + IiMustNoWaiters(inode); | |
1facf9fc | 27120 | + |
027c5e7a AM |
27121 | + udba = au_opt_udba(sb); |
27122 | + bend = au_sbend(sb); | |
27123 | + for (bindex = 0; bindex <= bend; bindex++) { | |
27124 | + br = au_sbr(sb, bindex); | |
27125 | + err = au_hnotify_reset_br(udba, br, br->br_perm); | |
1facf9fc | 27126 | + if (unlikely(err)) |
027c5e7a AM |
27127 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", |
27128 | + bindex, err); | |
27129 | + /* go on even if err */ | |
1facf9fc | 27130 | + } |
027c5e7a | 27131 | + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1)); |
1facf9fc | 27132 | + |
027c5e7a AM |
27133 | + di_write_unlock(root); |
27134 | + err = au_refresh_d(sb); | |
27135 | + e = au_refresh_i(sb); | |
27136 | + if (unlikely(e && !err)) | |
27137 | + err = e; | |
1facf9fc | 27138 | + /* aufs_write_lock() calls ..._child() */ |
27139 | + di_write_lock_child(root); | |
027c5e7a AM |
27140 | + |
27141 | + au_cpup_attr_all(inode, /*force*/1); | |
27142 | + | |
27143 | + if (unlikely(err)) | |
27144 | + AuIOErr("refresh failed, ignored, %d\n", err); | |
1facf9fc | 27145 | +} |
27146 | + | |
27147 | +/* stop extra interpretation of errno in mount(8), and strange error messages */ | |
27148 | +static int cvt_err(int err) | |
27149 | +{ | |
27150 | + AuTraceErr(err); | |
27151 | + | |
27152 | + switch (err) { | |
27153 | + case -ENOENT: | |
27154 | + case -ENOTDIR: | |
27155 | + case -EEXIST: | |
27156 | + case -EIO: | |
27157 | + err = -EINVAL; | |
27158 | + } | |
27159 | + return err; | |
27160 | +} | |
27161 | + | |
27162 | +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data) | |
27163 | +{ | |
4a4d8108 AM |
27164 | + int err, do_dx; |
27165 | + unsigned int mntflags; | |
1facf9fc | 27166 | + struct au_opts opts; |
27167 | + struct dentry *root; | |
27168 | + struct inode *inode; | |
27169 | + struct au_sbinfo *sbinfo; | |
27170 | + | |
27171 | + err = 0; | |
27172 | + root = sb->s_root; | |
27173 | + if (!data || !*data) { | |
e49829fe JR |
27174 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
27175 | + if (!err) { | |
27176 | + di_write_lock_child(root); | |
27177 | + err = au_opts_verify(sb, *flags, /*pending*/0); | |
27178 | + aufs_write_unlock(root); | |
27179 | + } | |
1facf9fc | 27180 | + goto out; |
27181 | + } | |
27182 | + | |
27183 | + err = -ENOMEM; | |
27184 | + memset(&opts, 0, sizeof(opts)); | |
27185 | + opts.opt = (void *)__get_free_page(GFP_NOFS); | |
27186 | + if (unlikely(!opts.opt)) | |
27187 | + goto out; | |
27188 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
27189 | + opts.flags = AuOpts_REMOUNT; | |
27190 | + opts.sb_flags = *flags; | |
27191 | + | |
27192 | + /* parse it before aufs lock */ | |
27193 | + err = au_opts_parse(sb, data, &opts); | |
27194 | + if (unlikely(err)) | |
27195 | + goto out_opts; | |
27196 | + | |
27197 | + sbinfo = au_sbi(sb); | |
27198 | + inode = root->d_inode; | |
27199 | + mutex_lock(&inode->i_mutex); | |
e49829fe JR |
27200 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
27201 | + if (unlikely(err)) | |
27202 | + goto out_mtx; | |
27203 | + di_write_lock_child(root); | |
1facf9fc | 27204 | + |
27205 | + /* au_opts_remount() may return an error */ | |
27206 | + err = au_opts_remount(sb, &opts); | |
27207 | + au_opts_free(&opts); | |
27208 | + | |
027c5e7a AM |
27209 | + if (au_ftest_opts(opts.flags, REFRESH)) |
27210 | + au_remount_refresh(sb); | |
1facf9fc | 27211 | + |
4a4d8108 AM |
27212 | + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) { |
27213 | + mntflags = au_mntflags(sb); | |
27214 | + do_dx = !!au_opt_test(mntflags, DIO); | |
27215 | + au_dy_arefresh(do_dx); | |
27216 | + } | |
27217 | + | |
076b876e | 27218 | + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */ |
1facf9fc | 27219 | + aufs_write_unlock(root); |
953406b4 | 27220 | + |
e49829fe JR |
27221 | +out_mtx: |
27222 | + mutex_unlock(&inode->i_mutex); | |
4f0767ce | 27223 | +out_opts: |
1facf9fc | 27224 | + free_page((unsigned long)opts.opt); |
4f0767ce | 27225 | +out: |
1facf9fc | 27226 | + err = cvt_err(err); |
27227 | + AuTraceErr(err); | |
27228 | + return err; | |
27229 | +} | |
27230 | + | |
4a4d8108 | 27231 | +static const struct super_operations aufs_sop = { |
1facf9fc | 27232 | + .alloc_inode = aufs_alloc_inode, |
27233 | + .destroy_inode = aufs_destroy_inode, | |
b752ccd1 | 27234 | + /* always deleting, no clearing */ |
1facf9fc | 27235 | + .drop_inode = generic_delete_inode, |
27236 | + .show_options = aufs_show_options, | |
27237 | + .statfs = aufs_statfs, | |
27238 | + .put_super = aufs_put_super, | |
537831f9 | 27239 | + .sync_fs = aufs_sync_fs, |
1facf9fc | 27240 | + .remount_fs = aufs_remount_fs |
27241 | +}; | |
27242 | + | |
27243 | +/* ---------------------------------------------------------------------- */ | |
27244 | + | |
27245 | +static int alloc_root(struct super_block *sb) | |
27246 | +{ | |
27247 | + int err; | |
27248 | + struct inode *inode; | |
27249 | + struct dentry *root; | |
27250 | + | |
27251 | + err = -ENOMEM; | |
27252 | + inode = au_iget_locked(sb, AUFS_ROOT_INO); | |
27253 | + err = PTR_ERR(inode); | |
27254 | + if (IS_ERR(inode)) | |
27255 | + goto out; | |
27256 | + | |
27257 | + inode->i_op = &aufs_dir_iop; | |
27258 | + inode->i_fop = &aufs_dir_fop; | |
27259 | + inode->i_mode = S_IFDIR; | |
9dbd164d | 27260 | + set_nlink(inode, 2); |
1facf9fc | 27261 | + unlock_new_inode(inode); |
27262 | + | |
92d182d2 | 27263 | + root = d_make_root(inode); |
1facf9fc | 27264 | + if (unlikely(!root)) |
92d182d2 | 27265 | + goto out; |
1facf9fc | 27266 | + err = PTR_ERR(root); |
27267 | + if (IS_ERR(root)) | |
92d182d2 | 27268 | + goto out; |
1facf9fc | 27269 | + |
4a4d8108 | 27270 | + err = au_di_init(root); |
1facf9fc | 27271 | + if (!err) { |
27272 | + sb->s_root = root; | |
27273 | + return 0; /* success */ | |
27274 | + } | |
27275 | + dput(root); | |
1facf9fc | 27276 | + |
4f0767ce | 27277 | +out: |
1facf9fc | 27278 | + return err; |
1facf9fc | 27279 | +} |
27280 | + | |
27281 | +static int aufs_fill_super(struct super_block *sb, void *raw_data, | |
27282 | + int silent __maybe_unused) | |
27283 | +{ | |
27284 | + int err; | |
27285 | + struct au_opts opts; | |
27286 | + struct dentry *root; | |
27287 | + struct inode *inode; | |
27288 | + char *arg = raw_data; | |
27289 | + | |
27290 | + if (unlikely(!arg || !*arg)) { | |
27291 | + err = -EINVAL; | |
4a4d8108 | 27292 | + pr_err("no arg\n"); |
1facf9fc | 27293 | + goto out; |
27294 | + } | |
27295 | + | |
27296 | + err = -ENOMEM; | |
27297 | + memset(&opts, 0, sizeof(opts)); | |
27298 | + opts.opt = (void *)__get_free_page(GFP_NOFS); | |
27299 | + if (unlikely(!opts.opt)) | |
27300 | + goto out; | |
27301 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
27302 | + opts.sb_flags = sb->s_flags; | |
27303 | + | |
27304 | + err = au_si_alloc(sb); | |
27305 | + if (unlikely(err)) | |
27306 | + goto out_opts; | |
27307 | + | |
27308 | + /* all timestamps always follow the ones on the branch */ | |
27309 | + sb->s_flags |= MS_NOATIME | MS_NODIRATIME; | |
27310 | + sb->s_op = &aufs_sop; | |
027c5e7a | 27311 | + sb->s_d_op = &aufs_dop; |
1facf9fc | 27312 | + sb->s_magic = AUFS_SUPER_MAGIC; |
27313 | + sb->s_maxbytes = 0; | |
c1595e42 | 27314 | + sb->s_stack_depth = 1; |
1facf9fc | 27315 | + au_export_init(sb); |
c1595e42 | 27316 | + /* au_xattr_init(sb); */ |
1facf9fc | 27317 | + |
27318 | + err = alloc_root(sb); | |
27319 | + if (unlikely(err)) { | |
27320 | + si_write_unlock(sb); | |
27321 | + goto out_info; | |
27322 | + } | |
27323 | + root = sb->s_root; | |
27324 | + inode = root->d_inode; | |
27325 | + | |
27326 | + /* | |
27327 | + * actually we can parse options regardless aufs lock here. | |
27328 | + * but at remount time, parsing must be done before aufs lock. | |
27329 | + * so we follow the same rule. | |
27330 | + */ | |
27331 | + ii_write_lock_parent(inode); | |
27332 | + aufs_write_unlock(root); | |
27333 | + err = au_opts_parse(sb, arg, &opts); | |
27334 | + if (unlikely(err)) | |
27335 | + goto out_root; | |
27336 | + | |
27337 | + /* lock vfs_inode first, then aufs. */ | |
27338 | + mutex_lock(&inode->i_mutex); | |
1facf9fc | 27339 | + aufs_write_lock(root); |
27340 | + err = au_opts_mount(sb, &opts); | |
27341 | + au_opts_free(&opts); | |
1facf9fc | 27342 | + aufs_write_unlock(root); |
27343 | + mutex_unlock(&inode->i_mutex); | |
4a4d8108 AM |
27344 | + if (!err) |
27345 | + goto out_opts; /* success */ | |
1facf9fc | 27346 | + |
4f0767ce | 27347 | +out_root: |
1facf9fc | 27348 | + dput(root); |
27349 | + sb->s_root = NULL; | |
4f0767ce | 27350 | +out_info: |
2cbb1c4b | 27351 | + dbgaufs_si_fin(au_sbi(sb)); |
1facf9fc | 27352 | + kobject_put(&au_sbi(sb)->si_kobj); |
27353 | + sb->s_fs_info = NULL; | |
4f0767ce | 27354 | +out_opts: |
1facf9fc | 27355 | + free_page((unsigned long)opts.opt); |
4f0767ce | 27356 | +out: |
1facf9fc | 27357 | + AuTraceErr(err); |
27358 | + err = cvt_err(err); | |
27359 | + AuTraceErr(err); | |
27360 | + return err; | |
27361 | +} | |
27362 | + | |
27363 | +/* ---------------------------------------------------------------------- */ | |
27364 | + | |
027c5e7a AM |
27365 | +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags, |
27366 | + const char *dev_name __maybe_unused, | |
27367 | + void *raw_data) | |
1facf9fc | 27368 | +{ |
027c5e7a | 27369 | + struct dentry *root; |
1facf9fc | 27370 | + struct super_block *sb; |
27371 | + | |
27372 | + /* all timestamps always follow the ones on the branch */ | |
27373 | + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */ | |
027c5e7a AM |
27374 | + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super); |
27375 | + if (IS_ERR(root)) | |
27376 | + goto out; | |
27377 | + | |
27378 | + sb = root->d_sb; | |
27379 | + si_write_lock(sb, !AuLock_FLUSH); | |
27380 | + sysaufs_brs_add(sb, 0); | |
27381 | + si_write_unlock(sb); | |
27382 | + au_sbilist_add(sb); | |
27383 | + | |
27384 | +out: | |
27385 | + return root; | |
1facf9fc | 27386 | +} |
27387 | + | |
e49829fe JR |
27388 | +static void aufs_kill_sb(struct super_block *sb) |
27389 | +{ | |
27390 | + struct au_sbinfo *sbinfo; | |
27391 | + | |
27392 | + sbinfo = au_sbi(sb); | |
27393 | + if (sbinfo) { | |
27394 | + au_sbilist_del(sb); | |
27395 | + aufs_write_lock(sb->s_root); | |
076b876e | 27396 | + au_fhsm_fin(sb); |
e49829fe JR |
27397 | + if (sbinfo->si_wbr_create_ops->fin) |
27398 | + sbinfo->si_wbr_create_ops->fin(sb); | |
27399 | + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) { | |
27400 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE); | |
027c5e7a | 27401 | + au_remount_refresh(sb); |
e49829fe JR |
27402 | + } |
27403 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
27404 | + au_plink_put(sb, /*verbose*/1); | |
27405 | + au_xino_clr(sb); | |
1e00d052 | 27406 | + sbinfo->si_sb = NULL; |
e49829fe | 27407 | + aufs_write_unlock(sb->s_root); |
e49829fe JR |
27408 | + au_nwt_flush(&sbinfo->si_nowait); |
27409 | + } | |
98d9a5b1 | 27410 | + kill_anon_super(sb); |
e49829fe JR |
27411 | +} |
27412 | + | |
1facf9fc | 27413 | +struct file_system_type aufs_fs_type = { |
27414 | + .name = AUFS_FSTYPE, | |
c06a8ce3 AM |
27415 | + /* a race between rename and others */ |
27416 | + .fs_flags = FS_RENAME_DOES_D_MOVE, | |
027c5e7a | 27417 | + .mount = aufs_mount, |
e49829fe | 27418 | + .kill_sb = aufs_kill_sb, |
1facf9fc | 27419 | + /* no need to __module_get() and module_put(). */ |
27420 | + .owner = THIS_MODULE, | |
27421 | +}; | |
7f207e10 AM |
27422 | diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h |
27423 | --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
27424 | +++ linux/fs/aufs/super.h 2015-01-25 13:00:38.634380408 +0100 |
27425 | @@ -0,0 +1,641 @@ | |
1facf9fc | 27426 | +/* |
523b37e3 | 27427 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 27428 | + * |
27429 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27430 | + * it under the terms of the GNU General Public License as published by | |
27431 | + * the Free Software Foundation; either version 2 of the License, or | |
27432 | + * (at your option) any later version. | |
dece6358 AM |
27433 | + * |
27434 | + * This program is distributed in the hope that it will be useful, | |
27435 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27436 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27437 | + * GNU General Public License for more details. | |
27438 | + * | |
27439 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27440 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27441 | + */ |
27442 | + | |
27443 | +/* | |
27444 | + * super_block operations | |
27445 | + */ | |
27446 | + | |
27447 | +#ifndef __AUFS_SUPER_H__ | |
27448 | +#define __AUFS_SUPER_H__ | |
27449 | + | |
27450 | +#ifdef __KERNEL__ | |
27451 | + | |
27452 | +#include <linux/fs.h> | |
1facf9fc | 27453 | +#include "rwsem.h" |
27454 | +#include "spl.h" | |
27455 | +#include "wkq.h" | |
27456 | + | |
27457 | +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *); | |
27458 | +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t, | |
27459 | + loff_t *); | |
27460 | + | |
27461 | +/* policies to select one among multiple writable branches */ | |
27462 | +struct au_wbr_copyup_operations { | |
27463 | + int (*copyup)(struct dentry *dentry); | |
27464 | +}; | |
27465 | + | |
392086de AM |
27466 | +#define AuWbr_DIR 1 /* target is a dir */ |
27467 | +#define AuWbr_PARENT (1 << 1) /* always require a parent */ | |
27468 | + | |
27469 | +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name) | |
27470 | +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; } | |
27471 | +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; } | |
27472 | + | |
1facf9fc | 27473 | +struct au_wbr_create_operations { |
392086de | 27474 | + int (*create)(struct dentry *dentry, unsigned int flags); |
1facf9fc | 27475 | + int (*init)(struct super_block *sb); |
27476 | + int (*fin)(struct super_block *sb); | |
27477 | +}; | |
27478 | + | |
27479 | +struct au_wbr_mfs { | |
27480 | + struct mutex mfs_lock; /* protect this structure */ | |
27481 | + unsigned long mfs_jiffy; | |
27482 | + unsigned long mfs_expire; | |
27483 | + aufs_bindex_t mfs_bindex; | |
27484 | + | |
27485 | + unsigned long long mfsrr_bytes; | |
27486 | + unsigned long long mfsrr_watermark; | |
27487 | +}; | |
27488 | + | |
86dc4139 AM |
27489 | +struct pseudo_link { |
27490 | + union { | |
27491 | + struct hlist_node hlist; | |
27492 | + struct rcu_head rcu; | |
27493 | + }; | |
27494 | + struct inode *inode; | |
27495 | +}; | |
27496 | + | |
27497 | +#define AuPlink_NHASH 100 | |
27498 | +static inline int au_plink_hash(ino_t ino) | |
27499 | +{ | |
27500 | + return ino % AuPlink_NHASH; | |
27501 | +} | |
27502 | + | |
076b876e AM |
27503 | +/* File-based Hierarchical Storage Management */ |
27504 | +struct au_fhsm { | |
27505 | +#ifdef CONFIG_AUFS_FHSM | |
27506 | + /* allow only one process who can receive the notification */ | |
27507 | + spinlock_t fhsm_spin; | |
27508 | + pid_t fhsm_pid; | |
27509 | + wait_queue_head_t fhsm_wqh; | |
27510 | + atomic_t fhsm_readable; | |
27511 | + | |
c1595e42 | 27512 | + /* these are protected by si_rwsem */ |
076b876e | 27513 | + unsigned long fhsm_expire; |
c1595e42 | 27514 | + aufs_bindex_t fhsm_bottom; |
076b876e AM |
27515 | +#endif |
27516 | +}; | |
27517 | + | |
1facf9fc | 27518 | +struct au_branch; |
27519 | +struct au_sbinfo { | |
27520 | + /* nowait tasks in the system-wide workqueue */ | |
27521 | + struct au_nowait_tasks si_nowait; | |
27522 | + | |
b752ccd1 AM |
27523 | + /* |
27524 | + * tried sb->s_umount, but failed due to the dependecy between i_mutex. | |
27525 | + * rwsem for au_sbinfo is necessary. | |
27526 | + */ | |
dece6358 | 27527 | + struct au_rwsem si_rwsem; |
1facf9fc | 27528 | + |
b752ccd1 AM |
27529 | + /* prevent recursive locking in deleting inode */ |
27530 | + struct { | |
27531 | + unsigned long *bitmap; | |
27532 | + spinlock_t tree_lock; | |
27533 | + struct radix_tree_root tree; | |
27534 | + } au_si_pid; | |
27535 | + | |
7f207e10 | 27536 | + /* |
523b37e3 AM |
27537 | + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from |
27538 | + * remount. | |
7f207e10 AM |
27539 | + */ |
27540 | + atomic_long_t si_ninodes, si_nfiles; | |
27541 | + | |
1facf9fc | 27542 | + /* branch management */ |
27543 | + unsigned int si_generation; | |
27544 | + | |
27545 | + /* see above flags */ | |
27546 | + unsigned char au_si_status; | |
27547 | + | |
27548 | + aufs_bindex_t si_bend; | |
7f207e10 AM |
27549 | + |
27550 | + /* dirty trick to keep br_id plus */ | |
27551 | + unsigned int si_last_br_id : | |
27552 | + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1; | |
1facf9fc | 27553 | + struct au_branch **si_branch; |
27554 | + | |
27555 | + /* policy to select a writable branch */ | |
27556 | + unsigned char si_wbr_copyup; | |
27557 | + unsigned char si_wbr_create; | |
27558 | + struct au_wbr_copyup_operations *si_wbr_copyup_ops; | |
27559 | + struct au_wbr_create_operations *si_wbr_create_ops; | |
27560 | + | |
27561 | + /* round robin */ | |
27562 | + atomic_t si_wbr_rr_next; | |
27563 | + | |
27564 | + /* most free space */ | |
27565 | + struct au_wbr_mfs si_wbr_mfs; | |
27566 | + | |
076b876e AM |
27567 | + /* File-based Hierarchical Storage Management */ |
27568 | + struct au_fhsm si_fhsm; | |
27569 | + | |
1facf9fc | 27570 | + /* mount flags */ |
27571 | + /* include/asm-ia64/siginfo.h defines a macro named si_flags */ | |
27572 | + unsigned int si_mntflags; | |
27573 | + | |
27574 | + /* external inode number (bitmap and translation table) */ | |
27575 | + au_readf_t si_xread; | |
27576 | + au_writef_t si_xwrite; | |
27577 | + struct file *si_xib; | |
27578 | + struct mutex si_xib_mtx; /* protect xib members */ | |
27579 | + unsigned long *si_xib_buf; | |
27580 | + unsigned long si_xib_last_pindex; | |
27581 | + int si_xib_next_bit; | |
27582 | + aufs_bindex_t si_xino_brid; | |
392086de AM |
27583 | + unsigned long si_xino_jiffy; |
27584 | + unsigned long si_xino_expire; | |
1facf9fc | 27585 | + /* reserved for future use */ |
27586 | + /* unsigned long long si_xib_limit; */ /* Max xib file size */ | |
27587 | + | |
27588 | +#ifdef CONFIG_AUFS_EXPORT | |
27589 | + /* i_generation */ | |
27590 | + struct file *si_xigen; | |
27591 | + atomic_t si_xigen_next; | |
27592 | +#endif | |
27593 | + | |
27594 | + /* vdir parameters */ | |
e49829fe | 27595 | + unsigned long si_rdcache; /* max cache time in jiffies */ |
1facf9fc | 27596 | + unsigned int si_rdblk; /* deblk size */ |
27597 | + unsigned int si_rdhash; /* hash size */ | |
27598 | + | |
27599 | + /* | |
27600 | + * If the number of whiteouts are larger than si_dirwh, leave all of | |
27601 | + * them after au_whtmp_ren to reduce the cost of rmdir(2). | |
27602 | + * future fsck.aufs or kernel thread will remove them later. | |
27603 | + * Otherwise, remove all whiteouts and the dir in rmdir(2). | |
27604 | + */ | |
27605 | + unsigned int si_dirwh; | |
27606 | + | |
27607 | + /* | |
27608 | + * rename(2) a directory with all children. | |
27609 | + */ | |
27610 | + /* reserved for future use */ | |
27611 | + /* int si_rendir; */ | |
27612 | + | |
27613 | + /* pseudo_link list */ | |
86dc4139 | 27614 | + struct au_sphlhead si_plink[AuPlink_NHASH]; |
1facf9fc | 27615 | + wait_queue_head_t si_plink_wq; |
4a4d8108 | 27616 | + spinlock_t si_plink_maint_lock; |
e49829fe | 27617 | + pid_t si_plink_maint_pid; |
1facf9fc | 27618 | + |
523b37e3 AM |
27619 | + /* file list */ |
27620 | + struct au_sphlhead si_files; | |
27621 | + | |
1facf9fc | 27622 | + /* |
27623 | + * sysfs and lifetime management. | |
27624 | + * this is not a small structure and it may be a waste of memory in case | |
27625 | + * of sysfs is disabled, particulary when many aufs-es are mounted. | |
27626 | + * but using sysfs is majority. | |
27627 | + */ | |
27628 | + struct kobject si_kobj; | |
27629 | +#ifdef CONFIG_DEBUG_FS | |
86dc4139 AM |
27630 | + struct dentry *si_dbgaufs; |
27631 | + struct dentry *si_dbgaufs_plink; | |
27632 | + struct dentry *si_dbgaufs_xib; | |
1facf9fc | 27633 | +#ifdef CONFIG_AUFS_EXPORT |
27634 | + struct dentry *si_dbgaufs_xigen; | |
27635 | +#endif | |
27636 | +#endif | |
27637 | + | |
e49829fe JR |
27638 | +#ifdef CONFIG_AUFS_SBILIST |
27639 | + struct list_head si_list; | |
27640 | +#endif | |
27641 | + | |
1facf9fc | 27642 | + /* dirty, necessary for unmounting, sysfs and sysrq */ |
27643 | + struct super_block *si_sb; | |
27644 | +}; | |
27645 | + | |
dece6358 AM |
27646 | +/* sbinfo status flags */ |
27647 | +/* | |
27648 | + * set true when refresh_dirs() failed at remount time. | |
27649 | + * then try refreshing dirs at access time again. | |
27650 | + * if it is false, refreshing dirs at access time is unnecesary | |
27651 | + */ | |
027c5e7a | 27652 | +#define AuSi_FAILED_REFRESH_DIR 1 |
076b876e AM |
27653 | + |
27654 | +#define AuSi_FHSM (1 << 1) /* fhsm is active now */ | |
27655 | + | |
27656 | +#ifndef CONFIG_AUFS_FHSM | |
27657 | +#undef AuSi_FHSM | |
27658 | +#define AuSi_FHSM 0 | |
27659 | +#endif | |
27660 | + | |
dece6358 AM |
27661 | +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi, |
27662 | + unsigned int flag) | |
27663 | +{ | |
27664 | + AuRwMustAnyLock(&sbi->si_rwsem); | |
27665 | + return sbi->au_si_status & flag; | |
27666 | +} | |
27667 | +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name) | |
27668 | +#define au_fset_si(sbinfo, name) do { \ | |
27669 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
27670 | + (sbinfo)->au_si_status |= AuSi_##name; \ | |
27671 | +} while (0) | |
27672 | +#define au_fclr_si(sbinfo, name) do { \ | |
27673 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
27674 | + (sbinfo)->au_si_status &= ~AuSi_##name; \ | |
27675 | +} while (0) | |
27676 | + | |
1facf9fc | 27677 | +/* ---------------------------------------------------------------------- */ |
27678 | + | |
27679 | +/* policy to select one among writable branches */ | |
4a4d8108 AM |
27680 | +#define AuWbrCopyup(sbinfo, ...) \ |
27681 | + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__)) | |
27682 | +#define AuWbrCreate(sbinfo, ...) \ | |
27683 | + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__)) | |
1facf9fc | 27684 | + |
27685 | +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */ | |
27686 | +#define AuLock_DW 1 /* write-lock dentry */ | |
27687 | +#define AuLock_IR (1 << 1) /* read-lock inode */ | |
27688 | +#define AuLock_IW (1 << 2) /* write-lock inode */ | |
27689 | +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */ | |
27690 | +#define AuLock_DIR (1 << 4) /* target is a dir */ | |
e49829fe JR |
27691 | +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */ |
27692 | +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */ | |
027c5e7a | 27693 | +#define AuLock_GEN (1 << 7) /* test digen/iigen */ |
1facf9fc | 27694 | +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name) |
7f207e10 AM |
27695 | +#define au_fset_lock(flags, name) \ |
27696 | + do { (flags) |= AuLock_##name; } while (0) | |
27697 | +#define au_fclr_lock(flags, name) \ | |
27698 | + do { (flags) &= ~AuLock_##name; } while (0) | |
1facf9fc | 27699 | + |
27700 | +/* ---------------------------------------------------------------------- */ | |
27701 | + | |
27702 | +/* super.c */ | |
27703 | +extern struct file_system_type aufs_fs_type; | |
27704 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino); | |
7f207e10 AM |
27705 | +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max, |
27706 | + void *arg); | |
27707 | +void au_array_free(void *array); | |
27708 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg); | |
27709 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max); | |
27710 | +void au_iarray_free(struct inode **a, unsigned long long max); | |
1facf9fc | 27711 | + |
27712 | +/* sbinfo.c */ | |
27713 | +void au_si_free(struct kobject *kobj); | |
27714 | +int au_si_alloc(struct super_block *sb); | |
27715 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr); | |
27716 | + | |
27717 | +unsigned int au_sigen_inc(struct super_block *sb); | |
27718 | +aufs_bindex_t au_new_br_id(struct super_block *sb); | |
27719 | + | |
e49829fe JR |
27720 | +int si_read_lock(struct super_block *sb, int flags); |
27721 | +int si_write_lock(struct super_block *sb, int flags); | |
27722 | +int aufs_read_lock(struct dentry *dentry, int flags); | |
1facf9fc | 27723 | +void aufs_read_unlock(struct dentry *dentry, int flags); |
27724 | +void aufs_write_lock(struct dentry *dentry); | |
27725 | +void aufs_write_unlock(struct dentry *dentry); | |
e49829fe | 27726 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags); |
1facf9fc | 27727 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2); |
27728 | + | |
b752ccd1 AM |
27729 | +int si_pid_test_slow(struct super_block *sb); |
27730 | +void si_pid_set_slow(struct super_block *sb); | |
27731 | +void si_pid_clr_slow(struct super_block *sb); | |
27732 | + | |
1facf9fc | 27733 | +/* wbr_policy.c */ |
27734 | +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[]; | |
27735 | +extern struct au_wbr_create_operations au_wbr_create_ops[]; | |
27736 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
c2b27bf2 | 27737 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex); |
076b876e | 27738 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart); |
c2b27bf2 AM |
27739 | + |
27740 | +/* mvdown.c */ | |
27741 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg); | |
1facf9fc | 27742 | + |
076b876e AM |
27743 | +#ifdef CONFIG_AUFS_FHSM |
27744 | +/* fhsm.c */ | |
27745 | + | |
27746 | +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm) | |
27747 | +{ | |
27748 | + pid_t pid; | |
27749 | + | |
27750 | + spin_lock(&fhsm->fhsm_spin); | |
27751 | + pid = fhsm->fhsm_pid; | |
27752 | + spin_unlock(&fhsm->fhsm_spin); | |
27753 | + | |
27754 | + return pid; | |
27755 | +} | |
27756 | + | |
27757 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force); | |
27758 | +void au_fhsm_wrote_all(struct super_block *sb, int force); | |
27759 | +int au_fhsm_fd(struct super_block *sb, int oflags); | |
27760 | +int au_fhsm_br_alloc(struct au_branch *br); | |
c1595e42 | 27761 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex); |
076b876e AM |
27762 | +void au_fhsm_fin(struct super_block *sb); |
27763 | +void au_fhsm_init(struct au_sbinfo *sbinfo); | |
27764 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec); | |
27765 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo); | |
27766 | +#else | |
27767 | +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex, | |
27768 | + int force) | |
27769 | +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force) | |
27770 | +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags) | |
c1595e42 JR |
27771 | +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm) |
27772 | +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br) | |
27773 | +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex) | |
076b876e AM |
27774 | +AuStubVoid(au_fhsm_fin, struct super_block *sb) |
27775 | +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo) | |
27776 | +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec) | |
27777 | +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo) | |
27778 | +#endif | |
27779 | + | |
1facf9fc | 27780 | +/* ---------------------------------------------------------------------- */ |
27781 | + | |
27782 | +static inline struct au_sbinfo *au_sbi(struct super_block *sb) | |
27783 | +{ | |
27784 | + return sb->s_fs_info; | |
27785 | +} | |
27786 | + | |
27787 | +/* ---------------------------------------------------------------------- */ | |
27788 | + | |
27789 | +#ifdef CONFIG_AUFS_EXPORT | |
a2a7ad62 | 27790 | +int au_test_nfsd(void); |
1facf9fc | 27791 | +void au_export_init(struct super_block *sb); |
b752ccd1 | 27792 | +void au_xigen_inc(struct inode *inode); |
1facf9fc | 27793 | +int au_xigen_new(struct inode *inode); |
27794 | +int au_xigen_set(struct super_block *sb, struct file *base); | |
27795 | +void au_xigen_clr(struct super_block *sb); | |
27796 | + | |
27797 | +static inline int au_busy_or_stale(void) | |
27798 | +{ | |
b752ccd1 | 27799 | + if (!au_test_nfsd()) |
1facf9fc | 27800 | + return -EBUSY; |
27801 | + return -ESTALE; | |
27802 | +} | |
27803 | +#else | |
b752ccd1 | 27804 | +AuStubInt0(au_test_nfsd, void) |
a2a7ad62 | 27805 | +AuStubVoid(au_export_init, struct super_block *sb) |
b752ccd1 | 27806 | +AuStubVoid(au_xigen_inc, struct inode *inode) |
4a4d8108 AM |
27807 | +AuStubInt0(au_xigen_new, struct inode *inode) |
27808 | +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base) | |
27809 | +AuStubVoid(au_xigen_clr, struct super_block *sb) | |
c1595e42 | 27810 | +AuStub(int, au_busy_or_stale, return -EBUSY, void) |
1facf9fc | 27811 | +#endif /* CONFIG_AUFS_EXPORT */ |
27812 | + | |
27813 | +/* ---------------------------------------------------------------------- */ | |
27814 | + | |
e49829fe JR |
27815 | +#ifdef CONFIG_AUFS_SBILIST |
27816 | +/* module.c */ | |
27817 | +extern struct au_splhead au_sbilist; | |
27818 | + | |
27819 | +static inline void au_sbilist_init(void) | |
27820 | +{ | |
27821 | + au_spl_init(&au_sbilist); | |
27822 | +} | |
27823 | + | |
27824 | +static inline void au_sbilist_add(struct super_block *sb) | |
27825 | +{ | |
27826 | + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist); | |
27827 | +} | |
27828 | + | |
27829 | +static inline void au_sbilist_del(struct super_block *sb) | |
27830 | +{ | |
27831 | + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist); | |
27832 | +} | |
53392da6 AM |
27833 | + |
27834 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
27835 | +static inline void au_sbilist_lock(void) | |
27836 | +{ | |
27837 | + spin_lock(&au_sbilist.spin); | |
27838 | +} | |
27839 | + | |
27840 | +static inline void au_sbilist_unlock(void) | |
27841 | +{ | |
27842 | + spin_unlock(&au_sbilist.spin); | |
27843 | +} | |
27844 | +#define AuGFP_SBILIST GFP_ATOMIC | |
27845 | +#else | |
27846 | +AuStubVoid(au_sbilist_lock, void) | |
27847 | +AuStubVoid(au_sbilist_unlock, void) | |
27848 | +#define AuGFP_SBILIST GFP_NOFS | |
27849 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ | |
e49829fe JR |
27850 | +#else |
27851 | +AuStubVoid(au_sbilist_init, void) | |
c1595e42 JR |
27852 | +AuStubVoid(au_sbilist_add, struct super_block *sb) |
27853 | +AuStubVoid(au_sbilist_del, struct super_block *sb) | |
53392da6 AM |
27854 | +AuStubVoid(au_sbilist_lock, void) |
27855 | +AuStubVoid(au_sbilist_unlock, void) | |
27856 | +#define AuGFP_SBILIST GFP_NOFS | |
e49829fe JR |
27857 | +#endif |
27858 | + | |
27859 | +/* ---------------------------------------------------------------------- */ | |
27860 | + | |
1facf9fc | 27861 | +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo) |
27862 | +{ | |
dece6358 | 27863 | + /* |
c1595e42 | 27864 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
27865 | + * so the tiny check for si_rwsem is unnecessary. |
27866 | + */ | |
27867 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
1facf9fc | 27868 | +#ifdef CONFIG_DEBUG_FS |
27869 | + sbinfo->si_dbgaufs = NULL; | |
86dc4139 | 27870 | + sbinfo->si_dbgaufs_plink = NULL; |
1facf9fc | 27871 | + sbinfo->si_dbgaufs_xib = NULL; |
27872 | +#ifdef CONFIG_AUFS_EXPORT | |
27873 | + sbinfo->si_dbgaufs_xigen = NULL; | |
27874 | +#endif | |
27875 | +#endif | |
27876 | +} | |
27877 | + | |
27878 | +/* ---------------------------------------------------------------------- */ | |
27879 | + | |
b752ccd1 AM |
27880 | +static inline pid_t si_pid_bit(void) |
27881 | +{ | |
27882 | + /* the origin of pid is 1, but the bitmap's is 0 */ | |
27883 | + return current->pid - 1; | |
27884 | +} | |
27885 | + | |
27886 | +static inline int si_pid_test(struct super_block *sb) | |
27887 | +{ | |
076b876e AM |
27888 | + pid_t bit; |
27889 | + | |
27890 | + bit = si_pid_bit(); | |
b752ccd1 AM |
27891 | + if (bit < PID_MAX_DEFAULT) |
27892 | + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
c1595e42 | 27893 | + return si_pid_test_slow(sb); |
b752ccd1 AM |
27894 | +} |
27895 | + | |
27896 | +static inline void si_pid_set(struct super_block *sb) | |
27897 | +{ | |
076b876e AM |
27898 | + pid_t bit; |
27899 | + | |
27900 | + bit = si_pid_bit(); | |
b752ccd1 AM |
27901 | + if (bit < PID_MAX_DEFAULT) { |
27902 | + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap)); | |
27903 | + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
27904 | + /* smp_mb(); */ | |
27905 | + } else | |
27906 | + si_pid_set_slow(sb); | |
27907 | +} | |
27908 | + | |
27909 | +static inline void si_pid_clr(struct super_block *sb) | |
27910 | +{ | |
076b876e AM |
27911 | + pid_t bit; |
27912 | + | |
27913 | + bit = si_pid_bit(); | |
b752ccd1 AM |
27914 | + if (bit < PID_MAX_DEFAULT) { |
27915 | + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap)); | |
27916 | + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap); | |
27917 | + /* smp_mb(); */ | |
27918 | + } else | |
27919 | + si_pid_clr_slow(sb); | |
27920 | +} | |
27921 | + | |
27922 | +/* ---------------------------------------------------------------------- */ | |
27923 | + | |
1facf9fc | 27924 | +/* lock superblock. mainly for entry point functions */ |
27925 | +/* | |
b752ccd1 AM |
27926 | + * __si_read_lock, __si_write_lock, |
27927 | + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock | |
1facf9fc | 27928 | + */ |
b752ccd1 | 27929 | +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem); |
1facf9fc | 27930 | + |
dece6358 AM |
27931 | +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem) |
27932 | +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem) | |
27933 | +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem) | |
27934 | + | |
b752ccd1 AM |
27935 | +static inline void si_noflush_read_lock(struct super_block *sb) |
27936 | +{ | |
27937 | + __si_read_lock(sb); | |
27938 | + si_pid_set(sb); | |
27939 | +} | |
27940 | + | |
27941 | +static inline int si_noflush_read_trylock(struct super_block *sb) | |
27942 | +{ | |
076b876e AM |
27943 | + int locked; |
27944 | + | |
27945 | + locked = __si_read_trylock(sb); | |
b752ccd1 AM |
27946 | + if (locked) |
27947 | + si_pid_set(sb); | |
27948 | + return locked; | |
27949 | +} | |
27950 | + | |
27951 | +static inline void si_noflush_write_lock(struct super_block *sb) | |
27952 | +{ | |
27953 | + __si_write_lock(sb); | |
27954 | + si_pid_set(sb); | |
27955 | +} | |
27956 | + | |
27957 | +static inline int si_noflush_write_trylock(struct super_block *sb) | |
27958 | +{ | |
076b876e AM |
27959 | + int locked; |
27960 | + | |
27961 | + locked = __si_write_trylock(sb); | |
b752ccd1 AM |
27962 | + if (locked) |
27963 | + si_pid_set(sb); | |
27964 | + return locked; | |
27965 | +} | |
27966 | + | |
e49829fe | 27967 | +#if 0 /* unused */ |
1facf9fc | 27968 | +static inline int si_read_trylock(struct super_block *sb, int flags) |
27969 | +{ | |
27970 | + if (au_ftest_lock(flags, FLUSH)) | |
27971 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
27972 | + return si_noflush_read_trylock(sb); | |
27973 | +} | |
e49829fe | 27974 | +#endif |
1facf9fc | 27975 | + |
b752ccd1 AM |
27976 | +static inline void si_read_unlock(struct super_block *sb) |
27977 | +{ | |
27978 | + si_pid_clr(sb); | |
27979 | + __si_read_unlock(sb); | |
27980 | +} | |
27981 | + | |
b752ccd1 | 27982 | +#if 0 /* unused */ |
1facf9fc | 27983 | +static inline int si_write_trylock(struct super_block *sb, int flags) |
27984 | +{ | |
27985 | + if (au_ftest_lock(flags, FLUSH)) | |
27986 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
27987 | + return si_noflush_write_trylock(sb); | |
27988 | +} | |
b752ccd1 AM |
27989 | +#endif |
27990 | + | |
27991 | +static inline void si_write_unlock(struct super_block *sb) | |
27992 | +{ | |
27993 | + si_pid_clr(sb); | |
27994 | + __si_write_unlock(sb); | |
27995 | +} | |
27996 | + | |
27997 | +#if 0 /* unused */ | |
27998 | +static inline void si_downgrade_lock(struct super_block *sb) | |
27999 | +{ | |
28000 | + __si_downgrade_lock(sb); | |
28001 | +} | |
28002 | +#endif | |
1facf9fc | 28003 | + |
28004 | +/* ---------------------------------------------------------------------- */ | |
28005 | + | |
28006 | +static inline aufs_bindex_t au_sbend(struct super_block *sb) | |
28007 | +{ | |
dece6358 | 28008 | + SiMustAnyLock(sb); |
1facf9fc | 28009 | + return au_sbi(sb)->si_bend; |
28010 | +} | |
28011 | + | |
28012 | +static inline unsigned int au_mntflags(struct super_block *sb) | |
28013 | +{ | |
dece6358 | 28014 | + SiMustAnyLock(sb); |
1facf9fc | 28015 | + return au_sbi(sb)->si_mntflags; |
28016 | +} | |
28017 | + | |
28018 | +static inline unsigned int au_sigen(struct super_block *sb) | |
28019 | +{ | |
dece6358 | 28020 | + SiMustAnyLock(sb); |
1facf9fc | 28021 | + return au_sbi(sb)->si_generation; |
28022 | +} | |
28023 | + | |
7f207e10 AM |
28024 | +static inline void au_ninodes_inc(struct super_block *sb) |
28025 | +{ | |
28026 | + atomic_long_inc(&au_sbi(sb)->si_ninodes); | |
28027 | +} | |
28028 | + | |
28029 | +static inline void au_ninodes_dec(struct super_block *sb) | |
28030 | +{ | |
28031 | + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes)); | |
28032 | + atomic_long_dec(&au_sbi(sb)->si_ninodes); | |
28033 | +} | |
28034 | + | |
28035 | +static inline void au_nfiles_inc(struct super_block *sb) | |
28036 | +{ | |
28037 | + atomic_long_inc(&au_sbi(sb)->si_nfiles); | |
28038 | +} | |
28039 | + | |
28040 | +static inline void au_nfiles_dec(struct super_block *sb) | |
28041 | +{ | |
28042 | + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles)); | |
28043 | + atomic_long_dec(&au_sbi(sb)->si_nfiles); | |
28044 | +} | |
28045 | + | |
1facf9fc | 28046 | +static inline struct au_branch *au_sbr(struct super_block *sb, |
28047 | + aufs_bindex_t bindex) | |
28048 | +{ | |
dece6358 | 28049 | + SiMustAnyLock(sb); |
1facf9fc | 28050 | + return au_sbi(sb)->si_branch[0 + bindex]; |
28051 | +} | |
28052 | + | |
28053 | +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid) | |
28054 | +{ | |
dece6358 | 28055 | + SiMustWriteLock(sb); |
1facf9fc | 28056 | + au_sbi(sb)->si_xino_brid = brid; |
28057 | +} | |
28058 | + | |
28059 | +static inline aufs_bindex_t au_xino_brid(struct super_block *sb) | |
28060 | +{ | |
dece6358 | 28061 | + SiMustAnyLock(sb); |
1facf9fc | 28062 | + return au_sbi(sb)->si_xino_brid; |
28063 | +} | |
28064 | + | |
28065 | +#endif /* __KERNEL__ */ | |
28066 | +#endif /* __AUFS_SUPER_H__ */ | |
7f207e10 AM |
28067 | diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c |
28068 | --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 28069 | +++ linux/fs/aufs/sysaufs.c 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 28070 | @@ -0,0 +1,104 @@ |
1facf9fc | 28071 | +/* |
523b37e3 | 28072 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 28073 | + * |
28074 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28075 | + * it under the terms of the GNU General Public License as published by | |
28076 | + * the Free Software Foundation; either version 2 of the License, or | |
28077 | + * (at your option) any later version. | |
dece6358 AM |
28078 | + * |
28079 | + * This program is distributed in the hope that it will be useful, | |
28080 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28081 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28082 | + * GNU General Public License for more details. | |
28083 | + * | |
28084 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28085 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28086 | + */ |
28087 | + | |
28088 | +/* | |
28089 | + * sysfs interface and lifetime management | |
28090 | + * they are necessary regardless sysfs is disabled. | |
28091 | + */ | |
28092 | + | |
1facf9fc | 28093 | +#include <linux/random.h> |
1facf9fc | 28094 | +#include "aufs.h" |
28095 | + | |
28096 | +unsigned long sysaufs_si_mask; | |
e49829fe | 28097 | +struct kset *sysaufs_kset; |
1facf9fc | 28098 | + |
28099 | +#define AuSiAttr(_name) { \ | |
28100 | + .attr = { .name = __stringify(_name), .mode = 0444 }, \ | |
28101 | + .show = sysaufs_si_##_name, \ | |
28102 | +} | |
28103 | + | |
28104 | +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path); | |
28105 | +struct attribute *sysaufs_si_attrs[] = { | |
28106 | + &sysaufs_si_attr_xi_path.attr, | |
28107 | + NULL, | |
28108 | +}; | |
28109 | + | |
4a4d8108 | 28110 | +static const struct sysfs_ops au_sbi_ops = { |
1facf9fc | 28111 | + .show = sysaufs_si_show |
28112 | +}; | |
28113 | + | |
28114 | +static struct kobj_type au_sbi_ktype = { | |
28115 | + .release = au_si_free, | |
28116 | + .sysfs_ops = &au_sbi_ops, | |
28117 | + .default_attrs = sysaufs_si_attrs | |
28118 | +}; | |
28119 | + | |
28120 | +/* ---------------------------------------------------------------------- */ | |
28121 | + | |
28122 | +int sysaufs_si_init(struct au_sbinfo *sbinfo) | |
28123 | +{ | |
28124 | + int err; | |
28125 | + | |
e49829fe | 28126 | + sbinfo->si_kobj.kset = sysaufs_kset; |
1facf9fc | 28127 | + /* cf. sysaufs_name() */ |
28128 | + err = kobject_init_and_add | |
e49829fe | 28129 | + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL, |
1facf9fc | 28130 | + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo)); |
28131 | + | |
28132 | + dbgaufs_si_null(sbinfo); | |
28133 | + if (!err) { | |
28134 | + err = dbgaufs_si_init(sbinfo); | |
28135 | + if (unlikely(err)) | |
28136 | + kobject_put(&sbinfo->si_kobj); | |
28137 | + } | |
28138 | + return err; | |
28139 | +} | |
28140 | + | |
28141 | +void sysaufs_fin(void) | |
28142 | +{ | |
28143 | + dbgaufs_fin(); | |
e49829fe JR |
28144 | + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
28145 | + kset_unregister(sysaufs_kset); | |
1facf9fc | 28146 | +} |
28147 | + | |
28148 | +int __init sysaufs_init(void) | |
28149 | +{ | |
28150 | + int err; | |
28151 | + | |
28152 | + do { | |
28153 | + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask)); | |
28154 | + } while (!sysaufs_si_mask); | |
28155 | + | |
4a4d8108 | 28156 | + err = -EINVAL; |
e49829fe JR |
28157 | + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj); |
28158 | + if (unlikely(!sysaufs_kset)) | |
4a4d8108 | 28159 | + goto out; |
e49829fe JR |
28160 | + err = PTR_ERR(sysaufs_kset); |
28161 | + if (IS_ERR(sysaufs_kset)) | |
1facf9fc | 28162 | + goto out; |
e49829fe | 28163 | + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
1facf9fc | 28164 | + if (unlikely(err)) { |
e49829fe | 28165 | + kset_unregister(sysaufs_kset); |
1facf9fc | 28166 | + goto out; |
28167 | + } | |
28168 | + | |
28169 | + err = dbgaufs_init(); | |
28170 | + if (unlikely(err)) | |
28171 | + sysaufs_fin(); | |
4f0767ce | 28172 | +out: |
1facf9fc | 28173 | + return err; |
28174 | +} | |
7f207e10 AM |
28175 | diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h |
28176 | --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
28177 | +++ linux/fs/aufs/sysaufs.h 2015-01-25 13:00:38.634380408 +0100 |
28178 | @@ -0,0 +1,101 @@ | |
1facf9fc | 28179 | +/* |
523b37e3 | 28180 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 28181 | + * |
28182 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28183 | + * it under the terms of the GNU General Public License as published by | |
28184 | + * the Free Software Foundation; either version 2 of the License, or | |
28185 | + * (at your option) any later version. | |
dece6358 AM |
28186 | + * |
28187 | + * This program is distributed in the hope that it will be useful, | |
28188 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28189 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28190 | + * GNU General Public License for more details. | |
28191 | + * | |
28192 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28193 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28194 | + */ |
28195 | + | |
28196 | +/* | |
28197 | + * sysfs interface and mount lifetime management | |
28198 | + */ | |
28199 | + | |
28200 | +#ifndef __SYSAUFS_H__ | |
28201 | +#define __SYSAUFS_H__ | |
28202 | + | |
28203 | +#ifdef __KERNEL__ | |
28204 | + | |
1facf9fc | 28205 | +#include <linux/sysfs.h> |
1facf9fc | 28206 | +#include "module.h" |
28207 | + | |
dece6358 AM |
28208 | +struct super_block; |
28209 | +struct au_sbinfo; | |
28210 | + | |
1facf9fc | 28211 | +struct sysaufs_si_attr { |
28212 | + struct attribute attr; | |
28213 | + int (*show)(struct seq_file *seq, struct super_block *sb); | |
28214 | +}; | |
28215 | + | |
28216 | +/* ---------------------------------------------------------------------- */ | |
28217 | + | |
28218 | +/* sysaufs.c */ | |
28219 | +extern unsigned long sysaufs_si_mask; | |
e49829fe | 28220 | +extern struct kset *sysaufs_kset; |
1facf9fc | 28221 | +extern struct attribute *sysaufs_si_attrs[]; |
28222 | +int sysaufs_si_init(struct au_sbinfo *sbinfo); | |
28223 | +int __init sysaufs_init(void); | |
28224 | +void sysaufs_fin(void); | |
28225 | + | |
28226 | +/* ---------------------------------------------------------------------- */ | |
28227 | + | |
28228 | +/* some people doesn't like to show a pointer in kernel */ | |
28229 | +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo) | |
28230 | +{ | |
28231 | + return sysaufs_si_mask ^ (unsigned long)sbinfo; | |
28232 | +} | |
28233 | + | |
28234 | +#define SysaufsSiNamePrefix "si_" | |
28235 | +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16) | |
28236 | +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name) | |
28237 | +{ | |
28238 | + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx", | |
28239 | + sysaufs_si_id(sbinfo)); | |
28240 | +} | |
28241 | + | |
28242 | +struct au_branch; | |
28243 | +#ifdef CONFIG_SYSFS | |
28244 | +/* sysfs.c */ | |
28245 | +extern struct attribute_group *sysaufs_attr_group; | |
28246 | + | |
28247 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb); | |
28248 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
28249 | + char *buf); | |
076b876e AM |
28250 | +long au_brinfo_ioctl(struct file *file, unsigned long arg); |
28251 | +#ifdef CONFIG_COMPAT | |
28252 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg); | |
28253 | +#endif | |
1facf9fc | 28254 | + |
28255 | +void sysaufs_br_init(struct au_branch *br); | |
28256 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
28257 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
28258 | + | |
28259 | +#define sysaufs_brs_init() do {} while (0) | |
28260 | + | |
28261 | +#else | |
28262 | +#define sysaufs_attr_group NULL | |
28263 | + | |
4a4d8108 | 28264 | +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb) |
c1595e42 JR |
28265 | +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj, |
28266 | + struct attribute *attr, char *buf) | |
4a4d8108 AM |
28267 | +AuStubVoid(sysaufs_br_init, struct au_branch *br) |
28268 | +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
28269 | +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) | |
1facf9fc | 28270 | + |
28271 | +static inline void sysaufs_brs_init(void) | |
28272 | +{ | |
28273 | + sysaufs_brs = 0; | |
28274 | +} | |
28275 | + | |
28276 | +#endif /* CONFIG_SYSFS */ | |
28277 | + | |
28278 | +#endif /* __KERNEL__ */ | |
28279 | +#endif /* __SYSAUFS_H__ */ | |
7f207e10 AM |
28280 | diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c |
28281 | --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 28282 | +++ linux/fs/aufs/sysfs.c 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 28283 | @@ -0,0 +1,372 @@ |
1facf9fc | 28284 | +/* |
523b37e3 | 28285 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 28286 | + * |
28287 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28288 | + * it under the terms of the GNU General Public License as published by | |
28289 | + * the Free Software Foundation; either version 2 of the License, or | |
28290 | + * (at your option) any later version. | |
dece6358 AM |
28291 | + * |
28292 | + * This program is distributed in the hope that it will be useful, | |
28293 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28294 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28295 | + * GNU General Public License for more details. | |
28296 | + * | |
28297 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28298 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28299 | + */ |
28300 | + | |
28301 | +/* | |
28302 | + * sysfs interface | |
28303 | + */ | |
28304 | + | |
076b876e | 28305 | +#include <linux/compat.h> |
1facf9fc | 28306 | +#include <linux/seq_file.h> |
1facf9fc | 28307 | +#include "aufs.h" |
28308 | + | |
4a4d8108 AM |
28309 | +#ifdef CONFIG_AUFS_FS_MODULE |
28310 | +/* this entry violates the "one line per file" policy of sysfs */ | |
28311 | +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr, | |
28312 | + char *buf) | |
28313 | +{ | |
28314 | + ssize_t err; | |
28315 | + static char *conf = | |
28316 | +/* this file is generated at compiling */ | |
28317 | +#include "conf.str" | |
28318 | + ; | |
28319 | + | |
28320 | + err = snprintf(buf, PAGE_SIZE, conf); | |
28321 | + if (unlikely(err >= PAGE_SIZE)) | |
28322 | + err = -EFBIG; | |
28323 | + return err; | |
28324 | +} | |
28325 | + | |
28326 | +static struct kobj_attribute au_config_attr = __ATTR_RO(config); | |
28327 | +#endif | |
28328 | + | |
1facf9fc | 28329 | +static struct attribute *au_attr[] = { |
4a4d8108 AM |
28330 | +#ifdef CONFIG_AUFS_FS_MODULE |
28331 | + &au_config_attr.attr, | |
28332 | +#endif | |
1facf9fc | 28333 | + NULL, /* need to NULL terminate the list of attributes */ |
28334 | +}; | |
28335 | + | |
28336 | +static struct attribute_group sysaufs_attr_group_body = { | |
28337 | + .attrs = au_attr | |
28338 | +}; | |
28339 | + | |
28340 | +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body; | |
28341 | + | |
28342 | +/* ---------------------------------------------------------------------- */ | |
28343 | + | |
28344 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb) | |
28345 | +{ | |
28346 | + int err; | |
28347 | + | |
dece6358 AM |
28348 | + SiMustAnyLock(sb); |
28349 | + | |
1facf9fc | 28350 | + err = 0; |
28351 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
28352 | + err = au_xino_path(seq, au_sbi(sb)->si_xib); | |
28353 | + seq_putc(seq, '\n'); | |
28354 | + } | |
28355 | + return err; | |
28356 | +} | |
28357 | + | |
28358 | +/* | |
28359 | + * the lifetime of branch is independent from the entry under sysfs. | |
28360 | + * sysfs handles the lifetime of the entry, and never call ->show() after it is | |
28361 | + * unlinked. | |
28362 | + */ | |
28363 | +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb, | |
392086de | 28364 | + aufs_bindex_t bindex, int idx) |
1facf9fc | 28365 | +{ |
1e00d052 | 28366 | + int err; |
1facf9fc | 28367 | + struct path path; |
28368 | + struct dentry *root; | |
28369 | + struct au_branch *br; | |
076b876e | 28370 | + au_br_perm_str_t perm; |
1facf9fc | 28371 | + |
28372 | + AuDbg("b%d\n", bindex); | |
28373 | + | |
1e00d052 | 28374 | + err = 0; |
1facf9fc | 28375 | + root = sb->s_root; |
28376 | + di_read_lock_parent(root, !AuLock_IR); | |
28377 | + br = au_sbr(sb, bindex); | |
392086de AM |
28378 | + |
28379 | + switch (idx) { | |
28380 | + case AuBrSysfs_BR: | |
28381 | + path.mnt = au_br_mnt(br); | |
28382 | + path.dentry = au_h_dptr(root, bindex); | |
28383 | + au_seq_path(seq, &path); | |
076b876e AM |
28384 | + au_optstr_br_perm(&perm, br->br_perm); |
28385 | + err = seq_printf(seq, "=%s\n", perm.a); | |
392086de AM |
28386 | + break; |
28387 | + case AuBrSysfs_BRID: | |
28388 | + err = seq_printf(seq, "%d\n", br->br_id); | |
392086de AM |
28389 | + break; |
28390 | + } | |
076b876e AM |
28391 | + di_read_unlock(root, !AuLock_IR); |
28392 | + if (err == -1) | |
28393 | + err = -E2BIG; | |
392086de | 28394 | + |
1e00d052 | 28395 | + return err; |
1facf9fc | 28396 | +} |
28397 | + | |
28398 | +/* ---------------------------------------------------------------------- */ | |
28399 | + | |
28400 | +static struct seq_file *au_seq(char *p, ssize_t len) | |
28401 | +{ | |
28402 | + struct seq_file *seq; | |
28403 | + | |
28404 | + seq = kzalloc(sizeof(*seq), GFP_NOFS); | |
28405 | + if (seq) { | |
28406 | + /* mutex_init(&seq.lock); */ | |
28407 | + seq->buf = p; | |
28408 | + seq->size = len; | |
28409 | + return seq; /* success */ | |
28410 | + } | |
28411 | + | |
28412 | + seq = ERR_PTR(-ENOMEM); | |
28413 | + return seq; | |
28414 | +} | |
28415 | + | |
392086de AM |
28416 | +#define SysaufsBr_PREFIX "br" |
28417 | +#define SysaufsBrid_PREFIX "brid" | |
1facf9fc | 28418 | + |
28419 | +/* todo: file size may exceed PAGE_SIZE */ | |
28420 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
1308ab2a | 28421 | + char *buf) |
1facf9fc | 28422 | +{ |
28423 | + ssize_t err; | |
392086de | 28424 | + int idx; |
1facf9fc | 28425 | + long l; |
28426 | + aufs_bindex_t bend; | |
28427 | + struct au_sbinfo *sbinfo; | |
28428 | + struct super_block *sb; | |
28429 | + struct seq_file *seq; | |
28430 | + char *name; | |
28431 | + struct attribute **cattr; | |
28432 | + | |
28433 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
28434 | + sb = sbinfo->si_sb; | |
1308ab2a | 28435 | + |
28436 | + /* | |
28437 | + * prevent a race condition between sysfs and aufs. | |
28438 | + * for instance, sysfs_file_read() calls sysfs_get_active_two() which | |
28439 | + * prohibits maintaining the sysfs entries. | |
28440 | + * hew we acquire read lock after sysfs_get_active_two(). | |
28441 | + * on the other hand, the remount process may maintain the sysfs/aufs | |
28442 | + * entries after acquiring write lock. | |
28443 | + * it can cause a deadlock. | |
28444 | + * simply we gave up processing read here. | |
28445 | + */ | |
28446 | + err = -EBUSY; | |
28447 | + if (unlikely(!si_noflush_read_trylock(sb))) | |
28448 | + goto out; | |
1facf9fc | 28449 | + |
28450 | + seq = au_seq(buf, PAGE_SIZE); | |
28451 | + err = PTR_ERR(seq); | |
28452 | + if (IS_ERR(seq)) | |
1308ab2a | 28453 | + goto out_unlock; |
1facf9fc | 28454 | + |
28455 | + name = (void *)attr->name; | |
28456 | + cattr = sysaufs_si_attrs; | |
28457 | + while (*cattr) { | |
28458 | + if (!strcmp(name, (*cattr)->name)) { | |
28459 | + err = container_of(*cattr, struct sysaufs_si_attr, attr) | |
28460 | + ->show(seq, sb); | |
28461 | + goto out_seq; | |
28462 | + } | |
28463 | + cattr++; | |
28464 | + } | |
28465 | + | |
392086de AM |
28466 | + if (!strncmp(name, SysaufsBrid_PREFIX, |
28467 | + sizeof(SysaufsBrid_PREFIX) - 1)) { | |
28468 | + idx = AuBrSysfs_BRID; | |
28469 | + name += sizeof(SysaufsBrid_PREFIX) - 1; | |
28470 | + } else if (!strncmp(name, SysaufsBr_PREFIX, | |
28471 | + sizeof(SysaufsBr_PREFIX) - 1)) { | |
28472 | + idx = AuBrSysfs_BR; | |
1facf9fc | 28473 | + name += sizeof(SysaufsBr_PREFIX) - 1; |
392086de AM |
28474 | + } else |
28475 | + BUG(); | |
28476 | + | |
28477 | + err = kstrtol(name, 10, &l); | |
28478 | + if (!err) { | |
28479 | + bend = au_sbend(sb); | |
28480 | + if (l <= bend) | |
28481 | + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx); | |
28482 | + else | |
28483 | + err = -ENOENT; | |
1facf9fc | 28484 | + } |
1facf9fc | 28485 | + |
4f0767ce | 28486 | +out_seq: |
1facf9fc | 28487 | + if (!err) { |
28488 | + err = seq->count; | |
28489 | + /* sysfs limit */ | |
28490 | + if (unlikely(err == PAGE_SIZE)) | |
28491 | + err = -EFBIG; | |
28492 | + } | |
28493 | + kfree(seq); | |
4f0767ce | 28494 | +out_unlock: |
1facf9fc | 28495 | + si_read_unlock(sb); |
4f0767ce | 28496 | +out: |
1facf9fc | 28497 | + return err; |
28498 | +} | |
28499 | + | |
28500 | +/* ---------------------------------------------------------------------- */ | |
28501 | + | |
076b876e AM |
28502 | +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg) |
28503 | +{ | |
28504 | + int err; | |
28505 | + int16_t brid; | |
28506 | + aufs_bindex_t bindex, bend; | |
28507 | + size_t sz; | |
28508 | + char *buf; | |
28509 | + struct seq_file *seq; | |
28510 | + struct au_branch *br; | |
28511 | + | |
28512 | + si_read_lock(sb, AuLock_FLUSH); | |
28513 | + bend = au_sbend(sb); | |
28514 | + err = bend + 1; | |
28515 | + if (!arg) | |
28516 | + goto out; | |
28517 | + | |
28518 | + err = -ENOMEM; | |
28519 | + buf = (void *)__get_free_page(GFP_NOFS); | |
28520 | + if (unlikely(!buf)) | |
28521 | + goto out; | |
28522 | + | |
28523 | + seq = au_seq(buf, PAGE_SIZE); | |
28524 | + err = PTR_ERR(seq); | |
28525 | + if (IS_ERR(seq)) | |
28526 | + goto out_buf; | |
28527 | + | |
28528 | + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path); | |
28529 | + for (bindex = 0; bindex <= bend; bindex++, arg++) { | |
28530 | + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg)); | |
28531 | + if (unlikely(err)) | |
28532 | + break; | |
28533 | + | |
28534 | + br = au_sbr(sb, bindex); | |
28535 | + brid = br->br_id; | |
28536 | + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id)); | |
28537 | + err = __put_user(brid, &arg->id); | |
28538 | + if (unlikely(err)) | |
28539 | + break; | |
28540 | + | |
28541 | + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm)); | |
28542 | + err = __put_user(br->br_perm, &arg->perm); | |
28543 | + if (unlikely(err)) | |
28544 | + break; | |
28545 | + | |
28546 | + au_seq_path(seq, &br->br_path); | |
28547 | + err = seq_putc(seq, '\0'); | |
28548 | + if (!err && seq->count <= sz) { | |
28549 | + err = copy_to_user(arg->path, seq->buf, seq->count); | |
28550 | + seq->count = 0; | |
28551 | + if (unlikely(err)) | |
28552 | + break; | |
28553 | + } else { | |
28554 | + err = -E2BIG; | |
28555 | + goto out_seq; | |
28556 | + } | |
28557 | + } | |
28558 | + if (unlikely(err)) | |
28559 | + err = -EFAULT; | |
28560 | + | |
28561 | +out_seq: | |
28562 | + kfree(seq); | |
28563 | +out_buf: | |
28564 | + free_page((unsigned long)buf); | |
28565 | +out: | |
28566 | + si_read_unlock(sb); | |
28567 | + return err; | |
28568 | +} | |
28569 | + | |
28570 | +long au_brinfo_ioctl(struct file *file, unsigned long arg) | |
28571 | +{ | |
28572 | + return au_brinfo(file->f_dentry->d_sb, (void __user *)arg); | |
28573 | +} | |
28574 | + | |
28575 | +#ifdef CONFIG_COMPAT | |
28576 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg) | |
28577 | +{ | |
28578 | + return au_brinfo(file->f_dentry->d_sb, compat_ptr(arg)); | |
28579 | +} | |
28580 | +#endif | |
28581 | + | |
28582 | +/* ---------------------------------------------------------------------- */ | |
28583 | + | |
1facf9fc | 28584 | +void sysaufs_br_init(struct au_branch *br) |
28585 | +{ | |
392086de AM |
28586 | + int i; |
28587 | + struct au_brsysfs *br_sysfs; | |
28588 | + struct attribute *attr; | |
4a4d8108 | 28589 | + |
392086de AM |
28590 | + br_sysfs = br->br_sysfs; |
28591 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28592 | + attr = &br_sysfs->attr; | |
28593 | + sysfs_attr_init(attr); | |
28594 | + attr->name = br_sysfs->name; | |
28595 | + attr->mode = S_IRUGO; | |
28596 | + br_sysfs++; | |
28597 | + } | |
1facf9fc | 28598 | +} |
28599 | + | |
28600 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
28601 | +{ | |
28602 | + struct au_branch *br; | |
28603 | + struct kobject *kobj; | |
392086de AM |
28604 | + struct au_brsysfs *br_sysfs; |
28605 | + int i; | |
1facf9fc | 28606 | + aufs_bindex_t bend; |
28607 | + | |
28608 | + dbgaufs_brs_del(sb, bindex); | |
28609 | + | |
28610 | + if (!sysaufs_brs) | |
28611 | + return; | |
28612 | + | |
28613 | + kobj = &au_sbi(sb)->si_kobj; | |
28614 | + bend = au_sbend(sb); | |
28615 | + for (; bindex <= bend; bindex++) { | |
28616 | + br = au_sbr(sb, bindex); | |
392086de AM |
28617 | + br_sysfs = br->br_sysfs; |
28618 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28619 | + sysfs_remove_file(kobj, &br_sysfs->attr); | |
28620 | + br_sysfs++; | |
28621 | + } | |
1facf9fc | 28622 | + } |
28623 | +} | |
28624 | + | |
28625 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
28626 | +{ | |
392086de | 28627 | + int err, i; |
1facf9fc | 28628 | + aufs_bindex_t bend; |
28629 | + struct kobject *kobj; | |
28630 | + struct au_branch *br; | |
392086de | 28631 | + struct au_brsysfs *br_sysfs; |
1facf9fc | 28632 | + |
28633 | + dbgaufs_brs_add(sb, bindex); | |
28634 | + | |
28635 | + if (!sysaufs_brs) | |
28636 | + return; | |
28637 | + | |
28638 | + kobj = &au_sbi(sb)->si_kobj; | |
28639 | + bend = au_sbend(sb); | |
28640 | + for (; bindex <= bend; bindex++) { | |
28641 | + br = au_sbr(sb, bindex); | |
392086de AM |
28642 | + br_sysfs = br->br_sysfs; |
28643 | + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name), | |
28644 | + SysaufsBr_PREFIX "%d", bindex); | |
28645 | + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name), | |
28646 | + SysaufsBrid_PREFIX "%d", bindex); | |
28647 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
28648 | + err = sysfs_create_file(kobj, &br_sysfs->attr); | |
28649 | + if (unlikely(err)) | |
28650 | + pr_warn("failed %s under sysfs(%d)\n", | |
28651 | + br_sysfs->name, err); | |
28652 | + br_sysfs++; | |
28653 | + } | |
1facf9fc | 28654 | + } |
28655 | +} | |
7f207e10 AM |
28656 | diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c |
28657 | --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 28658 | +++ linux/fs/aufs/sysrq.c 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 28659 | @@ -0,0 +1,157 @@ |
1facf9fc | 28660 | +/* |
523b37e3 | 28661 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 28662 | + * |
28663 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28664 | + * it under the terms of the GNU General Public License as published by | |
28665 | + * the Free Software Foundation; either version 2 of the License, or | |
28666 | + * (at your option) any later version. | |
dece6358 AM |
28667 | + * |
28668 | + * This program is distributed in the hope that it will be useful, | |
28669 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28670 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28671 | + * GNU General Public License for more details. | |
28672 | + * | |
28673 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28674 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28675 | + */ |
28676 | + | |
28677 | +/* | |
28678 | + * magic sysrq hanlder | |
28679 | + */ | |
28680 | + | |
1facf9fc | 28681 | +/* #include <linux/sysrq.h> */ |
027c5e7a | 28682 | +#include <linux/writeback.h> |
1facf9fc | 28683 | +#include "aufs.h" |
28684 | + | |
28685 | +/* ---------------------------------------------------------------------- */ | |
28686 | + | |
28687 | +static void sysrq_sb(struct super_block *sb) | |
28688 | +{ | |
28689 | + char *plevel; | |
28690 | + struct au_sbinfo *sbinfo; | |
28691 | + struct file *file; | |
523b37e3 AM |
28692 | + struct au_sphlhead *files; |
28693 | + struct au_finfo *finfo; | |
1facf9fc | 28694 | + |
28695 | + plevel = au_plevel; | |
28696 | + au_plevel = KERN_WARNING; | |
1facf9fc | 28697 | + |
4a4d8108 | 28698 | + /* since we define pr_fmt, call printk directly */ |
c06a8ce3 AM |
28699 | +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str) |
28700 | + | |
28701 | + sbinfo = au_sbi(sb); | |
4a4d8108 | 28702 | + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo)); |
c06a8ce3 | 28703 | + pr("superblock\n"); |
1facf9fc | 28704 | + au_dpri_sb(sb); |
027c5e7a AM |
28705 | + |
28706 | +#if 0 | |
c06a8ce3 | 28707 | + pr("root dentry\n"); |
1facf9fc | 28708 | + au_dpri_dentry(sb->s_root); |
c06a8ce3 | 28709 | + pr("root inode\n"); |
1facf9fc | 28710 | + au_dpri_inode(sb->s_root->d_inode); |
027c5e7a AM |
28711 | +#endif |
28712 | + | |
1facf9fc | 28713 | +#if 0 |
027c5e7a AM |
28714 | + do { |
28715 | + int err, i, j, ndentry; | |
28716 | + struct au_dcsub_pages dpages; | |
28717 | + struct au_dpage *dpage; | |
28718 | + | |
28719 | + err = au_dpages_init(&dpages, GFP_ATOMIC); | |
28720 | + if (unlikely(err)) | |
28721 | + break; | |
28722 | + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL); | |
28723 | + if (!err) | |
28724 | + for (i = 0; i < dpages.ndpage; i++) { | |
28725 | + dpage = dpages.dpages + i; | |
28726 | + ndentry = dpage->ndentry; | |
28727 | + for (j = 0; j < ndentry; j++) | |
28728 | + au_dpri_dentry(dpage->dentries[j]); | |
28729 | + } | |
28730 | + au_dpages_free(&dpages); | |
28731 | + } while (0); | |
28732 | +#endif | |
28733 | + | |
28734 | +#if 1 | |
28735 | + { | |
28736 | + struct inode *i; | |
076b876e | 28737 | + |
c06a8ce3 | 28738 | + pr("isolated inode\n"); |
2cbb1c4b JR |
28739 | + spin_lock(&inode_sb_list_lock); |
28740 | + list_for_each_entry(i, &sb->s_inodes, i_sb_list) { | |
28741 | + spin_lock(&i->i_lock); | |
b4510431 | 28742 | + if (1 || hlist_empty(&i->i_dentry)) |
027c5e7a | 28743 | + au_dpri_inode(i); |
2cbb1c4b JR |
28744 | + spin_unlock(&i->i_lock); |
28745 | + } | |
28746 | + spin_unlock(&inode_sb_list_lock); | |
027c5e7a | 28747 | + } |
1facf9fc | 28748 | +#endif |
c06a8ce3 | 28749 | + pr("files\n"); |
523b37e3 AM |
28750 | + files = &au_sbi(sb)->si_files; |
28751 | + spin_lock(&files->spin); | |
28752 | + hlist_for_each_entry(finfo, &files->head, fi_hlist) { | |
4a4d8108 | 28753 | + umode_t mode; |
076b876e | 28754 | + |
523b37e3 | 28755 | + file = finfo->fi_file; |
c06a8ce3 | 28756 | + mode = file_inode(file)->i_mode; |
38d290e6 | 28757 | + if (!special_file(mode)) |
1facf9fc | 28758 | + au_dpri_file(file); |
523b37e3 AM |
28759 | + } |
28760 | + spin_unlock(&files->spin); | |
c06a8ce3 | 28761 | + pr("done\n"); |
1facf9fc | 28762 | + |
c06a8ce3 | 28763 | +#undef pr |
1facf9fc | 28764 | + au_plevel = plevel; |
1facf9fc | 28765 | +} |
28766 | + | |
28767 | +/* ---------------------------------------------------------------------- */ | |
28768 | + | |
28769 | +/* module parameter */ | |
28770 | +static char *aufs_sysrq_key = "a"; | |
28771 | +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO); | |
28772 | +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME); | |
28773 | + | |
0c5527e5 | 28774 | +static void au_sysrq(int key __maybe_unused) |
1facf9fc | 28775 | +{ |
1facf9fc | 28776 | + struct au_sbinfo *sbinfo; |
28777 | + | |
027c5e7a | 28778 | + lockdep_off(); |
53392da6 | 28779 | + au_sbilist_lock(); |
e49829fe | 28780 | + list_for_each_entry(sbinfo, &au_sbilist.head, si_list) |
1facf9fc | 28781 | + sysrq_sb(sbinfo->si_sb); |
53392da6 | 28782 | + au_sbilist_unlock(); |
027c5e7a | 28783 | + lockdep_on(); |
1facf9fc | 28784 | +} |
28785 | + | |
28786 | +static struct sysrq_key_op au_sysrq_op = { | |
28787 | + .handler = au_sysrq, | |
28788 | + .help_msg = "Aufs", | |
28789 | + .action_msg = "Aufs", | |
28790 | + .enable_mask = SYSRQ_ENABLE_DUMP | |
28791 | +}; | |
28792 | + | |
28793 | +/* ---------------------------------------------------------------------- */ | |
28794 | + | |
28795 | +int __init au_sysrq_init(void) | |
28796 | +{ | |
28797 | + int err; | |
28798 | + char key; | |
28799 | + | |
28800 | + err = -1; | |
28801 | + key = *aufs_sysrq_key; | |
28802 | + if ('a' <= key && key <= 'z') | |
28803 | + err = register_sysrq_key(key, &au_sysrq_op); | |
28804 | + if (unlikely(err)) | |
4a4d8108 | 28805 | + pr_err("err %d, sysrq=%c\n", err, key); |
1facf9fc | 28806 | + return err; |
28807 | +} | |
28808 | + | |
28809 | +void au_sysrq_fin(void) | |
28810 | +{ | |
28811 | + int err; | |
076b876e | 28812 | + |
1facf9fc | 28813 | + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op); |
28814 | + if (unlikely(err)) | |
4a4d8108 | 28815 | + pr_err("err %d (ignored)\n", err); |
1facf9fc | 28816 | +} |
7f207e10 AM |
28817 | diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c |
28818 | --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 28819 | +++ linux/fs/aufs/vdir.c 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 28820 | @@ -0,0 +1,889 @@ |
1facf9fc | 28821 | +/* |
523b37e3 | 28822 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 28823 | + * |
28824 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28825 | + * it under the terms of the GNU General Public License as published by | |
28826 | + * the Free Software Foundation; either version 2 of the License, or | |
28827 | + * (at your option) any later version. | |
dece6358 AM |
28828 | + * |
28829 | + * This program is distributed in the hope that it will be useful, | |
28830 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28831 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28832 | + * GNU General Public License for more details. | |
28833 | + * | |
28834 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28835 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28836 | + */ |
28837 | + | |
28838 | +/* | |
28839 | + * virtual or vertical directory | |
28840 | + */ | |
28841 | + | |
28842 | +#include "aufs.h" | |
28843 | + | |
dece6358 | 28844 | +static unsigned int calc_size(int nlen) |
1facf9fc | 28845 | +{ |
dece6358 | 28846 | + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t)); |
1facf9fc | 28847 | +} |
28848 | + | |
28849 | +static int set_deblk_end(union au_vdir_deblk_p *p, | |
28850 | + union au_vdir_deblk_p *deblk_end) | |
28851 | +{ | |
28852 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) { | |
28853 | + p->de->de_str.len = 0; | |
28854 | + /* smp_mb(); */ | |
28855 | + return 0; | |
28856 | + } | |
28857 | + return -1; /* error */ | |
28858 | +} | |
28859 | + | |
28860 | +/* returns true or false */ | |
28861 | +static int is_deblk_end(union au_vdir_deblk_p *p, | |
28862 | + union au_vdir_deblk_p *deblk_end) | |
28863 | +{ | |
28864 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) | |
28865 | + return !p->de->de_str.len; | |
28866 | + return 1; | |
28867 | +} | |
28868 | + | |
28869 | +static unsigned char *last_deblk(struct au_vdir *vdir) | |
28870 | +{ | |
28871 | + return vdir->vd_deblk[vdir->vd_nblk - 1]; | |
28872 | +} | |
28873 | + | |
28874 | +/* ---------------------------------------------------------------------- */ | |
28875 | + | |
1308ab2a | 28876 | +/* estimate the apropriate size for name hash table */ |
28877 | +unsigned int au_rdhash_est(loff_t sz) | |
28878 | +{ | |
28879 | + unsigned int n; | |
28880 | + | |
28881 | + n = UINT_MAX; | |
28882 | + sz >>= 10; | |
28883 | + if (sz < n) | |
28884 | + n = sz; | |
28885 | + if (sz < AUFS_RDHASH_DEF) | |
28886 | + n = AUFS_RDHASH_DEF; | |
4a4d8108 | 28887 | + /* pr_info("n %u\n", n); */ |
1308ab2a | 28888 | + return n; |
28889 | +} | |
28890 | + | |
1facf9fc | 28891 | +/* |
28892 | + * the allocated memory has to be freed by | |
dece6358 | 28893 | + * au_nhash_wh_free() or au_nhash_de_free(). |
1facf9fc | 28894 | + */ |
dece6358 | 28895 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp) |
1facf9fc | 28896 | +{ |
1facf9fc | 28897 | + struct hlist_head *head; |
dece6358 | 28898 | + unsigned int u; |
076b876e | 28899 | + size_t sz; |
1facf9fc | 28900 | + |
076b876e AM |
28901 | + sz = sizeof(*nhash->nh_head) * num_hash; |
28902 | + head = kmalloc(sz, gfp); | |
dece6358 AM |
28903 | + if (head) { |
28904 | + nhash->nh_num = num_hash; | |
28905 | + nhash->nh_head = head; | |
28906 | + for (u = 0; u < num_hash; u++) | |
1facf9fc | 28907 | + INIT_HLIST_HEAD(head++); |
dece6358 | 28908 | + return 0; /* success */ |
1facf9fc | 28909 | + } |
1facf9fc | 28910 | + |
dece6358 | 28911 | + return -ENOMEM; |
1facf9fc | 28912 | +} |
28913 | + | |
dece6358 AM |
28914 | +static void nhash_count(struct hlist_head *head) |
28915 | +{ | |
28916 | +#if 0 | |
28917 | + unsigned long n; | |
28918 | + struct hlist_node *pos; | |
28919 | + | |
28920 | + n = 0; | |
28921 | + hlist_for_each(pos, head) | |
28922 | + n++; | |
4a4d8108 | 28923 | + pr_info("%lu\n", n); |
dece6358 AM |
28924 | +#endif |
28925 | +} | |
28926 | + | |
28927 | +static void au_nhash_wh_do_free(struct hlist_head *head) | |
1facf9fc | 28928 | +{ |
c06a8ce3 AM |
28929 | + struct au_vdir_wh *pos; |
28930 | + struct hlist_node *node; | |
1facf9fc | 28931 | + |
c06a8ce3 AM |
28932 | + hlist_for_each_entry_safe(pos, node, head, wh_hash) |
28933 | + kfree(pos); | |
1facf9fc | 28934 | +} |
28935 | + | |
dece6358 | 28936 | +static void au_nhash_de_do_free(struct hlist_head *head) |
1facf9fc | 28937 | +{ |
c06a8ce3 AM |
28938 | + struct au_vdir_dehstr *pos; |
28939 | + struct hlist_node *node; | |
1facf9fc | 28940 | + |
c06a8ce3 AM |
28941 | + hlist_for_each_entry_safe(pos, node, head, hash) |
28942 | + au_cache_free_vdir_dehstr(pos); | |
1facf9fc | 28943 | +} |
28944 | + | |
dece6358 AM |
28945 | +static void au_nhash_do_free(struct au_nhash *nhash, |
28946 | + void (*free)(struct hlist_head *head)) | |
1facf9fc | 28947 | +{ |
1308ab2a | 28948 | + unsigned int n; |
1facf9fc | 28949 | + struct hlist_head *head; |
1facf9fc | 28950 | + |
dece6358 | 28951 | + n = nhash->nh_num; |
1308ab2a | 28952 | + if (!n) |
28953 | + return; | |
28954 | + | |
dece6358 | 28955 | + head = nhash->nh_head; |
1308ab2a | 28956 | + while (n-- > 0) { |
dece6358 AM |
28957 | + nhash_count(head); |
28958 | + free(head++); | |
1facf9fc | 28959 | + } |
dece6358 | 28960 | + kfree(nhash->nh_head); |
1facf9fc | 28961 | +} |
28962 | + | |
dece6358 | 28963 | +void au_nhash_wh_free(struct au_nhash *whlist) |
1facf9fc | 28964 | +{ |
dece6358 AM |
28965 | + au_nhash_do_free(whlist, au_nhash_wh_do_free); |
28966 | +} | |
1facf9fc | 28967 | + |
dece6358 AM |
28968 | +static void au_nhash_de_free(struct au_nhash *delist) |
28969 | +{ | |
28970 | + au_nhash_do_free(delist, au_nhash_de_do_free); | |
1facf9fc | 28971 | +} |
28972 | + | |
28973 | +/* ---------------------------------------------------------------------- */ | |
28974 | + | |
28975 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, | |
28976 | + int limit) | |
28977 | +{ | |
28978 | + int num; | |
28979 | + unsigned int u, n; | |
28980 | + struct hlist_head *head; | |
c06a8ce3 | 28981 | + struct au_vdir_wh *pos; |
1facf9fc | 28982 | + |
28983 | + num = 0; | |
28984 | + n = whlist->nh_num; | |
28985 | + head = whlist->nh_head; | |
1308ab2a | 28986 | + for (u = 0; u < n; u++, head++) |
c06a8ce3 AM |
28987 | + hlist_for_each_entry(pos, head, wh_hash) |
28988 | + if (pos->wh_bindex == btgt && ++num > limit) | |
1facf9fc | 28989 | + return 1; |
1facf9fc | 28990 | + return 0; |
28991 | +} | |
28992 | + | |
28993 | +static struct hlist_head *au_name_hash(struct au_nhash *nhash, | |
dece6358 | 28994 | + unsigned char *name, |
1facf9fc | 28995 | + unsigned int len) |
28996 | +{ | |
dece6358 AM |
28997 | + unsigned int v; |
28998 | + /* const unsigned int magic_bit = 12; */ | |
28999 | + | |
1308ab2a | 29000 | + AuDebugOn(!nhash->nh_num || !nhash->nh_head); |
29001 | + | |
dece6358 AM |
29002 | + v = 0; |
29003 | + while (len--) | |
29004 | + v += *name++; | |
29005 | + /* v = hash_long(v, magic_bit); */ | |
29006 | + v %= nhash->nh_num; | |
29007 | + return nhash->nh_head + v; | |
29008 | +} | |
29009 | + | |
29010 | +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name, | |
29011 | + int nlen) | |
29012 | +{ | |
29013 | + return str->len == nlen && !memcmp(str->name, name, nlen); | |
1facf9fc | 29014 | +} |
29015 | + | |
29016 | +/* returns found or not */ | |
dece6358 | 29017 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen) |
1facf9fc | 29018 | +{ |
29019 | + struct hlist_head *head; | |
c06a8ce3 | 29020 | + struct au_vdir_wh *pos; |
1facf9fc | 29021 | + struct au_vdir_destr *str; |
29022 | + | |
dece6358 | 29023 | + head = au_name_hash(whlist, name, nlen); |
c06a8ce3 AM |
29024 | + hlist_for_each_entry(pos, head, wh_hash) { |
29025 | + str = &pos->wh_str; | |
1facf9fc | 29026 | + AuDbg("%.*s\n", str->len, str->name); |
dece6358 AM |
29027 | + if (au_nhash_test_name(str, name, nlen)) |
29028 | + return 1; | |
29029 | + } | |
29030 | + return 0; | |
29031 | +} | |
29032 | + | |
29033 | +/* returns found(true) or not */ | |
29034 | +static int test_known(struct au_nhash *delist, char *name, int nlen) | |
29035 | +{ | |
29036 | + struct hlist_head *head; | |
c06a8ce3 | 29037 | + struct au_vdir_dehstr *pos; |
dece6358 AM |
29038 | + struct au_vdir_destr *str; |
29039 | + | |
29040 | + head = au_name_hash(delist, name, nlen); | |
c06a8ce3 AM |
29041 | + hlist_for_each_entry(pos, head, hash) { |
29042 | + str = pos->str; | |
dece6358 AM |
29043 | + AuDbg("%.*s\n", str->len, str->name); |
29044 | + if (au_nhash_test_name(str, name, nlen)) | |
1facf9fc | 29045 | + return 1; |
29046 | + } | |
29047 | + return 0; | |
29048 | +} | |
29049 | + | |
dece6358 AM |
29050 | +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino, |
29051 | + unsigned char d_type) | |
29052 | +{ | |
29053 | +#ifdef CONFIG_AUFS_SHWH | |
29054 | + wh->wh_ino = ino; | |
29055 | + wh->wh_type = d_type; | |
29056 | +#endif | |
29057 | +} | |
29058 | + | |
29059 | +/* ---------------------------------------------------------------------- */ | |
29060 | + | |
29061 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
29062 | + unsigned int d_type, aufs_bindex_t bindex, | |
29063 | + unsigned char shwh) | |
1facf9fc | 29064 | +{ |
29065 | + int err; | |
29066 | + struct au_vdir_destr *str; | |
29067 | + struct au_vdir_wh *wh; | |
29068 | + | |
dece6358 | 29069 | + AuDbg("%.*s\n", nlen, name); |
1308ab2a | 29070 | + AuDebugOn(!whlist->nh_num || !whlist->nh_head); |
29071 | + | |
1facf9fc | 29072 | + err = -ENOMEM; |
dece6358 | 29073 | + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS); |
1facf9fc | 29074 | + if (unlikely(!wh)) |
29075 | + goto out; | |
29076 | + | |
29077 | + err = 0; | |
29078 | + wh->wh_bindex = bindex; | |
dece6358 AM |
29079 | + if (shwh) |
29080 | + au_shwh_init_wh(wh, ino, d_type); | |
1facf9fc | 29081 | + str = &wh->wh_str; |
dece6358 AM |
29082 | + str->len = nlen; |
29083 | + memcpy(str->name, name, nlen); | |
29084 | + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen)); | |
1facf9fc | 29085 | + /* smp_mb(); */ |
29086 | + | |
4f0767ce | 29087 | +out: |
1facf9fc | 29088 | + return err; |
29089 | +} | |
29090 | + | |
1facf9fc | 29091 | +static int append_deblk(struct au_vdir *vdir) |
29092 | +{ | |
29093 | + int err; | |
dece6358 | 29094 | + unsigned long ul; |
1facf9fc | 29095 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; |
29096 | + union au_vdir_deblk_p p, deblk_end; | |
29097 | + unsigned char **o; | |
29098 | + | |
29099 | + err = -ENOMEM; | |
dece6358 AM |
29100 | + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1), |
29101 | + GFP_NOFS); | |
1facf9fc | 29102 | + if (unlikely(!o)) |
29103 | + goto out; | |
29104 | + | |
29105 | + vdir->vd_deblk = o; | |
29106 | + p.deblk = kmalloc(deblk_sz, GFP_NOFS); | |
29107 | + if (p.deblk) { | |
29108 | + ul = vdir->vd_nblk++; | |
29109 | + vdir->vd_deblk[ul] = p.deblk; | |
29110 | + vdir->vd_last.ul = ul; | |
29111 | + vdir->vd_last.p.deblk = p.deblk; | |
29112 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29113 | + err = set_deblk_end(&p, &deblk_end); | |
29114 | + } | |
29115 | + | |
4f0767ce | 29116 | +out: |
1facf9fc | 29117 | + return err; |
29118 | +} | |
29119 | + | |
dece6358 AM |
29120 | +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino, |
29121 | + unsigned int d_type, struct au_nhash *delist) | |
29122 | +{ | |
29123 | + int err; | |
29124 | + unsigned int sz; | |
29125 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; | |
29126 | + union au_vdir_deblk_p p, *room, deblk_end; | |
29127 | + struct au_vdir_dehstr *dehstr; | |
29128 | + | |
29129 | + p.deblk = last_deblk(vdir); | |
29130 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29131 | + room = &vdir->vd_last.p; | |
29132 | + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk | |
29133 | + || !is_deblk_end(room, &deblk_end)); | |
29134 | + | |
29135 | + sz = calc_size(nlen); | |
29136 | + if (unlikely(sz > deblk_end.deblk - room->deblk)) { | |
29137 | + err = append_deblk(vdir); | |
29138 | + if (unlikely(err)) | |
29139 | + goto out; | |
29140 | + | |
29141 | + p.deblk = last_deblk(vdir); | |
29142 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29143 | + /* smp_mb(); */ | |
29144 | + AuDebugOn(room->deblk != p.deblk); | |
29145 | + } | |
29146 | + | |
29147 | + err = -ENOMEM; | |
4a4d8108 | 29148 | + dehstr = au_cache_alloc_vdir_dehstr(); |
dece6358 AM |
29149 | + if (unlikely(!dehstr)) |
29150 | + goto out; | |
29151 | + | |
29152 | + dehstr->str = &room->de->de_str; | |
29153 | + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen)); | |
29154 | + room->de->de_ino = ino; | |
29155 | + room->de->de_type = d_type; | |
29156 | + room->de->de_str.len = nlen; | |
29157 | + memcpy(room->de->de_str.name, name, nlen); | |
29158 | + | |
29159 | + err = 0; | |
29160 | + room->deblk += sz; | |
29161 | + if (unlikely(set_deblk_end(room, &deblk_end))) | |
29162 | + err = append_deblk(vdir); | |
29163 | + /* smp_mb(); */ | |
29164 | + | |
4f0767ce | 29165 | +out: |
dece6358 AM |
29166 | + return err; |
29167 | +} | |
29168 | + | |
29169 | +/* ---------------------------------------------------------------------- */ | |
29170 | + | |
29171 | +void au_vdir_free(struct au_vdir *vdir) | |
29172 | +{ | |
29173 | + unsigned char **deblk; | |
29174 | + | |
29175 | + deblk = vdir->vd_deblk; | |
29176 | + while (vdir->vd_nblk--) | |
29177 | + kfree(*deblk++); | |
29178 | + kfree(vdir->vd_deblk); | |
29179 | + au_cache_free_vdir(vdir); | |
29180 | +} | |
29181 | + | |
1308ab2a | 29182 | +static struct au_vdir *alloc_vdir(struct file *file) |
1facf9fc | 29183 | +{ |
29184 | + struct au_vdir *vdir; | |
1308ab2a | 29185 | + struct super_block *sb; |
1facf9fc | 29186 | + int err; |
29187 | + | |
1308ab2a | 29188 | + sb = file->f_dentry->d_sb; |
dece6358 AM |
29189 | + SiMustAnyLock(sb); |
29190 | + | |
1facf9fc | 29191 | + err = -ENOMEM; |
29192 | + vdir = au_cache_alloc_vdir(); | |
29193 | + if (unlikely(!vdir)) | |
29194 | + goto out; | |
29195 | + | |
29196 | + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS); | |
29197 | + if (unlikely(!vdir->vd_deblk)) | |
29198 | + goto out_free; | |
29199 | + | |
29200 | + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk; | |
1308ab2a | 29201 | + if (!vdir->vd_deblk_sz) { |
29202 | + /* estimate the apropriate size for deblk */ | |
29203 | + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL); | |
4a4d8108 | 29204 | + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */ |
1308ab2a | 29205 | + } |
1facf9fc | 29206 | + vdir->vd_nblk = 0; |
29207 | + vdir->vd_version = 0; | |
29208 | + vdir->vd_jiffy = 0; | |
29209 | + err = append_deblk(vdir); | |
29210 | + if (!err) | |
29211 | + return vdir; /* success */ | |
29212 | + | |
29213 | + kfree(vdir->vd_deblk); | |
29214 | + | |
4f0767ce | 29215 | +out_free: |
1facf9fc | 29216 | + au_cache_free_vdir(vdir); |
4f0767ce | 29217 | +out: |
1facf9fc | 29218 | + vdir = ERR_PTR(err); |
29219 | + return vdir; | |
29220 | +} | |
29221 | + | |
29222 | +static int reinit_vdir(struct au_vdir *vdir) | |
29223 | +{ | |
29224 | + int err; | |
29225 | + union au_vdir_deblk_p p, deblk_end; | |
29226 | + | |
29227 | + while (vdir->vd_nblk > 1) { | |
29228 | + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]); | |
29229 | + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */ | |
29230 | + vdir->vd_nblk--; | |
29231 | + } | |
29232 | + p.deblk = vdir->vd_deblk[0]; | |
29233 | + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz; | |
29234 | + err = set_deblk_end(&p, &deblk_end); | |
29235 | + /* keep vd_dblk_sz */ | |
29236 | + vdir->vd_last.ul = 0; | |
29237 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
29238 | + vdir->vd_version = 0; | |
29239 | + vdir->vd_jiffy = 0; | |
29240 | + /* smp_mb(); */ | |
29241 | + return err; | |
29242 | +} | |
29243 | + | |
29244 | +/* ---------------------------------------------------------------------- */ | |
29245 | + | |
1facf9fc | 29246 | +#define AuFillVdir_CALLED 1 |
29247 | +#define AuFillVdir_WHABLE (1 << 1) | |
dece6358 | 29248 | +#define AuFillVdir_SHWH (1 << 2) |
1facf9fc | 29249 | +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name) |
7f207e10 AM |
29250 | +#define au_fset_fillvdir(flags, name) \ |
29251 | + do { (flags) |= AuFillVdir_##name; } while (0) | |
29252 | +#define au_fclr_fillvdir(flags, name) \ | |
29253 | + do { (flags) &= ~AuFillVdir_##name; } while (0) | |
1facf9fc | 29254 | + |
dece6358 AM |
29255 | +#ifndef CONFIG_AUFS_SHWH |
29256 | +#undef AuFillVdir_SHWH | |
29257 | +#define AuFillVdir_SHWH 0 | |
29258 | +#endif | |
29259 | + | |
1facf9fc | 29260 | +struct fillvdir_arg { |
392086de | 29261 | + struct dir_context ctx; |
1facf9fc | 29262 | + struct file *file; |
29263 | + struct au_vdir *vdir; | |
dece6358 AM |
29264 | + struct au_nhash delist; |
29265 | + struct au_nhash whlist; | |
1facf9fc | 29266 | + aufs_bindex_t bindex; |
29267 | + unsigned int flags; | |
29268 | + int err; | |
29269 | +}; | |
29270 | + | |
392086de | 29271 | +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen, |
1facf9fc | 29272 | + loff_t offset __maybe_unused, u64 h_ino, |
29273 | + unsigned int d_type) | |
29274 | +{ | |
392086de | 29275 | + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx); |
1facf9fc | 29276 | + char *name = (void *)__name; |
29277 | + struct super_block *sb; | |
1facf9fc | 29278 | + ino_t ino; |
dece6358 | 29279 | + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH); |
1facf9fc | 29280 | + |
1facf9fc | 29281 | + arg->err = 0; |
dece6358 | 29282 | + sb = arg->file->f_dentry->d_sb; |
1facf9fc | 29283 | + au_fset_fillvdir(arg->flags, CALLED); |
29284 | + /* smp_mb(); */ | |
dece6358 | 29285 | + if (nlen <= AUFS_WH_PFX_LEN |
1facf9fc | 29286 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { |
dece6358 AM |
29287 | + if (test_known(&arg->delist, name, nlen) |
29288 | + || au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
29289 | + goto out; /* already exists or whiteouted */ | |
1facf9fc | 29290 | + |
29291 | + sb = arg->file->f_dentry->d_sb; | |
dece6358 | 29292 | + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino); |
4a4d8108 AM |
29293 | + if (!arg->err) { |
29294 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) | |
29295 | + d_type = DT_UNKNOWN; | |
dece6358 AM |
29296 | + arg->err = append_de(arg->vdir, name, nlen, ino, |
29297 | + d_type, &arg->delist); | |
4a4d8108 | 29298 | + } |
1facf9fc | 29299 | + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) { |
29300 | + name += AUFS_WH_PFX_LEN; | |
dece6358 AM |
29301 | + nlen -= AUFS_WH_PFX_LEN; |
29302 | + if (au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
29303 | + goto out; /* already whiteouted */ | |
1facf9fc | 29304 | + |
dece6358 AM |
29305 | + if (shwh) |
29306 | + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type, | |
29307 | + &ino); | |
4a4d8108 AM |
29308 | + if (!arg->err) { |
29309 | + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN) | |
29310 | + d_type = DT_UNKNOWN; | |
1facf9fc | 29311 | + arg->err = au_nhash_append_wh |
dece6358 AM |
29312 | + (&arg->whlist, name, nlen, ino, d_type, |
29313 | + arg->bindex, shwh); | |
4a4d8108 | 29314 | + } |
1facf9fc | 29315 | + } |
29316 | + | |
4f0767ce | 29317 | +out: |
1facf9fc | 29318 | + if (!arg->err) |
29319 | + arg->vdir->vd_jiffy = jiffies; | |
29320 | + /* smp_mb(); */ | |
29321 | + AuTraceErr(arg->err); | |
29322 | + return arg->err; | |
29323 | +} | |
29324 | + | |
dece6358 AM |
29325 | +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir, |
29326 | + struct au_nhash *whlist, struct au_nhash *delist) | |
29327 | +{ | |
29328 | +#ifdef CONFIG_AUFS_SHWH | |
29329 | + int err; | |
29330 | + unsigned int nh, u; | |
29331 | + struct hlist_head *head; | |
c06a8ce3 AM |
29332 | + struct au_vdir_wh *pos; |
29333 | + struct hlist_node *n; | |
dece6358 AM |
29334 | + char *p, *o; |
29335 | + struct au_vdir_destr *destr; | |
29336 | + | |
29337 | + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH)); | |
29338 | + | |
29339 | + err = -ENOMEM; | |
537831f9 | 29340 | + o = p = (void *)__get_free_page(GFP_NOFS); |
dece6358 AM |
29341 | + if (unlikely(!p)) |
29342 | + goto out; | |
29343 | + | |
29344 | + err = 0; | |
29345 | + nh = whlist->nh_num; | |
29346 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
29347 | + p += AUFS_WH_PFX_LEN; | |
29348 | + for (u = 0; u < nh; u++) { | |
29349 | + head = whlist->nh_head + u; | |
c06a8ce3 AM |
29350 | + hlist_for_each_entry_safe(pos, n, head, wh_hash) { |
29351 | + destr = &pos->wh_str; | |
dece6358 AM |
29352 | + memcpy(p, destr->name, destr->len); |
29353 | + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN, | |
c06a8ce3 | 29354 | + pos->wh_ino, pos->wh_type, delist); |
dece6358 AM |
29355 | + if (unlikely(err)) |
29356 | + break; | |
29357 | + } | |
29358 | + } | |
29359 | + | |
537831f9 | 29360 | + free_page((unsigned long)o); |
dece6358 | 29361 | + |
4f0767ce | 29362 | +out: |
dece6358 AM |
29363 | + AuTraceErr(err); |
29364 | + return err; | |
29365 | +#else | |
29366 | + return 0; | |
29367 | +#endif | |
29368 | +} | |
29369 | + | |
1facf9fc | 29370 | +static int au_do_read_vdir(struct fillvdir_arg *arg) |
29371 | +{ | |
29372 | + int err; | |
dece6358 | 29373 | + unsigned int rdhash; |
1facf9fc | 29374 | + loff_t offset; |
dece6358 AM |
29375 | + aufs_bindex_t bend, bindex, bstart; |
29376 | + unsigned char shwh; | |
1facf9fc | 29377 | + struct file *hf, *file; |
29378 | + struct super_block *sb; | |
29379 | + | |
1facf9fc | 29380 | + file = arg->file; |
29381 | + sb = file->f_dentry->d_sb; | |
dece6358 AM |
29382 | + SiMustAnyLock(sb); |
29383 | + | |
29384 | + rdhash = au_sbi(sb)->si_rdhash; | |
1308ab2a | 29385 | + if (!rdhash) |
29386 | + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL)); | |
dece6358 AM |
29387 | + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS); |
29388 | + if (unlikely(err)) | |
1facf9fc | 29389 | + goto out; |
dece6358 AM |
29390 | + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS); |
29391 | + if (unlikely(err)) | |
1facf9fc | 29392 | + goto out_delist; |
29393 | + | |
29394 | + err = 0; | |
29395 | + arg->flags = 0; | |
dece6358 AM |
29396 | + shwh = 0; |
29397 | + if (au_opt_test(au_mntflags(sb), SHWH)) { | |
29398 | + shwh = 1; | |
29399 | + au_fset_fillvdir(arg->flags, SHWH); | |
29400 | + } | |
29401 | + bstart = au_fbstart(file); | |
4a4d8108 | 29402 | + bend = au_fbend_dir(file); |
dece6358 | 29403 | + for (bindex = bstart; !err && bindex <= bend; bindex++) { |
4a4d8108 | 29404 | + hf = au_hf_dir(file, bindex); |
1facf9fc | 29405 | + if (!hf) |
29406 | + continue; | |
29407 | + | |
29408 | + offset = vfsub_llseek(hf, 0, SEEK_SET); | |
29409 | + err = offset; | |
29410 | + if (unlikely(offset)) | |
29411 | + break; | |
29412 | + | |
29413 | + arg->bindex = bindex; | |
29414 | + au_fclr_fillvdir(arg->flags, WHABLE); | |
dece6358 AM |
29415 | + if (shwh |
29416 | + || (bindex != bend | |
29417 | + && au_br_whable(au_sbr_perm(sb, bindex)))) | |
1facf9fc | 29418 | + au_fset_fillvdir(arg->flags, WHABLE); |
29419 | + do { | |
29420 | + arg->err = 0; | |
29421 | + au_fclr_fillvdir(arg->flags, CALLED); | |
29422 | + /* smp_mb(); */ | |
392086de | 29423 | + err = vfsub_iterate_dir(hf, &arg->ctx); |
1facf9fc | 29424 | + if (err >= 0) |
29425 | + err = arg->err; | |
29426 | + } while (!err && au_ftest_fillvdir(arg->flags, CALLED)); | |
392086de AM |
29427 | + |
29428 | + /* | |
29429 | + * dir_relax() may be good for concurrency, but aufs should not | |
29430 | + * use it since it will cause a lockdep problem. | |
29431 | + */ | |
1facf9fc | 29432 | + } |
dece6358 AM |
29433 | + |
29434 | + if (!err && shwh) | |
29435 | + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist); | |
29436 | + | |
29437 | + au_nhash_wh_free(&arg->whlist); | |
1facf9fc | 29438 | + |
4f0767ce | 29439 | +out_delist: |
dece6358 | 29440 | + au_nhash_de_free(&arg->delist); |
4f0767ce | 29441 | +out: |
1facf9fc | 29442 | + return err; |
29443 | +} | |
29444 | + | |
29445 | +static int read_vdir(struct file *file, int may_read) | |
29446 | +{ | |
29447 | + int err; | |
29448 | + unsigned long expire; | |
29449 | + unsigned char do_read; | |
392086de AM |
29450 | + struct fillvdir_arg arg = { |
29451 | + .ctx = { | |
29452 | + .actor = au_diractor(fillvdir) | |
29453 | + } | |
29454 | + }; | |
1facf9fc | 29455 | + struct inode *inode; |
29456 | + struct au_vdir *vdir, *allocated; | |
29457 | + | |
29458 | + err = 0; | |
c06a8ce3 | 29459 | + inode = file_inode(file); |
1facf9fc | 29460 | + IMustLock(inode); |
dece6358 AM |
29461 | + SiMustAnyLock(inode->i_sb); |
29462 | + | |
1facf9fc | 29463 | + allocated = NULL; |
29464 | + do_read = 0; | |
29465 | + expire = au_sbi(inode->i_sb)->si_rdcache; | |
29466 | + vdir = au_ivdir(inode); | |
29467 | + if (!vdir) { | |
29468 | + do_read = 1; | |
1308ab2a | 29469 | + vdir = alloc_vdir(file); |
1facf9fc | 29470 | + err = PTR_ERR(vdir); |
29471 | + if (IS_ERR(vdir)) | |
29472 | + goto out; | |
29473 | + err = 0; | |
29474 | + allocated = vdir; | |
29475 | + } else if (may_read | |
29476 | + && (inode->i_version != vdir->vd_version | |
29477 | + || time_after(jiffies, vdir->vd_jiffy + expire))) { | |
29478 | + do_read = 1; | |
29479 | + err = reinit_vdir(vdir); | |
29480 | + if (unlikely(err)) | |
29481 | + goto out; | |
29482 | + } | |
29483 | + | |
29484 | + if (!do_read) | |
29485 | + return 0; /* success */ | |
29486 | + | |
29487 | + arg.file = file; | |
29488 | + arg.vdir = vdir; | |
29489 | + err = au_do_read_vdir(&arg); | |
29490 | + if (!err) { | |
392086de | 29491 | + /* file->f_pos = 0; */ /* todo: ctx->pos? */ |
1facf9fc | 29492 | + vdir->vd_version = inode->i_version; |
29493 | + vdir->vd_last.ul = 0; | |
29494 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
29495 | + if (allocated) | |
29496 | + au_set_ivdir(inode, allocated); | |
29497 | + } else if (allocated) | |
29498 | + au_vdir_free(allocated); | |
29499 | + | |
4f0767ce | 29500 | +out: |
1facf9fc | 29501 | + return err; |
29502 | +} | |
29503 | + | |
29504 | +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src) | |
29505 | +{ | |
29506 | + int err, rerr; | |
29507 | + unsigned long ul, n; | |
29508 | + const unsigned int deblk_sz = src->vd_deblk_sz; | |
29509 | + | |
29510 | + AuDebugOn(tgt->vd_nblk != 1); | |
29511 | + | |
29512 | + err = -ENOMEM; | |
29513 | + if (tgt->vd_nblk < src->vd_nblk) { | |
29514 | + unsigned char **p; | |
29515 | + | |
dece6358 AM |
29516 | + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk, |
29517 | + GFP_NOFS); | |
1facf9fc | 29518 | + if (unlikely(!p)) |
29519 | + goto out; | |
29520 | + tgt->vd_deblk = p; | |
29521 | + } | |
29522 | + | |
1308ab2a | 29523 | + if (tgt->vd_deblk_sz != deblk_sz) { |
29524 | + unsigned char *p; | |
29525 | + | |
29526 | + tgt->vd_deblk_sz = deblk_sz; | |
29527 | + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS); | |
29528 | + if (unlikely(!p)) | |
29529 | + goto out; | |
29530 | + tgt->vd_deblk[0] = p; | |
29531 | + } | |
1facf9fc | 29532 | + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz); |
1facf9fc | 29533 | + tgt->vd_version = src->vd_version; |
29534 | + tgt->vd_jiffy = src->vd_jiffy; | |
29535 | + | |
29536 | + n = src->vd_nblk; | |
29537 | + for (ul = 1; ul < n; ul++) { | |
dece6358 AM |
29538 | + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz, |
29539 | + GFP_NOFS); | |
29540 | + if (unlikely(!tgt->vd_deblk[ul])) | |
1facf9fc | 29541 | + goto out; |
1308ab2a | 29542 | + tgt->vd_nblk++; |
1facf9fc | 29543 | + } |
1308ab2a | 29544 | + tgt->vd_nblk = n; |
29545 | + tgt->vd_last.ul = tgt->vd_last.ul; | |
29546 | + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul]; | |
29547 | + tgt->vd_last.p.deblk += src->vd_last.p.deblk | |
29548 | + - src->vd_deblk[src->vd_last.ul]; | |
1facf9fc | 29549 | + /* smp_mb(); */ |
29550 | + return 0; /* success */ | |
29551 | + | |
4f0767ce | 29552 | +out: |
1facf9fc | 29553 | + rerr = reinit_vdir(tgt); |
29554 | + BUG_ON(rerr); | |
29555 | + return err; | |
29556 | +} | |
29557 | + | |
29558 | +int au_vdir_init(struct file *file) | |
29559 | +{ | |
29560 | + int err; | |
29561 | + struct inode *inode; | |
29562 | + struct au_vdir *vdir_cache, *allocated; | |
29563 | + | |
392086de | 29564 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 29565 | + err = read_vdir(file, !file->f_pos); |
29566 | + if (unlikely(err)) | |
29567 | + goto out; | |
29568 | + | |
29569 | + allocated = NULL; | |
29570 | + vdir_cache = au_fvdir_cache(file); | |
29571 | + if (!vdir_cache) { | |
1308ab2a | 29572 | + vdir_cache = alloc_vdir(file); |
1facf9fc | 29573 | + err = PTR_ERR(vdir_cache); |
29574 | + if (IS_ERR(vdir_cache)) | |
29575 | + goto out; | |
29576 | + allocated = vdir_cache; | |
29577 | + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) { | |
392086de | 29578 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 29579 | + err = reinit_vdir(vdir_cache); |
29580 | + if (unlikely(err)) | |
29581 | + goto out; | |
29582 | + } else | |
29583 | + return 0; /* success */ | |
29584 | + | |
c06a8ce3 | 29585 | + inode = file_inode(file); |
1facf9fc | 29586 | + err = copy_vdir(vdir_cache, au_ivdir(inode)); |
29587 | + if (!err) { | |
29588 | + file->f_version = inode->i_version; | |
29589 | + if (allocated) | |
29590 | + au_set_fvdir_cache(file, allocated); | |
29591 | + } else if (allocated) | |
29592 | + au_vdir_free(allocated); | |
29593 | + | |
4f0767ce | 29594 | +out: |
1facf9fc | 29595 | + return err; |
29596 | +} | |
29597 | + | |
29598 | +static loff_t calc_offset(struct au_vdir *vdir) | |
29599 | +{ | |
29600 | + loff_t offset; | |
29601 | + union au_vdir_deblk_p p; | |
29602 | + | |
29603 | + p.deblk = vdir->vd_deblk[vdir->vd_last.ul]; | |
29604 | + offset = vdir->vd_last.p.deblk - p.deblk; | |
29605 | + offset += vdir->vd_deblk_sz * vdir->vd_last.ul; | |
29606 | + return offset; | |
29607 | +} | |
29608 | + | |
29609 | +/* returns true or false */ | |
392086de | 29610 | +static int seek_vdir(struct file *file, struct dir_context *ctx) |
1facf9fc | 29611 | +{ |
29612 | + int valid; | |
29613 | + unsigned int deblk_sz; | |
29614 | + unsigned long ul, n; | |
29615 | + loff_t offset; | |
29616 | + union au_vdir_deblk_p p, deblk_end; | |
29617 | + struct au_vdir *vdir_cache; | |
29618 | + | |
29619 | + valid = 1; | |
29620 | + vdir_cache = au_fvdir_cache(file); | |
29621 | + offset = calc_offset(vdir_cache); | |
29622 | + AuDbg("offset %lld\n", offset); | |
392086de | 29623 | + if (ctx->pos == offset) |
1facf9fc | 29624 | + goto out; |
29625 | + | |
29626 | + vdir_cache->vd_last.ul = 0; | |
29627 | + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0]; | |
392086de | 29628 | + if (!ctx->pos) |
1facf9fc | 29629 | + goto out; |
29630 | + | |
29631 | + valid = 0; | |
29632 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
392086de | 29633 | + ul = div64_u64(ctx->pos, deblk_sz); |
1facf9fc | 29634 | + AuDbg("ul %lu\n", ul); |
29635 | + if (ul >= vdir_cache->vd_nblk) | |
29636 | + goto out; | |
29637 | + | |
29638 | + n = vdir_cache->vd_nblk; | |
29639 | + for (; ul < n; ul++) { | |
29640 | + p.deblk = vdir_cache->vd_deblk[ul]; | |
29641 | + deblk_end.deblk = p.deblk + deblk_sz; | |
29642 | + offset = ul; | |
29643 | + offset *= deblk_sz; | |
392086de | 29644 | + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) { |
1facf9fc | 29645 | + unsigned int l; |
29646 | + | |
29647 | + l = calc_size(p.de->de_str.len); | |
29648 | + offset += l; | |
29649 | + p.deblk += l; | |
29650 | + } | |
29651 | + if (!is_deblk_end(&p, &deblk_end)) { | |
29652 | + valid = 1; | |
29653 | + vdir_cache->vd_last.ul = ul; | |
29654 | + vdir_cache->vd_last.p = p; | |
29655 | + break; | |
29656 | + } | |
29657 | + } | |
29658 | + | |
4f0767ce | 29659 | +out: |
1facf9fc | 29660 | + /* smp_mb(); */ |
29661 | + AuTraceErr(!valid); | |
29662 | + return valid; | |
29663 | +} | |
29664 | + | |
392086de | 29665 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx) |
1facf9fc | 29666 | +{ |
1facf9fc | 29667 | + unsigned int l, deblk_sz; |
29668 | + union au_vdir_deblk_p deblk_end; | |
29669 | + struct au_vdir *vdir_cache; | |
29670 | + struct au_vdir_de *de; | |
29671 | + | |
29672 | + vdir_cache = au_fvdir_cache(file); | |
392086de | 29673 | + if (!seek_vdir(file, ctx)) |
1facf9fc | 29674 | + return 0; |
29675 | + | |
29676 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
29677 | + while (1) { | |
29678 | + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
29679 | + deblk_end.deblk += deblk_sz; | |
29680 | + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) { | |
29681 | + de = vdir_cache->vd_last.p.de; | |
29682 | + AuDbg("%.*s, off%lld, i%lu, dt%d\n", | |
392086de | 29683 | + de->de_str.len, de->de_str.name, ctx->pos, |
1facf9fc | 29684 | + (unsigned long)de->de_ino, de->de_type); |
392086de AM |
29685 | + if (unlikely(!dir_emit(ctx, de->de_str.name, |
29686 | + de->de_str.len, de->de_ino, | |
29687 | + de->de_type))) { | |
1facf9fc | 29688 | + /* todo: ignore the error caused by udba? */ |
29689 | + /* return err; */ | |
29690 | + return 0; | |
29691 | + } | |
29692 | + | |
29693 | + l = calc_size(de->de_str.len); | |
29694 | + vdir_cache->vd_last.p.deblk += l; | |
392086de | 29695 | + ctx->pos += l; |
1facf9fc | 29696 | + } |
29697 | + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) { | |
29698 | + vdir_cache->vd_last.ul++; | |
29699 | + vdir_cache->vd_last.p.deblk | |
29700 | + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
392086de | 29701 | + ctx->pos = deblk_sz * vdir_cache->vd_last.ul; |
1facf9fc | 29702 | + continue; |
29703 | + } | |
29704 | + break; | |
29705 | + } | |
29706 | + | |
29707 | + /* smp_mb(); */ | |
29708 | + return 0; | |
29709 | +} | |
7f207e10 AM |
29710 | diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c |
29711 | --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
29712 | +++ linux/fs/aufs/vfsub.c 2015-01-25 13:00:38.634380408 +0100 |
29713 | @@ -0,0 +1,796 @@ | |
1facf9fc | 29714 | +/* |
523b37e3 | 29715 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 29716 | + * |
29717 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29718 | + * it under the terms of the GNU General Public License as published by | |
29719 | + * the Free Software Foundation; either version 2 of the License, or | |
29720 | + * (at your option) any later version. | |
dece6358 AM |
29721 | + * |
29722 | + * This program is distributed in the hope that it will be useful, | |
29723 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29724 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29725 | + * GNU General Public License for more details. | |
29726 | + * | |
29727 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29728 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29729 | + */ |
29730 | + | |
29731 | +/* | |
29732 | + * sub-routines for VFS | |
29733 | + */ | |
29734 | + | |
1308ab2a | 29735 | +#include <linux/ima.h> |
dece6358 AM |
29736 | +#include <linux/namei.h> |
29737 | +#include <linux/security.h> | |
29738 | +#include <linux/splice.h> | |
1facf9fc | 29739 | +#include "aufs.h" |
29740 | + | |
29741 | +int vfsub_update_h_iattr(struct path *h_path, int *did) | |
29742 | +{ | |
29743 | + int err; | |
29744 | + struct kstat st; | |
29745 | + struct super_block *h_sb; | |
29746 | + | |
29747 | + /* for remote fs, leave work for its getattr or d_revalidate */ | |
29748 | + /* for bad i_attr fs, handle them in aufs_getattr() */ | |
29749 | + /* still some fs may acquire i_mutex. we need to skip them */ | |
29750 | + err = 0; | |
29751 | + if (!did) | |
29752 | + did = &err; | |
29753 | + h_sb = h_path->dentry->d_sb; | |
29754 | + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb)); | |
29755 | + if (*did) | |
c06a8ce3 | 29756 | + err = vfs_getattr(h_path, &st); |
1facf9fc | 29757 | + |
29758 | + return err; | |
29759 | +} | |
29760 | + | |
29761 | +/* ---------------------------------------------------------------------- */ | |
29762 | + | |
4a4d8108 | 29763 | +struct file *vfsub_dentry_open(struct path *path, int flags) |
1308ab2a | 29764 | +{ |
29765 | + struct file *file; | |
29766 | + | |
b4510431 | 29767 | + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */, |
7f207e10 | 29768 | + current_cred()); |
2cbb1c4b JR |
29769 | + if (!IS_ERR_OR_NULL(file) |
29770 | + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | |
29771 | + i_readcount_inc(path->dentry->d_inode); | |
4a4d8108 | 29772 | + |
1308ab2a | 29773 | + return file; |
29774 | +} | |
29775 | + | |
1facf9fc | 29776 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode) |
29777 | +{ | |
29778 | + struct file *file; | |
29779 | + | |
2cbb1c4b | 29780 | + lockdep_off(); |
7f207e10 | 29781 | + file = filp_open(path, |
2cbb1c4b | 29782 | + oflags /* | __FMODE_NONOTIFY */, |
7f207e10 | 29783 | + mode); |
2cbb1c4b | 29784 | + lockdep_on(); |
1facf9fc | 29785 | + if (IS_ERR(file)) |
29786 | + goto out; | |
29787 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
29788 | + | |
4f0767ce | 29789 | +out: |
1facf9fc | 29790 | + return file; |
29791 | +} | |
29792 | + | |
29793 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path) | |
29794 | +{ | |
29795 | + int err; | |
29796 | + | |
1facf9fc | 29797 | + err = kern_path(name, flags, path); |
1facf9fc | 29798 | + if (!err && path->dentry->d_inode) |
29799 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ | |
29800 | + return err; | |
29801 | +} | |
29802 | + | |
29803 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, | |
29804 | + int len) | |
29805 | +{ | |
29806 | + struct path path = { | |
29807 | + .mnt = NULL | |
29808 | + }; | |
29809 | + | |
1308ab2a | 29810 | + /* VFS checks it too, but by WARN_ON_ONCE() */ |
1facf9fc | 29811 | + IMustLock(parent->d_inode); |
29812 | + | |
29813 | + path.dentry = lookup_one_len(name, parent, len); | |
29814 | + if (IS_ERR(path.dentry)) | |
29815 | + goto out; | |
29816 | + if (path.dentry->d_inode) | |
29817 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ | |
29818 | + | |
4f0767ce | 29819 | +out: |
4a4d8108 | 29820 | + AuTraceErrPtr(path.dentry); |
1facf9fc | 29821 | + return path.dentry; |
29822 | +} | |
29823 | + | |
b4510431 | 29824 | +void vfsub_call_lkup_one(void *args) |
2cbb1c4b | 29825 | +{ |
b4510431 AM |
29826 | + struct vfsub_lkup_one_args *a = args; |
29827 | + *a->errp = vfsub_lkup_one(a->name, a->parent); | |
2cbb1c4b JR |
29828 | +} |
29829 | + | |
1facf9fc | 29830 | +/* ---------------------------------------------------------------------- */ |
29831 | + | |
29832 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
29833 | + struct dentry *d2, struct au_hinode *hdir2) | |
29834 | +{ | |
29835 | + struct dentry *d; | |
29836 | + | |
2cbb1c4b | 29837 | + lockdep_off(); |
1facf9fc | 29838 | + d = lock_rename(d1, d2); |
2cbb1c4b | 29839 | + lockdep_on(); |
4a4d8108 | 29840 | + au_hn_suspend(hdir1); |
1facf9fc | 29841 | + if (hdir1 != hdir2) |
4a4d8108 | 29842 | + au_hn_suspend(hdir2); |
1facf9fc | 29843 | + |
29844 | + return d; | |
29845 | +} | |
29846 | + | |
29847 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
29848 | + struct dentry *d2, struct au_hinode *hdir2) | |
29849 | +{ | |
4a4d8108 | 29850 | + au_hn_resume(hdir1); |
1facf9fc | 29851 | + if (hdir1 != hdir2) |
4a4d8108 | 29852 | + au_hn_resume(hdir2); |
2cbb1c4b | 29853 | + lockdep_off(); |
1facf9fc | 29854 | + unlock_rename(d1, d2); |
2cbb1c4b | 29855 | + lockdep_on(); |
1facf9fc | 29856 | +} |
29857 | + | |
29858 | +/* ---------------------------------------------------------------------- */ | |
29859 | + | |
b4510431 | 29860 | +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl) |
1facf9fc | 29861 | +{ |
29862 | + int err; | |
29863 | + struct dentry *d; | |
29864 | + | |
29865 | + IMustLock(dir); | |
29866 | + | |
29867 | + d = path->dentry; | |
29868 | + path->dentry = d->d_parent; | |
b752ccd1 | 29869 | + err = security_path_mknod(path, d, mode, 0); |
1facf9fc | 29870 | + path->dentry = d; |
29871 | + if (unlikely(err)) | |
29872 | + goto out; | |
29873 | + | |
c1595e42 | 29874 | + lockdep_off(); |
b4510431 | 29875 | + err = vfs_create(dir, path->dentry, mode, want_excl); |
c1595e42 | 29876 | + lockdep_on(); |
1facf9fc | 29877 | + if (!err) { |
29878 | + struct path tmp = *path; | |
29879 | + int did; | |
29880 | + | |
29881 | + vfsub_update_h_iattr(&tmp, &did); | |
29882 | + if (did) { | |
29883 | + tmp.dentry = path->dentry->d_parent; | |
29884 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
29885 | + } | |
29886 | + /*ignore*/ | |
29887 | + } | |
29888 | + | |
4f0767ce | 29889 | +out: |
1facf9fc | 29890 | + return err; |
29891 | +} | |
29892 | + | |
29893 | +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname) | |
29894 | +{ | |
29895 | + int err; | |
29896 | + struct dentry *d; | |
29897 | + | |
29898 | + IMustLock(dir); | |
29899 | + | |
29900 | + d = path->dentry; | |
29901 | + path->dentry = d->d_parent; | |
b752ccd1 | 29902 | + err = security_path_symlink(path, d, symname); |
1facf9fc | 29903 | + path->dentry = d; |
29904 | + if (unlikely(err)) | |
29905 | + goto out; | |
29906 | + | |
c1595e42 | 29907 | + lockdep_off(); |
1facf9fc | 29908 | + err = vfs_symlink(dir, path->dentry, symname); |
c1595e42 | 29909 | + lockdep_on(); |
1facf9fc | 29910 | + if (!err) { |
29911 | + struct path tmp = *path; | |
29912 | + int did; | |
29913 | + | |
29914 | + vfsub_update_h_iattr(&tmp, &did); | |
29915 | + if (did) { | |
29916 | + tmp.dentry = path->dentry->d_parent; | |
29917 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
29918 | + } | |
29919 | + /*ignore*/ | |
29920 | + } | |
29921 | + | |
4f0767ce | 29922 | +out: |
1facf9fc | 29923 | + return err; |
29924 | +} | |
29925 | + | |
29926 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev) | |
29927 | +{ | |
29928 | + int err; | |
29929 | + struct dentry *d; | |
29930 | + | |
29931 | + IMustLock(dir); | |
29932 | + | |
29933 | + d = path->dentry; | |
29934 | + path->dentry = d->d_parent; | |
027c5e7a | 29935 | + err = security_path_mknod(path, d, mode, new_encode_dev(dev)); |
1facf9fc | 29936 | + path->dentry = d; |
29937 | + if (unlikely(err)) | |
29938 | + goto out; | |
29939 | + | |
c1595e42 | 29940 | + lockdep_off(); |
1facf9fc | 29941 | + err = vfs_mknod(dir, path->dentry, mode, dev); |
c1595e42 | 29942 | + lockdep_on(); |
1facf9fc | 29943 | + if (!err) { |
29944 | + struct path tmp = *path; | |
29945 | + int did; | |
29946 | + | |
29947 | + vfsub_update_h_iattr(&tmp, &did); | |
29948 | + if (did) { | |
29949 | + tmp.dentry = path->dentry->d_parent; | |
29950 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
29951 | + } | |
29952 | + /*ignore*/ | |
29953 | + } | |
29954 | + | |
4f0767ce | 29955 | +out: |
1facf9fc | 29956 | + return err; |
29957 | +} | |
29958 | + | |
29959 | +static int au_test_nlink(struct inode *inode) | |
29960 | +{ | |
29961 | + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */ | |
29962 | + | |
29963 | + if (!au_test_fs_no_limit_nlink(inode->i_sb) | |
29964 | + || inode->i_nlink < link_max) | |
29965 | + return 0; | |
29966 | + return -EMLINK; | |
29967 | +} | |
29968 | + | |
523b37e3 AM |
29969 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path, |
29970 | + struct inode **delegated_inode) | |
1facf9fc | 29971 | +{ |
29972 | + int err; | |
29973 | + struct dentry *d; | |
29974 | + | |
29975 | + IMustLock(dir); | |
29976 | + | |
29977 | + err = au_test_nlink(src_dentry->d_inode); | |
29978 | + if (unlikely(err)) | |
29979 | + return err; | |
29980 | + | |
b4510431 | 29981 | + /* we don't call may_linkat() */ |
1facf9fc | 29982 | + d = path->dentry; |
29983 | + path->dentry = d->d_parent; | |
b752ccd1 | 29984 | + err = security_path_link(src_dentry, path, d); |
1facf9fc | 29985 | + path->dentry = d; |
29986 | + if (unlikely(err)) | |
29987 | + goto out; | |
29988 | + | |
2cbb1c4b | 29989 | + lockdep_off(); |
523b37e3 | 29990 | + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode); |
2cbb1c4b | 29991 | + lockdep_on(); |
1facf9fc | 29992 | + if (!err) { |
29993 | + struct path tmp = *path; | |
29994 | + int did; | |
29995 | + | |
29996 | + /* fuse has different memory inode for the same inumber */ | |
29997 | + vfsub_update_h_iattr(&tmp, &did); | |
29998 | + if (did) { | |
29999 | + tmp.dentry = path->dentry->d_parent; | |
30000 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30001 | + tmp.dentry = src_dentry; | |
30002 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30003 | + } | |
30004 | + /*ignore*/ | |
30005 | + } | |
30006 | + | |
4f0767ce | 30007 | +out: |
1facf9fc | 30008 | + return err; |
30009 | +} | |
30010 | + | |
30011 | +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry, | |
523b37e3 AM |
30012 | + struct inode *dir, struct path *path, |
30013 | + struct inode **delegated_inode) | |
1facf9fc | 30014 | +{ |
30015 | + int err; | |
30016 | + struct path tmp = { | |
30017 | + .mnt = path->mnt | |
30018 | + }; | |
30019 | + struct dentry *d; | |
30020 | + | |
30021 | + IMustLock(dir); | |
30022 | + IMustLock(src_dir); | |
30023 | + | |
30024 | + d = path->dentry; | |
30025 | + path->dentry = d->d_parent; | |
30026 | + tmp.dentry = src_dentry->d_parent; | |
38d290e6 | 30027 | + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0); |
1facf9fc | 30028 | + path->dentry = d; |
30029 | + if (unlikely(err)) | |
30030 | + goto out; | |
30031 | + | |
2cbb1c4b | 30032 | + lockdep_off(); |
523b37e3 | 30033 | + err = vfs_rename(src_dir, src_dentry, dir, path->dentry, |
38d290e6 | 30034 | + delegated_inode, /*flags*/0); |
2cbb1c4b | 30035 | + lockdep_on(); |
1facf9fc | 30036 | + if (!err) { |
30037 | + int did; | |
30038 | + | |
30039 | + tmp.dentry = d->d_parent; | |
30040 | + vfsub_update_h_iattr(&tmp, &did); | |
30041 | + if (did) { | |
30042 | + tmp.dentry = src_dentry; | |
30043 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30044 | + tmp.dentry = src_dentry->d_parent; | |
30045 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30046 | + } | |
30047 | + /*ignore*/ | |
30048 | + } | |
30049 | + | |
4f0767ce | 30050 | +out: |
1facf9fc | 30051 | + return err; |
30052 | +} | |
30053 | + | |
30054 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode) | |
30055 | +{ | |
30056 | + int err; | |
30057 | + struct dentry *d; | |
30058 | + | |
30059 | + IMustLock(dir); | |
30060 | + | |
30061 | + d = path->dentry; | |
30062 | + path->dentry = d->d_parent; | |
b752ccd1 | 30063 | + err = security_path_mkdir(path, d, mode); |
1facf9fc | 30064 | + path->dentry = d; |
30065 | + if (unlikely(err)) | |
30066 | + goto out; | |
30067 | + | |
c1595e42 | 30068 | + lockdep_off(); |
1facf9fc | 30069 | + err = vfs_mkdir(dir, path->dentry, mode); |
c1595e42 | 30070 | + lockdep_on(); |
1facf9fc | 30071 | + if (!err) { |
30072 | + struct path tmp = *path; | |
30073 | + int did; | |
30074 | + | |
30075 | + vfsub_update_h_iattr(&tmp, &did); | |
30076 | + if (did) { | |
30077 | + tmp.dentry = path->dentry->d_parent; | |
30078 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
30079 | + } | |
30080 | + /*ignore*/ | |
30081 | + } | |
30082 | + | |
4f0767ce | 30083 | +out: |
1facf9fc | 30084 | + return err; |
30085 | +} | |
30086 | + | |
30087 | +int vfsub_rmdir(struct inode *dir, struct path *path) | |
30088 | +{ | |
30089 | + int err; | |
30090 | + struct dentry *d; | |
30091 | + | |
30092 | + IMustLock(dir); | |
30093 | + | |
30094 | + d = path->dentry; | |
30095 | + path->dentry = d->d_parent; | |
b752ccd1 | 30096 | + err = security_path_rmdir(path, d); |
1facf9fc | 30097 | + path->dentry = d; |
30098 | + if (unlikely(err)) | |
30099 | + goto out; | |
30100 | + | |
2cbb1c4b | 30101 | + lockdep_off(); |
1facf9fc | 30102 | + err = vfs_rmdir(dir, path->dentry); |
2cbb1c4b | 30103 | + lockdep_on(); |
1facf9fc | 30104 | + if (!err) { |
30105 | + struct path tmp = { | |
30106 | + .dentry = path->dentry->d_parent, | |
30107 | + .mnt = path->mnt | |
30108 | + }; | |
30109 | + | |
30110 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
30111 | + } | |
30112 | + | |
4f0767ce | 30113 | +out: |
1facf9fc | 30114 | + return err; |
30115 | +} | |
30116 | + | |
30117 | +/* ---------------------------------------------------------------------- */ | |
30118 | + | |
9dbd164d | 30119 | +/* todo: support mmap_sem? */ |
1facf9fc | 30120 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, |
30121 | + loff_t *ppos) | |
30122 | +{ | |
30123 | + ssize_t err; | |
30124 | + | |
2cbb1c4b | 30125 | + lockdep_off(); |
1facf9fc | 30126 | + err = vfs_read(file, ubuf, count, ppos); |
2cbb1c4b | 30127 | + lockdep_on(); |
1facf9fc | 30128 | + if (err >= 0) |
30129 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30130 | + return err; | |
30131 | +} | |
30132 | + | |
30133 | +/* todo: kernel_read()? */ | |
30134 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
30135 | + loff_t *ppos) | |
30136 | +{ | |
30137 | + ssize_t err; | |
30138 | + mm_segment_t oldfs; | |
b752ccd1 AM |
30139 | + union { |
30140 | + void *k; | |
30141 | + char __user *u; | |
30142 | + } buf; | |
1facf9fc | 30143 | + |
b752ccd1 | 30144 | + buf.k = kbuf; |
1facf9fc | 30145 | + oldfs = get_fs(); |
30146 | + set_fs(KERNEL_DS); | |
b752ccd1 | 30147 | + err = vfsub_read_u(file, buf.u, count, ppos); |
1facf9fc | 30148 | + set_fs(oldfs); |
30149 | + return err; | |
30150 | +} | |
30151 | + | |
30152 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
30153 | + loff_t *ppos) | |
30154 | +{ | |
30155 | + ssize_t err; | |
30156 | + | |
2cbb1c4b | 30157 | + lockdep_off(); |
1facf9fc | 30158 | + err = vfs_write(file, ubuf, count, ppos); |
2cbb1c4b | 30159 | + lockdep_on(); |
1facf9fc | 30160 | + if (err >= 0) |
30161 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30162 | + return err; | |
30163 | +} | |
30164 | + | |
30165 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos) | |
30166 | +{ | |
30167 | + ssize_t err; | |
30168 | + mm_segment_t oldfs; | |
b752ccd1 AM |
30169 | + union { |
30170 | + void *k; | |
30171 | + const char __user *u; | |
30172 | + } buf; | |
1facf9fc | 30173 | + |
b752ccd1 | 30174 | + buf.k = kbuf; |
1facf9fc | 30175 | + oldfs = get_fs(); |
30176 | + set_fs(KERNEL_DS); | |
b752ccd1 | 30177 | + err = vfsub_write_u(file, buf.u, count, ppos); |
1facf9fc | 30178 | + set_fs(oldfs); |
30179 | + return err; | |
30180 | +} | |
30181 | + | |
4a4d8108 AM |
30182 | +int vfsub_flush(struct file *file, fl_owner_t id) |
30183 | +{ | |
30184 | + int err; | |
30185 | + | |
30186 | + err = 0; | |
523b37e3 | 30187 | + if (file->f_op->flush) { |
2cbb1c4b JR |
30188 | + if (!au_test_nfs(file->f_dentry->d_sb)) |
30189 | + err = file->f_op->flush(file, id); | |
30190 | + else { | |
30191 | + lockdep_off(); | |
30192 | + err = file->f_op->flush(file, id); | |
30193 | + lockdep_on(); | |
30194 | + } | |
4a4d8108 AM |
30195 | + if (!err) |
30196 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); | |
30197 | + /*ignore*/ | |
30198 | + } | |
30199 | + return err; | |
30200 | +} | |
30201 | + | |
392086de | 30202 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx) |
1facf9fc | 30203 | +{ |
30204 | + int err; | |
30205 | + | |
523b37e3 | 30206 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 30207 | + |
2cbb1c4b | 30208 | + lockdep_off(); |
392086de | 30209 | + err = iterate_dir(file, ctx); |
2cbb1c4b | 30210 | + lockdep_on(); |
1facf9fc | 30211 | + if (err >= 0) |
30212 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
30213 | + return err; | |
30214 | +} | |
30215 | + | |
30216 | +long vfsub_splice_to(struct file *in, loff_t *ppos, | |
30217 | + struct pipe_inode_info *pipe, size_t len, | |
30218 | + unsigned int flags) | |
30219 | +{ | |
30220 | + long err; | |
30221 | + | |
2cbb1c4b | 30222 | + lockdep_off(); |
0fc653ad | 30223 | + err = do_splice_to(in, ppos, pipe, len, flags); |
2cbb1c4b | 30224 | + lockdep_on(); |
4a4d8108 | 30225 | + file_accessed(in); |
1facf9fc | 30226 | + if (err >= 0) |
30227 | + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/ | |
30228 | + return err; | |
30229 | +} | |
30230 | + | |
30231 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
30232 | + loff_t *ppos, size_t len, unsigned int flags) | |
30233 | +{ | |
30234 | + long err; | |
30235 | + | |
2cbb1c4b | 30236 | + lockdep_off(); |
0fc653ad | 30237 | + err = do_splice_from(pipe, out, ppos, len, flags); |
2cbb1c4b | 30238 | + lockdep_on(); |
1facf9fc | 30239 | + if (err >= 0) |
30240 | + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/ | |
30241 | + return err; | |
30242 | +} | |
30243 | + | |
53392da6 AM |
30244 | +int vfsub_fsync(struct file *file, struct path *path, int datasync) |
30245 | +{ | |
30246 | + int err; | |
30247 | + | |
30248 | + /* file can be NULL */ | |
30249 | + lockdep_off(); | |
30250 | + err = vfs_fsync(file, datasync); | |
30251 | + lockdep_on(); | |
30252 | + if (!err) { | |
30253 | + if (!path) { | |
30254 | + AuDebugOn(!file); | |
30255 | + path = &file->f_path; | |
30256 | + } | |
30257 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ | |
30258 | + } | |
30259 | + return err; | |
30260 | +} | |
30261 | + | |
1facf9fc | 30262 | +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */ |
30263 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, | |
30264 | + struct file *h_file) | |
30265 | +{ | |
30266 | + int err; | |
30267 | + struct inode *h_inode; | |
c06a8ce3 | 30268 | + struct super_block *h_sb; |
1facf9fc | 30269 | + |
1facf9fc | 30270 | + if (!h_file) { |
c06a8ce3 AM |
30271 | + err = vfsub_truncate(h_path, length); |
30272 | + goto out; | |
1facf9fc | 30273 | + } |
30274 | + | |
c06a8ce3 AM |
30275 | + h_inode = h_path->dentry->d_inode; |
30276 | + h_sb = h_inode->i_sb; | |
30277 | + lockdep_off(); | |
30278 | + sb_start_write(h_sb); | |
30279 | + lockdep_on(); | |
1facf9fc | 30280 | + err = locks_verify_truncate(h_inode, h_file, length); |
30281 | + if (!err) | |
953406b4 | 30282 | + err = security_path_truncate(h_path); |
2cbb1c4b JR |
30283 | + if (!err) { |
30284 | + lockdep_off(); | |
1facf9fc | 30285 | + err = do_truncate(h_path->dentry, length, attr, h_file); |
2cbb1c4b JR |
30286 | + lockdep_on(); |
30287 | + } | |
c06a8ce3 AM |
30288 | + lockdep_off(); |
30289 | + sb_end_write(h_sb); | |
30290 | + lockdep_on(); | |
1facf9fc | 30291 | + |
4f0767ce | 30292 | +out: |
1facf9fc | 30293 | + return err; |
30294 | +} | |
30295 | + | |
30296 | +/* ---------------------------------------------------------------------- */ | |
30297 | + | |
30298 | +struct au_vfsub_mkdir_args { | |
30299 | + int *errp; | |
30300 | + struct inode *dir; | |
30301 | + struct path *path; | |
30302 | + int mode; | |
30303 | +}; | |
30304 | + | |
30305 | +static void au_call_vfsub_mkdir(void *args) | |
30306 | +{ | |
30307 | + struct au_vfsub_mkdir_args *a = args; | |
30308 | + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode); | |
30309 | +} | |
30310 | + | |
30311 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode) | |
30312 | +{ | |
30313 | + int err, do_sio, wkq_err; | |
30314 | + | |
30315 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
30316 | + if (!do_sio) { |
30317 | + lockdep_off(); | |
1facf9fc | 30318 | + err = vfsub_mkdir(dir, path, mode); |
c1595e42 JR |
30319 | + lockdep_on(); |
30320 | + } else { | |
1facf9fc | 30321 | + struct au_vfsub_mkdir_args args = { |
30322 | + .errp = &err, | |
30323 | + .dir = dir, | |
30324 | + .path = path, | |
30325 | + .mode = mode | |
30326 | + }; | |
30327 | + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args); | |
30328 | + if (unlikely(wkq_err)) | |
30329 | + err = wkq_err; | |
30330 | + } | |
30331 | + | |
30332 | + return err; | |
30333 | +} | |
30334 | + | |
30335 | +struct au_vfsub_rmdir_args { | |
30336 | + int *errp; | |
30337 | + struct inode *dir; | |
30338 | + struct path *path; | |
30339 | +}; | |
30340 | + | |
30341 | +static void au_call_vfsub_rmdir(void *args) | |
30342 | +{ | |
30343 | + struct au_vfsub_rmdir_args *a = args; | |
30344 | + *a->errp = vfsub_rmdir(a->dir, a->path); | |
30345 | +} | |
30346 | + | |
30347 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path) | |
30348 | +{ | |
30349 | + int err, do_sio, wkq_err; | |
30350 | + | |
30351 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
30352 | + if (!do_sio) { |
30353 | + lockdep_off(); | |
1facf9fc | 30354 | + err = vfsub_rmdir(dir, path); |
c1595e42 JR |
30355 | + lockdep_on(); |
30356 | + } else { | |
1facf9fc | 30357 | + struct au_vfsub_rmdir_args args = { |
30358 | + .errp = &err, | |
30359 | + .dir = dir, | |
30360 | + .path = path | |
30361 | + }; | |
30362 | + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args); | |
30363 | + if (unlikely(wkq_err)) | |
30364 | + err = wkq_err; | |
30365 | + } | |
30366 | + | |
30367 | + return err; | |
30368 | +} | |
30369 | + | |
30370 | +/* ---------------------------------------------------------------------- */ | |
30371 | + | |
30372 | +struct notify_change_args { | |
30373 | + int *errp; | |
30374 | + struct path *path; | |
30375 | + struct iattr *ia; | |
523b37e3 | 30376 | + struct inode **delegated_inode; |
1facf9fc | 30377 | +}; |
30378 | + | |
30379 | +static void call_notify_change(void *args) | |
30380 | +{ | |
30381 | + struct notify_change_args *a = args; | |
30382 | + struct inode *h_inode; | |
30383 | + | |
30384 | + h_inode = a->path->dentry->d_inode; | |
30385 | + IMustLock(h_inode); | |
30386 | + | |
30387 | + *a->errp = -EPERM; | |
30388 | + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) { | |
c1595e42 | 30389 | + lockdep_off(); |
523b37e3 AM |
30390 | + *a->errp = notify_change(a->path->dentry, a->ia, |
30391 | + a->delegated_inode); | |
c1595e42 | 30392 | + lockdep_on(); |
1facf9fc | 30393 | + if (!*a->errp) |
30394 | + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/ | |
30395 | + } | |
30396 | + AuTraceErr(*a->errp); | |
30397 | +} | |
30398 | + | |
523b37e3 AM |
30399 | +int vfsub_notify_change(struct path *path, struct iattr *ia, |
30400 | + struct inode **delegated_inode) | |
1facf9fc | 30401 | +{ |
30402 | + int err; | |
30403 | + struct notify_change_args args = { | |
523b37e3 AM |
30404 | + .errp = &err, |
30405 | + .path = path, | |
30406 | + .ia = ia, | |
30407 | + .delegated_inode = delegated_inode | |
1facf9fc | 30408 | + }; |
30409 | + | |
30410 | + call_notify_change(&args); | |
30411 | + | |
30412 | + return err; | |
30413 | +} | |
30414 | + | |
523b37e3 AM |
30415 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
30416 | + struct inode **delegated_inode) | |
1facf9fc | 30417 | +{ |
30418 | + int err, wkq_err; | |
30419 | + struct notify_change_args args = { | |
523b37e3 AM |
30420 | + .errp = &err, |
30421 | + .path = path, | |
30422 | + .ia = ia, | |
30423 | + .delegated_inode = delegated_inode | |
1facf9fc | 30424 | + }; |
30425 | + | |
30426 | + wkq_err = au_wkq_wait(call_notify_change, &args); | |
30427 | + if (unlikely(wkq_err)) | |
30428 | + err = wkq_err; | |
30429 | + | |
30430 | + return err; | |
30431 | +} | |
30432 | + | |
30433 | +/* ---------------------------------------------------------------------- */ | |
30434 | + | |
30435 | +struct unlink_args { | |
30436 | + int *errp; | |
30437 | + struct inode *dir; | |
30438 | + struct path *path; | |
523b37e3 | 30439 | + struct inode **delegated_inode; |
1facf9fc | 30440 | +}; |
30441 | + | |
30442 | +static void call_unlink(void *args) | |
30443 | +{ | |
30444 | + struct unlink_args *a = args; | |
30445 | + struct dentry *d = a->path->dentry; | |
30446 | + struct inode *h_inode; | |
30447 | + const int stop_sillyrename = (au_test_nfs(d->d_sb) | |
c1595e42 | 30448 | + && au_dcount(d) == 1); |
1facf9fc | 30449 | + |
30450 | + IMustLock(a->dir); | |
30451 | + | |
30452 | + a->path->dentry = d->d_parent; | |
30453 | + *a->errp = security_path_unlink(a->path, d); | |
30454 | + a->path->dentry = d; | |
30455 | + if (unlikely(*a->errp)) | |
30456 | + return; | |
30457 | + | |
30458 | + if (!stop_sillyrename) | |
30459 | + dget(d); | |
30460 | + h_inode = d->d_inode; | |
30461 | + if (h_inode) | |
027c5e7a | 30462 | + ihold(h_inode); |
1facf9fc | 30463 | + |
2cbb1c4b | 30464 | + lockdep_off(); |
523b37e3 | 30465 | + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode); |
2cbb1c4b | 30466 | + lockdep_on(); |
1facf9fc | 30467 | + if (!*a->errp) { |
30468 | + struct path tmp = { | |
30469 | + .dentry = d->d_parent, | |
30470 | + .mnt = a->path->mnt | |
30471 | + }; | |
30472 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
30473 | + } | |
30474 | + | |
30475 | + if (!stop_sillyrename) | |
30476 | + dput(d); | |
30477 | + if (h_inode) | |
30478 | + iput(h_inode); | |
30479 | + | |
30480 | + AuTraceErr(*a->errp); | |
30481 | +} | |
30482 | + | |
30483 | +/* | |
30484 | + * @dir: must be locked. | |
30485 | + * @dentry: target dentry. | |
30486 | + */ | |
523b37e3 AM |
30487 | +int vfsub_unlink(struct inode *dir, struct path *path, |
30488 | + struct inode **delegated_inode, int force) | |
1facf9fc | 30489 | +{ |
30490 | + int err; | |
30491 | + struct unlink_args args = { | |
523b37e3 AM |
30492 | + .errp = &err, |
30493 | + .dir = dir, | |
30494 | + .path = path, | |
30495 | + .delegated_inode = delegated_inode | |
1facf9fc | 30496 | + }; |
30497 | + | |
30498 | + if (!force) | |
30499 | + call_unlink(&args); | |
30500 | + else { | |
30501 | + int wkq_err; | |
30502 | + | |
30503 | + wkq_err = au_wkq_wait(call_unlink, &args); | |
30504 | + if (unlikely(wkq_err)) | |
30505 | + err = wkq_err; | |
30506 | + } | |
30507 | + | |
30508 | + return err; | |
30509 | +} | |
7f207e10 AM |
30510 | diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h |
30511 | --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
30512 | +++ linux/fs/aufs/vfsub.h 2015-01-25 13:00:38.634380408 +0100 |
30513 | @@ -0,0 +1,310 @@ | |
1facf9fc | 30514 | +/* |
523b37e3 | 30515 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 30516 | + * |
30517 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30518 | + * it under the terms of the GNU General Public License as published by | |
30519 | + * the Free Software Foundation; either version 2 of the License, or | |
30520 | + * (at your option) any later version. | |
dece6358 AM |
30521 | + * |
30522 | + * This program is distributed in the hope that it will be useful, | |
30523 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30524 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30525 | + * GNU General Public License for more details. | |
30526 | + * | |
30527 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30528 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30529 | + */ |
30530 | + | |
30531 | +/* | |
30532 | + * sub-routines for VFS | |
30533 | + */ | |
30534 | + | |
30535 | +#ifndef __AUFS_VFSUB_H__ | |
30536 | +#define __AUFS_VFSUB_H__ | |
30537 | + | |
30538 | +#ifdef __KERNEL__ | |
30539 | + | |
30540 | +#include <linux/fs.h> | |
0c5527e5 | 30541 | +#include <linux/lglock.h> |
b4510431 | 30542 | +#include <linux/mount.h> |
c1595e42 | 30543 | +#include <linux/xattr.h> |
7f207e10 | 30544 | +#include "debug.h" |
1facf9fc | 30545 | + |
7f207e10 | 30546 | +/* copied from linux/fs/internal.h */ |
2cbb1c4b | 30547 | +/* todo: BAD approach!! */ |
c06a8ce3 | 30548 | +extern void __mnt_drop_write(struct vfsmount *); |
2cbb1c4b | 30549 | +extern spinlock_t inode_sb_list_lock; |
7f207e10 AM |
30550 | + |
30551 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 30552 | + |
30553 | +/* lock subclass for lower inode */ | |
30554 | +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */ | |
30555 | +/* reduce? gave up. */ | |
30556 | +enum { | |
c1595e42 | 30557 | + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */ |
1facf9fc | 30558 | + AuLsc_I_PARENT, /* lower inode, parent first */ |
30559 | + AuLsc_I_PARENT2, /* copyup dirs */ | |
dece6358 | 30560 | + AuLsc_I_PARENT3, /* copyup wh */ |
1facf9fc | 30561 | + AuLsc_I_CHILD, |
30562 | + AuLsc_I_CHILD2, | |
30563 | + AuLsc_I_End | |
30564 | +}; | |
30565 | + | |
30566 | +/* to debug easier, do not make them inlined functions */ | |
30567 | +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx)) | |
30568 | +#define IMustLock(i) MtxMustLock(&(i)->i_mutex) | |
30569 | + | |
30570 | +/* ---------------------------------------------------------------------- */ | |
30571 | + | |
7f207e10 AM |
30572 | +static inline void vfsub_drop_nlink(struct inode *inode) |
30573 | +{ | |
30574 | + AuDebugOn(!inode->i_nlink); | |
30575 | + drop_nlink(inode); | |
30576 | +} | |
30577 | + | |
027c5e7a AM |
30578 | +static inline void vfsub_dead_dir(struct inode *inode) |
30579 | +{ | |
30580 | + AuDebugOn(!S_ISDIR(inode->i_mode)); | |
30581 | + inode->i_flags |= S_DEAD; | |
30582 | + clear_nlink(inode); | |
30583 | +} | |
30584 | + | |
392086de AM |
30585 | +static inline int vfsub_native_ro(struct inode *inode) |
30586 | +{ | |
30587 | + return (inode->i_sb->s_flags & MS_RDONLY) | |
30588 | + || IS_RDONLY(inode) | |
30589 | + /* || IS_APPEND(inode) */ | |
30590 | + || IS_IMMUTABLE(inode); | |
30591 | +} | |
30592 | + | |
7f207e10 AM |
30593 | +/* ---------------------------------------------------------------------- */ |
30594 | + | |
30595 | +int vfsub_update_h_iattr(struct path *h_path, int *did); | |
30596 | +struct file *vfsub_dentry_open(struct path *path, int flags); | |
30597 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode); | |
1facf9fc | 30598 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path); |
b4510431 | 30599 | + |
1facf9fc | 30600 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
30601 | + int len); | |
b4510431 AM |
30602 | + |
30603 | +struct vfsub_lkup_one_args { | |
30604 | + struct dentry **errp; | |
30605 | + struct qstr *name; | |
30606 | + struct dentry *parent; | |
30607 | +}; | |
30608 | + | |
30609 | +static inline struct dentry *vfsub_lkup_one(struct qstr *name, | |
30610 | + struct dentry *parent) | |
30611 | +{ | |
30612 | + return vfsub_lookup_one_len(name->name, parent, name->len); | |
30613 | +} | |
30614 | + | |
30615 | +void vfsub_call_lkup_one(void *args); | |
30616 | + | |
30617 | +/* ---------------------------------------------------------------------- */ | |
30618 | + | |
30619 | +static inline int vfsub_mnt_want_write(struct vfsmount *mnt) | |
30620 | +{ | |
30621 | + int err; | |
076b876e | 30622 | + |
b4510431 AM |
30623 | + lockdep_off(); |
30624 | + err = mnt_want_write(mnt); | |
30625 | + lockdep_on(); | |
30626 | + return err; | |
30627 | +} | |
30628 | + | |
30629 | +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt) | |
30630 | +{ | |
30631 | + lockdep_off(); | |
30632 | + mnt_drop_write(mnt); | |
30633 | + lockdep_on(); | |
30634 | +} | |
1facf9fc | 30635 | + |
c06a8ce3 AM |
30636 | +static inline void vfsub_mnt_drop_write_file(struct file *file) |
30637 | +{ | |
30638 | + lockdep_off(); | |
30639 | + mnt_drop_write_file(file); | |
30640 | + lockdep_on(); | |
30641 | +} | |
30642 | + | |
1facf9fc | 30643 | +/* ---------------------------------------------------------------------- */ |
30644 | + | |
30645 | +struct au_hinode; | |
30646 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30647 | + struct dentry *d2, struct au_hinode *hdir2); | |
30648 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
30649 | + struct dentry *d2, struct au_hinode *hdir2); | |
30650 | + | |
537831f9 AM |
30651 | +int vfsub_create(struct inode *dir, struct path *path, int mode, |
30652 | + bool want_excl); | |
1facf9fc | 30653 | +int vfsub_symlink(struct inode *dir, struct path *path, |
30654 | + const char *symname); | |
30655 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev); | |
30656 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, | |
523b37e3 | 30657 | + struct path *path, struct inode **delegated_inode); |
1facf9fc | 30658 | +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry, |
523b37e3 AM |
30659 | + struct inode *hdir, struct path *path, |
30660 | + struct inode **delegated_inode); | |
1facf9fc | 30661 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode); |
30662 | +int vfsub_rmdir(struct inode *dir, struct path *path); | |
30663 | + | |
30664 | +/* ---------------------------------------------------------------------- */ | |
30665 | + | |
30666 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, | |
30667 | + loff_t *ppos); | |
30668 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
30669 | + loff_t *ppos); | |
30670 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
30671 | + loff_t *ppos); | |
30672 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, | |
30673 | + loff_t *ppos); | |
4a4d8108 | 30674 | +int vfsub_flush(struct file *file, fl_owner_t id); |
392086de AM |
30675 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx); |
30676 | + | |
30677 | +/* just for type-check */ | |
30678 | +static inline filldir_t au_diractor(int (*func)(struct dir_context *, | |
30679 | + const char *, int, loff_t, u64, | |
30680 | + unsigned)) | |
30681 | +{ | |
30682 | + return (filldir_t)func; | |
30683 | +} | |
30684 | + | |
1facf9fc | 30685 | + |
c06a8ce3 AM |
30686 | +static inline loff_t vfsub_f_size_read(struct file *file) |
30687 | +{ | |
30688 | + return i_size_read(file_inode(file)); | |
30689 | +} | |
30690 | + | |
4a4d8108 AM |
30691 | +static inline unsigned int vfsub_file_flags(struct file *file) |
30692 | +{ | |
30693 | + unsigned int flags; | |
30694 | + | |
30695 | + spin_lock(&file->f_lock); | |
30696 | + flags = file->f_flags; | |
30697 | + spin_unlock(&file->f_lock); | |
30698 | + | |
30699 | + return flags; | |
30700 | +} | |
1308ab2a | 30701 | + |
1facf9fc | 30702 | +static inline void vfsub_file_accessed(struct file *h_file) |
30703 | +{ | |
30704 | + file_accessed(h_file); | |
30705 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/ | |
30706 | +} | |
30707 | + | |
30708 | +static inline void vfsub_touch_atime(struct vfsmount *h_mnt, | |
30709 | + struct dentry *h_dentry) | |
30710 | +{ | |
30711 | + struct path h_path = { | |
30712 | + .dentry = h_dentry, | |
30713 | + .mnt = h_mnt | |
30714 | + }; | |
92d182d2 | 30715 | + touch_atime(&h_path); |
1facf9fc | 30716 | + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/ |
30717 | +} | |
30718 | + | |
0c3ec466 AM |
30719 | +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts, |
30720 | + int flags) | |
30721 | +{ | |
30722 | + return update_time(h_inode, ts, flags); | |
30723 | + /* no vfsub_update_h_iattr() since we don't have struct path */ | |
30724 | +} | |
30725 | + | |
4a4d8108 AM |
30726 | +long vfsub_splice_to(struct file *in, loff_t *ppos, |
30727 | + struct pipe_inode_info *pipe, size_t len, | |
30728 | + unsigned int flags); | |
30729 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
30730 | + loff_t *ppos, size_t len, unsigned int flags); | |
c06a8ce3 AM |
30731 | + |
30732 | +static inline long vfsub_truncate(struct path *path, loff_t length) | |
30733 | +{ | |
30734 | + long err; | |
076b876e | 30735 | + |
c06a8ce3 AM |
30736 | + lockdep_off(); |
30737 | + err = vfs_truncate(path, length); | |
30738 | + lockdep_on(); | |
30739 | + return err; | |
30740 | +} | |
30741 | + | |
4a4d8108 AM |
30742 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, |
30743 | + struct file *h_file); | |
53392da6 | 30744 | +int vfsub_fsync(struct file *file, struct path *path, int datasync); |
4a4d8108 | 30745 | + |
1facf9fc | 30746 | +/* ---------------------------------------------------------------------- */ |
30747 | + | |
30748 | +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin) | |
30749 | +{ | |
30750 | + loff_t err; | |
30751 | + | |
2cbb1c4b | 30752 | + lockdep_off(); |
1facf9fc | 30753 | + err = vfs_llseek(file, offset, origin); |
2cbb1c4b | 30754 | + lockdep_on(); |
1facf9fc | 30755 | + return err; |
30756 | +} | |
30757 | + | |
30758 | +/* ---------------------------------------------------------------------- */ | |
30759 | + | |
30760 | +/* dirty workaround for strict type of fmode_t */ | |
30761 | +union vfsub_fmu { | |
30762 | + fmode_t fm; | |
30763 | + unsigned int ui; | |
30764 | +}; | |
30765 | + | |
30766 | +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm) | |
30767 | +{ | |
30768 | + union vfsub_fmu u = { | |
30769 | + .fm = fm | |
30770 | + }; | |
30771 | + | |
30772 | + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui)); | |
30773 | + | |
30774 | + return u.ui; | |
30775 | +} | |
30776 | + | |
30777 | +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui) | |
30778 | +{ | |
30779 | + union vfsub_fmu u = { | |
30780 | + .ui = ui | |
30781 | + }; | |
30782 | + | |
30783 | + return u.fm; | |
30784 | +} | |
30785 | + | |
4a4d8108 AM |
30786 | +/* ---------------------------------------------------------------------- */ |
30787 | + | |
30788 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode); | |
30789 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path); | |
523b37e3 AM |
30790 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
30791 | + struct inode **delegated_inode); | |
30792 | +int vfsub_notify_change(struct path *path, struct iattr *ia, | |
30793 | + struct inode **delegated_inode); | |
30794 | +int vfsub_unlink(struct inode *dir, struct path *path, | |
30795 | + struct inode **delegated_inode, int force); | |
4a4d8108 | 30796 | + |
c1595e42 JR |
30797 | +/* ---------------------------------------------------------------------- */ |
30798 | + | |
30799 | +static inline int vfsub_setxattr(struct dentry *dentry, const char *name, | |
30800 | + const void *value, size_t size, int flags) | |
30801 | +{ | |
30802 | + int err; | |
30803 | + | |
30804 | + lockdep_off(); | |
30805 | + err = vfs_setxattr(dentry, name, value, size, flags); | |
30806 | + lockdep_on(); | |
30807 | + | |
30808 | + return err; | |
30809 | +} | |
30810 | + | |
30811 | +static inline int vfsub_removexattr(struct dentry *dentry, const char *name) | |
30812 | +{ | |
30813 | + int err; | |
30814 | + | |
30815 | + lockdep_off(); | |
30816 | + err = vfs_removexattr(dentry, name); | |
30817 | + lockdep_on(); | |
30818 | + | |
30819 | + return err; | |
30820 | +} | |
30821 | + | |
1facf9fc | 30822 | +#endif /* __KERNEL__ */ |
30823 | +#endif /* __AUFS_VFSUB_H__ */ | |
7f207e10 AM |
30824 | diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c |
30825 | --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 30826 | +++ linux/fs/aufs/wbr_policy.c 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 30827 | @@ -0,0 +1,765 @@ |
1facf9fc | 30828 | +/* |
523b37e3 | 30829 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 30830 | + * |
30831 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30832 | + * it under the terms of the GNU General Public License as published by | |
30833 | + * the Free Software Foundation; either version 2 of the License, or | |
30834 | + * (at your option) any later version. | |
dece6358 AM |
30835 | + * |
30836 | + * This program is distributed in the hope that it will be useful, | |
30837 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30838 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30839 | + * GNU General Public License for more details. | |
30840 | + * | |
30841 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30842 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30843 | + */ |
30844 | + | |
30845 | +/* | |
30846 | + * policies for selecting one among multiple writable branches | |
30847 | + */ | |
30848 | + | |
30849 | +#include <linux/statfs.h> | |
30850 | +#include "aufs.h" | |
30851 | + | |
30852 | +/* subset of cpup_attr() */ | |
30853 | +static noinline_for_stack | |
30854 | +int au_cpdown_attr(struct path *h_path, struct dentry *h_src) | |
30855 | +{ | |
30856 | + int err, sbits; | |
30857 | + struct iattr ia; | |
30858 | + struct inode *h_isrc; | |
30859 | + | |
30860 | + h_isrc = h_src->d_inode; | |
30861 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID; | |
30862 | + ia.ia_mode = h_isrc->i_mode; | |
30863 | + ia.ia_uid = h_isrc->i_uid; | |
30864 | + ia.ia_gid = h_isrc->i_gid; | |
30865 | + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID)); | |
86dc4139 | 30866 | + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags); |
523b37e3 AM |
30867 | + /* no delegation since it is just created */ |
30868 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 30869 | + |
30870 | + /* is this nfs only? */ | |
30871 | + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) { | |
30872 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
30873 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 30874 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); |
1facf9fc | 30875 | + } |
30876 | + | |
30877 | + return err; | |
30878 | +} | |
30879 | + | |
30880 | +#define AuCpdown_PARENT_OPQ 1 | |
30881 | +#define AuCpdown_WHED (1 << 1) | |
30882 | +#define AuCpdown_MADE_DIR (1 << 2) | |
30883 | +#define AuCpdown_DIROPQ (1 << 3) | |
30884 | +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name) | |
7f207e10 AM |
30885 | +#define au_fset_cpdown(flags, name) \ |
30886 | + do { (flags) |= AuCpdown_##name; } while (0) | |
30887 | +#define au_fclr_cpdown(flags, name) \ | |
30888 | + do { (flags) &= ~AuCpdown_##name; } while (0) | |
1facf9fc | 30889 | + |
1facf9fc | 30890 | +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst, |
c2b27bf2 | 30891 | + unsigned int *flags) |
1facf9fc | 30892 | +{ |
30893 | + int err; | |
30894 | + struct dentry *opq_dentry; | |
30895 | + | |
30896 | + opq_dentry = au_diropq_create(dentry, bdst); | |
30897 | + err = PTR_ERR(opq_dentry); | |
30898 | + if (IS_ERR(opq_dentry)) | |
30899 | + goto out; | |
30900 | + dput(opq_dentry); | |
c2b27bf2 | 30901 | + au_fset_cpdown(*flags, DIROPQ); |
1facf9fc | 30902 | + |
4f0767ce | 30903 | +out: |
1facf9fc | 30904 | + return err; |
30905 | +} | |
30906 | + | |
30907 | +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent, | |
30908 | + struct inode *dir, aufs_bindex_t bdst) | |
30909 | +{ | |
30910 | + int err; | |
30911 | + struct path h_path; | |
30912 | + struct au_branch *br; | |
30913 | + | |
30914 | + br = au_sbr(dentry->d_sb, bdst); | |
30915 | + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br); | |
30916 | + err = PTR_ERR(h_path.dentry); | |
30917 | + if (IS_ERR(h_path.dentry)) | |
30918 | + goto out; | |
30919 | + | |
30920 | + err = 0; | |
30921 | + if (h_path.dentry->d_inode) { | |
86dc4139 | 30922 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 30923 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path, |
30924 | + dentry); | |
30925 | + } | |
30926 | + dput(h_path.dentry); | |
30927 | + | |
4f0767ce | 30928 | +out: |
1facf9fc | 30929 | + return err; |
30930 | +} | |
30931 | + | |
30932 | +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 30933 | + struct au_pin *pin, |
1facf9fc | 30934 | + struct dentry *h_parent, void *arg) |
30935 | +{ | |
30936 | + int err, rerr; | |
4a4d8108 | 30937 | + aufs_bindex_t bopq, bstart; |
1facf9fc | 30938 | + struct path h_path; |
30939 | + struct dentry *parent; | |
30940 | + struct inode *h_dir, *h_inode, *inode, *dir; | |
c2b27bf2 | 30941 | + unsigned int *flags = arg; |
1facf9fc | 30942 | + |
30943 | + bstart = au_dbstart(dentry); | |
30944 | + /* dentry is di-locked */ | |
30945 | + parent = dget_parent(dentry); | |
30946 | + dir = parent->d_inode; | |
30947 | + h_dir = h_parent->d_inode; | |
30948 | + AuDebugOn(h_dir != au_h_iptr(dir, bdst)); | |
30949 | + IMustLock(h_dir); | |
30950 | + | |
86dc4139 | 30951 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); |
1facf9fc | 30952 | + if (unlikely(err < 0)) |
30953 | + goto out; | |
30954 | + h_path.dentry = au_h_dptr(dentry, bdst); | |
30955 | + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst); | |
30956 | + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, | |
30957 | + S_IRWXU | S_IRUGO | S_IXUGO); | |
30958 | + if (unlikely(err)) | |
30959 | + goto out_put; | |
c2b27bf2 | 30960 | + au_fset_cpdown(*flags, MADE_DIR); |
1facf9fc | 30961 | + |
1facf9fc | 30962 | + bopq = au_dbdiropq(dentry); |
c2b27bf2 AM |
30963 | + au_fclr_cpdown(*flags, WHED); |
30964 | + au_fclr_cpdown(*flags, DIROPQ); | |
1facf9fc | 30965 | + if (au_dbwh(dentry) == bdst) |
c2b27bf2 AM |
30966 | + au_fset_cpdown(*flags, WHED); |
30967 | + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst) | |
30968 | + au_fset_cpdown(*flags, PARENT_OPQ); | |
1facf9fc | 30969 | + h_inode = h_path.dentry->d_inode; |
30970 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); | |
c2b27bf2 AM |
30971 | + if (au_ftest_cpdown(*flags, WHED)) { |
30972 | + err = au_cpdown_dir_opq(dentry, bdst, flags); | |
1facf9fc | 30973 | + if (unlikely(err)) { |
30974 | + mutex_unlock(&h_inode->i_mutex); | |
30975 | + goto out_dir; | |
30976 | + } | |
30977 | + } | |
30978 | + | |
30979 | + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart)); | |
30980 | + mutex_unlock(&h_inode->i_mutex); | |
30981 | + if (unlikely(err)) | |
30982 | + goto out_opq; | |
30983 | + | |
c2b27bf2 | 30984 | + if (au_ftest_cpdown(*flags, WHED)) { |
1facf9fc | 30985 | + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst); |
30986 | + if (unlikely(err)) | |
30987 | + goto out_opq; | |
30988 | + } | |
30989 | + | |
30990 | + inode = dentry->d_inode; | |
30991 | + if (au_ibend(inode) < bdst) | |
30992 | + au_set_ibend(inode, bdst); | |
30993 | + au_set_h_iptr(inode, bdst, au_igrab(h_inode), | |
30994 | + au_hi_flags(inode, /*isdir*/1)); | |
076b876e | 30995 | + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0); |
1facf9fc | 30996 | + goto out; /* success */ |
30997 | + | |
30998 | + /* revert */ | |
4f0767ce | 30999 | +out_opq: |
c2b27bf2 | 31000 | + if (au_ftest_cpdown(*flags, DIROPQ)) { |
1facf9fc | 31001 | + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD); |
31002 | + rerr = au_diropq_remove(dentry, bdst); | |
31003 | + mutex_unlock(&h_inode->i_mutex); | |
31004 | + if (unlikely(rerr)) { | |
523b37e3 AM |
31005 | + AuIOErr("failed removing diropq for %pd b%d (%d)\n", |
31006 | + dentry, bdst, rerr); | |
1facf9fc | 31007 | + err = -EIO; |
31008 | + goto out; | |
31009 | + } | |
31010 | + } | |
4f0767ce | 31011 | +out_dir: |
c2b27bf2 | 31012 | + if (au_ftest_cpdown(*flags, MADE_DIR)) { |
1facf9fc | 31013 | + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path); |
31014 | + if (unlikely(rerr)) { | |
523b37e3 AM |
31015 | + AuIOErr("failed removing %pd b%d (%d)\n", |
31016 | + dentry, bdst, rerr); | |
1facf9fc | 31017 | + err = -EIO; |
31018 | + } | |
31019 | + } | |
4f0767ce | 31020 | +out_put: |
1facf9fc | 31021 | + au_set_h_dptr(dentry, bdst, NULL); |
31022 | + if (au_dbend(dentry) == bdst) | |
31023 | + au_update_dbend(dentry); | |
4f0767ce | 31024 | +out: |
1facf9fc | 31025 | + dput(parent); |
31026 | + return err; | |
31027 | +} | |
31028 | + | |
31029 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
31030 | +{ | |
31031 | + int err; | |
c2b27bf2 | 31032 | + unsigned int flags; |
1facf9fc | 31033 | + |
c2b27bf2 AM |
31034 | + flags = 0; |
31035 | + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags); | |
1facf9fc | 31036 | + |
31037 | + return err; | |
31038 | +} | |
31039 | + | |
31040 | +/* ---------------------------------------------------------------------- */ | |
31041 | + | |
31042 | +/* policies for create */ | |
31043 | + | |
c2b27bf2 | 31044 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex) |
4a4d8108 AM |
31045 | +{ |
31046 | + int err, i, j, ndentry; | |
31047 | + aufs_bindex_t bopq; | |
31048 | + struct au_dcsub_pages dpages; | |
31049 | + struct au_dpage *dpage; | |
31050 | + struct dentry **dentries, *parent, *d; | |
31051 | + | |
31052 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
31053 | + if (unlikely(err)) | |
31054 | + goto out; | |
31055 | + parent = dget_parent(dentry); | |
027c5e7a | 31056 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0); |
4a4d8108 AM |
31057 | + if (unlikely(err)) |
31058 | + goto out_free; | |
31059 | + | |
31060 | + err = bindex; | |
31061 | + for (i = 0; i < dpages.ndpage; i++) { | |
31062 | + dpage = dpages.dpages + i; | |
31063 | + dentries = dpage->dentries; | |
31064 | + ndentry = dpage->ndentry; | |
31065 | + for (j = 0; j < ndentry; j++) { | |
31066 | + d = dentries[j]; | |
31067 | + di_read_lock_parent2(d, !AuLock_IR); | |
31068 | + bopq = au_dbdiropq(d); | |
31069 | + di_read_unlock(d, !AuLock_IR); | |
31070 | + if (bopq >= 0 && bopq < err) | |
31071 | + err = bopq; | |
31072 | + } | |
31073 | + } | |
31074 | + | |
31075 | +out_free: | |
31076 | + dput(parent); | |
31077 | + au_dpages_free(&dpages); | |
31078 | +out: | |
31079 | + return err; | |
31080 | +} | |
31081 | + | |
1facf9fc | 31082 | +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex) |
31083 | +{ | |
31084 | + for (; bindex >= 0; bindex--) | |
31085 | + if (!au_br_rdonly(au_sbr(sb, bindex))) | |
31086 | + return bindex; | |
31087 | + return -EROFS; | |
31088 | +} | |
31089 | + | |
31090 | +/* top down parent */ | |
392086de AM |
31091 | +static int au_wbr_create_tdp(struct dentry *dentry, |
31092 | + unsigned int flags __maybe_unused) | |
1facf9fc | 31093 | +{ |
31094 | + int err; | |
31095 | + aufs_bindex_t bstart, bindex; | |
31096 | + struct super_block *sb; | |
31097 | + struct dentry *parent, *h_parent; | |
31098 | + | |
31099 | + sb = dentry->d_sb; | |
31100 | + bstart = au_dbstart(dentry); | |
31101 | + err = bstart; | |
31102 | + if (!au_br_rdonly(au_sbr(sb, bstart))) | |
31103 | + goto out; | |
31104 | + | |
31105 | + err = -EROFS; | |
31106 | + parent = dget_parent(dentry); | |
31107 | + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) { | |
31108 | + h_parent = au_h_dptr(parent, bindex); | |
31109 | + if (!h_parent || !h_parent->d_inode) | |
31110 | + continue; | |
31111 | + | |
31112 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
31113 | + err = bindex; | |
31114 | + break; | |
31115 | + } | |
31116 | + } | |
31117 | + dput(parent); | |
31118 | + | |
31119 | + /* bottom up here */ | |
4a4d8108 | 31120 | + if (unlikely(err < 0)) { |
1facf9fc | 31121 | + err = au_wbr_bu(sb, bstart - 1); |
4a4d8108 AM |
31122 | + if (err >= 0) |
31123 | + err = au_wbr_nonopq(dentry, err); | |
31124 | + } | |
1facf9fc | 31125 | + |
4f0767ce | 31126 | +out: |
1facf9fc | 31127 | + AuDbg("b%d\n", err); |
31128 | + return err; | |
31129 | +} | |
31130 | + | |
31131 | +/* ---------------------------------------------------------------------- */ | |
31132 | + | |
31133 | +/* an exception for the policy other than tdp */ | |
31134 | +static int au_wbr_create_exp(struct dentry *dentry) | |
31135 | +{ | |
31136 | + int err; | |
31137 | + aufs_bindex_t bwh, bdiropq; | |
31138 | + struct dentry *parent; | |
31139 | + | |
31140 | + err = -1; | |
31141 | + bwh = au_dbwh(dentry); | |
31142 | + parent = dget_parent(dentry); | |
31143 | + bdiropq = au_dbdiropq(parent); | |
31144 | + if (bwh >= 0) { | |
31145 | + if (bdiropq >= 0) | |
31146 | + err = min(bdiropq, bwh); | |
31147 | + else | |
31148 | + err = bwh; | |
31149 | + AuDbg("%d\n", err); | |
31150 | + } else if (bdiropq >= 0) { | |
31151 | + err = bdiropq; | |
31152 | + AuDbg("%d\n", err); | |
31153 | + } | |
31154 | + dput(parent); | |
31155 | + | |
4a4d8108 AM |
31156 | + if (err >= 0) |
31157 | + err = au_wbr_nonopq(dentry, err); | |
31158 | + | |
1facf9fc | 31159 | + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err))) |
31160 | + err = -1; | |
31161 | + | |
31162 | + AuDbg("%d\n", err); | |
31163 | + return err; | |
31164 | +} | |
31165 | + | |
31166 | +/* ---------------------------------------------------------------------- */ | |
31167 | + | |
31168 | +/* round robin */ | |
31169 | +static int au_wbr_create_init_rr(struct super_block *sb) | |
31170 | +{ | |
31171 | + int err; | |
31172 | + | |
31173 | + err = au_wbr_bu(sb, au_sbend(sb)); | |
31174 | + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */ | |
dece6358 | 31175 | + /* smp_mb(); */ |
1facf9fc | 31176 | + |
31177 | + AuDbg("b%d\n", err); | |
31178 | + return err; | |
31179 | +} | |
31180 | + | |
392086de | 31181 | +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31182 | +{ |
31183 | + int err, nbr; | |
31184 | + unsigned int u; | |
31185 | + aufs_bindex_t bindex, bend; | |
31186 | + struct super_block *sb; | |
31187 | + atomic_t *next; | |
31188 | + | |
31189 | + err = au_wbr_create_exp(dentry); | |
31190 | + if (err >= 0) | |
31191 | + goto out; | |
31192 | + | |
31193 | + sb = dentry->d_sb; | |
31194 | + next = &au_sbi(sb)->si_wbr_rr_next; | |
31195 | + bend = au_sbend(sb); | |
31196 | + nbr = bend + 1; | |
31197 | + for (bindex = 0; bindex <= bend; bindex++) { | |
392086de | 31198 | + if (!au_ftest_wbr(flags, DIR)) { |
1facf9fc | 31199 | + err = atomic_dec_return(next) + 1; |
31200 | + /* modulo for 0 is meaningless */ | |
31201 | + if (unlikely(!err)) | |
31202 | + err = atomic_dec_return(next) + 1; | |
31203 | + } else | |
31204 | + err = atomic_read(next); | |
31205 | + AuDbg("%d\n", err); | |
31206 | + u = err; | |
31207 | + err = u % nbr; | |
31208 | + AuDbg("%d\n", err); | |
31209 | + if (!au_br_rdonly(au_sbr(sb, err))) | |
31210 | + break; | |
31211 | + err = -EROFS; | |
31212 | + } | |
31213 | + | |
4a4d8108 AM |
31214 | + if (err >= 0) |
31215 | + err = au_wbr_nonopq(dentry, err); | |
31216 | + | |
4f0767ce | 31217 | +out: |
1facf9fc | 31218 | + AuDbg("%d\n", err); |
31219 | + return err; | |
31220 | +} | |
31221 | + | |
31222 | +/* ---------------------------------------------------------------------- */ | |
31223 | + | |
31224 | +/* most free space */ | |
392086de | 31225 | +static void au_mfs(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 31226 | +{ |
31227 | + struct super_block *sb; | |
31228 | + struct au_branch *br; | |
31229 | + struct au_wbr_mfs *mfs; | |
392086de | 31230 | + struct dentry *h_parent; |
1facf9fc | 31231 | + aufs_bindex_t bindex, bend; |
31232 | + int err; | |
31233 | + unsigned long long b, bavail; | |
7f207e10 | 31234 | + struct path h_path; |
1facf9fc | 31235 | + /* reduce the stack usage */ |
31236 | + struct kstatfs *st; | |
31237 | + | |
31238 | + st = kmalloc(sizeof(*st), GFP_NOFS); | |
31239 | + if (unlikely(!st)) { | |
31240 | + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM); | |
31241 | + return; | |
31242 | + } | |
31243 | + | |
31244 | + bavail = 0; | |
31245 | + sb = dentry->d_sb; | |
31246 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
dece6358 | 31247 | + MtxMustLock(&mfs->mfs_lock); |
1facf9fc | 31248 | + mfs->mfs_bindex = -EROFS; |
31249 | + mfs->mfsrr_bytes = 0; | |
392086de AM |
31250 | + if (!parent) { |
31251 | + bindex = 0; | |
31252 | + bend = au_sbend(sb); | |
31253 | + } else { | |
31254 | + bindex = au_dbstart(parent); | |
31255 | + bend = au_dbtaildir(parent); | |
31256 | + } | |
31257 | + | |
31258 | + for (; bindex <= bend; bindex++) { | |
31259 | + if (parent) { | |
31260 | + h_parent = au_h_dptr(parent, bindex); | |
31261 | + if (!h_parent || !h_parent->d_inode) | |
31262 | + continue; | |
31263 | + } | |
1facf9fc | 31264 | + br = au_sbr(sb, bindex); |
31265 | + if (au_br_rdonly(br)) | |
31266 | + continue; | |
31267 | + | |
31268 | + /* sb->s_root for NFS is unreliable */ | |
86dc4139 | 31269 | + h_path.mnt = au_br_mnt(br); |
7f207e10 AM |
31270 | + h_path.dentry = h_path.mnt->mnt_root; |
31271 | + err = vfs_statfs(&h_path, st); | |
1facf9fc | 31272 | + if (unlikely(err)) { |
31273 | + AuWarn1("failed statfs, b%d, %d\n", bindex, err); | |
31274 | + continue; | |
31275 | + } | |
31276 | + | |
31277 | + /* when the available size is equal, select the lower one */ | |
31278 | + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail) | |
31279 | + || sizeof(b) < sizeof(st->f_bsize)); | |
31280 | + b = st->f_bavail * st->f_bsize; | |
31281 | + br->br_wbr->wbr_bytes = b; | |
31282 | + if (b >= bavail) { | |
31283 | + bavail = b; | |
31284 | + mfs->mfs_bindex = bindex; | |
31285 | + mfs->mfs_jiffy = jiffies; | |
31286 | + } | |
31287 | + } | |
31288 | + | |
31289 | + mfs->mfsrr_bytes = bavail; | |
31290 | + AuDbg("b%d\n", mfs->mfs_bindex); | |
31291 | + kfree(st); | |
31292 | +} | |
31293 | + | |
392086de | 31294 | +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31295 | +{ |
31296 | + int err; | |
392086de | 31297 | + struct dentry *parent; |
1facf9fc | 31298 | + struct super_block *sb; |
31299 | + struct au_wbr_mfs *mfs; | |
31300 | + | |
31301 | + err = au_wbr_create_exp(dentry); | |
31302 | + if (err >= 0) | |
31303 | + goto out; | |
31304 | + | |
31305 | + sb = dentry->d_sb; | |
392086de AM |
31306 | + parent = NULL; |
31307 | + if (au_ftest_wbr(flags, PARENT)) | |
31308 | + parent = dget_parent(dentry); | |
1facf9fc | 31309 | + mfs = &au_sbi(sb)->si_wbr_mfs; |
31310 | + mutex_lock(&mfs->mfs_lock); | |
31311 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
31312 | + || mfs->mfs_bindex < 0 | |
31313 | + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex))) | |
392086de | 31314 | + au_mfs(dentry, parent); |
1facf9fc | 31315 | + mutex_unlock(&mfs->mfs_lock); |
31316 | + err = mfs->mfs_bindex; | |
392086de | 31317 | + dput(parent); |
1facf9fc | 31318 | + |
4a4d8108 AM |
31319 | + if (err >= 0) |
31320 | + err = au_wbr_nonopq(dentry, err); | |
31321 | + | |
4f0767ce | 31322 | +out: |
1facf9fc | 31323 | + AuDbg("b%d\n", err); |
31324 | + return err; | |
31325 | +} | |
31326 | + | |
31327 | +static int au_wbr_create_init_mfs(struct super_block *sb) | |
31328 | +{ | |
31329 | + struct au_wbr_mfs *mfs; | |
31330 | + | |
31331 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
31332 | + mutex_init(&mfs->mfs_lock); | |
31333 | + mfs->mfs_jiffy = 0; | |
31334 | + mfs->mfs_bindex = -EROFS; | |
31335 | + | |
31336 | + return 0; | |
31337 | +} | |
31338 | + | |
31339 | +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused) | |
31340 | +{ | |
31341 | + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock); | |
31342 | + return 0; | |
31343 | +} | |
31344 | + | |
31345 | +/* ---------------------------------------------------------------------- */ | |
31346 | + | |
31347 | +/* most free space and then round robin */ | |
392086de | 31348 | +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31349 | +{ |
31350 | + int err; | |
31351 | + struct au_wbr_mfs *mfs; | |
31352 | + | |
392086de | 31353 | + err = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 31354 | + if (err >= 0) { |
31355 | + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs; | |
dece6358 | 31356 | + mutex_lock(&mfs->mfs_lock); |
1facf9fc | 31357 | + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark) |
392086de | 31358 | + err = au_wbr_create_rr(dentry, flags); |
dece6358 | 31359 | + mutex_unlock(&mfs->mfs_lock); |
1facf9fc | 31360 | + } |
31361 | + | |
31362 | + AuDbg("b%d\n", err); | |
31363 | + return err; | |
31364 | +} | |
31365 | + | |
31366 | +static int au_wbr_create_init_mfsrr(struct super_block *sb) | |
31367 | +{ | |
31368 | + int err; | |
31369 | + | |
31370 | + au_wbr_create_init_mfs(sb); /* ignore */ | |
31371 | + err = au_wbr_create_init_rr(sb); | |
31372 | + | |
31373 | + return err; | |
31374 | +} | |
31375 | + | |
31376 | +/* ---------------------------------------------------------------------- */ | |
31377 | + | |
31378 | +/* top down parent and most free space */ | |
392086de | 31379 | +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 31380 | +{ |
31381 | + int err, e2; | |
31382 | + unsigned long long b; | |
31383 | + aufs_bindex_t bindex, bstart, bend; | |
31384 | + struct super_block *sb; | |
31385 | + struct dentry *parent, *h_parent; | |
31386 | + struct au_branch *br; | |
31387 | + | |
392086de | 31388 | + err = au_wbr_create_tdp(dentry, flags); |
1facf9fc | 31389 | + if (unlikely(err < 0)) |
31390 | + goto out; | |
31391 | + parent = dget_parent(dentry); | |
31392 | + bstart = au_dbstart(parent); | |
31393 | + bend = au_dbtaildir(parent); | |
31394 | + if (bstart == bend) | |
31395 | + goto out_parent; /* success */ | |
31396 | + | |
392086de | 31397 | + e2 = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 31398 | + if (e2 < 0) |
31399 | + goto out_parent; /* success */ | |
31400 | + | |
31401 | + /* when the available size is equal, select upper one */ | |
31402 | + sb = dentry->d_sb; | |
31403 | + br = au_sbr(sb, err); | |
31404 | + b = br->br_wbr->wbr_bytes; | |
31405 | + AuDbg("b%d, %llu\n", err, b); | |
31406 | + | |
31407 | + for (bindex = bstart; bindex <= bend; bindex++) { | |
31408 | + h_parent = au_h_dptr(parent, bindex); | |
31409 | + if (!h_parent || !h_parent->d_inode) | |
31410 | + continue; | |
31411 | + | |
31412 | + br = au_sbr(sb, bindex); | |
31413 | + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) { | |
31414 | + b = br->br_wbr->wbr_bytes; | |
31415 | + err = bindex; | |
31416 | + AuDbg("b%d, %llu\n", err, b); | |
31417 | + } | |
31418 | + } | |
31419 | + | |
4a4d8108 AM |
31420 | + if (err >= 0) |
31421 | + err = au_wbr_nonopq(dentry, err); | |
31422 | + | |
4f0767ce | 31423 | +out_parent: |
1facf9fc | 31424 | + dput(parent); |
4f0767ce | 31425 | +out: |
1facf9fc | 31426 | + AuDbg("b%d\n", err); |
31427 | + return err; | |
31428 | +} | |
31429 | + | |
31430 | +/* ---------------------------------------------------------------------- */ | |
31431 | + | |
392086de AM |
31432 | +/* |
31433 | + * - top down parent | |
31434 | + * - most free space with parent | |
31435 | + * - most free space round-robin regardless parent | |
31436 | + */ | |
31437 | +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags) | |
31438 | +{ | |
31439 | + int err; | |
31440 | + unsigned long long watermark; | |
31441 | + struct super_block *sb; | |
31442 | + struct au_branch *br; | |
31443 | + struct au_wbr_mfs *mfs; | |
31444 | + | |
31445 | + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT); | |
31446 | + if (unlikely(err < 0)) | |
31447 | + goto out; | |
31448 | + | |
31449 | + sb = dentry->d_sb; | |
31450 | + br = au_sbr(sb, err); | |
31451 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
31452 | + mutex_lock(&mfs->mfs_lock); | |
31453 | + watermark = mfs->mfsrr_watermark; | |
31454 | + mutex_unlock(&mfs->mfs_lock); | |
31455 | + if (br->br_wbr->wbr_bytes < watermark) | |
31456 | + /* regardless the parent dir */ | |
31457 | + err = au_wbr_create_mfsrr(dentry, flags); | |
31458 | + | |
31459 | +out: | |
31460 | + AuDbg("b%d\n", err); | |
31461 | + return err; | |
31462 | +} | |
31463 | + | |
31464 | +/* ---------------------------------------------------------------------- */ | |
31465 | + | |
1facf9fc | 31466 | +/* policies for copyup */ |
31467 | + | |
31468 | +/* top down parent */ | |
31469 | +static int au_wbr_copyup_tdp(struct dentry *dentry) | |
31470 | +{ | |
392086de | 31471 | + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0); |
1facf9fc | 31472 | +} |
31473 | + | |
31474 | +/* bottom up parent */ | |
31475 | +static int au_wbr_copyup_bup(struct dentry *dentry) | |
31476 | +{ | |
31477 | + int err; | |
31478 | + aufs_bindex_t bindex, bstart; | |
31479 | + struct dentry *parent, *h_parent; | |
31480 | + struct super_block *sb; | |
31481 | + | |
31482 | + err = -EROFS; | |
31483 | + sb = dentry->d_sb; | |
31484 | + parent = dget_parent(dentry); | |
31485 | + bstart = au_dbstart(parent); | |
31486 | + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) { | |
31487 | + h_parent = au_h_dptr(parent, bindex); | |
31488 | + if (!h_parent || !h_parent->d_inode) | |
31489 | + continue; | |
31490 | + | |
31491 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
31492 | + err = bindex; | |
31493 | + break; | |
31494 | + } | |
31495 | + } | |
31496 | + dput(parent); | |
31497 | + | |
31498 | + /* bottom up here */ | |
31499 | + if (unlikely(err < 0)) | |
31500 | + err = au_wbr_bu(sb, bstart - 1); | |
31501 | + | |
31502 | + AuDbg("b%d\n", err); | |
31503 | + return err; | |
31504 | +} | |
31505 | + | |
31506 | +/* bottom up */ | |
076b876e | 31507 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart) |
1facf9fc | 31508 | +{ |
31509 | + int err; | |
31510 | + | |
4a4d8108 AM |
31511 | + err = au_wbr_bu(dentry->d_sb, bstart); |
31512 | + AuDbg("b%d\n", err); | |
31513 | + if (err > bstart) | |
31514 | + err = au_wbr_nonopq(dentry, err); | |
1facf9fc | 31515 | + |
31516 | + AuDbg("b%d\n", err); | |
31517 | + return err; | |
31518 | +} | |
31519 | + | |
076b876e AM |
31520 | +static int au_wbr_copyup_bu(struct dentry *dentry) |
31521 | +{ | |
31522 | + int err; | |
31523 | + aufs_bindex_t bstart; | |
31524 | + | |
31525 | + bstart = au_dbstart(dentry); | |
31526 | + err = au_wbr_do_copyup_bu(dentry, bstart); | |
31527 | + return err; | |
31528 | +} | |
31529 | + | |
1facf9fc | 31530 | +/* ---------------------------------------------------------------------- */ |
31531 | + | |
31532 | +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = { | |
31533 | + [AuWbrCopyup_TDP] = { | |
31534 | + .copyup = au_wbr_copyup_tdp | |
31535 | + }, | |
31536 | + [AuWbrCopyup_BUP] = { | |
31537 | + .copyup = au_wbr_copyup_bup | |
31538 | + }, | |
31539 | + [AuWbrCopyup_BU] = { | |
31540 | + .copyup = au_wbr_copyup_bu | |
31541 | + } | |
31542 | +}; | |
31543 | + | |
31544 | +struct au_wbr_create_operations au_wbr_create_ops[] = { | |
31545 | + [AuWbrCreate_TDP] = { | |
31546 | + .create = au_wbr_create_tdp | |
31547 | + }, | |
31548 | + [AuWbrCreate_RR] = { | |
31549 | + .create = au_wbr_create_rr, | |
31550 | + .init = au_wbr_create_init_rr | |
31551 | + }, | |
31552 | + [AuWbrCreate_MFS] = { | |
31553 | + .create = au_wbr_create_mfs, | |
31554 | + .init = au_wbr_create_init_mfs, | |
31555 | + .fin = au_wbr_create_fin_mfs | |
31556 | + }, | |
31557 | + [AuWbrCreate_MFSV] = { | |
31558 | + .create = au_wbr_create_mfs, | |
31559 | + .init = au_wbr_create_init_mfs, | |
31560 | + .fin = au_wbr_create_fin_mfs | |
31561 | + }, | |
31562 | + [AuWbrCreate_MFSRR] = { | |
31563 | + .create = au_wbr_create_mfsrr, | |
31564 | + .init = au_wbr_create_init_mfsrr, | |
31565 | + .fin = au_wbr_create_fin_mfs | |
31566 | + }, | |
31567 | + [AuWbrCreate_MFSRRV] = { | |
31568 | + .create = au_wbr_create_mfsrr, | |
31569 | + .init = au_wbr_create_init_mfsrr, | |
31570 | + .fin = au_wbr_create_fin_mfs | |
31571 | + }, | |
31572 | + [AuWbrCreate_PMFS] = { | |
31573 | + .create = au_wbr_create_pmfs, | |
31574 | + .init = au_wbr_create_init_mfs, | |
31575 | + .fin = au_wbr_create_fin_mfs | |
31576 | + }, | |
31577 | + [AuWbrCreate_PMFSV] = { | |
31578 | + .create = au_wbr_create_pmfs, | |
31579 | + .init = au_wbr_create_init_mfs, | |
31580 | + .fin = au_wbr_create_fin_mfs | |
392086de AM |
31581 | + }, |
31582 | + [AuWbrCreate_PMFSRR] = { | |
31583 | + .create = au_wbr_create_pmfsrr, | |
31584 | + .init = au_wbr_create_init_mfsrr, | |
31585 | + .fin = au_wbr_create_fin_mfs | |
31586 | + }, | |
31587 | + [AuWbrCreate_PMFSRRV] = { | |
31588 | + .create = au_wbr_create_pmfsrr, | |
31589 | + .init = au_wbr_create_init_mfsrr, | |
31590 | + .fin = au_wbr_create_fin_mfs | |
1facf9fc | 31591 | + } |
31592 | +}; | |
7f207e10 AM |
31593 | diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c |
31594 | --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 31595 | +++ linux/fs/aufs/whout.c 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 31596 | @@ -0,0 +1,1056 @@ |
1facf9fc | 31597 | +/* |
523b37e3 | 31598 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 31599 | + * |
31600 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31601 | + * it under the terms of the GNU General Public License as published by | |
31602 | + * the Free Software Foundation; either version 2 of the License, or | |
31603 | + * (at your option) any later version. | |
dece6358 AM |
31604 | + * |
31605 | + * This program is distributed in the hope that it will be useful, | |
31606 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31607 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31608 | + * GNU General Public License for more details. | |
31609 | + * | |
31610 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31611 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31612 | + */ |
31613 | + | |
31614 | +/* | |
31615 | + * whiteout for logical deletion and opaque directory | |
31616 | + */ | |
31617 | + | |
1facf9fc | 31618 | +#include "aufs.h" |
31619 | + | |
31620 | +#define WH_MASK S_IRUGO | |
31621 | + | |
31622 | +/* | |
31623 | + * If a directory contains this file, then it is opaque. We start with the | |
31624 | + * .wh. flag so that it is blocked by lookup. | |
31625 | + */ | |
0c3ec466 AM |
31626 | +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ, |
31627 | + sizeof(AUFS_WH_DIROPQ) - 1); | |
1facf9fc | 31628 | + |
31629 | +/* | |
31630 | + * generate whiteout name, which is NOT terminated by NULL. | |
31631 | + * @name: original d_name.name | |
31632 | + * @len: original d_name.len | |
31633 | + * @wh: whiteout qstr | |
31634 | + * returns zero when succeeds, otherwise error. | |
31635 | + * succeeded value as wh->name should be freed by kfree(). | |
31636 | + */ | |
31637 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name) | |
31638 | +{ | |
31639 | + char *p; | |
31640 | + | |
31641 | + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN)) | |
31642 | + return -ENAMETOOLONG; | |
31643 | + | |
31644 | + wh->len = name->len + AUFS_WH_PFX_LEN; | |
31645 | + p = kmalloc(wh->len, GFP_NOFS); | |
31646 | + wh->name = p; | |
31647 | + if (p) { | |
31648 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
31649 | + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len); | |
31650 | + /* smp_mb(); */ | |
31651 | + return 0; | |
31652 | + } | |
31653 | + return -ENOMEM; | |
31654 | +} | |
31655 | + | |
31656 | +/* ---------------------------------------------------------------------- */ | |
31657 | + | |
31658 | +/* | |
31659 | + * test if the @wh_name exists under @h_parent. | |
31660 | + * @try_sio specifies the necessary of super-io. | |
31661 | + */ | |
076b876e | 31662 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio) |
1facf9fc | 31663 | +{ |
31664 | + int err; | |
31665 | + struct dentry *wh_dentry; | |
1facf9fc | 31666 | + |
1facf9fc | 31667 | + if (!try_sio) |
b4510431 | 31668 | + wh_dentry = vfsub_lkup_one(wh_name, h_parent); |
1facf9fc | 31669 | + else |
076b876e | 31670 | + wh_dentry = au_sio_lkup_one(wh_name, h_parent); |
1facf9fc | 31671 | + err = PTR_ERR(wh_dentry); |
31672 | + if (IS_ERR(wh_dentry)) | |
31673 | + goto out; | |
31674 | + | |
31675 | + err = 0; | |
31676 | + if (!wh_dentry->d_inode) | |
31677 | + goto out_wh; /* success */ | |
31678 | + | |
31679 | + err = 1; | |
31680 | + if (S_ISREG(wh_dentry->d_inode->i_mode)) | |
31681 | + goto out_wh; /* success */ | |
31682 | + | |
31683 | + err = -EIO; | |
523b37e3 AM |
31684 | + AuIOErr("%pd Invalid whiteout entry type 0%o.\n", |
31685 | + wh_dentry, wh_dentry->d_inode->i_mode); | |
1facf9fc | 31686 | + |
4f0767ce | 31687 | +out_wh: |
1facf9fc | 31688 | + dput(wh_dentry); |
4f0767ce | 31689 | +out: |
1facf9fc | 31690 | + return err; |
31691 | +} | |
31692 | + | |
31693 | +/* | |
31694 | + * test if the @h_dentry sets opaque or not. | |
31695 | + */ | |
076b876e | 31696 | +int au_diropq_test(struct dentry *h_dentry) |
1facf9fc | 31697 | +{ |
31698 | + int err; | |
31699 | + struct inode *h_dir; | |
31700 | + | |
31701 | + h_dir = h_dentry->d_inode; | |
076b876e | 31702 | + err = au_wh_test(h_dentry, &diropq_name, |
1facf9fc | 31703 | + au_test_h_perm_sio(h_dir, MAY_EXEC)); |
31704 | + return err; | |
31705 | +} | |
31706 | + | |
31707 | +/* | |
31708 | + * returns a negative dentry whose name is unique and temporary. | |
31709 | + */ | |
31710 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, | |
31711 | + struct qstr *prefix) | |
31712 | +{ | |
1facf9fc | 31713 | + struct dentry *dentry; |
31714 | + int i; | |
027c5e7a | 31715 | + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1], |
4a4d8108 | 31716 | + *name, *p; |
027c5e7a | 31717 | + /* strict atomic_t is unnecessary here */ |
1facf9fc | 31718 | + static unsigned short cnt; |
31719 | + struct qstr qs; | |
31720 | + | |
4a4d8108 AM |
31721 | + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN); |
31722 | + | |
1facf9fc | 31723 | + name = defname; |
027c5e7a AM |
31724 | + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1; |
31725 | + if (unlikely(prefix->len > DNAME_INLINE_LEN)) { | |
1facf9fc | 31726 | + dentry = ERR_PTR(-ENAMETOOLONG); |
4a4d8108 | 31727 | + if (unlikely(qs.len > NAME_MAX)) |
1facf9fc | 31728 | + goto out; |
31729 | + dentry = ERR_PTR(-ENOMEM); | |
31730 | + name = kmalloc(qs.len + 1, GFP_NOFS); | |
31731 | + if (unlikely(!name)) | |
31732 | + goto out; | |
31733 | + } | |
31734 | + | |
31735 | + /* doubly whiteout-ed */ | |
31736 | + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2); | |
31737 | + p = name + AUFS_WH_PFX_LEN * 2; | |
31738 | + memcpy(p, prefix->name, prefix->len); | |
31739 | + p += prefix->len; | |
31740 | + *p++ = '.'; | |
4a4d8108 | 31741 | + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN); |
1facf9fc | 31742 | + |
31743 | + qs.name = name; | |
31744 | + for (i = 0; i < 3; i++) { | |
b752ccd1 | 31745 | + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++); |
076b876e | 31746 | + dentry = au_sio_lkup_one(&qs, h_parent); |
1facf9fc | 31747 | + if (IS_ERR(dentry) || !dentry->d_inode) |
31748 | + goto out_name; | |
31749 | + dput(dentry); | |
31750 | + } | |
0c3ec466 | 31751 | + /* pr_warn("could not get random name\n"); */ |
1facf9fc | 31752 | + dentry = ERR_PTR(-EEXIST); |
31753 | + AuDbg("%.*s\n", AuLNPair(&qs)); | |
31754 | + BUG(); | |
31755 | + | |
4f0767ce | 31756 | +out_name: |
1facf9fc | 31757 | + if (name != defname) |
31758 | + kfree(name); | |
4f0767ce | 31759 | +out: |
4a4d8108 | 31760 | + AuTraceErrPtr(dentry); |
1facf9fc | 31761 | + return dentry; |
1facf9fc | 31762 | +} |
31763 | + | |
31764 | +/* | |
31765 | + * rename the @h_dentry on @br to the whiteouted temporary name. | |
31766 | + */ | |
31767 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br) | |
31768 | +{ | |
31769 | + int err; | |
31770 | + struct path h_path = { | |
86dc4139 | 31771 | + .mnt = au_br_mnt(br) |
1facf9fc | 31772 | + }; |
523b37e3 | 31773 | + struct inode *h_dir, *delegated; |
1facf9fc | 31774 | + struct dentry *h_parent; |
31775 | + | |
31776 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ | |
31777 | + h_dir = h_parent->d_inode; | |
31778 | + IMustLock(h_dir); | |
31779 | + | |
31780 | + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name); | |
31781 | + err = PTR_ERR(h_path.dentry); | |
31782 | + if (IS_ERR(h_path.dentry)) | |
31783 | + goto out; | |
31784 | + | |
31785 | + /* under the same dir, no need to lock_rename() */ | |
523b37e3 AM |
31786 | + delegated = NULL; |
31787 | + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated); | |
1facf9fc | 31788 | + AuTraceErr(err); |
523b37e3 AM |
31789 | + if (unlikely(err == -EWOULDBLOCK)) { |
31790 | + pr_warn("cannot retry for NFSv4 delegation" | |
31791 | + " for an internal rename\n"); | |
31792 | + iput(delegated); | |
31793 | + } | |
1facf9fc | 31794 | + dput(h_path.dentry); |
31795 | + | |
4f0767ce | 31796 | +out: |
4a4d8108 | 31797 | + AuTraceErr(err); |
1facf9fc | 31798 | + return err; |
31799 | +} | |
31800 | + | |
31801 | +/* ---------------------------------------------------------------------- */ | |
31802 | +/* | |
31803 | + * functions for removing a whiteout | |
31804 | + */ | |
31805 | + | |
31806 | +static int do_unlink_wh(struct inode *h_dir, struct path *h_path) | |
31807 | +{ | |
523b37e3 AM |
31808 | + int err, force; |
31809 | + struct inode *delegated; | |
1facf9fc | 31810 | + |
31811 | + /* | |
31812 | + * forces superio when the dir has a sticky bit. | |
31813 | + * this may be a violation of unix fs semantics. | |
31814 | + */ | |
31815 | + force = (h_dir->i_mode & S_ISVTX) | |
0c3ec466 | 31816 | + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid); |
523b37e3 AM |
31817 | + delegated = NULL; |
31818 | + err = vfsub_unlink(h_dir, h_path, &delegated, force); | |
31819 | + if (unlikely(err == -EWOULDBLOCK)) { | |
31820 | + pr_warn("cannot retry for NFSv4 delegation" | |
31821 | + " for an internal unlink\n"); | |
31822 | + iput(delegated); | |
31823 | + } | |
31824 | + return err; | |
1facf9fc | 31825 | +} |
31826 | + | |
31827 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
31828 | + struct dentry *dentry) | |
31829 | +{ | |
31830 | + int err; | |
31831 | + | |
31832 | + err = do_unlink_wh(h_dir, h_path); | |
31833 | + if (!err && dentry) | |
31834 | + au_set_dbwh(dentry, -1); | |
31835 | + | |
31836 | + return err; | |
31837 | +} | |
31838 | + | |
31839 | +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh, | |
31840 | + struct au_branch *br) | |
31841 | +{ | |
31842 | + int err; | |
31843 | + struct path h_path = { | |
86dc4139 | 31844 | + .mnt = au_br_mnt(br) |
1facf9fc | 31845 | + }; |
31846 | + | |
31847 | + err = 0; | |
b4510431 | 31848 | + h_path.dentry = vfsub_lkup_one(wh, h_parent); |
1facf9fc | 31849 | + if (IS_ERR(h_path.dentry)) |
31850 | + err = PTR_ERR(h_path.dentry); | |
31851 | + else { | |
31852 | + if (h_path.dentry->d_inode | |
31853 | + && S_ISREG(h_path.dentry->d_inode->i_mode)) | |
31854 | + err = do_unlink_wh(h_parent->d_inode, &h_path); | |
31855 | + dput(h_path.dentry); | |
31856 | + } | |
31857 | + | |
31858 | + return err; | |
31859 | +} | |
31860 | + | |
31861 | +/* ---------------------------------------------------------------------- */ | |
31862 | +/* | |
31863 | + * initialize/clean whiteout for a branch | |
31864 | + */ | |
31865 | + | |
31866 | +static void au_wh_clean(struct inode *h_dir, struct path *whpath, | |
31867 | + const int isdir) | |
31868 | +{ | |
31869 | + int err; | |
523b37e3 | 31870 | + struct inode *delegated; |
1facf9fc | 31871 | + |
31872 | + if (!whpath->dentry->d_inode) | |
31873 | + return; | |
31874 | + | |
86dc4139 AM |
31875 | + if (isdir) |
31876 | + err = vfsub_rmdir(h_dir, whpath); | |
523b37e3 AM |
31877 | + else { |
31878 | + delegated = NULL; | |
31879 | + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0); | |
31880 | + if (unlikely(err == -EWOULDBLOCK)) { | |
31881 | + pr_warn("cannot retry for NFSv4 delegation" | |
31882 | + " for an internal unlink\n"); | |
31883 | + iput(delegated); | |
31884 | + } | |
31885 | + } | |
1facf9fc | 31886 | + if (unlikely(err)) |
523b37e3 AM |
31887 | + pr_warn("failed removing %pd (%d), ignored.\n", |
31888 | + whpath->dentry, err); | |
1facf9fc | 31889 | +} |
31890 | + | |
31891 | +static int test_linkable(struct dentry *h_root) | |
31892 | +{ | |
31893 | + struct inode *h_dir = h_root->d_inode; | |
31894 | + | |
31895 | + if (h_dir->i_op->link) | |
31896 | + return 0; | |
31897 | + | |
523b37e3 AM |
31898 | + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n", |
31899 | + h_root, au_sbtype(h_root->d_sb)); | |
1facf9fc | 31900 | + return -ENOSYS; |
31901 | +} | |
31902 | + | |
31903 | +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */ | |
31904 | +static int au_whdir(struct inode *h_dir, struct path *path) | |
31905 | +{ | |
31906 | + int err; | |
31907 | + | |
31908 | + err = -EEXIST; | |
31909 | + if (!path->dentry->d_inode) { | |
31910 | + int mode = S_IRWXU; | |
31911 | + | |
31912 | + if (au_test_nfs(path->dentry->d_sb)) | |
31913 | + mode |= S_IXUGO; | |
86dc4139 | 31914 | + err = vfsub_mkdir(h_dir, path, mode); |
1facf9fc | 31915 | + } else if (S_ISDIR(path->dentry->d_inode->i_mode)) |
31916 | + err = 0; | |
31917 | + else | |
523b37e3 | 31918 | + pr_err("unknown %pd exists\n", path->dentry); |
1facf9fc | 31919 | + |
31920 | + return err; | |
31921 | +} | |
31922 | + | |
31923 | +struct au_wh_base { | |
31924 | + const struct qstr *name; | |
31925 | + struct dentry *dentry; | |
31926 | +}; | |
31927 | + | |
31928 | +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[], | |
31929 | + struct path *h_path) | |
31930 | +{ | |
31931 | + h_path->dentry = base[AuBrWh_BASE].dentry; | |
31932 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
31933 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
31934 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
31935 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
31936 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
31937 | +} | |
31938 | + | |
31939 | +/* | |
31940 | + * returns tri-state, | |
c1595e42 | 31941 | + * minus: error, caller should print the message |
1facf9fc | 31942 | + * zero: succuess |
c1595e42 | 31943 | + * plus: error, caller should NOT print the message |
1facf9fc | 31944 | + */ |
31945 | +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr, | |
31946 | + int do_plink, struct au_wh_base base[], | |
31947 | + struct path *h_path) | |
31948 | +{ | |
31949 | + int err; | |
31950 | + struct inode *h_dir; | |
31951 | + | |
31952 | + h_dir = h_root->d_inode; | |
31953 | + h_path->dentry = base[AuBrWh_BASE].dentry; | |
31954 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
31955 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
31956 | + if (do_plink) { | |
31957 | + err = test_linkable(h_root); | |
31958 | + if (unlikely(err)) { | |
31959 | + err = 1; | |
31960 | + goto out; | |
31961 | + } | |
31962 | + | |
31963 | + err = au_whdir(h_dir, h_path); | |
31964 | + if (unlikely(err)) | |
31965 | + goto out; | |
31966 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
31967 | + } else | |
31968 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
31969 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
31970 | + err = au_whdir(h_dir, h_path); | |
31971 | + if (unlikely(err)) | |
31972 | + goto out; | |
31973 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
31974 | + | |
4f0767ce | 31975 | +out: |
1facf9fc | 31976 | + return err; |
31977 | +} | |
31978 | + | |
31979 | +/* | |
31980 | + * for the moment, aufs supports the branch filesystem which does not support | |
31981 | + * link(2). testing on FAT which does not support i_op->setattr() fully either, | |
31982 | + * copyup failed. finally, such filesystem will not be used as the writable | |
31983 | + * branch. | |
31984 | + * | |
31985 | + * returns tri-state, see above. | |
31986 | + */ | |
31987 | +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr, | |
31988 | + int do_plink, struct au_wh_base base[], | |
31989 | + struct path *h_path) | |
31990 | +{ | |
31991 | + int err; | |
31992 | + struct inode *h_dir; | |
31993 | + | |
1308ab2a | 31994 | + WbrWhMustWriteLock(wbr); |
31995 | + | |
1facf9fc | 31996 | + err = test_linkable(h_root); |
31997 | + if (unlikely(err)) { | |
31998 | + err = 1; | |
31999 | + goto out; | |
32000 | + } | |
32001 | + | |
32002 | + /* | |
32003 | + * todo: should this create be done in /sbin/mount.aufs helper? | |
32004 | + */ | |
32005 | + err = -EEXIST; | |
32006 | + h_dir = h_root->d_inode; | |
32007 | + if (!base[AuBrWh_BASE].dentry->d_inode) { | |
86dc4139 AM |
32008 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
32009 | + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true); | |
1facf9fc | 32010 | + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode)) |
32011 | + err = 0; | |
32012 | + else | |
523b37e3 | 32013 | + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry); |
1facf9fc | 32014 | + if (unlikely(err)) |
32015 | + goto out; | |
32016 | + | |
32017 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
32018 | + if (do_plink) { | |
32019 | + err = au_whdir(h_dir, h_path); | |
32020 | + if (unlikely(err)) | |
32021 | + goto out; | |
32022 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
32023 | + } else | |
32024 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
32025 | + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry); | |
32026 | + | |
32027 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
32028 | + err = au_whdir(h_dir, h_path); | |
32029 | + if (unlikely(err)) | |
32030 | + goto out; | |
32031 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
32032 | + | |
4f0767ce | 32033 | +out: |
1facf9fc | 32034 | + return err; |
32035 | +} | |
32036 | + | |
32037 | +/* | |
32038 | + * initialize the whiteout base file/dir for @br. | |
32039 | + */ | |
86dc4139 | 32040 | +int au_wh_init(struct au_branch *br, struct super_block *sb) |
1facf9fc | 32041 | +{ |
32042 | + int err, i; | |
32043 | + const unsigned char do_plink | |
32044 | + = !!au_opt_test(au_mntflags(sb), PLINK); | |
1facf9fc | 32045 | + struct inode *h_dir; |
86dc4139 AM |
32046 | + struct path path = br->br_path; |
32047 | + struct dentry *h_root = path.dentry; | |
1facf9fc | 32048 | + struct au_wbr *wbr = br->br_wbr; |
32049 | + static const struct qstr base_name[] = { | |
0c3ec466 AM |
32050 | + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME, |
32051 | + sizeof(AUFS_BASE_NAME) - 1), | |
32052 | + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME, | |
32053 | + sizeof(AUFS_PLINKDIR_NAME) - 1), | |
32054 | + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME, | |
32055 | + sizeof(AUFS_ORPHDIR_NAME) - 1) | |
1facf9fc | 32056 | + }; |
32057 | + struct au_wh_base base[] = { | |
32058 | + [AuBrWh_BASE] = { | |
32059 | + .name = base_name + AuBrWh_BASE, | |
32060 | + .dentry = NULL | |
32061 | + }, | |
32062 | + [AuBrWh_PLINK] = { | |
32063 | + .name = base_name + AuBrWh_PLINK, | |
32064 | + .dentry = NULL | |
32065 | + }, | |
32066 | + [AuBrWh_ORPH] = { | |
32067 | + .name = base_name + AuBrWh_ORPH, | |
32068 | + .dentry = NULL | |
32069 | + } | |
32070 | + }; | |
32071 | + | |
1308ab2a | 32072 | + if (wbr) |
32073 | + WbrWhMustWriteLock(wbr); | |
1facf9fc | 32074 | + |
1facf9fc | 32075 | + for (i = 0; i < AuBrWh_Last; i++) { |
32076 | + /* doubly whiteouted */ | |
32077 | + struct dentry *d; | |
32078 | + | |
32079 | + d = au_wh_lkup(h_root, (void *)base[i].name, br); | |
32080 | + err = PTR_ERR(d); | |
32081 | + if (IS_ERR(d)) | |
32082 | + goto out; | |
32083 | + | |
32084 | + base[i].dentry = d; | |
32085 | + AuDebugOn(wbr | |
32086 | + && wbr->wbr_wh[i] | |
32087 | + && wbr->wbr_wh[i] != base[i].dentry); | |
32088 | + } | |
32089 | + | |
32090 | + if (wbr) | |
32091 | + for (i = 0; i < AuBrWh_Last; i++) { | |
32092 | + dput(wbr->wbr_wh[i]); | |
32093 | + wbr->wbr_wh[i] = NULL; | |
32094 | + } | |
32095 | + | |
32096 | + err = 0; | |
1e00d052 | 32097 | + if (!au_br_writable(br->br_perm)) { |
4a4d8108 | 32098 | + h_dir = h_root->d_inode; |
1facf9fc | 32099 | + au_wh_init_ro(h_dir, base, &path); |
1e00d052 | 32100 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 32101 | + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path); |
32102 | + if (err > 0) | |
32103 | + goto out; | |
32104 | + else if (err) | |
32105 | + goto out_err; | |
1e00d052 | 32106 | + } else { |
1facf9fc | 32107 | + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path); |
32108 | + if (err > 0) | |
32109 | + goto out; | |
32110 | + else if (err) | |
32111 | + goto out_err; | |
1facf9fc | 32112 | + } |
32113 | + goto out; /* success */ | |
32114 | + | |
4f0767ce | 32115 | +out_err: |
523b37e3 AM |
32116 | + pr_err("an error(%d) on the writable branch %pd(%s)\n", |
32117 | + err, h_root, au_sbtype(h_root->d_sb)); | |
4f0767ce | 32118 | +out: |
1facf9fc | 32119 | + for (i = 0; i < AuBrWh_Last; i++) |
32120 | + dput(base[i].dentry); | |
32121 | + return err; | |
32122 | +} | |
32123 | + | |
32124 | +/* ---------------------------------------------------------------------- */ | |
32125 | +/* | |
32126 | + * whiteouts are all hard-linked usually. | |
32127 | + * when its link count reaches a ceiling, we create a new whiteout base | |
32128 | + * asynchronously. | |
32129 | + */ | |
32130 | + | |
32131 | +struct reinit_br_wh { | |
32132 | + struct super_block *sb; | |
32133 | + struct au_branch *br; | |
32134 | +}; | |
32135 | + | |
32136 | +static void reinit_br_wh(void *arg) | |
32137 | +{ | |
32138 | + int err; | |
32139 | + aufs_bindex_t bindex; | |
32140 | + struct path h_path; | |
32141 | + struct reinit_br_wh *a = arg; | |
32142 | + struct au_wbr *wbr; | |
523b37e3 | 32143 | + struct inode *dir, *delegated; |
1facf9fc | 32144 | + struct dentry *h_root; |
32145 | + struct au_hinode *hdir; | |
32146 | + | |
32147 | + err = 0; | |
32148 | + wbr = a->br->br_wbr; | |
32149 | + /* big aufs lock */ | |
32150 | + si_noflush_write_lock(a->sb); | |
32151 | + if (!au_br_writable(a->br->br_perm)) | |
32152 | + goto out; | |
32153 | + bindex = au_br_index(a->sb, a->br->br_id); | |
32154 | + if (unlikely(bindex < 0)) | |
32155 | + goto out; | |
32156 | + | |
1308ab2a | 32157 | + di_read_lock_parent(a->sb->s_root, AuLock_IR); |
1facf9fc | 32158 | + dir = a->sb->s_root->d_inode; |
1facf9fc | 32159 | + hdir = au_hi(dir, bindex); |
32160 | + h_root = au_h_dptr(a->sb->s_root, bindex); | |
86dc4139 | 32161 | + AuDebugOn(h_root != au_br_dentry(a->br)); |
1facf9fc | 32162 | + |
4a4d8108 | 32163 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 32164 | + wbr_wh_write_lock(wbr); |
32165 | + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode, | |
32166 | + h_root, a->br); | |
32167 | + if (!err) { | |
86dc4139 AM |
32168 | + h_path.dentry = wbr->wbr_whbase; |
32169 | + h_path.mnt = au_br_mnt(a->br); | |
523b37e3 AM |
32170 | + delegated = NULL; |
32171 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, | |
32172 | + /*force*/0); | |
32173 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32174 | + pr_warn("cannot retry for NFSv4 delegation" | |
32175 | + " for an internal unlink\n"); | |
32176 | + iput(delegated); | |
32177 | + } | |
1facf9fc | 32178 | + } else { |
523b37e3 | 32179 | + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase); |
1facf9fc | 32180 | + err = 0; |
32181 | + } | |
32182 | + dput(wbr->wbr_whbase); | |
32183 | + wbr->wbr_whbase = NULL; | |
32184 | + if (!err) | |
86dc4139 | 32185 | + err = au_wh_init(a->br, a->sb); |
1facf9fc | 32186 | + wbr_wh_write_unlock(wbr); |
4a4d8108 | 32187 | + au_hn_imtx_unlock(hdir); |
1308ab2a | 32188 | + di_read_unlock(a->sb->s_root, AuLock_IR); |
076b876e AM |
32189 | + if (!err) |
32190 | + au_fhsm_wrote(a->sb, bindex, /*force*/0); | |
1facf9fc | 32191 | + |
4f0767ce | 32192 | +out: |
1facf9fc | 32193 | + if (wbr) |
32194 | + atomic_dec(&wbr->wbr_wh_running); | |
32195 | + atomic_dec(&a->br->br_count); | |
1facf9fc | 32196 | + si_write_unlock(a->sb); |
027c5e7a | 32197 | + au_nwt_done(&au_sbi(a->sb)->si_nowait); |
1facf9fc | 32198 | + kfree(arg); |
32199 | + if (unlikely(err)) | |
32200 | + AuIOErr("err %d\n", err); | |
32201 | +} | |
32202 | + | |
32203 | +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br) | |
32204 | +{ | |
32205 | + int do_dec, wkq_err; | |
32206 | + struct reinit_br_wh *arg; | |
32207 | + | |
32208 | + do_dec = 1; | |
32209 | + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1) | |
32210 | + goto out; | |
32211 | + | |
32212 | + /* ignore ENOMEM */ | |
32213 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
32214 | + if (arg) { | |
32215 | + /* | |
32216 | + * dec(wh_running), kfree(arg) and dec(br_count) | |
32217 | + * in reinit function | |
32218 | + */ | |
32219 | + arg->sb = sb; | |
32220 | + arg->br = br; | |
32221 | + atomic_inc(&br->br_count); | |
53392da6 | 32222 | + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0); |
1facf9fc | 32223 | + if (unlikely(wkq_err)) { |
32224 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
32225 | + atomic_dec(&br->br_count); | |
32226 | + kfree(arg); | |
32227 | + } | |
32228 | + do_dec = 0; | |
32229 | + } | |
32230 | + | |
4f0767ce | 32231 | +out: |
1facf9fc | 32232 | + if (do_dec) |
32233 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
32234 | +} | |
32235 | + | |
32236 | +/* ---------------------------------------------------------------------- */ | |
32237 | + | |
32238 | +/* | |
32239 | + * create the whiteout @wh. | |
32240 | + */ | |
32241 | +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex, | |
32242 | + struct dentry *wh) | |
32243 | +{ | |
32244 | + int err; | |
32245 | + struct path h_path = { | |
32246 | + .dentry = wh | |
32247 | + }; | |
32248 | + struct au_branch *br; | |
32249 | + struct au_wbr *wbr; | |
32250 | + struct dentry *h_parent; | |
523b37e3 | 32251 | + struct inode *h_dir, *delegated; |
1facf9fc | 32252 | + |
32253 | + h_parent = wh->d_parent; /* dir inode is locked */ | |
32254 | + h_dir = h_parent->d_inode; | |
32255 | + IMustLock(h_dir); | |
32256 | + | |
32257 | + br = au_sbr(sb, bindex); | |
86dc4139 | 32258 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 32259 | + wbr = br->br_wbr; |
32260 | + wbr_wh_read_lock(wbr); | |
32261 | + if (wbr->wbr_whbase) { | |
523b37e3 AM |
32262 | + delegated = NULL; |
32263 | + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated); | |
32264 | + if (unlikely(err == -EWOULDBLOCK)) { | |
32265 | + pr_warn("cannot retry for NFSv4 delegation" | |
32266 | + " for an internal link\n"); | |
32267 | + iput(delegated); | |
32268 | + } | |
1facf9fc | 32269 | + if (!err || err != -EMLINK) |
32270 | + goto out; | |
32271 | + | |
32272 | + /* link count full. re-initialize br_whbase. */ | |
32273 | + kick_reinit_br_wh(sb, br); | |
32274 | + } | |
32275 | + | |
32276 | + /* return this error in this context */ | |
b4510431 | 32277 | + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true); |
076b876e AM |
32278 | + if (!err) |
32279 | + au_fhsm_wrote(sb, bindex, /*force*/0); | |
1facf9fc | 32280 | + |
4f0767ce | 32281 | +out: |
1facf9fc | 32282 | + wbr_wh_read_unlock(wbr); |
32283 | + return err; | |
32284 | +} | |
32285 | + | |
32286 | +/* ---------------------------------------------------------------------- */ | |
32287 | + | |
32288 | +/* | |
32289 | + * create or remove the diropq. | |
32290 | + */ | |
32291 | +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex, | |
32292 | + unsigned int flags) | |
32293 | +{ | |
32294 | + struct dentry *opq_dentry, *h_dentry; | |
32295 | + struct super_block *sb; | |
32296 | + struct au_branch *br; | |
32297 | + int err; | |
32298 | + | |
32299 | + sb = dentry->d_sb; | |
32300 | + br = au_sbr(sb, bindex); | |
32301 | + h_dentry = au_h_dptr(dentry, bindex); | |
b4510431 | 32302 | + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry); |
1facf9fc | 32303 | + if (IS_ERR(opq_dentry)) |
32304 | + goto out; | |
32305 | + | |
32306 | + if (au_ftest_diropq(flags, CREATE)) { | |
32307 | + err = link_or_create_wh(sb, bindex, opq_dentry); | |
32308 | + if (!err) { | |
32309 | + au_set_dbdiropq(dentry, bindex); | |
32310 | + goto out; /* success */ | |
32311 | + } | |
32312 | + } else { | |
32313 | + struct path tmp = { | |
32314 | + .dentry = opq_dentry, | |
86dc4139 | 32315 | + .mnt = au_br_mnt(br) |
1facf9fc | 32316 | + }; |
32317 | + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp); | |
32318 | + if (!err) | |
32319 | + au_set_dbdiropq(dentry, -1); | |
32320 | + } | |
32321 | + dput(opq_dentry); | |
32322 | + opq_dentry = ERR_PTR(err); | |
32323 | + | |
4f0767ce | 32324 | +out: |
1facf9fc | 32325 | + return opq_dentry; |
32326 | +} | |
32327 | + | |
32328 | +struct do_diropq_args { | |
32329 | + struct dentry **errp; | |
32330 | + struct dentry *dentry; | |
32331 | + aufs_bindex_t bindex; | |
32332 | + unsigned int flags; | |
32333 | +}; | |
32334 | + | |
32335 | +static void call_do_diropq(void *args) | |
32336 | +{ | |
32337 | + struct do_diropq_args *a = args; | |
32338 | + *a->errp = do_diropq(a->dentry, a->bindex, a->flags); | |
32339 | +} | |
32340 | + | |
32341 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
32342 | + unsigned int flags) | |
32343 | +{ | |
32344 | + struct dentry *diropq, *h_dentry; | |
32345 | + | |
32346 | + h_dentry = au_h_dptr(dentry, bindex); | |
32347 | + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE)) | |
32348 | + diropq = do_diropq(dentry, bindex, flags); | |
32349 | + else { | |
32350 | + int wkq_err; | |
32351 | + struct do_diropq_args args = { | |
32352 | + .errp = &diropq, | |
32353 | + .dentry = dentry, | |
32354 | + .bindex = bindex, | |
32355 | + .flags = flags | |
32356 | + }; | |
32357 | + | |
32358 | + wkq_err = au_wkq_wait(call_do_diropq, &args); | |
32359 | + if (unlikely(wkq_err)) | |
32360 | + diropq = ERR_PTR(wkq_err); | |
32361 | + } | |
32362 | + | |
32363 | + return diropq; | |
32364 | +} | |
32365 | + | |
32366 | +/* ---------------------------------------------------------------------- */ | |
32367 | + | |
32368 | +/* | |
32369 | + * lookup whiteout dentry. | |
32370 | + * @h_parent: lower parent dentry which must exist and be locked | |
32371 | + * @base_name: name of dentry which will be whiteouted | |
32372 | + * returns dentry for whiteout. | |
32373 | + */ | |
32374 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
32375 | + struct au_branch *br) | |
32376 | +{ | |
32377 | + int err; | |
32378 | + struct qstr wh_name; | |
32379 | + struct dentry *wh_dentry; | |
32380 | + | |
32381 | + err = au_wh_name_alloc(&wh_name, base_name); | |
32382 | + wh_dentry = ERR_PTR(err); | |
32383 | + if (!err) { | |
b4510431 | 32384 | + wh_dentry = vfsub_lkup_one(&wh_name, h_parent); |
1facf9fc | 32385 | + kfree(wh_name.name); |
32386 | + } | |
32387 | + return wh_dentry; | |
32388 | +} | |
32389 | + | |
32390 | +/* | |
32391 | + * link/create a whiteout for @dentry on @bindex. | |
32392 | + */ | |
32393 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
32394 | + struct dentry *h_parent) | |
32395 | +{ | |
32396 | + struct dentry *wh_dentry; | |
32397 | + struct super_block *sb; | |
32398 | + int err; | |
32399 | + | |
32400 | + sb = dentry->d_sb; | |
32401 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex)); | |
32402 | + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) { | |
32403 | + err = link_or_create_wh(sb, bindex, wh_dentry); | |
076b876e | 32404 | + if (!err) { |
1facf9fc | 32405 | + au_set_dbwh(dentry, bindex); |
076b876e AM |
32406 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
32407 | + } else { | |
1facf9fc | 32408 | + dput(wh_dentry); |
32409 | + wh_dentry = ERR_PTR(err); | |
32410 | + } | |
32411 | + } | |
32412 | + | |
32413 | + return wh_dentry; | |
32414 | +} | |
32415 | + | |
32416 | +/* ---------------------------------------------------------------------- */ | |
32417 | + | |
32418 | +/* Delete all whiteouts in this directory on branch bindex. */ | |
32419 | +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist, | |
32420 | + aufs_bindex_t bindex, struct au_branch *br) | |
32421 | +{ | |
32422 | + int err; | |
32423 | + unsigned long ul, n; | |
32424 | + struct qstr wh_name; | |
32425 | + char *p; | |
32426 | + struct hlist_head *head; | |
c06a8ce3 | 32427 | + struct au_vdir_wh *pos; |
1facf9fc | 32428 | + struct au_vdir_destr *str; |
32429 | + | |
32430 | + err = -ENOMEM; | |
537831f9 | 32431 | + p = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 32432 | + wh_name.name = p; |
32433 | + if (unlikely(!wh_name.name)) | |
32434 | + goto out; | |
32435 | + | |
32436 | + err = 0; | |
32437 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
32438 | + p += AUFS_WH_PFX_LEN; | |
32439 | + n = whlist->nh_num; | |
32440 | + head = whlist->nh_head; | |
32441 | + for (ul = 0; !err && ul < n; ul++, head++) { | |
c06a8ce3 AM |
32442 | + hlist_for_each_entry(pos, head, wh_hash) { |
32443 | + if (pos->wh_bindex != bindex) | |
1facf9fc | 32444 | + continue; |
32445 | + | |
c06a8ce3 | 32446 | + str = &pos->wh_str; |
1facf9fc | 32447 | + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) { |
32448 | + memcpy(p, str->name, str->len); | |
32449 | + wh_name.len = AUFS_WH_PFX_LEN + str->len; | |
32450 | + err = unlink_wh_name(h_dentry, &wh_name, br); | |
32451 | + if (!err) | |
32452 | + continue; | |
32453 | + break; | |
32454 | + } | |
32455 | + AuIOErr("whiteout name too long %.*s\n", | |
32456 | + str->len, str->name); | |
32457 | + err = -EIO; | |
32458 | + break; | |
32459 | + } | |
32460 | + } | |
537831f9 | 32461 | + free_page((unsigned long)wh_name.name); |
1facf9fc | 32462 | + |
4f0767ce | 32463 | +out: |
1facf9fc | 32464 | + return err; |
32465 | +} | |
32466 | + | |
32467 | +struct del_wh_children_args { | |
32468 | + int *errp; | |
32469 | + struct dentry *h_dentry; | |
1308ab2a | 32470 | + struct au_nhash *whlist; |
1facf9fc | 32471 | + aufs_bindex_t bindex; |
32472 | + struct au_branch *br; | |
32473 | +}; | |
32474 | + | |
32475 | +static void call_del_wh_children(void *args) | |
32476 | +{ | |
32477 | + struct del_wh_children_args *a = args; | |
1308ab2a | 32478 | + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br); |
1facf9fc | 32479 | +} |
32480 | + | |
32481 | +/* ---------------------------------------------------------------------- */ | |
32482 | + | |
32483 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp) | |
32484 | +{ | |
32485 | + struct au_whtmp_rmdir *whtmp; | |
dece6358 | 32486 | + int err; |
1308ab2a | 32487 | + unsigned int rdhash; |
dece6358 AM |
32488 | + |
32489 | + SiMustAnyLock(sb); | |
1facf9fc | 32490 | + |
32491 | + whtmp = kmalloc(sizeof(*whtmp), gfp); | |
dece6358 AM |
32492 | + if (unlikely(!whtmp)) { |
32493 | + whtmp = ERR_PTR(-ENOMEM); | |
1facf9fc | 32494 | + goto out; |
dece6358 | 32495 | + } |
1facf9fc | 32496 | + |
32497 | + whtmp->dir = NULL; | |
027c5e7a | 32498 | + whtmp->br = NULL; |
1facf9fc | 32499 | + whtmp->wh_dentry = NULL; |
1308ab2a | 32500 | + /* no estimation for dir size */ |
32501 | + rdhash = au_sbi(sb)->si_rdhash; | |
32502 | + if (!rdhash) | |
32503 | + rdhash = AUFS_RDHASH_DEF; | |
32504 | + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp); | |
32505 | + if (unlikely(err)) { | |
32506 | + kfree(whtmp); | |
32507 | + whtmp = ERR_PTR(err); | |
32508 | + } | |
dece6358 | 32509 | + |
4f0767ce | 32510 | +out: |
dece6358 | 32511 | + return whtmp; |
1facf9fc | 32512 | +} |
32513 | + | |
32514 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp) | |
32515 | +{ | |
027c5e7a AM |
32516 | + if (whtmp->br) |
32517 | + atomic_dec(&whtmp->br->br_count); | |
1facf9fc | 32518 | + dput(whtmp->wh_dentry); |
32519 | + iput(whtmp->dir); | |
dece6358 | 32520 | + au_nhash_wh_free(&whtmp->whlist); |
1facf9fc | 32521 | + kfree(whtmp); |
32522 | +} | |
32523 | + | |
32524 | +/* | |
32525 | + * rmdir the whiteouted temporary named dir @h_dentry. | |
32526 | + * @whlist: whiteouted children. | |
32527 | + */ | |
32528 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32529 | + struct dentry *wh_dentry, struct au_nhash *whlist) | |
32530 | +{ | |
32531 | + int err; | |
32532 | + struct path h_tmp; | |
32533 | + struct inode *wh_inode, *h_dir; | |
32534 | + struct au_branch *br; | |
32535 | + | |
32536 | + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */ | |
32537 | + IMustLock(h_dir); | |
32538 | + | |
32539 | + br = au_sbr(dir->i_sb, bindex); | |
32540 | + wh_inode = wh_dentry->d_inode; | |
32541 | + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD); | |
32542 | + | |
32543 | + /* | |
32544 | + * someone else might change some whiteouts while we were sleeping. | |
32545 | + * it means this whlist may have an obsoleted entry. | |
32546 | + */ | |
32547 | + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE)) | |
32548 | + err = del_wh_children(wh_dentry, whlist, bindex, br); | |
32549 | + else { | |
32550 | + int wkq_err; | |
32551 | + struct del_wh_children_args args = { | |
32552 | + .errp = &err, | |
32553 | + .h_dentry = wh_dentry, | |
1308ab2a | 32554 | + .whlist = whlist, |
1facf9fc | 32555 | + .bindex = bindex, |
32556 | + .br = br | |
32557 | + }; | |
32558 | + | |
32559 | + wkq_err = au_wkq_wait(call_del_wh_children, &args); | |
32560 | + if (unlikely(wkq_err)) | |
32561 | + err = wkq_err; | |
32562 | + } | |
32563 | + mutex_unlock(&wh_inode->i_mutex); | |
32564 | + | |
32565 | + if (!err) { | |
32566 | + h_tmp.dentry = wh_dentry; | |
86dc4139 | 32567 | + h_tmp.mnt = au_br_mnt(br); |
1facf9fc | 32568 | + err = vfsub_rmdir(h_dir, &h_tmp); |
1facf9fc | 32569 | + } |
32570 | + | |
32571 | + if (!err) { | |
32572 | + if (au_ibstart(dir) == bindex) { | |
7f207e10 | 32573 | + /* todo: dir->i_mutex is necessary */ |
1facf9fc | 32574 | + au_cpup_attr_timesizes(dir); |
7f207e10 | 32575 | + vfsub_drop_nlink(dir); |
1facf9fc | 32576 | + } |
32577 | + return 0; /* success */ | |
32578 | + } | |
32579 | + | |
523b37e3 | 32580 | + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err); |
1facf9fc | 32581 | + return err; |
32582 | +} | |
32583 | + | |
32584 | +static void call_rmdir_whtmp(void *args) | |
32585 | +{ | |
32586 | + int err; | |
e49829fe | 32587 | + aufs_bindex_t bindex; |
1facf9fc | 32588 | + struct au_whtmp_rmdir *a = args; |
32589 | + struct super_block *sb; | |
32590 | + struct dentry *h_parent; | |
32591 | + struct inode *h_dir; | |
1facf9fc | 32592 | + struct au_hinode *hdir; |
32593 | + | |
32594 | + /* rmdir by nfsd may cause deadlock with this i_mutex */ | |
32595 | + /* mutex_lock(&a->dir->i_mutex); */ | |
e49829fe | 32596 | + err = -EROFS; |
1facf9fc | 32597 | + sb = a->dir->i_sb; |
e49829fe JR |
32598 | + si_read_lock(sb, !AuLock_FLUSH); |
32599 | + if (!au_br_writable(a->br->br_perm)) | |
32600 | + goto out; | |
32601 | + bindex = au_br_index(sb, a->br->br_id); | |
32602 | + if (unlikely(bindex < 0)) | |
1facf9fc | 32603 | + goto out; |
32604 | + | |
32605 | + err = -EIO; | |
1facf9fc | 32606 | + ii_write_lock_parent(a->dir); |
32607 | + h_parent = dget_parent(a->wh_dentry); | |
32608 | + h_dir = h_parent->d_inode; | |
e49829fe | 32609 | + hdir = au_hi(a->dir, bindex); |
86dc4139 AM |
32610 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); |
32611 | + if (unlikely(err)) | |
32612 | + goto out_mnt; | |
4a4d8108 | 32613 | + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT); |
e49829fe JR |
32614 | + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent, |
32615 | + a->br); | |
86dc4139 AM |
32616 | + if (!err) |
32617 | + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist); | |
4a4d8108 | 32618 | + au_hn_imtx_unlock(hdir); |
86dc4139 AM |
32619 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
32620 | + | |
32621 | +out_mnt: | |
1facf9fc | 32622 | + dput(h_parent); |
32623 | + ii_write_unlock(a->dir); | |
4f0767ce | 32624 | +out: |
1facf9fc | 32625 | + /* mutex_unlock(&a->dir->i_mutex); */ |
1facf9fc | 32626 | + au_whtmp_rmdir_free(a); |
027c5e7a AM |
32627 | + si_read_unlock(sb); |
32628 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
1facf9fc | 32629 | + if (unlikely(err)) |
32630 | + AuIOErr("err %d\n", err); | |
32631 | +} | |
32632 | + | |
32633 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32634 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args) | |
32635 | +{ | |
32636 | + int wkq_err; | |
e49829fe | 32637 | + struct super_block *sb; |
1facf9fc | 32638 | + |
32639 | + IMustLock(dir); | |
32640 | + | |
32641 | + /* all post-process will be done in do_rmdir_whtmp(). */ | |
e49829fe | 32642 | + sb = dir->i_sb; |
1facf9fc | 32643 | + args->dir = au_igrab(dir); |
e49829fe JR |
32644 | + args->br = au_sbr(sb, bindex); |
32645 | + atomic_inc(&args->br->br_count); | |
1facf9fc | 32646 | + args->wh_dentry = dget(wh_dentry); |
53392da6 | 32647 | + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0); |
1facf9fc | 32648 | + if (unlikely(wkq_err)) { |
523b37e3 | 32649 | + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err); |
1facf9fc | 32650 | + au_whtmp_rmdir_free(args); |
32651 | + } | |
32652 | +} | |
7f207e10 AM |
32653 | diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h |
32654 | --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 32655 | +++ linux/fs/aufs/whout.h 2015-01-25 13:00:38.634380408 +0100 |
076b876e | 32656 | @@ -0,0 +1,85 @@ |
1facf9fc | 32657 | +/* |
523b37e3 | 32658 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 32659 | + * |
32660 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32661 | + * it under the terms of the GNU General Public License as published by | |
32662 | + * the Free Software Foundation; either version 2 of the License, or | |
32663 | + * (at your option) any later version. | |
dece6358 AM |
32664 | + * |
32665 | + * This program is distributed in the hope that it will be useful, | |
32666 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32667 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32668 | + * GNU General Public License for more details. | |
32669 | + * | |
32670 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32671 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32672 | + */ |
32673 | + | |
32674 | +/* | |
32675 | + * whiteout for logical deletion and opaque directory | |
32676 | + */ | |
32677 | + | |
32678 | +#ifndef __AUFS_WHOUT_H__ | |
32679 | +#define __AUFS_WHOUT_H__ | |
32680 | + | |
32681 | +#ifdef __KERNEL__ | |
32682 | + | |
1facf9fc | 32683 | +#include "dir.h" |
32684 | + | |
32685 | +/* whout.c */ | |
32686 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name); | |
32687 | +struct au_branch; | |
076b876e AM |
32688 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio); |
32689 | +int au_diropq_test(struct dentry *h_dentry); | |
1facf9fc | 32690 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, |
32691 | + struct qstr *prefix); | |
32692 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br); | |
32693 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
32694 | + struct dentry *dentry); | |
86dc4139 | 32695 | +int au_wh_init(struct au_branch *br, struct super_block *sb); |
1facf9fc | 32696 | + |
32697 | +/* diropq flags */ | |
32698 | +#define AuDiropq_CREATE 1 | |
32699 | +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name) | |
7f207e10 AM |
32700 | +#define au_fset_diropq(flags, name) \ |
32701 | + do { (flags) |= AuDiropq_##name; } while (0) | |
32702 | +#define au_fclr_diropq(flags, name) \ | |
32703 | + do { (flags) &= ~AuDiropq_##name; } while (0) | |
1facf9fc | 32704 | + |
32705 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
32706 | + unsigned int flags); | |
32707 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
32708 | + struct au_branch *br); | |
32709 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
32710 | + struct dentry *h_parent); | |
32711 | + | |
32712 | +/* real rmdir for the whiteout-ed dir */ | |
32713 | +struct au_whtmp_rmdir { | |
32714 | + struct inode *dir; | |
e49829fe | 32715 | + struct au_branch *br; |
1facf9fc | 32716 | + struct dentry *wh_dentry; |
dece6358 | 32717 | + struct au_nhash whlist; |
1facf9fc | 32718 | +}; |
32719 | + | |
32720 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp); | |
32721 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp); | |
32722 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32723 | + struct dentry *wh_dentry, struct au_nhash *whlist); | |
32724 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
32725 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args); | |
32726 | + | |
32727 | +/* ---------------------------------------------------------------------- */ | |
32728 | + | |
32729 | +static inline struct dentry *au_diropq_create(struct dentry *dentry, | |
32730 | + aufs_bindex_t bindex) | |
32731 | +{ | |
32732 | + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE); | |
32733 | +} | |
32734 | + | |
32735 | +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex) | |
32736 | +{ | |
32737 | + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE)); | |
32738 | +} | |
32739 | + | |
32740 | +#endif /* __KERNEL__ */ | |
32741 | +#endif /* __AUFS_WHOUT_H__ */ | |
7f207e10 AM |
32742 | diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c |
32743 | --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 32744 | +++ linux/fs/aufs/wkq.c 2015-01-25 13:00:38.634380408 +0100 |
38d290e6 | 32745 | @@ -0,0 +1,213 @@ |
1facf9fc | 32746 | +/* |
523b37e3 | 32747 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 32748 | + * |
32749 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32750 | + * it under the terms of the GNU General Public License as published by | |
32751 | + * the Free Software Foundation; either version 2 of the License, or | |
32752 | + * (at your option) any later version. | |
dece6358 AM |
32753 | + * |
32754 | + * This program is distributed in the hope that it will be useful, | |
32755 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32756 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32757 | + * GNU General Public License for more details. | |
32758 | + * | |
32759 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32760 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32761 | + */ |
32762 | + | |
32763 | +/* | |
32764 | + * workqueue for asynchronous/super-io operations | |
32765 | + * todo: try new dredential scheme | |
32766 | + */ | |
32767 | + | |
dece6358 | 32768 | +#include <linux/module.h> |
1facf9fc | 32769 | +#include "aufs.h" |
32770 | + | |
9dbd164d | 32771 | +/* internal workqueue named AUFS_WKQ_NAME */ |
b752ccd1 | 32772 | + |
9dbd164d | 32773 | +static struct workqueue_struct *au_wkq; |
1facf9fc | 32774 | + |
32775 | +struct au_wkinfo { | |
32776 | + struct work_struct wk; | |
7f207e10 | 32777 | + struct kobject *kobj; |
1facf9fc | 32778 | + |
32779 | + unsigned int flags; /* see wkq.h */ | |
32780 | + | |
32781 | + au_wkq_func_t func; | |
32782 | + void *args; | |
32783 | + | |
1facf9fc | 32784 | + struct completion *comp; |
32785 | +}; | |
32786 | + | |
32787 | +/* ---------------------------------------------------------------------- */ | |
32788 | + | |
1facf9fc | 32789 | +static void wkq_func(struct work_struct *wk) |
32790 | +{ | |
32791 | + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk); | |
32792 | + | |
2dfbb274 | 32793 | + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)); |
7f207e10 AM |
32794 | + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY); |
32795 | + | |
1facf9fc | 32796 | + wkinfo->func(wkinfo->args); |
1facf9fc | 32797 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) |
32798 | + complete(wkinfo->comp); | |
32799 | + else { | |
7f207e10 | 32800 | + kobject_put(wkinfo->kobj); |
9dbd164d | 32801 | + module_put(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 32802 | + kfree(wkinfo); |
32803 | + } | |
32804 | +} | |
32805 | + | |
32806 | +/* | |
32807 | + * Since struct completion is large, try allocating it dynamically. | |
32808 | + */ | |
c2b27bf2 | 32809 | +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */ |
1facf9fc | 32810 | +#define AuWkqCompDeclare(name) struct completion *comp = NULL |
32811 | + | |
32812 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
32813 | +{ | |
32814 | + *comp = kmalloc(sizeof(**comp), GFP_NOFS); | |
32815 | + if (*comp) { | |
32816 | + init_completion(*comp); | |
32817 | + wkinfo->comp = *comp; | |
32818 | + return 0; | |
32819 | + } | |
32820 | + return -ENOMEM; | |
32821 | +} | |
32822 | + | |
32823 | +static void au_wkq_comp_free(struct completion *comp) | |
32824 | +{ | |
32825 | + kfree(comp); | |
32826 | +} | |
32827 | + | |
32828 | +#else | |
32829 | + | |
32830 | +/* no braces */ | |
32831 | +#define AuWkqCompDeclare(name) \ | |
32832 | + DECLARE_COMPLETION_ONSTACK(_ ## name); \ | |
32833 | + struct completion *comp = &_ ## name | |
32834 | + | |
32835 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
32836 | +{ | |
32837 | + wkinfo->comp = *comp; | |
32838 | + return 0; | |
32839 | +} | |
32840 | + | |
32841 | +static void au_wkq_comp_free(struct completion *comp __maybe_unused) | |
32842 | +{ | |
32843 | + /* empty */ | |
32844 | +} | |
32845 | +#endif /* 4KSTACKS */ | |
32846 | + | |
53392da6 | 32847 | +static void au_wkq_run(struct au_wkinfo *wkinfo) |
1facf9fc | 32848 | +{ |
53392da6 AM |
32849 | + if (au_ftest_wkq(wkinfo->flags, NEST)) { |
32850 | + if (au_wkq_test()) { | |
38d290e6 JR |
32851 | + AuWarn1("wkq from wkq, unless silly-rename on NFS," |
32852 | + " due to a dead dir by UDBA?\n"); | |
53392da6 AM |
32853 | + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT)); |
32854 | + } | |
32855 | + } else | |
32856 | + au_dbg_verify_kthread(); | |
32857 | + | |
32858 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) { | |
a1f66529 | 32859 | + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func); |
9dbd164d | 32860 | + queue_work(au_wkq, &wkinfo->wk); |
4a4d8108 AM |
32861 | + } else { |
32862 | + INIT_WORK(&wkinfo->wk, wkq_func); | |
32863 | + schedule_work(&wkinfo->wk); | |
32864 | + } | |
1facf9fc | 32865 | +} |
32866 | + | |
7f207e10 AM |
32867 | +/* |
32868 | + * Be careful. It is easy to make deadlock happen. | |
32869 | + * processA: lock, wkq and wait | |
32870 | + * processB: wkq and wait, lock in wkq | |
32871 | + * --> deadlock | |
32872 | + */ | |
b752ccd1 | 32873 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args) |
1facf9fc | 32874 | +{ |
32875 | + int err; | |
32876 | + AuWkqCompDeclare(comp); | |
32877 | + struct au_wkinfo wkinfo = { | |
b752ccd1 | 32878 | + .flags = flags, |
1facf9fc | 32879 | + .func = func, |
32880 | + .args = args | |
32881 | + }; | |
32882 | + | |
32883 | + err = au_wkq_comp_alloc(&wkinfo, &comp); | |
32884 | + if (!err) { | |
53392da6 | 32885 | + au_wkq_run(&wkinfo); |
1facf9fc | 32886 | + /* no timeout, no interrupt */ |
32887 | + wait_for_completion(wkinfo.comp); | |
32888 | + au_wkq_comp_free(comp); | |
4a4d8108 | 32889 | + destroy_work_on_stack(&wkinfo.wk); |
1facf9fc | 32890 | + } |
32891 | + | |
32892 | + return err; | |
32893 | + | |
32894 | +} | |
32895 | + | |
027c5e7a AM |
32896 | +/* |
32897 | + * Note: dget/dput() in func for aufs dentries are not supported. It will be a | |
32898 | + * problem in a concurrent umounting. | |
32899 | + */ | |
53392da6 AM |
32900 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
32901 | + unsigned int flags) | |
1facf9fc | 32902 | +{ |
32903 | + int err; | |
32904 | + struct au_wkinfo *wkinfo; | |
32905 | + | |
32906 | + atomic_inc(&au_sbi(sb)->si_nowait.nw_len); | |
32907 | + | |
32908 | + /* | |
32909 | + * wkq_func() must free this wkinfo. | |
32910 | + * it highly depends upon the implementation of workqueue. | |
32911 | + */ | |
32912 | + err = 0; | |
32913 | + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS); | |
32914 | + if (wkinfo) { | |
7f207e10 | 32915 | + wkinfo->kobj = &au_sbi(sb)->si_kobj; |
53392da6 | 32916 | + wkinfo->flags = flags & ~AuWkq_WAIT; |
1facf9fc | 32917 | + wkinfo->func = func; |
32918 | + wkinfo->args = args; | |
32919 | + wkinfo->comp = NULL; | |
7f207e10 | 32920 | + kobject_get(wkinfo->kobj); |
9dbd164d | 32921 | + __module_get(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 32922 | + |
53392da6 | 32923 | + au_wkq_run(wkinfo); |
1facf9fc | 32924 | + } else { |
32925 | + err = -ENOMEM; | |
e49829fe | 32926 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 32927 | + } |
32928 | + | |
32929 | + return err; | |
32930 | +} | |
32931 | + | |
32932 | +/* ---------------------------------------------------------------------- */ | |
32933 | + | |
32934 | +void au_nwt_init(struct au_nowait_tasks *nwt) | |
32935 | +{ | |
32936 | + atomic_set(&nwt->nw_len, 0); | |
4a4d8108 | 32937 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 32938 | + init_waitqueue_head(&nwt->nw_wq); |
32939 | +} | |
32940 | + | |
32941 | +void au_wkq_fin(void) | |
32942 | +{ | |
9dbd164d | 32943 | + destroy_workqueue(au_wkq); |
1facf9fc | 32944 | +} |
32945 | + | |
32946 | +int __init au_wkq_init(void) | |
32947 | +{ | |
9dbd164d | 32948 | + int err; |
b752ccd1 AM |
32949 | + |
32950 | + err = 0; | |
86dc4139 | 32951 | + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE); |
9dbd164d AM |
32952 | + if (IS_ERR(au_wkq)) |
32953 | + err = PTR_ERR(au_wkq); | |
32954 | + else if (!au_wkq) | |
32955 | + err = -ENOMEM; | |
b752ccd1 AM |
32956 | + |
32957 | + return err; | |
1facf9fc | 32958 | +} |
7f207e10 AM |
32959 | diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h |
32960 | --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 | 32961 | +++ linux/fs/aufs/wkq.h 2015-01-25 13:00:38.634380408 +0100 |
523b37e3 | 32962 | @@ -0,0 +1,91 @@ |
1facf9fc | 32963 | +/* |
523b37e3 | 32964 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 32965 | + * |
32966 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32967 | + * it under the terms of the GNU General Public License as published by | |
32968 | + * the Free Software Foundation; either version 2 of the License, or | |
32969 | + * (at your option) any later version. | |
dece6358 AM |
32970 | + * |
32971 | + * This program is distributed in the hope that it will be useful, | |
32972 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32973 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32974 | + * GNU General Public License for more details. | |
32975 | + * | |
32976 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32977 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32978 | + */ |
32979 | + | |
32980 | +/* | |
32981 | + * workqueue for asynchronous/super-io operations | |
32982 | + * todo: try new credentials management scheme | |
32983 | + */ | |
32984 | + | |
32985 | +#ifndef __AUFS_WKQ_H__ | |
32986 | +#define __AUFS_WKQ_H__ | |
32987 | + | |
32988 | +#ifdef __KERNEL__ | |
32989 | + | |
dece6358 AM |
32990 | +struct super_block; |
32991 | + | |
1facf9fc | 32992 | +/* ---------------------------------------------------------------------- */ |
32993 | + | |
32994 | +/* | |
32995 | + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue | |
32996 | + */ | |
32997 | +struct au_nowait_tasks { | |
32998 | + atomic_t nw_len; | |
32999 | + wait_queue_head_t nw_wq; | |
33000 | +}; | |
33001 | + | |
33002 | +/* ---------------------------------------------------------------------- */ | |
33003 | + | |
33004 | +typedef void (*au_wkq_func_t)(void *args); | |
33005 | + | |
33006 | +/* wkq flags */ | |
33007 | +#define AuWkq_WAIT 1 | |
9dbd164d | 33008 | +#define AuWkq_NEST (1 << 1) |
1facf9fc | 33009 | +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name) |
7f207e10 AM |
33010 | +#define au_fset_wkq(flags, name) \ |
33011 | + do { (flags) |= AuWkq_##name; } while (0) | |
33012 | +#define au_fclr_wkq(flags, name) \ | |
33013 | + do { (flags) &= ~AuWkq_##name; } while (0) | |
1facf9fc | 33014 | + |
9dbd164d AM |
33015 | +#ifndef CONFIG_AUFS_HNOTIFY |
33016 | +#undef AuWkq_NEST | |
33017 | +#define AuWkq_NEST 0 | |
33018 | +#endif | |
33019 | + | |
1facf9fc | 33020 | +/* wkq.c */ |
b752ccd1 | 33021 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args); |
53392da6 AM |
33022 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
33023 | + unsigned int flags); | |
1facf9fc | 33024 | +void au_nwt_init(struct au_nowait_tasks *nwt); |
33025 | +int __init au_wkq_init(void); | |
33026 | +void au_wkq_fin(void); | |
33027 | + | |
33028 | +/* ---------------------------------------------------------------------- */ | |
33029 | + | |
53392da6 AM |
33030 | +static inline int au_wkq_test(void) |
33031 | +{ | |
33032 | + return current->flags & PF_WQ_WORKER; | |
33033 | +} | |
33034 | + | |
b752ccd1 | 33035 | +static inline int au_wkq_wait(au_wkq_func_t func, void *args) |
1facf9fc | 33036 | +{ |
b752ccd1 | 33037 | + return au_wkq_do_wait(AuWkq_WAIT, func, args); |
1facf9fc | 33038 | +} |
33039 | + | |
33040 | +static inline void au_nwt_done(struct au_nowait_tasks *nwt) | |
33041 | +{ | |
e49829fe | 33042 | + if (atomic_dec_and_test(&nwt->nw_len)) |
1facf9fc | 33043 | + wake_up_all(&nwt->nw_wq); |
33044 | +} | |
33045 | + | |
33046 | +static inline int au_nwt_flush(struct au_nowait_tasks *nwt) | |
33047 | +{ | |
33048 | + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len)); | |
33049 | + return 0; | |
33050 | +} | |
33051 | + | |
33052 | +#endif /* __KERNEL__ */ | |
33053 | +#endif /* __AUFS_WKQ_H__ */ | |
c1595e42 JR |
33054 | diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c |
33055 | --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100 | |
33056 | +++ linux/fs/aufs/xattr.c 2015-01-25 13:00:38.634380408 +0100 | |
33057 | @@ -0,0 +1,334 @@ | |
33058 | +/* | |
33059 | + * Copyright (C) 2014 Junjiro R. Okajima | |
33060 | + * | |
33061 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33062 | + * it under the terms of the GNU General Public License as published by | |
33063 | + * the Free Software Foundation; either version 2 of the License, or | |
33064 | + * (at your option) any later version. | |
33065 | + * | |
33066 | + * This program is distributed in the hope that it will be useful, | |
33067 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33068 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33069 | + * GNU General Public License for more details. | |
33070 | + * | |
33071 | + * You should have received a copy of the GNU General Public License | |
33072 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
33073 | + */ | |
33074 | + | |
33075 | +/* | |
33076 | + * handling xattr functions | |
33077 | + */ | |
33078 | + | |
33079 | +#include <linux/xattr.h> | |
33080 | +#include "aufs.h" | |
33081 | + | |
33082 | +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags) | |
33083 | +{ | |
33084 | + if (!ignore_flags) | |
33085 | + goto out; | |
33086 | + switch (err) { | |
33087 | + case -ENOMEM: | |
33088 | + case -EDQUOT: | |
33089 | + goto out; | |
33090 | + } | |
33091 | + | |
33092 | + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) { | |
33093 | + err = 0; | |
33094 | + goto out; | |
33095 | + } | |
33096 | + | |
33097 | +#define cmp(brattr, prefix) do { \ | |
33098 | + if (!strncmp(name, XATTR_##prefix##_PREFIX, \ | |
33099 | + XATTR_##prefix##_PREFIX_LEN)) { \ | |
33100 | + if (ignore_flags & AuBrAttr_ICEX_##brattr) \ | |
33101 | + err = 0; \ | |
33102 | + goto out; \ | |
33103 | + } \ | |
33104 | + } while (0) | |
33105 | + | |
33106 | + cmp(SEC, SECURITY); | |
33107 | + cmp(SYS, SYSTEM); | |
33108 | + cmp(TR, TRUSTED); | |
33109 | + cmp(USR, USER); | |
33110 | +#undef cmp | |
33111 | + | |
33112 | + if (ignore_flags & AuBrAttr_ICEX_OTH) | |
33113 | + err = 0; | |
33114 | + | |
33115 | +out: | |
33116 | + return err; | |
33117 | +} | |
33118 | + | |
33119 | +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1; | |
33120 | + | |
33121 | +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, | |
33122 | + char *name, char **buf, unsigned int ignore_flags) | |
33123 | +{ | |
33124 | + int err; | |
33125 | + ssize_t ssz; | |
33126 | + struct inode *h_idst; | |
33127 | + | |
33128 | + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS); | |
33129 | + err = ssz; | |
33130 | + if (unlikely(err <= 0)) { | |
33131 | + AuTraceErr(err); | |
33132 | + if (err == -ENODATA | |
33133 | + || (err == -EOPNOTSUPP | |
33134 | + && (ignore_flags & au_xattr_out_of_list))) | |
33135 | + err = 0; | |
33136 | + goto out; | |
33137 | + } | |
33138 | + | |
33139 | + /* unlock it temporary */ | |
33140 | + h_idst = h_dst->d_inode; | |
33141 | + mutex_unlock(&h_idst->i_mutex); | |
33142 | + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0); | |
33143 | + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2); | |
33144 | + if (unlikely(err)) { | |
33145 | + AuDbg("%s, err %d\n", name, err); | |
33146 | + err = au_xattr_ignore(err, name, ignore_flags); | |
33147 | + } | |
33148 | + | |
33149 | +out: | |
33150 | + return err; | |
33151 | +} | |
33152 | + | |
33153 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags) | |
33154 | +{ | |
33155 | + int err, unlocked, acl_access, acl_default; | |
33156 | + ssize_t ssz; | |
33157 | + struct inode *h_isrc, *h_idst; | |
33158 | + char *value, *p, *o, *e; | |
33159 | + | |
33160 | + /* try stopping to update the source inode while we are referencing */ | |
33161 | + /* there should not be the parent-child relation ship between them */ | |
33162 | + h_isrc = h_src->d_inode; | |
33163 | + h_idst = h_dst->d_inode; | |
33164 | + mutex_unlock(&h_idst->i_mutex); | |
33165 | + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD); | |
33166 | + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2); | |
33167 | + unlocked = 0; | |
33168 | + | |
33169 | + /* some filesystems don't list POSIX ACL, for example tmpfs */ | |
33170 | + ssz = vfs_listxattr(h_src, NULL, 0); | |
33171 | + err = ssz; | |
33172 | + if (unlikely(err < 0)) { | |
33173 | + AuTraceErr(err); | |
33174 | + if (err == -ENODATA | |
33175 | + || err == -EOPNOTSUPP) | |
33176 | + err = 0; /* ignore */ | |
33177 | + goto out; | |
33178 | + } | |
33179 | + | |
33180 | + err = 0; | |
33181 | + p = NULL; | |
33182 | + o = NULL; | |
33183 | + if (ssz) { | |
33184 | + err = -ENOMEM; | |
33185 | + p = kmalloc(ssz, GFP_NOFS); | |
33186 | + o = p; | |
33187 | + if (unlikely(!p)) | |
33188 | + goto out; | |
33189 | + err = vfs_listxattr(h_src, p, ssz); | |
33190 | + } | |
33191 | + mutex_unlock(&h_isrc->i_mutex); | |
33192 | + unlocked = 1; | |
33193 | + AuDbg("err %d, ssz %zd\n", err, ssz); | |
33194 | + if (unlikely(err < 0)) | |
33195 | + goto out_free; | |
33196 | + | |
33197 | + err = 0; | |
33198 | + e = p + ssz; | |
33199 | + value = NULL; | |
33200 | + acl_access = 0; | |
33201 | + acl_default = 0; | |
33202 | + while (!err && p < e) { | |
33203 | + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS, | |
33204 | + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1); | |
33205 | + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT, | |
33206 | + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) | |
33207 | + - 1); | |
33208 | + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags); | |
33209 | + p += strlen(p) + 1; | |
33210 | + } | |
33211 | + AuTraceErr(err); | |
33212 | + ignore_flags |= au_xattr_out_of_list; | |
33213 | + if (!err && !acl_access) { | |
33214 | + err = au_do_cpup_xattr(h_dst, h_src, | |
33215 | + XATTR_NAME_POSIX_ACL_ACCESS, &value, | |
33216 | + ignore_flags); | |
33217 | + AuTraceErr(err); | |
33218 | + } | |
33219 | + if (!err && !acl_default) { | |
33220 | + err = au_do_cpup_xattr(h_dst, h_src, | |
33221 | + XATTR_NAME_POSIX_ACL_DEFAULT, &value, | |
33222 | + ignore_flags); | |
33223 | + AuTraceErr(err); | |
33224 | + } | |
33225 | + | |
33226 | + kfree(value); | |
33227 | + | |
33228 | +out_free: | |
33229 | + kfree(o); | |
33230 | +out: | |
33231 | + if (!unlocked) | |
33232 | + mutex_unlock(&h_isrc->i_mutex); | |
33233 | + AuTraceErr(err); | |
33234 | + return err; | |
33235 | +} | |
33236 | + | |
33237 | +/* ---------------------------------------------------------------------- */ | |
33238 | + | |
33239 | +enum { | |
33240 | + AU_XATTR_LIST, | |
33241 | + AU_XATTR_GET | |
33242 | +}; | |
33243 | + | |
33244 | +struct au_lgxattr { | |
33245 | + int type; | |
33246 | + union { | |
33247 | + struct { | |
33248 | + char *list; | |
33249 | + size_t size; | |
33250 | + } list; | |
33251 | + struct { | |
33252 | + const char *name; | |
33253 | + void *value; | |
33254 | + size_t size; | |
33255 | + } get; | |
33256 | + } u; | |
33257 | +}; | |
33258 | + | |
33259 | +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg) | |
33260 | +{ | |
33261 | + ssize_t err; | |
33262 | + struct path h_path; | |
33263 | + struct super_block *sb; | |
33264 | + | |
33265 | + sb = dentry->d_sb; | |
33266 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
33267 | + if (unlikely(err)) | |
33268 | + goto out; | |
33269 | + err = au_h_path_getattr(dentry, /*force*/1, &h_path); | |
33270 | + if (unlikely(err)) | |
33271 | + goto out_si; | |
33272 | + if (unlikely(!h_path.dentry)) | |
33273 | + /* illegally overlapped or something */ | |
33274 | + goto out_di; /* pretending success */ | |
33275 | + | |
33276 | + /* always topmost entry only */ | |
33277 | + switch (arg->type) { | |
33278 | + case AU_XATTR_LIST: | |
33279 | + err = vfs_listxattr(h_path.dentry, | |
33280 | + arg->u.list.list, arg->u.list.size); | |
33281 | + break; | |
33282 | + case AU_XATTR_GET: | |
33283 | + err = vfs_getxattr(h_path.dentry, | |
33284 | + arg->u.get.name, arg->u.get.value, | |
33285 | + arg->u.get.size); | |
33286 | + break; | |
33287 | + } | |
33288 | + | |
33289 | +out_di: | |
33290 | + di_read_unlock(dentry, AuLock_IR); | |
33291 | +out_si: | |
33292 | + si_read_unlock(sb); | |
33293 | +out: | |
33294 | + AuTraceErr(err); | |
33295 | + return err; | |
33296 | +} | |
33297 | + | |
33298 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size) | |
33299 | +{ | |
33300 | + struct au_lgxattr arg = { | |
33301 | + .type = AU_XATTR_LIST, | |
33302 | + .u.list = { | |
33303 | + .list = list, | |
33304 | + .size = size | |
33305 | + }, | |
33306 | + }; | |
33307 | + | |
33308 | + return au_lgxattr(dentry, &arg); | |
33309 | +} | |
33310 | + | |
33311 | +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value, | |
33312 | + size_t size) | |
33313 | +{ | |
33314 | + struct au_lgxattr arg = { | |
33315 | + .type = AU_XATTR_GET, | |
33316 | + .u.get = { | |
33317 | + .name = name, | |
33318 | + .value = value, | |
33319 | + .size = size | |
33320 | + }, | |
33321 | + }; | |
33322 | + | |
33323 | + return au_lgxattr(dentry, &arg); | |
33324 | +} | |
33325 | + | |
33326 | +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value, | |
33327 | + size_t size, int flags) | |
33328 | +{ | |
33329 | + struct au_srxattr arg = { | |
33330 | + .type = AU_XATTR_SET, | |
33331 | + .u.set = { | |
33332 | + .name = name, | |
33333 | + .value = value, | |
33334 | + .size = size, | |
33335 | + .flags = flags | |
33336 | + }, | |
33337 | + }; | |
33338 | + | |
33339 | + return au_srxattr(dentry, &arg); | |
33340 | +} | |
33341 | + | |
33342 | +int aufs_removexattr(struct dentry *dentry, const char *name) | |
33343 | +{ | |
33344 | + struct au_srxattr arg = { | |
33345 | + .type = AU_XATTR_REMOVE, | |
33346 | + .u.remove = { | |
33347 | + .name = name | |
33348 | + }, | |
33349 | + }; | |
33350 | + | |
33351 | + return au_srxattr(dentry, &arg); | |
33352 | +} | |
33353 | + | |
33354 | +/* ---------------------------------------------------------------------- */ | |
33355 | + | |
33356 | +#if 0 | |
33357 | +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size, | |
33358 | + const char *name, size_t name_len, int type) | |
33359 | +{ | |
33360 | + return aufs_listxattr(dentry, list, list_size); | |
33361 | +} | |
33362 | + | |
33363 | +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer, | |
33364 | + size_t size, int type) | |
33365 | +{ | |
33366 | + return aufs_getxattr(dentry, name, buffer, size); | |
33367 | +} | |
33368 | + | |
33369 | +static int au_xattr_set(struct dentry *dentry, const char *name, | |
33370 | + const void *value, size_t size, int flags, int type) | |
33371 | +{ | |
33372 | + return aufs_setxattr(dentry, name, value, size, flags); | |
33373 | +} | |
33374 | + | |
33375 | +static const struct xattr_handler au_xattr_handler = { | |
33376 | + /* no prefix, no flags */ | |
33377 | + .list = au_xattr_list, | |
33378 | + .get = au_xattr_get, | |
33379 | + .set = au_xattr_set | |
33380 | + /* why no remove? */ | |
33381 | +}; | |
33382 | + | |
33383 | +static const struct xattr_handler *au_xattr_handlers[] = { | |
33384 | + &au_xattr_handler | |
33385 | +}; | |
33386 | + | |
33387 | +void au_xattr_init(struct super_block *sb) | |
33388 | +{ | |
33389 | + /* sb->s_xattr = au_xattr_handlers; */ | |
33390 | +} | |
33391 | +#endif | |
7f207e10 AM |
33392 | diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c |
33393 | --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
33394 | +++ linux/fs/aufs/xino.c 2015-01-25 13:00:38.634380408 +0100 |
33395 | @@ -0,0 +1,1318 @@ | |
1facf9fc | 33396 | +/* |
523b37e3 | 33397 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
1facf9fc | 33398 | + * |
33399 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33400 | + * it under the terms of the GNU General Public License as published by | |
33401 | + * the Free Software Foundation; either version 2 of the License, or | |
33402 | + * (at your option) any later version. | |
dece6358 AM |
33403 | + * |
33404 | + * This program is distributed in the hope that it will be useful, | |
33405 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33406 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33407 | + * GNU General Public License for more details. | |
33408 | + * | |
33409 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33410 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33411 | + */ |
33412 | + | |
33413 | +/* | |
33414 | + * external inode number translation table and bitmap | |
33415 | + */ | |
33416 | + | |
33417 | +#include <linux/seq_file.h> | |
392086de | 33418 | +#include <linux/statfs.h> |
1facf9fc | 33419 | +#include "aufs.h" |
33420 | + | |
9dbd164d | 33421 | +/* todo: unnecessary to support mmap_sem since kernel-space? */ |
b752ccd1 | 33422 | +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size, |
1facf9fc | 33423 | + loff_t *pos) |
33424 | +{ | |
33425 | + ssize_t err; | |
33426 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33427 | + union { |
33428 | + void *k; | |
33429 | + char __user *u; | |
33430 | + } buf; | |
1facf9fc | 33431 | + |
b752ccd1 | 33432 | + buf.k = kbuf; |
1facf9fc | 33433 | + oldfs = get_fs(); |
33434 | + set_fs(KERNEL_DS); | |
33435 | + do { | |
33436 | + /* todo: signal_pending? */ | |
b752ccd1 | 33437 | + err = func(file, buf.u, size, pos); |
1facf9fc | 33438 | + } while (err == -EAGAIN || err == -EINTR); |
33439 | + set_fs(oldfs); | |
33440 | + | |
33441 | +#if 0 /* reserved for future use */ | |
33442 | + if (err > 0) | |
33443 | + fsnotify_access(file->f_dentry); | |
33444 | +#endif | |
33445 | + | |
33446 | + return err; | |
33447 | +} | |
33448 | + | |
33449 | +/* ---------------------------------------------------------------------- */ | |
33450 | + | |
b752ccd1 | 33451 | +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf, |
1facf9fc | 33452 | + size_t size, loff_t *pos) |
33453 | +{ | |
33454 | + ssize_t err; | |
33455 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33456 | + union { |
33457 | + void *k; | |
33458 | + const char __user *u; | |
33459 | + } buf; | |
1facf9fc | 33460 | + |
b752ccd1 | 33461 | + buf.k = kbuf; |
1facf9fc | 33462 | + oldfs = get_fs(); |
33463 | + set_fs(KERNEL_DS); | |
1facf9fc | 33464 | + do { |
33465 | + /* todo: signal_pending? */ | |
b752ccd1 | 33466 | + err = func(file, buf.u, size, pos); |
1facf9fc | 33467 | + } while (err == -EAGAIN || err == -EINTR); |
1facf9fc | 33468 | + set_fs(oldfs); |
33469 | + | |
33470 | +#if 0 /* reserved for future use */ | |
33471 | + if (err > 0) | |
33472 | + fsnotify_modify(file->f_dentry); | |
33473 | +#endif | |
33474 | + | |
33475 | + return err; | |
33476 | +} | |
33477 | + | |
33478 | +struct do_xino_fwrite_args { | |
33479 | + ssize_t *errp; | |
33480 | + au_writef_t func; | |
33481 | + struct file *file; | |
33482 | + void *buf; | |
33483 | + size_t size; | |
33484 | + loff_t *pos; | |
33485 | +}; | |
33486 | + | |
33487 | +static void call_do_xino_fwrite(void *args) | |
33488 | +{ | |
33489 | + struct do_xino_fwrite_args *a = args; | |
33490 | + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos); | |
33491 | +} | |
33492 | + | |
33493 | +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size, | |
33494 | + loff_t *pos) | |
33495 | +{ | |
33496 | + ssize_t err; | |
33497 | + | |
33498 | + /* todo: signal block and no wkq? */ | |
b752ccd1 AM |
33499 | + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) { |
33500 | + lockdep_off(); | |
33501 | + err = do_xino_fwrite(func, file, buf, size, pos); | |
33502 | + lockdep_on(); | |
33503 | + } else { | |
33504 | + /* | |
33505 | + * it breaks RLIMIT_FSIZE and normal user's limit, | |
33506 | + * users should care about quota and real 'filesystem full.' | |
33507 | + */ | |
1facf9fc | 33508 | + int wkq_err; |
33509 | + struct do_xino_fwrite_args args = { | |
33510 | + .errp = &err, | |
33511 | + .func = func, | |
33512 | + .file = file, | |
33513 | + .buf = buf, | |
33514 | + .size = size, | |
33515 | + .pos = pos | |
33516 | + }; | |
33517 | + | |
33518 | + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args); | |
33519 | + if (unlikely(wkq_err)) | |
33520 | + err = wkq_err; | |
b752ccd1 | 33521 | + } |
1facf9fc | 33522 | + |
33523 | + return err; | |
33524 | +} | |
33525 | + | |
33526 | +/* ---------------------------------------------------------------------- */ | |
33527 | + | |
33528 | +/* | |
33529 | + * create a new xinofile at the same place/path as @base_file. | |
33530 | + */ | |
33531 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src) | |
33532 | +{ | |
33533 | + struct file *file; | |
4a4d8108 | 33534 | + struct dentry *base, *parent; |
523b37e3 | 33535 | + struct inode *dir, *delegated; |
1facf9fc | 33536 | + struct qstr *name; |
1308ab2a | 33537 | + struct path path; |
4a4d8108 | 33538 | + int err; |
1facf9fc | 33539 | + |
33540 | + base = base_file->f_dentry; | |
33541 | + parent = base->d_parent; /* dir inode is locked */ | |
33542 | + dir = parent->d_inode; | |
33543 | + IMustLock(dir); | |
33544 | + | |
33545 | + file = ERR_PTR(-EINVAL); | |
33546 | + name = &base->d_name; | |
4a4d8108 AM |
33547 | + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len); |
33548 | + if (IS_ERR(path.dentry)) { | |
33549 | + file = (void *)path.dentry; | |
523b37e3 AM |
33550 | + pr_err("%pd lookup err %ld\n", |
33551 | + base, PTR_ERR(path.dentry)); | |
1facf9fc | 33552 | + goto out; |
33553 | + } | |
33554 | + | |
33555 | + /* no need to mnt_want_write() since we call dentry_open() later */ | |
4a4d8108 | 33556 | + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL); |
1facf9fc | 33557 | + if (unlikely(err)) { |
33558 | + file = ERR_PTR(err); | |
523b37e3 | 33559 | + pr_err("%pd create err %d\n", base, err); |
1facf9fc | 33560 | + goto out_dput; |
33561 | + } | |
33562 | + | |
c06a8ce3 | 33563 | + path.mnt = base_file->f_path.mnt; |
4a4d8108 | 33564 | + file = vfsub_dentry_open(&path, |
7f207e10 | 33565 | + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 33566 | + /* | __FMODE_NONOTIFY */); |
1facf9fc | 33567 | + if (IS_ERR(file)) { |
523b37e3 | 33568 | + pr_err("%pd open err %ld\n", base, PTR_ERR(file)); |
1facf9fc | 33569 | + goto out_dput; |
33570 | + } | |
33571 | + | |
523b37e3 AM |
33572 | + delegated = NULL; |
33573 | + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0); | |
33574 | + if (unlikely(err == -EWOULDBLOCK)) { | |
33575 | + pr_warn("cannot retry for NFSv4 delegation" | |
33576 | + " for an internal unlink\n"); | |
33577 | + iput(delegated); | |
33578 | + } | |
1facf9fc | 33579 | + if (unlikely(err)) { |
523b37e3 | 33580 | + pr_err("%pd unlink err %d\n", base, err); |
1facf9fc | 33581 | + goto out_fput; |
33582 | + } | |
33583 | + | |
33584 | + if (copy_src) { | |
33585 | + /* no one can touch copy_src xino */ | |
c06a8ce3 | 33586 | + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src)); |
1facf9fc | 33587 | + if (unlikely(err)) { |
523b37e3 | 33588 | + pr_err("%pd copy err %d\n", base, err); |
1facf9fc | 33589 | + goto out_fput; |
33590 | + } | |
33591 | + } | |
33592 | + goto out_dput; /* success */ | |
33593 | + | |
4f0767ce | 33594 | +out_fput: |
1facf9fc | 33595 | + fput(file); |
33596 | + file = ERR_PTR(err); | |
4f0767ce | 33597 | +out_dput: |
4a4d8108 | 33598 | + dput(path.dentry); |
4f0767ce | 33599 | +out: |
1facf9fc | 33600 | + return file; |
33601 | +} | |
33602 | + | |
33603 | +struct au_xino_lock_dir { | |
33604 | + struct au_hinode *hdir; | |
33605 | + struct dentry *parent; | |
33606 | + struct mutex *mtx; | |
33607 | +}; | |
33608 | + | |
33609 | +static void au_xino_lock_dir(struct super_block *sb, struct file *xino, | |
33610 | + struct au_xino_lock_dir *ldir) | |
33611 | +{ | |
33612 | + aufs_bindex_t brid, bindex; | |
33613 | + | |
33614 | + ldir->hdir = NULL; | |
33615 | + bindex = -1; | |
33616 | + brid = au_xino_brid(sb); | |
33617 | + if (brid >= 0) | |
33618 | + bindex = au_br_index(sb, brid); | |
33619 | + if (bindex >= 0) { | |
33620 | + ldir->hdir = au_hi(sb->s_root->d_inode, bindex); | |
4a4d8108 | 33621 | + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT); |
1facf9fc | 33622 | + } else { |
33623 | + ldir->parent = dget_parent(xino->f_dentry); | |
33624 | + ldir->mtx = &ldir->parent->d_inode->i_mutex; | |
33625 | + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT); | |
33626 | + } | |
33627 | +} | |
33628 | + | |
33629 | +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir) | |
33630 | +{ | |
33631 | + if (ldir->hdir) | |
4a4d8108 | 33632 | + au_hn_imtx_unlock(ldir->hdir); |
1facf9fc | 33633 | + else { |
33634 | + mutex_unlock(ldir->mtx); | |
33635 | + dput(ldir->parent); | |
33636 | + } | |
33637 | +} | |
33638 | + | |
33639 | +/* ---------------------------------------------------------------------- */ | |
33640 | + | |
33641 | +/* trucate xino files asynchronously */ | |
33642 | + | |
33643 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex) | |
33644 | +{ | |
33645 | + int err; | |
392086de AM |
33646 | + unsigned long jiffy; |
33647 | + blkcnt_t blocks; | |
1facf9fc | 33648 | + aufs_bindex_t bi, bend; |
392086de | 33649 | + struct kstatfs *st; |
1facf9fc | 33650 | + struct au_branch *br; |
33651 | + struct file *new_xino, *file; | |
33652 | + struct super_block *h_sb; | |
33653 | + struct au_xino_lock_dir ldir; | |
33654 | + | |
392086de AM |
33655 | + err = -ENOMEM; |
33656 | + st = kzalloc(sizeof(*st), GFP_NOFS); | |
33657 | + if (unlikely(!st)) | |
33658 | + goto out; | |
33659 | + | |
1facf9fc | 33660 | + err = -EINVAL; |
33661 | + bend = au_sbend(sb); | |
33662 | + if (unlikely(bindex < 0 || bend < bindex)) | |
392086de | 33663 | + goto out_st; |
1facf9fc | 33664 | + br = au_sbr(sb, bindex); |
33665 | + file = br->br_xino.xi_file; | |
33666 | + if (!file) | |
392086de AM |
33667 | + goto out_st; |
33668 | + | |
33669 | + err = vfs_statfs(&file->f_path, st); | |
33670 | + if (unlikely(err)) | |
33671 | + AuErr1("statfs err %d, ignored\n", err); | |
33672 | + jiffy = jiffies; | |
33673 | + blocks = file_inode(file)->i_blocks; | |
33674 | + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
33675 | + bindex, (u64)blocks, st->f_bfree, st->f_blocks); | |
1facf9fc | 33676 | + |
33677 | + au_xino_lock_dir(sb, file, &ldir); | |
33678 | + /* mnt_want_write() is unnecessary here */ | |
33679 | + new_xino = au_xino_create2(file, file); | |
33680 | + au_xino_unlock_dir(&ldir); | |
33681 | + err = PTR_ERR(new_xino); | |
392086de AM |
33682 | + if (IS_ERR(new_xino)) { |
33683 | + pr_err("err %d, ignored\n", err); | |
33684 | + goto out_st; | |
33685 | + } | |
1facf9fc | 33686 | + err = 0; |
33687 | + fput(file); | |
33688 | + br->br_xino.xi_file = new_xino; | |
33689 | + | |
86dc4139 | 33690 | + h_sb = au_br_sb(br); |
1facf9fc | 33691 | + for (bi = 0; bi <= bend; bi++) { |
33692 | + if (unlikely(bi == bindex)) | |
33693 | + continue; | |
33694 | + br = au_sbr(sb, bi); | |
86dc4139 | 33695 | + if (au_br_sb(br) != h_sb) |
1facf9fc | 33696 | + continue; |
33697 | + | |
33698 | + fput(br->br_xino.xi_file); | |
33699 | + br->br_xino.xi_file = new_xino; | |
33700 | + get_file(new_xino); | |
33701 | + } | |
33702 | + | |
392086de AM |
33703 | + err = vfs_statfs(&new_xino->f_path, st); |
33704 | + if (!err) { | |
33705 | + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
33706 | + bindex, (u64)file_inode(new_xino)->i_blocks, | |
33707 | + st->f_bfree, st->f_blocks); | |
33708 | + if (file_inode(new_xino)->i_blocks < blocks) | |
33709 | + au_sbi(sb)->si_xino_jiffy = jiffy; | |
33710 | + } else | |
33711 | + AuErr1("statfs err %d, ignored\n", err); | |
33712 | + | |
33713 | +out_st: | |
33714 | + kfree(st); | |
4f0767ce | 33715 | +out: |
1facf9fc | 33716 | + return err; |
33717 | +} | |
33718 | + | |
33719 | +struct xino_do_trunc_args { | |
33720 | + struct super_block *sb; | |
33721 | + struct au_branch *br; | |
33722 | +}; | |
33723 | + | |
33724 | +static void xino_do_trunc(void *_args) | |
33725 | +{ | |
33726 | + struct xino_do_trunc_args *args = _args; | |
33727 | + struct super_block *sb; | |
33728 | + struct au_branch *br; | |
33729 | + struct inode *dir; | |
33730 | + int err; | |
33731 | + aufs_bindex_t bindex; | |
33732 | + | |
33733 | + err = 0; | |
33734 | + sb = args->sb; | |
33735 | + dir = sb->s_root->d_inode; | |
33736 | + br = args->br; | |
33737 | + | |
33738 | + si_noflush_write_lock(sb); | |
33739 | + ii_read_lock_parent(dir); | |
33740 | + bindex = au_br_index(sb, br->br_id); | |
33741 | + err = au_xino_trunc(sb, bindex); | |
1facf9fc | 33742 | + ii_read_unlock(dir); |
33743 | + if (unlikely(err)) | |
392086de | 33744 | + pr_warn("err b%d, (%d)\n", bindex, err); |
1facf9fc | 33745 | + atomic_dec(&br->br_xino_running); |
33746 | + atomic_dec(&br->br_count); | |
1facf9fc | 33747 | + si_write_unlock(sb); |
027c5e7a | 33748 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 33749 | + kfree(args); |
33750 | +} | |
33751 | + | |
392086de AM |
33752 | +static int xino_trunc_test(struct super_block *sb, struct au_branch *br) |
33753 | +{ | |
33754 | + int err; | |
33755 | + struct kstatfs st; | |
33756 | + struct au_sbinfo *sbinfo; | |
33757 | + | |
33758 | + /* todo: si_xino_expire and the ratio should be customizable */ | |
33759 | + sbinfo = au_sbi(sb); | |
33760 | + if (time_before(jiffies, | |
33761 | + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire)) | |
33762 | + return 0; | |
33763 | + | |
33764 | + /* truncation border */ | |
33765 | + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st); | |
33766 | + if (unlikely(err)) { | |
33767 | + AuErr1("statfs err %d, ignored\n", err); | |
33768 | + return 0; | |
33769 | + } | |
33770 | + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC) | |
33771 | + return 0; | |
33772 | + | |
33773 | + return 1; | |
33774 | +} | |
33775 | + | |
1facf9fc | 33776 | +static void xino_try_trunc(struct super_block *sb, struct au_branch *br) |
33777 | +{ | |
33778 | + struct xino_do_trunc_args *args; | |
33779 | + int wkq_err; | |
33780 | + | |
392086de | 33781 | + if (!xino_trunc_test(sb, br)) |
1facf9fc | 33782 | + return; |
33783 | + | |
33784 | + if (atomic_inc_return(&br->br_xino_running) > 1) | |
33785 | + goto out; | |
33786 | + | |
33787 | + /* lock and kfree() will be called in trunc_xino() */ | |
33788 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
33789 | + if (unlikely(!args)) { | |
33790 | + AuErr1("no memory\n"); | |
33791 | + goto out_args; | |
33792 | + } | |
33793 | + | |
e49829fe | 33794 | + atomic_inc(&br->br_count); |
1facf9fc | 33795 | + args->sb = sb; |
33796 | + args->br = br; | |
53392da6 | 33797 | + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0); |
1facf9fc | 33798 | + if (!wkq_err) |
33799 | + return; /* success */ | |
33800 | + | |
4a4d8108 | 33801 | + pr_err("wkq %d\n", wkq_err); |
e49829fe | 33802 | + atomic_dec(&br->br_count); |
1facf9fc | 33803 | + |
4f0767ce | 33804 | +out_args: |
1facf9fc | 33805 | + kfree(args); |
4f0767ce | 33806 | +out: |
e49829fe | 33807 | + atomic_dec(&br->br_xino_running); |
1facf9fc | 33808 | +} |
33809 | + | |
33810 | +/* ---------------------------------------------------------------------- */ | |
33811 | + | |
33812 | +static int au_xino_do_write(au_writef_t write, struct file *file, | |
33813 | + ino_t h_ino, ino_t ino) | |
33814 | +{ | |
33815 | + loff_t pos; | |
33816 | + ssize_t sz; | |
33817 | + | |
33818 | + pos = h_ino; | |
33819 | + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) { | |
33820 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
33821 | + return -EFBIG; | |
33822 | + } | |
33823 | + pos *= sizeof(ino); | |
33824 | + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos); | |
33825 | + if (sz == sizeof(ino)) | |
33826 | + return 0; /* success */ | |
33827 | + | |
33828 | + AuIOErr("write failed (%zd)\n", sz); | |
33829 | + return -EIO; | |
33830 | +} | |
33831 | + | |
33832 | +/* | |
33833 | + * write @ino to the xinofile for the specified branch{@sb, @bindex} | |
33834 | + * at the position of @h_ino. | |
33835 | + * even if @ino is zero, it is written to the xinofile and means no entry. | |
33836 | + * if the size of the xino file on a specific filesystem exceeds the watermark, | |
33837 | + * try truncating it. | |
33838 | + */ | |
33839 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
33840 | + ino_t ino) | |
33841 | +{ | |
33842 | + int err; | |
33843 | + unsigned int mnt_flags; | |
33844 | + struct au_branch *br; | |
33845 | + | |
33846 | + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max) | |
33847 | + || ((loff_t)-1) > 0); | |
dece6358 | 33848 | + SiMustAnyLock(sb); |
1facf9fc | 33849 | + |
33850 | + mnt_flags = au_mntflags(sb); | |
33851 | + if (!au_opt_test(mnt_flags, XINO)) | |
33852 | + return 0; | |
33853 | + | |
33854 | + br = au_sbr(sb, bindex); | |
33855 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
33856 | + h_ino, ino); | |
33857 | + if (!err) { | |
33858 | + if (au_opt_test(mnt_flags, TRUNC_XINO) | |
86dc4139 | 33859 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
1facf9fc | 33860 | + xino_try_trunc(sb, br); |
33861 | + return 0; /* success */ | |
33862 | + } | |
33863 | + | |
33864 | + AuIOErr("write failed (%d)\n", err); | |
33865 | + return -EIO; | |
33866 | +} | |
33867 | + | |
33868 | +/* ---------------------------------------------------------------------- */ | |
33869 | + | |
33870 | +/* aufs inode number bitmap */ | |
33871 | + | |
33872 | +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE; | |
33873 | +static ino_t xib_calc_ino(unsigned long pindex, int bit) | |
33874 | +{ | |
33875 | + ino_t ino; | |
33876 | + | |
33877 | + AuDebugOn(bit < 0 || page_bits <= bit); | |
33878 | + ino = AUFS_FIRST_INO + pindex * page_bits + bit; | |
33879 | + return ino; | |
33880 | +} | |
33881 | + | |
33882 | +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit) | |
33883 | +{ | |
33884 | + AuDebugOn(ino < AUFS_FIRST_INO); | |
33885 | + ino -= AUFS_FIRST_INO; | |
33886 | + *pindex = ino / page_bits; | |
33887 | + *bit = ino % page_bits; | |
33888 | +} | |
33889 | + | |
33890 | +static int xib_pindex(struct super_block *sb, unsigned long pindex) | |
33891 | +{ | |
33892 | + int err; | |
33893 | + loff_t pos; | |
33894 | + ssize_t sz; | |
33895 | + struct au_sbinfo *sbinfo; | |
33896 | + struct file *xib; | |
33897 | + unsigned long *p; | |
33898 | + | |
33899 | + sbinfo = au_sbi(sb); | |
33900 | + MtxMustLock(&sbinfo->si_xib_mtx); | |
33901 | + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE | |
33902 | + || !au_opt_test(sbinfo->si_mntflags, XINO)); | |
33903 | + | |
33904 | + if (pindex == sbinfo->si_xib_last_pindex) | |
33905 | + return 0; | |
33906 | + | |
33907 | + xib = sbinfo->si_xib; | |
33908 | + p = sbinfo->si_xib_buf; | |
33909 | + pos = sbinfo->si_xib_last_pindex; | |
33910 | + pos *= PAGE_SIZE; | |
33911 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
33912 | + if (unlikely(sz != PAGE_SIZE)) | |
33913 | + goto out; | |
33914 | + | |
33915 | + pos = pindex; | |
33916 | + pos *= PAGE_SIZE; | |
c06a8ce3 | 33917 | + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE) |
1facf9fc | 33918 | + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos); |
33919 | + else { | |
33920 | + memset(p, 0, PAGE_SIZE); | |
33921 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
33922 | + } | |
33923 | + if (sz == PAGE_SIZE) { | |
33924 | + sbinfo->si_xib_last_pindex = pindex; | |
33925 | + return 0; /* success */ | |
33926 | + } | |
33927 | + | |
4f0767ce | 33928 | +out: |
b752ccd1 AM |
33929 | + AuIOErr1("write failed (%zd)\n", sz); |
33930 | + err = sz; | |
33931 | + if (sz >= 0) | |
33932 | + err = -EIO; | |
33933 | + return err; | |
33934 | +} | |
33935 | + | |
33936 | +/* ---------------------------------------------------------------------- */ | |
33937 | + | |
33938 | +static void au_xib_clear_bit(struct inode *inode) | |
33939 | +{ | |
33940 | + int err, bit; | |
33941 | + unsigned long pindex; | |
33942 | + struct super_block *sb; | |
33943 | + struct au_sbinfo *sbinfo; | |
33944 | + | |
33945 | + AuDebugOn(inode->i_nlink); | |
33946 | + | |
33947 | + sb = inode->i_sb; | |
33948 | + xib_calc_bit(inode->i_ino, &pindex, &bit); | |
33949 | + AuDebugOn(page_bits <= bit); | |
33950 | + sbinfo = au_sbi(sb); | |
33951 | + mutex_lock(&sbinfo->si_xib_mtx); | |
33952 | + err = xib_pindex(sb, pindex); | |
33953 | + if (!err) { | |
33954 | + clear_bit(bit, sbinfo->si_xib_buf); | |
33955 | + sbinfo->si_xib_next_bit = bit; | |
33956 | + } | |
33957 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
33958 | +} | |
33959 | + | |
33960 | +/* for s_op->delete_inode() */ | |
33961 | +void au_xino_delete_inode(struct inode *inode, const int unlinked) | |
33962 | +{ | |
33963 | + int err; | |
33964 | + unsigned int mnt_flags; | |
33965 | + aufs_bindex_t bindex, bend, bi; | |
33966 | + unsigned char try_trunc; | |
33967 | + struct au_iinfo *iinfo; | |
33968 | + struct super_block *sb; | |
33969 | + struct au_hinode *hi; | |
33970 | + struct inode *h_inode; | |
33971 | + struct au_branch *br; | |
33972 | + au_writef_t xwrite; | |
33973 | + | |
33974 | + sb = inode->i_sb; | |
33975 | + mnt_flags = au_mntflags(sb); | |
33976 | + if (!au_opt_test(mnt_flags, XINO) | |
33977 | + || inode->i_ino == AUFS_ROOT_INO) | |
33978 | + return; | |
33979 | + | |
33980 | + if (unlinked) { | |
33981 | + au_xigen_inc(inode); | |
33982 | + au_xib_clear_bit(inode); | |
33983 | + } | |
33984 | + | |
33985 | + iinfo = au_ii(inode); | |
33986 | + if (!iinfo) | |
33987 | + return; | |
1facf9fc | 33988 | + |
b752ccd1 AM |
33989 | + bindex = iinfo->ii_bstart; |
33990 | + if (bindex < 0) | |
33991 | + return; | |
1facf9fc | 33992 | + |
b752ccd1 AM |
33993 | + xwrite = au_sbi(sb)->si_xwrite; |
33994 | + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO); | |
33995 | + hi = iinfo->ii_hinode + bindex; | |
33996 | + bend = iinfo->ii_bend; | |
33997 | + for (; bindex <= bend; bindex++, hi++) { | |
33998 | + h_inode = hi->hi_inode; | |
33999 | + if (!h_inode | |
34000 | + || (!unlinked && h_inode->i_nlink)) | |
34001 | + continue; | |
1facf9fc | 34002 | + |
b752ccd1 AM |
34003 | + /* inode may not be revalidated */ |
34004 | + bi = au_br_index(sb, hi->hi_id); | |
34005 | + if (bi < 0) | |
34006 | + continue; | |
1facf9fc | 34007 | + |
b752ccd1 AM |
34008 | + br = au_sbr(sb, bi); |
34009 | + err = au_xino_do_write(xwrite, br->br_xino.xi_file, | |
34010 | + h_inode->i_ino, /*ino*/0); | |
34011 | + if (!err && try_trunc | |
86dc4139 | 34012 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
b752ccd1 | 34013 | + xino_try_trunc(sb, br); |
1facf9fc | 34014 | + } |
1facf9fc | 34015 | +} |
34016 | + | |
34017 | +/* get an unused inode number from bitmap */ | |
34018 | +ino_t au_xino_new_ino(struct super_block *sb) | |
34019 | +{ | |
34020 | + ino_t ino; | |
34021 | + unsigned long *p, pindex, ul, pend; | |
34022 | + struct au_sbinfo *sbinfo; | |
34023 | + struct file *file; | |
34024 | + int free_bit, err; | |
34025 | + | |
34026 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
34027 | + return iunique(sb, AUFS_FIRST_INO); | |
34028 | + | |
34029 | + sbinfo = au_sbi(sb); | |
34030 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34031 | + p = sbinfo->si_xib_buf; | |
34032 | + free_bit = sbinfo->si_xib_next_bit; | |
34033 | + if (free_bit < page_bits && !test_bit(free_bit, p)) | |
34034 | + goto out; /* success */ | |
34035 | + free_bit = find_first_zero_bit(p, page_bits); | |
34036 | + if (free_bit < page_bits) | |
34037 | + goto out; /* success */ | |
34038 | + | |
34039 | + pindex = sbinfo->si_xib_last_pindex; | |
34040 | + for (ul = pindex - 1; ul < ULONG_MAX; ul--) { | |
34041 | + err = xib_pindex(sb, ul); | |
34042 | + if (unlikely(err)) | |
34043 | + goto out_err; | |
34044 | + free_bit = find_first_zero_bit(p, page_bits); | |
34045 | + if (free_bit < page_bits) | |
34046 | + goto out; /* success */ | |
34047 | + } | |
34048 | + | |
34049 | + file = sbinfo->si_xib; | |
c06a8ce3 | 34050 | + pend = vfsub_f_size_read(file) / PAGE_SIZE; |
1facf9fc | 34051 | + for (ul = pindex + 1; ul <= pend; ul++) { |
34052 | + err = xib_pindex(sb, ul); | |
34053 | + if (unlikely(err)) | |
34054 | + goto out_err; | |
34055 | + free_bit = find_first_zero_bit(p, page_bits); | |
34056 | + if (free_bit < page_bits) | |
34057 | + goto out; /* success */ | |
34058 | + } | |
34059 | + BUG(); | |
34060 | + | |
4f0767ce | 34061 | +out: |
1facf9fc | 34062 | + set_bit(free_bit, p); |
7f207e10 | 34063 | + sbinfo->si_xib_next_bit = free_bit + 1; |
1facf9fc | 34064 | + pindex = sbinfo->si_xib_last_pindex; |
34065 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34066 | + ino = xib_calc_ino(pindex, free_bit); | |
34067 | + AuDbg("i%lu\n", (unsigned long)ino); | |
34068 | + return ino; | |
4f0767ce | 34069 | +out_err: |
1facf9fc | 34070 | + mutex_unlock(&sbinfo->si_xib_mtx); |
34071 | + AuDbg("i0\n"); | |
34072 | + return 0; | |
34073 | +} | |
34074 | + | |
34075 | +/* | |
34076 | + * read @ino from xinofile for the specified branch{@sb, @bindex} | |
34077 | + * at the position of @h_ino. | |
34078 | + * if @ino does not exist and @do_new is true, get new one. | |
34079 | + */ | |
34080 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
34081 | + ino_t *ino) | |
34082 | +{ | |
34083 | + int err; | |
34084 | + ssize_t sz; | |
34085 | + loff_t pos; | |
34086 | + struct file *file; | |
34087 | + struct au_sbinfo *sbinfo; | |
34088 | + | |
34089 | + *ino = 0; | |
34090 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
34091 | + return 0; /* no xino */ | |
34092 | + | |
34093 | + err = 0; | |
34094 | + sbinfo = au_sbi(sb); | |
34095 | + pos = h_ino; | |
34096 | + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) { | |
34097 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
34098 | + return -EFBIG; | |
34099 | + } | |
34100 | + pos *= sizeof(*ino); | |
34101 | + | |
34102 | + file = au_sbr(sb, bindex)->br_xino.xi_file; | |
c06a8ce3 | 34103 | + if (vfsub_f_size_read(file) < pos + sizeof(*ino)) |
1facf9fc | 34104 | + return 0; /* no ino */ |
34105 | + | |
34106 | + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos); | |
34107 | + if (sz == sizeof(*ino)) | |
34108 | + return 0; /* success */ | |
34109 | + | |
34110 | + err = sz; | |
34111 | + if (unlikely(sz >= 0)) { | |
34112 | + err = -EIO; | |
34113 | + AuIOErr("xino read error (%zd)\n", sz); | |
34114 | + } | |
34115 | + | |
34116 | + return err; | |
34117 | +} | |
34118 | + | |
34119 | +/* ---------------------------------------------------------------------- */ | |
34120 | + | |
34121 | +/* create and set a new xino file */ | |
34122 | + | |
34123 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent) | |
34124 | +{ | |
34125 | + struct file *file; | |
34126 | + struct dentry *h_parent, *d; | |
34127 | + struct inode *h_dir; | |
34128 | + int err; | |
34129 | + | |
34130 | + /* | |
34131 | + * at mount-time, and the xino file is the default path, | |
4a4d8108 | 34132 | + * hnotify is disabled so we have no notify events to ignore. |
1facf9fc | 34133 | + * when a user specified the xino, we cannot get au_hdir to be ignored. |
34134 | + */ | |
7f207e10 | 34135 | + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 34136 | + /* | __FMODE_NONOTIFY */, |
1facf9fc | 34137 | + S_IRUGO | S_IWUGO); |
34138 | + if (IS_ERR(file)) { | |
34139 | + if (!silent) | |
4a4d8108 | 34140 | + pr_err("open %s(%ld)\n", fname, PTR_ERR(file)); |
1facf9fc | 34141 | + return file; |
34142 | + } | |
34143 | + | |
34144 | + /* keep file count */ | |
34145 | + h_parent = dget_parent(file->f_dentry); | |
34146 | + h_dir = h_parent->d_inode; | |
34147 | + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT); | |
34148 | + /* mnt_want_write() is unnecessary here */ | |
523b37e3 AM |
34149 | + /* no delegation since it is just created */ |
34150 | + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0); | |
1facf9fc | 34151 | + mutex_unlock(&h_dir->i_mutex); |
34152 | + dput(h_parent); | |
34153 | + if (unlikely(err)) { | |
34154 | + if (!silent) | |
4a4d8108 | 34155 | + pr_err("unlink %s(%d)\n", fname, err); |
1facf9fc | 34156 | + goto out; |
34157 | + } | |
34158 | + | |
34159 | + err = -EINVAL; | |
34160 | + d = file->f_dentry; | |
34161 | + if (unlikely(sb == d->d_sb)) { | |
34162 | + if (!silent) | |
4a4d8108 | 34163 | + pr_err("%s must be outside\n", fname); |
1facf9fc | 34164 | + goto out; |
34165 | + } | |
34166 | + if (unlikely(au_test_fs_bad_xino(d->d_sb))) { | |
34167 | + if (!silent) | |
4a4d8108 AM |
34168 | + pr_err("xino doesn't support %s(%s)\n", |
34169 | + fname, au_sbtype(d->d_sb)); | |
1facf9fc | 34170 | + goto out; |
34171 | + } | |
34172 | + return file; /* success */ | |
34173 | + | |
4f0767ce | 34174 | +out: |
1facf9fc | 34175 | + fput(file); |
34176 | + file = ERR_PTR(err); | |
34177 | + return file; | |
34178 | +} | |
34179 | + | |
34180 | +/* | |
34181 | + * find another branch who is on the same filesystem of the specified | |
34182 | + * branch{@btgt}. search until @bend. | |
34183 | + */ | |
34184 | +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt, | |
34185 | + aufs_bindex_t bend) | |
34186 | +{ | |
34187 | + aufs_bindex_t bindex; | |
34188 | + struct super_block *tgt_sb = au_sbr_sb(sb, btgt); | |
34189 | + | |
34190 | + for (bindex = 0; bindex < btgt; bindex++) | |
34191 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
34192 | + return bindex; | |
34193 | + for (bindex++; bindex <= bend; bindex++) | |
34194 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
34195 | + return bindex; | |
34196 | + return -1; | |
34197 | +} | |
34198 | + | |
34199 | +/* ---------------------------------------------------------------------- */ | |
34200 | + | |
34201 | +/* | |
34202 | + * initialize the xinofile for the specified branch @br | |
34203 | + * at the place/path where @base_file indicates. | |
34204 | + * test whether another branch is on the same filesystem or not, | |
34205 | + * if @do_test is true. | |
34206 | + */ | |
34207 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino, | |
34208 | + struct file *base_file, int do_test) | |
34209 | +{ | |
34210 | + int err; | |
34211 | + ino_t ino; | |
34212 | + aufs_bindex_t bend, bindex; | |
34213 | + struct au_branch *shared_br, *b; | |
34214 | + struct file *file; | |
34215 | + struct super_block *tgt_sb; | |
34216 | + | |
34217 | + shared_br = NULL; | |
34218 | + bend = au_sbend(sb); | |
34219 | + if (do_test) { | |
86dc4139 | 34220 | + tgt_sb = au_br_sb(br); |
1facf9fc | 34221 | + for (bindex = 0; bindex <= bend; bindex++) { |
34222 | + b = au_sbr(sb, bindex); | |
86dc4139 | 34223 | + if (tgt_sb == au_br_sb(b)) { |
1facf9fc | 34224 | + shared_br = b; |
34225 | + break; | |
34226 | + } | |
34227 | + } | |
34228 | + } | |
34229 | + | |
34230 | + if (!shared_br || !shared_br->br_xino.xi_file) { | |
34231 | + struct au_xino_lock_dir ldir; | |
34232 | + | |
34233 | + au_xino_lock_dir(sb, base_file, &ldir); | |
34234 | + /* mnt_want_write() is unnecessary here */ | |
34235 | + file = au_xino_create2(base_file, NULL); | |
34236 | + au_xino_unlock_dir(&ldir); | |
34237 | + err = PTR_ERR(file); | |
34238 | + if (IS_ERR(file)) | |
34239 | + goto out; | |
34240 | + br->br_xino.xi_file = file; | |
34241 | + } else { | |
34242 | + br->br_xino.xi_file = shared_br->br_xino.xi_file; | |
34243 | + get_file(br->br_xino.xi_file); | |
34244 | + } | |
34245 | + | |
34246 | + ino = AUFS_ROOT_INO; | |
34247 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
34248 | + h_ino, ino); | |
b752ccd1 AM |
34249 | + if (unlikely(err)) { |
34250 | + fput(br->br_xino.xi_file); | |
34251 | + br->br_xino.xi_file = NULL; | |
34252 | + } | |
1facf9fc | 34253 | + |
4f0767ce | 34254 | +out: |
1facf9fc | 34255 | + return err; |
34256 | +} | |
34257 | + | |
34258 | +/* ---------------------------------------------------------------------- */ | |
34259 | + | |
34260 | +/* trucate a xino bitmap file */ | |
34261 | + | |
34262 | +/* todo: slow */ | |
34263 | +static int do_xib_restore(struct super_block *sb, struct file *file, void *page) | |
34264 | +{ | |
34265 | + int err, bit; | |
34266 | + ssize_t sz; | |
34267 | + unsigned long pindex; | |
34268 | + loff_t pos, pend; | |
34269 | + struct au_sbinfo *sbinfo; | |
34270 | + au_readf_t func; | |
34271 | + ino_t *ino; | |
34272 | + unsigned long *p; | |
34273 | + | |
34274 | + err = 0; | |
34275 | + sbinfo = au_sbi(sb); | |
dece6358 | 34276 | + MtxMustLock(&sbinfo->si_xib_mtx); |
1facf9fc | 34277 | + p = sbinfo->si_xib_buf; |
34278 | + func = sbinfo->si_xread; | |
c06a8ce3 | 34279 | + pend = vfsub_f_size_read(file); |
1facf9fc | 34280 | + pos = 0; |
34281 | + while (pos < pend) { | |
34282 | + sz = xino_fread(func, file, page, PAGE_SIZE, &pos); | |
34283 | + err = sz; | |
34284 | + if (unlikely(sz <= 0)) | |
34285 | + goto out; | |
34286 | + | |
34287 | + err = 0; | |
34288 | + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) { | |
34289 | + if (unlikely(*ino < AUFS_FIRST_INO)) | |
34290 | + continue; | |
34291 | + | |
34292 | + xib_calc_bit(*ino, &pindex, &bit); | |
34293 | + AuDebugOn(page_bits <= bit); | |
34294 | + err = xib_pindex(sb, pindex); | |
34295 | + if (!err) | |
34296 | + set_bit(bit, p); | |
34297 | + else | |
34298 | + goto out; | |
34299 | + } | |
34300 | + } | |
34301 | + | |
4f0767ce | 34302 | +out: |
1facf9fc | 34303 | + return err; |
34304 | +} | |
34305 | + | |
34306 | +static int xib_restore(struct super_block *sb) | |
34307 | +{ | |
34308 | + int err; | |
34309 | + aufs_bindex_t bindex, bend; | |
34310 | + void *page; | |
34311 | + | |
34312 | + err = -ENOMEM; | |
34313 | + page = (void *)__get_free_page(GFP_NOFS); | |
34314 | + if (unlikely(!page)) | |
34315 | + goto out; | |
34316 | + | |
34317 | + err = 0; | |
34318 | + bend = au_sbend(sb); | |
34319 | + for (bindex = 0; !err && bindex <= bend; bindex++) | |
34320 | + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) | |
34321 | + err = do_xib_restore | |
34322 | + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page); | |
34323 | + else | |
34324 | + AuDbg("b%d\n", bindex); | |
34325 | + free_page((unsigned long)page); | |
34326 | + | |
4f0767ce | 34327 | +out: |
1facf9fc | 34328 | + return err; |
34329 | +} | |
34330 | + | |
34331 | +int au_xib_trunc(struct super_block *sb) | |
34332 | +{ | |
34333 | + int err; | |
34334 | + ssize_t sz; | |
34335 | + loff_t pos; | |
34336 | + struct au_xino_lock_dir ldir; | |
34337 | + struct au_sbinfo *sbinfo; | |
34338 | + unsigned long *p; | |
34339 | + struct file *file; | |
34340 | + | |
dece6358 AM |
34341 | + SiMustWriteLock(sb); |
34342 | + | |
1facf9fc | 34343 | + err = 0; |
34344 | + sbinfo = au_sbi(sb); | |
34345 | + if (!au_opt_test(sbinfo->si_mntflags, XINO)) | |
34346 | + goto out; | |
34347 | + | |
34348 | + file = sbinfo->si_xib; | |
c06a8ce3 | 34349 | + if (vfsub_f_size_read(file) <= PAGE_SIZE) |
1facf9fc | 34350 | + goto out; |
34351 | + | |
34352 | + au_xino_lock_dir(sb, file, &ldir); | |
34353 | + /* mnt_want_write() is unnecessary here */ | |
34354 | + file = au_xino_create2(sbinfo->si_xib, NULL); | |
34355 | + au_xino_unlock_dir(&ldir); | |
34356 | + err = PTR_ERR(file); | |
34357 | + if (IS_ERR(file)) | |
34358 | + goto out; | |
34359 | + fput(sbinfo->si_xib); | |
34360 | + sbinfo->si_xib = file; | |
34361 | + | |
34362 | + p = sbinfo->si_xib_buf; | |
34363 | + memset(p, 0, PAGE_SIZE); | |
34364 | + pos = 0; | |
34365 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos); | |
34366 | + if (unlikely(sz != PAGE_SIZE)) { | |
34367 | + err = sz; | |
34368 | + AuIOErr("err %d\n", err); | |
34369 | + if (sz >= 0) | |
34370 | + err = -EIO; | |
34371 | + goto out; | |
34372 | + } | |
34373 | + | |
34374 | + mutex_lock(&sbinfo->si_xib_mtx); | |
34375 | + /* mnt_want_write() is unnecessary here */ | |
34376 | + err = xib_restore(sb); | |
34377 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
34378 | + | |
34379 | +out: | |
34380 | + return err; | |
34381 | +} | |
34382 | + | |
34383 | +/* ---------------------------------------------------------------------- */ | |
34384 | + | |
34385 | +/* | |
34386 | + * xino mount option handlers | |
34387 | + */ | |
34388 | +static au_readf_t find_readf(struct file *h_file) | |
34389 | +{ | |
34390 | + const struct file_operations *fop = h_file->f_op; | |
34391 | + | |
523b37e3 AM |
34392 | + if (fop->read) |
34393 | + return fop->read; | |
34394 | + if (fop->aio_read) | |
34395 | + return do_sync_read; | |
076b876e AM |
34396 | + if (fop->read_iter) |
34397 | + return new_sync_read; | |
1facf9fc | 34398 | + return ERR_PTR(-ENOSYS); |
34399 | +} | |
34400 | + | |
34401 | +static au_writef_t find_writef(struct file *h_file) | |
34402 | +{ | |
34403 | + const struct file_operations *fop = h_file->f_op; | |
34404 | + | |
523b37e3 AM |
34405 | + if (fop->write) |
34406 | + return fop->write; | |
34407 | + if (fop->aio_write) | |
34408 | + return do_sync_write; | |
076b876e AM |
34409 | + if (fop->write_iter) |
34410 | + return new_sync_write; | |
1facf9fc | 34411 | + return ERR_PTR(-ENOSYS); |
34412 | +} | |
34413 | + | |
34414 | +/* xino bitmap */ | |
34415 | +static void xino_clear_xib(struct super_block *sb) | |
34416 | +{ | |
34417 | + struct au_sbinfo *sbinfo; | |
34418 | + | |
dece6358 AM |
34419 | + SiMustWriteLock(sb); |
34420 | + | |
1facf9fc | 34421 | + sbinfo = au_sbi(sb); |
34422 | + sbinfo->si_xread = NULL; | |
34423 | + sbinfo->si_xwrite = NULL; | |
34424 | + if (sbinfo->si_xib) | |
34425 | + fput(sbinfo->si_xib); | |
34426 | + sbinfo->si_xib = NULL; | |
34427 | + free_page((unsigned long)sbinfo->si_xib_buf); | |
34428 | + sbinfo->si_xib_buf = NULL; | |
34429 | +} | |
34430 | + | |
34431 | +static int au_xino_set_xib(struct super_block *sb, struct file *base) | |
34432 | +{ | |
34433 | + int err; | |
34434 | + loff_t pos; | |
34435 | + struct au_sbinfo *sbinfo; | |
34436 | + struct file *file; | |
34437 | + | |
dece6358 AM |
34438 | + SiMustWriteLock(sb); |
34439 | + | |
1facf9fc | 34440 | + sbinfo = au_sbi(sb); |
34441 | + file = au_xino_create2(base, sbinfo->si_xib); | |
34442 | + err = PTR_ERR(file); | |
34443 | + if (IS_ERR(file)) | |
34444 | + goto out; | |
34445 | + if (sbinfo->si_xib) | |
34446 | + fput(sbinfo->si_xib); | |
34447 | + sbinfo->si_xib = file; | |
34448 | + sbinfo->si_xread = find_readf(file); | |
34449 | + sbinfo->si_xwrite = find_writef(file); | |
34450 | + | |
34451 | + err = -ENOMEM; | |
34452 | + if (!sbinfo->si_xib_buf) | |
34453 | + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS); | |
34454 | + if (unlikely(!sbinfo->si_xib_buf)) | |
34455 | + goto out_unset; | |
34456 | + | |
34457 | + sbinfo->si_xib_last_pindex = 0; | |
34458 | + sbinfo->si_xib_next_bit = 0; | |
c06a8ce3 | 34459 | + if (vfsub_f_size_read(file) < PAGE_SIZE) { |
1facf9fc | 34460 | + pos = 0; |
34461 | + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf, | |
34462 | + PAGE_SIZE, &pos); | |
34463 | + if (unlikely(err != PAGE_SIZE)) | |
34464 | + goto out_free; | |
34465 | + } | |
34466 | + err = 0; | |
34467 | + goto out; /* success */ | |
34468 | + | |
4f0767ce | 34469 | +out_free: |
1facf9fc | 34470 | + free_page((unsigned long)sbinfo->si_xib_buf); |
b752ccd1 AM |
34471 | + sbinfo->si_xib_buf = NULL; |
34472 | + if (err >= 0) | |
34473 | + err = -EIO; | |
4f0767ce | 34474 | +out_unset: |
b752ccd1 AM |
34475 | + fput(sbinfo->si_xib); |
34476 | + sbinfo->si_xib = NULL; | |
34477 | + sbinfo->si_xread = NULL; | |
34478 | + sbinfo->si_xwrite = NULL; | |
4f0767ce | 34479 | +out: |
b752ccd1 | 34480 | + return err; |
1facf9fc | 34481 | +} |
34482 | + | |
b752ccd1 AM |
34483 | +/* xino for each branch */ |
34484 | +static void xino_clear_br(struct super_block *sb) | |
34485 | +{ | |
34486 | + aufs_bindex_t bindex, bend; | |
34487 | + struct au_branch *br; | |
1facf9fc | 34488 | + |
b752ccd1 AM |
34489 | + bend = au_sbend(sb); |
34490 | + for (bindex = 0; bindex <= bend; bindex++) { | |
34491 | + br = au_sbr(sb, bindex); | |
34492 | + if (!br || !br->br_xino.xi_file) | |
34493 | + continue; | |
34494 | + | |
34495 | + fput(br->br_xino.xi_file); | |
34496 | + br->br_xino.xi_file = NULL; | |
34497 | + } | |
34498 | +} | |
34499 | + | |
34500 | +static int au_xino_set_br(struct super_block *sb, struct file *base) | |
1facf9fc | 34501 | +{ |
34502 | + int err; | |
b752ccd1 AM |
34503 | + ino_t ino; |
34504 | + aufs_bindex_t bindex, bend, bshared; | |
34505 | + struct { | |
34506 | + struct file *old, *new; | |
34507 | + } *fpair, *p; | |
34508 | + struct au_branch *br; | |
34509 | + struct inode *inode; | |
34510 | + au_writef_t writef; | |
1facf9fc | 34511 | + |
b752ccd1 AM |
34512 | + SiMustWriteLock(sb); |
34513 | + | |
34514 | + err = -ENOMEM; | |
34515 | + bend = au_sbend(sb); | |
34516 | + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS); | |
34517 | + if (unlikely(!fpair)) | |
1facf9fc | 34518 | + goto out; |
34519 | + | |
b752ccd1 AM |
34520 | + inode = sb->s_root->d_inode; |
34521 | + ino = AUFS_ROOT_INO; | |
34522 | + writef = au_sbi(sb)->si_xwrite; | |
34523 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) { | |
34524 | + br = au_sbr(sb, bindex); | |
34525 | + bshared = is_sb_shared(sb, bindex, bindex - 1); | |
34526 | + if (bshared >= 0) { | |
34527 | + /* shared xino */ | |
34528 | + *p = fpair[bshared]; | |
34529 | + get_file(p->new); | |
34530 | + } | |
34531 | + | |
34532 | + if (!p->new) { | |
34533 | + /* new xino */ | |
34534 | + p->old = br->br_xino.xi_file; | |
34535 | + p->new = au_xino_create2(base, br->br_xino.xi_file); | |
34536 | + err = PTR_ERR(p->new); | |
34537 | + if (IS_ERR(p->new)) { | |
34538 | + p->new = NULL; | |
34539 | + goto out_pair; | |
34540 | + } | |
34541 | + } | |
34542 | + | |
34543 | + err = au_xino_do_write(writef, p->new, | |
34544 | + au_h_iptr(inode, bindex)->i_ino, ino); | |
34545 | + if (unlikely(err)) | |
34546 | + goto out_pair; | |
34547 | + } | |
34548 | + | |
34549 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) { | |
34550 | + br = au_sbr(sb, bindex); | |
34551 | + if (br->br_xino.xi_file) | |
34552 | + fput(br->br_xino.xi_file); | |
34553 | + get_file(p->new); | |
34554 | + br->br_xino.xi_file = p->new; | |
34555 | + } | |
1facf9fc | 34556 | + |
4f0767ce | 34557 | +out_pair: |
b752ccd1 AM |
34558 | + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) |
34559 | + if (p->new) | |
34560 | + fput(p->new); | |
34561 | + else | |
34562 | + break; | |
34563 | + kfree(fpair); | |
4f0767ce | 34564 | +out: |
1facf9fc | 34565 | + return err; |
34566 | +} | |
b752ccd1 AM |
34567 | + |
34568 | +void au_xino_clr(struct super_block *sb) | |
34569 | +{ | |
34570 | + struct au_sbinfo *sbinfo; | |
34571 | + | |
34572 | + au_xigen_clr(sb); | |
34573 | + xino_clear_xib(sb); | |
34574 | + xino_clear_br(sb); | |
34575 | + sbinfo = au_sbi(sb); | |
34576 | + /* lvalue, do not call au_mntflags() */ | |
34577 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
34578 | +} | |
34579 | + | |
34580 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount) | |
34581 | +{ | |
34582 | + int err, skip; | |
34583 | + struct dentry *parent, *cur_parent; | |
34584 | + struct qstr *dname, *cur_name; | |
34585 | + struct file *cur_xino; | |
34586 | + struct inode *dir; | |
34587 | + struct au_sbinfo *sbinfo; | |
34588 | + | |
34589 | + SiMustWriteLock(sb); | |
34590 | + | |
34591 | + err = 0; | |
34592 | + sbinfo = au_sbi(sb); | |
34593 | + parent = dget_parent(xino->file->f_dentry); | |
34594 | + if (remount) { | |
34595 | + skip = 0; | |
34596 | + dname = &xino->file->f_dentry->d_name; | |
34597 | + cur_xino = sbinfo->si_xib; | |
34598 | + if (cur_xino) { | |
34599 | + cur_parent = dget_parent(cur_xino->f_dentry); | |
34600 | + cur_name = &cur_xino->f_dentry->d_name; | |
34601 | + skip = (cur_parent == parent | |
38d290e6 | 34602 | + && au_qstreq(dname, cur_name)); |
b752ccd1 AM |
34603 | + dput(cur_parent); |
34604 | + } | |
34605 | + if (skip) | |
34606 | + goto out; | |
34607 | + } | |
34608 | + | |
34609 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
34610 | + dir = parent->d_inode; | |
34611 | + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT); | |
34612 | + /* mnt_want_write() is unnecessary here */ | |
34613 | + err = au_xino_set_xib(sb, xino->file); | |
34614 | + if (!err) | |
34615 | + err = au_xigen_set(sb, xino->file); | |
34616 | + if (!err) | |
34617 | + err = au_xino_set_br(sb, xino->file); | |
34618 | + mutex_unlock(&dir->i_mutex); | |
34619 | + if (!err) | |
34620 | + goto out; /* success */ | |
34621 | + | |
34622 | + /* reset all */ | |
34623 | + AuIOErr("failed creating xino(%d).\n", err); | |
c1595e42 JR |
34624 | + au_xigen_clr(sb); |
34625 | + xino_clear_xib(sb); | |
b752ccd1 | 34626 | + |
4f0767ce | 34627 | +out: |
b752ccd1 AM |
34628 | + dput(parent); |
34629 | + return err; | |
34630 | +} | |
34631 | + | |
34632 | +/* ---------------------------------------------------------------------- */ | |
34633 | + | |
34634 | +/* | |
34635 | + * create a xinofile at the default place/path. | |
34636 | + */ | |
34637 | +struct file *au_xino_def(struct super_block *sb) | |
34638 | +{ | |
34639 | + struct file *file; | |
34640 | + char *page, *p; | |
34641 | + struct au_branch *br; | |
34642 | + struct super_block *h_sb; | |
34643 | + struct path path; | |
34644 | + aufs_bindex_t bend, bindex, bwr; | |
34645 | + | |
34646 | + br = NULL; | |
34647 | + bend = au_sbend(sb); | |
34648 | + bwr = -1; | |
34649 | + for (bindex = 0; bindex <= bend; bindex++) { | |
34650 | + br = au_sbr(sb, bindex); | |
34651 | + if (au_br_writable(br->br_perm) | |
86dc4139 | 34652 | + && !au_test_fs_bad_xino(au_br_sb(br))) { |
b752ccd1 AM |
34653 | + bwr = bindex; |
34654 | + break; | |
34655 | + } | |
34656 | + } | |
34657 | + | |
7f207e10 AM |
34658 | + if (bwr >= 0) { |
34659 | + file = ERR_PTR(-ENOMEM); | |
537831f9 | 34660 | + page = (void *)__get_free_page(GFP_NOFS); |
7f207e10 AM |
34661 | + if (unlikely(!page)) |
34662 | + goto out; | |
86dc4139 | 34663 | + path.mnt = au_br_mnt(br); |
7f207e10 AM |
34664 | + path.dentry = au_h_dptr(sb->s_root, bwr); |
34665 | + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME)); | |
34666 | + file = (void *)p; | |
34667 | + if (!IS_ERR(p)) { | |
34668 | + strcat(p, "/" AUFS_XINO_FNAME); | |
34669 | + AuDbg("%s\n", p); | |
34670 | + file = au_xino_create(sb, p, /*silent*/0); | |
34671 | + if (!IS_ERR(file)) | |
34672 | + au_xino_brid_set(sb, br->br_id); | |
34673 | + } | |
537831f9 | 34674 | + free_page((unsigned long)page); |
7f207e10 AM |
34675 | + } else { |
34676 | + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0); | |
34677 | + if (IS_ERR(file)) | |
34678 | + goto out; | |
34679 | + h_sb = file->f_dentry->d_sb; | |
34680 | + if (unlikely(au_test_fs_bad_xino(h_sb))) { | |
34681 | + pr_err("xino doesn't support %s(%s)\n", | |
34682 | + AUFS_XINO_DEFPATH, au_sbtype(h_sb)); | |
34683 | + fput(file); | |
34684 | + file = ERR_PTR(-EINVAL); | |
34685 | + } | |
34686 | + if (!IS_ERR(file)) | |
34687 | + au_xino_brid_set(sb, -1); | |
34688 | + } | |
0c5527e5 | 34689 | + |
7f207e10 AM |
34690 | +out: |
34691 | + return file; | |
34692 | +} | |
34693 | + | |
34694 | +/* ---------------------------------------------------------------------- */ | |
34695 | + | |
34696 | +int au_xino_path(struct seq_file *seq, struct file *file) | |
34697 | +{ | |
34698 | + int err; | |
34699 | + | |
34700 | + err = au_seq_path(seq, &file->f_path); | |
34701 | + if (unlikely(err < 0)) | |
34702 | + goto out; | |
34703 | + | |
34704 | + err = 0; | |
34705 | +#define Deleted "\\040(deleted)" | |
34706 | + seq->count -= sizeof(Deleted) - 1; | |
34707 | + AuDebugOn(memcmp(seq->buf + seq->count, Deleted, | |
34708 | + sizeof(Deleted) - 1)); | |
34709 | +#undef Deleted | |
34710 | + | |
34711 | +out: | |
34712 | + return err; | |
34713 | +} | |
537831f9 AM |
34714 | diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h |
34715 | --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100 | |
c1595e42 JR |
34716 | +++ linux/include/uapi/linux/aufs_type.h 2015-01-25 13:00:38.637713742 +0100 |
34717 | @@ -0,0 +1,419 @@ | |
7f207e10 | 34718 | +/* |
523b37e3 | 34719 | + * Copyright (C) 2005-2014 Junjiro R. Okajima |
7f207e10 AM |
34720 | + * |
34721 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34722 | + * it under the terms of the GNU General Public License as published by | |
34723 | + * the Free Software Foundation; either version 2 of the License, or | |
34724 | + * (at your option) any later version. | |
34725 | + * | |
34726 | + * This program is distributed in the hope that it will be useful, | |
34727 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34728 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34729 | + * GNU General Public License for more details. | |
34730 | + * | |
34731 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 34732 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
34733 | + */ |
34734 | + | |
34735 | +#ifndef __AUFS_TYPE_H__ | |
34736 | +#define __AUFS_TYPE_H__ | |
34737 | + | |
f6c5ef8b AM |
34738 | +#define AUFS_NAME "aufs" |
34739 | + | |
9dbd164d | 34740 | +#ifdef __KERNEL__ |
f6c5ef8b AM |
34741 | +/* |
34742 | + * define it before including all other headers. | |
34743 | + * sched.h may use pr_* macros before defining "current", so define the | |
34744 | + * no-current version first, and re-define later. | |
34745 | + */ | |
34746 | +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__ | |
34747 | +#include <linux/sched.h> | |
34748 | +#undef pr_fmt | |
a2a7ad62 AM |
34749 | +#define pr_fmt(fmt) \ |
34750 | + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \ | |
34751 | + (int)sizeof(current->comm), current->comm, current->pid | |
9dbd164d AM |
34752 | +#else |
34753 | +#include <stdint.h> | |
34754 | +#include <sys/types.h> | |
f6c5ef8b | 34755 | +#endif /* __KERNEL__ */ |
7f207e10 | 34756 | + |
f6c5ef8b AM |
34757 | +#include <linux/limits.h> |
34758 | + | |
c1595e42 | 34759 | +#define AUFS_VERSION "3.18.1+-20150119" |
7f207e10 AM |
34760 | + |
34761 | +/* todo? move this to linux-2.6.19/include/magic.h */ | |
34762 | +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's') | |
34763 | + | |
34764 | +/* ---------------------------------------------------------------------- */ | |
34765 | + | |
34766 | +#ifdef CONFIG_AUFS_BRANCH_MAX_127 | |
9dbd164d | 34767 | +typedef int8_t aufs_bindex_t; |
7f207e10 AM |
34768 | +#define AUFS_BRANCH_MAX 127 |
34769 | +#else | |
9dbd164d | 34770 | +typedef int16_t aufs_bindex_t; |
7f207e10 AM |
34771 | +#ifdef CONFIG_AUFS_BRANCH_MAX_511 |
34772 | +#define AUFS_BRANCH_MAX 511 | |
34773 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023) | |
34774 | +#define AUFS_BRANCH_MAX 1023 | |
34775 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767) | |
34776 | +#define AUFS_BRANCH_MAX 32767 | |
34777 | +#endif | |
34778 | +#endif | |
34779 | + | |
34780 | +#ifdef __KERNEL__ | |
34781 | +#ifndef AUFS_BRANCH_MAX | |
34782 | +#error unknown CONFIG_AUFS_BRANCH_MAX value | |
34783 | +#endif | |
34784 | +#endif /* __KERNEL__ */ | |
34785 | + | |
34786 | +/* ---------------------------------------------------------------------- */ | |
34787 | + | |
7f207e10 AM |
34788 | +#define AUFS_FSTYPE AUFS_NAME |
34789 | + | |
34790 | +#define AUFS_ROOT_INO 2 | |
34791 | +#define AUFS_FIRST_INO 11 | |
34792 | + | |
34793 | +#define AUFS_WH_PFX ".wh." | |
34794 | +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1) | |
34795 | +#define AUFS_WH_TMP_LEN 4 | |
86dc4139 | 34796 | +/* a limit for rmdir/rename a dir and copyup */ |
7f207e10 AM |
34797 | +#define AUFS_MAX_NAMELEN (NAME_MAX \ |
34798 | + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\ | |
34799 | + - 1 /* dot */\ | |
34800 | + - AUFS_WH_TMP_LEN) /* hex */ | |
34801 | +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino" | |
34802 | +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME | |
392086de AM |
34803 | +#define AUFS_XINO_DEF_SEC 30 /* seconds */ |
34804 | +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */ | |
7f207e10 AM |
34805 | +#define AUFS_DIRWH_DEF 3 |
34806 | +#define AUFS_RDCACHE_DEF 10 /* seconds */ | |
027c5e7a | 34807 | +#define AUFS_RDCACHE_MAX 3600 /* seconds */ |
7f207e10 AM |
34808 | +#define AUFS_RDBLK_DEF 512 /* bytes */ |
34809 | +#define AUFS_RDHASH_DEF 32 | |
34810 | +#define AUFS_WKQ_NAME AUFS_NAME "d" | |
027c5e7a AM |
34811 | +#define AUFS_MFS_DEF_SEC 30 /* seconds */ |
34812 | +#define AUFS_MFS_MAX_SEC 3600 /* seconds */ | |
076b876e | 34813 | +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */ |
86dc4139 | 34814 | +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */ |
7f207e10 AM |
34815 | + |
34816 | +/* pseudo-link maintenace under /proc */ | |
34817 | +#define AUFS_PLINK_MAINT_NAME "plink_maint" | |
34818 | +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME | |
34819 | +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME | |
34820 | + | |
34821 | +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */ | |
34822 | +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME | |
34823 | + | |
34824 | +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME | |
34825 | +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk" | |
34826 | +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph" | |
34827 | + | |
34828 | +/* doubly whiteouted */ | |
34829 | +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME | |
34830 | +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME | |
34831 | +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME | |
34832 | + | |
1e00d052 | 34833 | +/* branch permissions and attributes */ |
7f207e10 AM |
34834 | +#define AUFS_BRPERM_RW "rw" |
34835 | +#define AUFS_BRPERM_RO "ro" | |
34836 | +#define AUFS_BRPERM_RR "rr" | |
076b876e AM |
34837 | +#define AUFS_BRATTR_COO_REG "coo_reg" |
34838 | +#define AUFS_BRATTR_COO_ALL "coo_all" | |
34839 | +#define AUFS_BRATTR_FHSM "fhsm" | |
34840 | +#define AUFS_BRATTR_UNPIN "unpin" | |
c1595e42 JR |
34841 | +#define AUFS_BRATTR_ICEX "icex" |
34842 | +#define AUFS_BRATTR_ICEX_SEC "icexsec" | |
34843 | +#define AUFS_BRATTR_ICEX_SYS "icexsys" | |
34844 | +#define AUFS_BRATTR_ICEX_TR "icextr" | |
34845 | +#define AUFS_BRATTR_ICEX_USR "icexusr" | |
34846 | +#define AUFS_BRATTR_ICEX_OTH "icexoth" | |
1e00d052 AM |
34847 | +#define AUFS_BRRATTR_WH "wh" |
34848 | +#define AUFS_BRWATTR_NLWH "nolwh" | |
076b876e AM |
34849 | +#define AUFS_BRWATTR_MOO "moo" |
34850 | + | |
34851 | +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */ | |
34852 | +#define AuBrPerm_RO (1 << 1) /* readonly */ | |
34853 | +#define AuBrPerm_RR (1 << 2) /* natively readonly */ | |
34854 | +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR) | |
34855 | + | |
34856 | +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */ | |
34857 | +#define AuBrAttr_COO_ALL (1 << 4) | |
34858 | +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL) | |
34859 | + | |
34860 | +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */ | |
34861 | +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of | |
c1595e42 JR |
34862 | + branch. meaningless since |
34863 | + linux-3.18-rc1 */ | |
34864 | + | |
34865 | +/* ignore error in copying XATTR */ | |
34866 | +#define AuBrAttr_ICEX_SEC (1 << 7) | |
34867 | +#define AuBrAttr_ICEX_SYS (1 << 8) | |
34868 | +#define AuBrAttr_ICEX_TR (1 << 9) | |
34869 | +#define AuBrAttr_ICEX_USR (1 << 10) | |
34870 | +#define AuBrAttr_ICEX_OTH (1 << 11) | |
34871 | +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \ | |
34872 | + | AuBrAttr_ICEX_SYS \ | |
34873 | + | AuBrAttr_ICEX_TR \ | |
34874 | + | AuBrAttr_ICEX_USR \ | |
34875 | + | AuBrAttr_ICEX_OTH) | |
34876 | + | |
34877 | +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */ | |
076b876e AM |
34878 | +#define AuBrRAttr_Mask AuBrRAttr_WH |
34879 | + | |
c1595e42 JR |
34880 | +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */ |
34881 | +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */ | |
076b876e AM |
34882 | +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO) |
34883 | + | |
34884 | +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO) | |
34885 | + | |
c1595e42 | 34886 | +/* #warning test userspace */ |
076b876e AM |
34887 | +#ifdef __KERNEL__ |
34888 | +#ifndef CONFIG_AUFS_FHSM | |
34889 | +#undef AuBrAttr_FHSM | |
34890 | +#define AuBrAttr_FHSM 0 | |
34891 | +#endif | |
c1595e42 JR |
34892 | +#ifndef CONFIG_AUFS_XATTR |
34893 | +#undef AuBrAttr_ICEX | |
34894 | +#define AuBrAttr_ICEX 0 | |
34895 | +#undef AuBrAttr_ICEX_SEC | |
34896 | +#define AuBrAttr_ICEX_SEC 0 | |
34897 | +#undef AuBrAttr_ICEX_SYS | |
34898 | +#define AuBrAttr_ICEX_SYS 0 | |
34899 | +#undef AuBrAttr_ICEX_TR | |
34900 | +#define AuBrAttr_ICEX_TR 0 | |
34901 | +#undef AuBrAttr_ICEX_USR | |
34902 | +#define AuBrAttr_ICEX_USR 0 | |
34903 | +#undef AuBrAttr_ICEX_OTH | |
34904 | +#define AuBrAttr_ICEX_OTH 0 | |
34905 | +#endif | |
076b876e AM |
34906 | +#endif |
34907 | + | |
34908 | +/* the longest combination */ | |
c1595e42 JR |
34909 | +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */ |
34910 | +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \ | |
34911 | + "+" AUFS_BRATTR_COO_REG \ | |
34912 | + "+" AUFS_BRATTR_FHSM \ | |
34913 | + "+" AUFS_BRATTR_UNPIN \ | |
34914 | + "+" AUFS_BRATTR_ICEX_SEC \ | |
34915 | + "+" AUFS_BRATTR_ICEX_SYS \ | |
34916 | + "+" AUFS_BRATTR_ICEX_USR \ | |
34917 | + "+" AUFS_BRATTR_ICEX_OTH \ | |
076b876e AM |
34918 | + "+" AUFS_BRWATTR_NLWH) |
34919 | + | |
34920 | +typedef struct { | |
34921 | + char a[AuBrPermStrSz]; | |
34922 | +} au_br_perm_str_t; | |
34923 | + | |
34924 | +static inline int au_br_writable(int brperm) | |
34925 | +{ | |
34926 | + return brperm & AuBrPerm_RW; | |
34927 | +} | |
34928 | + | |
34929 | +static inline int au_br_whable(int brperm) | |
34930 | +{ | |
34931 | + return brperm & (AuBrPerm_RW | AuBrRAttr_WH); | |
34932 | +} | |
34933 | + | |
34934 | +static inline int au_br_wh_linkable(int brperm) | |
34935 | +{ | |
34936 | + return !(brperm & AuBrWAttr_NoLinkWH); | |
34937 | +} | |
34938 | + | |
34939 | +static inline int au_br_cmoo(int brperm) | |
34940 | +{ | |
34941 | + return brperm & AuBrAttr_CMOO_Mask; | |
34942 | +} | |
34943 | + | |
34944 | +static inline int au_br_fhsm(int brperm) | |
34945 | +{ | |
34946 | + return brperm & AuBrAttr_FHSM; | |
34947 | +} | |
7f207e10 AM |
34948 | + |
34949 | +/* ---------------------------------------------------------------------- */ | |
34950 | + | |
34951 | +/* ioctl */ | |
34952 | +enum { | |
34953 | + /* readdir in userspace */ | |
34954 | + AuCtl_RDU, | |
34955 | + AuCtl_RDU_INO, | |
34956 | + | |
076b876e AM |
34957 | + AuCtl_WBR_FD, /* pathconf wrapper */ |
34958 | + AuCtl_IBUSY, /* busy inode */ | |
34959 | + AuCtl_MVDOWN, /* move-down */ | |
34960 | + AuCtl_BR, /* info about branches */ | |
34961 | + AuCtl_FHSM_FD /* connection for fhsm */ | |
7f207e10 AM |
34962 | +}; |
34963 | + | |
34964 | +/* borrowed from linux/include/linux/kernel.h */ | |
34965 | +#ifndef ALIGN | |
34966 | +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) | |
34967 | +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | |
34968 | +#endif | |
34969 | + | |
34970 | +/* borrowed from linux/include/linux/compiler-gcc3.h */ | |
34971 | +#ifndef __aligned | |
34972 | +#define __aligned(x) __attribute__((aligned(x))) | |
53392da6 AM |
34973 | +#endif |
34974 | + | |
34975 | +#ifdef __KERNEL__ | |
34976 | +#ifndef __packed | |
7f207e10 AM |
34977 | +#define __packed __attribute__((packed)) |
34978 | +#endif | |
53392da6 | 34979 | +#endif |
7f207e10 AM |
34980 | + |
34981 | +struct au_rdu_cookie { | |
9dbd164d AM |
34982 | + uint64_t h_pos; |
34983 | + int16_t bindex; | |
34984 | + uint8_t flags; | |
34985 | + uint8_t pad; | |
34986 | + uint32_t generation; | |
7f207e10 AM |
34987 | +} __aligned(8); |
34988 | + | |
34989 | +struct au_rdu_ent { | |
9dbd164d AM |
34990 | + uint64_t ino; |
34991 | + int16_t bindex; | |
34992 | + uint8_t type; | |
34993 | + uint8_t nlen; | |
34994 | + uint8_t wh; | |
7f207e10 AM |
34995 | + char name[0]; |
34996 | +} __aligned(8); | |
34997 | + | |
34998 | +static inline int au_rdu_len(int nlen) | |
34999 | +{ | |
35000 | + /* include the terminating NULL */ | |
35001 | + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1, | |
9dbd164d | 35002 | + sizeof(uint64_t)); |
7f207e10 AM |
35003 | +} |
35004 | + | |
35005 | +union au_rdu_ent_ul { | |
35006 | + struct au_rdu_ent __user *e; | |
9dbd164d | 35007 | + uint64_t ul; |
7f207e10 AM |
35008 | +}; |
35009 | + | |
35010 | +enum { | |
35011 | + AufsCtlRduV_SZ, | |
35012 | + AufsCtlRduV_End | |
35013 | +}; | |
35014 | + | |
35015 | +struct aufs_rdu { | |
35016 | + /* input */ | |
35017 | + union { | |
9dbd164d AM |
35018 | + uint64_t sz; /* AuCtl_RDU */ |
35019 | + uint64_t nent; /* AuCtl_RDU_INO */ | |
7f207e10 AM |
35020 | + }; |
35021 | + union au_rdu_ent_ul ent; | |
9dbd164d | 35022 | + uint16_t verify[AufsCtlRduV_End]; |
7f207e10 AM |
35023 | + |
35024 | + /* input/output */ | |
9dbd164d | 35025 | + uint32_t blk; |
7f207e10 AM |
35026 | + |
35027 | + /* output */ | |
35028 | + union au_rdu_ent_ul tail; | |
35029 | + /* number of entries which were added in a single call */ | |
9dbd164d AM |
35030 | + uint64_t rent; |
35031 | + uint8_t full; | |
35032 | + uint8_t shwh; | |
7f207e10 AM |
35033 | + |
35034 | + struct au_rdu_cookie cookie; | |
35035 | +} __aligned(8); | |
35036 | + | |
1e00d052 AM |
35037 | +/* ---------------------------------------------------------------------- */ |
35038 | + | |
35039 | +struct aufs_wbr_fd { | |
9dbd164d AM |
35040 | + uint32_t oflags; |
35041 | + int16_t brid; | |
1e00d052 AM |
35042 | +} __aligned(8); |
35043 | + | |
35044 | +/* ---------------------------------------------------------------------- */ | |
35045 | + | |
027c5e7a | 35046 | +struct aufs_ibusy { |
9dbd164d AM |
35047 | + uint64_t ino, h_ino; |
35048 | + int16_t bindex; | |
027c5e7a AM |
35049 | +} __aligned(8); |
35050 | + | |
1e00d052 AM |
35051 | +/* ---------------------------------------------------------------------- */ |
35052 | + | |
392086de AM |
35053 | +/* error code for move-down */ |
35054 | +/* the actual message strings are implemented in aufs-util.git */ | |
35055 | +enum { | |
35056 | + EAU_MVDOWN_OPAQUE = 1, | |
35057 | + EAU_MVDOWN_WHITEOUT, | |
35058 | + EAU_MVDOWN_UPPER, | |
35059 | + EAU_MVDOWN_BOTTOM, | |
35060 | + EAU_MVDOWN_NOUPPER, | |
35061 | + EAU_MVDOWN_NOLOWERBR, | |
35062 | + EAU_Last | |
35063 | +}; | |
35064 | + | |
c2b27bf2 | 35065 | +/* flags for move-down */ |
392086de AM |
35066 | +#define AUFS_MVDOWN_DMSG 1 |
35067 | +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */ | |
35068 | +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */ | |
35069 | +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */ | |
35070 | +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */ | |
35071 | +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */ | |
35072 | +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */ | |
35073 | +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */ | |
35074 | +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */ | |
076b876e AM |
35075 | +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */ |
35076 | +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */ | |
35077 | +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */ | |
35078 | +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */ | |
c2b27bf2 | 35079 | + |
076b876e | 35080 | +/* index for move-down */ |
392086de AM |
35081 | +enum { |
35082 | + AUFS_MVDOWN_UPPER, | |
35083 | + AUFS_MVDOWN_LOWER, | |
35084 | + AUFS_MVDOWN_NARRAY | |
35085 | +}; | |
35086 | + | |
076b876e AM |
35087 | +/* |
35088 | + * additional info of move-down | |
35089 | + * number of free blocks and inodes. | |
35090 | + * subset of struct kstatfs, but smaller and always 64bit. | |
35091 | + */ | |
35092 | +struct aufs_stfs { | |
35093 | + uint64_t f_blocks; | |
35094 | + uint64_t f_bavail; | |
35095 | + uint64_t f_files; | |
35096 | + uint64_t f_ffree; | |
35097 | +}; | |
35098 | + | |
35099 | +struct aufs_stbr { | |
35100 | + int16_t brid; /* optional input */ | |
35101 | + int16_t bindex; /* output */ | |
35102 | + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */ | |
35103 | +} __aligned(8); | |
35104 | + | |
c2b27bf2 | 35105 | +struct aufs_mvdown { |
076b876e AM |
35106 | + uint32_t flags; /* input/output */ |
35107 | + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */ | |
35108 | + int8_t au_errno; /* output */ | |
35109 | +} __aligned(8); | |
35110 | + | |
35111 | +/* ---------------------------------------------------------------------- */ | |
35112 | + | |
35113 | +union aufs_brinfo { | |
35114 | + /* PATH_MAX may differ between kernel-space and user-space */ | |
35115 | + char _spacer[4096]; | |
392086de | 35116 | + struct { |
076b876e AM |
35117 | + int16_t id; |
35118 | + int perm; | |
35119 | + char path[0]; | |
35120 | + }; | |
c2b27bf2 AM |
35121 | +} __aligned(8); |
35122 | + | |
35123 | +/* ---------------------------------------------------------------------- */ | |
35124 | + | |
7f207e10 AM |
35125 | +#define AuCtlType 'A' |
35126 | +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu) | |
35127 | +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu) | |
1e00d052 AM |
35128 | +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \ |
35129 | + struct aufs_wbr_fd) | |
027c5e7a | 35130 | +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy) |
392086de AM |
35131 | +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \ |
35132 | + struct aufs_mvdown) | |
076b876e AM |
35133 | +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo) |
35134 | +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int) | |
7f207e10 AM |
35135 | + |
35136 | +#endif /* __AUFS_TYPE_H__ */ | |
c1595e42 | 35137 | aufs3.18.1+ loopback patch |
93a1a2a2 JR |
35138 | |
35139 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c | |
076b876e | 35140 | index 30efd68..77b31b4 100644 |
93a1a2a2 JR |
35141 | --- a/drivers/block/loop.c |
35142 | +++ b/drivers/block/loop.c | |
35143 | @@ -514,7 +514,7 @@ out: | |
35144 | } | |
35145 | ||
35146 | struct switch_request { | |
35147 | - struct file *file; | |
35148 | + struct file *file, *virt_file; | |
35149 | struct completion wait; | |
35150 | }; | |
35151 | ||
35152 | @@ -576,7 +576,8 @@ static int loop_thread(void *data) | |
35153 | * First it needs to flush existing IO, it does this by sending a magic | |
35154 | * BIO down the pipe. The completion of this BIO does the actual switch. | |
35155 | */ | |
35156 | -static int loop_switch(struct loop_device *lo, struct file *file) | |
35157 | +static int loop_switch(struct loop_device *lo, struct file *file, | |
35158 | + struct file *virt_file) | |
35159 | { | |
35160 | struct switch_request w; | |
35161 | struct bio *bio = bio_alloc(GFP_KERNEL, 0); | |
35162 | @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file) | |
35163 | return -ENOMEM; | |
35164 | init_completion(&w.wait); | |
35165 | w.file = file; | |
35166 | + w.virt_file = virt_file; | |
35167 | bio->bi_private = &w; | |
35168 | bio->bi_bdev = NULL; | |
35169 | loop_make_request(lo->lo_queue, bio); | |
35170 | @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo) | |
35171 | if (!lo->lo_thread) | |
35172 | return 0; | |
35173 | ||
35174 | - return loop_switch(lo, NULL); | |
35175 | + return loop_switch(lo, NULL, NULL); | |
35176 | } | |
35177 | ||
35178 | /* | |
35179 | @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) | |
35180 | mapping = file->f_mapping; | |
35181 | mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); | |
35182 | lo->lo_backing_file = file; | |
35183 | + lo->lo_backing_virt_file = p->virt_file; | |
35184 | lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ? | |
35185 | mapping->host->i_bdev->bd_block_size : PAGE_SIZE; | |
35186 | lo->old_gfp_mask = mapping_gfp_mask(mapping); | |
35187 | @@ -627,6 +630,13 @@ out: | |
35188 | complete(&p->wait); | |
35189 | } | |
35190 | ||
35191 | +static struct file *loop_real_file(struct file *file) | |
35192 | +{ | |
35193 | + struct file *f = NULL; | |
35194 | + if (file->f_dentry->d_sb->s_op->real_loop) | |
35195 | + f = file->f_dentry->d_sb->s_op->real_loop(file); | |
35196 | + return f; | |
35197 | +} | |
35198 | ||
35199 | /* | |
35200 | * loop_change_fd switched the backing store of a loopback device to | |
35201 | @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, | |
35202 | unsigned int arg) | |
35203 | { | |
35204 | struct file *file, *old_file; | |
35205 | + struct file *f, *virt_file = NULL, *old_virt_file; | |
35206 | struct inode *inode; | |
35207 | int error; | |
35208 | ||
35209 | @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, | |
35210 | file = fget(arg); | |
35211 | if (!file) | |
35212 | goto out; | |
35213 | + f = loop_real_file(file); | |
35214 | + if (f) { | |
35215 | + virt_file = file; | |
35216 | + file = f; | |
35217 | + get_file(file); | |
35218 | + } | |
35219 | ||
35220 | inode = file->f_mapping->host; | |
35221 | old_file = lo->lo_backing_file; | |
35222 | + old_virt_file = lo->lo_backing_virt_file; | |
35223 | ||
35224 | error = -EINVAL; | |
35225 | ||
35226 | @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, | |
35227 | goto out_putf; | |
35228 | ||
35229 | /* and ... switch */ | |
35230 | - error = loop_switch(lo, file); | |
35231 | + error = loop_switch(lo, file, virt_file); | |
35232 | if (error) | |
35233 | goto out_putf; | |
35234 | ||
35235 | fput(old_file); | |
35236 | + if (old_virt_file) | |
35237 | + fput(old_virt_file); | |
35238 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) | |
35239 | ioctl_by_bdev(bdev, BLKRRPART, 0); | |
35240 | return 0; | |
35241 | ||
35242 | out_putf: | |
35243 | fput(file); | |
35244 | + if (virt_file) | |
35245 | + fput(virt_file); | |
35246 | out: | |
35247 | return error; | |
35248 | } | |
35249 | @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo) | |
35250 | static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |
35251 | struct block_device *bdev, unsigned int arg) | |
35252 | { | |
35253 | - struct file *file, *f; | |
35254 | + struct file *file, *f, *virt_file = NULL; | |
35255 | struct inode *inode; | |
35256 | struct address_space *mapping; | |
35257 | unsigned lo_blocksize; | |
35258 | @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |
35259 | file = fget(arg); | |
35260 | if (!file) | |
35261 | goto out; | |
35262 | + f = loop_real_file(file); | |
35263 | + if (f) { | |
35264 | + virt_file = file; | |
35265 | + file = f; | |
35266 | + get_file(file); | |
35267 | + } | |
35268 | ||
35269 | error = -EBUSY; | |
35270 | if (lo->lo_state != Lo_unbound) | |
35271 | @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |
35272 | lo->lo_device = bdev; | |
35273 | lo->lo_flags = lo_flags; | |
35274 | lo->lo_backing_file = file; | |
35275 | + lo->lo_backing_virt_file = virt_file; | |
35276 | lo->transfer = transfer_none; | |
35277 | lo->ioctl = NULL; | |
35278 | lo->lo_sizelimit = 0; | |
35279 | @@ -948,6 +977,7 @@ out_clr: | |
35280 | lo->lo_thread = NULL; | |
35281 | lo->lo_device = NULL; | |
35282 | lo->lo_backing_file = NULL; | |
35283 | + lo->lo_backing_virt_file = NULL; | |
35284 | lo->lo_flags = 0; | |
35285 | set_capacity(lo->lo_disk, 0); | |
35286 | invalidate_bdev(bdev); | |
35287 | @@ -957,6 +987,8 @@ out_clr: | |
35288 | lo->lo_state = Lo_unbound; | |
35289 | out_putf: | |
35290 | fput(file); | |
35291 | + if (virt_file) | |
35292 | + fput(virt_file); | |
35293 | out: | |
35294 | /* This is safe: open() is still holding a reference. */ | |
35295 | module_put(THIS_MODULE); | |
35296 | @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, | |
35297 | static int loop_clr_fd(struct loop_device *lo) | |
35298 | { | |
35299 | struct file *filp = lo->lo_backing_file; | |
35300 | + struct file *virt_filp = lo->lo_backing_virt_file; | |
35301 | gfp_t gfp = lo->old_gfp_mask; | |
35302 | struct block_device *bdev = lo->lo_device; | |
35303 | ||
35304 | @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo) | |
35305 | ||
35306 | spin_lock_irq(&lo->lo_lock); | |
35307 | lo->lo_backing_file = NULL; | |
35308 | + lo->lo_backing_virt_file = NULL; | |
35309 | spin_unlock_irq(&lo->lo_lock); | |
35310 | ||
35311 | loop_release_xfer(lo); | |
35312 | @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo) | |
35313 | * bd_mutex which is usually taken before lo_ctl_mutex. | |
35314 | */ | |
35315 | fput(filp); | |
35316 | + if (virt_filp) | |
35317 | + fput(virt_filp); | |
35318 | return 0; | |
35319 | } | |
35320 | ||
35321 | diff --git a/drivers/block/loop.h b/drivers/block/loop.h | |
35322 | index 90df5d6..cb91822 100644 | |
35323 | --- a/drivers/block/loop.h | |
35324 | +++ b/drivers/block/loop.h | |
35325 | @@ -44,7 +44,7 @@ struct loop_device { | |
35326 | int (*ioctl)(struct loop_device *, int cmd, | |
35327 | unsigned long arg); | |
35328 | ||
35329 | - struct file * lo_backing_file; | |
35330 | + struct file * lo_backing_file, *lo_backing_virt_file; | |
35331 | struct block_device *lo_device; | |
35332 | unsigned lo_blocksize; | |
35333 | void *key_data; | |
35334 | diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c | |
c1595e42 | 35335 | index 3dd9138..63a424c 100644 |
93a1a2a2 JR |
35336 | --- a/fs/aufs/f_op.c |
35337 | +++ b/fs/aufs/f_op.c | |
076b876e | 35338 | @@ -367,7 +367,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, |
93a1a2a2 JR |
35339 | err = -EINVAL; |
35340 | h_file = au_hf_top(file); | |
35341 | get_file(h_file); | |
35342 | - if (au_test_loopback_kthread()) { | |
35343 | + if (0 && au_test_loopback_kthread()) { | |
35344 | au_warn_loopback(h_file->f_dentry->d_sb); | |
35345 | if (file->f_mapping != h_file->f_mapping) { | |
35346 | file->f_mapping = h_file->f_mapping; | |
35347 | diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c | |
35348 | index 3b03b52..4ab749d 100644 | |
35349 | --- a/fs/aufs/loop.c | |
35350 | +++ b/fs/aufs/loop.c | |
35351 | @@ -130,3 +130,19 @@ void au_loopback_fin(void) | |
35352 | symbol_put(loop_backing_file); | |
35353 | kfree(au_warn_loopback_array); | |
35354 | } | |
35355 | + | |
35356 | +/* ---------------------------------------------------------------------- */ | |
35357 | + | |
35358 | +/* support the loopback block device insude aufs */ | |
35359 | + | |
35360 | +struct file *aufs_real_loop(struct file *file) | |
35361 | +{ | |
35362 | + struct file *f; | |
35363 | + | |
35364 | + BUG_ON(!au_test_aufs(file->f_dentry->d_sb)); | |
35365 | + fi_read_lock(file); | |
35366 | + f = au_hf_top(file); | |
35367 | + fi_read_unlock(file); | |
35368 | + AuDebugOn(!f); | |
35369 | + return f; | |
35370 | +} | |
35371 | diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h | |
35372 | index da8b756..28cb7ea 100644 | |
35373 | --- a/fs/aufs/loop.h | |
35374 | +++ b/fs/aufs/loop.h | |
35375 | @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb); | |
35376 | ||
35377 | int au_loopback_init(void); | |
35378 | void au_loopback_fin(void); | |
35379 | + | |
35380 | +struct file *aufs_real_loop(struct file *file); | |
35381 | #else | |
35382 | +AuStub(struct file *, loop_backing_file, return NULL) | |
35383 | + | |
35384 | AuStubInt0(au_test_loopback_overlap, struct super_block *sb, | |
35385 | struct dentry *h_adding) | |
35386 | AuStubInt0(au_test_loopback_kthread, void) | |
35387 | @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb) | |
35388 | ||
35389 | AuStubInt0(au_loopback_init, void) | |
35390 | AuStubVoid(au_loopback_fin, void) | |
35391 | + | |
35392 | +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file) | |
35393 | #endif /* BLK_DEV_LOOP */ | |
35394 | ||
35395 | #endif /* __KERNEL__ */ | |
35396 | diff --git a/fs/aufs/super.c b/fs/aufs/super.c | |
c1595e42 | 35397 | index 2ec0b4f..65a6781 100644 |
93a1a2a2 JR |
35398 | --- a/fs/aufs/super.c |
35399 | +++ b/fs/aufs/super.c | |
c1595e42 | 35400 | @@ -812,7 +812,10 @@ static const struct super_operations aufs_sop = { |
93a1a2a2 JR |
35401 | .statfs = aufs_statfs, |
35402 | .put_super = aufs_put_super, | |
35403 | .sync_fs = aufs_sync_fs, | |
35404 | - .remount_fs = aufs_remount_fs | |
35405 | + .remount_fs = aufs_remount_fs, | |
35406 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
35407 | + .real_loop = aufs_real_loop | |
35408 | +#endif | |
35409 | }; | |
35410 | ||
35411 | /* ---------------------------------------------------------------------- */ | |
35412 | diff --git a/include/linux/fs.h b/include/linux/fs.h | |
c1595e42 | 35413 | index aabcbba..1a634f5 100644 |
93a1a2a2 JR |
35414 | --- a/include/linux/fs.h |
35415 | +++ b/include/linux/fs.h | |
c1595e42 | 35416 | @@ -1594,6 +1594,10 @@ struct super_operations { |
93a1a2a2 JR |
35417 | int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t); |
35418 | long (*nr_cached_objects)(struct super_block *, int); | |
35419 | long (*free_cached_objects)(struct super_block *, long, int); | |
35420 | +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE) | |
35421 | + /* and aufs */ | |
35422 | + struct file *(*real_loop)(struct file *); | |
35423 | +#endif | |
35424 | }; | |
35425 | ||
35426 | /* | |
c1595e42 JR |
35427 | diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h |
35428 | index 50777b5..f9c6b3d 100644 | |
35429 | --- a/include/linux/shmem_fs.h | |
35430 | +++ b/include/linux/shmem_fs.h | |
35431 | @@ -26,10 +26,13 @@ struct shmem_inode_info { | |
35432 | }; | |
35433 | ||
35434 | struct shmem_sb_info { | |
35435 | + struct mutex idr_lock; | |
35436 | + bool idr_nouse; | |
35437 | + struct idr idr; /* manages inode-number */ | |
35438 | unsigned long max_blocks; /* How many blocks are allowed */ | |
35439 | struct percpu_counter used_blocks; /* How many are allocated */ | |
35440 | - unsigned long max_inodes; /* How many inodes are allowed */ | |
35441 | - unsigned long free_inodes; /* How many are left for allocation */ | |
35442 | + int max_inodes; /* How many inodes are allowed */ | |
35443 | + int free_inodes; /* How many are left for allocation */ | |
35444 | spinlock_t stat_lock; /* Serialize shmem_sb_info changes */ | |
35445 | kuid_t uid; /* Mount uid for root directory */ | |
35446 | kgid_t gid; /* Mount gid for root directory */ | |
35447 | diff --git a/mm/shmem.c b/mm/shmem.c | |
35448 | index 185836b..ac7f9fb 100644 | |
35449 | --- a/mm/shmem.c | |
35450 | +++ b/mm/shmem.c | |
35451 | @@ -110,9 +110,13 @@ static unsigned long shmem_default_max_blocks(void) | |
35452 | return totalram_pages / 2; | |
35453 | } | |
35454 | ||
35455 | -static unsigned long shmem_default_max_inodes(void) | |
35456 | +static int shmem_default_max_inodes(void) | |
35457 | { | |
35458 | - return min(totalram_pages - totalhigh_pages, totalram_pages / 2); | |
35459 | + unsigned long ul; | |
35460 | + | |
35461 | + ul = INT_MAX; | |
35462 | + ul = min3(ul, totalram_pages - totalhigh_pages, totalram_pages / 2); | |
35463 | + return ul; | |
35464 | } | |
35465 | #endif | |
35466 | ||
35467 | @@ -592,6 +596,7 @@ static int shmem_setattr(struct dentry *dentry, struct iattr *attr) | |
35468 | static void shmem_evict_inode(struct inode *inode) | |
35469 | { | |
35470 | struct shmem_inode_info *info = SHMEM_I(inode); | |
35471 | + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); | |
35472 | ||
35473 | if (inode->i_mapping->a_ops == &shmem_aops) { | |
35474 | shmem_unacct_size(info->flags, inode->i_size); | |
35475 | @@ -607,6 +612,11 @@ static void shmem_evict_inode(struct inode *inode) | |
35476 | ||
35477 | simple_xattrs_free(&info->xattrs); | |
35478 | WARN_ON(inode->i_blocks); | |
35479 | + if (!sbinfo->idr_nouse && inode->i_ino) { | |
35480 | + mutex_lock(&sbinfo->idr_lock); | |
35481 | + idr_remove(&sbinfo->idr, inode->i_ino); | |
35482 | + mutex_unlock(&sbinfo->idr_lock); | |
35483 | + } | |
35484 | shmem_free_inode(inode->i_sb); | |
35485 | clear_inode(inode); | |
35486 | } | |
35487 | @@ -1406,13 +1416,13 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode | |
35488 | struct inode *inode; | |
35489 | struct shmem_inode_info *info; | |
35490 | struct shmem_sb_info *sbinfo = SHMEM_SB(sb); | |
35491 | + int ino; | |
35492 | ||
35493 | if (shmem_reserve_inode(sb)) | |
35494 | return NULL; | |
35495 | ||
35496 | inode = new_inode(sb); | |
35497 | if (inode) { | |
35498 | - inode->i_ino = get_next_ino(); | |
35499 | inode_init_owner(inode, dir, mode); | |
35500 | inode->i_blocks = 0; | |
35501 | inode->i_mapping->backing_dev_info = &shmem_backing_dev_info; | |
35502 | @@ -1454,6 +1464,25 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode | |
35503 | mpol_shared_policy_init(&info->policy, NULL); | |
35504 | break; | |
35505 | } | |
35506 | + | |
35507 | + if (!sbinfo->idr_nouse) { | |
35508 | + /* inum 0 and 1 are unused */ | |
35509 | + mutex_lock(&sbinfo->idr_lock); | |
35510 | + ino = idr_alloc(&sbinfo->idr, inode, 2, INT_MAX, | |
35511 | + GFP_NOFS); | |
35512 | + if (ino > 0) { | |
35513 | + inode->i_ino = ino; | |
35514 | + mutex_unlock(&sbinfo->idr_lock); | |
35515 | + __insert_inode_hash(inode, inode->i_ino); | |
35516 | + } else { | |
35517 | + inode->i_ino = 0; | |
35518 | + mutex_unlock(&sbinfo->idr_lock); | |
35519 | + iput(inode); | |
35520 | + /* shmem_free_inode() will be called */ | |
35521 | + inode = NULL; | |
35522 | + } | |
35523 | + } else | |
35524 | + inode->i_ino = get_next_ino(); | |
35525 | } else | |
35526 | shmem_free_inode(sb); | |
35527 | return inode; | |
35528 | @@ -2674,8 +2703,7 @@ static struct dentry *shmem_get_parent(struct dentry *child) | |
35529 | static int shmem_match(struct inode *ino, void *vfh) | |
35530 | { | |
35531 | __u32 *fh = vfh; | |
35532 | - __u64 inum = fh[2]; | |
35533 | - inum = (inum << 32) | fh[1]; | |
35534 | + __u64 inum = fh[1]; | |
35535 | return ino->i_ino == inum && fh[0] == ino->i_generation; | |
35536 | } | |
35537 | ||
35538 | @@ -2686,14 +2714,11 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb, | |
35539 | struct dentry *dentry = NULL; | |
35540 | u64 inum; | |
35541 | ||
35542 | - if (fh_len < 3) | |
35543 | + if (fh_len < 2) | |
35544 | return NULL; | |
35545 | ||
35546 | - inum = fid->raw[2]; | |
35547 | - inum = (inum << 32) | fid->raw[1]; | |
35548 | - | |
35549 | - inode = ilookup5(sb, (unsigned long)(inum + fid->raw[0]), | |
35550 | - shmem_match, fid->raw); | |
35551 | + inum = fid->raw[1]; | |
35552 | + inode = ilookup5(sb, inum, shmem_match, fid->raw); | |
35553 | if (inode) { | |
35554 | dentry = d_find_alias(inode); | |
35555 | iput(inode); | |
35556 | @@ -2705,30 +2730,15 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb, | |
35557 | static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len, | |
35558 | struct inode *parent) | |
35559 | { | |
35560 | - if (*len < 3) { | |
35561 | - *len = 3; | |
35562 | + if (*len < 2) { | |
35563 | + *len = 2; | |
35564 | return FILEID_INVALID; | |
35565 | } | |
35566 | ||
35567 | - if (inode_unhashed(inode)) { | |
35568 | - /* Unfortunately insert_inode_hash is not idempotent, | |
35569 | - * so as we hash inodes here rather than at creation | |
35570 | - * time, we need a lock to ensure we only try | |
35571 | - * to do it once | |
35572 | - */ | |
35573 | - static DEFINE_SPINLOCK(lock); | |
35574 | - spin_lock(&lock); | |
35575 | - if (inode_unhashed(inode)) | |
35576 | - __insert_inode_hash(inode, | |
35577 | - inode->i_ino + inode->i_generation); | |
35578 | - spin_unlock(&lock); | |
35579 | - } | |
35580 | - | |
35581 | fh[0] = inode->i_generation; | |
35582 | fh[1] = inode->i_ino; | |
35583 | - fh[2] = ((__u64)inode->i_ino) >> 32; | |
35584 | ||
35585 | - *len = 3; | |
35586 | + *len = 2; | |
35587 | return 1; | |
35588 | } | |
35589 | ||
35590 | @@ -2793,7 +2803,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, | |
35591 | goto bad_val; | |
35592 | } else if (!strcmp(this_char,"nr_inodes")) { | |
35593 | sbinfo->max_inodes = memparse(value, &rest); | |
35594 | - if (*rest) | |
35595 | + if (*rest || sbinfo->max_inodes < 2) | |
35596 | goto bad_val; | |
35597 | } else if (!strcmp(this_char,"mode")) { | |
35598 | if (remount) | |
35599 | @@ -2846,7 +2856,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data) | |
35600 | { | |
35601 | struct shmem_sb_info *sbinfo = SHMEM_SB(sb); | |
35602 | struct shmem_sb_info config = *sbinfo; | |
35603 | - unsigned long inodes; | |
35604 | + int inodes; | |
35605 | int error = -EINVAL; | |
35606 | ||
35607 | config.mpol = NULL; | |
35608 | @@ -2894,7 +2904,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) | |
35609 | seq_printf(seq, ",size=%luk", | |
35610 | sbinfo->max_blocks << (PAGE_CACHE_SHIFT - 10)); | |
35611 | if (sbinfo->max_inodes != shmem_default_max_inodes()) | |
35612 | - seq_printf(seq, ",nr_inodes=%lu", sbinfo->max_inodes); | |
35613 | + seq_printf(seq, ",nr_inodes=%d", sbinfo->max_inodes); | |
35614 | if (sbinfo->mode != (S_IRWXUGO | S_ISVTX)) | |
35615 | seq_printf(seq, ",mode=%03ho", sbinfo->mode); | |
35616 | if (!uid_eq(sbinfo->uid, GLOBAL_ROOT_UID)) | |
35617 | @@ -2983,6 +2993,8 @@ static void shmem_put_super(struct super_block *sb) | |
35618 | { | |
35619 | struct shmem_sb_info *sbinfo = SHMEM_SB(sb); | |
35620 | ||
35621 | + if (!sbinfo->idr_nouse) | |
35622 | + idr_destroy(&sbinfo->idr); | |
35623 | percpu_counter_destroy(&sbinfo->used_blocks); | |
35624 | mpol_put(sbinfo->mpol); | |
35625 | kfree(sbinfo); | |
35626 | @@ -3001,6 +3013,8 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent) | |
35627 | if (!sbinfo) | |
35628 | return -ENOMEM; | |
35629 | ||
35630 | + mutex_init(&sbinfo->idr_lock); | |
35631 | + idr_init(&sbinfo->idr); | |
35632 | sbinfo->mode = S_IRWXUGO | S_ISVTX; | |
35633 | sbinfo->uid = current_fsuid(); | |
35634 | sbinfo->gid = current_fsgid(); | |
35635 | @@ -3104,6 +3118,15 @@ static void shmem_destroy_inodecache(void) | |
35636 | kmem_cache_destroy(shmem_inode_cachep); | |
35637 | } | |
35638 | ||
35639 | +static __init void shmem_no_idr(struct super_block *sb) | |
35640 | +{ | |
35641 | + struct shmem_sb_info *sbinfo; | |
35642 | + | |
35643 | + sbinfo = SHMEM_SB(sb); | |
35644 | + sbinfo->idr_nouse = true; | |
35645 | + idr_destroy(&sbinfo->idr); | |
35646 | +} | |
35647 | + | |
35648 | static const struct address_space_operations shmem_aops = { | |
35649 | .writepage = shmem_writepage, | |
35650 | .set_page_dirty = __set_page_dirty_no_writeback, | |
35651 | @@ -3246,6 +3269,7 @@ int __init shmem_init(void) | |
35652 | printk(KERN_ERR "Could not kern_mount tmpfs\n"); | |
35653 | goto out1; | |
35654 | } | |
35655 | + shmem_no_idr(shm_mnt->mnt_sb); | |
35656 | return 0; | |
35657 | ||
35658 | out1: | |
35659 | diff --git a/fs/inode.c b/fs/inode.c | |
35660 | index 26753ba..61e0af2 100644 | |
35661 | --- a/fs/inode.c | |
35662 | +++ b/fs/inode.c | |
35663 | @@ -840,6 +840,8 @@ unsigned int get_next_ino(void) | |
35664 | unsigned int *p = &get_cpu_var(last_ino); | |
35665 | unsigned int res = *p; | |
35666 | ||
35667 | +start: | |
35668 | + | |
35669 | #ifdef CONFIG_SMP | |
35670 | if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) { | |
35671 | static atomic_t shared_last_ino; | |
35672 | @@ -849,7 +851,9 @@ unsigned int get_next_ino(void) | |
35673 | } | |
35674 | #endif | |
35675 | ||
35676 | - *p = ++res; | |
35677 | + if (unlikely(!++res)) | |
35678 | + goto start; /* never zero */ | |
35679 | + *p = res; | |
35680 | put_cpu_var(last_ino); | |
35681 | return res; | |
35682 | } |