xref: /openbsd/sys/dev/softraid_raid1c.c (revision 87edded1)
1*87edded1Stobhe /* $OpenBSD: softraid_raid1c.c,v 1.6 2021/10/24 14:50:42 tobhe Exp $ */
2c98f5080Sstsp /*
3c98f5080Sstsp  * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us>
4c98f5080Sstsp  * Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org>
5c98f5080Sstsp  * Copyright (c) 2008 Damien Miller <djm@mindrot.org>
6c98f5080Sstsp  * Copyright (c) 2009 Joel Sing <jsing@openbsd.org>
7c98f5080Sstsp  * Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
8c98f5080Sstsp  *
9c98f5080Sstsp  * Permission to use, copy, modify, and distribute this software for any
10c98f5080Sstsp  * purpose with or without fee is hereby granted, provided that the above
11c98f5080Sstsp  * copyright notice and this permission notice appear in all copies.
12c98f5080Sstsp  *
13c98f5080Sstsp  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14c98f5080Sstsp  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15c98f5080Sstsp  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16c98f5080Sstsp  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17c98f5080Sstsp  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18c98f5080Sstsp  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19c98f5080Sstsp  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20c98f5080Sstsp  */
21c98f5080Sstsp 
22c98f5080Sstsp #include "bio.h"
23c98f5080Sstsp 
24c98f5080Sstsp #include <sys/param.h>
25c98f5080Sstsp #include <sys/systm.h>
26c98f5080Sstsp #include <sys/buf.h>
27c98f5080Sstsp #include <sys/device.h>
28c98f5080Sstsp #include <sys/ioctl.h>
29c98f5080Sstsp #include <sys/malloc.h>
30c98f5080Sstsp #include <sys/kernel.h>
31c98f5080Sstsp #include <sys/disk.h>
32c98f5080Sstsp #include <sys/rwlock.h>
33c98f5080Sstsp #include <sys/queue.h>
34c98f5080Sstsp #include <sys/fcntl.h>
35c98f5080Sstsp #include <sys/mount.h>
36c98f5080Sstsp #include <sys/sensors.h>
37c98f5080Sstsp #include <sys/stat.h>
38c98f5080Sstsp #include <sys/task.h>
39c98f5080Sstsp #include <sys/conf.h>
40c98f5080Sstsp #include <sys/uio.h>
41c98f5080Sstsp 
42c98f5080Sstsp #include <crypto/cryptodev.h>
43c98f5080Sstsp 
44c98f5080Sstsp #include <scsi/scsi_all.h>
45c98f5080Sstsp #include <scsi/scsiconf.h>
46c98f5080Sstsp #include <scsi/scsi_disk.h>
47c98f5080Sstsp 
48c98f5080Sstsp #include <dev/softraidvar.h>
49c98f5080Sstsp 
50c98f5080Sstsp /* RAID 1C functions. */
51c98f5080Sstsp int	sr_raid1c_create(struct sr_discipline *, struct bioc_createraid *,
52c98f5080Sstsp 	    int, int64_t);
53c98f5080Sstsp int	sr_raid1c_add_offline_chunks(struct sr_discipline *, int);
54c98f5080Sstsp int	sr_raid1c_assemble(struct sr_discipline *, struct bioc_createraid *,
55c98f5080Sstsp 	    int, void *);
56eb0e73bdSstsp int	sr_raid1c_alloc_resources(struct sr_discipline *);
57eb0e73bdSstsp void	sr_raid1c_free_resources(struct sr_discipline *sd);
58eb0e73bdSstsp int	sr_raid1c_ioctl(struct sr_discipline *sd, struct bioc_discipline *bd);
59eb0e73bdSstsp int	sr_raid1c_meta_opt_handler(struct sr_discipline *,
60eb0e73bdSstsp 	    struct sr_meta_opt_hdr *);
61c98f5080Sstsp int	sr_raid1c_rw(struct sr_workunit *);
62c98f5080Sstsp int	sr_raid1c_dev_rw(struct sr_workunit *, struct sr_crypto_wu *);
63eb0e73bdSstsp void	sr_raid1c_done(struct sr_workunit *wu);
64c98f5080Sstsp 
65c98f5080Sstsp /* RAID1 functions */
66c98f5080Sstsp extern int	sr_raid1_init(struct sr_discipline *sd);
67c98f5080Sstsp extern int	sr_raid1_assemble(struct sr_discipline *,
68c98f5080Sstsp 		    struct bioc_createraid *, int, void *);
69c98f5080Sstsp extern int	sr_raid1_wu_done(struct sr_workunit *);
70c98f5080Sstsp extern void	sr_raid1_set_chunk_state(struct sr_discipline *, int, int);
71c98f5080Sstsp extern void	sr_raid1_set_vol_state(struct sr_discipline *);
72c98f5080Sstsp 
73c98f5080Sstsp /* CRYPTO raid functions */
74eb0e73bdSstsp extern struct sr_crypto_wu *sr_crypto_prepare(struct sr_workunit *,
75eb0e73bdSstsp 		    struct sr_crypto *, int);
76c98f5080Sstsp extern int	sr_crypto_meta_create(struct sr_discipline *,
77eb0e73bdSstsp 		    struct sr_crypto *, struct bioc_createraid *);
78eb0e73bdSstsp extern int	sr_crypto_set_key(struct sr_discipline *,
79eb0e73bdSstsp 		    struct sr_crypto *, struct bioc_createraid *, int, void *);
80eb0e73bdSstsp extern int	sr_crypto_alloc_resources_internal(struct sr_discipline *,
81eb0e73bdSstsp 		    struct sr_crypto *);
82eb0e73bdSstsp extern void	sr_crypto_free_resources_internal(struct sr_discipline *,
83eb0e73bdSstsp 		    struct sr_crypto *);
84eb0e73bdSstsp extern int	sr_crypto_ioctl_internal(struct sr_discipline *,
85eb0e73bdSstsp 		    struct sr_crypto *, struct bioc_discipline *);
86eb0e73bdSstsp int		sr_crypto_meta_opt_handler_internal(struct sr_discipline *,
87eb0e73bdSstsp 		    struct sr_crypto *, struct sr_meta_opt_hdr *);
88eb0e73bdSstsp void		sr_crypto_done_internal(struct sr_workunit *,
89eb0e73bdSstsp 		    struct sr_crypto *);
90c98f5080Sstsp 
91c98f5080Sstsp /* Discipline initialisation. */
92c98f5080Sstsp void
sr_raid1c_discipline_init(struct sr_discipline * sd)93c98f5080Sstsp sr_raid1c_discipline_init(struct sr_discipline *sd)
94c98f5080Sstsp {
95c98f5080Sstsp 	int i;
96c98f5080Sstsp 
97c98f5080Sstsp 	/* Fill out discipline members. */
98c98f5080Sstsp 	sd->sd_wu_size = sizeof(struct sr_crypto_wu);
99c98f5080Sstsp 	sd->sd_type = SR_MD_RAID1C;
100c98f5080Sstsp 	strlcpy(sd->sd_name, "RAID 1C", sizeof(sd->sd_name));
101c98f5080Sstsp 	sd->sd_capabilities = SR_CAP_SYSTEM_DISK | SR_CAP_AUTO_ASSEMBLE |
102c98f5080Sstsp 	    SR_CAP_REBUILD | SR_CAP_REDUNDANT;
103c98f5080Sstsp 	sd->sd_max_wu = SR_RAID1C_NOWU;
104c98f5080Sstsp 
105c98f5080Sstsp 	for (i = 0; i < SR_CRYPTO_MAXKEYS; i++)
106eb0e73bdSstsp 		sd->mds.mdd_raid1c.sr1c_crypto.scr_sid[i] = (u_int64_t)-1;
107c98f5080Sstsp 
108c98f5080Sstsp 	/* Setup discipline specific function pointers. */
109eb0e73bdSstsp 	sd->sd_alloc_resources = sr_raid1c_alloc_resources;
110c98f5080Sstsp 	sd->sd_assemble = sr_raid1c_assemble;
111c98f5080Sstsp 	sd->sd_create = sr_raid1c_create;
112eb0e73bdSstsp 	sd->sd_free_resources = sr_raid1c_free_resources;
113eb0e73bdSstsp 	sd->sd_ioctl_handler = sr_raid1c_ioctl;
114eb0e73bdSstsp 	sd->sd_meta_opt_handler = sr_raid1c_meta_opt_handler;
115c98f5080Sstsp 	sd->sd_scsi_rw = sr_raid1c_rw;
116eb0e73bdSstsp 	sd->sd_scsi_done = sr_raid1c_done;
117c98f5080Sstsp 	sd->sd_scsi_wu_done = sr_raid1_wu_done;
118c98f5080Sstsp 	sd->sd_set_chunk_state = sr_raid1_set_chunk_state;
119c98f5080Sstsp 	sd->sd_set_vol_state = sr_raid1_set_vol_state;
120c98f5080Sstsp }
121c98f5080Sstsp 
122c98f5080Sstsp int
sr_raid1c_create(struct sr_discipline * sd,struct bioc_createraid * bc,int no_chunk,int64_t coerced_size)123c98f5080Sstsp sr_raid1c_create(struct sr_discipline *sd, struct bioc_createraid *bc,
124c98f5080Sstsp     int no_chunk, int64_t coerced_size)
125c98f5080Sstsp {
126c98f5080Sstsp 	int rv;
127c98f5080Sstsp 
128c98f5080Sstsp 	if (no_chunk < 2) {
129c98f5080Sstsp 		sr_error(sd->sd_sc, "%s requires two or more chunks",
130c98f5080Sstsp 		    sd->sd_name);
131c98f5080Sstsp 		return EINVAL;
132c98f5080Sstsp 	}
133c98f5080Sstsp 
134c98f5080Sstsp 	sd->sd_meta->ssdi.ssd_size = coerced_size;
135c98f5080Sstsp 
136c98f5080Sstsp 	rv = sr_raid1_init(sd);
137c98f5080Sstsp 	if (rv)
138c98f5080Sstsp 		return rv;
139c98f5080Sstsp 
140eb0e73bdSstsp 	return sr_crypto_meta_create(sd, &sd->mds.mdd_raid1c.sr1c_crypto, bc);
141c98f5080Sstsp }
142c98f5080Sstsp 
143c98f5080Sstsp int
sr_raid1c_add_offline_chunks(struct sr_discipline * sd,int no_chunk)144c98f5080Sstsp sr_raid1c_add_offline_chunks(struct sr_discipline *sd, int no_chunk)
145c98f5080Sstsp {
146c98f5080Sstsp 	struct sr_chunk	*ch_entry, *ch_prev;
147c98f5080Sstsp 	struct sr_chunk **chunks;
148c98f5080Sstsp 	int c;
149c98f5080Sstsp 
150c98f5080Sstsp 	chunks = mallocarray(sd->sd_meta->ssdi.ssd_chunk_no,
151c98f5080Sstsp 	    sizeof(struct sr_chunk *), M_DEVBUF, M_WAITOK | M_ZERO);
152c98f5080Sstsp 
153c98f5080Sstsp 	for (c = 0; c < no_chunk; c++)
154c98f5080Sstsp 		chunks[c] = sd->sd_vol.sv_chunks[c];
155c98f5080Sstsp 
156c98f5080Sstsp 	for (c = no_chunk; c < sd->sd_meta->ssdi.ssd_chunk_no; c++) {
157c98f5080Sstsp 		ch_prev = chunks[c - 1];
158c98f5080Sstsp 		ch_entry = malloc(sizeof(struct sr_chunk), M_DEVBUF,
159c98f5080Sstsp 		    M_WAITOK | M_ZERO);
160c98f5080Sstsp 		ch_entry->src_meta.scm_status = BIOC_SDOFFLINE;
161c98f5080Sstsp 		ch_entry->src_dev_mm = NODEV;
162c98f5080Sstsp 		SLIST_INSERT_AFTER(ch_prev, ch_entry, src_link);
163c98f5080Sstsp 		chunks[c] = ch_entry;
164c98f5080Sstsp 	}
165c98f5080Sstsp 
166c98f5080Sstsp 	free(sd->sd_vol.sv_chunks, M_DEVBUF,
167c98f5080Sstsp 	    sizeof(struct sr_chunk *) * no_chunk);
168c98f5080Sstsp 	sd->sd_vol.sv_chunks = chunks;
169c98f5080Sstsp 
170c98f5080Sstsp 	return (0);
171c98f5080Sstsp }
172c98f5080Sstsp 
173c98f5080Sstsp int
sr_raid1c_assemble(struct sr_discipline * sd,struct bioc_createraid * bc,int no_chunk,void * data)174c98f5080Sstsp sr_raid1c_assemble(struct sr_discipline *sd, struct bioc_createraid *bc,
175c98f5080Sstsp     int no_chunk, void *data)
176c98f5080Sstsp {
177eb0e73bdSstsp 	struct sr_raid1c *mdd_raid1c = &sd->mds.mdd_raid1c;
178c98f5080Sstsp 	int rv;
179c98f5080Sstsp 
180c98f5080Sstsp 	/* Create NODEV place-holders for missing chunks. */
181c98f5080Sstsp 	if (no_chunk < sd->sd_meta->ssdi.ssd_chunk_no) {
182c98f5080Sstsp 		rv = sr_raid1c_add_offline_chunks(sd, no_chunk);
183c98f5080Sstsp 		if (rv)
184c98f5080Sstsp 			return (rv);
185c98f5080Sstsp 	}
186c98f5080Sstsp 
187c98f5080Sstsp 	rv = sr_raid1_assemble(sd, bc, no_chunk, NULL);
188c98f5080Sstsp 	if (rv)
189eb0e73bdSstsp 		return (rv);
190c98f5080Sstsp 
191eb0e73bdSstsp 	return sr_crypto_set_key(sd, &mdd_raid1c->sr1c_crypto, bc,
192eb0e73bdSstsp 	    no_chunk, data);
193eb0e73bdSstsp }
194eb0e73bdSstsp 
195eb0e73bdSstsp int
sr_raid1c_ioctl(struct sr_discipline * sd,struct bioc_discipline * bd)196eb0e73bdSstsp sr_raid1c_ioctl(struct sr_discipline *sd, struct bioc_discipline *bd)
197eb0e73bdSstsp {
198eb0e73bdSstsp 	struct sr_raid1c *mdd_raid1c = &sd->mds.mdd_raid1c;
199eb0e73bdSstsp 	return sr_crypto_ioctl_internal(sd, &mdd_raid1c->sr1c_crypto, bd);
200eb0e73bdSstsp }
201eb0e73bdSstsp 
202eb0e73bdSstsp int
sr_raid1c_alloc_resources(struct sr_discipline * sd)203eb0e73bdSstsp sr_raid1c_alloc_resources(struct sr_discipline *sd)
204eb0e73bdSstsp {
205eb0e73bdSstsp 	struct sr_raid1c *mdd_raid1c = &sd->mds.mdd_raid1c;
206eb0e73bdSstsp 	return sr_crypto_alloc_resources_internal(sd, &mdd_raid1c->sr1c_crypto);
207eb0e73bdSstsp }
208eb0e73bdSstsp 
209eb0e73bdSstsp void
sr_raid1c_free_resources(struct sr_discipline * sd)210eb0e73bdSstsp sr_raid1c_free_resources(struct sr_discipline *sd)
211eb0e73bdSstsp {
212eb0e73bdSstsp 	struct sr_raid1c *mdd_raid1c = &sd->mds.mdd_raid1c;
213eb0e73bdSstsp 	sr_crypto_free_resources_internal(sd, &mdd_raid1c->sr1c_crypto);
214c98f5080Sstsp }
215c98f5080Sstsp 
216c98f5080Sstsp int
sr_raid1c_dev_rw(struct sr_workunit * wu,struct sr_crypto_wu * crwu)217c98f5080Sstsp sr_raid1c_dev_rw(struct sr_workunit *wu, struct sr_crypto_wu *crwu)
218c98f5080Sstsp {
219c98f5080Sstsp 	struct sr_discipline	*sd = wu->swu_dis;
220c98f5080Sstsp 	struct scsi_xfer	*xs = wu->swu_xs;
221eb0e73bdSstsp 	struct sr_raid1c	*mdd_raid1c = &sd->mds.mdd_raid1c;
222c98f5080Sstsp 	struct sr_ccb		*ccb;
223c98f5080Sstsp 	struct uio		*uio;
224c98f5080Sstsp 	struct sr_chunk		*scp;
225c98f5080Sstsp 	int			ios, chunk, i, rt;
226c98f5080Sstsp 	daddr_t			blkno;
227c98f5080Sstsp 
228c98f5080Sstsp 	blkno = wu->swu_blk_start;
229c98f5080Sstsp 
230c98f5080Sstsp 	if (xs->flags & SCSI_DATA_IN)
231c98f5080Sstsp 		ios = 1;
232c98f5080Sstsp 	else
233c98f5080Sstsp 		ios = sd->sd_meta->ssdi.ssd_chunk_no;
234c98f5080Sstsp 
235c98f5080Sstsp 	for (i = 0; i < ios; i++) {
236c98f5080Sstsp 		if (xs->flags & SCSI_DATA_IN) {
237c98f5080Sstsp 			rt = 0;
238c98f5080Sstsp ragain:
239c98f5080Sstsp 			/* interleave reads */
240eb0e73bdSstsp 			chunk = mdd_raid1c->sr1c_raid1.sr1_counter++ %
241c98f5080Sstsp 			    sd->sd_meta->ssdi.ssd_chunk_no;
242c98f5080Sstsp 			scp = sd->sd_vol.sv_chunks[chunk];
243c98f5080Sstsp 			switch (scp->src_meta.scm_status) {
244c98f5080Sstsp 			case BIOC_SDONLINE:
245c98f5080Sstsp 			case BIOC_SDSCRUB:
246c98f5080Sstsp 				break;
247c98f5080Sstsp 
248c98f5080Sstsp 			case BIOC_SDOFFLINE:
249c98f5080Sstsp 			case BIOC_SDREBUILD:
250c98f5080Sstsp 			case BIOC_SDHOTSPARE:
251c98f5080Sstsp 				if (rt++ < sd->sd_meta->ssdi.ssd_chunk_no)
252c98f5080Sstsp 					goto ragain;
253c98f5080Sstsp 
254c98f5080Sstsp 				/* FALLTHROUGH */
255c98f5080Sstsp 			default:
256c98f5080Sstsp 				/* volume offline */
257c98f5080Sstsp 				printf("%s: is offline, cannot read\n",
258c98f5080Sstsp 				    DEVNAME(sd->sd_sc));
259c98f5080Sstsp 				goto bad;
260c98f5080Sstsp 			}
261c98f5080Sstsp 		} else {
262c98f5080Sstsp 			/* writes go on all working disks */
263c98f5080Sstsp 			chunk = i;
264c98f5080Sstsp 			scp = sd->sd_vol.sv_chunks[chunk];
265c98f5080Sstsp 			switch (scp->src_meta.scm_status) {
266c98f5080Sstsp 			case BIOC_SDONLINE:
267c98f5080Sstsp 				if (ISSET(wu->swu_flags, SR_WUF_REBUILD))
268c98f5080Sstsp 					continue;
269c98f5080Sstsp 				break;
270c98f5080Sstsp 
271c98f5080Sstsp 			case BIOC_SDSCRUB:
272c98f5080Sstsp 			case BIOC_SDREBUILD:
273c98f5080Sstsp 				break;
274c98f5080Sstsp 
275c98f5080Sstsp 			case BIOC_SDHOTSPARE: /* should never happen */
276c98f5080Sstsp 			case BIOC_SDOFFLINE:
277c98f5080Sstsp 				continue;
278c98f5080Sstsp 
279c98f5080Sstsp 			default:
280c98f5080Sstsp 				goto bad;
281c98f5080Sstsp 			}
282c98f5080Sstsp 		}
283c98f5080Sstsp 
284c98f5080Sstsp 		ccb = sr_ccb_rw(sd, chunk, blkno, xs->datalen, xs->data,
285c98f5080Sstsp 		    xs->flags, 0);
286c98f5080Sstsp 		if (!ccb) {
287c98f5080Sstsp 			/* should never happen but handle more gracefully */
288c98f5080Sstsp 			printf("%s: %s: too many ccbs queued\n",
289c98f5080Sstsp 			    DEVNAME(sd->sd_sc),
290c98f5080Sstsp 			    sd->sd_meta->ssd_devname);
291c98f5080Sstsp 			goto bad;
292c98f5080Sstsp 		}
293c98f5080Sstsp 		if (!ISSET(xs->flags, SCSI_DATA_IN) &&
294c98f5080Sstsp 		    !ISSET(wu->swu_flags, SR_WUF_REBUILD)) {
295c98f5080Sstsp 			uio = crwu->cr_crp->crp_buf;
296c98f5080Sstsp 			ccb->ccb_buf.b_data = uio->uio_iov->iov_base;
297c98f5080Sstsp 			ccb->ccb_opaque = crwu;
298c98f5080Sstsp 		}
299c98f5080Sstsp 		sr_wu_enqueue_ccb(wu, ccb);
300c98f5080Sstsp 	}
301c98f5080Sstsp 
302c98f5080Sstsp 	sr_schedule_wu(wu);
303c98f5080Sstsp 
304c98f5080Sstsp 	return (0);
305c98f5080Sstsp 
306c98f5080Sstsp bad:
307*87edded1Stobhe 	return (EINVAL);
308c98f5080Sstsp }
309c98f5080Sstsp 
310c98f5080Sstsp int
sr_raid1c_meta_opt_handler(struct sr_discipline * sd,struct sr_meta_opt_hdr * om)311eb0e73bdSstsp sr_raid1c_meta_opt_handler(struct sr_discipline *sd, struct sr_meta_opt_hdr *om)
312eb0e73bdSstsp {
313eb0e73bdSstsp 	struct sr_raid1c *mdd_raid1c = &sd->mds.mdd_raid1c;
314eb0e73bdSstsp 	return sr_crypto_meta_opt_handler_internal(sd,
315eb0e73bdSstsp 	    &mdd_raid1c->sr1c_crypto, om);
316eb0e73bdSstsp }
317eb0e73bdSstsp 
318eb0e73bdSstsp int
sr_raid1c_rw(struct sr_workunit * wu)319c98f5080Sstsp sr_raid1c_rw(struct sr_workunit *wu)
320c98f5080Sstsp {
321c98f5080Sstsp 	struct sr_crypto_wu	*crwu;
322eb0e73bdSstsp 	struct sr_raid1c	*mdd_raid1c;
323c98f5080Sstsp 	daddr_t			blkno;
324*87edded1Stobhe 	int			rv, err;
325*87edded1Stobhe 	int			s;
326c98f5080Sstsp 
327c98f5080Sstsp 	DNPRINTF(SR_D_DIS, "%s: sr_raid1c_rw wu %p\n",
328c98f5080Sstsp 	    DEVNAME(wu->swu_dis->sd_sc), wu);
329c98f5080Sstsp 
330c98f5080Sstsp 	if (sr_validate_io(wu, &blkno, "sr_raid1c_rw"))
331c98f5080Sstsp 		return (1);
332c98f5080Sstsp 
333c98f5080Sstsp 	if (ISSET(wu->swu_xs->flags, SCSI_DATA_OUT) &&
334c98f5080Sstsp 	    !ISSET(wu->swu_flags, SR_WUF_REBUILD)) {
335eb0e73bdSstsp 		mdd_raid1c = &wu->swu_dis->mds.mdd_raid1c;
336eb0e73bdSstsp 		crwu = sr_crypto_prepare(wu, &mdd_raid1c->sr1c_crypto, 1);
337*87edded1Stobhe 		rv = crypto_invoke(crwu->cr_crp);
338*87edded1Stobhe 
339*87edded1Stobhe 		DNPRINTF(SR_D_INTR, "%s: sr_raid1c_rw: wu %p xs: %p\n",
340*87edded1Stobhe 		    DEVNAME(wu->swu_dis->sd_sc), wu, wu->swu_xs);
341*87edded1Stobhe 
342*87edded1Stobhe 		if (rv) {
343*87edded1Stobhe 			/* fail io */
344*87edded1Stobhe 			wu->swu_xs->error = XS_DRIVER_STUFFUP;
345*87edded1Stobhe 			s = splbio();
346*87edded1Stobhe 			sr_scsi_done(wu->swu_dis, wu->swu_xs);
347*87edded1Stobhe 			splx(s);
348*87edded1Stobhe 		}
349*87edded1Stobhe 
350*87edded1Stobhe 		if ((err = sr_raid1c_dev_rw(wu, crwu)) != 0)
351*87edded1Stobhe 			return (err);
352c98f5080Sstsp 	} else
353c98f5080Sstsp 		rv = sr_raid1c_dev_rw(wu, NULL);
354c98f5080Sstsp 
355c98f5080Sstsp 	return (rv);
356c98f5080Sstsp }
357eb0e73bdSstsp 
358eb0e73bdSstsp void
sr_raid1c_done(struct sr_workunit * wu)359eb0e73bdSstsp sr_raid1c_done(struct sr_workunit *wu)
360eb0e73bdSstsp {
361eb0e73bdSstsp 	struct sr_raid1c *mdd_raid1c = &wu->swu_dis->mds.mdd_raid1c;
362eb0e73bdSstsp 	sr_crypto_done_internal(wu, &mdd_raid1c->sr1c_crypto);
363eb0e73bdSstsp }
364