Changeset 7fba146 in mainline


Ignore:
Timestamp:
2025-06-09T23:41:50Z (7 days ago)
Author:
Miroslav Cimerman <mc@…>
Children:
6791fbf
Parents:
83ff12f
Message:

hr: RAID 1: inc meta counter on first write

Location:
uspace/srv/bd/hr
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/metadata/foreign/geom/hr_g_mirror.c

    r83ff12f r7fba146  
    6262static bool meta_gmirror_has_valid_magic(const void *);
    6363static bool meta_gmirror_compare_uuids(const void *, const void *);
    64 static void meta_gmirror_inc_counter(void *);
     64static void meta_gmirror_inc_counter(hr_volume_t *);
    6565static errno_t meta_gmirror_save(hr_volume_t *, bool);
    6666static const char *meta_gmirror_get_devname(const void *);
     
    284284}
    285285
    286 static void meta_gmirror_inc_counter(void *md_v)
    287 {
    288         struct g_mirror_metadata *md = md_v;
     286static void meta_gmirror_inc_counter(hr_volume_t *vol)
     287{
     288        fibril_mutex_lock(&vol->md_lock);
     289
     290        struct g_mirror_metadata *md = vol->in_mem_md;
    289291
    290292        /* XXX: probably md_genid and not md_syncid is incremented */
    291293        md->md_genid++;
     294
     295        fibril_mutex_unlock(&vol->md_lock);
    292296}
    293297
  • uspace/srv/bd/hr/metadata/foreign/geom/hr_g_stripe.c

    r83ff12f r7fba146  
    6262static bool meta_gstripe_has_valid_magic(const void *);
    6363static bool meta_gstripe_compare_uuids(const void *, const void *);
    64 static void meta_gstripe_inc_counter(void *);
     64static void meta_gstripe_inc_counter(hr_volume_t *);
    6565static errno_t meta_gstripe_save(hr_volume_t *, bool);
    6666static const char *meta_gstripe_get_devname(const void *);
     
    286286}
    287287
    288 static void meta_gstripe_inc_counter(void *md_v)
    289 {
    290         (void)md_v;
     288static void meta_gstripe_inc_counter(hr_volume_t *vol)
     289{
     290        (void)vol;
    291291}
    292292
  • uspace/srv/bd/hr/metadata/foreign/softraid/hr_softraid.c

    r83ff12f r7fba146  
    6262static bool meta_softraid_has_valid_magic(const void *);
    6363static bool meta_softraid_compare_uuids(const void *, const void *);
    64 static void meta_softraid_inc_counter(void *);
     64static void meta_softraid_inc_counter(hr_volume_t *);
    6565static errno_t meta_softraid_save(hr_volume_t *, bool);
    6666static const char *meta_softraid_get_devname(const void *);
     
    419419}
    420420
    421 static void meta_softraid_inc_counter(void *md_v)
    422 {
    423         struct sr_metadata *md = md_v;
     421static void meta_softraid_inc_counter(hr_volume_t *vol)
     422{
     423        fibril_mutex_lock(&vol->md_lock);
     424
     425        struct sr_metadata *md = vol->in_mem_md;
    424426
    425427        md->ssd_ondisk++;
     428
     429        fibril_mutex_unlock(&vol->md_lock);
    426430}
    427431
  • uspace/srv/bd/hr/metadata/native.c

    r83ff12f r7fba146  
    6363static bool meta_native_has_valid_magic(const void *);
    6464static bool meta_native_compare_uuids(const void *, const void *);
    65 static void meta_native_inc_counter(void *);
     65static void meta_native_inc_counter(hr_volume_t *);
    6666static errno_t meta_native_save(hr_volume_t *, bool);
    6767static const char *meta_native_get_devname(const void *);
     
    365365}
    366366
    367 static void meta_native_inc_counter(void *md_v)
    368 {
    369         hr_metadata_t *md = md_v;
     367static void meta_native_inc_counter(hr_volume_t *vol)
     368{
     369        fibril_mutex_lock(&vol->md_lock);
     370
     371        hr_metadata_t *md = vol->in_mem_md;
    370372
    371373        md->counter++;
     374
     375        fibril_mutex_unlock(&vol->md_lock);
    372376}
    373377
     
    409413                meta_native_encode(md, md_block);
    410414                rc = meta_native_write_block(ext->svc_id, md_block);
    411                 if (with_state_callback && rc != EOK)
     415                if (rc != EOK && with_state_callback)
    412416                        vol->hr_ops.ext_state_cb(vol, i, rc);
    413417        }
  • uspace/srv/bd/hr/raid1.c

    r83ff12f r7fba146  
    5656#include "var.h"
    5757
     58static void hr_raid1_vol_state_eval_forced(hr_volume_t *);
    5859static size_t hr_raid1_count_good_extents(hr_volume_t *, uint64_t, size_t,
    5960    uint64_t);
     
    105106        new_volume->hr_bds.sarg = new_volume;
    106107
    107         /* force volume state update */
    108         hr_mark_vol_state_dirty(new_volume);
    109         hr_raid1_vol_state_eval(new_volume);
     108        hr_raid1_vol_state_eval_forced(new_volume);
    110109
    111110        fibril_rwlock_read_lock(&new_volume->states_lock);
     
    155154        bool exp = true;
    156155
    157         /* TODO: could also wrap this */
    158156        if (!atomic_compare_exchange_strong(&vol->state_dirty, &exp, false))
    159157                return;
    160158
    161         fibril_mutex_lock(&vol->md_lock);
    162 
    163         vol->meta_ops->inc_counter(vol->in_mem_md);
    164         /* XXX: save right away */
    165 
    166         fibril_mutex_unlock(&vol->md_lock);
     159        vol->meta_ops->inc_counter(vol);
     160        (void)vol->meta_ops->save(vol, WITH_STATE_CALLBACK);
     161
     162        hr_raid1_vol_state_eval_forced(vol);
     163}
     164
     165void hr_raid1_ext_state_cb(hr_volume_t *vol, size_t extent,
     166    errno_t rc)
     167{
     168        HR_DEBUG("%s()", __func__);
     169
     170        if (rc == EOK)
     171                return;
     172
     173        assert(fibril_rwlock_is_locked(&vol->extents_lock));
     174
     175        fibril_rwlock_write_lock(&vol->states_lock);
     176
     177        switch (rc) {
     178        case ENOMEM:
     179                hr_update_ext_state(vol, extent, HR_EXT_INVALID);
     180                break;
     181        case ENOENT:
     182                hr_update_ext_state(vol, extent, HR_EXT_MISSING);
     183                break;
     184        default:
     185                hr_update_ext_state(vol, extent, HR_EXT_FAILED);
     186        }
     187
     188        hr_mark_vol_state_dirty(vol);
     189
     190        fibril_rwlock_write_unlock(&vol->states_lock);
     191}
     192
     193static void hr_raid1_vol_state_eval_forced(hr_volume_t *vol)
     194{
     195        HR_DEBUG("%s()", __func__);
    167196
    168197        fibril_rwlock_read_lock(&vol->extents_lock);
     
    209238}
    210239
    211 void hr_raid1_ext_state_cb(hr_volume_t *vol, size_t extent,
    212     errno_t rc)
    213 {
    214         HR_DEBUG("%s()", __func__);
    215 
    216         if (rc == EOK)
    217                 return;
    218 
    219         assert(fibril_rwlock_is_locked(&vol->extents_lock));
    220 
    221         fibril_rwlock_write_lock(&vol->states_lock);
    222 
    223         switch (rc) {
    224         case ENOMEM:
    225                 hr_update_ext_state(vol, extent, HR_EXT_INVALID);
    226                 break;
    227         case ENOENT:
    228                 hr_update_ext_state(vol, extent, HR_EXT_MISSING);
    229                 break;
    230         default:
    231                 hr_update_ext_state(vol, extent, HR_EXT_FAILED);
    232         }
    233 
    234         hr_mark_vol_state_dirty(vol);
    235 
    236         fibril_rwlock_write_unlock(&vol->states_lock);
    237 }
    238 
    239240static errno_t hr_raid1_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    240241{
     
    328329        if (vol_state == HR_VOL_FAULTY || vol_state == HR_VOL_NONE)
    329330                return EIO;
     331
     332        if (!vol->data_dirty && type == HR_BD_WRITE) {
     333                vol->meta_ops->inc_counter(vol);
     334                vol->data_dirty = true;
     335        }
    330336
    331337        if (type == HR_BD_READ || type == HR_BD_WRITE)
     
    543549        fibril_rwlock_write_unlock(&vol->states_lock);
    544550
    545         rc = vol->meta_ops->save(vol, WITH_STATE_CALLBACK);
     551        (void)vol->meta_ops->save(vol, WITH_STATE_CALLBACK);
    546552
    547553end:
  • uspace/srv/bd/hr/superblock.c

    r83ff12f r7fba146  
    5050#include "var.h"
    5151
     52#include "metadata/native.h"
     53
    5254#include "metadata/foreign/geom/g_mirror.h"
    5355#include "metadata/foreign/geom/g_stripe.h"
    5456#include "metadata/foreign/softraid/softraidvar.h"
    55 
    56 #include "metadata/native.h"
    5757
    5858extern hr_superblock_ops_t metadata_native_ops;
  • uspace/srv/bd/hr/superblock.h

    r83ff12f r7fba146  
    5454        bool (*has_valid_magic)(const void *);
    5555        bool (*compare_uuids)(const void *, const void *);
    56         void (*inc_counter)(void *);
     56        void (*inc_counter)(hr_volume_t *);
    5757        errno_t (*save)(hr_volume_t *, bool);
    5858        const char *(*get_devname)(const void *);
  • uspace/srv/bd/hr/util.c

    r83ff12f r7fba146  
    151151        fibril_mutex_initialize(&vol->range_lock_list_lock);
    152152
     153        atomic_init(&vol->state_dirty, false);
     154        atomic_init(&vol->data_dirty, false);
    153155        atomic_init(&vol->rebuild_blk, 0);
    154         atomic_init(&vol->state_dirty, false);
    155156        atomic_init(&vol->open_cnt, 0);
    156157
     
    857858        meta_ops->init_meta2vol(list, vol);
    858859
    859         /*
    860          * TODO: something like mark md dirty or whatever
    861          *      - probably will be handled by each md type differently,
    862          *        by specific function pointers
    863          *      - deal with this when foreign md will be handled
    864          *
    865          * XXX: if thats the only thing that can change in metadata
    866          * during volume runtime, then whatever, but if more
    867          * things will need to be synced, think of something more clever
    868          *
    869          * TODO: remove from here and increment it the "first" time (if nothing
    870          * happens - no state changes, no rebuild, etc) - only after the first
    871          * write... but for now leave it here
    872          */
    873         (void)vol->meta_ops->inc_counter(vol->in_mem_md);
    874 
    875860        rc = vol->hr_ops.create(vol);
    876861        if (rc != EOK)
    877862                goto error;
    878863
    879         /*
    880          * XXX: register it here
    881          * ... if it fails on EEXIST try different name... like + 1 on the end
    882          *
    883          * or have metadata edit utility as a part of hrctl..., or create
    884          * the original name + 4 random characters, tell the user that the device
    885          * was created with this new name, and add a option to hrctl to rename
    886          * an active array, and then write the new dirty metadata...
    887          *
    888          * or just refuse to assemble a name that is already used...
    889          *
    890          * TODO: discuss
    891          */
    892864        rc = hr_register_volume(vol);
    893865        if (rc != EOK)
    894866                goto error;
    895 
    896         (void)vol->meta_ops->save(vol, WITH_STATE_CALLBACK);
    897867
    898868        fibril_rwlock_write_lock(&hr_volumes_lock);
  • uspace/srv/bd/hr/var.h

    r83ff12f r7fba146  
    101101        _Atomic bool state_dirty; /* dirty state */
    102102
     103        /*
     104         * used to increment metadata counter on first write,
     105         * allowing non-destructive read-only access
     106         */
     107        _Atomic bool data_dirty;
     108
    103109        /* XXX: atomic_uint_least64_t? */
    104110        _Atomic uint64_t rebuild_blk; /* rebuild position */
Note: See TracChangeset for help on using the changeset viewer.