Ignore:
Timestamp:
2025-06-27T22:21:05Z (11 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/geom/hr_g_stripe.c

    r78433bb raa9bad8  
    5454#include "g_stripe.h"
    5555
     56/* not exposed */
    5657static void *meta_gstripe_alloc_struct(void);
     58/* static void meta_gstripe_encode(void *, void *); */
     59static errno_t meta_gstripe_decode(const void *, void *);
     60static errno_t meta_gstripe_get_block(service_id_t, void **);
     61/* static errno_t meta_gstripe_write_block(service_id_t, const void *); */
     62static bool meta_gstripe_has_valid_magic(const void *);
     63
     64static errno_t meta_gstripe_probe(service_id_t, void **);
    5765static errno_t meta_gstripe_init_vol2meta(hr_volume_t *);
    5866static errno_t meta_gstripe_init_meta2vol(const list_t *, hr_volume_t *);
    59 static void meta_gstripe_encode(void *, void *);
    60 static errno_t meta_gstripe_decode(const void *, void *);
    61 static errno_t meta_gstripe_get_block(service_id_t, void **);
    62 static errno_t meta_gstripe_write_block(service_id_t, const void *);
    63 static bool meta_gstripe_has_valid_magic(const void *);
    6467static bool meta_gstripe_compare_uuids(const void *, const void *);
    6568static void meta_gstripe_inc_counter(hr_volume_t *);
     
    7578
    7679hr_superblock_ops_t metadata_gstripe_ops = {
    77         .alloc_struct = meta_gstripe_alloc_struct,
     80        .probe = meta_gstripe_probe,
    7881        .init_vol2meta = meta_gstripe_init_vol2meta,
    7982        .init_meta2vol = meta_gstripe_init_meta2vol,
    80         .encode = meta_gstripe_encode,
    81         .decode = meta_gstripe_decode,
    82         .get_block = meta_gstripe_get_block,
    83         .write_block = meta_gstripe_write_block,
    84         .has_valid_magic = meta_gstripe_has_valid_magic,
    8583        .compare_uuids = meta_gstripe_compare_uuids,
    8684        .inc_counter = meta_gstripe_inc_counter,
     
    9694};
    9795
    98 static void *meta_gstripe_alloc_struct(void)
    99 {
    100         return calloc(1, sizeof(struct g_stripe_metadata));
     96static errno_t meta_gstripe_probe(service_id_t svc_id, void **rmd)
     97{
     98        errno_t rc;
     99        void *meta_block;
     100
     101        void *metadata_struct = meta_gstripe_alloc_struct();
     102        if (metadata_struct == NULL)
     103                return ENOMEM;
     104
     105        rc = meta_gstripe_get_block(svc_id, &meta_block);
     106        if (rc != EOK)
     107                goto error;
     108
     109        rc = meta_gstripe_decode(meta_block, metadata_struct);
     110
     111        free(meta_block);
     112
     113        if (rc != EOK)
     114                goto error;
     115
     116        if (!meta_gstripe_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
     
    178204}
    179205
     206static bool meta_gstripe_compare_uuids(const void *md1_v, const void *md2_v)
     207{
     208        const struct g_stripe_metadata *md1 = md1_v;
     209        const struct g_stripe_metadata *md2 = md2_v;
     210        if (md1->md_id == md2->md_id)
     211                return true;
     212
     213        return false;
     214}
     215
     216static void meta_gstripe_inc_counter(hr_volume_t *vol)
     217{
     218        (void)vol;
     219}
     220
     221static errno_t meta_gstripe_save(hr_volume_t *vol, bool with_state_callback)
     222{
     223        HR_DEBUG("%s()", __func__);
     224
     225        return ENOTSUP;
     226}
     227
     228static errno_t meta_gstripe_save_ext(hr_volume_t *vol, size_t ext_idx,
     229    bool with_state_callback)
     230{
     231        HR_DEBUG("%s()", __func__);
     232
     233        return ENOTSUP;
     234}
     235
     236static const char *meta_gstripe_get_devname(const void *md_v)
     237{
     238        const struct g_stripe_metadata *md = md_v;
     239
     240        return md->md_name;
     241}
     242
     243static hr_level_t meta_gstripe_get_level(const void *md_v)
     244{
     245        (void)md_v;
     246
     247        return HR_LVL_0;
     248}
     249
     250static uint64_t meta_gstripe_get_data_offset(void)
     251{
     252        return 0;
     253}
     254
     255static size_t meta_gstripe_get_size(void)
     256{
     257        return 1;
     258}
     259
     260static uint8_t meta_gstripe_get_flags(void)
     261{
     262        uint8_t flags = 0;
     263
     264        return flags;
     265}
     266
     267static hr_metadata_type_t meta_gstripe_get_type(void)
     268{
     269        return HR_METADATA_GEOM_STRIPE;
     270}
     271
     272static void meta_gstripe_dump(const void *md_v)
     273{
     274        HR_DEBUG("%s()", __func__);
     275
     276        const struct g_stripe_metadata *md = md_v;
     277
     278        printf("     magic: %s\n", md->md_magic);
     279        printf("   version: %u\n", (u_int)md->md_version);
     280        printf("      name: %s\n", md->md_name);
     281        printf("        id: %u\n", (u_int)md->md_id);
     282        printf("        no: %u\n", (u_int)md->md_no);
     283        printf("       all: %u\n", (u_int)md->md_all);
     284        printf("stripesize: %u\n", (u_int)md->md_stripesize);
     285        printf(" mediasize: %jd\n", (intmax_t)md->md_provsize);
     286}
     287
     288static void *meta_gstripe_alloc_struct(void)
     289{
     290        return calloc(1, sizeof(struct g_stripe_metadata));
     291}
     292
     293#if 0
    180294static void meta_gstripe_encode(void *md_v, void *block)
    181295{
     
    184298        stripe_metadata_encode(md_v, block);
    185299}
     300#endif
    186301
    187302static errno_t meta_gstripe_decode(const void *block, void *md_v)
     
    239354}
    240355
     356#if 0
    241357static errno_t meta_gstripe_write_block(service_id_t dev, const void *block)
    242358{
     
    265381        return rc;
    266382}
     383#endif
    267384
    268385static bool meta_gstripe_has_valid_magic(const void *md_v)
     
    278395}
    279396
    280 static bool meta_gstripe_compare_uuids(const void *md1_v, const void *md2_v)
    281 {
    282         const struct g_stripe_metadata *md1 = md1_v;
    283         const struct g_stripe_metadata *md2 = md2_v;
    284         if (md1->md_id == md2->md_id)
    285                 return true;
    286 
    287         return false;
    288 }
    289 
    290 static void meta_gstripe_inc_counter(hr_volume_t *vol)
    291 {
    292         (void)vol;
    293 }
    294 
    295 static errno_t meta_gstripe_save(hr_volume_t *vol, bool with_state_callback)
    296 {
    297         HR_DEBUG("%s()", __func__);
    298 
    299         return ENOTSUP;
    300 }
    301 
    302 static errno_t meta_gstripe_save_ext(hr_volume_t *vol, size_t ext_idx,
    303     bool with_state_callback)
    304 {
    305         HR_DEBUG("%s()", __func__);
    306 
    307         return ENOTSUP;
    308 }
    309 
    310 static const char *meta_gstripe_get_devname(const void *md_v)
    311 {
    312         const struct g_stripe_metadata *md = md_v;
    313 
    314         return md->md_name;
    315 }
    316 
    317 static hr_level_t meta_gstripe_get_level(const void *md_v)
    318 {
    319         (void)md_v;
    320 
    321         return HR_LVL_0;
    322 }
    323 
    324 static uint64_t meta_gstripe_get_data_offset(void)
    325 {
    326         return 0;
    327 }
    328 
    329 static size_t meta_gstripe_get_size(void)
    330 {
    331         return 1;
    332 }
    333 
    334 static uint8_t meta_gstripe_get_flags(void)
    335 {
    336         uint8_t flags = 0;
    337 
    338         return flags;
    339 }
    340 
    341 static hr_metadata_type_t meta_gstripe_get_type(void)
    342 {
    343         return  HR_METADATA_GEOM_STRIPE;
    344 }
    345 
    346 static void meta_gstripe_dump(const void *md_v)
    347 {
    348         HR_DEBUG("%s()", __func__);
    349 
    350         const struct g_stripe_metadata *md = md_v;
    351 
    352         printf("     magic: %s\n", md->md_magic);
    353         printf("   version: %u\n", (u_int)md->md_version);
    354         printf("      name: %s\n", md->md_name);
    355         printf("        id: %u\n", (u_int)md->md_id);
    356         printf("        no: %u\n", (u_int)md->md_no);
    357         printf("       all: %u\n", (u_int)md->md_all);
    358         printf("stripesize: %u\n", (u_int)md->md_stripesize);
    359         printf(" mediasize: %jd\n", (intmax_t)md->md_provsize);
    360 }
    361 
    362397/** @}
    363398 */
Note: See TracChangeset for help on using the changeset viewer.