Skip to contentSkip to conversation

ext4: Add the EXT4_IOC_FREE_BLOCKS_INFO ioctl

RFC PATCH In review Akira Fujita 1 participant 1 message Sep 27, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 7/12 ext4: Add the EXT4_IOC_FREE_BLOCKS_INFO ioctl

ext4: online defrag -- Add the EXT4_IOC_FREE_BLOCKS_INFO ioctl.

From: Akira Fujita <[email protected]>

The EXT4_IOC_FREE_BLOCKS_INFO ioctl gets free extents information of the target block group.
This ioctl is used only in the force defrag (-f).

Defragger calculates the victim extents (which will be moved
into other block group in order to make contiguous free space for the target file) based on used/unused extents information.

---
 fs/ext4/balloc.c |    2 +-
 fs/ext4/defrag.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/ext4.h   |   27 +++++++++++++
 fs/ext4/ioctl.c  |    3 +-
 4 files changed, 142 insertions(+), 2 deletions(-)
fs/ext4/balloc.c +1 -1
index 02068fa..64ec04c 100644
@@ -919,7 +919,7 @@ static int ext4_test_allocatable(ext4_grpblk_t nr, struct buffer_head *bh)
  * bitmap on disk and the last-committed copy in journal, until we find a
  * bit free in both bitmaps.
  */
-static ext4_grpblk_t
+ext4_grpblk_t
 bitmap_search_next_usable_block(ext4_grpblk_t start, struct buffer_head *bh,
 					ext4_grpblk_t maxblocks)
 {
fs/ext4/defrag.c +112 -0

124 lines not on this page · raw message

fs/ext4/ext4.h +27 -0
index a635a76..ffe687b 100644
@@ -305,6 +305,7 @@ struct ext4_new_group_data {
 #define EXT4_IOC_DEFRAG			_IOW('f', 15, struct ext4_ext_defrag_data)
 #define EXT4_IOC_FIBMAP			_IOW('f', 16, ext4_fsblk_t)
 #define EXT4_IOC_GROUP_INFO		_IOW('f', 17, struct ext4_group_data_info)
+#define EXT4_IOC_FREE_BLOCKS_INFO	_IOW('f', 18, struct ext4_extents_info)
 
 /*
  * ioctl commands in 32 bit emulation
@@ -322,6 +323,20 @@ struct ext4_new_group_data {
 #define EXT4_IOC32_GETVERSION_OLD	FS_IOC32_GETVERSION
 #define EXT4_IOC32_SETVERSION_OLD	FS_IOC32_SETVERSION
 
+/*
+ * The following four macros are used for the defrag force mode.
+ *
+ * DEFRAG_MAX_ENT:	the maximum number of extents for exchanging between
+ *			kernel-space and user-space per an ioctl
+ */
+#define DEFRAG_MAX_ENT		32
+
+struct ext4_extent_data {
+	ext4_lblk_t block;		/* start logical block number */
+	ext4_fsblk_t start;		/* start physical block number */
+	int len;			/* blocks count */
+};
+
 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 */
@@ -333,6 +348,16 @@ struct ext4_group_data_info {
 	int s_inodes_per_group;		/* inodes per group */
 };
 
+struct ext4_extents_info {
+	unsigned long long ino;		/* inode number */
+	int max_entries;		/* maximum extents count */
+	int entries;			/* extent number/count */
+	ext4_lblk_t f_offset;		/* file offset */
+	ext4_grpblk_t g_offset;		/* group offset */
+	ext4_fsblk_t goal;		/* block offset for allocation */
+	struct ext4_extent_data ext[DEFRAG_MAX_ENT];
+};
+
 #define EXT4_TRANS_META_BLOCKS 4 /* bitmap + group desc + sb + inode */
 
 /*
@@ -1015,6 +1040,8 @@ extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
 extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
 extern void ext4_init_block_alloc_info(struct inode *);
 extern void ext4_rsv_window_add(struct super_block *sb, struct ext4_reserve_window_node *rsv);
+extern ext4_grpblk_t bitmap_search_next_usable_block(ext4_grpblk_t,
+				struct buffer_head *, ext4_grpblk_t);
 
 /* dir.c */
 extern int ext4_check_dir_entry(const char *, struct inode *,
fs/ext4/ioctl.c +2 -1
index c05502f..40bc2e1 100644
@@ -258,7 +258,8 @@ setversion_out:
 	}
 	case EXT4_IOC_FIBMAP:
 	case EXT4_IOC_DEFRAG:
-	case EXT4_IOC_GROUP_INFO: {
+	case EXT4_IOC_GROUP_INFO:
+	case EXT4_IOC_FREE_BLOCKS_INFO: {
 		return ext4_defrag_ioctl(inode, filp, cmd, arg);
 	}
 	case EXT4_IOC_GROUP_ADD: {