~ubuntu-branches/ubuntu/vivid/aufs/vivid

« back to all changes in this revision

Viewing changes to fs/aufs/f_op.c

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2007-12-15 23:32:51 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071215233251-2vgs2lmg8mai5d9e
Tags: 0+20071211-1ubuntu1
* Merge from debian unstable (LP: #175705), remaining changes:
  - Fix for Ubuntu Kernels (updated)
* patches/01_vserver.dpatch: Removed
* patches/06_ubuntu.dpatch: Added (update of ubuntu patch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 */
18
18
 
19
 
/* $Id: f_op.c,v 1.28 2007/05/27 23:03:45 sfjro Exp $ */
 
19
/* $Id: f_op.c,v 1.41 2007/10/29 04:41:28 sfjro Exp $ */
20
20
 
21
21
#include <linux/fsnotify.h>
22
22
#include <linux/pagemap.h>
26
26
#include "aufs.h"
27
27
 
28
28
/* common function to regular file and dir */
29
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
30
 
#define FlushArgs       hidden_file, id
 
29
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
 
30
#define FlushArgs       h_file, id
31
31
int aufs_flush(struct file *file, fl_owner_t id)
32
32
#else
33
 
#define FlushArgs       hidden_file
 
33
#define FlushArgs       h_file
34
34
int aufs_flush(struct file *file)
35
35
#endif
36
36
{
39
39
        aufs_bindex_t bindex, bend;
40
40
 
41
41
        dentry = file->f_dentry;
42
 
        LKTRTrace("%.*s\n", DLNPair(dentry));
 
42
        LKTRTrace("%.*s\n", AuDLNPair(dentry));
43
43
 
44
44
        // aufs_read_lock_file()
45
 
        si_read_lock(dentry->d_sb);
 
45
        si_read_lock(dentry->d_sb, !AuLock_FLUSH);
46
46
        fi_read_lock(file);
47
 
        di_read_lock_child(dentry, !AUFS_I_RLOCK);
 
47
        di_read_lock_child(dentry, AuLock_IW);
48
48
 
49
49
        err = 0;
50
50
        bend = fbend(file);
51
51
        for (bindex = fbstart(file); !err && bindex <= bend; bindex++) {
52
 
                struct file *hidden_file;
53
 
                hidden_file = au_h_fptr_i(file, bindex);
54
 
                if (hidden_file && hidden_file->f_op
55
 
                    && hidden_file->f_op->flush)
56
 
                        err = hidden_file->f_op->flush(FlushArgs);
 
52
                struct file *h_file;
 
53
                h_file = au_h_fptr_i(file, bindex);
 
54
                if (h_file && h_file->f_op && h_file->f_op->flush) {
 
55
                        err = h_file->f_op->flush(FlushArgs);
 
56
                        if (!err)
 
57
                                au_update_fuse_h_inode
 
58
                                        (h_file->f_vfsmnt, h_file->f_dentry);
 
59
                        /*ignore*/
 
60
                }
57
61
        }
 
62
        au_cpup_attr_timesizes(dentry->d_inode);
58
63
 
59
 
        di_read_unlock(dentry, !AUFS_I_RLOCK);
 
64
        di_read_unlock(dentry, AuLock_IW);
60
65
        fi_read_unlock(file);
61
66
        si_read_unlock(dentry->d_sb);
62
 
        TraceErr(err);
 
67
        AuTraceErr(err);
63
68
        return err;
64
69
}
65
70
#undef FlushArgs
77
82
        struct aufs_finfo *finfo;
78
83
 
79
84
        dentry = file->f_dentry;
80
 
        LKTRTrace("%.*s, flags 0%o\n", DLNPair(dentry), flags);
 
85
        LKTRTrace("%.*s, flags 0%o\n", AuDLNPair(dentry), flags);
81
86
        FiMustWriteLock(file);
82
87
        inode = dentry->d_inode;
83
88
        AuDebugOn(!inode || S_ISDIR(inode->i_mode));
89
94
        bindex = dbstart(dentry);
90
95
        AuDebugOn(!au_h_dptr(dentry)->d_inode);
91
96
        /* O_TRUNC is processed already */
92
 
        BUG_ON(test_ro(sb, bindex, inode) && (flags & O_TRUNC));
 
97
        BUG_ON(au_test_ro(sb, bindex, inode) && (flags & O_TRUNC));
93
98
 
94
 
        hidden_file = hidden_open(dentry, bindex, flags);
 
99
        hidden_file = au_h_open(dentry, bindex, flags, file);
95
100
        //if (LktrCond) {fput(hidden_file); br_put(stobr(dentry->d_sb, bindex));
96
101
        //hidden_file = ERR_PTR(-1);}
97
102
        if (!IS_ERR(hidden_file)) {
98
103
                set_fbstart(file, bindex);
99
104
                set_fbend(file, bindex);
100
105
                set_h_fptr(file, bindex, hidden_file);
 
106
                //AuDbgFile(file);
101
107
                return 0; /* success */
102
108
        }
103
109
        err = PTR_ERR(hidden_file);
104
 
        TraceErr(err);
 
110
        AuTraceErr(err);
105
111
        return err;
106
112
}
107
113
 
114
120
{
115
121
        struct super_block *sb = file->f_dentry->d_sb;
116
122
 
117
 
        LKTRTrace("i%lu, %.*s\n", inode->i_ino, DLNPair(file->f_dentry));
 
123
        LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(file->f_dentry));
118
124
 
119
 
        si_read_lock(sb);
120
 
        au_fin_finfo(file);
 
125
        si_read_lock(sb, !AuLock_FLUSH);
 
126
        au_finfo_fin(file);
121
127
        si_read_unlock(sb);
122
128
        return 0;
123
129
}
132
138
        struct file *hidden_file;
