xref: /freebsd/sys/geom/multipath/g_multipath.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1e770bc6bSMatt Jacob /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
33728855aSPedro F. Giffuni  *
4e770bc6bSMatt Jacob  * Copyright (c) 2006-2007 Matthew Jacob <mjacob@FreeBSD.org>
5e770bc6bSMatt Jacob  * All rights reserved.
6e770bc6bSMatt Jacob  *
7e770bc6bSMatt Jacob  * Redistribution and use in source and binary forms, with or without
8e770bc6bSMatt Jacob  * modification, are permitted provided that the following conditions
9e770bc6bSMatt Jacob  * are met:
10e770bc6bSMatt Jacob  * 1. Redistributions of source code must retain the above copyright
11e770bc6bSMatt Jacob  *    notice, this list of conditions and the following disclaimer.
12e770bc6bSMatt Jacob  * 2. Redistributions in binary form must reproduce the above copyright
13e770bc6bSMatt Jacob  *    notice, this list of conditions and the following disclaimer in the
14e770bc6bSMatt Jacob  *    documentation and/or other materials provided with the distribution.
15e770bc6bSMatt Jacob  *
16e770bc6bSMatt Jacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17e770bc6bSMatt Jacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18e770bc6bSMatt Jacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19e770bc6bSMatt Jacob  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20e770bc6bSMatt Jacob  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21e770bc6bSMatt Jacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22e770bc6bSMatt Jacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23e770bc6bSMatt Jacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24e770bc6bSMatt Jacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25e770bc6bSMatt Jacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e770bc6bSMatt Jacob  * SUCH DAMAGE.
27e770bc6bSMatt Jacob  */
28e770bc6bSMatt Jacob /*
29e770bc6bSMatt Jacob  * Based upon work by Pawel Jakub Dawidek <pjd@FreeBSD.org> for all of the
30e770bc6bSMatt Jacob  * fine geom examples, and by Poul Henning Kamp <phk@FreeBSD.org> for GEOM
31e770bc6bSMatt Jacob  * itself, all of which is most gratefully acknowledged.
32e770bc6bSMatt Jacob  */
33e770bc6bSMatt Jacob 
34e770bc6bSMatt Jacob #ifndef	_G_MULTIPATH_H_
35e770bc6bSMatt Jacob #define	_G_MULTIPATH_H_
36e770bc6bSMatt Jacob 
37e770bc6bSMatt Jacob #define	G_MULTIPATH_CLASS_NAME	"MULTIPATH"
38e770bc6bSMatt Jacob #define	G_MULTIPATH_VERSION	1
39e770bc6bSMatt Jacob #define	G_MULTIPATH_MAGIC	"GEOM::MULTIPATH"
40e770bc6bSMatt Jacob 
41e770bc6bSMatt Jacob #include <sys/endian.h>
42e770bc6bSMatt Jacob 
43e770bc6bSMatt Jacob #ifdef	_KERNEL
44e770bc6bSMatt Jacob 
45e770bc6bSMatt Jacob struct g_multipath_softc {
460c883cefSAlexander Motin 	struct g_provider *	sc_pp;
470c883cefSAlexander Motin 	struct g_consumer *	sc_active;
480c883cefSAlexander Motin 	struct mtx		sc_mtx;
49e770bc6bSMatt Jacob 	char			sc_name[16];
50e770bc6bSMatt Jacob 	char			sc_uuid[40];
51e6afd72bSAlexander Motin 	off_t			sc_size;
520c883cefSAlexander Motin 	int			sc_opened;
530c883cefSAlexander Motin 	int			sc_stopping;
540c883cefSAlexander Motin 	int			sc_ndisks;
550c883cefSAlexander Motin 	int			sc_active_active; /* Active/Active mode */
56e770bc6bSMatt Jacob };
57e770bc6bSMatt Jacob #endif	/* _KERNEL */
58e770bc6bSMatt Jacob 
59e770bc6bSMatt Jacob struct g_multipath_metadata {
60e770bc6bSMatt Jacob 	char		md_magic[16];	/* Magic Value */
61e770bc6bSMatt Jacob 	char 		md_uuid[40];	/* more magic */
62e770bc6bSMatt Jacob 	char		md_name[16];	/* a friendly name */
63e770bc6bSMatt Jacob 	uint32_t	md_version;	/* version */
64e770bc6bSMatt Jacob 	uint32_t	md_sectorsize;	/* sectorsize of provider */
65e770bc6bSMatt Jacob 	uint64_t	md_size;	/* absolute size of provider */
660c883cefSAlexander Motin 	uint8_t		md_active_active; /* Active/Active mode */
67e770bc6bSMatt Jacob };
68e770bc6bSMatt Jacob 
69e770bc6bSMatt Jacob static __inline void
70e770bc6bSMatt Jacob multipath_metadata_encode(const struct g_multipath_metadata *, u_char *);
71e770bc6bSMatt Jacob 
72e770bc6bSMatt Jacob static __inline void
73e770bc6bSMatt Jacob multipath_metadata_decode(u_char *, struct g_multipath_metadata *);
74e770bc6bSMatt Jacob 
75e770bc6bSMatt Jacob static __inline void
multipath_metadata_encode(const struct g_multipath_metadata * md,u_char * data)76e770bc6bSMatt Jacob multipath_metadata_encode(const struct g_multipath_metadata *md, u_char *data)
77e770bc6bSMatt Jacob {
78e770bc6bSMatt Jacob 	bcopy(md->md_magic, data, sizeof(md->md_magic));
79e770bc6bSMatt Jacob 	data += sizeof(md->md_magic);
80e770bc6bSMatt Jacob 	bcopy(md->md_uuid, data, sizeof(md->md_uuid));
81e770bc6bSMatt Jacob 	data += sizeof(md->md_uuid);
82e770bc6bSMatt Jacob 	bcopy(md->md_name, data, sizeof(md->md_name));
83e770bc6bSMatt Jacob 	data += sizeof(md->md_name);
84e770bc6bSMatt Jacob 	le32enc(data, md->md_version);
85e770bc6bSMatt Jacob 	data += sizeof(md->md_version);
86e770bc6bSMatt Jacob 	le32enc(data, md->md_sectorsize);
87e770bc6bSMatt Jacob 	data += sizeof(md->md_sectorsize);
88e770bc6bSMatt Jacob 	le64enc(data, md->md_size);
890c883cefSAlexander Motin 	data += sizeof(md->md_size);
900c883cefSAlexander Motin 	*data = md->md_active_active;
91e770bc6bSMatt Jacob }
92e770bc6bSMatt Jacob 
93e770bc6bSMatt Jacob static __inline void
multipath_metadata_decode(u_char * data,struct g_multipath_metadata * md)94e770bc6bSMatt Jacob multipath_metadata_decode(u_char *data, struct g_multipath_metadata *md)
95e770bc6bSMatt Jacob {
96e770bc6bSMatt Jacob 	bcopy(data, md->md_magic, sizeof(md->md_magic));
97e770bc6bSMatt Jacob 	data += sizeof(md->md_magic);
98e770bc6bSMatt Jacob 	bcopy(data, md->md_uuid, sizeof(md->md_uuid));
99e770bc6bSMatt Jacob 	data += sizeof(md->md_uuid);
100e770bc6bSMatt Jacob 	bcopy(data, md->md_name, sizeof(md->md_name));
101e770bc6bSMatt Jacob 	data += sizeof(md->md_name);
102e770bc6bSMatt Jacob 	md->md_version = le32dec(data);
103e770bc6bSMatt Jacob 	data += sizeof(md->md_version);
104e770bc6bSMatt Jacob 	md->md_sectorsize = le32dec(data);
105e770bc6bSMatt Jacob 	data += sizeof(md->md_sectorsize);
106e770bc6bSMatt Jacob 	md->md_size = le64dec(data);
1070c883cefSAlexander Motin 	data += sizeof(md->md_size);
1080c883cefSAlexander Motin 	md->md_active_active = *data;
109e770bc6bSMatt Jacob }
110e770bc6bSMatt Jacob #endif	/* _G_MULTIPATH_H_ */
111