aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dquot.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2011-12-06 16:58:24 -0500
committerBen Myers <bpm@sgi.com>2011-12-15 15:37:32 -0500
commit97e7ade506cdd7157d8b64c77696c082fb997476 (patch)
tree37cf54335972c92516e44444ce0dc36842b81e35 /fs/xfs/xfs_dquot.c
parent49d35a5cf115d9273edb8aa7e527502411b77712 (diff)
xfs: kill xfs_qm_idtodq
This function doesn't help the code flow, so merge the dquot allocation and transaction handling into xfs_qm_dqread. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_dquot.c')
-rw-r--r--fs/xfs/xfs_dquot.c137
1 files changed, 50 insertions, 87 deletions
diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
index fcfafaa41a7d..1a2aa173ef21 100644
--- a/fs/xfs/xfs_dquot.c
+++ b/fs/xfs/xfs_dquot.c
@@ -550,36 +550,62 @@ xfs_qm_dqtobp(
550 * Read in the ondisk dquot using dqtobp() then copy it to an incore version, 550 * Read in the ondisk dquot using dqtobp() then copy it to an incore version,
551 * and release the buffer immediately. 551 * and release the buffer immediately.
552 * 552 *
553 * If XFS_QMOPT_DQALLOC is set, allocate a dquot on disk if it needed.
553 */ 554 */
554/* ARGSUSED */
555STATIC int 555STATIC int
556xfs_qm_dqread( 556xfs_qm_dqread(
557 xfs_trans_t **tpp, 557 struct xfs_mount *mp,
558 xfs_dqid_t id, 558 xfs_dqid_t id,
559 xfs_dquot_t *dqp, /* dquot to get filled in */ 559 uint type,
560 uint flags) 560 uint flags,
561 struct xfs_dquot **O_dqpp)
561{ 562{
562 xfs_disk_dquot_t *ddqp; 563 struct xfs_dquot *dqp;
563 xfs_buf_t *bp; 564 struct xfs_disk_dquot *ddqp;
564 int error; 565 struct xfs_buf *bp;
565 xfs_trans_t *tp; 566 struct xfs_trans *tp = NULL;
567 int error;
568 int cancelflags = 0;
566 569
567 ASSERT(tpp); 570 dqp = xfs_qm_dqinit(mp, id, type);
568 571
569 trace_xfs_dqread(dqp); 572 trace_xfs_dqread(dqp);
570 573
574 if (flags & XFS_QMOPT_DQALLOC) {
575 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_DQALLOC);
576 error = xfs_trans_reserve(tp, XFS_QM_DQALLOC_SPACE_RES(mp),
577 XFS_WRITE_LOG_RES(mp) +
578 /*
579 * Round the chunklen up to the next multiple
580 * of 128 (buf log item chunk size)).
581 */
582 BBTOB(mp->m_quotainfo->qi_dqchunklen) - 1 + 128,
583 0,
584 XFS_TRANS_PERM_LOG_RES,
585 XFS_WRITE_LOG_COUNT);
586 if (error)
587 goto error1;
588 cancelflags = XFS_TRANS_RELEASE_LOG_RES;
589 }
590
571 /* 591 /*
572 * get a pointer to the on-disk dquot and the buffer containing it 592 * get a pointer to the on-disk dquot and the buffer containing it
573 * dqp already knows its own type (GROUP/USER). 593 * dqp already knows its own type (GROUP/USER).
574 */ 594 */
575 if ((error = xfs_qm_dqtobp(tpp, dqp, &ddqp, &bp, flags))) { 595 error = xfs_qm_dqtobp(&tp, dqp, &ddqp, &bp, flags);
576 return (error); 596 if (error) {
597 /*
598 * This can happen if quotas got turned off (ESRCH),
599 * or if the dquot didn't exist on disk and we ask to
600 * allocate (ENOENT).
601 */
602 trace_xfs_dqread_fail(dqp);
603 cancelflags |= XFS_TRANS_ABORT;
604 goto error1;
577 } 605 }
578 tp = *tpp;
579 606
580 /* copy everything from disk dquot to the incore dquot */ 607 /* copy everything from disk dquot to the incore dquot */
581 memcpy(&dqp->q_core, ddqp, sizeof(xfs_disk_dquot_t)); 608 memcpy(&dqp->q_core, ddqp, sizeof(xfs_disk_dquot_t));
582 ASSERT(be32_to_cpu(dqp->q_core.d_id) == id);
583 xfs_qm_dquot_logitem_init(dqp); 609 xfs_qm_dquot_logitem_init(dqp);
584 610
585 /* 611 /*
@@ -608,77 +634,22 @@ xfs_qm_dqread(
608 ASSERT(xfs_buf_islocked(bp)); 634 ASSERT(xfs_buf_islocked(bp));
609 xfs_trans_brelse(tp, bp); 635 xfs_trans_brelse(tp, bp);
610 636
611 return (error);
612}
613
614
615/*
616 * allocate an incore dquot from the kernel heap,
617 * and fill its core with quota information kept on disk.
618 * If XFS_QMOPT_DQALLOC is set, it'll allocate a dquot on disk
619 * if it wasn't already allocated.
620 */
621STATIC int
622xfs_qm_idtodq(
623 xfs_mount_t *mp,
624 xfs_dqid_t id, /* gid or uid, depending on type */
625 uint type, /* UDQUOT or GDQUOT */
626 uint flags, /* DQALLOC, DQREPAIR */
627 xfs_dquot_t **O_dqpp)/* OUT : incore dquot, not locked */
628{
629 xfs_dquot_t *dqp;
630 int error;
631 xfs_trans_t *tp;
632 int cancelflags=0;
633
634 dqp = xfs_qm_dqinit(mp, id, type);
635 tp = NULL;
636 if (flags & XFS_QMOPT_DQALLOC) {
637 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_DQALLOC);
638 error = xfs_trans_reserve(tp, XFS_QM_DQALLOC_SPACE_RES(mp),
639 XFS_WRITE_LOG_RES(mp) +
640 BBTOB(mp->m_quotainfo->qi_dqchunklen) - 1 +
641 128,
642 0,
643 XFS_TRANS_PERM_LOG_RES,
644 XFS_WRITE_LOG_COUNT);
645 if (error) {
646 cancelflags = 0;
647 goto error0;
648 }
649 cancelflags = XFS_TRANS_RELEASE_LOG_RES;
650 }
651
652 /*
653 * Read it from disk; xfs_dqread() takes care of
654 * all the necessary initialization of dquot's fields (locks, etc)
655 */
656 if ((error = xfs_qm_dqread(&tp, id, dqp, flags))) {
657 /*
658 * This can happen if quotas got turned off (ESRCH),
659 * or if the dquot didn't exist on disk and we ask to
660 * allocate (ENOENT).
661 */
662 trace_xfs_dqread_fail(dqp);
663 cancelflags |= XFS_TRANS_ABORT;
664 goto error0;
665 }
666 if (tp) { 637 if (tp) {
667 if ((error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES))) 638 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
668 goto error1; 639 if (error)
640 goto error0;
669 } 641 }
670 642
671 *O_dqpp = dqp; 643 *O_dqpp = dqp;
672 return (0); 644 return error;
673 645
674 error0: 646error1:
675 ASSERT(error);
676 if (tp) 647 if (tp)
677 xfs_trans_cancel(tp, cancelflags); 648 xfs_trans_cancel(tp, cancelflags);
678 error1: 649error0:
679 xfs_qm_dqdestroy(dqp); 650 xfs_qm_dqdestroy(dqp);
680 *O_dqpp = NULL; 651 *O_dqpp = NULL;
681 return (error); 652 return error;
682} 653}
683 654
684/* 655/*
@@ -832,19 +803,11 @@ restart:
832 version = h->qh_version; 803 version = h->qh_version;
833 mutex_unlock(&h->qh_lock); 804 mutex_unlock(&h->qh_lock);
834 805
835 /* 806 error = xfs_qm_dqread(mp, id, type, flags, &dqp);
836 * Allocate the dquot on the kernel heap, and read the ondisk 807 if (error) {
837 * portion off the disk. Also, do all the necessary initialization
838 * This can return ENOENT if dquot didn't exist on disk and we didn't
839 * ask it to allocate; ESRCH if quotas got turned off suddenly.
840 */
841 if ((error = xfs_qm_idtodq(mp, id, type,
842 flags & (XFS_QMOPT_DQALLOC|XFS_QMOPT_DQREPAIR|
843 XFS_QMOPT_DOWARN),
844 &dqp))) {
845 if (ip) 808 if (ip)
846 xfs_ilock(ip, XFS_ILOCK_EXCL); 809 xfs_ilock(ip, XFS_ILOCK_EXCL);
847 return (error); 810 return error;
848 } 811 }
849 812
850 /* 813 /*