aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/extents.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-04-03 22:04:52 -0400
committerTheodore Ts'o <tytso@mit.edu>2013-04-03 22:04:52 -0400
commit996bb9fddd5b68d1dfb5e27d30ca2c7a72448596 (patch)
treea066fe717c593c2189f886612fbe1282cfb7fdcc /fs/ext4/extents.c
parentd76a3a77113db020d9bb1e894822869410450bd9 (diff)
ext4: support simple conversion of extent-mapped inodes to use i_blocks
In order to make it simpler to test the code which support i_blocks/indirect-mapped inodes, support the conversion of inodes which are less than 12 blocks and which are contained in no more than a single extent. The primary intended use of this code is to converting freshly created zero-length files and empty directories. Note that the version of chattr in e2fsprogs 1.42.7 and earlier has a check that prevents the clearing of the extent flag. A simple patch which allows "chattr -e <file>" to work will be checked into the e2fsprogs git repository. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r--fs/ext4/extents.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index cbbe8a4deac6..235246719074 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4610,3 +4610,62 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4610 4610
4611 return error; 4611 return error;
4612} 4612}
4613
4614/*
4615 * Migrate a simple extent-based inode to use the i_blocks[] array
4616 */
4617int ext4_ind_migrate(struct inode *inode)
4618{
4619 struct ext4_extent_header *eh;
4620 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
4621 struct ext4_inode_info *ei = EXT4_I(inode);
4622 struct ext4_extent *ex;
4623 unsigned int i, len;
4624 ext4_fsblk_t blk;
4625 handle_t *handle;
4626 int ret;
4627
4628 if (!EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb,
4629 EXT4_FEATURE_INCOMPAT_EXTENTS) ||
4630 (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
4631 return -EINVAL;
4632
4633 down_write(&EXT4_I(inode)->i_data_sem);
4634 ret = ext4_ext_check_inode(inode);
4635 if (ret)
4636 goto errout;
4637
4638 eh = ext_inode_hdr(inode);
4639 ex = EXT_FIRST_EXTENT(eh);
4640 if (ext4_blocks_count(es) > EXT4_MAX_BLOCK_FILE_PHYS ||
4641 eh->eh_depth != 0 || eh->eh_entries > 1) {
4642 ret = -EOPNOTSUPP;
4643 goto errout;
4644 }
4645 if (eh->eh_entries == 0)
4646 blk = len = 0;
4647 else {
4648 len = le16_to_cpu(ex->ee_len);
4649 blk = ext4_ext_pblock(ex);
4650 if (len > EXT4_NDIR_BLOCKS) {
4651 ret = -EOPNOTSUPP;
4652 goto errout;
4653 }
4654 }
4655
4656 handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, 1);
4657 if (IS_ERR(handle)) {
4658 ret = PTR_ERR(handle);
4659 goto errout;
4660 }
4661
4662 ext4_clear_inode_flag(inode, EXT4_INODE_EXTENTS);
4663 memset(ei->i_data, 0, sizeof(ei->i_data));
4664 for (i=0; i < len; i++)
4665 ei->i_data[i] = cpu_to_le32(blk++);
4666 ext4_mark_inode_dirty(handle, inode);
4667 ext4_journal_stop(handle);
4668errout:
4669 up_write(&EXT4_I(inode)->i_data_sem);
4670 return ret;
4671}