]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: standardize quota verification function outputs
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 27 Feb 2018 04:43:17 +0000 (22:43 -0600)
committerEric Sandeen <sandeen@redhat.com>
Tue, 27 Feb 2018 04:43:17 +0000 (22:43 -0600)
Source kernel commit: eebf3cab9c5eac7fdb54fb9e9fb38c06f46f17f3

Rename xfs_dqcheck to xfs_dquot_verify and make it return an
xfs_failaddr_t like every other structure verifier function.
This enables us to check on-disk quotas in the same way that we check
everything else.  Callers are now responsible for logging errors, as
XFS_QMOPT_DOWARN goes away.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_dquot_buf.c
libxfs/xfs_quota_defs.h

index b5830d0f556e5b5c6e22ccaefaa625318d3612a6..43134e291ae2a6f95d7b5e602820422a47385445 100644 (file)
@@ -40,17 +40,14 @@ xfs_calc_dquots_per_chunk(
 /*
  * Do some primitive error checking on ondisk dquot data structures.
  */
-int
-xfs_dqcheck(
+xfs_failaddr_t
+xfs_dquot_verify(
        struct xfs_mount *mp,
        xfs_disk_dquot_t *ddq,
        xfs_dqid_t       id,
        uint             type,    /* used only when IO_dorepair is true */
-       uint             flags,
-       const char       *str)
+       uint             flags)
 {
-       int             errs = 0;
-
        /*
         * We can encounter an uninitialized dquot buffer for 2 reasons:
         * 1. If we crash while deleting the quotainode(s), and those blks got
@@ -66,77 +63,38 @@ xfs_dqcheck(
         * This is all fine; things are still consistent, and we haven't lost
         * any quota information. Just don't complain about bad dquot blks.
         */
-       if (ddq->d_magic != cpu_to_be16(XFS_DQUOT_MAGIC)) {
-               if (flags & XFS_QMOPT_DOWARN)
-                       xfs_alert(mp,
-                       "%s : XFS dquot ID 0x%x, magic 0x%x != 0x%x",
-                       str, id, be16_to_cpu(ddq->d_magic), XFS_DQUOT_MAGIC);
-               errs++;
-       }
-       if (ddq->d_version != XFS_DQUOT_VERSION) {
-               if (flags & XFS_QMOPT_DOWARN)
-                       xfs_alert(mp,
-                       "%s : XFS dquot ID 0x%x, version 0x%x != 0x%x",
-                       str, id, ddq->d_version, XFS_DQUOT_VERSION);
-               errs++;
-       }
+       if (ddq->d_magic != cpu_to_be16(XFS_DQUOT_MAGIC))
+               return __this_address;
+       if (ddq->d_version != XFS_DQUOT_VERSION)
+               return __this_address;
 
        if (ddq->d_flags != XFS_DQ_USER &&
            ddq->d_flags != XFS_DQ_PROJ &&
-           ddq->d_flags != XFS_DQ_GROUP) {
-               if (flags & XFS_QMOPT_DOWARN)
-                       xfs_alert(mp,
-                       "%s : XFS dquot ID 0x%x, unknown flags 0x%x",
-                       str, id, ddq->d_flags);
-               errs++;
-       }
+           ddq->d_flags != XFS_DQ_GROUP)
+               return __this_address;
 
-       if (id != -1 && id != be32_to_cpu(ddq->d_id)) {
-               if (flags & XFS_QMOPT_DOWARN)
-                       xfs_alert(mp,
-                       "%s : ondisk-dquot 0x%p, ID mismatch: "
-                       "0x%x expected, found id 0x%x",
-                       str, ddq, id, be32_to_cpu(ddq->d_id));
-               errs++;
-       }
+       if (id != -1 && id != be32_to_cpu(ddq->d_id))
+               return __this_address;
 
-       if (!errs && ddq->d_id) {
-               if (ddq->d_blk_softlimit &&
-                   be64_to_cpu(ddq->d_bcount) >
-                               be64_to_cpu(ddq->d_blk_softlimit)) {
-                       if (!ddq->d_btimer) {
-                               if (flags & XFS_QMOPT_DOWARN)
-                                       xfs_alert(mp,
-                       "%s : Dquot ID 0x%x (0x%p) BLK TIMER NOT STARTED",
-                                       str, (int)be32_to_cpu(ddq->d_id), ddq);
-                               errs++;
-                       }
-               }
-               if (ddq->d_ino_softlimit &&
-                   be64_to_cpu(ddq->d_icount) >
-                               be64_to_cpu(ddq->d_ino_softlimit)) {
-                       if (!ddq->d_itimer) {
-                               if (flags & XFS_QMOPT_DOWARN)
-                                       xfs_alert(mp,
-                       "%s : Dquot ID 0x%x (0x%p) INODE TIMER NOT STARTED",
-                                       str, (int)be32_to_cpu(ddq->d_id), ddq);
-                               errs++;
-                       }
-               }
-               if (ddq->d_rtb_softlimit &&
-                   be64_to_cpu(ddq->d_rtbcount) >
-                               be64_to_cpu(ddq->d_rtb_softlimit)) {
-                       if (!ddq->d_rtbtimer) {
-                               if (flags & XFS_QMOPT_DOWARN)
-                                       xfs_alert(mp,
-                       "%s : Dquot ID 0x%x (0x%p) RTBLK TIMER NOT STARTED",
-                                       str, (int)be32_to_cpu(ddq->d_id), ddq);
-                               errs++;
-                       }
-               }
-       }
+       if (!ddq->d_id)
+               return NULL;
 
-       return errs;
+       if (ddq->d_blk_softlimit &&
+           be64_to_cpu(ddq->d_bcount) > be64_to_cpu(ddq->d_blk_softlimit) &&
+           !ddq->d_btimer)
+               return __this_address;
+
+       if (ddq->d_ino_softlimit &&
+           be64_to_cpu(ddq->d_icount) > be64_to_cpu(ddq->d_ino_softlimit) &&
+           !ddq->d_itimer)
+               return __this_address;
+
+       if (ddq->d_rtb_softlimit &&
+           be64_to_cpu(ddq->d_rtbcount) > be64_to_cpu(ddq->d_rtb_softlimit) &&
+           !ddq->d_rtbtimer)
+               return __this_address;
+
+       return NULL;
 }
 
 /*
@@ -204,13 +162,13 @@ xfs_dquot_buf_verify_crc(
        return true;
 }
 
-STATIC bool
+STATIC xfs_failaddr_t
 xfs_dquot_buf_verify(
        struct xfs_mount        *mp,
-       struct xfs_buf          *bp,
-       int                     warn)
+       struct xfs_buf          *bp)
 {
        struct xfs_dqblk        *d = (struct xfs_dqblk *)bp->b_addr;
+       xfs_failaddr_t          fa;
        xfs_dqid_t              id = 0;
        int                     ndquots;
        int                     i;
@@ -234,41 +192,43 @@ xfs_dquot_buf_verify(
         */
        for (i = 0; i < ndquots; i++) {
                struct xfs_disk_dquot   *ddq;
-               int                     error;
 
                ddq = &d[i].dd_diskdq;
 
                if (i == 0)
                        id = be32_to_cpu(ddq->d_id);
 
-               error = xfs_dqcheck(mp, ddq, id + i, 0, warn, __func__);
-               if (error)
-                       return false;
+               fa = xfs_dquot_verify(mp, ddq, id + i, 0, 0);
+               if (fa)
+                       return fa;
        }