133
139
        struct super_block *sb;
134
140
        struct inode *h_inode;
135
 
        int dlgt;
136
141
 
137
142
        dentry = file->f_dentry;
138
143
        LKTRTrace("%.*s, cnt %lu, pos %Ld\n",
139
 
                  DLNPair(dentry), (unsigned long)count, *ppos);
 
144
                  AuDLNPair(dentry), (unsigned long)count, *ppos);
 
145
        //AuDbgDentry(dentry);
140
146
 
141
147
        sb = dentry->d_sb;
142
 
        si_read_lock(sb);
 
148
        si_read_lock(sb, AuLock_FLUSH);
143
149
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
144
150
                                      /*locked*/0);
145
151
        //if (LktrCond) {fi_read_unlock(file); err = -1;}
147
153
                goto out;
148
154
 
149
155
        /* support LSM and notify */
150
 
        dlgt = need_dlgt(sb);
151
156
        hidden_file = au_h_fptr(file);
152
157
        h_inode = hidden_file->f_dentry->d_inode;
153
 
        if (!au_flag_test(sb, AuFlag_UDBA_INOTIFY))
154
 
                err = vfsub_read_u(hidden_file, buf, count, ppos, dlgt);
155
 
        else {
156
 
                struct dentry *parent = dget_parent(dentry),
157
 
                        *h_parent = dget_parent(hidden_file->f_dentry);
158
 
                struct inode *dir = parent->d_inode,
159
 
                        *h_dir = h_parent->d_inode;
160
 
                aufs_bindex_t bstart = fbstart(file);
161
 
                hdir_lock(h_dir, dir, bstart);
162
 
                err = vfsub_read_u(hidden_file, buf, count, ppos, dlgt);
163
 
                hdir_unlock(h_dir, dir, bstart);
164
 
                dput(parent);
165
 
                dput(h_parent);
166
 
        }
 
158
        err = vfsub_read_u(hidden_file, buf, count, ppos, au_need_dlgt(sb));
167
159
        memcpy(&file->f_ra, &hidden_file->f_ra, sizeof(file->f_ra)); //??
168
160
        dentry->d_inode->i_atime = hidden_file->f_dentry->d_inode->i_atime;
169
161
 
170
162
        fi_read_unlock(file);
171
163
 out:
172
164
        si_read_unlock(sb);
173
 
        TraceErr(err);
 
165
        AuTraceErr(err);
174
166
        return err;
175
167
}
176
168
 
178
170
                          size_t count, loff_t *ppos)
179
171
{
180
172
        ssize_t err;
181
 
        struct dentry *dentry;
182
 
        struct inode *inode;
 
173
        struct dentry *dentry, *parent;
 
174
        struct inode *inode, *dir;
183
175
        struct super_block *sb;
184
 
        struct file *hidden_file;
185
 
        char __user *buf = (char __user*)__buf;
 
176
        struct file *h_file;
 
177
        char __user *buf = (char __user *)__buf;
186
178
        struct inode *h_inode;
187
 
        int dlgt;
 
179
        struct aufs_hin_ignore ign;
 
180
        struct vfsub_args vargs;
188
181
 
189
182
        dentry = file->f_dentry;
190
183
        LKTRTrace("%.*s, cnt %lu, pos %Ld\n",
191
 
                  DLNPair(dentry), (unsigned long)count, *ppos);
 
184
                  AuDLNPair(dentry), (unsigned long)count, *ppos);
192
185
 
193
186
        inode = dentry->d_inode;
194
 
        i_lock(inode);
 
187
        vfsub_i_lock(inode);
195
188
        sb = dentry->d_sb;
196
 
        si_read_lock(sb);
 
189
        si_read_lock(sb, AuLock_FLUSH);
