Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Simplify elaborate calls to quota_check_limit().



details:   https://anonhg.NetBSD.org/src/rev/3aa37b1a0aca
branches:  trunk
changeset: 773410:3aa37b1a0aca
user:      dholland <dholland%NetBSD.org@localhost>
date:      Wed Feb 01 17:48:10 2012 +0000

description:
Simplify elaborate calls to quota_check_limit().

diffstat:

 usr.bin/quota/quota.c        |  49 +++++++++++++++----------------------------
 usr.sbin/repquota/repquota.c |  23 ++++++++++---------
 2 files changed, 29 insertions(+), 43 deletions(-)

diffs (145 lines):

diff -r 2a6911749d48 -r 3aa37b1a0aca usr.bin/quota/quota.c
--- a/usr.bin/quota/quota.c     Wed Feb 01 17:11:46 2012 +0000
+++ b/usr.bin/quota/quota.c     Wed Feb 01 17:48:10 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota.c,v 1.46 2012/01/30 16:46:30 dholland Exp $      */
+/*     $NetBSD: quota.c,v 1.47 2012/02/01 17:48:10 dholland Exp $      */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)quota.c    8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: quota.c,v 1.46 2012/01/30 16:46:30 dholland Exp $");
+__RCSID("$NetBSD: quota.c,v 1.47 2012/02/01 17:48:10 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -610,46 +610,31 @@
 static int
 isover(struct quotaval *qv, time_t now)
 {
-       int ql_stat;
-
-       ql_stat = quota_check_limit(qv->qv_usage, 1,
-                                   qv->qv_softlimit,
-                                   qv->qv_hardlimit,
-                                   qv->qv_expiretime, now);
-       switch(QL_STATUS(ql_stat)) {
-           case QL_S_DENY_HARD:
-           case QL_S_DENY_GRACE:
-           case QL_S_ALLOW_SOFT:
-               return 1;
-           default:
-               break;
-       }
-       return 0;
+       return (qv->qv_usage >= qv->qv_hardlimit ||
+               qv->qv_usage >= qv->qv_softlimit);
 }
 
 static const char *
 getovermsg(struct quotaval *qv, const char *what, time_t now)
 {
        static char buf[64];
-       int ql_stat;
 
-       ql_stat = quota_check_limit(qv->qv_usage, 1,
-                                   qv->qv_softlimit,
-                                   qv->qv_hardlimit,
-                                   qv->qv_expiretime, now);
-       switch(QL_STATUS(ql_stat)) {
-           case QL_S_DENY_HARD:
+       if (qv->qv_usage >= qv->qv_hardlimit) {
                snprintf(buf, sizeof(buf), "%c%s limit reached on",
                         toupper((unsigned char)what[0]), what+1);
-               break;
-           case QL_S_DENY_GRACE:
-               snprintf(buf, sizeof(buf), "Over %s quota on", what);
-               break;
-           case QL_S_ALLOW_SOFT:
-               snprintf(buf, sizeof(buf), "In %s grace period on", what);
-               break;
-           default:
+               return buf;
+       }
+
+       if (qv->qv_usage < qv->qv_softlimit) {
+               /* Ok */
                return NULL;
        }
+
+       if (now > qv->qv_expiretime) {
+               snprintf(buf, sizeof(buf), "Over %s quota on", what);
+               return buf;
+       }
+
+       snprintf(buf, sizeof(buf), "In %s grace period on", what);
        return buf;
 }
diff -r 2a6911749d48 -r 3aa37b1a0aca usr.sbin/repquota/repquota.c
--- a/usr.sbin/repquota/repquota.c      Wed Feb 01 17:11:46 2012 +0000
+++ b/usr.sbin/repquota/repquota.c      Wed Feb 01 17:48:10 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: repquota.c,v 1.40 2012/02/01 05:12:45 dholland Exp $   */
+/*     $NetBSD: repquota.c,v 1.41 2012/02/01 17:48:10 dholland Exp $   */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)repquota.c 8.2 (Berkeley) 11/22/94";
 #else
-__RCSID("$NetBSD: repquota.c,v 1.40 2012/02/01 05:12:45 dholland Exp $");
+__RCSID("$NetBSD: repquota.c,v 1.41 2012/02/01 17:48:10 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -118,6 +118,7 @@
 static void    printquotas(int, struct quotahandle *);
 static void    exportquotas(void);
 static int     oneof(const char *, char *[], int cnt);
+static int isover(struct quotaval *qv, time_t now);
 
 int
 main(int argc, char **argv)
@@ -330,17 +331,11 @@
                if (fup == 0)
                        continue;
                for (i = 0; i < REPQUOTA_NUMOBJTYPES; i++) {
-                       switch (QL_STATUS(quota_check_limit(q[i].qv_usage, 1,
-                           q[i].qv_softlimit, q[i].qv_hardlimit,
-                           q[i].qv_expiretime, now))) {
-                       case QL_S_DENY_HARD:
-                       case QL_S_DENY_GRACE:
-                       case QL_S_ALLOW_SOFT:
+                       if (isover(&q[i], now)) {
                                timemsg[i] = timeprt(b0[i], 8, now,
                                    q[i].qv_expiretime);
                                overchar[i] = '+';
-                               break;
-                       default:
+                       } else {
                                if (vflag && q[i].qv_grace != QUOTA_NOTIME) {
                                        timemsg[i] = timeprt(b0[i], 8, 0,
                                                             q[i].qv_grace);
@@ -348,7 +343,6 @@
                                        timemsg[i] = "";
                                }
                                overchar[i] = '-';
-                               break;
                        }
                }
 
@@ -571,3 +565,10 @@
                        return i;
        return -1;
 }
+
+static int
+isover(struct quotaval *qv, time_t now)
+{ 
+       return (qv->qv_usage >= qv->qv_hardlimit ||
+               qv->qv_usage >= qv->qv_softlimit);
+} 



Home | Main Index | Thread Index | Old Index