xref: /freebsd-src/sys/geom/raid/g_raid.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
189b17223SAlexander Motin /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
33728855aSPedro F. Giffuni  *
489b17223SAlexander Motin  * Copyright (c) 2010 Alexander Motin <mav@FreeBSD.org>
589b17223SAlexander Motin  * All rights reserved.
689b17223SAlexander Motin  *
789b17223SAlexander Motin  * Redistribution and use in source and binary forms, with or without
889b17223SAlexander Motin  * modification, are permitted provided that the following conditions
989b17223SAlexander Motin  * are met:
1089b17223SAlexander Motin  * 1. Redistributions of source code must retain the above copyright
1189b17223SAlexander Motin  *    notice, this list of conditions and the following disclaimer.
1289b17223SAlexander Motin  * 2. Redistributions in binary form must reproduce the above copyright
1389b17223SAlexander Motin  *    notice, this list of conditions and the following disclaimer in the
1489b17223SAlexander Motin  *    documentation and/or other materials provided with the distribution.
1589b17223SAlexander Motin  *
1689b17223SAlexander Motin  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
1789b17223SAlexander Motin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1889b17223SAlexander Motin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1989b17223SAlexander Motin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
2089b17223SAlexander Motin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2189b17223SAlexander Motin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2289b17223SAlexander Motin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2389b17223SAlexander Motin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2489b17223SAlexander Motin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2589b17223SAlexander Motin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2689b17223SAlexander Motin  * SUCH DAMAGE.
2789b17223SAlexander Motin  */
2889b17223SAlexander Motin 
2989b17223SAlexander Motin #ifndef	_G_RAID_H_
3089b17223SAlexander Motin #define	_G_RAID_H_
3189b17223SAlexander Motin 
3289b17223SAlexander Motin #include <sys/param.h>
3389b17223SAlexander Motin #include <sys/kobj.h>
3489b17223SAlexander Motin #include <sys/bio.h>
3589b17223SAlexander Motin #include <sys/time.h>
36c89d2fbeSAlexander Motin #ifdef _KERNEL
37c89d2fbeSAlexander Motin #include <sys/sysctl.h>
38c89d2fbeSAlexander Motin #endif
3989b17223SAlexander Motin 
4089b17223SAlexander Motin #define	G_RAID_CLASS_NAME	"RAID"
4189b17223SAlexander Motin 
4289b17223SAlexander Motin #define	G_RAID_MAGIC		"GEOM::RAID"
4389b17223SAlexander Motin 
4489b17223SAlexander Motin #define	G_RAID_VERSION		0
4589b17223SAlexander Motin 
4689b17223SAlexander Motin struct g_raid_md_object;
4789b17223SAlexander Motin struct g_raid_tr_object;
4889b17223SAlexander Motin 
4989b17223SAlexander Motin #define	G_RAID_DEVICE_FLAG_NOAUTOSYNC	0x0000000000000001ULL
5089b17223SAlexander Motin #define	G_RAID_DEVICE_FLAG_NOFAILSYNC	0x0000000000000002ULL
5189b17223SAlexander Motin #define	G_RAID_DEVICE_FLAG_MASK	(G_RAID_DEVICE_FLAG_NOAUTOSYNC | \
5289b17223SAlexander Motin 					 G_RAID_DEVICE_FLAG_NOFAILSYNC)
5389b17223SAlexander Motin 
5489b17223SAlexander Motin #ifdef _KERNEL
5589b17223SAlexander Motin extern u_int g_raid_aggressive_spare;
5689b17223SAlexander Motin extern u_int g_raid_debug;
57c89d2fbeSAlexander Motin extern int g_raid_enable;
5889b17223SAlexander Motin extern int g_raid_read_err_thresh;
5989b17223SAlexander Motin extern u_int g_raid_start_timeout;
6089b17223SAlexander Motin extern struct g_class g_raid_class;
6189b17223SAlexander Motin 
62ac03832eSConrad Meyer #define	G_RAID_DEBUG(lvl, ...) \
63ac03832eSConrad Meyer     _GEOM_DEBUG("GEOM_RAID", g_raid_debug, (lvl), NULL, __VA_ARGS__)
64ac03832eSConrad Meyer #define	G_RAID_DEBUG1(lvl, sc, fmt, ...)				\
65ac03832eSConrad Meyer     _GEOM_DEBUG("GEOM_RAID", g_raid_debug, (lvl), NULL, "%s: " fmt,	\
66ac03832eSConrad Meyer 	(sc)->sc_name, ## __VA_ARGS__)
67ac03832eSConrad Meyer #define	G_RAID_LOGREQ(lvl, bp, ...) \
68ac03832eSConrad Meyer     _GEOM_DEBUG("GEOM_RAID", g_raid_debug, (lvl), (bp), __VA_ARGS__)
6989b17223SAlexander Motin 
7089b17223SAlexander Motin /*
7189b17223SAlexander Motin  * Flags we use to distinguish I/O initiated by the TR layer to maintain
7289b17223SAlexander Motin  * the volume's characteristics, fix subdisks, extra copies of data, etc.
7389b17223SAlexander Motin  *
7489b17223SAlexander Motin  * G_RAID_BIO_FLAG_SYNC		I/O to update an extra copy of the data
7589b17223SAlexander Motin  *				for RAID volumes that maintain extra data
7689b17223SAlexander Motin  *				and need to rebuild that data.
7789b17223SAlexander Motin  * G_RAID_BIO_FLAG_REMAP	I/O done to try to provoke a subdisk into
7889b17223SAlexander Motin  *				doing some desirable action such as bad
7989b17223SAlexander Motin  *				block remapping after we detect a bad part
8089b17223SAlexander Motin  *				of the disk.
8189b17223SAlexander Motin  * G_RAID_BIO_FLAG_LOCKED	I/O holds range lock that should re released.
8289b17223SAlexander Motin  *
8389b17223SAlexander Motin  * and the following meta item:
8489b17223SAlexander Motin  * G_RAID_BIO_FLAG_SPECIAL	And of the I/O flags that need to make it
8589b17223SAlexander Motin  *				through the range locking which would
8689b17223SAlexander Motin  *				otherwise defer the I/O until after that
8789b17223SAlexander Motin  *				range is unlocked.
8889b17223SAlexander Motin  */
8989b17223SAlexander Motin #define	G_RAID_BIO_FLAG_SYNC		0x01
9089b17223SAlexander Motin #define	G_RAID_BIO_FLAG_REMAP		0x02
9189b17223SAlexander Motin #define	G_RAID_BIO_FLAG_SPECIAL \
9289b17223SAlexander Motin 		(G_RAID_BIO_FLAG_SYNC|G_RAID_BIO_FLAG_REMAP)
9389b17223SAlexander Motin #define	G_RAID_BIO_FLAG_LOCKED		0x80
9489b17223SAlexander Motin 
9589b17223SAlexander Motin struct g_raid_lock {
9689b17223SAlexander Motin 	off_t			 l_offset;
9789b17223SAlexander Motin 	off_t			 l_length;
9889b17223SAlexander Motin 	void			*l_callback_arg;
9989b17223SAlexander Motin 	int			 l_pending;
10089b17223SAlexander Motin 	LIST_ENTRY(g_raid_lock)	 l_next;
10189b17223SAlexander Motin };
10289b17223SAlexander Motin 
10389b17223SAlexander Motin #define	G_RAID_EVENT_WAIT	0x01
10489b17223SAlexander Motin #define	G_RAID_EVENT_VOLUME	0x02
10589b17223SAlexander Motin #define	G_RAID_EVENT_SUBDISK	0x04
10689b17223SAlexander Motin #define	G_RAID_EVENT_DISK	0x08
10789b17223SAlexander Motin #define	G_RAID_EVENT_DONE	0x10
10889b17223SAlexander Motin struct g_raid_event {
10989b17223SAlexander Motin 	void			*e_tgt;
11089b17223SAlexander Motin 	int			 e_event;
11189b17223SAlexander Motin 	int			 e_flags;
11289b17223SAlexander Motin 	int			 e_error;
11389b17223SAlexander Motin 	TAILQ_ENTRY(g_raid_event) e_next;
11489b17223SAlexander Motin };
11589b17223SAlexander Motin #define G_RAID_DISK_S_NONE		0x00	/* State is unknown. */
11689b17223SAlexander Motin #define G_RAID_DISK_S_OFFLINE		0x01	/* Missing disk placeholder. */
11726c538bcSAlexander Motin #define G_RAID_DISK_S_DISABLED		0x02	/* Disabled. */
11826c538bcSAlexander Motin #define G_RAID_DISK_S_FAILED		0x03	/* Failed. */
11926c538bcSAlexander Motin #define G_RAID_DISK_S_STALE_FAILED	0x04	/* Old failed. */
12026c538bcSAlexander Motin #define G_RAID_DISK_S_SPARE		0x05	/* Hot-spare. */
12126c538bcSAlexander Motin #define G_RAID_DISK_S_STALE		0x06	/* Old disk, unused now. */
12226c538bcSAlexander Motin #define G_RAID_DISK_S_ACTIVE		0x07	/* Operational. */
12389b17223SAlexander Motin 
12489b17223SAlexander Motin #define G_RAID_DISK_E_DISCONNECTED	0x01
12589b17223SAlexander Motin 
12689b17223SAlexander Motin struct g_raid_disk {
12789b17223SAlexander Motin 	struct g_raid_softc	*d_softc;	/* Back-pointer to softc. */
12889b17223SAlexander Motin 	struct g_consumer	*d_consumer;	/* GEOM disk consumer. */
12989b17223SAlexander Motin 	void			*d_md_data;	/* Disk's metadata storage. */
130609a7474SAlexander Motin 	int			 d_candelete;	/* BIO_DELETE supported. */
13189b17223SAlexander Motin 	uint64_t		 d_flags;	/* Additional flags. */
13289b17223SAlexander Motin 	u_int			 d_state;	/* Disk state. */
13389b17223SAlexander Motin 	u_int			 d_load;	/* Disk average load. */
13489b17223SAlexander Motin 	off_t			 d_last_offset;	/* Last head offset. */
13589b17223SAlexander Motin 	int			 d_read_errs;	/* Count of the read errors */
13689b17223SAlexander Motin 	TAILQ_HEAD(, g_raid_subdisk)	 d_subdisks; /* List of subdisks. */
13789b17223SAlexander Motin 	TAILQ_ENTRY(g_raid_disk)	 d_next;	/* Next disk in the node. */
1386b6e2954SConrad Meyer 	struct g_kerneldump	 d_kd;		/* Kernel dumping method/args. */
13989b17223SAlexander Motin };
14089b17223SAlexander Motin 
14189b17223SAlexander Motin #define G_RAID_SUBDISK_S_NONE		0x00	/* Absent. */
14289b17223SAlexander Motin #define G_RAID_SUBDISK_S_FAILED		0x01	/* Failed. */
14389b17223SAlexander Motin #define G_RAID_SUBDISK_S_NEW		0x02	/* Blank. */
14489b17223SAlexander Motin #define G_RAID_SUBDISK_S_REBUILD	0x03	/* Blank + rebuild. */
14589b17223SAlexander Motin #define G_RAID_SUBDISK_S_UNINITIALIZED	0x04	/* Disk of the new volume. */
14689b17223SAlexander Motin #define G_RAID_SUBDISK_S_STALE		0x05	/* Dirty. */
14789b17223SAlexander Motin #define G_RAID_SUBDISK_S_RESYNC		0x06	/* Dirty + check/repair. */
14889b17223SAlexander Motin #define G_RAID_SUBDISK_S_ACTIVE		0x07	/* Usable. */
14989b17223SAlexander Motin 
15089b17223SAlexander Motin #define G_RAID_SUBDISK_E_NEW		0x01	/* A new subdisk has arrived */
15189b17223SAlexander Motin #define G_RAID_SUBDISK_E_FAILED		0x02	/* A subdisk failed, but remains in volume */
15289b17223SAlexander Motin #define G_RAID_SUBDISK_E_DISCONNECTED	0x03	/* A subdisk removed from volume. */
15389b17223SAlexander Motin #define G_RAID_SUBDISK_E_FIRST_TR_PRIVATE 0x80	/* translation private events */
15489b17223SAlexander Motin 
15589b17223SAlexander Motin #define G_RAID_SUBDISK_POS(sd)						\
15689b17223SAlexander Motin     ((sd)->sd_disk ? ((sd)->sd_disk->d_last_offset - (sd)->sd_offset) : 0)
15789b17223SAlexander Motin #define G_RAID_SUBDISK_TRACK_SIZE	(1 * 1024 * 1024)
15889b17223SAlexander Motin #define G_RAID_SUBDISK_LOAD(sd)						\
15989b17223SAlexander Motin     ((sd)->sd_disk ? ((sd)->sd_disk->d_load) : 0)
16089b17223SAlexander Motin #define G_RAID_SUBDISK_LOAD_SCALE	256
16189b17223SAlexander Motin 
16289b17223SAlexander Motin struct g_raid_subdisk {
16389b17223SAlexander Motin 	struct g_raid_softc	*sd_softc;	/* Back-pointer to softc. */
16489b17223SAlexander Motin 	struct g_raid_disk	*sd_disk;	/* Where this subdisk lives. */
16589b17223SAlexander Motin 	struct g_raid_volume	*sd_volume;	/* Volume, sd is a part of. */
16689b17223SAlexander Motin 	off_t			 sd_offset;	/* Offset on the disk. */
16789b17223SAlexander Motin 	off_t			 sd_size;	/* Size on the disk. */
16889b17223SAlexander Motin 	u_int			 sd_pos;	/* Position in volume. */
16989b17223SAlexander Motin 	u_int			 sd_state;	/* Subdisk state. */
17089b17223SAlexander Motin 	off_t			 sd_rebuild_pos; /* Rebuild position. */
17189b17223SAlexander Motin 	int			 sd_recovery;	/* Count of recovery reqs. */
17289b17223SAlexander Motin 	TAILQ_ENTRY(g_raid_subdisk)	 sd_next; /* Next subdisk on disk. */
17389b17223SAlexander Motin };
17489b17223SAlexander Motin 
17589b17223SAlexander Motin #define G_RAID_MAX_SUBDISKS	16
17689b17223SAlexander Motin #define G_RAID_MAX_VOLUMENAME	32
17789b17223SAlexander Motin 
17889b17223SAlexander Motin #define G_RAID_VOLUME_S_STARTING	0x00
17989b17223SAlexander Motin #define G_RAID_VOLUME_S_BROKEN		0x01
18089b17223SAlexander Motin #define G_RAID_VOLUME_S_DEGRADED	0x02
18189b17223SAlexander Motin #define G_RAID_VOLUME_S_SUBOPTIMAL	0x03
18289b17223SAlexander Motin #define G_RAID_VOLUME_S_OPTIMAL		0x04
18389b17223SAlexander Motin #define G_RAID_VOLUME_S_UNSUPPORTED	0x05
18489b17223SAlexander Motin #define G_RAID_VOLUME_S_STOPPED		0x06
18589b17223SAlexander Motin 
18689b17223SAlexander Motin #define G_RAID_VOLUME_S_ALIVE(s)			\
18789b17223SAlexander Motin     ((s) == G_RAID_VOLUME_S_DEGRADED ||			\
18889b17223SAlexander Motin      (s) == G_RAID_VOLUME_S_SUBOPTIMAL ||		\
18989b17223SAlexander Motin      (s) == G_RAID_VOLUME_S_OPTIMAL)
19089b17223SAlexander Motin 
19189b17223SAlexander Motin #define G_RAID_VOLUME_E_DOWN		0x00
19289b17223SAlexander Motin #define G_RAID_VOLUME_E_UP		0x01
19389b17223SAlexander Motin #define G_RAID_VOLUME_E_START		0x10
19489b17223SAlexander Motin #define G_RAID_VOLUME_E_STARTMD		0x11
19589b17223SAlexander Motin 
19689b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID0		0x00
19789b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID1		0x01
19889b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID3		0x03
19989b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID4		0x04
20089b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID5		0x05
20189b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID6		0x06
202dbb2e755SAlexander Motin #define G_RAID_VOLUME_RL_RAIDMDF	0x07
20389b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID1E		0x11
20489b17223SAlexander Motin #define G_RAID_VOLUME_RL_SINGLE		0x0f
20589b17223SAlexander Motin #define G_RAID_VOLUME_RL_CONCAT		0x1f
20689b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID5E		0x15
20789b17223SAlexander Motin #define G_RAID_VOLUME_RL_RAID5EE	0x25
208dbb2e755SAlexander Motin #define G_RAID_VOLUME_RL_RAID5R		0x35
20989b17223SAlexander Motin #define G_RAID_VOLUME_RL_UNKNOWN	0xff
21089b17223SAlexander Motin 
21189b17223SAlexander Motin #define G_RAID_VOLUME_RLQ_NONE		0x00
212dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R1SM		0x00
213dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R1MM		0x01
214dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R3P0		0x00
215dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R3PN		0x01
216dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R4P0		0x00
217dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R4PN		0x01
218fc1de960SAlexander Motin #define G_RAID_VOLUME_RLQ_R5RA		0x00
219fc1de960SAlexander Motin #define G_RAID_VOLUME_RLQ_R5RS		0x01
220fc1de960SAlexander Motin #define G_RAID_VOLUME_RLQ_R5LA		0x02
221fc1de960SAlexander Motin #define G_RAID_VOLUME_RLQ_R5LS		0x03
222dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R6RA		0x00
223dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R6RS		0x01
224dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R6LA		0x02
225dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R6LS		0x03
226dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_RMDFRA	0x00
227dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_RMDFRS	0x01
228dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_RMDFLA	0x02
229dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_RMDFLS	0x03
230dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R1EA		0x00
231dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R1EO		0x01
232dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5ERA		0x00
233dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5ERS		0x01
234dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5ELA		0x02
235dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5ELS		0x03
236dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5EERA	0x00
237dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5EERS	0x01
238dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5EELA	0x02
239dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5EELS	0x03
240dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5RRA		0x00
241dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5RRS		0x01
242dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5RLA		0x02
243dbb2e755SAlexander Motin #define G_RAID_VOLUME_RLQ_R5RLS		0x03
24489b17223SAlexander Motin #define G_RAID_VOLUME_RLQ_UNKNOWN	0xff
24589b17223SAlexander Motin 
24689b17223SAlexander Motin struct g_raid_volume;
24789b17223SAlexander Motin 
24889b17223SAlexander Motin struct g_raid_volume {
24989b17223SAlexander Motin 	struct g_raid_softc	*v_softc;	/* Back-pointer to softc. */
25089b17223SAlexander Motin 	struct g_provider	*v_provider;	/* GEOM provider. */
25189b17223SAlexander Motin 	struct g_raid_subdisk	 v_subdisks[G_RAID_MAX_SUBDISKS];
25289b17223SAlexander Motin 						/* Subdisks of this volume. */
25389b17223SAlexander Motin 	void			*v_md_data;	/* Volume's metadata storage. */
25489b17223SAlexander Motin 	struct g_raid_tr_object	*v_tr;		/* Transformation object. */
25589b17223SAlexander Motin 	char			 v_name[G_RAID_MAX_VOLUMENAME];
25689b17223SAlexander Motin 						/* Volume name. */
25789b17223SAlexander Motin 	u_int			 v_state;	/* Volume state. */
25889b17223SAlexander Motin 	u_int			 v_raid_level;	/* Array RAID level. */
25989b17223SAlexander Motin 	u_int			 v_raid_level_qualifier; /* RAID level det. */
26089b17223SAlexander Motin 	u_int			 v_disks_count;	/* Number of disks in array. */
2618f12ca2eSAlexander Motin 	u_int			 v_mdf_pdisks;	/* Number of parity disks
2628f12ca2eSAlexander Motin 						   in RAIDMDF array. */
2638f12ca2eSAlexander Motin 	uint16_t		 v_mdf_polynomial; /* Polynomial for RAIDMDF. */
2648f12ca2eSAlexander Motin 	uint8_t			 v_mdf_method;	/* Generation method for RAIDMDF. */
26589b17223SAlexander Motin 	u_int			 v_strip_size;	/* Array strip size. */
2668f12ca2eSAlexander Motin 	u_int			 v_rotate_parity; /* Rotate RAID5R parity
2678f12ca2eSAlexander Motin 						   after numer of stripes. */
26889b17223SAlexander Motin 	u_int			 v_sectorsize;	/* Volume sector size. */
26989b17223SAlexander Motin 	off_t			 v_mediasize;	/* Volume media size.  */
27089b17223SAlexander Motin 	struct bio_queue_head	 v_inflight;	/* In-flight write requests. */
27189b17223SAlexander Motin 	struct bio_queue_head	 v_locked;	/* Blocked I/O requests. */
27289b17223SAlexander Motin 	LIST_HEAD(, g_raid_lock) v_locks;	 /* List of locked regions. */
27389b17223SAlexander Motin 	int			 v_pending_lock; /* writes to locked region */
27489b17223SAlexander Motin 	int			 v_dirty;	/* Volume is DIRTY. */
27589b17223SAlexander Motin 	struct timeval		 v_last_done;	/* Time of the last I/O. */
27689b17223SAlexander Motin 	time_t			 v_last_write;	/* Time of the last write. */
27789b17223SAlexander Motin 	u_int			 v_writes;	/* Number of active writes. */
27889b17223SAlexander Motin 	struct root_hold_token	*v_rootmount;	/* Root mount delay token. */
27989b17223SAlexander Motin 	int			 v_starting;	/* Volume is starting */
28089b17223SAlexander Motin 	int			 v_stopping;	/* Volume is stopping */
28189b17223SAlexander Motin 	int			 v_provider_open; /* Number of opens. */
28289b17223SAlexander Motin 	int			 v_global_id;	/* Global volume ID (rX). */
2830f0b2fd8SAlexander Motin 	int			 v_read_only;	/* Volume is read-only. */
28489b17223SAlexander Motin 	TAILQ_ENTRY(g_raid_volume)	 v_next; /* List of volumes entry. */
28589b17223SAlexander Motin 	LIST_ENTRY(g_raid_volume)	 v_global_next; /* Global list entry. */
28689b17223SAlexander Motin };
28789b17223SAlexander Motin 
28889b17223SAlexander Motin #define G_RAID_NODE_E_WAKE	0x00
28989b17223SAlexander Motin #define G_RAID_NODE_E_START	0x01
29089b17223SAlexander Motin 
29189b17223SAlexander Motin struct g_raid_softc {
29289b17223SAlexander Motin 	struct g_raid_md_object	*sc_md;		/* Metadata object. */
29389b17223SAlexander Motin 	struct g_geom		*sc_geom;	/* GEOM class instance. */
29489b17223SAlexander Motin 	uint64_t		 sc_flags;	/* Additional flags. */
29589b17223SAlexander Motin 	TAILQ_HEAD(, g_raid_volume)	 sc_volumes;	/* List of volumes. */
29689b17223SAlexander Motin 	TAILQ_HEAD(, g_raid_disk)	 sc_disks;	/* List of disks. */
29789b17223SAlexander Motin 	struct sx		 sc_lock;	/* Main node lock. */
29889b17223SAlexander Motin 	struct proc		*sc_worker;	/* Worker process. */
29989b17223SAlexander Motin 	struct mtx		 sc_queue_mtx;	/* Worker queues lock. */
30089b17223SAlexander Motin 	TAILQ_HEAD(, g_raid_event) sc_events;	/* Worker events queue. */
30189b17223SAlexander Motin 	struct bio_queue_head	 sc_queue;	/* Worker I/O queue. */
30289b17223SAlexander Motin 	int			 sc_stopping;	/* Node is stopping */
30389b17223SAlexander Motin };
30489b17223SAlexander Motin #define	sc_name	sc_geom->name
30589b17223SAlexander Motin 
306c89d2fbeSAlexander Motin SYSCTL_DECL(_kern_geom_raid);
307c89d2fbeSAlexander Motin 
30889b17223SAlexander Motin /*
30989b17223SAlexander Motin  * KOBJ parent class of metadata processing modules.
31089b17223SAlexander Motin  */
31189b17223SAlexander Motin struct g_raid_md_class {
31289b17223SAlexander Motin 	KOBJ_CLASS_FIELDS;
313c89d2fbeSAlexander Motin 	int		 mdc_enable;
31489b17223SAlexander Motin 	int		 mdc_priority;
31589b17223SAlexander Motin 	LIST_ENTRY(g_raid_md_class) mdc_list;
31689b17223SAlexander Motin };
31789b17223SAlexander Motin 
31889b17223SAlexander Motin /*
31989b17223SAlexander Motin  * KOBJ instance of metadata processing module.
32089b17223SAlexander Motin  */
32189b17223SAlexander Motin struct g_raid_md_object {
32289b17223SAlexander Motin 	KOBJ_FIELDS;
32389b17223SAlexander Motin 	struct g_raid_md_class	*mdo_class;
32489b17223SAlexander Motin 	struct g_raid_softc	*mdo_softc;	/* Back-pointer to softc. */
32589b17223SAlexander Motin };
32689b17223SAlexander Motin 
32789b17223SAlexander Motin int g_raid_md_modevent(module_t, int, void *);
32889b17223SAlexander Motin 
329c89d2fbeSAlexander Motin #define	G_RAID_MD_DECLARE(name, label)				\
330c89d2fbeSAlexander Motin     static moduledata_t g_raid_md_##name##_mod = {		\
331c89d2fbeSAlexander Motin 	"g_raid_md_" __XSTRING(name),				\
33289b17223SAlexander Motin 	g_raid_md_modevent,					\
333c89d2fbeSAlexander Motin 	&g_raid_md_##name##_class				\
33489b17223SAlexander Motin     };								\
335c89d2fbeSAlexander Motin     DECLARE_MODULE(g_raid_md_##name, g_raid_md_##name##_mod,	\
336c89d2fbeSAlexander Motin 	SI_SUB_DRIVERS, SI_ORDER_SECOND);			\
337c89d2fbeSAlexander Motin     MODULE_DEPEND(g_raid_md_##name, geom_raid, 0, 0, 0);	\
3387029da5cSPawel Biernacki     SYSCTL_NODE(_kern_geom_raid, OID_AUTO, name,		\
3397029da5cSPawel Biernacki         CTLFLAG_RD | CTLFLAG_MPSAFE,				\
340c89d2fbeSAlexander Motin 	NULL, label " metadata module");			\
341c89d2fbeSAlexander Motin     SYSCTL_INT(_kern_geom_raid_##name, OID_AUTO, enable,	\
342af3b2549SHans Petter Selasky 	CTLFLAG_RWTUN, &g_raid_md_##name##_class.mdc_enable, 0,	\
343af3b2549SHans Petter Selasky 	"Enable " label " metadata format taste")
34489b17223SAlexander Motin 
34589b17223SAlexander Motin /*
34689b17223SAlexander Motin  * KOBJ parent class of data transformation modules.
34789b17223SAlexander Motin  */
34889b17223SAlexander Motin struct g_raid_tr_class {
34989b17223SAlexander Motin 	KOBJ_CLASS_FIELDS;
350c89d2fbeSAlexander Motin 	int		 trc_enable;
35189b17223SAlexander Motin 	int		 trc_priority;
352b43560abSAlexander Motin 	int		 trc_accept_unmapped;
35389b17223SAlexander Motin 	LIST_ENTRY(g_raid_tr_class) trc_list;
35489b17223SAlexander Motin };
35589b17223SAlexander Motin 
35689b17223SAlexander Motin /*
35789b17223SAlexander Motin  * KOBJ instance of data transformation module.
35889b17223SAlexander Motin  */
35989b17223SAlexander Motin struct g_raid_tr_object {
36089b17223SAlexander Motin 	KOBJ_FIELDS;
36189b17223SAlexander Motin 	struct g_raid_tr_class	*tro_class;
36289b17223SAlexander Motin 	struct g_raid_volume 	*tro_volume;	/* Back-pointer to volume. */
36389b17223SAlexander Motin };
36489b17223SAlexander Motin 
36589b17223SAlexander Motin int g_raid_tr_modevent(module_t, int, void *);
36689b17223SAlexander Motin 
367c89d2fbeSAlexander Motin #define	G_RAID_TR_DECLARE(name, label)				\
368c89d2fbeSAlexander Motin     static moduledata_t g_raid_tr_##name##_mod = {		\
369c89d2fbeSAlexander Motin 	"g_raid_tr_" __XSTRING(name),				\
37089b17223SAlexander Motin 	g_raid_tr_modevent,					\
371c89d2fbeSAlexander Motin 	&g_raid_tr_##name##_class				\
37289b17223SAlexander Motin     };								\
373c89d2fbeSAlexander Motin     DECLARE_MODULE(g_raid_tr_##name, g_raid_tr_##name##_mod,	\
374c89d2fbeSAlexander Motin 	SI_SUB_DRIVERS, SI_ORDER_FIRST);			\
375c89d2fbeSAlexander Motin     MODULE_DEPEND(g_raid_tr_##name, geom_raid, 0, 0, 0);	\
3767029da5cSPawel Biernacki     SYSCTL_NODE(_kern_geom_raid, OID_AUTO, name,		\
3777029da5cSPawel Biernacki         CTLFLAG_RD | CTLFLAG_MPSAFE,				\
378c89d2fbeSAlexander Motin 	NULL, label " transformation module");			\
379c89d2fbeSAlexander Motin     SYSCTL_INT(_kern_geom_raid_##name, OID_AUTO, enable,	\
380af3b2549SHans Petter Selasky 	CTLFLAG_RWTUN, &g_raid_tr_##name##_class.trc_enable, 0,	\
381af3b2549SHans Petter Selasky 	"Enable " label " transformation module taste")
38289b17223SAlexander Motin 
38389b17223SAlexander Motin const char * g_raid_volume_level2str(int level, int qual);
38489b17223SAlexander Motin int g_raid_volume_str2level(const char *str, int *level, int *qual);
38589b17223SAlexander Motin const char * g_raid_volume_state2str(int state);
38689b17223SAlexander Motin const char * g_raid_subdisk_state2str(int state);
38789b17223SAlexander Motin const char * g_raid_disk_state2str(int state);
38889b17223SAlexander Motin 
38989b17223SAlexander Motin struct g_raid_softc * g_raid_create_node(struct g_class *mp,
39089b17223SAlexander Motin     const char *name, struct g_raid_md_object *md);
3918df8e26aSAlexander Motin int g_raid_create_node_format(const char *format, struct gctl_req *req,
3928df8e26aSAlexander Motin     struct g_geom **gp);
39389b17223SAlexander Motin struct g_raid_volume * g_raid_create_volume(struct g_raid_softc *sc,
39489b17223SAlexander Motin     const char *name, int id);
39589b17223SAlexander Motin struct g_raid_disk * g_raid_create_disk(struct g_raid_softc *sc);
39689b17223SAlexander Motin const char * g_raid_get_diskname(struct g_raid_disk *disk);
397609a7474SAlexander Motin void g_raid_get_disk_info(struct g_raid_disk *disk);
39889b17223SAlexander Motin 
39989b17223SAlexander Motin int g_raid_start_volume(struct g_raid_volume *vol);
40089b17223SAlexander Motin 
40189b17223SAlexander Motin int g_raid_destroy_node(struct g_raid_softc *sc, int worker);
40289b17223SAlexander Motin int g_raid_destroy_volume(struct g_raid_volume *vol);
40389b17223SAlexander Motin int g_raid_destroy_disk(struct g_raid_disk *disk);
40489b17223SAlexander Motin 
40589b17223SAlexander Motin void g_raid_iodone(struct bio *bp, int error);
40689b17223SAlexander Motin void g_raid_subdisk_iostart(struct g_raid_subdisk *sd, struct bio *bp);
407489ba222SMitchell Horne int g_raid_subdisk_kerneldump(struct g_raid_subdisk *sd, void *virtual,
408489ba222SMitchell Horne     off_t offset, size_t length);
40989b17223SAlexander Motin 
41089b17223SAlexander Motin struct g_consumer *g_raid_open_consumer(struct g_raid_softc *sc,
41189b17223SAlexander Motin     const char *name);
41289b17223SAlexander Motin void g_raid_kill_consumer(struct g_raid_softc *sc, struct g_consumer *cp);
41389b17223SAlexander Motin 
41489b17223SAlexander Motin void g_raid_report_disk_state(struct g_raid_disk *disk);
41589b17223SAlexander Motin void g_raid_change_disk_state(struct g_raid_disk *disk, int state);
41689b17223SAlexander Motin void g_raid_change_subdisk_state(struct g_raid_subdisk *sd, int state);
41789b17223SAlexander Motin void g_raid_change_volume_state(struct g_raid_volume *vol, int state);
41889b17223SAlexander Motin 
41989b17223SAlexander Motin void g_raid_write_metadata(struct g_raid_softc *sc, struct g_raid_volume *vol,
42089b17223SAlexander Motin     struct g_raid_subdisk *sd, struct g_raid_disk *disk);
42189b17223SAlexander Motin void g_raid_fail_disk(struct g_raid_softc *sc,
42289b17223SAlexander Motin     struct g_raid_subdisk *sd, struct g_raid_disk *disk);
42389b17223SAlexander Motin 
42489b17223SAlexander Motin void g_raid_tr_flush_common(struct g_raid_tr_object *tr, struct bio *bp);
42589b17223SAlexander Motin int g_raid_tr_kerneldump_common(struct g_raid_tr_object *tr,
42689b17223SAlexander Motin     void *virtual, vm_offset_t physical, off_t offset, size_t length);
42789b17223SAlexander Motin 
42889b17223SAlexander Motin u_int g_raid_ndisks(struct g_raid_softc *sc, int state);
42989b17223SAlexander Motin u_int g_raid_nsubdisks(struct g_raid_volume *vol, int state);
43089b17223SAlexander Motin u_int g_raid_nopens(struct g_raid_softc *sc);
43189b17223SAlexander Motin struct g_raid_subdisk * g_raid_get_subdisk(struct g_raid_volume *vol,
43289b17223SAlexander Motin     int state);
43389b17223SAlexander Motin #define	G_RAID_DESTROY_SOFT		0
43489b17223SAlexander Motin #define	G_RAID_DESTROY_DELAYED	1
43589b17223SAlexander Motin #define	G_RAID_DESTROY_HARD		2
43689b17223SAlexander Motin int g_raid_destroy(struct g_raid_softc *sc, int how);
43789b17223SAlexander Motin int g_raid_event_send(void *arg, int event, int flags);
43889b17223SAlexander Motin int g_raid_lock_range(struct g_raid_volume *vol, off_t off, off_t len,
43989b17223SAlexander Motin     struct bio *ignore, void *argp);
44089b17223SAlexander Motin int g_raid_unlock_range(struct g_raid_volume *vol, off_t off, off_t len);
44189b17223SAlexander Motin 
44289b17223SAlexander Motin g_ctl_req_t g_raid_ctl;
44389b17223SAlexander Motin #endif	/* _KERNEL */
44489b17223SAlexander Motin 
44589b17223SAlexander Motin #endif	/* !_G_RAID_H_ */
446