ext4: main function of defrag and ioctl implementation
Subsystems (2)
RFC PATCH 1/8 ext4: main function of defrag and ioctl implementation
ext4: online defrag-- Main function of defrag and ioctl implementation
From: Akira Fujita <[email protected]>
Create the temporary inode and do defrag perdefrag_size (defalut 64MB).
Signed-off-by Akira Fujita <[email protected]>
Signed-off-by Takashi Sato <[email protected]>
--- fs/ext4/Makefile | 2 +- fs/ext4/defrag.c | 448 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/ext4.h | 18 ++ fs/ext4/ext4_extents.h | 2 + fs/ext4/extents.c | 2 +- fs/ext4/ioctl.c | 3 + 6 files changed, 473 insertions(+), 2 deletions(-)
fs/ext4/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_EXT4DEV_FS) += ext4dev.o ext4dev-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \ ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \ - ext4_jbd2.o migrate.o mballoc.o + ext4_jbd2.o migrate.o mballoc.o defrag.o ext4dev-$(CONFIG_EXT4DEV_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext4dev-$(CONFIG_EXT4DEV_FS_POSIX_ACL) += acl.o
fs/ext4/defrag.c +448 -0
448 lines not on this page · raw message
fs/ext4/ext4.h +18 -0
@@ -298,6 +298,7 @@ struct ext4_new_group_data {#define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)#define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)#define EXT4_IOC_MIGRATE _IO('f', 7) +#define EXT4_IOC_DEFRAG _IOW('f', 10, struct ext4_ext_defrag_data)/* * ioctl commands in 32 bit emulation
@@ -315,6 +316,18 @@ struct ext4_new_group_data {#define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION +/* +* Will go away. +* ext4 online defrag supports only 4KB block size. +*/ +#define DEFRAG_BLOCK_SIZE 4096 + +struct ext4_ext_defrag_data { +ext4_lblk_t start_offset;/* start offset to defrag in blocks */ +ext4_lblk_t defrag_size;/* size of defrag in blocks */ +ext4_fsblk_t goal;/* block offset for allocation */ +}; +/* * Mount options
@@ -1113,6 +1126,11 @@ extern void ext4_inode_bitmap_set(struct super_block *sb, struct ext4_group_desc *bg, ext4_fsblk_t blk);extern void ext4_inode_table_set (struct super_block *sb,struct ext4_group_desc *bg,ext4_fsblk_t blk); +/* defrag.c */ +extern int ext4_defrag (struct file *filp,ext4_lblk_t block_start, +ext4_lblk_t defrag_size); +extern int ext4_defrag_ioctl (struct inode *,struct file *,unsigned int , +unsigned long );static inline ext4_fsblk_t ext4_blocks_count (struct ext4_super_block *es) {
fs/ext4/ext4_extents.h +2 -0
@@ -228,5 +228,7 @@ extern int ext4_ext_search_left(struct inode *, struct ext4_ext_path *,extern int ext4_ext_search_right (struct inode *,struct ext4_ext_path *,ext4_lblk_t *,ext4_fsblk_t *);extern void ext4_ext_drop_refs (struct ext4_ext_path *); +extern ext4_fsblk_t ext_pblock (struct ext4_extent *ex); +extern void ext4_ext_drop_refs (struct ext4_ext_path *path);#endif /* _EXT4_EXTENTS */
fs/ext4/extents.c +1 -1
@@ -48,7 +48,7 @@* ext_pblock: * combine low and high parts of physical block number into ext4_fsblk_t */ -static ext4_fsblk_t ext_pblock (struct ext4_extent *ex) +ext4_fsblk_t ext_pblock (struct ext4_extent *ex) {ext4_fsblk_t block;
fs/ext4/ioctl.c +3 -0
@@ -241,6 +241,9 @@ setversion_out:return err; } +case EXT4_IOC_DEFRAG : { +return ext4_defrag_ioctl (inode, filp, cmd, arg); + }case EXT4_IOC_GROUP_ADD : {struct ext4_new_group_data input;struct super_block *sb = inode->i_sb;