197
190
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/1,
198
191
                                      /*locked*/1);
199
192
        //if (LktrCond) {fi_write_unlock(file); err = -1;}
205
198
                goto out_unlock;
206
199
 
207
200
        /* support LSM and notify */
208
 
        dlgt = need_dlgt(sb);
209
 
        hidden_file = au_h_fptr(file);
210
 
        h_inode = hidden_file->f_dentry->d_inode;
211
 
        if (!au_flag_test(sb, AuFlag_UDBA_INOTIFY))
212
 
                err = vfsub_write_u(hidden_file, buf, count, ppos, dlgt);
 
201
        vfsub_args_init(&vargs, &ign, au_need_dlgt(sb), 0);
 
202
        h_file = au_h_fptr(file);
 
203
        h_inode = h_file->f_dentry->d_inode;
 
204
        if (!au_flag_test_udba_inotify(sb))
 
205
                err = vfsub_write_u(h_file, buf, count, ppos, &vargs);
213
206
        else {
214
 
                struct dentry *parent = dget_parent(dentry),
215
 
                        *h_parent = dget_parent(hidden_file->f_dentry);
216
 
                struct inode *dir = parent->d_inode,
217
 
                        *h_dir = h_parent->d_inode;
218
 
                aufs_bindex_t bstart = fbstart(file);
219
 
                hdir_lock(h_dir, dir, bstart);
220
 
                err = vfsub_write_u(hidden_file, buf, count, ppos, dlgt);
221
 
                hdir_unlock(h_dir, dir, bstart);
 
207
                parent = dget_parent(dentry);
 
208
                dir = parent->d_inode;
 
209
                ii_read_lock_parent(dir);
 
210
                vfsub_ign_hinode(&vargs, IN_MODIFY, itohi(dir, fbstart(file)));
 
211
                err = vfsub_write_u(h_file, buf, count, ppos, &vargs);
 
212
                ii_read_unlock(dir);
222
213
                dput(parent);
223
 
                dput(h_parent);
224
 
        }
225
 
        ii_write_lock_child(inode);
226
 
        au_cpup_attr_timesizes(inode);
227
 
        ii_write_unlock(inode);
228
 
 
229
 
 out_unlock:
230
 
        fi_write_unlock(file);
231
 
 out:
232
 
        si_read_unlock(sb);
233
 
        i_unlock(inode);
234
 
        TraceErr(err);
235
 
        return err;
236
 
}
 
214
        }
 
215
        ii_write_lock_child(inode);
 
216
        au_cpup_attr_timesizes(inode);
 
217
        ii_write_unlock(inode);
 
218
 
 
219
 out_unlock:
 
220
        fi_write_unlock(file);
 
221
 out:
 
222
        si_read_unlock(sb);
 
223
        vfsub_i_unlock(inode);
 
224
        AuTraceErr(err);
 
225
        return err;
 
226
}
 
227
 
 
228
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) \
 
229
        || defined(CONFIG_AUFS_SPLICE_PATCH)
 
230
static int au_test_loopback(void)
 
231
{
 
232
        const char c = current->comm[4];
 
233
        /* true if a kernel thread named 'loop[0-9].*' accesses a file */
 
234
        const int loopback = (current->mm == NULL
 
235
                              && '0' <= c && c <= '9'
 
236
                              && strncmp(current->comm, "loop", 4) == 0);
 
237
        return loopback;
 
238
}
 
239
#endif
 
240
 
 
241
#ifdef CONFIG_AUFS_SPLICE_PATCH
 
242
static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
 
243
                                struct pipe_inode_info *pipe, size_t len,
 
244
                                unsigned int flags)
 
245
{
 
246
        ssize_t err;
 
247
        struct file *h_file;
 
248
        struct dentry *dentry;
 
249
        struct super_block *sb;
 
250
 
 
251
        dentry = file->f_dentry;
 
252
        LKTRTrace("%.*s, pos %Ld, len %lu\n",
 
253
                  AuDLNPair(dentry), *ppos, (unsigned long)len);
 
254
 
 
255
        sb = dentry->d_sb;
 
256
        si_read_lock(sb, AuLock_FLUSH);
 
257
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
 
258
                                      /*locked*/0);
 
259
        if (unlikely(err))
 
260
                goto out;
 
261
 
 
262
        err = -EINVAL;
 
263
        /* support LSM and notify */
 
264
        h_file = au_h_fptr(file);
 
265
        if (/* unlikely */(au_test_loopback())) {
 
266
                file->f_mapping = h_file->f_mapping;
 
267
                smp_mb(); /* unnecessary? */
 
268
        }
 
269
        err = vfsub_splice_to(h_file, ppos, pipe, len, flags, au_need_dlgt(sb));
 
270
        memcpy(&file->f_ra, &h_file->f_ra, sizeof(file->f_ra)); //??
 
