From 1255d388f034dc556d235a002527101781dbeb29 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 22 Oct 2001 07:09:25 +0000 Subject: [PATCH] 1067. [func] Allow quotas to be soft, isc_quota_soft(). --- CHANGES | 2 ++ lib/isc/include/isc/quota.h | 12 ++++++++++-- lib/isc/include/isc/result.h | 5 +++-- lib/isc/quota.c | 22 ++++++++++++++++------ lib/isc/result.c | 5 +++-- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 5c7dfd492e..4bd4d64d42 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +1067. [func] Allow quotas to be soft, isc_quota_soft(). + 1066. [bug] Provide a thread safe wrapper for strerror(). [RT #1689] diff --git a/lib/isc/include/isc/quota.h b/lib/isc/include/isc/quota.h index c1648205ac..fccbe2c705 100644 --- a/lib/isc/include/isc/quota.h +++ b/lib/isc/include/isc/quota.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: quota.h,v 1.8 2001/01/09 21:57:22 bwelling Exp $ */ +/* $Id: quota.h,v 1.9 2001/10/22 07:09:25 marka Exp $ */ #ifndef ISC_QUOTA_H #define ISC_QUOTA_H 1 @@ -53,6 +53,7 @@ struct isc_quota { /* Locked by lock. */ int max; int used; + isc_boolean_t soft; }; isc_result_t @@ -71,6 +72,12 @@ isc_quota_destroy(isc_quota_t *quota); * Destroy a quota object. */ +void +isc_quota_soft(isc_quota_t *quota, isc_boolean_t soft); +/* + * Turn on/off soft quotas. + */ + isc_result_t isc_quota_reserve(isc_quota_t *quota); /* @@ -78,6 +85,7 @@ isc_quota_reserve(isc_quota_t *quota); * * Returns: * ISC_R_SUCCESS Success + * ISC_R_SOFTQUOTA Success soft quota reached * ISC_R_QUOTA Quota is full */ @@ -91,7 +99,7 @@ isc_result_t isc_quota_attach(isc_quota_t *quota, isc_quota_t **p); /* * Like isc_quota_reserve, and also attaches '*p' to the - * quota if successful. + * quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA). */ void diff --git a/lib/isc/include/isc/result.h b/lib/isc/include/isc/result.h index 685385ee59..9988f20289 100644 --- a/lib/isc/include/isc/result.h +++ b/lib/isc/include/isc/result.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: result.h,v 1.57 2001/06/15 22:07:51 gson Exp $ */ +/* $Id: result.h,v 1.58 2001/10/22 07:09:24 marka Exp $ */ #ifndef ISC_RESULT_H #define ISC_RESULT_H 1 @@ -78,11 +78,12 @@ #define ISC_R_UNBALANCEDQUOTES 52 /* unbalanced quotes */ #define ISC_R_INPROGRESS 53 /* operation in progress */ #define ISC_R_CONNECTIONRESET 54 /* connection reset */ +#define ISC_R_SOFTQUOTA 55 /* soft quota reached */ /* * Not a result code: the number of results. */ -#define ISC_R_NRESULTS 55 +#define ISC_R_NRESULTS 56 ISC_LANG_BEGINDECLS diff --git a/lib/isc/quota.c b/lib/isc/quota.c index be836e935b..2cb578cc5d 100644 --- a/lib/isc/quota.c +++ b/lib/isc/quota.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: quota.c,v 1.11 2001/01/09 21:56:21 bwelling Exp $ */ +/* $Id: quota.c,v 1.12 2001/10/22 07:09:22 marka Exp $ */ #include @@ -28,6 +28,7 @@ isc_result_t isc_quota_init(isc_quota_t *quota, int max) { quota->max = max; quota->used = 0; + quota->soft = ISC_FALSE; return (isc_mutex_init("a->lock)); } @@ -36,9 +37,15 @@ isc_quota_destroy(isc_quota_t *quota) { INSIST(quota->used == 0); quota->max = -1; quota->used = -1; + quota->soft = ISC_FALSE; DESTROYLOCK("a->lock); } +void +isc_quota_soft(isc_quota_t *quota, isc_boolean_t soft) { + quota->soft = soft; +} + isc_result_t isc_quota_reserve(isc_quota_t *quota) { isc_result_t result; @@ -47,7 +54,11 @@ isc_quota_reserve(isc_quota_t *quota) { quota->used++; result = ISC_R_SUCCESS; } else { - result = ISC_R_QUOTA; + if (quota->soft) { + quota->used++; + result = ISC_R_SOFTQUOTA; + } else + result = ISC_R_QUOTA; } UNLOCK("a->lock); return (result); @@ -67,10 +78,9 @@ isc_quota_attach(isc_quota_t *quota, isc_quota_t **p) isc_result_t result; INSIST(p != NULL && *p == NULL); result = isc_quota_reserve(quota); - if (result != ISC_R_SUCCESS) - return (result); - *p = quota; - return (ISC_R_SUCCESS); + if (result == ISC_R_SUCCESS || result == ISC_R_SOFTQUOTA) + *p = quota; + return (result); } void diff --git a/lib/isc/result.c b/lib/isc/result.c index 085382f8b5..fbc24e222b 100644 --- a/lib/isc/result.c +++ b/lib/isc/result.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: result.c,v 1.56 2001/06/15 22:07:50 gson Exp $ */ +/* $Id: result.c,v 1.57 2001/10/22 07:09:21 marka Exp $ */ #include @@ -92,7 +92,8 @@ static const char *text[ISC_R_NRESULTS] = { "not blocking", /* 51 */ "unbalanced quotes", /* 52 */ "operation in progress", /* 53 */ - "connection reset" /* 54 */ + "connection reset", /* 54 */ + "soft quota reached" /* 55 */ }; #define ISC_RESULT_RESULTSET 2