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

« back to all changes in this revision

Viewing changes to fs/aufs/iinfo.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
1
/*
2
 
 * Copyright (C) 2005, 2006, 2007, 2008 Junjiro Okajima
 
2
 * Copyright (C) 2005-2008 Junjiro Okajima
3
3
 *
4
4
 * This program, aufs is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
16
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 */
18
18
 
19
 
/* $Id: iinfo.c,v 1.47 2008/02/18 04:37:44 sfjro Exp $ */
 
19
/*
 
20
 * inode private data
 
21
 *
 
22
 * $Id: iinfo.c,v 1.49 2008/04/13 23:42:55 sfjro Exp $
 
23
 */
20
24
 
21
25
#include "aufs.h"
22
26
 
23
 
struct aufs_iinfo *itoii(struct inode *inode)
 
27
struct au_iinfo *au_ii(struct inode *inode)
24
28
{
25
 
        struct aufs_iinfo *iinfo;
 
29
        struct au_iinfo *iinfo;
26
30
 
27
31
        iinfo = &(container_of(inode, struct aufs_icntnr, vfs_inode)->iinfo);
28
32
        /* bad_inode case */
29
33
        if (unlikely(!iinfo->ii_hinode))
30
34
                return NULL;
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);
34
38
        return iinfo;
35
39
}
36
40
 
37
 
aufs_bindex_t ibstart(struct inode *inode)
38
 
{
39
 
        IiMustAnyLock(inode);
40
 
        return itoii(inode)->ii_bstart;
41
 
}
42
 
 
43
 
aufs_bindex_t ibend(struct inode *inode)
44
 
{
45
 
        IiMustAnyLock(inode);
46
 
        return itoii(inode)->ii_bend;
47
 
}
48
 
 
49
 
struct aufs_vdir *ivdir(struct inode *inode)
50
 
{
51
 
        IiMustAnyLock(inode);
52
 
        AuDebugOn(!S_ISDIR(inode->i_mode));
53
 
        return itoii(inode)->ii_vdir;
54
 
}
55
 
 
56
 
struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
57
 
{
58
 
        struct aufs_hinode *hinode;
59
 
 
60
 
        IiMustAnyLock(inode);
61
 
 
62
 
        hinode = itoii(inode)->ii_hinode + bindex;
63
 
        return hinode->hi_whdentry;
64
 
}
65
 
 
66
41
struct inode *au_h_iptr_i(struct inode *inode, aufs_bindex_t bindex)
67
42
{
68
43
        struct inode *hidden_inode;
69
44
 
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;
75
50
}
76
51
 
77
 
struct inode *au_h_iptr(struct inode *inode)
78
 
{
79
 
        return au_h_iptr_i(inode, ibstart(inode));
80
 
}
81
 
 
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)
83
53
{
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;
89
59
}
90
60
 
91
61
// hard/soft set
92
 
void set_ibstart(struct inode *inode, aufs_bindex_t bindex)
 
62
void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
93
63
{
94
 
        struct aufs_iinfo *iinfo = itoii(inode);
 
64
        struct au_iinfo *iinfo = au_ii(inode);
95
65
        struct inode *h_inode;
96
66
 
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;
101
71
        if (h_inode)
102
72
                au_cpup_igen(inode, h_inode);
103
73
}
104
74
 
105
 
void set_ibend(struct inode *inode, aufs_bindex_t bindex)
106
 
{
107
 
        IiMustWriteLock(inode);
108
 
        AuDebugOn(sbend(inode->i_sb) < bindex
109
 
                  || bindex < ibstart(inode));
110
 
        itoii(inode)->ii_bend = bindex;
111
 
}
112
 
 
113
 
void set_ivdir(struct inode *inode, struct aufs_vdir *vdir)
114
 
{
115
 
        IiMustWriteLock(inode);
116
 
        AuDebugOn(!S_ISDIR(inode->i_mode)
117
 
                  || (itoii(inode)->ii_vdir && vdir));
118
 
        itoii(inode)->ii_vdir = vdir;
119
 
}
120
 
 
121
 
void aufs_hiput(struct aufs_hinode *hinode)
122
 
{
123
 
        au_hin_free(hinode);
124
 
        dput(hinode->hi_whdentry);
125
 
        iput(hinode->hi_inode);
126
 
}
127
 
 
128
75
unsigned int au_hi_flags(struct inode *inode, int isdir)
129
76
{
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);
133
79
 
134
80
        flags = 0;
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);
139
85
        return flags;
140
86
}
141
87
 
142
 
struct aufs_hinode *itohi(struct inode *inode, aufs_bindex_t bindex)
143
 
{
144
 
        //todo: this lock check causes some unnecessary locks in callers.
145
 
        IiMustAnyLock(inode);
146
 
        return itoii(inode)->ii_hinode + bindex;
147
 
}
148
 
 
149
 
void set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
150
 
                struct inode *h_inode, unsigned int flags)
151
 
{
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)
 
90
{
 
91
        struct au_hinode *hinode;
153
92
        struct inode *hi;
154
 
        struct aufs_iinfo *iinfo = itoii(inode);
 
93
        struct au_iinfo *iinfo = au_ii(inode);
155
94
 
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));
164
103
 
165
104
        if (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? */
172
111
                }
173
112
#endif
174
 
                aufs_hiput(hinode);
 
113
                au_hiput(hinode);
175
114
        }
176
115
        hinode->hi_inode = h_inode;
177
116
        if (h_inode) {
180
119
 
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
188
127
                        };
