Commit beec14df authored by Dave Kleikamp's avatar Dave Kleikamp

JFS: Fix off-by-one error in dbNextAG

In certain situations, dbNextAG set db_agpref to db_numag, with is
one higher than the last valid value.  This will eventually result in
a trap.
parent f20bf018
...@@ -648,7 +648,7 @@ int dbNextAG(struct inode *ipbmap) ...@@ -648,7 +648,7 @@ int dbNextAG(struct inode *ipbmap)
agpref = bmp->db_agpref; agpref = bmp->db_agpref;
if ((atomic_read(&bmp->db_active[agpref]) == 0) && if ((atomic_read(&bmp->db_active[agpref]) == 0) &&
(bmp->db_agfree[agpref] >= avgfree)) (bmp->db_agfree[agpref] >= avgfree))
goto found; goto unlock;
/* From the last preferred ag, find the next one with at least /* From the last preferred ag, find the next one with at least
* average free space. * average free space.
...@@ -660,9 +660,12 @@ int dbNextAG(struct inode *ipbmap) ...@@ -660,9 +660,12 @@ int dbNextAG(struct inode *ipbmap)
if (atomic_read(&bmp->db_active[agpref])) if (atomic_read(&bmp->db_active[agpref]))
/* open file is currently growing in this ag */ /* open file is currently growing in this ag */
continue; continue;
if (bmp->db_agfree[agpref] >= avgfree) if (bmp->db_agfree[agpref] >= avgfree) {
goto found; /* Return this one */
else if (bmp->db_agfree[agpref] > hwm) { bmp->db_agpref = agpref;
goto unlock;
} else if (bmp->db_agfree[agpref] > hwm) {
/* Less than avg. freespace, but best so far */
hwm = bmp->db_agfree[agpref]; hwm = bmp->db_agfree[agpref];
next_best = agpref; next_best = agpref;
} }
...@@ -673,12 +676,9 @@ int dbNextAG(struct inode *ipbmap) ...@@ -673,12 +676,9 @@ int dbNextAG(struct inode *ipbmap)
* next best * next best
*/ */
if (next_best != -1) if (next_best != -1)
agpref = next_best; bmp->db_agpref = next_best;
/* else leave db_agpref unchanged */
/* else agpref should be back to its original value */ unlock:
found:
bmp->db_agpref = agpref;
BMAP_UNLOCK(bmp); BMAP_UNLOCK(bmp);
/* return the preferred group. /* return the preferred group.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment