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


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

    r65706f1 ra0c3080  
    161161
    162162        vol->hotspares[vol->hotspare_no].svc_id = hotspare;
    163         vol->hotspares[vol->hotspare_no].status = HR_EXT_HOTSPARE;
     163        hr_update_hotspare_status(vol, vol->hotspare_no, HR_EXT_HOTSPARE);
     164
    164165        vol->hotspare_no++;
    165166
     
    172173                fid_t fib = fibril_create(hr_raid4_rebuild, vol);
    173174                if (fib == 0)
    174                         return EINVAL;
     175                        return ENOMEM;
    175176                fibril_start(fib);
    176177                fibril_detach(fib);
     
    233234            vol->status == HR_VOL_REBUILD)
    234235                return EOK;
    235         return EINVAL;
     236        return EIO;
    236237}
    237238
     
    258259        switch (bad) {
    259260        case 0:
    260                 if (old_state != HR_VOL_ONLINE) {
    261                         HR_WARN("RAID 4 has all extents online, "
    262                             "marking \"%s\" (%lu) as ONLINE",
    263                             vol->devname, vol->svc_id);
    264                         vol->status = HR_VOL_ONLINE;
    265                 }
     261                if (old_state != HR_VOL_ONLINE)
     262                        hr_update_vol_status(vol, HR_VOL_ONLINE);
    266263                return EOK;
    267264        case 1:
    268265                if (old_state != HR_VOL_DEGRADED &&
    269266                    old_state != HR_VOL_REBUILD) {
    270                         HR_WARN("RAID 4 array \"%s\" (%lu) has 1 extent "
    271                             "inactive, marking as DEGRADED",
    272                             vol->devname, vol->svc_id);
    273                         vol->status = HR_VOL_DEGRADED;
     267
     268                        hr_update_vol_status(vol, HR_VOL_DEGRADED);
     269
    274270                        if (vol->hotspare_no > 0) {
    275271                                fid_t fib = fibril_create(hr_raid4_rebuild,
    276272                                    vol);
    277                                 if (fib == 0) {
    278                                         return EINVAL;
    279                                 }
     273                                if (fib == 0)
     274                                        return ENOMEM;
    280275                                fibril_start(fib);
    281276                                fibril_detach(fib);
     
    284279                return EOK;
    285280        default:
    286                 if (old_state != HR_VOL_FAULTY) {
    287                         HR_WARN("RAID 4 array \"%s\" (%lu) has more "
    288                             "than one 1 extent unusable, marking as FAULTY",
    289                             vol->devname, vol->svc_id);
    290                         vol->status = HR_VOL_FAULTY;
    291                 }
    292                 return EINVAL;
     281                if (old_state != HR_VOL_FAULTY)
     282                        hr_update_vol_status(vol, HR_VOL_FAULTY);
     283                return EIO;
    293284        }
    294285}
     
    560551
    561552        left = cnt;
     553
    562554        while (left != 0) {
    563555                phys_block = ext_stripe * strip_size + strip_off;
     
    670662        }
    671663
     664        size_t hotspare_idx = vol->hotspare_no - 1;
     665
     666        hr_ext_status_t hs_state = vol->hotspares[hotspare_idx].status;
     667        if (hs_state != HR_EXT_HOTSPARE) {
     668                HR_ERROR("hr_raid4_rebuild(): invalid hotspare state \"%s\", "
     669                    "aborting rebuild\n", hr_get_ext_status_msg(hs_state));
     670                rc = EINVAL;
     671                goto end;
     672        }
     673
     674        HR_DEBUG("hr_raid4_rebuild(): swapping in hotspare\n");
     675
    672676        block_fini(vol->extents[bad].svc_id);
    673677
    674         size_t hotspare_idx = vol->hotspare_no - 1;
    675 
    676678        vol->extents[bad].svc_id = vol->hotspares[hotspare_idx].svc_id;
    677         hr_update_ext_status(vol, bad, HR_EXT_REBUILD);
     679        hr_update_ext_status(vol, bad, HR_EXT_HOTSPARE);
    678680
    679681        vol->hotspares[hotspare_idx].svc_id = 0;
    680         vol->hotspares[hotspare_idx].status = HR_EXT_MISSING;
     682        hr_update_hotspare_status(vol, hotspare_idx, HR_EXT_MISSING);
     683
    681684        vol->hotspare_no--;
    682685
    683         HR_WARN("hr_raid4_rebuild(): changing volume \"%s\" (%lu) state "
    684             "from %s to %s\n", vol->devname, vol->svc_id,
    685             hr_get_vol_status_msg(vol->status),
    686             hr_get_vol_status_msg(HR_VOL_REBUILD));
    687         vol->status = HR_VOL_REBUILD;
    688 
    689         hr_extent_t *hotspare = &vol->extents[bad];
    690 
    691         HR_DEBUG("hr_raid4_rebuild(): initing (%lu)\n", hotspare->svc_id);
    692 
    693         rc = block_init(hotspare->svc_id);
     686        hr_extent_t *rebuild_ext = &vol->extents[bad];
     687
     688        rc = block_init(rebuild_ext->svc_id);
    694689        if (rc != EOK) {
    695690                HR_ERROR("hr_raid4_rebuild(): initing (%lu) failed, "
    696                     "aborting rebuild\n", hotspare->svc_id);
     691                    "aborting rebuild\n", rebuild_ext->svc_id);
    697692                goto end;
    698693        }
     694
     695        HR_DEBUG("hr_raid4_rebuild(): starting rebuild on (%lu)\n",
     696            rebuild_ext->svc_id);
     697
     698        hr_update_ext_status(vol, bad, HR_EXT_REBUILD);
     699        hr_update_vol_status(vol, HR_VOL_REBUILD);
    699700
    700701        uint64_t max_blks = DATA_XFER_LIMIT / vol->bsize;
     
    705706        uint64_t ba = 0, cnt;
    706707        hr_add_ba_offset(vol, &ba);
     708
    707709        while (left != 0) {
    708710                cnt = min(left, max_blks);
     
    735737                }
    736738
    737                 rc = block_write_direct(hotspare->svc_id, ba, cnt, xorbuf);
     739                rc = block_write_direct(rebuild_ext->svc_id, ba, cnt, xorbuf);
    738740                if (rc != EOK) {
    739741                        hr_raid4_handle_extent_error(vol, bad, rc);
Note: See TracChangeset for help on using the changeset viewer.