Changeset aa9bad8 in mainline for uspace/srv/bd/hr/metadata/foreign/softraid
- Timestamp:
- 2025-06-27T22:21:05Z (9 months ago)
- Children:
- 2de7c1f
- Parents:
- 78433bb
- git-author:
- Miroslav Cimerman <mc@…> (2025-06-27 22:14:37)
- git-committer:
- Miroslav Cimerman <mc@…> (2025-06-27 22:21:05)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/hr/metadata/foreign/softraid/hr_softraid.c
r78433bb raa9bad8 54 54 #include "softraidvar.h" 55 55 56 /* not exposed */ 56 57 static void *meta_softraid_alloc_struct(void); 58 /* static void meta_softraid_encode(void *, void *); */ 59 static errno_t meta_softraid_decode(const void *, void *); 60 static errno_t meta_softraid_get_block(service_id_t, void **); 61 /* static errno_t meta_softraid_write_block(service_id_t, const void *); */ 62 static bool meta_softraid_has_valid_magic(const void *); 63 64 static errno_t meta_softraid_probe(service_id_t, void **); 57 65 static errno_t meta_softraid_init_vol2meta(hr_volume_t *); 58 66 static errno_t meta_softraid_init_meta2vol(const list_t *, hr_volume_t *); 59 static void meta_softraid_encode(void *, void *);60 static errno_t meta_softraid_decode(const void *, void *);61 static errno_t meta_softraid_get_block(service_id_t, void **);62 static errno_t meta_softraid_write_block(service_id_t, const void *);63 static bool meta_softraid_has_valid_magic(const void *);64 67 static bool meta_softraid_compare_uuids(const void *, const void *); 65 68 static void meta_softraid_inc_counter(hr_volume_t *); … … 75 78 76 79 hr_superblock_ops_t metadata_softraid_ops = { 77 . alloc_struct = meta_softraid_alloc_struct,80 .probe = meta_softraid_probe, 78 81 .init_vol2meta = meta_softraid_init_vol2meta, 79 82 .init_meta2vol = meta_softraid_init_meta2vol, 80 .encode = meta_softraid_encode,81 .decode = meta_softraid_decode,82 .get_block = meta_softraid_get_block,83 .write_block = meta_softraid_write_block,84 .has_valid_magic = meta_softraid_has_valid_magic,85 83 .compare_uuids = meta_softraid_compare_uuids, 86 84 .inc_counter = meta_softraid_inc_counter, … … 96 94 }; 97 95 98 static void *meta_softraid_alloc_struct(void) 99 { 100 return calloc(1, SR_META_SIZE * DEV_BSIZE); 96 static errno_t meta_softraid_probe(service_id_t svc_id, void **rmd) 97 { 98 errno_t rc; 99 void *meta_block; 100 101 void *metadata_struct = meta_softraid_alloc_struct(); 102 if (metadata_struct == NULL) 103 return ENOMEM; 104 105 rc = meta_softraid_get_block(svc_id, &meta_block); 106 if (rc != EOK) 107 goto error; 108 109 rc = meta_softraid_decode(meta_block, metadata_struct); 110 111 free(meta_block); 112 113 if (rc != EOK) 114 goto error; 115 116 if (!meta_softraid_has_valid_magic(metadata_struct)) { 117 rc = ENOFS; 118 goto error; 119 } 120 121 *rmd = metadata_struct; 122 return EOK; 123 124 error: 125 free(metadata_struct); 126 return ENOFS; 101 127 } 102 128 … … 181 207 } 182 208 209 static bool meta_softraid_compare_uuids(const void *m1_v, const void *m2_v) 210 { 211 const struct sr_metadata *m1 = m1_v; 212 const struct sr_metadata *m2 = m2_v; 213 if (memcmp(&m1->ssdi.ssd_uuid, &m2->ssdi.ssd_uuid, 214 SR_UUID_MAX) == 0) 215 return true; 216 217 return false; 218 } 219 220 static void meta_softraid_inc_counter(hr_volume_t *vol) 221 { 222 fibril_mutex_lock(&vol->md_lock); 223 224 struct sr_metadata *md = vol->in_mem_md; 225 226 md->ssd_ondisk++; 227 228 fibril_mutex_unlock(&vol->md_lock); 229 } 230 231 static errno_t meta_softraid_save(hr_volume_t *vol, bool with_state_callback) 232 { 233 HR_DEBUG("%s()", __func__); 234 235 return ENOTSUP; 236 } 237 238 static errno_t meta_softraid_save_ext(hr_volume_t *vol, size_t ext_idx, 239 bool with_state_callback) 240 { 241 HR_DEBUG("%s()", __func__); 242 243 return ENOTSUP; 244 } 245 246 static const char *meta_softraid_get_devname(const void *md_v) 247 { 248 const struct sr_metadata *md = md_v; 249 250 return md->ssd_devname; 251 } 252 253 static hr_level_t meta_softraid_get_level(const void *md_v) 254 { 255 const struct sr_metadata *md = md_v; 256 257 switch (md->ssdi.ssd_level) { 258 case 0: 259 return HR_LVL_0; 260 case 1: 261 return HR_LVL_1; 262 case 5: 263 return HR_LVL_5; 264 default: 265 return HR_LVL_UNKNOWN; 266 } 267 } 268 269 static uint64_t meta_softraid_get_data_offset(void) 270 { 271 return SR_DATA_OFFSET; 272 } 273 274 static size_t meta_softraid_get_size(void) 275 { 276 return SR_META_SIZE; 277 } 278 279 static uint8_t meta_softraid_get_flags(void) 280 { 281 uint8_t flags = 0; 282 283 return flags; 284 } 285 286 static hr_metadata_type_t meta_softraid_get_type(void) 287 { 288 return HR_METADATA_SOFTRAID; 289 } 290 291 static void meta_softraid_dump(const void *md_v) 292 { 293 HR_DEBUG("%s()", __func__); 294 295 const struct sr_metadata *md = md_v; 296 297 sr_meta_print(md); 298 } 299 300 static void *meta_softraid_alloc_struct(void) 301 { 302 return calloc(1, SR_META_SIZE * DEV_BSIZE); 303 } 304 305 #if 0 183 306 static void meta_softraid_encode(void *md_v, void *block) 184 307 { … … 188 311 (void)block; 189 312 } 313 #endif 190 314 191 315 static errno_t meta_softraid_decode(const void *block, void *md_v) … … 372 496 } 373 497 498 #if 0 374 499 static errno_t meta_softraid_write_block(service_id_t dev, const void *block) 375 500 { … … 398 523 return rc; 399 524 } 525 #endif 400 526 401 527 static bool meta_softraid_has_valid_magic(const void *md_v) … … 411 537 } 412 538 413 static bool meta_softraid_compare_uuids(const void *m1_v, const void *m2_v)414 {415 const struct sr_metadata *m1 = m1_v;416 const struct sr_metadata *m2 = m2_v;417 if (memcmp(&m1->ssdi.ssd_uuid, &m2->ssdi.ssd_uuid,418 SR_UUID_MAX) == 0)419 return true;420 421 return false;422 }423 424 static void meta_softraid_inc_counter(hr_volume_t *vol)425 {426 fibril_mutex_lock(&vol->md_lock);427 428 struct sr_metadata *md = vol->in_mem_md;429 430 md->ssd_ondisk++;431 432 fibril_mutex_unlock(&vol->md_lock);433 }434 435 static errno_t meta_softraid_save(hr_volume_t *vol, bool with_state_callback)436 {437 HR_DEBUG("%s()", __func__);438 439 return ENOTSUP;440 }441 442 static errno_t meta_softraid_save_ext(hr_volume_t *vol, size_t ext_idx,443 bool with_state_callback)444 {445 HR_DEBUG("%s()", __func__);446 447 return ENOTSUP;448 }449 450 static const char *meta_softraid_get_devname(const void *md_v)451 {452 const struct sr_metadata *md = md_v;453 454 return md->ssd_devname;455 }456 457 static hr_level_t meta_softraid_get_level(const void *md_v)458 {459 const struct sr_metadata *md = md_v;460 461 switch (md->ssdi.ssd_level) {462 case 0:463 return HR_LVL_0;464 case 1:465 return HR_LVL_1;466 case 5:467 return HR_LVL_5;468 default:469 return HR_LVL_UNKNOWN;470 }471 }472 473 static uint64_t meta_softraid_get_data_offset(void)474 {475 return SR_DATA_OFFSET;476 }477 478 static size_t meta_softraid_get_size(void)479 {480 return SR_META_SIZE;481 }482 483 static uint8_t meta_softraid_get_flags(void)484 {485 uint8_t flags = 0;486 487 return flags;488 }489 490 static hr_metadata_type_t meta_softraid_get_type(void)491 {492 return HR_METADATA_SOFTRAID;493 }494 495 static void meta_softraid_dump(const void *md_v)496 {497 HR_DEBUG("%s()", __func__);498 499 const struct sr_metadata *md = md_v;500 501 sr_meta_print(md);502 }503 504 539 /** @} 505 540 */
Note:
See TracChangeset
for help on using the changeset viewer.
