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

« back to all changes in this revision

Viewing changes to fs/aufs25/f_op.c

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2008-05-06 18:35:50 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080506183550-0b6c974kkgc46oeh
Tags: 0+20080506-1
* New upstream release, supports Kernel 2.6.25 (Closes: #479717)
* Fix building with older Kernels (Closes: #475042)
* Update the patches 01, 04 and 07 to also patch fs/aufs25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2008 Junjiro Okajima
 
3
 *
 
4
 * This program, aufs is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 */
 
18
 
 
19
/*
 
20
 * file and vm operations
 
21
 *
 
22
 * $Id: f_op.c,v 1.3 2008/04/28 03:04:12 sfjro Exp $
 
23
 */
 
24
 
 
25
//#include <linux/fsnotify.h>
 
26
#include <linux/fs_stack.h>
 
27
//#include <linux/pagemap.h>
 
28
#include <linux/poll.h>
 
29
//#include <linux/security.h>
 
30
#include "aufs.h"
 
31
 
 
32
/* common function to regular file and dir */
 
33
int aufs_flush(struct file *file, fl_owner_t id)
 
34
{
 
35
        int err;
 
36
        struct dentry *dentry;
 
37
        aufs_bindex_t bindex, bend;
 
38
 
 
39
        dentry = file->f_dentry;
 
40
        LKTRTrace("%.*s\n", AuDLNPair(dentry));
 
41
 
 
42
        // aufs_read_lock_file()
 
43
        si_read_lock(dentry->d_sb, !AuLock_FLUSH);
 
44
        fi_read_lock(file);
 
45
        di_read_lock_child(dentry, AuLock_IW);
 
46
 
 
47
        err = 0;
 
48
        bend = au_fbend(file);
 
49
        for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
 
50
                struct file *h_file;
 
51
                h_file = au_h_fptr(file, bindex);
 
52
                if (h_file && h_file->f_op && h_file->f_op->flush) {
 
53
                        err = h_file->f_op->flush(h_file, id);
 
54
                        if (!err)
 
55
                                au_update_fuse_h_inode
 
56
                                        (h_file->f_vfsmnt, h_file->f_dentry);
 
57
                        /*ignore*/
 
58
                }
 
59
        }
 
60
        au_cpup_attr_timesizes(dentry->d_inode);
 
61
 
 
62
        di_read_unlock(dentry, AuLock_IW);
 
63
        fi_read_unlock(file);
 
64
        si_read_unlock(dentry->d_sb);
 
65
        AuTraceErr(err);
 
66
        return err;
 
67
}
 
68
 
 
69
/* ---------------------------------------------------------------------- */
 
70
 
 
71
static int do_open_nondir(struct file *file, int flags)
 
72
{
 
73
        int err;
 
74
        aufs_bindex_t bindex;
 
75
        struct super_block *sb;
 
76
        struct file *h_file;
 
77
        struct dentry *dentry;
 
78
        struct inode *inode;
 
79
        struct au_finfo *finfo;
 
80
 
 
81
        dentry = file->f_dentry;
 
82
        LKTRTrace("%.*s, flags 0%o\n", AuDLNPair(dentry), flags);
 
83
        FiMustWriteLock(file);
 
84
        inode = dentry->d_inode;
 
85
        AuDebugOn(!inode || S_ISDIR(inode->i_mode));
 
86
 
 
87
        err = 0;
 
88
        finfo = au_fi(file);
 
89
        finfo->fi_h_vm_ops = NULL;
 
90
        sb = dentry->d_sb;
 
91
        bindex = au_dbstart(dentry);
 
92
        AuDebugOn(!au_h_dptr(dentry, bindex)->d_inode);
 
93
        /* O_TRUNC is processed already */
 
94
        BUG_ON(au_test_ro(sb, bindex, inode) && (flags & O_TRUNC));
 
95
 
 
96
        h_file = au_h_open(dentry, bindex, flags, file);
 
97
        //if (LktrCond) {fput(h_file); au_br_put(au_sbr(dentry->d_sb, bindex));
 
98
        //h_file = ERR_PTR(-1);}
 
99
        if (!IS_ERR(h_file)) {
 
100
                au_set_fbstart(file, bindex);
 
101
                au_set_fbend(file, bindex);
 
102
                au_set_h_fptr(file, bindex, h_file);
 
103
                au_update_figen(file);
 
104
                //file->f_ra = h_file->f_ra; //??
 
105
                //AuDbgFile(file);
 
106
                return 0; /* success */
 
107
        }
 
108
        err = PTR_ERR(h_file);
 
109
        AuTraceErr(err);
 
110
        return err;
 
111
}
 
112
 
 
113
static int aufs_open_nondir(struct inode *inode, struct file *file)
 
114
{
 
115
        return au_do_open(inode, file, do_open_nondir);
 
116
}
 
117
 
 
118
static int aufs_release_nondir(struct inode *inode, struct file *file)
 
119
{
 
120
        struct super_block *sb = file->f_dentry->d_sb;
 
121
 
 
122
        LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(file->f_dentry));
 
123
 
 
124
        si_read_lock(sb, !AuLock_FLUSH);
 
125
        au_finfo_fin(file);
 
126
        si_read_unlock(sb);
 
127
        return 0;
 
128
}
 