271
        dentry->d_inode->i_atime = h_file->f_dentry->d_inode->i_atime;
 
272
        fi_read_unlock(file);
 
273
 
 
274
 out:
 
275
        si_read_unlock(sb);
 
276
        AuTraceErr(err);
 
277
        return err;
 
278
}
 
279
 
 
280
static ssize_t
 
281
aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
 
282
                  size_t len, unsigned int flags)
 
283
{
 
284
        ssize_t err;
 
285
        struct dentry *dentry;
 
286
        struct inode *inode;
 
287
        struct super_block *sb;
 
288
        struct file *h_file;
 
289
        struct inode *h_inode;
 
290
        struct aufs_hin_ignore ign;
 
291
        struct vfsub_args vargs;
 
292
 
 
293
        dentry = file->f_dentry;
 
294
        LKTRTrace("%.*s, len %lu, pos %Ld\n",
 
295
                  AuDLNPair(dentry), (unsigned long)len, *ppos);
 
296
 
 
297
        inode = dentry->d_inode;
 
298
        vfsub_i_lock(inode);
 
299
        sb = dentry->d_sb;
 
300
        si_read_lock(sb, AuLock_FLUSH);
 
301
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/1,
 
302
                                      /*locked*/1);
 
303
        //if (LktrCond) {fi_write_unlock(file); err = -1;}
 
304
        if (unlikely(err))
 
305
                goto out;
 
306
        err = au_ready_to_write(file, -1);
 
307
        //if (LktrCond) err = -1;
 
308
        if (unlikely(err))
 
309
                goto out_unlock;
 
310
 
 
311
        /* support LSM and notify */
 
312
        vfsub_args_init(&vargs, &ign, au_need_dlgt(sb), 0);
 
313
        h_file = au_h_fptr(file);
 
314
        h_inode = h_file->f_dentry->d_inode;
 
315
        /* current do_splice_from() doesn't fire up the inotify event */
 
316
        if (1 || !au_flag_test_udba_inotify(sb))
 
317
                err = vfsub_splice_from(pipe, h_file, ppos, len, flags, &vargs);
 
318
        else {
 
319
                //struct dentry *parent = dget_parent(dentry);
 
320
                //vfsub_ign_hinode(&vargs, IN_MODIFY,
 
321
                //itohi(parent->d_inode, fbstart(file));
 
322
                err = vfsub_splice_from(pipe, h_file, ppos, len, flags, &vargs);
 
323
                //dput(parent);
 
324
        }
 
325
        ii_write_lock_child(inode);
 
326
        au_cpup_attr_timesizes(inode);
 
327
        ii_write_unlock(inode);
 
328
 
 
329
 out_unlock:
 
330
        fi_write_unlock(file);
 
331
 out:
 
332
        si_read_unlock(sb);
 
333
        vfsub_i_unlock(inode);
 
334
        AuTraceErr(err);
 
335
        return err;
 
336
}
 
337
#endif /* CONFIG_AUFS_SPLICE_PATCH */
237
338
 
238
339
/* ---------------------------------------------------------------------- */
239
340
 
240
 
#if 0 //def CONFIG_AUFS_ROBR
 
341
#ifdef CONFIG_AUFS_ROBR
241
342
struct lvma {
242
343
        struct list_head list;
243
344
        struct vm_area_struct *vma;
251
352
        struct aufs_sbinfo *sbinfo;
252
353
        int found, warn;
253
354
 
254
 
        TraceEnter();
255
 
        AuDebugOn(!SB_AUFS(sb));
 
355
        AuTraceEnter();
 
356
        AuDebugOn(!au_test_aufs(sb));
256
357
 
257
358
        warn = 0;
258
359
        found = 0;
277
378
        spin_unlock(&sbinfo->si_lvma_lock);
278
379
 
279
380
        if (unlikely(warn))
280
 
                Warn1("no memory for lvma\n");
 
381
                AuWarn1("no memory for lvma\n");
281
382
        return file;
282
383
}
283
384
 
287
388
        struct lvma *entry, *found;
288
389
        struct aufs_sbinfo *sbinfo;
289
390
 
290
 
        TraceEnter();
291
 
        AuDebugOn(!SB_AUFS(sb));
 
391
        AuTraceEnter();
 
392
        AuDebugOn(!au_test_aufs(sb));
292
393
 
293
394
        vma->vm_file = file;
294
395
 
296
397
        sbinfo = stosi(sb);
297
398
        spin_lock(&sbinfo->si_lvma_lock);
298
399
        list_for_each_entry(entry, &sbinfo->si_lvma, list)
