xfs: consolidate xfs_inumbers

From: Jie Liu <jeff.liu@oracle.com>

Consolidate xfs_inumbers() to make the formatter function return correct
error and make the source code looks a bit neat.

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
Jie Liu 2014-07-24 12:11:47 +10:00 committed by Dave Chinner
parent d716f8eedb
commit 549fa00679
2 changed files with 31 additions and 37 deletions

View file

@ -102,7 +102,7 @@ xfs_compat_growfs_rt_copyin(
STATIC int STATIC int
xfs_inumbers_fmt_compat( xfs_inumbers_fmt_compat(
void __user *ubuffer, void __user *ubuffer,
const xfs_inogrp_t *buffer, const struct xfs_inogrp *buffer,
long count, long count,
long *written) long *written)
{ {

View file

@ -512,7 +512,7 @@ xfs_bulkstat(
int int
xfs_inumbers_fmt( xfs_inumbers_fmt(
void __user *ubuffer, /* buffer to write to */ void __user *ubuffer, /* buffer to write to */
const xfs_inogrp_t *buffer, /* buffer to read from */ const struct xfs_inogrp *buffer, /* buffer to read from */
long count, /* # of elements to read */ long count, /* # of elements to read */
long *written) /* # of bytes written */ long *written) /* # of bytes written */
{ {
@ -527,37 +527,33 @@ xfs_inumbers_fmt(
*/ */
int /* error status */ int /* error status */
xfs_inumbers( xfs_inumbers(
xfs_mount_t *mp, /* mount point for filesystem */ struct xfs_mount *mp,/* mount point for filesystem */
xfs_ino_t *lastino, /* last inode returned */ xfs_ino_t *lastino,/* last inode returned */
int *count, /* size of buffer/count returned */ int *count,/* size of buffer/count returned */
void __user *ubuffer,/* buffer with inode descriptions */ void __user *ubuffer,/* buffer with inode descriptions */
inumbers_fmt_pf formatter) inumbers_fmt_pf formatter)
{ {
xfs_buf_t *agbp; xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, *lastino);
xfs_agino_t agino; xfs_agino_t agino = XFS_INO_TO_AGINO(mp, *lastino);
xfs_agnumber_t agno; struct xfs_btree_cur *cur = NULL;
int bcount; xfs_buf_t *agbp = NULL;
xfs_inogrp_t *buffer; struct xfs_inogrp *buffer;
int bufidx; int bcount;
xfs_btree_cur_t *cur; int left = *count;
int error; int bufidx = 0;
xfs_inobt_rec_incore_t r; int error = 0;
int i;
xfs_ino_t ino;
int left;
int tmp;
ino = (xfs_ino_t)*lastino;
agno = XFS_INO_TO_AGNO(mp, ino);
agino = XFS_INO_TO_AGINO(mp, ino);
left = *count;
*count = 0; *count = 0;
if (agno >= mp->m_sb.sb_agcount ||
*lastino != XFS_AGINO_TO_INO(mp, agno, agino))
return error;
bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer)));
buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP); buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
error = bufidx = 0;
cur = NULL;
agbp = NULL;
while (left > 0 && agno < mp->m_sb.sb_agcount) { while (left > 0 && agno < mp->m_sb.sb_agcount) {
struct xfs_inobt_rec_incore r;
int stat;
if (agbp == NULL) { if (agbp == NULL) {
error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
if (error) { if (error) {
@ -574,7 +570,7 @@ xfs_inumbers(
cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno, cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
XFS_BTNUM_INO); XFS_BTNUM_INO);
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE, error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE,
&tmp); &stat);
if (error) { if (error) {
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
cur = NULL; cur = NULL;
@ -589,8 +585,8 @@ xfs_inumbers(
continue; continue;
} }
} }
error = xfs_inobt_get_rec(cur, &r, &i); error = xfs_inobt_get_rec(cur, &r, &stat);
if (error || i == 0) { if (error || stat == 0) {
xfs_buf_relse(agbp); xfs_buf_relse(agbp);
agbp = NULL; agbp = NULL;
xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
@ -609,16 +605,15 @@ xfs_inumbers(
left--; left--;
if (bufidx == bcount) { if (bufidx == bcount) {
long written; long written;
if (formatter(ubuffer, buffer, bufidx, &written)) { error = formatter(ubuffer, buffer, bufidx, &written);
error = -EFAULT; if (error)
break; break;
}
ubuffer += written; ubuffer += written;
*count += bufidx; *count += bufidx;
bufidx = 0; bufidx = 0;
} }
if (left) { if (left) {
error = xfs_btree_increment(cur, 0, &tmp); error = xfs_btree_increment(cur, 0, &stat);
if (error) { if (error) {
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
cur = NULL; cur = NULL;
@ -636,9 +631,8 @@ xfs_inumbers(
if (!error) { if (!error) {
if (bufidx) { if (bufidx) {
long written; long written;
if (formatter(ubuffer, buffer, bufidx, &written)) error = formatter(ubuffer, buffer, bufidx, &written);
error = -EFAULT; if (!error)
else
*count += bufidx; *count += bufidx;
} }
*lastino = XFS_AGINO_TO_INO(mp, agno, agino); *lastino = XFS_AGINO_TO_INO(mp, agno, agino);