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 struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
27 struct inode *h_inode;
31 h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
32 AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
36 /* todo: hard/soft set? */
37 void au_hiput(struct au_hinode *hinode)
40 dput(hinode->hi_whdentry);
41 iput(hinode->hi_inode);
44 unsigned int au_hi_flags(struct inode *inode, int isdir)
47 const unsigned int mnt_flags = au_mntflags(inode->i_sb);
50 if (au_opt_test(mnt_flags, XINO))
51 au_fset_hi(flags, XINO);
52 if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
53 au_fset_hi(flags, HNOTIFY);
57 void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
58 struct inode *h_inode, unsigned int flags)
60 struct au_hinode *hinode;
62 struct au_iinfo *iinfo = au_ii(inode);
64 IiMustWriteLock(inode);
66 hinode = iinfo->ii_hinode + bindex;
67 hi = hinode->hi_inode;
68 AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
72 hinode->hi_inode = h_inode;
75 struct super_block *sb = inode->i_sb;
78 AuDebugOn(inode->i_mode
79 && (h_inode->i_mode & S_IFMT)
80 != (inode->i_mode & S_IFMT));
81 if (bindex == iinfo->ii_bstart)
82 au_cpup_igen(inode, h_inode);
83 br = au_sbr(sb, bindex);
84 hinode->hi_id = br->br_id;
85 if (au_ftest_hi(flags, XINO)) {
86 err = au_xino_write(sb, bindex, h_inode->i_ino,
89 AuIOErr1("failed au_xino_write() %d\n", err);
92 if (au_ftest_hi(flags, HNOTIFY)
93 && au_br_hnotifyable(br->br_perm)) {
94 err = au_hn_alloc(hinode, inode);
96 AuIOErr1("au_hn_alloc() %d\n", err);
101 void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
104 struct au_hinode *hinode;
106 IiMustWriteLock(inode);
108 hinode = au_ii(inode)->ii_hinode + bindex;
109 AuDebugOn(hinode->hi_whdentry);
110 hinode->hi_whdentry = h_wh;
113 void au_update_iigen(struct inode *inode, int half)
115 struct au_iinfo *iinfo;
116 struct au_iigen *iigen;
119 sigen = au_sigen(inode->i_sb);
120 iinfo = au_ii(inode);
121 iigen = &iinfo->ii_generation;
122 spin_lock(&iinfo->ii_genspin);
123 iigen->ig_generation = sigen;
125 au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
127 au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
128 spin_unlock(&iinfo->ii_genspin);
131 /* it may be called at remount time, too */
132 void au_update_ibrange(struct inode *inode, int do_put_zero)
134 struct au_iinfo *iinfo;
135 aufs_bindex_t bindex, bend;
137 iinfo = au_ii(inode);
141 IiMustWriteLock(inode);
143 if (do_put_zero && iinfo->ii_bstart >= 0) {
144 for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
148 h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
149 if (h_i && !h_i->i_nlink)
150 au_set_h_iptr(inode, bindex, NULL, 0);
154 iinfo->ii_bstart = -1;
156 bend = au_sbend(inode->i_sb);
157 for (bindex = 0; bindex <= bend; bindex++)
158 if (iinfo->ii_hinode[0 + bindex].hi_inode) {
159 iinfo->ii_bstart = bindex;
162 if (iinfo->ii_bstart >= 0)
163 for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
164 if (iinfo->ii_hinode[0 + bindex].hi_inode) {
165 iinfo->ii_bend = bindex;
168 AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
171 /* ---------------------------------------------------------------------- */
173 void au_icntnr_init_once(void *_c)
175 struct au_icntnr *c = _c;
176 struct au_iinfo *iinfo = &c->iinfo;
177 static struct lock_class_key aufs_ii;
179 spin_lock_init(&iinfo->ii_genspin);
180 au_rw_init(&iinfo->ii_rwsem);
181 au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
182 inode_init_once(&c->vfs_inode);
185 int au_iinfo_init(struct inode *inode)
187 struct au_iinfo *iinfo;
188 struct super_block *sb;
192 iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
193 nbr = au_sbend(sb) + 1;
194 if (unlikely(nbr <= 0))
196 iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
197 if (iinfo->ii_hinode) {
199 for (i = 0; i < nbr; i++)
200 iinfo->ii_hinode[i].hi_id = -1;
202 iinfo->ii_generation.ig_generation = au_sigen(sb);
203 iinfo->ii_bstart = -1;
205 iinfo->ii_vdir = NULL;
211 int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
214 struct au_hinode *hip;
216 AuRwMustWriteLock(&iinfo->ii_rwsem);
219 sz = sizeof(*hip) * (iinfo->ii_bend + 1);
222 hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
224 iinfo->ii_hinode = hip;
231 void au_iinfo_fin(struct inode *inode)
233 struct au_iinfo *iinfo;
234 struct au_hinode *hi;
235 struct super_block *sb;
236 aufs_bindex_t bindex, bend;
237 const unsigned char unlinked = !inode->i_nlink;
239 iinfo = au_ii(inode);
247 au_xino_delete_inode(inode, unlinked);
250 * it is safe to hide the dependency between sbinfo and
254 si_noflush_read_lock(sb);
255 au_xino_delete_inode(inode, unlinked);
261 au_vdir_free(iinfo->ii_vdir);
263 bindex = iinfo->ii_bstart;
265 hi = iinfo->ii_hinode + bindex;
266 bend = iinfo->ii_bend;
267 while (bindex++ <= bend) {
273 kfree(iinfo->ii_hinode);
274 iinfo->ii_hinode = NULL;
275 AuRwDestroy(&iinfo->ii_rwsem);