~ubuntu-branches/ubuntu/vivid/linux-ti-omap/vivid

« back to all changes in this revision

Viewing changes to ubuntu/aufs/dinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader, Amit Kucheria
  • Date: 2010-03-23 18:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20100323180512-iavj906ocnphdubp
Tags: 2.6.33-500.3
[ Amit Kucheria ]

* [Config] Fix the debug package name to end in -dbgsym
* SAUCE: Add the ubuntu/ drivers to omap
* SAUCE: Re-export the symbols for aufs
* [Config] Enable AUFS and COMPCACHE

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2009 Junjiro R. Okajima
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 */
 
18
 
 
19
/*
 
20
 * dentry private data
 
21
 */
 
22
 
 
23
#include "aufs.h"
 
24
 
 
25
int au_alloc_dinfo(struct dentry *dentry)
 
26
{
 
27
        struct au_dinfo *dinfo;
 
28
        struct super_block *sb;
 
29
        int nbr;
 
30
 
 
31
        dinfo = au_cache_alloc_dinfo();
 
32
        if (unlikely(!dinfo))
 
33
                goto out;
 
34
 
 
35
        sb = dentry->d_sb;
 
36
        nbr = au_sbend(sb) + 1;
 
37
        if (nbr <= 0)
 
38
                nbr = 1;
 
39
        dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
 
40
        if (unlikely(!dinfo->di_hdentry))
 
41
                goto out_dinfo;
 
42
 
 
43
        atomic_set(&dinfo->di_generation, au_sigen(sb));
 
44
        /* smp_mb(); */ /* atomic_set */
 
45
        au_rw_init_wlock_nested(&dinfo->di_rwsem, AuLsc_DI_CHILD);
 
46
        dinfo->di_bstart = -1;
 
47
        dinfo->di_bend = -1;
 
48
        dinfo->di_bwh = -1;
 
49
        dinfo->di_bdiropq = -1;
 
50
 
 
51
        dentry->d_fsdata = dinfo;
 
52
        dentry->d_op = &aufs_dop;
 
53
        return 0; /* success */
 
54
 
 
55
 out_dinfo:
 
56
        au_cache_free_dinfo(dinfo);
 
57
 out:
 
58
        return -ENOMEM;
 
59
}
 
60
 
 
61
int au_di_realloc(struct au_dinfo *dinfo, int nbr)
 
62
{
 
63
        int err, sz;
 
64
        struct au_hdentry *hdp;
 
65
 
 
66
        AuRwMustWriteLock(&dinfo->di_rwsem);
 
67
 
 
68
        err = -ENOMEM;
 
69
        sz = sizeof(*hdp) * (dinfo->di_bend + 1);
 
70
        if (!sz)
 
71
                sz = sizeof(*hdp);
 
72
        hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
 
73
        if (hdp) {
 
74
                dinfo->di_hdentry = hdp;
 
75
                err = 0;
 
76
        }
 
77
 
 
78
        return err;
 
79
}
 
80
 
 
81
/* ---------------------------------------------------------------------- */
 
82
 
 
83
static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
 
84
{
 
85
        switch (lsc) {
 
86
        case AuLsc_DI_CHILD:
 
87
                ii_write_lock_child(inode);
 
88
                break;
 
89
        case AuLsc_DI_CHILD2:
 
90
                ii_write_lock_child2(inode);
 
91
                break;
 
92
        case AuLsc_DI_CHILD3:
 
93
                ii_write_lock_child3(inode);
 
94
                break;
 
95
        case AuLsc_DI_PARENT:
 
96
                ii_write_lock_parent(inode);
 
97
                break;
 
98
        case AuLsc_DI_PARENT2:
 
99
                ii_write_lock_parent2(inode);
 
100
                break;
 
101
        case AuLsc_DI_PARENT3:
 
102
                ii_write_lock_parent3(inode);
 
103
                break;
 
104
        default:
 
105
                BUG();
 
106
        }
 
107
}
 
108
 
 
109
static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
 
110
{
 
111
        switch (lsc) {
 
112
        case AuLsc_DI_CHILD:
 
113
                ii_read_lock_child(inode);
 
114
                break;
 
115
        case AuLsc_DI_CHILD2:
 
116
                ii_read_lock_child2(inode);
 
117
                break;
 
118
        case AuLsc_DI_CHILD3:
 
119
                ii_read_lock_child3(inode);
 
120
                break;
 
121
        case AuLsc_DI_PARENT:
 
122
                ii_read_lock_parent(inode);
 
123
                break;
 
124
        case AuLsc_DI_PARENT2:
 
125
                ii_read_lock_parent2(inode);
 
126
                break;
 
127
        case AuLsc_DI_PARENT3:
 
128
                ii_read_lock_parent3(inode);
 
129
                break;
 
130
        default:
 
131
                BUG();
 
132
        }
 
133
}
 