299
 
                if (entry->vma == vma){
 
400
                if (entry->vma == vma) {
300
401
                        found = entry;
301
402
                        break;
302
403
                }
313
414
        struct file *file;
314
415
 
315
416
        file = vma->vm_file;
316
 
        if (file->private_data && au_is_aufs(file->f_dentry->d_sb))
 
417
        if (file->private_data && au_test_aufs(file->f_dentry->d_sb))
317
418
                return file;
318
419
        return NULL;
319
420
}
321
422
static void reset_file(struct vm_area_struct *vma, struct file *file)
322
423
{
323
424
        vma->vm_file = file;
324
 
        smp_mb();
 
425
        smp_mb(); /* flush vm_file */
325
426
}
326
427
#endif /* CONFIG_AUFS_ROBR */
327
428
 
 
429
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
 
430
static int aufs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 
431
{
 
432
        int err;
 
433
        struct dentry *dentry;
 
434
        struct file *file, *hidden_file;
 
435
        struct inode *inode;
 
436
        static DECLARE_WAIT_QUEUE_HEAD(wq);
 
437
        struct aufs_finfo *finfo;
 
438
 
 
439
        AuTraceEnter();
 
440
        AuDebugOn(!vma || !vma->vm_file);
 
441
        wait_event(wq, (file = safe_file(vma)));
 
442
        AuDebugOn(!au_test_aufs(file->f_dentry->d_sb));
 
443
        dentry = file->f_dentry;
 
444
        LKTRTrace("%.*s\n", AuDLNPair(dentry));
 
445
        inode = dentry->d_inode;
 
446
        AuDebugOn(!S_ISREG(inode->i_mode));
 
447
 
 
448
        /* do not revalidate, nor lock */
 
449
        finfo = ftofi(file);
 
450
        hidden_file = finfo->fi_hfile[0 + finfo->fi_bstart].hf_file;
 
451
        AuDebugOn(!hidden_file || !au_test_mmapped(file));
 
452
        vma->vm_file = hidden_file;
 
453
        //smp_mb();
 
454
#if 0 // debug
 
455
        AuDbg("fault %p, filemap_fault %p\n",
 
456
              finfo->fi_h_vm_ops->fault, filemap_fault);
 
457
#endif
 
458
        err = finfo->fi_h_vm_ops->fault(vma, vmf);
 
459
        reset_file(vma, file);
 
460
#if 0 //def CONFIG_SMP
 
461
        //wake_up_nr(&wq, online_cpu - 1);
 
462
        wake_up_all(&wq);
 
463
#else
 
464
        wake_up(&wq);
 
465
#endif
 
466
 
 
467
        if (!err) {
 
468
                //page->mapping = file->f_mapping;
 
469
                //get_page(page);
 
470
                //file->f_mapping = hidden_file->f_mapping;
 
471
                //touch_atime(NULL, dentry);
 
472
                //inode->i_atime = hidden_file->f_dentry->d_inode->i_atime;
 
473
        }
 
474
        AuTraceErr(err);
 
475
        //AuDbg("err %d\n", err);
 
476
        return err;
 
477
}
 
478
#else
328
479
static struct page *aufs_nopage(struct vm_area_struct *vma, unsigned long addr,
329
480
                                int *type)
330
481
{
335
486
        static DECLARE_WAIT_QUEUE_HEAD(wq);
336
487
        struct aufs_finfo *finfo;
337
488
 
338
 
        TraceEnter();
 
489
        AuTraceEnter();
339
490
        AuDebugOn(!vma || !vma->vm_file);
340
491
        wait_event(wq, (file = safe_file(vma)));
341
 
        AuDebugOn(!au_is_aufs(file->f_dentry->d_sb));
 
492
        AuDebugOn(!au_test_aufs(file->f_dentry->d_sb));
342
493
        dentry = file->f_dentry;
343
 
        LKTRTrace("%.*s, addr %lx\n", DLNPair(dentry), addr);
 
494
        LKTRTrace("%.*s, addr %lx\n", AuDLNPair(dentry), addr);
344
495
        inode = dentry->d_inode;
345
496
        AuDebugOn(!S_ISREG(inode->i_mode));
346
497
 
347
 
        // do not revalidate, nor lock
 
498
        /* do not revalidate, nor lock */
348
499
        finfo = ftofi(file);
349
500
        hidden_file = finfo->fi_hfile[0 + finfo->fi_bstart].hf_file;
350
 
        AuDebugOn(!hidden_file || !au_is_mmapped(file));
 
501
        AuDebugOn(!hidden_file || !au_test_mmapped(file));
351
502
        vma->vm_file = hidden_file;
352
503
        //smp_mb();
353
504
        page = finfo->fi_h_vm_ops->nopage(vma, addr, type);
365
516
                //touch_atime(NULL, dentry);
366
517
                //inode->i_atime = hidden_file->f_dentry->d_inode->i_atime;
367
518
        }
