Changeset da80de9 in mainline


Ignore:
Timestamp:
2025-06-07T11:52:34Z (8 days ago)
Author:
Miroslav Cimerman <mc@…>
Children:
d482b05
Parents:
49da044
Message:

hr: move state callback to hr_ops_t

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

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/hr.c

    r49da044 rda80de9  
    376376        fibril_rwlock_read_unlock(&vol->extents_lock);
    377377
    378         vol->hr_ops.state_event(vol);
     378        vol->hr_ops.vol_state_eval(vol);
    379379
    380380        async_answer_0(icall, EOK);
  • uspace/srv/bd/hr/io.c

    r49da044 rda80de9  
    6060         */
    6161        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);
    6363
    6464        return rc;
  • uspace/srv/bd/hr/metadata/native.c

    r49da044 rda80de9  
    389389                rc = meta_native_write_block(ext->svc_id, md_block);
    390390                if (with_state_callback && rc != EOK)
    391                         vol->state_callback(vol, i, rc);
     391                        vol->hr_ops.ext_state_cb(vol, i, rc);
    392392        }
    393393
     
    397397
    398398        if (with_state_callback)
    399                 vol->hr_ops.state_event(vol);
     399                vol->hr_ops.vol_state_eval(vol);
    400400
    401401        free(md_block);
  • uspace/srv/bd/hr/raid0.c

    r49da044 rda80de9  
    5353#include "var.h"
    5454
    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);
    5755static errno_t hr_raid0_bd_op(hr_bd_op_type_t, bd_srv_t *, aoff64_t, size_t,
    5856    void *, const void *, size_t);
     
    9290        }
    9391
    94         hr_raid0_update_vol_state(new_volume);
     92        hr_raid0_vol_state_eval(new_volume);
    9593        if (new_volume->state != HR_VOL_ONLINE) {
    9694                HR_NOTE("\"%s\": unusable state, not creating\n",
     
    103101        new_volume->hr_bds.sarg = new_volume;
    104102
    105         new_volume->state_callback = hr_raid0_state_callback;
    106 
    107103        return EOK;
    108104}
     
    130126}
    131127
    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 {
     128void hr_raid0_vol_state_eval(hr_volume_t *vol)
     129{
     130        HR_DEBUG("%s()", __func__);
     131
    196132        fibril_mutex_lock(&vol->md_lock);
    197133
     
    226162}
    227163
    228 static void hr_raid0_state_callback(hr_volume_t *vol, size_t extent, errno_t rc)
    229 {
     164void hr_raid0_ext_state_cb(hr_volume_t *vol, size_t extent, errno_t rc)
     165{
     166        HR_DEBUG("%s()", __func__);
     167
    230168        if (rc == EOK)
    231169                return;
     
    246184}
    247185
     186static 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
     197static 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
     208static 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
     213static 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
     219static 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
     225static 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
     233static 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
    248241static errno_t hr_raid0_bd_op(hr_bd_op_type_t type, bd_srv_t *bd, aoff64_t ba,
    249242    size_t cnt, void *dst, const void *src, size_t size)
    250243{
     244        HR_DEBUG("%s()", __func__);
     245
    251246        hr_volume_t *vol = bd->srvs->sarg;
    252247        errno_t rc;
  • uspace/srv/bd/hr/raid1.c

    r49da044 rda80de9  
    5656#include "var.h"
    5757
    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);
    6058static size_t hr_raid1_count_good_extents(hr_volume_t *, uint64_t, size_t,
    6159    uint64_t);
     
    106104        new_volume->hr_bds.sarg = new_volume;
    107105
    108         new_volume->state_callback = hr_raid1_ext_state_callback;
    109 
    110106        /* force volume state update */
    111107        hr_mark_vol_state_dirty(new_volume);
    112         hr_raid1_update_vol_state(new_volume);
     108        hr_raid1_vol_state_eval(new_volume);
    113109
    114110        fibril_rwlock_read_lock(&new_volume->states_lock);
     
    140136}
    141137
    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 
    149138errno_t hr_raid1_add_hotspare(hr_volume_t *vol, service_id_t hotspare)
    150139{
     
    153142        errno_t rc = hr_util_add_hotspare(vol, hotspare);
    154143
    155         hr_raid1_update_vol_state(vol);
     144        hr_raid1_vol_state_eval(vol);
    156145
    157146        return rc;
    158147}
    159148
    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 {
     149void hr_raid1_vol_state_eval(hr_volume_t *vol)
     150{
     151        HR_DEBUG("%s()", __func__);
     152
    217153        bool exp = true;
    218154
     
    271207}
    272208
    273 static void hr_raid1_ext_state_callback(hr_volume_t *vol, size_t extent,
     209void hr_raid1_ext_state_cb(hr_volume_t *vol, size_t extent,
    274210    errno_t rc)
    275211{
     212        HR_DEBUG("%s()", __func__);
     213
    276214        if (rc == EOK)
    277215                return;
     
    297235}
    298236
     237static 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
     248static 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
     259static 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
     264static 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
     270static 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
     276static 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
     284static 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
    299292static size_t hr_raid1_count_good_extents(hr_volume_t *vol, uint64_t ba,
    300293    size_t cnt, uint64_t rebuild_blk)
     
    319312    size_t cnt, void *data_read, const void *data_write, size_t size)
    320313{
     314        HR_DEBUG("%s()", __func__);
     315
    321316        hr_volume_t *vol = bd->srvs->sarg;
    322317        hr_range_lock_t *rl = NULL;
     
    377372
    378373                        if (rc != EOK) {
    379                                 hr_raid1_ext_state_callback(vol, i, rc);
     374                                hr_raid1_ext_state_cb(vol, i, rc);
    380375                        } else {
    381376                                successful++;
     
    458453        fibril_rwlock_read_unlock(&vol->extents_lock);
    459454
    460         hr_raid1_update_vol_state(vol);
     455        hr_raid1_vol_state_eval(vol);
    461456
    462457        return rc;
     
    565560        fibril_rwlock_read_unlock(&vol->extents_lock);
    566561
    567         hr_raid1_update_vol_state(vol);
     562        hr_raid1_vol_state_eval(vol);
    568563
    569564        if (buf != NULL)
     
    690685
    691686                if (rc != ENOMEM)
    692                         hr_raid1_ext_state_callback(vol, i, rc);
     687                        hr_raid1_ext_state_cb(vol, i, rc);
    693688
    694689                if (i + 1 >= vol->extent_no) {
     
    705700                                    "because of not enough memory\n",
    706701                                    vol->devname, vol->svc_id);
    707                                 hr_raid1_ext_state_callback(vol, rebuild_idx,
     702                                hr_raid1_ext_state_cb(vol, rebuild_idx,
    708703                                    ENOMEM);
    709704                        }
     
    723718                 * XXX: for now we do
    724719                 */
    725                 hr_raid1_ext_state_callback(vol, rebuild_idx, rc);
     720                hr_raid1_ext_state_cb(vol, rebuild_idx, rc);
    726721
    727722                HR_ERROR("rebuild on \"%s\" (%" PRIun "), failed due to "
  • uspace/srv/bd/hr/raid5.c

    r49da044 rda80de9  
    5757static ssize_t hr_raid5_get_bad_ext(hr_volume_t *);
    5858static 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);
    6059static void xor(void *, const void *, size_t);
    6160
     
    148147}
    149148
    150 void hr_raid5_state_event(hr_volume_t *vol)
     149void hr_raid5_vol_state_eval(hr_volume_t *vol)
    151150{
    152151        fibril_mutex_lock(&vol->lock);
     
    189188}
    190189
     190void 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
    191199static errno_t hr_raid5_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
    192200{
     
    299307                return EIO;
    300308        }
    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);
    310309}
    311310
     
    648647                        goto error;
    649648
    650                 hr_raid5_handle_extent_error(vol, extent, rc);
     649                hr_raid5_ext_state_cb(vol, extent, rc);
    651650
    652651                if (rc != EOK) {
     
    802801                                    ba, cnt, buf);
    803802                        if (rc != EOK) {
    804                                 hr_raid5_handle_extent_error(vol, i, rc);
     803                                hr_raid5_ext_state_cb(vol, i, rc);
    805804                                HR_ERROR("rebuild on \"%s\" (%" PRIun "), "
    806805                                    "failed due to a failed ONLINE extent, "
     
    818817                rc = block_write_direct(rebuild_ext->svc_id, ba, cnt, xorbuf);
    819818                if (rc != EOK) {
    820                         hr_raid5_handle_extent_error(vol, bad, rc);
     819                        hr_raid5_ext_state_cb(vol, bad, rc);
    821820                        HR_ERROR("rebuild on \"%s\" (%" PRIun "), failed due to "
    822821                            "the rebuilt extent number %zu failing\n",
  • uspace/srv/bd/hr/util.c

    r49da044 rda80de9  
    9898                vol->hr_ops.create = hr_raid0_create;
    9999                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;
    101102                break;
    102103        case HR_LVL_1:
    103104                vol->hr_ops.create = hr_raid1_create;
    104105                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;
    106108                if (meta_flags & HR_METADATA_HOTSPARE_SUPPORT)
    107109                        vol->hr_ops.add_hotspare = hr_raid1_add_hotspare;
     
    111113                vol->hr_ops.create = hr_raid5_create;
    112114                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;
    114117                if (meta_flags & HR_METADATA_HOTSPARE_SUPPORT)
    115118                        vol->hr_ops.add_hotspare = hr_raid5_add_hotspare;
  • uspace/srv/bd/hr/var.h

    r49da044 rda80de9  
    5858        errno_t (*create)(hr_volume_t *);
    5959        errno_t (*init)(hr_volume_t *);
    60         void (*state_event)(hr_volume_t *);
    6160        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);
    6263} hr_ops_t;
    6364
     
    104105        _Atomic int open_cnt; /* open/close() counter */
    105106        hr_vol_state_t state; /* volume state */
    106         void (*state_callback)(hr_volume_t *, size_t, errno_t);
    107107} hr_volume_t;
    108108
     
    136136extern errno_t hr_raid5_init(hr_volume_t *);
    137137
    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 
    142138extern errno_t hr_raid1_add_hotspare(hr_volume_t *, service_id_t);
    143139extern errno_t hr_raid5_add_hotspare(hr_volume_t *, service_id_t);
    144140
     141extern void hr_raid0_vol_state_eval(hr_volume_t *);
     142extern void hr_raid1_vol_state_eval(hr_volume_t *);
     143extern void hr_raid5_vol_state_eval(hr_volume_t *);
     144
     145extern void hr_raid0_ext_state_cb(hr_volume_t *, size_t, errno_t);
     146extern void hr_raid1_ext_state_cb(hr_volume_t *, size_t, errno_t);
     147extern void hr_raid5_ext_state_cb(hr_volume_t *, size_t, errno_t);
    145148#endif
    146149
Note: See TracChangeset for help on using the changeset viewer.