134
 
 
135
void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
 
136
{
 
137
        au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
 
138
        if (d->d_inode) {
 
139
                if (au_ftest_lock(flags, IW))
 
140
                        do_ii_write_lock(d->d_inode, lsc);
 
141
                else if (au_ftest_lock(flags, IR))
 
142
                        do_ii_read_lock(d->d_inode, lsc);
 
143
        }
 
144
}
 
145
 
 
146
void di_read_unlock(struct dentry *d, int flags)
 
147
{
 
148
        if (d->d_inode) {
 
149
                if (au_ftest_lock(flags, IW))
 
150
                        ii_write_unlock(d->d_inode);
 
151
                else if (au_ftest_lock(flags, IR))
 
152
                        ii_read_unlock(d->d_inode);
 
153
        }
 
154
        au_rw_read_unlock(&au_di(d)->di_rwsem);
 
155
}
 
156
 
 
157
void di_downgrade_lock(struct dentry *d, int flags)
 
158
{
 
159
        if (d->d_inode && au_ftest_lock(flags, IR))
 
160
                ii_downgrade_lock(d->d_inode);
 
161
        au_rw_dgrade_lock(&au_di(d)->di_rwsem);
 
162
}
 
163
 
 
164
void di_write_lock(struct dentry *d, unsigned int lsc)
 
165
{
 
166
        au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
 
167
        if (d->d_inode)
 
168
                do_ii_write_lock(d->d_inode, lsc);
 
169
}
 
170
 
 
171
void di_write_unlock(struct dentry *d)
 
172
{
 
173
        if (d->d_inode)
 
174
                ii_write_unlock(d->d_inode);
 
175
        au_rw_write_unlock(&au_di(d)->di_rwsem);
 
176
}
 
177
 
 
178
void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
 
179
{
 
180
        AuDebugOn(d1 == d2
 
181
                  || d1->d_inode == d2->d_inode
 
182
                  || d1->d_sb != d2->d_sb);
 
183
 
 
184
        if (isdir && au_test_subdir(d1, d2)) {
 
185
                di_write_lock_child(d1);
 
186
                di_write_lock_child2(d2);
 
187
        } else {
 
188
                /* there should be no races */
 
189
                di_write_lock_child(d2);
 
190
                di_write_lock_child2(d1);
 
191
        }
 
192
}
 
193
 
 
194
void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
 
195
{
 
196
        AuDebugOn(d1 == d2
 
197
                  || d1->d_inode == d2->d_inode
 
198
                  || d1->d_sb != d2->d_sb);
 
199
 
 
200
        if (isdir && au_test_subdir(d1, d2)) {
 
201
                di_write_lock_parent(d1);
 
202
                di_write_lock_parent2(d2);
 
203
        } else {
 
204
                /* there should be no races */
 
205
                di_write_lock_parent(d2);
 
206
                di_write_lock_parent2(d1);
 
207
        }
 
208
}
 
209
 
 
210
void di_write_unlock2(struct dentry *d1, struct dentry *d2)
 
211
{
 
212
        di_write_unlock(d1);
 
213
        if (d1->d_inode == d2->d_inode)
 
214
                au_rw_write_unlock(&au_di(d2)->di_rwsem);
 
215
        else
 
216
                di_write_unlock(d2);
 
217
}
 
218
 
 
219
/* ---------------------------------------------------------------------- */
 
220
 
 
221
struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
 
222
{
 
223
        struct dentry *d;
 
224
 
 
225
        DiMustAnyLock(dentry);
 
226
 
 
227
        if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
 
228
                return NULL;
 
229
        AuDebugOn(bindex < 0);
 
230
        d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
 
231
        AuDebugOn(d && (atomic_read(&d->d_count) <= 0));
 
232
        return d;
 
233
}
 
234
 
 
235
aufs_bindex_t au_dbtail(struct dentry *dentry)
 
236
{
 
237
        aufs_bindex_t bend, bwh;
 
238
 
 
239
        bend = au_dbend(dentry);
 
240
        if (0 <= bend) {
 
241
                bwh = au_dbwh(dentry);
 
242
                if (!bwh)
 
243
                        return bwh;
 
244
                if (0 < bwh && bwh < bend)
 
245
                        return bwh - 1;
 
246
        }
 
247
        return bend;
 
248
}
 
