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

« back to all changes in this revision

Viewing changes to fs/aufs25/sbinfo.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
/*
 
2
 * Copyright (C) 2005-2008 Junjiro 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
 * superblock private data
 
21
 *
 
22
 * $Id: sbinfo.c,v 1.3 2008/05/04 23:52:41 sfjro Exp $
 
23
 */
 
24
 
 
25
#include <linux/mnt_namespace.h>
 
26
#include <linux/smp_lock.h>
 
27
#include "aufs.h"
 
28
 
 
29
/*
 
30
 * they are necessary regardless sysfs is disabled.
 
31
 */
 
32
void au_si_free(struct kobject *kobj)
 
33
{
 
34
        struct au_sbinfo *sbinfo;
 
35
        struct super_block *sb;
 
36
 
 
37
        LKTRTrace("kobj %p\n", kobj);
 
38
        sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
 
39
        LKTRTrace("sbinfo %p\n", sbinfo);
 
40
        AuDebugOn(!list_empty(&sbinfo->si_plink));
 
41
 
 
42
        sb = sbinfo->si_sb;
 
43
        if (unlikely(!au_ftest_si(sbinfo, FAILED_INIT))) {
 
44
                au_sbilist_lock();
 
45
                au_sbilist_del(sbinfo);
 
46
                au_sbilist_unlock();
 
47
        }
 
48
 
 
49
        si_write_lock(sb);
 
50
        au_xino_clr(sb);
 
51
        au_br_free(sbinfo);
 
52
        kfree(sbinfo->si_branch);
 
53
        si_write_unlock(sb);
 
54
 
 
55
        //AuDbg("free\n");
 
56
        kfree(sbinfo);
 
57
}
 
58
 
 
59
int au_si_alloc(struct super_block *sb)
 
60
{
 
61
        int err;
 
62
        struct au_sbinfo *sbinfo;
 
63
 
 
64
        AuTraceEnter();
 
65
 
 
66
        err = -ENOMEM;
 
67
        sbinfo = kmalloc(sizeof(*sbinfo), GFP_KERNEL);
 
68
        //if (LktrCond) {kfree(sbinfo); sbinfo = NULL;}
 
69
        if (unlikely(!sbinfo))
 
70
                goto out;
 
71
        sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_KERNEL);
 
72
        //if (LktrCond) {kfree(sbinfo->si_branch); sbinfo->si_branch = NULL;}
 
73
        if (unlikely(!sbinfo->si_branch))
 
74
                goto out_sbinfo;
 
75
 
 
76
        memset(&sbinfo->si_kobj, 0, sizeof(sbinfo->si_kobj));
 
77
        err = sysaufs_si_init(sbinfo);
 
78
        if (unlikely(err))
 
79
                goto out_br;
 
80
 
 
81
        au_rw_init_wlock(&sbinfo->si_rwsem);
 
82
        sbinfo->si_generation = 0;
 
83
        //sbinfo->si_generation = INT_MAX - 2;
 
84
        sbinfo->au_si_status = 0;
 
85
        sbinfo->si_bend = -1;
 
86
        sbinfo->si_last_br_id = 0;
 
87
 
 
88
        sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
 
89
        sbinfo->si_wbr_create = AuWbrCreate_Def;
 
90
        sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + AuWbrCopyup_Def;
 
91
        sbinfo->si_wbr_create_ops = au_wbr_create_ops + AuWbrCreate_Def;
 
92
 
 
93
        sbinfo->si_mntflags = AuOpt_Def;
 
94
 
 
95
        sbinfo->si_xread = NULL;
 
96
        sbinfo->si_xwrite = NULL;
 
97
        sbinfo->si_xib = NULL;
 
98
        mutex_init(&sbinfo->si_xib_mtx);
 
99
        sbinfo->si_xib_buf = NULL;
 
100
        /* leave si_xib_last_pindex and si_xib_next_bit */
 
101
 
 
102
        au_nwt_init(&sbinfo->si_nowait);
 
103
 
 
104
        sbinfo->si_rdcache = AUFS_RDCACHE_DEF * HZ;
 
105
        sbinfo->si_dirwh = AUFS_DIRWH_DEF;
 
106
 
 
107
        spin_lock_init(&sbinfo->si_plink_lock);
 
108
        INIT_LIST_HEAD(&sbinfo->si_plink);
 
109
 
 
110
        /* leave other members for sysaufs and si_mnt. */
 
111
 
 
112
        au_robr_lvma_init(sbinfo);
 
113
        sb->s_fs_info = sbinfo;
 
114
        //sysaufs_si_get(sb);
 
115
 
 
116
        au_debug_sbinfo_init(sbinfo);
 
117
        return 0; /* success */
 
118
 
 
119
 out_br:
 
120
        kfree(sbinfo->si_branch);
 
121
 out_sbinfo:
 
122
        kfree(sbinfo);
 
123
 out:
 
124
        AuTraceErr(err);
 
125
        return err;
 
126
}
 
127
 
 
128
/* ---------------------------------------------------------------------- */
 
129
 
 
130
struct au_branch *au_sbr(struct super_block *sb, aufs_bindex_t bindex)
 
