From: Alex Elder Date: Tue, 13 Apr 2010 05:22:29 +0000 (+1000) Subject: xfs: fix min bufsize bugs in two places X-Git-Tag: v2.6.35-rc2~3^2^2~58 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6881a229f66f74e4e0a73504389695213987955b;p=platform%2Fkernel%2Flinux-3.10.git xfs: fix min bufsize bugs in two places This fixes a bug in two places that I found by inspection. In xlog_find_verify_cycle() and xlog_write_log_records(), the code attempts to allocate a buffer to hold as many blocks as possible. It gives up if the number of blocks to be allocated gets too small. Right now it uses log->l_sectbb_log as that lower bound, but I'm sure it's supposed to be the actual log sector size instead. That is, the lower bound should be (1 << log->l_sectbb_log). Also define a simple macro xlog_sectbb(log) to represent the number of basic blocks in a sector for the given log. (No change from original submission; I have implemented Christoph's suggestion about storing l_sectsize rather than l_sectbb_log in a new, separate patch in this series.) Signed-off-by: Alex Elder Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index f21eb8a..0d81a90 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -66,6 +66,9 @@ STATIC void xlog_recover_check_summary(xlog_t *); ((bbs + (log)->l_sectbb_mask + 1) & ~(log)->l_sectbb_mask) : (bbs) ) #define XLOG_SECTOR_ROUNDDOWN_BLKNO(log, bno) ((bno) & ~(log)->l_sectbb_mask) +/* Number of basic blocks in a log sector */ +#define xlog_sectbb(log) (1 << (log)->l_sectbb_log) + STATIC xfs_buf_t * xlog_get_bp( xlog_t *log, @@ -376,12 +379,16 @@ xlog_find_verify_cycle( xfs_caddr_t buf = NULL; int error = 0; + /* + * Greedily allocate a buffer big enough to handle the full + * range of basic blocks we'll be examining. If that fails, + * try a smaller size. We need to be able to read at least + * a log sector, or we're out of luck. + */ bufblks = 1 << ffs(nbblks); - while (!(bp = xlog_get_bp(log, bufblks))) { - /* can't get enough memory to do everything in one big buffer */ bufblks >>= 1; - if (bufblks <= log->l_sectbb_log) + if (bufblks < xlog_sectbb(log)) return ENOMEM; } @@ -1158,10 +1165,16 @@ xlog_write_log_records( int error = 0; int i, j = 0; + /* + * Greedily allocate a buffer big enough to handle the full + * range of basic blocks to be written. If that fails, try + * a smaller size. We need to be able to write at least a + * log sector, or we're out of luck. + */ bufblks = 1 << ffs(blocks); while (!(bp = xlog_get_bp(log, bufblks))) { bufblks >>= 1; - if (bufblks <= log->l_sectbb_log) + if (bufblks < xlog_sectbb(log)) return ENOMEM; }