geom_vinum_raid5.h revision 130389
1130389Sle/* 2130389Sle * Copyright (c) 2004 Lukas Ertl 3130389Sle * All rights reserved. 4130389Sle * 5130389Sle * Redistribution and use in source and binary forms, with or without 6130389Sle * modification, are permitted provided that the following conditions 7130389Sle * are met: 8130389Sle * 1. Redistributions of source code must retain the above copyright 9130389Sle * notice, this list of conditions and the following disclaimer. 10130389Sle * 2. Redistributions in binary form must reproduce the above copyright 11130389Sle * notice, this list of conditions and the following disclaimer in the 12130389Sle * documentation and/or other materials provided with the distribution. 13130389Sle * 14130389Sle * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15130389Sle * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16130389Sle * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17130389Sle * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18130389Sle * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19130389Sle * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20130389Sle * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21130389Sle * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22130389Sle * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23130389Sle * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24130389Sle * SUCH DAMAGE. 25130389Sle * 26130389Sle * $FreeBSD: head/sys/geom/vinum/geom_vinum_raid5.h 130389 2004-06-12 21:16:10Z le $ 27130389Sle */ 28130389Sle 29130389Sle#ifndef _GEOM_VINUM_RAID5_H_ 30130389Sle#define _GEOM_VINUM_RAID5_H_ 31130389Sle 32130389Sle/* 33130389Sle * A single RAID5 request usually needs more than one I/O transaction, 34130389Sle * depending on the state of the associated subdisks and the direction of the 35130389Sle * transaction (read or write). Every subrequest of a RAID5 request, 36130389Sle * represented by a gv_raid_packet, is defined by a gv_raid5_bit. 37130389Sle */ 38130389Sle 39130389Sle/* A subrequest of a RAID5 read/write operation. */ 40130389Slestruct gv_raid5_bit { 41130389Sle struct bio *bio; /* BIO of this subrequest. */ 42130389Sle caddr_t buf; /* Data buffer of this subrequest. */ 43130389Sle int malloc; /* Flag if data buffer was malloced. */ 44130389Sle struct g_consumer *consumer; /* Consumer to send the BIO to. */ 45130389Sle TAILQ_ENTRY(gv_raid5_bit) list; /* Entry in the list of this request. */ 46130389Sle}; 47130389Sle 48130389Sle/* Container for one or more gv_raid5_bits; represents a RAID5 I/O request. */ 49130389Slestruct gv_raid5_packet { 50130389Sle caddr_t buf; /* Data buffer of this RAID5 request. */ 51130389Sle off_t length; /* Size of data buffer. */ 52130389Sle off_t lockbase; /* Deny access to our plex offset. */ 53130389Sle off_t offset; /* The drive offset of the subdisk. */ 54130389Sle int bufmalloc; /* Flag if data buffer was malloced. */ 55130389Sle int active; /* Count of active subrequests. */ 56130389Sle int rqcount; /* Count of subrequests. */ 57130389Sle 58130389Sle struct bio *bio; /* Pointer to the original bio. */ 59130389Sle caddr_t data; /* Pointer to the original data. */ 60130389Sle 61130389Sle struct g_consumer *original; /* Consumer to the data stripe. */ 62130389Sle struct g_consumer *parity; /* Consumer to the parity stripe. */ 63130389Sle 64130389Sle /* State of this RAID5 packet. */ 65130389Sle enum { 66130389Sle SETUP, /* Newly created. */ 67130389Sle VALID, /* Ready for processing. */ 68130389Sle IO, /* Currently doing I/O. */ 69130389Sle FINISH /* Packet has finished. */ 70130389Sle } state; 71130389Sle 72130389Sle /* Type of this RAID5 transaction. */ 73130389Sle enum { 74130389Sle JUNK, /* Newly created, not valid. */ 75130389Sle NORMAL, /* Normal read or write. */ 76130389Sle ISPARITY, /* Containing only parity data. */ 77130389Sle NOPARITY, /* Parity stripe not available. */ 78130389Sle DEGRADED, /* Data stripe not available. */ 79130389Sle COMBINED /* Data and parity stripes ok, others not. */ 80130389Sle } type; 81130389Sle 82130389Sle TAILQ_HEAD(,gv_raid5_bit) bits; /* List of subrequests. */ 83130389Sle TAILQ_ENTRY(gv_raid5_packet) list; /* Entry in plex's packet list. */ 84130389Sle}; 85130389Sle 86130389Sleint gv_build_raid5_req(struct gv_raid5_packet *, struct bio *, caddr_t, 87130389Sle long, off_t); 88130389Slevoid gv_raid5_done(struct bio *); 89130389Slevoid gv_raid5_worker(void *); 90130389Slestruct gv_raid5_packet *gv_new_raid5_packet(void); 91130389Slestruct gv_raid5_bit *gv_new_raid5_bit(void); 92130389Sle 93130389Sle#endif /* !_GEOM_VINUM_RAID5_H_ */ 94