129
 
 
130
/* ---------------------------------------------------------------------- */
 
131
 
 
132
static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
 
133
                         loff_t *ppos)
 
134
{
 
135
        ssize_t err;
 
136
        struct dentry *dentry;
 
137
        struct file *h_file;
 
138
        struct super_block *sb;
 
139
        struct inode *h_inode;
 
140
 
 
141
        dentry = file->f_dentry;
 
142
        LKTRTrace("%.*s, cnt %lu, pos %Ld\n",
 
143
                  AuDLNPair(dentry), (unsigned long)count, *ppos);
 
144
        //AuDbgDentry(dentry);
 
145
 
 
146
        sb = dentry->d_sb;
 
147
        si_read_lock(sb, AuLock_FLUSH);
 
148
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
 
149
                                      /*locked*/0);
 
150
        //if (LktrCond) {fi_read_unlock(file); err = -1;}
 
151
        if (unlikely(err))
 
152
                goto out;
 
153
 
 
154
        /* support LSM and notify */
 
155
        h_file = au_h_fptr(file, au_fbstart(file));
 
156
        h_inode = h_file->f_dentry->d_inode;
 
157
        err = vfsub_read_u(h_file, buf, count, ppos,
 
158
                           au_opt_test_dlgt(au_mntflags(sb)));
 
159
        //file->f_ra = h_file->f_ra; //??
 
160
        fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
 
161
 
 
162
        fi_read_unlock(file);
 
163
 out:
 
164
        si_read_unlock(sb);
 
165
        AuTraceErr(err);
 
166
        return err;
 
167
}
 
168
 
 
169
static ssize_t aufs_write(struct file *file, const char __user *ubuf,
 
170
                          size_t count, loff_t *ppos)
 
171
{
 
172
        ssize_t err;
 
173
        struct dentry *dentry, *parent;
 
174
        struct inode *inode, *dir;
 
175
        struct super_block *sb;
 
176
        unsigned int mnt_flags;
 
177
        struct file *h_file;
 
178
        char __user *buf = (char __user *)ubuf;
 
179
        struct au_hin_ignore ign;
 
180
        struct vfsub_args vargs;
 
181
 
 
182
        dentry = file->f_dentry;
 
183
        LKTRTrace("%.*s, cnt %lu, pos %Ld\n",
 
184
                  AuDLNPair(dentry), (unsigned long)count, *ppos);
 
185
 
 
186
        inode = dentry->d_inode;
 
187
        mutex_lock(&inode->i_mutex);
 
188
        sb = dentry->d_sb;
 
189
        si_read_lock(sb, AuLock_FLUSH);
 
190
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/1,
 
191
                                      /*locked*/1);
 
