summaryrefslogtreecommitdiff
path: root/e2fsck/pass3.c
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2013-12-10 17:22:07 -0800
committerTheodore Ts'o <tytso@mit.edu>2013-12-12 13:27:08 -0500
commit4b58df1a53f517d700d921714610d1cec524dc92 (patch)
tree2850abcb5c2d65c6db041c72eabf067caf32eb20 /e2fsck/pass3.c
parent042a0f52ec79e448fd798df7757c6addeb00aede (diff)
downloade2fsprogs-4b58df1a53f517d700d921714610d1cec524dc92.tar.gz
e2fsck: in rehash, mark newly allocated extent blocks as found
When we're rehashing directories, it's possible that an extent block (or a map block) could be (silently) allocated by the underlying libext2fs when expanding the directory. This silent allocation is not captured in block_found_map, which is disastrous if later the rehash process expands another directory and uses that same block from before without realizing that it's now in use. Therefore, if we notice that the free block count has dropped by more than what e2fsck allocated itself during the expansion, we iterate the directory's blocks a second time to ensure that these silent allocations are marked in the found blocks bitmap. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'e2fsck/pass3.c')
-rw-r--r--e2fsck/pass3.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c
index fd8ec34e..d7a243e4 100644
--- a/e2fsck/pass3.c
+++ b/e2fsck/pass3.c
@@ -752,6 +752,27 @@ static int expand_dir_proc(ext2_filsys fs,
return BLOCK_CHANGED;
}
+/*
+ * Ensure that all blocks are marked in the block_found_map, since it's
+ * possible that the library allocated an extent node block or a block map
+ * block during the directory rebuilding; these new allocations are not
+ * captured in block_found_map. This is bad since we could later use
+ * block_found_map to allocate more blocks.
+ */
+static int find_new_blocks_proc(ext2_filsys fs,
+ blk64_t *blocknr,
+ e2_blkcnt_t blockcnt,
+ blk64_t ref_block EXT2FS_ATTR((unused)),
+ int ref_offset EXT2FS_ATTR((unused)),
+ void *priv_data)
+{
+ struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
+ e2fsck_t ctx = es->ctx;
+
+ ext2fs_mark_block_bitmap2(ctx->block_found_map, *blocknr);
+ return 0;
+}
+
errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
int num, int guaranteed_size)
{
@@ -759,7 +780,7 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
errcode_t retval;
struct expand_dir_struct es;
struct ext2_inode inode;
- blk64_t sz;
+ blk64_t sz, before, after;
if (!(fs->flags & EXT2_FLAG_RW))
return EXT2_ET_RO_FILSYS;
@@ -781,11 +802,27 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
es.newblocks = 0;
es.ctx = ctx;
+ before = ext2fs_free_blocks_count(fs->super);
retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND,
0, expand_dir_proc, &es);
if (es.err)
return es.err;
+ after = ext2fs_free_blocks_count(fs->super);
+
+ /*
+ * If the free block count has dropped by more than the blocks we
+ * allocated ourselves, then we must've allocated some extent/map
+ * blocks. Therefore, we must iterate this dir's blocks again to
+ * ensure that all newly allocated blocks are captured in
+ * block_found_map.
+ */
+ if ((before - after) > es.newblocks) {
+ retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_READ_ONLY,
+ 0, find_new_blocks_proc, &es);
+ if (es.err)
+ return es.err;
+ }
/*
* Update the size and block count fields in the inode.