Skip to contentSkip to conversation

Extent micro cleanups

PATCH In review Mingming Cao 2 participants 3 messages Jul 1, 2007 – Jul 11, 2007

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

PATCH 5/5 Extent micro cleanups

From: Dmitry Monakhov <[email protected]>
Subject: ext4: extent macros cleanup

- Replace math equation to it's macro equivalent
- make ext4_ext_grow_indepth() indexes/leaf correct

---
 fs/ext4/extents.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
fs/ext4/extents.c +7 -4
index 12fe3d7..1fd00ac 100644
@@ -375,7 +375,7 @@ ext4_ext_binsearch_idx(struct inode *inode, struct ext4_ext_path *path, int bloc
 	ext_debug("binsearch for %d(idx):  ", block);
 
 	l = EXT_FIRST_INDEX(eh) + 1;
-	r = EXT_FIRST_INDEX(eh) + le16_to_cpu(eh->eh_entries) - 1;
+	r = EXT_LAST_INDEX(eh);
 	while (l <= r) {
 		m = l + (r - l) / 2;
 		if (block < le32_to_cpu(m->ei_block))
@@ -440,7 +440,7 @@ ext4_ext_binsearch(struct inode *inode, struct ext4_ext_path *path, int block)
 	ext_debug("binsearch for %d:  ", block);
 
 	l = EXT_FIRST_EXTENT(eh) + 1;
-	r = EXT_FIRST_EXTENT(eh) + le16_to_cpu(eh->eh_entries) - 1;
+	r = EXT_LAST_EXTENT(eh);
 
 	while (l <= r) {
 		m = l + (r - l) / 2;
@@ -922,8 +922,11 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
 	curp->p_hdr->eh_max = cpu_to_le16(ext4_ext_space_root_idx(inode));
 	curp->p_hdr->eh_entries = cpu_to_le16(1);
 	curp->p_idx = EXT_FIRST_INDEX(curp->p_hdr);
-	/* FIXME: it works, but actually path[0] can be index */
-	curp->p_idx->ei_block = EXT_FIRST_EXTENT(path[0].p_hdr)->ee_block;
+	
+	if (path[0].p_hdr->eh_depth)
+	  curp->p_idx->ei_block = EXT_FIRST_INDEX(path[0].p_hdr)->ei_block;
+	else
+	  curp->p_idx->ei_block = EXT_FIRST_EXTENT(path[0].p_hdr)->ee_block;
 	ext4_idx_store_pblock(curp->p_idx, newblock);
 
 	neh = ext_inode_hdr(inode);
#1 lore raw
Quoted 4 lines · On Sun, 01 Jul 2007 03:38:59 -0400 Mingming Cao <[email protected]> wrote:

From: Dmitry Monakhov <[email protected]>
Subject: ext4: extent macros cleanup

- Replace math equation to it's macro equivalent

s/it's/its/;)

Quoted 1 line

- make ext4_ext_grow_indepth() indexes/leaf correct

hm, what was wrong with it?

Quoted 30 lines
---
 fs/ext4/extents.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
fs/ext4/extents.c +2 -2
index 12fe3d7..1fd00ac 100644
@@ -375,7 +375,7 @@ ext4_ext_binsearch_idx(struct inode *inode, struct ext4_ext_path *path, int bloc
 	ext_debug("binsearch for %d(idx):  ", block);
 
 	l = EXT_FIRST_INDEX(eh) + 1;
-	r = EXT_FIRST_INDEX(eh) + le16_to_cpu(eh->eh_entries) - 1;
+	r = EXT_LAST_INDEX(eh);
 	while (l <= r) {
 		m = l + (r - l) / 2;
 		if (block < le32_to_cpu(m->ei_block))
@@ -440,7 +440,7 @@ ext4_ext_binsearch(struct inode *inode, struct ext4_ext_path *path, int block)
 	ext_debug("binsearch for %d:  ", block);
 
 	l = EXT_FIRST_EXTENT(eh) + 1;
-	r = EXT_FIRST_EXTENT(eh) + le16_to_cpu(eh->eh_entries) - 1;
+	r = EXT_LAST_EXTENT(eh);
 
 	while (l <= r) {
 		m = l + (r - l) / 2;

fs/ext4/extents.c static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode, · line 929

Quoted 10 lines
fs/ext4/extents.c +5 -2
@@ -922,8 +922,11 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
 	curp->p_hdr->eh_max = cpu_to_le16(ext4_ext_space_root_idx(inode));
 	curp->p_hdr->eh_entries = cpu_to_le16(1);
 	curp->p_idx = EXT_FIRST_INDEX(curp->p_hdr);
-	/* FIXME: it works, but actually path[0] can be index */
-	curp->p_idx->ei_block = EXT_FIRST_EXTENT(path[0].p_hdr)->ee_block;
+	
+	if (path[0].p_hdr->eh_depth)
+	  curp->p_idx->ei_block = EXT_FIRST_INDEX(path[0].p_hdr)->ei_block;
+	else
+	  curp->p_idx->ei_block = EXT_FIRST_EXTENT(path[0].p_hdr)->ee_block;

whitespace bustage there.

#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Sun, 01 Jul 2007 03:38:59 -0400 Mingming Cao <[email protected]> wrote:

From: Dmitry Monakhov <[email protected]>
Subject: ext4: extent macros cleanup

- Replace math equation to it's macro equivalent

s/it's/its/;)

Okay.

Quoted 5 lines
Quoted 2 lines

- make ext4_ext_grow_indepth() indexes/leaf correct

hm, what was wrong with it?

Looking at the code, ext4_ext_ext_grow_indepth() implements tree growing procedure. It allocates a new index block, moves the top-level data of the tree(root or leaf blocks in i_data) into the new block, initializes the new root, creating index that points to the just created index block

The original top-level data (in i_data) could be extent tree root (index block) or extents (leaf block). The current code (without the patch) treats the top-level data always be the leaf block, which is incorrect.

assumes when the tree is growing the extent structure pass in is always

Quoted 19 lines

fs/ext4/extents.c static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode, · line 929

Quoted 11 lines
fs/ext4/extents.c +5 -2
@@ -922,8 +922,11 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
 	curp->p_hdr->eh_max = cpu_to_le16(ext4_ext_space_root_idx(inode));
 	curp->p_hdr->eh_entries = cpu_to_le16(1);
 	curp->p_idx = EXT_FIRST_INDEX(curp->p_hdr);
-	/* FIXME: it works, but actually path[0] can be index */
-	curp->p_idx->ei_block = EXT_FIRST_EXTENT(path[0].p_hdr)->ee_block;
+	
+	if (path[0].p_hdr->eh_depth)
+	  curp->p_idx->ei_block = EXT_FIRST_INDEX(path[0].p_hdr)->ei_block;
+	else
+	  curp->p_idx->ei_block = EXT_FIRST_EXTENT(path[0].p_hdr)->ee_block;

whitespace bustage there.

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html