16
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
/* $Id: iinfo.c,v 1.47 2008/02/18 04:37:44 sfjro Exp $ */
22
* $Id: iinfo.c,v 1.49 2008/04/13 23:42:55 sfjro Exp $
23
struct aufs_iinfo *itoii(struct inode *inode)
27
struct au_iinfo *au_ii(struct inode *inode)
25
struct aufs_iinfo *iinfo;
29
struct au_iinfo *iinfo;
27
31
iinfo = &(container_of(inode, struct aufs_icntnr, vfs_inode)->iinfo);
28
32
/* bad_inode case */
29
33
if (unlikely(!iinfo->ii_hinode))
31
35
AuDebugOn(!iinfo->ii_hinode
32
/* || stosi(inode->i_sb)->si_bend < iinfo->ii_bend */
36
/* || au_sbi(inode->i_sb)->si_bend < iinfo->ii_bend */
33
37
|| iinfo->ii_bend < iinfo->ii_bstart);
37
aufs_bindex_t ibstart(struct inode *inode)
40
return itoii(inode)->ii_bstart;
43
aufs_bindex_t ibend(struct inode *inode)
46
return itoii(inode)->ii_bend;
49
struct aufs_vdir *ivdir(struct inode *inode)
52
AuDebugOn(!S_ISDIR(inode->i_mode));
53
return itoii(inode)->ii_vdir;
56
struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
58
struct aufs_hinode *hinode;
62
hinode = itoii(inode)->ii_hinode + bindex;
63
return hinode->hi_whdentry;
66
41
struct inode *au_h_iptr_i(struct inode *inode, aufs_bindex_t bindex)
68
43
struct inode *hidden_inode;
70
45
IiMustAnyLock(inode);
71
AuDebugOn(bindex < 0 || ibend(inode) < bindex);
72
hidden_inode = itoii(inode)->ii_hinode[0 + bindex].hi_inode;
46
AuDebugOn(bindex < 0 || au_ibend(inode) < bindex);
47
hidden_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
73
48
AuDebugOn(hidden_inode && atomic_read(&hidden_inode->i_count) <= 0);
74
49
return hidden_inode;
77
struct inode *au_h_iptr(struct inode *inode)
79
return au_h_iptr_i(inode, ibstart(inode));
82
aufs_bindex_t itoid_index(struct inode *inode, aufs_bindex_t bindex)
52
aufs_bindex_t au_ii_br_id(struct inode *inode, aufs_bindex_t bindex)
84
54
IiMustAnyLock(inode);
85
55
AuDebugOn(bindex < 0
86
|| ibend(inode) < bindex
87
|| !itoii(inode)->ii_hinode[0 + bindex].hi_inode);
88
return itoii(inode)->ii_hinode[0 + bindex].hi_id;
56
|| au_ibend(inode) < bindex
57
|| !au_ii(inode)->ii_hinode[0 + bindex].hi_inode);
58
return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
92
void set_ibstart(struct inode *inode, aufs_bindex_t bindex)
62
void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
94
struct aufs_iinfo *iinfo = itoii(inode);
64
struct au_iinfo *iinfo = au_ii(inode);
95
65
struct inode *h_inode;
97
67
IiMustWriteLock(inode);
98
AuDebugOn(sbend(inode->i_sb) < bindex);
68
AuDebugOn(au_sbend(inode->i_sb) < bindex);
99
69
iinfo->ii_bstart = bindex;
100
70
h_inode = iinfo->ii_hinode[bindex + 0].hi_inode;
102
72
au_cpup_igen(inode, h_inode);
105
void set_ibend(struct inode *inode, aufs_bindex_t bindex)
107
IiMustWriteLock(inode);
108
AuDebugOn(sbend(inode->i_sb) < bindex
109
|| bindex < ibstart(inode));
110
itoii(inode)->ii_bend = bindex;
113
void set_ivdir(struct inode *inode, struct aufs_vdir *vdir)
115
IiMustWriteLock(inode);
116
AuDebugOn(!S_ISDIR(inode->i_mode)
117
|| (itoii(inode)->ii_vdir && vdir));
118
itoii(inode)->ii_vdir = vdir;
121
void aufs_hiput(struct aufs_hinode *hinode)
124
dput(hinode->hi_whdentry);
125
iput(hinode->hi_inode);
128
75
unsigned int au_hi_flags(struct inode *inode, int isdir)
130
77
unsigned int flags;
131
struct super_block *sb = inode->i_sb;
132
struct aufs_sbinfo *sbinfo = stosi(sb);
78
const unsigned int mnt_flags = au_mntflags(inode->i_sb);
135
if (AuFlag(sbinfo, f_xino) != AuXino_NONE)
81
if (au_opt_test(mnt_flags, XINO))
136
82
au_fset_hi(flags, XINO);
137
if (unlikely(isdir && au_flag_test_udba_inotify(sb)))
83
if (unlikely(isdir && au_opt_test(mnt_flags, UDBA_INOTIFY)))
138
84
au_fset_hi(flags, NOTIFY);
142
struct aufs_hinode *itohi(struct inode *inode, aufs_bindex_t bindex)
144
//todo: this lock check causes some unnecessary locks in callers.
145
IiMustAnyLock(inode);
146
return itoii(inode)->ii_hinode + bindex;
149
void set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
150
struct inode *h_inode, unsigned int flags)
152
struct aufs_hinode *hinode;
88
void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
89
struct inode *h_inode, unsigned int flags)
91
struct au_hinode *hinode;
154
struct aufs_iinfo *iinfo = itoii(inode);
93
struct au_iinfo *iinfo = au_ii(inode);
156
95
LKTRTrace("i%lu, b%d, hi%lu, flags 0x%x\n",
157
96
inode->i_ino, bindex, h_inode ? h_inode->i_ino : 0, flags);
158
97
IiMustWriteLock(inode);
159
98
hinode = iinfo->ii_hinode + bindex;
160
99
hi = hinode->hi_inode;
161
AuDebugOn(bindex < ibstart(inode) || ibend(inode) < bindex
100
AuDebugOn(bindex < au_ibstart(inode) || au_ibend(inode) < bindex
162
101
|| (h_inode && atomic_read(&h_inode->i_count) <= 0)
163
102
|| (h_inode && hi));
166
105
#if 0 // remove this
167
106
if (!hi->i_nlink && au_ftest_hi(flags, XINO)) {
168
AuDebugOn(sbr_id(sb, bindex) != hinode->hi_id);
169
xino_write0(inode->i_sb, bindex, hi->i_ino, 0);
107
AuDebugOn(au_sbr_id(sb, bindex) != hinode->hi_id);
108
au_xino_write0(inode->i_sb, bindex, hi->i_ino, 0);
170
109
/* ignore this error */
171
110
/* bad action? */
176
115
hinode->hi_inode = h_inode;
181
120
if (bindex == iinfo->ii_bstart)
182
121
au_cpup_igen(inode, h_inode);
183
hinode->hi_id = sbr_id(sb, bindex);
122
hinode->hi_id = au_sbr_id(sb, bindex);
184
123
if (au_ftest_hi(flags, XINO)) {
185
struct xino_entry xinoe = {
124
struct au_xino_entry xinoe = {
186
125
.ino = inode->i_ino,
187
126
//.h_gen = h_inode->i_generation
189
err = xino_write(sb, bindex, h_inode->i_ino, &xinoe);
192
AuIOErr1("failed xino_write() %d,"
195
AuFlagSet(stosi(sb), f_xino, AuXino_NONE);
128
err = au_xino_write(sb, bindex, h_inode->i_ino, &xinoe);
130
AuIOErr1("failed au_xino_write() %d\n", err);
198
#ifdef CONFIG_AUFS_HINOTIFY
199
133
if (unlikely(au_ftest_hi(flags, NOTIFY)
200
&& br_hinotifyable(sbr_perm(sb, bindex)))) {
134
&& au_br_hinotifyable(au_sbr_perm(sb, bindex)))) {
201
135
err = au_hin_alloc(hinode, inode, h_inode);
202
136
if (unlikely(err))
203
137
AuIOErr1("au_hin_alloc() %d\n", err);
205
AuDebugOn(!hinode->hi_notify);
211
void set_hi_wh(struct inode *inode, aufs_bindex_t bindex, struct dentry *h_wh)
142
void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
213
struct aufs_hinode *hinode;
145
struct au_hinode *hinode;
215
147
IiMustWriteLock(inode);
216
hinode = itoii(inode)->ii_hinode + bindex;
148
hinode = au_ii(inode)->ii_hinode + bindex;
217
149
AuDebugOn(hinode->hi_whdentry);
218
150
hinode->hi_whdentry = h_wh;