xref: /freebsd/sys/geom/virstor/g_virstor.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2006-2007 Ivan Voras <ivoras@freebsd.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _G_VIRSTOR_H_
30 #define _G_VIRSTOR_H_
31 
32 #define	G_VIRSTOR_CLASS_NAME "VIRSTOR"
33 
34 #define VIRSTOR_MAP_ALLOCATED 1
35 struct virstor_map_entry {
36 	uint16_t	flags;
37 	uint16_t	provider_no;
38 	uint32_t	provider_chunk;
39 };
40 
41 #define	VIRSTOR_MAP_ENTRY_SIZE (sizeof(struct virstor_map_entry))
42 #define	VIRSTOR_MAP_BLOCK_ENTRIES (maxphys / VIRSTOR_MAP_ENTRY_SIZE)
43 /* Struct size is guarded by MPASS in main source */
44 
45 #ifdef _KERNEL
46 
47 #define	LOG_MSG(lvl, ...) \
48     _GEOM_DEBUG("GEOM_VIRSTOR", g_virstor_debug, (lvl), NULL, __VA_ARGS__)
49 #define	LOG_MESSAGE LOG_MSG
50 
51 #define	LOG_REQ(lvl, bp, ...) \
52     _GEOM_DEBUG("GEOM_VIRSTOR", g_virstor_debug, (lvl), (bp), __VA_ARGS__)
53 #define	LOG_REQUEST LOG_REQ
54 
55 /* "critical" system announcements (e.g. "geom is up") */
56 #define	LVL_ANNOUNCE	0
57 /* errors */
58 #define	LVL_ERROR	1
59 /* warnings */
60 #define	LVL_WARNING	2
61 /* info, noncritical for system operation (user doesn't have to see it */
62 #define	LVL_INFO	5
63 /* debug info */
64 #define	LVL_DEBUG	10
65 /* more debug info */
66 #define	LVL_DEBUG2	12
67 /* superfluous debug info (large volumes of data) */
68 #define	LVL_MOREDEBUG	15
69 
70 /* Component data */
71 struct g_virstor_component {
72 	struct g_consumer	*gcons;
73 	struct g_virstor_softc	*sc;
74 	unsigned int		 index;		/* Component index in array */
75 	unsigned int		 chunk_count;
76 	unsigned int		 chunk_next;
77 	unsigned int		 chunk_reserved;
78 	unsigned int		 flags;
79 };
80 
81 /* Internal geom instance data */
82 struct g_virstor_softc {
83 	struct g_geom		*geom;
84 	struct g_provider	*provider;
85 	struct g_virstor_component *components;
86 	u_int			 n_components;
87 	u_int			 curr_component; /* Component currently used */
88 	uint32_t		 id;		/* Unique ID of this geom */
89 	off_t			 virsize;	/* Total size of virstor */
90 	off_t			 sectorsize;
91 	size_t			 chunk_size;
92 	size_t			 chunk_count;	/* governs map_size */
93 	struct virstor_map_entry *map;
94 	size_t			 map_size;	/* (in bytes) */
95 	size_t			 map_sectors;	/* Size of map in sectors */
96 	size_t			 me_per_sector;	/* # map entries in a sector */
97 	STAILQ_HEAD(, g_virstor_bio_q)	 delayed_bio_q;	/* Queue of delayed BIOs */
98 	struct mtx		 delayed_bio_q_mtx;
99 };
100 
101 /* "delayed BIOs" Queue element */
102 struct g_virstor_bio_q {
103 	struct bio		*bio;
104 	STAILQ_ENTRY(g_virstor_bio_q) linkage;
105 };
106 
107 #endif	/* _KERNEL */
108 
109 #endif	/* !_G_VIRSTOR_H_ */
110