1b09121f9SPawel Jakub Dawidek /*- 2b09121f9SPawel Jakub Dawidek * Copyright (c) 2003 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3b09121f9SPawel Jakub Dawidek * All rights reserved. 4b09121f9SPawel Jakub Dawidek * 5b09121f9SPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without 6b09121f9SPawel Jakub Dawidek * modification, are permitted provided that the following conditions 7b09121f9SPawel Jakub Dawidek * are met: 8b09121f9SPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright 9b09121f9SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer. 10b09121f9SPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright 11b09121f9SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the 12b09121f9SPawel Jakub Dawidek * documentation and/or other materials provided with the distribution. 13b09121f9SPawel Jakub Dawidek * 14b09121f9SPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15b09121f9SPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16b09121f9SPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17b09121f9SPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18b09121f9SPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19b09121f9SPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20b09121f9SPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21b09121f9SPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22b09121f9SPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23b09121f9SPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24b09121f9SPawel Jakub Dawidek * SUCH DAMAGE. 25b09121f9SPawel Jakub Dawidek * 26b09121f9SPawel Jakub Dawidek * $FreeBSD$ 27b09121f9SPawel Jakub Dawidek */ 28b09121f9SPawel Jakub Dawidek 29b09121f9SPawel Jakub Dawidek #ifndef _G_STRIPE_H_ 30b09121f9SPawel Jakub Dawidek #define _G_STRIPE_H_ 31b09121f9SPawel Jakub Dawidek 32b09121f9SPawel Jakub Dawidek #include <sys/endian.h> 33b09121f9SPawel Jakub Dawidek 34b09121f9SPawel Jakub Dawidek #define G_STRIPE_CLASS_NAME "STRIPE" 35b09121f9SPawel Jakub Dawidek 36b09121f9SPawel Jakub Dawidek #define G_STRIPE_MAGIC "GEOM::STRIPE" 37a2e31b8bSPawel Jakub Dawidek #define G_STRIPE_VERSION 1 38b09121f9SPawel Jakub Dawidek 39b09121f9SPawel Jakub Dawidek #ifdef _KERNEL 40b09121f9SPawel Jakub Dawidek #define G_STRIPE_TYPE_MANUAL 0 41b09121f9SPawel Jakub Dawidek #define G_STRIPE_TYPE_AUTOMATIC 1 42b09121f9SPawel Jakub Dawidek 43b09121f9SPawel Jakub Dawidek #define G_STRIPE_DEBUG(lvl, ...) do { \ 44b09121f9SPawel Jakub Dawidek if (g_stripe_debug >= (lvl)) { \ 45b09121f9SPawel Jakub Dawidek printf("GEOM_STRIPE"); \ 46b09121f9SPawel Jakub Dawidek if (g_stripe_debug > 0) \ 47b09121f9SPawel Jakub Dawidek printf("[%u]", lvl); \ 48b09121f9SPawel Jakub Dawidek printf(": "); \ 49b09121f9SPawel Jakub Dawidek printf(__VA_ARGS__); \ 50b09121f9SPawel Jakub Dawidek printf("\n"); \ 51b09121f9SPawel Jakub Dawidek } \ 52b09121f9SPawel Jakub Dawidek } while (0) 53b09121f9SPawel Jakub Dawidek #define G_STRIPE_LOGREQ(bp, ...) do { \ 54b09121f9SPawel Jakub Dawidek if (g_stripe_debug >= 2) { \ 55b09121f9SPawel Jakub Dawidek printf("GEOM_STRIPE[2]: "); \ 56b09121f9SPawel Jakub Dawidek printf(__VA_ARGS__); \ 57b09121f9SPawel Jakub Dawidek printf(" "); \ 58b09121f9SPawel Jakub Dawidek g_print_bio(bp); \ 59b09121f9SPawel Jakub Dawidek printf("\n"); \ 60b09121f9SPawel Jakub Dawidek } \ 61b09121f9SPawel Jakub Dawidek } while (0) 62b09121f9SPawel Jakub Dawidek 63b09121f9SPawel Jakub Dawidek struct g_stripe_softc { 64b09121f9SPawel Jakub Dawidek u_int sc_type; /* provider type */ 65b09121f9SPawel Jakub Dawidek struct g_geom *sc_geom; 66b09121f9SPawel Jakub Dawidek struct g_provider *sc_provider; 67b09121f9SPawel Jakub Dawidek uint32_t sc_id; /* stripe unique ID */ 68b09121f9SPawel Jakub Dawidek struct g_consumer **sc_disks; 69b09121f9SPawel Jakub Dawidek uint16_t sc_ndisks; 70b09121f9SPawel Jakub Dawidek uint32_t sc_stripesize; 71b09121f9SPawel Jakub Dawidek uint32_t sc_stripebits; 72b09121f9SPawel Jakub Dawidek }; 73889c5dc2SPawel Jakub Dawidek #define sc_name sc_geom->name 74b09121f9SPawel Jakub Dawidek #endif /* _KERNEL */ 75b09121f9SPawel Jakub Dawidek 76b09121f9SPawel Jakub Dawidek struct g_stripe_metadata { 77b09121f9SPawel Jakub Dawidek char md_magic[16]; /* Magic value. */ 78b09121f9SPawel Jakub Dawidek uint32_t md_version; /* Version number. */ 79726cb09fSPawel Jakub Dawidek char md_name[16]; /* Stripe name. */ 80b09121f9SPawel Jakub Dawidek uint32_t md_id; /* Unique ID. */ 81b09121f9SPawel Jakub Dawidek uint16_t md_no; /* Disk number. */ 82b09121f9SPawel Jakub Dawidek uint16_t md_all; /* Number of all disks. */ 83b09121f9SPawel Jakub Dawidek uint32_t md_stripesize; /* Stripe size. */ 84b09121f9SPawel Jakub Dawidek }; 85b09121f9SPawel Jakub Dawidek static __inline void 86b09121f9SPawel Jakub Dawidek stripe_metadata_encode(const struct g_stripe_metadata *md, u_char *data) 87b09121f9SPawel Jakub Dawidek { 88b09121f9SPawel Jakub Dawidek 89b09121f9SPawel Jakub Dawidek bcopy(md->md_magic, data, sizeof(md->md_magic)); 90b09121f9SPawel Jakub Dawidek le32enc(data + 16, md->md_version); 91b09121f9SPawel Jakub Dawidek bcopy(md->md_name, data + 20, sizeof(md->md_name)); 92b09121f9SPawel Jakub Dawidek le32enc(data + 36, md->md_id); 93b09121f9SPawel Jakub Dawidek le16enc(data + 40, md->md_no); 94b09121f9SPawel Jakub Dawidek le16enc(data + 42, md->md_all); 95b09121f9SPawel Jakub Dawidek le32enc(data + 44, md->md_stripesize); 96b09121f9SPawel Jakub Dawidek } 97b09121f9SPawel Jakub Dawidek static __inline void 98b09121f9SPawel Jakub Dawidek stripe_metadata_decode(const u_char *data, struct g_stripe_metadata *md) 99b09121f9SPawel Jakub Dawidek { 100b09121f9SPawel Jakub Dawidek 101b09121f9SPawel Jakub Dawidek bcopy(data, md->md_magic, sizeof(md->md_magic)); 102b09121f9SPawel Jakub Dawidek md->md_version = le32dec(data + 16); 103b09121f9SPawel Jakub Dawidek bcopy(data + 20, md->md_name, sizeof(md->md_name)); 104b09121f9SPawel Jakub Dawidek md->md_id = le32dec(data + 36); 105b09121f9SPawel Jakub Dawidek md->md_no = le16dec(data + 40); 106b09121f9SPawel Jakub Dawidek md->md_all = le16dec(data + 42); 107b09121f9SPawel Jakub Dawidek md->md_stripesize = le32dec(data + 44); 108b09121f9SPawel Jakub Dawidek } 109b09121f9SPawel Jakub Dawidek 110b09121f9SPawel Jakub Dawidek #ifndef BITCOUNT 111b09121f9SPawel Jakub Dawidek #define BITCOUNT(x) (((BX_(x) + (BX_(x) >> 4)) & 0x0F0F0F0F) % 255) 112b09121f9SPawel Jakub Dawidek #define BX_(x) ((x) - (((x) >> 1) & 0x77777777) - \ 113b09121f9SPawel Jakub Dawidek (((x) >> 2) & 0x33333333) - (((x) >> 3) & 0x11111111)) 114b09121f9SPawel Jakub Dawidek #endif 115b09121f9SPawel Jakub Dawidek 116b09121f9SPawel Jakub Dawidek #endif /* _G_STRIPE_H_ */ 117