~ubuntu-branches/ubuntu/raring/aufs/raring

« back to all changes in this revision

Viewing changes to fs/aufs/i_op_add.c

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2008-05-06 18:35:50 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080506183550-0b6c974kkgc46oeh
Tags: 0+20080506-1
* New upstream release, supports Kernel 2.6.25 (Closes: #479717)
* Fix building with older Kernels (Closes: #475042)
* Update the patches 01, 04 and 07 to also patch fs/aufs25

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2005, 2006, 2007, 2008 Junjiro Okajima
 
2
 * Copyright (C) 2005-2008 Junjiro Okajima
3
3
 *
4
4
 * This program, aufs is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
16
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 */
18
18
 
19
 
/* $Id: i_op_add.c,v 1.60 2008/02/18 04:37:16 sfjro Exp $ */
 
19
/*
 
20
 * inode operations (add entry)
 
21
 *
 
22
 * $Id: i_op_add.c,v 1.62 2008/04/13 23:42:23 sfjro Exp $
 
23
 */
20
24
 
21
25
#include "aufs.h"
22
26
 
33
37
        aufs_bindex_t bwh;
34
38
        struct inode *inode, *h_dir;
35
39
        struct dentry *wh;
36
 
        struct aufs_ndx ndx;
 
40
        struct au_ndx ndx;
 
41
        struct super_block *sb;
37
42
 
38
43
        LKTRTrace("wh %p, %.*s\n", wh_dentry, AuDLNPair(dentry));
39
44
 
41
46
        if (wh_dentry) {
42
47
                h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
43
48
                IMustLock(h_dir);
44
 
                bwh = dbwh(dentry);
45
 
                err = au_unlink_wh_dentry(h_dir, wh_dentry, dentry, dir,
 
49
                bwh = au_dbwh(dentry);
 
50
                err = au_wh_unlink_dentry(h_dir, wh_dentry, dentry, dir,
46
51
                                          /*dlgt*/0);
47
52
                //err = -1;
48
53
                if (unlikely(err))
56
61
                dir = dentry->d_parent->d_inode; /* dir inode is locked */
57
62
                IMustLock(dir);
58
63
                /* or always cpup dir mtime? */
59
 
                if (ibstart(dir) == dbstart(dentry))
 
64
                if (au_ibstart(dir) == au_dbstart(dentry))
60
65
                        au_cpup_attr_timesizes(dir);
61
66
                dir->i_version++;
62
67
                return 0; /* success */
67
72
                goto out;
68
73
 
69
74
        /* revert */
 
75
        sb = dentry->d_sb;
70
76
        ndx.flags = 0;
71
 
        if (unlikely(au_need_dlgt(dentry->d_sb)))
 
77
        if (unlikely(au_opt_test_dlgt(au_mntflags(sb))))
72
78
                au_fset_ndx(ndx.flags, DLGT);
73
 
        ndx.nfsmnt = au_nfsmnt(dentry->d_sb, bwh);
 
79
        ndx.nfsmnt = au_nfsmnt(sb, bwh);
74
80
        ndx.nd = NULL;
75
81
        //ndx.br = NULL;
76
82
        /* dir inode is locked */
77
 
        wh = simple_create_wh(dir, dentry, bwh, wh_dentry->d_parent, &ndx);
 
83
        wh = au_wh_create(dir, dentry, bwh, wh_dentry->d_parent, &ndx);
78
84
        //wh = ERR_PTR(-1);
79
85
        rerr = PTR_ERR(wh);
80
86
        if (!IS_ERR(wh)) {
95
101
 * following the checks in vfs, plus the parent-child relationship.
96
102
 */
97
103
int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
98
 
               struct dentry *h_parent, int isdir, struct aufs_ndx *ndx)
 
104
               struct dentry *h_parent, int isdir, struct au_ndx *ndx)
99
105
{
100
106
        int err, exist;
101
107
        struct dentry *h_dentry;
135
141
                goto out;
136
142
        err = 0;
137
143
 
138
 
        if (unlikely(au_flag_test_udba_inotify(dentry->d_sb))) {
 
144
        if (unlikely(au_opt_test(au_mntflags(dentry->d_sb), UDBA_INOTIFY))) {
139
145
                struct dentry *h_latest;
140
146
                struct qstr *qstr = &dentry->d_name;
141
147
 
142
148
                err = -EACCES;
143
 
                if (unlikely(au_test_perm
 
149
                if (unlikely(au_test_h_perm
144
150
                             (h_parent->d_inode, MAY_EXEC | MAY_WRITE,
145
151
                              au_ftest_ndx(ndx->flags, DLGT))))
146
152
                        goto out;
175
181
        int err;
176
182
        aufs_bindex_t bstart, bcpup;
177
183
        struct inode *dir, *h_dir, *gdir;
178
 
        struct aufs_ndx ndx;
 
184
        struct au_ndx ndx;
179
185
        struct super_block *sb;
180
 
        struct aufs_hinode *hgdir;
 
186
        struct au_hinode *hgdir;
 
187
        unsigned int mnt_flags;
181
188
 
182
189
        LKTRTrace("%.*s, src %p\n", AuDLNPair(dentry), src_dentry);
183
190
 
184
191
        parent = dentry->d_parent; /* dir inode is locked */
185
192
        IMustLock(parent->d_inode);
186
 
        bstart = dbstart(dentry);
 
193
        bstart = au_dbstart(dentry);
187
194
        err = au_wr_dir(dentry, src_dentry, wr_dir_args);
188
195
        bcpup = err;
189
196
        //err = -1;
192
199
                goto out;
193
200
 
194
201
        sb = parent->d_sb;
 
202
        mnt_flags = au_mntflags(sb);
195
203
        //todo: meaningless lock if CONFIG_AUFS_DEBUG is disabled.
196
204
        hgdir = NULL;
197
 
        if (unlikely(dt && au_flag_test_udba_inotify(sb) && !IS_ROOT(parent))) {
 
205
        if (unlikely(dt && au_opt_test(mnt_flags, UDBA_INOTIFY)
 
206
                     && !IS_ROOT(parent))) {
198
207
                gparent = dget_parent(parent);
199
208
                gdir = gparent->d_inode;
200
209
                ii_read_lock_parent2(gdir);
201
 
                hgdir = itohi(gdir, bcpup);
 
210
                hgdir = au_hi(gdir, bcpup);
202
211
                ii_read_unlock(gdir);
203
212
                dput(gparent);
204
213
        }
207
216
        h_dir = h_parent->d_inode;
208
217
 
209
218
        AuDbgSleep_UdbaRace();
210
 
        hdir_lock(h_dir, dir, bcpup);
 
219
        au_hdir_lock(h_dir, dir, bcpup);
211
220
 
212
221
        ndx.nfsmnt = au_nfsmnt(sb, bcpup);
213
222
        ndx.flags = 0;
214
 
        if (unlikely(au_need_dlgt(sb)))
 
223
        if (unlikely(au_opt_test_dlgt(mnt_flags)))
215
224
                au_fset_ndx(ndx.flags, DLGT);
216
225
        ndx.nd = NULL;
217
226
        //ndx.br = NULL;
218
227
        //ndx.nd_file = NULL;
219
228
 
220
 
        if (AuFlag(stosi(sb), f_udba) != AuUdba_NONE
221
 
            && dbstart(dentry) == bcpup) {
 
229
        if (!au_opt_test(mnt_flags, UDBA_NONE) && au_dbstart(dentry) == bcpup) {
222
230
                struct nameidata nd;
223
231
 
224
232
                if (unlikely(ndx.nfsmnt)) {
225
233
                        //todo: this is dirty hack
226
234
                        ndx.nd = &nd;
227
 
                        ndx.br = stobr(sb, bcpup);
 
235
                        ndx.br = au_sbr(sb, bcpup);
228
236
                        memset(&nd, 0, sizeof(nd));
229
237
                        nd.flags = LOOKUP_CREATE;
230
238
                        nd.intent.open.flags = O_EXCL;
242
250
        if (dt)
243
251
                au_dtime_store(dt, parent, h_parent, hgdir);
244
252
        wh_dentry = NULL;
245
 
        if (/* bcpup != bstart || */ bcpup != dbwh(dentry))
 
253
        if (/* bcpup != bstart || */ bcpup != au_dbwh(dentry))
246
254
                goto out; /* success */
247
255
 
248
 
        wh_dentry = lkup_wh(h_parent, &dentry->d_name, &ndx);
 
256
        wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, &ndx);
249
257
        //wh_dentry = ERR_PTR(-1);
250
258
 
251
259
 out_dir:
252
260
        if (IS_ERR(wh_dentry))
253
 
                hdir_unlock(h_dir, dir, bcpup);
 
261
                au_hdir_unlock(h_dir, dir, bcpup);
254
262
 out:
255
263
        AuTraceErrPtr(wh_dentry);
256
264
        return wh_dentry;
308
316
        h_dir = h_parent->d_inode;
309
317
        IMustLock(h_dir);
310
318
        sb = dir->i_sb;
311
 
        dlgt = au_need_dlgt(sb);
 
319
        dlgt = !!au_opt_test_dlgt(au_mntflags(sb));
312
320
 
313
321
#if 1 // partial testing
314
322
        switch (arg->type) {
315
323
        case Creat:
316
324
                AuDebugOn(au_test_nfs(h_dir->i_sb) && !arg->u.c.nd);
317
325
                err = au_h_create(h_dir, h_dentry, arg->u.c.mode, dlgt,
318
 
                                  arg->u.c.nd, au_nfsmnt(sb, dbstart(dentry)));
 
326
                                  arg->u.c.nd,
 
327
                                  au_nfsmnt(sb, au_dbstart(dentry)));
319
328
                break;
320
329
        case Symlink:
321
 
                err = vfsub_symlink(h_dir, h_dentry,
322
 
                                    arg->u.s.symname, S_IALLUGO, dlgt);
 
330
                err = vfsub_symlink(h_dir, h_dentry, arg->u.s.symname,
 
331
                                    S_IALLUGO, dlgt);
323
332
                break;
324
333
        case Mknod:
325
 
                err = vfsub_mknod(h_dir, h_dentry,
326
 
                                  arg->u.m.mode, arg->u.m.dev, dlgt);
 
334
                err = vfsub_mknod(h_dir, h_dentry, arg->u.m.mode, arg->u.m.dev,
 
335
                                  dlgt);
327
336
                break;
328
337
        default:
329
338
                BUG();
352
361
                d_drop(dentry);
353
362
        }
354
363
 
355
 
        hdir_unlock(h_dir, dir, dbstart(dentry));
 
364
        au_hdir_unlock(h_dir, dir, au_dbstart(dentry));
356
365
        dput(wh_dentry);
357
366
 
358
367
 out:
420
429
 
421
430
        gparent = NULL;
422
431
        gdir = NULL;
423
 
        if (unlikely(au_flag_test_udba_inotify(src_dentry->d_sb)
 
432
        if (unlikely(au_opt_test(au_mntflags(src_dentry->d_sb), UDBA_INOTIFY)
424
433
                     && !IS_ROOT(a->src_parent))) {
425
434
                gparent = dget_parent(a->src_parent);
426
435
                gdir = gparent->d_inode;
434
443
 
435
444
        if (!a->issamedir) {
436
445
                /* this temporary unlock/lock is safe */
437
 
                hdir_unlock(a->h_dir, dir, a->bdst);
 
446
                au_hdir_unlock(a->h_dir, dir, a->bdst);
438
447
                di_read_lock_parent2(a->src_parent, AuLock_IR);
439
448
                err = au_test_and_cpup_dirs(src_dentry, a->bdst, a->parent);
440
449
                //err = -1;
441
450
                if (unlikely(err)) {
442
 
                        hdir_lock(a->h_dir, dir, a->bdst);
 
451
                        au_hdir_lock(a->h_dir, dir, a->bdst);
443
452
                        goto out;
444
453
                }
445
454
 
447
456
                if (unlikely(gparent))
448
457
                        ii_read_lock_parent3(gdir);
449
458
                h_dir = au_h_iptr_i(src_dir, a->bdst);
450
 
                hdir_lock(h_dir, src_dir, a->bdst);
 
459
                au_hdir_lock(h_dir, src_dir, a->bdst);
451
460
        } else if (unlikely(gparent)) {
452
461
                /* this temporary unlock/lock is safe */
453
 
                hdir_unlock(a->h_dir, dir, a->bdst);
 
462
                au_hdir_unlock(a->h_dir, dir, a->bdst);
454
463
                ii_read_lock_parent3(gdir);
455
 
                hdir_lock(a->h_dir, dir, a->bdst);
 
464
                au_hdir_lock(a->h_dir, dir, a->bdst);
456
465
        }
457
466
        //todo: test parent-gparent relationship
458
467
 
469
478
 
470
479
 out:
471
480
        if (h_dir) {
472
 
                hdir_unlock(h_dir, src_dir, a->bdst);
473
 
                hdir_lock(a->h_dir, dir, a->bdst);
 
481
                au_hdir_unlock(h_dir, src_dir, a->bdst);
 
482
                au_hdir_lock(a->h_dir, dir, a->bdst);
474
483
        }
475
484
        if (!a->issamedir)
476
485
                di_read_unlock(a->src_parent, AuLock_IR);
493
502
        inode = src_dentry->d_inode;
494
503
        h_dentry = au_h_dptr(src_dentry);
495
504
        h_inode = h_dentry->d_inode;
496
 
        bstart = ibstart(inode);
 
505
        bstart = au_ibstart(inode);
497
506
        h_dst_inode = NULL;
498
507
        if (bstart <= a->bdst)
499
508
                h_dst_inode = au_h_iptr_i(inode, a->bdst);
500
509
 
501
510
        if (!h_dst_inode || !h_dst_inode->i_nlink) {
502
511
                /* copyup src_dentry as the name of dentry. */
503
 
                set_dbstart(src_dentry, a->bdst);
504
 
                set_h_dptr(src_dentry, a->bdst, dget(a->h_dentry));
 
512
                au_set_dbstart(src_dentry, a->bdst);
 
513
                au_set_h_dptr(src_dentry, a->bdst, dget(a->h_dentry));
505
514
                vfsub_i_lock_nested(h_inode, AuLsc_I_CHILD);
506
515
                err = au_sio_cpup_single(src_dentry, a->bdst, a->bsrc, -1,
507
516
                                         !AuCpup_DTIME);
508
517
                //err = -1;
509
518
                vfsub_i_unlock(h_inode);
510
 
                set_h_dptr(src_dentry, a->bdst, NULL);
511
 
                set_dbstart(src_dentry, a->bsrc);
 
519
                au_set_h_dptr(src_dentry, a->bdst, NULL);
 
520
                au_set_dbstart(src_dentry, a->bsrc);
512
521
        } else {
513
522
                /* the inode of src_dentry already exists on a.bdst branch */
514
523
                h_dentry = d_find_alias(h_dst_inode);
524
533
        }
525
534
 
526
535
        if (!err)
527
 
                au_append_plink(sb, a->inode, a->h_dentry, a->bdst);
 
536
                au_plink_append(sb, a->inode, a->h_dentry, a->bdst);
528
537
 
529
538
        AuTraceErr(err);
530
539
        return err;
538
547
        struct au_dtime dt;
539
548
        struct link_arg a;
540
549
        struct super_block *sb;
 
550
        unsigned int mnt_flags;
541
551
        struct vfsub_args vargs;
542
552
        struct au_wr_dir_args wr_dir_args = {
543
553
                //.force_btgt   = -1,
558
568
        a.issamedir = (a.src_parent == a.parent);
559
569
        if (!a.issamedir)
560
570
                au_fset_wrdir(wr_dir_args.flags, LOCK_SRCDIR);
561
 
        wr_dir_args.force_btgt = dbstart(src_dentry);
 
571
        wr_dir_args.force_btgt = au_dbstart(src_dentry);
562
572
        di_write_lock_parent(a.parent);
563
573
        wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
564
574
        wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &wr_dir_args);
574
584
        IMustLock(a.h_dir);
575
585
 
576
586
        err = 0;
577
 
        a.dlgt = au_need_dlgt(sb);
 
587
        mnt_flags = au_mntflags(sb);
 
588
        a.dlgt = !!au_opt_test_dlgt(mnt_flags);
578
589
 
579
590
        //todo: minor optimize, their sb may be same while their bindex differs.
580
 
        a.bsrc = dbstart(src_dentry);
581
 
        a.bdst = dbstart(dentry);
 
591
        a.bsrc = au_dbstart(src_dentry);
 
592
        a.bdst = au_dbstart(dentry);
582
593
        h_src_dentry = au_h_dptr(src_dentry);
583
 
        if (unlikely(!AuFlag(stosi(sb), f_plink))) {
 
594
        if (unlikely(!au_opt_test(mnt_flags, PLINK))) {
584
595
                /*
585
596
                 * copyup src_dentry to the branch we process,
586
597
                 * and then link(2) to it.
610
621
        if (unlikely(err))
611
622
                goto out_unlock;
612
623
        if (wh_dentry) {
613
 
                err = au_unlink_wh_dentry(a.h_dir, wh_dentry, dentry,
 
624
                err = au_wh_unlink_dentry(a.h_dir, wh_dentry, dentry,
614
625
                                          dir, /*dlgt*/0);
615
626
                //err = -1;
616
627
                if (unlikely(err))
630
641
#endif
631
642
 
632
643
        dir->i_version++;
633
 
        if (ibstart(dir) == dbstart(dentry))
 
644
        if (au_ibstart(dir) == au_dbstart(dentry))
634
645
                au_cpup_attr_timesizes(dir);
635
646
        if (!d_unhashed(a.h_dentry)
636
647
            /* || h_old_inode->i_nlink <= nlink */
648
659
        //au_debug_off();
649
660
        {
650
661
                aufs_bindex_t i;
651
 
                for (i = ibstart(a.inode); i <= ibend(a.inode); i++) {
652
 
                        struct xino_entry xinoe;
 
662
                for (i = au_ibstart(a.inode); i <= au_ibend(a.inode); i++) {
 
663
                        struct au_xino_entry xinoe;
653
664
                        struct inode *hi;
654
665
                        hi = au_h_iptr_i(a.inode, i);
655
666
                        if (hi) {
656
 
                                xino_read(sb, i, hi->i_ino, &xinoe);
 
667
                                au_xino_read(sb, i, hi->i_ino, &xinoe);
657
668
                                AuDbg("hi%lu, i%lu\n", hi->i_ino, xinoe.ino);
658
669
                        }
659
670
                }
671
682
                /* do not superio. */
672
683
                d = au_lkup_one(name->name, a.h_dentry->d_parent,
673
684
                                name->len, au_nfsmnt(sb, a.bdst)??,
674
 
                                au_need_dlgt(sb));
 
685
                                au_opt_test_dlgt(mnt_flags));
675
686
                rerr = PTR_ERR(d);
676
687
                if (IS_ERR(d))
677
688
                        goto out_rerr;
693
704
        d_drop(dentry);
694
705
        au_dtime_revert(&dt);
695
706
 out_unlock:
696
 
        hdir_unlock(a.h_dir, dir, a.bdst);
 
707
        au_hdir_unlock(a.h_dir, dir, a.bdst);
697
708
        dput(wh_dentry);
698
709
 out:
699
710
        if (unlikely(err)) {
710
721
int aufs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
711
722
{
712
723
        int err, rerr, diropq, dlgt;
713
 
        struct dentry *h_dentry, *h_parent, *wh_dentry, *parent,
714
 
                *opq_dentry;
 
724
        struct dentry *h_dentry, *h_parent, *wh_dentry, *parent, *opq_dentry;
715
725
        struct inode *h_dir, *h_inode;
716
726
        struct au_dtime dt;
717
727
        aufs_bindex_t bindex;
718
728
        struct super_block *sb;
 
729
        unsigned int mnt_flags;
719
730
        struct vfsub_args vargs;
720
731
        struct au_wr_dir_args wr_dir_args = {
721
732
                .force_btgt     = -1,
737
748
                goto out;
738
749
 
739
750
        sb = dentry->d_sb;
740
 
        bindex = dbstart(dentry);
 
751
        bindex = au_dbstart(dentry);
741
752
        h_dentry = au_h_dptr(dentry);
742
753
        h_parent = h_dentry->d_parent; /* dir inode is locked */
743
754
        h_dir = h_parent->d_inode;
744
755
        IMustLock(h_dir);
745
 
        dlgt = au_need_dlgt(sb);
 
756
        mnt_flags = au_mntflags(sb);
 
757
        dlgt = !!au_opt_test_dlgt(mnt_flags);
746
758
 
747
759
        err = vfsub_mkdir(h_dir, h_dentry, mode, dlgt);
748
760
        //err = -1;
752
764
 
753
765
        /* make the dir opaque */
754
766
        diropq = 0;
755
 
        if (wh_dentry || AuFlag(stosi(sb), f_always_diropq)) {
 
767
        if (wh_dentry || au_opt_test(mnt_flags, ALWAYS_DIROPQ)) {
756
768
                vfsub_i_lock_nested(h_inode, AuLsc_I_CHILD);
757
 
                opq_dentry = create_diropq(dentry, bindex, /*dlgt*/0);
 
769
                opq_dentry = au_diropq_create(dentry, bindex, /*dlgt*/0);
758
770
                //opq_dentry = ERR_PTR(-1);
759
771
                vfsub_i_unlock(h_inode);
760
772
                err = PTR_ERR(opq_dentry);
775
787
        if (diropq) {
776
788
                LKTRLabel(revert opq);
777
789
                vfsub_i_lock_nested(h_inode, AuLsc_I_CHILD);
778
 
                rerr = remove_diropq(dentry, bindex, dlgt);
 
790
                rerr = au_diropq_remove(dentry, bindex, dlgt);
779
791
                //rerr = -1;
780
792
                vfsub_i_unlock(h_inode);
781
793
                if (rerr) {
798
810
        d_drop(dentry);
799
811
        au_dtime_revert(&dt);
800
812
 out_unlock:
801
 
        hdir_unlock(h_dir, dir, bindex);
 
813
        au_hdir_unlock(h_dir, dir, bindex);
802
814
        dput(wh_dentry);
803
815
 out:
804
816
        if (unlikely(err)) {