diff options
author | Jie Liu <jeff.liu@oracle.com> | 2014-07-23 22:11:47 -0400 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2014-07-23 22:11:47 -0400 |
commit | 549fa00679dd14beaaa685486549c637e8e02182 (patch) | |
tree | ed62bcf174d4ada1cc71d3e233f1f2f627f45c45 /fs/xfs/xfs_itable.c | |
parent | d716f8eedb143387afd35d337327090b8348159e (diff) |
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>
Diffstat (limited to 'fs/xfs/xfs_itable.c')
-rw-r--r-- | fs/xfs/xfs_itable.c | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c index e15df1f70d79..df7605183aa2 100644 --- a/fs/xfs/xfs_itable.c +++ b/fs/xfs/xfs_itable.c | |||
@@ -512,7 +512,7 @@ xfs_bulkstat( | |||
512 | int | 512 | int |
513 | xfs_inumbers_fmt( | 513 | xfs_inumbers_fmt( |
514 | void __user *ubuffer, /* buffer to write to */ | 514 | void __user *ubuffer, /* buffer to write to */ |
515 | const xfs_inogrp_t *buffer, /* buffer to read from */ | 515 | const struct xfs_inogrp *buffer, /* buffer to read from */ |
516 | long count, /* # of elements to read */ | 516 | long count, /* # of elements to read */ |
517 | long *written) /* # of bytes written */ | 517 | long *written) /* # of bytes written */ |
518 | { | 518 | { |
@@ -527,37 +527,33 @@ xfs_inumbers_fmt( | |||
527 | */ | 527 | */ |
528 | int /* error status */ | 528 | int /* error status */ |
529 | xfs_inumbers( | 529 | xfs_inumbers( |
530 | xfs_mount_t *mp, /* mount point for filesystem */ | 530 | struct xfs_mount *mp,/* mount point for filesystem */ |
531 | xfs_ino_t *lastino, /* last inode returned */ | 531 | xfs_ino_t *lastino,/* last inode returned */ |
532 | int *count, /* size of buffer/count returned */ | 532 | int *count,/* size of buffer/count returned */ |
533 | void __user *ubuffer,/* buffer with inode descriptions */ | 533 | void __user *ubuffer,/* buffer with inode descriptions */ |
534 | inumbers_fmt_pf formatter) | 534 | inumbers_fmt_pf formatter) |
535 | { | 535 | { |
536 | xfs_buf_t *agbp; | 536 | xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, *lastino); |
537 | xfs_agino_t agino; | 537 | xfs_agino_t agino = XFS_INO_TO_AGINO(mp, *lastino); |
538 | xfs_agnumber_t agno; | 538 | struct xfs_btree_cur *cur = NULL; |
539 | int bcount; | 539 | xfs_buf_t *agbp = NULL; |
540 | xfs_inogrp_t *buffer; | 540 | struct xfs_inogrp *buffer; |
541 | int bufidx; | 541 | int bcount; |
542 | xfs_btree_cur_t *cur; | 542 | int left = *count; |
543 | int error; | 543 | int bufidx = 0; |
544 | xfs_inobt_rec_incore_t r; | 544 | int error = 0; |
545 | int i; | 545 | |
546 | xfs_ino_t ino; | ||
547 | int left; | ||
548 | int tmp; | ||
549 | |||
550 | ino = (xfs_ino_t)*lastino; | ||
551 | agno = XFS_INO_TO_AGNO(mp, ino); | ||
552 | agino = XFS_INO_TO_AGINO(mp, ino); | ||
553 | left = *count; | ||
554 | *count = 0; | 546 | *count = 0; |
547 | if (agno >= mp->m_sb.sb_agcount || | ||
548 | *lastino != XFS_AGINO_TO_INO(mp, agno, agino)) | ||
549 | return error; | ||
550 | |||
555 | bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); | 551 | bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); |
556 | buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP); | 552 | buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP); |
557 | error = bufidx = 0; | ||
558 | cur = NULL; | ||
559 | agbp = NULL; | ||
560 | while (left > 0 && agno < mp->m_sb.sb_agcount) { | 553 | while (left > 0 && agno < mp->m_sb.sb_agcount) { |
554 | struct xfs_inobt_rec_incore r; | ||
555 | int stat; | ||
556 | |||
561 | if (agbp == NULL) { | 557 | if (agbp == NULL) { |
562 | error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); | 558 | error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); |
563 | if (error) { | 559 | if (error) { |
@@ -574,7 +570,7 @@ xfs_inumbers( | |||
574 | cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno, | 570 | cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno, |
575 | XFS_BTNUM_INO); | 571 | XFS_BTNUM_INO); |
576 | error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE, | 572 | error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE, |
577 | &tmp); | 573 | &stat); |
578 | if (error) { | 574 | if (error) { |
579 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | 575 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); |
580 | cur = NULL; | 576 | cur = NULL; |
@@ -589,8 +585,8 @@ xfs_inumbers( | |||
589 | continue; | 585 | continue; |
590 | } | 586 | } |
591 | } | 587 | } |
592 | error = xfs_inobt_get_rec(cur, &r, &i); | 588 | error = xfs_inobt_get_rec(cur, &r, &stat); |
593 | if (error || i == 0) { | 589 | if (error || stat == 0) { |
594 | xfs_buf_relse(agbp); | 590 | xfs_buf_relse(agbp); |
595 | agbp = NULL; | 591 | agbp = NULL; |
596 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | 592 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); |
@@ -609,16 +605,15 @@ xfs_inumbers( | |||
609 | left--; | 605 | left--; |
610 | if (bufidx == bcount) { | 606 | if (bufidx == bcount) { |
611 | long written; | 607 | long written; |
612 | if (formatter(ubuffer, buffer, bufidx, &written)) { | 608 | error = formatter(ubuffer, buffer, bufidx, &written); |
613 | error = -EFAULT; | 609 | if (error) |
614 | break; | 610 | break; |
615 | } | ||
616 | ubuffer += written; | 611 | ubuffer += written; |
617 | *count += bufidx; | 612 | *count += bufidx; |
618 | bufidx = 0; | 613 | bufidx = 0; |
619 | } | 614 | } |
620 | if (left) { | 615 | if (left) { |
621 | error = xfs_btree_increment(cur, 0, &tmp); | 616 | error = xfs_btree_increment(cur, 0, &stat); |
622 | if (error) { | 617 | if (error) { |
623 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | 618 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); |
624 | cur = NULL; | 619 | cur = NULL; |
@@ -636,9 +631,8 @@ xfs_inumbers( | |||
636 | if (!error) { | 631 | if (!error) { |
637 | if (bufidx) { | 632 | if (bufidx) { |
638 | long written; | 633 | long written; |
639 | if (formatter(ubuffer, buffer, bufidx, &written)) | 634 | error = formatter(ubuffer, buffer, bufidx, &written); |
640 | error = -EFAULT; | 635 | if (!error) |
641 | else | ||
642 | *count += bufidx; | 636 | *count += bufidx; |
643 | } | 637 | } |
644 | *lastino = XFS_AGINO_TO_INO(mp, agno, agino); | 638 | *lastino = XFS_AGINO_TO_INO(mp, agno, agino); |