diff options
author | Mingming Cao <cmm@us.ibm.com> | 2008-07-14 17:52:37 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2008-07-14 17:52:37 -0400 |
commit | d2a1763791a634e315ec926b62829c1e88842c86 (patch) | |
tree | 75a701a89829ba7d728fdc19c30aa2794b9706b9 /fs/ext4/extents.c | |
parent | e8ced39d5e8911c662d4d69a342b9d053eaaac4e (diff) |
ext4: delayed allocation ENOSPC handling
This patch does block reservation for delayed
allocation, to avoid ENOSPC later at page flush time.
Blocks(data and metadata) are reserved at da_write_begin()
time, the freeblocks counter is updated by then, and the number of
reserved blocks is store in per inode counter.
At the writepage time, the unused reserved meta blocks are returned
back. At unlink/truncate time, reserved blocks are properly released.
Updated fix from Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
to fix the oldallocator block reservation accounting with delalloc, added
lock to guard the counters and also fix the reservation for meta blocks.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r-- | fs/ext4/extents.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 7844bbb2bac0..dabc3b68d249 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -248,6 +248,36 @@ static int ext4_ext_space_root_idx(struct inode *inode) | |||
248 | return size; | 248 | return size; |
249 | } | 249 | } |
250 | 250 | ||
251 | /* | ||
252 | * Calculate the number of metadata blocks needed | ||
253 | * to allocate @blocks | ||
254 | * Worse case is one block per extent | ||
255 | */ | ||
256 | int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks) | ||
257 | { | ||
258 | int lcap, icap, rcap, leafs, idxs, num; | ||
259 | int newextents = blocks; | ||
260 | |||
261 | rcap = ext4_ext_space_root_idx(inode); | ||
262 | lcap = ext4_ext_space_block(inode); | ||
263 | icap = ext4_ext_space_block_idx(inode); | ||
264 | |||
265 | /* number of new leaf blocks needed */ | ||
266 | num = leafs = (newextents + lcap - 1) / lcap; | ||
267 | |||
268 | /* | ||
269 | * Worse case, we need separate index block(s) | ||
270 | * to link all new leaf blocks | ||
271 | */ | ||
272 | idxs = (leafs + icap - 1) / icap; | ||
273 | do { | ||
274 | num += idxs; | ||
275 | idxs = (idxs + icap - 1) / icap; | ||
276 | } while (idxs > rcap); | ||
277 | |||
278 | return num; | ||
279 | } | ||
280 | |||
251 | static int | 281 | static int |
252 | ext4_ext_max_entries(struct inode *inode, int depth) | 282 | ext4_ext_max_entries(struct inode *inode, int depth) |
253 | { | 283 | { |
@@ -2910,7 +2940,7 @@ retry: | |||
2910 | } | 2940 | } |
2911 | ret = ext4_get_blocks_wrap(handle, inode, block, | 2941 | ret = ext4_get_blocks_wrap(handle, inode, block, |
2912 | max_blocks, &map_bh, | 2942 | max_blocks, &map_bh, |
2913 | EXT4_CREATE_UNINITIALIZED_EXT, 0); | 2943 | EXT4_CREATE_UNINITIALIZED_EXT, 0, 0); |
2914 | if (ret <= 0) { | 2944 | if (ret <= 0) { |
2915 | #ifdef EXT4FS_DEBUG | 2945 | #ifdef EXT4FS_DEBUG |
2916 | WARN_ON(ret <= 0); | 2946 | WARN_ON(ret <= 0); |