~ubuntu-branches/ubuntu/vivid/aufs/vivid

« back to all changes in this revision

Viewing changes to fs/aufs25/xino.c

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2008-08-21 14:58:54 UTC
  • mfrom: (1.1.8 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080821145854-4b49x09r4zmvlk5o
Tags: 0+20080719-4
01_vserver_apparmor.dpatch: [UPDATE] Disable vserver patches on kernel 
2.6.26, because they are not needed anymore. (Closes: #495921)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
/*
20
20
 * external inode number translation table and bitmap
21
21
 *
22
 
 * $Id: xino.c,v 1.8 2008/06/02 02:36:59 sfjro Exp $
 
22
 * $Id: xino.c,v 1.11 2008/07/14 00:17:57 sfjro Exp $
23
23
 */
24
24
 
25
25
#include <linux/uaccess.h>
146
146
        aufs_bindex_t bindex;
147
147
        int err;
148
148
        struct file *file;
 
149
        struct inode *dir;
149
150
 
150
151
        err = 0;
151
152
        sb = args->sb;
 
153
        dir = sb->s_root->d_inode;
152
154
        si_noflush_write_lock(sb);
 
155
        ii_read_lock_parent(dir);
153
156
        bindex = au_br_index(sb, args->br->br_id);
154
157
        AuDebugOn(bindex < 0);
155
158
        err = au_xino_trunc(sb, bindex);
156
159
        if (unlikely(err))
157
160
                goto out;
158
161
 
159
 
        file = args->br->br_xino;
 
162
        file = args->br->br_xino.xi_file;
160
163
        au_update_fuse_h_inode(args->br->br_mnt, file->f_dentry); /*ignore*/
161
164
        if (file->f_dentry->d_inode->i_blocks >= args->br->br_xino_upper)
162
165
                args->br->br_xino_upper += AUFS_XINO_TRUNC_STEP;
163
166
 
164
167
 out:
 
168
        ii_read_unlock(dir);
165
169
        si_write_unlock(sb);
166
170
        if (unlikely(err))
167
171
                AuWarn("err b%d, (%d)\n", bindex, err);
176
180
{
177
181
        struct xino_do_trunc_args *args;
178
182
        struct au_sbinfo *sbinfo;
179
 
        struct file *file = br->br_xino;
 
183
        struct file *file = br->br_xino.xi_file;
180
184
        int wkq_err;
181
185
 
182
186
        au_update_fuse_h_inode(br->br_mnt, file->f_dentry); /*ignore*/
186
190
                goto out;
187
191
 
188
192
        /* lock and kfree() will be called in trunc_xino() */
189
 
        args = kmalloc(sizeof(*args), GFP_TEMPORARY);
 
193
        args = kmalloc(sizeof(*args), GFP_NOFS);
190
194
        if (unlikely(!args)) {
191
195
                AuErr1("no memory\n");
192
196
                goto out_args;
261
265
                return 0;
262
266
 
263
267
        br = au_sbr(sb, bindex);
264
 
        file = br->br_xino;
 
268
        file = br->br_xino.xi_file;
265
269
        AuDebugOn(!file);
266
270
 
267
271
        err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, h_ino, xinoe);
455
459
 
456
460
        LKTRTrace("b%d, hi%lu\n", bindex, h_ino);
457
461
 
458
 
        if (unlikely(!au_opt_test_xino(au_mntflags(sb))))
459
 
                return 0; /* no ino */
460
 
 
461
 
        err = 0;
462
462
        xinoe->ino = 0;
 
463
        if (unlikely(!au_opt_test_xino(au_mntflags(sb))))
 
464
                return 0; /* no ino */
 
465
 
 
466
        err = 0;
463
467
        sbinfo = au_sbi(sb);
464
468
        pos = h_ino;
465
469
        if (unlikely(Au_LOFF_MAX / sizeof(*xinoe) - 1 < pos)) {
468
472
        }
469
473
        pos *= sizeof(*xinoe);
470
474
 
471
 
        file = au_sbr(sb, bindex)->br_xino;
 
475
        file = au_sbr(sb, bindex)->br_xino.xi_file;
472
476
        AuDebugOn(!file);
473
477
        if (i_size_read(file->f_dentry->d_inode) < pos + sizeof(*xinoe))
474
478
                return 0; /* no ino */
489
493
 
490
494
/* ---------------------------------------------------------------------- */
491
495
 
492
 
struct file *au_xino_create(struct super_block *sb, char *fname, int silent,
493
 
                            struct dentry *parent)
 
496
struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
494
497
{
495
498
        struct file *file;
496
499
        int err;
500
503
 
501
504
        LKTRTrace("%s\n", fname);
502
505
 
503
 
        /* LSM may detect it */
 
506
        /*
 
507
         * at mount-time, and the xino file is the default path,
 
508
         * hinotify is disabled so we have no inotify events to ignore.
 
509
         * when a user specified the xino, we cannot get au_hdir to be ignored.
 
510
         */
 
511
        vfsub_args_init(&vargs, /*ign*/NULL, /*dlgt*/0, 0);
504
512
        file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE,
505
513
                               S_IRUGO | S_IWUGO);
506
514
        if (IS_ERR(file)) {
512
520
        /* keep file count */
513
521
        h_parent = dget_parent(file->f_dentry);
514
522
        h_dir = h_parent->d_inode;
515
 
        vfsub_args_init(&vargs, NULL, 0, 0);
516
523
        mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
517
524
        err = vfsub_unlink(h_dir, file->f_dentry, &vargs);
518
525
        mutex_unlock(&h_dir->i_mutex);
546
553
        aufs_bindex_t bindex;
547
554
        struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
548
555
 
549
 
        for (bindex = 0; bindex <= bend; bindex++)
550
 
                if (unlikely(btgt != bindex && tgt_sb == au_sbr_sb(sb, bindex)))
 
556
        for (bindex = 0; bindex < btgt; bindex++)
 
557
                if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
 
558
                        return bindex;
 
559
        for (bindex++; bindex <= bend; bindex++)
 
560
                if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
551
561
                        return bindex;
552
562
        return -1;
553
563
}
564
574
        struct dentry *base, *dentry, *parent;
565
575
        struct inode *dir, *inode;
566
576
        struct qstr *name;
 
577
        struct au_hinode *hdir;
 
578
        struct au_branch *br;
 
579
        aufs_bindex_t bindex;
 
580
        struct au_hin_ignore ign;
567
581
        struct vfsub_args vargs;
568
582
        struct au_ndx ndx = {
569
583
                .nfsmnt = NULL,
590
604
                AuErr("%.*s lookup err %ld\n", AuLNPair(name), PTR_ERR(dentry));
591
605
                goto out;
592
606
        }
593
 
        err = vfsub_create(dir, dentry, S_IRUGO | S_IWUGO, NULL, /*dlgt*/0);
 
607
 
 
608
        hdir = NULL;
 
609
        br = au_sbi(sb)->si_xino_def_br;
 
610
        if (br) {
 
611
                bindex = au_find_bindex(sb, br);
 
612
                if (bindex >= 0)
 
613
                        hdir = au_hi(sb->s_root->d_inode, bindex);
 
614
        }
 
615
        vfsub_args_init(&vargs, &ign, 0, 0);
 
616
        vfsub_ign_hinode(&vargs, IN_CREATE, hdir);
 
617
        err = vfsub_create(dir, dentry, S_IRUGO | S_IWUGO, NULL, &vargs);
594
618
        if (unlikely(err)) {
595
619
                file = ERR_PTR(err);
596
620
                AuErr("%.*s create err %d\n", AuLNPair(name), err);
602
626
                AuErr("%.*s open err %ld\n", AuLNPair(name), PTR_ERR(file));
603
627
                goto out_dput;
604
628
        }
605
 
        vfsub_args_init(&vargs, NULL, 0, 0);
 
629
        vfsub_args_reinit(&vargs);
 
630
        vfsub_ign_hinode(&vargs, IN_DELETE, hdir);
606
631
        err = vfsub_unlink(dir, dentry, &vargs);
607
632
        if (unlikely(err)) {
608
633
                AuErr("%.*s unlink err %d\n", AuLNPair(name), err);
611
636
 
612
637
        if (copy_src) {
613
638
                inode = copy_src->f_dentry->d_inode;
614
 
                err = au_copy_file(file, copy_src, i_size_read(inode), sb);
 
639
                err = au_copy_file(file, copy_src, i_size_read(inode),
 
640
                                   hdir, sb);
615
641
                if (unlikely(err)) {
616
642
                        AuErr("%.*s copy err %d\n", AuLNPair(name), err);
617
643
                        goto out_fput;
651
677
        LKTRTrace("base_file %p, do_test %d\n", base_file, do_test);
652
678
        SiMustWriteLock(sb);
653
679
        AuDebugOn(!au_opt_test_xino(au_mntflags(sb)));
654
 
        AuDebugOn(br->br_xino);
 
680
        AuDebugOn(br->br_xino.xi_file);
655
681
 
656
682
        do_create = 1;
657
683
        bshared = -1;
669
695
        }
670
696
        if (unlikely(bshared >= 0)) {
671
697
                shared_br = au_sbr(sb, bshared);
672
 
                do_create = !shared_br->br_xino;
 
698
                do_create = !shared_br->br_xino.xi_file;
673
699
        }
674
700
 
675
701
        if (do_create) {
678
704
 
679
705
                mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
680
706
                file = au_xino_create2(sb, base_file, NULL);
681
 
                err = PTR_ERR(file);
682
707
                mutex_unlock(&dir->i_mutex);
683
708
                dput(parent);
 
709
                err = PTR_ERR(file);
684
710
                if (IS_ERR(file))
685
711
                        goto out;
686
 
                br->br_xino = file;
 
712
                br->br_xino.xi_file = file;
687
713
        } else {
688
 
                br->br_xino = shared_br->br_xino;
689
 
                get_file(br->br_xino);
 
714
                br->br_xino.xi_file = shared_br->br_xino.xi_file;
 
715
                get_file(br->br_xino.xi_file);
690
716
        }
691
717
 
692
718
        xinoe.ino = AUFS_ROOT_INO;
694
720
        xinoe.h_gen = h_inode->i_generation;
695
721
        WARN_ON(xinoe.h_gen == AuXino_INVALID_HGEN);
696
722
#endif
697
 
        err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino, h_ino,
698
 
                               &xinoe);
 
723
        err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
 
724
                               h_ino, &xinoe);
699
725
        if (!err)
700
726
                return 0; /* success */
701
727
 
763
789
        AuTraceEnter();
764
790
 
765
791
        err = -ENOMEM;
766
 
        page = (void *)__get_free_page(GFP_TEMPORARY);
 
792
        page = (void *)__get_free_page(GFP_NOFS);
767
793
        if (unlikely(!page))
768
794
                goto out;
769
795
 
772
798
        for (bindex = 0; !err && bindex <= bend; bindex++)
773
799
                if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
774
800
                        err = do_xib_restore
775
 
                                (sb, au_sbr(sb, bindex)->br_xino, page);
 
801
                                (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
776
802
                else
777
803
                        LKTRTrace("b%d\n", bindex);
778
804
        free_page((unsigned long)page);
925
951
 
926
952
        err = -ENOMEM;
927
953
        if (!sbinfo->si_xib_buf)
928
 
                sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_KERNEL);
 
954
                sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
929
955
        if (unlikely(!sbinfo->si_xib_buf))
930
956
                goto out_unset;
931
957
 
970
996
        bend = au_sbend(sb);
971
997
        for (bindex = 0; bindex <= bend; bindex++) {
972
998
                br = au_sbr(sb, bindex);
973
 
                if (unlikely(!br || !br->br_xino))
 
999
                if (unlikely(!br || !br->br_xino.xi_file))
974
1000
                        continue;
975
1001
 
976
 
                fput(br->br_xino);
977
 
                br->br_xino = NULL;
 
1002
                fput(br->br_xino.xi_file);
 
1003
                br->br_xino.xi_file = NULL;
978
1004
        }
979
1005
}
980
1006
 
995
1021
 
996
1022
        err = -ENOMEM;
997
1023
        bend = au_sbend(sb);
998
 
        fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_TEMPORARY);
 
1024
        fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
999
1025
        if (unlikely(!fpair))
1000
1026
                goto out;
1001
1027
 
1013
1039
 
1014
1040
                if (!p->new) {
1015
1041
                        /* new xino */
1016
 
                        p->old = br->br_xino;
1017
 
                        p->new = au_xino_create2(sb, base, br->br_xino);
 
1042
                        p->old = br->br_xino.xi_file;
 
1043
                        p->new = au_xino_create2(sb, base, br->br_xino.xi_file);
1018
1044
                        err = PTR_ERR(p->new);
1019
1045
                        if (IS_ERR(p->new)) {
1020
1046
                                p->new = NULL;
1030
1056
 
1031
1057
        for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
1032
1058
                br = au_sbr(sb, bindex);
1033
 
                AuDebugOn(p->old != br->br_xino);
1034
 
                if (br->br_xino)
1035
 
                        fput(br->br_xino);
 
1059
                AuDebugOn(p->old != br->br_xino.xi_file);
 
1060
                if (br->br_xino.xi_file)
 
1061
                        fput(br->br_xino.xi_file);
1036
1062
                get_file(p->new);
1037
 
                br->br_xino = p->new;
 
1063
                br->br_xino.xi_file = p->new;
1038
1064
        }
1039
1065
 
1040
1066
 out_pair:
1051
1077
 
1052
1078
void au_xino_clr(struct super_block *sb)
1053
1079
{
 
1080
        struct au_sbinfo *sbinfo;
 
1081
 
1054
1082
        AuTraceEnter();
1055
1083
        SiMustWriteLock(sb);
1056
1084
 
1057
1085
        xino_clear_xib(sb);
1058
1086
        xino_clear_br(sb);
 
1087
        sbinfo = au_sbi(sb);
1059
1088
        /* lvalue, do not call au_mntflags() */
1060
 
        au_opt_clr(au_sbi(sb)->si_mntflags, XINO);
 
1089
        au_opt_clr(sbinfo->si_mntflags, XINO);
 
1090
        sbinfo->si_xino_def_br = NULL;
1061
1091
}
1062
1092
 
1063
1093
int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
1093
1123
        }
1094
1124
 
1095
1125
        au_opt_set(sbinfo->si_mntflags, XINO);
 
1126
        sbinfo->si_xino_def_br = NULL;
1096
1127
        dir = parent->d_inode;
1097
1128
        mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
1098
1129
        err = au_xino_set_xib(sb, xino->file);
1131
1162
        if (unlikely(bindex < 0 || bend < bindex))
1132
1163
                goto out;
1133
1164
        br = au_sbr(sb, bindex);
1134
 
        if (unlikely(!br->br_xino))
 
1165
        if (unlikely(!br->br_xino.xi_file))
1135
1166
                goto out;
1136
1167
 
1137
 
        parent = dget_parent(br->br_xino->f_dentry);
 
1168
        parent = dget_parent(br->br_xino.xi_file->f_dentry);
1138
1169
        dir = parent->d_inode;
1139
1170
        mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
1140
 
        new_xino = au_xino_create2(sb, br->br_xino, br->br_xino);
 
1171
        new_xino = au_xino_create2(sb, br->br_xino.xi_file,
 
1172
                                   br->br_xino.xi_file);
1141
1173
        mutex_unlock(&dir->i_mutex);
1142
1174
        dput(parent);
1143
1175
        err = PTR_ERR(new_xino);
1144
1176
        if (IS_ERR(new_xino))
1145
1177
                goto out;
1146
1178
        err = 0;
1147
 
        fput(br->br_xino);
1148
 
        br->br_xino = new_xino;
 
1179
        fput(br->br_xino.xi_file);
 
1180
        br->br_xino.xi_file = new_xino;
1149
1181
 
1150
1182
        h_sb = br->br_mnt->mnt_sb;
1151
1183
        for (bi = 0; bi <= bend; bi++) {
1155
1187
                if (br->br_mnt->mnt_sb != h_sb)
1156
1188
                        continue;
1157
1189
 
1158
 
                fput(br->br_xino);
1159
 
                br->br_xino = new_xino;
 
1190
                fput(br->br_xino.xi_file);
 
1191
                br->br_xino.xi_file = new_xino;
1160
1192
                get_file(new_xino);
1161
1193
        }
1162
1194
 
1176
1208
        aufs_bindex_t bend, bindex, bwr;
1177
1209
        char *page, *p;
1178
1210
        struct path path;
 
1211
        struct dentry *root;
1179
1212
 
1180
1213
        AuTraceEnter();
1181
1214
 
 
1215
        root = sb->s_root;
1182
1216
        bend = au_sbend(sb);
1183
1217
        bwr = -1;
1184
1218
        for (bindex = 0; bindex <= bend; bindex++)
1185
1219
                if (au_br_writable(au_sbr_perm(sb, bindex))
1186
 
                    && !au_test_nfs(au_h_dptr(sb->s_root, bindex)->d_sb)) {
 
1220
                    && !au_test_nfs(au_h_dptr(root, bindex)->d_sb)) {
1187
1221
                        bwr = bindex;
1188
1222
                        break;
1189
1223
                }
1194
1228
                if (unlikely(!page))
1195
1229
                        goto out;
1196
1230
                path.mnt = au_sbr_mnt(sb, bwr);
1197
 
                path.dentry = au_h_dptr(sb->s_root, bwr);
 
1231
                path.dentry = au_h_dptr(root, bwr);
1198
1232
                p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
1199
1233
                file = (void *)p;
1200
1234
                if (p && !IS_ERR(p)) {
1201
1235
                        strcat(p, "/" AUFS_XINO_FNAME);
1202
1236
                        LKTRTrace("%s\n", p);
1203
 
                        file = au_xino_create(sb, p, /*silent*/0, sb->s_root);
 
1237
                        file = au_xino_create(sb, p, /*silent*/0);
 
1238
                        if (!IS_ERR(file))
 
1239
                                au_sbi(sb)->si_xino_def_br = au_sbr(sb, bwr);
1204
1240
                }
1205
1241
                __putname(page);
1206
1242
        } else {
1207
 
                file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
1208
 
                                      /*parent*/NULL);
 
1243
                file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
1209
1244
                if (unlikely(au_test_nfs(file->f_dentry->d_sb))) {
1210
1245
                        AuErr("xino or noxino option is required "
1211
1246
                              "since %s is NFS\n", AUFS_XINO_DEFPATH);
1212
1247
                        fput(file);
1213
1248
                        file = ERR_PTR(-EINVAL);
1214
1249
                }
 
1250
                if (!IS_ERR(file))
 
1251
                        au_sbi(sb)->si_xino_def_br = NULL;
1215
1252
        }
1216
1253
 
1217
1254
 out: