xref: /minix3/sys/sys/extent.h (revision 6c8f7fc3bac7ab5f78ee27de8bed706631d8c836)
1*6c8f7fc3SBen Gras /*	$NetBSD: extent.h,v 1.19 2012/01/27 18:53:10 para Exp $	*/
2*6c8f7fc3SBen Gras 
3*6c8f7fc3SBen Gras /*-
4*6c8f7fc3SBen Gras  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
5*6c8f7fc3SBen Gras  * All rights reserved.
6*6c8f7fc3SBen Gras  *
7*6c8f7fc3SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
8*6c8f7fc3SBen Gras  * by Jason R. Thorpe.
9*6c8f7fc3SBen Gras  *
10*6c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
11*6c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
12*6c8f7fc3SBen Gras  * are met:
13*6c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
14*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
15*6c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
16*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
17*6c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
18*6c8f7fc3SBen Gras  *
19*6c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*6c8f7fc3SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*6c8f7fc3SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*6c8f7fc3SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*6c8f7fc3SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*6c8f7fc3SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*6c8f7fc3SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*6c8f7fc3SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*6c8f7fc3SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*6c8f7fc3SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*6c8f7fc3SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
30*6c8f7fc3SBen Gras  */
31*6c8f7fc3SBen Gras 
32*6c8f7fc3SBen Gras #ifndef _SYS_EXTENT_H_
33*6c8f7fc3SBen Gras #define _SYS_EXTENT_H_
34*6c8f7fc3SBen Gras 
35*6c8f7fc3SBen Gras #include <sys/queue.h>
36*6c8f7fc3SBen Gras #include <sys/mutex.h>
37*6c8f7fc3SBen Gras #include <sys/condvar.h>
38*6c8f7fc3SBen Gras 
39*6c8f7fc3SBen Gras struct extent_region {
40*6c8f7fc3SBen Gras 	LIST_ENTRY(extent_region) er_link;	/* link in region list */
41*6c8f7fc3SBen Gras 	u_long 	er_start;		/* start of region */
42*6c8f7fc3SBen Gras 	u_long	er_end;			/* end of region */
43*6c8f7fc3SBen Gras 	int	er_flags;		/* misc. flags */
44*6c8f7fc3SBen Gras };
45*6c8f7fc3SBen Gras 
46*6c8f7fc3SBen Gras /* er_flags */
47*6c8f7fc3SBen Gras #define ER_ALLOC	0x01	/* region descriptor dynamically allocated */
48*6c8f7fc3SBen Gras 
49*6c8f7fc3SBen Gras struct extent {
50*6c8f7fc3SBen Gras 	const char *ex_name;		/* name of extent */
51*6c8f7fc3SBen Gras 	kmutex_t ex_lock;		/* lock on this extent */
52*6c8f7fc3SBen Gras 	kcondvar_t ex_cv;		/* synchronization */
53*6c8f7fc3SBen Gras 					/* allocated regions in extent */
54*6c8f7fc3SBen Gras 	LIST_HEAD(, extent_region) ex_regions;
55*6c8f7fc3SBen Gras 	u_long	ex_start;		/* start of extent */
56*6c8f7fc3SBen Gras 	u_long	ex_end;			/* end of extent */
57*6c8f7fc3SBen Gras 	int	ex_flags;		/* misc. information */
58*6c8f7fc3SBen Gras };
59*6c8f7fc3SBen Gras 
60*6c8f7fc3SBen Gras struct extent_fixed {
61*6c8f7fc3SBen Gras 	struct extent	fex_extent;	/* MUST BE FIRST */
62*6c8f7fc3SBen Gras 					/* freelist of region descriptors */
63*6c8f7fc3SBen Gras 	LIST_HEAD(, extent_region) fex_freelist;
64*6c8f7fc3SBen Gras 	void *		fex_storage;	/* storage space for descriptors */
65*6c8f7fc3SBen Gras 	size_t		fex_storagesize; /* size of storage space */
66*6c8f7fc3SBen Gras };
67*6c8f7fc3SBen Gras 
68*6c8f7fc3SBen Gras /* ex_flags; for internal use only */
69*6c8f7fc3SBen Gras #define EXF_FIXED	0x01		/* extent uses fixed storage */
70*6c8f7fc3SBen Gras #define EXF_NOCOALESCE	0x02		/* coalescing of regions not allowed */
71*6c8f7fc3SBen Gras #define EXF_FLWANTED	0x08		/* someone asleep on freelist */
72*6c8f7fc3SBen Gras 
73*6c8f7fc3SBen Gras #define EXF_BITS	"\20\4FLWANTED\2NOCOALESCE\1FIXED"
74*6c8f7fc3SBen Gras 
75*6c8f7fc3SBen Gras /* misc. flags passed to extent functions */
76*6c8f7fc3SBen Gras #define EX_NOWAIT	0x00		/* not safe to sleep */
77*6c8f7fc3SBen Gras #define EX_WAITOK	0x01		/* safe to sleep */
78*6c8f7fc3SBen Gras #define EX_FAST		0x02		/* take first fit in extent_alloc() */
79*6c8f7fc3SBen Gras #define EX_CATCH	0x04		/* catch signals while sleeping */
80*6c8f7fc3SBen Gras #define EX_NOCOALESCE	0x08		/* create a non-coalescing extent */
81*6c8f7fc3SBen Gras #define EX_MALLOCOK	0x10		/* safe to call kmem_alloc() */
82*6c8f7fc3SBen Gras #define EX_WAITSPACE	0x20		/* wait for space to become free */
83*6c8f7fc3SBen Gras #define EX_BOUNDZERO	0x40		/* boundary lines start at 0 */
84*6c8f7fc3SBen Gras 
85*6c8f7fc3SBen Gras /*
86*6c8f7fc3SBen Gras  * Special place holders for "alignment" and "boundary" arguments,
87*6c8f7fc3SBen Gras  * in the event the caller doesn't wish to use those features.
88*6c8f7fc3SBen Gras  */
89*6c8f7fc3SBen Gras #define EX_NOALIGN	1		/* don't do alignment */
90*6c8f7fc3SBen Gras #define EX_NOBOUNDARY	0		/* don't do boundary checking */
91*6c8f7fc3SBen Gras 
92*6c8f7fc3SBen Gras #if defined(_KERNEL) || defined(_EXTENT_TESTING)
93*6c8f7fc3SBen Gras #define EXTENT_FIXED_STORAGE_SIZE(_nregions)		\
94*6c8f7fc3SBen Gras 	(ALIGN(sizeof(struct extent_fixed)) +		\
95*6c8f7fc3SBen Gras 	((ALIGN(sizeof(struct extent_region))) *	\
96*6c8f7fc3SBen Gras 	 (_nregions)))
97*6c8f7fc3SBen Gras 
98*6c8f7fc3SBen Gras struct	extent *extent_create(const char *, u_long, u_long,
99*6c8f7fc3SBen Gras 	    void *, size_t, int);
100*6c8f7fc3SBen Gras void	extent_destroy(struct extent *);
101*6c8f7fc3SBen Gras int	extent_alloc_subregion1(struct extent *, u_long, u_long,
102*6c8f7fc3SBen Gras 	    u_long, u_long, u_long, u_long, int, u_long *);
103*6c8f7fc3SBen Gras int	extent_alloc_subregion(struct extent *, u_long, u_long,
104*6c8f7fc3SBen Gras 	    u_long, u_long, u_long, int, u_long *);
105*6c8f7fc3SBen Gras int	extent_alloc_region(struct extent *, u_long, u_long, int);
106*6c8f7fc3SBen Gras int	extent_alloc1(struct extent *, u_long, u_long, u_long, u_long, int,
107*6c8f7fc3SBen Gras 	    u_long *);
108*6c8f7fc3SBen Gras int	extent_alloc(struct extent *, u_long, u_long, u_long, int, u_long *);
109*6c8f7fc3SBen Gras int	extent_free(struct extent *, u_long, u_long, int);
110*6c8f7fc3SBen Gras void	extent_print(struct extent *);
111*6c8f7fc3SBen Gras void	extent_init(void);
112*6c8f7fc3SBen Gras 
113*6c8f7fc3SBen Gras #endif /* _KERNEL || _EXTENT_TESTING */
114*6c8f7fc3SBen Gras 
115*6c8f7fc3SBen Gras #endif /* ! _SYS_EXTENT_H_ */
116