2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006-2007 Ivan Voras <ivoras@freebsd.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
34 #define G_VIRSTOR_CLASS_NAME "VIRSTOR"
37 #define VIRSTOR_MAP_ALLOCATED 1
38 struct virstor_map_entry {
41 uint32_t provider_chunk;
44 #define VIRSTOR_MAP_ENTRY_SIZE (sizeof(struct virstor_map_entry))
45 #define VIRSTOR_MAP_BLOCK_ENTRIES (MAXPHYS / VIRSTOR_MAP_ENTRY_SIZE)
46 /* Struct size is guarded by CTASSERT in main source */
50 #define LOG_MSG(lvl, ...) \
51 _GEOM_DEBUG("GEOM_VIRSTOR", g_virstor_debug, (lvl), NULL, __VA_ARGS__)
52 #define LOG_MESSAGE LOG_MSG
54 #define LOG_REQ(lvl, bp, ...) \
55 _GEOM_DEBUG("GEOM_VIRSTOR", g_virstor_debug, (lvl), (bp), __VA_ARGS__)
56 #define LOG_REQUEST LOG_REQ
58 /* "critical" system announcements (e.g. "geom is up") */
59 #define LVL_ANNOUNCE 0
64 /* info, noncritical for system operation (user doesn't have to see it */
70 /* superfluous debug info (large volumes of data) */
71 #define LVL_MOREDEBUG 15
75 struct g_virstor_component {
76 struct g_consumer *gcons;
77 struct g_virstor_softc *sc;
78 unsigned int index; /* Component index in array */
79 unsigned int chunk_count;
80 unsigned int chunk_next;
81 unsigned int chunk_reserved;
86 /* Internal geom instance data */
87 struct g_virstor_softc {
89 struct g_provider *provider;
90 struct g_virstor_component *components;
92 u_int curr_component; /* Component currently used */
93 uint32_t id; /* Unique ID of this geom */
94 off_t virsize; /* Total size of virstor */
97 size_t chunk_count; /* governs map_size */
98 struct virstor_map_entry *map;
99 size_t map_size; /* (in bytes) */
100 size_t map_sectors; /* Size of map in sectors */
101 size_t me_per_sector; /* # map entries in a sector */
102 STAILQ_HEAD(, g_virstor_bio_q) delayed_bio_q; /* Queue of delayed BIOs */
103 struct mtx delayed_bio_q_mtx;
106 /* "delayed BIOs" Queue element */
107 struct g_virstor_bio_q {
109 STAILQ_ENTRY(g_virstor_bio_q) linkage;
116 #define _PATH_DEV "/dev/"
119 #endif /* !_G_VIRSTOR_H_ */