Changeset 095a989 in mainline


Ignore:
Timestamp:
2024-09-05T22:34:53Z (8 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
ee83e9c
Parents:
e192339
git-author:
Miroslav Cimerman <mc@…> (2024-09-05 22:31:28)
git-committer:
Miroslav Cimerman <mc@…> (2024-09-05 22:34:53)
Message:

hr: add status printing

Location:
uspace
Files:
5 edited

Legend:

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

    re192339 r095a989  
    231231                        return 0;
    232232                case 's':
    233                         printf("hrctl: status not implemented yet\n");
    234                         return 1;
     233                        rc = hr_print_status();
     234                        if (rc != EOK)
     235                                return 1;
     236                        return 0;
    235237                case 'a':
    236238                        if (str_size(optarg) > 31) {
  • uspace/lib/device/include/hr.h

    re192339 r095a989  
    6363} hr_config_t;
    6464
     65typedef struct hr_vol_info {
     66        service_id_t extents[HR_MAXDEVS];
     67        size_t extent_no;
     68        service_id_t svc_id;
     69        hr_level_t level;
     70        uint64_t nblocks;
     71        size_t bsize;
     72} hr_vol_info_t;
     73
    6574extern errno_t hr_sess_init(hr_t **);
    6675extern void hr_sess_destroy(hr_t *);
    6776
    6877extern errno_t hr_create(hr_t *, hr_config_t *);
     78extern errno_t hr_print_status(void);
    6979
    7080#endif
  • uspace/lib/device/include/ipc/hr.h

    re192339 r095a989  
    3939
    4040typedef enum {
    41         HR_CREATE = IPC_FIRST_USER_METHOD
     41        HR_CREATE = IPC_FIRST_USER_METHOD,
     42        HR_STATUS
    4243} hr_request_t;
    4344
  • uspace/lib/device/src/hr.c

    re192339 r095a989  
    114114}
    115115
     116static errno_t print_vol_info(size_t index, hr_vol_info_t *vol_info)
     117{
     118        errno_t rc;
     119        size_t i;
     120        char *devname;
     121
     122        printf("--- vol %zu ---\n", index);
     123
     124        printf("svc_id: %lu\n", vol_info->svc_id);
     125
     126        rc = loc_service_get_name(vol_info->svc_id, &devname);
     127        if (rc != EOK)
     128                return rc;
     129        printf("devname: %s\n", devname);
     130
     131        printf("level: %d\n", vol_info->level);
     132        printf("nblocks: %lu\n", vol_info->nblocks);
     133        printf("bsize: %zu\n", vol_info->bsize);
     134
     135        printf("extents: [index] [devname]\n");
     136        for (i = 0; i < vol_info->extent_no; i++) {
     137                rc = loc_service_get_name(vol_info->extents[i], &devname);
     138                if (rc != EOK)
     139                        return rc;
     140                printf("          %zu       %s\n", i, devname);
     141        }
     142        return EOK;
     143}
     144
     145errno_t hr_print_status(void)
     146{
     147        hr_t *hr;
     148        errno_t rc, retval;
     149        async_exch_t *exch;
     150        aid_t req;
     151        size_t size, i;
     152        hr_vol_info_t *vols;
     153
     154        rc = hr_sess_init(&hr);
     155        if (rc != EOK)
     156                return rc;
     157
     158        exch = async_exchange_begin(hr->sess);
     159        if (exch == NULL)
     160                return EINVAL;
     161
     162        req = async_send_0(exch, HR_STATUS, NULL);
     163
     164        rc = async_data_read_start(exch, &size, sizeof(size_t));
     165        if (rc != EOK) {
     166                async_exchange_end(exch);
     167                async_forget(req);
     168                return rc;
     169        }
     170
     171        vols = calloc(size, sizeof(hr_vol_info_t));
     172        if (vols == NULL) {
     173                async_exchange_end(exch);
     174                async_forget(req);
     175                return ENOMEM;
     176        }
     177
     178        for (i = 0; i < size; i++) {
     179                rc = async_data_read_start(exch, &vols[i],
     180                    sizeof(hr_vol_info_t));
     181                if (rc != EOK) {
     182                        async_exchange_end(exch);
     183                        async_forget(req);
     184                        goto error;
     185                }
     186        }
     187
     188        async_exchange_end(exch);
     189        async_wait_for(req, &retval);
     190        if (retval != EOK) {
     191                rc = retval;
     192                goto error;
     193        }
     194
     195        for (i = 0; i < size; i++) {
     196                rc = print_vol_info(i, &vols[i]);
     197                if (rc != EOK)
     198                        goto error;
     199        }
     200
     201error:
     202        if (vols != NULL)
     203                free(vols);
     204        return rc;
     205}
     206
    116207/** @}
    117208 */
  • uspace/srv/bd/hr/hr.c

    re192339 r095a989  
    136136}
    137137
     138static void hr_print_status_srv(ipc_call_t *icall)
     139{
     140        log_msg(LOG_DEFAULT, LVL_NOTE, "hr_status_srv()");
     141
     142        errno_t rc;
     143        size_t vol_cnt = 0;
     144        hr_vol_info_t info;
     145        ipc_call_t call;
     146        size_t size;
     147
     148        fibril_mutex_lock(&hr_volumes_lock);
     149
     150        vol_cnt = list_count(&hr_volumes);
     151
     152        if (!async_data_read_receive(&call, &size)) {
     153                rc = EREFUSED;
     154                goto error;
     155        }
     156
     157        if (size != sizeof(size_t)) {
     158                rc = EINVAL;
     159                goto error;
     160        }
     161
     162        rc = async_data_read_finalize(&call, &vol_cnt, size);
     163        if (rc != EOK)
     164                goto error;
     165
     166        list_foreach(hr_volumes, lvolumes, hr_volume_t, volume) {
     167                memcpy(info.extents, volume->devs,
     168                    sizeof(service_id_t) * HR_MAXDEVS);
     169                info.svc_id = volume->svc_id;
     170                info.extent_no = volume->dev_no;
     171                info.level = volume->level;
     172                info.nblocks = volume->nblocks;
     173                info.bsize = volume->bsize;
     174
     175                if (!async_data_read_receive(&call, &size)) {
     176                        rc = EREFUSED;
     177                        goto error;
     178                }
     179
     180                if (size != sizeof(hr_vol_info_t)) {
     181                        rc = EINVAL;
     182                        goto error;
     183                }
     184
     185                rc = async_data_read_finalize(&call, &info, size);
     186                if (rc != EOK)
     187                        goto error;
     188        }
     189
     190        fibril_mutex_unlock(&hr_volumes_lock);
     191        async_answer_0(icall, EOK);
     192        return;
     193error:
     194        fibril_mutex_unlock(&hr_volumes_lock);
     195        async_answer_0(&call, rc);
     196        async_answer_0(icall, rc);
     197}
     198
    138199static void hr_ctl_conn(ipc_call_t *icall, void *arg)
    139200{
     
    155216                case HR_CREATE:
    156217                        hr_create_srv(&call);
     218                        break;
     219                case HR_STATUS:
     220                        hr_print_status_srv(&call);
    157221                        break;
    158222                default:
Note: See TracChangeset for help on using the changeset viewer.