249
 
 
250
aufs_bindex_t au_dbtaildir(struct dentry *dentry)
 
251
{
 
252
        aufs_bindex_t bend, bopq;
 
253
 
 
254
        bend = au_dbtail(dentry);
 
255
        if (0 <= bend) {
 
256
                bopq = au_dbdiropq(dentry);
 
257
                if (0 <= bopq && bopq < bend)
 
258
                        bend = bopq;
 
259
        }
 
260
        return bend;
 
261
}
 
262
 
 
263
/* ---------------------------------------------------------------------- */
 
264
 
 
265
void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
 
266
                   struct dentry *h_dentry)
 
267
{
 
268
        struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
 
269
 
 
270
        DiMustWriteLock(dentry);
 
271
 
 
272
        if (hd->hd_dentry)
 
273
                au_hdput(hd);
 
274
        hd->hd_dentry = h_dentry;
 
275
}
 
276
 
 
277
void au_update_digen(struct dentry *dentry)
 
278
{
 
279
        atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
 
280
        /* smp_mb(); */ /* atomic_set */
 
281
}
 
282
 
 
283
void au_update_dbrange(struct dentry *dentry, int do_put_zero)
 
284
{
 
285
        struct au_dinfo *dinfo;
 
286
        struct dentry *h_d;
 
287
 
 
288
        DiMustWriteLock(dentry);
 
289
 
 
290
        dinfo = au_di(dentry);
 
291
        if (!dinfo || dinfo->di_bstart < 0)
 
292
                return;
 
293
 
 
294
        if (do_put_zero) {
 
295
                aufs_bindex_t bindex, bend;
 
296
 
 
297
                bend = dinfo->di_bend;
 
298
                for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
 
299
                        h_d = dinfo->di_hdentry[0 + bindex].hd_dentry;
 
300
                        if (h_d && !h_d->d_inode)
 
301
                                au_set_h_dptr(dentry, bindex, NULL);
 
302
                }
 
303
        }
 
304
 
 
305
        dinfo->di_bstart = -1;
 
306
        while (++dinfo->di_bstart <= dinfo->di_bend)
 
307
                if (dinfo->di_hdentry[0 + dinfo->di_bstart].hd_dentry)
 
308
                        break;
 
309
        if (dinfo->di_bstart > dinfo->di_bend) {
 
310
                dinfo->di_bstart = -1;
 
311
                dinfo->di_bend = -1;
 
312
                return;
 
313
        }
 
314
 
 
315
        dinfo->di_bend++;
 
316
        while (0 <= --dinfo->di_bend)
 
317
                if (dinfo->di_hdentry[0 + dinfo->di_bend].hd_dentry)
 
318
                        break;
 
319
        AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
 
320
}
 
321
 
 
322
void au_update_dbstart(struct dentry *dentry)
 
323
{
 
324
        aufs_bindex_t bindex, bend;
 
325
        struct dentry *h_dentry;
 
326
 
 
327
        bend = au_dbend(dentry);
 
328
        for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
 
329
                h_dentry = au_h_dptr(dentry, bindex);
 
330
                if (!h_dentry)
 
331
                        continue;
 
332
                if (h_dentry->d_inode) {
 
333
                        au_set_dbstart(dentry, bindex);
 
334
                        return;
 
335
                }
 
336
                au_set_h_dptr(dentry, bindex, NULL);
 
337
        }
 
338
}
 
339
 
 
340
void au_update_dbend(struct dentry *dentry)
 
341
{
 
342
        aufs_bindex_t bindex, bstart;
 
343
        struct dentry *h_dentry;
 
344
 
 
345
        bstart = au_dbstart(dentry);
 
346
        for (bindex = au_dbend(dentry); bindex <= bstart; bindex--) {
 
347
                h_dentry = au_h_dptr(dentry, bindex);
 
348
                if (!h_dentry)
 
349
                        continue;
 
350
                if (h_dentry->d_inode) {
 
351
                        au_set_dbend(dentry, bindex);
 
352
                        return;
 
353
                }
 
354
                au_set_h_dptr(dentry, bindex, NULL);
 
355
        }
 
356
}
 
357
 
 
358
int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
 
359
{
 
360
        aufs_bindex_t bindex, bend;
 
361
 
 
362
        bend = au_dbend(dentry);
 
363
        for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
 
364
                if (au_h_dptr(dentry, bindex) == h_dentry)
 
365
                        return bindex;
 
366
        return -1;
 
367
}