186dae1fpjd/*-
2a82e3a8pfg * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3a82e3a8pfg *
4668a028pjd * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
586dae1fpjd * All rights reserved.
686dae1fpjd *
786dae1fpjd * Redistribution and use in source and binary forms, with or without
886dae1fpjd * modification, are permitted provided that the following conditions
986dae1fpjd * are met:
1086dae1fpjd * 1. Redistributions of source code must retain the above copyright
1186dae1fpjd *    notice, this list of conditions and the following disclaimer.
1286dae1fpjd * 2. Redistributions in binary form must reproduce the above copyright
1386dae1fpjd *    notice, this list of conditions and the following disclaimer in the
1486dae1fpjd *    documentation and/or other materials provided with the distribution.
156f074b6pjd *
1686dae1fpjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
1786dae1fpjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1886dae1fpjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1986dae1fpjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
2086dae1fpjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2186dae1fpjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2286dae1fpjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2386dae1fpjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2486dae1fpjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2586dae1fpjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2686dae1fpjd * SUCH DAMAGE.
2786dae1fpjd *
2886dae1fpjd * $FreeBSD$
2986dae1fpjd */
3086dae1fpjd
3186dae1fpjd#ifndef	_G_STRIPE_H_
3286dae1fpjd#define	_G_STRIPE_H_
3386dae1fpjd
3486dae1fpjd#include <sys/endian.h>
3586dae1fpjd
3686dae1fpjd#define	G_STRIPE_CLASS_NAME	"STRIPE"
3786dae1fpjd
3886dae1fpjd#define	G_STRIPE_MAGIC		"GEOM::STRIPE"
39a98f255pjd/*
40a98f255pjd * Version history:
41a98f255pjd * 0 - Initial version number.
42a98f255pjd * 1 - Added 'stop' command for gstripe(8).
43a98f255pjd * 2 - Added md_provider field to metadata and '-h' option for gstripe(8).
44668a028pjd * 3 - Added md_provsize field to metadata.
45a98f255pjd */
46668a028pjd#define	G_STRIPE_VERSION	3
4786dae1fpjd
4886dae1fpjd#ifdef _KERNEL
4986dae1fpjd#define	G_STRIPE_TYPE_MANUAL	0
5086dae1fpjd#define	G_STRIPE_TYPE_AUTOMATIC	1
5186dae1fpjd
5210d53fccem#define	G_STRIPE_DEBUG(lvl, ...) \
5310d53fccem    _GEOM_DEBUG("GEOM_STRIPE", g_stripe_debug, (lvl), NULL, __VA_ARGS__)
5410d53fccem#define	G_STRIPE_LOGREQ(bp, ...) \
5510d53fccem    _GEOM_DEBUG("GEOM_STRIPE", g_stripe_debug, 2, (bp), __VA_ARGS__)
5686dae1fpjd
5786dae1fpjdstruct g_stripe_softc {
5886dae1fpjd	u_int		 sc_type;	/* provider type */
5986dae1fpjd	struct g_geom	*sc_geom;
6086dae1fpjd	struct g_provider *sc_provider;
6186dae1fpjd	uint32_t	 sc_id;		/* stripe unique ID */
6286dae1fpjd	struct g_consumer **sc_disks;
6386dae1fpjd	uint16_t	 sc_ndisks;
64f8a3770eugen	off_t		 sc_stripesize;
6586dae1fpjd	uint32_t	 sc_stripebits;
664219fc0mav	struct mtx	 sc_lock;
6786dae1fpjd};
683a2f13dpjd#define	sc_name	sc_geom->name
6986dae1fpjd#endif	/* _KERNEL */
7086dae1fpjd
7186dae1fpjdstruct g_stripe_metadata {
7286dae1fpjd	char		md_magic[16];	/* Magic value. */
7386dae1fpjd	uint32_t	md_version;	/* Version number. */
746639216pjd	char		md_name[16];	/* Stripe name. */
7586dae1fpjd	uint32_t	md_id;		/* Unique ID. */
7686dae1fpjd	uint16_t	md_no;		/* Disk number. */
7786dae1fpjd	uint16_t	md_all;		/* Number of all disks. */
7886dae1fpjd	uint32_t	md_stripesize;	/* Stripe size. */
79a98f255pjd	char		md_provider[16]; /* Hardcoded provider. */
80668a028pjd	uint64_t	md_provsize;	/* Provider's size. */
8186dae1fpjd};
8286dae1fpjdstatic __inline void
8386dae1fpjdstripe_metadata_encode(const struct g_stripe_metadata *md, u_char *data)
8486dae1fpjd{
8586dae1fpjd
8686dae1fpjd	bcopy(md->md_magic, data, sizeof(md->md_magic));
8786dae1fpjd	le32enc(data + 16, md->md_version);
8886dae1fpjd	bcopy(md->md_name, data + 20, sizeof(md->md_name));
8986dae1fpjd	le32enc(data + 36, md->md_id);
9086dae1fpjd	le16enc(data + 40, md->md_no);
9186dae1fpjd	le16enc(data + 42, md->md_all);
9286dae1fpjd	le32enc(data + 44, md->md_stripesize);
93a98f255pjd	bcopy(md->md_provider, data + 48, sizeof(md->md_provider));
94668a028pjd	le64enc(data + 64, md->md_provsize);
9586dae1fpjd}
9686dae1fpjdstatic __inline void
9786dae1fpjdstripe_metadata_decode(const u_char *data, struct g_stripe_metadata *md)
9886dae1fpjd{
9986dae1fpjd
10086dae1fpjd	bcopy(data, md->md_magic, sizeof(md->md_magic));
10186dae1fpjd	md->md_version = le32dec(data + 16);
10286dae1fpjd	bcopy(data + 20, md->md_name, sizeof(md->md_name));
10386dae1fpjd	md->md_id = le32dec(data + 36);
10486dae1fpjd	md->md_no = le16dec(data + 40);
10586dae1fpjd	md->md_all = le16dec(data + 42);
10686dae1fpjd	md->md_stripesize = le32dec(data + 44);
107a98f255pjd	bcopy(data + 48, md->md_provider, sizeof(md->md_provider));
108668a028pjd	md->md_provsize = le64dec(data + 64);
10986dae1fpjd}
11086dae1fpjd
11186dae1fpjd#endif	/* _G_STRIPE_H_ */
112