Changeset da80de9 in mainline
- Timestamp:
- 2025-06-07T11:52:34Z (8 days ago)
- Children:
- d482b05
- Parents:
- 49da044
- Location:
- uspace/srv/bd/hr
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/hr/hr.c
r49da044 rda80de9 376 376 fibril_rwlock_read_unlock(&vol->extents_lock); 377 377 378 vol->hr_ops. state_event(vol);378 vol->hr_ops.vol_state_eval(vol); 379 379 380 380 async_answer_0(icall, EOK); -
uspace/srv/bd/hr/io.c
r49da044 rda80de9 60 60 */ 61 61 if (rc != EOK && (rc != ENOMEM || io->type == HR_BD_WRITE)) 62 io->vol-> state_callback(io->vol, io->extent, rc);62 io->vol->hr_ops.ext_state_cb(io->vol, io->extent, rc); 63 63 64 64 return rc; -
uspace/srv/bd/hr/metadata/native.c
r49da044 rda80de9 389 389 rc = meta_native_write_block(ext->svc_id, md_block); 390 390 if (with_state_callback && rc != EOK) 391 vol-> state_callback(vol, i, rc);391 vol->hr_ops.ext_state_cb(vol, i, rc); 392 392 } 393 393 … … 397 397 398 398 if (with_state_callback) 399 vol->hr_ops. state_event(vol);399 vol->hr_ops.vol_state_eval(vol); 400 400 401 401 free(md_block); -
uspace/srv/bd/hr/raid0.c
r49da044 rda80de9 53 53 #include "var.h" 54 54 55 static void hr_raid0_update_vol_state(hr_volume_t *);56 static void hr_raid0_state_callback(hr_volume_t *, size_t, errno_t);57 55 static errno_t hr_raid0_bd_op(hr_bd_op_type_t, bd_srv_t *, aoff64_t, size_t, 58 56 void *, const void *, size_t); … … 92 90 } 93 91 94 hr_raid0_ update_vol_state(new_volume);92 hr_raid0_vol_state_eval(new_volume); 95 93 if (new_volume->state != HR_VOL_ONLINE) { 96 94 HR_NOTE("\"%s\": unusable state, not creating\n", … … 103 101 new_volume->hr_bds.sarg = new_volume; 104 102 105 new_volume->state_callback = hr_raid0_state_callback;106 107 103 return EOK; 108 104 } … … 130 126 } 131 127 132 void hr_raid0_state_event(hr_volume_t *vol) 133 { 134 HR_DEBUG("%s()", __func__); 135 136 hr_raid0_update_vol_state(vol); 137 } 138 139 static errno_t hr_raid0_bd_open(bd_srvs_t *bds, bd_srv_t *bd) 140 { 141 HR_DEBUG("%s()", __func__); 142 143 hr_volume_t *vol = bd->srvs->sarg; 144 145 atomic_fetch_add_explicit(&vol->open_cnt, 1, memory_order_relaxed); 146 147 return EOK; 148 } 149 150 static errno_t hr_raid0_bd_close(bd_srv_t *bd) 151 { 152 HR_DEBUG("%s()", __func__); 153 154 hr_volume_t *vol = bd->srvs->sarg; 155 156 atomic_fetch_sub_explicit(&vol->open_cnt, 1, memory_order_relaxed); 157 158 return EOK; 159 } 160 161 static errno_t hr_raid0_bd_sync_cache(bd_srv_t *bd, aoff64_t ba, size_t cnt) 162 { 163 return hr_raid0_bd_op(HR_BD_SYNC, bd, ba, cnt, NULL, NULL, 0); 164 } 165 166 static errno_t hr_raid0_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 167 void *buf, size_t size) 168 { 169 return hr_raid0_bd_op(HR_BD_READ, bd, ba, cnt, buf, NULL, size); 170 } 171 172 static errno_t hr_raid0_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 173 const void *data, size_t size) 174 { 175 return hr_raid0_bd_op(HR_BD_WRITE, bd, ba, cnt, NULL, data, size); 176 } 177 178 static errno_t hr_raid0_bd_get_block_size(bd_srv_t *bd, size_t *rsize) 179 { 180 hr_volume_t *vol = bd->srvs->sarg; 181 182 *rsize = vol->bsize; 183 return EOK; 184 } 185 186 static errno_t hr_raid0_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 187 { 188 hr_volume_t *vol = bd->srvs->sarg; 189 190 *rnb = vol->data_blkno; 191 return EOK; 192 } 193 194 static void hr_raid0_update_vol_state(hr_volume_t *vol) 195 { 128 void hr_raid0_vol_state_eval(hr_volume_t *vol) 129 { 130 HR_DEBUG("%s()", __func__); 131 196 132 fibril_mutex_lock(&vol->md_lock); 197 133 … … 226 162 } 227 163 228 static void hr_raid0_state_callback(hr_volume_t *vol, size_t extent, errno_t rc) 229 { 164 void hr_raid0_ext_state_cb(hr_volume_t *vol, size_t extent, errno_t rc) 165 { 166 HR_DEBUG("%s()", __func__); 167 230 168 if (rc == EOK) 231 169 return; … … 246 184 } 247 185 186 static errno_t hr_raid0_bd_open(bd_srvs_t *bds, bd_srv_t *bd) 187 { 188 HR_DEBUG("%s()", __func__); 189 190 hr_volume_t *vol = bd->srvs->sarg; 191 192 atomic_fetch_add_explicit(&vol->open_cnt, 1, memory_order_relaxed); 193 194 return EOK; 195 } 196 197 static errno_t hr_raid0_bd_close(bd_srv_t *bd) 198 { 199 HR_DEBUG("%s()", __func__); 200 201 hr_volume_t *vol = bd->srvs->sarg; 202 203 atomic_fetch_sub_explicit(&vol->open_cnt, 1, memory_order_relaxed); 204 205 return EOK; 206 } 207 208 static errno_t hr_raid0_bd_sync_cache(bd_srv_t *bd, aoff64_t ba, size_t cnt) 209 { 210 return hr_raid0_bd_op(HR_BD_SYNC, bd, ba, cnt, NULL, NULL, 0); 211 } 212 213 static errno_t hr_raid0_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 214 void *buf, size_t size) 215 { 216 return hr_raid0_bd_op(HR_BD_READ, bd, ba, cnt, buf, NULL, size); 217 } 218 219 static errno_t hr_raid0_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 220 const void *data, size_t size) 221 { 222 return hr_raid0_bd_op(HR_BD_WRITE, bd, ba, cnt, NULL, data, size); 223 } 224 225 static errno_t hr_raid0_bd_get_block_size(bd_srv_t *bd, size_t *rsize) 226 { 227 hr_volume_t *vol = bd->srvs->sarg; 228 229 *rsize = vol->bsize; 230 return EOK; 231 } 232 233 static errno_t hr_raid0_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 234 { 235 hr_volume_t *vol = bd->srvs->sarg; 236 237 *rnb = vol->data_blkno; 238 return EOK; 239 } 240 248 241 static errno_t hr_raid0_bd_op(hr_bd_op_type_t type, bd_srv_t *bd, aoff64_t ba, 249 242 size_t cnt, void *dst, const void *src, size_t size) 250 243 { 244 HR_DEBUG("%s()", __func__); 245 251 246 hr_volume_t *vol = bd->srvs->sarg; 252 247 errno_t rc; -
uspace/srv/bd/hr/raid1.c
r49da044 rda80de9 56 56 #include "var.h" 57 57 58 static void hr_raid1_update_vol_state(hr_volume_t *);59 static void hr_raid1_ext_state_callback(hr_volume_t *, size_t, errno_t);60 58 static size_t hr_raid1_count_good_extents(hr_volume_t *, uint64_t, size_t, 61 59 uint64_t); … … 106 104 new_volume->hr_bds.sarg = new_volume; 107 105 108 new_volume->state_callback = hr_raid1_ext_state_callback;109 110 106 /* force volume state update */ 111 107 hr_mark_vol_state_dirty(new_volume); 112 hr_raid1_ update_vol_state(new_volume);108 hr_raid1_vol_state_eval(new_volume); 113 109 114 110 fibril_rwlock_read_lock(&new_volume->states_lock); … … 140 136 } 141 137 142 void hr_raid1_state_event(hr_volume_t *vol)143 {144 HR_DEBUG("%s()", __func__);145 146 hr_raid1_update_vol_state(vol);147 }148 149 138 errno_t hr_raid1_add_hotspare(hr_volume_t *vol, service_id_t hotspare) 150 139 { … … 153 142 errno_t rc = hr_util_add_hotspare(vol, hotspare); 154 143 155 hr_raid1_ update_vol_state(vol);144 hr_raid1_vol_state_eval(vol); 156 145 157 146 return rc; 158 147 } 159 148 160 static errno_t hr_raid1_bd_open(bd_srvs_t *bds, bd_srv_t *bd) 161 { 162 HR_DEBUG("%s()", __func__); 163 164 hr_volume_t *vol = bd->srvs->sarg; 165 166 atomic_fetch_add_explicit(&vol->open_cnt, 1, memory_order_relaxed); 167 168 return EOK; 169 } 170 171 static errno_t hr_raid1_bd_close(bd_srv_t *bd) 172 { 173 HR_DEBUG("%s()", __func__); 174 175 hr_volume_t *vol = bd->srvs->sarg; 176 177 atomic_fetch_sub_explicit(&vol->open_cnt, 1, memory_order_relaxed); 178 179 return EOK; 180 } 181 182 static errno_t hr_raid1_bd_sync_cache(bd_srv_t *bd, aoff64_t ba, size_t cnt) 183 { 184 return hr_raid1_bd_op(HR_BD_SYNC, bd, ba, cnt, NULL, NULL, 0); 185 } 186 187 static errno_t hr_raid1_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 188 void *buf, size_t size) 189 { 190 return hr_raid1_bd_op(HR_BD_READ, bd, ba, cnt, buf, NULL, size); 191 } 192 193 static errno_t hr_raid1_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 194 const void *data, size_t size) 195 { 196 return hr_raid1_bd_op(HR_BD_WRITE, bd, ba, cnt, NULL, data, size); 197 } 198 199 static errno_t hr_raid1_bd_get_block_size(bd_srv_t *bd, size_t *rsize) 200 { 201 hr_volume_t *vol = bd->srvs->sarg; 202 203 *rsize = vol->bsize; 204 return EOK; 205 } 206 207 static errno_t hr_raid1_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 208 { 209 hr_volume_t *vol = bd->srvs->sarg; 210 211 *rnb = vol->data_blkno; 212 return EOK; 213 } 214 215 static void hr_raid1_update_vol_state(hr_volume_t *vol) 216 { 149 void hr_raid1_vol_state_eval(hr_volume_t *vol) 150 { 151 HR_DEBUG("%s()", __func__); 152 217 153 bool exp = true; 218 154 … … 271 207 } 272 208 273 static void hr_raid1_ext_state_callback(hr_volume_t *vol, size_t extent,209 void hr_raid1_ext_state_cb(hr_volume_t *vol, size_t extent, 274 210 errno_t rc) 275 211 { 212 HR_DEBUG("%s()", __func__); 213 276 214 if (rc == EOK) 277 215 return; … … 297 235 } 298 236 237 static errno_t hr_raid1_bd_open(bd_srvs_t *bds, bd_srv_t *bd) 238 { 239 HR_DEBUG("%s()", __func__); 240 241 hr_volume_t *vol = bd->srvs->sarg; 242 243 atomic_fetch_add_explicit(&vol->open_cnt, 1, memory_order_relaxed); 244 245 return EOK; 246 } 247 248 static errno_t hr_raid1_bd_close(bd_srv_t *bd) 249 { 250 HR_DEBUG("%s()", __func__); 251 252 hr_volume_t *vol = bd->srvs->sarg; 253 254 atomic_fetch_sub_explicit(&vol->open_cnt, 1, memory_order_relaxed); 255 256 return EOK; 257 } 258 259 static errno_t hr_raid1_bd_sync_cache(bd_srv_t *bd, aoff64_t ba, size_t cnt) 260 { 261 return hr_raid1_bd_op(HR_BD_SYNC, bd, ba, cnt, NULL, NULL, 0); 262 } 263 264 static errno_t hr_raid1_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 265 void *buf, size_t size) 266 { 267 return hr_raid1_bd_op(HR_BD_READ, bd, ba, cnt, buf, NULL, size); 268 } 269 270 static errno_t hr_raid1_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 271 const void *data, size_t size) 272 { 273 return hr_raid1_bd_op(HR_BD_WRITE, bd, ba, cnt, NULL, data, size); 274 } 275 276 static errno_t hr_raid1_bd_get_block_size(bd_srv_t *bd, size_t *rsize) 277 { 278 hr_volume_t *vol = bd->srvs->sarg; 279 280 *rsize = vol->bsize; 281 return EOK; 282 } 283 284 static errno_t hr_raid1_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 285 { 286 hr_volume_t *vol = bd->srvs->sarg; 287 288 *rnb = vol->data_blkno; 289 return EOK; 290 } 291 299 292 static size_t hr_raid1_count_good_extents(hr_volume_t *vol, uint64_t ba, 300 293 size_t cnt, uint64_t rebuild_blk) … … 319 312 size_t cnt, void *data_read, const void *data_write, size_t size) 320 313 { 314 HR_DEBUG("%s()", __func__); 315 321 316 hr_volume_t *vol = bd->srvs->sarg; 322 317 hr_range_lock_t *rl = NULL; … … 377 372 378 373 if (rc != EOK) { 379 hr_raid1_ext_state_c allback(vol, i, rc);374 hr_raid1_ext_state_cb(vol, i, rc); 380 375 } else { 381 376 successful++; … … 458 453 fibril_rwlock_read_unlock(&vol->extents_lock); 459 454 460 hr_raid1_ update_vol_state(vol);455 hr_raid1_vol_state_eval(vol); 461 456 462 457 return rc; … … 565 560 fibril_rwlock_read_unlock(&vol->extents_lock); 566 561 567 hr_raid1_ update_vol_state(vol);562 hr_raid1_vol_state_eval(vol); 568 563 569 564 if (buf != NULL) … … 690 685 691 686 if (rc != ENOMEM) 692 hr_raid1_ext_state_c allback(vol, i, rc);687 hr_raid1_ext_state_cb(vol, i, rc); 693 688 694 689 if (i + 1 >= vol->extent_no) { … … 705 700 "because of not enough memory\n", 706 701 vol->devname, vol->svc_id); 707 hr_raid1_ext_state_c allback(vol, rebuild_idx,702 hr_raid1_ext_state_cb(vol, rebuild_idx, 708 703 ENOMEM); 709 704 } … … 723 718 * XXX: for now we do 724 719 */ 725 hr_raid1_ext_state_c allback(vol, rebuild_idx, rc);720 hr_raid1_ext_state_cb(vol, rebuild_idx, rc); 726 721 727 722 HR_ERROR("rebuild on \"%s\" (%" PRIun "), failed due to " -
uspace/srv/bd/hr/raid5.c
r49da044 rda80de9 57 57 static ssize_t hr_raid5_get_bad_ext(hr_volume_t *); 58 58 static errno_t hr_raid5_update_vol_state(hr_volume_t *); 59 static void hr_raid5_handle_extent_error(hr_volume_t *, size_t, errno_t);60 59 static void xor(void *, const void *, size_t); 61 60 … … 148 147 } 149 148 150 void hr_raid5_ state_event(hr_volume_t *vol)149 void hr_raid5_vol_state_eval(hr_volume_t *vol) 151 150 { 152 151 fibril_mutex_lock(&vol->lock); … … 189 188 } 190 189 190 void hr_raid5_ext_state_cb(hr_volume_t *vol, size_t extent, 191 errno_t rc) 192 { 193 if (rc == ENOENT) 194 hr_update_ext_state(vol, extent, HR_EXT_MISSING); 195 else if (rc != EOK) 196 hr_update_ext_state(vol, extent, HR_EXT_FAILED); 197 } 198 191 199 static errno_t hr_raid5_bd_open(bd_srvs_t *bds, bd_srv_t *bd) 192 200 { … … 299 307 return EIO; 300 308 } 301 }302 303 static void hr_raid5_handle_extent_error(hr_volume_t *vol, size_t extent,304 errno_t rc)305 {306 if (rc == ENOENT)307 hr_update_ext_state(vol, extent, HR_EXT_MISSING);308 else if (rc != EOK)309 hr_update_ext_state(vol, extent, HR_EXT_FAILED);310 309 } 311 310 … … 648 647 goto error; 649 648 650 hr_raid5_ handle_extent_error(vol, extent, rc);649 hr_raid5_ext_state_cb(vol, extent, rc); 651 650 652 651 if (rc != EOK) { … … 802 801 ba, cnt, buf); 803 802 if (rc != EOK) { 804 hr_raid5_ handle_extent_error(vol, i, rc);803 hr_raid5_ext_state_cb(vol, i, rc); 805 804 HR_ERROR("rebuild on \"%s\" (%" PRIun "), " 806 805 "failed due to a failed ONLINE extent, " … … 818 817 rc = block_write_direct(rebuild_ext->svc_id, ba, cnt, xorbuf); 819 818 if (rc != EOK) { 820 hr_raid5_ handle_extent_error(vol, bad, rc);819 hr_raid5_ext_state_cb(vol, bad, rc); 821 820 HR_ERROR("rebuild on \"%s\" (%" PRIun "), failed due to " 822 821 "the rebuilt extent number %zu failing\n", -
uspace/srv/bd/hr/util.c
r49da044 rda80de9 98 98 vol->hr_ops.create = hr_raid0_create; 99 99 vol->hr_ops.init = hr_raid0_init; 100 vol->hr_ops.state_event = hr_raid0_state_event; 100 vol->hr_ops.vol_state_eval = hr_raid0_vol_state_eval; 101 vol->hr_ops.ext_state_cb = hr_raid0_ext_state_cb; 101 102 break; 102 103 case HR_LVL_1: 103 104 vol->hr_ops.create = hr_raid1_create; 104 105 vol->hr_ops.init = hr_raid1_init; 105 vol->hr_ops.state_event = hr_raid1_state_event; 106 vol->hr_ops.vol_state_eval = hr_raid1_vol_state_eval; 107 vol->hr_ops.ext_state_cb = hr_raid1_ext_state_cb; 106 108 if (meta_flags & HR_METADATA_HOTSPARE_SUPPORT) 107 109 vol->hr_ops.add_hotspare = hr_raid1_add_hotspare; … … 111 113 vol->hr_ops.create = hr_raid5_create; 112 114 vol->hr_ops.init = hr_raid5_init; 113 vol->hr_ops.state_event = hr_raid5_state_event; 115 vol->hr_ops.vol_state_eval = hr_raid5_vol_state_eval; 116 vol->hr_ops.ext_state_cb = hr_raid5_ext_state_cb; 114 117 if (meta_flags & HR_METADATA_HOTSPARE_SUPPORT) 115 118 vol->hr_ops.add_hotspare = hr_raid5_add_hotspare; -
uspace/srv/bd/hr/var.h
r49da044 rda80de9 58 58 errno_t (*create)(hr_volume_t *); 59 59 errno_t (*init)(hr_volume_t *); 60 void (*state_event)(hr_volume_t *);61 60 errno_t (*add_hotspare)(hr_volume_t *, service_id_t); 61 void (*vol_state_eval)(hr_volume_t *); 62 void (*ext_state_cb)(hr_volume_t *, size_t, errno_t); 62 63 } hr_ops_t; 63 64 … … 104 105 _Atomic int open_cnt; /* open/close() counter */ 105 106 hr_vol_state_t state; /* volume state */ 106 void (*state_callback)(hr_volume_t *, size_t, errno_t);107 107 } hr_volume_t; 108 108 … … 136 136 extern errno_t hr_raid5_init(hr_volume_t *); 137 137 138 extern void hr_raid0_state_event(hr_volume_t *);139 extern void hr_raid1_state_event(hr_volume_t *);140 extern void hr_raid5_state_event(hr_volume_t *);141 142 138 extern errno_t hr_raid1_add_hotspare(hr_volume_t *, service_id_t); 143 139 extern errno_t hr_raid5_add_hotspare(hr_volume_t *, service_id_t); 144 140 141 extern void hr_raid0_vol_state_eval(hr_volume_t *); 142 extern void hr_raid1_vol_state_eval(hr_volume_t *); 143 extern void hr_raid5_vol_state_eval(hr_volume_t *); 144 145 extern void hr_raid0_ext_state_cb(hr_volume_t *, size_t, errno_t); 146 extern void hr_raid1_ext_state_cb(hr_volume_t *, size_t, errno_t); 147 extern void hr_raid5_ext_state_cb(hr_volume_t *, size_t, errno_t); 145 148 #endif 146 149
Note:
See TracChangeset
for help on using the changeset viewer.