Changeset e0695ce in mainline for uspace/srv/bd/hr/util.c


Ignore:
Timestamp:
2025-06-23T16:50:43Z (9 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
6a8c1569
Parents:
f18e36e
git-author:
Miroslav Cimerman <mc@…> (2025-06-23 16:47:52)
git-committer:
Miroslav Cimerman <mc@…> (2025-06-23 16:50:43)
Message:

hr: save REBUILD position

File:
1 edited

Legend:

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

    rf18e36e re0695ce  
    281281
    282282        /* save metadata, but we don't care about states anymore */
    283         (void)vol->meta_ops->save(vol, NO_STATE_CALLBACK);
     283        vol->meta_ops->save(vol, NO_STATE_CALLBACK);
    284284
    285285        HR_NOTE("deactivating volume \"%s\"\n", vol->devname);
     
    11171117{
    11181118        errno_t rc = EOK;
     1119        size_t bad = vol->extent_no;
    11191120
    11201121        if (vol->level == HR_LVL_0)
     
    11251126        fibril_mutex_lock(&vol->hotspare_lock);
    11261127
    1127         size_t bad = vol->extent_no;
     1128        if (vol->state != HR_VOL_DEGRADED) {
     1129                rc = EINVAL;
     1130                goto error;
     1131        }
     1132
     1133        size_t rebuild = vol->extent_no;
    11281134        for (size_t i = 0; i < vol->extent_no; i++) {
    1129                 if (vol->extents[i].state != HR_EXT_ONLINE) {
    1130                         bad = i;
     1135                if (vol->extents[i].state == HR_EXT_REBUILD) {
     1136                        rebuild = i;
    11311137                        break;
    11321138                }
    11331139        }
    11341140
    1135         if (bad == vol->extent_no)
    1136                 rc = EINVAL;
    1137         else if (vol->state != HR_VOL_DEGRADED)
    1138                 rc = EINVAL;
     1141        if (rebuild < vol->extent_no) {
     1142                bad = rebuild;
     1143                goto init_rebuild;
     1144        }
    11391145
    11401146        size_t invalid = vol->extent_no;
     
    11461152        }
    11471153
    1148         if (invalid < vol->extent_no)
     1154        if (invalid < vol->extent_no) {
    11491155                bad = invalid;
    1150 
    1151         if (bad != invalid && vol->hotspare_no == 0)
     1156                goto init_rebuild;
     1157        }
     1158
     1159        for (size_t i = 0; i < vol->extent_no; i++) {
     1160                if (vol->extents[i].state != HR_EXT_ONLINE) {
     1161                        bad = i;
     1162                        break;
     1163                }
     1164        }
     1165
     1166        if (bad == vol->extent_no || vol->hotspare_no == 0) {
    11521167                rc = EINVAL;
    1153 
    1154         if (rc != EOK)
    1155                 goto error;
    1156 
    1157         if (bad != invalid) {
    1158                 size_t hotspare_idx = vol->hotspare_no - 1;
    1159 
    1160                 hr_ext_state_t hs_state = vol->hotspares[hotspare_idx].state;
    1161                 if (hs_state != HR_EXT_HOTSPARE) {
    1162                         HR_ERROR("hr_raid1_rebuild(): invalid hotspare"
    1163                             "state \"%s\", aborting rebuild\n",
    1164                             hr_get_ext_state_str(hs_state));
    1165                         rc = EINVAL;
    1166                         goto error;
    1167                 }
    1168 
    1169                 rc = hr_swap_hs(vol, bad, hotspare_idx);
    1170                 if (rc != EOK) {
    1171                         HR_ERROR("hr_raid1_rebuild(): swapping "
    1172                             "hotspare failed, aborting rebuild\n");
    1173                         goto error;
    1174                 }
     1168                goto error;
     1169        }
     1170
     1171        size_t hotspare_idx = vol->hotspare_no - 1;
     1172
     1173        hr_ext_state_t hs_state = vol->hotspares[hotspare_idx].state;
     1174        if (hs_state != HR_EXT_HOTSPARE) {
     1175                HR_ERROR("hr_raid1_rebuild(): invalid hotspare"
     1176                    "state \"%s\", aborting rebuild\n",
     1177                    hr_get_ext_state_str(hs_state));
     1178                rc = EINVAL;
     1179                goto error;
     1180        }
     1181
     1182        rc = hr_swap_hs(vol, bad, hotspare_idx);
     1183        if (rc != EOK) {
     1184                HR_ERROR("hr_raid1_rebuild(): swapping "
     1185                    "hotspare failed, aborting rebuild\n");
     1186                goto error;
    11751187        }
    11761188
     
    11801192            "(%"  PRIun  ")\n", bad, rebuild_ext->svc_id);
    11811193
    1182         atomic_store_explicit(&vol->rebuild_blk, 0, memory_order_relaxed);
    1183 
     1194init_rebuild:
    11841195        hr_update_ext_state(vol, bad, HR_EXT_REBUILD);
    11851196        hr_update_vol_state(vol, HR_VOL_REBUILD);
Note: See TracChangeset for help on using the changeset viewer.