1167050Smjacob/*-
2167050Smjacob * Copyright (c) 2006-2007 Matthew Jacob <mjacob@FreeBSD.org>
3167050Smjacob * All rights reserved.
4167050Smjacob *
5167050Smjacob * Redistribution and use in source and binary forms, with or without
6167050Smjacob * modification, are permitted provided that the following conditions
7167050Smjacob * are met:
8167050Smjacob * 1. Redistributions of source code must retain the above copyright
9167050Smjacob *    notice, this list of conditions and the following disclaimer.
10167050Smjacob * 2. Redistributions in binary form must reproduce the above copyright
11167050Smjacob *    notice, this list of conditions and the following disclaimer in the
12167050Smjacob *    documentation and/or other materials provided with the distribution.
13167050Smjacob *
14167050Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15167050Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16167050Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17167050Smjacob * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18167050Smjacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19167050Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20167050Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21167050Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22167050Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23167050Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24167050Smjacob * SUCH DAMAGE.
25167050Smjacob *
26167050Smjacob * $FreeBSD: releng/10.3/sys/geom/multipath/g_multipath.h 260478 2014-01-09 11:11:47Z mav $
27167050Smjacob */
28167050Smjacob/*
29167050Smjacob * Based upon work by Pawel Jakub Dawidek <pjd@FreeBSD.org> for all of the
30167050Smjacob * fine geom examples, and by Poul Henning Kamp <phk@FreeBSD.org> for GEOM
31167050Smjacob * itself, all of which is most gratefully acknowledged.
32167050Smjacob */
33167050Smjacob
34167050Smjacob#ifndef	_G_MULTIPATH_H_
35167050Smjacob#define	_G_MULTIPATH_H_
36167050Smjacob
37167050Smjacob#define	G_MULTIPATH_CLASS_NAME	"MULTIPATH"
38167050Smjacob#define	G_MULTIPATH_VERSION	1
39167050Smjacob#define	G_MULTIPATH_MAGIC	"GEOM::MULTIPATH"
40167050Smjacob
41167050Smjacob#include <sys/endian.h>
42167050Smjacob
43167050Smjacob#ifdef	_KERNEL
44167050Smjacob
45167050Smjacobstruct g_multipath_softc {
46227464Smav	struct g_provider *	sc_pp;
47227464Smav	struct g_consumer *	sc_active;
48227464Smav	struct mtx		sc_mtx;
49167050Smjacob	char			sc_name[16];
50167050Smjacob	char			sc_uuid[40];
51260478Smav	off_t			sc_size;
52227464Smav	int			sc_opened;
53227464Smav	int			sc_stopping;
54227464Smav	int			sc_ndisks;
55227464Smav	int			sc_active_active; /* Active/Active mode */
56167050Smjacob};
57167050Smjacob#endif	/* _KERNEL */
58167050Smjacob
59167050Smjacobstruct g_multipath_metadata {
60167050Smjacob	char		md_magic[16];	/* Magic Value */
61167050Smjacob	char 		md_uuid[40];	/* more magic */
62167050Smjacob	char		md_name[16];	/* a friendly name */
63167050Smjacob	uint32_t	md_version;	/* version */
64167050Smjacob	uint32_t	md_sectorsize;	/* sectorsize of provider */
65167050Smjacob	uint64_t	md_size;	/* absolute size of provider */
66227464Smav	uint8_t		md_active_active; /* Active/Active mode */
67167050Smjacob};
68167050Smjacob
69167050Smjacobstatic __inline void
70167050Smjacobmultipath_metadata_encode(const struct g_multipath_metadata *, u_char *);
71167050Smjacob
72167050Smjacobstatic __inline void
73167050Smjacobmultipath_metadata_decode(u_char *, struct g_multipath_metadata *);
74167050Smjacob
75167050Smjacobstatic __inline void
76167050Smjacobmultipath_metadata_encode(const struct g_multipath_metadata *md, u_char *data)
77167050Smjacob{
78167050Smjacob	bcopy(md->md_magic, data, sizeof(md->md_magic));
79167050Smjacob	data += sizeof(md->md_magic);
80167050Smjacob	bcopy(md->md_uuid, data, sizeof(md->md_uuid));
81167050Smjacob	data += sizeof(md->md_uuid);
82167050Smjacob	bcopy(md->md_name, data, sizeof(md->md_name));
83167050Smjacob	data += sizeof(md->md_name);
84167050Smjacob	le32enc(data, md->md_version);
85167050Smjacob	data += sizeof(md->md_version);
86167050Smjacob	le32enc(data, md->md_sectorsize);
87167050Smjacob	data += sizeof(md->md_sectorsize);
88167050Smjacob	le64enc(data, md->md_size);
89227464Smav	data += sizeof(md->md_size);
90227464Smav	*data = md->md_active_active;
91167050Smjacob}
92167050Smjacob
93167050Smjacobstatic __inline void
94167050Smjacobmultipath_metadata_decode(u_char *data, struct g_multipath_metadata *md)
95167050Smjacob{
96167050Smjacob	bcopy(data, md->md_magic, sizeof(md->md_magic));
97167050Smjacob	data += sizeof(md->md_magic);
98167050Smjacob	bcopy(data, md->md_uuid, sizeof(md->md_uuid));
99167050Smjacob	data += sizeof(md->md_uuid);
100167050Smjacob	bcopy(data, md->md_name, sizeof(md->md_name));
101167050Smjacob	data += sizeof(md->md_name);
102167050Smjacob	md->md_version = le32dec(data);
103167050Smjacob	data += sizeof(md->md_version);
104167050Smjacob	md->md_sectorsize = le32dec(data);
105167050Smjacob	data += sizeof(md->md_sectorsize);
106167050Smjacob	md->md_size = le64dec(data);
107227464Smav	data += sizeof(md->md_size);
108227464Smav	md->md_active_active = *data;
109167050Smjacob}
110167050Smjacob#endif	/* _G_MULTIPATH_H_ */
111