1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2004, 2007 Lukas Ertl
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30
31#ifndef	_GEOM_VINUM_H_
32#define	_GEOM_VINUM_H_
33
34/* geom_vinum_create.c */
35void	gv_concat(struct g_geom *gp, struct gctl_req *);
36void	gv_mirror(struct g_geom *gp, struct gctl_req *);
37void	gv_stripe(struct g_geom *gp, struct gctl_req *);
38void	gv_raid5(struct g_geom *gp, struct gctl_req *);
39int	gv_create_drive(struct gv_softc *, struct gv_drive *);
40int	gv_create_volume(struct gv_softc *, struct gv_volume *);
41int	gv_create_plex(struct gv_softc *, struct gv_plex *);
42int	gv_create_sd(struct gv_softc *, struct gv_sd *);
43
44/* geom_vinum_drive.c */
45void	gv_save_config(struct gv_softc *);
46int	gv_read_header(struct g_consumer *, struct gv_hdr *);
47int	gv_write_header(struct g_consumer *, struct gv_hdr *);
48
49/* geom_vinum_init.c */
50void	gv_start_obj(struct g_geom *, struct gctl_req *);
51int	gv_start_plex(struct gv_plex *);
52int	gv_start_vol(struct gv_volume *);
53
54/* geom_vinum_list.c */
55void	gv_ld(struct g_geom *, struct gctl_req *, struct sbuf *);
56void	gv_lp(struct g_geom *, struct gctl_req *, struct sbuf *);
57void	gv_ls(struct g_geom *, struct gctl_req *, struct sbuf *);
58void	gv_lv(struct g_geom *, struct gctl_req *, struct sbuf *);
59void	gv_list(struct g_geom *, struct gctl_req *);
60
61/* geom_vinum_move.c */
62void	gv_move(struct g_geom *, struct gctl_req *);
63int	gv_move_sd(struct gv_softc *, struct gv_sd *, struct gv_drive *, int);
64
65/* geom_vinum_rename.c */
66void	gv_rename(struct g_geom *, struct gctl_req *);
67int	gv_rename_drive(struct gv_softc *, struct gv_drive *, char *, int);
68int	gv_rename_plex(struct gv_softc *, struct gv_plex *, char *, int);
69int	gv_rename_sd(struct gv_softc *, struct gv_sd *, char *, int);
70int	gv_rename_vol(struct gv_softc *, struct gv_volume *, char *, int);
71
72/* geom_vinum_rm.c */
73void	gv_remove(struct g_geom *, struct gctl_req *);
74int	gv_resetconfig(struct gv_softc *);
75void	gv_rm_sd(struct gv_softc *sc, struct gv_sd *s);
76void	gv_rm_drive(struct gv_softc *, struct gv_drive *, int);
77void	gv_rm_plex(struct gv_softc *, struct gv_plex *);
78void	gv_rm_vol(struct gv_softc *, struct gv_volume *);
79
80
81/* geom_vinum_state.c */
82int	gv_sdstatemap(struct gv_plex *);
83void	gv_setstate(struct g_geom *, struct gctl_req *);
84int	gv_set_drive_state(struct gv_drive *, int, int);
85int	gv_set_sd_state(struct gv_sd *, int, int);
86int	gv_set_vol_state(struct gv_volume *, int, int);
87int	gv_set_plex_state(struct gv_plex *, int, int);
88void	gv_update_sd_state(struct gv_sd *);
89void	gv_update_plex_state(struct gv_plex *);
90void	gv_update_vol_state(struct gv_volume *);
91
92/* geom_vinum_subr.c */
93void		 	 gv_adjust_freespace(struct gv_sd *, off_t);
94void		 	 gv_free_sd(struct gv_sd *);
95struct gv_drive		*gv_find_drive(struct gv_softc *, char *);
96struct gv_drive		*gv_find_drive_device(struct gv_softc *, char *);
97struct gv_plex		*gv_find_plex(struct gv_softc *, char *);
98struct gv_sd		*gv_find_sd(struct gv_softc *, char *);
99struct gv_volume	*gv_find_vol(struct gv_softc *, char *);
100void			 gv_format_config(struct gv_softc *, struct sbuf *, int,
101			     char *);
102int			 gv_is_striped(struct gv_plex *);
103int			 gv_consumer_is_open(struct g_consumer *);
104int			 gv_provider_is_open(struct g_provider *);
105int			 gv_object_type(struct gv_softc *, char *);
106void			 gv_parse_config(struct gv_softc *, char *,
107			     struct gv_drive *);
108int			 gv_sd_to_drive(struct gv_sd *, struct gv_drive *);
109int			 gv_sd_to_plex(struct gv_sd *, struct gv_plex *);
110int			 gv_sdcount(struct gv_plex *, int);
111void			 gv_update_plex_config(struct gv_plex *);
112void			 gv_update_vol_size(struct gv_volume *, off_t);
113off_t			 gv_vol_size(struct gv_volume *);
114off_t			 gv_plex_size(struct gv_plex *);
115int			 gv_plexdown(struct gv_volume *);
116int			 gv_attach_plex(struct gv_plex *, struct gv_volume *,
117			     int);
118int			 gv_attach_sd(struct gv_sd *, struct gv_plex *, off_t,
119			     int);
120int			 gv_detach_plex(struct gv_plex *, int);
121int			 gv_detach_sd(struct gv_sd *, int);
122
123/* geom_vinum.c */
124void	gv_worker(void *);
125void	gv_post_event(struct gv_softc *, int, void *, void *, intmax_t,
126	    intmax_t);
127void	gv_worker_exit(struct gv_softc *);
128struct gv_event *gv_get_event(struct gv_softc *);
129void	gv_remove_event(struct gv_softc *, struct gv_event *);
130void	gv_drive_done(struct gv_drive *);
131void	gv_drive_tasted(struct gv_softc *, struct g_provider *);
132void	gv_drive_lost(struct gv_softc *, struct gv_drive *);
133void	gv_setup_objects(struct gv_softc *);
134void	gv_start(struct bio *);
135int	gv_access(struct g_provider *, int, int, int);
136void	gv_cleanup(struct gv_softc *);
137
138/* geom_vinum_volume.c */
139void	gv_done(struct bio *);
140void	gv_volume_start(struct gv_softc *, struct bio *);
141void	gv_volume_flush(struct gv_volume *);
142void	gv_bio_done(struct gv_softc *, struct bio *);
143
144/* geom_vinum_plex.c */
145void	gv_plex_start(struct gv_plex *, struct bio *);
146void	gv_plex_raid5_done(struct gv_plex *, struct bio *);
147void	gv_plex_normal_done(struct gv_plex *, struct bio *);
148int	gv_grow_request(struct gv_plex *, off_t, off_t, int, caddr_t);
149void	gv_grow_complete(struct gv_plex *, struct bio *);
150void	gv_init_request(struct gv_sd *, off_t, caddr_t, off_t);
151void	gv_init_complete(struct gv_plex *, struct bio *);
152void	gv_parity_request(struct gv_plex *, int, off_t);
153void	gv_parity_complete(struct gv_plex *, struct bio *);
154void	gv_rebuild_complete(struct gv_plex *, struct bio *);
155int	gv_sync_request(struct gv_plex *, struct gv_plex *, off_t, off_t, int,
156	    caddr_t);
157int	gv_sync_complete(struct gv_plex *, struct bio *);
158
159extern	u_int	g_vinum_debug;
160
161#define	G_VINUM_DEBUG(lvl, ...)	do {					\
162	if (g_vinum_debug >= (lvl)) {					\
163		printf("GEOM_VINUM");					\
164		if (g_vinum_debug > 0)					\
165			printf("[%u]", lvl);				\
166		printf(": ");						\
167		printf(__VA_ARGS__);					\
168		printf("\n");						\
169	}								\
170} while (0)
171
172#define	G_VINUM_LOGREQ(lvl, bp, ...)	do {				\
173	if (g_vinum_debug >= (lvl)) {					\
174		printf("GEOM_VINUM");					\
175		if (g_vinum_debug > 0)					\
176			printf("[%u]", lvl);				\
177		printf(": ");						\
178		printf(__VA_ARGS__);					\
179		printf(" ");						\
180		g_print_bio(bp);					\
181		printf("\n");						\
182	}								\
183} while (0)
184
185#endif /* !_GEOM_VINUM_H_ */
186