189
 
                        err = xino_write(sb, bindex, h_inode->i_ino, &xinoe);
190
 
                        if (unlikely(err)) {
191
 
                                /* bad action? */
192
 
                                AuIOErr1("failed xino_write() %d,"
193
 
                                         " force noxino\n",
194
 
                                         err);
195
 
                                AuFlagSet(stosi(sb), f_xino, AuXino_NONE);
196
 
                        }
 
128
                        err = au_xino_write(sb, bindex, h_inode->i_ino, &xinoe);
 
129
                        if (unlikely(err))
 
130
                                AuIOErr1("failed au_xino_write() %d\n", err);
197
131
                }
198
 
#ifdef CONFIG_AUFS_HINOTIFY
 
132
 
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);
204
 
                        else
205
 
                                AuDebugOn(!hinode->hi_notify);
206
138
                }
207
 
#endif
208
139
        }
209
140
}
210
141
 
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,
 
143
                  struct dentry *h_wh)
212
144
{
213
 
        struct aufs_hinode *hinode;
 
145
        struct au_hinode *hinode;
214
146
 
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;
219
151
}
222
154
{
223
155
        //IiMustWriteLock(inode);
224
156
        AuDebugOn(!inode->i_sb);
225
 
        atomic_set(&itoii(inode)->ii_generation, au_sigen(inode->i_sb));
 
157
        atomic_set(&au_ii(inode)->ii_generation, au_sigen(inode->i_sb));
226
158
        //smp_mb(); /* atomic_set */
227
159
}
228
160
 
229
161
/* it may be called at remount time, too */
230
162
void au_update_brange(struct inode *inode, int do_put_zero)
231
163
{
232
 
        struct aufs_iinfo *iinfo;
 
164
        struct au_iinfo *iinfo;
233
165
 
234
166
        LKTRTrace("i%lu, %d\n", inode->i_ino, do_put_zero);
235
167
        IiMustWriteLock(inode);
236
168
 
237
 
        iinfo = itoii(inode);
 
169
        iinfo = au_ii(inode);
238
170
        if (unlikely(!iinfo) || iinfo->ii_bstart < 0)
239
171
                return;
240
172
 
245
177
                        struct inode *h_i;
246
178
                        h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
247
179
                        if (h_i && !h_i->i_nlink)
248
 
                                set_h_iptr(inode, bindex, NULL, 0);
 
180
                                au_set_h_iptr(inode, bindex, NULL, 0);
249
181
                }
250
182
        }
251
183
 
270
202
 
271
203
int au_iinfo_init(struct inode *inode)
272
204
{
273
 
        struct aufs_iinfo *iinfo;
 
205
        struct au_iinfo *iinfo;
274
206
        struct super_block *sb;
275
207
        int nbr, i;
276
208
 
278
210
        AuDebugOn(!sb);
279
211
        iinfo = &(container_of(inode, struct aufs_icntnr, vfs_inode)->iinfo);
280
212
        AuDebugOn(iinfo->ii_hinode);
281
 
        nbr = sbend(sb) + 1;
 
213
        nbr = au_sbend(sb) + 1;
282
214
        if (unlikely(nbr <= 0))
283
215
                nbr = 1;
284
216
        iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_KERNEL);
288
220
                        iinfo->ii_hinode[i].hi_id = -1;
289
221
                atomic_set(&iinfo->ii_generation, au_sigen(sb));
290
222
                //smp_mb(); /* atomic_set */
291
 
                rw_init_nolock(&iinfo->ii_rwsem);
 
223
                au_rw_init_nolock(&iinfo->ii_rwsem);
292
224
                iinfo->ii_bstart = -1;
293
225
                iinfo->ii_bend = -1;
294
226
                iinfo->ii_vdir = NULL;
297
229
        return -ENOMEM;
298
230
}
299
231
 
300
 
static int au_iinfo_write0(struct super_block *sb, struct aufs_hinode *hinode,
 
232
static int au_iinfo_write0(struct super_block *sb, struct au_hinode *hinode,
301
233
                           ino_t ino)
302
234
{
303
235
        int err, locked;
305
237
 
306
238
        err = 0;
307
239
        locked = si_read_trylock(sb, !AuLock_FLUSH); // crucio!
308
 
        bindex = find_brindex(sb, hinode->hi_id);
 
240
        bindex = au_br_index(sb, hinode->hi_id);
309
241
        if (bindex >= 0)
310
 
                err = xino_write0(sb, bindex, hinode->hi_inode->i_ino, ino);
 
242
                err = au_xino_write0(sb, bindex, hinode->hi_inode->i_ino, ino);
311
243
        /* error action? */
312
244
        if (locked)
313
245
                si_read_unlock(sb);
316
248
 
317
249
void au_iinfo_fin(struct inode *inode)
318
250
{
319
 
        struct aufs_iinfo *iinfo;
 
251
        struct au_iinfo *iinfo;
320
252
        aufs_bindex_t bend;
321
 
        struct aufs_hinode *hi;
 
253
        struct au_hinode *hi;
322
254
        struct super_block *sb;
323
255
        int unlinked;
324
256
        ino_t ino;
325
257
 
326
 
        iinfo = itoii(inode);
 
258
        iinfo = au_ii(inode);
327
259
        /* bad_inode case */
328
260
        if (unlikely(!iinfo))
329
261
                return;
346
278
                                        /* ignore this error */
347
279
                                        ino = 0;
348
280
                                }
349
 
                                aufs_hiput(hi);
 
281
                                au_hiput(hi);
350
282
                        }
351
283
                        hi++;
352
284
                }