Changeset a19d7fc4 in mainline


Ignore:
Timestamp:
2024-09-06T14:56:46Z (8 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
4a2a6b8b
Parents:
09398589
git-author:
Miroslav Cimerman <mc@…> (2024-09-06 14:54:21)
git-committer:
Miroslav Cimerman <mc@…> (2024-09-06 14:56:46)
Message:

hr: add option (-T, —stop) for removing an active array

Location:
uspace
Files:
5 edited

Legend:

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

    r09398589 ra19d7fc4  
    8686        { "create-file", required_argument, 0, 'C' },
    8787        { "assemble-file", required_argument, 0, 'A' },
     88        { "stop", required_argument, 0, 'T' },
    8889        { 0, 0, 0, 0 }
    8990};
     
    231232
    232233        while (c != -1) {
    233                 c = getopt_long(argc, argv, "hsC:c:A:a:l:015Ln:",
     234                c = getopt_long(argc, argv, "hsC:c:A:a:l:015Ln:T:",
    234235                    long_options, NULL);
    235236                switch (c) {
     
    275276                        assemble = true;
    276277                        break;
     278                case 'T':
     279                        rc = hr_stop(optarg);
     280                        free(cfg);
     281                        if (rc != EOK)
     282                                return 1;
     283                        return 0;
    277284                case 'l':
    278285                        if (cfg->level != hr_l_empty)
  • uspace/lib/device/include/hr.h

    r09398589 ra19d7fc4  
    7878extern errno_t hr_create(hr_t *, hr_config_t *);
    7979extern errno_t hr_assemble(hr_t *, hr_config_t *);
     80extern errno_t hr_stop(const char *);
    8081extern errno_t hr_print_status(void);
    8182
  • uspace/lib/device/include/ipc/hr.h

    r09398589 ra19d7fc4  
    4141        HR_CREATE = IPC_FIRST_USER_METHOD,
    4242        HR_ASSEMBLE,
     43        HR_STOP,
    4344        HR_STATUS
    4445} hr_request_t;
  • uspace/lib/device/src/hr.c

    r09398589 ra19d7fc4  
    180180}
    181181
     182errno_t hr_stop(const char *devname)
     183{
     184        hr_t *hr;
     185        errno_t rc;
     186        async_exch_t *exch;
     187        service_id_t svc_id;
     188
     189        rc = loc_service_get_id(devname, &svc_id, 0);
     190        if (rc != EOK)
     191                return rc;
     192
     193        rc = hr_sess_init(&hr);
     194        if (rc != EOK)
     195                return rc;
     196
     197        exch = async_exchange_begin(hr->sess);
     198        if (exch == NULL) {
     199                rc = EINVAL;
     200                goto error;
     201        }
     202        rc = async_req_1_0(exch, HR_STOP, svc_id);
     203        async_exchange_end(exch);
     204
     205        if (rc != EOK)
     206                goto error;
     207error:
     208        hr_sess_destroy(hr);
     209        return rc;
     210}
     211
    182212errno_t hr_print_status(void)
    183213{
     
    187217        aid_t req;
    188218        size_t size, i;
    189         hr_vol_info_t *vols;
     219        hr_vol_info_t *vols = NULL;
    190220
    191221        rc = hr_sess_init(&hr);
     
    194224
    195225        exch = async_exchange_begin(hr->sess);
    196         if (exch == NULL)
    197                 return EINVAL;
     226        if (exch == NULL) {
     227                rc = EINVAL;
     228                goto error;
     229        }
    198230
    199231        req = async_send_0(exch, HR_STATUS, NULL);
    200 
    201232        rc = async_data_read_start(exch, &size, sizeof(size_t));
    202233        if (rc != EOK) {
     
    230261        }
    231262
     263        if (size == 0) {
     264                printf("no active arrays\n");
     265                goto error;
     266        }
     267
    232268        for (i = 0; i < size; i++) {
    233269                rc = print_vol_info(i, &vols[i]);
     
    237273
    238274error:
     275        hr_sess_destroy(hr);
    239276        if (vols != NULL)
    240277                free(vols);
  • uspace/srv/bd/hr/hr.c

    r09398589 ra19d7fc4  
    6161static service_id_t ctl_sid;
    6262
     63static hr_volume_t *hr_get_volume(service_id_t svc_id)
     64{
     65        log_msg(LOG_DEFAULT, LVL_DEBUG, "hr_get_volume(): (%" PRIun ")",
     66            svc_id);
     67
     68        fibril_mutex_lock(&hr_volumes_lock);
     69        list_foreach(hr_volumes, lvolumes, hr_volume_t, volume) {
     70                if (volume->svc_id == svc_id) {
     71                        fibril_mutex_unlock(&hr_volumes_lock);
     72                        return volume;
     73                }
     74        }
     75
     76        fibril_mutex_unlock(&hr_volumes_lock);
     77        return NULL;
     78}
     79
     80static errno_t hr_remove_volume(service_id_t svc_id)
     81{
     82        log_msg(LOG_DEFAULT, LVL_DEBUG, "hr_remove_volume(): (%" PRIun ")",
     83            svc_id);
     84
     85        fibril_mutex_lock(&hr_volumes_lock);
     86        list_foreach(hr_volumes, lvolumes, hr_volume_t, volume) {
     87                if (volume->svc_id == svc_id) {
     88                        hr_fini_devs(volume);
     89                        list_remove(&volume->lvolumes);
     90                        free(volume);
     91                        fibril_mutex_unlock(&hr_volumes_lock);
     92                        return EOK;
     93                }
     94        }
     95
     96        fibril_mutex_unlock(&hr_volumes_lock);
     97        return ENOENT;
     98}
     99
    63100static void hr_create_srv(ipc_call_t *icall)
    64101{
     
    262299}
    263300
     301static void hr_stop_srv(ipc_call_t *icall)
     302{
     303        log_msg(LOG_DEFAULT, LVL_NOTE, "hr_stop_srv()");
     304
     305        errno_t rc;
     306        service_id_t svc_id;
     307        hr_volume_t *vol;
     308
     309        svc_id = ipc_get_arg1(icall);
     310
     311        vol = hr_get_volume(svc_id);
     312        if (vol == NULL) {
     313                async_answer_0(icall, ENOENT);
     314                return;
     315        }
     316
     317        rc = hr_remove_volume(svc_id);
     318        if (rc != EOK) {
     319                async_answer_0(icall, rc);
     320                return;
     321        }
     322
     323        rc = loc_service_unregister(hr_srv, svc_id);
     324
     325        async_answer_0(icall, rc);
     326}
     327
    264328static void hr_print_status_srv(ipc_call_t *icall)
    265329{
     
    345409                        hr_create_srv(&call);
    346410                        break;
     411                case HR_ASSEMBLE:
     412                        hr_assemble_srv(&call);
     413                        break;
     414                case HR_STOP:
     415                        hr_stop_srv(&call);
     416                        break;
    347417                case HR_STATUS:
    348418                        hr_print_status_srv(&call);
    349419                        break;
    350                 case HR_ASSEMBLE:
    351                         hr_assemble_srv(&call);
    352                         break;
    353420                default:
    354421                        async_answer_0(&call, EINVAL);
    355422                }
    356423        }
    357 }
    358 
    359 static hr_volume_t *hr_get_volume(service_id_t svc_id)
    360 {
    361         log_msg(LOG_DEFAULT, LVL_DEBUG, "hr_get_volume(): (%" PRIun ")",
    362             svc_id);
    363 
    364         fibril_mutex_lock(&hr_volumes_lock);
    365         list_foreach(hr_volumes, lvolumes, hr_volume_t, volume) {
    366                 if (volume->svc_id == svc_id) {
    367                         fibril_mutex_unlock(&hr_volumes_lock);
    368                         return volume;
    369                 }
    370         }
    371 
    372         fibril_mutex_unlock(&hr_volumes_lock);
    373         return NULL;
    374424}
    375425
Note: See TracChangeset for help on using the changeset viewer.