1b09121f9SPawel Jakub Dawidek /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 33728855aSPedro F. Giffuni * 4e6890985SPawel Jakub Dawidek * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 5b09121f9SPawel Jakub Dawidek * All rights reserved. 6b09121f9SPawel Jakub Dawidek * 7b09121f9SPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without 8b09121f9SPawel Jakub Dawidek * modification, are permitted provided that the following conditions 9b09121f9SPawel Jakub Dawidek * are met: 10b09121f9SPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright 11b09121f9SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer. 12b09121f9SPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright 13b09121f9SPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the 14b09121f9SPawel Jakub Dawidek * documentation and/or other materials provided with the distribution. 15b09121f9SPawel Jakub Dawidek * 16b09121f9SPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17b09121f9SPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18b09121f9SPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19b09121f9SPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20b09121f9SPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21b09121f9SPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22b09121f9SPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23b09121f9SPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24b09121f9SPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25b09121f9SPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26b09121f9SPawel Jakub Dawidek * SUCH DAMAGE. 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" 376c74f517SPawel Jakub Dawidek /* 386c74f517SPawel Jakub Dawidek * Version history: 396c74f517SPawel Jakub Dawidek * 0 - Initial version number. 406c74f517SPawel Jakub Dawidek * 1 - Added 'stop' command for gstripe(8). 416c74f517SPawel Jakub Dawidek * 2 - Added md_provider field to metadata and '-h' option for gstripe(8). 42e6890985SPawel Jakub Dawidek * 3 - Added md_provsize field to metadata. 436c74f517SPawel Jakub Dawidek */ 44e6890985SPawel Jakub Dawidek #define G_STRIPE_VERSION 3 45b09121f9SPawel Jakub Dawidek 46b09121f9SPawel Jakub Dawidek #ifdef _KERNEL 47b09121f9SPawel Jakub Dawidek #define G_STRIPE_TYPE_MANUAL 0 48b09121f9SPawel Jakub Dawidek #define G_STRIPE_TYPE_AUTOMATIC 1 49b09121f9SPawel Jakub Dawidek 50*ea2d874cSMatthew Grooms #define G_STRIPE_FLAG_CANDELETE 0x00000001UL 51*ea2d874cSMatthew Grooms 52ac03832eSConrad Meyer #define G_STRIPE_DEBUG(lvl, ...) \ 53ac03832eSConrad Meyer _GEOM_DEBUG("GEOM_STRIPE", g_stripe_debug, (lvl), NULL, __VA_ARGS__) 54ac03832eSConrad Meyer #define G_STRIPE_LOGREQ(bp, ...) \ 55ac03832eSConrad Meyer _GEOM_DEBUG("GEOM_STRIPE", g_stripe_debug, 2, (bp), __VA_ARGS__) 56b09121f9SPawel Jakub Dawidek 57b09121f9SPawel Jakub Dawidek struct g_stripe_softc { 58b09121f9SPawel Jakub Dawidek u_int sc_type; /* provider type */ 59b09121f9SPawel Jakub Dawidek struct g_geom *sc_geom; 60b09121f9SPawel Jakub Dawidek struct g_provider *sc_provider; 61b09121f9SPawel Jakub Dawidek uint32_t sc_id; /* stripe unique ID */ 62b09121f9SPawel Jakub Dawidek struct g_consumer **sc_disks; 63b09121f9SPawel Jakub Dawidek uint16_t sc_ndisks; 646d305ab0SEugene Grosbein off_t sc_stripesize; 65b09121f9SPawel Jakub Dawidek uint32_t sc_stripebits; 6640ea77a0SAlexander Motin struct mtx sc_lock; 67*ea2d874cSMatthew Grooms int sc_flags; 68b09121f9SPawel Jakub Dawidek }; 69889c5dc2SPawel Jakub Dawidek #define sc_name sc_geom->name 70b09121f9SPawel Jakub Dawidek #endif /* _KERNEL */ 71b09121f9SPawel Jakub Dawidek 72b09121f9SPawel Jakub Dawidek struct g_stripe_metadata { 73b09121f9SPawel Jakub Dawidek char md_magic[16]; /* Magic value. */ 74b09121f9SPawel Jakub Dawidek uint32_t md_version; /* Version number. */ 75726cb09fSPawel Jakub Dawidek char md_name[16]; /* Stripe name. */ 76b09121f9SPawel Jakub Dawidek uint32_t md_id; /* Unique ID. */ 77b09121f9SPawel Jakub Dawidek uint16_t md_no; /* Disk number. */ 78b09121f9SPawel Jakub Dawidek uint16_t md_all; /* Number of all disks. */ 79b09121f9SPawel Jakub Dawidek uint32_t md_stripesize; /* Stripe size. */ 806c74f517SPawel Jakub Dawidek char md_provider[16]; /* Hardcoded provider. */ 81e6890985SPawel Jakub Dawidek uint64_t md_provsize; /* Provider's size. */ 82b09121f9SPawel Jakub Dawidek }; 83b09121f9SPawel Jakub Dawidek static __inline void 84b09121f9SPawel Jakub Dawidek stripe_metadata_encode(const struct g_stripe_metadata *md, u_char *data) 85b09121f9SPawel Jakub Dawidek { 86b09121f9SPawel Jakub Dawidek 87b09121f9SPawel Jakub Dawidek bcopy(md->md_magic, data, sizeof(md->md_magic)); 88b09121f9SPawel Jakub Dawidek le32enc(data + 16, md->md_version); 89b09121f9SPawel Jakub Dawidek bcopy(md->md_name, data + 20, sizeof(md->md_name)); 90b09121f9SPawel Jakub Dawidek le32enc(data + 36, md->md_id); 91b09121f9SPawel Jakub Dawidek le16enc(data + 40, md->md_no); 92b09121f9SPawel Jakub Dawidek le16enc(data + 42, md->md_all); 93b09121f9SPawel Jakub Dawidek le32enc(data + 44, md->md_stripesize); 946c74f517SPawel Jakub Dawidek bcopy(md->md_provider, data + 48, sizeof(md->md_provider)); 95e6890985SPawel Jakub Dawidek le64enc(data + 64, md->md_provsize); 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); 1086c74f517SPawel Jakub Dawidek bcopy(data + 48, md->md_provider, sizeof(md->md_provider)); 109e6890985SPawel Jakub Dawidek md->md_provsize = le64dec(data + 64); 110b09121f9SPawel Jakub Dawidek } 111b09121f9SPawel Jakub Dawidek 112b09121f9SPawel Jakub Dawidek #endif /* _G_STRIPE_H_ */ 113