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


Ignore:
Timestamp:
2024-11-28T17:09:52Z (7 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/raid5.c

    r65706f1 ra0c3080  
    158158
    159159        vol->hotspares[vol->hotspare_no].svc_id = hotspare;
    160         vol->hotspares[vol->hotspare_no].status = HR_EXT_HOTSPARE;
     160        hr_update_hotspare_status(vol, vol->hotspare_no, HR_EXT_HOTSPARE);
     161
    161162        vol->hotspare_no++;
    162163
     
    169170                fid_t fib = fibril_create(hr_raid5_rebuild, vol);
    170171                if (fib == 0)
    171                         return EINVAL;
     172                        return ENOMEM;
    172173                fibril_start(fib);
    173174                fibril_detach(fib);
     
    230231            vol->status == HR_VOL_REBUILD)
    231232                return EOK;
    232         return EINVAL;
     233        return EIO;
    233234}
    234235
     
    255256        switch (bad) {
    256257        case 0:
    257                 if (old_state != HR_VOL_ONLINE) {
    258                         HR_WARN("RAID 5 has all extents online, "
    259                             "marking \"%s\" (%lu) as ONLINE",
    260                             vol->devname, vol->svc_id);
    261                         vol->status = HR_VOL_ONLINE;
    262                 }
     258                if (old_state != HR_VOL_ONLINE)
     259                        hr_update_vol_status(vol, HR_VOL_ONLINE);
    263260                return EOK;
    264261        case 1:
    265262                if (old_state != HR_VOL_DEGRADED &&
    266263                    old_state != HR_VOL_REBUILD) {
    267                         HR_WARN("RAID 5 array \"%s\" (%lu) has 1 extent "
    268                             "inactive, marking as DEGRADED",
    269                             vol->devname, vol->svc_id);
    270                         vol->status = HR_VOL_DEGRADED;
     264
     265                        hr_update_vol_status(vol, HR_VOL_DEGRADED);
     266
    271267                        if (vol->hotspare_no > 0) {
    272268                                fid_t fib = fibril_create(hr_raid5_rebuild,
    273269                                    vol);
    274                                 if (fib == 0) {
    275                                         return EINVAL;
    276                                 }
     270                                if (fib == 0)
     271                                        return ENOMEM;
    277272                                fibril_start(fib);
    278273                                fibril_detach(fib);
     
    281276                return EOK;
    282277        default:
    283                 if (old_state != HR_VOL_FAULTY) {
    284                         HR_WARN("RAID 5 array \"%s\" (%lu) has more "
    285                             "than one 1 extent inactive, marking as FAULTY",
    286                             vol->devname, vol->svc_id);
    287                         vol->status = HR_VOL_FAULTY;
    288                 }
    289                 return EINVAL;
     278                if (old_state != HR_VOL_FAULTY)
     279                        hr_update_vol_status(vol, HR_VOL_FAULTY);
     280                return EIO;
    290281        }
    291282}
     
    560551
    561552        left = cnt;
     553
    562554        while (left != 0) {
    563555                phys_block = ext_stripe * strip_size + strip_off;
     
    674666        }
    675667
     668        size_t hotspare_idx = vol->hotspare_no - 1;
     669
     670        hr_ext_status_t hs_state = vol->hotspares[hotspare_idx].status;
     671        if (hs_state != HR_EXT_HOTSPARE) {
     672                HR_ERROR("hr_raid5_rebuild(): invalid hotspare state \"%s\", "
     673                    "aborting rebuild\n", hr_get_ext_status_msg(hs_state));
     674                rc = EINVAL;
     675                goto end;
     676        }
     677
     678        HR_DEBUG("hr_raid5_rebuild(): swapping in hotspare\n");
     679
    676680        block_fini(vol->extents[bad].svc_id);
    677681
    678         size_t hotspare_idx = vol->hotspare_no - 1;
    679 
    680682        vol->extents[bad].svc_id = vol->hotspares[hotspare_idx].svc_id;
    681         hr_update_ext_status(vol, bad, HR_EXT_REBUILD);
     683        hr_update_ext_status(vol, bad, HR_EXT_HOTSPARE);
    682684
    683685        vol->hotspares[hotspare_idx].svc_id = 0;
    684         vol->hotspares[hotspare_idx].status = HR_EXT_MISSING;
     686        hr_update_hotspare_status(vol, hotspare_idx, HR_EXT_MISSING);
     687
    685688        vol->hotspare_no--;
    686689
    687         HR_WARN("hr_raid5_rebuild(): changing volume \"%s\" (%lu) state "
    688             "from %s to %s\n", vol->devname, vol->svc_id,
    689             hr_get_vol_status_msg(vol->status),
    690             hr_get_vol_status_msg(HR_VOL_REBUILD));
    691         vol->status = HR_VOL_REBUILD;
    692 
    693         hr_extent_t *hotspare = &vol->extents[bad];
    694 
    695         HR_DEBUG("hr_raid5_rebuild(): initing (%lu)\n", hotspare->svc_id);
    696 
    697         rc = block_init(hotspare->svc_id);
     690        hr_extent_t *rebuild_ext = &vol->extents[bad];
     691
     692        rc = block_init(rebuild_ext->svc_id);
    698693        if (rc != EOK) {
    699694                HR_ERROR("hr_raid5_rebuild(): initing (%lu) failed, "
    700                     "aborting rebuild\n", hotspare->svc_id);
     695                    "aborting rebuild\n", rebuild_ext->svc_id);
    701696                goto end;
    702697        }
     698
     699        HR_DEBUG("hr_raid5_rebuild(): starting rebuild on (%lu)\n",
     700            rebuild_ext->svc_id);
     701
     702        hr_update_ext_status(vol, bad, HR_EXT_REBUILD);
     703        hr_update_vol_status(vol, HR_VOL_REBUILD);
    703704
    704705        uint64_t max_blks = DATA_XFER_LIMIT / vol->bsize;
     
    709710        uint64_t ba = 0, cnt;
    710711        hr_add_ba_offset(vol, &ba);
     712
    711713        while (left != 0) {
    712714                cnt = min(left, max_blks);
     
    741743                }
    742744
    743                 rc = block_write_direct(hotspare->svc_id, ba, cnt, xorbuf);
     745                rc = block_write_direct(rebuild_ext->svc_id, ba, cnt, xorbuf);
    744746                if (rc != EOK) {
    745747                        hr_raid5_handle_extent_error(vol, bad, rc);
Note: See TracChangeset for help on using the changeset viewer.