Skip to content

Commit 1911501

Browse files
robnbehlendorf
authored andcommitted
libspl: move random definitions from zfs_context.h
Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #17861
1 parent 55fb30e commit 1911501

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

include/sys/zfs_context.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ extern "C" {
126126
#include <sys/kmem.h>
127127
#include <sys/zfs_delay.h>
128128
#include <sys/vnode.h>
129-
#include <sys/random.h>
130129
#include <sys/callb.h>
131130
#include <sys/trace.h>
132131
#include <sys/systm.h>
133132
#include <sys/misc.h>
133+
#include <sys/random.h>
134134

135135
#include <sys/zfs_context_os.h>
136136

@@ -208,31 +208,8 @@ typedef off_t loff_t;
208208
#define NN_DIVISOR_1000 (1U << 0)
209209
#define NN_NUMBUF_SZ (6)
210210

211-
extern const char *random_path;
212-
extern const char *urandom_path;
213-
214211
extern int highbit64(uint64_t i);
215212
extern int lowbit64(uint64_t i);
216-
extern int random_get_bytes(uint8_t *ptr, size_t len);
217-
extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
218-
219-
static __inline__ uint32_t
220-
random_in_range(uint32_t range)
221-
{
222-
uint32_t r;
223-
224-
ASSERT(range != 0);
225-
226-
if (range == 1)
227-
return (0);
228-
229-
(void) random_get_pseudo_bytes((uint8_t *)&r, sizeof (r));
230-
231-
return (r % range);
232-
}
233-
234-
extern void random_init(void);
235-
extern void random_fini(void);
236213

237214
typedef struct callb_cpr {
238215
kmutex_t *cc_lockp;

lib/libspl/include/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ libspl_sys_HEADERS = \
5353
%D%/sys/priv.h \
5454
%D%/sys/processor.h \
5555
%D%/sys/procfs_list.h \
56+
%D%/sys/random.h \
5657
%D%/sys/rwlock.h \
5758
%D%/sys/simd.h \
5859
%D%/sys/stack.h \

lib/libspl/include/sys/misc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
#include <sys/utsname.h>
3333

34+
extern const char *random_path;
35+
extern const char *urandom_path;
36+
3437
/*
3538
* Hostname information
3639
*/

lib/libspl/include/sys/random.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: CDDL-1.0
2+
/*
3+
* CDDL HEADER START
4+
*
5+
* The contents of this file are subject to the terms of the
6+
* Common Development and Distribution License (the "License").
7+
* You may not use this file except in compliance with the License.
8+
*
9+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
* or https://opensource.org/licenses/CDDL-1.0.
11+
* See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*
14+
* When distributing Covered Code, include this CDDL HEADER in each
15+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
* If applicable, add the following below this CDDL HEADER, with the
17+
* fields enclosed by brackets "[]" replaced with your own identifying
18+
* information: Portions Copyright [yyyy] [name of copyright owner]
19+
*
20+
* CDDL HEADER END
21+
*/
22+
/*
23+
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24+
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25+
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
26+
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
27+
*/
28+
29+
#ifndef _SYS_RANDOM_H
30+
#define _SYS_RANDOM_H
31+
32+
extern int random_get_bytes(uint8_t *ptr, size_t len);
33+
extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
34+
35+
static __inline__ uint32_t
36+
random_in_range(uint32_t range)
37+
{
38+
uint32_t r;
39+
40+
ASSERT(range != 0);
41+
42+
if (range == 1)
43+
return (0);
44+
45+
(void) random_get_pseudo_bytes((uint8_t *)&r, sizeof (r));
46+
47+
return (r % range);
48+
}
49+
50+
#endif /* _SYS_RANDOM_H */

0 commit comments

Comments
 (0)