2
* Copyright (C) 2005, 2006, 2007 Junjiro Okajima
2
* Copyright (C) 2005-2008 Junjiro Okajima
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
19
/* $Id: finfo.c,v 1.31 2007/10/30 12:52:28 sfjro Exp $ */
22
* $Id: finfo.c,v 1.33 2008/04/13 23:41:21 sfjro Exp $
23
struct aufs_finfo *ftofi(struct file *file)
27
struct au_finfo *au_fi(struct file *file)
25
struct aufs_finfo *finfo = file->private_data;
29
struct au_finfo *finfo = file->private_data;
27
31
|| !finfo->fi_hfile
28
32
|| (0 < finfo->fi_bend
29
&& (/* stosi(file->f_dentry->d_sb)->si_bend
33
&& (/* au_sbi(file->f_dentry->d_sb)->si_bend
31
35
|| */ finfo->fi_bend < finfo->fi_bstart)));
36
aufs_bindex_t fbstart(struct file *file)
39
return ftofi(file)->fi_bstart;
42
aufs_bindex_t fbend(struct file *file)
45
return ftofi(file)->fi_bend;
48
struct aufs_vdir *fvdir_cache(struct file *file)
51
return ftofi(file)->fi_vdir_cache;
54
struct aufs_branch *ftobr(struct file *file, aufs_bindex_t bindex)
56
struct aufs_finfo *finfo = ftofi(file);
57
struct aufs_hfile *hf;
39
struct au_branch *au_fbr(struct file *file, aufs_bindex_t bindex)
41
struct au_finfo *finfo = au_fi(file);
59
44
FiMustAnyLock(file);
62
47
|| bindex < finfo->fi_bstart
63
48
|| finfo->fi_bend < bindex);
64
49
hf = finfo->fi_hfile + bindex;
65
AuDebugOn(hf->hf_br && br_count(hf->hf_br) <= 0);
50
AuDebugOn(hf->hf_br && au_br_count(hf->hf_br) <= 0);
69
54
struct file *au_h_fptr_i(struct file *file, aufs_bindex_t bindex)
71
struct aufs_finfo *finfo = ftofi(file);
72
struct aufs_hfile *hf;
56
struct au_finfo *finfo = au_fi(file);
74
59
FiMustAnyLock(file);
79
64
hf = finfo->fi_hfile + bindex;
80
65
AuDebugOn(hf->hf_file
81
66
&& file_count(hf->hf_file) <= 0
82
&& br_count(hf->hf_br) <= 0);
67
&& au_br_count(hf->hf_br) <= 0);
83
68
return hf->hf_file;
86
struct file *au_h_fptr(struct file *file)
88
return au_h_fptr_i(file, fbstart(file));
91
void set_fbstart(struct file *file, aufs_bindex_t bindex)
93
FiMustWriteLock(file);
94
AuDebugOn(sbend(file->f_dentry->d_sb) < bindex);
95
ftofi(file)->fi_bstart = bindex;
98
void set_fbend(struct file *file, aufs_bindex_t bindex)
100
FiMustWriteLock(file);
101
AuDebugOn(sbend(file->f_dentry->d_sb) < bindex
102
|| bindex < fbstart(file));
103
ftofi(file)->fi_bend = bindex;
106
void set_fvdir_cache(struct file *file, struct aufs_vdir *vdir_cache)
108
FiMustWriteLock(file);
109
AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode)
110
|| (ftofi(file)->fi_vdir_cache && vdir_cache));
111
ftofi(file)->fi_vdir_cache = vdir_cache;
114
void au_hfput(struct aufs_hfile *hf)
71
void au_hfput(struct au_hfile *hf)
116
73
if (hf->hf_file->f_mode & FMODE_EXEC)
117
74
au_allow_write_access(hf->hf_file);
118
75
fput(hf->hf_file);
119
76
hf->hf_file = NULL;
120
77
AuDebugOn(!hf->hf_br);
125
void set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
82
void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
127
struct aufs_finfo *finfo = ftofi(file);
128
struct aufs_hfile *hf;
84
struct au_finfo *finfo = au_fi(file);
130
87
FiMustWriteLock(file);
141
98
hf->hf_file = val;
142
hf->hf_br = stobr(file->f_dentry->d_sb, bindex);
99
hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
146
void au_update_figen(struct file *file)
148
atomic_set(&ftofi(file)->fi_generation, au_digen(file->f_dentry));
149
//smp_mb(); /* atomic_set */
152
103
void au_finfo_fin(struct file *file)
154
struct aufs_finfo *finfo;
105
struct au_finfo *finfo;
155
106
struct dentry *dentry;
156
107
aufs_bindex_t bindex, bend;
160
111
SiMustAnyLock(dentry->d_sb);
162
113
fi_write_lock(file);
164
bindex = fbstart(file);
114
bend = au_fbend(file);
115
bindex = au_fbstart(file);
166
117
for (; bindex <= bend; bindex++)
167
set_h_fptr(file, bindex, NULL);
118
au_set_h_fptr(file, bindex, NULL);
170
121
#ifdef CONFIG_AUFS_DEBUG
171
122
if (finfo->fi_bstart >= 0) {
123
bend = au_fbend(file);
173
124
for (bindex = finfo->fi_bstart; bindex <= bend; bindex++) {
174
struct aufs_hfile *hf;
175
126
hf = finfo->fi_hfile + bindex;
176
127
AuDebugOn(hf->hf_file || hf->hf_br);
200
151
finfo = au_cache_alloc_finfo();
202
finfo->fi_hfile = kcalloc(sbend(dentry->d_sb) + 1,
153
finfo->fi_hfile = kcalloc(au_sbend(dentry->d_sb) + 1,
203
154
sizeof(*finfo->fi_hfile), GFP_KERNEL);
204
155
if (finfo->fi_hfile) {
205
rw_init_wlock(&finfo->fi_rwsem);
156
au_rw_init_wlock(&finfo->fi_rwsem);
206
157
finfo->fi_bstart = -1;
207
158
finfo->fi_bend = -1;
208
159
atomic_set(&finfo->fi_generation, au_digen(dentry));