Changeset a0c3080 in mainline for uspace/srv/bd/hr/raid1.c


Ignore:
Timestamp:
2024-11-28T17:09:52Z (15 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
586b39d
Parents:
65706f1
Message:

hr: util: hotspare and volume change state functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/raid1.c

    r65706f1 ra0c3080  
    147147
    148148        vol->hotspares[vol->hotspare_no].svc_id = hotspare;
    149         vol->hotspares[vol->hotspare_no].status = HR_EXT_HOTSPARE;
     149        hr_update_hotspare_status(vol, vol->hotspare_no, HR_EXT_HOTSPARE);
     150
    150151        vol->hotspare_no++;
    151152
     
    158159                fid_t fib = fibril_create(hr_raid1_rebuild, vol);
    159160                if (fib == 0)
    160                         return EINVAL;
     161                        return ENOMEM;
    161162                fibril_start(fib);
    162163                fibril_detach(fib);
     
    219220            vol->status == HR_VOL_REBUILD)
    220221                return EOK;
    221         return EINVAL;
     222        return EIO;
    222223}
    223224
     
    232233
    233234        if (healthy == 0) {
    234                 if (old_state != HR_VOL_FAULTY) {
    235                         HR_WARN("RAID 1 needs at least 1 extent to be"
    236                             "ONLINE, marking \"%s\" (%lu) volume as FAULTY",
    237                             vol->devname, vol->svc_id);
    238                         vol->status = HR_VOL_FAULTY;
    239                 }
    240                 return EINVAL;
     235                if (old_state != HR_VOL_FAULTY)
     236                        hr_update_vol_status(vol, HR_VOL_FAULTY);
     237                return EIO;
    241238        } else if (healthy < vol->extent_no) {
    242239                if (old_state != HR_VOL_DEGRADED &&
    243240                    old_state != HR_VOL_REBUILD) {
    244                         HR_WARN("RAID 1 array \"%s\" (%lu) has some "
    245                             "unusable extent(s), marking volume as DEGRADED",
    246                             vol->devname, vol->svc_id);
    247                         vol->status = HR_VOL_DEGRADED;
     241
     242                        hr_update_vol_status(vol, HR_VOL_DEGRADED);
     243
    248244                        if (vol->hotspare_no > 0) {
    249245                                fid_t fib = fibril_create(hr_raid1_rebuild,
    250246                                    vol);
    251                                 if (fib == 0) {
    252                                         return EINVAL;
    253                                 }
     247                                if (fib == 0)
     248                                        return ENOMEM;
    254249                                fibril_start(fib);
    255250                                fibril_detach(fib);
     
    258253                return EOK;
    259254        } else {
    260                 if (old_state != HR_VOL_ONLINE) {
    261                         HR_WARN("RAID 1 array \"%s\" (%lu) has all extents "
    262                             "active, marking volume as ONLINE",
    263                             vol->devname, vol->svc_id);
    264                         vol->status = HR_VOL_ONLINE;
    265                 }
     255                if (old_state != HR_VOL_ONLINE)
     256                        hr_update_vol_status(vol, HR_VOL_ONLINE);
    266257                return EOK;
    267258        }
     
    297288
    298289        rc = hr_raid1_check_vol_status(vol);
    299         if (rc != EOK) {
    300                 fibril_mutex_unlock(&vol->lock);
    301                 return EIO;
    302         }
     290        if (rc != EOK)
     291                goto end;
    303292
    304293        size_t successful = 0;
     
    352341        default:
    353342                rc = EINVAL;
     343                goto end;
    354344        }
    355345
     
    359349                rc = EIO;
    360350
     351end:
    361352        (void)hr_raid1_update_vol_status(vol);
    362353        fibril_mutex_unlock(&vol->lock);
     
    400391        }
    401392
     393        size_t hotspare_idx = vol->hotspare_no - 1;
     394
     395        hr_ext_status_t hs_state = vol->hotspares[hotspare_idx].status;
     396        if (hs_state != HR_EXT_HOTSPARE) {
     397                HR_ERROR("hr_raid1_rebuild(): invalid hotspare state \"%s\", "
     398                    "aborting rebuild\n", hr_get_ext_status_msg(hs_state));
     399                rc = EINVAL;
     400                goto end;
     401        }
     402
     403        HR_DEBUG("hr_raid1_rebuild(): swapping in hotspare\n");
     404
    402405        block_fini(vol->extents[bad].svc_id);
    403406
    404         size_t hotspare_idx = vol->hotspare_no - 1;
    405 
    406         vol->rebuild_blk = 0;
    407407        vol->extents[bad].svc_id = vol->hotspares[hotspare_idx].svc_id;
    408         hr_update_ext_status(vol, bad, HR_EXT_REBUILD);
     408        hr_update_ext_status(vol, bad, HR_EXT_HOTSPARE);
    409409
    410410        vol->hotspares[hotspare_idx].svc_id = 0;
    411         vol->hotspares[hotspare_idx].status = HR_EXT_MISSING;
     411        hr_update_hotspare_status(vol, hotspare_idx, HR_EXT_MISSING);
     412
    412413        vol->hotspare_no--;
    413414
    414         HR_WARN("hr_raid1_rebuild(): changing volume \"%s\" (%lu) state "
    415             "from %s to %s\n", vol->devname, vol->svc_id,
    416             hr_get_vol_status_msg(vol->status),
    417             hr_get_vol_status_msg(HR_VOL_REBUILD));
    418         vol->status = HR_VOL_REBUILD;
    419 
    420         hr_extent_t *hotspare = &vol->extents[bad];
    421 
    422         HR_DEBUG("hr_raid1_rebuild(): initing (%lu)\n", hotspare->svc_id);
    423 
    424         rc = block_init(hotspare->svc_id);
     415        hr_extent_t *rebuild_ext = &vol->extents[bad];
     416
     417        rc = block_init(rebuild_ext->svc_id);
    425418        if (rc != EOK) {
    426419                HR_ERROR("hr_raid1_rebuild(): initing (%lu) failed, "
    427                     "aborting rebuild\n", hotspare->svc_id);
     420                    "aborting rebuild\n", rebuild_ext->svc_id);
    428421                goto end;
    429422        }
     423
     424        HR_DEBUG("hr_raid1_rebuild(): starting rebuild on (%lu)\n",
     425            rebuild_ext->svc_id);
     426
     427        hr_update_ext_status(vol, bad, HR_EXT_REBUILD);
     428        hr_update_vol_status(vol, HR_VOL_REBUILD);
    430429
    431430        size_t left = vol->data_blkno;
     
    435434        hr_extent_t *ext;
    436435
     436        vol->rebuild_blk = 0;
     437
    437438        size_t cnt;
    438439        uint64_t ba = 0;
    439440        hr_add_ba_offset(vol, &ba);
     441
    440442        while (left != 0) {
    441443                vol->rebuild_blk = ba;
     
    462464                }
    463465
    464                 rc = block_write_direct(hotspare->svc_id, ba, cnt, buf);
     466                rc = block_write_direct(rebuild_ext->svc_id, ba, cnt, buf);
    465467                if (rc != EOK) {
    466468                        hr_raid1_handle_extent_error(vol, bad, rc);
Note: See TracChangeset for help on using the changeset viewer.