2
* Copyright (C) 2005-2008 Junjiro 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
22
* $Id: inode.c,v 1.3 2008/04/28 03:04:12 sfjro Exp $
27
int au_refresh_hinode_self(struct inode *inode)
29
int err, new_sz, update;
31
struct au_hinode *p, *q, tmp;
32
struct super_block *sb;
33
struct au_iinfo *iinfo;
34
aufs_bindex_t bindex, bend, new_bindex;
36
LKTRTrace("i%lu\n", inode->i_ino);
37
IiMustWriteLock(inode);
43
new_sz = sizeof(*iinfo->ii_hinode) * (bend + 1);
45
p = au_kzrealloc(iinfo->ii_hinode, sizeof(*p) * (iinfo->ii_bend + 1),
52
p = iinfo->ii_hinode + iinfo->ii_bstart;
55
for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
60
new_bindex = au_br_index(sb, p->hi_id);
61
if (new_bindex == bindex)
70
if (new_bindex < iinfo->ii_bstart)
71
iinfo->ii_bstart = new_bindex;
72
if (iinfo->ii_bend < new_bindex)
73
iinfo->ii_bend = new_bindex;
74
/* swap two hidden inode, and loop again */
75
q = iinfo->ii_hinode + new_bindex;
84
au_update_brange(inode, /*do_put_zero*/0);
89
if (1 || first != au_h_iptr(inode, iinfo->ii_bstart))
90
au_cpup_attr_all(inode);
91
if (update && S_ISDIR(inode->i_mode))
93
au_update_iigen(inode);
100
int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
102
int err, update, isdir;
105
struct super_block *sb;
106
struct au_iinfo *iinfo;
107
aufs_bindex_t bindex, bend;
110
LKTRTrace("%.*s\n", AuDLNPair(dentry));
111
IiMustWriteLock(inode);
113
err = au_refresh_hinode_self(inode);
119
iinfo = au_ii(inode);
121
p = iinfo->ii_hinode + iinfo->ii_bstart;
123
isdir = S_ISDIR(inode->i_mode);
124
flags = au_hi_flags(inode, isdir);
125
bend = au_dbend(dentry);
126
for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
130
hd = au_h_dptr(dentry, bindex);
131
if (!hd || !hd->d_inode)
134
if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
135
hi = au_h_iptr(inode, bindex);
137
if (hi == hd->d_inode)
143
if (bindex < iinfo->ii_bstart)
144
iinfo->ii_bstart = bindex;
145
if (iinfo->ii_bend < bindex)
146
iinfo->ii_bend = bindex;
147
au_set_h_iptr(inode, bindex, igrab(hd->d_inode), flags);
150
au_update_brange(inode, /*do_put_zero*/0);
155
if (1 || first != au_h_iptr(inode, iinfo->ii_bstart))
156
au_cpup_attr_all(inode);
159
au_update_iigen(inode);
166
static int set_inode(struct inode *inode, struct dentry *dentry)
169
struct dentry *h_dentry;
170
struct inode *h_inode;
172
aufs_bindex_t bindex, bstart, btail;
173
struct au_iinfo *iinfo;
176
LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(dentry));
177
AuDebugOn(!(inode->i_state & I_NEW));
178
IiMustWriteLock(inode);
179
bstart = au_dbstart(dentry);
180
h_dentry = au_h_dptr(dentry, bstart);
181
AuDebugOn(!h_dentry);
182
h_inode = h_dentry->d_inode;
187
mode = h_inode->i_mode;
188
switch (mode & S_IFMT) {
190
btail = au_dbtail(dentry);
194
btail = au_dbtaildir(dentry);
195
inode->i_op = &aufs_dir_iop;
196
inode->i_fop = &aufs_dir_fop;
199
btail = au_dbtail(dentry);
200
inode->i_op = &aufs_symlink_iop;
206
btail = au_dbtail(dentry);
207
init_special_inode(inode, mode,
208
au_h_rdev(h_inode, /*h_mnt*/NULL, h_dentry));
211
AuIOErr("Unknown file type 0%o\n", mode);
216
flags = au_hi_flags(inode, isdir);
217
iinfo = au_ii(inode);
218
iinfo->ii_bstart = bstart;
219
iinfo->ii_bend = btail;
220
for (bindex = bstart; bindex <= btail; bindex++) {
221
h_dentry = au_h_dptr(dentry, bindex);
224
AuDebugOn(!h_dentry->d_inode);
225
au_set_h_iptr(inode, bindex, igrab(h_dentry->d_inode), flags);
227
au_cpup_attr_all(inode);
234
/* successful returns with iinfo write_locked */
235
//todo: return with unlocked?
236
static int reval_inode(struct inode *inode, struct dentry *dentry, int *matched)
239
struct inode *h_inode, *h_dinode;
240
aufs_bindex_t bindex, bend;
242
const int hinotify = au_opt_test(au_mntflags(inode->i_sb),
246
LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(dentry));
251
* before this function, if aufs got any iinfo lock, it must be only
252
* one, the parent dir.
253
* it can happen by UDBA and the obsoleted inode number.
256
if (unlikely(inode->i_ino == parent_ino(dentry)))
260
h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
261
mutex_lock_nested(&inode->i_mutex, AuLsc_I_CHILD);
262
ii_write_lock_new(inode);
263
bend = au_ibend(inode);
264
for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
265
h_inode = au_h_iptr(inode, bindex);
266
if (h_inode && h_inode == h_dinode) {
267
//&& (ibs != bstart || !au_test_higen(inode, h_inode)));
270
if (unlikely(au_iigen(inode) != au_digen(dentry)))
271
err = au_refresh_hinode(inode, dentry);
276
ii_write_unlock(inode);
277
mutex_unlock(&inode->i_mutex);
284
/* successful returns with iinfo write_locked */
285
//todo: return with unlocked?
286
struct inode *au_new_inode(struct dentry *dentry)
288
struct inode *inode, *h_inode;
289
struct dentry *h_dentry;
291
struct super_block *sb;
293
aufs_bindex_t bstart;
294
struct au_xino_entry xinoe;
296
LKTRTrace("%.*s\n", AuDLNPair(dentry));
298
bstart = au_dbstart(dentry);
299
h_dentry = au_h_dptr(dentry, bstart);
300
AuDebugOn(!h_dentry);
301
h_inode = h_dentry->d_inode;
304
h_ino = h_inode->i_ino;
305
err = au_xino_read(sb, bstart, h_ino, &xinoe);
307
inode = ERR_PTR(err);
312
xinoe.ino = au_xino_new_ino(sb);
314
inode = ERR_PTR(-EIO);
319
LKTRTrace("i%lu\n", xinoe.ino);
320
inode = au_iget_locked(sb, xinoe.ino);
321
err = PTR_ERR(inode);
325
LKTRTrace("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
326
if (inode->i_state & I_NEW) {
327
ii_write_lock_new(inode);
328
err = set_inode(inode, dentry);
330
unlock_new_inode(inode);
332
goto out; /* success */
334
ii_write_unlock(inode);
338
AuDebugOn(inode->i_state & I_LOCK);
339
err = reval_inode(inode, dentry, &match);
341
goto out; /* success */
346
if (unlikely(au_test_unique_ino(h_dentry, h_ino)))
347
AuWarn1("Un-notified UDBA or repeatedly renamed dir,"
348
" b%d, %s, %.*s, hi%lu, i%lu.\n",
349
bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
353
static unsigned char c;
355
struct dentry *d = d_find_alias(inode);
368
err = au_xino_write0(sb, bstart, h_ino, 0);
377
inode = ERR_PTR(err);
379
AuTraceErrPtr(inode);
383
/* ---------------------------------------------------------------------- */
385
int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
390
err = au_br_rdonly(au_sbr(sb, bindex));
392
/* pseudo-link after flushed may out of bounds */
395
&& au_ibstart(inode) <= bindex
396
&& bindex <= au_ibend(inode)) {
398
* permission check is unnecessary since vfsub routine
399
* will be called later
401
struct inode *hi = au_h_iptr(inode, bindex);
403
err = IS_IMMUTABLE(hi) ? -EROFS : 0;
410
int au_test_h_perm(struct inode *h_inode, int mask, int dlgt)
414
//todo: fake nameidata
415
return vfsub_permission(h_inode, mask, NULL, dlgt);
418
int au_test_h_perm_sio(struct inode *h_inode, int mask, int dlgt)
420
if (unlikely(au_test_nfs(h_inode->i_sb)
421
&& (mask & MAY_WRITE)
422
&& S_ISDIR(h_inode->i_mode)))
423
mask |= MAY_READ; /* force permission check */
424
return au_test_h_perm(h_inode, mask, dlgt);