192
        //if (LktrCond) {fi_write_unlock(file); err = -1;}
 
193
        if (unlikely(err))
 
194
                goto out;
 
195
        err = au_ready_to_write(file, -1);
 
196
        //if (LktrCond) err = -1;
 
197
        if (unlikely(err))
 
198
                goto out_unlock;
 
199
 
 
200
        /* support LSM and notify */
 
201
        mnt_flags = au_mntflags(sb);
 
202
        vfsub_args_init(&vargs, &ign, au_opt_test_dlgt(mnt_flags), 0);
 
203
        h_file = au_h_fptr(file, au_fbstart(file));
 
204
        if (!au_opt_test(mnt_flags, UDBA_INOTIFY))
 
205
                err = vfsub_write_u(h_file, buf, count, ppos, &vargs);
 
206
        else {
 
207
                parent = dget_parent(dentry);
 
208
                dir = parent->d_inode;
 
209
                ii_read_lock_parent(dir);
 
210
                vfsub_ign_hinode(&vargs, IN_MODIFY,
 
211
                                 au_hi(dir, au_fbstart(file)));
 
212
                err = vfsub_write_u(h_file, buf, count, ppos, &vargs);
 
213
                ii_read_unlock(dir);
 
214
                dput(parent);
 
215
        }
 
216
        ii_write_lock_child(inode);
 
217
        au_cpup_attr_timesizes(inode);
 
218
        ii_write_unlock(inode);
 
219
 
 
220
 out_unlock:
 
221
        fi_write_unlock(file);
 
222
 out:
 
223
        si_read_unlock(sb);
 
224
        mutex_unlock(&inode->i_mutex);
 
225
        AuTraceErr(err);
 
226
        return err;
 
227
}
 
228
 
 
229
#ifdef 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
 
 
240
static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
 
241
                                struct pipe_inode_info *pipe, size_t len,
 
242
                                unsigned int flags)
 
243
{
 
244
        ssize_t err;
 
245
        struct file *h_file;
 
246
        struct dentry *dentry;
 
247
        struct super_block *sb;
 
248
 
 
249
        dentry = file->f_dentry;
 
250
        LKTRTrace("%.*s, pos %Ld, len %lu\n",
 
251
                  AuDLNPair(dentry), *ppos, (unsigned long)len);
 
252
 
 
253
        sb = dentry->d_sb;
 
254
        si_read_lock(sb, AuLock_FLUSH);
 
255
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
 
256
                                      /*locked*/0);
 
257
        if (unlikely(err))
 
258
                goto out;
 
259
 
 
260
        err = -EINVAL;
 
261
        /* support LSM and notify */
 
262
        h_file = au_h_fptr(file, au_fbstart(file));
 
263
        if (/* unlikely */(au_test_loopback())) {
 
264
                file->f_mapping = h_file->f_mapping;
 
265
                smp_mb(); /* unnecessary? */
 
266
        }
 
267
        err = vfsub_splice_to(h_file, ppos, pipe, len, flags,
 
268
                              au_opt_test_dlgt(au_mntflags(sb)));
 
269
        //file->f_ra = h_file->f_ra; //??
 
270
        fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
 
271
        fi_read_unlock(file);
 
272
 
 
273
 out:
 
274
        si_read_unlock(sb);
 
275
        AuTraceErr(err);
 
276
        return err;
 
277
}
 
278
 
 
279
static ssize_t
 
280
aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
 
281
                  size_t len, unsigned int flags)
 
