Lines Matching +full:no +full:- +full:wp

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
57 struct gv_raid5_packet *wp, *wp2; in gv_raid5_start() local
62 wp = g_malloc(sizeof(*wp), M_WAITOK | M_ZERO); in gv_raid5_start()
63 wp->bio = bp; in gv_raid5_start()
64 wp->waiting = NULL; in gv_raid5_start()
65 wp->parity = NULL; in gv_raid5_start()
66 TAILQ_INIT(&wp->bits); in gv_raid5_start()
68 if (bp->bio_pflags & GV_BIO_REBUILD) in gv_raid5_start()
69 err = gv_raid5_rebuild(p, wp, bp, addr, boff, bcount); in gv_raid5_start()
70 else if (bp->bio_pflags & GV_BIO_CHECK) in gv_raid5_start()
71 err = gv_raid5_check(p, wp, bp, addr, boff, bcount); in gv_raid5_start()
73 err = gv_raid5_request(p, wp, bp, addr, boff, bcount, &delay); in gv_raid5_start()
77 g_free(wp); in gv_raid5_start()
82 * Building the sub-request failed, we probably need to clean up a lot. in gv_raid5_start()
86 TAILQ_FOREACH_SAFE(bq, &wp->bits, queue, bq2) { in gv_raid5_start()
87 TAILQ_REMOVE(&wp->bits, bq, queue); in gv_raid5_start()
90 if (wp->waiting != NULL) { in gv_raid5_start()
91 if (wp->waiting->bio_cflags & GV_BIO_MALLOC) in gv_raid5_start()
92 g_free(wp->waiting->bio_data); in gv_raid5_start()
93 gv_drive_done(wp->waiting->bio_caller1); in gv_raid5_start()
94 g_destroy_bio(wp->waiting); in gv_raid5_start()
96 if (wp->parity != NULL) { in gv_raid5_start()
97 if (wp->parity->bio_cflags & GV_BIO_MALLOC) in gv_raid5_start()
98 g_free(wp->parity->bio_data); in gv_raid5_start()
99 gv_drive_done(wp->parity->bio_caller1); in gv_raid5_start()
100 g_destroy_bio(wp->parity); in gv_raid5_start()
102 g_free(wp); in gv_raid5_start()
104 TAILQ_FOREACH_SAFE(wp, &p->packets, list, wp2) { in gv_raid5_start()
105 if (wp->bio != bp) in gv_raid5_start()
108 TAILQ_REMOVE(&p->packets, wp, list); in gv_raid5_start()
109 TAILQ_FOREACH_SAFE(bq, &wp->bits, queue, bq2) { in gv_raid5_start()
110 TAILQ_REMOVE(&wp->bits, bq, queue); in gv_raid5_start()
113 g_free(wp); in gv_raid5_start()
116 cbp = bioq_takefirst(p->bqueue); in gv_raid5_start()
118 if (cbp->bio_cflags & GV_BIO_MALLOC) in gv_raid5_start()
119 g_free(cbp->bio_data); in gv_raid5_start()
120 gv_drive_done(cbp->bio_caller1); in gv_raid5_start()
122 cbp = bioq_takefirst(p->bqueue); in gv_raid5_start()
126 if (bp->bio_pflags & GV_BIO_INTERNAL) { in gv_raid5_start()
127 if (bp->bio_pflags & GV_BIO_MALLOC) in gv_raid5_start()
128 g_free(bp->bio_data); in gv_raid5_start()
131 p->flags &= ~(GV_PLEX_SYNCING | GV_PLEX_REBUILDING | in gv_raid5_start()
139 return (wp); in gv_raid5_start()
149 struct gv_raid5_packet *wp, *owp; in gv_stripe_active() local
152 wp = bp->bio_caller2; in gv_stripe_active()
153 if (wp->lockbase == -1) in gv_stripe_active()
157 TAILQ_FOREACH(owp, &p->packets, list) { in gv_stripe_active()
158 if (owp == wp) in gv_stripe_active()
160 if ((wp->lockbase >= owp->lockbase) && in gv_stripe_active()
161 (wp->lockbase <= owp->lockbase + owp->length)) { in gv_stripe_active()
165 if ((wp->lockbase <= owp->lockbase) && in gv_stripe_active()
166 (wp->lockbase + wp->length >= owp->lockbase)) { in gv_stripe_active()
176 gv_raid5_check(struct gv_plex *p, struct gv_raid5_packet *wp, struct bio *bp, in gv_raid5_check() argument
185 if (p == NULL || LIST_EMPTY(&p->subdisks)) in gv_raid5_check()
193 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_check()
205 if (parity->state != GV_SD_UP) in gv_raid5_check()
208 wp->length = real_len; in gv_raid5_check()
209 wp->data = addr; in gv_raid5_check()
210 wp->lockbase = real_off; in gv_raid5_check()
213 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_check()
218 if (s->flags & GV_SD_GROW) in gv_raid5_check()
221 cbp = gv_raid5_clone_bio(bp, s, wp, NULL, 1); in gv_raid5_check()
224 cbp->bio_cmd = BIO_READ; in gv_raid5_check()
226 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_check()
229 bq->bp = cbp; in gv_raid5_check()
230 TAILQ_INSERT_TAIL(&wp->bits, bq, queue); in gv_raid5_check()
234 cbp = gv_raid5_clone_bio(bp, parity, wp, NULL, 1); in gv_raid5_check()
237 cbp->bio_cmd = BIO_READ; in gv_raid5_check()
238 wp->waiting = cbp; in gv_raid5_check()
244 cbp = gv_raid5_clone_bio(bp, parity, wp, addr, 1); in gv_raid5_check()
247 wp->parity = cbp; in gv_raid5_check()
254 gv_raid5_rebuild(struct gv_plex *p, struct gv_raid5_packet *wp, struct bio *bp, in gv_raid5_rebuild() argument
262 if (p == NULL || LIST_EMPTY(&p->subdisks)) in gv_raid5_rebuild()
269 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_rebuild()
270 if (s->state != GV_SD_UP) in gv_raid5_rebuild()
278 switch (broken->state) { in gv_raid5_rebuild()
283 if (!(bp->bio_pflags & GV_BIO_REBUILD)) in gv_raid5_rebuild()
286 G_VINUM_DEBUG(1, "sd %s is reviving", broken->name); in gv_raid5_rebuild()
289 broken->flags |= GV_SD_CANGOUP; in gv_raid5_rebuild()
300 wp->length = real_len; in gv_raid5_rebuild()
301 wp->data = addr; in gv_raid5_rebuild()
302 wp->lockbase = real_off; in gv_raid5_rebuild()
304 KASSERT(wp->length >= 0, ("gv_rebuild_raid5: wp->length < 0")); in gv_raid5_rebuild()
307 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_rebuild()
313 if (s->flags & GV_SD_GROW) in gv_raid5_rebuild()
316 cbp = gv_raid5_clone_bio(bp, s, wp, NULL, 1); in gv_raid5_rebuild()
319 cbp->bio_cmd = BIO_READ; in gv_raid5_rebuild()
321 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_rebuild()
324 bq->bp = cbp; in gv_raid5_rebuild()
325 TAILQ_INSERT_TAIL(&wp->bits, bq, queue); in gv_raid5_rebuild()
329 cbp = gv_raid5_clone_bio(bp, broken, wp, NULL, 1); in gv_raid5_rebuild()
332 wp->parity = cbp; in gv_raid5_rebuild()
334 p->synced = boff; in gv_raid5_rebuild()
342 gv_raid5_request(struct gv_plex *p, struct gv_raid5_packet *wp, in gv_raid5_request() argument
351 if (p == NULL || LIST_EMPTY(&p->subdisks)) in gv_raid5_request()
367 if (boff >= p->synced) { in gv_raid5_request()
370 } else if (boff + bcount <= p->synced) { in gv_raid5_request()
374 bioq_disksort(p->rqueue, bp); in gv_raid5_request()
383 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_request()
388 if (s->state != GV_SD_UP) in gv_raid5_request()
397 if (original->state != GV_SD_UP) in gv_raid5_request()
401 if (original->state == GV_SD_STALE && parity->state == GV_SD_STALE && in gv_raid5_request()
402 bp->bio_pflags & GV_BIO_SYNCREQ && bp->bio_cmd == BIO_WRITE) { in gv_raid5_request()
405 } else if (parity->state != GV_SD_UP) { in gv_raid5_request()
413 wp->length = real_len; in gv_raid5_request()
414 wp->data = addr; in gv_raid5_request()
415 wp->lockbase = real_off; in gv_raid5_request()
417 KASSERT(wp->length >= 0, ("gv_build_raid5_request: wp->length < 0")); in gv_raid5_request()
419 if ((p->flags & GV_PLEX_REBUILDING) && (boff + real_len < p->synced)) in gv_raid5_request()
422 if ((p->flags & GV_PLEX_REBUILDING) && (boff + real_len >= p->synced)) { in gv_raid5_request()
423 bioq_disksort(p->rqueue, bp); in gv_raid5_request()
428 switch (bp->bio_cmd) { in gv_raid5_request()
436 bzero(wp->data, wp->length); in gv_raid5_request()
437 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_request()
442 if (grow && s->flags & GV_SD_GROW) in gv_raid5_request()
444 cbp = gv_raid5_clone_bio(bp, s, wp, NULL, 1); in gv_raid5_request()
448 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_request()
451 bq->bp = cbp; in gv_raid5_request()
452 TAILQ_INSERT_TAIL(&wp->bits, bq, queue); in gv_raid5_request()
457 cbp = gv_raid5_clone_bio(bp, original, wp, addr, 0); in gv_raid5_request()
461 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_request()
463 wp->lockbase = -1; in gv_raid5_request()
476 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_request()
481 if (grow && s->flags & GV_SD_GROW) in gv_raid5_request()
484 cbp = gv_raid5_clone_bio(bp, s, wp, NULL, 1); in gv_raid5_request()
487 cbp->bio_cmd = BIO_READ; in gv_raid5_request()
489 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_request()
492 bq->bp = cbp; in gv_raid5_request()
493 TAILQ_INSERT_TAIL(&wp->bits, bq, queue); in gv_raid5_request()
497 cbp = gv_raid5_clone_bio(bp, parity, wp, NULL, 1); in gv_raid5_request()
500 bcopy(addr, cbp->bio_data, wp->length); in gv_raid5_request()
501 wp->parity = cbp; in gv_raid5_request()
507 cbp = gv_raid5_clone_bio(bp, original, wp, addr, 1); in gv_raid5_request()
511 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_request()
514 bq->bp = cbp; in gv_raid5_request()
515 TAILQ_INSERT_TAIL(&wp->bits, bq, queue); in gv_raid5_request()
524 cbp = gv_raid5_clone_bio(bp, parity, wp, NULL, 1); in gv_raid5_request()
527 cbp->bio_cmd = BIO_READ; in gv_raid5_request()
529 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_request()
532 bq->bp = cbp; in gv_raid5_request()
533 TAILQ_INSERT_TAIL(&wp->bits, bq, queue); in gv_raid5_request()
536 cbp = gv_raid5_clone_bio(bp, original, wp, NULL, 1); in gv_raid5_request()
539 cbp->bio_cmd = BIO_READ; in gv_raid5_request()
541 bioq_insert_tail(p->bqueue, cbp); in gv_raid5_request()
544 bq->bp = cbp; in gv_raid5_request()
545 TAILQ_INSERT_TAIL(&wp->bits, bq, queue); in gv_raid5_request()
548 cbp = gv_raid5_clone_bio(bp, original, wp, addr, 1); in gv_raid5_request()
557 wp->waiting = cbp; in gv_raid5_request()
560 cbp = gv_raid5_clone_bio(bp, parity, wp, NULL, 1); in gv_raid5_request()
565 wp->parity = cbp; in gv_raid5_request()
591 sdcount = p->sdcount; in gv_raid5_offset()
593 LIST_FOREACH(s, &p->subdisks, in_plex) { in gv_raid5_offset()
594 if (s->flags & GV_SD_GROW) in gv_raid5_offset()
595 sdcount--; in gv_raid5_offset()
600 psd = sdcount - 1 - ( boff / (p->stripesize * (sdcount - 1))) % in gv_raid5_offset()
605 stripeoff = boff % (p->stripesize * (sdcount - 1)); in gv_raid5_offset()
609 sd = stripeoff / p->stripesize; in gv_raid5_offset()
617 stripestart = (boff - stripeoff) / (sdcount - 1); in gv_raid5_offset()
620 stripeoff %= p->stripesize; in gv_raid5_offset()
625 stripeend = stripestart + p->stripesize; in gv_raid5_offset()
626 len_left = stripeend - *real_off; in gv_raid5_offset()
640 gv_raid5_clone_bio(struct bio *bp, struct gv_sd *s, struct gv_raid5_packet *wp, in gv_raid5_clone_bio() argument
649 cbp->bio_data = g_malloc(wp->length, M_WAITOK | M_ZERO); in gv_raid5_clone_bio()
650 cbp->bio_cflags |= GV_BIO_MALLOC; in gv_raid5_clone_bio()
652 cbp->bio_data = addr; in gv_raid5_clone_bio()
653 cbp->bio_offset = wp->lockbase + s->drive_offset; in gv_raid5_clone_bio()
654 cbp->bio_length = wp->length; in gv_raid5_clone_bio()
655 cbp->bio_done = gv_done; in gv_raid5_clone_bio()
656 cbp->bio_caller1 = s; in gv_raid5_clone_bio()
657 s->drive_sc->active++; in gv_raid5_clone_bio()
659 cbp->bio_caller2 = wp; in gv_raid5_clone_bio()