提交 6e57c542 编写于 作者: D Dave Chinner 提交者: Dave Chinner

xfs: bulkstat main loop logic is a mess

There are a bunch of variables tha tare more wildy scoped than they
need to be, obfuscated user buffer checks and tortured "next inode"
tracking. This all needs cleaning up to expose the real issues that
need fixing.

cc: <stable@vger.kernel.org> # 3.17
Signed-off-by: NDave Chinner <dchinner@redhat.com>
Reviewed-by: NBrian Foster <bfoster@redhat.com>
Signed-off-by: NDave Chinner <david@fromorbit.com>
上级 2b831ac6
...@@ -348,30 +348,23 @@ xfs_bulkstat( ...@@ -348,30 +348,23 @@ xfs_bulkstat(
xfs_agino_t agino; /* inode # in allocation group */ xfs_agino_t agino; /* inode # in allocation group */
xfs_agnumber_t agno; /* allocation group number */ xfs_agnumber_t agno; /* allocation group number */
xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */ xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
int end_of_ag; /* set if we've seen the ag end */
int error; /* error code */
int icount; /* count of inodes good in irbuf */
size_t irbsize; /* size of irec buffer in bytes */ size_t irbsize; /* size of irec buffer in bytes */
xfs_ino_t ino; /* inode number (filesystem) */
xfs_inobt_rec_incore_t *irbp; /* current irec buffer pointer */
xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */ xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */
xfs_inobt_rec_incore_t *irbufend; /* end of good irec buffer entries */
xfs_ino_t lastino; /* last inode number returned */ xfs_ino_t lastino; /* last inode number returned */
int nirbuf; /* size of irbuf */ int nirbuf; /* size of irbuf */
int rval; /* return value error code */ int rval; /* return value error code */
int ubcount; /* size of user's buffer */ int ubcount; /* size of user's buffer */
int stat;
struct xfs_bulkstat_agichunk ac; struct xfs_bulkstat_agichunk ac;
int error = 0;
/* /*
* Get the last inode value, see if there's nothing to do. * Get the last inode value, see if there's nothing to do.
*/ */
ino = (xfs_ino_t)*lastinop; lastino = *lastinop;
lastino = ino; agno = XFS_INO_TO_AGNO(mp, lastino);
agno = XFS_INO_TO_AGNO(mp, ino); agino = XFS_INO_TO_AGINO(mp, lastino);
agino = XFS_INO_TO_AGINO(mp, ino);
if (agno >= mp->m_sb.sb_agcount || if (agno >= mp->m_sb.sb_agcount ||
ino != XFS_AGINO_TO_INO(mp, agno, agino)) { lastino != XFS_AGINO_TO_INO(mp, agno, agino)) {
*done = 1; *done = 1;
*ubcountp = 0; *ubcountp = 0;
return 0; return 0;
...@@ -396,8 +389,13 @@ xfs_bulkstat( ...@@ -396,8 +389,13 @@ xfs_bulkstat(
* inode returned; 0 means start of the allocation group. * inode returned; 0 means start of the allocation group.
*/ */
rval = 0; rval = 0;
while (XFS_BULKSTAT_UBLEFT(ac.ac_ubleft) && agno < mp->m_sb.sb_agcount) { while (agno < mp->m_sb.sb_agcount) {
cond_resched(); struct xfs_inobt_rec_incore *irbp = irbuf;
struct xfs_inobt_rec_incore *irbufend = irbuf + nirbuf;
bool end_of_ag = false;
int icount = 0;
int stat;
error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
if (error) if (error)
break; break;
...@@ -407,10 +405,6 @@ xfs_bulkstat( ...@@ -407,10 +405,6 @@ xfs_bulkstat(
*/ */
cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno, cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
XFS_BTNUM_INO); XFS_BTNUM_INO);
irbp = irbuf;
irbufend = irbuf + nirbuf;
end_of_ag = 0;
icount = 0;
if (agino > 0) { if (agino > 0) {
/* /*
* In the middle of an allocation group, we need to get * In the middle of an allocation group, we need to get
...@@ -435,7 +429,7 @@ xfs_bulkstat( ...@@ -435,7 +429,7 @@ xfs_bulkstat(
error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &stat); error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &stat);
} }
if (error || stat == 0) { if (error || stat == 0) {
end_of_ag = 1; end_of_ag = true;
goto del_cursor; goto del_cursor;
} }
...@@ -448,7 +442,7 @@ xfs_bulkstat( ...@@ -448,7 +442,7 @@ xfs_bulkstat(
error = xfs_inobt_get_rec(cur, &r, &stat); error = xfs_inobt_get_rec(cur, &r, &stat);
if (error || stat == 0) { if (error || stat == 0) {
end_of_ag = 1; end_of_ag = true;
goto del_cursor; goto del_cursor;
} }
...@@ -470,7 +464,7 @@ xfs_bulkstat( ...@@ -470,7 +464,7 @@ xfs_bulkstat(
agino = r.ir_startino + XFS_INODES_PER_CHUNK; agino = r.ir_startino + XFS_INODES_PER_CHUNK;
error = xfs_btree_increment(cur, 0, &stat); error = xfs_btree_increment(cur, 0, &stat);
if (error || stat == 0) { if (error || stat == 0) {
end_of_ag = 1; end_of_ag = true;
goto del_cursor; goto del_cursor;
} }
cond_resched(); cond_resched();
...@@ -491,7 +485,7 @@ xfs_bulkstat( ...@@ -491,7 +485,7 @@ xfs_bulkstat(
*/ */
irbufend = irbp; irbufend = irbp;
for (irbp = irbuf; for (irbp = irbuf;
irbp < irbufend && XFS_BULKSTAT_UBLEFT(ac.ac_ubleft); irbp < irbufend && ac.ac_ubleft >= statstruct_size;
irbp++) { irbp++) {
error = xfs_bulkstat_ag_ichunk(mp, agno, irbp, error = xfs_bulkstat_ag_ichunk(mp, agno, irbp,
formatter, statstruct_size, &ac, formatter, statstruct_size, &ac,
...@@ -502,17 +496,15 @@ xfs_bulkstat( ...@@ -502,17 +496,15 @@ xfs_bulkstat(
cond_resched(); cond_resched();
} }
/* /* If we've run out of space, we are done */
* Set up for the next loop iteration. if (ac.ac_ubleft < statstruct_size)
*/
if (XFS_BULKSTAT_UBLEFT(ac.ac_ubleft)) {
if (end_of_ag) {
agno++;
agino = 0;
} else
agino = XFS_INO_TO_AGINO(mp, lastino);
} else
break; break;
if (end_of_ag) {
agno++;
agino = 0;
} else
agino = XFS_INO_TO_AGINO(mp, lastino);
} }
/* /*
* Done, we're either out of filesystem or space to put the data. * Done, we're either out of filesystem or space to put the data.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册