39
39
aufs_bindex_t bindex, bend;
41
41
dentry = file->f_dentry;
42
LKTRTrace("%.*s\n", DLNPair(dentry));
42
LKTRTrace("%.*s\n", AuDLNPair(dentry));
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);
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);
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);
57
au_update_fuse_h_inode
58
(h_file->f_vfsmnt, h_file->f_dentry);
62
au_cpup_attr_timesizes(dentry->d_inode);
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);
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);
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);
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;
170
162
fi_read_unlock(file);
172
164
si_read_unlock(sb);
178
170
size_t count, loff_t *ppos)
181
struct dentry *dentry;
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;
177
char __user *buf = (char __user *)__buf;
186
178
struct inode *h_inode;
179
struct aufs_hin_ignore ign;
180
struct vfsub_args vargs;
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);
193
186
inode = dentry->d_inode;
195
188
sb = dentry->d_sb;
189
si_read_lock(sb, AuLock_FLUSH);
197
190
err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/1,
199
192
//if (LktrCond) {fi_write_unlock(file); err = -1;}
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);
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);
225
ii_write_lock_child(inode);
226
au_cpup_attr_timesizes(inode);
227
ii_write_unlock(inode);
230
fi_write_unlock(file);
215
ii_write_lock_child(inode);
216
au_cpup_attr_timesizes(inode);
217
ii_write_unlock(inode);
220
fi_write_unlock(file);
223
vfsub_i_unlock(inode);
228
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) \
229
|| defined(CONFIG_AUFS_SPLICE_PATCH)
230
static int au_test_loopback(void)
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);
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,
248
struct dentry *dentry;
249
struct super_block *sb;
251
dentry = file->f_dentry;
252
LKTRTrace("%.*s, pos %Ld, len %lu\n",
253
AuDLNPair(dentry), *ppos, (unsigned long)len);
256
si_read_lock(sb, AuLock_FLUSH);
257
err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
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? */
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);
281
aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
282
size_t len, unsigned int flags)
285
struct dentry *dentry;
287
struct super_block *sb;
289
struct inode *h_inode;
290
struct aufs_hin_ignore ign;
291
struct vfsub_args vargs;
293
dentry = file->f_dentry;
294
LKTRTrace("%.*s, len %lu, pos %Ld\n",
295
AuDLNPair(dentry), (unsigned long)len, *ppos);
297
inode = dentry->d_inode;
300
si_read_lock(sb, AuLock_FLUSH);
301
err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/1,
303
//if (LktrCond) {fi_write_unlock(file); err = -1;}
306
err = au_ready_to_write(file, -1);
307
//if (LktrCond) err = -1;
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);
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);
325
ii_write_lock_child(inode);
326
au_cpup_attr_timesizes(inode);
327
ii_write_unlock(inode);
330
fi_write_unlock(file);
333
vfsub_i_unlock(inode);
337
#endif /* CONFIG_AUFS_SPLICE_PATCH */
238
339
/* ---------------------------------------------------------------------- */
240
#if 0 //def CONFIG_AUFS_ROBR
341
#ifdef CONFIG_AUFS_ROBR
242
343
struct list_head list;
243
344
struct vm_area_struct *vma;
321
422
static void reset_file(struct vm_area_struct *vma, struct file *file)
323
424
vma->vm_file = file;
425
smp_mb(); /* flush vm_file */
326
427
#endif /* CONFIG_AUFS_ROBR */
429
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
430
static int aufs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
433
struct dentry *dentry;
434
struct file *file, *hidden_file;
436
static DECLARE_WAIT_QUEUE_HEAD(wq);
437
struct aufs_finfo *finfo;
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));
448
/* do not revalidate, nor lock */
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;
455
AuDbg("fault %p, filemap_fault %p\n",
456
finfo->fi_h_vm_ops->fault, filemap_fault);
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);
468
//page->mapping = file->f_mapping;
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;
475
//AuDbg("err %d\n", err);
328
479
static struct page *aufs_nopage(struct vm_area_struct *vma, unsigned long addr,
335
486
static DECLARE_WAIT_QUEUE_HEAD(wq);
336
487
struct aufs_finfo *finfo;
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));
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;
353
504
page = finfo->fi_h_vm_ops->nopage(vma, addr, type);
373
524
unsigned long len, pgprot_t prot, unsigned long pgoff,
376
Err("please report me this application\n");
378
528
return ftofi(vma->vm_file)->fi_h_vm_ops->populate
379
529
(vma, addr, len, prot, pgoff, nonblock);
531
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) */
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)
385
539
.nopage = aufs_nopage,
386
540
.populate = aufs_populate,
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)
390
549
/* ---------------------------------------------------------------------- */
464
629
fi_write_unlock(file);
466
631
si_read_unlock(sb);
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)
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;
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);
489
650
sb = dentry->d_sb;
651
si_read_lock(sb, AuLock_FLUSH);
491
652
err = au_reval_and_lock_finfo(file, au_reopen_nondir, /*wlock*/0,
493
654
if (unlikely(err))
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;
503
// nfs uses some locks
505
err = h_file->f_op->sendfile
506
(h_file, ppos, count, actor, target);
662
smp_mb(); /* unnecessary? */
664
if (!au_test_nfs(h_file->f_vfsmnt->mnt_sb))
665
err = h_file->f_op->sendfile(h_file, ppos, count, actor,
669
err = h_file->f_op->sendfile(h_file, ppos, count, actor,
674
au_update_fuse_h_inode(h_file->f_vfsmnt,
508
677
dentry->d_inode->i_atime = h_file->f_dentry->d_inode->i_atime;
510
679
fi_read_unlock(file);
513
682
si_read_unlock(sb);
686
#endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22) */
518
688
/* ---------------------------------------------------------------------- */
642
814
si_read_unlock(sb);
647
819
/* ---------------------------------------------------------------------- */
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 *);
681
821
struct file_operations aufs_file_fop = {
682
822
.read = aufs_read,
683
823
.write = aufs_write,