-void ext3_discard_prealloc (struct inode * inode)
-{
-#ifdef EXT3_PREALLOCATE
- struct ext3_inode_info *ei = EXT3_I(inode);
- /* Writer: ->i_prealloc* */
- if (ei->i_prealloc_count) {
- unsigned short total = ei->i_prealloc_count;
- unsigned long block = ei->i_prealloc_block;
- ei->i_prealloc_count = 0;
- ei->i_prealloc_block = 0;
- /* Writer: end */
- ext3_free_blocks (inode, block, total);
- }
-#endif
-}
-
-static int ext3_alloc_block (handle_t *handle,
- struct inode * inode, unsigned long goal, int *err)
-{
- unsigned long result;
-
-#ifdef EXT3_PREALLOCATE
-#ifdef EXT3FS_DEBUG
- static unsigned long alloc_hits, alloc_attempts;
-#endif
- struct ext3_inode_info *ei = EXT3_I(inode);
- /* Writer: ->i_prealloc* */
- if (ei->i_prealloc_count &&
- (goal == ei->i_prealloc_block ||
- goal + 1 == ei->i_prealloc_block))
- {
- result = ei->i_prealloc_block++;
- ei->i_prealloc_count--;
- /* Writer: end */
- ext3_debug ("preallocation hit (%lu/%lu).\n",
- ++alloc_hits, ++alloc_attempts);
- } else {
- ext3_discard_prealloc (inode);
- ext3_debug ("preallocation miss (%lu/%lu).\n",
- alloc_hits, ++alloc_attempts);
- if (S_ISREG(inode->i_mode))
- result = ext3_new_block (inode, goal,
- &ei->i_prealloc_count,
- &ei->i_prealloc_block, err);
- else
- result = ext3_new_block (inode, goal, 0, 0, err);
- /*
- * AKPM: this is somewhat sticky. I'm not surprised it was
- * disabled in 2.2's ext3. Need to integrate b_committed_data
- * guarding with preallocation, if indeed preallocation is
- * effective.
- */
- }
-#else
- result = ext3_new_block (handle, inode, goal, 0, 0, err);
-#endif
- return result;
-}
-
-