368
 
        TraceErrPtr(page);
 
519
        AuTraceErrPtr(page);
369
520
        return page;
370
521
}
371
522
 
373
524
                         unsigned long len, pgprot_t prot, unsigned long pgoff,
374
525
                         int nonblock)
375
526
{
376
 
        Err("please report me this application\n");
377
 
        BUG();
 
527
        AuUnsupport();
378
528
        return ftofi(vma->vm_file)->fi_h_vm_ops->populate
379
529
                (vma, addr, len, prot, pgoff, nonblock);
380
530
}
 
531
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) */
381
532
 
382
533
static struct vm_operations_struct aufs_vm_ops = {
383
534
        //.open         = aufs_vmaopen,
384
535
        //.close                = aufs_vmaclose,
 
536
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
 
537
        .fault          = aufs_fault,
 
538
#else
385
539
        .nopage         = aufs_nopage,
386
540
        .populate       = aufs_populate,
 
541
#endif
 
542
#if 0 // rfu
 
543
        unsigned long (*nopfn)(struct vm_area_struct *area,
 
544
                               unsigned long address);
387
545
        //page_mkwrite(struct vm_area_struct *vma, struct page *page)
 
546
#endif
388
547
};
389
548
 
390
549
/* ---------------------------------------------------------------------- */
400
559
 
401
560
        dentry = file->f_dentry;
402
561
        LKTRTrace("%.*s, %lx, len %lu\n",
403
 
                  DLNPair(dentry), vma->vm_start, vma->vm_end - vma->vm_start);
 
562
                  AuDLNPair(dentry), vma->vm_start,
 
563
                  vma->vm_end - vma->vm_start);
404
564
        AuDebugOn(!S_ISREG(dentry->d_inode->i_mode));
405
565
        AuDebugOn(down_write_trylock(&vma->vm_mm->mmap_sem));
406
566
 
407
 
        mmapped = au_is_mmapped(file);
 
567
        mmapped = au_test_mmapped(file);
408
568
        wlock = 0;
409
569
        if (file->f_mode & FMODE_WRITE) {
410
570
                flags = VM_SHARED | VM_WRITE;
412
572
        }
413
573
 
414
574
        sb = dentry->d_sb;
415
 
        si_read_lock(sb);
 
575
        si_read_lock(sb, AuLock_FLUSH);
416
576
        err = au_reval_and_lock_finfo(file, au_reopen_nondir,
417
577
                                      wlock | !mmapped, /*locked*/0);
418
578
        //err = -1;
429
589
        h_file = au_h_fptr(file);
430
590
        vm_ops = ftofi(file)->fi_h_vm_ops;
431
591
        if (unlikely(!mmapped)) {
432
 
                // nfs uses some locks
433
 
                lockdep_off();
434
 
                err = h_file->f_op->mmap(h_file, vma);
435
 
                lockdep_on();
 
592
                if (!au_test_nfs(h_file->f_vfsmnt->mnt_sb))
 
593
                        err = h_file->f_op->mmap(h_file, vma);
 
594
                else {
 
595
                        lockdep_off();
 
596
                        err = h_file->f_op->mmap(h_file, vma);
 
597
                        lockdep_on();
 
598
                }
436
599
                if (unlikely(err))
437
600
                        goto out_unlock;
438
601
                vm_ops = vma->vm_ops;
440
603
                err = do_munmap(current->mm, vma->vm_start,
441
604
                                vma->vm_end - vma->vm_start);
442
605
                if (unlikely(err)) {
443
 
                        IOErr("failed internal unmapping %.*s, %d\n",
444
 
                              DLNPair(h_file->f_dentry), err);
 
606
                        AuIOErr("failed internal unmapping %.*s, %d\n",
 
607
                                AuDLNPair(h_file->f_dentry), err);
445
608
                        err = -EIO;
446
609
                        goto out_unlock;
447
610
                }
451
614
        err = generic_file_mmap(file, vma);
452
615
        if (!err) {
453
616
                file_accessed(h_file);
 
617
                au_update_fuse_h_inode(h_file->f_vfsmnt, h_file->f_dentry);
 
618
                /*ignore*/
454
619
                dentry->d_inode->i_atime = h_file->f_dentry->d_inode->i_atime;
455
620
                vma->vm_ops = &aufs_vm_ops;
456
621
                if (unlikely(!mmapped))
464
629
                fi_write_unlock(file);
465
630
 out:
466
631
        si_read_unlock(sb);
467
 
        TraceErr(err);
 
632
        AuTraceErr(err);
468
633
        return err;
469
634
}
470
635
 
 
636
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22)
471
637
// todo: try do_sendfile() in fs/read_write.c
472
638
static ssize_t aufs_sendfile(struct file *file, loff_t *ppos,
473
639
                             size_t count, read_actor_t actor, void *target)
