Changeset 1a9174e in mainline


Ignore:
Timestamp:
2018-06-29T15:35:50Z (6 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.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vol/vol.c

    r72c72d4 r1a9174e  
    190190                }
    191191
    192                 table_printf(table, "%s\t" "%s\t" "%s\t" "%d\t" "%s\n",
    193                     vinfo.label, svc_name, sfstype, vinfo.cur_mp_auto,
    194                     vinfo.cur_mp);
     192                table_printf(table, "%s\t" "%s\t" "%s\t" "%s\t" "%s\n",
     193                    vinfo.label, svc_name, sfstype,
     194                    vinfo.cur_mp_auto ? "Yes" : "", vinfo.cur_mp);
    195195
    196196                free(svc_name);
  • 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
  • uspace/srv/volsrv/part.h

    r72c72d4 r1a9174e  
    4747extern errno_t vol_part_add(service_id_t);
    4848extern errno_t vol_part_get_ids(service_id_t *, size_t, size_t *);
    49 extern errno_t vol_part_find_by_id(service_id_t, vol_part_t **);
     49extern errno_t vol_part_find_by_id_ref(service_id_t, vol_part_t **);
     50extern void vol_part_del_ref(vol_part_t *);
    5051extern errno_t vol_part_eject_part(vol_part_t *);
    5152extern errno_t vol_part_empty_part(vol_part_t *);
  • uspace/srv/volsrv/types/part.h

    r72c72d4 r1a9174e  
    3939
    4040#include <adt/list.h>
     41#include <atomic.h>
    4142#include <stdbool.h>
    4243#include <types/label.h>
     
    4647        /** Link to vol_parts */
    4748        link_t lparts;
     49        /** Reference count */
     50        atomic_t refcnt;
    4851        /** Service ID */
    4952        service_id_t svc_id;
  • uspace/srv/volsrv/volsrv.c

    r72c72d4 r1a9174e  
    144144        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_info_srv(%zu)",
    145145            sid);
    146         rc = vol_part_find_by_id(sid, &part);
     146        rc = vol_part_find_by_id_ref(sid, &part);
    147147        if (rc != EOK) {
    148148                async_answer_0(icall_handle, ENOENT);
     
    153153        if (rc != EOK) {
    154154                async_answer_0(icall_handle, EIO);
    155                 return;
     155                goto error;
    156156        }
    157157
     
    161161                async_answer_0(chandle, EREFUSED);
    162162                async_answer_0(icall_handle, EREFUSED);
    163                 return;
     163                goto error;
    164164        }
    165165
     
    167167                async_answer_0(chandle, EINVAL);
    168168                async_answer_0(icall_handle, EINVAL);
    169                 return;
     169                goto error;
    170170        }
    171171
     
    175175                async_answer_0(chandle, rc);
    176176                async_answer_0(icall_handle, rc);
    177                 return;
    178         }
    179 
    180         async_answer_0(icall_handle, EOK);
     177                goto error;
     178        }
     179
     180        async_answer_0(icall_handle, EOK);
     181error:
     182        vol_part_del_ref(part);
    181183}
    182184
     
    190192        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_eject_srv(%zu)", sid);
    191193
    192         rc = vol_part_find_by_id(sid, &part);
     194        rc = vol_part_find_by_id_ref(sid, &part);
    193195        if (rc != EOK) {
    194196                async_answer_0(icall_handle, ENOENT);
    195                 return;
     197                goto error;
    196198        }
    197199
     
    199201        if (rc != EOK) {
    200202                async_answer_0(icall_handle, EIO);
    201                 return;
    202         }
    203 
    204         async_answer_0(icall_handle, EOK);
     203                goto error;
     204        }
     205
     206        async_answer_0(icall_handle, EOK);
     207error:
     208        vol_part_del_ref(part);
    205209}
    206210
     
    214218        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_empty_srv(%zu)", sid);
    215219
    216         rc = vol_part_find_by_id(sid, &part);
     220        rc = vol_part_find_by_id_ref(sid, &part);
    217221        if (rc != EOK) {
    218222                async_answer_0(icall_handle, ENOENT);
     
    223227        if (rc != EOK) {
    224228                async_answer_0(icall_handle, EIO);
    225                 return;
    226         }
    227 
    228         async_answer_0(icall_handle, EOK);
     229                goto error;
     230        }
     231
     232        async_answer_0(icall_handle, EOK);
     233error:
     234        vol_part_del_ref(part);
    229235}
    230236
     
    292298        }
    293299
    294         rc = vol_part_find_by_id(sid, &part);
     300        rc = vol_part_find_by_id_ref(sid, &part);
    295301        if (rc != EOK) {
    296302                free(label);
     
    303309                free(label);
    304310                async_answer_0(icall_handle, rc);
     311                vol_part_del_ref(part);
    305312                return;
    306313        }
Note: See TracChangeset for help on using the changeset viewer.