Ignore:
Timestamp:
2025-06-27T22:21:05Z (9 months ago)
Author:
Miroslav Cimerman <mc@…>
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)
Message:

hr: let each format implement own probe

This will allow metadata to have superblocks in
different locations accross versions.

This also greatly reduces the format handling interface,
because now, functions used by the probing done
publicly in superblock.c are now used just
inside specific metadata format code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/metadata/foreign/softraid/hr_softraid.c

    r78433bb raa9bad8  
    5454#include "softraidvar.h"
    5555
     56/* not exposed */
    5657static void *meta_softraid_alloc_struct(void);
     58/* static void meta_softraid_encode(void *, void *); */
     59static errno_t meta_softraid_decode(const void *, void *);
     60static errno_t meta_softraid_get_block(service_id_t, void **);
     61/* static errno_t meta_softraid_write_block(service_id_t, const void *); */
     62static bool meta_softraid_has_valid_magic(const void *);
     63
     64static errno_t meta_softraid_probe(service_id_t, void **);
    5765static errno_t meta_softraid_init_vol2meta(hr_volume_t *);
    5866static 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 *);
    6467static bool meta_softraid_compare_uuids(const void *, const void *);
    6568static void meta_softraid_inc_counter(hr_volume_t *);
     
    7578
    7679hr_superblock_ops_t metadata_softraid_ops = {
    77         .alloc_struct = meta_softraid_alloc_struct,
     80        .probe = meta_softraid_probe,
    7881        .init_vol2meta = meta_softraid_init_vol2meta,
    7982        .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,
    8583        .compare_uuids = meta_softraid_compare_uuids,
    8684        .inc_counter = meta_softraid_inc_counter,
     
    9694};
    9795
    98 static void *meta_softraid_alloc_struct(void)
    99 {
    100         return calloc(1, SR_META_SIZE * DEV_BSIZE);
     96static 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
     124error:
     125        free(metadata_struct);
     126        return ENOFS;
    101127}
    102128
     
    181207}
    182208
     209static 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
     220static 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
     231static 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
     238static 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
     246static 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
     253static 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
     269static uint64_t meta_softraid_get_data_offset(void)
     270{
     271        return SR_DATA_OFFSET;
     272}
     273
     274static size_t meta_softraid_get_size(void)
     275{
     276        return SR_META_SIZE;
     277}
     278
     279static uint8_t meta_softraid_get_flags(void)
     280{
     281        uint8_t flags = 0;
     282
     283        return flags;
     284}
     285
     286static hr_metadata_type_t meta_softraid_get_type(void)
     287{
     288        return HR_METADATA_SOFTRAID;
     289}
     290
     291static 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
     300static void *meta_softraid_alloc_struct(void)
     301{
     302        return calloc(1, SR_META_SIZE * DEV_BSIZE);
     303}
     304
     305#if 0
    183306static void meta_softraid_encode(void *md_v, void *block)
    184307{
     
    188311        (void)block;
    189312}
     313#endif
    190314
    191315static errno_t meta_softraid_decode(const void *block, void *md_v)
     
    372496}
    373497
     498#if 0
    374499static errno_t meta_softraid_write_block(service_id_t dev, const void *block)
    375500{
     
    398523        return rc;
    399524}
     525#endif
    400526
    401527static bool meta_softraid_has_valid_magic(const void *md_v)
     
    411537}
    412538
    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 
    504539/** @}
    505540 */
Note: See TracChangeset for help on using the changeset viewer.