282
{
 
283
        ssize_t err;
 
284
        struct dentry *dentry;
 
285
        struct inode *inode, *h_inode;
 
286
        struct super_block *sb;
 
287
        struct file *h_file;
 
288
        struct au_hin_ignore ign;
 
289
        struct vfsub_args vargs;
 
290
        unsigned int mnt_flags;
 
291
 
 
292
        dentry = file->f_dentry;
 
293
        LKTRTrace("%.*s, len %lu, pos %Ld\n",
 
294
                  AuDLNPair(dentry), (unsigned long)len, *ppos);
 
295
 
 
296
        inode = dentry->d_inode;
 
297
        mutex_lock(&inode->i_mutex);
 
298
        sb = dentry->d_sb;
 
299
        si_read_lock(sb, AuLock_FLUSH);
 
300
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/1,
 
301
                                      /*locked*/1);
 
302
        //if (LktrCond) {fi_write_unlock(file); err = -1;}
 
303
        if (unlikely(err))
 
304
                goto out;
 
305
        err = au_ready_to_write(file, -1);
 
306
        //if (LktrCond) err = -1;
 
307
        if (unlikely(err))
 
308
                goto out_unlock;
 
309
 
 
310
        /* support LSM and notify */
 
311
        mnt_flags = au_mntflags(sb);
 
312
        vfsub_args_init(&vargs, &ign, au_opt_test_dlgt(mnt_flags), 0);
 
313
        h_file = au_h_fptr(file, au_fbstart(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_opt_test(mnt_flags, UDBA_INOTIFY))
 
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
                //au_hi(parent->d_inode, au_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
        mutex_unlock(&inode->i_mutex);
 
334
        AuTraceErr(err);
 
335
        return err;
 
336
}
 
337
#endif /* CONFIG_AUFS_SPLICE_PATCH */
 
338
 
 
339
/* ---------------------------------------------------------------------- */
 
340
 
 
341
static int aufs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 
342
{
 
343
        int err;
 
344
        struct dentry *dentry;
 
345
        struct file *file, *h_file;
 
346
        struct inode *inode;
 
347
        static DECLARE_WAIT_QUEUE_HEAD(wq);
 
348
        struct au_finfo *finfo;
 
349
        //struct page *page;
 
350
 
 
351
        AuTraceEnter();
 
352
        AuDebugOn(!vma || !vma->vm_file);
 
353
        //todo: non-robr mode, user vm_file as it is.
 
354
        wait_event(wq, (file = au_robr_safe_file(vma)));
 
355
        AuDebugOn(!au_test_aufs(file->f_dentry->d_sb));
 
356
        dentry = file->f_dentry;
 
357
        LKTRTrace("%.*s\n", AuDLNPair(dentry));
 
358
        inode = dentry->d_inode;
 
359
        AuDebugOn(!S_ISREG(inode->i_mode));
 
360
 
 
361
        /* do not revalidate, nor lock */
 
362
        finfo = au_fi(file);
 
363
        h_file = finfo->fi_hfile[0 + finfo->fi_bstart].hf_file;
 
364
        AuDebugOn(!h_file || !au_test_mmapped(file));
 
365
        vma->vm_file = h_file;
 
366
        //smp_mb();
 
367
        err = finfo->fi_h_vm_ops->fault(vma, vmf);
 
368
        //file->f_ra = h_file->f_ra; //??
 
369
        au_robr_reset_file(vma, file);
 
370
#if 0 //def CONFIG_SMP
 
371
        //wake_up_nr(&wq, online_cpu - 1);
 
372
        wake_up_all(&wq);
 
373
#else
 
374
        wake_up(&wq);
 
375
#endif
 
376
 
 
377
        if (!(err & VM_FAULT_ERROR)) {
 
378
#if 0
 
379
                page = vmf->page;
 
380
                AuDbg("%p, %d\n", page, page_mapcount(page));
 
381
#endif
 
382
                //page->mapping = file->f_mapping;
 
383
                //get_page(page);
 
384
                //file->f_mapping = h_file->f_mapping;
 
385
                //touch_atime(NULL, dentry);
 
386
                //inode->i_atime = h_file->f_dentry->d_inode->i_atime;
 
387
        }
 
388
        AuTraceErr(err);
 
389
        //AuDbg("err %d\n", err);
 
390
        return err;
 
391
}
 
