~ubuntu-branches/ubuntu/quantal/aufs/quantal

« back to all changes in this revision

Viewing changes to fs/aufs/wbr_policy.c

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2008-04-01 18:26:37 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080401182637-ujuqq47eiggw4y5w
Tags: 0+20080401-1
* New upstream snapshot
  - Remove bashisms in script (Closes: #471288)
* debian/conf.mk, linux-patch-aufs.kpatches.sysfs_get_dentry:
  - Remove support for this patch, no longer used
* debian/conf.mk:
  - Add hacks for arm to armel (Closes: #473767)
* debian/control:
  - Add Dm-Upload-Allowed
* debian/copyright:
  - Use http://wiki.debian.org/Proposals/CopyrightFormat
* debian/linux-patch-aufs.kpatches.{splice,put_filp}:
  - Add support for Kernel 2.6.24 (and 2.6.25)
* debian/patches:
  - 01_vserver_apparmor: Update patch
  - 06_rt: Add patch for realtime kernel
  - 07_splice_hack: Add hack to support splice operations (Closes: #473430)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2007 Junjiro Okajima
 
2
 * Copyright (C) 2007, 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: wbr_policy.c,v 1.5 2007/11/26 01:34:50 sfjro Exp $ */
 
19
/* $Id: wbr_policy.c,v 1.8 2008/03/16 23:46:30 sfjro Exp $ */
20
20
 
21
21
#include <linux/statfs.h>
22
22
#include "aufs.h"
60
60
 
61
61
struct au_cpdown_dir_args {
62
62
        struct dentry *parent;
63
 
        unsigned int parent_opq:1;
 
63
        unsigned int parent_opq; // bit-flags
64
64
};
65
65
 
66
66
static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
86
86
                goto out;
87
87
        h_dentry = au_h_dptr_i(dentry, bdst);
88
88
        dlgt = au_need_dlgt(dentry->d_sb);
89
 
        err = vfsub_sio_mkdir(h_dir, h_dentry, 0755, dlgt);
 
89
        err = vfsub_sio_mkdir(h_dir, h_dentry, S_IRWXU | S_IRUGO | S_IXUGO,
 
90
                              dlgt);
90
91
        if (unlikely(err))
91
92
                goto out_put;
92
93
 
189
190
 
190
191
/* ---------------------------------------------------------------------- */
191
192
 
192
 
#if 0
193
 
/*
194
 
 * returns writable branch index, otherwise an error.
195
 
 * todo: customizable writable-branch-policy
196
 
 */
197
 
static int find_rw_parent(struct dentry *dentry, aufs_bindex_t bend)
198
 
{
199
 
        int err;
200
 
        aufs_bindex_t bindex, candidate;
201
 
        struct super_block *sb;
202
 
        struct dentry *parent, *hidden_parent;
203
 
 
204
 
        err = bend;
205
 
        sb = dentry->d_sb;
206
 
        parent = dget_parent(dentry);
207
 
#if 1 // branch policy
208
 
        hidden_parent = au_h_dptr_i(parent, bend);
209
 
        if (hidden_parent && !br_rdonly(stobr(sb, bend)))
210
 
                goto out; /* success */
211
 
#endif
212
 
 
213
 
        candidate = -1;
214
 
        for (bindex = dbstart(parent); bindex <= bend; bindex++) {
215
 
                hidden_parent = au_h_dptr_i(parent, bindex);
216
 
                if (hidden_parent && !br_rdonly(stobr(sb, bindex))) {
217
 
#if 0 // branch policy
218
 
                        if (candidate == -1)
219
 
                                candidate = bindex;
220
 
                        if (!au_test_perm(hidden_parent->d_inode, MAY_WRITE))
221
 
                                return bindex;
222
 
#endif
223
 
                        err = bindex;
224
 
                        goto out; /* success */
225
 
                }
226
 
        }
227
 
#if 0 // branch policy
228
 
        err = candidate;
229
 
        if (candidate != -1)
230
 
                goto out; /* success */
231
 
#endif
232
 
        err = -EROFS;
233
 
 
234
 
 out:
235
 
        dput(parent);
236
 
        return err;
237
 
}
238
 
 
239
 
int find_rw_br(struct super_block *sb, aufs_bindex_t bend)
240
 
{
241
 
        aufs_bindex_t bindex;
242
 
 
243
 
        for (bindex = bend; bindex >= 0; bindex--)
244
 
                if (!br_rdonly(stobr(sb, bindex)))
245
 
                        return bindex;
246
 
        return -EROFS;
247
 
}
248
 
 
249
 
int find_rw_parent_br(struct dentry *dentry, aufs_bindex_t bend)
250
 
{
251
 
        int err;
252
 
 
253
 
        err = find_rw_parent(dentry, bend);
254
 
        if (err >= 0)
255
 
                return err;
256
 
        return find_rw_br(dentry->d_sb, bend);
257
 
}
258
 
 
259
 
#if 0 // branch policy
260
 
/*
261
 
 * dir_cpdown/nodir_cpdown(def)
262
 
 * wr_br_policy=dir | branch
263
 
 */
264
 
int au_rw(struct dentry *dentry, aufs_bindex_t bend)
265
 
{
266
 
        int err;
267
 
        struct super_block *sb;
268
 
 
269
 
        sb = dentry->d_sb;
270
 
        SiMustAnyLock(sb);
271
 
 
272
 
        if (!au_flag_test(sb, AuFlag_DIR_CPDOWN)) {
273
 
                dpages;
274
 
        }
275
 
}
276
 
#endif
277
 
#endif
278
 
 
279
 
/* ---------------------------------------------------------------------- */
280
 
 
281
193
/* policies for create */
282
194
 
283
195
static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
291
203
/* top down parent */
292
204
static int au_wbr_create_tdp(struct dentry *dentry, int isdir)
293
205
{
294
 
        int err;
 
206
        int err, dirperm1;
295
207
        struct super_block *sb;
296
208
        aufs_bindex_t bstart, bindex;
297
209
        struct dentry *parent, *h_parent;
 
210
        struct inode *h_dir;
298
211
 
299
212
        LKTRTrace("%.*s, dir %d\n", AuDLNPair(dentry), isdir);
300
213
 
301
214
        sb = dentry->d_sb;
 
215
        dirperm1 = au_need_dirperm1(sb);
302
216
        bstart = dbstart(dentry);
303
217
        err = bstart;
304
218
        if (!br_rdonly(stobr(sb, bstart)))
308
222
        parent = dget_parent(dentry);
309
223
        for (bindex = dbstart(parent); bindex < bstart; bindex++) {
310
224
                h_parent = au_h_dptr_i(parent, bindex);
311
 
                if (h_parent && !br_rdonly(stobr(sb, bindex))) {
312
 
                        err = bindex;
313
 
                        break;
 
225
                if (!h_parent)
 
226
                        continue;
 
227
                h_dir = h_parent->d_inode;
 
228
                if (!h_dir)
 
229
                        continue;
 
230
 
 
231
                if (!br_rdonly(stobr(sb, bindex))
 
232
                    && (!dirperm1
 
233
                        || au_test_perm(h_dir, MAY_WRITE | MAY_EXEC,
 
234
                                        /*dlgt*/0))) {
 
235
                                err = bindex;
 
236
                                break;
314
237
                }
315
238
        }
316
239
        dput(parent);
576
499
/* top down parent and most free space */
577
500
static int au_wbr_create_pmfs(struct dentry *dentry, int isdir)
578
501
{
579
 
        int err, e2;
 
502
        int err, e2, dirperm1;
580
503
        struct super_block *sb;
581
 
        struct dentry *parent;
 
504
        struct dentry *parent, *h_parent;
582
505
        aufs_bindex_t bindex, bstart, bend;
583
506
        struct aufs_branch *br;
584
507
        u64 b;
 
508
        struct inode *h_dir;
585
509
 
586
510
        //au_debug_on();
587
511
        LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), isdir);
596
520
                goto out_parent; /* success */
597
521
 
598
522
        e2 = au_wbr_create_mfs(dentry, isdir);
599
 
        if (unlikely(e2 < 0))
 
523
        if (e2 < 0)
600
524
                goto out_parent; /* success */
601
525
 
602
526
        /* when the available size is equal, select upper one */
603
527
        sb = dentry->d_sb;
604
528
        br = stobr(sb, err);
 
529
        dirperm1 = au_need_dirperm1(sb);
605
530
        b = br->br_bytes;
606
531
        LKTRTrace("b%d, %Lu\n", err, b);
 
532
 
 
533
        if (unlikely(dirperm1)) {
 
534
                for (bindex = bstart; bindex <= bend; bindex++) {
 
535
                        h_parent = au_h_dptr_i(parent, bindex);
 
536
                        if (!h_parent)
 
537
                                continue;
 
538
                        h_dir = h_parent->d_inode;
 
539
                        if (!h_dir)
 
540
                                continue;
 
541
 
 
542
                        br = stobr(sb, bindex);
 
543
                        if (!br_rdonly(br)
 
544
                            && au_test_perm(h_dir, MAY_WRITE | MAY_EXEC,
 
545
                                            /*dlgt*/0)
 
546
                            && br->br_bytes > b) {
 
547
                                b = br->br_bytes;
 
548
                                err = bindex;
 
549
                                LKTRTrace("b%d, %Lu\n", err, b);
 
550
                        }
 
551
                }
 
552
                if (err >= 0)
 
553
                        goto out_parent;
 
554
        }
607
555
        for (bindex = bstart; bindex <= bend; bindex++) {
608
 
                if (!au_h_dptr_i(parent, bindex))
 
556
                h_parent = au_h_dptr_i(parent, bindex);
 
557
                if (!h_parent || !h_parent->d_inode)
609
558
                        continue;
 
559
 
610
560
                br = stobr(sb, bindex);
611
561
                if (!br_rdonly(br) && br->br_bytes > b) {
612
562
                        b = br->br_bytes;
636
586
/* bottom up parent */
637
587
static int au_wbr_copyup_bup(struct dentry *dentry)
638
588
{
639
 
        int err;
 
589
        int err, dirperm1;
640
590
        struct dentry *parent, *h_parent;
641
591
        aufs_bindex_t bindex, bstart;
642
592
        struct super_block *sb;
 
593
        struct inode *h_dir;
643
594
 
644
595
        LKTRTrace("%.*s\n", AuDLNPair(dentry));
645
596
 
646
597
        err = -EROFS;
647
598
        sb = dentry->d_sb;
 
599
        dirperm1 = au_need_dirperm1(sb);
648
600
        parent = dget_parent(dentry);
649
601
        bstart = dbstart(parent);
650
602
        for (bindex = dbstart(dentry); bindex >= bstart; bindex--) {
651
603
                h_parent = au_h_dptr_i(parent, bindex);
652
 
                if (h_parent && !br_rdonly(stobr(sb, bindex))) {
 
604
                if (!h_parent)
 
605
                        continue;
 
606
                h_dir = h_parent->d_inode;
 
607
                if (!h_dir)
 
608
                        continue;
 
609
 
 
610
                if (!br_rdonly(stobr(sb, bindex))
 
611
                    && (!dirperm1
 
612
                        || au_test_perm(h_dir, MAY_WRITE | MAY_EXEC,
 
613
                                        /*dlgt*/0))) {
653
614
                        err = bindex;
654
615
                        break;
655
616
                }