Changeset c9ce6d22 in mainline


Ignore:
Timestamp:
2025-05-15T19:24:51Z (3 weeks ago)
Author:
Miroslav Cimerman <mc@…>
Children:
a2281efc
Parents:
9a3eec1
Message:

hr: refactor volume removal

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

Legend:

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

    r9a3eec1 rc9ce6d22  
    296296        errno_t rc = EOK;
    297297        service_id_t svc_id;
    298         hr_volume_t *vol;
    299298
    300299        svc_id = ipc_get_arg1(icall);
    301300
    302         vol = hr_get_volume(svc_id);
    303         if (vol == NULL) {
    304                 async_answer_0(icall, ENOENT);
    305                 return;
    306         }
    307 
    308         rc = hr_remove_volume(vol);
     301        rc = hr_remove_volume(svc_id);
    309302
    310303        async_answer_0(icall, rc);
     
    319312        HR_DEBUG("%s()", __func__);
    320313
    321         hr_volume_t *vol;
     314        service_id_t *vol_svcs = NULL;
    322315        errno_t rc = EOK;
    323 
    324         while (true) {
    325                 fibril_rwlock_write_lock(&hr_volumes_lock);
    326                 if (list_empty(&hr_volumes)) {
    327                         fibril_rwlock_write_unlock(&hr_volumes_lock);
    328                         break;
    329                 }
    330 
    331                 vol = list_pop(&hr_volumes, hr_volume_t, lvolumes);
    332 
    333                 fibril_rwlock_write_unlock(&hr_volumes_lock);
    334 
    335                 rc = hr_remove_volume(vol);
     316        size_t i, vol_cnt;
     317
     318        rc = hr_get_volume_svcs(&vol_cnt, &vol_svcs);
     319        if (rc != EOK)
     320                goto fail;
     321
     322        for (i = 0; i < vol_cnt; i++) {
     323                rc = hr_remove_volume(vol_svcs[i]);
    336324                if (rc != EOK)
    337325                        break;
    338326        }
    339327
     328fail:
     329        if (vol_svcs != NULL)
     330                free(vol_svcs);
    340331        async_answer_0(icall, rc);
    341332}
  • uspace/srv/bd/hr/util.c

    r9a3eec1 rc9ce6d22  
    215215                }
    216216        }
    217 
    218217        fibril_rwlock_read_unlock(&hr_volumes_lock);
     218
    219219        return rvol;
    220220}
    221221
    222 errno_t hr_remove_volume(hr_volume_t *vol)
    223 {
    224         HR_DEBUG("%s()", __func__);
     222errno_t hr_remove_volume(service_id_t svc_id)
     223{
     224        HR_DEBUG("%s()", __func__);
     225
     226        hr_volume_t *vol = hr_get_volume(svc_id);
     227        if (vol == NULL)
     228                return ENOENT;
    225229
    226230        fibril_rwlock_write_lock(&hr_volumes_lock);
     
    228232        int open_cnt = atomic_load_explicit(&vol->open_cnt,
    229233            memory_order_relaxed);
     234
    230235        /*
    231236         * The atomicity of this if condition (and this whole
     
    246251        /* save metadata, but we don't care about states anymore */
    247252        (void)vol->meta_ops->save(vol, NO_STATE_CALLBACK);
    248 
    249         service_id_t svc_id = vol->svc_id;
    250253
    251254        HR_NOTE("deactivating volume \"%s\"\n", vol->devname);
  • uspace/srv/bd/hr/util.h

    r9a3eec1 rc9ce6d22  
    7272extern errno_t           hr_get_volume_svcs(size_t *, service_id_t **);
    7373extern hr_volume_t      *hr_get_volume(service_id_t);
    74 extern errno_t           hr_remove_volume(hr_volume_t *);
     74extern errno_t           hr_remove_volume(service_id_t);
    7575extern errno_t           hr_init_extents_from_cfg(hr_volume_t *, hr_config_t *);
    7676extern void              hr_fini_devs(hr_volume_t *);
Note: See TracChangeset for help on using the changeset viewer.