Sun Jun 13 14:58:50 2021 UTC ()
Return ENOENT if the hashstat sysctl was called to query a specific hash
name and that hash name doesn't exist.


(simonb)
diff -r1.11 -r1.12 src/sys/kern/subr_hash.c

cvs diff -r1.11 -r1.12 src/sys/kern/subr_hash.c (expand / switch to unified diff)

--- src/sys/kern/subr_hash.c 2021/06/13 14:02:46 1.11
+++ src/sys/kern/subr_hash.c 2021/06/13 14:58:49 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_hash.c,v 1.11 2021/06/13 14:02:46 christos Exp $ */ 1/* $NetBSD: subr_hash.c,v 1.12 2021/06/13 14:58:49 simonb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1982, 1986, 1991, 1993 4 * Copyright (c) 1982, 1986, 1991, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc. 6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed 7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph 8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc. 10 * the permission of UNIX System Laboratories, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * @(#)kern_subr.c 8.4 (Berkeley) 2/14/95 36 * @(#)kern_subr.c 8.4 (Berkeley) 2/14/95
37 */ 37 */
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40__KERNEL_RCSID(0, "$NetBSD: subr_hash.c,v 1.11 2021/06/13 14:02:46 christos Exp $"); 40__KERNEL_RCSID(0, "$NetBSD: subr_hash.c,v 1.12 2021/06/13 14:58:49 simonb Exp $");
41 41
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/bitops.h> 43#include <sys/bitops.h>
44#include <sys/kmem.h> 44#include <sys/kmem.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/pslist.h> 46#include <sys/pslist.h>
47#include <sys/rwlock.h> 47#include <sys/rwlock.h>
48#include <sys/sysctl.h> 48#include <sys/sysctl.h>
49 49
50static int hashstat_sysctl(SYSCTLFN_PROTO); 50static int hashstat_sysctl(SYSCTLFN_PROTO);
51 51
52static size_t 52static size_t
53hash_list_size(enum hashtype htype) 53hash_list_size(enum hashtype htype)
@@ -233,26 +233,29 @@ hashstat_sysctl(SYSCTLFN_ARGS) @@ -233,26 +233,29 @@ hashstat_sysctl(SYSCTLFN_ARGS)
233 error = hash->hs_func(&hs, fill); 233 error = hash->hs_func(&hs, fill);
234 if (error) 234 if (error)
235 break; 235 break;
236 236
237 error = sysctl_copyout(l, &hs, oldp, sizeof(hs)); 237 error = sysctl_copyout(l, &hs, oldp, sizeof(hs));
238 if (error) 238 if (error)
239 break; 239 break;
240 written += sizeof(hs); 240 written += sizeof(hs);
241 oldp = (char *)oldp + sizeof(hs); 241 oldp = (char *)oldp + sizeof(hs);
242 } 242 }
243 rw_exit(&hashstat_lock); 243 rw_exit(&hashstat_lock);
244 sysctl_relock(); 244 sysctl_relock();
245 245
 246 if (query && written == 0) /* query not found? */
 247 error = ENOENT;
 248
246 *oldlenp = written; 249 *oldlenp = written;
247 return error; 250 return error;
248} 251}
249 252
250 253
251SYSCTL_SETUP(sysctl_hash_setup, "sysctl hash stats setup") 254SYSCTL_SETUP(sysctl_hash_setup, "sysctl hash stats setup")
252{ 255{
253 256
254 rw_init(&hashstat_lock); /* as good a place as any for this */ 257 rw_init(&hashstat_lock); /* as good a place as any for this */
255 258
256 sysctl_createv(NULL, 0, NULL, NULL, 259 sysctl_createv(NULL, 0, NULL, NULL,
257 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 260 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
258 CTLTYPE_STRUCT, 261 CTLTYPE_STRUCT,