]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: ensure .. is set sanely when rebuilding dir
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 1 Jun 2015 01:17:39 +0000 (11:17 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 1 Jun 2015 01:17:39 +0000 (11:17 +1000)
When we're rebuilding a directory, ensure that we reinitialize the
directory with a sane parent ('..') inode value.  If we don't, the
error return from xfs_dir_init() is ignored, and the rebuild process
becomes confused and leaves the directory corrupt.  If repair later
discovers that the rebuilt directory is an orphan, it'll try to attach
it to lost+found and abort on the corrupted directory.  Also fix
ignoring the return value of xfs_dir_init().

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
include/xfs_dir2.h
libxfs/xfs_dir2_priv.h
repair/phase6.c

index 3900130be748cce49eddd0ebc4b4e9907e2caab7..2d41c5f90d0310c7d4c5efbcf9afe54ec5211145 100644 (file)
@@ -100,6 +100,8 @@ extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_buf *bp,
 extern struct xfs_dir2_data_free *xfs_dir2_data_freefind(
                struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_unused *dup);
 
+extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino);
+
 extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;
 extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops;
 extern const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops;
index 1bad84c408295ae4db2de71d96c74b18fff5b2b2..926715f3c86e97ba28a9be693de9fba1b3696ece 100644 (file)
@@ -21,7 +21,6 @@
 struct dir_context;
 
 /* xfs_dir2.c */
-extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino);
 extern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space,
                                xfs_dir2_db_t *dbp);
 extern int xfs_dir_cilookup_result(struct xfs_da_args *args,
index 7a984bf5b9c4335fac741f5dd3f4ccecd0228501..105bce4d32aeb5782ed19db8cd0d6a2cd6410d58 100644 (file)
@@ -1321,7 +1321,8 @@ longform_dir2_rebuild(
         * for the libxfs_dir_init() call).
         */
        pip.i_ino = get_inode_parent(irec, ino_offset);
-       if (pip.i_ino == NULLFSINO)
+       if (pip.i_ino == NULLFSINO ||
+           xfs_dir_ino_validate(mp, pip.i_ino))
                pip.i_ino = mp->m_sb.sb_rootino;
 
        xfs_bmap_init(&flist, &firstblock);
@@ -1348,7 +1349,11 @@ longform_dir2_rebuild(
 
        ASSERT(done);
 
-       libxfs_dir_init(tp, ip, &pip);
+       error = libxfs_dir_init(tp, ip, &pip);
+       if (error) {
+               do_warn(_("xfs_dir_init failed -- error - %d\n"), error);
+               goto out_bmap_cancel;
+       }
 
        error = libxfs_bmap_finish(&tp, &flist, &committed);