392
 
 
393
static struct vm_operations_struct aufs_vm_ops = {
 
394
        //.open         = aufs_vmaopen,
 
395
        //.close                = aufs_vmaclose,
 
396
        .fault          = aufs_fault,
 
397
#if 0 // rfu
 
398
        unsigned long (*nopfn)(struct vm_area_struct *area,
 
399
                               unsigned long address);
 
400
        //page_mkwrite(struct vm_area_struct *vma, struct page *page)
 
401
#endif
 
402
};
 
403
 
 
404
/* ---------------------------------------------------------------------- */
 
405
 
 
406
static struct vm_operations_struct *au_vm_ops(struct file *h_file,
 
407
                                              struct vm_area_struct *vma)
 
408
{
 
409
        struct vm_operations_struct *vm_ops;
 
410
        int err;
 
411
 
 
412
        AuTraceEnter();
 
413
 
 
414
        if (!au_test_nfs(h_file->f_vfsmnt->mnt_sb))
 
415
                err = h_file->f_op->mmap(h_file, vma);
 
416
        else {
 
417
                lockdep_off();
 
418
                err = h_file->f_op->mmap(h_file, vma);
 
419
                lockdep_on();
 
420
        }
 
421
        vm_ops = ERR_PTR(err);
 
422
        if (unlikely(err))
 
423
                goto out;
 
424
        vm_ops = vma->vm_ops;
 
425
        err = do_munmap(current->mm, vma->vm_start,
 
426
                        vma->vm_end - vma->vm_start);
 
427
        if (unlikely(err)) {
 
428
                AuIOErr("failed internal unmapping %.*s, %d\n",
 
429
                        AuDLNPair(h_file->f_dentry), err);
 
430
                vm_ops = ERR_PTR(-EIO);
 
431
        }
 
432
 
 
433
 out:
 
434
        AuTraceErrPtr(vm_ops);
 
435
        return vm_ops;
 
436
}
 
437
 
 
438
static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
 
439
{
 
440
        int err, wlock, mmapped;
 
441
        struct dentry *dentry;
 
442
        struct super_block *sb;
 
443
        struct file *h_file;
 
444
        struct vm_operations_struct *vm_ops;
 
445
 
 
446
        dentry = file->f_dentry;
 
447
        LKTRTrace("%.*s, %lx, len %lu\n",
 
448
                  AuDLNPair(dentry), vma->vm_start,
 
449
                  vma->vm_end - vma->vm_start);
 
450
        AuDebugOn(!S_ISREG(dentry->d_inode->i_mode));
 
451
        AuDebugOn(down_write_trylock(&vma->vm_mm->mmap_sem));
 
452
 
 
453
        mmapped = au_test_mmapped(file); /* can be harmless race condition */
 
454
        wlock = !!(file->f_mode & FMODE_WRITE);
 
455
        sb = dentry->d_sb;
 
456
        si_read_lock(sb, AuLock_FLUSH);
 
457
        err = au_reval_and_lock_finfo(file, au_reopen_nondir,
 
458
                                      wlock | !mmapped, /*locked*/0);
 
459
        //err = -1;
 
460
        if (unlikely(err))
 
461
                goto out;
 
462
 
 
463
        if (wlock) {
 
464
                err = au_ready_to_write(file, -1);
 
465
                //err = -1;
 
466
                if (unlikely(err))
 
467
                        goto out_unlock;
 
468
        }
 
469
 
 
470
        h_file = au_h_fptr(file, au_fbstart(file));
 
471
        if (unlikely(au_test_fuse(h_file->f_dentry->d_sb))) {
 
472
                /*
 
473
                 * by this assignment, f_mapping will differs from aufs inode
 
474
                 * i_mapping.
 
475
                 * if someone else mixes the use of f_dentry->d_inode and
 
476
                 * f_mapping->host, then a problem may arise.
 
477
                 */
 
478
                file->f_mapping = h_file->f_mapping;
 
479
        }
 
480
 
 
481
        if (0 && h_file->f_op->mmap == generic_file_mmap) {
 
482
                err = generic_file_mmap(file, vma); /* instead of h_file */
 
483
                if (unlikely(err))
 
484
                        goto out_unlock;
 
485
                au_fi(file)->fi_h_vm_ops = vma->vm_ops;
 
486
        } else {
 
487
                vm_ops = NULL;
 
488
                if (!mmapped) {
 
489
                        vm_ops = au_vm_ops(h_file, vma);
 
490
                        err = PTR_ERR(vm_ops);
 
491
                        if (IS_ERR(vm_ops))
 
492
                                goto out_unlock;
 
493
                }
 
494
 
 
495
                err = generic_file_mmap(file, vma);
 
496
                if (unlikely(err))
 
497
                        goto out_unlock;
 
498
                vma->vm_ops = &aufs_vm_ops;
 
499
                if (!mmapped)
 
500
                        au_fi(file)->fi_h_vm_ops = vm_ops;
 
501
        }
 
502
 
 
503
        file_accessed(h_file);
 
504
        au_update_fuse_h_inode(h_file->f_vfsmnt, h_file->f_dentry); /*ignore*/
 
505
        fsstack_copy_attr_atime(dentry->d_inode, h_file->f_dentry->d_inode);
 
506
 
 
507
 out_unlock:
 
508
        if (!wlock && mmapped)
 
509
                fi_read_unlock(file);
 
510
        else
 
511
                fi_write_unlock(file);
 
512
 out:
 
513
        si_read_unlock(sb);
 
514
        AuTraceErr(err);
 
515
        return err;
 
516
}
 
