xref: /freebsd/sys/geom/virstor/g_virstor_md.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1f854db0bSPawel Jakub Dawidek /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
33728855aSPedro F. Giffuni  *
4f854db0bSPawel Jakub Dawidek  * Copyright (c) 2005 Ivan Voras <ivoras@gmail.com>
5f854db0bSPawel Jakub Dawidek  * All rights reserved.
6f854db0bSPawel Jakub Dawidek  *
7f854db0bSPawel Jakub Dawidek  * Redistribution and use in source and binary forms, with or without
8f854db0bSPawel Jakub Dawidek  * modification, are permitted provided that the following conditions
9f854db0bSPawel Jakub Dawidek  * are met:
10f854db0bSPawel Jakub Dawidek  * 1. Redistributions of source code must retain the above copyright
11f854db0bSPawel Jakub Dawidek  *    notice, this list of conditions and the following disclaimer.
12f854db0bSPawel Jakub Dawidek  * 2. Redistributions in binary form must reproduce the above copyright
13f854db0bSPawel Jakub Dawidek  *    notice, this list of conditions and the following disclaimer in the
14f854db0bSPawel Jakub Dawidek  *    documentation and/or other materials provided with the distribution.
15f854db0bSPawel Jakub Dawidek  *
16f854db0bSPawel Jakub Dawidek  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17f854db0bSPawel Jakub Dawidek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f854db0bSPawel Jakub Dawidek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f854db0bSPawel Jakub Dawidek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20f854db0bSPawel Jakub Dawidek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f854db0bSPawel Jakub Dawidek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f854db0bSPawel Jakub Dawidek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f854db0bSPawel Jakub Dawidek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f854db0bSPawel Jakub Dawidek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f854db0bSPawel Jakub Dawidek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f854db0bSPawel Jakub Dawidek  * SUCH DAMAGE.
27f854db0bSPawel Jakub Dawidek  */
28f854db0bSPawel Jakub Dawidek 
29f854db0bSPawel Jakub Dawidek #ifndef _G_VIRSTOR_MD_H_
30f854db0bSPawel Jakub Dawidek #define _G_VIRSTOR_MD_H_
31f854db0bSPawel Jakub Dawidek 
32f854db0bSPawel Jakub Dawidek /*
33f854db0bSPawel Jakub Dawidek  * Metadata declaration
34f854db0bSPawel Jakub Dawidek  */
35f854db0bSPawel Jakub Dawidek 
36f854db0bSPawel Jakub Dawidek #define	G_VIRSTOR_MAGIC		"GEOM::VIRSTOR"
37f854db0bSPawel Jakub Dawidek #define	G_VIRSTOR_VERSION	1
38f854db0bSPawel Jakub Dawidek 
39f854db0bSPawel Jakub Dawidek /* flag: provider is allocated */
40f854db0bSPawel Jakub Dawidek #define	VIRSTOR_PROVIDER_ALLOCATED	1
41f854db0bSPawel Jakub Dawidek /* flag: provider is currently being filled (usually it's the last
42f854db0bSPawel Jakub Dawidek  * provider with VIRSTOR_PROVIDER_ALLOCATED flag */
43f854db0bSPawel Jakub Dawidek #define VIRSTOR_PROVIDER_CURRENT	2
44f854db0bSPawel Jakub Dawidek 
45f854db0bSPawel Jakub Dawidek struct g_virstor_metadata {
46f854db0bSPawel Jakub Dawidek 	/* Data global to the virstor device */
47f854db0bSPawel Jakub Dawidek 	char		md_magic[16];		/* Magic value. */
48f854db0bSPawel Jakub Dawidek 	uint32_t	md_version;		/* Version number. */
49f854db0bSPawel Jakub Dawidek 	char		md_name[16];		/* Device name (e.g. "mydata") */
50f854db0bSPawel Jakub Dawidek 	uint32_t	md_id;			/* Unique ID. */
51f854db0bSPawel Jakub Dawidek 	uint64_t	md_virsize;		/* Virtual device's size */
52f854db0bSPawel Jakub Dawidek 	uint32_t	md_chunk_size;		/* Chunk size in bytes */
53f854db0bSPawel Jakub Dawidek 	uint16_t	md_count;		/* Total number of providers */
54f854db0bSPawel Jakub Dawidek 
55f854db0bSPawel Jakub Dawidek 	/* Data local to this provider */
56f854db0bSPawel Jakub Dawidek 	char		provider[16];		/* Hardcoded provider name */
57f854db0bSPawel Jakub Dawidek 	uint16_t	no;			/* Provider number/index */
58f854db0bSPawel Jakub Dawidek 	uint64_t	provsize;		/* Provider's size */
59f854db0bSPawel Jakub Dawidek 	uint32_t	chunk_count;		/* Number of chunks in this pr. */
60f854db0bSPawel Jakub Dawidek 	uint32_t	chunk_next;		/* Next chunk to allocate */
61f854db0bSPawel Jakub Dawidek 	uint16_t	chunk_reserved;		/* Count of "reserved" chunks */
62f854db0bSPawel Jakub Dawidek 	uint16_t	flags;			/* Provider's flags */
63f854db0bSPawel Jakub Dawidek };
64f854db0bSPawel Jakub Dawidek 
65f854db0bSPawel Jakub Dawidek void virstor_metadata_encode(struct g_virstor_metadata *md, unsigned char *data);
66f854db0bSPawel Jakub Dawidek void virstor_metadata_decode(unsigned char *data, struct g_virstor_metadata *md);
67f854db0bSPawel Jakub Dawidek 
68f854db0bSPawel Jakub Dawidek #endif	/* !_G_VIRSTOR_H_ */
69