1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2017 Nexenta Inc.  All rights reserved.
14  * Copyright 2020 Joyent, Inc.
15  */
16 
17 #ifndef _SYS_DKIOC_FREE_UTIL_H
18 #define	_SYS_DKIOC_FREE_UTIL_H
19 
20 #include <sys/dkio.h>
21 
22 #ifdef	__cplusplus
23 extern "C" {
24 #endif
25 
26 #define	DFL_COPYIN_MAX_EXTS	(1024 * 1024)
27 
28 #define	DFL_ISSYNC(dfl) (((dfl)->dfl_flags & DF_WAIT_SYNC) ? B_TRUE : B_FALSE)
29 
30 /*
31  * Since dkioc_free_list_t and in general DKIOCFREE use bytes to express
32  * values instead of blocks, dkioc_free_info_t uses bytes as well for
33  * consistency.
34  */
35 typedef struct dkioc_free_info {
36 	/* log2(block size) */
37 	uint64_t	dfi_bshift;
38 
39 	/* Maximum number of extents in a single request. 0 == no limit */
40 	uint64_t	dfi_max_ext;
41 
42 	/*
43 	 * Maximum total number of bytes in a single request.  0 == no limit.
44 	 * Must by a multiple of 1U << dfi_bshift (e.g. dfi_bshift == 9,
45 	 * dfk_max_bytes must be a multiple of 512).
46 	 */
47 	uint64_t	dfi_max_bytes;
48 
49 	/*
50 	 * Maximum length of an extent. 0 == same as dfi_max_bytes. If > 0,
51 	 * must be a multiple of 1U << dfi_shift (the block size) and
52 	 * <= dfi_max_bytes.
53 	 */
54 	uint64_t	dfi_max_ext_bytes;
55 
56 	/*
57 	 * Minimum alignment for starting extent offsets in bytes
58 	 * Must be > 0, and a multiple of 1U << dfi_shift.
59 	 *
60 	 * A possible future extention might be to also express a preferred
61 	 * alignment when splitting extents.
62 	 */
63 	uint64_t	dfi_align;
64 } dkioc_free_info_t;
65 
66 typedef int (*dfl_iter_fn_t)(dkioc_free_list_t *dfl, void *arg, int kmflag);
67 
68 int dfl_copyin(void *arg, dkioc_free_list_t **out, int ddi_flags, int kmflags);
69 void dfl_free(dkioc_free_list_t *dfl);
70 int dfl_iter(dkioc_free_list_t *dfl, const dkioc_free_info_t *dfi, uint64_t len,
71     dfl_iter_fn_t fn, void *arg, int kmflag);
72 
73 #ifdef	__cplusplus
74 }
75 #endif
76 
77 #endif /* _SYS_DKIOC_FREE_UTIL_H */
78