Whamcloud - gitweb
libext2fs: fix endian handling error; reduce fragmentation some
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 8 Nov 2014 02:27:53 +0000 (21:27 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 8 Nov 2014 02:27:53 +0000 (21:27 -0500)
If we're going to read the "nr - 1" entry in an indirect block for use
as a "goal" input to the block allocator, we need to byteswap the
entry.  While we're at it, if we're allocating blocks for the zeroth
entry in the indirect block, we might as well use the indirect block
as the starting point to try to reduce fragmentation.

(d_fallocate_blkmap will test this...)

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/bmap.c

index db2fd72..a8bb00d 100644 (file)
@@ -67,7 +67,7 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags,
 #endif
 
        if (!b && (flags & BMAP_ALLOC)) {
-               b = nr ? ((blk_t *) block_buf)[nr-1] : 0;
+               b = nr ? ext2fs_le32_to_cpu(((blk_t *)block_buf)[nr - 1]) : ind;
                retval = ext2fs_alloc_block(fs, b,
                                            block_buf + fs->blocksize, &b);
                if (retval)