2 * Copyright (C) 2005-2013 Junjiro R. Okajima
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.
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.
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
25 void au_hfput(struct au_hfile *hf, struct file *file)
27 /* todo: direct access f_flags */
28 if (vfsub_file_flags(file) & __FMODE_EXEC)
29 allow_write_access(hf->hf_file);
32 atomic_dec(&hf->hf_br->br_count);
36 void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
38 struct au_finfo *finfo = au_fi(file);
40 struct au_fidir *fidir;
42 fidir = finfo->fi_hdir;
44 AuDebugOn(finfo->fi_btop != bindex);
47 hf = fidir->fd_hfile + bindex;
49 if (hf && hf->hf_file)
52 FiMustWriteLock(file);
54 hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
58 void au_update_figen(struct file *file)
60 atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
61 /* smp_mb(); */ /* atomic_set */
64 /* ---------------------------------------------------------------------- */
66 struct au_fidir *au_fidir_alloc(struct super_block *sb)
68 struct au_fidir *fidir;
71 nbr = au_sbend(sb) + 1;
73 nbr = 2; /* initial allocate for 2 branches */
74 fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
78 fidir->fd_vdir_cache = NULL;
84 int au_fidir_realloc(struct au_finfo *finfo, int nbr)
87 struct au_fidir *fidir, *p;
89 AuRwMustWriteLock(&finfo->fi_rwsem);
90 fidir = finfo->fi_hdir;
94 p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
105 /* ---------------------------------------------------------------------- */
107 void au_finfo_fin(struct file *file)
109 struct au_finfo *finfo;
111 au_nfiles_dec(file->f_dentry->d_sb);
114 AuDebugOn(finfo->fi_hdir);
115 AuRwDestroy(&finfo->fi_rwsem);
116 au_cache_free_finfo(finfo);
119 void au_fi_init_once(void *_finfo)
121 struct au_finfo *finfo = _finfo;
122 static struct lock_class_key aufs_fi;
124 au_rw_init(&finfo->fi_rwsem);
125 au_rw_class(&finfo->fi_rwsem, &aufs_fi);
128 int au_finfo_init(struct file *file, struct au_fidir *fidir)
131 struct au_finfo *finfo;
132 struct dentry *dentry;
135 dentry = file->f_dentry;
136 finfo = au_cache_alloc_finfo();
137 if (unlikely(!finfo))
141 au_nfiles_inc(dentry->d_sb);
142 /* verbose coding for lock class name */
144 au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
146 au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
147 au_rw_write_lock(&finfo->fi_rwsem);
149 finfo->fi_hdir = fidir;
150 atomic_set(&finfo->fi_generation, au_digen(dentry));
151 /* smp_mb(); */ /* atomic_set */
153 file->private_data = finfo;