2 * Copyright (C) 2005-2012 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)
115 atomic_set(&au_ii(inode)->ii_generation, au_sigen(inode->i_sb));
116 /* smp_mb(); */ /* atomic_set */
119 /* it may be called at remount time, too */
120 void au_update_ibrange(struct inode *inode, int do_put_zero)
122 struct au_iinfo *iinfo;
123 aufs_bindex_t bindex, bend;
125 iinfo = au_ii(inode);
129 IiMustWriteLock(inode);
131 if (do_put_zero && iinfo->ii_bstart >= 0) {
132 for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
136 h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
137 if (h_i && !h_i->i_nlink)
138 au_set_h_iptr(inode, bindex, NULL, 0);
142 iinfo->ii_bstart = -1;
144 bend = au_sbend(inode->i_sb);
145 for (bindex = 0; bindex <= bend; bindex++)
146 if (iinfo->ii_hinode[0 + bindex].hi_inode) {
147 iinfo->ii_bstart = bindex;
150 if (iinfo->ii_bstart >= 0)
151 for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
152 if (iinfo->ii_hinode[0 + bindex].hi_inode) {
153 iinfo->ii_bend = bindex;
156 AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
159 /* ---------------------------------------------------------------------- */
161 void au_icntnr_init_once(void *_c)
163 struct au_icntnr *c = _c;
164 struct au_iinfo *iinfo = &c->iinfo;
165 static struct lock_class_key aufs_ii;
167 au_rw_init(&iinfo->ii_rwsem);
168 au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
169 inode_init_once(&c->vfs_inode);
172 int au_iinfo_init(struct inode *inode)
174 struct au_iinfo *iinfo;
175 struct super_block *sb;
179 iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
180 nbr = au_sbend(sb) + 1;
181 if (unlikely(nbr <= 0))
183 iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
184 if (iinfo->ii_hinode) {
186 for (i = 0; i < nbr; i++)
187 iinfo->ii_hinode[i].hi_id = -1;
189 atomic_set(&iinfo->ii_generation, au_sigen(sb));
190 /* smp_mb(); */ /* atomic_set */
191 iinfo->ii_bstart = -1;
193 iinfo->ii_vdir = NULL;
199 int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
202 struct au_hinode *hip;
204 AuRwMustWriteLock(&iinfo->ii_rwsem);
207 sz = sizeof(*hip) * (iinfo->ii_bend + 1);
210 hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
212 iinfo->ii_hinode = hip;
219 void au_iinfo_fin(struct inode *inode)
221 struct au_iinfo *iinfo;
222 struct au_hinode *hi;
223 struct super_block *sb;
224 aufs_bindex_t bindex, bend;
225 const unsigned char unlinked = !inode->i_nlink;
227 iinfo = au_ii(inode);
235 au_xino_delete_inode(inode, unlinked);
238 * it is safe to hide the dependency between sbinfo and
242 si_noflush_read_lock(sb);
243 au_xino_delete_inode(inode, unlinked);
249 au_vdir_free(iinfo->ii_vdir);
251 bindex = iinfo->ii_bstart;
253 hi = iinfo->ii_hinode + bindex;
254 bend = iinfo->ii_bend;
255 while (bindex++ <= bend) {
261 kfree(iinfo->ii_hinode);
262 iinfo->ii_hinode = NULL;
263 AuRwDestroy(&iinfo->ii_rwsem);