474
640
{
475
641
        ssize_t err;
476
642
        struct file *h_file;
477
 
        const char c = current->comm[4];
478
 
        /* true if a kernel thread named 'loop[0-9].*' accesses a file */
479
 
        const int loopback = (current->mm == NULL
480
 
                              && '0' <= c && c <= '9'
481
 
                              && strncmp(current->comm, "loop", 4) == 0);
482
643
        struct dentry *dentry;
483
644
        struct super_block *sb;
484
645
 
485
646
        dentry = file->f_dentry;
486
 
        LKTRTrace("%.*s, pos %Ld, cnt %lu, loopback %d\n",
487
 
                  DLNPair(dentry), *ppos, (unsigned long)count, loopback);
 
647
        LKTRTrace("%.*s, pos %Ld, cnt %lu\n",
 
648
                  AuDLNPair(dentry), *ppos, (unsigned long)count);
488
649
 
489
650
        sb = dentry->d_sb;
490
 
        si_read_lock(sb);
 
651
        si_read_lock(sb, AuLock_FLUSH);
491
652
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
492
653
                                      /*locked*/0);
493
654
        if (unlikely(err))
496
657
        err = -EINVAL;
497
658
        h_file = au_h_fptr(file);
498
659
        if (h_file->f_op && h_file->f_op->sendfile) {
499
 
                if (/* unlikely */(loopback)) {
 
660
                if (/* unlikely */(au_test_loopback())) {
500
661
                        file->f_mapping = h_file->f_mapping;
501
 
                        smp_mb(); //??
502
 
                }
503
 
                // nfs uses some locks
504
 
                lockdep_off();
505
 
                err = h_file->f_op->sendfile
506
 
                        (h_file, ppos, count, actor, target);
507
 
                lockdep_on();
 
662
                        smp_mb(); /* unnecessary? */
 
663
                }
 
664
                if (!au_test_nfs(h_file->f_vfsmnt->mnt_sb))
 
665
                        err = h_file->f_op->sendfile(h_file, ppos, count, actor,
 
666
                                                     target);
 
667
                else {
 
668
                        lockdep_off();
 
669
                        err = h_file->f_op->sendfile(h_file, ppos, count, actor,
 
670
                                                     target);
 
671
                        lockdep_on();
 
672
                }
 
673
                if (!err)
 
674
                        au_update_fuse_h_inode(h_file->f_vfsmnt,
 
675
                                               h_file->f_dentry);
 
676
                /*ignore*/
508
677
                dentry->d_inode->i_atime = h_file->f_dentry->d_inode->i_atime;
509
678
        }
510
679
        fi_read_unlock(file);
511
680
 
512
681
 out:
513
682
        si_read_unlock(sb);
514
 
        TraceErr(err);
 
683
        AuTraceErr(err);
515
684
        return err;
516
685
}
 
686
#endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22) */
517
687
 
518
688
/* ---------------------------------------------------------------------- */
519
689
 
529
699
        struct super_block *sb;
530
700
 
531
701
        dentry = file->f_dentry;
532
 
        LKTRTrace("%.*s, wait %p\n", DLNPair(dentry), wait);
 
702
        LKTRTrace("%.*s, wait %p\n", AuDLNPair(dentry), wait);
533
703
        AuDebugOn(S_ISDIR(dentry->d_inode->i_mode));
534
704
 
535
705
        /* We should pretend an error happend. */
536
706
        mask = POLLERR /* | POLLIN | POLLOUT */;
537
707
        sb = dentry->d_sb;
538
 
        si_read_lock(sb);
 
708
        si_read_lock(sb, !AuLock_FLUSH);
539
709
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
540
710
                                      /*locked*/0);
541
711
        //err = -1;
551
721
 
552
722
 out:
553
723
        si_read_unlock(sb);
554
 
        TraceErr((int)mask);
 
724
        AuTraceErr((int)mask);
555
725
        return mask;
556
726
}
557
727
 
560
730
{
561
731
        int err, my_lock;
562
732
        struct inode *inode;
563
 
        struct file *hidden_file;
 
733
        struct file *h_file;
564
734
        struct super_block *sb;
565
735
 
566
 
        LKTRTrace("%.*s, %d\n", DLNPair(dentry), datasync);
 
736
        LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), datasync);
567
737
        inode = dentry->d_inode;
568
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
 
738
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
569
739
        IMustLock(inode);
570
740
        my_lock = 0;
571
741
#else
572
742
        /* before 2.6.17,
573
743
         * msync(2) calls me without locking i_sem/i_mutex, but fsync(2).
574
744
         */
575
 
        my_lock = !i_trylock(inode);
 
745
        my_lock = !vfsub_i_trylock(inode);
576
746
#endif
577
747
 