131
{
 
132
        struct au_branch *br;
 
133
 
 
134
        SiMustAnyLock(sb);
 
135
        AuDebugOn(bindex < 0 || au_sbend(sb) < bindex);
 
136
        br = au_sbi(sb)->si_branch[0 + bindex];
 
137
        AuDebugOn(!br);
 
138
        return br;
 
139
}
 
140
 
 
141
au_gen_t au_sigen_inc(struct super_block *sb)
 
142
{
 
143
        au_gen_t gen;
 
144
 
 
145
        SiMustWriteLock(sb);
 
146
        gen = ++au_sbi(sb)->si_generation;
 
147
        au_update_digen(sb->s_root);
 
148
        au_update_iigen(sb->s_root->d_inode);
 
149
        sb->s_root->d_inode->i_version++;
 
150
        return gen;
 
151
}
 
152
 
 
153
int au_find_bindex(struct super_block *sb, struct au_branch *br)
 
154
{
 
155
        aufs_bindex_t bindex, bend;
 
156
 
 
157
        bend = au_sbend(sb);
 
158
        for (bindex = 0; bindex <= bend; bindex++)
 
159
                if (au_sbr(sb, bindex) == br)
 
160
                        return bindex;
 
161
        return -1;
 
162
}
 
163
 
 
164
/* ---------------------------------------------------------------------- */
 
165
 
 
166
/* dentry and super_block lock. call at entry point */
 
167
void aufs_read_lock(struct dentry *dentry, int flags)
 
168
{
 
169
        si_read_lock(dentry->d_sb, flags);
 
170
        if (au_ftest_lock(flags, DW))
 
171
                di_write_lock_child(dentry);
 
172
        else
 
173
                di_read_lock_child(dentry, flags);
 
174
}
 
175
 
 
176
void aufs_read_unlock(struct dentry *dentry, int flags)
 
177
{
 
178
        if (au_ftest_lock(flags, DW))
 
179
                di_write_unlock(dentry);
 
180
        else
 
181
                di_read_unlock(dentry, flags);
 
182
        si_read_unlock(dentry->d_sb);
 
183
}
 
184
 
 
185
void aufs_write_lock(struct dentry *dentry)
 
186
{
 
187
        si_write_lock(dentry->d_sb);
 
188
        di_write_lock_child(dentry);
 
189
}
 
190
 
 
191
void aufs_write_unlock(struct dentry *dentry)
 
192
{
 
193
        di_write_unlock(dentry);
 
194
        si_write_unlock(dentry->d_sb);
 
195
}
 
196
 
 
197
void aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
 
198
{
 
199
        AuDebugOn(d1 == d2 || d1->d_sb != d2->d_sb);
 
200
        si_read_lock(d1->d_sb, flags);
 
201
        di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
 
202
}
 
203
 
 
204
void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
 
205
{
 
206
        AuDebugOn(d1 == d2 || d1->d_sb != d2->d_sb);
 
207
        di_write_unlock2(d1, d2);
 
208
        si_read_unlock(d1->d_sb);
 
209
}
 
210
 
 
211
/* ---------------------------------------------------------------------- */
 
212
 
 
213
aufs_bindex_t au_new_br_id(struct super_block *sb)
 
214
{
 
215
        aufs_bindex_t br_id;
 
216
        struct au_sbinfo *sbinfo;
 
217
 
 
218
        AuTraceEnter();
 
219
        SiMustWriteLock(sb);
 
220
 
 
221
        sbinfo = au_sbi(sb);
 
222
        while (1) {
 
223
                br_id = ++sbinfo->si_last_br_id;
 
224
                if (br_id && au_br_index(sb, br_id) < 0)
 
225
                        return br_id;
 
226
        }
 
227
}
 
228
 
 
229
//todo: dirty
 
230
struct vfsmount *au_mntcache_get(struct super_block *sb)
 
231
{
 
232
        struct au_sbinfo *sbinfo;
 
233
        struct mnt_namespace *ns;
 
234
        struct vfsmount *pos;
 
235
 
 
236
        AuTraceEnter();
 
237
        //todo: check lock again
 
238
 
 
239
        sbinfo = au_sbi(sb);
 
240
        if (sbinfo->si_mntcache)
 
241
                goto out;
 
242
 
 
243
        /*  update si_mnt without sbinfo write lock */
 
244
        //todo: big kernel lock?
 
245
        /* vfsmount_lock is not exported */
 
246
        //root_mnt = current->fs->root.mnt;
 
247
        /* no get/put */
 
248
        AuDebugOn(!current->nsproxy);
 
249
        ns = current->nsproxy->mnt_ns;
 
250
        AuDebugOn(!ns);
 
251
        list_for_each_entry(pos, &ns->list, mnt_list)
 
252
                if (pos->mnt_sb == sb) {
 
253
                        sbinfo->si_mntcache = pos;
 
254
                        smp_mb();
 
255
                        break;
 
256
                }
 
257
 
 
258
 out:
 
259
        AuDebugOn(!sbinfo->si_mntcache);
 
260
        return mntget(sbinfo->si_mntcache);
 
261
}