1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 29 */ 30 31 #ifndef _G_VIRSTOR_H_ 32 #define _G_VIRSTOR_H_ 33 34 #define G_VIRSTOR_CLASS_NAME "VIRSTOR" 35 36 37 #define VIRSTOR_MAP_ALLOCATED 1 38 struct virstor_map_entry { 39 uint16_t flags; 40 uint16_t provider_no; 41 uint32_t provider_chunk; 42 }; 43 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 */ 47 48 #ifdef _KERNEL 49 50 #define LOG_MSG(lvl, ...) do { \ 51 if (g_virstor_debug >= (lvl)) { \ 52 printf("GEOM_" G_VIRSTOR_CLASS_NAME); \ 53 if ((lvl) > 0) \ 54 printf("[%u]", (lvl)); \ 55 printf(": "); \ 56 printf(__VA_ARGS__); \ 57 printf("\n"); \ 58 } \ 59 } while (0) 60 #define LOG_MESSAGE LOG_MSG 61 62 #define LOG_REQ(lvl, bp, ...) do { \ 63 if (g_virstor_debug >= (lvl)) { \ 64 printf("GEOM_" G_VIRSTOR_CLASS_NAME); \ 65 if ((lvl) > 0) \ 66 printf("[%u]", (lvl)); \ 67 printf(": "); \ 68 printf(__VA_ARGS__); \ 69 printf(" "); \ 70 g_print_bio(bp); \ 71 printf("\n"); \ 72 } \ 73 } while (0) 74 #define LOG_REQUEST LOG_REQ 75 76 /* "critical" system announcements (e.g. "geom is up") */ 77 #define LVL_ANNOUNCE 0 78 /* errors */ 79 #define LVL_ERROR 1 80 /* warnings */ 81 #define LVL_WARNING 2 82 /* info, noncritical for system operation (user doesn't have to see it */ 83 #define LVL_INFO 5 84 /* debug info */ 85 #define LVL_DEBUG 10 86 /* more debug info */ 87 #define LVL_DEBUG2 12 88 /* superfluous debug info (large volumes of data) */ 89 #define LVL_MOREDEBUG 15 90 91 92 /* Component data */ 93 struct g_virstor_component { 94 struct g_consumer *gcons; 95 struct g_virstor_softc *sc; 96 unsigned int index; /* Component index in array */ 97 unsigned int chunk_count; 98 unsigned int chunk_next; 99 unsigned int chunk_reserved; 100 unsigned int flags; 101 }; 102 103 104 /* Internal geom instance data */ 105 struct g_virstor_softc { 106 struct g_geom *geom; 107 struct g_provider *provider; 108 struct g_virstor_component *components; 109 u_int n_components; 110 u_int curr_component; /* Component currently used */ 111 uint32_t id; /* Unique ID of this geom */ 112 off_t virsize; /* Total size of virstor */ 113 off_t sectorsize; 114 size_t chunk_size; 115 size_t chunk_count; /* governs map_size */ 116 struct virstor_map_entry *map; 117 size_t map_size; /* (in bytes) */ 118 size_t map_sectors; /* Size of map in sectors */ 119 size_t me_per_sector; /* # map entries in a sector */ 120 STAILQ_HEAD(, g_virstor_bio_q) delayed_bio_q; /* Queue of delayed BIOs */ 121 struct mtx delayed_bio_q_mtx; 122 }; 123 124 /* "delayed BIOs" Queue element */ 125 struct g_virstor_bio_q { 126 struct bio *bio; 127 STAILQ_ENTRY(g_virstor_bio_q) linkage; 128 }; 129 130 131 #endif /* _KERNEL */ 132 133 #ifndef _PATH_DEV 134 #define _PATH_DEV "/dev/" 135 #endif 136 137 #endif /* !_G_VIRSTOR_H_ */ 138