source: mainline/uspace/srv/bd/hr/raid1.c@ 56214383

Last change on this file since 56214383 was 56214383, checked in by Miroslav Cimerman <mc@…>, 4 months ago

hr: util: hr_util_add_hotspare()

  • Property mode set to 100644
File size: 18.0 KB
Line 
1/*
2 * Copyright (c) 2025 Miroslav Cimerman
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup hr
30 * @{
31 */
32/**
33 * @file
34 */
35
36#include <bd_srv.h>
37#include <block.h>
38#include <errno.h>
39#include <hr.h>
40#include <io/log.h>
41#include <ipc/hr.h>
42#include <ipc/services.h>
43#include <loc.h>
44#include <task.h>
45#include <stdatomic.h>
46#include <stdio.h>
47#include <stdlib.h>
48#include <str_error.h>
49
50#include "fge.h"
51#include "io.h"
52#include "superblock.h"
53#include "util.h"
54#include "var.h"
55
56extern loc_srv_t *hr_srv;
57
58static void hr_raid1_update_vol_status(hr_volume_t *);
59static void hr_raid1_ext_state_callback(hr_volume_t *, size_t, errno_t);
60static size_t hr_raid1_count_good_extents(hr_volume_t *, uint64_t, size_t,
61 uint64_t);
62static errno_t hr_raid1_bd_op(hr_bd_op_type_t, bd_srv_t *, aoff64_t, size_t,
63 void *, const void *, size_t);
64static errno_t hr_raid1_rebuild(void *);
65static errno_t init_rebuild(hr_volume_t *, size_t *);
66static errno_t swap_hs(hr_volume_t *, size_t, size_t);
67static errno_t hr_raid1_restore_blocks(hr_volume_t *, size_t, uint64_t, size_t,
68 void *);
69
70/* bdops */
71static errno_t hr_raid1_bd_open(bd_srvs_t *, bd_srv_t *);
72static errno_t hr_raid1_bd_close(bd_srv_t *);
73static errno_t hr_raid1_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *,
74 size_t);
75static errno_t hr_raid1_bd_sync_cache(bd_srv_t *, aoff64_t, size_t);
76static errno_t hr_raid1_bd_write_blocks(bd_srv_t *, aoff64_t, size_t,
77 const void *, size_t);
78static errno_t hr_raid1_bd_get_block_size(bd_srv_t *, size_t *);
79static errno_t hr_raid1_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
80
81static bd_ops_t hr_raid1_bd_ops = {
82 .open = hr_raid1_bd_open,
83 .close = hr_raid1_bd_close,
84 .sync_cache = hr_raid1_bd_sync_cache,
85 .read_blocks = hr_raid1_bd_read_blocks,
86 .write_blocks = hr_raid1_bd_write_blocks,
87 .get_block_size = hr_raid1_bd_get_block_size,
88 .get_num_blocks = hr_raid1_bd_get_num_blocks
89};
90
91errno_t hr_raid1_create(hr_volume_t *new_volume)
92{
93 assert(new_volume->level == HR_LVL_1);
94
95 if (new_volume->extent_no < 2) {
96 HR_ERROR("RAID 1 array needs at least 2 devices\n");
97 return EINVAL;
98 }
99
100 bd_srvs_init(&new_volume->hr_bds);
101 new_volume->hr_bds.ops = &hr_raid1_bd_ops;
102 new_volume->hr_bds.sarg = new_volume;
103
104 /* force volume state update */
105 hr_mark_vol_state_dirty(new_volume);
106 hr_raid1_update_vol_status(new_volume);
107
108 fibril_rwlock_read_lock(&new_volume->states_lock);
109 hr_vol_status_t state = new_volume->status;
110 fibril_rwlock_read_unlock(&new_volume->states_lock);
111 if (state == HR_VOL_FAULTY || state == HR_VOL_NONE)
112 return EINVAL;
113
114 return EOK;
115}
116
117errno_t hr_raid1_init(hr_volume_t *vol)
118{
119 errno_t rc;
120 size_t bsize;
121 uint64_t total_blkno;
122
123 assert(vol->level == HR_LVL_1);
124
125 rc = hr_check_devs(vol, &total_blkno, &bsize);
126 if (rc != EOK)
127 return rc;
128
129 vol->nblocks = total_blkno / vol->extent_no;
130 vol->bsize = bsize;
131 vol->data_offset = HR_DATA_OFF;
132 vol->data_blkno = vol->nblocks - vol->data_offset;
133 vol->strip_size = 0;
134
135 return EOK;
136}
137
138void hr_raid1_status_event(hr_volume_t *vol)
139{
140 hr_raid1_update_vol_status(vol);
141}
142
143errno_t hr_raid1_add_hotspare(hr_volume_t *vol, service_id_t hotspare)
144{
145 HR_DEBUG("%s()", __func__);
146
147 errno_t rc = hr_util_add_hotspare(vol, hotspare);
148
149 hr_raid1_update_vol_status(vol);
150
151 return rc;
152}
153
154static errno_t hr_raid1_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
155{
156 HR_DEBUG("%s()", __func__);
157
158 hr_volume_t *vol = bd->srvs->sarg;
159
160 atomic_fetch_add_explicit(&vol->open_cnt, 1, memory_order_relaxed);
161
162 return EOK;
163}
164
165static errno_t hr_raid1_bd_close(bd_srv_t *bd)
166{
167 HR_DEBUG("%s()", __func__);
168
169 hr_volume_t *vol = bd->srvs->sarg;
170
171 atomic_fetch_sub_explicit(&vol->open_cnt, 1, memory_order_relaxed);
172
173 return EOK;
174}
175
176static errno_t hr_raid1_bd_sync_cache(bd_srv_t *bd, aoff64_t ba, size_t cnt)
177{
178 return hr_raid1_bd_op(HR_BD_SYNC, bd, ba, cnt, NULL, NULL, 0);
179}
180
181static errno_t hr_raid1_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
182 void *buf, size_t size)
183{
184 return hr_raid1_bd_op(HR_BD_READ, bd, ba, cnt, buf, NULL, size);
185}
186
187static errno_t hr_raid1_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
188 const void *data, size_t size)
189{
190 return hr_raid1_bd_op(HR_BD_WRITE, bd, ba, cnt, NULL, data, size);
191}
192
193static errno_t hr_raid1_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
194{
195 hr_volume_t *vol = bd->srvs->sarg;
196
197 *rsize = vol->bsize;
198 return EOK;
199}
200
201static errno_t hr_raid1_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
202{
203 hr_volume_t *vol = bd->srvs->sarg;
204
205 *rnb = vol->data_blkno;
206 return EOK;
207}
208
209static void hr_raid1_update_vol_status(hr_volume_t *vol)
210{
211 bool exp = true;
212
213 /* TODO: could also wrap this */
214 if (!atomic_compare_exchange_strong(&vol->state_dirty, &exp, false))
215 return;
216
217 fibril_rwlock_read_lock(&vol->extents_lock);
218 fibril_rwlock_read_lock(&vol->states_lock);
219
220 hr_vol_status_t old_state = vol->status;
221 size_t healthy = hr_count_extents(vol, HR_EXT_ONLINE);
222
223 fibril_rwlock_read_unlock(&vol->states_lock);
224 fibril_rwlock_read_unlock(&vol->extents_lock);
225
226 if (healthy == 0) {
227 if (old_state != HR_VOL_FAULTY) {
228 fibril_rwlock_write_lock(&vol->states_lock);
229 hr_update_vol_status(vol, HR_VOL_FAULTY);
230 fibril_rwlock_write_unlock(&vol->states_lock);
231 }
232 } else if (healthy < vol->extent_no) {
233 if (old_state != HR_VOL_REBUILD &&
234 old_state != HR_VOL_DEGRADED) {
235 fibril_rwlock_write_lock(&vol->states_lock);
236 hr_update_vol_status(vol, HR_VOL_DEGRADED);
237 fibril_rwlock_write_unlock(&vol->states_lock);
238 }
239
240 if (old_state != HR_VOL_REBUILD) {
241 if (vol->hotspare_no > 0) {
242 fid_t fib = fibril_create(hr_raid1_rebuild,
243 vol);
244 if (fib == 0)
245 return;
246 fibril_start(fib);
247 fibril_detach(fib);
248 }
249 }
250 } else {
251 if (old_state != HR_VOL_ONLINE) {
252 fibril_rwlock_write_lock(&vol->states_lock);
253 hr_update_vol_status(vol, HR_VOL_ONLINE);
254 fibril_rwlock_write_unlock(&vol->states_lock);
255 }
256 }
257}
258
259static void hr_raid1_ext_state_callback(hr_volume_t *vol, size_t extent,
260 errno_t rc)
261{
262 if (rc == EOK)
263 return;
264
265 assert(fibril_rwlock_is_locked(&vol->extents_lock));
266
267 fibril_rwlock_write_lock(&vol->states_lock);
268
269 switch (rc) {
270 case ENOMEM:
271 hr_update_ext_status(vol, extent, HR_EXT_INVALID);
272 break;
273 case ENOENT:
274 hr_update_ext_status(vol, extent, HR_EXT_MISSING);
275 break;
276 default:
277 hr_update_ext_status(vol, extent, HR_EXT_FAILED);
278 }
279
280 hr_mark_vol_state_dirty(vol);
281
282 fibril_rwlock_write_unlock(&vol->states_lock);
283}
284
285static size_t hr_raid1_count_good_extents(hr_volume_t *vol, uint64_t ba,
286 size_t cnt, uint64_t rebuild_blk)
287{
288 assert(fibril_rwlock_is_locked(&vol->extents_lock));
289 assert(fibril_rwlock_is_locked(&vol->states_lock));
290
291 size_t count = 0;
292 for (size_t i = 0; i < vol->extent_no; i++) {
293 if (vol->extents[i].status == HR_EXT_ONLINE ||
294 (vol->extents[i].status == HR_EXT_REBUILD &&
295 ba < rebuild_blk)) {
296 count++;
297 }
298 }
299
300 return count;
301
302}
303
304static errno_t hr_raid1_bd_op(hr_bd_op_type_t type, bd_srv_t *bd, aoff64_t ba,
305 size_t cnt, void *data_read, const void *data_write, size_t size)
306{
307 hr_volume_t *vol = bd->srvs->sarg;
308 hr_range_lock_t *rl = NULL;
309 errno_t rc;
310 size_t i;
311 uint64_t rebuild_blk;
312
313 fibril_rwlock_read_lock(&vol->states_lock);
314 hr_vol_status_t vol_state = vol->status;
315 fibril_rwlock_read_unlock(&vol->states_lock);
316
317 if (vol_state == HR_VOL_FAULTY || vol_state == HR_VOL_NONE)
318 return EIO;
319
320 if (type == HR_BD_READ || type == HR_BD_WRITE)
321 if (size < cnt * vol->bsize)
322 return EINVAL;
323
324 rc = hr_check_ba_range(vol, cnt, ba);
325 if (rc != EOK)
326 return rc;
327
328 /* allow full dev sync */
329 if (type != HR_BD_SYNC || ba != 0)
330 hr_add_ba_offset(vol, &ba);
331
332 /*
333 * extent order has to be locked for the whole IO duration,
334 * so that workers have consistent targets
335 */
336 fibril_rwlock_read_lock(&vol->extents_lock);
337
338 size_t successful = 0;
339 switch (type) {
340 case HR_BD_READ:
341 rebuild_blk = atomic_load_explicit(&vol->rebuild_blk,
342 memory_order_relaxed);
343
344 for (i = 0; i < vol->extent_no; i++) {
345 fibril_rwlock_read_lock(&vol->states_lock);
346 hr_ext_status_t state = vol->extents[i].status;
347 fibril_rwlock_read_unlock(&vol->states_lock);
348
349 if (state != HR_EXT_ONLINE &&
350 (state != HR_EXT_REBUILD ||
351 ba + cnt - 1 >= rebuild_blk)) {
352 continue;
353 }
354
355 rc = block_read_direct(vol->extents[i].svc_id, ba, cnt,
356 data_read);
357
358 if (rc == ENOMEM && i + 1 == vol->extent_no)
359 goto end;
360
361 if (rc == ENOMEM)
362 continue;
363
364 if (rc != EOK) {
365 hr_raid1_ext_state_callback(vol, i, rc);
366 } else {
367 successful++;
368 break;
369 }
370 }
371 break;
372 case HR_BD_SYNC:
373 case HR_BD_WRITE:
374 if (type == HR_BD_WRITE) {
375 rl = hr_range_lock_acquire(vol, ba, cnt);
376 if (rl == NULL) {
377 rc = ENOMEM;
378 goto end;
379 }
380 }
381
382 fibril_rwlock_read_lock(&vol->states_lock);
383
384 rebuild_blk = atomic_load_explicit(&vol->rebuild_blk,
385 memory_order_relaxed);
386
387 size_t good = hr_raid1_count_good_extents(vol, ba, cnt,
388 rebuild_blk);
389
390 hr_fgroup_t *group = hr_fgroup_create(vol->fge, good);
391 if (group == NULL) {
392 if (type == HR_BD_WRITE)
393 hr_range_lock_release(rl);
394 rc = ENOMEM;
395 fibril_rwlock_read_unlock(&vol->states_lock);
396 goto end;
397 }
398
399 for (i = 0; i < vol->extent_no; i++) {
400 if (vol->extents[i].status != HR_EXT_ONLINE &&
401 (vol->extents[i].status != HR_EXT_REBUILD ||
402 ba >= rebuild_blk)) {
403 /*
404 * When the extent is being rebuilt,
405 * we only write to the part that is already
406 * rebuilt. If IO starts after vol->rebuild_blk
407 * we do not proceed, the write is going to
408 * be replicated later in the rebuild.
409 */
410 continue;
411 }
412
413 hr_io_t *io = hr_fgroup_alloc(group);
414 io->extent = i;
415 io->data_write = data_write;
416 io->data_read = data_read;
417 io->ba = ba;
418 io->cnt = cnt;
419 io->type = type;
420 io->vol = vol;
421 io->state_callback = hr_raid1_ext_state_callback;
422
423 hr_fgroup_submit(group, hr_io_worker, io);
424 }
425
426 fibril_rwlock_read_unlock(&vol->states_lock);
427
428 (void)hr_fgroup_wait(group, &successful, NULL);
429
430 if (type == HR_BD_WRITE)
431 hr_range_lock_release(rl);
432
433 break;
434 default:
435 rc = EINVAL;
436 goto end;
437 }
438
439 if (successful > 0)
440 rc = EOK;
441 else
442 rc = EIO;
443
444end:
445 fibril_rwlock_read_unlock(&vol->extents_lock);
446
447 hr_raid1_update_vol_status(vol);
448
449 return rc;
450}
451
452/*
453 * Put the last HOTSPARE extent in place
454 * of first that != ONLINE, and start the rebuild.
455 */
456static errno_t hr_raid1_rebuild(void *arg)
457{
458 HR_DEBUG("%s()", __func__);
459
460 hr_volume_t *vol = arg;
461 void *buf = NULL;
462 size_t rebuild_idx;
463 errno_t rc;
464
465 rc = init_rebuild(vol, &rebuild_idx);
466 if (rc != EOK)
467 return rc;
468
469 size_t left = vol->data_blkno;
470 size_t max_blks = DATA_XFER_LIMIT / vol->bsize;
471 buf = malloc(max_blks * vol->bsize);
472
473 size_t cnt;
474 uint64_t ba = 0;
475 hr_add_ba_offset(vol, &ba);
476
477 /*
478 * XXX: this is useless here after simplified DI, because
479 * rebuild cannot be triggered while ongoing rebuild
480 */
481 fibril_rwlock_read_lock(&vol->extents_lock);
482
483 hr_range_lock_t *rl = NULL;
484
485 unsigned int percent, old_percent = 100;
486 while (left != 0) {
487 cnt = min(max_blks, left);
488
489 rl = hr_range_lock_acquire(vol, ba, cnt);
490 if (rl == NULL) {
491 rc = ENOMEM;
492 goto end;
493 }
494
495 atomic_store_explicit(&vol->rebuild_blk, ba,
496 memory_order_relaxed);
497
498 rc = hr_raid1_restore_blocks(vol, rebuild_idx, ba, cnt, buf);
499
500 percent = ((ba + cnt) * 100) / vol->data_blkno;
501 if (percent != old_percent) {
502 if (percent % 5 == 0)
503 HR_DEBUG("\"%s\" REBUILD progress: %u%%\n",
504 vol->devname, percent);
505 }
506
507 hr_range_lock_release(rl);
508
509 if (rc != EOK)
510 goto end;
511
512 ba += cnt;
513 left -= cnt;
514 old_percent = percent;
515 }
516
517 HR_DEBUG("hr_raid1_rebuild(): rebuild finished on \"%s\" (%lu), "
518 "extent no. %lu\n", vol->devname, vol->svc_id, rebuild_idx);
519
520 fibril_rwlock_write_lock(&vol->states_lock);
521
522 hr_update_ext_status(vol, rebuild_idx, HR_EXT_ONLINE);
523
524 /*
525 * We can be optimistic here, if some extents are
526 * still INVALID, FAULTY or MISSING, the update vol
527 * function will pick them up, and set the volume
528 * state accordingly.
529 */
530 hr_update_vol_status(vol, HR_VOL_ONLINE);
531 hr_mark_vol_state_dirty(vol);
532
533 fibril_rwlock_write_unlock(&vol->states_lock);
534
535 /*
536 * For now write metadata at the end, because
537 * we don't sync metada accross extents yet.
538 */
539 hr_write_meta_to_ext(vol, rebuild_idx);
540end:
541 if (rc != EOK) {
542 /*
543 * We can fail either because:
544 * - the rebuild extent failing or invalidation
545 * - there is are no ONLINE extents (vol is FAULTY)
546 * - we got ENOMEM on all READs (we also invalidate the
547 * rebuild extent here, for now)
548 */
549 fibril_rwlock_write_lock(&vol->states_lock);
550 hr_update_vol_status(vol, HR_VOL_DEGRADED);
551 hr_mark_vol_state_dirty(vol);
552 fibril_rwlock_write_unlock(&vol->states_lock);
553 }
554
555 fibril_rwlock_read_unlock(&vol->extents_lock);
556
557 hr_raid1_update_vol_status(vol);
558
559 if (buf != NULL)
560 free(buf);
561
562 return rc;
563}
564
565static errno_t init_rebuild(hr_volume_t *vol, size_t *rebuild_idx)
566{
567 errno_t rc = EOK;
568
569 fibril_rwlock_write_lock(&vol->extents_lock);
570 fibril_rwlock_write_lock(&vol->states_lock);
571 fibril_mutex_lock(&vol->hotspare_lock);
572
573 if (vol->hotspare_no == 0) {
574 HR_WARN("hr_raid1_rebuild(): no free hotspares on \"%s\", "
575 "aborting rebuild\n", vol->devname);
576 rc = EINVAL;
577 goto error;
578 }
579
580 size_t bad = vol->extent_no;
581 for (size_t i = 0; i < vol->extent_no; i++) {
582 if (vol->extents[i].status != HR_EXT_ONLINE) {
583 bad = i;
584 break;
585 }
586 }
587
588 if (bad == vol->extent_no) {
589 HR_WARN("hr_raid1_rebuild(): no bad extent on \"%s\", "
590 "aborting rebuild\n", vol->devname);
591 rc = EINVAL;
592 goto error;
593 }
594
595 size_t hotspare_idx = vol->hotspare_no - 1;
596
597 hr_ext_status_t hs_state = vol->hotspares[hotspare_idx].status;
598 if (hs_state != HR_EXT_HOTSPARE) {
599 HR_ERROR("hr_raid1_rebuild(): invalid hotspare state \"%s\", "
600 "aborting rebuild\n", hr_get_ext_status_msg(hs_state));
601 rc = EINVAL;
602 goto error;
603 }
604
605 rc = swap_hs(vol, bad, hotspare_idx);
606 if (rc != EOK) {
607 HR_ERROR("hr_raid1_rebuild(): swapping hotspare failed, "
608 "aborting rebuild\n");
609 goto error;
610 }
611
612 hr_extent_t *rebuild_ext = &vol->extents[bad];
613
614 HR_DEBUG("hr_raid1_rebuild(): starting REBUILD on extent no. %lu (%lu)"
615 "\n", bad, rebuild_ext->svc_id);
616
617 atomic_store_explicit(&vol->rebuild_blk, 0, memory_order_relaxed);
618
619 hr_update_ext_status(vol, bad, HR_EXT_REBUILD);
620 hr_update_vol_status(vol, HR_VOL_REBUILD);
621
622 *rebuild_idx = bad;
623error:
624 fibril_mutex_unlock(&vol->hotspare_lock);
625 fibril_rwlock_write_unlock(&vol->states_lock);
626 fibril_rwlock_write_unlock(&vol->extents_lock);
627
628 return rc;
629}
630
631static errno_t swap_hs(hr_volume_t *vol, size_t bad, size_t hs)
632{
633 HR_DEBUG("hr_raid1_rebuild(): swapping in hotspare\n");
634
635 service_id_t faulty_svc_id = vol->extents[bad].svc_id;
636 service_id_t hs_svc_id = vol->hotspares[hs].svc_id;
637
638 hr_update_ext_svc_id(vol, bad, hs_svc_id);
639 hr_update_ext_status(vol, bad, HR_EXT_HOTSPARE);
640
641 hr_update_hotspare_svc_id(vol, hs, 0);
642 hr_update_hotspare_status(vol, hs, HR_EXT_MISSING);
643
644 vol->hotspare_no--;
645
646 if (faulty_svc_id != 0)
647 block_fini(faulty_svc_id);
648
649 return EOK;
650}
651
652static errno_t hr_raid1_restore_blocks(hr_volume_t *vol, size_t rebuild_idx,
653 uint64_t ba, size_t cnt, void *buf)
654{
655 assert(fibril_rwlock_is_locked(&vol->extents_lock));
656
657 errno_t rc = ENOENT;
658 hr_extent_t *ext, *rebuild_ext = &vol->extents[rebuild_idx];
659
660 fibril_rwlock_read_lock(&vol->states_lock);
661 hr_ext_status_t rebuild_ext_status = rebuild_ext->status;
662 fibril_rwlock_read_unlock(&vol->states_lock);
663
664 if (rebuild_ext_status != HR_EXT_REBUILD)
665 return EINVAL;
666
667 for (size_t i = 0; i < vol->extent_no; i++) {
668 fibril_rwlock_read_lock(&vol->states_lock);
669 ext = &vol->extents[i];
670 if (ext->status != HR_EXT_ONLINE) {
671 fibril_rwlock_read_unlock(&vol->states_lock);
672 continue;
673 }
674 fibril_rwlock_read_unlock(&vol->states_lock);
675
676 rc = block_read_direct(ext->svc_id, ba, cnt, buf);
677 if (rc == EOK)
678 break;
679
680 if (rc != ENOMEM)
681 hr_raid1_ext_state_callback(vol, i, rc);
682
683 if (i + 1 >= vol->extent_no) {
684 if (rc != ENOMEM) {
685 HR_ERROR("rebuild on \"%s\" (%lu), failed due "
686 "to too many failed extents\n",
687 vol->devname, vol->svc_id);
688 }
689
690 /* for now we have to invalidate the rebuild extent */
691 if (rc == ENOMEM) {
692 HR_ERROR("rebuild on \"%s\" (%lu), failed due "
693 "to too many failed reads, because of not "
694 "enough memory\n",
695 vol->devname, vol->svc_id);
696 hr_raid1_ext_state_callback(vol, rebuild_idx,
697 ENOMEM);
698 }
699
700 return rc;
701 }
702 }
703
704 rc = block_write_direct(rebuild_ext->svc_id, ba, cnt, buf);
705 if (rc != EOK) {
706 /*
707 * Here we dont handle ENOMEM, because maybe in the
708 * future, there is going to be M_WAITOK, or we are
709 * going to wait for more memory, so that we don't
710 * have to invalidate it...
711 *
712 * XXX: for now we do
713 */
714 hr_raid1_ext_state_callback(vol, rebuild_idx, rc);
715
716 HR_ERROR("rebuild on \"%s\" (%lu), failed due to "
717 "the rebuilt extent no. %lu WRITE (rc: %s)\n",
718 vol->devname, vol->svc_id, rebuild_idx, str_error(rc));
719
720 return rc;
721 }
722
723 return EOK;
724}
725
726/** @}
727 */
Note: See TracBrowser for help on using the repository browser.