Changeset 1a9174e in mainline for uspace/srv/volsrv/part.c


Ignore:
Timestamp:
2018-06-29T15:35:50Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d3b2ffa
Parents:
72c72d4
git-author:
Jiri Svoboda <jiri@…> (2018-06-28 18:34:52)
git-committer:
Jiri Svoboda <jiri@…> (2018-06-29 15:35:50)
Message:

Volume server needs to react to partitions being removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/volsrv/part.c

    r72c72d4 r1a9174e  
    5151
    5252static errno_t vol_part_add_locked(service_id_t);
     53static void vol_part_remove_locked(vol_part_t *);
     54static errno_t vol_part_find_by_id_ref_locked(service_id_t, vol_part_t **);
     55
    5356static LIST_INITIALIZE(vol_parts); /* of vol_part_t */
    5457static FIBRIL_MUTEX_INITIALIZE(vol_parts_lock);
     
    8386}
    8487
    85 /** Check for new partitions */
     88/** Check for new and removed partitions */
    8689static errno_t vol_part_check_new(void)
    8790{
    8891        bool already_known;
     92        bool still_exists;
    8993        category_id_t part_cat;
    9094        service_id_t *svcs;
    9195        size_t count, i;
     96        link_t *cur, *next;
     97        vol_part_t *part;
    9298        errno_t rc;
    9399
     
    109115        }
    110116
     117        /* Check for new partitions */
    111118        for (i = 0; i < count; i++) {
    112119                already_known = false;
    113120
     121                // XXX Make this faster
    114122                list_foreach(vol_parts, lparts, vol_part_t, part) {
    115123                        if (part->svc_id == svcs[i]) {
     
    130138        }
    131139
     140        /* Check for removed partitions */
     141        cur = list_first(&vol_parts);
     142        while (cur != NULL) {
     143                next = list_next(cur, &vol_parts);
     144                part = list_get_instance(cur, vol_part_t, lparts);
     145
     146                still_exists = false;
     147                // XXX Make this faster
     148                for (i = 0; i < count; i++) {
     149                        if (part->svc_id == svcs[i]) {
     150                                still_exists = true;
     151                                break;
     152                        }
     153                }
     154
     155                if (!still_exists) {
     156                        log_msg(LOG_DEFAULT, LVL_NOTE, "Partition '%zu' is gone",
     157                            part->svc_id);
     158                        vol_part_remove_locked(part);
     159                }
     160
     161                cur = next;
     162        }
     163
     164        free(svcs);
     165
    132166        fibril_mutex_unlock(&vol_parts_lock);
    133167        return EOK;
     
    144178        }
    145179
     180        atomic_set(&part->refcnt, 1);
    146181        link_initialize(&part->lparts);
    147182        part->pcnt = vpc_empty;
     
    152187static void vol_part_delete(vol_part_t *part)
    153188{
     189        log_msg(LOG_DEFAULT, LVL_ERROR, "Freeing partition %p", part);
    154190        if (part == NULL)
    155191                return;
     
    263299}
    264300
    265 
    266301static errno_t vol_part_add_locked(service_id_t sid)
    267302{
     
    273308
    274309        /* Check for duplicates */
    275         rc = vol_part_find_by_id(sid, &part);
    276         if (rc == EOK)
     310        rc = vol_part_find_by_id_ref_locked(sid, &part);
     311        if (rc == EOK) {
     312                vol_part_del_ref(part);
    277313                return EEXIST;
     314        }
    278315
    279316        log_msg(LOG_DEFAULT, LVL_NOTE, "partition %zu is new", sid);
     
    308345        vol_part_delete(part);
    309346        return rc;
     347}
     348
     349static void vol_part_remove_locked(vol_part_t *part)
     350{
     351        assert(fibril_mutex_is_locked(&vol_parts_lock));
     352        log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_remove_locked(%zu)", part->svc_id);
     353
     354        list_remove(&part->lparts);
     355
     356        log_msg(LOG_DEFAULT, LVL_NOTE, "Removed partition.");
     357        vol_part_del_ref(part);
    310358}
    311359
     
    374422}
    375423
    376 errno_t vol_part_find_by_id(service_id_t sid, vol_part_t **rpart)
    377 {
     424static errno_t vol_part_find_by_id_ref_locked(service_id_t sid,
     425    vol_part_t **rpart)
     426{
     427        assert(fibril_mutex_is_locked(&vol_parts_lock));
     428
    378429        list_foreach(vol_parts, lparts, vol_part_t, part) {
    379430                if (part->svc_id == sid) {
     431                        /* Add reference */
     432                        atomic_inc(&part->refcnt);
    380433                        *rpart = part;
    381                         /* XXX Add reference */
    382434                        return EOK;
    383435                }
     
    385437
    386438        return ENOENT;
     439}
     440
     441errno_t vol_part_find_by_id_ref(service_id_t sid, vol_part_t **rpart)
     442{
     443        errno_t rc;
     444
     445        fibril_mutex_lock(&vol_parts_lock);
     446        rc = vol_part_find_by_id_ref_locked(sid, rpart);
     447        fibril_mutex_unlock(&vol_parts_lock);
     448
     449        return rc;
     450}
     451
     452void vol_part_del_ref(vol_part_t *part)
     453{
     454        if (atomic_predec(&part->refcnt) == 0)
     455                vol_part_delete(part);
    387456}
    388457
Note: See TracChangeset for help on using the changeset viewer.