2
* Copyright (C) 2006-2008 Junjiro Okajima
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.
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.
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
22
* $Id: hinotify.c,v 1.4 2008/05/04 23:52:19 sfjro Exp $
28
static const __u32 AuInMask = (IN_MOVE | IN_DELETE | IN_CREATE
30
| IN_MODIFY | IN_ATTRIB
31
/* | IN_DELETE_SELF | IN_MOVE_SELF */
33
static struct inotify_handle *in_handle;
35
/* the size of an array for ignore counter */
36
static int au_hin_nignore;
38
AuCacheFuncs(hinotify, AuCache_HINOTIFY);
40
int au_hin_alloc(struct au_hinode *hinode, struct inode *inode,
41
struct inode *hidden_inode)
44
struct au_hinotify *hin;
47
LKTRTrace("i%lu, hi%lu\n", inode->i_ino, hidden_inode->i_ino);
50
hin = au_cache_alloc_hinotify();
52
AuDebugOn(hinode->hi_notify);
53
hinode->hi_notify = hin;
54
hin->hin_aufs_inode = inode;
55
for (i = 0; i < au_hin_nignore; i++)
56
atomic_set(hin->hin_ignore + i, 0);
58
inotify_init_watch(&hin->hin_watch);
59
wd = inotify_add_watch(in_handle, &hin->hin_watch, hidden_inode,
62
return 0; /* success */
65
put_inotify_watch(&hin->hin_watch);
66
au_cache_free_hinotify(hin);
67
hinode->hi_notify = NULL;
74
void au_hin_free(struct au_hinode *hinode)
77
struct au_hinotify *hin;
81
hin = hinode->hi_notify;
84
if (atomic_read(&hin->hin_watch.count))
85
err = inotify_rm_watch(in_handle, &hin->hin_watch);
88
au_cache_free_hinotify(hin);
89
hinode->hi_notify = NULL;
91
AuIOErr1("failed inotify_rm_watch() %d\n", err);
95
/* ---------------------------------------------------------------------- */
97
static void ctl_hinotify(struct au_hinode *hinode, const __u32 mask)
99
struct inode *h_inode;
100
struct inotify_watch *watch;
102
h_inode = hinode->hi_inode;
103
LKTRTrace("hi%lu, sb %p, 0x%x\n", h_inode->i_ino, h_inode->i_sb, mask);
105
if (!hinode->hi_notify)
108
watch = &hinode->hi_notify->hin_watch;
112
wd = inotify_find_update_watch(in_handle, h_inode, mask);
117
/* struct inotify_handle is hidden */
118
mutex_lock(&h_inode->inotify_mutex);
119
//mutex_lock(&watch->ih->mutex);
121
//mutex_unlock(&watch->ih->mutex);
122
mutex_unlock(&h_inode->inotify_mutex);
124
LKTRTrace("watch %p, mask %u\n", watch, watch->mask);
127
#define suspend_hinotify(hi) ctl_hinotify(hi, 0)
128
#define resume_hinotify(hi) ctl_hinotify(hi, AuInMask)
130
void au_do_hdir_lock(struct inode *h_dir, struct inode *dir,
131
aufs_bindex_t bindex, unsigned int lsc)
133
struct au_hinode *hinode;
135
LKTRTrace("i%lu, b%d, lsc %d\n", dir->i_ino, bindex, lsc);
136
AuDebugOn(!S_ISDIR(dir->i_mode));
137
hinode = au_ii(dir)->ii_hinode + bindex;
138
AuDebugOn(h_dir != hinode->hi_inode);
140
mutex_lock_nested(&h_dir->i_mutex, lsc);
141
suspend_hinotify(hinode);
144
void au_hdir_unlock(struct inode *h_dir, struct inode *dir,
145
aufs_bindex_t bindex)
147
struct au_hinode *hinode;
149
LKTRTrace("i%lu, b%d\n", dir->i_ino, bindex);
150
AuDebugOn(!S_ISDIR(dir->i_mode));
151
hinode = au_ii(dir)->ii_hinode + bindex;
152
AuDebugOn(h_dir != hinode->hi_inode);
154
resume_hinotify(hinode);
155
mutex_unlock(&h_dir->i_mutex);
158
struct dentry *au_hdir_lock_rename(struct dentry **h_parents,
159
struct inode **dirs, aufs_bindex_t bindex,
162
struct dentry *h_trap;
163
struct au_hinode *hinode;
165
LKTRTrace("%.*s, %.*s\n",
166
AuDLNPair(h_parents[0]), AuDLNPair(h_parents[1]));
168
h_trap = vfsub_lock_rename(h_parents[0], h_parents[1]);
169
hinode = au_ii(dirs[0])->ii_hinode + bindex;
170
AuDebugOn(h_parents[0]->d_inode != hinode->hi_inode);
171
suspend_hinotify(hinode);
173
hinode = au_ii(dirs[1])->ii_hinode + bindex;
174
AuDebugOn(h_parents[1]->d_inode != hinode->hi_inode);
175
suspend_hinotify(hinode);
181
void au_hdir_unlock_rename(struct dentry **h_parents, struct inode **dirs,
182
aufs_bindex_t bindex, int issamedir)
184
struct au_hinode *hinode;
186
LKTRTrace("%.*s, %.*s\n",
187
AuDLNPair(h_parents[0]), AuDLNPair(h_parents[1]));
189
hinode = au_ii(dirs[0])->ii_hinode + bindex;
190
AuDebugOn(h_parents[0]->d_inode != hinode->hi_inode);
191
resume_hinotify(hinode);
193
hinode = au_ii(dirs[1])->ii_hinode + bindex;
194
AuDebugOn(h_parents[1]->d_inode != hinode->hi_inode);
195
resume_hinotify(hinode);
197
vfsub_unlock_rename(h_parents[0], h_parents[1]);
200
void au_reset_hinotify(struct inode *inode, unsigned int flags)
202
aufs_bindex_t bindex, bend;
204
struct dentry *iwhdentry;
206
LKTRTrace("i%lu, 0x%x\n", inode->i_ino, flags);
208
bend = au_ibend(inode);
209
for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
210
hi = au_h_iptr(inode, bindex);
212
//mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD);
213
iwhdentry = au_hi_wh(inode, bindex);
214
if (unlikely(iwhdentry))
217
au_set_h_iptr(inode, bindex, NULL, 0);
218
au_set_h_iptr(inode, bindex, igrab(hi),
222
//mutex_unlock(&hi->i_mutex);
227
/* ---------------------------------------------------------------------- */
229
/* cf. fsnotify_change() */
230
__u32 vfsub_events_notify_change(struct iattr *ia)
233
const unsigned int amtime = (ATTR_ATIME | ATTR_MTIME);
236
if ((ia->ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
237
|| (ia->ia_valid & amtime) == amtime)
239
if ((ia->ia_valid & ATTR_SIZE)
240
|| (ia->ia_valid & amtime) == ATTR_MTIME)
245
void vfsub_ign_hinode(struct vfsub_args *vargs, __u32 events,
246
struct au_hinode *hinode)
248
struct au_hin_ignore *ign;
252
ign = vargs->ignore + vargs->nignore++;
253
ign->ign_events = events;
254
ign->ign_hinode = hinode;
257
void vfsub_ignore(struct vfsub_args *vargs)
260
struct au_hin_ignore *ign;
265
au_hin_ignore(ign->ign_hinode, ign->ign_events);
270
void vfsub_unignore(struct vfsub_args *vargs)
273
struct au_hin_ignore *ign;
278
au_hin_unignore(ign->ign_hinode, ign->ign_events);
283
/* ---------------------------------------------------------------------- */
285
void au_hin_ignore(struct au_hinode *hinode, __u32 events)
290
LKTRTrace("0x%x\n", events);
291
AuDebugOn(!hinode || !events);
292
if (unlikely(!hinode->hi_inode || !hinode->hi_notify)) {
294
* it may happen by this scenario.
295
* - a file and its parent dir exist on two branches
296
* - a file on the upper branch is opened
297
* - the parent dir and the file are removed by udba
298
* - the parent is re-accessed, and new dentry/inode in
299
* aufs is generated for it, based upon the one on the lower
301
* - the opened file is re-accessed, re-validated, and it may be
302
* re-connected to the new parent dentry
303
* it means the file in aufs cannot get the actual removed
304
* parent dir on the branch.
308
LKTRTrace("hi%lu\n", hinode->hi_inode->i_ino);
310
AuDbg("hi%lu, 0x%x\n", hinode->hi_inode->i_ino, events);
312
AuDebugOn(!hinode->hi_notify);
314
ign = hinode->hi_notify->hin_ignore;
315
for (i = 0; i < au_hin_nignore; i++)
316
if (1U << i & events)
317
atomic_inc_return(ign + i);
320
void au_hin_unignore(struct au_hinode *hinode, __u32 events)
325
LKTRTrace("0x%x\n", events);
326
AuDebugOn(!hinode || !events);
327
if (unlikely(!hinode->hi_inode || !hinode->hi_notify))
329
LKTRTrace("hi%lu\n", hinode->hi_inode->i_ino);
331
AuDbg("hi%lu, 0x%x\n", hinode->hi_inode->i_ino, events);
333
AuDebugOn(!hinode->hi_notify);
335
ign = hinode->hi_notify->hin_ignore;
336
for (i = 0; i < au_hin_nignore; i++)
337
if (1U << i & events)
338
atomic_dec_return(ign + i);
341
/* ---------------------------------------------------------------------- */
343
static char *in_name(u32 mask)
345
#ifdef CONFIG_AUFS_DEBUG
346
#define test_ret(flag) if (mask & flag) return #flag;
350
test_ret(IN_CLOSE_WRITE);
351
test_ret(IN_CLOSE_NOWRITE);
353
test_ret(IN_MOVED_FROM);
354
test_ret(IN_MOVED_TO);
357
test_ret(IN_DELETE_SELF);
358
test_ret(IN_MOVE_SELF);
359
test_ret(IN_UNMOUNT);
360
test_ret(IN_Q_OVERFLOW);
361
test_ret(IN_IGNORED);
369
/* ---------------------------------------------------------------------- */
371
static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
374
struct dentry *dentry, *d, *parent;
377
LKTRTrace("%.*s, dir%lu\n", nlen, name, dir->i_ino);
379
parent = d_find_alias(dir);
384
spin_lock(&dcache_lock);
385
list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
386
LKTRTrace("%.*s\n", AuDLNPair(d));
388
if (dname->len != nlen || memcmp(dname->name, name, nlen))
390
if (!atomic_read(&d->d_count)) {
391
spin_lock(&d->d_lock);
393
spin_unlock(&d->d_lock);
400
spin_unlock(&dcache_lock);
404
di_write_lock_child(dentry);
408
static struct inode *lookup_wlock_by_ino(struct super_block *sb,
409
aufs_bindex_t bindex, ino_t h_ino)
412
struct au_xino_entry xinoe;
415
LKTRTrace("b%d, hi%lu\n", bindex, h_ino);
416
AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
419
err = au_xino_read(sb, bindex, h_ino, &xinoe);
420
if (!err && xinoe.ino)
421
inode = ilookup(sb, xinoe.ino);
424
if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
425
AuWarn("wrong root branch\n");
431
ii_write_lock_child(inode);
433
if (au_iigen(inode) == au_sigen(sb))
434
goto out; /* success */
436
err = au_refresh_hinode_self(inode);
438
goto out; /* success */
440
AuIOErr1("err %d ignored, but ino will be broken\n", err);
441
ii_write_unlock(inode);
450
static int hin_xino(struct inode *inode, struct inode *h_inode)
453
aufs_bindex_t bindex, bend, bfound, bstart;
456
LKTRTrace("i%lu, hi%lu\n", inode->i_ino, h_inode->i_ino);
459
if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
460
AuWarn("branch root dir was changed\n");
465
bend = au_ibend(inode);
466
bstart = au_ibstart(inode);
468
if (bindex == bend) {
469
/* keep this ino in rename case */
473
for (bindex = bstart; bindex <= bend; bindex++) {
474
if (au_h_iptr(inode, bindex) == h_inode) {
482
for (bindex = bstart; bindex <= bend; bindex++) {
483
h_i = au_h_iptr(inode, bindex);
485
err = au_xino_write0(inode->i_sb, bindex, h_i->i_ino,
487
/* ignore this error */
491
/* children inode number will be broken */
498
static int hin_gen_tree(struct dentry *dentry)
500
int err, i, j, ndentry;
501
struct au_dcsub_pages dpages;
502
struct au_dpage *dpage;
503
struct dentry **dentries;
505
LKTRTrace("%.*s\n", AuDLNPair(dentry));
507
err = au_dpages_init(&dpages, GFP_TEMPORARY);
510
err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
514
for (i = 0; i < dpages.ndpage; i++) {
515
dpage = dpages.dpages + i;
516
dentries = dpage->dentries;
517
ndentry = dpage->ndentry;
518
for (j = 0; j < ndentry; j++) {
521
LKTRTrace("%.*s\n", AuDLNPair(d));
528
//reset children xino? cached children only?
529
au_iigen_dec(d->d_inode);
534
au_dpages_free(&dpages);
536
/* discard children */
537
dentry_unhash(dentry);
545
* return 0 if processed.
547
static int hin_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
548
const unsigned int isdir)
554
LKTRTrace("%.*s, i%lu\n", nlen, name, inode->i_ino);
557
if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
558
AuWarn("branch root dir was changed\n");
566
spin_lock(&dcache_lock);
567
list_for_each_entry(d, &inode->i_dentry, d_alias) {
569
if (dname->len != nlen
570
&& memcmp(dname->name, name, nlen))
573
spin_lock(&d->d_lock);
576
spin_unlock(&d->d_lock);
579
spin_unlock(&dcache_lock);
581
au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIRS);
582
d = d_find_alias(inode);
589
if (dname->len == nlen && !memcmp(dname->name, name, nlen))
590
err = hin_gen_tree(d);
599
static int hin_gen_by_name(struct dentry *dentry, const unsigned int isdir)
604
LKTRTrace("%.*s\n", AuDLNPair(dentry));
606
inode = dentry->d_inode;
608
//|| (inode && inode->i_ino == AUFS_ROOT_INO)
610
AuWarn("branch root dir was changed\n");
617
au_digen_dec(dentry);
621
au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIRS);
623
err = hin_gen_tree(dentry);
630
static void hin_attr(struct inode *inode, struct inode *h_inode)
632
struct dentry *h_dentry;
634
LKTRTrace("i%lu, hi%lu\n", inode->i_ino, h_inode->i_ino);
636
if (au_h_iptr(inode, au_ibstart(inode)) != h_inode)
639
h_dentry = d_find_alias(h_inode);
641
au_update_fuse_h_inode(NULL, h_dentry);
646
au_cpup_attr_all(inode);
649
/* ---------------------------------------------------------------------- */
651
/* hinotify job flags */
652
#define AuHinJob_XINO0 1
653
#define AuHinJob_GEN (1 << 1)
654
#define AuHinJob_DIRENT (1 << 2)
655
#define AuHinJob_ATTR (1 << 3)
656
#define AuHinJob_ISDIR (1 << 4)
657
#define AuHinJob_TRYXINO0 (1 << 5)
658
#define AuHinJob_MNTPNT (1 << 6)
659
#define au_ftest_hinjob(flags, name) ((flags) & AuHinJob_##name)
660
#define au_fset_hinjob(flags, name) { (flags) |= AuHinJob_##name; }
661
#define au_fclr_hinjob(flags, name) { (flags) &= ~AuHinJob_##name; }
663
struct hin_job_args {
665
struct inode *inode, *h_inode, *dir, *h_dir;
666
struct dentry *dentry;
671
static int hin_job(struct hin_job_args *a)
673
const unsigned int isdir = au_ftest_hinjob(a->flags, ISDIR);
676
if (au_ftest_hinjob(a->flags, XINO0) && a->inode)
677
hin_xino(a->inode, a->h_inode);
678
/* ignore this error */
680
if (au_ftest_hinjob(a->flags, TRYXINO0)
683
mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
686
AuDbgInode(a->inode);
687
AuDbgInode(a->h_inode);
690
if (!a->h_inode->i_nlink)
691
hin_xino(a->inode, a->h_inode);
692
/* ignore this error */
693
mutex_unlock(&a->h_inode->i_mutex);
696
/* make the generation obsolete */
697
if (au_ftest_hinjob(a->flags, GEN)) {
700
err = hin_gen_by_inode(a->h_name, a->h_nlen, a->inode,
702
if (err && a->dentry)
703
hin_gen_by_name(a->dentry, isdir);
704
/* ignore this error */
707
/* make dir entries obsolete */
708
if (au_ftest_hinjob(a->flags, DIRENT) && a->inode) {
709
struct au_vdir *vdir;
710
IiMustWriteLock(a->inode);
711
vdir = au_ivdir(a->inode);
714
//IMustLock(a->inode);
715
//a->inode->i_version++;
718
/* update the attr */
719
if (au_ftest_hinjob(a->flags, ATTR) && a->inode && a->h_inode)
720
hin_attr(a->inode, a->h_inode);
722
/* can do nothing but warn */
723
if (au_ftest_hinjob(a->flags, MNTPNT)
725
&& d_mountpoint(a->dentry))
726
AuWarn("mount-point %.*s is removed or renamed\n",
727
AuDLNPair(a->dentry));
732
/* ---------------------------------------------------------------------- */
734
enum { CHILD, PARENT };
735
struct postproc_args {
736
struct inode *h_dir, *dir, *h_child_inode;
738
unsigned int flags[2];
739
unsigned int h_child_nlen;
743
static void postproc(void *_args)
745
struct postproc_args *a = _args;
746
struct super_block *sb;
747
aufs_bindex_t bindex, bend, bfound;
751
struct hin_job_args args;
752
struct dentry *dentry;
753
struct au_sbinfo *sbinfo;
756
AuDebugOn(!a->h_dir);
760
LKTRTrace("mask 0x%x %s, i%lu, hi%lu, hci%lu\n",
761
a->mask, in_name(a->mask), a->dir->i_ino, a->h_dir->i_ino,
762
a->h_child_inode ? a->h_child_inode->i_ino : 0);
766
// do not lock here because of d_revalidate() may cause a deadlock.
767
//mutex_lock(&a->dir->i_mutex);
773
si_noflush_write_lock(sb);
775
ii_read_lock_parent(a->dir);
777
bend = au_ibend(a->dir);
778
for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
779
if (au_h_iptr(a->dir, bindex) == a->h_dir) {
783
ii_read_unlock(a->dir);
784
if (unlikely(bfound < 0))
787
xino = !!au_opt_test(au_mntflags(sb), XINO);
789
if (a->h_child_inode)
790
h_ino = a->h_child_inode->i_ino;
794
&& (au_ftest_hinjob(a->flags[CHILD], GEN)
795
|| au_ftest_hinjob(a->flags[CHILD], MNTPNT)))
796
dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
800
inode = dentry->d_inode;
801
if (xino && !inode && h_ino
802
&& (au_ftest_hinjob(a->flags[CHILD], XINO0)
803
|| au_ftest_hinjob(a->flags[CHILD], TRYXINO0)
804
|| au_ftest_hinjob(a->flags[CHILD], GEN)
805
|| au_ftest_hinjob(a->flags[CHILD], ATTR)))
806
inode = lookup_wlock_by_ino(sb, bfound, h_ino);
809
args.flags = a->flags[CHILD];
810
args.dentry = dentry;
812
args.h_inode = a->h_child_inode;
814
args.h_dir = a->h_dir;
815
args.h_name = a->h_child_name;
816
args.h_nlen = a->h_child_nlen;
817
err = hin_job(&args);
819
di_write_unlock(dentry);
822
ii_write_unlock(inode);
827
ii_write_lock_parent(a->dir);
828
args.flags = a->flags[PARENT];
831
args.h_inode = a->h_dir;
836
err = hin_job(&args);
837
ii_write_unlock(a->dir);
842
//mutex_unlock(&a->dir->i_mutex);
843
au_nwt_dec(&sbinfo->si_nowait);
845
iput(a->h_child_inode);
854
#define ilog2(n) ffz(~(n))
857
static void aufs_inotify(struct inotify_watch *watch, u32 wd, u32 mask,
858
u32 cookie, const char *h_child_name,
859
struct inode *h_child_inode)
861
struct au_hinotify *hinotify;
862
struct postproc_args *args;
863
int len, wkq_err, isdir, isroot, wh, idx;
866
unsigned int flags[2];
867
struct super_block *sb;
870
LKTRTrace("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s, hi%lu\n",
871
watch->inode->i_ino, wd, mask, in_name(mask), cookie,
872
h_child_name ? h_child_name : "",
873
h_child_inode ? h_child_inode->i_ino : 0);
874
#if 0 //defined(ForceInotify) || defined(DbgInotify)
875
AuDbg("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s, hi%lu\n",
876
watch->inode->i_ino, wd, mask, in_name(mask), cookie,
877
h_child_name ? h_child_name : "",
878
h_child_inode ? h_child_inode->i_ino : 0);
880
/* if IN_UNMOUNT happens, there must be another bug */
881
if (mask & (IN_IGNORED | IN_UNMOUNT)) {
882
//WARN_ON(watch->inode->i_ino == 15);
883
put_inotify_watch(watch);
888
if (!h_child_name || strcmp(h_child_name, AUFS_XINO_FNAME))
889
AuDbg("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s,"
891
watch->inode->i_ino, wd, mask, in_name(mask), cookie,
892
h_child_name ? h_child_name : "",
893
h_child_inode ? h_child_inode->i_ino : 0);
897
hinotify = container_of(watch, struct au_hinotify, hin_watch);
898
AuDebugOn(!hinotify || !hinotify->hin_aufs_inode);
899
idx = ilog2(mask & IN_ALL_EVENTS);
900
AuDebugOn(au_hin_nignore <= idx);
901
cnt = hinotify->hin_ignore + idx;
902
if (0 <= atomic_dec_return(cnt))
904
atomic_inc_return(cnt);
907
AuDbg("i%lu, wd %d, mask 0x%x %s, cookie 0x%x, hcname %s, hi%lu\n",
908
watch->inode->i_ino, wd, mask, in_name(mask), cookie,
909
h_child_name ? h_child_name : "",
910
h_child_inode ? h_child_inode->i_ino : 0);
913
if (!h_child_name || strcmp(h_child_name, AUFS_XINO_FNAME))
918
dir = igrab(hinotify->hin_aufs_inode);
921
isroot = (dir->i_ino == AUFS_ROOT_INO);
925
len = strlen(h_child_name);
926
if (!memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
927
h_child_name += AUFS_WH_PFX_LEN;
928
len -= AUFS_WH_PFX_LEN;
935
isdir = !!S_ISDIR(h_child_inode->i_mode);
936
flags[PARENT] = AuHinJob_ISDIR;
939
flags[CHILD] = AuHinJob_ISDIR;
940
switch (mask & IN_ALL_EVENTS) {
946
au_fset_hinjob(flags[CHILD], ATTR);
948
au_fset_hinjob(flags[PARENT], ATTR);
951
/* IN_MOVED_FROM is the first event in rename(2) */
954
AuDebugOn(!h_child_name || !h_child_inode);
955
au_fset_hinjob(flags[CHILD], GEN);
956
au_fset_hinjob(flags[CHILD], ATTR);
958
au_fset_hinjob(flags[CHILD], XINO0);
959
au_fset_hinjob(flags[CHILD], MNTPNT);
961
au_fset_hinjob(flags[PARENT], ATTR);
962
au_fset_hinjob(flags[PARENT], DIRENT);
966
AuDebugOn(!h_child_name || !h_child_inode);
967
au_fset_hinjob(flags[PARENT], ATTR);
968
au_fset_hinjob(flags[PARENT], DIRENT);
969
au_fset_hinjob(flags[CHILD], GEN);
971
if (!isdir && h_child_inode->i_nlink > 1)
972
au_fset_hinjob(flags[CHILD], ATTR);
977
* aufs never be able to get this child inode.
978
* revalidation should be in d_revalidate()
979
* by checking i_nlink, i_generation or d_unhashed().
981
AuDebugOn(!h_child_name);
982
au_fset_hinjob(flags[PARENT], ATTR);
983
au_fset_hinjob(flags[PARENT], DIRENT);
984
au_fset_hinjob(flags[CHILD], GEN);
985
au_fset_hinjob(flags[CHILD], TRYXINO0);
986
au_fset_hinjob(flags[CHILD], MNTPNT);
991
au_fset_hinjob(flags[PARENT], GEN);
996
* when an inotify is set to an aufs inode,
997
* such inode can be isolated and this event can be fired
1000
AuDebugOn(h_child_name || h_child_inode);
1001
if (unlikely(isroot)) {
1002
AuWarn("root branch was moved\n");
1009
au_fset_hinjob(flags[PARENT], XINO0);
1010
au_fset_hinjob(flags[PARENT], GEN);
1011
au_fset_hinjob(flags[PARENT], ATTR);
1012
au_fset_hinjob(flags[PARENT], DIRENT);
1013
//au_fset_hinjob(flags[PARENT], MNTPNT);
1021
#if 0 //def DbgInotify
1026
h_child_inode = NULL;
1028
/* iput() and kfree() will be called in postproc() */
1030
* inotify_mutex is already acquired and kmalloc/prune_icache may lock
1031
* iprune_mutex. strange.
1034
args = kmalloc(sizeof(*args) + len + 1, GFP_TEMPORARY);
1036
if (unlikely(!args)) {
1037
AuErr1("no memory\n");
1041
args->flags[PARENT] = flags[PARENT];
1042
args->flags[CHILD] = flags[CHILD];
1045
args->h_dir = igrab(watch->inode);
1047
igrab(h_child_inode);
1048
args->h_child_inode = h_child_inode;
1049
args->h_child_nlen = len;
1053
memcpy(p, h_child_name, len + 1);
1057
au_nwt_inc(&au_sbi(sb)->si_nowait);
1059
wkq_err = au_wkq_nowait(postproc, args, sb, /*dlgt*/0);
1061
if (unlikely(wkq_err)) {
1062
AuErr("wkq %d\n", wkq_err);
1063
au_nwt_dec(&au_sbi(sb)->si_nowait);
1067
static void aufs_inotify_destroy(struct inotify_watch *watch)
1072
static struct inotify_operations aufs_inotify_ops = {
1073
.handle_event = aufs_inotify,
1074
.destroy_watch = aufs_inotify_destroy
1077
/* ---------------------------------------------------------------------- */
1079
static void au_hin_destroy_cache(void)
1081
kmem_cache_destroy(au_cachep[AuCache_HINOTIFY]);
1082
au_cachep[AuCache_HINOTIFY] = NULL;
1085
int __init au_inotify_init(void)
1088
while (1U << au_hin_nignore < AuInMask)
1090
//AuDbg("au_hin_nignore %d\n", au_hin_nignore);
1091
AuDebugOn(au_hin_nignore != 10);
1093
in_handle = ERR_PTR(-ENOMEM);
1094
au_cachep[AuCache_HINOTIFY]
1095
= AuCacheX(au_hinotify, sizeof(atomic_t) * au_hin_nignore);
1096
if (unlikely(!au_cachep[AuCache_HINOTIFY]))
1099
in_handle = inotify_init(&aufs_inotify_ops);
1100
if (!IS_ERR(in_handle))
1103
au_hin_destroy_cache();
1105
AuTraceErrPtr(in_handle);
1106
return PTR_ERR(in_handle);
1109
void au_inotify_fin(void)
1111
inotify_destroy(in_handle);
1112
if (au_cachep[AuCache_HINOTIFY])
1113
au_hin_destroy_cache();