xref: /freebsd/sys/geom/linux_lvm/g_linux_lvm.h (revision a0ee8cc6)
1 /*-
2  * Copyright (c) 2008 Andrew Thompson <thompsa@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 #define	G_LLVM_DEBUG(lvl, ...)	do {					\
30 	if (g_llvm_debug >= (lvl)) {					\
31 		printf("GEOM_LINUX_LVM");				\
32 		if (g_llvm_debug > 0)					\
33 			printf("[%u]", lvl);				\
34 		printf(": ");						\
35 		printf(__VA_ARGS__);					\
36 		printf("\n");						\
37 	}								\
38 } while (0)
39 
40 #define	G_LLVM_CLASS_NAME	"LINUX_LVM"
41 #define	G_LLVM_NAMELEN		128
42 #define	G_LLVM_UUIDLEN		40
43 #define	G_LLVM_MAGIC		"\040\114\126\115\062\040\170\133" \
44 				"\065\101\045\162\060\116\052\076"
45 
46 struct g_llvm_label {
47 	uint64_t	ll_sector;
48 	uint32_t	ll_crc;
49 	uint32_t	ll_offset;
50 	char		ll_uuid[G_LLVM_UUIDLEN];
51 	uint64_t	ll_size;
52 	uint64_t	ll_pestart;
53 	uint64_t	ll_md_offset;
54 	uint64_t	ll_md_size;
55 };
56 
57 struct g_llvm_metadata {
58 	uint32_t		md_csum;
59 	uint32_t		md_version;
60 	uint64_t		md_start;
61 	uint64_t		md_size;
62 	uint64_t		md_reloffset;
63 	uint64_t		md_relsize;
64 	struct g_llvm_vg	*md_vg;
65 };
66 
67 struct g_llvm_lv {
68 	LIST_ENTRY(g_llvm_lv)	lv_next;
69 	struct g_llvm_vg	*lv_vg;
70 	char			lv_name[G_LLVM_NAMELEN];
71 	char			lv_uuid[G_LLVM_UUIDLEN];
72 	int			lv_sgcount;
73 	int			lv_sgactive;
74 	struct g_provider	*lv_gprov;
75 	int			lv_extentcount;
76 	LIST_HEAD(, g_llvm_segment) lv_segs;
77 	int			lv_numsegs;
78 	struct g_llvm_segment	*lv_firstsg;
79 };
80 
81 struct g_llvm_pv {
82 	LIST_ENTRY(g_llvm_pv)	pv_next;
83 	struct g_llvm_vg	*pv_vg;
84 	char			pv_name[G_LLVM_NAMELEN];
85 	char			pv_uuid[G_LLVM_UUIDLEN];
86 	size_t			pv_size;
87 	off_t			pv_start;
88 	int			pv_count;
89 	struct g_provider	*pv_gprov;
90 	struct g_consumer	*pv_gcons;
91 };
92 
93 struct g_llvm_segment {
94 	LIST_ENTRY(g_llvm_segment)	sg_next;
95 	int			sg_start;
96 	int			sg_end;
97 	int			sg_count;
98 	char			sg_pvname[G_LLVM_NAMELEN];
99 	struct g_llvm_pv	*sg_pv;
100 	int			sg_pvstart;
101 	off_t			sg_pvoffset;
102 };
103 
104 struct g_llvm_vg {
105 	LIST_ENTRY(g_llvm_vg)	vg_next;
106 	char			vg_name[G_LLVM_NAMELEN];
107 	char			vg_uuid[G_LLVM_UUIDLEN];
108 	size_t			vg_extentsize;
109 	int			vg_sectorsize;
110 	struct g_geom		*vg_geom;
111 	LIST_HEAD(, g_llvm_pv)	vg_pvs;
112 	LIST_HEAD(, g_llvm_lv)	vg_lvs;
113 };
114