3 * Copyright (C) 2005-2009
4 * Neil Brown <neilb@suse.de>
5 * Released under the GPL, version 2
10 * Every time blocks are allocated or deallocated, we must track them:
15 void lafs_summary_update(struct fs *fs, struct inode *ino,
16 u64 oldphys, u64 newphys,
17 int is_index, int phase, int moveref)
19 /* Whether writing a block or truncating, we hold a reference
20 * to ->iblock, so can access it without locking
22 struct lafs_inode *lai;
25 if (oldphys && newphys) {
26 // FIXME what snapshot should I use?
27 lafs_seg_move(fs, oldphys, newphys, 0, phase, moveref);
30 if (oldphys == 0 && newphys == 0)
34 future = (phase != !!test_bit(B_Phase1, &lai->iblock->b.flags));
41 spin_lock(&ino->i_lock);
44 lai->piblocks += diff;
49 lai->ciblocks += diff;
58 1 << (fs->blocksize_bits - 9);
60 spin_unlock(&ino->i_lock);
63 lai = LAFSI(lai->filesys);
64 spin_lock(&lai->vfs_inode.i_lock);
66 lai->md.fs.pblocks_used += diff;
68 lai->md.fs.cblocks_used += diff;
71 BUG_ON(lai->md.fs.ablocks_used == 0 && diff > 0);
73 lai->md.fs.ablocks_used--;
75 spin_unlock(&lai->vfs_inode.i_lock);
77 /* per user/group/tree */
79 lafs_qcommit(fs, ino, diff, phase);
81 // FIXME what snapshot should I use?
82 lafs_seg_move(fs, oldphys, newphys, 0, phase, moveref);
85 int lafs_summary_allocate(struct fs *fs, struct inode *ino, int diff)
87 /* this is where quota checks happen */
89 struct lafs_inode *lai = LAFSI(ino);
90 lai = LAFSI(LAFSI(ino)->filesys);
91 spin_lock(&lai->vfs_inode.i_lock);
92 if (lai->md.fs.blocks_allowed &&
94 lai->md.fs.cblocks_used +
95 lai->md.fs.pblocks_used +
96 lai->md.fs.ablocks_used + diff
97 > lai->md.fs.blocks_allowed)
100 lai->md.fs.ablocks_used += diff;
102 spin_unlock(&lai->vfs_inode.i_lock);
106 err = lafs_quota_allocate(fs, ino, diff * fs->blocksize);
108 spin_lock(&lai->vfs_inode.i_lock);
109 lai->md.fs.ablocks_used -= diff;
110 spin_unlock(&lai->vfs_inode.i_lock);
115 spin_lock(&ino->i_lock);
116 lai->ablocks += diff;
117 ino->i_blocks += (blkcnt_t)diff << (fs->blocksize_bits - 9) ;
118 spin_unlock(&ino->i_lock);