diff options
author | Daniel Hartmeier <dhartmei@cvs.openbsd.org> | 2002-02-25 04:53:17 +0000 |
---|---|---|
committer | Daniel Hartmeier <dhartmei@cvs.openbsd.org> | 2002-02-25 04:53:17 +0000 |
commit | f7848364f2a1ee9cef20b19f1396e5796a1b5c6f (patch) | |
tree | 81fc6f5369cf786c5f1cd932eddbdf58dfa6c64b | |
parent | 0f17b0b30f9e5187cb51ca2a7a7d427e5f66a350 (diff) |
Make pool_sethardlimit() check that it doesn't decrease the limit below
the current size of the pool. ok art@
-rw-r--r-- | share/man/man9/pool.9 | 11 | ||||
-rw-r--r-- | sys/kern/subr_pool.c | 19 | ||||
-rw-r--r-- | sys/kern/uipc_mbuf.c | 4 | ||||
-rw-r--r-- | sys/sys/pool.h | 4 |
4 files changed, 25 insertions, 13 deletions
diff --git a/share/man/man9/pool.9 b/share/man/man9/pool.9 index 02156e4edd6..24785646a11 100644 --- a/share/man/man9/pool.9 +++ b/share/man/man9/pool.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pool.9,v 1.16 2002/02/25 00:23:20 art Exp $ +.\" $OpenBSD: pool.9,v 1.17 2002/02/25 04:53:16 dhartmei Exp $ .\" $NetBSD: pool.9,v 1.18 2001/06/21 11:59:01 wiz Exp $ .\" .\" Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -75,7 +75,7 @@ .Fn pool_sethiwat "struct pool *pp" "int n" .Ft void .Fn pool_setlowat "struct pool *pp" "int n" -.Ft void +.Ft int .Fo pool_sethardlimit .Fa "struct pool *pp" .Fa "int n" @@ -305,8 +305,8 @@ Unlike this function does not allocate the necessary memory up-front. .El .Ss SETTING HARD LIMITS -The -.Fn pool_sethardlmit +The function +.Fn pool_sethardlimit sets a hard limit on the pool to .Fa n items. @@ -315,6 +315,9 @@ If the hard limit is reached will be printed to the console, but no more than every .Fa ratecap seconds. +Upon successful completion, a value of 0 is returned. +The value EINVAL is returned when the current size of the pool +already exceeds the requested hard limit. .Ss POTENTIAL PITFALLS Note that undefined behaviour results when mixing the storage providing methods supported by the pool resource routines. diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index e9ea1657039..d6cb4495ad6 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.27 2002/02/23 02:52:56 art Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.28 2002/02/25 04:53:16 dhartmei Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -1217,12 +1217,18 @@ pool_sethiwat(struct pool *pp, int n) simple_unlock(&pp->pr_slock); } -void -pool_sethardlimit(struct pool *pp, int n, const char *warnmess, int ratecap) +int +pool_sethardlimit(struct pool *pp, unsigned n, const char *warnmess, int ratecap) { + int error = 0; simple_lock(&pp->pr_slock); + if (n < pp->pr_nout) { + error = EINVAL; + goto done; + } + pp->pr_hardlimit = n; pp->pr_hardlimit_warning = warnmess; pp->pr_hardlimit_ratecap.tv_sec = ratecap; @@ -1233,11 +1239,14 @@ pool_sethardlimit(struct pool *pp, int n, const char *warnmess, int ratecap) * In-line version of pool_sethiwat(), because we don't want to * release the lock. */ - pp->pr_maxpages = (n == 0) - ? 0 + pp->pr_maxpages = (n == 0 || n == UINT_MAX) + ? n : roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage; + done: simple_unlock(&pp->pr_slock); + + return (error); } /* diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 6a913bb0e98..8aaddd83194 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_mbuf.c,v 1.55 2002/02/17 22:59:53 maja Exp $ */ +/* $OpenBSD: uipc_mbuf.c,v 1.56 2002/02/25 04:53:16 dhartmei Exp $ */ /* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */ /* @@ -130,7 +130,7 @@ mbinit() * mbuf clusters the kernel is to support. Log the limit * reached message max once a minute. */ - pool_sethardlimit(&mclpool, nmbclust, mclpool_warnmsg, 60); + (void)pool_sethardlimit(&mclpool, nmbclust, mclpool_warnmsg, 60); /* * Set a low water mark for both mbufs and clusters. This should diff --git a/sys/sys/pool.h b/sys/sys/pool.h index 18c25df4cf5..bf1a1a46023 100644 --- a/sys/sys/pool.h +++ b/sys/sys/pool.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pool.h,v 1.10 2002/02/23 02:52:56 art Exp $ */ +/* $OpenBSD: pool.h,v 1.11 2002/02/25 04:53:16 dhartmei Exp $ */ /* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */ /*- @@ -224,7 +224,7 @@ void _pool_reclaim(struct pool *, const char *, long); int pool_prime(struct pool *, int); void pool_setlowat(struct pool *, int); void pool_sethiwat(struct pool *, int); -void pool_sethardlimit(struct pool *, int, const char *, int); +int pool_sethardlimit(struct pool *, unsigned, const char *, int); void pool_drain(void *); /* |