517
 
 
518
/* ---------------------------------------------------------------------- */
 
519
 
 
520
static unsigned int aufs_poll(struct file *file, poll_table *wait)
 
521
{
 
522
        unsigned int mask;
 
523
        struct file *h_file;
 
524
        int err;
 
525
        struct dentry *dentry;
 
526
        struct super_block *sb;
 
527
 
 
528
        dentry = file->f_dentry;
 
529
        LKTRTrace("%.*s, wait %p\n", AuDLNPair(dentry), wait);
 
530
        AuDebugOn(S_ISDIR(dentry->d_inode->i_mode));
 
531
 
 
532
        /* We should pretend an error happened. */
 
533
        mask = POLLERR /* | POLLIN | POLLOUT */;
 
534
        sb = dentry->d_sb;
 
535
        si_read_lock(sb, AuLock_FLUSH);
 
536
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
 
537
                                      /*locked*/0);
 
538
        //err = -1;
 
539
        if (unlikely(err))
 
540
                goto out;
 
541
 
 
542
        /* it is not an error of hidden_file has no operation */
 
543
        mask = DEFAULT_POLLMASK;
 
544
        h_file = au_h_fptr(file, au_fbstart(file));
 
545
        if (h_file->f_op && h_file->f_op->poll)
 
546
                mask = h_file->f_op->poll(h_file, wait);
 
547
        fi_read_unlock(file);
 
548
 
 
549
 out:
 
550
        si_read_unlock(sb);
 
551
        AuTraceErr((int)mask);
 
552
        return mask;
 
553
}
 
554
 
 
555
static int aufs_fsync_nondir(struct file *file, struct dentry *dentry,
 
556
                             int datasync)
 
557
{
 
558
        int err;
 
559
        struct inode *inode;
 
560
        struct file *h_file;
 
561
        struct super_block *sb;
 
562
 
 
563
        LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), datasync);
 
564
        inode = dentry->d_inode;
 
565
 
 
566
        IMustLock(file->f_mapping->host);
 
567
        if (unlikely(inode != file->f_mapping->host)) {
 
568
                mutex_unlock(&file->f_mapping->host->i_mutex);
 
569
                mutex_lock(&inode->i_mutex);
 
570
        }
 
