extents.c (4255c224b97f6d286d9d791962dec2b02c652b42) extents.c (0f2af21aae11972fa924374ddcf52e88347cf5a8)
1/*
2 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com
3 * Written by Alex Tomas <alex@clusterfs.com>
4 *
5 * Architecture independence:
6 * Copyright (c) 2005, Bull S.A.
7 * Written by Pierre Peiffer <pierre.peiffer@bull.net>
8 *

--- 4783 unchanged lines hidden (view full) ---

4792
4793 lblk = start >> blkbits;
4794 max_blocks = (end >> blkbits);
4795 if (max_blocks < lblk)
4796 max_blocks = 0;
4797 else
4798 max_blocks -= lblk;
4799
1/*
2 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com
3 * Written by Alex Tomas <alex@clusterfs.com>
4 *
5 * Architecture independence:
6 * Copyright (c) 2005, Bull S.A.
7 * Written by Pierre Peiffer <pierre.peiffer@bull.net>
8 *

--- 4783 unchanged lines hidden (view full) ---

4792
4793 lblk = start >> blkbits;
4794 max_blocks = (end >> blkbits);
4795 if (max_blocks < lblk)
4796 max_blocks = 0;
4797 else
4798 max_blocks -= lblk;
4799
4800 flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT |
4801 EXT4_GET_BLOCKS_CONVERT_UNWRITTEN |
4802 EXT4_EX_NOCACHE;
4803 if (mode & FALLOC_FL_KEEP_SIZE)
4804 flags |= EXT4_GET_BLOCKS_KEEP_SIZE;
4805
4806 mutex_lock(&inode->i_mutex);
4807
4808 /*
4809 * Indirect files do not support unwritten extnets
4810 */
4811 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
4812 ret = -EOPNOTSUPP;
4813 goto out_mutex;
4814 }
4815
4816 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
4817 offset + len > i_size_read(inode)) {
4818 new_size = offset + len;
4819 ret = inode_newsize_ok(inode, new_size);
4820 if (ret)
4821 goto out_mutex;
4800 mutex_lock(&inode->i_mutex);
4801
4802 /*
4803 * Indirect files do not support unwritten extnets
4804 */
4805 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
4806 ret = -EOPNOTSUPP;
4807 goto out_mutex;
4808 }
4809
4810 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
4811 offset + len > i_size_read(inode)) {
4812 new_size = offset + len;
4813 ret = inode_newsize_ok(inode, new_size);
4814 if (ret)
4815 goto out_mutex;
4822 /*
4823 * If we have a partial block after EOF we have to allocate
4824 * the entire block.
4825 */
4826 if (partial_end)
4827 max_blocks += 1;
4828 }
4829
4816 }
4817
4818 flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT;
4819 if (mode & FALLOC_FL_KEEP_SIZE)
4820 flags |= EXT4_GET_BLOCKS_KEEP_SIZE;
4821
4822 /* Preallocate the range including the unaligned edges */
4823 if (partial_begin || partial_end) {
4824 ret = ext4_alloc_file_blocks(file,
4825 round_down(offset, 1 << blkbits) >> blkbits,
4826 (round_up((offset + len), 1 << blkbits) -
4827 round_down(offset, 1 << blkbits)) >> blkbits,
4828 new_size, flags, mode);
4829 if (ret)
4830 goto out_mutex;
4831
4832 }
4833
4834 /* Zero range excluding the unaligned edges */
4830 if (max_blocks > 0) {
4835 if (max_blocks > 0) {
4836 flags |= (EXT4_GET_BLOCKS_CONVERT_UNWRITTEN |
4837 EXT4_EX_NOCACHE);
4831
4832 /* Now release the pages and zero block aligned part of pages*/
4833 truncate_pagecache_range(inode, start, end - 1);
4834 inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
4835
4836 /* Wait all existing dio workers, newcomers will block on i_mutex */
4837 ext4_inode_block_unlocked_dio(inode);
4838 inode_dio_wait(inode);

--- 861 unchanged lines hidden ---
4838
4839 /* Now release the pages and zero block aligned part of pages*/
4840 truncate_pagecache_range(inode, start, end - 1);
4841 inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
4842
4843 /* Wait all existing dio workers, newcomers will block on i_mutex */
4844 ext4_inode_block_unlocked_dio(inode);
4845 inode_dio_wait(inode);

--- 861 unchanged lines hidden ---