578
748
        sb = dentry->d_sb;
579
 
        si_read_lock(sb);
 
749
        si_read_lock(sb, !AuLock_FLUSH);
580
750
        err = 0; //-EBADF; // posix?
581
751
        if (unlikely(!(file->f_mode & FMODE_WRITE)))
582
752
                goto out;
591
761
                goto out_unlock;
592
762
 
593
763
        err = -EINVAL;
594
 
        hidden_file = au_h_fptr(file);
595
 
        if (hidden_file->f_op && hidden_file->f_op->fsync) {
 
764
        h_file = au_h_fptr(file);
 
765
        if (h_file->f_op && h_file->f_op->fsync) {
596
766
                // todo: apparmor thread?
597
767
                //file->f_mapping->host->i_mutex
598
768
                ii_write_lock_child(inode);
599
 
                hi_lock_child(hidden_file->f_dentry->d_inode);
600
 
                err = hidden_file->f_op->fsync
601
 
                        (hidden_file, hidden_file->f_dentry, datasync);
 
769
                vfsub_i_lock_nested(h_file->f_dentry->d_inode, AuLsc_I_CHILD);
 
770
                err = h_file->f_op->fsync(h_file, h_file->f_dentry, datasync);
602
771
                //err = -1;
 
772
                if (!err)
 
773
                        au_update_fuse_h_inode(h_file->f_vfsmnt,
 
774
                                               h_file->f_dentry);
603
775
                au_cpup_attr_timesizes(inode);
604
 
                i_unlock(hidden_file->f_dentry->d_inode);
 
776
                vfsub_i_unlock(h_file->f_dentry->d_inode);
605
777
                ii_write_unlock(inode);
606
778
        }
607
779
 
609
781
        fi_write_unlock(file);
610
782
 out:
611
783
        if (unlikely(my_lock))
612
 
                i_unlock(inode);
 
784
                vfsub_i_unlock(inode);
613
785
        si_read_unlock(sb);
614
 
        TraceErr(err);
 
786
        AuTraceErr(err);
615
787
        return err;
616
788
}
617
789
 
623
795
        struct super_block *sb;
624
796
 
625
797
        dentry = file->f_dentry;
626
 
        LKTRTrace("%.*s, %d\n", DLNPair(dentry), flag);
 
798
        LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), flag);
627
799
 
628
800
        sb = dentry->d_sb;
629
 
        si_read_lock(sb);
 
801
        si_read_lock(sb, !AuLock_FLUSH);
630
802
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
631
803
                                      /*locked*/0);
632
804
        //err = -1;
640
812
 
641
813
 out:
642
814
        si_read_unlock(sb);
643
 
        TraceErr(err);
 
815
        AuTraceErr(err);
644
816
        return err;
645
817
}
646
818
 
647
819
/* ---------------------------------------------------------------------- */
648
820
 
649
 
#if 0 // comment
650
 
struct file_operations {
651
 
        struct module *owner;
652
 
        loff_t (*llseek) (struct file *, loff_t, int);
653
 
        ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
654
 
        ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t);
655
 
        ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
656
 
        ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t);
657
 
        int (*readdir) (struct file *, void *, filldir_t);
658
 
        unsigned int (*poll) (struct file *, struct poll_table_struct *);
659
 
        int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
660
 
        long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
661
 
        long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
662
 
        int (*mmap) (struct file *, struct vm_area_struct *);
663
 
        int (*open) (struct inode *, struct file *);
664
 
        int (*flush) (struct file *);
665
 
        int (*release) (struct inode *, struct file *);
666
 
        int (*fsync) (struct file *, struct dentry *, int datasync);
667
 
        int (*aio_fsync) (struct kiocb *, int datasync);
668
 
        int (*fasync) (int, struct file *, int);
669
 
        int (*lock) (struct file *, int, struct file_lock *);
670
 
        ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
671
 
        ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
672
 
        ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *);
673
 
        ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
674
 
        unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
675
 
        int (*check_flags)(int);
676
 
        int (*dir_notify)(struct file *file, unsigned long arg);
677
 
        int (*flock) (struct file *, int, struct file_lock *);
678
 
};
679
 
#endif
680
 
 
681
821
struct file_operations aufs_file_fop = {
682
822
        .read           = aufs_read,
683
823
        .write          = aufs_write,
688
828
        .release        = aufs_release_nondir,
689
829
        .fsync          = aufs_fsync_nondir,
690
830
        .fasync         = aufs_fasync,
 
831
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22)
691
832
        .sendfile       = aufs_sendfile,
 
833
#endif
 
834
#ifdef CONFIG_AUFS_SPLICE_PATCH
 
835
        .splice_write   = aufs_splice_write,
 
836
        .splice_read    = aufs_splice_read,
 
837
#endif
692
838
};