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
20
* external inode number translation table and bitmap
22
* $Id: xino.c,v 1.4 2008/05/04 23:53:49 sfjro Exp $
25
//#include <linux/fsnotify.h>
26
//#include <linux/smp_lock.h>
27
#include <linux/uaccess.h>
30
/* ---------------------------------------------------------------------- */
32
static ssize_t xino_fread(au_readf_t func, struct file *file, void *buf,
33
size_t size, loff_t *pos)
38
LKTRTrace("%.*s, sz %lu, *pos %Ld\n",
39
AuDLNPair(file->f_dentry), (unsigned long)size, *pos);
45
err = func(file, (char __user *)buf, size, pos);
46
} while (err == -EAGAIN || err == -EINTR);
51
fsnotify_access(file->f_dentry);
58
/* ---------------------------------------------------------------------- */
60
static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *buf,
61
size_t size, loff_t *pos)
71
err = func(file, (const char __user *)buf, size, pos);
72
} while (err == -EAGAIN || err == -EINTR);
77
au_update_fuse_h_inode(file->f_vfsmnt, file->f_dentry);
82
fsnotify_modify(file->f_dentry);
89
struct do_xino_fwrite_args {
98
static void call_do_xino_fwrite(void *args)
100
struct do_xino_fwrite_args *a = args;
101
*a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
104
static ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf,
105
size_t size, loff_t *pos)
109
LKTRTrace("%.*s, sz %lu, *pos %Ld\n",
110
AuDLNPair(file->f_dentry), (unsigned long)size, *pos);
112
// signal block and no wkq?
114
* it breaks RLIMIT_FSIZE and normal user's limit,
115
* users should care about quota and real 'filesystem full.'
117
if (!au_test_wkq(current)) {
119
struct do_xino_fwrite_args args = {
127
wkq_err = au_wkq_wait(call_do_xino_fwrite, &args, /*dlgt*/0);
128
if (unlikely(wkq_err))
131
err = do_xino_fwrite(func, file, buf, size, pos);
137
/* ---------------------------------------------------------------------- */
139
struct xino_do_trunc_args {
140
struct vfsmount *mnt;
141
struct au_branch *br;
144
static void xino_do_trunc(void *_args)
146
struct xino_do_trunc_args *args = _args;
147
struct super_block *sb;
148
aufs_bindex_t bindex;
153
sb = args->mnt->mnt_sb;
154
si_noflush_write_lock(sb);
155
bindex = au_br_index(sb, args->br->br_id);
156
AuDebugOn(bindex < 0);
157
err = au_xino_trunc(sb, bindex);
161
file = args->br->br_xino;
162
au_update_fuse_h_inode(args->br->br_mnt, file->f_dentry); /*ignore*/
163
if (file->f_dentry->d_inode->i_blocks >= args->br->br_xino_upper)
164
args->br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
165
//AuDbg("%Lu\n", (unsigned long long)args->br->br_xino_upper);
170
AuWarn("err b%d, (%d)\n", bindex, err);
171
au_nwt_dec(&au_sbi(sb)->si_nowait);
172
atomic_dec_return(&args->br->br_xino_running);
178
static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
180
struct xino_do_trunc_args *args;
181
struct au_sbinfo *sbinfo;
182
struct file *file = br->br_xino;
185
au_update_fuse_h_inode(br->br_mnt, file->f_dentry); /*ignore*/
186
if (file->f_dentry->d_inode->i_blocks < br->br_xino_upper)
188
if (atomic_inc_return(&br->br_xino_running) > 1)
191
/* lock and kfree() will be called in trunc_xino() */
192
args = kmalloc(sizeof(*args), GFP_TEMPORARY);
194
args->mnt = au_mntcache_get(sb);
198
au_nwt_inc(&sbinfo->si_nowait);
199
wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*dlgt*/0);
201
return; /* success */
203
AuErr("wkq %d\n", wkq_err);
204
au_nwt_dec(&sbinfo->si_nowait);
209
AuErr1("no memory\n");
211
atomic_dec_return(&br->br_xino_running);
214
/* ---------------------------------------------------------------------- */
216
#define Au_LOFF_MAX ((loff_t)LLONG_MAX)
218
static int au_xino_do_write(au_writef_t write, struct file *file,
219
ino_t h_ino, struct au_xino_entry *xinoe)
227
if (unlikely(Au_LOFF_MAX / sizeof(*xinoe) - 1 < pos)) {
228
AuIOErr1("too large hi%lu\n", h_ino);
231
pos *= sizeof(*xinoe);
232
sz = xino_fwrite(write, file, xinoe, sizeof(*xinoe), &pos);
233
if (sz == sizeof(*xinoe))
234
return 0; /* success */
236
AuIOErr("write failed (%ld)\n", (long)sz);
241
* write @ino to the xinofile for the specified branch{@sb, @bindex}
242
* at the position of @_ino.
243
* when @ino is zero, it is written to the xinofile and means no entry.
245
int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
246
struct au_xino_entry *xinoe)
250
struct au_branch *br;
251
unsigned int mnt_flags;
253
LKTRTrace("b%d, hi%lu, i%lu\n", bindex, h_ino, xinoe->ino);
254
BUILD_BUG_ON(sizeof(long long) != sizeof(Au_LOFF_MAX)
255
|| ((loff_t) - 1) > 0);
257
mnt_flags = au_mntflags(sb);
258
if (unlikely(!au_opt_test(mnt_flags, XINO)))
261
br = au_sbr(sb, bindex);
265
err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, h_ino, xinoe);
267
if (unlikely(au_opt_test(mnt_flags, TRUNC_XINO)
268
&& au_test_trunc_xino(br->br_mnt->mnt_sb)))
269
xino_try_trunc(sb, br);
270
return 0; /* success */
273
AuIOErr("write failed (%d)\n", err);
277
/* ---------------------------------------------------------------------- */
279
static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
280
//static const int page_bits = 4;
281
static ino_t xib_calc_ino(unsigned long pindex, int bit)
284
AuDebugOn(bit < 0 || page_bits <= bit);
285
ino = AUFS_FIRST_INO + pindex * page_bits + bit;
289
static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
291
AuDebugOn(ino < AUFS_FIRST_INO);
292
ino -= AUFS_FIRST_INO;
293
*pindex = ino / page_bits;
294
*bit = ino % page_bits;
297
static int xib_pindex(struct super_block *sb, unsigned long pindex)
300
struct au_sbinfo *sbinfo;
306
LKTRTrace("pindex %lu\n", pindex);
308
MtxMustLock(&sbinfo->si_xib_mtx);
309
AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
310
|| !au_opt_test(sbinfo->si_mntflags, XINO));
312
if (pindex == sbinfo->si_xib_last_pindex)
315
xib = sbinfo->si_xib;
316
p = sbinfo->si_xib_buf;
317
pos = sbinfo->si_xib_last_pindex;
319
sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
320
if (unlikely(sz != PAGE_SIZE))
325
if (i_size_read(xib->f_dentry->d_inode) >= pos + PAGE_SIZE)
326
sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
328
memset(p, 0, PAGE_SIZE);
329
sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
331
if (sz == PAGE_SIZE) {
332
sbinfo->si_xib_last_pindex = pindex;
333
return 0; /* success */
337
AuIOErr1("write failed (%ld)\n", (long)sz);
345
/* ---------------------------------------------------------------------- */
347
int au_xino_write0(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
351
unsigned long pindex;
352
struct au_sbinfo *sbinfo;
353
struct au_xino_entry xinoe = {
357
LKTRTrace("b%d, hi%lu, i%lu\n", bindex, h_ino, ino);
360
if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
365
AuDebugOn(ino < AUFS_FIRST_INO);
366
xib_calc_bit(ino, &pindex, &bit);
367
AuDebugOn(page_bits <= bit);
368
mutex_lock(&sbinfo->si_xib_mtx);
369
err = xib_pindex(sb, pindex);
371
clear_bit(bit, sbinfo->si_xib_buf);
372
sbinfo->si_xib_next_bit = bit;
374
mutex_unlock(&sbinfo->si_xib_mtx);
378
err = au_xino_write(sb, bindex, h_ino, &xinoe);
382
ino_t au_xino_new_ino(struct super_block *sb)
385
struct au_sbinfo *sbinfo;
387
unsigned long *p, pindex, ul, pend;
394
if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
395
return iunique(sb, AUFS_FIRST_INO);
397
mutex_lock(&sbinfo->si_xib_mtx);
398
p = sbinfo->si_xib_buf;
399
free_bit = sbinfo->si_xib_next_bit;
400
//AuDbg("bit %d, pindex %d\n", free_bit, sbinfo->si_xib_last_pindex);
401
//AuDbg("bit %d, %d\n", free_bit, test_bit(free_bit, p));
402
if (free_bit < page_bits && !test_bit(free_bit, p))
403
goto out; /* success */
404
free_bit = find_first_zero_bit(p, page_bits);
405
if (free_bit < page_bits)
406
goto out; /* success */
408
pindex = sbinfo->si_xib_last_pindex;
409
for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
410
err = xib_pindex(sb, ul);
413
free_bit = find_first_zero_bit(p, page_bits);
414
if (free_bit < page_bits)
415
goto out; /* success */
418
file = sbinfo->si_xib;
419
pend = i_size_read(file->f_dentry->d_inode) / PAGE_SIZE;
420
for (ul = pindex + 1; ul <= pend; ul++) {
421
err = xib_pindex(sb, ul);
424
free_bit = find_first_zero_bit(p, page_bits);
425
if (free_bit < page_bits)
426
goto out; /* success */
431
set_bit(free_bit, p);
432
sbinfo->si_xib_next_bit++;
433
pindex = sbinfo->si_xib_last_pindex;
434
mutex_unlock(&sbinfo->si_xib_mtx);
435
ino = xib_calc_ino(pindex, free_bit);
436
//AuDbg("i%lu\n", ino);
437
LKTRTrace("i%lu\n", ino);
441
mutex_unlock(&sbinfo->si_xib_mtx);
448
* read @ino from xinofile for the specified branch{@sb, @bindex}
449
* at the position of @h_ino.
450
* if @ino does not exist and @do_new is true, get new one.
452
int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
453
struct au_xino_entry *xinoe)
459
struct au_sbinfo *sbinfo;
461
LKTRTrace("b%d, hi%lu\n", bindex, h_ino);
466
if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
467
return 0; /* no ino */
470
if (unlikely(Au_LOFF_MAX / sizeof(*xinoe) - 1 < pos)) {
471
AuIOErr1("too large hi%lu\n", h_ino);
474
pos *= sizeof(*xinoe);
476
file = au_sbr(sb, bindex)->br_xino;
478
if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*xinoe))
479
return 0; /* no ino */
481
sz = xino_fread(sbinfo->si_xread, file, xinoe, sizeof(*xinoe), &pos);
482
if (sz == sizeof(*xinoe))
483
return 0; /* success */
486
if (unlikely(sz >= 0)) {
488
AuIOErr("xino read error (%ld)\n", (long)sz);
495
/* ---------------------------------------------------------------------- */
497
struct file *au_xino_create(struct super_block *sb, char *fname, int silent,
498
struct dentry *parent)
502
struct dentry *h_parent;
504
struct vfsub_args vargs;
505
//const int hinotify = au_opt_test(au_mntflags(sb), UDBA_INOTIFY);
507
LKTRTrace("%s\n", fname);
508
//AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
510
/* LSM may detect it */
511
file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE,
513
//file = ERR_PTR(-1);
516
AuErr("open %s(%ld)\n", fname, PTR_ERR(file));
520
/* keep file count */
521
h_parent = dget_parent(file->f_dentry);
522
h_dir = h_parent->d_inode;
523
vfsub_args_init(&vargs, NULL, 0, 0);
524
mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
525
err = vfsub_unlink(h_dir, file->f_dentry, &vargs);
526
mutex_unlock(&h_dir->i_mutex);
530
AuErr("unlink %s(%d)\n", fname, err);
534
if (sb != file->f_dentry->d_sb)
535
return file; /* success */
538
AuErr("%s must be outside\n", fname);
548
* find another branch who is on the same filesystem of the specified
549
* branch{@btgt}. search until @bend.
551
static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
554
aufs_bindex_t bindex;
555
struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
557
for (bindex = 0; bindex <= bend; bindex++)
558
if (unlikely(btgt != bindex && tgt_sb == au_sbr_sb(sb, bindex)))
564
* create a new xinofile at the same place/path as @base_file.
567
struct file *au_xino_create2(struct super_block *sb, struct file *base_file,
568
struct file *copy_src)
572
struct dentry *base, *dentry, *parent;
573
struct inode *dir, *inode;
575
struct vfsub_args vargs;
576
struct au_ndx ndx = {
583
base = base_file->f_dentry;
584
LKTRTrace("%.*s\n", AuDLNPair(base));
585
parent = base->d_parent; /* dir inode is locked */
586
dir = parent->d_inode;
589
file = ERR_PTR(-EINVAL);
590
if (unlikely(au_test_nfs(parent->d_sb)))
593
/* do not superio, nor NFS. */
594
name = &base->d_name;
595
dentry = au_lkup_one(name->name, parent, name->len, &ndx);
596
//if (LktrCond) {dput(dentry); dentry = ERR_PTR(-1);}
597
if (IS_ERR(dentry)) {
598
file = (void *)dentry;
599
AuErr("%.*s lookup err %ld\n", AuLNPair(name), PTR_ERR(dentry));
602
err = vfsub_create(dir, dentry, S_IRUGO | S_IWUGO, NULL, /*dlgt*/0);
603
//if (LktrCond) {vfs_unlink(dir, dentry); err = -1;}
606
AuErr("%.*s create err %d\n", AuLNPair(name), err);
609
file = dentry_open(dget(dentry), mntget(base_file->f_vfsmnt),
610
O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE);
611
//if (LktrCond) {fput(file); file = ERR_PTR(-1);}
613
AuErr("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
616
vfsub_args_init(&vargs, NULL, 0, 0);
617
err = vfsub_unlink(dir, dentry, &vargs);
618
//if (LktrCond) err = -1;
620
AuErr("%.*s unlink err %d\n", AuLNPair(name), err);
625
inode = copy_src->f_dentry->d_inode;
626
err = au_copy_file(file, copy_src, i_size_read(inode), sb);
628
AuErr("%.*s copy err %d\n", AuLNPair(name), err);
632
goto out_dput; /* success */
644
/* ---------------------------------------------------------------------- */
647
* initialize the xinofile for the specified branch{@sb, @bindex}
648
* at the place/path where @base_file indicates.
649
* test whether another branch is on the same filesystem or not,
650
* if @do_test is true.
652
int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
653
struct file *base_file, int do_test)
656
struct au_branch *shared_br;
657
aufs_bindex_t bshared, bend;
659
struct au_xino_entry xinoe;
660
struct dentry *parent;
663
LKTRTrace("base_file %p, do_test %d\n", base_file, do_test);
665
AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
666
AuDebugOn(br->br_xino);
673
aufs_bindex_t bindex;
675
struct super_block *tgt_sb = br->br_mnt->mnt_sb;
676
for (bindex = 0; bindex <= bend; bindex++)
677
if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) {
682
if (unlikely(bshared >= 0)) {
683
shared_br = au_sbr(sb, bshared);
684
do_create = !shared_br->br_xino;
688
parent = dget_parent(base_file->f_dentry);
689
dir = parent->d_inode;
691
mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
692
file = au_xino_create2(sb, base_file, NULL);
694
mutex_unlock(&dir->i_mutex);
700
br->br_xino = shared_br->br_xino;
701
get_file(br->br_xino);
704
xinoe.ino = AUFS_ROOT_INO;
705
//xinoe.h_gen = h_inode->i_generation;
706
//WARN_ON(xinoe.h_gen == AuXino_INVALID_HGEN);
707
err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino, h_ino,
709
//if (LktrCond) err = -1;
711
return 0; /* success */
714
//br->br_xino = NULL;
722
static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
725
struct au_sbinfo *sbinfo;
729
struct au_xino_entry *xinoe;
730
unsigned long pindex;
737
func = sbinfo->si_xread;
738
pend = i_size_read(file->f_dentry->d_inode);
739
#ifdef CONFIG_AUFS_DEBUG
740
if (unlikely(pend > (1 << 22)))
741
AuWarn("testing a large xino file %Ld\n", (long long)pend);
745
sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
747
if (unlikely(sz <= 0))
751
for (xinoe = page; sz > 0; xinoe++, sz -= sizeof(xinoe)) {
752
//AuDbg("i%lu\n", xinoe->ino);
753
if (unlikely(xinoe->ino < AUFS_FIRST_INO))
756
xib_calc_bit(xinoe->ino, &pindex, &bit);
757
AuDebugOn(page_bits <= bit);
758
err = xib_pindex(sb, pindex);
760
set_bit(bit, sbinfo->si_xib_buf);
763
//AuDbg("i%lu, bit %d\n", xinoe->ino, bit);
772
static int xib_restore(struct super_block *sb)
775
aufs_bindex_t bindex, bend;
782
page = (void *)__get_free_page(GFP_TEMPORARY);
788
for (bindex = 0; !err && bindex <= bend; bindex++)
789
if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
791
(sb, au_sbr(sb, bindex)->br_xino, page);
793
LKTRTrace("b%d\n", bindex);
794
free_page((unsigned long)page);
802
int au_xib_trunc(struct super_block *sb)
805
struct au_sbinfo *sbinfo;
810
struct dentry *parent;
813
unsigned int mnt_flags;
818
mnt_flags = au_mntflags(sb);
819
if (unlikely(!au_opt_test(mnt_flags, XINO)))
824
parent = dget_parent(sbinfo->si_xib->f_dentry);
825
dir = parent->d_inode;
826
mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
827
file = au_xino_create2(sb, sbinfo->si_xib, NULL);
828
mutex_unlock(&dir->i_mutex);
833
fput(sbinfo->si_xib);
834
sbinfo->si_xib = file;
836
p = sbinfo->si_xib_buf;
837
memset(p, 0, PAGE_SIZE);
839
sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
840
if (unlikely(sz != PAGE_SIZE)) {
842
AuIOErr("err %d\n", err);
848
if (au_opt_test(mnt_flags, XINO)) {
849
mutex_lock(&sbinfo->si_xib_mtx);
850
err = xib_restore(sb);
851
mutex_unlock(&sbinfo->si_xib_mtx);
854
/* is it really safe? */
855
AuDebugOn(!kernel_locked());
856
ino = AUFS_FIRST_INO;
857
list_for_each_entry(inode, &sb->s_inodes, i_sb_list)
858
if (ino < inode->i_ino)
861
/* make iunique to return larger than active max inode number */
873
/* ---------------------------------------------------------------------- */
876
* xino mount option handlers
878
static au_readf_t find_readf(struct file *h_file)
880
const struct file_operations *fop = h_file->f_op;
888
return ERR_PTR(-ENOSYS);
891
static au_writef_t find_writef(struct file *h_file)
893
const struct file_operations *fop = h_file->f_op;
899
return do_sync_write;
901
return ERR_PTR(-ENOSYS);
905
static void xino_clear_xib(struct super_block *sb)
907
struct au_sbinfo *sbinfo;
913
sbinfo->si_xread = NULL;
914
sbinfo->si_xwrite = NULL;
916
fput(sbinfo->si_xib);
917
sbinfo->si_xib = NULL;
918
free_page((unsigned long)sbinfo->si_xib_buf);
919
sbinfo->si_xib_buf = NULL;
922
static int au_xino_set_xib(struct super_block *sb, struct file *base)
925
struct au_sbinfo *sbinfo;
929
LKTRTrace("%.*s\n", AuDLNPair(base->f_dentry));
933
file = au_xino_create2(sb, base, sbinfo->si_xib);
938
fput(sbinfo->si_xib);
939
sbinfo->si_xib = file;
940
sbinfo->si_xread = find_readf(file);
941
AuDebugOn(IS_ERR(sbinfo->si_xread));
942
sbinfo->si_xwrite = find_writef(file);
943
AuDebugOn(IS_ERR(sbinfo->si_xwrite));
946
if (!sbinfo->si_xib_buf)
947
sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_KERNEL);
948
if (unlikely(!sbinfo->si_xib_buf))
951
sbinfo->si_xib_last_pindex = 0;
952
sbinfo->si_xib_next_bit = 0;
954
/* no need to lock for i_size_read() */
955
if (i_size_read(file->f_dentry->d_inode) < PAGE_SIZE) {
957
err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
959
if (unlikely(err != PAGE_SIZE))
963
goto out; /* success */
966
free_page((unsigned long)sbinfo->si_xib_buf);
967
sbinfo->si_xib_buf = NULL;
971
fput(sbinfo->si_xib);
972
sbinfo->si_xib = NULL;
973
sbinfo->si_xread = NULL;
974
sbinfo->si_xwrite = NULL;
980
/* xino for each branch */
981
static void xino_clear_br(struct super_block *sb)
983
aufs_bindex_t bindex, bend;
984
struct au_branch *br;
990
for (bindex = 0; bindex <= bend; bindex++) {
991
br = au_sbr(sb, bindex);
992
if (unlikely(!br || !br->br_xino))
1000
static int au_xino_set_br(struct super_block *sb, struct file *base)
1003
aufs_bindex_t bindex, bend, bshared;
1004
struct au_branch *br, *shared;
1005
struct au_xino_entry xinoe;
1007
struct inode *inode;
1009
LKTRTrace("%.*s\n", AuDLNPair(base->f_dentry));
1010
SiMustWriteLock(sb);
1012
bend = au_sbend(sb);
1013
for (bindex = bend; bindex >= 0; bindex--) {
1014
br = au_sbr(sb, bindex);
1015
if (!br->br_xino || file_count(br->br_xino) == 1)
1022
for (bindex = 0; bindex <= bend; bindex++) {
1023
br = au_sbr(sb, bindex);
1026
AuDebugOn(file_count(br->br_xino) != 1);
1027
file = au_xino_create2(sb, base, br->br_xino);
1030
err = PTR_ERR(file);
1038
inode = sb->s_root->d_inode;
1039
xinoe.ino = AUFS_ROOT_INO;
1040
for (bindex = 0; !err && bindex <= bend; bindex++) {
1041
br = au_sbr(sb, bindex);
1044
bshared = is_sb_shared(sb, bindex, bindex);
1046
file = au_xino_create2(sb, base, NULL);
1049
err = PTR_ERR(file);
1054
shared = au_sbr(sb, bshared);
1055
AuDebugOn(!shared->br_xino);
1056
br->br_xino = shared->br_xino;
1057
get_file(br->br_xino);
1059
err = au_xino_write(sb, bindex,
1060
au_h_iptr(inode, bindex)->i_ino, &xinoe);
1068
void au_xino_clr(struct super_block *sb)
1071
SiMustWriteLock(sb);
1075
au_opt_clr(au_sbi(sb)->si_mntflags, XINO);
1078
int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
1081
struct dentry *parent, *cur_parent;
1082
struct qstr *dname, *cur_name;
1083
struct file *cur_xino;
1085
struct au_sbinfo *sbinfo;
1087
LKTRTrace("remount %d\n", remount);
1088
SiMustWriteLock(sb);
1091
sbinfo = au_sbi(sb);
1092
parent = dget_parent(xino->file->f_dentry);
1095
dname = &xino->file->f_dentry->d_name;
1096
cur_xino = sbinfo->si_xib;
1098
cur_parent = dget_parent(cur_xino->f_dentry);
1099
cur_name = &cur_xino->f_dentry->d_name;
1100
skip = (cur_parent == parent
1101
&& dname->len == cur_name->len
1102
&& !memcmp(dname->name, cur_name->name,
1110
au_opt_set(sbinfo->si_mntflags, XINO);
1111
dir = parent->d_inode;
1112
mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
1113
err = au_xino_set_xib(sb, xino->file);
1115
err = au_xino_set_br(sb, xino->file);
1116
mutex_unlock(&dir->i_mutex);
1118
goto out; /* success */
1121
AuIOErr("failed creating xino, forcing noxino (%d).\n", err);
1131
int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
1134
struct au_branch *br;
1135
struct file *new_xino;
1136
struct super_block *h_sb;
1137
aufs_bindex_t bi, bend;
1138
struct dentry *parent;
1142
LKTRTrace("b%d\n", bindex);
1143
SiMustWriteLock(sb);
1146
bend = au_sbend(sb);
1147
if (unlikely(bindex < 0 || bend < bindex))
1149
br = au_sbr(sb, bindex);
1150
if (unlikely(!br->br_xino))
1153
parent = dget_parent(br->br_xino->f_dentry);
1154
dir = parent->d_inode;
1155
//AuDbgFile(br->br_xino);
1156
mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
1157
new_xino = au_xino_create2(sb, br->br_xino, br->br_xino);
1158
mutex_unlock(&dir->i_mutex);
1159
//AuDbgFile(new_xino);
1161
err = PTR_ERR(new_xino);
1162
if (IS_ERR(new_xino))
1166
br->br_xino = new_xino;
1168
h_sb = br->br_mnt->mnt_sb;
1169
for (bi = 0; bi <= bend; bi++) {
1170
if (unlikely(bi == bindex))
1172
br = au_sbr(sb, bi);
1173
if (br->br_mnt->mnt_sb != h_sb)
1177
br->br_xino = new_xino;
1187
/* ---------------------------------------------------------------------- */
1190
* create a xinofile at the default place/path.
1192
struct file *au_xino_def(struct super_block *sb)
1195
aufs_bindex_t bend, bindex, bwr;
1201
bend = au_sbend(sb);
1203
for (bindex = 0; bindex <= bend; bindex++)
1204
if (au_br_writable(au_sbr_perm(sb, bindex))
1205
&& !au_test_nfs(au_h_dptr(sb->s_root, bindex)->d_sb)) {
1211
// todo: rewrite with au_lkup_one()
1212
file = ERR_PTR(-ENOMEM);
1214
//if (LktrCond) {__putname(page); page = NULL;}
1215
if (unlikely(!page))
1217
path.mnt = au_sbr_mnt(sb, bwr);
1218
path.dentry = au_h_dptr(sb->s_root, bwr);
1219
p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
1220
//if (LktrCond) p = ERR_PTR(-1);
1222
if (p && !IS_ERR(p)) {
1223
strcat(p, "/" AUFS_XINO_FNAME);
1224
LKTRTrace("%s\n", p);
1225
file = au_xino_create(sb, p, /*silent*/0, sb->s_root);
1226
//if (LktrCond) {fput(file); file = ERR_PTR(-1);}
1230
file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
1232
//if (LktrCond) {fput(file); file = ERR_PTR(-1);}
1233
if (unlikely(au_test_nfs(file->f_dentry->d_sb))) {
1234
AuErr("xino or noxino option is required "
1235
"since %s is NFS\n", AUFS_XINO_DEFPATH);
1237
file = ERR_PTR(-EINVAL);
1242
AuTraceErrPtr(file);