wok view linux/stuff/aufs3-mmap.patch @ rev 15743

linux: update modules.list
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jan 02 15:04:05 2014 +0100 (2014-01-02)
parents f4df390821bc
children
line source
1 aufs3.2 mmap patch
3 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
4 index b1822dd..d8518aa 100644
5 --- a/fs/proc/nommu.c
6 +++ b/fs/proc/nommu.c
7 @@ -45,7 +45,9 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
8 file = region->vm_file;
10 if (file) {
11 - struct inode *inode = region->vm_file->f_path.dentry->d_inode;
12 + struct inode *inode;
13 + file = vmr_pr_or_file(region);
14 + inode = file->f_path.dentry->d_inode;
15 dev = inode->i_sb->s_dev;
16 ino = inode->i_ino;
17 }
18 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
19 index e418c5a..06bbf80 100644
20 --- a/fs/proc/task_mmu.c
21 +++ b/fs/proc/task_mmu.c
22 @@ -221,7 +221,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
23 int len;
25 if (file) {
26 - struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
27 + struct inode *inode;
28 + file = vma_pr_or_file(vma);
29 + inode = file->f_path.dentry->d_inode;
30 dev = inode->i_sb->s_dev;
31 ino = inode->i_ino;
32 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
33 @@ -1044,6 +1046,7 @@ static int show_numa_map(struct seq_file *m, void *v)
34 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
36 if (file) {
37 + file = vma_pr_or_file(vma);
38 seq_printf(m, " file=");
39 seq_path(m, &file->f_path, "\n\t= ");
40 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
41 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
42 index 980de54..b59aa1e 100644
43 --- a/fs/proc/task_nommu.c
44 +++ b/fs/proc/task_nommu.c
45 @@ -147,7 +147,9 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
46 file = vma->vm_file;
48 if (file) {
49 - struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
50 + struct inode *inode;
51 + file = vma_pr_or_file(file);
52 + inode = file->f_path.dentry->d_inode;
53 dev = inode->i_sb->s_dev;
54 ino = inode->i_ino;
55 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
56 diff --git a/include/linux/mm.h b/include/linux/mm.h
57 index 4baadd1..b1ee63e 100644
58 --- a/include/linux/mm.h
59 +++ b/include/linux/mm.h
60 @@ -17,6 +17,9 @@
61 #include <linux/pfn.h>
62 #include <linux/bit_spinlock.h>
63 #include <linux/shrinker.h>
64 +#include <linux/dcache.h>
65 +#include <linux/file.h>
66 +#include <linux/fs.h>
68 struct mempolicy;
69 struct anon_vma;
70 @@ -984,6 +987,87 @@ static inline int fixup_user_fault(struct task_struct *tsk,
71 }
72 #endif
74 +/*
75 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
76 + * in /proc/PID/maps.
77 + */
78 +/* #define AUFS_DEBUG_MMAP */
79 +static inline void aufs_trace(struct file *f, struct file *pr,
80 + const char func[], int line, const char func2[])
81 +{
82 +#ifdef AUFS_DEBUG_MMAP
83 + if (pr)
84 + pr_info("%s:%d: %s, %p\n", func, line, func2,
85 + f ? (char *)f->f_dentry->d_name.name : "(null)");
86 +#endif
87 +}
88 +
89 +static inline struct file *vmr_do_pr_or_file(struct vm_region *region,
90 + const char func[], int line)
91 +{
92 + struct file *f = region->vm_file, *pr = region->vm_prfile;
93 + aufs_trace(f, pr, func, line, __func__);
94 + return (f && pr) ? pr : f;
95 +}
96 +
97 +static inline void vmr_do_fput(struct vm_region *region,
98 + const char func[], int line)
99 +{
100 + struct file *f = region->vm_file, *pr = region->vm_prfile;
101 + aufs_trace(f, pr, func, line, __func__);
102 + fput(f);
103 + if (f && pr)
104 + fput(pr);
105 +}
106 +
107 +static inline void vma_do_file_update_time(struct vm_area_struct *vma,
108 + const char func[], int line)
109 +{
110 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
111 + aufs_trace(f, pr, func, line, __func__);
112 + file_update_time(f);
113 + if (f && pr)
114 + file_update_time(pr);
115 +}
116 +
117 +static inline struct file *vma_do_pr_or_file(struct vm_area_struct *vma,
118 + const char func[], int line)
119 +{
120 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
121 + aufs_trace(f, pr, func, line, __func__);
122 + return (f && pr) ? pr : f;
123 +}
124 +
125 +static inline void vma_do_get_file(struct vm_area_struct *vma,
126 + const char func[], int line)
127 +{
128 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
129 + aufs_trace(f, pr, func, line, __func__);
130 + get_file(f);
131 + if (f && pr)
132 + get_file(pr);
133 +}
134 +
135 +static inline void vma_do_fput(struct vm_area_struct *vma,
136 + const char func[], int line)
137 +{
138 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
139 + aufs_trace(f, pr, func, line, __func__);
140 + fput(f);
141 + if (f && pr)
142 + fput(pr);
143 +}
144 +
145 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
146 + __LINE__)
147 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
148 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
149 + __LINE__)
150 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
151 + __LINE__)
152 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
153 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
154 +
155 extern int make_pages_present(unsigned long addr, unsigned long end);
156 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
157 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
158 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
159 index 5b42f1b..a49a07e 100644
160 --- a/include/linux/mm_types.h
161 +++ b/include/linux/mm_types.h
162 @@ -186,6 +186,7 @@ struct vm_region {
163 unsigned long vm_top; /* region allocated to here */
164 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
165 struct file *vm_file; /* the backing file or NULL */
166 + struct file *vm_prfile; /* the virtual backing file or NULL */
168 int vm_usage; /* region usage count (access under nommu_region_sem) */
169 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
170 @@ -245,6 +246,7 @@ struct vm_area_struct {
171 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
172 units, *not* PAGE_CACHE_SIZE */
173 struct file * vm_file; /* File we map to (can be NULL). */
174 + struct file *vm_prfile; /* shadow of vm_file */
175 void * vm_private_data; /* was vm_pte (shared mem) */
177 #ifndef CONFIG_MMU
178 diff --git a/kernel/fork.c b/kernel/fork.c
179 index da4a6a1..4a31675 100644
180 --- a/kernel/fork.c
181 +++ b/kernel/fork.c
182 @@ -378,7 +378,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
183 struct inode *inode = file->f_path.dentry->d_inode;
184 struct address_space *mapping = file->f_mapping;
186 - get_file(file);
187 + vma_get_file(tmp);
188 if (tmp->vm_flags & VM_DENYWRITE)
189 atomic_dec(&inode->i_writecount);
190 mutex_lock(&mapping->i_mmap_mutex);
191 diff --git a/mm/fremap.c b/mm/fremap.c
192 index 9ed4fd4..00ee66b 100644
193 --- a/mm/fremap.c
194 +++ b/mm/fremap.c
195 @@ -198,10 +198,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
196 struct file *file = vma->vm_file;
198 flags &= MAP_NONBLOCK;
199 - get_file(file);
200 + vma_get_file(vma);
201 addr = mmap_region(file, start, size,
202 flags, vma->vm_flags, pgoff);
203 - fput(file);
204 + vma_fput(vma);
205 if (IS_ERR_VALUE(addr)) {
206 err = addr;
207 } else {
208 diff --git a/mm/memory.c b/mm/memory.c
209 index 829d437..6c6f9f1 100644
210 --- a/mm/memory.c
211 +++ b/mm/memory.c
212 @@ -2684,7 +2684,7 @@ reuse:
214 /* file_update_time outside page_lock */
215 if (vma->vm_file)
216 - file_update_time(vma->vm_file);
217 + vma_file_update_time(vma);
219 return ret;
220 }
221 @@ -3369,7 +3369,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
223 /* file_update_time outside page_lock */
224 if (vma->vm_file)
225 - file_update_time(vma->vm_file);
226 + vma_file_update_time(vma);
227 } else {
228 unlock_page(vmf.page);
229 if (anon)
230 diff --git a/mm/mmap.c b/mm/mmap.c
231 index eae90af..570ac61 100644
232 --- a/mm/mmap.c
233 +++ b/mm/mmap.c
234 @@ -231,7 +231,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
235 if (vma->vm_ops && vma->vm_ops->close)
236 vma->vm_ops->close(vma);
237 if (vma->vm_file) {
238 - fput(vma->vm_file);
239 + vma_fput(vma);
240 if (vma->vm_flags & VM_EXECUTABLE)
241 removed_exe_file_vma(vma->vm_mm);
242 }
243 @@ -618,7 +618,7 @@ again: remove_next = 1 + (end > next->vm_end);
245 if (remove_next) {
246 if (file) {
247 - fput(file);
248 + vma_fput(vma);
249 if (next->vm_flags & VM_EXECUTABLE)
250 removed_exe_file_vma(mm);
251 }
252 @@ -1334,8 +1334,8 @@ out:
253 unmap_and_free_vma:
254 if (correct_wcount)
255 atomic_inc(&inode->i_writecount);
256 + vma_fput(vma);
257 vma->vm_file = NULL;
258 - fput(file);
260 /* Undo any partial mapping done by a device driver. */
261 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
262 @@ -1964,7 +1964,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
263 goto out_free_mpol;
265 if (new->vm_file) {
266 - get_file(new->vm_file);
267 + vma_get_file(new);
268 if (vma->vm_flags & VM_EXECUTABLE)
269 added_exe_file_vma(mm);
270 }
271 @@ -1988,7 +1988,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
272 if (new->vm_file) {
273 if (vma->vm_flags & VM_EXECUTABLE)
274 removed_exe_file_vma(mm);
275 - fput(new->vm_file);
276 + vma_fput(new);
277 }
278 unlink_anon_vmas(new);
279 out_free_mpol:
280 @@ -2355,7 +2355,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
281 new_vma->vm_end = addr + len;
282 new_vma->vm_pgoff = pgoff;
283 if (new_vma->vm_file) {
284 - get_file(new_vma->vm_file);
285 + vma_get_file(new_vma);
286 if (vma->vm_flags & VM_EXECUTABLE)
287 added_exe_file_vma(mm);
288 }
289 diff --git a/mm/msync.c b/mm/msync.c
290 index 632df45..02d770e 100644
291 --- a/mm/msync.c
292 +++ b/mm/msync.c
293 @@ -80,10 +80,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
294 start = vma->vm_end;
295 if ((flags & MS_SYNC) && file &&
296 (vma->vm_flags & VM_SHARED)) {
297 - get_file(file);
298 + vma_get_file(vma);
299 up_read(&mm->mmap_sem);
300 error = vfs_fsync(file, 0);
301 - fput(file);
302 + vma_fput(vma);
303 if (error || start >= end)
304 goto out;
305 down_read(&mm->mmap_sem);
306 diff --git a/mm/nommu.c b/mm/nommu.c
307 index b982290..6eb4f31 100644
308 --- a/mm/nommu.c
309 +++ b/mm/nommu.c
310 @@ -632,7 +632,7 @@ static void __put_nommu_region(struct vm_region *region)
311 up_write(&nommu_region_sem);
313 if (region->vm_file)
314 - fput(region->vm_file);
315 + vmr_fput(region);
317 /* IO memory and memory shared directly out of the pagecache
318 * from ramfs/tmpfs mustn't be released here */
319 @@ -790,7 +790,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
320 if (vma->vm_ops && vma->vm_ops->close)
321 vma->vm_ops->close(vma);
322 if (vma->vm_file) {
323 - fput(vma->vm_file);
324 + vma_fput(vma);
325 if (vma->vm_flags & VM_EXECUTABLE)
326 removed_exe_file_vma(mm);
327 }
328 @@ -1363,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file,
329 goto error_just_free;
330 }
331 }
332 - fput(region->vm_file);
333 + vmr_fput(region);
334 kmem_cache_free(vm_region_jar, region);
335 region = pregion;
336 result = start;
337 @@ -1439,10 +1439,10 @@ error_just_free:
338 up_write(&nommu_region_sem);
339 error:
340 if (region->vm_file)
341 - fput(region->vm_file);
342 + vmr_fput(region);
343 kmem_cache_free(vm_region_jar, region);
344 if (vma->vm_file)
345 - fput(vma->vm_file);
346 + vma_fput(vma);
347 if (vma->vm_flags & VM_EXECUTABLE)
348 removed_exe_file_vma(vma->vm_mm);
349 kmem_cache_free(vm_area_cachep, vma);