1 /*- 2 * Copyright (c) 2006-2007 Ivan Voras <ivoras@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _G_VIRSTOR_H_ 30 #define _G_VIRSTOR_H_ 31 32 #define G_VIRSTOR_CLASS_NAME "VIRSTOR" 33 34 35 #define VIRSTOR_MAP_ALLOCATED 1 36 struct virstor_map_entry { 37 uint16_t flags; 38 uint16_t provider_no; 39 uint32_t provider_chunk; 40 }; 41 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 */ 45 46 #ifdef _KERNEL 47 48 #define LOG_MSG(lvl, ...) do { \ 49 if (g_virstor_debug >= (lvl)) { \ 50 printf("GEOM_" G_VIRSTOR_CLASS_NAME); \ 51 if (lvl > 0) \ 52 printf("[%u]", lvl); \ 53 printf(": "); \ 54 printf(__VA_ARGS__); \ 55 printf("\n"); \ 56 } \ 57 } while (0) 58 #define LOG_MESSAGE LOG_MSG 59 60 #define LOG_REQ(lvl, bp, ...) do { \ 61 if (g_virstor_debug >= (lvl)) { \ 62 printf("GEOM_" G_VIRSTOR_CLASS_NAME); \ 63 if (lvl > 0) \ 64 printf("[%u]", lvl); \ 65 printf(": "); \ 66 printf(__VA_ARGS__); \ 67 printf(" "); \ 68 g_print_bio(bp); \ 69 printf("\n"); \ 70 } \ 71 } while (0) 72 #define LOG_REQUEST LOG_REQ 73 74 /* "critical" system announcements (e.g. "geom is up") */ 75 #define LVL_ANNOUNCE 0 76 /* errors */ 77 #define LVL_ERROR 1 78 /* warnings */ 79 #define LVL_WARNING 2 80 /* info, noncritical for system operation (user doesn't have to see it */ 81 #define LVL_INFO 5 82 /* debug info */ 83 #define LVL_DEBUG 10 84 /* more debug info */ 85 #define LVL_DEBUG2 12 86 /* superfluous debug info (large volumes of data) */ 87 #define LVL_MOREDEBUG 15 88 89 90 /* Component data */ 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; 98 unsigned int flags; 99 }; 100 101 102 /* Internal geom instance data */ 103 struct g_virstor_softc { 104 struct g_geom *geom; 105 struct g_provider *provider; 106 struct g_virstor_component *components; 107 u_int n_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 */ 111 off_t sectorsize; 112 size_t chunk_size; 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; 120 }; 121 122 /* "delayed BIOs" Queue element */ 123 struct g_virstor_bio_q { 124 struct bio *bio; 125 STAILQ_ENTRY(g_virstor_bio_q) linkage; 126 }; 127 128 129 #endif /* _KERNEL */ 130 131 #ifndef _PATH_DEV 132 #define _PATH_DEV "/dev/" 133 #endif 134 135 #endif /* !_G_VIRSTOR_H_ */ 136