-       return true;
+
+       return NULL;
 }
 
 static xfs_failaddr_t
 xfs_dquot_buf_verify_struct(
-       struct xfs_buf  *bp)
+       struct xfs_buf          *bp)
 {
        struct xfs_mount        *mp = bp->b_target->bt_mount;
 
-       if (!xfs_dquot_buf_verify(mp, bp, 0))
-               return __this_address;
-       return NULL;
+       return xfs_dquot_buf_verify(mp, bp);
 }
 
 static void
 xfs_dquot_buf_read_verify(
-       struct xfs_buf  *bp)
+       struct xfs_buf          *bp)
 {
        struct xfs_mount        *mp = bp->b_target->bt_mount;
+       xfs_failaddr_t          fa;
 
        if (!xfs_dquot_buf_verify_crc(mp, bp))
                xfs_verifier_error(bp, -EFSBADCRC, __this_address);
-       else if (!xfs_dquot_buf_verify(mp, bp, XFS_QMOPT_DOWARN))
-               xfs_verifier_error(bp, -EFSCORRUPTED, __this_address);
+       else {
+               fa = xfs_dquot_buf_verify(mp, bp);
+               if (fa)
+                       xfs_verifier_error(bp, -EFSCORRUPTED, __this_address);
+       }
 }
 
 /*
@@ -284,7 +244,7 @@ xfs_dquot_buf_readahead_verify(
        struct xfs_mount        *mp = bp->b_target->bt_mount;
 
        if (!xfs_dquot_buf_verify_crc(mp, bp) ||
-           !xfs_dquot_buf_verify(mp, bp, 0)) {
+           xfs_dquot_buf_verify(mp, bp) != NULL) {
                xfs_buf_ioerror(bp, -EIO);
                bp->b_flags &= ~XBF_DONE;
        }
@@ -297,14 +257,14 @@ xfs_dquot_buf_readahead_verify(
  */
 static void
 xfs_dquot_buf_write_verify(
-       struct xfs_buf  *bp)
+       struct xfs_buf          *bp)
 {
        struct xfs_mount        *mp = bp->b_target->bt_mount;
+       xfs_failaddr_t          fa;
 
-       if (!xfs_dquot_buf_verify(mp, bp, XFS_QMOPT_DOWARN)) {
+       fa = xfs_dquot_buf_verify(mp, bp);
+       if (fa)
                xfs_verifier_error(bp, -EFSCORRUPTED, __this_address);
-               return;
-       }
 }
 
 const struct xfs_buf_ops xfs_dquot_buf_ops = {
index 7187ec93fc7630e00006bce243aadea13abd0317..bb1b13a9b5f48b445e6585231f53893ec4f0d45a 100644 (file)
@@ -112,7 +112,6 @@ typedef uint16_t    xfs_qwarncnt_t;
 #define XFS_QMOPT_PQUOTA       0x0000008 /* project dquot requested */
 #define XFS_QMOPT_FORCE_RES    0x0000010 /* ignore quota limits */
 #define XFS_QMOPT_SBVERSION    0x0000040 /* change superblock version num */
-#define XFS_QMOPT_DOWARN        0x0000400 /* increase warning cnt if needed */
 #define XFS_QMOPT_GQUOTA       0x0002000 /* group dquot requested */
 #define XFS_QMOPT_ENOSPC       0x0004000 /* enospc instead of edquot (prj) */
 #define XFS_QMOPT_DQNEXT       0x0008000 /* return next dquot >= this ID */
@@ -152,8 +151,9 @@ typedef uint16_t    xfs_qwarncnt_t;
                (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA)
 #define XFS_QMOPT_RESBLK_MASK  (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)
 
-extern int xfs_dqcheck(struct xfs_mount *mp, xfs_disk_dquot_t *ddq,
-                      xfs_dqid_t id, uint type, uint flags, const char *str);
+extern xfs_failaddr_t xfs_dquot_verify(struct xfs_mount *mp,
+               struct xfs_disk_dquot *ddq, xfs_dqid_t id, uint type,
+               uint flags);
 extern int xfs_calc_dquots_per_chunk(unsigned int nbblks);
 extern int xfs_dquot_repair(struct xfs_mount *mp, struct xfs_disk_dquot *ddq,
                xfs_dqid_t id, uint type);