Comments
Patch
@@ -709,9 +709,11 @@ errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle)
{
int retval = 0;
+ int orig_height;
blk64_t start;
struct extent_path *path;
struct ext2fs_extent extent;
+ struct ext2_extent_info info;
EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE);
@@ -732,6 +734,10 @@ errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle)
/* modified node's start block */
start = extent.e_lblk;
+ if ((retval = ext2fs_extent_get_info(handle, &info)))
+ return retval;
+ orig_height = info.max_depth - info.curr_level;
+
/* traverse up until index not first, or startblk matches, or top */
while (handle->level > 0 &&
(path->left == path->entries - 1)) {
@@ -750,7 +756,7 @@ errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle)
}
/* put handle back to where we started */
- retval = ext2fs_extent_goto(handle, start);
+ retval = extent_goto(handle, orig_height, start);
done:
return retval;
}
@@ -1943,6 +1949,23 @@ void do_print_all(int argc, char **argv)
}
}
+void do_fix_parents(int argc, char **argv)
+{
+ struct ext2fs_extent extent;
+ struct ext2_extent_info info;
+ errcode_t retval;
+
+ if (common_extent_args_process(argc, argv, 1, 1, "fix_parents", "",
+ CHECK_FS_RW))
+ return;
+
+ retval = ext2fs_extent_fix_parents(current_handle);
+ if (retval) {
+ com_err(argv[0], retval, 0);
+ return;
+ }
+}
+
void do_info(int argc, char **argv)
{
struct ext2fs_extent extent;
@@ -55,6 +55,9 @@ request do_insert_node, "Insert node",
request do_split_node, "Split node",
split_node, split;
+request do_fix_parents, "Fix parents",
+ fix_parents, fixp;
+
request do_set_bmap, "Set block mapping",
set_bmap;
Previously, ext2fs_extent_fix_parents() would only avoid modifying the cursor location associated with the extent handle the cursor was pointed at a leaf node in the extent tree. This is because it saved the starting logical block number of the current extent, but not the "level" of the extent (where level 0 is the leaf node, level 1 is the interior node which points at blocks containing leaf nodes, etc.) Fix ext2fs_extent_fix_parents() so it is guaranteed to not change the current extent in the handle even if the current extent is not at the bottom of the tree. Also add a fix_extent command to the tst_extents program to make it easier to test this function. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> --- lib/ext2fs/extent.c | 25 ++++++++++++++++++++++++- lib/ext2fs/extent_dbg.ct | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-)