2 * Copyright (c) 2006-2007 Ivan Voras <ivoras@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #define G_VIRSTOR_CLASS_NAME "VIRSTOR"
35 #define VIRSTOR_MAP_ALLOCATED 1
36 struct virstor_map_entry {
39 uint32_t provider_chunk;
42 #define VIRSTOR_MAP_ENTRY_SIZE (sizeof(struct virstor_map_entry))
43 #define VIRSTOR_MAP_BLOCK_ENTRIES (MAXPHYS / VIRSTOR_MAP_ENTRY_SIZE)
44 /* Struct size is guarded by CTASSERT in main source */
48 #define LOG_MSG(lvl, ...) do { \
49 if (g_virstor_debug >= (lvl)) { \
50 printf("GEOM_" G_VIRSTOR_CLASS_NAME); \
52 printf("[%u]", lvl); \
54 printf(__VA_ARGS__); \
58 #define LOG_MESSAGE LOG_MSG
60 #define LOG_REQ(lvl, bp, ...) do { \
61 if (g_virstor_debug >= (lvl)) { \
62 printf("GEOM_" G_VIRSTOR_CLASS_NAME); \
64 printf("[%u]", lvl); \
66 printf(__VA_ARGS__); \
72 #define LOG_REQUEST LOG_REQ
74 /* "critical" system announcements (e.g. "geom is up") */
75 #define LVL_ANNOUNCE 0
80 /* info, noncritical for system operation (user doesn't have to see it */
86 /* superfluous debug info (large volumes of data) */
87 #define LVL_MOREDEBUG 15
91 struct g_virstor_component {
92 struct g_consumer *gcons;
93 struct g_virstor_softc *sc;
94 unsigned int index; /* Component index in array */
95 unsigned int chunk_count;
96 unsigned int chunk_next;
97 unsigned int chunk_reserved;
102 /* Internal geom instance data */
103 struct g_virstor_softc {
105 struct g_provider *provider;
106 struct g_virstor_component *components;
108 u_int curr_component; /* Component currently used */
109 uint32_t id; /* Unique ID of this geom */
110 off_t virsize; /* Total size of virstor */
113 size_t chunk_count; /* governs map_size */
114 struct virstor_map_entry *map;
115 size_t map_size; /* (in bytes) */
116 size_t map_sectors; /* Size of map in sectors */
117 size_t me_per_sector; /* # map entries in a sector */
118 STAILQ_HEAD(, g_virstor_bio_q) delayed_bio_q; /* Queue of delayed BIOs */
119 struct mtx delayed_bio_q_mtx;
122 /* "delayed BIOs" Queue element */
123 struct g_virstor_bio_q {
125 STAILQ_ENTRY(g_virstor_bio_q) linkage;
132 #define _PATH_DEV "/dev/"
135 #endif /* !_G_VIRSTOR_H_ */