16
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
/* $Id: vfsub.c,v 1.8 2007/06/04 02:17:35 sfjro Exp $ */
19
/* $Id: vfsub.c,v 1.24 2007/12/10 01:20:14 sfjro Exp $ */
20
20
// I'm going to slightly mad
24
24
/* ---------------------------------------------------------------------- */
26
#ifdef CONFIG_AUFS_DLGT
26
#ifdef CONFIG_AUFS_HINOTIFY
27
/* cf. fsnotify_change() */
28
__u32 vfsub_events_notify_change(struct iattr *ia)
31
const unsigned int amtime = (ATTR_ATIME | ATTR_MTIME);
34
if ((ia->ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
35
|| (ia->ia_valid & amtime) == amtime)
37
if ((ia->ia_valid & ATTR_SIZE)
38
|| (ia->ia_valid & amtime) == ATTR_MTIME)
43
void vfsub_ign_hinode(struct vfsub_args *vargs, __u32 events,
44
struct aufs_hinode *hinode)
46
struct aufs_hin_ignore *ign;
50
ign = vargs->ignore + vargs->nignore++;
51
ign->ign_events = events;
52
ign->ign_hinode = hinode;
55
void vfsub_ignore(struct vfsub_args *vargs)
58
struct aufs_hin_ignore *ign;
63
au_hin_ignore(ign->ign_hinode, ign->ign_events);
68
void vfsub_unignore(struct vfsub_args *vargs)
71
struct aufs_hin_ignore *ign;
76
au_hin_unignore(ign->ign_hinode, ign->ign_events);
80
#endif /* CONFIG_AUFS_HINOTIFY */
82
/* ---------------------------------------------------------------------- */
84
#if defined(CONFIG_AUFS_DLGT) || defined(CONFIG_AUFS_HINOTIFY)
27
85
struct permission_args {
29
87
struct inode *inode;
235
293
struct inode *src_dir, *dir;
236
294
struct dentry *src_dentry, *dentry;
295
struct vfsub_args *vargs;
239
298
static void call_rename(void *args)
241
300
struct rename_args *a = args;
301
vfsub_ignore(a->vargs);
242
302
*a->errp = do_vfsub_rename(a->src_dir, a->src_dentry, a->dir,
304
if (unlikely(*a->errp))
305
vfsub_unignore(a->vargs);
246
308
int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
247
struct inode *dir, struct dentry *dentry, int dlgt)
309
struct inode *dir, struct dentry *dentry,
310
struct vfsub_args *vargs)
250
return do_vfsub_rename(src_dir, src_dentry, dir, dentry);
316
err = do_vfsub_rename(src_dir, src_dentry, dir, dentry);
318
vfsub_unignore(vargs);
253
321
struct rename_args args = {
255
323
.src_dir = src_dir,
256
324
.src_dentry = src_dentry,
260
329
wkq_err = au_wkq_wait(call_rename, &args, /*dlgt*/1);
261
330
if (unlikely(wkq_err))
267
336
struct rmdir_args {
269
338
struct inode *dir;
270
339
struct dentry *dentry;
340
struct vfsub_args *vargs;
273
343
static void call_rmdir(void *args)
275
345
struct rmdir_args *a = args;
346
vfsub_ignore(a->vargs);
276
347
*a->errp = do_vfsub_rmdir(a->dir, a->dentry);
348
if (unlikely(*a->errp))
349
vfsub_unignore(a->vargs);
279
int vfsub_rmdir(struct inode *dir, struct dentry *dentry, int dlgt)
352
int vfsub_rmdir(struct inode *dir, struct dentry *dentry,
353
struct vfsub_args *vargs)
282
return do_vfsub_rmdir(dir, dentry);
359
err = do_vfsub_rmdir(dir, dentry);
361
vfsub_unignore(vargs);
285
364
struct rmdir_args args = {
290
370
wkq_err = au_wkq_wait(call_rmdir, &args, /*dlgt*/1);
291
371
if (unlikely(wkq_err))
297
377
/* ---------------------------------------------------------------------- */
492
struct vfsub_args *vargs;
414
495
static void call_write_k(void *args)
416
497
struct write_args *a = args;
417
498
LKTRTrace("%.*s, cnt %lu, pos %Ld\n",
418
DLNPair(a->file->f_dentry), (unsigned long)a->count,
499
AuDLNPair(a->file->f_dentry), (unsigned long)a->count,
501
vfsub_ignore(a->vargs);
420
502
*a->errp = do_vfsub_write_k(a->file, a->kbuf, a->count, a->ppos);
503
if (unlikely(*a->errp < 0))
504
vfsub_unignore(a->vargs);
423
507
ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
424
loff_t *ppos, int dlgt)
508
loff_t *ppos, struct vfsub_args *vargs)
427
return do_vfsub_write_u(file, ubuf, count, ppos);
429
ssize_t err, written;
514
err = do_vfsub_write_u(file, ubuf, count, ppos);
515
if (unlikely(err < 0))
516
vfsub_unignore(vargs);
431
520
struct write_args args = {
438
528
if (unlikely(!count))
538
#endif /* CONFIG_AUFS_DLGT */
634
struct splice_to_args {
638
struct pipe_inode_info *pipe;
643
static void call_splice_to(void *args)
645
struct splice_to_args *a = args;
646
*a->errp = do_vfsub_splice_to(a->in, a->ppos, a->pipe, a->len,
650
long vfsub_splice_to(struct file *in, loff_t *ppos,
651
struct pipe_inode_info *pipe, size_t len,
652
unsigned int flags, int dlgt)
655
return do_vfsub_splice_to(in, ppos, pipe, len, flags);
659
struct splice_to_args args = {
667
wkq_err = au_wkq_wait(call_splice_to, &args, /*dlgt*/1);
668
if (unlikely(wkq_err))
674
struct splice_from_args {
676
struct pipe_inode_info *pipe;
681
struct vfsub_args *vargs;
684
static void call_splice_from(void *args)
686
struct splice_from_args *a = args;
687
vfsub_ignore(a->vargs);
688
*a->errp = do_vfsub_splice_from(a->pipe, a->out, a->ppos, a->len,
690
if (unlikely(*a->errp < 0))
691
vfsub_unignore(a->vargs);
694
long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
695
loff_t *ppos, size_t len, unsigned int flags,
696
struct vfsub_args *vargs)
702
err = do_vfsub_splice_from(pipe, out, ppos, len, flags);
703
if (unlikely(err < 0))
704
vfsub_unignore(vargs);
707
struct splice_from_args args = {
716
wkq_err = au_wkq_wait(call_splice_from, &args, /*dlgt*/1);
717
if (unlikely(wkq_err))
723
/* ---------------------------------------------------------------------- */
725
struct getattr_args {
727
struct vfsmount *mnt;
728
struct dentry *dentry;
732
static void call_getattr(void *args)
734
struct getattr_args *a = args;
735
*a->errp = do_vfsub_getattr(a->mnt, a->dentry, a->st);
738
int vfsub_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *st,
742
return do_vfsub_getattr(mnt, dentry, st);
745
struct getattr_args args = {
751
wkq_err = au_wkq_wait(call_getattr, &args, /*dlgt*/1);
752
if (unlikely(wkq_err))
757
#endif /* CONFIG_AUFS_DLGT || CONFIG_AUFS_HINOTIFY */
759
/* ---------------------------------------------------------------------- */
761
struct au_vfsub_mkdir_args {
764
struct dentry *dentry;
769
static void au_call_vfsub_mkdir(void *args)
771
struct au_vfsub_mkdir_args *a = args;
772
*a->errp = vfsub_mkdir(a->dir, a->dentry, a->mode, a->dlgt);
775
int vfsub_sio_mkdir(struct inode *dir, struct dentry *dentry, int mode,
778
int err, do_sio, wkq_err;
780
LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
782
do_sio = au_test_perm(dir, MAY_EXEC | MAY_WRITE, dlgt);
784
err = vfsub_mkdir(dir, dentry, mode, dlgt);
786
struct au_vfsub_mkdir_args args = {
793
wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args, /*dlgt*/0);
794
if (unlikely(wkq_err))
802
struct au_vfsub_rmdir_args {
805
struct dentry *dentry;
806
struct vfsub_args *vargs;
809
static void au_call_vfsub_rmdir(void *args)
811
struct au_vfsub_rmdir_args *a = args;
812
*a->errp = vfsub_rmdir(a->dir, a->dentry, a->vargs);
815
int vfsub_sio_rmdir(struct inode *dir, struct dentry *dentry, int dlgt)
817
int err, do_sio, wkq_err;
818
struct vfsub_args vargs;
820
LKTRTrace("i%lu, %.*s\n", dir->i_ino, AuDLNPair(dentry));
822
vfsub_args_init(&vargs, /*ign*/NULL, dlgt, /*force_unlink*/0);
823
do_sio = au_test_perm(dir, MAY_EXEC | MAY_WRITE, dlgt);
825
err = vfsub_rmdir(dir, dentry, &vargs);
827
struct au_vfsub_rmdir_args args = {
833
wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args, /*dlgt*/0);
834
if (unlikely(wkq_err))
540
842
/* ---------------------------------------------------------------------- */
551
854
struct inode *h_inode;
553
856
LKTRTrace("%.*s, ia_valid 0x%x\n",
554
DLNPair(a->h_dentry), a->ia->ia_valid);
857
AuDLNPair(a->h_dentry), a->ia->ia_valid);
555
858
h_inode = a->h_dentry->d_inode;
556
859
IMustLock(h_inode);
558
861
*a->errp = -EPERM;
559
862
if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
863
vfsub_ignore(a->vargs);
561
*a->errp = notify_change(a->h_dentry, NULL, a->ia);
865
*a->errp = notify_change(a->h_dentry, a->ia);
868
au_update_fuse_h_inode(NULL, a->h_dentry); /*ignore*/
870
vfsub_unignore(a->vargs);
872
AuTraceErr(*a->errp);
567
int vfsub_notify_change(struct dentry *dentry, struct iattr *ia, int dlgt)
875
int vfsub_notify_change(struct dentry *dentry, struct iattr *ia,
876
struct vfsub_args *vargs)
570
879
struct notify_change_args args = {
572
881
.h_dentry = dentry,
576
886
#ifndef CONFIG_AUFS_DLGT
577
887
call_notify_change(&args);
580
890
call_notify_change(&args);
1015
/* ---------------------------------------------------------------------- */
1017
#ifdef CONFIG_AUFS_WORKAROUND_FUSE
1018
/* h_mnt can be NULL, is it safe? */
1019
int au_update_fuse_h_inode(struct vfsmount *h_mnt, struct dentry *h_dentry)
1024
LKTRTrace("%.*s\n", AuDLNPair(h_dentry));
1027
if (unlikely(h_dentry->d_inode
1028
//&& atomic_read(&h_dentry->d_inode->i_count)
1029
&& au_test_fuse(h_dentry->d_sb))) {
1030
err = vfsub_getattr(h_mnt, h_dentry, &st, /*dlgt*/0);
1031
if (unlikely(err)) {
1032
AuDbg("err %d\n", err);
1034
AuDbgDentry(h_dentry);
1045
* This function was born after a discussion with the FUSE developer.
1046
* The inode attributes on a filesystem who defines i_op->getattr()
1047
* is unreliable since such fs may not maintain the attributes at lookup.
1048
* This function doesn't want the result of stat, instead wants the side-effect
1049
* which refreshes the attributes.
1050
* Hmm, there seems to be no such filesystem except fuse.
1052
int vfsub_i_attr(struct vfsmount *mnt, struct dentry *dentry, int dlgt)
1055
struct inode *inode;
1056
struct inode_operations *op;
1059
inode = dentry->d_inode;
1064
if (unlikely(op && op->getattr && !au_test_aufs(dentry->d_sb))) {
1065
err = security_inode_getattr(mnt, dentry);
1067
err = op->getattr(mnt, dentry, &st);