571
        IMustLock(inode);
 
572
 
 
573
        sb = dentry->d_sb;
 
574
        si_read_lock(sb, AuLock_FLUSH);
 
575
        err = 0; //-EBADF; // posix?
 
576
        if (unlikely(!(file->f_mode & FMODE_WRITE)))
 
577
                goto out;
 
578
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/1,
 
579
                                      /*locked*/1);
 
580
        //err = -1;
 
581
        if (unlikely(err))
 
582
                goto out;
 
583
        err = au_ready_to_write(file, -1);
 
584
        //err = -1;
 
585
        if (unlikely(err))
 
586
                goto out_unlock;
 
587
 
 
588
        err = -EINVAL;
 
589
        h_file = au_h_fptr(file, au_fbstart(file));
 
590
        if (h_file->f_op && h_file->f_op->fsync) {
 
591
                ii_write_lock_child(inode);
 
592
                mutex_lock_nested(&h_file->f_dentry->d_inode->i_mutex,
 
593
                                  AuLsc_I_CHILD);
 
594
                err = h_file->f_op->fsync(h_file, h_file->f_dentry, datasync);
 
595
                //err = -1;
 
596
                if (!err)
 
597
                        au_update_fuse_h_inode(h_file->f_vfsmnt,
 
598
                                               h_file->f_dentry);
 
599
                au_cpup_attr_timesizes(inode);
 
600
                mutex_unlock(&h_file->f_dentry->d_inode->i_mutex);
 
601
                ii_write_unlock(inode);
 
602
        }
 
603
 
 
604
 out_unlock:
 
605
        fi_write_unlock(file);
 
606
 out:
 
607
        si_read_unlock(sb);
 
608
        if (unlikely(inode != file->f_mapping->host)) {
 
609
                mutex_unlock(&inode->i_mutex);
 
610
                mutex_lock(&file->f_mapping->host->i_mutex);
 
611
        }
 
612
        AuTraceErr(err);
 
613
        return err;
 
614
}
 
615
 
 
616
static int aufs_fasync(int fd, struct file *file, int flag)
 
617
{
 
618
        int err;
 
619
        struct file *h_file;
 
620
        struct dentry *dentry;
 
621
        struct super_block *sb;
 
622
 
 
623
        dentry = file->f_dentry;
 
624
        LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), flag);
 
625
 
 
626
        sb = dentry->d_sb;
 
627
        si_read_lock(sb, AuLock_FLUSH);
 
628
        err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
 
629
                                      /*locked*/0);
 
630
        //err = -1;
 
631
        if (unlikely(err))
 
632
                goto out;
 
633
 
 
634
        h_file = au_h_fptr(file, au_fbstart(file));
 
635
        if (h_file->f_op && h_file->f_op->fasync)
 
636
                err = h_file->f_op->fasync(fd, h_file, flag);
 
637
        fi_read_unlock(file);
 
638
 
 
639
 out:
 
640
        si_read_unlock(sb);
 
641
        AuTraceErr(err);
 
642
        return err;
 
643
}
 
644
 
 
645
/* ---------------------------------------------------------------------- */
 
646
 
 
647
struct file_operations aufs_file_fop = {
 
648
        .read           = aufs_read,
 
649
        .write          = aufs_write,
 
650
        .poll           = aufs_poll,
 
651
        .mmap           = aufs_mmap,
 
652
        .open           = aufs_open_nondir,
 
653
        .flush          = aufs_flush,
 
654
        .release        = aufs_release_nondir,
 
655
        .fsync          = aufs_fsync_nondir,
 
656
        .fasync         = aufs_fasync,
 
657
#ifdef CONFIG_AUFS_SPLICE_PATCH
 
658
        .splice_write   = aufs_splice_write,
 
659
        .splice_read    = aufs_splice_read,
 
660
#endif
 
661
};